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.ucenter.Department; import org.jeecg.modules.dnc.utils.ValidateUtil; import org.apache.commons.collections4.ListUtils; 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 implements IComponentDepartmentService { @Override @Transactional(rollbackFor = {Exception.class}) public boolean deleteByComponentId(String componentId) { if(!ValidateUtil.validateString(componentId)) return false; LambdaQueryWrapper lambdaQueryWrapper = Wrappers.lambdaQuery(); lambdaQueryWrapper.eq(ComponentDepartment::getComponentId, componentId); return super.remove(lambdaQueryWrapper); } @Override public List getDepartPermsByComponentId(String componentId) { return super.getBaseMapper().getDepartPermsByComponentId(componentId); } @Override public List 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 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 componentDepartments) { if(componentDepartments == null || componentDepartments.isEmpty()) return false; if(componentDepartments.size() == 1) { return super.removeById(componentDepartments.get(0).getComponentDepartId()); } List ids = new ArrayList<>(); componentDepartments.forEach(item -> { ids.add(item.getComponentDepartId()); }); if(ids.size() > 1000){ List> idsArr = ListUtils.partition(ids, 1000); for(List arr : idsArr){ super.removeByIds(arr); } return true; }else { return super.removeByIds(ids); } } @Override public List getByComponentIdsAndDepartIds(List componentIds, List departIds) { if(componentIds == null || componentIds.isEmpty() || departIds == null || departIds.isEmpty()) return null; List total = new ArrayList<>(); List> compListArr; List> 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 compList : compListArr) { for(List departList : departListArr){ LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); queryWrapper.in(ComponentDepartment::getComponentId, compList); queryWrapper.in(ComponentDepartment::getDepartId, departList); List list = super.list(queryWrapper); if(list != null && !list.isEmpty()){ total.addAll(list); } } } return total; } }