day_01
yuanjunzhe 2024-03-28 14:27:55 +08:00
parent 484b5604bd
commit a433983f0d
18 changed files with 547 additions and 21 deletions

View File

@ -0,0 +1,31 @@
<?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>
<description>
muyu-common-cache缓存基准
</description>
<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,62 @@
package com.muyu.common.cache;
/**
* @author DongZl
* @description:
* @Date 2024-3-26 03:25
*/
public interface Cache <K, V> {
/**
* key
* @return key
*/
public String keyPre();
/**
*
* @param key ID
* @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 refreshData (K key);
}

View File

@ -0,0 +1,96 @@
package com.muyu.common.cache.abs;
import com.muyu.common.cache.Cache;
import com.muyu.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.concurrent.TimeUnit;
/**
* @author DongZl
* @description:
* @Date 2024-3-27 03:10
*/
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 refreshData (K key) {
this.put(key, getData(key));
}
/**
*
* @param key ID
* @return
*/
public abstract V getData(K key);
/**
*
*/
public abstract V defaultValue();
}

View File

@ -0,0 +1,43 @@
<?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>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-common-core</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>muyu-product-common</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,60 @@
package com.muyu.product.cache;
import com.muyu.common.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;
/**
* @author DongZl
* @description:
* @Date 2024-3-27 03:30
*/
@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;
/**
* @author DongZl
* @description:
* @Date 2024-3-27 03:34
*/
public interface ProjectInfoData {
/**
*
* @param key ID
* @return
*/
public ProjectInfo getData (Long key);
}

View File

@ -54,17 +54,17 @@ public class ProjectInfo extends BaseEntity {
/** 主类型 */
@Excel(name = "主类型")
@ApiModelProperty(name = "主类型", value = "主类型")
private String mianType;
private Long mianType;
/** 父类型 */
@Excel(name = "父类型")
@ApiModelProperty(name = "父类型", value = "父类型")
private String parentType;
private Long parentType;
/** 商品类型 */
@Excel(name = "商品类型")
@ApiModelProperty(name = "商品类型", value = "商品类型")
private String type;
private Long type;
/** 商品图片 */
@Excel(name = "商品图片")

View File

@ -37,15 +37,15 @@ public class ProjectAddModel extends BaseEntity {
/** 主类型 */
@ApiModelProperty(name = "主类型", value = "主类型")
private String mianType;
private Long mianType;
/** 父类型 */
@ApiModelProperty(name = "父类型", value = "父类型")
private String parentType;
private Long parentType;
/** 商品类型 */
@ApiModelProperty(name = "商品类型", value = "商品类型")
private String type;
private Long type;
/** 商品图片 */
@ApiModelProperty(name = "商品图片", value = "商品图片")

View File

@ -1,6 +1,7 @@
package com.muyu.product.domain.model;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.product.domain.AttributeInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -33,4 +34,13 @@ public class TemplateAttributeModel extends BaseEntity {
*
*/
private String code;
public static TemplateAttributeModel attributeInfoBuild(AttributeInfo attributeInfo){
return TemplateAttributeModel.builder()
.id(attributeInfo.getId())
.name(attributeInfo.getName())
.code(attributeInfo.getCode())
.build();
}
}

View File

@ -33,15 +33,15 @@ public class ProjectInfoEditReq extends BaseEntity {
/** 主类型 */
@ApiModelProperty(name = "主类型", value = "主类型")
private String mianType;
private Long mianType;
/** 父类型 */
@ApiModelProperty(name = "父类型", value = "父类型")
private String parentType;
private Long parentType;
/** 商品类型 */
@ApiModelProperty(name = "商品类型", value = "商品类型")
private String type;
private Long type;
/** 商品图片 */
@ApiModelProperty(name = "商品图片", value = "商品图片")

View File

@ -33,15 +33,15 @@ public class ProjectInfoQueryReq extends BaseEntity {
/** 主类型 */
@ApiModelProperty(name = "主类型", value = "主类型")
private String mianType;
private Long mianType;
/** 父类型 */
@ApiModelProperty(name = "父类型", value = "父类型")
private String parentType;
private Long parentType;
/** 商品类型 */
@ApiModelProperty(name = "商品类型", value = "商品类型")
private String type;
private Long type;
/** 商品图片 */
@ApiModelProperty(name = "商品图片", value = "商品图片")

View File

@ -0,0 +1,76 @@
package com.muyu.product.domain.resp;/**
* @Authoryjz
* @Packagecom.muyu.product.domain.resp
* @Projectcloud_service
* @nameProjectDetailResp
* @Date2024/3/25 17:11
*/
import com.muyu.product.domain.*;
import com.muyu.product.domain.model.RuleAttrAddModel;
import com.muyu.product.domain.model.TemplateAttributeGroupModel;
import com.muyu.product.domain.model.TemplateAttributeModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
*@ClassName ProjectDetailResp
*@Description
*@Author JunZhe.Yuan
*@Date 2024/3/25 17:11
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ProjectDetailResp {
/**
*
*/
private List<CategoryInfo> categoryInfoList;
/**
*
*/
private ProjectInfo projectInfo;
/**
*
*/
private BrandInfo brandInfo;
/**
* Sku
*/
private List<ProjectSkuInfo> projectSkuInfoList;
/**
*
*/
private List<AsProductAttributeInfo> productAttributeInfoList;
/**
*
*/
private List<RuleAttrAddModel> ruleAttrModelList;
/**
*
*/
private List<TemplateAttributeModel> attributeInfoList;
/**
*
*/
private List<TemplateAttributeGroupModel> attributeGroupList;
}

View File

@ -11,6 +11,7 @@ import com.muyu.product.domain.ProjectInfo;
import com.muyu.product.domain.req.ProjectInfoEditReq;
import com.muyu.product.domain.req.ProjectInfoQueryReq;
import com.muyu.product.domain.req.ProjectInfoSaveReq;
import com.muyu.product.domain.resp.ProjectDetailResp;
import com.muyu.product.service.ProjectInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@ -70,6 +71,19 @@ public class ProjectInfoController extends BaseController {
return Result.success(projectInfoService.getById(id));
}
/**
*
*/
@ApiOperation("获取商品信息详细信息")
@RequiresPermissions("product:info:query")
@GetMapping(value = "/detail/{id}")
@ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
public Result<ProjectDetailResp> getDetailInfo(@PathVariable("id") Long id) {
return Result.success(projectInfoService.getDetailInfo(id));
}
/**
*
*/

View File

@ -8,6 +8,7 @@ import com.muyu.product.domain.CategoryInfo;
import com.muyu.product.domain.model.CategoryInfoSaveModel;
import com.muyu.product.domain.resp.CategoryCommonElementResp;
import com.muyu.product.domain.resp.CategoryParentCommonElementResp;
import org.apache.poi.ss.formula.functions.T;
import java.util.List;
@ -67,4 +68,6 @@ public interface CategoryInfoService extends IService<CategoryInfo> {
* @return
*/
CategoryCommonElementResp getTemplateAttributeByCateGoryId (Long cateGoryId);
public <T,AS> List<T> getCommon(Long categoryId,IService<AS> iService,IService<T> bsiService);
}

View File

@ -2,7 +2,9 @@ package com.muyu.product.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.product.domain.ProjectInfo;
import com.muyu.product.domain.req.ProjectInfoEditReq;
import com.muyu.product.domain.req.ProjectInfoSaveReq;
import com.muyu.product.domain.resp.ProjectDetailResp;
import java.util.List;
@ -24,4 +26,8 @@ public interface ProjectInfoService extends IService<ProjectInfo> {
boolean save(ProjectInfoSaveReq projectInfoSaveReq);
ProjectDetailResp getDetailInfo(Long id);
}

View File

@ -4,21 +4,19 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.ObjUtils;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.product.domain.AsProductAttributeInfo;
import com.muyu.product.domain.ProjectInfo;
import com.muyu.product.domain.ProjectSkuInfo;
import com.muyu.product.domain.model.AttrValueModel;
import com.muyu.product.domain.model.ProductSkuModel;
import com.muyu.product.domain.model.ProjectAddModel;
import com.muyu.product.domain.*;
import com.muyu.product.domain.model.*;
import com.muyu.product.domain.req.ProjectInfoEditReq;
import com.muyu.product.domain.req.ProjectInfoSaveReq;
import com.muyu.product.domain.resp.CategoryCommonElementResp;
import com.muyu.product.domain.resp.ProjectDetailResp;
import com.muyu.product.mapper.ProjectInfoMapper;
import com.muyu.product.service.AsProductAttributeInfoService;
import com.muyu.product.service.ProjectInfoService;
import com.muyu.product.service.ProjectSkuInfoService;
import com.muyu.product.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
@ -37,6 +35,18 @@ public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, Proje
@Autowired
private ProjectSkuInfoService projectSkuInfoService;
@Autowired
private CategoryInfoService categoryInfoService;
@Autowired
private RuleAttrInfoService ruleAttrInfoService;
@Autowired
private BrandInfoService brandInfoService;
@Autowired
private AttributeInfoService attributeInfoService;
/**
*
*
@ -119,4 +129,99 @@ public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, Proje
return save;
}
/**
* ID
*
* @param id ID
* @return
*/
@Override
public ProjectDetailResp getDetailInfo (Long id) {
// 商品信息获取
ProjectInfo projectInfo = this.getById(id);
// 品牌信息
BrandInfo brandInfo = this.brandInfoService.getById(projectInfo.getBrandId());
// 品类集合
List<CategoryInfo> categoryInfoList = categoryInfoService.listByIds(new ArrayList<>() {{
add(projectInfo.getMianType());
add(projectInfo.getParentType());
add(projectInfo.getType());
}});
// 商品Sku集合
List<ProjectSkuInfo> projectSkuInfoList = this.projectSkuInfoService.list(new LambdaQueryWrapper<>() {{
eq(ProjectSkuInfo::getProjectId, id);
}});
// 商品和属性集合
List<AsProductAttributeInfo> productAttributeInfoList = this.asProductAttributeInfoService.list(new LambdaQueryWrapper<>() {{
eq(AsProductAttributeInfo::getProductId, id);
}});
// 商品规格
List<RuleAttrAddModel> ruleAttrModelList = ruleAttrInfoService.list(new LambdaQueryWrapper<>() {{
eq(RuleAttrInfo::getRuleId, projectInfo.getRuleId());
}}).stream()
.map(RuleAttrAddModel::infoBuild).toList();
CategoryCommonElementResp templateAttribute = this.categoryInfoService.getTemplateAttributeByCateGoryId(projectInfo.getType());
List<TemplateAttributeGroupModel> templateAttributeGroupList = templateAttribute.getTemplateAttributeGroupList();
List<TemplateAttributeModel> templateAttributeList = new ArrayList<>(){{
addAll(templateAttribute.getTemplateAttributeList());
}};
// 属性组和商品属性的ID
List<Long> notInAttributeIdList = new ArrayList<>();
List<Long> attributeGroupIdList = templateAttributeGroupList.stream()
.flatMap(templateAttributeGroupModel -> templateAttributeGroupModel.getAttributeList().stream())
.map(TemplateAttributeModel::getId)
.toList();
List<Long> attributeIdList = templateAttributeList.stream()
.map(TemplateAttributeModel::getId)
.toList();
if (!attributeGroupIdList.isEmpty()){
notInAttributeIdList.addAll( attributeGroupIdList );
}
if (!attributeIdList.isEmpty()){
notInAttributeIdList.addAll( attributeIdList );
}
// 添加上,商品的自有属性
List<AsProductAttributeInfo> productAttributeList = this.asProductAttributeInfoService.list(
new LambdaQueryWrapper<>() {{
eq(AsProductAttributeInfo::getProductId, projectInfo.getId());
if (!notInAttributeIdList.isEmpty()){
notIn(AsProductAttributeInfo::getAttributeId, notInAttributeIdList);
}
}}
);
List<TemplateAttributeModel> projectAttributeList = new ArrayList<>();
if (!productAttributeList.isEmpty()){
List<Long> attrIdList = productAttributeList.stream()
.map(AsProductAttributeInfo::getAttributeId)
.toList();
projectAttributeList = attributeInfoService.list(
new LambdaQueryWrapper<>() {{
in(AttributeInfo::getId, attrIdList);
}}
).stream()
.map(TemplateAttributeModel::attributeInfoBuild)
.toList();
}
// 把自有属性添加到商品属性的集合当中,进行合并
if (!projectAttributeList.isEmpty()){
templateAttributeList.addAll(projectAttributeList);
}
return ProjectDetailResp.builder()
.projectInfo(projectInfo)
.brandInfo(brandInfo)
.categoryInfoList(categoryInfoList)
.projectSkuInfoList(projectSkuInfoList)
.productAttributeInfoList(productAttributeInfoList)
.ruleAttrModelList(ruleAttrModelList)
.attributeInfoList(templateAttributeList)
.attributeGroupList(templateAttributeGroupList)
.build();
}
}

View File

@ -15,6 +15,7 @@
<module>muyu-product-common</module>
<module>muyu-product-remote</module>
<module>muyu-product-service</module>
<module>muyu-product-cache</module>
</modules>
<properties>

View File

@ -228,6 +228,7 @@
<module>muyu-visual</module>
<module>muyu-modules</module>
<module>muyu-common</module>
<module>muyu-common/muyu-common-cache</module>
</modules>
<packaging>pom</packaging>