package com.caimei.www.controller.unlimited;

import com.caimei.www.controller.BaseController;
import com.caimei.www.pojo.JsonModel;
import com.caimei.www.pojo.page.PageContent;
import com.caimei.www.pojo.page.PageFloor;
import com.caimei.www.service.page.EquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 项目仪器(equipment)
 *
 * @author : Charles
 * @date : 2020/7/16
 */
@Controller
public class EquipmentController extends BaseController {

	private static final String equipment_LIST_PATH = "equipment/list";
	private static final String equipment_DETAIL_PATH = "equipment/detail";

    private EquipmentService equipmentService;
    @Autowired
    public void setEquipmentService(EquipmentService equipmentService) {
        this.equipmentService = equipmentService;
    }


    /**
     * 项目仪器搜索结果页
     */
    @GetMapping("/equipment/list.html")
    public String search() {
        return equipment_LIST_PATH;
    }

    /**
     * 项目仪器详情页
     */
    @GetMapping("/equipment/detail.html")
    public String home(final Model model, @RequestParam("id") Integer equipmentId) {
        PageContent detail = equipmentService.getEquipmentById(equipmentId);
        model.addAttribute("equipment", detail);
        return equipment_DETAIL_PATH;
    }

    /**
     * 获取项目仪器详情页中层信息(搭配推荐,相似商品)
     */
    @GetMapping("/equipment/recommend")
    @ResponseBody
    public JsonModel<List<PageFloor>> getEquipmentRecommendById(Integer equipmentId) {
        return equipmentService.getEquipmentRecommendById(equipmentId);
    }

}
