package itn.let.mjo.msgCustom.web;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
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.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.ibm.icu.text.DecimalFormat;

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.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.com.utl.fcc.service.EgovStringUtil;
import itn.let.lett.service.HashConfVO;
import itn.let.lett.service.LetterService;
import itn.let.mjo.mjocommon.MjonCommon;
import itn.let.mjo.msg.service.MjonMsgVO;
import itn.let.mjo.msgCustom.service.MjonMsgCustomService;
import itn.let.mjo.msgCustom.service.MjonMsgCustomVO;
import itn.let.mjo.msgdata.service.MjonMsgDataService;
import itn.let.sym.ccm.cde.service.CateCode;
import itn.let.sym.site.service.EgovSiteManagerService;
import itn.let.sym.site.service.JoinSettingVO;
import itn.let.uss.umt.service.MberManageVO;
import itn.let.utl.user.service.MjonNoticeSendUtil;

@Controller
public class MjonMsgCustomWebController {

	@Resource(name = "mjonMsgCustomService")
	private MjonMsgCustomService mjonMsgCustomService;
	
	@Resource(name = "MjonMsgDataService")
	private MjonMsgDataService mjonMsgDataService;
	
	@Resource(name = "LetterService")
	private LetterService letterService;
	
	@Resource(name = "EgovCmmUseService")
	private EgovCmmUseService cmmUseService;
	
	@Resource(name = "EgovFileMngUtil")
	private EgovFileMngUtil fileUtil;
	
	@Resource(name = "EgovFileMngService")
	private EgovFileMngService fileMngService;
	
	/** 첨부파일 저장경로 */
	@Value("#{globalSettings['Globals.file.saveDir']}")
	private String fileSaveDir;
	
    /** 알림전송 Util */
    @Resource(name = "mjonNoticeSendUtil")
    private MjonNoticeSendUtil mjonNoticeSendUtil;	
	
	@Resource(name="MjonCommon")
	private MjonCommon mjonCommon;
    
	/** 사이트 설정 */ 
	@Resource(name = "egovSiteManagerService")
	EgovSiteManagerService egovSiteManagerService;
	
	/** 사용자 맞춤제작 화면*/
	@RequestMapping(value= {"/web/mjon/custom/selectMsgCustomView.do"})
	public String selectMsgCustomView(@ModelAttribute("searchVO") MjonMsgCustomVO mjonMsgCustomVO
			, HttpServletRequest request
			, ModelMap model) throws Exception{
		
		String url = request.getHeader("REFERER");
		if(url != null) {
			if(url.contains("web/mjon/msgcampain/selectMsgDataView.do")) {
				model.addAttribute("msgcampain", request.getParameter("pageType"));
			}
		}
			
		//로그인 권한정보 불러오기
		LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
				
		// 맞춤문자 설정
		mjonMsgCustomVO.setLetterType("C");
		String categoryType = "C";
		
		// 문자 카테고리 리스트 불러오기
		List<CateCode> cateConfList = letterService.selectCateConfWithList(categoryType);
		model.addAttribute("cateCodeList", cateConfList);	
		
		// 문자 해쉬태그 리스트 불러오기
		String msgType = "C";
		List<HashConfVO> hashTagList = letterService.selectHashTagWithList(msgType);
		model.addAttribute("hashTagList", hashTagList);
		model.addAttribute("mjonMsgCustomVO", mjonMsgCustomVO);
		model.addAttribute("loginVO", loginVO);
		
		for(int i=0 ; i < cateConfList.size(); i++) {
			if("선거".equals(cateConfList.get(i).getCateNm())) {
				mjonMsgCustomVO.setCategoryCode(cateConfList.get(i).getCateCode());
			}
		}
		
    	//1.시스템 기본 단가 정보 불러오기
    	JoinSettingVO sysJoinSetVO = mjonMsgDataService.selectJoinSettingInfo();
    	String customSamplePrice = "0";		// 문자온 샘플 수정(글자, 색상, 폰트 등)
    	String customEditPrice = "0";		// 이미지 편집(첨부이미지 1장)
    	String customEdit3Price = "0";		// 이미지 편집(첨부이미지 3장이하)
    	String customTextPrice = "0";		// 텍스트 단순수정
    	
    	DecimalFormat df = new DecimalFormat("###,###");
    	customSamplePrice = df.format(sysJoinSetVO.getCustomSamplePrice());
    	customEditPrice = df.format(sysJoinSetVO.getCustomEditPrice());
    	customEdit3Price = df.format(sysJoinSetVO.getCustomEdit3Price());
    	customTextPrice = df.format(sysJoinSetVO.getCustomTextPrice());
    	
    	model.addAttribute("customSamplePrice", customSamplePrice);
    	model.addAttribute("customEditPrice", customEditPrice);
    	model.addAttribute("customEdit3Price", customEdit3Price);
    	model.addAttribute("customTextPrice", customTextPrice);
		
		return "/web/custom/MsgCustomView";
	}
	
	/** 사용자 맞춤제작 샘플 이미지 리스트*/
	@RequestMapping(value= {"/web/mjon/custom/selectMsgCustomSampleListAjax.do"})
	public String selectMsgCustomSampleListAjax(@ModelAttribute("searchVO") MjonMsgCustomVO mjonMsgCustomVO
			, ModelMap model) throws Exception{
		
		//그림 문자 리스트 불러오기
		//LetterVO letterVO = new LetterVO();
		if(mjonMsgCustomVO.getPageUnit() != 10) {
			mjonMsgCustomVO.setPageUnit(mjonMsgCustomVO.getPageUnit());
		}
		
		if ("best".equals(mjonMsgCustomVO.getCategoryCode())) {
			mjonMsgCustomVO.setBestCategory("Y");
			mjonMsgCustomVO.setCategoryCode("");
			
		}
		

		/** pageing */
		PaginationInfo paginationInfo = new PaginationInfo();
		paginationInfo.setCurrentPageNo(mjonMsgCustomVO.getPageIndex());
		paginationInfo.setRecordCountPerPage(mjonMsgCustomVO.getPageUnit());
		paginationInfo.setPageSize(mjonMsgCustomVO.getPageSize());

		mjonMsgCustomVO.setFirstIndex(paginationInfo.getFirstRecordIndex());
		mjonMsgCustomVO.setLastIndex(paginationInfo.getLastRecordIndex());
		mjonMsgCustomVO.setRecordCountPerPage(paginationInfo.getRecordCountPerPage());
		
		// 문자 종류 정보가 없으면 단문문자로 셋팅
		mjonMsgCustomVO.setLetterType("C");
		
		// 그림 문자 리스트
		List<?> resultCustomList = mjonMsgDataService.selectPhotoLetterList(mjonMsgCustomVO);
		model.addAttribute("resultCustomList", resultCustomList);
		paginationInfo.setTotalRecordCount( resultCustomList.size()> 0 ? ((Long)((EgovMap)resultCustomList.get(0)).get("totCnt")).intValue() : 0);
		model.addAttribute("paginationInfo", paginationInfo);
		model.addAttribute("mjonMsgCustomVO", mjonMsgCustomVO);
		
		return "/web/custom/MsgCustomListAjax";
	}
	
	/** 사용자 맞춤제작 내보관함 리스트*/
	@RequestMapping(value= {"/web/mjon/custom/selectMsgMyCustomListAjax.do"})
	public String selectMsgMyCustomListAjax(@ModelAttribute("searchVO") MjonMsgCustomVO mjonMsgCustomVO
			, RedirectAttributes redirectAttributes
			, ModelMap model) throws Exception{
		
		LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
		String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());

		if(userId == "") {
			redirectAttributes.addFlashAttribute("message", "맞춤제작 내보관함 서비스는 로그인 후 이용 가능합니다.");
			return "redirect:/web/user/login/login.do";
		}
		
		if(mjonMsgCustomVO.getPageUnit() != 10) {
			mjonMsgCustomVO.setPageUnit(mjonMsgCustomVO.getPageUnit());
		}

		/** pageing */
		PaginationInfo paginationInfo = new PaginationInfo();
		paginationInfo.setCurrentPageNo(mjonMsgCustomVO.getPageIndex());
		paginationInfo.setRecordCountPerPage(mjonMsgCustomVO.getPageUnit());
		paginationInfo.setPageSize(mjonMsgCustomVO.getPageSize());

		mjonMsgCustomVO.setFirstIndex(paginationInfo.getFirstRecordIndex());
		mjonMsgCustomVO.setLastIndex(paginationInfo.getLastRecordIndex());
		mjonMsgCustomVO.setRecordCountPerPage(paginationInfo.getRecordCountPerPage());
		
		// 문자 종류 정보가 없으면 단문문자로 셋팅
		mjonMsgCustomVO.setLetterType("C");
		
		// 내 보관함 이미지 목록 조회
		mjonMsgCustomVO.setUserId(userId);
		List<MjonMsgCustomVO> resultCustomImgList = mjonMsgCustomService.selectMjonMsgMyCustomImgList(mjonMsgCustomVO);
		
		model.addAttribute("resultCustomList", resultCustomImgList);
		paginationInfo.setTotalRecordCount( resultCustomImgList.size()> 0 ? resultCustomImgList.get(0).getTotCnt() : 0);
		model.addAttribute("paginationInfo", paginationInfo);
		model.addAttribute("mjonMsgCustomVO", mjonMsgCustomVO);
		
		return "/web/custom/MsgMyCustomListAjax";
	}
	
	/** 사용자 맞춤제작 내보관함 삭제 - LETTNFILEDETAIL 테이블 FILE_DELETE_YN 컬럼 업데이트*/
	@RequestMapping(value= {"/web/mjon/custom/deleteMsgMyCustomAjax.do"})
	public ModelAndView deleteMsgMyCustomAjax(@RequestParam("chk") String[] chk, @ModelAttribute("searchVO") MjonMsgCustomVO mjonMsgCustomVO
			, ModelMap model) throws Exception{
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("jsonView");
		
		//최종수정 ID - 로그인 ID
		LoginVO user = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
		mjonMsgCustomVO.setLastUpdusrId(user.getId());
		
		try {
			for(String target : chk) {
				mjonMsgCustomVO.setAttachFileId(target.split("\\|")[0]);
				mjonMsgCustomVO.setFileSn(target.split("\\|")[1]);
				mjonMsgCustomService.deleteMsgMyCustomAjax(mjonMsgCustomVO);
			}
			modelAndView.addObject("result", "success");
		}catch (Exception e) {
			modelAndView.addObject("message", "다시 시도 부탁드립니다.");
			modelAndView.addObject("result", "fail");
		}
		
		return modelAndView;
	}
	
	/** 사용자 맞춤제작 팝업*/
	@RequestMapping(value= {"/web/mjon/custom/selectMsgCustomPopupAjax.do"})
	public String selectMsgCustomPopupAjax(@ModelAttribute("searchVO") MjonMsgCustomVO mjonMsgCustomVO
			, ModelMap model) throws Exception{
		
		//로그인 권한정보 불러오기
		LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
		String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
		String author = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getAuthority());
		
		if(!userId.equals("") && !author.equals("ROLE_ADMIN")) {
			//2.사용자 개인 단가 정보 불러오기
			MberManageVO mberManageVO = new MberManageVO();
			mberManageVO = mjonMsgDataService.selectMberManageInfo(userId);
			double money = mberManageVO.getUserMoney();
			BigDecimal userMoney = new BigDecimal(money).setScale(0, RoundingMode.HALF_DOWN);
			model.addAttribute("userMoney", userMoney);
		}
		
		String categoryType = "C";
		// 문자 카테고리 리스트 불러오기
		List<CateCode> cateConfList = letterService.selectCateConfWithList(categoryType);
		model.addAttribute("cateConfList", cateConfList);	
		
		ComDefaultCodeVO comDefaultCodeVO = new ComDefaultCodeVO();
		//제작형태 코드 조회
		comDefaultCodeVO.setCodeId("ITN030");
		List<?> codeResult = cmmUseService.selectCmmCodeDetail(comDefaultCodeVO);
		model.addAttribute("codeResult", codeResult);
		
		return "/web/custom/MsgCustomPopupAjax";
	}
	
	/** 사용자 맞춤제작 팝업 이미지 리스트*/
	@RequestMapping(value= {"/web/mjon/custom/selectCustomPopupImgListAjax.do"})
	public ModelAndView selectgCustomPopupImgListAjax(@ModelAttribute("searchVO") MjonMsgCustomVO mjonMsgCustomVO
			, ModelMap model) throws Exception{
		
		ModelAndView modelAndView = new ModelAndView(); 
		modelAndView.setViewName("jsonView");
		
		if ("best".equals(mjonMsgCustomVO.getCategoryCode())) {
			mjonMsgCustomVO.setBestCategory("Y");
			mjonMsgCustomVO.setCategoryCode("");
			
		}
		
		// 샘플그림 리스트 조회
		List<?> resultCustomList = mjonMsgDataService.selectCustomPopupImgList(mjonMsgCustomVO);
		model.addAttribute("resultCustomList", resultCustomList);
		modelAndView.addObject("status", "success");
		
		return modelAndView;
	}
	
	/** 첨부파일 포함하여 맞춤제작요청  등록*/
	@RequestMapping(value = {"/web/mjon/custom/insertCustomImgInfoAjax.do"})
	public ModelAndView insertCustomImgInfoAjax(final MultipartHttpServletRequest multiRequest
			, MjonMsgCustomVO mjonMsgCustomVO
			, HttpServletRequest request) throws Exception {
		
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("jsonView");
		
		LoginVO loginVO = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
		String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
		
		MjonMsgVO mjonMsgVO = new MjonMsgVO();
		mjonMsgVO.setUserId(userId); // 조회 아이디 등록
		
		
		String userMoney = mjonMsgDataService.selectBeforeCashData(mjonMsgVO); // 현재 보유금액 조회
		BigDecimal befCash = new BigDecimal(userMoney).setScale(0, RoundingMode.HALF_EVEN); // 현재 보유금액 변환
		BigDecimal totMsgPrice = new BigDecimal(mjonMsgCustomVO.getCustomAmount()).setScale(0, RoundingMode.HALF_EVEN); // 맞춤문자 결제 예상 금액
		
		// befCash(현재 보유금액) 값이 totMsgPrice(맞춤문자전송 금액) 보다 많으면 문자 전송
		//if(befCash.compareTo(totMsgPrice) < 0 || befCash.compareTo(totMsgPrice) == 0) {
		if(befCash.compareTo(totMsgPrice) < 0) {
			modelAndView.addObject("result", "notMoney");
			return modelAndView;
		}
		
		// 맞춤문자 첨부 이미지  업로드
		String customSampleImg = "";
		String customSampleImgFileSn = "";
		/*if(!mjonMsgCustomVO.getTempImg1().equals("")) {
			customSampleImg = mjonMsgCustomVO.getTempImg1();
			customSampleImgFileSn= mjonMsgCustomVO.getTempImg1FileSn();
		}
		if(!mjonMsgCustomVO.getTempImg2().equals("")) {
			
			if(customSampleImg != "" ) {
				customSampleImg += "/"+mjonMsgCustomVO.getTempImg2();
				customSampleImgFileSn += "/"+mjonMsgCustomVO.getTempImg2FileSn();
			}else {
				customSampleImg += mjonMsgCustomVO.getTempImg2();
				customSampleImgFileSn += "/"+mjonMsgCustomVO.getTempImg2FileSn();
			}
		}
		if(!mjonMsgCustomVO.getTempImg3().equals("")) {
			
			if(customSampleImg != "" ) {
				customSampleImg += "/"+mjonMsgCustomVO.getTempImg3();
				customSampleImgFileSn += "/"+mjonMsgCustomVO.getTempImg3FileSn();
			}else {
				customSampleImg += mjonMsgCustomVO.getTempImg3();
				customSampleImgFileSn += "/"+mjonMsgCustomVO.getTempImg3FileSn();
			}
		}*/
		
		// 첨부파일 ID 생성 및 구분자 등록 
		String atchFileId = "";
		final Map<String, MultipartFile> files = multiRequest.getFileMap();
		if (!files.isEmpty()) {
			
			String imagePath = "";
			Date now = new Date();
			SimpleDateFormat formatDate = new SimpleDateFormat("yyyyMMdd");
			String fdlDate = formatDate.format(now);
			
			//로컬 과 개발서버의 이미지 저장 경로 분기처리
			if(request.getServerName().equals("localhost")) {
				imagePath = fileSaveDir+"src/main/webapp/MMS/" + fdlDate;
			}else{
				/*imagePath = "/usr/local/tomcat_mjon/webapps/mjon/MMS/" + fdlDate;*/
				imagePath = fileSaveDir+"/file/MMS/" + fdlDate;
			}
			
			List<FileVO> result = fileUtil.parseImageFileInf(files, "CUSTOM_", 0, "", imagePath, "");
			atchFileId = fileMngService.insertFileInfs(result);
			
			for(int i=0; i < result.size(); i++) {
				if(customSampleImgFileSn != "" ) {
//					customSampleImg += "/"+atchFileId;
					customSampleImgFileSn += "/"+i;
				}else {
//					customSampleImg += atchFileId;
					customSampleImgFileSn += i;
				}
			}
		}
		
		mjonMsgCustomVO.setCustomUploadImg(atchFileId);
		mjonMsgCustomVO.setCustomUploadImgFileSn(customSampleImgFileSn);
		mjonMsgCustomVO.setUserId(userId);
		mjonMsgCustomVO.setFrstRegisterId(userId);
		mjonMsgCustomVO.setLastUpdusrId(userId);
		mjonMsgCustomService.insertMjonMsgCustomInfo(mjonMsgCustomVO);
		
		// 법인폰 알람여부 체크
		JoinSettingVO joinSettingVO = new JoinSettingVO();
		joinSettingVO = egovSiteManagerService.selectAdminNotiDetail();
		// 이메일 체크
		if (joinSettingVO != null && joinSettingVO.getEmailNoti().equals("Y")) {
			String emailTitle = "문자관리 > 문자맞춤제작 요청";
			// CS관리자 이메일 알림전송
			mjonNoticeSendUtil.csAdminEmailNoticeSend(loginVO.getName(), loginVO.getId(), emailTitle);					
		}		
		
		// SLACK 체크
		if (joinSettingVO != null && joinSettingVO.getSlackNoti().equals("Y")) {		
			// Slack 메시지 발송(단순본문)
			String msg = "[문자온] 문자맞춤제작 요청 - " + loginVO.getName() +"("+ loginVO.getId() + ")";
			mjonCommon.sendSimpleSlackMsg(msg);
		}
		
		modelAndView.addObject("result", "success");
		return modelAndView;
	}
	
	/** 첨부파일 없이 맞춤제작요청 등록*/
	@RequestMapping(value = {"/web/mjon/custom/insertCustomImgInfoNoFileAjax.do"})
	public ModelAndView insertCustomImgInfoNoFileAjax( MjonMsgCustomVO mjonMsgCustomVO
			, HttpServletRequest request) throws Exception {
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("jsonView");
		
		LoginVO loginVO = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
		String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
		
		MjonMsgVO mjonMsgVO = new MjonMsgVO();
		mjonMsgVO.setUserId(userId); // 조회 아이디 등록
		
		
		String userMoney = mjonMsgDataService.selectBeforeCashData(mjonMsgVO); // 현재 보유금액 조회
		BigDecimal befCash = new BigDecimal(userMoney).setScale(0, RoundingMode.HALF_EVEN); // 현재 보유금액 변환
		BigDecimal totMsgPrice = new BigDecimal(mjonMsgCustomVO.getCustomAmount()).setScale(0, RoundingMode.HALF_EVEN); // 맞춤문자 결제 예상 금액
		
		// befCash(현재 보유금액) 값이 totMsgPrice(맞춤문자전송 금액) 보다 많으면 문자 전송
		//if(befCash.compareTo(totMsgPrice) < 0 || befCash.compareTo(totMsgPrice) == 0) {
		if(befCash.compareTo(totMsgPrice) < 0) {
			modelAndView.addObject("result", "notMoney");
			return modelAndView;
		}
		
		mjonMsgCustomVO.setUserId(userId);
		mjonMsgCustomVO.setFrstRegisterId(userId);
		mjonMsgCustomVO.setLastUpdusrId(userId);
		mjonMsgCustomService.insertMjonMsgCustomInfo(mjonMsgCustomVO);
		
		// 법인폰 알람여부 체크
		JoinSettingVO joinSettingVO = new JoinSettingVO();
		joinSettingVO = egovSiteManagerService.selectAdminNotiDetail();
		// 이메일 체크
		if (joinSettingVO != null && joinSettingVO.getEmailNoti().equals("Y")) {
			String emailTitle = "문자관리 > 문자맞춤제작 요청";
			// CS관리자 이메일 알림전송
			mjonNoticeSendUtil.csAdminEmailNoticeSend(loginVO.getName(), loginVO.getId(), emailTitle);		
		}
		
		// SLACK 체크
		if (joinSettingVO != null && joinSettingVO.getSlackNoti().equals("Y")) {		
			// Slack 메시지 발송(단순본문)
			String msg = "[문자온] 문자맞춤제작 요청 - " + loginVO.getName() +"("+ loginVO.getId() + ")";
			mjonCommon.sendSimpleSlackMsg(msg);		
		}
		
		modelAndView.addObject("result", "success");
		return modelAndView;
	}
	
	/** 사용자 맞춤제작 팝업*/
	@RequestMapping(value= {"/web/mjon/custom/MsgCustomVeiwPopupAjax.do"})
	public String selectMsgCustomPopupDetailAjax(@ModelAttribute("searchVO") MjonMsgCustomVO mjonMsgCustomVO
			, ModelMap model) throws Exception{
		
		//로그인 권한정보 불러오기
		LoginVO loginVO = EgovUserDetailsHelper.isAuthenticated()? (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser():null;
		String userId = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getId());
		String author = loginVO == null ? "" : EgovStringUtil.isNullToString(loginVO.getAuthority());
		
		return "/web/custom/MsgCustomVeiwPopupAjax";
	}
	
	/** 맞춤제작 상세보기 팝업 리스트 조회*/
	@RequestMapping(value= {"/web/mjon/custom/selectMyCustomImgRequestListAjax.do"})
	public ModelAndView selectMyCustomImgRequestListAjax(@ModelAttribute("searchVO") MjonMsgCustomVO mjonMsgCustomVO
			, ModelMap model) throws Exception{
		
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("jsonView");
		try {
			
			List<MjonMsgCustomVO> customList = mjonMsgCustomService.selectMyCustomImgRequestList(mjonMsgCustomVO);
			
			for(int i=0; i < customList.size(); i++) {
				if("Y".equals(customList.get(i).getCustomUploadYn())) {
					
					String sampleFileSn[] = customList.get(i).getCustomUploadImgFileSn().split("/");
					
					FileVO fileVO = new FileVO();
					String fileName = "";
					for(int j=0; j< sampleFileSn.length; j++) {
						fileVO.setAtchFileId(customList.get(i).getCustomUploadImg());
						fileVO.setFileSn(sampleFileSn[j]);
						FileVO result = fileMngService.selectFileInf(fileVO);
						
						// JSPark 2023.03.07 => 널 체크 추가
						if (result != null) {
							if(j != 0 ) {
								fileName = fileName +",  ";
							}
							fileName = fileName + result.getOrignlFileNm();
						}
					}
					
					customList.get(i).setTempImg1(fileName);
				}
			}
			
			modelAndView.addObject("customList", customList);
			modelAndView.addObject("result", "success");
		}catch (Exception e) {
			modelAndView.addObject("message", "다시 시도 부탁드립니다.");
			modelAndView.addObject("result", "fail");
		}
		
		return modelAndView;
	}
}
