瀏覽代碼

中小型底座版本

andy 1 年之前
父節點
當前提交
079aaf938d

+ 7 - 0
mainFactory/Dockerfile

@@ -0,0 +1,7 @@
+# 选择运行时基础镜像
+FROM tencent-kona-jdk:17.0.9
+RUN mkdir "/app"
+WORKDIR /app
+COPY target/*.jar /app/app.jar
+EXPOSE 8080
+ENTRYPOINT ["java","-jar","app.jar"]

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

@@ -3,11 +3,10 @@ package org.bfkj.api;
 
 import jakarta.servlet.http.HttpServletRequest;
 import org.bfkj.application.AuthApplicationImpl;
-import org.bfkj.services.SecurityService;
-import org.bfkj.utils.HttpRequestUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.time.LocalDateTime;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -18,101 +17,102 @@ public class AuthManageApi {
 
     @Autowired
     AuthApplicationImpl authApplication;
-    @Autowired
-    private SecurityService securityService;
+//    @Autowired
+//    private SecurityService securityService;
 
     @PostMapping("getToken")
     public Object getToken(@RequestBody Map<String, String> body, HttpServletRequest httpServletRequest) {
-        try {
-            Map<String, Object> bodyMap = new HashMap<>(body);
-            Map<String, Object> requestData = HttpRequestUtil.combineData(null, bodyMap, httpServletRequest);
-
-            Map<String, Object> result = securityService.getToken(requestData);
-            if ("0".equals(result.get("code"))) {
-                Map<String, Object> temp = new HashMap<>();
-                Map<String, Object> returnData = (Map<String, Object>) result.get("returnData");
-
-                temp.put("app_effective", returnData.get("expirestime"));
-                temp.put("app_token", returnData.get("token"));
-                temp.put("app_name", returnData.get("appname"));
-                temp.put("app_eng_name", returnData.get("appenname"));
-                temp.put("background", returnData.get("background"));
-                temp.put("app_log", returnData.get("logo"));
-                temp.put("app_small_log", returnData.get("smalllogo"));
-                result.put("returnData", temp);
-            }
-            return result;
-        } catch (Exception e) {
-            String sessionID = httpServletRequest.getSession().getId();
-            return authApplication.getToken(body, sessionID);
-        }
+        System.out.println(LocalDateTime.now() + ": 获取token: " + body);
+//        try {
+//            Map<String, Object> bodyMap = new HashMap<>(body);
+//            Map<String, Object> requestData = HttpRequestUtil.combineData(null, bodyMap, httpServletRequest);
+//
+//            Map<String, Object> result = securityService.getToken(requestData);
+//            if ("0".equals(result.get("code"))) {
+//                Map<String, Object> temp = new HashMap<>();
+//                Map<String, Object> returnData = (Map<String, Object>) result.get("returnData");
+//
+//                temp.put("app_effective", returnData.get("expirestime"));
+//                temp.put("app_token", returnData.get("token"));
+//                temp.put("app_name", returnData.get("appname"));
+//                temp.put("app_eng_name", returnData.get("appenname"));
+//                temp.put("background", returnData.get("background"));
+//                temp.put("app_log", returnData.get("logo"));
+//                temp.put("app_small_log", returnData.get("smalllogo"));
+//                result.put("returnData", temp);
+//            }
+//            return result;
+//        } catch (Exception e) {
+        String sessionID = httpServletRequest.getSession().getId();
+        return authApplication.getToken(body, sessionID);
+//        }
     }
 
     @PostMapping("application-token")
     public Object applicationToken(@RequestBody Map<String, String> body, HttpServletRequest httpServletRequest) {
 
+//        try {
+//            Map<String, Object> bodyMap = new HashMap<>(body);
+//            Map<String, Object> requestData = HttpRequestUtil.combineData(null, bodyMap, httpServletRequest);
+//
+//            Map<String, Object> result = securityService.getToken(requestData);
+//            if ("0".equals(result.get("code"))) {
+//                Map<String, Object> returnData = (Map<String, Object>) result.get("returnData");
+//
+//                Object appToken = returnData.get("token");
+//                Object expirestime = returnData.get("expirestime");
+//                requestData.put("appToken", appToken);
+//                requestData.put("expireTime", expirestime);
+//                requestData.remove("token");
+//                requestData.remove("expirestime");
+//            }
+//            return result;
+//        } catch (Exception exception) {
+
+        String sessionID = httpServletRequest.getSession().getId();
+        Map rsData = (Map) authApplication.getToken(body, sessionID);
+        HashMap<String, Object> rsMap = new HashMap<>();
+        var message = "message";
         try {
-            Map<String, Object> bodyMap = new HashMap<>(body);
-            Map<String, Object> requestData = HttpRequestUtil.combineData(null, bodyMap, httpServletRequest);
-
-            Map<String, Object> result = securityService.getToken(requestData);
-            if ("0".equals(result.get("code"))) {
-                Map<String, Object> returnData = (Map<String, Object>) result.get("returnData");
-
-                Object appToken = returnData.get("token");
-                Object expirestime = returnData.get("expirestime");
-                requestData.put("appToken",appToken);
-                requestData.put("expireTime",expirestime);
-                requestData.remove("token");
-                requestData.remove("expirestime");
-            }
-            return result;
-        } catch (Exception exception) {
-
-            String sessionID = httpServletRequest.getSession().getId();
-            Map rsData = (Map) authApplication.getToken(body, sessionID);
-            HashMap<String, Object> rsMap = new HashMap<>();
-            var message = "message";
-            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;
+            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;
+//        }
     }
 
 
-    @PostMapping({"refreshToken","flush-token"})
+    @PostMapping({"refreshToken", "flush-token"})
     public Object refreshToken(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, String> body, HttpServletRequest httpServletRequest) {
 
-        try {
-            Map<String, Object> bodyMap = new HashMap<>(body);
-            Map<String, Object> requestData = HttpRequestUtil.combineData(headers, bodyMap, httpServletRequest);
-
-            Map<String, Object> result = securityService.refreshToken(requestData);
-            if ("0".equals(result.get("code"))) {
-                Map<String, Object> returnData = (Map<String, Object>) result.get("returnData");
-                Object appToken = returnData.get("token");
-                Object expirestime = returnData.get("expirestime");
-                if(httpServletRequest.getRequestURI().endsWith("refreshToken")) {
-                    requestData.put("app_token", appToken);
-                    requestData.put("app_effective", expirestime);
-                }else{
-                    requestData.put("expireTime", expirestime);
-                }
-                requestData.remove("token");
-                requestData.remove("expirestime");
-            }
-            return result;
-        } catch (Exception exception) {
-            return authApplication.refreshToken(body);
-        }
+//        try {
+//            Map<String, Object> bodyMap = new HashMap<>(body);
+//            Map<String, Object> requestData = HttpRequestUtil.combineData(headers, bodyMap, httpServletRequest);
+//
+//            Map<String, Object> result = securityService.refreshToken(requestData);
+//            if ("0".equals(result.get("code"))) {
+//                Map<String, Object> returnData = (Map<String, Object>) result.get("returnData");
+//                Object appToken = returnData.get("token");
+//                Object expirestime = returnData.get("expirestime");
+//                if (httpServletRequest.getRequestURI().endsWith("refreshToken")) {
+//                    requestData.put("app_token", appToken);
+//                    requestData.put("app_effective", expirestime);
+//                } else {
+//                    requestData.put("expireTime", expirestime);
+//                }
+//                requestData.remove("token");
+//                requestData.remove("expirestime");
+//            }
+//            return result;
+//        } catch (Exception exception) {
+        return authApplication.refreshToken(body);
+//        }
     }
 
     /**

+ 165 - 165
mainFactory/src/main/java/org/bfkj/api/SecurityApi.java

@@ -1,165 +1,165 @@
-package org.bfkj.api;
-
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import jakarta.servlet.http.HttpServletRequest;
-import org.bfkj.services.SecurityService;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.*;
-
-import java.util.Map;
-
-import static org.bfkj.utils.HttpRequestUtil.combineData;
-
-@RestController
-public class SecurityApi {
-
-
-    private final SecurityService securityService;
-
-
-    public SecurityApi(SecurityService securityService) {
-        this.securityService = securityService;
-    }
-
-    /**
-     * 获取appToken appToken
-     *
-     * @param headers
-     * @param body
-     * @return
-     */
-    @PostMapping("user/getToken")
-    public ResponseEntity getToken(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) throws JsonProcessingException {
-        Map<String, Object> requestData = combineData(headers, body, httpRequest);
-        Map<String, Object> result = securityService.getToken(requestData);
-        return ResponseEntity.ok(result);
-    }
-
-    /**
-     * 刷新appToken
-     *
-     * @param headers
-     * @return
-     */
-    @PostMapping("user/refreshToken")
-    public ResponseEntity refreshToken(@RequestHeader Map<String, Object> headers, HttpServletRequest httpRequest) throws JsonProcessingException {
-        Map<String, Object> requestData = combineData(headers, null, httpRequest);
-        Map<String, Object> result = securityService.refreshToken(requestData);
-        return ResponseEntity.ok(result);
-    }
-
-    /**
-     * 校验token 包含appToken 和用户token
-     *
-     * @param headers
-     * @param body
-     * @return
-     */
-    @PostMapping({"user/testToken","foxlibc/testToken"})
-    public ResponseEntity testToken(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
-        Map<String, Object> requestData = combineData(headers, body, httpRequest);
-
-        Map<String, Object> result = securityService.verifyToken(requestData);
-        return ResponseEntity.ok(result);
-    }
-
-    /**
-     * 获取验证码
-     *
-     * @param headers
-     * @param body
-     * @return
-     */
-    @PostMapping({"user/verifyCode","foxlibc/verification-code"})
-    public ResponseEntity getCode(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
-        Map<String, Object> requestData = combineData(headers, body, httpRequest);
-        Map<String, Object> result = securityService.verifyCode(requestData);
-        return ResponseEntity.ok(result);
-    }
-
-    /**
-     * 强制登录
-     *
-     * @param headers
-     * @param body
-     * @return
-     */
-    @PostMapping({"user/forceLogin","foxlibc/force_sign"})
-    public ResponseEntity forceLogin(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
-        Map<String, Object> requestData = combineData(headers, body, httpRequest);
-        Map<String, Object> result = securityService.forceLogin(requestData);
-        return ResponseEntity.ok(result);
-    }
-
-    /**
-     * 登录
-     *
-     * @param headers
-     * @param body
-     * @return
-     */
-    @PostMapping({"user/login","foxlibc/sign-in"})
-    public ResponseEntity login(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
-        Map<String, Object> requestData = combineData(headers, body, httpRequest);
-        Map<String, Object> result = securityService.login(requestData);
-        return ResponseEntity.ok(result);
-    }
-
-    /**
-     * 获取权限
-     *
-     * @param headers
-     * @param body
-     * @return
-     */
-    @PostMapping({"user/permissions","foxlibc/permissions"})
-    public ResponseEntity getPermissions(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
-        Map<String, Object> requestData = combineData(headers, body, httpRequest);
-        Map<String, Object> result = securityService.permission(requestData,0);
-        return ResponseEntity.ok(result);
-    }
-
-
-    /**
-     * 更改密码
-     *
-     * @param headers
-     * @param body
-     * @return
-     */
-    @PostMapping({"user/changePassword","foxlibc/reset-passwd"})
-    public ResponseEntity changePwd(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
-        Map<String, Object> requestData = combineData(headers, body, httpRequest);
-        Map<String, Object> result = securityService.changePassword(requestData);
-        return ResponseEntity.ok(result);
-    }
-
-    /**
-     * 登出注销
-     *
-     * @param headers
-     * @param body
-     * @return
-     */
-    @PostMapping({"user/logOut","foxlibc/sign-out}"})
-    public ResponseEntity logOut(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
-        Map<String, Object> requestData = combineData(headers, body, httpRequest);
-        Map<String, Object> result = securityService.logOut(requestData);
-        return ResponseEntity.ok(result);
-    }
-
-    /**
-     * 用户心跳检查   判断用户是否在线
-     *
-     * @param headers
-     * @param body
-     * @return
-     */
-    @PostMapping({"user/health","foxlibc/health"})
-    public ResponseEntity health(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
-        Map<String, Object> requestData = combineData(headers, body, httpRequest);
-        Map<String, Object> result = securityService.userHeartbeat(requestData);
-        return ResponseEntity.ok(result);
-    }
-}
+//package org.bfkj.api;
+//
+//
+//import com.fasterxml.jackson.core.JsonProcessingException;
+//import jakarta.servlet.http.HttpServletRequest;
+//import org.bfkj.services.SecurityService;
+//import org.springframework.http.ResponseEntity;
+//import org.springframework.web.bind.annotation.*;
+//
+//import java.util.Map;
+//
+//import static org.bfkj.utils.HttpRequestUtil.combineData;
+//
+//@RestController
+//public class SecurityApi {
+//
+//
+//    private final SecurityService securityService;
+//
+//
+//    public SecurityApi(SecurityService securityService) {
+//        this.securityService = securityService;
+//    }
+//
+//    /**
+//     * 获取appToken appToken
+//     *
+//     * @param headers
+//     * @param body
+//     * @return
+//     */
+//    @PostMapping("user/getToken")
+//    public ResponseEntity getToken(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) throws JsonProcessingException {
+//        Map<String, Object> requestData = combineData(headers, body, httpRequest);
+//        Map<String, Object> result = securityService.getToken(requestData);
+//        return ResponseEntity.ok(result);
+//    }
+//
+//    /**
+//     * 刷新appToken
+//     *
+//     * @param headers
+//     * @return
+//     */
+//    @PostMapping("user/refreshToken")
+//    public ResponseEntity refreshToken(@RequestHeader Map<String, Object> headers, HttpServletRequest httpRequest) throws JsonProcessingException {
+//        Map<String, Object> requestData = combineData(headers, null, httpRequest);
+//        Map<String, Object> result = securityService.refreshToken(requestData);
+//        return ResponseEntity.ok(result);
+//    }
+//
+//    /**
+//     * 校验token 包含appToken 和用户token
+//     *
+//     * @param headers
+//     * @param body
+//     * @return
+//     */
+//    @PostMapping({"user/testToken","foxlibc/testToken"})
+//    public ResponseEntity testToken(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
+//        Map<String, Object> requestData = combineData(headers, body, httpRequest);
+//
+//        Map<String, Object> result = securityService.verifyToken(requestData);
+//        return ResponseEntity.ok(result);
+//    }
+//
+//    /**
+//     * 获取验证码
+//     *
+//     * @param headers
+//     * @param body
+//     * @return
+//     */
+//    @PostMapping({"user/verifyCode","foxlibc/verification-code"})
+//    public ResponseEntity getCode(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
+//        Map<String, Object> requestData = combineData(headers, body, httpRequest);
+//        Map<String, Object> result = securityService.verifyCode(requestData);
+//        return ResponseEntity.ok(result);
+//    }
+//
+//    /**
+//     * 强制登录
+//     *
+//     * @param headers
+//     * @param body
+//     * @return
+//     */
+//    @PostMapping({"user/forceLogin","foxlibc/force_sign"})
+//    public ResponseEntity forceLogin(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
+//        Map<String, Object> requestData = combineData(headers, body, httpRequest);
+//        Map<String, Object> result = securityService.forceLogin(requestData);
+//        return ResponseEntity.ok(result);
+//    }
+//
+//    /**
+//     * 登录
+//     *
+//     * @param headers
+//     * @param body
+//     * @return
+//     */
+//    @PostMapping({"user/login","foxlibc/sign-in"})
+//    public ResponseEntity login(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
+//        Map<String, Object> requestData = combineData(headers, body, httpRequest);
+//        Map<String, Object> result = securityService.login(requestData);
+//        return ResponseEntity.ok(result);
+//    }
+//
+//    /**
+//     * 获取权限
+//     *
+//     * @param headers
+//     * @param body
+//     * @return
+//     */
+//    @PostMapping({"user/permissions","foxlibc/permissions"})
+//    public ResponseEntity getPermissions(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
+//        Map<String, Object> requestData = combineData(headers, body, httpRequest);
+//        Map<String, Object> result = securityService.permission(requestData,0);
+//        return ResponseEntity.ok(result);
+//    }
+//
+//
+//    /**
+//     * 更改密码
+//     *
+//     * @param headers
+//     * @param body
+//     * @return
+//     */
+//    @PostMapping({"user/changePassword","foxlibc/reset-passwd"})
+//    public ResponseEntity changePwd(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
+//        Map<String, Object> requestData = combineData(headers, body, httpRequest);
+//        Map<String, Object> result = securityService.changePassword(requestData);
+//        return ResponseEntity.ok(result);
+//    }
+//
+//    /**
+//     * 登出注销
+//     *
+//     * @param headers
+//     * @param body
+//     * @return
+//     */
+//    @PostMapping({"user/logOut","foxlibc/sign-out}"})
+//    public ResponseEntity logOut(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
+//        Map<String, Object> requestData = combineData(headers, body, httpRequest);
+//        Map<String, Object> result = securityService.logOut(requestData);
+//        return ResponseEntity.ok(result);
+//    }
+//
+//    /**
+//     * 用户心跳检查   判断用户是否在线
+//     *
+//     * @param headers
+//     * @param body
+//     * @return
+//     */
+//    @PostMapping({"user/health","foxlibc/health"})
+//    public ResponseEntity health(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
+//        Map<String, Object> requestData = combineData(headers, body, httpRequest);
+//        Map<String, Object> result = securityService.userHeartbeat(requestData);
+//        return ResponseEntity.ok(result);
+//    }
+//}

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

@@ -296,7 +296,7 @@ public class AuthApplicationImpl {
         }
         try {
             String user_id = params.get("user_id");
-            myDbHelper.updateByCondition("update t_user set user_token = null,user_status = 0,LogoutTime = NOW() where user_id=?", null, user_id);
+            myDbHelper.updateByCondition("update t_user set user_token = null,LogoutTime = NOW() where user_id=?", null, user_id);
             return processSuccess("用户登出成功");
         } catch (Exception e) {
             return processFail("用户登出失败: ");

+ 40 - 40
mainFactory/src/main/java/org/bfkj/services/ApplicationService.java

@@ -1,40 +1,40 @@
-package org.bfkj.services;
-
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.bfkj.domain.Application;
-import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.jdbc.core.BeanPropertyRowMapper;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.core.RowMapper;
-import org.springframework.stereotype.Service;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Map;
-
-@Service
-public class ApplicationService {
-
-    private ObjectMapper objectMapper=new ObjectMapper();
-
-    private final JdbcTemplate securityJdbcTemplate;
-
-
-    public ApplicationService(@Qualifier("securityJdbcTemplate") JdbcTemplate securityJdbcTemplate) {
-        this.securityJdbcTemplate = securityJdbcTemplate;
-    }
-
-    public Application findById(Integer id) {
-        return (Application) securityJdbcTemplate.queryForObject("select * from application where applicationid = ? ", new BeanPropertyRowMapper(Application.class), id);
-    }
-
-    public Application findByAppId(String id) {
-       return (Application) securityJdbcTemplate.queryForObject("select * from application where appid = ? ", new BeanPropertyRowMapper(Application.class),id);
-
-
-    }
-
-}
+//package org.bfkj.services;
+//
+//
+//import com.fasterxml.jackson.core.JsonProcessingException;
+//import com.fasterxml.jackson.databind.ObjectMapper;
+//import org.bfkj.domain.Application;
+//import org.springframework.beans.BeanUtils;
+//import org.springframework.beans.factory.annotation.Qualifier;
+//import org.springframework.jdbc.core.BeanPropertyRowMapper;
+//import org.springframework.jdbc.core.JdbcTemplate;
+//import org.springframework.jdbc.core.RowMapper;
+//import org.springframework.stereotype.Service;
+//
+//import java.sql.ResultSet;
+//import java.sql.SQLException;
+//import java.util.Map;
+//
+//@Service
+//public class ApplicationService {
+//
+//    private ObjectMapper objectMapper=new ObjectMapper();
+//
+//    private final JdbcTemplate securityJdbcTemplate;
+//
+//
+//    public ApplicationService(@Qualifier("securityJdbcTemplate") JdbcTemplate securityJdbcTemplate) {
+//        this.securityJdbcTemplate = securityJdbcTemplate;
+//    }
+//
+//    public Application findById(Integer id) {
+//        return (Application) securityJdbcTemplate.queryForObject("select * from application where applicationid = ? ", new BeanPropertyRowMapper(Application.class), id);
+//    }
+//
+//    public Application findByAppId(String id) {
+//       return (Application) securityJdbcTemplate.queryForObject("select * from application where appid = ? ", new BeanPropertyRowMapper(Application.class),id);
+//
+//
+//    }
+//
+//}

+ 444 - 441
mainFactory/src/main/java/org/bfkj/services/SecurityService.java

@@ -1,441 +1,444 @@
-package org.bfkj.services;
-
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import jakarta.annotation.Nullable;
-import org.bfkj.domain.*;
-import org.bfkj.services.cache.CodeCacheService;
-import org.bfkj.utils.CommonUtil;
-import org.bfkj.utils.RandomGraphic;
-import org.springframework.stereotype.Service;
-
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.*;
-
-@Service
-public class SecurityService {
-
-
-    private DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
-
-    private final static Map<String, List<String>> alias = new HashMap<>();
-
-    static {
-        alias.put("appid", List.of("appid", "app_id", "appId", "APPID"));
-        alias.put("appsecret", List.of("appSecret", "app_secret", "APP_SECRET", "appsecret", "APPSECRET"));
-        alias.put("sessionid", List.of("sessionId", "sessionid"));
-        alias.put("requestip", List.of("requestIp", "requestip"));
-        alias.put("username", List.of("username"));
-        alias.put("password", List.of("password"));
-        alias.put("version", List.of("version"));
-    }
-
-    private final ApplicationService applicationService;
-    private final ApplicationconnectlogService applicationconnectlogService;
-    private final UserloginlogService userloginlogService;
-    private final PermissionsService permissionsService;
-    private final UserinfoService userinfoService;
-    private final CodeCacheService codeCacheService;
-
-    public SecurityService(ApplicationService applicationService, ApplicationconnectlogService applicationconnectlogService, UserloginlogService userloginlogService, PermissionsService permissionsService, UserinfoService userinfoService, CodeCacheService codeCacheService) {
-        this.applicationService = applicationService;
-        this.applicationconnectlogService = applicationconnectlogService;
-        this.userloginlogService = userloginlogService;
-        this.permissionsService = permissionsService;
-        this.userinfoService = userinfoService;
-        this.codeCacheService = codeCacheService;
-    }
-
-
-    //安全类服务
-    //连接认证--获取连接令牌
-    public Map<String, Object> getToken(Map<String, Object> requestData) throws JsonProcessingException {
-        Optional<String> appid = getValue("appid", requestData);
-        Optional<String> appSecret = getValue("appsecret", requestData);
-        Optional<String> requestIp = getValue("requestip", requestData);
-        Optional<String> sessionId = getValue("sessionid", requestData);
-
-        Map<String, Object> result = new HashMap<>();
-        if (appid.isPresent() && appSecret.isPresent()) {
-//            无条件删除过期的数据
-            applicationconnectlogService.removeExpiresData();
-            result.putAll(getAppToken(appid.get(), appSecret.get(), requestIp.get(), sessionId.get()));
-        } else {
-            result.put("code", "-1");
-            result.put("message", "appid 或者 appSecret 错误");
-        }
-        return result;
-    }
-
-    private Map<String, Object> getAppToken(String appid, String appSecret, String requestIp, String sessionId) throws JsonProcessingException {
-        Application application = applicationService.findByAppId(appid);
-        Map<String, Object> result = new HashMap<>();
-        if (appSecret.equals(application.getAppsecret())) {
-//            令牌
-            String md5Token = CommonUtil.toMD5("%s:%s".formatted(LocalDateTime.now(), sessionId));
-//            有效期时长
-            Long apptokeneffective = application.getApptokeneffective();
-//            过期时间
-            LocalDateTime expiresTime = LocalDateTime.now().plusSeconds(apptokeneffective);
-//            新增记录
-            Appconnectlog applicationconnectlog = new Appconnectlog();
-
-            applicationconnectlog.setAppid(appid);
-            applicationconnectlog.setExpiretime(expiresTime);
-            applicationconnectlog.setApptoken(md5Token);
-            applicationconnectlog.setRequestip(requestIp);
-            applicationconnectlog.setRequesttime(LocalDateTime.now());
-            applicationconnectlog.setLasttime(LocalDateTime.now());
-            applicationconnectlogService.save(applicationconnectlog);
-            Map<String, Object> data = new HashMap<>();
-            data.put("token", md5Token);
-            data.put("expirestime", expiresTime.format(dateTimeFormatter));
-            data.put("appname", application.getAppname());
-            data.put("appenname", application.getAppengname());
-            data.put("logo", application.getApplogo());
-            data.put("smalllogo", application.getSmalllogo());
-            data.put("background", application.getBackgroundimage());
-            data.put("securitycoderule", application.getSecuritycoderule());
-            result.put("returnData", data);
-            result.put("code", "0");
-            result.put("message", null);
-        } else {
-            result.put("message", "用户或密码错误");
-            result.put("code", "-1");
-        }
-        return result;
-    }
-
-
-
-    //校验连接令牌
-    public Map<String, Object> verifyToken(Map<String, Object> requestData) {
-        Optional<String> token = getValue("token", requestData);
-
-        Optional<String> requestIp = getValue("requestip", requestData);
-
-        Map<String, Object> result = new HashMap<>();
-        if (token.isEmpty()) {
-            result.put("code", "-1");
-            result.put("message", "token错误");
-        } else {
-            Appconnectlog applicationLog = applicationconnectlogService.findByTokenAndRequestIp(token.get(), requestIp.get());
-            if (LocalDateTime.now().isAfter(applicationLog.getExpiretime())) {
-                result.put("code", "-1");
-                result.put("message", "token已过期");
-            } else {
-                result.put("code", "0");
-                result.put("message", "token校验通过");
-
-                Map<String, Object> data = new HashMap<>();
-                data.put("validstatus", true);
-                result.put("returnData", data);
-            }
-        }
-        return result;
-    }
-
-    //刷新连接令牌
-    public Map<String, Object> refreshToken(Map<String, Object> requestData) {
-        Map<String, Object> resultData = new HashMap<>();
-        Map<String, Object> map = verifyToken(requestData);
-        Optional<String> version = getValue("version", requestData);
-
-        if (map.get("code").equals("0")) {
-            Optional<String> requestIp = getValue("requestIp", requestData);
-            Optional<String> token = getValue("token", requestData);
-
-            Appconnectlog applicationconnectlog = applicationconnectlogService.findByTokenAndRequestIp(token.get(), requestIp.get());
-            Application application = applicationService.findByAppId(applicationconnectlog.getAppid());
-            LocalDateTime expiresTime = LocalDateTime.now().plusSeconds(application.getApptokeneffective());
-            applicationconnectlogService.updateApplicationLogTokenExpiresTime(applicationconnectlog.getAppid(), token.get(), expiresTime);
-            resultData.put("code", "0");
-            Map<String, Object> data = new HashMap<>();
-            data.put("expirestime", expiresTime.format(dateTimeFormatter));
-            data.put("token", token.get());
-            if ("1".equals(version.orElse("1"))) {
-                resultData.put("returnData", data);
-            } else {
-                resultData.put("data", data);
-            }
-        } else {
-            resultData.putAll(map);
-        }
-        return resultData;
-    }
-
-    //获取登录验证码
-    public Map<String, Object> verifyCode(Map<String, Object> requestData) {
-        Map<String, Object> resultData = new HashMap<>();
-        Optional<String> token = getValue("token", requestData);
-        Optional<String> ip = getValue("requestip", requestData);
-        Optional<String> sessionId = getValue("sessionid", requestData);
-        Map<String, Object> testToken = verifyToken(requestData);
-        if ("0".equals(testToken.get("code"))) {
-            Appconnectlog applicationLog = applicationconnectlogService.findByTokenAndRequestIp(token.get(), ip.get());
-            String appid = applicationLog.getAppid();
-            Application application = applicationService.findByAppId(appid);
-            String securitycoderule = application.getSecuritycoderule();
-            Long securitycodeeffective = application.getSecuritycodeeffective();
-            Integer securitycoderulelength = application.getSecuritycoderulelength();
-            Map<String, Object> codeMap = RandomGraphic.generateVerifyCode(securitycoderulelength, securitycoderule);
-
-            String code = codeMap.get("verifyCode").toString();
-            String verifyCodeImage = codeMap.get("verifyCodeImage").toString();
-            codeCacheService.addCode(code, sessionId.get(), securitycodeeffective);
-            resultData.put("code", "0");
-//            编译后的验证码
-
-            Map<String, Object> data = new HashMap<>();
-            data.put("verifyCodeImage", verifyCodeImage);
-            resultData.put("returnData", data);
-        } else {
-            resultData.put("code", "-1");
-            resultData.put("message", "token已经过期");
-        }
-        return resultData;
-    }
-
-
-    //用户登录
-    public Map<String, Object> login(Map<String, Object> requestData) {
-        Map<String, Object> testToken = verifyToken(requestData);
-        Map<String, Object> resultData = new HashMap<>();
-        if (testToken.get("code").equals("0")) {
-            //用户登录日志单独记录--方便控制用户在线状态、用户登录时长、用户心跳等
-            Optional<String> username = getValue("username", requestData);
-            Optional<String> password = getValue("password", requestData);
-            Optional<String> code = getValue("verifycode", requestData);
-            Optional<String> sessionId = getValue("sessionid", requestData);
-            Optional<String> requestIp = getValue("requestip", requestData);
-            Optional<String> token = getValue("token", requestData);
-            resultData.putAll(getUserToken(token.get(), username.get(), password.get(), code.get(), requestIp.get(), sessionId.get(), true));
-        } else {
-            resultData.put("code", "-1");
-            resultData.put("message", "token已经过期");
-        }
-        return resultData;
-    }
-
-    private Map<String, Object> getUserToken(@Nullable String appToken, @Nullable String userName, @Nullable String password, @Nullable String code, @Nullable String requestIp, String sessionId, Boolean checkCode) {
-        Map<String, Object> result = new HashMap<>();
-        Appconnectlog applicationconnectlog = applicationconnectlogService.findByTokenAndRequestIp(appToken, requestIp);
-        if (Objects.isNull(applicationconnectlog)) {
-            result.put("code", "-1");
-            result.put("message", "apptoken 错误");
-            return result;
-        }
-        Application application = applicationService.findByAppId(applicationconnectlog.getAppid());
-
-        if (checkCode && Objects.nonNull(application.getSecuritycoderule()) && !codeCacheService.check(code, sessionId)) {
-            result.put("code", "-1");
-            result.put("message", "验证码错误");
-        } else {
-            Integer multilogin = application.getMultilogin();
-            Userinfo user = userinfoService.findByUsername(userName);
-            List<Userloginlog> userloginlogs = userloginlogService.findByUserId(user.getUserid());
-            if (!userloginlogs.isEmpty()) {
-                result.put("code", "0");
-                if (multilogin == 1) {
-                    userloginlogService.expiresByUserid(user.getUserid());
-                }
-                userloginlogService.insertUserLoginLog(requestIp, sessionId, user.getUserid(), null, appToken, application.getAppid());
-                result.put("returnData", new HashMap<>() {{
-                    put("userstatus", 1);
-                }});
-                return result;
-            } else {
-                result.put("code", "0");
-                result.put("returnData", new HashMap<>() {{
-                    put("userstatus", 0);
-                }});
-            }
-            userloginlogService.insertUserLoginLog(requestIp, sessionId, user.getUserid(), null, appToken, application.getAppid());
-
-        }
-        return result;
-    }
-
-    //强制登录
-    public Map<String, Object> forceLogin(Map<String, Object> requestData) {
-
-        Map<String, Object> verifyTokenResult = verifyToken(requestData);
-        if (!verifyTokenResult.get("code").equals("0")) {
-            return verifyTokenResult;
-        }
-        Optional<String> token = getValue("token", requestData);
-        Optional<String> sessionId = getValue("sessionid", requestData);
-        Optional<String> requestIp = getValue("requestip", requestData);
-        Userloginlog userloginlog = userloginlogService.findByAppToken(token.get(), sessionId.get());
-        Map<String, Object> result = new HashMap<>();
-        if (Objects.isNull(userloginlog)) {
-            result.put("code", "-1");
-            result.put("message", "登录失败");
-        } else {
-            Map<String, Object> data = new HashMap<>();
-            Appconnectlog appconnectlog = applicationconnectlogService.findByTokenAndRequestIp(token.get(), requestIp.get());
-            if (Objects.nonNull(appconnectlog)) {
-                String appid = appconnectlog.getAppid();
-                Application application = applicationService.findByAppId(appid);
-                if (Objects.nonNull(application)) {
-                    result.put("code", "0");
-                    data.put("userid", userloginlog.getUserid());
-                    Long apptokeneffective = application.getApptokeneffective();
-                    data.put("expirestime", LocalDateTime.now().plusSeconds(apptokeneffective).format(dateTimeFormatter));
-                    String userToken = CommonUtil.toMD5("%s:%s".formatted(sessionId.get(), LocalDateTime.now()));
-                    data.put("usertoken", userToken);
-                    userloginlogService.removeUserLoginAppToken(sessionId.get(), userloginlog.getUserid(), userToken);
-                } else {
-                    result.put("code", "-1");
-                    result.put("message", "应用配置没有找到");
-                }
-            } else {
-                result.put("code", "-1");
-                result.put("message", "应用token没有找到");
-            }
-        }
-        return result;
-    }
-
-    private Map<String, Object> checkUserToken(Map<String, Object> requestData) {
-        Optional<String> userToken = getValue("usertoken", requestData);
-        Optional<String> sessionId = getValue("sessionid", requestData);
-        Userloginlog userloginlog = userloginlogService.findByUserToken(userToken.get(), sessionId.get());
-
-        String appid = userloginlog.getAppid();
-        Application application = applicationService.findByAppId(appid);
-        if (userloginlog.getLastheartbeat().plusSeconds(application.getApptokeneffective()).isBefore(LocalDateTime.now())) {
-            return new HashMap<>() {{
-                put("code", "1");
-                put("message", "用户token已过期");
-            }};
-        } else {
-            return new HashMap<>() {{
-                put("code", "0");
-            }};
-        }
-
-    }
-
-    //用户登出
-    public Map<String, Object> logOut(Map<String, Object> requestData) {
-        Map<String, Object> resultData = checkUserToken(requestData);
-        if (!"0".equals(resultData.get("code"))) {
-            return resultData;
-        } else {
-            resultData = new HashMap<>();
-
-            Optional<String> userToken = getValue("usertoken", requestData);
-            Optional<String> sessionId = getValue("sessionid", requestData);
-            Userloginlog userloginlog = userloginlogService.findByUserToken(userToken.get(), sessionId.get());
-
-            userloginlogService.removeUserLoginLogByUserId(userloginlog.getUserid());
-            permissionsService.removePermissions(userloginlog.getUserid());
-            resultData.put("code", "0");
-            resultData.put("message", "成功");
-            return resultData;
-        }
-    }
-
-
-    //获取用户权限
-    public Map<String, Object> permission(Map<String, Object> requestData, Integer version) {
-
-        Map<String, Object> resultData = checkUserToken(requestData);
-        if (!"0".equals(resultData.get("code"))) {
-            return resultData;
-        } else {
-            Optional<String> userToken = getValue("usertoken", requestData);
-            Optional<String> sessionId = getValue("sessionid", requestData);
-            Userloginlog userloginlog = userloginlogService.findByUserToken(userToken.get(), sessionId.get());
-            if ("0".equals(version)) {
-                List<Permissions> ps = permissionsService.getPermissions(userloginlog.getUserid().toString());
-                resultData = new HashMap<>();
-                resultData.put("code", "0");
-                resultData.put("returnData", ps);
-            } else {
-                List<Map<String, Object>> ps = permissionsService.getPermissionsOld(userloginlog.getUserid().toString());
-                resultData = new HashMap<>();
-                resultData.put("code", "0");
-                resultData.put("returnData", ps);
-            }
-        }
-        return resultData;
-    }
-
-    //应用API及数据权限
-    public Map<String, Object> changePassword(Map<String, Object> requestData) {
-
-        Map<String, Object> resultData = checkUserToken(requestData);
-        if (!"0".equals(resultData.get("code"))) {
-            return resultData;
-        } else {
-            Optional<String> usertoken = getValue("usertoken", requestData);
-            Optional<String> oldPassword = getValue("oldpassword", requestData);
-            Optional<String> password = getValue("password", requestData);
-
-            Optional<String> userToken = getValue("usertoken", requestData);
-            Optional<String> sessionId = getValue("sessionid", requestData);
-            Userloginlog userloginlog = userloginlogService.findByUserToken(userToken.get(), sessionId.get());
-            Integer userId = userloginlog.getUserid();
-            Userinfo userinfo = userinfoService.findByUserId(userId);
-            if (Objects.nonNull(userinfo)) {
-                String userpassword = userinfo.getUserpassword();
-                if (!userpassword.equals(oldPassword.get())) {
-                    resultData.put("message", "密码错误");
-                    resultData.put("code", "-1");
-                    return resultData;
-                } else {
-                    userinfoService.updateUserPassword(userId, password.get());
-                }
-                resultData = new HashMap<>();
-                resultData.put("code", "0");
-                resultData.put("message", "修改成功");
-            }
-
-        }
-        return resultData;
-    }
-
-    //用户心跳
-    public Map<String, Object> userHeartbeat(Map<String, Object> requestData) {
-        Map<String, Object> resultData = checkUserToken(requestData);
-        if (!"0".equals(resultData.get("code"))) {
-            return resultData;
-        } else {
-            resultData = new HashMap<>();
-            Optional<String> userToken = getValue("usertoken", requestData);
-            Optional<String> sessionId = getValue("sessionid", requestData);
-            Userloginlog userloginlog1 = userloginlogService.findByUserToken(userToken.get(), sessionId.get());
-            if (Objects.nonNull(userloginlog1)) {
-                List<Userloginlog> userloginlogs = userloginlogService.findByUserId(userloginlog1.getUserid());
-
-                if (Objects.nonNull(userloginlogs) && !userloginlogs.isEmpty()) {
-                    for (Userloginlog userloginlog : userloginlogs) {
-
-                        userloginlogService.updateLoginLogUserLastTimeById(userloginlog.getLoginid(), sessionId.get());
-
-                        resultData.put("code", "0");
-                        resultData.put("message", "用户在线");
-
-                    }
-                    if (resultData.isEmpty()) {
-                        resultData.put("code", "-1");
-                        resultData.put("message", "查询失败");
-                    }
-
-                } else {
-                    resultData.put("code", "-1");
-                    resultData.put("message", "查询失败");
-                }
-            }
-        }
-        return resultData;
-    }
-
-
-    private Optional<String> getValue(String key, Map<String, Object> data) {
-        return alias.getOrDefault(key, Collections.singletonList(key)).stream().map(data::get).filter(Objects::nonNull).map(Object::toString).findAny();
-    }
-}
+//package org.bfkj.services;
+//
+//
+//import com.fasterxml.jackson.core.JsonProcessingException;
+//import jakarta.annotation.Nullable;
+//import org.bfkj.domain.*;
+//import org.bfkj.services.cache.CodeCacheService;
+//import org.bfkj.utils.CommonUtil;
+//import org.bfkj.utils.RandomGraphic;
+//import org.springframework.stereotype.Service;
+//
+//import java.time.LocalDateTime;
+//import java.time.format.DateTimeFormatter;
+//import java.util.*;
+//
+//@Service
+//public class SecurityService {
+//
+//
+//    private DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+//
+//    private final static Map<String, List<String>> alias = new HashMap<>();
+//
+//    static {
+//        alias.put("appid", List.of("appid", "app_id", "appId", "APPID"));
+//        alias.put("appsecret", List.of("appSecret", "app_secret", "APP_SECRET", "appsecret", "APPSECRET"));
+//        alias.put("sessionid", List.of("sessionId", "sessionid"));
+//        alias.put("requestip", List.of("requestIp", "requestip"));
+//        alias.put("username", List.of("username"));
+//        alias.put("password", List.of("password"));
+//        alias.put("version", List.of("version"));
+//    }
+//
+//    private final ApplicationService applicationService;
+//    private final ApplicationconnectlogService applicationconnectlogService;
+//    private final UserloginlogService userloginlogService;
+//    private final PermissionsService permissionsService;
+//    private final UserinfoService userinfoService;
+//    private final CodeCacheService codeCacheService;
+//
+//    public SecurityService(ApplicationService applicationService, ApplicationconnectlogService applicationconnectlogService, UserloginlogService userloginlogService, PermissionsService permissionsService, UserinfoService userinfoService, CodeCacheService codeCacheService) {
+//        this.applicationService = applicationService;
+//        this.applicationconnectlogService = applicationconnectlogService;
+//        this.userloginlogService = userloginlogService;
+//        this.permissionsService = permissionsService;
+//        this.userinfoService = userinfoService;
+//        this.codeCacheService = codeCacheService;
+//    }
+//
+//
+//    //安全类服务
+//    //连接认证--获取连接令牌
+//    public Map<String, Object> getToken(Map<String, Object> requestData) throws JsonProcessingException {
+//        Optional<String> appid = getValue("appid", requestData);
+//        Optional<String> appSecret = getValue("appsecret", requestData);
+//        Optional<String> requestIp = getValue("requestip", requestData);
+//        Optional<String> sessionId = getValue("sessionid", requestData);
+//
+//        Map<String, Object> result = new HashMap<>();
+//        if (appid.isPresent() && appSecret.isPresent()) {
+////            无条件删除过期的数据
+//            applicationconnectlogService.removeExpiresData();
+//            result.putAll(getAppToken(appid.get(), appSecret.get(), requestIp.get(), sessionId.get()));
+//        } else {
+//            result.put("code", "-1");
+//            result.put("message", "appid 或者 appSecret 错误");
+//        }
+//        return result;
+//    }
+//
+//    private Map<String, Object> getAppToken(String appid, String appSecret, String requestIp, String sessionId) throws JsonProcessingException {
+//
+//        System.out.println(LocalDateTime.now()+"开始获取数据库中的application的数据");
+//        Application application = applicationService.findByAppId(appid);
+//        System.out.println(LocalDateTime.now()+"获取到数据库中的application的数据");
+//        Map<String, Object> result = new HashMap<>();
+//        if (appSecret.equals(application.getAppsecret())) {
+////            令牌
+//            String md5Token = CommonUtil.toMD5("%s:%s".formatted(LocalDateTime.now(), sessionId));
+////            有效期时长
+//            Long apptokeneffective = application.getApptokeneffective();
+////            过期时间
+//            LocalDateTime expiresTime = LocalDateTime.now().plusSeconds(apptokeneffective);
+////            新增记录
+//            Appconnectlog applicationconnectlog = new Appconnectlog();
+//
+//            applicationconnectlog.setAppid(appid);
+//            applicationconnectlog.setExpiretime(expiresTime);
+//            applicationconnectlog.setApptoken(md5Token);
+//            applicationconnectlog.setRequestip(requestIp);
+//            applicationconnectlog.setRequesttime(LocalDateTime.now());
+//            applicationconnectlog.setLasttime(LocalDateTime.now());
+//            applicationconnectlogService.save(applicationconnectlog);
+//            Map<String, Object> data = new HashMap<>();
+//            data.put("token", md5Token);
+//            data.put("expirestime", expiresTime.format(dateTimeFormatter));
+//            data.put("appname", application.getAppname());
+//            data.put("appenname", application.getAppengname());
+//            data.put("logo", application.getApplogo());
+//            data.put("smalllogo", application.getSmalllogo());
+//            data.put("background", application.getBackgroundimage());
+//            data.put("securitycoderule", application.getSecuritycoderule());
+//            result.put("returnData", data);
+//            result.put("code", "0");
+//            result.put("message", null);
+//        } else {
+//            result.put("message", "用户或密码错误");
+//            result.put("code", "-1");
+//        }
+//        return result;
+//    }
+//
+//
+//
+//    //校验连接令牌
+//    public Map<String, Object> verifyToken(Map<String, Object> requestData) {
+//        Optional<String> token = getValue("token", requestData);
+//
+//        Optional<String> requestIp = getValue("requestip", requestData);
+//
+//        Map<String, Object> result = new HashMap<>();
+//        if (token.isEmpty()) {
+//            result.put("code", "-1");
+//            result.put("message", "token错误");
+//        } else {
+//            Appconnectlog applicationLog = applicationconnectlogService.findByTokenAndRequestIp(token.get(), requestIp.get());
+//            if (LocalDateTime.now().isAfter(applicationLog.getExpiretime())) {
+//                result.put("code", "-1");
+//                result.put("message", "token已过期");
+//            } else {
+//                result.put("code", "0");
+//                result.put("message", "token校验通过");
+//
+//                Map<String, Object> data = new HashMap<>();
+//                data.put("validstatus", true);
+//                result.put("returnData", data);
+//            }
+//        }
+//        return result;
+//    }
+//
+//    //刷新连接令牌
+//    public Map<String, Object> refreshToken(Map<String, Object> requestData) {
+//        Map<String, Object> resultData = new HashMap<>();
+//        Map<String, Object> map = verifyToken(requestData);
+//        Optional<String> version = getValue("version", requestData);
+//
+//        if (map.get("code").equals("0")) {
+//            Optional<String> requestIp = getValue("requestIp", requestData);
+//            Optional<String> token = getValue("token", requestData);
+//
+//            Appconnectlog applicationconnectlog = applicationconnectlogService.findByTokenAndRequestIp(token.get(), requestIp.get());
+//            Application application = applicationService.findByAppId(applicationconnectlog.getAppid());
+//            LocalDateTime expiresTime = LocalDateTime.now().plusSeconds(application.getApptokeneffective());
+//            applicationconnectlogService.updateApplicationLogTokenExpiresTime(applicationconnectlog.getAppid(), token.get(), expiresTime);
+//            resultData.put("code", "0");
+//            Map<String, Object> data = new HashMap<>();
+//            data.put("expirestime", expiresTime.format(dateTimeFormatter));
+//            data.put("token", token.get());
+//            if ("1".equals(version.orElse("1"))) {
+//                resultData.put("returnData", data);
+//            } else {
+//                resultData.put("data", data);
+//            }
+//        } else {
+//            resultData.putAll(map);
+//        }
+//        return resultData;
+//    }
+//
+//    //获取登录验证码
+//    public Map<String, Object> verifyCode(Map<String, Object> requestData) {
+//        Map<String, Object> resultData = new HashMap<>();
+//        Optional<String> token = getValue("token", requestData);
+//        Optional<String> ip = getValue("requestip", requestData);
+//        Optional<String> sessionId = getValue("sessionid", requestData);
+//        Map<String, Object> testToken = verifyToken(requestData);
+//        if ("0".equals(testToken.get("code"))) {
+//            Appconnectlog applicationLog = applicationconnectlogService.findByTokenAndRequestIp(token.get(), ip.get());
+//            String appid = applicationLog.getAppid();
+//            Application application = applicationService.findByAppId(appid);
+//            String securitycoderule = application.getSecuritycoderule();
+//            Long securitycodeeffective = application.getSecuritycodeeffective();
+//            Integer securitycoderulelength = application.getSecuritycoderulelength();
+//            Map<String, Object> codeMap = RandomGraphic.generateVerifyCode(securitycoderulelength, securitycoderule);
+//
+//            String code = codeMap.get("verifyCode").toString();
+//            String verifyCodeImage = codeMap.get("verifyCodeImage").toString();
+//            codeCacheService.addCode(code, sessionId.get(), securitycodeeffective);
+//            resultData.put("code", "0");
+////            编译后的验证码
+//
+//            Map<String, Object> data = new HashMap<>();
+//            data.put("verifyCodeImage", verifyCodeImage);
+//            resultData.put("returnData", data);
+//        } else {
+//            resultData.put("code", "-1");
+//            resultData.put("message", "token已经过期");
+//        }
+//        return resultData;
+//    }
+//
+//
+//    //用户登录
+//    public Map<String, Object> login(Map<String, Object> requestData) {
+//        Map<String, Object> testToken = verifyToken(requestData);
+//        Map<String, Object> resultData = new HashMap<>();
+//        if (testToken.get("code").equals("0")) {
+//            //用户登录日志单独记录--方便控制用户在线状态、用户登录时长、用户心跳等
+//            Optional<String> username = getValue("username", requestData);
+//            Optional<String> password = getValue("password", requestData);
+//            Optional<String> code = getValue("verifycode", requestData);
+//            Optional<String> sessionId = getValue("sessionid", requestData);
+//            Optional<String> requestIp = getValue("requestip", requestData);
+//            Optional<String> token = getValue("token", requestData);
+//            resultData.putAll(getUserToken(token.get(), username.get(), password.get(), code.get(), requestIp.get(), sessionId.get(), true));
+//        } else {
+//            resultData.put("code", "-1");
+//            resultData.put("message", "token已经过期");
+//        }
+//        return resultData;
+//    }
+//
+//    private Map<String, Object> getUserToken(@Nullable String appToken, @Nullable String userName, @Nullable String password, @Nullable String code, @Nullable String requestIp, String sessionId, Boolean checkCode) {
+//        Map<String, Object> result = new HashMap<>();
+//        Appconnectlog applicationconnectlog = applicationconnectlogService.findByTokenAndRequestIp(appToken, requestIp);
+//        if (Objects.isNull(applicationconnectlog)) {
+//            result.put("code", "-1");
+//            result.put("message", "apptoken 错误");
+//            return result;
+//        }
+//        Application application = applicationService.findByAppId(applicationconnectlog.getAppid());
+//
+//        if (checkCode && Objects.nonNull(application.getSecuritycoderule()) && !codeCacheService.check(code, sessionId)) {
+//            result.put("code", "-1");
+//            result.put("message", "验证码错误");
+//        } else {
+//            Integer multilogin = application.getMultilogin();
+//            Userinfo user = userinfoService.findByUsername(userName);
+//            List<Userloginlog> userloginlogs = userloginlogService.findByUserId(user.getUserid());
+//            if (!userloginlogs.isEmpty()) {
+//                result.put("code", "0");
+//                if (multilogin == 1) {
+//                    userloginlogService.expiresByUserid(user.getUserid());
+//                }
+//                userloginlogService.insertUserLoginLog(requestIp, sessionId, user.getUserid(), null, appToken, application.getAppid());
+//                result.put("returnData", new HashMap<>() {{
+//                    put("userstatus", 1);
+//                }});
+//                return result;
+//            } else {
+//                result.put("code", "0");
+//                result.put("returnData", new HashMap<>() {{
+//                    put("userstatus", 0);
+//                }});
+//            }
+//            userloginlogService.insertUserLoginLog(requestIp, sessionId, user.getUserid(), null, appToken, application.getAppid());
+//
+//        }
+//        return result;
+//    }
+//
+//    //强制登录
+//    public Map<String, Object> forceLogin(Map<String, Object> requestData) {
+//
+//        Map<String, Object> verifyTokenResult = verifyToken(requestData);
+//        if (!verifyTokenResult.get("code").equals("0")) {
+//            return verifyTokenResult;
+//        }
+//        Optional<String> token = getValue("token", requestData);
+//        Optional<String> sessionId = getValue("sessionid", requestData);
+//        Optional<String> requestIp = getValue("requestip", requestData);
+//        Userloginlog userloginlog = userloginlogService.findByAppToken(token.get(), sessionId.get());
+//        Map<String, Object> result = new HashMap<>();
+//        if (Objects.isNull(userloginlog)) {
+//            result.put("code", "-1");
+//            result.put("message", "登录失败");
+//        } else {
+//            Map<String, Object> data = new HashMap<>();
+//            Appconnectlog appconnectlog = applicationconnectlogService.findByTokenAndRequestIp(token.get(), requestIp.get());
+//            if (Objects.nonNull(appconnectlog)) {
+//                String appid = appconnectlog.getAppid();
+//                Application application = applicationService.findByAppId(appid);
+//                if (Objects.nonNull(application)) {
+//                    result.put("code", "0");
+//                    data.put("userid", userloginlog.getUserid());
+//                    Long apptokeneffective = application.getApptokeneffective();
+//                    data.put("expirestime", LocalDateTime.now().plusSeconds(apptokeneffective).format(dateTimeFormatter));
+//                    String userToken = CommonUtil.toMD5("%s:%s".formatted(sessionId.get(), LocalDateTime.now()));
+//                    data.put("usertoken", userToken);
+//                    userloginlogService.removeUserLoginAppToken(sessionId.get(), userloginlog.getUserid(), userToken);
+//                } else {
+//                    result.put("code", "-1");
+//                    result.put("message", "应用配置没有找到");
+//                }
+//            } else {
+//                result.put("code", "-1");
+//                result.put("message", "应用token没有找到");
+//            }
+//        }
+//        return result;
+//    }
+//
+//    private Map<String, Object> checkUserToken(Map<String, Object> requestData) {
+//        Optional<String> userToken = getValue("usertoken", requestData);
+//        Optional<String> sessionId = getValue("sessionid", requestData);
+//        Userloginlog userloginlog = userloginlogService.findByUserToken(userToken.get(), sessionId.get());
+//
+//        String appid = userloginlog.getAppid();
+//        Application application = applicationService.findByAppId(appid);
+//        if (userloginlog.getLastheartbeat().plusSeconds(application.getApptokeneffective()).isBefore(LocalDateTime.now())) {
+//            return new HashMap<>() {{
+//                put("code", "1");
+//                put("message", "用户token已过期");
+//            }};
+//        } else {
+//            return new HashMap<>() {{
+//                put("code", "0");
+//            }};
+//        }
+//
+//    }
+//
+//    //用户登出
+//    public Map<String, Object> logOut(Map<String, Object> requestData) {
+//        Map<String, Object> resultData = checkUserToken(requestData);
+//        if (!"0".equals(resultData.get("code"))) {
+//            return resultData;
+//        } else {
+//            resultData = new HashMap<>();
+//
+//            Optional<String> userToken = getValue("usertoken", requestData);
+//            Optional<String> sessionId = getValue("sessionid", requestData);
+//            Userloginlog userloginlog = userloginlogService.findByUserToken(userToken.get(), sessionId.get());
+//
+//            userloginlogService.removeUserLoginLogByUserId(userloginlog.getUserid());
+//            permissionsService.removePermissions(userloginlog.getUserid());
+//            resultData.put("code", "0");
+//            resultData.put("message", "成功");
+//            return resultData;
+//        }
+//    }
+//
+//
+//    //获取用户权限
+//    public Map<String, Object> permission(Map<String, Object> requestData, Integer version) {
+//
+//        Map<String, Object> resultData = checkUserToken(requestData);
+//        if (!"0".equals(resultData.get("code"))) {
+//            return resultData;
+//        } else {
+//            Optional<String> userToken = getValue("usertoken", requestData);
+//            Optional<String> sessionId = getValue("sessionid", requestData);
+//            Userloginlog userloginlog = userloginlogService.findByUserToken(userToken.get(), sessionId.get());
+//            if ("0".equals(version)) {
+//                List<Permissions> ps = permissionsService.getPermissions(userloginlog.getUserid().toString());
+//                resultData = new HashMap<>();
+//                resultData.put("code", "0");
+//                resultData.put("returnData", ps);
+//            } else {
+//                List<Map<String, Object>> ps = permissionsService.getPermissionsOld(userloginlog.getUserid().toString());
+//                resultData = new HashMap<>();
+//                resultData.put("code", "0");
+//                resultData.put("returnData", ps);
+//            }
+//        }
+//        return resultData;
+//    }
+//
+//    //应用API及数据权限
+//    public Map<String, Object> changePassword(Map<String, Object> requestData) {
+//
+//        Map<String, Object> resultData = checkUserToken(requestData);
+//        if (!"0".equals(resultData.get("code"))) {
+//            return resultData;
+//        } else {
+//            Optional<String> usertoken = getValue("usertoken", requestData);
+//            Optional<String> oldPassword = getValue("oldpassword", requestData);
+//            Optional<String> password = getValue("password", requestData);
+//
+//            Optional<String> userToken = getValue("usertoken", requestData);
+//            Optional<String> sessionId = getValue("sessionid", requestData);
+//            Userloginlog userloginlog = userloginlogService.findByUserToken(userToken.get(), sessionId.get());
+//            Integer userId = userloginlog.getUserid();
+//            Userinfo userinfo = userinfoService.findByUserId(userId);
+//            if (Objects.nonNull(userinfo)) {
+//                String userpassword = userinfo.getUserpassword();
+//                if (!userpassword.equals(oldPassword.get())) {
+//                    resultData.put("message", "密码错误");
+//                    resultData.put("code", "-1");
+//                    return resultData;
+//                } else {
+//                    userinfoService.updateUserPassword(userId, password.get());
+//                }
+//                resultData = new HashMap<>();
+//                resultData.put("code", "0");
+//                resultData.put("message", "修改成功");
+//            }
+//
+//        }
+//        return resultData;
+//    }
+//
+//    //用户心跳
+//    public Map<String, Object> userHeartbeat(Map<String, Object> requestData) {
+//        Map<String, Object> resultData = checkUserToken(requestData);
+//        if (!"0".equals(resultData.get("code"))) {
+//            return resultData;
+//        } else {
+//            resultData = new HashMap<>();
+//            Optional<String> userToken = getValue("usertoken", requestData);
+//            Optional<String> sessionId = getValue("sessionid", requestData);
+//            Userloginlog userloginlog1 = userloginlogService.findByUserToken(userToken.get(), sessionId.get());
+//            if (Objects.nonNull(userloginlog1)) {
+//                List<Userloginlog> userloginlogs = userloginlogService.findByUserId(userloginlog1.getUserid());
+//
+//                if (Objects.nonNull(userloginlogs) && !userloginlogs.isEmpty()) {
+//                    for (Userloginlog userloginlog : userloginlogs) {
+//
+//                        userloginlogService.updateLoginLogUserLastTimeById(userloginlog.getLoginid(), sessionId.get());
+//
+//                        resultData.put("code", "0");
+//                        resultData.put("message", "用户在线");
+//
+//                    }
+//                    if (resultData.isEmpty()) {
+//                        resultData.put("code", "-1");
+//                        resultData.put("message", "查询失败");
+//                    }
+//
+//                } else {
+//                    resultData.put("code", "-1");
+//                    resultData.put("message", "查询失败");
+//                }
+//            }
+//        }
+//        return resultData;
+//    }
+//
+//
+//    private Optional<String> getValue(String key, Map<String, Object> data) {
+//        return alias.getOrDefault(key, Collections.singletonList(key)).stream().map(data::get).filter(Objects::nonNull).map(Object::toString).findAny();
+//    }
+//}