package com.fs.store.controller;

import java.util.List;

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

/**
 * 素材分组Controller
 *
 * @author fs
 * @date 2022-03-15
 */
@RestController
@RequestMapping("/store/materialGroup")
public class FsMaterialGroupController extends BaseController
{
    @Autowired
    private IFsMaterialGroupService fsMaterialGroupService;

    /**
     * 查询素材分组列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FsMaterialGroup fsMaterialGroup)
    {
        startPage();
        List<FsMaterialGroup> list = fsMaterialGroupService.selectFsMaterialGroupList(fsMaterialGroup);
        return getDataTable(list);
    }

    /**
     * 导出素材分组列表
     */
    @Log(title = "素材分组", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsMaterialGroup fsMaterialGroup)
    {
        List<FsMaterialGroup> list = fsMaterialGroupService.selectFsMaterialGroupList(fsMaterialGroup);
        ExcelUtil<FsMaterialGroup> util = new ExcelUtil<>(FsMaterialGroup.class);
        return util.exportExcel(list, "materialGroup");
    }

    /**
     * 获取素材分组详细信息
     */
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") Long groupId)
    {
        return AjaxResult.success(fsMaterialGroupService.selectFsMaterialGroupById(groupId));
    }

    /**
     * 新增素材分组
     */
    @Log(title = "素材分组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsMaterialGroup fsMaterialGroup)
    {
        return toAjax(fsMaterialGroupService.insertFsMaterialGroup(fsMaterialGroup));
    }

    /**
     * 修改素材分组
     */
    @Log(title = "素材分组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsMaterialGroup fsMaterialGroup)
    {
        return toAjax(fsMaterialGroupService.updateFsMaterialGroup(fsMaterialGroup));
    }

    /**
     * 删除素材分组
     */
    @Log(title = "素材分组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable Long[] groupIds)
    {
        return toAjax(fsMaterialGroupService.deleteFsMaterialGroupByIds(groupIds));
    }

    @GetMapping("/getAllList")
    public R getAllList(FsMaterialGroup fsMaterialGroup)
    {
        List<FsMaterialGroup> list = fsMaterialGroupService.selectFsMaterialGroupList(fsMaterialGroup);
        return R.ok().put("data",list);
    }
}
