1.feat(): 添加 redis缓存

2.fix(): 更新公共路径
更新时间09301533
dev.entOperation
微醺 2024-09-30 15:33:37 +08:00
parent a7b8987be4
commit b9f3cac204
19 changed files with 253 additions and 18 deletions

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.muyu</groupId>
<artifactId>cloud-common</artifactId>
<version>3.6.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-common-cache</artifactId>
<description>
cloud-common-cache redis缓存架构
</description>
<dependencies>
<!-- redis 缓存模块 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-redis</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,33 @@
package com.muyu.common.cache.config;
/**
*
* @ClassName CacheAbsBasic
* @Description CacheAbsBasic:
* @Date 2024/9/30 1:39
* @author MingWei.Zong
*/
import com.muyu.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
public abstract class CacheAbsBasic<K,V> implements CacheBasic<K,V> {
@Autowired
private RedisService redisService;
@Override
public void put(K key, V value) {
redisService.setCacheObject(encode(key),value);
}
@Override
public V get(K key) {
return redisService.getCacheObject(encode(key));
}
@Override
public void remove(K key) {
redisService.deleteObject(encode(key));
}
}

View File

@ -0,0 +1,21 @@
package com.muyu.common.cache.config;
import java.awt.image.Kernel;
/**
*
* @ClassName CacheBasic
* @Description CacheBasic:
* @Date 2024/9/30 1:36
* @author MingWei.Zong
*/
public interface CacheBasic<K,V> extends PrimaryKeyBasic<K>{
void put(K key,V value);
V get(K key);
void remove(K key);
}

View File

@ -0,0 +1,45 @@
package com.muyu.common.cache.config;
/**
*
* @ClassName PrimaryKeyBasic
* @Description PrimaryKeyBasic:
* @Date 2024/9/30 0:15
* @author MingWei.Zong
*/
public interface PrimaryKeyBasic <K>{
/**
* key
*/
public String keyPre();
/**
*
* @param key
* @return
*/
public default String encode(K key){
return keyPre() + key.toString();
}
/**
* Key
* @param key key
* @return
*/
public K decode(String key);
}

View File

@ -21,6 +21,7 @@
<module>cloud-common-system</module> <module>cloud-common-system</module>
<module>cloud-common-xxl</module> <module>cloud-common-xxl</module>
<module>cloud-common-rabbit</module> <module>cloud-common-rabbit</module>
<module>cloud-common-cache</module>
</modules> </modules>
<artifactId>cloud-common</artifactId> <artifactId>cloud-common</artifactId>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>cloud-modules-enterprise</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>cloud-modules-enterprise-cache</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<description>
cloud-modules-enterprise-cache redis 缓存平台
</description>
<dependencies>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-cache</artifactId>
<version>3.6.3</version>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-modules-enterprise-common</artifactId>
</dependency>
</dependencies>
</project>

View File

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

View File

@ -77,6 +77,13 @@
<artifactId>cloud-common-api-doc</artifactId> <artifactId>cloud-common-api-doc</artifactId>
</dependency> </dependency>
<!-- redis 缓存 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-modules-enterprise-cache</artifactId>
<version>3.6.3</version>
</dependency>
<!-- 企业业务平台 - 公共依赖 --> <!-- 企业业务平台 - 公共依赖 -->
<dependency> <dependency>
<groupId>com.muyu</groupId> <groupId>com.muyu</groupId>

View File

@ -6,8 +6,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
/** /**
* *
*
* @author muyu * @author muyu
*/ */
@EnableCustomConfig @EnableCustomConfig

View File

@ -5,6 +5,7 @@ import com.muyu.enterprise.service.CarCompanyService;
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 io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
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.*;
@ -19,17 +20,19 @@ import java.util.List;
*/ */
@RestController @RestController
@RequestMapping("/carCompany") @RequestMapping("/carCompany")
/** 构造必备注解 只有用 final 修饰 才会被构造注入 */
@RequiredArgsConstructor //制动构造注入 默认无参 Lombook包下
@Tag(name = "CarCompanyController", description = "企业表") @Tag(name = "CarCompanyController", description = "企业表")
public class CarCompanyController extends BaseController { public class CarCompanyController extends BaseController {
@Autowired private final CarCompanyService sysCarCompanyService;
private CarCompanyService sysCarCompanyService;
/** /**
* *
*/ */
@PostMapping("selectCompany") @PostMapping("selectCompany")
public Result<List<CarCompany>> selectCompany(){ public Result<List<CarCompany>> selectCompany(){
startPage();
return Result.success(sysCarCompanyService.list()); return Result.success(sysCarCompanyService.list());
} }

View File

@ -6,6 +6,7 @@ import com.muyu.enterprise.domain.CarCompany;
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 io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -23,11 +24,12 @@ import java.util.List;
*/ */
@RestController @RestController
@RequestMapping("/carConfig") @RequestMapping("/carConfig")
/** 构造必备注解 只有用 final 修饰 才会被构造注入 */
@RequiredArgsConstructor //制动构造注入 默认无参 Lombook包下
@Tag(name = "CarConfigController", description = "车辆配置") @Tag(name = "CarConfigController", description = "车辆配置")
public class CarConfigController extends BaseController { public class CarConfigController extends BaseController {
@Autowired private final CarConfigService carConfigService;
private CarConfigService carConfigService;
/** /**
* configId * configId
@ -36,6 +38,7 @@ public class CarConfigController extends BaseController {
*/ */
@PostMapping("selectByConfigId") @PostMapping("selectByConfigId")
public Result selectByConfigId(@RequestParam("configId") Long configId){ public Result selectByConfigId(@RequestParam("configId") Long configId){
startPage();
return Result.success(carConfigService.selectByConfigId(configId)); return Result.success(carConfigService.selectByConfigId(configId));
} }

View File

@ -3,6 +3,7 @@ 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.enterprise.domain.CarManage; import com.muyu.enterprise.domain.CarManage;
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;
@ -14,6 +15,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 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.*;
@ -28,13 +30,16 @@ import java.util.List;
*/ */
@RestController @RestController
@RequestMapping("/carManage") @RequestMapping("/carManage")
/** 构造必备注解 只有用 final 修饰 才会被构造注入 */
@RequiredArgsConstructor //制动构造注入 默认无参 Lombook包下
@Tag(name = "CarManageController", description = "车辆管理") @Tag(name = "CarManageController", description = "车辆管理")
public class CarManageController extends BaseController { public class CarManageController extends BaseController {
@Autowired private final CarManageCacheService carManageCacheService;
private CarCompanyService sysCarCompanyService;
@Autowired private final CarCompanyService sysCarCompanyService;
private CarManageService sysCarService;
private final CarManageService sysCarService;
/** /**
@ -44,6 +49,7 @@ public class CarManageController extends BaseController {
*/ */
@PostMapping("carListShow2") @PostMapping("carListShow2")
public Result<List<CarVO>> carListShow2(@RequestBody CarDTO carDTO){ public Result<List<CarVO>> carListShow2(@RequestBody CarDTO carDTO){
startPage();
return Result.success(sysCarService.carListShow2(carDTO)); return Result.success(sysCarService.carListShow2(carDTO));
} }
@ -82,6 +88,8 @@ public class CarManageController extends BaseController {
String key2 = RandomUtil.randomNumbers(17); String key2 = RandomUtil.randomNumbers(17);
carVO.setCarVin(key2); carVO.setCarVin(key2);
sysCarService.save(carVO); sysCarService.save(carVO);
// 存到缓存中去
carManageCacheService.put(carVO.getCarVin(),new CarManage());
return Result.success("车辆添加成功"); return Result.success("车辆添加成功");
} }

View File

@ -6,6 +6,7 @@ import com.muyu.common.core.web.controller.BaseController;
import com.muyu.enterprise.domain.CarMessage; import com.muyu.enterprise.domain.CarMessage;
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 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.*;
@ -20,10 +21,12 @@ import java.util.List;
*/ */
@RestController @RestController
@RequestMapping("/carMessage") @RequestMapping("/carMessage")
/** 构造必备注解 只有用 final 修饰 才会被构造注入 */
@RequiredArgsConstructor //制动构造注入 默认无参 Lombook包下
@Tag(name = "报文",description = "报文模块") @Tag(name = "报文",description = "报文模块")
public class CarMessageController extends BaseController { public class CarMessageController extends BaseController {
@Autowired
private CarMessageService sysCarMessageService; private final CarMessageService sysCarMessageService;
/** /**
* *
@ -31,6 +34,7 @@ public class CarMessageController extends BaseController {
*/ */
@PostMapping("selectMessageShow") @PostMapping("selectMessageShow")
public List<CarMessage> selectMessageShow(@RequestParam("templateId") Long templateId){ public List<CarMessage> selectMessageShow(@RequestParam("templateId") Long templateId){
startPage();
return sysCarMessageService.selectMessageShow(templateId); return sysCarMessageService.selectMessageShow(templateId);
} }

View File

@ -7,6 +7,7 @@ import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.enterprise.domain.CarMessageType; import com.muyu.enterprise.domain.CarMessageType;
import com.muyu.enterprise.service.CarMessageTypeService; import com.muyu.enterprise.service.CarMessageTypeService;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
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.*;
@ -21,10 +22,12 @@ import java.util.List;
*/ */
@RestController @RestController
@RequestMapping("carMessageType") @RequestMapping("carMessageType")
/** 构造必备注解 只有用 final 修饰 才会被构造注入 */
@RequiredArgsConstructor //制动构造注入 默认无参 Lombook包下
@Tag(name = "报文类型" ,description = "报文类型") @Tag(name = "报文类型" ,description = "报文类型")
public class CarMessageTypeController extends BaseController { public class CarMessageTypeController extends BaseController {
@Autowired
private CarMessageTypeService sysCarMessageTypeService; private final CarMessageTypeService sysCarMessageTypeService;
/** /**
* *
@ -32,6 +35,7 @@ public class CarMessageTypeController extends BaseController {
*/ */
@PostMapping("messageTypeList") @PostMapping("messageTypeList")
public Result messageTypeList(){ public Result messageTypeList(){
startPage();
List<CarMessageType> list = sysCarMessageTypeService.list(); List<CarMessageType> list = sysCarMessageTypeService.list();
return Result.success(list); return Result.success(list);
} }

View File

@ -5,6 +5,7 @@ import com.muyu.enterprise.service.CarTemplateService;
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 io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
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.*;
@ -18,10 +19,12 @@ import java.util.List;
*/ */
@RestController @RestController
@RequestMapping("/carTemplate") // 报文模版 @RequestMapping("/carTemplate") // 报文模版
/** 构造必备注解 只有用 final 修饰 才会被构造注入 */
@RequiredArgsConstructor //制动构造注入 默认无参 Lombook包下
@Tag(name = "模版模块",description = "报文模版模块") @Tag(name = "模版模块",description = "报文模版模块")
public class CarTemplateController extends BaseController { public class CarTemplateController extends BaseController {
@Autowired
private CarTemplateService sysCarTemplateService; private final CarTemplateService sysCarTemplateService;
/** /**
* *
@ -29,6 +32,7 @@ public class CarTemplateController extends BaseController {
*/ */
@PostMapping("selectTemplateShow") @PostMapping("selectTemplateShow")
public List<CarTemplate> selectTemplateShow(){ public List<CarTemplate> selectTemplateShow(){
startPage();
return sysCarTemplateService.selectTemplateShow(); return sysCarTemplateService.selectTemplateShow();
} }
/** /**

View File

@ -4,11 +4,14 @@ import com.muyu.common.core.domain.Result;
import com.muyu.enterprise.domain.CarType; import com.muyu.enterprise.domain.CarType;
import com.muyu.enterprise.service.CarTypeService; import com.muyu.enterprise.service.CarTypeService;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
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.*;
import java.util.List; import java.util.List;
import static com.muyu.common.core.utils.PageUtils.startPage;
/** /**
* *
* @ClassName CarController * @ClassName CarController
@ -18,11 +21,12 @@ import java.util.List;
*/ */
@RestController @RestController
@RequestMapping("/carType") @RequestMapping("/carType")
/** 构造必备注解 只有用 final 修饰 才会被构造注入 */
@RequiredArgsConstructor //制动构造注入 默认无参 Lombook包下
@Tag(name = "CarTypeController",description = "车辆类型") @Tag(name = "CarTypeController",description = "车辆类型")
public class CarTypeController { public class CarTypeController {
@Autowired private final CarTypeService carTypeService;
private CarTypeService carTypeService;
/** /**
* *
@ -30,6 +34,7 @@ public class CarTypeController {
*/ */
@GetMapping("/carTypeList") @GetMapping("/carTypeList")
private Result<List<CarType>> carTypeList() { private Result<List<CarType>> carTypeList() {
startPage();
List<CarType> carTypeList = carTypeService.list(); List<CarType> carTypeList = carTypeService.list();
return Result.success(carTypeList); return Result.success(carTypeList);
} }

View File

@ -15,6 +15,7 @@
<modules> <modules>
<module>cloud-modules-enterprise-server</module> <module>cloud-modules-enterprise-server</module>
<module>cloud-modules-enterprise-common</module> <module>cloud-modules-enterprise-common</module>
<module>cloud-modules-enterprise-cache</module>
</modules> </modules>
<description> <description>