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

import incheon.com.cmm.ComDefaultVO;
import incheon.com.security.vo.LoginVO;
import incheon.res.rdm.oe.seol.service.RdmOeSeolService;
import incheon.res.rdm.oe.seol.vo.RdmOeSeol;
import incheon.res.rdm.oe.seol.vo.RdmOeSeolVO;
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 java.util.List;


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

	@Resource
    private RdmOeSeolService rdmOeSeolService;

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


	/**
	 * @MethodDESC : 새올민원행정접수 목록
	 */
	@RequestMapping(value = "/RdmOeSeolL010.do")

	public String selectSeolList(@ModelAttribute("loginUser") LoginVO loginVO, @RequestParam(defaultValue = "1") int pageIndex, @ModelAttribute RdmOeSeolVO vo, ModelMap model)
	  throws Exception{
		String bzentyInstMngNo = loginVO.getRoadMngInstCd();
		vo.setBzentyInstMngNo(bzentyInstMngNo.substring(0,3));

		/*페이징*/
		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 = rdmOeSeolService.selectSeolList(vo);

        model.addAttribute("resultList", resultList);

        int totCnt = rdmOeSeolService.countSeol(vo);
        paginationInfo.setTotalRecordCount(totCnt);

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

		return "res/rdm/oe/seol/RdmOeSeolL010";
	}


	/**
	 * @MethodDESC : 새올민원행정 상세정보
	 */
	@RequestMapping("/RdmOeSeolR010.do")
    public String	selectSeol(@ModelAttribute("rdmOeSeolVO") RdmOeSeolVO vo,
            ModelMap model) throws Exception {

		RdmOeSeol result	= rdmOeSeolService.selectSeol(vo);
		model.addAttribute("result", result);
		model.addAttribute("searchVo", vo);

        return "res/rdm/oe/seol/RdmOeSeolR010";
    }



}