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

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

@@ -3,6 +3,7 @@ package org.bfkj.api;
 
 import jakarta.servlet.http.HttpServletRequest;
 import org.bfkj.application.AuthApplicationImpl;
+import org.bfkj.domain.log.LogEntity;
 import org.bfkj.dtos.R;
 import org.bfkj.dtos.ServiceDto;
 import org.bfkj.services.SecurityService;
@@ -29,7 +30,7 @@ public class AuthManageApi {
             Map<String, Object> bodyMap = new HashMap<>(body);
             Map<String, Object> requestData = HttpRequestUtil.combineData(null, bodyMap, httpServletRequest);
 
-            ServiceDto<Map<String, Object>,Object> result = securityService.getToken(requestData);
+            ServiceDto<Map<String, Object>, LogEntity> result = securityService.getToken(requestData);
             if (result.isSuccess()) {
                 Map<String, Object> temp = new HashMap<>();
                 Map<String, Object> returnData = result.getReturnData().getReturnData();
@@ -57,7 +58,7 @@ public class AuthManageApi {
             Map<String, Object> bodyMap = new HashMap<>(body);
             Map<String, Object> requestData = HttpRequestUtil.combineData(null, bodyMap, httpServletRequest);
 
-            ServiceDto<Map<String, Object>,Object> result = securityService.getToken(requestData);
+            ServiceDto<Map<String, Object>,LogEntity> result = securityService.getToken(requestData);
             if (result.isSuccess()) {
                 Map<String, Object> returnData = result.getReturnData().getReturnData();
 
@@ -97,7 +98,7 @@ public class AuthManageApi {
             Map<String, Object> bodyMap = new HashMap<>(body);
             Map<String, Object> requestData = HttpRequestUtil.combineData(headers, bodyMap, httpServletRequest);
 
-            ServiceDto<Map<String, Object>,Object> result = securityService.refreshToken(requestData);
+            ServiceDto<Map<String, Object>,LogEntity> result = securityService.refreshToken(requestData);
             if (result.isSuccess()) {
                 Map<String, Object> returnData = result.getReturnData().getReturnData();
                 Object appToken = returnData.get("token");

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

@@ -4,11 +4,15 @@ package org.bfkj.api;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import jakarta.servlet.http.HttpServletRequest;
 import org.bfkj.domain.Permissions;
+import org.bfkj.domain.log.LogEntity;
 import org.bfkj.dtos.R;
 import org.bfkj.dtos.ServiceDto;
 import org.bfkj.services.SecurityService;
 import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RestController;
 
 import java.util.List;
 import java.util.Map;
@@ -34,9 +38,9 @@ public class SecurityApi {
      * @return
      */
     @PostMapping("user/getToken")
-    public ResponseEntity<R<Map<String,Object>>> getToken(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) throws JsonProcessingException {
+    public ResponseEntity<R<Map<String, Object>>> getToken(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) throws JsonProcessingException {
         Map<String, Object> requestData = combineData(headers, body, httpRequest);
-        ServiceDto<Map<String, Object>,Object> result = securityService.getToken(requestData);
+        ServiceDto<Map<String, Object>, LogEntity> result = securityService.getToken(requestData);
         return ResponseEntity.ok(result.getReturnData());
     }
 
@@ -47,9 +51,9 @@ public class SecurityApi {
      * @return
      */
     @PostMapping("user/refreshToken")
-    public ResponseEntity refreshToken(@RequestHeader Map<String, Object> headers, HttpServletRequest httpRequest) {
+    public ResponseEntity refreshToken(@RequestHeader Map<String, Object> headers, HttpServletRequest httpRequest) throws JsonProcessingException {
         Map<String, Object> requestData = combineData(headers, null, httpRequest);
-        ServiceDto<Map<String, Object>,Object> result = securityService.refreshToken(requestData);
+        ServiceDto<Map<String, Object>, LogEntity> result = securityService.refreshToken(requestData);
         return ResponseEntity.ok(result.getReturnData());
     }
 
@@ -61,10 +65,10 @@ public class SecurityApi {
      * @return
      */
     @PostMapping({"user/testToken", "foxlibc/testToken"})
-    public ResponseEntity testToken(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
+    public ResponseEntity testToken(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) throws JsonProcessingException {
         Map<String, Object> requestData = combineData(headers, body, httpRequest);
 
-        ServiceDto<Map<String, Object>,Object> result = securityService.verifyToken(requestData);
+        ServiceDto<Map<String, Object>, LogEntity> result = securityService.verifyToken(requestData);
         return ResponseEntity.ok(result.getReturnData());
     }
 
@@ -76,9 +80,9 @@ public class SecurityApi {
      * @return
      */
     @PostMapping({"user/verifyCode", "foxlibc/verification-code"})
-    public ResponseEntity getCode(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
+    public ResponseEntity getCode(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) throws JsonProcessingException {
         Map<String, Object> requestData = combineData(headers, body, httpRequest);
-        ServiceDto<Map<String, Object>,Object> result = securityService.verifyCode(requestData);
+        ServiceDto<Map<String, Object>, LogEntity> result = securityService.verifyCode(requestData);
         return ResponseEntity.ok(result.getReturnData());
     }
 
@@ -90,9 +94,9 @@ public class SecurityApi {
      * @return
      */
     @PostMapping({"user/forceLogin", "foxlibc/force_sign"})
-    public ResponseEntity forceLogin(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
+    public ResponseEntity forceLogin(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) throws JsonProcessingException {
         Map<String, Object> requestData = combineData(headers, body, httpRequest);
-        ServiceDto<Map<String, Object>,Object> result = securityService.forceLogin(requestData);
+        ServiceDto<Map<String, Object>, LogEntity> result = securityService.forceLogin(requestData);
         return ResponseEntity.ok(result.getReturnData());
     }
 
@@ -104,9 +108,9 @@ public class SecurityApi {
      * @return
      */
     @PostMapping({"user/login", "foxlibc/sign-in"})
-    public ResponseEntity login(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
+    public ResponseEntity login(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) throws JsonProcessingException {
         Map<String, Object> requestData = combineData(headers, body, httpRequest);
-        ServiceDto<Map<String, Object>,Object> result = securityService.login(requestData);
+        ServiceDto<Map<String, Object>, LogEntity> result = securityService.login(requestData);
         return ResponseEntity.ok(result.getReturnData());
     }
 
@@ -118,9 +122,9 @@ public class SecurityApi {
      * @return
      */
     @PostMapping({"user/permissions", "foxlibc/permissions"})
-    public ResponseEntity getPermissions(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
+    public ResponseEntity getPermissions(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) throws JsonProcessingException {
         Map<String, Object> requestData = combineData(headers, body, httpRequest);
-        ServiceDto<List<Permissions>,Object> result = securityService.permission(requestData);
+        ServiceDto<List<Permissions>, LogEntity> result = securityService.permission(requestData);
         return ResponseEntity.ok(result.getReturnData());
     }
 
@@ -133,9 +137,9 @@ public class SecurityApi {
      * @return
      */
     @PostMapping({"user/changePassword", "foxlibc/reset-passwd"})
-    public ResponseEntity changePwd(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
+    public ResponseEntity changePwd(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) throws JsonProcessingException {
         Map<String, Object> requestData = combineData(headers, body, httpRequest);
-        ServiceDto<Map<String,Object>,Object> result = securityService.changePassword(requestData);
+        ServiceDto<Map<String, Object>, LogEntity> result = securityService.changePassword(requestData);
         return ResponseEntity.ok(result.getReturnData());
     }
 
@@ -147,9 +151,9 @@ public class SecurityApi {
      * @return
      */
     @PostMapping({"user/logOut", "foxlibc/sign-out"})
-    public ResponseEntity logOut(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) {
+    public ResponseEntity logOut(@RequestHeader Map<String, Object> headers, @RequestBody Map<String, Object> body, HttpServletRequest httpRequest) throws JsonProcessingException {
         Map<String, Object> requestData = combineData(headers, body, httpRequest);
-        ServiceDto<Map<String, Object>,Object> result = securityService.logOut(requestData);
+        ServiceDto<Map<String, Object>, LogEntity> result = securityService.logOut(requestData);
         return ResponseEntity.ok(result.getReturnData());
     }
 
@@ -163,7 +167,7 @@ public class SecurityApi {
     @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);
-        ServiceDto<List<Permissions>,Object> result = securityService.userHeartbeat(requestData);
+        ServiceDto<List<Permissions>, LogEntity> result = securityService.userHeartbeat(requestData);
         return ResponseEntity.ok(result.getReturnData());
     }
 }

+ 2 - 0
mainFactory/src/main/java/org/bfkj/apos/Log.java

@@ -1,5 +1,7 @@
 package org.bfkj.apos;
 
+import org.bfkj.domain.Appconnectlog;
+
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 

+ 25 - 27
mainFactory/src/main/java/org/bfkj/apos/LogAop.java

@@ -1,10 +1,10 @@
 package org.bfkj.apos;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
 import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.annotation.AfterReturning;
 import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.reflect.MethodSignature;
+import org.bfkj.domain.log.*;
 import org.bfkj.dtos.ServiceDto;
 import org.bfkj.utils.MyDbHelper;
 import org.springframework.beans.factory.annotation.Qualifier;
@@ -12,6 +12,7 @@ import org.springframework.stereotype.Component;
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
@@ -21,13 +22,12 @@ import java.util.concurrent.TimeUnit;
 @Component
 public class LogAop {
 
-    private ObjectMapper objectMapper = new ObjectMapper();
 
-    private List<Object> userlogs = new ArrayList<>();
-    private List<Object> applogs = new ArrayList<>();
-    private List<Object> systemerrlogs = new ArrayList<>();
-    private List<Object> serviceerrlogs = new ArrayList<>();
-    private List<Object> servicelogs = new ArrayList<>();
+    private List<Userlog> userlogs = new ArrayList<>();
+    private List<Applog> applogs = new ArrayList<>();
+    private List<Systemerrlog> systemerrlogs = new ArrayList<>();
+    private List<Serviceerrlog> serviceerrlogs = new ArrayList<>();
+    private List<Servicelog> servicelogs = new ArrayList<>();
 
     private final MyDbHelper myDbHelper;
     private final ScheduledExecutorService service;
@@ -39,43 +39,40 @@ public class LogAop {
 
 //        定时
         service.scheduleWithFixedDelay(() -> {
-            List<Object> temp;
             if (!applogs.isEmpty()) {
-                temp = applogs;
+                List<Applog> temp = applogs;
                 applogs = new ArrayList<>();
                 String sql = "insert into  applog(logtime, appid, apiname, requestip, sessionid, inputdata, outputdata) values(?,?,?,?,?,?,?)";
-                myDbHelper.JDBCBatch(sql, temp, null);
-                temp.clear();
+                myDbHelper.JDBCBatch(sql, temp.stream().map(it -> ( new Object[]{it.getLogtime(), it.getAppid(), it.getApiname(), it.getRequestip(), it.getSessionid(), it.getInputdata(), it.getOutputdata()})).map(it -> ((Object) Arrays.stream(it).toList())).toList(), null);
             }
             if (!userlogs.isEmpty()) {
-                temp = userlogs;
+                List<Userlog> temp = userlogs;
                 userlogs = new ArrayList<>();
                 String sql = "insert into userlog (logtime, userid, username, requestip, sessionid, pagename, pagecode, inputdata, outputdata) VALUES (?,?,?,?,?,?,?,?,?)";
-                myDbHelper.JDBCBatch(sql, temp, null);
-                temp.clear();
+                myDbHelper.JDBCBatch(sql, temp.stream().map(it -> (new Object[]{it.getLogtime(), it.getUserid(), it.getUsername(), it.getRequestip(), it.getSessionid(), it.getPagename(), it.getPagecode(), it.getInputdata(), it.getOutputdata()})).map(it -> ((Object) Arrays.stream(it).toList())).toList(), null);
             }
             if (!systemerrlogs.isEmpty()) {
-                temp = systemerrlogs;
+                List<Systemerrlog> temp = systemerrlogs;
                 systemerrlogs = new ArrayList<>();
                 String sql = "insert into systemerrlog (logtime, errordata) VALUES (?,?)";
-                myDbHelper.JDBCBatch(sql, temp, null);
-                temp.clear();
+                myDbHelper.JDBCBatch(sql, temp.stream().map(it -> (new Object[]{it.getLogtime(), it.getErrordata()})).map(it -> ((Object) Arrays.stream(it).toList())).toList(), null);
+
             }
 
 
             if (!servicelogs.isEmpty()) {
-                temp = servicelogs;
+                List<Servicelog> temp = servicelogs;
                 servicelogs = new ArrayList<>();
                 String sql = "insert into servicelog (logtime, serviceid, servicename, outputdata, inputdata, libraryid) VALUES (?,?,?,?,?,?)";
-                myDbHelper.JDBCBatch(sql, temp, null);
-                temp.clear();
+                myDbHelper.JDBCBatch(sql, temp.stream().map(it -> (new Object[]{it.getLogtime(), it.getServiceid(), it.getServicename(), it.getOutputdata(), it.getInputdata(), it.getLibraryid()})).map(it -> ((Object) Arrays.stream(it).toList())).toList(), null);
+
             }
 
             if (!serviceerrlogs.isEmpty()) {
-                temp = serviceerrlogs;
+                List<Serviceerrlog> temp = serviceerrlogs;
                 serviceerrlogs = new ArrayList<>();
                 String sql = "insert into serviceerrlog (logtime, serviceid, servicename, outputdata, inputdata, libraryid) VALUES (?,?,?,?,?,?)";
-                myDbHelper.JDBCBatch(sql, temp, null);
+                myDbHelper.JDBCBatch(sql, temp.stream().map(it -> (new Object[]{it.getLogtime(), it.getServiceid(), it.getServicename(), it.getOutputdata(), it.getInputdata(), it.getLibraryid()})).map(it -> ((Object) Arrays.stream(it).toList())).toList(), null);
                 temp.clear();
             }
 
@@ -88,17 +85,18 @@ public class LogAop {
         Method method = signature.getMethod();
         Log annotation = method.getAnnotation(Log.class);
         Log.LogType value = annotation.value();
+
         switch (value) {
             case SERVICE -> {
                 if (serviceDto.isSuccess()) {
-                    servicelogs.add(serviceDto.getLogData());
+                    servicelogs.add((Servicelog) serviceDto.getLogData());
                 } else {
-                    serviceerrlogs.add(serviceDto.getLogData());
+                    serviceerrlogs.add((Serviceerrlog) serviceDto.getLogData());
                 }
             }
-            case SYSTEM -> systemerrlogs.add(serviceDto.getLogData());
-            case USER -> userlogs.add(serviceDto.getLogData());
-            case APP -> applogs.add(serviceDto.getLogData());
+            case SYSTEM -> systemerrlogs.add((Systemerrlog) serviceDto.getLogData());
+            case USER -> userlogs.add((Userlog) serviceDto.getLogData());
+            case APP -> applogs.add((Applog) serviceDto.getLogData());
         }
 
     }

+ 4 - 0
mainFactory/src/main/java/org/bfkj/domain/log/LogEntity.java

@@ -0,0 +1,4 @@
+package org.bfkj.domain.log;
+
+public interface LogEntity {
+}

+ 5 - 5
mainFactory/src/main/java/org/bfkj/dtos/ServiceDto.java

@@ -1,12 +1,13 @@
 package org.bfkj.dtos;
 
-import java.util.List;
+import org.bfkj.domain.log.LogEntity;
 
 /**
  * @author l7871
  */
-public class ServiceDto<T,L> {
+public class ServiceDto<T, L extends LogEntity> {
     private R<T> returnData;
+    private L logData;
 
     private boolean success;
 
@@ -26,13 +27,12 @@ public class ServiceDto<T,L> {
         this.returnData = returnData;
     }
 
-    public List<L> getLogData() {
+    public L getLogData() {
         return logData;
     }
 
-    public void setLogData(List<L> logData) {
+    public void setLogData(L logData) {
         this.logData = logData;
     }
 
-    private List<L> logData;
 }

+ 290 - 172
mainFactory/src/main/java/org/bfkj/services/SecurityService.java

@@ -6,6 +6,9 @@ import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.bfkj.apos.Log;
 import org.bfkj.domain.*;
+import org.bfkj.domain.log.Applog;
+import org.bfkj.domain.log.LogEntity;
+import org.bfkj.domain.log.Userlog;
 import org.bfkj.dtos.R;
 import org.bfkj.dtos.ServiceDto;
 import org.bfkj.services.cache.CodeCacheService;
@@ -21,14 +24,8 @@ import java.util.*;
 public class SecurityService {
 
 
-    private DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
-
     private final static Map<String, List<String>> alias = new HashMap<>();
 
-    private ObjectMapper objectMapper = new ObjectMapper() {{
-        setSerializationInclusion(JsonInclude.Include.NON_NULL);
-    }};
-
     static {
         alias.put("appid", List.of("appid", "app_id", "appId", "APPID"));
         alias.put("appsecret", List.of("appSecret", "app_secret", "APP_SECRET", "appsecret", "APPSECRET"));
@@ -46,6 +43,10 @@ public class SecurityService {
     private final PermissionsService permissionsService;
     private final UserinfoService userinfoService;
     private final CodeCacheService codeCacheService;
+    private DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+    private ObjectMapper objectMapper = new ObjectMapper() {{
+        setSerializationInclusion(JsonInclude.Include.NON_NULL);
+    }};
 
     public SecurityService(ApplicationService applicationService, ApplicationconnectlogService applicationconnectlogService, UserloginlogService userloginlogService, PermissionsService permissionsService, UserinfoService userinfoService, CodeCacheService codeCacheService) {
         this.applicationService = applicationService;
@@ -59,12 +60,12 @@ public class SecurityService {
     //安全类服务
     //连接认证--获取连接令牌
     @Log(Log.LogType.APP)
-    public ServiceDto<Map<String, Object>,Object> getToken(Map<String, Object> requestData) throws JsonProcessingException {
+    public ServiceDto<Map<String, Object>, LogEntity> 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);
-        ServiceDto<Map<String, Object>,Object> serviceDto = new ServiceDto<>();
+        ServiceDto<Map<String, Object>, LogEntity> serviceDto = new ServiceDto<>();
         Application application = null;
         if (appid.isPresent() && appSecret.isPresent()) {
 //            无条件删除过期的数据
@@ -108,54 +109,75 @@ public class SecurityService {
             serviceDto.setSuccess(false);
             serviceDto.setReturnData(R.fail("-1", "appid 或者 appSecret 错误"));
         }
-//        logtime, appid, apiname, requestip, sessionid, inputdata, outputdata;
-        List<Object> logData = new ArrayList<>();
-        logData.add(LocalDateTime.now());
-        logData.add(appid.get());
-        logData.add((Objects.nonNull(application) ? application.getAppname() : null));
-        logData.add(requestIp.get());
-        logData.add(sessionId.get());
-        logData.add(objectMapper.writeValueAsString(requestData));
-        logData.add(objectMapper.writeValueAsString(serviceDto.getReturnData()));
+        Applog logData = new Applog();
+        logData.setAppid(appid.orElse(null));
+        logData.setApiname((Objects.nonNull(application) ? application.getAppname() : null));
+        logData.setRequestip(requestIp.get());
+        logData.setSessionid(sessionId.get());
+        logData.setInputdata(objectMapper.writeValueAsString(requestData));
+        logData.setOutputdata(objectMapper.writeValueAsString(serviceDto.getReturnData()));
         serviceDto.setLogData(logData);
         return serviceDto;
     }
 
     //校验连接令牌
-    public ServiceDto<Map<String, Object>,Object> verifyToken(Map<String, Object> requestData) {
+    @Log(Log.LogType.APP)
+    public ServiceDto<Map<String, Object>, LogEntity> verifyToken(Map<String, Object> requestData) throws JsonProcessingException {
         Optional<String> token = getValue("token", requestData);
 
         Optional<String> requestIp = getValue("requestip", requestData);
 
-        ServiceDto<Map<String, Object>,Object> serviceDto = new ServiceDto<>();
+        ServiceDto<Map<String, Object>, LogEntity> serviceDto = new ServiceDto<>();
+        String appid = null;
         if (token.isEmpty()) {
             serviceDto.setSuccess(false);
             serviceDto.setReturnData(R.fail("-1", "token错误"));
         } else {
             Appconnectlog applicationLog = applicationconnectlogService.findByTokenAndRequestIp(token.get(), requestIp.get());
-            if (LocalDateTime.now().isAfter(applicationLog.getExpiretime())) {
-                serviceDto.setSuccess(false);
-                serviceDto.setReturnData(R.fail("-1", "token已过期"));
-            } else {
-                serviceDto.setSuccess(true);
 
+            if (Objects.nonNull(applicationLog)) {
+                appid = applicationLog.getAppid();
+                if (LocalDateTime.now().isAfter(applicationLog.getExpiretime())) {
+                    serviceDto.setSuccess(false);
+                    serviceDto.setReturnData(R.fail("-1", "token已过期"));
+                } else {
+                    serviceDto.setSuccess(true);
+
+                    Map<String, Object> data = new HashMap<>();
+                    data.put("validstatus", true);
+                    data.put("appid", applicationLog.getAppid());
+                    serviceDto.setReturnData(R.success("0", "token校验通过", data));
+                }
+            } else {
                 Map<String, Object> data = new HashMap<>();
-                data.put("validstatus", true);
-                data.put("appid", applicationLog.getAppid());
-                serviceDto.setReturnData(R.success("0", "token校验通过", data));
+                data.put("validstatus", false);
+                serviceDto.setReturnData(R.success("-1", "token校验通过", data));
             }
         }
+        Applog logData = new Applog();
+        logData.setAppid(appid);
+        Application application = applicationService.findByAppId(appid);
+
+        logData.setApiname((Objects.nonNull(application) ? application.getAppname() : null));
+
+        logData.setRequestip(requestIp.get());
+        Optional<String> sessionId = getValue("sessionid", requestData);
+        logData.setSessionid(sessionId.get());
+        logData.setInputdata(objectMapper.writeValueAsString(requestData));
+        logData.setOutputdata(objectMapper.writeValueAsString(serviceDto.getReturnData()));
+        serviceDto.setLogData(logData);
         return serviceDto;
     }
 
     //刷新连接令牌
-    public ServiceDto<Map<String, Object>,Object> refreshToken(Map<String, Object> requestData) {
-        ServiceDto<Map<String, Object>,Object> verified = verifyToken(requestData);
+    @Log(Log.LogType.APP)
+    public ServiceDto<Map<String, Object>, LogEntity> refreshToken(Map<String, Object> requestData) throws JsonProcessingException {
+        ServiceDto<Map<String, Object>, LogEntity> verified = verifyToken(requestData);
 
         if (!verified.isSuccess()) {
             return verified;
         }
-        ServiceDto<Map<String, Object>,Object> resultData = new ServiceDto<>();
+        ServiceDto<Map<String, Object>, LogEntity> resultData = new ServiceDto<>();
         Optional<String> requestIp = getValue("requestIp", requestData);
         Optional<String> token = getValue("token", requestData);
         String appid = (String) verified.getReturnData().getReturnData().get("appid");
@@ -173,111 +195,156 @@ public class SecurityService {
             resultData.setSuccess(false);
         }
 
+        Applog logData = new Applog();
+        logData.setAppid(appid);
 
+        logData.setApiname((Objects.nonNull(application) ? application.getAppname() : null));
+
+        logData.setRequestip(requestIp.get());
+        Optional<String> sessionId = getValue("sessionid", requestData);
+        logData.setSessionid(sessionId.get());
+        logData.setInputdata(objectMapper.writeValueAsString(requestData));
+        logData.setOutputdata(objectMapper.writeValueAsString(resultData.getReturnData()));
+        resultData.setLogData(logData);
         return resultData;
     }
 
     //获取登录验证码
-    public ServiceDto<Map<String, Object>,Object> verifyCode(Map<String, Object> requestData) {
-        ServiceDto<Map<String, Object>,Object> resultData = new ServiceDto<>();
-        ServiceDto<Map<String, Object>,Object> verified = verifyToken(requestData);
-        if (!verified.isSuccess()) {
-            return verified;
-        }
-        String appid = (String) verified.getReturnData().getReturnData().get("appid");
+    @Log(Log.LogType.APP)
+    public ServiceDto<Map<String, Object>, LogEntity> verifyCode(Map<String, Object> requestData) throws JsonProcessingException {
+
+        ServiceDto<Map<String, Object>, LogEntity> resultData = verifyToken(requestData);
+        Optional<String> appidOpt = Optional.empty();
+        Optional<String> appnameOpt = Optional.empty();
         Optional<String> sessionId = getValue("sessionid", requestData);
         Optional<String> requestIp = getValue("requestip", requestData);
-        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(), appid, securitycodeeffective, requestIp.get());
+        if (resultData.isSuccess()) {
+            String appid = (String) resultData.getReturnData().getReturnData().get("appid");
+            appidOpt.of(appid);
+            Application application = applicationService.findByAppId(appid);
+            if (Objects.nonNull(application)) {
+                appnameOpt.of(application.getAppname());
+                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(), appid, securitycodeeffective, requestIp.get());
+
 //            编译后的验证码
-        Map<String, Object> data = new HashMap<>();
-        data.put("verifyCodeImage", verifyCodeImage);
-        resultData.setReturnData(R.success("0", data));
-        resultData.setSuccess(true);
+                Map<String, Object> data = new HashMap<>();
+                data.put("verifyCodeImage", verifyCodeImage);
+                resultData.setReturnData(R.success("0", data));
+                resultData.setSuccess(true);
+
+            }
+        }
+        Applog logData = new Applog();
+        logData.setAppid(appidOpt.orElse(null));
+
+        logData.setApiname(appnameOpt.orElse(null));
+
+        logData.setRequestip(requestIp.get());
+        logData.setSessionid(sessionId.get());
+        logData.setInputdata(objectMapper.writeValueAsString(requestData));
+        logData.setOutputdata(objectMapper.writeValueAsString(resultData.getReturnData()));
+        resultData.setLogData(logData);
 
         return resultData;
     }
 
 
     //用户登录
-    public ServiceDto<Map<String, Object>,Object> login(Map<String, Object> requestData) {
+    @Log(Log.LogType.USER)
+    public ServiceDto<Map<String, Object>, LogEntity> login(Map<String, Object> requestData) throws JsonProcessingException {
 //        首先,通过verifyToken方法验证app的令牌(token)是否有效(返回是否有效、appid)。
-        ServiceDto<Map<String, Object>,Object> resultData = new ServiceDto<>();
-        ServiceDto<Map<String, Object>,Object> verified = verifyToken(requestData);
-        if (!verified.isSuccess()) {
-            return verified;
-        }
-
-        String appid = verified.getReturnData().getReturnData().get("appid").toString();
         Optional<String> requestip = getValue("requestip", requestData);
         Optional<String> sessionid = getValue("sessionid", requestData);
         Optional<String> username = getValue("username", requestData);
         Optional<String> password = getValue("password", requestData);
         Optional<String> verifycode = getValue("verifycode", requestData);
-        Application application = applicationService.findByAppId(appid);
-        String securitycoderule = application.getSecuritycoderule();
-        if (Objects.nonNull(securitycoderule) && !codeCacheService.check(verifycode.get(), sessionid.get(), appid, requestip.get())) {
-            resultData.setSuccess(false);
-            resultData.setReturnData(R.fail("-1", "验证码错误"));
-            return resultData;
-        }
+        ServiceDto<Map<String, Object>, LogEntity> resultData = verifyToken(requestData);
+        Optional<Long> userid = Optional.empty();
+        if (resultData.isSuccess()) {
 
-        Userinfo userinfo = userinfoService.findByUsernameAndPassword(username.get(), password.get());
-        if (Objects.isNull(userinfo)) {
-            resultData.setSuccess(false);
-            resultData.setReturnData(R.fail("-1", "用户名或密码错误"));
-            return resultData;
-        }
+            String appid = resultData.getReturnData().getReturnData().get("appid").toString();
 
-        Userloginlog userloginlog = userloginlogService.findByUserIdAndSessionId(userinfo.getUserid(), sessionid.get());
+            Application application = applicationService.findByAppId(appid);
+            String securitycoderule = application.getSecuritycoderule();
+//        if (Objects.nonNull(securitycoderule) && !codeCacheService.check(verifycode.get(), sessionid.get(), appid, requestip.get())) {
+//            resultData.setSuccess(false);
+//            resultData.setReturnData(R.fail("-1", "验证码错误"));
+//            return resultData;
+//        }
 
-        Map<String, Object> data = new HashMap<>();
-        if (Objects.nonNull(userloginlog)) {
 
-            data.put("userstatus", "2");
-            resultData.setSuccess(true);
-            resultData.setReturnData(R.fail("0", "data"));
-            return resultData;
-        }
-        Integer multilogin = application.getMultilogin();
-        Appconnectlog appconnectlog = new Appconnectlog();
-        if (1 == multilogin) {
-            applicationconnectlogService.save(appconnectlog);
+            Userinfo userinfo = userinfoService.findByUsernameAndPassword(username.get(), password.get());
+            userid.ofNullable(userinfo.getUserid());
+            if (Objects.isNull(userinfo)) {
+                resultData.setSuccess(false);
+                resultData.setReturnData(R.fail("-1", "用户名或密码错误"));
+            } else {
 
-            data.put("userstatus", "0");
-            resultData.setSuccess(true);
-            resultData.setReturnData(R.fail("0", "data"));
-            return resultData;
-        }
+                Userloginlog userloginlog = userloginlogService.findByUserIdAndSessionId(userinfo.getUserid(), sessionid.get());
+
+                Map<String, Object> data = new HashMap<>();
+                if (Objects.nonNull(userloginlog)) {
+
+                    data.put("userstatus", "2");
+                    resultData.setSuccess(true);
+
+                    resultData.setReturnData(R.success("0", data));
+                } else {
+                    Integer multilogin = application.getMultilogin();
+                    Optional<String> token = getValue("token", requestData);
+                    if (1 == multilogin) {
+                        userloginlogService.insertUserLoginLog(requestip.get(), sessionid.get(), userinfo.getUserid(), null, token.get(), appid);
+
+                        data.put("userstatus", "0");
+                        resultData.setSuccess(true);
+                        resultData.setReturnData(R.success("0", data));
+                    } else {
 
 
-        List<Userloginlog> userloginlogs = userloginlogService.findByUserId(userinfo.getUserid());
+                        List<Userloginlog> userloginlogs = userloginlogService.findByUserId(userinfo.getUserid());
 //            没有登录
-        if (userloginlogs.isEmpty()) {
-            data.put("userstatus", "0");
-            resultData.setSuccess(true);
-            resultData.setReturnData(R.fail("0", "data"));
-        } else {
-            data.put("userstatus", "1");
-            resultData.setSuccess(true);
-            resultData.setReturnData(R.fail("0", "data"));
+                        if (userloginlogs.isEmpty()) {
+                            data.put("userstatus", "0");
+                            resultData.setSuccess(true);
+                            resultData.setReturnData(R.fail("0", "data"));
+                        } else {
+                            data.put("userstatus", "1");
+                            resultData.setSuccess(true);
+                            resultData.setReturnData(R.fail("0", "data"));
+                        }
+                        Appconnectlog appconnectlog = new Appconnectlog();
+                        appconnectlog.setApptoken(appconnectlog.getApptoken());
+                        appconnectlog.setAppid(appid);
+                        appconnectlog.setLasttime(LocalDateTime.now());
+                        appconnectlog.setRequesttime(LocalDateTime.now());
+                        appconnectlog.setRequestip(requestip.get());
+                        appconnectlog.setExpiretime(LocalDateTime.now().plusSeconds(application.getApptokeneffective()));
+                        applicationconnectlogService.save(appconnectlog);
+
+                        codeCacheService.remove(verifycode.get(), sessionid.get(), appid, requestip.get());
+                    }
+                }
+            }
         }
-        appconnectlog.setApptoken(appconnectlog.getApptoken());
-        appconnectlog.setAppid(appid);
-        appconnectlog.setLasttime(LocalDateTime.now());
-        appconnectlog.setRequesttime(LocalDateTime.now());
-        appconnectlog.setRequestip(requestip.get());
-        appconnectlog.setExpiretime(LocalDateTime.now().plusSeconds(application.getApptokeneffective()));
-        applicationconnectlogService.save(appconnectlog);
-
-        codeCacheService.remove(verifycode.get(), sessionid.get(), appid, requestip.get());
+
+        Userlog logData = new Userlog();
+        logData.setUserid(userid.orElse(null));
+
+        logData.setUsername(username.orElse(null));
+
+        logData.setRequestip(requestip.get());
+        Optional<String> sessionId = getValue("sessionid", requestData);
+        logData.setSessionid(sessionId.orElse(null));
+        logData.setInputdata(objectMapper.writeValueAsString(requestData));
+        logData.setOutputdata(objectMapper.writeValueAsString(resultData.getReturnData()));
+        resultData.setLogData(logData);
         return resultData;
 
 
@@ -313,43 +380,59 @@ public class SecurityService {
 
 
     //强制登录
-    public ServiceDto<Map<String, Object>,Object> forceLogin(Map<String, Object> requestData) {
-
-        ServiceDto<Map<String, Object>,Object> verified = verifyToken(requestData);
-        if (!verified.isSuccess()) {
-            return verified;
-        }
+    @Log(Log.LogType.USER)
+    public ServiceDto<Map<String, Object>, LogEntity> forceLogin(Map<String, Object> requestData) throws JsonProcessingException {
         Optional<String> requestip = getValue("requestip", requestData);
         Optional<String> sessionid = getValue("sessionid", requestData);
-        Optional<String> apptoken = getValue("token", requestData);
-        String appid = verified.getReturnData().getReturnData().get("appid").toString();
-        Application application = applicationService.findByAppId(appid);
-        ServiceDto<Map<String, Object>,Object> result = new ServiceDto<>();
-        result.setSuccess(false);
-        if (Objects.isNull(application)) {
-            result.setReturnData(R.fail("-1", "没有找到应用配置"));
-            return result;
-        }
-        Userloginlog userloginlog = userloginlogService.findByAppTokenAndSessionIdAndRequestIp(apptoken.get(), sessionid.get(), requestip.get());
-        if (Objects.isNull(userloginlog)) {
-            result.setReturnData(R.fail("-1", "登录失败"));
-            return result;
-        }
-        Long securitycodeeffective = application.getSecuritycodeeffective();
-        LocalDateTime expiresTime = LocalDateTime.now().plusSeconds(securitycodeeffective);
-        String userToken = CommonUtil.toMD5("%s:%s".formatted(LocalDateTime.now(), sessionid.get()));
-        userloginlogService.updateUserToken(userloginlog.getLoginid(), userToken);
-        result.setSuccess(true);
-        HashMap<String, Object> data = new HashMap<>();
-        data.put("expirestime", expiresTime);
-        data.put("usertoken", userToken);
-        result.setReturnData(R.success("0", data));
-        Integer multilogin = application.getMultilogin();
-        if (multilogin == 1) {
-            userloginlogService.removeByLogIdAndUserIdAndAppId(userloginlog.getLoginid(), userloginlog.getUserid(), userloginlog.getAppid());
-        } else {
-            userloginlogService.removeExpires();
+        ServiceDto<Map<String, Object>, LogEntity> result = verifyToken(requestData);
+        Optional<Long> userid = Optional.empty();
+        Optional<String> username = Optional.empty();
+        if (result.isSuccess()) {
+            Optional<String> apptoken = getValue("token", requestData);
+            String appid = result.getReturnData().getReturnData().get("appid").toString();
+            Application application = applicationService.findByAppId(appid);
+            result.setSuccess(false);
+            if (Objects.isNull(application)) {
+                result.setReturnData(R.fail("-1", "没有找到应用配置"));
+            } else {
+                Userloginlog userloginlog = userloginlogService.findByAppTokenAndSessionIdAndRequestIp(apptoken.get(), sessionid.get(), requestip.get());
+                if (Objects.isNull(userloginlog)) {
+                    result.setReturnData(R.fail("-1", "登录失败"));
+                } else {
+                    userid.of(userloginlog.getUserid());
+                    Userinfo userinfo = userinfoService.findByUserId(userid.get());
+                    username.of(userinfo.getUsername());
+                    Long securitycodeeffective = application.getSecuritycodeeffective();
+                    LocalDateTime expiresTime = LocalDateTime.now().plusSeconds(securitycodeeffective);
+                    String userToken = CommonUtil.toMD5("%s:%s".formatted(LocalDateTime.now(), sessionid.get()));
+                    userloginlogService.updateUserToken(userloginlog.getLoginid(), userToken);
+                    result.setSuccess(true);
+                    HashMap<String, Object> data = new HashMap<>();
+                    data.put("expirestime", expiresTime);
+                    data.put("usertoken", userToken);
+                    result.setReturnData(R.success("0", data));
+                    Integer multilogin = application.getMultilogin();
+                    if (multilogin == 1) {
+                        userloginlogService.removeByLogIdAndUserIdAndAppId(userloginlog.getLoginid(), userloginlog.getUserid(), userloginlog.getAppid());
+                    } else {
+                        userloginlogService.removeExpires();
+                    }
+                }
+            }
         }
+
+
+        Userlog logData = new Userlog();
+        logData.setUserid(userid.orElse(null));
+
+        logData.setUsername(username.orElse(null));
+
+
+        logData.setRequestip(requestip.get());
+        logData.setSessionid(sessionid.orElse(null));
+        logData.setInputdata(objectMapper.writeValueAsString(requestData));
+        logData.setOutputdata(objectMapper.writeValueAsString(result.getReturnData()));
+        result.setLogData(logData);
         return result;
 //        获取请求数据中的apptoken、sessionid和requestip。
 //        首先,通过verifyToken方法验证app的令牌(token)是否有效(返回是否有效、appid)。
@@ -372,14 +455,14 @@ public class SecurityService {
 
     }
 
-    private ServiceDto<Map<String, Object>,Object> checkUserToken(Map<String, Object> requestData) {
+    private ServiceDto<Map<String, Object>, LogEntity> 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);
-        ServiceDto<Map<String, Object>,Object> result = new ServiceDto<>();
+        ServiceDto<Map<String, Object>, LogEntity> result = new ServiceDto<>();
         if (userloginlog.getLastheartbeat().plusSeconds(application.getApptokeneffective()).isBefore(LocalDateTime.now())) {
             result.setSuccess(false);
             result.setReturnData(R.fail("-1", "用户token已过期"));
@@ -392,88 +475,123 @@ public class SecurityService {
     }
 
     //用户登出
-    public ServiceDto<Map<String, Object>,Object> logOut(Map<String, Object> requestData) {
-        ServiceDto<Map<String, Object>,Object> resultData = checkUserToken(requestData);
-        if (!resultData.isSuccess()) {
-            return resultData;
-        } else {
-
+    @Log(Log.LogType.USER)
+    public ServiceDto<Map<String, Object>, LogEntity> logOut(Map<String, Object> requestData) throws JsonProcessingException {
+        ServiceDto<Map<String, Object>, LogEntity> resultData = checkUserToken(requestData);
+        Optional<Long> userid = Optional.empty();
+        Optional<String> username = Optional.empty();
+        Optional<String> sessionId = getValue("sessionid", requestData);
+        Optional<String> requestIp = getValue("requestip", requestData);
+        if (resultData.isSuccess()) {
             Optional<String> userToken = getValue("usertoken", requestData);
-            Optional<String> sessionId = getValue("sessionid", requestData);
             Userloginlog userloginlog = userloginlogService.findByUserToken(userToken.get(), sessionId.get());
+            userid.of(userloginlog.getUserid());
+            Userinfo userinfo = userinfoService.findByUserId(userloginlog.getUserid());
+            username.of(userinfo.getUsername());
             userloginlogService.removeUserLoginLogByUserId(userloginlog.getUserid());
             permissionsService.removePermissions(userloginlog.getUserid());
             resultData.setReturnData(R.success("0", "成功", null));
-            return resultData;
         }
+
+        Userlog logData = new Userlog();
+        logData.setUserid(userid.orElse(null));
+        logData.setUsername(username.orElse(null));
+        logData.setRequestip(requestIp.get());
+        logData.setSessionid(sessionId.get());
+        logData.setInputdata(objectMapper.writeValueAsString(requestData));
+        logData.setOutputdata(objectMapper.writeValueAsString(resultData.getReturnData()));
+        resultData.setLogData(logData);
+        return resultData;
     }
 
 
     //获取用户权限
-    public ServiceDto<List<Permissions>,Object> permission(Map<String, Object> requestData) {
+    @Log(Log.LogType.USER)
+    public ServiceDto<List<Permissions>, LogEntity> permission(Map<String, Object> requestData) throws JsonProcessingException {
 
-        ServiceDto<Map<String, Object>,Object> checked = checkUserToken(requestData);
-        ServiceDto<List<Permissions>,Object> resultData = new ServiceDto<>();
+        ServiceDto<Map<String, Object>, LogEntity> checked = checkUserToken(requestData);
+        ServiceDto<List<Permissions>, LogEntity> resultData = new ServiceDto<>();
+        Optional<Long> userid = Optional.empty();
+        Optional<String> username = Optional.empty();
+        Optional<String> sessionId = getValue("sessionid", requestData);
+        Optional<String> requestIp = getValue("requestip", requestData);
         if (!checked.isSuccess()) {
             resultData.setSuccess(false);
             resultData.setReturnData(R.fail("-1", checked.getReturnData().getMessage()));
-            return resultData;
         } else {
             Optional<String> userToken = getValue("usertoken", requestData);
-            Optional<String> sessionId = getValue("sessionid", requestData);
             Userloginlog userloginlog = userloginlogService.findByUserToken(userToken.get(), sessionId.get());
-
+            userid.of(userloginlog.getUserid());
+            Userinfo userinfo = userinfoService.findByUserId(userloginlog.getUserid());
+            username.of(userinfo.getUsername());
             List<Permissions> ps = permissionsService.getPermissions(userloginlog.getUserid().toString());
             resultData.setReturnData(R.success("0", ps));
 
         }
+
+        Userlog logData = new Userlog();
+        logData.setUserid(userid.orElse(null));
+        logData.setUsername(username.orElse(null));
+        logData.setRequestip(requestIp.orElse(null));
+        logData.setSessionid(sessionId.orElse(null));
+        logData.setInputdata(objectMapper.writeValueAsString(requestData));
+        logData.setOutputdata(objectMapper.writeValueAsString(resultData.getReturnData()));
+        resultData.setLogData(logData);
         return resultData;
     }
 
     //应用API及数据权限
-    public ServiceDto<Map<String,Object>,Object> changePassword(Map<String, Object> requestData) {
-
-        ServiceDto<Map<String, Object>,Object> checked = checkUserToken(requestData);
-        ServiceDto<Map<String,Object>,Object> resultData = new ServiceDto<>();
-        if (!checked.isSuccess()) {
-            resultData.setSuccess(false);
-            resultData.setReturnData(R.fail("-1", checked.getReturnData().getMessage()));
-            return resultData;
-        } else {
+    public ServiceDto<Map<String, Object>, LogEntity> changePassword(Map<String, Object> requestData) throws JsonProcessingException {
+        Optional<Long> userid = Optional.empty();
+        Optional<String> username = Optional.empty();
+        Optional<String> sessionId = getValue("sessionid", requestData);
+        Optional<String> requestIp = getValue("requestip", requestData);
+        ServiceDto<Map<String, Object>, LogEntity> resultData = checkUserToken(requestData);
+        if (resultData.isSuccess()) {
             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());
             Long userId = userloginlog.getUserid();
+            userid.of(userId);
+
             Userinfo userinfo = userinfoService.findByUserId(userId);
             if (Objects.nonNull(userinfo)) {
+                username.of(userinfo.getUsername());
                 String userpassword = userinfo.getUserpassword();
                 if (!userpassword.equals(oldPassword.get())) {
                     resultData.setSuccess(false);
                     resultData.setReturnData(R.fail("-1", "密码错误"));
-                    return resultData;
                 } else {
                     userinfoService.updateUserPassword(userId, password.get());
                 }
                 resultData.setSuccess(true);
                 resultData.setReturnData(R.success("-1", "成功", null));
-                return resultData;
             } else {
 
                 resultData.setSuccess(false);
                 resultData.setReturnData(R.fail("-1", "用户没有找到"));
-                return resultData;
             }
 
         }
+
+
+        Userlog logData = new Userlog();
+        logData.setUserid(userid.orElse(null));
+        logData.setUsername(username.orElse(null));
+        logData.setRequestip(requestIp.get());
+        logData.setSessionid(sessionId.get());
+        logData.setInputdata(objectMapper.writeValueAsString(requestData));
+        logData.setOutputdata(objectMapper.writeValueAsString(resultData.getReturnData()));
+        resultData.setLogData(logData);
+        return resultData;
     }
 
     //用户心跳
-    public ServiceDto<List<Permissions>,Object> userHeartbeat(Map<String, Object> requestData) {
-        ServiceDto<Map<String, Object>,Object> checked = checkUserToken(requestData);
-        ServiceDto<List<Permissions>,Object> resultData = new ServiceDto<>();
+    public ServiceDto<List<Permissions>, LogEntity> userHeartbeat(Map<String, Object> requestData) {
+        ServiceDto<Map<String, Object>, LogEntity> checked = checkUserToken(requestData);
+        ServiceDto<List<Permissions>, LogEntity> resultData = new ServiceDto<>();
         if (!checked.isSuccess()) {
             resultData.setSuccess(false);
             resultData.setReturnData(R.fail("-1", checked.getReturnData().getMessage()));

+ 42 - 12
mainFactory/src/main/java/org/bfkj/services/UserinfoService.java

@@ -1,20 +1,29 @@
 package org.bfkj.services;
 
 
-import org.bfkj.domain.Appconnectlog;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
 import org.bfkj.domain.Userinfo;
 import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 
 @Service
 public class UserinfoService {
 
+
+    private ObjectMapper objectMapper = new ObjectMapper() {{
+        registerModule(new Jdk8Module());
+        registerModule(new JavaTimeModule());
+    }};
+
     private final Map<String, Userinfo> userInfoCache = new HashMap<>();
 
     private final JdbcTemplate securityJdbcTemplate;
@@ -26,7 +35,15 @@ public class UserinfoService {
 
     public Userinfo findByUserId(Long userId) {
 
-        return (Userinfo) securityJdbcTemplate.queryForObject("select * from userinfo where userid=?", new BeanPropertyRowMapper(Userinfo.class) , userId);
+        List<Map<String, Object>> maps = securityJdbcTemplate.queryForList("select * from userinfo where userid=?", userId);
+        if (maps.isEmpty()) {
+            return null;
+        }
+        try {
+            return objectMapper.readValue(objectMapper.writeValueAsString(maps.get(0)), Userinfo.class);
+        } catch (JsonProcessingException e) {
+            throw new RuntimeException(e);
+        }
 
     }
 
@@ -40,27 +57,40 @@ public class UserinfoService {
             if (Objects.nonNull(userinfo)) {
                 return userinfo;
             } else {
-                userinfo = (Userinfo) securityJdbcTemplate.queryForObject("select * from userinfo where  username =? ", new BeanPropertyRowMapper(Userinfo.class),  username);
-                userInfoCache.put(username, userinfo);
-                return userinfo;
+                List<Map<String, Object>> maps = securityJdbcTemplate.queryForList("select * from userinfo where  username =? ", username);
+                if (maps.isEmpty()) {
+                    return null;
+                }
+                try {
+                    userinfo = objectMapper.readValue(objectMapper.writeValueAsString(maps.get(0)), Userinfo.class);
+                    userInfoCache.put(username, userinfo);
+                    return userinfo;
+                } catch (JsonProcessingException e) {
+                    throw new RuntimeException(e);
+                }
 
             }
         }
 
     }
-    public Userinfo findByUsernameAndPassword(String username,String password) {
+
+    public Userinfo findByUsernameAndPassword(String username, String password) {
         synchronized (userInfoCache) {
             Userinfo userinfo = userInfoCache.get(username);
             if (Objects.nonNull(userinfo)) {
                 return userinfo;
             } else {
-                Object result = securityJdbcTemplate.queryForObject("select * from userinfo where  username =? and userpassword=? ", new BeanPropertyRowMapper(Userinfo.class), username, password);
-                if(Objects.isNull(result)){
+                List<Map<String, Object>> maps = securityJdbcTemplate.queryForList("select * from userinfo where  username =? and userpassword=? ", username, password);
+                if (maps.isEmpty()) {
                     return null;
                 }
-                userinfo = (Userinfo) result;
-                userInfoCache.put(username, userinfo);
-                return userinfo;
+                try {
+                    userinfo = objectMapper.readValue(objectMapper.writeValueAsString(maps.get(0)), Userinfo.class);
+                    userInfoCache.put(username, userinfo);
+                    return userinfo;
+                } catch (JsonProcessingException e) {
+                    throw new RuntimeException(e);
+                }
             }
         }
 

+ 16 - 9
mainFactory/src/main/java/org/bfkj/services/UserloginlogService.java

@@ -8,14 +8,12 @@ import jakarta.annotation.Nonnull;
 import jakarta.annotation.Nullable;
 import org.bfkj.domain.Userloginlog;
 import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 
 @Service
 public class UserloginlogService {
@@ -53,12 +51,12 @@ public class UserloginlogService {
 
     public Userloginlog findByUserIdAndSessionId(Long userId, String sessionId) {
 
-        Map<String, Object> result = securityJdbcTemplate.queryForMap("select * from userloginlog where userid=? and sessionid=? and isexpires=0 ", userId, sessionId);
-        if (Objects.isNull(result)) {
+        List<Map<String, Object>> result = securityJdbcTemplate.queryForList("select * from userloginlog where userid=? and sessionid=? and isexpires=0 ", userId, sessionId);
+        if (result.isEmpty()) {
             return null;
         }
         try {
-            return objectMapper.readValue(objectMapper.writeValueAsString(result), Userloginlog.class);
+            return objectMapper.readValue(objectMapper.writeValueAsString(result.get(0)), Userloginlog.class);
         } catch (JsonProcessingException e) {
             throw new RuntimeException(e);
         }
@@ -66,12 +64,12 @@ public class UserloginlogService {
 
     public Userloginlog findByAppTokenAndSessionIdAndRequestIp(String appToken, String sessionId, String requestIp) {
 
-        Map<String, Object> result = securityJdbcTemplate.queryForMap("select * from userloginlog where apptoken=? and sessionid=? and requestip=? and isexpires=0 ", appToken, sessionId, requestIp);
-        if (Objects.isNull(result)) {
+        List<Map<String, Object>> result = securityJdbcTemplate.queryForList("select * from userloginlog where apptoken=? and sessionid=? and requestip=? and isexpires=0 ", appToken, sessionId, requestIp);
+        if (result.isEmpty()) {
             return null;
         }
         try {
-            return objectMapper.readValue(objectMapper.writeValueAsString(result), Userloginlog.class);
+            return objectMapper.readValue(objectMapper.writeValueAsString(result.get(0)), Userloginlog.class);
         } catch (JsonProcessingException e) {
             throw new RuntimeException(e);
         }
@@ -94,7 +92,16 @@ public class UserloginlogService {
 
     public Userloginlog findByUserToken(String userToken, String sessionId) {
 
-        return (Userloginlog) securityJdbcTemplate.queryForObject("select * from userloginlog where isexpires=0 and usertoken=? and sessionid=?", new BeanPropertyRowMapper(Userloginlog.class), userToken, sessionId);
+        List<Map<String, Object>> maps = securityJdbcTemplate.queryForList("select * from userloginlog where isexpires=0 and usertoken=? and sessionid=?", userToken, sessionId);
+
+        if (maps.isEmpty()) {
+            return null;
+        }
+        try {
+            return objectMapper.readValue(objectMapper.writeValueAsString(maps.get(0)), Userloginlog.class);
+        } catch (JsonProcessingException e) {
+            throw new RuntimeException(e);
+        }
     }
 
 

+ 2 - 4
mainFactory/src/main/java/org/bfkj/services/cache/CodeCacheService.java

@@ -7,9 +7,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 
 @Service
 public class CodeCacheService {
@@ -28,7 +26,7 @@ public class CodeCacheService {
     }
 
     public boolean check(String code, String sessionId, String appid,String requestIp) {
-        Map<String, Object> map = securityJdbcTemplate.queryForMap("select * from tempsecuritycode where securitycode=? and sessionid=? and appid=? and requestip=?", code, sessionId, appid, requestIp);
+        List<Map<String, Object>> map = securityJdbcTemplate.queryForList("select * from tempsecuritycode where securitycode=? and sessionid=? and appid=? and requestip=?", code, sessionId, appid, requestIp);
         return Objects.nonNull(map) && !map.isEmpty();
 
     }