package com.fs.app.controller.live;

import com.fs.app.controller.AppBaseController;
import com.fs.common.annotation.Log;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.domain.R;
import com.fs.common.core.redis.RedisCache;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.ServletUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.his.service.IFsStoreProductService;
import com.fs.hisStore.service.IFsStoreProductScrmService;
import com.fs.live.domain.LiveGoods;
import com.fs.live.service.ILiveGoodsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 直播商品Controller
 *
 * @author fs
 * @date 2025-07-08
 */
@RestController
@RequestMapping("/app/live/liveGoods")
public class LiveGoodsController extends AppBaseController
{
    @Autowired
    private ILiveGoodsService liveGoodsService;

    @Autowired
    private IFsStoreProductScrmService fsStoreProductService;

    @Autowired
    private RedisCache redisCache;

    /**
     * 查询直播商品列表
     */
    @GetMapping("/list")
    public R list(LiveGoods liveGoods)
    {
        PageHelper.startPage(Integer.parseInt(ServletUtils.getParameter("pageNum")), Integer.parseInt(ServletUtils.getParameter("pageSize")));
        List<LiveGoods> list = liveGoodsService.selectLiveGoodsList(liveGoods);
        PageInfo<LiveGoods> listPageInfo=new PageInfo<>(list);
        return R.ok().put("data",listPageInfo);
    }

    /**
     * 导出直播商品列表
     */
    @Log(title = "直播商品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LiveGoods liveGoods)
    {
        List<LiveGoods> list = liveGoodsService.selectLiveGoodsList(liveGoods);
        ExcelUtil<LiveGoods> util = new ExcelUtil<LiveGoods>(LiveGoods.class);
        return util.exportExcel(list, "直播商品数据");
    }

    /**
     * 获取直播商品详细信息
     */
    @GetMapping(value = "/{goodsId}")
    public AjaxResult getInfo(@PathVariable("goodsId") Long goodsId)
    {
        return AjaxResult.success(liveGoodsService.selectLiveGoodsByGoodsId(goodsId));
    }

    /**
     * 新增直播商品
     */
    @Log(title = "直播商品", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody LiveGoods liveGoods)
    {
        liveGoodsService.insertLiveGoods(liveGoods);
        return R.ok();
    }

    /**
     * 修改直播商品
     */
    @Log(title = "直播商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody LiveGoods liveGoods)
    {
        return liveGoodsService.updateLiveGoods(liveGoods);
    }

    /**
     * 删除直播商品
     */
    @Log(title = "直播商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodsIds}")
    public R remove(@PathVariable Long[] goodsIds)
    {
        liveGoodsService.deleteLiveGoodsByGoodsIds(goodsIds);
        return R.ok();
    }

    /**
     * 获取直播店铺
     * */
    @GetMapping("/liveStore/{liveId}")
    public R liveGoodsStore(@PathVariable Long liveId,@RequestParam String key)
    {
        String userId = getUserId();
        return liveGoodsService.getStoreByLiveId(liveId, key, userId);
    }

    /**
     *商品详情
     */
    @GetMapping("/liveGoodsDetail/{productId}")
    public R liveGoodsDetail(@PathVariable Long productId)
    {
        return R.ok().put("data",fsStoreProductService.selectFsStoreProductById(productId));
    }

    /**
     *当前正在展示的商品
     */
    @GetMapping("/showGoods/{liveId}")
    public R showGoods(@PathVariable Long liveId)
    {
        return R.ok().put("data", liveGoodsService.showGoods(liveId));
    }


}
