package com.fs.store.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.store.domain.FsIntegralGoods;
import com.fs.store.service.IFsIntegralGoodsService;
import com.fs.store.vo.FsIntegralGoodsListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 积分商品Controller
 *
 * @author fs
 * @date 2023-11-02
 */
@RestController
@RequestMapping("/his/integralGoods")
public class FsIntegralGoodsController extends BaseController
{
    @Autowired
    private IFsIntegralGoodsService fsIntegralGoodsService;

    /**
     * 查询积分商品列表
     */
    @PreAuthorize("@ss.hasPermi('his:integralGoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsIntegralGoods fsIntegralGoods)
    {
        startPage();
        List<FsIntegralGoodsListVO> list = fsIntegralGoodsService.selectFsIntegralGoodsListVO(fsIntegralGoods);
        return getDataTable(list);
    }

    /**
     * 导出积分商品列表
     */
    @PreAuthorize("@ss.hasPermi('his:integralGoods:export')")
    @Log(title = "积分商品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsIntegralGoods fsIntegralGoods)
    {
        List<FsIntegralGoods> list = fsIntegralGoodsService.selectFsIntegralGoodsList(fsIntegralGoods);
        ExcelUtil<FsIntegralGoods> util = new ExcelUtil<FsIntegralGoods>(FsIntegralGoods.class);
        return util.exportExcel(list, "积分商品数据");
    }

    /**
     * 获取积分商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:integralGoods:query')")
    @GetMapping(value = "/{goodsId}")
    public AjaxResult getInfo(@PathVariable("goodsId") Long goodsId)
    {
        return AjaxResult.success(fsIntegralGoodsService.selectFsIntegralGoodsByGoodsId(goodsId));
    }


    @Log(title = "商品导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<FsIntegralGoods> util = new ExcelUtil<>(FsIntegralGoods.class);
        List<FsIntegralGoods> list = util.importExcel(file.getInputStream());
        String message = fsIntegralGoodsService.importIntegralGoodsService(list);
        return AjaxResult.success(message);
    }

    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<FsIntegralGoods> util = new ExcelUtil<>(FsIntegralGoods.class);
        return util.importTemplateExcel("商品数据");
    }


    /**
     * 新增积分商品
     */
    @PreAuthorize("@ss.hasPermi('his:integralGoods:add')")
    @Log(title = "积分商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsIntegralGoods fsIntegralGoods)
    {
        return toAjax(fsIntegralGoodsService.insertFsIntegralGoods(fsIntegralGoods));
    }

    /**
     * 修改积分商品
     */
    @PreAuthorize("@ss.hasPermi('his:integralGoods:edit')")
    @Log(title = "积分商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsIntegralGoods fsIntegralGoods)
    {
        return toAjax(fsIntegralGoodsService.updateFsIntegralGoods(fsIntegralGoods));
    }

    /**
     * 删除积分商品
     */
    @PreAuthorize("@ss.hasPermi('his:integralGoods:remove')")
    @Log(title = "积分商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodsIds}")
    public AjaxResult remove(@PathVariable Long[] goodsIds)
    {
        return toAjax(fsIntegralGoodsService.deleteFsIntegralGoodsByGoodsIds(goodsIds));
    }
}
