package com.fs.company.controller.qw;

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.enums.BusinessType;
import com.fs.common.utils.ServletUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.framework.security.LoginUser;
import com.fs.framework.service.TokenService;
import com.fs.qw.domain.QwGroupchatStatistic;
import com.fs.qw.param.QwGroupchatStatisticParams;
import com.fs.qw.service.IQwGroupchatStatisticService;
import com.fs.qw.vo.QwGroupchatStatisticVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企微群聊数据统计数据Controller
 *
 * @author qw
 * @date 2024-08-05
 */
@RestController
@RequestMapping("/qw/statistic")
public class QwGroupchatStatisticController extends BaseController
{
    @Autowired
    private IQwGroupchatStatisticService qwGroupchatStatisticService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询企微群聊数据统计数据列表
     */
    @PreAuthorize("@ss.hasPermi('qw:statistic:list')")
    @GetMapping("/list")
    public R list(QwGroupchatStatisticParams params)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long companyId = loginUser.getCompany().getCompanyId();
        params.setCompanyid(companyId);

        return qwGroupchatStatisticService.selectQwGroupchatStatisticList(params);
    }

    /**
     * 导出企微群聊数据统计数据列表
     */
    @PreAuthorize("@ss.hasPermi('qw:statistic:export')")
    @Log(title = "企微群聊数据统计数据", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QwGroupchatStatisticParams params)
    {
        R data = qwGroupchatStatisticService.selectQwGroupchatStatisticList(params);
        ExcelUtil<QwGroupchatStatisticVO> util = new ExcelUtil<QwGroupchatStatisticVO>(QwGroupchatStatisticVO.class);
        return util.exportExcel((List<QwGroupchatStatisticVO>) data.get("list"), "企微群聊数据统计数据数据");
    }

    /**
     * 获取企微群聊数据统计数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('qw:statistic:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(qwGroupchatStatisticService.selectQwGroupchatStatisticById(id));
    }

    /**
     * 新增企微群聊数据统计数据
     */
    @PreAuthorize("@ss.hasPermi('qw:statistic:add')")
    @Log(title = "企微群聊数据统计数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QwGroupchatStatistic qwGroupchatStatistic)
    {
        return toAjax(qwGroupchatStatisticService.insertQwGroupchatStatistic(qwGroupchatStatistic));
    }

    /**
     * 修改企微群聊数据统计数据
     */
    @PreAuthorize("@ss.hasPermi('qw:statistic:edit')")
    @Log(title = "企微群聊数据统计数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QwGroupchatStatistic qwGroupchatStatistic)
    {
        return toAjax(qwGroupchatStatisticService.updateQwGroupchatStatistic(qwGroupchatStatistic));
    }

    /**
     * 删除企微群聊数据统计数据
     */
    @PreAuthorize("@ss.hasPermi('qw:statistic:remove')")
    @Log(title = "企微群聊数据统计数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qwGroupchatStatisticService.deleteQwGroupchatStatisticByIds(ids));
    }
}
