Commit cc41a27c authored by hanbing's avatar hanbing

方案管理-方案下发,信号机方案同步

parent f0d18106
......@@ -77,4 +77,10 @@ public class PlanSendController {
return jsonViewObject;
}
@ApiOperation(value = "信号机方案同步", notes = "信号机方案同步")
@PostMapping("/syncScheme")
public JsonViewObject syncScheme(@RequestBody CrossIdDTO crossIdDTO) {
JsonViewObject jsonViewObject = schemeSendService.syncScheme(crossIdDTO);
return jsonViewObject;
}
}
......@@ -28,4 +28,8 @@ public interface CrossLightsMapper {
List<CrossLightsPO> selectByLightsIdsAndDir(@Param("lightsIds") List<Integer> lightsIds,
@Param("dir") Integer dir);
void update(CrossLightsPO crossLightsPO);
void insertOne(CrossLightsPO crossLightsPO);
}
......@@ -23,4 +23,8 @@ public interface CrossPhaseLightsMapper {
List<CrossPhaseLightsPO> selectByLightsId(@Param("lightsId") Integer lightsId);
void updateLightsId(@Param("oldId") Integer oldId, @Param("newId") Integer newId);
Integer selectIdByThreeIds(Integer lightsId, Integer phaseId, String crossId);
void insertOne(CrossPhaseLightsPO crossPhaseLightsPO);
}
......@@ -14,9 +14,9 @@ import java.util.List;
@Repository
public interface CrossPhaseMapper {
Integer selectIdByCrossIdAndPhaseNo(@Param("crossId") String crossId,
@Param("schemeId") Integer schemeId,
@Param("coordPhaseNo") String coordPhaseNo);
Integer selectIdByCrossIdAndCoordPhaseNo(@Param("crossId") String crossId,
@Param("schemeId") Integer schemeId,
@Param("coordPhaseNo") String coordPhaseNo);
void insertOne(CrossPhasePO crossPhasePO);
......@@ -40,4 +40,8 @@ public interface CrossPhaseMapper {
List<CrossPhasePO> selectByCrossIdAndSchemeId(@Param("crossId") String crossId,
@Param("schemeId") Integer schemeId);
Integer selectIdByCrossIdAndPhaseNo(String crossId, String phaseNo);
void update(CrossPhasePO crossPhasePO);
}
......@@ -33,4 +33,8 @@ public interface CrossSchemeMapper {
@Param("schemeName") String schemeName);
CrossSchemePO selectById(@Param("id") Integer id);
void insertOne(CrossSchemePO crossSchemePO);
void update(CrossSchemePO crossSchemePO);
}
......@@ -24,4 +24,6 @@ public interface SchemeSendService {
JsonViewObject yellowLightControl(CrossIdDTO crossIdDTO);
JsonViewObject restore(CrossIdAndPhaseIdDTO crossIdAndPhaseIdDTO);
JsonViewObject syncScheme(CrossIdDTO crossIdDTO);
}
package net.wanji.web.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.wanji.feign.pojo.result.JsonViewObject;
import net.wanji.feign.pojo.vo.ControlCommandVO;
import net.wanji.feign.pojo.vo.CrossIdVO;
import net.wanji.feign.pojo.vo.LockControlVO;
import net.wanji.feign.pojo.vo.ScheduleSendVO;
import net.wanji.feign.pojo.vo.SchemeSendVO;
......@@ -10,18 +14,24 @@ import net.wanji.web.dto.CrossIdAndPhaseIdDTO;
import net.wanji.web.dto.CrossIdDTO;
import net.wanji.web.dto.ScheduleIdDTO;
import net.wanji.web.dto.SchemeIdDTO;
import net.wanji.web.mapper.scheme.CrossLightsMapper;
import net.wanji.web.mapper.scheme.CrossPhaseLightsMapper;
import net.wanji.web.mapper.scheme.CrossPhaseMapper;
import net.wanji.web.mapper.scheme.CrossPlanMapper;
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.CrossSchedulesPlanPO;
import net.wanji.web.po.scheme.CrossSchemePO;
import net.wanji.web.service.SchemeSendService;
import net.wanji.web.vo.SchemePhaseLightsVO;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
......@@ -42,15 +52,20 @@ public class SchemeSendServiceImpl implements SchemeSendService {
private final CrossPlanMapper crossPlanMapper;
private final CrossSchemeMapper crossSchemeMapper;
private final CrossPhaseMapper crossPhaseMapper;
private final CrossLightsMapper crossLightsMapper;
private final CrossPhaseLightsMapper crossPhaseLightsMapper;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
private Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
public SchemeSendServiceImpl(@Qualifier("net.wanji.feign.service.UtcFeignClients") UtcFeignClients utcFeignClients, CrossSchedulesPlanMapper crossSchedulesPlanMapper, CrossPlanMapper crossPlanMapper, CrossSchemeMapper crossSchemeMapper, CrossPhaseMapper crossPhaseMapper) {
public SchemeSendServiceImpl(@Qualifier("net.wanji.feign.service.UtcFeignClients") UtcFeignClients utcFeignClients, CrossSchedulesPlanMapper crossSchedulesPlanMapper, CrossPlanMapper crossPlanMapper, CrossSchemeMapper crossSchemeMapper, CrossPhaseMapper crossPhaseMapper, CrossLightsMapper crossLightsMapper, CrossPhaseLightsMapper crossPhaseLightsMapper) {
this.utcFeignClients = utcFeignClients;
this.crossSchedulesPlanMapper = crossSchedulesPlanMapper;
this.crossPlanMapper = crossPlanMapper;
this.crossSchemeMapper = crossSchemeMapper;
this.crossPhaseMapper = crossPhaseMapper;
this.crossLightsMapper = crossLightsMapper;
this.crossPhaseLightsMapper = crossPhaseLightsMapper;
}
@Override
......@@ -191,6 +206,73 @@ public class SchemeSendServiceImpl implements SchemeSendService {
return jsonViewObject.success();
}
@Override
@Transactional
public JsonViewObject syncScheme(CrossIdDTO crossIdDTO) {
CrossIdVO crossIdVO = new CrossIdVO();
crossIdVO.setCrossId(crossIdDTO.getCrossId());
JsonViewObject jsonViewObject = utcFeignClients.schemePhaseLights(crossIdVO);
if (Objects.isNull(jsonViewObject) || jsonViewObject.getCode() != 200) {
return jsonViewObject.fail("信号机静态信息获取-方案信息-UTC服务调用异常");
}
Object content = jsonViewObject.getContent();
if (ObjectUtil.isNotNull(content)) {
// 信息入库
String contentStr = gson.toJson(content);
SchemePhaseLightsVO schemePhaseLightsVO = gson.fromJson(contentStr, SchemePhaseLightsVO.class);
if (ObjectUtil.isEmpty(schemePhaseLightsVO)) {
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);
}
}
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);
}
}
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);
}
}
List<CrossPhaseLightsPO> crossPhaseLightsPOList = schemePhaseLightsVO.getCrossPhaseLightsPOList();
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);
}
}
}
return jsonViewObject.success();
}
@NotNull
private static ControlCommandVO getControlCommandVO(CrossIdDTO crossIdDTO) {
ControlCommandVO commandVO = new ControlCommandVO();
......
......@@ -185,7 +185,7 @@ public class SchemeConfigServiceImpl implements SchemeConfigService {
phaseListElement.setYellowFlash(1);
}
phaseListElement.setAccompanyPhaseNoList(new ArrayList<>());
Integer phaseId = crossPhaseMapper.selectIdByCrossIdAndPhaseNo(crossId, schemeId, phaseNo);
Integer phaseId = crossPhaseMapper.selectIdByCrossIdAndCoordPhaseNo(crossId, schemeId, phaseNo);
List<SaveSchemeConfigDTO.DirListElement> dirList = buildDirList(crossId, phaseId);
phaseListElement.setDirList(dirList);
......@@ -289,7 +289,7 @@ public class SchemeConfigServiceImpl implements SchemeConfigService {
phaseListElement.setGreenFlash(1);
}
// 伴随相位的母相位列表
Integer phaseId = crossPhaseMapper.selectIdByCrossIdAndPhaseNo(crossId, schemeId, phaseNo);
Integer phaseId = crossPhaseMapper.selectIdByCrossIdAndCoordPhaseNo(crossId, schemeId, phaseNo);
if (phaseType == 3) {
List<String> superPhaseNoList = new ArrayList<>();
List<Integer> superIdList = crossAccompanyPhaseMapper.selectByPhaseId(phaseId);
......@@ -418,7 +418,7 @@ public class SchemeConfigServiceImpl implements SchemeConfigService {
String schemeNo = phaseScheme.getSchemeNo();
Integer schemeId = crossSchemeMapper.selectIdByCrossIdAndSchemeNo(crossId, schemeNo);
String coordPhaseNo = phaseScheme.getCoordPhaseNo();
Integer phaseId = crossPhaseMapper.selectIdByCrossIdAndPhaseNo(crossId, schemeId, coordPhaseNo);
Integer phaseId = crossPhaseMapper.selectIdByCrossIdAndCoordPhaseNo(crossId, schemeId, coordPhaseNo);
if (phaseId != null) {
crossSchemeMapper.updateCoordPhase(crossId, schemeNo, phaseId);
}
......@@ -550,7 +550,7 @@ public class SchemeConfigServiceImpl implements SchemeConfigService {
CrossAccompanyPhasePO crossAccompanyPhasePO = new CrossAccompanyPhasePO();
crossAccompanyPhasePO.setCrossId(crossId);
crossAccompanyPhasePO.setPhaseId(accompanyPhaseId);
Integer superPhaseId = crossPhaseMapper.selectIdByCrossIdAndPhaseNo(
Integer superPhaseId = crossPhaseMapper.selectIdByCrossIdAndCoordPhaseNo(
crossId, schemeId,superPhaseNo);
crossAccompanyPhasePO.setSuperId(superPhaseId);
crossAccompanyPhasePOList.add(crossAccompanyPhasePO);
......
package net.wanji.web.vo;
import lombok.Data;
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.CrossSchemePO;
import java.util.List;
@Data
public class SchemePhaseLightsVO {
private List<CrossSchemePO> crossSchemeList;
private List<CrossPhasePO> crossPhaseList;
private List<CrossLightsPO> crossLightsList;
private List<CrossPhaseLightsPO> crossPhaseLightsPOList;
}
\ No newline at end of file
......@@ -22,6 +22,27 @@
</foreach>
</insert>
<insert id="insertOne" keyProperty="id" useGeneratedKeys="true">
insert into t_base_cross_lights(lights_no,type,dir,sort,cross_id)
values (#{lightsNo},#{type},#{dir},#{sort},#{crossId})
</insert>
<update id="update">
update t_base_cross_lights
<set>
<if test="type != null and type != ''">
type = #{type},
</if>
<if test="dir != null and dir != ''">
dir = #{dir},
</if>
<if test="sort != null and sort != ''">
sort = #{sort},
</if>
</set>
where cross_id = #{crossId} and lights_no=#{lightsNo}
</update>
<delete id="deleteByCrossId">
delete from t_base_cross_lights
where cross_id = #{crossId}
......
......@@ -20,6 +20,11 @@
</foreach>
</insert>
<insert id="insertOne" keyProperty="id" useGeneratedKeys="true">
insert into t_base_cross_phase_lights(lights_id,phase_id,cross_id)
values (#{lightsId},#{phaseId},#{crossId})
</insert>
<update id="updateLightsId">
update t_base_cross_phase_lights
set lights_id = #{newId}
......@@ -45,5 +50,10 @@
where lights_id = #{lightsId}
</select>
<select id="selectIdByThreeIds" resultType="java.lang.Integer">
SELECT id from t_base_cross_phase_lights
WHERE cross_id = #{crossId} and lights_id = #{lightsId} and phase_id = #{phaseId}
</select>
</mapper>
......@@ -31,12 +31,70 @@
values (#{phaseNo},#{name},#{sort},#{crossId},#{planId},#{ringNo},#{groupNo},#{phaseType},#{controlMode},#{phaseTime},#{greenTime},#{greenFlashTime},#{yellowFlashTime},#{redFlashTime},#{pedFlashTime},#{yellowTime},#{redTime},#{minGreenTime},#{maxGreenTime})
</insert>
<update id="update">
update t_base_cross_phase
<set>
<if test="name != null and name != ''">
name = #{name},
</if>
<if test="sort != null and sort != ''">
sort = #{sort},
</if>
<if test="planId != null and planId != ''">
plan_id = #{planId},
</if>
<if test="ringNo != null and ringNo != ''">
ring_no = #{ringNo},
</if>
<if test="groupNo != null and groupNo != ''">
group_no = #{groupNo},
</if>
<if test="phaseType != null and phaseType != ''">
phase_type = #{phaseType},
</if>
<if test="controlMode != null and controlMode != ''">
control_mode = #{controlMode},
</if>
<if test="phaseTime != null and phaseTime != ''">
phase_time = #{phaseTime},
</if>
<if test="greenTime != null and greenTime != ''">
green_time = #{greenTime},
</if>
<if test="greenFlashTime != null and greenFlashTime != ''">
green_flash_time = #{greenFlashTime},
</if>
<if test="yellowFlashTime != null and yellowFlashTime != ''">
yellow_flash_time = #{yellowFlashTime},
</if>
<if test="redFlashTime != null and redFlashTime != ''">
red_flash_time = #{redFlashTime},
</if>
<if test="pedFlashTime != null and pedFlashTime != ''">
ped_flash_time = #{pedFlashTime},
</if>
<if test="yellowTime != null and yellowTime != ''">
yellow_time = #{yellowTime},
</if>
<if test="redTime != null and redTime != ''">
red_time = #{redTime},
</if>
<if test="minGreenTime != null and minGreenTime != ''">
min_green_time = #{minGreenTime},
</if>
<if test="maxGreenTime != null and maxGreenTime != ''">
max_green_time = #{maxGreenTime},
</if>
</set>
where cross_id = #{crossId} and phase_no = #{phaseNo}
</update>
<delete id="deleteByCrossId">
delete from t_base_cross_phase
where cross_id = #{crossId}
</delete>
<select id="selectIdByCrossIdAndPhaseNo" resultType="java.lang.Integer">
<select id="selectIdByCrossIdAndCoordPhaseNo" resultType="java.lang.Integer">
select id from t_base_cross_phase
where cross_id = #{crossId} and plan_id = #{schemeId} and phase_no = #{coordPhaseNo}
</select>
......@@ -88,5 +146,10 @@
order by sort
</select>
<select id="selectIdByCrossIdAndPhaseNo" resultType="java.lang.Integer">
select id from t_base_cross_phase
where cross_id = #{crossId} and phase_no = #{phaseNo}
</select>
</mapper>
......@@ -25,12 +25,42 @@
</foreach>
</insert>
<insert id="insertOne">
insert into t_base_cross_scheme(scheme_no,name,cross_id,cycle,coord_phase,offset,source,is_deleted)
values (#{schemeNo},#{name},#{crossId},#{cycle},#{coordPhase},#{offset},#{source},#{isDeleted})
</insert>
<update id="updateCoordPhase">
update t_base_cross_scheme
set coord_phase = #{phaseId}
where cross_id = #{crossId} and scheme_no = #{schemeNo}
</update>
<update id="update">
update t_base_cross_scheme
<set>
<if test="name != null and name != ''">
name = #{name},
</if>
<if test="cycle != null and cycle != ''">
cycle = #{cycle},
</if>
<if test="coordPhase != null and coordPhase != ''">
coord_phase = #{coordPhase},
</if>
<if test="offset != null and offset != ''">
offset = #{offset},
</if>
<if test="source != null and source != ''">
source = #{source},
</if>
<if test="isDeleted != null and isDeleted != ''">
is_deleted = #{isDeleted},
</if>
</set>
where cross_id = #{crossId} and scheme_no = #{schemeNo}
</update>
<delete id="deleteByCrossId">
delete from t_base_cross_scheme
where cross_id = #{crossId}
......
package net.wanji.feign.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 方案管理-路口配置-获取路口方向列表输入参数
*
* @author Kent HAN
* @date 2022/12/20 10:17
*/
@Data
public class CrossIdVO {
@ApiModelProperty(value = "路口ID,如:c7e7b1f352dd4acab4a60088eb391cca", required = true)
private String crossId;
}
......@@ -49,4 +49,10 @@ public interface UtcFeignClients {
@PostMapping("/controlCommand/phaseDiffSend")
JsonViewObject phaseDiffSend();
/**
* 方案数据-方案信息、相位信息、灯组信息
*/
@PostMapping("/staticInfo/schemePhaseLights")
JsonViewObject schemePhaseLights(@RequestBody CrossIdVO crossIdVO);
}
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