package com.fs.company.controller.store;

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.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.his.domain.FsStoreProductCategory;
import com.fs.his.service.IFsStoreProductCategoryService;
import com.fs.his.vo.FsStoreProductCategoryVO;
import com.fs.his.vo.FsStoreProductCategorysVO;
import com.fs.his.vo.OptionsVO;
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 2023-06-08
 */
@RestController
@RequestMapping("/store/storeProductCategory")
public class FsStoreProductCategoryController extends BaseController
{
    @Autowired
    private IFsStoreProductCategoryService fsStoreProductCategoryService;

    /**
     * 查询商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('his:storeProductCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsStoreProductCategory fsStoreProductCategory)
    {

        List<FsStoreProductCategoryVO> list = fsStoreProductCategoryService.selectFsStoreProductCategoryListVO(fsStoreProductCategory);

        return getDataTable(list);
    }
    /**
     * 查询商品父类列表
     */
    @GetMapping("pid/list")
    public AjaxResult userlist()
    {
        List<OptionsVO> list = fsStoreProductCategoryService.selectFsStoreProductPidList();
        return AjaxResult.success(list);
    }
    /**
     * 导出商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('his: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, "商品分类数据");
    }

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

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

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

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

    @GetMapping("/getAllList")
    public R getAllList(FsStoreProductCategory fsStoreProductCategory)
    {

        List<FsStoreProductCategorysVO> list = fsStoreProductCategoryService.selectFsStoreProductCategorysVOList();
        return R.ok().put("data", list);
    }

    @GetMapping("/getPidList")
    public R getPidList(FsStoreProductCategory fsStoreProductCategory)
    {

        List<FsStoreProductCategoryVO> list = fsStoreProductCategoryService.getPidList();

        return R.ok().put("data", list);
    }
}
