package com.yc.education.controller.admin;

import com.yc.education.model.Designs;
import com.yc.education.model.Designsen;
import com.yc.education.service.DesignsService;
import com.yc.education.service.DesignsenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @program: hsa
 * @description:
 * @author: hgueng
 * @create: 2019-11-14 10:54
 **/

@Controller
public class DesignsController {

    @Autowired
    private DesignsService designsService;

    @Autowired
    private DesignsenService designsenService;

    //查找所有的关于汉思
    @RequestMapping("admin/designs_list.html")
    public String designsList(Model model){
        List<Designs> list = designsService.findDesignsAll();
        model.addAttribute("list", list);
        return "admin/designs_list";
    }

    //查找所有的关于汉思
    @RequestMapping("admin/designs_list_en.html")
    public String designsListEn(Model model){
        List<Designsen> listen = designsenService.findDesignsAll();
        model.addAttribute("list", listen);
        return "adminEn/designs_list";
    }

    //添加关于汉思界面跳转
    @RequestMapping("admin/add_designs.html")
    public String addDesigns(){
        return "admin/add_designs";
    }

    //添加关于汉思界面跳转
    @RequestMapping("admin/add_designs_en.html")
    public String addDesignsEn(){
        return "adminEn/add_designs";
    }

    //提交关于汉思的内容
    @RequestMapping("admin/submit_addDesigns.html")
    public String submitAddDesigns(Designs designs){
        designsService.save(designs);
        return "redirect: designs_list.html";
    }

    //提交关于汉思的内容
    @RequestMapping("admin/submit_addDesigns_en.html")
    public String submitAddDesignsEn(Designsen designsen){
        designsenService.save(designsen);
        return "redirect: designs_list_en.html";
    }

    //根据id编辑关于汉斯的内筒
    @RequestMapping("admin/update_designs.html")
    public String updateDesigns(Model model,Integer pid){
        Designs designs = designsService.selectByKey(pid);
        model.addAttribute("designs", designs);
        return "admin/update_designs";
    }

    //根据id编辑关于汉斯的内筒
    @RequestMapping("admin/update_designs_en.html")
    public String updateDesignsEn(Model model,Integer pid){
        Designsen designsen = designsenService.selectByKey(pid);
        model.addAttribute("designs", designsen);
        return "adminEn/update_designs";
    }

    //提交编辑后的关于汉思
    @RequestMapping("admin/submit_upDesigns.html")
    public String submitUpDesigns(Designs designs){
        designsService.updateNotNull(designs);
        return "redirect: designs_list.html";
    }

    //提交编辑后的关于汉思
    @RequestMapping("admin/submit_upDesigns_en.html")
    public String submitUpDesignsEn(Designsen designsen){
        designsenService.updateNotNull(designsen);
        return "redirect: designs_list_en.html";
    }

    //根据id删除关于汉思的简介
    @RequestMapping(value = "/admin/delete_designs.html",method = RequestMethod.POST)
    @ResponseBody
    public String deleteDesigns(Integer pid){
        int num = designsService.delete(pid);
        if (num > 0) {
            return "ok";
        } else {
            return "error";
        }
    }

    //根据id删除关于汉思的简介
    @RequestMapping(value = "/admin/delete_designs_en.html",method = RequestMethod.POST)
    @ResponseBody
    public String deleteDesignsEn(Integer pid){
        int num = designsenService.delete(pid);
        if (num > 0) {
            return "ok";
        } else {
            return "error";
        }
    }


}
