From 9507e920be75526d63703315db7b06cce1218884 Mon Sep 17 00:00:00 2001 From: wyl <wangyulong990316@outlook.com> Date: Sat, 23 Nov 2024 21:52:01 +0000 Subject: [PATCH] delete function in superAdmin page --- .../admin/SuperAdminController.java | 14 ++-- .../mapper/SuperAdminMapper.java | 24 ++++--- .../service/SuperAdminService.java | 2 +- .../service/imp/SuperAdminServiceImp.java | 4 +- .../resources/static/css/mainSupAdminView.css | 38 +++++++++- src/main/resources/static/css/style.css | 8 +-- src/main/resources/templates/leftView.html | 2 +- .../resources/templates/mainHospitalView.html | 70 ++++++++++++++++--- .../resources/templates/mainSupAdminView.html | 47 ++++++++++++- 9 files changed, 178 insertions(+), 31 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 6e95753..829f386 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 @@ -30,13 +30,19 @@ public class SuperAdminController { } /** - *delete information by id + *delete hospital information by id * @param ids * @return */ - @DeleteMapping("/deleteById") - public Result deleteById(@RequestBody List<Integer> ids){ - Result result= superAdminService.deleteById(ids); + @DeleteMapping("/deleteHospitalById") + public Result deleteHospitalById(@RequestBody List<Integer> ids){ + Result result= superAdminService.deleteById(ids,"hospital"); + return result; + } + + @DeleteMapping("/deleteAdminById") + public Result deleteAdminById(@RequestBody List<Integer> ids){ + Result result= superAdminService.deleteById(ids,"commonAdmin"); 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 b84022f..eca4d75 100644 --- a/src/main/java/com/cardiff/client_project/mapper/SuperAdminMapper.java +++ b/src/main/java/com/cardiff/client_project/mapper/SuperAdminMapper.java @@ -69,9 +69,21 @@ public class SuperAdminMapper { * @param ids * @return */ - public int[] deleteById(List<Integer> ids) { + public int[] deleteByIdAndType(List<Integer> ids,String type) { //TODO - String sql = "DELETE FROM common_admin WHERE id=?"; + String sql = ""; + String sql_1=""; + String sql_2=""; + if(type.equals("hospital")){ + sql = "DELETE FROM hospital WHERE id=?"; + sql_1="ALTER TABLE hospital DROP COLUMN id;"; + sql_2="ALTER TABLE hospital ADD COLUMN id INT NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;"; + } + if(type.equals("commonAdmin")){ + sql = "DELETE FROM common_admin WHERE id=?"; + sql_1="ALTER TABLE common_admin DROP COLUMN id;"; + sql_2="ALTER TABLE common_admin ADD COLUMN id INT NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;"; + } List<Object[]> idList = new ArrayList<>(); // Build parameter list for (Integer id : ids) { @@ -79,12 +91,8 @@ public class SuperAdminMapper { } // Batch delete int[] item = jdbcTemplate.batchUpdate(sql, idList); - String s; - s = "ALTER TABLE common_admin DROP COLUMN id;"; - jdbcTemplate.update(s); - s= "ALTER TABLE common_admin ADD COLUMN id INT NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;"; - jdbcTemplate.update(s); - + jdbcTemplate.update(sql_1); + jdbcTemplate.update(sql_2); return item; } 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 9e07869..02968ed 100644 --- a/src/main/java/com/cardiff/client_project/service/SuperAdminService.java +++ b/src/main/java/com/cardiff/client_project/service/SuperAdminService.java @@ -20,7 +20,7 @@ public interface SuperAdminService { * @param ids * @return */ - Result deleteById(List<Integer> ids); + Result deleteById(List<Integer> ids,String type); /** * Query admin information 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 3b43e3b..f637d01 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 @@ -61,8 +61,8 @@ public class SuperAdminServiceImp implements SuperAdminService { * @return */ @Override - public Result deleteById(List<Integer> ids) { - superAdminMapper.deleteById(ids); + public Result deleteById(List<Integer> ids,String type) { + superAdminMapper.deleteByIdAndType(ids,type); return Result.success(ResponseCode.SUCCESS); } diff --git a/src/main/resources/static/css/mainSupAdminView.css b/src/main/resources/static/css/mainSupAdminView.css index bcfaff7..c7cc29e 100644 --- a/src/main/resources/static/css/mainSupAdminView.css +++ b/src/main/resources/static/css/mainSupAdminView.css @@ -89,6 +89,9 @@ table { margin-top: 20px; /* Space between table and content above */ border-radius: 8px; /* Rounded corners for the table */ overflow: hidden; /* Ensure rounded corners are not covered by content */ + justify-content: center; + align-items: center; + text-align: center; } /* Table Header Style */ @@ -97,9 +100,9 @@ th { color: white; /* Header text color */ padding: 12px 15px; /* Header padding */ font-size: 16px; /* Header text size */ - text-align: left; /* Left alignment */ } + /* Table Cell Style */ td { padding: 12px 15px; /* Cell padding */ @@ -122,6 +125,39 @@ tr:hover { table, th, td { border: 1px solid #ddd; /* Table border */ } +/*.tdOption {*/ +/* display: flex;*/ +/* flex-direction: row;*/ +/* justify-content: center;*/ +/* align-items: center;*/ +/* text-align: center;*/ +/*}*/ + +/* é»˜è®¤æŒ‰é’®æ ·å¼ */ +label.btn { + font-size: 16px; + font-weight: bold; + color: #333333; + margin-right: 10px; + padding: 10px; + cursor: pointer; + transition: background-color 0.3s ease, transform 0.1s ease; + border-radius: 5px; +} + +/* 点击åŽçš„æ¿€æ´»æ ·å¼ */ +label.btn.active { + background-color: #007bff; /* èƒŒæ™¯è‰²æ”¹å˜ */ + color: white; /* æ–‡å—é¢œè‰²æ”¹å˜ */ + transform: scale(0.98); /* æŒ‰é’®ç¼©å°æ•ˆæžœ */ +} + +/* é¼ æ ‡æ‚¬åœæ—¶çš„æ ·å¼ */ +label.btn:hover { + background-color: #0056b3; + color: white; +} + /* Add Shadow and Rounded Corner Effect */ table { diff --git a/src/main/resources/static/css/style.css b/src/main/resources/static/css/style.css index 7e0e246..f558ba5 100644 --- a/src/main/resources/static/css/style.css +++ b/src/main/resources/static/css/style.css @@ -1,4 +1,4 @@ -/* è®¾ç½®å¯¼èˆªé¡¹çš„æ ·å¼ */ +/* basic */ .nav-item { background-color: #93a5e7; color: white; @@ -11,8 +11,8 @@ transition: background-color 0.3s ease, transform 0.2s ease; } -/* é¼ æ ‡æ‚¬åœæ—¶çš„æ•ˆæžœ */ +/* hover */ .nav-item:hover { background-color: #555; - transform: scale(1.05);/* Magnification effect */ -} \ No newline at end of file + transform: scale(1.05); /* Magnification effect */ +} diff --git a/src/main/resources/templates/leftView.html b/src/main/resources/templates/leftView.html index c8503f1..b7fd8a8 100644 --- a/src/main/resources/templates/leftView.html +++ b/src/main/resources/templates/leftView.html @@ -8,7 +8,7 @@ <!-- Vertical navigation bar --> <div class="nav-item" onclick="chooseAdmin()">CommonAdmin</div> <div class="nav-item" onclick="chooseHospital()">Hospital</div> -<div class="nav-item" onclick="chooseOut()">Sign Out</div> +<div class="nav-item" onclick="chooseOut()" style="margin-top: 448px">Sign Out</div> </body> <script> function chooseAdmin(){ diff --git a/src/main/resources/templates/mainHospitalView.html b/src/main/resources/templates/mainHospitalView.html index 87da4ee..9fc90f3 100644 --- a/src/main/resources/templates/mainHospitalView.html +++ b/src/main/resources/templates/mainHospitalView.html @@ -35,18 +35,28 @@ <th>MAX</th> <th>NOW</th> <th>STATUS</th> + <th>OPTION</th> </tr> </thead> <tbody> <!-- Ergodic set --> - <tr th:each="row : ${tableData}"> - <td th:text="${row['id']}"></td> - <td th:text="${row['name']}"></td> - <td th:text="${row['phone']}"></td> - <td th:text="${row['address']}"></td> - <td th:text="${row['maxAmount']}"></td> - <td th:text="${row['amountPatient']}"></td> - <td th:text="${row['status_str']}"></td> + <tr th:each="row : ${tableData}" + th:data-id="${row.id}" + th:data-name="${row.name}" + th:data-phone="${row.phone}" + th:data-address="${row.address}"> + <td th:text="${row.id}"></td> + <td th:text="${row.name}"></td> + <td th:text="${row.phone}"></td> + <td th:text="${row.address}"></td> + <td th:text="${row.maxAmount}"></td> + <td th:text="${row.amountPatient}"></td> + <td th:text="${row.status_str}"></td> + <td class="tdOption"> + <label id="btn" class="btn">Edit</label> + <label id="delete" class="btn">Delete</label> + <label id="btn" class="btn">Freeze</label> + </td> </tr> </tbody> </table> @@ -54,6 +64,42 @@ <script th:inline="javascript"> + $(document).on("click","#delete",function (){ + const clickedLabel = this; + // remove active class + const labels = document.querySelectorAll('.tdOption .btn'); + labels.forEach(label => label.classList.remove('active')); + + // add active class + clickedLabel.classList.add('active'); + + const row = $(this).closest('tr'); + // get data in row + row.data('id'); // get ID + let ids = new Array(); + ids.push(row.data('id')) + console.log(ids) + $.ajax({ + contentType: "application/json", + url: "/superAdmin/deleteHospitalById", + type: "DELETE", + data: JSON.stringify(ids), + dataType: "Json", + success: function (data) { + console.log(data) + if(data.code==1){ + console.log(data) + window.location.reload() + }else { + alert(data.msg) + } + }, + + }); + + }) + + //use jQuery's load() to load content dynamically,Events cannot be bound in dom mode $(document).on("click", "#searchButton", function () { let status=document.getElementById("searchStatus").value; @@ -94,7 +140,7 @@ // create new table data.forEach(row => { const tr = ` - <tr> + <tr data-id="${row.id}"> <td>${row.id}</td> <td>${row.name}</td> <td>${row.phone}</td> @@ -102,11 +148,17 @@ <td>${row.maxAmount}</td> <td>${row.amountPatient}</td> <td>${row.status_str}</td> + <td class="tdOption"> + <label id="btn" class="btn">Edit</label> + <label id="delete" class="btn">Delete</label> + <label id="btn" class="btn">Freeze</label> + </td> </tr> `; tbody.append(tr); }); } + </script> </body> </html> diff --git a/src/main/resources/templates/mainSupAdminView.html b/src/main/resources/templates/mainSupAdminView.html index 7ce7725..c17c927 100644 --- a/src/main/resources/templates/mainSupAdminView.html +++ b/src/main/resources/templates/mainSupAdminView.html @@ -30,6 +30,7 @@ <th>PHONE</th> <th>EMAIL</th> <th>STATUS</th> + <th>OPTION</th> </tr> </thead> <tbody> @@ -39,12 +40,51 @@ <td th:text="${row['phone']}"></td> <td th:text="${row['email']}"></td> <td th:text="${row['status_str']}"></td> + <td class="tdOption"> + <label id="btn" class="btn">Edit</label> + <label id="delete" class="btn">Delete</label> + <label id="btn" class="btn">Freeze</label> + </td> </tr> </tbody> </table> </div> <script th:inline="javascript"> + $(document).on("click","#delete",function (){ + const clickedLabel = this; + // remove active class + const labels = document.querySelectorAll('.tdOption .btn'); + labels.forEach(label => label.classList.remove('active')); + + // add active class + clickedLabel.classList.add('active'); + + const row = $(this).closest('tr'); + // get data in row + row.data('id'); // get ID + let ids = new Array(); + ids.push(row.data('id')) + console.log(ids) + $.ajax({ + contentType: "application/json", + url: "/superAdmin/deleteAdminById", + type: "DELETE", + data: JSON.stringify(ids), + dataType: "Json", + success: function (data) { + console.log(data) + if(data.code==1){ + console.log(data) + window.location.reload() + }else { + alert(data.msg) + } + }, + + }); + + }) //use jQuery's load() to load content dynamically,Events cannot be bound in dom mode $(document).on("click", "#searchButton", function () { @@ -85,12 +125,17 @@ // create new table data.forEach(row => { const tr = ` - <tr> + <tr data-id="${row.id}"> <td>${row.id}</td> <td>${row.name}</td> <td>${row.phone}</td> <td>${row.email}</td> <td>${row.status_str}</td> + <td class="tdOption"> + <label id="btn" class="btn">Edit</label> + <label id="delete" class="btn">Delete</label> + <label id="btn" class="btn">Freeze</label> + </td> </tr> `; tbody.append(tr); -- GitLab