1.feat(): 添加:

a.添加了自定义的一个预警类
b.添加了远调的代码,连同熔断
2.fix(): 修复了:
a.修改了redis在列表通过vin码存储
b.修改了redis的存储类型
c.优化了一些代码

更新时间10081949
dev.entBusiness
微醺 2024-10-10 11:22:59 +08:00
parent 4f52c6c4ac
commit 4ca2fd7e7e
24 changed files with 179 additions and 130 deletions

View File

@ -1,5 +1,7 @@
package com.muyu.common.cache.config;
import com.muyu.common.core.text.StrFormatter;
/**
*
* @ClassName PrimaryKeyBasic
@ -13,13 +15,18 @@ public interface PrimaryKeyBasic <K>{
*/
public String keyPre();
/**
* key
*/
public String keyPost();
/**
*
* @param key
* @return
*/
public default String encode(K key){
return keyPre() + key.toString();
return StrFormatter.format("{}:vin{}:{}", keyPre(), key.toString(), keyPost());
}
/**

View File

@ -1,29 +0,0 @@
package com.muyu.enterprise.cache;
import com.muyu.common.cache.config.CacheAbsBasic;
import com.muyu.enterprise.domain.CarCompany;
import com.muyu.enterprise.domain.CarManage;
/**
* redis
* @ClassName CarCompanyCacheService
* @Description CarCompanyCacheService:
* @Date 2024/10/3 15:22
* @author MingWei.Zong()
*/
public class CarCompanyCacheService extends CacheAbsBasic<String, CarCompany> {
@Override
public String keyPre() {
return "CarCompany:info:";
}
@Override
public String decode(String key) {
return key.replace("CarCompany:info:","");
}
}

View File

@ -16,13 +16,18 @@ import com.muyu.enterprise.domain.SysCarFault;
public class CarFaultCacheService extends CacheAbsBasic<String, SysCarFault> {
@Override
public String keyPre() {
return "sysCarFault:info:";
return "vehicleDeterminationStandard";
}
@Override
public String keyPost() {
return "fault";
}
@Override
public String decode(String key) {
return key.replace("faultType:info:","");
return "";
}

View File

@ -1,30 +1,33 @@
package com.muyu.enterprise.cache;
import com.muyu.common.cache.config.CacheAbsBasic;
import com.muyu.enterprise.domain.CarManage;
import com.muyu.enterprise.domain.vo.CarVO;
import java.util.List;
/**
* redis
* redis
* @ClassName CarManageCacheService
* @Description CarManageCacheService:
* @Date 2024/10/3 15:22
* @author MingWei.Zong()
*/
public class CarManageCacheService extends CacheAbsBasic<String, List<CarManage>> {
public class CarManageCacheService extends CacheAbsBasic<String, List<CarVO>> {
@Override
public String keyPre() {
return "carManage:info:";
return "vehicleDeterminationStandard";
}
@Override
public String keyPost() {
return "carManage";
}
@Override
public String decode(String key) {
return key.replace("carManage:info:","");
return "";
}

View File

@ -1,30 +0,0 @@
package com.muyu.enterprise.cache;
import com.muyu.common.cache.config.CacheAbsBasic;
import com.muyu.enterprise.domain.CarMessage;
/**
* redis
* @ClassName CarMessageCacheService
* @Description CarMessageCacheService:
* @Date 2024/9/30 11:42
* @author MingWei.Zong()
*/
public class CarMessageCacheService extends CacheAbsBasic<String, CarMessage> {
@Override
public String keyPre() {
return "carMessage:info:";
}
// @Override
// public String encode(String key) {
// return super.encode(key);
// }
@Override
public String decode(String key) {
return key.replace("carMessage:info:","");
}
}

View File

@ -3,6 +3,7 @@ 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.vo.CarTemplateVO;
/**
* redis
@ -12,17 +13,21 @@ import com.muyu.enterprise.domain.CarTemplate;
* @author MingWei.Zong()
*/
public class CarTemplateCacheService extends CacheAbsBasic<String, CarTemplate> {
public class CarTemplateCacheService extends CacheAbsBasic<String, CarTemplateVO> {
@Override
public String keyPre() {
return "carTemplate:info:";
return "vehicleDeterminationStandard";
}
@Override
public String keyPost() {
return "messageTemplate";
}
@Override
public String decode(String key) {
return key.replace("carTemplate:info:","");
return "";
}

View File

@ -15,13 +15,18 @@ import com.muyu.enterprise.domain.vo.WarnVo;
public class CarWarnCacheService extends CacheAbsBasic<String, WarnVo> {
@Override
public String keyPre() {
return "warnStrategy:info:";
return "vehicleDeterminationStandard";
}
@Override
public String keyPost() {
return "warn";
}
@Override
public String decode(String key) {
return key.replace("warnStrategy:info:","");
return "";
}

View File

@ -15,14 +15,18 @@ import com.muyu.enterprise.domain.dateBase.ElectronicFence;
public class ElectronicFenceCacheService extends CacheAbsBasic<String, ElectronicFence> {
@Override
public String keyPre() {
return "electronicFence:info:";
return "vehicleDeterminationStandard";
}
@Override
public String keyPost() {
return "electronicFence";
}
@Override
public String decode(String key) {
return key.replace("electronicFence:info:","");
return "";
}

View File

@ -1,7 +1,5 @@
com.muyu.enterprise.cache.CarCompanyCacheService
com.muyu.enterprise.cache.CarFaultCacheService
com.muyu.enterprise.cache.CarManageCacheService
com.muyu.enterprise.cache.CarMessageCacheService
com.muyu.enterprise.cache.CarTemplateCacheService
com.muyu.enterprise.cache.CarWarnCacheService
com.muyu.enterprise.cache.ElectronicFenceCacheService
com.muyu.enterprise.cache.CarManageCacheService

View File

@ -28,7 +28,7 @@ public class CarType {
* id
*/
@TableId(value = "car_type_id",type = IdType.AUTO)
private Integer carTypeId;
private long carTypeId;
/**
*
@ -38,7 +38,7 @@ public class CarType {
/**
* id
*/
private Integer templateId;
private long templateId;
}

View File

@ -0,0 +1,61 @@
package com.muyu.enterprise.domain.vo;
/**
*
*
* @ClassName CarTemplateVO
* @PATH com.muyu.enterprise.domain.vo:
* @Date 2024/10/9 20:42
* @author MingWei.Zong()
*/
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName(value = "car_template",autoResultMap = true)
public class CarTemplateVO {
/**
*
*/
@TableId(value = "template_id",type = IdType.AUTO)
private Long templateId;
/**
*
*/
private String templateName;
/**
*
*/
private String templateDescribe;
/**
*
*/
private String remark;
/**
*
*/
private Long messageId;
/**
*
*/
private String messageType;
/**
*
*/
private Integer messageStartIndex;
/**
*
*/
private Integer messageEndIndex;
/**
*
*/
private String messageLabel;
}

View File

@ -18,26 +18,6 @@ import org.springframework.web.client.RestTemplate;
public class CloudEnterpriseApplication {
public static void main (String[] args) {
SpringApplication.run(CloudEnterpriseApplication.class, args);
System.out.println(" _ooOoo_\n" +
" o8888888o\n" +
" 88\" . \"88\n" +
" (| -_- |)\n" +
" O\\ = /O\n" +
" ____/`---'\\____\n" +
" .' \\\\| |// `.\n" +
" / \\\\||| : |||// \\\n" +
" / _||||| -:- |||||- \\\n" +
" | | \\\\\\ - /// | |\n" +
" | \\_| ''\\---/'' | |\n" +
" \\ .-\\__ `-` ___/-. /\n" +
" ___`. .' /--.--\\ `. . __\n" +
" .\"\" '< `.___\\_<|>_/___.' >'\"\".\n" +
" | | : `- \\`.;`\\ _ /`;.`/ - ` : | |\n" +
" \\ \\ `-. \\_ __\\ /__ _/ .-` / /\n" +
" ======`-.____`-.___\\_____/___.-`____.-'======\n" +
" `=---='\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
" // 佛祖保佑 永不宕机 永无BUG //");
}
//实现远程调用

View File

@ -1,23 +1,17 @@
package com.muyu.enterprise.controller;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.RandomUtil;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.enterprise.cache.CarManageCacheService;
import com.muyu.enterprise.domain.CarManage;
import com.muyu.enterprise.domain.CarMessage;
import com.muyu.enterprise.domain.dto.CarDTO;
import com.muyu.enterprise.domain.vo.CarVO;
import com.muyu.enterprise.service.CarCompanyService;
import com.muyu.enterprise.service.CarManageService;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.security.utils.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -100,7 +94,8 @@ public class CarManageController extends BaseController {
// 随机生成VIN码
String key2 = RandomUtil.randomNumbers(17);
carVO.setCarVin(key2);
carManageService.insertCar(carVO);
// carVO
// carManageService.insertCar();
return Result.success("添加成功");
}

View File

@ -3,8 +3,6 @@ package com.muyu.enterprise.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.enterprise.cache.CarManageCacheService;
import com.muyu.enterprise.cache.CarMessageCacheService;
import com.muyu.enterprise.domain.CarMessage;
import com.muyu.enterprise.service.CarMessageService;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -28,7 +26,7 @@ import java.util.List;
@Tag(name = "报文",description = "报文模块")
public class CarMessageController extends BaseController {
private final CarMessageCacheService carMessageCacheService;
// private final CarMessageCacheService carMessageCacheService;
private final CarMessageService sysCarMessageService;
@Autowired
private CarMessageService carMessageService;
@ -70,7 +68,7 @@ public class CarMessageController extends BaseController {
public Result insertMessage(@RequestBody CarMessage carMessage){
sysCarMessageService.save(carMessage);
//报文 redis
carMessageCacheService.put(carMessage.getMessageType(),new CarMessage());
// carMessageCacheService.put(carMessage.getMessageType(),new CarMessage());
return Result.success("添加成功");
}
/**

View File

@ -45,10 +45,20 @@ public class CarTypeController {
* @return
*/
@PostMapping("/catTypeId")
private Result<CarType> catTypeId(@RequestParam("catTypeId") Integer catTypeId) {
private Result<CarType> catTypeId(@RequestParam("catTypeId") Long catTypeId) {
CarType carType = carTypeService.findById(catTypeId);
return Result.success(carType);
}
/**
* id
* @param templateId
* @return
*/
@PostMapping("/selectCarTemplateByTemplateId")
private Result<CarType> selectCarTemplateByTemplateId(@RequestParam("templateId") Long templateId) {
CarType carType = carTypeService.SelectCarTemplateByTemplateId(templateId);
return Result.success(carType);
}
}

View File

@ -13,6 +13,6 @@ import org.apache.ibatis.annotations.Param;
*/
@Mapper
public interface CarTypeMapper extends BaseMapper<CarType> {
CarType findById(@Param("catTypeId") Integer catTypeId);
}

View File

@ -10,6 +10,12 @@ import com.muyu.enterprise.domain.CarType;
* @Date 2024/9/28 16:52
*/
public interface CarTypeService extends IService<CarType> {
CarType findById(Integer catTypeId);
CarType findById(long catTypeId);
/**
* id
* @param templateId
* @return
*/
CarType SelectCarTemplateByTemplateId(Long templateId);
}

View File

@ -74,7 +74,7 @@ public class CarManageServiceImpl extends ServiceImpl<CarManageMapper, CarManage
SysEnt data = remoteEntService.getById(carVO.getEnterpriseId()).getData();
carVO.setName(data.getName());
// 存到 redis
carManageCacheService.put(carVO.getCarVin(),list);
carManageCacheService.put(carVO.getCarVin(),carVOS);
});
return carVOS;
}
@ -102,8 +102,9 @@ public class CarManageServiceImpl extends ServiceImpl<CarManageMapper, CarManage
@Override
public void insertCar(CarManage carVO) {
ArrayList<CarManage> carVOS = new ArrayList<>();
carVOS.add(carVO);
CarVO carVO1 = BeanUtil.copyProperties(carVO, CarVO.class);
List<CarVO> carVOS = new ArrayList<>();
carVOS.add(carVO1);
save(carVO);
// 存到缓存中去
carManageCacheService.put(carVO.getCarVin(),carVOS);

View File

@ -1,9 +1,16 @@
package com.muyu.enterprise.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.enterprise.cache.CarTemplateCacheService;
import com.muyu.enterprise.domain.CarManage;
import com.muyu.enterprise.domain.CarTemplate;
import com.muyu.enterprise.domain.CarType;
import com.muyu.enterprise.mapper.CarManageMapper;
import com.muyu.enterprise.mapper.CarTemplateMapper;
import com.muyu.enterprise.service.CarManageService;
import com.muyu.enterprise.service.CarTemplateService;
import com.muyu.enterprise.service.CarTypeService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -16,8 +23,15 @@ import java.util.List;
* @Date 2024/9/28 16:52
*/
@Service
@Log4j2
public class CarTemplateServiceImpl extends ServiceImpl<CarTemplateMapper, CarTemplate> implements CarTemplateService {
@Autowired
private CarTemplateCacheService carTemplateCacheService;
@Autowired
private CarManageService carManageService;
@Autowired
private CarTypeService carTypeService;
@Autowired
private CarTemplateMapper sysCarTemplateMapper;
/**
@ -36,6 +50,14 @@ public class CarTemplateServiceImpl extends ServiceImpl<CarTemplateMapper, CarTe
*/
@Override
public CarTemplate selectTemplateByTemplateId(Long templateId) {
return sysCarTemplateMapper.selectById(templateId);
// 通过id查询报文信息
CarTemplate carTemplate = sysCarTemplateMapper.selectById(templateId);
// 获取到车辆的 vin 用于存储 redis 1.通过报文模版id 获取车辆类型 id
CarType carType = carTypeService.SelectCarTemplateByTemplateId(templateId);
// 通过 车辆类型ID 获取 车辆信息
CarManage carManage = carManageService.carManageShowByCarTypeId(carType.getCarTypeId());
// 将报文信息存储到 redis
carTemplateCacheService.put(carManage.getCarVin(),carTemplate);
return carTemplate;
}
}

View File

@ -23,8 +23,17 @@ public class CarTypeTypeServiceImpl
private CarTypeMapper carTypeMapper;
@Override
public CarType findById(Integer catTypeId) {
CarType carType= carTypeMapper.findById(catTypeId);
return carType;
public CarType findById(long catTypeId) {
return getById(catTypeId);
}
/**
* id
* @param templateId
* @return
*/
@Override
public CarType SelectCarTemplateByTemplateId(Long templateId) {
return getById(templateId);
}
}

View File

@ -2,8 +2,10 @@ package com.muyu.enterprise.service.impl;
import java.util.List;
import com.muyu.enterprise.cache.CarFaultCacheService;
import com.muyu.enterprise.domain.SysCarFault;
import com.muyu.enterprise.service.SysCarFaultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.muyu.enterprise.mapper.SysCarFaultMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -23,6 +25,9 @@ public class SysCarFaultServiceImpl
extends ServiceImpl<SysCarFaultMapper, SysCarFault>
implements SysCarFaultService {
@Autowired
private CarFaultCacheService carFaultCacheService;
/**
*
*
@ -58,7 +63,7 @@ public class SysCarFaultServiceImpl
queryWrapper.eq(StringUtils.isNotEmpty(sysCarFault.getFaultWarn()),
SysCarFault::getFaultWarn, sysCarFault.getFaultWarn());
// carFaultCacheService.put();
return this.list(queryWrapper);
}

View File

@ -1,10 +1,8 @@
package com.muyu.enterprise.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.enterprise.cache.CarManageCacheService;
import com.muyu.enterprise.cache.CarWarnCacheService;
import com.muyu.enterprise.domain.CarManage;
import com.muyu.enterprise.domain.WarnRule;

View File

@ -3,7 +3,5 @@
<mapper namespace="com.muyu.enterprise.mapper.CarTypeMapper">
<select id="findById" resultType="com.muyu.enterprise.domain.CarType">
select * from t_car_type where t_car_type.car_type_id = #{catTypeId}
</select>
</mapper>

View File

@ -1,7 +1,6 @@
package com.muyu.event.process.consumer;
import com.muyu.enterprise.cache.CarFaultCacheService;
import com.muyu.enterprise.cache.CarManageCacheService;
import com.muyu.enterprise.cache.CarWarnCacheService;
import com.muyu.enterprise.cache.ElectronicFenceCacheService;
import com.muyu.event.process.constant.CacheHandlerConstants;
@ -13,7 +12,6 @@ import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
@ -35,7 +33,7 @@ public class GoOnlineConsumer {
/**
*
*/
private final CarManageCacheService carManageCacheService;
// private final CarManageCacheService carManageCacheService;
/**
*
@ -66,7 +64,7 @@ public class GoOnlineConsumer {
public void online(String vin) {
log.info("车辆vin码{},该车辆已上线", vin);
cacheUtil.put(vin, new HashMap<String, Object>() {{
put(CacheHandlerConstants.CAR_MANAGE_KEY, carManageCacheService.get(vin));
// put(CacheHandlerConstants.CAR_MANAGE_KEY, carManageCacheService.get(vin));
put(CacheHandlerConstants.FAULT_RULE_KEY, carFaultCacheService.get(vin));
put(CacheHandlerConstants.ELECTRONIC_FENCE_KEY, electronicFenceCacheService.get(vin));
put(CacheHandlerConstants.WARN_RULE_KEY, carWarnCacheService.get(vin));