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

import com.baidu.ueditor.ActionEnter;
import com.baidu.ueditor.define.ActionMap;
import com.baidu.ueditor.define.BaseState;
import com.yc.education.model.Foot;
import com.yc.education.service.FootService;
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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *@ClassName FootController
 *@Description TODO
 *@Author QuZhangJing
 *@Date 2019/10/24 10:03
 *@Version 1.0
 */
@Controller
public class FootController {
    @Autowired
    FootService footService;

    /*查询页面*/
    @RequestMapping("admin/foot-list.html")
    public ModelAndView getfoot(){
        ModelAndView modelAndView =new ModelAndView();
        Foot foots = footService.getFoots();
        modelAndView.addObject("foots", foots);
        return modelAndView;
    }
    /*查询单条*/
     @RequestMapping("admin/footById.html")
    public ModelAndView footById(Integer id){
         Foot footById = footService.getFootById(id);
     ModelAndView modelAndView=new ModelAndView("admin/foot-update");
     modelAndView.addObject("footById", footById);
     return modelAndView;
     }
     /*执行修改*/
    @RequestMapping("admin/foot-update.html")
    public void updateFoot(Foot foot, HttpServletRequest request, HttpServletResponse response)throws  Exception{
        String rootPath = request.getSession().getServletContext().getRealPath("/");
        String contextPath = request.getSession().getServletContext().getContextPath();
        BaseState state = (BaseState) new ActionEnter(request, rootPath, contextPath, "img").invoke(ActionMap.UPLOAD_FILE);
        String url = state.getInfo("url");
        if (url!=null&&!url.equals("")){
            foot.setWechatqrcode(url);
        }
        footService.updateNotNull(foot);
        response.sendRedirect("foot-list.html");
    }
}
