deason 7 роки тому
батько
коміт
b813b51e86

+ 7 - 5
src/main/java/cn/com/qmth/examcloud/app/controller/DeviceRecordController.java

@@ -8,6 +8,7 @@
 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.Result;
 import cn.com.qmth.examcloud.app.service.DeviceRecordService;
 import org.slf4j.Logger;
@@ -15,7 +16,10 @@ 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.*;
+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;
 
 /**
  * 设备访问记录Controller
@@ -34,10 +38,8 @@ public class DeviceRecordController {
 
     @ResponseBody
     @RequestMapping(value = "/list", method = RequestMethod.POST)
-    public Result<Page<DeviceRecord>> list(@RequestBody(required = false) DeviceRecord params,
-                                           @RequestParam(defaultValue = "1") Integer pageNo,
-                                           @RequestParam(defaultValue = "10") Integer pageSize) throws Exception {
-        return deviceRecordService.getDeviceRecordList(params, pageNo, pageSize);
+    public Result<Page<DeviceRecord>> list(@RequestBody(required = false) DeviceRecordQuery params) throws Exception {
+        return deviceRecordService.getDeviceRecordList(params);
     }
 
 }

+ 3 - 0
src/main/java/cn/com/qmth/examcloud/app/model/DeviceRecord.java

@@ -17,6 +17,9 @@ import java.util.Date;
 /**
  * 设备访问记录
  * 注:用于记录APP端调用接口时header中附带来源信息
+ *
+ * @author: fengdesheng
+ * @since: 2018/7/16
  */
 @Entity
 @Table(name = "app_device_record")

+ 42 - 0
src/main/java/cn/com/qmth/examcloud/app/model/DeviceRecordQuery.java

@@ -0,0 +1,42 @@
+/*
+ * *************************************************
+ * Copyright (c) 2018 QMTH. All Rights Reserved.
+ * Created by Deason on 2018-08-01 11:45:59.
+ * *************************************************
+ */
+
+package cn.com.qmth.examcloud.app.model;
+
+/**
+ * 设备访问记录查询类
+ *
+ * @author: fengdesheng
+ * @since: 2018/7/16
+ */
+public class DeviceRecordQuery extends DeviceRecord {
+    private Integer pageSize;
+    private Integer pageNo;
+
+    public Integer getPageSize() {
+        if (pageSize == null || pageSize < 1) {
+            pageSize = 1;
+        }
+        return pageSize;
+    }
+
+    public void setPageSize(Integer pageSize) {
+        this.pageSize = pageSize;
+    }
+
+    public Integer getPageNo() {
+        if (pageNo == null || pageNo < 1) {
+            pageNo = 1;
+        }
+        return pageNo;
+    }
+
+    public void setPageNo(Integer pageNo) {
+        this.pageNo = pageNo;
+    }
+
+}

+ 2 - 1
src/main/java/cn/com/qmth/examcloud/app/service/DeviceRecordService.java

@@ -8,6 +8,7 @@
 package cn.com.qmth.examcloud.app.service;
 
 import cn.com.qmth.examcloud.app.model.DeviceRecord;
+import cn.com.qmth.examcloud.app.model.DeviceRecordQuery;
 import cn.com.qmth.examcloud.app.model.Result;
 import org.springframework.data.domain.Page;
 
@@ -19,7 +20,7 @@ import org.springframework.data.domain.Page;
  */
 public interface DeviceRecordService {
 
-    Result<Page<DeviceRecord>> getDeviceRecordList(DeviceRecord params, Integer pageNo, Integer pageSize);
+    Result<Page<DeviceRecord>> getDeviceRecordList(DeviceRecordQuery params);
 
     void addDeviceRecord(DeviceRecord deviceRecord);
 

+ 3 - 8
src/main/java/cn/com/qmth/examcloud/app/service/impl/DeviceRecordServiceImpl.java

@@ -9,6 +9,7 @@ package cn.com.qmth.examcloud.app.service.impl;
 
 import cn.com.qmth.examcloud.app.dao.DeviceRecordRepository;
 import cn.com.qmth.examcloud.app.model.DeviceRecord;
+import cn.com.qmth.examcloud.app.model.DeviceRecordQuery;
 import cn.com.qmth.examcloud.app.model.Result;
 import cn.com.qmth.examcloud.app.service.DeviceRecordService;
 import org.apache.commons.lang3.StringUtils;
@@ -45,7 +46,7 @@ public class DeviceRecordServiceImpl implements DeviceRecordService {
 
     @SuppressWarnings("unchecked")
     @Override
-    public Result<Page<DeviceRecord>> getDeviceRecordList(DeviceRecord params, Integer pageNo, Integer pageSize) {
+    public Result<Page<DeviceRecord>> getDeviceRecordList(DeviceRecordQuery params) {
         Specification<DeviceRecord> spec = null;
         if (params != null) {
             spec = new Specification<DeviceRecord>() {
@@ -98,14 +99,8 @@ public class DeviceRecordServiceImpl implements DeviceRecordService {
                 }
             };
         }
-        if (pageNo < 1) {
-            pageNo = 1;
-        }
-        if (pageSize < 1) {
-            pageSize = 1;
-        }
         Sort sort = new Sort(Sort.Direction.DESC, "id");
-        Pageable pageable = new PageRequest(pageNo - 1, pageSize, sort);
+        Pageable pageable = new PageRequest(params.getPageNo() - 1, params.getPageSize(), sort);
         Page<DeviceRecord> page = deviceRecordRepository.findAll(spec, pageable);
         return new Result<>().success(page);
     }

+ 9 - 2
src/main/resources/templates/deviceRecord/list.ftl

@@ -69,7 +69,7 @@
         <thead>
         <tr>
             <th style="width: 150px">操作时间</th>
-            <th>操作内容</th>
+            <th>操作内容<span id="contentTotal" style="float: right;font-weight: normal"></span></th>
         </tr>
         </thead>
         <tbody id="contentDiv"></tbody>
@@ -80,6 +80,9 @@
 <script src="${base}/styles/jquery/jquery-1.9.1.min.js"></script>
 <script src="${base}/page.js"></script>
 <script type="text/javascript">
+    var basePath = '${base!}';
+    var curPageSize = 2;
+
     $(function () {
         loadData(1, true);
     });
@@ -105,10 +108,13 @@
         params.loginKey = $('#loginKey').val();
         params.loginToken = $('#loginToken').val();
         params.ip = $('#ip').val();
+        params.pageSize = curPageSize;
+        params.pageNo = curPageNo;
 
         $("#contentDiv").empty();
+        $("#contentTotal").html('共 0 条,共 0 页');
         $.ajax({
-            url: '${base!}/device/record/list?pageSize=8&pageNo=' + curPageNo,
+            url: basePath + '/device/record/list',
             contentType: "application/json; charset=UTF-8",
             dataType: "json",
             type: "POST",
@@ -119,6 +125,7 @@
                     if (data.numberOfElements > 0) {
                         var html = render(data.content);
                         $("#contentDiv").html(html);
+                        $("#contentTotal").html('共 ' + data.totalElements + ' 条,共 ' + data.totalPages + ' 页');
                         if (needCreatePage) {
                             $("#contentPager").createPage({
                                 pageCount: data.totalPages,