File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
package itn.let.cop.resve.web;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.annotation.Resource;
import org.apache.commons.lang3.ArrayUtils;
import org.json.simple.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springmodules.validation.commons.DefaultBeanValidator;
import com.ibm.icu.util.StringTokenizer;
import egovframework.rte.fdl.property.EgovPropertyService;
import egovframework.rte.fdl.security.userdetails.util.EgovUserDetailsHelper;
import egovframework.rte.psl.dataaccess.util.EgovMap;
import egovframework.rte.ptl.mvc.tags.ui.pagination.PaginationInfo;
import itn.com.cmm.ComDefaultCodeVO;
import itn.com.cmm.EgovMessageSource;
import itn.com.cmm.LoginVO;
import itn.com.cmm.service.EgovCmmUseService;
import itn.com.cmm.service.EgovFileMngService;
import itn.com.cmm.service.EgovFileMngUtil;
import itn.com.cmm.service.FileVO;
import itn.let.cop.resve.service.Resve;
import itn.let.cop.resve.service.ResveManageService;
import itn.let.cop.resve.service.ResveVO;
import itn.let.sec.ram.service.AuthorManageVO;
import itn.let.sec.ram.service.EgovAuthorManageService;
/**
* 대관신청 관리를 위한 컨트롤러 클래스
* @author
* @since 2018.11.21
* @version 1.0
* @see
*
* <pre>
* << 개정이력(Modification Information) >>
*
* 수정일 수정자 수정내용
* ------- -------- ---------------------------
* 2018.11.10 최초 생성
*
* </pre>
*/
@Controller
public class ResveManageController {
@Resource(name = "ResveManageService")
private ResveManageService resveManageService;
@Resource(name = "EgovCmmUseService")
private EgovCmmUseService cmmUseService;
@Resource(name = "propertiesService")
protected EgovPropertyService propertyService;
@Autowired
private DefaultBeanValidator beanValidator;
@Resource(name = "egovAuthorManageService")
private EgovAuthorManageService egovAuthorManageService;
@Resource(name="egovMessageSource")
EgovMessageSource egovMessageSource;
@Resource(name = "EgovFileMngUtil")
private EgovFileMngUtil fileUtil;
@Resource(name = "EgovFileMngService")
private EgovFileMngService fileMngService;
private static final Logger LOGGER = LoggerFactory.getLogger(ResveManageController.class);
/**
* 대관관리 목록을 조회한다.
*
* @param ResveVO
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/cop/resve/selectResveManageList.do")
public String selectResveManageList(@ModelAttribute("searchVO") ResveVO resveVO, ModelMap model) throws Exception {
resveVO.setPageUnit(propertyService.getInt("pageUnit"));
resveVO.setPageSize(propertyService.getInt("pageSize"));
PaginationInfo paginationInfo = new PaginationInfo();
paginationInfo.setCurrentPageNo(resveVO.getPageIndex());
paginationInfo.setRecordCountPerPage(resveVO.getPageUnit());
paginationInfo.setPageSize(resveVO.getPageSize());
resveVO.setFirstIndex(paginationInfo.getFirstRecordIndex());
resveVO.setLastIndex(paginationInfo.getLastRecordIndex());
resveVO.setRecordCountPerPage(paginationInfo.getRecordCountPerPage());
Map<String, Object> map = resveManageService.selectResveManageList(resveVO);
int totCnt = Integer.parseInt((String) map.get("resultCnt"));
paginationInfo.setTotalRecordCount(totCnt);
model.addAttribute("resultList", map.get("resultList"));
model.addAttribute("resultCnt", map.get("resultCnt"));
model.addAttribute("paginationInfo", paginationInfo);
return "cop/resve/resveManageList";
}
/**
* 신규 게시판 마스터 등록을 위한 등록페이지로 이동한다.
*
* @param boardMasterVO
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/cop/resve/addResveManage.do")
public String addResve(@ModelAttribute("searchVO") ResveVO resveVO, @ModelAttribute("resve") Resve resve,
ModelMap model, BindingResult bindingResult, RedirectAttributes redirectAttributes) throws Exception {
// 공통코드 및 권한목록 Set
setCodeNAuth(model);
return "cop/resve/resveManageRegist";
}
/**
* 신규 대관관리 정보를 등록한다.
*
* @param resveVO
* @param resve
* @param status
* @return
* @throws Exception
*/
@RequestMapping("/cop/resve/insertResveManage.do")
public String insertBBSMasterInf(final MultipartHttpServletRequest multiRequest, @ModelAttribute("searchVO") ResveVO resveVO, @ModelAttribute("resve") Resve resve, BindingResult bindingResult,
SessionStatus status, ModelMap model, RedirectAttributes redirectAttributes) throws Exception {
LoginVO user = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
beanValidator.validate(resve, bindingResult);
if (bindingResult.hasErrors()) {
// 공통코드 및 권한목록 Set
setCodeNAuth(model);
return "cop/resve/resveManageRegist";
}
// 대관신청 희망일자 가능 여부
int posbleDate = resveManageService.resvePosbleDate(resve);
if (posbleDate > 0) {
// 공통코드 및 권한목록 Set
setCodeNAuth(model);
model.addAttribute("message", "대관 희망기간일이 가능하지 않습니다.");
return "cop/resve/resveManageRegist";
}
// 파일업로드
final Map<String, MultipartFile> files = multiRequest.getFileMap();
if (!files.isEmpty()) {
String storePath = "Globals.resveFileStorePath";
long posblAtchFileSize = propertyService.getInt("posblAtchFileSize");
int posblResveThumbAtchFileNum = propertyService.getInt("posblResveThumbAtchFileNum");
int posblResveImgAtchFileNum = propertyService.getInt("posblResveImgAtchFileNum");
int posblResvePortpolioAtchFileNum = propertyService.getInt("posblResvePortpolioAtchFileNum");
final Map<String, MultipartFile> thumbFiles = new HashMap<String, MultipartFile>();
final Map<String, MultipartFile> imgFiles = new HashMap<String, MultipartFile>();
final Map<String, MultipartFile> portpolioFiles = new HashMap<String, MultipartFile>();
Set keySet = files.keySet();
Iterator<String> keyItr = keySet.iterator();
while (keyItr.hasNext()) {
String key = keyItr.next();
String fileCnd = !("").equals(key) ? key.split("_")[0] : "";
String orginFileName = files.get(key).getOriginalFilename();
if ("".equals(orginFileName)) continue;
switch (fileCnd) {
case "thumb" : thumbFiles.put(key, files.get(key)); break;
case "img" : imgFiles.put(key, files.get(key)); break;
case "portfolio" : portpolioFiles.put(key, files.get(key)) ; break;
}
}
// 기 업로드 개수
int atchFileCnt = 0;
// 파일 개수/사이즈/확장자 체크
if (!isPosblAtchFile(thumbFiles, "썸네일", model, atchFileCnt, posblResveThumbAtchFileNum, posblAtchFileSize, true)) {
model.addAttribute("resve", resve);
return "cop/resve/resveManageRegist";
}
if (!isPosblAtchFile(imgFiles, "대표이미지", model, atchFileCnt, posblResveImgAtchFileNum, posblAtchFileSize, true)) {
model.addAttribute("resve", resve);
return "cop/resve/resveManageRegist";
}
if (!isPosblAtchFile(portpolioFiles, "포트폴리오", model, atchFileCnt, posblResvePortpolioAtchFileNum, posblAtchFileSize, false)) {
model.addAttribute("resve", resve);
return "cop/resve/resveManageRegist";
}
List<FileVO> result = new ArrayList<FileVO>();
result = fileUtil.parseFileInf(thumbFiles, "RESVE_", 0, "", storePath, "");
String thumbAtchFileId = fileMngService.insertFileInfs(result);
result = fileUtil.parseFileInf(imgFiles, "RESVE_", 0, "", storePath, "");
String imgAtchFileId = fileMngService.insertFileInfs(result);
result = fileUtil.parseFileInf(portpolioFiles, "RESVE_", 0, "", storePath, "");
String portfolioAtchFileId = fileMngService.insertFileInfs(result);
resve.setThumbAtchFileId(thumbAtchFileId);
resve.setImgAtchFileId(imgAtchFileId);
resve.setPortfolioAtchFileId(portfolioAtchFileId);
}
resve.setMemberId(user.getUniqId()); // 최종수정자ID. (사용없음 참조용)
resveManageService.insertResveManage(resve);
redirectAttributes.addFlashAttribute("message", egovMessageSource.getMessage("success.common.insert"));
return "redirect:/cop/resve/selectResveManageList.do";
}
/**
* 대관관리 상세내용을 조회한다.
*
* @param searchVO
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/cop/resve/selectResveManage.do")
public String selectResveManageInf(@ModelAttribute("searchVO") ResveVO searchVO, ModelMap model, RedirectAttributes redirectAttributes) throws Exception {
ResveVO vo = resveManageService.selectResveManageInf(searchVO);
model.addAttribute("result", vo);
// 공통코드 및 권한목록 Set
setCodeNAuth(model);
return "cop/resve/resveManageUpdt";
}
/**
* 대관관리 정보를 수정한다.
*
* @param boardMasterVO
* @param boardMaster
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/cop/resve/updateResveManageInf.do")
public String updateResveManageInf(@ModelAttribute("searchVO") ResveVO resveVO, @ModelAttribute("resve") Resve resve, BindingResult bindingResult,
ModelMap model, RedirectAttributes redirectAttributes) throws Exception {
// 승인완료 선택 시 희망일자 가능여부
if (("b").equals(resve.getResState())) {
ResveVO vo = resveManageService.selectResveManageInf(resveVO);
// 대관신청 희망일자 가능 여부
int posbleDate = resveManageService.resvePosbleDate(vo);
if (posbleDate > 0) {
// 공통코드 및 권한목록 Set
setCodeNAuth(model);
model.addAttribute("message", "대관 희망기간일이 가능하지 않습니다.");
model.addAttribute("result", vo);
return "cop/resve/resveManageUpdt";
}
}
resveManageService.updateResveManageInf(resve);
redirectAttributes.addAttribute("pageIndex", resveVO.getPageIndex());
redirectAttributes.addAttribute("searchCnd", resveVO.getSearchCnd());
redirectAttributes.addAttribute("searchWrd", resveVO.getSearchWrd());
redirectAttributes.addFlashAttribute("message", egovMessageSource.getMessage("success.common.update"));
return "redirect:/cop/resve/selectResveManageList.do";
}
/**
* 대관신청 전시기간 시작일 가능 일자 조회
* @param commandMap 파라메터전달용 commandMap
* @param model 화면모델
* @throws Exception
*/
@RequestMapping(value = "/cop/resve/resveResSdateListAjax.do")
public ModelAndView resveResSdateListAjax(@RequestParam Map<String, Object> commandMap) throws Exception {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("jsonView");
String searchYyyyMm = (String) commandMap.get("searchYyyyMm");
String selectExRoom = (String) commandMap.get("selectExRoom");
Resve vo = new Resve();
vo.setSelectExRoom(selectExRoom);
Calendar cal = Calendar.getInstance();
int year = Integer.parseInt(searchYyyyMm.substring(0, 4));
int month = Integer.parseInt(searchYyyyMm.substring(4, 6));
cal.set(year, month-1, 1);
int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String date = sdf.format(cal.getTime());
vo.setSearchDate(date);
date = date.substring(0, 6) + (maxDay<10 ? "0"+maxDay : maxDay );
vo.setSearchDate1(date);
List<EgovMap> result = resveManageService.resveResSdateList(vo);
modelAndView.addObject("result", result);
return modelAndView;
}
/**
* 공통코드 및 권한목록 Set
* @param model
* @throws Exception
*/
private void setCodeNAuth(ModelMap model) throws Exception {
// 승인상태
ComDefaultCodeVO comDefaultCodeVO = new ComDefaultCodeVO();
comDefaultCodeVO.setCodeId("ITN006");
List<?> codeResult = cmmUseService.selectCmmCodeDetail(comDefaultCodeVO);
model.addAttribute("resStateList", codeResult);
// 신처자 구분
comDefaultCodeVO.setCodeId("ITN007");
codeResult = cmmUseService.selectCmmCodeDetail(comDefaultCodeVO);
model.addAttribute("userTypeList", codeResult);
AuthorManageVO authorManageVO = new AuthorManageVO();
authorManageVO.setAuthorManageList(egovAuthorManageService.selectAuthorAllList(authorManageVO));
model.addAttribute("authorList", authorManageVO.getAuthorManageList());
// 파일개수/사이즈
model.addAttribute("maxThumbFileNum", propertyService.getInt("posblResveThumbAtchFileNum"));
model.addAttribute("maxImgFileNum", propertyService.getInt("posblResveImgAtchFileNum"));
model.addAttribute("maxPortpolioFileNum", propertyService.getInt("posblResvePortpolioAtchFileNum"));
model.addAttribute("maxFileSize", propertyService.getInt("posblAtchFileSize"));
}
/**
* 선택된 대관신청정보를 삭제한다.
* @param applyNums String
* @param resveVO ResveVO
* @return String
* @exception Exception
*/
@RequestMapping(value = "/cop/resve/deleteResveManages.do")
public String deleteBBSMasterInfs(@RequestParam("applyNums") String applyNums, @ModelAttribute("ResveVO") ResveVO resveVO, RedirectAttributes redirectAttributes)
throws Exception {
String[] strApplyNums = applyNums.split(";");
for (int i = 0; i < strApplyNums.length; i++) {
String[] strApplyNumNAtchFileId = strApplyNums[i].split("\\|");
resveVO.setApplyNum(Integer.parseInt(strApplyNumNAtchFileId[0]));
if (!("-").equals(strApplyNumNAtchFileId[1])) resveVO.setThumbAtchFileId(strApplyNumNAtchFileId[1]);
if (!("-").equals(strApplyNumNAtchFileId[2])) resveVO.setImgAtchFileId(strApplyNumNAtchFileId[2]);
if (!("-").equals(strApplyNumNAtchFileId[3])) resveVO.setPortfolioAtchFileId(strApplyNumNAtchFileId[3]);
resveManageService.deleteResveManage(resveVO);
}
resveVO.setPageIndex(1);
redirectAttributes.addAttribute("pageIndex", resveVO.getPageIndex());
redirectAttributes.addAttribute("searchCnd", resveVO.getSearchCnd());
redirectAttributes.addAttribute("searchWrd", resveVO.getSearchWrd());
redirectAttributes.addFlashAttribute("message", egovMessageSource.getMessage("success.common.delete"));
return "redirect:/cop/resve/selectResveManageList.do";
}
/**
* 첨부파일 개수, 사이즈, 확장자 체크
* @param fileList 파일리스트
* @param name 파일 항목명
* @param model
* @param atchFileCnt 기업로드된 파일 수
* @param posblAtchFileCnt 업로드 가능 파일 수
* @param posblAtchFileSize 업로드 가능 파일 사이즈
* @param isImg 이미지 여부
* @return boolean
* @throws Exception
*/
private boolean isPosblAtchFile(Map<String, MultipartFile> fileList, String name, ModelMap model,
int atchFileCnt, int posblAtchFileCnt, long posblAtchFileSize, boolean isImg) throws Exception {
String flashMessage = "";
boolean posblAtchFileFlag = true;
boolean posblAtchFileSizeFlag = true;
boolean posblAtchFileExtFlag = true;
Iterator<Entry<String, MultipartFile>> itr = fileList.entrySet().iterator();
MultipartFile file;
while (itr.hasNext()) {
Entry<String, MultipartFile> entry = itr.next();
file = entry.getValue();
long fileMg = file.getSize();
String orginFileName = file.getOriginalFilename();
int index = orginFileName.lastIndexOf(".");
String fileExt = orginFileName.substring(index + 1);
if (fileMg > posblAtchFileSize) posblAtchFileSizeFlag = false;
if (isImg) {
String[] imgExts = {"gif", "jpg", "bmp", "jpeg", "png"};
if (ArrayUtils.indexOf(imgExts, fileExt.toLowerCase()) == -1) posblAtchFileExtFlag = false;
}
}
if (!posblAtchFileExtFlag) {
flashMessage += name + ": 이미지 형식의 확장자만 업로드 가능합니다." + "\\n";
posblAtchFileFlag = false;
}
if(!posblAtchFileSizeFlag) {
flashMessage += name + ": 파일사이즈가 초과되었습니다. 최대크기 " + posblAtchFileSize + "mb" + "\\n";
posblAtchFileFlag = false;
}
if ((fileList.size()+atchFileCnt) > posblAtchFileCnt) {
flashMessage += name + ": 파일 개수가 초과되었습니다. 최대개수 " + posblAtchFileCnt + "개" + "\\n";
posblAtchFileFlag = false;
}
if (!posblAtchFileFlag) model.addAttribute("message", flashMessage);
return posblAtchFileFlag;
}
/**
* ************************************ 사용자 ************************************
*/
/**
* (사용자)대관현황 목록 데이터를 조회한다. (달력)
*
* @param ResveVO
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/web/cop/resve/selectResveListAjax.do")
public ModelAndView selectResveListAjaxWeb(@ModelAttribute("searchVO") ResveVO resveVO, ModelMap model, @RequestParam Map<String, Object> commandMap) throws Exception {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("jsonView");
Calendar cal = Calendar.getInstance();
String searchYear = (String) commandMap.get("searchYear");
String searchMonth = (String) commandMap.get("searchMonth");
LOGGER.debug("resveList(web) input searchYear: " + searchYear + " searchMonth: " + searchMonth);
if (searchYear == null || searchMonth == null
|| ("").equals(searchYear) || ("").equals(searchMonth)) {
int iYear = cal.get(java.util.Calendar.YEAR);
int iMonth = cal.get(java.util.Calendar.MONTH);
searchYear = Integer.toString(iYear);
searchMonth = (iMonth+1) < 10 ? "0" + Integer.toString(iMonth+1) : Integer.toString(iMonth+1);
}
resveVO.setSearchDate(searchYear + searchMonth + "01");
// 년월해당 전시관 내역 조회
List<ResveVO> result = resveManageService.selectResveManageListWeb(resveVO);
// 조회 결과 파싱
JSONObject resultList = new JSONObject();
resultList.put("searchYear", searchYear);
resultList.put("searchMonth", searchMonth);
for (ResveVO vo : result) {
String[] exRoomArr = new String[5];
exRoomArr[0] = vo.getExRoom1();
exRoomArr[1] = vo.getExRoom2();
exRoomArr[2] = vo.getExRoom3();
exRoomArr[3] = vo.getExRoom5Am();
exRoomArr[4] = vo.getExRoom5Pm();
JSONObject resveJson = new JSONObject();
for (int i=0; i < exRoomArr.length; i++) {
StringTokenizer strTk = new StringTokenizer(exRoomArr[i], ",");
String tmpExRoom = strTk.hasMoreTokens() ? strTk.nextToken() : "";
String[] tmpArr = tmpExRoom.split("\\|");
JSONObject infoJson = new JSONObject();
if (tmpArr.length == 3) {
infoJson.put("applyNum", tmpArr[0]);
infoJson.put("exName", tmpArr[1]);
infoJson.put("authorName", tmpArr[2]);
} else {
infoJson.put("applyNum", "null");
}
infoJson.put("idx", i);
String exRoomIdx = Integer.toString(i+1);
if (("4").equals(exRoomIdx)) exRoomIdx = "5Am";
else if (("5").equals(exRoomIdx)) exRoomIdx = "5Pm";
resveJson.put("exRoom"+exRoomIdx, infoJson);
}
// LOGGER.debug(vo.getStrDate());
resultList.put(vo.getStrDate(), resveJson);
}
LOGGER.debug("resveList(web) search searchYear: " + searchYear + " searchMonth: " + searchMonth);
// model.addAttribute("resultList", result);
modelAndView.addObject("resultList", resultList);
return modelAndView;
}
/**
* (사용자)대관현황 목록 화면을 조회한다. (달력)
*
* @param searchVO
* @param commandMap
* @param indvdlSchdulManageVO
* @param model
* @return "/cop/smt/sim/EgovIndvdlSchdulManageMonthList"
* @throws Exception
*/
@RequestMapping(value="/web/cop/resve/selectResveList.do")
public String selectResveListWeb(@ModelAttribute("searchVO") ResveVO resveVO, ModelMap model)
throws Exception {
//if (!checkAuthority(model)) return "cmm/uat/uia/EgovLoginUsr"; // server-side 권한 확인
//일정구분 검색 유지
// model.addAttribute("searchKeyword", commandMap.get("searchKeyword") == null ? "" : (String)commandMap.get("searchKeyword"));
// model.addAttribute("searchCondition", commandMap.get("searchCondition") == null ? "" : (String)commandMap.get("searchCondition"));
/*java.util.Calendar cal = java.util.Calendar.getInstance();
String sYear = resveVO.getSearchYear();
String sMonth = resveVO.getSearchMonth();
sYear = "2018";
sMonth = "11";
int iYear = cal.get(java.util.Calendar.YEAR);
int iMonth = cal.get(java.util.Calendar.MONTH);
//int iDate = cal.get(java.util.Calendar.DATE);
//검색 설정
String sSearchDate = "";
if(("").equals(sYear) || ("").equals(sMonth)){
sSearchDate += Integer.toString(iYear);
sSearchDate += Integer.toString(iMonth+1).length() == 1 ? "0" + Integer.toString(iMonth+1) : Integer.toString(iMonth+1);
}else{
iYear = Integer.parseInt(sYear);
iMonth = Integer.parseInt(sMonth);
sSearchDate += sYear;
sSearchDate += Integer.toString(iMonth+1).length() == 1 ? "0" + Integer.toString(iMonth+1) :Integer.toString(iMonth+1);
}
model.addAttribute("schdulSe", null);
model.addAttribute("searchMonth", sSearchDate);
model.addAttribute("searchMode", "MONTH");
model.addAttribute("resultList", null);*/
return "/web/cop/resve/resveList";
}
}