yaowanxin
2 天以前 b91fd38a14e93ae6f1a1fb2babfe7ca8c1c420fe
修改方法,SQL
已修改2个文件
163 ■■■■■ 文件已修改
cnas-device/src/main/java/com/ruoyi/device/utils/DataAcquisition.java 159 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cnas-device/src/main/resources/mapper/DeviceMaintenanceMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cnas-device/src/main/java/com/ruoyi/device/utils/DataAcquisition.java
@@ -117,7 +117,7 @@
                    map = analysisList(data, userMap, device, entrustCode, sampleCode);
                    break;
                case ".xls":
                    map = analysisString(data, userMap, device, entrustCode, sampleCode);
                    map = analysisTxt(data, userMap, device, entrustCode, sampleCode);
                    break;
                case ".txt":
                    map = analysisTxt(data, userMap, device, entrustCode, sampleCode);
@@ -479,6 +479,7 @@
                    String firstNumber = lastLine.split("\t")[0];
                    list.add(firstNumber);
                } else {
                    list = analyzeData(data, v, k, ",");
                }
                // 委托编号与样品编号存在
@@ -545,7 +546,24 @@
        });
        return map;
    }
    public static Map<String, Object> analysisList1(String data, Map<String, List<DataConfig>> dataConfig,
                                                   Device device, String entrustCode, String sampleCode) {
        Map<String, Object> map = new HashMap<>();
        dataConfig.forEach((k, v) -> {
            List<Object> list = new ArrayList<>();
            // 委托编号与样品编号不存在,定:1、Y定范围,X定横坐标;2、只存在Y;3、只存在X
            if (ObjectUtils.isEmpty(device.getEntrustCode()) && ObjectUtils.isEmpty(device.getSampleCode())) {
                list = analyzeData(data, v, k, splitIdentifier);
                // 委托编号与样品编号存在
            } else if (ObjectUtils.isNotEmpty(device.getEntrustCode()) && ObjectUtils.isNotEmpty(device.getSampleCode())) {
                list = analyzeDataEntrustCodAndSampleCode(data, v, k, splitIdentifier, device, entrustCode, sampleCode);
            }
            // 进行公式计算
            Object resultValue = calculationFormula(list, v.get(0), k, device);
            map.put(k, resultValue);
        });
        return map;
    }
    private static List<Object> analyzeDataEntrustCodAndSampleCode(String data, List<DataConfig> v, String k, String splitIdentifier,
                                                                   Device device, String entrustCodeValue, String sampleCodeValue) {
        entrustCodeValue = entrustCodeValue.replaceAll(" ", "");
@@ -631,7 +649,117 @@
    private static String getRefer(String refer) {
        return ObjectUtils.isNotEmpty(refer) ? refer.replaceAll(" ", "") : "";
    }
    /**
     * 委托编号与样品编号都为空执行
     *
     * @param data  采集到的文件字符串
     * @param v     用户配置好的x,y轴定位数据与参照物
     * @param k     检验项名称
     * @param split 分割符
     * @return 提取的数据列表
     */
    public static List<Object> analyzeData1(String data, List<DataConfig> v, String k, String split) {
        List<Object> list = new ArrayList<>();
        // 预处理数据:移除多余空格并保留关键分隔符
        String processedData = data.replaceAll("\\s+", " ").trim();
        for (int configIndex = 0; configIndex < v.size(); configIndex++) {
            // 取两个用户配置的参照物
            String referx = getRefer(v.get(configIndex).getReferx());
            String refery = getRefer(v.get(configIndex).getRefery());
            if (ObjectUtils.isEmpty(refery) && ObjectUtils.isEmpty(referx)) {
                System.out.println("参照物为空,跳过当前配置,k: " + k);
                continue;
            }
            // 最终结果
            List<Object> result = new ArrayList<>();
            // 通过\n将字符串分割为行
            String[] aColumnY = processedData.replaceAll(" ", "").split("\n");
            Integer end = null;
            // 采集数据:Y轴
            for (int i = 0; i < aColumnY.length; i++) {
                String line = aColumnY[i].trim();
                if (line.isEmpty()) continue; // 跳过空行
                // 如果Y参照不为空与X参照为空则执行,同时该行包含Y参照
                if (ObjectUtils.isNotEmpty(refery) && ObjectUtils.isEmpty(referx) && line.contains(refery)) {
                    try {
                        // 取Y坐标值
                        int y = getXOrY(v.get(configIndex).getY(), k, "Y");
                        String[] aLineX = line.split(split);
                        for (int j = 0; j < aLineX.length; j++) {
                            if (aLineX[j].contains(refery)) {
                                if (i + y >= aColumnY.length) {
                                    System.err.println(k + ":Y轴定位超出数据范围,当前数据行数: " + aColumnY.length + ",尝试访问行: " + (i + y));
                                    continue;
                                }
                                String[] split1 = aColumnY[i + y].split(split);
                                if (j >= split1.length) {
                                    System.err.println(k + ":X轴定位超出数据范围,当前行元素个数: " + split1.length + ",尝试访问位置: " + j);
                                    continue;
                                }
                                result.add(split1[j]);
                            }
                        }
                    } catch (Exception e) {
                        System.err.println(k + ":在处理仅Y参照逻辑时出现异常: " + e.getMessage());
                    }
                }
                // 如果Y参照不为空与X参照不为空则执行,此处Y定区域
                else if (ObjectUtils.isNotEmpty(refery) && ObjectUtils.isNotEmpty(referx)) {
                    try {
                        // 取x的值,防止报错
                        int x = getXOrY(v.get(configIndex).getX(), k, "X");
                        // 取Y坐标值
                        int y = getXOrY(v.get(configIndex).getY(), k, "Y");
                        // 缓存Y的结束值
                        if (ObjectUtils.isEmpty(end) && line.contains(refery)) {
                            end = i + y;
                        }
                        // 判断是否在参照物为起点,Y坐标值为最终范围
                        if (ObjectUtils.isNotEmpty(end) && i <= end) {
                            String[] aLineX = line.split(split);
                            for (int j = 0; j < aLineX.length; j++) {
                                if (aLineX[j].contains(referx)) {
                                    if (j + x >= aLineX.length) {
                                        System.err.println(k + ":X轴定位超出数据范围,当前行元素个数: " + aLineX.length + ",尝试访问位置: " + (j + x));
                                        continue;
                                    }
                                    result.add(aLineX[j + x]);
                                    break;
                                }
                            }
                        }
                    } catch (Exception e) {
                        System.err.println(k + ":在处理XY参照逻辑时出现异常: " + e.getMessage());
                    }
                }
                // 如果X参照不为空同时该行包含X参照,则执行下面的代码
                else if (line.contains(referx) && ObjectUtils.isEmpty(refery)) {
                    try {
                        String[] aLineX = line.split(split);
                        // 取x的值,防止报错
                        int x = getXOrY(v.get(configIndex).getX(), k, "X");
                        for (int j = 0; j < aLineX.length; j++) {
                            if (aLineX[j].contains(referx)) {
                                if (j + x >= aLineX.length) {
                                    System.err.println(k + ":X轴定位超出数据范围,当前行元素个数: " + aLineX.length + ",尝试访问位置: " + (j + x));
                                    continue;
                                }
                                result.add(aLineX[j + x]);
                            }
                        }
                    } catch (Exception e) {
                        System.err.println(k + ":在处理仅X参照逻辑时出现异常: " + e.getMessage());
                    }
                }
            }
            // 防止计算公式的时候出现:[null] 这种数据
            if (ObjectUtils.isNotEmpty(result)) {
                list.addAll(result);
            }
        }
        return list;
    }
    /**
     * 委托编号与样品编号都为空执行
     *
@@ -643,6 +771,10 @@
     */
    public static List<Object> analyzeData(String data, List<DataConfig> v, String k, String split) {
        List<Object> list = new ArrayList<>();
        // 预处理数据:移除多余空格并保留关键分隔符
//        String processedData = data.replaceAll("\\s+", " ").trim();
        for (int config = 0; config < v.size(); config++) {
            // 取两个用户配置的参照物
            String referx = getRefer(v.get(config).getReferx());
@@ -651,17 +783,20 @@
                continue;
            }
            // 最终结果
            List<Object> result = new ArrayList<>();
//            List<Object> result = new ArrayList<>();
            // 通过\n将字符串分割为行
            String[] aColumnY = data.replaceAll(" ", "").split("\n");
            Integer end = null;
            // 采集数据:Y轴
            for (int i = 0; i < aColumnY.length; i++) {
//                String line = aColumnY[i].trim();
//                if (line.isEmpty()) continue; // 跳过空行
                // 如果Y参照不为空与X参照为空则执行,同时该行包含Y参照
                if (ObjectUtils.isNotEmpty(refery) && ObjectUtils.isEmpty(referx) && aColumnY[i].contains(refery)) {
                if (ObjectUtils.isNotEmpty(refery) && ObjectUtils .isEmpty(referx) && aColumnY[i].contains(refery)) {
                    // 取Y坐标值
                    int y = getXOrY(v.get(config).getY(), k, "Y");
                    String[] aLineX = aColumnY[i].split(split);
//                    String[] aLineX = line.split(split);
                    for (int j = 0; j < aLineX.length; j++) {
                        if (aLineX[j].contains(refery)) {
                            String[] split1 = new String[0];
@@ -671,7 +806,9 @@
                                throw new ErrorException(k + ":Y轴定位超出!");
                            }
                            try {
                                result.add(split1[j]);
//                                System.out.println("----------");
                                list.add(split1[j]);
                            } catch (Exception e) {
                                throw new ErrorException(k + ":X轴定位超出!");
                            }
@@ -693,7 +830,8 @@
                        for (int j = 0; j < aLineX.length; j++) {
                            if (aLineX[j].contains(referx)) {
                                try {
                                    result.add(aLineX[j + x]);
//                                    System.out.println("77777777777777");
                                    list.add(aLineX[j + x]);
                                } catch (Exception e) {
                                    throw new ErrorException(k + ":X轴定位超出!");
                                }
@@ -709,7 +847,8 @@
                    for (int j = 0; j < aLineX.length; j++) {
                        if (aLineX[j].contains(referx)) {
                            try {
                                result.add(aLineX[j + x]);
//                                System.out.println("4444444444444444");
                                list.add(aLineX[j + x]);
                            } catch (Exception e) {
                                throw new ErrorException(k + ":X轴定位超出!");
                            }
@@ -718,10 +857,10 @@
                }
            }
            // 防止计算公式的时候出现:[null] 这种数据
            if (ObjectUtils.isNotEmpty(result)) {
//            if (ObjectUtils.isNotEmpty(result)) {
//                String formatProcessing = getFormatProcessing(result);
                list.addAll(result);
            }
//                list.addAll(result);
//            }
        }
        return list;
    }
cnas-device/src/main/resources/mapper/DeviceMaintenanceMapper.xml
@@ -8,8 +8,8 @@
    <select id="selectDeviceMaintenancePage" resultType="com.ruoyi.device.dto.DeviceMaintenanceDto">
        select * from (
        select db.*,
        d.device_name,
        d.management_number
        d.device_name as d_device_name,
        d.management_number as d_management_number
        from device_maintenance db
        left join device d on db.device_id = d.id)a
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">