Skip to content
Snippets Groups Projects
Commit e2b7e61e authored by Yulong Wang's avatar Yulong Wang
Browse files

Merge branch 'wyl' into 'main'

delete function in superAdmin page

See merge request !25
parents b4ab098e 9507e920
No related branches found
No related tags found
1 merge request!25delete function in superAdmin page
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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
......
......@@ -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);
}
......
......@@ -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 {
......
/* 设置导航项的样式 */
/* 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 */
}
......@@ -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(){
......
......@@ -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>
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment