Commit 67d2e97b authored by hanbing's avatar hanbing

[update] 信号机方案同步,灯组号去重

parent b539b44c
......@@ -4,6 +4,7 @@ import net.wanji.web.po.scheme.CrossLightsPO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.List;
/**
......@@ -16,7 +17,7 @@ public interface CrossLightsMapper {
void deleteByCrossId(@Param("crossId") String crossId);
void insertBatch(@Param("entities") List<CrossLightsPO> entities);
void insertBatch(@Param("entities") Collection<CrossLightsPO> entities);
CrossLightsPO selectByCrossIdAndLedNum(@Param("crossId") String crossId, @Param("ledNum") String ledNum);
......
......@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.wanji.common.dto.CrossIdDTO;
import net.wanji.feign.pojo.result.JsonViewObject;
import net.wanji.feign.pojo.vo.ControlCommandVO;
import net.wanji.feign.pojo.vo.CrossIdVO;
......@@ -14,7 +15,6 @@ import net.wanji.feign.pojo.vo.SchemeSendVO;
import net.wanji.feign.service.UtcFeignClients;
import net.wanji.web.dto.CrossIdAndPhaseIdsDTO;
import net.wanji.web.dto.CrossIdAndTimeDTO;
import net.wanji.common.dto.CrossIdDTO;
import net.wanji.web.dto.RunningPlanDTO;
import net.wanji.web.dto.SaveSchemeConfigDTO;
import net.wanji.web.dto.ScheduleIdDTO;
......@@ -27,7 +27,6 @@ import net.wanji.web.mapper.scheme.CrossSchedulesMapper;
import net.wanji.web.mapper.scheme.CrossSchedulesPlanMapper;
import net.wanji.web.mapper.scheme.CrossSchemeMapper;
import net.wanji.web.po.scheme.CrossLightsPO;
import net.wanji.web.po.scheme.CrossPhaseLightsPO;
import net.wanji.web.po.scheme.CrossPhasePO;
import net.wanji.web.po.scheme.CrossPlanPO;
import net.wanji.web.po.scheme.CrossSchedulesPO;
......@@ -45,11 +44,14 @@ import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
/**
......@@ -268,52 +270,34 @@ public class PlanSendServiceImpl implements PlanSendService {
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());
// 灯组号去重
TreeSet<CrossLightsPO> crossLightsSet = distinctLightsNo(crossLightsList);
// 修改灯组数据内容
changeLightsData(crossLightsList);
// 保存新灯组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));
}
changeLightsType(crossLightsSet);
crossLightsMapper.insertBatch(crossLightsSet);
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();
}
private static void changeLightsData(List<CrossLightsPO> crossLightsList) {
for (CrossLightsPO crossLightsPO : crossLightsList) {
private TreeSet<CrossLightsPO> distinctLightsNo(List<CrossLightsPO> crossLightsList) {
TreeSet<CrossLightsPO> crossLightsSet = crossLightsList.stream()
.collect(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(CrossLightsPO::getLightsNo))));
return crossLightsSet;
}
private static void changeLightsType(Set<CrossLightsPO> crossLightsSet) {
for (CrossLightsPO crossLightsPO : crossLightsSet) {
Integer type = crossLightsPO.getType();
if (type == 2) {
crossLightsPO.setType(1);
......
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