|
@@ -1,530 +1,543 @@
|
|
|
package org.bfkj.application;
|
|
|
|
|
|
-
|
|
|
import org.bfkj.config.AppConfig;
|
|
|
import org.bfkj.config.ObjectMap;
|
|
|
-import org.bfkj.utils.*;
|
|
|
+import org.bfkj.utils.LogUtils;
|
|
|
+import org.bfkj.utils.MapTools;
|
|
|
+import org.bfkj.utils.MyDbHelper;
|
|
|
+import org.bfkj.utils.ScriptEnginePro;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
public class DataProcess {
|
|
|
- private String serviceId;
|
|
|
- private long lastActive;
|
|
|
- private String errorMessage = null;
|
|
|
- private MyDbHelper baseDbHelper = null;
|
|
|
-
|
|
|
- private Map<String, Integer> serviceErrorCount = new HashMap<>();
|
|
|
-
|
|
|
- private List<Map<String, Object>> calcList;
|
|
|
- private Map<String, ScriptEnginePro> ScriptEngineProMaps = new HashMap<>();
|
|
|
- private Map<String, MyDbHelper> calcDbHelperMaps = new HashMap<>();
|
|
|
-
|
|
|
- private List<String> serviceAuthMap = new ArrayList<>();
|
|
|
-
|
|
|
- private Set<Integer> enableLogCalculationLibrary = new HashSet<>();
|
|
|
-
|
|
|
- public DataProcess(String service_Id) {
|
|
|
- lastActive = System.currentTimeMillis();
|
|
|
- serviceId = service_Id;
|
|
|
- try {
|
|
|
- baseDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.REMOTE_DB_CONNECT);
|
|
|
- if (Objects.nonNull(baseDbHelper.getErrorMessage())) {
|
|
|
- errorMessage = "获取底座myDbHelper对象异常: ".concat(baseDbHelper.getErrorMessage());
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, Object> calculationMap = baseDbHelper.queryByParamsReturnList("SELECT CL.*,DI.* FROM calculation_library CL left JOIN datasourceinfo DI ON DI.dataSourceID = CL.datasource_id WHERE CL.service_id =? and CL.library_type is not null order by library_sort,library_id", service_Id);
|
|
|
-
|
|
|
- calcList = Objects.isNull(calculationMap.get("returnData")) ? null : (List<Map<String, Object>>) calculationMap.get("returnData");
|
|
|
- if (!calculationMap.get("code").equals("0") || calcList == null || calcList.isEmpty()) {
|
|
|
- errorMessage = "查询".concat(serviceId).concat("的算法失败:").concat(calculationMap.containsKey("message") ? calculationMap.get("message").toString() : "对应算法不存在");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, Object> serviceAuth = baseDbHelper.queryByParamsReturnList("SELECT app_id FROM appService WHERE serviceID = ?", service_Id);
|
|
|
- if (!serviceAuth.get("code").equals("0")) {
|
|
|
- errorMessage = "获取".concat(service_Id).concat("的应用安全等级出错:").concat(serviceAuth.get("message").toString());
|
|
|
- return;
|
|
|
- }
|
|
|
- Object serviceAuthList = serviceAuth.get("returnData");
|
|
|
- if (!Objects.isNull(serviceAuthList)) {
|
|
|
- serviceAuthMap = ((List<Map<String, Object>>) serviceAuthList).stream().map(map -> map.get("app_id").toString()).toList();
|
|
|
- }
|
|
|
- List<Map<String, Object>> returnData = (List<Map<String, Object>>) calculationMap.getOrDefault("returnData", Collections.EMPTY_LIST);
|
|
|
+ private String serviceId;
|
|
|
+ private long lastActive;
|
|
|
+ private String errorMessage = null;
|
|
|
+ private MyDbHelper baseDbHelper = null;
|
|
|
+
|
|
|
+ private Map<String, Integer> serviceErrorCount = new HashMap<>();
|
|
|
+
|
|
|
+ private List<Map<String, Object>> calcList;
|
|
|
+ private Map<String, ScriptEnginePro> ScriptEngineProMaps = new HashMap<>();
|
|
|
+ private Map<String, MyDbHelper> calcDbHelperMaps = new HashMap<>();
|
|
|
+
|
|
|
+ private List<String> serviceAuthMap = new ArrayList<>();
|
|
|
+
|
|
|
+ private Set<Integer> enableLogCalculationLibrary = new HashSet<>();
|
|
|
+
|
|
|
+ public DataProcess(String service_Id) {
|
|
|
+ lastActive = System.currentTimeMillis();
|
|
|
+ serviceId = service_Id;
|
|
|
+ try {
|
|
|
+ baseDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.REMOTE_DB_CONNECT);
|
|
|
+ if ( Objects.nonNull(baseDbHelper.getErrorMessage()) ) {
|
|
|
+ errorMessage = "获取底座myDbHelper对象异常: ".concat(baseDbHelper.getErrorMessage());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> calculationMap = baseDbHelper.queryByParamsReturnList("SELECT CL.*,DI.* FROM calculation_library CL left JOIN datasourceinfo DI ON DI.dataSourceID = CL.datasource_id WHERE CL.service_id =? and CL.library_type is not null order by library_sort,library_id", service_Id);
|
|
|
+
|
|
|
+ calcList = Objects.isNull(calculationMap.get("returnData")) ? null : (List<Map<String, Object>>) calculationMap.get("returnData");
|
|
|
+ if ( ! calculationMap.get("code").equals("0") || calcList == null || calcList.isEmpty() ) {
|
|
|
+ errorMessage = "查询".concat(serviceId).concat("的算法失败:").concat(calculationMap.containsKey("message") ? calculationMap.get("message").toString() : "对应算法不存在");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> serviceAuth = baseDbHelper.queryByParamsReturnList("SELECT app_id FROM appService WHERE serviceID = ?", service_Id);
|
|
|
+ if ( ! serviceAuth.get("code").equals("0") ) {
|
|
|
+ errorMessage = "获取".concat(service_Id).concat("的应用安全等级出错:").concat(serviceAuth.get("message").toString());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Object serviceAuthList = serviceAuth.get("returnData");
|
|
|
+ if ( ! Objects.isNull(serviceAuthList) ) {
|
|
|
+ serviceAuthMap = ((List<Map<String, Object>>) serviceAuthList).stream().map(map -> map.get("app_id").toString()).toList();
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> returnData = (List<Map<String, Object>>) calculationMap.getOrDefault("returnData", Collections.EMPTY_LIST);
|
|
|
|
|
|
- List<Integer> enabled = returnData.stream()
|
|
|
- .filter(it -> Objects.nonNull(it.get("processType")) && "1".equals(it.get("processType").toString()))
|
|
|
- .map(it -> ((Integer) it.get("library_id"))).toList();
|
|
|
- enableLogCalculationLibrary.addAll(enabled);
|
|
|
- } catch (Exception e) {
|
|
|
- errorMessage = "数据处理对象初始化异常: ".concat(serviceId).concat(";异常信息:").concat(LogUtils.getException(e));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public void close() {
|
|
|
- try {
|
|
|
- for (ScriptEnginePro scriptEnginePro : ScriptEngineProMaps.values()) {
|
|
|
- scriptEnginePro.close();
|
|
|
- }
|
|
|
- ScriptEngineProMaps.clear();
|
|
|
- for (MyDbHelper calcMyDbHelper : calcDbHelperMaps.values()) {
|
|
|
- calcMyDbHelper.close();
|
|
|
- }
|
|
|
- calcDbHelperMaps.clear();
|
|
|
+ List<Integer> enabled = returnData.stream()
|
|
|
+ .filter(it -> Objects.nonNull(it.get("processType")) && "1".equals(it.get("processType").toString()))
|
|
|
+ .map(it -> ((Integer) it.get("library_id"))).toList();
|
|
|
+ enableLogCalculationLibrary.addAll(enabled);
|
|
|
+ } catch ( Exception e ) {
|
|
|
+ errorMessage = "数据处理对象初始化异常: ".concat(serviceId).concat(";异常信息:").concat(LogUtils.getException(e));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void close() {
|
|
|
+ try {
|
|
|
+ for ( ScriptEnginePro scriptEnginePro : ScriptEngineProMaps.values() ) {
|
|
|
+ scriptEnginePro.close();
|
|
|
+ }
|
|
|
+ ScriptEngineProMaps.clear();
|
|
|
+ for ( MyDbHelper calcMyDbHelper : calcDbHelperMaps.values() ) {
|
|
|
+ calcMyDbHelper.close();
|
|
|
+ }
|
|
|
+ calcDbHelperMaps.clear();
|
|
|
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("dataProcess 关闭异常: " + LogUtils.getException(e));
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public Map<String, Object> processSuccess(Object returnData) {
|
|
|
- if (returnData instanceof Map) {
|
|
|
- Map<String, Object> resultData1 = new HashMap<>();
|
|
|
- try {
|
|
|
- resultData1 = (Map<String, Object>) returnData;
|
|
|
- } catch (Exception e) {
|
|
|
- resultData1.put("returnData", returnData);
|
|
|
- }
|
|
|
- resultData1.put("code", "0");
|
|
|
- return resultData1;
|
|
|
- }
|
|
|
- Map<String, Object> returnMap = new HashMap<>();
|
|
|
- returnMap.put("code", "0");
|
|
|
- returnMap.put("returnData", returnData);
|
|
|
- return returnMap;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public Map<String, Object> processFail(String errorMessage, String libraryId) {
|
|
|
- Map<String, Object> returnMap = new HashMap<>();
|
|
|
- returnMap.put("code", "-1");
|
|
|
- returnMap.put("message", errorMessage);
|
|
|
- if (!MapTools.isBlank(libraryId)) {
|
|
|
- returnMap.put("library_id", libraryId);
|
|
|
- }
|
|
|
- return returnMap;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public Map<String, Object> processData(Map<String, Object> inputData, String... user_id) {
|
|
|
- try {
|
|
|
-
|
|
|
- if (!MapTools.isBlank(errorMessage)) {
|
|
|
- LogUtils.log("processData:1", "-1", null, "服务不可用".concat(errorMessage), serviceId, inputData, null, null, null);
|
|
|
- return processFail("服务不可用".concat(errorMessage), null);
|
|
|
- }
|
|
|
- if (System.currentTimeMillis() - lastActive > 2000) {
|
|
|
- lastActive = System.currentTimeMillis();
|
|
|
- baseDbHelper.updateByCondition("update serviceinfo set runState = ? ,lastactive = ? where serviceID =?", null, "1", new Date(lastActive), serviceId);
|
|
|
- }
|
|
|
-
|
|
|
- if (!inputData.containsKey("dataObjectId")) {
|
|
|
- inputData.put("dataObjectId", createLifeCycleCol(Long.valueOf(AppConfig.WORK_ID), Integer.parseInt(serviceId)));
|
|
|
- }
|
|
|
- String dataObjectId = inputData.get("dataObjectId").toString();
|
|
|
-
|
|
|
- inputData = authCheck(inputData, user_id);
|
|
|
- if ("-1".equals(inputData.get("code")) || (Objects.nonNull(inputData.get("message")) && inputData.get("message").toString().equals("服务未授任何数据权限"))) {
|
|
|
- return inputData;
|
|
|
- }
|
|
|
- List<Map<String, Object>> calcData = new ArrayList<>();
|
|
|
- calcData.add(inputData);
|
|
|
- Map<String, Object> execResult = execCalultion(calcData, null, dataObjectId);
|
|
|
- String library_id = execResult.get("library_id").toString();
|
|
|
- List<Map<String, Object>> preListData = (List<Map<String, Object>>) execResult.get("preData");
|
|
|
- calcData = (List<Map<String, Object>>) execResult.get("calcData");
|
|
|
-
|
|
|
+ } catch ( Exception e ) {
|
|
|
+ System.out.println("dataProcess 关闭异常: " + LogUtils.getException(e));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Object> processSuccess(Object returnData) {
|
|
|
+ if ( returnData instanceof Map ) {
|
|
|
+ Map<String, Object> resultData1 = new HashMap<>();
|
|
|
+ try {
|
|
|
+ resultData1 = (Map<String, Object>) returnData;
|
|
|
+ } catch ( Exception e ) {
|
|
|
+ resultData1.put("returnData", returnData);
|
|
|
+ }
|
|
|
+ resultData1.put("code", "0");
|
|
|
+ return resultData1;
|
|
|
+ }
|
|
|
+ Map<String, Object> returnMap = new HashMap<>();
|
|
|
+ returnMap.put("code", "0");
|
|
|
+ returnMap.put("returnData", returnData);
|
|
|
+ return returnMap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Object> processFail(String errorMessage, String libraryId) {
|
|
|
+ Map<String, Object> returnMap = new HashMap<>();
|
|
|
+ returnMap.put("code", "-1");
|
|
|
+ returnMap.put("message", errorMessage);
|
|
|
+ if ( ! MapTools.isBlank(libraryId) ) {
|
|
|
+ returnMap.put("library_id", libraryId);
|
|
|
+ }
|
|
|
+ return returnMap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Object> processData(Map<String, Object> inputData, String... user_id) {
|
|
|
+ try {
|
|
|
+
|
|
|
+ if ( ! MapTools.isBlank(errorMessage) ) {
|
|
|
+ LogUtils.log("processData:1", "-1", null, "服务不可用".concat(errorMessage), serviceId, inputData, null, null, null);
|
|
|
+ return processFail("服务不可用".concat(errorMessage), null);
|
|
|
+ }
|
|
|
+ if ( System.currentTimeMillis() - lastActive > 2000 ) {
|
|
|
+ lastActive = System.currentTimeMillis();
|
|
|
+ baseDbHelper.updateByCondition("update serviceinfo set runState = ? ,lastactive = ? where serviceID =?", null, "1", new Date(lastActive), serviceId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( ! inputData.containsKey("dataObjectId") ) {
|
|
|
+ inputData.put("dataObjectId", createLifeCycleCol(Long.valueOf(AppConfig.WORK_ID), Integer.parseInt(serviceId)));
|
|
|
+ }
|
|
|
+ String dataObjectId = inputData.get("dataObjectId").toString();
|
|
|
+
|
|
|
+ inputData = authCheck(inputData, user_id);
|
|
|
+ if ( "-1".equals(inputData.get("code")) || (Objects.nonNull(inputData.get("message")) && inputData.get("message").toString().equals("服务未授任何数据权限")) ) {
|
|
|
+ return inputData;
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> calcData = new ArrayList<>();
|
|
|
+ calcData.add(inputData);
|
|
|
+ Map<String, Object> execResult = execCalultion(calcData, null, dataObjectId);
|
|
|
+ String library_id = execResult.get("library_id").toString();
|
|
|
+ List<Map<String, Object>> preListData = (List<Map<String, Object>>) execResult.get("preData");
|
|
|
+ calcData = (List<Map<String, Object>>) execResult.get("calcData");
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
- Map<String, Object> lastResult = library_id.endsWith("N") ? preListData.get(preListData.size() - 1) : calcData.get(calcData.size() - 1);
|
|
|
- if (Objects.equals(lastResult.get("code"), "-1")) {
|
|
|
- Object message = lastResult.get("message");
|
|
|
- LogUtils.log("processData:3", "-1", library_id, Objects.nonNull(message) ? message.toString() : null, serviceId, calcData, dataObjectId, preListData, inputData.get("event"));
|
|
|
- return processFail(library_id.concat("数据计算错误:").concat(lastResult.get("message").toString()), library_id);
|
|
|
- }
|
|
|
-
|
|
|
- List<Map<String, Object>> logData = calcData;
|
|
|
- logData = logData.stream()
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .filter(it ->
|
|
|
- {
|
|
|
+ Map<String, Object> lastResult = library_id.endsWith("N") ? preListData.get(preListData.size() - 1) : calcData.get(calcData.size() - 1);
|
|
|
+ if ( Objects.equals(lastResult.get("code"), "-1") ) {
|
|
|
+ Object message = lastResult.get("message");
|
|
|
+ LogUtils.log("processData:3", "-1", library_id, Objects.nonNull(message) ? message.toString() : null, serviceId, calcData, dataObjectId, preListData, inputData.get("event"));
|
|
|
+ return processFail(library_id.concat("数据计算错误:").concat(lastResult.get("message").toString()), library_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map<String, Object>> logData = calcData;
|
|
|
+ logData = logData.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .filter(it ->
|
|
|
+ {
|
|
|
|
|
|
- Object libraryId = it.get("library_id");
|
|
|
- return Objects.isNull(libraryId) || enableLogCalculationLibrary.contains(Integer.parseInt(libraryId.toString()));
|
|
|
- }
|
|
|
- ).collect(Collectors.toList());
|
|
|
+ Object libraryId = it.get("library_id");
|
|
|
+ return Objects.isNull(libraryId) || enableLogCalculationLibrary.contains(Integer.parseInt(libraryId.toString()));
|
|
|
+ }
|
|
|
+ ).collect(Collectors.toList());
|
|
|
|
|
|
- if (logData.size() == 1 && "0".equals(logData.get(0).getOrDefault("library_id", 0).toString())) {
|
|
|
- logData.clear();
|
|
|
- }
|
|
|
+ if ( logData.size() == 1 && "0".equals(logData.get(0).getOrDefault("library_id", 0).toString()) ) {
|
|
|
+ logData.clear();
|
|
|
+ }
|
|
|
|
|
|
- if (!logData.isEmpty()) {
|
|
|
- LogUtils.log("DataProcess:9999", "0", library_id, "数据接收后处理成功", serviceId, logData, dataObjectId, preListData, inputData.get("event"));
|
|
|
- }
|
|
|
- calcData = calcData.stream().filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
- return processSuccess(calcData.get(calcData.size() - 1));
|
|
|
- } catch (Exception e) {
|
|
|
- return processFail("processData 异常: " + LogUtils.getException(e), null);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public Map<String, Object> authCheck(Map<String, Object> inputData, String... user_id) {
|
|
|
- try {
|
|
|
- Object appid = inputData.get("appid");
|
|
|
- if (Objects.nonNull(appid) && !serviceAuthMap.contains(appid.toString())) {
|
|
|
- return processFail("服务未授权", null);
|
|
|
- }
|
|
|
-
|
|
|
- if (Objects.nonNull(user_id) && inputData.containsKey("authId") && !"1,9999".contains(user_id[0])) {
|
|
|
- Map<String, Object> userDataAuthMap = baseDbHelper.queryByParamsReturnList("SELECT QCS.columnName,TUA.row_auth FROM t_user_group_auth TUA LEFT JOIN querytemplatecolumnset QCS on TUA.queryTemplateColumnSetID = QCS.queryTemplateColumnSetID WHERE TUA.user_id = ? AND TUA.auth_id = ? AND QCS.columnName is not null AND TUA.queryTemplateColumnSetID IS NOT NULL", user_id[0], inputData.get("authId"));
|
|
|
- if (userDataAuthMap.get("code").equals("-1") || Objects.isNull(userDataAuthMap.get("returnData")) || ((List<Map<String, Object>>) userDataAuthMap.get("returnData")).isEmpty()) {
|
|
|
- if (userDataAuthMap.get("code").equals("0")) {
|
|
|
- userDataAuthMap.put("message", "服务未授任何数据权限");
|
|
|
- }
|
|
|
- return userDataAuthMap;
|
|
|
- }
|
|
|
- List<Map<String, Object>> rowAuth = new ArrayList<>();
|
|
|
- List<String> authColumn = new ArrayList<>();
|
|
|
- List<Map<String, Object>> dataAuth = (List<Map<String, Object>>) userDataAuthMap.get("returnData");
|
|
|
- dataAuth.forEach(dataAuthMap -> {
|
|
|
- String columnName = dataAuthMap.get("columnName").toString();
|
|
|
- authColumn.add(columnName);
|
|
|
- Object rowAuthObj = dataAuthMap.get("row_auth");
|
|
|
- if (Objects.nonNull(rowAuthObj)) {
|
|
|
-
|
|
|
-
|
|
|
- Map<String, Object> authExtendMapList = baseDbHelper.queryByParamsReturnList("select nextRule from belowSet where auth_id =?", inputData.get("authId"));
|
|
|
- if ("-1".equals(authExtendMapList.get("code"))) {
|
|
|
- System.out.println("权限集成执行异常".concat(authExtendMapList.get("message").toString()));
|
|
|
- return;
|
|
|
- }
|
|
|
- Object nextRule = authExtendMapList.get("returnData") instanceof List<?> tempList && !tempList.isEmpty() && tempList.get(0) instanceof Map tempMap ? tempMap.get("nextRule") : null;
|
|
|
- String tempRowAuth = rowAuthObj.toString();
|
|
|
- String connect = tempRowAuth.startsWith("!") ? "!=" : "=";
|
|
|
- tempRowAuth = tempRowAuth.startsWith("!") ? tempRowAuth.substring(1) : tempRowAuth;
|
|
|
- String[] row_auths = tempRowAuth.split(",", -1);
|
|
|
- for (String row_auth : row_auths) {
|
|
|
- if (MapTools.isBlank(row_auth)) continue;
|
|
|
- Map<String, Object> signRowAuth = new HashMap<>();
|
|
|
- signRowAuth.put(columnName, row_auth);
|
|
|
- rowAuth.addAll(baseDbHelper.changeSignFilter(signRowAuth, connect, connect.equals("!=") ? "and" : "or"));
|
|
|
-
|
|
|
- if (Objects.nonNull(nextRule)) {
|
|
|
- List<Object> childAuthList = extendNextAuth(columnName, row_auth, nextRule);
|
|
|
- if (!childAuthList.isEmpty()) {
|
|
|
- childAuthList.forEach(authid -> {
|
|
|
- Map<String, Object> tpSignRowAuth = new HashMap<>();
|
|
|
- tpSignRowAuth.put(columnName, authid);
|
|
|
- rowAuth.addAll(baseDbHelper.changeSignFilter(tpSignRowAuth, connect, connect.equals("!=") ? "and" : "or"));
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- if (rowAuth.size() > 0) {
|
|
|
- rowAuth.get(0).put("left", "(".concat(rowAuth.get(0).get("left").toString()));
|
|
|
- rowAuth.get(rowAuth.size() - 1).put("connector", " and ");
|
|
|
- rowAuth.get(rowAuth.size() - 1).put("right", " ) ".concat(rowAuth.get(rowAuth.size() - 1).get("right").toString()));
|
|
|
- inputData.put("rowAuth", rowAuth);
|
|
|
- }
|
|
|
- inputData.put("authColumn", authColumn);
|
|
|
- }
|
|
|
- inputData.put("currentUser", user_id);
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("authCheck 异常:" + LogUtils.getException(e));
|
|
|
- }
|
|
|
- return inputData;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * @param columnName ID
|
|
|
- * @param row_auth 2
|
|
|
- * @param nextRule t_user_group.up_user_groupid
|
|
|
- * @return
|
|
|
- */
|
|
|
- private List<Object> extendNextAuth(String columnName, String row_auth, Object nextRule) {
|
|
|
- List<Object> returnData = new ArrayList<>();
|
|
|
- String[] rule = nextRule.toString().split("\\.", -1);
|
|
|
- Map<String, Object> queryAuthReturnList = baseDbHelper.queryByParamsReturnList("select " + columnName + " from " + rule[0] + " where " + rule[1] + " = ?", row_auth);
|
|
|
- if ("-1".equals(queryAuthReturnList.get("code")) || ((List) queryAuthReturnList.get("returnData")).isEmpty()) {
|
|
|
- return returnData;
|
|
|
- }
|
|
|
- ((List<Map<String, Object>>) queryAuthReturnList.get("returnData")).stream().filter(Objects::nonNull).forEach(authvalue -> {
|
|
|
- returnData.add(authvalue.get(columnName));
|
|
|
- returnData.addAll(extendNextAuth(columnName, authvalue.get(columnName).toString(), nextRule));
|
|
|
- });
|
|
|
- return returnData;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public Map<String, Object> execCalultion(List<Map<String, Object>> inData, String beginLibraryId, String dataObjectId) {
|
|
|
- Map<String, Object> returnData = new HashMap<>();
|
|
|
- List<Map<String, Object>> preData = new ArrayList<>();
|
|
|
- String lastLibraryId = "";
|
|
|
- List<Map<String, Object>> calcData = Objects.isNull(inData) || inData.isEmpty() ? new ArrayList<>() : inData;
|
|
|
- try {
|
|
|
- Map<String, Object> preCalMap = new HashMap<>();
|
|
|
-
|
|
|
- long beginTime = System.currentTimeMillis();
|
|
|
- for (Map<String, Object> calculationLibrary : calcList) {
|
|
|
- lastLibraryId = calculationLibrary.get("library_id").toString();
|
|
|
- if (MapTools.isNotBlank(beginLibraryId) && !beginLibraryId.equals(lastLibraryId)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- beginLibraryId = null;
|
|
|
- Object is_exec = calculationLibrary.get("is_exec");
|
|
|
- if (Objects.nonNull(is_exec) && !MapTools.isBlank(is_exec.toString())) {
|
|
|
- lastLibraryId = lastLibraryId.concat("_N");
|
|
|
- preCalMap.put("library_id", lastLibraryId);
|
|
|
- preCalMap.put("library_type", 2);
|
|
|
- preCalMap.put("computing_expression", is_exec);
|
|
|
- Map<String, Object> preEnginResult = execEngine(lastLibraryId, preCalMap, calcData);
|
|
|
- preEnginResult.put("preExecTime", System.currentTimeMillis() - beginTime);
|
|
|
- beginTime = System.currentTimeMillis();
|
|
|
-
|
|
|
- preData.add(preEnginResult);
|
|
|
- setServiceErrorCount(lastLibraryId, preEnginResult.get("code").toString());
|
|
|
- if ("-1".equals(preEnginResult.get("code")) || Objects.equals("2", preEnginResult.get("returnData"))) {
|
|
|
- break;
|
|
|
- }
|
|
|
- if (Objects.equals("1", preEnginResult.get("returnData"))) {
|
|
|
- calcData.add(null);
|
|
|
- continue;
|
|
|
- }
|
|
|
- lastLibraryId = calculationLibrary.get("library_id").toString();
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, Object> currentResult = calculationLibrary.get("library_type").toString().equals("3") ? execDB(lastLibraryId, calculationLibrary, inData, dataObjectId) : execEngine(lastLibraryId, calculationLibrary, inData);
|
|
|
- currentResult.put("execTime", System.currentTimeMillis() - beginTime);
|
|
|
- beginTime = System.currentTimeMillis();
|
|
|
-
|
|
|
- setServiceErrorCount(lastLibraryId, Objects.nonNull(currentResult) && currentResult.containsKey("code") ? currentResult.get("code").toString() : "0");
|
|
|
- calcData.add(currentResult);
|
|
|
- if (Objects.nonNull(currentResult) && !currentResult.get("code").equals("0")) {
|
|
|
- break;
|
|
|
- } else {
|
|
|
- currentResult.put("library_id", lastLibraryId);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("execCalultion: 算法执行异常: " + LogUtils.getException(e));
|
|
|
- }
|
|
|
- returnData.put("library_id", lastLibraryId);
|
|
|
- returnData.put("preData", preData);
|
|
|
- returnData.put("calcData", calcData);
|
|
|
- return returnData;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private Map<String, Object> execEngine(String library_id, Map<String, Object> currentCalMap, List<Map<String, Object>> calcAllData) {
|
|
|
- try {
|
|
|
- if (!ScriptEngineProMaps.containsKey(library_id)) {
|
|
|
- ScriptEngineProMaps.put(library_id, new ScriptEnginePro(currentCalMap));
|
|
|
- }
|
|
|
- ScriptEnginePro currentEngin = ScriptEngineProMaps.get(library_id);
|
|
|
- String errMessage = "";
|
|
|
- if (Objects.nonNull(currentEngin) && Objects.nonNull(currentEngin.getErrorMessage())) {
|
|
|
- errMessage = currentEngin.getErrorMessage();
|
|
|
- currentEngin.close();
|
|
|
- currentEngin = null;
|
|
|
- }
|
|
|
- if (Objects.isNull(currentEngin)) {
|
|
|
- ScriptEngineProMaps.remove(library_id);
|
|
|
- return processFail("创建引擎失败".concat(errMessage), library_id);
|
|
|
- }
|
|
|
- Map<String, String> parmaNames = currentEngin.getParmaNames();
|
|
|
- Map<String, Object> paramValue = new HashMap<>();
|
|
|
- for (String key : parmaNames.keySet()) {
|
|
|
- Object currentData = dataSubscription(calcAllData, key, currentCalMap);
|
|
|
- paramValue.put(currentCalMap.get("library_type").toString().equals("2") ? parmaNames.get(key) : key, currentData);
|
|
|
- }
|
|
|
- Map<String, Object> stringObjectMap = currentEngin.execScript(paramValue);
|
|
|
- return stringObjectMap;
|
|
|
- } catch (Exception e) {
|
|
|
- return processFail("创建引擎失败".concat(LogUtils.getException(e)), library_id);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private Map<String, Object> execDB(String library_id, Map<String, Object> calculationLibrary, List<Map<String, Object>> calcData, String dataObjectId) {
|
|
|
- try {
|
|
|
- Object connectConfigObj = calculationLibrary.get("connectConfig");
|
|
|
- if (Objects.isNull(connectConfigObj)) {
|
|
|
- return processFail("连接信息未配置 ", library_id);
|
|
|
- }
|
|
|
- if (!calcDbHelperMaps.containsKey(library_id)) {
|
|
|
- calcDbHelperMaps.put(library_id, new MyDbHelper(connectConfigObj.toString()));
|
|
|
- }
|
|
|
- MyDbHelper myDbHelper = calcDbHelperMaps.get(library_id);
|
|
|
- String errMessage = "";
|
|
|
- if (Objects.nonNull(myDbHelper) && MapTools.isNotBlank(errMessage)) {
|
|
|
- errMessage = myDbHelper.getErrorMessage();
|
|
|
- myDbHelper.close();
|
|
|
- myDbHelper = null;
|
|
|
- }
|
|
|
- if (Objects.isNull(myDbHelper)) {
|
|
|
- calcDbHelperMaps.remove(library_id);
|
|
|
- return processFail("获取业务数据库对象失败".concat(errMessage), library_id);
|
|
|
- }
|
|
|
-
|
|
|
- String paramIndex = Objects.isNull(calculationLibrary.get("parmIndex")) ? (String.valueOf(calcData.size() - 1)).concat(calcData.size() == 1 ? ".dataContent" : ".returnData") : calculationLibrary.get("parmIndex").toString();
|
|
|
- Object tempDBPrams = dataSubscription(calcData, "List.".concat(paramIndex), calculationLibrary);
|
|
|
-
|
|
|
-
|
|
|
- if ("7".equals(calculationLibrary.get("event")) && !Objects.isNull(calculationLibrary.get("tableName")) && !Objects.isNull(calculationLibrary.get("computing_expression"))) {
|
|
|
- Map<String, Object> tempCalcInfo = calculationLibrary;
|
|
|
- String tableName = tempCalcInfo.get("tableName").toString();
|
|
|
- String sqlStr = tempCalcInfo.get("computing_expression").toString();
|
|
|
- tempCalcInfo.put("tableName", "");
|
|
|
- tempDBPrams = myDbHelper.generalProcess(tempCalcInfo, tempDBPrams, dataObjectId, calcData.get(0));
|
|
|
-
|
|
|
-
|
|
|
- tempCalcInfo.put("tableName", tableName);
|
|
|
- tempCalcInfo.put("computing_expression", "");
|
|
|
- tempCalcInfo.put("event", "6");
|
|
|
- return myDbHelper.generalProcess(tempCalcInfo, tempDBPrams, dataObjectId, calcData.get(0));
|
|
|
- }
|
|
|
- return myDbHelper.generalProcess(calculationLibrary, tempDBPrams, dataObjectId, calcData.get(0));
|
|
|
- } catch (Exception e) {
|
|
|
- return processFail("数据库执行失败".concat(LogUtils.getException(e)), library_id);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private Object dataSubscription(List<Map<String, Object>> calcAllData, String paramRule, Map<String, Object> calculationLibrary) {
|
|
|
- try {
|
|
|
- String[] itemRule = paramRule.split("\\.", -1);
|
|
|
- String dataType = itemRule.length > 0 ? itemRule[0] : "List";
|
|
|
- dataType = dataType.endsWith("]") ? dataType.substring(0, dataType.indexOf("[")) : dataType;
|
|
|
- String dataLocation = itemRule.length > 1 ? itemRule[1] : "";
|
|
|
- if (dataLocation.equals("T")) {
|
|
|
- Object tempObj = itemRule.length > 2 ? MapTools.isBlank(itemRule[2]) ? ("List".equals(dataType) ? new ArrayList<>() : ("JSON,Map".contains(dataType) ? new HashMap<>() : null)) : itemRule[2] : null;
|
|
|
- if ("Boolean".equals(dataType)) {
|
|
|
- tempObj = itemRule[2].equals("true");
|
|
|
- }
|
|
|
- return tempObj;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- Object returnData = dataLocation.equals("L") ? calculationLibrary : MapTools.isNumber(dataLocation) ? calcAllData.get(Integer.parseInt(dataLocation)) : null;
|
|
|
- for (int index = 2; index < itemRule.length; index++) {
|
|
|
- if (Objects.isNull(returnData)) return null;
|
|
|
- if (returnData instanceof String) {
|
|
|
- returnData = MapTools.strToObj(returnData.toString());
|
|
|
- }
|
|
|
- if (MapTools.isNumber(itemRule[index])) {
|
|
|
-
|
|
|
- int tempIndex = Integer.parseInt(itemRule[index]);
|
|
|
- returnData = returnData instanceof List<?> tempList && tempList.size() > tempIndex ? tempList.get(tempIndex) : returnData;
|
|
|
- } else {
|
|
|
- if (returnData instanceof Map) {
|
|
|
- returnData = itemRule[index].equals("returnData") && Objects.isNull(((Map<?, ?>) returnData).get("returnData")) ? ((Map<?, ?>) returnData).get("dataContent") : ((Map<?, ?>) returnData).get(itemRule[index]);
|
|
|
- } else {
|
|
|
- if (returnData instanceof List && ((List<?>) returnData).size() > 0 && ((List<?>) returnData).get(0) instanceof Map) {
|
|
|
- returnData = ((Map<?, ?>) ((List<?>) returnData).get(0)).get(itemRule[index]);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (Objects.nonNull(returnData)) {
|
|
|
- if ("List,Map".contains(dataType) && returnData instanceof String) {
|
|
|
- returnData = MapTools.strToObj(returnData.toString());
|
|
|
- }
|
|
|
- if ("List".equals(dataType) && !(returnData instanceof List<?>)) {
|
|
|
- List<Object> tempList = new ArrayList<>();
|
|
|
- tempList.add(returnData);
|
|
|
- returnData = tempList;
|
|
|
- }
|
|
|
- if ("Array".contains(dataType)) {
|
|
|
- if (returnData instanceof List<?> tempList && !tempList.isEmpty()) {
|
|
|
- List<Object> tpList = new ArrayList<>();
|
|
|
- for (Object o : tempList) {
|
|
|
- if (o instanceof Map<?, ?>) {
|
|
|
- tpList.add(MapTools.objToJSONStr(o));
|
|
|
- } else if (o instanceof String tpStr && tpStr.contains("=") && tpStr.contains("{") && tpStr.contains("}")) {
|
|
|
- tpList.add(MapTools.objToJSONStr(MapTools.strToObj(tpStr)));
|
|
|
- } else {
|
|
|
- tpList.add(o);
|
|
|
- }
|
|
|
- }
|
|
|
- returnData = tpList;
|
|
|
- }
|
|
|
- if (returnData instanceof Map<?, ?> tpMap) {
|
|
|
- returnData = MapTools.objToJSONStr(tpMap);
|
|
|
- }
|
|
|
- if (returnData instanceof String tpStr && tpStr.contains("=") && tpStr.contains("{") && tpStr.contains("}")) {
|
|
|
- returnData = MapTools.objToJSONStr(MapTools.strToObj(tpStr));
|
|
|
- }
|
|
|
- }
|
|
|
+ if ( ! logData.isEmpty() ) {
|
|
|
+ LogUtils.log("DataProcess:9999", "0", library_id, "数据接收后处理成功", serviceId, logData, dataObjectId, preListData, inputData.get("event"));
|
|
|
+ }
|
|
|
+ calcData = calcData.stream().filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+ return processSuccess(calcData.get(calcData.size() - 1));
|
|
|
+ } catch ( Exception e ) {
|
|
|
+ return processFail("processData 异常: " + LogUtils.getException(e), null);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Object> authCheck(Map<String, Object> inputData, String... user_id) {
|
|
|
+ try {
|
|
|
+ Object appid = inputData.get("appid");
|
|
|
+ if ( Objects.nonNull(appid) && ! serviceAuthMap.contains(appid.toString()) ) {
|
|
|
+ return processFail("服务未授权", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( Objects.nonNull(user_id) && inputData.containsKey("authId") && ! "1,9999".contains(user_id[0]) ) {
|
|
|
+ Map<String, Object> userDataAuthMap = baseDbHelper.queryByParamsReturnList("SELECT QCS.columnName,TUA.row_auth FROM t_user_group_auth TUA LEFT JOIN querytemplatecolumnset QCS on TUA.queryTemplateColumnSetID = QCS.queryTemplateColumnSetID WHERE TUA.user_id = ? AND TUA.auth_id = ? AND QCS.columnName is not null AND TUA.queryTemplateColumnSetID IS NOT NULL", user_id[0], inputData.get("authId"));
|
|
|
+ if ( userDataAuthMap.get("code").equals("-1") || Objects.isNull(userDataAuthMap.get("returnData")) || ((List<Map<String, Object>>) userDataAuthMap.get("returnData")).isEmpty() ) {
|
|
|
+ if ( userDataAuthMap.get("code").equals("0") ) {
|
|
|
+ userDataAuthMap.put("message", "服务未授任何数据权限");
|
|
|
+ }
|
|
|
+ return userDataAuthMap;
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> rowAuth = new ArrayList<>();
|
|
|
+ List<String> authColumn = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> dataAuth = (List<Map<String, Object>>) userDataAuthMap.get("returnData");
|
|
|
+ dataAuth.forEach(dataAuthMap -> {
|
|
|
+ String columnName = dataAuthMap.get("columnName").toString();
|
|
|
+ authColumn.add(columnName);
|
|
|
+ Object rowAuthObj = dataAuthMap.get("row_auth");
|
|
|
+ if ( Objects.nonNull(rowAuthObj) ) {
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Object> authExtendMapList = baseDbHelper.queryByParamsReturnList("select nextRule from belowSet where auth_id =?", inputData.get("authId"));
|
|
|
+ if ( "-1".equals(authExtendMapList.get("code")) ) {
|
|
|
+ System.out.println("权限集成执行异常".concat(authExtendMapList.get("message").toString()));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Object nextRule = authExtendMapList.get("returnData") instanceof List<?> tempList && ! tempList.isEmpty() && tempList.get(0) instanceof Map tempMap ? tempMap.get("nextRule") : null;
|
|
|
+ String tempRowAuth = rowAuthObj.toString();
|
|
|
+ String connect = tempRowAuth.startsWith("!") ? "!=" : "=";
|
|
|
+ tempRowAuth = tempRowAuth.startsWith("!") ? tempRowAuth.substring(1) : tempRowAuth;
|
|
|
+ String[] row_auths = tempRowAuth.split(",", - 1);
|
|
|
+ for ( String row_auth : row_auths ) {
|
|
|
+ if ( MapTools.isBlank(row_auth) ) continue;
|
|
|
+ Map<String, Object> signRowAuth = new HashMap<>();
|
|
|
+ signRowAuth.put(columnName, row_auth);
|
|
|
+ rowAuth.addAll(baseDbHelper.changeSignFilter(signRowAuth, connect, connect.equals("!=") ? "and" : "or"));
|
|
|
+
|
|
|
+ if ( Objects.nonNull(nextRule) ) {
|
|
|
+ List<Object> childAuthList = extendNextAuth(columnName, row_auth, nextRule);
|
|
|
+ if ( ! childAuthList.isEmpty() ) {
|
|
|
+ childAuthList.forEach(authid -> {
|
|
|
+ Map<String, Object> tpSignRowAuth = new HashMap<>();
|
|
|
+ tpSignRowAuth.put(columnName, authid);
|
|
|
+ rowAuth.addAll(baseDbHelper.changeSignFilter(tpSignRowAuth, connect, connect.equals("!=") ? "and" : "or"));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if ( rowAuth.size() > 0 ) {
|
|
|
+ rowAuth.get(0).put("left", "(".concat(rowAuth.get(0).get("left").toString()));
|
|
|
+ rowAuth.get(rowAuth.size() - 1).put("connector", " and ");
|
|
|
+ rowAuth.get(rowAuth.size() - 1).put("right", " ) ".concat(rowAuth.get(rowAuth.size() - 1).get("right").toString()));
|
|
|
+ inputData.put("rowAuth", rowAuth);
|
|
|
+ }
|
|
|
+ inputData.put("authColumn", authColumn);
|
|
|
+ }
|
|
|
+ inputData.put("currentUser", user_id);
|
|
|
+ } catch ( Exception e ) {
|
|
|
+ System.out.println("authCheck 异常:" + LogUtils.getException(e));
|
|
|
+ }
|
|
|
+ return inputData;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * @param columnName ID
|
|
|
+ * @param row_auth 2
|
|
|
+ * @param nextRule t_user_group.up_user_groupid
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<Object> extendNextAuth(String columnName, String row_auth, Object nextRule) {
|
|
|
+ List<Object> returnData = new ArrayList<>();
|
|
|
+ String[] rule = nextRule.toString().split("\\.", - 1);
|
|
|
+ Map<String, Object> queryAuthReturnList = baseDbHelper.queryByParamsReturnList("select " + columnName + " from " + rule[0] + " where " + rule[1] + " = ?", row_auth);
|
|
|
+ if ( "-1".equals(queryAuthReturnList.get("code")) || ((List) queryAuthReturnList.get("returnData")).isEmpty() ) {
|
|
|
+ return returnData;
|
|
|
+ }
|
|
|
+ ((List<Map<String, Object>>) queryAuthReturnList.get("returnData")).stream().filter(Objects::nonNull).forEach(authvalue -> {
|
|
|
+ returnData.add(authvalue.get(columnName));
|
|
|
+ returnData.addAll(extendNextAuth(columnName, authvalue.get(columnName).toString(), nextRule));
|
|
|
+ });
|
|
|
+ return returnData;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Object> execCalultion(List<Map<String, Object>> inData, String beginLibraryId, String dataObjectId) {
|
|
|
+ Map<String, Object> returnData = new HashMap<>();
|
|
|
+ List<Map<String, Object>> preData = new ArrayList<>();
|
|
|
+ String lastLibraryId = "";
|
|
|
+ List<Map<String, Object>> calcData = Objects.isNull(inData) || inData.isEmpty() ? new ArrayList<>() : inData;
|
|
|
+ try {
|
|
|
+ Map<String, Object> preCalMap = new HashMap<>();
|
|
|
+
|
|
|
+ long beginTime = System.currentTimeMillis();
|
|
|
+ for ( Map<String, Object> calculationLibrary : calcList ) {
|
|
|
+ lastLibraryId = calculationLibrary.get("library_id").toString();
|
|
|
+ if ( MapTools.isNotBlank(beginLibraryId) && ! beginLibraryId.equals(lastLibraryId) ) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ beginLibraryId = null;
|
|
|
+ Object is_exec = calculationLibrary.get("is_exec");
|
|
|
+ if ( Objects.nonNull(is_exec) && ! MapTools.isBlank(is_exec.toString()) ) {
|
|
|
+ lastLibraryId = lastLibraryId.concat("_N");
|
|
|
+ preCalMap.put("library_id", lastLibraryId);
|
|
|
+ preCalMap.put("library_type", 2);
|
|
|
+ preCalMap.put("computing_expression", is_exec);
|
|
|
+ Map<String, Object> preEnginResult = execEngine(lastLibraryId, preCalMap, calcData);
|
|
|
+ preEnginResult.put("preExecTime", System.currentTimeMillis() - beginTime);
|
|
|
+ beginTime = System.currentTimeMillis();
|
|
|
+
|
|
|
+ preData.add(preEnginResult);
|
|
|
+ setServiceErrorCount(lastLibraryId, preEnginResult.get("code").toString());
|
|
|
+ if ( "-1".equals(preEnginResult.get("code")) || Objects.equals("2", preEnginResult.get("returnData")) ) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if ( Objects.equals("1", preEnginResult.get("returnData")) ) {
|
|
|
+ calcData.add(null);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ lastLibraryId = calculationLibrary.get("library_id").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> currentResult = calculationLibrary.get("library_type").toString().equals("3") ? execDB(lastLibraryId, calculationLibrary, inData, dataObjectId) : execEngine(lastLibraryId, calculationLibrary, inData);
|
|
|
+ currentResult.put("execTime", System.currentTimeMillis() - beginTime);
|
|
|
+ beginTime = System.currentTimeMillis();
|
|
|
+
|
|
|
+ setServiceErrorCount(lastLibraryId, Objects.nonNull(currentResult) && currentResult.containsKey("code") ? currentResult.get("code").toString() : "0");
|
|
|
+ calcData.add(currentResult);
|
|
|
+ if ( Objects.nonNull(currentResult) && ! currentResult.get("code").equals("0") ) {
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ currentResult.put("library_id", lastLibraryId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch ( Exception e ) {
|
|
|
+ System.out.println("execCalultion: 算法执行异常: " + LogUtils.getException(e));
|
|
|
+ }
|
|
|
+ returnData.put("library_id", lastLibraryId);
|
|
|
+ returnData.put("preData", preData);
|
|
|
+ returnData.put("calcData", calcData);
|
|
|
+ return returnData;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Map<String, Object> execEngine(String library_id, Map<String, Object> currentCalMap, List<Map<String, Object>> calcAllData) {
|
|
|
+ try {
|
|
|
+
|
|
|
+ if ( ! ScriptEngineProMaps.containsKey(library_id) ) {
|
|
|
+ ScriptEngineProMaps.put(library_id, new ScriptEnginePro(currentCalMap));
|
|
|
+ }
|
|
|
+
|
|
|
+ ScriptEnginePro currentEngin = ScriptEngineProMaps.get(library_id);
|
|
|
+ String errMessage = "";
|
|
|
+
|
|
|
+ if ( Objects.nonNull(currentEngin) && Objects.nonNull(currentEngin.getErrorMessage()) ) {
|
|
|
+ errMessage = currentEngin.getErrorMessage();
|
|
|
+ currentEngin.close();
|
|
|
+ currentEngin = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( Objects.isNull(currentEngin) ) {
|
|
|
+ ScriptEngineProMaps.remove(library_id);
|
|
|
+ return processFail("创建引擎失败".concat(errMessage), library_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, String> parmaNames = currentEngin.getParmaNames();
|
|
|
+ Map<String, Object> paramValue = new HashMap<>();
|
|
|
+
|
|
|
+ for ( String key : parmaNames.keySet() ) {
|
|
|
+
|
|
|
+ Object currentData = dataSubscription(calcAllData, key, currentCalMap);
|
|
|
+ paramValue.put(currentCalMap.get("library_type").toString().equals("2") ? parmaNames.get(key) : key, currentData);
|
|
|
+ }
|
|
|
+ Map<String, Object> stringObjectMap = currentEngin.execScript(paramValue);
|
|
|
+ return stringObjectMap;
|
|
|
+ } catch ( Exception e ) {
|
|
|
+ return processFail("创建引擎失败".concat(LogUtils.getException(e)), library_id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Map<String, Object> execDB(String library_id, Map<String, Object> calculationLibrary, List<Map<String, Object>> calcData, String dataObjectId) {
|
|
|
+ try {
|
|
|
+ Object connectConfigObj = calculationLibrary.get("connectConfig");
|
|
|
+ if ( Objects.isNull(connectConfigObj) ) {
|
|
|
+ return processFail("连接信息未配置 ", library_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( ! calcDbHelperMaps.containsKey(library_id) ) {
|
|
|
+ calcDbHelperMaps.put(library_id, new MyDbHelper(connectConfigObj.toString()));
|
|
|
+ }
|
|
|
+
|
|
|
+ MyDbHelper myDbHelper = calcDbHelperMaps.get(library_id);
|
|
|
+ String errMessage = "";
|
|
|
+
|
|
|
+ if ( Objects.nonNull(myDbHelper) && MapTools.isNotBlank(errMessage) ) {
|
|
|
+ errMessage = myDbHelper.getErrorMessage();
|
|
|
+ myDbHelper.close();
|
|
|
+ myDbHelper = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( Objects.isNull(myDbHelper) ) {
|
|
|
+ calcDbHelperMaps.remove(library_id);
|
|
|
+ return processFail("获取业务数据库对象失败".concat(errMessage), library_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ String paramIndex = Objects.isNull(calculationLibrary.get("parmIndex")) ? (String.valueOf(calcData.size() - 1)).concat(calcData.size() == 1 ? ".dataContent" : ".returnData") : calculationLibrary.get("parmIndex").toString();
|
|
|
+ Object tempDBPrams = dataSubscription(calcData, "List.".concat(paramIndex), calculationLibrary);
|
|
|
+
|
|
|
+
|
|
|
+ if ( "7".equals(calculationLibrary.get("event")) && ! Objects.isNull(calculationLibrary.get("tableName")) && ! Objects.isNull(calculationLibrary.get("computing_expression")) ) {
|
|
|
+ Map<String, Object> tempCalcInfo = calculationLibrary;
|
|
|
+ String tableName = tempCalcInfo.get("tableName").toString();
|
|
|
+ String sqlStr = tempCalcInfo.get("computing_expression").toString();
|
|
|
+ tempCalcInfo.put("tableName", "");
|
|
|
+ tempDBPrams = myDbHelper.generalProcess(tempCalcInfo, tempDBPrams, dataObjectId, calcData.get(0));
|
|
|
+
|
|
|
+
|
|
|
+ tempCalcInfo.put("tableName", tableName);
|
|
|
+ tempCalcInfo.put("computing_expression", "");
|
|
|
+ tempCalcInfo.put("event", "6");
|
|
|
+ return myDbHelper.generalProcess(tempCalcInfo, tempDBPrams, dataObjectId, calcData.get(0));
|
|
|
+ }
|
|
|
+ return myDbHelper.generalProcess(calculationLibrary, tempDBPrams, dataObjectId, calcData.get(0));
|
|
|
+ } catch ( Exception e ) {
|
|
|
+ return processFail("数据库执行失败".concat(LogUtils.getException(e)), library_id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Object dataSubscription(List<Map<String, Object>> calcAllData, String paramRule, Map<String, Object> calculationLibrary) {
|
|
|
+ try {
|
|
|
+ String[] itemRule = paramRule.split("\\.", - 1);
|
|
|
+ String dataType = itemRule.length > 0 ? itemRule[0] : "List";
|
|
|
+ dataType = dataType.endsWith("]") ? dataType.substring(0, dataType.indexOf("[")) : dataType;
|
|
|
+ String dataLocation = itemRule.length > 1 ? itemRule[1] : "";
|
|
|
+ if ( dataLocation.equals("T") ) {
|
|
|
+ Object tempObj = itemRule.length > 2 ? MapTools.isBlank(itemRule[2]) ? ("List".equals(dataType) ? new ArrayList<>() : ("JSON,Map".contains(dataType) ? new HashMap<>() : null)) : itemRule[2] : null;
|
|
|
+ if ( "Boolean".equals(dataType) ) {
|
|
|
+ tempObj = itemRule[2].equals("true");
|
|
|
+ }
|
|
|
+ return tempObj;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Object returnData = dataLocation.equals("L") ? calculationLibrary : MapTools.isNumber(dataLocation) ? calcAllData.get(Integer.parseInt(dataLocation)) : null;
|
|
|
+ for ( int index = 2; index < itemRule.length; index++ ) {
|
|
|
+ if ( Objects.isNull(returnData) ) return null;
|
|
|
+ if ( returnData instanceof String ) {
|
|
|
+ returnData = MapTools.strToObj(returnData.toString());
|
|
|
+ }
|
|
|
+ if ( MapTools.isNumber(itemRule[index]) ) {
|
|
|
+
|
|
|
+ int tempIndex = Integer.parseInt(itemRule[index]);
|
|
|
+ returnData = returnData instanceof List<?> tempList && tempList.size() > tempIndex ? tempList.get(tempIndex) : returnData;
|
|
|
+ } else {
|
|
|
+ if ( returnData instanceof Map ) {
|
|
|
+ returnData = itemRule[index].equals("returnData") && Objects.isNull(((Map<?, ?>) returnData).get("returnData")) ? ((Map<?, ?>) returnData).get("dataContent") : ((Map<?, ?>) returnData).get(itemRule[index]);
|
|
|
+ } else {
|
|
|
+ if ( returnData instanceof List && ((List<?>) returnData).size() > 0 && ((List<?>) returnData).get(0) instanceof Map ) {
|
|
|
+ returnData = ((Map<?, ?>) ((List<?>) returnData).get(0)).get(itemRule[index]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ( Objects.nonNull(returnData) ) {
|
|
|
+ if ( "List,Map".contains(dataType) && returnData instanceof String ) {
|
|
|
+ returnData = MapTools.strToObj(returnData.toString());
|
|
|
+ }
|
|
|
+ if ( "List".equals(dataType) && ! (returnData instanceof List<?>) ) {
|
|
|
+ List<Object> tempList = new ArrayList<>();
|
|
|
+ tempList.add(returnData);
|
|
|
+ returnData = tempList;
|
|
|
+ }
|
|
|
+ if ( "Array".contains(dataType) ) {
|
|
|
+ if ( returnData instanceof List<?> tempList && ! tempList.isEmpty() ) {
|
|
|
+ List<Object> tpList = new ArrayList<>();
|
|
|
+ for ( Object o : tempList ) {
|
|
|
+ if ( o instanceof Map<?, ?> ) {
|
|
|
+ tpList.add(MapTools.objToJSONStr(o));
|
|
|
+ } else if ( o instanceof String tpStr && tpStr.contains("=") && tpStr.contains("{") && tpStr.contains("}") ) {
|
|
|
+ tpList.add(MapTools.objToJSONStr(MapTools.strToObj(tpStr)));
|
|
|
+ } else {
|
|
|
+ tpList.add(o);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ returnData = tpList;
|
|
|
+ }
|
|
|
+ if ( returnData instanceof Map<?, ?> tpMap ) {
|
|
|
+ returnData = MapTools.objToJSONStr(tpMap);
|
|
|
+ }
|
|
|
+ if ( returnData instanceof String tpStr && tpStr.contains("=") && tpStr.contains("{") && tpStr.contains("}") ) {
|
|
|
+ returnData = MapTools.objToJSONStr(MapTools.strToObj(tpStr));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
- returnData = "Map".equals(dataType) && !(returnData instanceof Map<?, ?>) ? null
|
|
|
- : ("String".equals(dataType) ? MapTools.objToJSONStr(returnData) : ("Boolean".equals(dataType) ? returnData.toString().equals("true") : ("JSONStr".equals(dataType) ? MapTools.objToJSONStr(returnData) : returnData)));
|
|
|
- }
|
|
|
- return returnData;
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("数据订阅异常: ".concat(LogUtils.getException(e)));
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public void setServiceErrorCount(String library_id, String success) {
|
|
|
- if (!success.equals("0")) {
|
|
|
- Integer errCount = Objects.isNull(serviceErrorCount.get(library_id)) ? 1 : serviceErrorCount.get(library_id) + 1;
|
|
|
- serviceErrorCount.put(library_id, errCount);
|
|
|
- if (errCount > AppConfig.SERVICE_ERR_MAX) {
|
|
|
- ServiceInputControl.stop(serviceId);
|
|
|
- }
|
|
|
- } else {
|
|
|
- serviceErrorCount.put(library_id, 0);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private long sequence = 0L;
|
|
|
- private long lastTimestamp = -1L;
|
|
|
-
|
|
|
- public String createLifeCycleCol(Long workerId, Integer serviceId) {
|
|
|
- long timestamp = System.currentTimeMillis();
|
|
|
-
|
|
|
- if (lastTimestamp == timestamp) {
|
|
|
- sequence++;
|
|
|
- if (sequence > 999L) {
|
|
|
- sequence = 0;
|
|
|
- while (lastTimestamp == System.currentTimeMillis()) {
|
|
|
- }
|
|
|
- timestamp = System.currentTimeMillis();
|
|
|
- }
|
|
|
- } else {
|
|
|
- sequence = 0L;
|
|
|
- }
|
|
|
- lastTimestamp = timestamp;
|
|
|
-
|
|
|
- return String.valueOf(timestamp).concat(String.format("%03d", sequence)).concat(String.format("%04d", workerId)).concat(String.format("%04d", serviceId));
|
|
|
- }
|
|
|
-
|
|
|
- public String getServiceId() {
|
|
|
- return serviceId;
|
|
|
- }
|
|
|
-
|
|
|
- public String getErrorMessage() {
|
|
|
- return errorMessage;
|
|
|
- }
|
|
|
-
|
|
|
- public long getLastActive() {
|
|
|
- return lastActive;
|
|
|
- }
|
|
|
+ returnData = "Map".equals(dataType) && ! (returnData instanceof Map<?, ?>) ? null
|
|
|
+ : ("String".equals(dataType) ? MapTools.objToJSONStr(returnData) : ("Boolean".equals(dataType) ? returnData.toString().equals("true") : ("JSONStr".equals(dataType) ? MapTools.objToJSONStr(returnData) : returnData)));
|
|
|
+ }
|
|
|
+ return returnData;
|
|
|
+ } catch ( Exception e ) {
|
|
|
+ System.out.println("数据订阅异常: ".concat(LogUtils.getException(e)));
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void setServiceErrorCount(String library_id, String success) {
|
|
|
+ if ( ! success.equals("0") ) {
|
|
|
+ Integer errCount = Objects.isNull(serviceErrorCount.get(library_id)) ? 1 : serviceErrorCount.get(library_id) + 1;
|
|
|
+ serviceErrorCount.put(library_id, errCount);
|
|
|
+ if ( errCount > AppConfig.SERVICE_ERR_MAX ) {
|
|
|
+ ServiceInputControl.stop(serviceId);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ serviceErrorCount.put(library_id, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private long sequence = 0L;
|
|
|
+ private long lastTimestamp = - 1L;
|
|
|
+
|
|
|
+ public String createLifeCycleCol(Long workerId, Integer serviceId) {
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
+
|
|
|
+ if ( lastTimestamp == timestamp ) {
|
|
|
+ sequence++;
|
|
|
+ if ( sequence > 999L ) {
|
|
|
+ sequence = 0;
|
|
|
+ while ( lastTimestamp == System.currentTimeMillis() ) {
|
|
|
+ }
|
|
|
+ timestamp = System.currentTimeMillis();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ sequence = 0L;
|
|
|
+ }
|
|
|
+ lastTimestamp = timestamp;
|
|
|
+
|
|
|
+ return String.valueOf(timestamp).concat(String.format("%03d", sequence)).concat(String.format("%04d", workerId)).concat(String.format("%04d", serviceId));
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getServiceId() {
|
|
|
+ return serviceId;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getErrorMessage() {
|
|
|
+ return errorMessage;
|
|
|
+ }
|
|
|
+
|
|
|
+ public long getLastActive() {
|
|
|
+ return lastActive;
|
|
|
+ }
|
|
|
}
|