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.QwUserbehaviorData;
import com.fs.qw.param.QwUserbehaviorDataParams;
import com.fs.qw.service.IQwUserbehaviorDataService;
import com.fs.qw.vo.QwUserbehaviorDataVO;
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 fs
 * @date 2024-08-05
 */
@RestController
@RequestMapping("/qw/userBehaviorData")
public class QwUserbehaviorDataController extends BaseController
{
    @Autowired
    private IQwUserbehaviorDataService qwUserbehaviorDataService;

    @Autowired
    private TokenService tokenService;

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

        return qwUserbehaviorDataService.selectQwUserbehaviorDataList(params);
    }

    /**
     * 导出企微联系客户统计数据列表
     */
    @PreAuthorize("@ss.hasPermi('qw:userBehaviorData:export')")
    @Log(title = "企微联系客户统计数据", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QwUserbehaviorDataParams params)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long companyId = loginUser.getCompany().getCompanyId();
        params.setCompanyid(companyId);

        R data = qwUserbehaviorDataService.selectQwUserbehaviorDataList(params);

        ExcelUtil<QwUserbehaviorDataVO> util = new ExcelUtil<QwUserbehaviorDataVO>(QwUserbehaviorDataVO.class);
        return util.exportExcel((List<QwUserbehaviorDataVO>) data.get("list"), "企微联系客户统计数据数据");
    }

    /**
     * 获取企微联系客户统计数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('qw:userBehaviorData:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(qwUserbehaviorDataService.selectQwUserbehaviorDataById(id));
    }

    /**
     * 新增企微联系客户统计数据
     */
    @PreAuthorize("@ss.hasPermi('qw:userBehaviorData:add')")
    @Log(title = "企微联系客户统计数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QwUserbehaviorData qwUserbehaviorData)
    {
        return toAjax(qwUserbehaviorDataService.insertQwUserbehaviorData(qwUserbehaviorData));
    }

    /**
     * 修改企微联系客户统计数据
     */
    @PreAuthorize("@ss.hasPermi('qw:userBehaviorData:edit')")
    @Log(title = "企微联系客户统计数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QwUserbehaviorData qwUserbehaviorData)
    {
        return toAjax(qwUserbehaviorDataService.updateQwUserbehaviorData(qwUserbehaviorData));
    }

    /**
     * 删除企微联系客户统计数据
     */
    @PreAuthorize("@ss.hasPermi('qw:userBehaviorData:remove')")
    @Log(title = "企微联系客户统计数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qwUserbehaviorDataService.deleteQwUserbehaviorDataByIds(ids));
    }
}
