Commit 5fd23cacc7da16488aebd091d34967b8597e2fe4

Authored by YunaiV
1 parent 30de2176

✨ ERP:增加 ERP 销售订单的实现 50%(详情)

新年快乐~
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/sale/vo/order/ErpSaleOrderPageReqVO.java
... ... @@ -30,6 +30,19 @@ public class ErpSaleOrderPageReqVO extends PageParam {
30 30 */
31 31 public static final Integer IN_STATUS_ALL = 2;
32 32  
  33 + /**
  34 + * 退货状态 - 无
  35 + */
  36 + public static final Integer RETURN_STATUS_NONE = 0;
  37 + /**
  38 + * 退货状态 - 部分
  39 + */
  40 + public static final Integer RETURN_STATUS_PART = 1;
  41 + /**
  42 + * 退货状态 - 全部
  43 + */
  44 + public static final Integer RETURN_STATUS_ALL = 2;
  45 +
33 46 @Schema(description = "销售单编号", example = "XS001")
34 47 private String no;
35 48  
... ... @@ -55,4 +68,7 @@ public class ErpSaleOrderPageReqVO extends PageParam {
55 68 @Schema(description = "入库状态", example = "2")
56 69 private Integer inStatus;
57 70  
  71 + @Schema(description = "退货状态", example = "2")
  72 + private Integer returnStatus;
  73 +
58 74 }
59 75 \ No newline at end of file
... ...
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/sale/vo/order/ErpSaleOrderRespVO.java
... ... @@ -23,22 +23,33 @@ public class ErpSaleOrderRespVO {
23 23 @ExcelProperty("销售单编号")
24 24 private String no;
25 25  
  26 + @Schema(description = "销售状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  27 + @ExcelProperty("销售状态")
  28 + private Integer status;
  29 +
26 30 @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1724")
27 31 private Long customerId;
28 32 @Schema(description = "客户名称", example = "芋道")
29 33 @ExcelProperty("客户名称")
30 34 private String customerName;
31 35  
32   - @Schema(description = "下单时间", requiredMode = Schema.RequiredMode.REQUIRED)
33   - @ExcelProperty("下单时间")
34   - private LocalDateTime orderTime;
  36 + @Schema(description = "结算账户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "311.89")
  37 + @ExcelProperty("结算账户编号")
  38 + private Long accountId;
35 39  
36 40 @Schema(description = "销售员编号", example = "1888")
37 41 private Long saleUserId;
38 42  
39   - @Schema(description = "结算账户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "311.89")
40   - @ExcelProperty("结算账户编号")
41   - private Long accountId;
  43 + @Schema(description = "下单时间", requiredMode = Schema.RequiredMode.REQUIRED)
  44 + @ExcelProperty("下单时间")
  45 + private LocalDateTime orderTime;
  46 +
  47 + @Schema(description = "合计数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15663")
  48 + @ExcelProperty("合计数量")
  49 + private BigDecimal totalCount;
  50 + @Schema(description = "最终合计价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "24906")
  51 + @ExcelProperty("最终合计价格")
  52 + private BigDecimal totalPrice;
42 53  
43 54 @Schema(description = "合计产品价格,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127")
44 55 private BigDecimal totalProductPrice;
... ... @@ -56,10 +67,6 @@ public class ErpSaleOrderRespVO {
56 67 @NotNull(message = "定金金额,单位:元不能为空")
57 68 private BigDecimal depositPrice;
58 69  
59   - @Schema(description = "销售状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
60   - @ExcelProperty("销售状态")
61   - private Integer status;
62   -
63 70 @Schema(description = "附件地址", example = "https://www.iocoder.cn")
64 71 @ExcelProperty("附件地址")
65 72 private String fileUrl;
... ... @@ -84,6 +91,16 @@ public class ErpSaleOrderRespVO {
84 91 @ExcelProperty("产品信息")
85 92 private String productNames;
86 93  
  94 + // ========== 销售入库 ==========
  95 +
  96 + @Schema(description = "销售入库数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
  97 + private BigDecimal inCount;
  98 +
  99 + // ========== 销售退货(出库)) ==========
  100 +
  101 + @Schema(description = "销售退货数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
  102 + private BigDecimal returnCount;
  103 +
87 104 @Data
88 105 public static class Item {
89 106  
... ... @@ -106,6 +123,9 @@ public class ErpSaleOrderRespVO {
106 123 @Schema(description = "税率,百分比", example = "99.88")
107 124 private BigDecimal taxPercent;
108 125  
  126 + @Schema(description = "税额,单位:元", example = "100.00")
  127 + private BigDecimal taxPrice;
  128 +
109 129 @Schema(description = "备注", example = "随便")
110 130 private String remark;
111 131  
... ...
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpStockController.java
... ... @@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.RequestParam;
31 31 import org.springframework.web.bind.annotation.RestController;
32 32  
33 33 import java.io.IOException;
  34 +import java.math.BigDecimal;
34 35 import java.util.List;
35 36 import java.util.Map;
36 37  
... ... @@ -66,6 +67,13 @@ public class ErpStockController {
66 67 return success(BeanUtils.toBean(stock, ErpStockRespVO.class));
67 68 }
68 69  
  70 + @GetMapping("/get-count")
  71 + @Operation(summary = "获得产品库存数量")
  72 + @Parameter(name = "productId", description = "产品编号", example = "10")
  73 + public CommonResult<BigDecimal> getStockCount(@RequestParam("productId") Long productId) {
  74 + return success(stockService.getStockCount(productId));
  75 + }
  76 +
69 77 @GetMapping("/page")
70 78 @Operation(summary = "获得产品库存分页")
71 79 @PreAuthorize("@ss.hasPermission('erp:stock:query')")
... ...
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/sale/ErpSaleOrderMapper.java
... ... @@ -6,10 +6,12 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
6 6 import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
7 7 import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.order.ErpSaleOrderPageReqVO;
8 8 import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleOrderDO;
9   -import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO;
  9 +import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleOrderItemDO;
10 10 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
11 11 import org.apache.ibatis.annotations.Mapper;
12 12  
  13 +import java.util.Objects;
  14 +
13 15 /**
14 16 * ERP 销售订单 Mapper
15 17 *
... ... @@ -27,9 +29,25 @@ public interface ErpSaleOrderMapper extends BaseMapperX&lt;ErpSaleOrderDO&gt; {
27 29 .likeIfPresent(ErpSaleOrderDO::getRemark, reqVO.getRemark())
28 30 .eqIfPresent(ErpSaleOrderDO::getCreator, reqVO.getCreator())
29 31 .orderByDesc(ErpSaleOrderDO::getId);
  32 + // 入库状态。为什么需要 t. 的原因,是因为联表查询时,需要指定表名,不然会报 in_count 错误
  33 + if (Objects.equals(reqVO.getInStatus(), ErpSaleOrderPageReqVO.IN_STATUS_NONE)) {
  34 + query.eq(ErpSaleOrderDO::getInCount, 0);
  35 + } else if (Objects.equals(reqVO.getInStatus(), ErpSaleOrderPageReqVO.IN_STATUS_PART)) {
  36 + query.gt(ErpSaleOrderDO::getInCount, 0).apply("t.in_count < t.total_count");
  37 + } else if (Objects.equals(reqVO.getInStatus(), ErpSaleOrderPageReqVO.IN_STATUS_ALL)) {
  38 + query.apply("t.in_count = t.total_count");
  39 + }
  40 + // 退货状态
  41 + if (Objects.equals(reqVO.getReturnStatus(), ErpSaleOrderPageReqVO.RETURN_STATUS_NONE)) {
  42 + query.eq(ErpSaleOrderDO::getReturnCount, 0);
  43 + } else if (Objects.equals(reqVO.getReturnStatus(), ErpSaleOrderPageReqVO.RETURN_STATUS_PART)) {
  44 + query.gt(ErpSaleOrderDO::getReturnCount, 0).apply("t.return_count < t.total_count");
  45 + } else if (Objects.equals(reqVO.getReturnStatus(), ErpSaleOrderPageReqVO.RETURN_STATUS_ALL)) {
  46 + query.apply("t.return_count = t.total_count");
  47 + }
30 48 if (reqVO.getProductId() != null) {
31   - query.leftJoin(ErpStockOutItemDO.class, ErpStockOutItemDO::getOutId, ErpSaleOrderDO::getId)
32   - .eq(reqVO.getProductId() != null, ErpStockOutItemDO::getProductId, reqVO.getProductId())
  49 + query.leftJoin(ErpSaleOrderItemDO.class, ErpSaleOrderItemDO::getOrderId, ErpSaleOrderDO::getId)
  50 + .eq(reqVO.getProductId() != null, ErpSaleOrderItemDO::getProductId, reqVO.getProductId())
33 51 .groupBy(ErpSaleOrderDO::getId); // 避免 1 对多查询,产生相同的 1
34 52 }
35 53 return selectJoinPage(reqVO, ErpSaleOrderDO.class, query);
... ...
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/product/ErpProductServiceImpl.java
... ... @@ -105,6 +105,9 @@ public class ErpProductServiceImpl implements ErpProductService {
105 105  
106 106 @Override
107 107 public List<ErpProductRespVO> getProductVOList(Collection<Long> ids) {
  108 + if (CollUtil.isEmpty(ids)) {
  109 + return Collections.emptyList();
  110 + }
108 111 List<ErpProductDO> list = productMapper.selectBatchIds(ids);
109 112 return buildProductVOList(list);
110 113 }
... ...
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockService.java
... ... @@ -33,6 +33,8 @@ public interface ErpStockService {
33 33 /**
34 34 * 获得产品库存数量
35 35 *
  36 + * 如果不存在库存记录,则返回 0
  37 + *
36 38 * @param productId 产品编号
37 39 * @return 产品库存数量
38 40 */
... ...
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockServiceImpl.java
... ... @@ -51,7 +51,8 @@ public class ErpStockServiceImpl implements ErpStockService {
51 51  
52 52 @Override
53 53 public BigDecimal getStockCount(Long productId) {
54   - return stockMapper.selectSumByProductId(productId);
  54 + BigDecimal count = stockMapper.selectSumByProductId(productId);
  55 + return count != null ? count : BigDecimal.ZERO;
55 56 }
56 57  
57 58 @Override
... ...