Commit 3680ea33 authored by duanruiming's avatar duanruiming

信号控制-调用utc服务指令控制

parent 68d373f3
package net.wanji.web.controller;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import net.wanji.web.common.Result;
import net.wanji.web.util.HttpRestUtil;
import net.wanji.web.vo.signalservice.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* @author duanruiming
* @date 2023/01/04 16:10
*/
@Api(value = "SignalServiceController", description = "信号控制")
@RequestMapping("/controlCommand")
@RestController
@SuppressWarnings("all")
public class SignalServiceController {
@Autowired
private HttpRestUtil httpRestUtil;
@Value("${utcServiceUrl}")
private String utcServiceUrl;
@ApiOperation(value = "信号机方案下发-基础方案下发", notes = "信号机方案下发-基础方案下发")
@PostMapping("/schemeSend")
public <T> Result<T> schemeSend(HttpServletRequest httpServletRequest, @RequestBody SchemeSendVO schemeSendVO) {
String param = JSONObject.toJSONString(schemeSendVO);
Result result = httpRestUtil.doPost(utcServiceUrl.concat(getRemoteUri(httpServletRequest)), null, param, Result.class);
if (Objects.isNull(result) || result.getState() != 200) {
return Result.error(result.getState(), "远程服务调用异常url".concat(utcServiceUrl.concat(getRemoteUri(httpServletRequest))));
}
return Result.success("success");
}
@ApiOperation(value = "计划下发-计划信息、时段信息", notes = "计划下发-计划信息、时段信息")
@PostMapping("/planSend")
public <T> Result<T> planSend(HttpServletRequest httpServletRequest, @RequestBody PlanSendVO planSendVO) throws Exception {
String param = JSONObject.toJSONString(planSendVO);
Result result = httpRestUtil.doPost(utcServiceUrl.concat(getRemoteUri(httpServletRequest)), null, param, Result.class);
if (Objects.isNull(result) || result.getState() != 200) {
return Result.error(result.getState(), "远程服务调用异常url".concat(utcServiceUrl.concat(getRemoteUri(httpServletRequest))));
}
return Result.success("success");
}
@ApiOperation(value = "时间表下发-时间表信息", notes = "时间表下发-时间表信息")
@PostMapping("/scheduleSend")
public <T> Result<T> scheduleSend(HttpServletRequest httpServletRequest, @RequestBody ScheduleSendVO scheduleSendVO) throws Exception {
String param = JSONObject.toJSONString(scheduleSendVO);
Result result = httpRestUtil.doPost(utcServiceUrl.concat(getRemoteUri(httpServletRequest)), null, param, Result.class);
if (Objects.isNull(result) || result.getState() != 200) {
return Result.error(result.getState(), "远程服务调用异常url".concat(utcServiceUrl.concat(getRemoteUri(httpServletRequest))));
}
return Result.success("success");
}
@ApiOperation(value = "相位配时下发-(下发相位参数)", notes = "相位配时下发-(下发相位参数)")
@PostMapping("/phaseTimingSend")
public <T> Result<T> phaseTimingSend(HttpServletRequest httpServletRequest, @RequestBody PhaseTimingSendVO phaseTimingSendVO) throws Exception {
String param = JSONObject.toJSONString(phaseTimingSendVO);
Result result = httpRestUtil.doPost(utcServiceUrl.concat(getRemoteUri(httpServletRequest)), null, param, Result.class);
if (Objects.isNull(result) || result.getState() != 200) {
return Result.error(result.getState(), "远程服务调用异常url".concat(utcServiceUrl.concat(getRemoteUri(httpServletRequest))));
}
return Result.success("success");
}
@ApiOperation(value = "灯态控制-路口全红/黄闪/关灯控制/恢复", notes = "灯态控制-路口全红/黄闪/关灯控制/恢复")
@PostMapping("/lampStateControl")
public <T> Result<T> allRedControl(@RequestBody @Validated ControlCommandVO commandVO) throws Exception {
Integer controlType = commandVO.getControlType();
String uri = "";
if (1 == controlType) {
uri = "/controlCommand/allRedControl";
}
if (2 == controlType) {
uri = "/controlCommand/yellowLightControl";
}
if (3 == controlType) {
uri = "/controlCommand/closeLightControl";
}
String param = JSONObject.toJSONString(commandVO);
Result result = httpRestUtil.doPost(utcServiceUrl.concat(uri), null, param, Result.class);
if (Objects.isNull(result) || result.getState() != 200) {
return Result.error(result.getState(), "远程服务调用异常url".concat(utcServiceUrl.concat(uri)));
}
return Result.success("success");
}
@ApiOperation(value = "步进控制-步进控制/恢复", notes = "步进控制-步进控制/恢复")
@ApiImplicitParams({
@ApiImplicitParam(name = "command", value = "1 开始步进 0 取消步进", paramType = "query", required = true, dataType = "int"),
@ApiImplicitParam(name = "stepNum", value = "0 顺序步进 n 跳过n个相位", paramType = "query", required = true, dataType = "int"),
})
@PostMapping("/stepControl")
public <T> Result<T> stepControl(HttpServletRequest httpServletRequest, @RequestParam String code,
@RequestParam Integer command,
@RequestParam int stepNum) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("code", code);
map.put("command", command);
map.put("stepNum", stepNum);
String param = JSONObject.toJSONString(map);
Result result = httpRestUtil.doPost(utcServiceUrl.concat(getRemoteUri(httpServletRequest)), null, param, Result.class);
if (Objects.isNull(result) || result.getState() != 200) {
return Result.error(result.getState(), "远程服务调用异常url".concat(utcServiceUrl.concat(getRemoteUri(httpServletRequest))));
}
return Result.success("success");
}
@ApiOperation(value = "恢复时间表-恢复路口时间表执行", notes = "恢复时间表-恢复路口时间表执行")
@PostMapping("/recoverSchedule")
public <T> Result<T> recoverSchedule(HttpServletRequest httpServletRequest, @RequestParam String code) throws Exception {
Result result = httpRestUtil.doPost(utcServiceUrl.concat(getRemoteUri(httpServletRequest)), null, code, Result.class);
if (Objects.isNull(result) || result.getState() != 200) {
return Result.error(result.getState(), "远程服务调用异常url".concat(utcServiceUrl.concat(getRemoteUri(httpServletRequest))));
}
return Result.success("success");
}
@ApiOperation(value = "锁定控制-相位锁定/解锁", notes = "锁定控制-相位锁定/解锁")
@PostMapping("/lockControl")
public <T> Result<T> lockControl(HttpServletRequest httpServletRequest, @RequestBody @Validated ControlCommandVO commandVO) throws Exception {
String param = JSONObject.toJSONString(commandVO);
Result result = httpRestUtil.doPost(utcServiceUrl.concat(getRemoteUri(httpServletRequest)), null, param, Result.class);
if (Objects.isNull(result) || result.getState() != 200) {
return Result.error(result.getState(), "远程服务调用异常url".concat(utcServiceUrl.concat(getRemoteUri(httpServletRequest))));
}
return Result.success("success");
}
@ApiOperation(value = "相位差下发", notes = "相位差下发")
@PostMapping("/phaseDiffSend")
public <T> Result<T> phaseDiffSend(HttpServletRequest httpServletRequest) {
Result result = httpRestUtil.doPost(utcServiceUrl.concat(getRemoteUri(httpServletRequest)), null, null, Result.class);
if (Objects.isNull(result) || result.getState() != 200) {
return Result.error(result.getState(), "远程服务调用异常url".concat(utcServiceUrl.concat(getRemoteUri(httpServletRequest))));
}
return Result.success("success");
}
public static String getRemoteUri(HttpServletRequest httpServletRequest) {
String requestURI = httpServletRequest.getRequestURI().substring(4);
return requestURI;
}
}
...@@ -189,8 +189,9 @@ public class SituationDetectionController extends BaseController { ...@@ -189,8 +189,9 @@ public class SituationDetectionController extends BaseController {
List<Map<String, Object>> content = (List<Map<String, Object>>) jsonViewObject.getContent(); List<Map<String, Object>> content = (List<Map<String, Object>>) jsonViewObject.getContent();
Map<String, Object> result = content.get(0); Map<String, Object> result = content.get(0);
String signalId = (String) result.get("signalId"); String signalId = (String) result.get("signalId");
String crossId = (String) result.get("crossId");
Integer faultType = (Integer) result.get("faultType"); Integer faultType = (Integer) result.get("faultType");
if (Objects.nonNull(faultType) && faultType != 0 && StringUtils.isNotEmpty(signalId)) { if (Objects.nonNull(faultType) && faultType != 0 && StringUtils.isNotEmpty(crossId)) {
CommonEventAlarmOutVo commonEventAlarmOutVo = new CommonEventAlarmOutVo(); CommonEventAlarmOutVo commonEventAlarmOutVo = new CommonEventAlarmOutVo();
commonEventAlarmOutVo.setEventType(3); commonEventAlarmOutVo.setEventType(3);
commonEventAlarmOutVo.setEventId(signalId); commonEventAlarmOutVo.setEventId(signalId);
...@@ -199,7 +200,7 @@ public class SituationDetectionController extends BaseController { ...@@ -199,7 +200,7 @@ public class SituationDetectionController extends BaseController {
commonEventAlarmOutVo.setStatus(String.valueOf(faultType)); commonEventAlarmOutVo.setStatus(String.valueOf(faultType));
commonEventAlarmOutVo.setStartTime(formatNow); commonEventAlarmOutVo.setStartTime(formatNow);
TBaseCrossInfo tBaseCrossInfo = situationDetectionService.selectCrossInfoById(signalId); TBaseCrossInfo tBaseCrossInfo = situationDetectionService.selectCrossInfoById(crossId);
if (Objects.nonNull(tBaseCrossInfo)) { if (Objects.nonNull(tBaseCrossInfo)) {
commonEventAlarmOutVo.setCoordinate(tBaseCrossInfo.getLocation()); commonEventAlarmOutVo.setCoordinate(tBaseCrossInfo.getLocation());
} }
......
...@@ -16,6 +16,7 @@ import org.springframework.web.client.RestTemplate; ...@@ -16,6 +16,7 @@ import org.springframework.web.client.RestTemplate;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Objects;
@Component @Component
public class HttpRestUtil { public class HttpRestUtil {
...@@ -94,11 +95,12 @@ public class HttpRestUtil { ...@@ -94,11 +95,12 @@ public class HttpRestUtil {
* @description: 发送POST请求,支持转换类型,应用多变性返回值,classType返回值类型 * @description: 发送POST请求,支持转换类型,应用多变性返回值,classType返回值类型
*/ */
public <T> T doPost(String url, Map<String, String> headers, String param, Class<T> classType) { public <T> T doPost(String url, Map<String, String> headers, String param, Class<T> classType) {
Map<String, String> header = Objects.isNull(headers) ? buildHeader() : headers;
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
LOGGER.info("\n 请求地址 = {} || 请求方式 = {} || 请求头 = {} || 请求参数 = {}", LOGGER.info("\n 请求地址 = {} || 请求方式 = {} || 请求头 = {} || 请求参数 = {}",
url, "POST", JSON.toJSONString(headers), JSON.toJSONString(param)); url, "POST", JSON.toJSONString(header), JSON.toJSONString(param));
//封装httpEntity //封装httpEntity
HttpEntity httpEntity = getHttpEntity(headers, param); HttpEntity httpEntity = getHttpEntity(header, param);
ResponseEntity<T> responseEntity; ResponseEntity<T> responseEntity;
try { try {
responseEntity = restTemplate.postForEntity(url, httpEntity, classType); responseEntity = restTemplate.postForEntity(url, httpEntity, classType);
......
package net.wanji.web.vo.signalservice;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
/**
* 控制指令VO
*
* @author wuxiaokai
* @date 2022/11/15 15:05:57
*/
@Data
@ApiModel(value = "ControlCommandVO", description = "相位锁定实体类")
public class ControlCommandVO {
@ApiModelProperty(value = "路口编号", notes = "路口编号")
@NotNull(message = "路口编号不可为空")
private String crossCode;
/**
* 1 锁定; 0 取消
*/
@ApiModelProperty(value = "1是;0否")
@NotNull(message = "控制标识不可为空,1是;0否")
@Max(value = 1, message = "控制标识:1是;0否")
@Min(value = 0, message = "控制标识:1是;0否")
private Integer command;
@ApiModelProperty(value = "1全红 2黄闪 3关灯")
@NotNull(message = "控制类型不可为空,1全红 2黄闪 3关灯")
private Integer controlType;
@ApiModelProperty(value = "持续时间")
private Integer duration;
}
package net.wanji.web.vo.signalservice;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Data
@ApiModel(value = "下发相位参数输入参数", description = "下发相位参数输入参数")
public class PhaseTimingSendVO {
@ApiModelProperty(value = "路口编号", notes = "路口编号")
private String crossCode;
@ApiModelProperty(value = "需要下发的相位列表", notes = "需要下发的相位列表")
private List<Phase> phaseList;
/**
* 相位
*/
@Setter
@Getter
public static class Phase {
/**
* 相位号
*/
@ApiModelProperty(value = "相位号", notes = "相位号")
private Integer phaseNo;
/**
* 相位描述
*/
@ApiModelProperty(value = "相位描述", notes = "相位描述")
private String desc;
/**
* 黄灯
*/
@ApiModelProperty(value = "黄灯", notes = "黄灯")
private Integer yellow;
/**
* 全红
*/
@ApiModelProperty(value = "全红", notes = "全红")
private Integer allred;
/**
* 绿闪
*/
@ApiModelProperty(value = "绿闪", notes = "绿闪")
private String greenFlash;
/**
* 红闪
*/
@ApiModelProperty(value = "红闪", notes = "红闪")
private String redFlash;
/**
* 最小绿
*/
@ApiModelProperty(value = "最小绿", notes = "最小绿")
private String minGreen;
/**
* 最大绿
*/
@ApiModelProperty(value = "最大绿", notes = "最大绿")
private String maxGreen;
/**
* 相位关联的车道列表
*/
@ApiModelProperty(value = "相位关联的车道列表", notes = "相位关联的车道列表")
private List<Lane> lanes;
@Setter
@Getter
public static class Lane {
/**
* 车道号
*/
@ApiModelProperty(value = "车道号", notes = "车道号")
private Integer laneNo;
/**
* 方向
*/
@ApiModelProperty(value = "方向", notes = "方向")
private Integer direction;
/**
* 转向
*/
@ApiModelProperty(value = "转向", notes = "转向")
private Integer turn;
}
}
}
package net.wanji.web.vo.signalservice;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* 信号机计划下发VO
*
* @author wuxiaokai
* @date 2022/11/24 15:55:08
*/
@Setter
@Getter
@ApiModel(value = "信号机计划下发输入参数", description = "信号机计划下发输入参数")
public class PlanSendVO {
@ApiModelProperty(value = "路口编号", notes = "路口编号")
private String crossCode;
@ApiModelProperty(value = "计划列表", notes = "计划列表")
private List<Plan> planList;
@Setter
@Getter
public static class Plan {
/**
* 计划号
*/
@ApiModelProperty(value = "计划号", notes = "计划号")
private String planNo;
/**
* 计划描述
*/
@ApiModelProperty(value = "计划描述", notes = "计划描述")
private String planDescribe;
/**
* 时段列表
*/
@ApiModelProperty(value = "时段列表", notes = "时段列表")
private List<Section> sectionList;
@Setter
@Getter
public static class Section {
/**
* 时段号
*/
@ApiModelProperty(value = "时段号", notes = "时段号")
private String sectionNo;
/**
* 开始时间
*/
@ApiModelProperty(value = "开始时间", notes = "开始时间")
private String beginTime;
/**
* 结束时间
*/
@ApiModelProperty(value = "结束时间", notes = "结束时间")
private String endTime;
/**
* 控制模式:1定周期;2绿灯;3黄灯;4红灯;5关灯;6绿闪;7黄闪;8红闪
*/
@ApiModelProperty(value = "控制模式:1定周期;2绿灯;3黄灯;4红灯;5关灯;6绿闪;7黄闪;8红闪", notes = "")
private String controlMode;
/**
* 方案号
*/
@ApiModelProperty(value = "方案号", notes = "")
private String patternNo;
}
}
}
package net.wanji.web.vo.signalservice;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Data
@ApiModel(value = "信号机时间表下发输入参数", description = "信号机时间表下发输入参数")
public class ScheduleSendVO {
@ApiModelProperty(value = "路口编号", notes = "路口编号")
private String crossCode;
@ApiModelProperty(value = "时间表", notes = "时间表")
private List<Schedule> schedules;
@Setter
@Getter
public static class Schedule {
/**
* 星期列表
*/
@ApiModelProperty(value = "星期列表", notes = "星期列表")
private List<Week> weeks;
/**
* 特殊日期列表
*/
@ApiModelProperty(value = "特殊日期列表", notes = "特殊日期列表")
private List<SpecialDay> specialDays;
@Setter
@Getter
public static class Week {
@ApiModelProperty(value = "星期", notes = "星期")
private Integer weekNum;
@ApiModelProperty(value = "计划号", notes = "计划号")
private Integer planNo;
}
@Setter
@Getter
public static class SpecialDay {
/**
* 日期 2019-05-01
*/
@ApiModelProperty(value = "日期", notes = "日期")
private String dateStr;
/**
* 计划号
*/
@ApiModelProperty(value = "计划号", notes = "计划号")
private Integer planNo;
}
}
}
package net.wanji.web.vo.signalservice;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Data
@ApiModel(value = "信号机方案下发输入参数", description = "信号机方案下发输入参数")
public class SchemeSendVO {
@ApiModelProperty(value = "路口编号", notes = "路口编号")
private String crossCode;
@ApiModelProperty(value = "方案列表", notes = "方案列表")
private List<Pattern> patternList;
/**
* 方案
*/
@Setter
@Getter
public static class Pattern {
/**
* 方案号
*/
@ApiModelProperty(value = "方案号", notes = "")
private String patternNo;
/**
* 方案名称
*/
@ApiModelProperty(value = "方案名称", notes = "")
private String patternName;
/**
* 方案周期
*/
@ApiModelProperty(value = "方案周期", notes = "")
private String cycle;
/**
* 协调相位号
*/
@ApiModelProperty(value = "协调相位号", notes = "")
private String coordPhase;
/**
* 协调相位差
*/
@ApiModelProperty(value = "协调相位差", notes = "协调相位差")
private String offset;
@ApiModelProperty(value = "环列表", notes = "环列表")
private List<Ring> rings;
@Setter
@Getter
public static class Ring {
@ApiModelProperty(value = "环号", notes = "环号")
private String ringNo;
@ApiModelProperty(value = "相位列表", notes = "相位列表")
private List<Phase> phaseList;
/**
* 相位
*/
@Setter
@Getter
public static class Phase {
/**
* 相位号
*/
@ApiModelProperty(value = "相位号", notes = "")
private String phaseNo;
/**
* 相位名称
*/
@ApiModelProperty(value = "相位名称", notes = "")
private String phaseName;
/**
* 相位序号
*/
@ApiModelProperty(value = "相位序号", notes = "")
private String sort;
/**
* 控制模式:1定周期;2绿灯;3黄灯;4红灯;5关灯;6绿闪;7黄闪;8红闪
*/
@ApiModelProperty(value = "控制模式:1定周期;2绿灯;3黄灯;4红灯;5关灯;6绿闪;7黄闪;8红闪", notes = "")
private String controlMode;
/**
* 最小绿灯时间
*/
@ApiModelProperty(value = "最小绿灯时间", notes = "")
private String minGreenTime;
/**
* 最大绿灯时间
*/
@ApiModelProperty(value = "最大绿灯时间", notes = "")
private String maxGreenTime;
/**
* 相位时间
*/
@ApiModelProperty(value = "相位时间", notes = "")
private String phaseTime;
/**
* 绿灯时间
*/
@ApiModelProperty(value = "绿灯时间", notes = "")
private String greenTime;
/**
* 绿闪时间
*/
@ApiModelProperty(value = "绿闪时间", notes = "")
private String greenFlashTime;
/**
* 行闪时间
*/
@ApiModelProperty(value = "行闪时间", notes = "")
private String pedFlashTime;
/**
* 黄灯时间
*/
@ApiModelProperty(value = "黄灯时间", notes = "")
private String yellowTime;
/**
* 红灯时间
*/
@ApiModelProperty(value = "红灯时间", notes = "")
private String redTime;
}
//@Setter
//@Getter
//public static class Lights {
//
// /**
// * 灯组号
// */
// @ApiModelProperty(value = "灯组号", notes = "")
// private String lightsNo;
// /**
// * 灯组名称
// */
// @ApiModelProperty(value = "灯组名称", notes = "")
// private String name;
// /**
// * 灯组类型:1箭头;2圆饼,3行人
// */
// @ApiModelProperty(value = "灯组类型:1箭头2圆饼3行人", notes = "")
// private String type;
// /**
// * 灯组方向:1北;2东北;3东;4东南;5南;6西南;7西;8西北
// */
// @ApiModelProperty(value = "灯组方向:1北;2东北;3东;4东南;5南;6西南;7西;8西北", notes = "")
// private String dir;
// /**
// * 灯组转向:1左转;2右转;3直行;4左掉头;5直左;6直右;7右掉头;8向左合流;9向右合流;10左转加掉头;11右转加掉头;12直行加左掉头;13直行加右掉头;14左转右转;15左直右;16左转右转加掉头;17左直掉头;18左直右掉头;20行人
// */
// @ApiModelProperty(value = "灯组转向:1左转;2右转;3直行;4左掉头;5直左;6直右;7右掉头;8向左合流;9向右合流;10左转加掉头;11右转加掉头;12直行加左掉头;13直行加右掉头;14左转右转;15左直右;16左转右转加掉头;17左直掉头;18左直右掉头;20行人", notes = "")
// private String turn;
// /**
// * 行人进出口:1进口;2出口,3进出口
// */
// @ApiModelProperty(value = "行人进出口:1进口2出口,3进出口", notes = "")
// private String inOutType;
//}
}
}
}
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