Commit 2d02430768bcb5ad1bb8a7f251ccbeebc705768a
1 parent
62ef4b16
✨ ERP:采购出库 50%
Showing
18 changed files
with
1172 additions
and
9 deletions
yudao-module-erp/yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/enums/ErrorCodeConstants.java
| @@ -34,6 +34,14 @@ ErrorCode PURCHASE_ORDER_ITEM_RETURN_FAIL_IN_EXCEED = new ErrorCode(1_030_101_00 | @@ -34,6 +34,14 @@ ErrorCode PURCHASE_ORDER_ITEM_RETURN_FAIL_IN_EXCEED = new ErrorCode(1_030_101_00 | ||
| 34 | ErrorCode PURCHASE_IN_NO_EXISTS = new ErrorCode(1_030_102_004, "生成入库单失败,请重新提交"); | 34 | ErrorCode PURCHASE_IN_NO_EXISTS = new ErrorCode(1_030_102_004, "生成入库单失败,请重新提交"); |
| 35 | ErrorCode PURCHASE_IN_UPDATE_FAIL_APPROVE = new ErrorCode(1_030_102_005, "采购入库单({})已审核,无法修改"); | 35 | ErrorCode PURCHASE_IN_UPDATE_FAIL_APPROVE = new ErrorCode(1_030_102_005, "采购入库单({})已审核,无法修改"); |
| 36 | 36 | ||
| 37 | + // ========== ERP 采购退货(1-030-103-000) ========== | ||
| 38 | + ErrorCode PURCHASE_RETURN_NOT_EXISTS = new ErrorCode(1_030_103_000, "采购退货单不存在"); | ||
| 39 | + ErrorCode PURCHASE_RETURN_DELETE_FAIL_APPROVE = new ErrorCode(1_030_103_001, "采购退货单({})已审核,无法删除"); | ||
| 40 | + ErrorCode PURCHASE_RETURN_PROCESS_FAIL = new ErrorCode(1_030_103_002, "反审核失败,只有已审核的退货单才能反审核"); | ||
| 41 | + ErrorCode PURCHASE_RETURN_APPROVE_FAIL = new ErrorCode(1_030_103_003, "审核失败,只有未审核的退货单才能审核"); | ||
| 42 | + ErrorCode PURCHASE_RETURN_NO_EXISTS = new ErrorCode(1_030_103_004, "生成退货单失败,请重新提交"); | ||
| 43 | + ErrorCode PURCHASE_RETURN_UPDATE_FAIL_APPROVE = new ErrorCode(1_030_103_005, "采购退货单({})已审核,无法修改"); | ||
| 44 | + | ||
| 37 | // ========== ERP 客户(1-030-200-000)========== | 45 | // ========== ERP 客户(1-030-200-000)========== |
| 38 | ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(1_020_200_000, "客户不存在"); | 46 | ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(1_020_200_000, "客户不存在"); |
| 39 | ErrorCode CUSTOMER_NOT_ENABLE = new ErrorCode(1_020_200_001, "客户({})未启用"); | 47 | ErrorCode CUSTOMER_NOT_ENABLE = new ErrorCode(1_020_200_001, "客户({})未启用"); |
yudao-module-erp/yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/enums/stock/ErpStockRecordBizTypeEnum.java
| @@ -39,6 +39,9 @@ public enum ErpStockRecordBizTypeEnum implements IntArrayValuable { | @@ -39,6 +39,9 @@ public enum ErpStockRecordBizTypeEnum implements IntArrayValuable { | ||
| 39 | 39 | ||
| 40 | PURCHASE_IN(70, "采购入库"), | 40 | PURCHASE_IN(70, "采购入库"), |
| 41 | PURCHASE_IN_CANCEL(71, "采购入库(作废)"), | 41 | PURCHASE_IN_CANCEL(71, "采购入库(作废)"), |
| 42 | + | ||
| 43 | + PURCHASE_RETURN(80, "采购退货出库"), | ||
| 44 | + PURCHASE_RETURN_CANCEL(81, "采购退货出库(作废)"), | ||
| 42 | ; | 45 | ; |
| 43 | 46 | ||
| 44 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpStockRecordBizTypeEnum::getType).toArray(); | 47 | 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/purchase/ErpPurchaseReturnController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.purchase; | ||
| 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.purchase.vo.returns.ErpPurchaseReturnPageReqVO; | ||
| 13 | +import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.returns.ErpPurchaseReturnRespVO; | ||
| 14 | +import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.returns.ErpPurchaseReturnSaveReqVO; | ||
| 15 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnDO; | ||
| 16 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnItemDO; | ||
| 17 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpSupplierDO; | ||
| 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.purchase.ErpPurchaseReturnService; | ||
| 21 | +import cn.iocoder.yudao.module.erp.service.purchase.ErpSupplierService; | ||
| 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/purchase-return") | ||
| 48 | +@Validated | ||
| 49 | +public class ErpPurchaseReturnController { | ||
| 50 | + | ||
| 51 | + @Resource | ||
| 52 | + private ErpPurchaseReturnService purchaseReturnService; | ||
| 53 | + @Resource | ||
| 54 | + private ErpStockService stockService; | ||
| 55 | + @Resource | ||
| 56 | + private ErpProductService productService; | ||
| 57 | + @Resource | ||
| 58 | + private ErpSupplierService supplierService; | ||
| 59 | + | ||
| 60 | + @Resource | ||
| 61 | + private AdminUserApi adminUserApi; | ||
| 62 | + | ||
| 63 | + @PostMapping("/create") | ||
| 64 | + @Operation(summary = "创建采购退货") | ||
| 65 | + @PreAuthorize("@ss.hasPermission('erp:purchase-return:create')") | ||
| 66 | + public CommonResult<Long> createPurchaseReturn(@Valid @RequestBody ErpPurchaseReturnSaveReqVO createReqVO) { | ||
| 67 | + return success(purchaseReturnService.createPurchaseReturn(createReqVO)); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + @PutMapping("/update") | ||
| 71 | + @Operation(summary = "更新采购退货") | ||
| 72 | + @PreAuthorize("@ss.hasPermission('erp:purchase-return:update')") | ||
| 73 | + public CommonResult<Boolean> updatePurchaseReturn(@Valid @RequestBody ErpPurchaseReturnSaveReqVO updateReqVO) { | ||
| 74 | + purchaseReturnService.updatePurchaseReturn(updateReqVO); | ||
| 75 | + return success(true); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + @PutMapping("/update-status") | ||
| 79 | + @Operation(summary = "更新采购退货的状态") | ||
| 80 | + @PreAuthorize("@ss.hasPermission('erp:purchase-return:update-status')") | ||
| 81 | + public CommonResult<Boolean> updatePurchaseReturnStatus(@RequestParam("id") Long id, | ||
| 82 | + @RequestParam("status") Integer status) { | ||
| 83 | + purchaseReturnService.updatePurchaseReturnStatus(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:purchase-return:delete')") | ||
| 91 | + public CommonResult<Boolean> deletePurchaseReturn(@RequestParam("ids") List<Long> ids) { | ||
| 92 | + purchaseReturnService.deletePurchaseReturn(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:purchase-return:query')") | ||
| 100 | + public CommonResult<ErpPurchaseReturnRespVO> getPurchaseReturn(@RequestParam("id") Long id) { | ||
| 101 | + ErpPurchaseReturnDO purchaseReturn = purchaseReturnService.getPurchaseReturn(id); | ||
| 102 | + if (purchaseReturn == null) { | ||
| 103 | + return success(null); | ||
| 104 | + } | ||
| 105 | + List<ErpPurchaseReturnItemDO> purchaseReturnItemList = purchaseReturnService.getPurchaseReturnItemListByReturnId(id); | ||
| 106 | + Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap( | ||
| 107 | + convertSet(purchaseReturnItemList, ErpPurchaseReturnItemDO::getProductId)); | ||
| 108 | + return success(BeanUtils.toBean(purchaseReturn, ErpPurchaseReturnRespVO.class, purchaseReturnVO -> | ||
| 109 | + purchaseReturnVO.setItems(BeanUtils.toBean(purchaseReturnItemList, ErpPurchaseReturnRespVO.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:purchase-return:query')") | ||
| 120 | + public CommonResult<PageResult<ErpPurchaseReturnRespVO>> getPurchaseReturnPage(@Valid ErpPurchaseReturnPageReqVO pageReqVO) { | ||
| 121 | + PageResult<ErpPurchaseReturnDO> pageResult = purchaseReturnService.getPurchaseReturnPage(pageReqVO); | ||
| 122 | + return success(buildPurchaseReturnVOPageResult(pageResult)); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + @GetMapping("/export-excel") | ||
| 126 | + @Operation(summary = "导出采购退货 Excel") | ||
| 127 | + @PreAuthorize("@ss.hasPermission('erp:purchase-return:export')") | ||
| 128 | + @OperateLog(type = EXPORT) | ||
| 129 | + public void exportPurchaseReturnExcel(@Valid ErpPurchaseReturnPageReqVO pageReqVO, | ||
| 130 | + HttpServletResponse response) throws IOException { | ||
| 131 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | ||
| 132 | + List<ErpPurchaseReturnRespVO> list = buildPurchaseReturnVOPageResult(purchaseReturnService.getPurchaseReturnPage(pageReqVO)).getList(); | ||
| 133 | + // 导出 Excel | ||
| 134 | + ExcelUtils.write(response, "采购退货.xls", "数据", ErpPurchaseReturnRespVO.class, list); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + private PageResult<ErpPurchaseReturnRespVO> buildPurchaseReturnVOPageResult(PageResult<ErpPurchaseReturnDO> pageResult) { | ||
| 138 | + if (CollUtil.isEmpty(pageResult.getList())) { | ||
| 139 | + return PageResult.empty(pageResult.getTotal()); | ||
| 140 | + } | ||
| 141 | + // 1.1 退货项 | ||
| 142 | + List<ErpPurchaseReturnItemDO> purchaseReturnItemList = purchaseReturnService.getPurchaseReturnItemListByReturnIds( | ||
| 143 | + convertSet(pageResult.getList(), ErpPurchaseReturnDO::getId)); | ||
| 144 | + Map<Long, List<ErpPurchaseReturnItemDO>> purchaseReturnItemMap = convertMultiMap(purchaseReturnItemList, ErpPurchaseReturnItemDO::getReturnId); | ||
| 145 | + // 1.2 产品信息 | ||
| 146 | + Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap( | ||
| 147 | + convertSet(purchaseReturnItemList, ErpPurchaseReturnItemDO::getProductId)); | ||
| 148 | + // 1.3 供应商信息 | ||
| 149 | + Map<Long, ErpSupplierDO> supplierMap = supplierService.getSupplierMap( | ||
| 150 | + convertSet(pageResult.getList(), ErpPurchaseReturnDO::getSupplierId)); | ||
| 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, ErpPurchaseReturnRespVO.class, purchaseReturn -> { | ||
| 156 | + purchaseReturn.setItems(BeanUtils.toBean(purchaseReturnItemMap.get(purchaseReturn.getId()), ErpPurchaseReturnRespVO.Item.class, | ||
| 157 | + item -> MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName()) | ||
| 158 | + .setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName())))); | ||
| 159 | + purchaseReturn.setProductNames(CollUtil.join(purchaseReturn.getItems(), ",", ErpPurchaseReturnRespVO.Item::getProductName)); | ||
| 160 | + MapUtils.findAndThen(supplierMap, purchaseReturn.getSupplierId(), supplier -> purchaseReturn.setSupplierName(supplier.getName())); | ||
| 161 | + MapUtils.findAndThen(userMap, Long.parseLong(purchaseReturn.getCreator()), user -> purchaseReturn.setCreatorName(user.getNickname())); | ||
| 162 | + }); | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | +} | ||
| 0 | \ No newline at end of file | 166 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/purchase/vo/returns/ErpPurchaseReturnPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.purchase.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 ErpPurchaseReturnPageReqVO extends PageParam { | ||
| 19 | + | ||
| 20 | + @Schema(description = "采购单编号", example = "XS001") | ||
| 21 | + private String no; | ||
| 22 | + | ||
| 23 | + @Schema(description = "供应商编号", example = "1724") | ||
| 24 | + private Long supplierId; | ||
| 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 | \ No newline at end of file | 52 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/purchase/vo/returns/ErpPurchaseReturnRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.purchase.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 ErpPurchaseReturnRespVO { | ||
| 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 supplierId; | ||
| 32 | + @Schema(description = "供应商名称", example = "芋道") | ||
| 33 | + @ExcelProperty("供应商名称") | ||
| 34 | + private String supplierName; | ||
| 35 | + | ||
| 36 | + @Schema(description = "结算账户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "311.89") | ||
| 37 | + @ExcelProperty("结算账户编号") | ||
| 38 | + private Long accountId; | ||
| 39 | + | ||
| 40 | + @Schema(description = "退货时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 41 | + @ExcelProperty("退货时间") | ||
| 42 | + private LocalDateTime returnTime; | ||
| 43 | + | ||
| 44 | + @Schema(description = "采购订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386") | ||
| 45 | + private Long orderId; | ||
| 46 | + @Schema(description = "采购订单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "XS001") | ||
| 47 | + private String orderNo; | ||
| 48 | + | ||
| 49 | + @Schema(description = "合计数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15663") | ||
| 50 | + @ExcelProperty("合计数量") | ||
| 51 | + private BigDecimal totalCount; | ||
| 52 | + @Schema(description = "最终合计价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "24906") | ||
| 53 | + @ExcelProperty("最终合计价格") | ||
| 54 | + private BigDecimal totalPrice; | ||
| 55 | + | ||
| 56 | + @Schema(description = "合计产品价格,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127") | ||
| 57 | + private BigDecimal totalProductPrice; | ||
| 58 | + | ||
| 59 | + @Schema(description = "合计税额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127") | ||
| 60 | + private BigDecimal totalTaxPrice; | ||
| 61 | + | ||
| 62 | + @Schema(description = "优惠率,百分比", requiredMode = Schema.RequiredMode.REQUIRED, example = "99.88") | ||
| 63 | + private BigDecimal discountPercent; | ||
| 64 | + | ||
| 65 | + @Schema(description = "优惠金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127") | ||
| 66 | + private BigDecimal discountPrice; | ||
| 67 | + | ||
| 68 | + @Schema(description = "定金金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127") | ||
| 69 | + private BigDecimal otherPrice; | ||
| 70 | + | ||
| 71 | + @Schema(description = "本次退款,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127") | ||
| 72 | + private BigDecimal refundPrice; | ||
| 73 | + @Schema(description = "本次欠款,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "666") | ||
| 74 | + private BigDecimal debtPrice; | ||
| 75 | + | ||
| 76 | + @Schema(description = "附件地址", example = "https://www.iocoder.cn") | ||
| 77 | + @ExcelProperty("附件地址") | ||
| 78 | + private String fileUrl; | ||
| 79 | + | ||
| 80 | + @Schema(description = "备注", example = "你猜") | ||
| 81 | + @ExcelProperty("备注") | ||
| 82 | + private String remark; | ||
| 83 | + | ||
| 84 | + @Schema(description = "创建人", example = "芋道") | ||
| 85 | + private String creator; | ||
| 86 | + @Schema(description = "创建人名称", example = "芋道") | ||
| 87 | + private String creatorName; | ||
| 88 | + | ||
| 89 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 90 | + @ExcelProperty("创建时间") | ||
| 91 | + private LocalDateTime createTime; | ||
| 92 | + | ||
| 93 | + @Schema(description = "退货项列表", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 94 | + private List<Item> items; | ||
| 95 | + | ||
| 96 | + @Schema(description = "产品信息", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 97 | + @ExcelProperty("产品信息") | ||
| 98 | + private String productNames; | ||
| 99 | + | ||
| 100 | + @Data | ||
| 101 | + public static class Item { | ||
| 102 | + | ||
| 103 | + @Schema(description = "退货项编号", example = "11756") | ||
| 104 | + private Long id; | ||
| 105 | + | ||
| 106 | + @Schema(description = "采购订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756") | ||
| 107 | + private Long orderItemId; | ||
| 108 | + | ||
| 109 | + @Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | ||
| 110 | + private Long warehouseId; | ||
| 111 | + | ||
| 112 | + @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | ||
| 113 | + private Long productId; | ||
| 114 | + | ||
| 115 | + @Schema(description = "产品单位单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | ||
| 116 | + private Long productUnitId; | ||
| 117 | + | ||
| 118 | + @Schema(description = "产品单价", example = "100.00") | ||
| 119 | + private BigDecimal productPrice; | ||
| 120 | + | ||
| 121 | + @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | ||
| 122 | + @NotNull(message = "产品数量不能为空") | ||
| 123 | + private BigDecimal count; | ||
| 124 | + | ||
| 125 | + @Schema(description = "税率,百分比", example = "99.88") | ||
| 126 | + private BigDecimal taxPercent; | ||
| 127 | + | ||
| 128 | + @Schema(description = "税额,单位:元", example = "100.00") | ||
| 129 | + private BigDecimal taxPrice; | ||
| 130 | + | ||
| 131 | + @Schema(description = "备注", example = "随便") | ||
| 132 | + private String remark; | ||
| 133 | + | ||
| 134 | + // ========== 关联字段 ========== | ||
| 135 | + | ||
| 136 | + @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "巧克力") | ||
| 137 | + private String productName; | ||
| 138 | + @Schema(description = "产品条码", requiredMode = Schema.RequiredMode.REQUIRED, example = "A9985") | ||
| 139 | + private String productBarCode; | ||
| 140 | + @Schema(description = "产品单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "盒") | ||
| 141 | + private String productUnitName; | ||
| 142 | + | ||
| 143 | + @Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | ||
| 144 | + private BigDecimal stockCount; // 该字段仅仅在“详情”和“编辑”时使用 | ||
| 145 | + | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | +} | ||
| 0 | \ No newline at end of file | 149 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/purchase/vo/returns/ErpPurchaseReturnSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.purchase.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 ErpPurchaseReturnSaveReqVO { | ||
| 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 = "退货时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 22 | + @NotNull(message = "退货时间不能为空") | ||
| 23 | + private LocalDateTime returnTime; | ||
| 24 | + | ||
| 25 | + @Schema(description = "采购订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386") | ||
| 26 | + @NotNull(message = "采购订单编号不能为空") | ||
| 27 | + private Long orderId; | ||
| 28 | + | ||
| 29 | + @Schema(description = "优惠率,百分比", requiredMode = Schema.RequiredMode.REQUIRED, example = "99.88") | ||
| 30 | + private BigDecimal discountPercent; | ||
| 31 | + | ||
| 32 | + @Schema(description = "其它金额,单位:元", example = "7127") | ||
| 33 | + private BigDecimal otherPrice; | ||
| 34 | + | ||
| 35 | + @Schema(description = "本次退款,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127") | ||
| 36 | + @NotNull(message = "本次退款不能为空") | ||
| 37 | + private BigDecimal refundPrice; | ||
| 38 | + | ||
| 39 | + @Schema(description = "附件地址", example = "https://www.iocoder.cn") | ||
| 40 | + private String fileUrl; | ||
| 41 | + | ||
| 42 | + @Schema(description = "备注", example = "你猜") | ||
| 43 | + private String remark; | ||
| 44 | + | ||
| 45 | + @Schema(description = "退货清单列表") | ||
| 46 | + private List<Item> items; | ||
| 47 | + | ||
| 48 | + @Data | ||
| 49 | + public static class Item { | ||
| 50 | + | ||
| 51 | + @Schema(description = "退货项编号", example = "11756") | ||
| 52 | + private Long id; | ||
| 53 | + | ||
| 54 | + @Schema(description = "采购订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756") | ||
| 55 | + @NotNull(message = "采购订单项编号不能为空") | ||
| 56 | + private Long orderItemId; | ||
| 57 | + | ||
| 58 | + @Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | ||
| 59 | + @NotNull(message = "仓库编号不能为空") | ||
| 60 | + private Long warehouseId; | ||
| 61 | + | ||
| 62 | + @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | ||
| 63 | + @NotNull(message = "产品编号不能为空") | ||
| 64 | + private Long productId; | ||
| 65 | + | ||
| 66 | + @Schema(description = "产品单位单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | ||
| 67 | + @NotNull(message = "产品单位单位不能为空") | ||
| 68 | + private Long productUnitId; | ||
| 69 | + | ||
| 70 | + @Schema(description = "产品单价", example = "100.00") | ||
| 71 | + private BigDecimal productPrice; | ||
| 72 | + | ||
| 73 | + @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | ||
| 74 | + @NotNull(message = "产品数量不能为空") | ||
| 75 | + private BigDecimal count; | ||
| 76 | + | ||
| 77 | + @Schema(description = "税率,百分比", example = "99.88") | ||
| 78 | + private BigDecimal taxPercent; | ||
| 79 | + | ||
| 80 | + @Schema(description = "备注", example = "随便") | ||
| 81 | + private String remark; | ||
| 82 | + | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | +} | ||
| 0 | \ No newline at end of file | 86 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/purchase/ErpPurchaseInDO.java
| @@ -31,7 +31,7 @@ public class ErpPurchaseInDO extends BaseDO { | @@ -31,7 +31,7 @@ public class ErpPurchaseInDO extends BaseDO { | ||
| 31 | @TableId | 31 | @TableId |
| 32 | private Long id; | 32 | private Long id; |
| 33 | /** | 33 | /** |
| 34 | - * 销售入库单号 | 34 | + * 采购入库单号 |
| 35 | */ | 35 | */ |
| 36 | private String no; | 36 | private String no; |
| 37 | /** | 37 | /** |
| @@ -105,7 +105,7 @@ public class ErpPurchaseInDO extends BaseDO { | @@ -105,7 +105,7 @@ public class ErpPurchaseInDO extends BaseDO { | ||
| 105 | private BigDecimal otherPrice; | 105 | private BigDecimal otherPrice; |
| 106 | 106 | ||
| 107 | /** | 107 | /** |
| 108 | - * 本次收款,单位:元 | 108 | + * 本次退款,单位:元 |
| 109 | * | 109 | * |
| 110 | * refundPrice = totalPrice + otherPrice - debtPrice | 110 | * refundPrice = totalPrice + otherPrice - debtPrice |
| 111 | */ | 111 | */ |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/purchase/ErpPurchaseReturnDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.dal.dataobject.purchase; | ||
| 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_purchase_return") | ||
| 19 | +@KeySequence("erp_purchase_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 ErpPurchaseReturnDO 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 ErpSupplierDO#getId()} | ||
| 47 | + */ | ||
| 48 | + private Long supplierId; | ||
| 49 | + /** | ||
| 50 | + * 结算账户编号 | ||
| 51 | + * | ||
| 52 | + * 关联 {@link ErpAccountDO#getId()} | ||
| 53 | + */ | ||
| 54 | + private Long accountId; | ||
| 55 | + /** | ||
| 56 | + * 退货时间 | ||
| 57 | + */ | ||
| 58 | + private LocalDateTime returnTime; | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 采购订单编号 | ||
| 62 | + * | ||
| 63 | + * 关联 {@link ErpPurchaseOrderDO#getId()} | ||
| 64 | + */ | ||
| 65 | + private Long orderId; | ||
| 66 | + /** | ||
| 67 | + * 采购订单号 | ||
| 68 | + * | ||
| 69 | + * 冗余 {@link ErpPurchaseOrderDO#getNo()} | ||
| 70 | + */ | ||
| 71 | + private String orderNo; | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * 合计数量 | ||
| 75 | + */ | ||
| 76 | + private BigDecimal totalCount; | ||
| 77 | + /** | ||
| 78 | + * 最终合计价格,单位:元 | ||
| 79 | + * | ||
| 80 | + * totalPrice = totalProductPrice + totalTaxPrice - discountPrice | ||
| 81 | + */ | ||
| 82 | + private BigDecimal totalPrice; | ||
| 83 | + | ||
| 84 | + /** | ||
| 85 | + * 合计产品价格,单位:元 | ||
| 86 | + */ | ||
| 87 | + private BigDecimal totalProductPrice; | ||
| 88 | + /** | ||
| 89 | + * 合计税额,单位:元 | ||
| 90 | + */ | ||
| 91 | + private BigDecimal totalTaxPrice; | ||
| 92 | + /** | ||
| 93 | + * 优惠率,百分比 | ||
| 94 | + */ | ||
| 95 | + private BigDecimal discountPercent; | ||
| 96 | + /** | ||
| 97 | + * 优惠金额,单位:元 | ||
| 98 | + * | ||
| 99 | + * discountPrice = (totalProductPrice + totalTaxPrice) * discountPercent | ||
| 100 | + */ | ||
| 101 | + private BigDecimal discountPrice; | ||
| 102 | + /** | ||
| 103 | + * 其它金额,单位:元 | ||
| 104 | + */ | ||
| 105 | + private BigDecimal otherPrice; | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * 本次退款,单位:元 | ||
| 109 | + * | ||
| 110 | + * refundPrice = totalPrice + otherPrice - debtPrice | ||
| 111 | + */ | ||
| 112 | + private BigDecimal refundPrice; | ||
| 113 | + /** | ||
| 114 | + * 本次欠款,单位:元 | ||
| 115 | + */ | ||
| 116 | + private BigDecimal debtPrice; | ||
| 117 | + | ||
| 118 | + /** | ||
| 119 | + * 附件地址 | ||
| 120 | + */ | ||
| 121 | + private String fileUrl; | ||
| 122 | + /** | ||
| 123 | + * 备注 | ||
| 124 | + */ | ||
| 125 | + private String remark; | ||
| 126 | + | ||
| 127 | +} | ||
| 0 | \ No newline at end of file | 128 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/purchase/ErpPurchaseReturnItemDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.dal.dataobject.purchase; | ||
| 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_purchase_return_items") | ||
| 19 | +@KeySequence("erp_purchase_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 ErpPurchaseReturnItemDO extends BaseDO { | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 编号 | ||
| 30 | + */ | ||
| 31 | + @TableId | ||
| 32 | + private Long id; | ||
| 33 | + /** | ||
| 34 | + * 采购退货编号 | ||
| 35 | + * | ||
| 36 | + * 关联 {@link ErpPurchaseReturnDO##getId()} | ||
| 37 | + */ | ||
| 38 | + private Long returnId; | ||
| 39 | + /** | ||
| 40 | + * 采购订单项编号 | ||
| 41 | + * | ||
| 42 | + * 关联 {@link ErpPurchaseOrderItemDO#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 | \ No newline at end of file | 96 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/purchase/ErpPurchaseInItemMapper.java
| @@ -35,10 +35,10 @@ public interface ErpPurchaseInItemMapper extends BaseMapperX<ErpPurchaseInItemDO | @@ -35,10 +35,10 @@ public interface ErpPurchaseInItemMapper extends BaseMapperX<ErpPurchaseInItemDO | ||
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | /** | 37 | /** |
| 38 | - * 基于销售订单编号,查询每个销售订单项的入库数量之和 | 38 | + * 基于采购订单编号,查询每个采购订单项的入库数量之和 |
| 39 | * | 39 | * |
| 40 | * @param inIds 入库订单项编号数组 | 40 | * @param inIds 入库订单项编号数组 |
| 41 | - * @return key:销售订单项编号;value:入库数量之和 | 41 | + * @return key:采购订单项编号;value:入库数量之和 |
| 42 | */ | 42 | */ |
| 43 | default Map<Long, BigDecimal> selectOrderItemCountSumMapByInIds(Collection<Long> inIds) { | 43 | default Map<Long, BigDecimal> selectOrderItemCountSumMapByInIds(Collection<Long> inIds) { |
| 44 | if (CollUtil.isEmpty(inIds)) { | 44 | if (CollUtil.isEmpty(inIds)) { |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/purchase/ErpPurchaseOrderMapper.java
| @@ -45,7 +45,7 @@ public interface ErpPurchaseOrderMapper extends BaseMapperX<ErpPurchaseOrderDO> | @@ -45,7 +45,7 @@ public interface ErpPurchaseOrderMapper extends BaseMapperX<ErpPurchaseOrderDO> | ||
| 45 | } else if (Objects.equals(reqVO.getReturnStatus(), ErpPurchaseOrderPageReqVO.RETURN_STATUS_ALL)) { | 45 | } else if (Objects.equals(reqVO.getReturnStatus(), ErpPurchaseOrderPageReqVO.RETURN_STATUS_ALL)) { |
| 46 | query.apply("t.return_count = t.total_count"); | 46 | query.apply("t.return_count = t.total_count"); |
| 47 | } | 47 | } |
| 48 | - // 可采购出库 | 48 | + // 可采购入库 |
| 49 | if (Boolean.TRUE.equals(reqVO.getInEnable())) { | 49 | if (Boolean.TRUE.equals(reqVO.getInEnable())) { |
| 50 | query.eq(ErpPurchaseOrderDO::getStatus, ErpAuditStatus.APPROVE.getStatus()) | 50 | query.eq(ErpPurchaseOrderDO::getStatus, ErpAuditStatus.APPROVE.getStatus()) |
| 51 | .apply("t.in_count < t.total_count"); | 51 | .apply("t.in_count < t.total_count"); |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/purchase/ErpPurchaseReturnItemMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.dal.mysql.purchase; | ||
| 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.purchase.ErpPurchaseReturnItemDO; | ||
| 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 ErpPurchaseReturnItemMapper extends BaseMapperX<ErpPurchaseReturnItemDO> { | ||
| 24 | + | ||
| 25 | + default List<ErpPurchaseReturnItemDO> selectListByReturnId(Long returnId) { | ||
| 26 | + return selectList(ErpPurchaseReturnItemDO::getReturnId, returnId); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + default List<ErpPurchaseReturnItemDO> selectListByReturnIds(Collection<Long> returnIds) { | ||
| 30 | + return selectList(ErpPurchaseReturnItemDO::getReturnId, returnIds); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + default int deleteByReturnId(Long returnId) { | ||
| 34 | + return delete(ErpPurchaseReturnItemDO::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<ErpPurchaseReturnItemDO>() | ||
| 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 | \ No newline at end of file | 57 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/purchase/ErpPurchaseReturnMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.dal.mysql.purchase; | ||
| 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.MPJLambdaWrapperX; | ||
| 6 | +import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.returns.ErpPurchaseReturnPageReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnDO; | ||
| 8 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnItemDO; | ||
| 9 | +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | ||
| 10 | +import org.apache.ibatis.annotations.Mapper; | ||
| 11 | + | ||
| 12 | +import java.util.List; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * ERP 采购退货 Mapper | ||
| 16 | + * | ||
| 17 | + * @author 芋道源码 | ||
| 18 | + */ | ||
| 19 | +@Mapper | ||
| 20 | +public interface ErpPurchaseReturnMapper extends BaseMapperX<ErpPurchaseReturnDO> { | ||
| 21 | + | ||
| 22 | + default PageResult<ErpPurchaseReturnDO> selectPage(ErpPurchaseReturnPageReqVO reqVO) { | ||
| 23 | + MPJLambdaWrapperX<ErpPurchaseReturnDO> query = new MPJLambdaWrapperX<ErpPurchaseReturnDO>() | ||
| 24 | + .likeIfPresent(ErpPurchaseReturnDO::getNo, reqVO.getNo()) | ||
| 25 | + .eqIfPresent(ErpPurchaseReturnDO::getSupplierId, reqVO.getSupplierId()) | ||
| 26 | + .betweenIfPresent(ErpPurchaseReturnDO::getReturnTime, reqVO.getReturnTime()) | ||
| 27 | + .eqIfPresent(ErpPurchaseReturnDO::getStatus, reqVO.getStatus()) | ||
| 28 | + .likeIfPresent(ErpPurchaseReturnDO::getRemark, reqVO.getRemark()) | ||
| 29 | + .eqIfPresent(ErpPurchaseReturnDO::getCreator, reqVO.getCreator()) | ||
| 30 | + .eqIfPresent(ErpPurchaseReturnDO::getAccountId, reqVO.getAccountId()) | ||
| 31 | + .likeIfPresent(ErpPurchaseReturnDO::getOrderNo, reqVO.getOrderNo()) | ||
| 32 | + .orderByDesc(ErpPurchaseReturnDO::getId); | ||
| 33 | + if (reqVO.getWarehouseId() != null || reqVO.getProductId() != null) { | ||
| 34 | + query.leftJoin(ErpPurchaseReturnItemDO.class, ErpPurchaseReturnItemDO::getReturnId, ErpPurchaseReturnDO::getId) | ||
| 35 | + .eq(reqVO.getWarehouseId() != null, ErpPurchaseReturnItemDO::getWarehouseId, reqVO.getWarehouseId()) | ||
| 36 | + .eq(reqVO.getProductId() != null, ErpPurchaseReturnItemDO::getProductId, reqVO.getProductId()) | ||
| 37 | + .groupBy(ErpPurchaseReturnDO::getId); // 避免 1 对多查询,产生相同的 1 | ||
| 38 | + } | ||
| 39 | + return selectJoinPage(reqVO, ErpPurchaseReturnDO.class, query); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + default int updateByIdAndStatus(Long id, Integer status, ErpPurchaseReturnDO updateObj) { | ||
| 43 | + return update(updateObj, new LambdaUpdateWrapper<ErpPurchaseReturnDO>() | ||
| 44 | + .eq(ErpPurchaseReturnDO::getId, id).eq(ErpPurchaseReturnDO::getStatus, status)); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + default ErpPurchaseReturnDO selectByNo(String no) { | ||
| 48 | + return selectOne(ErpPurchaseReturnDO::getNo, no); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + default List<ErpPurchaseReturnDO> selectListByOrderId(Long orderId) { | ||
| 52 | + return selectList(ErpPurchaseReturnDO::getOrderId, orderId); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | +} | ||
| 0 | \ No newline at end of file | 56 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/sale/ErpSaleReturnItemMapper.java
| @@ -35,10 +35,10 @@ public interface ErpSaleReturnItemMapper extends BaseMapperX<ErpSaleReturnItemDO | @@ -35,10 +35,10 @@ public interface ErpSaleReturnItemMapper extends BaseMapperX<ErpSaleReturnItemDO | ||
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | /** | 37 | /** |
| 38 | - * 基于销售订单编号,查询每个销售订单项的出库数量之和 | 38 | + * 基于销售订单编号,查询每个销售订单项的退货数量之和 |
| 39 | * | 39 | * |
| 40 | * @param returnIds 出库订单项编号数组 | 40 | * @param returnIds 出库订单项编号数组 |
| 41 | - * @return key:销售订单项编号;value:出库数量之和 | 41 | + * @return key:销售订单项编号;value:退货数量之和 |
| 42 | */ | 42 | */ |
| 43 | default Map<Long, BigDecimal> selectOrderItemCountSumMapByReturnIds(Collection<Long> returnIds) { | 43 | default Map<Long, BigDecimal> selectOrderItemCountSumMapByReturnIds(Collection<Long> returnIds) { |
| 44 | if (CollUtil.isEmpty(returnIds)) { | 44 | if (CollUtil.isEmpty(returnIds)) { |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/redis/no/ErpNoRedisDAO.java
| @@ -59,6 +59,10 @@ public class ErpNoRedisDAO { | @@ -59,6 +59,10 @@ public class ErpNoRedisDAO { | ||
| 59 | * 采购入库 {@link cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInDO} | 59 | * 采购入库 {@link cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInDO} |
| 60 | */ | 60 | */ |
| 61 | public static final String PURCHASE_IN_NO_PREFIX = "CGRK"; | 61 | public static final String PURCHASE_IN_NO_PREFIX = "CGRK"; |
| 62 | + /** | ||
| 63 | + * 采购退货 {@link cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnDO} | ||
| 64 | + */ | ||
| 65 | + public static final String PURCHASE_RETURN_NO_PREFIX = "CGTH"; | ||
| 62 | 66 | ||
| 63 | @Resource | 67 | @Resource |
| 64 | private StringRedisTemplate stringRedisTemplate; | 68 | private StringRedisTemplate stringRedisTemplate; |
| @@ -76,7 +80,7 @@ public class ErpNoRedisDAO { | @@ -76,7 +80,7 @@ public class ErpNoRedisDAO { | ||
| 76 | String key = RedisKeyConstants.NO + noPrefix; | 80 | String key = RedisKeyConstants.NO + noPrefix; |
| 77 | Long no = stringRedisTemplate.opsForValue().increment(key); | 81 | Long no = stringRedisTemplate.opsForValue().increment(key); |
| 78 | // 设置过期时间 | 82 | // 设置过期时间 |
| 79 | - stringRedisTemplate.expire(key, Duration.ofMinutes(1L)); | 83 | + stringRedisTemplate.expire(key, Duration.ofDays(1L)); |
| 80 | return noPrefix + String.format("%06d", no); | 84 | return noPrefix + String.format("%06d", no); |
| 81 | } | 85 | } |
| 82 | 86 |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/purchase/ErpPurchaseReturnService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.service.purchase; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | +import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.returns.ErpPurchaseReturnPageReqVO; | ||
| 5 | +import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.returns.ErpPurchaseReturnSaveReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnDO; | ||
| 7 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnItemDO; | ||
| 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 ErpPurchaseReturnService { | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 创建采购退货 | ||
| 22 | + * | ||
| 23 | + * @param createReqVO 创建信息 | ||
| 24 | + * @return 编号 | ||
| 25 | + */ | ||
| 26 | + Long createPurchaseReturn(@Valid ErpPurchaseReturnSaveReqVO createReqVO); | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 更新采购退货 | ||
| 30 | + * | ||
| 31 | + * @param updateReqVO 更新信息 | ||
| 32 | + */ | ||
| 33 | + void updatePurchaseReturn(@Valid ErpPurchaseReturnSaveReqVO updateReqVO); | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * 更新采购退货的状态 | ||
| 37 | + * | ||
| 38 | + * @param id 编号 | ||
| 39 | + * @param status 状态 | ||
| 40 | + */ | ||
| 41 | + void updatePurchaseReturnStatus(Long id, Integer status); | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * 删除采购退货 | ||
| 45 | + * | ||
| 46 | + * @param ids 编号数组 | ||
| 47 | + */ | ||
| 48 | + void deletePurchaseReturn(List<Long> ids); | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * 获得采购退货 | ||
| 52 | + * | ||
| 53 | + * @param id 编号 | ||
| 54 | + * @return 采购退货 | ||
| 55 | + */ | ||
| 56 | + ErpPurchaseReturnDO getPurchaseReturn(Long id); | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * 获得采购退货分页 | ||
| 60 | + * | ||
| 61 | + * @param pageReqVO 分页查询 | ||
| 62 | + * @return 采购退货分页 | ||
| 63 | + */ | ||
| 64 | + PageResult<ErpPurchaseReturnDO> getPurchaseReturnPage(ErpPurchaseReturnPageReqVO pageReqVO); | ||
| 65 | + | ||
| 66 | + // ==================== 采购退货项 ==================== | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * 获得采购退货项列表 | ||
| 70 | + * | ||
| 71 | + * @param returnId 采购退货编号 | ||
| 72 | + * @return 采购退货项列表 | ||
| 73 | + */ | ||
| 74 | + List<ErpPurchaseReturnItemDO> getPurchaseReturnItemListByReturnId(Long returnId); | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * 获得采购退货项 List | ||
| 78 | + * | ||
| 79 | + * @param returnIds 采购退货编号数组 | ||
| 80 | + * @return 采购退货项 List | ||
| 81 | + */ | ||
| 82 | + List<ErpPurchaseReturnItemDO> getPurchaseReturnItemListByReturnIds(Collection<Long> returnIds); | ||
| 83 | + | ||
| 84 | +} | ||
| 0 | \ No newline at end of file | 85 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/purchase/ErpPurchaseReturnServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.service.purchase; | ||
| 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.purchase.vo.returns.ErpPurchaseReturnPageReqVO; | ||
| 9 | +import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.returns.ErpPurchaseReturnSaveReqVO; | ||
| 10 | +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO; | ||
| 11 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseOrderDO; | ||
| 12 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnDO; | ||
| 13 | +import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnItemDO; | ||
| 14 | +import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpPurchaseReturnItemMapper; | ||
| 15 | +import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpPurchaseReturnMapper; | ||
| 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 jakarta.annotation.Resource; | ||
| 24 | +import org.springframework.context.annotation.Lazy; | ||
| 25 | +import org.springframework.stereotype.Service; | ||
| 26 | +import org.springframework.transaction.annotation.Transactional; | ||
| 27 | +import org.springframework.validation.annotation.Validated; | ||
| 28 | + | ||
| 29 | +import java.math.BigDecimal; | ||
| 30 | +import java.util.Collection; | ||
| 31 | +import java.util.Collections; | ||
| 32 | +import java.util.List; | ||
| 33 | +import java.util.Map; | ||
| 34 | + | ||
| 35 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 36 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; | ||
| 37 | +import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*; | ||
| 38 | + | ||
| 39 | +// TODO 芋艿:记录操作日志 | ||
| 40 | + | ||
| 41 | +/** | ||
| 42 | + * ERP 采购退货 Service 实现类 | ||
| 43 | + * | ||
| 44 | + * @author 芋道源码 | ||
| 45 | + */ | ||
| 46 | +@Service | ||
| 47 | +@Validated | ||
| 48 | +public class ErpPurchaseReturnServiceImpl implements ErpPurchaseReturnService { | ||
| 49 | + | ||
| 50 | + @Resource | ||
| 51 | + private ErpPurchaseReturnMapper purchaseReturnMapper; | ||
| 52 | + @Resource | ||
| 53 | + private ErpPurchaseReturnItemMapper purchaseReturnItemMapper; | ||
| 54 | + | ||
| 55 | + @Resource | ||
| 56 | + private ErpNoRedisDAO noRedisDAO; | ||
| 57 | + | ||
| 58 | + @Resource | ||
| 59 | + private ErpProductService productService; | ||
| 60 | + @Resource | ||
| 61 | + @Lazy // 延迟加载,避免循环依赖 | ||
| 62 | + private ErpPurchaseOrderService purchaseOrderService; | ||
| 63 | + @Resource | ||
| 64 | + private ErpAccountService accountService; | ||
| 65 | + @Resource | ||
| 66 | + private ErpStockRecordService stockRecordService; | ||
| 67 | + | ||
| 68 | + @Override | ||
| 69 | + @Transactional(rollbackFor = Exception.class) | ||
| 70 | + public Long createPurchaseReturn(ErpPurchaseReturnSaveReqVO createReqVO) { | ||
| 71 | + // 1.1 校验采购订单已审核 | ||
| 72 | + ErpPurchaseOrderDO purchaseOrder = purchaseOrderService.validatePurchaseOrder(createReqVO.getOrderId()); | ||
| 73 | + // 1.2 校验退货项的有效性 | ||
| 74 | + List<ErpPurchaseReturnItemDO> purchaseReturnItems = validatePurchaseReturnItems(createReqVO.getItems()); | ||
| 75 | + // 1.3 校验结算账户 | ||
| 76 | + accountService.validateAccount(createReqVO.getAccountId()); | ||
| 77 | + // 1.4 生成调拨单号,并校验唯一性 | ||
| 78 | + String no = noRedisDAO.generate(ErpNoRedisDAO.PURCHASE_RETURN_NO_PREFIX); | ||
| 79 | + if (purchaseReturnMapper.selectByNo(no) != null) { | ||
| 80 | + throw exception(PURCHASE_RETURN_NO_EXISTS); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + // 2.1 插入退货 | ||
| 84 | + ErpPurchaseReturnDO purchaseReturn = BeanUtils.toBean(createReqVO, ErpPurchaseReturnDO.class, in -> in | ||
| 85 | + .setNo(no).setStatus(ErpAuditStatus.PROCESS.getStatus())) | ||
| 86 | + .setOrderNo(purchaseOrder.getNo()).setSupplierId(purchaseOrder.getSupplierId()); | ||
| 87 | + calculateTotalPrice(purchaseReturn, purchaseReturnItems); | ||
| 88 | + purchaseReturnMapper.insert(purchaseReturn); | ||
| 89 | + // 2.2 插入退货项 | ||
| 90 | + purchaseReturnItems.forEach(o -> o.setReturnId(purchaseReturn.getId())); | ||
| 91 | + purchaseReturnItemMapper.insertBatch(purchaseReturnItems); | ||
| 92 | + | ||
| 93 | + // 3. 更新采购订单的退货数量 | ||
| 94 | + updatePurchaseOrderReturnCount(createReqVO.getOrderId()); | ||
| 95 | + return purchaseReturn.getId(); | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + @Override | ||
| 99 | + @Transactional(rollbackFor = Exception.class) | ||
| 100 | + public void updatePurchaseReturn(ErpPurchaseReturnSaveReqVO updateReqVO) { | ||
| 101 | + // 1.1 校验存在 | ||
| 102 | + ErpPurchaseReturnDO purchaseReturn = validatePurchaseReturnExists(updateReqVO.getId()); | ||
| 103 | + if (ErpAuditStatus.APPROVE.getStatus().equals(purchaseReturn.getStatus())) { | ||
| 104 | + throw exception(PURCHASE_RETURN_UPDATE_FAIL_APPROVE, purchaseReturn.getNo()); | ||
| 105 | + } | ||
| 106 | + // 1.2 校验采购订单已审核 | ||
| 107 | + ErpPurchaseOrderDO purchaseOrder = purchaseOrderService.validatePurchaseOrder(updateReqVO.getOrderId()); | ||
| 108 | + // 1.3 校验结算账户 | ||
| 109 | + accountService.validateAccount(updateReqVO.getAccountId()); | ||
| 110 | + // 1.4 校验订单项的有效性 | ||
| 111 | + List<ErpPurchaseReturnItemDO> purchaseReturnItems = validatePurchaseReturnItems(updateReqVO.getItems()); | ||
| 112 | + | ||
| 113 | + // 2.1 更新退货 | ||
| 114 | + ErpPurchaseReturnDO updateObj = BeanUtils.toBean(updateReqVO, ErpPurchaseReturnDO.class) | ||
| 115 | + .setOrderNo(purchaseOrder.getNo()).setSupplierId(purchaseOrder.getSupplierId()); | ||
| 116 | + calculateTotalPrice(updateObj, purchaseReturnItems); | ||
| 117 | + purchaseReturnMapper.updateById(updateObj); | ||
| 118 | + // 2.2 更新退货项 | ||
| 119 | + updatePurchaseReturnItemList(updateReqVO.getId(), purchaseReturnItems); | ||
| 120 | + | ||
| 121 | + // 3.1 更新采购订单的出库数量 | ||
| 122 | + updatePurchaseOrderReturnCount(updateObj.getOrderId()); | ||
| 123 | + // 3.2 注意:如果采购订单编号变更了,需要更新“老”采购订单的出库数量 | ||
| 124 | + if (ObjectUtil.notEqual(purchaseReturn.getOrderId(), updateObj.getOrderId())) { | ||
| 125 | + updatePurchaseOrderReturnCount(purchaseReturn.getOrderId()); | ||
| 126 | + } | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + private void calculateTotalPrice(ErpPurchaseReturnDO purchaseReturn, List<ErpPurchaseReturnItemDO> purchaseReturnItems) { | ||
| 130 | + purchaseReturn.setTotalCount(getSumValue(purchaseReturnItems, ErpPurchaseReturnItemDO::getCount, BigDecimal::add)); | ||
| 131 | + purchaseReturn.setTotalProductPrice(getSumValue(purchaseReturnItems, ErpPurchaseReturnItemDO::getTotalPrice, BigDecimal::add, BigDecimal.ZERO)); | ||
| 132 | + purchaseReturn.setTotalTaxPrice(getSumValue(purchaseReturnItems, ErpPurchaseReturnItemDO::getTaxPrice, BigDecimal::add, BigDecimal.ZERO)); | ||
| 133 | + purchaseReturn.setTotalPrice(purchaseReturn.getTotalProductPrice().add(purchaseReturn.getTotalTaxPrice())); | ||
| 134 | + // 计算优惠价格 | ||
| 135 | + if (purchaseReturn.getDiscountPercent() == null) { | ||
| 136 | + purchaseReturn.setDiscountPercent(BigDecimal.ZERO); | ||
| 137 | + } | ||
| 138 | + purchaseReturn.setDiscountPrice(MoneyUtils.priceMultiplyPercent(purchaseReturn.getTotalPrice(), purchaseReturn.getDiscountPercent())); | ||
| 139 | + purchaseReturn.setTotalPrice(purchaseReturn.getTotalPrice().subtract(purchaseReturn.getDiscountPrice())); | ||
| 140 | + // 计算应退金额 | ||
| 141 | + BigDecimal allPrice = purchaseReturn.getTotalPrice().add(purchaseReturn.getOtherPrice()); | ||
| 142 | + purchaseReturn.setDebtPrice(allPrice.subtract(purchaseReturn.getRefundPrice())); | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + private void updatePurchaseOrderReturnCount(Long orderId) { | ||
| 146 | + // 1.1 查询采购订单对应的采购出库单列表 | ||
| 147 | + List<ErpPurchaseReturnDO> purchaseReturns = purchaseReturnMapper.selectListByOrderId(orderId); | ||
| 148 | + // 1.2 查询对应的采购订单项的退货数量 | ||
| 149 | + Map<Long, BigDecimal> returnCountMap = purchaseReturnItemMapper.selectOrderItemCountSumMapByReturnIds( | ||
| 150 | + convertList(purchaseReturns, ErpPurchaseReturnDO::getId)); | ||
| 151 | + // 2. 更新采购订单的出库数量 | ||
| 152 | + purchaseOrderService.updatePurchaseOrderReturnCount(orderId, returnCountMap); | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + @Override | ||
| 156 | + @Transactional(rollbackFor = Exception.class) | ||
| 157 | + public void updatePurchaseReturnStatus(Long id, Integer status) { | ||
| 158 | + boolean approve = ErpAuditStatus.APPROVE.getStatus().equals(status); | ||
| 159 | + // 1.1 校验存在 | ||
| 160 | + ErpPurchaseReturnDO purchaseReturn = validatePurchaseReturnExists(id); | ||
| 161 | + // 1.2 校验状态 | ||
| 162 | + if (purchaseReturn.getStatus().equals(status)) { | ||
| 163 | + throw exception(approve ? PURCHASE_RETURN_APPROVE_FAIL : PURCHASE_RETURN_PROCESS_FAIL); | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + // 2. 更新状态 | ||
| 167 | + int updateCount = purchaseReturnMapper.updateByIdAndStatus(id, purchaseReturn.getStatus(), | ||
| 168 | + new ErpPurchaseReturnDO().setStatus(status)); | ||
| 169 | + if (updateCount == 0) { | ||
| 170 | + throw exception(approve ? PURCHASE_RETURN_APPROVE_FAIL : PURCHASE_RETURN_PROCESS_FAIL); | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + // 3. 变更库存 | ||
| 174 | + List<ErpPurchaseReturnItemDO> purchaseReturnItems = purchaseReturnItemMapper.selectListByReturnId(id); | ||
| 175 | + Integer bizType = approve ? ErpStockRecordBizTypeEnum.PURCHASE_RETURN.getType() | ||
| 176 | + : ErpStockRecordBizTypeEnum.PURCHASE_RETURN_CANCEL.getType(); | ||
| 177 | + purchaseReturnItems.forEach(purchaseReturnItem -> { | ||
| 178 | + BigDecimal count = approve ? purchaseReturnItem.getCount().negate() : purchaseReturnItem.getCount(); | ||
| 179 | + stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO( | ||
| 180 | + purchaseReturnItem.getProductId(), purchaseReturnItem.getWarehouseId(), count, | ||
| 181 | + bizType, purchaseReturnItem.getReturnId(), purchaseReturnItem.getId(), purchaseReturn.getNo())); | ||
| 182 | + }); | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + private List<ErpPurchaseReturnItemDO> validatePurchaseReturnItems(List<ErpPurchaseReturnSaveReqVO.Item> list) { | ||
| 186 | + // 1. 校验产品存在 | ||
| 187 | + List<ErpProductDO> productList = productService.validProductList( | ||
| 188 | + convertSet(list, ErpPurchaseReturnSaveReqVO.Item::getProductId)); | ||
| 189 | + Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId); | ||
| 190 | + // 2. 转化为 ErpPurchaseReturnItemDO 列表 | ||
| 191 | + return convertList(list, o -> BeanUtils.toBean(o, ErpPurchaseReturnItemDO.class, item -> { | ||
| 192 | + item.setProductUnitId(productMap.get(item.getProductId()).getUnitId()); | ||
| 193 | + item.setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount())); | ||
| 194 | + if (item.getTotalPrice() == null) { | ||
| 195 | + return; | ||
| 196 | + } | ||
| 197 | + if (item.getTaxPercent() != null) { | ||
| 198 | + item.setTaxPrice(MoneyUtils.priceMultiplyPercent(item.getTotalPrice(), item.getTaxPercent())); | ||
| 199 | + } | ||
| 200 | + })); | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + private void updatePurchaseReturnItemList(Long id, List<ErpPurchaseReturnItemDO> newList) { | ||
| 204 | + // 第一步,对比新老数据,获得添加、修改、删除的列表 | ||
| 205 | + List<ErpPurchaseReturnItemDO> oldList = purchaseReturnItemMapper.selectListByReturnId(id); | ||
| 206 | + List<List<ErpPurchaseReturnItemDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录 | ||
| 207 | + (oldVal, newVal) -> oldVal.getId().equals(newVal.getId())); | ||
| 208 | + | ||
| 209 | + // 第二步,批量添加、修改、删除 | ||
| 210 | + if (CollUtil.isNotEmpty(diffList.get(0))) { | ||
| 211 | + diffList.get(0).forEach(o -> o.setReturnId(id)); | ||
| 212 | + purchaseReturnItemMapper.insertBatch(diffList.get(0)); | ||
| 213 | + } | ||
| 214 | + if (CollUtil.isNotEmpty(diffList.get(1))) { | ||
| 215 | + purchaseReturnItemMapper.updateBatch(diffList.get(1)); | ||
| 216 | + } | ||
| 217 | + if (CollUtil.isNotEmpty(diffList.get(2))) { | ||
| 218 | + purchaseReturnItemMapper.deleteBatchIds(convertList(diffList.get(2), ErpPurchaseReturnItemDO::getId)); | ||
| 219 | + } | ||
| 220 | + } | ||
| 221 | + | ||
| 222 | + @Override | ||
| 223 | + @Transactional(rollbackFor = Exception.class) | ||
| 224 | + public void deletePurchaseReturn(List<Long> ids) { | ||
| 225 | + // 1. 校验不处于已审批 | ||
| 226 | + List<ErpPurchaseReturnDO> purchaseReturns = purchaseReturnMapper.selectBatchIds(ids); | ||
| 227 | + if (CollUtil.isEmpty(purchaseReturns)) { | ||
| 228 | + return; | ||
| 229 | + } | ||
| 230 | + purchaseReturns.forEach(purchaseReturn -> { | ||
| 231 | + if (ErpAuditStatus.APPROVE.getStatus().equals(purchaseReturn.getStatus())) { | ||
| 232 | + throw exception(PURCHASE_RETURN_DELETE_FAIL_APPROVE, purchaseReturn.getNo()); | ||
| 233 | + } | ||
| 234 | + }); | ||
| 235 | + | ||
| 236 | + // 2. 遍历删除,并记录操作日志 | ||
| 237 | + purchaseReturns.forEach(purchaseReturn -> { | ||
| 238 | + // 2.1 删除订单 | ||
| 239 | + purchaseReturnMapper.deleteById(purchaseReturn.getId()); | ||
| 240 | + // 2.2 删除订单项 | ||
| 241 | + purchaseReturnItemMapper.deleteByReturnId(purchaseReturn.getId()); | ||
| 242 | + | ||
| 243 | + // 2.3 更新采购订单的出库数量 | ||
| 244 | + updatePurchaseOrderReturnCount(purchaseReturn.getOrderId()); | ||
| 245 | + }); | ||
| 246 | + | ||
| 247 | + } | ||
| 248 | + | ||
| 249 | + private ErpPurchaseReturnDO validatePurchaseReturnExists(Long id) { | ||
| 250 | + ErpPurchaseReturnDO purchaseReturn = purchaseReturnMapper.selectById(id); | ||
| 251 | + if (purchaseReturn == null) { | ||
| 252 | + throw exception(PURCHASE_RETURN_NOT_EXISTS); | ||
| 253 | + } | ||
| 254 | + return purchaseReturn; | ||
| 255 | + } | ||
| 256 | + | ||
| 257 | + @Override | ||
| 258 | + public ErpPurchaseReturnDO getPurchaseReturn(Long id) { | ||
| 259 | + return purchaseReturnMapper.selectById(id); | ||
| 260 | + } | ||
| 261 | + | ||
| 262 | + @Override | ||
| 263 | + public PageResult<ErpPurchaseReturnDO> getPurchaseReturnPage(ErpPurchaseReturnPageReqVO pageReqVO) { | ||
| 264 | + return purchaseReturnMapper.selectPage(pageReqVO); | ||
| 265 | + } | ||
| 266 | + | ||
| 267 | + // ==================== 采购退货项 ==================== | ||
| 268 | + | ||
| 269 | + @Override | ||
| 270 | + public List<ErpPurchaseReturnItemDO> getPurchaseReturnItemListByReturnId(Long returnId) { | ||
| 271 | + return purchaseReturnItemMapper.selectListByReturnId(returnId); | ||
| 272 | + } | ||
| 273 | + | ||
| 274 | + @Override | ||
| 275 | + public List<ErpPurchaseReturnItemDO> getPurchaseReturnItemListByReturnIds(Collection<Long> returnIds) { | ||
| 276 | + if (CollUtil.isEmpty(returnIds)) { | ||
| 277 | + return Collections.emptyList(); | ||
| 278 | + } | ||
| 279 | + return purchaseReturnItemMapper.selectListByReturnIds(returnIds); | ||
| 280 | + } | ||
| 281 | + | ||
| 282 | +} | ||
| 0 | \ No newline at end of file | 283 | \ 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
| @@ -157,7 +157,7 @@ public class ErpSaleReturnServiceImpl implements ErpSaleReturnService { | @@ -157,7 +157,7 @@ public class ErpSaleReturnServiceImpl implements ErpSaleReturnService { | ||
| 157 | private void updateSaleOrderReturnCount(Long orderId) { | 157 | private void updateSaleOrderReturnCount(Long orderId) { |
| 158 | // 1.1 查询销售订单对应的销售出库单列表 | 158 | // 1.1 查询销售订单对应的销售出库单列表 |
| 159 | List<ErpSaleReturnDO> saleReturns = saleReturnMapper.selectListByOrderId(orderId); | 159 | List<ErpSaleReturnDO> saleReturns = saleReturnMapper.selectListByOrderId(orderId); |
| 160 | - // 1.2 查询对应的销售订单项的出库数量 | 160 | + // 1.2 查询对应的销售订单项的退货数量 |
| 161 | Map<Long, BigDecimal> returnCountMap = saleReturnItemMapper.selectOrderItemCountSumMapByReturnIds( | 161 | Map<Long, BigDecimal> returnCountMap = saleReturnItemMapper.selectOrderItemCountSumMapByReturnIds( |
| 162 | convertList(saleReturns, ErpSaleReturnDO::getId)); | 162 | convertList(saleReturns, ErpSaleReturnDO::getId)); |
| 163 | // 2. 更新销售订单的出库数量 | 163 | // 2. 更新销售订单的出库数量 |