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.yiboshi.science.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yiboshi.science.base.BaseServiceImpl;
import com.yiboshi.science.base.Pagination;
import com.yiboshi.science.dao.ComExpertGroupDAO;
import com.yiboshi.science.entity.ComExpertGroup;
import com.yiboshi.science.param.dto.ComExpertGroupDTO;
import com.yiboshi.science.param.query.ComExpertGroupQueryVO;
import com.yiboshi.science.service.ComExpertGroupMembersService;
import com.yiboshi.science.service.ComExpertGroupService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import static java.util.Objects.isNull;
@Service
@AllArgsConstructor
public class ComExpertGroupServiceImpl extends BaseServiceImpl<ComExpertGroupDAO, ComExpertGroupQueryVO, ComExpertGroupDTO, ComExpertGroup> implements ComExpertGroupService {
@Autowired
private ComExpertGroupDAO comExpertGroupDAO;
@Autowired
private ComExpertGroupMembersService comExpertGroupMembersService;
@Override
protected void setCriteriaForQuery(ComExpertGroupQueryVO vo, QueryWrapper<ComExpertGroupQueryVO> criteria) {
if (Objects.nonNull(vo.getName())) {
criteria.like("a.name", vo.getName());
}
if (Objects.nonNull(vo.getYear())) {
criteria.eq("b.year", vo.getYear());
}
if (Objects.nonNull(vo.getBatch())) {
criteria.eq("b.batch", vo.getBatch());
}
}
@Override
protected void setCriteriaOrder(QueryWrapper<ComExpertGroup> criteria){
criteria.orderByAsc("created");
}
@Override
public Pagination<ComExpertGroupDTO> getListByPage(ComExpertGroupQueryVO vo) {
QueryWrapper criteria = new QueryWrapper();
setCriteriaForQuery(vo, criteria);
Page<ComExpertGroupQueryVO> page = new Page<>(vo.getPageIndex(), vo.getPageSize());
List<ComExpertGroupDTO> dtoList = comExpertGroupDAO.getListByPage(page, criteria).getRecords();
return new Pagination<>(dtoList, page.getTotal(), vo.getPageSize());
}
@Transactional
public void insertOrUpdateGroupList(List<ComExpertGroupDTO> expertGroup, String batchId) {
ComExpertGroup comExpertGroup = new ComExpertGroup();
comExpertGroup.setBatchId(batchId);
final List<ComExpertGroup>[] list = new List[]{this.entityList(comExpertGroup)};
expertGroup.forEach((e) -> {
String groupId = "";
ComExpertGroup ComExpertGroup = convert2Entity(e);
if (Objects.nonNull(e.getId())) {
groupId = this.update(ComExpertGroup);
if (null != list[0] && list[0].size() > 0) {
list[0] = list[0].stream().filter(f -> !f.getId().equals(e.getId())).collect(Collectors.toList());
}
} else {
ComExpertGroup.setBatchId(batchId);
groupId = this.insert(ComExpertGroup);
}
if (Objects.nonNull(e.getMembers()) && e.getMembers().size() > 0) {
comExpertGroupMembersService.insertMemberList(e.getMembers(), groupId);
}
});
if (null != list[0] && list[0].size() > 0) {
list[0].forEach((e) -> {
comExpertGroupMembersService.deleteByGroupId(e.getId());
});
}
}
public List<ComExpertGroupDTO> getExpertGroupListByBatchId(String batchId) {
ComExpertGroup comExpertGroup = new ComExpertGroup();
comExpertGroup.setBatchId(batchId);
List<ComExpertGroupDTO> list = this.dtoList(comExpertGroup);;
if (null != list && list.size() > 0) {
list.forEach((e) -> {
if (!isNull(e)) {
e.setMembers(comExpertGroupMembersService.getExpertIdListByGroupId(e.getId()));
}
});
}
return list;
}
public List<ComExpertGroupDTO> getExpertGroupList() {
ComExpertGroup entity = new ComExpertGroup();
return this.dtoList(entity);
}
}