Commit a11d5dc5f10a1e3e00f9f6e20dd2146f7556b193

Authored by YunaiV
1 parent c463f831

🔨 CRM:优化产品代码的实现

Showing 22 changed files with 252 additions and 324 deletions
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/DictTypeConstants.java
@@ -7,10 +7,11 @@ package cn.iocoder.yudao.module.crm.enums; @@ -7,10 +7,11 @@ package cn.iocoder.yudao.module.crm.enums;
7 */ 7 */
8 public interface DictTypeConstants { 8 public interface DictTypeConstants {
9 9
10 - // ========== CRM 模块 ==========  
11 String CRM_CUSTOMER_INDUSTRY = "crm_customer_industry"; // CRM 客户所属行业 10 String CRM_CUSTOMER_INDUSTRY = "crm_customer_industry"; // CRM 客户所属行业
12 String CRM_CUSTOMER_LEVEL = "crm_customer_level"; // CRM 客户等级 11 String CRM_CUSTOMER_LEVEL = "crm_customer_level"; // CRM 客户等级
13 String CRM_CUSTOMER_SOURCE = "crm_customer_source"; // CRM 客户来源 12 String CRM_CUSTOMER_SOURCE = "crm_customer_source"; // CRM 客户来源
14 String CRM_AUDIT_STATUS = "crm_audit_status"; // CRM 审批状态 13 String CRM_AUDIT_STATUS = "crm_audit_status"; // CRM 审批状态
  14 + String CRM_PRODUCT_UNIT = "crm_product_unit"; // CRM 产品单位
  15 + String CRM_PRODUCT_STATUS = "crm_product_status"; // CRM 产品状态
15 16
16 } 17 }
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
@@ -50,18 +50,16 @@ public interface ErrorCodeConstants { @@ -50,18 +50,16 @@ public interface ErrorCodeConstants {
50 ErrorCode CRM_PERMISSION_DELETE_SELF_PERMISSION_FAIL_EXIST_OWNER = new ErrorCode(1_020_007_007, "删除数据权限失败,原因:不能删除负责人"); 50 ErrorCode CRM_PERMISSION_DELETE_SELF_PERMISSION_FAIL_EXIST_OWNER = new ErrorCode(1_020_007_007, "删除数据权限失败,原因:不能删除负责人");
51 51
52 // ========== 产品 1_020_008_000 ========== 52 // ========== 产品 1_020_008_000 ==========
53 - ErrorCode CRM_PRODUCT_NOT_EXISTS = new ErrorCode(1_020_008_000, "产品不存在");  
54 - ErrorCode CRM_PRODUCT_NO_EXISTS = new ErrorCode(1_020_008_001, "产品编号已存在"); 53 + ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_020_008_000, "产品不存在");
  54 + ErrorCode PRODUCT_NO_EXISTS = new ErrorCode(1_020_008_001, "产品编号已存在");
55 55
56 // ========== 产品分类 1_020_009_000 ========== 56 // ========== 产品分类 1_020_009_000 ==========
57 - ErrorCode CRM_PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_020_009_000, "产品分类不存在");  
58 - ErrorCode CRM_PRODUCT_CATEGORY_EXISTS = new ErrorCode(1_020_009_001, "产品分类已存在");  
59 -  
60 - ErrorCode CRM_PRODUCT_CATEGORY_USED = new ErrorCode(1_020_009_002, "产品分类已关联产品");  
61 -  
62 - ErrorCode CRM_CATEGORY_PARENT_NOT_EXISTS = new ErrorCode(1_020_009_003, "父分类不存在");  
63 - ErrorCode CRM_CATEGORY_PARENT_NOT_FIRST_LEVEL = new ErrorCode(1_020_009_004, "父分类不能是二级分类");  
64 - ErrorCode CRM_CATEGORY_EXISTS_CHILDREN = new ErrorCode(1_020_009_005, "存在子分类,无法删除"); 57 + ErrorCode PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_020_009_000, "产品分类不存在");
  58 + ErrorCode PRODUCT_CATEGORY_EXISTS = new ErrorCode(1_020_009_001, "产品分类已存在");
  59 + ErrorCode PRODUCT_CATEGORY_USED = new ErrorCode(1_020_009_002, "产品分类已关联产品");
  60 + ErrorCode PRODUCT_CATEGORY_PARENT_NOT_EXISTS = new ErrorCode(1_020_009_003, "父分类不存在");
  61 + ErrorCode PRODUCT_CATEGORY_PARENT_NOT_FIRST_LEVEL = new ErrorCode(1_020_009_004, "父分类不能是二级分类");
  62 + ErrorCode product_CATEGORY_EXISTS_CHILDREN = new ErrorCode(1_020_009_005, "存在子分类,无法删除");
65 63
66 // ========== 商机状态类型 1_020_010_000 ========== 64 // ========== 商机状态类型 1_020_010_000 ==========
67 ErrorCode BUSINESS_STATUS_TYPE_NOT_EXISTS = new ErrorCode(1_020_010_000, "商机状态类型不存在"); 65 ErrorCode BUSINESS_STATUS_TYPE_NOT_EXISTS = new ErrorCode(1_020_010_000, "商机状态类型不存在");
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/common/CrmBizTypeEnum.java
@@ -21,7 +21,9 @@ public enum CrmBizTypeEnum implements IntArrayValuable { @@ -21,7 +21,9 @@ public enum CrmBizTypeEnum implements IntArrayValuable {
21 CRM_CUSTOMER(2, "客户"), 21 CRM_CUSTOMER(2, "客户"),
22 CRM_CONTACT(3, "联系人"), 22 CRM_CONTACT(3, "联系人"),
23 CRM_BUSINESS(4, "商机"), 23 CRM_BUSINESS(4, "商机"),
24 - CRM_CONTRACT(5, "合同"); 24 + CRM_CONTRACT(5, "合同"),
  25 + CRM_PRODUCT(6, "产品")
  26 + ;
25 27
26 public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CrmBizTypeEnum::getType).toArray(); 28 public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CrmBizTypeEnum::getType).toArray();
27 29
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/product/CrmProductStatusEnum.java
@@ -7,12 +7,15 @@ import lombok.Getter; @@ -7,12 +7,15 @@ import lombok.Getter;
7 import java.util.Arrays; 7 import java.util.Arrays;
8 8
9 /** 9 /**
  10 + * CRM 商品状态
  11 + *
10 * @author ZanGe丶 12 * @author ZanGe丶
11 - * @create 2023-11-30 21:53 13 + * @since 2023-11-30 21:53
12 */ 14 */
13 @Getter 15 @Getter
14 @AllArgsConstructor 16 @AllArgsConstructor
15 public enum CrmProductStatusEnum implements IntArrayValuable { 17 public enum CrmProductStatusEnum implements IntArrayValuable {
  18 +
16 DISABLE(0, "下架"), 19 DISABLE(0, "下架"),
17 ENABLE(1, "上架"); 20 ENABLE(1, "上架");
18 21
@@ -32,13 +35,4 @@ public enum CrmProductStatusEnum implements IntArrayValuable { @@ -32,13 +35,4 @@ public enum CrmProductStatusEnum implements IntArrayValuable {
32 return ARRAYS; 35 return ARRAYS;
33 } 36 }
34 37
35 - /**  
36 - * 判断是否处于【上架】状态  
37 - *  
38 - * @param status 状态  
39 - * @return 是否处于【上架】状态  
40 - */  
41 - public static boolean isEnable(Integer status) {  
42 - return ENABLE.getStatus().equals(status);  
43 - }  
44 } 38 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/CrmProductController.java
1 package cn.iocoder.yudao.module.crm.controller.admin.product; 1 package cn.iocoder.yudao.module.crm.controller.admin.product;
2 2
  3 +import cn.hutool.core.collection.CollUtil;
3 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  7 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
5 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; 8 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
6 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; 9 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
7 -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.*; 10 +import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO;
  11 +import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductRespVO;
  12 +import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductSaveReqVO;
8 import cn.iocoder.yudao.module.crm.convert.product.CrmProductConvert; 13 import cn.iocoder.yudao.module.crm.convert.product.CrmProductConvert;
  14 +import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO;
9 import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO; 15 import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
  16 +import cn.iocoder.yudao.module.crm.service.product.CrmProductCategoryService;
10 import cn.iocoder.yudao.module.crm.service.product.CrmProductService; 17 import cn.iocoder.yudao.module.crm.service.product.CrmProductService;
  18 +import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
  19 +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
11 import io.swagger.v3.oas.annotations.Operation; 20 import io.swagger.v3.oas.annotations.Operation;
12 import io.swagger.v3.oas.annotations.Parameter; 21 import io.swagger.v3.oas.annotations.Parameter;
13 import io.swagger.v3.oas.annotations.tags.Tag; 22 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -19,12 +28,17 @@ import javax.annotation.Resource; @@ -19,12 +28,17 @@ import javax.annotation.Resource;
19 import javax.servlet.http.HttpServletResponse; 28 import javax.servlet.http.HttpServletResponse;
20 import javax.validation.Valid; 29 import javax.validation.Valid;
21 import java.io.IOException; 30 import java.io.IOException;
  31 +import java.util.Collections;
22 import java.util.List; 32 import java.util.List;
  33 +import java.util.Map;
  34 +import java.util.stream.Stream;
23 35
24 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 36 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  37 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
  38 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap;
25 import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; 39 import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
26 40
27 -@Tag(name = "管理后台 - 产品") 41 +@Tag(name = "管理后台 - CRM 产品")
28 @RestController 42 @RestController
29 @RequestMapping("/crm/product") 43 @RequestMapping("/crm/product")
30 @Validated 44 @Validated
@@ -32,18 +46,23 @@ public class CrmProductController { @@ -32,18 +46,23 @@ public class CrmProductController {
32 46
33 @Resource 47 @Resource
34 private CrmProductService productService; 48 private CrmProductService productService;
  49 + @Resource
  50 + private CrmProductCategoryService productCategoryService;
  51 +
  52 + @Resource
  53 + private AdminUserApi adminUserApi;
35 54
36 @PostMapping("/create") 55 @PostMapping("/create")
37 @Operation(summary = "创建产品") 56 @Operation(summary = "创建产品")
38 @PreAuthorize("@ss.hasPermission('crm:product:create')") 57 @PreAuthorize("@ss.hasPermission('crm:product:create')")
39 - public CommonResult<Long> createProduct(@Valid @RequestBody CrmProductCreateReqVO createReqVO) { 58 + public CommonResult<Long> createProduct(@Valid @RequestBody CrmProductSaveReqVO createReqVO) {
40 return success(productService.createProduct(createReqVO)); 59 return success(productService.createProduct(createReqVO));
41 } 60 }
42 61
43 @PutMapping("/update") 62 @PutMapping("/update")
44 @Operation(summary = "更新产品") 63 @Operation(summary = "更新产品")
45 @PreAuthorize("@ss.hasPermission('crm:product:update')") 64 @PreAuthorize("@ss.hasPermission('crm:product:update')")
46 - public CommonResult<Boolean> updateProduct(@Valid @RequestBody CrmProductUpdateReqVO updateReqVO) { 65 + public CommonResult<Boolean> updateProduct(@Valid @RequestBody CrmProductSaveReqVO updateReqVO) {
47 productService.updateProduct(updateReqVO); 66 productService.updateProduct(updateReqVO);
48 return success(true); 67 return success(true);
49 } 68 }
@@ -63,7 +82,7 @@ public class CrmProductController { @@ -63,7 +82,7 @@ public class CrmProductController {
63 @PreAuthorize("@ss.hasPermission('crm:product:query')") 82 @PreAuthorize("@ss.hasPermission('crm:product:query')")
64 public CommonResult<CrmProductRespVO> getProduct(@RequestParam("id") Long id) { 83 public CommonResult<CrmProductRespVO> getProduct(@RequestParam("id") Long id) {
65 CrmProductDO product = productService.getProduct(id); 84 CrmProductDO product = productService.getProduct(id);
66 - return success(CrmProductConvert.INSTANCE.convert(product)); 85 + return success(BeanUtils.toBean(product, CrmProductRespVO.class));
67 } 86 }
68 87
69 @GetMapping("/page") 88 @GetMapping("/page")
@@ -71,19 +90,31 @@ public class CrmProductController { @@ -71,19 +90,31 @@ public class CrmProductController {
71 @PreAuthorize("@ss.hasPermission('crm:product:query')") 90 @PreAuthorize("@ss.hasPermission('crm:product:query')")
72 public CommonResult<PageResult<CrmProductRespVO>> getProductPage(@Valid CrmProductPageReqVO pageVO) { 91 public CommonResult<PageResult<CrmProductRespVO>> getProductPage(@Valid CrmProductPageReqVO pageVO) {
73 PageResult<CrmProductDO> pageResult = productService.getProductPage(pageVO); 92 PageResult<CrmProductDO> pageResult = productService.getProductPage(pageVO);
74 - return success(CrmProductConvert.INSTANCE.convertPage(pageResult)); 93 + return success(new PageResult<>(getProductDetailList(pageResult.getList()), pageResult.getTotal()));
75 } 94 }
76 95
77 @GetMapping("/export-excel") 96 @GetMapping("/export-excel")
78 @Operation(summary = "导出产品 Excel") 97 @Operation(summary = "导出产品 Excel")
79 @PreAuthorize("@ss.hasPermission('crm:product:export')") 98 @PreAuthorize("@ss.hasPermission('crm:product:export')")
80 @OperateLog(type = EXPORT) 99 @OperateLog(type = EXPORT)
81 - public void exportProductExcel(@Valid CrmProductExportReqVO exportReqVO, 100 + public void exportProductExcel(@Valid CrmProductPageReqVO exportReqVO,
82 HttpServletResponse response) throws IOException { 101 HttpServletResponse response) throws IOException {
83 - List<CrmProductDO> list = productService.getProductList(exportReqVO); 102 + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
  103 + List<CrmProductDO> list = productService.getProductPage(exportReqVO).getList();
84 // 导出 Excel 104 // 导出 Excel
85 - List<CrmProductExcelVO> datas = CrmProductConvert.INSTANCE.convertList02(list);  
86 - ExcelUtils.write(response, "产品.xls", "数据", CrmProductExcelVO.class, datas); 105 + ExcelUtils.write(response, "产品.xls", "数据", CrmProductRespVO.class,
  106 + getProductDetailList(list));
  107 + }
  108 +
  109 + private List<CrmProductRespVO> getProductDetailList(List<CrmProductDO> list) {
  110 + if (CollUtil.isEmpty(list)) {
  111 + return Collections.emptyList();
  112 + }
  113 + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
  114 + convertSetByFlatMap(list, user -> Stream.of(Long.valueOf(user.getCreator()), user.getOwnerUserId())));
  115 + List<CrmProductCategoryDO> productCategoryList = productCategoryService.getProductCategoryList(
  116 + convertSet(list, CrmProductDO::getCategoryId));
  117 + return CrmProductConvert.INSTANCE.convertList(list, userMap, productCategoryList);
87 } 118 }
88 119
89 } 120 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/product/CrmProductCreateReqVO.java deleted
1 -package cn.iocoder.yudao.module.crm.controller.admin.product.vo.product;  
2 -  
3 -import lombok.*;  
4 -import io.swagger.v3.oas.annotations.media.Schema;  
5 -  
6 -import javax.validation.constraints.NotNull;  
7 -  
8 -@Schema(description = "管理后台 - 产品创建 Request VO")  
9 -@Data  
10 -@EqualsAndHashCode(callSuper = true)  
11 -@ToString(callSuper = true)  
12 -public class CrmProductCreateReqVO extends CrmProductBaseVO {  
13 - @Schema(description = "负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31926")  
14 - @NotNull(message = "负责人的用户编号不能为空")  
15 - private Long ownerUserId;  
16 -}  
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/product/CrmProductExcelVO.java deleted
1 -package cn.iocoder.yudao.module.crm.controller.admin.product.vo.product;  
2 -  
3 -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;  
4 -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;  
5 -import com.alibaba.excel.annotation.ExcelProperty;  
6 -import lombok.Data;  
7 -  
8 -import java.time.LocalDateTime;  
9 -  
10 -// TODO 芋艿:这个导出最后搞 那暂时就放着不动了哈  
11 -/**  
12 - * 产品 Excel VO  
13 - *  
14 - * @author ZanGe丶  
15 - */  
16 -@Data  
17 -public class CrmProductExcelVO {  
18 -  
19 - @ExcelProperty("主键id")  
20 - private Long id;  
21 -  
22 - @ExcelProperty("产品名称")  
23 - private String name;  
24 -  
25 - @ExcelProperty("产品编码")  
26 - private String no;  
27 -  
28 - @ExcelProperty("单位")  
29 - private String unit;  
30 -  
31 - @ExcelProperty("价格")  
32 - private Long price;  
33 -  
34 - @ExcelProperty(value = "状态", converter = DictConvert.class)  
35 - @DictFormat("crm_product_status") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中  
36 - private Integer status;  
37 -  
38 - @ExcelProperty("产品分类ID")  
39 - private Long categoryId;  
40 -  
41 - @ExcelProperty("产品描述")  
42 - private String description;  
43 -  
44 - @ExcelProperty("负责人的用户编号")  
45 - private Long ownerUserId;  
46 -  
47 - @ExcelProperty("创建时间")  
48 - private LocalDateTime createTime;  
49 -  
50 -}  
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/product/CrmProductExportReqVO.java deleted
1 -package cn.iocoder.yudao.module.crm.controller.admin.product.vo.product;  
2 -  
3 -import io.swagger.v3.oas.annotations.media.Schema;  
4 -import lombok.Data;  
5 -import org.springframework.format.annotation.DateTimeFormat;  
6 -  
7 -import java.time.LocalDateTime;  
8 -  
9 -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;  
10 -  
11 -// TODO 芋艿:这个导出最后搞  
12 -@Schema(description = "管理后台 - 产品 Excel 导出 Request VO,参数和 ProductPageReqVO 是一致的")  
13 -@Data  
14 -public class CrmProductExportReqVO {  
15 -  
16 - @Schema(description = "产品名称", example = "李四")  
17 - private String name;  
18 -  
19 - @Schema(description = "产品编码")  
20 - private String no;  
21 -  
22 - @Schema(description = "单位")  
23 - private String unit;  
24 -  
25 - @Schema(description = "价格", example = "8911")  
26 - private Long price;  
27 -  
28 - @Schema(description = "状态", example = "2")  
29 - private Integer status;  
30 -  
31 - @Schema(description = "产品分类ID", example = "1738")  
32 - private Long categoryId;  
33 -  
34 - @Schema(description = "产品描述", example = "你说的对")  
35 - private String description;  
36 -  
37 - @Schema(description = "负责人的用户编号", example = "31926")  
38 - private Long ownerUserId;  
39 -  
40 - @Schema(description = "创建时间")  
41 - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)  
42 - private LocalDateTime[] createTime;  
43 -  
44 -}  
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/product/CrmProductPageReqVO.java
@@ -5,14 +5,8 @@ import io.swagger.v3.oas.annotations.media.Schema; @@ -5,14 +5,8 @@ import io.swagger.v3.oas.annotations.media.Schema;
5 import lombok.Data; 5 import lombok.Data;
6 import lombok.EqualsAndHashCode; 6 import lombok.EqualsAndHashCode;
7 import lombok.ToString; 7 import lombok.ToString;
8 -import org.springframework.format.annotation.DateTimeFormat;  
9 8
10 -import java.time.LocalDateTime;  
11 -  
12 -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;  
13 -  
14 -// TODO @zange-ok:按照需求,裁剪下筛选的字段,目前应该只要 name 和 status  
15 -@Schema(description = "管理后台 - 产品分页 Request VO") 9 +@Schema(description = "管理后台 - CRM 产品分页 Request VO")
16 @Data 10 @Data
17 @EqualsAndHashCode(callSuper = true) 11 @EqualsAndHashCode(callSuper = true)
18 @ToString(callSuper = true) 12 @ToString(callSuper = true)
@@ -21,29 +15,7 @@ public class CrmProductPageReqVO extends PageParam { @@ -21,29 +15,7 @@ public class CrmProductPageReqVO extends PageParam {
21 @Schema(description = "产品名称", example = "李四") 15 @Schema(description = "产品名称", example = "李四")
22 private String name; 16 private String name;
23 17
24 - @Schema(description = "产品编码")  
25 - private String no;  
26 -  
27 - @Schema(description = "单位")  
28 - private String unit;  
29 -  
30 - @Schema(description = "价格", example = "8911")  
31 - private Long price;  
32 -  
33 - @Schema(description = "状态", example = "2") 18 + @Schema(description = "状态", example = "1")
34 private Integer status; 19 private Integer status;
35 20
36 - @Schema(description = "产品分类ID", example = "1738")  
37 - private Long categoryId;  
38 -  
39 - @Schema(description = "产品描述", example = "你说的对")  
40 - private String description;  
41 -  
42 - @Schema(description = "负责人的用户编号", example = "31926")  
43 - private Long ownerUserId;  
44 -  
45 - @Schema(description = "创建时间")  
46 - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)  
47 - private LocalDateTime[] createTime;  
48 -  
49 } 21 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/product/CrmProductRespVO.java
1 package cn.iocoder.yudao.module.crm.controller.admin.product.vo.product; 1 package cn.iocoder.yudao.module.crm.controller.admin.product.vo.product;
2 2
  3 +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
  4 +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
  5 +import cn.iocoder.yudao.module.crm.enums.DictTypeConstants;
  6 +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
  7 +import com.alibaba.excel.annotation.ExcelProperty;
3 import io.swagger.v3.oas.annotations.media.Schema; 8 import io.swagger.v3.oas.annotations.media.Schema;
4 -import lombok.*; 9 +import lombok.Data;
5 10
6 -import javax.validation.constraints.NotNull;  
7 import java.time.LocalDateTime; 11 import java.time.LocalDateTime;
8 12
9 -@Schema(description = "管理后台 - 产品 Response VO") 13 +@Schema(description = "管理后台 - CRM 产品 Response VO")
10 @Data 14 @Data
11 -@EqualsAndHashCode(callSuper = true)  
12 -@ToString(callSuper = true)  
13 -public class CrmProductRespVO extends CrmProductBaseVO { 15 +@ExcelIgnoreUnannotated
  16 +public class CrmProductRespVO {
14 17
15 - @Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "20529") 18 + @Schema(description = "产品编号", example = "20529")
  19 + @ExcelProperty("产品编号")
16 private Long id; 20 private Long id;
17 21
18 - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)  
19 - private LocalDateTime createTime; 22 + @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "好产品")
  23 + @ExcelProperty("产品名称")
  24 + private String name;
  25 +
  26 + @Schema(description = "产品编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "12306")
  27 + @ExcelProperty("产品编码")
  28 + private String no;
  29 +
  30 + @Schema(description = "单位", example = "2")
  31 + @ExcelProperty(value = "单位", converter = DictConvert.class)
  32 + @DictFormat(DictTypeConstants.CRM_PRODUCT_UNIT)
  33 + private Integer unit;
  34 +
  35 + @Schema(description = "价格, 单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "8911")
  36 + @ExcelProperty("价格,单位:分")
  37 + private Long price;
  38 +
  39 + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "上架")
  40 + @ExcelProperty(value = "单位", converter = DictConvert.class)
  41 + @DictFormat(DictTypeConstants.CRM_PRODUCT_STATUS)
  42 + private Integer status;
  43 +
  44 + @Schema(description = "产品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  45 + private Long categoryId;
  46 + @Schema(description = "产品分类名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "衣服")
  47 + @ExcelProperty("产品分类")
  48 + private String categoryName;
  49 +
  50 + @Schema(description = "产品描述", example = "你说的对")
  51 + @ExcelProperty("产品描述")
  52 + private String description;
20 53
21 @Schema(description = "负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31926") 54 @Schema(description = "负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31926")
22 - @NotNull(message = "负责人的用户编号不能为空")  
23 private Long ownerUserId; 55 private Long ownerUserId;
  56 + @Schema(description = "负责人的用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码")
  57 + @ExcelProperty("负责人")
  58 + private String ownerUserName;
  59 +
  60 + @Schema(description = "创建人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
  61 + private String creator;
  62 + @Schema(description = "创建人名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码")
  63 + @ExcelProperty("创建人")
  64 + private String creatorName;
  65 +
  66 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  67 + @ExcelProperty("创建时间")
  68 + private LocalDateTime createTime;
  69 +
24 } 70 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/product/CrmProductBaseVO.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/product/CrmProductSaveReqVO.java
1 package cn.iocoder.yudao.module.crm.controller.admin.product.vo.product; 1 package cn.iocoder.yudao.module.crm.controller.admin.product.vo.product;
2 2
  3 +import lombok.*;
3 import io.swagger.v3.oas.annotations.media.Schema; 4 import io.swagger.v3.oas.annotations.media.Schema;
4 -import lombok.Data;  
5 5
6 import javax.validation.constraints.NotNull; 6 import javax.validation.constraints.NotNull;
7 7
8 -// TODO @zange-ok:需要加 CRM 前置噢  
9 -/**  
10 - * 产品 Base VO,提供给添加、修改、详细的子 VO 使用  
11 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成  
12 - */ 8 +@Schema(description = "管理后台 - CRM 产品创建/修改 Request VO")
13 @Data 9 @Data
14 -public class CrmProductBaseVO { 10 +public class CrmProductSaveReqVO {
15 11
16 - // TODO @zange:example 要写哈;主要是接口文档,可以基于 example 可以生产请求参数 12 + @Schema(description = "产品编号", example = "20529")
  13 + private Long id;
17 14
18 @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "好产品") 15 @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "好产品")
19 @NotNull(message = "产品名称不能为空") 16 @NotNull(message = "产品名称不能为空")
@@ -24,22 +21,25 @@ public class CrmProductBaseVO { @@ -24,22 +21,25 @@ public class CrmProductBaseVO {
24 private String no; 21 private String no;
25 22
26 @Schema(description = "单位", example = "2") 23 @Schema(description = "单位", example = "2")
27 - private String unit; 24 + private Integer unit;
28 25
29 - @Schema(description = "价格", example = "8911") 26 + @Schema(description = "价格, 单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "8911")
  27 + @NotNull(message = "价格不能为空")
30 private Long price; 28 private Long price;
31 29
32 @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "上架") 30 @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "上架")
33 @NotNull(message = "状态不能为空") 31 @NotNull(message = "状态不能为空")
34 private Integer status; 32 private Integer status;
35 33
36 - @Schema(description = "产品分类ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")  
37 - @NotNull(message = "产品分类ID不能为空") 34 + @Schema(description = "产品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  35 + @NotNull(message = "产品分类编号不能为空")
38 private Long categoryId; 36 private Long categoryId;
39 37
40 @Schema(description = "产品描述", example = "你说的对") 38 @Schema(description = "产品描述", example = "你说的对")
41 private String description; 39 private String description;
42 40
43 - // TODO @zange-ok:这个字段只有 create 可以传递,update 不传递;所以放到 create 和 resp 里; 41 + @Schema(description = "负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31926")
  42 + @NotNull(message = "负责人的用户编号不能为空")
  43 + private Long ownerUserId;
44 44
45 } 45 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/product/CrmProductUpdateReqVO.java deleted
1 -package cn.iocoder.yudao.module.crm.controller.admin.product.vo.product;  
2 -  
3 -import io.swagger.v3.oas.annotations.media.Schema;  
4 -import lombok.*;  
5 -  
6 -import javax.validation.constraints.*;  
7 -  
8 -@Schema(description = "管理后台 - 产品更新 Request VO")  
9 -@Data  
10 -@EqualsAndHashCode(callSuper = true)  
11 -@ToString(callSuper = true)  
12 -public class CrmProductUpdateReqVO extends CrmProductBaseVO {  
13 -  
14 - @Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "20529")  
15 - @NotNull(message = "主键id不能为空")  
16 - private Long id;  
17 -  
18 -}  
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/product/CrmProductConvert.java
1 package cn.iocoder.yudao.module.crm.convert.product; 1 package cn.iocoder.yudao.module.crm.convert.product;
2 2
3 -import cn.iocoder.yudao.framework.common.pojo.PageResult;  
4 -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductCreateReqVO;  
5 -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductExcelVO; 3 +import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
  4 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6 import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductRespVO; 5 import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductRespVO;
7 -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductUpdateReqVO; 6 +import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO;
8 import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO; 7 import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
  8 +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
9 import org.mapstruct.Mapper; 9 import org.mapstruct.Mapper;
10 import org.mapstruct.factory.Mappers; 10 import org.mapstruct.factory.Mappers;
11 11
12 import java.util.List; 12 import java.util.List;
  13 +import java.util.Map;
  14 +
  15 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
13 16
14 /** 17 /**
15 * 产品 Convert 18 * 产品 Convert
@@ -21,16 +24,17 @@ public interface CrmProductConvert { @@ -21,16 +24,17 @@ public interface CrmProductConvert {
21 24
22 CrmProductConvert INSTANCE = Mappers.getMapper(CrmProductConvert.class); 25 CrmProductConvert INSTANCE = Mappers.getMapper(CrmProductConvert.class);
23 26
24 - CrmProductDO convert(CrmProductCreateReqVO bean);  
25 -  
26 - CrmProductDO convert(CrmProductUpdateReqVO bean);  
27 -  
28 - CrmProductRespVO convert(CrmProductDO bean);  
29 -  
30 - List<CrmProductRespVO> convertList(List<CrmProductDO> list);  
31 -  
32 - PageResult<CrmProductRespVO> convertPage(PageResult<CrmProductDO> page);  
33 -  
34 - List<CrmProductExcelVO> convertList02(List<CrmProductDO> list); 27 + default List<CrmProductRespVO> convertList(List<CrmProductDO> list,
  28 + Map<Long, AdminUserRespDTO> userMap,
  29 + List<CrmProductCategoryDO> categoryList) {
  30 + List<CrmProductRespVO> voList = BeanUtils.toBean(list, CrmProductRespVO.class);
  31 + Map<Long, CrmProductCategoryDO> categoryMap = convertMap(categoryList, CrmProductCategoryDO::getId);
  32 + for (CrmProductRespVO vo : voList) {
  33 + MapUtils.findAndThen(categoryMap, vo.getCategoryId(), category -> vo.setCategoryName(category.getName()));
  34 + MapUtils.findAndThen(userMap, vo.getOwnerUserId(), user -> vo.setOwnerUserName(user.getNickname()));
  35 + MapUtils.findAndThen(userMap, Long.valueOf(vo.getCreator()), user -> vo.setCreatorName(user.getNickname()));
  36 + }
  37 + return voList;
  38 + }
35 39
36 } 40 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/product/CrmProductDO.java
@@ -8,7 +8,7 @@ import com.baomidou.mybatisplus.annotation.TableName; @@ -8,7 +8,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
8 import lombok.*; 8 import lombok.*;
9 9
10 /** 10 /**
11 - * 产品 DO 11 + * CRM 产品 DO
12 * 12 *
13 * @author ZanGe丶 13 * @author ZanGe丶
14 */ 14 */
@@ -23,7 +23,7 @@ import lombok.*; @@ -23,7 +23,7 @@ import lombok.*;
23 public class CrmProductDO extends BaseDO { 23 public class CrmProductDO extends BaseDO {
24 24
25 /** 25 /**
26 - * 主键 id 26 + * 编号
27 */ 27 */
28 @TableId 28 @TableId
29 private Long id; 29 private Long id;
@@ -37,20 +37,24 @@ public class CrmProductDO extends BaseDO { @@ -37,20 +37,24 @@ public class CrmProductDO extends BaseDO {
37 private String no; 37 private String no;
38 /** 38 /**
39 * 单位 39 * 单位
  40 + *
  41 + * 字典 {@link cn.iocoder.yudao.module.crm.enums.DictTypeConstants#CRM_PRODUCT_UNIT}
40 */ 42 */
41 - private String unit; 43 + private Integer unit;
42 /** 44 /**
43 - * 价格 45 + * 价格,单位:分
44 */ 46 */
45 private Long price; 47 private Long price;
46 /** 48 /**
47 * 状态 49 * 状态
  50 + *
48 * 关联 {@link CrmProductStatusEnum} 51 * 关联 {@link CrmProductStatusEnum}
49 */ 52 */
50 private Integer status; 53 private Integer status;
51 /** 54 /**
52 * 产品分类 ID 55 * 产品分类 ID
53 - * 关联 {@link CrmProductCategoryDO#id} 56 + *
  57 + * 关联 {@link CrmProductCategoryDO#getId()} 字段
54 */ 58 */
55 private Long categoryId; 59 private Long categoryId;
56 /** 60 /**
@@ -59,6 +63,8 @@ public class CrmProductDO extends BaseDO { @@ -59,6 +63,8 @@ public class CrmProductDO extends BaseDO {
59 private String description; 63 private String description;
60 /** 64 /**
61 * 负责人的用户编号 65 * 负责人的用户编号
  66 + *
  67 + * 关联 AdminUserDO 的 id 字段
62 */ 68 */
63 private Long ownerUserId; 69 private Long ownerUserId;
64 70
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/product/CrmProductMapper.java
@@ -3,15 +3,12 @@ package cn.iocoder.yudao.module.crm.dal.mysql.product; @@ -3,15 +3,12 @@ package cn.iocoder.yudao.module.crm.dal.mysql.product;
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; 4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; 5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
6 -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductExportReqVO;  
7 import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO; 6 import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO;
8 import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO; 7 import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
9 import org.apache.ibatis.annotations.Mapper; 8 import org.apache.ibatis.annotations.Mapper;
10 9
11 -import java.util.List;  
12 -  
13 /** 10 /**
14 - * 产品 Mapper 11 + * CRM 产品 Mapper
15 * 12 *
16 * @author ZanGe丶 13 * @author ZanGe丶
17 */ 14 */
@@ -25,14 +22,8 @@ public interface CrmProductMapper extends BaseMapperX&lt;CrmProductDO&gt; { @@ -25,14 +22,8 @@ public interface CrmProductMapper extends BaseMapperX&lt;CrmProductDO&gt; {
25 .orderByDesc(CrmProductDO::getId)); 22 .orderByDesc(CrmProductDO::getId));
26 } 23 }
27 24
28 - default List<CrmProductDO> selectList(CrmProductExportReqVO reqVO) {  
29 - return selectList(new LambdaQueryWrapperX<CrmProductDO>()  
30 - .likeIfPresent(CrmProductDO::getName, reqVO.getName())  
31 - .eqIfPresent(CrmProductDO::getStatus, reqVO.getStatus())  
32 - .orderByDesc(CrmProductDO::getId));  
33 - }  
34 -  
35 default CrmProductDO selectByNo(String no) { 25 default CrmProductDO selectByNo(String no) {
36 return selectOne(CrmProductDO::getNo, no); 26 return selectOne(CrmProductDO::getNo, no);
37 } 27 }
  28 +
38 } 29 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/product/package-info.java deleted
1 -/**  
2 - * 产品表  
3 - */  
4 -package cn.iocoder.yudao.module.crm.dal.mysql.product;  
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/product/CrmProductCategoryService.java
@@ -6,10 +6,11 @@ import cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory.C @@ -6,10 +6,11 @@ import cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory.C
6 import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO; 6 import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO;
7 7
8 import javax.validation.Valid; 8 import javax.validation.Valid;
  9 +import java.util.Collection;
9 import java.util.List; 10 import java.util.List;
10 11
11 /** 12 /**
12 - * 产品分类 Service 接口 13 + * CRM 产品分类 Service 接口
13 * 14 *
14 * @author ZanGe丶 15 * @author ZanGe丶
15 */ 16 */
@@ -48,9 +49,17 @@ public interface CrmProductCategoryService { @@ -48,9 +49,17 @@ public interface CrmProductCategoryService {
48 /** 49 /**
49 * 获得产品分类列表 50 * 获得产品分类列表
50 * 51 *
51 - * @param ids 编号 52 + * @param listReqVO 列表请求
52 * @return 产品分类列表 53 * @return 产品分类列表
53 */ 54 */
54 - List<CrmProductCategoryDO> getProductCategoryList(CrmProductCategoryListReqVO treeListReqVO); 55 + List<CrmProductCategoryDO> getProductCategoryList(CrmProductCategoryListReqVO listReqVO);
  56 +
  57 + /**
  58 + * 获得产品分类列表
  59 + *
  60 + * @param ids 编号数组
  61 + * @return 产品分类列表
  62 + */
  63 + List<CrmProductCategoryDO> getProductCategoryList(Collection<Long> ids);
55 64
56 } 65 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/product/CrmProductCategoryServiceImpl.java
@@ -12,6 +12,7 @@ import org.springframework.stereotype.Service; @@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
12 import org.springframework.validation.annotation.Validated; 12 import org.springframework.validation.annotation.Validated;
13 13
14 import javax.annotation.Resource; 14 import javax.annotation.Resource;
  15 +import java.util.Collection;
15 import java.util.List; 16 import java.util.List;
16 import java.util.Objects; 17 import java.util.Objects;
17 18
@@ -19,7 +20,6 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU @@ -19,7 +20,6 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
19 import static cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO.PARENT_ID_NULL; 20 import static cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO.PARENT_ID_NULL;
20 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; 21 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
21 22
22 -// TODO @zange-ok:这个类所在的包,放到 product 下;  
23 /** 23 /**
24 * 产品分类 Service 实现类 24 * 产品分类 Service 实现类
25 * 25 *
@@ -29,10 +29,11 @@ import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; @@ -29,10 +29,11 @@ import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
29 @Validated 29 @Validated
30 public class CrmProductCategoryServiceImpl implements CrmProductCategoryService { 30 public class CrmProductCategoryServiceImpl implements CrmProductCategoryService {
31 31
32 - @Resource 32 + @Resource(name = "crmProductCategoryMapper")
33 private CrmProductCategoryMapper productCategoryMapper; 33 private CrmProductCategoryMapper productCategoryMapper;
  34 +
34 @Resource 35 @Resource
35 - @Lazy 36 + @Lazy // 延迟加载,解决循环依赖问题
36 private CrmProductService crmProductService; 37 private CrmProductService crmProductService;
37 38
38 @Override 39 @Override
@@ -63,7 +64,7 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService @@ -63,7 +64,7 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService
63 CrmProductCategoryDO productCategoryDO = productCategoryMapper.selectByName(updateReqVO.getName()); 64 CrmProductCategoryDO productCategoryDO = productCategoryMapper.selectByName(updateReqVO.getName());
64 if (productCategoryDO != null && 65 if (productCategoryDO != null &&
65 ObjUtil.notEqual(productCategoryDO.getId(), updateReqVO.getId())) { 66 ObjUtil.notEqual(productCategoryDO.getId(), updateReqVO.getId())) {
66 - throw exception(CRM_PRODUCT_CATEGORY_EXISTS); 67 + throw exception(PRODUCT_CATEGORY_EXISTS);
67 } 68 }
68 // 更新 69 // 更新
69 CrmProductCategoryDO updateObj = CrmProductCategoryConvert.INSTANCE.convert(updateReqVO); 70 CrmProductCategoryDO updateObj = CrmProductCategoryConvert.INSTANCE.convert(updateReqVO);
@@ -77,11 +78,11 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService @@ -77,11 +78,11 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService
77 validateProductCategoryExists(id); 78 validateProductCategoryExists(id);
78 // 校验是否还有子分类 79 // 校验是否还有子分类
79 if (productCategoryMapper.selectCountByParentId(id) > 0) { 80 if (productCategoryMapper.selectCountByParentId(id) > 0) {
80 - throw exception(CRM_CATEGORY_EXISTS_CHILDREN); 81 + throw exception(product_CATEGORY_EXISTS_CHILDREN);
81 } 82 }
82 // 校验是否被产品使用 83 // 校验是否被产品使用
83 if (crmProductService.getProductByCategoryId(id) !=null) { 84 if (crmProductService.getProductByCategoryId(id) !=null) {
84 - throw exception(CRM_PRODUCT_CATEGORY_USED); 85 + throw exception(PRODUCT_CATEGORY_USED);
85 } 86 }
86 // 删除 87 // 删除
87 productCategoryMapper.deleteById(id); 88 productCategoryMapper.deleteById(id);
@@ -89,7 +90,7 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService @@ -89,7 +90,7 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService
89 90
90 private void validateProductCategoryExists(Long id) { 91 private void validateProductCategoryExists(Long id) {
91 if (productCategoryMapper.selectById(id) == null) { 92 if (productCategoryMapper.selectById(id) == null) {
92 - throw exception(CRM_PRODUCT_CATEGORY_NOT_EXISTS); 93 + throw exception(PRODUCT_CATEGORY_NOT_EXISTS);
93 } 94 }
94 } 95 }
95 96
@@ -101,11 +102,11 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService @@ -101,11 +102,11 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService
101 // 父分类不存在 102 // 父分类不存在
102 CrmProductCategoryDO category = productCategoryMapper.selectById(id); 103 CrmProductCategoryDO category = productCategoryMapper.selectById(id);
103 if (category == null) { 104 if (category == null) {
104 - throw exception(CRM_CATEGORY_PARENT_NOT_EXISTS); 105 + throw exception(PRODUCT_CATEGORY_PARENT_NOT_EXISTS);
105 } 106 }
106 // 父分类不能是二级分类 107 // 父分类不能是二级分类
107 if (!Objects.equals(category.getParentId(), PARENT_ID_NULL)) { 108 if (!Objects.equals(category.getParentId(), PARENT_ID_NULL)) {
108 - throw exception(CRM_CATEGORY_PARENT_NOT_FIRST_LEVEL); 109 + throw exception(PRODUCT_CATEGORY_PARENT_NOT_FIRST_LEVEL);
109 } 110 }
110 } 111 }
111 112
@@ -115,8 +116,13 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService @@ -115,8 +116,13 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService
115 } 116 }
116 117
117 @Override 118 @Override
118 - public List<CrmProductCategoryDO> getProductCategoryList(CrmProductCategoryListReqVO treeListReqVO) {  
119 - return productCategoryMapper.selectList(treeListReqVO); 119 + public List<CrmProductCategoryDO> getProductCategoryList(CrmProductCategoryListReqVO listReqVO) {
  120 + return productCategoryMapper.selectList(listReqVO);
  121 + }
  122 +
  123 + @Override
  124 + public List<CrmProductCategoryDO> getProductCategoryList(Collection<Long> ids) {
  125 + return productCategoryMapper.selectBatchIds(ids);
120 } 126 }
121 127
122 } 128 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/product/CrmProductService.java
1 package cn.iocoder.yudao.module.crm.service.product; 1 package cn.iocoder.yudao.module.crm.service.product;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductCreateReqVO;  
5 -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductExportReqVO;  
6 import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO; 4 import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO;
7 -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductUpdateReqVO; 5 +import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductSaveReqVO;
8 import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO; 6 import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
9 7
10 import javax.validation.Valid; 8 import javax.validation.Valid;
@@ -12,7 +10,7 @@ import java.util.Collection; @@ -12,7 +10,7 @@ import java.util.Collection;
12 import java.util.List; 10 import java.util.List;
13 11
14 /** 12 /**
15 - * 产品 Service 接口 13 + * CRM 产品 Service 接口
16 * 14 *
17 * @author ZanGe丶 15 * @author ZanGe丶
18 */ 16 */
@@ -24,14 +22,14 @@ public interface CrmProductService { @@ -24,14 +22,14 @@ public interface CrmProductService {
24 * @param createReqVO 创建信息 22 * @param createReqVO 创建信息
25 * @return 编号 23 * @return 编号
26 */ 24 */
27 - Long createProduct(@Valid CrmProductCreateReqVO createReqVO); 25 + Long createProduct(@Valid CrmProductSaveReqVO createReqVO);
28 26
29 /** 27 /**
30 * 更新产品 28 * 更新产品
31 * 29 *
32 * @param updateReqVO 更新信息 30 * @param updateReqVO 更新信息
33 */ 31 */
34 - void updateProduct(@Valid CrmProductUpdateReqVO updateReqVO); 32 + void updateProduct(@Valid CrmProductSaveReqVO updateReqVO);
35 33
36 /** 34 /**
37 * 删除产品 35 * 删除产品
@@ -65,14 +63,6 @@ public interface CrmProductService { @@ -65,14 +63,6 @@ public interface CrmProductService {
65 PageResult<CrmProductDO> getProductPage(CrmProductPageReqVO pageReqVO); 63 PageResult<CrmProductDO> getProductPage(CrmProductPageReqVO pageReqVO);
66 64
67 /** 65 /**
68 - * 获得产品列表, 用于 Excel 导出  
69 - *  
70 - * @param exportReqVO 查询条件  
71 - * @return 产品列表  
72 - */  
73 - List<CrmProductDO> getProductList(CrmProductExportReqVO exportReqVO);  
74 -  
75 - /**  
76 * 获得产品 66 * 获得产品
77 * 67 *
78 * @param categoryId 分类编号 68 * @param categoryId 分类编号
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/product/CrmProductServiceImpl.java
@@ -3,27 +3,32 @@ package cn.iocoder.yudao.module.crm.service.product; @@ -3,27 +3,32 @@ package cn.iocoder.yudao.module.crm.service.product;
3 import cn.hutool.core.collection.CollUtil; 3 import cn.hutool.core.collection.CollUtil;
4 import cn.hutool.core.collection.ListUtil; 4 import cn.hutool.core.collection.ListUtil;
5 import cn.iocoder.yudao.framework.common.pojo.PageResult; 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductCreateReqVO;  
7 -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductExportReqVO; 6 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
8 import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO; 7 import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO;
9 -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductUpdateReqVO;  
10 -import cn.iocoder.yudao.module.crm.convert.product.CrmProductConvert; 8 +import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductSaveReqVO;
11 import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO; 9 import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO;
12 import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO; 10 import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
13 import cn.iocoder.yudao.module.crm.dal.mysql.product.CrmProductMapper; 11 import cn.iocoder.yudao.module.crm.dal.mysql.product.CrmProductMapper;
  12 +import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
  13 +import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
  14 +import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
  15 +import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
  16 +import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
14 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 17 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
15 import org.springframework.stereotype.Service; 18 import org.springframework.stereotype.Service;
16 import org.springframework.validation.annotation.Validated; 19 import org.springframework.validation.annotation.Validated;
17 20
18 import javax.annotation.Resource; 21 import javax.annotation.Resource;
19 import java.util.Collection; 22 import java.util.Collection;
  23 +import java.util.Collections;
20 import java.util.List; 24 import java.util.List;
21 25
22 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 26 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
23 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; 27 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
24 28
  29 +// TODO 芋艿:数据权限
25 /** 30 /**
26 - * 产品 Service 实现类 31 + * CRM 产品 Service 实现类
27 * 32 *
28 * @author ZanGe丶 33 * @author ZanGe丶
29 */ 34 */
@@ -31,59 +36,80 @@ import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; @@ -31,59 +36,80 @@ import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
31 @Validated 36 @Validated
32 public class CrmProductServiceImpl implements CrmProductService { 37 public class CrmProductServiceImpl implements CrmProductService {
33 38
34 - @Resource 39 + @Resource(name = "crmProductMapper")
35 private CrmProductMapper productMapper; 40 private CrmProductMapper productMapper;
  41 +
36 @Resource 42 @Resource
37 private CrmProductCategoryService productCategoryService; 43 private CrmProductCategoryService productCategoryService;
  44 + @Resource
  45 + private CrmPermissionService permissionService;
  46 +
  47 + @Resource
  48 + private AdminUserApi adminUserApi;
38 49
39 @Override 50 @Override
40 - public Long createProduct(CrmProductCreateReqVO createReqVO) {  
41 - // 校验产品编号是否存在  
42 - validateProductNoDuplicate(createReqVO.getNo());  
43 - // TODO @zange-ok:需要校验 categoryId 是否存在; 51 + public Long createProduct(CrmProductSaveReqVO createReqVO) {
  52 + // 校验产品
  53 + adminUserApi.validateUserList(Collections.singleton(createReqVO.getOwnerUserId()));
  54 + validateProductNoDuplicate(null, createReqVO.getNo());
44 validateProductCategoryExists(createReqVO.getCategoryId()); 55 validateProductCategoryExists(createReqVO.getCategoryId());
45 - // 插入  
46 - CrmProductDO product = CrmProductConvert.INSTANCE.convert(createReqVO); 56 +
  57 + // 插入产品
  58 + CrmProductDO product = BeanUtils.toBean(createReqVO, CrmProductDO.class);
47 productMapper.insert(product); 59 productMapper.insert(product);
48 - // 返回 60 +
  61 + // 插入数据权限
  62 + permissionService.createPermission(new CrmPermissionCreateReqBO().setUserId(product.getOwnerUserId())
  63 + .setBizType(CrmBizTypeEnum.CRM_PRODUCT.getType()).setBizId(product.getId())
  64 + .setLevel(CrmPermissionLevelEnum.OWNER.getLevel()));
49 return product.getId(); 65 return product.getId();
50 } 66 }
51 67
52 @Override 68 @Override
53 - public void updateProduct(CrmProductUpdateReqVO updateReqVO) {  
54 - // 校验存在 69 + public void updateProduct(CrmProductSaveReqVO updateReqVO) {
  70 + // 校验产品
  71 + updateReqVO.setOwnerUserId(null); // 不修改负责人
55 validateProductExists(updateReqVO.getId()); 72 validateProductExists(updateReqVO.getId());
56 - // TODO @zange-ok:需要校验 categoryId 是否存在; 73 + validateProductNoDuplicate(updateReqVO.getId(), updateReqVO.getNo());
57 validateProductCategoryExists(updateReqVO.getCategoryId()); 74 validateProductCategoryExists(updateReqVO.getCategoryId());
58 - // 更新  
59 - CrmProductDO updateObj = CrmProductConvert.INSTANCE.convert(updateReqVO);  
60 - productMapper.updateById(updateObj);  
61 - }  
62 75
63 - @Override  
64 - public void deleteProduct(Long id) {  
65 - // 校验存在  
66 - validateProductExists(id);  
67 - // 删除  
68 - productMapper.deleteById(id); 76 + // 更新产品
  77 + CrmProductDO updateObj = BeanUtils.toBean(updateReqVO, CrmProductDO.class);
  78 + productMapper.updateById(updateObj);
69 } 79 }
70 80
71 - // TODO @zange-ok:validateProductExists 要不只校验是否存在;然后是否 no 重复,交给 validateProductNo,名字改成 validateProductNoDuplicate,和别的模块保持一致哈;  
72 private void validateProductExists(Long id) { 81 private void validateProductExists(Long id) {
73 CrmProductDO product = productMapper.selectById(id); 82 CrmProductDO product = productMapper.selectById(id);
74 if (product == null) { 83 if (product == null) {
75 - throw exception(CRM_PRODUCT_NOT_EXISTS); 84 + throw exception(PRODUCT_NOT_EXISTS);
76 } 85 }
77 } 86 }
78 87
  88 + private void validateProductNoDuplicate(Long id, String no) {
  89 + CrmProductDO product = productMapper.selectByNo(no);
  90 + if (product == null
  91 + || product.getId().equals(id)) {
  92 + return;
  93 + }
  94 + throw exception(PRODUCT_NO_EXISTS);
  95 + }
  96 +
79 private void validateProductCategoryExists(Long categoryId) { 97 private void validateProductCategoryExists(Long categoryId) {
80 - CrmProductCategoryDO productCategory = productCategoryService.getProductCategory(categoryId);  
81 - if (productCategory == null) {  
82 - throw exception(CRM_PRODUCT_CATEGORY_NOT_EXISTS); 98 + CrmProductCategoryDO category = productCategoryService.getProductCategory(categoryId);
  99 + if (category == null) {
  100 + throw exception(PRODUCT_CATEGORY_NOT_EXISTS);
83 } 101 }
84 } 102 }
85 103
86 @Override 104 @Override
  105 + public void deleteProduct(Long id) {
  106 + // 校验存在
  107 + validateProductExists(id);
  108 + // 删除
  109 + productMapper.deleteById(id);
  110 + }
  111 +
  112 + @Override
87 public CrmProductDO getProduct(Long id) { 113 public CrmProductDO getProduct(Long id) {
88 return productMapper.selectById(id); 114 return productMapper.selectById(id);
89 } 115 }
@@ -102,20 +128,8 @@ public class CrmProductServiceImpl implements CrmProductService { @@ -102,20 +128,8 @@ public class CrmProductServiceImpl implements CrmProductService {
102 } 128 }
103 129
104 @Override 130 @Override
105 - public List<CrmProductDO> getProductList(CrmProductExportReqVO exportReqVO) {  
106 - return productMapper.selectList(exportReqVO);  
107 - }  
108 -  
109 - @Override  
110 public CrmProductDO getProductByCategoryId(Long categoryId) { 131 public CrmProductDO getProductByCategoryId(Long categoryId) {
111 return productMapper.selectOne(new LambdaQueryWrapper<CrmProductDO>().eq(CrmProductDO::getCategoryId, categoryId)); 132 return productMapper.selectOne(new LambdaQueryWrapper<CrmProductDO>().eq(CrmProductDO::getCategoryId, categoryId));
112 } 133 }
113 134
114 - private void validateProductNoDuplicate(String no) {  
115 - CrmProductDO product = productMapper.selectOne(new LambdaQueryWrapper<CrmProductDO>().eq(CrmProductDO::getNo, no));  
116 - if (product != null) {  
117 - throw exception(CRM_PRODUCT_NO_EXISTS);  
118 - }  
119 - }  
120 -  
121 } 135 }
yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/receivable/CrmCrmReceivableServiceImplTest.java
@@ -108,16 +108,12 @@ public class CrmCrmReceivableServiceImplTest extends BaseDbUnitTest { @@ -108,16 +108,12 @@ public class CrmCrmReceivableServiceImplTest extends BaseDbUnitTest {
108 o.setPlanId(null); 108 o.setPlanId(null);
109 o.setCustomerId(null); 109 o.setCustomerId(null);
110 o.setContractId(null); 110 o.setContractId(null);
111 - o.setCheckStatus(null);  
112 o.setProcessInstanceId(null); 111 o.setProcessInstanceId(null);
113 o.setReturnTime(null); 112 o.setReturnTime(null);
114 o.setReturnType(null); 113 o.setReturnType(null);
115 o.setPrice(null); 114 o.setPrice(null);
116 o.setOwnerUserId(null); 115 o.setOwnerUserId(null);
117 - o.setBatchId(null);  
118 o.setSort(null); 116 o.setSort(null);
119 - o.setDataScope(null);  
120 - o.setDataScopeDeptIds(null);  
121 o.setAuditStatus(null); 117 o.setAuditStatus(null);
122 o.setRemark(null); 118 o.setRemark(null);
123 o.setCreateTime(null); 119 o.setCreateTime(null);
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/DictDataController.java
@@ -58,7 +58,7 @@ public class DictDataController { @@ -58,7 +58,7 @@ public class DictDataController {
58 return success(true); 58 return success(true);
59 } 59 }
60 60
61 - @GetMapping("/list-all-simple") 61 + @GetMapping({"/list-all-simple", "simple-list"})
62 @Operation(summary = "获得全部字典数据列表", description = "一般用于管理后台缓存字典数据在本地") 62 @Operation(summary = "获得全部字典数据列表", description = "一般用于管理后台缓存字典数据在本地")
63 // 无需添加权限认证,因为前端全局都需要 63 // 无需添加权限认证,因为前端全局都需要
64 public CommonResult<List<DictDataSimpleRespVO>> getSimpleDictDataList() { 64 public CommonResult<List<DictDataSimpleRespVO>> getSimpleDictDataList() {