zhangherong
2025-06-25 23855599412c4d61b38d78f0f3abd3430a48b5b1
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/service/impl/ProcessSpecVersionDepartmentServiceImpl.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,133 @@
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.apache.commons.collections4.ListUtils;
import org.jeecg.modules.dnc.entity.ProcessSpecVersionDepartment;
import org.jeecg.modules.dnc.mapper.ProcessSpecVersionDepartmentMapper;
import org.jeecg.modules.dnc.service.IProcessSpecVersionDepartmentService;
import org.jeecg.modules.dnc.utils.ValidateUtil;
import org.jeecg.modules.system.entity.MdcProduction;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class ProcessSpecVersionDepartmentServiceImpl extends ServiceImpl<ProcessSpecVersionDepartmentMapper, ProcessSpecVersionDepartment> implements IProcessSpecVersionDepartmentService {
    /**
     * æ ¹æ®å·¥è‰ºè§„程版本id删除部门权限
     * @param psvId
     * @return
     */
    @Override
    public boolean deleteByPsvId(String psvId) {
        if(!ValidateUtil.validateString(psvId))
            return false;
        LambdaQueryWrapper<ProcessSpecVersionDepartment> lambdaQueryWrapper =  Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ProcessSpecVersionDepartment::getPsvId, psvId);
        return super.remove(lambdaQueryWrapper);
    }
    /**
     * èŽ·å–å·²åˆ†é…çš„éƒ¨é—¨
     * @param psvId
     * @return
     */
    @Override
    public List<MdcProduction> getDepartPermsByPsvId(String psvId){
        return super.baseMapper.getDepartPermsByPsvId(psvId);
    }
    /**
     * èŽ·å–å·²åˆ†é…çš„éƒ¨é—¨
     * @param psvId
     * @return
     */
    @Override
    public List<MdcProduction> getDepartNonPermsByPsvId(String psvId){
        return super.baseMapper.getDepartNonPermsByPsvId(psvId);
    }
    /**
     * æŸ¥è¯¢éƒ¨é—¨æƒé™
     * @param psvId
     * @param departId
     * @return
     */
    @Override
    public ProcessSpecVersionDepartment getByProcessSpecVersionIdAndDepartId(String psvId, String departId){
        if(!ValidateUtil.validateString(psvId) || !ValidateUtil.validateString(psvId))
            return null;
        List<ProcessSpecVersionDepartment> list = super.lambdaQuery().eq(ProcessSpecVersionDepartment::getPsvId, psvId).eq(ProcessSpecVersionDepartment::getDepartId, departId).list();
        if(list == null || list.isEmpty())
            return null;
        return list.get(0);
    }
    /**
     * ç§»é™¤éƒ¨é—¨æƒé™
     * @param processSpecVersionDepartments
     * @return
     */
    @Override
    public boolean removeByCollection(List<ProcessSpecVersionDepartment> processSpecVersionDepartments){
        if(processSpecVersionDepartments == null || processSpecVersionDepartments.isEmpty())
            return false;
        if(processSpecVersionDepartments.size() == 1)
            return super.removeById(processSpecVersionDepartments.get(0).getId());
        List<String> ids = new ArrayList<>();
        processSpecVersionDepartments.forEach(item -> {
            ids.add(item.getId());
        });
        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);
        }
    }
    /**
     * æŸ¥è¯¢ä¸€ç»„部门权限
     * @param psvIds
     * @param ids
     * @return
     */
    @Override
    public List<ProcessSpecVersionDepartment> getByPsvIdsAndDepartIds(List<String> psvIds, List<String> ids){
        if(psvIds == null || psvIds.isEmpty() || ids == null || ids.isEmpty())
            return null;
        List<ProcessSpecVersionDepartment> total = new ArrayList<>();
        List<List<String>> compListArr;
        List<List<String>> departListArr;
        if(psvIds.size() > 1000){
            compListArr = ListUtils.partition(psvIds, 100);
        }else {
            compListArr = ListUtils.partition(psvIds, 1000);
        }
        if(ids.size() > 1000){
            departListArr = ListUtils.partition(ids, 100);
        }else {
            departListArr = ListUtils.partition(ids, 1000);
        }
        for(List<String> compList : compListArr) {
            for(List<String> departList : departListArr){
                LambdaQueryWrapper<ProcessSpecVersionDepartment> queryWrapper = Wrappers.lambdaQuery();
                queryWrapper.in(ProcessSpecVersionDepartment::getPsvId, compList);
                queryWrapper.in(ProcessSpecVersionDepartment::getDepartId, departList);
                List<ProcessSpecVersionDepartment> list = super.list(queryWrapper);
                if(list != null && !list.isEmpty()){
                    total.addAll(list);
                }
            }
        }
        return total;
    }
}