TTInfoServiceImpl.java
3.9 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
package com.bsth.service.schedule.impl;
import com.bsth.entity.schedule.TTInfo;
import com.bsth.service.schedule.ScheduleException;
import com.bsth.service.schedule.TTInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by xu on 16/12/20.
*/
@Service
public class TTInfoServiceImpl extends BServiceImpl<TTInfo, Long> implements TTInfoService {
@Override
public void validate_name(TTInfo ttInfo) throws ScheduleException {
// 名字重复验证
Map<String, Object> param = new HashMap<>();
if (ttInfo.getId() != null) {
param.put("id_ne", ttInfo.getId());
}
param.put("xl.id_eq", ttInfo.getXl().getId());
param.put("name_eq", ttInfo.getName());
if (!CollectionUtils.isEmpty(list(param))) {
throw new ScheduleException("名字重复");
}
}
@Override
public void validate_n_d(TTInfo ttInfo) throws ScheduleException {
// 常规有效日重复验证
// 找出所有未作废,已启用的时刻表,验证
Map<String, Object> param = new HashMap<>();
if (ttInfo.getId() != null) {
param.put("id_ne", ttInfo.getId());
}
param.put("xl.id_eq", ttInfo.getXl().getId());
param.put("isCancel_eq", false);
param.put("isEnableDisTemplate_eq", true);
List<TTInfo> ttInfos = list(param);
if (StringUtils.isEmpty(ttInfo.getRule_days())) {
throw new ScheduleException("常规有效日为空");
} else {
String[] nds = ttInfo.getRule_days().split(",");
for (TTInfo t : ttInfos) {
String[] nds_e = t.getRule_days().split(",");
for (int i = 0; i < 7; i++) {
if ("0".equals(nds[i])) {
//
} else {
if (nds[i].equals(nds_e[i])) {
throw new ScheduleException("当前常规有效日期已经使用");
}
}
}
}
}
}
@Override
public void validate_s_d(TTInfo ttInfo) throws ScheduleException {
// 特殊有效日重复验证
// 找出所有未作废,已启用的时刻表,验证
Map<String, Object> param = new HashMap<>();
if (ttInfo.getId() != null) {
param.put("id_ne", ttInfo.getId());
}
param.put("xl.id_eq", ttInfo.getXl().getId());
param.put("isCancel_eq", false);
param.put("isEnableDisTemplate_eq", true);
List<TTInfo> ttInfos = list(param);
if (StringUtils.isEmpty(ttInfo.getSpecial_days())) {
//
} else {
String[] sds = ttInfo.getSpecial_days().split(",");
for (TTInfo t : ttInfos) {
if (StringUtils.isEmpty(t.getSpecial_days())) {
//
} else {
for (String sd : sds) {
if (t.getSpecial_days().indexOf(sd) != -1) {
throw new ScheduleException("当前特殊日期已经使用");
}
}
}
}
}
}
@Transactional
@Override
public void delete(Long aLong) throws ScheduleException {
toggleCancel(aLong);
}
@Transactional
@Override
public void toggleCancel(Long id) throws ScheduleException {
TTInfo ttInfo = findById(id);
if (ttInfo.getIsCancel()) {
ttInfo.setIsCancel(false);
} else {
ttInfo.setIsCancel(true);
}
}
}