itsm_ysm/src/main/java/nlib/col/web/RentController.java
2021-11-23 08:11:25 +09:00

290 lines
9.6 KiB
Java

package nlib.col.web;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.core.Authentication;
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 org.springframework.web.bind.annotation.RequestParam;
import nlib.cmm.NlibCommonController;
import nlib.cmm.service.CodeService;
import nlib.cmm.service.NlibProperty;
import nlib.cmm.service.PagingVO;
import nlib.col.service.CollectionService;
import nlib.col.service.CollectionVO;
import nlib.col.service.RentService;
import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.restful.service.DataApiVO;
import nlib.util.StringUtil;
/**
* <pre>
* @Class Name : RentController.java
*
* @Description : 대출 Controller
*
*
* @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
*
* </pre>
*
* @ ------------ -------- ---------------------------
* @ 수정일 수정자 수정내용
* @ ------------ -------- ---------------------------
* @ 2021. 7. 21. JSYOO 최초 생성
* @ 2021.10. 14. KNKIM 대출목록 API방식 변경 및 화면설계서 적용 개발
*
*
* @author 이씨플라자 * DIGITALSHIP JSYOO
* @since 2021. 7. 21.
* @version 1.0
*
*/
@Controller
public class RentController extends NlibCommonController
{
private static final Logger log = LoggerFactory.getLogger(RentController.class);
static final String DEFUALT_PAGE_SIZE = NlibProperty.getProperty("list.paging.page.size");
@Resource(name = "rentService")
private RentService rentService;
@Resource(name = "collectionService")
private CollectionService collectionService;
@Resource(name = "codeService")
private CodeService codeService;
/**
* 대출 목록 화면을 호출한다.
*
* @param request
* @param searchVO
* @param model
* @param message
* @return
* @throws Exception
*/
@Secured("ROLE_USER")
@RequestMapping("/rent/listRentItems.do")
public String listRentItems(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/rent/listRentItems";
}
// 대출자료 문화원 목록 조회
List<HashMap<String, String>> rentMngOrgList = rentService.listRentMngOrg(mbInfoId);
model.addAttribute("rentMngOrgList" , rentMngOrgList);
model.addAttribute("bookLtRvStatusCd", StringUtil.getString(searchVO.getBookLtRvStatusCd(), "A"));
model.addAttribute("pageSize" , searchVO.getPageSize());
model.addAttribute("pageIndex" , searchVO.getPageIndex());
model.addAttribute("message" , message);
return "nlib/rent/listRentItems";
}
/**
* 대출 목록을 조회한다.
*
* @param req
* @return
*/
@Secured("ROLE_USER")
@RequestMapping(value="/rent/listRentItemsAjax.do")
public ResponseEntity<String> listRentItemsAjax(
HttpServletRequest request,
@RequestBody CollectionVO searchVO) {
String message = null;
String mbInfoId = getMbInfoId(request);
int totCount = 0;
if(StringUtil.isEmpty(mbInfoId)) {
message = "로그인하신 후, 이용바랍니다.";
}
if(StringUtil.isEmpty(searchVO.getBookLtRvStatusCd())) {
searchVO.setBookLtRvStatusCd("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 = rentService.listRentItems(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="/rent/cancelRentItemAjax.do")
public ResponseEntity<String> cancelRentItemAjax(
HttpServletRequest request,
@RequestBody CollectionVO searchVO) {
String resultMessage = null;
String resultCode = "F";
String mbInfoId = getMbInfoId(request);
int totCount = 0;
if(StringUtil.isEmpty(mbInfoId)) {
resultMessage = "로그인하신 후, 이용바랍니다.";
}
if(StringUtil.isEmpty(searchVO.getMngOrgCd())) {
resultMessage = "문화원정보가 부적합합니다. 다시 요청하여 주시기 바랍니다.";
}
if(StringUtil.isEmpty(searchVO.getRsrvId())) {
resultMessage = "취소할 대출(예약)선청번호 정보가 부적합합니다. 다시 요청하여 주시기 바랍니다.";
}
//-------------------------------
// JSON변환 응답 처리
//-------------------------------
// JS-GRID 페이징 처리를 포함한 응답값 처리
// {data: [{...}],
// itemsCount: 255
// }
HashMap<String, Object> retMap = new HashMap<String, Object>();
if(resultMessage == null) {
// 로그인 사용자 정보 설정
searchVO.setMbInfoId(mbInfoId);
// 대출취소신청
DataApiResVO resVO = rentService.cancelRentItem(searchVO);
resultCode = resVO.getResultCode();
resultMessage = resVO.getResultMessage();
}
retMap.put("resultCode" , resultCode);
retMap.put("resultMessage" , resultMessage);
return makeResponseEntityJson(retMap);
}
@Secured("ROLE_USER")
@RequestMapping(value={"/rent/confirmRentFromCart.do", "/rent/confirmRent.do"})
public String confirmRent(HttpServletRequest request, CollectionVO rentVO, ModelMap model) throws Exception {
boolean fromCart = request.getServletPath().contains("Cart.do");
String mbInfoId = getMbInfoId(request);
if(StringUtil.isEmpty(mbInfoId)) {
model.addAttribute("message", "로그인 후, 이용해 주시기 바랍니다.");
return "nlib/rent/confirmRent";
}
if(rentVO == null || StringUtil.isEmpty(rentVO.getSelItems())) {
model.addAttribute("message", "대출(예약)신청할 정보가 없습니다.");
return "nlib/rent/confirmRent";
}
String selItems = rentVO.getSelItems();
List<CollectionVO> list = collectionService.makeInfoListOfCollectionVO(selItems, mbInfoId);
if(StringUtil.isEmpty(rentVO.getMngOrgNm()) && list != null && list.size() > 0) {
rentVO.setMngOrgCd(list.get(0).getMngOrgCd());
rentVO.setMngOrgNm(list.get(0).getMngOrgNm());
}
model.addAttribute("rentVO", rentVO);
model.addAttribute("list", list);
if(fromCart) model.addAttribute("fromCart", fromCart ? "Y" : "N");
return "nlib/rent/confirmRent";
}
@Secured("ROLE_USER")
@RequestMapping(value={"/rent/insertRentItemsFromCart.do", "/rent/insertRentItems.do"})
public String insertRentItems(HttpServletRequest request, CollectionVO rentVO, ModelMap model) throws Exception {
boolean fromCart = request.getServletPath().contains("Cart.do");
String retJsp = "nlib/rent/insertRentItems";
String mbInfoId = getMbInfoId(request);
if(StringUtil.isEmpty(mbInfoId)) {
model.addAttribute("message", "로그인 후, 이용해 주시기 바랍니다.");
return retJsp;
}
if(rentVO == null || StringUtil.isEmpty(rentVO.getSelItems())) {
model.addAttribute("message", "대출(예약)신청할 정보가 없습니다.");
return retJsp;
}
if(StringUtil.isEmpty(rentVO.getMngOrgCd())) {
model.addAttribute("message", "관리문화원 정보가 없습니다.");
return retJsp;
}
String selItems = rentVO.getSelItems();
List<CollectionVO> list = collectionService.makeListOfCollectionVO(selItems);
list = rentService.insertRentItems(list, mbInfoId, rentVO.getMngOrgCd(), fromCart);
list = collectionService.setDetailInfoForList(list, mbInfoId);
model.addAttribute("rentVO", rentVO);
model.addAttribute("list", list);
if(fromCart) model.addAttribute("fromCart", fromCart ? "Y" : "N");
return retJsp;
}
}