Merge remote-tracking branch 'origin/dev' into dev
commit
152296d63a
|
@ -0,0 +1,23 @@
|
||||||
|
package com.muyu.enterprise.cache;
|
||||||
|
|
||||||
|
import com.muyu.common.cache.CacheAbsBacis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所有故障缓存服务
|
||||||
|
*/
|
||||||
|
public class AllFaultCacheService extends CacheAbsBacis {
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String keyPre() {
|
||||||
|
return "Allfault:info:";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String decode(String key) {
|
||||||
|
return key.replace("Allfault:info:", "");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.muyu.enterprise.cache;
|
||||||
|
|
||||||
|
import com.muyu.common.cache.CacheAbsBacis;
|
||||||
|
import com.muyu.domain.Fence;
|
||||||
|
import com.muyu.domain.req.FenceReq;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所有电子围栏缓存
|
||||||
|
*/
|
||||||
|
public class AllFenceCahceService extends CacheAbsBacis<String, FenceReq> {
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String keyPre() {
|
||||||
|
return "Allfence:info:";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String decode(String key) {
|
||||||
|
return key.replace("Allfence:info:", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.muyu.enterprise.cache;
|
||||||
|
|
||||||
|
import com.muyu.common.cache.CacheAbsBacis;
|
||||||
|
import com.muyu.domain.resp.MessageValueListResp;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报文模版缓存
|
||||||
|
*/
|
||||||
|
public class AllMessageValueCacheService extends CacheAbsBacis<String, List<MessageValueListResp>> {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String keyPre() {
|
||||||
|
return "allmessagevalue:info:";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String decode(String key) {
|
||||||
|
return key.replace("allmessagevalue:info:", "");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.muyu.enterprise.cache;
|
||||||
|
|
||||||
|
import com.muyu.common.cache.CacheAbsBacis;
|
||||||
|
import com.muyu.domain.Vehicle;
|
||||||
|
import com.muyu.domain.req.VehicleAddReq;
|
||||||
|
import com.muyu.domain.req.VehicleManageReq;
|
||||||
|
import com.muyu.domain.resp.VehicleManageResp;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所有车辆缓存
|
||||||
|
*/
|
||||||
|
public class AllVehicleCacheService extends CacheAbsBacis<String, VehicleManageResp> {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存key前缀
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String keyPre() {
|
||||||
|
return "allvehicle:info:";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String decode(String key) {
|
||||||
|
return key.replace("allvehicle:info:", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.muyu.enterprise.cache;
|
||||||
|
|
||||||
|
import com.muyu.common.cache.CacheAbsBacis;
|
||||||
|
import com.muyu.domain.VehicleType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所有车辆类型缓存
|
||||||
|
*/
|
||||||
|
public class AllVehicleTypeCacheService extends CacheAbsBacis<String, VehicleType> {
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String keyPre() {
|
||||||
|
return "vehicleType:info:";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String decode(String key) {
|
||||||
|
return key.replace("vehicleType:info:", "");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.muyu.enterprise.cache;
|
||||||
|
|
||||||
|
import com.muyu.common.cache.CacheAbsBacis;
|
||||||
|
import com.muyu.domain.MessageValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报文模版缓存
|
||||||
|
*/
|
||||||
|
public class MessageValueCacheService extends CacheAbsBacis<String, MessageValue> {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String keyPre() {
|
||||||
|
return "messagevalue:info:";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String decode(String key) {
|
||||||
|
return key.replace("messagevalue:info:", "");
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ import com.muyu.common.cache.CacheAbsBacis;
|
||||||
import com.muyu.domain.Vehicle;
|
import com.muyu.domain.Vehicle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 车辆缓存
|
* 添加车辆缓存
|
||||||
*/
|
*/
|
||||||
public class VehicleCacheService extends CacheAbsBacis<String, Vehicle> {
|
public class VehicleCacheService extends CacheAbsBacis<String, Vehicle> {
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
com.muyu.enterprise.cache.VehicleCacheService
|
com.muyu.enterprise.cache.AllFaultCacheService
|
||||||
|
com.muyu.enterprise.cache.AllFenceCahceService
|
||||||
|
com.muyu.enterprise.cache.AllMessageValueCacheService
|
||||||
|
com.muyu.enterprise.cache.AllVehicleCacheService
|
||||||
|
com.muyu.enterprise.cache.AllVehicleTypeCacheService
|
||||||
com.muyu.enterprise.cache.FaultCacheService
|
com.muyu.enterprise.cache.FaultCacheService
|
||||||
com.muyu.enterprise.cache.FenceCahceService
|
com.muyu.enterprise.cache.FenceCahceService
|
||||||
|
com.muyu.enterprise.cache.MessageTemplateCacheService
|
||||||
|
com.muyu.enterprise.cache.MessageValueCacheService
|
||||||
|
com.muyu.enterprise.cache.VehicleCacheService
|
||||||
|
com.muyu.enterprise.cache.VehicleTypeCacheService
|
||||||
com.muyu.enterprise.cache.WarnRuleCacheService
|
com.muyu.enterprise.cache.WarnRuleCacheService
|
||||||
com.muyu.enterprise.cache.WarnStrategyCacheService
|
com.muyu.enterprise.cache.WarnStrategyCacheService
|
||||||
com.muyu.enterprise.cache.MessageTemplateCacheService
|
|
||||||
com.muyu.enterprise.cache.VehicleTypeCacheService
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class VehicleType extends BaseEntity {
|
||||||
* 报文模版外键
|
* 报文模版外键
|
||||||
*/
|
*/
|
||||||
@Schema(type = "Integer",description = "报文模版外键")
|
@Schema(type = "Integer",description = "报文模版外键")
|
||||||
private Integer messageTemplateId;
|
private Long messageTemplateId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加车辆类型
|
* 添加车辆类型
|
||||||
|
|
|
@ -28,7 +28,9 @@ import java.security.Security;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电子围栏信息
|
||||||
|
*/
|
||||||
@RequestMapping("/elect")
|
@RequestMapping("/elect")
|
||||||
@RestController
|
@RestController
|
||||||
@Log4j2
|
@Log4j2
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.enterprise.controller;
|
||||||
import com.muyu.common.security.utils.SecurityUtils;
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
import com.muyu.common.system.domain.LoginUser;
|
import com.muyu.common.system.domain.LoginUser;
|
||||||
import com.muyu.domain.req.BoundFenceGroupReq;
|
import com.muyu.domain.req.BoundFenceGroupReq;
|
||||||
|
import com.muyu.enterprise.cache.AllVehicleCacheService;
|
||||||
import com.muyu.enterprise.cache.VehicleCacheService;
|
import com.muyu.enterprise.cache.VehicleCacheService;
|
||||||
import com.muyu.enterprise.service.VehicleService;
|
import com.muyu.enterprise.service.VehicleService;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
@ -20,9 +21,11 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,11 +45,10 @@ public class VehicleController extends BaseController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private VehicleService vehicleService;
|
private VehicleService vehicleService;
|
||||||
|
|
||||||
//车辆缓存
|
//添加车辆缓存
|
||||||
@Autowired
|
@Autowired
|
||||||
private VehicleCacheService vehicleCacheService;
|
private VehicleCacheService vehicleCacheService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询车辆管理列表
|
* 查询车辆管理列表
|
||||||
*
|
*
|
||||||
|
@ -57,6 +59,11 @@ public class VehicleController extends BaseController {
|
||||||
public Result<TableDataInfo<VehicleManageResp>> getVehicleList(@RequestBody VehicleManageReq vehicleManageReq) {
|
public Result<TableDataInfo<VehicleManageResp>> getVehicleList(@RequestBody VehicleManageReq vehicleManageReq) {
|
||||||
startPage();
|
startPage();
|
||||||
List<VehicleManageResp> list = vehicleService.getVehicleList(vehicleManageReq);
|
List<VehicleManageResp> list = vehicleService.getVehicleList(vehicleManageReq);
|
||||||
|
//将车辆信息存到Redis
|
||||||
|
List<Vehicle> vehicleList = vehicleService.list();
|
||||||
|
vehicleList.forEach(vehicle -> {
|
||||||
|
vehicleCacheService.put(vehicle.getVehicleVin(), vehicle);
|
||||||
|
});
|
||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,13 @@ 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(databaseName+vehicleType.getVehicleTypeId(),vehicleType);
|
||||||
|
vehicleTypeCacheService.put(String.valueOf(vehicleType.getVehicleTypeId()),vehicleType);
|
||||||
return Result.success(save? "添加成功" : "添加失败");
|
return Result.success(save? "添加成功" : "添加失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,12 @@ package com.muyu.enterprise.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.muyu.enterprise.mapper.MessageValueMapper;
|
|
||||||
import com.muyu.enterprise.service.MessageValueService;
|
|
||||||
import com.muyu.domain.MessageValue;
|
import com.muyu.domain.MessageValue;
|
||||||
import com.muyu.domain.req.MessageValueReq;
|
import com.muyu.domain.req.MessageValueReq;
|
||||||
import com.muyu.domain.resp.MessageValueListResp;
|
import com.muyu.domain.resp.MessageValueListResp;
|
||||||
|
import com.muyu.enterprise.cache.AllMessageValueCacheService;
|
||||||
|
import com.muyu.enterprise.mapper.MessageValueMapper;
|
||||||
|
import com.muyu.enterprise.service.MessageValueService;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -31,6 +32,9 @@ public class MessageValueServiceImpl
|
||||||
@Autowired
|
@Autowired
|
||||||
private MessageValueMapper messageValueMapper;
|
private MessageValueMapper messageValueMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AllMessageValueCacheService allMessageValueCacheService;
|
||||||
|
|
||||||
public MessageValueServiceImpl(MessageValueMapper messageValueMapper) {
|
public MessageValueServiceImpl(MessageValueMapper messageValueMapper) {
|
||||||
this.messageValueMapper = messageValueMapper;
|
this.messageValueMapper = messageValueMapper;
|
||||||
}
|
}
|
||||||
|
@ -63,11 +67,13 @@ public class MessageValueServiceImpl
|
||||||
LambdaQueryWrapper<MessageValue> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<MessageValue> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(MessageValue::getTemplateId, templateId);
|
queryWrapper.eq(MessageValue::getTemplateId, templateId);
|
||||||
List<MessageValue> list = this.list(queryWrapper);
|
List<MessageValue> list = this.list(queryWrapper);
|
||||||
return list.stream()
|
List<MessageValueListResp> collect = list.stream()
|
||||||
.map(messageValue -> MessageValueListResp.valueBuild(
|
.map(messageValue -> MessageValueListResp.valueBuild(
|
||||||
messageValue
|
messageValue
|
||||||
)
|
)
|
||||||
).collect(Collectors.toList());
|
).collect(Collectors.toList());
|
||||||
|
allMessageValueCacheService.put(String.valueOf(templateId), collect);
|
||||||
|
return collect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import com.muyu.domain.VehicleType;
|
||||||
import com.muyu.domain.req.BoundFenceGroupReq;
|
import com.muyu.domain.req.BoundFenceGroupReq;
|
||||||
import com.muyu.domain.req.VehicleManageReq;
|
import com.muyu.domain.req.VehicleManageReq;
|
||||||
import com.muyu.domain.resp.VehicleManageResp;
|
import com.muyu.domain.resp.VehicleManageResp;
|
||||||
|
import com.muyu.enterprise.cache.AllVehicleCacheService;
|
||||||
import com.muyu.enterprise.mapper.VehicleMapper;
|
import com.muyu.enterprise.mapper.VehicleMapper;
|
||||||
import com.muyu.enterprise.service.VehicleService;
|
import com.muyu.enterprise.service.VehicleService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
package com.muyu.cloud.protocol.parsing.feign;
|
|
||||||
|
|
||||||
import com.muyu.common.core.domain.Result;
|
|
||||||
import com.muyu.domain.resp.MessageValueListResp;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: LiDongJia
|
|
||||||
* @Package: com.muyu.cloud.protocol.parsing.feign
|
|
||||||
* @Project: 2112-car-cloud-server
|
|
||||||
* @name: RemoteServiceClient
|
|
||||||
* @Date: 2024/9/28 14:49
|
|
||||||
* @Description: 远程调用接口
|
|
||||||
*/
|
|
||||||
@FeignClient(name = "cloud-car")
|
|
||||||
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查询报文数据
|
|
||||||
* @param templateId
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@GetMapping("/messageValue/findByTemplateId/{templateId}")
|
|
||||||
@Operation(summary = "根据报文模版id查询报文数据", description = "根据报文模版id查询报文数据")
|
|
||||||
public Result<List<MessageValueListResp>> findByTemplateId(@PathVariable("templateId") Long templateId);
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
package com.muyu.cloud.protocol.parsing.feign.factory;
|
|
||||||
|
|
||||||
import com.muyu.cloud.protocol.parsing.feign.RemoteServiceClient;
|
|
||||||
import com.muyu.common.core.domain.Result;
|
|
||||||
import com.muyu.domain.resp.MessageValueListResp;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 报文模版对象服务降级处理
|
|
||||||
* @Author:李庆帅
|
|
||||||
* @Package:com.muyu.analysis.parsing.remote.factory
|
|
||||||
* @Project:cloud-server
|
|
||||||
* @name:RemoteServiceClientFactory
|
|
||||||
* @Date:2024/9/28 21:16
|
|
||||||
*/
|
|
||||||
public class RemoteServiceClientFactory implements FallbackFactory<RemoteServiceClient>
|
|
||||||
{
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(com.muyu.cloud.protocol.parsing.feign.factory.RemoteServiceClientFactory.class);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RemoteServiceClient create(Throwable throwable) {
|
|
||||||
log.error("报文模版传参调用失败:{}", throwable.getMessage());
|
|
||||||
return new RemoteServiceClient() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Result<Long> findByVehicleVin(String vehicleVin) {
|
|
||||||
return Result.success(Long.valueOf(vehicleVin));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Result<List<MessageValueListResp>> findByTemplateId(Long templateId) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,16 +1,17 @@
|
||||||
package com.muyu.cloud.protocol.parsing.test;
|
package com.muyu.cloud.protocol.parsing.test;
|
||||||
|
|
||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.muyu.domain.Vehicle;
|
||||||
import com.muyu.cloud.protocol.parsing.feign.RemoteServiceClient;
|
import com.muyu.domain.VehicleType;
|
||||||
import com.muyu.common.core.domain.Result;
|
|
||||||
import com.muyu.domain.resp.MessageValueListResp;
|
import com.muyu.domain.resp.MessageValueListResp;
|
||||||
|
import com.muyu.enterprise.cache.AllMessageValueCacheService;
|
||||||
|
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;
|
||||||
import org.eclipse.paho.client.mqttv3.*;
|
import org.eclipse.paho.client.mqttv3.*;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
@ -27,17 +28,20 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@Component
|
@Component
|
||||||
public class ParsingTest {
|
public class ParsingMessage {
|
||||||
|
|
||||||
@Resource
|
|
||||||
private RedisTemplate<String, Object> redisTemplate;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RemoteServiceClient remoteServiceClient;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private KafkaProducer<String, String> kafkaProducer;
|
private KafkaProducer<String, String> kafkaProducer;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private VehicleCacheService vehicleCacheService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private VehicleTypeCacheService vehicleTypeCacheService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AllMessageValueCacheService allMessageValueCacheService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 协议解析
|
* 协议解析
|
||||||
*/
|
*/
|
||||||
|
@ -92,32 +96,34 @@ public class ParsingTest {
|
||||||
String vehicleVin = result.substring(1, 18);
|
String vehicleVin = result.substring(1, 18);
|
||||||
log.info("车辆VIN码: " + vehicleVin);
|
log.info("车辆VIN码: " + vehicleVin);
|
||||||
//根据车辆VIN码查询报文模板ID
|
//根据车辆VIN码查询报文模板ID
|
||||||
Result<Long> byVehicleVin = remoteServiceClient.findByVehicleVin(vehicleVin);
|
Vehicle vehicle = vehicleCacheService.get(vehicleVin);
|
||||||
Long templateId = byVehicleVin.getData();
|
Long vehicleTypeId = vehicle.getVehicleTypeId();
|
||||||
List<MessageValueListResp> templateList;
|
VehicleType vehicleType = vehicleTypeCacheService.get(String.valueOf(vehicleTypeId));
|
||||||
//从redis缓存中获取报文模板数据
|
Long templateId = vehicleType.getMessageTemplateId();
|
||||||
try {
|
List<MessageValueListResp> templateList = allMessageValueCacheService.get(String.valueOf(templateId));
|
||||||
String redisKey = "messageTemplate" + templateId;
|
// //从redis缓存中获取报文模板数据
|
||||||
if (redisTemplate.hasKey(redisKey)) {
|
// try {
|
||||||
List<Object> list = redisTemplate.opsForList().range(redisKey, 0, -1);
|
// String redisKey = "messageTemplate" + templateId;
|
||||||
templateList = list.stream()
|
// if (redisTemplate.hasKey(redisKey)) {
|
||||||
.map(obj -> JSON.parseObject(obj.toString(), MessageValueListResp.class))
|
// List<Object> list = redisTemplate.opsForList().range(redisKey, 0, -1);
|
||||||
.toList();
|
// templateList = list.stream()
|
||||||
log.info("Redis缓存查询成功");
|
// .map(obj -> JSON.parseObject(obj.toString(), MessageValueListResp.class))
|
||||||
} else {
|
// .toList();
|
||||||
Result<List<MessageValueListResp>> byTemplateId = remoteServiceClient.findByTemplateId(templateId);
|
// log.info("Redis缓存查询成功");
|
||||||
templateList = byTemplateId.getData();
|
// } else {
|
||||||
templateList.forEach(
|
// Result<List<MessageValueListResp>> byTemplateId = remoteServiceClient.findByTemplateId(templateId);
|
||||||
listResp ->
|
// templateList = byTemplateId.getData();
|
||||||
redisTemplate.opsForList().rightPush(
|
// templateList.forEach(
|
||||||
redisKey, JSON.toJSONString(listResp)
|
// listResp ->
|
||||||
)
|
// redisTemplate.opsForList().rightPush(
|
||||||
);
|
// redisKey, JSON.toJSONString(listResp)
|
||||||
log.info("数据库查询成功");
|
// )
|
||||||
}
|
// );
|
||||||
} catch (Exception e) {
|
// log.info("数据库查询成功");
|
||||||
throw new RuntimeException("获取报文模板失败");
|
// }
|
||||||
}
|
// } catch (Exception e) {
|
||||||
|
// throw new RuntimeException("获取报文模板失败");
|
||||||
|
// }
|
||||||
//判断报文模板列表不为空
|
//判断报文模板列表不为空
|
||||||
if (templateList.isEmpty()) {
|
if (templateList.isEmpty()) {
|
||||||
throw new RuntimeException("报文模版为空");
|
throw new RuntimeException("报文模版为空");
|
Loading…
Reference in New Issue