Commit 926286fe08799aea7a78c08c0fbb6220897404df
1 parent
dbc367ad
✨ ERP:初始化销售退货逻辑 50%
Showing
19 changed files
with
1263 additions
and
39 deletions
yudao-module-erp/yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/enums/ErrorCodeConstants.java
| ... | ... | @@ -26,7 +26,9 @@ public interface ErrorCodeConstants { |
| 26 | 26 | ErrorCode SALE_ORDER_UPDATE_FAIL_APPROVE = new ErrorCode(1_020_201_005, "销售订单({})已审核,无法修改"); |
| 27 | 27 | ErrorCode SALE_ORDER_NOT_APPROVE = new ErrorCode(1_020_201_006, "销售订单未审核,无法操作"); |
| 28 | 28 | ErrorCode SALE_ORDER_ITEM_OUT_FAIL_PRODUCT_EXCEED = new ErrorCode(1_020_201_007, "销售订单项({})超过最大允许出库数量({})"); |
| 29 | - ErrorCode SALE_ORDER_PROCESS_FAIL_EXISTS_OUT = new ErrorCode(1_020_201_002, "反审核失败,已存在对应的销售出库单"); | |
| 29 | + ErrorCode SALE_ORDER_PROCESS_FAIL_EXISTS_OUT = new ErrorCode(1_020_201_008, "反审核失败,已存在对应的销售出库单"); | |
| 30 | + ErrorCode SALE_ORDER_ITEM_RETURN_FAIL_OUT_EXCEED = new ErrorCode(1_020_201_009, "销售订单项({})超过最大允许退货数量({})"); | |
| 31 | + ErrorCode SALE_ORDER_PROCESS_FAIL_EXISTS_RETURN = new ErrorCode(1_020_201_010, "反审核失败,已存在对应的销售退货单"); | |
| 30 | 32 | |
| 31 | 33 | // ========== ERP 销售出库(1-030-202-000) ========== |
| 32 | 34 | ErrorCode SALE_OUT_NOT_EXISTS = new ErrorCode(1_020_202_000, "销售出库单不存在"); |
| ... | ... | @@ -36,6 +38,14 @@ public interface ErrorCodeConstants { |
| 36 | 38 | ErrorCode SALE_OUT_NO_EXISTS = new ErrorCode(1_020_202_004, "生成出库单失败,请重新提交"); |
| 37 | 39 | ErrorCode SALE_OUT_UPDATE_FAIL_APPROVE = new ErrorCode(1_020_202_005, "销售出库单({})已审核,无法修改"); |
| 38 | 40 | |
| 41 | + // ========== ERP 销售退货(1-030-203-000) ========== | |
| 42 | + ErrorCode SALE_RETURN_NOT_EXISTS = new ErrorCode(1_020_203_000, "销售退货单不存在"); | |
| 43 | + ErrorCode SALE_RETURN_DELETE_FAIL_APPROVE = new ErrorCode(1_020_203_001, "销售退货单({})已审核,无法删除"); | |
| 44 | + ErrorCode SALE_RETURN_PROCESS_FAIL = new ErrorCode(1_020_203_002, "反审核失败,只有已审核的退货单才能反审核"); | |
| 45 | + ErrorCode SALE_RETURN_APPROVE_FAIL = new ErrorCode(1_020_203_003, "审核失败,只有未审核的退货单才能审核"); | |
| 46 | + ErrorCode SALE_RETURN_NO_EXISTS = new ErrorCode(1_020_203_004, "生成退货单失败,请重新提交"); | |
| 47 | + ErrorCode SALE_RETURN_UPDATE_FAIL_APPROVE = new ErrorCode(1_020_203_005, "销售退货单({})已审核,无法修改"); | |
| 48 | + | |
| 39 | 49 | // ========== ERP 仓库 1-030-400-000 ========== |
| 40 | 50 | ErrorCode WAREHOUSE_NOT_EXISTS = new ErrorCode(1_030_400_000, "仓库不存在"); |
| 41 | 51 | ErrorCode WAREHOUSE_NOT_ENABLE = new ErrorCode(1_030_400_001, "仓库({})未启用"); | ... | ... |
yudao-module-erp/yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/enums/stock/ErpStockRecordBizTypeEnum.java
| ... | ... | @@ -33,6 +33,9 @@ public enum ErpStockRecordBizTypeEnum implements IntArrayValuable { |
| 33 | 33 | |
| 34 | 34 | SALE_OUT(50, "销售出库"), |
| 35 | 35 | SALE_OUT_CANCEL(51, "销售出库(作废)"), |
| 36 | + | |
| 37 | + SALE_RETURN(60, "销售退货入库"), | |
| 38 | + SALE_RETURN_CANCEL(61, "销售退货入库(作废)"), | |
| 36 | 39 | ; |
| 37 | 40 | |
| 38 | 41 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpStockRecordBizTypeEnum::getType).toArray(); | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/sale/ErpSaleReturnController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.sale; | |
| 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.sale.vo.returns.ErpSaleReturnPageReqVO; | |
| 13 | +import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.returns.ErpSaleReturnRespVO; | |
| 14 | +import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.returns.ErpSaleReturnSaveReqVO; | |
| 15 | +import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpCustomerDO; | |
| 16 | +import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleReturnDO; | |
| 17 | +import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleReturnItemDO; | |
| 18 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO; | |
| 19 | +import cn.iocoder.yudao.module.erp.service.product.ErpProductService; | |
| 20 | +import cn.iocoder.yudao.module.erp.service.sale.ErpCustomerService; | |
| 21 | +import cn.iocoder.yudao.module.erp.service.sale.ErpSaleReturnService; | |
| 22 | +import cn.iocoder.yudao.module.erp.service.stock.ErpStockService; | |
| 23 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | |
| 24 | +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | |
| 25 | +import io.swagger.v3.oas.annotations.Operation; | |
| 26 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 27 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 28 | +import jakarta.annotation.Resource; | |
| 29 | +import jakarta.servlet.http.HttpServletResponse; | |
| 30 | +import jakarta.validation.Valid; | |
| 31 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 32 | +import org.springframework.validation.annotation.Validated; | |
| 33 | +import org.springframework.web.bind.annotation.*; | |
| 34 | + | |
| 35 | +import java.io.IOException; | |
| 36 | +import java.math.BigDecimal; | |
| 37 | +import java.util.List; | |
| 38 | +import java.util.Map; | |
| 39 | + | |
| 40 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 41 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap; | |
| 42 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | |
| 43 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | |
| 44 | + | |
| 45 | +@Tag(name = "管理后台 - ERP 销售退货") | |
| 46 | +@RestController | |
| 47 | +@RequestMapping("/erp/sale-return") | |
| 48 | +@Validated | |
| 49 | +public class ErpSaleReturnController { | |
| 50 | + | |
| 51 | + @Resource | |
| 52 | + private ErpSaleReturnService saleReturnService; | |
| 53 | + @Resource | |
| 54 | + private ErpStockService stockService; | |
| 55 | + @Resource | |
| 56 | + private ErpProductService productService; | |
| 57 | + @Resource | |
| 58 | + private ErpCustomerService customerService; | |
| 59 | + | |
| 60 | + @Resource | |
| 61 | + private AdminUserApi adminUserApi; | |
| 62 | + | |
| 63 | + @PostMapping("/create") | |
| 64 | + @Operation(summary = "创建销售退货") | |
| 65 | + @PreAuthorize("@ss.hasPermission('erp:stock-return:create')") | |
| 66 | + public CommonResult<Long> createSaleReturn(@Valid @RequestBody ErpSaleReturnSaveReqVO createReqVO) { | |
| 67 | + return success(saleReturnService.createSaleReturn(createReqVO)); | |
| 68 | + } | |
| 69 | + | |
| 70 | + @PutMapping("/update") | |
| 71 | + @Operation(summary = "更新销售退货") | |
| 72 | + @PreAuthorize("@ss.hasPermission('erp:stock-return:update')") | |
| 73 | + public CommonResult<Boolean> updateSaleReturn(@Valid @RequestBody ErpSaleReturnSaveReqVO updateReqVO) { | |
| 74 | + saleReturnService.updateSaleReturn(updateReqVO); | |
| 75 | + return success(true); | |
| 76 | + } | |
| 77 | + | |
| 78 | + @PutMapping("/update-status") | |
| 79 | + @Operation(summary = "更新销售退货的状态") | |
| 80 | + @PreAuthorize("@ss.hasPermission('erp:stock-return:update-status')") | |
| 81 | + public CommonResult<Boolean> updateSaleReturnStatus(@RequestParam("id") Long id, | |
| 82 | + @RequestParam("status") Integer status) { | |
| 83 | + saleReturnService.updateSaleReturnStatus(id, status); | |
| 84 | + return success(true); | |
| 85 | + } | |
| 86 | + | |
| 87 | + @DeleteMapping("/delete") | |
| 88 | + @Operation(summary = "删除销售退货") | |
| 89 | + @Parameter(name = "ids", description = "编号数组", required = true) | |
| 90 | + @PreAuthorize("@ss.hasPermission('erp:stock-return:delete')") | |
| 91 | + public CommonResult<Boolean> deleteSaleReturn(@RequestParam("ids") List<Long> ids) { | |
| 92 | + saleReturnService.deleteSaleReturn(ids); | |
| 93 | + return success(true); | |
| 94 | + } | |
| 95 | + | |
| 96 | + @GetMapping("/get") | |
| 97 | + @Operation(summary = "获得销售退货") | |
| 98 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 99 | + @PreAuthorize("@ss.hasPermission('erp:stock-return:query')") | |
| 100 | + public CommonResult<ErpSaleReturnRespVO> getSaleReturn(@RequestParam("id") Long id) { | |
| 101 | + ErpSaleReturnDO saleReturn = saleReturnService.getSaleReturn(id); | |
| 102 | + if (saleReturn == null) { | |
| 103 | + return success(null); | |
| 104 | + } | |
| 105 | + List<ErpSaleReturnItemDO> saleReturnItemList = saleReturnService.getSaleReturnItemListByReturnId(id); | |
| 106 | + Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap( | |
| 107 | + convertSet(saleReturnItemList, ErpSaleReturnItemDO::getProductId)); | |
| 108 | + return success(BeanUtils.toBean(saleReturn, ErpSaleReturnRespVO.class, saleReturnVO -> | |
| 109 | + saleReturnVO.setItems(BeanUtils.toBean(saleReturnItemList, ErpSaleReturnRespVO.Item.class, item -> { | |
| 110 | + ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId()); | |
| 111 | + item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO); | |
| 112 | + MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName()) | |
| 113 | + .setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName())); | |
| 114 | + })))); | |
| 115 | + } | |
| 116 | + | |
| 117 | + @GetMapping("/page") | |
| 118 | + @Operation(summary = "获得销售退货分页") | |
| 119 | + @PreAuthorize("@ss.hasPermission('erp:stock-return:query')") | |
| 120 | + public CommonResult<PageResult<ErpSaleReturnRespVO>> getSaleReturnPage(@Valid ErpSaleReturnPageReqVO pageReqVO) { | |
| 121 | + PageResult<ErpSaleReturnDO> pageResult = saleReturnService.getSaleReturnPage(pageReqVO); | |
| 122 | + return success(buildSaleReturnVOPageResult(pageResult)); | |
| 123 | + } | |
| 124 | + | |
| 125 | + @GetMapping("/export-excel") | |
| 126 | + @Operation(summary = "导出销售退货 Excel") | |
| 127 | + @PreAuthorize("@ss.hasPermission('erp:stock-return:export')") | |
| 128 | + @OperateLog(type = EXPORT) | |
| 129 | + public void exportSaleReturnExcel(@Valid ErpSaleReturnPageReqVO pageReqVO, | |
| 130 | + HttpServletResponse response) throws IOException { | |
| 131 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 132 | + List<ErpSaleReturnRespVO> list = buildSaleReturnVOPageResult(saleReturnService.getSaleReturnPage(pageReqVO)).getList(); | |
| 133 | + // 导出 Excel | |
| 134 | + ExcelUtils.write(response, "销售退货.xls", "数据", ErpSaleReturnRespVO.class, list); | |
| 135 | + } | |
| 136 | + | |
| 137 | + private PageResult<ErpSaleReturnRespVO> buildSaleReturnVOPageResult(PageResult<ErpSaleReturnDO> pageResult) { | |
| 138 | + if (CollUtil.isEmpty(pageResult.getList())) { | |
| 139 | + return PageResult.empty(pageResult.getTotal()); | |
| 140 | + } | |
| 141 | + // 1.1 退货项 | |
| 142 | + List<ErpSaleReturnItemDO> saleReturnItemList = saleReturnService.getSaleReturnItemListByReturnIds( | |
| 143 | + convertSet(pageResult.getList(), ErpSaleReturnDO::getId)); | |
| 144 | + Map<Long, List<ErpSaleReturnItemDO>> saleReturnItemMap = convertMultiMap(saleReturnItemList, ErpSaleReturnItemDO::getReturnId); | |
| 145 | + // 1.2 商品信息 | |
| 146 | + Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap( | |
| 147 | + convertSet(saleReturnItemList, ErpSaleReturnItemDO::getProductId)); | |
| 148 | + // 1.3 客户信息 | |
| 149 | + Map<Long, ErpCustomerDO> customerMap = customerService.getCustomerMap( | |
| 150 | + convertSet(pageResult.getList(), ErpSaleReturnDO::getCustomerId)); | |
| 151 | + // 1.4 管理员信息 | |
| 152 | + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap( | |
| 153 | + convertSet(pageResult.getList(), erpStockRecordDO -> Long.parseLong(erpStockRecordDO.getCreator()))); | |
| 154 | + // 2. 开始拼接 | |
| 155 | + return BeanUtils.toBean(pageResult, ErpSaleReturnRespVO.class, saleReturn -> { | |
| 156 | + saleReturn.setItems(BeanUtils.toBean(saleReturnItemMap.get(saleReturn.getId()), ErpSaleReturnRespVO.Item.class, | |
| 157 | + item -> MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName()) | |
| 158 | + .setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName())))); | |
| 159 | + saleReturn.setProductNames(CollUtil.join(saleReturn.getItems(), ",", ErpSaleReturnRespVO.Item::getProductName)); | |
| 160 | + MapUtils.findAndThen(customerMap, saleReturn.getCustomerId(), supplier -> saleReturn.setCustomerName(supplier.getName())); | |
| 161 | + MapUtils.findAndThen(userMap, Long.parseLong(saleReturn.getCreator()), user -> saleReturn.setCreatorName(user.getNickname())); | |
| 162 | + }); | |
| 163 | + } | |
| 164 | + | |
| 165 | +} | |
| 0 | 166 | \ 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/out/ErpSaleOutPageReqVO.java
| ... | ... | @@ -30,7 +30,7 @@ public class ErpSaleOutPageReqVO extends PageParam { |
| 30 | 30 | @Schema(description = "备注", example = "你猜") |
| 31 | 31 | private String remark; |
| 32 | 32 | |
| 33 | - @Schema(description = "销售状态", example = "2") | |
| 33 | + @Schema(description = "出库状态", example = "2") | |
| 34 | 34 | private Integer status; |
| 35 | 35 | |
| 36 | 36 | @Schema(description = "创建者") | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/sale/vo/out/ErpSaleOutRespVO.java
| ... | ... | @@ -10,7 +10,7 @@ import java.math.BigDecimal; |
| 10 | 10 | import java.time.LocalDateTime; |
| 11 | 11 | import java.util.List; |
| 12 | 12 | |
| 13 | -@Schema(description = "管理后台 - ERP 出库出库 Response VO") | |
| 13 | +@Schema(description = "管理后台 - ERP 销售出库 Response VO") | |
| 14 | 14 | @Data |
| 15 | 15 | @ExcelIgnoreUnannotated |
| 16 | 16 | public class ErpSaleOutRespVO { | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/sale/vo/returns/ErpSaleReturnPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.sale.vo.returns; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | + | |
| 12 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 13 | + | |
| 14 | +@Schema(description = "管理后台 - ERP 销售退货分页 Request VO") | |
| 15 | +@Data | |
| 16 | +@EqualsAndHashCode(callSuper = true) | |
| 17 | +@ToString(callSuper = true) | |
| 18 | +public class ErpSaleReturnPageReqVO extends PageParam { | |
| 19 | + | |
| 20 | + @Schema(description = "销售单编号", example = "XS001") | |
| 21 | + private String no; | |
| 22 | + | |
| 23 | + @Schema(description = "客户编号", example = "1724") | |
| 24 | + private Long customerId; | |
| 25 | + | |
| 26 | + @Schema(description = "退货时间") | |
| 27 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 28 | + private LocalDateTime[] returnTime; | |
| 29 | + | |
| 30 | + @Schema(description = "备注", example = "你猜") | |
| 31 | + private String remark; | |
| 32 | + | |
| 33 | + @Schema(description = "退货状态", example = "2") | |
| 34 | + private Integer status; | |
| 35 | + | |
| 36 | + @Schema(description = "创建者") | |
| 37 | + private String creator; | |
| 38 | + | |
| 39 | + @Schema(description = "产品编号", example = "1") | |
| 40 | + private Long productId; | |
| 41 | + | |
| 42 | + @Schema(description = "仓库编号", example = "1") | |
| 43 | + private Long warehouseId; | |
| 44 | + | |
| 45 | + @Schema(description = "结算账号编号", example = "1") | |
| 46 | + private Long accountId; | |
| 47 | + | |
| 48 | + @Schema(description = "销售单号", example = "1") | |
| 49 | + private String orderNo; | |
| 50 | + | |
| 51 | +} | |
| 0 | 52 | \ 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/returns/ErpSaleReturnRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.sale.vo.returns; | |
| 2 | + | |
| 3 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | |
| 4 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import jakarta.validation.constraints.NotNull; | |
| 7 | +import lombok.Data; | |
| 8 | + | |
| 9 | +import java.math.BigDecimal; | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - ERP 销售退货 Response VO") | |
| 14 | +@Data | |
| 15 | +@ExcelIgnoreUnannotated | |
| 16 | +public class ErpSaleReturnRespVO { | |
| 17 | + | |
| 18 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386") | |
| 19 | + @ExcelProperty("编号") | |
| 20 | + private Long id; | |
| 21 | + | |
| 22 | + @Schema(description = "退货单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "XS001") | |
| 23 | + @ExcelProperty("退货单编号") | |
| 24 | + private String no; | |
| 25 | + | |
| 26 | + @Schema(description = "退货状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | |
| 27 | + @ExcelProperty("退货状态") | |
| 28 | + private Integer status; | |
| 29 | + | |
| 30 | + @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1724") | |
| 31 | + private Long customerId; | |
| 32 | + @Schema(description = "客户名称", example = "芋道") | |
| 33 | + @ExcelProperty("客户名称") | |
| 34 | + private String customerName; | |
| 35 | + | |
| 36 | + @Schema(description = "结算账户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "311.89") | |
| 37 | + @ExcelProperty("结算账户编号") | |
| 38 | + private Long accountId; | |
| 39 | + | |
| 40 | + @Schema(description = "退货员编号", example = "1888") | |
| 41 | + private Long saleUserId; | |
| 42 | + | |
| 43 | + @Schema(description = "退货时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 44 | + @ExcelProperty("退货时间") | |
| 45 | + private LocalDateTime outTime; | |
| 46 | + | |
| 47 | + @Schema(description = "销售订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386") | |
| 48 | + private Long orderId; | |
| 49 | + @Schema(description = "销售订单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "XS001") | |
| 50 | + private String orderNo; | |
| 51 | + | |
| 52 | + @Schema(description = "合计数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15663") | |
| 53 | + @ExcelProperty("合计数量") | |
| 54 | + private BigDecimal totalCount; | |
| 55 | + @Schema(description = "最终合计价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "24906") | |
| 56 | + @ExcelProperty("最终合计价格") | |
| 57 | + private BigDecimal totalPrice; | |
| 58 | + | |
| 59 | + @Schema(description = "合计产品价格,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127") | |
| 60 | + private BigDecimal totalProductPrice; | |
| 61 | + | |
| 62 | + @Schema(description = "合计税额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127") | |
| 63 | + private BigDecimal totalTaxPrice; | |
| 64 | + | |
| 65 | + @Schema(description = "优惠率,百分比", requiredMode = Schema.RequiredMode.REQUIRED, example = "99.88") | |
| 66 | + private BigDecimal discountPercent; | |
| 67 | + | |
| 68 | + @Schema(description = "优惠金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127") | |
| 69 | + private BigDecimal discountPrice; | |
| 70 | + | |
| 71 | + @Schema(description = "定金金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127") | |
| 72 | + private BigDecimal otherPrice; | |
| 73 | + | |
| 74 | + @Schema(description = "本次退款,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127") | |
| 75 | + private BigDecimal refundPrice; | |
| 76 | + @Schema(description = "本次欠款,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "666") | |
| 77 | + private BigDecimal debtPrice; | |
| 78 | + | |
| 79 | + | |
| 80 | + @Schema(description = "附件地址", example = "https://www.iocoder.cn") | |
| 81 | + @ExcelProperty("附件地址") | |
| 82 | + private String fileUrl; | |
| 83 | + | |
| 84 | + @Schema(description = "备注", example = "你猜") | |
| 85 | + @ExcelProperty("备注") | |
| 86 | + private String remark; | |
| 87 | + | |
| 88 | + @Schema(description = "审核人", example = "芋道") | |
| 89 | + private String creator; | |
| 90 | + @Schema(description = "审核人名称", example = "芋道") | |
| 91 | + private String creatorName; | |
| 92 | + | |
| 93 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 94 | + @ExcelProperty("创建时间") | |
| 95 | + private LocalDateTime createTime; | |
| 96 | + | |
| 97 | + @Schema(description = "退货项列表", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 98 | + private List<Item> items; | |
| 99 | + | |
| 100 | + @Schema(description = "产品信息", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 101 | + @ExcelProperty("产品信息") | |
| 102 | + private String productNames; | |
| 103 | + | |
| 104 | + @Data | |
| 105 | + public static class Item { | |
| 106 | + | |
| 107 | + @Schema(description = "退货项编号", example = "11756") | |
| 108 | + private Long id; | |
| 109 | + | |
| 110 | + @Schema(description = "销售订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756") | |
| 111 | + private Long orderItemId; | |
| 112 | + | |
| 113 | + @Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | |
| 114 | + private Long warehouseId; | |
| 115 | + | |
| 116 | + @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | |
| 117 | + private Long productId; | |
| 118 | + | |
| 119 | + @Schema(description = "产品单位单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | |
| 120 | + private Long productUnitId; | |
| 121 | + | |
| 122 | + @Schema(description = "产品单价", example = "100.00") | |
| 123 | + private BigDecimal productPrice; | |
| 124 | + | |
| 125 | + @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | |
| 126 | + @NotNull(message = "产品数量不能为空") | |
| 127 | + private BigDecimal count; | |
| 128 | + | |
| 129 | + @Schema(description = "税率,百分比", example = "99.88") | |
| 130 | + private BigDecimal taxPercent; | |
| 131 | + | |
| 132 | + @Schema(description = "税额,单位:元", example = "100.00") | |
| 133 | + private BigDecimal taxPrice; | |
| 134 | + | |
| 135 | + @Schema(description = "备注", example = "随便") | |
| 136 | + private String remark; | |
| 137 | + | |
| 138 | + // ========== 关联字段 ========== | |
| 139 | + | |
| 140 | + @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "巧克力") | |
| 141 | + private String productName; | |
| 142 | + @Schema(description = "产品条码", requiredMode = Schema.RequiredMode.REQUIRED, example = "A9985") | |
| 143 | + private String productBarCode; | |
| 144 | + @Schema(description = "产品单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "盒") | |
| 145 | + private String productUnitName; | |
| 146 | + | |
| 147 | + @Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | |
| 148 | + private BigDecimal stockCount; // 该字段仅仅在“详情”和“编辑”时使用 | |
| 149 | + | |
| 150 | + } | |
| 151 | + | |
| 152 | +} | |
| 0 | 153 | \ 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/returns/ErpSaleReturnSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.sale.vo.returns; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import jakarta.validation.constraints.NotNull; | |
| 5 | +import lombok.Data; | |
| 6 | + | |
| 7 | +import java.math.BigDecimal; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | +import java.util.List; | |
| 10 | + | |
| 11 | +@Schema(description = "管理后台 - ERP 销售退货新增/修改 Request VO") | |
| 12 | +@Data | |
| 13 | +public class ErpSaleReturnSaveReqVO { | |
| 14 | + | |
| 15 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386") | |
| 16 | + private Long id; | |
| 17 | + | |
| 18 | + @Schema(description = "结算账户编号", example = "31189") | |
| 19 | + private Long accountId; | |
| 20 | + | |
| 21 | + @Schema(description = "销售员编号", example = "1888") | |
| 22 | + private Long saleUserId; | |
| 23 | + | |
| 24 | + @Schema(description = "退货时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 25 | + @NotNull(message = "退货时间不能为空") | |
| 26 | + private LocalDateTime returnTime; | |
| 27 | + | |
| 28 | + @Schema(description = "销售订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386") | |
| 29 | + @NotNull(message = "销售订单编号不能为空") | |
| 30 | + private Long orderId; | |
| 31 | + | |
| 32 | + @Schema(description = "优惠率,百分比", requiredMode = Schema.RequiredMode.REQUIRED, example = "99.88") | |
| 33 | + private BigDecimal discountPercent; | |
| 34 | + | |
| 35 | + @Schema(description = "其它金额,单位:元", example = "7127") | |
| 36 | + private BigDecimal otherPrice; | |
| 37 | + | |
| 38 | + @Schema(description = "本次退款,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127") | |
| 39 | + @NotNull(message = "本次退款不能为空") | |
| 40 | + private BigDecimal refundPrice; | |
| 41 | + | |
| 42 | + @Schema(description = "附件地址", example = "https://www.iocoder.cn") | |
| 43 | + private String fileUrl; | |
| 44 | + | |
| 45 | + @Schema(description = "备注", example = "你猜") | |
| 46 | + private String remark; | |
| 47 | + | |
| 48 | + @Schema(description = "退货清单列表") | |
| 49 | + private List<Item> items; | |
| 50 | + | |
| 51 | + @Data | |
| 52 | + public static class Item { | |
| 53 | + | |
| 54 | + @Schema(description = "退货项编号", example = "11756") | |
| 55 | + private Long id; | |
| 56 | + | |
| 57 | + @Schema(description = "销售订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756") | |
| 58 | + @NotNull(message = "销售订单项编号不能为空") | |
| 59 | + private Long orderItemId; | |
| 60 | + | |
| 61 | + @Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | |
| 62 | + @NotNull(message = "仓库编号不能为空") | |
| 63 | + private Long warehouseId; | |
| 64 | + | |
| 65 | + @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | |
| 66 | + @NotNull(message = "产品编号不能为空") | |
| 67 | + private Long productId; | |
| 68 | + | |
| 69 | + @Schema(description = "产品单位单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | |
| 70 | + @NotNull(message = "产品单位单位不能为空") | |
| 71 | + private Long productUnitId; | |
| 72 | + | |
| 73 | + @Schema(description = "产品单价", example = "100.00") | |
| 74 | + private BigDecimal productPrice; | |
| 75 | + | |
| 76 | + @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | |
| 77 | + @NotNull(message = "产品数量不能为空") | |
| 78 | + private BigDecimal count; | |
| 79 | + | |
| 80 | + @Schema(description = "税率,百分比", example = "99.88") | |
| 81 | + private BigDecimal taxPercent; | |
| 82 | + | |
| 83 | + @Schema(description = "备注", example = "随便") | |
| 84 | + private String remark; | |
| 85 | + | |
| 86 | + } | |
| 87 | + | |
| 88 | +} | |
| 0 | 89 | \ No newline at end of file | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/sale/ErpSaleReturnDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.dal.dataobject.sale; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 4 | +import cn.iocoder.yudao.module.erp.dal.dataobject.finance.ErpAccountDO; | |
| 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 | +import java.time.LocalDateTime; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * ERP 销售退货 DO | |
| 15 | + * | |
| 16 | + * @author 芋道源码 | |
| 17 | + */ | |
| 18 | +@TableName(value = "erp_sale_return") | |
| 19 | +@KeySequence("erp_sale_return_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 20 | +@Data | |
| 21 | +@EqualsAndHashCode(callSuper = true) | |
| 22 | +@ToString(callSuper = true) | |
| 23 | +@Builder | |
| 24 | +@NoArgsConstructor | |
| 25 | +@AllArgsConstructor | |
| 26 | +public class ErpSaleReturnDO extends BaseDO { | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 编号 | |
| 30 | + */ | |
| 31 | + @TableId | |
| 32 | + private Long id; | |
| 33 | + /** | |
| 34 | + * 销售退货单号 | |
| 35 | + */ | |
| 36 | + private String no; | |
| 37 | + /** | |
| 38 | + * 退货状态 | |
| 39 | + * | |
| 40 | + * 枚举 {@link cn.iocoder.yudao.module.erp.enums.ErpAuditStatus} | |
| 41 | + */ | |
| 42 | + private Integer status; | |
| 43 | + /** | |
| 44 | + * 客户编号 | |
| 45 | + * | |
| 46 | + * 关联 {@link ErpCustomerDO#getId()} | |
| 47 | + */ | |
| 48 | + private Long customerId; | |
| 49 | + /** | |
| 50 | + * 结算账户编号 | |
| 51 | + * | |
| 52 | + * 关联 {@link ErpAccountDO#getId()} | |
| 53 | + */ | |
| 54 | + private Long accountId; | |
| 55 | + /** | |
| 56 | + * 销售员编号 | |
| 57 | + * | |
| 58 | + * 关联 AdminUserDO 的 id 字段 | |
| 59 | + */ | |
| 60 | + private Long saleUserId; | |
| 61 | + /** | |
| 62 | + * 退货时间 | |
| 63 | + */ | |
| 64 | + private LocalDateTime returnTime; | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * 销售订单编号 | |
| 68 | + * | |
| 69 | + * 关联 {@link ErpSaleOrderDO#getId()} | |
| 70 | + */ | |
| 71 | + private Long orderId; | |
| 72 | + /** | |
| 73 | + * 销售订单号 | |
| 74 | + * | |
| 75 | + * 冗余 {@link ErpSaleOrderDO#getNo()} | |
| 76 | + */ | |
| 77 | + private String orderNo; | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * 合计数量 | |
| 81 | + */ | |
| 82 | + private BigDecimal totalCount; | |
| 83 | + /** | |
| 84 | + * 最终合计价格,单位:元 | |
| 85 | + * | |
| 86 | + * totalPrice = totalProductPrice + totalTaxPrice - discountPrice | |
| 87 | + */ | |
| 88 | + private BigDecimal totalPrice; | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * 合计产品价格,单位:元 | |
| 92 | + */ | |
| 93 | + private BigDecimal totalProductPrice; | |
| 94 | + /** | |
| 95 | + * 合计税额,单位:元 | |
| 96 | + */ | |
| 97 | + private BigDecimal totalTaxPrice; | |
| 98 | + /** | |
| 99 | + * 优惠率,百分比 | |
| 100 | + */ | |
| 101 | + private BigDecimal discountPercent; | |
| 102 | + /** | |
| 103 | + * 优惠金额,单位:元 | |
| 104 | + * | |
| 105 | + * discountPrice = (totalProductPrice + totalTaxPrice) * discountPercent | |
| 106 | + */ | |
| 107 | + private BigDecimal discountPrice; | |
| 108 | + /** | |
| 109 | + * 其它金额,单位:元 | |
| 110 | + */ | |
| 111 | + private BigDecimal otherPrice; | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * 本次收款,单位:元 | |
| 115 | + * | |
| 116 | + * refundPrice = totalPrice + otherPrice - debtPrice | |
| 117 | + */ | |
| 118 | + private BigDecimal refundPrice; | |
| 119 | + /** | |
| 120 | + * 本次欠款,单位:元 | |
| 121 | + */ | |
| 122 | + private BigDecimal debtPrice; | |
| 123 | + | |
| 124 | + /** | |
| 125 | + * 附件地址 | |
| 126 | + */ | |
| 127 | + private String fileUrl; | |
| 128 | + /** | |
| 129 | + * 备注 | |
| 130 | + */ | |
| 131 | + private String remark; | |
| 132 | + | |
| 133 | +} | |
| 0 | 134 | \ No newline at end of file | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/sale/ErpSaleReturnItemDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.dal.dataobject.sale; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 4 | +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO; | |
| 5 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO; | |
| 6 | +import com.baomidou.mybatisplus.annotation.KeySequence; | |
| 7 | +import com.baomidou.mybatisplus.annotation.TableId; | |
| 8 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 9 | +import lombok.*; | |
| 10 | + | |
| 11 | +import java.math.BigDecimal; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * ERP 销售退货项 DO | |
| 15 | + * | |
| 16 | + * @author 芋道源码 | |
| 17 | + */ | |
| 18 | +@TableName("erp_sale_return_items") | |
| 19 | +@KeySequence("erp_sale_return_items_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 20 | +@Data | |
| 21 | +@EqualsAndHashCode(callSuper = true) | |
| 22 | +@ToString(callSuper = true) | |
| 23 | +@Builder | |
| 24 | +@NoArgsConstructor | |
| 25 | +@AllArgsConstructor | |
| 26 | +public class ErpSaleReturnItemDO extends BaseDO { | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 编号 | |
| 30 | + */ | |
| 31 | + @TableId | |
| 32 | + private Long id; | |
| 33 | + /** | |
| 34 | + * 销售退货编号 | |
| 35 | + * | |
| 36 | + * 关联 {@link ErpSaleReturnDO##getId()} | |
| 37 | + */ | |
| 38 | + private Long returnId; | |
| 39 | + /** | |
| 40 | + * 销售订单项编号 | |
| 41 | + * | |
| 42 | + * 关联 {@link ErpSaleOrderItemDO#getId()} | |
| 43 | + * 目的:方便更新关联的销售订单项的退货数量 | |
| 44 | + */ | |
| 45 | + private Long orderItemId; | |
| 46 | + /** | |
| 47 | + * 仓库编号 | |
| 48 | + * | |
| 49 | + * 关联 {@link ErpWarehouseDO#getId()} | |
| 50 | + */ | |
| 51 | + private Long warehouseId; | |
| 52 | + /** | |
| 53 | + * 产品编号 | |
| 54 | + * | |
| 55 | + * 关联 {@link ErpProductDO#getId()} | |
| 56 | + */ | |
| 57 | + private Long productId; | |
| 58 | + /** | |
| 59 | + * 产品单位单位 | |
| 60 | + * | |
| 61 | + * 冗余 {@link ErpProductDO#getUnitId()} | |
| 62 | + */ | |
| 63 | + private Long productUnitId; | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * 产品单位单价,单位:元 | |
| 67 | + */ | |
| 68 | + private BigDecimal productPrice; | |
| 69 | + /** | |
| 70 | + * 数量 | |
| 71 | + */ | |
| 72 | + private BigDecimal count; | |
| 73 | + /** | |
| 74 | + * 总价,单位:元 | |
| 75 | + * | |
| 76 | + * totalPrice = productPrice * count | |
| 77 | + */ | |
| 78 | + private BigDecimal totalPrice; | |
| 79 | + /** | |
| 80 | + * 税率,百分比 | |
| 81 | + */ | |
| 82 | + private BigDecimal taxPercent; | |
| 83 | + /** | |
| 84 | + * 税额,单位:元 | |
| 85 | + * | |
| 86 | + * taxPrice = totalPrice * taxPercent | |
| 87 | + */ | |
| 88 | + private BigDecimal taxPrice; | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * 备注 | |
| 92 | + */ | |
| 93 | + private String remark; | |
| 94 | + | |
| 95 | +} | |
| 0 | 96 | \ No newline at end of file | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/sale/ErpSaleOutItemMapper.java
| ... | ... | @@ -22,16 +22,16 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. |
| 22 | 22 | @Mapper |
| 23 | 23 | public interface ErpSaleOutItemMapper extends BaseMapperX<ErpSaleOutItemDO> { |
| 24 | 24 | |
| 25 | - default List<ErpSaleOutItemDO> selectListByOutId(Long orderId) { | |
| 26 | - return selectList(ErpSaleOutItemDO::getOutId, orderId); | |
| 25 | + default List<ErpSaleOutItemDO> selectListByOutId(Long outId) { | |
| 26 | + return selectList(ErpSaleOutItemDO::getOutId, outId); | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - default List<ErpSaleOutItemDO> selectListByOutIds(Collection<Long> orderIds) { | |
| 30 | - return selectList(ErpSaleOutItemDO::getOutId, orderIds); | |
| 29 | + default List<ErpSaleOutItemDO> selectListByOutIds(Collection<Long> outIds) { | |
| 30 | + return selectList(ErpSaleOutItemDO::getOutId, outIds); | |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - default int deleteByOutId(Long orderId) { | |
| 34 | - return delete(ErpSaleOutItemDO::getOutId, orderId); | |
| 33 | + default int deleteByOutId(Long outId) { | |
| 34 | + return delete(ErpSaleOutItemDO::getOutId, outId); | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/sale/ErpSaleReturnItemMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.dal.mysql.sale; | |
| 2 | + | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 5 | +import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleReturnItemDO; | |
| 6 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
| 7 | +import org.apache.ibatis.annotations.Mapper; | |
| 8 | + | |
| 9 | +import java.math.BigDecimal; | |
| 10 | +import java.util.Collection; | |
| 11 | +import java.util.Collections; | |
| 12 | +import java.util.List; | |
| 13 | +import java.util.Map; | |
| 14 | + | |
| 15 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | |
| 16 | + | |
| 17 | +/** | |
| 18 | + * ERP 销售退货项 Mapper | |
| 19 | + * | |
| 20 | + * @author 芋道源码 | |
| 21 | + */ | |
| 22 | +@Mapper | |
| 23 | +public interface ErpSaleReturnItemMapper extends BaseMapperX<ErpSaleReturnItemDO> { | |
| 24 | + | |
| 25 | + default List<ErpSaleReturnItemDO> selectListByReturnId(Long returnId) { | |
| 26 | + return selectList(ErpSaleReturnItemDO::getReturnId, returnId); | |
| 27 | + } | |
| 28 | + | |
| 29 | + default List<ErpSaleReturnItemDO> selectListByReturnIds(Collection<Long> returnIds) { | |
| 30 | + return selectList(ErpSaleReturnItemDO::getReturnId, returnIds); | |
| 31 | + } | |
| 32 | + | |
| 33 | + default int deleteByReturnId(Long returnId) { | |
| 34 | + return delete(ErpSaleReturnItemDO::getReturnId, returnId); | |
| 35 | + } | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * 基于销售订单编号,查询每个销售订单项的出库数量之和 | |
| 39 | + * | |
| 40 | + * @param returnIds 出库订单项编号数组 | |
| 41 | + * @return key:销售订单项编号;value:出库数量之和 | |
| 42 | + */ | |
| 43 | + default Map<Long, BigDecimal> selectOrderItemCountSumMapByReturnIds(Collection<Long> returnIds) { | |
| 44 | + if (CollUtil.isEmpty(returnIds)) { | |
| 45 | + return Collections.emptyMap(); | |
| 46 | + } | |
| 47 | + // SQL sum 查询 | |
| 48 | + List<Map<String, Object>> result = selectMaps(new QueryWrapper<ErpSaleReturnItemDO>() | |
| 49 | + .select("order_item_id, SUM(count) AS sumCount") | |
| 50 | + .groupBy("order_item_id") | |
| 51 | + .in("return_id", returnIds)); | |
| 52 | + // 获得数量 | |
| 53 | + return convertMap(result, obj -> (Long) obj.get("order_item_id"), obj -> (BigDecimal) obj.get("sumCount")); | |
| 54 | + } | |
| 55 | + | |
| 56 | +} | |
| 0 | 57 | \ No newline at end of file | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/sale/ErpSaleReturnMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.dal.mysql.sale; | |
| 2 | + | |
| 3 | + | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX; | |
| 7 | +import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.returns.ErpSaleReturnPageReqVO; | |
| 8 | +import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleReturnDO; | |
| 9 | +import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleReturnItemDO; | |
| 10 | +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | |
| 11 | +import org.apache.ibatis.annotations.Mapper; | |
| 12 | + | |
| 13 | +import java.util.List; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * ERP 销售退货 Mapper | |
| 17 | + * | |
| 18 | + * @author 芋道源码 | |
| 19 | + */ | |
| 20 | +@Mapper | |
| 21 | +public interface ErpSaleReturnMapper extends BaseMapperX<ErpSaleReturnDO> { | |
| 22 | + | |
| 23 | + default PageResult<ErpSaleReturnDO> selectPage(ErpSaleReturnPageReqVO reqVO) { | |
| 24 | + MPJLambdaWrapperX<ErpSaleReturnDO> query = new MPJLambdaWrapperX<ErpSaleReturnDO>() | |
| 25 | + .likeIfPresent(ErpSaleReturnDO::getNo, reqVO.getNo()) | |
| 26 | + .eqIfPresent(ErpSaleReturnDO::getCustomerId, reqVO.getCustomerId()) | |
| 27 | + .betweenIfPresent(ErpSaleReturnDO::getReturnTime, reqVO.getReturnTime()) | |
| 28 | + .eqIfPresent(ErpSaleReturnDO::getStatus, reqVO.getStatus()) | |
| 29 | + .likeIfPresent(ErpSaleReturnDO::getRemark, reqVO.getRemark()) | |
| 30 | + .eqIfPresent(ErpSaleReturnDO::getCreator, reqVO.getCreator()) | |
| 31 | + .eqIfPresent(ErpSaleReturnDO::getAccountId, reqVO.getAccountId()) | |
| 32 | + .likeIfPresent(ErpSaleReturnDO::getOrderNo, reqVO.getOrderNo()) | |
| 33 | + .orderByDesc(ErpSaleReturnDO::getId); | |
| 34 | + if (reqVO.getWarehouseId() != null || reqVO.getProductId() != null) { | |
| 35 | + query.leftJoin(ErpSaleReturnItemDO.class, ErpSaleReturnItemDO::getReturnId, ErpSaleReturnDO::getId) | |
| 36 | + .eq(reqVO.getWarehouseId() != null, ErpSaleReturnItemDO::getWarehouseId, reqVO.getWarehouseId()) | |
| 37 | + .eq(reqVO.getProductId() != null, ErpSaleReturnItemDO::getProductId, reqVO.getProductId()) | |
| 38 | + .groupBy(ErpSaleReturnDO::getId); // 避免 1 对多查询,产生相同的 1 | |
| 39 | + } | |
| 40 | + return selectJoinPage(reqVO, ErpSaleReturnDO.class, query); | |
| 41 | + } | |
| 42 | + | |
| 43 | + default int updateByIdAndStatus(Long id, Integer status, ErpSaleReturnDO updateObj) { | |
| 44 | + return update(updateObj, new LambdaUpdateWrapper<ErpSaleReturnDO>() | |
| 45 | + .eq(ErpSaleReturnDO::getId, id).eq(ErpSaleReturnDO::getStatus, status)); | |
| 46 | + } | |
| 47 | + | |
| 48 | + default ErpSaleReturnDO selectByNo(String no) { | |
| 49 | + return selectOne(ErpSaleReturnDO::getNo, no); | |
| 50 | + } | |
| 51 | + | |
| 52 | + default List<ErpSaleReturnDO> selectListByOrderId(Long orderId) { | |
| 53 | + return selectList(ErpSaleReturnDO::getOrderId, orderId); | |
| 54 | + } | |
| 55 | + | |
| 56 | +} | |
| 0 | 57 | \ No newline at end of file | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/redis/no/ErpNoRedisDAO.java
| ... | ... | @@ -46,6 +46,10 @@ public class ErpNoRedisDAO { |
| 46 | 46 | * 销售出库 {@link cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleOutDO} |
| 47 | 47 | */ |
| 48 | 48 | public static final String SALE_OUT_NO_PREFIX = "XSCK"; |
| 49 | + /** | |
| 50 | + * 销售退货 {@link cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleReturnDO} | |
| 51 | + */ | |
| 52 | + public static final String SALE_RETURN_NO_PREFIX = "XSTH"; | |
| 49 | 53 | |
| 50 | 54 | @Resource |
| 51 | 55 | private StringRedisTemplate stringRedisTemplate; | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/sale/ErpSaleOrderService.java
| ... | ... | @@ -46,9 +46,17 @@ public interface ErpSaleOrderService { |
| 46 | 46 | * 更新销售订单的出库数量 |
| 47 | 47 | * |
| 48 | 48 | * @param id 编号 |
| 49 | - * @param returnCountMap 出库数量 Map:key 销售订单项编号;value 出库数量 | |
| 49 | + * @param outCountMap 出库数量 Map:key 销售订单项编号;value 出库数量 | |
| 50 | 50 | */ |
| 51 | - void updateSaleOrderOutCount(Long id, Map<Long, BigDecimal> returnCountMap); | |
| 51 | + void updateSaleOrderOutCount(Long id, Map<Long, BigDecimal> outCountMap); | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * 更新销售订单的退货数量 | |
| 55 | + * | |
| 56 | + * @param orderId 编号 | |
| 57 | + * @param returnCountMap 退货数量 Map:key 销售订单项编号;value 退货数量 | |
| 58 | + */ | |
| 59 | + void updateSaleOrderReturnCount(Long orderId, Map<Long, BigDecimal> returnCountMap); | |
| 52 | 60 | |
| 53 | 61 | /** |
| 54 | 62 | * 删除销售订单 | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/sale/ErpSaleOrderServiceImpl.java
| ... | ... | @@ -149,7 +149,10 @@ public class ErpSaleOrderServiceImpl implements ErpSaleOrderService { |
| 149 | 149 | if (!approve && saleOrder.getOutCount().compareTo(BigDecimal.ZERO) > 0) { |
| 150 | 150 | throw exception(SALE_ORDER_PROCESS_FAIL_EXISTS_OUT); |
| 151 | 151 | } |
| 152 | - // TODO @芋艿:需要校验是不是有有退货 | |
| 152 | + // 1.4 存在销售退货单,无法反审核 | |
| 153 | + if (!approve && saleOrder.getReturnCount().compareTo(BigDecimal.ZERO) > 0) { | |
| 154 | + throw exception(SALE_ORDER_PROCESS_FAIL_EXISTS_RETURN); | |
| 155 | + } | |
| 153 | 156 | |
| 154 | 157 | // 2. 更新状态 |
| 155 | 158 | int updateCount = saleOrderMapper.updateByIdAndStatus(id, saleOrder.getStatus(), |
| ... | ... | @@ -159,26 +162,6 @@ public class ErpSaleOrderServiceImpl implements ErpSaleOrderService { |
| 159 | 162 | } |
| 160 | 163 | } |
| 161 | 164 | |
| 162 | - @Override | |
| 163 | - public void updateSaleOrderOutCount(Long id, Map<Long, BigDecimal> returnCountMap) { | |
| 164 | - List<ErpSaleOrderItemDO> orderItems = saleOrderItemMapper.selectListByOrderId(id); | |
| 165 | - // 1. 更新每个销售订单项 | |
| 166 | - orderItems.forEach(item -> { | |
| 167 | - BigDecimal outCount = returnCountMap.getOrDefault(item.getId(), BigDecimal.ZERO); | |
| 168 | - if (item.getOutCount().equals(outCount)) { | |
| 169 | - return; | |
| 170 | - } | |
| 171 | - if (outCount.compareTo(item.getCount()) > 0) { | |
| 172 | - throw exception(SALE_ORDER_ITEM_OUT_FAIL_PRODUCT_EXCEED, | |
| 173 | - productService.getProduct(item.getProductId()).getName(), item.getCount()); | |
| 174 | - } | |
| 175 | - saleOrderItemMapper.updateById(new ErpSaleOrderItemDO().setId(item.getId()).setOutCount(outCount)); | |
| 176 | - }); | |
| 177 | - // 2. 更新销售订单 | |
| 178 | - BigDecimal totalOutCount = getSumValue(returnCountMap.values(), value -> value, BigDecimal::add, BigDecimal.ZERO); | |
| 179 | - saleOrderMapper.updateById(new ErpSaleOrderDO().setId(id).setOutCount(totalOutCount)); | |
| 180 | - } | |
| 181 | - | |
| 182 | 165 | private List<ErpSaleOrderItemDO> validateSaleOrderItems(List<ErpSaleOrderSaveReqVO.Item> list) { |
| 183 | 166 | // 1. 校验产品存在 |
| 184 | 167 | List<ErpProductDO> productList = productService.validProductList( |
| ... | ... | @@ -219,6 +202,46 @@ public class ErpSaleOrderServiceImpl implements ErpSaleOrderService { |
| 219 | 202 | } |
| 220 | 203 | |
| 221 | 204 | @Override |
| 205 | + public void updateSaleOrderOutCount(Long id, Map<Long, BigDecimal> outCountMap) { | |
| 206 | + List<ErpSaleOrderItemDO> orderItems = saleOrderItemMapper.selectListByOrderId(id); | |
| 207 | + // 1. 更新每个销售订单项 | |
| 208 | + orderItems.forEach(item -> { | |
| 209 | + BigDecimal outCount = outCountMap.getOrDefault(item.getId(), BigDecimal.ZERO); | |
| 210 | + if (item.getOutCount().equals(outCount)) { | |
| 211 | + return; | |
| 212 | + } | |
| 213 | + if (outCount.compareTo(item.getCount()) > 0) { | |
| 214 | + throw exception(SALE_ORDER_ITEM_OUT_FAIL_PRODUCT_EXCEED, | |
| 215 | + productService.getProduct(item.getProductId()).getName(), item.getCount()); | |
| 216 | + } | |
| 217 | + saleOrderItemMapper.updateById(new ErpSaleOrderItemDO().setId(item.getId()).setOutCount(outCount)); | |
| 218 | + }); | |
| 219 | + // 2. 更新销售订单 | |
| 220 | + BigDecimal totalOutCount = getSumValue(outCountMap.values(), value -> value, BigDecimal::add, BigDecimal.ZERO); | |
| 221 | + saleOrderMapper.updateById(new ErpSaleOrderDO().setId(id).setOutCount(totalOutCount)); | |
| 222 | + } | |
| 223 | + | |
| 224 | + @Override | |
| 225 | + public void updateSaleOrderReturnCount(Long orderId, Map<Long, BigDecimal> returnCountMap) { | |
| 226 | + List<ErpSaleOrderItemDO> orderItems = saleOrderItemMapper.selectListByOrderId(orderId); | |
| 227 | + // 1. 更新每个销售订单项 | |
| 228 | + orderItems.forEach(item -> { | |
| 229 | + BigDecimal returnCount = returnCountMap.getOrDefault(item.getId(), BigDecimal.ZERO); | |
| 230 | + if (item.getReturnCount().equals(returnCount)) { | |
| 231 | + return; | |
| 232 | + } | |
| 233 | + if (returnCount.compareTo(item.getOutCount()) > 0) { | |
| 234 | + throw exception(SALE_ORDER_ITEM_RETURN_FAIL_OUT_EXCEED, | |
| 235 | + productService.getProduct(item.getProductId()).getName(), item.getOutCount()); | |
| 236 | + } | |
| 237 | + saleOrderItemMapper.updateById(new ErpSaleOrderItemDO().setId(item.getId()).setReturnCount(returnCount)); | |
| 238 | + }); | |
| 239 | + // 2. 更新销售订单 | |
| 240 | + BigDecimal totalReturnCount = getSumValue(returnCountMap.values(), value -> value, BigDecimal::add, BigDecimal.ZERO); | |
| 241 | + saleOrderMapper.updateById(new ErpSaleOrderDO().setId(orderId).setReturnCount(totalReturnCount)); | |
| 242 | + } | |
| 243 | + | |
| 244 | + @Override | |
| 222 | 245 | @Transactional(rollbackFor = Exception.class) |
| 223 | 246 | public void deleteSaleOrder(List<Long> ids) { |
| 224 | 247 | // 1. 校验不处于已审批 | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/sale/ErpSaleOutServiceImpl.java
| ... | ... | @@ -40,7 +40,7 @@ import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*; |
| 40 | 40 | // TODO 芋艿:记录操作日志 |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | - * ERP 销售订单 Service 实现类 | |
| 43 | + * ERP 销售出库 Service 实现类 | |
| 44 | 44 | * |
| 45 | 45 | * @author 芋道源码 |
| 46 | 46 | */ |
| ... | ... | @@ -74,7 +74,7 @@ public class ErpSaleOutServiceImpl implements ErpSaleOutService { |
| 74 | 74 | public Long createSaleOut(ErpSaleOutSaveReqVO createReqVO) { |
| 75 | 75 | // 1.1 校验销售订单已审核 |
| 76 | 76 | ErpSaleOrderDO saleOrder = saleOrderService.validateSaleOrder(createReqVO.getOrderId()); |
| 77 | - // 1.2 校验订单项的有效性 | |
| 77 | + // 1.2 校验出库项的有效性 | |
| 78 | 78 | List<ErpSaleOutItemDO> saleOutItems = validateSaleOutItems(createReqVO.getItems()); |
| 79 | 79 | // 1.3 校验结算账户 |
| 80 | 80 | accountService.validateAccount(createReqVO.getAccountId()); |
| ... | ... | @@ -88,13 +88,13 @@ public class ErpSaleOutServiceImpl implements ErpSaleOutService { |
| 88 | 88 | throw exception(SALE_OUT_NO_EXISTS); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - // 2.1 插入订单 | |
| 91 | + // 2.1 插入出库 | |
| 92 | 92 | ErpSaleOutDO saleOut = BeanUtils.toBean(createReqVO, ErpSaleOutDO.class, in -> in |
| 93 | 93 | .setNo(no).setStatus(ErpAuditStatus.PROCESS.getStatus())) |
| 94 | 94 | .setOrderNo(saleOrder.getNo()).setCustomerId(saleOrder.getCustomerId()); |
| 95 | 95 | calculateTotalPrice(saleOut, saleOutItems); |
| 96 | 96 | saleOutMapper.insert(saleOut); |
| 97 | - // 2.2 插入订单项 | |
| 97 | + // 2.2 插入出库项 | |
| 98 | 98 | saleOutItems.forEach(o -> o.setOutId(saleOut.getId())); |
| 99 | 99 | saleOutItemMapper.insertBatch(saleOutItems); |
| 100 | 100 | |
| ... | ... | @@ -122,12 +122,12 @@ public class ErpSaleOutServiceImpl implements ErpSaleOutService { |
| 122 | 122 | // 1.5 校验订单项的有效性 |
| 123 | 123 | List<ErpSaleOutItemDO> saleOutItems = validateSaleOutItems(updateReqVO.getItems()); |
| 124 | 124 | |
| 125 | - // 2.1 更新订单 | |
| 125 | + // 2.1 更新出库 | |
| 126 | 126 | ErpSaleOutDO updateObj = BeanUtils.toBean(updateReqVO, ErpSaleOutDO.class) |
| 127 | 127 | .setOrderNo(saleOrder.getNo()).setCustomerId(saleOrder.getCustomerId()); |
| 128 | 128 | calculateTotalPrice(updateObj, saleOutItems); |
| 129 | 129 | saleOutMapper.updateById(updateObj); |
| 130 | - // 2.2 更新订单项 | |
| 130 | + // 2.2 更新出库项 | |
| 131 | 131 | updateSaleOutItemList(updateReqVO.getId(), saleOutItems); |
| 132 | 132 | |
| 133 | 133 | // 3.1 更新销售订单的出库数量 |
| ... | ... | @@ -278,7 +278,7 @@ public class ErpSaleOutServiceImpl implements ErpSaleOutService { |
| 278 | 278 | return saleOutMapper.selectPage(pageReqVO); |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - // ==================== 订单项 ==================== | |
| 281 | + // ==================== 销售出库项 ==================== | |
| 282 | 282 | |
| 283 | 283 | @Override |
| 284 | 284 | public List<ErpSaleOutItemDO> getSaleOutItemListByOutId(Long outId) { | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/sale/ErpSaleReturnService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.service.sale; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.returns.ErpSaleReturnPageReqVO; | |
| 5 | +import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.returns.ErpSaleReturnSaveReqVO; | |
| 6 | +import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleReturnDO; | |
| 7 | +import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleReturnItemDO; | |
| 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 ErpSaleReturnService { | |
| 19 | + | |
| 20 | + /** | |
| 21 | + * 创建销售退货 | |
| 22 | + * | |
| 23 | + * @param createReqVO 创建信息 | |
| 24 | + * @return 编号 | |
| 25 | + */ | |
| 26 | + Long createSaleReturn(@Valid ErpSaleReturnSaveReqVO createReqVO); | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 更新销售退货 | |
| 30 | + * | |
| 31 | + * @param updateReqVO 更新信息 | |
| 32 | + */ | |
| 33 | + void updateSaleReturn(@Valid ErpSaleReturnSaveReqVO updateReqVO); | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * 更新销售退货的状态 | |
| 37 | + * | |
| 38 | + * @param id 编号 | |
| 39 | + * @param status 状态 | |
| 40 | + */ | |
| 41 | + void updateSaleReturnStatus(Long id, Integer status); | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * 删除销售退货 | |
| 45 | + * | |
| 46 | + * @param ids 编号数组 | |
| 47 | + */ | |
| 48 | + void deleteSaleReturn(List<Long> ids); | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * 获得销售退货 | |
| 52 | + * | |
| 53 | + * @param id 编号 | |
| 54 | + * @return 销售退货 | |
| 55 | + */ | |
| 56 | + ErpSaleReturnDO getSaleReturn(Long id); | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * 获得销售退货分页 | |
| 60 | + * | |
| 61 | + * @param pageReqVO 分页查询 | |
| 62 | + * @return 销售退货分页 | |
| 63 | + */ | |
| 64 | + PageResult<ErpSaleReturnDO> getSaleReturnPage(ErpSaleReturnPageReqVO pageReqVO); | |
| 65 | + | |
| 66 | + // ==================== 销售退货项 ==================== | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * 获得销售退货项列表 | |
| 70 | + * | |
| 71 | + * @param returnId 销售退货编号 | |
| 72 | + * @return 销售退货项列表 | |
| 73 | + */ | |
| 74 | + List<ErpSaleReturnItemDO> getSaleReturnItemListByReturnId(Long returnId); | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * 获得销售退货项 List | |
| 78 | + * | |
| 79 | + * @param returnIds 销售退货编号数组 | |
| 80 | + * @return 销售退货项 List | |
| 81 | + */ | |
| 82 | + List<ErpSaleReturnItemDO> getSaleReturnItemListByReturnIds(Collection<Long> returnIds); | |
| 83 | + | |
| 84 | +} | |
| 0 | 85 | \ No newline at end of file | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/sale/ErpSaleReturnServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.service.sale; | |
| 2 | + | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.hutool.core.util.ObjectUtil; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | |
| 7 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 8 | +import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.returns.ErpSaleReturnPageReqVO; | |
| 9 | +import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.returns.ErpSaleReturnSaveReqVO; | |
| 10 | +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO; | |
| 11 | +import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleOrderDO; | |
| 12 | +import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleReturnDO; | |
| 13 | +import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleReturnItemDO; | |
| 14 | +import cn.iocoder.yudao.module.erp.dal.mysql.sale.ErpSaleReturnItemMapper; | |
| 15 | +import cn.iocoder.yudao.module.erp.dal.mysql.sale.ErpSaleReturnMapper; | |
| 16 | +import cn.iocoder.yudao.module.erp.dal.redis.no.ErpNoRedisDAO; | |
| 17 | +import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus; | |
| 18 | +import cn.iocoder.yudao.module.erp.enums.stock.ErpStockRecordBizTypeEnum; | |
| 19 | +import cn.iocoder.yudao.module.erp.service.finance.ErpAccountService; | |
| 20 | +import cn.iocoder.yudao.module.erp.service.product.ErpProductService; | |
| 21 | +import cn.iocoder.yudao.module.erp.service.stock.ErpStockRecordService; | |
| 22 | +import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO; | |
| 23 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | |
| 24 | +import jakarta.annotation.Resource; | |
| 25 | +import org.springframework.context.annotation.Lazy; | |
| 26 | +import org.springframework.stereotype.Service; | |
| 27 | +import org.springframework.transaction.annotation.Transactional; | |
| 28 | +import org.springframework.validation.annotation.Validated; | |
| 29 | + | |
| 30 | +import java.math.BigDecimal; | |
| 31 | +import java.util.Collection; | |
| 32 | +import java.util.Collections; | |
| 33 | +import java.util.List; | |
| 34 | +import java.util.Map; | |
| 35 | + | |
| 36 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 37 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; | |
| 38 | +import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*; | |
| 39 | + | |
| 40 | +// TODO 芋艿:记录操作日志 | |
| 41 | + | |
| 42 | +/** | |
| 43 | + * ERP 销售退货 Service 实现类 | |
| 44 | + * | |
| 45 | + * @author 芋道源码 | |
| 46 | + */ | |
| 47 | +@Service | |
| 48 | +@Validated | |
| 49 | +public class ErpSaleReturnServiceImpl implements ErpSaleReturnService { | |
| 50 | + | |
| 51 | + @Resource | |
| 52 | + private ErpSaleReturnMapper saleReturnMapper; | |
| 53 | + @Resource | |
| 54 | + private ErpSaleReturnItemMapper saleReturnItemMapper; | |
| 55 | + | |
| 56 | + @Resource | |
| 57 | + private ErpNoRedisDAO noRedisDAO; | |
| 58 | + | |
| 59 | + @Resource | |
| 60 | + private ErpProductService productService; | |
| 61 | + @Resource | |
| 62 | + @Lazy // 延迟加载,避免循环依赖 | |
| 63 | + private ErpSaleOrderService saleOrderService; | |
| 64 | + @Resource | |
| 65 | + private ErpAccountService accountService; | |
| 66 | + @Resource | |
| 67 | + private ErpStockRecordService stockRecordService; | |
| 68 | + | |
| 69 | + @Resource | |
| 70 | + private AdminUserApi adminUserApi; | |
| 71 | + | |
| 72 | + @Override | |
| 73 | + @Transactional(rollbackFor = Exception.class) | |
| 74 | + public Long createSaleReturn(ErpSaleReturnSaveReqVO createReqVO) { | |
| 75 | + // 1.1 校验销售订单已审核 | |
| 76 | + ErpSaleOrderDO saleOrder = saleOrderService.validateSaleOrder(createReqVO.getOrderId()); | |
| 77 | + // 1.2 校验退货项的有效性 | |
| 78 | + List<ErpSaleReturnItemDO> saleReturnItems = validateSaleReturnItems(createReqVO.getItems()); | |
| 79 | + // 1.3 校验结算账户 | |
| 80 | + accountService.validateAccount(createReqVO.getAccountId()); | |
| 81 | + // 1.4 校验销售人员 | |
| 82 | + if (createReqVO.getSaleUserId() != null) { | |
| 83 | + adminUserApi.validateUser(createReqVO.getSaleUserId()); | |
| 84 | + } | |
| 85 | + // 1.5 生成调拨单号,并校验唯一性 | |
| 86 | + String no = noRedisDAO.generate(ErpNoRedisDAO.SALE_RETURN_NO_PREFIX); | |
| 87 | + if (saleReturnMapper.selectByNo(no) != null) { | |
| 88 | + throw exception(SALE_RETURN_NO_EXISTS); | |
| 89 | + } | |
| 90 | + | |
| 91 | + // 2.1 插入退货 | |
| 92 | + ErpSaleReturnDO saleReturn = BeanUtils.toBean(createReqVO, ErpSaleReturnDO.class, in -> in | |
| 93 | + .setNo(no).setStatus(ErpAuditStatus.PROCESS.getStatus())) | |
| 94 | + .setOrderNo(saleOrder.getNo()).setCustomerId(saleOrder.getCustomerId()); | |
| 95 | + calculateTotalPrice(saleReturn, saleReturnItems); | |
| 96 | + saleReturnMapper.insert(saleReturn); | |
| 97 | + // 2.2 插入退货项 | |
| 98 | + saleReturnItems.forEach(o -> o.setReturnId(saleReturn.getId())); | |
| 99 | + saleReturnItemMapper.insertBatch(saleReturnItems); | |
| 100 | + | |
| 101 | + // 3. 更新销售订单的退货数量 | |
| 102 | + updateSaleOrderReturnCount(createReqVO.getOrderId()); | |
| 103 | + return saleReturn.getId(); | |
| 104 | + } | |
| 105 | + | |
| 106 | + @Override | |
| 107 | + @Transactional(rollbackFor = Exception.class) | |
| 108 | + public void updateSaleReturn(ErpSaleReturnSaveReqVO updateReqVO) { | |
| 109 | + // 1.1 校验存在 | |
| 110 | + ErpSaleReturnDO saleReturn = validateSaleReturnExists(updateReqVO.getId()); | |
| 111 | + if (ErpAuditStatus.APPROVE.getStatus().equals(saleReturn.getStatus())) { | |
| 112 | + throw exception(SALE_RETURN_UPDATE_FAIL_APPROVE, saleReturn.getNo()); | |
| 113 | + } | |
| 114 | + // 1.2 校验销售订单已审核 | |
| 115 | + ErpSaleOrderDO saleOrder = saleOrderService.validateSaleOrder(updateReqVO.getOrderId()); | |
| 116 | + // 1.3 校验结算账户 | |
| 117 | + accountService.validateAccount(updateReqVO.getAccountId()); | |
| 118 | + // 1.4 校验销售人员 | |
| 119 | + if (updateReqVO.getSaleUserId() != null) { | |
| 120 | + adminUserApi.validateUser(updateReqVO.getSaleUserId()); | |
| 121 | + } | |
| 122 | + // 1.5 校验订单项的有效性 | |
| 123 | + List<ErpSaleReturnItemDO> saleReturnItems = validateSaleReturnItems(updateReqVO.getItems()); | |
| 124 | + | |
| 125 | + // 2.1 更新退货 | |
| 126 | + ErpSaleReturnDO updateObj = BeanUtils.toBean(updateReqVO, ErpSaleReturnDO.class) | |
| 127 | + .setOrderNo(saleOrder.getNo()).setCustomerId(saleOrder.getCustomerId()); | |
| 128 | + calculateTotalPrice(updateObj, saleReturnItems); | |
| 129 | + saleReturnMapper.updateById(updateObj); | |
| 130 | + // 2.2 更新退货项 | |
| 131 | + updateSaleReturnItemList(updateReqVO.getId(), saleReturnItems); | |
| 132 | + | |
| 133 | + // 3.1 更新销售订单的出库数量 | |
| 134 | + updateSaleOrderReturnCount(updateObj.getOrderId()); | |
| 135 | + // 3.2 注意:如果销售订单编号变更了,需要更新“老”销售订单的出库数量 | |
| 136 | + if (ObjectUtil.notEqual(saleReturn.getOrderId(), updateObj.getOrderId())) { | |
| 137 | + updateSaleOrderReturnCount(saleReturn.getOrderId()); | |
| 138 | + } | |
| 139 | + } | |
| 140 | + | |
| 141 | + private void calculateTotalPrice(ErpSaleReturnDO saleReturn, List<ErpSaleReturnItemDO> saleReturnItems) { | |
| 142 | + saleReturn.setTotalCount(getSumValue(saleReturnItems, ErpSaleReturnItemDO::getCount, BigDecimal::add)); | |
| 143 | + saleReturn.setTotalProductPrice(getSumValue(saleReturnItems, ErpSaleReturnItemDO::getTotalPrice, BigDecimal::add, BigDecimal.ZERO)); | |
| 144 | + saleReturn.setTotalTaxPrice(getSumValue(saleReturnItems, ErpSaleReturnItemDO::getTaxPrice, BigDecimal::add, BigDecimal.ZERO)); | |
| 145 | + saleReturn.setTotalPrice(saleReturn.getTotalProductPrice().add(saleReturn.getTotalTaxPrice())); | |
| 146 | + // 计算优惠价格 | |
| 147 | + if (saleReturn.getDiscountPercent() == null) { | |
| 148 | + saleReturn.setDiscountPercent(BigDecimal.ZERO); | |
| 149 | + } | |
| 150 | + saleReturn.setDiscountPrice(MoneyUtils.priceMultiplyPercent(saleReturn.getTotalPrice(), saleReturn.getDiscountPercent())); | |
| 151 | + saleReturn.setTotalPrice(saleReturn.getTotalPrice().subtract(saleReturn.getDiscountPrice())); | |
| 152 | + // 计算应退金额 | |
| 153 | + BigDecimal allPrice = saleReturn.getTotalPrice().add(saleReturn.getOtherPrice()); | |
| 154 | + saleReturn.setDebtPrice(allPrice.subtract(saleReturn.getRefundPrice())); | |
| 155 | + } | |
| 156 | + | |
| 157 | + private void updateSaleOrderReturnCount(Long orderId) { | |
| 158 | + // 1.1 查询销售订单对应的销售出库单列表 | |
| 159 | + List<ErpSaleReturnDO> saleReturns = saleReturnMapper.selectListByOrderId(orderId); | |
| 160 | + // 1.2 查询对应的销售订单项的出库数量 | |
| 161 | + Map<Long, BigDecimal> returnCountMap = saleReturnItemMapper.selectOrderItemCountSumMapByReturnIds( | |
| 162 | + convertList(saleReturns, ErpSaleReturnDO::getId)); | |
| 163 | + // 2. 更新销售订单的出库数量 | |
| 164 | + saleOrderService.updateSaleOrderReturnCount(orderId, returnCountMap); | |
| 165 | + } | |
| 166 | + | |
| 167 | + @Override | |
| 168 | + @Transactional(rollbackFor = Exception.class) | |
| 169 | + public void updateSaleReturnStatus(Long id, Integer status) { | |
| 170 | + boolean approve = ErpAuditStatus.APPROVE.getStatus().equals(status); | |
| 171 | + // 1.1 校验存在 | |
| 172 | + ErpSaleReturnDO saleReturn = validateSaleReturnExists(id); | |
| 173 | + // 1.2 校验状态 | |
| 174 | + if (saleReturn.getStatus().equals(status)) { | |
| 175 | + throw exception(approve ? SALE_RETURN_APPROVE_FAIL : SALE_RETURN_PROCESS_FAIL); | |
| 176 | + } | |
| 177 | + | |
| 178 | + // 2. 更新状态 | |
| 179 | + int updateCount = saleReturnMapper.updateByIdAndStatus(id, saleReturn.getStatus(), | |
| 180 | + new ErpSaleReturnDO().setStatus(status)); | |
| 181 | + if (updateCount == 0) { | |
| 182 | + throw exception(approve ? SALE_RETURN_APPROVE_FAIL : SALE_RETURN_PROCESS_FAIL); | |
| 183 | + } | |
| 184 | + | |
| 185 | + // 3. 变更库存 | |
| 186 | + List<ErpSaleReturnItemDO> saleReturnItems = saleReturnItemMapper.selectListByReturnId(id); | |
| 187 | + Integer bizType = approve ? ErpStockRecordBizTypeEnum.SALE_RETURN.getType() | |
| 188 | + : ErpStockRecordBizTypeEnum.SALE_RETURN_CANCEL.getType(); | |
| 189 | + saleReturnItems.forEach(saleReturnItem -> { | |
| 190 | + BigDecimal count = approve ? saleReturnItem.getCount().negate() : saleReturnItem.getCount(); | |
| 191 | + stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO( | |
| 192 | + saleReturnItem.getProductId(), saleReturnItem.getWarehouseId(), count, | |
| 193 | + bizType, saleReturnItem.getReturnId(), saleReturnItem.getId(), saleReturn.getNo())); | |
| 194 | + }); | |
| 195 | + } | |
| 196 | + | |
| 197 | + private List<ErpSaleReturnItemDO> validateSaleReturnItems(List<ErpSaleReturnSaveReqVO.Item> list) { | |
| 198 | + // 1. 校验产品存在 | |
| 199 | + List<ErpProductDO> productList = productService.validProductList( | |
| 200 | + convertSet(list, ErpSaleReturnSaveReqVO.Item::getProductId)); | |
| 201 | + Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId); | |
| 202 | + // 2. 转化为 ErpSaleReturnItemDO 列表 | |
| 203 | + return convertList(list, o -> BeanUtils.toBean(o, ErpSaleReturnItemDO.class, item -> { | |
| 204 | + item.setProductUnitId(productMap.get(item.getProductId()).getUnitId()); | |
| 205 | + item.setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount())); | |
| 206 | + if (item.getTotalPrice() == null) { | |
| 207 | + return; | |
| 208 | + } | |
| 209 | + if (item.getTaxPercent() == null) { | |
| 210 | + item.setTaxPercent(BigDecimal.ZERO); | |
| 211 | + } else { | |
| 212 | + item.setTaxPrice(MoneyUtils.priceMultiplyPercent(item.getTotalPrice(), item.getTaxPercent())); | |
| 213 | + } | |
| 214 | + })); | |
| 215 | + } | |
| 216 | + | |
| 217 | + private void updateSaleReturnItemList(Long id, List<ErpSaleReturnItemDO> newList) { | |
| 218 | + // 第一步,对比新老数据,获得添加、修改、删除的列表 | |
| 219 | + List<ErpSaleReturnItemDO> oldList = saleReturnItemMapper.selectListByReturnId(id); | |
| 220 | + List<List<ErpSaleReturnItemDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录 | |
| 221 | + (oldVal, newVal) -> oldVal.getId().equals(newVal.getId())); | |
| 222 | + | |
| 223 | + // 第二步,批量添加、修改、删除 | |
| 224 | + if (CollUtil.isNotEmpty(diffList.get(0))) { | |
| 225 | + diffList.get(0).forEach(o -> o.setReturnId(id)); | |
| 226 | + saleReturnItemMapper.insertBatch(diffList.get(0)); | |
| 227 | + } | |
| 228 | + if (CollUtil.isNotEmpty(diffList.get(1))) { | |
| 229 | + saleReturnItemMapper.updateBatch(diffList.get(1)); | |
| 230 | + } | |
| 231 | + if (CollUtil.isNotEmpty(diffList.get(2))) { | |
| 232 | + saleReturnItemMapper.deleteBatchIds(convertList(diffList.get(2), ErpSaleReturnItemDO::getId)); | |
| 233 | + } | |
| 234 | + } | |
| 235 | + | |
| 236 | + @Override | |
| 237 | + @Transactional(rollbackFor = Exception.class) | |
| 238 | + public void deleteSaleReturn(List<Long> ids) { | |
| 239 | + // 1. 校验不处于已审批 | |
| 240 | + List<ErpSaleReturnDO> saleReturns = saleReturnMapper.selectBatchIds(ids); | |
| 241 | + if (CollUtil.isEmpty(saleReturns)) { | |
| 242 | + return; | |
| 243 | + } | |
| 244 | + saleReturns.forEach(saleReturn -> { | |
| 245 | + if (ErpAuditStatus.APPROVE.getStatus().equals(saleReturn.getStatus())) { | |
| 246 | + throw exception(SALE_RETURN_DELETE_FAIL_APPROVE, saleReturn.getNo()); | |
| 247 | + } | |
| 248 | + }); | |
| 249 | + | |
| 250 | + // 2. 遍历删除,并记录操作日志 | |
| 251 | + saleReturns.forEach(saleReturn -> { | |
| 252 | + // 2.1 删除订单 | |
| 253 | + saleReturnMapper.deleteById(saleReturn.getId()); | |
| 254 | + // 2.2 删除订单项 | |
| 255 | + saleReturnItemMapper.deleteByReturnId(saleReturn.getId()); | |
| 256 | + | |
| 257 | + // 2.3 更新销售订单的出库数量 | |
| 258 | + updateSaleOrderReturnCount(saleReturn.getOrderId()); | |
| 259 | + }); | |
| 260 | + | |
| 261 | + } | |
| 262 | + | |
| 263 | + private ErpSaleReturnDO validateSaleReturnExists(Long id) { | |
| 264 | + ErpSaleReturnDO saleReturn = saleReturnMapper.selectById(id); | |
| 265 | + if (saleReturn == null) { | |
| 266 | + throw exception(SALE_RETURN_NOT_EXISTS); | |
| 267 | + } | |
| 268 | + return saleReturn; | |
| 269 | + } | |
| 270 | + | |
| 271 | + @Override | |
| 272 | + public ErpSaleReturnDO getSaleReturn(Long id) { | |
| 273 | + return saleReturnMapper.selectById(id); | |
| 274 | + } | |
| 275 | + | |
| 276 | + @Override | |
| 277 | + public PageResult<ErpSaleReturnDO> getSaleReturnPage(ErpSaleReturnPageReqVO pageReqVO) { | |
| 278 | + return saleReturnMapper.selectPage(pageReqVO); | |
| 279 | + } | |
| 280 | + | |
| 281 | + // ==================== 销售退货项 ==================== | |
| 282 | + | |
| 283 | + @Override | |
| 284 | + public List<ErpSaleReturnItemDO> getSaleReturnItemListByReturnId(Long returnId) { | |
| 285 | + return saleReturnItemMapper.selectListByReturnId(returnId); | |
| 286 | + } | |
| 287 | + | |
| 288 | + @Override | |
| 289 | + public List<ErpSaleReturnItemDO> getSaleReturnItemListByReturnIds(Collection<Long> returnIds) { | |
| 290 | + if (CollUtil.isEmpty(returnIds)) { | |
| 291 | + return Collections.emptyList(); | |
| 292 | + } | |
| 293 | + return saleReturnItemMapper.selectListByReturnIds(returnIds); | |
| 294 | + } | |
| 295 | + | |
| 296 | +} | |
| 0 | 297 | \ No newline at end of file | ... | ... |