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.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