Commit a36ae0c469f9ab634c7fcc80e370fd3194d1a98c
1 parent
e66ded28
✨ ERP:完成 product 信息、分类、单位的实现
Showing
18 changed files
with
255 additions
and
54 deletions
yudao-module-erp/yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/ErrorCodeConstants.java
| @@ -19,8 +19,11 @@ public interface ErrorCodeConstants { | @@ -19,8 +19,11 @@ public interface ErrorCodeConstants { | ||
| 19 | ErrorCode PRODUCT_CATEGORY_PARENT_ERROR = new ErrorCode(1_030_501_003, "不能设置自己为父产品分类"); | 19 | ErrorCode PRODUCT_CATEGORY_PARENT_ERROR = new ErrorCode(1_030_501_003, "不能设置自己为父产品分类"); |
| 20 | ErrorCode PRODUCT_CATEGORY_NAME_DUPLICATE = new ErrorCode(1_030_501_004, "已经存在该分类名称的产品分类"); | 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, "不能设置自己的子分类为父分类"); | 21 | ErrorCode PRODUCT_CATEGORY_PARENT_IS_CHILD = new ErrorCode(1_030_501_005, "不能设置自己的子分类为父分类"); |
| 22 | + ErrorCode PRODUCT_CATEGORY_EXITS_PRODUCT = new ErrorCode(1_030_502_002, "存在产品使用该分类,无法删除"); | ||
| 22 | 23 | ||
| 23 | // ========== ERP 产品单位 1-030-502-000 ========== | 24 | // ========== ERP 产品单位 1-030-502-000 ========== |
| 24 | ErrorCode PRODUCT_UNIT_NOT_EXISTS = new ErrorCode(1_030_502_000, "产品单位不存在"); | 25 | ErrorCode PRODUCT_UNIT_NOT_EXISTS = new ErrorCode(1_030_502_000, "产品单位不存在"); |
| 26 | + ErrorCode PRODUCT_UNIT_NAME_DUPLICATE = new ErrorCode(1_030_502_001, "已存在该名字的产品单位"); | ||
| 27 | + ErrorCode PRODUCT_UNIT_EXITS_PRODUCT = new ErrorCode(1_030_502_002, "存在产品使用该单位,无法删除"); | ||
| 25 | 28 | ||
| 26 | } | 29 | } |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/ErpProductCategoryController.java
| 1 | package cn.iocoder.yudao.module.erp.controller.admin.product; | 1 | package cn.iocoder.yudao.module.erp.controller.admin.product; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 6 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| @@ -23,6 +24,7 @@ import java.io.IOException; | @@ -23,6 +24,7 @@ import java.io.IOException; | ||
| 23 | import java.util.List; | 24 | import java.util.List; |
| 24 | 25 | ||
| 25 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 26 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 27 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | ||
| 26 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | 28 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 27 | 29 | ||
| 28 | @Tag(name = "管理后台 - ERP 产品分类") | 30 | @Tag(name = "管理后台 - ERP 产品分类") |
| @@ -35,14 +37,14 @@ public class ErpProductCategoryController { | @@ -35,14 +37,14 @@ public class ErpProductCategoryController { | ||
| 35 | private ErpProductCategoryService productCategoryService; | 37 | private ErpProductCategoryService productCategoryService; |
| 36 | 38 | ||
| 37 | @PostMapping("/create") | 39 | @PostMapping("/create") |
| 38 | - @Operation(summary = "创建ERP 产品分类") | 40 | + @Operation(summary = "创建产品分类") |
| 39 | @PreAuthorize("@ss.hasPermission('erp:product-category:create')") | 41 | @PreAuthorize("@ss.hasPermission('erp:product-category:create')") |
| 40 | public CommonResult<Long> createProductCategory(@Valid @RequestBody ErpProductCategorySaveReqVO createReqVO) { | 42 | public CommonResult<Long> createProductCategory(@Valid @RequestBody ErpProductCategorySaveReqVO createReqVO) { |
| 41 | return success(productCategoryService.createProductCategory(createReqVO)); | 43 | return success(productCategoryService.createProductCategory(createReqVO)); |
| 42 | } | 44 | } |
| 43 | 45 | ||
| 44 | @PutMapping("/update") | 46 | @PutMapping("/update") |
| 45 | - @Operation(summary = "更新ERP 产品分类") | 47 | + @Operation(summary = "更新产品分类") |
| 46 | @PreAuthorize("@ss.hasPermission('erp:product-category:update')") | 48 | @PreAuthorize("@ss.hasPermission('erp:product-category:update')") |
| 47 | public CommonResult<Boolean> updateProductCategory(@Valid @RequestBody ErpProductCategorySaveReqVO updateReqVO) { | 49 | public CommonResult<Boolean> updateProductCategory(@Valid @RequestBody ErpProductCategorySaveReqVO updateReqVO) { |
| 48 | productCategoryService.updateProductCategory(updateReqVO); | 50 | productCategoryService.updateProductCategory(updateReqVO); |
| @@ -50,7 +52,7 @@ public class ErpProductCategoryController { | @@ -50,7 +52,7 @@ public class ErpProductCategoryController { | ||
| 50 | } | 52 | } |
| 51 | 53 | ||
| 52 | @DeleteMapping("/delete") | 54 | @DeleteMapping("/delete") |
| 53 | - @Operation(summary = "删除ERP 产品分类") | 55 | + @Operation(summary = "删除产品分类") |
| 54 | @Parameter(name = "id", description = "编号", required = true) | 56 | @Parameter(name = "id", description = "编号", required = true) |
| 55 | @PreAuthorize("@ss.hasPermission('erp:product-category:delete')") | 57 | @PreAuthorize("@ss.hasPermission('erp:product-category:delete')") |
| 56 | public CommonResult<Boolean> deleteProductCategory(@RequestParam("id") Long id) { | 58 | public CommonResult<Boolean> deleteProductCategory(@RequestParam("id") Long id) { |
| @@ -59,31 +61,40 @@ public class ErpProductCategoryController { | @@ -59,31 +61,40 @@ public class ErpProductCategoryController { | ||
| 59 | } | 61 | } |
| 60 | 62 | ||
| 61 | @GetMapping("/get") | 63 | @GetMapping("/get") |
| 62 | - @Operation(summary = "获得ERP 产品分类") | 64 | + @Operation(summary = "获得产品分类") |
| 63 | @Parameter(name = "id", description = "编号", required = true, example = "1024") | 65 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 64 | @PreAuthorize("@ss.hasPermission('erp:product-category:query')") | 66 | @PreAuthorize("@ss.hasPermission('erp:product-category:query')") |
| 65 | public CommonResult<ErpProductCategoryRespVO> getProductCategory(@RequestParam("id") Long id) { | 67 | public CommonResult<ErpProductCategoryRespVO> getProductCategory(@RequestParam("id") Long id) { |
| 66 | - ErpProductCategoryDO productCategory = productCategoryService.getProductCategory(id); | ||
| 67 | - return success(BeanUtils.toBean(productCategory, ErpProductCategoryRespVO.class)); | 68 | + ErpProductCategoryDO category = productCategoryService.getProductCategory(id); |
| 69 | + return success(BeanUtils.toBean(category, ErpProductCategoryRespVO.class)); | ||
| 68 | } | 70 | } |
| 69 | 71 | ||
| 70 | @GetMapping("/list") | 72 | @GetMapping("/list") |
| 71 | - @Operation(summary = "获得ERP 产品分类列表") | 73 | + @Operation(summary = "获得产品分类列表") |
| 72 | @PreAuthorize("@ss.hasPermission('erp:product-category:query')") | 74 | @PreAuthorize("@ss.hasPermission('erp:product-category:query')") |
| 73 | public CommonResult<List<ErpProductCategoryRespVO>> getProductCategoryList(@Valid ErpProductCategoryListReqVO listReqVO) { | 75 | public CommonResult<List<ErpProductCategoryRespVO>> getProductCategoryList(@Valid ErpProductCategoryListReqVO listReqVO) { |
| 74 | List<ErpProductCategoryDO> list = productCategoryService.getProductCategoryList(listReqVO); | 76 | List<ErpProductCategoryDO> list = productCategoryService.getProductCategoryList(listReqVO); |
| 75 | return success(BeanUtils.toBean(list, ErpProductCategoryRespVO.class)); | 77 | return success(BeanUtils.toBean(list, ErpProductCategoryRespVO.class)); |
| 76 | } | 78 | } |
| 77 | 79 | ||
| 80 | + @GetMapping("/simple-list") | ||
| 81 | + @Operation(summary = "获得产品分类精简列表", description = "只包含被开启的分类,主要用于前端的下拉选项") | ||
| 82 | + public CommonResult<List<ErpProductCategoryRespVO>> getProductCategorySimpleList() { | ||
| 83 | + List<ErpProductCategoryDO> list = productCategoryService.getProductCategoryList( | ||
| 84 | + new ErpProductCategoryListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus())); | ||
| 85 | + return success(convertList(list, category -> new ErpProductCategoryRespVO() | ||
| 86 | + .setId(category.getId()).setName(category.getName()).setParentId(category.getParentId()))); | ||
| 87 | + } | ||
| 88 | + | ||
| 78 | @GetMapping("/export-excel") | 89 | @GetMapping("/export-excel") |
| 79 | - @Operation(summary = "导出ERP 产品分类 Excel") | 90 | + @Operation(summary = "导出产品分类 Excel") |
| 80 | @PreAuthorize("@ss.hasPermission('erp:product-category:export')") | 91 | @PreAuthorize("@ss.hasPermission('erp:product-category:export')") |
| 81 | @OperateLog(type = EXPORT) | 92 | @OperateLog(type = EXPORT) |
| 82 | public void exportProductCategoryExcel(@Valid ErpProductCategoryListReqVO listReqVO, | 93 | public void exportProductCategoryExcel(@Valid ErpProductCategoryListReqVO listReqVO, |
| 83 | HttpServletResponse response) throws IOException { | 94 | HttpServletResponse response) throws IOException { |
| 84 | List<ErpProductCategoryDO> list = productCategoryService.getProductCategoryList(listReqVO); | 95 | List<ErpProductCategoryDO> list = productCategoryService.getProductCategoryList(listReqVO); |
| 85 | // 导出 Excel | 96 | // 导出 Excel |
| 86 | - ExcelUtils.write(response, "ERP 产品分类.xls", "数据", ErpProductCategoryRespVO.class, | 97 | + ExcelUtils.write(response, "产品分类.xls", "数据", ErpProductCategoryRespVO.class, |
| 87 | BeanUtils.toBean(list, ErpProductCategoryRespVO.class)); | 98 | BeanUtils.toBean(list, ErpProductCategoryRespVO.class)); |
| 88 | } | 99 | } |
| 89 | 100 |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/ErpProductController.java
| 1 | package cn.iocoder.yudao.module.erp.controller.admin.product; | 1 | package cn.iocoder.yudao.module.erp.controller.admin.product; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageParam; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | ||
| 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 8 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 7 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 9 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 8 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | 10 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 9 | import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductPageReqVO; | 11 | 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; | 12 | 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; | 13 | import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductSaveReqVO; |
| 14 | +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO; | ||
| 12 | import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO; | 15 | import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO; |
| 16 | +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO; | ||
| 17 | +import cn.iocoder.yudao.module.erp.service.product.ErpProductCategoryService; | ||
| 13 | import cn.iocoder.yudao.module.erp.service.product.ErpProductService; | 18 | import cn.iocoder.yudao.module.erp.service.product.ErpProductService; |
| 19 | +import cn.iocoder.yudao.module.erp.service.product.ErpProductUnitService; | ||
| 14 | import io.swagger.v3.oas.annotations.Operation; | 20 | import io.swagger.v3.oas.annotations.Operation; |
| 15 | import io.swagger.v3.oas.annotations.Parameter; | 21 | import io.swagger.v3.oas.annotations.Parameter; |
| 16 | import io.swagger.v3.oas.annotations.tags.Tag; | 22 | import io.swagger.v3.oas.annotations.tags.Tag; |
| @@ -22,9 +28,10 @@ import org.springframework.validation.annotation.Validated; | @@ -22,9 +28,10 @@ import org.springframework.validation.annotation.Validated; | ||
| 22 | import org.springframework.web.bind.annotation.*; | 28 | import org.springframework.web.bind.annotation.*; |
| 23 | 29 | ||
| 24 | import java.io.IOException; | 30 | import java.io.IOException; |
| 25 | -import java.util.List; | 31 | +import java.util.Map; |
| 26 | 32 | ||
| 27 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 33 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 34 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | ||
| 28 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | 35 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 29 | 36 | ||
| 30 | @Tag(name = "管理后台 - ERP 产品") | 37 | @Tag(name = "管理后台 - ERP 产品") |
| @@ -35,6 +42,10 @@ public class ErpProductController { | @@ -35,6 +42,10 @@ public class ErpProductController { | ||
| 35 | 42 | ||
| 36 | @Resource | 43 | @Resource |
| 37 | private ErpProductService productService; | 44 | private ErpProductService productService; |
| 45 | + @Resource | ||
| 46 | + private ErpProductCategoryService productCategoryService; | ||
| 47 | + @Resource | ||
| 48 | + private ErpProductUnitService productUnitService; | ||
| 38 | 49 | ||
| 39 | @PostMapping("/create") | 50 | @PostMapping("/create") |
| 40 | @Operation(summary = "创建产品") | 51 | @Operation(summary = "创建产品") |
| @@ -74,7 +85,7 @@ public class ErpProductController { | @@ -74,7 +85,7 @@ public class ErpProductController { | ||
| 74 | @PreAuthorize("@ss.hasPermission('erp:product:query')") | 85 | @PreAuthorize("@ss.hasPermission('erp:product:query')") |
| 75 | public CommonResult<PageResult<ProductRespVO>> getProductPage(@Valid ProductPageReqVO pageReqVO) { | 86 | public CommonResult<PageResult<ProductRespVO>> getProductPage(@Valid ProductPageReqVO pageReqVO) { |
| 76 | PageResult<ErpProductDO> pageResult = productService.getProductPage(pageReqVO); | 87 | PageResult<ErpProductDO> pageResult = productService.getProductPage(pageReqVO); |
| 77 | - return success(BeanUtils.toBean(pageResult, ProductRespVO.class)); | 88 | + return success(buildProductDetailPage(pageResult)); |
| 78 | } | 89 | } |
| 79 | 90 | ||
| 80 | @GetMapping("/export-excel") | 91 | @GetMapping("/export-excel") |
| @@ -84,10 +95,26 @@ public class ErpProductController { | @@ -84,10 +95,26 @@ public class ErpProductController { | ||
| 84 | public void exportProductExcel(@Valid ProductPageReqVO pageReqVO, | 95 | public void exportProductExcel(@Valid ProductPageReqVO pageReqVO, |
| 85 | HttpServletResponse response) throws IOException { | 96 | HttpServletResponse response) throws IOException { |
| 86 | pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | 97 | pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
| 87 | - List<ErpProductDO> list = productService.getProductPage(pageReqVO).getList(); | 98 | + PageResult<ErpProductDO> pageResult = productService.getProductPage(pageReqVO); |
| 88 | // 导出 Excel | 99 | // 导出 Excel |
| 89 | ExcelUtils.write(response, "产品.xls", "数据", ProductRespVO.class, | 100 | ExcelUtils.write(response, "产品.xls", "数据", ProductRespVO.class, |
| 90 | - BeanUtils.toBean(list, ProductRespVO.class)); | 101 | + buildProductDetailPage(pageResult).getList()); |
| 102 | + } | ||
| 103 | + | ||
| 104 | + private PageResult<ProductRespVO> buildProductDetailPage(PageResult<ErpProductDO> pageResult) { | ||
| 105 | + if (CollUtil.isEmpty(pageResult.getList())) { | ||
| 106 | + return PageResult.empty(pageResult.getTotal()); | ||
| 107 | + } | ||
| 108 | + Map<Long, ErpProductCategoryDO> categoryMap = productCategoryService.getProductCategoryMap( | ||
| 109 | + convertSet(pageResult.getList(), ErpProductDO::getCategoryId)); | ||
| 110 | + Map<Long, ErpProductUnitDO> unitMap = productUnitService.getProductUnitMap( | ||
| 111 | + convertSet(pageResult.getList(), ErpProductDO::getUnitId)); | ||
| 112 | + return BeanUtils.toBean(pageResult, ProductRespVO.class, product -> { | ||
| 113 | + MapUtils.findAndThen(categoryMap, product.getCategoryId(), | ||
| 114 | + category -> product.setCategoryName(category.getName())); | ||
| 115 | + MapUtils.findAndThen(unitMap, product.getUnitId(), | ||
| 116 | + unit -> product.setUnitName(unit.getName())); | ||
| 117 | + }); | ||
| 91 | } | 118 | } |
| 92 | 119 | ||
| 93 | } | 120 | } |
| 94 | \ No newline at end of file | 121 | \ 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
| 1 | package cn.iocoder.yudao.module.erp.controller.admin.product; | 1 | package cn.iocoder.yudao.module.erp.controller.admin.product; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | 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.PageParam; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| @@ -25,6 +26,7 @@ import java.io.IOException; | @@ -25,6 +26,7 @@ import java.io.IOException; | ||
| 25 | import java.util.List; | 26 | import java.util.List; |
| 26 | 27 | ||
| 27 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 28 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 29 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | ||
| 28 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | 30 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 29 | 31 | ||
| 30 | @Tag(name = "管理后台 - ERP 产品单位") | 32 | @Tag(name = "管理后台 - ERP 产品单位") |
| @@ -77,6 +79,13 @@ public class ErpProductUnitController { | @@ -77,6 +79,13 @@ public class ErpProductUnitController { | ||
| 77 | return success(BeanUtils.toBean(pageResult, ErpProductUnitRespVO.class)); | 79 | return success(BeanUtils.toBean(pageResult, ErpProductUnitRespVO.class)); |
| 78 | } | 80 | } |
| 79 | 81 | ||
| 82 | + @GetMapping("/simple-list") | ||
| 83 | + @Operation(summary = "获得产品单位精简列表", description = "只包含被开启的单位,主要用于前端的下拉选项") | ||
| 84 | + public CommonResult<List<ErpProductUnitRespVO>> getProductUnitSimpleList() { | ||
| 85 | + List<ErpProductUnitDO> list = productUnitService.getProductUnitListByStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 86 | + return success(convertList(list, unit -> new ErpProductUnitRespVO().setId(unit.getId()).setName(unit.getName()))); | ||
| 87 | + } | ||
| 88 | + | ||
| 80 | @GetMapping("/export-excel") | 89 | @GetMapping("/export-excel") |
| 81 | @Operation(summary = "导出产品单位 Excel") | 90 | @Operation(summary = "导出产品单位 Excel") |
| 82 | @PreAuthorize("@ss.hasPermission('erp:product-unit:export')") | 91 | @PreAuthorize("@ss.hasPermission('erp:product-unit:export')") |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/vo/product/ProductRespVO.java
| @@ -26,12 +26,16 @@ public class ProductRespVO { | @@ -26,12 +26,16 @@ public class ProductRespVO { | ||
| 26 | private String barCode; | 26 | private String barCode; |
| 27 | 27 | ||
| 28 | @Schema(description = "产品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11161") | 28 | @Schema(description = "产品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11161") |
| 29 | - @ExcelProperty("产品分类编号") | ||
| 30 | private Long categoryId; | 29 | private Long categoryId; |
| 30 | + @Schema(description = "产品分类", requiredMode = Schema.RequiredMode.REQUIRED, example = "水果") | ||
| 31 | + @ExcelProperty("产品分类") | ||
| 32 | + private String categoryName; | ||
| 31 | 33 | ||
| 32 | @Schema(description = "单位编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8869") | 34 | @Schema(description = "单位编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8869") |
| 33 | - @ExcelProperty("单位编号") | ||
| 34 | - private Integer unitId; | 35 | + private Long unitId; |
| 36 | + @Schema(description = "单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "个") | ||
| 37 | + @ExcelProperty("单位") | ||
| 38 | + private String unitName; | ||
| 35 | 39 | ||
| 36 | @Schema(description = "产品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | 40 | @Schema(description = "产品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") |
| 37 | @ExcelProperty("产品状态") | 41 | @ExcelProperty("产品状态") |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/vo/product/ProductSaveReqVO.java
| 1 | package cn.iocoder.yudao.module.erp.controller.admin.product.vo.product; | 1 | package cn.iocoder.yudao.module.erp.controller.admin.product.vo.product; |
| 2 | 2 | ||
| 3 | import io.swagger.v3.oas.annotations.media.Schema; | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | -import lombok.*; | ||
| 5 | -import java.util.*; | ||
| 6 | -import jakarta.validation.constraints.*; | 4 | +import jakarta.validation.constraints.NotEmpty; |
| 5 | +import jakarta.validation.constraints.NotNull; | ||
| 6 | +import lombok.Data; | ||
| 7 | + | ||
| 7 | import java.math.BigDecimal; | 8 | import java.math.BigDecimal; |
| 8 | 9 | ||
| 9 | @Schema(description = "管理后台 - ERP 产品新增/修改 Request VO") | 10 | @Schema(description = "管理后台 - ERP 产品新增/修改 Request VO") |
| @@ -27,7 +28,7 @@ public class ProductSaveReqVO { | @@ -27,7 +28,7 @@ public class ProductSaveReqVO { | ||
| 27 | 28 | ||
| 28 | @Schema(description = "单位编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8869") | 29 | @Schema(description = "单位编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8869") |
| 29 | @NotNull(message = "单位编号不能为空") | 30 | @NotNull(message = "单位编号不能为空") |
| 30 | - private Integer unitId; | 31 | + private Long unitId; |
| 31 | 32 | ||
| 32 | @Schema(description = "产品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | 33 | @Schema(description = "产品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") |
| 33 | @NotNull(message = "产品状态不能为空") | 34 | @NotNull(message = "产品状态不能为空") |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/vo/unit/ErpProductUnitPageReqVO.java
| @@ -5,11 +5,6 @@ import io.swagger.v3.oas.annotations.media.Schema; | @@ -5,11 +5,6 @@ import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | import lombok.Data; | 5 | import lombok.Data; |
| 6 | import lombok.EqualsAndHashCode; | 6 | import lombok.EqualsAndHashCode; |
| 7 | import lombok.ToString; | 7 | import lombok.ToString; |
| 8 | -import org.springframework.format.annotation.DateTimeFormat; | ||
| 9 | - | ||
| 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 | 8 | ||
| 14 | @Schema(description = "管理后台 - ERP 产品单位分页 Request VO") | 9 | @Schema(description = "管理后台 - ERP 产品单位分页 Request VO") |
| 15 | @Data | 10 | @Data |
| @@ -23,8 +18,4 @@ public class ErpProductUnitPageReqVO extends PageParam { | @@ -23,8 +18,4 @@ public class ErpProductUnitPageReqVO extends PageParam { | ||
| 23 | @Schema(description = "单位状态", example = "1") | 18 | @Schema(description = "单位状态", example = "1") |
| 24 | private Integer status; | 19 | private Integer status; |
| 25 | 20 | ||
| 26 | - @Schema(description = "创建时间") | ||
| 27 | - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 28 | - private LocalDateTime[] createTime; | ||
| 29 | - | ||
| 30 | } | 21 | } |
| 31 | \ No newline at end of file | 22 | \ 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
| 1 | package cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit; | 1 | package cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | ||
| 4 | +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; | ||
| 3 | import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | 5 | import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; |
| 4 | import com.alibaba.excel.annotation.ExcelProperty; | 6 | import com.alibaba.excel.annotation.ExcelProperty; |
| 5 | import io.swagger.v3.oas.annotations.media.Schema; | 7 | import io.swagger.v3.oas.annotations.media.Schema; |
| 6 | -import jakarta.validation.constraints.NotNull; | ||
| 7 | import lombok.Data; | 8 | import lombok.Data; |
| 8 | 9 | ||
| 9 | import java.time.LocalDateTime; | 10 | import java.time.LocalDateTime; |
| @@ -23,7 +24,7 @@ public class ErpProductUnitRespVO { | @@ -23,7 +24,7 @@ public class ErpProductUnitRespVO { | ||
| 23 | 24 | ||
| 24 | @Schema(description = "单位状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | 25 | @Schema(description = "单位状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 25 | @ExcelProperty("单位状态") | 26 | @ExcelProperty("单位状态") |
| 26 | - @NotNull(message = "分类排序不能为空") | 27 | + @DictFormat(DictTypeConstants.COMMON_STATUS) |
| 27 | private Integer status; | 28 | private Integer status; |
| 28 | 29 | ||
| 29 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | 30 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/vo/unit/ErpProductUnitSaveReqVO.java
| 1 | package cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit; | 1 | package cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | ||
| 3 | import io.swagger.v3.oas.annotations.media.Schema; | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | import jakarta.validation.constraints.NotEmpty; | 6 | import jakarta.validation.constraints.NotEmpty; |
| 5 | import jakarta.validation.constraints.NotNull; | 7 | import jakarta.validation.constraints.NotNull; |
| @@ -18,6 +20,7 @@ public class ErpProductUnitSaveReqVO { | @@ -18,6 +20,7 @@ public class ErpProductUnitSaveReqVO { | ||
| 18 | 20 | ||
| 19 | @Schema(description = "单位状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | 21 | @Schema(description = "单位状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 20 | @NotNull(message = "单位状态不能为空") | 22 | @NotNull(message = "单位状态不能为空") |
| 23 | + @InEnum(CommonStatusEnum.class) | ||
| 21 | private Integer status; | 24 | private Integer status; |
| 22 | 25 | ||
| 23 | } | 26 | } |
| 24 | \ 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/dataobject/product/ErpProductDO.java
| @@ -45,9 +45,9 @@ public class ErpProductDO extends BaseDO { | @@ -45,9 +45,9 @@ public class ErpProductDO extends BaseDO { | ||
| 45 | /** | 45 | /** |
| 46 | * 单位编号 | 46 | * 单位编号 |
| 47 | * | 47 | * |
| 48 | - * TODO 芋艿,关联 | 48 | + * 关联 {@link ErpProductUnitDO#getId()} |
| 49 | */ | 49 | */ |
| 50 | - private Integer unitId; | 50 | + private Long unitId; |
| 51 | /** | 51 | /** |
| 52 | * 产品状态 | 52 | * 产品状态 |
| 53 | * | 53 | * |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/product/ErpProductMapper.java
| @@ -23,4 +23,12 @@ public interface ErpProductMapper extends BaseMapperX<ErpProductDO> { | @@ -23,4 +23,12 @@ public interface ErpProductMapper extends BaseMapperX<ErpProductDO> { | ||
| 23 | .orderByDesc(ErpProductDO::getId)); | 23 | .orderByDesc(ErpProductDO::getId)); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | + default Long selectCountByCategoryId(Long categoryId) { | ||
| 27 | + return selectCount(ErpProductDO::getCategoryId, categoryId); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + default Long selectCountByUnitId(Long unitId) { | ||
| 31 | + return selectCount(ErpProductDO::getUnitId, unitId); | ||
| 32 | + } | ||
| 33 | + | ||
| 26 | } | 34 | } |
| 27 | \ 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/ErpProductUnitMapper.java
| @@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit.ErpProductUn | @@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit.ErpProductUn | ||
| 7 | import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO; | 7 | import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO; |
| 8 | import org.apache.ibatis.annotations.Mapper; | 8 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 9 | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 10 | /** | 12 | /** |
| 11 | * ERP 产品单位 Mapper | 13 | * ERP 产品单位 Mapper |
| 12 | * | 14 | * |
| @@ -19,8 +21,15 @@ public interface ErpProductUnitMapper extends BaseMapperX<ErpProductUnitDO> { | @@ -19,8 +21,15 @@ public interface ErpProductUnitMapper extends BaseMapperX<ErpProductUnitDO> { | ||
| 19 | return selectPage(reqVO, new LambdaQueryWrapperX<ErpProductUnitDO>() | 21 | return selectPage(reqVO, new LambdaQueryWrapperX<ErpProductUnitDO>() |
| 20 | .likeIfPresent(ErpProductUnitDO::getName, reqVO.getName()) | 22 | .likeIfPresent(ErpProductUnitDO::getName, reqVO.getName()) |
| 21 | .eqIfPresent(ErpProductUnitDO::getStatus, reqVO.getStatus()) | 23 | .eqIfPresent(ErpProductUnitDO::getStatus, reqVO.getStatus()) |
| 22 | - .betweenIfPresent(ErpProductUnitDO::getCreateTime, reqVO.getCreateTime()) | ||
| 23 | .orderByDesc(ErpProductUnitDO::getId)); | 24 | .orderByDesc(ErpProductUnitDO::getId)); |
| 24 | } | 25 | } |
| 25 | 26 | ||
| 27 | + default ErpProductUnitDO selectByName(String name) { | ||
| 28 | + return selectOne(ErpProductUnitDO::getName, name); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + default List<ErpProductUnitDO> selectListByStatus(Integer status) { | ||
| 32 | + return selectList(ErpProductUnitDO::getStatus, status); | ||
| 33 | + } | ||
| 34 | + | ||
| 26 | } | 35 | } |
| 27 | \ 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/service/product/ErpProductCategoryService.java
| @@ -5,7 +5,11 @@ import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProdu | @@ -5,7 +5,11 @@ import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProdu | ||
| 5 | import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO; | 5 | import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO; |
| 6 | import jakarta.validation.Valid; | 6 | import jakarta.validation.Valid; |
| 7 | 7 | ||
| 8 | +import java.util.Collection; | ||
| 8 | import java.util.List; | 9 | import java.util.List; |
| 10 | +import java.util.Map; | ||
| 11 | + | ||
| 12 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | ||
| 9 | 13 | ||
| 10 | /** | 14 | /** |
| 11 | * ERP 产品分类 Service 接口 | 15 | * ERP 产品分类 Service 接口 |
| @@ -40,7 +44,7 @@ public interface ErpProductCategoryService { | @@ -40,7 +44,7 @@ public interface ErpProductCategoryService { | ||
| 40 | * 获得产品分类 | 44 | * 获得产品分类 |
| 41 | * | 45 | * |
| 42 | * @param id 编号 | 46 | * @param id 编号 |
| 43 | - * @return ERP 产品分类 | 47 | + * @return 产品分类 |
| 44 | */ | 48 | */ |
| 45 | ErpProductCategoryDO getProductCategory(Long id); | 49 | ErpProductCategoryDO getProductCategory(Long id); |
| 46 | 50 | ||
| @@ -48,8 +52,26 @@ public interface ErpProductCategoryService { | @@ -48,8 +52,26 @@ public interface ErpProductCategoryService { | ||
| 48 | * 获得产品分类列表 | 52 | * 获得产品分类列表 |
| 49 | * | 53 | * |
| 50 | * @param listReqVO 查询条件 | 54 | * @param listReqVO 查询条件 |
| 51 | - * @return ERP 产品分类列表 | 55 | + * @return 产品分类列表 |
| 52 | */ | 56 | */ |
| 53 | List<ErpProductCategoryDO> getProductCategoryList(ErpProductCategoryListReqVO listReqVO); | 57 | List<ErpProductCategoryDO> getProductCategoryList(ErpProductCategoryListReqVO listReqVO); |
| 54 | 58 | ||
| 59 | + /** | ||
| 60 | + * 获得产品分类列表 | ||
| 61 | + * | ||
| 62 | + * @param ids 编号数组 | ||
| 63 | + * @return 产品分类列表 | ||
| 64 | + */ | ||
| 65 | + List<ErpProductCategoryDO> getProductCategoryList(Collection<Long> ids); | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * 获得产品分类 Map | ||
| 69 | + * | ||
| 70 | + * @param ids 编号数组 | ||
| 71 | + * @return 产品分类 Map | ||
| 72 | + */ | ||
| 73 | + default Map<Long, ErpProductCategoryDO> getProductCategoryMap(Collection<Long> ids) { | ||
| 74 | + return convertMap(getProductCategoryList(ids), ErpProductCategoryDO::getId); | ||
| 75 | + } | ||
| 76 | + | ||
| 55 | } | 77 | } |
| 56 | \ No newline at end of file | 78 | \ 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
| @@ -6,9 +6,11 @@ import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProdu | @@ -6,9 +6,11 @@ import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProdu | ||
| 6 | import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO; | 6 | import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO; |
| 7 | import cn.iocoder.yudao.module.erp.dal.mysql.product.ErpProductCategoryMapper; | 7 | import cn.iocoder.yudao.module.erp.dal.mysql.product.ErpProductCategoryMapper; |
| 8 | import jakarta.annotation.Resource; | 8 | import jakarta.annotation.Resource; |
| 9 | +import org.springframework.context.annotation.Lazy; | ||
| 9 | import org.springframework.stereotype.Service; | 10 | import org.springframework.stereotype.Service; |
| 10 | import org.springframework.validation.annotation.Validated; | 11 | import org.springframework.validation.annotation.Validated; |
| 11 | 12 | ||
| 13 | +import java.util.Collection; | ||
| 12 | import java.util.List; | 14 | import java.util.List; |
| 13 | import java.util.Objects; | 15 | import java.util.Objects; |
| 14 | 16 | ||
| @@ -27,6 +29,10 @@ public class ErpProductCategoryServiceImpl implements ErpProductCategoryService | @@ -27,6 +29,10 @@ public class ErpProductCategoryServiceImpl implements ErpProductCategoryService | ||
| 27 | @Resource | 29 | @Resource |
| 28 | private ErpProductCategoryMapper productCategoryMapper; | 30 | private ErpProductCategoryMapper productCategoryMapper; |
| 29 | 31 | ||
| 32 | + @Resource | ||
| 33 | + @Lazy // 延迟加载,避免循环依赖 | ||
| 34 | + private ErpProductService productService; | ||
| 35 | + | ||
| 30 | @Override | 36 | @Override |
| 31 | public Long createProductCategory(ErpProductCategorySaveReqVO createReqVO) { | 37 | public Long createProductCategory(ErpProductCategorySaveReqVO createReqVO) { |
| 32 | // 校验父分类编号的有效性 | 38 | // 校验父分类编号的有效性 |
| @@ -57,13 +63,17 @@ public class ErpProductCategoryServiceImpl implements ErpProductCategoryService | @@ -57,13 +63,17 @@ public class ErpProductCategoryServiceImpl implements ErpProductCategoryService | ||
| 57 | 63 | ||
| 58 | @Override | 64 | @Override |
| 59 | public void deleteProductCategory(Long id) { | 65 | public void deleteProductCategory(Long id) { |
| 60 | - // 校验存在 | 66 | + // 1.1 校验存在 |
| 61 | validateProductCategoryExists(id); | 67 | validateProductCategoryExists(id); |
| 62 | - // 校验是否有子产品分类 | 68 | + // 1.2 校验是否有子产品分类 |
| 63 | if (productCategoryMapper.selectCountByParentId(id) > 0) { | 69 | if (productCategoryMapper.selectCountByParentId(id) > 0) { |
| 64 | throw exception(PRODUCT_CATEGORY_EXITS_CHILDREN); | 70 | throw exception(PRODUCT_CATEGORY_EXITS_CHILDREN); |
| 65 | } | 71 | } |
| 66 | - // 删除 | 72 | + // 1.3 校验是否有产品 |
| 73 | + if (productService.getProductCountByCategoryId(id) > 0) { | ||
| 74 | + throw exception(PRODUCT_CATEGORY_EXITS_PRODUCT); | ||
| 75 | + } | ||
| 76 | + // 2. 删除 | ||
| 67 | productCategoryMapper.deleteById(id); | 77 | productCategoryMapper.deleteById(id); |
| 68 | } | 78 | } |
| 69 | 79 | ||
| @@ -131,4 +141,9 @@ public class ErpProductCategoryServiceImpl implements ErpProductCategoryService | @@ -131,4 +141,9 @@ public class ErpProductCategoryServiceImpl implements ErpProductCategoryService | ||
| 131 | return productCategoryMapper.selectList(listReqVO); | 141 | return productCategoryMapper.selectList(listReqVO); |
| 132 | } | 142 | } |
| 133 | 143 | ||
| 144 | + @Override | ||
| 145 | + public List<ErpProductCategoryDO> getProductCategoryList(Collection<Long> ids) { | ||
| 146 | + return productCategoryMapper.selectBatchIds(ids); | ||
| 147 | + } | ||
| 148 | + | ||
| 134 | } | 149 | } |
| 135 | \ No newline at end of file | 150 | \ 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
| @@ -51,4 +51,20 @@ public interface ErpProductService { | @@ -51,4 +51,20 @@ public interface ErpProductService { | ||
| 51 | */ | 51 | */ |
| 52 | PageResult<ErpProductDO> getProductPage(ProductPageReqVO pageReqVO); | 52 | PageResult<ErpProductDO> getProductPage(ProductPageReqVO pageReqVO); |
| 53 | 53 | ||
| 54 | + /** | ||
| 55 | + * 基于产品分类编号,获得产品数量 | ||
| 56 | + * | ||
| 57 | + * @param categoryId 产品分类编号 | ||
| 58 | + * @return 产品数量 | ||
| 59 | + */ | ||
| 60 | + Long getProductCountByCategoryId(Long categoryId); | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * 基于产品单位编号,获得产品数量 | ||
| 64 | + * | ||
| 65 | + * @param unitId 产品单位编号 | ||
| 66 | + * @return 产品数量 | ||
| 67 | + */ | ||
| 68 | + Long getProductCountByUnitId(Long unitId); | ||
| 69 | + | ||
| 54 | } | 70 | } |
| 55 | \ No newline at end of file | 71 | \ 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
| @@ -69,4 +69,14 @@ public class ErpProductServiceImpl implements ErpProductService { | @@ -69,4 +69,14 @@ public class ErpProductServiceImpl implements ErpProductService { | ||
| 69 | return productMapper.selectPage(pageReqVO); | 69 | return productMapper.selectPage(pageReqVO); |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | + @Override | ||
| 73 | + public Long getProductCountByCategoryId(Long categoryId) { | ||
| 74 | + return productMapper.selectCountByCategoryId(categoryId); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + @Override | ||
| 78 | + public Long getProductCountByUnitId(Long unitId) { | ||
| 79 | + return productMapper.selectCountByUnitId(unitId); | ||
| 80 | + } | ||
| 81 | + | ||
| 72 | } | 82 | } |
| 73 | \ No newline at end of file | 83 | \ 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
| 1 | package cn.iocoder.yudao.module.erp.service.product; | 1 | package cn.iocoder.yudao.module.erp.service.product; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 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.ErpProductUnitPageReqVO; |
| 4 | import cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit.ErpProductUnitSaveReqVO; | 5 | 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; | 6 | import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO; |
| 7 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | 7 | +import jakarta.validation.Valid; |
| 8 | + | ||
| 9 | +import java.util.Collection; | ||
| 10 | +import java.util.List; | ||
| 11 | +import java.util.Map; | ||
| 12 | + | ||
| 13 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | ||
| 8 | 14 | ||
| 9 | /** | 15 | /** |
| 10 | * ERP 产品单位 Service 接口 | 16 | * ERP 产品单位 Service 接口 |
| @@ -51,4 +57,30 @@ public interface ErpProductUnitService { | @@ -51,4 +57,30 @@ public interface ErpProductUnitService { | ||
| 51 | */ | 57 | */ |
| 52 | PageResult<ErpProductUnitDO> getProductUnitPage(ErpProductUnitPageReqVO pageReqVO); | 58 | PageResult<ErpProductUnitDO> getProductUnitPage(ErpProductUnitPageReqVO pageReqVO); |
| 53 | 59 | ||
| 60 | + /** | ||
| 61 | + * 获得指定状态的产品单位列表 | ||
| 62 | + * | ||
| 63 | + * @param status 状态 | ||
| 64 | + * @return 产品单位列表 | ||
| 65 | + */ | ||
| 66 | + List<ErpProductUnitDO> getProductUnitListByStatus(Integer status); | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * 获得产品单位列表 | ||
| 70 | + * | ||
| 71 | + * @param ids 编号数组 | ||
| 72 | + * @return 产品单位列表 | ||
| 73 | + */ | ||
| 74 | + List<ErpProductUnitDO> getProductUnitList(Collection<Long> ids); | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * 获得产品单位 Map | ||
| 78 | + * | ||
| 79 | + * @param ids 编号数组 | ||
| 80 | + * @return 产品单位 Map | ||
| 81 | + */ | ||
| 82 | + default Map<Long, ErpProductUnitDO> getProductUnitMap(Collection<Long> ids) { | ||
| 83 | + return convertMap(getProductUnitList(ids), ErpProductUnitDO::getId); | ||
| 84 | + } | ||
| 85 | + | ||
| 54 | } | 86 | } |
| 55 | \ 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/service/product/ErpProductUnitServiceImpl.java
| 1 | package cn.iocoder.yudao.module.erp.service.product; | 1 | package cn.iocoder.yudao.module.erp.service.product; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 3 | import cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit.ErpProductUnitPageReqVO; | 5 | 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; | 6 | import cn.iocoder.yudao.module.erp.controller.admin.product.vo.unit.ErpProductUnitSaveReqVO; |
| 5 | -import org.springframework.stereotype.Service; | 7 | +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO; |
| 8 | +import cn.iocoder.yudao.module.erp.dal.mysql.product.ErpProductUnitMapper; | ||
| 9 | +import com.google.common.annotations.VisibleForTesting; | ||
| 6 | import jakarta.annotation.Resource; | 10 | import jakarta.annotation.Resource; |
| 11 | +import org.springframework.context.annotation.Lazy; | ||
| 12 | +import org.springframework.stereotype.Service; | ||
| 7 | import org.springframework.validation.annotation.Validated; | 13 | import org.springframework.validation.annotation.Validated; |
| 8 | 14 | ||
| 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; | 15 | +import java.util.Collection; |
| 16 | +import java.util.List; | ||
| 14 | 17 | ||
| 15 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 18 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 16 | -import static cn.iocoder.yudao.module.erp.ErrorCodeConstants.PRODUCT_UNIT_NOT_EXISTS; | 19 | +import static cn.iocoder.yudao.module.erp.ErrorCodeConstants.*; |
| 17 | 20 | ||
| 18 | /** | 21 | /** |
| 19 | * ERP 产品单位 Service 实现类 | 22 | * ERP 产品单位 Service 实现类 |
| @@ -27,29 +30,55 @@ public class ErpProductUnitServiceImpl implements ErpProductUnitService { | @@ -27,29 +30,55 @@ public class ErpProductUnitServiceImpl implements ErpProductUnitService { | ||
| 27 | @Resource | 30 | @Resource |
| 28 | private ErpProductUnitMapper productUnitMapper; | 31 | private ErpProductUnitMapper productUnitMapper; |
| 29 | 32 | ||
| 33 | + @Resource | ||
| 34 | + @Lazy // 延迟加载,避免循环依赖 | ||
| 35 | + private ErpProductService productService; | ||
| 36 | + | ||
| 30 | @Override | 37 | @Override |
| 31 | public Long createProductUnit(ErpProductUnitSaveReqVO createReqVO) { | 38 | public Long createProductUnit(ErpProductUnitSaveReqVO createReqVO) { |
| 32 | - // 插入 | 39 | + // 1. 校验名字唯一 |
| 40 | + validateProductUnitNameUnique(null, createReqVO.getName()); | ||
| 41 | + // 2. 插入 | ||
| 33 | ErpProductUnitDO unit = BeanUtils.toBean(createReqVO, ErpProductUnitDO.class); | 42 | ErpProductUnitDO unit = BeanUtils.toBean(createReqVO, ErpProductUnitDO.class); |
| 34 | productUnitMapper.insert(unit); | 43 | productUnitMapper.insert(unit); |
| 35 | - // 返回 | ||
| 36 | return unit.getId(); | 44 | return unit.getId(); |
| 37 | } | 45 | } |
| 38 | 46 | ||
| 39 | @Override | 47 | @Override |
| 40 | public void updateProductUnit(ErpProductUnitSaveReqVO updateReqVO) { | 48 | public void updateProductUnit(ErpProductUnitSaveReqVO updateReqVO) { |
| 41 | - // 校验存在 | 49 | + // 1.1 校验存在 |
| 42 | validateProductUnitExists(updateReqVO.getId()); | 50 | validateProductUnitExists(updateReqVO.getId()); |
| 43 | - // 更新 | 51 | + // 1.2 校验名字唯一 |
| 52 | + validateProductUnitNameUnique(updateReqVO.getId(), updateReqVO.getName()); | ||
| 53 | + // 2. 更新 | ||
| 44 | ErpProductUnitDO updateObj = BeanUtils.toBean(updateReqVO, ErpProductUnitDO.class); | 54 | ErpProductUnitDO updateObj = BeanUtils.toBean(updateReqVO, ErpProductUnitDO.class); |
| 45 | productUnitMapper.updateById(updateObj); | 55 | productUnitMapper.updateById(updateObj); |
| 46 | } | 56 | } |
| 47 | 57 | ||
| 58 | + @VisibleForTesting | ||
| 59 | + void validateProductUnitNameUnique(Long id, String name) { | ||
| 60 | + ErpProductUnitDO unit = productUnitMapper.selectByName(name); | ||
| 61 | + if (unit == null) { | ||
| 62 | + return; | ||
| 63 | + } | ||
| 64 | + // 如果 id 为空,说明不用比较是否为相同 id 的字典类型 | ||
| 65 | + if (id == null) { | ||
| 66 | + throw exception(PRODUCT_UNIT_NAME_DUPLICATE); | ||
| 67 | + } | ||
| 68 | + if (!unit.getId().equals(id)) { | ||
| 69 | + throw exception(PRODUCT_UNIT_NAME_DUPLICATE); | ||
| 70 | + } | ||
| 71 | + } | ||
| 72 | + | ||
| 48 | @Override | 73 | @Override |
| 49 | public void deleteProductUnit(Long id) { | 74 | public void deleteProductUnit(Long id) { |
| 50 | - // 校验存在 | 75 | + // 1.1 校验存在 |
| 51 | validateProductUnitExists(id); | 76 | validateProductUnitExists(id); |
| 52 | - // 删除 | 77 | + // 1.2 校验商品是否使用 |
| 78 | + if (productService.getProductCountByUnitId(id) > 0) { | ||
| 79 | + throw exception(PRODUCT_UNIT_EXITS_PRODUCT); | ||
| 80 | + } | ||
| 81 | + // 2. 删除 | ||
| 53 | productUnitMapper.deleteById(id); | 82 | productUnitMapper.deleteById(id); |
| 54 | } | 83 | } |
| 55 | 84 | ||
| @@ -69,4 +98,14 @@ public class ErpProductUnitServiceImpl implements ErpProductUnitService { | @@ -69,4 +98,14 @@ public class ErpProductUnitServiceImpl implements ErpProductUnitService { | ||
| 69 | return productUnitMapper.selectPage(pageReqVO); | 98 | return productUnitMapper.selectPage(pageReqVO); |
| 70 | } | 99 | } |
| 71 | 100 | ||
| 101 | + @Override | ||
| 102 | + public List<ErpProductUnitDO> getProductUnitListByStatus(Integer status) { | ||
| 103 | + return productUnitMapper.selectListByStatus(status); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + @Override | ||
| 107 | + public List<ErpProductUnitDO> getProductUnitList(Collection<Long> ids) { | ||
| 108 | + return productUnitMapper.selectBatchIds(ids); | ||
| 109 | + } | ||
| 110 | + | ||
| 72 | } | 111 | } |
| 73 | \ No newline at end of file | 112 | \ No newline at end of file |