Commit 748d9bf8 authored by zhoushiguang's avatar zhoushiguang
parents f7baaa67 62936068
...@@ -9,8 +9,9 @@ import lombok.Getter; ...@@ -9,8 +9,9 @@ import lombok.Getter;
*/ */
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum CrossOptStrategyEnum { public enum CrossOptResultStrategyEnum {
ZERO(0, "无策略"), // 优化策略
ZERO(0, "均衡调控"),
ONE(1, "绿灯空放"), ONE(1, "绿灯空放"),
TWO(2, "失衡"), TWO(2, "失衡"),
THREE(3, "溢出"); THREE(3, "溢出");
...@@ -19,11 +20,11 @@ public enum CrossOptStrategyEnum { ...@@ -19,11 +20,11 @@ public enum CrossOptStrategyEnum {
private String desc; private String desc;
public static String getDesc(int code) { public static String getDesc(int code) {
for (CrossOptStrategyEnum value : CrossOptStrategyEnum.values()) { for (CrossOptResultStrategyEnum value : CrossOptResultStrategyEnum.values()) {
if (code == value.code) { if (code == value.code) {
return value.getDesc(); return value.getDesc();
} }
} }
return "无策略"; return CrossOptResultStrategyEnum.ZERO.getDesc();
} }
} }
...@@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.*; ...@@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
...@@ -153,6 +154,45 @@ public class InduceSendController { ...@@ -153,6 +154,45 @@ public class InduceSendController {
.body("程序查询错误请联系管理员".getBytes(StandardCharsets.UTF_8)); .body("程序查询错误请联系管理员".getBytes(StandardCharsets.UTF_8));
} }
} }
@ApiOperation(value = "根据设备编号和发布时间获取诱导发布图片", notes = "根据设备编号和发布时间获取诱导发布图片")
@GetMapping(value = "/fileCodeHist")
public ResponseEntity<byte[]> ftpFileByCodeAndTime(@RequestParam("equipCode") String equipCode, @RequestParam("date") Date date) {
LambdaQueryWrapper<InduceHist> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(InduceHist::getEquipCode, equipCode);
queryWrapper.le(InduceHist::getCreateTime, date);
queryWrapper.orderByDesc(InduceHist::getCreateTime);
queryWrapper.last("limit 1");
InduceHist pictureFile = this.induceHistService.getOne(queryWrapper,false);
if (Objects.isNull(pictureFile) || pictureFile.getFilePath() == null) {
return ResponseEntity.status(HttpStatus.OK)
.body("无效的文件ID".getBytes(StandardCharsets.UTF_8));
}
try {
// 获取ftp服务器图片
byte[] imageBytes = this.induceSendService.downloadImage(pictureFile.getFilePath());
if (imageBytes != null && imageBytes.length > 0) {
// 设置响应头
HttpHeaders headers = new HttpHeaders();
// 图片类型
headers.set("Content-Type", "image/jpeg");
// 设置内容长度
headers.set("Content-Length", String.valueOf(imageBytes.length));
// 设置文件名
headers.set("Content-Disposition", "inline; filename=\"" + pictureFile.getSourceId() + ".bmp\"");
// 返回响应
return new ResponseEntity<>(imageBytes, headers, HttpStatus.OK);
} else {
return ResponseEntity.status(HttpStatus.OK)
.body("未查询到对应文件".getBytes(StandardCharsets.UTF_8));
}
} catch (IOException e) {
log.error("ftp文件下载失败: ", e.getMessage());
return ResponseEntity.status(HttpStatus.OK)
.body("程序查询错误请联系管理员".getBytes(StandardCharsets.UTF_8));
}
}
/** /**
* 获取ftp图片 * 获取ftp图片
*/ */
......
...@@ -10,7 +10,7 @@ import net.wanji.databus.dao.mapper.CrossDataRealtimeMapper; ...@@ -10,7 +10,7 @@ import net.wanji.databus.dao.mapper.CrossDataRealtimeMapper;
import net.wanji.databus.dao.mapper.CrossDirDataHistMapper; import net.wanji.databus.dao.mapper.CrossDirDataHistMapper;
import net.wanji.databus.dao.mapper.CrossDirDataRealtimeMapper; import net.wanji.databus.dao.mapper.CrossDirDataRealtimeMapper;
import net.wanji.databus.po.*; import net.wanji.databus.po.*;
import net.wanji.opt.common.enums.CrossOptStrategyEnum; import net.wanji.opt.common.enums.CrossOptResultStrategyEnum;
import net.wanji.opt.common.enums.OptStatusEnum; import net.wanji.opt.common.enums.OptStatusEnum;
import net.wanji.opt.common.enums.StrategyControlEnum; import net.wanji.opt.common.enums.StrategyControlEnum;
import net.wanji.opt.dao.mapper.HoloEventMapper; import net.wanji.opt.dao.mapper.HoloEventMapper;
...@@ -95,7 +95,6 @@ public class CrossIndexServiceImpl implements CrossIndexService { ...@@ -95,7 +95,6 @@ public class CrossIndexServiceImpl implements CrossIndexService {
for (StrategyCrossResultEntity entity : list) { for (StrategyCrossResultEntity entity : list) {
CrossOptResult crossOptResult = new CrossOptResult(); CrossOptResult crossOptResult = new CrossOptResult();
Date date = entity.getIssueTime(); Date date = entity.getIssueTime();
//Date date = DateUtil.parse(entity.getIssueTime(), "yyyy-MM-dd HH:mm:ss");
crossOptResult.setTimeStamp(date); crossOptResult.setTimeStamp(date);
Integer countDown = entity.getCountDown(); Integer countDown = entity.getCountDown();
if (entity.getCurrentAlgo() == 2) { if (entity.getCurrentAlgo() == 2) {
...@@ -104,7 +103,7 @@ public class CrossIndexServiceImpl implements CrossIndexService { ...@@ -104,7 +103,7 @@ public class CrossIndexServiceImpl implements CrossIndexService {
crossOptResult.setCountDown(countDown); crossOptResult.setCountDown(countDown);
Integer currentAlgo = entity.getCurrentAlgo(); Integer currentAlgo = entity.getCurrentAlgo();
crossOptResult.setStrategy(currentAlgo); crossOptResult.setStrategy(currentAlgo);
crossOptResult.setStrategyName(CrossOptStrategyEnum.getDesc(currentAlgo)); crossOptResult.setStrategyName(CrossOptResultStrategyEnum.getDesc(currentAlgo));
crossOptResults.add(crossOptResult); crossOptResults.add(crossOptResult);
} }
} }
...@@ -172,13 +171,13 @@ public class CrossIndexServiceImpl implements CrossIndexService { ...@@ -172,13 +171,13 @@ public class CrossIndexServiceImpl implements CrossIndexService {
for (Map.Entry<Integer, List<StrategyCrossResultEntity>> entry : listMap.entrySet()) { for (Map.Entry<Integer, List<StrategyCrossResultEntity>> entry : listMap.entrySet()) {
Integer currentAlgo = entry.getKey(); Integer currentAlgo = entry.getKey();
List<StrategyCrossResultEntity> value = entry.getValue(); List<StrategyCrossResultEntity> value = entry.getValue();
if (Objects.equals(currentAlgo, CrossOptStrategyEnum.ONE.getCode())) { if (Objects.equals(currentAlgo, CrossOptResultStrategyEnum.ONE.getCode())) {
crossStatusCountVO.setPhaseEmptyCount(value.size()); crossStatusCountVO.setPhaseEmptyCount(value.size());
} }
if (Objects.equals(currentAlgo, CrossOptStrategyEnum.TWO.getCode())) { if (Objects.equals(currentAlgo, CrossOptResultStrategyEnum.TWO.getCode())) {
crossStatusCountVO.setUnbalanceCount(value.size()); crossStatusCountVO.setUnbalanceCount(value.size());
} }
if (Objects.equals(currentAlgo, CrossOptStrategyEnum.THREE.getCode())) { if (Objects.equals(currentAlgo, CrossOptResultStrategyEnum.THREE.getCode())) {
crossStatusCountVO.setOverFlowCount(value.size()); crossStatusCountVO.setOverFlowCount(value.size());
} }
} }
......
...@@ -138,11 +138,12 @@ public class GreenBeltServiceImpl implements GreenBeltInfoService { ...@@ -138,11 +138,12 @@ public class GreenBeltServiceImpl implements GreenBeltInfoService {
detail.setStartTime(dirDataHistPO.getStartTime()); detail.setStartTime(dirDataHistPO.getStartTime());
detail.setGreenTimeRatio(greenTimeRatio); detail.setGreenTimeRatio(greenTimeRatio);
for (GreenBeltKeyCrossFlowTimeVO.Detail optResult : optResults) { for (GreenBeltKeyCrossFlowTimeVO.Detail optResult : optResults) {
Integer curDir = GreenBeltDirEnum.getInDir(optResult.getDir());
if (StringUtils.equalsIgnoreCase("cancel", optResult.getDir()) && Objects.equals(curDir, dirType) if (StringUtils.equalsIgnoreCase("cancel", optResult.getDir())
&& dirDataHistPO.getStartTime().getTime() == optResult.getStartTime().getTime()) { && dirDataHistPO.getStartTime().getTime() == optResult.getStartTime().getTime()) {
greenTimeRatio = 0.0; greenTimeRatio = 0.0;
} }
Integer curDir = GreenBeltDirEnum.getInDir(optResult.getDir());
if (StringUtils.equalsIgnoreCase(crossId, optResult.getCrossId()) && Objects.equals(curDir, dirType) if (StringUtils.equalsIgnoreCase(crossId, optResult.getCrossId()) && Objects.equals(curDir, dirType)
&& dirDataHistPO.getStartTime().getTime() == optResult.getStartTime().getTime()) { && dirDataHistPO.getStartTime().getTime() == optResult.getStartTime().getTime()) {
detail.setGreenTimeRatio(optResult.getGreenTimeRatio() * 100); detail.setGreenTimeRatio(optResult.getGreenTimeRatio() * 100);
...@@ -262,7 +263,6 @@ public class GreenBeltServiceImpl implements GreenBeltInfoService { ...@@ -262,7 +263,6 @@ public class GreenBeltServiceImpl implements GreenBeltInfoService {
LambdaQueryWrapper<StrategyGreenOptHistEntity> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<StrategyGreenOptHistEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StrategyGreenOptHistEntity::getGreenId, greenId); queryWrapper.eq(StrategyGreenOptHistEntity::getGreenId, greenId);
queryWrapper.ge(StrategyGreenOptHistEntity::getControlTime, startOfDay); queryWrapper.ge(StrategyGreenOptHistEntity::getControlTime, startOfDay);
queryWrapper.ge(StrategyGreenOptHistEntity::getControlMethod, 1);
List<StrategyGreenOptHistEntity> entities = strategyGreenOptHistMapper.selectList(queryWrapper); List<StrategyGreenOptHistEntity> entities = strategyGreenOptHistMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(greenwaveHistPOS)) { if (!CollectionUtils.isEmpty(greenwaveHistPOS)) {
Map<String, List<GreenwaveHistPO>> greenDirMap = greenwaveHistPOS.stream().collect(Collectors.groupingBy(GreenwaveHistPO::getRoadDirection)); Map<String, List<GreenwaveHistPO>> greenDirMap = greenwaveHistPOS.stream().collect(Collectors.groupingBy(GreenwaveHistPO::getRoadDirection));
...@@ -289,7 +289,7 @@ public class GreenBeltServiceImpl implements GreenBeltInfoService { ...@@ -289,7 +289,7 @@ public class GreenBeltServiceImpl implements GreenBeltInfoService {
&& minuteDate.getTime() == startTimeminuteDate.getTime()) { && minuteDate.getTime() == startTimeminuteDate.getTime()) {
greenWidthTime = entity.getGreenWidthTime(); greenWidthTime = entity.getGreenWidthTime();
} }
if (entity.getControlMethod() <= 0) { if (entity.getControlMethod() < 0 && minuteDate.getTime() == startTimeminuteDate.getTime()) {
greenWidthTime = 0.0; greenWidthTime = 0.0;
} }
} }
......
...@@ -259,6 +259,9 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -259,6 +259,9 @@ public class StrategyControlServiceImpl implements StrategyControlService {
StrategyControlDataEntity strategyControlDataEntity = strategyList.get(0); StrategyControlDataEntity strategyControlDataEntity = strategyList.get(0);
histVO.setStrategy(strategyControlDataEntity.getStrategy()); histVO.setStrategy(strategyControlDataEntity.getStrategy());
histVO.setStrategyName("绿波带"); histVO.setStrategyName("绿波带");
} else {
histVO.setStrategy(0);
histVO.setStrategyName("绿波带");
} }
histVO.setOptTime(entity.getControlTime()); histVO.setOptTime(entity.getControlTime());
histVO.setResult(Objects.equals(1, entity.getControlMethod()) ? "失败" : "成功"); histVO.setResult(Objects.equals(1, entity.getControlMethod()) ? "失败" : "成功");
...@@ -313,6 +316,7 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -313,6 +316,7 @@ public class StrategyControlServiceImpl implements StrategyControlService {
} }
strategyControlDataEntity.setCrossName(greenwaveInfoPO.getName()); strategyControlDataEntity.setCrossName(greenwaveInfoPO.getName());
strategyControlDataEntity.setWkt(greenwaveInfoPO.getWkt()); strategyControlDataEntity.setWkt(greenwaveInfoPO.getWkt());
strategyControlDataEntity.setOptMethod("效率提升");
results.add(strategyControlDataEntity); results.add(strategyControlDataEntity);
} }
} }
...@@ -366,8 +370,6 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -366,8 +370,6 @@ public class StrategyControlServiceImpl implements StrategyControlService {
queryWrapper.eq(StrategyControlDataEntity::getBizType, type); queryWrapper.eq(StrategyControlDataEntity::getBizType, type);
queryWrapper.le(StrategyControlDataEntity::getScheduleStart, current); queryWrapper.le(StrategyControlDataEntity::getScheduleStart, current);
queryWrapper.ge(StrategyControlDataEntity::getScheduleEnd, current); queryWrapper.ge(StrategyControlDataEntity::getScheduleEnd, current);
//queryWrapper.ge(StrategyControlDataEntity::getScheduleStart, current);
//queryWrapper.le(StrategyControlDataEntity::getScheduleEnd, current);
List<StrategyControlDataEntity> entities = strategyControlInfoMapper.selectList(queryWrapper); List<StrategyControlDataEntity> entities = strategyControlInfoMapper.selectList(queryWrapper);
List<StrategyControlDataEntity> results = new ArrayList<>(entities.size()); List<StrategyControlDataEntity> results = new ArrayList<>(entities.size());
for (StrategyControlDataEntity entity : entities) { for (StrategyControlDataEntity entity : entities) {
......
package net.wanji.opt.vo; package net.wanji.opt.vo;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import net.wanji.opt.config.Double2TwoDecimalPlacesSerializer;
/** /**
* @author Kent HAN * @author Kent HAN
...@@ -20,6 +22,7 @@ public class MainlineEvaluateBottomCurveVO { ...@@ -20,6 +22,7 @@ public class MainlineEvaluateBottomCurveVO {
private String scopeName; private String scopeName;
@ApiModelProperty(value = "数值") @ApiModelProperty(value = "数值")
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
private Double value; private Double value;
@ApiModelProperty(value = "指标时间戳") @ApiModelProperty(value = "指标时间戳")
......
...@@ -33,6 +33,7 @@ import org.springframework.stereotype.Service; ...@@ -33,6 +33,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -235,9 +236,9 @@ public class ControlCommandServiceImpl implements ControlCommandService { ...@@ -235,9 +236,9 @@ public class ControlCommandServiceImpl implements ControlCommandService {
// boolean isOk = true; // boolean isOk = true;
if (isOk) { if (isOk) {
return jsonViewObject.fail("第 "+i+1+" 次相位步进失败,取消步进成功,路口号: " + code); return jsonViewObject.fail("第 "+ (i+1) +" 次相位步进失败,取消步进成功,路口号: " + code);
} else { } else {
return jsonViewObject.fail("第 "+i+1+" 次相位步进失败,取消步进失败,路口号: " + code); return jsonViewObject.fail("第 "+ (i+1) +" 次相位步进失败,取消步进失败,路口号: " + code);
} }
} }
//停顿10ms //停顿10ms
...@@ -252,9 +253,9 @@ public class ControlCommandServiceImpl implements ControlCommandService { ...@@ -252,9 +253,9 @@ public class ControlCommandServiceImpl implements ControlCommandService {
// boolean isOk = true; // boolean isOk = true;
if (isOk) { if (isOk) {
return jsonViewObject.fail("第 "+i+1+" 次相位步进失败,但取消步进成功,路口号: " + code); return jsonViewObject.fail("第 "+(i+1)+" 次相位步进失败,但取消步进成功,路口号: " + code);
} else { } else {
return jsonViewObject.fail("第 "+i+1+" 次相位步进失败,取消步进失败,路口号: " + code); return jsonViewObject.fail("第 "+(i+1)+" 次相位步进失败,取消步进失败,路口号: " + code);
} }
} }
......
...@@ -262,8 +262,9 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy ...@@ -262,8 +262,9 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy
@Override @Override
public JsonViewObject stepControlStrategy(String crossId, Integer command, Integer stepNum) throws Exception { public JsonViewObject stepControlStrategy(String crossId, Integer command, Integer stepNum) throws Exception {
String now = LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER);
JsonViewObject jsonViewObject; JsonViewObject jsonViewObject;
try {
String now = LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER);
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)) {
...@@ -280,6 +281,10 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy ...@@ -280,6 +281,10 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy
jsonObject.put("stepNum",stepNum); jsonObject.put("stepNum",stepNum);
//插入命令操作日志 //插入命令操作日志
insertCommandLog(now,jsonViewObject, jsonObject,1); insertCommandLog(now,jsonViewObject, jsonObject,1);
} catch (Exception e) {
log.error("stepControlStrategy步进控制远程服务调用异常:", e);
jsonViewObject = JsonViewObject.newInstance().fail("步进控制远程服务调用异常");
}
return jsonViewObject; return jsonViewObject;
} }
...@@ -290,7 +295,8 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy ...@@ -290,7 +295,8 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy
* @Param jsonObject 参数 * @Param jsonObject 参数
* @return void * @return void
**/ **/
public void insertCommandLog(String queryTime,JsonViewObject jsonViewObject, JSONObject jsonObject,int commandType){ public void insertCommandLog(String queryTime,JsonViewObject jsonViewObject, JSONObject jsonObject,int commandType) throws Exception{
try {
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());
...@@ -300,6 +306,7 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy ...@@ -300,6 +306,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("insertCommandLog服务器请求返回 信息jsonViewObject:{}",jsonViewObject);
int commandResult = 0; int commandResult = 0;
if (code == 200){ if (code == 200){
commandResult = 1; commandResult = 1;
...@@ -316,13 +323,16 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy ...@@ -316,13 +323,16 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy
LightsStatusVO2 lightsStatusVO2 = list.get(0); LightsStatusVO2 lightsStatusVO2 = list.get(0);
String runMode = lightsStatusVO2.getRunMode(); String runMode = lightsStatusVO2.getRunMode();
String lampTime = lightsStatusVO2.getTimeStamp(); String lampTime = lightsStatusVO2.getTimeStamp();
//时间转换
// lampTime = LocalDateTimeUtil.formatTimeStamp(Long.valueOf(lampTime), LocalDateTimeUtil.TIMEFORMATTER);
signalCommandLogPO.setRunMode(runMode); signalCommandLogPO.setRunMode(runMode);
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,8 +342,13 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy ...@@ -332,8 +342,13 @@ 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 { }else {
log.info("定时任务 插入t_signal_command失败,crossId = {},commandType = {},time = {},insert = {}", jsonObject.getString("crossId"), commandType, LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER),insert1);
}
} else {
//更新 //更新
SignalCommandPO signalCommandPO = signalCommandPOS.get(0); SignalCommandPO signalCommandPO = signalCommandPOS.get(0);
signalCommandPO.setDataInfo(jsonObject.toJSONString()); signalCommandPO.setDataInfo(jsonObject.toJSONString());
...@@ -343,10 +358,23 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy ...@@ -343,10 +358,23 @@ 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);
} }
} }
} }
LambdaQueryWrapper<SignalCommandPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(SignalCommandPO::getCrossId,jsonObject.getString("crossId"));
List<SignalCommandPO> signalCommandPOS = signalCommandPOMapper.selectList(lambdaQueryWrapper);
log.error("更新t_signal_command成功,数据库中查询结果集:{}", signalCommandPOS);
} catch (Exception e) {
log.error("insertCommandLog命令日志插入失败:", e);
throw new RuntimeException(e);
}
}
@Override @Override
public JsonViewObject setSignalControlStrategy(String crossId, Integer command, Integer commandType) throws Exception { public JsonViewObject setSignalControlStrategy(String crossId, Integer command, Integer commandType) throws Exception {
...@@ -367,12 +395,16 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy ...@@ -367,12 +395,16 @@ public class ControlCommandStrategyServiceImpl implements ControlCommandStrategy
if (StringUtils.isBlank(crossId)) { if (StringUtils.isBlank(crossId)) {
return jsonViewObject.fail("路口编号不能为空"); return jsonViewObject.fail("路口编号不能为空");
} }
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)) {
jsonViewObject = hkControlCommandService.recoverSchedule(crossId); jsonViewObject = hkControlCommandService.recoverSchedule(crossId);
} else { } else {
jsonViewObject = wanJiControlCommandService.recoverSchedule(crossId); 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
...@@ -53,30 +50,35 @@ public class CommandFaildTask { ...@@ -53,30 +50,35 @@ public class CommandFaildTask {
@Resource @Resource
private SignalCommandLogPOMapper signalCommandLogPOMapper; private SignalCommandLogPOMapper signalCommandLogPOMapper;
@Scheduled(cron = "0/5 * * * * ?") @Scheduled(fixedRate = 5 * 1000, initialDelay = 10 * 1000)
@Async
public void commandFaildTask() throws Exception { public void commandFaildTask() throws Exception {
try {
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("定时任务恢复控制指令,需要执行恢复路口集合size:{}, crossInfoPOList = {}", crossInfoPOList.size(), 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); throw new Exception(e);
} }
} }
} }
} catch (Exception e) {
log.error("commandFaildTask定时任务执行异常:", e);
throw new RuntimeException(e);
}
} }
/** /**
...@@ -85,24 +87,24 @@ public class CommandFaildTask { ...@@ -85,24 +87,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 +118,13 @@ public class CommandFaildTask { ...@@ -116,9 +118,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 +133,11 @@ public class CommandFaildTask { ...@@ -127,14 +133,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 +146,24 @@ public class CommandFaildTask { ...@@ -143,24 +146,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) {
try {
String now = LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER); String now = LocalDateTimeUtil.formatNow(LocalDateTimeUtil.TIMEFORMATTER);
JsonViewObject jsonViewObject = JsonViewObject.newInstance(); JsonViewObject jsonViewObject = JsonViewObject.newInstance();
JSONObject jsonObject = new JSONObject();
jsonObject.put("crossId", crossId);
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)) {
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 +172,15 @@ public class CommandFaildTask { ...@@ -169,13 +172,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 +190,10 @@ public class CommandFaildTask { ...@@ -185,11 +190,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 +203,8 @@ public class CommandFaildTask { ...@@ -199,8 +203,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 +214,20 @@ public class CommandFaildTask { ...@@ -210,20 +214,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 +242,26 @@ public class CommandFaildTask { ...@@ -238,14 +242,26 @@ 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);
}
List<SignalCommandPO> signalCommandPOS = signalCommandPOMapper.selectList(lambdaQueryWrapper);
log.error("定时任务 更新t_signal_command成功,数据库中查询结果集:{}", signalCommandPOS);
} }
} }
...@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -89,6 +90,24 @@ public class SignalCommandSyncTask { ...@@ -89,6 +90,24 @@ public class SignalCommandSyncTask {
log.error("路口在线状态控制模式更新失败,路口编号信息:{}", entry, e); log.error("路口在线状态控制模式更新失败,路口编号信息:{}", entry, e);
} }
} }
saveAndUpdate(insertList, updateList);
List<SignalCommandPO> sendList = new ArrayList<>();
sendList.addAll(insertList);
sendList.addAll(updateList);
if (!CollectionUtils.isEmpty(sendList)) {
sendAlarmKafka(sendList);
}
} else {
log.error("从路口灯态缓存获取控制模式在线离线状态为空:{}", crossLightsStatusMap);
}
} catch (Exception e) {
log.error("信号机状态同步异常:", e);
}
}
@Transactional(rollbackFor = Exception.class)
public void saveAndUpdate(List<SignalCommandPO> insertList, List<SignalCommandPO> updateList) {
try {
if (!CollectionUtils.isEmpty(insertList)) { if (!CollectionUtils.isEmpty(insertList)) {
signalCommandPOMapper.insertBatch(insertList); signalCommandPOMapper.insertBatch(insertList);
List<SignalCommandLogPO> signalCommandLogPOS = new ArrayList<>(insertList.size()); List<SignalCommandLogPO> signalCommandLogPOS = new ArrayList<>(insertList.size());
...@@ -102,17 +121,9 @@ public class SignalCommandSyncTask { ...@@ -102,17 +121,9 @@ public class SignalCommandSyncTask {
signalCommandLogPOMapper.insertBatch(signalCommandLogPOS); signalCommandLogPOMapper.insertBatch(signalCommandLogPOS);
log.info("路口状态控制模式变动,数据库更新成功:{}", updateList); log.info("路口状态控制模式变动,数据库更新成功:{}", updateList);
} }
List<SignalCommandPO> sendList = new ArrayList<>();
sendList.addAll(insertList);
sendList.addAll(updateList);
if (!CollectionUtils.isEmpty(sendList)) {
sendAlarmKafka(sendList);
}
} else {
log.error("从路口灯态缓存获取控制模式在线离线状态为空:{}", crossLightsStatusMap);
}
} catch (Exception e) { } catch (Exception e) {
log.error("信号机状态同步异常:", e); log.error("路口状态控制模式变动,数据库更新失败:", e);
throw new RuntimeException(e);
} }
} }
...@@ -121,8 +132,6 @@ public class SignalCommandSyncTask { ...@@ -121,8 +132,6 @@ public class SignalCommandSyncTask {
insertPO.setCrossId(crossId); insertPO.setCrossId(crossId);
insertPO.setStatus(statusCache); insertPO.setStatus(statusCache);
insertPO.setRunMode(runModeCache); insertPO.setRunMode(runModeCache);
insertPO.setCommandResult(1);
insertPO.setUpdateCount(0);
insertPO.setInsertTime(new Date()); insertPO.setInsertTime(new Date());
insertPO.setLampTime(lampTime); insertPO.setLampTime(lampTime);
return insertPO; return insertPO;
......
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