From 0e5bddf6084d3dfb7bcad7217d4320898416eba3 Mon Sep 17 00:00:00 2001
From: zouyu <2723363702@qq.com>
Date: 星期四, 23 十月 2025 16:49:12 +0800
Subject: [PATCH] 拆分原材料和外购成品的业务流程(报检、下单、检验)
---
cnas-device/src/main/java/com/ruoyi/device/utils/DataAcquisition.java | 94 +++++++++-------------------------------------
1 files changed, 19 insertions(+), 75 deletions(-)
diff --git a/cnas-device/src/main/java/com/ruoyi/device/utils/DataAcquisition.java b/cnas-device/src/main/java/com/ruoyi/device/utils/DataAcquisition.java
index c717dd4..751b778 100644
--- a/cnas-device/src/main/java/com/ruoyi/device/utils/DataAcquisition.java
+++ b/cnas-device/src/main/java/com/ruoyi/device/utils/DataAcquisition.java
@@ -7,9 +7,11 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.ruoyi.common.core.domain.Result;
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;
@@ -26,6 +28,8 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+import static com.ruoyi.framework.datasource.DynamicDataSourceContextHolder.log;
+
public class DataAcquisition {
private static final String HTTP = "http://";
@@ -37,6 +41,8 @@
private static final String splitIdentifier = "@-@"; // 鑷畾涔夊敮涓�鏍囪瘑鍒嗗壊绗�
public static final String frequency = "frequency";
+
+ private CollectBridgeMapper collectBridgeMapper;
/**
* 鏁伴噰鍏ュ彛
@@ -71,14 +77,17 @@
* 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;
@@ -86,7 +95,6 @@
String result = null;
try {
result = HttpUtil.get(http);
- System.out.println("璇锋眰杩斿洖缁撴灉: " + result);
} catch (IORuntimeException e) {
e.printStackTrace();
throw new ErrorException("鎵�鍦ㄧ數鑴戞湭瀹夎鎴栨湭鍚姩锛歀IMS鏂囦欢閲囬泦鍣紒");
@@ -99,7 +107,7 @@
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 -> {
@@ -149,9 +157,9 @@
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;
@@ -163,70 +171,6 @@
}
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 {
- // 瑙f瀽 JSON 鏁扮粍瀛楃涓蹭负 List<BigDecimal>
- List<BigDecimal> values = JSONArray.parseArray((String) value, BigDecimal.class);
- list.addAll(values);
- numberOfDataEntries.addAndGet(values.size());
- } catch (Exception e) {
- // 瑙f瀽澶辫触锛岃褰曢敊璇棩蹇楋紝浣跨敤鍘熷瓧绗︿覆鍊�
- System.err.println("瑙f瀽 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;
}
@@ -549,7 +493,7 @@
* @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());
@@ -579,7 +523,7 @@
if (listResult.size() >= 1) {
hashMap.put("result", listResult);
} else {
- hashMap.put("result", listResult.get(0).toString());
+ hashMap.put("result", listResult);
}
hashMap.put("equipName", device.getDeviceName());
hashMap.put("equipValue", device.getManagementNumber());
@@ -760,7 +704,7 @@
}
// 闃叉鍙傜収鐗╀负绌烘姤閿欙紝杩涜鍒ゆ柇濡傛灉涓虹┖璧嬪�肩┖瀛楃
- private static String getRefer(String refer) {
+ public static String getRefer(String refer) {
return ObjectUtils.isNotEmpty(refer) ? refer.replaceAll(" ", "") : "";
}
/**
--
Gitblit v1.9.3