Compare commits

...

4 Commits

Author SHA1 Message Date
李东佳 c1c93dcaba feat(): 测试 2024-10-04 16:42:12 +08:00
sy200 d1440fb706 feat:()优化代码 2024-10-04 09:13:30 +08:00
sy200 3ed255fe1e feat:()添加报文模版缓存 2024-10-02 14:33:01 +08:00
sy200 1d91e51199 feat:()添加报文模版缓存 2024-10-02 09:40:38 +08:00
26 changed files with 288 additions and 98 deletions

View File

@ -2,6 +2,9 @@ package com.muyu.enterprise.cache;
import com.muyu.common.cache.CacheAbsBacis;
import com.muyu.domain.Fence;
import com.muyu.domain.resp.FenceResp;
import java.util.List;
/**
*
@ -21,4 +24,5 @@ public class FenceCahceService extends CacheAbsBacis<String, Fence> {
public String decode(String key) {
return key.replace("fence:info:", "");
}
}

View File

@ -0,0 +1,26 @@
package com.muyu.enterprise.cache;
import com.muyu.common.cache.CacheAbsBacis;
import com.muyu.domain.MessageTemplate;
/**
*
*/
public class MessageTemplateCacheService extends CacheAbsBacis<String, MessageTemplate> {
@Override
public void clear() {
}
@Override
public String keyPre() {
return "messageTemplate:info:";
}
@Override
public String decode(String key) {
return key.replace("messageTemplate:info:", "");
}
}

View File

@ -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:", "");
}
}

View File

@ -0,0 +1,24 @@
package com.muyu.enterprise.cache;
import com.muyu.common.cache.CacheAbsBacis;
import com.muyu.domain.VehicleType;
/**
*
*/
public class VehicleTypeCacheService 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:", "");
}
}

View File

@ -14,11 +14,11 @@ public class WarnRuleCacheService extends CacheAbsBacis<String, WarnRule> {
@Override
public String keyPre() {
return "warn:info:";
return "warnRule:info:";
}
@Override
public String decode(String key) {
return key.replace("warn:info:", "");
return key.replace("warnRule:info:", "");
}
}

View File

@ -5,7 +5,7 @@ import com.muyu.domain.WarnRule;
import com.muyu.domain.WarnStrategy;
/**
*
*
*/
public class WarnStrategyCacheService extends CacheAbsBacis<String, WarnStrategy> {
@Override
@ -15,11 +15,11 @@ public class WarnStrategyCacheService extends CacheAbsBacis<String, WarnStrategy
@Override
public String keyPre() {
return "warn:info:";
return "warnStrategy:info:";
}
@Override
public String decode(String key) {
return key.replace("warn:info:", "");
return key.replace("warnStrategy:info:", "");
}
}

View File

@ -3,3 +3,5 @@ com.muyu.enterprise.cache.FaultCacheService
com.muyu.enterprise.cache.FenceCahceService
com.muyu.enterprise.cache.WarnRuleCacheService
com.muyu.enterprise.cache.WarnStrategyCacheService
com.muyu.enterprise.cache.MessageTemplateCacheService
com.muyu.enterprise.cache.VehicleTypeCacheService

View File

@ -3,9 +3,6 @@ package com.muyu.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.annotation.Excel.ColumnType;
import com.muyu.common.core.web.domain.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
@ -44,7 +41,16 @@ public class VehicleType extends BaseEntity {
*
*/
@Schema(type = "Integer",description = "报文模版外键")
private Integer messageTemplateId;
private Long messageTemplateId;
/**
*
*/
public static VehicleType addBuilder(VehicleType vehicleType) {
return VehicleType.builder().
vehicleTypeId(vehicleType.getVehicleTypeId()).
vehicleTypeName(vehicleType.getVehicleTypeName()).
build();
}
}

View File

@ -0,0 +1,30 @@
package com.muyu.domain.req;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
*
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Tag(name = "绑定围栏组参数")
public class BoundFenceGroupReq {
/**
* Id
*/
private Long vehicleId;
/**
* Ids
*/
private List<Long> fenceGroupIds;
}

View File

@ -54,7 +54,7 @@ public class ElectController extends BaseController {
public Result<TableDataInfo<FenceResp>> showList(@RequestBody @Validated FenceReq req) {
startPage();
List<FenceResp> list = electService.selectFenceList(req);
fenceCahceService.get(String.valueOf(req));
//将列表存到Redis
return getDataTable(list);
}
@ -155,5 +155,4 @@ public class ElectController extends BaseController {
return Result.success(fences);
}
}

View File

@ -1,8 +1,11 @@
package com.muyu.enterprise.controller;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.domain.MessageTemplate;
import com.muyu.domain.req.MessageTemplateAddReq;
import com.muyu.domain.resp.MessageTemplateListResp;
import com.muyu.enterprise.cache.MessageTemplateCacheService;
import com.muyu.enterprise.service.MessageTemplateService;
import com.muyu.common.core.domain.Result;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -30,6 +33,10 @@ public class MessageTemplateController {
@Autowired
private MessageTemplateService messageTemplateService;
//缓存
@Autowired
private MessageTemplateCacheService templateCacheService;
/**
*
*1
@ -55,8 +62,14 @@ public class MessageTemplateController {
*/
@PostMapping("/")
public Result<String> save(@RequestBody MessageTemplateAddReq messageTemplateAddReq) {
messageTemplateService.save(MessageTemplate.addBuild(messageTemplateAddReq));
return Result.success("添加成功");
boolean save = messageTemplateService.save(MessageTemplate.addBuild(messageTemplateAddReq));
//获取用户信息
LoginUser loginUser = SecurityUtils.getLoginUser();
//获取租户唯一标识
String databaseName = loginUser.getSysUser().getDatabaseName();
//添加到缓存
templateCacheService.put(databaseName+messageTemplateAddReq.getMessageTemplateName(), MessageTemplate.addBuild(messageTemplateAddReq));
return Result.success(save? "新增成功" : "新增失败");
}
/**

View File

@ -2,6 +2,7 @@ package com.muyu.enterprise.controller;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.domain.req.BoundFenceGroupReq;
import com.muyu.enterprise.cache.VehicleCacheService;
import com.muyu.enterprise.service.VehicleService;
import com.muyu.common.core.domain.Result;
@ -69,12 +70,12 @@ public class VehicleController extends BaseController {
@Operation(summary = "新增车辆", description = "录入车辆信息")
public Result<String> save(@RequestBody VehicleAddReq vehicleAddReq) {
boolean save = vehicleService.save(Vehicle.addBuild(vehicleAddReq));
//获取用户信息
LoginUser loginUser = SecurityUtils.getLoginUser();
//获取租户唯一标识
String databaseName = loginUser.getSysUser().getDatabaseName();
// //获取用户信息
// LoginUser loginUser = SecurityUtils.getLoginUser();
// //获取租户唯一标识
// String databaseName = loginUser.getSysUser().getDatabaseName();
//存到redis
vehicleCacheService.put(databaseName+vehicleAddReq.getVehicleVin(), Vehicle.addBuild(vehicleAddReq));
vehicleCacheService.put(vehicleAddReq.getVehicleVin(), Vehicle.addBuild(vehicleAddReq));
return Result.success(save? "新增成功" : "新增失败");
}
@ -144,20 +145,9 @@ public class VehicleController extends BaseController {
*/
@GetMapping("/addBoundFenceGroup")
@Operation(description = "车辆绑定围栏组")
public Result<String> boundFenceGroup(
@Validated @RequestBody BoundMiddle boundMiddle){
return null;
}
/**
* vinid
* @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);
public Result boundFenceGroup(
@Validated @RequestBody BoundFenceGroupReq boundFenceGroupReq){
vehicleService.boundFenceGroup(boundFenceGroupReq);
return Result.success("绑定成功");
}
}

View File

@ -1,15 +1,20 @@
package com.muyu.enterprise.controller;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.domain.MessageValue;
import com.muyu.domain.VehicleType;
import com.muyu.domain.req.MessageValueAddReq;
import com.muyu.domain.req.VehicleAddReq;
import com.muyu.enterprise.cache.VehicleCacheService;
import com.muyu.enterprise.cache.VehicleTypeCacheService;
import com.muyu.enterprise.service.VehicleTypeService;
import com.muyu.common.core.domain.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -30,6 +35,9 @@ public class VehicleTypeController {
@Autowired
private VehicleTypeService vehicleTypeService;
@Autowired
private VehicleTypeCacheService vehicleTypeCacheService;
/**
*
* @return
@ -37,6 +45,28 @@ public class VehicleTypeController {
@RequestMapping(path = "/", method = RequestMethod.POST)
@Operation(summary = "车辆类型列表",description = "车辆类型列表")
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);
}
/**
*
* @param vehicleType
* @return
*/
@PostMapping("/add")
@Operation(summary = "添加报文数据", description = "新增报文数据")
public Result<String> save(@RequestBody VehicleType vehicleType) {
boolean save = vehicleTypeService.save(vehicleType);
// //获取用户信息
// LoginUser loginUser = SecurityUtils.getLoginUser();
// //获取租户唯一标识
// String databaseName = loginUser.getSysUser().getDatabaseName();
//存到redis
vehicleTypeCacheService.put(String.valueOf(vehicleType.getVehicleTypeId()),vehicleType);
return Result.success(save? "添加成功" : "添加失败");
}
}

View File

@ -30,11 +30,6 @@ public interface ElectMapper extends MPJBaseMapper<Fence> {
@Select("select * from fence where fence_id=#{fenceId}")
List<Fence> mapShow(@Param("fenceId") Long fenceId);
// /**
// * 根据id查询车辆
// */
// Fence boundFence(@Param("fenceId") Long fenceId);
/**
* ()
*/

View File

@ -28,7 +28,16 @@ public interface FencegroupMapper extends MPJBaseMapper<FenceGroup> {
@Select("SELECT g.fence_group_id,g.group_type,g.priority,g.`status`,f.fence_id, group_CONCAT( f.fence_name ) AS fence_name FROM fence_group g LEFT JOIN middle m ON m.fence_group_id = g.fence_group_id LEFT JOIN fence f ON m.fence_id = f.fence_id GROUP BY g.fence_group_id")
List<FenceGroup> showGroupList(FenceGroupReq req);
@Insert("INSERT INTO `vehicle-basic`.`middle` (`fence_id`, `fence_group_id`) VALUES <foreach collection=\"fenceIds\" item=\"id\" separator=\",\"> (#{id},#{fenceGroupId}) </foreach>")
// @Insert("INSERT INTO `vehicle-basic`.`middle` (`fence_id`, `fence_group_id`) VALUES <foreach collection='fenceIds' item='id' separator=','> (#{id},#{fenceGroupId}) </foreach>")
// @Insert({ "<script>", "INSERT INTO user_role (user_id, role_id) VALUES ", "<foreach collection='roleIds' item='roleId' separator=','>", "(#{userId}, #{roleId})", "</foreach>", "</script>" })
@Insert({
"<script>",
"INSERT INTO `vehicle-basic`.`middle` (fence_id, fence_group_id) VALUES ",
"<foreach collection='fenceIds' item='id' separator=','>",
"(#{id}, #{fenceGroupId})",
"</foreach>",
"</script>"
})
void addMiddle(@Param("fenceIds") Integer[] fenceIds,@Param("fenceGroupId") Long fenceGroupId);
}

View File

@ -2,8 +2,10 @@ package com.muyu.enterprise.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.muyu.domain.Vehicle;
import com.muyu.domain.req.BoundFenceGroupReq;
import com.muyu.domain.req.VehicleManageReq;
import com.muyu.domain.resp.VehicleManageResp;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
@ -30,14 +32,17 @@ public interface VehicleMapper extends MPJBaseMapper<Vehicle> {
/**
*
* @param boundFenceGroupReq
*/
void bindFenceGroup(@Param("fenceGroupIds") Integer[] fenceGroupIds, @Param("vehicleId") Long vehicleId);
// @Insert("INSERT INTO `vehicle-basic`.`bound_middle` (`fence_group_id`,`vehicle_id`) VALUES <foreach collection=\"fenceGroupIds\" item=\"id\" separator=\",\"> (#{id},#{vehicleId}) </foreach>")
@Insert({
"<script>",
"INSERT INTO `vehicle-basic`.`bound_middle` (fence_group_id,vehicle_id) VALUES ",
"<foreach collection='fenceGroupIds' item='id' separator=','>",
"(#{id}, #{vehicleId})",
"</foreach>",
"</script>"
})
void boundFenceGroup(BoundFenceGroupReq boundFenceGroupReq);
/**
* vinid
* @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);
}

View File

@ -19,7 +19,5 @@ public interface IFencegroupService extends IService<FenceGroup> {
void addGroup(FenceGroupAddReq addReq);
// List<FenceGroup> haveFence(HaveFence haveFence);
//
}

View File

@ -2,8 +2,10 @@ package com.muyu.enterprise.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.domain.Vehicle;
import com.muyu.domain.req.BoundFenceGroupReq;
import com.muyu.domain.req.VehicleManageReq;
import com.muyu.domain.resp.VehicleManageResp;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -24,11 +26,8 @@ public interface VehicleService extends IService<Vehicle> {
*/
List<VehicleManageResp> getVehicleList(VehicleManageReq vehicleManageReq);
/**
* vinid
* @param vehicleVin
* @return
*
*/
Long findByVehicleVin(String vehicleVin);
void boundFenceGroup(BoundFenceGroupReq boundFenceGroupReq);
}

View File

@ -2,6 +2,7 @@ package com.muyu.enterprise.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.muyu.enterprise.cache.FenceCahceService;
import com.muyu.enterprise.mapper.ElectMapper;
import com.muyu.enterprise.mapper.WarnLogsMapper;
import com.muyu.enterprise.service.ElectService;
@ -25,6 +26,10 @@ public class ElectServiceImpl
@Autowired
private WarnLogsMapper warnLogsMapper;
@Autowired
private FenceCahceService fenceCahceService;
@Override
public List<FenceResp> selectFenceList(FenceReq req) {
@ -39,6 +44,11 @@ public class ElectServiceImpl
req.getFenceName()
);
List<FenceResp> list = electMapper.selectJoinList(FenceResp.class, wrapper);
String decode = fenceCahceService.decode(String.valueOf(list));
//将获取到的数据存到Redis
// fenceCahceService.put(String.valueOf(decode),d);
return list;
}
//

View File

@ -41,10 +41,5 @@ public class FencegroupServiceImpl
}
// @Override
// public List<FenceGroup> haveFence(HaveFence haveFence) {
// return null;
// }
}

View File

@ -5,6 +5,7 @@ import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.domain.Vehicle;
import com.muyu.domain.VehicleType;
import com.muyu.domain.req.BoundFenceGroupReq;
import com.muyu.domain.req.VehicleManageReq;
import com.muyu.domain.resp.VehicleManageResp;
import com.muyu.enterprise.mapper.VehicleMapper;
@ -58,15 +59,11 @@ public class VehicleServiceImpl
return list;
}
/**
* vinid
* @param vehicleVin
* @return
*/
@Override
public Long findByVehicleVin(String vehicleVin) {
Long templateId = vehicleMapper.findByVehicleVin(vehicleVin);
return templateId;
public void boundFenceGroup(BoundFenceGroupReq boundFenceGroupReq) {
vehicleMapper.boundFenceGroup(boundFenceGroupReq);
}
}

View File

@ -100,6 +100,13 @@
<artifactId>cloud-common-kafka</artifactId>
</dependency>
<!--缓存依赖-->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-modules-enterprise-cache</artifactId>
<version>3.6.3</version>
</dependency>
</dependencies>
<build>

View File

@ -116,6 +116,12 @@
<artifactId>cloud-common-kafka</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-modules-enterprise-cache</artifactId>
<version>3.6.3</version>
</dependency>
</dependencies>
<build>

View File

@ -20,15 +20,6 @@ import java.util.List;
@FeignClient(name = "cloud-car")
public interface RemoteServiceClient {
/**
* vinid
* @param vehicleVin
* @return
*/
@GetMapping("/vehicleManage/findByVehicleVin/{vehicleVin}")
@Operation(description = "通过车辆vin码查询模板id")
public Result<Long> findByVehicleVin(@PathVariable("vehicleVin") String vehicleVin);
/**
* id
* @param templateId

View File

@ -26,11 +26,6 @@ public class RemoteServiceClientFactory implements FallbackFactory<RemoteService
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;

View File

@ -4,7 +4,16 @@ import cn.hutool.json.JSONObject;
import com.alibaba.fastjson.JSON;
import com.muyu.cloud.protocol.parsing.feign.RemoteServiceClient;
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.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 org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
@ -30,7 +39,7 @@ import java.util.List;
public class ParsingTest {
@Resource
private RedisTemplate<String, Object> redisTemplate;
private RedisService redisService;
@Autowired
private RemoteServiceClient remoteServiceClient;
@ -38,6 +47,15 @@ public class ParsingTest {
@Resource
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
* @return
* @param messageStr
* @return
*/
public JSONObject protocolParsing(String messageStr) {
//根据空格切割数据
@ -91,15 +109,23 @@ public class ParsingTest {
//取出车辆VIN码
String vehicleVin = result.substring(1, 18);
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
Result<Long> byVehicleVin = remoteServiceClient.findByVehicleVin(vehicleVin);
Long templateId = byVehicleVin.getData();
Long templateId = cacheVehicleType.getMessageTemplateId();
List<MessageValueListResp> templateList;
//从redis缓存中获取报文模板数据
try {
String redisKey = "messageTemplate" + templateId;
if (redisTemplate.hasKey(redisKey)) {
List<Object> list = redisTemplate.opsForList().range(redisKey, 0, -1);
if (redisService.hasKey(redisKey)) {
// List<Object> list = redisTemplate.opsForList().range(redisKey, 0, -1);
List<MessageValueListResp> list = messageValueCacheService.get(redisKey);
templateList = list.stream()
.map(obj -> JSON.parseObject(obj.toString(), MessageValueListResp.class))
.toList();
@ -107,12 +133,13 @@ public class ParsingTest {
} else {
Result<List<MessageValueListResp>> byTemplateId = remoteServiceClient.findByTemplateId(templateId);
templateList = byTemplateId.getData();
templateList.forEach(
listResp ->
redisTemplate.opsForList().rightPush(
redisKey, JSON.toJSONString(listResp)
)
);
messageValueCacheService.put(redisKey , templateList);
// templateList.forEach(
// listResp ->
// redisTemplate.opsForList().rightPush(
// redisKey, JSON.toJSONString(listResp)
// )
// );
log.info("数据库查询成功");
}
} catch (Exception e) {