package com.gic.haoban.manage.web.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.JSONResponse;
import com.gic.api.base.commons.Page;
import com.gic.clerk.api.dto.AuthorizedUser;
import com.gic.commons.util.DataApiUtils;
import com.gic.commons.util.DateUtil;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.haoban.manage.web.qo.chat.SingleChatClerkReq;
import com.gic.haoban.manage.web.qo.chat.SingleChatDetailReq;
import com.gic.haoban.manage.web.qo.chat.SingleChatOverviewReq;
import com.gic.haoban.manage.web.qo.chat.SingleChatStoreGroupReq;
import com.gic.haoban.manage.web.qo.wechatwork.StoreGroupCommonQO;
import com.gic.haoban.manage.web.qo.wechatwork.WechatWorkLostClerkQO;
import com.gic.haoban.manage.web.qo.wechatwork.WechatWorkLostStoreGroupQO;
import com.gic.haoban.manage.web.utils.AuthorizedUserUtils;
import com.gic.haoban.manage.web.utils.data.ConcurrencyUtils;
import com.gic.haoban.manage.web.utils.data.MapThreadHandlerRequest;
import com.gic.haoban.manage.web.utils.data.StoreAuthUtils;
import com.gic.haoban.manage.web.vo.chat.SingleChatClerkVO;
import com.gic.haoban.manage.web.vo.chat.SingleChatDetailVO;
import com.gic.haoban.manage.web.vo.chat.SingleChatOverviewVO;
import com.gic.haoban.manage.web.vo.chat.SingleChatStoreGroupVO;
import com.gic.haoban.manage.web.vo.wechatwork.*;
import com.gic.qcloud.BucketNameEnum;
import com.gic.web.common.controller.NewBaseController;
import com.gic.web.common.download.DownloadTask;
import com.gic.web.common.download.DownloadTaskUtil;
import com.gic.web.common.download.constants.TaskTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * * 会话数据统计
 * *
 * *
 *
 * @author shangfeng
 * @date 2024-06-19 10:58:42
 */
@Slf4j
@RestController
@RequestMapping("chat-data")
public class ChatDataController extends NewBaseController {

    @Autowired
    private StoreAuthUtils storeAuthUtils;

    /**
     *  data_mbr_scale_haoban_qw_chat_count_dev
     *  data_mbr_scale_haoban_qw_chat_detail_dev
     *  data_mbr_scale_haoban_qw_chat_overview_date_dev
     *  data_mbr_scale_haoban_qw_chat_overview_dev
     *  data_mbr_scale_haoban_qw_group_chat_con_detail_dev
     *  data_mbr_scale_haoban_qw_group_chat_count_dev
     *  data_mbr_scale_haoban_qw_group_chat_date_dev
     *  data_mbr_scale_haoban_qw_group_chat_detail_dev
     *  data_mbr_scale_haoban_qw_group_chat_exit_dev
     *  data_mbr_scale_haoban_qw_group_chat_join_dev
     *  data_mbr_scale_haoban_qw_group_chat_overview_dev
     */

    /**
     * 单聊统计 会话数据概览
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping("single-chat-overview")
    public RestResponse<SingleChatOverviewVO> singleChatOverview(@RequestBody SingleChatOverviewReq req) {
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(req);
        storeAuthUtils.setCommonParam(jsonObject, new StoreGroupCommonQO().setStoreGroupId(req.getStoreGroupId()));
        Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), "data_mbr_scale_haoban_qw_chat_overview");
        List<JSONObject> list = DataApiUtils.getDataList(res);
        List<SingleChatOverviewVO> voList = JSONArray.parseArray(JSON.toJSONString(list), SingleChatOverviewVO.class);

        return RestResponse.successResult(CollectionUtils.isEmpty(voList) ? null : voList.get(0));

    }


    /**
     * 单聊统计 趋势图
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping("single-chat-overview-trend")
    public RestResponse<List<SingleChatOverviewVO>> singleChatOverviewTrend(@RequestBody SingleChatOverviewReq req) throws ParseException {

        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(req);
        storeAuthUtils.setCommonParam(jsonObject, new StoreGroupCommonQO().setStoreGroupId(req.getStoreGroupId()));

        List<MapThreadHandlerRequest> list = new ArrayList<>();
        jsonObject.put("groupType", 1);
        list.add(new MapThreadHandlerRequest(jsonObject, "data_mbr_scale_haoban_qw_chat_overview_date", "1_activeSessionsNum"));
        jsonObject.put("groupType", 2);
        list.add(new MapThreadHandlerRequest(jsonObject, "data_mbr_scale_haoban_qw_chat_overview_date", "2_custSessionsNum"));
        jsonObject.put("groupType", 3);
        list.add(new MapThreadHandlerRequest(jsonObject, "data_mbr_scale_haoban_qw_chat_overview_date", "3_replySessionsNum"));
        jsonObject.put("groupType", 4);
        list.add(new MapThreadHandlerRequest(jsonObject, "data_mbr_scale_haoban_qw_chat_overview_date", "4_replySessionsPrport"));
        jsonObject.put("groupType", 5);
        list.add(new MapThreadHandlerRequest(jsonObject, "data_mbr_scale_haoban_qw_chat_overview_date", "5_averageFirstReplyTime"));
        jsonObject.put("groupType", 6);
        list.add(new MapThreadHandlerRequest(jsonObject, "data_mbr_scale_haoban_qw_chat_overview_date", "6_sessionsCustNum"));
        jsonObject.put("groupType", 7);
        list.add(new MapThreadHandlerRequest(jsonObject, "data_mbr_scale_haoban_qw_chat_overview_date", "7_launchSessionsCustNum"));
        jsonObject.put("groupType", 8);
        list.add(new MapThreadHandlerRequest(jsonObject, "data_mbr_scale_haoban_qw_chat_overview_date", "8_launchSessionsSalesNum"));
        jsonObject.put("groupType", 9);
        list.add(new MapThreadHandlerRequest(jsonObject, "data_mbr_scale_haoban_qw_chat_overview_date", "9_sendNewsNum"));

        Map<String, List<JSONObject>> map = ConcurrencyUtils.concurrencyDataForMap(list);
        List<JSONObject> resultList = new ArrayList<>();
        if (map != null) {
            map.forEach((k, v) -> {
                if (CollectionUtils.isNotEmpty(v)) {
                    for (JSONObject tempJson : v) {
                        tempJson.put(k.substring(0, 1), tempJson.get(k.substring(2)));
                    }
                    resultList.addAll(v);
                }
            });
        }
        Map<String, List<JSONObject>> voMap = resultList.stream().collect(Collectors.groupingBy(e -> e.getString("bizDate")));

        List<String> dateList = DateUtil.getBetweenDates(req.getStartDate(), req.getEndDate());
        List<SingleChatOverviewVO> voList = new ArrayList<>();
        for (String date : dateList) {
            SingleChatOverviewVO vo = new SingleChatOverviewVO();
            vo.setBizDate(date);
            List<JSONObject> mapValue = voMap.get(date);
            if (CollectionUtils.isNotEmpty(mapValue)) {
                for (JSONObject tempJson : mapValue) {
                    if (tempJson.containsKey("1")) {
                        vo.setActiveSessionsNum(tempJson.getInteger("1"));
                    }
                    if (tempJson.containsKey("2")) {
                        vo.setCustSessionsNum(tempJson.getInteger("2"));
                    }
                    if (tempJson.containsKey("3")) {
                        vo.setReplySessionsNum(tempJson.getInteger("3"));
                    }
                    if (tempJson.containsKey("4")) {
                        vo.setReplySessionsPrport(tempJson.getInteger("4"));
                    }
                    if (tempJson.containsKey("5")) {
                        vo.setAverageFirstReplyTime(tempJson.getInteger("5"));
                    }
                    if (tempJson.containsKey("6")) {
                        vo.setSessionsCustNum(tempJson.getInteger("6"));
                    }
                    if (tempJson.containsKey("7")) {
                        vo.setLaunchSessionsCustNum(tempJson.getInteger("7"));
                    }
                    if (tempJson.containsKey("8")) {
                        vo.setLaunchSessionsSalesNum(tempJson.getInteger("8"));
                    }
                    if (tempJson.containsKey("9")) {
                        vo.setSendNewsNum(tempJson.getInteger("9"));
                    }
                }
            }
            voList.add(vo);
        }

        return RestResponse.successResult(voList);


    }


    /**
     * 单聊统计 会话数据统计
     * 门店维度
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping("single-chat-store-data")
    public RestResponse<DataPageVO<SingleChatStoreGroupVO>> singleChatStoreData(@RequestBody SingleChatStoreGroupReq req) {
        JSONObject jsonObject = new JSONObject();
        req.dealWithParam(jsonObject);
        storeAuthUtils.setStoreGroupJsonParam(jsonObject, req);
        jsonObject.put("apolloKey", "data_mbr_scale_haoban_qw_chat_count");
        jsonObject.put("groupType", 1);
        DataPageVO vo = storeAuthUtils.getDataCommon(jsonObject.toJSONString(), req.getPageNum(), "data_mbr_scale_haoban_qw_chat_count", req.getPageSize(), true);
        if (CollectionUtils.isNotEmpty(vo.getRows())) {
            vo.setRows(JSONArray.parseArray(JSON.toJSONString(vo.getRows()), SingleChatStoreGroupVO.class));
        }
        return RestResponse.successResult(vo);

    }

    /**
     * 单聊统计 会话数据统计
     * 导购维度
     * <p>
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping("single-chat-clerk-data")
    public RestResponse<DataPageVO<SingleChatClerkVO>> singleChatClerkData(@RequestBody SingleChatClerkReq req) {
        JSONObject jsonObject = new JSONObject();
        req.dealWithParam(jsonObject);
        storeAuthUtils.setCommonParam(jsonObject, new StoreGroupCommonQO());
        jsonObject.put("groupType", 2);
        Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), "data_mbr_scale_haoban_qw_chat_count");

        Page page = DataApiUtils.getPageData(res);
        DataPageVO vo = new DataPageVO();
        vo.setPageSize(page.getPageSize());
        vo.setPageNum(page.getCurrentPage());

        List<JSONObject> list = page.getResult();

        vo.setTotalNum(page.getTotalCount());

        jsonObject.put("groupType", 1);
        jsonObject.put("storeGroup", 8);
        JSONObject total = storeAuthUtils.getTotalJson(jsonObject, "data_mbr_scale_haoban_qw_chat_count");
        if (list == null) {
            list = new ArrayList<>();
        }
        if (total != null) {
            total.put("clerkName", "合计（" + list.size() + "）");
            list.add(0, total);
        }
        vo.setRows(list);
        if (CollectionUtils.isNotEmpty(vo.getRows())) {
            vo.setRows(JSONArray.parseArray(JSON.toJSONString(vo.getRows()), SingleChatClerkVO.class));
        }
        return RestResponse.successResult(vo);

    }


    /**
     * 单聊统计 会话数据统计
     * 数据导出
     * 门店维度
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping(value = "export-single-chat-store-data")
    public RestResponse<Object> exportSingleChatStoreData(@RequestBody SingleChatStoreGroupReq req) {

        DownloadTask task = new DownloadTask();
        task.setTaskTypeEnum(TaskTypeEnum.WECHAT_WORK_STORE_GROUP);
        task.setDataType(req.getDataType());
        task.setUser(getUserInfo());

        task.setTotalCount(singleChatStoreData(req).getResult().getTotalNum());

        JSONObject jsonObject = new JSONObject();
        req.dealWithParam(jsonObject);
        storeAuthUtils.setStoreGroupJsonParam(jsonObject, req);
        jsonObject.put("apolloKey", "data_mbr_scale_haoban_qw_chat_count");
        jsonObject.put("groupType", 1);
        //Excel的标题是字段进行计算
        List<String> indexList = new ArrayList<>();
        List<String> fieldList = new ArrayList<>();

        Integer storeGroup = jsonObject.getInteger("storeGroup");
        boolean isStore = storeGroup != null && storeGroup == 7;

        if (isStore) {
            indexList.add("门店名称");
            fieldList.add("storeName");
            indexList.add("门店code");
            fieldList.add("storeCode");
        } else {
            indexList.add("分组名称");
            fieldList.add("storeGroupName");
        }

        indexList.add("上级分组");
        fieldList.add("parentStoreGroupName");
        indexList.add("删除导购人数");
        fieldList.add("deleteSalesNum");
        indexList.add("导购删除人数");
        fieldList.add("salesDeleteNum");
        indexList.add("单向好友人数");
        fieldList.add("onewayFriendNum");


        task.setFileName("流失好友-门店维度数据统计-" + req.getStartDate() + "_" + req.getEndDate());
        task.setChannelName("数据-企微数据-流失好友");
        task.setBucketName(BucketNameEnum.REPORT_50000.getName());
        jsonObject.put("indexList", indexList);
        jsonObject.put("fieldList", fieldList);
        task.setSearchDataParams(jsonObject.toJSONString());
        task.setHandler(null);
        JSONResponse downloadTask = DownloadTaskUtil.createDownloadTask(task);
        return RestResponse.successResult(downloadTask.getResult());
    }


    /**
     * 单聊统计 会话数据统计
     * 数据导出
     * 导购维度
     * <p>
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping(value = "export-single-chat-clerk-data")
    public RestResponse<Object> exportSingleChatClerkData(@RequestBody SingleChatClerkReq req) {
        DownloadTask task = new DownloadTask();
        task.setTaskTypeEnum(TaskTypeEnum.WECHAT_WORK_CLERK_DETAIL);
        task.setDataType(req.getDataType());
        task.setUser(getUserInfo());

        task.setTotalCount(singleChatClerkData(req).getResult().getTotalNum());

        JSONObject jsonObject = new JSONObject();
        req.dealWithParam(jsonObject);
        storeAuthUtils.setCommonParam(jsonObject, new StoreGroupCommonQO());
        jsonObject.put("apolloKey", "data_mbr_scale_haoban_qw_chat_count");
        jsonObject.put("groupType", 2);
        //Excel的标题是字段进行计算
        List<String> indexList = new ArrayList<>();
        List<String> fieldList = new ArrayList<>();
        indexList.add("导购姓名");
        fieldList.add("clerkName");
        indexList.add("导购code");
        fieldList.add("clerkCode");
        indexList.add("所属门店名称");
        fieldList.add("storeName");
        indexList.add("所属门店code");
        fieldList.add("storeCode");
        indexList.add("所属分组");
        fieldList.add("storeGroupName");
        indexList.add("删除导购人数");
        fieldList.add("deleteSalesNum");
        indexList.add("导购删除人数");
        fieldList.add("salesDeleteNum");
        indexList.add("单向好友人数");
        fieldList.add("onewayFriendNum");


        task.setFileName("流失好友-导购维度数据统计-" + req.getStartDate() + "_" + req.getEndDate());
        task.setChannelName("数据-企微数据-流失好友");
        task.setBucketName(BucketNameEnum.REPORT_50000.getName());
        jsonObject.put("indexList", indexList);
        jsonObject.put("fieldList", fieldList);
        task.setSearchDataParams(jsonObject.toJSONString());
        task.setHandler(null);
        JSONResponse downloadTask = DownloadTaskUtil.createDownloadTask(task);
        return RestResponse.successResult(downloadTask.getResult());
    }


    /**
     * 单聊统计 会话数据详情
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping("single-chat-details")
    public RestResponse<DataPageVO<SingleChatDetailVO>> singleChatDetails(@RequestBody SingleChatDetailReq req) {

        JSONObject jsonObject = new JSONObject();
        req.dealWithParam(jsonObject);
        storeAuthUtils.setCommonParam(jsonObject, new StoreGroupCommonQO());
        Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), "data_mbr_scale_haoban_qw_chat_detail");
        Page page = DataApiUtils.getPageData(res);
        DataPageVO<SingleChatDetailVO> vo = new DataPageVO();
        vo.setPageSize(page.getPageSize());
        vo.setPageNum(page.getCurrentPage());

        List<JSONObject> list = page.getResult();
        if (CollectionUtils.isNotEmpty(list)) {
            List<SingleChatDetailVO> voList = JSONArray.parseArray(JSON.toJSONString(list), SingleChatDetailVO.class);
            vo.setRows(voList);
        }
        vo.setTotalNum(page.getTotalCount());
        return RestResponse.successResult(vo);

    }


    /**
     * 单聊统计 会话数据详情
     * 数据导出
     * * *
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping("export-single-chat-details")
    public RestResponse<Object> exportSingleChatDetails(@RequestBody SingleChatDetailReq req) {

        DownloadTask task = new DownloadTask();
        task.setTaskTypeEnum(TaskTypeEnum.WECHAT_WORK_MEMBER_DETAIL);
        task.setDataType(req.getDataType());
        task.setUser(getUserInfo());

        task.setTotalCount(singleChatDetails(req).getResult().getTotalNum());

        JSONObject jsonObject = new JSONObject();
        req.dealWithParam(jsonObject);
        storeAuthUtils.setCommonParam(jsonObject, new StoreGroupCommonQO());
        jsonObject.put("apolloKey", "data_mbr_scale_haoban_qw_chat_detail");
        //Excel的标题是字段进行计算
        List<String> indexList = new ArrayList<>();
        List<String> fieldList = new ArrayList<>();
        indexList.add("客户姓名");
        fieldList.add("memberName");
        indexList.add("客户昵称");
        fieldList.add("memberNick");
        indexList.add("客户手机号");
        fieldList.add("memberPhone");
        indexList.add("导购姓名");
        fieldList.add("clerkName");
        indexList.add("导购code");
        fieldList.add("clerkCode");
        indexList.add("所属门店名称");
        fieldList.add("storeName");
        indexList.add("所属门店code");
        fieldList.add("storeCode");
        indexList.add("删除类型");
        fieldList.add("deleteType");
        indexList.add("留存天数");
        fieldList.add("remainDays");
        indexList.add("添加好友时间");
        fieldList.add("addTime");
        indexList.add("最近消费时间");
        fieldList.add("lastCsmeDate");
        indexList.add("删除时间");
        fieldList.add("deleteTime");


        task.setFileName( "流失好友-流失明细-" + req.getStartDate() + "_" + req.getEndDate());
        task.setChannelName("数据-企微数据-流失好友");
        task.setBucketName(BucketNameEnum.REPORT_50000.getName());
        jsonObject.put("indexList", indexList);
        jsonObject.put("fieldList", fieldList);
        task.setSearchDataParams(jsonObject.toJSONString());
        task.setHandler(null);
        JSONResponse downloadTask = DownloadTaskUtil.createDownloadTask(task);
        return RestResponse.successResult(downloadTask.getResult());


    }


    /**
     * 群聊统计 群数据概览
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping("group-overview")
    public RestResponse<SingleChatOverviewVO> groupOverview(@RequestBody SingleChatOverviewReq req) {

        return RestResponse.successResult();

    }


    /**
     * 群聊统计 趋势图
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping("group-overview-trend")
    public RestResponse<SingleChatOverviewVO> groupOverviewTrend(@RequestBody SingleChatOverviewReq req) {

        return RestResponse.successResult();

    }


    /**
     * 群聊统计 群数据统计
     * 门店维度
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping("group-store-data")
    public RestResponse<DataPageVO<SingleChatOverviewVO>> groupStoreData(@RequestBody SingleChatOverviewReq req) {

        return RestResponse.successResult();

    }

    /**
     * 群聊统计 群数据统计
     * 导购维度
     * <p>
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping("group-clerk-data")
    public RestResponse<DataPageVO<SingleChatOverviewVO>> groupClerkData(@RequestBody SingleChatOverviewReq req) {

        return RestResponse.successResult();

    }


    /**
     * 群聊统计 群数据统计
     * 数据导出
     * 门店维度
     * *
     *
     * @param qo
     * @return
     */
    @RequestMapping(value = "export-group-store-data")
    public RestResponse<Object> exportGroupStoreData(@RequestBody WechatWorkLostStoreGroupQO qo) {

        DownloadTask task = new DownloadTask();
        task.setTaskTypeEnum(TaskTypeEnum.WECHAT_WORK_STORE_GROUP);
        task.setDataType(qo.getDataType());
        task.setUser(getUserInfo());

        task.setTotalCount(singleChatStoreData(null).getResult().getTotalNum());

        JSONObject jsonObject = new JSONObject();
        qo.dealWithParam(jsonObject);
        storeAuthUtils.setStoreGroupJsonParam(jsonObject, qo);
        jsonObject.put("apolloKey", "data_mbr_scale_haoban_background_loss_statisti");
        jsonObject.put("groupType", 1);
        //Excel的标题是字段进行计算
        List<String> indexList = new ArrayList<>();
        List<String> fieldList = new ArrayList<>();

        Integer storeGroup = jsonObject.getInteger("storeGroup");
        boolean isStore = storeGroup != null && storeGroup == 7;

        if (isStore) {
            indexList.add("门店名称");
            fieldList.add("storeName");
            indexList.add("门店code");
            fieldList.add("storeCode");
        } else {
            indexList.add("分组名称");
            fieldList.add("storeGroupName");
        }

        indexList.add("上级分组");
        fieldList.add("parentStoreGroupName");
        indexList.add("删除导购人数");
        fieldList.add("deleteSalesNum");
        indexList.add("导购删除人数");
        fieldList.add("salesDeleteNum");
        indexList.add("单向好友人数");
        fieldList.add("onewayFriendNum");


        task.setFileName("流失好友-门店维度数据统计-" + qo.getStartDate() + "_" + qo.getEndDate());
        task.setChannelName("数据-企微数据-流失好友");
        task.setBucketName(BucketNameEnum.REPORT_50000.getName());
        jsonObject.put("indexList", indexList);
        jsonObject.put("fieldList", fieldList);
        task.setSearchDataParams(jsonObject.toJSONString());
        task.setHandler(null);
        JSONResponse downloadTask = DownloadTaskUtil.createDownloadTask(task);
        return RestResponse.successResult(downloadTask.getResult());
    }


    /**
     * 群聊统计 群数据统计
     * 数据导出
     * 导购维度
     * <p>
     * *
     *
     * @param qo
     * @return
     */
    @RequestMapping(value = "export-group-clerk-data")
    public RestResponse<Object> exportGroupClerkData(@RequestBody WechatWorkLostClerkQO qo) {
        DownloadTask task = new DownloadTask();
        task.setTaskTypeEnum(TaskTypeEnum.WECHAT_WORK_CLERK_DETAIL);
        task.setDataType(qo.getDataType());
        task.setUser(getUserInfo());

        task.setTotalCount(singleChatClerkData(null).getResult().getTotalNum());

        JSONObject jsonObject = new JSONObject();
        qo.dealWithParam(jsonObject);
        storeAuthUtils.setCommonParam(jsonObject, new StoreGroupCommonQO());
        jsonObject.put("apolloKey", "data_mbr_scale_haoban_background_loss_statisti");
        jsonObject.put("groupType", 2);
        //Excel的标题是字段进行计算
        List<String> indexList = new ArrayList<>();
        List<String> fieldList = new ArrayList<>();
        indexList.add("导购姓名");
        fieldList.add("clerkName");
        indexList.add("导购code");
        fieldList.add("clerkCode");
        indexList.add("所属门店名称");
        fieldList.add("storeName");
        indexList.add("所属门店code");
        fieldList.add("storeCode");
        indexList.add("所属分组");
        fieldList.add("storeGroupName");
        indexList.add("删除导购人数");
        fieldList.add("deleteSalesNum");
        indexList.add("导购删除人数");
        fieldList.add("salesDeleteNum");
        indexList.add("单向好友人数");
        fieldList.add("onewayFriendNum");


        task.setFileName("流失好友-导购维度数据统计-" + qo.getStartDate() + "_" + qo.getEndDate());
        task.setChannelName("数据-企微数据-流失好友");
        task.setBucketName(BucketNameEnum.REPORT_50000.getName());
        jsonObject.put("indexList", indexList);
        jsonObject.put("fieldList", fieldList);
        task.setSearchDataParams(jsonObject.toJSONString());
        task.setHandler(null);
        JSONResponse downloadTask = DownloadTaskUtil.createDownloadTask(task);
        return RestResponse.successResult(downloadTask.getResult());
    }


    /**
     * 群聊统计 群数据明细
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping("group-data-details")
    public RestResponse<DataPageVO<SingleChatOverviewVO>> groupDataDetails(@RequestBody SingleChatOverviewReq req) {

        return RestResponse.successResult();

    }


    /**
     * 群聊统计 群数据明细
     * 数据导出
     * * *
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping("export-group-data-details")
    public RestResponse<DataPageVO<SingleChatOverviewVO>> exportGroupDataDetails(@RequestBody SingleChatOverviewReq req) {

        return RestResponse.successResult();

    }


    /**
     * 群聊统计 入群明细
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping("join-group-details")
    public RestResponse<DataPageVO<SingleChatOverviewVO>> joinGroupDetails(@RequestBody SingleChatOverviewReq req) {

        return RestResponse.successResult();

    }


    /**
     * 群聊统计 入群明细
     * 数据导出
     * * *
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping("export-join-group-details")
    public RestResponse<Object> exportJoinGroupDetails(@RequestBody SingleChatOverviewReq req) {

        return RestResponse.successResult();

    }


    /**
     * 群聊统计 退群明细
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping("exit-group-details")
    public RestResponse<DataPageVO<SingleChatOverviewVO>> exitGroupDetails(@RequestBody SingleChatOverviewReq req) {

        return RestResponse.successResult();

    }


    /**
     * 群聊统计 退群明细
     * 数据导出
     * * *
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping("export-exit-group-details")
    public RestResponse<Object> exportExitGroupDetails(@RequestBody SingleChatOverviewReq req) {

        return RestResponse.successResult();

    }


    /**
     * 群聊统计 会话明细
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping("group-chat-details")
    public RestResponse<DataPageVO<SingleChatOverviewVO>> groupChatDetails(@RequestBody SingleChatOverviewReq req) {

        return RestResponse.successResult();

    }


    /**
     * 群聊统计 会话明细
     * 数据导出
     * * *
     * *
     *
     * @param req
     * @return
     */
    @RequestMapping("export-group-chat-details")
    public RestResponse<Object> exportGroupChatDetails(@RequestBody SingleChatOverviewReq req) {

        return RestResponse.successResult();

    }

    private AuthorizedUser getUserInfo() {
        return AuthorizedUserUtils.getUserInfo();
    }

}
