| | |
| | | package com.ruoyi.purchase.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | |
| | | |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | | import java.time.Instant; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | |
| | | @Slf4j |
| | | @RequiredArgsConstructor |
| | | public class PurchaseLedgerServiceImpl extends ServiceImpl<PurchaseLedgerMapper, PurchaseLedger> implements IPurchaseLedgerService { |
| | | |
| | | private static final Long IMPORT_PRODUCT_PARENT_ID = 3L; |
| | | |
| | | private final PurchaseLedgerMapper purchaseLedgerMapper; |
| | | private final SalesLedgerMapper salesLedgerMapper; |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public AjaxResult importData(MultipartFile file) { |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | try { |
| | | InputStream inputStream = file.getInputStream(); |
| | | ExcelUtil<PurchaseLedgerImportDto> salesLedgerImportDtoExcelUtil = new ExcelUtil<>(PurchaseLedgerImportDto.class); |
| | | Map<String, List<PurchaseLedgerImportDto>> stringListMap = salesLedgerImportDtoExcelUtil.importExcelMultiSheet(Arrays.asList("采购台账数据", "采购产品数据"), inputStream, 0); |
| | | if (CollectionUtils.isEmpty(stringListMap)) return AjaxResult.error("采购表格为空!"); |
| | | // 业务层合并 |
| | | List<PurchaseLedgerImportDto> salesLedgerImportDtoList = stringListMap.get("采购台账数据"); |
| | | if (CollectionUtils.isEmpty(salesLedgerImportDtoList)) return AjaxResult.error("采购台账数据为空!"); |
| | | List<PurchaseLedgerImportDto> salesLedgerProductImportDtoList = stringListMap.get("采购产品数据"); |
| | | if (CollectionUtils.isEmpty(salesLedgerProductImportDtoList)) return AjaxResult.error("采购产品数据为空!"); |
| | | // 供应商数据 |
| | | List<SupplierManage> customers = supplierManageMapper.selectList(new LambdaQueryWrapper<SupplierManage>().in(SupplierManage::getSupplierName, |
| | | salesLedgerImportDtoList.stream().map(PurchaseLedgerImportDto::getSupplierName).collect(Collectors.toList()))); |
| | | List<Map<String,Object>> list = productModelMapper.getProductAndModelList(); |
| | | // 录入人数据 |
| | | List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>().in(SysUser::getNickName, |
| | | salesLedgerImportDtoList.stream().map(PurchaseLedgerImportDto::getRecorderName).collect(Collectors.toList()))); |
| | | for (PurchaseLedgerImportDto salesLedgerImportDto : salesLedgerImportDtoList) { |
| | | PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectOne(new LambdaQueryWrapper<PurchaseLedger>() |
| | | .eq(PurchaseLedger::getPurchaseContractNumber, salesLedgerImportDto.getPurchaseContractNumber()) |
| | | .last("limit 1")); |
| | | if(purchaseLedger != null){ |
| | | try (InputStream inputStream = file.getInputStream()) { |
| | | ExcelUtil<PurchaseLedgerImportDto> excelUtil = new ExcelUtil<>(PurchaseLedgerImportDto.class); |
| | | Map<String, List<PurchaseLedgerImportDto>> sheetData = excelUtil.importExcelMultiSheet( |
| | | Arrays.asList("采购台账数据", "采购产品数据"), inputStream, 0); |
| | | if (CollectionUtils.isEmpty(sheetData)) { |
| | | return AjaxResult.error("采购表格为空!"); |
| | | } |
| | | |
| | | List<PurchaseLedgerImportDto> purchaseImports = sheetData.get("采购台账数据"); |
| | | if (CollectionUtils.isEmpty(purchaseImports)) { |
| | | return AjaxResult.error("采购台账数据为空!"); |
| | | } |
| | | List<PurchaseLedgerImportDto> productImports = sheetData.get("采购产品数据"); |
| | | if (CollectionUtils.isEmpty(productImports)) { |
| | | return AjaxResult.error("采购产品数据为空!"); |
| | | } |
| | | |
| | | List<String> supplierNames = purchaseImports.stream() |
| | | .map(PurchaseLedgerImportDto::getSupplierName) |
| | | .filter(StringUtils::hasText) |
| | | .map(StringUtils::trim) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | Map<String, SupplierManage> supplierMap = CollectionUtils.isEmpty(supplierNames) |
| | | ? Collections.emptyMap() |
| | | : supplierManageMapper.selectList(new LambdaQueryWrapper<SupplierManage>() |
| | | .in(SupplierManage::getSupplierName, supplierNames)) |
| | | .stream() |
| | | .collect(Collectors.toMap( |
| | | supplier -> StringUtils.trim(supplier.getSupplierName()), |
| | | supplier -> supplier, |
| | | (first, ignored) -> first)); |
| | | |
| | | List<String> recorderNames = purchaseImports.stream() |
| | | .map(PurchaseLedgerImportDto::getRecorderName) |
| | | .filter(StringUtils::hasText) |
| | | .map(StringUtils::trim) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | Map<String, SysUser> recorderMap = CollectionUtils.isEmpty(recorderNames) |
| | | ? Collections.emptyMap() |
| | | : sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>() |
| | | .in(SysUser::getNickName, recorderNames)) |
| | | .stream() |
| | | .collect(Collectors.toMap( |
| | | user -> StringUtils.trim(user.getNickName()), |
| | | user -> user, |
| | | (first, ignored) -> first)); |
| | | |
| | | Map<String, ProductModel> importedProductModelCache = new HashMap<>(); |
| | | int addedCount = 0; |
| | | int overwrittenCount = 0; |
| | | int skippedCount = 0; |
| | | |
| | | for (PurchaseLedgerImportDto purchaseImport : purchaseImports) { |
| | | String purchaseContractNumber = requireImportText( |
| | | purchaseImport.getPurchaseContractNumber(), "采购单号不能为空!"); |
| | | purchaseImport.setPurchaseContractNumber(purchaseContractNumber); |
| | | purchaseImport.setSupplierName(StringUtils.trim(purchaseImport.getSupplierName())); |
| | | purchaseImport.setProjectName(StringUtils.trim(purchaseImport.getProjectName())); |
| | | purchaseImport.setRecorderName(StringUtils.trim(purchaseImport.getRecorderName())); |
| | | |
| | | List<PurchaseLedgerProductImportDto> purchaseProducts = productImports.stream() |
| | | .filter(productImport -> sameImportText( |
| | | productImport.getPurchaseContractNumber(), purchaseContractNumber)) |
| | | .map(productImport -> (PurchaseLedgerProductImportDto) productImport) |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(purchaseProducts)) { |
| | | throw new BaseException("采购单号:" + purchaseContractNumber + ",无对应产品数据!"); |
| | | } |
| | | |
| | | List<PurchaseLedger> existingLedgers = purchaseLedgerMapper.selectList( |
| | | new LambdaQueryWrapper<PurchaseLedger>() |
| | | .eq(PurchaseLedger::getPurchaseContractNumber, purchaseContractNumber)); |
| | | PurchaseLedger ledgerToOverwrite = existingLedgers.stream() |
| | | .filter(existing -> Objects.equals(existing.getApprovalStatus(), 1)) |
| | | .filter(existing -> isSameImportedPurchase(existing, purchaseImport)) |
| | | .findFirst() |
| | | .orElse(null); |
| | | if (ledgerToOverwrite == null && CollectionUtils.isNotEmpty(existingLedgers)) { |
| | | skippedCount++; |
| | | continue; |
| | | } |
| | | PurchaseLedger salesLedger = new PurchaseLedger(); |
| | | BeanUtils.copyProperties(salesLedgerImportDto, salesLedger); |
| | | // 通过供应商名称查询ID |
| | | salesLedger.setSupplierId(customers.stream() |
| | | .filter(customer -> customer.getSupplierName().equals(salesLedger.getSupplierName())) |
| | | .findFirst() |
| | | .map(SupplierManage::getId) |
| | | .orElse(null)); |
| | | Long aLong = sysUsers.stream() |
| | | .filter(sysUser -> sysUser.getNickName().equals(salesLedger.getRecorderName())) |
| | | .findFirst() |
| | | .map(SysUser::getUserId) |
| | | .orElse(null); |
| | | if (aLong == null) |
| | | throw new RuntimeException("录入人:" + salesLedger.getRecorderName() + ",无对应用户!"); |
| | | salesLedger.setRecorderId(aLong); |
| | | // 采购产品数据绑定,通过采购单号获取对应采购产品数据 |
| | | List<PurchaseLedgerProductImportDto> salesLedgerProductImportDtos = salesLedgerProductImportDtoList.stream() |
| | | .filter(salesLedgerProductImportDto -> salesLedgerProductImportDto.getPurchaseContractNumber().equals(salesLedger.getPurchaseContractNumber())) |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(salesLedgerProductImportDtos)) |
| | | throw new RuntimeException("采购单号:" + salesLedgerImportDto.getPurchaseContractNumber() + ",无对应产品数据!"); |
| | | salesLedger.setContractAmount(salesLedgerProductImportDtos.stream() |
| | | .map(PurchaseLedgerProductImportDto::getTaxInclusiveTotalPrice) |
| | | .reduce(BigDecimal.ZERO,BigDecimal::add)); |
| | | // 通过销售单号绑定销售 |
| | | SalesLedger salesLedger1 = salesLedgerMapper.selectOne(new LambdaQueryWrapper<SalesLedger>() |
| | | .eq(SalesLedger::getSalesContractNo, salesLedger.getSalesContractNo()) |
| | | .last("LIMIT 1")); |
| | | if(salesLedger1 != null){ |
| | | salesLedger.setSalesLedgerId(salesLedger1.getId()); |
| | | } |
| | | if (StringUtils.hasText(salesLedger.getApproveUserIds())) { |
| | | // 采购审核:历史导入模板传审批人姓名时,继续兼容转换为用户ID。 |
| | | String[] split = salesLedger.getApproveUserIds().split(","); |
| | | List<Long> ids = new ArrayList<>(); |
| | | for (int i = 0; i < split.length; i++) { |
| | | SysUser sysUser = sysUserMapper.selectOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getNickName, split[i]) |
| | | .last("LIMIT 1")); |
| | | if (sysUser != null) { |
| | | ids.add(sysUser.getUserId()); |
| | | } |
| | | } |
| | | // 将集合转为字符串,隔开 |
| | | String collect = ids.stream().map(Object::toString).collect(Collectors.joining(",")); |
| | | salesLedger.setApproveUserIds(collect); |
| | | } |
| | | purchaseLedgerMapper.insert(salesLedger); |
| | | |
| | | for (PurchaseLedgerProductImportDto salesLedgerProductImportDto : salesLedgerProductImportDtos) { |
| | | SalesLedgerProduct salesLedgerProduct = new SalesLedgerProduct(); |
| | | BeanUtils.copyProperties(salesLedgerProductImportDto, salesLedgerProduct); |
| | | salesLedgerProduct.setSalesLedgerId(salesLedger.getId()); |
| | | salesLedgerProduct.setType(2); |
| | | AmountUtils.normalizeSalesLedgerProduct(salesLedgerProduct); |
| | | // 计算不含税总价 |
| | | salesLedgerProduct.setTaxExclusiveTotalPrice( |
| | | PurchaseLedger purchaseLedger = buildImportedPurchaseLedger( |
| | | purchaseImport, purchaseProducts, supplierMap, recorderMap); |
| | | boolean overwrite = ledgerToOverwrite != null; |
| | | if (overwrite) { |
| | | purchaseLedger.setId(ledgerToOverwrite.getId()); |
| | | purchaseLedger.setApprovalStatus(1); |
| | | updateImportedPurchaseLedger(purchaseLedger); |
| | | clearImportedPurchaseContents(purchaseLedger.getId(), purchaseContractNumber); |
| | | overwrittenCount++; |
| | | } else { |
| | | purchaseLedger.setApprovalStatus(1); |
| | | purchaseLedgerMapper.insert(purchaseLedger); |
| | | addedCount++; |
| | | } |
| | | |
| | | for (PurchaseLedgerProductImportDto productImport : purchaseProducts) { |
| | | ProductModel productModel = findOrCreateImportedProductModel( |
| | | productImport, importedProductModelCache); |
| | | SalesLedgerProduct purchaseProduct = new SalesLedgerProduct(); |
| | | BeanUtils.copyProperties(productImport, purchaseProduct); |
| | | purchaseProduct.setSalesLedgerId(purchaseLedger.getId()); |
| | | purchaseProduct.setType(2); |
| | | purchaseProduct.setProductId(productModel.getProductId()); |
| | | purchaseProduct.setProductModelId(productModel.getId()); |
| | | AmountUtils.normalizeSalesLedgerProduct(purchaseProduct); |
| | | purchaseProduct.setTaxExclusiveTotalPrice( |
| | | AmountUtils.calcTaxExclusiveTotalPrice( |
| | | salesLedgerProduct.getTaxInclusiveTotalPrice(), |
| | | salesLedgerProduct.getTaxRate() |
| | | ) |
| | | ); |
| | | list.stream() |
| | | .filter(map -> map.get("productName").equals(salesLedgerProduct.getProductCategory()) && map.get("model").equals(salesLedgerProduct.getSpecificationModel())) |
| | | .findFirst() |
| | | .ifPresent(map -> { |
| | | salesLedgerProduct.setProductModelId(Long.parseLong(map.get("modelId").toString())); |
| | | salesLedgerProduct.setProductId(Long.parseLong(map.get("id").toString())); |
| | | }); |
| | | salesLedgerProduct.setRegister(loginUser.getNickName()); |
| | | salesLedgerProduct.setRegisterDate(LocalDateTime.now()); |
| | | salesLedgerProduct.setApproveStatus(0); |
| | | // 是否质检判断 |
| | | salesLedgerProduct.setIsChecked(salesLedgerProductImportDto.getIsChecked() == 1); |
| | | if(salesLedgerProductImportDto.getIsChecked() == 1){ |
| | | addQualityInspect(salesLedger, salesLedgerProduct); |
| | | purchaseProduct.getTaxInclusiveTotalPrice(), |
| | | purchaseProduct.getTaxRate())); |
| | | purchaseProduct.setRegister(loginUser.getNickName()); |
| | | purchaseProduct.setRegisterDate(LocalDateTime.now()); |
| | | purchaseProduct.setApproveStatus(0); |
| | | purchaseProduct.setIsChecked(Objects.equals(productImport.getIsChecked(), 1)); |
| | | salesLedgerProductMapper.insert(purchaseProduct); |
| | | if (Boolean.TRUE.equals(purchaseProduct.getIsChecked())) { |
| | | addQualityInspect(purchaseLedger, purchaseProduct); |
| | | } |
| | | salesLedgerProductMapper.insert(salesLedgerProduct); |
| | | } |
| | | // 采购审核 |
| | | addApproveByPurchase(loginUser,salesLedger); |
| | | } |
| | | |
| | | return AjaxResult.success("导入成功"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | if (!overwrite) { |
| | | addApproveByPurchase(loginUser, purchaseLedger); |
| | | } |
| | | return AjaxResult.success("导入失败"); |
| | | } |
| | | |
| | | return AjaxResult.success(String.format( |
| | | "导入成功:新增%d条,覆盖%d条,跳过%d条", addedCount, overwrittenCount, skippedCount)); |
| | | } catch (BaseException e) { |
| | | log.error("导入采购台账失败:{}", e.getMessage(), e); |
| | | throw e; |
| | | } catch (Exception e) { |
| | | log.error("导入采购台账失败", e); |
| | | throw new BaseException("导入失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private PurchaseLedger buildImportedPurchaseLedger( |
| | | PurchaseLedgerImportDto purchaseImport, |
| | | List<PurchaseLedgerProductImportDto> purchaseProducts, |
| | | Map<String, SupplierManage> supplierMap, |
| | | Map<String, SysUser> recorderMap) { |
| | | PurchaseLedger purchaseLedger = new PurchaseLedger(); |
| | | BeanUtils.copyProperties(purchaseImport, purchaseLedger); |
| | | |
| | | SupplierManage supplier = supplierMap.get(purchaseLedger.getSupplierName()); |
| | | purchaseLedger.setSupplierId(supplier == null ? null : supplier.getId()); |
| | | |
| | | SysUser recorder = recorderMap.get(purchaseLedger.getRecorderName()); |
| | | if (recorder == null) { |
| | | throw new BaseException("录入人:" + purchaseLedger.getRecorderName() + ",无对应用户!"); |
| | | } |
| | | purchaseLedger.setRecorderId(recorder.getUserId()); |
| | | purchaseLedger.setContractAmount(purchaseProducts.stream() |
| | | .map(PurchaseLedgerProductImportDto::getTaxInclusiveTotalPrice) |
| | | .filter(Objects::nonNull) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | |
| | | if (StringUtils.hasText(purchaseLedger.getSalesContractNo())) { |
| | | SalesLedger salesLedger = salesLedgerMapper.selectOne(new LambdaQueryWrapper<SalesLedger>() |
| | | .eq(SalesLedger::getSalesContractNo, purchaseLedger.getSalesContractNo()) |
| | | .last("LIMIT 1")); |
| | | purchaseLedger.setSalesLedgerId(salesLedger == null ? null : salesLedger.getId()); |
| | | } else { |
| | | purchaseLedger.setSalesLedgerId(null); |
| | | } |
| | | purchaseLedger.setApproveUserIds(convertImportedApproverNames(purchaseLedger.getApproveUserIds())); |
| | | return purchaseLedger; |
| | | } |
| | | |
| | | private String convertImportedApproverNames(String approverNames) { |
| | | if (!StringUtils.hasText(approverNames)) { |
| | | return approverNames; |
| | | } |
| | | List<Long> userIds = new ArrayList<>(); |
| | | for (String approverName : approverNames.split("[,,]")) { |
| | | String trimmedName = StringUtils.trim(approverName); |
| | | if (!StringUtils.hasText(trimmedName)) { |
| | | continue; |
| | | } |
| | | SysUser user = sysUserMapper.selectOne(new LambdaQueryWrapper<SysUser>() |
| | | .eq(SysUser::getNickName, trimmedName) |
| | | .last("LIMIT 1")); |
| | | if (user != null) { |
| | | userIds.add(user.getUserId()); |
| | | } |
| | | } |
| | | return userIds.stream().map(String::valueOf).collect(Collectors.joining(",")); |
| | | } |
| | | |
| | | private ProductModel findOrCreateImportedProductModel( |
| | | PurchaseLedgerProductImportDto productImport, |
| | | Map<String, ProductModel> cache) { |
| | | String productCategory = requireImportText( |
| | | productImport.getProductCategory(), "采购产品的产品大类不能为空!"); |
| | | String specificationModel = StringUtils.trim(productImport.getSpecificationModel()); |
| | | if (!StringUtils.hasText(specificationModel)) { |
| | | specificationModel = productCategory; |
| | | } |
| | | productImport.setProductCategory(productCategory); |
| | | productImport.setSpecificationModel(specificationModel); |
| | | productImport.setUnit(StringUtils.trim(productImport.getUnit())); |
| | | |
| | | String cacheKey = productCategory + "::" + specificationModel; |
| | | ProductModel cachedModel = cache.get(cacheKey); |
| | | if (cachedModel != null) { |
| | | return cachedModel; |
| | | } |
| | | |
| | | List<Product> sameNameProducts = productMapper.selectList(new LambdaQueryWrapper<Product>() |
| | | .eq(Product::getProductName, productCategory)); |
| | | for (Product product : sameNameProducts) { |
| | | ProductModel existingModel = productModelMapper.selectOne(new LambdaQueryWrapper<ProductModel>() |
| | | .eq(ProductModel::getProductId, product.getId()) |
| | | .eq(ProductModel::getModel, specificationModel) |
| | | .last("LIMIT 1")); |
| | | if (existingModel != null) { |
| | | cache.put(cacheKey, existingModel); |
| | | return existingModel; |
| | | } |
| | | } |
| | | |
| | | Product product = sameNameProducts.stream() |
| | | .filter(item -> Objects.equals(item.getParentId(), IMPORT_PRODUCT_PARENT_ID)) |
| | | .findFirst() |
| | | .orElse(null); |
| | | if (product == null) { |
| | | product = new Product(); |
| | | product.setParentId(IMPORT_PRODUCT_PARENT_ID); |
| | | product.setProductName(productCategory); |
| | | productMapper.insert(product); |
| | | } |
| | | |
| | | ProductModel productModel = new ProductModel(); |
| | | productModel.setProductId(product.getId()); |
| | | productModel.setModel(specificationModel); |
| | | productModel.setUnit(productImport.getUnit()); |
| | | productModel.setProductCode(specificationModel + "-001"); |
| | | productModelMapper.insert(productModel); |
| | | cache.put(cacheKey, productModel); |
| | | return productModel; |
| | | } |
| | | |
| | | private void updateImportedPurchaseLedger(PurchaseLedger purchaseLedger) { |
| | | purchaseLedgerMapper.update(null, new LambdaUpdateWrapper<PurchaseLedger>() |
| | | .eq(PurchaseLedger::getId, purchaseLedger.getId()) |
| | | .set(PurchaseLedger::getPurchaseContractNumber, purchaseLedger.getPurchaseContractNumber()) |
| | | .set(PurchaseLedger::getSupplierId, purchaseLedger.getSupplierId()) |
| | | .set(PurchaseLedger::getSupplierName, purchaseLedger.getSupplierName()) |
| | | .set(PurchaseLedger::getRecorderId, purchaseLedger.getRecorderId()) |
| | | .set(PurchaseLedger::getRecorderName, purchaseLedger.getRecorderName()) |
| | | .set(PurchaseLedger::getSalesContractNo, purchaseLedger.getSalesContractNo()) |
| | | .set(PurchaseLedger::getProjectName, purchaseLedger.getProjectName()) |
| | | .set(PurchaseLedger::getEntryDate, purchaseLedger.getEntryDate()) |
| | | .set(PurchaseLedger::getExecutionDate, purchaseLedger.getExecutionDate()) |
| | | .set(PurchaseLedger::getRemarks, purchaseLedger.getRemarks()) |
| | | .set(PurchaseLedger::getSalesLedgerId, purchaseLedger.getSalesLedgerId()) |
| | | .set(PurchaseLedger::getContractAmount, purchaseLedger.getContractAmount()) |
| | | .set(PurchaseLedger::getPaymentMethod, purchaseLedger.getPaymentMethod()) |
| | | .set(PurchaseLedger::getApproveUserIds, purchaseLedger.getApproveUserIds()) |
| | | .set(PurchaseLedger::getApprovalStatus, 1) |
| | | .set(PurchaseLedger::getUpdatedAt, new Date())); |
| | | } |
| | | |
| | | private void clearImportedPurchaseContents(Long purchaseLedgerId, String purchaseContractNumber) { |
| | | List<QualityInspect> qualityInspects = qualityInspectMapper.selectList( |
| | | new LambdaQueryWrapper<QualityInspect>() |
| | | .eq(QualityInspect::getPurchaseLedgerId, purchaseLedgerId)); |
| | | boolean hasSubmittedInspect = qualityInspects.stream() |
| | | .anyMatch(inspect -> Objects.equals(inspect.getInspectState(), 1)); |
| | | if (hasSubmittedInspect) { |
| | | throw new BaseException("采购单号:" + purchaseContractNumber + ",存在已提交的检验单,不能覆盖!"); |
| | | } |
| | | List<Long> inspectIds = qualityInspects.stream() |
| | | .map(QualityInspect::getId) |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isNotEmpty(inspectIds)) { |
| | | qualityInspectParamMapper.delete(new LambdaQueryWrapper<QualityInspectParam>() |
| | | .in(QualityInspectParam::getInspectId, inspectIds)); |
| | | qualityInspectMapper.delete(new LambdaQueryWrapper<QualityInspect>() |
| | | .eq(QualityInspect::getPurchaseLedgerId, purchaseLedgerId)); |
| | | } |
| | | |
| | | List<SalesLedgerProduct> existingProducts = salesLedgerProductMapper.selectList( |
| | | new LambdaQueryWrapper<SalesLedgerProduct>() |
| | | .eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedgerId) |
| | | .eq(SalesLedgerProduct::getType, 2)); |
| | | for (SalesLedgerProduct existingProduct : existingProducts) { |
| | | procurementRecordStorageMapper.delete(new LambdaQueryWrapper<ProcurementRecordStorage>() |
| | | .eq(ProcurementRecordStorage::getSalesLedgerProductId, existingProduct.getId())); |
| | | } |
| | | salesLedgerProductMapper.delete(new LambdaQueryWrapper<SalesLedgerProduct>() |
| | | .eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedgerId) |
| | | .eq(SalesLedgerProduct::getType, 2)); |
| | | } |
| | | |
| | | private boolean isSameImportedPurchase( |
| | | PurchaseLedger existingLedger, PurchaseLedgerImportDto purchaseImport) { |
| | | return sameImportText(existingLedger.getPurchaseContractNumber(), purchaseImport.getPurchaseContractNumber()) |
| | | && sameImportText(existingLedger.getSupplierName(), purchaseImport.getSupplierName()) |
| | | && sameImportText(existingLedger.getProjectName(), purchaseImport.getProjectName()) |
| | | && sameImportDate(existingLedger.getExecutionDate(), purchaseImport.getExecutionDate()) |
| | | && sameImportDate(existingLedger.getEntryDate(), purchaseImport.getEntryDate()); |
| | | } |
| | | |
| | | private boolean sameImportText(String left, String right) { |
| | | return Objects.equals(StringUtils.trim(left), StringUtils.trim(right)); |
| | | } |
| | | |
| | | private boolean sameImportDate(Date left, Date right) { |
| | | if (left == null || right == null) { |
| | | return left == null && right == null; |
| | | } |
| | | LocalDate leftDate = Instant.ofEpochMilli(left.getTime()) |
| | | .atZone(ZoneId.systemDefault()) |
| | | .toLocalDate(); |
| | | LocalDate rightDate = Instant.ofEpochMilli(right.getTime()) |
| | | .atZone(ZoneId.systemDefault()) |
| | | .toLocalDate(); |
| | | return leftDate.equals(rightDate); |
| | | } |
| | | |
| | | private String requireImportText(String value, String message) { |
| | | String trimmedValue = StringUtils.trim(value); |
| | | if (!StringUtils.hasText(trimmedValue)) { |
| | | throw new BaseException(message); |
| | | } |
| | | return trimmedValue; |
| | | } |
| | | |
| | | @Override |