| | |
| | | import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.crm.api.customer.CrmCustomerApi; |
| | | import cn.iocoder.yudao.module.crm.api.contract.CrmContractApi; |
| | | import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.order.ErpSaleOrderPageReqVO; |
| | | import cn.iocoder.yudao.module.erp.controller.admin.sale.vo.order.ErpSaleOrderSaveReqVO; |
| | | import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO; |
| | |
| | | private ErpProductService productService; |
| | | @Resource |
| | | private CrmCustomerApi customerApi; |
| | | @Resource |
| | | private CrmContractApi contractApi; |
| | | @Resource |
| | | private ErpAccountService accountService; |
| | | |
| | |
| | | throw exception(approve ? SALE_ORDER_APPROVE_FAIL : SALE_ORDER_PROCESS_FAIL); |
| | | } |
| | | // 1.3 存在销售出库单,无法反审核 |
| | | if (!approve && saleOrder.getOutCount().compareTo(BigDecimal.ZERO) > 0) { |
| | | BigDecimal outCount = saleOrder.getOutCount() != null ? saleOrder.getOutCount() : BigDecimal.ZERO; |
| | | if (!approve && outCount.compareTo(BigDecimal.ZERO) > 0) { |
| | | throw exception(SALE_ORDER_PROCESS_FAIL_EXISTS_OUT); |
| | | } |
| | | // 1.4 存在销售退货单,无法反审核 |
| | | if (!approve && saleOrder.getReturnCount().compareTo(BigDecimal.ZERO) > 0) { |
| | | BigDecimal returnCount = saleOrder.getReturnCount() != null ? saleOrder.getReturnCount() : BigDecimal.ZERO; |
| | | if (!approve && returnCount.compareTo(BigDecimal.ZERO) > 0) { |
| | | throw exception(SALE_ORDER_PROCESS_FAIL_EXISTS_RETURN); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void cancelSaleOrder(Long id) { |
| | | // 1.1 校验存在 |
| | | ErpSaleOrderDO saleOrder = validateSaleOrderExists(id); |
| | | // 1.2 校验状态:只有已审核的订单才能作废 |
| | | if (!ErpAuditStatus.APPROVE.getStatus().equals(saleOrder.getStatus())) { |
| | | throw exception(SALE_ORDER_CANCEL_FAIL_NOT_APPROVE, saleOrder.getNo()); |
| | | } |
| | | // 1.3 存在销售出库单,无法作废 |
| | | BigDecimal outCount = saleOrder.getOutCount() != null ? saleOrder.getOutCount() : BigDecimal.ZERO; |
| | | if (outCount.compareTo(BigDecimal.ZERO) > 0) { |
| | | throw exception(SALE_ORDER_CANCEL_FAIL_EXISTS_OUT); |
| | | } |
| | | // 1.4 存在销售退货单,无法作废 |
| | | BigDecimal returnCount = saleOrder.getReturnCount() != null ? saleOrder.getReturnCount() : BigDecimal.ZERO; |
| | | if (returnCount.compareTo(BigDecimal.ZERO) > 0) { |
| | | throw exception(SALE_ORDER_CANCEL_FAIL_EXISTS_RETURN); |
| | | } |
| | | |
| | | // 2. 更新状态为已作废 |
| | | int updateCount = saleOrderMapper.updateByIdAndStatus(id, saleOrder.getStatus(), |
| | | new ErpSaleOrderDO().setStatus(ErpAuditStatus.CANCEL.getStatus())); |
| | | if (updateCount == 0) { |
| | | throw exception(SALE_ORDER_CANCEL_FAIL); |
| | | } |
| | | |
| | | // 3. 同步更新关联合同状态为已作废 |
| | | if (saleOrder.getContractId() != null) { |
| | | contractApi.updateContractStatus(saleOrder.getContractId(), 50).getCheckedData(); // 50 = 已作废 |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void enableSaleOrder(Long id) { |
| | | // 1.1 校验存在 |
| | | ErpSaleOrderDO saleOrder = validateSaleOrderExists(id); |
| | | // 1.2 校验状态:只有已作废的订单才能重新启用 |
| | | if (!ErpAuditStatus.CANCEL.getStatus().equals(saleOrder.getStatus())) { |
| | | throw exception(SALE_ORDER_ENABLE_FAIL_NOT_CANCEL, saleOrder.getNo()); |
| | | } |
| | | |
| | | // 2. 更新状态为已审核 |
| | | int updateCount = saleOrderMapper.updateByIdAndStatus(id, saleOrder.getStatus(), |
| | | new ErpSaleOrderDO().setStatus(ErpAuditStatus.APPROVE.getStatus())); |
| | | if (updateCount == 0) { |
| | | throw exception(SALE_ORDER_ENABLE_FAIL); |
| | | } |
| | | |
| | | // 3. 同步更新关联合同状态为审核通过 |
| | | if (saleOrder.getContractId() != null) { |
| | | contractApi.updateContractStatus(saleOrder.getContractId(), 20).getCheckedData(); // 20 = 审核通过 |
| | | } |
| | | } |
| | | |
| | | private List<ErpSaleOrderItemDO> validateSaleOrderItems(List<ErpSaleOrderSaveReqVO.Item> list) { |
| | | // 1. 校验产品存在 |
| | | List<ErpProductDO> productList = productService.validProductList( |