liding
2 天以前 b28173836631e9ecb1aafbaa5786c0383462208e
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -24,18 +24,18 @@
import com.ruoyi.other.mapper.TempFileMapper;
import com.ruoyi.other.pojo.TempFile;
import com.ruoyi.production.mapper.*;
import com.ruoyi.production.pojo.*;
import com.ruoyi.production.service.ProductionProductMainService;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SysDeptMapper;
import com.ruoyi.project.system.mapper.SysUserMapper;
import com.ruoyi.quality.mapper.QualityInspectMapper;
import com.ruoyi.quality.pojo.QualityInspect;
import com.ruoyi.sales.dto.*;
import com.ruoyi.sales.mapper.*;
import com.ruoyi.sales.pojo.*;
import com.ruoyi.sales.service.ISalesLedgerProductService;
import com.ruoyi.sales.service.ISalesLedgerService;
import com.ruoyi.stock.dto.StockInventoryDto;
import com.ruoyi.stock.mapper.StockInventoryMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
@@ -128,6 +128,9 @@
    private final QualityInspectMapper qualityInspectMapper;
    private final StockInventoryMapper stockInventoryMapper;
    @Autowired
    private SysDeptMapper sysDeptMapper;
@@ -146,7 +149,9 @@
    private ProductMapper productMapper;
    @Autowired
    private ProductStructureMapper productStructureMapper;
;
    @Autowired
    private ProductionProductMainService productionProductMainService;
    ;
    @Override
    public List<SalesLedger> selectSalesLedgerList(SalesLedgerDto salesLedgerDto) {
@@ -178,7 +183,7 @@
                    .eq(ShippingInfo::getSalesLedgerProductId, product.getId())
                    .orderByDesc(ShippingInfo::getCreateTime)
                    .last("limit 1"));
            if(shippingInfo != null){
            if (shippingInfo != null) {
                product.setShippingStatus(shippingInfo.getStatus());
            }
        }
@@ -350,7 +355,7 @@
//            // 产品大类数据
//            List<Product> productList = productMapper.selectList(new LambdaQueryWrapper<Product>().in(Product::getProductName,
//                    salesLedgerProductImportDtoList.stream().map(SalesLedgerImportDto::getProductCategory).collect(Collectors.toList())));
            List<Map<String,Object>> list = productModelMapper.getProductAndModelList();
            List<Map<String, Object>> list = productModelMapper.getProductAndModelList();
            // 录入人数据
            List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>().in(SysUser::getNickName,
                    salesLedgerImportDtoList.stream().map(SalesLedgerImportDto::getEntryPerson).collect(Collectors.toList())));
@@ -358,7 +363,7 @@
                SalesLedger salesLedger1 = salesLedgerMapper.selectOne(new LambdaQueryWrapper<SalesLedger>()
                        .eq(SalesLedger::getSalesContractNo, salesLedgerImportDto.getSalesContractNo())
                        .last("LIMIT 1"));
                if(salesLedger1 != null){
                if (salesLedger1 != null) {
                    continue;
                }
                SalesLedger salesLedger = new SalesLedger();
@@ -391,7 +396,7 @@
                    throw new RuntimeException("销售单号:" + salesLedgerImportDto.getSalesContractNo() + ",无对应产品数据!");
                salesLedger.setContractAmount(salesLedgerProductImportDtos.stream()
                        .map(SalesLedgerProductImportDto::getTaxInclusiveTotalPrice)
                        .reduce(BigDecimal.ZERO,BigDecimal::add));
                        .reduce(BigDecimal.ZERO, BigDecimal::add));
                salesLedgerMapper.insert(salesLedger);
@@ -553,25 +558,20 @@
        // 删除发货台账记录
        List<ShippingInfo> shippingInfos = shippingInfoMapper.selectList(new LambdaQueryWrapper<ShippingInfo>()
                .in(ShippingInfo::getSalesLedgerId, idList));
        if(CollectionUtils.isNotEmpty(shippingInfos)){
        if (CollectionUtils.isNotEmpty(shippingInfos)) {
            shippingInfoServiceImpl.delete(shippingInfos.stream().map(ShippingInfo::getId).collect(Collectors.toList()));
        }
        // 删除附件表
        commonFileService.deleteByBusinessIds(idList, FileNameType.SALE.getValue());
        // 删除生产管控数据
        // 删除生产订单数据
        LambdaQueryWrapper<SalesLedgerScheduling> in = new LambdaQueryWrapper<SalesLedgerScheduling>()
                .in(SalesLedgerScheduling::getSalesLedgerId, idList);
        salesLedgerSchedulingMapper.delete(in);
        // 删除生产派工数据
        LambdaQueryWrapper<SalesLedgerWork> workOrderWrapper = new LambdaQueryWrapper<>();
        workOrderWrapper.in(SalesLedgerWork::getSalesLedgerId, idList);
        salesLedgerWorkMapper.delete(workOrderWrapper);
        // 删除生产核算数据
        LambdaQueryWrapper<SalesLedgerProductionAccounting> reportWrapper = new LambdaQueryWrapper<>();
        reportWrapper.in(SalesLedgerProductionAccounting::getSalesLedgerId, idList);
        salesLedgerProductionAccountingMapper.delete(reportWrapper);
        //查询生产报工id
        ArrayList<Long> mainIdList = productionProductMainService.listMain(idList);
        if (CollectionUtils.isNotEmpty(mainIdList)) {
            mainIdList.stream().forEach(mainId -> {
                productionProductMainService.removeProductMain(mainId);
            });
        }
        // 2. 再删除主表数据
        return salesLedgerMapper.deleteBatchIds(idList);
    }
@@ -709,9 +709,26 @@
        List<SalesLedgerProduct> updateList = partitionedProducts.get(true);
        List<SalesLedgerProduct> insertList = partitionedProducts.get(false);
        List<StockInventoryDto> stockInventoryDtos = stockInventoryMapper.selectProductList();
        // 执行更新操作
        if (!updateList.isEmpty()) {
            for (SalesLedgerProduct product : updateList) {
                // 查询库存数量
                SalesLedgerProduct oldProduct = salesLedgerProductMapper.selectById(product.getId());
                BigDecimal quantityChange = product.getQuantity().subtract(oldProduct.getQuantity());
                // 如果数量增加了,检查库存
                if (quantityChange.compareTo(BigDecimal.ZERO) > 0) {
                    for (StockInventoryDto stockInventoryDto : stockInventoryDtos) {
                        if (stockInventoryDto.getProductId().equals(product.getId())) {
                            if (quantityChange.compareTo(stockInventoryDto.getQualitity()) > 0) {
                                throw new RuntimeException("库存不足");
                            }
                            break;
                        }
                    }
                }
                product.setType(type);
                salesLedgerProductMapper.updateById(product);
            }
@@ -719,13 +736,18 @@
        // 执行插入操作
        if (!insertList.isEmpty()) {
            for (SalesLedgerProduct salesLedgerProduct : insertList) {
                for (StockInventoryDto stockInventoryDto : stockInventoryDtos) {
                    if (stockInventoryDto.getProductId().equals(salesLedgerProduct.getId())) {
                        if (salesLedgerProduct.getQuantity().compareTo(stockInventoryDto.getQualitity()) > 0) {
                            throw new RuntimeException("库存不足");
                        }
                    }
                }
                salesLedgerProduct.setType(type);
                salesLedgerProduct.setNoInvoiceNum(salesLedgerProduct.getQuantity());
                salesLedgerProduct.setNoInvoiceAmount(salesLedgerProduct.getTaxInclusiveTotalPrice());
                salesLedgerProduct.setPendingInvoiceTotal(salesLedgerProduct.getTaxInclusiveTotalPrice());
                salesLedgerProductMapper.insert(salesLedgerProduct);
                // 添加生产数据
                salesLedgerProductServiceImpl.addProductionData(salesLedgerProduct);
            }
        }
    }