package com.yc.education.controller.admin;/**
 * huangpan
 * 2019/10/14
 * energy
 */

import com.github.pagehelper.PageInfo;
import com.yc.education.model.Contactclassify;
import com.yc.education.model.Contactus;
import com.yc.education.service.ContactclassifyService;
import com.yc.education.service.ContacusService;
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.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 *@ClassName ContactusController
 *@Description TODO
 *@Author QuZhangJing
 *@Date 2019/10/14 18:37
 *@Version 1.0
 */
@Controller
@RequestMapping("/admin/")
public class ContactusController {
    @Autowired
    ContacusService contacusService;
    @Autowired
    ContactclassifyService contactclassifyService;
    /*查询信息*/
    @RequestMapping("contactus-list.html")
    public ModelAndView getContacus(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum ,
                                    @RequestParam(value = "pageSize",defaultValue = "12") Integer pageSize){
        ModelAndView modelAndView=new ModelAndView();
        List<Contactus> contacus = contacusService.getContacus(pageNum,pageSize);
        modelAndView.addObject("contacus", new PageInfo<>(contacus));
        List<Contactclassify> cclassify = contactclassifyService.getCclassify();
        modelAndView.addObject("cclassify", cclassify);
        return modelAndView;
    }
    /*查询单条信息*/
    @RequestMapping("contacusById.html")
    public ModelAndView contacusById(Integer id){
        ModelAndView modelAndView=new ModelAndView("admin/contacus-sel.html");
        Contactus contacusById = contacusService.getContacusById(id);
        modelAndView.addObject("contacusById", contacusById);
        return modelAndView;
    }
    /*删除信息*/
    @RequestMapping("delConacusById.html")
    @ResponseBody
    public void delConacusById(Integer id){
        contacusService.delContacusById(id);
    }
}
