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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
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.ComProjectDAO;
import com.yiboshi.science.dao.ComProjectGroupDAO;
import com.yiboshi.science.entity.*;
import com.yiboshi.science.param.dto.*;
import com.yiboshi.science.param.query.ComProjectAuditQueryVO;
import com.yiboshi.science.param.query.ComProjectGroupQueryVO;
import com.yiboshi.science.service.*;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Service
@AllArgsConstructor
public class ComProjectGroupServiceImpl extends BaseServiceImpl<ComProjectGroupDAO, ComProjectGroupQueryVO, ComProjectGroupDTO, ComProjectGroup> implements ComProjectGroupService {
@Autowired
private ComProjectGroupDAO comProjectGroupDAO;
@Autowired
private ComProjectDAO comProjectDAO;
@Autowired
private ComProjectGroupDetailService comProjectGroupDetailService;
@Autowired
private ComProjectGroupAssignService comProjectGroupAssignService;
@Autowired
private SystemParameterService systemParameterService;
@Autowired
private ComProjectAssignService comProjectAssignService;
@Autowired
private ComBatchService comBatchService;
@Autowired
private ComProjectAuditService comProjectAuditService;
@Override
protected void setCriteriaForQuery(ComProjectGroupQueryVO vo, QueryWrapper<ComProjectGroupQueryVO> criteria) {
if (Objects.nonNull(vo.getGroupYear())) {
criteria.eq("group_year", vo.getGroupYear());
}
if (Objects.nonNull(vo.getGroupName())) {
criteria.like("group_name", vo.getGroupName());
}
if (Objects.nonNull(vo.getKnowledgeId())) {
criteria.eq("knowledge_id", vo.getKnowledgeId());
}
if (Objects.nonNull(vo.getKnowledgeParentId())) {
criteria.eq("e.id", vo.getKnowledgeParentId());
}
if (Objects.nonNull(vo.getAssignState())) {
criteria.eq("assign_state", vo.getAssignState());
}
}
public Pagination<ComProjectGroupDTO> getProjectGroupListByPage(ComProjectGroupQueryVO vo) {
QueryWrapper criteria = new QueryWrapper();
setCriteriaForQuery(vo, criteria);
Page<ComProjectGroupQueryVO> page = new Page<>(vo.getPageIndex(), vo.getPageSize());
List<ComProjectGroupDTO> dtoList = comProjectGroupDAO.getListByPage(page, criteria).getRecords();
if (null != dtoList && dtoList.size() != 0) {
dtoList.forEach((e) -> {
e.setExpertList(comProjectGroupAssignService.getAssignExpertList(e.getId()));
e.setProjectList(comProjectGroupDetailService.getProjectDetailList(e.getId()));
});
}
return new Pagination<>(dtoList, page.getTotal(), vo.getPageSize());
}
private String InsertProjectGroup(int ReportYear, int ProjCount, String ProjGroupName, String KnowledgeId, String Remark) {
ComProjectGroup entity = new ComProjectGroup();
entity.setGroupYear(ReportYear);
entity.setGroupName(ProjGroupName);
entity.setKnowledgeId(KnowledgeId);
entity.setProjCount(ProjCount);
entity.setExpertCount(0);
entity.setRemark(Remark);
entity.setAssignState(0);
return this.insert(entity);
}
private void JoinProjectGroup(String groupId, String projId) {
ComProjectGroupDetailDTO dto = comProjectGroupDetailService.getProjectGroupDetailByGP(groupId, projId);
if (null == dto) {
ComProjectGroupDetail detailEntity = new ComProjectGroupDetail();
detailEntity.setGroupId(groupId);
detailEntity.setProjId(projId);
comProjectGroupDetailService.insert(detailEntity);
}
}
@Transactional
public void processProjectGroup(String ProjectID) {
ComProjectDTO projDTO = comProjectDAO.getById(ProjectID);
if (null == projDTO)
return;
SystemParameter ParaModel = systemParameterService.getParentModelByChildId(projDTO.getKnowledgeId());
ComProjectGroupDTO groupDTO = comProjectGroupDAO.getProjectGroupByKnowLedgeIDYear(projDTO.getReportYear(), ParaModel.getId());
if (null == groupDTO) {
String groupId = InsertProjectGroup(projDTO.getReportYear(), 1, ParaModel.getName() + "项目组-1", ParaModel.getId(), "");
JoinProjectGroup(groupId, projDTO.getId());
} else {
if (groupDTO.getProjCount() < 30) {
groupDTO.setProjCount(groupDTO.getProjCount() + 1);
ComProjectGroup entity = this.convert2Entity(groupDTO);
this.update(entity);
JoinProjectGroup(groupDTO.getId(), projDTO.getId());
if (groupDTO.getExpertCount() > 0) {
List<String> projects = new ArrayList();
projects.add(projDTO.getId());
List<ComProjectGroupAssignDTO> list = comProjectGroupAssignService.getAssignExpertList(groupDTO.getId());
List<String> experts = new ArrayList();
list.forEach(e -> {
experts.add(e.getExpertId());
});
comProjectAssignService.assignProject(projDTO.getReportYear(), projects, experts);
}
} else {
Integer index = groupDTO.getGroupName().indexOf("-");
String strContent = groupDTO.getGroupName().substring(index + 1);
Integer ProjGroupCount = Integer.parseInt(strContent) + 1;
String ProjGroupName = ParaModel.getName() + "项目组-" + ProjGroupCount;
String groupId = InsertProjectGroup(projDTO.getReportYear(), 1, ProjGroupName, ParaModel.getId(), "");
JoinProjectGroup(groupId, projDTO.getId());
}
}
}
public void CalculateGroupProjectCount(String groupId) {
List<ComProjectGroupDetailDTO> list = comProjectGroupDetailService.getProjectDetailList(groupId);
ComProjectGroup model = new ComProjectGroup();
model.setId(groupId);
if (null == list || list.size() == 0)
model.setProjCount(0);
else
model.setProjCount(list.size());
this.update(model);
}
public void CalculateGroupExpertCount(String groupId) {
List<ComProjectGroupAssignDTO> list = comProjectGroupAssignService.getAssignExpertList(groupId);
ComProjectGroup model = new ComProjectGroup();
model.setId(groupId);
if (null == list || list.size() == 0) {
model.setExpertCount(0);
model.setAssignState(0);
}
else {
model.setExpertCount(list.size());
model.setAssignState(1);
}
this.update(model);
}
@Transactional
public boolean addProjectGroupKnowledge(String groupId, List<String> KnowledgeList, ComProjectAuditQueryVO vo) {
List<ComProject> ProjList = new ArrayList<>();
KnowledgeList.forEach(e -> {
vo.setKnowledgeId(e);
vo.setAuditType(1);
List<ComProjectAuditDTO> projList = comProjectAuditService.getAuditProjectList(vo);
if (null != projList && projList.size() > 0) {
projList.forEach(p -> {
ComProject entity = new ComProject();
entity.setId(p.getProjId());
entity.setKnowledgeId(e);
ProjList.add(entity);
});
}
});
if (ProjList.size() > 0) {
ProjList.forEach(e -> {
ComProjectGroupDetail model = new ComProjectGroupDetail();
model.setProjId(e.getId());
model.setKnowledgeId(e.getKnowledgeId());
model.setGroupId(groupId);
comProjectGroupDetailService.insert(model);
});
processGroupProjectExpert(groupId);
CalculateGroupProjectCount(groupId);
return true;
} else return false;
}
@Transactional
public boolean InsertProjectGroup(List<String> IdList, String groupId) {
ComProjectGroupDTO dto = this.getGroupById(groupId);
if (null == dto)
return false;
IdList.forEach(e -> {
ComProjectGroupDetail model = new ComProjectGroupDetail();
model.setProjId(e);
model.setGroupId(groupId);
comProjectGroupDetailService.insert(model);
});
processGroupProjectExpert(groupId);
CalculateGroupProjectCount(groupId);
return true;
}
@Transactional
public boolean updataProjectGroupAdjust(List<String> IdList, String groupId) {
ComProjectGroupDetail entity = comProjectGroupDetailService.entityById(IdList.get(0));
String oldGroupId = entity.getGroupId();
ComProjectGroupDTO dto = this.getGroupById(oldGroupId);
if (null != dto.getExpertCount() && dto.getExpertCount() > 0)
return false;
dto = this.getGroupById(groupId);
if (null != dto.getExpertCount() && dto.getExpertCount() > 0)
return false;
IdList.forEach(e -> {
ComProjectGroupDetail model = new ComProjectGroupDetail();
model.setId(e);
model.setGroupId(groupId);
comProjectGroupDetailService.update(model);
});
CalculateGroupProjectCount(oldGroupId);
CalculateGroupProjectCount(groupId);
CalculateGroupExpertCount(oldGroupId);
CalculateGroupExpertCount(groupId);
return true;
}
public ComProjectGroupDTO getGroupById(String id) {
ComProjectGroup model = this.entityById(id);
ComProjectGroupDTO dto = convert2DTO(model);
dto.setExpertList(comProjectGroupAssignService.getAssignExpertList(dto.getId()));
return dto;
}
@Transactional
public String save(ComProjectGroupDTO group) {
if (null == group.getId()) {
return insertGroup(group);
} else {
return updateGroup(group);
}
}
public String insertGroup(ComProjectGroupDTO group) {
ComProjectGroup model = this.convert2Entity(group);
return this.insert(model);
}
public String updateGroup(ComProjectGroupDTO group) {
ComProjectGroup model = this.convert2Entity(group);
return this.update(model);
}
public String deleteByGroupId(String id) {
this.deleteById(id);
return id;
}
private List<ComProjectAssignDTO> getAssignExpertList(String projectId) {
return comProjectGroupDAO.getAssignExpertList(projectId);
}
@Transactional
public String assignProjectGroup(int projType, List<String> GroupList, List<String> ExpertList) {
GroupList.forEach(g -> {
ExpertList.forEach(e -> {
ComProjectGroupAssign entity = new ComProjectGroupAssign();
entity.setGroupId(g);
entity.setExpertId(e);
if (null == comProjectGroupAssignService.getEntity(entity)) {
entity = new ComProjectGroupAssign();
entity.setGroupId(g);
entity.setExpertId(e);
comProjectGroupAssignService.insert(entity);
}
});
});
List<ComProjectGroupDetailDTO> ProjectInfoList = comProjectGroupDetailService.getProjectListByGroupIds(GroupList);
Integer reportYear = comBatchService.getReportYear(projType);
List<String> ProjectList = new ArrayList<>();
ProjectInfoList.forEach(p -> {
ProjectList.add(p.getProjId());
});
String strContent = comProjectAssignService.assignProject(reportYear, ProjectList, ExpertList);
GroupList.forEach(g -> {
this.CalculateGroupExpertCount(g);
});
return strContent;
}
@Transactional
public String deleteAssignGroupExpert(String id) {
ComProjectGroupAssign comProjectGroupAssign = comProjectGroupAssignService.getById(id);
if (null == comProjectGroupAssign)
throw new BusinessException("分配记录已删除!");
List<ComProjectGroupDetailDTO> projectDetailList = comProjectGroupDetailService.getProjectDetailList(comProjectGroupAssign.getGroupId());
projectDetailList.forEach(e -> {
ComProjectAssign entity = new ComProjectAssign();
entity.setProjId(e.getProjId());
entity.setExpertId(comProjectGroupAssign.getExpertId());
comProjectAssignService.delete(entity);
comProjectAssignService.updateAssignState(e.getProjId());
});
List<ComProjectGroupDTO> list = comProjectAssignService.getProjectGroupAssignById(comProjectGroupAssign.getGroupId(), comProjectGroupAssign.getExpertId());
if (null != list && list.size() > 0) {
list.forEach(e -> {
this.deleteById(e.getAssignId());
});
}
comProjectGroupAssignService.deleteById(id);
this.CalculateGroupExpertCount(comProjectGroupAssign.getGroupId());
return id;
}
@Transactional
public boolean deleteProjectGroupKnowledge(String groupId, String knowledgeId) {
ComProjectGroupDTO dto = getGroupById(groupId);
if (null == dto)
return false;
List<ComProjectGroupAssignDTO> expertDetailList = comProjectGroupAssignService.getAssignExpertList(groupId);
//判断是否分配了专家(分配了专家的项目组不能移除项目)
if (null != expertDetailList && expertDetailList.size() > 0)
return false;
List<ComProjectGroupDetailDTO> projectDetailList = comProjectGroupDetailService.getProjectDetailList(groupId);
projectDetailList.forEach(e -> {
if (e.getKnowledgeId().equals(knowledgeId))
comProjectGroupDetailService.deleteById(e.getId());
});
this.CalculateGroupProjectCount(groupId);
return true;
}
@Transactional
public boolean deleteProjectGroupDetail(String groupId, String knowledgeId) {
ComProjectGroupDTO dto = getGroupById(groupId);
if (null == dto)
return false;
List<ComProjectGroupAssignDTO> expertDetailList = comProjectGroupAssignService.getAssignExpertList(groupId);
//判断是否分配了专家(分配了专家的项目组不能移除项目)
if (null != expertDetailList && expertDetailList.size() > 0)
return false;
List<ComProjectGroupDetailDTO> projectDetailList = comProjectGroupDetailService.getProjectDetailList2(groupId);
projectDetailList.forEach(e -> {
if (e.getKnowledgeId().equals(knowledgeId))
comProjectGroupDetailService.deleteById(e.getId());
});
this.CalculateGroupProjectCount(groupId);
return true;
}
@Transactional
public boolean deleteGroupProjectExpert(String groupId, String projId) {
ComProjectGroupDTO dto = getGroupById(groupId);
if (null == dto)
return false;
List<ComProjectGroupDetailDTO> projectDetailList = comProjectGroupDetailService.getProjectDetailList(groupId);
List<ComProjectGroupAssignDTO> expertDetailList = comProjectGroupAssignService.getAssignExpertList(groupId);
if (null == projectDetailList || projectDetailList.size() == 0)
return false;
//判断是否分配了专家(分配了专家的项目不能移除)
if (null != expertDetailList && expertDetailList.size() > 0)
return false;
projectDetailList.forEach(e -> {
if (e.getGroupId().equals(groupId) && e.getProjId().equals(projId)) {
comProjectGroupDetailService.deleteById(e.getId());
comProjectAssignService.updateAssignState(projId);
}
});
expertDetailList.forEach(e -> {
ComProjectAssign entity = new ComProjectAssign();
entity.setExpertId(e.getExpertId());
entity.setProjId(projId);
comProjectAssignService.delete(entity);
});
this.CalculateGroupProjectCount(groupId);
this.CalculateGroupExpertCount(groupId);
return true;
}
/**
* 项目专家分配
* @param groupId
* @return
*/
@Transactional
public void processGroupProjectExpert(String groupId) {
ComProjectGroupDTO dto = getGroupById(groupId);
if (null == dto)
return;
List<ComProjectGroupDetailDTO> projectDetailList = comProjectGroupDetailService.getProjectDetailList(groupId);
List<ComProjectGroupAssignDTO> expertDetailList = comProjectGroupAssignService.getAssignExpertList(groupId);
if (null == projectDetailList || projectDetailList.size() == 0)
return;
if (null == expertDetailList || expertDetailList.size() == 0)
return;
projectDetailList.forEach(e -> {
expertDetailList.forEach(p -> {
ComProjectAssign entity = new ComProjectAssign();
entity.setProjId(e.getProjId());
entity.setExpertId(p.getExpertId());
List<ComProjectAssign> list = comProjectAssignService.entityList(entity);
if (null == list || list.size() == 0) {
ComProjectAssign assign = new ComProjectAssign();
assign.setProjId(e.getProjId());
assign.setExpertId(p.getExpertId());
assign.setAssignYear(dto.getGroupYear());
comProjectAssignService.insert(assign);
comProjectAssignService.updateAssignState(e.getProjId());
}
});
});
}
/**
* 项目二级学科统计
* @param groupId
* @return
*/
public List<ComProjectKnowledgeStatisticDTO> getProjectKnowledgeStatisticByGroupId(String groupId) {
List<ComProjectKnowledgeStatisticDTO> list = comProjectGroupDAO.getProjectKnowledgeStatisticByGroupId(groupId);
return list;
}
}