package com.sooka.module.web.cms;

import com.github.pagehelper.PageInfo;
import com.sooka.component.lucene.util.IndexObject;
import com.sooka.module.web.cms.service.ContentService;
import com.sooka.module.web.cms.vo.TCmsContentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;


/**
 * Description:内容管理控制器
 *
 *
 * @create 2017-04-17
 **/
@Controller
@RequestMapping("/system/cms/rdjt")
public class RdjtController {


    @Autowired
    private ContentService contentService;

    @RequestMapping
    public String index() {
        return "cms/rdjt";
    }


    /**
     * 走进润德
     * @return
     */
    @RequestMapping("/goRD")
    public String cxcNews() {
        return "www/xylh/news";
    }


    /**
     * 去新闻列表页面
     * @return
     */
    @RequestMapping("/cxcList")
    public String selectBzgf(@RequestParam(value = "pageCurrent",defaultValue = "1") Integer pageNumber,
                             @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize, Long category_id,Model model){
        TCmsContentVo c= new TCmsContentVo();
        c.setCategoryId(category_id);
        PageInfo p = contentService.pages(pageNumber,pageSize,c);
        List<IndexObject> list;
        if(p!=null){
            list = p.getList();
            model.addAttribute("model",list);
            model.addAttribute("total",p.getTotal());//总数
            model.addAttribute("pagesize",p.getPageSize());//页数
            model.addAttribute("pagenum",p.getPageNum());
            model.addAttribute("category_id",category_id);
        }else {
            list = new ArrayList<>();
            model.addAttribute("model",list);
            model.addAttribute("total",1);//总数
            model.addAttribute("pagesize",1);//页数
            model.addAttribute("pagenum",1);
            model.addAttribute("category_id",category_id);
        }
        return "www/xylh/list";
    }

}
