From ca7685886ae8a4a4bb6717d48a1c48cf3934faf3 Mon Sep 17 00:00:00 2001
From: zouyu <2723363702@qq.com>
Date: 星期五, 21 十一月 2025 22:20:25 +0800
Subject: [PATCH] oa调整
---
cnas-device/src/main/java/com/ruoyi/device/utils/DataAcquisition.java | 101 +++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 79 insertions(+), 22 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 360eae6..05308ae 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,7 +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;
@@ -24,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://";
@@ -36,6 +42,8 @@
public static final String frequency = "frequency";
+ private CollectBridgeMapper collectBridgeMapper;
+
/**
* 鏁伴噰鍏ュ彛
*
@@ -43,7 +51,7 @@
* @param device
* @return
*/
- 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) {
+ public static Map<String, Object> dataAcquisitionEntrance(List<DataConfig> dataConfig, Device device, String entrustCode,String lotBatchNo, String sampleCode, String ip, String cableTag, String dbUserName, String dbPassword,String dbTable) {
// 鍒ゆ柇鏄惁鏄奖鍍忔祴閲忎华
if (device.getManagementNumber().equals("JCZX-ZB-OP07001")) {
if (device.getFileType().equals(".xlsx")) {
@@ -69,22 +77,26 @@
* 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 +
+ "&lotBatchNo=" + lotBatchNo +
+ "&cableTag=" + cableTag +
"&dbTable=" + dbTable;
System.out.println("璇锋眰鐨� URL: " + http);
String result = null;
try {
result = HttpUtil.get(http);
- System.out.println("璇锋眰杩斿洖缁撴灉: " + result);
} catch (IORuntimeException e) {
e.printStackTrace();
throw new ErrorException("鎵�鍦ㄧ數鑴戞湭瀹夎鎴栨湭鍚姩锛歀IMS鏂囦欢閲囬泦鍣紒");
@@ -97,7 +109,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 -> {
@@ -116,11 +128,12 @@
case ".docx":
map = analysisString(data, userMap, device, entrustCode, sampleCode);
break;
+ case ".xls":
case ".xlsx":
map = analysisList(data, userMap, device, entrustCode, sampleCode);
break;
- case ".xls":
- map = analysisTxt(data, userMap, device, entrustCode, sampleCode);
+ case ".pngInExcel":
+ map = analysisPngInExcel(data, userMap, device, entrustCode, sampleCode);
break;
case ".txt":
map = analysisTxt(data, userMap, device, entrustCode, sampleCode);
@@ -147,6 +160,9 @@
case ".png":
map = readPngString(data, userMap, device);
break;
+// case ".mqtt":
+// map = getActualResistanceValueAsMap(userMap, device);
+// break;
default:
map = null;
break;
@@ -159,6 +175,7 @@
return map;
}
}
+
public static Map<String, Object> createFrequency(String entrustCode, String sampleCode, Map<String, Object> map) {
Set<String> set = new LinkedHashSet<>();
@@ -263,9 +280,10 @@
// 浠� JSON 鏁版嵁涓彁鍙� data 鏁扮粍
JSONArray dataList = JSONArray.parseArray(jsonObject.get("data").toString());
dataConfig.forEach((k, v) -> {
- AtomicInteger numberOfDataEntries = new AtomicInteger();
+ AtomicInteger numberOfDataEntries = new AtomicInteger(0);
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());
@@ -280,15 +298,15 @@
List<Object> result = new ArrayList<>();
for (int i = 0; i < numberOfDataEntries.get(); i++) {
String aggregate = "";
- for (int j = 0; j < v.size(); j++) {
- int index;
- if (j == 0) {
- index = i;
- } else {
- index = numberOfDataEntries.get() + i;
- }
- aggregate += list.get(index).toString() + ",";
- }
+// for (int j = 0; j < v.size(); j++) {
+// int index;
+// if (j == 0) {
+// index = i;
+// } else {
+// index = numberOfDataEntries.get() + i;
+// }
+// }
+ aggregate += list.get(i).toString() + ",";
int lastIndex = aggregate.lastIndexOf(",");
String substring = aggregate.substring(0, lastIndex);
result.add(substring);
@@ -478,7 +496,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());
@@ -505,10 +523,10 @@
listResult.addAll(list);
}
// 涓轰簡缁欏墠绔仛鏁版嵁鍖哄垎
- if (listResult.size() > 1) {
+ 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());
@@ -546,6 +564,45 @@
} else if (ObjectUtils.isNotEmpty(device.getEntrustCode()) && ObjectUtils.isNotEmpty(device.getSampleCode())) {
list = analyzeDataEntrustCodAndSampleCode(data, v, k, ",", device, entrustCode, sampleCode);
}
+ // 杩涜鍏紡璁$畻
+ Object resultValue = calculationFormula(list, v.get(0), k, device);
+ map.put(k, resultValue);
+ });
+ return map;
+ }
+
+ /**
+ * 瑙f瀽excel涓瘑鍒埌鐨勫浘鐗囧唴瀹�
+ *
+ * @param data 閲囬泦鍒扮殑鏂囦欢瀛楃涓�
+ * @param dataConfig 鐢ㄦ埛閰嶇疆濂界殑x,y杞村畾浣嶆暟鎹笌鍙傜収鐗�
+ * @return
+ */
+ private static Map<String, Object> analysisPngInExcel(String data, Map<String, List<DataConfig>> dataConfig,
+ Device device, String entrustCode, String sampleCode) {
+ Map<String, Object> map = new HashMap<>();
+ //澶勭悊data
+ Map<String,List<Object>> dataMap = new HashMap<>();
+ String[] rows = data.split("\n");
+ String[] headRow = rows[0].split(" ");//鑾峰彇琛ㄥご鍒楄〃
+ for (int i = 0; i < headRow.length; i++) {
+ //鏁版嵁鏈�澶氫簲鏉�
+ List<Object> vals = new ArrayList<>();
+ for (int j = 1; j <= 5; j++) {
+ String[] cols = rows[j].split(" ");
+ vals.add(cols[i]);
+ }
+ dataMap.put(headRow[i],vals);
+ }
+ dataConfig.forEach((k, v) -> {
+ List<Object> list = new ArrayList<>();
+ v.stream().sorted(Comparator.comparing(DataConfig::getX)).forEach(config->{
+ for (Map.Entry<String, List<Object>> entry : dataMap.entrySet()) {
+ if(entry.getKey().contains(config.getReferx())){
+ list.addAll(entry.getValue());
+ }
+ }
+ });
// 杩涜鍏紡璁$畻
Object resultValue = calculationFormula(list, v.get(0), k, device);
map.put(k, resultValue);
@@ -689,7 +746,7 @@
}
// 闃叉鍙傜収鐗╀负绌烘姤閿欙紝杩涜鍒ゆ柇濡傛灉涓虹┖璧嬪�肩┖瀛楃
- private static String getRefer(String refer) {
+ public static String getRefer(String refer) {
return ObjectUtils.isNotEmpty(refer) ? refer.replaceAll(" ", "") : "";
}
/**
--
Gitblit v1.9.3