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

import incheon.com.cmm.ComDefaultVO;
import incheon.com.security.vo.LoginVO;
import incheon.res.rdm.oe.levy.service.RdmOeLevyService;
import incheon.res.rdm.oe.levy.vo.RdmOeLevy;
import incheon.res.rdm.oe.levy.vo.RdmOeLevyVO;
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 RdmOeLevyController{

	@Resource
    private RdmOeLevyService rdmOeLevyService;

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


	/**
	 * @MethodDESC : 세입수입부과 정보 목록
	 */
	@RequestMapping(value = "/RdmOeLevyL010.do")

	public String selectLevyList(@ModelAttribute("loginUser") LoginVO loginVO,
								 @RequestParam(defaultValue = "1") int pageIndex, @ModelAttribute RdmOeLevyVO 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 = rdmOeLevyService.selectLevyList(vo);

        model.addAttribute("resultList", resultList);

        int totCnt = rdmOeLevyService.countLevy(vo);
        paginationInfo.setTotalRecordCount(totCnt);

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

		return "res/rdm/oe/levy/RdmOeLevyL010";
	}


	/**
	 * @MethodDESC : 세입수입부과 상세정보
	 */
	@RequestMapping("/RdmOeLevyR010.do")
    public String	selectLevy(@ModelAttribute("rdmOeLevyVO") RdmOeLevyVO vo,
            ModelMap model) throws Exception {

		RdmOeLevy result	= rdmOeLevyService.selectLevy(vo);
		model.addAttribute("result", result);
		model.addAttribute("searchVo", vo);

        return "res/rdm/oe/levy/RdmOeLevyR010";
    }



}