张晓波
2023-09-19 164694c47c35d6654df69b533e8dbf8b5423efc5
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
package com.thhy.staff.modules.biz.depart.service.impl;
 
import com.alibaba.nacos.api.utils.StringUtils;
import com.thhy.general.common.BasicStatus;
import com.thhy.general.config.SysUserInfo;
import com.thhy.general.exception.BasicException;
import com.thhy.general.utils.UserInfoUtils;
import com.thhy.staff.modules.biz.depart.entity.*;
import com.thhy.staff.modules.biz.depart.mapper.DepartMapper;
import com.thhy.staff.modules.biz.depart.service.DepartService;
import com.thhy.staff.modules.biz.group.mapper.GroupMapper;
import com.thhy.staff.modules.biz.platuser.entity.PlatUser;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
 
/**
 *  服务实现类
 * @author zhang_xiao_bo
 * @since 2023-03-31 13:07:46
 */
@Service
public class DepartServiceImpl implements DepartService {
 
 
 
    @Autowired
    private DepartMapper departMapper;
 
    @Autowired
    private GroupMapper groupMapper;
 
    public Depart get(Serializable id){
        return departMapper.queryById(id);
    }
 
    public List<DepartListVo> findList(Depart depart){
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        return departMapper.findList(depart.setCompanyId(sysUserInfo.getCompanyId()));
    }
 
 
    public List<DepartListVo> findListForExport(Depart depart, String token) {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo(token);
        return departMapper.findList(depart.setCompanyId(sysUserInfo.getCompanyId()));
    }
 
    @Override
    public List<DepartGroupPullVo> pulldownList() {
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        if(StringUtils.isEmpty(sysUserInfo.getCompanyId())){
            throw new BasicException(BasicStatus.NO_PERMIT);
        }
        List<DepartGroupPullVo> departGroupPullVos = departMapper.findPull(sysUserInfo.getCompanyId());
        for(DepartGroupPullVo departGroupPullVo : departGroupPullVos){
            List<GroupPullDownVo> groupPullDownVos = groupMapper.findPullByDepartId(departGroupPullVo.getDepartId());
            departGroupPullVo.setGroups(groupPullDownVos);
        }
        return departGroupPullVos;
    }
 
    /**
     * 增加和修改
     * @param depart
     */
    @Transactional
    public void addDepart(Depart depart){
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        if(depart.getDepartId() == null){
            //增加操作
            depart.setCreateUser(sysUserInfo.getUserId());
            departMapper.insert(depart);
            departMapper.insertCompanyDepart(new DepartCompany(sysUserInfo.getCompanyId(),depart.getDepartId()));
        }else{
            //修改操作
            depart.setUpdateTime(new Date());
            depart.setUpdateUser(sysUserInfo.getUserId());
            departMapper.update(depart);
        }
 
    }
 
    /**
     * 修改
     * @param depart
     */
    public void update(Depart depart){
        departMapper.update(depart);
    }
 
    /**
     * 删除
     * @param departId
     */
    public void delete(Serializable departId){
        departMapper.deletelogic(departId);
    }
 
    @Override
    public List<PlatUser> departUserList(DepartUserDto departUserDto) {
        return departMapper.queryUserByDepart(departUserDto);
    }
}