From 94288b8314a4cdc9feedfba28292af41104aeaaf Mon Sep 17 00:00:00 2001 From: zhuo <2089219845@qq.com> Date: 星期六, 29 三月 2025 10:06:03 +0800 Subject: [PATCH] 检验任务数据预警 --- inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java | 128 +++++++++++++++++++++++++++++++++++++++++- 1 files changed, 124 insertions(+), 4 deletions(-) diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java index 4443888..f8d709c 100644 --- a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java +++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java @@ -158,6 +158,11 @@ private ISysDictTypeService iSysDictTypeService; @Resource private InsOrderRatesService insOrderRatesService; + @Resource + private InsProductDeviationWarningService insProductDeviationWarningService; + @Resource + private InsProductDeviationWarningDetailService insProductDeviationWarningDetailService; + @Override public IPage<InsOrderPlanVO> selectInsOrderPlanList(Page page, InsOrderPlanDTO insOrderPlanDTO) { @@ -939,6 +944,15 @@ // 鍒ゆ柇鏄惁鏈変笉鍚堟牸, 鏈変笉鍚堟牸涓嶈兘绉诲簱 // todo: ifs绉诲簱 insReportService.isRawMaterial(order); + + // 16 鍒ゆ柇褰撳墠鏍峰搧鏄惁涓哄師鏉愭枡, 鍘熸潗鏂欓渶瑕佽繘琛屾暟鎹垎鏋�, 鍒ゆ柇涔嬪墠10鏉℃暟鎹悓涓�涓緵搴斿晢, 鍚屼竴涓楠岄」鐨勫亸宸槸鍚﹁秴杩�10% + // 鏌ヨifs淇℃伅鑾峰彇鑾峰彇鍓�10涓緵搴斿晢涓�鏍风殑, 妫�楠岄」涓�鏍蜂俊鎭� + threadPoolTaskExecutor.execute(() -> { + // 娣诲姞鍒嗘瀽鏁版嵁 + addAnalysis(productList, ifsInventoryQuantity, order); + }); + + } else { // 淇敼鎴愬搧鐘舵�� // 鍒ゆ柇鏄惁鏈変笉鍚堟牸 @@ -957,6 +971,115 @@ return 1; } + /** + * *****娣诲姞鍒嗘瀽鏁版嵁****** + * @param productList + * @param ifsInventoryQuantity + * @param order + */ + private void addAnalysis(List<InsProduct> productList, IfsInventoryQuantity ifsInventoryQuantity, InsOrder order) { + for (InsProduct insProduct : productList) { + // todo: 鏆傛椂鍒ゆ柇鏄惁鏄�佸寲 + if (insProduct.getInspectionItem().contains("鑰佸寲")) { + List<InsProductDeviationWarningDetail> insProductAnalysisDtoList = insProductMapper.selectAnalysis(insProduct, ifsInventoryQuantity.getSupplierName()); + + if (insProductAnalysisDtoList.size() < 10) { + continue; + } + + // 鍒ゆ柇褰撳墠妫�娴嬮」鏄惁鍋忓樊瓒呰繃10% + List<String> laseValueList = insProductAnalysisDtoList.stream().map(InsProductDeviationWarningDetail::getTestValue) + .collect(Collectors.toList()); + + double deviation = isDeviationOverTenPercent(laseValueList, insProduct.getLastValue()); + // 鍒ゆ柇鍋忓樊鏄惁澶т簬10 + if (deviation > 10) { + // 鍒ゆ柇涔嬪墠鏄惁娣诲姞杩�, 娣诲姞杩囦笉闇�瑕佹坊鍔� + long count = insProductDeviationWarningService.count(Wrappers.<InsProductDeviationWarning>lambdaQuery() + .eq(InsProductDeviationWarning::getInsProductId, insProduct.getId())); + if (count == 0L) { + // 鍙戦�侀�氱煡, 骞朵笖娣诲姞鏁版嵁 + // 娣诲姞涓昏〃淇℃伅 + InsProductDeviationWarning deviationWarning = new InsProductDeviationWarning(); + deviationWarning.setInsOrderId(order.getId()); + deviationWarning.setInsSampleId(insProduct.getInsSampleId()); + deviationWarning.setInsProductId(insProduct.getId()); + deviationWarning.setEntrustCode(order.getEntrustCode()); + deviationWarning.setSampleCode(insProduct.getSampleCode()); + deviationWarning.setSupplierName(ifsInventoryQuantity.getSupplierName()); + deviationWarning.setDeviationValue(Double.toString(deviation)); + deviationWarning.setDetectionTime(insProduct.getUpdateTime()); + insProductDeviationWarningService.save(deviationWarning); + + // 娣诲姞璇︽儏鏁版嵁 + InsProductDeviationWarningDetail deviationWarningDetail = new InsProductDeviationWarningDetail(); + deviationWarningDetail.setInsOrderId(order.getId()); + deviationWarningDetail.setInsSampleId(insProduct.getInsSampleId()); + deviationWarningDetail.setInsProductId(insProduct.getId()); + deviationWarningDetail.setEntrustCode(order.getEntrustCode()); + deviationWarningDetail.setSampleCode(insProduct.getSampleCode()); + deviationWarningDetail.setSupplierName(ifsInventoryQuantity.getSupplierName()); + deviationWarningDetail.setTestValue(insProduct.getLastValue()); + deviationWarningDetail.setIsIssue(1); + + insProductAnalysisDtoList.add(deviationWarningDetail); + + // 娣诲姞id + for (InsProductDeviationWarningDetail warningDetail : insProductAnalysisDtoList) { + warningDetail.setDeviationWarningId(deviationWarning.getDeviationWarningId()); + } + + insProductDeviationWarningDetailService.saveBatch(insProductAnalysisDtoList); + + +// String message = ""; +// message += "妫�楠屼换鍔″鏍搁�氱煡"; +// message += "\n鎻愪氦浜�: " + userName; +// message += "\n濮旀墭缂栧彿: " + order.getEntrustCode(); +// message += "\n鏍峰搧鍚嶇О: " + insSample.getModel(); +// message += "\n瑙勬牸鍨嬪彿: " + order.getPartDetail(); +// if (ifsInventoryQuantity != null) { +// message += "\n鎵规鍙�: " + ifsInventoryQuantity.getUpdateBatchNo(); +// } +// //鍙戦�佷紒涓氬井淇℃秷鎭�氱煡 鎻愪氦澶嶆牳 +// try { +// WxCpUtils.inform(sendUserAccount, message, null); +// } catch (Exception e) { +// throw new RuntimeException(e); +// } + } + } + } + } + } + + /** + * *****璁$畻鍋忓樊**** + * @param data + * @param targetStr + * @return + */ + public static double isDeviationOverTenPercent(List<String> data, String targetStr) { + if (data.isEmpty()) { + return 0; + } + List<Double> doubleData = data.stream() + .map(Double::parseDouble) + .collect(Collectors.toList()); + double sum = doubleData.stream().mapToDouble(Double::doubleValue).sum(); + double average = sum / doubleData.size(); + + double target = Double.parseDouble(targetStr); + double deviationPercent = Math.abs(target - average) / average * 100; + + return deviationPercent; + } + + /** + * ******鍘熷璁板綍妯℃澘澶嶅埗***** + * @param orderId + * @param ids + */ private void templateCopy(Integer orderId, List<Integer> ids) { // 鍒犻櫎鍘熸湰妯℃澘 insOrderStandardTemplateService.remove(Wrappers.<InsOrderStandardTemplate>lambdaQuery() @@ -1904,10 +2027,6 @@ ConfigureBuilder builder = Configure.builder(); builder.useSpringEL(true); - // 鑾峰彇褰撳墠鏃堕棿 - LocalDate currentDate = LocalDate.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - String formattedDate = currentDate.format(formatter); InputStream inputStream = this.getClass().getResourceAsStream("/static/small-report-template.docx"); XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render( @@ -2444,6 +2563,7 @@ InputStream inputStream = this.getClass().getResourceAsStream("/static/report-template.docx"); Configure configure = Configure.builder() .bind("deviceList", new HackLoopTableRenderPolicy()) + .useSpringEL(true) .build(); XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render( -- Gitblit v1.9.3