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

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.JSONResponse;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.clerk.api.dto.AuthorizedUser;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.api.dto.EnterpriseDTO;
import com.gic.enterprise.api.service.EnterpriseService;
import com.gic.haoban.base.api.common.pojo.dto.WebLoginDTO;
import com.gic.haoban.common.utils.AuthWebRequestUtil;
import com.gic.haoban.manage.api.constants.StatisticsApolloKeyConstant;
import com.gic.haoban.manage.api.dto.chat.*;
import com.gic.haoban.manage.api.qdto.chat.GroupChatActivityInviteLogQDTO;
import com.gic.haoban.manage.api.qdto.chat.GroupChatActivityRewardLogQDTO;
import com.gic.haoban.manage.api.service.chat.GroupChatActivityApiService;
import com.gic.haoban.manage.api.service.chat.GroupChatActivityLogApiService;
import com.gic.haoban.manage.web.handle.GroupChatActivityInviterHandle;
import com.gic.haoban.manage.web.handle.GroupChatActivityJoinHandle;
import com.gic.haoban.manage.web.handle.GroupChatActivityRewardHandle;
import com.gic.haoban.manage.web.qo.chat.*;
import com.gic.haoban.manage.web.vo.chat.*;
import com.gic.member.api.constant.RewardResultTypeEnum;
import com.gic.member.api.dto.MemberDTO;
import com.gic.member.api.dto.MemberDocDTO;
import com.gic.member.api.service.MemberService;
import com.gic.qcloud.BucketNameEnum;
import com.gic.web.common.download.DownloadTask;
import com.gic.web.common.download.DownloadTaskUtil;
import com.gic.web.common.download.constants.TaskTypeEnum;
import com.gic.web.common.utils.DataApiUtils;
import com.gic.web.common.utils.SessionContextUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 社群邀请有礼数据
 *
 * @author shangfeng
 * @date 2024-10-10 15:56:56
 */
@RestController
@RequestMapping("/group-chat-activity-data")
public class GroupChatActivityDataController {

    @Resource
    private GroupChatActivityLogApiService groupChatActivityLogApiService;

    @Resource
    private GroupChatActivityApiService groupChatActivityApiService;

    @Resource
    private EnterpriseService enterpriseService;

    @Resource
    private MemberService memberService;

    @Resource
    private GroupChatActivityJoinHandle groupChatActivityJoinHandle;

    @Resource
    private GroupChatActivityInviterHandle groupChatActivityInviterHandle;

    @Resource
    private GroupChatActivityRewardHandle groupChatActivityRewardHandle;

    /**
     * 列表统计数据
     *
     * @param joinDataReq
     * @return
     */
    @RequestMapping("get-join-data-list")
    @ResponseBody
    public RestResponse<List<GroupChatActivityJoinDataVO>> getJoinDataList(@RequestBody GroupChatActivityJoinDataReq joinDataReq) {
        WebLoginDTO user = AuthWebRequestUtil.getLoginUser();

        GroupChatActivityDataOverviewReq overviewReq = new GroupChatActivityDataOverviewReq();
        overviewReq.setEnterpriseId(user.getEnterpriseId());
        overviewReq.setChatActivityId(StringUtils.join(joinDataReq.getChatActivityIdList(), ","));

        Map<String, Object> res = DataApiUtils.http(JSON.toJSONString(overviewReq), StatisticsApolloKeyConstant.data_mkt_group_chat_data_overview);
        Map<String, GroupChatDataOverviewVO> map = Maps.newHashMap();
        List<GroupChatDataOverviewVO> list = DataApiUtils.parsePageDataList(res, GroupChatDataOverviewVO.class);

        if (CollectionUtils.isNotEmpty(list)) {
            map = list.stream().collect(Collectors.toMap(GroupChatDataOverviewVO::getChatActivityId, groupChatDataOverviewVO -> groupChatDataOverviewVO));
        }
        Map<String, GroupChatDataOverviewVO> finalMap = map;
        List<GroupChatActivityJoinDataVO> joinDataVOList = joinDataReq.getChatActivityIdList().stream().map(chatActivityId -> {
            GroupChatActivityJoinDataVO groupChatActivityJoinDataVO = new GroupChatActivityJoinDataVO();
            groupChatActivityJoinDataVO.setChatActivityId(chatActivityId);
            GroupChatDataOverviewVO groupChatDataOverviewVO = finalMap.get(chatActivityId.toString());
            if (Objects.nonNull(groupChatDataOverviewVO)) {
                if (StringUtils.isNotEmpty(groupChatDataOverviewVO.getInviterNum())) {
                    groupChatActivityJoinDataVO.setInviterNum(Integer.parseInt(groupChatDataOverviewVO.getInviterNum()));
                }
                if (StringUtils.isNotEmpty(groupChatDataOverviewVO.getInviteeNum())) {
                    groupChatActivityJoinDataVO.setInviteeNum(Integer.parseInt(groupChatDataOverviewVO.getInviteeNum()));
                }
                if (StringUtils.isNotEmpty(groupChatDataOverviewVO.getEffectiveInviteeNum())) {
                    groupChatActivityJoinDataVO.setEffectiveInviteeNum(Integer.parseInt(groupChatDataOverviewVO.getEffectiveInviteeNum()));
                }
            }
            return groupChatActivityJoinDataVO;
        }).collect(Collectors.toList());

        return RestResponse.successResult(joinDataVOList);
    }


    /**
     * 数据概览
     *
     * @param overviewReq
     * @return
     */
    @RequestMapping("overview")
    @ResponseBody
    public RestResponse<GroupChatDataOverviewVO> overview(@RequestBody GroupChatActivityDataOverviewReq overviewReq) {
        WebLoginDTO user = AuthWebRequestUtil.getLoginUser();
        overviewReq.setEnterpriseId(user.getEnterpriseId());
        Map<String, Object> res = DataApiUtils.http(JSON.toJSONString(overviewReq), StatisticsApolloKeyConstant.data_mkt_group_chat_data_overview);
        Page page = DataApiUtils.getPageData(res);
        List<JSONObject> result = page.getResult();
        if (CollectionUtils.isEmpty(result)) {
            return RestResponse.successResult(null);
        }
        GroupChatDataOverviewVO groupChatDataOverviewVO = JSON.parseObject(JSON.toJSONString(result.get(0)), GroupChatDataOverviewVO.class);
        return RestResponse.successResult(groupChatDataOverviewVO);
    }

    /**
     * 阶梯奖励数据
     *
     * @param rewardLevelReq
     * @return
     */
    @RequestMapping("reward_level")
    @ResponseBody
    public RestResponse<Page<GroupChatDataRewardLevelVO>> rewardLevel(@RequestBody GroupChatActivityDataRewardLevelReq rewardLevelReq) {
        WebLoginDTO user = AuthWebRequestUtil.getLoginUser();
        rewardLevelReq.setEnterpriseId(user.getEnterpriseId());
        Map<String, Object> res = DataApiUtils.http(JSON.toJSONString(rewardLevelReq), StatisticsApolloKeyConstant.data_mkt_group_chat_data_reward_level);
        Page page = DataApiUtils.getPageData(res);
        if (CollectionUtils.isNotEmpty(page.getResult())) {
            List<GroupChatDataRewardLevelVO> groupChatDataOverviewVOList = JSON.parseArray(JSON.toJSONString(page.getResult()), GroupChatDataRewardLevelVO.class);
            page.setResult(groupChatDataOverviewVOList);
        }
        return RestResponse.successResult(page);
    }

    /**
     * 参与客户明细
     *
     * @param inviterDetailReq
     * @return
     */
    @RequestMapping("join_detail")
    @ResponseBody
    public RestResponse<Page<GroupChatDataJoinDetailVO>> joinDetail(@RequestBody GroupChatActivityDataInviterDetailReq inviterDetailReq) {
        WebLoginDTO user = AuthWebRequestUtil.getLoginUser();
        inviterDetailReq.setEnterpriseId(user.getEnterpriseId());
        Map<String, Object> res = DataApiUtils.http(JSON.toJSONString(inviterDetailReq), StatisticsApolloKeyConstant.data_mkt_group_chat_data_inviter_detail);
        Page page = DataApiUtils.getPageData(res);
        if (CollectionUtils.isNotEmpty(page.getResult())) {
            List<GroupChatDataJoinDetailVO> groupChatDataJoinDetailVOS = JSON.parseArray(JSON.toJSONString(page.getResult()), GroupChatDataJoinDetailVO.class);
            page.setResult(groupChatDataJoinDetailVOS);
        }
        return RestResponse.successResult(page);
    }

    /**
     * 参与客户明细
     *
     * @param inviterDetailReq
     * @return
     */
    @RequestMapping("join_detail_export")
    @ResponseBody
    public RestResponse<Object> joinDetailExport(@RequestBody GroupChatActivityDataInviterDetailReq inviterDetailReq) {
        WebLoginDTO user = AuthWebRequestUtil.getLoginUser();
        inviterDetailReq.setEnterpriseId(user.getEnterpriseId());
        Map<String, Object> res = DataApiUtils.http(JSON.toJSONString(inviterDetailReq), StatisticsApolloKeyConstant.data_mkt_group_chat_data_inviter_detail);
        Page page = DataApiUtils.getPageData(res);
        if (CollectionUtils.isNotEmpty(page.getResult())) {
            List<GroupChatDataJoinDetailVO> groupChatDataJoinDetailVOS = JSON.parseArray(JSON.toJSONString(page.getResult()), GroupChatDataJoinDetailVO.class);
            page.setResult(groupChatDataJoinDetailVOS);
        }
        return RestResponse.successResult(page);
    }

    /**
     * 邀请明细
     *
     * @param inviteLogQDTO
     * @return
     */
    @RequestMapping("inviter_detail")
    @ResponseBody
    public RestResponse<Page<GroupChatActivityInviteVO>> inviterDetail(@RequestBody GroupChatActivityInviteLogQDTO inviteLogQDTO) {
        if (StringUtils.isEmpty(inviteLogQDTO.getEnterpriseId())) {
            WebLoginDTO user = AuthWebRequestUtil.getLoginUser();
            inviteLogQDTO.setEnterpriseId(user.getEnterpriseId());
        }

        inviteLogQDTO.setSortFiled("create_time");
        inviteLogQDTO.setSortType("desc");
        ServiceResponse<Page<GroupChatActivityInviteLogDTO>> listServiceResponse = groupChatActivityLogApiService.queryInviteLogDetails(inviteLogQDTO);
        if (!listServiceResponse.isSuccess()) {
            return RestResponse.failure(listServiceResponse.getCode(), listServiceResponse.getMessage());
        }
        Page<GroupChatActivityInviteVO> page = new Page<>(inviteLogQDTO.getPageNum(), inviteLogQDTO.getPageSize(), 0, 0);
        Page<GroupChatActivityInviteLogDTO> groupChatActivityInviteLogPage = listServiceResponse.getResult();

        if (CollectionUtils.isEmpty(groupChatActivityInviteLogPage.getResult())) {
            return RestResponse.successResult(page);
        }
        Map<String, MemberDocDTO> memberDocDTOMap = Maps.newHashMap();
        List<String> inviteeMemberIdList = groupChatActivityInviteLogPage.getResult().stream()
                .map(GroupChatActivityInviteLogDTO::getInviteeMemberId).filter(Objects::nonNull).collect(Collectors.toList());
        if (CollectionUtils.isNotEmpty(inviteeMemberIdList)) {
            EnterpriseDTO enterpriseDTO = enterpriseService.getEnterpriseById(inviteLogQDTO.getEnterpriseId());
            List<MemberDocDTO> memberDocDTOList = memberService.getMembersFromSearchIndex(enterpriseDTO.getEnterpriseMicroSignal(), inviteeMemberIdList);
            memberDocDTOMap = memberDocDTOList.stream().collect(Collectors.toMap(MemberDocDTO::getMemberId, memberDocDTO -> memberDocDTO));
        }

        Map<String, MemberDocDTO> finalMemberDocDTOMap = memberDocDTOMap;
        List<GroupChatActivityInviteVO> groupChatActivityInviteVOList = groupChatActivityInviteLogPage.getResult().stream().map(groupChatActivityInviteLogDTO -> {
            GroupChatActivityInviteVO groupChatActivityInviteVO = new GroupChatActivityInviteVO();
            groupChatActivityInviteVO.setNickName(groupChatActivityInviteLogDTO.getNickName());
            MemberDocDTO memberDocDTO = finalMemberDocDTOMap.get(groupChatActivityInviteLogDTO.getInviteeMemberId());
            if (Objects.nonNull(memberDocDTO)) {
                groupChatActivityInviteVO.setPhotoUrl(memberDocDTO.getPhotoUrl());
            }
            return groupChatActivityInviteVO;
        }).collect(Collectors.toList());
        page.setResult(groupChatActivityInviteVOList);
        page.setResult(groupChatActivityInviteVOList);
        page.setTotalCount(groupChatActivityInviteLogPage.getTotalCount());
        page.setTotalPage(groupChatActivityInviteLogPage.getTotalPage());
        return RestResponse.successResult(page);
    }

    /**
     * 邀请明细
     *
     * @param inviteLogQDTO
     * @return
     */
    @RequestMapping("inviter_detail_export")
    @ResponseBody
    public RestResponse<Object> inviterDetailExport(@RequestBody GroupChatActivityInviteLogQDTO inviteLogQDTO) {
        WebLoginDTO user = AuthWebRequestUtil.getLoginUser();
        inviteLogQDTO.setEnterpriseId(user.getEnterpriseId());
        inviteLogQDTO.setSortFiled("create_time");
        inviteLogQDTO.setSortType("desc");
        ServiceResponse<Page<GroupChatActivityInviteLogDTO>> listServiceResponse = groupChatActivityLogApiService.queryInviteLogDetails(inviteLogQDTO);
        if (!listServiceResponse.isSuccess()) {
            return RestResponse.failure(listServiceResponse.getCode(), listServiceResponse.getMessage());
        }
        Page<GroupChatActivityInviteVO> page = new Page<>(inviteLogQDTO.getPageNum(), inviteLogQDTO.getPageSize(), 0, 0);
        Page<GroupChatActivityInviteLogDTO> groupChatActivityInviteLogPage = listServiceResponse.getResult();

        if (CollectionUtils.isEmpty(groupChatActivityInviteLogPage.getResult())) {
            return RestResponse.successResult(page);
        }
        Map<String, MemberDocDTO> memberDocDTOMap = Maps.newHashMap();
        List<String> inviteeMemberIdList = groupChatActivityInviteLogPage.getResult().stream()
                .map(GroupChatActivityInviteLogDTO::getInviteeMemberId).filter(Objects::nonNull).collect(Collectors.toList());
        if (CollectionUtils.isNotEmpty(inviteeMemberIdList)) {
            EnterpriseDTO enterpriseDTO = enterpriseService.getEnterpriseById(inviteLogQDTO.getEnterpriseId());
            List<MemberDocDTO> memberDocDTOList = memberService.getMembersFromSearchIndex(enterpriseDTO.getEnterpriseMicroSignal(), inviteeMemberIdList);
            memberDocDTOMap = memberDocDTOList.stream().collect(Collectors.toMap(MemberDocDTO::getMemberId, memberDocDTO -> memberDocDTO));
        }

        Map<String, MemberDocDTO> finalMemberDocDTOMap = memberDocDTOMap;
        List<GroupChatActivityInviteVO> groupChatActivityInviteVOList = groupChatActivityInviteLogPage.getResult().stream().map(groupChatActivityInviteLogDTO -> {
            GroupChatActivityInviteVO groupChatActivityInviteVO = new GroupChatActivityInviteVO();
            groupChatActivityInviteVO.setNickName(groupChatActivityInviteLogDTO.getNickName());
            MemberDocDTO memberDocDTO = finalMemberDocDTOMap.get(groupChatActivityInviteLogDTO.getInviteeMemberId());
            if (Objects.nonNull(memberDocDTO)) {
                groupChatActivityInviteVO.setPhotoUrl(memberDocDTO.getPhotoUrl());
            }
            return groupChatActivityInviteVO;
        }).collect(Collectors.toList());
        page.setResult(groupChatActivityInviteVOList);
        page.setResult(groupChatActivityInviteVOList);
        page.setTotalCount(groupChatActivityInviteLogPage.getTotalCount());
        page.setTotalPage(groupChatActivityInviteLogPage.getTotalPage());
        return RestResponse.successResult(page);
    }

    /**
     * 奖励明细
     *
     * @param rewardLogReq
     * @return
     */
    @RequestMapping("reward_detail")
    @ResponseBody
    public RestResponse<Page<GroupChatActivityRewardLogVO>> rewardDetail(@RequestBody GroupChatActivityRewardLogReq rewardLogReq) {
        if (StringUtils.isEmpty(rewardLogReq.getEnterpriseId())) {
            WebLoginDTO user = AuthWebRequestUtil.getLoginUser();
            rewardLogReq.setEnterpriseId(user.getEnterpriseId());
        }
        GroupChatActivityRewardLogQDTO rewardLogQDTO = new GroupChatActivityRewardLogQDTO();
        BeanUtils.copyProperties(rewardLogReq, rewardLogQDTO);
        ServiceResponse<Page<GroupChatActivityRewardLogDTO>> listServiceResponse = groupChatActivityLogApiService.queryRewardLogDetails(rewardLogQDTO);
        if (!listServiceResponse.isSuccess()) {
            return RestResponse.failure(listServiceResponse.getCode(), listServiceResponse.getMessage());
        }
        Page<GroupChatActivityRewardLogVO> page = new Page<>(rewardLogQDTO.getPageNum(), rewardLogQDTO.getPageSize(), 0, 0);
        Page<GroupChatActivityRewardLogDTO> groupChatActivityInviteLogPage = listServiceResponse.getResult();

        if (CollectionUtils.isEmpty(groupChatActivityInviteLogPage.getResult())) {
            return RestResponse.successResult(page);
        }

        List<GroupChatActivityRewardLogVO> groupChatActivityInviteVOList = convertToInteractionDetailVO(groupChatActivityInviteLogPage.getResult());
        page.setResult(groupChatActivityInviteVOList);
        page.setResult(groupChatActivityInviteVOList);
        page.setTotalCount(groupChatActivityInviteLogPage.getTotalCount());
        page.setTotalPage(groupChatActivityInviteLogPage.getTotalPage());
        return RestResponse.successResult(page);

    }

    /**
     * 奖励明细导出
     *
     * @param rewardLogReq
     * @return
     */
    @RequestMapping("reward_detail_export")
    @ResponseBody
    public RestResponse<Object> rewardDetailExport(@RequestBody GroupChatActivityRewardLogReq rewardLogReq) {
        WebLoginDTO user = AuthWebRequestUtil.getLoginUser();
        rewardLogReq.setEnterpriseId(user.getEnterpriseId());

        AuthorizedUser loginUser = SessionContextUtils.getLoginUser();

        DownloadTask task = new DownloadTask();
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(rewardLogReq));

        task.setTaskTypeEnum(TaskTypeEnum.GROUP_CHAT_ACTIVITY_REWARD);
        task.setDataType(rewardLogReq.getDataType());
        task.setUser(loginUser);
        task.setTotalCount(rewardDetail(rewardLogReq).getResult().getTotalCount());

        //查询奖励配置
        ServiceResponse<GroupChatActivityDTO> serviceActivityDetail = groupChatActivityApiService
                .getActivityDetail(rewardLogReq.getEnterpriseId(), rewardLogReq.getChatActivityId());
        GroupChatActivityDTO groupChatActivityDTO = serviceActivityDetail.getResult();

        //获取所有奖励类型
        Set<Integer> rewardTypeList = Sets.newHashSet();
        Map<Integer, List<GroupChatActivityRewardDTO>> rewardMap = groupChatActivityDTO.getRewardMap();
        rewardMap.forEach((key, value) -> {
            value.forEach(groupChatActivityRewardDTO -> {
                groupChatActivityRewardDTO.getDetailList().forEach(groupChatActivityRewardDetailDTO -> {
                    rewardTypeList.add(groupChatActivityRewardDetailDTO.getRewardType());
                });
            });
        });

        boolean isSettingIntegral = rewardTypeList.contains(RewardResultTypeEnum.integral.getType());
        boolean isSettingGrowth = rewardTypeList.contains(RewardResultTypeEnum.growth.getType());
        boolean isSettingCoupon = rewardTypeList.contains(RewardResultTypeEnum.coupon.getType());

        List<String> fieldList = new ArrayList<>();
        List<String> indexList = new ArrayList<>();
        fieldList.add("name");
        indexList.add("客户姓名");

        fieldList.add("nickName");
        indexList.add("客户昵称");

        fieldList.add("phoneNumber");
        indexList.add("客户手机号");

        fieldList.add("rewardInvite");
        indexList.add("奖励类型");

        fieldList.add("inviteLevel");
        indexList.add("奖励说明");

        if (isSettingIntegral) {
            fieldList.add("integral");
            indexList.add("奖励积分");
        }
        if (isSettingGrowth) {
            fieldList.add("growth");
            indexList.add("奖励成长值");
        }
        if (isSettingCoupon) {
            fieldList.add("cardInfo");
            indexList.add("奖励卡券");
        }

        fieldList.add("createTime");
        indexList.add("发放时间");

        task.setFileName("社群邀请有礼-活动名称-奖励明细");
        task.setChannelName("社群邀请有礼-活动名称-奖励明细");
        task.setBucketName(BucketNameEnum.REPORT_50000.getName());

        jsonObject.put("indexList", indexList);
        jsonObject.put("fieldList", fieldList);
        task.setSearchDataParams(jsonObject.toJSONString());
        task.setHandler(groupChatActivityRewardHandle);
        JSONResponse downloadTask = DownloadTaskUtil.createDownloadTask(task);

        return RestResponse.successResult(downloadTask.getResult());

    }

    /**
     * 奖励明细数据转换
     *
     * @param groupChatActivityRewardLogDTOS
     * @return
     */
    private List<GroupChatActivityRewardLogVO> convertToInteractionDetailVO(List<GroupChatActivityRewardLogDTO> groupChatActivityRewardLogDTOS) {
        List<String> memberIds = groupChatActivityRewardLogDTOS.stream().map(GroupChatActivityRewardLogDTO::getMemberId).collect(Collectors.toList());
        //会员信息
        List<MemberDTO> memberDtoList = memberService.getMemberDtoList(memberIds);
        //会员map
        Map<String, MemberDTO> memberDTOMap = memberDtoList.stream().collect(Collectors.toMap(MemberDTO::getMemberId, m -> m, (m1, m2) -> m2));

        return groupChatActivityRewardLogDTOS.stream().map(groupChatActivityRewardLogDTO -> {
            GroupChatActivityRewardLogVO groupChatActivityRewardLogVO = new GroupChatActivityRewardLogVO();
            BeanUtils.copyProperties(groupChatActivityRewardLogDTO, groupChatActivityRewardLogVO);
            MemberDTO memberDTO = memberDTOMap.get(groupChatActivityRewardLogDTO.getMemberId());
            if (Objects.nonNull(memberDTO)) {
                groupChatActivityRewardLogVO.setName(memberDTO.getMemberName());
                groupChatActivityRewardLogVO.setNickName(memberDTO.getThirdNickname());
                groupChatActivityRewardLogVO.setPhoneNumber(memberDTO.getPhoneNumber());
                groupChatActivityRewardLogVO.setMemberDeleteFlag(0);
            } else {
                groupChatActivityRewardLogVO.setMemberDeleteFlag(1);
            }
            if (CollectionUtils.isNotEmpty(groupChatActivityRewardLogDTO.getRewardDetailLogDTOList())) {
                int integral = 0;
                int growth = 0;
                List<String> cardList = Lists.newArrayList();
                for (GroupChatActivityRewardDetailLogDTO groupChatActivityRewardDetailLogDTO : groupChatActivityRewardLogDTO.getRewardDetailLogDTOList()) {
                    if (groupChatActivityRewardDetailLogDTO.getRewardType().equals(RewardResultTypeEnum.integral.getType())) {
                        integral += Integer.parseInt(groupChatActivityRewardDetailLogDTO.getRewardValue());
                    }
                    if (groupChatActivityRewardDetailLogDTO.getRewardType().equals(RewardResultTypeEnum.growth.getType())) {
                        growth += Integer.parseInt(groupChatActivityRewardDetailLogDTO.getRewardValue());
                    }
                    if (groupChatActivityRewardDetailLogDTO.getRewardType().equals(RewardResultTypeEnum.coupon.getType())) {
                        String card = groupChatActivityRewardDetailLogDTO.getRewardName() + "(";
                        if (groupChatActivityRewardDetailLogDTO.getSuccessFlag() == 1) {
                            card += groupChatActivityRewardDetailLogDTO.getRewardValue() + ")";
                        } else {
                            card += groupChatActivityRewardDetailLogDTO.getRewardRemark() + ")";
                        }
                        cardList.add(card);
                    }
                }
                groupChatActivityRewardLogVO.setIntegral(integral);
                groupChatActivityRewardLogVO.setGrowth(growth);
                groupChatActivityRewardLogVO.setCardInfo(StringUtils.join(cardList, "、"));
            }
            return groupChatActivityRewardLogVO;
        }).collect(Collectors.toList());


    }
}
