From f682213b9ff8a7d41ea16edfb1b68d996c46e080 Mon Sep 17 00:00:00 2001
From: zhuo <2089219845@qq.com>
Date: 星期六, 29 三月 2025 14:03:36 +0800
Subject: [PATCH] 1.清除无用方法 2.检测项目预警修改 3.数采绑定调整

---
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java |  394 ++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 310 insertions(+), 84 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 69d71dc..8daa256 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
@@ -2,6 +2,8 @@
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
@@ -30,6 +32,7 @@
 import com.ruoyi.basic.service.StandardTemplateService;
 import com.ruoyi.common.constant.DictDataConstants;
 import com.ruoyi.common.constant.InsOrderTypeConstants;
+import com.ruoyi.common.constant.MenuJumpPathConstants;
 import com.ruoyi.common.core.domain.entity.Custom;
 import com.ruoyi.common.core.domain.entity.InformationNotification;
 import com.ruoyi.common.core.domain.entity.User;
@@ -42,6 +45,7 @@
 import com.ruoyi.inspect.util.HackLoopTableRenderPolicy;
 import com.ruoyi.inspect.vo.InsOrderPlanTaskSwitchVo;
 import com.ruoyi.inspect.vo.InsOrderPlanVO;
+import com.ruoyi.performance.mapper.AuxiliaryOutputWorkingHoursMapper;
 import com.ruoyi.performance.mapper.PerformanceShiftMapper;
 import com.ruoyi.performance.mapper.ShiftTimeMapper;
 import com.ruoyi.performance.pojo.AuxiliaryOutputWorkingHours;
@@ -55,6 +59,7 @@
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.xwpf.usermodel.*;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.io.ClassPathResource;
 import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
@@ -67,8 +72,10 @@
 import java.math.RoundingMode;
 import java.nio.file.Files;
 import java.nio.file.Paths;
+import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.LocalTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -97,14 +104,9 @@
     private InsOrderStateMapper insOrderStateMapper;
     @Resource
     private InsProductMapper insProductMapper;
-    @Resource
-    private ShiftTimeMapper shiftTimeMapper;
-    @Resource
-    private PerformanceShiftMapper performanceShiftMapper;
+
     @Value("${wordUrl}")
     private String wordUrl;
-    @Value("${twoCode}")
-    private String twoCode;
     @Resource
     private InsReportMapper insReportMapper;
     @Resource
@@ -115,6 +117,8 @@
     private AuxiliaryOutputWorkingHoursService auxiliaryOutputWorkingHoursService;
     @Resource
     private AuxiliaryOutputWorkingHoursTemporaryService auxiliaryOutputWorkingHoursTemporaryService;
+    @Resource
+    private AuxiliaryOutputWorkingHoursMapper auxiliaryOutputWorkingHoursMapper;
     @Resource
     private InformationNotificationService informationNotificationService;
     @Resource
@@ -141,8 +145,7 @@
     private InsOrderFactoryVerifyMapper insOrderFactoryVerifyMapper;
     @Resource
     private InsOrderFactoryVerifyItemService insOrderFactoryVerifyItemService;
-    @Value("${file.licenseUrl}")
-    private String licenseUrl;
+
     @Resource
     private SpotCheckQuarterItemMapper spotCheckQuarterItemMapper;
     @Resource
@@ -155,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) {
@@ -228,17 +236,19 @@
 
         // 鏌ヨ鍘傚瀵嗗害
         String supplierDensity = "";
-        SampleProductDto sampleProductDto = list.get(0);
+        if (CollectionUtils.isNotEmpty(list)) {
+            SampleProductDto sampleProductDto = list.get(0);
 
-        // 鍒ゆ柇鏈夋病鏈夌粦瀹氬瀷鍙�
-        String modelValue = insSampleMapper.selectSupplierDensityModel(sampleProductDto.getSample(),
-                order.getProduction(),
-                sampleProductDto.getModel());
-        if (StringUtils.isNotBlank(modelValue)) {
-            supplierDensity = modelValue;
-        } else {
-            supplierDensity = insSampleMapper.selectSupplierDensity(sampleProductDto.getSample(),
-                    order.getProduction());
+            // 鍒ゆ柇鏈夋病鏈夌粦瀹氬瀷鍙�
+            String modelValue = insSampleMapper.selectSupplierDensityModel(sampleProductDto.getSample(),
+                    order.getProduction(),
+                    sampleProductDto.getModel());
+            if (StringUtils.isNotBlank(modelValue)) {
+                supplierDensity = modelValue;
+            } else {
+                supplierDensity = insSampleMapper.selectSupplierDensity(sampleProductDto.getSample(),
+                        order.getProduction());
+            }
         }
         map.put("supplierDensity", supplierDensity);
         return map;
@@ -493,6 +503,14 @@
                     }
                 }
 
+                //鏌ヨ妫�楠屽崟淇℃伅
+                // 娣诲姞宸ユ椂
+                InsProduct finalInsProduct = insProductMapper.selectById(product.getId());
+                threadPoolTaskExecutor.execute(() -> {
+                    InsOrder insOrder = insOrderMapper.selectById(insSample.getInsOrderId());
+                    this.addAuxiliary(userId, finalInsProduct, insOrder);
+                });
+
             }
         });
         String sampleIdStr = insContext.keySet().stream().findFirst().orElse(null);
@@ -509,55 +527,60 @@
 
         // 娣诲姞璁惧璁板綍
         threadPoolTaskExecutor.execute(() -> {
-            InsOrder order = insOrderMapper.selectById(insSample.getInsOrderId());
-            User user = userMapper.selectById(userId);
-            // 鏌ヨ璁惧浣跨敤璁板綍鏌ヨ璇ヨ鍗曠殑浣跨敤璁板綍
-            List<InsOrderDeviceRecordDto> deviceRecordDtoList = insOrderDeviceRecordMapper.selectDeviceNumber(insSample.getInsOrderId());
-            Set<String> recordCodeset = deviceRecordDtoList.stream().map(InsOrderDeviceRecordDto::getManagementNumber).collect(Collectors.toSet());
+            // 娣诲姞璁惧浣跨敤璁板綍
+            addDeviceRecord(insSample, userId);
+        });
+    }
 
-            // 鑾峰彇璁㈠崟璁惧缂栧彿
-            List<InsProductResult> resultList = insProductResultMapper.selectResultByOrderId(insSample.getInsOrderId());
-            Set<String> deviceCodeSet = new HashSet<>();
-            for (InsProductResult result : resultList) {
-                // 娣诲姞璁惧缂栧彿
-                List<JSONObject> jsonObjects = JSON.parseArray(result.getEquipValue(), JSONObject.class);
-                for (JSONObject jsonObject : jsonObjects) {
-                    if (!"".equals(jsonObject.get("v") + "")) {
-                        List<String> v = StrUtil.split(jsonObject.get("v") + "", "锛�");
-                        deviceCodeSet.addAll(v);
-                    }
+    private synchronized void addDeviceRecord(InsSample insSample, Integer userId) {
+        InsOrder order = insOrderMapper.selectById(insSample.getInsOrderId());
+        User user = userMapper.selectById(userId);
+        // 鏌ヨ璁惧浣跨敤璁板綍鏌ヨ璇ヨ鍗曠殑浣跨敤璁板綍
+        List<InsOrderDeviceRecordDto> deviceRecordDtoList = insOrderDeviceRecordMapper.selectDeviceNumber(insSample.getInsOrderId());
+        Set<String> recordCodeset = deviceRecordDtoList.stream().map(InsOrderDeviceRecordDto::getManagementNumber).collect(Collectors.toSet());
+
+        // 鑾峰彇璁㈠崟璁惧缂栧彿
+        List<InsProductResult> resultList = insProductResultMapper.selectResultByOrderId(insSample.getInsOrderId());
+        Set<String> deviceCodeSet = new HashSet<>();
+        for (InsProductResult result : resultList) {
+            // 娣诲姞璁惧缂栧彿
+            List<JSONObject> jsonObjects = JSON.parseArray(result.getEquipValue(), JSONObject.class);
+            for (JSONObject jsonObject : jsonObjects) {
+                if (!"".equals(jsonObject.get("v") + "")) {
+                    List<String> v = StrUtil.split(jsonObject.get("v") + "", "锛�");
+                    deviceCodeSet.addAll(v);
                 }
             }
-            // 1.鍒ゆ柇鏄惁鏈夋病鏈夋坊鍔犵殑浣跨敤璁板綍
-            Set<String> orderDeviceNumbers = getDeviceDifference(deviceCodeSet, recordCodeset);
-            // 娣诲姞浣跨敤璁板綍, 鏍规嵁缂栧彿鏌ヨ璁惧id
-            if (CollectionUtils.isNotEmpty(orderDeviceNumbers)) {
-                List<Integer> orderDeviceIds = insOrderDeviceRecordMapper.selectDeviceIdsByNumbers(orderDeviceNumbers);
-                List<InsOrderDeviceRecord> collect = orderDeviceIds.stream().map(deviceId -> {
-                    InsOrderDeviceRecord insOrderDeviceRecord = new InsOrderDeviceRecord();
-                    insOrderDeviceRecord.setInsOrderId(insSample.getInsOrderId());
-                    insOrderDeviceRecord.setDeviceId(deviceId);
-                    insOrderDeviceRecord.setSampleCode(order.getEntrustCode());
-                    insOrderDeviceRecord.setUseBefore(1);
-                    insOrderDeviceRecord.setUseAfter(1);
-                    insOrderDeviceRecord.setUsePerson(user.getName());
-                    insOrderDeviceRecord.setUsePersonId(user.getId());
-                    return insOrderDeviceRecord;
-                }).collect(Collectors.toList());
+        }
+        // 1.鍒ゆ柇鏄惁鏈夋病鏈夋坊鍔犵殑浣跨敤璁板綍
+        Set<String> orderDeviceNumbers = getDeviceDifference(deviceCodeSet, recordCodeset);
+        // 娣诲姞浣跨敤璁板綍, 鏍规嵁缂栧彿鏌ヨ璁惧id
+        if (CollectionUtils.isNotEmpty(orderDeviceNumbers)) {
+            List<Integer> orderDeviceIds = insOrderDeviceRecordMapper.selectDeviceIdsByNumbers(orderDeviceNumbers);
+            List<InsOrderDeviceRecord> collect = orderDeviceIds.stream().map(deviceId -> {
+                InsOrderDeviceRecord insOrderDeviceRecord = new InsOrderDeviceRecord();
+                insOrderDeviceRecord.setInsOrderId(insSample.getInsOrderId());
+                insOrderDeviceRecord.setDeviceId(deviceId);
+                insOrderDeviceRecord.setSampleCode(order.getEntrustCode());
+                insOrderDeviceRecord.setUseBefore(1);
+                insOrderDeviceRecord.setUseAfter(1);
+                insOrderDeviceRecord.setUsePerson(user.getName());
+                insOrderDeviceRecord.setUsePersonId(user.getId());
+                return insOrderDeviceRecord;
+            }).collect(Collectors.toList());
 
-                insOrderDeviceRecordService.saveBatch(collect);
+            insOrderDeviceRecordService.saveBatch(collect);
 
-            }
+        }
 
-            // 2.鍒ゆ柇鏄惁鍙栨秷浜嗚澶囦娇鐢�
-            Set<String> repoprNumbers = getDeviceDifference(recordCodeset, deviceCodeSet);
-            if (CollectionUtils.isNotEmpty(repoprNumbers)) {
-                List<Integer> reportDeviceIds = insOrderDeviceRecordMapper.selectDeviceIdsByNumbers(repoprNumbers);
-                insOrderDeviceRecordMapper.delete(Wrappers.<InsOrderDeviceRecord>lambdaQuery()
-                        .in(InsOrderDeviceRecord::getDeviceId, reportDeviceIds)
-                        .eq(InsOrderDeviceRecord::getInsOrderId, insSample.getInsOrderId()));
-            }
-        });
+        // 2.鍒ゆ柇鏄惁鍙栨秷浜嗚澶囦娇鐢�
+        Set<String> repoprNumbers = getDeviceDifference(recordCodeset, deviceCodeSet);
+        if (CollectionUtils.isNotEmpty(repoprNumbers)) {
+            List<Integer> reportDeviceIds = insOrderDeviceRecordMapper.selectDeviceIdsByNumbers(repoprNumbers);
+            insOrderDeviceRecordMapper.delete(Wrappers.<InsOrderDeviceRecord>lambdaQuery()
+                    .in(InsOrderDeviceRecord::getDeviceId, reportDeviceIds)
+                    .eq(InsOrderDeviceRecord::getInsOrderId, insSample.getInsOrderId()));
+        }
     }
 
     private static Set<String> getDeviceDifference(Set<String> number1, Set<String> number2) {
@@ -656,7 +679,7 @@
     }
 
     /**
-     * todo: 娓呴櫎娌℃湁浣跨敤鐨勬楠岄」
+     * todo: 鍘熷璁板綍妯℃澘娓呴櫎娌℃湁浣跨敤鐨勬楠岄」(鏆傛椂鏈塨ug鏃犳硶浣跨敤)
      * @param sheet
      * @param itemNameList
      */
@@ -780,11 +803,13 @@
             int count = 0;
             for (InsProduct product : insProducts) {
                 count++;
-                str += "<br/>" + count + "锛�" + product.getInspectionItem() + " " + product.getInspectionItemSubclass() + "<br/>";
-
+                str +=  (count != 0 ? "\n" : "") + count + "锛�" +
+                        product.getInspectionItemClass() + " " +
+                        product.getInspectionItem() + " " +
+                        product.getInspectionItemSubclass();
             }
             if (ObjectUtils.isNotEmpty(str)) {
-                throw new ErrorException("<strong>瀛樺湪寰呮楠岀殑椤圭洰锛�</strong><br/>" + str);
+                throw new ErrorException("瀛樺湪寰呮楠岀殑椤圭洰锛�" + str);
             }
         }
 
@@ -810,7 +835,7 @@
         info.setSenderId(userId);
         info.setConsigneeId(verifyUser);
         info.setViewStatus(false);
-        info.setJumpPath("b1-inspect-orderPlan-review");
+        info.setJumpPath(MenuJumpPathConstants.INSPECTION_REVIEW);
         informationNotificationService.addInformationNotification(info);
 
         // 6.澶嶆牳浜�--鏂板妫�楠屽崟鐩稿叧璐熻矗浜�
@@ -856,19 +881,19 @@
         }
 
         // 12.娣诲姞宸ユ椂
-        // 鍒犻櫎鍘熸湰璁㈠崟宸ユ椂
-        auxiliaryOutputWorkingHoursService.remove(Wrappers.<AuxiliaryOutputWorkingHours>lambdaQuery()
-                .eq(AuxiliaryOutputWorkingHours::getOrderId, orderId));
-        // 鏌ヨ宸ユ椂鏆傚瓨
-        List<AuxiliaryOutputWorkingHoursTemporary> hoursTemporaries = auxiliaryOutputWorkingHoursTemporaryService.list(Wrappers.<AuxiliaryOutputWorkingHoursTemporary>lambdaQuery()
-                .eq(AuxiliaryOutputWorkingHoursTemporary::getOrderId, orderId));
-        List<AuxiliaryOutputWorkingHours> outputWorkingHours = hoursTemporaries.stream().map(hoursTemporary -> {
-            AuxiliaryOutputWorkingHours workingHours = new AuxiliaryOutputWorkingHours();
-            BeanUtil.copyProperties(hoursTemporary, workingHours);
-            workingHours.setId(null);
-            return workingHours;
-        }).collect(Collectors.toList());
-        auxiliaryOutputWorkingHoursService.saveBatch(outputWorkingHours);
+//        // 鍒犻櫎鍘熸湰璁㈠崟宸ユ椂
+//        auxiliaryOutputWorkingHoursService.remove(Wrappers.<AuxiliaryOutputWorkingHours>lambdaQuery()
+//                .eq(AuxiliaryOutputWorkingHours::getOrderId, orderId));
+//        // 鏌ヨ宸ユ椂鏆傚瓨
+//        List<AuxiliaryOutputWorkingHoursTemporary> hoursTemporaries = auxiliaryOutputWorkingHoursTemporaryService.list(Wrappers.<AuxiliaryOutputWorkingHoursTemporary>lambdaQuery()
+//                .eq(AuxiliaryOutputWorkingHoursTemporary::getOrderId, orderId));
+//        List<AuxiliaryOutputWorkingHours> outputWorkingHours = hoursTemporaries.stream().map(hoursTemporary -> {
+//            AuxiliaryOutputWorkingHours workingHours = new AuxiliaryOutputWorkingHours();
+//            BeanUtil.copyProperties(hoursTemporary, workingHours);
+//            workingHours.setId(null);
+//            return workingHours;
+//        }).collect(Collectors.toList());
+//        auxiliaryOutputWorkingHoursService.saveBatch(outputWorkingHours);
 
         // 13.娣诲姞璁㈠崟璐圭敤缁熻淇℃伅
         List<InsProduct> productList = insProductMapper.selectProductByOrderId(orderId);
@@ -924,6 +949,15 @@
             // 鍒ゆ柇鏄惁鏈変笉鍚堟牸, 鏈変笉鍚堟牸涓嶈兘绉诲簱
             // todo: ifs绉诲簱
             insReportService.isRawMaterial(order);
+
+            // 16 鍒ゆ柇褰撳墠鏍峰搧鏄惁涓哄師鏉愭枡, 鍘熸潗鏂欓渶瑕佽繘琛屾暟鎹垎鏋�, 鍒ゆ柇涔嬪墠10鏉℃暟鎹悓涓�涓緵搴斿晢, 鍚屼竴涓楠岄」鐨勫亸宸槸鍚﹁秴杩�10%
+            // 鏌ヨifs淇℃伅鑾峰彇鑾峰彇鍓�10涓緵搴斿晢涓�鏍风殑, 妫�楠岄」涓�鏍蜂俊鎭�
+            threadPoolTaskExecutor.execute(() -> {
+                // 娣诲姞鍒嗘瀽鏁版嵁
+                addAnalysis(productList, ifsInventoryQuantity, order);
+            });
+
+
         } else {
             // 淇敼鎴愬搧鐘舵��
             // 鍒ゆ柇鏄惁鏈変笉鍚堟牸
@@ -942,6 +976,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("鑰佸寲") && insProduct.getInsResult().equals(1)) {
+                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()
@@ -1889,10 +2032,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(
@@ -2429,6 +2568,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(
@@ -4227,7 +4367,7 @@
         FileOutputStream os = null;
         try {
             //鍑瘉 涓嶇劧鍒囨崲鍚庢湁姘村嵃
-            InputStream is = Files.newInputStream(new File(licenseUrl).toPath());
+            InputStream is = new ClassPathResource("/lib/license.xml").getInputStream();
             License license = new License();
             license.setLicense(is);
             if (!license.getIsLicensed()) {
@@ -4294,4 +4434,90 @@
                 .set(SpotCheckQuarterItem::getResult, unqualifiedCount.equals(0L) ? "鍚堟牸" : "涓嶅悎鏍�"));
     }
 
+    /**
+     * 娣诲姞宸ユ椂
+     * @param userId
+     * @param insProduct
+     * @param insOrder
+     */
+    private synchronized void addAuxiliary(Integer userId, InsProduct insProduct, InsOrder insOrder) {
+        if (insProduct.getIsBinding().equals(1)) {
+            return;
+        }
+
+        //棣栧厛鍒ゆ柇褰撳墠浜虹殑褰撳墠鏃堕棿鏄惁鏄帓鐝椂闂村唴,濡傛灉涓嶆槸灏辨槸鍔犵彮
+        LocalDateTime today = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT);
+
+        //鏍¢獙濡傛灉杩欎釜浜鸿繖涓娴嬮」鐩凡缁忔坊鍔犺繃浜�
+        List<AuxiliaryOutputWorkingHours> count2s = auxiliaryOutputWorkingHoursMapper.selectList(Wrappers.<AuxiliaryOutputWorkingHours>lambdaQuery()
+                .eq(AuxiliaryOutputWorkingHours::getCheck, userId)
+                .eq(AuxiliaryOutputWorkingHours::getInsProductId, insProduct.getId()));
+        if (CollectionUtils.isNotEmpty(count2s)) {
+            auxiliaryOutputWorkingHoursMapper.deleteBatchIds(count2s.stream().map(auxiliaryOutputWorkingHours -> auxiliaryOutputWorkingHours.getId()).collect(Collectors.toList()));
+        }
+        if (ObjectUtils.isNotEmpty(insProduct.getManHour()) && StringUtils.isNotBlank(insProduct.getLastValue())) {
+            AuxiliaryOutputWorkingHours auxiliaryOutputWorkingHours = new AuxiliaryOutputWorkingHours();
+            auxiliaryOutputWorkingHours.setInspectionItemClass(insProduct.getInspectionItemClass());//妫�娴嬮」鍒嗙被
+            auxiliaryOutputWorkingHours.setInspectionItem(insProduct.getInspectionItem());//妫�娴嬬埗椤�
+            auxiliaryOutputWorkingHours.setInspectionItemSubclass(insProduct.getInspectionItemSubclass());//妫�娴嬪瓙椤�
+            auxiliaryOutputWorkingHours.setSample(insSampleMapper.selectById(insProduct.getInsSampleId()).getSampleCode());//鏍峰搧缂栧彿
+            auxiliaryOutputWorkingHours.setOrderId(insOrder.getId());//璁㈠崟id
+            auxiliaryOutputWorkingHours.setOrderNo(insOrder.getEntrustCode());//闈炲姞鐝鎵樺崟鍙�
+            auxiliaryOutputWorkingHours.setWorkTime(insProduct.getManHour());//闈炲姞鐝伐鏃�
+            auxiliaryOutputWorkingHours.setAmount(1);//闈炲姞鐝暟閲�
+            auxiliaryOutputWorkingHours.setOutputWorkTime((ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours.getOvertimeWorkTime()) ? auxiliaryOutputWorkingHours.getOvertimeWorkTime() : BigDecimal.ZERO).add(ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours.getWorkTime()) ? auxiliaryOutputWorkingHours.getWorkTime() : BigDecimal.ZERO));//浜ч噺宸ユ椂
+            auxiliaryOutputWorkingHours.setManHourGroup(insProduct.getManHourGroup());//宸ユ椂鍒嗙粍
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+            DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+            auxiliaryOutputWorkingHours.setDateTime(LocalDateTime.now().toLocalDate().atStartOfDay().format(formatters));//鏃ユ湡
+            LocalDateTime localDateTime = LocalDateTime.now();
+            DateTime parse = DateUtil.parse(localDateTime.format(formatter));
+            auxiliaryOutputWorkingHours.setWeekDay(getWeek(localDateTime.format(formatters)));//鏄熸湡
+            auxiliaryOutputWorkingHours.setWeek(String.valueOf(DateUtil.weekOfYear(DateUtil.offsetDay(parse, 1))));//鍛ㄦ
+            auxiliaryOutputWorkingHours.setCheck(userId);//妫�娴嬩汉
+            auxiliaryOutputWorkingHours.setPrice(insProduct.getPrice());//鍗曚环
+            auxiliaryOutputWorkingHours.setSampleId(insProduct.getInsSampleId());//鏍峰搧id
+            auxiliaryOutputWorkingHours.setInsProductId(insProduct.getId());//妫�楠岄」id
+
+            auxiliaryOutputWorkingHoursMapper.insert(auxiliaryOutputWorkingHours);
+
+        }
+    }
+
+
+    public static String getWeek(String dayStr) {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        try {
+            Date date = sdf.parse(dayStr);
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(date);
+            int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
+            int day = calendar.get(Calendar.DAY_OF_MONTH);
+            return getWeekDay(dayOfWeek);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    public static String getWeekDay(int dayOfWeek) {
+        switch (dayOfWeek) {
+            case Calendar.MONDAY:
+                return "鍛ㄤ竴";
+            case Calendar.TUESDAY:
+                return "鍛ㄤ簩";
+            case Calendar.WEDNESDAY:
+                return "鍛ㄤ笁";
+            case Calendar.THURSDAY:
+                return "鍛ㄥ洓";
+            case Calendar.FRIDAY:
+                return "鍛ㄤ簲";
+            case Calendar.SATURDAY:
+                return "鍛ㄥ叚";
+            case Calendar.SUNDAY:
+                return "鍛ㄦ棩";
+            default:
+                return "鏈煡";
+        }
+    }
 }

--
Gitblit v1.9.3