From b91fd38a14e93ae6f1a1fb2babfe7ca8c1c420fe Mon Sep 17 00:00:00 2001
From: yaowanxin <3588231647@qq.com>
Date: 星期三, 16 七月 2025 17:33:14 +0800
Subject: [PATCH] 修改方法,SQL
---
cnas-device/src/main/resources/mapper/DeviceMaintenanceMapper.xml | 4
cnas-device/src/main/java/com/ruoyi/device/utils/DataAcquisition.java | 159 +++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 151 insertions(+), 12 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 02ec469..98c04ec 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
@@ -117,7 +117,7 @@
map = analysisList(data, userMap, device, entrustCode, sampleCode);
break;
case ".xls":
- map = analysisString(data, userMap, device, entrustCode, sampleCode);
+ map = analysisTxt(data, userMap, device, entrustCode, sampleCode);
break;
case ".txt":
map = analysisTxt(data, userMap, device, entrustCode, sampleCode);
@@ -479,6 +479,7 @@
String firstNumber = lastLine.split("\t")[0];
list.add(firstNumber);
} else {
+
list = analyzeData(data, v, k, ",");
}
// 濮旀墭缂栧彿涓庢牱鍝佺紪鍙峰瓨鍦�
@@ -545,7 +546,24 @@
});
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銆乊瀹氳寖鍥达紝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(" ", "");
@@ -631,7 +649,117 @@
private 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;
+ }
/**
* 濮旀墭缂栧彿涓庢牱鍝佺紪鍙烽兘涓虹┖鎵ц
*
@@ -643,6 +771,10 @@
*/
public static List<Object> analyzeData(String data, List<DataConfig> v, String k, String split) {
List<Object> list = new ArrayList<>();
+
+ // 棰勫鐞嗘暟鎹細绉婚櫎澶氫綑绌烘牸骞朵繚鐣欏叧閿垎闅旂
+// String processedData = data.replaceAll("\\s+", " ").trim();
+
for (int config = 0; config < v.size(); config++) {
// 鍙栦袱涓敤鎴烽厤缃殑鍙傜収鐗�
String referx = getRefer(v.get(config).getReferx());
@@ -651,17 +783,20 @@
continue;
}
// 鏈�缁堢粨鏋�
- List<Object> result = new ArrayList<>();
+// List<Object> result = new ArrayList<>();
// 閫氳繃\n灏嗗瓧绗︿覆鍒嗗壊涓鸿
String[] aColumnY = data.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) && aColumnY[i].contains(refery)) {
+ if (ObjectUtils.isNotEmpty(refery) && ObjectUtils .isEmpty(referx) && aColumnY[i].contains(refery)) {
// 鍙朰鍧愭爣鍊�
int y = getXOrY(v.get(config).getY(), k, "Y");
String[] aLineX = aColumnY[i].split(split);
+// String[] aLineX = line.split(split);
for (int j = 0; j < aLineX.length; j++) {
if (aLineX[j].contains(refery)) {
String[] split1 = new String[0];
@@ -671,7 +806,9 @@
throw new ErrorException(k + "锛歒杞村畾浣嶈秴鍑猴紒");
}
try {
- result.add(split1[j]);
+// System.out.println("----------");
+ list.add(split1[j]);
+
} catch (Exception e) {
throw new ErrorException(k + "锛歑杞村畾浣嶈秴鍑猴紒");
}
@@ -693,7 +830,8 @@
for (int j = 0; j < aLineX.length; j++) {
if (aLineX[j].contains(referx)) {
try {
- result.add(aLineX[j + x]);
+// System.out.println("77777777777777");
+ list.add(aLineX[j + x]);
} catch (Exception e) {
throw new ErrorException(k + "锛歑杞村畾浣嶈秴鍑猴紒");
}
@@ -709,7 +847,8 @@
for (int j = 0; j < aLineX.length; j++) {
if (aLineX[j].contains(referx)) {
try {
- result.add(aLineX[j + x]);
+// System.out.println("4444444444444444");
+ list.add(aLineX[j + x]);
} catch (Exception e) {
throw new ErrorException(k + "锛歑杞村畾浣嶈秴鍑猴紒");
}
@@ -718,10 +857,10 @@
}
}
// 闃叉璁$畻鍏紡鐨勬椂鍊欏嚭鐜帮細[null] 杩欑鏁版嵁
- if (ObjectUtils.isNotEmpty(result)) {
+// if (ObjectUtils.isNotEmpty(result)) {
// String formatProcessing = getFormatProcessing(result);
- list.addAll(result);
- }
+// list.addAll(result);
+// }
}
return list;
}
diff --git a/cnas-device/src/main/resources/mapper/DeviceMaintenanceMapper.xml b/cnas-device/src/main/resources/mapper/DeviceMaintenanceMapper.xml
index b6ab4cc..326ff4f 100644
--- a/cnas-device/src/main/resources/mapper/DeviceMaintenanceMapper.xml
+++ b/cnas-device/src/main/resources/mapper/DeviceMaintenanceMapper.xml
@@ -8,8 +8,8 @@
<select id="selectDeviceMaintenancePage" resultType="com.ruoyi.device.dto.DeviceMaintenanceDto">
select * from (
select db.*,
- d.device_name,
- d.management_number
+ d.device_name as d_device_name,
+ d.management_number as d_management_number
from device_maintenance db
left join device d on db.device_id = d.id)a
<if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
--
Gitblit v1.9.3