package com.iamberry.wechat.handles.official;

import com.iamberry.wechat.core.entity.PaperBean;
import com.iamberry.wechat.core.entity.official.Prospectus;
import com.iamberry.wechat.face.official.ProspectusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/admin/official")
public class AdminProspectusHandler {

    @Autowired
    ProspectusService prospectusService;

    /**
     * 列表
     * @return
     * @throws Exception
     * @author LJK
     * create date : 2015年12月24日16:08:49
     */
    @RequestMapping("/prospectus_list")
    public ModelAndView listUI(@RequestParam(value="pageNO",defaultValue="1") Integer pageNO,
                               @RequestParam(value="pageSize",defaultValue="8") Integer pageSize,
                               Prospectus prospectus
                             ) throws Exception {
        ModelAndView mv = new ModelAndView("admin/official/list");

        PaperBean bean = new PaperBean();
        bean.setMinNum((pageNO-1)*pageSize);
        bean.setMaxNum(pageSize);
        prospectus.setBean(bean);
        List<Prospectus> prospectusList = prospectusService.selectProspectusPage(prospectus);

        Integer size = prospectusService.selectProspectusCount(prospectus);
        size = size/pageSize;
        if(size%pageSize > 0){
            size++;
        }
        mv.addObject("prospectusList",prospectusList);
        mv.addObject("pageNO", pageNO);
        mv.addObject("pageSize",size );
        mv.addObject("url","/admin/official/prospectus_list?pageNO=");
        return mv;
    }

    /**
     * 添加
     * @return
     * @throws Exception
     * @author LJK
     * create date : 2015年12月24日16:08:49
     */
    @RequestMapping("/to_add_prospectus")
    public ModelAndView toAddProspectus(Prospectus prospectus) throws Exception {
        ModelAndView mv = new ModelAndView("admin/official/addProspectus");
        return mv;
    }




}
