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.pos.service.impl; |
|
26 |
|
|
27 |
import cn.hutool.core.bean.BeanUtil; |
|
28 |
import cn.hutool.core.util.ObjectUtil; |
|
29 |
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
30 |
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
31 |
import org.springframework.stereotype.Service; |
|
32 |
import org.springframework.transaction.annotation.Transactional; |
|
33 |
import vip.xiaonuo.core.enums.CommonStatusEnum; |
|
34 |
import vip.xiaonuo.core.exception.ServiceException; |
|
35 |
import vip.xiaonuo.core.factory.PageFactory; |
|
36 |
import vip.xiaonuo.core.pojo.page.PageResult; |
|
37 |
import vip.xiaonuo.core.util.PoiUtil; |
|
38 |
import vip.xiaonuo.sys.modular.emp.service.SysEmpExtOrgPosService; |
|
39 |
import vip.xiaonuo.sys.modular.emp.service.SysEmpPosService; |
|
40 |
import vip.xiaonuo.sys.modular.pos.entity.SysPos; |
|
41 |
import vip.xiaonuo.sys.modular.pos.enums.SysPosExceptionEnum; |
|
42 |
import vip.xiaonuo.sys.modular.pos.mapper.SysPosMapper; |
|
43 |
import vip.xiaonuo.sys.modular.pos.param.SysPosParam; |
|
44 |
import vip.xiaonuo.sys.modular.pos.service.SysPosService; |
|
45 |
|
|
46 |
import javax.annotation.Resource; |
|
47 |
import java.util.List; |
|
48 |
|
|
49 |
/** |
|
50 |
* 系统职位service接口实现类 |
|
51 |
* |
|
52 |
* @author xuyuxiang yubaoshan |
|
53 |
* @date 2020/3/13 16:01 |
|
54 |
*/ |
|
55 |
@Service |
|
56 |
public class SysPosServiceImpl extends ServiceImpl<SysPosMapper, SysPos> implements SysPosService { |
|
57 |
|
|
58 |
@Resource |
|
59 |
private SysEmpPosService sysEmpPosService; |
|
60 |
|
|
61 |
@Resource |
|
62 |
private SysEmpExtOrgPosService sysEmpExtOrgPosService; |
|
63 |
|
|
64 |
@Override |
|
65 |
public PageResult<SysPos> page(SysPosParam sysPosParam) { |
|
66 |
LambdaQueryWrapper<SysPos> queryWrapper = new LambdaQueryWrapper<>(); |
|
67 |
if (ObjectUtil.isNotNull(sysPosParam)) { |
|
68 |
//根据职位名称模糊查询 |
|
69 |
if (ObjectUtil.isNotEmpty(sysPosParam.getName())) { |
|
70 |
queryWrapper.like(SysPos::getName, sysPosParam.getName()); |
|
71 |
} |
|
72 |
//根据职位编码模糊查询 |
|
73 |
if (ObjectUtil.isNotEmpty(sysPosParam.getCode())) { |
|
74 |
queryWrapper.like(SysPos::getCode, sysPosParam.getCode()); |
|
75 |
} |
|
76 |
} |
|
77 |
queryWrapper.eq(SysPos::getStatus, CommonStatusEnum.ENABLE.getCode()); |
|
78 |
//根据排序升序排列,序号越小越在前 |
|
79 |
queryWrapper.orderByAsc(SysPos::getSort); |
|
80 |
return new PageResult<>(this.page(PageFactory.defaultPage(), queryWrapper)); |
|
81 |
} |
|
82 |
|
|
83 |
@Override |
|
84 |
public List<SysPos> list(SysPosParam sysPosParam) { |
|
85 |
LambdaQueryWrapper<SysPos> queryWrapper = new LambdaQueryWrapper<>(); |
|
86 |
if (ObjectUtil.isNotNull(sysPosParam)) { |
|
87 |
//根据职位编码模糊查询 |
|
88 |
if (ObjectUtil.isNotEmpty(sysPosParam.getCode())) { |
|
89 |
queryWrapper.eq(SysPos::getCode, sysPosParam.getCode()); |
|
90 |
} |
|
91 |
} |
|
92 |
queryWrapper.eq(SysPos::getStatus, CommonStatusEnum.ENABLE.getCode()); |
|
93 |
//根据排序升序排列,序号越小越在前 |
|
94 |
queryWrapper.orderByAsc(SysPos::getSort); |
|
95 |
return this.list(queryWrapper); |
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public void add(SysPosParam sysPosParam) { |
|
100 |
//校验参数,检查是否存在相同的名称和编码 |
|
101 |
checkParam(sysPosParam, false); |
|
102 |
SysPos sysPos = new SysPos(); |
|
103 |
BeanUtil.copyProperties(sysPosParam, sysPos); |
|
104 |
sysPos.setStatus(CommonStatusEnum.ENABLE.getCode()); |
|
105 |
this.save(sysPos); |
|
106 |
} |
|
107 |
|
|
108 |
@Transactional(rollbackFor = Exception.class) |
|
109 |
@Override |
|
110 |
public void delete(List<SysPosParam> sysPosParamList) { |
|
111 |
sysPosParamList.forEach(sysPosParam -> { |
|
112 |
SysPos sysPos = this.querySysPos(sysPosParam); |
|
113 |
Long id = sysPos.getId(); |
|
114 |
//该职位下是否有员工 |
|
115 |
boolean hasPosEmp = sysEmpPosService.hasPosEmp(id); |
|
116 |
//只要还有,则不能删 |
|
117 |
if (hasPosEmp) { |
|
118 |
throw new ServiceException(SysPosExceptionEnum.POS_CANNOT_DELETE); |
|
119 |
} |
|
120 |
//该附属职位下是否有员工 |
|
121 |
boolean hasExtPosEmp = sysEmpExtOrgPosService.hasExtPosEmp(id); |
|
122 |
//只要还有,则不能删 |
|
123 |
if (hasExtPosEmp) { |
|
124 |
throw new ServiceException(SysPosExceptionEnum.POS_CANNOT_DELETE); |
|
125 |
} |
|
126 |
sysPos.setStatus(CommonStatusEnum.DELETED.getCode()); |
|
127 |
this.updateById(sysPos); |
|
128 |
}); |
|
129 |
} |
|
130 |
|
|
131 |
@Transactional(rollbackFor = Exception.class) |
|
132 |
@Override |
|
133 |
public void edit(SysPosParam sysPosParam) { |
|
134 |
SysPos sysPos = this.querySysPos(sysPosParam); |
|
135 |
//校验参数,检查是否存在相同的名称和编码 |
|
136 |
checkParam(sysPosParam, true); |
|
137 |
BeanUtil.copyProperties(sysPosParam, sysPos); |
|
138 |
//不能修改状态,用修改状态接口修改状态 |
|
139 |
sysPos.setStatus(null); |
|
140 |
this.updateById(sysPos); |
|
141 |
} |
|
142 |
|
|
143 |
@Override |
|
144 |
public SysPos detail(SysPosParam sysPosParam) { |
|
145 |
return this.querySysPos(sysPosParam); |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* 校验参数,检查是否存在相同的名称和编码 |
|
150 |
* |
|
151 |
* @author xuyuxiang |
|
152 |
* @date 2020/3/25 21:23 |
|
153 |
*/ |
|
154 |
private void checkParam(SysPosParam sysPosParam, boolean isExcludeSelf) { |
|
155 |
Long id = sysPosParam.getId(); |
|
156 |
String name = sysPosParam.getName(); |
|
157 |
String code = sysPosParam.getCode(); |
|
158 |
|
|
159 |
LambdaQueryWrapper<SysPos> queryWrapperByName = new LambdaQueryWrapper<>(); |
|
160 |
queryWrapperByName.eq(SysPos::getName, name) |
|
161 |
.ne(SysPos::getStatus, CommonStatusEnum.DELETED.getCode()); |
|
162 |
|
|
163 |
LambdaQueryWrapper<SysPos> queryWrapperByCode = new LambdaQueryWrapper<>(); |
|
164 |
queryWrapperByCode.eq(SysPos::getCode, code) |
|
165 |
.ne(SysPos::getStatus, CommonStatusEnum.DELETED.getCode()); |
|
166 |
|
|
167 |
if (isExcludeSelf) { |
|
168 |
queryWrapperByName.ne(SysPos::getId, id); |
|
169 |
queryWrapperByCode.ne(SysPos::getId, id); |
|
170 |
} |
|
171 |
|
|
172 |
int countByName = this.count(queryWrapperByName); |
|
173 |
int countByCode = this.count(queryWrapperByCode); |
|
174 |
|
|
175 |
if (countByName >= 1) { |
|
176 |
throw new ServiceException(SysPosExceptionEnum.POS_NAME_REPEAT); |
|
177 |
} |
|
178 |
if (countByCode >= 1) { |
|
179 |
throw new ServiceException(SysPosExceptionEnum.POS_CODE_REPEAT); |
|
180 |
} |
|
181 |
} |
|
182 |
|
|
183 |
/** |
|
184 |
* 获取系统职位 |
|
185 |
* |
|
186 |
* @author xuyuxiang |
|
187 |
* @date 2020/3/26 9:56 |
|
188 |
*/ |
|
189 |
private SysPos querySysPos(SysPosParam sysPosParam) { |
|
190 |
SysPos sysPos = this.getById(sysPosParam.getId()); |
|
191 |
if (ObjectUtil.isNull(sysPos)) { |
|
192 |
throw new ServiceException(SysPosExceptionEnum.POS_NOT_EXIST); |
|
193 |
} |
|
194 |
return sysPos; |
|
195 |
} |
|
196 |
|
|
197 |
@Override |
|
198 |
public void export(SysPosParam sysPosParam) { |
|
199 |
List<SysPos> list = this.list(sysPosParam); |
|
200 |
PoiUtil.exportExcelWithStream("SnowyPos.xls", SysPos.class, list); |
|
201 |
} |
|
202 |
} |