Commit 7bc7adc0 authored by duanruiming's avatar duanruiming

[update] 优化信号机状态定时任务

parent 3d227444
package net.wanji.web.entity; package net.wanji.web.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
...@@ -11,6 +13,7 @@ import java.util.Date; ...@@ -11,6 +13,7 @@ import java.util.Date;
*/ */
@Data @Data
public class TDeviceStatusLog { public class TDeviceStatusLog {
@TableId(type = IdType.AUTO)
@ApiModelProperty(value = "id") @ApiModelProperty(value = "id")
private Integer id; private Integer id;
@ApiModelProperty(value = "设备代码") @ApiModelProperty(value = "设备代码")
......
...@@ -4,8 +4,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -4,8 +4,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.wanji.common.framework.rest.JsonViewObject; import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.common.utils.tool.BeanMapUtils;
import net.wanji.databus.vo.SignalStatusVO;
import net.wanji.feign.service.UtcFeignClients; import net.wanji.feign.service.UtcFeignClients;
import net.wanji.web.dto.SignalStatusLogDTO;
import net.wanji.web.entity.TCrossControlHist; import net.wanji.web.entity.TCrossControlHist;
import net.wanji.web.entity.TDeviceStatusInfo; import net.wanji.web.entity.TDeviceStatusInfo;
import net.wanji.web.entity.TDeviceStatusLog; import net.wanji.web.entity.TDeviceStatusLog;
...@@ -18,6 +19,7 @@ import org.springframework.stereotype.Component; ...@@ -18,6 +19,7 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
/** /**
...@@ -42,11 +44,13 @@ public class SignalStatusTask { ...@@ -42,11 +44,13 @@ public class SignalStatusTask {
log.error("定时任务同步信号机设备状态utcService调用异常"); log.error("定时任务同步信号机设备状态utcService调用异常");
return; return;
} }
List<SignalStatusLogDTO> content = (List<SignalStatusLogDTO>) jsonViewObject.getContent(); List<Map<String, Object>> source = (List<Map<String, Object>>) jsonViewObject.getContent();
content.forEach(signalStatusLogDTO -> { List<SignalStatusVO> content = BeanMapUtils.mapsToObjects(source, SignalStatusVO.class);
String signalId = signalStatusLogDTO.getSignalId(); content.forEach(signalStatusVO -> {
Integer currentSignalStatus = signalStatusLogDTO.getStatus() == null ? 0 : signalStatusLogDTO.getStatus(); String signalId = signalStatusVO.getSignalId();
Integer currentFaultType = signalStatusLogDTO.getFaultType() == null ? 0 : signalStatusLogDTO.getFaultType(); String crossId = signalStatusVO.getCrossId();
Integer currentSignalStatus = signalStatusVO.getStatus() == null ? 0 : signalStatusVO.getStatus();
Integer currentFaultType = signalStatusVO.getFaultType() == null ? 0 : signalStatusVO.getFaultType();
// 更新数据库状态 // 更新数据库状态
LambdaQueryWrapper<TDeviceStatusInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<TDeviceStatusInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
...@@ -58,9 +62,9 @@ public class SignalStatusTask { ...@@ -58,9 +62,9 @@ public class SignalStatusTask {
tDeviceStatusInfo.setFaultType(currentFaultType); tDeviceStatusInfo.setFaultType(currentFaultType);
tDeviceStatusMapper.updateById(tDeviceStatusInfo); tDeviceStatusMapper.updateById(tDeviceStatusInfo);
} }
insertDeviceStatusLog(signalStatusLogDTO, signalId, currentSignalStatus, currentFaultType); insertDeviceStatusLog(signalStatusVO, crossId, currentSignalStatus, currentFaultType);
} }
insertControlHist(signalStatusLogDTO); insertControlHist(signalStatusVO);
}); });
} catch (Exception e) { } catch (Exception e) {
log.error("定时任务同步信号机设备状态远程utcService调用异常", e); log.error("定时任务同步信号机设备状态远程utcService调用异常", e);
...@@ -70,12 +74,12 @@ public class SignalStatusTask { ...@@ -70,12 +74,12 @@ public class SignalStatusTask {
/** /**
* 插入控制历史表 * 插入控制历史表
* *
* @param signalStatusLogDTO * @param signalStatusVO
*/ */
private void insertControlHist(SignalStatusLogDTO signalStatusLogDTO) { private void insertControlHist(SignalStatusVO signalStatusVO) {
// 更新控制历史表 // 更新控制历史表
String crossId = signalStatusLogDTO.getCrossId(); String crossId = signalStatusVO.getCrossId();
Integer controlType = signalStatusLogDTO.getControlType(); Integer controlType = signalStatusVO.getControlType();
TCrossControlHist tCrossControlHist = controlHistMapper.selectRecentOne(crossId); TCrossControlHist tCrossControlHist = controlHistMapper.selectRecentOne(crossId);
if (Objects.nonNull(tCrossControlHist) && !Objects.equals(controlType, tCrossControlHist.getType())) { if (Objects.nonNull(tCrossControlHist) && !Objects.equals(controlType, tCrossControlHist.getType())) {
controlHistMapper.insertOne(crossId, controlType, "未知"); controlHistMapper.insertOne(crossId, controlType, "未知");
...@@ -85,26 +89,28 @@ public class SignalStatusTask { ...@@ -85,26 +89,28 @@ public class SignalStatusTask {
/** /**
* 信号机状态插入设备日志表 * 信号机状态插入设备日志表
* *
* @param signalStatusLogDTO * @param signalStatusVO
* @param signalId * @param crossId
* @param currentSignalStatus * @param currentSignalStatus
* @param currentFaultType * @param currentFaultType
*/ */
private void insertDeviceStatusLog(SignalStatusLogDTO signalStatusLogDTO, String signalId, Integer currentSignalStatus, Integer currentFaultType) { private void insertDeviceStatusLog(SignalStatusVO signalStatusVO, String crossId, Integer currentSignalStatus, Integer currentFaultType) {
// 插入日志表 // 插入日志表
TDeviceStatusLog tDeviceStatusLogInfoDB = tDeviceStatusLogMapper.selectLastOne(signalId); TDeviceStatusLog tDeviceStatusLogInfoDB = tDeviceStatusLogMapper.selectLastOne(crossId);
// DB数据是故障,如果当前正常非故障,状态为 FaultType=100 故障已处理 // DB数据是故障,如果当前正常非故障,状态为 FaultType=100 故障已处理
if (Objects.nonNull(tDeviceStatusLogInfoDB) || tDeviceStatusLogInfoDB.getFaultType() != 0 && currentFaultType == 0) { if (Objects.nonNull(tDeviceStatusLogInfoDB) || tDeviceStatusLogInfoDB.getFaultType() != 0 && currentFaultType == 0) {
tDeviceStatusLogInfoDB.setStatus(currentSignalStatus); tDeviceStatusLogInfoDB.setStatus(currentSignalStatus);
tDeviceStatusLogInfoDB.setFaultType(100); tDeviceStatusLogInfoDB.setFaultType(100);
tDeviceStatusLogInfoDB.setId(null);
tDeviceStatusLogMapper.insert(tDeviceStatusLogInfoDB); tDeviceStatusLogMapper.insert(tDeviceStatusLogInfoDB);
} else { } else {
TDeviceStatusLog tDeviceStatusLog = new TDeviceStatusLog(); TDeviceStatusLog tDeviceStatusLog = new TDeviceStatusLog();
tDeviceStatusLog.setCode(signalId); tDeviceStatusLog.setCode(crossId);
tDeviceStatusLog.setName(signalStatusLogDTO.getSignalId()); tDeviceStatusLog.setName(signalStatusVO.getSignalId());
tDeviceStatusLog.setType(1); tDeviceStatusLog.setType(1);
tDeviceStatusLog.setStatus(signalStatusLogDTO.getStatus()); tDeviceStatusLog.setStatus(signalStatusVO.getStatus());
tDeviceStatusLog.setFaultType(currentFaultType); tDeviceStatusLog.setFaultType(currentFaultType);
tDeviceStatusLog.setId(null);
tDeviceStatusLogMapper.insert(tDeviceStatusLog); tDeviceStatusLogMapper.insert(tDeviceStatusLog);
} }
} }
......
...@@ -2,14 +2,24 @@ ...@@ -2,14 +2,24 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="net.wanji.web.mapper.TDeviceStatusLogMapper"> <mapper namespace="net.wanji.web.mapper.TDeviceStatusLogMapper">
<select id="selectLastOne"> <resultMap type="net.wanji.web.entity.TDeviceStatusLog" id="BaseResultMap">
<result property="id" column="id"/>
<result property="code" column="code"/>
<result property="name" column="name"/>
<result property="type" column="type"/>
<result property="status" column="status"/>
<result property="faultType" column="fault_type"/>
<result property="gmtCreate" column="gmt_create"/>
</resultMap>
<select id="selectLastOne" resultMap="BaseResultMap" parameterType="String">
select id, code, name, type, status,fault_type, gmt_create select id, code, name, type, status,fault_type, gmt_create
from t_device_status_log from t_device_status_log
<where> <where>
<if test="code != null and code != ''"> <if test="code != null and code != ''">
and code = #{code} and code = #{code}
</if> </if>
and gmt_create = select max(gmt_create) from t_device_status_log group by gmt_create desc limit 1
</where> </where>
</select> </select>
</mapper> </mapper>
\ No newline at end of file
...@@ -48,7 +48,7 @@ public class HkRunningStatusServiceImpl implements HkRunningStatusService { ...@@ -48,7 +48,7 @@ public class HkRunningStatusServiceImpl implements HkRunningStatusService {
JSONObject object = JSON.parseObject(strResult); JSONObject object = JSON.parseObject(strResult);
Object o = object.get("code"); Object o = object.get("code");
// 多信号机情况下,跳过返回信息不成功的获取返回消息成功的信号机数据 // 多信号机情况下,跳过返回信息不成功的获取返回消息成功的信号机数据
if (!Objects.equals(o, 0)) { if (!Objects.equals(String.valueOf(o), "0")) {
continue; continue;
} }
if (Constants.HK_SUCCESS_CODE.equals(object.getInteger(Constants.HK_CODE_KEY))) { if (Constants.HK_SUCCESS_CODE.equals(object.getInteger(Constants.HK_CODE_KEY))) {
...@@ -61,16 +61,19 @@ public class HkRunningStatusServiceImpl implements HkRunningStatusService { ...@@ -61,16 +61,19 @@ public class HkRunningStatusServiceImpl implements HkRunningStatusService {
po.setStatus(transferStatus(obj.getInteger("state"))); po.setStatus(transferStatus(obj.getInteger("state")));
// 告警信息 // 告警信息
Integer hasFault = obj.getInteger("hasFault"); Integer hasFault = obj.getInteger("hasFault");
if (hasFault == 0) { // if (hasFault == 0) {
po.setFaultType(hasFault); po.setFaultType(hasFault);
} // }
// 从Redis中查询控制类型 // 从Redis中查询控制类型
String lightsStatusVOStr = redisUtil.getHash(RedisKeyConst.KEY_PREFIX + RedisKeyConst.LIGHTS_STATUS, String lightsStatusVOStr = redisUtil.getHash(RedisKeyConst.KEY_PREFIX + RedisKeyConst.LIGHTS_STATUS,
baseCrossInfo.getManufacturerCode() + Constants.SEPARATOR_UNDER_LINE + po.getSignalId()); baseCrossInfo.getManufacturerCode() + Constants.SEPARATOR_UNDER_LINE + po.getSignalId());
LightsStatusVO lightsStatusVO = JSON.parseObject(lightsStatusVOStr, LightsStatusVO.class); LightsStatusVO lightsStatusVO = JSON.parseObject(lightsStatusVOStr, LightsStatusVO.class);
Integer controlType = 1;
if (Objects.nonNull(lightsStatusVO)) {
String runMode = lightsStatusVO.getRunMode(); String runMode = lightsStatusVO.getRunMode();
int runModeInt = Integer.parseInt(runMode); int runModeInt = Integer.parseInt(runMode);
Integer controlType = HkControlModeEnum.getCodeByHkCode(runModeInt); controlType = HkControlModeEnum.getCodeByHkCode(runModeInt);
}
po.setControlType(controlType); po.setControlType(controlType);
result.add(po); result.add(po);
} }
......
...@@ -76,10 +76,10 @@ public class BeanMapUtils { ...@@ -76,10 +76,10 @@ public class BeanMapUtils {
try { try {
bean = clazz.newInstance(); bean = clazz.newInstance();
for (Field field : getAllFields(clazz)) { for (Field field : getAllFields(clazz)) {
if (map.containsKey(humpToLine(field.getName()))) { if (map.containsKey(field.getName())) {
boolean flag = field.isAccessible(); boolean flag = field.isAccessible();
field.setAccessible(true); field.setAccessible(true);
Object object = map.get(humpToLine(field.getName())); Object object = map.get(field.getName());
if (object != null) { if (object != null) {
if (field.getType().isAssignableFrom(object.getClass())) { if (field.getType().isAssignableFrom(object.getClass())) {
field.set(bean, object); field.set(bean, object);
......
...@@ -257,4 +257,14 @@ ...@@ -257,4 +257,14 @@
#{id} #{id}
</foreach> </foreach>
</select> </select>
<select id="selectById" resultType="net.wanji.databus.po.CrossInfoPO">
select <include refid="baseColumn"/>
from t_base_cross_info
<where>
<if test="id != null and id != ''">
id = #{id}
</if>
</where>
</select>
</mapper> </mapper>
\ No newline at end of file
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