| | |
| | | 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>() |
| | | PurchaseLedger existPurchaseLedger = purchaseLedgerMapper.selectOne(new LambdaQueryWrapper<PurchaseLedger>() |
| | | .eq(PurchaseLedger::getPurchaseContractNumber, salesLedgerImportDto.getPurchaseContractNumber()) |
| | | .last("limit 1")); |
| | | if(purchaseLedger != null){ |
| | | // å·²å®¡æ ¸éè¿çéè´åè·³è¿ï¼ä¸åéå¤å¯¼å
¥ |
| | | if (existPurchaseLedger != null && ApprovalStatusEnum.APPROVED.getCode().equals(existPurchaseLedger.getApprovalStatus())) { |
| | | 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)); |
| | | // å¾
å®¡æ ¸ç¶æçéè´åï¼å é¤è¯¥åä¸ç产å详æ
å审æ¹å®ä¾ï¼éæ°å½å
¥è¯¦æ
|
| | | if (existPurchaseLedger != null) { |
| | | salesLedgerProductMapper.delete(new LambdaQueryWrapper<SalesLedgerProduct>() |
| | | .eq(SalesLedgerProduct::getSalesLedgerId, existPurchaseLedger.getId()) |
| | | .eq(SalesLedgerProduct::getType, 2)); |
| | | // æ¸
ç该åä¸çè´¨æ£è®°å½åè´¨æ£åæ° |
| | | deleteQualityInspectByPurchaseLedger(existPurchaseLedger.getId()); |
| | | ApprovalInstance existApprovalInstance = approvalInstanceService.getOne( |
| | | Wrappers.<ApprovalInstance>lambdaQuery() |
| | | .eq(ApprovalInstance::getBusinessId, existPurchaseLedger.getId()) |
| | | .eq(ApprovalInstance::getBusinessType, 5L) |
| | | .eq(ApprovalInstance::getDeleted, 0) |
| | | .orderByDesc(ApprovalInstance::getId) |
| | | .last("limit 1")); |
| | | if (existApprovalInstance != null) { |
| | | approvalInstanceService.delete(Collections.singletonList(existApprovalInstance.getId())); |
| | | } |
| | | salesLedger.setId(existPurchaseLedger.getId()); |
| | | salesLedger.setApprovalStatus(ApprovalStatusEnum.PENDING.getCode()); |
| | | } |
| | | // éè¿ä¾åºååç§°æ¥è¯¢IDï¼ä¸åå¨åèªå¨æ°å¢ |
| | | salesLedger.setSupplierId(findOrCreateSupplier(salesLedger.getSupplierName(), customers)); |
| | | Long aLong = sysUsers.stream() |
| | | .filter(sysUser -> sysUser.getNickName().equals(salesLedger.getRecorderName())) |
| | | .findFirst() |
| | |
| | | String collect = ids.stream().map(Object::toString).collect(Collectors.joining(",")); |
| | | salesLedger.setApproveUserIds(collect); |
| | | } |
| | | if (salesLedger.getId() == null) { |
| | | purchaseLedgerMapper.insert(salesLedger); |
| | | } else { |
| | | // å¾
å®¡æ ¸ç¶æéæ°å½å
¥æ¶ï¼æ´æ°ä¸»è¡¨ |
| | | purchaseLedgerMapper.updateById(salesLedger); |
| | | } |
| | | |
| | | for (PurchaseLedgerProductImportDto salesLedgerProductImportDto : salesLedgerProductImportDtos) { |
| | | SalesLedgerProduct salesLedgerProduct = new SalesLedgerProduct(); |
| | |
| | | salesLedgerProduct.setSalesLedgerId(salesLedger.getId()); |
| | | salesLedgerProduct.setType(2); |
| | | // 计ç®ä¸å«ç¨æ»ä»· |
| | | salesLedgerProduct.setTaxExclusiveTotalPrice(salesLedgerProduct.getTaxInclusiveTotalPrice().divide(new BigDecimal(1).add(salesLedgerProduct.getTaxRate().divide(new BigDecimal(100))), 2, RoundingMode.HALF_UP)); |
| | | 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.setTaxExclusiveTotalPrice(salesLedgerProduct.getTaxInclusiveTotalPrice().divide(new BigDecimal(1).add(salesLedgerProduct.getTaxRate().divide(new BigDecimal(100))), 6, RoundingMode.HALF_UP)); |
| | | // 产å大类/è§æ ¼åå·ä¸å卿¶èªå¨å建 |
| | | String productName = salesLedgerProduct.getProductCategory(); |
| | | if (StringUtils.isNotBlank(productName)) { |
| | | // è§æ ¼åå·ä¸ºç©ºæ¶ç¨äº§å大类ä½ä¸ºè§æ ¼åå· |
| | | String model = StringUtils.isNotBlank(salesLedgerProduct.getSpecificationModel()) |
| | | ? salesLedgerProduct.getSpecificationModel() |
| | | : productName; |
| | | salesLedgerProduct.setSpecificationModel(model); |
| | | Long productId = findOrCreateProduct(productName, list); |
| | | Long modelId = findOrCreateProductModel(productId, productName, model, |
| | | salesLedgerProduct.getUnit(), list); |
| | | salesLedgerProduct.setProductId(productId); |
| | | salesLedgerProduct.setProductModelId(modelId); |
| | | } |
| | | salesLedgerProduct.setRegister(loginUser.getNickName()); |
| | | salesLedgerProduct.setRegisterDate(LocalDateTime.now()); |
| | | salesLedgerProduct.setApproveStatus(0); |
| | |
| | | return AjaxResult.success("导å
¥æå"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return AjaxResult.error("导å
¥å¤±è´¥ï¼" + e.getMessage()); |
| | | } |
| | | return AjaxResult.success("导å
¥å¤±è´¥"); |
| | | } |
| | | |
| | | /** |
| | | * æ¥æ¾ææ°å¢ä¾åºåï¼supplier_manage 表æ supplier_name å¹é
ï¼ä¸åå¨åæ°å¢ï¼ç¼ºå¤±ä¿¡æ¯é»è®¤å"/" |
| | | */ |
| | | private Long findOrCreateSupplier(String supplierName, List<SupplierManage> supplierList) { |
| | | if (StringUtils.isBlank(supplierName)) { |
| | | return null; |
| | | } |
| | | // å
ååè¡¨ä¸æ¥æ¾ï¼æ¬æ¬¡å¯¼å
¥å·²æ°å¢çä¹å
å«å¨å
ï¼ |
| | | for (SupplierManage supplier : supplierList) { |
| | | if (supplierName.equals(supplier.getSupplierName())) { |
| | | return supplier.getId(); |
| | | } |
| | | } |
| | | // æ°æ®åºæ¥æ¾ |
| | | SupplierManage existSupplier = supplierManageMapper.selectOne(new LambdaQueryWrapper<SupplierManage>() |
| | | .eq(SupplierManage::getSupplierName, supplierName) |
| | | .last("limit 1")); |
| | | if (existSupplier != null) { |
| | | supplierList.add(existSupplier); |
| | | return existSupplier.getId(); |
| | | } |
| | | // æ°å¢ä¾åºåï¼ç¼ºå¤±ä¿¡æ¯ï¼ç¨å·ãå°åãçµè¯çï¼é»è®¤å"/" |
| | | SupplierManage newSupplier = new SupplierManage(); |
| | | newSupplier.setSupplierName(supplierName); |
| | | newSupplier.setTaxpayerIdentificationNum("/"); |
| | | newSupplier.setCompanyAddress("/"); |
| | | newSupplier.setSupplierType("/"); |
| | | newSupplier.setCompanyPhone("/"); |
| | | newSupplier.setBankAccountName("/"); |
| | | newSupplier.setBankAccountNum("/"); |
| | | newSupplier.setContactUserName("/"); |
| | | newSupplier.setContactUserPhone("/"); |
| | | supplierManageMapper.insert(newSupplier); |
| | | supplierList.add(newSupplier); |
| | | return newSupplier.getId(); |
| | | } |
| | | |
| | | /** |
| | | * æ¥æ¾ææ°å¢äº§å大类ï¼product 表æ product_name å¹é
ï¼ä¸åå¨åæ°å¢ï¼é»è®¤ç¶ID为278 |
| | | */ |
| | | private Long findOrCreateProduct(String productName, List<Map<String, Object>> productAndModelList) { |
| | | // å
ååè¡¨ä¸æ¥æ¾ï¼æ¬æ¬¡å¯¼å
¥å·²æ°å¢çä¹å
å«å¨å
ï¼ |
| | | for (Map<String, Object> map : productAndModelList) { |
| | | if (map.get("productName") != null && productName.equals(map.get("productName"))) { |
| | | return Long.valueOf(map.get("id").toString()); |
| | | } |
| | | } |
| | | // æ°æ®åºæ¥æ¾ï¼å·²åå¨ä½ææ è§æ ¼åå·ç产åä¸å¨å
åå表ä¸ï¼ |
| | | Product existProduct = productMapper.selectOne(new LambdaQueryWrapper<Product>() |
| | | .eq(Product::getProductName, productName) |
| | | .last("limit 1")); |
| | | if (existProduct != null) { |
| | | return existProduct.getId(); |
| | | } |
| | | // æ°å¢äº§å大类ï¼é»è®¤ç¶ID为278 |
| | | Product product = new Product(); |
| | | product.setProductName(productName); |
| | | product.setParentId(278L); |
| | | productMapper.insert(product); |
| | | return product.getId(); |
| | | } |
| | | |
| | | /** |
| | | * æ¥æ¾ææ°å¢äº§åè§æ ¼åå·ï¼product_model æ 产åID+è§æ ¼åå· å¹é
ï¼ä¸åå¨åæ°å¢ã |
| | | * 产åç¼ç = è§æ ¼åå· + "_" + ä¸ä½æµæ°´å·ï¼è§æ ¼åå·ä¸ºç©ºæ¶ç¨äº§å大类ä½ä¸ºè§æ ¼åå·ã |
| | | */ |
| | | private Long findOrCreateProductModel(Long productId, String productName, String model, String unit, |
| | | List<Map<String, Object>> productAndModelList) { |
| | | // å
ååè¡¨ä¸æ¥æ¾ |
| | | for (Map<String, Object> map : productAndModelList) { |
| | | if (map.get("id") != null && Long.valueOf(map.get("id").toString()).equals(productId) |
| | | && model.equals(map.get("model"))) { |
| | | return Long.valueOf(map.get("modelId").toString()); |
| | | } |
| | | } |
| | | // æ°æ®åºæ¥æ¾ |
| | | ProductModel existProductModel = productModelMapper.selectOne(new LambdaQueryWrapper<ProductModel>() |
| | | .eq(ProductModel::getProductId, productId) |
| | | .eq(ProductModel::getModel, model) |
| | | .last("limit 1")); |
| | | if (existProductModel != null) { |
| | | return existProductModel.getId(); |
| | | } |
| | | // æ°å¢è§æ ¼åå·ï¼äº§åç¼ç = è§æ ¼åå· + "_" + ä¸ä½æµæ°´å·ï¼å产åä¸èªå¢ï¼ |
| | | long count = productModelMapper.selectCount(new LambdaQueryWrapper<ProductModel>() |
| | | .eq(ProductModel::getProductId, productId)); |
| | | ProductModel productModel = new ProductModel(); |
| | | productModel.setProductId(productId); |
| | | productModel.setModel(model); |
| | | productModel.setUnit(unit); |
| | | productModel.setProductCode(model + "_" + String.format("%03d", count + 1)); |
| | | productModelMapper.insert(productModel); |
| | | // è®°å½å°å
åå表ï¼é¿å
æ¬æ¬¡å¯¼å
¥å
éå¤å建 |
| | | Map<String, Object> newMap = new HashMap<>(); |
| | | newMap.put("id", productId); |
| | | newMap.put("modelId", productModel.getId()); |
| | | newMap.put("productName", productName); |
| | | newMap.put("model", model); |
| | | productAndModelList.add(newMap); |
| | | return productModel.getId(); |
| | | } |
| | | |
| | | /** |
| | | * å é¤éè´åä¸çè´¨æ£è®°å½åè´¨æ£åæ°ï¼å·²æäº¤çæ£éªåä¸å
许å é¤ï¼ |
| | | */ |
| | | private void deleteQualityInspectByPurchaseLedger(Long purchaseLedgerId) { |
| | | LambdaQueryWrapper<QualityInspect> inspectWrapper = new LambdaQueryWrapper<>(); |
| | | inspectWrapper.eq(QualityInspect::getPurchaseLedgerId, purchaseLedgerId); |
| | | List<QualityInspect> qualityInspects = qualityInspectMapper.selectList(inspectWrapper); |
| | | for (QualityInspect qualityInspect : qualityInspects) { |
| | | if (ObjectUtils.isNotEmpty(qualityInspect.getInspectState()) && qualityInspect.getInspectState().equals(1)) { |
| | | throw new BaseException("å·²æäº¤çæ£éªåä¸è½å é¤"); |
| | | } |
| | | } |
| | | List<Long> inspectIds = qualityInspects.stream() |
| | | .map(QualityInspect::getId) |
| | | .collect(Collectors.toList()); |
| | | if (!inspectIds.isEmpty()) { |
| | | qualityInspectParamMapper.delete(new LambdaQueryWrapper<QualityInspectParam>() |
| | | .in(QualityInspectParam::getInspectId, inspectIds)); |
| | | } |
| | | qualityInspectMapper.delete(inspectWrapper); |
| | | } |
| | | |
| | | @Override |