| | |
| | | import com.ruoyi.approve.pojo.ApproveProcess; |
| | | import com.ruoyi.approve.service.impl.ApproveProcessServiceImpl; |
| | | import com.ruoyi.common.enums.FileNameType; |
| | | import com.ruoyi.common.enums.StockQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum; |
| | | import com.ruoyi.other.service.impl.TempFileServiceImpl; |
| | | import com.ruoyi.procurementrecord.utils.StockUtils; |
| | | import com.ruoyi.sales.dto.SalesLedgerProductDto; |
| | | import com.ruoyi.sales.dto.ShippingInfoDto; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.mapper.ShippingInfoMapper; |
| | |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | |
| | | //扣减库存 |
| | | if(!"已发货".equals(byId.getStatus())){ |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(byId.getSalesLedgerProductId()); |
| | | stockUtils.substractStock(salesLedgerProduct.getProductModelId(), salesLedgerProduct.getQuantity(), StockQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId()); |
| | | stockUtils.substractStock(salesLedgerProduct.getProductModelId(), salesLedgerProduct.getQuantity(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId()); |
| | | } |
| | | byId.setExpressNumber(req.getExpressNumber()); |
| | | byId.setExpressCompany(req.getExpressCompany()); |
| | | byId.setStatus("已发货"); |
| | | byId.setShippingCarNumber(req.getShippingCarNumber()); |
| | | boolean update = this.updateById(req); |
| | | byId.setShippingDate(req.getShippingDate()); |
| | | boolean update = this.updateById(byId); |
| | | // 迁移文件 |
| | | if(CollectionUtils.isNotEmpty(req.getTempFileIds())){ |
| | | tempFileService.migrateTempFilesToFormal(req.getId(), req.getTempFileIds(), FileNameType.SHIP.getValue()); |
| | |
| | | // 扣已发货库存 |
| | | for (ShippingInfo shippingInfo : shippingInfos) { |
| | | if("已发货".equals(shippingInfo.getStatus())) { |
| | | stockUtils.deleteStockOutRecord(shippingInfo.getId(), StockQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode()); |
| | | stockUtils.deleteStockOutRecord(shippingInfo.getId(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode()); |
| | | } |
| | | } |
| | | // 删除发货审批 |
| | |
| | | |
| | | return this.removeBatchByIds(ids); |
| | | } |
| | | |
| | | @Override |
| | | public List<SalesLedgerProductDto> getReturnManagementDtoById(Long shippingId) { |
| | | return shippingInfoMapper.getReturnManagementDtoById(shippingId ); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public List<ShippingInfo> getShippingInfoByCustomerName(String customerName) { |
| | | return shippingInfoMapper.getShippingInfoByCustomerName(customerName); |
| | | } |
| | | |
| | | /** |
| | | * 一键发货 - 自动审批通过并出库 |
| | | * 不创建审批流程,直接扣减库存 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public boolean oneClickShipping(ShippingInfoDto req) throws IOException { |
| | | // 获取销售台账产品信息 |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(req.getSalesLedgerProductId()); |
| | | if (salesLedgerProduct == null) { |
| | | throw new RuntimeException("销售产品不存在"); |
| | | } |
| | | |
| | | // 生成发货单号 |
| | | String shippingNo = com.ruoyi.common.utils.OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SH", "shipping_no"); |
| | | |
| | | // 创建发货记录,状态直接为"已发货" |
| | | ShippingInfo shippingInfo = new ShippingInfo(); |
| | | shippingInfo.setShippingNo(shippingNo); |
| | | shippingInfo.setSalesLedgerId(req.getSalesLedgerId()); |
| | | shippingInfo.setSalesLedgerProductId(req.getSalesLedgerProductId()); |
| | | shippingInfo.setType(req.getType()); |
| | | shippingInfo.setShippingDate(req.getShippingDate()); |
| | | shippingInfo.setShippingCarNumber(req.getShippingCarNumber()); |
| | | shippingInfo.setExpressCompany(req.getExpressCompany()); |
| | | shippingInfo.setExpressNumber(req.getExpressNumber()); |
| | | shippingInfo.setStatus("已发货"); |
| | | boolean save = this.save(shippingInfo); |
| | | |
| | | if (save) { |
| | | // 直接扣减库存 |
| | | stockUtils.substractStock( |
| | | salesLedgerProduct.getProductModelId(), |
| | | salesLedgerProduct.getQuantity(), |
| | | StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), |
| | | shippingInfo.getId() |
| | | ); |
| | | |
| | | // 迁移附件 |
| | | if (CollectionUtils.isNotEmpty(req.getTempFileIds())) { |
| | | tempFileService.migrateTempFilesToFormal(shippingInfo.getId(), req.getTempFileIds(), FileNameType.SHIP.getValue()); |
| | | } |
| | | } |
| | | |
| | | return save; |
| | | } |
| | | |
| | | /** |
| | | * 批量一键发货 - 将销售台账下所有未发货的产品全部发货 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public boolean batchOneClickShipping(Long salesLedgerId, ShippingInfoDto req) throws IOException { |
| | | // 查询该销售台账下所有产品 |
| | | List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList( |
| | | new LambdaQueryWrapper<SalesLedgerProduct>() |
| | | .eq(SalesLedgerProduct::getSalesLedgerId, salesLedgerId) |
| | | .eq(SalesLedgerProduct::getType, 1) // 销售类型 |
| | | ); |
| | | |
| | | if (CollectionUtils.isEmpty(products)) { |
| | | throw new RuntimeException("该销售台账下没有产品"); |
| | | } |
| | | |
| | | // 过滤出未发货的产品(没有发货记录或发货状态不是"已发货") |
| | | List<SalesLedgerProduct> unshippedProducts = new ArrayList<>(); |
| | | for (SalesLedgerProduct product : products) { |
| | | ShippingInfo existingShipping = shippingInfoMapper.selectOne( |
| | | new LambdaQueryWrapper<ShippingInfo>() |
| | | .eq(ShippingInfo::getSalesLedgerProductId, product.getId()) |
| | | .eq(ShippingInfo::getStatus, "已发货") |
| | | .last("limit 1") |
| | | ); |
| | | if (existingShipping == null) { |
| | | unshippedProducts.add(product); |
| | | } |
| | | } |
| | | |
| | | if (CollectionUtils.isEmpty(unshippedProducts)) { |
| | | throw new RuntimeException("该销售台账下所有产品已发货"); |
| | | } |
| | | |
| | | // 为每个未发货的产品创建发货记录 |
| | | for (SalesLedgerProduct product : unshippedProducts) { |
| | | // 生成发货单号 |
| | | String shippingNo = com.ruoyi.common.utils.OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SH", "shipping_no"); |
| | | |
| | | // 创建发货记录 |
| | | ShippingInfo shippingInfo = new ShippingInfo(); |
| | | shippingInfo.setShippingNo(shippingNo); |
| | | shippingInfo.setSalesLedgerId(salesLedgerId); |
| | | shippingInfo.setSalesLedgerProductId(product.getId()); |
| | | shippingInfo.setType(req.getType()); |
| | | shippingInfo.setShippingDate(req.getShippingDate()); |
| | | shippingInfo.setShippingCarNumber(req.getShippingCarNumber()); |
| | | shippingInfo.setExpressCompany(req.getExpressCompany()); |
| | | shippingInfo.setExpressNumber(req.getExpressNumber()); |
| | | shippingInfo.setStatus("已发货"); |
| | | |
| | | boolean save = this.save(shippingInfo); |
| | | if (save) { |
| | | // 扣减库存 |
| | | stockUtils.substractStock( |
| | | product.getProductModelId(), |
| | | product.getQuantity(), |
| | | StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), |
| | | shippingInfo.getId() |
| | | ); |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | } |