package com.fs.store.controller;

import java.util.List;

import com.fs.common.core.domain.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.store.domain.FsStoreProductCategory;
import com.fs.store.service.IFsStoreProductCategoryService;
import com.fs.common.utils.poi.ExcelUtil;

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

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

    /**
     * 导出商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductCategory:export')")
    @Log(title = "商品分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsStoreProductCategory fsStoreProductCategory)
    {
        List<FsStoreProductCategory> list = fsStoreProductCategoryService.selectFsStoreProductCategoryList(fsStoreProductCategory);
        ExcelUtil<FsStoreProductCategory> util = new ExcelUtil<FsStoreProductCategory>(FsStoreProductCategory.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 FsStoreProductCategory fsStoreProductCategory)
    {
        return toAjax(fsStoreProductCategoryService.insertFsStoreProductCategory(fsStoreProductCategory));
    }

    /**
     * 修改商品分类
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductCategory:edit')")
    @Log(title = "商品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsStoreProductCategory 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(FsStoreProductCategory fsStoreProductCategory)
    {
        fsStoreProductCategory.setIsShow(1);
        fsStoreProductCategory.setIsDel(0);
        List<FsStoreProductCategory> list = fsStoreProductCategoryService.selectFsStoreProductCategoryList(fsStoreProductCategory);
        return R.ok().put("data", list);
    }
}
