package kcg.faics.report.web;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;

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

import kcg.faics.cmmn.excel.ExcelExporter;
import kcg.faics.cmmn.service.CodeService;
import kcg.faics.member.service.MemberAuthService;
import kcg.faics.member.service.MemberService;
import kcg.faics.member.vo.MemberVO;
import kcg.faics.report.service.ReportCategoryService;
import kcg.faics.report.service.ReportJudgeService;
import kcg.faics.report.service.ReportService;
import kcg.faics.report.vo.ReportSearchVO;
import kcg.faics.report.vo.ReportVO;
import kcg.faics.sec.LoginUserVO;
import kcg.faics.sec.UserUtil;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.support.SessionStatus;
import org.springmodules.validation.commons.DefaultBeanValidator;

import egovframework.rte.fdl.property.EgovPropertyService;
import egovframework.rte.ptl.mvc.tags.ui.pagination.PaginationInfo;
/**
 * @author 하영지
 * 견문 검색 컨트롤러
 */
@Controller
@RequestMapping("/report")
public class ReportListController {
	/**
	 * properties값을 가져오는 인터페이스.
	 **/
	@Resource(name = "propertiesService")
	private EgovPropertyService propertiesService;

	/**
	 * 사용자 권한 관련 서비스.
	 */
	@Resource(name = "memberAuthService")
	private MemberAuthService memberAuthService;
	
	/**
	 * 견문 기본 인터페이스이다. 
	 */
	@Resource(name = "reportService")
	private ReportService reportService;

	/**
	 * 견문 결재 인터페이스 
	 */
	@Resource(name = "reportJudgeService")
	private ReportJudgeService judgeService;
	
	/**
	 * 사용자 인터페이스
	 */
	@Resource(name = "memberService")
	private MemberService memberService;
	
	/**
	 * Validator - 유효성 검사
	 **/
	@Resource(name = "beanValidator")
	private DefaultBeanValidator beanValidator;

	/**
	 * 코드 인터페이스
	 */
	@Resource(name = "codeService")
	private CodeService codeService;

	/**
	 * 견문 분류 인터페이스
	 */
	@Resource(name = "reportCategoryService")
	private ReportCategoryService cateService;
	
	/**
	 * message.properties의 값을 가져오는 인터페이스.
	 */
	@Autowired
	private MessageSource messageSource;
	
	/**
	 * 견문 검색 화면을 반환한다.
	 * 
	 * @param reportSearchVO 견문 검색 객체
	 * @param model 모델객체
	 * @return 견문검색화면
	 * @throws Exception 기본예외처리
	 */
	@RequestMapping(value = "/search.do")
	public String search(final ReportSearchVO reportSearchVO, final Model model) throws Exception {
		try {
			//분류 1,2,3,4
			model.addAttribute("category1", cateService.getCategory1());
			model.addAttribute("category2", cateService.getCategory2());
			model.addAttribute("category3", cateService.getCategory3());
			model.addAttribute("category4", cateService.getCategory4());

			int myGroupCode = ReportCommon.getMyGroupCode();
			model.addAttribute("myGroupCode", myGroupCode);
			
			switch (myGroupCode) {
			case 3:
				model.addAttribute("placeList", codeService.getPlace1List(false));
				break;
			case 2:
				model.addAttribute("placeList", codeService.getPlace1SubListWithMain(UserUtil.getMemberInfo().getPlace1()));
				break;
			default:
				model.addAttribute("myPlaceCode", UserUtil.getMemberInfo().getPlace1());
				model.addAttribute("myPlaceName", UserUtil.getMemberInfo().getPlace1Str());
				break;
			}
			
			model.addAttribute("judgeList", judgeService.selectJudgeCode());
			
			model.addAttribute("reportSearchVO", reportSearchVO);
			
		} catch (Exception e) {
		}
		return "report/search.tiles";
	}

	/**
	 * 견문 검색 결과 화면을 반환한다.
	 * 
	 * @param reportSearchVO 견문 검색 객체
	 * @param model 모델객체
	 * @param request 리퀘스트객체
	 * @param status 상태 객체
	 * @return 견문검색결과화면
	 * @throws Exception 기본예외처리
	 */
	@RequestMapping(value = "/searchResult.do")
	public String search(@ModelAttribute final ReportSearchVO reportSearchVO, final Model model,
			final HttpServletRequest request, final SessionStatus status) throws Exception {
		try {
			//분류 1,2,3,4
			model.addAttribute("category1", cateService.getCategory1());
			model.addAttribute("category2", cateService.getCategory2());
			model.addAttribute("category3", cateService.getCategory3());
			model.addAttribute("category4", cateService.getCategory4());
			//소속
			model.addAttribute("placeList", codeService.getPlace1List(false));
			// 접속한 사용자의 그룹코드
			model.addAttribute("myGroupCode", ReportCommon.getMyGroupCode());

			/* 페이징 처리 정보 */
			reportSearchVO.setPageUnit(propertiesService.getInt("pageUnit"));
			reportSearchVO.setPageSize(propertiesService.getInt("pageSize"));

			/* 페이징 처리 */
			PaginationInfo paginationInfo = new PaginationInfo();
			paginationInfo.setCurrentPageNo(reportSearchVO.getPageIndex());
			paginationInfo.setRecordCountPerPage(reportSearchVO.getRecordCountPerPage());
			paginationInfo.setPageSize(reportSearchVO.getPageSize());

			reportSearchVO.setFirstIndex(paginationInfo.getFirstRecordIndex());
			reportSearchVO.setLastIndex(paginationInfo.getLastRecordIndex());
			reportSearchVO.setRecordCountPerPage(paginationInfo.getRecordCountPerPage());
			
			ReportSearchVO vo = ReportCommon.setSearchUserInfo(reportSearchVO); 
			// 전체 갯수 설정
			int totSearchCnt = reportService.selectListCnt(vo);
			paginationInfo.setTotalRecordCount(totSearchCnt);
			model.addAttribute("paginationInfo", paginationInfo);

			/* 게시판 상단 페이지 및 게시물 정보 표현을 위한 데이터 */
			int totCnt = reportService.selectTotalCnt(vo);
			model.addAttribute("totalCnt", totCnt);
			List<ReportVO> reportList = reportService.selectList(ReportCommon.setSearchUserInfo(vo));
			model.addAttribute("reportList", reportList);
			
			// 검색 조건
			model.addAttribute("reportSearchVO", vo);
			// 평가 목록
			model.addAttribute("judgeList", judgeService.judgeList());
			
			return "report/reportList.tiles";
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return search(reportSearchVO, model);
	}
	

	/**
	 * 검색결과의 전체목록을 엑셀로 내보낸다.
	 * 
	 * @param reportSearchVO 견문 검색 객체
	 * @param model Model 객체
	 * @param locale Locale 객체
	 * @return 엑셀(전체목록)
	 * @throws Exception 기본 예외 처리
	 */
	@RequestMapping(value = "/listtoexcel.do")
	public String exportExcel(@ModelAttribute final ReportSearchVO reportSearchVO, final Model model, final Locale locale) throws Exception {
		LinkedHashMap<String, String> header = new LinkedHashMap<String, String>();
		header.put("docNo", messageSource.getMessage("report.list.num", null, locale));
		header.put("reporter", messageSource.getMessage("report.search.reporter", null, locale));
		header.put("inSubject", messageSource.getMessage("board.header.title", null, locale));
		header.put("inInfodate", messageSource.getMessage("report.view.infodate", null, locale));
		header.put("judgeStr", messageSource.getMessage("report.view.appraisal", null, locale));
		header.put("fullReportStr", messageSource.getMessage("report.type.fullReport", null, locale));
		header.put("inCategory1Str", messageSource.getMessage("report.view.category1", null, locale));
		header.put("inCategory2Str", messageSource.getMessage("report.view.category2", null, locale));
		header.put("inCategory3Str", messageSource.getMessage("report.view.category3", null, locale));
		header.put("inCategory4Str", messageSource.getMessage("report.view.category4", null, locale));
		try {
			Date d = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
			String title = String.format("%s_%s", messageSource.getMessage("report.title", null, locale), sdf.format(d));
			
			List<ReportVO> list = reportService.selectListAll(ReportCommon.setSearchUserInfo(reportSearchVO));
			
			model.addAttribute("excel", new ExcelExporter<ReportVO>(header, list, title));
			model.addAttribute("filename", title);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return "excelView";
	}

	/**
	 * 결재 대기 목록 화면을 반환한다.
	 * 
	 * @param reportSearchVO 견문 검색 객체
	 * @param model 모델객체
	 * @param request 리퀘스트객체
	 * @param status 상태 객체
	 * @return 견문 결재대기목록 화면
	 * @throws Exception 기본예외처리
	 */
	@RequestMapping(value = "/waitList.do")
	public String waitList(@ModelAttribute final ReportSearchVO reportSearchVO, final Model model,
			final HttpServletRequest request, final SessionStatus status) throws Exception {
		try {
			//분류 1,2,3,4
			model.addAttribute("category1", cateService.getUseCategory1());
			model.addAttribute("category2", cateService.getUseCategory2());
			model.addAttribute("category3", cateService.getUseCategory3());
			model.addAttribute("category4", cateService.getUseCategory4());
			//소속
			model.addAttribute("placeList", codeService.getPlace1List(false));
			// 접속한 사용자 정보
			model.addAttribute("myGroupCode", ReportCommon.getMyGroupCode());

			/* 페이징 처리 정보 */
			reportSearchVO.setPageUnit(propertiesService.getInt("pageUnit"));
			reportSearchVO.setPageSize(propertiesService.getInt("pageSize"));

			/* 페이징 처리 */
			PaginationInfo paginationInfo = new PaginationInfo();
			paginationInfo.setCurrentPageNo(reportSearchVO.getPageIndex());
			paginationInfo.setRecordCountPerPage(reportSearchVO.getRecordCountPerPage());
			paginationInfo.setPageSize(reportSearchVO.getPageSize());

			reportSearchVO.setFirstIndex(paginationInfo.getFirstRecordIndex());
			reportSearchVO.setLastIndex(paginationInfo.getLastRecordIndex());
			reportSearchVO.setRecordCountPerPage(paginationInfo.getRecordCountPerPage());
			
			ReportSearchVO vo = ReportCommon.setSearchUserInfo(reportSearchVO);

			// 권한 설정
			LoginUserVO loginUserVO = UserUtil.getMemberInfo();
			int myDutiesCode = ReportCommon.getDutiesCodeForApprove(loginUserVO.getDuties());
			vo.setDutiesForApprove(myDutiesCode);
			model.addAttribute("myDutiesCode", myDutiesCode);
			
			// 전체 갯수 설정
			int totSearchCnt = judgeService.selectWaitListCnt(vo);
			paginationInfo.setTotalRecordCount(totSearchCnt);
			model.addAttribute("paginationInfo", paginationInfo);
			model.addAttribute("totalCnt", totSearchCnt);

			List<ReportVO> reportList = judgeService.selectWaitList(vo);
			model.addAttribute("reportList", reportList);
			
			// 검색 조건
			model.addAttribute("reportSearchVO", vo);
			// 평가 목록
			model.addAttribute("judgeList", judgeService.judgeList());
			
			model.addAttribute("reportVO", new ReportVO());
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return "report/waitList.tiles";
	}

	/**
	 * 선택된 견문의 승인화면을 반환한다.
	 * 
	 * @param reportVO 임시 저장된 견문 객체
	 * @param model model객체
	 * @return 견문 승인 화면
	 * @throws Exception 기본예외처리
	 */
	@RequestMapping(value = "/approval.do", method = RequestMethod.GET)
	public String approvalView(@ModelAttribute("reportVO") final ReportVO reportVO, final Model model) throws Exception {
		try {
			ReportVO vo = reportService.select(reportVO);
			model.addAttribute("reportVO", vo);
			
			LoginUserVO user = UserUtil.getMemberInfo();
			model.addAttribute("loginUserVO", user);
			
			model.addAttribute("myGroupCode", ReportCommon.getMyGroupCode());
			int myDutiesCode = ReportCommon.getDutiesCodeForApprove(user.getDuties());
			model.addAttribute("myDutiesCode", myDutiesCode);
			model.addAttribute("loginPlace1", user.getPlace1Str().substring(user.getPlace1Str().length() - 2));
			
			model.addAttribute("docGroupCode", ReportCommon.getGroupCode(vo.getInPlaceCode()));
			
			model.addAttribute("ju1section", judgeService.selectOne(vo.getInJuseq1Section()));
			model.addAttribute("ju2section", judgeService.selectOne(vo.getInJuseq2Section()));
			model.addAttribute("ju3section", judgeService.selectOne(vo.getInJuseq3Section()));
			model.addAttribute("ju1head", judgeService.selectOne(vo.getInJuseq1Head()));
			model.addAttribute("ju2head", judgeService.selectOne(vo.getInJuseq2Head()));
			model.addAttribute("ju3head", judgeService.selectOne(vo.getInJuseq3Head()));
			
			//분류 1,2,3,4
			model.addAttribute("category1", cateService.getUseCategory1());
			model.addAttribute("category2", cateService.getUseCategory2());
			model.addAttribute("category3", cateService.getUseCategory3());
			model.addAttribute("category4", cateService.getUseCategory4());
			
			model.addAttribute("inUseCategory1", vo.getInUseCategory1());
			model.addAttribute("inUseCategory2", vo.getInUseCategory2());
			model.addAttribute("inUseCategory3", vo.getInUseCategory3());
			model.addAttribute("inUseCategory4", vo.getInUseCategory4());
			
			// 조회 타입
			boolean modifyProcess = (Character.getNumericValue(vo.getInStateCode().charAt(0)) > ReportCommon.getMyGroupCode() || vo.getInStateCode().charAt(1) == '4');
			boolean modifyAuth = (vo.getInUserid() != user.getUserid() && myDutiesCode < 2);
			model.addAttribute("viewDoc", (modifyProcess | modifyAuth));
			 
			model.addAttribute("approveInfo", judgeService.selectApprove());
			
			return "report/approval.tiles";
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "error/bizError";
	}

	/**
	 * 여러 개의 견문을 결재한다.
	 * 
	 * @param reportVO 견문객체
	 * @param model 모델 객체
	 * @param request 리퀘스트 객체
	 * @param status 세션객체
	 * @return 견문 대기 목록 조회
	 * @throws Exception 기본 예외 처리
	 */
	@RequestMapping(value = {"/approval.do", "/approvalList.do"}, method = RequestMethod.POST)
	public String approvalSubmit(@ModelAttribute final ReportVO reportVO, final Model model, 
			final HttpServletRequest request, final SessionStatus status) throws Exception {
		
		HashMap<String, Object> map = judgeService.approve(reportVO);  
		if (map.get("msg").toString() != "") {
			model.addAttribute("errorMsg", map.get("msg"));
			
			String requestUrl = request.getRequestURL().toString();
			if (requestUrl.indexOf("/approvalList.do") > 0) {
				return waitList(null, null, null, null);
			} else {
				return approvalView(reportVO, model);
			}
		}
		
		status.setComplete();
		
		return "redirect:/report/waitList.do";
	}
	
	/**
	 * 견문 결재 처리 목록을 반환한다.
	 * 
	 * @param reportSearchVO 견문 검색 객체
	 * @param model 모델 객체
	 * @param request 리퀘스트 객체
	 * @param status 세션 객체
	 * @return 견문 결재 처리 목록 화면
	 * @throws Exception 기본 예외 처리
	 */
	@RequestMapping(value = "approveList.do")
	public String approveList(@ModelAttribute final ReportSearchVO reportSearchVO, final Model model,
			final HttpServletRequest request, final SessionStatus status) throws Exception {
		
		LoginUserVO loginUserVO = UserUtil.getMemberInfo();
		int dutieCode = ReportCommon.getDutiesCodeForApprove(loginUserVO.getDuties());
		
		// 권한 체크
		if (dutieCode != 2 && dutieCode != 3) {
			return "redirect:/report/myList.do"; 
		}
		
		try {
			// 기간 설정
			Calendar cal = new GregorianCalendar();
			SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
			if (StringUtils.isBlank(reportSearchVO.getDateStart())) {
				cal.add(Calendar.MONTH, -1);
				reportSearchVO.setDateStart(dateFormatter.format(cal.getTime()));
			}
			if (StringUtils.isBlank(reportSearchVO.getDateEnd())) {
				cal = new GregorianCalendar();
				reportSearchVO.setDateEnd(dateFormatter.format(cal.getTime()));
			}
			
			//분류 1,2,3,4
			model.addAttribute("category1", cateService.getCategory1());
			model.addAttribute("category2", cateService.getCategory2());
			model.addAttribute("category3", cateService.getCategory3());
			model.addAttribute("category4", cateService.getCategory4());
			//소속
			model.addAttribute("placeList", codeService.getPlace1List(false));
			// 접속한 사용자 정보
			model.addAttribute("myGroupCode", ReportCommon.getMyGroupCode());
			model.addAttribute("myDutiesCode", dutieCode);

			/* 페이징 처리 정보 */
			reportSearchVO.setPageUnit(propertiesService.getInt("pageUnit"));
			reportSearchVO.setPageSize(propertiesService.getInt("pageSize"));
			
			/* 페이징 처리 */
			PaginationInfo paginationInfo = new PaginationInfo();
			paginationInfo.setCurrentPageNo(reportSearchVO.getPageIndex());
			paginationInfo.setRecordCountPerPage(15);
			paginationInfo.setPageSize(reportSearchVO.getPageSize());

			reportSearchVO.setFirstIndex(paginationInfo.getFirstRecordIndex());
			reportSearchVO.setLastIndex(paginationInfo.getLastRecordIndex());
			reportSearchVO.setRecordCountPerPage(paginationInfo.getRecordCountPerPage());
			
			ReportSearchVO vo = ReportCommon.setSearchUserInfo(reportSearchVO); 
			// 전체 갯수 설정
			int totSearchCnt = judgeService.selectApproveListCnt(vo);
			paginationInfo.setTotalRecordCount(totSearchCnt);
			model.addAttribute("paginationInfo", paginationInfo);
			model.addAttribute("totalCnt", totSearchCnt);

			List<ReportVO> reportList = judgeService.selectApproveList(vo);
			model.addAttribute("reportList", reportList);
			
			// 검색 조건
			model.addAttribute("reportSearchVO", vo);
			// 평가 목록
			model.addAttribute("judgeList", judgeService.judgeList());
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return "report/approveList.tiles";
	}
	
	/**
	 * 견문 처리 목록에 대한 엑셀 문서를 반환한다.
	 * 
	 * @param reportSearchVO 견문 검색 객체
	 * @param model Model 객체
	 * @param locale Locale 객체
	 * @return 견문 처리 목록 엑셀 문서
	 */
	@RequestMapping(value = "approveExcel")
	public String approveExcel(@ModelAttribute final ReportSearchVO reportSearchVO, final Model model, final Locale locale) {
		LinkedHashMap<String, String> header = new LinkedHashMap<String, String>();
		header.put("docNo", messageSource.getMessage("report.list.num", null, locale));
		header.put("reporter", messageSource.getMessage("report.search.reporter", null, locale));
		header.put("inSubject", messageSource.getMessage("board.header.title", null, locale));
		header.put("inInfodate", messageSource.getMessage("report.view.infodate", null, locale));
		header.put("isSection", messageSource.getMessage("report.view.approval", null, locale) 
				+ messageSource.getMessage("member.view.rptPermission.section", null, locale));
		header.put("isHead", messageSource.getMessage("report.view.approval", null, locale) 
				+ messageSource.getMessage("member.view.rptPermission.head", null, locale));
		header.put("isJudge1", messageSource.getMessage("report.type.newsflash", null, locale));
		header.put("isJudge2", messageSource.getMessage("report.type.judge", null, locale));
		header.put("isJudge3", messageSource.getMessage("report.type.middle", null, locale));
		header.put("isJudge4", messageSource.getMessage("report.type.notice", null, locale));
		header.put("isJudge5", messageSource.getMessage("report.type.record", null, locale));
		header.put("isJudge6", messageSource.getMessage("report.type.survey", null, locale));
		header.put("isJudge7", messageSource.getMessage("report.type.reference", null, locale));
		header.put("isReport1", messageSource.getMessage("report.type.fullReport1", null, locale) 
				+ messageSource.getMessage("report.type.fullReport", null, locale));
		header.put("isReport2", messageSource.getMessage("report.type.fullReport2", null, locale) 
				+ messageSource.getMessage("report.type.fullReport", null, locale));
		
		try {
			Date d = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
			String title = String.format("%s_%s", messageSource.getMessage("report.title", null, locale), sdf.format(d));
			
			List<ReportVO> list = judgeService.selectApproveListAll(ReportCommon.setSearchUserInfo(reportSearchVO));
			
			model.addAttribute("excel", new ExcelExporter<ReportVO>(header, list, title));
			model.addAttribute("filename", title);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return "excelView";
	}

	/**
	 * 내실적 목록을 반환한다.
	 * 
	 * @param reportSearchVO 견문 검색 객체
	 * @param model 모델 객체
	 * @param request 리퀘스트 객체
	 * @param status 세션 객체
	 * @return 내실적 목록 화면
	 * @throws Exception 기본 예외 처리
	 */
	@RequestMapping(value = "myList.do")
	public String myList(@ModelAttribute final ReportSearchVO reportSearchVO, final Model model,
			final HttpServletRequest request, final SessionStatus status) throws Exception {		
		try {
			LoginUserVO userVO = UserUtil.getMemberInfo();
			// 기간 설정
			Calendar cal = new GregorianCalendar();
			SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
			if (StringUtils.isBlank(reportSearchVO.getDateStart())) {
				cal.add(Calendar.YEAR, -1);
				reportSearchVO.setDateStart(dateFormatter.format(cal.getTime()));
			}
			if (StringUtils.isBlank(reportSearchVO.getDateEnd())) {
				cal = new GregorianCalendar();
				reportSearchVO.setDateEnd(dateFormatter.format(cal.getTime()));
			}
			
			//분류 1,2,3,4
			model.addAttribute("category1", cateService.getCategory1());
			model.addAttribute("category2", cateService.getCategory2());
			model.addAttribute("category3", cateService.getCategory3());
			model.addAttribute("category4", cateService.getCategory4());
			//소속
			model.addAttribute("placeList", codeService.getPlace1List(false));
			// 접속한 사용자 정보
			model.addAttribute("myGroupCode", ReportCommon.getMyGroupCode());
			model.addAttribute("myDutiesCode", ReportCommon.getDutiesCodeForApprove(userVO.getDuties()));

			/* 페이징 처리 정보 */
			reportSearchVO.setPageUnit(propertiesService.getInt("pageUnit"));
			reportSearchVO.setPageSize(propertiesService.getInt("pageSize"));
			
			/* 페이징 처리 */
			PaginationInfo paginationInfo = new PaginationInfo();
			paginationInfo.setCurrentPageNo(reportSearchVO.getPageIndex());
			paginationInfo.setRecordCountPerPage(15);
			paginationInfo.setPageSize(reportSearchVO.getPageSize());

			reportSearchVO.setFirstIndex(paginationInfo.getFirstRecordIndex());
			reportSearchVO.setLastIndex(paginationInfo.getLastRecordIndex());
			reportSearchVO.setRecordCountPerPage(paginationInfo.getRecordCountPerPage());
			
			ReportSearchVO vo = ReportCommon.setSearchUserInfo(reportSearchVO); 
			// 전체 갯수 설정
			int totSearchCnt = judgeService.selectMyListCnt(vo);
			paginationInfo.setTotalRecordCount(totSearchCnt);
			model.addAttribute("paginationInfo", paginationInfo);
			model.addAttribute("totalCnt", totSearchCnt);

			List<ReportVO> reportList = judgeService.selectMyList(vo);
			model.addAttribute("reportList", reportList);
			
			// 검색 조건
			model.addAttribute("reportSearchVO", vo);
			// 평가 목록
			model.addAttribute("judgeList", judgeService.judgeList());
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return "report/myList.tiles";
	}
	

	/**
	 * 견문 처리 목록에 대한 엑셀 문서를 반환한다.
	 * 
	 * @param reportSearchVO 견문 검색 객체
	 * @param model Model 객체
	 * @param locale Locale 객체
	 * @return 견문 처리 목록 엑셀 문서
	 */
	@RequestMapping(value = "myListExcel")
	public String myListExcel(@ModelAttribute final ReportSearchVO reportSearchVO, final Model model, final Locale locale) {
		LinkedHashMap<String, String> header = new LinkedHashMap<String, String>();
		header.put("docNo", messageSource.getMessage("report.list.num", null, locale));
		header.put("reporter", messageSource.getMessage("report.search.reporter", null, locale));
		header.put("inSubject", messageSource.getMessage("board.header.title", null, locale));
		header.put("inInfodate", messageSource.getMessage("report.view.infodate", null, locale));
		header.put("isHead", messageSource.getMessage("report.view.approval", null, locale) 
				+ messageSource.getMessage("member.view.rptPermission.head", null, locale));
		header.put("isSection", messageSource.getMessage("report.view.approval", null, locale) 
				+ messageSource.getMessage("member.view.rptPermission.section", null, locale));
		header.put("isJudge1", messageSource.getMessage("report.type.newsflash", null, locale));
		header.put("isJudge2", messageSource.getMessage("report.type.judge", null, locale));
		header.put("isJudge3", messageSource.getMessage("report.type.middle", null, locale));
		header.put("isJudge4", messageSource.getMessage("report.type.notice", null, locale));
		header.put("isJudge5", messageSource.getMessage("report.type.record", null, locale));
		header.put("isJudge6", messageSource.getMessage("report.type.survey", null, locale));
		header.put("isJudge7", messageSource.getMessage("report.type.reference", null, locale));
		header.put("isReport1", messageSource.getMessage("report.type.fullReport1", null, locale) 
				+ messageSource.getMessage("report.type.fullReport", null, locale));
		header.put("isReport2", messageSource.getMessage("report.type.fullReport2", null, locale) 
				+ messageSource.getMessage("report.type.fullReport", null, locale));
		header.put("inCategory1Str", messageSource.getMessage("report.view.category1", null, locale));
		header.put("inCategory2Str", messageSource.getMessage("report.view.category2", null, locale));
		header.put("inCategory3Str", messageSource.getMessage("report.view.category3", null, locale));
		header.put("inCategory4Str", messageSource.getMessage("report.view.category4", null, locale));
		
		try {
			Date d = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
			String title = String.format("%s_%s", messageSource.getMessage("report.title", null, locale), sdf.format(d));
			
			List<ReportVO> list = judgeService.selectMyListAll(ReportCommon.setSearchUserInfo(reportSearchVO));
			
			model.addAttribute("excel", new ExcelExporter<ReportVO>(header, list, title));
			model.addAttribute("filename", title);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return "excelView";
	}
}
