Commit af2428c0 authored by zhouleilei's avatar zhouleilei

控制指令新增日志

parent 87055487
...@@ -300,6 +300,7 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy ...@@ -300,6 +300,7 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String ip = IpAddressUtil.getIpAddress(request); String ip = IpAddressUtil.getIpAddress(request);
signalCommandLogPO.setIp(ip); signalCommandLogPO.setIp(ip);
log.info("服务器请求返回 信息jsonViewObject:{}",jsonViewObject);
int commandResult = 0; int commandResult = 0;
if (code == 200){ if (code == 200){
commandResult = 1; commandResult = 1;
...@@ -322,7 +323,12 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy ...@@ -322,7 +323,12 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy
signalCommandLogPO.setLampTime(lampTime); signalCommandLogPO.setLampTime(lampTime);
} }
} }
signalCommandLogPOMapper.insert(signalCommandLogPO); int insert = signalCommandLogPOMapper.insert(signalCommandLogPO);
if (insert > 0) {
log.info("定时任务 插入t_signal_command_log成功,crossId = {},commandType = {},time = {},insert = {}", jsonObject.getString("crossId"), commandType, LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER),insert);
}else {
log.info("定时任务 插入t_signal_command_log失败,crossId = {},commandType = {},time = {},insert = {}", jsonObject.getString("crossId"), commandType, LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER),insert);
}
//排除查询环图接口 //排除查询环图接口
if (commandType != 10){ if (commandType != 10){
LambdaQueryWrapper<SignalCommandPO> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SignalCommandPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
...@@ -332,7 +338,12 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy ...@@ -332,7 +338,12 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy
//插入 //插入
SignalCommandPO signalCommandPO = new SignalCommandPO(); SignalCommandPO signalCommandPO = new SignalCommandPO();
BeanUtil.copyProperties(signalCommandLogPO,signalCommandPO); BeanUtil.copyProperties(signalCommandLogPO,signalCommandPO);
signalCommandPOMapper.insert(signalCommandPO); int insert1 = signalCommandPOMapper.insert(signalCommandPO);
if (insert1 > 0) {
log.info("定时任务 插入t_signal_command成功,crossId = {},commandType = {},time = {},insert = {}", jsonObject.getString("crossId"), commandType, LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER),insert1);
}else {
log.info("定时任务 插入t_signal_command失败,crossId = {},commandType = {},time = {},insert = {}", jsonObject.getString("crossId"), commandType, LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER),insert1);
}
}else { }else {
//更新 //更新
SignalCommandPO signalCommandPO = signalCommandPOS.get(0); SignalCommandPO signalCommandPO = signalCommandPOS.get(0);
...@@ -343,7 +354,12 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy ...@@ -343,7 +354,12 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy
signalCommandPO.setIp(ip); signalCommandPO.setIp(ip);
signalCommandPO.setQueryTime(queryTime); signalCommandPO.setQueryTime(queryTime);
signalCommandPO.setUpdateCount(0); signalCommandPO.setUpdateCount(0);
signalCommandPOMapper.update(signalCommandPO,lambdaQueryWrapper); int update = signalCommandPOMapper.update(signalCommandPO, lambdaQueryWrapper);
if (update > 0) {
log.info("定时任务 更新t_signal_command成功,crossId = {},commandType = {},time = {},update = {}", jsonObject.getString("crossId"), commandType, LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER),update);
}else {
log.info("定时任务 更新t_signal_command失败,crossId = {},commandType = {},time = {},update = {}", jsonObject.getString("crossId"), commandType, LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER),update);
}
} }
} }
} }
...@@ -367,11 +383,15 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy ...@@ -367,11 +383,15 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy
if (StringUtils.isBlank(crossId)) { if (StringUtils.isBlank(crossId)) {
return jsonViewObject.fail("路口编号不能为空"); return jsonViewObject.fail("路口编号不能为空");
} }
String manufacturerIdCode = crossInfoCache.getManufacturerCodeByCrossId(crossId); try {
if (StringUtils.equals(BasicEnum.ManufacturerEnum.HK.getCode(), manufacturerIdCode)) { String manufacturerIdCode = crossInfoCache.getManufacturerCodeByCrossId(crossId);
jsonViewObject = hkControlCommandService.recoverSchedule(crossId); if (StringUtils.equals(BasicEnum.ManufacturerEnum.HK.getCode(), manufacturerIdCode)) {
} else { jsonViewObject = hkControlCommandService.recoverSchedule(crossId);
jsonViewObject = wanJiControlCommandService.recoverSchedule(crossId); } else {
jsonViewObject = wanJiControlCommandService.recoverSchedule(crossId);
}
} catch (Exception e) {
jsonViewObject = JsonViewObject.newInstance().fail(e.getMessage());
} }
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("crossId",crossId); jsonObject.put("crossId",crossId);
......
...@@ -19,8 +19,6 @@ import net.wanji.utc.common.typeenum.BasicEnum; ...@@ -19,8 +19,6 @@ import net.wanji.utc.common.typeenum.BasicEnum;
import net.wanji.utc.service.control.ControlCommandService; import net.wanji.utc.service.control.ControlCommandService;
import net.wanji.utc.service.control.ControlCommandStrategyService; import net.wanji.utc.service.control.ControlCommandStrategyService;
import net.wanji.utc.util.StringUtils; import net.wanji.utc.util.StringUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -36,7 +34,6 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -36,7 +34,6 @@ import java.util.concurrent.ConcurrentHashMap;
*/ */
@Component @Component
@Slf4j @Slf4j
@EnableAsync
@SuppressWarnings("all") @SuppressWarnings("all")
public class CommandFaildTask { public class CommandFaildTask {
@Resource @Resource
...@@ -54,26 +51,25 @@ public class CommandFaildTask { ...@@ -54,26 +51,25 @@ public class CommandFaildTask {
private SignalCommandLogPOMapper signalCommandLogPOMapper; private SignalCommandLogPOMapper signalCommandLogPOMapper;
@Scheduled(cron = "0/5 * * * * ?") @Scheduled(cron = "0/5 * * * * ?")
@Async
public void commandFaildTask() throws Exception { public void commandFaildTask() throws Exception {
LambdaQueryWrapper<SignalCommandPO> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SignalCommandPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(SignalCommandPO::getCommandResult, 2); lambdaQueryWrapper.eq(SignalCommandPO::getCommandResult, 2);
List<SignalCommandPO> crossInfoPOList = signalCommandPOMapper.selectList(lambdaQueryWrapper); List<SignalCommandPO> crossInfoPOList = signalCommandPOMapper.selectList(lambdaQueryWrapper);
log.info("定时任务恢复控制指令,需要执行恢复路口集合crossInfoPOList = {}", crossInfoPOList);
if (ObjectUtil.isNotEmpty(crossInfoPOList)) { if (ObjectUtil.isNotEmpty(crossInfoPOList)) {
for (SignalCommandPO signalCommandPO : crossInfoPOList) { for (SignalCommandPO signalCommandPO : crossInfoPOList) {
String crossId = signalCommandPO.getCrossId(); String crossId = signalCommandPO.getCrossId();
Integer commandType = signalCommandPO.getCommandType(); Integer commandType = signalCommandPO.getCommandType();
Integer updateCount = signalCommandPO.getUpdateCount(); Integer updateCount = signalCommandPO.getUpdateCount();
if (ObjectUtil.isNull(updateCount)){ if (ObjectUtil.isNull(updateCount)) {
updateCount = 0; updateCount = 0;
} }
try { try {
log.info("定时任务自动恢复开始执行(不保证恢复成功),crossId={},commandType={},updateCount={}", crossId, commandType, updateCount);
//处理数据 //处理数据
handlerCommand(crossId, commandType,updateCount); handlerCommand(crossId, commandType, updateCount);
log.info("定时任务自动恢复执行成功(不保证恢复成功),crossId={},commandType={},updateCount={}",crossId,commandType,updateCount);
} catch (Exception e) { } catch (Exception e) {
log.error("定时任务自动恢复报错,crossId={},commandType={},updateCount={}",crossId,commandType,updateCount); log.error("定时任务自动恢复报错,crossId={},commandType={},updateCount={}", crossId, commandType, updateCount);
throw new RuntimeException(e);
} }
} }
} }
...@@ -85,24 +81,24 @@ public class CommandFaildTask { ...@@ -85,24 +81,24 @@ public class CommandFaildTask {
* @Param crossId 路口编号 * @Param crossId 路口编号
* @Param commandType 控制模式 * @Param commandType 控制模式
**/ **/
private void handlerCommand(String crossId, Integer commandType,int updateCount) { private void handlerCommand(String crossId, Integer commandType, int updateCount) {
switch (commandType) { switch (commandType) {
//1-步进控制/恢复(公用);2-恢复时间表(公用);3-相位锁定/解锁(公用);4-临时方案下发(公用);5-下发命令失败,程序下发恢复指令;10-查询环图失败记录', //1-步进控制/恢复(公用);2-恢复时间表(公用);3-相位锁定/解锁(公用);4-临时方案下发(公用);5-下发命令失败,程序下发恢复指令;10-查询环图失败记录',
case 1: case 1:
//恢复步进 //恢复步进
recoverStepControlStrategy(crossId,updateCount,commandType); recoverStepControlStrategy(crossId, updateCount, commandType);
break; break;
case 2: case 2:
//恢复时间表 //恢复时间表
recoverScheduleStrategy(crossId,updateCount,commandType); recoverScheduleStrategy(crossId, updateCount, commandType);
break; break;
case 3: case 3:
//相位解锁 //相位解锁
recoverLockControlStrategy(crossId,updateCount,commandType); recoverLockControlStrategy(crossId, updateCount, commandType);
break; break;
case 4: case 4:
//恢复 临时方案下发 //恢复 临时方案下发
recoverScheduleStrategy(crossId, updateCount,commandType); recoverScheduleStrategy(crossId, updateCount, commandType);
break; break;
default: default:
log.error("commandType有误,crossId={},commandType={}", crossId, commandType); log.error("commandType有误,crossId={},commandType={}", crossId, commandType);
...@@ -116,9 +112,13 @@ public class CommandFaildTask { ...@@ -116,9 +112,13 @@ public class CommandFaildTask {
* @Description 恢复步进 * @Description 恢复步进
* @Param crossId * @Param crossId
**/ **/
private void recoverStepControlStrategy(String crossId,int updateCount,int commandType) { private void recoverStepControlStrategy(String crossId, int updateCount, int commandType) {
String now = LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER); String now = LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER);
JsonViewObject jsonViewObject; JsonViewObject jsonViewObject;
JSONObject jsonObject = new JSONObject();
jsonObject.put("crossId", crossId);
jsonObject.put("command", 0);
jsonObject.put("stepNum", 0);
try { try {
String manufacturerIdCode = crossInfoCache.getManufacturerCodeByCrossId(crossId); String manufacturerIdCode = crossInfoCache.getManufacturerCodeByCrossId(crossId);
if (StringUtils.equals(BasicEnum.ManufacturerEnum.HK.getCode(), manufacturerIdCode)) { if (StringUtils.equals(BasicEnum.ManufacturerEnum.HK.getCode(), manufacturerIdCode)) {
...@@ -127,14 +127,11 @@ public class CommandFaildTask { ...@@ -127,14 +127,11 @@ public class CommandFaildTask {
jsonViewObject = wanJiControlCommandService.stepControl(crossId, 0, 0); jsonViewObject = wanJiControlCommandService.stepControl(crossId, 0, 0);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("定时任务 恢复步进出错,crossId={}", crossId);
jsonViewObject = JsonViewObject.newInstance().fail(e.getMessage()); jsonViewObject = JsonViewObject.newInstance().fail(e.getMessage());
} }
JSONObject jsonObject = new JSONObject();
jsonObject.put("crossId", crossId);
jsonObject.put("command", 0);
jsonObject.put("stepNum", 0);
//插入命令操作日志 //插入命令操作日志
insertCommandLog(now, jsonViewObject, jsonObject,commandType,updateCount); insertCommandLog(now, jsonViewObject, jsonObject, commandType, updateCount);
} }
/** /**
...@@ -143,24 +140,24 @@ public class CommandFaildTask { ...@@ -143,24 +140,24 @@ public class CommandFaildTask {
* @Param crossId * @Param crossId
**/ **/
private void recoverScheduleStrategy(String crossId,int updateCount,int commandType) { private void recoverScheduleStrategy(String crossId, int updateCount, int commandType) {
String now = LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER);
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
JSONObject jsonObject = new JSONObject();
jsonObject.put("crossId", crossId);
try { try {
String now = LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER);
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
String manufacturerIdCode = crossInfoCache.getManufacturerCodeByCrossId(crossId); String manufacturerIdCode = crossInfoCache.getManufacturerCodeByCrossId(crossId);
if (StringUtils.equals(BasicEnum.ManufacturerEnum.HK.getCode(), manufacturerIdCode)) { if (StringUtils.equals(BasicEnum.ManufacturerEnum.HK.getCode(), manufacturerIdCode)) {
jsonViewObject = hkControlCommandService.recoverSchedule(crossId); jsonViewObject = hkControlCommandService.recoverSchedule(crossId);
} else { } else {
jsonViewObject = wanJiControlCommandService.recoverSchedule(crossId); jsonViewObject = wanJiControlCommandService.recoverSchedule(crossId);
} }
JSONObject jsonObject = new JSONObject();
jsonObject.put("crossId",crossId);
//插入命令操作日志
insertCommandLog(now,jsonViewObject, jsonObject,commandType,updateCount);
} catch (Exception e) { } catch (Exception e) {
log.error("定时任务 恢复时间表出错,crossId={}",crossId); log.error("定时任务 恢复时间表出错,crossId={}", crossId);
throw new RuntimeException(e); jsonViewObject = JsonViewObject.newInstance().fail(e.getMessage());
} }
//插入命令操作日志
insertCommandLog(now, jsonViewObject, jsonObject, commandType, updateCount);
} }
/** /**
...@@ -169,13 +166,15 @@ public class CommandFaildTask { ...@@ -169,13 +166,15 @@ public class CommandFaildTask {
* @Param crossId * @Param crossId
**/ **/
private void recoverLockControlStrategy(String crossId,int updateCount,int commandType) { private void recoverLockControlStrategy(String crossId, int updateCount, int commandType) {
String now = LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER); String now = LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER);
JsonViewObject jsonViewObject; JsonViewObject jsonViewObject;
ControlCommandVO commandVO = new ControlCommandVO(); ControlCommandVO commandVO = new ControlCommandVO();
commandVO.setCrossCode(crossId); commandVO.setCrossCode(crossId);
commandVO.setCommand(0); commandVO.setCommand(0);
commandVO.setDuration(0); commandVO.setDuration(0);
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(commandVO));
jsonObject.put("crossId", commandVO.getCrossCode());
try { try {
String manufacturerIdCode = crossInfoCache.getManufacturerCodeByCrossId(commandVO.getCrossCode()); String manufacturerIdCode = crossInfoCache.getManufacturerCodeByCrossId(commandVO.getCrossCode());
if (StringUtils.equals(BasicEnum.ManufacturerEnum.HK.getCode(), manufacturerIdCode)) { if (StringUtils.equals(BasicEnum.ManufacturerEnum.HK.getCode(), manufacturerIdCode)) {
...@@ -185,11 +184,10 @@ public class CommandFaildTask { ...@@ -185,11 +184,10 @@ public class CommandFaildTask {
} }
} catch (Exception e) { } catch (Exception e) {
jsonViewObject = JsonViewObject.newInstance().fail(e.getMessage()); jsonViewObject = JsonViewObject.newInstance().fail(e.getMessage());
log.error("定时任务 恢复临时方案下发出错,crossId={}", crossId);
} }
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(commandVO));
jsonObject.put("crossId",commandVO.getCrossCode());
//插入命令操作日志 //插入命令操作日志
insertCommandLog(now,jsonViewObject, jsonObject,commandType,updateCount); insertCommandLog(now, jsonViewObject, jsonObject, commandType, updateCount);
} }
/** /**
...@@ -199,8 +197,8 @@ public class CommandFaildTask { ...@@ -199,8 +197,8 @@ public class CommandFaildTask {
* @Param jsonViewObject 操作结果 * @Param jsonViewObject 操作结果
* @Param jsonObject 参数 * @Param jsonObject 参数
**/ **/
public void insertCommandLog(String queryTime, JsonViewObject jsonViewObject, JSONObject jsonObject, int commandType,int updateCount) { public void insertCommandLog(String queryTime, JsonViewObject jsonViewObject, JSONObject jsonObject, int commandType, int updateCount) {
updateCount = updateCount+1; updateCount = updateCount + 1;
SignalCommandLogPO signalCommandLogPO = new SignalCommandLogPO(); SignalCommandLogPO signalCommandLogPO = new SignalCommandLogPO();
signalCommandLogPO.setCrossId(jsonObject.getString("crossId")); signalCommandLogPO.setCrossId(jsonObject.getString("crossId"));
signalCommandLogPO.setDataInfo(jsonObject.toJSONString()); signalCommandLogPO.setDataInfo(jsonObject.toJSONString());
...@@ -210,20 +208,20 @@ public class CommandFaildTask { ...@@ -210,20 +208,20 @@ public class CommandFaildTask {
Integer code = jsonViewObject.getCode(); Integer code = jsonViewObject.getCode();
String ip = "localhost"; String ip = "localhost";
signalCommandLogPO.setIp(ip); signalCommandLogPO.setIp(ip);
log.info("定时任务返回 信息jsonViewObject:{}", jsonViewObject);
if (code == 200) { if (code == 200) {
signalCommandLogPO.setCommandResult(1); signalCommandLogPO.setCommandResult(1);
signalCommandLogPO.setUpdateCount(0); signalCommandLogPO.setUpdateCount(0);
} else { } else {
if (updateCount >= 24){ if (updateCount >= 24) {
//如果两分钟更新失败,则将状态设置为3 //如果两分钟更新失败,则将状态设置为3
signalCommandLogPO.setCommandResult(3); signalCommandLogPO.setCommandResult(3);
}else { signalCommandLogPO.setUpdateCount(0);
} else {
signalCommandLogPO.setCommandResult(2); signalCommandLogPO.setCommandResult(2);
} }
} }
signalCommandLogPO.setResultMessage(jsonViewObject.getMessage()); signalCommandLogPO.setResultMessage(jsonViewObject.getMessage());
ConcurrentHashMap<String, List<LightsStatusVO2>> produceListMap = SignalStatusTask.produceListMap; ConcurrentHashMap<String, List<LightsStatusVO2>> produceListMap = SignalStatusTask.produceListMap;
if (!produceListMap.isEmpty()) { if (!produceListMap.isEmpty()) {
List<LightsStatusVO2> list = produceListMap.get(jsonObject.get("crossId")); List<LightsStatusVO2> list = produceListMap.get(jsonObject.get("crossId"));
...@@ -238,14 +236,24 @@ public class CommandFaildTask { ...@@ -238,14 +236,24 @@ public class CommandFaildTask {
} }
} }
//插入日志表 //插入日志表
signalCommandLogPOMapper.insert(signalCommandLogPO); int insert = signalCommandLogPOMapper.insert(signalCommandLogPO);
if (insert > 0) {
log.info("定时任务 插入t_signal_command_log成功,crossId = {},commandType = {},time = {},insert = {}", jsonObject.getString("crossId"), commandType, LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER),insert);
}else {
log.info("定时任务 插入t_signal_command_log失败,crossId = {},commandType = {},time = {},insert = {}", jsonObject.getString("crossId"), commandType, LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER),insert);
}
SignalCommandPO signalCommandPO = new SignalCommandPO(); SignalCommandPO signalCommandPO = new SignalCommandPO();
BeanUtil.copyProperties(signalCommandLogPO, signalCommandPO); BeanUtil.copyProperties(signalCommandLogPO, signalCommandPO);
signalCommandPO.setCommandType(commandType); signalCommandPO.setCommandType(commandType);
//更新状态表 //更新状态表
LambdaQueryWrapper<SignalCommandPO> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SignalCommandPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(SignalCommandPO::getCrossId,jsonObject.getString("crossId")); lambdaQueryWrapper.eq(SignalCommandPO::getCrossId, jsonObject.getString("crossId"));
signalCommandPOMapper.update(signalCommandPO,lambdaQueryWrapper); int update = signalCommandPOMapper.update(signalCommandPO, lambdaQueryWrapper);
if (update > 0) {
log.info("定时任务 更新t_signal_command成功,crossId = {},commandType = {},time = {},update = {}", jsonObject.getString("crossId"), commandType, LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER),update);
}else {
log.info("定时任务 更新t_signal_command失败,crossId = {},commandType = {},time = {},update = {}", jsonObject.getString("crossId"), commandType, LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER),update);
}
} }
} }
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