package com.yc.education.controller.user;

import com.yc.education.model.Classify01;
import com.yc.education.model.Classify02;
import com.yc.education.model.Designs;
import com.yc.education.model.Product;
import com.yc.education.service.Classify01Service;
import com.yc.education.service.Classify02Service;
import com.yc.education.service.DesignsService;
import com.yc.education.service.ProductService;
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.RequestParam;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

@Controller
public class ProductsWapController {

    @Autowired
    private Classify01Service classify01Service;

    @Autowired
    private Classify02Service classify02Service;

    @Autowired
    private ProductService productService;

    @Autowired
    private DesignsService designsService;

    //查找所属的产品
    @RequestMapping("project_list_wap.html")
    public String projectList(@RequestParam(value="cid",defaultValue="0")Integer cid,
                              @RequestParam(value="wid",defaultValue="0")Integer wid, Model model){
        List<Product> list = productService.findProductByPid(cid,wid,null,null,null);
        model.addAttribute("list",list);
        List<Classify01> list01 = classify01Service.findAllClass01();
        model.addAttribute("list01",list01);
        if(cid!=0){
            List<Classify02> list02 = classify02Service.findClassByCid(cid);
            model.addAttribute("list02",list02);
        }
        model.addAttribute("cid",cid);
        model.addAttribute("wid",wid);
        model.addAttribute("type",1);
        if(cid!=0){
            Classify01 classify01 = classify01Service.selectByKey(cid);
            model.addAttribute("type_s",classify01);
        }
        /*if(wid!=0){
            Classify02 classify02 = classify02Service.selectByKey(wid);
            model.addAttribute("type_ss",classify02);
        }*/
        if(cid==0&&wid==0){
            Map<String,String> map = new HashMap<>();
            map.put("a","经典案例");
            map.put("b","Classic Case");
            model.addAttribute("type_sss",map);
        }
        return "hsawap/project_list_wap";
    }

    //根据id查找商品详情
    @RequestMapping("projects_wap.html")
    public String projects(Integer pid,Model model){
        Product product = productService.selectByKey(pid);
        model.addAttribute("product",product);
        model.addAttribute("type",1);
        Classify01 classify01 = classify01Service.selectByKey(product.getCid());
        model.addAttribute("type_s",classify01);
        Classify02 classify02 = classify02Service.selectByKey(product.getWid());
        if(classify02!=null){
            model.addAttribute("type_ss",classify02);
        }
        return "hsawap/projects_wap";
    }


    //根据pid查找关于汉思
    @RequestMapping("designs_wap.html")
    public String designs(Integer pid,Model model){
        Designs designs;
        List<Designs> list = designsService.findDesignsAll();
        if(pid==0){
            designs = list.get(0);
        }else{
            designs = designsService.selectByKey(pid);
        }
        model.addAttribute("designs",designs);
        model.addAttribute("list",list);
        model.addAttribute("type",2);
        return "hsawap/designs_wap";
    }

    //联系我们的静态界面
    @RequestMapping("contact_wap.html")
    public String contact(Model model){
        model.addAttribute("type",4);
        Map<String,String> map = new HashMap<>();
        map.put("a","联系我们");
        map.put("b","Contact HSa");
        model.addAttribute("type_sss",map);
        return "hsawap/contact_wap";
    }


}
