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
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;
    }
}