Commit e66ded2860fce310eea7c657bf103b81a248ba83

Authored by YunaiV
1 parent bf8ec221

✨ ERP:初始化 product 信息、分类、单位的实现

Showing 28 changed files with 1624 additions and 0 deletions
yudao-module-erp/yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/ErrorCodeConstants.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp;
  2 +
  3 +import cn.iocoder.yudao.framework.common.exception.ErrorCode;
  4 +
  5 +/**
  6 + * ERP 错误码枚举类
  7 + * <p>
  8 + * erp 系统,使用 1-030-000-000 段
  9 + */
  10 +public interface ErrorCodeConstants {
  11 +
  12 + // ========== ERP 产品 1-030-500-000 ==========
  13 + ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_030_500_000, "产品不存在");
  14 +
  15 + // ========== ERP 产品分类 1-030-501-000 ==========
  16 + ErrorCode PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_030_501_000, "产品分类不存在");
  17 + ErrorCode PRODUCT_CATEGORY_EXITS_CHILDREN = new ErrorCode(1_030_501_001, "存在存在子产品分类,无法删除");
  18 + ErrorCode PRODUCT_CATEGORY_PARENT_NOT_EXITS = new ErrorCode(1_030_501_002,"父级产品分类不存在");
  19 + ErrorCode PRODUCT_CATEGORY_PARENT_ERROR = new ErrorCode(1_030_501_003, "不能设置自己为父产品分类");
  20 + ErrorCode PRODUCT_CATEGORY_NAME_DUPLICATE = new ErrorCode(1_030_501_004, "已经存在该分类名称的产品分类");
  21 + ErrorCode PRODUCT_CATEGORY_PARENT_IS_CHILD = new ErrorCode(1_030_501_005, "不能设置自己的子分类为父分类");
  22 +
  23 + // ========== ERP 产品单位 1-030-502-000 ==========
  24 + ErrorCode PRODUCT_UNIT_NOT_EXISTS = new ErrorCode(1_030_502_000, "产品单位不存在");
  25 +
  26 +}
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/ErpProductCategoryController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.product;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  4 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  5 +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
  6 +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
  7 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategoryListReqVO;
  8 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategoryRespVO;
  9 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategorySaveReqVO;
  10 +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO;
  11 +import cn.iocoder.yudao.module.erp.service.product.ErpProductCategoryService;
  12 +import io.swagger.v3.oas.annotations.Operation;
  13 +import io.swagger.v3.oas.annotations.Parameter;
  14 +import io.swagger.v3.oas.annotations.tags.Tag;
  15 +import jakarta.annotation.Resource;
  16 +import jakarta.servlet.http.HttpServletResponse;
  17 +import jakarta.validation.Valid;
  18 +import org.springframework.security.access.prepost.PreAuthorize;
  19 +import org.springframework.validation.annotation.Validated;
  20 +import org.springframework.web.bind.annotation.*;
  21 +
  22 +import java.io.IOException;
  23 +import java.util.List;
  24 +
  25 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  26 +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
  27 +
  28 +@Tag(name = "管理后台 - ERP 产品分类")
  29 +@RestController
  30 +@RequestMapping("/erp/product-category")
  31 +@Validated
  32 +public class ErpProductCategoryController {
  33 +
  34 + @Resource
  35 + private ErpProductCategoryService productCategoryService;
  36 +
  37 + @PostMapping("/create")
  38 + @Operation(summary = "创建ERP 产品分类")
  39 + @PreAuthorize("@ss.hasPermission('erp:product-category:create')")
  40 + public CommonResult<Long> createProductCategory(@Valid @RequestBody ErpProductCategorySaveReqVO createReqVO) {
  41 + return success(productCategoryService.createProductCategory(createReqVO));
  42 + }
  43 +
  44 + @PutMapping("/update")
  45 + @Operation(summary = "更新ERP 产品分类")
  46 + @PreAuthorize("@ss.hasPermission('erp:product-category:update')")
  47 + public CommonResult<Boolean> updateProductCategory(@Valid @RequestBody ErpProductCategorySaveReqVO updateReqVO) {
  48 + productCategoryService.updateProductCategory(updateReqVO);
  49 + return success(true);
  50 + }
  51 +
  52 + @DeleteMapping("/delete")
  53 + @Operation(summary = "删除ERP 产品分类")
  54 + @Parameter(name = "id", description = "编号", required = true)
  55 + @PreAuthorize("@ss.hasPermission('erp:product-category:delete')")
  56 + public CommonResult<Boolean> deleteProductCategory(@RequestParam("id") Long id) {
  57 + productCategoryService.deleteProductCategory(id);
  58 + return success(true);
  59 + }
  60 +
  61 + @GetMapping("/get")
  62 + @Operation(summary = "获得ERP 产品分类")
  63 + @Parameter(name = "id", description = "编号", required = true, example = "1024")
  64 + @PreAuthorize("@ss.hasPermission('erp:product-category:query')")
  65 + public CommonResult<ErpProductCategoryRespVO> getProductCategory(@RequestParam("id") Long id) {
  66 + ErpProductCategoryDO productCategory = productCategoryService.getProductCategory(id);
  67 + return success(BeanUtils.toBean(productCategory, ErpProductCategoryRespVO.class));
  68 + }
  69 +
  70 + @GetMapping("/list")
  71 + @Operation(summary = "获得ERP 产品分类列表")
  72 + @PreAuthorize("@ss.hasPermission('erp:product-category:query')")
  73 + public CommonResult<List<ErpProductCategoryRespVO>> getProductCategoryList(@Valid ErpProductCategoryListReqVO listReqVO) {
  74 + List<ErpProductCategoryDO> list = productCategoryService.getProductCategoryList(listReqVO);
  75 + return success(BeanUtils.toBean(list, ErpProductCategoryRespVO.class));
  76 + }
  77 +
  78 + @GetMapping("/export-excel")
  79 + @Operation(summary = "导出ERP 产品分类 Excel")
  80 + @PreAuthorize("@ss.hasPermission('erp:product-category:export')")
  81 + @OperateLog(type = EXPORT)
  82 + public void exportProductCategoryExcel(@Valid ErpProductCategoryListReqVO listReqVO,
  83 + HttpServletResponse response) throws IOException {
  84 + List<ErpProductCategoryDO> list = productCategoryService.getProductCategoryList(listReqVO);
  85 + // 导出 Excel
  86 + ExcelUtils.write(response, "ERP 产品分类.xls", "数据", ErpProductCategoryRespVO.class,
  87 + BeanUtils.toBean(list, ErpProductCategoryRespVO.class));
  88 + }
  89 +
  90 +}
0 \ No newline at end of file 91 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/ErpProductController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.product;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  4 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  7 +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
  8 +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
  9 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductPageReqVO;
  10 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductRespVO;
  11 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductSaveReqVO;
  12 +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
  13 +import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
  14 +import io.swagger.v3.oas.annotations.Operation;
  15 +import io.swagger.v3.oas.annotations.Parameter;
  16 +import io.swagger.v3.oas.annotations.tags.Tag;
  17 +import jakarta.annotation.Resource;
  18 +import jakarta.servlet.http.HttpServletResponse;
  19 +import jakarta.validation.Valid;
  20 +import org.springframework.security.access.prepost.PreAuthorize;
  21 +import org.springframework.validation.annotation.Validated;
  22 +import org.springframework.web.bind.annotation.*;
  23 +
  24 +import java.io.IOException;
  25 +import java.util.List;
  26 +
  27 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  28 +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
  29 +
  30 +@Tag(name = "管理后台 - ERP 产品")
  31 +@RestController
  32 +@RequestMapping("/erp/product")
  33 +@Validated
  34 +public class ErpProductController {
  35 +
  36 + @Resource
  37 + private ErpProductService productService;
  38 +
  39 + @PostMapping("/create")
  40 + @Operation(summary = "创建产品")
  41 + @PreAuthorize("@ss.hasPermission('erp:product:create')")
  42 + public CommonResult<Long> createProduct(@Valid @RequestBody ProductSaveReqVO createReqVO) {
  43 + return success(productService.createProduct(createReqVO));
  44 + }
  45 +
  46 + @PutMapping("/update")
  47 + @Operation(summary = "更新产品")
  48 + @PreAuthorize("@ss.hasPermission('erp:product:update')")
  49 + public CommonResult<Boolean> updateProduct(@Valid @RequestBody ProductSaveReqVO updateReqVO) {
  50 + productService.updateProduct(updateReqVO);
  51 + return success(true);
  52 + }
  53 +
  54 + @DeleteMapping("/delete")
  55 + @Operation(summary = "删除产品")
  56 + @Parameter(name = "id", description = "编号", required = true)
  57 + @PreAuthorize("@ss.hasPermission('erp:product:delete')")
  58 + public CommonResult<Boolean> deleteProduct(@RequestParam("id") Long id) {
  59 + productService.deleteProduct(id);
  60 + return success(true);
  61 + }
  62 +
  63 + @GetMapping("/get")
  64 + @Operation(summary = "获得产品")
  65 + @Parameter(name = "id", description = "编号", required = true, example = "1024")
  66 + @PreAuthorize("@ss.hasPermission('erp:product:query')")
  67 + public CommonResult<ProductRespVO> getProduct(@RequestParam("id") Long id) {
  68 + ErpProductDO product = productService.getProduct(id);
  69 + return success(BeanUtils.toBean(product, ProductRespVO.class));
  70 + }
  71 +
  72 + @GetMapping("/page")
  73 + @Operation(summary = "获得产品分页")
  74 + @PreAuthorize("@ss.hasPermission('erp:product:query')")
  75 + public CommonResult<PageResult<ProductRespVO>> getProductPage(@Valid ProductPageReqVO pageReqVO) {
  76 + PageResult<ErpProductDO> pageResult = productService.getProductPage(pageReqVO);
  77 + return success(BeanUtils.toBean(pageResult, ProductRespVO.class));
  78 + }
  79 +
  80 + @GetMapping("/export-excel")
  81 + @Operation(summary = "导出产品 Excel")
  82 + @PreAuthorize("@ss.hasPermission('erp:product:export')")
  83 + @OperateLog(type = EXPORT)
  84 + public void exportProductExcel(@Valid ProductPageReqVO pageReqVO,
  85 + HttpServletResponse response) throws IOException {
  86 + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
  87 + List<ErpProductDO> list = productService.getProductPage(pageReqVO).getList();
  88 + // 导出 Excel
  89 + ExcelUtils.write(response, "产品.xls", "数据", ProductRespVO.class,
  90 + BeanUtils.toBean(list, ProductRespVO.class));
  91 + }
  92 +
  93 +}
0 \ No newline at end of file 94 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/ErpProductUnitController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.product;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  4 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  7 +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
  8 +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
  9 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit.ErpProductUnitPageReqVO;
  10 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit.ErpProductUnitRespVO;
  11 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit.ErpProductUnitSaveReqVO;
  12 +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO;
  13 +import cn.iocoder.yudao.module.erp.service.product.ErpProductUnitService;
  14 +import io.swagger.v3.oas.annotations.Operation;
  15 +import io.swagger.v3.oas.annotations.Parameter;
  16 +import io.swagger.v3.oas.annotations.tags.Tag;
  17 +import jakarta.annotation.Resource;
  18 +import jakarta.servlet.http.HttpServletResponse;
  19 +import jakarta.validation.Valid;
  20 +import org.springframework.security.access.prepost.PreAuthorize;
  21 +import org.springframework.validation.annotation.Validated;
  22 +import org.springframework.web.bind.annotation.*;
  23 +
  24 +import java.io.IOException;
  25 +import java.util.List;
  26 +
  27 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  28 +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
  29 +
  30 +@Tag(name = "管理后台 - ERP 产品单位")
  31 +@RestController
  32 +@RequestMapping("/erp/product-unit")
  33 +@Validated
  34 +public class ErpProductUnitController {
  35 +
  36 + @Resource
  37 + private ErpProductUnitService productUnitService;
  38 +
  39 + @PostMapping("/create")
  40 + @Operation(summary = "创建产品单位")
  41 + @PreAuthorize("@ss.hasPermission('erp:product-unit:create')")
  42 + public CommonResult<Long> createProductUnit(@Valid @RequestBody ErpProductUnitSaveReqVO createReqVO) {
  43 + return success(productUnitService.createProductUnit(createReqVO));
  44 + }
  45 +
  46 + @PutMapping("/update")
  47 + @Operation(summary = "更新产品单位")
  48 + @PreAuthorize("@ss.hasPermission('erp:product-unit:update')")
  49 + public CommonResult<Boolean> updateProductUnit(@Valid @RequestBody ErpProductUnitSaveReqVO updateReqVO) {
  50 + productUnitService.updateProductUnit(updateReqVO);
  51 + return success(true);
  52 + }
  53 +
  54 + @DeleteMapping("/delete")
  55 + @Operation(summary = "删除产品单位")
  56 + @Parameter(name = "id", description = "编号", required = true)
  57 + @PreAuthorize("@ss.hasPermission('erp:product-unit:delete')")
  58 + public CommonResult<Boolean> deleteProductUnit(@RequestParam("id") Long id) {
  59 + productUnitService.deleteProductUnit(id);
  60 + return success(true);
  61 + }
  62 +
  63 + @GetMapping("/get")
  64 + @Operation(summary = "获得产品单位")
  65 + @Parameter(name = "id", description = "编号", required = true, example = "1024")
  66 + @PreAuthorize("@ss.hasPermission('erp:product-unit:query')")
  67 + public CommonResult<ErpProductUnitRespVO> getProductUnit(@RequestParam("id") Long id) {
  68 + ErpProductUnitDO productUnit = productUnitService.getProductUnit(id);
  69 + return success(BeanUtils.toBean(productUnit, ErpProductUnitRespVO.class));
  70 + }
  71 +
  72 + @GetMapping("/page")
  73 + @Operation(summary = "获得产品单位分页")
  74 + @PreAuthorize("@ss.hasPermission('erp:product-unit:query')")
  75 + public CommonResult<PageResult<ErpProductUnitRespVO>> getProductUnitPage(@Valid ErpProductUnitPageReqVO pageReqVO) {
  76 + PageResult<ErpProductUnitDO> pageResult = productUnitService.getProductUnitPage(pageReqVO);
  77 + return success(BeanUtils.toBean(pageResult, ErpProductUnitRespVO.class));
  78 + }
  79 +
  80 + @GetMapping("/export-excel")
  81 + @Operation(summary = "导出产品单位 Excel")
  82 + @PreAuthorize("@ss.hasPermission('erp:product-unit:export')")
  83 + @OperateLog(type = EXPORT)
  84 + public void exportProductUnitExcel(@Valid ErpProductUnitPageReqVO pageReqVO,
  85 + HttpServletResponse response) throws IOException {
  86 + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
  87 + List<ErpProductUnitDO> list = productUnitService.getProductUnitPage(pageReqVO).getList();
  88 + // 导出 Excel
  89 + ExcelUtils.write(response, "产品单位.xls", "数据", ErpProductUnitRespVO.class,
  90 + BeanUtils.toBean(list, ErpProductUnitRespVO.class));
  91 + }
  92 +
  93 +}
0 \ No newline at end of file 94 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/vo/category/ErpProductCategoryListReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.product.vo.category;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +@Schema(description = "管理后台 - ERP 产品分类列表 Request VO")
  7 +@Data
  8 +public class ErpProductCategoryListReqVO {
  9 +
  10 + @Schema(description = "分类名称", example = "芋艿")
  11 + private String name;
  12 +
  13 + @Schema(description = "开启状态", example = "1")
  14 + private Integer status;
  15 +
  16 +}
0 \ No newline at end of file 17 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/vo/category/ErpProductCategoryRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.product.vo.category;
  2 +
  3 +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
  4 +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
  5 +import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
  6 +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
  7 +import com.alibaba.excel.annotation.ExcelProperty;
  8 +import io.swagger.v3.oas.annotations.media.Schema;
  9 +import lombok.Data;
  10 +
  11 +import java.time.LocalDateTime;
  12 +
  13 +@Schema(description = "管理后台 - ERP 产品分类 Response VO")
  14 +@Data
  15 +@ExcelIgnoreUnannotated
  16 +public class ErpProductCategoryRespVO {
  17 +
  18 + @Schema(description = "分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "5860")
  19 + @ExcelProperty("分类编号")
  20 + private Long id;
  21 +
  22 + @Schema(description = "父分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "21829")
  23 + @ExcelProperty("父分类编号")
  24 + private Long parentId;
  25 +
  26 + @Schema(description = "分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
  27 + @ExcelProperty("分类名称")
  28 + private String name;
  29 +
  30 + @Schema(description = "分类编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "S110")
  31 + @ExcelProperty("分类编码")
  32 + private String code;
  33 +
  34 + @Schema(description = "分类排序", example = "10")
  35 + @ExcelProperty("分类排序")
  36 + private Integer sort;
  37 +
  38 + @Schema(description = "开启状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  39 + @ExcelProperty(value = "开启状态", converter = DictConvert.class)
  40 + @DictFormat(DictTypeConstants.COMMON_STATUS)
  41 + private Integer status;
  42 +
  43 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  44 + @ExcelProperty("创建时间")
  45 + private LocalDateTime createTime;
  46 +
  47 +}
0 \ No newline at end of file 48 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/vo/category/ErpProductCategorySaveReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.product.vo.category;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import jakarta.validation.constraints.NotEmpty;
  5 +import jakarta.validation.constraints.NotNull;
  6 +import lombok.Data;
  7 +
  8 +@Schema(description = "管理后台 - ERP 产品分类新增/修改 Request VO")
  9 +@Data
  10 +public class ErpProductCategorySaveReqVO {
  11 +
  12 + @Schema(description = "分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "5860")
  13 + private Long id;
  14 +
  15 + @Schema(description = "父分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "21829")
  16 + @NotNull(message = "父分类编号不能为空")
  17 + private Long parentId;
  18 +
  19 + @Schema(description = "分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
  20 + @NotEmpty(message = "分类名称不能为空")
  21 + private String name;
  22 +
  23 + @Schema(description = "分类编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "S110")
  24 + @NotEmpty(message = "分类编码不能为空")
  25 + private String code;
  26 +
  27 + @Schema(description = "分类排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
  28 + @NotNull(message = "分类排序不能为空")
  29 + private Integer sort;
  30 +
  31 + @Schema(description = "开启状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  32 + @NotNull(message = "开启状态不能为空")
  33 + private Integer status;
  34 +
  35 +}
0 \ No newline at end of file 36 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/vo/product/ProductPageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.product.vo.product;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.v3.oas.annotations.media.Schema;
  6 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  7 +import java.math.BigDecimal;
  8 +import org.springframework.format.annotation.DateTimeFormat;
  9 +import java.time.LocalDateTime;
  10 +
  11 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  12 +
  13 +@Schema(description = "管理后台 - ERP 产品分页 Request VO")
  14 +@Data
  15 +@EqualsAndHashCode(callSuper = true)
  16 +@ToString(callSuper = true)
  17 +public class ProductPageReqVO extends PageParam {
  18 +
  19 + @Schema(description = "产品名称", example = "李四")
  20 + private String name;
  21 +
  22 + @Schema(description = "产品分类编号", example = "11161")
  23 + private Long categoryId;
  24 +
  25 + @Schema(description = "创建时间")
  26 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  27 + private LocalDateTime[] createTime;
  28 +
  29 +}
0 \ No newline at end of file 30 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/vo/product/ProductRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.product.vo.product;
  2 +
  3 +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
  4 +import com.alibaba.excel.annotation.ExcelProperty;
  5 +import io.swagger.v3.oas.annotations.media.Schema;
  6 +import lombok.Data;
  7 +
  8 +import java.math.BigDecimal;
  9 +import java.time.LocalDateTime;
  10 +
  11 +@Schema(description = "管理后台 - ERP 产品 Response VO")
  12 +@Data
  13 +@ExcelIgnoreUnannotated
  14 +public class ProductRespVO {
  15 +
  16 + @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15672")
  17 + @ExcelProperty("产品编号")
  18 + private Long id;
  19 +
  20 + @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
  21 + @ExcelProperty("产品名称")
  22 + private String name;
  23 +
  24 + @Schema(description = "产品条码", requiredMode = Schema.RequiredMode.REQUIRED, example = "X110")
  25 + @ExcelProperty("产品条码")
  26 + private String barCode;
  27 +
  28 + @Schema(description = "产品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11161")
  29 + @ExcelProperty("产品分类编号")
  30 + private Long categoryId;
  31 +
  32 + @Schema(description = "单位编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8869")
  33 + @ExcelProperty("单位编号")
  34 + private Integer unitId;
  35 +
  36 + @Schema(description = "产品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  37 + @ExcelProperty("产品状态")
  38 + private Integer status;
  39 +
  40 + @Schema(description = "产品规格", example = "红色")
  41 + @ExcelProperty("产品规格")
  42 + private String standard;
  43 +
  44 + @Schema(description = "产品备注", example = "你猜")
  45 + @ExcelProperty("产品备注")
  46 + private String remark;
  47 +
  48 + @Schema(description = "保质期天数", example = "10")
  49 + @ExcelProperty("保质期天数")
  50 + private Integer expiryDay;
  51 +
  52 + @Schema(description = "基础重量(kg)", example = "1.00")
  53 + @ExcelProperty("基础重量(kg)")
  54 + private BigDecimal weight;
  55 +
  56 + @Schema(description = "采购价格,单位:元", example = "10.30")
  57 + @ExcelProperty("采购价格,单位:元")
  58 + private BigDecimal purchasePrice;
  59 +
  60 + @Schema(description = "销售价格,单位:元", example = "74.32")
  61 + @ExcelProperty("销售价格,单位:元")
  62 + private BigDecimal salePrice;
  63 +
  64 + @Schema(description = "最低价格,单位:元", example = "161.87")
  65 + @ExcelProperty("最低价格,单位:元")
  66 + private BigDecimal minPrice;
  67 +
  68 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  69 + @ExcelProperty("创建时间")
  70 + private LocalDateTime createTime;
  71 +
  72 +}
0 \ No newline at end of file 73 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/vo/product/ProductSaveReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.product.vo.product;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.*;
  5 +import java.util.*;
  6 +import jakarta.validation.constraints.*;
  7 +import java.math.BigDecimal;
  8 +
  9 +@Schema(description = "管理后台 - ERP 产品新增/修改 Request VO")
  10 +@Data
  11 +public class ProductSaveReqVO {
  12 +
  13 + @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15672")
  14 + private Long id;
  15 +
  16 + @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
  17 + @NotEmpty(message = "产品名称不能为空")
  18 + private String name;
  19 +
  20 + @Schema(description = "产品条码", requiredMode = Schema.RequiredMode.REQUIRED, example = "X110")
  21 + @NotEmpty(message = "产品条码不能为空")
  22 + private String barCode;
  23 +
  24 + @Schema(description = "产品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11161")
  25 + @NotNull(message = "产品分类编号不能为空")
  26 + private Long categoryId;
  27 +
  28 + @Schema(description = "单位编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8869")
  29 + @NotNull(message = "单位编号不能为空")
  30 + private Integer unitId;
  31 +
  32 + @Schema(description = "产品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  33 + @NotNull(message = "产品状态不能为空")
  34 + private Integer status;
  35 +
  36 + @Schema(description = "产品规格", example = "红色")
  37 + private String standard;
  38 +
  39 + @Schema(description = "产品备注", example = "你猜")
  40 + private String remark;
  41 +
  42 + @Schema(description = "保质期天数", example = "10")
  43 + private Integer expiryDay;
  44 +
  45 + @Schema(description = "基础重量(kg)", example = "1.00")
  46 + private BigDecimal weight;
  47 +
  48 + @Schema(description = "采购价格,单位:元", example = "10.30")
  49 + private BigDecimal purchasePrice;
  50 +
  51 + @Schema(description = "销售价格,单位:元", example = "74.32")
  52 + private BigDecimal salePrice;
  53 +
  54 + @Schema(description = "最低价格,单位:元", example = "161.87")
  55 + private BigDecimal minPrice;
  56 +
  57 +}
0 \ No newline at end of file 58 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/vo/unit/ErpProductUnitPageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import io.swagger.v3.oas.annotations.media.Schema;
  5 +import lombok.Data;
  6 +import lombok.EqualsAndHashCode;
  7 +import lombok.ToString;
  8 +import org.springframework.format.annotation.DateTimeFormat;
  9 +
  10 +import java.time.LocalDateTime;
  11 +
  12 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  13 +
  14 +@Schema(description = "管理后台 - ERP 产品单位分页 Request VO")
  15 +@Data
  16 +@EqualsAndHashCode(callSuper = true)
  17 +@ToString(callSuper = true)
  18 +public class ErpProductUnitPageReqVO extends PageParam {
  19 +
  20 + @Schema(description = "单位名字", example = "芋艿")
  21 + private String name;
  22 +
  23 + @Schema(description = "单位状态", example = "1")
  24 + private Integer status;
  25 +
  26 + @Schema(description = "创建时间")
  27 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  28 + private LocalDateTime[] createTime;
  29 +
  30 +}
0 \ No newline at end of file 31 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/vo/unit/ErpProductUnitRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit;
  2 +
  3 +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
  4 +import com.alibaba.excel.annotation.ExcelProperty;
  5 +import io.swagger.v3.oas.annotations.media.Schema;
  6 +import jakarta.validation.constraints.NotNull;
  7 +import lombok.Data;
  8 +
  9 +import java.time.LocalDateTime;
  10 +
  11 +@Schema(description = "管理后台 - ERP 产品单位 Response VO")
  12 +@Data
  13 +@ExcelIgnoreUnannotated
  14 +public class ErpProductUnitRespVO {
  15 +
  16 + @Schema(description = "单位编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31254")
  17 + @ExcelProperty("单位编号")
  18 + private Long id;
  19 +
  20 + @Schema(description = "单位名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
  21 + @ExcelProperty("单位名字")
  22 + private String name;
  23 +
  24 + @Schema(description = "单位状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  25 + @ExcelProperty("单位状态")
  26 + @NotNull(message = "分类排序不能为空")
  27 + private Integer status;
  28 +
  29 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  30 + @ExcelProperty("创建时间")
  31 + private LocalDateTime createTime;
  32 +
  33 +}
0 \ No newline at end of file 34 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/vo/unit/ErpProductUnitSaveReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import jakarta.validation.constraints.NotEmpty;
  5 +import jakarta.validation.constraints.NotNull;
  6 +import lombok.Data;
  7 +
  8 +@Schema(description = "管理后台 - ERP 产品单位新增/修改 Request VO")
  9 +@Data
  10 +public class ErpProductUnitSaveReqVO {
  11 +
  12 + @Schema(description = "单位编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31254")
  13 + private Long id;
  14 +
  15 + @Schema(description = "单位名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
  16 + @NotEmpty(message = "单位名字不能为空")
  17 + private String name;
  18 +
  19 + @Schema(description = "单位状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  20 + @NotNull(message = "单位状态不能为空")
  21 + private Integer status;
  22 +
  23 +}
0 \ No newline at end of file 24 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/product/ErpProductCategoryDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.dal.dataobject.product;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import com.baomidou.mybatisplus.annotation.KeySequence;
  5 +import com.baomidou.mybatisplus.annotation.TableId;
  6 +import com.baomidou.mybatisplus.annotation.TableName;
  7 +import lombok.*;
  8 +
  9 +/**
  10 + * ERP 产品分类 DO
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +@TableName("erp_product_category")
  15 +@KeySequence("erp_product_category_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  16 +@Data
  17 +@EqualsAndHashCode(callSuper = true)
  18 +@ToString(callSuper = true)
  19 +@Builder
  20 +@NoArgsConstructor
  21 +@AllArgsConstructor
  22 +public class ErpProductCategoryDO extends BaseDO {
  23 +
  24 + public static final Long PARENT_ID_ROOT = 0L;
  25 +
  26 + /**
  27 + * 分类编号
  28 + */
  29 + @TableId
  30 + private Long id;
  31 + /**
  32 + * 父分类编号
  33 + */
  34 + private Long parentId;
  35 + /**
  36 + * 分类名称
  37 + */
  38 + private String name;
  39 + /**
  40 + * 分类编码
  41 + */
  42 + private String code;
  43 + /**
  44 + * 分类排序
  45 + */
  46 + private Integer sort;
  47 + /**
  48 + * 开启状态
  49 + *
  50 + * 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum}
  51 + */
  52 + private Integer status;
  53 +
  54 +}
0 \ No newline at end of file 55 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/product/ErpProductDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.dal.dataobject.product;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import com.baomidou.mybatisplus.annotation.KeySequence;
  5 +import com.baomidou.mybatisplus.annotation.TableId;
  6 +import com.baomidou.mybatisplus.annotation.TableName;
  7 +import lombok.*;
  8 +
  9 +import java.math.BigDecimal;
  10 +
  11 +/**
  12 + * ERP 产品 DO
  13 + *
  14 + * @author 芋道源码
  15 + */
  16 +@TableName("erp_product")
  17 +@KeySequence("erp_product_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  18 +@Data
  19 +@EqualsAndHashCode(callSuper = true)
  20 +@ToString(callSuper = true)
  21 +@Builder
  22 +@NoArgsConstructor
  23 +@AllArgsConstructor
  24 +public class ErpProductDO extends BaseDO {
  25 +
  26 + /**
  27 + * 产品编号
  28 + */
  29 + @TableId
  30 + private Long id;
  31 + /**
  32 + * 产品名称
  33 + */
  34 + private String name;
  35 + /**
  36 + * 产品条码
  37 + */
  38 + private String barCode;
  39 + /**
  40 + * 产品分类编号
  41 + *
  42 + * 关联 {@link ErpProductCategoryDO#getId()}
  43 + */
  44 + private Long categoryId;
  45 + /**
  46 + * 单位编号
  47 + *
  48 + * TODO 芋艿,关联
  49 + */
  50 + private Integer unitId;
  51 + /**
  52 + * 产品状态
  53 + *
  54 + * 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum}
  55 + */
  56 + private Integer status;
  57 + /**
  58 + * 产品规格
  59 + */
  60 + private String standard;
  61 + /**
  62 + * 产品备注
  63 + */
  64 + private String remark;
  65 + /**
  66 + * 保质期天数
  67 + */
  68 + private Integer expiryDay;
  69 + /**
  70 + * 基础重量(kg)
  71 + */
  72 + private BigDecimal weight;
  73 + /**
  74 + * 采购价格,单位:元
  75 + */
  76 + private BigDecimal purchasePrice;
  77 + /**
  78 + * 销售价格,单位:元
  79 + */
  80 + private BigDecimal salePrice;
  81 + /**
  82 + * 最低价格,单位:元
  83 + */
  84 + private BigDecimal minPrice;
  85 +
  86 +}
0 \ No newline at end of file 87 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/product/ErpProductUnitDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.dal.dataobject.product;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import java.time.LocalDateTime;
  6 +import java.time.LocalDateTime;
  7 +import com.baomidou.mybatisplus.annotation.*;
  8 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  9 +
  10 +/**
  11 + * ERP 产品单位 DO
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@TableName("erp_product_unit")
  16 +@KeySequence("erp_product_unit_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  17 +@Data
  18 +@EqualsAndHashCode(callSuper = true)
  19 +@ToString(callSuper = true)
  20 +@Builder
  21 +@NoArgsConstructor
  22 +@AllArgsConstructor
  23 +public class ErpProductUnitDO extends BaseDO {
  24 +
  25 + /**
  26 + * 单位编号
  27 + */
  28 + @TableId
  29 + private Long id;
  30 + /**
  31 + * 单位名字
  32 + */
  33 + private String name;
  34 + /**
  35 + * 单位状态
  36 + */
  37 + private Integer status;
  38 +
  39 +}
0 \ No newline at end of file 40 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/product/ErpProductCategoryMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.dal.mysql.product;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  4 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  5 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategoryListReqVO;
  6 +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO;
  7 +import org.apache.ibatis.annotations.Mapper;
  8 +
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * ERP 产品分类 Mapper
  13 + *
  14 + * @author 芋道源码
  15 + */
  16 +@Mapper
  17 +public interface ErpProductCategoryMapper extends BaseMapperX<ErpProductCategoryDO> {
  18 +
  19 + default List<ErpProductCategoryDO> selectList(ErpProductCategoryListReqVO reqVO) {
  20 + return selectList(new LambdaQueryWrapperX<ErpProductCategoryDO>()
  21 + .likeIfPresent(ErpProductCategoryDO::getName, reqVO.getName())
  22 + .eqIfPresent(ErpProductCategoryDO::getStatus, reqVO.getStatus())
  23 + .orderByDesc(ErpProductCategoryDO::getId));
  24 + }
  25 +
  26 + default ErpProductCategoryDO selectByParentIdAndName(Long parentId, String name) {
  27 + return selectOne(ErpProductCategoryDO::getParentId, parentId, ErpProductCategoryDO::getName, name);
  28 + }
  29 +
  30 + default Long selectCountByParentId(Long parentId) {
  31 + return selectCount(ErpProductCategoryDO::getParentId, parentId);
  32 + }
  33 +
  34 +}
0 \ No newline at end of file 35 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/product/ErpProductMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.dal.mysql.product;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  5 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  6 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductPageReqVO;
  7 +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
  8 +import org.apache.ibatis.annotations.Mapper;
  9 +
  10 +/**
  11 + * ERP 产品 Mapper
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@Mapper
  16 +public interface ErpProductMapper extends BaseMapperX<ErpProductDO> {
  17 +
  18 + default PageResult<ErpProductDO> selectPage(ProductPageReqVO reqVO) {
  19 + return selectPage(reqVO, new LambdaQueryWrapperX<ErpProductDO>()
  20 + .likeIfPresent(ErpProductDO::getName, reqVO.getName())
  21 + .eqIfPresent(ErpProductDO::getCategoryId, reqVO.getCategoryId())
  22 + .betweenIfPresent(ErpProductDO::getCreateTime, reqVO.getCreateTime())
  23 + .orderByDesc(ErpProductDO::getId));
  24 + }
  25 +
  26 +}
0 \ No newline at end of file 27 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/product/ErpProductUnitMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.dal.mysql.product;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  5 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  6 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit.ErpProductUnitPageReqVO;
  7 +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO;
  8 +import org.apache.ibatis.annotations.Mapper;
  9 +
  10 +/**
  11 + * ERP 产品单位 Mapper
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@Mapper
  16 +public interface ErpProductUnitMapper extends BaseMapperX<ErpProductUnitDO> {
  17 +
  18 + default PageResult<ErpProductUnitDO> selectPage(ErpProductUnitPageReqVO reqVO) {
  19 + return selectPage(reqVO, new LambdaQueryWrapperX<ErpProductUnitDO>()
  20 + .likeIfPresent(ErpProductUnitDO::getName, reqVO.getName())
  21 + .eqIfPresent(ErpProductUnitDO::getStatus, reqVO.getStatus())
  22 + .betweenIfPresent(ErpProductUnitDO::getCreateTime, reqVO.getCreateTime())
  23 + .orderByDesc(ErpProductUnitDO::getId));
  24 + }
  25 +
  26 +}
0 \ No newline at end of file 27 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/product/ErpProductCategoryService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.service.product;
  2 +
  3 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategoryListReqVO;
  4 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategorySaveReqVO;
  5 +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO;
  6 +import jakarta.validation.Valid;
  7 +
  8 +import java.util.List;
  9 +
  10 +/**
  11 + * ERP 产品分类 Service 接口
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +public interface ErpProductCategoryService {
  16 +
  17 + /**
  18 + * 创建产品分类
  19 + *
  20 + * @param createReqVO 创建信息
  21 + * @return 编号
  22 + */
  23 + Long createProductCategory(@Valid ErpProductCategorySaveReqVO createReqVO);
  24 +
  25 + /**
  26 + * 更新产品分类
  27 + *
  28 + * @param updateReqVO 更新信息
  29 + */
  30 + void updateProductCategory(@Valid ErpProductCategorySaveReqVO updateReqVO);
  31 +
  32 + /**
  33 + * 删除产品分类
  34 + *
  35 + * @param id 编号
  36 + */
  37 + void deleteProductCategory(Long id);
  38 +
  39 + /**
  40 + * 获得产品分类
  41 + *
  42 + * @param id 编号
  43 + * @return ERP 产品分类
  44 + */
  45 + ErpProductCategoryDO getProductCategory(Long id);
  46 +
  47 + /**
  48 + * 获得产品分类列表
  49 + *
  50 + * @param listReqVO 查询条件
  51 + * @return ERP 产品分类列表
  52 + */
  53 + List<ErpProductCategoryDO> getProductCategoryList(ErpProductCategoryListReqVO listReqVO);
  54 +
  55 +}
0 \ No newline at end of file 56 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/product/ErpProductCategoryServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.service.product;
  2 +
  3 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  4 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategoryListReqVO;
  5 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategorySaveReqVO;
  6 +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO;
  7 +import cn.iocoder.yudao.module.erp.dal.mysql.product.ErpProductCategoryMapper;
  8 +import jakarta.annotation.Resource;
  9 +import org.springframework.stereotype.Service;
  10 +import org.springframework.validation.annotation.Validated;
  11 +
  12 +import java.util.List;
  13 +import java.util.Objects;
  14 +
  15 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  16 +import static cn.iocoder.yudao.module.erp.ErrorCodeConstants.*;
  17 +
  18 +/**
  19 + * ERP 产品分类 Service 实现类
  20 + *
  21 + * @author 芋道源码
  22 + */
  23 +@Service
  24 +@Validated
  25 +public class ErpProductCategoryServiceImpl implements ErpProductCategoryService {
  26 +
  27 + @Resource
  28 + private ErpProductCategoryMapper productCategoryMapper;
  29 +
  30 + @Override
  31 + public Long createProductCategory(ErpProductCategorySaveReqVO createReqVO) {
  32 + // 校验父分类编号的有效性
  33 + validateParentProductCategory(null, createReqVO.getParentId());
  34 + // 校验分类名称的唯一性
  35 + validateProductCategoryNameUnique(null, createReqVO.getParentId(), createReqVO.getName());
  36 +
  37 + // 插入
  38 + ErpProductCategoryDO category = BeanUtils.toBean(createReqVO, ErpProductCategoryDO.class);
  39 + productCategoryMapper.insert(category);
  40 + // 返回
  41 + return category.getId();
  42 + }
  43 +
  44 + @Override
  45 + public void updateProductCategory(ErpProductCategorySaveReqVO updateReqVO) {
  46 + // 校验存在
  47 + validateProductCategoryExists(updateReqVO.getId());
  48 + // 校验父分类编号的有效性
  49 + validateParentProductCategory(updateReqVO.getId(), updateReqVO.getParentId());
  50 + // 校验分类名称的唯一性
  51 + validateProductCategoryNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName());
  52 +
  53 + // 更新
  54 + ErpProductCategoryDO updateObj = BeanUtils.toBean(updateReqVO, ErpProductCategoryDO.class);
  55 + productCategoryMapper.updateById(updateObj);
  56 + }
  57 +
  58 + @Override
  59 + public void deleteProductCategory(Long id) {
  60 + // 校验存在
  61 + validateProductCategoryExists(id);
  62 + // 校验是否有子产品分类
  63 + if (productCategoryMapper.selectCountByParentId(id) > 0) {
  64 + throw exception(PRODUCT_CATEGORY_EXITS_CHILDREN);
  65 + }
  66 + // 删除
  67 + productCategoryMapper.deleteById(id);
  68 + }
  69 +
  70 + private void validateProductCategoryExists(Long id) {
  71 + if (productCategoryMapper.selectById(id) == null) {
  72 + throw exception(PRODUCT_CATEGORY_NOT_EXISTS);
  73 + }
  74 + }
  75 +
  76 + private void validateParentProductCategory(Long id, Long parentId) {
  77 + if (parentId == null || ErpProductCategoryDO.PARENT_ID_ROOT.equals(parentId)) {
  78 + return;
  79 + }
  80 + // 1. 不能设置自己为父产品分类
  81 + if (Objects.equals(id, parentId)) {
  82 + throw exception(PRODUCT_CATEGORY_PARENT_ERROR);
  83 + }
  84 + // 2. 父产品分类不存在
  85 + ErpProductCategoryDO parentCategory = productCategoryMapper.selectById(parentId);
  86 + if (parentCategory == null) {
  87 + throw exception(PRODUCT_CATEGORY_PARENT_NOT_EXITS);
  88 + }
  89 + // 3. 递归校验父产品分类,如果父产品分类是自己的子产品分类,则报错,避免形成环路
  90 + if (id == null) { // id 为空,说明新增,不需要考虑环路
  91 + return;
  92 + }
  93 + for (int i = 0; i < Short.MAX_VALUE; i++) {
  94 + // 3.1 校验环路
  95 + parentId = parentCategory.getParentId();
  96 + if (Objects.equals(id, parentId)) {
  97 + throw exception(PRODUCT_CATEGORY_PARENT_IS_CHILD);
  98 + }
  99 + // 3.2 继续递归下一级父产品分类
  100 + if (parentId == null || ErpProductCategoryDO.PARENT_ID_ROOT.equals(parentId)) {
  101 + break;
  102 + }
  103 + parentCategory = productCategoryMapper.selectById(parentId);
  104 + if (parentCategory == null) {
  105 + break;
  106 + }
  107 + }
  108 + }
  109 +
  110 + private void validateProductCategoryNameUnique(Long id, Long parentId, String name) {
  111 + ErpProductCategoryDO productCategory = productCategoryMapper.selectByParentIdAndName(parentId, name);
  112 + if (productCategory == null) {
  113 + return;
  114 + }
  115 + // 如果 id 为空,说明不用比较是否为相同 id 的产品分类
  116 + if (id == null) {
  117 + throw exception(PRODUCT_CATEGORY_NAME_DUPLICATE);
  118 + }
  119 + if (!Objects.equals(productCategory.getId(), id)) {
  120 + throw exception(PRODUCT_CATEGORY_NAME_DUPLICATE);
  121 + }
  122 + }
  123 +
  124 + @Override
  125 + public ErpProductCategoryDO getProductCategory(Long id) {
  126 + return productCategoryMapper.selectById(id);
  127 + }
  128 +
  129 + @Override
  130 + public List<ErpProductCategoryDO> getProductCategoryList(ErpProductCategoryListReqVO listReqVO) {
  131 + return productCategoryMapper.selectList(listReqVO);
  132 + }
  133 +
  134 +}
0 \ No newline at end of file 135 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/product/ErpProductService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.service.product;
  2 +
  3 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductPageReqVO;
  4 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductSaveReqVO;
  5 +import jakarta.validation.*;
  6 +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
  7 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  8 +
  9 +/**
  10 + * ERP 产品 Service 接口
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +public interface ErpProductService {
  15 +
  16 + /**
  17 + * 创建产品
  18 + *
  19 + * @param createReqVO 创建信息
  20 + * @return 编号
  21 + */
  22 + Long createProduct(@Valid ProductSaveReqVO createReqVO);
  23 +
  24 + /**
  25 + * 更新产品
  26 + *
  27 + * @param updateReqVO 更新信息
  28 + */
  29 + void updateProduct(@Valid ProductSaveReqVO updateReqVO);
  30 +
  31 + /**
  32 + * 删除产品
  33 + *
  34 + * @param id 编号
  35 + */
  36 + void deleteProduct(Long id);
  37 +
  38 + /**
  39 + * 获得产品
  40 + *
  41 + * @param id 编号
  42 + * @return 产品
  43 + */
  44 + ErpProductDO getProduct(Long id);
  45 +
  46 + /**
  47 + * 获得产品分页
  48 + *
  49 + * @param pageReqVO 分页查询
  50 + * @return 产品分页
  51 + */
  52 + PageResult<ErpProductDO> getProductPage(ProductPageReqVO pageReqVO);
  53 +
  54 +}
0 \ No newline at end of file 55 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/product/ErpProductServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.service.product;
  2 +
  3 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductPageReqVO;
  4 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductSaveReqVO;
  5 +import org.springframework.stereotype.Service;
  6 +import jakarta.annotation.Resource;
  7 +import org.springframework.validation.annotation.Validated;
  8 +
  9 +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
  10 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  11 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  12 +
  13 +import cn.iocoder.yudao.module.erp.dal.mysql.product.ErpProductMapper;
  14 +
  15 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  16 +import static cn.iocoder.yudao.module.erp.ErrorCodeConstants.PRODUCT_NOT_EXISTS;
  17 +
  18 +/**
  19 + * ERP 产品 Service 实现类
  20 + *
  21 + * @author 芋道源码
  22 + */
  23 +@Service
  24 +@Validated
  25 +public class ErpProductServiceImpl implements ErpProductService {
  26 +
  27 + @Resource
  28 + private ErpProductMapper productMapper;
  29 +
  30 + @Override
  31 + public Long createProduct(ProductSaveReqVO createReqVO) {
  32 + // 插入
  33 + ErpProductDO product = BeanUtils.toBean(createReqVO, ErpProductDO.class);
  34 + productMapper.insert(product);
  35 + // 返回
  36 + return product.getId();
  37 + }
  38 +
  39 + @Override
  40 + public void updateProduct(ProductSaveReqVO updateReqVO) {
  41 + // 校验存在
  42 + validateProductExists(updateReqVO.getId());
  43 + // 更新
  44 + ErpProductDO updateObj = BeanUtils.toBean(updateReqVO, ErpProductDO.class);
  45 + productMapper.updateById(updateObj);
  46 + }
  47 +
  48 + @Override
  49 + public void deleteProduct(Long id) {
  50 + // 校验存在
  51 + validateProductExists(id);
  52 + // 删除
  53 + productMapper.deleteById(id);
  54 + }
  55 +
  56 + private void validateProductExists(Long id) {
  57 + if (productMapper.selectById(id) == null) {
  58 + throw exception(PRODUCT_NOT_EXISTS);
  59 + }
  60 + }
  61 +
  62 + @Override
  63 + public ErpProductDO getProduct(Long id) {
  64 + return productMapper.selectById(id);
  65 + }
  66 +
  67 + @Override
  68 + public PageResult<ErpProductDO> getProductPage(ProductPageReqVO pageReqVO) {
  69 + return productMapper.selectPage(pageReqVO);
  70 + }
  71 +
  72 +}
0 \ No newline at end of file 73 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/product/ErpProductUnitService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.service.product;
  2 +
  3 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit.ErpProductUnitPageReqVO;
  4 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit.ErpProductUnitSaveReqVO;
  5 +import jakarta.validation.*;
  6 +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO;
  7 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  8 +
  9 +/**
  10 + * ERP 产品单位 Service 接口
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +public interface ErpProductUnitService {
  15 +
  16 + /**
  17 + * 创建产品单位
  18 + *
  19 + * @param createReqVO 创建信息
  20 + * @return 编号
  21 + */
  22 + Long createProductUnit(@Valid ErpProductUnitSaveReqVO createReqVO);
  23 +
  24 + /**
  25 + * 更新产品单位
  26 + *
  27 + * @param updateReqVO 更新信息
  28 + */
  29 + void updateProductUnit(@Valid ErpProductUnitSaveReqVO updateReqVO);
  30 +
  31 + /**
  32 + * 删除产品单位
  33 + *
  34 + * @param id 编号
  35 + */
  36 + void deleteProductUnit(Long id);
  37 +
  38 + /**
  39 + * 获得产品单位
  40 + *
  41 + * @param id 编号
  42 + * @return 产品单位
  43 + */
  44 + ErpProductUnitDO getProductUnit(Long id);
  45 +
  46 + /**
  47 + * 获得产品单位分页
  48 + *
  49 + * @param pageReqVO 分页查询
  50 + * @return 产品单位分页
  51 + */
  52 + PageResult<ErpProductUnitDO> getProductUnitPage(ErpProductUnitPageReqVO pageReqVO);
  53 +
  54 +}
0 \ No newline at end of file 55 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/product/ErpProductUnitServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.service.product;
  2 +
  3 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit.ErpProductUnitPageReqVO;
  4 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit.ErpProductUnitSaveReqVO;
  5 +import org.springframework.stereotype.Service;
  6 +import jakarta.annotation.Resource;
  7 +import org.springframework.validation.annotation.Validated;
  8 +
  9 +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO;
  10 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  11 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  12 +
  13 +import cn.iocoder.yudao.module.erp.dal.mysql.product.ErpProductUnitMapper;
  14 +
  15 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  16 +import static cn.iocoder.yudao.module.erp.ErrorCodeConstants.PRODUCT_UNIT_NOT_EXISTS;
  17 +
  18 +/**
  19 + * ERP 产品单位 Service 实现类
  20 + *
  21 + * @author 芋道源码
  22 + */
  23 +@Service
  24 +@Validated
  25 +public class ErpProductUnitServiceImpl implements ErpProductUnitService {
  26 +
  27 + @Resource
  28 + private ErpProductUnitMapper productUnitMapper;
  29 +
  30 + @Override
  31 + public Long createProductUnit(ErpProductUnitSaveReqVO createReqVO) {
  32 + // 插入
  33 + ErpProductUnitDO unit = BeanUtils.toBean(createReqVO, ErpProductUnitDO.class);
  34 + productUnitMapper.insert(unit);
  35 + // 返回
  36 + return unit.getId();
  37 + }
  38 +
  39 + @Override
  40 + public void updateProductUnit(ErpProductUnitSaveReqVO updateReqVO) {
  41 + // 校验存在
  42 + validateProductUnitExists(updateReqVO.getId());
  43 + // 更新
  44 + ErpProductUnitDO updateObj = BeanUtils.toBean(updateReqVO, ErpProductUnitDO.class);
  45 + productUnitMapper.updateById(updateObj);
  46 + }
  47 +
  48 + @Override
  49 + public void deleteProductUnit(Long id) {
  50 + // 校验存在
  51 + validateProductUnitExists(id);
  52 + // 删除
  53 + productUnitMapper.deleteById(id);
  54 + }
  55 +
  56 + private void validateProductUnitExists(Long id) {
  57 + if (productUnitMapper.selectById(id) == null) {
  58 + throw exception(PRODUCT_UNIT_NOT_EXISTS);
  59 + }
  60 + }
  61 +
  62 + @Override
  63 + public ErpProductUnitDO getProductUnit(Long id) {
  64 + return productUnitMapper.selectById(id);
  65 + }
  66 +
  67 + @Override
  68 + public PageResult<ErpProductUnitDO> getProductUnitPage(ErpProductUnitPageReqVO pageReqVO) {
  69 + return productUnitMapper.selectPage(pageReqVO);
  70 + }
  71 +
  72 +}
0 \ No newline at end of file 73 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/resources/mapper/product/ErpProductUnitMapper.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="cn.iocoder.yudao.module.erp.dal.mysql.product.ErpProductUnitMapper">
  4 +
  5 + <!--
  6 + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
  7 + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
  8 + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
  9 + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
  10 + -->
  11 +
  12 +</mapper>
0 \ No newline at end of file 13 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/test/java/cn/iocoder/yudao/module/erp/service/product/ErpProductUnitServiceImplTest.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.service.product;
  2 +
  3 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit.ErpProductUnitPageReqVO;
  4 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit.ErpProductUnitSaveReqVO;
  5 +import org.junit.jupiter.api.Disabled;
  6 +import org.junit.jupiter.api.Test;
  7 +
  8 +import jakarta.annotation.Resource;
  9 +
  10 +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
  11 +
  12 +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO;
  13 +import cn.iocoder.yudao.module.erp.dal.mysql.product.ErpProductUnitMapper;
  14 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  15 +
  16 +import org.springframework.context.annotation.Import;
  17 +
  18 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
  19 +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
  20 +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
  21 +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
  22 +import static org.junit.jupiter.api.Assertions.*;
  23 +
  24 +/**
  25 + * {@link ErpProductUnitServiceImpl} 的单元测试类
  26 + *
  27 + * @author 芋道源码
  28 + */
  29 +@Import(ErpProductUnitServiceImpl.class)
  30 +public class ErpProductUnitServiceImplTest extends BaseDbUnitTest {
  31 +
  32 + @Resource
  33 + private ErpProductUnitServiceImpl productUnitService;
  34 +
  35 + @Resource
  36 + private ErpProductUnitMapper productUnitMapper;
  37 +
  38 + @Test
  39 + public void testCreateProductUnit_success() {
  40 + // 准备参数
  41 + ErpProductUnitSaveReqVO createReqVO = randomPojo(ErpProductUnitSaveReqVO.class).setId(null);
  42 +
  43 + // 调用
  44 + Long productUnitId = productUnitService.createProductUnit(createReqVO);
  45 + // 断言
  46 + assertNotNull(productUnitId);
  47 + // 校验记录的属性是否正确
  48 + ErpProductUnitDO productUnit = productUnitMapper.selectById(productUnitId);
  49 + assertPojoEquals(createReqVO, productUnit, "id");
  50 + }
  51 +
  52 + @Test
  53 + public void testUpdateProductUnit_success() {
  54 + // mock 数据
  55 + ErpProductUnitDO dbProductUnit = randomPojo(ErpProductUnitDO.class);
  56 + productUnitMapper.insert(dbProductUnit);// @Sql: 先插入出一条存在的数据
  57 + // 准备参数
  58 + ErpProductUnitSaveReqVO updateReqVO = randomPojo(ErpProductUnitSaveReqVO.class, o -> {
  59 + o.setId(dbProductUnit.getId()); // 设置更新的 ID
  60 + });
  61 +
  62 + // 调用
  63 + productUnitService.updateProductUnit(updateReqVO);
  64 + // 校验是否更新正确
  65 + ErpProductUnitDO productUnit = productUnitMapper.selectById(updateReqVO.getId()); // 获取最新的
  66 + assertPojoEquals(updateReqVO, productUnit);
  67 + }
  68 +
  69 + @Test
  70 + public void testUpdateProductUnit_notExists() {
  71 + // 准备参数
  72 + ErpProductUnitSaveReqVO updateReqVO = randomPojo(ErpProductUnitSaveReqVO.class);
  73 +
  74 + // 调用, 并断言异常
  75 + assertServiceException(() -> productUnitService.updateProductUnit(updateReqVO), PRODUCT_UNIT_NOT_EXISTS);
  76 + }
  77 +
  78 + @Test
  79 + public void testDeleteProductUnit_success() {
  80 + // mock 数据
  81 + ErpProductUnitDO dbProductUnit = randomPojo(ErpProductUnitDO.class);
  82 + productUnitMapper.insert(dbProductUnit);// @Sql: 先插入出一条存在的数据
  83 + // 准备参数
  84 + Long id = dbProductUnit.getId();
  85 +
  86 + // 调用
  87 + productUnitService.deleteProductUnit(id);
  88 + // 校验数据不存在了
  89 + assertNull(productUnitMapper.selectById(id));
  90 + }
  91 +
  92 + @Test
  93 + public void testDeleteProductUnit_notExists() {
  94 + // 准备参数
  95 + Long id = randomLongId();
  96 +
  97 + // 调用, 并断言异常
  98 + assertServiceException(() -> productUnitService.deleteProductUnit(id), PRODUCT_UNIT_NOT_EXISTS);
  99 + }
  100 +
  101 + @Test
  102 + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
  103 + public void testGetProductUnitPage() {
  104 + // mock 数据
  105 + ErpProductUnitDO dbProductUnit = randomPojo(ErpProductUnitDO.class, o -> { // 等会查询到
  106 + o.setName(null);
  107 + o.setStatus(null);
  108 + o.setCreateTime(null);
  109 + });
  110 + productUnitMapper.insert(dbProductUnit);
  111 + // 测试 name 不匹配
  112 + productUnitMapper.insert(cloneIgnoreId(dbProductUnit, o -> o.setName(null)));
  113 + // 测试 status 不匹配
  114 + productUnitMapper.insert(cloneIgnoreId(dbProductUnit, o -> o.setStatus(null)));
  115 + // 测试 createTime 不匹配
  116 + productUnitMapper.insert(cloneIgnoreId(dbProductUnit, o -> o.setCreateTime(null)));
  117 + // 准备参数
  118 + ErpProductUnitPageReqVO reqVO = new ErpProductUnitPageReqVO();
  119 + reqVO.setName(null);
  120 + reqVO.setStatus(null);
  121 + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
  122 +
  123 + // 调用
  124 + PageResult<ErpProductUnitDO> pageResult = productUnitService.getProductUnitPage(reqVO);
  125 + // 断言
  126 + assertEquals(1, pageResult.getTotal());
  127 + assertEquals(1, pageResult.getList().size());
  128 + assertPojoEquals(dbProductUnit, pageResult.getList().get(0));
  129 + }
  130 +
  131 +}
0 \ No newline at end of file 132 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/test/java/cn/iocoder/yudao/module/erp/service/product/ProductServiceImplTest.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.service.product;
  2 +
  3 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductPageReqVO;
  4 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductSaveReqVO;
  5 +import org.junit.jupiter.api.Disabled;
  6 +import org.junit.jupiter.api.Test;
  7 +
  8 +import jakarta.annotation.Resource;
  9 +
  10 +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
  11 +
  12 +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
  13 +import cn.iocoder.yudao.module.erp.dal.mysql.product.ErpProductMapper;
  14 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  15 +
  16 +import org.springframework.context.annotation.Import;
  17 +
  18 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
  19 +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
  20 +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
  21 +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
  22 +import static org.junit.jupiter.api.Assertions.*;
  23 +
  24 +/**
  25 + * {@link ErpProductServiceImpl} 的单元测试类
  26 + *
  27 + * @author 芋道源码
  28 + */
  29 +@Import(ErpProductServiceImpl.class)
  30 +public class ProductServiceImplTest extends BaseDbUnitTest {
  31 +
  32 + @Resource
  33 + private ErpProductServiceImpl productService;
  34 +
  35 + @Resource
  36 + private ErpProductMapper productMapper;
  37 +
  38 + @Test
  39 + public void testCreateProduct_success() {
  40 + // 准备参数
  41 + ProductSaveReqVO createReqVO = randomPojo(ProductSaveReqVO.class).setId(null);
  42 +
  43 + // 调用
  44 + Long productId = productService.createProduct(createReqVO);
  45 + // 断言
  46 + assertNotNull(productId);
  47 + // 校验记录的属性是否正确
  48 + ErpProductDO product = productMapper.selectById(productId);
  49 + assertPojoEquals(createReqVO, product, "id");
  50 + }
  51 +
  52 + @Test
  53 + public void testUpdateProduct_success() {
  54 + // mock 数据
  55 + ErpProductDO dbProduct = randomPojo(ErpProductDO.class);
  56 + productMapper.insert(dbProduct);// @Sql: 先插入出一条存在的数据
  57 + // 准备参数
  58 + ProductSaveReqVO updateReqVO = randomPojo(ProductSaveReqVO.class, o -> {
  59 + o.setId(dbProduct.getId()); // 设置更新的 ID
  60 + });
  61 +
  62 + // 调用
  63 + productService.updateProduct(updateReqVO);
  64 + // 校验是否更新正确
  65 + ErpProductDO product = productMapper.selectById(updateReqVO.getId()); // 获取最新的
  66 + assertPojoEquals(updateReqVO, product);
  67 + }
  68 +
  69 + @Test
  70 + public void testUpdateProduct_notExists() {
  71 + // 准备参数
  72 + ProductSaveReqVO updateReqVO = randomPojo(ProductSaveReqVO.class);
  73 +
  74 + // 调用, 并断言异常
  75 + assertServiceException(() -> productService.updateProduct(updateReqVO), PRODUCT_NOT_EXISTS);
  76 + }
  77 +
  78 + @Test
  79 + public void testDeleteProduct_success() {
  80 + // mock 数据
  81 + ErpProductDO dbProduct = randomPojo(ErpProductDO.class);
  82 + productMapper.insert(dbProduct);// @Sql: 先插入出一条存在的数据
  83 + // 准备参数
  84 + Long id = dbProduct.getId();
  85 +
  86 + // 调用
  87 + productService.deleteProduct(id);
  88 + // 校验数据不存在了
  89 + assertNull(productMapper.selectById(id));
  90 + }
  91 +
  92 + @Test
  93 + public void testDeleteProduct_notExists() {
  94 + // 准备参数
  95 + Long id = randomLongId();
  96 +
  97 + // 调用, 并断言异常
  98 + assertServiceException(() -> productService.deleteProduct(id), PRODUCT_NOT_EXISTS);
  99 + }
  100 +
  101 + @Test
  102 + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
  103 + public void testGetProductPage() {
  104 + // mock 数据
  105 + ErpProductDO dbProduct = randomPojo(ErpProductDO.class, o -> { // 等会查询到
  106 + o.setName(null);
  107 + o.setCategoryId(null);
  108 + o.setCreateTime(null);
  109 + });
  110 + productMapper.insert(dbProduct);
  111 + // 测试 name 不匹配
  112 + productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setName(null)));
  113 + // 测试 categoryId 不匹配
  114 + productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setCategoryId(null)));
  115 + // 测试 createTime 不匹配
  116 + productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setCreateTime(null)));
  117 + // 准备参数
  118 + ProductPageReqVO reqVO = new ProductPageReqVO();
  119 + reqVO.setName(null);
  120 + reqVO.setCategoryId(null);
  121 + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
  122 +
  123 + // 调用
  124 + PageResult<ErpProductDO> pageResult = productService.getProductPage(reqVO);
  125 + // 断言
  126 + assertEquals(1, pageResult.getTotal());
  127 + assertEquals(1, pageResult.getList().size());
  128 + assertPojoEquals(dbProduct, pageResult.getList().get(0));
  129 + }
  130 +
  131 +}
0 \ No newline at end of file 132 \ No newline at end of file