Crunchy
2024-07-19 193daa341f2123d07a0dda7111fbceb02bb734c9
文件采集完成 - 80%
已修改1个文件
172 ■■■■■ 文件已修改
cnas-server/src/main/java/com/yuanchu/mom/utils/DataAcquisition.java 172 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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,y!");
                    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+)?");
    /**
     * 解析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 + ",Y轴值:" + 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;
    }
    /**
     * 解析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++) {
                    // 得出用户配置的x轴
                    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) {}
                    }
                    // 得出用户配置的x轴
//                    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 + ",Y轴值:" + 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;
    }
    /**
     * 解析String数据
     * 取X,Y两个定位
     * @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 + ",Y轴值:" + 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;
    }