mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 10:18:42 +08:00 
			
		
		
		
	code review:crm 商品逻辑
This commit is contained in:
		| @@ -1,32 +1,28 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.product; | ||||
|  | ||||
| import org.springframework.web.bind.annotation.*; | ||||
| import javax.annotation.Resource; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
| import org.springframework.security.access.prepost.PreAuthorize; | ||||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||||
| import io.swagger.v3.oas.annotations.Parameter; | ||||
| import io.swagger.v3.oas.annotations.Operation; | ||||
|  | ||||
| import javax.validation.constraints.*; | ||||
| import javax.validation.*; | ||||
| import javax.servlet.http.*; | ||||
| import java.util.*; | ||||
| import java.io.IOException; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
| import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||||
| import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
| import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | ||||
| import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | ||||
|  | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.product.vo.*; | ||||
| import cn.iocoder.yudao.module.crm.dal.dataobject.product.ProductDO; | ||||
| import cn.iocoder.yudao.module.crm.convert.product.ProductConvert; | ||||
| import cn.iocoder.yudao.module.crm.dal.dataobject.product.ProductDO; | ||||
| import cn.iocoder.yudao.module.crm.service.product.ProductService; | ||||
| import io.swagger.v3.oas.annotations.Operation; | ||||
| import io.swagger.v3.oas.annotations.Parameter; | ||||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||||
| import org.springframework.security.access.prepost.PreAuthorize; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
| import org.springframework.web.bind.annotation.*; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import javax.servlet.http.HttpServletResponse; | ||||
| import javax.validation.Valid; | ||||
| import java.io.IOException; | ||||
| import java.util.List; | ||||
|  | ||||
| import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||||
| import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | ||||
|  | ||||
| @Tag(name = "管理后台 - 产品") | ||||
| @RestController | ||||
| @@ -70,15 +66,6 @@ public class ProductController { | ||||
|         return success(ProductConvert.INSTANCE.convert(product)); | ||||
|     } | ||||
|  | ||||
|     @GetMapping("/list") | ||||
|     @Operation(summary = "获得产品列表") | ||||
|     @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") | ||||
|     @PreAuthorize("@ss.hasPermission('crm:product:query')") | ||||
|     public CommonResult<List<ProductRespVO>> getProductList(@RequestParam("ids") Collection<Long> ids) { | ||||
|         List<ProductDO> list = productService.getProductList(ids); | ||||
|         return success(ProductConvert.INSTANCE.convertList(list)); | ||||
|     } | ||||
|  | ||||
|     @GetMapping("/page") | ||||
|     @Operation(summary = "获得产品分页") | ||||
|     @PreAuthorize("@ss.hasPermission('crm:product:query')") | ||||
|   | ||||
| @@ -1,12 +1,11 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.product.vo; | ||||
|  | ||||
| import io.swagger.v3.oas.annotations.media.Schema; | ||||
| import lombok.*; | ||||
| import java.util.*; | ||||
| import java.time.LocalDateTime; | ||||
| import java.time.LocalDateTime; | ||||
| import javax.validation.constraints.*; | ||||
| import lombok.Data; | ||||
|  | ||||
| import javax.validation.constraints.NotNull; | ||||
|  | ||||
| // TODO @zange:需要加 CRM 前置噢 | ||||
| /** | ||||
|  * 产品 Base VO,提供给添加、修改、详细的子 VO 使用 | ||||
|  * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | ||||
| @@ -14,6 +13,8 @@ import javax.validation.constraints.*; | ||||
| @Data | ||||
| public class ProductBaseVO { | ||||
|  | ||||
|     // TODO @zange:example 要写哈;主要是接口文档,可以基于 example 可以生产请求参数 | ||||
|  | ||||
|     @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") | ||||
|     @NotNull(message = "产品名称不能为空") | ||||
|     private String name; | ||||
| @@ -39,6 +40,8 @@ public class ProductBaseVO { | ||||
|     @Schema(description = "产品描述", example = "你说的对") | ||||
|     private String description; | ||||
|  | ||||
|     // TODO @zange:这个字段只有 create 可以传递,update 不传递;所以放到 create 和 resp 里; | ||||
|  | ||||
|     @Schema(description = "负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31926") | ||||
|     @NotNull(message = "负责人的用户编号不能为空") | ||||
|     private Long ownerUserId; | ||||
|   | ||||
| @@ -1,16 +1,13 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.product.vo; | ||||
|  | ||||
| import io.swagger.v3.oas.annotations.media.Schema; | ||||
| import lombok.*; | ||||
| import java.util.*; | ||||
| import java.time.LocalDateTime; | ||||
| import java.time.LocalDateTime; | ||||
|  | ||||
| import com.alibaba.excel.annotation.ExcelProperty; | ||||
| import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | ||||
| import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | ||||
| import com.alibaba.excel.annotation.ExcelProperty; | ||||
| import lombok.Data; | ||||
|  | ||||
| import java.time.LocalDateTime; | ||||
|  | ||||
| // TODO 芋艿:这个导出最后搞 | ||||
| /** | ||||
|  * 产品 Excel VO | ||||
|  * | ||||
|   | ||||
| @@ -1,14 +1,14 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.product.vo; | ||||
|  | ||||
| import lombok.*; | ||||
| import java.util.*; | ||||
| import io.swagger.v3.oas.annotations.media.Schema; | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||||
| import java.time.LocalDateTime; | ||||
| import lombok.Data; | ||||
| import org.springframework.format.annotation.DateTimeFormat; | ||||
|  | ||||
| import java.time.LocalDateTime; | ||||
|  | ||||
| import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||||
|  | ||||
| // TODO 芋艿:这个导出最后搞 | ||||
| @Schema(description = "管理后台 - 产品 Excel 导出 Request VO,参数和 ProductPageReqVO 是一致的") | ||||
| @Data | ||||
| public class ProductExportReqVO { | ||||
|   | ||||
| @@ -1,14 +1,17 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.product.vo; | ||||
|  | ||||
| import lombok.*; | ||||
| import java.util.*; | ||||
| import io.swagger.v3.oas.annotations.media.Schema; | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||||
| import io.swagger.v3.oas.annotations.media.Schema; | ||||
| import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | ||||
| import lombok.ToString; | ||||
| import org.springframework.format.annotation.DateTimeFormat; | ||||
|  | ||||
| import java.time.LocalDateTime; | ||||
|  | ||||
| import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||||
|  | ||||
| // TODO @zange:按照需求,裁剪下筛选的字段,目前应该只要 name 和 status | ||||
| @Schema(description = "管理后台 - 产品分页 Request VO") | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
|   | ||||
| @@ -1,11 +1,9 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo; | ||||
|  | ||||
| import io.swagger.v3.oas.annotations.media.Schema; | ||||
| import lombok.*; | ||||
| import java.util.*; | ||||
| import java.time.LocalDateTime; | ||||
| import java.time.LocalDateTime; | ||||
| import javax.validation.constraints.*; | ||||
| import lombok.Data; | ||||
|  | ||||
| import javax.validation.constraints.NotNull; | ||||
|  | ||||
| /** | ||||
|  * 产品分类 Base VO,提供给添加、修改、详细的子 VO 使用 | ||||
| @@ -18,8 +16,8 @@ public class ProductCategoryBaseVO { | ||||
|     @NotNull(message = "名称不能为空") | ||||
|     private String name; | ||||
|  | ||||
|     @Schema(description = "父级id", requiredMode = Schema.RequiredMode.REQUIRED, example = "4680") | ||||
|     @NotNull(message = "父级id不能为空") | ||||
|     @Schema(description = "父级 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "4680") | ||||
|     @NotNull(message = "父级 id 不能为空") | ||||
|     private Long parentId; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -6,11 +6,7 @@ import lombok.Data; | ||||
|  | ||||
| import java.time.LocalDateTime; | ||||
|  | ||||
| /** | ||||
|  * 产品分类 List VO | ||||
|  * | ||||
|  * @author ZanGe丶 | ||||
|  */ | ||||
| // TODO 芋艿:这个导出最后搞;命名应该是按照 ProductExportReqVO 风格 | ||||
| @Schema(description = "管理后台 - 产品分类列表 Request VO") | ||||
| @Data | ||||
| public class ProductCategoryListReqVO { | ||||
| @@ -18,7 +14,7 @@ public class ProductCategoryListReqVO { | ||||
|     @ExcelProperty("名称") | ||||
|     private String name; | ||||
|  | ||||
|     @ExcelProperty("父级id") | ||||
|     @ExcelProperty("父级 id") | ||||
|     private Long parentId; | ||||
|  | ||||
|     @ExcelProperty("创建时间") | ||||
|   | ||||
| @@ -1,9 +1,11 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo; | ||||
|  | ||||
| import io.swagger.v3.oas.annotations.media.Schema; | ||||
| import lombok.*; | ||||
| import java.util.*; | ||||
| import javax.validation.constraints.*; | ||||
| import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | ||||
| import lombok.ToString; | ||||
|  | ||||
| import javax.validation.constraints.NotNull; | ||||
|  | ||||
| @Schema(description = "管理后台 - 产品分类更新 Request VO") | ||||
| @Data | ||||
| @@ -11,8 +13,8 @@ import javax.validation.constraints.*; | ||||
| @ToString(callSuper = true) | ||||
| public class ProductCategoryUpdateReqVO extends ProductCategoryBaseVO { | ||||
|  | ||||
|     @Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "23902") | ||||
|     @NotNull(message = "主键id不能为空") | ||||
|     @Schema(description = "主键 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "23902") | ||||
|     @NotNull(message = "主键 id 不能为空") | ||||
|     private Long id; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,11 +1,10 @@ | ||||
| package cn.iocoder.yudao.module.crm.dal.dataobject.product; | ||||
|  | ||||
| import lombok.*; | ||||
| import java.util.*; | ||||
| import java.time.LocalDateTime; | ||||
| import java.time.LocalDateTime; | ||||
| import com.baomidou.mybatisplus.annotation.*; | ||||
| import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||||
| import com.baomidou.mybatisplus.annotation.KeySequence; | ||||
| import com.baomidou.mybatisplus.annotation.TableId; | ||||
| import com.baomidou.mybatisplus.annotation.TableName; | ||||
| import lombok.*; | ||||
|  | ||||
| /** | ||||
|  * 产品 DO | ||||
| @@ -23,7 +22,7 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||||
| public class ProductDO extends BaseDO { | ||||
|  | ||||
|     /** | ||||
|      * 主键id | ||||
|      * 主键 id | ||||
|      */ | ||||
|     @TableId | ||||
|     private Long id; | ||||
| @@ -47,10 +46,12 @@ public class ProductDO extends BaseDO { | ||||
|      * 状态 | ||||
|      * | ||||
|      * 枚举 {@link TODO crm_product_status 对应的类} | ||||
|      * // TODO @zange:这个写个枚举类,然后 {@link关联下 | ||||
|      */ | ||||
|     private Integer status; | ||||
|     /** | ||||
|      * 产品分类ID | ||||
|      * 产品分类 ID | ||||
|      * // TODO @zange:这个要写下关联 CategoryDO 的 id 字段;参考下别的模块哈 | ||||
|      */ | ||||
|     private Long categoryId; | ||||
|     /** | ||||
|   | ||||
| @@ -1,11 +1,10 @@ | ||||
| package cn.iocoder.yudao.module.crm.dal.dataobject.productcategory; | ||||
|  | ||||
| import lombok.*; | ||||
| import java.util.*; | ||||
| import java.time.LocalDateTime; | ||||
| import java.time.LocalDateTime; | ||||
| import com.baomidou.mybatisplus.annotation.*; | ||||
| import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||||
| import com.baomidou.mybatisplus.annotation.KeySequence; | ||||
| import com.baomidou.mybatisplus.annotation.TableId; | ||||
| import com.baomidou.mybatisplus.annotation.TableName; | ||||
| import lombok.*; | ||||
|  | ||||
| /** | ||||
|  * 产品分类 DO | ||||
| @@ -32,7 +31,8 @@ public class ProductCategoryDO extends BaseDO { | ||||
|      */ | ||||
|     private String name; | ||||
|     /** | ||||
|      * 父级id | ||||
|      * 父级 id | ||||
|      * // TODO @zange:这个要写下关联 CategoryDO 的 id 字段;参考下别的模块哈 | ||||
|      */ | ||||
|     private Long parentId; | ||||
|  | ||||
|   | ||||
| @@ -36,8 +36,9 @@ public class ProductServiceImpl implements ProductService { | ||||
|  | ||||
|     @Override | ||||
|     public Long createProduct(ProductCreateReqVO createReqVO) { | ||||
|         //校验产品编号是否存在 | ||||
|         // 校验产品编号是否存在 | ||||
|         validateProductNo(createReqVO.getNo()); | ||||
|         // TODO @zange:需要校验 categoryId 是否存在; | ||||
|         // 插入 | ||||
|         ProductDO product = ProductConvert.INSTANCE.convert(createReqVO); | ||||
|         productMapper.insert(product); | ||||
| @@ -49,6 +50,7 @@ public class ProductServiceImpl implements ProductService { | ||||
|     public void updateProduct(ProductUpdateReqVO updateReqVO) { | ||||
|         // 校验存在 | ||||
|         validateProductExists(updateReqVO.getId(), updateReqVO.getNo()); | ||||
|         // TODO @zange:需要校验 categoryId 是否存在; | ||||
|         // 更新 | ||||
|         ProductDO updateObj = ProductConvert.INSTANCE.convert(updateReqVO); | ||||
|         productMapper.updateById(updateObj); | ||||
| @@ -62,6 +64,7 @@ public class ProductServiceImpl implements ProductService { | ||||
|         productMapper.deleteById(id); | ||||
|     } | ||||
|  | ||||
|     // TODO @zange:validateProductExists 要不只校验是否存在;然后是否 no 重复,交给 validateProductNo,名字改成 validateProductNoDuplicate,和别的模块保持一致哈; | ||||
|     private void validateProductExists(Long id, String no) { | ||||
|         ProductDO product = productMapper.selectById(id); | ||||
|         if (product == null) { | ||||
| @@ -101,4 +104,5 @@ public class ProductServiceImpl implements ProductService { | ||||
|             throw exception(PRODUCT_NO_EXISTS); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,23 +1,21 @@ | ||||
| package cn.iocoder.yudao.module.crm.service.productcategory; | ||||
|  | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo.ProductCategoryCreateReqVO; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo.ProductCategoryListReqVO; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo.ProductCategoryUpdateReqVO; | ||||
| import cn.iocoder.yudao.module.crm.convert.productcategory.ProductCategoryConvert; | ||||
| import cn.iocoder.yudao.module.crm.dal.dataobject.productcategory.ProductCategoryDO; | ||||
| import cn.iocoder.yudao.module.crm.dal.mysql.productcategory.ProductCategoryMapper; | ||||
| import org.springframework.stereotype.Service; | ||||
| import javax.annotation.Resource; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
|  | ||||
| import java.util.*; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo.*; | ||||
| import cn.iocoder.yudao.module.crm.dal.dataobject.productcategory.ProductCategoryDO; | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
|  | ||||
| import cn.iocoder.yudao.module.crm.convert.productcategory.ProductCategoryConvert; | ||||
| import cn.iocoder.yudao.module.crm.dal.mysql.productcategory.ProductCategoryMapper; | ||||
| import javax.annotation.Resource; | ||||
| import java.util.List; | ||||
|  | ||||
| import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||||
| import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; | ||||
|  | ||||
| import cn.hutool.core.collection.CollUtil; | ||||
| import cn.hutool.core.collection.ListUtil; | ||||
| import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.PRODUCT_CATEGORY_NOT_EXISTS; | ||||
|  | ||||
| // TODO @zange:这个类所在的包,放到 product 下; | ||||
| /** | ||||
|  * 产品分类 Service 实现类 | ||||
|  * | ||||
| @@ -32,6 +30,7 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { | ||||
|  | ||||
|     @Override | ||||
|     public Long createProductCategory(ProductCategoryCreateReqVO createReqVO) { | ||||
|         // TODO zange:参考 mall: ProductCategoryServiceImpl 补充下必要的参数校验; | ||||
|         // 插入 | ||||
|         ProductCategoryDO productCategory = ProductCategoryConvert.INSTANCE.convert(createReqVO); | ||||
|         productCategoryMapper.insert(productCategory); | ||||
| @@ -41,6 +40,7 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { | ||||
|  | ||||
|     @Override | ||||
|     public void updateProductCategory(ProductCategoryUpdateReqVO updateReqVO) { | ||||
|         // TODO zange:参考 mall: ProductCategoryServiceImpl 补充下必要的参数校验; | ||||
|         // 校验存在 | ||||
|         validateProductCategoryExists(updateReqVO.getId()); | ||||
|         // 更新 | ||||
| @@ -50,6 +50,7 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { | ||||
|  | ||||
|     @Override | ||||
|     public void deleteProductCategory(Long id) { | ||||
|         // TODO zange:参考 mall: ProductCategoryServiceImpl 补充下必要的参数校验; | ||||
|         // 校验存在 | ||||
|         validateProductCategoryExists(id); | ||||
|         // 删除 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user