feat():提交合并之后代码
commit
2bd123b42c
|
@ -12,7 +12,7 @@
|
||||||
<artifactId>cloud-common-cache</artifactId>
|
<artifactId>cloud-common-cache</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
cloud-common-cache redis缓存架构
|
cloud-common-cache 缓存基准模块
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
|
@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
|
||||||
public abstract class CacheAbsBasic<K,V> implements CacheBasic<K,V> {
|
public abstract class CacheAbsBasic<K,V> implements CacheBasic<K,V> {
|
||||||
|
@ -21,16 +22,44 @@ public abstract class CacheAbsBasic<K,V> implements CacheBasic<K,V> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void put(K key, V value) {
|
public void put(K key, V value) {
|
||||||
redisService.setCacheObject(encode(key),value);
|
|
||||||
|
try {
|
||||||
|
redisService.setCacheObject(encode(key), value,30L, TimeUnit.MINUTES);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("运行时异常,异常信息为:{}"+e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public V get(K key) {
|
public V get(K key) {
|
||||||
|
|
||||||
|
try {
|
||||||
return redisService.getCacheObject(encode(key));
|
return redisService.getCacheObject(encode(key));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("运行时异常,异常信息为:{}"+e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove(K key) {
|
public void remove(K key) {
|
||||||
|
|
||||||
|
try {
|
||||||
redisService.deleteObject(encode(key));
|
redisService.deleteObject(encode(key));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("运行时异常,异常信息为:{}"+e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hashKey(K key){
|
||||||
|
Boolean b = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
b = redisService.hasKey(encode(key));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("运行时异常,异常信息为:{}"+e.getMessage());
|
||||||
|
}
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -18,5 +18,6 @@ public interface CacheBasic<K,V> extends PrimaryKeyBasic<K>{
|
||||||
|
|
||||||
void remove(K key);
|
void remove(K key);
|
||||||
|
|
||||||
|
boolean hashKey(K key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,26 +9,28 @@ package com.muyu.common.cache.config;
|
||||||
*/
|
*/
|
||||||
public interface PrimaryKeyBasic <K>{
|
public interface PrimaryKeyBasic <K>{
|
||||||
/**
|
/**
|
||||||
* key 前缀
|
* 主键前缀
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public String keyPre();
|
public String keyPre();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编码
|
* 主键编码
|
||||||
* @param key 缓存键
|
* @param key 缓存建
|
||||||
* @return 装修键
|
* @return 装修建
|
||||||
*/
|
*/
|
||||||
public default String encode(K key){
|
public default String encode(K key){
|
||||||
return keyPre() + key.toString();
|
return keyPre() + key.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解码 Key
|
* 主键解码
|
||||||
* @param key 解码后的key
|
* @param key 缓存建
|
||||||
* @return
|
* @return 装修建
|
||||||
*/
|
*/
|
||||||
public K decode(String key);
|
public default K decode(String key) {
|
||||||
|
return (K) key.substring(keyPre().length());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,17 +18,16 @@
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
cloud-modules-enterprise-cache redis 缓存平台
|
cloud-modules-enterprise-cache redis 缓存基准服务
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- cache缓存基准模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-cache</artifactId>
|
<artifactId>cloud-common-cache</artifactId>
|
||||||
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- 企业业务平台服务 - 公共依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-modules-enterprise-common</artifactId>
|
<artifactId>cloud-modules-enterprise-common</artifactId>
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.muyu.enterprise.cache;
|
||||||
|
|
||||||
|
import com.muyu.common.cache.config.CacheAbsBasic;
|
||||||
|
import com.muyu.enterprise.domain.CarCompany;
|
||||||
|
import com.muyu.enterprise.domain.CarTemplate;
|
||||||
|
import com.muyu.enterprise.domain.car.MessageValue;
|
||||||
|
import com.muyu.enterprise.domain.resp.car.MessageValueListResp;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报文类型缓存---实现类
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @ClassName CarTemplateCacheService
|
||||||
|
* @Description CarTemplateCacheService:类的描述
|
||||||
|
* @Date 2024/10/3 15:22
|
||||||
|
* @author MingWei.Zong
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class CarMessageValueCacheService extends CacheAbsBasic<String,List<MessageValueListResp>> {
|
||||||
|
/**
|
||||||
|
* 前缀
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String keyPre()
|
||||||
|
{
|
||||||
|
return "messageValue:info";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String encode(String key)
|
||||||
|
{
|
||||||
|
return super.encode(key);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String decode(String key)
|
||||||
|
{
|
||||||
|
return key.replace("messageValue:info:","");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.muyu.enterprise.cache;
|
||||||
|
|
||||||
|
import com.muyu.common.cache.config.CacheAbsBasic;
|
||||||
|
import com.muyu.enterprise.domain.car.Vehicle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆管理---实现类
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @ClassName CarMessageCacheService
|
||||||
|
* @Description CarMessageCacheService:类的描述
|
||||||
|
* @Date 2024/9/30 11:42
|
||||||
|
* @author MingWei.Zong
|
||||||
|
*/
|
||||||
|
public class CarVehicleCacheService extends CacheAbsBasic<String, Vehicle> {
|
||||||
|
@Override
|
||||||
|
public String keyPre(){
|
||||||
|
return "sysCar:info";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String encode(String key){
|
||||||
|
return super.encode(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String decode(String key){
|
||||||
|
return super.decode(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.muyu.enterprise.cache;
|
||||||
|
|
||||||
|
import com.muyu.common.cache.config.CacheAbsBasic;
|
||||||
|
import com.muyu.enterprise.domain.CarManage;
|
||||||
|
import com.muyu.enterprise.domain.car.VehicleType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆类型的缓存---实现类
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @ClassName CarManageCacheService
|
||||||
|
* @Description CarManageCacheService:类的描述
|
||||||
|
* @Date 2024/10/3 15:22
|
||||||
|
* @author MingWei.Zong
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class CarVehicleTypeCacheService extends CacheAbsBasic<String, VehicleType> {
|
||||||
|
@Override
|
||||||
|
public String keyPre()
|
||||||
|
{
|
||||||
|
return "sysCarType:info";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String encode(String key)
|
||||||
|
{
|
||||||
|
return super.encode(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String decode(String key)
|
||||||
|
{
|
||||||
|
return super.decode(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
com.muyu.enterprise.cache.CarCompanyCacheService
|
com.muyu.enterprise.cache.CarCompanyCacheService
|
||||||
com.muyu.enterprise.cache.CarFaultCacheService
|
com.muyu.enterprise.cache.CarFaultCacheService
|
||||||
com.muyu.enterprise.cache.CarManageCacheService
|
com.muyu.enterprise.cache.CarVehicleTypeCacheService
|
||||||
com.muyu.enterprise.cache.CarMessageCacheService
|
com.muyu.enterprise.cache.CarVehicleCacheService
|
||||||
com.muyu.enterprise.cache.CarTemplateCacheService
|
com.muyu.enterprise.cache.CarMessageValueCacheService
|
||||||
com.muyu.enterprise.cache.CarWarnCacheService
|
com.muyu.enterprise.cache.CarWarnCacheService
|
||||||
com.muyu.enterprise.cache.ElectronicFenceCacheService
|
com.muyu.enterprise.cache.ElectronicFenceCacheService
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 报文数据服务
|
* 报文数据服务
|
||||||
|
*
|
||||||
* @Author:李庆帅
|
* @Author:李庆帅
|
||||||
* @Package:com.muyu.analysis.parsing.feign
|
* @Package:com.muyu.analysis.parsing.feign
|
||||||
* @Project:cloud-server
|
* @Project:cloud-server
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
com.muyu.enterprise.remote.factory.RemoteVehicleServiceFactory
|
|
||||||
com.muyu.enterprise.remote.factory.RemoteMessageValueServiceFactory
|
com.muyu.enterprise.remote.factory.RemoteMessageValueServiceFactory
|
||||||
|
com.muyu.enterprise.remote.factory.RemoteVehicleServiceFactory
|
||||||
|
|
|
@ -3,9 +3,10 @@ package com.muyu.enterprise.controller;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
import com.muyu.common.core.utils.StringUtils;
|
import com.muyu.common.core.utils.StringUtils;
|
||||||
import com.muyu.enterprise.cache.CarManageCacheService;
|
import com.muyu.common.core.utils.poi.ExcelUtil;
|
||||||
import com.muyu.enterprise.domain.CarManage;
|
import com.muyu.enterprise.domain.CarManage;
|
||||||
import com.muyu.enterprise.domain.CarMessage;
|
import com.muyu.enterprise.domain.CarMessage;
|
||||||
|
import com.muyu.enterprise.domain.car.Vehicle;
|
||||||
import com.muyu.enterprise.domain.dto.CarDTO;
|
import com.muyu.enterprise.domain.dto.CarDTO;
|
||||||
import com.muyu.enterprise.domain.vo.CarVO;
|
import com.muyu.enterprise.domain.vo.CarVO;
|
||||||
import com.muyu.enterprise.service.CarCompanyService;
|
import com.muyu.enterprise.service.CarCompanyService;
|
||||||
|
@ -16,6 +17,7 @@ import com.muyu.common.core.web.page.TableDataInfo;
|
||||||
import com.muyu.common.security.utils.SecurityUtils;
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
@ -36,7 +38,6 @@ import java.util.List;
|
||||||
@Tag(name = "CarManageController", description = "车辆管理")
|
@Tag(name = "CarManageController", description = "车辆管理")
|
||||||
public class CarManageController extends BaseController {
|
public class CarManageController extends BaseController {
|
||||||
|
|
||||||
private final CarManageCacheService carManageCacheService;
|
|
||||||
|
|
||||||
private final CarCompanyService sysCarCompanyService;
|
private final CarCompanyService sysCarCompanyService;
|
||||||
|
|
||||||
|
@ -128,6 +129,27 @@ public class CarManageController extends BaseController {
|
||||||
carManageService.removeBatchByIds(ids);
|
carManageService.removeBatchByIds(ids);
|
||||||
return Result.success("车辆删除成功");
|
return Result.success("车辆删除成功");
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 导出所有车辆数据
|
||||||
|
* @param response 请求对象
|
||||||
|
*/
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(HttpServletResponse response) {
|
||||||
|
List<CarManage> list = carManageService.list();
|
||||||
|
ExcelUtil<CarManage> util = new ExcelUtil<>(CarManage.class);
|
||||||
|
util.exportExcel(response, list, "车辆数据");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 通过车辆vin码查询模板id
|
||||||
|
* @param carManageVin 请求对象
|
||||||
|
* @return 返回结果
|
||||||
|
*/
|
||||||
|
@GetMapping("/findByCarManageVin/{carManageVin}")
|
||||||
|
@Operation(description = "通过车辆vin码查询模板id")
|
||||||
|
public Result<Long> findByCarManageVin(@PathVariable("vehicleVin") String carManageVin) {
|
||||||
|
Long byCarManageVin = carManageService.findByCarManageVin(carManageVin);
|
||||||
|
return Result.success(byCarManageVin);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,10 @@ package com.muyu.enterprise.controller;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.web.controller.BaseController;
|
import com.muyu.common.core.web.controller.BaseController;
|
||||||
import com.muyu.enterprise.cache.CarManageCacheService;
|
import com.muyu.enterprise.cache.CarVehicleTypeCacheService;
|
||||||
import com.muyu.enterprise.cache.CarMessageCacheService;
|
import com.muyu.enterprise.cache.CarVehicleCacheService;
|
||||||
import com.muyu.enterprise.domain.CarMessage;
|
import com.muyu.enterprise.domain.CarMessage;
|
||||||
|
import com.muyu.enterprise.domain.car.Vehicle;
|
||||||
import com.muyu.enterprise.service.CarMessageService;
|
import com.muyu.enterprise.service.CarMessageService;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
@ -28,7 +29,7 @@ import java.util.List;
|
||||||
@Tag(name = "报文",description = "报文模块")
|
@Tag(name = "报文",description = "报文模块")
|
||||||
public class CarMessageController extends BaseController {
|
public class CarMessageController extends BaseController {
|
||||||
|
|
||||||
private final CarMessageCacheService carMessageCacheService;
|
private final CarVehicleCacheService carMessageCacheService;
|
||||||
private final CarMessageService sysCarMessageService;
|
private final CarMessageService sysCarMessageService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private CarMessageService carMessageService;
|
private CarMessageService carMessageService;
|
||||||
|
@ -70,7 +71,7 @@ public class CarMessageController extends BaseController {
|
||||||
public Result insertMessage(@RequestBody CarMessage carMessage){
|
public Result insertMessage(@RequestBody CarMessage carMessage){
|
||||||
sysCarMessageService.save(carMessage);
|
sysCarMessageService.save(carMessage);
|
||||||
//报文 redis
|
//报文 redis
|
||||||
carMessageCacheService.put(carMessage.getMessageType(),new CarMessage());
|
carMessageCacheService.put(carMessage.getMessageType(),new Vehicle());
|
||||||
return Result.success("添加成功");
|
return Result.success("添加成功");
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,6 +4,7 @@ package com.muyu.enterprise.controller.car;
|
||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.web.controller.BaseController;
|
import com.muyu.common.core.web.controller.BaseController;
|
||||||
|
import com.muyu.enterprise.cache.CarMessageValueCacheService;
|
||||||
import com.muyu.enterprise.domain.car.MessageValue;
|
import com.muyu.enterprise.domain.car.MessageValue;
|
||||||
import com.muyu.enterprise.domain.req.car.MessageValueAddReq;
|
import com.muyu.enterprise.domain.req.car.MessageValueAddReq;
|
||||||
import com.muyu.enterprise.domain.req.car.MessageValueReq;
|
import com.muyu.enterprise.domain.req.car.MessageValueReq;
|
||||||
|
@ -37,18 +38,22 @@ public class MessageValueController extends BaseController
|
||||||
@Autowired
|
@Autowired
|
||||||
private MessageValueService messageValueService;
|
private MessageValueService messageValueService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CarMessageValueCacheService carMessageValueCacheService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 报文数据列表查询
|
* 报文数据条件查询
|
||||||
* @param messageValueReq 请求对象
|
* @param messageValueReq 请求对象
|
||||||
* @return 返回结果
|
* @return 返回结果
|
||||||
*/
|
*/
|
||||||
@RequestMapping(value = "/list", method = RequestMethod.POST)
|
@RequestMapping(value = "/list", method = RequestMethod.POST)
|
||||||
@Operation(summary = "报文数据列表", description = "根据报文类别, 报文模版筛选报文数据")
|
@Operation(summary = "报文数据条件查询", description = "根据报文类别, 报文模版筛选报文数据")
|
||||||
public Result<List<MessageValueListResp>> findAll(@RequestBody MessageValueReq messageValueReq) {
|
public Result<List<MessageValueListResp>> findAll(@RequestBody MessageValueReq messageValueReq) {
|
||||||
List<MessageValueListResp> list = messageValueService.findAll(messageValueReq);
|
List<MessageValueListResp> list = messageValueService.findAll(messageValueReq);
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提供预警和故障使用
|
* 提供预警和故障使用
|
||||||
* @return 返回结果
|
* @return 返回结果
|
||||||
|
@ -111,6 +116,11 @@ public class MessageValueController extends BaseController
|
||||||
@Operation(summary = "根据报文模版id查询报文数据", description = "根据报文模版id查询报文数据")
|
@Operation(summary = "根据报文模版id查询报文数据", description = "根据报文模版id查询报文数据")
|
||||||
public Result<List<MessageValueListResp>> findByTemplateId(@PathVariable("templateId") Long templateId){
|
public Result<List<MessageValueListResp>> findByTemplateId(@PathVariable("templateId") Long templateId){
|
||||||
List<MessageValueListResp> list = messageValueService.findByTemplateId(templateId);
|
List<MessageValueListResp> list = messageValueService.findByTemplateId(templateId);
|
||||||
|
//存入缓存中com.muyu.enterprise.cache.CarMessageValueCacheService
|
||||||
|
carMessageValueCacheService.put(
|
||||||
|
String.valueOf(
|
||||||
|
templateId
|
||||||
|
), list);
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import com.muyu.common.core.utils.poi.ExcelUtil;
|
||||||
import com.muyu.common.core.web.controller.BaseController;
|
import com.muyu.common.core.web.controller.BaseController;
|
||||||
import com.muyu.common.core.web.page.TableDataInfo;
|
import com.muyu.common.core.web.page.TableDataInfo;
|
||||||
import com.muyu.common.log.annotation.Log;
|
import com.muyu.common.log.annotation.Log;
|
||||||
|
import com.muyu.enterprise.cache.CarVehicleCacheService;
|
||||||
import com.muyu.enterprise.domain.car.Vehicle;
|
import com.muyu.enterprise.domain.car.Vehicle;
|
||||||
import com.muyu.enterprise.domain.req.car.VehicleAddReq;
|
import com.muyu.enterprise.domain.req.car.VehicleAddReq;
|
||||||
import com.muyu.enterprise.domain.req.car.VehicleManageReq;
|
import com.muyu.enterprise.domain.req.car.VehicleManageReq;
|
||||||
|
@ -41,6 +42,9 @@ public class VehicleController extends BaseController
|
||||||
@Autowired
|
@Autowired
|
||||||
private VehicleService vehicleService;
|
private VehicleService vehicleService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CarVehicleCacheService carVehicleCacheService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询车辆管理列表
|
* 查询车辆管理列表
|
||||||
* @param vehicleManageReq 请求对象
|
* @param vehicleManageReq 请求对象
|
||||||
|
@ -74,7 +78,10 @@ public class VehicleController extends BaseController
|
||||||
@GetMapping("/{vehicleId}")
|
@GetMapping("/{vehicleId}")
|
||||||
@Operation(summary = "通过id查询车辆信息", description = "通过id查询车辆信息")
|
@Operation(summary = "通过id查询车辆信息", description = "通过id查询车辆信息")
|
||||||
public Result<Vehicle> findById(@PathVariable("vehicleId") Long vehicleId) {
|
public Result<Vehicle> findById(@PathVariable("vehicleId") Long vehicleId) {
|
||||||
return Result.success(vehicleService.getById(vehicleId));
|
Vehicle byId = vehicleService.getById(vehicleId);
|
||||||
|
//存入缓存中com.muyu.enterprise.cache.carVehicleCacheService
|
||||||
|
carVehicleCacheService.put(String.valueOf(byId.getVehicleVin()), byId);
|
||||||
|
return Result.success(byId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.enterprise.controller.car;
|
||||||
|
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.web.controller.BaseController;
|
import com.muyu.common.core.web.controller.BaseController;
|
||||||
|
import com.muyu.enterprise.cache.CarVehicleTypeCacheService;
|
||||||
import com.muyu.enterprise.domain.car.VehicleType;
|
import com.muyu.enterprise.domain.car.VehicleType;
|
||||||
import com.muyu.enterprise.service.car.VehicleTypeService;
|
import com.muyu.enterprise.service.car.VehicleTypeService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
@ -33,14 +34,22 @@ public class VehicleTypeController extends BaseController
|
||||||
@Autowired
|
@Autowired
|
||||||
private VehicleTypeService vehicleTypeService;
|
private VehicleTypeService vehicleTypeService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CarVehicleTypeCacheService carVehicleTypeCacheService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 车辆类型查询
|
* 车辆类型查询
|
||||||
* @return 返回结果
|
* @return 返回结果
|
||||||
*/
|
*/
|
||||||
@RequestMapping(path = "/", method = RequestMethod.POST)
|
@RequestMapping(value = "/findAll", 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();
|
||||||
|
for (VehicleType vehicleType : list) {
|
||||||
|
//存入缓存中com.muyu.enterprise.cache.CarVehicleTypeCacheService
|
||||||
|
carVehicleTypeCacheService.put(String.valueOf(vehicleType.getVehicleTypeId()),vehicleType);
|
||||||
|
}
|
||||||
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import com.muyu.enterprise.domain.dto.CarDTO;
|
||||||
import com.muyu.enterprise.domain.vo.CarVO;
|
import com.muyu.enterprise.domain.vo.CarVO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -21,5 +22,11 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface CarManageMapper extends MPJBaseMapper<CarManage> {
|
public interface CarManageMapper extends MPJBaseMapper<CarManage> {
|
||||||
|
/**
|
||||||
|
* 通过车辆vin码查询模板id
|
||||||
|
* @param carManageVin 请求对象
|
||||||
|
* @return 返回结果
|
||||||
|
*/
|
||||||
|
@Select("SELECT t.template_id FROM car_manage v LEFT JOIN car_type t ON v.car_type_id = t.car_type_id WHERE v.car_vin = #{carManageVin}")
|
||||||
|
Long findByCarManageVin(String carManageVin);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,14 @@ public interface CarManageService extends IService<CarManage> {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void insertCar(CarManage carVO);
|
void insertCar(CarManage carVO);
|
||||||
|
/**
|
||||||
|
* 通过车辆vin码查询模板id
|
||||||
|
* @param carManageVin 请求对象
|
||||||
|
* @return 返回结果
|
||||||
|
*/
|
||||||
|
Long findByCarManageVin(String carManageVin);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过 carTypeId 查询车辆信息
|
* 通过 carTypeId 查询车辆信息
|
||||||
|
|
|
@ -9,15 +9,18 @@ import com.muyu.enterprise.cache.CarManageCacheService;
|
||||||
import com.muyu.enterprise.domain.CarCompany;
|
import com.muyu.enterprise.domain.CarCompany;
|
||||||
import com.muyu.enterprise.domain.CarConfig;
|
import com.muyu.enterprise.domain.CarConfig;
|
||||||
import com.muyu.enterprise.domain.CarManage;
|
import com.muyu.enterprise.domain.CarManage;
|
||||||
|
import com.muyu.enterprise.domain.car.Vehicle;
|
||||||
import com.muyu.enterprise.domain.dto.CarDTO;
|
import com.muyu.enterprise.domain.dto.CarDTO;
|
||||||
import com.muyu.enterprise.domain.vo.CarVO;
|
import com.muyu.enterprise.domain.vo.CarVO;
|
||||||
import com.muyu.enterprise.mapper.CarManageMapper;
|
import com.muyu.enterprise.mapper.CarManageMapper;
|
||||||
import com.muyu.enterprise.service.CarCompanyService;
|
import com.muyu.enterprise.service.CarCompanyService;
|
||||||
import com.muyu.enterprise.service.CarConfigService;
|
import com.muyu.enterprise.service.CarConfigService;
|
||||||
import com.muyu.enterprise.service.CarManageService;
|
import com.muyu.enterprise.service.CarManageService;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -38,7 +41,7 @@ public class CarManageServiceImpl extends ServiceImpl<CarManageMapper, CarManage
|
||||||
private CarConfigService carConfigService;
|
private CarConfigService carConfigService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private CarManageCacheService carManageCacheService;
|
private CarManageCacheService carManageCacheService;
|
||||||
@Autowired
|
@Resource
|
||||||
private RemoteEntService remoteEntService;
|
private RemoteEntService remoteEntService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private CarManageMapper carManageMapper;
|
private CarManageMapper carManageMapper;
|
||||||
|
@ -128,6 +131,15 @@ public class CarManageServiceImpl extends ServiceImpl<CarManageMapper, CarManage
|
||||||
public CarManage carManageShowByCarId(Long carId) {
|
public CarManage carManageShowByCarId(Long carId) {
|
||||||
return getById(carId);
|
return getById(carId);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 通过车辆vin码查询模板id
|
||||||
|
* @param carManageVin 请求对象
|
||||||
|
* @return 返回结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Long findByCarManageVin(String carManageVin) {
|
||||||
|
Long templateId = carManageMapper.findByCarManageVin(carManageVin);
|
||||||
|
return templateId;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,13 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 报文类型业务实现层
|
||||||
* @Author:李庆帅
|
* @Author:李庆帅
|
||||||
* @Package:com.muyu.car.service.impl
|
* @Package:com.muyu.car.service.impl
|
||||||
* @Project:cloud-server
|
* @Project:cloud-server
|
||||||
* @name:MessageTemplateServiceImpl
|
* @name:MessageTemplateServiceImpl
|
||||||
* @Date:2024/9/26 22:31
|
* @Date:2024/9/26 22:31
|
||||||
* @Description: 报文类型业务层
|
* @Description:
|
||||||
*/
|
*/
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@Service
|
@Service
|
||||||
|
|
|
@ -5,6 +5,7 @@ import cn.hutool.json.JSONObject;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
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.cache.CarMessageValueCacheService;
|
||||||
import com.muyu.enterprise.domain.car.MessageValue;
|
import com.muyu.enterprise.domain.car.MessageValue;
|
||||||
import com.muyu.enterprise.domain.req.car.MessageValueReq;
|
import com.muyu.enterprise.domain.req.car.MessageValueReq;
|
||||||
import com.muyu.enterprise.domain.resp.car.MessageValueListResp;
|
import com.muyu.enterprise.domain.resp.car.MessageValueListResp;
|
||||||
|
@ -22,6 +23,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 报文数据业务实现层
|
||||||
* @Author:李庆帅
|
* @Author:李庆帅
|
||||||
* @Package:com.muyu.car.service.impl
|
* @Package:com.muyu.car.service.impl
|
||||||
* @Project:cloud-server
|
* @Project:cloud-server
|
||||||
|
@ -45,6 +47,8 @@ extends ServiceImpl<MessageValueMapper,
|
||||||
*/
|
*/
|
||||||
@Resource
|
@Resource
|
||||||
private RedisTemplate<String, Object> redisTemplate;
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
@Autowired
|
||||||
|
private CarMessageValueCacheService carMessageValueCacheService;
|
||||||
|
|
||||||
|
|
||||||
public MessageValueServiceImpl(MessageValueMapper messageValueMapper) {
|
public MessageValueServiceImpl(MessageValueMapper messageValueMapper) {
|
||||||
|
|
|
@ -16,12 +16,13 @@ import org.springframework.stereotype.Service;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 车辆管理业务实现层
|
||||||
* @Author:李庆帅
|
* @Author:李庆帅
|
||||||
* @Package:com.muyu.car.service.impl
|
* @Package:com.muyu.car.service.impl
|
||||||
* @Project:cloud-server
|
* @Project:cloud-server
|
||||||
* @name:VehicleServiceImpl
|
* @name:VehicleServiceImpl
|
||||||
* @Date:2024/9/26 22:35
|
* @Date:2024/9/26 22:35
|
||||||
* @Description: 车辆管理业务层
|
* @Description:
|
||||||
*/
|
*/
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@Service
|
@Service
|
||||||
|
|
|
@ -8,12 +8,13 @@ import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 车辆类型业务实现层
|
||||||
* @Author:李庆帅
|
* @Author:李庆帅
|
||||||
* @Package:com.muyu.car.service.impl
|
* @Package:com.muyu.car.service.impl
|
||||||
* @Project:cloud-server
|
* @Project:cloud-server
|
||||||
* @name:VehicleTypeServiceImpl
|
* @name:VehicleTypeServiceImpl
|
||||||
* @Date:2024/9/26 22:36
|
* @Date:2024/9/26 22:36
|
||||||
* @Description: 车辆类型实现层
|
* @Description:
|
||||||
*/
|
*/
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@Service
|
@Service
|
||||||
|
|
|
@ -5,4 +5,5 @@
|
||||||
<mapper namespace="com.muyu.enterprise.mapper.CarManageMapper">
|
<mapper namespace="com.muyu.enterprise.mapper.CarManageMapper">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.muyu.event.process.consumer;
|
package com.muyu.event.process.consumer;
|
||||||
|
|
||||||
import com.muyu.enterprise.cache.CarFaultCacheService;
|
import com.muyu.enterprise.cache.CarFaultCacheService;
|
||||||
import com.muyu.enterprise.cache.CarManageCacheService;
|
import com.muyu.enterprise.cache.CarVehicleTypeCacheService;
|
||||||
import com.muyu.enterprise.cache.CarWarnCacheService;
|
import com.muyu.enterprise.cache.CarWarnCacheService;
|
||||||
import com.muyu.enterprise.cache.ElectronicFenceCacheService;
|
import com.muyu.enterprise.cache.ElectronicFenceCacheService;
|
||||||
import com.muyu.event.process.constant.CacheHandlerConstants;
|
import com.muyu.event.process.constant.CacheHandlerConstants;
|
||||||
|
@ -35,7 +35,7 @@ public class GoOnlineConsumer {
|
||||||
/**
|
/**
|
||||||
* 车辆管理缓存服务
|
* 车辆管理缓存服务
|
||||||
*/
|
*/
|
||||||
private final CarManageCacheService carManageCacheService;
|
private final CarVehicleTypeCacheService carManageCacheService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 车辆故障缓存服务
|
* 车辆故障缓存服务
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
|
||||||
<!-- SpringCloud Alibaba Nacos -->
|
<!-- SpringCloud Alibaba Nacos -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
@ -89,41 +87,56 @@
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-modules-enterprise-common</artifactId>
|
<artifactId>cloud-modules-enterprise-common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- mybatis-plus-join依赖 -->
|
<!-- mybatis-plus-join依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.yulichang</groupId>
|
<groupId>com.github.yulichang</groupId>
|
||||||
<artifactId>mybatis-plus-join</artifactId>
|
<artifactId>mybatis-plus-join</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 核心模块 - 公共依赖 -->
|
<!-- 核心模块 - 公共依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-core</artifactId>
|
<artifactId>cloud-common-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- kafka依赖 - 公共依赖 -->
|
<!-- kafka依赖 - 公共依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-kafka</artifactId>
|
<artifactId>cloud-common-kafka</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- mqtt消息队列遥测传输协议服务 -->
|
<!-- mqtt消息队列遥测传输协议服务 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-mqtt</artifactId>
|
<artifactId>cloud-common-mqtt</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Spring Boot的缓存启动器 -->
|
<!-- Spring Boot的缓存启动器 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-cache</artifactId>
|
<artifactId>spring-boot-starter-cache</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 高性能的Java缓存库缓存解决方案 -->
|
<!-- 高性能的Java缓存库缓存解决方案 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||||
<artifactId>caffeine</artifactId>
|
<artifactId>caffeine</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 企业远程模块 -->
|
<!-- 企业远程模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-modules-enterprise-remote</artifactId>
|
<artifactId>cloud-modules-enterprise-remote</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 缓存基准服务 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-modules-enterprise-cache</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 协议解析启动类
|
* 协议解析启动类
|
||||||
|
|
|
@ -4,6 +4,11 @@ import com.muyu.common.core.constant.KafkaConstants;
|
||||||
import com.muyu.common.core.constant.RedisConstants;
|
import com.muyu.common.core.constant.RedisConstants;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.mqtt.MQTTConnect;
|
import com.muyu.common.mqtt.MQTTConnect;
|
||||||
|
import com.muyu.enterprise.cache.CarMessageValueCacheService;
|
||||||
|
import com.muyu.enterprise.cache.CarVehicleCacheService;
|
||||||
|
import com.muyu.enterprise.cache.CarVehicleTypeCacheService;
|
||||||
|
import com.muyu.enterprise.domain.car.Vehicle;
|
||||||
|
import com.muyu.enterprise.domain.car.VehicleType;
|
||||||
import com.muyu.enterprise.domain.resp.car.MessageValueListResp;
|
import com.muyu.enterprise.domain.resp.car.MessageValueListResp;
|
||||||
import com.muyu.enterprise.remote.RemoteMessageValueService;
|
import com.muyu.enterprise.remote.RemoteMessageValueService;
|
||||||
import com.muyu.enterprise.remote.RemoteVehicleService;
|
import com.muyu.enterprise.remote.RemoteVehicleService;
|
||||||
|
@ -15,7 +20,6 @@ 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.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@ -33,6 +37,9 @@ import java.util.List;
|
||||||
@Component
|
@Component
|
||||||
public class ParsingMQTT {
|
public class ParsingMQTT {
|
||||||
|
|
||||||
|
private final static String topic = "sysCar_vin_topic";
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private RedisTemplate<String, Object> redisTemplate;
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
|
@ -45,6 +52,18 @@ public class ParsingMQTT {
|
||||||
@Resource
|
@Resource
|
||||||
private RemoteMessageValueService remoteMessageValueService;
|
private RemoteMessageValueService remoteMessageValueService;
|
||||||
|
|
||||||
|
//车辆信息
|
||||||
|
@Resource
|
||||||
|
private CarVehicleCacheService vehicleCacheService;
|
||||||
|
|
||||||
|
//车辆类型信息
|
||||||
|
@Resource
|
||||||
|
private CarVehicleTypeCacheService vehicleTypeCacheService;
|
||||||
|
|
||||||
|
//报文模版信息
|
||||||
|
@Resource
|
||||||
|
private CarMessageValueCacheService allMessageValueCacheService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 协议解析
|
* 协议解析
|
||||||
*/
|
*/
|
||||||
|
@ -59,7 +78,7 @@ public class ParsingMQTT {
|
||||||
MqttClient sampleClient = new MqttClient(MQTTConnect.BROKER, MQTTConnect.CLIENT_ID);
|
MqttClient sampleClient = new MqttClient(MQTTConnect.BROKER, MQTTConnect.CLIENT_ID);
|
||||||
MqttConnectOptions connOpts = new MqttConnectOptions();
|
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||||
connOpts.setCleanSession(true);
|
connOpts.setCleanSession(true);
|
||||||
log.info("Connecting to MQTTConnect.BROKER: {}", MQTTConnect.BROKER);
|
log.info("连接中MQTTConnect.BROKER: {}", MQTTConnect.BROKER);
|
||||||
sampleClient.connect(connOpts);
|
sampleClient.connect(connOpts);
|
||||||
sampleClient.subscribe(MQTTConnect.TOPIC, 0);
|
sampleClient.subscribe(MQTTConnect.TOPIC, 0);
|
||||||
sampleClient.setCallback(new MqttCallback() {
|
sampleClient.setCallback(new MqttCallback() {
|
||||||
|
@ -78,7 +97,7 @@ public class ParsingMQTT {
|
||||||
ProducerRecord<String, String> producerRecord = new ProducerRecord<>(KafkaConstants.MESSAGE_PARSING,
|
ProducerRecord<String, String> producerRecord = new ProducerRecord<>(KafkaConstants.MESSAGE_PARSING,
|
||||||
entries.toString() );
|
entries.toString() );
|
||||||
kafkaProducer.send(producerRecord);
|
kafkaProducer.send(producerRecord);
|
||||||
log.info("解析之后的数据"+entries);
|
log.info("解析之后的数据:"+entries);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,33 +119,11 @@ public class ParsingMQTT {
|
||||||
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 = remoteVehicleService.findByVehicleVin(vehicleVin);
|
// 根据车辆VIN码查询车辆信息
|
||||||
Long templateId = byVehicleVin.getData();
|
Vehicle vehicle = vehicleCacheService.get(vehicleVin);
|
||||||
List<MessageValueListResp> templateList;
|
VehicleType vehicleType = vehicleTypeCacheService.get(String.valueOf(vehicle.getVehicleTypeId()));
|
||||||
//从redis缓存中获取报文模板数据
|
Long templateId = vehicleType.getMessageTemplateId();
|
||||||
try {
|
List<MessageValueListResp> templateList = allMessageValueCacheService.get(String.valueOf(templateId));
|
||||||
String redisKey = RedisConstants.MESSAGE_TEMPLATE + templateId;
|
|
||||||
if (redisTemplate.hasKey(redisKey)) {
|
|
||||||
List<Object> list = redisTemplate.opsForList().range(redisKey, 0, -1);
|
|
||||||
templateList = list.stream()
|
|
||||||
.map(obj -> JSON.parseObject(obj.toString(), MessageValueListResp.class))
|
|
||||||
.toList();
|
|
||||||
log.info("Redis缓存查询成功");
|
|
||||||
} else {
|
|
||||||
Result<List<MessageValueListResp>> byTemplateId = remoteMessageValueService.findByTemplateId(templateId);
|
|
||||||
templateList = byTemplateId.getData();
|
|
||||||
templateList.forEach(
|
|
||||||
listResp ->
|
|
||||||
redisTemplate.opsForList().rightPush(
|
|
||||||
redisKey, JSON.toJSONString(listResp)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
log.info("数据库查询成功:"+byTemplateId);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.info("获取报文模板失败");
|
|
||||||
throw new RuntimeException("获取报文模板失败");
|
|
||||||
}
|
|
||||||
//判断报文模板列表不为空
|
//判断报文模板列表不为空
|
||||||
if (templateList.isEmpty()) {
|
if (templateList.isEmpty()) {
|
||||||
log.info("报文模版为空");
|
log.info("报文模版为空");
|
||||||
|
|
|
@ -1,86 +0,0 @@
|
||||||
package com.muyu.analysis.parsing.mqtt;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
import org.w3c.dom.stylesheets.LinkStyle;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author:李庆帅
|
|
||||||
* @Package:com.muyu.analysis.parsing.mqtt
|
|
||||||
* @Project:cloud-server
|
|
||||||
* @name:Test2
|
|
||||||
* @Date:2024/10/6 20:36
|
|
||||||
*/
|
|
||||||
@Log4j2
|
|
||||||
public class Test2
|
|
||||||
{
|
|
||||||
private static final int DURATION_SECONDS = 5;
|
|
||||||
private static List<JSONObject> receivedStrings = new ArrayList<>();
|
|
||||||
private static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
|
||||||
private static int elapsedSeconds = 0;
|
|
||||||
private static String file = "elapsed" ;
|
|
||||||
|
|
||||||
public static void main(String[] args){
|
|
||||||
//定义一个任务,每秒执行一次
|
|
||||||
Runnable task = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
JSONObject stringFromSource = getStringFromSource();
|
|
||||||
receivedStrings.add(stringFromSource);
|
|
||||||
System.out.println("Received:"+stringFromSource);
|
|
||||||
//清理超过的数据
|
|
||||||
cleanUpOIdStrings();
|
|
||||||
//检查超速条件
|
|
||||||
checkForSpeeding();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
//每个1秒执行一次任务
|
|
||||||
scheduler.scheduleAtFixedRate(task,0,1, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
//模拟从某个源获取字符串的方法
|
|
||||||
private static JSONObject getStringFromSource(){
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
|
||||||
jsonObject.put("message","Hello World");
|
|
||||||
jsonObject.put("time",System.currentTimeMillis());
|
|
||||||
jsonObject.put("elapsed",elapsedSeconds);
|
|
||||||
return jsonObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
//清理超过60秒的数据
|
|
||||||
private static void cleanUpOIdStrings(){
|
|
||||||
long currentTime = System.currentTimeMillis();
|
|
||||||
receivedStrings.removeIf(jsonObject ->currentTime-jsonObject.getLong("time")>TimeUnit.SECONDS.toMicros(DURATION_SECONDS));
|
|
||||||
}
|
|
||||||
|
|
||||||
//检查是否有超速情况
|
|
||||||
private static void checkForSpeeding()
|
|
||||||
{
|
|
||||||
if(receivedStrings.size() < 2)return;//如果数据不足,直接返回
|
|
||||||
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
|
||||||
jsonObject.put("message","你好");
|
|
||||||
jsonObject.put("time",System.currentTimeMillis());
|
|
||||||
jsonObject.put("elapsed",10);
|
|
||||||
|
|
||||||
for (int i = 0; i < receivedStrings.size(); i++) {
|
|
||||||
JSONObject current = receivedStrings.get(i);
|
|
||||||
JSONObject next = receivedStrings.get(i + 1);
|
|
||||||
|
|
||||||
Short currentElapsed = current.getShort(file);
|
|
||||||
Short nextElapsed = next.getShort(file);
|
|
||||||
receivedStrings.add(jsonObject);
|
|
||||||
//检查条件,如果相差大于12,则记录错误
|
|
||||||
if (nextElapsed - currentElapsed > 12) {
|
|
||||||
System.out.println("出错啦!出错啦!车子超速啦!!!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue