Commit 5f96130b authored by duanruiming's avatar duanruiming

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

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