| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.ruoyi.common.utils.RedisUtil; |
| | | import com.ruoyi.device.constant.DCResistanceMqttConstants; |
| | | import com.ruoyi.device.dto.DeviceCollectionDto; |
| | | import com.ruoyi.device.pojo.DataConfig; |
| | | import com.ruoyi.device.pojo.Device; |
| | |
| | | * @param device |
| | | * @return |
| | | */ |
| | | public static Map<String, Object> dataAcquisitionEntrance(List<DataConfig> dataConfig, Device device, String entrustCode, String sampleCode, String ip, String cableTag) { |
| | | public static Map<String, Object> dataAcquisitionEntrance(List<DataConfig> dataConfig, Device device, String entrustCode, String sampleCode, String ip, String cableTag, String dbUserName, String dbPassword,String dbTable) { |
| | | // 判断是否是影像测量仪 |
| | | if (device.getManagementNumber().equals("JCZX-ZB-OP07001")) { |
| | | if (device.getFileType().equals(".xlsx")) { |
| | |
| | | "&sampleCode=" + sampleCode + |
| | | "&mdbEntrustCode=" + device.getEntrustCode() + |
| | | "&mdbSampleCode=" + device.getSampleCode() + |
| | | "&dbFileName=" + device.getDbFileName(); |
| | | "&dbFileName=" + device.getDbFileName()+ |
| | | "&dbUserName=" + dbUserName + |
| | | "&dbPassword=" + dbPassword + |
| | | "&dbTable=" + dbTable; |
| | | System.out.println("请求的 URL: " + http); |
| | | String result = null; |
| | | try { |
| | |
| | | } |
| | | break; |
| | | case ".db": |
| | | // map = analysisDb1(data, userMap, device); |
| | | map = analysisDb(data, userMap, device); |
| | | break; |
| | | case ".mysql": |
| | | // map = analysisDb1(data, userMap, device); |
| | | map = analysisDb(data, userMap, device); |
| | | break; |
| | | case ".png": |
| | | map = readPngString(data, userMap, device); |
| | | break; |
| | | case ".mqtt": |
| | | map = getActualResistanceValueAsMap(userMap, device); |
| | | break; |
| | | default: |
| | | map = null; |
| | |
| | | return map; |
| | | } |
| | | } |
| | | /** |
| | | * 从 Redis 中获取实际电阻值,并以键值对形式返回 |
| | | * @param dataConfig 数据配置信息 |
| | | * @param device 设备信息 |
| | | * @return 包含实际电阻值处理结果的键值对;若未获取到有效数据则返回空 Map |
| | | */ |
| | | public static Map<String, Object> getActualResistanceValueAsMap(Map<String, List<DataConfig>> dataConfig, Device device) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | if (ObjectUtils.isEmpty(dataConfig)) { |
| | | return map; |
| | | } |
| | | dataConfig.forEach((k, v) -> { |
| | | AtomicInteger numberOfDataEntries = new AtomicInteger(); |
| | | List<Object> list = new ArrayList<>(); |
| | | for (int config = 0; config < v.size(); config++) { |
| | | String refery = getRefer(v.get(config).getRefery()); |
| | | // 从 Redis 中获取值 |
| | | Object value = RedisUtil.get(refery); |
| | | if (ObjectUtils.isNotEmpty(value)) { |
| | | if (value instanceof String && ((String) value).startsWith("[") && ((String) value).endsWith("]")) { |
| | | try { |
| | | // 解析 JSON 数组字符串为 List<BigDecimal> |
| | | List<BigDecimal> values = JSONArray.parseArray((String) value, BigDecimal.class); |
| | | list.addAll(values); |
| | | numberOfDataEntries.addAndGet(values.size()); |
| | | } catch (Exception e) { |
| | | // 解析失败,记录错误日志,使用原字符串值 |
| | | System.err.println("解析 Redis 返回的 JSON 数组失败: " + value); |
| | | list.add(value); |
| | | numberOfDataEntries.addAndGet(1); |
| | | } |
| | | } else { |
| | | numberOfDataEntries.addAndGet(1); |
| | | list.add(value); |
| | | |
| | | } |
| | | } |
| | | } |
| | | // 拼接数采配置 |
| | | List<Object> result = new ArrayList<>(); |
| | | for (int i = 0; i < numberOfDataEntries.get(); i++) { |
| | | StringBuilder aggregate = new StringBuilder(); |
| | | for (int j = 0; j < v.size(); j++) { |
| | | int index; |
| | | if (j == 0) { |
| | | index = i; |
| | | } else { |
| | | index = numberOfDataEntries.get() + i; |
| | | } |
| | | if (index < list.size()) { |
| | | aggregate.append(list.get(index).toString()).append(","); |
| | | } |
| | | } |
| | | if (aggregate.length() > 0) { |
| | | aggregate.setLength(aggregate.length() - 1); |
| | | } |
| | | result.add(aggregate.toString()); |
| | | } |
| | | // 进行公式计算 |
| | | Object resultValue = calculationFormula(result, v.get(0), k, device); |
| | | map.put(k, resultValue); |
| | | }); |
| | | return map; |
| | | } |
| | | |
| | | |
| | | public static Map<String, Object> createFrequency(String entrustCode, String sampleCode, Map<String, Object> map) { |
| | | Set<String> set = new LinkedHashSet<>(); |
| | |
| | | |
| | | return "1"; |
| | | } |
| | | private static Map<String, Object> analysisDb1(String data, Map<String, List<DataConfig>> dataConfig, Device device) { |
| | | JSONObject jsonObject = JSON.parseObject(data); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | if (jsonObject.isEmpty()) { |
| | | return map; |
| | | } |
| | | // 从 JSON 数据中提取 data 数组 |
| | | JSONArray dataList = JSONArray.parseArray(jsonObject.get("data").toString()); |
| | | dataConfig.forEach((k, v) -> { |
| | | AtomicInteger numberOfDataEntries = new AtomicInteger(); |
| | | List<Object> list = new ArrayList<>(); |
| | | for (int config = 0; config < v.size(); config++) { |
| | | String refery = getRefer(v.get(config).getRefery()); |
| | | for (int i = 0; i < dataList.size(); i++) { |
| | | JSONObject jsonObject1 = JSON.parseObject(dataList.get(i).toString()); |
| | | // if (ObjectUtils.isNotEmpty(jsonObject1.get(refery))) { |
| | | // numberOfDataEntries.addAndGet(1); |
| | | // list.add(jsonObject1.get(refery)); |
| | | // } |
| | | Object o = jsonObject1.get(refery); |
| | | if (ObjectUtils.isNotEmpty(o)) { |
| | | numberOfDataEntries.addAndGet(1); |
| | | list.add(o); |
| | | } |
| | | } |
| | | } |
| | | // 拼接数采配置 |
| | | List<Object> result = new ArrayList<>(); |
| | | for (int i = 0; i < numberOfDataEntries.get(); i++) { |
| | | StringBuilder aggregate = new StringBuilder(); |
| | | for (int j = 0; j < v.size(); j++) { |
| | | int index; |
| | | if (j == 0) { |
| | | index = i; |
| | | } else { |
| | | index = numberOfDataEntries.get() + i; |
| | | } |
| | | aggregate.append(list.get(index).toString()).append(","); |
| | | } |
| | | if (aggregate.length() > 0) { |
| | | aggregate.setLength(aggregate.length() - 1); |
| | | } |
| | | result.add(aggregate.toString()); |
| | | } |
| | | // 进行公式计算 |
| | | Object resultValue = calculationFormula(result, v.get(0), k, device); |
| | | map.put(k, resultValue); |
| | | }); |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 需要通过X,Y轴定位 |
| | |
| | | * @param dataConfig |
| | | * @return |
| | | */ |
| | | |
| | | private static Map<String, Object> analysisDb(String data, Map<String, List<DataConfig>> dataConfig, Device device) { |
| | | JSONObject jsonObject = JSON.parseObject(data); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | if (jsonObject.isEmpty()) { |
| | | return map; |
| | | } |
| | | // 从 JSON 数据中提取 data 数组 |
| | | JSONArray dataList = JSONArray.parseArray(jsonObject.get("data").toString()); |
| | | dataConfig.forEach((k, v) -> { |
| | | AtomicInteger numberOfDataEntries = new AtomicInteger(); |
| | | List<Object> list = new ArrayList<>(); |
| | | for (int config = 0; config < v.size(); config++) { |
| | | // String refery = v.get(config).getRefery(); |
| | | String refery = getRefer(v.get(config).getRefery()); |
| | | for (int i = 0; i < dataList.size(); i++) { |
| | | JSONObject jsonObject1 = JSON.parseObject(dataList.get(i).toString()); |
| | |
| | | listResult.addAll(list); |
| | | } |
| | | // 为了给前端做数据区分 |
| | | if (listResult.size() > 1) { |
| | | if (listResult.size() >= 1) { |
| | | hashMap.put("result", listResult); |
| | | } else { |
| | | hashMap.put("result", listResult.get(0).toString()); |
| | |
| | | }); |
| | | 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(" ", ""); |
| | |
| | | continue; |
| | | } |
| | | // 最终结果 |
| | | // List<Object> result = new ArrayList<>(); |
| | | List<Object> result = new ArrayList<>(); |
| | | // 通过\n将字符串分割为行 |
| | | String[] aColumnY = data.replaceAll(" ", "").split("\n"); |
| | | Integer end = null; |
| | |
| | | } |
| | | try { |
| | | // System.out.println("----------"); |
| | | list.add(split1[j]); |
| | | result.add(split1[j]); |
| | | |
| | | } catch (Exception e) { |
| | | throw new ErrorException(k + ":X轴定位超出!"); |
| | |
| | | if (aLineX[j].contains(referx)) { |
| | | try { |
| | | // System.out.println("77777777777777"); |
| | | list.add(aLineX[j + x]); |
| | | result.add(aLineX[j + x]); |
| | | } catch (Exception e) { |
| | | throw new ErrorException(k + ":X轴定位超出!"); |
| | | } |
| | |
| | | if (aLineX[j].contains(referx)) { |
| | | try { |
| | | // System.out.println("4444444444444444"); |
| | | list.add(aLineX[j + x]); |
| | | result.add(aLineX[j + x]); |
| | | } catch (Exception e) { |
| | | throw new ErrorException(k + ":X轴定位超出!"); |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | // 防止计算公式的时候出现:[null] 这种数据 |
| | | // if (ObjectUtils.isNotEmpty(result)) { |
| | | // 防止计算公式的时候出现:[null] 这种数据 |
| | | if (ObjectUtils.isNotEmpty(result)) { |
| | | // String formatProcessing = getFormatProcessing(result); |
| | | // list.addAll(result); |
| | | // } |
| | | list.addAll(result); |
| | | } |
| | | } |
| | | return list; |
| | | } |