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.QwTagGroup;
import com.fs.qw.service.IQwTagGroupService;
import com.fs.qw.vo.QwTagGroupAddParam;
import com.fs.qw.vo.QwTagGroupListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企微客户标签组Controller
 *
 * @author fs
 * @date 2024-06-20
 */
@RestController
@RequestMapping("/qw/tagGroup")
public class QwTagGroupController extends BaseController
{
    @Autowired
    private IQwTagGroupService qwTagGroupService;

    @Autowired
    private RedisTemplate redisTemplate;

    /**
    * 所有标签列表
    */
    @GetMapping("/allList")
    public TableDataInfo allList(QwTagGroup qwTagGroup)
    {
        startPage();

        List<QwTagGroupListVO> list = qwTagGroupService.selectQwTagGroupListVO(qwTagGroup);
        return getDataTable(list);
    }

    /**
     * 所有标签列表（无分页）
     * @param qwTagGroup
     * @return
     */
    @GetMapping("/getAllList")
    public TableDataInfo getAllList(QwTagGroup qwTagGroup)
    {
        List<QwTagGroupListVO> list = qwTagGroupService.selectQwTagGroupListVO(qwTagGroup);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('qw:tagGroup:sync')")
    @Log(title = "同步标签", businessType = BusinessType.INSERT)
    @PostMapping("/syncTag/{corpId}")
    public R syncTag(@PathVariable("corpId") String corpId)
    {

        return qwTagGroupService.syncQwTagGroup(corpId);
    }
    /**
     * 查询企微客户标签组列表
     */
    @PreAuthorize("@ss.hasPermi('qw:tagGroup:list')")
    @GetMapping("/list")
    public TableDataInfo list(QwTagGroup qwTagGroup)
    {
        startPage();

        List<QwTagGroupListVO> list = qwTagGroupService.selectQwTagGroupListVO(qwTagGroup);
        return getDataTable(list);
    }
    /**
     * 获取企微客户标签组详细信息
     */
//    @PreAuthorize("@ss.hasPermi('qw:tagGroup:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(qwTagGroupService.selectQwTagGroupByIdVO(id));
    }
    /**
     * 删除企微客户标签组
     */
    @PreAuthorize("@ss.hasPermi('qw:tagGroup:remove')")
    @Log(title = "企微客户标签组", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable Long[] ids)
    {

        return qwTagGroupService.deleteQwTagGroupByIds(ids);
    }
    /**
     * 新增企微客户标签组
     */
    @PreAuthorize("@ss.hasPermi('qw:tagGroup:add')")
    @Log(title = "企微客户标签组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QwTagGroupAddParam qwTagGroup)
    {

        return toAjax(qwTagGroupService.insertQwTagGroupParam(qwTagGroup));
    }
    /**
     * 修改企微客户标签组
     */
    @PreAuthorize("@ss.hasPermi('qw:tagGroup:edit')")
    @Log(title = "企微客户标签组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QwTagGroupAddParam qwTagGroup)
    {

        return toAjax(qwTagGroupService.updateQwTagGroupParam(qwTagGroup));
    }
    /**
     * 导出企微客户标签组列表
     */
    @PreAuthorize("@ss.hasPermi('qw:tagGroup:export')")
    @Log(title = "企微客户标签组", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QwTagGroup qwTagGroup)
    {

        List<QwTagGroup> list = qwTagGroupService.selectQwTagGroupList(qwTagGroup);
        ExcelUtil<QwTagGroup> util = new ExcelUtil<QwTagGroup>(QwTagGroup.class);
        return util.exportExcel(list, "企微客户标签组数据");
    }
}
