package cokr.xit.fims.sprt.web;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

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

import org.apache.poi.ss.usermodel.CellStyle;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cokr.xit.applib.Print;
import cokr.xit.base.code.CommonCode;
import cokr.xit.base.docs.xls.CellDef;
import cokr.xit.base.docs.xls.Format;
import cokr.xit.base.docs.xls.Style;
import cokr.xit.base.docs.xls.XLSWriter;
import cokr.xit.base.file.service.FileQuery;
import cokr.xit.base.file.service.bean.FileBean;
import cokr.xit.base.user.dao.UserMapper;
import cokr.xit.base.web.ApplicationController;
import cokr.xit.fims.base.FimsUser;
import cokr.xit.fims.base.service.bean.OgdpBean;
import cokr.xit.fims.cmmn.CmmnUtil;
import cokr.xit.fims.cmmn.FimsPrintOption;
import cokr.xit.fims.cmmn.OtptStngQuery;
import cokr.xit.fims.cmmn.OutsourcingFileMaker;
import cokr.xit.fims.cmmn.OutsourcingStngQuery;
import cokr.xit.fims.cmmn.dao.OtptStngMapper;
import cokr.xit.fims.cmmn.hwp.format.CrdnConfirm;
import cokr.xit.fims.cmmn.hwp.format.CrdnList;
import cokr.xit.fims.cmmn.hwp.format.RcvmtConfirm;
import cokr.xit.fims.cmmn.hwp.format.ReportOnClaims;
import cokr.xit.fims.cmmn.hwp.format.RequestForDelivery;
import cokr.xit.fims.cmmn.pdf.print.format.Advntce;
import cokr.xit.fims.cmmn.pdf.print.format.Nht;
import cokr.xit.fims.cmmn.service.bean.OtptStngBean;
import cokr.xit.fims.cmmn.service.bean.OutsourcingStngBean;
import cokr.xit.fims.cmmn.service.bean.StngBean;
import cokr.xit.fims.cmmn.xls.FormatMaker;
import cokr.xit.fims.cmmn.xls.StyleMaker;
import cokr.xit.fims.crdn.Crdn;
import cokr.xit.fims.crdn.CrdnQuery;
import cokr.xit.fims.crdn.dao.CrdnListMapper;
import cokr.xit.fims.mngt.service.bean.TaskBean;
import cokr.xit.fims.mngt.service.bean.TaskProcessor;
import cokr.xit.fims.sndb.SndbQuery;
import cokr.xit.fims.sndb.Sndng;
import cokr.xit.fims.sndb.service.bean.SndngBean;
import cokr.xit.fims.sprt.Keyword;
import cokr.xit.fims.sprt.SprtQuery;
import cokr.xit.fims.sprt.dao.IntegrationSearchMapper;
import cokr.xit.fims.sprt.service.IntegrationSearchService;
import cokr.xit.fims.sprt.service.bean.MediaBean;
import cokr.xit.foundation.UserInfo;
import cokr.xit.foundation.data.DataObject;

/**통합 조회 서비스의 웹 컨트롤러
*
* <p>상세 설명:
*
* <pre>
* ============ 변경 이력 ============
* 2023-08-18	JoJH 최초 작성
* ================================
* </pre>
*/
@Controller
@RequestMapping(name = "통합 조회", value = Sprt01Controller.CLASS_URL)
public class Sprt01Controller extends ApplicationController {

	public static final String CLASS_URL = "/sprt/sprt01";

	public class METHOD_URL {
		public static final String
		integrationSearchMain  = "/010/main.do",
		getIntegrationDataList = "/010/list.do",
		manageEtcCnMain        = "/020/info.do",

		inputEtcCnMain         = "/100/info.do",
		inputEtcCn             = "/100/update.do",
		printCrdnMain                    = "/110/info.do",
		makeCrdnListFileFromHwpFormat    = "/110/makeCrdnListFileFromHwpFormat.do",
		makeCrdnConfirmFileFromHwpFormat = "/110/makeCrdnConfirmFileFromHwpFormat.do",
		printBillMain                           = "/120/info.do",
		makeRequestForDeliveryFileFromHwpFormat = "/120/makeRequestForDeliveryFileFromHwpFormat.do",
		makeReportOnClaimsFileFromHwpFormat     = "/120/makeReportOnClaimsFileFromHwpFormat.do",
		makeRcvmtConfirmFileFromHwpFormat	= "/130/makeRcvmtConfirmFileFromHwpFormat.do",
		printAdvntceMain       = "/140/info.do",
		makeAdvntcePdf         = "/140/makeAdvntcePdf.do",
		makeAdvntceOutsourcing = "/140/makeAdvntceOutsourcing.do",
		printNhtMain           = "/150/info.do",
		makeNhtPdf             = "/150/makeNhtPdf.do",
		makeNhtOutsourcing     = "/150/makeNhtOutsourcing.do"
		;
	}

	/**통합 조회 서비스*/
	@Resource(name="integrationSearchService")
	private IntegrationSearchService integrationSearchService;
	@Resource(name="userMapper")
	protected UserMapper userMapper;
	@Resource(name="otptStngBean")
	protected OtptStngBean otptStngBean;
	@Resource(name="outsourcingStngBean")
	protected OutsourcingStngBean outsourcingStngBean;
	@Resource(name = "fileBean")
	private FileBean fileBean;
	@Resource(name = "sndngBean")
	private SndngBean sndngBean;
	@Resource(name = "taskBean")
	private TaskBean taskBean;
	@Resource(name = "ogdpBean")
	private OgdpBean ogdpBean;
	@Resource(name = "mediaBean")
	private MediaBean mediaBean;
	@Resource(name = "stngBean")
	private StngBean stngBean;
	@Resource(name = "crdnListMapper")
	private CrdnListMapper crdnListMapper;
	@Resource(name = "integrationSearchMapper")
	private IntegrationSearchMapper integrationSearchMapper;
	@Resource(name = "otptStngMapper")
	private OtptStngMapper otptStngMapper;

	/**통합 조회 메인화면(fims/sprt/sprt01/010-main)을 연다.
	 *
	 * @return /fims/sprt/sprt01010
	 */
	@RequestMapping(name="통합조회 메인", value=METHOD_URL.integrationSearchMain)
	public ModelAndView integrationSearchMain() {
		TaskProcessor taskProcessor = TaskProcessor.get();
		DataObject taskVltnCdGrps = taskProcessor.getTaskVltnCdGrps();
		List<String> vltnCdGrps = taskVltnCdGrps.values().stream()
			.map(v -> (String)v)
			.collect(Collectors.toCollection(ArrayList::new));
		vltnCdGrps.addAll(List.of("FIM003", "FIM010", "FIM026", "FIM054"));
		String[] cdGrps = vltnCdGrps.toArray(new String[vltnCdGrps.size()]);
		Map<String, List<CommonCode>> commonCodes = getCodesOf(cdGrps);

		ModelAndView mav = new ModelAndView("fims/sprt/sprt01010-main")
			.addObject("pageName", "sprt01010")
			.addObject("sggCd", currentUser().getOrgID())
			.addObject("TaskListForSgg", stngBean.filterTaskSectionCodeForSgg(commonCodes.get("FIM054")))
			.addObject("vltnCdGrps", taskVltnCdGrps);
		vltnCdGrps.forEach(cdGrp -> mav.addObject(cdGrp + "List", commonCodes.get(cdGrp)));

		return addCodes(commonCodes, mav, cdGrps);
	}

	/**지정한 조건에 따라 통합 조회 자료 목록을 반환한다.<br />
	 * {@link IntegrationSearchService#getIntegrationDataList(SprtQuery)} 참고
	 * @param query 통합 조회 조건
	 * @return jsonView
	 */
	@RequestMapping(name="통합조회 자료 목록", value=METHOD_URL.getIntegrationDataList)
	public ModelAndView getIntegrationDataList(SprtQuery query, HttpServletRequest req) {
		makeIntegrationSearchQuery(query, req);
		List<DataObject> list = integrationSearchService.getIntegrationDataList(query);
		List<DataObject> upList = list.stream().filter(item -> item.string("RCVMT_ETC_YN").equals("N")).toList();
		List<DataObject> downList = list.stream().filter(item -> item.string("RCVMT_ETC_YN").equals("Y")).toList();

		if("xls".equals(query.getDownload())) {
			List<CellDef> cellDefs = fromJson(query.getCellDefs(), CellDef.listType());

			String fileName = "통합조회자료 목록";
			List<DataObject> listForExcel;
			if(ifEmpty(query.getGridType(), () -> "").equals("up")) {
				fileName += "(미납자료)";
				listForExcel = upList;
			} else if(ifEmpty(query.getGridType(), () -> "").equals("down")) {
				fileName += "(수납,기타)";
				listForExcel = downList;
			} else {
				listForExcel = list;
			}

			XLSWriter xlsx = new XLSWriter().worksheet(0);
			Format format = new Format(xlsx);
			CellStyle center = format.cellStyle(Style.CENTER);
			CellStyle numeric = format.n_nn0();
			CellStyle dateYMD = format.yyyy_mm_dd();
			CellStyle dateDT = format.yyyy_mm_dd_hh_mm_ss();

			Map<String, Object> valueMap = new HashMap<String, Object>();
			valueMap.put("시군구명"  	, format.of("SGG_NM").style(center));
			valueMap.put("과태료명"  	, format.of("TASK_SE_NM").style(center));
			valueMap.put("민원신청인"  	, format.of("CVLCPT_APLCNT_NM").style(center));
			valueMap.put("민원접수번호"	, format.of("CVLCPT_RCPT_NO").style(center));
			valueMap.put("민원접수일자"	, FormatMaker.yyyy_mm_dd(format, "CVLCPT_RCPT_YMD").style(dateYMD));
			valueMap.put("민원목록번호"	, format.of("CVLCPT_LIST_NO").style(center));
			valueMap.put("고지번호" 	, format.of("GOJI_NO").style(center));
			valueMap.put("단속일시"  	, FormatMaker.yyyy_mm_dd_hh_mm_ss(format, "CRDN_YMD_TM").style(dateDT));
			valueMap.put("단속차량번호"	, format.of("VHRNO"));
			valueMap.put("대체차량번호"	, format.of("RPM_SZR_VHRNO"));
			valueMap.put("사진건수"  	, format.of("ATCH_FILE_CNT").style(center));
			valueMap.put("차량확인"  	, format.of("PRK_PSBLTY_RSLT_NM").style(center));
			valueMap.put("납부자명"  	, format.of("RTPYR_NM").style(center));
			valueMap.put("납부자번호"	, format.of("RTPYR_NO").style(center));
			valueMap.put("처리상태"		, format.of("CRDN_STTS_NM").style(center));
			valueMap.put("처리일자" 	, FormatMaker.yyyy_mm_dd(format, "CRDN_STTS_CHG_YMD").style(dateYMD));
			valueMap.put("제외일자" 	, FormatMaker.yyyy_mm_dd(format, "LEVY_EXCL_YMD").style(dateYMD));
			valueMap.put("제외사유" 	, format.of("LEVY_EXCL_RSN_NM"));
			valueMap.put("단속등록구분"	, format.of("CRDN_REG_SE_NM").style(center));
			valueMap.put("단속입력구분"	, format.of("CRDN_INPT_SE_NM").style(center));
			valueMap.put("단속구분" 	, format.of("CRDN_SE_NM").style(center));
			valueMap.put("법정동" 		, format.of("CRDN_STDG_NM").style(center));
			valueMap.put("단속장소" 	, format.of("CRDN_PLC"));
			valueMap.put("의견진술여부"	, format.of("OPNN_SBMSN_YN_NM").style(center));
			valueMap.put("사전통지기한"	, FormatMaker.yyyy_mm_dd(format, "ADVNTCE_DUDT_YMD").style(dateYMD));
			valueMap.put("견인여부"		, format.of("TOWNG_YN_NM").style(center));
			valueMap.put("기타사항" 	, format.of("ETC_CN"));
			valueMap.put("감경구분"		, format.of("RDCT_SE_NM").style(center));
			valueMap.put("부과일자"		, FormatMaker.yyyy_mm_dd(format, "LEVY_YMD").style(dateYMD));
			valueMap.put("납기일자"		, FormatMaker.yyyy_mm_dd(format, "DUDT_YMD").style(dateYMD));
			valueMap.put("미납금액"		, format.of("MINAP_AMT").style(numeric));
			valueMap.put("납기후일자"	, FormatMaker.yyyy_mm_dd(format, "DUDT_AFTR_YMD").style(dateYMD));
			valueMap.put("납기후금액"	, format.of("DUDT_AFTR_AMT").style(numeric));
			valueMap.put("압류일자" 	, FormatMaker.yyyy_mm_dd(format, "SZR_YMD").style(dateYMD));
			valueMap.put("압류해제일자" , FormatMaker.yyyy_mm_dd(format, "SZR_RMV_YMD").style(dateYMD));
			valueMap.put("과태료금액"	, format.of("FFNLG_AMT").style(numeric));
			valueMap.put("본세"			, format.of("LEVY_PCPTAX").style(numeric));
			valueMap.put("가산금"		, format.of("LEVY_ADAMT").style(numeric));
			valueMap.put("전자납부번호"	, format.of("EPAYNO").style(center));
			valueMap.put("은행명"		, format.of("BANK_NM").style(center));
			valueMap.put("가상계좌번호"	, format.of("VR_ACTNO").style(center));
			valueMap.put("수납유형"		, format.of("PAY_MTHD_SE_NM").style(center));
			valueMap.put("수납일자"		, FormatMaker.yyyy_mm_dd(format, "RCVMT_YMD").style(dateYMD));
			valueMap.put("수납금액"		, format.of("RCVMT_AMT").style(numeric));
			valueMap.put("수납본세"		, format.of("RCVMT_PCPTAX").style(numeric));
			valueMap.put("수납가산금"	, format.of("RCVMT_ADAMT").style(numeric));
			valueMap.put("거주상태"		, format.of("RTPYR_STTS_NM").style(center));
			valueMap.put("납부자주소"	, format.of("RTPYR_FULL_ADDR"));

			CellDef.setValues(cellDefs, valueMap);

			xlsx.cell(0, 0).value(fileName).value(center).merge(0, cellDefs.size()-1)
				.cell(3, 0).rowValues(CellDef.header(cellDefs, () -> StyleMaker.headerStyle(xlsx)))
				.cell(4, 0).values(listForExcel, CellDef.values(cellDefs.stream().map(i -> {if(i.getValue() instanceof Format) {i.setField(null);}; return i;}).toList()));

			return new ModelAndView("downloadView").addObject("download", xlsx.getDownloadable().setFilename(fileName+".xlsx"))
					.addObject("downloadData", listForExcel).addObject("dataNames", cellDefs.stream().map(CellDef::getLabel).toList());
		}

		return new ModelAndView("jsonView")
			.addObject("upList", upList)
			.addObject("downList", downList);
	}

	private void makeIntegrationSearchQuery(SprtQuery query, HttpServletRequest req) {
		Map<String, String[]> pm = req.getParameterMap();
		Enumeration<String> pns = req.getParameterNames();

		List<Keyword> ischKeywordSet = new ArrayList<>();

		List<String> ischOnlyDataSet = new ArrayList<>();
		List<String> ischExclDataSet = new ArrayList<>();

		while(pns.hasMoreElements()) {

			String key = pns.nextElement();
			String[] value = pm.get(key);

			if(!key.startsWith("isch")) {
				continue;
			}
			if(value == null || value.length == 0) {
				continue;
			}

			if(value.length == 1 && ifEmpty(value[0], () -> "").equals("")) {
				continue;
			}

			if(key.startsWith("ischOnlyData") || key.startsWith("ischExclData")) {
				String word = this.fnFirstLower(key.substring(12));

				if(key.startsWith("ischOnlyData")) {
					ischOnlyDataSet.add(word);
				} else if(key.startsWith("ischExclData")) {
					ischExclDataSet.add(word);
				}
				continue;
			}

			String word = this.fnFirstLower(key.substring(4));
			int substringEnd = 0;
			if(key.endsWith("Similar")){
				substringEnd = 7;
			} else if(key.endsWith("From")) {
				substringEnd = 4;
			} else if(key.endsWith("To")){
				substringEnd = 2;
			}

			if(substringEnd != 0) {
				word = word.substring(0, word.length() - substringEnd);
			}

			int findIndex = -1;
			for (int i = 0; i < ischKeywordSet.size(); i++) {
	            if (ischKeywordSet.get(i).getName().equals(word)) {
	            	findIndex = i;
	                break;
	            }
	        }

			if(findIndex == -1){

				Keyword keyword = new Keyword();
				keyword.setName(word);

				if(key.endsWith("Similar")){
					keyword.setSimilar(value[0]);
				} else if(key.endsWith("From")){
					keyword.setFrom(value[0]);
				} else if(key.endsWith("To")){
					keyword.setTo(value[0]);
				} else {
					keyword.setValue(value[0]);
				}

				ischKeywordSet.add(keyword);

			} else {

				if(key.endsWith("Similar")){
					ischKeywordSet.get(findIndex).setSimilar(value[0]);
				} else if(key.endsWith("From")){
					ischKeywordSet.get(findIndex).setFrom(value[0]);
				} else if(key.endsWith("To")){
					ischKeywordSet.get(findIndex).setTo(value[0]);
				} else {
					ischKeywordSet.get(findIndex).setValue(value[0]);
				}

			}
		}

		ischKeywordSet.removeIf(item -> item.getSimilar() != null && item.getValue() == null);

		query.setIschKeywordSet(ischKeywordSet);
		query.setIschOnlyDataSet(ischOnlyDataSet);
		query.setIschExclDataSet(ischExclDataSet);
	}

	private String fnFirstLower(String string) {

		String temp1 = string.substring(0,1).toLowerCase();
		String temp2 = string.substring(1);
		return temp1 + temp2;
	}


	/**특기사항 일괄 입력 화면을 연다.
	 *
	 * @return /fims/sprt/sprt01100
	 */
	@RequestMapping(name="특기사항 일괄 입력 화면", value=METHOD_URL.inputEtcCnMain)
	public ModelAndView inputEtcCnMain(String... crdnIds) {
		return new ModelAndView("fims/sprt/sprt01100-info")
			.addObject("pageName", "sprt01100")
			.addObject("crdnIds", toJson(crdnIds));
	}

	/**특기사항을 일괄 갱신한다.
	 * @param etcCn 특기사항, crdnIds 단속 ID 목록
	 * @return jsonView
	 * <pre><code> {
	 *     "affected": 저장된 정보수
	 *     "saved": 저장되었으면 true, 그렇지 않으면 false
	 * }</code></pre>
	 */
	@RequestMapping(name="특기사항 일괄 입력", value=METHOD_URL.inputEtcCn)
	public ModelAndView inputEtcCn(Crdn crdn, String... crdnIds) {
		String rtnMsg = integrationSearchService.updateEtcCn(crdn.getEtcCn(), crdnIds);
		return new ModelAndView("jsonView")
			.addObject("saved", rtnMsg.contains("[S]"));
	}

	/**단속내역서,확인서 출력 화면을 연다.
	 *
	 * @return /fims/sprt/sprt01110
	 */
	@RequestMapping(name="단속 내역서,확인서 출력 화면", value=METHOD_URL.printCrdnMain)
	public ModelAndView printCrdnMain(String... crdnIds) {
		return new ModelAndView("fims/sprt/sprt01110-info")
			.addObject("pageName", "sprt01110")
			.addObject("crdnIds", toJson(crdnIds));
	}

	/** 단속내역서를 한글 파일로 작성한다.
	 * @return 단속내역서 hwp파일
	 */
	@RequestMapping(name="단속 내역서 한글 파일 생성", value=METHOD_URL.makeCrdnListFileFromHwpFormat)
	public ModelAndView makeCrdnListFileFromHwpFormat(String privateInfoYn, String... crdnIds) {
		FimsPrintOption printOption = new FimsPrintOption();
		printOption.setPrivateInfoYn(privateInfoYn);
		UserInfo userInfo = currentUser();
		ogdpBean.initUserInfo(userInfo);
		Print print = new Print();
		print.setPrintRequestUserInfo(userInfo);

		CrdnQuery query = new CrdnQuery()
			.setCrdnIds(crdnIds);
		List<DataObject> dataObjectList = crdnListMapper.selectCrackdownList(query);

		CrdnList hwpFormat = new CrdnList(print, printOption, dataObjectList);
		HashMap<String, Object> result = hwpFormat.makeFile().andDownload();

		return new ModelAndView("downloadView")
			.addAllObjects(result);
	}

	/** 단속확인서를 한글 파일로 작성한다.
	 * @return 단속확인서 hwp파일
	 */
	@RequestMapping(name="단속 확인서 한글 파일 생성", value=METHOD_URL.makeCrdnConfirmFileFromHwpFormat)
	public ModelAndView makeCrdnConfirmFileFromHwpFormat(String... crdnIds) {
		FimsPrintOption printOption = new FimsPrintOption();

		UserInfo userInfo = currentUser();
		ogdpBean.initUserInfo(userInfo);
		Print print = new Print();
		print.setPrintRequestUserInfo(userInfo);

		CrdnQuery query = new CrdnQuery()
			.setCrdnIds(crdnIds);
		List<DataObject> dataObjectList = crdnListMapper.selectCrackdownList(query);

		for(int i=0; i < dataObjectList.size(); i++) {
			DataObject dataObject = dataObjectList.get(i);
			String crndId = dataObject.string("CRDN_ID");

			FileQuery fileQuery = new FileQuery()
				.setInfoType(Crdn.INF_TYPE)
				.setInfoKeys(crndId);
			List<DataObject> fileInfoList = fileBean.getFileList(fileQuery);
			if(fileInfoList != null && fileInfoList.size() > 0) {
				dataObject.set("PHOTO1", fileInfoList.get(0).string("URL"));
				if(fileInfoList.size() >= 2)
					dataObject.set("PHOTO2", fileInfoList.get(1).string("URL"));
				if(fileInfoList.size() >= 3)
					dataObject.set("PHOTO3", fileInfoList.get(2).string("URL"));
				if(fileInfoList.size() >= 4)
					dataObject.set("PHOTO4", fileInfoList.get(3).string("URL"));
			}

		}

		CrdnConfirm hwpFormat = new CrdnConfirm(print, printOption, dataObjectList);
		HashMap<String, Object> result = hwpFormat.makeFile().andDownload();
		return new ModelAndView("downloadView")
			.addAllObjects(result);
	}

	/**교부청구서,채권신고서 출력 화면을 연다.
	 *
	 * @return /fims/sprt/sprt01120
	 */
	@RequestMapping(name="교부청구서,채권신고서 출력 화면", value=METHOD_URL.printBillMain)
	public ModelAndView printBillMain(String... crdnIds) {
		return new ModelAndView("fims/sprt/sprt01120-info")
			.addObject("pageName", "sprt01120")
			.addObject("crdnIds", toJson(crdnIds));
	}

	/** 교부청구서를 한글 파일로 작성한다.
	 * @return hwp파일
	 */
	@RequestMapping(name="교부청구서 한글 파일 생성", value=METHOD_URL.makeRequestForDeliveryFileFromHwpFormat)
	public ModelAndView makeRequestForDeliveryFileFromHwpFormat(FimsPrintOption printOption, String globalVariableInfo, String... crdnIds) {
		DataObject sggStngInfo = stngBean.getStng("sgg");
		DataObject deptStngInfo = stngBean.getStng("dept");

		Map<String, String> globalVariable = new HashMap<String,String>();

		DataObject dataObject = fromJson(globalVariableInfo, DataObject.class);

		globalVariable.put("docNo", dataObject.string("docNo"));
		globalVariable.put("caseNo", dataObject.string("caseNo"));
		globalVariable.put("receiver", dataObject.string("receiver"));
		globalVariable.put("rtpyrNm", dataObject.string("rtpyrNm"));
		globalVariable.put("rtpyrNo", dataObject.string("rtpyrNo"));
		globalVariable.put("vhrno", dataObject.string("vhrno"));
		globalVariable.put("rtpyrFullAddr", dataObject.string("rtpyrFullAddr"));
		globalVariable.put("dtbnBankNm", deptStngInfo.string("DTBN_BANK_NM"));
		globalVariable.put("dtbnActno", deptStngInfo.string("DTBN_ACTNO"));
		globalVariable.put("offcsFilePath", sggStngInfo.string("OFFCS_FILE_PATH"));
		printOption.setGlobalVariable(globalVariable);

		UserInfo userInfo = currentUser();
		ogdpBean.initUserInfo(userInfo);
		Print print = new Print();
		print.setPrintRequestUserInfo(userInfo);

		SprtQuery sprtQuery = new SprtQuery()
			.setCrdnIds(crdnIds);
		List<DataObject> dataObjectList = integrationSearchMapper.selectIntegrationDataList(sprtQuery);


		RequestForDelivery hwpFormat = new RequestForDelivery(print, printOption, dataObjectList);
		HashMap<String, Object> result = hwpFormat.makeFile().andDownload();
		return new ModelAndView("downloadView")
			.addAllObjects(result);
	}

	/** 채권신고서를 한글 파일로 작성한다.
	 * @return 채권신고서 hwp파일
	 */
	@RequestMapping(name="채권신고서 한글 파일 생성", value=METHOD_URL.makeReportOnClaimsFileFromHwpFormat)
	public ModelAndView makeReportOnClaimsFileFromHwpFormat(FimsPrintOption printOption, String globalVariableInfo, String... crdnIds) {
		DataObject sggStngInfo = stngBean.getStng("sgg");
		DataObject deptStngInfo = stngBean.getStng("dept");

		UserInfo userInfo = currentUser();
		ogdpBean.initUserInfo(userInfo);
		Print print = new Print();
		print.setPrintRequestUserInfo(userInfo);

		Map<String, String> globalVariable = new HashMap<String,String>();

		DataObject dataObject = fromJson(globalVariableInfo, DataObject.class);

		globalVariable.put("caseNo", dataObject.string("caseNo"));
		globalVariable.put("rtpyrNm", dataObject.string("rtpyrNm"));
		globalVariable.put("rtpyrNo", dataObject.string("rtpyrNo"));
		globalVariable.put("rtpyrFullAddr", dataObject.string("rtpyrFullAddr"));

		String deptNm = (String) print.getPrintRequestUserInfo().getInfo().get("deptNm");
		String deptAddr = sggStngInfo.string("INST_FULL_ADDR") + " " + deptNm;
		globalVariable.put("deptAddr", deptAddr);
		globalVariable.put("deptTelno", deptStngInfo.string("DEPT_TELNO"));
		globalVariable.put("deptFxno", deptStngInfo.string("DEPT_FXNO"));
		globalVariable.put("offcsFilePath", sggStngInfo.string("OFFCS_FILE_PATH"));
		printOption.setGlobalVariable(globalVariable);

		SprtQuery sprtQuery = new SprtQuery()
			.setCrdnIds(crdnIds);
		List<DataObject> dataObjectList = integrationSearchMapper.selectIntegrationDataList(sprtQuery);

		ReportOnClaims hwpFormat = new ReportOnClaims(print, printOption, dataObjectList);
		HashMap<String, Object> result = hwpFormat.makeFile().andDownload();

		return new ModelAndView("downloadView")
			.addAllObjects(result);
	}

	/** 납부확인서를 한글 파일로 작성한다.
	 * @return 납부확인서 hwp파일
	 */
	@RequestMapping(name="납부확인서 한글 파일 생성", value=METHOD_URL.makeRcvmtConfirmFileFromHwpFormat)
	public ModelAndView makeRcvmtConfirmFileFromHwpFormat(String... crdnIds) {
		UserInfo userInfo = currentUser();
		ogdpBean.initUserInfo(userInfo);
		Print print = new Print();
		print.setPrintRequestUserInfo(userInfo);

		FimsPrintOption printOption = new FimsPrintOption();
		printOption.setGlobalVariable(new HashMap<String,String>());

		SprtQuery sprtQuery = new SprtQuery()
			.setCrdnIds(crdnIds);
		List<DataObject> dataObjectList = integrationSearchMapper.selectIntegrationDataList(sprtQuery);

		RcvmtConfirm hwpFormat = new RcvmtConfirm(print, printOption, dataObjectList);
		HashMap<String, Object> result = hwpFormat.makeFile().andDownload();
		return new ModelAndView("downloadView")
			.addAllObjects(result);
	}

	/**사전통지서 출력 화면을 연다.
	 *
	 * @return /fims/sprt/sprt01140
	 */
	@RequestMapping(name="사전통지서 출력 화면", value=METHOD_URL.printAdvntceMain)
	public ModelAndView printAdvntceMain(String... crdnIds) {
		return new ModelAndView("fims/sprt/sprt01140-info")
			.addObject("pageName", "sprt01140")
			.addObject("crdnIds", toJson(crdnIds));
	}

	/** 사전통지서를 PDF 파일로 작성한다.
	 * @return 사전통지서 PDF파일
	 */
	@RequestMapping(name="사전통지서 pdf 파일 생성", value=METHOD_URL.makeAdvntcePdf)
	public ModelAndView makeAdvntcePdf(String[] crdnIds, Sndng sndng, FimsPrintOption printOption) {
		UserInfo userInfo = currentUser();
		ogdpBean.initUserInfo(userInfo);

		sndng.setSggCd((String)userInfo.getInfo().get("sggCd"));

		SprtQuery sprtQuery = new SprtQuery()
			.setCrdnIds(crdnIds);

		List<DataObject> dataObjectList = new ArrayList<DataObject>();
		if(crdnIds.length == 1 && crdnIds[0].equals("sample")) {
			DataObject sample = new Advntce().createSampleData();
			dataObjectList.add(sample);
		} else {
			//발송 등록
			List<DataObject> dataObjectList0 = integrationSearchMapper.selectIntegrationDataList(sprtQuery);
			SndbQuery sndbQuery = new SndbQuery()
				.setCrdnIds(crdnIds);
			sndng.setSndngRegSeCd("02");
			sndng.setSndngSeCd("02");
			sndng.setTnocs(crdnIds.length);
			sndng.setGramt(CmmnUtil.sumByKey(dataObjectList0, "FFNLG_AMT"));
			String today = dateFormats.format("yyyyMMdd", System.currentTimeMillis());
			sndng.setSndngYmd(today);

			sndbQuery.setSggCd(sndng.getSggCd());
			sndbQuery.setTaskSeCd(sndng.getTaskSeCd());
			DataObject advntceYmdInfo = taskBean.getAdvntceYmdInfo(sndbQuery);
			String sndngEndYmd = CmmnUtil.addDay(today, toInt(advntceYmdInfo.get("ADVNTCE_DAY_CNT")));
			sndng.setSndngEndYmd(sndngEndYmd);

			DataObject first = dataObjectList0.get(0);
			sndng.setTtlNm(first.string("TASK_SE_NM")+" "+"사전통지서");
			sndng.setRsndYn("N");
			String insertSndngResult = sndngBean.createAdvntceSndngList(sndbQuery, sndng).getMessage();
			if(!insertSndngResult.contains("[S]")) {
				throw new RuntimeException(insertSndngResult);
			}

			//발송 등록 후 출력대상조회
			dataObjectList = integrationSearchMapper.selectIntegrationDataList(sprtQuery);

			for(int i=0; i < dataObjectList.size(); i++) {
				DataObject dataObject = dataObjectList.get(i);
				String crdnId = dataObject.string("CRDN_ID");

				FileQuery fileQuery = new FileQuery();
				fileQuery.setInfoType(Crdn.INF_TYPE);
				fileQuery.setInfoKeys(crdnId);
				List<DataObject> fileInfoList = fileBean.getFileList(fileQuery);
				if(fileInfoList != null && fileInfoList.size() > 0) {

					for(int j=0; j<fileInfoList.size(); j++) {
						dataObject.set("CRDN_PHOTO"+(j+1), fileInfoList.get(j).string("URL"));
						dataObject.set("CRDN_PHOTO"+(j+1)+"KEY", fileInfoList.get(j).string("FILE_ID"));

						List<DataObject> mosSet = mediaBean.getMosaicList(fileInfoList.get(j).string("FILE_ID"));
						if(mosSet != null && !mosSet.isEmpty()) {
							dataObject.set("MOS"+fileInfoList.get(j).string("FILE_ID"), mosSet);
						}
					}

				}

			}
		}


		Print print = new Print();
		print.setPrintRequestUserInfo(userInfo);

		//출력물 기본 설정
		OtptStngQuery otptStngQuery = new OtptStngQuery();
		String paperSeCd = printOption.getPaperSeCd();
		String taskSeCd = printOption.getTaskSeCd();
		otptStngQuery.setSggCd((String)userInfo.getInfo().get("sggCd"));
		otptStngQuery.setTaskSeCd(taskSeCd);
		otptStngQuery.setSndngSeCd("02");
		otptStngQuery.setPaperSeCd(paperSeCd);
		DataObject otptBscStng = otptStngMapper.selectOtptBscStng(otptStngQuery);
		if(otptBscStng == null) {
			otptBscStng = new DataObject();
		}
		//출력 요소별 설정
		List<DataObject> otptArtclStngList = otptStngMapper.selectOtptArtclStngList(otptStngQuery);

		DataObject sggStngInfo = stngBean.getStng("sgg");
		DataObject deptStngInfo = stngBean.getStng("dept");
		//
		Map<String, String> globalVariable = printOption.getGlobalVariable();
		if(globalVariable == null) {
			globalVariable = new HashMap<String, String>();
		}
		globalVariable.put("offcsFilePath", sggStngInfo.string("OFFCS_FILE_PATH"));
		globalVariable.put("logoFilePath", sggStngInfo.string("LOGO_FILE_PATH"));
		globalVariable.put("instAddr", sggStngInfo.string("INST_ADDR"));
		globalVariable.put("instDaddr", sggStngInfo.string("INST_DADDR"));
		globalVariable.put("instZip", sggStngInfo.string("INST_ZIP"));
		globalVariable.put("deptTelno", deptStngInfo.string("DEPT_TELNO"));
		globalVariable.put("deptFxno", deptStngInfo.string("DEPT_FXNO"));
		if(!otptBscStng.string("BCRN_IMG_PATH").equals("")) {
			globalVariable.put("bcrnImgPath", otptBscStng.string("BCRN_IMG_PATH"));
		}
		printOption.setGlobalVariable(globalVariable);

		Advntce pdfFormat = new Advntce(print,printOption,otptBscStng,otptArtclStngList,paperSeCd,dataObjectList);
		Map<String, Object> result = pdfFormat.makeFile();

		return new ModelAndView("downloadView")
			.addAllObjects(result);
	}


	/** 사전통지 정보로 txt파일,이미지파일을 생성하고 압축파일로 반환한다.
	 * @return 사전통지서 압축파일
	 */
	@RequestMapping(name="사전통지서 외주 파일 생성", value=METHOD_URL.makeAdvntceOutsourcing)
	public ModelAndView makeAdvntceOutsourcing(String[] crdnIds, Sndng sndng, FimsPrintOption printOption) {
		UserInfo userInfo = currentUser();
		ogdpBean.initUserInfo(userInfo);

		sndng.setSggCd((String)userInfo.getInfo().get("sggCd"));

		SprtQuery sprtQuery = new SprtQuery()
			.setCrdnIds(crdnIds);
		//발송 등록
		List<DataObject> dataObjectList0 = integrationSearchMapper.selectIntegrationDataList(sprtQuery);

		SndbQuery sndbQuery = new SndbQuery()
			.setCrdnIds(crdnIds);
		sndng.setSndngSeCd("02");
		sndng.setTnocs(crdnIds.length);
		sndng.setGramt(CmmnUtil.sumByKey(dataObjectList0, "FFNLG_AMT"));

		String today = dateFormats.format("yyyyMMdd", System.currentTimeMillis());
		sndng.setSndngYmd(today);

		sndbQuery
			.setSggCd(sndng.getSggCd())
			.setTaskSeCd(sndng.getTaskSeCd());
		DataObject advntceYmdInfo = taskBean.getAdvntceYmdInfo(sndbQuery);
		String sndngEndYmd = CmmnUtil.addDay(today, toInt(advntceYmdInfo.get("ADVNTCE_DAY_CNT")));
		sndng.setSndngEndYmd(sndngEndYmd);

		DataObject first = dataObjectList0.get(0);
		sndng.setTtlNm(first.string("TASK_SE_NM")+" "+first.string("VLTN_ARTCL")+" "+"사전통지서");

		sndng.setRsndYn("N");
		String insertSndngResult = sndngBean.createAdvntceSndngList(sndbQuery, sndng).getMessage();
		if(insertSndngResult.contains("[F]"))
			throw new RuntimeException(insertSndngResult);

		//발송 등록 후 출력대상조회
		List<DataObject> dataObjectList = integrationSearchMapper.selectIntegrationDataList(sprtQuery);
		String taskSeCd = "";
		for(int i=0; i < dataObjectList.size(); i++) {
			DataObject sndngDtl = integrationSearchMapper.selectLatestSndngDtlInfo(dataObjectList.get(i).string("CRDN_ID"));
			dataObjectList.get(i).set("SNDNG_DTL_ID",sndngDtl.string("SNDNG_DTL_ID"));
			dataObjectList.get(i).set("SNDNG_YMD",sndngDtl.string("SNDNG_YMD"));
			dataObjectList.get(i).set("OPNN_RANGE",
					dataObjectList.get(i).string("SNDNG_YMD")+"~"+dataObjectList.get(i).string("DUDT_YMD"));
			dataObjectList.get(i).set("RG_NO",sndngDtl.string("RG_NO"));
		}

		for(int i=0; i < dataObjectList.size(); i++) {
			DataObject dataObject = dataObjectList.get(i);

			if(taskSeCd.equals("")) {
				taskSeCd = dataObject.string("TASK_SE_CD");
			}

			FileQuery fileQuery = new FileQuery()
				.setInfoType(Crdn.INF_TYPE)
				.setInfoKeys(dataObject.string("CRDN_ID"));
			List<DataObject> fileInfoList = fileBean.getFileList(fileQuery);

			if(fileInfoList != null) {
				int crdnPhotoCnt = fileInfoList.size();
				for(int j=0; j < fileInfoList.size(); j++) {
					DataObject fileInfo = fileInfoList.get(j);

					dataObject.set("CRDN_PHOTO"+(j+1), fileInfo.string("FILE_PATH"));
					dataObject.set("CRDN_PHOTO"+(j+1)+"KEY", fileInfo.string("FILE_ID"));
					List<DataObject> mosSet = mediaBean.getMosaicList(fileInfo.string("FILE_ID"));
					if(mosSet != null) {
						for(int k=0; k < mosSet.size(); k++) {
							dataObject.set("MOS"+fileInfo.string("FILE_ID"), mosSet);
						}
					}
				}
				dataObject.set("CRDN_PHOTO_CNT", crdnPhotoCnt);
			} else {
				dataObject.set("CRDN_PHOTO_CNT", 0);
			}

		}

		FimsUser currentUser = (FimsUser) currentUser().getUser();
		String sggCd = currentUser.getOrgID();

		OutsourcingStngQuery stngQuery = new OutsourcingStngQuery();
		stngQuery.setSggCd(sggCd);
		stngQuery.setTaskSeCd(taskSeCd);
		stngQuery.setSndngSeCd("02");
		List<DataObject> printStngItems = outsourcingStngBean.getArtclStngList(stngQuery);

		OutsourcingFileMaker osMaker = new OutsourcingFileMaker("사전통지", printOption, printStngItems, dataObjectList);
		Map<String, Object> result = osMaker.makeFile();

		return new ModelAndView("downloadView").addAllObjects(result);
	}


	/**고지서 출력 화면을 연다.
	 *
	 * @return /fims/sprt/sprt01150
	 */
	@RequestMapping(name="고지서 출력 화면", value=METHOD_URL.printNhtMain)
	public ModelAndView printNhtMain(String... crdnIds) {
		return new ModelAndView("fims/sprt/sprt01150-info")
			.addObject("pageName", "sprt01150")
			.addObject("crdnIds", toJson(crdnIds));
	}

	/** 고지서를 PDF 파일로 작성한다.
	 * @return 고지서 PDF파일
	 */
	@RequestMapping(name="고지서 pdf 파일 생성", value=METHOD_URL.makeNhtPdf)
	public ModelAndView makeNhtPdf(String[] crdnIds, Sndng sndng, FimsPrintOption printOption) {
		UserInfo userInfo = currentUser();
		ogdpBean.initUserInfo(userInfo);

		sndng.setSggCd((String)userInfo.getInfo().get("sggCd"));

		SprtQuery sprtQuery = new SprtQuery()
			.setCrdnIds(crdnIds);

		List<DataObject> dataObjectList = new ArrayList<DataObject>();

		if(crdnIds.length == 1 && crdnIds[0].equals("sample")) {
			DataObject sample = new Nht().createSampleData();
			dataObjectList.add(sample);
		} else {

			//발송 등록
			List<DataObject> dataObjectList0 = integrationSearchMapper.selectIntegrationDataList(sprtQuery);
			SndbQuery sndbQuery = new SndbQuery()
				.setCrdnIds(crdnIds);
			sndng.setSndngSeCd("03");
			sndng.setTnocs(crdnIds.length);
			sndng.setGramt(CmmnUtil.sumByKey(dataObjectList0, "FFNLG_AMT"));

			String today = dateFormats.format("yyyyMMdd", System.currentTimeMillis());
			sndng.setSndngYmd(today);

			sndbQuery
				.setSggCd(sndng.getSggCd())
				.setTaskSeCd(sndng.getTaskSeCd());
			DataObject advntceYmdInfo = taskBean.getAdvntceYmdInfo(sndbQuery);
			String sndngEndYmd = CmmnUtil.addDay(today, toInt(advntceYmdInfo.get("ADVNTCE_DAY_CNT")));
			sndng.setSndngEndYmd(sndngEndYmd);

			DataObject first = dataObjectList0.get(0);
			sndng.setTtlNm(first.string("TASK_SE_NM")+" "+first.string("VLTN_ARTCL")+" "+"고지서");

			sndng.setRsndYn("N");
			String insertSndngResult = sndngBean.createAdvntceSndngList(sndbQuery, sndng).getMessage();
			if(insertSndngResult.contains("[F]"))
				throw new RuntimeException(insertSndngResult);

			//발송 등록 후 출력대상조회
			dataObjectList = integrationSearchMapper.selectIntegrationDataList(sprtQuery);

			for(int i=0; i < dataObjectList.size(); i++) {
				DataObject dataObject = dataObjectList.get(i);
				String crdnId = dataObject.string("CRDN_ID");

				FileQuery fileQuery = new FileQuery();
				fileQuery.setInfoType(Crdn.INF_TYPE);
				fileQuery.setInfoKeys(crdnId);
				List<DataObject> fileInfoList = fileBean.getFileList(fileQuery);
				if(fileInfoList != null && fileInfoList.size() > 0) {

					for(int j=0; j<fileInfoList.size(); j++) {
						dataObject.set("CRDN_PHOTO"+(j+1), fileInfoList.get(j).string("URL"));
						dataObject.set("CRDN_PHOTO"+(j+1)+"KEY", fileInfoList.get(j).string("FILE_ID"));

						List<DataObject> mosSet = mediaBean.getMosaicList(fileInfoList.get(j).string("FILE_ID"));
						if(mosSet != null && !mosSet.isEmpty()) {
							dataObject.set("MOS"+fileInfoList.get(j).string("FILE_ID"), mosSet);
						}
					}

				}

			}
		}

		Print print = new Print();
		print.setPrintRequestUserInfo(userInfo);

		//출력물 기본 설정
		OtptStngQuery otptStngQuery = new OtptStngQuery();
		String paperSeCd = printOption.getPaperSeCd();
		String taskSeCd = printOption.getTaskSeCd();
		otptStngQuery.setSggCd((String)userInfo.getInfo().get("sggCd"));
		otptStngQuery.setTaskSeCd(taskSeCd);
		otptStngQuery.setSndngSeCd("03");
		otptStngQuery.setPaperSeCd(paperSeCd);
		DataObject otptBscStng = otptStngMapper.selectOtptBscStng(otptStngQuery);
		if(otptBscStng == null) {
			otptBscStng = new DataObject();
		}
		//출력 요소별 설정
		List<DataObject> otptArtclStngList = otptStngMapper.selectOtptArtclStngList(otptStngQuery);

		DataObject sggStngInfo = stngBean.getStng("sgg");
		DataObject deptStngInfo = stngBean.getStng("dept");
		//
		Map<String, String> globalVariable = printOption.getGlobalVariable();
		if(globalVariable == null) {
			globalVariable = new HashMap<String, String>();
		}
		globalVariable.put("offcsFilePath", sggStngInfo.string("OFFCS_FILE_PATH"));
		globalVariable.put("logoFilePath", sggStngInfo.string("LOGO_FILE_PATH"));
		globalVariable.put("instAddr", sggStngInfo.string("INST_ADDR"));
		globalVariable.put("instDaddr", sggStngInfo.string("INST_DADDR"));
		globalVariable.put("instZip", sggStngInfo.string("INST_ZIP"));
		globalVariable.put("deptTelno", deptStngInfo.string("DEPT_TELNO"));
		globalVariable.put("deptFxno", deptStngInfo.string("DEPT_FXNO"));
		if(!otptBscStng.string("BCRN_IMG_PATH").equals("")) {
			globalVariable.put("bcrnImgPath", otptBscStng.string("BCRN_IMG_PATH"));
		}
		printOption.setGlobalVariable(globalVariable);

		Nht pdfFormat = new Nht(print,printOption,otptBscStng,otptArtclStngList,paperSeCd,dataObjectList);
		Map<String, Object> result = pdfFormat.makeFile();

		return new ModelAndView("downloadView").addAllObjects(result);
	}

	/** 고지 정보로 txt파일,이미지파일을 생성하고 압축파일로 반환한다.
	 * @return 고지서 압축파일
	 */
	@RequestMapping(name="고지서 외주 파일 생성", value=METHOD_URL.makeNhtOutsourcing)
	public ModelAndView makeNhtOutsourcing(String[] crdnIds, Sndng sndng, FimsPrintOption printOption) {
		UserInfo userInfo = currentUser();
		ogdpBean.initUserInfo(userInfo);

		sndng.setSggCd((String)userInfo.getInfo().get("sggCd"));

		SprtQuery sprtQuery = new SprtQuery()
			.setCrdnIds(crdnIds);

		//발송 등록
		List<DataObject> dataObjectList0 = integrationSearchMapper.selectIntegrationDataList(sprtQuery);
		SndbQuery sndbQuery = new SndbQuery()
			.setCrdnIds(crdnIds);
		sndng.setSndngSeCd("03");
		sndng.setTnocs(crdnIds.length);
		sndng.setGramt(CmmnUtil.sumByKey(dataObjectList0, "FFNLG_AMT"));

		String today = dateFormats.format("yyyyMMdd", System.currentTimeMillis());
		sndng.setSndngYmd(today);

		sndbQuery
			.setSggCd(sndng.getSggCd())
			.setTaskSeCd(sndng.getTaskSeCd());
		DataObject advntceYmdInfo = taskBean.getAdvntceYmdInfo(sndbQuery);
		String sndngEndYmd = CmmnUtil.addDay(today, toInt(advntceYmdInfo.get("ADVNTCE_DAY_CNT")));
		sndng.setSndngEndYmd(sndngEndYmd);

		DataObject first = dataObjectList0.get(0);
		sndng.setTtlNm(first.string("TASK_SE_NM")+" "+first.string("VLTN_ARTCL")+" "+"고지서");

		sndng.setRsndYn("N");
		String insertSndngResult = sndngBean.createAdvntceSndngList(sndbQuery, sndng).getMessage();
		if(insertSndngResult.contains("[F]"))
			throw new RuntimeException(insertSndngResult);

		//발송 등록 후 출력대상조회
		List<DataObject> dataObjectList = integrationSearchMapper.selectIntegrationDataList(sprtQuery);
		String taskSeCd = "";
		for(int i=0; i < dataObjectList.size(); i++) {
			DataObject sndngDtl = integrationSearchMapper.selectLatestSndngDtlInfo(dataObjectList.get(i).string("CRDN_ID"));
			dataObjectList.get(i).set("SNDNG_DTL_ID",sndngDtl.string("SNDNG_DTL_ID"));
			dataObjectList.get(i).set("SNDNG_YMD",sndngDtl.string("SNDNG_YMD"));
			dataObjectList.get(i).set("OPNN_RANGE",
					dataObjectList.get(i).string("SNDNG_YMD")+"~"+dataObjectList.get(i).string("DUDT_YMD"));
			dataObjectList.get(i).set("RG_NO",sndngDtl.string("RG_NO"));
		}

		for(int i=0; i < dataObjectList.size(); i++) {
			DataObject dataObject = dataObjectList.get(i);

			if(taskSeCd.equals("")) {
				taskSeCd = dataObject.string("TASK_SE_CD");
			}

			FileQuery fileQuery = new FileQuery()
				.setInfoType(Crdn.INF_TYPE)
				.setInfoKeys(dataObject.string("CRDN_ID"));
			List<DataObject> fileInfoList = fileBean.getFileList(fileQuery);

			if(fileInfoList != null) {
				int crdnPhotoCnt = fileInfoList.size();
				for(int j=0; j < fileInfoList.size(); j++) {
					DataObject fileInfo = fileInfoList.get(j);

					dataObject.set("CRDN_PHOTO"+(j+1), fileInfo.string("FILE_PATH"));
					dataObject.set("CRDN_PHOTO"+(j+1)+"KEY", fileInfo.string("FILE_ID"));
					List<DataObject> mosSet = mediaBean.getMosaicList(fileInfo.string("FILE_ID"));
					if(mosSet != null) {
						for(int k=0; k < mosSet.size(); k++) {
							dataObject.set("MOS"+fileInfo.string("FILE_ID"), mosSet);
						}
					}
				}
				dataObject.set("CRDN_PHOTO_CNT", crdnPhotoCnt);
			} else {
				dataObject.set("CRDN_PHOTO_CNT", 0);
			}

		}

		OutsourcingStngQuery stngQuery = new OutsourcingStngQuery()
			.setSndngSeCd("03")
			.setSggCd(currentUser().getOrgID())
			.setTaskSeCd(taskSeCd);
		List<DataObject> printStngItems = outsourcingStngBean.getArtclStngList(stngQuery);

		OutsourcingFileMaker osMaker = new OutsourcingFileMaker("고지서", printOption, printStngItems, dataObjectList);
		Map<String, Object> result = osMaker.makeFile();

		return new ModelAndView("downloadView")
			.addAllObjects(result);
	}
}