Commit 9e00e290 authored by zhouleilei's avatar zhouleilei

1、新增定时任务一键同步所有路口方案;2、新增页面一键同步接口;3、路口同步日志记录

parent e9cd0122
package net.wanji.web.controller; package net.wanji.web.controller;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses; import io.swagger.annotations.ApiResponses;
import net.wanji.common.annotation.aspect.AspectLog; import net.wanji.common.annotation.aspect.AspectLog;
import net.wanji.common.enums.BaseEnum; import net.wanji.common.enums.BaseEnum;
import net.wanji.common.framework.Constants;
import net.wanji.common.framework.rest.JsonViewObject; import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.common.utils.tool.DateUtil;
import net.wanji.databus.bo.CrossIdBO; import net.wanji.databus.bo.CrossIdBO;
import net.wanji.databus.dao.entity.CrossSyncLogPO;
import net.wanji.databus.dao.mapper.CrossSyncLogMapper;
import net.wanji.web.dto.*; import net.wanji.web.dto.*;
import net.wanji.web.po.RingPhasePO; import net.wanji.web.po.RingPhasePO;
import net.wanji.web.service.impl.PlanSendServiceImpl; import net.wanji.web.service.impl.PlanSendServiceImpl;
import net.wanji.web.vo.PhaseListByTimeVO; import net.wanji.web.vo.PhaseListByTimeVO;
import net.wanji.web.vo.PhaseListVO; import net.wanji.web.vo.PhaseListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -31,6 +38,9 @@ import java.util.List; ...@@ -31,6 +38,9 @@ import java.util.List;
public class PlanSendController { public class PlanSendController {
private final PlanSendServiceImpl planSendService; private final PlanSendServiceImpl planSendService;
@Autowired
private CrossSyncLogMapper crossSyncLogMapper;
public PlanSendController(PlanSendServiceImpl planSendService) { public PlanSendController(PlanSendServiceImpl planSendService) {
this.planSendService = planSendService; this.planSendService = planSendService;
} }
...@@ -95,10 +105,43 @@ public class PlanSendController { ...@@ -95,10 +105,43 @@ public class PlanSendController {
@ApiOperation(value = "信号机方案同步", notes = "信号机方案同步") @ApiOperation(value = "信号机方案同步", notes = "信号机方案同步")
@PostMapping("/syncScheme") @PostMapping("/syncScheme")
public JsonViewObject syncScheme(@RequestBody CrossIdBO crossIdBO) throws Exception { public JsonViewObject syncScheme(@RequestBody CrossIdBO crossIdBO) throws Exception {
JsonViewObject jsonViewObject = planSendService.syncScheme(crossIdBO); JsonViewObject jsonViewObject = null;
CrossSyncLogPO crossSyncLogPO = new CrossSyncLogPO();
String dt = DateUtil.format(new Date(), Constants.DATE_FORMAT.E_DATE_FORMAT_DAY);
crossSyncLogPO.setCrossId(crossIdBO.getCrossId());
crossSyncLogPO.setType(2);
crossSyncLogPO.setDt(dt);
try {
jsonViewObject = planSendService.syncScheme(crossIdBO);
crossSyncLogPO.setResultCode(jsonViewObject.getCode());
crossSyncLogPO.setResultMessage(JSON.toJSONString(jsonViewObject));
} catch (Exception e) {
jsonViewObject = JsonViewObject.newInstance();
jsonViewObject.setCode(500);
jsonViewObject.setMessage(e.getMessage());
crossSyncLogPO.setResultCode(500);
crossSyncLogPO.setResultMessage("手动同步报错");
}
crossSyncLogMapper.insert(crossSyncLogPO);
return jsonViewObject; return jsonViewObject;
} }
@AspectLog(description = "信号机方案同步-一键同步所有路口", operationType = BaseEnum.OperationTypeEnum.UPDATE)
@ApiOperation(value = "信号机方案同步-一键同步所有路口", notes = "信号机方案同步-一键同步所有路口")
@PostMapping("/syncAllCross")
public JsonViewObject syncAllCross() throws Exception {
JsonViewObject jsonViewObject = null;
jsonViewObject = JsonViewObject.newInstance();
try {
planSendService.syncAllCross(3);
return JsonViewObject.newInstance().success("全量同步成功");
} catch (Exception e) {
return JsonViewObject.newInstance().fail("全量同步失败");
}
}
@AspectLog(description = "信号机调度日计划同步", operationType = BaseEnum.OperationTypeEnum.UPDATE) @AspectLog(description = "信号机调度日计划同步", operationType = BaseEnum.OperationTypeEnum.UPDATE)
@ApiOperation(value = "信号机调度日计划同步", notes = "信号机调度日计划同步") @ApiOperation(value = "信号机调度日计划同步", notes = "信号机调度日计划同步")
@PostMapping("/syncSchedules") @PostMapping("/syncSchedules")
......
...@@ -29,6 +29,12 @@ public interface PlanSendService { ...@@ -29,6 +29,12 @@ public interface PlanSendService {
JsonViewObject restore(CrossIdAndPhaseIdsDTO crossIdAndPhaseIdsDTO); JsonViewObject restore(CrossIdAndPhaseIdsDTO crossIdAndPhaseIdsDTO);
JsonViewObject syncScheme(CrossIdBO crossIdBO) throws Exception; JsonViewObject syncScheme(CrossIdBO crossIdBO) throws Exception;
/**
* @Description 全量同步所有路口
* @Param [type] 1-定时任务同步;2-单路口手动同步;3-页面一键同步所有路口
* @return void
**/
void syncAllCross(int type);
PhaseListByTimeVO phaseListByTime(CrossIdAndTimeDTO crossIdAndTimeDTO); PhaseListByTimeVO phaseListByTime(CrossIdAndTimeDTO crossIdAndTimeDTO);
......
...@@ -3,12 +3,14 @@ package net.wanji.web.service.impl; ...@@ -3,12 +3,14 @@ package net.wanji.web.service.impl;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.wanji.common.framework.Constants;
import net.wanji.common.framework.rest.JsonViewObject; import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.common.utils.tool.JacksonUtils; import net.wanji.common.utils.tool.JacksonUtils;
import net.wanji.databus.bo.CrossIdBO; import net.wanji.databus.bo.CrossIdBO;
...@@ -18,6 +20,7 @@ import net.wanji.databus.dto.*; ...@@ -18,6 +20,7 @@ import net.wanji.databus.dto.*;
import net.wanji.databus.po.*; import net.wanji.databus.po.*;
import net.wanji.databus.vo.*; import net.wanji.databus.vo.*;
import net.wanji.feign.service.UtcFeignClients; import net.wanji.feign.service.UtcFeignClients;
import net.wanji.web.cache.BaseCrossInfoCache;
import net.wanji.web.common.enums.CrossDirChangeEnum; import net.wanji.web.common.enums.CrossDirChangeEnum;
import net.wanji.web.dto.*; import net.wanji.web.dto.*;
import net.wanji.web.mapper.scheme.CrossDirInfoMapper; import net.wanji.web.mapper.scheme.CrossDirInfoMapper;
...@@ -30,6 +33,7 @@ import net.wanji.web.vo.PhaseListByTimeVO; ...@@ -30,6 +33,7 @@ import net.wanji.web.vo.PhaseListByTimeVO;
import net.wanji.web.vo.PhaseListVO; import net.wanji.web.vo.PhaseListVO;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -64,6 +68,12 @@ public class PlanSendServiceImpl implements PlanSendService { ...@@ -64,6 +68,12 @@ public class PlanSendServiceImpl implements PlanSendService {
private final CrossBaseLaneInfoMapper crossBaseLaneInfoMapper; private final CrossBaseLaneInfoMapper crossBaseLaneInfoMapper;
private final CrossDirInfoMapper crossDirInfoMapper; private final CrossDirInfoMapper crossDirInfoMapper;
@Autowired
private BaseCrossInfoCache baseCrossInfoCache;
@Autowired
private CrossSyncLogMapper crossSyncLogMapper;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat hourMinuteSdf = new SimpleDateFormat("HH:mm"); SimpleDateFormat hourMinuteSdf = new SimpleDateFormat("HH:mm");
...@@ -520,6 +530,64 @@ public class PlanSendServiceImpl implements PlanSendService { ...@@ -520,6 +530,64 @@ public class PlanSendServiceImpl implements PlanSendService {
return jsonViewObject.success(); return jsonViewObject.success();
} }
@Override
public void syncAllCross(int type) {
long s = System.currentTimeMillis();
String startMes = "";
if (type == 1){
startMes = "定时任务";
}else if (type == 3){
startMes = "页面一键同步";
}
log.info("{},--路口同步开始",startMes);
List<CrossSyncLogPO> list = new ArrayList<>();
//获取所有信控路口的路口编号
List<String> isSignalCrossIdList = baseCrossInfoCache.getIsSignalCrossIdList();
String dt = net.wanji.common.utils.tool.DateUtil.format(new Date(), Constants.DATE_FORMAT.E_DATE_FORMAT_DAY);
if (org.apache.commons.collections.CollectionUtils.isNotEmpty(isSignalCrossIdList)) {
for (String crossIdId : isSignalCrossIdList) {
CrossIdBO crossIdBO = new CrossIdBO();
crossIdBO.setCrossId(crossIdId);
JsonViewObject jsonViewObject = null;
CrossSyncLogPO crossSyncLogPO = new CrossSyncLogPO();
crossSyncLogPO.setCrossId(crossIdId);
//1-定时任务同步;2-单路口手动同步;3-页面一键同步所有路口
crossSyncLogPO.setType(type);
int code = 0;
try {
jsonViewObject = syncScheme(crossIdBO);
code = jsonViewObject.getCode();
crossSyncLogPO.setResultCode(code);
crossSyncLogPO.setResultMessage(JSON.toJSONString(jsonViewObject));
} catch (Exception e) {
code = 500;
crossSyncLogPO.setResultCode(code);
String resultMes = "";
if (type == 1){
resultMes = "定时任务报错,路口号:"+crossIdId;
}else if (type == 3){
resultMes = "页面一键同步报错,路口号:"+crossIdId;
}else {
resultMes = "全量同步报错,路口号:"+crossIdId;
}
crossSyncLogPO.setResultMessage(resultMes);
// throw new RuntimeException(e);
}
crossSyncLogPO.setDt(dt);
crossSyncLogMapper.insert(crossSyncLogPO);
if (code == 200) {
log.info("路口 {} 同步成功", crossIdId);
} else {
log.info("路口 {} 同步失败", crossIdId);
}
list.add(crossSyncLogPO);
}
long e = System.currentTimeMillis();
log.info("{},--路口同步完成,数量:{},耗时:{}s",startMes,list.size(), (e - s)/1000);
}
}
/** /**
* @Description 解决车道重复问题 * @Description 解决车道重复问题
* @Param [crossLaneLightsPOS, crossLightsPOS] * @Param [crossLaneLightsPOS, crossLightsPOS]
......
package net.wanji.web.task;
import lombok.extern.slf4j.Slf4j;
import net.wanji.web.service.impl.PlanSendServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* 定时同步方案等静态信息
*
* @author zhouleilei
* @date 2024/12/25 13:01
*/
@Component
@Slf4j
@SuppressWarnings("all")
public class SchemeUpdateTask {
@Autowired
private PlanSendServiceImpl planSendService;
@Scheduled(cron = "0 30 0 * * ?")
public void runningStatusAlarm() {
try {
planSendService.syncAllCross(1);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
package net.wanji.databus.dao.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
*
* @author leilei.zhou
* @date 2025/03/31 15:30
*/
@TableName("t_base_cross_sync_log")
@Data
public class CrossSyncLogPO {
@ApiModelProperty(value = "路口ID")
@TableField("cross_id")
private String crossId;
@ApiModelProperty(value = "同步状态:200-成功,500以及其他-失败")
@TableField("result_code")
private Integer resultCode;
@ApiModelProperty(value = "同步类型:1-定时任务同步;2-单路口手动同步;3-页面一键同步所有路口")
@TableField("type")
private Integer type;
@ApiModelProperty(value = "返回信息")
@TableField("result_message")
private String resultMessage;
@ApiModelProperty(value = "天")
@TableField("dt")
private String dt;
@ApiModelProperty(value = "插入时间 yyyy-MM-dd HH:mm:ss")
@TableField("insert_time")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date insertTime;
}
package net.wanji.databus.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.databus.dao.entity.CrossSyncLogPO;
import org.springframework.stereotype.Repository;
/**
*
* @author leilei.zhou
* @date 2025/03/31 15:30
*/
@Repository
public interface CrossSyncLogMapper extends BaseMapper<CrossSyncLogPO> {
}
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