zhangherong
2025-06-25 2fb6c67b2c0c72195eef6fe5f7904d739b46e2c0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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;
    }
}