projectInfoCache
parent
51ba9f2877
commit
6c17b06a7c
|
@ -0,0 +1,27 @@
|
|||
<?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>muyu-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-common-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>
|
||||
|
||||
<dependencies>
|
||||
<!-- common缓存-->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-redis</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,61 @@
|
|||
package com.muyu.cache;
|
||||
|
||||
/**
|
||||
* 缓存接口基类 CaChe
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/3/27
|
||||
*/
|
||||
public interface CaChe <K,V> {
|
||||
/**
|
||||
* key前缀
|
||||
* @return key前缀
|
||||
*/
|
||||
public String keyPre();
|
||||
|
||||
/**
|
||||
* 编码
|
||||
* @param key
|
||||
* @return 键
|
||||
*/
|
||||
public String encode(K key);
|
||||
|
||||
/**
|
||||
* 解码
|
||||
* @param redisKey 数据库键
|
||||
* @return ID
|
||||
*/
|
||||
public K decode(String redisKey);
|
||||
|
||||
/**
|
||||
* 通过key获取value值
|
||||
* @param key 键
|
||||
* @return 值
|
||||
*/
|
||||
public V get(K key);
|
||||
|
||||
/**
|
||||
* 缓存添加/修改
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
*/
|
||||
public void put(K key,V value);
|
||||
|
||||
/**
|
||||
* 通过键删除
|
||||
* @param key 键
|
||||
*/
|
||||
public void remove(K key);
|
||||
|
||||
/**
|
||||
* 刷新缓存时间
|
||||
* @param key 键
|
||||
*/
|
||||
public void refreshTime(K key);
|
||||
|
||||
/**
|
||||
* 刷新缓存数据
|
||||
* @param key 键
|
||||
*/
|
||||
public void refreshDate(K key);
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package com.muyu.cache.abs;
|
||||
|
||||
import com.muyu.cache.CaChe;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 缓存抽象类 CacheAbs
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/3/27
|
||||
*/
|
||||
public abstract class CacheAbs<K,V> implements CaChe<K,V> {
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
/**
|
||||
* 编码
|
||||
* @param key Id
|
||||
* @return 值
|
||||
*/
|
||||
@Override
|
||||
public String encode(K key) {
|
||||
return keyPre()+key;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过key获取value 值
|
||||
* @param key 键
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public V get(K key) {
|
||||
V value= redisService.getCacheObject(encode(key));
|
||||
if (value == null){
|
||||
value = getData(key);
|
||||
if (value == null ){
|
||||
value = defaultValue();
|
||||
}
|
||||
}
|
||||
this.put(key,value);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存添加/修改
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
*/
|
||||
@Override
|
||||
public void put(K key, V value) {
|
||||
this.redisService.setCacheObject(encode(key), value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过键删除
|
||||
* @param key 键
|
||||
*/
|
||||
@Override
|
||||
public void remove(K key) {
|
||||
this.redisService.deleteObject(encode(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新缓存
|
||||
* @param key 键
|
||||
*/
|
||||
@Override
|
||||
public void refreshTime(K key) {
|
||||
this.redisService.expire(encode(key), 60, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新缓存数据
|
||||
* @param key 键
|
||||
*/
|
||||
@Override
|
||||
public void refreshDate(K key) {
|
||||
this.put(key,getData(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* 从数据库获取数据
|
||||
* @param key ID
|
||||
* @return 缓存对象
|
||||
*/
|
||||
public abstract V getData(K key);
|
||||
|
||||
/**
|
||||
* 默认值
|
||||
*/
|
||||
public abstract V defaultValue();
|
||||
}
|
|
@ -18,6 +18,7 @@
|
|||
<module>muyu-common-datascope</module>
|
||||
<module>muyu-common-datasource</module>
|
||||
<module>muyu-common-system</module>
|
||||
<module>muyu-common-cache</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>muyu-common</artifactId>
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
<?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>muyu-product</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-product-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>
|
||||
<dependencies>
|
||||
<!--缓存基准模块-->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-cache</artifactId>
|
||||
|
||||
</dependency>
|
||||
<!--商品模块 common依赖-->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-product-common</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,53 @@
|
|||
package com.muyu.product.cache;
|
||||
|
||||
import com.muyu.cache.abs.CacheAbs;
|
||||
import com.muyu.common.core.text.Convert;
|
||||
import com.muyu.product.domain.ProjectInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 商品缓存 ProjectInfoCache
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/3/27
|
||||
*/
|
||||
@Component
|
||||
public class ProjectInfoCache extends CacheAbs<Long, ProjectInfo> {
|
||||
@Autowired
|
||||
private ProjectInfoData projectInfoData;
|
||||
|
||||
/**
|
||||
* key 前缀
|
||||
* @return key 前缀
|
||||
*/
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "project:info:";
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码
|
||||
* @param redisKey 数据库键
|
||||
* @return ID
|
||||
*/
|
||||
@Override
|
||||
public Long decode(String redisKey) {
|
||||
return Convert.toLong(redisKey.replace(keyPre(), ""),0L);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从数据库获取数据
|
||||
* @param key ID
|
||||
* @return 缓存对象
|
||||
*/
|
||||
@Override
|
||||
public ProjectInfo getData(Long key) {
|
||||
return projectInfoData.getData(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectInfo defaultValue() {
|
||||
return new ProjectInfo();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.muyu.product.cache;
|
||||
|
||||
import com.muyu.product.domain.ProjectInfo;
|
||||
|
||||
/**
|
||||
* 缓存数据获取 ProjectInfoData
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/3/27
|
||||
*/
|
||||
public interface ProjectInfoData {
|
||||
/**
|
||||
* 从数据库获取数据
|
||||
* @param key ID
|
||||
* @return 缓存对象
|
||||
*/
|
||||
public ProjectInfo getData(Long key);
|
||||
}
|
|
@ -18,6 +18,11 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!--商品模块 缓存 依赖-->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-product-cache</artifactId>
|
||||
</dependency>
|
||||
<!-- 商品模块 common 依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
|
@ -84,6 +89,18 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-swagger</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-product-cache</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-product-cache</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.product.cache;
|
||||
|
||||
import com.muyu.product.domain.ProjectInfo;
|
||||
import com.muyu.product.service.ProjectInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 缓存数据获取 ProjectInfoDataImpl
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/3/27
|
||||
*/
|
||||
@Service
|
||||
public class ProjectInfoDataImpl implements ProjectInfoData{
|
||||
@Autowired
|
||||
private ProjectInfoService projectInfoService;
|
||||
|
||||
/**
|
||||
* 从数据库获取数据
|
||||
* @param key ID
|
||||
* @return 缓存对象
|
||||
*/
|
||||
@Override
|
||||
public ProjectInfo getData(Long key){
|
||||
return projectInfoService.getById(key);
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.muyu.product.cache.ProjectInfoCache;
|
||||
import com.muyu.product.domain.AsProductAttributeInfo;
|
||||
import com.muyu.product.domain.ProjectSkuInfo;
|
||||
import com.muyu.product.domain.model.CategoryInfoSaveModel;
|
||||
|
@ -87,31 +88,50 @@ public class ProjectInfoController extends BaseController {
|
|||
public Result<ProjectDetailResp> getDetailInfo(@PathVariable("id") Long id) {
|
||||
return Result.success(projectInfoService.getDetailInfo(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品信息详细信息
|
||||
*/
|
||||
/**
|
||||
* 获取商品信息详细信息
|
||||
*/
|
||||
@ApiOperation("获取商品信息详细信息")
|
||||
@RequiresPermissions("product:info:query")
|
||||
@GetMapping(value = "/cache/{id}")
|
||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
||||
public Result<ProjectInfo> getCacheInfo(@PathVariable("id") Long id) {
|
||||
return Result.success(projectInfoService.getById(id));
|
||||
}
|
||||
@Autowired
|
||||
private ProjectInfoCache projectInfoCache;
|
||||
@ApiOperation("获取商品信息详细信息")
|
||||
@RequiresPermissions("product:info:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
||||
public Result<ProjectAddModel> getInfo(@PathVariable("id") Long id) {
|
||||
|
||||
LambdaQueryWrapper<AsProductAttributeInfo> asProductAttributeInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
asProductAttributeInfoLambdaQueryWrapper.eq(AsProductAttributeInfo::getProductId, id);
|
||||
List<AsProductAttributeInfo> list = asProductAttributeInfoService.list(asProductAttributeInfoLambdaQueryWrapper);
|
||||
|
||||
ProjectInfo projectInfo = projectInfoService.getById(id);
|
||||
LambdaQueryWrapper<ProjectSkuInfo> projectSkuInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
projectSkuInfoLambdaQueryWrapper.eq(ProjectSkuInfo::getProjectId,id);
|
||||
List<ProjectSkuInfo> projectSkuInfos = projectSkuInfoService.list(projectSkuInfoLambdaQueryWrapper);
|
||||
ProjectAddModel projectAddModel = ProjectAddModel.queryBuild(projectInfo,
|
||||
list, projectSkuInfos
|
||||
);
|
||||
projectAddModel.setId(id);
|
||||
return Result.success(projectAddModel);
|
||||
public Result<ProjectInfo> getInfo(@PathVariable("id") Long id) {
|
||||
return Result.success(projectInfoCache.get(id));
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 获取商品信息详细信息
|
||||
// */
|
||||
// @ApiOperation("获取商品信息详细信息")
|
||||
// @RequiresPermissions("product:info:query")
|
||||
// @GetMapping(value = "/{id}")
|
||||
// @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
|
||||
// public Result<ProjectAddModel> getInfo(@PathVariable("id") Long id) {
|
||||
//
|
||||
// LambdaQueryWrapper<AsProductAttributeInfo> asProductAttributeInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// asProductAttributeInfoLambdaQueryWrapper.eq(AsProductAttributeInfo::getProductId, id);
|
||||
// List<AsProductAttributeInfo> list = asProductAttributeInfoService.list(asProductAttributeInfoLambdaQueryWrapper);
|
||||
//
|
||||
// ProjectInfo projectInfo = projectInfoService.getById(id);
|
||||
// LambdaQueryWrapper<ProjectSkuInfo> projectSkuInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// projectSkuInfoLambdaQueryWrapper.eq(ProjectSkuInfo::getProjectId,id);
|
||||
// List<ProjectSkuInfo> projectSkuInfos = projectSkuInfoService.list(projectSkuInfoLambdaQueryWrapper);
|
||||
// ProjectAddModel projectAddModel = ProjectAddModel.queryBuild(projectInfo,
|
||||
// list, projectSkuInfos
|
||||
// );
|
||||
// projectAddModel.setId(id);
|
||||
// return Result.success(projectAddModel);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 新增商品信息
|
||||
*/
|
||||
|
|
|
@ -32,4 +32,6 @@ public interface ProjectInfoService extends IService<ProjectInfo> {
|
|||
boolean del(List<Long> ids);
|
||||
|
||||
ProjectDetailResp getDetailInfo(Long id);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
<module>muyu-product-common</module>
|
||||
<module>muyu-product-remote</module>
|
||||
<module>muyu-product-server</module>
|
||||
<module>muyu-product-cache</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
|
14
pom.xml
14
pom.xml
|
@ -150,6 +150,13 @@
|
|||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 缓存基准模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-cache</artifactId>
|
||||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 接口模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
|
@ -220,6 +227,13 @@
|
|||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 商品模块 缓存 依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-product-cache</artifactId>
|
||||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
|
Loading…
Reference in New Issue