MatchDictServiceImpl.java
7.51 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
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.dto.match.MatchDictDTO;
import com.zhongzhi.dto.match.SelectListPageDTO;
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 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.List;
/**
* <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, ProjectType.SEED_TRACK);
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);
if (matchDictDTO.getSchedule().size() > 0) {
for (MatchScheduleDO matchScheduleDO : matchDictDTO.getSchedule()) {
MatchScheduleDO matchSchedule = new MatchScheduleDO();
BeanUtils.copyProperties(matchScheduleDO, matchSchedule);
matchSchedule.setMatchId(matchDictDO.getId());
matchScheduleService.save(matchSchedule);
}
}
}
@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)
.eq(MatchDictDO::getMatchType, ProjectType.VOCATIONAL));
}
public void updateMatchDate(MatchDictDO matchDictDO) {
this.baseMapper.updateById(matchDictDO);
}
public MatchDictDO getMatch(MatchDictDO matchDictDO) {
return this.baseMapper.selectById(matchDictDO.getId());
}
@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, ProjectType.VOCATIONAL);
for (MatchDictVO record : iPage.getRecords()) {
List<MatchScheduleDO> list = matchScheduleService.list(new QueryWrapper<MatchScheduleDO>()
.lambda()
.eq(MatchScheduleDO::getMatchId, record.getId()));
record.setSchedule(list);
}
return iPage;
}
}