From 193daa341f2123d07a0dda7111fbceb02bb734c9 Mon Sep 17 00:00:00 2001
From: Crunchy <3114200645@qq.com>
Date: 星期五, 19 七月 2024 17:55:03 +0800
Subject: [PATCH] 文件采集完成 - 80%

---
 cnas-server/src/main/java/com/yuanchu/mom/utils/DataAcquisition.java |  172 +++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 107 insertions(+), 65 deletions(-)

diff --git a/cnas-server/src/main/java/com/yuanchu/mom/utils/DataAcquisition.java b/cnas-server/src/main/java/com/yuanchu/mom/utils/DataAcquisition.java
index 99e3fd7..b2ffe28 100644
--- a/cnas-server/src/main/java/com/yuanchu/mom/utils/DataAcquisition.java
+++ b/cnas-server/src/main/java/com/yuanchu/mom/utils/DataAcquisition.java
@@ -97,10 +97,17 @@
                     }
                 }
             }
+            map.put("frequency", "1");
             return Result.success(map);
         }
     }
 
+    /**
+     * 闇�瑕侀�氳繃X,Y杞村畾浣�
+     * @param data
+     * @param dataConfig
+     * @return
+     */
     private static Map<String, String> analysisDb(String data, Map<String, List<DataConfig>> dataConfig) {
         JSONObject jsonObject = JSON.parseObject(data);
         JSONArray dataList = JSONArray.parseArray(jsonObject.get("data").toString());
@@ -111,7 +118,7 @@
             for (int config = 0; config < v.size(); config++) {
                 String referx = v.get(config).getReferx();
                 if(ObjectUtils.isEmpty(v.get(config).getX()) && ObjectUtils.isEmpty(v.get(config).getY())) {
-                    throw new ErrorException("鏈粰" + k + "杩涜鏁伴噰閰嶇疆x锛寉锛�");
+                    continue;
                 }
                 int x = Integer.parseInt(v.get(config).getX());
                 int y = Integer.parseInt(v.get(config).getY());
@@ -128,12 +135,18 @@
                 }
             }
             // 杩涜鍏紡璁$畻
-            String resultValue = calculationFormula(list, v.get(0));
+            String resultValue = calculationFormula(list, v.get(0), k);
             map.put(k, resultValue);
         });
         return map;
     }
 
+    /**
+     * 闇�瑕侀�氳繃X,Y杞村畾浣�
+     * @param data
+     * @param dataConfig
+     * @return
+     */
     private static Map<String, String> analysisMdb(String data, Map<String, List<DataConfig>> dataConfig, String entrustCode, String sampleCode) {
         JSONObject jsonObject = JSON.parseObject(data);
         JSONArray dataList = JSONArray.parseArray(jsonObject.get("data").toString());
@@ -161,7 +174,7 @@
                 }
             }
             // 杩涜鍏紡璁$畻
-            String resultValue = calculationFormula(list, v.get(0));
+            String resultValue = calculationFormula(list, v.get(0), k);
             map.put(k, resultValue);
         });
         return map;
@@ -169,7 +182,7 @@
 
     private static Pattern SPATTERN = Pattern.compile("([-+])?\\d+(\\.\\d+)?");
     /**
-     * 瑙f瀽String鏁版嵁
+     * 鍙渶X杞�
      * @param data 閲囬泦鍒扮殑鏂囦欢瀛楃涓�
      * @param dataConfig 鐢ㄦ埛閰嶇疆濂界殑x,y杞村畾浣嶆暟鎹笌鍙傜収鐗�
      * @return
@@ -204,7 +217,7 @@
                 }
             }
             // 杩涜鍏紡璁$畻
-            String resultValue = calculationFormula(list, v.get(0));
+            String resultValue = calculationFormula(list, v.get(0), k);
             map.put(k, resultValue);
         });
         return map;
@@ -216,7 +229,7 @@
      * @param dataConfig 瀛樺偍鍏紡鐨勫璞�
      * @return
      */
-    private static String calculationFormula(List<Object> list, DataConfig dataConfig) {
+    private static String calculationFormula(List<Object> list, DataConfig dataConfig, String insProductItem) {
         // 濡傛灉涓嶄负绌猴紝杩涜鍏紡璁$畻
         if (ObjectUtils.isNotEmpty(dataConfig.getFormula())) {
 
@@ -224,10 +237,11 @@
         // 鍚﹀垯锛氭病鏈夊叕寮忎唬琛ㄤ笉闇�瑕佽绠楋紝鐩存帴鎻愬彇List閲岄潰鐨勬暟鎹�
         } else {
             // 杩欓噷鍙細鍙栧垪琛ㄧ涓�涓暟鎹�
-            if (list.size() > 0) {
+            if (list.size() > 1) {
+                throw new ErrorException("鏈粰锛�" + insProductItem + " 閰嶇疆鍏紡锛屽彲鏄嵈閲囬泦鍒颁簡" + list.size() + "涓�硷紒鍒嗗埆涓猴細" + list);
+            } else {
                 return list.get(0).toString();
             }
-            return null;
         }
     }
 
@@ -254,39 +268,41 @@
                     String[] aLineX = aColumnY[i].split(",");
                     for (int j = 0; j < aLineX.length; j++) {
                         if (ObjectUtils.isNotEmpty(referx) && aLineX[j].contains(referx)) {
-                            int x = Integer.parseInt(v.get(config).getX());
                             try {
+                                int x = Integer.parseInt(v.get(config).getX());
                                 xResult = aLineX[j + x];
-                            } catch (Exception e) {
-                                throw new ErrorException("鏁伴噰閰嶇疆X杞磋秴鍑猴紒");
-                            }
+                            } catch (Exception e) {}
                         }
                         if (ObjectUtils.isNotEmpty(refery) && aLineX[j].contains(refery)) {
-                            int y = Integer.parseInt(v.get(config).getY());
                             try {
+                                int y = Integer.parseInt(v.get(config).getY());
                                 String[] split = aColumnY[i + y].split(",");
                                 yResult = split[split.length - 1];
-                            } catch (Exception e) {
-                                throw new ErrorException("鏁伴噰閰嶇疆Y杞磋秴鍑猴紒");
-                            }
+                            } catch (Exception e) {}
                         }
                     }
                 }
-                if (ObjectUtils.isEmpty(xResult) && ObjectUtils.isEmpty(yResult)) {
-                    throw new ErrorException("鍙傜収鐗╀负锛�" + referx + "涓�" + refery + "鏈彇鍒板�硷紒璇锋鏌ユ暟閲囬厤缃紒");
+                if (ObjectUtils.isNotEmpty(xResult) && ObjectUtils.isNotEmpty(yResult)) {
+                    if(xResult.equals(yResult)) {
+                        list.add(xResult);
+                    } else {
+                        throw new ErrorException(k + "椤圭洰X杞村�硷細" + xResult + "锛孻杞村�硷細" + yResult + "鍙栧緱鐨勬暟鎹笉鐩稿悓锛佽妫�鏌ユ暟閲囬厤缃紒");
+                    }
                 }
-                list.add(yResult);
-                list.add(xResult);
             }
             // 杩涜鍏紡璁$畻
-            String resultValue = calculationFormula(list, v.get(0));
-            map.put(k, resultValue);
+            if (list.size() > 0) {
+                String resultValue = calculationFormula(list, v.get(0), k);
+                map.put(k, resultValue);
+            } else {
+                map.put(k, null);
+            }
         });
         return map;
     }
 
     /**
-     * 瑙f瀽String鏁版嵁
+     *
      * @param data 閲囬泦鍒扮殑鏂囦欢瀛楃涓�
      * @param dataConfig 鐢ㄦ埛閰嶇疆濂界殑x,y杞村畾浣嶆暟鎹笌鍙傜収鐗�
      * @return
@@ -298,47 +314,74 @@
             List<Object> list = new ArrayList<>();
             for (int config = 0; config < v.size(); config++) {
                 String referx = v.get(config).getReferx();
+                String refery = v.get(config).getRefery();
                 String xResult = null;
+                String yResult = null;
                 // 閫氳繃\n灏嗗瓧绗︿覆鍒嗗壊涓鸿
                 String[] aColumnY = processingDataAfterSpaces.split("\n");
                 // 璇ュ惊鐜緱鍑虹敤鎴烽厤缃殑y杞�
                 for (int i = 0; i < aColumnY.length; i++) {
-                    // 寰楀嚭鐢ㄦ埛閰嶇疆鐨剎杞�
-                    String[] aLineX = aColumnY[i].split(splitIdentifier);
-                    for (int j = 0; j < aLineX.length; j++) {
-                        if (ObjectUtils.isNotEmpty(referx) && aLineX[j].replaceAll(" ", "").contains(referx.replaceAll(" ", ""))) {
-                            int x = Integer.parseInt(v.get(config).getX());
-                            try {
-                                xResult = aLineX[j + x];
-                            } catch (Exception e) {
-                                throw new ErrorException("鏁伴噰閰嶇疆X杞磋秴鍑猴紒");
+                    if (aColumnY[i].replaceAll(" ", "").contains(refery.replaceAll(" ", ""))) {
+                        int y = Integer.parseInt(v.get(config).getY());
+                        int x = Integer.parseInt(v.get(config).getX());
+                        String[] split = aColumnY[i + y].split(splitIdentifier);
+                        for (int i1 = 0; i1 < split.length; i1++) {
+                            if (split[i1].replaceAll(" ", "").equals(referx.replaceAll(" ", ""))) {
+//                                split[i1 + x]
                             }
                         }
+//                        String[] aLineX = aColumnY[i].split(splitIdentifier);
+//                        try {
+//                            int y = Integer.parseInt(v.get(config).getY());
+//                            String[] split = aColumnY[i + y].split(splitIdentifier);
+//                            yResult = split[split.length - 1];
+//                        } catch (Exception e) {}
+                    }
+                    // 寰楀嚭鐢ㄦ埛閰嶇疆鐨剎杞�
+
+//                    for (int j = 0; j < aLineX.length; j++) {
+//                        if (ObjectUtils.isNotEmpty(referx) && aLineX[j].replaceAll(" ", "").contains(referx.replaceAll(" ", ""))) {
+//                            try {
+//                                int x = Integer.parseInt(v.get(config).getX());
+//                                xResult = aLineX[j + x];
+//                            } catch (Exception e) {}
+//                        }
+//
+//                    }
+                }
+                if (ObjectUtils.isNotEmpty(yResult)) {
+                    yResult = yResult.replaceAll(" ", "");
+                    // 缁撴灉鍖呭惈鐗规畩瀛楃锛岄渶瑕佸墧闄ゆ帀
+                    if(yResult.contains("=")) {
+                        String[] split = yResult.split("=");
+                        list.add(split[split.length - 1]);
+                    } else if (yResult.contains(":")) {
+                        String[] split = yResult.split(":");
+                        list.add(split[split.length - 1].replaceAll("%",  ""));
                     }
                 }
-                if (ObjectUtils.isEmpty(xResult)) {
-                    throw new ErrorException("鍙傜収鐗╀负锛�" + referx + "鏈彇鍒板�硷紒璇锋鏌ユ暟閲囬厤缃紒");
-                }
-                // 缁撴灉鍖呭惈鐗规畩瀛楃锛岄渶瑕佸墧闄ゆ帀
-                if(xResult.contains("=")) {
-                    String[] split = xResult.split("=");
-                    list.add(split[split.length - 1]);
-                } else if (xResult.contains(":")) {
-                    String[] split = xResult.split(":");
-                    list.add(split[split.length - 1].replaceAll("%", ""));
-                } else {
-                    list.add(xResult);
+                System.out.println(xResult + "=========" + yResult);
+                if (ObjectUtils.isNotEmpty(xResult) && ObjectUtils.isNotEmpty(yResult)) {
+                    if(xResult.equals(yResult)) {
+                        list.add(xResult);
+                    } else {
+                        throw new ErrorException("X杞村�硷細" + xResult + "锛孻杞村�硷細" + yResult + "鍙栧緱鐨勬暟鎹笉鐩稿悓锛佽妫�鏌ユ暟閲囬厤缃紒");
+                    }
                 }
             }
             // 杩涜鍏紡璁$畻
-            String resultValue = calculationFormula(list, v.get(0));
-            map.put(k, resultValue);
+            if (list.size() > 0) {
+                String resultValue = calculationFormula(list, v.get(0), k);
+                map.put(k, resultValue);
+            } else {
+                map.put(k, null);
+            }
         });
         return map;
     }
 
     /**
-     * 瑙f瀽String鏁版嵁
+     * 鍙朮锛孻涓や釜瀹氫綅
      * @param data 閲囬泦鍒扮殑鏂囦欢瀛楃涓�
      * @param dataConfig 鐢ㄦ埛閰嶇疆濂界殑x,y杞村畾浣嶆暟鎹笌鍙傜収鐗�
      * @return
@@ -360,36 +403,35 @@
                     String[] aLineX = aColumnY[i].split(splitIdentifier);
                     for (int j = 0; j < aLineX.length; j++) {
                         if (ObjectUtils.isNotEmpty(referx) && referx.equals(aLineX[j])) {
-                            int x = Integer.parseInt(v.get(config).getX());
                             try {
+                                int x = Integer.parseInt(v.get(config).getX());
                                 xResult = aLineX[j + x];
-                            } catch (Exception e) {
-                                throw new ErrorException("鏁伴噰閰嶇疆X杞磋秴鍑猴紒");
-                            }
+                            } catch (Exception e) {}
                         }
                         if (ObjectUtils.isNotEmpty(refery) && refery.equals(aLineX[j])) {
-                            int y = Integer.parseInt(v.get(config).getY());
-                            String aColumnData = aColumnY[i + y]; // 鑾峰彇鍒扮Y琛岀殑鏁版嵁
                             try {
+                                int y = Integer.parseInt(v.get(config).getY());
+                                String aColumnData = aColumnY[i + y]; // 鑾峰彇鍒扮Y琛岀殑鏁版嵁
                                 yResult = aColumnData.split(splitIdentifier)[j];
-                            } catch (Exception e) {
-                                throw new ErrorException("鏁伴噰閰嶇疆Y杞磋秴鍑猴紒");
-                            }
+                            } catch (Exception e) {}
                         }
                     }
                 }
-                if (ObjectUtils.isEmpty(xResult) || ObjectUtils.isEmpty(yResult)) {
-                    throw new ErrorException("X杞存垨Y杞存湭鍙栧埌鍊硷紒璇锋鏌ユ暟閲囬厤缃紒");
-                }
-                if(xResult.equals(yResult)) {
-                    list.add(xResult);
-                } else {
-                    throw new ErrorException("X杞翠笌Y杞村彇寰楃殑鏁版嵁涓嶇浉鍚岋紒璇锋鏌ユ暟閲囬厤缃紒");
+                if (ObjectUtils.isNotEmpty(xResult) && ObjectUtils.isNotEmpty(yResult)) {
+                    if(xResult.equals(yResult)) {
+                        list.add(xResult);
+                    } else {
+                        throw new ErrorException("X杞村�硷細" + xResult + "锛孻杞村�硷細" + yResult + "鍙栧緱鐨勬暟鎹笉鐩稿悓锛佽妫�鏌ユ暟閲囬厤缃紒");
+                    }
                 }
             }
             // 杩涜鍏紡璁$畻
-            String resultValue = calculationFormula(list, v.get(0));
-            map.put(k, resultValue);
+            if (list.size() > 0) {
+                String resultValue = calculationFormula(list, v.get(0), k);
+                map.put(k, resultValue);
+            } else {
+                map.put(k, null);
+            }
         });
         return map;
     }

--
Gitblit v1.9.3