mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +08:00 
			
		
		
		
	Merge remote-tracking branch 'origin/feature/crm' into feature/crm
This commit is contained in:
		| @@ -0,0 +1,89 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.product; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||||
| 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 cn.iocoder.yudao.module.crm.controller.admin.product.vo.*; | ||||
| 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 | ||||
| @RequestMapping("/crm/product") | ||||
| @Validated | ||||
| public class ProductController { | ||||
|  | ||||
|     @Resource | ||||
|     private ProductService productService; | ||||
|  | ||||
|     @PostMapping("/create") | ||||
|     @Operation(summary = "创建产品") | ||||
|     @PreAuthorize("@ss.hasPermission('crm:product:create')") | ||||
|     public CommonResult<Long> createProduct(@Valid @RequestBody ProductCreateReqVO createReqVO) { | ||||
|         return success(productService.createProduct(createReqVO)); | ||||
|     } | ||||
|  | ||||
|     @PutMapping("/update") | ||||
|     @Operation(summary = "更新产品") | ||||
|     @PreAuthorize("@ss.hasPermission('crm:product:update')") | ||||
|     public CommonResult<Boolean> updateProduct(@Valid @RequestBody ProductUpdateReqVO updateReqVO) { | ||||
|         productService.updateProduct(updateReqVO); | ||||
|         return success(true); | ||||
|     } | ||||
|  | ||||
|     @DeleteMapping("/delete") | ||||
|     @Operation(summary = "删除产品") | ||||
|     @Parameter(name = "id", description = "编号", required = true) | ||||
|     @PreAuthorize("@ss.hasPermission('crm:product:delete')") | ||||
|     public CommonResult<Boolean> deleteProduct(@RequestParam("id") Long id) { | ||||
|         productService.deleteProduct(id); | ||||
|         return success(true); | ||||
|     } | ||||
|  | ||||
|     @GetMapping("/get") | ||||
|     @Operation(summary = "获得产品") | ||||
|     @Parameter(name = "id", description = "编号", required = true, example = "1024") | ||||
|     @PreAuthorize("@ss.hasPermission('crm:product:query')") | ||||
|     public CommonResult<ProductRespVO> getProduct(@RequestParam("id") Long id) { | ||||
|         ProductDO product = productService.getProduct(id); | ||||
|         return success(ProductConvert.INSTANCE.convert(product)); | ||||
|     } | ||||
|  | ||||
|     @GetMapping("/page") | ||||
|     @Operation(summary = "获得产品分页") | ||||
|     @PreAuthorize("@ss.hasPermission('crm:product:query')") | ||||
|     public CommonResult<PageResult<ProductRespVO>> getProductPage(@Valid ProductPageReqVO pageVO) { | ||||
|         PageResult<ProductDO> pageResult = productService.getProductPage(pageVO); | ||||
|         return success(ProductConvert.INSTANCE.convertPage(pageResult)); | ||||
|     } | ||||
|  | ||||
|     @GetMapping("/export-excel") | ||||
|     @Operation(summary = "导出产品 Excel") | ||||
|     @PreAuthorize("@ss.hasPermission('crm:product:export')") | ||||
|     @OperateLog(type = EXPORT) | ||||
|     public void exportProductExcel(@Valid ProductExportReqVO exportReqVO, | ||||
|               HttpServletResponse response) throws IOException { | ||||
|         List<ProductDO> list = productService.getProductList(exportReqVO); | ||||
|         // 导出 Excel | ||||
|         List<ProductExcelVO> datas = ProductConvert.INSTANCE.convertList02(list); | ||||
|         ExcelUtils.write(response, "产品.xls", "数据", ProductExcelVO.class, datas); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,49 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.product.vo; | ||||
|  | ||||
| import io.swagger.v3.oas.annotations.media.Schema; | ||||
| import lombok.Data; | ||||
|  | ||||
| import javax.validation.constraints.NotNull; | ||||
|  | ||||
| // TODO @zange:需要加 CRM 前置噢 | ||||
| /** | ||||
|  * 产品 Base VO,提供给添加、修改、详细的子 VO 使用 | ||||
|  * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | ||||
|  */ | ||||
| @Data | ||||
| public class ProductBaseVO { | ||||
|  | ||||
|     // TODO @zange:example 要写哈;主要是接口文档,可以基于 example 可以生产请求参数 | ||||
|  | ||||
|     @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") | ||||
|     @NotNull(message = "产品名称不能为空") | ||||
|     private String name; | ||||
|  | ||||
|     @Schema(description = "产品编码", requiredMode = Schema.RequiredMode.REQUIRED) | ||||
|     @NotNull(message = "产品编码不能为空") | ||||
|     private String no; | ||||
|  | ||||
|     @Schema(description = "单位") | ||||
|     private String unit; | ||||
|  | ||||
|     @Schema(description = "价格", example = "8911") | ||||
|     private Long price; | ||||
|  | ||||
|     @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | ||||
|     @NotNull(message = "状态不能为空") | ||||
|     private Integer status; | ||||
|  | ||||
|     @Schema(description = "产品分类ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1738") | ||||
|     @NotNull(message = "产品分类ID不能为空") | ||||
|     private Long categoryId; | ||||
|  | ||||
|     @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; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +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 javax.validation.constraints.*; | ||||
|  | ||||
| @Schema(description = "管理后台 - 产品创建 Request VO") | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @ToString(callSuper = true) | ||||
| public class ProductCreateReqVO extends ProductBaseVO { | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,50 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.product.vo; | ||||
|  | ||||
| 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 | ||||
|  * | ||||
|  * @author ZanGe丶 | ||||
|  */ | ||||
| @Data | ||||
| public class ProductExcelVO { | ||||
|  | ||||
|     @ExcelProperty("主键id") | ||||
|     private Long id; | ||||
|  | ||||
|     @ExcelProperty("产品名称") | ||||
|     private String name; | ||||
|  | ||||
|     @ExcelProperty("产品编码") | ||||
|     private String no; | ||||
|  | ||||
|     @ExcelProperty("单位") | ||||
|     private String unit; | ||||
|  | ||||
|     @ExcelProperty("价格") | ||||
|     private Long price; | ||||
|  | ||||
|     @ExcelProperty(value = "状态", converter = DictConvert.class) | ||||
|     @DictFormat("crm_product_status") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 | ||||
|     private Integer status; | ||||
|  | ||||
|     @ExcelProperty("产品分类ID") | ||||
|     private Long categoryId; | ||||
|  | ||||
|     @ExcelProperty("产品描述") | ||||
|     private String description; | ||||
|  | ||||
|     @ExcelProperty("负责人的用户编号") | ||||
|     private Long ownerUserId; | ||||
|  | ||||
|     @ExcelProperty("创建时间") | ||||
|     private LocalDateTime createTime; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,44 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.product.vo; | ||||
|  | ||||
| import io.swagger.v3.oas.annotations.media.Schema; | ||||
| 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 { | ||||
|  | ||||
|     @Schema(description = "产品名称", example = "李四") | ||||
|     private String name; | ||||
|  | ||||
|     @Schema(description = "产品编码") | ||||
|     private String no; | ||||
|  | ||||
|     @Schema(description = "单位") | ||||
|     private String unit; | ||||
|  | ||||
|     @Schema(description = "价格", example = "8911") | ||||
|     private Long price; | ||||
|  | ||||
|     @Schema(description = "状态", example = "2") | ||||
|     private Integer status; | ||||
|  | ||||
|     @Schema(description = "产品分类ID", example = "1738") | ||||
|     private Long categoryId; | ||||
|  | ||||
|     @Schema(description = "产品描述", example = "你说的对") | ||||
|     private String description; | ||||
|  | ||||
|     @Schema(description = "负责人的用户编号", example = "31926") | ||||
|     private Long ownerUserId; | ||||
|  | ||||
|     @Schema(description = "创建时间") | ||||
|     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||||
|     private LocalDateTime[] createTime; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,49 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.product.vo; | ||||
|  | ||||
| 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) | ||||
| @ToString(callSuper = true) | ||||
| public class ProductPageReqVO extends PageParam { | ||||
|  | ||||
|     @Schema(description = "产品名称", example = "李四") | ||||
|     private String name; | ||||
|  | ||||
|     @Schema(description = "产品编码") | ||||
|     private String no; | ||||
|  | ||||
|     @Schema(description = "单位") | ||||
|     private String unit; | ||||
|  | ||||
|     @Schema(description = "价格", example = "8911") | ||||
|     private Long price; | ||||
|  | ||||
|     @Schema(description = "状态", example = "2") | ||||
|     private Integer status; | ||||
|  | ||||
|     @Schema(description = "产品分类ID", example = "1738") | ||||
|     private Long categoryId; | ||||
|  | ||||
|     @Schema(description = "产品描述", example = "你说的对") | ||||
|     private String description; | ||||
|  | ||||
|     @Schema(description = "负责人的用户编号", example = "31926") | ||||
|     private Long ownerUserId; | ||||
|  | ||||
|     @Schema(description = "创建时间") | ||||
|     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||||
|     private LocalDateTime[] createTime; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,19 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.product.vo; | ||||
|  | ||||
| import io.swagger.v3.oas.annotations.media.Schema; | ||||
| import lombok.*; | ||||
| import java.time.LocalDateTime; | ||||
|  | ||||
| @Schema(description = "管理后台 - 产品 Response VO") | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @ToString(callSuper = true) | ||||
| public class ProductRespVO extends ProductBaseVO { | ||||
|  | ||||
|     @Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "20529") | ||||
|     private Long id; | ||||
|  | ||||
|     @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||||
|     private LocalDateTime createTime; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,18 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.product.vo; | ||||
|  | ||||
| import io.swagger.v3.oas.annotations.media.Schema; | ||||
| import lombok.*; | ||||
| import java.util.*; | ||||
| import javax.validation.constraints.*; | ||||
|  | ||||
| @Schema(description = "管理后台 - 产品更新 Request VO") | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @ToString(callSuper = true) | ||||
| public class ProductUpdateReqVO extends ProductBaseVO { | ||||
|  | ||||
|     @Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "20529") | ||||
|     @NotNull(message = "主键id不能为空") | ||||
|     private Long id; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,81 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.productcategory; | ||||
|  | ||||
| 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.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.productcategory.vo.*; | ||||
| import cn.iocoder.yudao.module.crm.dal.dataobject.productcategory.ProductCategoryDO; | ||||
| import cn.iocoder.yudao.module.crm.convert.productcategory.ProductCategoryConvert; | ||||
| import cn.iocoder.yudao.module.crm.service.productcategory.ProductCategoryService; | ||||
|  | ||||
| @Tag(name = "管理后台 - 产品分类") | ||||
| @RestController | ||||
| @RequestMapping("/crm/product-category") | ||||
| @Validated | ||||
| public class ProductCategoryController { | ||||
|  | ||||
|     @Resource | ||||
|     private ProductCategoryService productCategoryService; | ||||
|  | ||||
|     @PostMapping("/create") | ||||
|     @Operation(summary = "创建产品分类") | ||||
|     @PreAuthorize("@ss.hasPermission('crm:product-category:create')") | ||||
|     public CommonResult<Long> createProductCategory(@Valid @RequestBody ProductCategoryCreateReqVO createReqVO) { | ||||
|         return success(productCategoryService.createProductCategory(createReqVO)); | ||||
|     } | ||||
|  | ||||
|     @PutMapping("/update") | ||||
|     @Operation(summary = "更新产品分类") | ||||
|     @PreAuthorize("@ss.hasPermission('crm:product-category:update')") | ||||
|     public CommonResult<Boolean> updateProductCategory(@Valid @RequestBody ProductCategoryUpdateReqVO updateReqVO) { | ||||
|         productCategoryService.updateProductCategory(updateReqVO); | ||||
|         return success(true); | ||||
|     } | ||||
|  | ||||
|     @DeleteMapping("/delete") | ||||
|     @Operation(summary = "删除产品分类") | ||||
|     @Parameter(name = "id", description = "编号", required = true) | ||||
|     @PreAuthorize("@ss.hasPermission('crm:product-category:delete')") | ||||
|     public CommonResult<Boolean> deleteProductCategory(@RequestParam("id") Long id) { | ||||
|         productCategoryService.deleteProductCategory(id); | ||||
|         return success(true); | ||||
|     } | ||||
|  | ||||
|     @GetMapping("/get") | ||||
|     @Operation(summary = "获得产品分类") | ||||
|     @Parameter(name = "id", description = "编号", required = true, example = "1024") | ||||
|     @PreAuthorize("@ss.hasPermission('crm:product-category:query')") | ||||
|     public CommonResult<ProductCategoryRespVO> getProductCategory(@RequestParam("id") Long id) { | ||||
|         ProductCategoryDO productCategory = productCategoryService.getProductCategory(id); | ||||
|         return success(ProductCategoryConvert.INSTANCE.convert(productCategory)); | ||||
|     } | ||||
|  | ||||
|     @GetMapping("/list") | ||||
|     @Operation(summary = "获得产品分类列表") | ||||
|     @PreAuthorize("@ss.hasPermission('crm:product-category:query')") | ||||
|     public CommonResult<List<ProductCategoryRespVO>> getProductCategoryList(@Valid ProductCategoryListReqVO treeListReqVO) { | ||||
|         List<ProductCategoryDO> list = productCategoryService.getProductCategoryList(treeListReqVO); | ||||
|         return success(ProductCategoryConvert.INSTANCE.convertList(list)); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,23 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo; | ||||
|  | ||||
| import io.swagger.v3.oas.annotations.media.Schema; | ||||
| import lombok.Data; | ||||
|  | ||||
| import javax.validation.constraints.NotNull; | ||||
|  | ||||
| /** | ||||
|  * 产品分类 Base VO,提供给添加、修改、详细的子 VO 使用 | ||||
|  * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | ||||
|  */ | ||||
| @Data | ||||
| public class ProductCategoryBaseVO { | ||||
|  | ||||
|     @Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") | ||||
|     @NotNull(message = "名称不能为空") | ||||
|     private String name; | ||||
|  | ||||
|     @Schema(description = "父级 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "4680") | ||||
|     @NotNull(message = "父级 id 不能为空") | ||||
|     private Long parentId; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo; | ||||
|  | ||||
| import lombok.*; | ||||
| import java.util.*; | ||||
| import io.swagger.v3.oas.annotations.media.Schema; | ||||
| import javax.validation.constraints.*; | ||||
|  | ||||
| @Schema(description = "管理后台 - 产品分类创建 Request VO") | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @ToString(callSuper = true) | ||||
| public class ProductCategoryCreateReqVO extends ProductCategoryBaseVO { | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,23 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo; | ||||
|  | ||||
| import com.alibaba.excel.annotation.ExcelProperty; | ||||
| import io.swagger.v3.oas.annotations.media.Schema; | ||||
| import lombok.Data; | ||||
|  | ||||
| import java.time.LocalDateTime; | ||||
|  | ||||
| // TODO 芋艿:这个导出最后搞;命名应该是按照 ProductExportReqVO 风格 | ||||
| @Schema(description = "管理后台 - 产品分类列表 Request VO") | ||||
| @Data | ||||
| public class ProductCategoryListReqVO { | ||||
|  | ||||
|     @ExcelProperty("名称") | ||||
|     private String name; | ||||
|  | ||||
|     @ExcelProperty("父级 id") | ||||
|     private Long parentId; | ||||
|  | ||||
|     @ExcelProperty("创建时间") | ||||
|     private LocalDateTime createTime; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,19 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo; | ||||
|  | ||||
| import io.swagger.v3.oas.annotations.media.Schema; | ||||
| import lombok.*; | ||||
| import java.time.LocalDateTime; | ||||
|  | ||||
| @Schema(description = "管理后台 - 产品分类 Response VO") | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @ToString(callSuper = true) | ||||
| public class ProductCategoryRespVO extends ProductCategoryBaseVO { | ||||
|  | ||||
|     @Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "23902") | ||||
|     private Long id; | ||||
|  | ||||
|     @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||||
|     private LocalDateTime createTime; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,20 @@ | ||||
| package cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo; | ||||
|  | ||||
| import io.swagger.v3.oas.annotations.media.Schema; | ||||
| import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | ||||
| import lombok.ToString; | ||||
|  | ||||
| import javax.validation.constraints.NotNull; | ||||
|  | ||||
| @Schema(description = "管理后台 - 产品分类更新 Request VO") | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @ToString(callSuper = true) | ||||
| public class ProductCategoryUpdateReqVO extends ProductCategoryBaseVO { | ||||
|  | ||||
|     @Schema(description = "主键 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "23902") | ||||
|     @NotNull(message = "主键 id 不能为空") | ||||
|     private Long id; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,34 @@ | ||||
| package cn.iocoder.yudao.module.crm.convert.product; | ||||
|  | ||||
| import java.util.*; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
|  | ||||
| import org.mapstruct.Mapper; | ||||
| import org.mapstruct.factory.Mappers; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.product.vo.*; | ||||
| import cn.iocoder.yudao.module.crm.dal.dataobject.product.ProductDO; | ||||
|  | ||||
| /** | ||||
|  * 产品 Convert | ||||
|  * | ||||
|  * @author ZanGe丶 | ||||
|  */ | ||||
| @Mapper | ||||
| public interface ProductConvert { | ||||
|  | ||||
|     ProductConvert INSTANCE = Mappers.getMapper(ProductConvert.class); | ||||
|  | ||||
|     ProductDO convert(ProductCreateReqVO bean); | ||||
|  | ||||
|     ProductDO convert(ProductUpdateReqVO bean); | ||||
|  | ||||
|     ProductRespVO convert(ProductDO bean); | ||||
|  | ||||
|     List<ProductRespVO> convertList(List<ProductDO> list); | ||||
|  | ||||
|     PageResult<ProductRespVO> convertPage(PageResult<ProductDO> page); | ||||
|  | ||||
|     List<ProductExcelVO> convertList02(List<ProductDO> list); | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,30 @@ | ||||
| package cn.iocoder.yudao.module.crm.convert.productcategory; | ||||
|  | ||||
| import java.util.*; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
|  | ||||
| import org.mapstruct.Mapper; | ||||
| import org.mapstruct.factory.Mappers; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo.*; | ||||
| import cn.iocoder.yudao.module.crm.dal.dataobject.productcategory.ProductCategoryDO; | ||||
|  | ||||
| /** | ||||
|  * 产品分类 Convert | ||||
|  * | ||||
|  * @author ZanGe丶 | ||||
|  */ | ||||
| @Mapper | ||||
| public interface ProductCategoryConvert { | ||||
|  | ||||
|     ProductCategoryConvert INSTANCE = Mappers.getMapper(ProductCategoryConvert.class); | ||||
|  | ||||
|     ProductCategoryDO convert(ProductCategoryCreateReqVO bean); | ||||
|  | ||||
|     ProductCategoryDO convert(ProductCategoryUpdateReqVO bean); | ||||
|  | ||||
|     ProductCategoryRespVO convert(ProductCategoryDO bean); | ||||
|  | ||||
|     List<ProductCategoryRespVO> convertList(List<ProductCategoryDO> list); | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,66 @@ | ||||
| package cn.iocoder.yudao.module.crm.dal.dataobject.product; | ||||
|  | ||||
| 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 | ||||
|  * | ||||
|  * @author ZanGe丶 | ||||
|  */ | ||||
| @TableName("crm_product") | ||||
| @KeySequence("crm_product_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @ToString(callSuper = true) | ||||
| @Builder | ||||
| @NoArgsConstructor | ||||
| @AllArgsConstructor | ||||
| public class ProductDO extends BaseDO { | ||||
|  | ||||
|     /** | ||||
|      * 主键 id | ||||
|      */ | ||||
|     @TableId | ||||
|     private Long id; | ||||
|     /** | ||||
|      * 产品名称 | ||||
|      */ | ||||
|     private String name; | ||||
|     /** | ||||
|      * 产品编码 | ||||
|      */ | ||||
|     private String no; | ||||
|     /** | ||||
|      * 单位 | ||||
|      */ | ||||
|     private String unit; | ||||
|     /** | ||||
|      * 价格 | ||||
|      */ | ||||
|     private Long price; | ||||
|     /** | ||||
|      * 状态 | ||||
|      * | ||||
|      * 枚举 {@link TODO crm_product_status 对应的类} | ||||
|      * // TODO @zange:这个写个枚举类,然后 {@link关联下 | ||||
|      */ | ||||
|     private Integer status; | ||||
|     /** | ||||
|      * 产品分类 ID | ||||
|      * // TODO @zange:这个要写下关联 CategoryDO 的 id 字段;参考下别的模块哈 | ||||
|      */ | ||||
|     private Long categoryId; | ||||
|     /** | ||||
|      * 产品描述 | ||||
|      */ | ||||
|     private String description; | ||||
|     /** | ||||
|      * 负责人的用户编号 | ||||
|      */ | ||||
|     private Long ownerUserId; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,39 @@ | ||||
| package cn.iocoder.yudao.module.crm.dal.dataobject.productcategory; | ||||
|  | ||||
| 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 | ||||
|  * | ||||
|  * @author ZanGe丶 | ||||
|  */ | ||||
| @TableName("crm_product_category") | ||||
| @KeySequence("crm_product_category_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @ToString(callSuper = true) | ||||
| @Builder | ||||
| @NoArgsConstructor | ||||
| @AllArgsConstructor | ||||
| public class ProductCategoryDO extends BaseDO { | ||||
|  | ||||
|     /** | ||||
|      * 主键id | ||||
|      */ | ||||
|     @TableId | ||||
|     private Long id; | ||||
|     /** | ||||
|      * 名称 | ||||
|      */ | ||||
|     private String name; | ||||
|     /** | ||||
|      * 父级 id | ||||
|      * // TODO @zange:这个要写下关联 CategoryDO 的 id 字段;参考下别的模块哈 | ||||
|      */ | ||||
|     private Long parentId; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,48 @@ | ||||
| package cn.iocoder.yudao.module.crm.dal.mysql.product; | ||||
|  | ||||
| import java.util.*; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
| import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||||
| import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||||
| import cn.iocoder.yudao.module.crm.dal.dataobject.product.ProductDO; | ||||
| import org.apache.ibatis.annotations.Mapper; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.product.vo.*; | ||||
|  | ||||
| /** | ||||
|  * 产品 Mapper | ||||
|  * | ||||
|  * @author ZanGe丶 | ||||
|  */ | ||||
| @Mapper | ||||
| public interface ProductMapper extends BaseMapperX<ProductDO> { | ||||
|  | ||||
|     default PageResult<ProductDO> selectPage(ProductPageReqVO reqVO) { | ||||
|         return selectPage(reqVO, new LambdaQueryWrapperX<ProductDO>() | ||||
|                 .likeIfPresent(ProductDO::getName, reqVO.getName()) | ||||
|                 .likeIfPresent(ProductDO::getNo, reqVO.getNo()) | ||||
|                 .eqIfPresent(ProductDO::getUnit, reqVO.getUnit()) | ||||
|                 .eqIfPresent(ProductDO::getPrice, reqVO.getPrice()) | ||||
|                 .eqIfPresent(ProductDO::getStatus, reqVO.getStatus()) | ||||
|                 .eqIfPresent(ProductDO::getCategoryId, reqVO.getCategoryId()) | ||||
|                 .eqIfPresent(ProductDO::getDescription, reqVO.getDescription()) | ||||
|                 .eqIfPresent(ProductDO::getOwnerUserId, reqVO.getOwnerUserId()) | ||||
|                 .betweenIfPresent(ProductDO::getCreateTime, reqVO.getCreateTime()) | ||||
|                 .orderByDesc(ProductDO::getId)); | ||||
|     } | ||||
|  | ||||
|     default List<ProductDO> selectList(ProductExportReqVO reqVO) { | ||||
|         return selectList(new LambdaQueryWrapperX<ProductDO>() | ||||
|                 .likeIfPresent(ProductDO::getName, reqVO.getName()) | ||||
|                 .likeIfPresent(ProductDO::getNo, reqVO.getNo()) | ||||
|                 .eqIfPresent(ProductDO::getUnit, reqVO.getUnit()) | ||||
|                 .eqIfPresent(ProductDO::getPrice, reqVO.getPrice()) | ||||
|                 .eqIfPresent(ProductDO::getStatus, reqVO.getStatus()) | ||||
|                 .eqIfPresent(ProductDO::getCategoryId, reqVO.getCategoryId()) | ||||
|                 .eqIfPresent(ProductDO::getDescription, reqVO.getDescription()) | ||||
|                 .eqIfPresent(ProductDO::getOwnerUserId, reqVO.getOwnerUserId()) | ||||
|                 .betweenIfPresent(ProductDO::getCreateTime, reqVO.getCreateTime()) | ||||
|                 .orderByDesc(ProductDO::getId)); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,28 @@ | ||||
| package cn.iocoder.yudao.module.crm.dal.mysql.productcategory; | ||||
|  | ||||
| import java.util.*; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
| import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||||
| import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||||
| import cn.iocoder.yudao.module.crm.dal.dataobject.productcategory.ProductCategoryDO; | ||||
| import org.apache.ibatis.annotations.Mapper; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo.*; | ||||
|  | ||||
| /** | ||||
|  * 产品分类 Mapper | ||||
|  * | ||||
|  * @author ZanGe丶 | ||||
|  */ | ||||
| @Mapper | ||||
| public interface ProductCategoryMapper extends BaseMapperX<ProductCategoryDO> { | ||||
|  | ||||
|  | ||||
|     default List<ProductCategoryDO> selectList(ProductCategoryListReqVO reqVO) { | ||||
|         return selectList(new LambdaQueryWrapperX<ProductCategoryDO>() | ||||
|                 .likeIfPresent(ProductCategoryDO::getName, reqVO.getName()) | ||||
|                 .eqIfPresent(ProductCategoryDO::getParentId, reqVO.getParentId()) | ||||
|                 .orderByDesc(ProductCategoryDO::getId)); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,70 @@ | ||||
| package cn.iocoder.yudao.module.crm.service.product; | ||||
|  | ||||
| import java.util.*; | ||||
| import javax.validation.*; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.product.vo.*; | ||||
| import cn.iocoder.yudao.module.crm.dal.dataobject.product.ProductDO; | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
|  | ||||
| /** | ||||
|  * 产品 Service 接口 | ||||
|  * | ||||
|  * @author ZanGe丶 | ||||
|  */ | ||||
| public interface ProductService { | ||||
|  | ||||
|     /** | ||||
|      * 创建产品 | ||||
|      * | ||||
|      * @param createReqVO 创建信息 | ||||
|      * @return 编号 | ||||
|      */ | ||||
|     Long createProduct(@Valid ProductCreateReqVO createReqVO); | ||||
|  | ||||
|     /** | ||||
|      * 更新产品 | ||||
|      * | ||||
|      * @param updateReqVO 更新信息 | ||||
|      */ | ||||
|     void updateProduct(@Valid ProductUpdateReqVO updateReqVO); | ||||
|  | ||||
|     /** | ||||
|      * 删除产品 | ||||
|      * | ||||
|      * @param id 编号 | ||||
|      */ | ||||
|     void deleteProduct(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 获得产品 | ||||
|      * | ||||
|      * @param id 编号 | ||||
|      * @return 产品 | ||||
|      */ | ||||
|     ProductDO getProduct(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 获得产品列表 | ||||
|      * | ||||
|      * @param ids 编号 | ||||
|      * @return 产品列表 | ||||
|      */ | ||||
|     List<ProductDO> getProductList(Collection<Long> ids); | ||||
|  | ||||
|     /** | ||||
|      * 获得产品分页 | ||||
|      * | ||||
|      * @param pageReqVO 分页查询 | ||||
|      * @return 产品分页 | ||||
|      */ | ||||
|     PageResult<ProductDO> getProductPage(ProductPageReqVO pageReqVO); | ||||
|  | ||||
|     /** | ||||
|      * 获得产品列表, 用于 Excel 导出 | ||||
|      * | ||||
|      * @param exportReqVO 查询条件 | ||||
|      * @return 产品列表 | ||||
|      */ | ||||
|     List<ProductDO> getProductList(ProductExportReqVO exportReqVO); | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,108 @@ | ||||
| package cn.iocoder.yudao.module.crm.service.product; | ||||
|  | ||||
| import cn.hutool.core.collection.CollUtil; | ||||
| import cn.hutool.core.collection.ListUtil; | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.product.vo.ProductCreateReqVO; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.product.vo.ProductExportReqVO; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.product.vo.ProductPageReqVO; | ||||
| import cn.iocoder.yudao.module.crm.controller.admin.product.vo.ProductUpdateReqVO; | ||||
| 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.dal.mysql.product.ProductMapper; | ||||
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||||
| import org.springframework.stereotype.Service; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import java.util.Collection; | ||||
| import java.util.List; | ||||
|  | ||||
| import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||||
| import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.PRODUCT_NOT_EXISTS; | ||||
| import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.PRODUCT_NO_EXISTS; | ||||
|  | ||||
| /** | ||||
|  * 产品 Service 实现类 | ||||
|  * | ||||
|  * @author ZanGe丶 | ||||
|  */ | ||||
| @Service | ||||
| @Validated | ||||
| public class ProductServiceImpl implements ProductService { | ||||
|  | ||||
|     @Resource | ||||
|     private ProductMapper productMapper; | ||||
|  | ||||
|     @Override | ||||
|     public Long createProduct(ProductCreateReqVO createReqVO) { | ||||
|         // 校验产品编号是否存在 | ||||
|         validateProductNo(createReqVO.getNo()); | ||||
|         // TODO @zange:需要校验 categoryId 是否存在; | ||||
|         // 插入 | ||||
|         ProductDO product = ProductConvert.INSTANCE.convert(createReqVO); | ||||
|         productMapper.insert(product); | ||||
|         // 返回 | ||||
|         return product.getId(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void updateProduct(ProductUpdateReqVO updateReqVO) { | ||||
|         // 校验存在 | ||||
|         validateProductExists(updateReqVO.getId(), updateReqVO.getNo()); | ||||
|         // TODO @zange:需要校验 categoryId 是否存在; | ||||
|         // 更新 | ||||
|         ProductDO updateObj = ProductConvert.INSTANCE.convert(updateReqVO); | ||||
|         productMapper.updateById(updateObj); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void deleteProduct(Long id) { | ||||
|         // 校验存在 | ||||
|         validateProductExists(id, null); | ||||
|         // 删除 | ||||
|         productMapper.deleteById(id); | ||||
|     } | ||||
|  | ||||
|     // TODO @zange:validateProductExists 要不只校验是否存在;然后是否 no 重复,交给 validateProductNo,名字改成 validateProductNoDuplicate,和别的模块保持一致哈; | ||||
|     private void validateProductExists(Long id, String no) { | ||||
|         ProductDO product = productMapper.selectById(id); | ||||
|         if (product == null) { | ||||
|             throw exception(PRODUCT_NOT_EXISTS); | ||||
|         } | ||||
|         if (no != null && no.equals(product.getNo())) { | ||||
|             throw exception(PRODUCT_NO_EXISTS); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public ProductDO getProduct(Long id) { | ||||
|         return productMapper.selectById(id); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public List<ProductDO> getProductList(Collection<Long> ids) { | ||||
|         if (CollUtil.isEmpty(ids)) { | ||||
|             return ListUtil.empty(); | ||||
|         } | ||||
|         return productMapper.selectBatchIds(ids); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public PageResult<ProductDO> getProductPage(ProductPageReqVO pageReqVO) { | ||||
|         return productMapper.selectPage(pageReqVO); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public List<ProductDO> getProductList(ProductExportReqVO exportReqVO) { | ||||
|         return productMapper.selectList(exportReqVO); | ||||
|     } | ||||
|  | ||||
|     private void validateProductNo(String no) { | ||||
|         ProductDO product = productMapper.selectOne(new LambdaQueryWrapper<ProductDO>().eq(ProductDO::getNo, no)); | ||||
|         if (product != null) { | ||||
|             throw exception(PRODUCT_NO_EXISTS); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,54 @@ | ||||
| package cn.iocoder.yudao.module.crm.service.productcategory; | ||||
|  | ||||
| import java.util.*; | ||||
| import javax.validation.*; | ||||
| 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; | ||||
|  | ||||
| /** | ||||
|  * 产品分类 Service 接口 | ||||
|  * | ||||
|  * @author ZanGe丶 | ||||
|  */ | ||||
| public interface ProductCategoryService { | ||||
|  | ||||
|     /** | ||||
|      * 创建产品分类 | ||||
|      * | ||||
|      * @param createReqVO 创建信息 | ||||
|      * @return 编号 | ||||
|      */ | ||||
|     Long createProductCategory(@Valid ProductCategoryCreateReqVO createReqVO); | ||||
|  | ||||
|     /** | ||||
|      * 更新产品分类 | ||||
|      * | ||||
|      * @param updateReqVO 更新信息 | ||||
|      */ | ||||
|     void updateProductCategory(@Valid ProductCategoryUpdateReqVO updateReqVO); | ||||
|  | ||||
|     /** | ||||
|      * 删除产品分类 | ||||
|      * | ||||
|      * @param id 编号 | ||||
|      */ | ||||
|     void deleteProductCategory(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 获得产品分类 | ||||
|      * | ||||
|      * @param id 编号 | ||||
|      * @return 产品分类 | ||||
|      */ | ||||
|     ProductCategoryDO getProductCategory(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 获得产品分类列表 | ||||
|      * | ||||
|      * @param ids 编号 | ||||
|      * @return 产品分类列表 | ||||
|      */ | ||||
|     List<ProductCategoryDO> getProductCategoryList(ProductCategoryListReqVO treeListReqVO); | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,76 @@ | ||||
| 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 org.springframework.validation.annotation.Validated; | ||||
|  | ||||
| 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.PRODUCT_CATEGORY_NOT_EXISTS; | ||||
|  | ||||
| // TODO @zange:这个类所在的包,放到 product 下; | ||||
| /** | ||||
|  * 产品分类 Service 实现类 | ||||
|  * | ||||
|  * @author ZanGe丶 | ||||
|  */ | ||||
| @Service | ||||
| @Validated | ||||
| public class ProductCategoryServiceImpl implements ProductCategoryService { | ||||
|  | ||||
|     @Resource | ||||
|     private ProductCategoryMapper productCategoryMapper; | ||||
|  | ||||
|     @Override | ||||
|     public Long createProductCategory(ProductCategoryCreateReqVO createReqVO) { | ||||
|         // TODO zange:参考 mall: ProductCategoryServiceImpl 补充下必要的参数校验; | ||||
|         // 插入 | ||||
|         ProductCategoryDO productCategory = ProductCategoryConvert.INSTANCE.convert(createReqVO); | ||||
|         productCategoryMapper.insert(productCategory); | ||||
|         // 返回 | ||||
|         return productCategory.getId(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void updateProductCategory(ProductCategoryUpdateReqVO updateReqVO) { | ||||
|         // TODO zange:参考 mall: ProductCategoryServiceImpl 补充下必要的参数校验; | ||||
|         // 校验存在 | ||||
|         validateProductCategoryExists(updateReqVO.getId()); | ||||
|         // 更新 | ||||
|         ProductCategoryDO updateObj = ProductCategoryConvert.INSTANCE.convert(updateReqVO); | ||||
|         productCategoryMapper.updateById(updateObj); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void deleteProductCategory(Long id) { | ||||
|         // TODO zange:参考 mall: ProductCategoryServiceImpl 补充下必要的参数校验; | ||||
|         // 校验存在 | ||||
|         validateProductCategoryExists(id); | ||||
|         // 删除 | ||||
|         productCategoryMapper.deleteById(id); | ||||
|     } | ||||
|  | ||||
|     private void validateProductCategoryExists(Long id) { | ||||
|         if (productCategoryMapper.selectById(id) == null) { | ||||
|             throw exception(PRODUCT_CATEGORY_NOT_EXISTS); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public ProductCategoryDO getProductCategory(Long id) { | ||||
|         return productCategoryMapper.selectById(id); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public List<ProductCategoryDO> getProductCategoryList(ProductCategoryListReqVO treeListReqVO) { | ||||
|         return productCategoryMapper.selectList(treeListReqVO); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,12 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||||
| <mapper namespace="cn.iocoder.yudao.module.crm.dal.mysql.product.ProductMapper"> | ||||
|  | ||||
|     <!-- | ||||
|         一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 | ||||
|         无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 | ||||
|         代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 | ||||
|         文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ | ||||
|      --> | ||||
|  | ||||
| </mapper> | ||||
| @@ -0,0 +1,12 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||||
| <mapper namespace="cn.iocoder.yudao.module.crm.dal.mysql.productcategory.ProductCategoryMapper"> | ||||
|  | ||||
|     <!-- | ||||
|         一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 | ||||
|         无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 | ||||
|         代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 | ||||
|         文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ | ||||
|      --> | ||||
|  | ||||
| </mapper> | ||||
		Reference in New Issue
	
	Block a user
	 Wanwan
					Wanwan