package jnpf.notice.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import jnpf.cultivate.utils.UserApiV2Util;
import jnpf.model.cultivate.dto.learn.BatchCommonCountDto;
import jnpf.model.cultivate.vo.common.InnerPowerUserVO;
import jnpf.model.notice.domain.FtbNoticeAnnouncements;
import jnpf.model.notice.domain.FtbNoticeAnnouncementsReceive;
import jnpf.model.notice.dto.FtbNoticeAnnouncementsReceiveDto;
import jnpf.model.notice.enums.NoticeEnums;
import jnpf.model.notice.req.announcement.QueryUserListReq;
import jnpf.notice.mapper.FtbNoticeAnnouncementsReceiveMapper;
import jnpf.notice.service.FtbNoticeAnnouncementsReceiveService;
import jnpf.notice.service.FtbNoticeAnnouncementsService;
import jnpf.notice.utils.NoticeUtils;
import jnpf.permission.entity.UserEntity;
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;

/**
 * @author 许贵林
 * @description 针对表【ftb_notice_announcements_receive(公告用户接收表)】的数据库操作Service实现
 * @createDate 2024-05-08 09:42:09
 */
@Service
public class FtbNoticeAnnouncementsReceiveServiceImpl extends ServiceImpl<FtbNoticeAnnouncementsReceiveMapper, FtbNoticeAnnouncementsReceive>
        implements FtbNoticeAnnouncementsReceiveService {


    @Autowired
    private NoticeUtils noticeUtils;

    @Autowired
    private FtbNoticeAnnouncementsService ftbNoticeAnnouncementsService;
    @Autowired
    private UserApiV2Util userApiV2Util;

    /**
     * 根据公告ID查询用户
     *
     * @param announcementId 公告ID
     */
    @Override
    public List<FtbNoticeAnnouncementsReceiveDto> queryUserList(String announcementId) {
        LambdaQueryWrapper<FtbNoticeAnnouncementsReceive> wrapper = new LambdaQueryWrapper<FtbNoticeAnnouncementsReceive>()
                .eq(FtbNoticeAnnouncementsReceive::getAnnouncementId, announcementId)
                .eq(FtbNoticeAnnouncementsReceive::getIsCancel, NoticeEnums.UserNoticeCancelStatus.NOT_CANCEL.getCode())// 是否撤销，0未撤销 1已撤销
                .eq(FtbNoticeAnnouncementsReceive::getEnabledMark, NoticeEnums.DeleteType.VALID.getCode());
        List<FtbNoticeAnnouncementsReceive> list = baseMapper.selectList(wrapper);
        return convertFtbNoticeAnnouncementsReceiveDto(list);
    }


    /**
     * 查询用户列表
     *
     * @param req
     * @param selectUserOrgAndPosition 是否查询用户组织及职位 true 查询 false 不查询
     * @return
     */
    @Override
    public PageInfo<FtbNoticeAnnouncementsReceiveDto> queryUserListForReadStatus(QueryUserListReq req, Boolean selectUserOrgAndPosition) {
        //判断如果是全部用户 且 草稿 待发布 撤销状态  直接查询所有用户
        FtbNoticeAnnouncements noticeAnnouncements = ftbNoticeAnnouncementsService.queryAndCheckById(req.getAnnouncementId());
        NoticeEnums.ReceiveUserTypeEnum receiveUserTypeEnum = NoticeEnums.ReceiveUserTypeEnum.getByCode(noticeAnnouncements.getReceiveUserType());
        NoticeEnums.NoticeStatus oldNoticeStaus = NoticeEnums.NoticeStatus.fromCode(noticeAnnouncements.getStatus());
        if (receiveUserTypeEnum == NoticeEnums.ReceiveUserTypeEnum.ALL
                && oldNoticeStaus != NoticeEnums.NoticeStatus.PUBLISHED) {
            if (req.getType().equals(1)) {
                return queryAllAcceptUser(req);
            } else {
                return PageInfo.EMPTY;
            }
        }
        List<String> powerUserIds = new ArrayList<>();
        if(NoticeEnums.NoticeStatus.PUBLISHED!=oldNoticeStaus){
                //过滤权限
                InnerPowerUserVO innerPowerUserVO = userApiV2Util.getLoginManagerUserIdsForEncode();
                if(innerPowerUserVO.getCode().equals(2)){
                    powerUserIds = List.of("-1");
                } else if (innerPowerUserVO.getCode().equals(1)) {
                    powerUserIds.addAll(innerPowerUserVO.getUserIds());
                }
        }
        req.setPowerUserIds(powerUserIds);

        Page<FtbNoticeAnnouncementsReceiveDto> queryPage = baseMapper.queryUserListForReadStatus(Page.of(req.getCurrentPage(), req.getPageSize()), req);
        List<FtbNoticeAnnouncementsReceiveDto> records = queryPage.getRecords();

        if (CollectionUtil.isNotEmpty(records)) {
            noticeUtils.fillFlowerAndHeadLog(records);
        }
        //构建分页返回数据
        PageInfo<FtbNoticeAnnouncementsReceiveDto> pageInfo = new PageInfo<>();
        pageInfo.setList(records);
        pageInfo.setPageSize((int) queryPage.getSize());
        pageInfo.setPageNum((int) queryPage.getCurrent());
        pageInfo.setTotal((int) queryPage.getTotal());
        return pageInfo;
    }

    /**
     * 查询全部接受用户
     * @param req
     * @return
     */
    private PageInfo<FtbNoticeAnnouncementsReceiveDto> queryAllAcceptUser(QueryUserListReq req) {
        return noticeUtils.queryUserByPage(req);

    }

    /**
     * 根据提醒状态 查询公告的用户
     *
     * @param announcementId 公告ID
     * @param alertStatus    提醒状态 1未提醒 2已提醒
     * @return
     */
    @Override
    public List<FtbNoticeAnnouncementsReceiveDto> queryUserListForAlertStatus(String announcementId, Integer alertStatus) {
        LambdaQueryWrapper<FtbNoticeAnnouncementsReceive> wrapper = new LambdaQueryWrapper<FtbNoticeAnnouncementsReceive>()
                .eq(FtbNoticeAnnouncementsReceive::getAnnouncementId, announcementId)
                .eq(FtbNoticeAnnouncementsReceive::getAlertStatus, alertStatus) //1未提醒 2已提醒
                .eq(FtbNoticeAnnouncementsReceive::getIsCancel, NoticeEnums.UserNoticeCancelStatus.NOT_CANCEL.getCode()) //0未撤销 1已撤销
                .eq(FtbNoticeAnnouncementsReceive::getEnabledMark, NoticeEnums.DeleteType.VALID.getCode());
        List<FtbNoticeAnnouncementsReceive> list = baseMapper.selectList(wrapper);
        return convertFtbNoticeAnnouncementsReceiveDto(list);
    }

    /**
     * 查询需要提醒的用户列表
     * @param announcementId 公告的唯一标识符
     * @return
     */
    @Override
    public List<FtbNoticeAnnouncementsReceiveDto> queryNeedAlertUserList(String announcementId) {
        LambdaQueryWrapper<FtbNoticeAnnouncementsReceive> wrapper = new LambdaQueryWrapper<FtbNoticeAnnouncementsReceive>()
                .eq(FtbNoticeAnnouncementsReceive::getAnnouncementId, announcementId)
                .eq(FtbNoticeAnnouncementsReceive::getAlertStatus, NoticeEnums.AlertStatus.UNNOTIFIED.getCode()) //1未提醒 2已提醒
                .eq(FtbNoticeAnnouncementsReceive::getReadStatus, NoticeEnums.ReadStatus.UNREAD.getCode()) //是否已读，1未读，2已读
                .eq(FtbNoticeAnnouncementsReceive::getIsCancel, NoticeEnums.UserNoticeCancelStatus.NOT_CANCEL.getCode()) //0未撤销 1已撤销
                .eq(FtbNoticeAnnouncementsReceive::getEnabledMark, NoticeEnums.DeleteType.VALID.getCode());
        List<FtbNoticeAnnouncementsReceive> list = baseMapper.selectList(wrapper);
        return convertFtbNoticeAnnouncementsReceiveDto(list);
    }

    /**
     * 完成提醒
     *
     * @param announcementId
     */
    @Override
    public void updateCompleteAlertAll(String announcementId) {
        LambdaUpdateWrapper<FtbNoticeAnnouncementsReceive> updateWrapper = Wrappers.lambdaUpdate();
        updateWrapper.eq(FtbNoticeAnnouncementsReceive::getAnnouncementId, announcementId)
                .eq(FtbNoticeAnnouncementsReceive::getAlertStatus, NoticeEnums.AlertStatus.UNNOTIFIED.getCode()) //1未提醒 2已提醒
                .eq(FtbNoticeAnnouncementsReceive::getIsCancel, NoticeEnums.UserNoticeCancelStatus.NOT_CANCEL.getCode()) //0未撤销 1已撤销
                .eq(FtbNoticeAnnouncementsReceive::getEnabledMark, NoticeEnums.DeleteType.VALID.getCode())
                .set(FtbNoticeAnnouncementsReceive::getAlertStatus, NoticeEnums.AlertStatus.NOTIFIED.getCode())
                .set(FtbNoticeAnnouncementsReceive::getAlertTime, new Date());
        baseMapper.update(new FtbNoticeAnnouncementsReceive(), updateWrapper);
    }
    /**
     * 修改一个用户已经完成提醒
     *
     * @param announcementId
     * @param userId
     */
    @Override
    public void updateCompleteAlert(String announcementId, String userId) {
        LambdaUpdateWrapper<FtbNoticeAnnouncementsReceive> updateWrapper = Wrappers.lambdaUpdate();
        updateWrapper.eq(FtbNoticeAnnouncementsReceive::getAnnouncementId, announcementId)
                .eq(FtbNoticeAnnouncementsReceive::getAlertStatus, NoticeEnums.AlertStatus.UNNOTIFIED.getCode()) //1未提醒 2已提醒
                .eq(FtbNoticeAnnouncementsReceive::getUserId, userId)
                .set(FtbNoticeAnnouncementsReceive::getAlertStatus, NoticeEnums.AlertStatus.NOTIFIED.getCode())
                .set(FtbNoticeAnnouncementsReceive::getAlertTime, new Date());
        baseMapper.update(new FtbNoticeAnnouncementsReceive(), updateWrapper);
    }
    /**
     * 完成阅读
     *
     * @param announcementId
     * @param userId
     */
    @Override
    public void updateCompleteRead(String announcementId, String userId) {
        LambdaUpdateWrapper<FtbNoticeAnnouncementsReceive> updateWrapper = Wrappers.lambdaUpdate();
        updateWrapper.eq(FtbNoticeAnnouncementsReceive::getAnnouncementId, announcementId)
                .eq(FtbNoticeAnnouncementsReceive::getReadStatus, NoticeEnums.ReadStatus.UNREAD.getCode()) //1未读，2已读
                .eq(FtbNoticeAnnouncementsReceive::getEnabledMark, NoticeEnums.DeleteType.VALID.getCode())
                .eq(FtbNoticeAnnouncementsReceive::getUserId, userId)
                .set(FtbNoticeAnnouncementsReceive::getReadStatus, NoticeEnums.ReadStatus.READ.getCode())
                .set(FtbNoticeAnnouncementsReceive::getReadTime, new Date());
        baseMapper.update(new FtbNoticeAnnouncementsReceive(), updateWrapper);
    }


    /**
     * 根据公告ID和用户ID查询用户
     *
     * 此方法旨在处理特定公告与用户的关联查询，用于获取特定公告的用户信息
     *
     * @param announcementId 公告ID，用于标识特定的公告
     * @param userId 用户ID，用于标识特定的用户
     * @return 返回包含公告和用户信息的对象，便于进一步处理和展示
     */
    @Override
    public FtbNoticeAnnouncementsReceive queryUserForUserId(String announcementId, String userId) {
        LambdaQueryWrapper<FtbNoticeAnnouncementsReceive> wrapper = new LambdaQueryWrapper<FtbNoticeAnnouncementsReceive>()
                .eq(FtbNoticeAnnouncementsReceive::getAnnouncementId, announcementId)
                .eq(FtbNoticeAnnouncementsReceive::getUserId, userId)
                .eq(FtbNoticeAnnouncementsReceive::getIsCancel, NoticeEnums.UserNoticeCancelStatus.NOT_CANCEL.getCode()) //0未撤销 1已撤销
                .eq(FtbNoticeAnnouncementsReceive::getEnabledMark, NoticeEnums.DeleteType.VALID.getCode());
        List<FtbNoticeAnnouncementsReceive> list = baseMapper.selectList(wrapper);
        if (CollectionUtil.isEmpty(list)) {
            return null;
        }
        return list.get(0);

    }
    /**
     * 根据用户ID查询用户通知公告记录（忽略删除状态）
     * 此方法用于获取特定用户的通知公告记录，即使该记录被标记为已删除也能查询到
     * 主要用于后台管理或数据统计等场景，需要管理员权限
     *
     * @param announcementId 公告ID，用于标识特定的通知公告
     * @param userId 用户ID，用于标识接收通知公告的用户
     * @return 返回匹配指定公告ID和用户ID的通知公告记录，包括未删除和已删除的记录
     */
    @Override
    public FtbNoticeAnnouncementsReceive queryUserForUserIdIngoreDelete(String announcementId, String userId) {
        LambdaQueryWrapper<FtbNoticeAnnouncementsReceive> wrapper = new LambdaQueryWrapper<FtbNoticeAnnouncementsReceive>()
                .eq(FtbNoticeAnnouncementsReceive::getAnnouncementId, announcementId)
                .eq(FtbNoticeAnnouncementsReceive::getUserId, userId);
        List<FtbNoticeAnnouncementsReceive> list = baseMapper.selectList(wrapper);
        if (CollectionUtil.isEmpty(list)) {
            return null;
        }
        return list.get(0);

    }
    /**
     * 检查查询公告 是否已读，返回未读列表
     *
     * @param userId
     * @param ids
     * @return
     */
    @Override
    public List<String> checkIsRead(String userId, List<String> ids) {
        LambdaQueryWrapper<FtbNoticeAnnouncementsReceive> wrapper = new LambdaQueryWrapper<FtbNoticeAnnouncementsReceive>()
                .select(FtbNoticeAnnouncementsReceive::getAnnouncementId)
                .in(FtbNoticeAnnouncementsReceive::getAnnouncementId, ids)
                .eq(FtbNoticeAnnouncementsReceive::getUserId, userId)
                .eq(FtbNoticeAnnouncementsReceive::getReadStatus, NoticeEnums.ReadStatus.UNREAD.getCode())
                .eq(FtbNoticeAnnouncementsReceive::getIsCancel, NoticeEnums.UserNoticeCancelStatus.NOT_CANCEL.getCode()) //0未撤销 1已撤销
                .eq(FtbNoticeAnnouncementsReceive::getEnabledMark, NoticeEnums.DeleteType.VALID.getCode()).orderByDesc(FtbNoticeAnnouncementsReceive::getCreatorTime);
        List<FtbNoticeAnnouncementsReceive> list = baseMapper.selectList(wrapper);
        if (CollectionUtil.isEmpty(list)) {
            return new ArrayList<>();
        }
        List<String> noReadLit = new ArrayList<>();
        for (FtbNoticeAnnouncementsReceive ftbNoticeAnnouncementsReceive : list) {
            noReadLit.add(ftbNoticeAnnouncementsReceive.getAnnouncementId());
        }
        return noReadLit;
    }
    /**
     * 查询公告阅读状态的数量
     *
     * @param announcementId
     * @param readStatus     1未读，2已读
     * @return
     */
    @Override
    public Long queryReadStatusCount(String announcementId, Integer readStatus) {
        LambdaQueryWrapper<FtbNoticeAnnouncementsReceive> wrapper = new LambdaQueryWrapper<FtbNoticeAnnouncementsReceive>()
                .select(FtbNoticeAnnouncementsReceive::getUserId)
                .eq(FtbNoticeAnnouncementsReceive::getAnnouncementId, announcementId)
                .eq(FtbNoticeAnnouncementsReceive::getReadStatus, readStatus)
                .eq(FtbNoticeAnnouncementsReceive::getIsCancel, NoticeEnums.UserNoticeCancelStatus.NOT_CANCEL.getCode()) //0未撤销 1已撤销
                .eq(FtbNoticeAnnouncementsReceive::getEnabledMark, NoticeEnums.DeleteType.VALID.getCode()).orderByDesc(FtbNoticeAnnouncementsReceive::getCreatorTime);
        List<FtbNoticeAnnouncementsReceive> list= baseMapper.selectList(wrapper);
        if (CollectionUtil.isEmpty( list)) {
            return 0L;
        }
        List<String> userIds = list.stream().map(FtbNoticeAnnouncementsReceive::getUserId).collect(Collectors.toList());
        List<UserEntity> userNameForUserIdsReturnList = userApiV2Util.getUserNameForUserIdsReturnList(userIds);
        return Long.valueOf(userNameForUserIdsReturnList.size());

    }
    /**
     * 查询未提醒用户数量
     *
     * @param announcementId
     * @return
     */
    @Override
    public Long queryNoAlertUserNum(String announcementId) {
        LambdaQueryWrapper<FtbNoticeAnnouncementsReceive> wrapper = new LambdaQueryWrapper<FtbNoticeAnnouncementsReceive>()
                .eq(FtbNoticeAnnouncementsReceive::getAnnouncementId, announcementId)
                .eq(FtbNoticeAnnouncementsReceive::getAlertStatus, NoticeEnums.AlertStatus.UNNOTIFIED.getCode())
                .eq(FtbNoticeAnnouncementsReceive::getIsCancel, NoticeEnums.UserNoticeCancelStatus.NOT_CANCEL.getCode()) //0未撤销 1已撤销
                .eq(FtbNoticeAnnouncementsReceive::getEnabledMark, NoticeEnums.DeleteType.VALID.getCode()).orderByDesc(FtbNoticeAnnouncementsReceive::getCreatorTime);
        List<FtbNoticeAnnouncementsReceive> list = baseMapper.selectList(wrapper);
        if (CollectionUtil.isEmpty(list)) {
            return 0L;
        }
        List<String> userIds = list.stream().map(FtbNoticeAnnouncementsReceive::getUserId).collect(Collectors.toList());
        List<UserEntity> userNameForUserIdsReturnList = userApiV2Util.getUserNameForUserIdsReturnList(userIds);
        return Long.valueOf(userNameForUserIdsReturnList.size());
    }
    /**
     * 取消网页公告提醒
     *
     * @param announcementId 公告的唯一标识符
     * @param userId 用户的唯一标识符
     */
    @Override
    public void cancelWebAlert(String announcementId, String userId) {
        LambdaUpdateWrapper<FtbNoticeAnnouncementsReceive> updateWrapper = Wrappers.lambdaUpdate();
        updateWrapper.eq(FtbNoticeAnnouncementsReceive::getAnnouncementId, announcementId)
                .eq(FtbNoticeAnnouncementsReceive::getUserId, userId)
                .set(FtbNoticeAnnouncementsReceive::getWebCancel, 1);
        baseMapper.update(new FtbNoticeAnnouncementsReceive(), updateWrapper);
    }

    /**
     * 添加公告接收用户
     *
     * @param announcementsId 公告ID
     * @param userList        接收用户列表
     */
    @Override
    public List<FtbNoticeAnnouncementsReceive> addReceiveUser(String announcementsId, List<String> userList) {
        if (CollectionUtil.isEmpty(userList) || StringUtils.isEmpty(announcementsId)) {
            return new ArrayList<>();
        }
        //兼容 重复撤销和发布
        Map<String, FtbNoticeAnnouncementsReceive> map = new HashMap<>();
        LambdaQueryWrapper<FtbNoticeAnnouncementsReceive> wrapper = new LambdaQueryWrapper<FtbNoticeAnnouncementsReceive>()
                .select(FtbNoticeAnnouncementsReceive::getId, FtbNoticeAnnouncementsReceive::getUserId)
                .eq(FtbNoticeAnnouncementsReceive::getAnnouncementId, announcementsId);
        List<FtbNoticeAnnouncementsReceive> oldList = baseMapper.selectList(wrapper);
        if (CollectionUtil.isNotEmpty(oldList)) {
            for (FtbNoticeAnnouncementsReceive ftbNoticeAnnouncementsReceive : oldList) {
                map.put(ftbNoticeAnnouncementsReceive.getUserId(), ftbNoticeAnnouncementsReceive);
            }
        }

        List<FtbNoticeAnnouncementsReceive> addList = new ArrayList<>();
        List<FtbNoticeAnnouncementsReceive> updateList = new ArrayList<>();
        for (String userId : userList) {
            FtbNoticeAnnouncementsReceive receive = new FtbNoticeAnnouncementsReceive();
            FtbNoticeAnnouncementsReceive old = map.get(userId);

            receive.setAnnouncementId(announcementsId);
            receive.setUserId(userId);
            receive.setIsCancel(NoticeEnums.UserNoticeCancelStatus.NOT_CANCEL.getCode());
            receive.setAlertStatus(NoticeEnums.AlertStatus.UNNOTIFIED.getCode());
            receive.setReadStatus(NoticeEnums.ReadStatus.UNREAD.getCode());
            receive.setEnabledMark(NoticeEnums.DeleteType.VALID.getCode());
            receive.setWebCancel(0);
            receive.setCreatorTime(new Date());
            if (null != old) {
                receive.setId(old.getId());
                updateList.add(receive);
            } else {
                addList.add(receive);
            }

        }
        if (CollectionUtil.isNotEmpty(updateList)) {
            updateBatchById(updateList);
        }
        if (CollectionUtil.isNotEmpty(addList)) {
            saveBatch(addList);
        }
        addList.addAll(updateList);
        return addList;
    }
    /**
     * 删除公告接收用户
     *
     * @param announcementsId 公告ID
     */
    @Override
    public void deleteReceiveUser(String announcementsId) {
        LambdaUpdateWrapper<FtbNoticeAnnouncementsReceive> updateWrapper = Wrappers.lambdaUpdate();
        updateWrapper.eq(FtbNoticeAnnouncementsReceive::getAnnouncementId, announcementsId);
        updateWrapper.set(FtbNoticeAnnouncementsReceive::getEnabledMark, NoticeEnums.DeleteType.INVALID.getCode());
        baseMapper.update(new FtbNoticeAnnouncementsReceive(), updateWrapper);
    }
    /**
     * 取消接收用户通知
     *
     * @param announcementId 通知的唯一标识符，用于标识特定的通知
     */
    @Override
    public void cancelReceiveUser(String announcementId) {
        LambdaUpdateWrapper<FtbNoticeAnnouncementsReceive> updateWrapper = Wrappers.lambdaUpdate();
        updateWrapper.eq(FtbNoticeAnnouncementsReceive::getAnnouncementId, announcementId);
        updateWrapper.set(FtbNoticeAnnouncementsReceive::getIsCancel, NoticeEnums.UserNoticeCancelStatus.CANCEL.getCode());
        baseMapper.update(new FtbNoticeAnnouncementsReceive(), updateWrapper);
    }
    /**
     * 重置通知的已读、提醒和网页取消状态
     *
     * @param announcementId 通知的唯一标识符，用于标识特定的通知
     */
    @Override
    public void resetReadAndAlertAndWebCancel(String announcementId) {
        LambdaUpdateWrapper<FtbNoticeAnnouncementsReceive> updateWrapper = Wrappers.lambdaUpdate();
        updateWrapper.eq(FtbNoticeAnnouncementsReceive::getAnnouncementId, announcementId);
        updateWrapper.eq(FtbNoticeAnnouncementsReceive::getIsCancel, NoticeEnums.UserNoticeCancelStatus.NOT_CANCEL.getCode());
        updateWrapper.eq(FtbNoticeAnnouncementsReceive::getEnabledMark, NoticeEnums.DeleteType.VALID.getCode());
        updateWrapper.set(FtbNoticeAnnouncementsReceive::getAlertStatus, NoticeEnums.AlertStatus.UNNOTIFIED.getCode());
        updateWrapper.set(FtbNoticeAnnouncementsReceive::getReadStatus, NoticeEnums.ReadStatus.UNREAD.getCode());
        updateWrapper.set(FtbNoticeAnnouncementsReceive::getWebCancel, 0);
        baseMapper.update(new FtbNoticeAnnouncementsReceive(), updateWrapper);
    }
    /**
     * 编辑公告时，处理公告接收用户
     *
     * @param announcementId 公告ID
     * @param noticeStatus
     */
    @Override
    public void dealAnnouncementUserWhenEdit(String announcementId, List<String> userList, NoticeEnums.NoticeStatus noticeStatus) {

        LambdaUpdateWrapper<FtbNoticeAnnouncementsReceive> updateWrapper = Wrappers.lambdaUpdate();
        updateWrapper.eq(FtbNoticeAnnouncementsReceive::getAnnouncementId, announcementId);
        updateWrapper.set(FtbNoticeAnnouncementsReceive::getIsCancel, NoticeEnums.UserNoticeCancelStatus.CANCEL.getCode());
        baseMapper.update(new FtbNoticeAnnouncementsReceive(), updateWrapper);


    }

    /**
     * 对象转换
     * @param list
     * @return
     */
    private List<FtbNoticeAnnouncementsReceiveDto> convertFtbNoticeAnnouncementsReceiveDto(List<FtbNoticeAnnouncementsReceive> list) {
        if (CollectionUtil.isEmpty(list)) {
            return new ArrayList<>();
        }
        return BeanUtil.copyToList(list, FtbNoticeAnnouncementsReceiveDto.class);
    }


    /**
     * 根据公告id查询用户数量
     * @param adList 公告id
     * @return 公告数量
     */
    @Override
    public List<BatchCommonCountDto> queryCountAcceptUserNum(List<String> adList) {
        return baseMapper.queryCountAcceptUserNum(adList);
    }

    /**
     * 批量根据公告id查询用户未提醒数量
     * @param adList 公告id
     * @return 公告数量
     */
    @Override
    public List<BatchCommonCountDto> batchQueryNoAlertUserNum(List<String> adList) {
        return baseMapper.batchQueryNoAlertUserNum(adList);
    }
}




