Commit 09734f43 authored by hanbing's avatar hanbing

方案下发-信号机方案同步

parent bbf60c16
......@@ -44,6 +44,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
......@@ -242,18 +243,56 @@ public class PlanSendServiceImpl implements PlanSendService {
}
List<CrossSchemePO> crossSchemeList = schemePhaseLightsVO.getCrossSchemeList();
crossSchemeMapper.deleteByCrossId(crossId);
// 保存旧方案ID
List<Integer> oldSchemeIds = crossSchemeList.stream().map(CrossSchemePO::getId).collect(Collectors.toList());;
// 保存新方案ID
crossSchemeMapper.insertBatch(crossSchemeList);
List<Integer> newSchemeIds = crossSchemeList.stream().map(CrossSchemePO::getId).collect(Collectors.toList());;
// 生成新旧方案ID映射
Map<Integer, Integer> oldNewSchemeId = new HashMap<>();
for (int i = 0; i < oldSchemeIds.size(); i++) {
oldNewSchemeId.put(oldSchemeIds.get(i), newSchemeIds.get(i));
}
List<CrossPhasePO> crossPhaseList = schemePhaseLightsVO.getCrossPhaseList();
crossPhaseMapper.deleteByCrossId(crossId);
// 保存旧相位ID
List<Integer> oldPhaseIds = crossPhaseList.stream().map(CrossPhasePO::getId).collect(Collectors.toList());
// 更新方案ID
for (CrossPhasePO crossPhasePO : crossPhaseList) {
crossPhasePO.setPlanId(oldNewSchemeId.get(crossPhasePO.getPlanId()));
}
// 保存新相位ID
crossPhaseMapper.insertBatch(crossPhaseList);
List<Integer> newPhaseIds = crossPhaseList.stream().map(CrossPhasePO::getId).collect(Collectors.toList());
// 生成新旧相位ID映射
Map<Integer, Integer> oldNewPhaseId = new HashMap<>();
for (int i = 0; i < oldPhaseIds.size(); i++) {
oldNewPhaseId.put(oldPhaseIds.get(i), newPhaseIds.get(i));
}
List<CrossLightsPO> crossLightsList = schemePhaseLightsVO.getCrossLightsList();
crossLightsMapper.deleteByCrossId(crossId);
// 保存旧灯组ID
List<Integer> oldLightsIds = crossLightsList.stream().map(CrossLightsPO::getId).collect(Collectors.toList());
// 保存新灯组ID
crossLightsMapper.insertBatch(crossLightsList);
List<Integer> newLightsIds = crossLightsList.stream().map(CrossLightsPO::getId).collect(Collectors.toList());
// 生成新旧灯组ID映射
Map<Integer, Integer> oldNewLightsId = new HashMap<>();
for (int i = 0; i < oldLightsIds.size(); i++) {
oldNewLightsId.put(oldLightsIds.get(i), newLightsIds.get(i));
}
List<CrossPhaseLightsPO> crossPhaseLightsPOList = schemePhaseLightsVO.getCrossPhaseLightsPOList();
crossPhaseLightsMapper.deleteByCrossId(crossId);
// 更新ID
for (CrossPhaseLightsPO crossPhaseLightsPO : crossPhaseLightsPOList) {
Integer oldPhaseId = crossPhaseLightsPO.getPhaseId();
Integer oldLightsId = crossPhaseLightsPO.getLightsId();
crossPhaseLightsPO.setPhaseId(oldNewPhaseId.get(oldPhaseId));
crossPhaseLightsPO.setLightsId(oldNewLightsId.get(oldLightsId));
}
crossPhaseLightsMapper.insertBatch(crossPhaseLightsPOList);
}
return jsonViewObject.success();
......
......@@ -18,7 +18,7 @@ public interface CrossPhaseMapper {
List<CrossPhasePO> selectByCrossIdAndPlanId(@Param("crossId") String crossId, @Param("planId") String planId);
List<Integer> selectIdsByPhaseNo(@Param("phaseNo") Integer phaseNo);
List<Integer> selectIdsByPhaseNo(String crossId, @Param("phaseNo") Integer phaseNo);
List<CrossPhasePO> selectByCrossId(@Param("crossId") String crossId);
}
......@@ -111,12 +111,12 @@ public class HkSchemePhaseLightsServiceImpl implements HkSchemePhaseLightsServic
PhaseCache phaseCache = laneNoMap.get(Integer.parseInt(laneNo));
if (phaseCache != null) {
Integer phaseNo = phaseCache.getPhaseNo();
List<Integer> ids = crossPhaseMapper.selectIdsByPhaseNo(phaseNo);
if (ids != null) {
for (Integer id : ids) {
List<Integer> phaseIds = crossPhaseMapper.selectIdsByPhaseNo(crossId, phaseNo);
if (phaseIds != null) {
for (Integer phaseId : phaseIds) {
CrossPhaseLightsPO crossPhaseLightsPO = new CrossPhaseLightsPO();
crossPhaseLightsPO.setLightsId(crossLightsPOId);
crossPhaseLightsPO.setPhaseId(id);
crossPhaseLightsPO.setPhaseId(phaseId);
crossPhaseLightsPO.setCrossId(crossId);
crossPhaseLightsPOSet.add(crossPhaseLightsPO);
}
......
......@@ -56,7 +56,7 @@
<select id="selectIdsByPhaseNo" resultType="java.lang.Integer">
select id from t_cross_phase
where phase_no = #{phaseNo}
where cross_id = #{crossId} and phase_no = #{phaseNo}
</select>
<select id="selectByCrossId" resultMap="BaseResultMap">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment