bug
jiangping
2023-11-07 64b432916af9c9218ab3f3eca614e26c542142ae
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
package doumeemes.service.system.impl;
 
import doumeemes.dao.system.SystemPositionMapper;
import doumeemes.dao.system.model.SystemPosition;
import doumeemes.dao.system.vo.SystemPositionListVO;
import doumeemes.service.system.SystemPositionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 岗位Service实现
 * @author Eva.Caesar Liu
 * @date 2022/04/18 18:12
 */
@Service
public class SystemPositionServiceImpl implements SystemPositionService {
 
    @Autowired
    private SystemPositionMapper systemPositionMapper;
 
    @Override
    public Integer create(SystemPosition systemPosition) {
        systemPositionMapper.insert(systemPosition);
        return systemPosition.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        SystemPosition systemPosition = new SystemPosition();
        systemPosition.setId(id);
        systemPosition.setDeleted(Boolean.TRUE);
        this.updateById(systemPosition);
    }
 
    @Override
    @Transactional
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) return;
        for (Integer id : ids) {
            this.deleteById(id);
        }
    }
 
    @Override
    public void updateById(SystemPosition systemPosition) {
        systemPositionMapper.updateById(systemPosition);
    }
 
    @Override
    @Transactional
    public void updateByIdInBatch(List<SystemPosition> systemPositions) {
        if (CollectionUtils.isEmpty(systemPositions)) return;
        for (SystemPosition systemPosition: systemPositions) {
            this.updateById(systemPosition);
        }
    }
 
    @Override
    public SystemPosition findById(Integer id) {
        return systemPositionMapper.selectById(id);
    }
 
    @Override
    public List<SystemPosition> findByIds(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return Collections.emptyList();
        }
        QueryWrapper<SystemPosition> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().in(SystemPosition::getId, ids).eq(SystemPosition::getDeleted, Boolean.FALSE);
        return systemPositionMapper.selectList(queryWrapper);
    }
 
    @Override
    public SystemPosition findOne(SystemPosition systemPosition) {
        return systemPositionMapper.selectOne(new QueryWrapper<>(systemPosition));
    }
 
    @Override
    public List<SystemPosition> findList(SystemPosition systemPosition) {
        return systemPositionMapper.selectList(new QueryWrapper<>(systemPosition));
    }
 
    @Override
    public List<SystemPositionListVO> findList() {
        return systemPositionMapper.selectManageList();
    }
 
    @Override
    public List<SystemPosition> findByUserId(Integer userId) {
        return systemPositionMapper.selectByUserId(userId);
    }
 
    @Override
    public long count(SystemPosition systemPosition) {
        return systemPositionMapper.selectCount(new QueryWrapper<>(systemPosition));
    }
 
    @Override
    public List<Integer> findChildren(Integer positionId) {
        List<Integer> pool = new ArrayList<>();
        this.fillChildren(pool, Arrays.asList(positionId));
        return pool;
    }
 
    /**
     * 获取子岗位ID
     * @author Eva.Caesar Liu
     * @date 2022/04/18 18:12
     */
    private void fillChildren(List<Integer> pool, List<Integer> parentIds) {
        QueryWrapper<SystemPosition> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(SystemPosition::getDeleted, Boolean.FALSE)
                .in(SystemPosition::getParentId, parentIds);
        List<SystemPosition> positions = systemPositionMapper.selectList(queryWrapper);
        List<Integer> ids = positions.stream().map(SystemPosition::getId).collect(Collectors.toList());
        if (ids.size() > 0) {
            pool.addAll(ids);
            this.fillChildren(pool, ids);
        }
    }
}