From 61550e93b8734dcd1136eeb75422190850a46da7 Mon Sep 17 00:00:00 2001
From: wyl <wangyulong990316@outlook.com>
Date: Thu, 28 Nov 2024 00:02:08 +0000
Subject: [PATCH] primary realization paging query

---
 .../admin/SuperAdminController.java           | 10 +++++++++
 .../mapper/SuperAdminMapper.java              | 17 ++++++++++-----
 .../service/SuperAdminService.java            |  8 +++++++
 .../service/imp/SuperAdminServiceImp.java     | 20 ++++++++++++++++++
 .../resources/static/js/mainSupAdminView.js   | 21 ++++++++++++++++++-
 .../resources/templates/mainSupAdminView.html |  9 +++++++-
 6 files changed, 78 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/cardiff/client_project/controller/admin/SuperAdminController.java b/src/main/java/com/cardiff/client_project/controller/admin/SuperAdminController.java
index a33e0be..d89d540 100644
--- a/src/main/java/com/cardiff/client_project/controller/admin/SuperAdminController.java
+++ b/src/main/java/com/cardiff/client_project/controller/admin/SuperAdminController.java
@@ -71,4 +71,14 @@ public class SuperAdminController {
         Result result= superAdminService.update(selectDTO);
         return result;
     }
+
+    /**
+     * page selete
+     */
+    @GetMapping("/pageSelect")
+    public Result pageSelect(@RequestParam String type,@RequestParam Integer pageSize){
+        System.out.println("type: "+type+"" +pageSize);
+        Result result=superAdminService.selectPage(type,pageSize,1);
+        return result;
+    }
 }
diff --git a/src/main/java/com/cardiff/client_project/mapper/SuperAdminMapper.java b/src/main/java/com/cardiff/client_project/mapper/SuperAdminMapper.java
index 7a3a350..b60dbcc 100644
--- a/src/main/java/com/cardiff/client_project/mapper/SuperAdminMapper.java
+++ b/src/main/java/com/cardiff/client_project/mapper/SuperAdminMapper.java
@@ -305,29 +305,24 @@ public class SuperAdminMapper {
     public Object getInforByName(String username){
 
             try {
-                // 1. 查询 super_admin 表
                 String sql = "select * from super_admin where name=?";
                 return jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper<>(SuperUser.class));
             } catch (Exception s) {
                 try {
-                    // 2. 查询 hospital 表
                     String sql = "select * from hospital where email=?";
                     return jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper<>(Hospital.class));
                 } catch (Exception h) {
                     try {
-                        // 3. 查询 common_admin 表
                         String sql = "select * from common_admin where email=?";
                         return jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper<>(CommonAdmin.class));
                     } catch (Exception c) {
                         try {
-                            // 4. 查询 patient 表
                             String sql = "select * from patient where email=?";
                             return jdbcTemplate.queryForObject(sql, new Object[]{username}, new BeanPropertyRowMapper<>(Patient.class));
                         } catch (Exception p) {}
                     }
                 }
             }
-            // 如果所有查询都为空,返回 null
             return null;
     }
 
@@ -381,4 +376,16 @@ public class SuperAdminMapper {
             return Result.error(ResponseCode.ERROR);
         }
     }
+
+    /**
+     * page select
+     * @param pageSize
+     */
+    public List<CommonAdmin> selectPageCommonAdmin(Integer pageSize,Integer pageNumber) {
+        String sql="select * from common_admin LIMIT ? OFFSET ?";
+        int offset = (pageNumber - 1) * pageSize;
+        List<CommonAdmin> query = jdbcTemplate.query(sql, new Object[]{pageSize,offset}, new BeanPropertyRowMapper<>(CommonAdmin.class));
+        System.out.println(query);
+        return query;
+    }
 }
diff --git a/src/main/java/com/cardiff/client_project/service/SuperAdminService.java b/src/main/java/com/cardiff/client_project/service/SuperAdminService.java
index 02968ed..df236a0 100644
--- a/src/main/java/com/cardiff/client_project/service/SuperAdminService.java
+++ b/src/main/java/com/cardiff/client_project/service/SuperAdminService.java
@@ -46,4 +46,12 @@ public interface SuperAdminService {
      * @return
      */
     Result selectByItem(SelectDTO selectDTO);
+
+    /**
+     * page select
+     * @param type
+     * @param pageSize
+     * @return
+     */
+    Result selectPage(String type, Integer pageSize,Integer pageNumber);
 }
diff --git a/src/main/java/com/cardiff/client_project/service/imp/SuperAdminServiceImp.java b/src/main/java/com/cardiff/client_project/service/imp/SuperAdminServiceImp.java
index 4589db4..2d40b2a 100644
--- a/src/main/java/com/cardiff/client_project/service/imp/SuperAdminServiceImp.java
+++ b/src/main/java/com/cardiff/client_project/service/imp/SuperAdminServiceImp.java
@@ -200,5 +200,25 @@ public class SuperAdminServiceImp implements SuperAdminService {
         }
 
     }
+
+    /**
+     * page select
+     * @param type
+     * @param pageSize
+     * @return
+     */
+    @Override
+    public Result selectPage(String type, Integer pageSize,Integer pageNumber) {
+        if(type.equals("commonAdmin")){
+            List<CommonAdmin> commonAdmins = superAdminMapper.selectPageCommonAdmin(pageSize, pageNumber);
+            if(commonAdmins.size()>0){
+                return Result.success(commonAdmins);
+            }
+        }
+        if(type.equals("hospital")){
+
+        }
+        return Result.error(ResponseCode.ERROR);
+    }
 }
 
diff --git a/src/main/resources/static/js/mainSupAdminView.js b/src/main/resources/static/js/mainSupAdminView.js
index ad3e90a..5648095 100644
--- a/src/main/resources/static/js/mainSupAdminView.js
+++ b/src/main/resources/static/js/mainSupAdminView.js
@@ -253,4 +253,23 @@ function updateTable(data) {
         `;
         tbody.append(tr);
     });
-}
\ No newline at end of file
+}
+$(document).on("change","#page-size",function (){
+    let pageSize=document.getElementById("page-size").value
+    $.ajax({
+        contentType: "application/json",
+        url: `/superAdmin/pageSelect?type=commonAdmin&pageSize=${pageSize}`,
+        type: "GET",
+        dataType: "Json",
+        success: function (data) {
+            console.log(data)
+            if (data.code != 0) {
+                updateTable(data.data)
+                //location.reload()
+            } else {
+                alert(data.msg)
+            }
+        },
+    })
+
+})
\ No newline at end of file
diff --git a/src/main/resources/templates/mainSupAdminView.html b/src/main/resources/templates/mainSupAdminView.html
index ac416b1..c0d52d8 100644
--- a/src/main/resources/templates/mainSupAdminView.html
+++ b/src/main/resources/templates/mainSupAdminView.html
@@ -91,7 +91,14 @@
     <button type="button" id="addAdmin" style="margin-right: 170px;margin-left: 20px">Submit</button>
     <button type="button" onclick="location.reload()">Cancel</button>
 </div>
-
+<div>
+    <select id="page-size">
+        <option value="">items per page</option>
+        <option value="1">1</option>
+        <option value="2">2</option>
+        <option value="15">15</option>
+    </select>
+</div>
 <script src="/js/mainSupAdminView.js"></script>
 </body>
 </html>
-- 
GitLab