| | |
| | | package com.ruoyi.purchase.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.pojo.AccountExpense; |
| | | import com.ruoyi.account.pojo.AccountIncome; |
| | | import com.ruoyi.account.service.AccountExpenseService; |
| | | import com.ruoyi.account.service.AccountIncomeService; |
| | | import com.ruoyi.approve.pojo.ApproveProcess; |
| | | import com.ruoyi.approve.service.impl.ApproveProcessServiceImpl; |
| | | import com.ruoyi.approve.vo.ApproveProcessVO; |
| | | import com.ruoyi.basic.mapper.ProductMapper; |
| | | import com.ruoyi.basic.mapper.ProductModelMapper; |
| | | import com.ruoyi.basic.mapper.SupplierManageMapper; |
| | | import com.ruoyi.basic.pojo.Customer; |
| | | import com.ruoyi.basic.pojo.Product; |
| | | import com.ruoyi.basic.pojo.ProductModel; |
| | | import com.ruoyi.basic.pojo.SupplierManage; |
| | | import com.ruoyi.common.enums.FileNameType; |
| | | 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.exception.ServiceException; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | |
| | | import com.ruoyi.other.mapper.TempFileMapper; |
| | | import com.ruoyi.other.pojo.TempFile; |
| | | import com.ruoyi.procurementrecord.mapper.ProcurementRecordMapper; |
| | | import com.ruoyi.procurementrecord.utils.StockUtils; |
| | | import com.ruoyi.procurementrecord.pojo.ProcurementRecordStorage; |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | import com.ruoyi.purchase.dto.PurchaseLedgerDto; |
| | | import com.ruoyi.purchase.dto.PurchaseLedgerImportDto; |
| | | import com.ruoyi.purchase.dto.PurchaseLedgerProductImportDto; |
| | | import com.ruoyi.purchase.dto.PurchaseScanStockDto; |
| | | import com.ruoyi.purchase.mapper.*; |
| | | import com.ruoyi.purchase.pojo.*; |
| | | import com.ruoyi.purchase.service.IPurchaseLedgerService; |
| | | import com.ruoyi.quality.mapper.*; |
| | | import com.ruoyi.quality.pojo.*; |
| | | import com.ruoyi.sales.dto.SalesLedgerImportDto; |
| | | import com.ruoyi.sales.dto.SalesLedgerProductImportDto; |
| | | import com.ruoyi.sales.mapper.*; |
| | | import com.ruoyi.sales.pojo.CommonFile; |
| | | import com.ruoyi.sales.pojo.InvoiceRegistrationProduct; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import com.ruoyi.sales.service.impl.CommonFileServiceImpl; |
| | | import lombok.RequiredArgsConstructor; |
| | | import com.ruoyi.stock.dto.StockInventoryDto; |
| | | import com.ruoyi.stock.service.StockInventoryService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.ruoyi.common.enums.SaleEnum.PURCHASE; |
| | | |
| | | /** |
| | | * 采购台账Service业务层处理 |
| | |
| | | private PurchaseLedgerTemplateMapper purchaseLedgerTemplateMapper; |
| | | @Autowired |
| | | private SalesLedgerProductTemplateMapper salesLedgerProductTemplateMapper; |
| | | @Autowired |
| | | private StockInventoryService stockInventoryService; |
| | | @Autowired |
| | | private StockUtils stockUtils; |
| | | @Value("${file.upload-dir}") |
| | | private String uploadDir; |
| | | |
| | |
| | | if (!updateList.isEmpty()) { |
| | | for (SalesLedgerProduct product : updateList) { |
| | | product.setType(type); |
| | | product.fillRemainingQuantity(); |
| | | salesLedgerProductMapper.updateById(product); |
| | | } |
| | | } |
| | |
| | | salesLedgerProduct.setFutureTickets(salesLedgerProduct.getQuantity()); |
| | | salesLedgerProduct.setFutureTicketsAmount(salesLedgerProduct.getTaxInclusiveTotalPrice()); |
| | | salesLedgerProduct.setPendingTicketsTotal(salesLedgerProduct.getTaxInclusiveTotalPrice()); |
| | | salesLedgerProduct.fillRemainingQuantity(); |
| | | salesLedgerProductMapper.insert(salesLedgerProduct); |
| | | } |
| | | } |
| | |
| | | productWrapper.eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedger.getId()) |
| | | .eq(SalesLedgerProduct::getType, purchaseLedgerDto.getType()); |
| | | List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(productWrapper); |
| | | products.forEach(SalesLedgerProduct::fillRemainingQuantity); |
| | | |
| | | // 3.查询上传文件 |
| | | LambdaQueryWrapper<CommonFile> salesLedgerFileWrapper = new LambdaQueryWrapper<>(); |
| | |
| | | product.setTicketsAmount(null); |
| | | product.setTempFutureTickets(product.getFutureTickets()); |
| | | product.setTempFutureTicketsAmount(product.getFutureTicketsAmount()); |
| | | product.fillRemainingQuantity(); |
| | | }); |
| | | resultDto.setProductData(productList); |
| | | return resultDto; |
| | |
| | | if(salesLedgerProductImportDto.getIsChecked() == 1){ |
| | | addQualityInspect(salesLedger, salesLedgerProduct); |
| | | } |
| | | salesLedgerProduct.fillRemainingQuantity(); |
| | | salesLedgerProductMapper.insert(salesLedgerProduct); |
| | | } |
| | | // 采购审核 |
| | |
| | | productWrapper.eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedger.getId()) |
| | | .eq(SalesLedgerProduct::getType, 2); |
| | | List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(productWrapper); |
| | | products.forEach(SalesLedgerProduct::fillRemainingQuantity); |
| | | |
| | | // 4. 转换 DTO |
| | | PurchaseLedgerDto resultDto = new PurchaseLedgerDto(); |
| | |
| | | approveProcessService.addApprove(approveProcessVO); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void scanInbound(PurchaseScanStockDto dto) { |
| | | if (dto == null || dto.getPurchaseLedgerId() == null) { |
| | | throw new ServiceException("采购入库失败,入库数据不能为空"); |
| | | } |
| | | PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(dto.getPurchaseLedgerId()); |
| | | if (purchaseLedger == null) { |
| | | throw new ServiceException("入库失败,采购台账不存在"); |
| | | } |
| | | if (CollectionUtils.isEmpty(dto.getSalesLedgerProductList())) { |
| | | throw new ServiceException("采购入库失败,入库产品不能为空"); |
| | | } |
| | | int purchaseType = PURCHASE.getCode(); |
| | | Map<Long, BigDecimal> inboundQtyByLineId = new LinkedHashMap<>(); |
| | | for (SalesLedgerProduct inbound : dto.getSalesLedgerProductList()) { |
| | | if (inbound == null || inbound.getId() == null) { |
| | | throw new ServiceException("入库失败,采购产品信息不完整"); |
| | | } |
| | | BigDecimal inboundQty = inbound.getStockedQuantity(); |
| | | if (inboundQty == null) { |
| | | throw new ServiceException("入库失败,入库数量不能为空"); |
| | | } |
| | | if (inboundQty.compareTo(BigDecimal.ZERO) < 0) { |
| | | throw new ServiceException("入库失败,入库数量不能为负数"); |
| | | } |
| | | inboundQtyByLineId.merge(inbound.getId(), inboundQty, BigDecimal::add); |
| | | } |
| | | Long purchaseId = purchaseLedger.getId(); |
| | | for (Map.Entry<Long, BigDecimal> entry : inboundQtyByLineId.entrySet()) { |
| | | Long productLineId = entry.getKey(); |
| | | BigDecimal inboundThisLine = entry.getValue(); |
| | | if (inboundThisLine.compareTo(BigDecimal.ZERO) == 0) { |
| | | continue; |
| | | } |
| | | SalesLedgerProduct dbProduct = salesLedgerProductMapper.selectById(productLineId); |
| | | if (dbProduct == null) { |
| | | throw new ServiceException("入库失败,采购产品不存在"); |
| | | } |
| | | if (!Objects.equals(dbProduct.getSalesLedgerId(), purchaseId) || !Objects.equals(dbProduct.getType(), purchaseType)) { |
| | | throw new ServiceException("入库失败,产品与采购台账不匹配"); |
| | | } |
| | | if (dbProduct.getProductModelId() == null) { |
| | | throw new ServiceException("入库失败,产品规格未维护,无法入库"); |
| | | } |
| | | BigDecimal oldStocked = dbProduct.getStockedQuantity() == null ? BigDecimal.ZERO : dbProduct.getStockedQuantity(); |
| | | BigDecimal newStocked = oldStocked.add(inboundThisLine); |
| | | |
| | | StockInventoryDto stockInventoryDto = new StockInventoryDto(); |
| | | stockInventoryDto.setRecordId(dbProduct.getId()); |
| | | stockInventoryDto.setRecordType(StockInQualifiedRecordTypeEnum.PURCHASE_SCAN_STOCK_IN.getCode()); |
| | | stockInventoryDto.setQualitity(inboundThisLine); |
| | | stockInventoryDto.setProductModelId(dbProduct.getProductModelId()); |
| | | stockInventoryDto.setSalesLedgerId(null); |
| | | stockInventoryDto.setSalesLedgerProductId(dbProduct.getId()); |
| | | stockInventoryService.addstockInventory(stockInventoryDto); |
| | | |
| | | BigDecimal orderQty = dbProduct.getQuantity() == null ? BigDecimal.ZERO : dbProduct.getQuantity(); |
| | | int lineStockStatus; |
| | | if (newStocked.compareTo(BigDecimal.ZERO) <= 0) { |
| | | lineStockStatus = 0; |
| | | } else if (orderQty.compareTo(BigDecimal.ZERO) > 0 && newStocked.compareTo(orderQty) < 0) { |
| | | lineStockStatus = 1; |
| | | } else { |
| | | lineStockStatus = 2; |
| | | } |
| | | dbProduct.setStockedQuantity(newStocked); |
| | | dbProduct.setProductStockStatus(lineStockStatus); |
| | | dbProduct.fillRemainingQuantity(); |
| | | salesLedgerProductMapper.updateById(dbProduct); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void scanOutbound(PurchaseScanStockDto dto) { |
| | | if (dto == null || dto.getPurchaseLedgerId() == null) { |
| | | throw new ServiceException("采购出库失败,出库数据不能为空"); |
| | | } |
| | | PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(dto.getPurchaseLedgerId()); |
| | | if (purchaseLedger == null) { |
| | | throw new ServiceException("出库失败,采购台账不存在"); |
| | | } |
| | | if (CollectionUtils.isEmpty(dto.getSalesLedgerProductList())) { |
| | | throw new ServiceException("采购出库失败,出库产品不能为空"); |
| | | } |
| | | int purchaseType = PURCHASE.getCode(); |
| | | Map<Long, BigDecimal> outboundQtyByLineId = new LinkedHashMap<>(); |
| | | for (SalesLedgerProduct line : dto.getSalesLedgerProductList()) { |
| | | if (line == null || line.getId() == null) { |
| | | throw new ServiceException("出库失败,采购产品信息不完整"); |
| | | } |
| | | BigDecimal outboundQty = line.getStockedQuantity(); |
| | | if (outboundQty == null) { |
| | | throw new ServiceException("出库失败,出库数量不能为空"); |
| | | } |
| | | if (outboundQty.compareTo(BigDecimal.ZERO) < 0) { |
| | | throw new ServiceException("出库失败,出库数量不能为负数"); |
| | | } |
| | | outboundQtyByLineId.merge(line.getId(), outboundQty, BigDecimal::add); |
| | | } |
| | | Long purchaseId = purchaseLedger.getId(); |
| | | for (Map.Entry<Long, BigDecimal> entry : outboundQtyByLineId.entrySet()) { |
| | | Long productLineId = entry.getKey(); |
| | | BigDecimal outboundThisLine = entry.getValue(); |
| | | if (outboundThisLine.compareTo(BigDecimal.ZERO) == 0) { |
| | | continue; |
| | | } |
| | | SalesLedgerProduct dbProduct = salesLedgerProductMapper.selectById(productLineId); |
| | | if (dbProduct == null) { |
| | | throw new ServiceException("出库失败,采购产品不存在"); |
| | | } |
| | | if (!Objects.equals(dbProduct.getSalesLedgerId(), purchaseId) || !Objects.equals(dbProduct.getType(), purchaseType)) { |
| | | throw new ServiceException("出库失败,产品与采购台账不匹配"); |
| | | } |
| | | if (dbProduct.getProductModelId() == null) { |
| | | throw new ServiceException("出库失败,产品规格未维护,无法出库"); |
| | | } |
| | | stockUtils.assertQualifiedAvailable(dbProduct.getProductModelId(), outboundThisLine); |
| | | |
| | | BigDecimal oldStocked = dbProduct.getStockedQuantity() == null ? BigDecimal.ZERO : dbProduct.getStockedQuantity(); |
| | | BigDecimal newStocked = oldStocked.subtract(outboundThisLine); |
| | | if (newStocked.compareTo(BigDecimal.ZERO) < 0) { |
| | | newStocked = BigDecimal.ZERO; |
| | | } |
| | | |
| | | StockInventoryDto stockInventoryDto = new StockInventoryDto(); |
| | | stockInventoryDto.setRecordId(dbProduct.getId()); |
| | | stockInventoryDto.setRecordType(StockOutQualifiedRecordTypeEnum.PURCHASE_SCAN_STOCK_OUT.getCode()); |
| | | stockInventoryDto.setQualitity(outboundThisLine); |
| | | stockInventoryDto.setProductModelId(dbProduct.getProductModelId()); |
| | | stockInventoryDto.setSalesLedgerId(null); |
| | | stockInventoryDto.setSalesLedgerProductId(dbProduct.getId()); |
| | | stockInventoryService.subtractStockInventory(stockInventoryDto); |
| | | |
| | | BigDecimal orderQty = dbProduct.getQuantity() == null ? BigDecimal.ZERO : dbProduct.getQuantity(); |
| | | int lineStockStatus; |
| | | if (newStocked.compareTo(BigDecimal.ZERO) <= 0) { |
| | | lineStockStatus = 0; |
| | | } else if (orderQty.compareTo(BigDecimal.ZERO) > 0 && newStocked.compareTo(orderQty) < 0) { |
| | | lineStockStatus = 1; |
| | | } else { |
| | | lineStockStatus = 2; |
| | | } |
| | | dbProduct.setStockedQuantity(newStocked); |
| | | dbProduct.setProductStockStatus(lineStockStatus); |
| | | dbProduct.fillRemainingQuantity(); |
| | | salesLedgerProductMapper.updateById(dbProduct); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void scanInboundUnqualified(PurchaseScanStockDto dto) { |
| | | if (dto == null || dto.getPurchaseLedgerId() == null) { |
| | | throw new ServiceException("采购不合格入库失败,入库数据不能为空"); |
| | | } |
| | | PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(dto.getPurchaseLedgerId()); |
| | | if (purchaseLedger == null) { |
| | | throw new ServiceException("不合格入库失败,采购台账不存在"); |
| | | } |
| | | if (CollectionUtils.isEmpty(dto.getSalesLedgerProductList())) { |
| | | throw new ServiceException("采购不合格入库失败,入库产品不能为空"); |
| | | } |
| | | int purchaseType = PURCHASE.getCode(); |
| | | Map<Long, BigDecimal> inboundQtyByLineId = new LinkedHashMap<>(); |
| | | for (SalesLedgerProduct inbound : dto.getSalesLedgerProductList()) { |
| | | if (inbound == null || inbound.getId() == null) { |
| | | throw new ServiceException("不合格入库失败,采购产品信息不完整"); |
| | | } |
| | | BigDecimal inboundQty = inbound.getStockedQuantity(); |
| | | if (inboundQty == null) { |
| | | throw new ServiceException("不合格入库失败,入库数量不能为空"); |
| | | } |
| | | if (inboundQty.compareTo(BigDecimal.ZERO) < 0) { |
| | | throw new ServiceException("不合格入库失败,入库数量不能为负数"); |
| | | } |
| | | inboundQtyByLineId.merge(inbound.getId(), inboundQty, BigDecimal::add); |
| | | } |
| | | Long purchaseId = purchaseLedger.getId(); |
| | | for (Map.Entry<Long, BigDecimal> entry : inboundQtyByLineId.entrySet()) { |
| | | Long productLineId = entry.getKey(); |
| | | BigDecimal inboundThisLine = entry.getValue(); |
| | | if (inboundThisLine.compareTo(BigDecimal.ZERO) == 0) { |
| | | continue; |
| | | } |
| | | SalesLedgerProduct dbProduct = salesLedgerProductMapper.selectById(productLineId); |
| | | if (dbProduct == null) { |
| | | throw new ServiceException("不合格入库失败,采购产品不存在"); |
| | | } |
| | | if (!Objects.equals(dbProduct.getSalesLedgerId(), purchaseId) || !Objects.equals(dbProduct.getType(), purchaseType)) { |
| | | throw new ServiceException("不合格入库失败,产品与采购台账不匹配"); |
| | | } |
| | | if (dbProduct.getProductModelId() == null) { |
| | | throw new ServiceException("不合格入库失败,产品规格未维护,无法入库"); |
| | | } |
| | | stockUtils.addUnStock(null, null, dbProduct.getProductModelId(), inboundThisLine, |
| | | StockInUnQualifiedRecordTypeEnum.PURCHASE_SCAN_UNSTOCK_IN.getCode(), dbProduct.getId()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void scanOutboundUnqualified(PurchaseScanStockDto dto) { |
| | | if (dto == null || dto.getPurchaseLedgerId() == null) { |
| | | throw new ServiceException("采购不合格出库失败,出库数据不能为空"); |
| | | } |
| | | PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(dto.getPurchaseLedgerId()); |
| | | if (purchaseLedger == null) { |
| | | throw new ServiceException("不合格出库失败,采购台账不存在"); |
| | | } |
| | | if (CollectionUtils.isEmpty(dto.getSalesLedgerProductList())) { |
| | | throw new ServiceException("采购不合格出库失败,出库产品不能为空"); |
| | | } |
| | | int purchaseType = PURCHASE.getCode(); |
| | | Map<Long, BigDecimal> outboundQtyByLineId = new LinkedHashMap<>(); |
| | | for (SalesLedgerProduct line : dto.getSalesLedgerProductList()) { |
| | | if (line == null || line.getId() == null) { |
| | | throw new ServiceException("不合格出库失败,采购产品信息不完整"); |
| | | } |
| | | BigDecimal outboundQty = line.getStockedQuantity(); |
| | | if (outboundQty == null) { |
| | | throw new ServiceException("不合格出库失败,出库数量不能为空"); |
| | | } |
| | | if (outboundQty.compareTo(BigDecimal.ZERO) < 0) { |
| | | throw new ServiceException("不合格出库失败,出库数量不能为负数"); |
| | | } |
| | | outboundQtyByLineId.merge(line.getId(), outboundQty, BigDecimal::add); |
| | | } |
| | | Long purchaseId = purchaseLedger.getId(); |
| | | for (Map.Entry<Long, BigDecimal> entry : outboundQtyByLineId.entrySet()) { |
| | | Long productLineId = entry.getKey(); |
| | | BigDecimal outboundThisLine = entry.getValue(); |
| | | if (outboundThisLine.compareTo(BigDecimal.ZERO) == 0) { |
| | | continue; |
| | | } |
| | | SalesLedgerProduct dbProduct = salesLedgerProductMapper.selectById(productLineId); |
| | | if (dbProduct == null) { |
| | | throw new ServiceException("不合格出库失败,采购产品不存在"); |
| | | } |
| | | if (!Objects.equals(dbProduct.getSalesLedgerId(), purchaseId) || !Objects.equals(dbProduct.getType(), purchaseType)) { |
| | | throw new ServiceException("不合格出库失败,产品与采购台账不匹配"); |
| | | } |
| | | if (dbProduct.getProductModelId() == null) { |
| | | throw new ServiceException("不合格出库失败,产品规格未维护,无法出库"); |
| | | } |
| | | stockUtils.assertUnqualifiedAvailable(dbProduct.getProductModelId(), outboundThisLine); |
| | | stockUtils.subtractUnStock(null, null, dbProduct.getProductModelId(), outboundThisLine, |
| | | StockOutUnQualifiedRecordTypeEnum.PURCHASE_SCAN_UNSTOCK_OUT.getCode(), dbProduct.getId()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 下划线命名转驼峰命名 |
| | | */ |