package incheon.res.rdm.oe.gfc.web;

import incheon.com.cmm.ComDefaultVO;
import incheon.com.security.vo.LoginVO;
import incheon.res.rdm.oe.gfc.service.RdmOeGfcService;
import incheon.res.rdm.oe.gfc.vo.RdmOeGfc;
import incheon.res.rdm.oe.gfc.vo.RdmOeGfcVO;
import org.egovframe.rte.fdl.property.EgovPropertyService;
import org.egovframe.rte.ptl.mvc.tags.ui.pagination.PaginationInfo;
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.bind.annotation.SessionAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Calendar;
import java.util.Date;
import java.util.List;


@Controller
@SessionAttributes(types = ComDefaultVO.class)
@RequestMapping("${api.rps-path}")
public class RdmOeGfcController{

	@Resource
    private RdmOeGfcService rdmOeGfcService;

    @Resource(name = "propertiesService")
    protected EgovPropertyService propertiesService;


	/**
	 * @MethodDESC : 수수료정보 목록
	 */
	@RequestMapping(value = "/RdmOeGfcL010.do")
	public String selectGfcList(@ModelAttribute("loginUser") LoginVO loginVO, @RequestParam(defaultValue = "1") int pageIndex, @ModelAttribute RdmOeGfcVO vo, ModelMap model)
	  throws Exception{

		vo.setMngInstCd(loginVO.getRoadMngInstCd());

		String strDatSe = vo.getStrDatSe();
		String endDatSe = vo.getEndDatSe();

		if(vo.getStrDatSe() == null || vo.getStrDatSe().equals("")){
			Calendar cal = Calendar.getInstance();
			cal.setTime(new Date());
			cal.add(cal.MONTH, -2);
			strDatSe = new java.text.SimpleDateFormat ("yyyyMMdd").format(cal.getTime());
			vo.setStrDatSe(strDatSe);

			Calendar cal2 = Calendar.getInstance();
			cal2.setTime(new Date());
			cal2.add(cal.MONTH, 1);
			endDatSe = new java.text.SimpleDateFormat ("yyyyMMdd").format(cal2.getTime());
			vo.setStrDatSe(endDatSe);
		}
		
		vo.setStrDatSe(strDatSe.replaceAll("-", ""));
		vo.setEndDatSe(endDatSe.replaceAll("-", ""));

		/*페이징*/
		vo.setPageIndex(pageIndex);

		PaginationInfo paginationInfo = new PaginationInfo();
		paginationInfo.setCurrentPageNo(pageIndex);
		paginationInfo.setRecordCountPerPage(vo.getRecordCountPerPage());
		paginationInfo.setPageSize(vo.getPageSize());

		vo.setFirstIndex(paginationInfo.getFirstRecordIndex());
		vo.setLastIndex(paginationInfo.getLastRecordIndex());
		vo.setRecordCountPerPage(paginationInfo.getRecordCountPerPage());

        List resultList = rdmOeGfcService.selectG4fcList(vo);

        model.addAttribute("resultList", resultList);

        int totCnt = rdmOeGfcService.countG4fc(vo);
        paginationInfo.setTotalRecordCount(totCnt);

        model.addAttribute("paginationInfo", paginationInfo);
        model.addAttribute("searchVo", vo);

		return "res/rdm/oe/gfc/RdmOeGfcL010";
	}


	/**
	 * @MethodDESC : 수수료정보 상세정보
	 */
	@RequestMapping("/RdmOeGfcR010.do")
    public String	selectGfc(HttpServletRequest request, @ModelAttribute("rdmOeGfcVO") RdmOeGfcVO vo,
            ModelMap model) throws Exception {

		RdmOeGfc result	= rdmOeGfcService.selectG4fc(vo);
		model.addAttribute("result", result);
		model.addAttribute("searchVo", vo);

        return "res/rdm/oe/gfc/RdmOeGfcR010";
    }

}