| | |
| | | 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); |
| | |
| | | String firstNumber = lastLine.split("\t")[0]; |
| | | list.add(firstNumber); |
| | | } else { |
| | | |
| | | list = analyzeData(data, v, k, ","); |
| | | } |
| | | // 委托编号与样品编号存在 |
| | |
| | | }); |
| | | 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(" ", ""); |
| | |
| | | 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; |
| | | } |
| | | /** |
| | | * 委托编号与样品编号都为空执行 |
| | | * |
| | |
| | | */ |
| | | 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()); |
| | |
| | | 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]; |
| | |
| | | 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轴定位超出!"); |
| | | } |
| | |
| | | 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轴定位超出!"); |
| | | } |
| | |
| | | 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轴定位超出!"); |
| | | } |
| | |
| | | } |
| | | } |
| | | // 防止计算公式的时候出现:[null] 这种数据 |
| | | if (ObjectUtils.isNotEmpty(result)) { |
| | | // if (ObjectUtils.isNotEmpty(result)) { |
| | | // String formatProcessing = getFormatProcessing(result); |
| | | list.addAll(result); |
| | | } |
| | | // list.addAll(result); |
| | | // } |
| | | } |
| | | return list; |
| | | } |