feat(): 测试
parent
d1440fb706
commit
c1c93dcaba
|
@ -0,0 +1,32 @@
|
||||||
|
package com.muyu.enterprise.cache;
|
||||||
|
|
||||||
|
import com.muyu.common.cache.CacheAbsBacis;
|
||||||
|
import com.muyu.domain.resp.MessageValueListResp;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报文模版数据缓存
|
||||||
|
* @Author: LiDongJia
|
||||||
|
* @Package: com.muyu.enterprise.cache
|
||||||
|
* @Project: cloud-server
|
||||||
|
* @name: MessageValueCacheService
|
||||||
|
* @Date: 2024/10/4 10:10
|
||||||
|
* @Description: 报文模版数据缓存
|
||||||
|
*/
|
||||||
|
public class MessageValueCacheService extends CacheAbsBacis<String, List<MessageValueListResp>> {
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String keyPre() {
|
||||||
|
return "messageValue:info:";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String decode(String key) {
|
||||||
|
return key.replace("messageValue:info:", "");
|
||||||
|
}
|
||||||
|
}
|
|
@ -41,7 +41,7 @@ public class VehicleType extends BaseEntity {
|
||||||
* 报文模版外键
|
* 报文模版外键
|
||||||
*/
|
*/
|
||||||
@Schema(type = "Integer",description = "报文模版外键")
|
@Schema(type = "Integer",description = "报文模版外键")
|
||||||
private Integer messageTemplateId;
|
private Long messageTemplateId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加车辆类型
|
* 添加车辆类型
|
||||||
|
|
|
@ -70,12 +70,12 @@ public class VehicleController extends BaseController {
|
||||||
@Operation(summary = "新增车辆", description = "录入车辆信息")
|
@Operation(summary = "新增车辆", description = "录入车辆信息")
|
||||||
public Result<String> save(@RequestBody VehicleAddReq vehicleAddReq) {
|
public Result<String> save(@RequestBody VehicleAddReq vehicleAddReq) {
|
||||||
boolean save = vehicleService.save(Vehicle.addBuild(vehicleAddReq));
|
boolean save = vehicleService.save(Vehicle.addBuild(vehicleAddReq));
|
||||||
//获取用户信息
|
// //获取用户信息
|
||||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
// LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||||
//获取租户唯一标识
|
// //获取租户唯一标识
|
||||||
String databaseName = loginUser.getSysUser().getDatabaseName();
|
// String databaseName = loginUser.getSysUser().getDatabaseName();
|
||||||
//存到redis
|
//存到redis
|
||||||
vehicleCacheService.put(databaseName+vehicleAddReq.getVehicleVin(), Vehicle.addBuild(vehicleAddReq));
|
vehicleCacheService.put(vehicleAddReq.getVehicleVin(), Vehicle.addBuild(vehicleAddReq));
|
||||||
return Result.success(save? "新增成功" : "新增失败");
|
return Result.success(save? "新增成功" : "新增失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,16 +150,4 @@ public class VehicleController extends BaseController {
|
||||||
vehicleService.boundFenceGroup(boundFenceGroupReq);
|
vehicleService.boundFenceGroup(boundFenceGroupReq);
|
||||||
return Result.success("绑定成功");
|
return Result.success("绑定成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过车辆vin码查询模板id
|
|
||||||
* @param vehicleVin
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@GetMapping("/findByVehicleVin/{vehicleVin}")
|
|
||||||
@Operation(description = "通过车辆vin码查询模板id")
|
|
||||||
public Result<Long> findByVehicleVin(@PathVariable("vehicleVin") String vehicleVin) {
|
|
||||||
Long templateId = vehicleService.findByVehicleVin(vehicleVin);
|
|
||||||
return Result.success(templateId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,11 @@ public class VehicleTypeController {
|
||||||
@RequestMapping(path = "/", method = RequestMethod.POST)
|
@RequestMapping(path = "/", method = RequestMethod.POST)
|
||||||
@Operation(summary = "车辆类型列表",description = "车辆类型列表")
|
@Operation(summary = "车辆类型列表",description = "车辆类型列表")
|
||||||
public Result<List<VehicleType>> findAll(){
|
public Result<List<VehicleType>> findAll(){
|
||||||
return Result.success(vehicleTypeService.list());
|
List<VehicleType> list = vehicleTypeService.list();
|
||||||
|
list.forEach(vehicleType -> {
|
||||||
|
vehicleTypeCacheService.put(String.valueOf(vehicleType.getVehicleTypeId()),vehicleType);
|
||||||
|
});
|
||||||
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,12 +61,12 @@ public class VehicleTypeController {
|
||||||
@Operation(summary = "添加报文数据", description = "新增报文数据")
|
@Operation(summary = "添加报文数据", description = "新增报文数据")
|
||||||
public Result<String> save(@RequestBody VehicleType vehicleType) {
|
public Result<String> save(@RequestBody VehicleType vehicleType) {
|
||||||
boolean save = vehicleTypeService.save(vehicleType);
|
boolean save = vehicleTypeService.save(vehicleType);
|
||||||
//获取用户信息
|
// //获取用户信息
|
||||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
// LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||||
//获取租户唯一标识
|
// //获取租户唯一标识
|
||||||
String databaseName = loginUser.getSysUser().getDatabaseName();
|
// String databaseName = loginUser.getSysUser().getDatabaseName();
|
||||||
//存到redis
|
//存到redis
|
||||||
vehicleTypeCacheService.put(databaseName+vehicleType.getVehicleTypeId(),vehicleType);
|
vehicleTypeCacheService.put(String.valueOf(vehicleType.getVehicleTypeId()),vehicleType);
|
||||||
return Result.success(save? "添加成功" : "添加失败");
|
return Result.success(save? "添加成功" : "添加失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,14 +30,6 @@ public interface VehicleMapper extends MPJBaseMapper<Vehicle> {
|
||||||
*/
|
*/
|
||||||
List<VehicleManageResp> findAll(VehicleManageReq vehicleManageReq);
|
List<VehicleManageResp> findAll(VehicleManageReq vehicleManageReq);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据车辆vin查询模版id
|
|
||||||
* @param vehicleVin
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Select("SELECT t.message_template_id FROM vehicle v LEFT JOIN vehicle_type t ON v.vehicle_type_id = t.vehicle_type_id WHERE v.vehicle_vin = #{vehicleVin}")
|
|
||||||
Long findByVehicleVin(String vehicleVin);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 车辆绑定围栏组
|
* 车辆绑定围栏组
|
||||||
* @param boundFenceGroupReq
|
* @param boundFenceGroupReq
|
||||||
|
|
|
@ -26,14 +26,6 @@ public interface VehicleService extends IService<Vehicle> {
|
||||||
*/
|
*/
|
||||||
List<VehicleManageResp> getVehicleList(VehicleManageReq vehicleManageReq);
|
List<VehicleManageResp> getVehicleList(VehicleManageReq vehicleManageReq);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据车辆vin查询模板id
|
|
||||||
* @param vehicleVin
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Long findByVehicleVin(String vehicleVin);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 绑定围栏组
|
* 绑定围栏组
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -59,17 +59,6 @@ public class VehicleServiceImpl
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据车辆vin查询模板id
|
|
||||||
* @param vehicleVin
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Long findByVehicleVin(String vehicleVin) {
|
|
||||||
Long templateId = vehicleMapper.findByVehicleVin(vehicleVin);
|
|
||||||
return templateId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void boundFenceGroup(BoundFenceGroupReq boundFenceGroupReq) {
|
public void boundFenceGroup(BoundFenceGroupReq boundFenceGroupReq) {
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,12 @@
|
||||||
<artifactId>cloud-common-kafka</artifactId>
|
<artifactId>cloud-common-kafka</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-modules-enterprise-cache</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -20,15 +20,6 @@ import java.util.List;
|
||||||
@FeignClient(name = "cloud-car")
|
@FeignClient(name = "cloud-car")
|
||||||
public interface RemoteServiceClient {
|
public interface RemoteServiceClient {
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过车辆vin码查询模板id
|
|
||||||
* @param vehicleVin
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@GetMapping("/vehicleManage/findByVehicleVin/{vehicleVin}")
|
|
||||||
@Operation(description = "通过车辆vin码查询模板id")
|
|
||||||
public Result<Long> findByVehicleVin(@PathVariable("vehicleVin") String vehicleVin);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据报文模版id查询报文数据
|
* 根据报文模版id查询报文数据
|
||||||
* @param templateId
|
* @param templateId
|
||||||
|
|
|
@ -26,11 +26,6 @@ public class RemoteServiceClientFactory implements FallbackFactory<RemoteService
|
||||||
log.error("报文模版传参调用失败:{}", throwable.getMessage());
|
log.error("报文模版传参调用失败:{}", throwable.getMessage());
|
||||||
return new RemoteServiceClient() {
|
return new RemoteServiceClient() {
|
||||||
|
|
||||||
@Override
|
|
||||||
public Result<Long> findByVehicleVin(String vehicleVin) {
|
|
||||||
return Result.success(Long.valueOf(vehicleVin));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<List<MessageValueListResp>> findByTemplateId(Long templateId) {
|
public Result<List<MessageValueListResp>> findByTemplateId(Long templateId) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -4,7 +4,16 @@ import cn.hutool.json.JSONObject;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.muyu.cloud.protocol.parsing.feign.RemoteServiceClient;
|
import com.muyu.cloud.protocol.parsing.feign.RemoteServiceClient;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.common.redis.service.RedisService;
|
||||||
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
|
import com.muyu.common.system.domain.LoginUser;
|
||||||
|
import com.muyu.domain.Vehicle;
|
||||||
|
import com.muyu.domain.VehicleType;
|
||||||
import com.muyu.domain.resp.MessageValueListResp;
|
import com.muyu.domain.resp.MessageValueListResp;
|
||||||
|
import com.muyu.enterprise.cache.MessageTemplateCacheService;
|
||||||
|
import com.muyu.enterprise.cache.MessageValueCacheService;
|
||||||
|
import com.muyu.enterprise.cache.VehicleCacheService;
|
||||||
|
import com.muyu.enterprise.cache.VehicleTypeCacheService;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||||
|
@ -30,7 +39,7 @@ import java.util.List;
|
||||||
public class ParsingTest {
|
public class ParsingTest {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private RedisTemplate<String, Object> redisTemplate;
|
private RedisService redisService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RemoteServiceClient remoteServiceClient;
|
private RemoteServiceClient remoteServiceClient;
|
||||||
|
@ -38,6 +47,15 @@ public class ParsingTest {
|
||||||
@Resource
|
@Resource
|
||||||
private KafkaProducer<String, String> kafkaProducer;
|
private KafkaProducer<String, String> kafkaProducer;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private VehicleTypeCacheService vehicleTypeCacheService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private VehicleCacheService vehicleCacheService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MessageValueCacheService messageValueCacheService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 协议解析
|
* 协议解析
|
||||||
*/
|
*/
|
||||||
|
@ -76,8 +94,8 @@ public class ParsingTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 协议解析
|
* 协议解析
|
||||||
* @param messageStr
|
* @param messageStr 报文数据
|
||||||
* @return
|
* @return 解析后的数据
|
||||||
*/
|
*/
|
||||||
public JSONObject protocolParsing(String messageStr) {
|
public JSONObject protocolParsing(String messageStr) {
|
||||||
//根据空格切割数据
|
//根据空格切割数据
|
||||||
|
@ -91,15 +109,23 @@ public class ParsingTest {
|
||||||
//取出车辆VIN码
|
//取出车辆VIN码
|
||||||
String vehicleVin = result.substring(1, 18);
|
String vehicleVin = result.substring(1, 18);
|
||||||
log.info("车辆VIN码: " + vehicleVin);
|
log.info("车辆VIN码: " + vehicleVin);
|
||||||
|
//获取用户信息
|
||||||
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||||
|
//获取租户唯一标识
|
||||||
|
String databaseName = loginUser.getSysUser().getDatabaseName();
|
||||||
|
//根据车辆VIN码查询车辆信息
|
||||||
|
Vehicle cacheVehicle = vehicleCacheService.get(databaseName + vehicleVin);
|
||||||
|
Long vehicleTypeId = cacheVehicle.getVehicleTypeId();
|
||||||
|
VehicleType cacheVehicleType = vehicleTypeCacheService.get(databaseName + vehicleTypeId);
|
||||||
//根据车辆VIN码查询报文模板ID
|
//根据车辆VIN码查询报文模板ID
|
||||||
Result<Long> byVehicleVin = remoteServiceClient.findByVehicleVin(vehicleVin);
|
Long templateId = cacheVehicleType.getMessageTemplateId();
|
||||||
Long templateId = byVehicleVin.getData();
|
|
||||||
List<MessageValueListResp> templateList;
|
List<MessageValueListResp> templateList;
|
||||||
//从redis缓存中获取报文模板数据
|
//从redis缓存中获取报文模板数据
|
||||||
try {
|
try {
|
||||||
String redisKey = "messageTemplate" + templateId;
|
String redisKey = "messageTemplate" + templateId;
|
||||||
if (redisTemplate.hasKey(redisKey)) {
|
if (redisService.hasKey(redisKey)) {
|
||||||
List<Object> list = redisTemplate.opsForList().range(redisKey, 0, -1);
|
// List<Object> list = redisTemplate.opsForList().range(redisKey, 0, -1);
|
||||||
|
List<MessageValueListResp> list = messageValueCacheService.get(redisKey);
|
||||||
templateList = list.stream()
|
templateList = list.stream()
|
||||||
.map(obj -> JSON.parseObject(obj.toString(), MessageValueListResp.class))
|
.map(obj -> JSON.parseObject(obj.toString(), MessageValueListResp.class))
|
||||||
.toList();
|
.toList();
|
||||||
|
@ -107,12 +133,13 @@ public class ParsingTest {
|
||||||
} else {
|
} else {
|
||||||
Result<List<MessageValueListResp>> byTemplateId = remoteServiceClient.findByTemplateId(templateId);
|
Result<List<MessageValueListResp>> byTemplateId = remoteServiceClient.findByTemplateId(templateId);
|
||||||
templateList = byTemplateId.getData();
|
templateList = byTemplateId.getData();
|
||||||
templateList.forEach(
|
messageValueCacheService.put(redisKey , templateList);
|
||||||
listResp ->
|
// templateList.forEach(
|
||||||
redisTemplate.opsForList().rightPush(
|
// listResp ->
|
||||||
redisKey, JSON.toJSONString(listResp)
|
// redisTemplate.opsForList().rightPush(
|
||||||
)
|
// redisKey, JSON.toJSONString(listResp)
|
||||||
);
|
// )
|
||||||
|
// );
|
||||||
log.info("数据库查询成功");
|
log.info("数据库查询成功");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
Loading…
Reference in New Issue