Commit 3678752a610f70e414f4fe6f2ecf498604904b81
1 parent
c94f71a3
🔨 CRM:优化产品分类代码的实现
Showing
15 changed files
with
130 additions
and
175 deletions
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/CrmProductCategoryController.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.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory.CrmProductCategoryCreateReqVO; | ||
| 5 | -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory.CrmProductCategoryListReqVO; | ||
| 6 | -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory.CrmProductCategoryRespVO; | ||
| 7 | -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory.CrmProductCategoryUpdateReqVO; | ||
| 8 | -import cn.iocoder.yudao.module.crm.convert.product.CrmProductCategoryConvert; | 4 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | +import cn.iocoder.yudao.module.crm.controller.admin.product.vo.category.CrmProductCategoryCreateReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.crm.controller.admin.product.vo.category.CrmProductCategoryListReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.crm.controller.admin.product.vo.category.CrmProductCategoryRespVO; | ||
| 9 | import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO; | 8 | import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO; |
| 10 | import cn.iocoder.yudao.module.crm.service.product.CrmProductCategoryService; | 9 | import cn.iocoder.yudao.module.crm.service.product.CrmProductCategoryService; |
| 11 | import io.swagger.v3.oas.annotations.Operation; | 10 | import io.swagger.v3.oas.annotations.Operation; |
| @@ -21,7 +20,7 @@ import java.util.List; | @@ -21,7 +20,7 @@ import java.util.List; | ||
| 21 | 20 | ||
| 22 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 21 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 23 | 22 | ||
| 24 | -@Tag(name = "管理后台 - 产品分类") | 23 | +@Tag(name = "管理后台 - CRM 产品分类") |
| 25 | @RestController | 24 | @RestController |
| 26 | @RequestMapping("/crm/product-category") | 25 | @RequestMapping("/crm/product-category") |
| 27 | @Validated | 26 | @Validated |
| @@ -40,7 +39,7 @@ public class CrmProductCategoryController { | @@ -40,7 +39,7 @@ public class CrmProductCategoryController { | ||
| 40 | @PutMapping("/update") | 39 | @PutMapping("/update") |
| 41 | @Operation(summary = "更新产品分类") | 40 | @Operation(summary = "更新产品分类") |
| 42 | @PreAuthorize("@ss.hasPermission('crm:product-category:update')") | 41 | @PreAuthorize("@ss.hasPermission('crm:product-category:update')") |
| 43 | - public CommonResult<Boolean> updateProductCategory(@Valid @RequestBody CrmProductCategoryUpdateReqVO updateReqVO) { | 42 | + public CommonResult<Boolean> updateProductCategory(@Valid @RequestBody CrmProductCategoryCreateReqVO updateReqVO) { |
| 44 | productCategoryService.updateProductCategory(updateReqVO); | 43 | productCategoryService.updateProductCategory(updateReqVO); |
| 45 | return success(true); | 44 | return success(true); |
| 46 | } | 45 | } |
| @@ -59,16 +58,16 @@ public class CrmProductCategoryController { | @@ -59,16 +58,16 @@ public class CrmProductCategoryController { | ||
| 59 | @Parameter(name = "id", description = "编号", required = true, example = "1024") | 58 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 60 | @PreAuthorize("@ss.hasPermission('crm:product-category:query')") | 59 | @PreAuthorize("@ss.hasPermission('crm:product-category:query')") |
| 61 | public CommonResult<CrmProductCategoryRespVO> getProductCategory(@RequestParam("id") Long id) { | 60 | public CommonResult<CrmProductCategoryRespVO> getProductCategory(@RequestParam("id") Long id) { |
| 62 | - CrmProductCategoryDO productCategory = productCategoryService.getProductCategory(id); | ||
| 63 | - return success(CrmProductCategoryConvert.INSTANCE.convert(productCategory)); | 61 | + CrmProductCategoryDO category = productCategoryService.getProductCategory(id); |
| 62 | + return success(BeanUtils.toBean(category, CrmProductCategoryRespVO.class)); | ||
| 64 | } | 63 | } |
| 65 | 64 | ||
| 66 | @GetMapping("/list") | 65 | @GetMapping("/list") |
| 67 | @Operation(summary = "获得产品分类列表") | 66 | @Operation(summary = "获得产品分类列表") |
| 68 | @PreAuthorize("@ss.hasPermission('crm:product-category:query')") | 67 | @PreAuthorize("@ss.hasPermission('crm:product-category:query')") |
| 69 | - public CommonResult<List<CrmProductCategoryRespVO>> getProductCategoryList(@Valid CrmProductCategoryListReqVO treeListReqVO) { | ||
| 70 | - List<CrmProductCategoryDO> list = productCategoryService.getProductCategoryList(treeListReqVO); | ||
| 71 | - return success(CrmProductCategoryConvert.INSTANCE.convertList(list)); | 68 | + public CommonResult<List<CrmProductCategoryRespVO>> getProductCategoryList(@Valid CrmProductCategoryListReqVO listReqVO) { |
| 69 | + List<CrmProductCategoryDO> list = productCategoryService.getProductCategoryList(listReqVO); | ||
| 70 | + return success(BeanUtils.toBean(list, CrmProductCategoryRespVO.class)); | ||
| 72 | } | 71 | } |
| 73 | 72 | ||
| 74 | } | 73 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/CrmProductController.java
| @@ -4,7 +4,7 @@ import cn.hutool.core.collection.CollUtil; | @@ -4,7 +4,7 @@ import cn.hutool.core.collection.CollUtil; | ||
| 4 | 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; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 6 | 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; | 7 | +import cn.iocoder.yudao.framework.common.util.collection.SetUtils; |
| 8 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 8 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 9 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | 9 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 10 | import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO; | 10 | import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO; |
| @@ -82,7 +82,13 @@ public class CrmProductController { | @@ -82,7 +82,13 @@ public class CrmProductController { | ||
| 82 | @PreAuthorize("@ss.hasPermission('crm:product:query')") | 82 | @PreAuthorize("@ss.hasPermission('crm:product:query')") |
| 83 | public CommonResult<CrmProductRespVO> getProduct(@RequestParam("id") Long id) { | 83 | public CommonResult<CrmProductRespVO> getProduct(@RequestParam("id") Long id) { |
| 84 | CrmProductDO product = productService.getProduct(id); | 84 | CrmProductDO product = productService.getProduct(id); |
| 85 | - return success(BeanUtils.toBean(product, CrmProductRespVO.class)); | 85 | + if (product == null) { |
| 86 | + return success(null); | ||
| 87 | + } | ||
| 88 | + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap( | ||
| 89 | + SetUtils.asSet( Long.valueOf(product.getCreator()), product.getOwnerUserId())); | ||
| 90 | + CrmProductCategoryDO category = productCategoryService.getProductCategory(product.getCategoryId()); | ||
| 91 | + return success(CrmProductConvert.INSTANCE.convert(product, userMap, category)); | ||
| 86 | } | 92 | } |
| 87 | 93 | ||
| 88 | @GetMapping("/page") | 94 | @GetMapping("/page") |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/category/CrmProductCategoryCreateReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.controller.admin.product.vo.category; | ||
| 2 | + | ||
| 3 | +import lombok.*; | ||
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | + | ||
| 6 | +import javax.validation.constraints.NotNull; | ||
| 7 | + | ||
| 8 | +@Schema(description = "管理后台 - CRM 产品分类创建/更新 Request VO") | ||
| 9 | +@Data | ||
| 10 | +public class CrmProductCategoryCreateReqVO{ | ||
| 11 | + | ||
| 12 | + @Schema(description = "分类编号", example = "23902") | ||
| 13 | + private Long id; | ||
| 14 | + | ||
| 15 | + @Schema(description = "分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") | ||
| 16 | + @NotNull(message = "分类名称不能为空") | ||
| 17 | + private String name; | ||
| 18 | + | ||
| 19 | + @Schema(description = "父级编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "4680") | ||
| 20 | + @NotNull(message = "父级编号不能为空") | ||
| 21 | + private Long parentId; | ||
| 22 | + | ||
| 23 | +} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/productcategory/CrmProductCategoryListReqVO.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/category/CrmProductCategoryListReqVO.java
| 1 | -package cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory; | 1 | +package cn.iocoder.yudao.module.crm.controller.admin.product.vo.category; |
| 2 | 2 | ||
| 3 | import com.alibaba.excel.annotation.ExcelProperty; | 3 | import com.alibaba.excel.annotation.ExcelProperty; |
| 4 | import io.swagger.v3.oas.annotations.media.Schema; | 4 | import io.swagger.v3.oas.annotations.media.Schema; |
| @@ -6,8 +6,7 @@ import lombok.Data; | @@ -6,8 +6,7 @@ import lombok.Data; | ||
| 6 | 6 | ||
| 7 | import java.time.LocalDateTime; | 7 | import java.time.LocalDateTime; |
| 8 | 8 | ||
| 9 | -// TODO 芋艿:这个导出最后搞;命名应该是按照 ProductExportReqVO 风格 | ||
| 10 | -@Schema(description = "管理后台 - 产品分类列表 Request VO") | 9 | +@Schema(description = "管理后台 - CRM 产品分类列表 Request VO") |
| 11 | @Data | 10 | @Data |
| 12 | public class CrmProductCategoryListReqVO { | 11 | public class CrmProductCategoryListReqVO { |
| 13 | 12 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/productcategory/CrmProductCategoryRespVO.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/category/CrmProductCategoryRespVO.java
| 1 | -package cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory; | 1 | +package cn.iocoder.yudao.module.crm.controller.admin.product.vo.category; |
| 2 | 2 | ||
| 3 | import io.swagger.v3.oas.annotations.media.Schema; | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | import lombok.*; | 4 | import lombok.*; |
| 5 | + | ||
| 5 | import java.time.LocalDateTime; | 6 | import java.time.LocalDateTime; |
| 6 | 7 | ||
| 7 | -@Schema(description = "管理后台 - 产品分类 Response VO") | 8 | +@Schema(description = "管理后台 - CRM 产品分类 Response VO") |
| 8 | @Data | 9 | @Data |
| 9 | -@EqualsAndHashCode(callSuper = true) | ||
| 10 | -@ToString(callSuper = true) | ||
| 11 | -public class CrmProductCategoryRespVO extends CrmProductCategoryBaseVO { | 10 | +public class CrmProductCategoryRespVO { |
| 12 | 11 | ||
| 13 | - @Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "23902") | 12 | + @Schema(description = "分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23902") |
| 14 | private Long id; | 13 | private Long id; |
| 15 | 14 | ||
| 15 | + @Schema(description = "分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") | ||
| 16 | + private String name; | ||
| 17 | + | ||
| 18 | + @Schema(description = "父级编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "4680") | ||
| 19 | + private Long parentId; | ||
| 20 | + | ||
| 16 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | 21 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| 17 | private LocalDateTime createTime; | 22 | private LocalDateTime createTime; |
| 18 | 23 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/product/CrmProductRespVO.java
| @@ -67,4 +67,8 @@ public class CrmProductRespVO { | @@ -67,4 +67,8 @@ public class CrmProductRespVO { | ||
| 67 | @ExcelProperty("创建时间") | 67 | @ExcelProperty("创建时间") |
| 68 | private LocalDateTime createTime; | 68 | private LocalDateTime createTime; |
| 69 | 69 | ||
| 70 | + @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 71 | + @ExcelProperty("更新时间") | ||
| 72 | + private LocalDateTime updateTime; | ||
| 73 | + | ||
| 70 | } | 74 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/productcategory/CrmProductCategoryBaseVO.java deleted
| 1 | -package cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory; | ||
| 2 | - | ||
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | -import lombok.Data; | ||
| 5 | - | ||
| 6 | -import javax.validation.constraints.NotNull; | ||
| 7 | - | ||
| 8 | -/** | ||
| 9 | - * 产品分类 Base VO,提供给添加、修改、详细的子 VO 使用 | ||
| 10 | - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | ||
| 11 | - */ | ||
| 12 | -@Data | ||
| 13 | -public class CrmProductCategoryBaseVO { | ||
| 14 | - | ||
| 15 | - @Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") | ||
| 16 | - @NotNull(message = "名称不能为空") | ||
| 17 | - private String name; | ||
| 18 | - | ||
| 19 | - @Schema(description = "父级 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "4680") | ||
| 20 | - @NotNull(message = "父级 id 不能为空") | ||
| 21 | - private Long parentId; | ||
| 22 | - | ||
| 23 | -} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/productcategory/CrmProductCategoryCreateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory; | ||
| 2 | - | ||
| 3 | -import lombok.*; | ||
| 4 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | - | ||
| 6 | -@Schema(description = "管理后台 - 产品分类创建 Request VO") | ||
| 7 | -@Data | ||
| 8 | -@EqualsAndHashCode(callSuper = true) | ||
| 9 | -@ToString(callSuper = true) | ||
| 10 | -public class CrmProductCategoryCreateReqVO extends CrmProductCategoryBaseVO { | ||
| 11 | - | ||
| 12 | -} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/productcategory/CrmProductCategoryUpdateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory; | ||
| 2 | - | ||
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | -import lombok.Data; | ||
| 5 | -import lombok.EqualsAndHashCode; | ||
| 6 | -import lombok.ToString; | ||
| 7 | - | ||
| 8 | -import javax.validation.constraints.NotNull; | ||
| 9 | - | ||
| 10 | -@Schema(description = "管理后台 - 产品分类更新 Request VO") | ||
| 11 | -@Data | ||
| 12 | -@EqualsAndHashCode(callSuper = true) | ||
| 13 | -@ToString(callSuper = true) | ||
| 14 | -public class CrmProductCategoryUpdateReqVO extends CrmProductCategoryBaseVO { | ||
| 15 | - | ||
| 16 | - @Schema(description = "主键 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "23902") | ||
| 17 | - @NotNull(message = "主键 id 不能为空") | ||
| 18 | - private Long id; | ||
| 19 | - | ||
| 20 | -} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/product/CrmProductCategoryConvert.java deleted
| 1 | -package cn.iocoder.yudao.module.crm.convert.product; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory.CrmProductCategoryCreateReqVO; | ||
| 4 | -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory.CrmProductCategoryRespVO; | ||
| 5 | -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory.CrmProductCategoryUpdateReqVO; | ||
| 6 | -import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO; | ||
| 7 | -import org.mapstruct.Mapper; | ||
| 8 | -import org.mapstruct.factory.Mappers; | ||
| 9 | - | ||
| 10 | -import java.util.List; | ||
| 11 | - | ||
| 12 | -/** | ||
| 13 | - * 产品分类 Convert | ||
| 14 | - * | ||
| 15 | - * @author ZanGe丶 | ||
| 16 | - */ | ||
| 17 | -@Mapper | ||
| 18 | -public interface CrmProductCategoryConvert { | ||
| 19 | - | ||
| 20 | - CrmProductCategoryConvert INSTANCE = Mappers.getMapper(CrmProductCategoryConvert.class); | ||
| 21 | - | ||
| 22 | - CrmProductCategoryDO convert(CrmProductCategoryCreateReqVO bean); | ||
| 23 | - | ||
| 24 | - CrmProductCategoryDO convert(CrmProductCategoryUpdateReqVO bean); | ||
| 25 | - | ||
| 26 | - CrmProductCategoryRespVO convert(CrmProductCategoryDO bean); | ||
| 27 | - | ||
| 28 | - List<CrmProductCategoryRespVO> convertList(List<CrmProductCategoryDO> list); | ||
| 29 | - | ||
| 30 | -} |
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.util.collection.CollectionUtils; | ||
| 3 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | 4 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; |
| 4 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductRespVO; | 6 | import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductRespVO; |
| @@ -11,6 +12,7 @@ import org.mapstruct.factory.Mappers; | @@ -11,6 +12,7 @@ import org.mapstruct.factory.Mappers; | ||
| 11 | 12 | ||
| 12 | import java.util.List; | 13 | import java.util.List; |
| 13 | import java.util.Map; | 14 | import java.util.Map; |
| 15 | +import java.util.Optional; | ||
| 14 | 16 | ||
| 15 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | 17 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; |
| 16 | 18 | ||
| @@ -27,14 +29,18 @@ public interface CrmProductConvert { | @@ -27,14 +29,18 @@ public interface CrmProductConvert { | ||
| 27 | default List<CrmProductRespVO> convertList(List<CrmProductDO> list, | 29 | default List<CrmProductRespVO> convertList(List<CrmProductDO> list, |
| 28 | Map<Long, AdminUserRespDTO> userMap, | 30 | Map<Long, AdminUserRespDTO> userMap, |
| 29 | List<CrmProductCategoryDO> categoryList) { | 31 | List<CrmProductCategoryDO> categoryList) { |
| 30 | - List<CrmProductRespVO> voList = BeanUtils.toBean(list, CrmProductRespVO.class); | ||
| 31 | Map<Long, CrmProductCategoryDO> categoryMap = convertMap(categoryList, CrmProductCategoryDO::getId); | 32 | 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; | 33 | + return CollectionUtils.convertList(list, |
| 34 | + product -> convert(product, userMap, categoryMap.get(product.getCategoryId()))); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + default CrmProductRespVO convert(CrmProductDO product, | ||
| 38 | + Map<Long, AdminUserRespDTO> userMap, CrmProductCategoryDO category) { | ||
| 39 | + CrmProductRespVO productVO = BeanUtils.toBean(product, CrmProductRespVO.class); | ||
| 40 | + Optional.ofNullable(category).ifPresent(c -> productVO.setCategoryName(c.getName())); | ||
| 41 | + MapUtils.findAndThen(userMap, productVO.getOwnerUserId(), user -> productVO.setOwnerUserName(user.getNickname())); | ||
| 42 | + MapUtils.findAndThen(userMap, Long.valueOf(productVO.getCreator()), user -> productVO.setCreatorName(user.getNickname())); | ||
| 43 | + return productVO; | ||
| 38 | } | 44 | } |
| 39 | 45 | ||
| 40 | } | 46 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/product/CrmProductCategoryDO.java
| @@ -31,17 +31,18 @@ public class CrmProductCategoryDO extends BaseDO { | @@ -31,17 +31,18 @@ public class CrmProductCategoryDO extends BaseDO { | ||
| 31 | public static final int CATEGORY_LEVEL = 2; | 31 | public static final int CATEGORY_LEVEL = 2; |
| 32 | 32 | ||
| 33 | /** | 33 | /** |
| 34 | - * 主键id | 34 | + * 分类编号 |
| 35 | */ | 35 | */ |
| 36 | @TableId | 36 | @TableId |
| 37 | private Long id; | 37 | private Long id; |
| 38 | /** | 38 | /** |
| 39 | - * 名称 | 39 | + * 分类名称 |
| 40 | */ | 40 | */ |
| 41 | private String name; | 41 | private String name; |
| 42 | /** | 42 | /** |
| 43 | - * 父级 id | ||
| 44 | - * // TODO @zange-ok:这个要写下关联 CategoryDO 的 id 字段;参考下别的模块哈 | 43 | + * 父级编号 |
| 44 | + * | ||
| 45 | + * 关联 {@link CrmProductCategoryDO#getId()} | ||
| 45 | */ | 46 | */ |
| 46 | private Long parentId; | 47 | private Long parentId; |
| 47 | 48 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/product/CrmProductCategoryMapper.java
| @@ -2,32 +2,33 @@ package cn.iocoder.yudao.module.crm.dal.mysql.product; | @@ -2,32 +2,33 @@ package cn.iocoder.yudao.module.crm.dal.mysql.product; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | 4 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 5 | -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory.CrmProductCategoryListReqVO; | 5 | +import cn.iocoder.yudao.module.crm.controller.admin.product.vo.category.CrmProductCategoryListReqVO; |
| 6 | import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO; | 6 | import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO; |
| 7 | import org.apache.ibatis.annotations.Mapper; | 7 | import org.apache.ibatis.annotations.Mapper; |
| 8 | 8 | ||
| 9 | import java.util.List; | 9 | import java.util.List; |
| 10 | 10 | ||
| 11 | /** | 11 | /** |
| 12 | - * 产品分类 Mapper | 12 | + * CRM 产品分类 Mapper |
| 13 | * | 13 | * |
| 14 | * @author ZanGe丶 | 14 | * @author ZanGe丶 |
| 15 | */ | 15 | */ |
| 16 | @Mapper | 16 | @Mapper |
| 17 | public interface CrmProductCategoryMapper extends BaseMapperX<CrmProductCategoryDO> { | 17 | public interface CrmProductCategoryMapper extends BaseMapperX<CrmProductCategoryDO> { |
| 18 | 18 | ||
| 19 | - | ||
| 20 | default List<CrmProductCategoryDO> selectList(CrmProductCategoryListReqVO reqVO) { | 19 | default List<CrmProductCategoryDO> selectList(CrmProductCategoryListReqVO reqVO) { |
| 21 | return selectList(new LambdaQueryWrapperX<CrmProductCategoryDO>() | 20 | return selectList(new LambdaQueryWrapperX<CrmProductCategoryDO>() |
| 22 | .likeIfPresent(CrmProductCategoryDO::getName, reqVO.getName()) | 21 | .likeIfPresent(CrmProductCategoryDO::getName, reqVO.getName()) |
| 23 | .eqIfPresent(CrmProductCategoryDO::getParentId, reqVO.getParentId()) | 22 | .eqIfPresent(CrmProductCategoryDO::getParentId, reqVO.getParentId()) |
| 24 | .orderByDesc(CrmProductCategoryDO::getId)); | 23 | .orderByDesc(CrmProductCategoryDO::getId)); |
| 25 | } | 24 | } |
| 26 | - default CrmProductCategoryDO selectByName(String name) { | ||
| 27 | - return selectOne(CrmProductCategoryDO::getName, name); | 25 | + |
| 26 | + default CrmProductCategoryDO selectByParentIdAndName(Long parentId, String name) { | ||
| 27 | + return selectOne(CrmProductCategoryDO::getParentId, parentId, CrmProductCategoryDO::getName, name); | ||
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | default Long selectCountByParentId(Long parentId) { | 30 | default Long selectCountByParentId(Long parentId) { |
| 31 | return selectCount(CrmProductCategoryDO::getParentId, parentId); | 31 | return selectCount(CrmProductCategoryDO::getParentId, parentId); |
| 32 | } | 32 | } |
| 33 | + | ||
| 33 | } | 34 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/product/CrmProductCategoryService.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.module.crm.controller.admin.product.vo.productcategory.CrmProductCategoryCreateReqVO; | ||
| 4 | -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory.CrmProductCategoryListReqVO; | ||
| 5 | -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory.CrmProductCategoryUpdateReqVO; | 3 | +import cn.iocoder.yudao.module.crm.controller.admin.product.vo.category.CrmProductCategoryCreateReqVO; |
| 4 | +import cn.iocoder.yudao.module.crm.controller.admin.product.vo.category.CrmProductCategoryListReqVO; | ||
| 6 | import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO; | 5 | import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO; |
| 7 | 6 | ||
| 8 | import javax.validation.Valid; | 7 | import javax.validation.Valid; |
| @@ -29,7 +28,7 @@ public interface CrmProductCategoryService { | @@ -29,7 +28,7 @@ public interface CrmProductCategoryService { | ||
| 29 | * | 28 | * |
| 30 | * @param updateReqVO 更新信息 | 29 | * @param updateReqVO 更新信息 |
| 31 | */ | 30 | */ |
| 32 | - void updateProductCategory(@Valid CrmProductCategoryUpdateReqVO updateReqVO); | 31 | + void updateProductCategory(@Valid CrmProductCategoryCreateReqVO updateReqVO); |
| 33 | 32 | ||
| 34 | /** | 33 | /** |
| 35 | * 删除产品分类 | 34 | * 删除产品分类 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/product/CrmProductCategoryServiceImpl.java
| 1 | package cn.iocoder.yudao.module.crm.service.product; | 1 | package cn.iocoder.yudao.module.crm.service.product; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.util.ObjUtil; | ||
| 4 | -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory.CrmProductCategoryCreateReqVO; | ||
| 5 | -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory.CrmProductCategoryListReqVO; | ||
| 6 | -import cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory.CrmProductCategoryUpdateReqVO; | ||
| 7 | -import cn.iocoder.yudao.module.crm.convert.product.CrmProductCategoryConvert; | 3 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 4 | +import cn.iocoder.yudao.module.crm.controller.admin.product.vo.category.CrmProductCategoryCreateReqVO; | ||
| 5 | +import cn.iocoder.yudao.module.crm.controller.admin.product.vo.category.CrmProductCategoryListReqVO; | ||
| 8 | import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO; | 6 | import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO; |
| 9 | import cn.iocoder.yudao.module.crm.dal.mysql.product.CrmProductCategoryMapper; | 7 | import cn.iocoder.yudao.module.crm.dal.mysql.product.CrmProductCategoryMapper; |
| 10 | import org.springframework.context.annotation.Lazy; | 8 | import org.springframework.context.annotation.Lazy; |
| @@ -21,7 +19,7 @@ import static cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCateg | @@ -21,7 +19,7 @@ import static cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCateg | ||
| 21 | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; | 19 | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; |
| 22 | 20 | ||
| 23 | /** | 21 | /** |
| 24 | - * 产品分类 Service 实现类 | 22 | + * CRM 产品分类 Service 实现类 |
| 25 | * | 23 | * |
| 26 | * @author ZanGe丶 | 24 | * @author ZanGe丶 |
| 27 | */ | 25 | */ |
| @@ -38,56 +36,29 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService | @@ -38,56 +36,29 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService | ||
| 38 | 36 | ||
| 39 | @Override | 37 | @Override |
| 40 | public Long createProductCategory(CrmProductCategoryCreateReqVO createReqVO) { | 38 | public Long createProductCategory(CrmProductCategoryCreateReqVO createReqVO) { |
| 41 | - // TODO zange:参考 mall: ProductCategoryServiceImpl 补充下必要的参数校验; | ||
| 42 | - // 校验父分类存在 | 39 | + // 1.1 校验父分类存在 |
| 43 | validateParentProductCategory(createReqVO.getParentId()); | 40 | validateParentProductCategory(createReqVO.getParentId()); |
| 44 | - // 分类名称是否存在 | ||
| 45 | - CrmProductCategoryDO dbProductCategory = productCategoryMapper.selectByName(createReqVO.getName()); | ||
| 46 | - if (dbProductCategory != null) { | ||
| 47 | - return dbProductCategory.getId(); | ||
| 48 | - } | ||
| 49 | - // 插入 | ||
| 50 | - CrmProductCategoryDO productCategory = CrmProductCategoryConvert.INSTANCE.convert(createReqVO); | ||
| 51 | - productCategoryMapper.insert(productCategory); | ||
| 52 | - // 返回 | ||
| 53 | - return productCategory.getId(); | 41 | + // 1.2 分类名称是否存在 |
| 42 | + validateProductNameExists(null, createReqVO.getParentId(), createReqVO.getName()); | ||
| 43 | + // 2. 插入 | ||
| 44 | + CrmProductCategoryDO category = BeanUtils.toBean(createReqVO, CrmProductCategoryDO.class); | ||
| 45 | + productCategoryMapper.insert(category); | ||
| 46 | + return category.getId(); | ||
| 54 | } | 47 | } |
| 55 | 48 | ||
| 56 | @Override | 49 | @Override |
| 57 | - public void updateProductCategory(CrmProductCategoryUpdateReqVO updateReqVO) { | ||
| 58 | - // TODO zange:参考 mall: ProductCategoryServiceImpl 补充下必要的参数校验; | ||
| 59 | - // 校验存在 | 50 | + public void updateProductCategory(CrmProductCategoryCreateReqVO updateReqVO) { |
| 51 | + // 1.1 校验存在 | ||
| 60 | validateProductCategoryExists(updateReqVO.getId()); | 52 | validateProductCategoryExists(updateReqVO.getId()); |
| 61 | - // 校验父分类存在 | 53 | + // 1.2 校验父分类存在 |
| 62 | validateParentProductCategory(updateReqVO.getParentId()); | 54 | validateParentProductCategory(updateReqVO.getParentId()); |
| 63 | - // 校验名字重复 | ||
| 64 | - CrmProductCategoryDO productCategoryDO = productCategoryMapper.selectByName(updateReqVO.getName()); | ||
| 65 | - if (productCategoryDO != null && | ||
| 66 | - ObjUtil.notEqual(productCategoryDO.getId(), updateReqVO.getId())) { | ||
| 67 | - throw exception(PRODUCT_CATEGORY_EXISTS); | ||
| 68 | - } | ||
| 69 | - // 更新 | ||
| 70 | - CrmProductCategoryDO updateObj = CrmProductCategoryConvert.INSTANCE.convert(updateReqVO); | 55 | + // 1.3 分类名称是否存在 |
| 56 | + validateProductNameExists(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName()); | ||
| 57 | + // 2. 更新 | ||
| 58 | + CrmProductCategoryDO updateObj = BeanUtils.toBean(updateReqVO, CrmProductCategoryDO.class); | ||
| 71 | productCategoryMapper.updateById(updateObj); | 59 | productCategoryMapper.updateById(updateObj); |
| 72 | } | 60 | } |
| 73 | 61 | ||
| 74 | - @Override | ||
| 75 | - public void deleteProductCategory(Long id) { | ||
| 76 | - // TODO zange:参考 mall: ProductCategoryServiceImpl 补充下必要的参数校验; | ||
| 77 | - // 校验存在 | ||
| 78 | - validateProductCategoryExists(id); | ||
| 79 | - // 校验是否还有子分类 | ||
| 80 | - if (productCategoryMapper.selectCountByParentId(id) > 0) { | ||
| 81 | - throw exception(product_CATEGORY_EXISTS_CHILDREN); | ||
| 82 | - } | ||
| 83 | - // 校验是否被产品使用 | ||
| 84 | - if (crmProductService.getProductByCategoryId(id) !=null) { | ||
| 85 | - throw exception(PRODUCT_CATEGORY_USED); | ||
| 86 | - } | ||
| 87 | - // 删除 | ||
| 88 | - productCategoryMapper.deleteById(id); | ||
| 89 | - } | ||
| 90 | - | ||
| 91 | private void validateProductCategoryExists(Long id) { | 62 | private void validateProductCategoryExists(Long id) { |
| 92 | if (productCategoryMapper.selectById(id) == null) { | 63 | if (productCategoryMapper.selectById(id) == null) { |
| 93 | throw exception(PRODUCT_CATEGORY_NOT_EXISTS); | 64 | throw exception(PRODUCT_CATEGORY_NOT_EXISTS); |
| @@ -110,6 +81,32 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService | @@ -110,6 +81,32 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService | ||
| 110 | } | 81 | } |
| 111 | } | 82 | } |
| 112 | 83 | ||
| 84 | + private void validateProductNameExists(Long id, Long parentId, String name) { | ||
| 85 | + CrmProductCategoryDO category = productCategoryMapper.selectByParentIdAndName(parentId, name); | ||
| 86 | + if (category == null | ||
| 87 | + || category.getId().equals(id)) { | ||
| 88 | + return; | ||
| 89 | + } | ||
| 90 | + throw exception(PRODUCT_CATEGORY_EXISTS); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + @Override | ||
| 94 | + public void deleteProductCategory(Long id) { | ||
| 95 | + // TODO zange:参考 mall: ProductCategoryServiceImpl 补充下必要的参数校验; | ||
| 96 | + // 校验存在 | ||
| 97 | + validateProductCategoryExists(id); | ||
| 98 | + // 校验是否还有子分类 | ||
| 99 | + if (productCategoryMapper.selectCountByParentId(id) > 0) { | ||
| 100 | + throw exception(product_CATEGORY_EXISTS_CHILDREN); | ||
| 101 | + } | ||
| 102 | + // 校验是否被产品使用 | ||
| 103 | + if (crmProductService.getProductByCategoryId(id) !=null) { | ||
| 104 | + throw exception(PRODUCT_CATEGORY_USED); | ||
| 105 | + } | ||
| 106 | + // 删除 | ||
| 107 | + productCategoryMapper.deleteById(id); | ||
| 108 | + } | ||
| 109 | + | ||
| 113 | @Override | 110 | @Override |
| 114 | public CrmProductCategoryDO getProductCategory(Long id) { | 111 | public CrmProductCategoryDO getProductCategory(Long id) { |
| 115 | return productCategoryMapper.selectById(id); | 112 | return productCategoryMapper.selectById(id); |