Commit cb25f5d8 authored by wuxiaokai's avatar wuxiaokai

计划下发-计划信息、时段信息

parent 03b87a05
......@@ -73,6 +73,14 @@ public class Result<T> implements Serializable {
return Result.response(state, message, null);
}
public static <T> Result<T> error(Integer state) {
return Result.response(state, INTERNAL_SERVER_ERROR.getResultMsg(), null);
}
public static <T> Result<T> error() {
return error(INTERNAL_SERVER_ERROR);
}
public static <T> Result<T> error(ResultEnum resultEnum, String message) {
return Result.response(resultEnum.getResultCode(), message, null);
}
......
......@@ -4,6 +4,8 @@ import lombok.Getter;
import lombok.Setter;
import net.wanji.utc.common.BaseInfoInterface;
import static net.wanji.utc.common.ResultEnum.INTERNAL_SERVER_ERROR;
/**
* @author wuxiaokai
* @date 2022/11/21 9:38:54
......@@ -23,7 +25,7 @@ public class ControlException extends RuntimeException {
protected String errorMsg;
public ControlException() {
super();
this(INTERNAL_SERVER_ERROR.getResultCode(), INTERNAL_SERVER_ERROR.getResultMsg());
}
public ControlException(BaseInfoInterface errorInfoInterface) {
......@@ -39,14 +41,11 @@ public class ControlException extends RuntimeException {
}
public ControlException(String errorMsg) {
super(errorMsg);
this.errorMsg = errorMsg;
this(INTERNAL_SERVER_ERROR.getResultCode(), errorMsg);
}
public ControlException(Integer errorCode, String errorMsg) {
super(errorMsg);
this.errorCode = errorCode;
this.errorMsg = errorMsg;
this(errorCode, errorMsg, null);
}
public ControlException(Integer errorCode, String errorMsg, Throwable cause) {
......
package net.wanji.utc.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.wanji.utc.common.Result;
import net.wanji.utc.common.exception.ControlException;
import net.wanji.utc.common.typeenum.BasicEnum;
......@@ -20,8 +23,10 @@ import static net.wanji.utc.common.ResultEnum.BODY_NOT_MATCH;
* @author wuxiaokai
* @date 2022/11/15 13:21:10
*/
@Slf4j
@RestController
@RequestMapping("/controlCommand")
@Api(value = "控制指令接口", description = "控制指令接口", tags = "控制指令接口")
public class ControlCommandController {
@Value("${signal.mock}")
......@@ -35,6 +40,7 @@ public class ControlCommandController {
/**
*/
@ApiOperation(value = "方案下发-基础方案下发", notes = "方案下发-基础方案下发")
@PostMapping("/schemeSend")
public <T> Result<T> schemeSend(@RequestParam String signalId, @RequestParam Integer command) {
if (mock) return Result.success();
......@@ -54,22 +60,28 @@ public class ControlCommandController {
* @param planSendVO 计划下发VO
* @return {@link Result}<{@link T}>
*/
@ApiOperation(value = "计划下发-计划信息、时段信息", notes = "计划下发-计划信息、时段信息")
@PostMapping("/planSend")
public <T> Result<T> planSend(@RequestParam String signalId, @RequestBody PlanSendVO planSendVO) {
if (mock) return Result.success();
CrossInfoPO crossInfoPO = crossInfoMapper.selectByCode(signalId);
if (crossInfoPO == null) {
throw new ControlException(BODY_NOT_MATCH.getResultCode(), "参数错误,信号机ID不正确。");
}
planSendVO.setTelesemeId(crossInfoPO.getCode());
planSendVO.setManufacturerAbbr(crossInfoPO.getManufacturerId() + "");
Integer manufacturerId = crossInfoPO.getManufacturerId();
if (manufacturerId.equals(BasicEnum.ManufacturerEnum.HK.getCode())) {
return hkControlCommandService.planSend(planSendVO);
} else {
try {
CrossInfoPO crossInfoPO = crossInfoMapper.selectByCode(signalId);
if (crossInfoPO == null) {
throw new ControlException(BODY_NOT_MATCH.getResultCode(), "参数错误,信号机ID不正确。");
}
planSendVO.setCode(crossInfoPO.getCode());
planSendVO.setManufacturerAbbr(crossInfoPO.getManufacturerId() + "");
Integer manufacturerId = crossInfoPO.getManufacturerId();
if (manufacturerId.equals(BasicEnum.ManufacturerEnum.HK.getCode())) {
return hkControlCommandService.planSend(planSendVO);
} else {
// todo else
return null;
// todo else
return null;
}
} catch (Exception ex) {
log.error("计划下发-计划信息、时段信息异常:{}", ex.getMessage());
throw new ControlException("计划下发-计划信息、时段信息异常");
}
}
......@@ -80,6 +92,7 @@ public class ControlCommandController {
* @param command 指令
* @return {@link Result}<{@link T}>
*/
@ApiOperation(value = "全红控制-路口全红控制/恢复", notes = "全红控制-路口全红控制/恢复")
@PostMapping("/allRedControl")
public <T> Result<T> allRedControl(@RequestParam String signalId, @RequestParam Integer command) {
if (mock) return Result.success();
......@@ -99,6 +112,7 @@ public class ControlCommandController {
* @param command 命令
* @return {@link Result}<{@link T}>
*/
@ApiOperation(value = "黄闪控制-路口黄闪控制/恢复", notes = "黄闪控制-路口黄闪控制/恢复")
@PostMapping("/yellowLightControl")
public <T> Result<T> yellowLightControl(@RequestParam String signalId, @RequestParam Integer command) {
if (mock) return Result.success();
......@@ -118,6 +132,7 @@ public class ControlCommandController {
* @param command 命令
* @return {@link Result}<{@link T}>
*/
@ApiOperation(value = "关灯控制-路口关灯控制/开灯", notes = "关灯控制-路口关灯控制/开灯")
@PostMapping("/closeLightControl")
public <T> Result<T> closeLightControl(@RequestParam String signalId, @RequestParam Integer command) {
if (mock) return Result.success();
......@@ -138,6 +153,7 @@ public class ControlCommandController {
* @param stepNum 一步num
* @return {@link Result}<{@link T}>
*/
@ApiOperation(value = "步进控制-步进控制/恢复", notes = "步进控制-步进控制/恢复")
@PostMapping("/stepControl")
public <T> Result<T> stepControl(@RequestParam String signalId,
@RequestParam Integer command,
......
......@@ -8,6 +8,8 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
import static net.wanji.utc.common.ResultEnum.INTERNAL_SERVER_ERROR;
/**
* @author wuxiaokai
* @date 2022/11/21 9:06:40
......@@ -30,8 +32,8 @@ public class GlobalExceptionHandler {
*/
@ExceptionHandler(value = NullPointerException.class)
public Result<String> exceptionHandler(HttpServletRequest req, NullPointerException e) {
log.error("发生空指针异常!原因是:", e);
return Result.error("");
log.error("发生空指针异常!原因是:{}", e.getMessage());
return Result.error(INTERNAL_SERVER_ERROR.getResultCode(), e.getMessage());
}
/**
......@@ -39,7 +41,7 @@ public class GlobalExceptionHandler {
*/
@ExceptionHandler(value = Exception.class)
public Result<String> exceptionHandler(HttpServletRequest req, Exception e) {
log.error("未知异常!原因是:", e);
return Result.error("");
log.error("未知异常!原因是:{}", e.getMessage());
return Result.error(INTERNAL_SERVER_ERROR.getResultCode(), e.getMessage());
}
}
......@@ -20,7 +20,7 @@ public interface ControlCommandService {
/**
* 计划下发
*/
<T> Result<T> planSend(PlanSendVO planSendVO);
<T> Result<T> planSend(PlanSendVO planSendVO) throws Exception;
/**
* 时间表下发
......
package net.wanji.utc.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
......@@ -16,14 +17,14 @@ import net.wanji.utc.service.ControlCommandService;
import net.wanji.utc.service.HkGetSignalMethodService;
import net.wanji.utc.vo.PhaseLock;
import net.wanji.utc.vo.plansend.PlanSendVO;
import net.wanji.utc.vo.plansend.SectionPlan;
import net.wanji.utc.vo.plansend.TimeSlice;
import net.wanji.utc.vo.signal.SignalLightStateVo;
import net.wanji.utc.vo.signal.SignalRingVo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import static net.wanji.utc.common.constant.Constants.*;
......@@ -51,8 +52,13 @@ public class HKControlCommandServiceImpl implements ControlCommandService {
}
@Override
public <T> Result<T> planSend(PlanSendVO planSendVO) {
return null;
public <T> Result<T> planSend(PlanSendVO planSendVO) throws Exception {
if (sendPlanInfo(planSendVO)) {
if (sendTimeInfo(planSendVO)) {
return Result.success();
}
}
return Result.error("下发指令失败");
}
@Override
......@@ -187,4 +193,136 @@ public class HKControlCommandServiceImpl implements ControlCommandService {
baseSignals.add(baseSignal);
return hkGetSignalMethodService.queryHkSignalInfo(baseSignals);
}
/**
* 下发时段信息
*
* @param planSendVO 计划下发VO
* @return boolean
*/
private boolean sendTimeInfo(PlanSendVO planSendVO) throws Exception {
//拼接参数
JSONObject bodyObjectParam = new JSONObject();
// 拼接参数 海康后续修改不传入 controlType ,controlType 取值默认为原始值
List<SectionPlan> sectionPlans = planSendVO.getSectionPlans();
for (SectionPlan plan : sectionPlans) {
//拼接参数,信号机方案对象
JSONObject signalObjectParam = new JSONObject();
//拼接参数,信号列表
JSONArray signalArrayParam = new JSONArray();
//拼接参数,方案列表
JSONArray planArrayParam = new JSONArray();
//拼接参数,时段列表
JSONArray sectionArrayParam = new JSONArray();
List<TimeSlice> timeSlices = plan.getTimeSlices();
for (TimeSlice timeSlice : timeSlices) {
JSONObject section = new JSONObject();
section.put("timeSecNo", timeSlice.getTimeSliceId());
section.put("patternNo", timeSlice.getTimePlanId());
section.put("beginTime", timeSlice.getStartTime());
sectionArrayParam.add(section);
}
JSONObject planObjectParam = new JSONObject();
planObjectParam.put("planNo", plan.getSectionPlanId());
planObjectParam.put("planName", plan.getSectionPlanDesc());
planObjectParam.put("sectionList", sectionArrayParam);
planArrayParam.add(planObjectParam);
signalObjectParam.put("crossCode", planSendVO.getCode());
signalObjectParam.put("planList", planArrayParam);
signalArrayParam.add(signalObjectParam);
bodyObjectParam.put("data", signalArrayParam);
}
// 下发时段方案
String strResult = ArtemisHttpUtil.doPostStringArtemis(artemisConfig, getPathMapByApiCode("updateSectionPlans"), bodyObjectParam.toJSONString(), null, null, "application/json", null);
JSONObject object = JSON.parseObject(strResult);
return object.getInteger(HK_CODE_KEY).equals(HK_SUCCESS_CODE);
}
/**
* 下发计划信息
*
* @param planSendVO 计划下发VO
* @return boolean
* @throws Exception 异常
*/
private boolean sendPlanInfo(PlanSendVO planSendVO) throws Exception {
JSONArray body = new JSONArray();
body.add(planSendVO.getCode());
Map<String, String> path = getPathMapByApiCode("queryRunPlan");
String strResult = ArtemisHttpUtil.doPostStringArtemis(artemisConfig, path, body.toString(), null, null, "application/json", null);
JSONObject jsonObj = JSON.parseObject(strResult);
//日期 id
int id = 1;
if (jsonObj.getInteger(HK_CODE_KEY).equals(HK_SUCCESS_CODE)) {
// 获取日期列表
JSONArray schedulesArray = jsonObj.getJSONArray("data").getJSONObject(0).getJSONArray("schedules");
JSONObject scheduleObj = schedulesArray.getJSONObject(schedulesArray.size() - 1);
id = scheduleObj.getInteger("id");
}
//拼接参数
JSONObject bodyObjectParam = new JSONObject();
JSONArray schedulesArrayParam = new JSONArray();
// 获取传入的星期数组
JSONArray weeks = JSON.parseArray(JSON.toJSONString(planSendVO.getWeeks()));
// 获取传入的特殊日期数组
JSONArray specialDays = JSON.parseArray(JSON.toJSONString(planSendVO.getSpecialDays()));
if (null != weeks) {
//去重,获取所有的运行方案号
Set<String> set = new HashSet<>();
for (int i = 0; i < weeks.size(); i++) {
String sectionPlanId = weeks.getJSONObject(i).getString("sectionPlanId");
set.add(sectionPlanId);
}
if (null != specialDays) {
for (int i = 0; i < specialDays.size(); i++) {
String sectionPlanId = specialDays.getJSONObject(i).getString("sectionPlanId");
set.add(sectionPlanId);
}
}
int num = 0;
for (String planNo : set) {
JSONObject schedulesObjectParam = new JSONObject();
List<Integer> weeksListParam = new ArrayList<>();
// 遍历星期列表,拼接星期集合参数
for (int i = 0; i < weeks.size(); i++) {
JSONObject week = weeks.getJSONObject(i);
String weekNum = week.getString("weekNum");
String sectionPlanId = week.getString("sectionPlanId");
if (planNo.equals(sectionPlanId)) {
weeksListParam.add(Integer.valueOf(weekNum));
}
}
// 遍历特殊日期列表,拼接特殊日期集合参数
if (null != specialDays) {
List<String> specialDaysListParam = new ArrayList<>();
for (int i = 0; i < specialDays.size(); i++) {
JSONObject specialDay = specialDays.getJSONObject(i);
String dateStr = specialDay.getString("dateStr");
String sectionPlanId = specialDay.getString("sectionPlanId");
if (planNo.equals(sectionPlanId)) {
specialDaysListParam.add(dateStr);
}
}
schedulesObjectParam.put("dates", specialDaysListParam);
//0 说明 dates 内的日期是日期集合,1 说明是dates 内的数据是日期范围
schedulesObjectParam.put("isPeriod", 0);
}
//scheduleNo 日期号 ,支持返回【1~128】
if (id + set.size() > 128) {
schedulesObjectParam.put("scheduleNo", 128 - set.size() - (++num));
} else {
schedulesObjectParam.put("scheduleNo", id + (++num));
}
schedulesObjectParam.put("planNo", planNo);
schedulesObjectParam.put("weeks", weeksListParam);
schedulesArrayParam.add(schedulesObjectParam);
}
}
bodyObjectParam.put("crossCode", planSendVO.getCode());
bodyObjectParam.put("schedules", schedulesArrayParam);
// 下发路口运行计划方案
String updateResult = ArtemisHttpUtil.doPostStringArtemis(artemisConfig, getPathMapByApiCode("updateRunPlan"), bodyObjectParam.toJSONString(), null, null, "application/json", null);
JSONObject updateObject = JSON.parseObject(updateResult);
return updateObject.getInteger(HK_CODE_KEY).equals(HK_SUCCESS_CODE);
}
}
......@@ -16,17 +16,23 @@ import java.util.List;
@ApiModel(value = "SectionPlan", description = "路口时段方案实体")
public class SectionPlan {
//时段方案编号
/**
* 时段方案编号
*/
@ApiModelProperty(value = "时段方案编号")
private String sectionPlanId;
//时段方案描述
/**
* 时段方案描述
*/
@ApiModelProperty(value = "时段方案描述")
private String sectionPlanDesc;
//时段数据列表
/**
* 时段数据列表
*/
@ApiModelProperty(value = "时段数据列表")
private List<Timeslice> timeslices;
private List<TimeSlice> timeSlices;
}
......@@ -12,26 +12,36 @@ import lombok.Data;
*/
@Data
@ApiModel(value = "Timeslice", description = "时段数据实体")
public class Timeslice {
public class TimeSlice {
//时段编号
/**
* 时段编号
*/
@ApiModelProperty(value = "时段编号")
private String timesliceid;
private String timeSliceId;
//时段描述
/**
* 时段描述
*/
@ApiModelProperty(value = "时段描述")
private String timeslicedesc;
private String timeSliceDesc;
//时段顺序号
/**
* 时段顺序号
*/
@ApiModelProperty(value = "时段顺序号")
private Integer timesliceorderid;
private Integer timeSliceOrderId;
//开始时间,格式 HH:MI:00
/**
* 开始时间,格式 HH:MI:00
*/
@ApiModelProperty(value = "开始时间,格式 HH:MI:00")
private String starttime;
private String startTime;
//配时方案编号
/**
* 配时方案编号
*/
@ApiModelProperty(value = "配时方案编号")
private String timeplanid;
private String timePlanId;
}
......@@ -10,5 +10,6 @@ import lombok.Data;
public class Week {
private Integer weekNum;
private Integer sectionPlanId;
}
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