Commit 180f4056 authored by hanbing's avatar hanbing

[update] utc,海信信号机灯态接收

parent 34d832a5
package net.wanji.feign.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author duanruiming
* @date 2023/05/19 9:41
*/
@Configuration(value = "FeignHisenseClientsConfig")
@EnableFeignClients(basePackages = "net.wanji.feign")
@Slf4j
public class FeignHisenseClientsConfig {
@Value("${utc.hisense.service.url}")
private String url;
@Bean
public void testUrl() {
log.info("===========feign config url hisense :" + url);
}
}
package net.wanji.feign.service;
import net.wanji.feign.config.FeignHisenseClientsConfig;
import net.wanji.feign.service.common.UtcFeignCommon;
import org.springframework.cloud.openfeign.FeignClient;
/**
* @author duanruiming
* @date 2023/05/19 9:05
*/
@FeignClient(name = "UtcHisenseFeignClients", url = "${utc.hisense.service.url}",
configuration = FeignHisenseClientsConfig.class)
public interface UtcHisenseFeignClients extends UtcFeignCommon {
}
utc.service.url=http://10.102.1.182:32000/utc
utc.dt.service.url=http://10.102.1.182:39002/utc-dt
\ No newline at end of file
utc.dt.service.url=http://10.102.1.182:39002/utc-dt
utc.hisense.service.url=http://10.102.1.182:39003/utc-hisense
\ No newline at end of file
utc.service.url=http://172.17.0.1:32000/utc
utc.dt.service.url=http://10.102.1.182:39002/utc-dt
\ No newline at end of file
utc.dt.service.url=http://172.17.0.1:39002/utc-dt
utc.hisense.service.url=http://172.17.0.1:39003/utc-hisense
\ No newline at end of file
utc.service.url=http://172.17.0.1:42000/utc
utc.dt.service.url=http://172.17.0.1:49002/utc-dt
\ No newline at end of file
utc.dt.service.url=http://172.17.0.1:49002/utc-dt
utc.hisense.service.url=http://172.17.0.1:49003/utc-hisense
\ No newline at end of file
utc.service.url=http://localhost:32000/utc
utc.dt.service.url=http://localhost:39002/utc-dt
\ No newline at end of file
utc.dt.service.url=http://localhost:39002/utc-dt
utc.hisense.service.url=http://localhost:39003/utc-hisense
\ No newline at end of file
utc.service.url=http://172.17.0.1:32000/utc
\ No newline at end of file
utc.service.url=http://172.17.0.1:32000/utc
utc.dt.service.url=http://172.17.0.1:39002/utc-dt
utc.hisense.service.url=http://172.17.0.1:39003/utc-hisense
\ No newline at end of file
utc.service.url=http://172.17.0.1:32000/utc
\ No newline at end of file
utc.service.url=http://172.17.0.1:32000/utc
utc.dt.service.url=http://172.17.0.1:39002/utc-dt
utc.hisense.service.url=http://172.17.0.1:39003/utc-hisense
\ No newline at end of file
......@@ -8,7 +8,7 @@ import org.apache.commons.lang3.StringUtils;
* @date 2023/05/08 10:17
*/
@Getter
public enum CommandResultSign {
public enum CommandResultSignEnum {
HEARTBEAT("80", "heartBeatService"),
GET_DEVICE_INFO("0d0120", "getDeviceInfoService"),
......@@ -47,7 +47,7 @@ public enum CommandResultSign {
private String hexSign;
private String className;
CommandResultSign(String hexSign, String className) {
CommandResultSignEnum(String hexSign, String className) {
this.hexSign = hexSign;
this.className = className;
}
......@@ -56,7 +56,7 @@ public enum CommandResultSign {
if (StringUtils.isEmpty(hexSign)) {
return null;
}
for (CommandResultSign uniqueCommandResultSign : values()) {
for (CommandResultSignEnum uniqueCommandResultSign : values()) {
if (uniqueCommandResultSign.hexSign.equals(hexSign)) {
return uniqueCommandResultSign.className;
}
......
......@@ -8,6 +8,7 @@ import io.netty.channel.socket.DatagramPacket;
import lombok.extern.slf4j.Slf4j;
import net.wanji.utc.dt.cache.CrossInfoCache;
import net.wanji.utc.dt.cache.netty.NettyMessageCache;
import net.wanji.utc.dt.common.enums.CommandResultSignEnum;
import net.wanji.utc.dt.netty.commandsign.CommandResultSign;
import net.wanji.utc.dt.netty.pojo.CommandPojo;
import net.wanji.utc.dt.netty.response.CommandResponseFactory;
......@@ -48,7 +49,7 @@ public class NettyServerHandler extends SimpleChannelInboundHandler<DatagramPack
log.error("返回命令标识为空hexSign: {}", hexSign);
return;
}
String className = net.wanji.utc.dt.common.enums.CommandResultSign.getClassNameByHexSign(hexSign);
String className = CommandResultSignEnum.getClassNameByHexSign(hexSign);
CommandResponseFactory commandResponseFactory = (CommandResponseFactory) ServiceBeanContext.getBean(className);
String key = StringUtils.join("/", remote.getHostString(), ":", remote.getPort(), "/", hexSign);
CommandPojo commandPojo = getCommandPojo(key, data);
......
......@@ -44,7 +44,7 @@ public class NettyClient {
.channel(NioDatagramChannel.class)
.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(65535))
.localAddress(new InetSocketAddress(localPort))
.remoteAddress(new InetSocketAddress(remotePort))
// .remoteAddress(new InetSocketAddress(remotePort))
.handler(new ChannelInitializer<NioDatagramChannel>() {
@Override
protected void initChannel(NioDatagramChannel datagramChannel) {
......
package net.wanji.utc.hisense.netty.codec;
import cn.hutool.core.util.HexUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
......@@ -19,6 +18,6 @@ public class MessageDecoder extends ByteToMessageDecoder {
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
byte[] bytes = new byte[in.readableBytes()];
in.readBytes(bytes);
out.add(HexUtil.encodeHexStr(bytes));
out.add(bytes);
}
}
package net.wanji.utc.hisense.netty.commandsign;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.alibaba.fastjson.JSON;
import net.wanji.utc.hisense.pojo.convert.RunningLightsStatusPojo;
/**
......@@ -8,8 +8,10 @@ import net.wanji.utc.hisense.pojo.convert.RunningLightsStatusPojo;
* @date 2023/05/08 10:14
*/
public class CommandResultSign {
public static Object getHexSign(String data) {
ObjectMapper mapper = new ObjectMapper();
return mapper.convertValue(data, RunningLightsStatusPojo.class);
Object runningLightsStatusPojo = JSON.parseObject(data, RunningLightsStatusPojo.class);
return runningLightsStatusPojo;
}
}
package net.wanji.utc.hisense.netty.handler;
import cn.hutool.core.util.HexUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
......@@ -9,17 +8,21 @@ import lombok.extern.slf4j.Slf4j;
import net.wanji.common.framework.spring.ServiceBeanContext;
import net.wanji.databus.po.CrossInfoPO;
import net.wanji.utc.hisense.cache.CrossInfoCache;
import net.wanji.utc.hisense.cache.SignalDataCache;
import net.wanji.utc.hisense.cache.netty.NettyMessageCache;
import net.wanji.utc.hisense.common.enums.CommandResultSignEnum;
import net.wanji.utc.hisense.netty.commandsign.CommandResultSign;
import net.wanji.utc.hisense.netty.pojo.CommandPojo;
import net.wanji.utc.hisense.netty.response.CommandResponseFactory;
import net.wanji.utc.hisense.pojo.convert.RunningLightsStatusPojo;
import net.wanji.utc.hisense.pojo.netty.MessageResultPojo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Objects;
@Slf4j
......@@ -43,11 +46,25 @@ public class NettyServerHandler extends SimpleChannelInboundHandler<DatagramPack
int i = content.readableBytes();
byte[] b = new byte[i];
content.readBytes(b);
String data = HexUtil.encodeHexStr(b);
String data = new String(b, StandardCharsets.UTF_8);
Object resultPojo = CommandResultSign.getHexSign(data);
String className = CommandResultSignEnum.getResultPojo(resultPojo);
CommandResponseFactory commandResponseFactory = (CommandResponseFactory) ServiceBeanContext.getBean(className);
String key = StringUtils.join("/", remote.getHostString(), ":", remote.getPort(), "/", resultPojo.getClass().getSimpleName());
if (CommandResultSignEnum.GET_RUNNING_STATE_INFO.getClassName().equals(className)) {
// 直接set灯态缓存
RunningLightsStatusPojo pojo = (RunningLightsStatusPojo) resultPojo;
String crossId = pojo.getCID();
Map<String, RunningLightsStatusPojo> cache = SignalDataCache.runningStateInfoCache;
cache.put(crossId, pojo);
}
Object bean = ServiceBeanContext.getBean(className);
CommandResponseFactory commandResponseFactory = ServiceBeanContext.getBean(className);
String key = StringUtils.join("/", remote.getHostString(), ":", remote.getPort(), "/",
resultPojo.getClass().getSimpleName());
CommandPojo commandPojo = getCommandPojo(key, resultPojo);
Object hexResult = commandResponseFactory.getCommandResponse(commandPojo);
if (Objects.nonNull(hexResult)) {
......
......@@ -2,19 +2,10 @@ package net.wanji.utc.hisense.netty.response.impl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.wanji.utc.hisense.cache.CrossInfoCache;
import net.wanji.utc.hisense.common.constants.Constants;
import net.wanji.utc.hisense.netty.NettyClient;
import net.wanji.utc.hisense.netty.pojo.CommandPojo;
import net.wanji.utc.hisense.netty.response.CommandResponseFactory;
import net.wanji.utc.hisense.pojo.netty.MessageResultPojo;
import net.wanji.databus.po.CrossInfoPO;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* @author duanruiming
* @date 2023/05/12 11:00
......@@ -24,25 +15,9 @@ import java.util.Map;
@RequiredArgsConstructor
public class HeartBeatService implements CommandResponseFactory {
private final CrossInfoCache crossInfoCache;
private final ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Override
public Object getCommandResponse(CommandPojo commandPojo) {
return commandPojo.getResponseMsg();
}
@Scheduled(fixedRate = 30 * 1000, initialDelay = 10 * 1000)
public void heartbeat() {
Map<String, CrossInfoPO> crossInfoMap = crossInfoCache.getCrossInfoCache();
for (Map.Entry<String, CrossInfoPO> entry : crossInfoMap.entrySet()) {
CrossInfoPO crossInfoPO = entry.getValue();
String ip = crossInfoPO.getIp();
Integer port = crossInfoPO.getPort();
threadPoolTaskExecutor.execute(() -> {
String heartBeatRequest = Constants.buildMessage(Constants.COMMAND_HEART_BEAT_QUERY);
MessageResultPojo resultPojo = NettyClient.sendMessage(ip, port, heartBeatRequest, Constants.COMMAND_HEART_BEAT_REPLY, 300);
});
}
}
}
package net.wanji.utc.hisense.service.protocol.impl.base;
import lombok.extern.slf4j.Slf4j;
import net.wanji.databus.po.CrossInfoPO;
import net.wanji.utc.hisense.netty.NettyClient;
import net.wanji.utc.hisense.pojo.netty.MessageResultPojo;
import net.wanji.utc.hisense.service.protocol.ProtocolConversion;
import net.wanji.databus.po.CrossInfoPO;
import org.springframework.stereotype.Service;
/**
......
......@@ -10,6 +10,6 @@ spring:
password: nacos
application:
# dubbo启动需要程序名称
name: utc-dt
name: utc-hisense
main:
allow-circular-references: true
......@@ -38,7 +38,7 @@
<charset>${encoding}</charset>
</encoder>
<!--滚动策略-->
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAnhisenseimeBasedRollingPolicy">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!--路径-->
<fileNamePattern>${LOG_PATH}/hisense/%d{yyyy-MM-dd}/info.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<MaxHistory>30</MaxHistory>
......@@ -57,7 +57,7 @@
<charset>${encoding}</charset>
</encoder>
<!--滚动策略-->
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAnhisenseimeBasedRollingPolicy">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!--路径-->
<fileNamePattern>${LOG_PATH}/hisense/%d{yyyy-MM-dd}/error.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<MaxHistory>30</MaxHistory>
......
......@@ -8,7 +8,8 @@ public class BasicEnum {
@AllArgsConstructor
public enum ManufacturerEnum {
HK("海康", "HK"),
DT("东土", "DT");
DT("东土", "DT"),
HISENSE("海信", "HISENSE");
private String nick;
private String code;
......
......@@ -26,7 +26,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* @date 2022/11/21 9:11
......@@ -59,8 +58,8 @@ public class SignalStatusServiceImpl implements SignalStatusService {
signalStatusLogPOList = hkRunningStatusService.getHkRunningStatus(baseCrossInfoList);
} else {
// todo 其他厂商
List<String> crossIdList = baseCrossInfoList.stream().map(BaseCrossInfo::getCrossId).collect(Collectors.toList());
signalStatusLogPOList = wanJiRunningStatusService.runningStatus(crossIdList);
// List<String> crossIdList = baseCrossInfoList.stream().map(BaseCrossInfo::getCrossId).collect(Collectors.toList());
// signalStatusLogPOList = wanJiRunningStatusService.runningStatus(crossIdList);
}
// 更新Redis
if (null != signalStatusLogPOList) {
......@@ -129,8 +128,8 @@ public class SignalStatusServiceImpl implements SignalStatusService {
lightsStatusVOList = hkLightsStatusService.getHkLightsStatus(baseCrossInfoList);
} else {
// todo 其他厂商
List<String> crossIdList = baseCrossInfoList.stream().map(BaseCrossInfo::getCrossId).collect(Collectors.toList());
lightsStatusVOList = wanJiRunningStatusService.lightsStatus(crossIdList);
// List<String> crossIdList = baseCrossInfoList.stream().map(BaseCrossInfo::getCrossId).collect(Collectors.toList());
// lightsStatusVOList = wanJiRunningStatusService.lightsStatus(crossIdList);
}
// 更新Redis
if (lightsStatusVOList != null) {
......
......@@ -49,8 +49,8 @@ public class StaticInfoServiceImpl implements StaticInfoService {
crossInfoPOList = hkCrossInfoService.hkCrossBasicInfo();
} else {
// todo 其他厂商
Integer manufacturerId = manufacturerInfoMapper.selectIdByCode(crossInfoVO.getManufacturerCode());
crossInfoPOList = crossInfoMapper.selectByManufacturerId(manufacturerId);
// Integer manufacturerId = manufacturerInfoMapper.selectIdByCode(crossInfoVO.getManufacturerCode());
// crossInfoPOList = crossInfoMapper.selectByManufacturerId(manufacturerId);
}
//存储信号机信息
if (crossInfoPOList.size() == 0) {
......@@ -91,10 +91,10 @@ public class StaticInfoServiceImpl implements StaticInfoService {
if (Objects.equals(BasicEnum.ManufacturerEnum.HK.getCode(), manufacturerCode)) {
// 海康
hkSchemePhaseLightsService.hkSchemePhaseLights(crossId, crossCode);
// todo 其他厂商
} else {
// todo 其他厂商
// 默认万集标准服务
wanjiCommonStaticInfoService.schemePhaseLights(crossId, crossCode);
// wanjiCommonStaticInfoService.schemePhaseLights(crossId, crossCode);
}
}
......
package net.wanji.utc.task;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -13,6 +15,7 @@ import net.wanji.databus.po.ManufacturerInfoPO;
import net.wanji.databus.po.SignalStatusLogPO;
import net.wanji.databus.vo.LightsStatusVO;
import net.wanji.feign.service.UtcDTFeignClients;
import net.wanji.feign.service.UtcHisenseFeignClients;
import net.wanji.utc.common.constant.Constants;
import net.wanji.utc.common.typeenum.BasicEnum;
import net.wanji.utc.service.runninginfo.HkLightsStatusService;
......@@ -20,6 +23,7 @@ import net.wanji.utc.service.runninginfo.SignalStatusService;
import net.wanji.utc.websocket.RealTimeDataWebSocket;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
......@@ -87,7 +91,11 @@ public class SignalStatusTask {
JsonViewObject jsonViewObject = utcDTFeignClients.lightStatus(crossId);
ObjectMapper mapper = new ObjectMapper();
lightsStatusVOS = mapper.convertValue(jsonViewObject.getContent(), new TypeReference<List<LightsStatusVO>>() {});
} else if (StringUtils.equals(BasicEnum.ManufacturerEnum.HISENSE.getCode(),
manufacturerInfoPO.getCode())){
JsonViewObject jsonViewObject = utcHisenseFeignClients.lightStatus(crossId);
String content = (String) jsonViewObject.getContent();
lightsStatusVOS = JSON.parseObject(content, new TypeReference<List<LightsStatusVO>>() {});
}
long end = System.currentTimeMillis();
log.info("当前路口编号:{},海康返回灯态时间:{}ms", crossId, (end - start));
......
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