diff --git a/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminFaultController.java b/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminFaultController.java new file mode 100644 index 0000000..83fdb75 --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminFaultController.java @@ -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"; + } +} diff --git a/src/main/java/cn/edu/cqwu/repair/dao/FaultDao.java b/src/main/java/cn/edu/cqwu/repair/dao/FaultDao.java new file mode 100644 index 0000000..d6f8b14 --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/dao/FaultDao.java @@ -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 findAllFault(); + int deleteFault(int id); +} diff --git a/src/main/java/cn/edu/cqwu/repair/dao/impl/FaultDaoImpl.java b/src/main/java/cn/edu/cqwu/repair/dao/impl/FaultDaoImpl.java new file mode 100644 index 0000000..28d2f98 --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/dao/impl/FaultDaoImpl.java @@ -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 findAllFault() { + return (ArrayList) MAPPER.selectAll(); + } + + @Override + public int deleteFault(int id) { + QueryWrapper qw = new QueryWrapper(); + qw.where(FAULT.FAULT_ID.eq(id)); + return MAPPER.deleteByQuery(qw); + } +} diff --git a/src/main/java/cn/edu/cqwu/repair/listener/MyServletContextListener.java b/src/main/java/cn/edu/cqwu/repair/listener/MyServletContextListener.java index 0c92750..a3481b6 100644 --- a/src/main/java/cn/edu/cqwu/repair/listener/MyServletContextListener.java +++ b/src/main/java/cn/edu/cqwu/repair/listener/MyServletContextListener.java @@ -6,6 +6,7 @@ import javax.servlet.ServletContextListener; import javax.servlet.annotation.WebListener; import cn.edu.cqwu.repair.dao.DeviceDao; +import cn.edu.cqwu.repair.dao.FaultDao; import cn.edu.cqwu.repair.util.AppInit; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; @@ -24,6 +25,8 @@ public class MyServletContextListener extends AppInit implements ServletContextL if (context != null) { DeviceDao deviceDao = context.getBean(DeviceDao.class); initDevice(application, deviceDao); + FaultDao faultDao = context.getBean(FaultDao.class); + initFault(application, faultDao); } } diff --git a/src/main/java/cn/edu/cqwu/repair/util/AppInit.java b/src/main/java/cn/edu/cqwu/repair/util/AppInit.java index d3492f9..9c263fd 100644 --- a/src/main/java/cn/edu/cqwu/repair/util/AppInit.java +++ b/src/main/java/cn/edu/cqwu/repair/util/AppInit.java @@ -1,6 +1,7 @@ package cn.edu.cqwu.repair.util; import cn.edu.cqwu.repair.dao.DeviceDao; +import cn.edu.cqwu.repair.dao.FaultDao; import javax.servlet.ServletContext; @@ -8,6 +9,10 @@ import javax.servlet.ServletContext; * @author xtaod */ public class AppInit { + public static void initFault(ServletContext servletContext, FaultDao faultDao) { + servletContext.setAttribute("faults", faultDao.findAllFault()); + } + public static void initDevice(ServletContext servletContext, DeviceDao deviceDao) { servletContext.setAttribute("device", deviceDao.findAllDevice()); } diff --git a/src/main/webapp/admin/fault.jsp b/src/main/webapp/admin/fault.jsp new file mode 100644 index 0000000..440ddc5 --- /dev/null +++ b/src/main/webapp/admin/fault.jsp @@ -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" %> + + + + + + ${title} + + + + + + + +
+ <%@ include file="../includes/header.jsp" %> + +
+ + +

已添加的报修类型列表

+ + + + + + + + + + + + + + + + + + + + + +
故障序号故障名称删除故障
${rows.count}${fault.faultName}删除 +
+ +

添加报修类型

+ + + + +
+
+ 故障名称 + +
+ +

+ +

+
+
+
+ + \ No newline at end of file diff --git a/src/main/webapp/includes/menu.jsp b/src/main/webapp/includes/menu.jsp index 73b5731..e074b74 100644 --- a/src/main/webapp/includes/menu.jsp +++ b/src/main/webapp/includes/menu.jsp @@ -47,8 +47,8 @@