Commit 04a213d9 authored by duanruiming's avatar duanruiming

[add] 新增信号机本地手动控制同步逻辑

parent b43a0bb6
package net.wanji.web.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author Kent HAN
* @date 2022/11/21 11:18
*/
@Data
public class SignalStatusLogDTO {
/** 日志ID */
@ApiModelProperty(value = "日志ID",notes = "")
private Integer id ;
/** 路口ID */
@ApiModelProperty(value = "路口ID",notes = "")
private String crossId ;
/** 信号机ID */
@ApiModelProperty(value = "信号机ID",notes = "")
private String signalId ;
/** 信号状态:0离线;1在线 */
@ApiModelProperty(value = "信号状态:0离线;1在线",notes = "")
private Integer status ;
/** 故障类型:0正常;1检测器故障;2时钟故障;3电源故障;4驱动模块故障;5信号灯故障;6箱门开启;7方案错误;8绿冲突;9红全熄;10行人红熄; */
@ApiModelProperty(value = "故障类型:0正常;1检测器故障;2时钟故障;3电源故障;4驱动模块故障;5信号灯故障;6箱门开启;7方案错误;8绿冲突;9红全熄;10行人红熄;",notes = "")
private Integer faultType ;
/** 控制类型:1时间表;2全红;3黄闪;4锁定;5中心优化;6MEC优化;7现场手动 */
@ApiModelProperty(value = "控制类型:1时间表;2全红;3黄闪;4锁定;5中心优化;6MEC优化;7现场手动",notes = "")
private Integer controlType ;
/** 创建时间 */
@ApiModelProperty(value = "创建时间",notes = "")
private Date gmtCreate ;
}
......@@ -45,4 +45,7 @@ public class TCrossControlHist {
*/
@ApiModelProperty(name = "修改时间", notes = "")
private Date gmtModified;
@ApiModelProperty(name = "操作人", notes = "")
private String operationUser;
}
package net.wanji.web.mapper;
import net.wanji.web.entity.TCrossControlHist;
import net.wanji.web.po.ControlHistPO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
......@@ -16,5 +17,7 @@ import java.util.List;
public interface ControlHistMapper {
List<ControlHistPO> selectByCrossId(@Param("crossId") String crossId, @Param("todayDate") Date todayDate);
int insertOne(@Param("crossId") String crossId, @Param("type") Integer type);
int insertOne(@Param("crossId") String crossId, @Param("type") Integer type, @Param("operationUser") String operationUser);
TCrossControlHist selectRecentOne(@Param("crossId") String crossId);
}
package net.wanji.web.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import net.wanji.web.po.GreenwaveRealtimePO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
......@@ -13,7 +12,6 @@ import java.util.List;
* @date 2022/10/27 14:25
*/
@Repository
@DS("webService")
public interface GreenwaveRealtimeMapper {
List<GreenwaveRealtimePO> selectByAdCodeAndCurrentTime(@Param("adCode") String adCode,
......
package net.wanji.web.task;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.wanji.feign.pojo.result.JsonViewObject;
import net.wanji.feign.service.UtcFeignClients;
import net.wanji.web.dto.SignalStatusLogDTO;
import net.wanji.web.entity.TCrossControlHist;
import net.wanji.web.entity.TDeviceStatusInfo;
import net.wanji.web.mapper.ControlHistMapper;
import net.wanji.web.mapper.TDeviceStatusMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
......@@ -20,14 +22,12 @@ import java.util.Objects;
* @date 2023/01/03 10:43
*/
@Component
@RequiredArgsConstructor
@Slf4j
public class SignalStatusTask {
@Autowired
private UtcFeignClients utcFeignClients;
@Autowired
private TDeviceStatusMapper tDeviceStatusMapper;
private final UtcFeignClients utcFeignClients;
private final TDeviceStatusMapper tDeviceStatusMapper;
private final ControlHistMapper controlHistMapper;
@Scheduled(fixedRate = 1 * 60 * 1000)
public void syncSignalStatus() {
......@@ -37,14 +37,13 @@ public class SignalStatusTask {
log.error("定时任务同步信号机设备状态utcService调用异常");
return;
}
List<Map<String, Object>> content = (List<Map<String, Object>>) jsonViewObject.getContent();
content.forEach(map -> {
Map<String, Object> result = map;
String signalId = (String) result.get("signalId");
Integer currentSignalStatus = result.get("status") == null ? 0 : (Integer) result.get("status");
Integer currentFaultType = result.get("faultType") == null ? 0 : (Integer) result.get("faultType");
List<SignalStatusLogDTO> content = (List<SignalStatusLogDTO>) jsonViewObject.getContent();
content.forEach(signalStatusLogDTO -> {
String signalId = signalStatusLogDTO.getSignalId();
Integer currentSignalStatus = signalStatusLogDTO.getStatus() == null ? 0 : signalStatusLogDTO.getStatus();
Integer currentFaultType = signalStatusLogDTO.getFaultType() == null ? 0 : signalStatusLogDTO.getFaultType();
// 当前服务数据库状态
// 更新数据库状态
LambdaQueryWrapper<TDeviceStatusInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
if (StringUtils.isNotEmpty(signalId)) {
lambdaQueryWrapper.eq(TDeviceStatusInfo::getCode, signalId);
......@@ -55,6 +54,13 @@ public class SignalStatusTask {
tDeviceStatusMapper.updateById(tDeviceStatusInfo);
}
}
// 更新控制历史表
String crossId = signalStatusLogDTO.getCrossId();
Integer controlType = signalStatusLogDTO.getControlType();
TCrossControlHist tCrossControlHist = controlHistMapper.selectRecentOne(crossId);
if (Objects.nonNull(tCrossControlHist) && !Objects.equals(controlType, tCrossControlHist.getType())) {
controlHistMapper.insertOne(crossId, controlType, "未知");
}
});
} catch (Exception e) {
log.error("定时任务同步信号机设备状态远程utcService调用异常", e);
......
......@@ -12,7 +12,7 @@ import lombok.Data;
@ApiModel(value = "CommonEventAlarmOutVo", description = "统一事件告警检测返回结果")
public class CommonEventAlarmOutVo {
@ApiModelProperty(value = "事件编号:1:路口报警、2:事件报警、3:信号机故障")
@ApiModelProperty(value = "事件类型:1:路口报警、2:事件报警、3:信号机故障")
Integer eventType;
@ApiModelProperty(value = "事件id")
......
......@@ -16,10 +16,11 @@
<result property="startTime" column="start_time" jdbcType="TIMESTAMP"/>
<result property="gmtCreate" column="gmt_create" jdbcType="TIMESTAMP"/>
<result property="gmtModified" column="gmt_modified" jdbcType="TIMESTAMP"/>
<result property="operationUser" column="operation_user" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
id, crossId, type, startTime, gmt_create, gmt_modified
id, cross_id, type, start_time, gmt_create, gmt_modified, operation_user
</sql>
<select id="selectByCrossId" resultMap="BaseResultMap">
......@@ -33,7 +34,19 @@
</select>
<insert id="insertOne">
insert into t_cross_control_hist (cross_id, type, start_time, gmt_create, gmt_modified)
values (#{crossId}, #{type}, now(), now(), now())
insert into t_cross_control_hist (cross_id, type, start_time, gmt_create, gmt_modified, operation_user)
values (#{crossId}, #{type}, now(), now(), now(), #{operationUser})
</insert>
<select id="selectRecentOne" resultType="net.wanji.web.entity.TCrossControlHist">
select
<include refid="Base_Column_List"/>
from t_cross_control_hist
<where>
<if test="crossId != null and crossId !=''">
cross_id = #{crossId}
</if>
and start_time = (select max(start_time) from t_cross_control_hist)
</where>
</select>
</mapper>
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