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

import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.BasePageInfo;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.EntityUtil;
import com.gic.haoban.manage.api.dto.chat.GroupChatDataDTO;
import com.gic.haoban.manage.api.dto.qdto.chat.ChatDataSearchQDTO;
import com.gic.haoban.manage.api.service.chat.GroupChatDataApiService;
import com.gic.haoban.manage.web.vo.chat.GroupChatDataVO;
import com.gic.web.common.download.DownloadHandlerAbstract;
import com.gic.web.common.download.context.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;

@Service
public class GroupChatDataExcelHandler extends DownloadHandlerAbstract<GroupChatDataVO> {

    @Autowired
    private GroupChatDataApiService groupChatDataApiService;

    @Override
    public List<GroupChatDataVO> getData(Context context, String searchDataParams, Integer currentPage) {
        ChatDataSearchQDTO qdto = JSON.parseObject(searchDataParams, ChatDataSearchQDTO.class);
        BasePageInfo basePageInfo = new BasePageInfo() ;
        basePageInfo.setPageSize(this.getPageSize());
        basePageInfo.setPageNum(currentPage);
        ServiceResponse<Page<GroupChatDataDTO>> resp = this.groupChatDataApiService.listStaffData(qdto, basePageInfo);
        List<GroupChatDataVO> voList = new ArrayList<>() ;
        for (GroupChatDataDTO dto : resp.getResult().getResult()) {
            GroupChatDataVO vo = EntityUtil.changeEntityByJSON(GroupChatDataVO.class, dto);
                voList.add(vo);
        }
        return voList;
    }

    @Override
    public List<String> getColumnNames() {
        return Arrays.asList("群主", "群总数", "新增群数", "活跃群数","群人数","新增人数","活跃人数","退群人数", "群聊消息总数");
    }

    @Override
    public LinkedHashMap<String, List<String>> doubleColumnNames() {
        return null;
    }

    @Override
    public List<String> getColumns() {
        return  Arrays.asList("staffName","chatTotal","newChatCnt","chatHasMsg","memberTotal","newMemberCnt","memberHasMsg", "quitUserCount", "msgTotal");
    }
}
