ChildTaskPlanServiceImpl.java
4.99 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
package com.bsth.service.realcontrol.impl;
import com.bsth.common.ResponseCode;
import com.bsth.data.BasicData;
import com.bsth.data.Station2ParkBuffer;
import com.bsth.data.schedule.DayOfSchedule;
import com.bsth.entity.realcontrol.ChildTaskPlan;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.repository.realcontrol.ChildTaskPlanRepository;
import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
import com.bsth.service.impl.BaseServiceImpl;
import com.bsth.service.realcontrol.ChildTaskPlanService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.HashMap;
import java.util.Map;
@Service
public class ChildTaskPlanServiceImpl extends BaseServiceImpl<ChildTaskPlan, Long> implements ChildTaskPlanService {
@Autowired
ScheduleRealInfoRepository scheduleRealInfoRepository;
@Autowired
ChildTaskPlanRepository childTaskPlanRepository;
@Autowired
DayOfSchedule dayOfSchedule;
@Autowired
JdbcTemplate jdbcTemplate;
Logger logger = LoggerFactory.getLogger(this.getClass());
@Transactional
@Override
public Map<String, Object> save(ChildTaskPlan t) {
Map<String, Object> rs = new HashMap();
try {
ScheduleRealInfo sch = dayOfSchedule.get(t.getSchedule().getId());
//保存起终点名称
//String prefix = sch.getXlBm() + "_" + sch.getXlDir() + "_";
if(StringUtils.isEmpty(t.getStartStationName()))
t.setStartStationName(getStationName(sch.getXlBm(), t.getStartStation()));
//t.setStartStationName(BasicData.getStationNameByCode(t.getStartStation(), prefix));
if(StringUtils.isEmpty(t.getEndStationName()))
t.setEndStationName(getStationName(sch.getXlBm(), t.getEndStation()));
//t.setEndStationName(BasicData.getStationNameByCode(t.getEndStation(), prefix));
if(t.getDestroyReason() == null)
t.setDestroyReason("");
//烂班说明,为兼容之前的数据结构
if(t.isDestroy() && StringUtils.isEmpty(t.getDestroyReason()))
t.setDestroyReason(t.getReason());
//先持久化子任务
rs = super.save(t);
//关联主任务
sch.getcTasks().add(t);
dayOfSchedule.save(sch);
//直接持久化
//scheduleRealInfoRepository.save(sch);
//站到场对照
t.setSchedule(sch);
Station2ParkBuffer.put(t);
rs.put("status", ResponseCode.SUCCESS);
rs.put("t", sch);
}catch (Exception e){
logger.error("", e);
rs.put("status", ResponseCode.ERROR);
rs.put("msg", e.getMessage());
}
return rs;
}
private String getStationName(String lineCode, String stationCode){
String name;
String prefix1 = lineCode + "_" + 0 + "_",
prefix2 = lineCode + "_" + 1 + "_";
name = BasicData.getStationNameByCode(stationCode, prefix1);
if(StringUtils.isEmpty(name))
name = BasicData.getStationNameByCode(stationCode, prefix2);
return name;
}
@Override
public Map<String, Object> delete(Long id) {
Map<String, Object> rs;
ChildTaskPlan cPlan = childTaskPlanRepository.findOne(id);
//删除子任务
rs = super.delete(id);
//dayOfSchedule.save(sch);
//解除和主任务关联
ScheduleRealInfo sch = dayOfSchedule.get(cPlan.getSchedule().getId());
sch.getcTasks().remove(cPlan);
rs.put("t", sch);
return rs;
}
@Override
public Map<String, Object> saveHistory(ChildTaskPlan t) {
Map<String, Object> rs = new HashMap();
try {
ScheduleRealInfo sch = t.getSchedule();
//保存起终点名称
String prefix = sch.getXlBm() + "_" + sch.getXlDir() + "_";
if(StringUtils.isEmpty(t.getStartStationName()))
t.setStartStationName(BasicData.getStationNameByCode(t.getStartStation(), prefix));
if(StringUtils.isEmpty(t.getEndStationName()))
t.setEndStationName(BasicData.getStationNameByCode(t.getEndStation(), prefix));
//先持久化子任务
rs = super.save(t);
rs.put("status", ResponseCode.SUCCESS);
}catch (Exception e){
logger.error("", e);
rs.put("status", ResponseCode.ERROR);
rs.put("msg", e.getMessage());
}
return rs;
}
@Override
public Map<String, Object> delHistory(Long id) {
return super.delete(id);
}
}