| | |
| | | } |
| | | } |
| | | } |
| | | 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()); |
| | |
| | | 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()); |
| | |
| | | } |
| | | } |
| | | // 进行公式计算 |
| | | 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()); |
| | |
| | | } |
| | | } |
| | | // 进行公式计算 |
| | | String resultValue = calculationFormula(list, v.get(0)); |
| | | String resultValue = calculationFormula(list, v.get(0), k); |
| | | map.put(k, resultValue); |
| | | }); |
| | | return map; |
| | |
| | | |
| | | private static Pattern SPATTERN = Pattern.compile("([-+])?\\d+(\\.\\d+)?"); |
| | | /** |
| | | * 解析String数据 |
| | | * 只需X轴 |
| | | * @param data 采集到的文件字符串 |
| | | * @param dataConfig 用户配置好的x,y轴定位数据与参照物 |
| | | * @return |
| | |
| | | } |
| | | } |
| | | // 进行公式计算 |
| | | String resultValue = calculationFormula(list, v.get(0)); |
| | | String resultValue = calculationFormula(list, v.get(0), k); |
| | | map.put(k, resultValue); |
| | | }); |
| | | return map; |
| | |
| | | * @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())) { |
| | | |
| | |
| | | // 否则:没有公式代表不需要计算,直接提取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; |
| | | } |
| | | } |
| | | |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | 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; |
| | | } |