Commit 27724e37b73dd0e894a32876c9ef064ff1611c65
1 parent
c146806b
feat(shop): 添加产品关联文章功能
- 新增产品关联文章导入接口和相关服务 - 实现产品和文章的关联逻辑- 添加文章和文章类别相关的数据结构和接口
Showing
17 changed files
with
211 additions
and
101 deletions
admin/pom.xml
@@ -36,6 +36,11 @@ | @@ -36,6 +36,11 @@ | ||
36 | <optional>true</optional> | 36 | <optional>true</optional> |
37 | </dependency> | 37 | </dependency> |
38 | <dependency> | 38 | <dependency> |
39 | + <groupId>com.alibaba</groupId> | ||
40 | + <artifactId>easyexcel</artifactId> | ||
41 | + <version>3.3.4</version> | ||
42 | + </dependency> | ||
43 | + <dependency> | ||
39 | <groupId>org.springframework.boot</groupId> | 44 | <groupId>org.springframework.boot</groupId> |
40 | <artifactId>spring-boot-starter-aop</artifactId> | 45 | <artifactId>spring-boot-starter-aop</artifactId> |
41 | </dependency> | 46 | </dependency> |
admin/src/main/java/com/canrd/shop/domain/dto/ImportProductRelatedArticle.java
0 → 100644
1 | +package com.canrd.shop.domain.dto; | ||
2 | + | ||
3 | +import com.alibaba.excel.annotation.ExcelProperty; | ||
4 | +import lombok.Data; | ||
5 | + | ||
6 | +/** | ||
7 | + * @author zgt | ||
8 | + * @project canrd-services | ||
9 | + * @description | ||
10 | + * @date 2024/11/22 | ||
11 | + */ | ||
12 | +@Data | ||
13 | +public class ImportProductRelatedArticle { | ||
14 | + @ExcelProperty("Product ID") | ||
15 | + private String productId; | ||
16 | + @ExcelProperty("Link") | ||
17 | + private String link; | ||
18 | + @ExcelProperty("Title") | ||
19 | + private String title; | ||
20 | +} |
shop/src/main/java/com/canrd/shop/common/excel/listenter/ImportRelatedArticleListener.java
0 → 100644
1 | +package com.canrd.shop.common.excel.listenter; | ||
2 | + | ||
3 | +import com.alibaba.excel.context.AnalysisContext; | ||
4 | +import com.alibaba.excel.event.AnalysisEventListener; | ||
5 | +import com.alibaba.excel.metadata.data.ReadCellData; | ||
6 | +import com.canrd.shop.module.dto.*; | ||
7 | +import com.canrd.shop.service.*; | ||
8 | +import lombok.NoArgsConstructor; | ||
9 | +import lombok.NonNull; | ||
10 | +import lombok.RequiredArgsConstructor; | ||
11 | + | ||
12 | +import java.util.HashSet; | ||
13 | +import java.util.List; | ||
14 | +import java.util.Map; | ||
15 | +import java.util.Set; | ||
16 | +import java.util.stream.Collectors; | ||
17 | + | ||
18 | +/** | ||
19 | + * @author zgt | ||
20 | + * @project canrd-services | ||
21 | + * @description | ||
22 | + * @date 2024/11/22 | ||
23 | + */ | ||
24 | +@RequiredArgsConstructor | ||
25 | +@NoArgsConstructor | ||
26 | +public class ImportRelatedArticleListener extends AnalysisEventListener<ImportProductRelatedJournal> { | ||
27 | + @NonNull | ||
28 | + private ProductService productService; | ||
29 | + @NonNull | ||
30 | + private IProductcategoryrelationService productCategoryrelationService; | ||
31 | + @NonNull | ||
32 | + private IJournalCategoryRelationService journalCategoryService; | ||
33 | + @NonNull | ||
34 | + private IJournalService journalService; | ||
35 | + @NonNull | ||
36 | + private ProductCategoryService productCategoryService; | ||
37 | + private Set<String> rootCategoryIds = new HashSet<>(); | ||
38 | + @Override | ||
39 | + public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) { | ||
40 | + List<ProductCategoryDO> list = productCategoryService.list(); | ||
41 | + Set<String> parentIds = list.stream().map(ProductCategoryDO::getParentId).collect(Collectors.toSet()); | ||
42 | + List<ProductCategoryDO> rootCate = list.stream().filter(cate -> !parentIds.contains(cate.getId())).collect(Collectors.toList()); | ||
43 | + rootCategoryIds = rootCate.stream().map(ProductCategoryDO::getId).collect(Collectors.toSet()); | ||
44 | + super.invokeHead(headMap, context); | ||
45 | + } | ||
46 | + | ||
47 | + @Override | ||
48 | + public void invoke(ImportProductRelatedJournal importProductRelatedJournal, AnalysisContext analysisContext) { | ||
49 | + String productId = importProductRelatedJournal.getProductId(); | ||
50 | + Journal journal = Journal.builder() | ||
51 | + .link(importProductRelatedJournal.getLink()) | ||
52 | + .title(importProductRelatedJournal.getTitle()) | ||
53 | + .productId(productId) | ||
54 | + .build(); | ||
55 | + journalService.save(journal); | ||
56 | + List<Productcategoryrelation> list = productCategoryrelationService.lambdaQuery() | ||
57 | + .eq(Productcategoryrelation::getProductId, productId) | ||
58 | + .in(Productcategoryrelation::getCategoryId, rootCategoryIds) | ||
59 | + .list(); | ||
60 | + List<JournalCategoryRelation> relations = list.stream().map(productcategoryrelation -> JournalCategoryRelation.builder() | ||
61 | + .journalId(journal.getId()) | ||
62 | + .categoryId(productcategoryrelation.getCategoryId()) | ||
63 | + .build()).collect(Collectors.toList()); | ||
64 | + journalCategoryService.saveBatch(relations); | ||
65 | + } | ||
66 | + | ||
67 | + @Override | ||
68 | + public void doAfterAllAnalysed(AnalysisContext analysisContext) { | ||
69 | + } | ||
70 | +} |
shop/src/main/java/com/canrd/shop/controller/ProductController.java
@@ -4,9 +4,11 @@ import cn.hutool.core.collection.CollUtil; | @@ -4,9 +4,11 @@ import cn.hutool.core.collection.CollUtil; | ||
4 | import com.alibaba.excel.EasyExcel; | 4 | import com.alibaba.excel.EasyExcel; |
5 | import com.canrd.shop.common.constant.ServerResult; | 5 | import com.canrd.shop.common.constant.ServerResult; |
6 | import com.canrd.shop.common.excel.listenter.ImportRelatedCategoryListenter; | 6 | import com.canrd.shop.common.excel.listenter.ImportRelatedCategoryListenter; |
7 | +import com.canrd.shop.common.excel.listenter.ImportRelatedArticleListener; | ||
7 | import com.canrd.shop.common.exception.BusinessException; | 8 | import com.canrd.shop.common.exception.BusinessException; |
8 | import com.canrd.shop.common.jsr303.OperateGroup; | 9 | import com.canrd.shop.common.jsr303.OperateGroup; |
9 | import com.canrd.shop.config.StaticHtmlConfig; | 10 | import com.canrd.shop.config.StaticHtmlConfig; |
11 | +import com.canrd.shop.module.dto.ImportProductRelatedJournal; | ||
10 | import com.canrd.shop.module.dto.ProductCategoryDO; | 12 | import com.canrd.shop.module.dto.ProductCategoryDO; |
11 | import com.canrd.shop.module.dto.ProductDO; | 13 | import com.canrd.shop.module.dto.ProductDO; |
12 | import com.canrd.shop.module.dto.ProductFunctionDO; | 14 | import com.canrd.shop.module.dto.ProductFunctionDO; |
@@ -14,14 +16,11 @@ import com.canrd.shop.module.vo.ImportRelatedCategoryVo; | @@ -14,14 +16,11 @@ import com.canrd.shop.module.vo.ImportRelatedCategoryVo; | ||
14 | import com.canrd.shop.module.vo.ProductCategoryQueryVO; | 16 | import com.canrd.shop.module.vo.ProductCategoryQueryVO; |
15 | import com.canrd.shop.module.vo.ProductQueryVO; | 17 | import com.canrd.shop.module.vo.ProductQueryVO; |
16 | import com.canrd.shop.module.vo.ProductVO; | 18 | import com.canrd.shop.module.vo.ProductVO; |
17 | -import com.canrd.shop.service.IEbCategorysRelationService; | ||
18 | -import com.canrd.shop.service.ProductCategoryService; | ||
19 | -import com.canrd.shop.service.ProductFunctionService; | ||
20 | -import com.canrd.shop.service.ProductService; | 19 | +import com.canrd.shop.service.*; |
21 | import freemarker.template.Configuration; | 20 | import freemarker.template.Configuration; |
22 | import freemarker.template.Template; | 21 | import freemarker.template.Template; |
23 | import freemarker.template.TemplateException; | 22 | import freemarker.template.TemplateException; |
24 | -import org.apache.catalina.Server; | 23 | +import lombok.NonNull; |
25 | import org.apache.commons.lang3.StringUtils; | 24 | import org.apache.commons.lang3.StringUtils; |
26 | import org.springframework.beans.factory.annotation.Autowired; | 25 | import org.springframework.beans.factory.annotation.Autowired; |
27 | import org.springframework.beans.factory.annotation.Value; | 26 | import org.springframework.beans.factory.annotation.Value; |
@@ -32,10 +31,7 @@ import org.springframework.web.multipart.MultipartFile; | @@ -32,10 +31,7 @@ import org.springframework.web.multipart.MultipartFile; | ||
32 | 31 | ||
33 | import javax.annotation.Resource; | 32 | import javax.annotation.Resource; |
34 | import java.io.*; | 33 | import java.io.*; |
35 | -import java.lang.reflect.Field; | ||
36 | -import java.net.URL; | ||
37 | import java.util.*; | 34 | import java.util.*; |
38 | -import java.util.stream.Stream; | ||
39 | 35 | ||
40 | /** | 36 | /** |
41 | * (Product)表控制层 | 37 | * (Product)表控制层 |
@@ -47,6 +43,12 @@ import java.util.stream.Stream; | @@ -47,6 +43,12 @@ import java.util.stream.Stream; | ||
47 | @RequestMapping("/shop/product") | 43 | @RequestMapping("/shop/product") |
48 | public class ProductController { | 44 | public class ProductController { |
49 | @Autowired | 45 | @Autowired |
46 | + private IProductcategoryrelationService productCategoryrelationService; | ||
47 | + @Autowired | ||
48 | + private IJournalCategoryRelationService journalCategoryService; | ||
49 | + @Autowired | ||
50 | + private IJournalService journalService; | ||
51 | + @Autowired | ||
50 | private Configuration freeMarkerConfig; | 52 | private Configuration freeMarkerConfig; |
51 | @Value("${spring.profiles.active}") | 53 | @Value("${spring.profiles.active}") |
52 | private String activeProfile; | 54 | private String activeProfile; |
@@ -238,5 +240,16 @@ public class ProductController { | @@ -238,5 +240,16 @@ public class ProductController { | ||
238 | return ServerResult.success(); | 240 | return ServerResult.success(); |
239 | } | 241 | } |
240 | 242 | ||
243 | + | ||
244 | + @PostMapping("importRelatedJournal") | ||
245 | + @ResponseBody | ||
246 | + public ServerResult importRelatedJournal(MultipartFile file) throws IOException { | ||
247 | + EasyExcel.read(file.getInputStream(), | ||
248 | + ImportProductRelatedJournal.class, | ||
249 | + new ImportRelatedArticleListener(productService,productCategoryrelationService,journalCategoryService,journalService,productCategoryService)) | ||
250 | + .sheet() | ||
251 | + .doRead(); | ||
252 | + return ServerResult.success(); | ||
253 | + } | ||
241 | } | 254 | } |
242 | 255 |
src/main/java/com/order/erp/mapper/ProductcategoryrelationMapper.java renamed to shop/src/main/java/com/canrd/shop/mapper/JournalCategoryRelationMapper.java
1 | -package com.order.erp.mapper; | 1 | +package com.canrd.shop.mapper; |
2 | 2 | ||
3 | -import com.order.erp.domain.model.Productcategoryrelation; | ||
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
4 | +import com.canrd.shop.module.dto.JournalCategoryRelation; | ||
5 | 5 | ||
6 | /** | 6 | /** |
7 | * <p> | 7 | * <p> |
@@ -9,8 +9,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; | @@ -9,8 +9,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
9 | * </p> | 9 | * </p> |
10 | * | 10 | * |
11 | * @author author | 11 | * @author author |
12 | - * @since 2024-11-14 | 12 | + * @since 2024-11-25 |
13 | */ | 13 | */ |
14 | -public interface ProductcategoryrelationMapper extends BaseMapper<Productcategoryrelation> { | 14 | +public interface JournalCategoryRelationMapper extends BaseMapper<JournalCategoryRelation> { |
15 | 15 | ||
16 | } | 16 | } |
src/main/java/com/order/erp/mapper/EbCategorysRelationMapper.java renamed to shop/src/main/java/com/canrd/shop/mapper/JournalMapper.java
1 | -package com.order.erp.mapper; | 1 | +package com.canrd.shop.mapper; |
2 | 2 | ||
3 | -import com.order.erp.domain.model.EbCategorysRelation; | ||
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
4 | +import com.canrd.shop.module.dto.Journal; | ||
5 | 5 | ||
6 | /** | 6 | /** |
7 | * <p> | 7 | * <p> |
@@ -9,8 +9,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; | @@ -9,8 +9,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
9 | * </p> | 9 | * </p> |
10 | * | 10 | * |
11 | * @author author | 11 | * @author author |
12 | - * @since 2024-11-14 | 12 | + * @since 2024-11-25 |
13 | */ | 13 | */ |
14 | -public interface EbCategorysRelationMapper extends BaseMapper<EbCategorysRelation> { | 14 | +public interface JournalMapper extends BaseMapper<Journal> { |
15 | 15 | ||
16 | } | 16 | } |
shop/src/main/java/com/canrd/shop/module/dto/ImportProductRelatedJournal.java
0 → 100644
1 | +package com.canrd.shop.module.dto; | ||
2 | + | ||
3 | +import com.alibaba.excel.annotation.ExcelProperty; | ||
4 | +import lombok.Data; | ||
5 | + | ||
6 | +/** | ||
7 | + * @author zgt | ||
8 | + * @project canrd-services | ||
9 | + * @description | ||
10 | + * @date 2024/11/22 | ||
11 | + */ | ||
12 | +@Data | ||
13 | +public class ImportProductRelatedJournal { | ||
14 | + @ExcelProperty("Product ID") | ||
15 | + private String productId; | ||
16 | + @ExcelProperty("Link") | ||
17 | + private String link; | ||
18 | + @ExcelProperty("Title") | ||
19 | + private String title; | ||
20 | +} |
src/main/java/com/order/erp/domain/model/Productcategoryrelation.java renamed to shop/src/main/java/com/canrd/shop/module/dto/Journal.java
1 | -package com.order.erp.domain.model; | 1 | +package com.canrd.shop.module.dto; |
2 | 2 | ||
3 | import com.baomidou.mybatisplus.annotation.TableName; | 3 | import com.baomidou.mybatisplus.annotation.TableName; |
4 | import com.baomidou.mybatisplus.annotation.IdType; | 4 | import com.baomidou.mybatisplus.annotation.IdType; |
5 | -import java.time.LocalDateTime; | ||
6 | import com.baomidou.mybatisplus.annotation.TableId; | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
7 | import java.io.Serializable; | 6 | import java.io.Serializable; |
8 | -import io.swagger.annotations.ApiModel; | ||
9 | -import io.swagger.annotations.ApiModelProperty; | 7 | + |
8 | +import lombok.AllArgsConstructor; | ||
10 | import lombok.Data; | 9 | import lombok.Data; |
11 | import lombok.EqualsAndHashCode; | 10 | import lombok.EqualsAndHashCode; |
11 | +import lombok.NoArgsConstructor; | ||
12 | import lombok.experimental.Accessors; | 12 | import lombok.experimental.Accessors; |
13 | +import lombok.experimental.SuperBuilder; | ||
13 | 14 | ||
14 | /** | 15 | /** |
15 | * <p> | 16 | * <p> |
@@ -17,22 +18,25 @@ import lombok.experimental.Accessors; | @@ -17,22 +18,25 @@ import lombok.experimental.Accessors; | ||
17 | * </p> | 18 | * </p> |
18 | * | 19 | * |
19 | * @author author | 20 | * @author author |
20 | - * @since 2024-11-14 | 21 | + * @since 2024-11-25 |
21 | */ | 22 | */ |
22 | @Data | 23 | @Data |
23 | @EqualsAndHashCode(callSuper = false) | 24 | @EqualsAndHashCode(callSuper = false) |
24 | -@Accessors(chain = true) | ||
25 | -@TableName("productcategoryrelation") | ||
26 | -@ApiModel(value="Productcategoryrelation对象", description="") | ||
27 | -public class Productcategoryrelation implements Serializable { | 25 | +@SuperBuilder |
26 | +@AllArgsConstructor | ||
27 | +@NoArgsConstructor | ||
28 | +@TableName("journal") | ||
29 | +public class Journal implements Serializable { | ||
28 | 30 | ||
29 | private static final long serialVersionUID = 1L; | 31 | private static final long serialVersionUID = 1L; |
30 | 32 | ||
31 | - private String productId; | 33 | + @TableId(value = "id", type = IdType.AUTO) |
34 | + private Long id; | ||
32 | 35 | ||
33 | - private String categoryId; | 36 | + private String link; |
34 | 37 | ||
35 | - private LocalDateTime modifyDate; | 38 | + private String productId; |
36 | 39 | ||
40 | + private String title; | ||
37 | 41 | ||
38 | } | 42 | } |
src/main/java/com/order/erp/domain/model/EbCategorysRelation.java renamed to shop/src/main/java/com/canrd/shop/module/dto/JournalCategoryRelation.java
1 | -package com.order.erp.domain.model; | 1 | +package com.canrd.shop.module.dto; |
2 | 2 | ||
3 | import com.baomidou.mybatisplus.annotation.TableName; | 3 | import com.baomidou.mybatisplus.annotation.TableName; |
4 | import com.baomidou.mybatisplus.annotation.IdType; | 4 | import com.baomidou.mybatisplus.annotation.IdType; |
5 | import com.baomidou.mybatisplus.annotation.TableId; | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
6 | import java.io.Serializable; | 6 | import java.io.Serializable; |
7 | -import io.swagger.annotations.ApiModel; | ||
8 | -import io.swagger.annotations.ApiModelProperty; | 7 | + |
8 | +import lombok.AllArgsConstructor; | ||
9 | import lombok.Data; | 9 | import lombok.Data; |
10 | import lombok.EqualsAndHashCode; | 10 | import lombok.EqualsAndHashCode; |
11 | +import lombok.NoArgsConstructor; | ||
11 | import lombok.experimental.Accessors; | 12 | import lombok.experimental.Accessors; |
13 | +import lombok.experimental.SuperBuilder; | ||
12 | 14 | ||
13 | /** | 15 | /** |
14 | * <p> | 16 | * <p> |
@@ -16,29 +18,24 @@ import lombok.experimental.Accessors; | @@ -16,29 +18,24 @@ import lombok.experimental.Accessors; | ||
16 | * </p> | 18 | * </p> |
17 | * | 19 | * |
18 | * @author author | 20 | * @author author |
19 | - * @since 2024-11-14 | 21 | + * @since 2024-11-25 |
20 | */ | 22 | */ |
21 | @Data | 23 | @Data |
22 | @EqualsAndHashCode(callSuper = false) | 24 | @EqualsAndHashCode(callSuper = false) |
23 | -@Accessors(chain = true) | ||
24 | -@TableName("eb_categorys_relation") | ||
25 | -@ApiModel(value="EbCategorysRelation对象", description="") | ||
26 | -public class EbCategorysRelation implements Serializable { | 25 | +@SuperBuilder |
26 | +@AllArgsConstructor | ||
27 | +@NoArgsConstructor | ||
28 | +@TableName("journal_category_relation") | ||
29 | +public class JournalCategoryRelation implements Serializable { | ||
27 | 30 | ||
28 | private static final long serialVersionUID = 1L; | 31 | private static final long serialVersionUID = 1L; |
29 | 32 | ||
30 | @TableId(value = "id", type = IdType.AUTO) | 33 | @TableId(value = "id", type = IdType.AUTO) |
31 | private Long id; | 34 | private Long id; |
32 | 35 | ||
33 | - private String categoryName; | ||
34 | - | ||
35 | - private String relatedCategoryName; | ||
36 | - | ||
37 | - private Integer categoryId; | ||
38 | - | ||
39 | - private Integer relatedCategoryId; | 36 | + private Long journalId; |
40 | 37 | ||
41 | - private Integer relevance; | 38 | + private String categoryId; |
42 | 39 | ||
43 | 40 | ||
44 | } | 41 | } |
shop/src/main/java/com/canrd/shop/module/vo/ProductVO.java
1 | package com.canrd.shop.module.vo; | 1 | package com.canrd.shop.module.vo; |
2 | 2 | ||
3 | +import com.canrd.shop.module.dto.Journal; | ||
3 | import lombok.*; | 4 | import lombok.*; |
4 | import lombok.experimental.SuperBuilder; | 5 | import lombok.experimental.SuperBuilder; |
5 | 6 | ||
@@ -145,4 +146,6 @@ public class ProductVO implements Serializable { | @@ -145,4 +146,6 @@ public class ProductVO implements Serializable { | ||
145 | 146 | ||
146 | private List<String> RelatedProductIds; | 147 | private List<String> RelatedProductIds; |
147 | 148 | ||
149 | + private List<Journal> journals; | ||
150 | + | ||
148 | } | 151 | } |
src/main/java/com/order/erp/service/IProductcategoryrelationService.java renamed to shop/src/main/java/com/canrd/shop/service/IJournalCategoryRelationService.java
1 | -package com.order.erp.service; | 1 | +package com.canrd.shop.service; |
2 | 2 | ||
3 | -import com.order.erp.domain.model.Productcategoryrelation; | ||
4 | import com.baomidou.mybatisplus.extension.service.IService; | 3 | import com.baomidou.mybatisplus.extension.service.IService; |
4 | +import com.canrd.shop.module.dto.JournalCategoryRelation; | ||
5 | 5 | ||
6 | /** | 6 | /** |
7 | * <p> | 7 | * <p> |
@@ -9,8 +9,8 @@ import com.baomidou.mybatisplus.extension.service.IService; | @@ -9,8 +9,8 @@ import com.baomidou.mybatisplus.extension.service.IService; | ||
9 | * </p> | 9 | * </p> |
10 | * | 10 | * |
11 | * @author author | 11 | * @author author |
12 | - * @since 2024-11-14 | 12 | + * @since 2024-11-25 |
13 | */ | 13 | */ |
14 | -public interface IProductcategoryrelationService extends IService<Productcategoryrelation> { | 14 | +public interface IJournalCategoryRelationService extends IService<JournalCategoryRelation> { |
15 | 15 | ||
16 | } | 16 | } |
src/main/java/com/order/erp/service/IEbCategorysRelationService.java renamed to shop/src/main/java/com/canrd/shop/service/IJournalService.java
1 | -package com.order.erp.service; | 1 | +package com.canrd.shop.service; |
2 | 2 | ||
3 | -import com.order.erp.domain.model.EbCategorysRelation; | ||
4 | import com.baomidou.mybatisplus.extension.service.IService; | 3 | import com.baomidou.mybatisplus.extension.service.IService; |
4 | +import com.canrd.shop.module.dto.Journal; | ||
5 | 5 | ||
6 | /** | 6 | /** |
7 | * <p> | 7 | * <p> |
@@ -9,8 +9,8 @@ import com.baomidou.mybatisplus.extension.service.IService; | @@ -9,8 +9,8 @@ import com.baomidou.mybatisplus.extension.service.IService; | ||
9 | * </p> | 9 | * </p> |
10 | * | 10 | * |
11 | * @author author | 11 | * @author author |
12 | - * @since 2024-11-14 | 12 | + * @since 2024-11-25 |
13 | */ | 13 | */ |
14 | -public interface IEbCategorysRelationService extends IService<EbCategorysRelation> { | 14 | +public interface IJournalService extends IService<Journal> { |
15 | 15 | ||
16 | } | 16 | } |
src/main/java/com/order/erp/service/impl/ProductcategoryrelationServiceImpl.java renamed to shop/src/main/java/com/canrd/shop/service/impl/JournalCategoryRelationServiceImpl.java
1 | -package com.order.erp.service.impl; | 1 | +package com.canrd.shop.service.impl; |
2 | 2 | ||
3 | -import com.order.erp.domain.model.Productcategoryrelation; | ||
4 | -import com.order.erp.mapper.ProductcategoryrelationMapper; | ||
5 | -import com.order.erp.service.IProductcategoryrelationService; | ||
6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
4 | +import com.canrd.shop.mapper.JournalCategoryRelationMapper; | ||
5 | +import com.canrd.shop.module.dto.JournalCategoryRelation; | ||
6 | +import com.canrd.shop.service.IJournalCategoryRelationService; | ||
7 | import org.springframework.stereotype.Service; | 7 | import org.springframework.stereotype.Service; |
8 | 8 | ||
9 | /** | 9 | /** |
@@ -12,9 +12,9 @@ import org.springframework.stereotype.Service; | @@ -12,9 +12,9 @@ import org.springframework.stereotype.Service; | ||
12 | * </p> | 12 | * </p> |
13 | * | 13 | * |
14 | * @author author | 14 | * @author author |
15 | - * @since 2024-11-14 | 15 | + * @since 2024-11-25 |
16 | */ | 16 | */ |
17 | @Service | 17 | @Service |
18 | -public class ProductcategoryrelationServiceImpl extends ServiceImpl<ProductcategoryrelationMapper, Productcategoryrelation> implements IProductcategoryrelationService { | 18 | +public class JournalCategoryRelationServiceImpl extends ServiceImpl<JournalCategoryRelationMapper, JournalCategoryRelation> implements IJournalCategoryRelationService { |
19 | 19 | ||
20 | } | 20 | } |
src/main/java/com/order/erp/service/impl/EbCategorysRelationServiceImpl.java renamed to shop/src/main/java/com/canrd/shop/service/impl/JournalServiceImpl.java
1 | -package com.order.erp.service.impl; | 1 | +package com.canrd.shop.service.impl; |
2 | 2 | ||
3 | -import com.order.erp.domain.model.EbCategorysRelation; | ||
4 | -import com.order.erp.mapper.EbCategorysRelationMapper; | ||
5 | -import com.order.erp.service.IEbCategorysRelationService; | 3 | +import com.canrd.shop.module.dto.Journal; |
4 | +import com.canrd.shop.service.IJournalService; | ||
6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 5 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
6 | +import com.canrd.shop.mapper.JournalMapper; | ||
7 | import org.springframework.stereotype.Service; | 7 | import org.springframework.stereotype.Service; |
8 | 8 | ||
9 | /** | 9 | /** |
@@ -12,9 +12,9 @@ import org.springframework.stereotype.Service; | @@ -12,9 +12,9 @@ import org.springframework.stereotype.Service; | ||
12 | * </p> | 12 | * </p> |
13 | * | 13 | * |
14 | * @author author | 14 | * @author author |
15 | - * @since 2024-11-14 | 15 | + * @since 2024-11-25 |
16 | */ | 16 | */ |
17 | @Service | 17 | @Service |
18 | -public class EbCategorysRelationServiceImpl extends ServiceImpl<EbCategorysRelationMapper, EbCategorysRelation> implements IEbCategorysRelationService { | 18 | +public class JournalServiceImpl extends ServiceImpl<JournalMapper, Journal> implements IJournalService { |
19 | 19 | ||
20 | } | 20 | } |
shop/src/main/java/com/canrd/shop/service/impl/ProductServiceImpl.java
@@ -77,6 +77,11 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im | @@ -77,6 +77,11 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im | ||
77 | @Autowired | 77 | @Autowired |
78 | private IEbCategorysRelationService ebCategorysRelationService; | 78 | private IEbCategorysRelationService ebCategorysRelationService; |
79 | 79 | ||
80 | + @Autowired | ||
81 | + private IJournalCategoryRelationService journalCategoryService; | ||
82 | + @Autowired | ||
83 | + private IJournalService journalService; | ||
84 | + | ||
80 | /** | 85 | /** |
81 | * 通过ID查询单条数据 | 86 | * 通过ID查询单条数据 |
82 | * <p> | 87 | * <p> |
@@ -144,9 +149,11 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im | @@ -144,9 +149,11 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im | ||
144 | StringJoiner orderByJoiner = new StringJoiner(" when "," order by case pc.id when "," else 0 end "); | 149 | StringJoiner orderByJoiner = new StringJoiner(" when "," order by case pc.id when "," else 0 end "); |
145 | cateId2Relevance.forEach((k,v)->orderByJoiner.add("'"+k+"'"+" then "+v)); | 150 | cateId2Relevance.forEach((k,v)->orderByJoiner.add("'"+k+"'"+" then "+v)); |
146 | QueryWrapper<ProductDO> objectQueryWrapper = new QueryWrapper<ProductDO>() | 151 | QueryWrapper<ProductDO> objectQueryWrapper = new QueryWrapper<ProductDO>() |
152 | + .eq("ismarketable",true) | ||
147 | .in("pc.id", cateId2Relevance.keySet()) | 153 | .in("pc.id", cateId2Relevance.keySet()) |
148 | .select("distinct p.id","pc.id") | 154 | .select("distinct p.id","pc.id") |
149 | .last(orderByJoiner.toString()); | 155 | .last(orderByJoiner.toString()); |
156 | + | ||
150 | List<ProductDO> relatedProducts = this | 157 | List<ProductDO> relatedProducts = this |
151 | .list(objectQueryWrapper); | 158 | .list(objectQueryWrapper); |
152 | List<String> relatedProductIds = relatedProducts.stream() | 159 | List<String> relatedProductIds = relatedProducts.stream() |
@@ -156,6 +163,14 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im | @@ -156,6 +163,14 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im | ||
156 | .collect(Collectors.toList()); | 163 | .collect(Collectors.toList()); |
157 | productVO.setRelatedProductIds(relatedProductIds); | 164 | productVO.setRelatedProductIds(relatedProductIds); |
158 | 165 | ||
166 | + List<JournalCategoryRelation> journalCategoryRelations = journalCategoryService.lambdaQuery() | ||
167 | + .in(JournalCategoryRelation::getCategoryId, categoryIds) | ||
168 | + .list(); | ||
169 | + List<Long> journalIds = journalCategoryRelations.stream().map(JournalCategoryRelation::getJournalId).collect(Collectors.toList()); | ||
170 | + List<Journal> journals = journalService.lambdaQuery() | ||
171 | + .in(Journal::getId, journalIds) | ||
172 | + .page(new Page<>(1,10)).getRecords(); | ||
173 | + productVO.setJournals(journals); | ||
159 | productVO.setPriceShow(productPriceShow); | 174 | productVO.setPriceShow(productPriceShow); |
160 | 175 | ||
161 | 176 |
src/main/resources/mapper/EbCategorysRelationMapper.xml deleted
100644 → 0
1 | -<?xml version="1.0" encoding="UTF-8"?> | ||
2 | -<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
3 | -<mapper namespace="com.order.erp.mapper.EbCategorysRelationMapper"> | ||
4 | - | ||
5 | - <!-- 通用查询映射结果 --> | ||
6 | - <resultMap id="BaseResultMap" type="com.order.erp.domain.model.EbCategorysRelation"> | ||
7 | - <id column="id" property="id" /> | ||
8 | - <result column="category_name" property="categoryName" /> | ||
9 | - <result column="related_category_name" property="relatedCategoryName" /> | ||
10 | - <result column="category_id" property="categoryId" /> | ||
11 | - <result column="related_category_id" property="relatedCategoryId" /> | ||
12 | - <result column="relevance" property="relevance" /> | ||
13 | - </resultMap> | ||
14 | - | ||
15 | - <!-- 通用查询结果列 --> | ||
16 | - <sql id="Base_Column_List"> | ||
17 | - id, category_name, related_category_name, category_id, related_category_id, relevance | ||
18 | - </sql> | ||
19 | - | ||
20 | -</mapper> |
src/main/resources/mapper/ProductcategoryrelationMapper.xml deleted
100644 → 0
1 | -<?xml version="1.0" encoding="UTF-8"?> | ||
2 | -<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
3 | -<mapper namespace="com.order.erp.mapper.ProductcategoryrelationMapper"> | ||
4 | - | ||
5 | - <!-- 通用查询映射结果 --> | ||
6 | - <resultMap id="BaseResultMap" type="com.order.erp.domain.model.Productcategoryrelation"> | ||
7 | - <result column="productId" property="productId" /> | ||
8 | - <result column="categoryId" property="categoryId" /> | ||
9 | - <result column="modifyDate" property="modifyDate" /> | ||
10 | - </resultMap> | ||
11 | - | ||
12 | - <!-- 通用查询结果列 --> | ||
13 | - <sql id="Base_Column_List"> | ||
14 | - productId, categoryId, modifyDate | ||
15 | - </sql> | ||
16 | - | ||
17 | -</mapper> |