From be3659167ebc85d3ad4bf0311ed2051c0da0281d Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期二, 23 七月 2024 10:31:36 +0800
Subject: [PATCH] 班次权限
---
cnas-server/src/main/java/com/yuanchu/mom/utils/DataAcquisition.java | 322 ++++++++++++++++++++++++++++-------------------------
1 files changed, 171 insertions(+), 151 deletions(-)
diff --git a/cnas-server/src/main/java/com/yuanchu/mom/utils/DataAcquisition.java b/cnas-server/src/main/java/com/yuanchu/mom/utils/DataAcquisition.java
index 99e3fd7..d89a644 100644
--- a/cnas-server/src/main/java/com/yuanchu/mom/utils/DataAcquisition.java
+++ b/cnas-server/src/main/java/com/yuanchu/mom/utils/DataAcquisition.java
@@ -9,7 +9,6 @@
import com.yuanchu.mom.exception.ErrorException;
import com.yuanchu.mom.pojo.DataConfig;
import com.yuanchu.mom.pojo.Device;
-import com.yuanchu.mom.vo.Result;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
@@ -27,17 +26,16 @@
private static final String splitIdentifier = "@-@"; // 鑷畾涔夊敮涓�鏍囪瘑鍒嗗壊绗�
+ public static final String frequency = "frequency";
/**
* 鏁伴噰鍏ュ彛
+ *
* @param request
* @param dataConfig
* @param device
* @return
*/
- public static Result<?> dataAcquisitionEntrance(HttpServletRequest request, List<DataConfig> dataConfig, Device device, String entrustCode, String sampleCode) {
- String ipAddress = request.getRemoteAddr();
- // 闃叉鍥炵幆鍦板潃鍙樹负IPv6
- String ip = ipAddress.equals("0:0:0:0:0:0:0:1") ? "127.0.0.1" : ipAddress;
+ public static Map<String, String> dataAcquisitionEntrance(HttpServletRequest request, List<DataConfig> dataConfig, Device device, String entrustCode, String sampleCode, String ip) {
String http = HTTP + ip + GETFILE + "?filePath=" + device.getCollectUrl() + "&fileExtension=" + device.getFileType();
String result = null;
try {
@@ -45,7 +43,7 @@
} catch (IORuntimeException e) {
throw new ErrorException("鎵�鍦ㄧ數鑴戞湭瀹夎鎴栨湭鍚姩锛歀IMS鏂囦欢閲囬泦鍣紒");
}
- JSONObject jsonObject = JSON.parseObject(result);
+ JSONObject jsonObject = JSON.parseObject(result);
if (Objects.equals(jsonObject.get("code"), 1)) {
if (ObjectUtils.isEmpty(jsonObject.get("msg"))) {
throw new ErrorException("鏈煡璇㈠埌鏁版嵁锛屽彲鑳芥枃浠惰矾寰勯厤缃敊璇紒");
@@ -88,7 +86,7 @@
if (ObjectUtils.isNotEmpty(device.getStorageUrl())) {
String s = HTTP + ip + MOVEFILE + "?startFilePath=" + device.getCollectUrl() + "&endFilePath=" + device.getStorageUrl();
String storageUrlResult = HttpUtil.get(s);
- JSONObject storageUrlResultJson = JSON.parseObject(storageUrlResult);
+ JSONObject storageUrlResultJson = JSON.parseObject(storageUrlResult);
if (Objects.equals(storageUrlResultJson.get("code"), 1)) {
if (ObjectUtils.isEmpty(storageUrlResultJson.get("msg"))) {
throw new ErrorException("瀛樺偍鍦板潃閿欒锛屽彲鑳芥枃浠惰矾寰勯厤缃敊璇紒");
@@ -97,10 +95,31 @@
}
}
}
- return Result.success(map);
+ return map;
}
}
+ public static String createFrequency(String entrustCode, String sampleCode) {
+ String key = frequency + ":" + entrustCode + ":" + sampleCode;
+ boolean b = RedisUtil.hasKey(key);
+ String frequencyValue;
+ if (b) {
+ long incr = RedisUtil.incr(key, 1);
+ frequencyValue = String.valueOf(incr);
+ } else {
+ RedisUtil.set(key, 1);
+ frequencyValue = "1";
+ }
+ return frequencyValue;
+ }
+
+ /**
+ * 闇�瑕侀�氳繃X,Y杞村畾浣�
+ *
+ * @param data
+ * @param dataConfig
+ * @return
+ */
private static Map<String, String> analysisDb(String data, Map<String, List<DataConfig>> dataConfig) {
JSONObject jsonObject = JSON.parseObject(data);
JSONArray dataList = JSONArray.parseArray(jsonObject.get("data").toString());
@@ -109,12 +128,9 @@
dataConfig.forEach((k, v) -> {
List<Object> list = new ArrayList<>();
for (int config = 0; config < v.size(); config++) {
- String referx = v.get(config).getReferx();
- if(ObjectUtils.isEmpty(v.get(config).getX()) && ObjectUtils.isEmpty(v.get(config).getY())) {
- throw new ErrorException("鏈粰" + k + "杩涜鏁伴噰閰嶇疆x锛寉锛�");
- }
- int x = Integer.parseInt(v.get(config).getX());
- int y = Integer.parseInt(v.get(config).getY());
+ String referx = getRefer(v.get(config).getReferx());
+ int x = getXOrY(v.get(config).getX(), k, "X");
+ int y = getXOrY(v.get(config).getY(), k, "Y");
String key = "";
for (int i = 0; i < columnList.size(); i++) {
if (columnList.get(i).equals(referx)) {
@@ -124,16 +140,32 @@
JSONObject jsonObject1 = JSON.parseObject(dataList.get(y).toString());
Object o = jsonObject1.get(key);
if (ObjectUtils.isNotEmpty(o)) {
- list.add(o);
+ // 灏忔暟鐐硅繘涓変綅
+ double v1 = 0;
+ try {
+ v1 = Double.parseDouble(o.toString());
+ double v2 = v1 / 1000;
+ list.add(v2);
+ } catch (NumberFormatException e) {
+ list.add(o);
+ }
+
}
}
// 杩涜鍏紡璁$畻
- String resultValue = calculationFormula(list, v.get(0));
+ String resultValue = calculationFormula(list, v.get(0), k);
map.put(k, resultValue);
});
return map;
}
+ /**
+ * 闇�瑕侀�氳繃X,Y杞村畾浣�
+ *
+ * @param data
+ * @param dataConfig
+ * @return
+ */
private static Map<String, String> analysisMdb(String data, Map<String, List<DataConfig>> dataConfig, String entrustCode, String sampleCode) {
JSONObject jsonObject = JSON.parseObject(data);
JSONArray dataList = JSONArray.parseArray(jsonObject.get("data").toString());
@@ -142,8 +174,8 @@
dataConfig.forEach((k, v) -> {
List<Object> list = new ArrayList<>();
for (int config = 0; config < v.size(); config++) {
- String referx = v.get(config).getReferx();
- int x = Integer.parseInt(v.get(config).getX());
+ String referx = getRefer(v.get(config).getReferx());
+ int x = getXOrY(v.get(config).getX(), k, "X");
String key = "";
for (int i = 0; i < columnList.size(); i++) {
if (columnList.get(i).equals(referx)) {
@@ -161,16 +193,18 @@
}
}
// 杩涜鍏紡璁$畻
- String resultValue = calculationFormula(list, v.get(0));
+ String resultValue = calculationFormula(list, v.get(0), k);
map.put(k, resultValue);
});
return map;
}
private static Pattern SPATTERN = Pattern.compile("([-+])?\\d+(\\.\\d+)?");
+
/**
- * 瑙f瀽String鏁版嵁
- * @param data 閲囬泦鍒扮殑鏂囦欢瀛楃涓�
+ * 鍙渶X杞�
+ *
+ * @param data 閲囬泦鍒扮殑鏂囦欢瀛楃涓�
* @param dataConfig 鐢ㄦ埛閰嶇疆濂界殑x,y杞村畾浣嶆暟鎹笌鍙傜収鐗�
* @return
*/
@@ -179,15 +213,15 @@
dataConfig.forEach((k, v) -> {
List<Object> list = new ArrayList<>();
for (int config = 0; config < v.size(); config++) {
- String referx = v.get(config).getReferx();
- String xResult = null;
+ String referx = getRefer(v.get(config).getReferx());
+ String result = null;
// 閫氳繃\n灏嗗瓧绗︿覆鍒嗗壊涓鸿
String[] aColumnY = data.split("\n");
List<String> list1 = new ArrayList<>();
// 璇ュ惊鐜緱鍑虹敤鎴烽厤缃殑y杞�
for (int i = 0; i < aColumnY.length; i++) {
String addDataWithSpaces = referx.replaceAll("", " ");
- int x = Integer.parseInt(v.get(config).getX());
+ int x = getXOrY(v.get(config).getX(), k, "X");
if (aColumnY[i].contains(addDataWithSpaces)) {
Matcher matcher = SPATTERN.matcher(aColumnY[i]);
while (matcher.find()) {
@@ -196,15 +230,15 @@
}
}
if (ObjectUtils.isNotEmpty(list1)) {
- xResult = list1.get(x);
+ result = list1.get(x);
}
}
- if (ObjectUtils.isNotEmpty(xResult)) {
- list.add(xResult);
+ if (ObjectUtils.isNotEmpty(result)) {
+ list.add(result);
}
}
// 杩涜鍏紡璁$畻
- String resultValue = calculationFormula(list, v.get(0));
+ String resultValue = calculationFormula(list, v.get(0), k);
map.put(k, resultValue);
});
return map;
@@ -212,185 +246,171 @@
/**
* 浠庢枃浠朵腑鎻愬彇鍑烘潵鐨勬枃瀛楋紝濡傛灉鏈夊叕寮忥紝杩涜鍏紡璁$畻锛屽惁鍒欏彇鍒楄〃绗竴涓��
- * @param list 鎻愬彇鍑虹殑鏁板瓧
+ *
+ * @param list 鎻愬彇鍑虹殑鏁板瓧
* @param dataConfig 瀛樺偍鍏紡鐨勫璞�
* @return
*/
- private static String calculationFormula(List<Object> list, DataConfig dataConfig) {
+ private static String calculationFormula(List<Object> list, DataConfig dataConfig, String insProductItem) {
+ if (list.size() == 0) {
+ return null;
+ }
// 濡傛灉涓嶄负绌猴紝杩涜鍏紡璁$畻
if (ObjectUtils.isNotEmpty(dataConfig.getFormula())) {
return null;
- // 鍚﹀垯锛氭病鏈夊叕寮忎唬琛ㄤ笉闇�瑕佽绠楋紝鐩存帴鎻愬彇List閲岄潰鐨勬暟鎹�
+ // 鍚﹀垯锛氭病鏈夊叕寮忎唬琛ㄤ笉闇�瑕佽绠楋紝鐩存帴鎻愬彇List閲岄潰鐨勬暟鎹�
} else {
// 杩欓噷鍙細鍙栧垪琛ㄧ涓�涓暟鎹�
- if (list.size() > 0) {
+ if (list.size() > 1) {
+ throw new ErrorException("鏈粰锛�" + insProductItem + " 閰嶇疆鍏紡锛屽彲鏄嵈閲囬泦鍒颁簡" + list.size() + "涓�硷紒鍒嗗埆涓猴細" + list);
+ } else {
return list.get(0).toString();
}
- return null;
}
}
/**
* 瑙f瀽String鏁版嵁
- * @param data 閲囬泦鍒扮殑鏂囦欢瀛楃涓�
+ *
+ * @param data 閲囬泦鍒扮殑鏂囦欢瀛楃涓�
* @param dataConfig 鐢ㄦ埛閰嶇疆濂界殑x,y杞村畾浣嶆暟鎹笌鍙傜収鐗�
* @return
*/
private static Map<String, String> analysisTxt(String data, Map<String, List<DataConfig>> dataConfig) {
Map<String, String> map = new HashMap<>();
dataConfig.forEach((k, v) -> {
- List<Object> list = new ArrayList<>();
- for (int config = 0; config < v.size(); config++) {
- String referx = v.get(config).getReferx();
- String refery = v.get(config).getRefery();
- String xResult = null;
- String yResult = null;
- // 閫氳繃\n灏嗗瓧绗︿覆鍒嗗壊涓鸿
- String[] aColumnY = data.split("\n");
- // 璇ュ惊鐜緱鍑虹敤鎴烽厤缃殑y杞�
- for (int i = 0; i < aColumnY.length; i++) {
- // 寰楀嚭鐢ㄦ埛閰嶇疆鐨剎杞�
- String[] aLineX = aColumnY[i].split(",");
- for (int j = 0; j < aLineX.length; j++) {
- if (ObjectUtils.isNotEmpty(referx) && aLineX[j].contains(referx)) {
- int x = Integer.parseInt(v.get(config).getX());
- try {
- xResult = aLineX[j + x];
- } catch (Exception e) {
- throw new ErrorException("鏁伴噰閰嶇疆X杞磋秴鍑猴紒");
- }
- }
- if (ObjectUtils.isNotEmpty(refery) && aLineX[j].contains(refery)) {
- int y = Integer.parseInt(v.get(config).getY());
- try {
- String[] split = aColumnY[i + y].split(",");
- yResult = split[split.length - 1];
- } catch (Exception e) {
- throw new ErrorException("鏁伴噰閰嶇疆Y杞磋秴鍑猴紒");
- }
- }
- }
- }
- if (ObjectUtils.isEmpty(xResult) && ObjectUtils.isEmpty(yResult)) {
- throw new ErrorException("鍙傜収鐗╀负锛�" + referx + "涓�" + refery + "鏈彇鍒板�硷紒璇锋鏌ユ暟閲囬厤缃紒");
- }
- list.add(yResult);
- list.add(xResult);
- }
+ List<Object> list = analyzeData(data, v, k, ",");
// 杩涜鍏紡璁$畻
- String resultValue = calculationFormula(list, v.get(0));
+ String resultValue = calculationFormula(list, v.get(0), k);
map.put(k, resultValue);
});
return map;
}
/**
- * 瑙f瀽String鏁版嵁
- * @param data 閲囬泦鍒扮殑鏂囦欢瀛楃涓�
+ * @param data 閲囬泦鍒扮殑鏂囦欢瀛楃涓�
* @param dataConfig 鐢ㄦ埛閰嶇疆濂界殑x,y杞村畾浣嶆暟鎹笌鍙傜収鐗�
* @return
*/
private static Map<String, String> analysisString(String data, Map<String, List<DataConfig>> dataConfig) {
- String processingDataAfterSpaces = data.replaceAll(" +", splitIdentifier).replaceAll("\r", "");
+ String processingDataAfterSpaces = data
+ .replaceAll(" +", splitIdentifier)
+ .replaceAll("\r", "")
+ .replaceAll(" ", "");
Map<String, String> map = new HashMap<>();
dataConfig.forEach((k, v) -> {
- List<Object> list = new ArrayList<>();
- for (int config = 0; config < v.size(); config++) {
- String referx = v.get(config).getReferx();
- String xResult = null;
- // 閫氳繃\n灏嗗瓧绗︿覆鍒嗗壊涓鸿
- String[] aColumnY = processingDataAfterSpaces.split("\n");
- // 璇ュ惊鐜緱鍑虹敤鎴烽厤缃殑y杞�
- for (int i = 0; i < aColumnY.length; i++) {
- // 寰楀嚭鐢ㄦ埛閰嶇疆鐨剎杞�
- String[] aLineX = aColumnY[i].split(splitIdentifier);
- for (int j = 0; j < aLineX.length; j++) {
- if (ObjectUtils.isNotEmpty(referx) && aLineX[j].replaceAll(" ", "").contains(referx.replaceAll(" ", ""))) {
- int x = Integer.parseInt(v.get(config).getX());
- try {
- xResult = aLineX[j + x];
- } catch (Exception e) {
- throw new ErrorException("鏁伴噰閰嶇疆X杞磋秴鍑猴紒");
- }
- }
- }
- }
- if (ObjectUtils.isEmpty(xResult)) {
- throw new ErrorException("鍙傜収鐗╀负锛�" + referx + "鏈彇鍒板�硷紒璇锋鏌ユ暟閲囬厤缃紒");
- }
- // 缁撴灉鍖呭惈鐗规畩瀛楃锛岄渶瑕佸墧闄ゆ帀
- if(xResult.contains("=")) {
- String[] split = xResult.split("=");
- list.add(split[split.length - 1]);
- } else if (xResult.contains(":")) {
- String[] split = xResult.split(":");
- list.add(split[split.length - 1].replaceAll("%", ""));
- } else {
- list.add(xResult);
- }
- }
+ List<Object> list = analyzeData(processingDataAfterSpaces, v, k, splitIdentifier);
// 杩涜鍏紡璁$畻
- String resultValue = calculationFormula(list, v.get(0));
+ String resultValue = calculationFormula(list, v.get(0), k);
map.put(k, resultValue);
});
return map;
}
/**
- * 瑙f瀽String鏁版嵁
- * @param data 閲囬泦鍒扮殑鏂囦欢瀛楃涓�
+ * 鍙朮锛孻涓や釜瀹氫綅
+ *
+ * @param data 閲囬泦鍒扮殑鏂囦欢瀛楃涓�
* @param dataConfig 鐢ㄦ埛閰嶇疆濂界殑x,y杞村畾浣嶆暟鎹笌鍙傜収鐗�
* @return
*/
public static Map<String, String> analysisList(String data, Map<String, List<DataConfig>> dataConfig) {
Map<String, String> map = new HashMap<>();
dataConfig.forEach((k, v) -> {
- List<Object> list = new ArrayList<>();
- for (int config = 0; config < v.size(); config++) {
- String referx = v.get(config).getReferx();
- String refery = v.get(config).getRefery();
- String xResult = null;
- String yResult = null;
- // 閫氳繃\n灏嗗瓧绗︿覆鍒嗗壊涓鸿
- String[] aColumnY = data.split("\n");
- // 璇ュ惊鐜緱鍑虹敤鎴烽厤缃殑y杞�
- for (int i = 0; i < aColumnY.length; i++) {
- // 寰楀嚭鐢ㄦ埛閰嶇疆鐨剎杞�
- String[] aLineX = aColumnY[i].split(splitIdentifier);
- for (int j = 0; j < aLineX.length; j++) {
- if (ObjectUtils.isNotEmpty(referx) && referx.equals(aLineX[j])) {
- int x = Integer.parseInt(v.get(config).getX());
- try {
- xResult = aLineX[j + x];
- } catch (Exception e) {
- throw new ErrorException("鏁伴噰閰嶇疆X杞磋秴鍑猴紒");
+ // 鐢ㄦ埛鍙兘缁欎竴涓瓙椤圭洰閰嶇疆浜嗗涓厤缃紝鍗充竴涓」鐩彇澶氫釜鍊硷紝鎵�浠ラ渶瑕佸惊鐜�
+ List<Object> list = analyzeData(data, v, k, splitIdentifier);
+ // 杩涜鍏紡璁$畻
+ String resultValue = calculationFormula(list, v.get(0), k);
+ map.put(k, resultValue);
+ });
+ return map;
+ }
+
+ // 鐢变簬鍦ㄦ柟娉曚腑浼氬ぇ閲忕殑鍒ゆ柇锛屾墍浠ュ仛涓�涓柟娉�
+ private static int getXOrY(String value, String k, String tips) {
+ try {
+ return Integer.parseInt(value);
+ } catch (NumberFormatException e) {
+ throw new ErrorException(k + "锛氭湭閰嶇疆" + tips + "鍧愭爣杞寸殑鍊硷紒");
+ }
+ }
+
+ // 闃叉鍙傜収鐗╀负绌烘姤閿欙紝杩涜鍒ゆ柇濡傛灉涓虹┖璧嬪�肩┖瀛楃
+ private static String getRefer(String refer) {
+ return ObjectUtils.isNotEmpty(refer) ? refer.replaceAll(" ", "") : "";
+ }
+
+ public static List<Object> analyzeData(String data, List<DataConfig> v, String k, String split) {
+ List<Object> list = new ArrayList<>();
+ for (int config = 0; config < v.size(); config++) {
+ // 鍙栦袱涓敤鎴烽厤缃殑鍙傜収鐗�
+ String referx = getRefer(v.get(config).getReferx());
+ String refery = getRefer(v.get(config).getRefery());
+ // 鏈�缁堢粨鏋�
+ String result = null;
+ // 閫氳繃\n灏嗗瓧绗︿覆鍒嗗壊涓鸿
+ String[] aColumnY = data.replaceAll(" ", "").split("\n");
+ Integer end = null;
+ // 閲囬泦鏁版嵁锛歒杞�
+ for (int i = 0; i < aColumnY.length; i++) {
+ // 鍙杧鐨勫�硷紝闃叉鎶ラ敊
+ int x = getXOrY(v.get(config).getX(), k, "X");
+ // 濡傛灉Y涓嶺鐢ㄦ埛閮介厤缃簡鍒欐墽琛�
+ if (ObjectUtils.isNotEmpty(refery)) {
+ // 鍙朰鍧愭爣鍊�
+ int y = getXOrY(v.get(config).getY(), k, "Y");
+ // 缂撳瓨Y鐨勭粨鏉熷��
+ if (ObjectUtils.isEmpty(end) && aColumnY[i].contains(refery)) {
+ end = i + y;
+ }
+ // 鍒ゆ柇鏄惁鍦ㄥ弬鐓х墿涓鸿捣鍒帮紝Y鍧愭爣鍊间负鏈�缁堣寖鍥�
+ if (ObjectUtils.isNotEmpty(end) && i <= end) {
+ String[] aLineX = aColumnY[i].split(split);
+ for (int j = 0; j < aLineX.length; j++) {
+ if (aLineX[j].contains(referx)) {
+ try {
+ result = aLineX[j + x];
+ } catch (Exception e) {
+ throw new ErrorException(k + "锛歑杞村畾浣嶈秴鍑猴紒");
+ }
+ break;
}
}
- if (ObjectUtils.isNotEmpty(refery) && refery.equals(aLineX[j])) {
- int y = Integer.parseInt(v.get(config).getY());
- String aColumnData = aColumnY[i + y]; // 鑾峰彇鍒扮Y琛岀殑鏁版嵁
+ }
+ // 濡傛灉鍙厤缃簡X锛屽垯鎵ц涓嬮潰鐨勪唬鐮�
+ } else if (aColumnY[i].contains(referx) && ObjectUtils.isEmpty(refery)) {
+ String[] aLineX = aColumnY[i].split(split);
+ for (int j = 0; j < aLineX.length; j++) {
+ if (aLineX[j].contains(referx)) {
try {
- yResult = aColumnData.split(splitIdentifier)[j];
+ result = aLineX[j + x];
} catch (Exception e) {
- throw new ErrorException("鏁伴噰閰嶇疆Y杞磋秴鍑猴紒");
+ throw new ErrorException(k + "锛歑杞村畾浣嶈秴鍑猴紒");
}
}
}
}
- if (ObjectUtils.isEmpty(xResult) || ObjectUtils.isEmpty(yResult)) {
- throw new ErrorException("X杞存垨Y杞存湭鍙栧埌鍊硷紒璇锋鏌ユ暟閲囬厤缃紒");
- }
- if(xResult.equals(yResult)) {
- list.add(xResult);
- } else {
- throw new ErrorException("X杞翠笌Y杞村彇寰楃殑鏁版嵁涓嶇浉鍚岋紒璇锋鏌ユ暟閲囬厤缃紒");
- }
}
- // 杩涜鍏紡璁$畻
- String resultValue = calculationFormula(list, v.get(0));
- map.put(k, resultValue);
- });
- return map;
+ // 闃叉璁$畻鍏紡鐨勬椂鍊欏嚭鐜帮細[null] 杩欑鏁版嵁
+ if (ObjectUtils.isNotEmpty(result)) {
+ String formatProcessing = getFormatProcessing(result);
+ list.add(formatProcessing);
+ }
+ }
+ return list;
+ }
+
+ public static String getFormatProcessing(String value) {
+ value = value.replaceAll("%", "");
+ if(value.contains("=")){
+ String[] split = value.split("=");
+ return split[split.length - 1];
+ } else if(value.contains(":")) {
+ String[] split = value.split(":");
+ return split[split.length - 1];
+ } else {
+ return value;
+ }
}
}
--
Gitblit v1.9.3