Commit 6cd45b92 authored by duanruiming's avatar duanruiming

[update] 优化持久层

parent c9a6d3b7
......@@ -6,8 +6,8 @@
<artifactId>traffic-signal-platform</artifactId>
<version>0.2.1</version>
</parent>
<artifactId>signal-communication-service</artifactId>
<name>signal-communication-service</name>
<artifactId>signal-utc-dt-service</artifactId>
<name>signal-utc-dt-service</name>
<properties>
<java.version>1.8</java.version>
......
......@@ -17,10 +17,10 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableTransactionManagement
@EnableScheduling
@SuppressWarnings("all")
public class CommunicationApplication implements CommandLineRunner {
public class Application implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(CommunicationApplication.class, args);
SpringApplication.run(Application.class, args);
}
@Override
......
package net.wanji.com.cache;
import lombok.extern.slf4j.Slf4j;
import net.wanji.com.mapper.TCrossInfoMapper;
import net.wanji.com.pojo.po.CrossInfoPO;
import net.wanji.databus.dao.mapper.CrossInfoMapper;
import net.wanji.databus.po.CrossInfoPO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
......@@ -23,7 +23,7 @@ import java.util.Map;
public class CrossInfoCache implements CommandLineRunner {
@Resource
private TCrossInfoMapper tCrossInfoMapper;
private CrossInfoMapper crossInfoMapper;
private static final Map<String, CrossInfoPO> crossInfoMap = new HashMap<>();
......@@ -47,10 +47,10 @@ public class CrossInfoCache implements CommandLineRunner {
}
private void init() {
List<CrossInfoPO> crossInfoPOS = tCrossInfoMapper.selectAll();
for (CrossInfoPO crossInfoPO : crossInfoPOS) {
String key = StringUtils.join("/", crossInfoPO.getIp(), ":", crossInfoPO.getPort());
crossInfoMap.put(key, crossInfoPO);
List<CrossInfoPO> CrossInfoPOS = crossInfoMapper.selectAll();
for (CrossInfoPO CrossInfoPO : CrossInfoPOS) {
String key = StringUtils.join("/", CrossInfoPO.getIp(), ":", CrossInfoPO.getPort());
crossInfoMap.put(key, CrossInfoPO);
}
}
......
......@@ -10,12 +10,12 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import net.wanji.com.pojo.po.SignalStatusLogPO;
import net.wanji.com.pojo.vo.LightsStatusVO;
import net.wanji.com.service.controller.SignalStatusService;
import net.wanji.common.annotation.aspect.AspectLog;
import net.wanji.common.enums.BaseEnum;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.databus.po.SignalStatusLogPO;
import net.wanji.databus.vo.LightsStatusVO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......
......@@ -5,18 +5,18 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import net.wanji.com.pojo.dto.CrossInfoDTO;
import net.wanji.com.pojo.dto.CrossSchedulesDTO;
import net.wanji.com.pojo.dto.PlanSectionDTO;
import net.wanji.com.pojo.dto.SchemePhaseLightsDTO;
import net.wanji.com.pojo.po.CrossInfoPO;
import net.wanji.com.pojo.po.CrossSchedulesPO;
import net.wanji.com.pojo.vo.PlanSectionVO;
import net.wanji.com.pojo.vo.SchemePhaseLightsVO;
import net.wanji.com.service.controller.StaticInfoService;
import net.wanji.common.annotation.aspect.AspectLog;
import net.wanji.common.enums.BaseEnum;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.databus.dao.entity.CrossSchedulesPO;
import net.wanji.databus.dto.CrossInfoDTO;
import net.wanji.databus.dto.CrossSchedulesDTO;
import net.wanji.databus.dto.PlanSectionDTO;
import net.wanji.databus.dto.SchemePhaseLightsDTO;
import net.wanji.databus.po.CrossInfoPO;
import net.wanji.databus.vo.PlanSectionVO;
import net.wanji.databus.vo.SchemePhaseLightsVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
......
......@@ -102,7 +102,7 @@ public class NettyServer {
}
MessageResultPojo resultPojo = NettyMessageCache.NETTY_MESSAGE_RESULT_MAP.remove(key);
if (Objects.nonNull(resultPojo)) {
return resultPojo.getMessageHexStr();
return resultPojo.getHexMessageResult();
}
return null;
}
......
......@@ -8,13 +8,14 @@ import net.wanji.com.cache.CrossInfoCache;
import net.wanji.com.cache.netty.NettyMessageCache;
import net.wanji.com.common.enums.HexSign;
import net.wanji.com.netty.agreementcommon.AgreementCommon;
import net.wanji.com.netty.result.CommandResultService;
import net.wanji.com.pojo.netty.MessageResultPojo;
import net.wanji.com.pojo.po.CrossInfoPO;
import net.wanji.com.service.protocol.ProtocolConversionService;
import net.wanji.common.framework.spring.ServiceBeanContext;
import net.wanji.databus.po.CrossInfoPO;
import org.apache.commons.lang3.StringUtils;
import javax.annotation.Resource;
import java.util.Objects;
@Slf4j
@NoArgsConstructor
......@@ -53,19 +54,19 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
return;
}
String className = HexSign.getClassNameByHexSign(hexSign);
ProtocolConversionService bean = (ProtocolConversionService) ServiceBeanContext.getBean(className);
CommandResultService commandResultService = (CommandResultService) ServiceBeanContext.getBean(className);
CrossInfoPO crossInfo = crossInfoCache.getCrossInfo(key);
String result = bean.protocolConvert(crossInfo);
if (StringUtils.isNotEmpty(result)) {
setResultData(key, result);
String hexResult = commandResultService.getCommandResult(crossInfo);
if (Objects.nonNull(hexResult)) {
setResultData(key, hexResult);
}
}
private void setResultData(String key, String data) {
private void setResultData(String key, String hexResult) {
MessageResultPojo resultPojo = NettyMessageCache.NETTY_MESSAGE_RESULT_MAP.get(key);
if (resultPojo != null) {
resultPojo.setMessageHexStr(data);
resultPojo.setHexMessageResult(hexResult);
resultPojo.getCountDownLatch().countDown();
}
}
......
package net.wanji.com.netty.result;
import net.wanji.databus.po.CrossInfoPO;
/**
* @author duanruiming
* @date 2023/05/10 10:07
*/
public interface CommandResultService {
String getCommandResult(CrossInfoPO crossInfo);
}
......@@ -33,5 +33,5 @@ public class MessageResultPojo {
/**
* netty响应消息16进制字符串
*/
private String messageHexStr;
private String hexMessageResult;
}
......@@ -3,10 +3,10 @@ package net.wanji.com.service;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.wanji.com.mapper.TCrossInfoMapper;
import net.wanji.com.mapper.ManufacturerInfoMapper;
import net.wanji.com.pojo.po.CrossInfoPO;
import net.wanji.com.pojo.po.ManufacturerInfoPO;
import net.wanji.databus.dao.mapper.CrossInfoMapper;
import net.wanji.databus.dao.mapper.ManufacturerInfoMapper;
import net.wanji.databus.po.CrossInfoPO;
import net.wanji.databus.po.ManufacturerInfoPO;
import org.springframework.stereotype.Service;
/**
......@@ -18,7 +18,7 @@ import org.springframework.stereotype.Service;
@RequiredArgsConstructor
public class CommonService {
private final TCrossInfoMapper TCrossInfoMapper;
private final CrossInfoMapper crossInfoMapper;
private final ManufacturerInfoMapper manufacturerInfoMapper;
/**
......@@ -29,7 +29,7 @@ public class CommonService {
*/
@NonNull
public String getManufacturerCodeByCrossId(String crossId) {
CrossInfoPO crossInfoPO = TCrossInfoMapper.selectByPrimaryKey(crossId);
CrossInfoPO crossInfoPO = crossInfoMapper.selectByPrimaryKey(crossId);
Integer manufacturerId = crossInfoPO.getManufacturerId();
ManufacturerInfoPO manufacturerInfoPO = manufacturerInfoMapper.selectById(manufacturerId);
return manufacturerInfoPO.getCode();
......
package net.wanji.com.service.controller;
import net.wanji.com.pojo.po.SignalStatusLogPO;
import net.wanji.com.pojo.vo.LightsStatusVO;
import net.wanji.databus.po.SignalStatusLogPO;
import net.wanji.databus.vo.LightsStatusVO;
import java.util.List;
......
package net.wanji.com.service.controller;
import net.wanji.com.pojo.dto.CrossInfoDTO;
import net.wanji.com.pojo.dto.CrossSchedulesDTO;
import net.wanji.com.pojo.dto.PlanSectionDTO;
import net.wanji.com.pojo.dto.SchemePhaseLightsDTO;
import net.wanji.com.pojo.po.CrossInfoPO;
import net.wanji.com.pojo.po.CrossSchedulesPO;
import net.wanji.com.pojo.vo.PlanSectionVO;
import net.wanji.com.pojo.vo.SchemePhaseLightsVO;
import net.wanji.databus.dao.entity.CrossSchedulesPO;
import net.wanji.databus.dto.CrossInfoDTO;
import net.wanji.databus.dto.CrossSchedulesDTO;
import net.wanji.databus.dto.PlanSectionDTO;
import net.wanji.databus.dto.SchemePhaseLightsDTO;
import net.wanji.databus.po.CrossInfoPO;
import net.wanji.databus.vo.PlanSectionVO;
import net.wanji.databus.vo.SchemePhaseLightsVO;
import java.util.List;
......
package net.wanji.com.service.controller.impl;
import net.wanji.com.pojo.po.SignalStatusLogPO;
import net.wanji.com.pojo.vo.LightsStatusVO;
import net.wanji.com.service.controller.SignalStatusService;
import net.wanji.common.enums.BaseEnum;
import net.wanji.databus.po.SignalStatusLogPO;
import net.wanji.databus.vo.LightsStatusVO;
import org.springframework.stereotype.Service;
import java.util.List;
......
package net.wanji.com.service.controller.impl;
import net.wanji.com.pojo.dto.CrossInfoDTO;
import net.wanji.com.pojo.dto.CrossSchedulesDTO;
import net.wanji.com.pojo.dto.PlanSectionDTO;
import net.wanji.com.pojo.dto.SchemePhaseLightsDTO;
import net.wanji.com.pojo.po.CrossInfoPO;
import net.wanji.com.pojo.po.CrossSchedulesPO;
import net.wanji.com.pojo.vo.PlanSectionVO;
import net.wanji.com.pojo.vo.SchemePhaseLightsVO;
import net.wanji.com.service.controller.StaticInfoService;
import net.wanji.common.enums.BaseEnum;
import net.wanji.databus.dao.entity.CrossSchedulesPO;
import net.wanji.databus.dto.CrossInfoDTO;
import net.wanji.databus.dto.CrossSchedulesDTO;
import net.wanji.databus.dto.PlanSectionDTO;
import net.wanji.databus.dto.SchemePhaseLightsDTO;
import net.wanji.databus.po.CrossInfoPO;
import net.wanji.databus.vo.PlanSectionVO;
import net.wanji.databus.vo.SchemePhaseLightsVO;
import org.springframework.stereotype.Service;
import java.util.List;
......
package net.wanji.com.service.protocol;
import net.wanji.com.pojo.po.CrossInfoPO;
import net.wanji.databus.po.CrossInfoPO;
/**
* @author duanruiming
* @date 2023/05/08 10:25
*/
public interface ProtocolConversionService {
public interface ProtocolConversionService<R, T> {
/**
* 协议解析接口
* 协议解析为实体类
*
* @param crossInfo
* @return
*/
String protocolConvert(CrossInfoPO crossInfo);
R protocolConvertEntity(CrossInfoPO crossInfo);
String entityConvertProtocol(T t);
}
package net.wanji.com.service.protocol.impl;
import net.wanji.com.netty.NettyServer;
import net.wanji.com.service.protocol.ProtocolConversionService;
import net.wanji.databus.po.CrossInfoPO;
/**
* @author duanruiming
* @date 2023/05/09 17:35
*/
public class PhaseServiceImpl implements ProtocolConversionService<Object, Object> {
@Override
public Object protocolConvertEntity(CrossInfoPO crossInfo) {
String hexResult = NettyServer.sendMessage("ip", 80, "aadd", "1122", 300);
return null;
}
@Override
public String entityConvertProtocol(Object o) {
return null;
}
}
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