package com.caimei.www.controller.unlimited;

import com.caimei.www.controller.BaseController;
import com.caimei.www.pojo.JsonModel;
import com.caimei.www.pojo.content.PageContent;
import com.caimei.www.pojo.content.PageFloor;
import com.caimei.www.service.InstrumentService;
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;


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

	private static final String INSTRUMENT_SEARCH_PATH = "instrument/search";
	private static final String INSTRUMENT_DETAIL_PATH = "instrument/detail";

    private InstrumentService instrumentService;
    @Autowired
    public void setInstrumentService(InstrumentService instrumentService) {
        this.instrumentService = instrumentService;
    }


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

    /**
     * 项目仪器详情页
     */
    @GetMapping("/instrument/detail.html")
    public String home(final Model model, @RequestParam("id") Integer instrumentId) {
        PageContent detail = instrumentService.getInstrumentById(instrumentId);
        model.addAttribute("instrument", detail);
        return INSTRUMENT_DETAIL_PATH;
    }

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

}
