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.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.hisStore.domain.FsStoreProductTemplateScrm;
import com.fs.hisStore.service.IFsStoreProductTemplateScrmService;
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-15
 */
@RestController
@RequestMapping("/store/store/storeProductTemplate")
public class FsStoreProductTemplateScrmController extends BaseController
{
    @Autowired
    private IFsStoreProductTemplateScrmService fsStoreProductTemplateService;

    /**
     * 查询商品模板列表
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductTemplate:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsStoreProductTemplateScrm fsStoreProductTemplate)
    {
        startPage();
        List<FsStoreProductTemplateScrm> list = fsStoreProductTemplateService.selectFsStoreProductTemplateList(fsStoreProductTemplate);
        return getDataTable(list);
    }

    /**
     * 导出商品模板列表
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductTemplate:export')")
    @Log(title = "商品模板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsStoreProductTemplateScrm fsStoreProductTemplate)
    {
        List<FsStoreProductTemplateScrm> list = fsStoreProductTemplateService.selectFsStoreProductTemplateList(fsStoreProductTemplate);
        ExcelUtil<FsStoreProductTemplateScrm> util = new ExcelUtil<FsStoreProductTemplateScrm>(FsStoreProductTemplateScrm.class);
        return util.exportExcel(list, "storeProductTemplate");
    }

    /**
     * 获取商品模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductTemplate:query')")
    @GetMapping(value = "/{tempId}")
    public AjaxResult getInfo(@PathVariable("tempId") Long tempId)
    {
        return AjaxResult.success(fsStoreProductTemplateService.selectFsStoreProductTemplateById(tempId));
    }

    /**
     * 新增商品模板
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductTemplate:add')")
    @Log(title = "商品模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsStoreProductTemplateScrm fsStoreProductTemplate)
    {
        return toAjax(fsStoreProductTemplateService.insertFsStoreProductTemplate(fsStoreProductTemplate));
    }

    /**
     * 修改商品模板
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductTemplate:edit')")
    @Log(title = "商品模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsStoreProductTemplateScrm fsStoreProductTemplate)
    {
        return toAjax(fsStoreProductTemplateService.updateFsStoreProductTemplate(fsStoreProductTemplate));
    }

    /**
     * 删除商品模板
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductTemplate:remove')")
    @Log(title = "商品模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tempIds}")
    public AjaxResult remove(@PathVariable Long[] tempIds)
    {
        return toAjax(fsStoreProductTemplateService.deleteFsStoreProductTemplateByIds(tempIds));
    }
}
