admin address
This commit is contained in:
parent
dd2d0d7263
commit
8a1f2b8539
@ -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";
|
||||
}
|
||||
}
|
@ -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";
|
||||
}
|
||||
|
17
src/main/java/cn/edu/cqwu/repair/dao/AddressDao.java
Normal file
17
src/main/java/cn/edu/cqwu/repair/dao/AddressDao.java
Normal file
@ -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<Address> findAllAddress();
|
||||
ArrayList<Address> findAddressByParent(int parent);
|
||||
int deleteAddress(int id);
|
||||
Address findAddressById(int id);
|
||||
}
|
@ -9,6 +9,8 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public interface FaultDao {
|
||||
int add(Fault fault);
|
||||
int update(Fault fault);
|
||||
ArrayList<Fault> findAllFault();
|
||||
int deleteFault(int id);
|
||||
Fault findFaultById(int id);
|
||||
}
|
||||
|
@ -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<Address> findAllAddress() {
|
||||
return (ArrayList<Address>) MAPPER.selectAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<Address> findAddressByParent(int parent) {
|
||||
QueryWrapper qw = new QueryWrapper();
|
||||
qw.where(ADDRESS.IS_PARENT.eq(parent));
|
||||
return (ArrayList<Address>) 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);
|
||||
}
|
||||
}
|
@ -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<Fault> findAllFault() {
|
||||
return (ArrayList<Fault>) 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);
|
||||
}
|
||||
}
|
||||
|
@ -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 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
116
src/main/webapp/admin/address.jsp
Normal file
116
src/main/webapp/admin/address.jsp
Normal file
@ -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" %>
|
||||
<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.addressMess}">
|
||||
<div class="alert alert-warning" role="alert">
|
||||
${requestScope.addressMess}
|
||||
</div>
|
||||
</c:if>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">区域序号</th>
|
||||
<th scope="col">区域名称</th>
|
||||
<th scope="col">操作</th>
|
||||
<th scope="col">删除</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<c:forEach items="${applicationScope.addresses1}" var="address" varStatus="rows">
|
||||
<tr>
|
||||
<td>${rows.count}</td>
|
||||
<td>${address.addressName}</td>
|
||||
<td><a href="${webroot}/admin/address/query.do?addressId=${address.addressId}">修改</a>
|
||||
<td><a href="${webroot}/admin/address/delete.do?addressId=${address.addressId}">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
<c:forEach items="${applicationScope.addresses0}" var="address0" varStatus="rows0">
|
||||
<c:if test="${address0.parentId == address.addressId}">
|
||||
<tr>
|
||||
<td>-</td>
|
||||
<td>---- ${address0.addressName}</td>
|
||||
<td><a href="${webroot}/admin/address/query.do?addressId=${address0.addressId}">修改</a>
|
||||
<td><a href="${webroot}/admin/address/delete.do?addressId=${address0.addressId}">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
</c:if>
|
||||
</c:forEach>
|
||||
</c:forEach>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<c:if test="${not empty requestScope.updateAddressId}">
|
||||
<h1 class="h3 mb-3 fw-normal">修改区域</h1>
|
||||
</c:if>
|
||||
<c:if test="${empty requestScope.updateAddressId}">
|
||||
<h1 class="h3 mb-3 fw-normal">添加区域</h1>
|
||||
</c:if>
|
||||
<c:if test="${not empty requestScope.addMess}">
|
||||
<div class="alert alert-warning" role="alert">
|
||||
${requestScope.addMess}
|
||||
</div>
|
||||
</c:if>
|
||||
|
||||
<c:if test="${not empty requestScope.updateAddressId}">
|
||||
<form action="${webroot}/admin/address/update.do?addressId=${requestScope.updateAddressId}" method="post">
|
||||
</c:if>
|
||||
<c:if test="${empty requestScope.updateAddressId}">
|
||||
<form action="${webroot}/admin/address/add.do" method="post">
|
||||
</c:if>
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">区域名称</span>
|
||||
<input type="text" class="form-control" name="addressName" id="addressName" value="${requestScope.updateAddressName}" required>
|
||||
</div>
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">上级区域</span>
|
||||
<select class="form-select" name="parentId" id="parentId" required>
|
||||
<option value="0">无</option>
|
||||
<c:forEach items="${applicationScope.addresses1}" var="address" varStatus="rows">
|
||||
<c:if test="${address.addressId != requestScope.updateAddressParentId}">
|
||||
<option value="${address.addressId}">${address.addressName}</option>
|
||||
</c:if>
|
||||
<c:if test="${address.addressId == requestScope.updateAddressParentId}">
|
||||
<option value="${address.addressId}" selected>${address.addressName}</option>
|
||||
</c:if>
|
||||
</c:forEach>
|
||||
</select>
|
||||
</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>
|
@ -41,7 +41,8 @@
|
||||
<tr>
|
||||
<th scope="col">故障序号</th>
|
||||
<th scope="col">故障名称</th>
|
||||
<th scope="col">删除故障</th>
|
||||
<th scope="col">操作</th>
|
||||
<th scope="col">删除</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -49,6 +50,7 @@
|
||||
<tr>
|
||||
<td>${rows.count}</td>
|
||||
<td>${fault.faultName}</td>
|
||||
<td><a href="${webroot}/admin/fault/query.do?faultId=${fault.faultId}">修改</a>
|
||||
<td><a href="${webroot}/admin/fault/delete.do?faultId=${fault.faultId}">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
@ -56,17 +58,27 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h1 class="h3 mb-3 fw-normal">添加报修类型</h1>
|
||||
<c:if test="${not empty requestScope.updateFaultId}">
|
||||
<h1 class="h3 mb-3 fw-normal">修改报修类型</h1>
|
||||
</c:if>
|
||||
<c:if test="${empty requestScope.updateFaultId}">
|
||||
<h1 class="h3 mb-3 fw-normal">添加报修类型</h1>
|
||||
</c:if>
|
||||
<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">
|
||||
<c:if test="${not empty requestScope.updateFaultId}">
|
||||
<form action="${webroot}/admin/fault/update.do?faultId=${requestScope.updateFaultId}" method="post">
|
||||
</c:if>
|
||||
<c:if test="${empty requestScope.updateFaultId}">
|
||||
<form action="${webroot}/admin/fault/add.do" method="post">
|
||||
</c:if>
|
||||
<div class="input-group mb-3">
|
||||
<span class="input-group-text">故障名称</span>
|
||||
<input type="text" class="form-control" name="faultName" id="faultName" required>
|
||||
<input type="text" class="form-control" name="faultName" id="faultName" value="${requestScope.updateFaultName}" required>
|
||||
</div>
|
||||
<input class="btn btn-primary w-100 py-2" type="submit" id="submit">
|
||||
<br/><br/>
|
||||
|
@ -52,8 +52,8 @@
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a href="${webroot}/admin/state.jsp" class="nav-link link-body-emphasis" aria-current="page">
|
||||
>> 报修区域管理
|
||||
<a href="${webroot}/admin/address.jsp" class="nav-link link-body-emphasis" aria-current="page">
|
||||
>> 报修区域维护
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
|
Loading…
Reference in New Issue
Block a user