package web.controller;
import com.alibaba.excel.EasyExcel;
import config.SpringContextUtil;
import entity.Course;
import entity.Leave;
import entity.LeaveData;
import entity.Student;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import service.CourseService;
import service.LeaveService;
import serviceImpl.CourseServiceImpl;
import serviceImpl.LeaveServiceImpl;
import java.io.*;
import java.net.URLEncoder;
import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@WebServlet(name = "leave", urlPatterns = "/leave")
public class LeaveServlet extends HttpServlet {
private String leave_list_page = "/WEB-INF/views/student/student_leave_list.jsp";
private String leave_viewAdd_page = "/WEB-INF/views/student/student_leave_add.jsp";
private String instructor_leave_list_page = "/WEB-INF/views/instructor/instructor_leave_list.jsp";
private String instructor_leave_viewExamine_page = "/WEB-INF/views/instructor/instructor_leave_examine.jsp";
private String instructor_leave_viewExport_page = "/WEB-INF/views/instructor/instructor_export_leave_list.jsp";
@Autowired
private LeaveService leaveService;
@Autowired
private CourseService courseService;
@Override
public void init() throws ServletException {
this.leaveService = (LeaveServiceImpl) SpringContextUtil.getBean("leaveServiceImpl", LeaveServiceImpl.class);
this.courseService = (CourseServiceImpl) SpringContextUtil.getBean("courseServiceImpl", CourseServiceImpl.class);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String action = req.getParameter("action");
if (action == null) {
List<Leave> leaves = leaveService.getAllLeave();
req.setAttribute("leaves", leaves);
RequestDispatcher dispatcher = req.getRequestDispatcher(leave_list_page);
dispatcher.forward(req, resp);
} else if (action.equals("delete")) {
String leaveID = req.getParameter("leaveID");
boolean flag = leaveService.deleteLeave(leaveID);
if (flag) {
String message = "删除成功!";
resp.setContentType("text/html;charset=UTF-8");
String jsCode = "<script>alert('" + message + "');window.location.href='" + req.getContextPath() + "/leave';</script>";
resp.getWriter().write(jsCode);
}
} else if (action.equals("viewAdd")) {
/*
* 给请假申请表单生成leaveID
* */
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
String text = now.format(formatter);
SecureRandom random = new SecureRandom();
int randomNum = 100 + random.nextInt(900);
String randomNumberString = String.valueOf(randomNum);
String leaveID = (text + randomNumberString);
req.setAttribute("leaveID", leaveID);
/*
* 将课程列表传入
* */
List<Course> courses = courseService.getAllCourses();
req.setAttribute("courses", courses);
RequestDispatcher dispatcher = req.getRequestDispatcher(leave_viewAdd_page);
dispatcher.forward(req, resp);
} else if (action.equals("add")) {
String leaveID = req.getParameter("leaveID");
String courseID = req.getParameter("courseID");
String reason = req.getParameter("reason");
int daynum = Integer.parseInt(req.getParameter("daynum"));
/*
* 生成当下时间用作请假申请时间(applytime)
* */
LocalDateTime now = LocalDateTime.now();
Date applytime = Date.from(now.atZone(ZoneId.systemDefault()).toInstant());
/*
* 获取存在会话里的学号
* */
Student student = (Student) req.getSession().getAttribute("student");
String stuNo = student.getStuID();
String status = "0";
Leave leave = new Leave(leaveID, courseID, reason, daynum, stuNo, applytime, status);
boolean flag = leaveService.addLeave(leave);
if (flag) {
String message = "添加成功!";
resp.setContentType("text/html;charset=UTF-8");
String jsCode = "<script>alert('" + message + "');window.location.href='" + req.getContextPath() + "/leave';</script>";
resp.getWriter().write(jsCode);
}
} else if (action.equals("viewLeavelist")) {
List<Leave> leaves = leaveService.getAllLeave();
req.setAttribute("leaves", leaves);
RequestDispatcher dispatcher = req.getRequestDispatcher(instructor_leave_list_page);
dispatcher.forward(req, resp);
} else if (action.equals(("viewExamine"))) {
String leaveID = req.getParameter("leaveID");
Leave leave = leaveService.getLeaveByLeaveID(leaveID);
req.setAttribute("leave", leave);
RequestDispatcher dispatcher = req.getRequestDispatcher(instructor_leave_viewExamine_page);
dispatcher.forward(req, resp);
} else if (action.equals("examine")) {
String leaveID = req.getParameter("leaveID");
String opinion = req.getParameter("opinion");
String status = req.getParameter("status");
/*
* 生成当下时间用作请假审核时间(audittime)
* */
LocalDateTime now = LocalDateTime.now();
Date audittime = Date.from(now.atZone(ZoneId.systemDefault()).toInstant());
Leave leave = new Leave(leaveID, opinion, status, audittime);
boolean flag = leaveService.examineLeave(leave);
if (flag) {
String message = "审核成功!";
resp.setContentType("text/html;charset=UTF-8");
String jsCode = "<script>alert('" + message + "');window.location.href='" + req.getContextPath() + "/leave?action=viewLeavelist';</script>";
resp.getWriter().write(jsCode);
}
} else if (action.equals("search")) {
String leaveID = req.getParameter("leaveID");
String courseID = req.getParameter("courseID");
String stuNo = req.getParameter("stuNo");
List<Leave> leaves = leaveService.searchLeave(leaveID, courseID, stuNo);
req.getSession().setAttribute("leaves", leaves);
req.setAttribute("leaves", leaves);
/*
* 处理时间数据上的格式
* */
/*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
List<String> applytimes = new ArrayList<>();
List<String> audittimes = new ArrayList<>();
for (Leave leave : leaves){
applytimes.add(sdf.format(leave.getApplytime()));
audittimes.add(sdf.format(leave.getAudittime()));
}
req.setAttribute("applytimes", applytimes);
req.setAttribute("audittimes", audittimes);*/
RequestDispatcher dispatcher = req.getRequestDispatcher(instructor_leave_viewExport_page);
dispatcher.forward(req, resp);
} else if (action.equals("viewExport")) {
RequestDispatcher dispatcher = req.getRequestDispatcher(instructor_leave
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
大三上学期期中课设:请假系统,软件架构:采用spring管理,mybatis,servlet.zip【源码+sql文件】
资源推荐
资源详情
资源评论
收起资源包目录
2024秋学期期中课设(大三):请假系统,软件架构:采用spring管理,mybatis,servlet.zip【源码+sql文件】 (228个子文件)
LeaveServlet.class 11KB
StudentServlet.class 6KB
CourseServlet.class 6KB
InstructorServlet.class 6KB
ClassesServlet.class 6KB
DepartmentServlet.class 5KB
LoginServlet.class 4KB
DemoData.class 4KB
Leave.class 4KB
Student.class 4KB
UserServlet.class 3KB
LeaveData.class 3KB
Course.class 3KB
Instructor.class 2KB
Classes.class 2KB
User.class 2KB
InstructorServiceImpl.class 2KB
StudentServiceImpl.class 2KB
UserServiceImpl.class 2KB
LeaveServiceImpl.class 2KB
DepartmentServiceImpl.class 2KB
ClassesServiceImpl.class 2KB
CourseServiceImpl.class 2KB
Department.class 1KB
EncodeFilter.class 1KB
InitServlet.class 1KB
test.class 1KB
SpringContextUtil.class 892B
InstructorMapper.class 890B
StudentMapper.class 842B
LeaveMapper.class 752B
DepartmentMapper.class 743B
InstructorService.class 722B
ClassesMapper.class 716B
CourseMapper.class 710B
DepartmentService.class 700B
StudentService.class 676B
LeaveService.class 604B
ClassesService.class 586B
CourseService.class 578B
UserMapper.class 432B
UserService.class 304B
.gitignore 182B
poi-ooxml-lite-5.2.5.jar 5.67MB
druid-1.2.19.jar 3.72MB
jakarta.servlet.jsp.jstl-2.0.0.jar 3.53MB
poi-5.2.5.jar 2.84MB
mysql-connector-j-8.0.33.jar 2.37MB
commons-math3-3.6.1.jar 2.11MB
xmlbeans-5.2.0.jar 2.1MB
lombok-1.18.36.jar 1.96MB
poi-ooxml-5.2.5.jar 1.93MB
mybatis-3.5.16.jar 1.73MB
ehcache-3.9.11.jar 1.71MB
protobuf-java-3.21.9.jar 1.59MB
spring-core-5.2.25.RELEASE.jar 1.38MB
spring-context-5.2.25.RELEASE.jar 1.18MB
commons-compress-1.25.0.jar 1.03MB
thymeleaf-3.1.2.RELEASE.jar 916KB
javassist-3.29.0-GA.jar 775KB
commons-collections4-4.4.jar 734KB
spring-beans-5.2.25.RELEASE.jar 673KB
spring-test-5.2.25.RELEASE.jar 670KB
easyexcel-core-4.0.3.jar 528KB
commons-io-2.15.0.jar 489KB
easyexcel-support-3.3.4.jar 448KB
spring-jdbc-5.2.25.RELEASE.jar 400KB
junit-4.13.2.jar 376KB
spring-aop-5.2.25.RELEASE.jar 365KB
servlet-api.jar 358KB
servlet-api.jar 358KB
commons-codec-1.16.0.jar 352KB
jakarta.servlet-api-6.0.0.jar 339KB
log4j-api-2.21.1.jar 310KB
spring-tx-5.2.25.RELEASE.jar 307KB
jakarta.servlet-api-5.0.0.jar 301KB
spring-expression-5.2.25.RELEASE.jar 279KB
ognl-3.3.4.jar 259KB
attoparser-2.0.7.RELEASE.jar 241KB
taglibs-standard-impl-1.2.5.jar 202KB
thymeleaf-spring5-3.1.2.RELEASE.jar 182KB
unbescape-1.1.6.RELEASE.jar 170KB
jakarta.xml.bind-api-3.0.0.jar 126KB
curvesapi-1.08.jar 114KB
jakarta.el-api-5.0.0.jar 86KB
jakarta.el-api-4.0.0.jar 79KB
jsp-api.jar 77KB
mybatis-spring-2.0.6.jar 70KB
jakarta.servlet.jsp-api-3.1.0.jar 69KB
jakarta.servlet.jsp-api-3.0.0.jar 65KB
slf4j-api-2.0.7.jar 62KB
jakarta.activation-2.0.0.jar 61KB
commons-csv-1.11.0.jar 55KB
jakarta.servlet.jsp.jstl-api-3.0.0.jar 45KB
jakarta.servlet.jsp.jstl-api-2.0.0.jar 45KB
hamcrest-core-1.3.jar 44KB
slf4j-api-1.7.36.jar 40KB
SparseBitSet-1.3.jar 25KB
spring-jcl-5.2.25.RELEASE.jar 23KB
easyexcel-4.0.3.jar 3KB
共 228 条
- 1
- 2
- 3
资源评论
编程ID
- 粉丝: 8w+
- 资源: 817
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功