package com.fs.store.controller;

import java.util.List;
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.FsStoreProductTemplate;
import com.fs.store.service.IFsStoreProductTemplateService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 商品模板Controller
 * 
 * @author fs
 * @date 2022-03-15
 */
@RestController
@RequestMapping("/store/storeProductTemplate")
public class FsStoreProductTemplateController extends BaseController
{
    @Autowired
    private IFsStoreProductTemplateService fsStoreProductTemplateService;

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

    /**
     * 导出商品模板列表
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductTemplate:export')")
    @Log(title = "商品模板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsStoreProductTemplate fsStoreProductTemplate)
    {
        List<FsStoreProductTemplate> list = fsStoreProductTemplateService.selectFsStoreProductTemplateList(fsStoreProductTemplate);
        ExcelUtil<FsStoreProductTemplate> util = new ExcelUtil<FsStoreProductTemplate>(FsStoreProductTemplate.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 FsStoreProductTemplate fsStoreProductTemplate)
    {
        return toAjax(fsStoreProductTemplateService.insertFsStoreProductTemplate(fsStoreProductTemplate));
    }

    /**
     * 修改商品模板
     */
    @PreAuthorize("@ss.hasPermi('store:storeProductTemplate:edit')")
    @Log(title = "商品模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsStoreProductTemplate 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));
    }
}
