Commit bbf60c16 authored by hanbing's avatar hanbing

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

parent eb6a34d0
......@@ -4,8 +4,8 @@ import net.wanji.web.po.scheme.CrossPhaseLightsPO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
* 相位灯组关系;(t_base_cross_phase_lights)表数据库访问层
......@@ -16,7 +16,7 @@ import java.util.Set;
public interface CrossPhaseLightsMapper {
void deleteByCrossId(@Param("crossId") String crossId);
void insertBatchBySet(@Param("entities") Set<CrossPhaseLightsPO> entities);
void insertBatch(@Param("entities") Collection<CrossPhaseLightsPO> entities);
List<CrossPhaseLightsPO> selectByPhaseId(@Param("phaseId") Integer phaseId);
......
......@@ -44,4 +44,6 @@ public interface CrossPhaseMapper {
Integer selectIdByCrossIdAndPhaseNo(String crossId, String phaseNo);
void update(CrossPhasePO crossPhasePO);
void insertBatch(List<CrossPhasePO> crossPhaseList);
}
......@@ -226,7 +226,8 @@ public class PlanSendServiceImpl implements PlanSendService {
@Transactional
public JsonViewObject syncScheme(CrossIdDTO crossIdDTO) {
CrossIdVO crossIdVO = new CrossIdVO();
crossIdVO.setCrossId(crossIdDTO.getCrossId());
String crossId = crossIdDTO.getCrossId();
crossIdVO.setCrossId(crossId);
JsonViewObject jsonViewObject = utcFeignClients.schemePhaseLights(crossIdVO);
if (Objects.isNull(jsonViewObject) || jsonViewObject.getCode() != 200) {
return jsonViewObject.fail("信号机静态信息获取-方案信息-UTC服务调用异常");
......@@ -240,53 +241,20 @@ public class PlanSendServiceImpl implements PlanSendService {
return jsonViewObject.fail("信号机方案对象转换结果为空,未更新数据库");
}
List<CrossSchemePO> crossSchemeList = schemePhaseLightsVO.getCrossSchemeList();
for (CrossSchemePO crossSchemePO : crossSchemeList) {
String crossId = crossSchemePO.getCrossId();
String schemeNo = crossSchemePO.getSchemeNo();
Integer schemeId = crossSchemeMapper.selectIdByCrossIdAndSchemeNo(crossId, schemeNo);
if (!ObjectUtil.isEmpty(schemeId)) {
// 如果有相同的路口ID和方案号,则更新
crossSchemeMapper.update(crossSchemePO);
} else {
// 否则插入
crossSchemeMapper.insertOne(crossSchemePO);
}
}
crossSchemeMapper.deleteByCrossId(crossId);
crossSchemeMapper.insertBatch(crossSchemeList);
List<CrossPhasePO> crossPhaseList = schemePhaseLightsVO.getCrossPhaseList();
for (CrossPhasePO crossPhasePO : crossPhaseList) {
String crossId = crossPhasePO.getCrossId();
String phaseNo = crossPhasePO.getPhaseNo();
Integer phaseId = crossPhaseMapper.selectIdByCrossIdAndPhaseNo(crossId, phaseNo);
if (ObjectUtil.isNotEmpty(phaseId)) {
crossPhaseMapper.update(crossPhasePO);
} else {
crossPhaseMapper.insertOne(crossPhasePO);
}
}
crossPhaseMapper.deleteByCrossId(crossId);
crossPhaseMapper.insertBatch(crossPhaseList);
List<CrossLightsPO> crossLightsList = schemePhaseLightsVO.getCrossLightsList();
for (CrossLightsPO crossLightsPO : crossLightsList) {
String crossId = crossLightsPO.getCrossId();
String lightsNo = crossLightsPO.getLightsNo();
CrossLightsPO crossLightsPO1 = crossLightsMapper.selectByCrossIdAndLedNum(crossId, lightsNo);
if (ObjectUtil.isNotEmpty(crossLightsPO1)) {
crossLightsMapper.update(crossLightsPO);
} else {
crossLightsMapper.insertOne(crossLightsPO);
}
}
crossLightsMapper.deleteByCrossId(crossId);
crossLightsMapper.insertBatch(crossLightsList);
List<CrossPhaseLightsPO> crossPhaseLightsPOList = schemePhaseLightsVO.getCrossPhaseLightsPOList();
if (crossPhaseLightsPOList != null) {
for (CrossPhaseLightsPO crossPhaseLightsPO : crossPhaseLightsPOList) {
Integer lightsId = crossPhaseLightsPO.getLightsId();
Integer phaseId = crossPhaseLightsPO.getPhaseId();
String crossId = crossPhaseLightsPO.getCrossId();
Integer id = crossPhaseLightsMapper.selectIdByThreeIds(lightsId, phaseId, crossId);
// 如果数据库中有记录则跳过,无记录则插入
if (ObjectUtil.isEmpty(id)) {
crossPhaseLightsMapper.insertOne(crossPhaseLightsPO);
}
}
}
crossPhaseLightsMapper.deleteByCrossId(crossId);
crossPhaseLightsMapper.insertBatch(crossPhaseLightsPOList);
}
return jsonViewObject.success();
}
......
......@@ -664,7 +664,7 @@ public class SchemeConfigServiceImpl implements SchemeConfigService {
crossPhaseLightsPOSet.add(crossPhaseLightsPO);
}
}
crossPhaseLightsMapper.insertBatchBySet(crossPhaseLightsPOSet);
crossPhaseLightsMapper.insertBatch(crossPhaseLightsPOSet);
}
private void updateCrossScheme(SaveSchemeConfigDTO saveSchemeConfigDTO) {
......
......@@ -12,7 +12,7 @@
<result property="gmtModified" column="gmt_modified"/>
</resultMap>
<insert id="insertBatchBySet" keyProperty="id" useGeneratedKeys="true">
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into t_base_cross_phase_lights(lights_id,phase_id,cross_id)
values
<foreach collection="entities" item="entity" separator=",">
......
......@@ -31,6 +31,14 @@
values (#{phaseNo},#{name},#{sort},#{crossId},#{planId},#{ringNo},#{groupNo},#{phaseType},#{controlMode},#{phaseTime},#{greenTime},#{greenFlashTime},#{yellowFlashTime},#{redFlashTime},#{pedFlashTime},#{yellowTime},#{redTime},#{minGreenTime},#{maxGreenTime})
</insert>
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into t_base_cross_phase(phase_no,name,sort,cross_id,plan_id,ring_no,group_no,phase_type,control_mode,phase_time,green_time,green_flash_time,yellow_flash_time,red_flash_time,ped_flash_time,yellow_time,red_time,min_green_time,max_green_time)
values
<foreach collection="crossPhaseList" item="entity" separator=",">
(#{entity.phaseNo},#{entity.name},#{entity.sort},#{entity.crossId},#{entity.planId},#{entity.ringNo},#{entity.groupNo},#{entity.phaseType},#{entity.controlMode},#{entity.phaseTime},#{entity.greenTime},#{entity.greenFlashTime},#{entity.yellowFlashTime},#{entity.redFlashTime},#{entity.pedFlashTime},#{entity.yellowTime},#{entity.redTime},#{entity.minGreenTime},#{entity.maxGreenTime})
</foreach>
</insert>
<update id="update">
update t_base_cross_phase
<set>
......
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