feat:()添加报文模版缓存

dev.protocol
sy200 2024-10-02 14:33:01 +08:00
parent 1d91e51199
commit 3ed255fe1e
13 changed files with 98 additions and 14 deletions

View File

@ -2,6 +2,9 @@ package com.muyu.enterprise.cache;
import com.muyu.common.cache.CacheAbsBacis; import com.muyu.common.cache.CacheAbsBacis;
import com.muyu.domain.Fence; 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) { public String decode(String key) {
return key.replace("fence:info:", ""); return key.replace("fence: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

@ -3,3 +3,4 @@ com.muyu.enterprise.cache.FaultCacheService
com.muyu.enterprise.cache.FenceCahceService com.muyu.enterprise.cache.FenceCahceService
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

View File

@ -3,9 +3,6 @@ package com.muyu.domain;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; 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 com.muyu.common.core.web.domain.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*; import lombok.*;
@ -46,5 +43,14 @@ public class VehicleType extends BaseEntity {
@Schema(type = "Integer",description = "报文模版外键") @Schema(type = "Integer",description = "报文模版外键")
private Integer messageTemplateId; private Integer messageTemplateId;
/**
*
*/
public static VehicleType addBuilder(VehicleType vehicleType) {
return VehicleType.builder().
vehicleTypeId(vehicleType.getVehicleTypeId()).
vehicleTypeName(vehicleType.getVehicleTypeName()).
build();
}
} }

View File

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

View File

@ -1,15 +1,20 @@
package com.muyu.enterprise.controller; 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.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.enterprise.service.VehicleTypeService;
import com.muyu.common.core.domain.Result; import com.muyu.common.core.domain.Result;
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 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.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
@ -30,6 +35,9 @@ public class VehicleTypeController {
@Autowired @Autowired
private VehicleTypeService vehicleTypeService; private VehicleTypeService vehicleTypeService;
@Autowired
private VehicleTypeCacheService vehicleTypeCacheService;
/** /**
* *
* @return * @return
@ -39,4 +47,22 @@ public class VehicleTypeController {
public Result<List<VehicleType>> findAll(){ public Result<List<VehicleType>> findAll(){
return Result.success(vehicleTypeService.list()); return Result.success(vehicleTypeService.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(databaseName+vehicleType.getVehicleTypeId(),vehicleType);
return Result.success(save? "添加成功" : "添加失败");
}
} }

View File

@ -40,4 +40,5 @@ public interface VehicleMapper extends MPJBaseMapper<Vehicle> {
*/ */
@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}") @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); Long findByVehicleVin(String vehicleVin);
} }

View File

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

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.domain.Vehicle; import com.muyu.domain.Vehicle;
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 org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@ -31,4 +32,10 @@ public interface VehicleService extends IService<Vehicle> {
* @return * @return
*/ */
Long findByVehicleVin(String vehicleVin); Long findByVehicleVin(String vehicleVin);
/**
*
*/
void bindFenceGroup(@Param("fenceGroupIds") Integer[] fenceGroupIds, @Param("vehicleId") Long vehicleId);
} }

View File

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

View File

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

View File

@ -69,4 +69,9 @@ public class VehicleServiceImpl
return templateId; return templateId;
} }
@Override
public void bindFenceGroup(Integer[] fenceGroupIds, Long vehicleId) {
vehicleMapper.bindFenceGroup(fenceGroupIds, vehicleId);
}
} }

View File

@ -100,6 +100,13 @@
<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>