package com.fs.qw.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.qw.domain.QwMaterial;
import com.fs.qw.domain.QwMaterialGroup;
import com.fs.qw.service.IQwMaterialGroupService;
import com.fs.qw.service.IQwMaterialService;
import com.fs.store.domain.FsMaterialGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 企微功能账号管理Controller
 *
 * @author fs
 * @date 2023-08-23
 */
@RestController
@RequestMapping("/qw/materialGroup")
public class QwMaterialGroupController extends BaseController
{
    @Autowired
    private IQwMaterialGroupService qwMaterialGroupService;

    /**
     * 查询企微素材分组列表
     */
    @PreAuthorize("@ss.hasPermi('system:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(QwMaterialGroup qwMaterialGroup)
    {
        startPage();
        List<QwMaterialGroup> list = qwMaterialGroupService.selectQwMaterialGroupList(qwMaterialGroup);
        return getDataTable(list);
    }

    /**
     * 导出企微素材分组列表
     */
    @PreAuthorize("@ss.hasPermi('system:group:export')")
    @Log(title = "企微素材分组", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QwMaterialGroup qwMaterialGroup)
    {
        List<QwMaterialGroup> list = qwMaterialGroupService.selectQwMaterialGroupList(qwMaterialGroup);
        ExcelUtil<QwMaterialGroup> util = new ExcelUtil<QwMaterialGroup>(QwMaterialGroup.class);
        return util.exportExcel(list, "group");
    }

    /**
     * 获取企微素材分组详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:group:query')")
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") Long groupId)
    {
        return AjaxResult.success(qwMaterialGroupService.selectQwMaterialGroupById(groupId));
    }

    /**
     * 新增企微素材分组
     */
    @PreAuthorize("@ss.hasPermi('system:group:add')")
    @Log(title = "企微素材分组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QwMaterialGroup qwMaterialGroup)
    {
        return toAjax(qwMaterialGroupService.insertQwMaterialGroup(qwMaterialGroup));
    }

    /**
     * 修改企微素材分组
     */
    @PreAuthorize("@ss.hasPermi('system:group:edit')")
    @Log(title = "企微素材分组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QwMaterialGroup qwMaterialGroup)
    {
        return toAjax(qwMaterialGroupService.updateQwMaterialGroup(qwMaterialGroup));
    }

    /**
     * 删除企微素材分组
     */
    @PreAuthorize("@ss.hasPermi('system:group:remove')")
    @Log(title = "企微素材分组", businessType = BusinessType.DELETE)
    @DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable Long[] groupIds)
    {
        return toAjax(qwMaterialGroupService.deleteQwMaterialGroupByIds(groupIds));
    }

    @GetMapping("/getAllList")
    public R getAllList(QwMaterialGroup qwMaterialGroup)
    {
        List<QwMaterialGroup> list = qwMaterialGroupService.selectQwMaterialGroupList(qwMaterialGroup);
        return R.ok().put("data",list);
    }

}
