Commit 46d26659bf49b6457be3cad084979e90c43d2d54

Authored by YunaiV
1 parent db79926c

✨ ERP:初始化其它入库的表单 50%

Showing 28 changed files with 960 additions and 24 deletions
yudao-module-erp/yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/enums/DictTypeConstants.java
@@ -7,6 +7,7 @@ package cn.iocoder.yudao.module.erp.enums; @@ -7,6 +7,7 @@ package cn.iocoder.yudao.module.erp.enums;
7 */ 7 */
8 public interface DictTypeConstants { 8 public interface DictTypeConstants {
9 9
  10 + String AUDIT_STATUS = "erp_audit_status"; // 审核状态
10 String STOCK_RECORD_BIZ_TYPE = "erp_stock_record_biz_type"; // 库存明细的业务类型 11 String STOCK_RECORD_BIZ_TYPE = "erp_stock_record_biz_type"; // 库存明细的业务类型
11 12
12 } 13 }
yudao-module-erp/yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/enums/ErpAuditStatus.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.enums;
  2 +
  3 +import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
  4 +import lombok.Getter;
  5 +import lombok.RequiredArgsConstructor;
  6 +
  7 +import java.util.Arrays;
  8 +
  9 +/**
  10 + * ERP 审核状态枚举
  11 + *
  12 + * TODO 芋艿:目前只有待审批、已审批两个状态,未来接入工作流后,会丰富下:待提交(草稿)=》已提交(待审核)=》审核通过、审核不通过;另外,工作流需要支持“反审核”,把工作流退回到原点;
  13 + *
  14 + * @author 芋道源码
  15 + */
  16 +@RequiredArgsConstructor
  17 +@Getter
  18 +public enum ErpAuditStatus implements IntArrayValuable {
  19 +
  20 + PROCESS(10, "未审核"), // 审核中
  21 + APPROVE(20, "已审核"); // 审核通过
  22 +
  23 + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpAuditStatus::getStatus).toArray();
  24 +
  25 + /**
  26 + * 状态
  27 + */
  28 + private final Integer status;
  29 + /**
  30 + * 状态名
  31 + */
  32 + private final String name;
  33 +
  34 + @Override
  35 + public int[] array() {
  36 + return ARRAYS;
  37 + }
  38 +
  39 +}
yudao-module-erp/yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/enums/ErrorCodeConstants.java
@@ -14,9 +14,14 @@ public interface ErrorCodeConstants { @@ -14,9 +14,14 @@ public interface ErrorCodeConstants {
14 14
15 // ========== ERP 仓库 1-030-400-000 ========== 15 // ========== ERP 仓库 1-030-400-000 ==========
16 ErrorCode WAREHOUSE_NOT_EXISTS = new ErrorCode(1_030_400_000, "仓库不存在"); 16 ErrorCode WAREHOUSE_NOT_EXISTS = new ErrorCode(1_030_400_000, "仓库不存在");
  17 + ErrorCode WAREHOUSE_NOT_ENABLE = new ErrorCode(1_030_500_001, "仓库({})未启用");
  18 +
  19 + // ========== ERP 其它入库单 1-030-401-000 ==========
  20 + ErrorCode STOCK_IN_NOT_EXISTS = new ErrorCode(1_030_401_000, "其它入库单不存在");
17 21
18 // ========== ERP 产品 1-030-500-000 ========== 22 // ========== ERP 产品 1-030-500-000 ==========
19 ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_030_500_000, "产品不存在"); 23 ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_030_500_000, "产品不存在");
  24 + ErrorCode PRODUCT_NOT_ENABLE = new ErrorCode(1_030_500_001, "产品({})未启用");
20 25
21 // ========== ERP 产品分类 1-030-501-000 ========== 26 // ========== ERP 产品分类 1-030-501-000 ==========
22 ErrorCode PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_030_501_000, "产品分类不存在"); 27 ErrorCode PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_030_501_000, "产品分类不存在");
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/product/ErpProductController.java
@@ -26,6 +26,7 @@ import java.io.IOException; @@ -26,6 +26,7 @@ import java.io.IOException;
26 import java.util.List; 26 import java.util.List;
27 27
28 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;
29 import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; 30 import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
30 31
31 @Tag(name = "管理后台 - ERP 产品") 32 @Tag(name = "管理后台 - ERP 产品")
@@ -80,8 +81,12 @@ public class ErpProductController { @@ -80,8 +81,12 @@ public class ErpProductController {
80 @GetMapping("/simple-list") 81 @GetMapping("/simple-list")
81 @Operation(summary = "获得产品精简列表", description = "只包含被开启的产品,主要用于前端的下拉选项") 82 @Operation(summary = "获得产品精简列表", description = "只包含被开启的产品,主要用于前端的下拉选项")
82 public CommonResult<List<ErpProductRespVO>> getProductSimpleList() { 83 public CommonResult<List<ErpProductRespVO>> getProductSimpleList() {
83 - List<ErpProductDO> list = productService.getProductListByStatus(CommonStatusEnum.ENABLE.getStatus());  
84 - return success(BeanUtils.toBean(list, ErpProductRespVO.class)); 84 + List<ErpProductRespVO> list = productService.getProductVOListByStatus(CommonStatusEnum.ENABLE.getStatus());
  85 + return success(convertList(list, product -> new ErpProductRespVO().setId(product.getId())
  86 + .setName(product.getName()).setBarCode(product.getBarCode())
  87 + .setCategoryId(product.getCategoryId()).setCategoryName(product.getCategoryName())
  88 + .setUnitId(product.getUnitId()).setUnitName(product.getUnitName())
  89 + .setPurchasePrice(product.getPurchasePrice()).setSalePrice(product.getSalePrice()).setMinPrice(product.getMinPrice())));
85 } 90 }
86 91
87 @GetMapping("/export-excel") 92 @GetMapping("/export-excel")
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpStockController.java
@@ -18,6 +18,7 @@ import cn.iocoder.yudao.module.erp.service.stock.ErpStockService; @@ -18,6 +18,7 @@ import cn.iocoder.yudao.module.erp.service.stock.ErpStockService;
18 import cn.iocoder.yudao.module.erp.service.stock.ErpWarehouseService; 18 import cn.iocoder.yudao.module.erp.service.stock.ErpWarehouseService;
19 import io.swagger.v3.oas.annotations.Operation; 19 import io.swagger.v3.oas.annotations.Operation;
20 import io.swagger.v3.oas.annotations.Parameter; 20 import io.swagger.v3.oas.annotations.Parameter;
  21 +import io.swagger.v3.oas.annotations.Parameters;
21 import io.swagger.v3.oas.annotations.tags.Tag; 22 import io.swagger.v3.oas.annotations.tags.Tag;
22 import jakarta.annotation.Resource; 23 import jakarta.annotation.Resource;
23 import jakarta.servlet.http.HttpServletResponse; 24 import jakarta.servlet.http.HttpServletResponse;
@@ -52,10 +53,16 @@ public class ErpStockController { @@ -52,10 +53,16 @@ public class ErpStockController {
52 53
53 @GetMapping("/get") 54 @GetMapping("/get")
54 @Operation(summary = "获得产品库存") 55 @Operation(summary = "获得产品库存")
55 - @Parameter(name = "id", description = "编号", required = true, example = "1024") 56 + @Parameters({
  57 + @Parameter(name = "id", description = "编号", example = "1"), // 方案一:传递 id
  58 + @Parameter(name = "productId", description = "产品编号", example = "10"), // 方案二:传递 productId + warehouseId
  59 + @Parameter(name = "warehouseId", description = "仓库编号", example = "2")
  60 + })
56 @PreAuthorize("@ss.hasPermission('erp:stock:query')") 61 @PreAuthorize("@ss.hasPermission('erp:stock:query')")
57 - public CommonResult<ErpStockRespVO> getStock(@RequestParam("id") Long id) {  
58 - ErpStockDO stock = stockService.getStock(id); 62 + public CommonResult<ErpStockRespVO> getStock(@RequestParam(value = "id", required = false) Long id,
  63 + @RequestParam(value = "productId", required = false) Long productId,
  64 + @RequestParam(value = "warehouseId", required = false) Long warehouseId) {
  65 + ErpStockDO stock = id != null ? stockService.getStock(id) : stockService.getStock(productId, warehouseId);
59 return success(BeanUtils.toBean(stock, ErpStockRespVO.class)); 66 return success(BeanUtils.toBean(stock, ErpStockRespVO.class));
60 } 67 }
61 68
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpStockInController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.stock;
  2 +
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  6 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  7 +import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
  8 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  9 +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
  10 +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
  11 +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
  12 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInPageReqVO;
  13 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInRespVO;
  14 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSaveReqVO;
  15 +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
  16 +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO;
  17 +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO;
  18 +import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
  19 +import cn.iocoder.yudao.module.erp.service.stock.ErpStockInService;
  20 +import cn.iocoder.yudao.module.erp.service.stock.ErpStockService;
  21 +import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
  22 +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
  23 +import io.swagger.v3.oas.annotations.Operation;
  24 +import io.swagger.v3.oas.annotations.Parameter;
  25 +import io.swagger.v3.oas.annotations.tags.Tag;
  26 +import jakarta.annotation.Resource;
  27 +import jakarta.servlet.http.HttpServletResponse;
  28 +import jakarta.validation.Valid;
  29 +import org.springframework.security.access.prepost.PreAuthorize;
  30 +import org.springframework.validation.annotation.Validated;
  31 +import org.springframework.web.bind.annotation.*;
  32 +
  33 +import java.io.IOException;
  34 +import java.math.BigDecimal;
  35 +import java.util.List;
  36 +import java.util.Map;
  37 +
  38 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  39 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap;
  40 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
  41 +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
  42 +
  43 +@Tag(name = "管理后台 - ERP 其它入库单")
  44 +@RestController
  45 +@RequestMapping("/erp/stock-in")
  46 +@Validated
  47 +public class ErpStockInController {
  48 +
  49 + @Resource
  50 + private ErpStockInService stockInService;
  51 + @Resource
  52 + private ErpStockService stockService;
  53 + @Resource
  54 + private ErpProductService productService;
  55 +
  56 + @Resource
  57 + private AdminUserApi adminUserApi;
  58 +
  59 + @PostMapping("/create")
  60 + @Operation(summary = "创建其它入库单")
  61 + @PreAuthorize("@ss.hasPermission('erp:stock-in:create')")
  62 + public CommonResult<Long> createStockIn(@Valid @RequestBody ErpStockInSaveReqVO createReqVO) {
  63 + return success(stockInService.createStockIn(createReqVO));
  64 + }
  65 +
  66 + @PutMapping("/update")
  67 + @Operation(summary = "更新其它入库单")
  68 + @PreAuthorize("@ss.hasPermission('erp:stock-in:update')")
  69 + public CommonResult<Boolean> updateStockIn(@Valid @RequestBody ErpStockInSaveReqVO updateReqVO) {
  70 + stockInService.updateStockIn(updateReqVO);
  71 + return success(true);
  72 + }
  73 +
  74 + @DeleteMapping("/delete")
  75 + @Operation(summary = "删除其它入库单")
  76 + @Parameter(name = "id", description = "编号", required = true)
  77 + @PreAuthorize("@ss.hasPermission('erp:stock-in:delete')")
  78 + public CommonResult<Boolean> deleteStockIn(@RequestParam("id") Long id) {
  79 + stockInService.deleteStockIn(id);
  80 + return success(true);
  81 + }
  82 +
  83 + @GetMapping("/get")
  84 + @Operation(summary = "获得其它入库单")
  85 + @Parameter(name = "id", description = "编号", required = true, example = "1024")
  86 + @PreAuthorize("@ss.hasPermission('erp:stock-in:query')")
  87 + public CommonResult<ErpStockInRespVO> getStockIn(@RequestParam("id") Long id) {
  88 + ErpStockInDO stockIn = stockInService.getStockIn(id);
  89 + if (stockIn == null) {
  90 + return success(null);
  91 + }
  92 + List<ErpStockInItemDO> stockInItems = stockInService.getStockInItemListByInId(id);
  93 +
  94 + return success(BeanUtils.toBean(stockIn, ErpStockInRespVO.class, stockInVO ->
  95 + stockInVO.setItems(BeanUtils.toBean(stockInItems, ErpStockInRespVO.Item.class, item -> {
  96 + ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId());
  97 + item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO);
  98 + }))));
  99 + }
  100 +
  101 + @GetMapping("/page")
  102 + @Operation(summary = "获得其它入库单分页")
  103 + @PreAuthorize("@ss.hasPermission('erp:stock-in:query')")
  104 + public CommonResult<PageResult<ErpStockInRespVO>> getStockInPage(@Valid ErpStockInPageReqVO pageReqVO) {
  105 + PageResult<ErpStockInDO> pageResult = stockInService.getStockInPage(pageReqVO);
  106 + return success(buildStockInVOPageResult(pageResult));
  107 + }
  108 +
  109 + @GetMapping("/export-excel")
  110 + @Operation(summary = "导出其它入库单 Excel")
  111 + @PreAuthorize("@ss.hasPermission('erp:stock-in:export')")
  112 + @OperateLog(type = EXPORT)
  113 + public void exportStockInExcel(@Valid ErpStockInPageReqVO pageReqVO,
  114 + HttpServletResponse response) throws IOException {
  115 + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
  116 + List<ErpStockInRespVO> list = buildStockInVOPageResult(stockInService.getStockInPage(pageReqVO)).getList();
  117 + // 导出 Excel
  118 + ExcelUtils.write(response, "其它入库单.xls", "数据", ErpStockInRespVO.class, list);
  119 + }
  120 +
  121 + private PageResult<ErpStockInRespVO> buildStockInVOPageResult(PageResult<ErpStockInDO> pageResult) {
  122 + if (CollUtil.isEmpty(pageResult.getList())) {
  123 + return PageResult.empty(pageResult.getTotal());
  124 + }
  125 + // 1.1 入库项
  126 + List<ErpStockInItemDO> stockInItemList = stockInService.getStockInItemListByInIds(
  127 + convertSet(pageResult.getList(), ErpStockInDO::getId));
  128 + Map<Long, List<ErpStockInItemDO>> stockInItemMap = convertMultiMap(stockInItemList, ErpStockInItemDO::getInId);
  129 + // 1.2 商品信息
  130 + Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
  131 + convertSet(stockInItemList, ErpStockInItemDO::getProductId));
  132 + // 1.3 管理员信息
  133 + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
  134 + convertSet(pageResult.getList(), erpStockRecordDO -> Long.parseLong(erpStockRecordDO.getCreator())));
  135 + // 2. 开始拼接
  136 + return BeanUtils.toBean(pageResult, ErpStockInRespVO.class, stockIn -> {
  137 + stockIn.setItems(BeanUtils.toBean(stockInItemMap.get(stockIn.getId()), ErpStockInRespVO.Item.class,
  138 + item -> MapUtils.findAndThen(productMap, item.getProductId(),
  139 + product -> item.setProductName(product.getName()).setProductUnitName(product.getUnitName()))));
  140 + stockIn.setProductNames(CollUtil.join(stockIn.getItems(), ",", ErpStockInRespVO.Item::getProductName));
  141 + MapUtils.findAndThen(userMap, Long.parseLong(stockIn.getCreator()), user -> stockIn.setCreatorName(user.getNickname()));
  142 + });
  143 + }
  144 +
  145 +}
0 \ No newline at end of file 146 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpStockRecordController.java
@@ -9,8 +9,8 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; @@ -9,8 +9,8 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
9 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; 9 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
10 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; 10 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
11 import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO; 11 import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
12 -import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stockrecord.ErpStockRecordPageReqVO;  
13 -import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stockrecord.ErpStockRecordRespVO; 12 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record.ErpStockRecordPageReqVO;
  13 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record.ErpStockRecordRespVO;
14 import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO; 14 import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO;
15 import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO; 15 import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
16 import cn.iocoder.yudao.module.erp.service.product.ErpProductService; 16 import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/in/ErpStockInPageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import cn.iocoder.yudao.framework.common.validation.InEnum;
  5 +import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus;
  6 +import io.swagger.v3.oas.annotations.media.Schema;
  7 +import lombok.Data;
  8 +import lombok.EqualsAndHashCode;
  9 +import lombok.ToString;
  10 +import org.springframework.format.annotation.DateTimeFormat;
  11 +
  12 +import java.time.LocalDateTime;
  13 +
  14 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  15 +
  16 +@Schema(description = "管理后台 - ERP 其它入库单分页 Request VO")
  17 +@Data
  18 +@EqualsAndHashCode(callSuper = true)
  19 +@ToString(callSuper = true)
  20 +public class ErpStockInPageReqVO extends PageParam {
  21 +
  22 + @Schema(description = "入库单号", example = "S123")
  23 + private String no;
  24 +
  25 + @Schema(description = "供应商编号", example = "3113")
  26 + private Long supplierId;
  27 +
  28 + @Schema(description = "入库时间")
  29 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  30 + private LocalDateTime[] inTime;
  31 +
  32 + @Schema(description = "状态", example = "10")
  33 + @InEnum(ErpAuditStatus.class)
  34 + private Integer status;
  35 +
  36 + @Schema(description = "备注", example = "随便")
  37 + private String remark;
  38 +
  39 + @Schema(description = "创建者")
  40 + private String creator;
  41 +
  42 +}
0 \ No newline at end of file 43 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/in/ErpStockInRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in;
  2 +
  3 +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
  4 +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
  5 +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
  6 +import com.alibaba.excel.annotation.ExcelProperty;
  7 +import io.swagger.v3.oas.annotations.media.Schema;
  8 +import lombok.Data;
  9 +
  10 +import java.math.BigDecimal;
  11 +import java.time.LocalDateTime;
  12 +import java.util.List;
  13 +
  14 +import static cn.iocoder.yudao.module.erp.enums.DictTypeConstants.AUDIT_STATUS;
  15 +
  16 +@Schema(description = "管理后台 - ERP 其它入库单 Response VO")
  17 +@Data
  18 +@ExcelIgnoreUnannotated
  19 +public class ErpStockInRespVO {
  20 +
  21 + @Schema(description = "入库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756")
  22 + @ExcelProperty("入库编号")
  23 + private Long id;
  24 +
  25 + @Schema(description = "入库单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "S123")
  26 + @ExcelProperty("入库单号")
  27 + private String no;
  28 +
  29 + @Schema(description = "供应商编号", example = "3113")
  30 + @ExcelProperty("供应商编号")
  31 + private Long supplierId;
  32 +
  33 + @Schema(description = "入库时间", requiredMode = Schema.RequiredMode.REQUIRED)
  34 + @ExcelProperty("入库时间")
  35 + private LocalDateTime inTime;
  36 +
  37 + @Schema(description = "合计数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15663")
  38 + @ExcelProperty("合计数量")
  39 + private BigDecimal totalCount;
  40 +
  41 + @Schema(description = "合计金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "24906")
  42 + @ExcelProperty("合计金额")
  43 + private BigDecimal totalPrice;
  44 +
  45 + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
  46 + @ExcelProperty(value = "状态", converter = DictConvert.class)
  47 + @DictFormat(AUDIT_STATUS)
  48 + private Integer status;
  49 +
  50 + @Schema(description = "备注", example = "随便")
  51 + @ExcelProperty("备注")
  52 + private String remark;
  53 +
  54 + @Schema(description = "附件 URL", example = "https://www.iocoder.cn/1.doc")
  55 + private String fileUrl;
  56 +
  57 + @Schema(description = "审核人", example = "芋道")
  58 + private String creator;
  59 + @Schema(description = "审核人名称", example = "芋道")
  60 + private String creatorName;
  61 +
  62 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  63 + @ExcelProperty("创建时间")
  64 + private LocalDateTime createTime;
  65 +
  66 + @Schema(description = "入库项列表", requiredMode = Schema.RequiredMode.REQUIRED)
  67 + private List<Item> items;
  68 +
  69 + @Schema(description = "产品信息", requiredMode = Schema.RequiredMode.REQUIRED)
  70 + @ExcelProperty("产品信息")
  71 + private String productNames;
  72 +
  73 + @Data
  74 + public static class Item {
  75 +
  76 + @Schema(description = "入库项编号", example = "11756")
  77 + private Long id;
  78 +
  79 + @Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
  80 + private Long warehouseId;
  81 +
  82 + @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
  83 + private Long productId;
  84 +
  85 + @Schema(description = "产品单价", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
  86 + private BigDecimal productPrice;
  87 +
  88 + @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
  89 + private BigDecimal count;
  90 +
  91 + @Schema(description = "备注", example = "随便")
  92 + private String remark;
  93 +
  94 + // ========== 关联字段 ==========
  95 +
  96 + @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "巧克力")
  97 + private String productName;
  98 + @Schema(description = "产品单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "盒")
  99 + private String productUnitName;
  100 +
  101 + @Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
  102 + private BigDecimal stockCount; // 该字段仅仅在“详情”和“编辑”时使用
  103 +
  104 + }
  105 +
  106 +}
0 \ No newline at end of file 107 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/in/ErpStockInSaveReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import jakarta.validation.Valid;
  5 +import jakarta.validation.constraints.NotEmpty;
  6 +import jakarta.validation.constraints.NotNull;
  7 +import lombok.Data;
  8 +
  9 +import java.math.BigDecimal;
  10 +import java.time.LocalDateTime;
  11 +import java.util.List;
  12 +
  13 +@Schema(description = "管理后台 - ERP 其它入库单新增/修改 Request VO")
  14 +@Data
  15 +public class ErpStockInSaveReqVO {
  16 +
  17 + @Schema(description = "入库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756")
  18 + private Long id;
  19 +
  20 + @Schema(description = "入库单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "S123")
  21 + @NotEmpty(message = "入库单号不能为空")
  22 + private String no;
  23 +
  24 + @Schema(description = "供应商编号", example = "3113")
  25 + private Long supplierId;
  26 +
  27 + @Schema(description = "入库时间", requiredMode = Schema.RequiredMode.REQUIRED)
  28 + @NotNull(message = "入库时间不能为空")
  29 + private LocalDateTime inTime;
  30 +
  31 + @Schema(description = "备注", example = "随便")
  32 + private String remark;
  33 +
  34 + @Schema(description = "附件 URL", example = "https://www.iocoder.cn/1.doc")
  35 + private String fileUrl;
  36 +
  37 + @Schema(description = "入库项列表", requiredMode = Schema.RequiredMode.REQUIRED)
  38 + @NotEmpty(message = "入库项列表不能为空")
  39 + @Valid
  40 + private List<Item> items;
  41 +
  42 + @Data
  43 + public static class Item {
  44 +
  45 + @Schema(description = "入库项编号", example = "11756")
  46 + private Long id;
  47 +
  48 + @Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
  49 + @NotNull(message = "仓库编号不能为空")
  50 + private Long warehouseId;
  51 +
  52 + @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
  53 + @NotNull(message = "产品编号不能为空")
  54 + private Long productId;
  55 +
  56 + @Schema(description = "产品单价", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
  57 + @NotNull(message = "产品单价不能为空")
  58 + private BigDecimal productPrice;
  59 +
  60 + @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
  61 + @NotNull(message = "产品数量不能为空")
  62 + private BigDecimal count;
  63 +
  64 + @Schema(description = "备注", example = "随便")
  65 + private String remark;
  66 +
  67 + }
  68 +
  69 +}
0 \ No newline at end of file 70 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/stockrecord/ErpStockRecordPageReqVO.java renamed to yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/record/ErpStockRecordPageReqVO.java
1 -package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stockrecord; 1 +package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.PageParam; 3 import cn.iocoder.yudao.framework.common.pojo.PageParam;
4 import io.swagger.v3.oas.annotations.media.Schema; 4 import io.swagger.v3.oas.annotations.media.Schema;
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/stockrecord/ErpStockRecordRespVO.java renamed to yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/record/ErpStockRecordRespVO.java
1 -package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stockrecord; 1 +package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record;
2 2
3 import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; 3 import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
4 import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; 4 import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/stock/ErpStockInDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.dal.dataobject.stock;
  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 +import java.time.LocalDateTime;
  11 +
  12 +/**
  13 + * ERP 其它入库单 DO
  14 + *
  15 + * @author 芋道源码
  16 + */
  17 +@TableName("erp_stock_in")
  18 +@KeySequence("erp_stock_in_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  19 +@Data
  20 +@EqualsAndHashCode(callSuper = true)
  21 +@ToString(callSuper = true)
  22 +@Builder
  23 +@NoArgsConstructor
  24 +@AllArgsConstructor
  25 +public class ErpStockInDO extends BaseDO {
  26 +
  27 + /**
  28 + * 入库编号
  29 + */
  30 + @TableId
  31 + private Long id;
  32 + /**
  33 + * 入库单号
  34 + */
  35 + private String no;
  36 + /**
  37 + * 供应商编号
  38 + *
  39 + * TODO 芋艿:待关联
  40 + */
  41 + private Long supplierId;
  42 + /**
  43 + * 入库时间
  44 + */
  45 + private LocalDateTime inTime;
  46 + /**
  47 + * 合计数量
  48 + */
  49 + private BigDecimal totalCount;
  50 + /**
  51 + * 合计金额,单位:元
  52 + */
  53 + private BigDecimal totalPrice;
  54 + /**
  55 + * 状态
  56 + *
  57 + * 枚举 {@link cn.iocoder.yudao.module.erp.enums.ErpAuditStatus}
  58 + */
  59 + private Integer status;
  60 + /**
  61 + * 备注
  62 + */
  63 + private String remark;
  64 + /**
  65 + * 附件 URL
  66 + */
  67 + private String fileUrl;
  68 +
  69 +}
0 \ No newline at end of file 70 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/stock/ErpStockInItemDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.dal.dataobject.stock;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
  5 +import com.baomidou.mybatisplus.annotation.KeySequence;
  6 +import com.baomidou.mybatisplus.annotation.TableId;
  7 +import com.baomidou.mybatisplus.annotation.TableName;
  8 +import lombok.*;
  9 +
  10 +import java.math.BigDecimal;
  11 +
  12 +/**
  13 + * ERP 其它入库单项 DO
  14 + *
  15 + * @author 芋道源码
  16 + */
  17 +@TableName("erp_stock_in_item")
  18 +@KeySequence("erp_stock_in_item_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  19 +@Data
  20 +@EqualsAndHashCode(callSuper = true)
  21 +@ToString(callSuper = true)
  22 +@Builder
  23 +@NoArgsConstructor
  24 +@AllArgsConstructor
  25 +public class ErpStockInItemDO extends BaseDO {
  26 +
  27 + /**
  28 + * 入库项编号
  29 + */
  30 + @TableId
  31 + private Long id;
  32 + /**
  33 + * 入库编号
  34 + *
  35 + * 关联 {@link ErpStockInDO#getId()}
  36 + */
  37 + private Long inId;
  38 + /**
  39 + * 仓库编号
  40 + *
  41 + * 关联 {@link ErpWarehouseDO#getId()}
  42 + */
  43 + private Long warehouseId;
  44 + /**
  45 + * 产品编号
  46 + *
  47 + * 关联 {@link ErpProductDO#getId()}
  48 + */
  49 + private Long productId;
  50 + /**
  51 + * 产品单位编号
  52 + *
  53 + * 冗余 {@link ErpProductDO#getUnitId()}
  54 + */
  55 + private Long productUnitId;
  56 + /**
  57 + * 产品单价
  58 + */
  59 + private BigDecimal productPrice;
  60 + /**
  61 + * 产品数量
  62 + */
  63 + private BigDecimal count;
  64 + /**
  65 + * 合计金额,单位:元
  66 + */
  67 + private BigDecimal totalPrice;
  68 + /**
  69 + * 备注
  70 + */
  71 + private String remark;
  72 +
  73 +}
0 \ No newline at end of file 74 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/stock/ErpStockInItemMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.dal.mysql.stock;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  4 +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO;
  5 +import org.apache.ibatis.annotations.Mapper;
  6 +
  7 +import java.util.Collection;
  8 +import java.util.List;
  9 +
  10 +/**
  11 + * ERP 其它入库单项 Mapper
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@Mapper
  16 +public interface ErpStockInItemMapper extends BaseMapperX<ErpStockInItemDO> {
  17 +
  18 + default List<ErpStockInItemDO> selectListByInId(Long inId) {
  19 + return selectList(ErpStockInItemDO::getInId, inId);
  20 + }
  21 +
  22 + default List<ErpStockInItemDO> selectListByInIds(Collection<Long> inIds) {
  23 + return selectList(ErpStockInItemDO::getInId, inIds);
  24 + }
  25 +
  26 + default int deleteByInId(Long inId) {
  27 + return delete(ErpStockInItemDO::getInId, inId);
  28 + }
  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/dal/mysql/stock/ErpStockInMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.dal.mysql.stock;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  5 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  6 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInPageReqVO;
  7 +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO;
  8 +import org.apache.ibatis.annotations.Mapper;
  9 +
  10 +/**
  11 + * ERP 其它入库单 Mapper
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@Mapper
  16 +public interface ErpStockInMapper extends BaseMapperX<ErpStockInDO> {
  17 +
  18 + default PageResult<ErpStockInDO> selectPage(ErpStockInPageReqVO reqVO) {
  19 + return selectPage(reqVO, new LambdaQueryWrapperX<ErpStockInDO>()
  20 + .eqIfPresent(ErpStockInDO::getNo, reqVO.getNo())
  21 + .eqIfPresent(ErpStockInDO::getSupplierId, reqVO.getSupplierId())
  22 + .betweenIfPresent(ErpStockInDO::getInTime, reqVO.getInTime())
  23 + .eqIfPresent(ErpStockInDO::getStatus, reqVO.getStatus())
  24 + .likeIfPresent(ErpStockInDO::getRemark, reqVO.getRemark())
  25 + .eqIfPresent(ErpStockInDO::getCreator, reqVO.getCreator())
  26 + .orderByDesc(ErpStockInDO::getId));
  27 + }
  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/dal/mysql/stock/ErpStockMapper.java
@@ -22,4 +22,9 @@ public interface ErpStockMapper extends BaseMapperX&lt;ErpStockDO&gt; { @@ -22,4 +22,9 @@ public interface ErpStockMapper extends BaseMapperX&lt;ErpStockDO&gt; {
22 .orderByDesc(ErpStockDO::getId)); 22 .orderByDesc(ErpStockDO::getId));
23 } 23 }
24 24
  25 + default ErpStockDO selectByProductIdAndWarehouseId(Long productId, Long warehouseId) {
  26 + return selectOne(ErpStockDO::getProductId, productId,
  27 + ErpStockDO::getWarehouseId, warehouseId);
  28 + }
  29 +
25 } 30 }
26 \ 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/dal/mysql/stock/ErpStockRecordMapper.java
@@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.erp.dal.mysql.stock; @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.erp.dal.mysql.stock;
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; 4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; 5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
6 -import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stockrecord.ErpStockRecordPageReqVO; 6 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record.ErpStockRecordPageReqVO;
7 import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO; 7 import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO;
8 import org.apache.ibatis.annotations.Mapper; 8 import org.apache.ibatis.annotations.Mapper;
9 9
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/product/ErpProductService.java
@@ -43,6 +43,14 @@ public interface ErpProductService { @@ -43,6 +43,14 @@ public interface ErpProductService {
43 void deleteProduct(Long id); 43 void deleteProduct(Long id);
44 44
45 /** 45 /**
  46 + * 校验产品们的有效性
  47 + *
  48 + * @param ids 编号数组
  49 + * @return 产品列表
  50 + */
  51 + List<ErpProductDO> validProductList(Collection<Long> ids);
  52 +
  53 + /**
46 * 获得产品 54 * 获得产品
47 * 55 *
48 * @param id 编号 56 * @param id 编号
@@ -51,12 +59,12 @@ public interface ErpProductService { @@ -51,12 +59,12 @@ public interface ErpProductService {
51 ErpProductDO getProduct(Long id); 59 ErpProductDO getProduct(Long id);
52 60
53 /** 61 /**
54 - * 获得指定状态的产品列表 62 + * 获得指定状态的产品 VO 列表
55 * 63 *
56 * @param status 状态 64 * @param status 状态
57 - * @return 产品列表 65 + * @return 产品 VO 列表
58 */ 66 */
59 - List<ErpProductDO> getProductListByStatus(Integer status); 67 + List<ErpProductRespVO> getProductVOListByStatus(Integer status);
60 68
61 /** 69 /**
62 * 获得产品 VO 列表 70 * 获得产品 VO 列表
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/product/ErpProductServiceImpl.java
1 package cn.iocoder.yudao.module.erp.service.product; 1 package cn.iocoder.yudao.module.erp.service.product;
2 2
3 import cn.hutool.core.collection.CollUtil; 3 import cn.hutool.core.collection.CollUtil;
  4 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.framework.common.util.collection.MapUtils; 6 import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
6 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 7 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@@ -15,14 +16,11 @@ import jakarta.annotation.Resource; @@ -15,14 +16,11 @@ import jakarta.annotation.Resource;
15 import org.springframework.stereotype.Service; 16 import org.springframework.stereotype.Service;
16 import org.springframework.validation.annotation.Validated; 17 import org.springframework.validation.annotation.Validated;
17 18
18 -import java.util.Collection;  
19 -import java.util.Collections;  
20 -import java.util.List;  
21 -import java.util.Map; 19 +import java.util.*;
22 20
23 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 21 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
24 -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;  
25 -import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.PRODUCT_NOT_EXISTS; 22 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
  23 +import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
26 24
27 /** 25 /**
28 * ERP 产品 Service 实现类 26 * ERP 产品 Service 实现类
@@ -67,6 +65,25 @@ public class ErpProductServiceImpl implements ErpProductService { @@ -67,6 +65,25 @@ public class ErpProductServiceImpl implements ErpProductService {
67 productMapper.deleteById(id); 65 productMapper.deleteById(id);
68 } 66 }
69 67
  68 + @Override
  69 + public List<ErpProductDO> validProductList(Collection<Long> ids) {
  70 + if (CollUtil.isEmpty(ids)) {
  71 + return Collections.emptyList();
  72 + }
  73 + List<ErpProductDO> list = productMapper.selectBatchIds(ids);
  74 + Map<Long, ErpProductDO> productMap = convertMap(list, ErpProductDO::getId);
  75 + for (Long id : ids) {
  76 + ErpProductDO product = productMap.get(id);
  77 + if (productMap.get(id) == null) {
  78 + throw exception(PRODUCT_NOT_EXISTS);
  79 + }
  80 + if (CommonStatusEnum.isDisable(product.getStatus())) {
  81 + throw exception(PRODUCT_NOT_ENABLE, product.getName());
  82 + }
  83 + }
  84 + return list;
  85 + }
  86 +
70 private void validateProductExists(Long id) { 87 private void validateProductExists(Long id) {
71 if (productMapper.selectById(id) == null) { 88 if (productMapper.selectById(id) == null) {
72 throw exception(PRODUCT_NOT_EXISTS); 89 throw exception(PRODUCT_NOT_EXISTS);
@@ -79,8 +96,9 @@ public class ErpProductServiceImpl implements ErpProductService { @@ -79,8 +96,9 @@ public class ErpProductServiceImpl implements ErpProductService {
79 } 96 }
80 97
81 @Override 98 @Override
82 - public List<ErpProductDO> getProductListByStatus(Integer status) {  
83 - return productMapper.selectListByStatus(status); 99 + public List<ErpProductRespVO> getProductVOListByStatus(Integer status) {
  100 + List<ErpProductDO> list = productMapper.selectListByStatus(status);
  101 + return buildProductVOList(list);
84 } 102 }
85 103
86 @Override 104 @Override
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockInService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.service.stock;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInPageReqVO;
  5 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSaveReqVO;
  6 +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO;
  7 +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO;
  8 +import jakarta.validation.Valid;
  9 +
  10 +import java.util.Collection;
  11 +import java.util.List;
  12 +
  13 +/**
  14 + * ERP 其它入库单 Service 接口
  15 + *
  16 + * @author 芋道源码
  17 + */
  18 +public interface ErpStockInService {
  19 +
  20 + /**
  21 + * 创建其它入库单
  22 + *
  23 + * @param createReqVO 创建信息
  24 + * @return 编号
  25 + */
  26 + Long createStockIn(@Valid ErpStockInSaveReqVO createReqVO);
  27 +
  28 + /**
  29 + * 更新其它入库单
  30 + *
  31 + * @param updateReqVO 更新信息
  32 + */
  33 + void updateStockIn(@Valid ErpStockInSaveReqVO updateReqVO);
  34 +
  35 + /**
  36 + * 删除其它入库单
  37 + *
  38 + * @param id 编号
  39 + */
  40 + void deleteStockIn(Long id);
  41 +
  42 + /**
  43 + * 获得其它入库单
  44 + *
  45 + * @param id 编号
  46 + * @return 其它入库单
  47 + */
  48 + ErpStockInDO getStockIn(Long id);
  49 +
  50 + /**
  51 + * 获得其它入库单分页
  52 + *
  53 + * @param pageReqVO 分页查询
  54 + * @return 其它入库单分页
  55 + */
  56 + PageResult<ErpStockInDO> getStockInPage(ErpStockInPageReqVO pageReqVO);
  57 +
  58 + // ==================== 入库项 ====================
  59 +
  60 + /**
  61 + * 获得其它入库单项列表
  62 + *
  63 + * @param inId 入库编号
  64 + * @return 其它入库单项列表
  65 + */
  66 + List<ErpStockInItemDO> getStockInItemListByInId(Long inId);
  67 +
  68 + /**
  69 + * 获得其它入库单项 List
  70 + *
  71 + * @param inIds 入库编号数组
  72 + * @return 其它入库单项 List
  73 + */
  74 + List<ErpStockInItemDO> getStockInItemListByInIds(Collection<Long> inIds);
  75 +
  76 +}
0 \ No newline at end of file 77 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockInServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.service.stock;
  2 +
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  5 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  6 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInPageReqVO;
  7 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSaveReqVO;
  8 +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
  9 +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO;
  10 +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO;
  11 +import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInItemMapper;
  12 +import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInMapper;
  13 +import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus;
  14 +import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
  15 +import jakarta.annotation.Resource;
  16 +import org.springframework.stereotype.Service;
  17 +import org.springframework.transaction.annotation.Transactional;
  18 +import org.springframework.validation.annotation.Validated;
  19 +
  20 +import java.math.BigDecimal;
  21 +import java.util.Collection;
  22 +import java.util.Collections;
  23 +import java.util.List;
  24 +import java.util.Map;
  25 +
  26 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  27 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
  28 +import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.STOCK_IN_NOT_EXISTS;
  29 +
  30 +
  31 +/**
  32 + * ERP 其它入库单 Service 实现类
  33 + *
  34 + * @author 芋道源码
  35 + */
  36 +@Service
  37 +@Validated
  38 +public class ErpStockInServiceImpl implements ErpStockInService {
  39 +
  40 + @Resource
  41 + private ErpStockInMapper stockInMapper;
  42 + @Resource
  43 + private ErpStockInItemMapper stockInItemMapper;
  44 +
  45 + @Resource
  46 + private ErpProductService productService;
  47 + @Resource
  48 + private ErpWarehouseService warehouseService;
  49 +
  50 + @Override
  51 + @Transactional(rollbackFor = Exception.class)
  52 + public Long createStockIn(ErpStockInSaveReqVO createReqVO) {
  53 + // 1.1 校验入库项的有效性
  54 + List<ErpStockInItemDO> stockInItems = validateStockInItems(createReqVO.getItems());
  55 + // 1.2 TODO 芋艿:校验供应商
  56 +
  57 + // 2.1 插入入库单
  58 + ErpStockInDO stockIn = BeanUtils.toBean(createReqVO, ErpStockInDO.class, in -> in
  59 + .setStatus(ErpAuditStatus.PROCESS.getStatus())
  60 + .setTotalCount(getSumValue(stockInItems, ErpStockInItemDO::getCount, BigDecimal::add))
  61 + .setTotalPrice(getSumValue(stockInItems, ErpStockInItemDO::getTotalPrice, BigDecimal::add)));
  62 + stockInMapper.insert(stockIn);
  63 + // 2. 插入子表
  64 + stockInItems.forEach(o -> o.setInId(stockIn.getId()));
  65 + stockInItemMapper.insertBatch(stockInItems);
  66 + return stockIn.getId();
  67 + }
  68 +
  69 + @Override
  70 + @Transactional(rollbackFor = Exception.class)
  71 + public void updateStockIn(ErpStockInSaveReqVO updateReqVO) {
  72 + // 1.1 校验存在
  73 + validateStockInExists(updateReqVO.getId());
  74 + // 1.2 TODO 芋艿:校验供应商
  75 + // 1.3 校验入库项的有效性
  76 + List<ErpStockInItemDO> stockInItems = validateStockInItems(updateReqVO.getItems());
  77 +
  78 + // 2.1 更新入库单
  79 + ErpStockInDO updateObj = BeanUtils.toBean(updateReqVO, ErpStockInDO.class, in -> in
  80 + .setTotalCount(getSumValue(stockInItems, ErpStockInItemDO::getCount, BigDecimal::add))
  81 + .setTotalPrice(getSumValue(stockInItems, ErpStockInItemDO::getTotalPrice, BigDecimal::add)));
  82 + stockInMapper.updateById(updateObj);
  83 + // 2.2 更新入库单项
  84 + updateStockInItemList(updateReqVO.getId(), stockInItems);
  85 + }
  86 +
  87 + private List<ErpStockInItemDO> validateStockInItems(List<ErpStockInSaveReqVO.Item> list) {
  88 + // 1.1 校验产品存在
  89 + List<ErpProductDO> productList = productService.validProductList(convertSet(list, ErpStockInSaveReqVO.Item::getProductId));
  90 + Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId);
  91 + // 1.2 校验仓库存在
  92 + warehouseService.validWarehouseList(convertSet(list, ErpStockInSaveReqVO.Item::getWarehouseId));
  93 + // 2. 转化为 ErpStockInItemDO 列表
  94 + return convertList(list, o -> BeanUtils.toBean(o, ErpStockInItemDO.class, item -> item
  95 + .setProductUnitId(productMap.get(item.getProductId()).getUnitId())
  96 + .setTotalPrice(item.getProductPrice().multiply(item.getCount()))));
  97 + }
  98 +
  99 + private void updateStockInItemList(Long id, List<ErpStockInItemDO> newList) {
  100 + // 第一步,对比新老数据,获得添加、修改、删除的列表
  101 + List<ErpStockInItemDO> oldList = stockInItemMapper.selectListByInId(id);
  102 + List<List<ErpStockInItemDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录
  103 + (oldVal, newVal) -> oldVal.getId().equals(newVal.getId()));
  104 +
  105 + // 第二步,批量添加、修改、删除
  106 + if (CollUtil.isNotEmpty(diffList.get(0))) {
  107 + diffList.get(0).forEach(o -> o.setInId(id));
  108 + stockInItemMapper.insertBatch(diffList.get(0));
  109 + }
  110 + if (CollUtil.isNotEmpty(diffList.get(1))) {
  111 + stockInItemMapper.updateBatch(diffList.get(1));
  112 + }
  113 + if (CollUtil.isNotEmpty(diffList.get(2))) {
  114 + stockInItemMapper.deleteBatchIds(convertList(diffList.get(2), ErpStockInItemDO::getId));
  115 + }
  116 + }
  117 +
  118 + @Override
  119 + @Transactional(rollbackFor = Exception.class)
  120 + public void deleteStockIn(Long id) {
  121 + // 1. 校验存在
  122 + validateStockInExists(id);
  123 + // TODO 芋艿:校验一下;
  124 +
  125 + // 2.1 删除
  126 + stockInMapper.deleteById(id);
  127 + // 2.2 删除子表
  128 + stockInItemMapper.deleteByInId(id);
  129 + }
  130 +
  131 + private void validateStockInExists(Long id) {
  132 + if (stockInMapper.selectById(id) == null) {
  133 + throw exception(STOCK_IN_NOT_EXISTS);
  134 + }
  135 + }
  136 +
  137 + @Override
  138 + public ErpStockInDO getStockIn(Long id) {
  139 + return stockInMapper.selectById(id);
  140 + }
  141 +
  142 + @Override
  143 + public PageResult<ErpStockInDO> getStockInPage(ErpStockInPageReqVO pageReqVO) {
  144 + return stockInMapper.selectPage(pageReqVO);
  145 + }
  146 +
  147 + // ==================== 子表(ERP 其它入库单项) ====================
  148 +
  149 + @Override
  150 + public List<ErpStockInItemDO> getStockInItemListByInId(Long inId) {
  151 + return stockInItemMapper.selectListByInId(inId);
  152 + }
  153 +
  154 + @Override
  155 + public List<ErpStockInItemDO> getStockInItemListByInIds(Collection<Long> inIds) {
  156 + if (CollUtil.isEmpty(inIds)) {
  157 + return Collections.emptyList();
  158 + }
  159 + return stockInItemMapper.selectListByInIds(inIds);
  160 + }
  161 +
  162 +}
0 \ No newline at end of file 163 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockRecordService.java
1 package cn.iocoder.yudao.module.erp.service.stock; 1 package cn.iocoder.yudao.module.erp.service.stock;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 -import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stockrecord.ErpStockRecordPageReqVO; 4 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record.ErpStockRecordPageReqVO;
5 import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO; 5 import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO;
6 6
7 /** 7 /**
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockRecordServiceImpl.java
1 package cn.iocoder.yudao.module.erp.service.stock; 1 package cn.iocoder.yudao.module.erp.service.stock;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 -import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stockrecord.ErpStockRecordPageReqVO; 4 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record.ErpStockRecordPageReqVO;
5 import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO; 5 import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO;
6 import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockRecordMapper; 6 import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockRecordMapper;
7 import jakarta.annotation.Resource; 7 import jakarta.annotation.Resource;
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockService.java
@@ -20,6 +20,15 @@ public interface ErpStockService { @@ -20,6 +20,15 @@ public interface ErpStockService {
20 ErpStockDO getStock(Long id); 20 ErpStockDO getStock(Long id);
21 21
22 /** 22 /**
  23 + * 基于产品 + 仓库,获得产品库存
  24 + *
  25 + * @param productId 产品编号
  26 + * @param warehouseId 仓库编号
  27 + * @return 产品库存
  28 + */
  29 + ErpStockDO getStock(Long productId, Long warehouseId);
  30 +
  31 + /**
23 * 获得产品库存分页 32 * 获得产品库存分页
24 * 33 *
25 * @param pageReqVO 分页查询 34 * @param pageReqVO 分页查询
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockServiceImpl.java
@@ -26,6 +26,11 @@ public class ErpStockServiceImpl implements ErpStockService { @@ -26,6 +26,11 @@ public class ErpStockServiceImpl implements ErpStockService {
26 } 26 }
27 27
28 @Override 28 @Override
  29 + public ErpStockDO getStock(Long productId, Long warehouseId) {
  30 + return stockMapper.selectByProductIdAndWarehouseId(productId, warehouseId);
  31 + }
  32 +
  33 + @Override
29 public PageResult<ErpStockDO> getStockPage(ErpStockPageReqVO pageReqVO) { 34 public PageResult<ErpStockDO> getStockPage(ErpStockPageReqVO pageReqVO) {
30 return stockMapper.selectPage(pageReqVO); 35 return stockMapper.selectPage(pageReqVO);
31 } 36 }
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpWarehouseService.java
@@ -58,6 +58,14 @@ public interface ErpWarehouseService { @@ -58,6 +58,14 @@ public interface ErpWarehouseService {
58 ErpWarehouseDO getWarehouse(Long id); 58 ErpWarehouseDO getWarehouse(Long id);
59 59
60 /** 60 /**
  61 + * 校验仓库列表的有效性
  62 + *
  63 + * @param ids 编号数组
  64 + * @return 仓库列表
  65 + */
  66 + List<ErpWarehouseDO> validWarehouseList(Collection<Long> ids);
  67 +
  68 + /**
61 * 获得指定状态的仓库列表 69 * 获得指定状态的仓库列表
62 * 70 *
63 * @param status 状态 71 * @param status 状态
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpWarehouseServiceImpl.java
1 package cn.iocoder.yudao.module.erp.service.stock; 1 package cn.iocoder.yudao.module.erp.service.stock;
2 2
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 6 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
5 import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.ErpWarehouseSaveReqVO; 7 import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.ErpWarehouseSaveReqVO;
6 import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehousePageReqVO; 8 import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehousePageReqVO;
  9 +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
7 import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO; 10 import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
8 import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpWarehouseMapper; 11 import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpWarehouseMapper;
9 import jakarta.annotation.Resource; 12 import jakarta.annotation.Resource;
@@ -12,10 +15,13 @@ import org.springframework.transaction.annotation.Transactional; @@ -12,10 +15,13 @@ import org.springframework.transaction.annotation.Transactional;
12 import org.springframework.validation.annotation.Validated; 15 import org.springframework.validation.annotation.Validated;
13 16
14 import java.util.Collection; 17 import java.util.Collection;
  18 +import java.util.Collections;
15 import java.util.List; 19 import java.util.List;
  20 +import java.util.Map;
16 21
17 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 22 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
18 -import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.WAREHOUSE_NOT_EXISTS; 23 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
  24 +import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
19 25
20 /** 26 /**
21 * ERP 仓库 Service 实现类 27 * ERP 仓库 Service 实现类
@@ -84,6 +90,25 @@ public class ErpWarehouseServiceImpl implements ErpWarehouseService { @@ -84,6 +90,25 @@ public class ErpWarehouseServiceImpl implements ErpWarehouseService {
84 } 90 }
85 91
86 @Override 92 @Override
  93 + public List<ErpWarehouseDO> validWarehouseList(Collection<Long> ids) {
  94 + if (CollUtil.isEmpty(ids)) {
  95 + return Collections.emptyList();
  96 + }
  97 + List<ErpWarehouseDO> list = warehouseMapper.selectBatchIds(ids);
  98 + Map<Long, ErpWarehouseDO> warehouseMap = convertMap(list, ErpWarehouseDO::getId);
  99 + for (Long id : ids) {
  100 + ErpWarehouseDO warehouse = warehouseMap.get(id);
  101 + if (warehouseMap.get(id) == null) {
  102 + throw exception(WAREHOUSE_NOT_EXISTS);
  103 + }
  104 + if (CommonStatusEnum.isDisable(warehouse.getStatus())) {
  105 + throw exception(WAREHOUSE_NOT_ENABLE, warehouse.getName());
  106 + }
  107 + }
  108 + return list;
  109 + }
  110 +
  111 + @Override
87 public List<ErpWarehouseDO> getWarehouseListByStatus(Integer status) { 112 public List<ErpWarehouseDO> getWarehouseListByStatus(Integer status) {
88 return warehouseMapper.selectListByStatus(status); 113 return warehouseMapper.selectListByStatus(status);
89 } 114 }