package com.ruoyi.busi.service.impl;

import java.util.*;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.base.domain.BaseCategory;
import com.ruoyi.base.domain.BaseCity;
import com.ruoyi.base.service.IBaseCategoryService;
import com.ruoyi.base.service.IBaseCityService;
import com.ruoyi.busi.domain.*;
import com.ruoyi.busi.mapper.BusiNoticeSignMapper;
import com.ruoyi.busi.query.AppNoticeQuery;
import com.ruoyi.busi.service.IBusiNoticeFormService;
import com.ruoyi.busi.service.IBusiSubscribeService;
import com.ruoyi.busi.service.IBusiUserLoveService;
import com.ruoyi.busi.vo.BusiNoticeVo;
import com.ruoyi.busi.vo.SubscribeDataObj;
import com.ruoyi.common.core.domain.DlBaseEntity;

import java.util.stream.Collectors;

import cn.hutool.core.date.DateUtil;
import com.ruoyi.busi.utils.NoticeUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.busi.query.BusiNoticeQuery;
import com.ruoyi.constant.DictConstants;
import com.ruoyi.member.domain.MemberApply;
import com.ruoyi.member.domain.MemberUser;
import com.ruoyi.member.service.IMemberApplyService;
import com.ruoyi.member.service.IMemberUserService;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.ISysDictTypeService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.busi.mapper.BusiNoticeMapper;
import com.ruoyi.busi.service.IBusiNoticeService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 通告Service业务层处理
 *
 * @author 朱春云
 * @date 2025-03-17
 */
@Service
public class BusiNoticeServiceImpl extends ServiceImpl<BusiNoticeMapper,BusiNotice>  implements IBusiNoticeService
{
    @Autowired
    private IBaseCategoryService baseCategoryService;
    @Autowired
    private BusiNoticeMapper busiNoticeMapper;
    @Autowired
    private BusiNoticeSignMapper busiNoticeSignMapper;
    @Autowired
    private NoticeUtils noticeUtils;
    @Autowired
    private IBusiUserLoveService userLoveService;
    @Autowired
    private ISysUserService userService;
    @Autowired
    private IMemberUserService memberUserService;
    @Autowired
    private ISysDictDataService dictDataService;
    @Autowired
    private IBusiSubscribeService subscribeService;
    @Autowired
    private IBusiNoticeFormService busiNoticeFormService;
    @Autowired
    private IBaseCityService cityService;


    @Override
    public IPage<BusiNoticeVo> queryListPage(BusiNoticeQuery query, Page<BusiNotice> page) {
        return busiNoticeMapper.queryListPage(query, page);
    }

    /**
     * 新增通告
     * @param data 通告对象
     */
    @Override
    @Transactional
    public void saveVo(BusiNotice data) {
        //获取当前登录用户
        data.setUserId(SecurityUtils.getUserId());
        if (StringUtils.isNotEmpty(data.getApprovalStatus())&&data.getApprovalStatus().equals("8")){
            //草稿数据直接保存
            this.save(data);
        }else {
            //判断 内容重复度 是否大于70%
            //先获取 当前系统中截止日期之前的
            LambdaQueryWrapper<BusiNotice> queryWrapper =new LambdaQueryWrapper<>();
            queryWrapper.gt(BusiNotice::getEndDate, DateUtil.format(new Date(),"yyyy-MM-dd")).eq(BusiNotice::getApprovalStatus,1);
            List<BusiNotice> list = this.list(queryWrapper);
            //无问题数据直接审核通过
            data.setApprovalStatus("1");
            data.setApprovalUserId(null);
            data.setApprovalTime(new Date());
            //遍历 list的每条数据与data对比，如果两条数据相似度大于70% 提出预警
            for (BusiNotice busiNotice : list) {
                double v1 = NoticeUtils.computeJaccardSimilarity(data.getTitle(), busiNotice.getTitle());
                double v2 = NoticeUtils.computeJaccardSimilarity(data.getDetail(), busiNotice.getDetail());
                if (v1>=0.7&&v2>=0.7){
                    //title 和 detail 相似度大于70% 待审核
                    data.setApprovalStatus("0");
                    data.setSimilarityIds(Optional.ofNullable(data.getSimilarityIds()).orElse("")+busiNotice.getId()+",");
                }
            }
            if (StringUtils.isNotEmpty(data.getSimilarityIds())){
                //删除结尾的最后一个逗号
                data.setSimilarityIds(data.getSimilarityIds().substring(0, data.getSimilarityIds().length() - 1));
            }
            this.save(data);
        }
        //保存表单数据
        if (CollectionUtil.isNotEmpty(data.getCustomForm())){
            int sort = 1;
            for (String title : data.getCustomForm()) {
                BusiNoticeForm noticeForm = new BusiNoticeForm();
                noticeForm.setNoticeId(data.getId());
                noticeForm.setLabelTitle(title);
                noticeForm.setSort(sort++);
                busiNoticeFormService.save(noticeForm);
            }
        }

    }


    @Override
    @Transactional
    public void updateByIdVo(BusiNotice data) {

        //获取当前登录用户
        data.setUserId(SecurityUtils.getUserId());
        if (StringUtils.isNotEmpty(data.getApprovalStatus())&&data.getApprovalStatus().equals("8")){
            //草稿数据直接保存
            this.updateById(data);
        }else {
            //判断 内容重复度 是否大于70%
            //先获取 当前系统中截止日期之前的
            LambdaQueryWrapper<BusiNotice> queryWrapper =new LambdaQueryWrapper<>();
            queryWrapper.gt(BusiNotice::getEndDate, DateUtil.format(new Date(),"yyyy-MM-dd")).eq(BusiNotice::getApprovalStatus,1)
                    .ne(BusiNotice::getId,data.getId());
            List<BusiNotice> list = this.list(queryWrapper);
            //无问题数据直接审核通过
            data.setApprovalStatus("1");
            data.setApprovalUserId(null);
            data.setApprovalTime(new Date());
            //遍历 list的每条数据与data对比，如果两条数据相似度大于70% 提出预警
            for (BusiNotice busiNotice : list) {
                double v1 = NoticeUtils.computeJaccardSimilarity(data.getTitle(), busiNotice.getTitle());
                double v2 = NoticeUtils.computeJaccardSimilarity(data.getDetail(), busiNotice.getDetail());
                if (v1>=0.7&&v2>=0.7){
                    //title 和 detail 相似度大于70% 待审核
                    data.setApprovalStatus("0");
                    data.setSimilarityIds(Optional.ofNullable(data.getSimilarityIds()).orElse("")+busiNotice.getId()+",");
                }
            }
            if (StringUtils.isNotEmpty(data.getSimilarityIds())){
                //删除结尾的最后一个逗号
                data.setSimilarityIds(data.getSimilarityIds().substring(0, data.getSimilarityIds().length() - 1));
            }
            this.updateById(data);
        }
        //先删除表单数据
        busiNoticeFormService.remove(new LambdaQueryWrapper<BusiNoticeForm>().eq(BusiNoticeForm::getNoticeId,data.getId()));
        //保存表单数据
        if (CollectionUtil.isNotEmpty(data.getCustomForm())){
            int sort = 1;
            for (String title : data.getCustomForm()) {
                BusiNoticeForm noticeForm = new BusiNoticeForm();
                noticeForm.setNoticeId(data.getId());
                noticeForm.setLabelTitle(title);
                noticeForm.setSort(sort++);
                busiNoticeFormService.save(noticeForm);
            }
        }

    }

    @Override
    @Transactional
    public String saveOrUpdateVo(BusiNotice data) {
        if(ObjectUtil.isNotEmpty(data.getCityId())){
            //转换城市名称
            LambdaQueryWrapper<BaseCity> queryWrapper =new LambdaQueryWrapper<>();
            queryWrapper.eq(BaseCity::getCityId,data.getCityId());
            BaseCity city = cityService.getOne(queryWrapper);
            String cityName = city.getName();
            queryWrapper =new LambdaQueryWrapper<>();
            queryWrapper.eq(BaseCity::getCityId,city.getParentId());
            BaseCity parentCity = cityService.getOne(queryWrapper);
            data.setCity(cityName);
            data.setProvince(parentCity.getName());
        }
        if (StringUtils.isNotEmpty(data.getId())){
            this.updateByIdVo(data);
        }else {
            this.saveVo(data);
        }
        return data.getId();
    }

    @Override
    @Transactional
    public void removeByIdsVo(List<String> ids) {
        for (String id : ids) {
            busiNoticeFormService.remove(new LambdaQueryWrapper<BusiNoticeForm>().eq(BusiNoticeForm::getNoticeId,id));
            this.removeById(id);
        }
    }


    /**
     * 查询博主报名的通告
     *
     * @param userId 博主id
     * @return java.util.List<com.ruoyi.busi.vo.BusiNoticeVo>
     * @author PQZ
     * @date 11:05 2025/3/22
     **/
    @Override
    public IPage<BusiNoticeVo> queryListByUserId(Long userId,Page<BusiNotice> page) {
        return busiNoticeMapper.queryListByUserId(userId,page);
    }
    /**
     * 发布或者下架
     * @param noticeId 通告主键
     * @param publishTakeDown 1发布0下架
     */
    @Override
    public void publishTakeDown(String noticeId, String publishTakeDown) {
        BusiNotice data = this.getById(noticeId);
        if (publishTakeDown.equals("1")){
            //如果是发布
            //判断 内容重复度 是否大于70%
            //先获取 当前系统中截止日期之前的
            LambdaQueryWrapper<BusiNotice> queryWrapper =new LambdaQueryWrapper<>();
            queryWrapper.gt(BusiNotice::getEndDate, DateUtil.format(new Date(),"yyyy-MM-dd")).eq(BusiNotice::getApprovalStatus,1);
            List<BusiNotice> list = this.list(queryWrapper);
            //无问题数据直接审核通过
            data.setApprovalStatus("1");
            //遍历 list的每条数据与data对比，如果两条数据相似度大于70% 提出预警
            for (BusiNotice busiNotice : list) {
                double v1 = NoticeUtils.computeJaccardSimilarity(data.getTitle(), busiNotice.getTitle());
                double v2 = NoticeUtils.computeJaccardSimilarity(data.getDetail(), busiNotice.getDetail());
                if (v1>=0.7&&v2>=0.7){
                    //title 和 detail 相似度大于70% 待审核
                    data.setApprovalStatus("0");
                    data.setSimilarityIds(Optional.ofNullable(data.getSimilarityIds()).orElse("")+busiNotice.getId()+",");
                }
            }
            if (StringUtils.isNotEmpty(data.getSimilarityIds())){
                //删除结尾的最后一个逗号
                data.setSimilarityIds(data.getSimilarityIds().substring(0, data.getSimilarityIds().length() - 1));
            }

        }else {
            //如果是关闭 关闭状态
            data.setApprovalStatus("2");
        }
        this.updateById(data);
    }

    /**
     * 审核接口
     * @param query 审核参数
     */

    @Override
    public void auditInfo(BusiNoticeQuery query) {
        BusiNotice busiNotice = this.getById(query.getId());
        //1代表审核通过
        if (query.getApprovalStatus().equals("1")){
            busiNotice.setApprovalStatus("1");
        }else {
            busiNotice.setApprovalStatus("9");
        }
        busiNotice.setApprovalUserId(SecurityUtils.getUserId());
        busiNotice.setApprovalTime(new Date());
        busiNotice.setApprovalRemark(query.getApprovalRemark());
        this.updateById(busiNotice);
    }

    /**
     * 小程序端查询通告列表
     *
     * @param query TODO
     * @param page  TODO
     * @return com.baomidou.mybatisplus.core.metadata.IPage<com.ruoyi.busi.domain.BusiNotice>
     * @author vinjor-M
     * @date 15:41 2025/3/25
     **/
    @Override
    public IPage<BusiNoticeVo> queryAppListPage(AppNoticeQuery query, Page<BusiNotice> page) {
        IPage<BusiNoticeVo> pageList = busiNoticeMapper.queryAppListPage(query,page);
        List<String> idList = pageList.getRecords().stream().map(BusiNotice::getId).collect(Collectors.toList());
        if(!idList.isEmpty()){
            //查博主类型字典
            List<BaseCategory> categoryList = baseCategoryService.listByParentCode(DictConstants.BLOGGER_TYPES_KEY,null);
            //转map
            Map<String,String> categoryMap = categoryList.stream().collect(Collectors.toMap(BaseCategory::getCode,BaseCategory::getTitle));
            pageList.getRecords().forEach(item->{
                //报名数量、浏览量、相关字典转换
                if(null==item.getViewNum()){
                    item.setViewNum(0);
                }
                item.setBloggerTypesText(noticeUtils.translateBloggerTypes(item.getBloggerTypes(),categoryMap));
                if(StringUtils.isNotEmpty(item.getImages())){
                    item.setMainImage(item.getImages().split(StrUtil.COMMA)[0]);
                }
            });
        }
        //TODO 后续需要拼接开通会员的通告主发布的通告，增加曝光度，这部分逻辑需要商讨
        return pageList;


    }
    /**
     * 小程序端查询浏览通告列表
     * @author zcy
     * @date 15:39 2025/3/29
     * @param query 查询条件
     * @return com.ruoyi.common.core.domain.AjaxResult
     **/
    @Override
    public IPage<BusiNoticeVo> appFootprintList(AppNoticeQuery query, Page<BusiNotice> page) {
        query.setUserId(SecurityUtils.getUserId());
        IPage<BusiNoticeVo> pageList = busiNoticeMapper.appFootprintList(query,page);
        List<String> idList = pageList.getRecords().stream().map(BusiNotice::getId).collect(Collectors.toList());
        if(!idList.isEmpty()){
            //查博主类型字典
            List<BaseCategory> categoryList = baseCategoryService.listByParentCode(DictConstants.BLOGGER_TYPES_KEY,null);
            //转map
            Map<String,String> categoryMap = categoryList.stream().collect(Collectors.toMap(BaseCategory::getCode,BaseCategory::getTitle));
            pageList.getRecords().forEach(item->{
                //报名数量、浏览量、相关字典转换
                if(null==item.getViewNum()){
                    item.setViewNum(0);
                }

                item.setBloggerTypesText(noticeUtils.translateBloggerTypes(item.getBloggerTypes(),categoryMap));
                if(StringUtils.isNotEmpty(item.getImages())){
                    item.setMainImage(item.getImages().split(StrUtil.COMMA)[0]);
                }
            });
        }
        return pageList;
    }

    /**
     * 小程序端查询通告详细信息
     * @author 朱春云
     * @date 15:39 2025/3/29
     * @param noticeId 通告id
     * @return JSONObject
     **/
    @Override
    public JSONObject appGetDetail(String noticeId) {
        JSONObject res =new JSONObject();
        //通告信息
        BusiNoticeVo detail = busiNoticeMapper.selectByIdVo(noticeId);
        //再获取报名动态表单
        List<BusiNoticeForm> customForm = busiNoticeFormService.list(new LambdaQueryWrapper<BusiNoticeForm>()
                .eq(BusiNoticeForm::getNoticeId,noticeId).orderByAsc(BusiNoticeForm::getSort));
        detail.setCustomForm(customForm.stream().map(BusiNoticeForm::getLabelTitle).collect(Collectors.toList()));
        //获取城市id
        LambdaQueryWrapper<BaseCity> queryWrapperCity = new LambdaQueryWrapper<>();
        queryWrapperCity.eq(BaseCity::getName,detail.getCity());
        List<BaseCity> list = cityService.list(queryWrapperCity);
        for (BaseCity baseCity : list) {
            queryWrapperCity = new LambdaQueryWrapper<>();
            queryWrapperCity.eq(BaseCity::getCityId,baseCity.getParentId());
            BaseCity byId = cityService.getOne(queryWrapperCity);
            if (byId.getName().equals(detail.getProvince())) {
                detail.setCityId(baseCity.getCityId());
            }
        }

        res.put("noticeDetail",detail);
        //通告主信息
        SysUser userDetail = userService.selectUserById(detail.getUserId());
        JSONObject userDetailJson = new JSONObject();
        userDetailJson.put("userId",userDetail.getUserId());
        userDetailJson.put("nickName",userDetail.getNickName());
        userDetailJson.put("avatar",Optional.ofNullable(userDetail.getAvatar()).orElse(""));
        //关联认证表
        LambdaQueryWrapper<MemberUser> queryWrapperMember =new LambdaQueryWrapper<>();
        queryWrapperMember.eq(MemberUser::getUserId,userDetail.getUserId()).eq(MemberUser::getUserType,"01").last("limit 1");
        MemberUser memberUser = memberUserService.getOne(queryWrapperMember);
        userDetailJson.put("identityType","未认证");
        if (null != memberUser&&StringUtils.isNotEmpty(memberUser.getIdentityType())){
            userDetailJson.put("identityType",dictDataService.selectDictLabel("dl_identity_type",memberUser.getIdentityType()));
        }
        res.put("userDetail",userDetailJson);
        //已报名用户头像
        List<BusiNoticeSign> signList = busiNoticeSignMapper.selectList(new LambdaQueryWrapper<BusiNoticeSign>().eq(BusiNoticeSign::getNoticeId, noticeId));
        List<String> signUserAvatarList = signList.stream().map(it-> Optional.ofNullable(it.getAvatar()).orElse("")
        ).collect(Collectors.toList());
        res.put("signUserAvatarList",signUserAvatarList);
        //当前用户是否已关注该通告主
        Long userId=null;
        try {
             userId = SecurityUtils.getUserId();
        }catch (Exception ignored){
            //未登录状态
        }
        res.put("isLove",false);
        res.put("isSign",false);
        res.put("passSign",false);
        if (null != userId){
            LambdaQueryWrapper<BusiUserLove> queryWrapper =new LambdaQueryWrapper<>();
            queryWrapper.eq(BusiUserLove::getUserId,userId).eq(BusiUserLove::getLoveUserId,detail.getUserId());
            if(userLoveService.getOne(queryWrapper)!=null){
                //当前用户已关注通告主
                res.put("isLove",true);
            }
            //当前用户是否已报名该通告
            if(busiNoticeSignMapper.selectOne(new LambdaQueryWrapper<BusiNoticeSign>().eq(BusiNoticeSign::getNoticeId, noticeId).eq(BusiNoticeSign::getUserId, userId).last("limit 1"))!=null){
                res.put("isSign",true);
            }

            //当前用户是否已通过当前报名
            if(busiNoticeSignMapper.selectOne(new LambdaQueryWrapper<BusiNoticeSign>().eq(BusiNoticeSign::getNoticeId, noticeId).eq(BusiNoticeSign::getUserId, userId).eq(BusiNoticeSign::getStatus,"1").last("limit 1"))!=null){
                res.put("passSign",true);
            }
        }
        return res;
    }
    /**
     * 小程序端查询订阅通告列表
     * @author zcy
     * @date 15:39 2025/3/29
     * @param query 查询条件
     * @return com.ruoyi.common.core.domain.AjaxResult
     **/
    @Override
    public IPage<BusiNoticeVo> subscribeList(AppNoticeQuery query, Page<BusiNotice> page) {
        //获取当前登录用户
        Long userId = SecurityUtils.getUserId();
        LambdaQueryWrapper<BusiSubscribe> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BusiSubscribe::getUserId,userId).last("limit 1");
        BusiSubscribe subscribe = subscribeService.getOne(queryWrapper);
        if(null!=subscribe){
            //如果使用订阅 则获取 订阅规则进行查询
            SubscribeDataObj subscribeDataObj = JSONObject.parseObject(subscribe.getJsonObj(), SubscribeDataObj.class);
            if (subscribeDataObj.getPlatformCode().contains("-1")){
                subscribeDataObj.setPlatformCode(null);
            }
            if (subscribeDataObj.getBloggerTypeCode().contains("-1")){
                subscribeDataObj.setBloggerTypeCode(null);
            }
            if (subscribeDataObj.getSettleTypeCode().contains("-1")){
                subscribeDataObj.setSettleTypeCode(null);
            }
            if(!subscribeDataObj.getFansLimit()){
                subscribeDataObj.setFansDown(null);
                subscribeDataObj.setFansUp(null);
            }
            if(!subscribeDataObj.getFeeLimit()){
                subscribeDataObj.setFeeDown(null);
                subscribeDataObj.setFeeUp(null);
            }
            IPage<BusiNoticeVo> pageList = baseMapper.subscribeList(subscribeDataObj, page);

            List<String> idList = pageList.getRecords().stream().map(BusiNotice::getId).collect(Collectors.toList());
            if(!idList.isEmpty()){
                //查博主类型字典
                List<BaseCategory> categoryList = baseCategoryService.listByParentCode(DictConstants.BLOGGER_TYPES_KEY,null);
                //转map
                Map<String,String> categoryMap = categoryList.stream().collect(Collectors.toMap(BaseCategory::getCode,BaseCategory::getTitle));
                pageList.getRecords().forEach(item->{
                    //报名数量、浏览量、相关字典转换
                    if(null==item.getViewNum()){
                        item.setViewNum(0);
                    }
                    item.setBloggerTypesText(noticeUtils.translateBloggerTypes(item.getBloggerTypes(),categoryMap));
                    if(StringUtils.isNotEmpty(item.getImages())){
                        item.setMainImage(item.getImages().split(StrUtil.COMMA)[0]);
                    }
                });
            }
            return pageList;
        }else {
            //未设置订阅则使用常规查询
            return this.queryAppListPage(query,page);
        }

    }
    /**
     * 小程序端关注订阅通告列表
     * @author zcy
     * @date 15:39 2025/3/29
     * @param query 查询条件
     * @return com.ruoyi.common.core.domain.AjaxResult
     **/
    @Override
    public IPage<BusiNoticeVo> loveList(AppNoticeQuery query, Page<BusiNotice> page) {
        //获取当前登录用户
        Long userId = SecurityUtils.getUserId();
        query.setUserId(userId);
        IPage<BusiNoticeVo> pageList = baseMapper.loveList(query, page);
        List<String> idList = pageList.getRecords().stream().map(BusiNotice::getId).collect(Collectors.toList());
        if(!idList.isEmpty()){
            //查博主类型字典
            List<BaseCategory> categoryList = baseCategoryService.listByParentCode(DictConstants.BLOGGER_TYPES_KEY,null);
            //转map
            Map<String,String> categoryMap = categoryList.stream().collect(Collectors.toMap(BaseCategory::getCode,BaseCategory::getTitle));
            pageList.getRecords().forEach(item->{
                //报名数量、浏览量、相关字典转换
                if(null==item.getViewNum()){
                    item.setViewNum(0);
                }
                item.setBloggerTypesText(noticeUtils.translateBloggerTypes(item.getBloggerTypes(),categoryMap));
                if(StringUtils.isNotEmpty(item.getImages())){
                    item.setMainImage(item.getImages().split(StrUtil.COMMA)[0]);
                }
            });
        }
        return pageList;
    }
    /**
     * 小程序端我的通告列表
     * @author zcy
     * @date 15:39 2025/3/29
     * @param query 查询条件
     * @return com.ruoyi.common.core.domain.AjaxResult
     **/
    @Override
    public IPage<BusiNoticeVo> myNoticeList(AppNoticeQuery query, Page<BusiNotice> page) {
        //获取当前登录用户
        Long userId = SecurityUtils.getUserId();
        query.setUserId(userId);
        IPage<BusiNoticeVo> pageList = baseMapper.myNoticeList(query, page);
        List<String> idList = pageList.getRecords().stream().map(BusiNotice::getId).collect(Collectors.toList());
        if(!idList.isEmpty()){
            //查博主类型字典
            List<BaseCategory> categoryList = baseCategoryService.listByParentCode(DictConstants.BLOGGER_TYPES_KEY,null);
            //转map
            Map<String,String> categoryMap = categoryList.stream().collect(Collectors.toMap(BaseCategory::getCode,BaseCategory::getTitle));
            pageList.getRecords().forEach(item->{
                //报名数量、浏览量、相关字典转换
                if(null==item.getViewNum()){
                    item.setViewNum(0);
                }
                item.setBloggerTypesText(noticeUtils.translateBloggerTypes(item.getBloggerTypes(),categoryMap));
                if(StringUtils.isNotEmpty(item.getImages())){
                    item.setMainImage(item.getImages().split(StrUtil.COMMA)[0]);
                }
            });
        }
        return pageList;
    }

    @Override
    public IPage<BusiNoticeVo> myPublishNoticeList(AppNoticeQuery query, Page<BusiNotice> page) {
        //获取当前登录用户
        Long userId = SecurityUtils.getUserId();
        query.setUserId(userId);
        IPage<BusiNoticeVo> pageList = baseMapper.myPublishNoticeList(query, page);
        List<String> idList = pageList.getRecords().stream().map(BusiNotice::getId).collect(Collectors.toList());
        if(!idList.isEmpty()){
            //查博主类型字典
            List<BaseCategory> categoryList = baseCategoryService.listByParentCode(DictConstants.BLOGGER_TYPES_KEY,null);
            //转map
            Map<String,String> categoryMap = categoryList.stream().collect(Collectors.toMap(BaseCategory::getCode,BaseCategory::getTitle));
            pageList.getRecords().forEach(item->{
                //报名数量、浏览量、相关字典转换
                if(null==item.getViewNum()){
                    item.setViewNum(0);
                }
                item.setBloggerTypesText(noticeUtils.translateBloggerTypes(item.getBloggerTypes(),categoryMap));
                if(StringUtils.isNotEmpty(item.getImages())){
                    item.setMainImage(item.getImages().split(StrUtil.COMMA)[0]);
                }
            });
        }
        return pageList;
    }


}
