package com.yc.education.controller;

import com.yc.education.model.NewsCenter;
import com.yc.education.model.NewsType;
import com.yc.education.model.SuccessCase;
import com.yc.education.service.INewsCenterService;
import com.yc.education.service.INewsTypeService;
import com.yc.education.service.ISuccessCaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 好菜网站 首页控制层
 * @author Hickey
 * @create 2019-07-23 9:11
 */
@Controller
public class HomePageController {

    @Autowired
    private INewsTypeService iNewsTypeService;

    @Autowired
    private INewsCenterService iNewsCenterService;

    @Autowired
    private  ISuccessCaseService iSuccessCaseService;

    /**
     * 前台 网站首页展示
     * @return
     */
    @RequestMapping("index.html")
    public ModelAndView showHomePage(Integer id){

        ModelAndView mav = new ModelAndView();

        NewsType  findId =  iNewsTypeService.listIdByWeight();//查询类别中权重最大的类别id,传给新闻中心界面
        mav.addObject("findId",findId);

        List<SuccessCase>   listCaseByState  = iSuccessCaseService.findCaseByState();//查询所有推荐的信息
        mav.addObject("listCaseByState",listCaseByState);

        List<NewsType>  newsType   =  iNewsTypeService.listAllType();//主页左下角展示新闻类别和新闻信息
        //将所有类别遍历  根据类别id查询该类别下的所有信息  并通过newstype实体类的setter方法把所有信息值赋给newsCenterList(List) 前台遍历
        for (NewsType type:newsType) {
            List<NewsCenter> listAllNews = iNewsCenterService.listAllNews(type.getId()); //根据新闻类别id查询所有该类别下的新闻
            type.setNewsCenterList(listAllNews);
    }
        mav.addObject("newsType",newsType);

        //首页轮播图  根据想要展示某个类别案例的推荐案例 来进行查询    根据条件查询所有推荐案例(typeid=1)    此处查餐饮装修下的推荐案例
        List<SuccessCase> listCaseByCondition  =  iSuccessCaseService.listCaseByCondition();
        mav.addObject("listCaseByCondition",listCaseByCondition);


        return  mav;
    }



}
