admin fault

This commit is contained in:
xtaodada 2024-05-15 22:05:55 +08:00
parent 7c889fed2a
commit dd2d0d7263
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
7 changed files with 187 additions and 2 deletions

View File

@ -0,0 +1,47 @@
package cn.edu.cqwu.repair.controller.admin;
import cn.edu.cqwu.repair.dao.FaultDao;
import cn.edu.cqwu.repair.util.AppInit;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import cn.edu.cqwu.repair.entity.Fault;
import javax.servlet.http.HttpServletRequest;
/**
* @author xtaod
*/
@Controller
public class AdminFaultController {
private final FaultDao faultDao;
public AdminFaultController(FaultDao faultDao) {
this.faultDao = faultDao;
}
@RequestMapping("/admin/fault/delete.do")
public String deleteFault(int faultId, Model model, HttpServletRequest request) {
if (faultDao.deleteFault(faultId) > 0) {
model.addAttribute("faultMess", "删除成功");
AppInit.initFault(request.getServletContext(), faultDao);
} else {
model.addAttribute("faultMess", "删除失败");
}
return "/admin/fault";
}
@RequestMapping("/admin/fault/add.do")
public String addFault(String faultName, Model model, HttpServletRequest request) {
Fault fault = new Fault();
fault.setFaultName(faultName);
if (faultDao.add(fault) > 0) {
model.addAttribute("faultMess", "添加成功");
AppInit.initFault(request.getServletContext(), faultDao);
} else {
model.addAttribute("faultMess", "添加失败");
}
return "/admin/fault";
}
}

View File

@ -0,0 +1,14 @@
package cn.edu.cqwu.repair.dao;
import cn.edu.cqwu.repair.entity.Fault;
import java.util.ArrayList;
/**
* @author xtaod
*/
public interface FaultDao {
int add(Fault fault);
ArrayList<Fault> findAllFault();
int deleteFault(int id);
}

View File

@ -0,0 +1,37 @@
package cn.edu.cqwu.repair.dao.impl;
import cn.edu.cqwu.repair.dao.FaultDao;
import cn.edu.cqwu.repair.db.ConnectionFactory;
import cn.edu.cqwu.repair.entity.Fault;
import cn.edu.cqwu.repair.entity.mapper.FaultMapper;
import com.mybatisflex.core.query.QueryWrapper;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import static cn.edu.cqwu.repair.entity.table.FaultTableDef.FAULT;
/**
* @author xtaod
*/
@Component
public class FaultDaoImpl implements FaultDao {
private static final FaultMapper MAPPER = ConnectionFactory.getMapper(FaultMapper.class);
@Override
public int add(Fault fault) {
return MAPPER.insert(fault);
}
@Override
public ArrayList<Fault> findAllFault() {
return (ArrayList<Fault>) MAPPER.selectAll();
}
@Override
public int deleteFault(int id) {
QueryWrapper qw = new QueryWrapper();
qw.where(FAULT.FAULT_ID.eq(id));
return MAPPER.deleteByQuery(qw);
}
}

View File

@ -6,6 +6,7 @@ import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener; import javax.servlet.annotation.WebListener;
import cn.edu.cqwu.repair.dao.DeviceDao; import cn.edu.cqwu.repair.dao.DeviceDao;
import cn.edu.cqwu.repair.dao.FaultDao;
import cn.edu.cqwu.repair.util.AppInit; import cn.edu.cqwu.repair.util.AppInit;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils; import org.springframework.web.context.support.WebApplicationContextUtils;
@ -24,6 +25,8 @@ public class MyServletContextListener extends AppInit implements ServletContextL
if (context != null) { if (context != null) {
DeviceDao deviceDao = context.getBean(DeviceDao.class); DeviceDao deviceDao = context.getBean(DeviceDao.class);
initDevice(application, deviceDao); initDevice(application, deviceDao);
FaultDao faultDao = context.getBean(FaultDao.class);
initFault(application, faultDao);
} }
} }

View File

@ -1,6 +1,7 @@
package cn.edu.cqwu.repair.util; package cn.edu.cqwu.repair.util;
import cn.edu.cqwu.repair.dao.DeviceDao; import cn.edu.cqwu.repair.dao.DeviceDao;
import cn.edu.cqwu.repair.dao.FaultDao;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@ -8,6 +9,10 @@ import javax.servlet.ServletContext;
* @author xtaod * @author xtaod
*/ */
public class AppInit { public class AppInit {
public static void initFault(ServletContext servletContext, FaultDao faultDao) {
servletContext.setAttribute("faults", faultDao.findAllFault());
}
public static void initDevice(ServletContext servletContext, DeviceDao deviceDao) { public static void initDevice(ServletContext servletContext, DeviceDao deviceDao) {
servletContext.setAttribute("device", deviceDao.findAllDevice()); servletContext.setAttribute("device", deviceDao.findAllDevice());
} }

View File

@ -0,0 +1,79 @@
<%--
Created by IntelliJ IDEA.
User: xtaod
Date: 2024/5/15
Time: 下午9:54
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<c:set var="title" value="报修类型维护"/>
<c:set var="webroot" value="${pageContext.request.contextPath}"/>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>${title}</title>
<link rel="stylesheet" href="${webroot}/styles/bootstrap.min.css" crossorigin="anonymous">
<script src="${webroot}/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="${webroot}/styles/sidebar.css" crossorigin="anonymous">
<link rel="stylesheet" href="${webroot}/styles/index.css" crossorigin="anonymous">
<link rel="stylesheet" href="${webroot}/styles/entry.css" crossorigin="anonymous">
</head>
<body>
<main class="d-flex flex-nowrap">
<%@ include file="../includes/header.jsp" %>
<main class="form-signin w-100 m-auto scrollspy" style="min-width: 800px">
<img class="mb-4" src="${webroot}/images/logo.jpg" alt="" width="72" height="72">
<h1 class="h3 mb-3 fw-normal">已添加的报修类型列表</h1>
<c:if test="${not empty requestScope.faultMess}">
<div class="alert alert-warning" role="alert">
${requestScope.faultMess}
</div>
</c:if>
<table class="table">
<thead>
<tr>
<th scope="col">故障序号</th>
<th scope="col">故障名称</th>
<th scope="col">删除故障</th>
</tr>
</thead>
<tbody>
<c:forEach items="${applicationScope.faults}" var="fault" varStatus="rows">
<tr>
<td>${rows.count}</td>
<td>${fault.faultName}</td>
<td><a href="${webroot}/admin/fault/delete.do?faultId=${fault.faultId}">删除</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
<h1 class="h3 mb-3 fw-normal">添加报修类型</h1>
<c:if test="${not empty requestScope.addMess}">
<div class="alert alert-warning" role="alert">
${requestScope.addMess}
</div>
</c:if>
<form action="${webroot}/admin/fault/add.do" method="post">
<div class="input-group mb-3">
<span class="input-group-text">故障名称</span>
<input type="text" class="form-control" name="faultName" id="faultName" required>
</div>
<input class="btn btn-primary w-100 py-2" type="submit" id="submit">
<br/><br/>
<input class="btn btn-primary w-100 py-2" type="reset" value="重置">
<br/><br/>
</form>
</main>
</main>
</body>
</html>

View File

@ -47,8 +47,8 @@
</a> </a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a href="${webroot}/admin/state.jsp" class="nav-link link-body-emphasis" aria-current="page"> <a href="${webroot}/admin/fault.jsp" class="nav-link link-body-emphasis" aria-current="page">
>> 报修类型管理 >> 报修类型维护
</a> </a>
</li> </li>
<li class="nav-item"> <li class="nav-item">