Team project/대학학사관리 - Chelsea University
휴학 신청 처리하기
개발자공부
2024. 10. 25. 18:00
JSP
들어온 휴학 신청이 있다면 리스트를 클릭했을 때 상세보기를 확인할 수 있습니다. 이 페이지에서 승인할지 반려할지 선택 처리할 수 있습니다.
더보기
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ include file="/WEB-INF/views/home/studentHeader.jsp"%>
<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/main.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/sidebar.css">
<!-- 세부 메뉴 + 메인 -->
<div class="d-flex justify-content-center align-items-start" style="display:flex; min-width: 100em;">
<!-- 세부 메뉴 div-->
<div class="sub--menu">
<div class="sub--menu--top">
<h2>MY</h2>
</div>
<!-- 메뉴 -->
<!-- 선택된 메뉴에 class="selected--menu" 추가해주세요 -->
<div class="sub--menu--mid">
<table class="sub--menu--table" border="1">
<tbody><tr>
<td><a href="/chelseaUniversity/user/studentList">학생 명단 조회</a></td>
</tr>
<tr>
<td><a href="/chelseaUniversity/user/professorList">교수 명단 조회</a></td>
</tr>
<tr>
<td><a href="/chelseaUniversity/user/student">학생 등록</a></td>
</tr>
<tr>
<td><a href="/chelseaUniversity/user/professor">교수 등록</a></td>
</tr>
<tr>
<td><a href="/chelseaUniversity/tuition/bill">등록금 고지서 발송</a></td>
</tr>
<tr>
<td><a href="/chelseaUniversity/break/list/staff">휴학 처리</a></td>
</tr>
<tr>
<td><a href="/chelseaUniversity/sugang/period">수강신청 기간 설정</a></td>
</tr>
</tbody></table>
</div>
</div>
<main class="main-content">
<h1 class="sub--title">휴학 처리</h1>
<div class="split--div"></div>
<table class="table table-striped sub--list--table">
<tr>
<th>단과대</th>
<td>${college.name}</td>
<th>학과</th>
<td>${deptInfo.name}</td>
</tr>
<tr>
<th>학번</th>
<td>${studentInfo.id}</td>
<th>학년</th>
<td>${studentInfo.grade}</td>
</tr>
<tr>
<th>전화번호</th>
<td>${studentInfo.tel}</td>
<th>성명</th>
<td>${studentInfo.name}</td>
</tr>
<tr>
<th>주소</th>
<td>${studentInfo.address}</td>
</tr>
<tr>
<th>기간</th>
<td>${breakApp.fromYear}년도${breakApp.fromSemester}학기부터${breakApp.toYear}년도 ${breakApp.toSemester}학기까지</td>
</tr>
<tr>
<th>휴학 구분</th>
<td>${breakApp.type}휴학</td>
</tr>
<tr>
<p>위와 같이 휴학하고자 하오니 허가하여 주시기 바랍니다.</p>
</tr>
</table>
<div class="div-form1">
<form action="${pageContext.request.contextPath}/break/update?id=${breakApp.id}" method="post">
<input type="hidden" name="status" value="승인">
<button type=submit class="btn-edit">승인하기</button>
</form>
<form action="${pageContext.request.contextPath}/break/update?id=${breakApp.id}" method="post">
<input type="hidden" name="status" value="반려">
<button type=submit class="btn-edit">반려하기</button>
</form>
</div>
</main>
</div>
<%@ include file="/WEB-INF/views/home/footer.jsp"%>
Controller
휴학 요청이 들어왔는 지 확인, 승인 혹은 반려 처리 기능이 있습니다. 교직원이 승인을 눌러야만 복학 날짜와 함께 학생 재적 상태가 휴학으로 변경됩니다. 반려를 누른다면 재적 상태는 변하지 않고 학생은 휴학 신청이 처리중에서 반려로 바뀐 것을 확인할 수 있습니다.
더보기
package com.chelseaUniversity.ver1.controller;
@WebServlet("/break/*")
public class BreakController extends HttpServlet {
private static final long serialVersionUID = 1L;
private BreakAppRepository breakAppRepository;
private StudentRepository studentRepository;
private DepartmentRepository departmentRepository;
private CollegeRepository collegeRepository;
private StuStatRepository stuStatRepository;
@Override
public void init() throws ServletException {
breakAppRepository = new BreakAppRepositoryImpl();
studentRepository = new StudentRepositoryImpl();
departmentRepository = new DepartmentRepositoryImpl();
collegeRepository = new CollegeRepositoryImpl();
stuStatRepository = new StuStatRepositoryImpl();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action = request.getPathInfo();
HttpSession session = request.getSession();
StudentInfoDto principalStu = null;
User userRole = (User) session.getAttribute("user");
if ("student".equalsIgnoreCase(userRole.getUserRole())) {
principalStu = (StudentInfoDto) session.getAttribute("principal");
}
BreakApp app = null;
if (principalStu != null) {
app = breakAppRepository.selectByStudentIdOne(principalStu.getId());
request.setAttribute("app", app);
}
boolean status = false;
if (app != null) {
request.setAttribute("app", app);
status = "승인".equals(app.getStatus()) ? true : false;
request.setAttribute("status", status);
}
boolean application = app != null ? true : false;
request.setAttribute("application", application);
if (action != null || action.trim().isEmpty()) {
switch (action) {
case "/application":
if (status) {
String message = "휴학 상태입니다.";
request.setAttribute("message", message);
}
request.setAttribute("application", application);
request.getRequestDispatcher("/WEB-INF/views/student/breakApplication.jsp").forward(request, response);
break;
case "/list":
request.setAttribute("application", application);
request.getRequestDispatcher("/WEB-INF/views/student/breakHistory.jsp").forward(request, response);
break;
case "/list/staff":
readBreakList(request, response, session);
break;
case "/breakDetail":
readBreakDetail(request, response, session);
request.getRequestDispatcher("/WEB-INF/views/staff/breakDetail.jsp").forward(request, response);
break;
case "/detail":
readBreakHistoryDetail(request, response, principalStu, app);
break;
default:
response.sendError(HttpServletResponse.SC_NOT_FOUND);
break;
}
} else {
response.sendRedirect(request.getContextPath());
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action = request.getPathInfo();
HttpSession session = request.getSession();
User userRole = (User) session.getAttribute("user");
StudentInfoDto principal = null;
if ("student".equalsIgnoreCase(userRole.getUserRole())) {
principal = (StudentInfoDto) session.getAttribute("principal");
}
if (action != null || action.trim().isEmpty()) {
switch (action) {
case "/application":
insertBreakApplication(request, response, principal);
response.sendRedirect(request.getContextPath() + "/break/list");
break;
case "/update":
updateBreak(request, response, session);
break;
case "/delete":
deleteBreak(request, response);
break;
default:
response.sendError(HttpServletResponse.SC_NOT_FOUND);
break;
}
} else {
response.sendRedirect(request.getContextPath());
}
}
/**
* 교직원 -> 휴학 요청 들어왔는지 확인
*
* @param request
* @param response
* @param session
* @throws ServletException
* @throws IOException
*/
private void readBreakList(HttpServletRequest request, HttpServletResponse response, HttpSession session)
throws ServletException, IOException {
try {
List<BreakApp> breakAppList = breakAppRepository.selectByStatus("처리중");
request.setAttribute("breakAppList", breakAppList);
request.getRequestDispatcher("/WEB-INF/views/staff/breakListStaff.jsp").forward(request, response);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 교직원 -> 휴학 신청 상세보기
*
* @param request
* @param response
* @param session
*/
private void readBreakDetail(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
int id = Integer.parseInt(request.getParameter("id"));
// 휴학신청 상태 받아오기
BreakApp breakApp = breakAppRepository.selectById(id);
// 학생 정보
Student studentInfo = studentRepository.selectByStudentId(breakApp.getStudentId());
// 소속 학과 이름
Department deptInfo = departmentRepository.selectById(studentInfo.getDeptId());
// 소속 단과대 이름
College college = collegeRepository.selectCollegeDtoById(deptInfo.getCollegeId());
request.setAttribute("breakApp", breakApp);
request.setAttribute("studentInfo", studentInfo);
request.setAttribute("deptInfo", deptInfo);
request.setAttribute("college", college);
}
/**
* 교직원 -> 휴학 처리 (승인 혹은 반려)
*
* @param request
* @param response
* @param session
* @throws IOException
*/
private void updateBreak(HttpServletRequest request, HttpServletResponse response, HttpSession session)
throws IOException {
String breakStatus = request.getParameter("status");
int breakId = Integer.parseInt(request.getParameter("id"));
BreakApp breakApp = breakAppRepository.selectById(breakId);
breakAppRepository.updateById(breakApp.getId(), breakStatus);
if (breakStatus.equals("승인")) {
BreakApp breakAppEntity = breakAppRepository.selectById(breakApp.getId());
String newToDate = null;
if (breakAppEntity.getToSemester() == 1) {
newToDate = breakAppEntity.getToYear() + "-08-31";
} else {
newToDate = (breakAppEntity.getToYear() + 1) + "-02-28";
}
// 가장 최근 기존 학적 상태
List<StuStat> stuStatInfo = stuStatRepository.selectByStudentIdOrderbyIdDesc(breakApp.getStudentId());
// 기존 학적 상태에서 to_date를 now()로 변경 + 휴학상태로 변경
int updateToNowDate = stuStatRepository.updateOldStatus(stuStatInfo.get(0).getId());
int updateBreakSta = stuStatRepository.updateStatusToBreak("휴학", stuStatInfo.get(0).getId());
// 새로운 학적 상태 추가
int insertRowCount = stuStatRepository.insert(breakAppEntity.getStudentId(), "휴학", newToDate,
breakApp.getId());
if (updateToNowDate + updateBreakSta + insertRowCount == 3) {
request.setAttribute("acceptBreak", breakApp);
}
}
response.sendRedirect(request.getContextPath() + "/break/list/staff");
}
/**
* 휴학 신청을 취소하는 메소드
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
private void deleteBreak(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
int id = Integer.parseInt(request.getParameter("id"));
breakAppRepository.deleteById(id);
request.getRequestDispatcher("/WEB-INF/views/student/breakHistory.jsp").forward(request, response);
} catch (NumberFormatException e) {
e.printStackTrace();
response.sendRedirect("/WEB-INF/views/student/breakHistory.jsp");
}
}
/**
* 휴학신청서 생성 메소드
*
* @param request
* @param response
* @param principal
*/
private void insertBreakApplication(HttpServletRequest request, HttpServletResponse response,
StudentInfoDto principal) {
BreakAppFormDto dto = BreakAppFormDto.builder().studentId(principal.getId()).studentGrade(principal.getGrade())
// TODO - 년도, 학기 고정값 >> 동적으로 년도와 학기 가져와야 됨.
.fromYear(2024).fromSemester(1).toYear(Integer.parseInt(request.getParameter("toYear")))
.toSemester(Integer.parseInt(request.getParameter("toSemester"))).type(request.getParameter("type"))
.build();
if (dto != null) {
breakAppRepository.insert(dto);
}
}
/**
* 휴학 신청내역 자세히 보는 메소드
*
* @param request
* @param response
* @param principalStu
* @param app
* @throws ServletException
* @throws IOException
*/
private void readBreakHistoryDetail(HttpServletRequest request, HttpServletResponse response,
StudentInfoDto principalStu, BreakApp app) throws ServletException, IOException {
try {
int id = Integer.parseInt(request.getParameter("id"));
app = breakAppRepository.selectById(id);
request.setAttribute("app", app);
request.setAttribute("principal", principalStu);
request.getRequestDispatcher("/WEB-INF/views/student/breakHistoryDetail.jsp").forward(request, response);
} catch (NumberFormatException e) {
e.printStackTrace();
response.sendRedirect("/WEB-INF/views/student/breakHistory.jsp");
}
}
}