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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
package com.yiboshi.science.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yiboshi.arch.exception.BusinessException;
import com.yiboshi.science.base.BaseServiceImpl;
import com.yiboshi.science.base.Pagination;
import com.yiboshi.science.dao.ComExpertDAO;
import com.yiboshi.science.entity.*;
import com.yiboshi.science.enumeration.CommonEnum;
import com.yiboshi.science.param.dto.ComExpertDTO;
import com.yiboshi.science.param.dto.ComPersonDTO;
import com.yiboshi.science.param.query.ComExpertQueryVO;
import com.yiboshi.science.service.*;
import com.yiboshi.science.utils.ChineseToPinyin;
import com.yiboshi.science.utils.StringUtil;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
import static com.yiboshi.science.utils.StringUtil.hideAllPhoneNum;
import static com.yiboshi.science.utils.StringUtil.hideAllIdCardNum;
@Service
@AllArgsConstructor
public class ComExpertServiceImpl extends BaseServiceImpl<ComExpertDAO, ComExpertQueryVO, ComExpertDTO, ComExpert> implements ComExpertService {
@Autowired
private ComExpertDAO comExpertDAO;
@Autowired
private ComExpertSpecService comExpertSpecService;
@Autowired
private ComPersonService comPersonService;
@Autowired
private ComUnitService comUnitService;
@Autowired
private SystemUserService systemUserService;
@Autowired
private SystemUserRoleService systemUserRoleService;
@Autowired
private SystemParameterService systemParameterService;
@Override
protected void setCriteriaForQuery(ComExpertQueryVO vo, QueryWrapper<ComExpertQueryVO> criteria) {
if (Objects.nonNull(vo.getUnitId())) {
criteria.eq("a.unit_id", vo.getUnitId());
}
if (Objects.nonNull(vo.getReportState())) {
criteria.eq("a.report_state", vo.getReportState());
}
if (Objects.nonNull(vo.getCertId())) {
criteria.eq("e.cert_id", vo.getCertId());
}
if (Objects.nonNull(vo.getPersonName())) {
criteria.eq("e.person_name", vo.getPersonName());
}
if (Objects.nonNull(vo.getWorkUnit())) {
criteria.eq("e.work_unit", vo.getWorkUnit());
}
if (Objects.nonNull(vo.getUnitName())) {
criteria.like("d.unit_name", vo.getUnitName());
}
if (Objects.nonNull(vo.getUsername())) {
criteria.eq("f.username", vo.getUsername());
}
if (Objects.nonNull(vo.getRoleId())) {
criteria.eq("l.role_id", vo.getRoleId());
}
if (Objects.nonNull(vo.getRemark())) {
criteria.like("a.remark", vo.getRemark());
}
if (Objects.nonNull(vo.getTitle())) {
criteria.eq("e.title", vo.getTitle());
}
if (Objects.nonNull(vo.getTitleParentId())) {
criteria.eq("i.parent_id", vo.getTitleParentId());
}
if (Objects.nonNull(vo.getSpec())) {
criteria.eq("e.spec", vo.getSpec());
}
if (Objects.nonNull(vo.getSpecParentId())) {
criteria.eq("j.parent_id", vo.getSpecParentId());
}
}
@Override
public Pagination<ComExpertDTO> getListByPage(ComExpertQueryVO vo) {
QueryWrapper criteria = new QueryWrapper();
setCriteriaForQuery(vo, criteria);
Page<ComExpertQueryVO> page = new Page<>(vo.getPageIndex(), vo.getPageSize());
List<ComExpertDTO> dtoList = comExpertDAO.getListByPage(page, criteria).getRecords();
return new Pagination<>(dtoList, page.getTotal(), vo.getPageSize());
}
public ComExpertDTO getExpertById(String id) {
ComExpertDTO dto = comExpertDAO.getExpertById(id);
if (null != dto) {
dto.setSpecList(comExpertSpecService.getListByExpertId(id));
dto.setAuditSpecList(comExpertSpecService.getIdListByExpertId(id));
dto.setCertId(hideAllIdCardNum(dto.getCertId()));
// if (Objects.nonNull(dto.getMobile()))
// dto.setMobile(hideAllPhoneNum(dto.getMobile()));
}
return dto;
}
@Transactional
public String insert(ComExpertDTO dto) {
dto.setReportState(1);
dto.setCertId(dto.getCertId().toLowerCase());
ComPerson comPerson = comPersonService.getPersonByCertId(dto.getCertId());
ComExpert comExpert = new ComExpert();
String personId = "";
if (comPerson != null) {
personId = comPerson.getId();
comExpert.setPersonId(personId);
comExpert = this.getEntity(comExpert);
if (null != comExpert)
throw new BusinessException("专家已存在!");
if (!dto.getPersonName().equals(comPerson.getPersonName()))
throw new BusinessException("该证件号已存在系统中,但姓名不一致,请检查!");
if (!dto.getMobile().equals(comPerson.getMobile()))
throw new BusinessException("该手机号已注册,请检查后再试!");
StringUtil.copyObj2Obj(dto, comPerson);
comPerson.setId(personId);
comPersonService.updateById(comPerson);
systemUserRoleService.addRoleByPersonId(personId, CommonEnum.systemRole.expert.getCode().toString());
} else {
if (comPersonService.isMobileExist(dto.getMobile()))
throw new BusinessException("该手机号已注册,请检查后再试!");
comPerson = new ComPerson();
StringUtil.copyObj2Obj(dto, comPerson);
ComUnit comUnit = comUnitService.isExist(dto.getUnitName());
if (null != comUnit)
comPerson.setUnitId(comUnit.getId());
comPerson.setPersonState(CommonEnum.personState.normal.getCode());
personId = comPersonService.insert(comPerson);
String pwd = dto.getCertId().substring(dto.getCertId().length() - 6).toLowerCase();
String UserName = ChineseToPinyin.toPinyin(comPerson.getPersonName());
systemUserService.CreateUser(UserName, pwd, personId, CommonEnum.systemRole.expert.getCode().toString(), CommonEnum.userState.normal.getCode());
}
comExpert = new ComExpert();
comExpert.setPersonId(personId);
comExpert.setRemark(dto.getRemark());
comExpert.setExpertState(CommonEnum.loginState.start.getCode());
String id = this.insert(comExpert);
dto.setId(comExpert.getId());
comExpertSpecService.insertSpecList(dto.getAuditSpecList(), id);
return dto.getId();
}
@Transactional
public String update(ComExpertDTO dto) {
ComExpert comExpert = this.entityById(dto.getId());
if (null == comExpert)
throw new BusinessException("专家不存在或已删除!");
ComPerson comPerson = new ComPerson();
StringUtil.copyObj2Obj(dto, comPerson);
comPerson.setId(comExpert.getPersonId());
comPerson.setCertId(null);
comPerson.setMobile(null);
comExpert = new ComExpert();
comExpert.setId(dto.getId());
comExpert.setRemark(dto.getRemark());
this.update(comExpert);
comPersonService.updateById(comPerson);
comExpertSpecService.insertSpecList(dto.getAuditSpecList(), dto.getId());
return dto.getId();
}
@Transactional
public String deleteExpert(ComExpertDTO d) {
//systemUserRoleService.deleteById(d.getUserRoleId());
if (null != d.getUserRoleId())
throw new BusinessException("系统限制,专家暂时不能删除!");
return d.getUserRoleId();
}
public String updateExpertState(ComExpertDTO d) {
ComExpert comExpert = new ComExpert();
comExpert.setId(d.getId());
comExpert.setExpertState(d.getExpertState());
String id = this.update(comExpert);
systemUserRoleService.updateStateById(d.getUserRoleId(), d.getExpertState());
return id;
}
public String expertImport(List<ComExpertDTO> list) {
try {
//职称
List<SystemParameter> titleList = systemParameterService.getListByType(7);
//专业学科
List<SystemParameter> specList = systemParameterService.getListByType(42);
list.forEach(e -> {
if (null != comPersonService.getPersonByCertId(e.getCertId()))
return;
if (null != e.getTitleName()) {
List<SystemParameter> findList1 = titleList.stream().filter(p -> e.getTitleName().equals(p.getName())).collect(Collectors.toList());
if (findList1.size() > 0)
e.setTitle(findList1.stream().findFirst().get().getId());
}
if (null != e.getSpecName()) {
List<SystemParameter> findList2 = specList.stream().filter(p -> e.getSpecName().equals(p.getName())).collect(Collectors.toList());
if (findList2.size() > 0) {
List<String> audtiSpecList = new ArrayList<>();
audtiSpecList.add(findList2.stream().findFirst().get().getId());
e.setAuditSpecList(audtiSpecList);
}
}
insert(e);
});
return "专家导入成功!";
} catch (Exception e) {
throw new BusinessException(e.getMessage());
}
}
public Boolean expertIsExist(String certId, String id) {
Boolean isExist = false;
ComExpertDTO dto = this.getExpertByCertId(certId);
if (null != dto) {
if (Objects.nonNull(id) && !id.equals("")) {
ComExpertDTO comExpertDTO = comExpertDAO.getExpertById(id);
if (null != comExpertDTO && !comExpertDTO.getCertId().equals(certId)) {
isExist = true;
}
} else {
isExist = true;
}
}
return isExist;
}
public List<SelectListItem> getExpertListByIdList(Map<String, Object> id) {
List<String> idList = null;
if (id.containsKey("idList")) {
idList = (List<String>) id.get("idList");
}
QueryWrapper<SystemMenu> w = new QueryWrapper<SystemMenu>();
if (Objects.nonNull(idList) && idList.size() > 0) {
w.in("a.id", idList);
}
List<ComExpertDTO> list = comExpertDAO.getExpertListByIdList(w);
List<SelectListItem> Item = new ArrayList<>();
if (null != list && list.size() > 0) {
list.forEach((e) -> {
SelectListItem treeListItem = new SelectListItem(e.getPersonName(), e.getId(), "", false, false, new ArrayList<>());
Item.add(treeListItem);
});
}
return Item;
}
public ComExpertDTO getExpertByCertId(String certId) {
return comExpertDAO.getExpertByCertId(certId);
}
}