Commit 6cd45b92 authored by duanruiming's avatar duanruiming

[update] 优化持久层

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