ChildTaskPlanServiceImpl.java
2.67 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
package com.bsth.service.realcontrol.impl;
import com.bsth.data.BasicData;
import com.bsth.data.match.Arrival2Schedule;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.Map;
@Service
public class ChildTaskPlanServiceImpl extends BaseServiceImpl<ChildTaskPlan, Long> implements ChildTaskPlanService {
/*@Autowired
ScheduleRealInfoServiceImpl scheduleRealInfoService;*/
@Autowired
ScheduleRealInfoRepository scheduleRealInfoRepository;
@Autowired
ChildTaskPlanRepository childTaskPlanRepository;
@Autowired
DayOfSchedule dayOfSchedule;
@Autowired
Arrival2Schedule arrival2Schedule;
@Autowired
JdbcTemplate jdbcTemplate;
@Transactional
@Override
public Map<String, Object> save(ChildTaskPlan t) {
ScheduleRealInfo sch = dayOfSchedule.get(t.getSchedule().getId());
Map<String, Object> rs;
//保存起终点名称
String prefix = sch.getXlBm() + "_" + sch.getXlDir() + "_";
t.setStartStationName(BasicData.getStationNameByCode(t.getStartStation(), prefix));
t.setEndStationName(BasicData.getStationNameByCode(t.getEndStation(), prefix));
//先持久化子任务
rs = super.save(t);
//再关联主任务
sch.getcTasks().add(t);
dayOfSchedule.save(sch);
rs.put("t", sch);
if (sch.getZdsjActual() == null)
arrival2Schedule.removeExpect(sch.getClZbh());
return rs;
}
@Override
public Map<String, Object> delete(Long id) {
Map<String, Object> rs;
ChildTaskPlan cPlan = childTaskPlanRepository.findOne(id);
//解除和主任务关联
ScheduleRealInfo sch = dayOfSchedule.get(cPlan.getSchedule().getId());
sch.getcTasks().remove(cPlan);
//删除关联表数据
jdbcTemplate.execute("delete from bsth_c_s_sp_info_real_c_tasks where bsth_c_s_sp_info_real=" + sch.getId() + " and c_tasks=" + cPlan.getId());
//删除子任务
rs = super.delete(id);
dayOfSchedule.save(sch);
rs.put("t", sch);
return rs;
}
}