| | |
| | | import com.ruoyi.common.utils.RedisUtil; |
| | | import com.ruoyi.device.constant.DCResistanceMqttConstants; |
| | | import com.ruoyi.device.dto.DeviceCollectionDto; |
| | | import com.ruoyi.device.mapper.CollectBridgeMapper; |
| | | import com.ruoyi.device.pojo.DataConfig; |
| | | import com.ruoyi.device.pojo.Device; |
| | | import com.ruoyi.framework.exception.ErrorException; |
| | |
| | | private static final String splitIdentifier = "@-@"; // 自定义唯一标识分割符 |
| | | |
| | | public static final String frequency = "frequency"; |
| | | |
| | | private CollectBridgeMapper collectBridgeMapper; |
| | | |
| | | /** |
| | | * 数采入口 |
| | |
| | | * mdbEntrustCode mdb文件需要:委托编号字段 为什么没有去这个mdb前缀呢?因为已经给客户的部分电脑上安装了采集器,而用户不接受重新安装采集器,所以就没有去除 |
| | | * mdbSampleCode mdb文件需要:样品编号字段 |
| | | */ |
| | | String mdbEntrustCode = StringUtils.isNotBlank(device.getEntrustCode())?device.getEntrustCode():""; |
| | | String mdbSampleCode = StringUtils.isNotBlank(device.getSampleCode())?device.getSampleCode():""; |
| | | String dbFileName = StringUtils.isNotBlank(device.getDbFileName())?device.getDbFileName():""; |
| | | String http = HTTP + ip + GETFILE + |
| | | "?filePath=" + device.getCollectUrl() + |
| | | "&fileExtension=" + device.getFileType() + |
| | | "&entrustCode=" + entrustCode + |
| | | "&sampleCode=" + sampleCode + |
| | | "&mdbEntrustCode=" + device.getEntrustCode() + |
| | | "&mdbSampleCode=" + device.getSampleCode() + |
| | | "&dbFileName=" + device.getDbFileName()+ |
| | | "&mdbEntrustCode=" + mdbEntrustCode + |
| | | "&mdbSampleCode=" + mdbSampleCode + |
| | | "&dbFileName=" + dbFileName + |
| | | "&dbUserName=" + dbUserName + |
| | | "&dbPassword=" + dbPassword + |
| | | "&dbTable=" + dbTable; |
| | |
| | | String result = null; |
| | | try { |
| | | result = HttpUtil.get(http); |
| | | System.out.println("请求返回结果: " + result); |
| | | } catch (IORuntimeException e) { |
| | | e.printStackTrace(); |
| | | throw new ErrorException("所在电脑未安装或未启动:LIMS文件采集器!"); |
| | |
| | | throw new ErrorException(jsonObject.get("msg") + ""); |
| | | } |
| | | } else { |
| | | String data = jsonObject.get("data") + ""; |
| | | String data = jsonObject.get("data") + ""; |
| | | // 考虑到一个检测项可能会存在多个数采配置,所以需要进行分组 |
| | | Map<String, List<DataConfig>> userMap = dataConfig.stream() |
| | | .peek(i -> { |
| | |
| | | case ".png": |
| | | map = readPngString(data, userMap, device); |
| | | break; |
| | | case ".mqtt": |
| | | map = getActualResistanceValueAsMap(userMap, device); |
| | | break; |
| | | // case ".mqtt": |
| | | // map = getActualResistanceValueAsMap(userMap, device); |
| | | // break; |
| | | default: |
| | | map = null; |
| | | break; |
| | |
| | | } |
| | | 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()); |
| | | if (refery.equals(DCResistanceMqttConstants.NSDQCS_DQCS_DZZ)){ |
| | | // 从 Redis 中获取一个数据 |
| | | Object value = RedisUtil.get(refery); |
| | | list.add(value); |
| | | numberOfDataEntries.addAndGet(1); |
| | | }else { |
| | | // 从 Redis 中获取列表数据 |
| | | List<Object> objectList = RedisUtil.lGet(refery, 0, -1); |
| | | for (Object item : objectList) { |
| | | // System.out.println(item); |
| | | String[] split = item.toString().replace("[","").replace("]","").split(","); |
| | | for (Object a : |
| | | split) { |
| | | list.add(a); |
| | | numberOfDataEntries.addAndGet(1); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 拼接数采配置 |
| | | 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; |
| | | } |
| | | |
| | | |
| | |
| | | * @param dataConfig 存储公式的对象 |
| | | * @return |
| | | */ |
| | | private static Object calculationFormula(List<Object> list, DataConfig dataConfig, String insProductItem, Device device) { |
| | | public static Object calculationFormula(List<Object> list, DataConfig dataConfig, String insProductItem, Device device) { |
| | | if (list.size() == 0) { |
| | | Map<String, Object> hashMap = new HashMap<>(); |
| | | hashMap.put("equipName", device.getDeviceName()); |
| | |
| | | } |
| | | |
| | | // 防止参照物为空报错,进行判断如果为空赋值空字符 |
| | | private static String getRefer(String refer) { |
| | | public static String getRefer(String refer) { |
| | | return ObjectUtils.isNotEmpty(refer) ? refer.replaceAll(" ", "") : ""; |
| | | } |
| | | /** |