Browse Source

清理代码

andy 1 year ago
parent
commit
f185843859

+ 54 - 49
mainFactory/src/main/java/org/bfkj/MainFactoryApplication.java

@@ -8,6 +8,7 @@ import org.bfkj.utils.MapTools;
 import org.bfkj.utils.MyDbHelper;
 import org.bfkj.utils.ScheduleUtil;
 import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@@ -18,6 +19,8 @@ import org.springframework.scheduling.annotation.Scheduled;
 
 import java.io.File;
 import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /**
  * 初始化
@@ -27,25 +30,27 @@ import java.util.*;
 @EnableScheduling
 public class MainFactoryApplication implements InitializingBean {
 
-    private final String INSERT_SQL = "INSERT INTO log_success ( success, location, logContent, createtime, serviceId, workId, event, iNDataContent, outDataContent, calculationLocation, dataObjectId) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
-    private final String ERROR_SQL = "INSERT INTO log_error ( success, location, logContent, createtime, serviceId, workId, event, iNDataContent, outDataContent, calculationLocation, dataObjectId) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
+    private static final Logger logger = Logger.getLogger(MainFactoryApplication.class.getName());
+
+    private static final String INSERT_SQL = "INSERT INTO log_success ( success, location, logContent, createtime, serviceId, workId, event, iNDataContent, outDataContent, calculationLocation, dataObjectId) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
+    private static final String ERROR_SQL = "INSERT INTO log_error ( success, location, logContent, createtime, serviceId, workId, event, iNDataContent, outDataContent, calculationLocation, dataObjectId) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
 
     private RemoteDB remoteDB;
     private RemoteLogDB remoteLogDB;
 
-    private final BaseConfig baseConfig;
+    @Value("${baseConfig.sourceData:true}")
+    private boolean enableSourceData;
 
-    public MainFactoryApplication(RemoteDB remoteDB, RemoteLogDB remoteLogDB, BaseConfig baseConfig) {
+    public MainFactoryApplication(RemoteDB remoteDB, RemoteLogDB remoteLogDB) {
         this.remoteDB = remoteDB;
         this.remoteLogDB = remoteLogDB;
-        this.baseConfig = baseConfig;
     }
 
     /*服务初始化: 启动服务*/
     public static void main(String[] args) {
         String path = System.getProperty("user.dir"); //获取当前项目的路径
         if (!checkFileDir(path)) {
-            System.out.println("配置文件夹检测失败");
+            logger.log(Level.SEVERE, "配置文件夹检测失败");
             return;
         }
         /*获取初始地址*/
@@ -55,32 +60,28 @@ public class MainFactoryApplication implements InitializingBean {
         String systemParams = env.getProperty("systemParams");
         if (Objects.nonNull(systemParams) && !"".equals(systemParams)) {
             Map<String, Object> inSystemParams = (Map<String, Object>) MapTools.strToObj(systemParams);
-            for (String key : inSystemParams.keySet()) {
+            inSystemParams.keySet().forEach(key -> {
                 String keyValue = inSystemParams.get(key).toString().replace("path", path);
-                if (Objects.isNull(MapTools.strToObj(keyValue))) {
-                    systemDefaultParams.put(key, keyValue);
-                } else {
-                    systemDefaultParams.put(key, keyValue);
-                }
-            }
+                systemDefaultParams.put(key, keyValue);
+            });
             /*设置远程连接、服务地址*/
             AppConfig.serviceURL = systemDefaultParams.get("serviceURL");
             AppConfig.REMOTE_DB_CONNECT = systemDefaultParams.get("remote_db_connect");
         }
         MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.REMOTE_DB_CONNECT);
         if (Objects.nonNull(myDbHelper.getErrorMessage())) {
-            System.out.println("初始化获取MyDbHelper对象异常");
+            logger.log(Level.SEVERE, "初始化获取MyDbHelper对象异常");
             return;
         }
         if (!initDB(myDbHelper)) {
-            System.out.println("初始化远程数据库失败");
+            logger.log(Level.SEVERE, "初始化远程数据库失败");
             return;
         }
         Runtime.getRuntime().addShutdownHook(new Thread(MainFactoryApplication::currentWorkExit));
         try {
             Map<String, String> hasDeployNodeIDMap = myDbHelper.queryForObject("select Max(deployNodeID) from deploynode where serviceURL = ? ", AppConfig.serviceURL);
-            if (hasDeployNodeIDMap.get("code").equals("-1")) {
-                System.out.println("初始化获取机器表信息: 执行SQL失败 " + hasDeployNodeIDMap.get("message"));
+            if ("-1".equals(hasDeployNodeIDMap.get("code"))) {
+                logger.log(Level.SEVERE, "初始化获取机器表信息: 执行SQL失败 %s".formatted(hasDeployNodeIDMap.get("message")));
                 return;
             }
             String workID = hasDeployNodeIDMap.get("returnData");
@@ -88,40 +89,41 @@ public class MainFactoryApplication implements InitializingBean {
                 AppConfig.WORK_ID = workID;
             } else {
                 Map<String, String> returnKeyValues = myDbHelper.insertReturnKeyValues("insert into deploynode(serviceURL)  values(?)", AppConfig.serviceURL);
-                if (returnKeyValues.get("code").equals("-1")) {
-                    System.out.println("根据serviceURL新增入库失败: " + ("insert into deploynode(serviceURL)  values(?)") + " 参数: " + AppConfig.serviceURL);
+                if ("-1".equals(returnKeyValues.get("code"))) {
+                    logger.log(Level.SEVERE, "根据serviceURL新增入库失败: " + ("insert into deploynode(serviceURL)  values(?)") + " 参数: " + AppConfig.serviceURL);
                     return;
                 }
                 AppConfig.WORK_ID = returnKeyValues.get("returnData");
                 if (!MapTools.isNumber(AppConfig.WORK_ID)) {
-                    System.out.println("初始化workID异常: " + AppConfig.WORK_ID);
+                    logger.log(Level.SEVERE, "初始化workID异常: " + AppConfig.WORK_ID);
                     return;
                 }
             }
         } catch (Exception e) {
-            System.out.println("初始化workID异常: " + LogUtils.getException(e));
+            logger.log(Level.SEVERE, "初始化workID异常: " + LogUtils.getException(e));
             return;
         }
 
         Map<String, Object> serviceListResult = myDbHelper.queryByParamsReturnList("SELECT serviceID,serviceType FROM serviceinfo WHERE workId = ?", AppConfig.WORK_ID);
         List<Map<String, Object>> serviceList = MapTools.getMapList(serviceListResult);
-        if (!serviceListResult.get("code").equals("0") || null == serviceList) {
-            System.out.println("初始化获取服务异常: " + serviceListResult.get("message"));
+        if (!"0".equals(serviceListResult.get("code")) || null == serviceList) {
+            logger.log(Level.SEVERE, "初始化获取服务异常: " + serviceListResult.get("message"));
             return;
         }
         int autoCount = 0;
         for (Map<String, Object> map : serviceList) {
             // 开启一个线程,启动主动采集
             Object threadsObj = map.get("serviceType");
-            if (Objects.nonNull(threadsObj) && threadsObj.toString().equals("4")) {
+            if (Objects.nonNull(threadsObj) && "4".equals(threadsObj.toString())) {
                 autoCount++;
                 Map<String, Object> requestParams = new HashMap<>();
                 requestParams.put("serviceId", map.get("serviceID").toString());
                 ServiceInputControl.startOrStop(requestParams, "1");
             }
         }
-        System.out.println("本机共部署服务个数:" + serviceList.size() + ",启动主动采集个数:" + autoCount);
+        logger.log(Level.INFO, "本机共部署服务个数:" + serviceList.size() + ",启动主动采集个数:" + autoCount);
     }
+
     /**
      * 获取系统默认参数
      *
@@ -144,73 +146,74 @@ public class MainFactoryApplication implements InitializingBean {
         //关闭数据库连接
         ObjectMap.getordropMyDbHelper(AppConfig.REMOTE_DB_CONNECT).close();
         ObjectMap.getordropMyDbHelper(AppConfig.REMOTE_DB_LOG_CONNECT).close();
-        System.out.println("系统正常退出");
+        logger.log(Level.INFO, "系统正常退出");
     }
 
     /*创建文件夹*/
     private static boolean checkFileDir(String path) {
         //初始化默认文件创建
-        List<String> pathList = new ArrayList<>() {{
-            add("cache");
-            add("plugins");
-            add("ftp");
-            add("upload");
-            add("log");
-        }};
+        List<String> pathList = new ArrayList<>();
+        pathList.add("cache");
+        pathList.add("plugins");
+        pathList.add("ftp");
+        pathList.add("upload");
+        pathList.add("log");
+
         for (String paths : pathList) {
             /*创建文件夹*/
             File pluginPath = new File(path + File.separator + paths);
             if (!pluginPath.exists() && !pluginPath.mkdir()) {
-                //todo 系统目录或配置文件检测失败
+                // 系统目录或配置文件检测失败
                 return false;
             }
         }
         return true;
     }
+
     public static boolean initDB(MyDbHelper myDbHelper) {
 
         Map<String, String> hasAppMap = myDbHelper.queryForObject("select count(1) hasCount  from t_application where app_id =?", "1");
-        if (hasAppMap.get("code").equals("-1")) {
+        if ("-1".equals(hasAppMap.get("code"))) {
             System.out.println("初始化数据库 查询应用信息,查询失败: " + hasAppMap.get("message"));
             return false;
         }
         String hasApp = hasAppMap.get("returnData");
-        if (MapTools.isBlank(hasApp) || hasApp.equals("0")) {
+        if (MapTools.isBlank(hasApp) || "0".equals(hasApp)) {
             myDbHelper.execute("ALTER TABLE `t_application` AUTO_INCREMENT=1;");
             myDbHelper.execute("INSERT INTO `t_application` (`app_name`, `app_show_id`, `app_show_secret`, `app_code_rule`) VALUES ('底座', 'q7kdjmmaf0kerwpf', '9inu7zpllz1folzsljm498dcpi0lsog1', 'N2');");
         }
 
         Map<String, String> hasUserApp = myDbHelper.queryForObject("select count(1) hasUser  from t_user where user_id =?", "1");
-        if (hasUserApp.get("code").equals("-1")) {
+        if ("-1".equals(hasUserApp.get("code"))) {
             System.out.println("初始化数据库 查询用户信息信息,查询失败: " + hasAppMap.get("message"));
             return false;
         }
         String hasUser = hasUserApp.get("returnData");
-        if (MapTools.isBlank(hasUser) || hasUser.equals("0")) {
+        if (MapTools.isBlank(hasUser) || "0".equals(hasUser)) {
             myDbHelper.execute("ALTER TABLE `t_user` AUTO_INCREMENT=1;");
             myDbHelper.execute("INSERT INTO `t_user` (`user_name`, `user_pwd`) VALUES ( 'zhaoke', 'cab264992e7cf0de822013e569a0fec5');");
         }
 
         Map<String, String> hasAuthApp = myDbHelper.queryForObject("select count(1) hasAuth  from t_auth");
-        if (hasAuthApp.get("code").equals("-1")) {
+        if ("-1".equals(hasAuthApp.get("code"))) {
             System.out.println("初始化数据库 查询权限信息信息,查询失败: " + hasAppMap.get("message"));
             return false;
         }
         String hasAuth = hasAuthApp.get("returnData");
-        if (MapTools.isBlank(hasAuth) || hasAuth.equals("0")) {
+        if (MapTools.isBlank(hasAuth) || "0".equals(hasAuth)) {
             myDbHelper.execute("ALTER TABLE `t_auth` AUTO_INCREMENT=1;");
             myDbHelper.execute("INSERT INTO `t_auth` (`app_id`, `auth_name`, `auth_type`, `up_auth_id`, `auth_ident`, `auth_status`, `auth_comment`, `show_type`, `show_icon`, `show_index`, `is_link`, `route_info`, `file_link`, `queryTemplateID`, `is_show`, `code`, `queryparams`) VALUES (1, '系统设置', 1, NULL, 'systemSetting', NULL, NULL, 1, NULL, NULL, NULL, '/systemSetting', NULL, NULL, 1, NULL, NULL);");
         }
 
         Map<String, String> hasServiceApp = myDbHelper.queryForObject("select count(1) hasService  from serviceinfo");
-        if (hasServiceApp.get("code").equals("-1")) {
+        if ("-1".equals(hasServiceApp.get("code"))) {
             System.out.println("初始化数据库 查询用户信息信息,查询失败: " + hasAppMap.get("message"));
             return false;
         }
 
         //初始化服务
         String hasService = hasServiceApp.get("returnData");
-        if (MapTools.isBlank(hasService) || hasService.equals("0")) {
+        if (MapTools.isBlank(hasService) || "0".equals(hasService)) {
             myDbHelper.execute("ALTER TABLE `serviceinfo` AUTO_INCREMENT=1;");
             myDbHelper.execute("INSERT INTO `serviceinfo` (`serviceName`, `serviceDescribe`, `serviceType`) VALUES ( '获取全部权限', '获取全部权限', 1);");
         }
@@ -226,9 +229,9 @@ public class MainFactoryApplication implements InitializingBean {
 
     @Scheduled(cron = "0 15 * * * ?")
     public void closeObject() {
-        long timeOut = 15 * 1000 * 60;
+        long timeOut = 15L * 1000 * 60;
         Collection<DataProcess> tpList = ObjectMap.dataProcessMaps.values();
-        for (DataProcess dataProcess : tpList ) {
+        for (DataProcess dataProcess : tpList) {
             if (System.currentTimeMillis() - dataProcess.getLastActive() > timeOut) {
                 String serviceId = dataProcess.getServiceId();
                 ObjectMap.getordropInput(serviceId, false);
@@ -238,7 +241,7 @@ public class MainFactoryApplication implements InitializingBean {
 
 
     /*1每一分钟手动释放资源*/
-    @Scheduled(cron = "0 1 * * * ?")
+//    @Scheduled(cron = "0 */1 * * * ?")
     public void clearGc() {
         Runtime.getRuntime().gc();
     }
@@ -249,7 +252,9 @@ public class MainFactoryApplication implements InitializingBean {
         Map<String, List<Object>> logSuccessMap = LogUtils.logSuccessMapList;
         Map<String, List<Object>> logErrorMap = LogUtils.logErrorMapList;
         /*批量写日志*/
-        if (logSuccessMap.size() == 0 && logErrorMap.size() == 0) return;
+        if (logSuccessMap.size() == 0 && logErrorMap.size() == 0) {
+            return;
+        }
         long current = System.currentTimeMillis();
         List<String> successList = logSuccessMap.keySet().stream().filter(key -> Long.parseLong(key) < current).toList();
         List<Object> logSuccessList = new ArrayList<>();
@@ -270,8 +275,8 @@ public class MainFactoryApplication implements InitializingBean {
         }
 
         try {
-            if (logSuccessList.size() > 0) logDbHelper.JDBCBatch(INSERT_SQL, logSuccessList, null);
-            if (logErrorList.size() > 0) logDbHelper.JDBCBatch(ERROR_SQL, logErrorList, null);
+            logDbHelper.JDBCBatch(INSERT_SQL, logSuccessList, null);
+            logDbHelper.JDBCBatch(ERROR_SQL, logErrorList, null);
         } catch (Exception e) {
             System.out.println("日志记录异常" + LogUtils.getException(e));
         }
@@ -289,7 +294,7 @@ 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();
+            AppConfig.SOURCE_DATA = enableSourceData;
 
         } catch (Exception e) {
             System.out.println("配置文件中,连接数据库信息错误");

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

@@ -21,34 +21,34 @@ public class AuthManageApi {
     AuthApplicationImpl authApplication;
 
     @PostMapping("getToken")
-    public Object getToken(@RequestBody Map<String, String> params, HttpServletRequest httpServletRequest) {
+    public Object getToken(@RequestBody Map<String, String> body, HttpServletRequest httpServletRequest) {
         String sessionID = httpServletRequest.getSession().getId();
-        return authApplication.getToken(params, sessionID);
+        return authApplication.getToken(body, sessionID);
     }
 
     @PostMapping("application-token")
-    public Object application_token(@RequestBody Map<String, String> params, HttpServletRequest httpServletRequest) {
+    public Object applicationToken(@RequestBody Map<String, String> body, HttpServletRequest httpServletRequest) {
         String sessionID = httpServletRequest.getSession().getId();
-        Map rsData =  (Map)authApplication.getToken(params, sessionID);
+        Map rsData = (Map) authApplication.getToken(body, sessionID);
         HashMap<String, Object> rsMap = new HashMap<>();
+        var message = "message";
         try {
-            rsMap.put("code",rsData.get("code"));
+            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"));
+            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) {
-        return authApplication.refreshToken(params);
+    public Object refreshToken(@RequestBody Map<String, String> body) {
+        return authApplication.refreshToken(body);
     }
 
     /**
@@ -57,7 +57,7 @@ public class AuthManageApi {
      * @param params {appId:"",token:""}
      * @return 验证码执行结果信息
      */
-    @PostMapping("getVCode") //todo getVCode()
+    @PostMapping("getVCode")
     public Object getVCode(@RequestBody Map<String, Object> params) {
         return authApplication.getVCode(params);
     }
@@ -72,14 +72,15 @@ public class AuthManageApi {
     public Map<String, Object> signIn(@RequestBody Map<String, String> data) {
         return authApplication.signIn(data);
     }
+
     @PostMapping("loginOut")
-    public Map<String, Object>loginOut(@RequestBody Map<String, String> params) {
-        return authApplication.loginOut(params);
+    public Map<String, Object> loginOut(@RequestBody Map<String, String> body) {
+        return authApplication.loginOut(body);
     }
 
     @PostMapping("getAuth")
-    public Map<String, Object> getAuth(@RequestBody Map<String, String> params) {
-        return authApplication.getAuth(params);
+    public Map<String, Object> getAuth(@RequestBody Map<String, String> body) {
+        return authApplication.getAuth(body);
     }
 
 

+ 19 - 17
mainFactory/src/main/java/org/bfkj/api/CommonApi.java

@@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.HashMap;
 import java.util.List;
@@ -33,13 +34,14 @@ public class CommonApi {
     /**
      * 服务数据恢复 : 因为日志的数据内容拆分为4个字段,所有此方法需要调整可
      */
-    @RequestMapping("abnormalDataRecovery")
-    public Map<String, Object> abnormalDataRecovery(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
-        String verificationToke = authApplication.verificationUserToken(token);
+    @PostMapping("abnormalDataRecovery")
+    public Map<String, Object> abnormalDataRecovery(@RequestHeader Map<String, String> headers, @RequestBody Map<String, Object> params) {
+        String verificationToke = authApplication.verificationUserToken(headers);
         if (!MapTools.isBlank(verificationToke)) {
             HashMap<String, Object> errMap = new HashMap<>();
             errMap.put("code", "-1");
-            errMap.put("message", "用户令牌验证失败:" + verificationToke);
+            String message = "message";
+            errMap.put(message, "用户令牌验证失败:" + verificationToke);
             return errMap;
         }
         return authApplication.abnormalDataRecovery(params);
@@ -50,16 +52,16 @@ public class CommonApi {
      */
     @PostMapping("query")
     @ResponseBody
-    public Object queryApi(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
+    public Object queryApi(@RequestHeader Map<String, String> headers, @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");
+            stringObjectMap = commonInterface(headers, callBack, "0");
         } else {
-            stringObjectMap = commonInterface(token, params, "0");
+            stringObjectMap = commonInterface(headers, params, "0");
         }
         return stringObjectMap;
     }
@@ -69,8 +71,8 @@ public class CommonApi {
      */
     @PostMapping("newdata")
     @ResponseBody
-    public Object newDataApi(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
-        return commonInterface(token, params, "1");
+    public Object newDataApi(@RequestHeader Map<String, String> headers, @RequestBody Map<String, Object> params) {
+        return commonInterface(headers, params, "1");
     }
 
     /**
@@ -79,8 +81,8 @@ public class CommonApi {
      */
     @PostMapping("modifydata")
     @ResponseBody
-    public Object modifyDataApi(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
-        return commonInterface(token, params, "2");
+    public Object modifyDataApi(@RequestHeader Map<String, String> headers, @RequestBody Map<String, Object> params) {
+        return commonInterface(headers, params, "2");
     }
 
     /**
@@ -90,8 +92,8 @@ public class CommonApi {
      */
     @PostMapping("movedata")
     @ResponseBody
-    public Object moveDataApi(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
-        return commonInterface(token, params, "3");
+    public Object moveDataApi(@RequestHeader Map<String, String> headers, @RequestBody Map<String, Object> params) {
+        return commonInterface(headers, params, "3");
     }
 
     /**
@@ -173,16 +175,16 @@ public class CommonApi {
 
 
     @PostMapping("/upload")
-    public Object upload(@RequestParam(value = "file") MultipartFile excelFile, @RequestParam(value = "serviceId") String serviceID ,@RequestHeader Map<String,Object> requestHeader) throws Exception {
+    public Object upload(@RequestParam(value = "file") MultipartFile excelFile, @RequestParam(value = "serviceId") String serviceID, @RequestHeader Map<String, Object> requestHeader) throws IOException {
         if (excelFile.isEmpty()) {
             return MapTools.processFail("文件夹为空,重新上传");
         } else {
             String userName = "";
-            if (requestHeader.containsKey("user_id")){
+            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 ){
+                if (o instanceof List<?> tpList && !tpList.isEmpty() && tpList.get(0) instanceof Map<?,?> currentMap) {
                     userName = Objects.toString(currentMap.get("user_name"));
                 }
 
@@ -190,7 +192,7 @@ public class CommonApi {
 
             String fileName = excelFile.getOriginalFilename();
             InputStream is = excelFile.getInputStream();
-            Map<String, Object> uploadFile = importExcelUtils.upload(fileName, is,userName);
+            Map<String, Object> uploadFile = importExcelUtils.upload(fileName, is, userName);
             if ("-1".equals(uploadFile.get("code"))) {
                 return uploadFile;
             }

+ 16 - 20
mainFactory/src/main/java/org/bfkj/api/ControllerApi.java

@@ -9,7 +9,6 @@ import org.springframework.web.bind.annotation.*;
 import java.util.HashMap;
 import java.util.Map;
 
-//todo  控制类 API(start,stop)
 
 @RestController
 @RequestMapping("controlApi")
@@ -19,40 +18,37 @@ public class ControllerApi {
 
     /***
      * 主动采集与被动采集的启动
-     * @param token
-     * @param params
+     * @param headers 请求头
+     * @param body 请求内容
      * @return
      */
     @PostMapping("start")
     @ResponseBody
-    public Map<String,Object> start(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
-        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;
-        }
-        //令牌校验
-        return ServiceInputControl.startOrStop(params, "1");
+    public Map<String,Object> start(@RequestHeader Map<String, String> headers, @RequestBody Map<String, Object> body) {
+        return startOrStopService(headers, body, "1");
     }
     /**
      * 主动采集与被动采集的停止
      *
-     * @param token
-     * @param params
+     * @param headers 请求头
+     * @param body 请求内容
      * @return
      */
     @PostMapping("stop")
     @ResponseBody
-    public Map<String,Object> stop(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
-        String verificationToke = authApplication.verificationUserToken(token);
+    public Map<String,Object> stop(@RequestHeader Map<String, String> headers, @RequestBody Map<String, Object> body) {
+        return startOrStopService(headers, body, "0");
+    }
+
+    private Map<String, Object> startOrStopService(Map<String, String> headers, Map<String, Object> body, String number) {
+        String verificationToke = authApplication.verificationUserToken(headers);
         if (!MapTools.isBlank(verificationToke)) {
             HashMap<String, Object> errMap = new HashMap<>();
-            errMap.put("code","-1");
-            errMap.put("message","用户令牌验证失败:" + verificationToke);
+            errMap.put("code", "-1");
+            errMap.put("message", "用户令牌验证失败:" + verificationToke);
             return errMap;
         }
-        return ServiceInputControl.startOrStop(params, "0");
+        //令牌校验
+        return ServiceInputControl.startOrStop(body, number);
     }
 }

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

@@ -25,8 +25,8 @@ public class NewCommonApi {
 
     @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);
+    public Object search(@RequestHeader Map<String, String> headers, @RequestBody Map<String, Object> body) {
+        return commonInterface(headers, body, "0", (body.containsKey("id") && !body.containsKey("serviceId")) ? Objects.toString(body.get("id")) : null);
     }
     /**
      * 统一接收处理

+ 9 - 5
mainFactory/src/main/java/org/bfkj/api/TransferData.java

@@ -8,11 +8,14 @@ import org.springframework.web.bind.annotation.*;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
+import java.util.logging.Logger;
 
 
 @RestController
 @RequestMapping("externalApi/openApi")
 public class TransferData {
+    private static final Logger logger = Logger.getLogger(TransferData.class.getName());
+
     /**
      * /**
      * /**
@@ -20,13 +23,14 @@ public class TransferData {
      */
     @PostMapping("sendData")
     @ResponseBody
-    public Object sendData(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
-        System.out.println("params"+params);
-        Object serviceId = params.get("serviceId");
+    public Object sendData(@RequestHeader Map<String, String> headers, @RequestBody Map<String, Object> body) {
+        String msg = String.format("params%s", body);
+        logger.info(msg);
+        Object serviceId = body.get("serviceId");
         if (Objects.isNull(serviceId)) {
             HashMap<String, Object> errMap = new HashMap<>();
             errMap.put("code", "-1");
-            errMap.put("message", "缺失必要的参数:serviceId" + params);
+            errMap.put("message", "缺失必要的参数:serviceId" + body);
             return errMap;
         }
         //通过服务ID 查询对应服务的服务类型是否为1,如果时则继续,否则返回
@@ -37,6 +41,6 @@ public class TransferData {
             errMap.put("message", "服务不可用:" + (null == dataProcessObj ? "" : dataProcessObj.getErrorMessage()));
             return errMap;
         }
-        return dataProcessObj.processData(params, token.get("user_id"));
+        return dataProcessObj.processData(body, headers.get("user_id"));
     }
 }

+ 1 - 1
mainFactory/src/main/java/org/bfkj/application/AuthApplicationImpl.java

@@ -250,7 +250,7 @@ public class AuthApplicationImpl {
             return processFail("用户名或密码错误");
         }
         String userID = userInfoList.get(0).get("user_id").toString();
-        String userToken = MapTools.getMD5Str(new Date().getTime() + "");
+        String userToken = MapTools.getMD5Str(String.valueOf(new Date().getTime()));
         try {
             Object token_valid_duration = userInfoList.get(0).get("token_valid_duration");
             myDbHelper.updateByCondition("update t_user set user_token = ?,user_status = 1,signInTime = NOW(),token_valid_time = if(" + Objects.isNull(token_valid_duration) + ",null, DATE_ADD(NOW(),INTERVAL   " + (Objects.isNull(token_valid_duration) ? 0 : Integer.parseInt(token_valid_duration.toString())) + " SECOND) )  where user_id= ? ", null, userToken, userID);

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

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

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

@@ -1,25 +0,0 @@
-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;
-    }
-}

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

@@ -141,7 +141,7 @@ public class DataFormat {
                         HashMap<String, Object> errorMap = new HashMap<>();
                         errorMap.put("dataObjectId", dataObjectId);
                         errorMap.put("errMessage", "报文数据格式错误");
-                        if ("true".equals(AppConfig.SOURCE_DATA)){
+                        if (AppConfig.SOURCE_DATA){
                             errorMap.put("sourceData", tempTypeStr);
                         }
                         if (!returnDataList.contains(errorMap)) {
@@ -155,7 +155,7 @@ public class DataFormat {
                 signDataMap.put("dataType", dataType);//默认报文类型
                 signDataMap.put("dataObjectId", dataObjectId); //默认生命周期ID
 //                signDataMap.put("sourceData", signData); //默认原始报文--因为要记录完整的原始报文,所以不去头不去尾
-                if ("true".equals(AppConfig.SOURCE_DATA)){
+                if (AppConfig.SOURCE_DATA){
                     signDataMap.put("sourceData", signData);
                 }
                 String[] rowDataList = signData.split("(?=\\.[A-Z]{1}\\/)", -1);//使用.字母/进行分组,获得行数据
@@ -348,7 +348,7 @@ public class DataFormat {
             HashMap<String, Object> errorMap = new HashMap<>();
             errorMap.put("dataObjectId", dataObjectId);
             errorMap.put("errMessage", "报文数据格式错误");
-            if ("true".equals(AppConfig.SOURCE_DATA)){
+            if (AppConfig.SOURCE_DATA){
                 errorMap.put("sourceData", typeStr);
             }
             returnDataList.add(errorMap);
@@ -534,14 +534,14 @@ public class DataFormat {
             Element root = doc.getRootElement();
             Map<String, Object> returnMap = xmlToMap(root);
 //            returnMap.put("souceData", xml);
-            if ("true".equals(AppConfig.SOURCE_DATA)){
+            if (AppConfig.SOURCE_DATA){
                 returnMap.put("sourceData", xml);
             }
             return processSuccess(returnMap);
         } catch (Exception e) {
             Map<String, Object> errMap = processFail("入参不是规则的xml :" + xml);
 //            errMap.put("souceData", xml);
-            if ("true".equals(AppConfig.SOURCE_DATA)){
+            if (AppConfig.SOURCE_DATA){
                 errMap.put("sourceData", xml);
             }
             return errMap;
@@ -568,7 +568,7 @@ public class DataFormat {
         } catch (Exception e) {
             Map<String, Object> errMap = processFail("入参不是规则的xml");
 //            errMap.put("souceData", xmlList);
-            if ("true".equals(AppConfig.SOURCE_DATA)){
+            if (AppConfig.SOURCE_DATA){
                 errMap.put("sourceData", xmlList);
             }
             return errMap;