对比新文件 |
| | |
| | | package org.jeecg.modules.dnc.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.jeecg.modules.dnc.entity.PartsDepartment; |
| | | import org.jeecg.modules.dnc.mapper.PartsDepartmentMapper; |
| | | import org.jeecg.modules.dnc.utils.ValidateUtil; |
| | | import org.jeecg.modules.dnc.service.IPartsDepartmentService; |
| | | import org.apache.commons.collections4.ListUtils; |
| | | import org.jeecg.modules.system.entity.MdcProduction; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | public class PartsDepartmentServiceImpl extends ServiceImpl<PartsDepartmentMapper, PartsDepartment> implements IPartsDepartmentService { |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public boolean deleteByPartsId(String partsId) { |
| | | if(!ValidateUtil.validateString(partsId)) |
| | | return false; |
| | | LambdaQueryWrapper<PartsDepartment> lambdaQueryWrapper = Wrappers.lambdaQuery(); |
| | | lambdaQueryWrapper.eq(PartsDepartment::getPartsId, partsId); |
| | | return super.remove(lambdaQueryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<MdcProduction> getDepartPermsByPartsId(String partsId) { |
| | | return super.getBaseMapper().getDepartPermsByPartsId(partsId); |
| | | } |
| | | |
| | | @Override |
| | | public List<MdcProduction> getDepartNonPermsByProductId(String partsId) { |
| | | return super.getBaseMapper().getDepartNonPermsByPartsId(partsId); |
| | | } |
| | | |
| | | @Override |
| | | public PartsDepartment getByPartsIdAndDepartId(String partsId, String departId) { |
| | | if(!ValidateUtil.validateString(partsId) || !ValidateUtil.validateString(departId)) |
| | | return null; |
| | | List<PartsDepartment> list = super.lambdaQuery().eq(PartsDepartment::getPartsId, partsId).eq(PartsDepartment::getDepartId, departId).list(); |
| | | if(list == null || list.isEmpty()) |
| | | return null; |
| | | return list.get(0); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public boolean removeByCollection(List<PartsDepartment> partsDepartments) { |
| | | if(partsDepartments == null || partsDepartments.isEmpty()) |
| | | return false; |
| | | if(partsDepartments.size() == 1) |
| | | return super.removeById(partsDepartments.get(0).getPartsDepartId()); |
| | | List<String> ids = new ArrayList<>(); |
| | | partsDepartments.forEach(item -> { |
| | | ids.add(item.getPartsDepartId()); |
| | | }); |
| | | if(ids.size() > 1000){ |
| | | List<List<String>> idsArr = ListUtils.partition(ids, 1000); |
| | | for(List<String> arr : idsArr){ |
| | | super.removeByIds(arr); |
| | | } |
| | | return true; |
| | | }else { |
| | | return super.removeByIds(ids); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<PartsDepartment> getByPartsIdsAndDepartIds(List<String> partsIds, List<String> departIds) { |
| | | if(partsIds == null || partsIds.isEmpty() || departIds == null || departIds.isEmpty()) |
| | | return null; |
| | | List<PartsDepartment> total = new ArrayList<>(); |
| | | List<List<String>> partListArr; |
| | | List<List<String>> departListArr; |
| | | if(partsIds.size() > 1000){ |
| | | partListArr = ListUtils.partition(partsIds, 100); |
| | | }else { |
| | | partListArr = ListUtils.partition(partsIds, 1000); |
| | | } |
| | | if(departIds.size() > 1000){ |
| | | departListArr = ListUtils.partition(departIds, 100); |
| | | }else { |
| | | departListArr = ListUtils.partition(departIds, 1000); |
| | | } |
| | | for(List<String> partList : partListArr) { |
| | | for(List<String> departList : departListArr){ |
| | | LambdaQueryWrapper<PartsDepartment> queryWrapper = Wrappers.lambdaQuery(); |
| | | queryWrapper.in(PartsDepartment::getPartsId, partList); |
| | | queryWrapper.in(PartsDepartment::getDepartId, departList); |
| | | List<PartsDepartment> list = super.list(queryWrapper); |
| | | if(list != null && !list.isEmpty()){ |
| | | total.addAll(list); |
| | | } |
| | | } |
| | | } |
| | | return total; |
| | | } |
| | | } |