|
@@ -36,6 +36,8 @@ import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.OutputStream;
|
|
|
import java.util.*;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* 公用工程Controller
|
|
@@ -182,13 +184,22 @@ public class TPssrPublicController extends BaseController {
|
|
|
String checkRequire = tPssrPublic.getCheckRequire();
|
|
|
String checkCondition = tPssrPublic.getCheckCondition();
|
|
|
String valveStatus = tPssrPublic.getValveStatus();
|
|
|
- if (checkRequire.contains("达")) {
|
|
|
- String rKpa = checkRequire.substring(checkRequire.indexOf("压力达"), checkRequire.indexOf("kpa"));
|
|
|
- String rTemp = checkRequire.substring(checkRequire.indexOf("温度达"), checkRequire.indexOf("℃"));
|
|
|
- String rMpa = checkRequire.substring(checkRequire.indexOf("压力达"), checkRequire.indexOf("Mpa"));
|
|
|
- String cKpa = checkCondition.substring(checkCondition.indexOf("压力达"), checkCondition.indexOf("kpa"));
|
|
|
- String cTemp = checkCondition.substring(checkCondition.indexOf("温度达"), checkCondition.indexOf("℃"));
|
|
|
- String cMpa = checkCondition.substring(checkCondition.indexOf("压力达"), checkCondition.indexOf("Mpa"));
|
|
|
+
|
|
|
+ // 提取值
|
|
|
+ Double[] conditionValues = extractValues(checkCondition.replace(" ",""));
|
|
|
+ Double[] requireValues = extractValues(checkRequire.replace(" ",""));
|
|
|
+
|
|
|
+ // 比对逻辑
|
|
|
+ if (conditionValues != null && requireValues != null) {
|
|
|
+ boolean isSatisfied = compareValues(conditionValues, requireValues);
|
|
|
+
|
|
|
+ // 输出结果
|
|
|
+ if (isSatisfied) {
|
|
|
+ tPssrPublic.setCheckResult("✔");
|
|
|
+ } else {
|
|
|
+ tPssrPublic.setCheckResult("✖");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -197,6 +208,59 @@ public class TPssrPublicController extends BaseController {
|
|
|
return toAjax(tPssrPublicService.updateTPssrPublic(tPssrPublic));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 从字符串中提取压力和温度的值
|
|
|
+ *
|
|
|
+ * @param input 输入的字符串
|
|
|
+ * @return 返回 [压力值, 温度值] 数组;如果格式不正确,返回 null
|
|
|
+ */
|
|
|
+ public static Double[] extractValues(String input) {
|
|
|
+ // 正则表达式动态匹配“压力达”或“压差达”,并提取纯数值和单位
|
|
|
+ String regex = "(压力达|压差达)\\s*(\\d+(\\.\\d+)?)\\s*(kpa|Mpa).*?" +
|
|
|
+ "温度达\\s*(\\d+(\\.\\d+)?)\\s*℃";
|
|
|
+ Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
|
|
|
+ Matcher matcher = pattern.matcher(input);
|
|
|
+
|
|
|
+ if (matcher.find()) {
|
|
|
+ // 提取压力/压差值
|
|
|
+ double value = Double.parseDouble(matcher.group(2));
|
|
|
+
|
|
|
+ // 提取温度值(可能为空)
|
|
|
+ Double temperature = null;
|
|
|
+ if (matcher.group(5) != null) {
|
|
|
+ temperature = Double.parseDouble(matcher.group(5));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果温度值为空,只返回压力/压差值
|
|
|
+ return temperature != null ? new Double[]{value, temperature} : new Double[]{value};
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 比对方法:检查 require 中的值是否小于 condition 中的值
|
|
|
+ *
|
|
|
+ * @param condition 条件值数组 [压力值, 温度值]
|
|
|
+ * @param require 要求值数组 [压力值, 温度值]
|
|
|
+ * @return 如果 require 中的值均小于 condition 中的值,则返回 true,否则返回 false
|
|
|
+ */
|
|
|
+ public static boolean compareValues(Double[] condition, Double[] require) {
|
|
|
+ // 比较压力值或压差值
|
|
|
+ if (require[0] > condition[0]) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 比较温度值(如果 condition 和 require 都包含温度值)
|
|
|
+ if (condition.length > 1 && require.length > 1 && condition[1] != null && require[1] != null) {
|
|
|
+ if (require[1] > condition[1]) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true; // 如果所有值都满足条件,返回 true
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 修改公用工程
|
|
|
*/
|