ChildTaskPlanServiceImpl.java
3.08 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
package com.bsth.service.realcontrol.impl;
import com.bsth.common.ResponseCode;
import com.bsth.data.BasicData;
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(BasicData.getStationNameByCode(t.getStartStation(), prefix));
if(StringUtils.isEmpty(t.getEndStationName()))
t.setEndStationName(BasicData.getStationNameByCode(t.getEndStation(), prefix));
//先持久化子任务
rs = super.save(t);
//关联主任务
System.out.println("schschsch: " + sch);
System.out.println("sch.getcTasks()sch.getcTasks(): " + sch.getcTasks());
sch.getcTasks().add(t);
dayOfSchedule.save(sch);
//直接持久化
//scheduleRealInfoRepository.save(sch);
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;
}
@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;
}
}