diff --git a/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminAddressController.java b/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminAddressController.java new file mode 100644 index 0000000..5218577 --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminAddressController.java @@ -0,0 +1,92 @@ +package cn.edu.cqwu.repair.controller.admin; + +import cn.edu.cqwu.repair.dao.AddressDao; +import cn.edu.cqwu.repair.entity.Address; +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 javax.servlet.http.HttpServletRequest; + +/** + * @author xtaod + */ +@Controller +public class AdminAddressController { + private final AddressDao addressDao; + + public AdminAddressController(AddressDao addressDao) { + this.addressDao = addressDao; + } + + @RequestMapping("/admin/address/delete.do") + public String deleteAddress(int addressId, Model model, HttpServletRequest request) { + if (addressDao.deleteAddress(addressId) > 0) { + model.addAttribute("addressMess", "删除成功"); + AppInit.initAddress(request.getServletContext(), addressDao); + } else { + model.addAttribute("addressMess", "删除失败"); + } + return "/admin/address"; + } + + @RequestMapping("/admin/address/add.do") + public String addAddress(String addressName, int parentId, Model model, HttpServletRequest request) { + Address address = new Address(); + address.setAddressName(addressName); + if (parentId == 0) { + address.setIsParent(1); + address.setParentId(null); + } else { + address.setIsParent(0); + address.setParentId(parentId); + } + if (addressDao.add(address) > 0) { + model.addAttribute("addMess", "添加成功"); + AppInit.initAddress(request.getServletContext(), addressDao); + } else { + model.addAttribute("addMess", "添加失败"); + } + return "/admin/address"; + } + + @RequestMapping("/admin/address/update.do") + public String updateAddress(int addressId, String addressName, int parentId, Model model, HttpServletRequest request) { + Address address = addressDao.findAddressById(addressId); + if (address == null) { + model.addAttribute("addMess", "未找到该故障,请重试"); + AppInit.initAddress(request.getServletContext(), addressDao); + } else { + address.setAddressName(addressName); + if (parentId == 0) { + address.setIsParent(1); + address.setParentId(null); + } else { + address.setIsParent(0); + address.setParentId(parentId); + } + if (addressDao.update(address) > 0) { + model.addAttribute("addMess", "修改成功"); + AppInit.initAddress(request.getServletContext(), addressDao); + } else { + model.addAttribute("addMess", "修改失败"); + } + } + return "/admin/address"; + } + + @RequestMapping("/admin/address/query.do") + public String queryAddress(int addressId, Model model, HttpServletRequest request) { + Address address = addressDao.findAddressById(addressId); + if (address == null) { + model.addAttribute("addressMess", "未找到该故障,请重试"); + AppInit.initAddress(request.getServletContext(), addressDao); + } else { + model.addAttribute("updateAddressId", address.getAddressId()); + model.addAttribute("updateAddressName", address.getAddressName()); + model.addAttribute("updateAddressParentId", address.getParentId()); + } + return "/admin/address"; + } +} 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 index 83fdb75..9a4767e 100644 --- a/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminFaultController.java +++ b/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminFaultController.java @@ -1,13 +1,12 @@ package cn.edu.cqwu.repair.controller.admin; import cn.edu.cqwu.repair.dao.FaultDao; +import cn.edu.cqwu.repair.entity.Fault; 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; /** @@ -37,10 +36,41 @@ public class AdminFaultController { Fault fault = new Fault(); fault.setFaultName(faultName); if (faultDao.add(fault) > 0) { - model.addAttribute("faultMess", "添加成功"); + model.addAttribute("addMess", "添加成功"); AppInit.initFault(request.getServletContext(), faultDao); } else { - model.addAttribute("faultMess", "添加失败"); + model.addAttribute("addMess", "添加失败"); + } + return "/admin/fault"; + } + + @RequestMapping("/admin/fault/update.do") + public String updateFault(int faultId, String faultName, Model model, HttpServletRequest request) { + Fault fault = faultDao.findFaultById(faultId); + if (fault == null) { + model.addAttribute("addMess", "未找到该故障,请重试"); + AppInit.initFault(request.getServletContext(), faultDao); + } else { + fault.setFaultName(faultName); + if (faultDao.update(fault) > 0) { + model.addAttribute("addMess", "修改成功"); + AppInit.initFault(request.getServletContext(), faultDao); + } else { + model.addAttribute("addMess", "修改失败"); + } + } + return "/admin/fault"; + } + + @RequestMapping("/admin/fault/query.do") + public String queryFault(int faultId, Model model, HttpServletRequest request) { + Fault fault = faultDao.findFaultById(faultId); + if (fault == null) { + model.addAttribute("faultMess", "未找到该故障,请重试"); + AppInit.initFault(request.getServletContext(), faultDao); + } else { + model.addAttribute("updateFaultId", fault.getFaultId()); + model.addAttribute("updateFaultName", fault.getFaultName()); } return "/admin/fault"; } diff --git a/src/main/java/cn/edu/cqwu/repair/dao/AddressDao.java b/src/main/java/cn/edu/cqwu/repair/dao/AddressDao.java new file mode 100644 index 0000000..b40f2d6 --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/dao/AddressDao.java @@ -0,0 +1,17 @@ +package cn.edu.cqwu.repair.dao; + +import cn.edu.cqwu.repair.entity.Address; + +import java.util.ArrayList; + +/** + * @author xtaod + */ +public interface AddressDao { + int add(Address address); + int update(Address address); + ArrayList
findAllAddress(); + ArrayList
findAddressByParent(int parent); + int deleteAddress(int id); + Address findAddressById(int id); +} diff --git a/src/main/java/cn/edu/cqwu/repair/dao/FaultDao.java b/src/main/java/cn/edu/cqwu/repair/dao/FaultDao.java index d6f8b14..a47af04 100644 --- a/src/main/java/cn/edu/cqwu/repair/dao/FaultDao.java +++ b/src/main/java/cn/edu/cqwu/repair/dao/FaultDao.java @@ -9,6 +9,8 @@ import java.util.ArrayList; */ public interface FaultDao { int add(Fault fault); + int update(Fault fault); ArrayList findAllFault(); int deleteFault(int id); + Fault findFaultById(int id); } diff --git a/src/main/java/cn/edu/cqwu/repair/dao/impl/AddressDaoImpl.java b/src/main/java/cn/edu/cqwu/repair/dao/impl/AddressDaoImpl.java new file mode 100644 index 0000000..4f84ab5 --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/dao/impl/AddressDaoImpl.java @@ -0,0 +1,56 @@ +package cn.edu.cqwu.repair.dao.impl; + +import cn.edu.cqwu.repair.dao.AddressDao; +import cn.edu.cqwu.repair.db.ConnectionFactory; +import cn.edu.cqwu.repair.entity.Address; +import cn.edu.cqwu.repair.entity.mapper.AddressMapper; +import com.mybatisflex.core.query.QueryWrapper; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; + +import static cn.edu.cqwu.repair.entity.table.AddressTableDef.ADDRESS; + +/** + * @author xtaod + */ +@Component +public class AddressDaoImpl implements AddressDao { + private final static AddressMapper MAPPER = ConnectionFactory.getMapper(AddressMapper.class); + + @Override + public int add(Address address) { + return MAPPER.insert(address); + } + + @Override + public int update(Address address) { + return MAPPER.update(address); + } + + @Override + public ArrayList
findAllAddress() { + return (ArrayList
) MAPPER.selectAll(); + } + + @Override + public ArrayList
findAddressByParent(int parent) { + QueryWrapper qw = new QueryWrapper(); + qw.where(ADDRESS.IS_PARENT.eq(parent)); + return (ArrayList
) MAPPER.selectListByQuery(qw); + } + + @Override + public int deleteAddress(int id) { + QueryWrapper qw = new QueryWrapper(); + qw.where(ADDRESS.ADDRESS_ID.eq(id)); + return MAPPER.deleteByQuery(qw); + } + + @Override + public Address findAddressById(int id) { + QueryWrapper qw = new QueryWrapper(); + qw.where(ADDRESS.ADDRESS_ID.eq(id)); + return MAPPER.selectOneByQuery(qw); + } +} 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 index 28d2f98..25a364c 100644 --- a/src/main/java/cn/edu/cqwu/repair/dao/impl/FaultDaoImpl.java +++ b/src/main/java/cn/edu/cqwu/repair/dao/impl/FaultDaoImpl.java @@ -23,6 +23,11 @@ public class FaultDaoImpl implements FaultDao { return MAPPER.insert(fault); } + @Override + public int update(Fault fault) { + return MAPPER.update(fault); + } + @Override public ArrayList findAllFault() { return (ArrayList) MAPPER.selectAll(); @@ -34,4 +39,11 @@ public class FaultDaoImpl implements FaultDao { qw.where(FAULT.FAULT_ID.eq(id)); return MAPPER.deleteByQuery(qw); } + + @Override + public Fault findFaultById(int id) { + QueryWrapper qw = new QueryWrapper(); + qw.where(FAULT.FAULT_ID.eq(id)); + return MAPPER.selectOneByQuery(qw); + } } diff --git a/src/main/java/cn/edu/cqwu/repair/entity/Address.java b/src/main/java/cn/edu/cqwu/repair/entity/Address.java index ece82f2..7ba4388 100644 --- a/src/main/java/cn/edu/cqwu/repair/entity/Address.java +++ b/src/main/java/cn/edu/cqwu/repair/entity/Address.java @@ -16,6 +16,8 @@ public class Address { private String addressName; // 是否是父地址 private int isParent; + // 父地址id + private Integer parentId; public int getAddressId() { return addressId; @@ -41,12 +43,21 @@ public class Address { this.isParent = isParent; } + public Integer getParentId() { + return parentId; + } + + public void setParentId(Integer parentId) { + this.parentId = parentId; + } + @Override public String toString() { return "Address{" + "addressId=" + addressId + ", addressName='" + addressName + '\'' + ", isParent=" + isParent + + ", parentId=" + parentId + '}'; } } 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 a3481b6..b055166 100644 --- a/src/main/java/cn/edu/cqwu/repair/listener/MyServletContextListener.java +++ b/src/main/java/cn/edu/cqwu/repair/listener/MyServletContextListener.java @@ -5,6 +5,7 @@ import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.servlet.annotation.WebListener; +import cn.edu.cqwu.repair.dao.AddressDao; import cn.edu.cqwu.repair.dao.DeviceDao; import cn.edu.cqwu.repair.dao.FaultDao; import cn.edu.cqwu.repair.util.AppInit; @@ -27,6 +28,8 @@ public class MyServletContextListener extends AppInit implements ServletContextL initDevice(application, deviceDao); FaultDao faultDao = context.getBean(FaultDao.class); initFault(application, faultDao); + AddressDao addressDao = context.getBean(AddressDao.class); + initAddress(application, addressDao); } } 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 9c263fd..a57edbb 100644 --- a/src/main/java/cn/edu/cqwu/repair/util/AppInit.java +++ b/src/main/java/cn/edu/cqwu/repair/util/AppInit.java @@ -1,5 +1,6 @@ package cn.edu.cqwu.repair.util; +import cn.edu.cqwu.repair.dao.AddressDao; import cn.edu.cqwu.repair.dao.DeviceDao; import cn.edu.cqwu.repair.dao.FaultDao; @@ -16,4 +17,10 @@ public class AppInit { public static void initDevice(ServletContext servletContext, DeviceDao deviceDao) { servletContext.setAttribute("device", deviceDao.findAllDevice()); } + + public static void initAddress(ServletContext servletContext, AddressDao addressDao) { + servletContext.setAttribute("addresses", addressDao.findAllAddress()); + servletContext.setAttribute("addresses0", addressDao.findAddressByParent(0)); + servletContext.setAttribute("addresses1", addressDao.findAddressByParent(1)); + } } diff --git a/src/main/webapp/admin/address.jsp b/src/main/webapp/admin/address.jsp new file mode 100644 index 0000000..468eb82 --- /dev/null +++ b/src/main/webapp/admin/address.jsp @@ -0,0 +1,116 @@ +<%-- + Created by IntelliJ IDEA. + User: xtaod + Date: 2024/5/15 + Time: 下午10:24 + 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}${address.addressName}修改 + 删除 +
----- ${address0.addressName}修改 + 删除 +
+ + +

修改区域

+
+ +

添加区域

+
+ + + + + +
+ + + + +
+ 区域名称 + +
+
+ 上级区域 + +
+ +

+ +

+
+
+
+ + \ No newline at end of file diff --git a/src/main/webapp/admin/fault.jsp b/src/main/webapp/admin/fault.jsp index 440ddc5..83e895b 100644 --- a/src/main/webapp/admin/fault.jsp +++ b/src/main/webapp/admin/fault.jsp @@ -41,7 +41,8 @@ 故障序号 故障名称 - 删除故障 + 操作 + 删除 @@ -49,6 +50,7 @@ ${rows.count} ${fault.faultName} + 修改 删除 @@ -56,17 +58,27 @@ -

添加报修类型

+ +

修改报修类型

+
+ +

添加报修类型

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


diff --git a/src/main/webapp/includes/menu.jsp b/src/main/webapp/includes/menu.jsp index e074b74..0cf3214 100644 --- a/src/main/webapp/includes/menu.jsp +++ b/src/main/webapp/includes/menu.jsp @@ -52,8 +52,8 @@