| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.enums.ApprovalStatusEnum; |
| | | import com.ruoyi.common.enums.ReviewStatusEnum; |
| | | import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum; |
| | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.purchase.mapper.PurchaseLedgerMapper; |
| | | import com.ruoyi.purchase.pojo.PurchaseLedger; |
| | | import com.ruoyi.quality.mapper.QualityInspectMapper; |
| | | import com.ruoyi.quality.pojo.QualityInspect; |
| | | import com.ruoyi.stock.dto.StockInRecordDto; |
| | | import com.ruoyi.stock.dto.StockInventoryDto; |
| | | import com.ruoyi.stock.dto.StockUninventoryDto; |
| | | import com.ruoyi.stock.execl.StockInRecordExportData; |
| | | import com.ruoyi.production.mapper.ProductionOrderPickMapper; |
| | | import com.ruoyi.production.pojo.ProductionOrderPick; |
| | | import com.ruoyi.stock.mapper.StockInRecordMapper; |
| | | import com.ruoyi.stock.mapper.StockInventoryMapper; |
| | | import com.ruoyi.stock.mapper.StockUninventoryMapper; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | |
| | | private StockInRecordMapper stockInRecordMapper; |
| | | private StockInventoryMapper stockInventoryMapper; |
| | | private StockUninventoryMapper stockUninventoryMapper; |
| | | private ProductionOrderPickMapper productionOrderPickMapper; |
| | | private PurchaseLedgerMapper purchaseLedgerMapper; |
| | | private QualityInspectMapper qualityInspectMapper; |
| | | |
| | | @Override |
| | | public IPage<StockInRecordDto> listPage(Page page, StockInRecordDto stockInRecordDto) { |
| | |
| | | return stockUninventoryMapper.selectOne(eq); |
| | | } |
| | | |
| | | /** |
| | | * 回滚生产退料入库的领料记录退料数量 |
| | | * @param stockInRecord 入库记录 |
| | | */ |
| | | private void rollbackFeedReturnQty(StockInRecord stockInRecord) { |
| | | ProductionOrderPick productionOrderPick = productionOrderPickMapper.selectById(stockInRecord.getRecordId()); |
| | | if (productionOrderPick != null) { |
| | | BigDecimal returnQty = productionOrderPick.getReturnQty(); |
| | | if (returnQty == null) { |
| | | returnQty = BigDecimal.ZERO; |
| | | } |
| | | BigDecimal newReturnQty = returnQty.subtract(stockInRecord.getStockInNum()); |
| | | if (newReturnQty.compareTo(BigDecimal.ZERO) < 0) { |
| | | newReturnQty = BigDecimal.ZERO; |
| | | } |
| | | productionOrderPick.setReturnQty(newReturnQty); |
| | | // 重新计算实际用量 |
| | | BigDecimal actualQty = productionOrderPick.getQuantity().add( |
| | | productionOrderPick.getFeedingQty() != null ? productionOrderPick.getFeedingQty() : BigDecimal.ZERO) |
| | | .subtract(newReturnQty); |
| | | productionOrderPick.setActualQty(actualQty); |
| | | productionOrderPick.setReturned(newReturnQty.compareTo(BigDecimal.ZERO) > 0); |
| | | productionOrderPickMapper.updateById(productionOrderPick); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int batchDeletePending(List<Long> ids) { |
| | |
| | | } |
| | | if (stockInRecord.getApprovalStatus() != null && !ReviewStatusEnum.PENDING_REVIEW.getCode().equals(stockInRecord.getApprovalStatus())) { |
| | | throw new BaseException("只有待审批状态的记录才能删除,入库批次:" + stockInRecord.getInboundBatches()); |
| | | } |
| | | |
| | | // 如果是生产退料入库,删除时需要回滚领料记录的退料数量 |
| | | if (StockInQualifiedRecordTypeEnum.FEED_RETURN_IN.getCode().equals(stockInRecord.getRecordType())) { |
| | | rollbackFeedReturnQty(stockInRecord); |
| | | } |
| | | } |
| | | return stockInRecordMapper.deleteBatchIds(ids); |
| | |
| | | } |
| | | stockInRecord.setApprovalStatus(approvalStatus); |
| | | stockInRecordMapper.updateById(stockInRecord); |
| | | |
| | | // 审批驳回时,如果是生产退料入库,需要回滚领料记录的退料数量 |
| | | if (ReviewStatusEnum.REJECTED.getCode().equals(approvalStatus) && |
| | | StockInQualifiedRecordTypeEnum.FEED_RETURN_IN.getCode().equals(stockInRecord.getRecordType())) { |
| | | rollbackFeedReturnQty(stockInRecord); |
| | | } |
| | | |
| | | // 审批通过时,库存增加 |
| | | if (ReviewStatusEnum.APPROVED.getCode().equals(approvalStatus)) { |
| | | if ("0".equals(stockInRecord.getType())) { |
| | |
| | | setQualitity(stockInRecord.getStockInNum()); |
| | | setBatchNo(stockInRecord.getBatchNo()); |
| | | setRemark(stockInRecord.getRemark()); |
| | | setWarnNum(stockInRecord.getWarnNum()); |
| | | setVersion(1); |
| | | }}); |
| | | } else { |
| | |
| | | stockUninventoryMapper.updateAddStockUnInventory(stockUninventoryDto); |
| | | } |
| | | } |
| | | |
| | | // 采购相关入库审批通过时,回写采购台账状态为已通过 |
| | | String recordType = stockInRecord.getRecordType(); |
| | | Long purchaseLedgerId = null; |
| | | if (StockInQualifiedRecordTypeEnum.PURCHASE_STOCK_IN.getCode().equals(recordType)) { |
| | | // 采购直接入库:recordId 就是采购台账ID |
| | | purchaseLedgerId = stockInRecord.getRecordId(); |
| | | } else if (StockInQualifiedRecordTypeEnum.CUSTOMIZATION_UNSTOCK_OUT.getCode().equals(recordType)) { |
| | | // 采购质检合格入库:recordId 是质检单ID,需通过质检单找到采购台账ID |
| | | Long qualityInspectId = stockInRecord.getRecordId(); |
| | | if (qualityInspectId != null) { |
| | | QualityInspect qualityInspect = qualityInspectMapper.selectById(qualityInspectId); |
| | | if (qualityInspect != null) { |
| | | purchaseLedgerId = qualityInspect.getPurchaseLedgerId(); |
| | | } |
| | | } |
| | | } |
| | | if (purchaseLedgerId != null) { |
| | | PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(purchaseLedgerId); |
| | | if (purchaseLedger != null && !ApprovalStatusEnum.APPROVED.getCode().equals(purchaseLedger.getApprovalStatus())) { |
| | | purchaseLedger.setApprovalStatus(ApprovalStatusEnum.APPROVED.getCode()); |
| | | purchaseLedgerMapper.updateById(purchaseLedger); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return ids.size(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int batchReAudit(List<Long> ids) { |
| | | if (CollectionUtils.isEmpty(ids)) { |
| | | throw new BaseException("请选择至少一条数据"); |
| | | } |
| | | |
| | | for (Long id : ids) { |
| | | StockInRecord stockInRecord = stockInRecordMapper.selectById(id); |
| | | if (stockInRecord == null) { |
| | | throw new BaseException("入库记录不存在,无法重新审核!!!"); |
| | | } |
| | | // 只有驳回状态才能重新审核 |
| | | if (!ReviewStatusEnum.REJECTED.getCode().equals(stockInRecord.getApprovalStatus())) { |
| | | throw new BaseException("只有驳回状态的记录才能重新审核,入库批次:" + stockInRecord.getInboundBatches()); |
| | | } |
| | | |
| | | // 如果是生产退料入库,恢复退料数量(因为驳回时已扣减) |
| | | if (StockInQualifiedRecordTypeEnum.FEED_RETURN_IN.getCode().equals(stockInRecord.getRecordType())) { |
| | | ProductionOrderPick productionOrderPick = productionOrderPickMapper.selectById(stockInRecord.getRecordId()); |
| | | if (productionOrderPick != null) { |
| | | BigDecimal returnQty = productionOrderPick.getReturnQty(); |
| | | if (returnQty == null) { |
| | | returnQty = BigDecimal.ZERO; |
| | | } |
| | | // 重新审核时恢复退料数量 |
| | | BigDecimal newReturnQty = returnQty.add(stockInRecord.getStockInNum()); |
| | | productionOrderPick.setReturnQty(newReturnQty); |
| | | // 重新计算实际用量 |
| | | BigDecimal actualQty = productionOrderPick.getQuantity().add( |
| | | productionOrderPick.getFeedingQty() != null ? productionOrderPick.getFeedingQty() : BigDecimal.ZERO) |
| | | .subtract(newReturnQty); |
| | | productionOrderPick.setActualQty(actualQty); |
| | | productionOrderPick.setReturned(newReturnQty.compareTo(BigDecimal.ZERO) > 0); |
| | | productionOrderPickMapper.updateById(productionOrderPick); |
| | | } |
| | | } |
| | | |
| | | // 将状态改为待审核 |
| | | stockInRecord.setApprovalStatus(ReviewStatusEnum.PENDING_REVIEW.getCode()); |
| | | stockInRecordMapper.updateById(stockInRecord); |
| | | } |
| | | |
| | | return ids.size(); |
| | | } |
| | | } |