package com.fs.app.controller.store;


import cn.hutool.json.JSONUtil;
import com.fs.app.annotation.Login;
import com.fs.app.controller.AppBaseController;
import com.fs.app.vo.IndexVO;
import com.fs.common.core.domain.R;
import com.fs.hisStore.domain.*;
import com.fs.hisStore.param.*;
import com.fs.hisStore.service.*;
import com.fs.hisStore.vo.*;
import com.fs.store.config.ConceptConfig;
import com.fs.system.service.ISysConfigService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.Cacheable;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Api("首页接口")
@RestController
@RequestMapping(value="/store/app/index")
public class IndexScrmController extends AppBaseController {

	@Autowired
	private IFsArticleCateScrmService articleCateService;

	@Autowired
	private IFsAdvScrmService advService;

	@Autowired
	private IFsStoreProductScrmService productService;



	@Autowired
	private IFsArticleScrmService articleService;

	@Autowired
	private IFsStoreCartScrmService cartService;
	@Autowired
	private IFsMenuScrmService menuService;
	@Autowired
	private IFsStoreCanvasScrmService storeCanvasService;
	@Autowired
	private ISysConfigService configService;
	@ApiOperation("获取首页数据")
	@GetMapping("/getIndexData")
	public R getIndexData(HttpServletRequest request){
		List<FsArticleCateListQueryVO> articleCateList=articleCateService.selectFsArticleCateListQuery();
		List<FsAdvListQueryVO> advList=advService.selectFsAdvListQuery(1);
		List<FsStoreProductListQueryVO> newProductList=productService.selectFsStoreProductNewQuery(10);
		List<FsStoreProductListQueryVO> hotProductList=productService.selectFsStoreProductHotQuery(10);
		IndexVO vo=IndexVO.builder().articleCateList(articleCateList).advList(advList).newProductList(newProductList).hotProductList(hotProductList).build();
		return R.ok().put("data", vo);
	}




	@ApiOperation("读取菜单数据")
	@GetMapping("/getMenu")
	@Cacheable("menu")
	public R getMenu(FsMenuScrm map){
		map.setIsShow(1);
		map.setMenuType(1);
		List<FsMenuScrm> list=menuService.selectFsMenuList(map);
		return R.ok().put("data",list);
	}


	@ApiOperation("读取养生有道")
	@GetMapping("/getMenuTwo")
	@Cacheable("menuTwo")
	public R getMenuTwo(HttpServletRequest request){
		FsMenuScrm map=new FsMenuScrm();
		map.setIsShow(1);
		map.setMenuType(2);
		List<FsMenuScrm> list=menuService.selectFsMenuList(map);
		return R.ok().put("data",list);
	}

	@ApiOperation("读取个人中心")
	@GetMapping("/getMenuUser")
	@Cacheable("menuUser")
	public R getMenuUser(HttpServletRequest request){
		FsMenuScrm map=new FsMenuScrm();
		map.setIsShow(1);
		map.setMenuType(3);
		List<FsMenuScrm> list=menuService.selectFsMenuList(map);
		return R.ok().put("data",list);
	}

	@ApiOperation("企业理念")
	@GetMapping("/getConcept")
	@Cacheable("getConcept")
	public R getConcept(HttpServletRequest request){
		String json=configService.selectConfigByKey("store.concept");
		ConceptConfig config = JSONUtil.toBean(json, ConceptConfig.class);
		return R.ok().put("data",config);
	}


	@ApiOperation("读取画布数据")
	@GetMapping("/getCanvas")
	@Cacheable("canvas")
	public R getCanvas(HttpServletRequest request){
		FsStoreCanvasScrm map=new FsStoreCanvasScrm();
		map.setIsDel(0);
		map.setType(1);
		List<FsStoreCanvasScrm> canvas=storeCanvasService.selectFsStoreCanvasList(map);
		if (CollectionUtils.isNotEmpty(canvas)){
			return R.ok().put("data", canvas.get(0));
		}
		return R.ok();
	}



	@ApiOperation("获取推荐健康知识")
	@GetMapping("/getTuiArticle")
	public R getTuiArticle(FsArticleQueryParam param){

		List<FsArticleListQueryVO> list=articleService.selectFsArticleListQuery(param);
		return R.ok().put("data", list);
	}


	@Login
	@ApiOperation("获取购物车数量")
	@GetMapping("/getCartCount")
	public R getCartCount(){
		Integer count=cartService.selectFsStoreCartCountByUserId(Long.parseLong(getUserId()));
		return R.ok().put("data", count);
	}

	@Autowired
	private IFsFamousPrescribeScrmService fsFamousPrescribeService;

	@Autowired
	private IFsQuestionsScrmService questionsService;

	@Autowired
	private IFsMedicatedFoodScrmService medicatedFoodService;

	@Autowired
	private IFsVesselScrmService vesselService;

	@Autowired
	private IFsChineseMedicineScrmService chineseMedicineService;

	@ApiOperation("获取名方列表")
	@GetMapping("/getFamousPrescribeList")
	public R getFamousPrescribeList(FsFamousPrescribeListUParam param)
	{
		PageHelper.startPage(param.getPageNum(), param.getPageSize());
		List<FsFamousPrescribeListUVO> list=fsFamousPrescribeService.selectFsFamousPrescribeListUVO(param);
		PageInfo<FsFamousPrescribeListUVO> listPageInfo=new PageInfo<>(list);
		return R.ok().put("data",listPageInfo);
	}

	@GetMapping("/getFamousPrescribeById")
	public R getFamousPrescribeById(@RequestParam("id")Long id)
	{
		FsFamousPrescribeScrm fsFamousPrescribe=fsFamousPrescribeService.selectFsFamousPrescribeById(id);
		return R.ok().put("data",fsFamousPrescribe);
	}
	@ApiOperation("获取问答列表")
	@GetMapping("/getQuestionsList")
	public R getQuestionsList(FsQuestionsListUParam param)
	{
		PageHelper.startPage(param.getPageNum(), param.getPageSize());
		List<FsQuestionsListUVO> list=questionsService.selectFsQuestionsListUVO(param);
		PageInfo<FsQuestionsListUVO> listPageInfo=new PageInfo<>(list);
		return R.ok().put("data",listPageInfo);
	}

	@GetMapping("/getQuestionsById")
	public R getQuestionsById(@RequestParam("id")Long id)
	{
		FsQuestionsScrm questions=questionsService.selectFsQuestionsById(id);
		return R.ok().put("data",questions);
	}
	@ApiOperation("获取穴位列表")
	@GetMapping("/getVesselList")
	public R getVesselList(FsVesselListUParam param)
	{
		PageHelper.startPage(param.getPageNum(), param.getPageSize());
		List<FsVesselListUVO> list=vesselService.selectFsVesselListUVO(param);
		PageInfo<FsVesselListUVO> listPageInfo=new PageInfo<>(list);
		return R.ok().put("data",listPageInfo);
	}

	@GetMapping("/getVesselById")
	public R getVesselById(@RequestParam("id")Long id)
	{
		FsVesselScrm vessel=vesselService.selectFsVesselById(id);
		return R.ok().put("data",vessel);
	}
	@ApiOperation("获取食谱列表")
	@GetMapping("/getMedicatedFoodList")
	public R getMedicatedFoodList(FsMedicateFoodListUParam param)
	{
		PageHelper.startPage(param.getPageNum(), param.getPageSize());
		List<FsMedicateFoodListUVO> list=medicatedFoodService.selectFsMedicatedFoodListUVO(param);
		PageInfo<FsMedicateFoodListUVO> listPageInfo=new PageInfo<>(list);
		return R.ok().put("data",listPageInfo);
	}

	@GetMapping("/getMedicatedFoodById")
	public R getMedicatedFoodById(@RequestParam("id")Long id)
	{
		FsMedicatedFoodScrm food=medicatedFoodService.selectFsMedicatedFoodById(id);
		return R.ok().put("data",food);
	}
	@ApiOperation("获取中医列表")
	@GetMapping("/getChineseMedicineList")
	public R getChineseMedicineList(FsChineseMedicineListUParam param)
	{
		PageHelper.startPage(param.getPageNum(), param.getPageSize());
		List<FsChineseMedicineListUVO> list=chineseMedicineService.selectFsChineseMedicineListUVO(param);
		PageInfo<FsChineseMedicineListUVO> listPageInfo=new PageInfo<>(list);
		return R.ok().put("data",listPageInfo);
	}

	@GetMapping("/getChineseMedicineById")
	public R getChineseMedicineById(@RequestParam("id")Long id)
	{
		FsChineseMedicineScrm chineseMedicine=chineseMedicineService.selectFsChineseMedicineById(id);
		return R.ok().put("data",chineseMedicine);
	}


}
