projectInfoCache

master
rouchen 2024-03-27 20:41:25 +08:00
parent 51ba9f2877
commit 6c17b06a7c
13 changed files with 390 additions and 19 deletions

View File

@ -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>

View File

@ -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);
/**
* keyvalue
* @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);
}

View File

@ -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;
}
/**
* keyvalue
* @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();
}

View File

@ -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>

View File

@ -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>

View File

@ -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();
}
}

View File

@ -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);
}

View File

@ -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>

View File

@ -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);
}
}

View File

@ -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);
// }
/**
*
*/

View File

@ -32,4 +32,6 @@ public interface ProjectInfoService extends IService<ProjectInfo> {
boolean del(List<Long> ids);
ProjectDetailResp getDetailInfo(Long id);
}

View File

@ -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
View File

@ -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>