package com.fs.store.controller;

import java.util.List;

import com.fs.common.core.domain.R;
import com.fs.store.param.FsShippingTemplatesAddEditParam;
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.FsShippingTemplates;
import com.fs.store.service.IFsShippingTemplatesService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 运费模板Controller
 * 
 * @author fs
 * @date 2022-03-15
 */
@RestController
@RequestMapping("/store/shippingTemplates")
public class FsShippingTemplatesController extends BaseController
{
    @Autowired
    private IFsShippingTemplatesService fsShippingTemplatesService;

    /**
     * 查询运费模板列表
     */
    @PreAuthorize("@ss.hasPermi('store:shippingTemplates:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsShippingTemplates fsShippingTemplates)
    {
        startPage();
        fsShippingTemplates.setIsDel(0);
        List<FsShippingTemplates> list = fsShippingTemplatesService.selectFsShippingTemplatesList(fsShippingTemplates);
        return getDataTable(list);
    }

    /**
     * 导出运费模板列表
     */
    @PreAuthorize("@ss.hasPermi('store:shippingTemplates:export')")
    @Log(title = "运费模板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsShippingTemplates fsShippingTemplates)
    {
        List<FsShippingTemplates> list = fsShippingTemplatesService.selectFsShippingTemplatesList(fsShippingTemplates);
        ExcelUtil<FsShippingTemplates> util = new ExcelUtil<FsShippingTemplates>(FsShippingTemplates.class);
        return util.exportExcel(list, "shippingTemplates");
    }

    /**
     * 获取运费模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:shippingTemplates:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsShippingTemplatesService.selectFsShippingTemplatesById(id));
    }

    /**
     * 新增运费模板
     */
    @PreAuthorize("@ss.hasPermi('store:shippingTemplates:add')")
    @Log(title = "运费模板", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody FsShippingTemplatesAddEditParam param)
    {
        return fsShippingTemplatesService.addOrEdit(param);
    }
    /**
     * 修改运费模板
     */
    @PreAuthorize("@ss.hasPermi('store:shippingTemplates:edit')")
    @Log(title = "运费模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody FsShippingTemplatesAddEditParam param)
    {
        return fsShippingTemplatesService.addOrEdit(param);
    }
    /**
     * 删除运费模板
     */
    @PreAuthorize("@ss.hasPermi('store:shippingTemplates:remove')")
    @Log(title = "运费模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsShippingTemplatesService.deleteFsShippingTemplatesByIds(ids));
    }

    @GetMapping("/getAllList")
    public R getAllList(FsShippingTemplates fsShippingTemplates)
    {
        fsShippingTemplates.setIsDel(0);
        List<FsShippingTemplates> list = fsShippingTemplatesService.selectFsShippingTemplatesList(fsShippingTemplates);
        return R.ok().put("data",list);
    }
}
