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.FsMaterialScrm;
import com.fs.hisStore.service.IFsMaterialScrmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 素材库Controller
 *
 * @author fs
 * @date 2022-03-15
 */
@RestController
@RequestMapping("/store/store/material")
public class FsMaterialScrmController extends BaseController
{
    @Autowired
    private IFsMaterialScrmService fsMaterialService;

    /**
     * 查询素材库列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FsMaterialScrm fsMaterial)
    {
        startPage();
        List<FsMaterialScrm> list = fsMaterialService.selectFsMaterialList(fsMaterial);
        return getDataTable(list);
    }

    /**
     * 导出素材库列表
     */
    @Log(title = "素材库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsMaterialScrm fsMaterial)
    {
        List<FsMaterialScrm> list = fsMaterialService.selectFsMaterialList(fsMaterial);
        ExcelUtil<FsMaterialScrm> util = new ExcelUtil<FsMaterialScrm>(FsMaterialScrm.class);
        return util.exportExcel(list, "material");
    }

    /**
     * 获取素材库详细信息
     */
    @GetMapping(value = "/{materialId}")
    public AjaxResult getInfo(@PathVariable("materialId") Long materialId)
    {
        return AjaxResult.success(fsMaterialService.selectFsMaterialById(materialId));
    }

    /**
     * 新增素材库
     */
    @Log(title = "素材库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsMaterialScrm fsMaterial)
    {
        return toAjax(fsMaterialService.insertFsMaterial(fsMaterial));
    }

    /**
     * 修改素材库
     */
    @Log(title = "素材库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsMaterialScrm fsMaterial)
    {
        return toAjax(fsMaterialService.updateFsMaterial(fsMaterial));
    }

    /**
     * 删除素材库
     */
    @Log(title = "素材库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{materialIds}")
    public AjaxResult remove(@PathVariable Long[] materialIds)
    {
        return toAjax(fsMaterialService.deleteFsMaterialByIds(materialIds));
    }
}
