package com.controller;



import com.entity.EmergencyResources;
import com.entity.News;
import com.service.*;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 *  通用控制类
 * @ignore
 * @Author:Alcedo QQ:815657032
 * @Date 2020/4/15 11:05
 */
@Controller
public class CommonController {
    @Resource
    private UsersService usersService;
    @Resource
    private NewsService newsService;
    @Resource
    private ResourcesTypeService resourcesTypeService;
    @Resource
    private EmergencyResourcesService emergencyResourcesService;



    /*通用方法*/
   public void commonMethod( ModelMap map){
        Map<String,Object> uMap = new HashMap<>();
        map.put("ulist",usersService.getAll(uMap));

       Map<String,Object> yMap = new HashMap<>();
       yMap.put("utype","普通用户");
       map.put("yhlist",usersService.getAll(yMap));


        Map<String,Object> tMap = new HashMap<>();
        map.put("tlist",resourcesTypeService.getAll(tMap));

        map.put("glist",emergencyResourcesService.getAll(null));
        map.put("flist",resourcesTypeService.getAll(null));


    }

    //	首页内容
    @RequestMapping("admin/welcome.do")
    public String showWelcome(ModelMap map){
        List<EmergencyResources> rList = emergencyResourcesService.getAll(null);
        List<News> newslist=newsService.getByPage(null);
        map.put("rlist", rList);
        map.put("nlist", newslist);
        return "admin/welcome";
    }


    //	主显示内容
    @RequestMapping("index.do")
    public String showIndex(ModelMap map){
        Map<String, Object> pmap=new HashMap<String,Object>();
        Map<String, Object> pmap2=new HashMap<String,Object>();
        Map<String, Object> jzmap=new HashMap<String,Object>();
        Map<String, Object> zkmap=new HashMap<>();
        pmap.put("pageno", 0);
        pmap.put("pageSize", 4);

        pmap2.put("pageno", 0);
        pmap2.put("pageSize", 10);

        jzmap.put("pageno", 0);
        jzmap.put("pageSize", 12);
        jzmap.put("status", "上架");

        zkmap.put("pageno", 0);
        zkmap.put("pageSize", 12);

        List<News> list=newsService.getByPage(pmap);

        commonMethod(map);

        map.put("nlist", list);

        return "index2";
    }







}
