✨ ERP:采购出库 50%
This commit is contained in:
parent
62ef4b16af
commit
2d02430768
|
@ -34,6 +34,14 @@ ErrorCode PURCHASE_ORDER_ITEM_RETURN_FAIL_IN_EXCEED = new ErrorCode(1_030_101_00
|
|||
ErrorCode PURCHASE_IN_NO_EXISTS = new ErrorCode(1_030_102_004, "生成入库单失败,请重新提交");
|
||||
ErrorCode PURCHASE_IN_UPDATE_FAIL_APPROVE = new ErrorCode(1_030_102_005, "采购入库单({})已审核,无法修改");
|
||||
|
||||
// ========== ERP 采购退货(1-030-103-000) ==========
|
||||
ErrorCode PURCHASE_RETURN_NOT_EXISTS = new ErrorCode(1_030_103_000, "采购退货单不存在");
|
||||
ErrorCode PURCHASE_RETURN_DELETE_FAIL_APPROVE = new ErrorCode(1_030_103_001, "采购退货单({})已审核,无法删除");
|
||||
ErrorCode PURCHASE_RETURN_PROCESS_FAIL = new ErrorCode(1_030_103_002, "反审核失败,只有已审核的退货单才能反审核");
|
||||
ErrorCode PURCHASE_RETURN_APPROVE_FAIL = new ErrorCode(1_030_103_003, "审核失败,只有未审核的退货单才能审核");
|
||||
ErrorCode PURCHASE_RETURN_NO_EXISTS = new ErrorCode(1_030_103_004, "生成退货单失败,请重新提交");
|
||||
ErrorCode PURCHASE_RETURN_UPDATE_FAIL_APPROVE = new ErrorCode(1_030_103_005, "采购退货单({})已审核,无法修改");
|
||||
|
||||
// ========== ERP 客户(1-030-200-000)==========
|
||||
ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(1_020_200_000, "客户不存在");
|
||||
ErrorCode CUSTOMER_NOT_ENABLE = new ErrorCode(1_020_200_001, "客户({})未启用");
|
||||
|
|
|
@ -39,6 +39,9 @@ public enum ErpStockRecordBizTypeEnum implements IntArrayValuable {
|
|||
|
||||
PURCHASE_IN(70, "采购入库"),
|
||||
PURCHASE_IN_CANCEL(71, "采购入库(作废)"),
|
||||
|
||||
PURCHASE_RETURN(80, "采购退货出库"),
|
||||
PURCHASE_RETURN_CANCEL(81, "采购退货出库(作废)"),
|
||||
;
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpStockRecordBizTypeEnum::getType).toArray();
|
||||
|
|
|
@ -0,0 +1,165 @@
|
|||
package cn.iocoder.yudao.module.erp.controller.admin.purchase;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.returns.ErpPurchaseReturnPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.returns.ErpPurchaseReturnRespVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.returns.ErpPurchaseReturnSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnItemDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpSupplierDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
|
||||
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
|
||||
import cn.iocoder.yudao.module.erp.service.purchase.ErpPurchaseReturnService;
|
||||
import cn.iocoder.yudao.module.erp.service.purchase.ErpSupplierService;
|
||||
import cn.iocoder.yudao.module.erp.service.stock.ErpStockService;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Tag(name = "管理后台 - ERP 采购退货")
|
||||
@RestController
|
||||
@RequestMapping("/erp/purchase-return")
|
||||
@Validated
|
||||
public class ErpPurchaseReturnController {
|
||||
|
||||
@Resource
|
||||
private ErpPurchaseReturnService purchaseReturnService;
|
||||
@Resource
|
||||
private ErpStockService stockService;
|
||||
@Resource
|
||||
private ErpProductService productService;
|
||||
@Resource
|
||||
private ErpSupplierService supplierService;
|
||||
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建采购退货")
|
||||
@PreAuthorize("@ss.hasPermission('erp:purchase-return:create')")
|
||||
public CommonResult<Long> createPurchaseReturn(@Valid @RequestBody ErpPurchaseReturnSaveReqVO createReqVO) {
|
||||
return success(purchaseReturnService.createPurchaseReturn(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新采购退货")
|
||||
@PreAuthorize("@ss.hasPermission('erp:purchase-return:update')")
|
||||
public CommonResult<Boolean> updatePurchaseReturn(@Valid @RequestBody ErpPurchaseReturnSaveReqVO updateReqVO) {
|
||||
purchaseReturnService.updatePurchaseReturn(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/update-status")
|
||||
@Operation(summary = "更新采购退货的状态")
|
||||
@PreAuthorize("@ss.hasPermission('erp:purchase-return:update-status')")
|
||||
public CommonResult<Boolean> updatePurchaseReturnStatus(@RequestParam("id") Long id,
|
||||
@RequestParam("status") Integer status) {
|
||||
purchaseReturnService.updatePurchaseReturnStatus(id, status);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除采购退货")
|
||||
@Parameter(name = "ids", description = "编号数组", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('erp:purchase-return:delete')")
|
||||
public CommonResult<Boolean> deletePurchaseReturn(@RequestParam("ids") List<Long> ids) {
|
||||
purchaseReturnService.deletePurchaseReturn(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得采购退货")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('erp:purchase-return:query')")
|
||||
public CommonResult<ErpPurchaseReturnRespVO> getPurchaseReturn(@RequestParam("id") Long id) {
|
||||
ErpPurchaseReturnDO purchaseReturn = purchaseReturnService.getPurchaseReturn(id);
|
||||
if (purchaseReturn == null) {
|
||||
return success(null);
|
||||
}
|
||||
List<ErpPurchaseReturnItemDO> purchaseReturnItemList = purchaseReturnService.getPurchaseReturnItemListByReturnId(id);
|
||||
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
|
||||
convertSet(purchaseReturnItemList, ErpPurchaseReturnItemDO::getProductId));
|
||||
return success(BeanUtils.toBean(purchaseReturn, ErpPurchaseReturnRespVO.class, purchaseReturnVO ->
|
||||
purchaseReturnVO.setItems(BeanUtils.toBean(purchaseReturnItemList, ErpPurchaseReturnRespVO.Item.class, item -> {
|
||||
ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId());
|
||||
item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO);
|
||||
MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName())
|
||||
.setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName()));
|
||||
}))));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得采购退货分页")
|
||||
@PreAuthorize("@ss.hasPermission('erp:purchase-return:query')")
|
||||
public CommonResult<PageResult<ErpPurchaseReturnRespVO>> getPurchaseReturnPage(@Valid ErpPurchaseReturnPageReqVO pageReqVO) {
|
||||
PageResult<ErpPurchaseReturnDO> pageResult = purchaseReturnService.getPurchaseReturnPage(pageReqVO);
|
||||
return success(buildPurchaseReturnVOPageResult(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出采购退货 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('erp:purchase-return:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportPurchaseReturnExcel(@Valid ErpPurchaseReturnPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<ErpPurchaseReturnRespVO> list = buildPurchaseReturnVOPageResult(purchaseReturnService.getPurchaseReturnPage(pageReqVO)).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "采购退货.xls", "数据", ErpPurchaseReturnRespVO.class, list);
|
||||
}
|
||||
|
||||
private PageResult<ErpPurchaseReturnRespVO> buildPurchaseReturnVOPageResult(PageResult<ErpPurchaseReturnDO> pageResult) {
|
||||
if (CollUtil.isEmpty(pageResult.getList())) {
|
||||
return PageResult.empty(pageResult.getTotal());
|
||||
}
|
||||
// 1.1 退货项
|
||||
List<ErpPurchaseReturnItemDO> purchaseReturnItemList = purchaseReturnService.getPurchaseReturnItemListByReturnIds(
|
||||
convertSet(pageResult.getList(), ErpPurchaseReturnDO::getId));
|
||||
Map<Long, List<ErpPurchaseReturnItemDO>> purchaseReturnItemMap = convertMultiMap(purchaseReturnItemList, ErpPurchaseReturnItemDO::getReturnId);
|
||||
// 1.2 产品信息
|
||||
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
|
||||
convertSet(purchaseReturnItemList, ErpPurchaseReturnItemDO::getProductId));
|
||||
// 1.3 供应商信息
|
||||
Map<Long, ErpSupplierDO> supplierMap = supplierService.getSupplierMap(
|
||||
convertSet(pageResult.getList(), ErpPurchaseReturnDO::getSupplierId));
|
||||
// 1.4 管理员信息
|
||||
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
|
||||
convertSet(pageResult.getList(), erpStockRecordDO -> Long.parseLong(erpStockRecordDO.getCreator())));
|
||||
// 2. 开始拼接
|
||||
return BeanUtils.toBean(pageResult, ErpPurchaseReturnRespVO.class, purchaseReturn -> {
|
||||
purchaseReturn.setItems(BeanUtils.toBean(purchaseReturnItemMap.get(purchaseReturn.getId()), ErpPurchaseReturnRespVO.Item.class,
|
||||
item -> MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName())
|
||||
.setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName()))));
|
||||
purchaseReturn.setProductNames(CollUtil.join(purchaseReturn.getItems(), ",", ErpPurchaseReturnRespVO.Item::getProductName));
|
||||
MapUtils.findAndThen(supplierMap, purchaseReturn.getSupplierId(), supplier -> purchaseReturn.setSupplierName(supplier.getName()));
|
||||
MapUtils.findAndThen(userMap, Long.parseLong(purchaseReturn.getCreator()), user -> purchaseReturn.setCreatorName(user.getNickname()));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.returns;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - ERP 采购退货分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ErpPurchaseReturnPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "采购单编号", example = "XS001")
|
||||
private String no;
|
||||
|
||||
@Schema(description = "供应商编号", example = "1724")
|
||||
private Long supplierId;
|
||||
|
||||
@Schema(description = "退货时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] returnTime;
|
||||
|
||||
@Schema(description = "备注", example = "你猜")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "退货状态", example = "2")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "创建者")
|
||||
private String creator;
|
||||
|
||||
@Schema(description = "产品编号", example = "1")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "仓库编号", example = "1")
|
||||
private Long warehouseId;
|
||||
|
||||
@Schema(description = "结算账号编号", example = "1")
|
||||
private Long accountId;
|
||||
|
||||
@Schema(description = "采购单号", example = "1")
|
||||
private String orderNo;
|
||||
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
package cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.returns;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - ERP 采购退货 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class ErpPurchaseReturnRespVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386")
|
||||
@ExcelProperty("编号")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "退货单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "XS001")
|
||||
@ExcelProperty("退货单编号")
|
||||
private String no;
|
||||
|
||||
@Schema(description = "退货状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty("退货状态")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "供应商编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1724")
|
||||
private Long supplierId;
|
||||
@Schema(description = "供应商名称", example = "芋道")
|
||||
@ExcelProperty("供应商名称")
|
||||
private String supplierName;
|
||||
|
||||
@Schema(description = "结算账户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "311.89")
|
||||
@ExcelProperty("结算账户编号")
|
||||
private Long accountId;
|
||||
|
||||
@Schema(description = "退货时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("退货时间")
|
||||
private LocalDateTime returnTime;
|
||||
|
||||
@Schema(description = "采购订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386")
|
||||
private Long orderId;
|
||||
@Schema(description = "采购订单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "XS001")
|
||||
private String orderNo;
|
||||
|
||||
@Schema(description = "合计数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15663")
|
||||
@ExcelProperty("合计数量")
|
||||
private BigDecimal totalCount;
|
||||
@Schema(description = "最终合计价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "24906")
|
||||
@ExcelProperty("最终合计价格")
|
||||
private BigDecimal totalPrice;
|
||||
|
||||
@Schema(description = "合计产品价格,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127")
|
||||
private BigDecimal totalProductPrice;
|
||||
|
||||
@Schema(description = "合计税额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127")
|
||||
private BigDecimal totalTaxPrice;
|
||||
|
||||
@Schema(description = "优惠率,百分比", requiredMode = Schema.RequiredMode.REQUIRED, example = "99.88")
|
||||
private BigDecimal discountPercent;
|
||||
|
||||
@Schema(description = "优惠金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127")
|
||||
private BigDecimal discountPrice;
|
||||
|
||||
@Schema(description = "定金金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127")
|
||||
private BigDecimal otherPrice;
|
||||
|
||||
@Schema(description = "本次退款,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127")
|
||||
private BigDecimal refundPrice;
|
||||
@Schema(description = "本次欠款,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
|
||||
private BigDecimal debtPrice;
|
||||
|
||||
@Schema(description = "附件地址", example = "https://www.iocoder.cn")
|
||||
@ExcelProperty("附件地址")
|
||||
private String fileUrl;
|
||||
|
||||
@Schema(description = "备注", example = "你猜")
|
||||
@ExcelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "创建人", example = "芋道")
|
||||
private String creator;
|
||||
@Schema(description = "创建人名称", example = "芋道")
|
||||
private String creatorName;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "退货项列表", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private List<Item> items;
|
||||
|
||||
@Schema(description = "产品信息", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("产品信息")
|
||||
private String productNames;
|
||||
|
||||
@Data
|
||||
public static class Item {
|
||||
|
||||
@Schema(description = "退货项编号", example = "11756")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "采购订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756")
|
||||
private Long orderItemId;
|
||||
|
||||
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
|
||||
private Long warehouseId;
|
||||
|
||||
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "产品单位单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
|
||||
private Long productUnitId;
|
||||
|
||||
@Schema(description = "产品单价", example = "100.00")
|
||||
private BigDecimal productPrice;
|
||||
|
||||
@Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
|
||||
@NotNull(message = "产品数量不能为空")
|
||||
private BigDecimal count;
|
||||
|
||||
@Schema(description = "税率,百分比", example = "99.88")
|
||||
private BigDecimal taxPercent;
|
||||
|
||||
@Schema(description = "税额,单位:元", example = "100.00")
|
||||
private BigDecimal taxPrice;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
private String remark;
|
||||
|
||||
// ========== 关联字段 ==========
|
||||
|
||||
@Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "巧克力")
|
||||
private String productName;
|
||||
@Schema(description = "产品条码", requiredMode = Schema.RequiredMode.REQUIRED, example = "A9985")
|
||||
private String productBarCode;
|
||||
@Schema(description = "产品单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "盒")
|
||||
private String productUnitName;
|
||||
|
||||
@Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
|
||||
private BigDecimal stockCount; // 该字段仅仅在“详情”和“编辑”时使用
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.returns;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - ERP 采购退货新增/修改 Request VO")
|
||||
@Data
|
||||
public class ErpPurchaseReturnSaveReqVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "结算账户编号", example = "31189")
|
||||
private Long accountId;
|
||||
|
||||
@Schema(description = "退货时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "退货时间不能为空")
|
||||
private LocalDateTime returnTime;
|
||||
|
||||
@Schema(description = "采购订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17386")
|
||||
@NotNull(message = "采购订单编号不能为空")
|
||||
private Long orderId;
|
||||
|
||||
@Schema(description = "优惠率,百分比", requiredMode = Schema.RequiredMode.REQUIRED, example = "99.88")
|
||||
private BigDecimal discountPercent;
|
||||
|
||||
@Schema(description = "其它金额,单位:元", example = "7127")
|
||||
private BigDecimal otherPrice;
|
||||
|
||||
@Schema(description = "本次退款,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "7127")
|
||||
@NotNull(message = "本次退款不能为空")
|
||||
private BigDecimal refundPrice;
|
||||
|
||||
@Schema(description = "附件地址", example = "https://www.iocoder.cn")
|
||||
private String fileUrl;
|
||||
|
||||
@Schema(description = "备注", example = "你猜")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "退货清单列表")
|
||||
private List<Item> items;
|
||||
|
||||
@Data
|
||||
public static class Item {
|
||||
|
||||
@Schema(description = "退货项编号", example = "11756")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "采购订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756")
|
||||
@NotNull(message = "采购订单项编号不能为空")
|
||||
private Long orderItemId;
|
||||
|
||||
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
|
||||
@NotNull(message = "仓库编号不能为空")
|
||||
private Long warehouseId;
|
||||
|
||||
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
|
||||
@NotNull(message = "产品编号不能为空")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "产品单位单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
|
||||
@NotNull(message = "产品单位单位不能为空")
|
||||
private Long productUnitId;
|
||||
|
||||
@Schema(description = "产品单价", example = "100.00")
|
||||
private BigDecimal productPrice;
|
||||
|
||||
@Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
|
||||
@NotNull(message = "产品数量不能为空")
|
||||
private BigDecimal count;
|
||||
|
||||
@Schema(description = "税率,百分比", example = "99.88")
|
||||
private BigDecimal taxPercent;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
private String remark;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -31,7 +31,7 @@ public class ErpPurchaseInDO extends BaseDO {
|
|||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 销售入库单号
|
||||
* 采购入库单号
|
||||
*/
|
||||
private String no;
|
||||
/**
|
||||
|
@ -105,7 +105,7 @@ public class ErpPurchaseInDO extends BaseDO {
|
|||
private BigDecimal otherPrice;
|
||||
|
||||
/**
|
||||
* 本次收款,单位:元
|
||||
* 本次退款,单位:元
|
||||
*
|
||||
* refundPrice = totalPrice + otherPrice - debtPrice
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,127 @@
|
|||
package cn.iocoder.yudao.module.erp.dal.dataobject.purchase;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.finance.ErpAccountDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* ERP 采购退货 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName(value = "erp_purchase_return")
|
||||
@KeySequence("erp_purchase_return_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ErpPurchaseReturnDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 采购退货单号
|
||||
*/
|
||||
private String no;
|
||||
/**
|
||||
* 退货状态
|
||||
*
|
||||
* 枚举 {@link cn.iocoder.yudao.module.erp.enums.ErpAuditStatus}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 供应商编号
|
||||
*
|
||||
* 关联 {@link ErpSupplierDO#getId()}
|
||||
*/
|
||||
private Long supplierId;
|
||||
/**
|
||||
* 结算账户编号
|
||||
*
|
||||
* 关联 {@link ErpAccountDO#getId()}
|
||||
*/
|
||||
private Long accountId;
|
||||
/**
|
||||
* 退货时间
|
||||
*/
|
||||
private LocalDateTime returnTime;
|
||||
|
||||
/**
|
||||
* 采购订单编号
|
||||
*
|
||||
* 关联 {@link ErpPurchaseOrderDO#getId()}
|
||||
*/
|
||||
private Long orderId;
|
||||
/**
|
||||
* 采购订单号
|
||||
*
|
||||
* 冗余 {@link ErpPurchaseOrderDO#getNo()}
|
||||
*/
|
||||
private String orderNo;
|
||||
|
||||
/**
|
||||
* 合计数量
|
||||
*/
|
||||
private BigDecimal totalCount;
|
||||
/**
|
||||
* 最终合计价格,单位:元
|
||||
*
|
||||
* totalPrice = totalProductPrice + totalTaxPrice - discountPrice
|
||||
*/
|
||||
private BigDecimal totalPrice;
|
||||
|
||||
/**
|
||||
* 合计产品价格,单位:元
|
||||
*/
|
||||
private BigDecimal totalProductPrice;
|
||||
/**
|
||||
* 合计税额,单位:元
|
||||
*/
|
||||
private BigDecimal totalTaxPrice;
|
||||
/**
|
||||
* 优惠率,百分比
|
||||
*/
|
||||
private BigDecimal discountPercent;
|
||||
/**
|
||||
* 优惠金额,单位:元
|
||||
*
|
||||
* discountPrice = (totalProductPrice + totalTaxPrice) * discountPercent
|
||||
*/
|
||||
private BigDecimal discountPrice;
|
||||
/**
|
||||
* 其它金额,单位:元
|
||||
*/
|
||||
private BigDecimal otherPrice;
|
||||
|
||||
/**
|
||||
* 本次退款,单位:元
|
||||
*
|
||||
* refundPrice = totalPrice + otherPrice - debtPrice
|
||||
*/
|
||||
private BigDecimal refundPrice;
|
||||
/**
|
||||
* 本次欠款,单位:元
|
||||
*/
|
||||
private BigDecimal debtPrice;
|
||||
|
||||
/**
|
||||
* 附件地址
|
||||
*/
|
||||
private String fileUrl;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package cn.iocoder.yudao.module.erp.dal.dataobject.purchase;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* ERP 采购退货项 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("erp_purchase_return_items")
|
||||
@KeySequence("erp_purchase_return_items_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ErpPurchaseReturnItemDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 采购退货编号
|
||||
*
|
||||
* 关联 {@link ErpPurchaseReturnDO##getId()}
|
||||
*/
|
||||
private Long returnId;
|
||||
/**
|
||||
* 采购订单项编号
|
||||
*
|
||||
* 关联 {@link ErpPurchaseOrderItemDO#getId()}
|
||||
* 目的:方便更新关联的采购订单项的退货数量
|
||||
*/
|
||||
private Long orderItemId;
|
||||
/**
|
||||
* 仓库编号
|
||||
*
|
||||
* 关联 {@link ErpWarehouseDO#getId()}
|
||||
*/
|
||||
private Long warehouseId;
|
||||
/**
|
||||
* 产品编号
|
||||
*
|
||||
* 关联 {@link ErpProductDO#getId()}
|
||||
*/
|
||||
private Long productId;
|
||||
/**
|
||||
* 产品单位单位
|
||||
*
|
||||
* 冗余 {@link ErpProductDO#getUnitId()}
|
||||
*/
|
||||
private Long productUnitId;
|
||||
|
||||
/**
|
||||
* 产品单位单价,单位:元
|
||||
*/
|
||||
private BigDecimal productPrice;
|
||||
/**
|
||||
* 数量
|
||||
*/
|
||||
private BigDecimal count;
|
||||
/**
|
||||
* 总价,单位:元
|
||||
*
|
||||
* totalPrice = productPrice * count
|
||||
*/
|
||||
private BigDecimal totalPrice;
|
||||
/**
|
||||
* 税率,百分比
|
||||
*/
|
||||
private BigDecimal taxPercent;
|
||||
/**
|
||||
* 税额,单位:元
|
||||
*
|
||||
* taxPrice = totalPrice * taxPercent
|
||||
*/
|
||||
private BigDecimal taxPrice;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
}
|
|
@ -35,10 +35,10 @@ public interface ErpPurchaseInItemMapper extends BaseMapperX<ErpPurchaseInItemDO
|
|||
}
|
||||
|
||||
/**
|
||||
* 基于销售订单编号,查询每个销售订单项的入库数量之和
|
||||
* 基于采购订单编号,查询每个采购订单项的入库数量之和
|
||||
*
|
||||
* @param inIds 入库订单项编号数组
|
||||
* @return key:销售订单项编号;value:入库数量之和
|
||||
* @return key:采购订单项编号;value:入库数量之和
|
||||
*/
|
||||
default Map<Long, BigDecimal> selectOrderItemCountSumMapByInIds(Collection<Long> inIds) {
|
||||
if (CollUtil.isEmpty(inIds)) {
|
||||
|
|
|
@ -45,7 +45,7 @@ public interface ErpPurchaseOrderMapper extends BaseMapperX<ErpPurchaseOrderDO>
|
|||
} else if (Objects.equals(reqVO.getReturnStatus(), ErpPurchaseOrderPageReqVO.RETURN_STATUS_ALL)) {
|
||||
query.apply("t.return_count = t.total_count");
|
||||
}
|
||||
// 可采购出库
|
||||
// 可采购入库
|
||||
if (Boolean.TRUE.equals(reqVO.getInEnable())) {
|
||||
query.eq(ErpPurchaseOrderDO::getStatus, ErpAuditStatus.APPROVE.getStatus())
|
||||
.apply("t.in_count < t.total_count");
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
package cn.iocoder.yudao.module.erp.dal.mysql.purchase;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnItemDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
|
||||
/**
|
||||
* ERP 采购退货项 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface ErpPurchaseReturnItemMapper extends BaseMapperX<ErpPurchaseReturnItemDO> {
|
||||
|
||||
default List<ErpPurchaseReturnItemDO> selectListByReturnId(Long returnId) {
|
||||
return selectList(ErpPurchaseReturnItemDO::getReturnId, returnId);
|
||||
}
|
||||
|
||||
default List<ErpPurchaseReturnItemDO> selectListByReturnIds(Collection<Long> returnIds) {
|
||||
return selectList(ErpPurchaseReturnItemDO::getReturnId, returnIds);
|
||||
}
|
||||
|
||||
default int deleteByReturnId(Long returnId) {
|
||||
return delete(ErpPurchaseReturnItemDO::getReturnId, returnId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 基于采购订单编号,查询每个采购订单项的退货数量之和
|
||||
*
|
||||
* @param returnIds 入库订单项编号数组
|
||||
* @return key:采购订单项编号;value:退货数量之和
|
||||
*/
|
||||
default Map<Long, BigDecimal> selectOrderItemCountSumMapByReturnIds(Collection<Long> returnIds) {
|
||||
if (CollUtil.isEmpty(returnIds)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
// SQL sum 查询
|
||||
List<Map<String, Object>> result = selectMaps(new QueryWrapper<ErpPurchaseReturnItemDO>()
|
||||
.select("order_item_id, SUM(count) AS sumCount")
|
||||
.groupBy("order_item_id")
|
||||
.in("return_id", returnIds));
|
||||
// 获得数量
|
||||
return convertMap(result, obj -> (Long) obj.get("order_item_id"), obj -> (BigDecimal) obj.get("sumCount"));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package cn.iocoder.yudao.module.erp.dal.mysql.purchase;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.returns.ErpPurchaseReturnPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnItemDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ERP 采购退货 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface ErpPurchaseReturnMapper extends BaseMapperX<ErpPurchaseReturnDO> {
|
||||
|
||||
default PageResult<ErpPurchaseReturnDO> selectPage(ErpPurchaseReturnPageReqVO reqVO) {
|
||||
MPJLambdaWrapperX<ErpPurchaseReturnDO> query = new MPJLambdaWrapperX<ErpPurchaseReturnDO>()
|
||||
.likeIfPresent(ErpPurchaseReturnDO::getNo, reqVO.getNo())
|
||||
.eqIfPresent(ErpPurchaseReturnDO::getSupplierId, reqVO.getSupplierId())
|
||||
.betweenIfPresent(ErpPurchaseReturnDO::getReturnTime, reqVO.getReturnTime())
|
||||
.eqIfPresent(ErpPurchaseReturnDO::getStatus, reqVO.getStatus())
|
||||
.likeIfPresent(ErpPurchaseReturnDO::getRemark, reqVO.getRemark())
|
||||
.eqIfPresent(ErpPurchaseReturnDO::getCreator, reqVO.getCreator())
|
||||
.eqIfPresent(ErpPurchaseReturnDO::getAccountId, reqVO.getAccountId())
|
||||
.likeIfPresent(ErpPurchaseReturnDO::getOrderNo, reqVO.getOrderNo())
|
||||
.orderByDesc(ErpPurchaseReturnDO::getId);
|
||||
if (reqVO.getWarehouseId() != null || reqVO.getProductId() != null) {
|
||||
query.leftJoin(ErpPurchaseReturnItemDO.class, ErpPurchaseReturnItemDO::getReturnId, ErpPurchaseReturnDO::getId)
|
||||
.eq(reqVO.getWarehouseId() != null, ErpPurchaseReturnItemDO::getWarehouseId, reqVO.getWarehouseId())
|
||||
.eq(reqVO.getProductId() != null, ErpPurchaseReturnItemDO::getProductId, reqVO.getProductId())
|
||||
.groupBy(ErpPurchaseReturnDO::getId); // 避免 1 对多查询,产生相同的 1
|
||||
}
|
||||
return selectJoinPage(reqVO, ErpPurchaseReturnDO.class, query);
|
||||
}
|
||||
|
||||
default int updateByIdAndStatus(Long id, Integer status, ErpPurchaseReturnDO updateObj) {
|
||||
return update(updateObj, new LambdaUpdateWrapper<ErpPurchaseReturnDO>()
|
||||
.eq(ErpPurchaseReturnDO::getId, id).eq(ErpPurchaseReturnDO::getStatus, status));
|
||||
}
|
||||
|
||||
default ErpPurchaseReturnDO selectByNo(String no) {
|
||||
return selectOne(ErpPurchaseReturnDO::getNo, no);
|
||||
}
|
||||
|
||||
default List<ErpPurchaseReturnDO> selectListByOrderId(Long orderId) {
|
||||
return selectList(ErpPurchaseReturnDO::getOrderId, orderId);
|
||||
}
|
||||
|
||||
}
|
|
@ -35,10 +35,10 @@ public interface ErpSaleReturnItemMapper extends BaseMapperX<ErpSaleReturnItemDO
|
|||
}
|
||||
|
||||
/**
|
||||
* 基于销售订单编号,查询每个销售订单项的出库数量之和
|
||||
* 基于销售订单编号,查询每个销售订单项的退货数量之和
|
||||
*
|
||||
* @param returnIds 出库订单项编号数组
|
||||
* @return key:销售订单项编号;value:出库数量之和
|
||||
* @return key:销售订单项编号;value:退货数量之和
|
||||
*/
|
||||
default Map<Long, BigDecimal> selectOrderItemCountSumMapByReturnIds(Collection<Long> returnIds) {
|
||||
if (CollUtil.isEmpty(returnIds)) {
|
||||
|
|
|
@ -59,6 +59,10 @@ public class ErpNoRedisDAO {
|
|||
* 采购入库 {@link cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseInDO}
|
||||
*/
|
||||
public static final String PURCHASE_IN_NO_PREFIX = "CGRK";
|
||||
/**
|
||||
* 采购退货 {@link cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnDO}
|
||||
*/
|
||||
public static final String PURCHASE_RETURN_NO_PREFIX = "CGTH";
|
||||
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
@ -76,7 +80,7 @@ public class ErpNoRedisDAO {
|
|||
String key = RedisKeyConstants.NO + noPrefix;
|
||||
Long no = stringRedisTemplate.opsForValue().increment(key);
|
||||
// 设置过期时间
|
||||
stringRedisTemplate.expire(key, Duration.ofMinutes(1L));
|
||||
stringRedisTemplate.expire(key, Duration.ofDays(1L));
|
||||
return noPrefix + String.format("%06d", no);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
package cn.iocoder.yudao.module.erp.service.purchase;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.returns.ErpPurchaseReturnPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.returns.ErpPurchaseReturnSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnItemDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ERP 采购退货 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface ErpPurchaseReturnService {
|
||||
|
||||
/**
|
||||
* 创建采购退货
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createPurchaseReturn(@Valid ErpPurchaseReturnSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新采购退货
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updatePurchaseReturn(@Valid ErpPurchaseReturnSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 更新采购退货的状态
|
||||
*
|
||||
* @param id 编号
|
||||
* @param status 状态
|
||||
*/
|
||||
void updatePurchaseReturnStatus(Long id, Integer status);
|
||||
|
||||
/**
|
||||
* 删除采购退货
|
||||
*
|
||||
* @param ids 编号数组
|
||||
*/
|
||||
void deletePurchaseReturn(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得采购退货
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 采购退货
|
||||
*/
|
||||
ErpPurchaseReturnDO getPurchaseReturn(Long id);
|
||||
|
||||
/**
|
||||
* 获得采购退货分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 采购退货分页
|
||||
*/
|
||||
PageResult<ErpPurchaseReturnDO> getPurchaseReturnPage(ErpPurchaseReturnPageReqVO pageReqVO);
|
||||
|
||||
// ==================== 采购退货项 ====================
|
||||
|
||||
/**
|
||||
* 获得采购退货项列表
|
||||
*
|
||||
* @param returnId 采购退货编号
|
||||
* @return 采购退货项列表
|
||||
*/
|
||||
List<ErpPurchaseReturnItemDO> getPurchaseReturnItemListByReturnId(Long returnId);
|
||||
|
||||
/**
|
||||
* 获得采购退货项 List
|
||||
*
|
||||
* @param returnIds 采购退货编号数组
|
||||
* @return 采购退货项 List
|
||||
*/
|
||||
List<ErpPurchaseReturnItemDO> getPurchaseReturnItemListByReturnIds(Collection<Long> returnIds);
|
||||
|
||||
}
|
|
@ -0,0 +1,282 @@
|
|||
package cn.iocoder.yudao.module.erp.service.purchase;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.returns.ErpPurchaseReturnPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.returns.ErpPurchaseReturnSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseOrderDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.purchase.ErpPurchaseReturnItemDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpPurchaseReturnItemMapper;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.purchase.ErpPurchaseReturnMapper;
|
||||
import cn.iocoder.yudao.module.erp.dal.redis.no.ErpNoRedisDAO;
|
||||
import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus;
|
||||
import cn.iocoder.yudao.module.erp.enums.stock.ErpStockRecordBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.erp.service.finance.ErpAccountService;
|
||||
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
|
||||
import cn.iocoder.yudao.module.erp.service.stock.ErpStockRecordService;
|
||||
import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
|
||||
|
||||
// TODO 芋艿:记录操作日志
|
||||
|
||||
/**
|
||||
* ERP 采购退货 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ErpPurchaseReturnServiceImpl implements ErpPurchaseReturnService {
|
||||
|
||||
@Resource
|
||||
private ErpPurchaseReturnMapper purchaseReturnMapper;
|
||||
@Resource
|
||||
private ErpPurchaseReturnItemMapper purchaseReturnItemMapper;
|
||||
|
||||
@Resource
|
||||
private ErpNoRedisDAO noRedisDAO;
|
||||
|
||||
@Resource
|
||||
private ErpProductService productService;
|
||||
@Resource
|
||||
@Lazy // 延迟加载,避免循环依赖
|
||||
private ErpPurchaseOrderService purchaseOrderService;
|
||||
@Resource
|
||||
private ErpAccountService accountService;
|
||||
@Resource
|
||||
private ErpStockRecordService stockRecordService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createPurchaseReturn(ErpPurchaseReturnSaveReqVO createReqVO) {
|
||||
// 1.1 校验采购订单已审核
|
||||
ErpPurchaseOrderDO purchaseOrder = purchaseOrderService.validatePurchaseOrder(createReqVO.getOrderId());
|
||||
// 1.2 校验退货项的有效性
|
||||
List<ErpPurchaseReturnItemDO> purchaseReturnItems = validatePurchaseReturnItems(createReqVO.getItems());
|
||||
// 1.3 校验结算账户
|
||||
accountService.validateAccount(createReqVO.getAccountId());
|
||||
// 1.4 生成调拨单号,并校验唯一性
|
||||
String no = noRedisDAO.generate(ErpNoRedisDAO.PURCHASE_RETURN_NO_PREFIX);
|
||||
if (purchaseReturnMapper.selectByNo(no) != null) {
|
||||
throw exception(PURCHASE_RETURN_NO_EXISTS);
|
||||
}
|
||||
|
||||
// 2.1 插入退货
|
||||
ErpPurchaseReturnDO purchaseReturn = BeanUtils.toBean(createReqVO, ErpPurchaseReturnDO.class, in -> in
|
||||
.setNo(no).setStatus(ErpAuditStatus.PROCESS.getStatus()))
|
||||
.setOrderNo(purchaseOrder.getNo()).setSupplierId(purchaseOrder.getSupplierId());
|
||||
calculateTotalPrice(purchaseReturn, purchaseReturnItems);
|
||||
purchaseReturnMapper.insert(purchaseReturn);
|
||||
// 2.2 插入退货项
|
||||
purchaseReturnItems.forEach(o -> o.setReturnId(purchaseReturn.getId()));
|
||||
purchaseReturnItemMapper.insertBatch(purchaseReturnItems);
|
||||
|
||||
// 3. 更新采购订单的退货数量
|
||||
updatePurchaseOrderReturnCount(createReqVO.getOrderId());
|
||||
return purchaseReturn.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updatePurchaseReturn(ErpPurchaseReturnSaveReqVO updateReqVO) {
|
||||
// 1.1 校验存在
|
||||
ErpPurchaseReturnDO purchaseReturn = validatePurchaseReturnExists(updateReqVO.getId());
|
||||
if (ErpAuditStatus.APPROVE.getStatus().equals(purchaseReturn.getStatus())) {
|
||||
throw exception(PURCHASE_RETURN_UPDATE_FAIL_APPROVE, purchaseReturn.getNo());
|
||||
}
|
||||
// 1.2 校验采购订单已审核
|
||||
ErpPurchaseOrderDO purchaseOrder = purchaseOrderService.validatePurchaseOrder(updateReqVO.getOrderId());
|
||||
// 1.3 校验结算账户
|
||||
accountService.validateAccount(updateReqVO.getAccountId());
|
||||
// 1.4 校验订单项的有效性
|
||||
List<ErpPurchaseReturnItemDO> purchaseReturnItems = validatePurchaseReturnItems(updateReqVO.getItems());
|
||||
|
||||
// 2.1 更新退货
|
||||
ErpPurchaseReturnDO updateObj = BeanUtils.toBean(updateReqVO, ErpPurchaseReturnDO.class)
|
||||
.setOrderNo(purchaseOrder.getNo()).setSupplierId(purchaseOrder.getSupplierId());
|
||||
calculateTotalPrice(updateObj, purchaseReturnItems);
|
||||
purchaseReturnMapper.updateById(updateObj);
|
||||
// 2.2 更新退货项
|
||||
updatePurchaseReturnItemList(updateReqVO.getId(), purchaseReturnItems);
|
||||
|
||||
// 3.1 更新采购订单的出库数量
|
||||
updatePurchaseOrderReturnCount(updateObj.getOrderId());
|
||||
// 3.2 注意:如果采购订单编号变更了,需要更新“老”采购订单的出库数量
|
||||
if (ObjectUtil.notEqual(purchaseReturn.getOrderId(), updateObj.getOrderId())) {
|
||||
updatePurchaseOrderReturnCount(purchaseReturn.getOrderId());
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateTotalPrice(ErpPurchaseReturnDO purchaseReturn, List<ErpPurchaseReturnItemDO> purchaseReturnItems) {
|
||||
purchaseReturn.setTotalCount(getSumValue(purchaseReturnItems, ErpPurchaseReturnItemDO::getCount, BigDecimal::add));
|
||||
purchaseReturn.setTotalProductPrice(getSumValue(purchaseReturnItems, ErpPurchaseReturnItemDO::getTotalPrice, BigDecimal::add, BigDecimal.ZERO));
|
||||
purchaseReturn.setTotalTaxPrice(getSumValue(purchaseReturnItems, ErpPurchaseReturnItemDO::getTaxPrice, BigDecimal::add, BigDecimal.ZERO));
|
||||
purchaseReturn.setTotalPrice(purchaseReturn.getTotalProductPrice().add(purchaseReturn.getTotalTaxPrice()));
|
||||
// 计算优惠价格
|
||||
if (purchaseReturn.getDiscountPercent() == null) {
|
||||
purchaseReturn.setDiscountPercent(BigDecimal.ZERO);
|
||||
}
|
||||
purchaseReturn.setDiscountPrice(MoneyUtils.priceMultiplyPercent(purchaseReturn.getTotalPrice(), purchaseReturn.getDiscountPercent()));
|
||||
purchaseReturn.setTotalPrice(purchaseReturn.getTotalPrice().subtract(purchaseReturn.getDiscountPrice()));
|
||||
// 计算应退金额
|
||||
BigDecimal allPrice = purchaseReturn.getTotalPrice().add(purchaseReturn.getOtherPrice());
|
||||
purchaseReturn.setDebtPrice(allPrice.subtract(purchaseReturn.getRefundPrice()));
|
||||
}
|
||||
|
||||
private void updatePurchaseOrderReturnCount(Long orderId) {
|
||||
// 1.1 查询采购订单对应的采购出库单列表
|
||||
List<ErpPurchaseReturnDO> purchaseReturns = purchaseReturnMapper.selectListByOrderId(orderId);
|
||||
// 1.2 查询对应的采购订单项的退货数量
|
||||
Map<Long, BigDecimal> returnCountMap = purchaseReturnItemMapper.selectOrderItemCountSumMapByReturnIds(
|
||||
convertList(purchaseReturns, ErpPurchaseReturnDO::getId));
|
||||
// 2. 更新采购订单的出库数量
|
||||
purchaseOrderService.updatePurchaseOrderReturnCount(orderId, returnCountMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updatePurchaseReturnStatus(Long id, Integer status) {
|
||||
boolean approve = ErpAuditStatus.APPROVE.getStatus().equals(status);
|
||||
// 1.1 校验存在
|
||||
ErpPurchaseReturnDO purchaseReturn = validatePurchaseReturnExists(id);
|
||||
// 1.2 校验状态
|
||||
if (purchaseReturn.getStatus().equals(status)) {
|
||||
throw exception(approve ? PURCHASE_RETURN_APPROVE_FAIL : PURCHASE_RETURN_PROCESS_FAIL);
|
||||
}
|
||||
|
||||
// 2. 更新状态
|
||||
int updateCount = purchaseReturnMapper.updateByIdAndStatus(id, purchaseReturn.getStatus(),
|
||||
new ErpPurchaseReturnDO().setStatus(status));
|
||||
if (updateCount == 0) {
|
||||
throw exception(approve ? PURCHASE_RETURN_APPROVE_FAIL : PURCHASE_RETURN_PROCESS_FAIL);
|
||||
}
|
||||
|
||||
// 3. 变更库存
|
||||
List<ErpPurchaseReturnItemDO> purchaseReturnItems = purchaseReturnItemMapper.selectListByReturnId(id);
|
||||
Integer bizType = approve ? ErpStockRecordBizTypeEnum.PURCHASE_RETURN.getType()
|
||||
: ErpStockRecordBizTypeEnum.PURCHASE_RETURN_CANCEL.getType();
|
||||
purchaseReturnItems.forEach(purchaseReturnItem -> {
|
||||
BigDecimal count = approve ? purchaseReturnItem.getCount().negate() : purchaseReturnItem.getCount();
|
||||
stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO(
|
||||
purchaseReturnItem.getProductId(), purchaseReturnItem.getWarehouseId(), count,
|
||||
bizType, purchaseReturnItem.getReturnId(), purchaseReturnItem.getId(), purchaseReturn.getNo()));
|
||||
});
|
||||
}
|
||||
|
||||
private List<ErpPurchaseReturnItemDO> validatePurchaseReturnItems(List<ErpPurchaseReturnSaveReqVO.Item> list) {
|
||||
// 1. 校验产品存在
|
||||
List<ErpProductDO> productList = productService.validProductList(
|
||||
convertSet(list, ErpPurchaseReturnSaveReqVO.Item::getProductId));
|
||||
Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId);
|
||||
// 2. 转化为 ErpPurchaseReturnItemDO 列表
|
||||
return convertList(list, o -> BeanUtils.toBean(o, ErpPurchaseReturnItemDO.class, item -> {
|
||||
item.setProductUnitId(productMap.get(item.getProductId()).getUnitId());
|
||||
item.setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount()));
|
||||
if (item.getTotalPrice() == null) {
|
||||
return;
|
||||
}
|
||||
if (item.getTaxPercent() != null) {
|
||||
item.setTaxPrice(MoneyUtils.priceMultiplyPercent(item.getTotalPrice(), item.getTaxPercent()));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void updatePurchaseReturnItemList(Long id, List<ErpPurchaseReturnItemDO> newList) {
|
||||
// 第一步,对比新老数据,获得添加、修改、删除的列表
|
||||
List<ErpPurchaseReturnItemDO> oldList = purchaseReturnItemMapper.selectListByReturnId(id);
|
||||
List<List<ErpPurchaseReturnItemDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录
|
||||
(oldVal, newVal) -> oldVal.getId().equals(newVal.getId()));
|
||||
|
||||
// 第二步,批量添加、修改、删除
|
||||
if (CollUtil.isNotEmpty(diffList.get(0))) {
|
||||
diffList.get(0).forEach(o -> o.setReturnId(id));
|
||||
purchaseReturnItemMapper.insertBatch(diffList.get(0));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(diffList.get(1))) {
|
||||
purchaseReturnItemMapper.updateBatch(diffList.get(1));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(diffList.get(2))) {
|
||||
purchaseReturnItemMapper.deleteBatchIds(convertList(diffList.get(2), ErpPurchaseReturnItemDO::getId));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deletePurchaseReturn(List<Long> ids) {
|
||||
// 1. 校验不处于已审批
|
||||
List<ErpPurchaseReturnDO> purchaseReturns = purchaseReturnMapper.selectBatchIds(ids);
|
||||
if (CollUtil.isEmpty(purchaseReturns)) {
|
||||
return;
|
||||
}
|
||||
purchaseReturns.forEach(purchaseReturn -> {
|
||||
if (ErpAuditStatus.APPROVE.getStatus().equals(purchaseReturn.getStatus())) {
|
||||
throw exception(PURCHASE_RETURN_DELETE_FAIL_APPROVE, purchaseReturn.getNo());
|
||||
}
|
||||
});
|
||||
|
||||
// 2. 遍历删除,并记录操作日志
|
||||
purchaseReturns.forEach(purchaseReturn -> {
|
||||
// 2.1 删除订单
|
||||
purchaseReturnMapper.deleteById(purchaseReturn.getId());
|
||||
// 2.2 删除订单项
|
||||
purchaseReturnItemMapper.deleteByReturnId(purchaseReturn.getId());
|
||||
|
||||
// 2.3 更新采购订单的出库数量
|
||||
updatePurchaseOrderReturnCount(purchaseReturn.getOrderId());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private ErpPurchaseReturnDO validatePurchaseReturnExists(Long id) {
|
||||
ErpPurchaseReturnDO purchaseReturn = purchaseReturnMapper.selectById(id);
|
||||
if (purchaseReturn == null) {
|
||||
throw exception(PURCHASE_RETURN_NOT_EXISTS);
|
||||
}
|
||||
return purchaseReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErpPurchaseReturnDO getPurchaseReturn(Long id) {
|
||||
return purchaseReturnMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ErpPurchaseReturnDO> getPurchaseReturnPage(ErpPurchaseReturnPageReqVO pageReqVO) {
|
||||
return purchaseReturnMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
// ==================== 采购退货项 ====================
|
||||
|
||||
@Override
|
||||
public List<ErpPurchaseReturnItemDO> getPurchaseReturnItemListByReturnId(Long returnId) {
|
||||
return purchaseReturnItemMapper.selectListByReturnId(returnId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ErpPurchaseReturnItemDO> getPurchaseReturnItemListByReturnIds(Collection<Long> returnIds) {
|
||||
if (CollUtil.isEmpty(returnIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return purchaseReturnItemMapper.selectListByReturnIds(returnIds);
|
||||
}
|
||||
|
||||
}
|
|
@ -157,7 +157,7 @@ public class ErpSaleReturnServiceImpl implements ErpSaleReturnService {
|
|||
private void updateSaleOrderReturnCount(Long orderId) {
|
||||
// 1.1 查询销售订单对应的销售出库单列表
|
||||
List<ErpSaleReturnDO> saleReturns = saleReturnMapper.selectListByOrderId(orderId);
|
||||
// 1.2 查询对应的销售订单项的出库数量
|
||||
// 1.2 查询对应的销售订单项的退货数量
|
||||
Map<Long, BigDecimal> returnCountMap = saleReturnItemMapper.selectOrderItemCountSumMapByReturnIds(
|
||||
convertList(saleReturns, ErpSaleReturnDO::getId));
|
||||
// 2. 更新销售订单的出库数量
|
||||
|
|
Loading…
Reference in New Issue