| | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.service.AccountIncomeService; |
| | | import com.ruoyi.approve.service.IApproveProcessService; |
| | | import com.ruoyi.approve.vo.ApproveProcessVO; |
| | | import com.fasterxml.jackson.databind.JsonNode; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.fasterxml.jackson.databind.node.ObjectNode; |
| | | import com.ruoyi.account.service.AccountIncomeService; |
| | | import com.ruoyi.approve.pojo.ApproveProcess; |
| | | import com.ruoyi.common.enums.ApproveTypeEnum; |
| | | import com.ruoyi.approve.service.IApproveProcessService; |
| | | import com.ruoyi.approve.vo.ApproveProcessVO; |
| | | import com.ruoyi.basic.mapper.CustomerMapper; |
| | | import com.ruoyi.basic.mapper.ProductMapper; |
| | | import com.ruoyi.basic.mapper.ProductModelMapper; |
| | |
| | | import com.ruoyi.basic.pojo.Product; |
| | | import com.ruoyi.basic.pojo.ProductModel; |
| | | import com.ruoyi.basic.service.ICustomerRegionsService; |
| | | import com.ruoyi.common.enums.FileNameType; |
| | | import com.ruoyi.common.enums.SaleEnum; |
| | | import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.enums.StockInUnQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.enums.StockOutUnQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.enums.*; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.EnumUtil; |
| | | import com.ruoyi.common.utils.OrderUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.*; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.security.LoginUser; |
| | | import com.ruoyi.other.mapper.TempFileMapper; |
| | | import com.ruoyi.other.pojo.TempFile; |
| | | import com.ruoyi.procurementrecord.utils.StockUtils; |
| | | import com.ruoyi.production.mapper.*; |
| | | import com.ruoyi.production.pojo.ProcessRoute; |
| | | import com.ruoyi.production.pojo.ProcessRouteItem; |
| | | import com.ruoyi.production.service.ProductionProductMainService; |
| | | |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.mapper.SysDeptMapper; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | import com.ruoyi.procurementrecord.utils.StockUtils; |
| | | import com.ruoyi.purchase.dto.SimpleReturnOrderGroupDto; |
| | | import com.ruoyi.purchase.mapper.PurchaseReturnOrderProductsMapper; |
| | | import com.ruoyi.quality.mapper.QualityInspectMapper; |
| | |
| | | import com.ruoyi.sales.service.ISalesLedgerService; |
| | | import com.ruoyi.stock.dto.StockInventoryDto; |
| | | import com.ruoyi.stock.mapper.StockInRecordMapper; |
| | | import com.ruoyi.stock.mapper.StockInventoryMapper; |
| | | import com.ruoyi.stock.mapper.StockOutRecordMapper; |
| | | import com.ruoyi.stock.pojo.StockInRecord; |
| | | import com.ruoyi.stock.pojo.StockOutRecord; |
| | |
| | | import java.nio.file.StandardCopyOption; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.time.YearMonth; |
| | | import java.time.ZoneId; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | |
| | | private final StockInventoryService stockInventoryService; |
| | | private final StockInRecordMapper stockInRecordMapper; |
| | | private final StockOutRecordMapper stockOutRecordMapper; |
| | | private final StockInventoryMapper stockInventoryMapper; |
| | | private final StockInRecordService stockInRecordService; |
| | | private final StockOutRecordService stockOutRecordService; |
| | | private final StockUtils stockUtils; |
| | | private final ShipmentApprovalMapper shipmentApprovalMapper; |
| | | |
| | | @Autowired |
| | | private IApproveProcessService approveProcessService; |
| | | |
| | |
| | | public List getTopFiveList() { |
| | | // 查询原始数据 |
| | | LambdaQueryWrapper<SalesLedger> queryWrapper = Wrappers.lambdaQuery(); |
| | | queryWrapper.select(SalesLedger::getCustomerId, SalesLedger::getCustomerName, SalesLedger::getContractAmount).orderByDesc(SalesLedger::getContractAmount); |
| | | queryWrapper.select(SalesLedger::getCustomerId, SalesLedger::getCustomerName, SalesLedger::getContractAmount) |
| | | .orderByDesc(SalesLedger::getContractAmount) |
| | | .ne(SalesLedger::getReviewStatus, 2); // 排除反审核数据 |
| | | List<SalesLedger> records = salesLedgerMapper.selectList(queryWrapper); |
| | | |
| | | // 按客户ID分组并聚合金额 |
| | |
| | | |
| | | @Override |
| | | public IPage<SalesLedger> selectSalesLedgerListPage(Page page, SalesLedgerDto salesLedgerDto) { |
| | | // 添加 reviewStatus 的筛选条件 |
| | | IPage<SalesLedger> iPage = salesLedgerMapper.selectSalesLedgerListPage(page, salesLedgerDto); |
| | | |
| | | if (CollectionUtils.isEmpty(iPage.getRecords())) { |
| | |
| | | salesLedger.setIsFh(isFh); |
| | | |
| | | salesLedger.setIsEdit(!isFh); |
| | | |
| | | // 根据 reviewStatus 控制反审相关字段的显示 |
| | | if (salesLedger.getReviewStatus() != null && salesLedger.getReviewStatus() != 2) { |
| | | // 当 reviewStatus 不为 2 时,隐藏反审时间、反审人和反审人ID |
| | | salesLedger.setCounterReviewTime(null); |
| | | salesLedger.setCounterReviewPerson(null); |
| | | salesLedger.setCounterReviewPersonId(null); |
| | | } |
| | | } |
| | | |
| | | if (salesLedgerDto.getStatus() != null && salesLedgerDto.getStatus()) { |
| | |
| | | if (CollectionUtils.isEmpty(idList)) { |
| | | return 0; |
| | | } |
| | | // 校验:已审核的订单不能删除 |
| | | List<SalesLedger> ledgers = salesLedgerMapper.selectBatchIds(idList); |
| | | for (SalesLedger ledger : ledgers) { |
| | | if (ledger.getReviewStatus() != null && ledger.getReviewStatus() == 1) { |
| | | throw new ServiceException("已审核的订单不能删除:" + ledger.getSalesContractNo()); |
| | | } |
| | | } |
| | | // 删除销售管理数据 |
| | | LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.in(SalesLedgerProduct::getSalesLedgerId, idList).select(SalesLedgerProduct::getId); |
| | |
| | | } else { |
| | | if (salesLedger.getDeliveryStatus() == 5) { |
| | | throw new ServiceException("订单已发货,禁止编辑"); |
| | | } |
| | | // 查询数据库中的原始记录用于校验 |
| | | SalesLedger existingLedger = salesLedgerMapper.selectById(salesLedger.getId()); |
| | | if (salesLedger.getReviewStatus() != null && salesLedger.getReviewStatus() == 1) { |
| | | // 审核操作:校验审核人不能是录入人(仅对未审核→已审核的转换) |
| | | if (existingLedger != null && existingLedger.getReviewStatus() != null && existingLedger.getReviewStatus() == 0) { |
| | | Long currentUserId = SecurityUtils.getUserId(); |
| | | String entryPerson = existingLedger.getEntryPerson(); |
| | | if (entryPerson != null && entryPerson.equals(String.valueOf(currentUserId))) { |
| | | throw new ServiceException("不能审核本人录入的订单"); |
| | | } |
| | | } |
| | | salesLedger.setReviewStatus(salesLedgerDto.getReviewStatus()); |
| | | } else if (salesLedger.getReviewStatus() != null && salesLedger.getReviewStatus() == 2) { |
| | | handleCounterReview(salesLedger); |
| | | } else { |
| | | // 未审核状态的编辑操作:校验已审核的订单不能编辑 |
| | | if (existingLedger != null && existingLedger.getReviewStatus() != null && existingLedger.getReviewStatus() == 1) { |
| | | throw new ServiceException("已审核的订单不能编辑"); |
| | | } |
| | | salesLedger.setReviewStatus(0); |
| | | } |
| | | salesLedgerMapper.updateById(salesLedger); |
| | | } |
| | |
| | | qualityInspect.setModel(dbProduct.getSpecificationModel()); |
| | | qualityInspect.setUnit(resolveInspectUnit(dbProduct)); |
| | | qualityInspect.setQuantity(inspectQty); |
| | | qualityInspect.setQualifiedQuantity(inspectQty); |
| | | qualityInspect.setUnqualifiedQuantity(BigDecimal.ZERO); |
| | | qualityInspect.setPassRate(BigDecimal.valueOf(100)); |
| | | qualityInspect.setCheckResult("合格"); |
| | | qualityInspect.setInspectState(1); |
| | | qualityInspect.setApprovalStatus(1); |
| | |
| | | } |
| | | baseMapper.updateById(salesLedger); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 处理销售台账反审逻辑 |
| | | * 1. 设置反审相关信息(时间、人员) |
| | | * 2. 复制原销售台账及产品数据,生成新的台账 |
| | | * 3. 对原台账的库存数据进行反向操作 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public List<Long> counterReview(CounterReviewDto dto) { |
| | | if (dto == null || CollectionUtils.isEmpty(dto.getIds())) { |
| | | throw new ServiceException("请选择要反审核的订单"); |
| | | } |
| | | if (dto.getCounterReviewType() == null || (dto.getCounterReviewType() != 1 && dto.getCounterReviewType() != 2)) { |
| | | throw new ServiceException("请选择反审核类型:作废或重新生成"); |
| | | } |
| | | if (dto.getCounterReviewDesc() == null || dto.getCounterReviewDesc().trim().isEmpty()) { |
| | | throw new ServiceException("请输入反审核描述"); |
| | | } |
| | | |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | List<Long> newLedgerIds = new ArrayList<>(); |
| | | |
| | | for (Long id : dto.getIds()) { |
| | | SalesLedger originalLedger = salesLedgerMapper.selectById(id); |
| | | if (originalLedger == null) { |
| | | throw new ServiceException("订单不存在,无法反审核"); |
| | | } |
| | | if (originalLedger.getReviewStatus() == null || originalLedger.getReviewStatus() != 1) { |
| | | throw new ServiceException("订单" + originalLedger.getSalesContractNo() + "不是已审核状态,无法反审核"); |
| | | } |
| | | |
| | | // 1. 标记原订单为已反审 |
| | | originalLedger.setReviewStatus(2); |
| | | originalLedger.setCounterReviewTime(LocalDateTime.now()); |
| | | originalLedger.setCounterReviewPerson(loginUser.getUser().getNickName()); |
| | | originalLedger.setCounterReviewPersonId(loginUser.getUserId()); |
| | | originalLedger.setCounterReviewType(dto.getCounterReviewType()); |
| | | originalLedger.setCounterReviewDesc(dto.getCounterReviewDesc()); |
| | | salesLedgerMapper.updateById(originalLedger); |
| | | |
| | | // 2. 作废库存:入库扣减、出库增加、删除记录 |
| | | processOriginalOrderStock(id); |
| | | |
| | | // 3. 清除质检记录 |
| | | clearQualityInspectRecords(id); |
| | | |
| | | // 4. 清除发货信息和发货审批记录 |
| | | clearShippingAndApprovalRecords(id); |
| | | |
| | | // 5. 取消审批流程 |
| | | cancelApproveProcesses(id, originalLedger.getSalesContractNo()); |
| | | |
| | | // 6. 重新生成:创建新台账副本 |
| | | if (dto.getCounterReviewType() == 2) { |
| | | SalesLedger newLedger = new SalesLedger(); |
| | | BeanUtils.copyProperties(originalLedger, newLedger); |
| | | newLedger.setId(null); |
| | | newLedger.setSalesContractNo(generateSalesContractNo()); |
| | | newLedger.setDeliveryStatus(1); |
| | | newLedger.setStockStatus(0); |
| | | newLedger.setReviewStatus(0); |
| | | newLedger.setCounterReviewTime(null); |
| | | newLedger.setCounterReviewPerson(null); |
| | | newLedger.setCounterReviewPersonId(null); |
| | | newLedger.setCounterReviewType(null); |
| | | newLedger.setCounterReviewDesc(null); |
| | | salesLedgerMapper.insert(newLedger); |
| | | |
| | | // 复制产品到新台账 |
| | | List<SalesLedgerProduct> originalProducts = salesLedgerProductMapper.selectList( |
| | | Wrappers.<SalesLedgerProduct>lambdaQuery() |
| | | .eq(SalesLedgerProduct::getSalesLedgerId, id) |
| | | ); |
| | | for (SalesLedgerProduct originalProduct : originalProducts) { |
| | | SalesLedgerProduct newProduct = new SalesLedgerProduct(); |
| | | BeanUtils.copyProperties(originalProduct, newProduct); |
| | | newProduct.setId(null); |
| | | newProduct.setSalesLedgerId(newLedger.getId()); |
| | | newProduct.setStockedQuantity(BigDecimal.ZERO); |
| | | newProduct.setShippedQuantity(BigDecimal.ZERO); |
| | | newProduct.setUnqualifiedStockedQuantity(BigDecimal.ZERO); |
| | | newProduct.setUnqualifiedShippedQuantity(BigDecimal.ZERO); |
| | | newProduct.setReturnQuality(BigDecimal.ZERO); |
| | | newProduct.setAvailableQuality(newProduct.getQuantity().subtract(newProduct.getReturnQuality())); |
| | | newProduct.setProductStockStatus(0); |
| | | newProduct.fillRemainingQuantity(); |
| | | salesLedgerProductMapper.insert(newProduct); |
| | | } |
| | | newLedgerIds.add(newLedger.getId()); |
| | | } |
| | | } |
| | | return newLedgerIds; |
| | | } |
| | | |
| | | /** |
| | | * 旧版反审处理(兼容 addOrUpdateSalesLedger 中 reviewStatus=2 的调用) |
| | | */ |
| | | private void handleCounterReview(SalesLedger salesLedger) { |
| | | // 1. 设置反审相关信息 |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | salesLedger.setCounterReviewTime(LocalDateTime.now()); |
| | | salesLedger.setCounterReviewPerson(loginUser.getUser().getNickName()); |
| | | salesLedger.setCounterReviewPersonId(loginUser.getUserId()); |
| | | salesLedger.setReviewStatus(2); |
| | | |
| | | Long originalSalesLedgerId = salesLedger.getId(); |
| | | |
| | | // 2. 查询原销售台账数据 |
| | | SalesLedger originalLedger = salesLedgerMapper.selectById(originalSalesLedgerId); |
| | | if (originalLedger == null) { |
| | | throw new ServiceException("原订单不存在,无法反审"); |
| | | } |
| | | |
| | | // 3. 创建新的销售台账,复制原台账数据 |
| | | SalesLedger newLedger = new SalesLedger(); |
| | | BeanUtils.copyProperties(originalLedger, newLedger); |
| | | newLedger.setId(null); // 清空ID,准备插入新记录 |
| | | newLedger.setSalesContractNo(generateSalesContractNo()); // 生成新合同号 |
| | | newLedger.setDeliveryStatus(1); // 设置为未发货状态 |
| | | newLedger.setStockStatus(0); // 设置为未入库状态 |
| | | newLedger.setReviewStatus(0); // 设置为未审核状态 |
| | | newLedger.setCounterReviewTime(null); // 清空反审时间 |
| | | newLedger.setCounterReviewPerson(null); // 清空反审人 |
| | | newLedger.setCounterReviewPersonId(null); // 清空反审人ID |
| | | |
| | | // 4. 插入新的销售台账 |
| | | salesLedgerMapper.insert(newLedger); |
| | | |
| | | // 5. 查询并复制原台账的所有产品数据 |
| | | List<SalesLedgerProduct> originalProducts = salesLedgerProductMapper.selectList( |
| | | Wrappers.<SalesLedgerProduct>lambdaQuery() |
| | | .eq(SalesLedgerProduct::getSalesLedgerId, originalSalesLedgerId) |
| | | ); |
| | | |
| | | for (SalesLedgerProduct originalProduct : originalProducts) { |
| | | // 5.1 创建新产品记录,复制原产品数据 |
| | | SalesLedgerProduct newProduct = new SalesLedgerProduct(); |
| | | BeanUtils.copyProperties(originalProduct, newProduct); |
| | | newProduct.setId(null); // 清空ID,准备插入新记录 |
| | | newProduct.setSalesLedgerId(newLedger.getId()); // 关联到新的台账ID |
| | | newProduct.setStockedQuantity(BigDecimal.ZERO); // 已入库数量重置为0 |
| | | newProduct.setShippedQuantity(BigDecimal.ZERO); // 已出库数量重置为0 |
| | | newProduct.setUnqualifiedStockedQuantity(BigDecimal.ZERO); // 不合格入库数量重置为0 |
| | | newProduct.setUnqualifiedShippedQuantity(BigDecimal.ZERO); // 不合格出库数量重置为0 |
| | | newProduct.setReturnQuality(BigDecimal.ZERO); // 退货数量重置为0 |
| | | newProduct.setAvailableQuality(newProduct.getQuantity().subtract(newProduct.getReturnQuality())); // 重新计算可用数量 |
| | | newProduct.setProductStockStatus(0); // 产品库存状态重置为0 |
| | | newProduct.fillRemainingQuantity(); // 重新计算剩余数量 |
| | | |
| | | // 5.2 插入新产品记录 |
| | | salesLedgerProductMapper.insert(newProduct); |
| | | } |
| | | |
| | | // 6. 处理原订单的库存数据(生成反审出入库记录) |
| | | processOriginalOrderStock(originalSalesLedgerId); |
| | | |
| | | // 7. 清除原订单的质检记录 |
| | | clearQualityInspectRecords(originalSalesLedgerId); |
| | | |
| | | // 8. 清除原订单的发货信息和发货审批记录 |
| | | clearShippingAndApprovalRecords(originalSalesLedgerId); |
| | | |
| | | // 9. 取消原订单相关的审批流程 |
| | | cancelApproveProcesses(originalSalesLedgerId, originalLedger.getSalesContractNo()); |
| | | } |
| | | |
| | | /** |
| | | * 清除原订单的质检记录 |
| | | */ |
| | | private void clearQualityInspectRecords(Long originalSalesLedgerId) { |
| | | // 删除与原订单关联的质检记录 |
| | | qualityInspectMapper.delete( |
| | | Wrappers.<QualityInspect>lambdaQuery() |
| | | .eq(QualityInspect::getPurchaseLedgerId, originalSalesLedgerId) |
| | | ); |
| | | } |
| | | |
| | | /** |
| | | * 清除原订单的发货信息和发货审批记录 |
| | | */ |
| | | private void clearShippingAndApprovalRecords(Long originalSalesLedgerId) { |
| | | // 1. 查询原订单的所有发货信息 |
| | | List<ShippingInfo> shippingInfos = shippingInfoMapper.selectList( |
| | | Wrappers.<ShippingInfo>lambdaQuery() |
| | | .eq(ShippingInfo::getSalesLedgerId, originalSalesLedgerId) |
| | | ); |
| | | |
| | | // 2. 删除发货审批记录 |
| | | if (!CollectionUtils.isEmpty(shippingInfos)) { |
| | | List<Long> shippingInfoIds = shippingInfos.stream() |
| | | .map(ShippingInfo::getId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | shipmentApprovalMapper.delete( |
| | | Wrappers.<ShipmentApproval>lambdaQuery() |
| | | .eq(ShipmentApproval::getSalesLedgerId, originalSalesLedgerId) |
| | | .or() |
| | | .in(ShipmentApproval::getShippingInfoId, shippingInfoIds) |
| | | ); |
| | | |
| | | // 3. 删除发货信息记录 |
| | | shippingInfoMapper.delete( |
| | | Wrappers.<ShippingInfo>lambdaQuery() |
| | | .eq(ShippingInfo::getSalesLedgerId, originalSalesLedgerId) |
| | | ); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 取消原订单相关的审批流程 |
| | | */ |
| | | private void cancelApproveProcesses(Long originalSalesLedgerId, String originalSalesContractNo) { |
| | | // 取消入库审批流程 |
| | | List<ApproveProcess> stockInApproveProcesses = approveProcessService.list( |
| | | new LambdaQueryWrapper<ApproveProcess>() |
| | | .eq(ApproveProcess::getApproveType, ApproveTypeEnum.STOCK_IN.getCode()) |
| | | .like(ApproveProcess::getApproveRemark, "salesStock:" + originalSalesLedgerId + ":") |
| | | .eq(ApproveProcess::getApproveDelete, 0) |
| | | ); |
| | | |
| | | for (ApproveProcess process : stockInApproveProcesses) { |
| | | process.setApproveStatus(3); // 设置为审批失败状态 |
| | | process.setApproveDelete(1); // 标记为已删除 |
| | | approveProcessService.updateById(process); |
| | | } |
| | | |
| | | // 取消发货审批流程 |
| | | List<ApproveProcess> deliveryApproveProcesses = approveProcessService.list( |
| | | new LambdaQueryWrapper<ApproveProcess>() |
| | | .eq(ApproveProcess::getApproveType, 7) // 发货审批类型 |
| | | .like(ApproveProcess::getApproveReason, "发货审批:" + originalSalesContractNo) |
| | | .eq(ApproveProcess::getApproveDelete, 0) |
| | | ); |
| | | |
| | | for (ApproveProcess process : deliveryApproveProcesses) { |
| | | process.setApproveStatus(3); // 设置为审批失败状态 |
| | | process.setApproveDelete(1); // 标记为已删除 |
| | | approveProcessService.updateById(process); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理原订单的库存数据 |
| | | * 1. 删除原订单的所有入库记录,并扣减库存 |
| | | * 2. 删除原订单的所有出库记录,并增加库存 |
| | | */ |
| | | private void processOriginalOrderStock(Long originalSalesLedgerId) { |
| | | // 1. 查询原订单的所有入库记录 |
| | | List<StockInRecord> stockInRecords = stockInRecordMapper.selectList( |
| | | Wrappers.<StockInRecord>lambdaQuery() |
| | | .eq(StockInRecord::getSalesLedgerId, originalSalesLedgerId) |
| | | ); |
| | | |
| | | // 2. 删除入库记录并扣减库存 |
| | | for (StockInRecord stockInRecord : stockInRecords) { |
| | | // 从库存表中扣减相应数量 |
| | | StockInventoryDto stockInventoryDto = new StockInventoryDto(); |
| | | stockInventoryDto.setProductModelId(stockInRecord.getProductModelId()); |
| | | stockInventoryDto.setQualitity(stockInRecord.getStockInNum()); |
| | | stockInventoryMapper.updateSubtractStockInventory(stockInventoryDto); |
| | | } |
| | | |
| | | // 3. 删除所有入库记录 |
| | | stockInRecordMapper.delete( |
| | | Wrappers.<StockInRecord>lambdaQuery() |
| | | .eq(StockInRecord::getSalesLedgerId, originalSalesLedgerId) |
| | | ); |
| | | |
| | | // 4. 查询原订单的所有出库记录 |
| | | List<StockOutRecord> stockOutRecords = stockOutRecordMapper.selectList( |
| | | Wrappers.<StockOutRecord>lambdaQuery() |
| | | .eq(StockOutRecord::getSalesLedgerId, originalSalesLedgerId) |
| | | ); |
| | | |
| | | // 5. 删除出库记录并增加库存 |
| | | for (StockOutRecord stockOutRecord : stockOutRecords) { |
| | | // 向库存表中增加相应数量 |
| | | StockInventoryDto stockInventoryDto = new StockInventoryDto(); |
| | | stockInventoryDto.setProductModelId(stockOutRecord.getProductModelId()); |
| | | stockInventoryDto.setQualitity(stockOutRecord.getStockOutNum()); |
| | | stockInventoryMapper.updateAddStockInventory(stockInventoryDto); |
| | | } |
| | | |
| | | // 6. 删除所有出库记录 |
| | | stockOutRecordMapper.delete( |
| | | Wrappers.<StockOutRecord>lambdaQuery() |
| | | .eq(StockOutRecord::getSalesLedgerId, originalSalesLedgerId) |
| | | ); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void markOrderCompleted(List<Long> ids) { |
| | | if (CollectionUtils.isEmpty(ids)) { |
| | | throw new ServiceException("请选择要标记完成的订单"); |
| | | } |
| | | for (Long id : ids) { |
| | | SalesLedger ledger = salesLedgerMapper.selectById(id); |
| | | if (ledger == null) { |
| | | throw new ServiceException("订单不存在,无法标记完成"); |
| | | } |
| | | if (ledger.getReviewStatus() == null || ledger.getReviewStatus() != 1) { |
| | | throw new ServiceException("订单" + ledger.getSalesContractNo() + "不是已审核状态,无法标记完成"); |
| | | } |
| | | if (ledger.getOrderStatus() != null && ledger.getOrderStatus() == 1) { |
| | | throw new ServiceException("订单" + ledger.getSalesContractNo() + "已完成,无需重复标记"); |
| | | } |
| | | } |
| | | salesLedgerMapper.update(null, |
| | | Wrappers.<SalesLedger>lambdaUpdate() |
| | | .in(SalesLedger::getId, ids) |
| | | .set(SalesLedger::getOrderStatus, 1) |
| | | ); |
| | | } |
| | | |
| | | @Override |
| | | public void incrementPrintCount(Long id, String printType) { |
| | | if (id == null) { |
| | | throw new ServiceException("销售台账ID不能为空"); |
| | | } |
| | | if (printType == null || (!"label".equals(printType) && !"document".equals(printType))) { |
| | | throw new ServiceException("打印类型必须为 label 或 document"); |
| | | } |
| | | SalesLedger ledger = salesLedgerMapper.selectById(id); |
| | | if (ledger == null) { |
| | | throw new ServiceException("销售台账不存在"); |
| | | } |
| | | if ("label".equals(printType)) { |
| | | int currentCount = ledger.getLabelPrintCount() == null ? 0 : ledger.getLabelPrintCount(); |
| | | salesLedgerMapper.update(null, |
| | | Wrappers.<SalesLedger>lambdaUpdate() |
| | | .eq(SalesLedger::getId, id) |
| | | .set(SalesLedger::getLabelPrintCount, currentCount + 1) |
| | | ); |
| | | } else { |
| | | int currentCount = ledger.getDocumentPrintCount() == null ? 0 : ledger.getDocumentPrintCount(); |
| | | salesLedgerMapper.update(null, |
| | | Wrappers.<SalesLedger>lambdaUpdate() |
| | | .eq(SalesLedger::getId, id) |
| | | .set(SalesLedger::getDocumentPrintCount, currentCount + 1) |
| | | ); |
| | | } |
| | | } |
| | | } |