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

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.Page;
import com.gic.commons.util.DateUtil;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.api.dto.security.DownloadReportDTO;
import com.gic.haoban.manage.web.controller.chat.GroupChatActivityDataController;
import com.gic.haoban.manage.web.qo.chat.GroupChatActivityInviteLogReq;
import com.gic.haoban.manage.web.qo.chat.GroupChatActivityJoinDetailReq;
import com.gic.haoban.manage.web.qo.chat.GroupChatActivityRewardLogReq;
import com.gic.haoban.manage.web.vo.chat.GroupChatActivityInviteLogVO;
import com.gic.haoban.manage.web.vo.chat.GroupChatActivityRewardLogExportVO;
import com.gic.haoban.manage.web.vo.chat.GroupChatActivityRewardLogVO;
import com.gic.haoban.manage.web.vo.chat.GroupChatDataJoinDetailVO;
import com.gic.web.common.download.DownloadHandlerAbstract;
import com.gic.web.common.download.context.Context;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * @author shangfeng
 * @date 2024-10-11 17:29:51
 */
@Component
public class GroupChatActivityJoinHandle extends DownloadHandlerAbstract<GroupChatDataJoinDetailVO> {

    private static Logger log = LogManager.getLogger(GroupChatActivityJoinHandle.class);

    @Resource
    private GroupChatActivityDataController groupChatActivityDataController;

    @Override
    public List<GroupChatDataJoinDetailVO> getData(Context context, String searchDataParams, Integer currentPage) {
        GroupChatActivityJoinDetailReq joinDetailReq = JSON.parseObject(searchDataParams, GroupChatActivityJoinDetailReq.class);
        joinDetailReq.setPageNum(currentPage);
        joinDetailReq.setPageSize(getPageSize());
        log.info("社群邀请有礼参与客户数据导出，请求参数={}", JSON.toJSONString(joinDetailReq));
        RestResponse<Page<GroupChatDataJoinDetailVO>> dataPageVORestResponse = groupChatActivityDataController.joinDetail(joinDetailReq);
        List<GroupChatDataJoinDetailVO> groupChatDataJoinDetailVOS = dataPageVORestResponse.getResult().getResult();
        if (CollectionUtils.isEmpty(groupChatDataJoinDetailVOS)) {
            return Lists.newArrayList();
        }
        for (GroupChatDataJoinDetailVO groupChatDataJoinDetailVO : groupChatDataJoinDetailVOS) {
           if(groupChatDataJoinDetailVO.getMemberDeleteFlag() == 1){
               groupChatDataJoinDetailVO.setName("账号已注销");
           }
        }
        log.info("社群邀请有礼参与客户数据导出={}", JSON.toJSONString(groupChatDataJoinDetailVOS));

        return groupChatDataJoinDetailVOS;
    }


    @Override
    public List<String> getColumnNames() {
        return Lists.newArrayList();
    }

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

    @Override
    public List<String> getColumns() {
        return Lists.newArrayList();
    }

    @Override
    public List<String> getColumns(Context context) {
        DownloadReportDTO downloadReportDTO = context.getDownloadReportDTO();
        String searchDataParams = downloadReportDTO.getSearchDataParams();
        JSONObject jsonObject = JSONObject.parseObject(searchDataParams);
        List<String> list = (List<String>) jsonObject.get("fieldList");
        return list;
    }

    @Override
    public List<String> getColumnNames(Context context) {
        DownloadReportDTO downloadReportDTO = context.getDownloadReportDTO();
        String searchDataParams = downloadReportDTO.getSearchDataParams();
        JSONObject jsonObject = JSONObject.parseObject(searchDataParams);
        List<String> list = (List<String>) jsonObject.get("indexList");
        return list;
    }

}
