package com.example.his.api.front.controller;

import cn.hutool.core.bean.BeanUtil;
import com.example.his.api.common.result.R;

import com.example.his.api.db.pojo.GoodsSnapshotEntity;
import com.example.his.api.front.service.GoodsService;
import com.example.his.api.req.FrontGoods.GoodsByPartIdForm;
import com.example.his.api.req.FrontGoods.GoodsSearchForm;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;

@RestController("FrontGoodsController")
@RequestMapping("/front/goods")
public class GoodsController {

    @Resource
    private GoodsService goodsService;


    // 体检套餐-查询id
    @GetMapping("/searchGoodsById")
    public R searchGoodsById(@RequestParam Integer id) {
        HashMap goods = goodsService.searchGoodsById(id);
        return R.success(goods);
    }


    // 体检套餐-推荐内容
    @PostMapping("/searchGoodsByPartId")
    public R searchGoodsByPartId(@RequestBody @Valid GoodsByPartIdForm form) {
        Map map = BeanUtil.beanToMap(form);
        HashMap partIdMap = goodsService.searchGoodsByPartId(map);
        return R.success(partIdMap);
    }

    // 体检套餐-查询商品
    @PostMapping("/searchGoodsByPage")
    public R searchGoodsByPage(@RequestBody @Valid GoodsSearchForm form) {
        Map map = BeanUtil.beanToMap(form);
        PageInfo<HashMap> list = goodsService.searchGoodsByPage(map);
        return R.success(list);
    }

    // 查询商品快照
    @GetMapping("/searchSnapshotById")
    public R searchSnapshotById(@RequestParam String snapShotId) {
        HashMap map = goodsService.searchSnapshotById(snapShotId);
        return R.success(map);
    }
}
