package com.tzld.piaoquan.api.service.wecom.thirdparty.impl;

import com.alibaba.fastjson.JSONObject;
import com.tzld.piaoquan.api.common.enums.ExceptionEnum;
import com.tzld.piaoquan.api.common.enums.wecom.ConfigTaskContentTypeEnum;
import com.tzld.piaoquan.api.common.exception.CommonException;
import com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.*;
import com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ext.ThirdPartWeComRoomMapperExt;
import com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ext.ThirdPartWeComStaffMapperExt;
import com.tzld.piaoquan.api.job.wecom.thirdpart.WeComSendMsgJob;
import com.tzld.piaoquan.api.model.param.wecom.thirdpart.*;
import com.tzld.piaoquan.api.model.po.wecom.thirdpart.*;
import com.tzld.piaoquan.api.model.vo.IdNameVO;
import com.tzld.piaoquan.api.model.vo.wecom.thirdpart.*;
import com.tzld.piaoquan.api.service.wecom.thirdparty.WeComThirdPartyRoomService;
import com.tzld.piaoquan.api.service.wecom.thirdparty.WeComThirdPartyService;
import com.tzld.piaoquan.growth.common.utils.DateUtil;
import com.tzld.piaoquan.growth.common.utils.DistributedIdGenerator;
import com.tzld.piaoquan.growth.common.utils.page.Page;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Service
public class WeComThirdPartyRoomServiceImpl implements WeComThirdPartyRoomService {

    @Autowired
    private WeComThirdPartyService weComThirdPartyService;
    @Autowired
    private WeComSendMsgJob weComSendMsgJob;
    @Autowired
    private ThirdPartWeComRoomMapper roomMapper;
    @Autowired
    private ThirdPartWeComRoomUserMapper roomUserMapper;
    @Autowired
    private ThirdPartWeComRoomConfigMapper roomConfigMapper;
    @Autowired
    private ThirdPartWeComRoomConfigTaskMapper roomConfigTaskMapper;
    @Autowired
    private ThirdPartWeComRoomConfigTaskContentMapper roomConfigTaskContentMapper;
    @Autowired
    private ThirdPartWeComStaffMapperExt staffMapperExt;
    @Autowired
    private ThirdPartWeComRoomMapperExt roomMapperExt;

    @Override
    public Page<ThirdPartyRoomVO> list(ThirdPartyRoomListParam param) {
        Page<ThirdPartyRoomVO> result = new Page<>(param.getPageNum(), param.getPageSize());
        int offset = (param.getPageNum() - 1) * param.getPageSize();
        List<Long> pushAccountIds = null;
        if (StringUtils.isNotBlank(param.getPushAccountName())) {
            pushAccountIds = staffMapperExt.getStaffIdByName(param.getPushAccountName());
            if (CollectionUtils.isEmpty(pushAccountIds)) {
                result.setTotalSize(0);
                return result;
            }
        }
        int count = roomMapperExt.getRoomCount(param, pushAccountIds);
        result.setTotalSize(count);
        if (count == 0) {
            return result;
        }
        List<ThirdPartWeComRoom> roomList = roomMapperExt.getRoomList(param, pushAccountIds, offset, param.getPageSize());
        List<ThirdPartyRoomVO> list = buildThirdPartyRoomVOList(roomList);
        result.setObjs(list);
        return result;
    }

    private List<ThirdPartyRoomVO> buildThirdPartyRoomVOList(List<ThirdPartWeComRoom> roomList) {
        List<Long> roomIds = roomList.stream().map(ThirdPartWeComRoom::getId).collect(Collectors.toList());
        List<Long> corpIds = roomList.stream().map(ThirdPartWeComRoom::getCorpId).collect(Collectors.toList());
        List<ThirdPartWeComCorp> corpList = weComThirdPartyService.getCorpListByIds(corpIds);
        Map<Long, ThirdPartWeComCorp> corpMap = corpList.stream()
                .collect(Collectors.toMap(ThirdPartWeComCorp::getId, corp -> corp));
        List<Long> staffIds = roomList.stream().map(ThirdPartWeComRoom::getStaffId).collect(Collectors.toList());
        List<ThirdPartWeComStaff> staffList = weComThirdPartyService.getStaffByIds(staffIds);
        Map<Long, ThirdPartWeComStaff> staffMap = staffList.stream()
                .collect(Collectors.toMap(ThirdPartWeComStaff::getId, staff -> staff));
        List<ThirdPartWeComRoomConfig> roomConfigList = getRoomConfigList(roomIds);
        Map<Long, ThirdPartWeComRoomConfig> roomConfigMap = roomConfigList.stream()
                .collect(Collectors.toMap(ThirdPartWeComRoomConfig::getRoomId, config -> config));
        List<ThirdPartWeComStaff> pushStaffList = getRoomConfigPushList(roomConfigList);
        Map<Long, ThirdPartWeComStaff> pushStaffMap = pushStaffList.stream()
                .collect(Collectors.toMap(ThirdPartWeComStaff::getThirdStaffId, staff -> staff));

        List<ThirdPartyRoomVO> result = new ArrayList<>();
        for (ThirdPartWeComRoom room : roomList) {
            ThirdPartyRoomVO vo = new ThirdPartyRoomVO();
            vo.setId(room.getId());
            vo.setCorpName(corpMap.get(room.getCorpId()).getName());
            vo.setRoomName(room.getName());
            vo.setGroupLeaderName(staffMap.get(room.getStaffId()).getName());
            ThirdPartWeComRoomConfig roomConfig = roomConfigMap.get(room.getId());
            if (Objects.nonNull(roomConfig)) {
                List<IdNameVO<Long>> pushAccountNameList = new ArrayList<>();
                ThirdPartWeComStaff primaryStaff = pushStaffMap.get(roomConfig.getPrimaryThirdStaffId());
                if (Objects.nonNull(primaryStaff)) {
                    pushAccountNameList.add(new IdNameVO<>(primaryStaff.getThirdStaffId(), primaryStaff.getName()));
                }
                ThirdPartWeComStaff secondaryStaff = pushStaffMap.get(roomConfig.getSecondThirdStaffId());
                if (Objects.nonNull(secondaryStaff)) {
                    pushAccountNameList.add(new IdNameVO<>(secondaryStaff.getThirdStaffId(), secondaryStaff.getName()));
                }
                vo.setPushAccountNameList(pushAccountNameList);
            }
            vo.setMemberCount(room.getMemberCount());
            result.add(vo);
        }
        return result;
    }

    private List<ThirdPartWeComRoomConfig> getRoomConfigList(List<Long> roomIds) {
        ThirdPartWeComRoomConfigExample example = new ThirdPartWeComRoomConfigExample();
        example.createCriteria().andRoomIdIn(roomIds).andStatusEqualTo(1);
        return roomConfigMapper.selectByExample(example);
    }

    @Override
    public List<IdNameVO<Long>> getPushAccountList(Long roomId, String name) {
        ThirdPartWeComRoom room = weComThirdPartyService.getRoomById(roomId);
        Long accountId = room.getStaffId();
        List<ThirdPartWeComStaff> pushStaffList = staffMapperExt.getPushStaffList(accountId, roomId, name);
        return pushStaffList.stream().map(staff -> new IdNameVO<>(staff.getThirdStaffId(), staff.getName())).collect(Collectors.toList());
    }

    @Override
    public ThirdPartyRoomConfigVO getRoomConfig(ThirdPartyConfigGetParam param) {
        ThirdPartWeComRoomConfig config = getRoomConfig(param.getId());
        if (Objects.isNull(config)) {
            return null;
        }
        List<ThirdPartWeComStaff> pushStaffList = getRoomConfigPushList(Collections.singletonList(config));
        Map<Long, String> pushStaffMap = pushStaffList.stream()
                .collect(Collectors.toMap(ThirdPartWeComStaff::getThirdStaffId, ThirdPartWeComStaff::getName));
        List<ThirdPartWeComRoomConfigTask> taskList = getRoomConfigTasks(config.getId());
        List<String> taskIds = taskList.stream().map(ThirdPartWeComRoomConfigTask::getId).collect(Collectors.toList());
        List<ThirdPartWeComRoomConfigTaskContent> contentList = getRoomConfigTaskContents(taskIds);
        Map<String, List<ThirdPartWeComRoomConfigTaskContent>> taskContentMap = contentList.stream()
                .collect(Collectors.groupingBy(ThirdPartWeComRoomConfigTaskContent::getTaskId));
        ThirdPartyRoomConfigVO result = new ThirdPartyRoomConfigVO();
        result.setPutScene(config.getPutScene());
        result.setChannel(config.getChannel());
        if (Objects.nonNull(config.getPrimaryThirdStaffId())) {
            result.setPrimaryThirdStaffId(config.getPrimaryThirdStaffId());
            result.setPrimaryThirdStaffName(pushStaffMap.get(config.getPrimaryThirdStaffId()));
        }
        if (Objects.nonNull(config.getSecondThirdStaffId())) {
            result.setSecondThirdStaffId(config.getSecondThirdStaffId());
            result.setSecondThirdStaffName(pushStaffMap.get(config.getSecondThirdStaffId()));
        }
        result.setTaskList(taskList.stream().map(task -> {
            ThirdPartyRoomConfigTaskVO vo = new ThirdPartyRoomConfigTaskVO();
            vo.setSwitchFlag(task.getSwitchFlag());
            vo.setSendTime(JSONObject.parseArray(task.getSendTime(), String.class));
            vo.setRandomMin(task.getRandomMin());
            vo.setSeq(task.getSeq());
            List<ThirdPartWeComRoomConfigTaskContent> contents = taskContentMap.get(task.getId());
            vo.setContentList(contents.stream().map(content -> {
                ThirdPartyRoomConfigTaskContentVO contentVO = new ThirdPartyRoomConfigTaskContentVO();
                contentVO.setType(content.getType());
                contentVO.setContent(content.getContent());
                contentVO.setSource(content.getSource());
                contentVO.setSourceContent(content.getSourceContent());
                contentVO.setSeq(content.getSeq());
                return contentVO;
            }).collect(Collectors.toList()));
            return vo;
        }).collect(Collectors.toList()));
        return result;
    }

    @Override
    public List<ThirdPartWeComStaff> getRoomConfigPushList(List<ThirdPartWeComRoomConfig> configList) {
        if (CollectionUtils.isEmpty(configList)) {
            return Collections.emptyList();
        }
        List<Long> thirdStaffIds = new ArrayList<>();
        for (ThirdPartWeComRoomConfig config : configList) {
            if (Objects.nonNull(config.getPrimaryThirdStaffId())) {
                thirdStaffIds.add(config.getPrimaryThirdStaffId());
            }
            if (Objects.nonNull(config.getSecondThirdStaffId())) {
                thirdStaffIds.add(config.getSecondThirdStaffId());
            }
        }
        return weComThirdPartyService.getStaffListByThirdStaffIds(thirdStaffIds);
    }

    private ThirdPartWeComRoomConfig getRoomConfig(Long roomId) {
        ThirdPartWeComRoomConfigExample example = new ThirdPartWeComRoomConfigExample();
        example.createCriteria().andRoomIdEqualTo(roomId).andStatusEqualTo(1);
        List<ThirdPartWeComRoomConfig> configs = roomConfigMapper.selectByExample(example);
        if (configs.isEmpty()) {
            return null;
        }
        return configs.get(0);
    }

    private List<ThirdPartWeComRoomConfigTask> getRoomConfigTasks(String configId) {
        ThirdPartWeComRoomConfigTaskExample example = new ThirdPartWeComRoomConfigTaskExample();
        example.createCriteria().andConfigIdEqualTo(configId);
        return roomConfigTaskMapper.selectByExample(example);
    }

    @Override
    public List<ThirdPartWeComRoomConfigTask> getRoomConfigTasks(List<String> configIds) {
        if (CollectionUtils.isEmpty(configIds)) {
            return Collections.emptyList();
        }
        ThirdPartWeComRoomConfigTaskExample example = new ThirdPartWeComRoomConfigTaskExample();
        example.createCriteria().andConfigIdIn(configIds);
        return roomConfigTaskMapper.selectByExample(example);
    }

    @Override
    public List<ThirdPartWeComRoomConfigTaskContent> getRoomConfigTaskContents(List<String> taskIds) {
        if (CollectionUtils.isEmpty(taskIds)) {
            return Collections.emptyList();
        }
        ThirdPartWeComRoomConfigTaskContentExample example = new ThirdPartWeComRoomConfigTaskContentExample();
        example.createCriteria().andTaskIdIn(taskIds);
        return roomConfigTaskContentMapper.selectByExample(example);
    }

    @Override
    public void saveRoomConfig(ThirdPartyRoomConfigParam param, String accountConfigId) {
        // check param
        ThirdPartWeComRoom room = weComThirdPartyService.getRoomById(param.getRoomId());
        if (Objects.isNull(room)) {
            throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "群不存在");
        }
        checkRoomConfigParam(param, room);
        ThirdPartWeComRoomConfig config = getRoomConfig(param.getRoomId());
        if (Objects.nonNull(config)) {
            config.setStatus(0);
            config.setUpdateTime(new Date());
            roomConfigMapper.updateByPrimaryKey(config);
        }
        ThirdPartWeComRoomConfig newConfig = new ThirdPartWeComRoomConfig();
        newConfig.setId(DistributedIdGenerator.generate());
        newConfig.setAccountConfigId(accountConfigId);
        newConfig.setRoomId(param.getRoomId());
        newConfig.setPutScene(param.getPutScene());
        newConfig.setChannel(param.getChannel());
        newConfig.setPrimaryThirdStaffId(param.getPrimaryThirdStaffId());
        newConfig.setSecondThirdStaffId(param.getSecondThirdStaffId());
        newConfig.setStatus(1);
        newConfig.setCreateTime(new Date());
        newConfig.setUpdateTime(new Date());
        roomConfigMapper.insert(newConfig);
        List<ThirdPartWeComRoomConfigTask> taskList = new ArrayList<>();
        for (ThirdPartyRoomConfigTaskParam taskParam : param.getTaskList()) {
            ThirdPartWeComRoomConfigTask newTask = new ThirdPartWeComRoomConfigTask();
            newTask.setId(DistributedIdGenerator.generate());
            newTask.setConfigId(newConfig.getId());
            newTask.setSwitchFlag(taskParam.getSwitchFlag());
            newTask.setSendTime(JSONObject.toJSONString(taskParam.getSendTime()));
            newTask.setRandomMin(taskParam.getRandomMin());
            newTask.setSeq(taskParam.getSeq());
            newTask.setCreateTime(new Date());
            newTask.setUpdateTime(new Date());
            roomConfigTaskMapper.insert(newTask);
            taskList.add(newTask);
            for (ThirdPartyRoomConfigTaskContentParam taskContentParam : taskParam.getContentList()) {
                ThirdPartWeComRoomConfigTaskContent newContent = new ThirdPartWeComRoomConfigTaskContent();
                newContent.setId(DistributedIdGenerator.generate());
                newContent.setTaskId(newTask.getId());
                newContent.setType(taskContentParam.getType());
                newContent.setContent(taskContentParam.getContent());
                newContent.setSource(taskContentParam.getSource());
                newContent.setSourceContent(taskContentParam.getSourceContent());
                newContent.setSeq(taskContentParam.getSeq());
                newContent.setCreateTime(new Date());
                newContent.setUpdateTime(new Date());
                roomConfigTaskContentMapper.insert(newContent);
            }
        }
        String now = DateUtil.getCurrentDateStr("HH:mm");
        weComSendMsgJob.randomRoomSendTime(room, newConfig, taskList, now);
    }

    private void checkRoomConfigParam(ThirdPartyRoomConfigParam param, ThirdPartWeComRoom room) {
        if (Objects.isNull(param.getRoomId())) {
            throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "群id不能为空");
        }
        if (StringUtils.isBlank(param.getPutScene())) {
            throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "推送场景不能为空");
        }
        if (Objects.isNull(param.getPrimaryThirdStaffId())) {
            throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "主推送人员不能为空");
        }
        if (CollectionUtils.isEmpty(param.getTaskList())) {
            throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "任务列表不能为空");
        }
        List<ThirdPartWeComRoomUser> roomUserList = getRoomUserListByRoomId(room.getThirdRoomId());
        List<Long> roomUserIdList = roomUserList.stream().map(ThirdPartWeComRoomUser::getUin).collect(Collectors.toList());
        if (!roomUserIdList.contains(param.getPrimaryThirdStaffId())) {
            param.setPrimaryThirdStaffId(room.getThirdCreateUserId());
        }
        if (Objects.nonNull(param.getSecondThirdStaffId()) && !roomUserIdList.contains(param.getSecondThirdStaffId())) {
            param.setSecondThirdStaffId(room.getThirdCreateUserId());
        }
        List<String> timeList = new ArrayList<>();
        for (ThirdPartyRoomConfigTaskParam task : param.getTaskList()) {
            if (CollectionUtils.isEmpty(task.getSendTime())) {
                throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "推送时间不能为空");
            }
            for (String sendTime : task.getSendTime()) {
                if (timeList.contains(sendTime)) {
                    throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "推送时间不能重复: " + sendTime);
                } else {
                    timeList.add(sendTime);
                }
            }
            if (Objects.nonNull(task.getRandomMin())) {
                if (task.getRandomMin() < 0) {
                    throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "随机浮动分钟不能小于0");
                } else if (task.getRandomMin() > 30) {
                    throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "随机浮动分钟不能大于30");
                }
            }
            if (CollectionUtils.isEmpty(task.getContentList()) || task.getContentList().size() > 3) {
                throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "任务内容不能为空，最多3条");
            }
            for (ThirdPartyRoomConfigTaskContentParam content : task.getContentList()) {
                if (Objects.isNull(content.getType())) {
                    throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "任务内容类型不能为空");
                }
                if (content.getType() == ConfigTaskContentTypeEnum.TEXT.getVal()
                        && StringUtils.isBlank(content.getContent())) {
                    throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "文案不能为空");
                } else if (content.getType() == ConfigTaskContentTypeEnum.MINI_PROGRAM.getVal()
                        && Objects.isNull(content.getSource())) {
                    throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "小程序来源不能为空");
                }
            }
        }

    }

    @Override
    public List<ThirdPartWeComRoomUser> getRoomUserListByRoomId(String thirdRoomId) {
        ThirdPartWeComRoomUserExample example = new ThirdPartWeComRoomUserExample();
        example.createCriteria().andThirdRoomIdEqualTo(thirdRoomId);
        return roomUserMapper.selectByExample(example);
    }

    @Override
    public List<ThirdPartWeComRoomUser> getRoomUserListByRoomIds(List<String> thirdRoomIds) {
        if (CollectionUtils.isEmpty(thirdRoomIds)) {
            return new ArrayList<>();
        }
        ThirdPartWeComRoomUserExample example = new ThirdPartWeComRoomUserExample();
        example.createCriteria().andThirdRoomIdIn(thirdRoomIds);
        return roomUserMapper.selectByExample(example);
    }

    @Override
    public void saveRoomConfig(ThirdPartWeComRoom room, String accountConfigId, ThirdPartyAccountConfigParam param) {
        ThirdPartyRoomConfigParam roomConfigParam = buildRoomConfigParam(room, param);
        saveRoomConfig(roomConfigParam, accountConfigId);
    }

    private ThirdPartyRoomConfigParam buildRoomConfigParam(ThirdPartWeComRoom room, ThirdPartyAccountConfigParam param) {
        ThirdPartyRoomConfigParam roomConfigParam = new ThirdPartyRoomConfigParam();
        roomConfigParam.setRoomId(room.getId());
        roomConfigParam.setPutScene(param.getPutScene());
        roomConfigParam.setChannel(param.getChannel());
        roomConfigParam.setOpenRoomSendSwitchNum(param.getOpenRoomSendSwitchNum());
        roomConfigParam.setPrimaryThirdStaffId(param.getPrimaryThirdStaffId());
        roomConfigParam.setPrimaryThirdStaffName(param.getPrimaryThirdStaffName());
        roomConfigParam.setSecondThirdStaffId(param.getSecondThirdStaffId());
        roomConfigParam.setSecondThirdStaffName(param.getSecondThirdStaffName());
        List<ThirdPartyRoomConfigTaskParam> taskList = new ArrayList<>();
        for (ThirdPartyAccountConfigTaskParam taskParam : param.getTaskList()) {
            ThirdPartyRoomConfigTaskParam task = new ThirdPartyRoomConfigTaskParam();
            task.setSwitchFlag(taskParam.getSwitchFlag());
            task.setSendTime(taskParam.getSendTime());
            task.setRandomMin(taskParam.getRandomMin());
            task.setSeq(taskParam.getSeq());
            List<ThirdPartyRoomConfigTaskContentParam> contentList = new ArrayList<>();
            for (ThirdPartyAccountConfigTaskContentParam taskContentParam : taskParam.getContentList()) {
                ThirdPartyRoomConfigTaskContentParam content = new ThirdPartyRoomConfigTaskContentParam();
                content.setType(taskContentParam.getType());
                content.setContent(taskContentParam.getContent());
                content.setSource(taskContentParam.getSource());
                content.setSourceContent(taskContentParam.getSourceContent());
                content.setSeq(taskContentParam.getSeq());
                contentList.add(content);
            }
            task.setContentList(contentList);
            taskList.add(task);
        }
        roomConfigParam.setTaskList(taskList);
        return roomConfigParam;
    }

    @Override
    public void saveRoomConfig(ThirdPartWeComRoom room, String accountConfigId, ThirdPartyAccountConfigVO configVO) {
        ThirdPartyRoomConfigParam roomConfigParam = buildRoomConfigParam(room, configVO);
        saveRoomConfig(roomConfigParam, accountConfigId);
    }

    private ThirdPartyRoomConfigParam buildRoomConfigParam(ThirdPartWeComRoom room, ThirdPartyAccountConfigVO configVO) {
        ThirdPartyRoomConfigParam roomConfigParam = new ThirdPartyRoomConfigParam();
        roomConfigParam.setRoomId(room.getId());
        roomConfigParam.setPutScene(configVO.getPutScene());
        roomConfigParam.setChannel(configVO.getChannel());
        roomConfigParam.setOpenRoomSendSwitchNum(configVO.getOpenRoomSendSwitchNum());
        roomConfigParam.setPrimaryThirdStaffId(configVO.getPrimaryThirdStaffId());
        roomConfigParam.setPrimaryThirdStaffName(configVO.getPrimaryThirdStaffName());
        roomConfigParam.setSecondThirdStaffId(configVO.getSecondThirdStaffId());
        roomConfigParam.setSecondThirdStaffName(configVO.getSecondThirdStaffName());
        List<ThirdPartyRoomConfigTaskParam> taskList = new ArrayList<>();
        for (ThirdPartyAccountConfigTaskVO taskVO : configVO.getTaskList()) {
            ThirdPartyRoomConfigTaskParam task = new ThirdPartyRoomConfigTaskParam();
            task.setSwitchFlag(taskVO.getSwitchFlag());
            task.setSendTime(taskVO.getSendTime());
            task.setRandomMin(taskVO.getRandomMin());
            task.setSeq(taskVO.getSeq());
            List<ThirdPartyRoomConfigTaskContentParam> contentList = new ArrayList<>();
            for (ThirdPartyAccountConfigTaskContentVO taskContentVO : taskVO.getContentList()) {
                ThirdPartyRoomConfigTaskContentParam content = new ThirdPartyRoomConfigTaskContentParam();
                content.setType(taskContentVO.getType());
                content.setContent(taskContentVO.getContent());
                content.setSource(taskContentVO.getSource());
                content.setSourceContent(taskContentVO.getSourceContent());
                content.setSeq(taskContentVO.getSeq());
                contentList.add(content);
            }
            task.setContentList(contentList);
            taskList.add(task);
        }
        roomConfigParam.setTaskList(taskList);
        return roomConfigParam;
    }

    @Override
    public List<ThirdPartWeComRoomConfig> getRoomConfigListByRoomIds(List<Long> roomIds) {
        if (CollectionUtils.isEmpty(roomIds)) {
            return Collections.emptyList();
        }
        ThirdPartWeComRoomConfigExample example = new ThirdPartWeComRoomConfigExample();
        example.createCriteria().andRoomIdIn(roomIds).andStatusEqualTo(1);
        return roomConfigMapper.selectByExample(example);
    }

    @Override
    public List<ThirdPartWeComRoom> getRoomListByRoomIds(List<Long> roomIds) {
        if (CollectionUtils.isEmpty(roomIds)) {
            return Collections.emptyList();
        }
        ThirdPartWeComRoomExample example = new ThirdPartWeComRoomExample();
        example.createCriteria().andIdIn(roomIds).andIsDeleteEqualTo(0);
        return roomMapper.selectByExample(example);
    }

    @Override
    public List<ThirdPartWeComRoomConfig> getAccountConfigRoomConfigList(String accountConfigId) {
        ThirdPartWeComRoomConfigExample example = new ThirdPartWeComRoomConfigExample();
        example.createCriteria().andAccountConfigIdEqualTo(accountConfigId).andStatusEqualTo(1);
        return roomConfigMapper.selectByExample(example);
    }
}
