Browse Source

最新编码 并对sourceData进行控制

pms 1 năm trước cách đây
mục cha
commit
e928fdf9f6

+ 7 - 5
mainFactory/src/main/java/org/bfkj/MainFactoryApplication.java

@@ -2,10 +2,7 @@ package org.bfkj;
 
 import org.bfkj.application.DataProcess;
 import org.bfkj.application.ServiceInputControl;
-import org.bfkj.config.AppConfig;
-import org.bfkj.config.ObjectMap;
-import org.bfkj.config.RemoteDB;
-import org.bfkj.config.RemoteLogDB;
+import org.bfkj.config.*;
 import org.bfkj.utils.LogUtils;
 import org.bfkj.utils.MapTools;
 import org.bfkj.utils.MyDbHelper;
@@ -36,9 +33,12 @@ public class MainFactoryApplication implements InitializingBean {
     private RemoteDB remoteDB;
     private RemoteLogDB remoteLogDB;
 
-    public MainFactoryApplication(RemoteDB remoteDB, RemoteLogDB remoteLogDB) {
+    private final BaseConfig baseConfig;
+
+    public MainFactoryApplication(RemoteDB remoteDB, RemoteLogDB remoteLogDB, BaseConfig baseConfig) {
         this.remoteDB = remoteDB;
         this.remoteLogDB = remoteLogDB;
+        this.baseConfig = baseConfig;
     }
 
     /*服务初始化: 启动服务*/
@@ -289,6 +289,8 @@ public class MainFactoryApplication implements InitializingBean {
             maplogDB.put("driver-class-name", maplogDB.get("driverClassName"));
             AppConfig.REMOTE_DB_LOG_CONNECT = MapTools.objToJSONStr(maplogDB);
             AppConfig.serviceURL = remoteDB.getServiceURL();
+            AppConfig.SOURCE_DATA = baseConfig.getSourceData();
+
         } catch (Exception e) {
             System.out.println("配置文件中,连接数据库信息错误");
         }

+ 42 - 22
mainFactory/src/main/java/org/bfkj/api/CommonApi.java

@@ -13,6 +13,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import java.io.InputStream;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 
@@ -52,12 +53,17 @@ 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")) {
-            params.put("serviceId",params.get("id"));
-            params.put("event", "0");
-            params.remove("id");
+            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");
         }
-        return commonInterface(token, params, "0");
+        return stringObjectMap;
     }
+
     /**
      * 新增入口CRUD
      */
@@ -92,22 +98,25 @@ public class CommonApi {
      * 统一接收处理
      */
     private Map<String, Object> commonInterface(Map<String, String> token, Map<String, Object> params, String defaultEvent) {
-        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;
+        if (!params.containsKey("id")) {
+            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;
+                }
+                params.remove("id");
+            } 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");//获取参数中的事件标识
@@ -164,13 +173,24 @@ public class CommonApi {
 
 
     @PostMapping("/upload")
-    public Object upload(@RequestParam(value = "file") MultipartFile excelFile, @RequestParam(value = "serviceId") String serviceID, @RequestParam(value = "token") String token) throws Exception {
+    public Object upload(@RequestParam(value = "file") MultipartFile excelFile, @RequestParam(value = "serviceId") String serviceID ,@RequestHeader Map<String,Object> requestHeader) throws Exception {
         if (excelFile.isEmpty()) {
             return MapTools.processFail("文件夹为空,重新上传");
         } else {
+            String userName = "";
+            if (requestHeader.containsKey("user_id")){
+                MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.REMOTE_DB_CONNECT);
+                Map<String, Object> userId = myDbHelper.queryByParamsReturnList("SELECT user_name FROM t_user  WHERE user_id = ?", Objects.toString(requestHeader.get("user_id")));
+                Object o = userId.get("returnData");
+                if (o instanceof List<?> tpList  && !tpList.isEmpty() && tpList.get(0) instanceof Map currentMap ){
+                    userName = Objects.toString(currentMap.get("user_name"));
+                }
+
+            }
+
             String fileName = excelFile.getOriginalFilename();
             InputStream is = excelFile.getInputStream();
-            Map<String, Object> uploadFile = importExcelUtils.upload(fileName, is);
+            Map<String, Object> uploadFile = importExcelUtils.upload(fileName, is,userName);
             if ("-1".equals(uploadFile.get("code"))) {
                 return uploadFile;
             }

+ 2 - 0
mainFactory/src/main/java/org/bfkj/config/AppConfig.java

@@ -20,6 +20,8 @@ public class AppConfig {
 
     public static HashMap<String, HashSet<Object>> event6Map = new HashMap<>();//用于事件6是否存在的内存检测
 
+    public static String SOURCE_DATA="";
+
     public static HashMap<String, String> staticEvent = new HashMap<>() {{
         put("select", "0");
         put("update", "2");

+ 25 - 0
mainFactory/src/main/java/org/bfkj/config/BaseConfig.java

@@ -0,0 +1,25 @@
+package org.bfkj.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+
+/**
+ * @author Administrator
+ * 特殊配置处理
+ */
+@Component
+@ConfigurationProperties(prefix = "baseConfig")
+public class BaseConfig {
+    @Value("${baseConfig.sourceData}")
+    private String sourceData;
+
+    public String getSourceData() {
+        return sourceData;
+    }
+
+    public void setSourceData(String sourceData) {
+        this.sourceData = sourceData;
+    }
+}

+ 35 - 31
mainFactory/src/main/java/org/bfkj/protocol/WebAPI.java

@@ -19,7 +19,7 @@ public class WebAPI {
     private HttpHeaders webApiHeader;
     private String webapiMethod;
 
-    private Map<String,Object> baseHeader = new HashMap<>();
+    private Map<String, Object> baseHeader = new HashMap<>();
 
     /**
      * webapi 执行入口函数
@@ -27,10 +27,10 @@ public class WebAPI {
     public Map<String, Object> execWebApi(Object header, String method, Object defaultBody, String connectConfig) {
         Map<String, Object> connectConfigMaps = (Map<String, Object>) MapTools.strToObj(connectConfig);
         Map<String, Object> restTemplateResult = initWebApiParams(connectConfigMaps); // 通过连接配置 获取restTemplate
-        if (!restTemplateResult.get("code").equals("0")) {
+
+        if (!"0".equals(restTemplateResult.get("code"))) {
             return MapTools.processFail(restTemplateResult.get("message").toString());
         }
-
         if (header instanceof Map) {
             Map<String, Object> temeMap = (Map) header;
             if (!temeMap.isEmpty()) {
@@ -82,40 +82,44 @@ public class WebAPI {
     }
 
     public Map<String, Object> initWebApiParams(Map<String, Object> connectConfig) {
-        if (restTemplate == null) {
-            if (Objects.isNull(connectConfig)) {
-                return MapTools.processFail("webapi请求配置参数为空");
-            }
-            webapiURL = Objects.nonNull(connectConfig.get("url")) ? connectConfig.get("url").toString() : null;
-            if (Objects.isNull(webapiURL)) {
-                return MapTools.processFail("webapi请求地址为空");
-            }
-            Object tempHeaders = connectConfig.get("headers"); //需确定返回的是一个map对象还是字符串  headers: {ContentType:"JSON"}
-            webApiHeader = new HttpHeaders();
-            if (Objects.isNull(tempHeaders)) {
-                webApiHeader.setContentType(MediaType.APPLICATION_JSON);
-            }
-            if (tempHeaders instanceof Map) {
-                baseHeader = (Map) tempHeaders;
-                if (!baseHeader.isEmpty()) {
-                    for (String key : baseHeader.keySet()) {
-                        webApiHeader.add(key, baseHeader.get(key).toString());
+        try {
+            if (restTemplate == null) {
+                if (Objects.isNull(connectConfig)) {
+                    return MapTools.processFail("webapi请求配置参数为空");
+                }
+                webapiURL = Objects.nonNull(connectConfig.get("url")) ? connectConfig.get("url").toString() : null;
+                if (Objects.isNull(webapiURL)) {
+                    return MapTools.processFail("webapi请求地址为空");
+                }
+                Object tempHeaders = connectConfig.get("headers"); //需确定返回的是一个map对象还是字符串  headers: {ContentType:"JSON"}
+                webApiHeader = new HttpHeaders();
+                if (Objects.isNull(tempHeaders)) {
+                    webApiHeader.setContentType(MediaType.APPLICATION_JSON);
+                }
+                if (tempHeaders instanceof Map) {
+                    baseHeader = (Map) tempHeaders;
+                    if (!baseHeader.isEmpty()) {
+                        for (String key : baseHeader.keySet()) {
+                            webApiHeader.add(key, baseHeader.get(key).toString());
+                        }
                     }
                 }
-            }
-            Object webMethod = connectConfig.get("method"); //需确定返回的是一个map对象还是字符串  headers: {ContentType:"JSON"}
-            if (Objects.nonNull(webMethod)) {
-                webapiMethod = webMethod.toString().toLowerCase();
-            } else {
-                webapiMethod = "post";
-            }
+                Object webMethod = connectConfig.get("method"); //需确定返回的是一个map对象还是字符串  headers: {ContentType:"JSON"}
+                if (Objects.nonNull(webMethod)) {
+                    webapiMethod = webMethod.toString().toLowerCase();
+                } else {
+                    webapiMethod = "post";
+                }
 //            HttpComponentsClientHttpRequestFactory httpComponentsClientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory();
 //            httpComponentsClientHttpRequestFactory.setConnectTimeout(6000);
 //            httpComponentsClientHttpRequestFactory.setConnectionRequestTimeout(6000);
-            restTemplate = new RestTemplate();
-            restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
+                restTemplate = new RestTemplate();
+                restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
+            }
+        } catch (Exception e) {
+                   return MapTools.processFail(LogUtils.getException(e));
         }
-        return MapTools.processSuccess(restTemplate);
+        return MapTools.processSuccess(null);
     }
 
     /**

+ 23 - 6
mainFactory/src/main/java/org/bfkj/utils/DataFormat.java

@@ -1,6 +1,7 @@
 package org.bfkj.utils;
 
 
+import org.bfkj.config.AppConfig;
 import org.bfkj.config.ObjectMap;
 import org.dom4j.Attribute;
 import org.dom4j.Document;
@@ -140,7 +141,9 @@ public class DataFormat {
                         HashMap<String, Object> errorMap = new HashMap<>();
                         errorMap.put("dataObjectId", dataObjectId);
                         errorMap.put("errMessage", "报文数据格式错误");
-                        errorMap.put("sourceData", tempTypeStr);
+                        if ("true".equals(AppConfig.SOURCE_DATA)){
+                            errorMap.put("sourceData", tempTypeStr);
+                        }
                         if (!returnDataList.contains(errorMap)) {
                             returnDataList.add(errorMap);
                         }
@@ -151,7 +154,10 @@ public class DataFormat {
                 Map<String, Object> signDataMap = new HashMap<>();//创建一个当前报文的MAP
                 signDataMap.put("dataType", dataType);//默认报文类型
                 signDataMap.put("dataObjectId", dataObjectId); //默认生命周期ID
-                signDataMap.put("sourceData", signData); //默认原始报文--因为要记录完整的原始报文,所以不去头不去尾
+//                signDataMap.put("sourceData", signData); //默认原始报文--因为要记录完整的原始报文,所以不去头不去尾
+                if ("true".equals(AppConfig.SOURCE_DATA)){
+                    signDataMap.put("sourceData", signData);
+                }
                 String[] rowDataList = signData.split("(?=\\.[A-Z]{1}\\/)", -1);//使用.字母/进行分组,获得行数据
                 //获取第一行的数据:第一行,BPM为空,BSM直接使用indexOf判断即可
                 signDataMap.put("dataState", dataType.equals("BSM") ? (rowDataList[0].contains("DEL") ? "DEL" : (rowDataList[0].contains("CHG") ? "CHG" : "ADD")) : null);
@@ -342,7 +348,9 @@ public class DataFormat {
             HashMap<String, Object> errorMap = new HashMap<>();
             errorMap.put("dataObjectId", dataObjectId);
             errorMap.put("errMessage", "报文数据格式错误");
-            errorMap.put("sourceData", typeStr);
+            if ("true".equals(AppConfig.SOURCE_DATA)){
+                errorMap.put("sourceData", typeStr);
+            }
             returnDataList.add(errorMap);
         }
         return returnDataList;
@@ -525,11 +533,17 @@ public class DataFormat {
             Document doc = DocumentHelper.parseText(xmlStr);
             Element root = doc.getRootElement();
             Map<String, Object> returnMap = xmlToMap(root);
-            returnMap.put("souceData", xml);
+//            returnMap.put("souceData", xml);
+            if ("true".equals(AppConfig.SOURCE_DATA)){
+                returnMap.put("sourceData", xml);
+            }
             return processSuccess(returnMap);
         } catch (Exception e) {
             Map<String, Object> errMap = processFail("入参不是规则的xml :" + xml);
-            errMap.put("souceData", xml);
+//            errMap.put("souceData", xml);
+            if ("true".equals(AppConfig.SOURCE_DATA)){
+                errMap.put("sourceData", xml);
+            }
             return errMap;
         }
     }
@@ -553,7 +567,10 @@ public class DataFormat {
             return xmlList instanceof List<?> ? MapTools.processSuccess(rsList) : rsList.get(0);
         } catch (Exception e) {
             Map<String, Object> errMap = processFail("入参不是规则的xml");
-            errMap.put("souceData", xmlList);
+//            errMap.put("souceData", xmlList);
+            if ("true".equals(AppConfig.SOURCE_DATA)){
+                errMap.put("sourceData", xmlList);
+            }
             return errMap;
         }
     }

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

@@ -15,7 +15,7 @@ public class ImportExcelUtils {
 
 
     // 将表格中的数据添加到List集合中
-    public Map<String, Object> upload(String fileName, InputStream is) {
+    public Map<String, Object> upload(String fileName, InputStream is, String userName) {
         String dataObjectId = System.currentTimeMillis() +"";
         try {
             File file = new File(System.getProperty("user.dir") + File.separator + "upload" + File.separator + System.currentTimeMillis() + "_" + fileName);
@@ -46,6 +46,7 @@ public class ImportExcelUtils {
                         Date now2 = Calendar.getInstance().getTime();
                         tempMap.put("createtime",format1.format(now2));
                         tempMap.put("dataObjectId",dataObjectId);
+                        tempMap.put("userName",userName);
                         if (tempMap.keySet().size() > 2){
                             tempMapList.add(tempMap);
                         }

+ 5 - 13
mainFactory/src/main/resources/application-prod.yml

@@ -16,25 +16,16 @@ spring:
       suffix: .html
 
 log:
-  url: jdbc:mysql://10.211.66.16:3163/DPFBLOG
+  url: jdbc:mysql://120.26.64.82:3306/yq_2.0
   title: root
-  cipher: QtrmuqDw^bJu$
+  cipher: 123@bigdata
   type: com.mysql.cj.jdbc.Driver
-
-#mydb:
-#  url: ${MYDB_URL:jdbc:mysql://rm-bp12c6mmk845m73p48o.mysql.rds.aliyuncs.com:3306/test_cen}
-#  title: ${MYDB_USER:bf_dev_epi}
-#  cipher: ${MYDB_PASSWD:Bfepi2021(}
-#  type: ${MYDB_DRIVER:com.mysql.cj.jdbc.Driver}
-#  serviceURL: ${MY_SERVICE_URL:127.0.0.99:00}
-
-
 mydb:
   url: ${MYDB_URL:jdbc:mysql://10.211.66.16:3163/DISACenter_2}
   title: ${MYDB_USER:root}
   cipher: ${MYDB_PASSWD:QtrmuqDw^bJu$}
   type: ${MYDB_DRIVER:com.mysql.cj.jdbc.Driver}
-  serviceURL: ${MY_SERVICE_URL:127.0.0.99:00}
+  serviceURL: ${MY_SERVICE_URL:127.0.0.1:8080}
 
 #isEs:
 #  open: true
@@ -46,6 +37,8 @@ mydb:
 #  password: ""
 #  successIndexName: "success_log_center2"
 #  errorIndexName: "error_log_center2"
+baseConfig:
+  sourceData : true
 
 isEs:
   open: false
@@ -58,7 +51,6 @@ isEs:
   successIndexName: "success_log_center"
   errorIndexName: "error_log_center"
 
-
 service:
   pool:
     maxPoolSize: 512

+ 50 - 0
mainFactory/src/main/resources/application-zxx.yml

@@ -0,0 +1,50 @@
+server:
+  port: ${PORT:8046}
+  servlet:
+    encoding:
+      charset: UTF-8
+      force: true
+      enabled: true
+  codec:
+    max-in-memory-size: -1
+  application:
+    name: mainFactory
+spring:
+  mvc:
+    view:
+      prefix: /
+      suffix: .html
+
+log:
+  url: jdbc:mysql://10.199.7.11:3306/DPFBLOG
+  title: bigdata
+  cipher: ml9*pO4866
+  type: com.mysql.cj.jdbc.Driver
+
+mydb:
+  url: ${MYDB_URL:jdbc:mysql://10.199.7.11:3306/DISACenter_2}
+  title: ${MYDB_USER:bigdata}
+  cipher: ${MYDB_PASSWD:ml9*pO4866}
+  type: ${MYDB_DRIVER:com.mysql.cj.jdbc.Driver}
+  serviceURL: ${MY_SERVICE_URL:10.199.1.11:8046}
+
+isEs:
+  open: false
+  scheme: http
+  hostname: 10.211.67.175
+  port: 9201
+  auth: true
+  username: "elastic"
+  password: "TUihk5^a0J+GkI4!4"
+  successIndexName: "success_log_center"
+  errorIndexName: "error_log_center"
+
+
+service:
+  pool:
+    maxPoolSize: 512
+    corePoolSize: 6
+    queueCapacity: 1024
+    keepAliveSeconds: 60
+    threadNamePrefix: logthreadpool
+    waitForTasksToCompleteOnShutdown: true