package com.fs.his.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.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;

import com.fs.common.utils.poi.ExcelUtil;
import com.fs.his.domain.FsMaterialGroup;
import com.fs.his.service.IFsMaterialGroupService;
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/materialGroup")
public class FsMaterialGroupController extends BaseController
{
    @Autowired
    private IFsMaterialGroupService fsMaterialGroupService;

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

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

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

    /**
     * 新增素材分组
     */
    @Log(title = "素材分组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsMaterialGroup fsMaterialGroup)
    {
        fsMaterialGroup.setStoreId(0L);
        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.deleteFsMaterialGroupByGroupIds(groupIds));
    }

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