MatchDictServiceImpl.java
9.52 KB
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
package com.zhongzhi.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhongzhi.common.constant.ProjectType;
import com.zhongzhi.common.utils.DateFormatUtil;
import com.zhongzhi.common.utils.ExcelUtil;
import com.zhongzhi.dto.match.MatchDictDTO;
import com.zhongzhi.dto.match.SelectListPageDTO;
import com.zhongzhi.dto.project.ProjectSummaryDTO;
import com.zhongzhi.model.MatchDictDO;
import com.zhongzhi.dao.MatchDictDAO;
import com.zhongzhi.model.MatchScheduleDO;
import com.zhongzhi.service.MatchDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongzhi.service.MatchScheduleService;
import com.zhongzhi.vo.match.MatchDictVO;
import com.zhongzhi.vo.match.ProjectSummaryVO;
import org.springframework.beans.BeanUtils;
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;
/**
* <p>
* 赛事年份管理 服务实现类
* </p>
*
* @author DengMin
* @since 2021-05-17
*/
@Service
public class MatchDictServiceImpl extends ServiceImpl<MatchDictDAO, MatchDictDO> implements MatchDictService {
@Autowired
private MatchScheduleService matchScheduleService;
@Override
public MatchDictDO getMainTrackMatch() {
return this.baseMapper.selectOne(new QueryWrapper<MatchDictDO>()
.lambda()
.eq(MatchDictDO::getMatchType, ProjectType.MAIN_TRACK)
.eq(MatchDictDO::getStatus, 1));
}
@Override
public MatchDictDO getSeedTrackMatch() {
return this.baseMapper.selectOne(new QueryWrapper<MatchDictDO>()
.lambda()
.eq(MatchDictDO::getMatchType, ProjectType.SEED_TRACK)
.eq(MatchDictDO::getStatus, 1));
}
@Override
public void updateMatch(MatchDictDTO matchDictDTO) {
MatchDictDO matchDict = this.baseMapper.selectById(matchDictDTO.getId());
MatchDictDO match = this.baseMapper.selectOne(new QueryWrapper<MatchDictDO>()
.lambda()
.eq(MatchDictDO::getMatchType, matchDict.getMatchType())
.eq(MatchDictDO::getStatus, 1));
if (matchDictDTO.getStatus() != null) {
if (match != null && !match.getId().equals(matchDictDTO.getId())) {
match.setStatus(0);
this.baseMapper.updateById(match);
}
}
MatchDictDO matchDictDO = new MatchDictDO();
BeanUtils.copyProperties(matchDictDTO, matchDictDO);
this.baseMapper.updateById(matchDictDO);
if (matchDictDTO.getSchedule() != null && matchDictDTO.getSchedule().size() > 0) {
List<MatchScheduleDO> list = matchScheduleService.list(new QueryWrapper<MatchScheduleDO>()
.lambda()
.eq(MatchScheduleDO::getMatchId, matchDictDTO.getId()));
if (list.size() > 0) {
for (MatchScheduleDO matchScheduleDO : list) {
if (matchDictDTO.getSchedule().stream().filter(ms -> ms.getScheduleTime().equals(matchScheduleDO.getScheduleTime()) &&
ms.getExplains().equals(matchScheduleDO.getExplains())).findAny().isPresent()) {
continue;
} else {
matchScheduleService.removeById(matchScheduleDO.getId());
}
}
}
for (MatchScheduleDO matchScheduleDO : matchDictDTO.getSchedule()) {
if (list.stream().filter(ms -> ms.getExplains().equals(matchScheduleDO.getExplains()) &&
DateFormatUtil.format(ms.getScheduleTime(), DateFormatUtil.FMT_sdf_yMd).equals(DateFormatUtil.format(matchScheduleDO.getScheduleTime(), DateFormatUtil.FMT_sdf_yMd))).findAny().isPresent()) {
MatchScheduleDO matchSchedule = matchScheduleService.getOne(new QueryWrapper<MatchScheduleDO>()
.lambda()
.eq(MatchScheduleDO::getMatchId, matchScheduleDO.getMatchId())
.eq(MatchScheduleDO::getExplains, matchScheduleDO.getExplains())
.eq(MatchScheduleDO::getScheduleTime, DateFormatUtil.format(matchScheduleDO.getScheduleTime(), DateFormatUtil.FMT_sdf_yMd)));
if (matchSchedule != null) {
matchScheduleDO.setId(matchSchedule.getId());
matchScheduleService.updateById(matchScheduleDO);
}
} else {
matchScheduleDO.setMatchId(matchDictDTO.getId());
matchScheduleService.save(matchScheduleDO);
}
}
}
}
@Override
public IPage<MatchDictVO> getSeedTrackMatchPage(SelectListPageDTO selectListPageDTO) {
Page page = new Page(selectListPageDTO.getPageNo(), selectListPageDTO.getPageSize());
IPage<MatchDictVO> iPage = this.baseMapper.getSeedTrackMatchPage(page);
for (MatchDictVO record : iPage.getRecords()) {
List<MatchScheduleDO> list = matchScheduleService.list(new QueryWrapper<MatchScheduleDO>()
.lambda()
.eq(MatchScheduleDO::getMatchId, record.getId()));
record.setSchedule(list);
}
return iPage;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void createMatch(MatchDictDTO matchDictDTO) {
MatchDictDO matchDictDO = new MatchDictDO();
BeanUtils.copyProperties(matchDictDTO, matchDictDO);
this.baseMapper.insert(matchDictDO);
}
@Override
public List<MatchDictDO> getMatch() {
return this.baseMapper.selectList(new QueryWrapper<MatchDictDO>()
.lambda()
.eq(MatchDictDO::getStatus, 1));
}
@Override
public MatchDictDO getVocationalMatch() {
return this.baseMapper.selectOne(new QueryWrapper<MatchDictDO>()
.lambda()
.eq(MatchDictDO::getStatus, 1));
}
public void updateMatchDate(MatchDictDO matchDictDO) {
this.baseMapper.updateById(matchDictDO);
}
public MatchDictDO getMatch(MatchDictDO matchDictDO) {
return this.baseMapper.selectById(matchDictDO.getId());
}
@Override
public List<ProjectSummaryVO> projectSummary(ProjectSummaryDTO projectSummaryDTO) {
// ===================== 1. 固定顺序(必须和图2一致)=====================
List<String> ALL_COLLEGES = Arrays.asList(
"会计学院",
"金融学院",
"工商管理学院",
"国际经贸学院",
"财税与公共管理学院",
"统计与数学学院",
"计算机与人工智能学院",
"外国语学院",
"保险学院",
"法学院",
"金融科技学院",
"人文艺术学院",
"序伦书院"
);
List<ProjectSummaryVO> projectSummaryVOS = this.baseMapper.projectSummary(projectSummaryDTO.getMatchId(), projectSummaryDTO.getStartDate(), projectSummaryDTO.getEndDate());
// ===================== 3. 关键代码:补全所有学院,没有数据则为0 =====================
// 把SQL结果转成 Map<学院名, 数据>,方便快速查找
Map<String, ProjectSummaryVO> dataMap = projectSummaryVOS.stream()
.collect(Collectors.toMap(ProjectSummaryVO::getXueyuan, d -> d));
// 遍历固定顺序列表 → 有数据用数据,没数据补0
List<ProjectSummaryVO> finalResult = ALL_COLLEGES.stream()
.map(college -> {
ProjectSummaryVO data = dataMap.get(college);
if (data != null) {
return data;
} else {
// 没有数据 → 构造 0 值对象
return new ProjectSummaryVO(college, 0, 0);
}
})
.collect(Collectors.toList());
int i = 1;
String[] split = "159,114,62,72,89,59,93,33,37,34,36,8,4".split(",");
for (ProjectSummaryVO projectSummaryVO : finalResult){
projectSummaryVO.setFixCnt(Integer.valueOf(split[i-1]));
projectSummaryVO.setId(i ++);
}
return finalResult;
}
@Override
public void exportProjectSummary(ProjectSummaryDTO projectSummaryDTO) {
List<ProjectSummaryVO> projectSummaryVOS = projectSummary(projectSummaryDTO);
ExcelUtil.writeExcel(projectSummaryVOS,ProjectSummaryVO.class);
}
@Override
public List<MatchDictDO> getList(String projectType, String projectGroup) {
return this.baseMapper.getList(projectType, projectGroup);
}
@Override
public IPage getVocationalPage(SelectListPageDTO selectListPageDTO) {
Page page = new Page(selectListPageDTO.getPageNo(), selectListPageDTO.getPageSize());
IPage<MatchDictVO> iPage = this.baseMapper.getSeedTrackMatchPage(page);
// for (MatchDictVO record : iPage.getRecords()) {
// List<MatchScheduleDO> list = matchScheduleService.list(new QueryWrapper<MatchScheduleDO>()
// .lambda()
// .eq(MatchScheduleDO::getMatchId, record.getId()));
// record.setSchedule(list);
// }
return iPage;
}
}