RuleSchedulingServiceImpl.java
7.61 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
package com.ruoyi.scheduling.service.impl;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollectionUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.pojo.dto.RuleSchedulingDto;
import com.ruoyi.pojo.vo.RuleSchedulingResponseVo;
import com.ruoyi.pojo.vo.RuleSchedulingVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.scheduling.mapper.RuleSchedulingMapper;
import com.ruoyi.scheduling.domain.RuleScheduling;
import com.ruoyi.scheduling.service.IRuleSchedulingService;
import static com.ruoyi.common.RuleSchedulingProperties.*;
import static com.ruoyi.common.WeekEnum.FREE;
/**
* 排版规则Service业务层处理
*
* @author guzijian
* @date 2023-08-04
*/
@Service
public class RuleSchedulingServiceImpl implements IRuleSchedulingService {
@Autowired
private RuleSchedulingMapper ruleSchedulingMapper;
/**
* 查询排版规则
*
* @param id 排版规则主键
* @return 排版规则
*/
@Override
public RuleScheduling selectRuleSchedulingById(Long id) {
return ruleSchedulingMapper.selectRuleSchedulingById(id);
}
/**
* 查询排版规则列表
*
* @param ruleScheduling 排版规则
* @return 排版规则
*/
@Override
public List<RuleScheduling> selectRuleSchedulingList(RuleScheduling ruleScheduling) {
return ruleSchedulingMapper.selectRuleSchedulingList(ruleScheduling);
}
/**
* 新增排版规则
*
* @param ruleScheduling 排版规则
* @return 结果
*/
@Override
public int insertRuleScheduling(RuleScheduling ruleScheduling) {
handleNewAddScheduling(ruleScheduling);
String username = SecurityUtils.getUsername();
ruleScheduling.setCreateBy(username);
ruleScheduling.setUpdateBy(username);
Date date = DateUtils.getNowDate();
ruleScheduling.setCreateTime(date);
ruleScheduling.setUpdateTime(date);
return ruleSchedulingMapper.insertRuleScheduling(ruleScheduling);
}
private void handleNewAddScheduling(RuleScheduling ruleScheduling) {
// 如果没有分班则重置第一段后的规则
if (NO_SEGMENTATION.equals(ruleScheduling.getSecondFlag())){
ruleScheduling.setSecondSignDayTomorrow(null);
ruleScheduling.setSecondSignInWorkingRange(null);
ruleScheduling.setSecondWorkSignInTime(null);
ruleScheduling.setSecondQuittingSignInTime(null);
ruleScheduling.setSecondSignInQuittingRange(null);
}
}
/**
* 修改排版规则
*
* @param ruleScheduling 排版规则
* @return 结果
*/
@Override
public int updateRuleScheduling(RuleScheduling ruleScheduling) {
handleNewAddScheduling(ruleScheduling);
ruleScheduling.setUpdateTime(DateUtils.getNowDate());
ruleScheduling.setUpdateBy(SecurityUtils.getUsername());
return ruleSchedulingMapper.updateRuleScheduling(ruleScheduling);
}
/**
* 批量删除排版规则
*
* @param ids 需要删除的排版规则主键
* @return 结果
*/
@Override
public int deleteRuleSchedulingByIds(Long[] ids) {
return ruleSchedulingMapper.deleteRuleSchedulingByIds(ids);
}
/**
* 删除排版规则信息
*
* @param id 排版规则主键
* @return 结果
*/
@Override
public int deleteRuleSchedulingById(Long id) {
return ruleSchedulingMapper.deleteRuleSchedulingById(id);
}
@Override
public List<RuleSchedulingVo> selectRuleSchedulingListVo(RuleScheduling ruleScheduling) {
List<RuleScheduling> list = ruleSchedulingMapper.selectRuleSchedulingList(ruleScheduling);
return handleRuleScheduling(list);
}
@Override
public List<RuleSchedulingResponseVo> handleResponseRuleSchedulingList(List<RuleScheduling> list) {
return list.stream()
.map(item -> {
RuleSchedulingResponseVo vo = new RuleSchedulingResponseVo();
BeanUtils.copyProperties(item, vo);
vo.setRangeTime(handleRuleSchedulingRangeTime(item));
return vo;
})
.collect(Collectors.toList());
}
@Override
public List<RuleSchedulingVo> selectRuleSchedulingListVoBySettingId(Integer settingId) {
List<RuleScheduling> list = ruleSchedulingMapper.selectRuleSchedulingListVoBySettingId(settingId);
return handleRuleScheduling(list);
}
@Override
public List<RuleSchedulingDto> selectRuleSchedulingListVoBySettingIds(List<Integer> settingList) {
if (CollectionUtil.isEmpty(settingList)){
return new ArrayList<>();
}
return ruleSchedulingMapper.selectRuleSchedulingListVoBySettingIds(settingList);
}
public static List<RuleSchedulingVo> handleRuleScheduling(List<RuleScheduling> list) {
if (CollectionUtil.isEmpty(list)) {
return null;
}
// 处理返回数据
return list
.stream()
.map(item -> {
RuleSchedulingVo vo = new RuleSchedulingVo();
vo.setRuleName(item.getRuleName());
vo.setId(item.getId());
if (item.getRuleName().equals(FREE.getDescription())){
return vo;
}
vo.setRangeTime(handleRuleSchedulingRangeTime(item));
return vo;
})
.collect(Collectors.toList());
}
public static String handleRuleSchedulingRangeTime(RuleScheduling item) {
// 处理存在分段的数据
if (HAVE_SEGMENTATION.equals(item.getSecondFlag())) {
return handleSegmentation(item);
}
// 处理不存在分段的数据
else {
return handleNoSegmentation(item);
}
}
private static String handleNoSegmentation(RuleScheduling item) {
// 处理不隔天的情况
if (TOMORROW_NO.equals(item.getFirstSignInDayTomorrow())) {
return transformTimeType(item.getFirstWorkSignInTime()) + TOMORROW_NO_STRING + transformTimeType(item.getFirstQuittingSignInTime());
}
// 隔天
else {
return transformTimeType(item.getFirstWorkSignInTime()) + TOMORROW_YES_STRING + transformTimeType(item.getFirstQuittingSignInTime());
}
}
private static String handleSegmentation(RuleScheduling item) {
// 隔天
String firstRangeTimeString = handleNoSegmentation(item);
String secondRangeTimeString = handleHaveSegmentation(item);
return firstRangeTimeString + ";" + secondRangeTimeString;
}
private static String handleHaveSegmentation(RuleScheduling item) {
// 处理不隔天的情况
if (TOMORROW_NO.equals(item.getSecondSignDayTomorrow())) {
return transformTimeType(item.getSecondWorkSignInTime()) + TOMORROW_NO_STRING + transformTimeType(item.getSecondQuittingSignInTime());
}
// 隔天
else {
return transformTimeType(item.getSecondWorkSignInTime()) + TOMORROW_YES_STRING + transformTimeType(item.getSecondQuittingSignInTime());
}
}
private static String transformTimeType(Date time) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
return simpleDateFormat.format(time);
}
}