ChildTaskPlanServiceImpl.java 1.8 KB
package com.bsth.service.realcontrol.impl;

import java.util.Map;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bsth.entity.realcontrol.ChildTaskPlan;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.repository.realcontrol.ChildTaskPlanRepository;
import com.bsth.service.impl.BaseServiceImpl;
import com.bsth.service.realcontrol.ChildTaskPlanService;
import com.bsth.service.realcontrol.buffer.ScheduleBuffer;
import com.bsth.vehicle.common.CommonMapped;

@Service
public class ChildTaskPlanServiceImpl extends BaseServiceImpl<ChildTaskPlan, Long> implements ChildTaskPlanService{

	/*@Autowired
	ScheduleRealInfoServiceImpl scheduleRealInfoService;*/
	
	@Autowired
	ChildTaskPlanRepository childTaskPlanRepository;
	
	@Transactional
	@Override
	public Map<String, Object> save(ChildTaskPlan t) {
		Map<String, Object> rs;
		//保存起终点名称
		Map<String, String> map = CommonMapped.stationCodeMap;
		
		t.setStartStationName(map.get(t.getStartStation()));
		t.setEndStationName(map.get(t.getEndStation()));
		//先持久化子任务
		rs = super.save(t);
		//再关联主任务
		ScheduleRealInfo sch = ScheduleBuffer.findOne(t.getSchedule().getId());
		sch.getcTasks().add(t);
		//rs = scheduleRealInfoService.save(sch);
		
		rs.put("t", sch);
		return rs;
	}

	@Override
	public Map<String, Object> delete(Long id) {
		Map<String, Object> rs;
		
		ChildTaskPlan cPlan = childTaskPlanRepository.findOne(id);
		//解除和主任务关联
		ScheduleRealInfo sch = ScheduleBuffer.findOne(cPlan.getSchedule().getId());
		sch.getcTasks().remove(cPlan);
		//删除子任务
		rs = super.delete(id);
		rs.put("t", sch);
		return rs;
	}
}