352 lines
12 KiB
Java
352 lines
12 KiB
Java
package nlib.col.web;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.security.access.annotation.Secured;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.ModelMap;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import nlib.cmm.NlibCommonController;
|
|
import nlib.cmm.service.NlibProperty;
|
|
import nlib.cmm.service.PagingVO;
|
|
import nlib.col.service.CollectionService;
|
|
import nlib.col.service.CollectionVO;
|
|
import nlib.col.service.ReadService;
|
|
import nlib.restful.service.DataApiResVO;
|
|
import nlib.util.StringUtil;
|
|
|
|
/**
|
|
* <pre>
|
|
* @Class Name : ReadController.java
|
|
*
|
|
* @Description : 방문열람을 관리하는 컨트롤러
|
|
*
|
|
*
|
|
* @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
|
|
*
|
|
* </pre>
|
|
*
|
|
* @ ------------ -------- ---------------------------
|
|
* @ 수정일 수정자 수정내용
|
|
* @ ------------ -------- ---------------------------
|
|
* @ 2021. 10. 27. KNKIM 최초 생성
|
|
*
|
|
*
|
|
* @author 이씨플라자 * DIGITALSHIP KNKIM
|
|
* @since 2021. 10. 27.
|
|
* @version 1.0
|
|
*
|
|
*/
|
|
@Controller
|
|
public class ReadController extends NlibCommonController {
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(ReadController.class);
|
|
|
|
@Resource(name = "readService")
|
|
private ReadService readService;
|
|
|
|
|
|
@Resource(name = "collectionService")
|
|
private CollectionService collectionService;
|
|
|
|
|
|
/**
|
|
* 열람신청을 등록하는 화면을 표출한다.
|
|
*
|
|
* @param request
|
|
* @param readVO
|
|
* @param model
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@Secured("ROLE_USER")
|
|
@RequestMapping(value={"/read/confirmReadFromCart.do", "/read/confirmRead.do"})
|
|
public String confirmRead(HttpServletRequest request, CollectionVO readVO, String csrfToken, String fromPage, ModelMap model) throws Exception {
|
|
|
|
String retJsp = "nlib/read/confirmRead";
|
|
boolean fromCart = request.getServletPath().contains("Cart.do");
|
|
|
|
String mbInfoId = getMbInfoId(request);
|
|
|
|
if(StringUtil.isEmpty(mbInfoId)) {
|
|
model.addAttribute("message", "로그인 후, 이용해 주시기 바랍니다.");
|
|
return retJsp;
|
|
}
|
|
|
|
if(!isValidCsrfToken(request, csrfToken)) {
|
|
if(fromCart && StringUtil.getString(fromPage, "").equalsIgnoreCase("login")) {
|
|
// 비로그인자의 카트에서 신청을 실행하여 로그인 후 신청 진입으로 돌아온 경우
|
|
return "redirect:/cart/listCartItems.do?cartTypeCd=2";
|
|
} else {
|
|
model.addAttribute("message", "잘못된 접근입니다.");
|
|
return retJsp;
|
|
}
|
|
}
|
|
|
|
if(readVO == null || StringUtil.isEmpty(readVO.getSelItems())) {
|
|
if(fromCart && StringUtil.getString(fromPage, "").equalsIgnoreCase("login")) {
|
|
// 비로그인자의 카트에서 신청을 실행하여 로그인 후 신청 진입으로 돌아온 경우
|
|
return "redirect:/cart/listCartItems.do";
|
|
} else {
|
|
model.addAttribute("message", "신청할 정보가 없습니다.");
|
|
return "nlib/read/confirmRead";
|
|
}
|
|
}
|
|
|
|
String selItems = readVO.getSelItems();
|
|
|
|
List<CollectionVO> list = collectionService.makeInfoListOfCollectionVO(selItems, mbInfoId);
|
|
List<HashMap<String, String>> listDates = readService.listDates();
|
|
|
|
if(StringUtil.isEmpty(readVO.getMngOrgNm()) && list != null && list.size() > 0) {
|
|
readVO.setMngOrgCd(list.get(0).getMngOrgCd());
|
|
readVO.setMngOrgNm(list.get(0).getMngOrgNm());
|
|
}
|
|
|
|
// CSRF 토큰 생성
|
|
String token = generateCsrfToken(request);
|
|
model.addAttribute("csrfToken", token);
|
|
|
|
model.addAttribute("readVO", readVO);
|
|
model.addAttribute("list", list);
|
|
model.addAttribute("listDates", listDates);
|
|
if(fromCart) model.addAttribute("fromCart", fromCart ? "Y" : "N");
|
|
|
|
return retJsp;
|
|
}
|
|
|
|
/**
|
|
* 열람신청을 등록한다.
|
|
*
|
|
* @param request
|
|
* @param readVO
|
|
* @param model
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@Secured("ROLE_USER")
|
|
@RequestMapping(value={"/read/insertReadItemsFromCart.do", "/read/insertReadItems.do"})
|
|
public String insertReadItems(HttpServletRequest request, CollectionVO readVO, String csrfToken, ModelMap model) throws Exception {
|
|
|
|
boolean fromCart = request.getServletPath().contains("Cart.do");
|
|
String retJsp = "nlib/read/insertReadItems";
|
|
String mbInfoId = getMbInfoId(request);
|
|
|
|
if(StringUtil.isEmpty(mbInfoId)) {
|
|
model.addAttribute("message", "로그인 후, 이용해 주시기 바랍니다.");
|
|
return retJsp;
|
|
}
|
|
|
|
if(!isValidCsrfToken(request, csrfToken)) {
|
|
model.addAttribute("message", "잘못된 접근입니다.");
|
|
return retJsp;
|
|
}
|
|
|
|
if(readVO == null || StringUtil.isEmpty(readVO.getSelItems())) {
|
|
model.addAttribute("message", "대출(예약)신청할 정보가 없습니다.");
|
|
return retJsp;
|
|
}
|
|
|
|
if(StringUtil.isEmpty(readVO.getMngOrgCd())) {
|
|
model.addAttribute("message", "관리문화원 정보가 없습니다.");
|
|
return retJsp;
|
|
}
|
|
|
|
if(StringUtil.isEmpty(readVO.getHopeReqPridDtmFrom() )) {
|
|
model.addAttribute("message", "방문희망일 시작일자를 확인할 수 없습니다.");
|
|
return retJsp;
|
|
}
|
|
|
|
if(StringUtil.isEmpty(readVO.getHopeReqPridDtmTo() )) {
|
|
model.addAttribute("message", "방문희망일 종료일자를 확인할 수 없습니다.");
|
|
return retJsp;
|
|
}
|
|
|
|
if(readVO.getHopeReqPridDtmFrom().compareTo(readVO.getHopeReqPridDtmTo()) > 0) {
|
|
model.addAttribute("message", "방문희망일 종료일자는 시작일자 이후이어야 합니다.");
|
|
return retJsp;
|
|
}
|
|
|
|
|
|
String selItems = readVO.getSelItems();
|
|
|
|
List<CollectionVO> list = collectionService.makeListOfCollectionVO(selItems);
|
|
|
|
list = readService.insertReadItems(list, mbInfoId, readVO, fromCart);
|
|
list = collectionService.setDetailInfoForList(list, mbInfoId);
|
|
|
|
model.addAttribute("readVO", readVO);
|
|
model.addAttribute("list", list);
|
|
if(fromCart) model.addAttribute("fromCart", fromCart ? "Y" : "N");
|
|
|
|
return retJsp;
|
|
}
|
|
|
|
|
|
/**
|
|
* 열람 목록 화면을 호출한다.
|
|
*
|
|
* @param request
|
|
* @param searchVO
|
|
* @param model
|
|
* @param message
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
@Secured("ROLE_USER")
|
|
@RequestMapping("/read/listReadItems.do")
|
|
public String listReadItems(HttpServletRequest request, CollectionVO searchVO, ModelMap model, String message) throws Exception {
|
|
|
|
String mbInfoId = getMbInfoId(request);
|
|
|
|
if(StringUtil.isEmpty(mbInfoId)) {
|
|
message = "로그인하신 후, 이용바랍니다.";
|
|
model.addAttribute("message", message);
|
|
return "nlib/read/listReadItems";
|
|
}
|
|
|
|
// CSRF 토큰 생성
|
|
String token = generateCsrfToken(request);
|
|
model.addAttribute("csrfToken", token);
|
|
|
|
// 대출자료 문화원 목록 조회
|
|
List<HashMap<String, String>> readMngOrgList = readService.listReadMngOrg(mbInfoId);
|
|
model.addAttribute("rentMngOrgList" , readMngOrgList);
|
|
|
|
model.addAttribute("reqStatusDivCd", StringUtil.getString(searchVO.getReqStatusDivCd(), "A")); // 기본값 신청
|
|
model.addAttribute("pageSize" , searchVO.getPageSize());
|
|
model.addAttribute("pageIndex" , searchVO.getPageIndex());
|
|
model.addAttribute("message" , message);
|
|
|
|
return "nlib/read/listReadItems";
|
|
}
|
|
|
|
/**
|
|
* 대출 목록을 조회한다.
|
|
*
|
|
* @param req
|
|
* @return
|
|
*/
|
|
@Secured("ROLE_USER")
|
|
@RequestMapping(value="/read/listReadItemsAjax.do")
|
|
public ResponseEntity<String> listReadItemsAjax(
|
|
HttpServletRequest request,
|
|
@RequestBody CollectionVO searchVO) {
|
|
|
|
String message = null;
|
|
String mbInfoId = getMbInfoId(request);
|
|
int totCount = 0;
|
|
|
|
if(StringUtil.isEmpty(mbInfoId)) {
|
|
message = "로그인하신 후, 이용바랍니다.";
|
|
}
|
|
|
|
if(StringUtil.isEmpty(searchVO.getReqStatusDivCd())) {
|
|
searchVO.setReqStatusDivCd("A"); // 신청/예약 기본 설정
|
|
}
|
|
|
|
//-------------------------------
|
|
// JSON변환 응답 처리
|
|
//-------------------------------
|
|
// JS-GRID 페이징 처리를 포함한 응답값 처리
|
|
// {data: [{...}],
|
|
// itemsCount: 255
|
|
// }
|
|
HashMap<String, Object> retMap = new HashMap<String, Object>();
|
|
|
|
if(StringUtil.isNotEmpty(mbInfoId)) {
|
|
|
|
// 로그인 사용자 정보 설정
|
|
searchVO.setMbInfoId(mbInfoId);
|
|
|
|
// 조회
|
|
// 대출상태구분코드("": 전체, A:신청, B:대출준비완료, C:취소, W:대출중, R0:정상반납, R1:연체반납, P:연체)
|
|
DataApiResVO resVO = readService.listReadItems(searchVO);
|
|
totCount = resVO.getRecordTotCount();
|
|
retMap.put("data" , resVO.getRecordList());
|
|
retMap.put("pageIndex" , resVO.getPageIndex());
|
|
} else {
|
|
retMap.put("pageIndex" , searchVO.getPageIndex());
|
|
retMap.put("message" , "로그인하신 후, 이용바랍니다.");
|
|
}
|
|
retMap.put("itemsCount", totCount);
|
|
|
|
PagingVO pageVO = new PagingVO();
|
|
pageVO.setPagingVO(totCount, searchVO.getPageIndex(), searchVO.getPageSize());
|
|
retMap.put("pagingPageIndex" , pageVO.getPageIndex());
|
|
retMap.put("pagingTotRecordCount", pageVO.getTotRecordCount());
|
|
retMap.put("pagingStartPage" , pageVO.getStartPage());
|
|
retMap.put("pagingEndPage" , pageVO.getEndPage());
|
|
retMap.put("pagingLastPage" , pageVO.getLastPage());
|
|
|
|
return makeResponseEntityJson(retMap);
|
|
}
|
|
|
|
@Secured("ROLE_USER")
|
|
@RequestMapping(value="/read/cancelReadItemAjax.do")
|
|
public ResponseEntity<String> cancelReadItemAjax (
|
|
HttpServletRequest request,
|
|
String csrfToken,
|
|
@RequestBody CollectionVO searchVO) {
|
|
|
|
String resultMessage = null;
|
|
String resultCode = "F";
|
|
String mbInfoId = getMbInfoId(request);
|
|
int totCount = 0;
|
|
|
|
if(StringUtil.isEmpty(mbInfoId)) {
|
|
resultMessage = "로그인하신 후, 이용바랍니다.";
|
|
}
|
|
|
|
if(!isValidCsrfToken(request, csrfToken)) {
|
|
resultMessage = "잘못된 접근입니다.";
|
|
}
|
|
|
|
if(resultMessage != null && StringUtil.isEmpty(searchVO.getMngOrgCd())) {
|
|
resultMessage = "문화원정보가 부적합합니다. 다시 요청하여 주시기 바랍니다.";
|
|
}
|
|
|
|
if(resultMessage != null && StringUtil.isEmpty(searchVO.getReqId())) {
|
|
resultMessage = "취소할 방문열람신청번호 정보가 부적합합니다. 다시 요청하여 주시기 바랍니다.";
|
|
}
|
|
|
|
if(resultMessage != null && StringUtil.isEmpty(searchVO.getMasterId())) {
|
|
resultMessage = "취소할 자료정보 정보가 부적합합니다. 다시 요청하여 주시기 바랍니다.";
|
|
}
|
|
|
|
//-------------------------------
|
|
// JSON변환 응답 처리
|
|
//-------------------------------
|
|
// JS-GRID 페이징 처리를 포함한 응답값 처리
|
|
// {data: [{...}],
|
|
// itemsCount: 255
|
|
// }
|
|
HashMap<String, Object> retMap = new HashMap<String, Object>();
|
|
|
|
if(resultMessage == null) {
|
|
|
|
// 로그인 사용자 정보 설정
|
|
searchVO.setMbInfoId(mbInfoId);
|
|
|
|
// 대출취소신청
|
|
DataApiResVO resVO = readService.cancelReadItem(searchVO);
|
|
resultCode = resVO.getResultCode();
|
|
resultMessage = resVO.getResultMessage();
|
|
}
|
|
|
|
retMap.put("resultCode" , resultCode);
|
|
retMap.put("resultMessage" , resultMessage);
|
|
|
|
return makeResponseEntityJson(retMap);
|
|
}
|
|
}
|