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-xxl</module>
<module>cloud-common-rabbit</module>
<module>cloud-common-cache</module>
</modules>
<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>
</dependency>
<!-- redis 缓存 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-modules-enterprise-cache</artifactId>
<version>3.6.3</version>
</dependency>
<!-- 企业业务平台 - 公共依赖 -->
<dependency>
<groupId>com.muyu</groupId>

View File

@ -6,8 +6,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
*
*
*
* @author muyu
*/
@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.web.controller.BaseController;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -19,17 +20,19 @@ import java.util.List;
*/
@RestController
@RequestMapping("/carCompany")
/** 构造必备注解 只有用 final 修饰 才会被构造注入 */
@RequiredArgsConstructor //制动构造注入 默认无参 Lombook包下
@Tag(name = "CarCompanyController", description = "企业表")
public class CarCompanyController extends BaseController {
@Autowired
private CarCompanyService sysCarCompanyService;
private final CarCompanyService sysCarCompanyService;
/**
*
*/
@PostMapping("selectCompany")
public Result<List<CarCompany>> selectCompany(){
startPage();
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.CarConfigService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -23,11 +24,12 @@ import java.util.List;
*/
@RestController
@RequestMapping("/carConfig")
/** 构造必备注解 只有用 final 修饰 才会被构造注入 */
@RequiredArgsConstructor //制动构造注入 默认无参 Lombook包下
@Tag(name = "CarConfigController", description = "车辆配置")
public class CarConfigController extends BaseController {
@Autowired
private CarConfigService carConfigService;
private final CarConfigService carConfigService;
/**
* configId
@ -36,6 +38,7 @@ public class CarConfigController extends BaseController {
*/
@PostMapping("selectByConfigId")
public Result selectByConfigId(@RequestParam("configId") Long configId){
startPage();
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.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.dto.CarDTO;
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 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.*;
@ -28,13 +30,16 @@ import java.util.List;
*/
@RestController
@RequestMapping("/carManage")
/** 构造必备注解 只有用 final 修饰 才会被构造注入 */
@RequiredArgsConstructor //制动构造注入 默认无参 Lombook包下
@Tag(name = "CarManageController", description = "车辆管理")
public class CarManageController extends BaseController {
@Autowired
private CarCompanyService sysCarCompanyService;
@Autowired
private CarManageService sysCarService;
private final CarManageCacheService carManageCacheService;
private final CarCompanyService sysCarCompanyService;
private final CarManageService sysCarService;
/**
@ -44,6 +49,7 @@ public class CarManageController extends BaseController {
*/
@PostMapping("carListShow2")
public Result<List<CarVO>> carListShow2(@RequestBody CarDTO carDTO){
startPage();
return Result.success(sysCarService.carListShow2(carDTO));
}
@ -82,6 +88,8 @@ public class CarManageController extends BaseController {
String key2 = RandomUtil.randomNumbers(17);
carVO.setCarVin(key2);
sysCarService.save(carVO);
// 存到缓存中去
carManageCacheService.put(carVO.getCarVin(),new CarManage());
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.service.CarMessageService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -20,10 +21,12 @@ import java.util.List;
*/
@RestController
@RequestMapping("/carMessage")
/** 构造必备注解 只有用 final 修饰 才会被构造注入 */
@RequiredArgsConstructor //制动构造注入 默认无参 Lombook包下
@Tag(name = "报文",description = "报文模块")
public class CarMessageController extends BaseController {
@Autowired
private CarMessageService sysCarMessageService;
private final CarMessageService sysCarMessageService;
/**
*
@ -31,6 +34,7 @@ public class CarMessageController extends BaseController {
*/
@PostMapping("selectMessageShow")
public List<CarMessage> selectMessageShow(@RequestParam("templateId") Long templateId){
startPage();
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.service.CarMessageTypeService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -21,10 +22,12 @@ import java.util.List;
*/
@RestController
@RequestMapping("carMessageType")
/** 构造必备注解 只有用 final 修饰 才会被构造注入 */
@RequiredArgsConstructor //制动构造注入 默认无参 Lombook包下
@Tag(name = "报文类型" ,description = "报文类型")
public class CarMessageTypeController extends BaseController {
@Autowired
private CarMessageTypeService sysCarMessageTypeService;
private final CarMessageTypeService sysCarMessageTypeService;
/**
*
@ -32,6 +35,7 @@ public class CarMessageTypeController extends BaseController {
*/
@PostMapping("messageTypeList")
public Result messageTypeList(){
startPage();
List<CarMessageType> list = sysCarMessageTypeService.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.web.controller.BaseController;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -18,10 +19,12 @@ import java.util.List;
*/
@RestController
@RequestMapping("/carTemplate") // 报文模版
/** 构造必备注解 只有用 final 修饰 才会被构造注入 */
@RequiredArgsConstructor //制动构造注入 默认无参 Lombook包下
@Tag(name = "模版模块",description = "报文模版模块")
public class CarTemplateController extends BaseController {
@Autowired
private CarTemplateService sysCarTemplateService;
private final CarTemplateService sysCarTemplateService;
/**
*
@ -29,6 +32,7 @@ public class CarTemplateController extends BaseController {
*/
@PostMapping("selectTemplateShow")
public List<CarTemplate> selectTemplateShow(){
startPage();
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.service.CarTypeService;
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;
import static com.muyu.common.core.utils.PageUtils.startPage;
/**
*
* @ClassName CarController
@ -18,11 +21,12 @@ import java.util.List;
*/
@RestController
@RequestMapping("/carType")
/** 构造必备注解 只有用 final 修饰 才会被构造注入 */
@RequiredArgsConstructor //制动构造注入 默认无参 Lombook包下
@Tag(name = "CarTypeController",description = "车辆类型")
public class CarTypeController {
@Autowired
private CarTypeService carTypeService;
private final CarTypeService carTypeService;
/**
*
@ -30,6 +34,7 @@ public class CarTypeController {
*/
@GetMapping("/carTypeList")
private Result<List<CarType>> carTypeList() {
startPage();
List<CarType> carTypeList = carTypeService.list();
return Result.success(carTypeList);
}

View File

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