inleft
2022-03-02 42b7d05dfdf60ee67c876084a3240ff48a3bf3a5
commit | author | age
9bcb19 1 /*
I 2 Copyright [2020] [https://www.xiaonuo.vip]
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8   http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
17
18 1.请不要删除和修改根目录下的LICENSE文件。
19 2.请不要删除和修改Snowy源码头部的版权声明。
20 3.请保留源码和相关描述文件的项目出处,作者声明等。
21 4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy
22 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy
23 6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
24  */
25 package vip.xiaonuo.sys.modular.emp.service.impl;
26
27 import cn.hutool.core.bean.BeanUtil;
28 import cn.hutool.core.collection.CollectionUtil;
29 import cn.hutool.core.lang.Dict;
30 import cn.hutool.core.util.ObjectUtil;
31 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
32 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
33 import org.springframework.stereotype.Service;
34 import org.springframework.transaction.annotation.Transactional;
35 import vip.xiaonuo.core.pojo.login.LoginEmpInfo;
36 import vip.xiaonuo.sys.modular.emp.entity.SysEmp;
37 import vip.xiaonuo.sys.modular.emp.mapper.SysEmpMapper;
38 import vip.xiaonuo.sys.modular.emp.param.SysEmpParam;
39 import vip.xiaonuo.sys.modular.emp.result.SysEmpInfo;
40 import vip.xiaonuo.sys.modular.emp.service.SysEmpExtOrgPosService;
41 import vip.xiaonuo.sys.modular.emp.service.SysEmpPosService;
42 import vip.xiaonuo.sys.modular.emp.service.SysEmpService;
43 import vip.xiaonuo.sys.modular.user.service.SysUserService;
44
45 import javax.annotation.Resource;
46 import java.util.List;
47 import java.util.Set;
48 import java.util.stream.Collectors;
49
50 /**
51  * 员工service接口实现类
52  *
53  * @author xuyuxiang
54  * @date 2020/3/13 15:10
55  */
56 @Service
57 public class SysEmpServiceImpl extends ServiceImpl<SysEmpMapper, SysEmp> implements SysEmpService {
58
59     @Resource
60     private SysEmpExtOrgPosService sysEmpExtOrgPosService;
61
62     @Resource
63     private SysEmpPosService sysEmpPosService;
64
65     @Resource
66     private SysUserService sysUserService;
67
68     @Override
69     public LoginEmpInfo getLoginEmpInfo(Long empId) {
70
71         LoginEmpInfo loginEmpInfo = new LoginEmpInfo();
72         //获取员工信息
73         SysEmp sysEmp = this.getById(empId);
74         if (ObjectUtil.isNotNull(sysEmp)) {
75             BeanUtil.copyProperties(sysEmp, loginEmpInfo);
76             //获取附属机构和职位信息
77             List<Dict> empExtOrgPosDictList = sysEmpExtOrgPosService.getEmpExtOrgPosDictList(sysEmp.getId(), false);
78             loginEmpInfo.setExtOrgPos(empExtOrgPosDictList);
79
80             //获取所属职位信息
81             List<Dict> empEmpPosDictList = sysEmpPosService.getEmpPosDictList(sysEmp.getId(), false);
82             loginEmpInfo.setPositions(empEmpPosDictList);
83         } else {
84             loginEmpInfo.setExtOrgPos(CollectionUtil.newArrayList());
85             loginEmpInfo.setPositions(CollectionUtil.newArrayList());
86         }
87         return loginEmpInfo;
88     }
89
90     @Override
91     public SysEmpInfo getSysEmpInfo(Long empId) {
92         SysEmpInfo sysEmpInfo = new SysEmpInfo();
93         //获取员工信息
94         SysEmp sysEmp = this.getById(empId);
95         if (ObjectUtil.isNotNull(sysEmp)) {
96             BeanUtil.copyProperties(sysEmp, sysEmpInfo);
97             //获取附属机构和职位信息
98             List<Dict> empExtOrgPosDictList = sysEmpExtOrgPosService.getEmpExtOrgPosDictList(sysEmp.getId(), true);
99             sysEmpInfo.setExtOrgPos(empExtOrgPosDictList);
100
101             //获取所属职位信息
102             List<Dict> empEmpPosDictList = sysEmpPosService.getEmpPosDictList(sysEmp.getId(), true);
103             sysEmpInfo.setPositions(empEmpPosDictList);
104         } else {
105             sysEmpInfo.setExtOrgPos(CollectionUtil.newArrayList());
106             sysEmpInfo.setPositions(CollectionUtil.newArrayList());
107         }
108         return sysEmpInfo;
109     }
110
111     @Transactional(rollbackFor = Exception.class)
112     @Override
113     public void addOrUpdate(SysEmpParam sysEmpParam) {
114         Long empId = sysEmpParam.getId();
115         SysEmp sysEmp = this.getById(empId);
116         if (ObjectUtil.isNull(sysEmp)) {
117             sysEmp = new SysEmp();
118         }
119         BeanUtil.copyProperties(sysEmpParam, sysEmp);
120         this.saveOrUpdate(sysEmp);
121         //编辑附属机构职位相关信息
122         List<Dict> extIdList = sysEmpParam.getExtIds();
123         sysEmpExtOrgPosService.addOrEdit(empId, extIdList);
124         //编辑职位相关信息
125         List<Long> posIdList = sysEmpParam.getPosIdList();
126         sysEmpPosService.addOrEdit(empId, posIdList);
127     }
128
129     @Override
130     public void updateEmpOrgInfo(Long orgId, String orgName) {
131         LambdaQueryWrapper<SysEmp> queryWrapper = new LambdaQueryWrapper<>();
132         queryWrapper.eq(SysEmp::getOrgId, orgId);
133         this.list(queryWrapper).forEach(sysEmp -> {
134             sysEmp.setOrgName(orgName);
135             this.updateById(sysEmp);
136         });
137     }
138
139     @Override
140     public boolean hasOrgEmp(Long orgId) {
141         LambdaQueryWrapper<SysEmp> queryWrapper = new LambdaQueryWrapper<>();
142         queryWrapper.eq(SysEmp::getOrgId, orgId);
143         List<SysEmp> list = this.list(queryWrapper);
144         if(ObjectUtil.isEmpty(list)) {
145             return false;
146         } else {
147             Set<Long> collect = list.stream().map(SysEmp::getId).collect(Collectors.toSet());
148             return sysUserService.hasAllDeletedUser(collect);
149         }
150     }
151
152     @Transactional(rollbackFor = Exception.class)
153     @Override
154     public void deleteEmpInfoByUserId(Long empId) {
155         //删除员工信息
156         this.removeById(empId);
157
158         //级联删除对应的员工-附属信息
159         sysEmpExtOrgPosService.deleteEmpExtInfoByUserId(empId);
160
161         //级联删除对用的员工-职位信息
162         sysEmpPosService.deleteEmpPosInfoByUserId(empId);
163     }
164 }