Commit 5f96130b authored by duanruiming's avatar duanruiming

[update] 优化海康实时状态自动任务,下发方案返回实体

parent ddd3efeb
...@@ -8,7 +8,7 @@ import lombok.Data; ...@@ -8,7 +8,7 @@ import lombok.Data;
*/ */
@Data @Data
public class HKResponse { public class HKResponse {
private Integer code; private String code;
private String msg; private String msg;
private Integer type; private Integer type;
private Object data; private Object data;
......
...@@ -143,7 +143,7 @@ public class HKControlCommandServiceImpl implements ControlCommandService { ...@@ -143,7 +143,7 @@ public class HKControlCommandServiceImpl implements ControlCommandService {
Map<String, String> path = PathUtil.getPathMapByApiCode("downloadTimeSpands"); Map<String, String> path = PathUtil.getPathMapByApiCode("downloadTimeSpands");
String strResult = ArtemisHttpUtil.doPostStringArtemis(artemisConfig, path, JSON.toJSONString(fieldMap), null, null, "application/json", null); String strResult = ArtemisHttpUtil.doPostStringArtemis(artemisConfig, path, JSON.toJSONString(fieldMap), null, null, "application/json", null);
HKResponse hkResponse = JSONObject.parseObject(strResult, HKResponse.class); HKResponse hkResponse = JSONObject.parseObject(strResult, HKResponse.class);
if (Objects.nonNull(hkResponse) && Objects.equals(HK_SUCCESS_STRING_CODE, hkResponse.getCode())) { if (Objects.nonNull(hkResponse) && Objects.equals(HK_SUCCESS_STRING_CODE, String.valueOf(hkResponse.getCode()))) {
return jsonViewObject.success("海康下发信号机计划成功"); return jsonViewObject.success("海康下发信号机计划成功");
} }
return jsonViewObject.fail("海康下发信号机计划失败,".concat(hkResponse.getMsg())); return jsonViewObject.fail("海康下发信号机计划失败,".concat(hkResponse.getMsg()));
......
...@@ -23,6 +23,7 @@ import net.wanji.utc.util.PathUtil; ...@@ -23,6 +23,7 @@ import net.wanji.utc.util.PathUtil;
import net.wanji.utc.util.StringUtils; import net.wanji.utc.util.StringUtils;
import net.wanji.utc.vo.LightsStatusVO; import net.wanji.utc.vo.LightsStatusVO;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.*; import java.util.*;
...@@ -100,74 +101,76 @@ public class HkLightsStatusServiceImpl implements HkLightsStatusService { ...@@ -100,74 +101,76 @@ public class HkLightsStatusServiceImpl implements HkLightsStatusService {
Object data = callHKService("getRealtimeSchemeStateInfo", jsonBody); Object data = callHKService("getRealtimeSchemeStateInfo", jsonBody);
if (Objects.nonNull(data)) { if (Objects.nonNull(data)) {
RealTimeStateInfoListPO realTimeStateInfoListPO = JSONObject.parseObject(String.valueOf(data), RealTimeStateInfoListPO.class); RealTimeStateInfoListPO realTimeStateInfoListPO = JSONObject.parseObject(String.valueOf(data), RealTimeStateInfoListPO.class);
LightsStatusVO infoVo = null; LightsStatusVO infoVo = new LightsStatusVO();
for (RealTimeStateInfoPO resultPO : realTimeStateInfoListPO.getList()) { if (!CollectionUtils.isEmpty(realTimeStateInfoListPO.getList())) {
infoVo = new LightsStatusVO(); for (RealTimeStateInfoPO resultPO : realTimeStateInfoListPO.getList()) {
Integer patternNo = resultPO.getPatternNo(); infoVo = new LightsStatusVO();
List<RingsPO> rings = resultPO.getRings(); // 环列表 Integer patternNo = resultPO.getPatternNo();
List<ChannelStatePO> channelState = resultPO.getChannelState();// 灯组列表 List<RingsPO> rings = resultPO.getRings(); // 环列表
String HKControlType = resultPO.getControlType(); List<ChannelStatePO> channelState = resultPO.getChannelState();// 灯组列表
String WJControlType = null; String HKControlType = resultPO.getControlType();
if (StringUtils.isNotBlank(HKControlType)) { String WJControlType = null;
WJControlType = runModeParseMap.get(HKControlType); if (StringUtils.isNotBlank(HKControlType)) {
} WJControlType = runModeParseMap.get(HKControlType);
if (StringUtils.isEmpty(WJControlType)) { }
WJControlType = "255";// 转换失败默认临时方案 if (StringUtils.isEmpty(WJControlType)) {
} WJControlType = "255";// 转换失败默认临时方案
infoVo.setRunMode(WJControlType);// 控制模式 }
infoVo.setPhasePlanId(String.valueOf(patternNo)); // 相位方案号 infoVo.setRunMode(WJControlType);// 控制模式
int cycleLen = resultPO.getCycle(); // 周期时长 infoVo.setPhasePlanId(String.valueOf(patternNo)); // 相位方案号
int curRunTime = resultPO.getCurRunTime(); // 当前运行时长 int cycleLen = resultPO.getCycle(); // 周期时长
int cycleCountDown = cycleLen - curRunTime; // 周期剩余时长 int curRunTime = resultPO.getCurRunTime(); // 当前运行时长
infoVo.setCode(signalCode); int cycleCountDown = cycleLen - curRunTime; // 周期剩余时长
infoVo.setCrossId(crossId); infoVo.setCode(signalCode);
infoVo.setCrossId(crossId);
// infoVo.setManufacturerCode(""); // 应该不需要 // infoVo.setManufacturerCode(""); // 应该不需要
infoVo.setCycleCountDown(cycleCountDown); infoVo.setCycleCountDown(cycleCountDown);
infoVo.setCycleLen(cycleLen); infoVo.setCycleLen(cycleLen);
// 循环相位列表 // 循环相位列表
Map<String, Object> phaseMap = new HashMap<>(); Map<String, Object> phaseMap = new HashMap<>();
for (RingsPO ring : rings) { for (RingsPO ring : rings) {
List<PhaseInfoPO> phaseList = ring.getPhaseList(); List<PhaseInfoPO> phaseList = ring.getPhaseList();
for (PhaseInfoPO phaseInfoPO : phaseList) { for (PhaseInfoPO phaseInfoPO : phaseList) {
Integer phaseNo = phaseInfoPO.getPhaseNo(); Integer phaseNo = phaseInfoPO.getPhaseNo();
Integer vehicleStatus = phaseInfoPO.getVehicleStatus(); Integer vehicleStatus = phaseInfoPO.getVehicleStatus();
Integer phaseLength = phaseInfoPO.getPhaseLength(); Integer phaseLength = phaseInfoPO.getPhaseLength();
Integer red = phaseInfoPO.getRed(); Integer red = phaseInfoPO.getRed();
Integer yellow = phaseInfoPO.getYellow(); Integer yellow = phaseInfoPO.getYellow();
Integer green = phaseLength - yellow - red; Integer green = phaseLength - yellow - red;
phaseMap.put(String.valueOf(phaseNo), green); phaseMap.put(String.valueOf(phaseNo), green);
if (2 != vehicleStatus) { // 2红灯 if (2 != vehicleStatus) { // 2红灯
infoVo.setPhaseId(String.valueOf(phaseNo)); infoVo.setPhaseId(String.valueOf(phaseNo));
}
} }
} }
} infoVo.setPhaseMap(phaseMap);
infoVo.setPhaseMap(phaseMap);
Map<String, Object> dirLampGroupMap = new HashMap<>(); Map<String, Object> dirLampGroupMap = new HashMap<>();
// 循环构建灯组对象(从灯组表获取灯组信息) // 循环构建灯组对象(从灯组表获取灯组信息)
for (ChannelStatePO channelStatePO : channelState) { for (ChannelStatePO channelStatePO : channelState) {
Integer channelNo = channelStatePO.getChannelNo(); Integer channelNo = channelStatePO.getChannelNo();
Integer state = channelStatePO.getState(); Integer state = channelStatePO.getState();
String color = transferHKLampGroup(state); String color = transferHKLampGroup(state);
for (CrossLightsPO po : crossLightsPOList) { for (CrossLightsPO po : crossLightsPOList) {
if (StringUtils.equals(po.getLightsNo(), String.valueOf(channelNo))) { if (StringUtils.equals(po.getLightsNo(), String.valueOf(channelNo))) {
String direction = po.getDir().toString(); String direction = po.getDir().toString();
String turn = po.getTurn().toString(); String turn = po.getTurn().toString();
if (dirLampGroupMap.get(direction) != null) { if (dirLampGroupMap.get(direction) != null) {
Map<String, String> mstr = (Map<String, String>) dirLampGroupMap.get(direction); Map<String, String> mstr = (Map<String, String>) dirLampGroupMap.get(direction);
mstr.put(turn, color); mstr.put(turn, color);
dirLampGroupMap.put(direction, mstr); dirLampGroupMap.put(direction, mstr);
} else { } else {
Map<String, String> lamp = new HashMap<>(); Map<String, String> lamp = new HashMap<>();
lamp.put(turn, color); lamp.put(turn, color);
dirLampGroupMap.put(direction, lamp); dirLampGroupMap.put(direction, lamp);
}
} }
} }
} }
infoVo.setDirLampGroupMap(dirLampGroupMap);
} }
infoVo.setDirLampGroupMap(dirLampGroupMap); result.add(infoVo);
} }
result.add(infoVo);
} }
} }
return result; return result;
...@@ -196,7 +199,7 @@ public class HkLightsStatusServiceImpl implements HkLightsStatusService { ...@@ -196,7 +199,7 @@ public class HkLightsStatusServiceImpl implements HkLightsStatusService {
String responseStr = ArtemisHttpUtil.doPostStringArtemis(artemisConfig, path, jsonBody, null, null, "application/json", null); String responseStr = ArtemisHttpUtil.doPostStringArtemis(artemisConfig, path, jsonBody, null, null, "application/json", null);
if (StringUtils.isNotBlank(responseStr)) { if (StringUtils.isNotBlank(responseStr)) {
HKResponse hkResponse = JSONObject.parseObject(responseStr, HKResponse.class); HKResponse hkResponse = JSONObject.parseObject(responseStr, HKResponse.class);
if (Objects.nonNull(hkResponse) && Objects.equals(Constants.HK_SUCCESS_CODE, hkResponse.getCode())) { if (Objects.nonNull(hkResponse) && Objects.equals(Constants.HK_SUCCESS_STRING_CODE, hkResponse.getCode())) {
return hkResponse.getData(); return hkResponse.getData();
} else { } else {
log.error("ArtemisHttpUtil海康服务调用异常,请求路径:{}, 返回信息: {}, 请求信息: {}", apiPath, hkResponse, jsonBody); log.error("ArtemisHttpUtil海康服务调用异常,请求路径:{}, 返回信息: {}, 请求信息: {}", apiPath, hkResponse, jsonBody);
......
...@@ -23,6 +23,7 @@ import net.wanji.utc.service.staticinfo.HkCrossSchedulesService; ...@@ -23,6 +23,7 @@ import net.wanji.utc.service.staticinfo.HkCrossSchedulesService;
import net.wanji.utc.util.PathUtil; import net.wanji.utc.util.PathUtil;
import net.wanji.utc.util.StringUtils; import net.wanji.utc.util.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.*; import java.util.*;
...@@ -47,7 +48,7 @@ public class HkCrossSchedulesServiceImpl implements HkCrossSchedulesService { ...@@ -47,7 +48,7 @@ public class HkCrossSchedulesServiceImpl implements HkCrossSchedulesService {
String body = JSONArray.toJSONString(crossCodeList); String body = JSONArray.toJSONString(crossCodeList);
String responseStr = ArtemisHttpUtil.doPostStringArtemis(artemisConfig, path, body, null, null, "application/json", null); String responseStr = ArtemisHttpUtil.doPostStringArtemis(artemisConfig, path, body, null, null, "application/json", null);
HKResponse hkResponse = JSONObject.parseObject(responseStr, HKResponse.class); HKResponse hkResponse = JSONObject.parseObject(responseStr, HKResponse.class);
if (Objects.nonNull(hkResponse) && Objects.equals(Constants.HK_SUCCESS_CODE, hkResponse.getCode())) { if (Objects.nonNull(hkResponse) && Objects.equals(Constants.HK_SUCCESS_STRING_CODE, hkResponse.getCode())) {
String dataStr = String.valueOf(hkResponse.getData()); String dataStr = String.valueOf(hkResponse.getData());
if (StringUtils.isNotBlank(dataStr)) { if (StringUtils.isNotBlank(dataStr)) {
List<ScheduleResponseListPO> scheduleResponseListPOS = JSONObject.parseObject(dataStr, new TypeReference<List<ScheduleResponseListPO>>() {}); List<ScheduleResponseListPO> scheduleResponseListPOS = JSONObject.parseObject(dataStr, new TypeReference<List<ScheduleResponseListPO>>() {});
...@@ -55,43 +56,45 @@ public class HkCrossSchedulesServiceImpl implements HkCrossSchedulesService { ...@@ -55,43 +56,45 @@ public class HkCrossSchedulesServiceImpl implements HkCrossSchedulesService {
String crossCode = scheduleResponseListPO.getCrossCode(); String crossCode = scheduleResponseListPO.getCrossCode();
List<ScheduleResponsePO> schedules = scheduleResponseListPO.getSchedules(); List<ScheduleResponsePO> schedules = scheduleResponseListPO.getSchedules();
List<CrossSchedulesPO> crossSchedulesPOList = new ArrayList<>(); List<CrossSchedulesPO> crossSchedulesPOList = new ArrayList<>();
for (ScheduleResponsePO scheduleResponsePO : schedules) { if (!CollectionUtils.isEmpty(schedules)) {
String code = BasicEnum.ManufacturerEnum.HK.getCode(); for (ScheduleResponsePO scheduleResponsePO : schedules) {
ManufacturerInfoPO manufacturerInfoPO = manufacturerInfoMapper.selectByCode(code); String code = BasicEnum.ManufacturerEnum.HK.getCode();
Integer manufacturerId = manufacturerInfoPO.getId(); ManufacturerInfoPO manufacturerInfoPO = manufacturerInfoMapper.selectByCode(code);
String crossId = crossInfoMapper.selectIdByCodeAndManufacturerId(crossCode, manufacturerId); Integer manufacturerId = manufacturerInfoPO.getId();
List<Integer> weeks = scheduleResponsePO.getWeeks(); String crossId = crossInfoMapper.selectIdByCodeAndManufacturerId(crossCode, manufacturerId);
String desc = scheduleResponsePO.getDesc(); List<Integer> weeks = scheduleResponsePO.getWeeks();
Integer planNo = scheduleResponsePO.getPlanNo(); String desc = scheduleResponsePO.getDesc();
Integer planId = crossPlanMapper.selectIdByNo(crossId, planNo); Integer planNo = scheduleResponsePO.getPlanNo();
for (int k = 0; k < weeks.size(); k++) { Integer planId = crossPlanMapper.selectIdByNo(crossId, planNo);
Integer week = weeks.get(k); for (int k = 0; k < weeks.size(); k++) {
CrossSchedulesPO crossSchedulesPO = new CrossSchedulesPO(); Integer week = weeks.get(k);
crossSchedulesPO.setScheduleNo(scheduleResponsePO.getId()); CrossSchedulesPO crossSchedulesPO = new CrossSchedulesPO();
crossSchedulesPO.setName(desc); crossSchedulesPO.setScheduleNo(scheduleResponsePO.getId());
crossSchedulesPO.setCrossId(crossId); crossSchedulesPO.setName(desc);
crossSchedulesPO.setPlanId(planId); crossSchedulesPO.setCrossId(crossId);
crossSchedulesPO.setWeek(week); crossSchedulesPO.setPlanId(planId);
if (week != 0) { crossSchedulesPO.setWeek(week);
crossSchedulesPOList.add(crossSchedulesPO); if (week != 0) {
} else { crossSchedulesPOList.add(crossSchedulesPO);
// 特殊日期 } else {
List<DatePO> dates = scheduleResponsePO.getDates(); // 特殊日期
for (int m = 0; m < dates.size(); m++) { List<DatePO> dates = scheduleResponsePO.getDates();
DatePO date = dates.get(m); for (int m = 0; m < dates.size(); m++) {
List<Integer> days = date.getDays(); DatePO date = dates.get(m);
for (int n = 0; n < days.size(); n++) { List<Integer> days = date.getDays();
Integer day = days.get(n); for (int n = 0; n < days.size(); n++) {
Date specialDate = toDate(date, day); Integer day = days.get(n);
crossSchedulesPO.setSpecialDate(specialDate); Date specialDate = toDate(date, day);
crossSchedulesPOList.add(crossSchedulesPO); crossSchedulesPO.setSpecialDate(specialDate);
crossSchedulesPOList.add(crossSchedulesPO);
}
} }
} }
} }
// 插入数据库
crossSchedulesMapper.deleteByCrossId(crossId);
crossSchedulesMapper.insertBatch(crossSchedulesPOList);
} }
// 插入数据库
crossSchedulesMapper.deleteByCrossId(crossId);
crossSchedulesMapper.insertBatch(crossSchedulesPOList);
} }
} }
} }
......
...@@ -13,10 +13,9 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -13,10 +13,9 @@ 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.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -66,18 +65,19 @@ public class SignalStatusTask { ...@@ -66,18 +65,19 @@ public class SignalStatusTask {
} }
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
List<LightsStatusVO> lightsStatusVOS = hkLightsStatusService.getHkLightsStatus("14Q1409IRF0"); List<LightsStatusVO> lightsStatusVOS = hkLightsStatusService.getHkLightsStatus(crossId);
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
System.err.println(crossId + ":线程池名称:" + Thread.currentThread().getName()); log.info("当前路口编号:{},海康返回灯态时间:{}ms", crossId, (end - start));
System.err.println(crossId + ":海康平台返回灯态数据时间: " + (end - start) / 1000 + "--" + LocalDateTime.now());
RealTimeDataWebSocket webSocket = entry.getValue(); RealTimeDataWebSocket webSocket = entry.getValue();
for (LightsStatusVO lightsStatusVO : lightsStatusVOS) { if (!CollectionUtils.isEmpty(lightsStatusVOS)) {
if (Objects.equals(lightsStatusVO.getCrossId(), crossId)) { for (LightsStatusVO lightsStatusVO : lightsStatusVOS) {
try { if (Objects.equals(lightsStatusVO.getCrossId(), crossId)) {
webSocket.sendInfo(JSONObject.toJSONString(lightsStatusVOS, SerializerFeature.WriteMapNullValue), crossIdStr); try {
} catch (IOException e) { webSocket.sendInfo(JSONObject.toJSONString(lightsStatusVOS, SerializerFeature.WriteMapNullValue), crossIdStr);
log.error("RealTimeDataWebSocket发送异常,"); } catch (Exception e) {
log.error("RealTimeDataWebSocket发送异常,异常信息:", e);
}
} }
} }
} }
......
...@@ -32,7 +32,24 @@ spring: ...@@ -32,7 +32,24 @@ spring:
timeout: 5000 timeout: 5000
database: 5 database: 5
# 信号平台 # 大厅信号平台
#signal:
# # true测试不执行方案下发 重点
# mock: false
# # 厂商接口
# manufacturer:
# hk:
# # 服务地址
# artemisHost: 10.100.4.30
# # 接口服务验证用户名
# artemisAppKey: 21882146
# # 接口服务验证密钥
# artemisAppSecret: iYwMHJSo7CAX62TjyGEb
# # 海康能力开放平台的网站路径
# artemisPath: /artemis
# 工位信号平台
signal: signal:
# true测试不执行方案下发 重点 # true测试不执行方案下发 重点
mock: false mock: false
...@@ -40,10 +57,10 @@ signal: ...@@ -40,10 +57,10 @@ signal:
manufacturer: manufacturer:
hk: hk:
# 服务地址 # 服务地址
artemisHost: 10.100.4.30 artemisHost: 10.100.1.58
# 接口服务验证用户名 # 接口服务验证用户名
artemisAppKey: 21882146 artemisAppKey: 20893705
# 接口服务验证密钥 # 接口服务验证密钥
artemisAppSecret: iYwMHJSo7CAX62TjyGEb artemisAppSecret: jwr6D6h8xcZbgjqiwe6G
# 海康能力开放平台的网站路径 # 海康能力开放平台的网站路径
artemisPath: /artemis artemisPath: /artemis
\ No newline at end of file
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