From dc7300e21fe53f74e08eb2fa494a83430e2e54ca Mon Sep 17 00:00:00 2001
From: zouyu <2723363702@qq.com>
Date: 星期四, 26 三月 2026 11:25:58 +0800
Subject: [PATCH] 绩效管理:人员考勤功能模块
---
cnas-device/src/main/java/com/ruoyi/device/utils/DataAcquisition.java | 335 +++++++++++++++++++------------------------------------
1 files changed, 116 insertions(+), 219 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 281b5fa..8e600f3 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
@@ -2,15 +2,18 @@
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.fasterxml.jackson.core.type.TypeReference;
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;
@@ -41,6 +44,8 @@
public static final String frequency = "frequency";
+ private CollectBridgeMapper collectBridgeMapper;
+
/**
* 鏁伴噰鍏ュ彛
*
@@ -48,7 +53,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")) {
@@ -74,22 +79,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鏂囦欢閲囬泦鍣紒");
@@ -102,7 +111,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 -> {
@@ -121,17 +130,19 @@
case ".docx":
map = analysisString(data, userMap, device, entrustCode, sampleCode);
break;
+ case ".xls":
case ".xlsx":
+ case ".csv":
map = analysisList(data, userMap, device, entrustCode, sampleCode);
break;
- case ".xls":
- map = analysisTxt(data, userMap, device, entrustCode, sampleCode);
+ case ".serialPort":
+ map = analysisSerialPortList(data, userMap, device, entrustCode, sampleCode);
+ break;
+ case ".pngInExcel":
+ map = analysisPngInExcel(data, userMap, device, entrustCode, sampleCode);
break;
case ".txt":
map = analysisTxt(data, userMap, device, entrustCode, sampleCode);
- break;
- case ".csv":
- map = analysisList(data, userMap, device, entrustCode, sampleCode);
break;
case ".mdb":
// 鍒ゆ柇鏄惁鏄媺鍔涙満JCZX-ZB-FF01014
@@ -142,19 +153,17 @@
}
break;
case ".db":
-// map = analysisDb1(data, userMap, device);
- map = analysisDb(data, userMap, device);
- break;
case ".mysql":
+ case ".sqlserver":
// 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;
+// case ".mqtt":
+// map = getActualResistanceValueAsMap(userMap, device);
+// break;
default:
map = null;
break;
@@ -166,68 +175,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());
- 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);
- List<?> 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;
}
@@ -334,7 +281,7 @@
// 浠� 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();
@@ -352,15 +299,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);
@@ -400,23 +347,25 @@
}
}
// 鎷兼帴鏁伴噰閰嶇疆
- 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() + ",";
- }
- int lastIndex = aggregate.lastIndexOf(",");
- String substring = aggregate.substring(0, lastIndex);
- result.add(substring);
-
- }
+ List<Object> result = new ArrayList<>(list);
+// String join = String.join(",", list.stream().map(String::valueOf).collect(Collectors.toList()));
+// result.add(join);
+// 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() + ",";
+// }
+// int lastIndex = aggregate.lastIndexOf(",");
+// String substring = aggregate.substring(0, lastIndex);
+// result.add(substring);
+//
+// }
// 杩涜鍏紡璁$畻
Object resultValue = calculationFormula(result, v.get(0), k, device);
map.put(k, resultValue);
@@ -550,8 +499,8 @@
* @param dataConfig 瀛樺偍鍏紡鐨勫璞�
* @return
*/
- private static Object calculationFormula(List<Object> list, DataConfig dataConfig, String insProductItem, Device device) {
- if (list.size() == 0) {
+ public static Object calculationFormula(List<Object> list, DataConfig dataConfig, String insProductItem, Device device) {
+ if (list.isEmpty()) {
Map<String, Object> hashMap = new HashMap<>();
hashMap.put("equipName", device.getDeviceName());
hashMap.put("equipValue", device.getManagementNumber());
@@ -626,6 +575,45 @@
}
/**
+ * 瑙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);
+ });
+ return map;
+ }
+
+ /**
* @param data 閲囬泦鍒扮殑鏂囦欢瀛楃涓�
* @param dataConfig 鐢ㄦ埛閰嶇疆濂界殑x,y杞村畾浣嶆暟鎹笌鍙傜収鐗�
* @return
@@ -672,6 +660,25 @@
} 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;
+ }
+
+ /**
+ * 澶勭悊涓插彛鏁版嵁
+ *
+ * @param data 閲囬泦鍒扮殑鏂囦欢瀛楃涓�
+ * @param dataConfig 鐢ㄦ埛閰嶇疆濂界殑x,y杞村畾浣嶆暟鎹笌鍙傜収鐗�
+ * @return
+ */
+ public static Map<String, Object> analysisSerialPortList(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 = JSONObject.parseObject(data,new TypeReference<List<Object>>(){}.getType());
// 杩涜鍏紡璁$畻
Object resultValue = calculationFormula(list, v.get(0), k, device);
map.put(k, resultValue);
@@ -761,120 +768,10 @@
}
// 闃叉鍙傜収鐗╀负绌烘姤閿欙紝杩涜鍒ゆ柇濡傛灉涓虹┖璧嬪�肩┖瀛楃
- private static String getRefer(String refer) {
+ public static String getRefer(String refer) {
return ObjectUtils.isNotEmpty(refer) ? refer.replaceAll(" ", "") : "";
}
- /**
- * 濮旀墭缂栧彿涓庢牱鍝佺紪鍙烽兘涓虹┖鎵ц
- *
- * @param data 閲囬泦鍒扮殑鏂囦欢瀛楃涓�
- * @param v 鐢ㄦ埛閰嶇疆濂界殑x,y杞村畾浣嶆暟鎹笌鍙傜収鐗�
- * @param k 妫�楠岄」鍚嶇О
- * @param split 鍒嗗壊绗�
- * @return 鎻愬彇鐨勬暟鎹垪琛�
- */
- public static List<Object> analyzeData1(String data, List<DataConfig> v, String k, String split) {
- List<Object> list = new ArrayList<>();
- // 棰勫鐞嗘暟鎹細绉婚櫎澶氫綑绌烘牸骞朵繚鐣欏叧閿垎闅旂
- String processedData = data.replaceAll("\\s+", " ").trim();
- for (int configIndex = 0; configIndex < v.size(); configIndex++) {
- // 鍙栦袱涓敤鎴烽厤缃殑鍙傜収鐗�
- String referx = getRefer(v.get(configIndex).getReferx());
- String refery = getRefer(v.get(configIndex).getRefery());
- if (ObjectUtils.isEmpty(refery) && ObjectUtils.isEmpty(referx)) {
- System.out.println("鍙傜収鐗╀负绌猴紝璺宠繃褰撳墠閰嶇疆锛宬: " + k);
- continue;
- }
- // 鏈�缁堢粨鏋�
- List<Object> result = new ArrayList<>();
- // 閫氳繃\n灏嗗瓧绗︿覆鍒嗗壊涓鸿
- String[] aColumnY = processedData.replaceAll(" ", "").split("\n");
- Integer end = null;
- // 閲囬泦鏁版嵁锛歒杞�
- for (int i = 0; i < aColumnY.length; i++) {
- String line = aColumnY[i].trim();
- if (line.isEmpty()) continue; // 璺宠繃绌鸿
- // 濡傛灉Y鍙傜収涓嶄负绌轰笌X鍙傜収涓虹┖鍒欐墽琛岋紝鍚屾椂璇ヨ鍖呭惈Y鍙傜収
- if (ObjectUtils.isNotEmpty(refery) && ObjectUtils.isEmpty(referx) && line.contains(refery)) {
- try {
- // 鍙朰鍧愭爣鍊�
- int y = getXOrY(v.get(configIndex).getY(), k, "Y");
- String[] aLineX = line.split(split);
- for (int j = 0; j < aLineX.length; j++) {
- if (aLineX[j].contains(refery)) {
- if (i + y >= aColumnY.length) {
- System.err.println(k + "锛歒杞村畾浣嶈秴鍑烘暟鎹寖鍥达紝褰撳墠鏁版嵁琛屾暟: " + aColumnY.length + "锛屽皾璇曡闂: " + (i + y));
- continue;
- }
- String[] split1 = aColumnY[i + y].split(split);
- if (j >= split1.length) {
- System.err.println(k + "锛歑杞村畾浣嶈秴鍑烘暟鎹寖鍥达紝褰撳墠琛屽厓绱犱釜鏁�: " + split1.length + "锛屽皾璇曡闂綅缃�: " + j);
- continue;
- }
- result.add(split1[j]);
- }
- }
- } catch (Exception e) {
- System.err.println(k + "锛氬湪澶勭悊浠匶鍙傜収閫昏緫鏃跺嚭鐜板紓甯�: " + e.getMessage());
- }
- }
- // 濡傛灉Y鍙傜収涓嶄负绌轰笌X鍙傜収涓嶄负绌哄垯鎵ц,姝ゅY瀹氬尯鍩�
- else if (ObjectUtils.isNotEmpty(refery) && ObjectUtils.isNotEmpty(referx)) {
- try {
- // 鍙杧鐨勫�硷紝闃叉鎶ラ敊
- int x = getXOrY(v.get(configIndex).getX(), k, "X");
- // 鍙朰鍧愭爣鍊�
- int y = getXOrY(v.get(configIndex).getY(), k, "Y");
- // 缂撳瓨Y鐨勭粨鏉熷��
- if (ObjectUtils.isEmpty(end) && line.contains(refery)) {
- end = i + y;
- }
- // 鍒ゆ柇鏄惁鍦ㄥ弬鐓х墿涓鸿捣鐐癸紝Y鍧愭爣鍊间负鏈�缁堣寖鍥�
- if (ObjectUtils.isNotEmpty(end) && i <= end) {
- String[] aLineX = line.split(split);
- for (int j = 0; j < aLineX.length; j++) {
- if (aLineX[j].contains(referx)) {
- if (j + x >= aLineX.length) {
- System.err.println(k + "锛歑杞村畾浣嶈秴鍑烘暟鎹寖鍥达紝褰撳墠琛屽厓绱犱釜鏁�: " + aLineX.length + "锛屽皾璇曡闂綅缃�: " + (j + x));
- continue;
- }
- result.add(aLineX[j + x]);
- break;
- }
- }
- }
- } catch (Exception e) {
- System.err.println(k + "锛氬湪澶勭悊XY鍙傜収閫昏緫鏃跺嚭鐜板紓甯�: " + e.getMessage());
- }
- }
- // 濡傛灉X鍙傜収涓嶄负绌哄悓鏃惰琛屽寘鍚玐鍙傜収锛屽垯鎵ц涓嬮潰鐨勪唬鐮�
- else if (line.contains(referx) && ObjectUtils.isEmpty(refery)) {
- try {
- String[] aLineX = line.split(split);
- // 鍙杧鐨勫�硷紝闃叉鎶ラ敊
- int x = getXOrY(v.get(configIndex).getX(), k, "X");
- for (int j = 0; j < aLineX.length; j++) {
- if (aLineX[j].contains(referx)) {
- if (j + x >= aLineX.length) {
- System.err.println(k + "锛歑杞村畾浣嶈秴鍑烘暟鎹寖鍥达紝褰撳墠琛屽厓绱犱釜鏁�: " + aLineX.length + "锛屽皾璇曡闂綅缃�: " + (j + x));
- continue;
- }
- result.add(aLineX[j + x]);
- }
- }
- } catch (Exception e) {
- System.err.println(k + "锛氬湪澶勭悊浠匵鍙傜収閫昏緫鏃跺嚭鐜板紓甯�: " + e.getMessage());
- }
- }
- }
- // 闃叉璁$畻鍏紡鐨勬椂鍊欏嚭鐜帮細[null] 杩欑鏁版嵁
- if (ObjectUtils.isNotEmpty(result)) {
- list.addAll(result);
- }
- }
- return list;
- }
/**
* 濮旀墭缂栧彿涓庢牱鍝佺紪鍙烽兘涓虹┖鎵ц
*
--
Gitblit v1.9.3