pms 1 rok temu
rodzic
commit
3730cf48db

+ 2 - 1
mainFactory/src/main/java/org/bfkj/MainFactoryApplication.java

@@ -227,7 +227,8 @@ public class MainFactoryApplication implements InitializingBean {
     @Scheduled(cron = "0 15 * * * ?")
     public void closeObject() {
         long timeOut = 15 * 1000 * 60;
-        for (DataProcess dataProcess : ObjectMap.dataProcessMaps.values()) {
+        Collection<DataProcess> tpList = ObjectMap.dataProcessMaps.values();
+        for (DataProcess dataProcess : tpList ) {
             if (System.currentTimeMillis() - dataProcess.getLastActive() > timeOut) {
                 String serviceId = dataProcess.getServiceId();
                 ObjectMap.getordropInput(serviceId, false);

+ 20 - 0
mainFactory/src/main/java/org/bfkj/api/AuthManageApi.java

@@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.HashMap;
 import java.util.Map;
 
 @RestController
@@ -25,6 +26,25 @@ public class AuthManageApi {
         return authApplication.getToken(params, sessionID);
     }
 
+    @PostMapping("application-token")
+    public Object application_token(@RequestBody Map<String, String> params, HttpServletRequest httpServletRequest) {
+        String sessionID = httpServletRequest.getSession().getId();
+        Map rsData =  (Map)authApplication.getToken(params, sessionID);
+        HashMap<String, Object> rsMap = new HashMap<>();
+        try {
+            rsMap.put("code",rsData.get("code"));
+            HashMap<String, Object> dataMap = new HashMap<>();
+            dataMap.put("expireTime",((Map)rsData.get("returnData")).get("app_effective"));
+            dataMap.put("appToken",((Map)rsData.get("returnData")).get("app_token"));
+            rsMap.put("data",dataMap);
+            rsMap.put("message",rsData.get("message"));
+        }catch (Exception e){
+            rsMap.put("message",rsData.get("message"));
+        }
+        return rsMap;
+    }
+
+
     // todo 新增refreshToken()
     @PostMapping("refreshToken")
     public Object refreshToken(@RequestBody Map<String, String> params) {

+ 4 - 9
mainFactory/src/main/java/org/bfkj/api/CommonApi.java

@@ -52,17 +52,12 @@ public class CommonApi {
     public Object queryApi(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
         Map<String, Object> stringObjectMap;
         if (params.containsKey("id") && !params.containsKey("serviceId")) {
-            Map<String, Object> callBack = new HashMap<>();
-            callBack.put("serviceId", "200241");
-            callBack.put("dataContent", params);
-            callBack.put("event", "0");
-            stringObjectMap = commonInterface(token, callBack, "0");
-        } else {
-            stringObjectMap = commonInterface(token, params, "0");
+            params.put("serviceId",params.get("id"));
+            params.put("event", "0");
+            params.remove("id");
         }
-        return stringObjectMap;
+        return commonInterface(token, params, "0");
     }
-
     /**
      * 新增入口CRUD
      */

+ 106 - 0
mainFactory/src/main/java/org/bfkj/api/NewCommonApi.java

@@ -0,0 +1,106 @@
+package org.bfkj.api;
+
+import org.bfkj.application.AuthApplicationImpl;
+import org.bfkj.application.DataProcess;
+import org.bfkj.config.AppConfig;
+import org.bfkj.config.ObjectMap;
+import org.bfkj.utils.MapTools;
+import org.bfkj.utils.MyDbHelper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * 统一入口
+ */
+@RestController
+@RequestMapping("newOpenApi")
+//@CrossOrigin
+public class NewCommonApi {
+    @Autowired
+    private AuthApplicationImpl authApplication;
+
+    @PostMapping("search")
+    @ResponseBody
+    public Object search(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
+        return commonInterface(token, params, "0", (params.containsKey("id") && !params.containsKey("serviceId")) ? Objects.toString(params.get("id")) : null);
+    }
+    /**
+     * 统一接收处理
+     */
+    private Map<String, Object> commonInterface(Map<String, String> token, Map<String, Object> params, String defaultEvent, String... queryId) {
+        if (Objects.isNull(queryId) || Objects.isNull(queryId[0])) {
+            if (token.containsKey("token")) {
+                String appToken = token.get("token");
+                String verificationToke = authApplication.verificationToken(appToken);
+                if (!MapTools.isNumber(verificationToke)) {
+                    HashMap<String, Object> errMap = new HashMap<>();
+                    errMap.put("code", "-1");
+                    errMap.put("message", "应用token验证失败:" + verificationToke);
+                    return errMap;
+                }
+            } else {
+                String verificationToke = authApplication.verificationUserToken(token);
+                if (!MapTools.isBlank(verificationToke)) {
+                    HashMap<String, Object> errMap = new HashMap<>();
+                    errMap.put("code", "-1");
+                    errMap.put("message", "用户令牌验证失败:" + verificationToke);
+                    return errMap;
+                }
+            }
+        }
+        Object event = params.get("event");//获取参数中的事件标识
+        if (Objects.isNull(event) && !MapTools.isBlank(defaultEvent)) {//如果参数中的没有事件标识并且有默认事件标识则使用默认事件标识
+            event = defaultEvent;
+            params.put("event", defaultEvent);
+        }
+        if (!MapTools.isBlank(defaultEvent) && !event.equals(defaultEvent)) {//如果有默认事件标识且传入的事件标识与默认事件标识不相同则返回错误
+            HashMap<String, Object> errMap = new HashMap<>();
+            errMap.put("code", "-1");
+            errMap.put("message", "当前接口只支持event为" + defaultEvent + ",当前接收参数为:" + params);
+            return errMap;
+
+        }
+        Object serviceId = Objects.nonNull(queryId) && Objects.nonNull(queryId[0]) ? (Integer.parseInt(queryId[0]) + 10000) : params.get("serviceId");
+        if (Objects.isNull(serviceId) || !params.containsKey("event")) {
+            HashMap<String, Object> errMap = new HashMap<>();
+            errMap.put("code", "-1");
+            errMap.put("message", "缺失必要的参数:服务编号serviceId或事件标识event" + params);
+            return errMap;
+        }
+        //通过服务ID 查询对应服务的服务类型是否为1,如果时则继续,否则返回
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.REMOTE_DB_CONNECT);
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            HashMap<String, Object> errMap = new HashMap<>();
+            errMap.put("code", "-1");
+            errMap.put("message", "服务:" + serviceId + " 获取数据库对象失败,异常信息 " + myDbHelper.getErrorMessage());
+            return errMap;
+        }
+        Map<String, String> hasServiceMap = myDbHelper.queryForObject("select count(1) count from serviceinfo  where serviceID=? and serviceType = 1", serviceId);
+        if (hasServiceMap.get("code").equals("-1")) {
+            System.out.println("数据接受获取服务信息,查询失败: " + hasServiceMap.get("message"));
+            HashMap<String, Object> errMap = new HashMap<>();
+            errMap.put("code", "-1");
+            errMap.put("message", "数据接受获取服务信息,查询失败: " + hasServiceMap.get("message"));
+            return errMap;
+        }
+        String count = hasServiceMap.get("returnData");
+        if ("".equals(count) || "0".equals(count)) {
+            HashMap<String, Object> errMap = new HashMap<>();
+            errMap.put("code", "-1");
+            errMap.put("message", "服务:" + serviceId + "是采集服务不支持操作");
+            return errMap;
+        }
+        DataProcess dataProcessObj = ObjectMap.getordropInput(serviceId.toString(), true);//获取数据输出处理对象
+        if (null == dataProcessObj || !MapTools.isBlank(dataProcessObj.getErrorMessage())) {
+            HashMap<String, Object> errMap = new HashMap<>();
+            errMap.put("code", "-1");
+            errMap.put("message", "服务不可用:" + (null == dataProcessObj ? "" : dataProcessObj.getErrorMessage()));
+            return errMap;
+        }
+        return dataProcessObj.processData(params, token.get("user_id"));
+    }
+}

+ 15 - 11
mainFactory/src/main/java/org/bfkj/utils/MyDbHelper.java

@@ -95,6 +95,11 @@ public class MyDbHelper {//目前只差主键的条件优化
                     : (Objects.nonNull(calcInfo) && Objects.nonNull(calcInfo.get("event"))) ? calcInfo.get("event").toString() //优先算法定义的事件
                     : (Objects.nonNull(inputData) && Objects.nonNull(inputData.get("event"))) ? inputData.get("event").toString() : null;//否则上传参数的事件
             //-----入参检测
+
+            if (Objects.isNull(event) && MapTools.isNotBlank(sqlStr) && sqlStr.toLowerCase().contains(") union")) {
+                event = Objects.toString(calcInfo.get("event"));
+            }
+
             if (MapTools.isBlank(event) || (MapTools.isBlank(tableName) && MapTools.isBlank(sqlStr))) {//如果表名为空 且SQL为空则返回错误
                 return processFail("generalProcess函数: 表为空且SQL为空或事件为空", null, inParams);
             }
@@ -253,7 +258,7 @@ public class MyDbHelper {//目前只差主键的条件优化
     /*标准化SQL*/
     private String standarSQLStr(String sqlStr) {
         String newSqlStr = sqlStr;
-        String[] sqlKeyWordList = "select,from,where,group by,limit,order by".split(",",-1);
+        String[] sqlKeyWordList = "select,from,where,group by,limit,order by".split(",", -1);
         for (String sqlKeyWord : sqlKeyWordList) {//循环进行替换
             Pattern p = Pattern.compile(sqlKeyWord, Pattern.CASE_INSENSITIVE);
             Matcher m = p.matcher(newSqlStr);
@@ -285,10 +290,10 @@ public class MyDbHelper {//目前只差主键的条件优化
                 HashMap<String, Object> tempMap = new HashMap<>();
                 String columnName = rsd.getColumnName(i + 1);
                 String columnLabel = rsd.getColumnLabel(i + 1);
-                tempMap.put("columnName",Objects.isNull(columnLabel)? columnName:columnLabel);
+                tempMap.put("columnName", Objects.isNull(columnLabel) ? columnName : columnLabel);
                 tempMap.put("columnType", rsd.getColumnType(i + 1));
                 tempMap.put("columnTypeName", rsd.getColumnTypeName(i + 1));
-                tempMap.put("columnLable",Objects.isNull(columnLabel)? columnName:columnLabel );
+                tempMap.put("columnLable", Objects.isNull(columnLabel) ? columnName : columnLabel);
                 allColumnList.add(tempMap);
             }
             return processSuccess(allColumnList);
@@ -387,7 +392,7 @@ public class MyDbHelper {//目前只差主键的条件优化
 
     //根据sql语句获取表名:查询存在多层多表联合等复杂情况,暂时不支持
     private String getTableBySql(String sqlStr) {
-        String[] sqlSplit = sqlStr.split("\\s+",-1);//使用空格进行分组
+        String[] sqlSplit = sqlStr.split("\\s+", -1);//使用空格进行分组
         return sqlSplit.length < 3 ? null : sqlSplit[0].equals("insert") ? (sqlSplit[2].indexOf("(") > 0 ? sqlSplit[2].substring(0, sqlSplit[2].indexOf("(")) : sqlSplit[2])//insert into 表名(字段名)
                 : sqlSplit[0].equals("update") ? sqlSplit[1]//update 表名
                 : sqlSplit[0].equals("delete") ? sqlSplit[2] : null;//delete from 表名
@@ -460,7 +465,7 @@ public class MyDbHelper {//目前只差主键的条件优化
                 Object currentVar = valueObj.get(newColumnName);//优先从当前MAP中直接获取
 
                 if (columnName.startsWith(":")) {//处理in,只是书名号方式存在
-                    String[] varSplit = Objects.isNull(currentVar) ? null : currentVar.toString().split(",",-1);//使用逗号进行分组
+                    String[] varSplit = Objects.isNull(currentVar) ? null : currentVar.toString().split(",", -1);//使用逗号进行分组
                     if (Objects.isNull(varSplit)) {//
                         newSqlStr = newSqlStr.replaceFirst(columnName.concat("?"), "?"); //修订SQL
                     } else {
@@ -552,7 +557,6 @@ public class MyDbHelper {//目前只差主键的条件优化
     }
 
     //检测数据是否已经存在,使用同步锁(tableName,whereStr,filterList)
-
     private synchronized String isExist(String tableName, String whereStr, List<Object> dbFilter) {
         String event = "2";//默认为更新
         if (!AppConfig.event6Map.containsKey(tableName)) {//如果对应表名未建立缓存则初始化一个
@@ -565,9 +569,9 @@ public class MyDbHelper {//目前只差主键的条件优化
                 List<Map<String, Object>> isExistResult = theJdbcTemplate.queryForList("select 1 from ".concat(tableName).concat(" where ").concat(whereStr).concat(" limit 1"), dbFilter.toArray());
                 event = (isExistResult.size() == 0) ? "1" : event;//数据库不存在则新增
                 //如果是新增则修订为新增SQL
-               if (tableUniqe.size() > 3000){
-                   tableUniqe.clear();
-               }
+                if (tableUniqe.size() > 3000) {
+                    tableUniqe.clear();
+                }
                 tableUniqe.add(oldKey);//无论是新增还是更新都添加到缓存
             } catch (Exception e) {//查询失败并不更新缓存
                 //打印错误即可
@@ -690,7 +694,7 @@ public class MyDbHelper {//目前只差主键的条件优化
 
     //JDBC更新
     public Map<String, Object> JDBCBatch(String sqlStr, List<Object> dbValue, Object signParam) {
-        if ((sqlStr.startsWith("update") ||sqlStr.contains("?")) && (dbValue.size() == 0 || (dbValue.get(0) instanceof List<?> list && list.isEmpty()) )) {  //要求参数但是参数为空则返回
+        if ((sqlStr.startsWith("update") || sqlStr.contains("?")) && (dbValue.size() == 0 || (dbValue.get(0) instanceof List<?> list && list.isEmpty()))) {  //要求参数但是参数为空则返回
             return processSuccess(null);
         }
         Connection connection = null;
@@ -703,7 +707,7 @@ public class MyDbHelper {//目前只差主键的条件优化
 
                 Object[] signdbValue = ((List<Object>) dbValue.get(i)).toArray();
                 for (int index = 0; index < signdbValue.length; index++) {
-                    sqlPS.setObject(index + 1,signdbValue[index]);
+                    sqlPS.setObject(index + 1, signdbValue[index]);
                 }
                 sqlPS.addBatch();
                 if ((i + 1) % 10 == 0) {

+ 1 - 1
mainFactory/src/main/java/org/bfkj/utils/RandomGraphic.java

@@ -90,7 +90,7 @@ public class RandomGraphic {
         }
         shear(g2, w, h, c);// 使图片扭曲
         g2.setColor(getRandColor(100, 160));
-        int fontSize = h - 4;
+        int fontSize = h - 4; //
         Font font = new Font("Algerian", Font.ITALIC, fontSize);
         g2.setFont(font);
         char[] chars = code.toCharArray();