diff --git a/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminOrderController.java b/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminOrderController.java new file mode 100644 index 0000000..6986856 --- /dev/null +++ b/src/main/java/cn/edu/cqwu/repair/controller/admin/AdminOrderController.java @@ -0,0 +1,74 @@ +package cn.edu.cqwu.repair.controller.admin; + +import cn.edu.cqwu.repair.dao.OrderDao; +import cn.edu.cqwu.repair.dao.WorkerDao; +import cn.edu.cqwu.repair.entity.Order; +import cn.edu.cqwu.repair.service.OrderService; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; + +import java.util.ArrayList; + +/** + * @author xtaod + */ +@Controller +public class AdminOrderController { + OrderDao orderDao; + WorkerDao workerDao; + OrderService orderService; + + public AdminOrderController(OrderDao orderDao, WorkerDao workerDao, OrderService orderService) { + this.orderDao = orderDao; + this.workerDao = workerDao; + this.orderService = orderService; + } + + @RequestMapping("/admin/order_manage/manage.do") + public String manage( + String userNo, + String workerNo, + String contact, + String phone, + Model model) { + model.addAttribute("userNo", userNo); + model.addAttribute("workerNo", workerNo); + model.addAttribute("contact", contact); + model.addAttribute("phone", phone); + if (userNo != null && workerNo != null && contact != null && phone != null) { + ArrayList orders = orderDao.find(userNo, workerNo, contact, phone); + model.addAttribute("Orders", orders); + } else { + model.addAttribute("stuManageMess", "* 请输入查询条件!"); + } + return "/admin/order"; + } + + @RequestMapping("/admin/order_manage/delete.do") + public String delete(int id, Model model) { + if (orderDao.delete(id) != 0) { + model.addAttribute("orderMess", "* 订单 " + id + " 已删除!"); + } else { + model.addAttribute("orderMess", "* 订单 " + id + " 删除失败!"); + } + return "/admin/order"; + } + + @RequestMapping("/admin/order_manage/choose.do") + public String choose(int id, Model model) { + model.addAttribute("id", id); + model.addAttribute("workers", workerDao.findAll()); + return "/admin/order_choose"; + } + + @RequestMapping("/admin/order_manage/chooseApply.do") + public String chooseApply(int id, int workerNo, Model model) { + if (orderService.modifyOrderStatus(id, workerNo) != 0) { + model.addAttribute("orderMess", "* 订单 " + id + " 已分配给工人 " + workerNo + "!"); + } else { + model.addAttribute("orderMess", "* 订单 " + id + " 分配失败!"); + } + return "/admin/order_choose"; + } +} diff --git a/src/main/java/cn/edu/cqwu/repair/dao/OrderDao.java b/src/main/java/cn/edu/cqwu/repair/dao/OrderDao.java index 3391a93..d5b0fa1 100644 --- a/src/main/java/cn/edu/cqwu/repair/dao/OrderDao.java +++ b/src/main/java/cn/edu/cqwu/repair/dao/OrderDao.java @@ -8,6 +8,8 @@ public interface OrderDao { int add(Order order); int update(Order order); + int delete(Order order); + int delete(int orderId); ArrayList findByStudent_id(int stuId); ArrayList findCurrent(int stuId); ArrayList findByWorkerId(int workerId); @@ -17,4 +19,7 @@ public interface OrderDao { public Order findByOrderId(int orderId); public ArrayList findHistoryList(int workerId); + + ArrayList find(String userNo, String workerNo, String contact, String phone); + } diff --git a/src/main/java/cn/edu/cqwu/repair/dao/WorkerDao.java b/src/main/java/cn/edu/cqwu/repair/dao/WorkerDao.java index 7627bb0..8047e9f 100644 --- a/src/main/java/cn/edu/cqwu/repair/dao/WorkerDao.java +++ b/src/main/java/cn/edu/cqwu/repair/dao/WorkerDao.java @@ -12,6 +12,7 @@ public interface WorkerDao { public ArrayList findWorkersLikeUsername(String username); ArrayList findAll(); + Worker findByUserId(int userId); int deleteByUserName(String username); diff --git a/src/main/java/cn/edu/cqwu/repair/dao/impl/OrderDaoImpl.java b/src/main/java/cn/edu/cqwu/repair/dao/impl/OrderDaoImpl.java index 372e01d..f19b956 100644 --- a/src/main/java/cn/edu/cqwu/repair/dao/impl/OrderDaoImpl.java +++ b/src/main/java/cn/edu/cqwu/repair/dao/impl/OrderDaoImpl.java @@ -13,6 +13,7 @@ import org.springframework.stereotype.Component; import java.util.ArrayList; +import static cn.edu.cqwu.repair.entity.table.StuTableDef.STU; import static cn.edu.cqwu.repair.entity.table.WorkerTableDef.WORKER; import static cn.edu.cqwu.repair.entity.table.OrderTableDef.ORDER; @@ -33,6 +34,20 @@ public class OrderDaoImpl implements OrderDao { return mapper.update(order); } + @Override + public int delete(Order order) { + return mapper.delete(order); + } + + @Override + public int delete(int orderId) { + Order order = findByOrderId(orderId); + if (order == null) { + return 0; + } + return delete(order); + } + @Override public ArrayList findByStudent_id(int stuId) { QueryWrapper qw = new QueryWrapper(); @@ -87,4 +102,25 @@ public class OrderDaoImpl implements OrderDao { return (ArrayList) mapper.selectListByQuery(qw); } + @Override + public ArrayList find(String userNo, String workerNo, String contact, String phone) { + QueryWrapper qw = new QueryWrapper(); + qw.select(ORDER.ALL_COLUMNS); + if (userNo != null && !userNo.isEmpty()) { + qw.leftJoin(STU).on(ORDER.STUDENT_ID.eq(STU.USERID)); + qw.where(STU.USER_NO.like(userNo)); + } + if (workerNo != null && !workerNo.isEmpty()) { + qw.leftJoin(WORKER).on(ORDER.WORKER_ID.eq(WORKER.USERID)); + qw.where(WORKER.USER_NO.like(workerNo)); + } + if (contact != null && !contact.isEmpty()) { + qw.where(ORDER.CONTACT.like(contact)); + } + if (phone != null && !phone.isEmpty()) { + qw.where(ORDER.PHONE.like(phone)); + } + return (ArrayList) mapper.selectListByQuery(qw); + } + } diff --git a/src/main/java/cn/edu/cqwu/repair/dao/impl/WorkerDaoImpl.java b/src/main/java/cn/edu/cqwu/repair/dao/impl/WorkerDaoImpl.java index ec5574c..cc16ba8 100644 --- a/src/main/java/cn/edu/cqwu/repair/dao/impl/WorkerDaoImpl.java +++ b/src/main/java/cn/edu/cqwu/repair/dao/impl/WorkerDaoImpl.java @@ -59,6 +59,13 @@ public class WorkerDaoImpl implements WorkerDao { return (ArrayList) MAPPER.selectAll(); } + @Override + public Worker findByUserId(int userId) { + QueryWrapper qw = new QueryWrapper(); + qw.select(WORKER.ALL_COLUMNS).where(WORKER.USERID.eq(userId)); + return MAPPER.selectOneByQuery(qw); + } + @Override public int deleteByUserName(String username) { QueryWrapper qw = new QueryWrapper(); diff --git a/src/main/java/cn/edu/cqwu/repair/service/OrderService.java b/src/main/java/cn/edu/cqwu/repair/service/OrderService.java index fa959c8..b917b44 100644 --- a/src/main/java/cn/edu/cqwu/repair/service/OrderService.java +++ b/src/main/java/cn/edu/cqwu/repair/service/OrderService.java @@ -1,8 +1,13 @@ package cn.edu.cqwu.repair.service; +import cn.edu.cqwu.repair.entity.Order; +import cn.edu.cqwu.repair.entity.Worker; + /** * @author xtaod */ public interface OrderService { void submitWorkers(); + int modifyOrderStatus(int orderId, int workerId); + int modifyOrderStatus(Order order, Worker worker); } diff --git a/src/main/java/cn/edu/cqwu/repair/service/impl/OrderServiceImpl.java b/src/main/java/cn/edu/cqwu/repair/service/impl/OrderServiceImpl.java index 2bf1454..4921bc8 100644 --- a/src/main/java/cn/edu/cqwu/repair/service/impl/OrderServiceImpl.java +++ b/src/main/java/cn/edu/cqwu/repair/service/impl/OrderServiceImpl.java @@ -42,9 +42,33 @@ public class OrderServiceImpl implements OrderService { } } + @Override + public int modifyOrderStatus(int orderId, int workerId) { + Order order = orderDao.findByOrderId(orderId); + Worker worker = workerDao.findByUserId(workerId); + return modifyOrderStatus(order, worker); + } + + @Override + public int modifyOrderStatus(Order order, Worker worker) { + if (order.getWorkerId() != 0) { + Worker oldWorker = workerDao.findByUserId(order.getWorkerId()); + oldWorker.setOrderStatus(WorkerStatus.FREE.value); + workerDao.update(oldWorker); + System.out.println("修改了 worker " + oldWorker.getUserid() + " - " + oldWorker.getOrderStatus()); + } + order.setWorkerId(worker.getUserid()); + order.setOrderStatus(OrderStatus.PROGRESS.value); + worker.setOrderStatus(WorkerStatus.BUSY.value); + workerDao.update(worker); + System.out.println("修改了 order " + order.getOrderId() + " - " + order.getOrderStatus()); + System.out.println("修改了 worker " + worker.getUserid() + " - " + worker.getOrderStatus()); + return orderDao.update(order); + } + @Override @Async - @Scheduled(cron = "0 0/5 * * * ? ") + @Scheduled(cron = "0 */5 * * * ? ") public void submitWorkers() { System.out.println("[submitWorkers] start"); initDeviceMap(); @@ -52,13 +76,7 @@ public class OrderServiceImpl implements OrderService { for (Order order: orders) { Worker worker = getFreeWorker(deviceTypeMap.get(order.getDeviceId())); if (worker != null) { - order.setWorkerId(worker.getUserid()); - order.setOrderStatus(OrderStatus.PROGRESS.value); - orderDao.update(order); - worker.setOrderStatus(WorkerStatus.BUSY.value); - workerDao.update(worker); - System.out.println("修改了 order " + order.getOrderId() + " - " + order.getOrderStatus()); - System.out.println("修改了 worker " + worker.getUserid() + " - " + worker.getOrderStatus()); + modifyOrderStatus(order, worker); } } System.out.println("[submitWorkers] end"); diff --git a/src/main/resources/springmvc.xml b/src/main/resources/springmvc.xml index ef299ca..e787357 100644 --- a/src/main/resources/springmvc.xml +++ b/src/main/resources/springmvc.xml @@ -3,12 +3,15 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" + xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc - http://www.springframework.org/schema/mvc/spring-mvc.xsd"> + http://www.springframework.org/schema/mvc/spring-mvc.xsd + http://www.springframework.org/schema/task + http://www.springframework.org/schema/task/spring-task.xsd"> @@ -19,5 +22,15 @@ + + + + + + + + + + diff --git a/src/main/webapp/admin/order.jsp b/src/main/webapp/admin/order.jsp new file mode 100644 index 0000000..2529fa2 --- /dev/null +++ b/src/main/webapp/admin/order.jsp @@ -0,0 +1,114 @@ +<%-- + Created by IntelliJ IDEA. + User: xtaod + Date: 2024/6/6 + Time: 下午9:48 + To change this template use File | Settings | File Templates. +--%> +<%@ page import="cn.edu.cqwu.repair.entity.Device" %> +<%@ 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" %> + +
+ + +

${title}

+ + + + +
+
+ 学号 + +
+
+ 工号 + +
+
+ 联系人 + +
+
+ 手机号 + +
+ +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
序号联系人名称联系人电话详细地点故障描述处理状态操作
${loop.index + 1}${repairOrder.contact}${repairOrder.phone}${repairOrder.address}${repairOrder.faultDesc} + + + 待安排维修人员 + + + 正在维修中 + + + 等待评价 + + + 维修已完成 + + + + 分配 | + 详情 | + 撤销 +
+
+
+
+ + diff --git a/src/main/webapp/admin/order_choose.jsp b/src/main/webapp/admin/order_choose.jsp new file mode 100644 index 0000000..96c8f29 --- /dev/null +++ b/src/main/webapp/admin/order_choose.jsp @@ -0,0 +1,58 @@ +<%-- + Created by IntelliJ IDEA. + User: xtaod + Date: 2024/6/6 + Time: 下午10:18 + To change this template use File | Settings | File Templates. +--%> +<%@ page import="cn.edu.cqwu.repair.entity.Device" %> +<%@ 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" %> + +
+ + +

${title}

+ + + + +
+
+ 维修人员 + +
+ +

+
+
+
+ + diff --git a/src/main/webapp/includes/menu.jsp b/src/main/webapp/includes/menu.jsp index 7f1fd95..da82859 100644 --- a/src/main/webapp/includes/menu.jsp +++ b/src/main/webapp/includes/menu.jsp @@ -62,7 +62,7 @@