package com.fs.oms.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.oms.domain.OmsProductCategory;
import com.fs.oms.service.IOmsProductCategoryService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 商品分类Controller
 * 
 * @author oms
 * @date 2023-06-09
 */
@RestController
@RequestMapping("/oms/category")
public class OmsProductCategoryController extends BaseController
{
    @Autowired
    private IOmsProductCategoryService omsProductCategoryService;

    /**
     * 查询商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('oms:category:list')")
    @GetMapping("/list")
    public AjaxResult list(OmsProductCategory omsProductCategory)
    {
        List<OmsProductCategory> list = omsProductCategoryService.selectOmsProductCategoryList(omsProductCategory);
        return AjaxResult.success(list);
    }

    /**
     * 导出商品分类列表
     */
    @PreAuthorize("@ss.hasPermi('oms:category:export')")
    @Log(title = "商品分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OmsProductCategory omsProductCategory)
    {
        List<OmsProductCategory> list = omsProductCategoryService.selectOmsProductCategoryList(omsProductCategory);
        ExcelUtil<OmsProductCategory> util = new ExcelUtil<OmsProductCategory>(OmsProductCategory.class);
        return util.exportExcel(list, "category");
    }

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

    /**
     * 新增商品分类
     */
    @PreAuthorize("@ss.hasPermi('oms:category:add')")
    @Log(title = "商品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmsProductCategory omsProductCategory)
    {
        return toAjax(omsProductCategoryService.insertOmsProductCategory(omsProductCategory));
    }

    /**
     * 修改商品分类
     */
    @PreAuthorize("@ss.hasPermi('oms:category:edit')")
    @Log(title = "商品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmsProductCategory omsProductCategory)
    {
        return toAjax(omsProductCategoryService.updateOmsProductCategory(omsProductCategory));
    }

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

    @GetMapping("/getAllList")
    public R getAllList(OmsProductCategory omsProductCategory)
    {
        omsProductCategory.setIsShow(1);
        omsProductCategory.setIsDel(0);
        List<OmsProductCategory> list = omsProductCategoryService.selectOmsProductCategoryList(omsProductCategory);
        return R.ok().put("data", list);
    }
}
