GuideboardInfoServiceImpl.java
3.68 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
package com.bsth.service.schedule.impl;
import com.bsth.entity.schedule.GuideboardInfo;
import com.bsth.entity.schedule.TTInfoDetail;
import com.bsth.service.schedule.GuideboardInfoService;
import com.bsth.service.schedule.ScheduleException;
import com.bsth.service.schedule.TTInfoDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.transaction.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 路牌信息服务。
*/
@Service
public class GuideboardInfoServiceImpl extends BServiceImpl<GuideboardInfo, Long> implements GuideboardInfoService {
@Autowired
private TTInfoDetailService ttInfoDetailService;
@Override
public void validate_lpno(GuideboardInfo guideboardInfo) throws ScheduleException {
// 查询条件
Map<String, Object> param = new HashMap<>();
if (guideboardInfo.getId() != null) {
param.put("id_ne", guideboardInfo.getId());
}
if (guideboardInfo.getXl() == null || guideboardInfo.getXl().getId() == null) {
throw new ScheduleException("线路未选择");
} else {
param.put("isCancel_eq", false); // 作废的也算入判定区
param.put("xl.id_eq", guideboardInfo.getXl().getId());
param.put("lpNo_eq", guideboardInfo.getLpNo());
if (!CollectionUtils.isEmpty(list(param))) {
throw new ScheduleException("路牌编号重复");
}
}
}
@Override
public void validate_lpname(GuideboardInfo guideboardInfo) throws ScheduleException {
// 查询条件
Map<String, Object> param = new HashMap<>();
if (guideboardInfo.getId() != null) {
param.put("id_ne", guideboardInfo.getId());
}
if (guideboardInfo.getXl() == null || guideboardInfo.getXl().getId() == null) {
throw new ScheduleException("线路未选择");
} else {
param.put("isCancel_eq", false); // 作废的也算入判定区
param.put("xl.id_eq", guideboardInfo.getXl().getId());
param.put("lpName_eq", guideboardInfo.getLpName());
if (!CollectionUtils.isEmpty(list(param))) {
throw new ScheduleException("路牌名字重复");
}
}
}
@Transactional
@Override
public void delete(Long aLong) throws ScheduleException {
// 删除操作就是作废操作
toggleCancel(aLong);
}
// 作废方法
@Transactional
public void toggleCancel(Long id) throws ScheduleException {
GuideboardInfo guideboardInfo = findById(id);
Map<String, Object> param = new HashMap<>();
if (guideboardInfo.getIsCancel()) {
validate_lpno(guideboardInfo);
validate_lpname(guideboardInfo);
guideboardInfo.setIsCancel(false);
} else {
param.clear();
param.put("xl.id_eq", guideboardInfo.getXl().getId());
param.put("ttinfo.isCancel_eq", false);
param.put("lp.id_eq", guideboardInfo.getId());
List<TTInfoDetail> ttInfoDetailList = (List<TTInfoDetail>) ttInfoDetailService.list(param);
if (CollectionUtils.isEmpty(ttInfoDetailList)) {
guideboardInfo.setIsCancel(true);
} else {
throw new ScheduleException("在时刻表" +
ttInfoDetailList.get(0).getTtinfo().getName() +
"已使用,无法作废!");
}
}
}
}