deason 7 年之前
父節點
當前提交
07ad7e4bc8

+ 2 - 0
src/main/java/cn/com/qmth/examcloud/app/ApiApplication.java

@@ -11,7 +11,9 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.builder.SpringApplicationBuilder;
 import org.springframework.boot.web.support.SpringBootServletInitializer;
+import org.springframework.scheduling.annotation.EnableAsync;
 
+@EnableAsync
 @SpringBootApplication
 public class ApiApplication extends SpringBootServletInitializer {
 

+ 8 - 2
src/main/java/cn/com/qmth/examcloud/app/config/AccessInterceptor.java

@@ -25,6 +25,13 @@ public class AccessInterceptor extends HandlerInterceptorAdapter {
 
     @Override
     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+        //异步保存设备访问记录
+        DeviceRecord record = this.parseParams(request);
+        deviceRecordService.addDeviceRecord(record);
+        return true;
+    }
+
+    private DeviceRecord parseParams(HttpServletRequest request) {
         String system = request.getHeader("system");
         String deviceId = request.getHeader("deviceId");
         String netType = request.getHeader("netType");
@@ -54,8 +61,7 @@ public class AccessInterceptor extends HandlerInterceptorAdapter {
         record.setLoginToken(token);
         record.setUrl(url);
         record.setCreateDate(new Date());
-        deviceRecordService.addDeviceRecord(record);
-        return true;
+        return record;
     }
 
 }

+ 2 - 2
src/main/java/cn/com/qmth/examcloud/app/config/InterceptorConfig.java

@@ -23,8 +23,8 @@ public class InterceptorConfig extends WebMvcConfigurerAdapter {
     @Override
     public void addInterceptors(InterceptorRegistry registry) {
         registry.addInterceptor(accessInterceptor())
-                .addPathPatterns("/**")
-                .excludePathPatterns("/");
+                .addPathPatterns("/api/**")
+                .excludePathPatterns("/", "/swagger-resources");
         super.addInterceptors(registry);
     }
 

+ 2 - 3
src/main/java/cn/com/qmth/examcloud/app/controller/DeviceRecordController.java

@@ -13,14 +13,13 @@ import cn.com.qmth.examcloud.app.service.DeviceRecordService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
 
-import java.util.List;
-
 /**
  * 设备访问记录Controller
  */
@@ -38,7 +37,7 @@ public class DeviceRecordController {
 
     @ResponseBody
     @RequestMapping(value = "/list", method = RequestMethod.POST)
-    public Result<List<DeviceRecord>> list(@RequestBody DeviceRecord params) throws Exception {
+    public Result<Page<DeviceRecord>> list(@RequestBody DeviceRecord params) throws Exception {
         return deviceRecordService.getDeviceRecordList(params);
     }
 

+ 6 - 5
src/main/java/cn/com/qmth/examcloud/app/service/DeviceRecordService.java

@@ -13,13 +13,13 @@ import cn.com.qmth.examcloud.app.repository.DeviceRecordRepository;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.util.Assert;
 
-import java.util.List;
-
 /**
  * 设备访问记录Service
  */
@@ -29,10 +29,11 @@ public class DeviceRecordService {
     @Autowired
     private DeviceRecordRepository deviceRecordRepository;
 
-    public Result<List<DeviceRecord>> getDeviceRecordList(DeviceRecord params) {
+    public Result<Page<DeviceRecord>> getDeviceRecordList(DeviceRecord params) {
         Specification<DeviceRecord> spec = null;
-        List<DeviceRecord> list = deviceRecordRepository.findAll(spec);
-        return new Result<>().success(list);
+        Pageable pageable = null;
+        Page<DeviceRecord> page = deviceRecordRepository.findAll(spec, pageable);
+        return new Result<>().success(page);
     }
 
     @Async