deason 6 gadi atpakaļ
vecāks
revīzija
ddad0095d5

+ 23 - 6
src/main/java/cn/com/qmth/examcloud/app/controller/DeviceRecordController.java

@@ -9,17 +9,21 @@ package cn.com.qmth.examcloud.app.controller;
 
 import cn.com.qmth.examcloud.app.model.DeviceRecord;
 import cn.com.qmth.examcloud.app.model.DeviceRecordQuery;
+import cn.com.qmth.examcloud.app.model.LoginInfo;
 import cn.com.qmth.examcloud.app.model.Result;
 import cn.com.qmth.examcloud.app.service.DeviceRecordService;
+import cn.com.qmth.examcloud.app.service.UserAuthService;
+import org.apache.commons.lang3.StringUtils;
 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 org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.*;
+
+import static cn.com.qmth.examcloud.app.model.Constants.PARAM_KEY;
+import static cn.com.qmth.examcloud.app.model.Constants.PARAM_TOKEN;
 
 /**
  * 设备访问记录Controller
@@ -30,15 +34,28 @@ public class DeviceRecordController {
     private static Logger log = LoggerFactory.getLogger(DeviceRecordController.class);
     @Autowired
     private DeviceRecordService deviceRecordService;
+    @Autowired
+    private UserAuthService userAuthService;
 
     @RequestMapping(value = "/list", method = RequestMethod.GET)
-    public String list() {
+    public String list(@RequestParam String key, @RequestParam String token, Model model) throws Exception {
+        model.addAttribute(PARAM_KEY, key);
+        model.addAttribute(PARAM_TOKEN, token);
         return "deviceRecord/list";
     }
 
     @ResponseBody
     @RequestMapping(value = "/list", method = RequestMethod.POST)
-    public Result<Page<DeviceRecord>> list(@RequestBody(required = false) DeviceRecordQuery params) throws Exception {
+    public Result<Page<DeviceRecord>> list(@RequestBody(required = false) DeviceRecordQuery params,
+                                           @RequestParam(required = false) String key,
+                                           @RequestParam(required = false) String token) throws Exception {
+        if (StringUtils.isBlank(key) || StringUtils.isBlank(token)) {
+            throw new IllegalArgumentException("[Param] key or token must be not null.");
+        }
+        /*LoginInfo loginInfo = userAuthService.getLoginInfo(key);
+        if (loginInfo == null || !token.equals(loginInfo.getToken())) {
+            throw new IllegalArgumentException("[Param] key or token is wrong.");
+        }*/
         return deviceRecordService.getDeviceRecordList(params);
     }
 

+ 16 - 14
src/main/resources/templates/deviceRecord/list.ftl

@@ -119,26 +119,28 @@
         $("#contentTable").empty();
         $("#contentPage").empty();
         $.ajax({
-            url: basePath + '/device/record/list',
+            url: basePath + '/device/record/list?key=${key!}&token=${token!}',
             contentType: "application/json; charset=UTF-8",
             dataType: "json",
             type: "POST",
             data: JSON.stringify(params),
             success: function (response) {
-                if (response && response.code == '200') {
-                    var page = response.data;
-                    var list = render(page.content);
-                    $("#contentTable").html(list);
-
-                    $("#contentPage").createPage({
-                        totalElements: page.totalElements,
-                        totalPages: page.totalPages,
-                        current: curPageNo,
-                        backFn: function (current) {
-                            loadData(current);
-                        }
-                    });
+                if (!response || response.code != '200') {
+                    console.error(response);
+                    return;
                 }
+                var page = response.data;
+                var list = render(page.content);
+                $("#contentTable").html(list);
+
+                $("#contentPage").createPage({
+                    totalElements: page.totalElements,
+                    totalPages: page.totalPages,
+                    current: curPageNo,
+                    backFn: function (current) {
+                        loadData(current);
+                    }
+                });
             }
         });
     }