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

import com.baidu.ueditor.ActionEnter;
import com.baidu.ueditor.define.ActionMap;
import com.baidu.ueditor.define.BaseState;
import com.yc.education.model.Corporate;
import com.yc.education.service.CorporateService;
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 CorporateController
 *@Description TODO
 *@Author QuZhangJing
 *@Date 2019/10/16 9:52
 *@Version 1.0
 */
@Controller
public class CorporateController {

    @Autowired
    CorporateService corporateService;
    /*查询信息*/
    @RequestMapping("admin/corporate-list.html")
    public ModelAndView getCorporate(){
        ModelAndView modelAndView=new ModelAndView();
        Corporate corporate = corporateService.selCorprate();
        modelAndView.addObject("corporate", corporate);
        return modelAndView;
    }
    /*修改信息*/
    @RequestMapping("admin/corporateById.html")
    public ModelAndView selCorporate(){
        ModelAndView modelAndView=new ModelAndView("admin/corporate-update");
        Corporate corporate = corporateService.selCorprate();
        modelAndView.addObject("corporate", corporate);
        return modelAndView;
    }
    /*执行修改*/
    @RequestMapping("admin/corporate-update.html")
    public void updateCorporate(Corporate corporate, 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(""))
        corporate.setSurfaceplot(url);
    corporateService.updateNotNull(corporate);
    response.sendRedirect("corporate-list.html");
    }
}
