对比新文件 |
| | |
| | | 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.ComponentDepartment; |
| | | import org.jeecg.modules.dnc.mapper.ComponentDepartmentMapper; |
| | | import org.jeecg.modules.dnc.service.IComponentDepartmentService; |
| | | import org.jeecg.modules.dnc.utils.ValidateUtil; |
| | | 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 ComponentDepartmentServiceImpl extends ServiceImpl<ComponentDepartmentMapper, ComponentDepartment> implements IComponentDepartmentService { |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public boolean deleteByComponentId(String componentId) { |
| | | if(!ValidateUtil.validateString(componentId)) |
| | | return false; |
| | | LambdaQueryWrapper<ComponentDepartment> lambdaQueryWrapper = Wrappers.lambdaQuery(); |
| | | lambdaQueryWrapper.eq(ComponentDepartment::getComponentId, componentId); |
| | | return super.remove(lambdaQueryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<MdcProduction> getDepartPermsByComponentId(String componentId) { |
| | | return super.getBaseMapper().getDepartPermsByComponentId(componentId); |
| | | } |
| | | |
| | | @Override |
| | | public List<MdcProduction> getDepartNonPermsByComponentId(String componentId) { |
| | | return super.getBaseMapper().getDepartNonPermsByComponentId(componentId); |
| | | } |
| | | |
| | | @Override |
| | | public ComponentDepartment getByComponentIdAndDepartId(String componentId, String departId) { |
| | | if(!ValidateUtil.validateString(componentId) || !ValidateUtil.validateString(departId)) |
| | | return null; |
| | | List<ComponentDepartment> list = super.lambdaQuery().eq(ComponentDepartment::getComponentId, componentId).eq(ComponentDepartment::getDepartId, departId).list(); |
| | | if(list == null || list.isEmpty()) |
| | | return null; |
| | | return list.get(0); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public boolean removeByCollection(List<ComponentDepartment> componentDepartments) { |
| | | if(componentDepartments == null || componentDepartments.isEmpty()) |
| | | return false; |
| | | if(componentDepartments.size() == 1) { |
| | | return super.removeById(componentDepartments.get(0).getComponentDepartId()); |
| | | } |
| | | List<String> ids = new ArrayList<>(); |
| | | componentDepartments.forEach(item -> { |
| | | ids.add(item.getComponentDepartId()); |
| | | }); |
| | | 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<ComponentDepartment> getByComponentIdsAndDepartIds(List<String> componentIds, List<String> departIds) { |
| | | if(componentIds == null || componentIds.isEmpty() || departIds == null || departIds.isEmpty()) |
| | | return null; |
| | | List<ComponentDepartment> total = new ArrayList<>(); |
| | | List<List<String>> compListArr; |
| | | List<List<String>> departListArr; |
| | | if(componentIds.size() > 1000){ |
| | | compListArr = ListUtils.partition(componentIds, 100); |
| | | }else { |
| | | compListArr = ListUtils.partition(componentIds, 1000); |
| | | } |
| | | if(departIds.size() > 1000){ |
| | | departListArr = ListUtils.partition(departIds, 100); |
| | | }else { |
| | | departListArr = ListUtils.partition(departIds, 1000); |
| | | } |
| | | for(List<String> compList : compListArr) { |
| | | for(List<String> departList : departListArr){ |
| | | LambdaQueryWrapper<ComponentDepartment> queryWrapper = Wrappers.lambdaQuery(); |
| | | queryWrapper.in(ComponentDepartment::getComponentId, compList); |
| | | queryWrapper.in(ComponentDepartment::getDepartId, departList); |
| | | List<ComponentDepartment> list = super.list(queryWrapper); |
| | | if(list != null && !list.isEmpty()){ |
| | | total.addAll(list); |
| | | } |
| | | } |
| | | } |
| | | return total; |
| | | } |
| | | } |