| | |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.fasterxml.jackson.databind.node.ObjectNode; |
| | | import com.ruoyi.account.service.AccountIncomeService; |
| | | import com.ruoyi.aftersalesservice.dto.AfterSalesProductDto; |
| | | import com.ruoyi.aftersalesservice.dto.AfterSalesServiceNewDto; |
| | | import com.ruoyi.aftersalesservice.service.AfterSalesServiceService; |
| | | import com.ruoyi.approve.pojo.ApproveProcess; |
| | | import com.ruoyi.approve.service.IApproveProcessService; |
| | | import com.ruoyi.approve.vo.ApproveProcessVO; |
| | |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.data.redis.core.script.DefaultRedisScript; |
| | | import org.springframework.security.core.Authentication; |
| | |
| | | ; |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Autowired |
| | | @Lazy |
| | | private AfterSalesServiceService afterSalesServiceService; |
| | | |
| | | private final ICustomerRegionsService customerRegionsService; |
| | | @Autowired |
| | |
| | | if (products == null || products.isEmpty()) { |
| | | throw new ServiceException("å
¥åºå¤±è´¥,å
¥åºäº§åä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | long pendingInspectCount = qualityInspectMapper.selectCount(Wrappers.<com.ruoyi.quality.pojo.QualityInspect>lambdaQuery() |
| | | .eq(com.ruoyi.quality.pojo.QualityInspect::getSalesLedgerId, ledger.getId()) |
| | | .in(com.ruoyi.quality.pojo.QualityInspect::getSalesLedgerProductId, products) |
| | | .eq(com.ruoyi.quality.pojo.QualityInspect::getInspectState, 0)); |
| | | if (pendingInspectCount > 0) { |
| | | throw new ServiceException("å
¥åºå¤±è´¥,éä¸ç产åä¸åå¨å¾
å¤ççæåæ£éªå,请å
å®æè´¨æ£"); |
| | | } |
| | | |
| | | // æ¥è¯¢éå®è®¢åç产å |
| | | List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(Wrappers.<SalesLedgerProduct>lambdaQuery().in(SalesLedgerProduct::getId, products)); |
| | | if (salesLedgerProducts == null || salesLedgerProducts.isEmpty()) { |
| | |
| | | if (inboundQty.compareTo(BigDecimal.ZERO) <= 0) { |
| | | continue; |
| | | } |
| | | StockInventoryDto stockInventoryDto = new StockInventoryDto(); |
| | | stockInventoryDto.setRecordId(product.getId()); |
| | | stockInventoryDto.setRecordType(StockInQualifiedRecordTypeEnum.SALE_STOCK_IN.getCode()); |
| | | stockInventoryDto.setQualitity(inboundQty); |
| | | stockInventoryDto.setProductModelId(product.getProductModelId()); |
| | | stockInventoryDto.setSalesLedgerId(ledger.getId()); |
| | | stockInventoryDto.setSalesLedgerProductId(product.getId()); |
| | | stockInventoryService.addstockInventory(stockInventoryDto); |
| | | |
| | | BigDecimal newStocked = oldStocked.add(inboundQty); |
| | | 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; |
| | | // æ°å¢ä¸æ¡æåçè´¨æ£ä¿¡æ¯ |
| | | com.ruoyi.quality.pojo.QualityInspect qualityInspect = new com.ruoyi.quality.pojo.QualityInspect(); |
| | | qualityInspect.setInspectType(2); // 2: åºåæ£éª (æåæ£éª) |
| | | qualityInspect.setCustomer(ledger.getCustomerName()); |
| | | qualityInspect.setSalesLedgerId(ledger.getId()); |
| | | qualityInspect.setSalesLedgerProductId(product.getId()); |
| | | qualityInspect.setProductId(product.getProductId()); |
| | | qualityInspect.setProductName(product.getProductCategory()); |
| | | qualityInspect.setModel(product.getSpecificationModel()); |
| | | qualityInspect.setProductModelId(product.getProductModelId()); |
| | | qualityInspect.setUnit(product.getUnit()); |
| | | qualityInspect.setQuantity(inboundQty); |
| | | qualityInspect.setQualifiedQuantity(inboundQty); |
| | | qualityInspect.setUnqualifiedQuantity(BigDecimal.ZERO); |
| | | qualityInspect.setPassRate(BigDecimal.valueOf(100).setScale(2, java.math.RoundingMode.HALF_UP)); |
| | | qualityInspect.setInspectState(0); |
| | | qualityInspectMapper.insert(qualityInspect); |
| | | |
| | | // æ¥è¯¢æ£æµæ åå¹¶æ·»å è´¨æ£åæ° |
| | | List<com.ruoyi.quality.pojo.QualityTestStandard> qualityTestStandardList = qualityTestStandardMapper.getQualityTestStandardByProductId(product.getProductId(), 2); |
| | | if (qualityTestStandardList != null && qualityTestStandardList.size() > 0) { |
| | | qualityInspect.setTestStandardId(qualityTestStandardList.get(0).getId()); |
| | | qualityInspectMapper.updateById(qualityInspect); |
| | | List<com.ruoyi.quality.pojo.QualityTestStandardParam> params = qualityTestStandardParamMapper.selectList(com.baomidou.mybatisplus.core.toolkit.Wrappers.<com.ruoyi.quality.pojo.QualityTestStandardParam>lambdaQuery() |
| | | .eq(com.ruoyi.quality.pojo.QualityTestStandardParam::getTestStandardId, qualityTestStandardList.get(0).getId())); |
| | | for (com.ruoyi.quality.pojo.QualityTestStandardParam p : params) { |
| | | com.ruoyi.quality.pojo.QualityInspectParam param = new com.ruoyi.quality.pojo.QualityInspectParam(); |
| | | org.springframework.beans.BeanUtils.copyProperties(p, param); |
| | | param.setId(null); |
| | | param.setInspectId(qualityInspect.getId()); |
| | | qualityInspectParamMapper.insert(param); |
| | | } |
| | | } |
| | | product.setStockedQuantity(newStocked); |
| | | product.setProductStockStatus(lineStockStatus); |
| | | product.fillRemainingQuantity(); |
| | | salesLedgerProductMapper.updateById(product); |
| | | } |
| | | // æéå®è®¢å产åå
¥åºæ
嵿´æ°ä¸»åå
¥åºç¶æï¼1-é¨åå
¥åºï¼2-å·²å
¥åº |
| | | List<SalesLedgerProduct> ledgerAllProducts = salesLedgerProductMapper.selectList(Wrappers.<SalesLedgerProduct>lambdaQuery().eq(SalesLedgerProduct::getSalesLedgerId, ledger.getId())); |
| | | boolean hasStocked = CollectionUtils.isNotEmpty(ledgerAllProducts) && ledgerAllProducts.stream().anyMatch(item -> { |
| | | BigDecimal sq = item.getStockedQuantity(); |
| | | return sq != null && sq.compareTo(BigDecimal.ZERO) > 0; |
| | | }); |
| | | boolean allStocked = CollectionUtils.isNotEmpty(ledgerAllProducts) && ledgerAllProducts.stream().allMatch(item -> { |
| | | BigDecimal orderQty = item.getQuantity() == null ? BigDecimal.ZERO : item.getQuantity(); |
| | | BigDecimal stockedQty = item.getStockedQuantity() == null ? BigDecimal.ZERO : item.getStockedQuantity(); |
| | | return orderQty.compareTo(BigDecimal.ZERO) <= 0 || stockedQty.compareTo(orderQty) >= 0; |
| | | }); |
| | | ledger.setStockStatus(allStocked ? 2 : (hasStocked ? 1 : 0)); |
| | | // æ´æ°ä¸»åç¶æä¸ºæªå®å
¨å
¥åºï¼å¾
è´¨æ£å®æåæ´æ°ï¼ |
| | | ledger.setStockStatus(0); |
| | | baseMapper.updateById(ledger); |
| | | } |
| | | |
| | |
| | | if (CollectionUtils.isEmpty(rowList)) { |
| | | return; |
| | | } |
| | | if (StringUtils.hasText(rowList.get(0).getCustomerName()) && rowList.get(0).getCustomerName().startsWith("è¡¥ç")) { |
| | | return; |
| | | } |
| | | rowList.sort(Comparator.comparing(r -> buildCategoryProductName(r) + "||" + buildSpecificationModel(r))); |
| | | SalesLedger ledger = salesLedgerMapper.selectOne(new LambdaQueryWrapper<SalesLedger>().eq(SalesLedger::getSalesContractNo, orderNo).last("LIMIT 1")); |
| | | SalesLedger ledger = salesLedgerMapper.selectOne(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<SalesLedger>().eq(SalesLedger::getSalesContractNo, orderNo).last("LIMIT 1")); |
| | | if (ledger == null) { |
| | | // throw new ServiceException("导å
¥å¤±è´¥,订åç¼å·[" + orderNo + "]ä¸åå¨,æ æ³è¡¥å½å·²åè´§æ°æ®"); |
| | | return; |
| | | } |
| | | |
| | | boolean skipInboundAndShipping = false; |
| | | if (org.springframework.util.StringUtils.hasText(ledger.getCustomerName()) && ledger.getCustomerName().startsWith("è¡¥ç")) { |
| | | if (ledger.getEntryDate() != null) { |
| | | java.time.LocalDate entryDate = com.ruoyi.common.utils.DateUtils.toLocalDate(ledger.getEntryDate()); |
| | | if (entryDate.plusDays(7).isAfter(java.time.LocalDate.now())) { |
| | | skipInboundAndShipping = true; |
| | | } |
| | | } |
| | | } |
| | | if (skipInboundAndShipping) { |
| | | return; |
| | | } |
| | | List<SalesLedgerProduct> dbProducts = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>().eq(SalesLedgerProduct::getSalesLedgerId, ledger.getId()).eq(SalesLedgerProduct::getType, SaleEnum.SALE.getCode())); |
| | |
| | | |
| | | ledger.setContractAmount(BigDecimal.ZERO); |
| | | salesLedgerMapper.insert(ledger); |
| | | bindImportProcessRoute(ledger.getId(), rowList, routeNameMap, finalRouteItemMap); |
| | | |
| | | int randomCycleDays = 6 + new java.util.Random().nextInt(3); // 6, 7, 8 |
| | | Date reportDate = rowList.get(0).getReportDate(); |
| | | bindImportProcessRoute(ledger.getId(), rowList, routeNameMap, finalRouteItemMap, reportDate, randomCycleDays); |
| | | int reviewCount = 0; |
| | | |
| | | BigDecimal contractAmount = BigDecimal.ZERO; |
| | |
| | | // salesLedgerProductServiceImpl.addProductionData(product); |
| | | contractAmount = contractAmount.add(lineAmount); |
| | | |
| | | boolean skipInboundAndShipping = false; |
| | | if (customer.getCustomerName() != null && customer.getCustomerName().startsWith("è¡¥ç")) { |
| | | if (ledger.getEntryDate() != null) { |
| | | java.time.LocalDate entryDate = com.ruoyi.common.utils.DateUtils.toLocalDate(ledger.getEntryDate()); |
| | | if (entryDate.plusDays(7).isAfter(java.time.LocalDate.now())) { |
| | | skipInboundAndShipping = true; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (customer.getCustomerName() != null && customer.getCustomerName().startsWith("è¡¥ç") && !skipInboundAndShipping) { |
| | | Long inspectId = createNotShippingQualityInspect(ledger, product, row, qty); |
| | | stockUtils.addStock( |
| | | ledger.getId(), |
| | |
| | | product.getId() |
| | | ); |
| | | |
| | | StockInRecord inRecord = stockInRecordMapper.selectOne(new LambdaQueryWrapper<StockInRecord>() |
| | | StockInRecord inRecord = stockInRecordMapper.selectOne(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<StockInRecord>() |
| | | .eq(StockInRecord::getSalesLedgerProductId, product.getId()) |
| | | .orderByDesc(StockInRecord::getId).last("LIMIT 1")); |
| | | if (inRecord != null) { |
| | |
| | | } |
| | | inRecord.setInboundBatches(batch); |
| | | if (row.getReportDate() != null) { |
| | | LocalDateTime reportDateTime = LocalDateTime.ofInstant(row.getReportDate().toInstant(), ZoneId.systemDefault()); |
| | | java.time.LocalDateTime reportDateTime = java.time.LocalDateTime.ofInstant(row.getReportDate().toInstant(), java.time.ZoneId.systemDefault()); |
| | | inRecord.setCreateTime(reportDateTime); |
| | | inRecord.setUpdateTime(reportDateTime); |
| | | } |
| | | stockInRecordMapper.updateById(inRecord); |
| | | } |
| | | |
| | | StockOutRecord outRecord = stockOutRecordMapper.selectOne(new LambdaQueryWrapper<StockOutRecord>() |
| | | StockOutRecord outRecord = stockOutRecordMapper.selectOne(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<StockOutRecord>() |
| | | .eq(StockOutRecord::getSalesLedgerProductId, product.getId()) |
| | | .orderByDesc(StockOutRecord::getId).last("LIMIT 1")); |
| | | if (outRecord != null) { |
| | |
| | | } catch (Exception e) { |
| | | log.error("èªå¨çæå货审æ¹ç³è¯·å¤±è´¥", e); |
| | | } |
| | | |
| | | try { |
| | | AfterSalesServiceNewDto afterSalesDto = new AfterSalesServiceNewDto(); |
| | | afterSalesDto.setSalesLedgerId(ledger.getId()); |
| | | afterSalesDto.setCustomerName(customer.getCustomerName()); |
| | | afterSalesDto.setCheckUserId(creatorUser.getUserId()); |
| | | afterSalesDto.setProDesc("åºç°å®ç"); |
| | | |
| | | List<AfterSalesProductDto> afterSalesProducts = new ArrayList<>(); |
| | | List<Long> productModelIdList = new ArrayList<>(); |
| | | for (SalesLedgerProduct p : latestProducts) { |
| | | AfterSalesProductDto productDto = new AfterSalesProductDto(); |
| | | productDto.setId(p.getId()); |
| | | productDto.setAfterSalesQuantity(defaultDecimal(p.getQuantity())); |
| | | afterSalesProducts.add(productDto); |
| | | if (p.getProductModelId() != null) { |
| | | productModelIdList.add(p.getProductModelId()); |
| | | } |
| | | } |
| | | afterSalesDto.setAfterSalesProductList(afterSalesProducts); |
| | | afterSalesDto.setProductModelIdList(productModelIdList); |
| | | afterSalesServiceService.addAfterSalesServiceDto(afterSalesDto); |
| | | } catch (Exception e) { |
| | | log.error("èªå¨çæå®åè®°å½åéç¥å¤±è´¥", e); |
| | | } |
| | | } |
| | | |
| | | salesLedgerMapper.updateById(ledger); |
| | |
| | | return result; |
| | | } |
| | | |
| | | private void bindImportProcessRoute(Long salesLedgerId, List<SalesNotShippingImportDto> rowList, Map<String, ProcessRoute> routeNameMap, Map<Long, List<ProcessRouteItem>> routeItemMap) { |
| | | private void bindImportProcessRoute(Long salesLedgerId, List<SalesNotShippingImportDto> rowList, Map<String, ProcessRoute> routeNameMap, Map<Long, List<ProcessRouteItem>> routeItemMap, Date reportDate, int randomCycleDays) { |
| | | String flowKey = rowList.stream().map(SalesNotShippingImportDto::getProcessFlow).filter(StringUtils::hasText).map(this::normalizeRouteFlowKey).filter(StringUtils::hasText).findFirst().orElse(""); |
| | | if (!StringUtils.hasText(flowKey)) { |
| | | throw new ServiceException("导å
¥å¤±è´¥,订åå·¥èºæµç¨ä¸è½ä¸ºç©º"); |
| | |
| | | bindList.add(bind); |
| | | } |
| | | salesLedgerProcessRouteService.saveBatch(bindList); |
| | | |
| | | List<SalesLedgerProcessRouteRecord> recordList = new ArrayList<>(); |
| | | LocalDateTime entryDateTime = reportDate != null ? LocalDateTime.ofInstant(reportDate.toInstant(), ZoneId.systemDefault()) : LocalDateTime.now(); |
| | | int totalItems = routeItems.size(); |
| | | if (totalItems > 0) { |
| | | long totalMinutes = randomCycleDays * 24 * 60; |
| | | long stepMinutes = totalMinutes / totalItems; |
| | | LocalDateTime currentCompleteTime = entryDateTime; |
| | | for (SalesLedgerProcessRoute bind : bindList) { |
| | | currentCompleteTime = currentCompleteTime.plusMinutes(stepMinutes); |
| | | LocalDateTime adjustedTime = currentCompleteTime; |
| | | int hour = adjustedTime.getHour(); |
| | | if (hour < 10) { |
| | | adjustedTime = adjustedTime.withHour(10).withMinute(10); |
| | | } else if (hour >= 12 && hour < 14) { |
| | | adjustedTime = adjustedTime.withHour(14).withMinute(10); |
| | | } else if (hour > 18 || (hour == 18 && adjustedTime.getMinute() > 30)) { |
| | | adjustedTime = adjustedTime.plusDays(1).withHour(10).withMinute(10); |
| | | } |
| | | if (!recordList.isEmpty()) { |
| | | LocalDateTime prevTime = recordList.get(recordList.size() - 1).getCompletedTime(); |
| | | if (!adjustedTime.isAfter(prevTime)) { |
| | | adjustedTime = prevTime.plusMinutes(15); |
| | | int newHour = adjustedTime.getHour(); |
| | | if (newHour == 12 || newHour == 13) { |
| | | adjustedTime = adjustedTime.withHour(14).withMinute(0); |
| | | } else if (newHour > 18 || (newHour == 18 && adjustedTime.getMinute() > 30)) { |
| | | adjustedTime = adjustedTime.plusDays(1).withHour(10).withMinute(0); |
| | | } |
| | | } |
| | | } |
| | | currentCompleteTime = adjustedTime; |
| | | SalesLedgerProcessRouteRecord record = new SalesLedgerProcessRouteRecord(); |
| | | record.setSalesLedgerId(salesLedgerId); |
| | | record.setSalesLedgerProcessRouteId(bind.getId()); |
| | | record.setIsCompleted(1); |
| | | record.setCompletedTime(currentCompleteTime); |
| | | record.setCreateTime(currentCompleteTime); |
| | | recordList.add(record); |
| | | } |
| | | salesLedgerProcessRouteRecordService.saveBatch(recordList); |
| | | } |
| | | } |
| | | |
| | | private ProcessRoute createImportProcessRoute(String flowKey, Map<String, ProcessRoute> routeNameMap, Map<Long, List<ProcessRouteItem>> routeItemMap) { |