package com.fs.hisStore.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.domain.R;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.hisStore.domain.FsStoreProductCategoryScrm;
import com.fs.hisStore.service.IFsStoreProductCategoryScrmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品分类Controller
 *
 * @author fs
 * @date 2022-03-16
 */
@RestController
@RequestMapping("/store/store/storeProductCategory")
public class FsStoreProductCategoryScrmController extends BaseController
{
    @Autowired
    private IFsStoreProductCategoryScrmService fsStoreProductCategoryService;

    /**
     * 查询商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductCategory:list')")
    @GetMapping("/list")
    public AjaxResult list(FsStoreProductCategoryScrm fsStoreProductCategory)
    {
        List<FsStoreProductCategoryScrm> list = fsStoreProductCategoryService.selectFsStoreProductCategoryList(fsStoreProductCategory);
        return AjaxResult.success(list);
    }

    /**
     * 导出商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductCategory:export')")
    @Log(title = "商品分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsStoreProductCategoryScrm fsStoreProductCategory)
    {
        List<FsStoreProductCategoryScrm> list = fsStoreProductCategoryService.selectFsStoreProductCategoryList(fsStoreProductCategory);
        ExcelUtil<FsStoreProductCategoryScrm> util = new ExcelUtil<FsStoreProductCategoryScrm>(FsStoreProductCategoryScrm.class);
        return util.exportExcel(list, "storeProductCategory");
    }

    /**
     * 获取商品分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductCategory:query')")
    @GetMapping(value = "/{cateId}")
    public AjaxResult getInfo(@PathVariable("cateId") Long cateId)
    {
        return AjaxResult.success(fsStoreProductCategoryService.selectFsStoreProductCategoryById(cateId));
    }

    /**
     * 新增商品分类
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductCategory:add')")
    @Log(title = "商品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsStoreProductCategoryScrm fsStoreProductCategory)
    {
        return toAjax(fsStoreProductCategoryService.insertFsStoreProductCategory(fsStoreProductCategory));
    }

    /**
     * 修改商品分类
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductCategory:edit')")
    @Log(title = "商品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsStoreProductCategoryScrm fsStoreProductCategory)
    {
        return toAjax(fsStoreProductCategoryService.updateFsStoreProductCategory(fsStoreProductCategory));
    }

    /**
     * 删除商品分类
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductCategory:remove')")
    @Log(title = "商品分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cateIds}")
    public AjaxResult remove(@PathVariable Long[] cateIds)
    {
        return toAjax(fsStoreProductCategoryService.deleteFsStoreProductCategoryByIds(cateIds));
    }

    @GetMapping("/getAllList")
    public R getAllList(FsStoreProductCategoryScrm fsStoreProductCategory)
    {
        fsStoreProductCategory.setIsShow(1);
        fsStoreProductCategory.setIsDel(0);
        List<FsStoreProductCategoryScrm> list = fsStoreProductCategoryService.selectFsStoreProductCategoryList(fsStoreProductCategory);
        return R.ok().put("data", list);
    }
}
