ThemeService.java 16.9 KB
Newer Older
刘基明's avatar
刘基明 committed
1 2
package com.tanpu.community.service;

刘基明's avatar
刘基明 committed
3
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
刘基明's avatar
刘基明 committed
4
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
5
import com.tanpu.biz.common.enums.RelTypeEnum;
张辰's avatar
张辰 committed
6
import com.tanpu.biz.common.enums.community.ReportStatusEnum;
刘基明's avatar
刘基明 committed
7
import com.tanpu.common.constant.ErrorCodeConstant;
刘基明's avatar
刘基明 committed
8
import com.tanpu.common.exception.BizException;
9
import com.tanpu.common.util.JsonUtil;
刘基明's avatar
刘基明 committed
10
import com.tanpu.common.uuid.UuidGenHelper;
刘基明's avatar
刘基明 committed
11 12
import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.qo.TopicFollowQo;
13 14
import com.tanpu.community.api.beans.req.comment.CreateCommentReq;
import com.tanpu.community.api.beans.req.theme.ThemeContentReq;
刘基明's avatar
刘基明 committed
15
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp;
刘基明's avatar
刘基明 committed
16
import com.tanpu.community.api.enums.DeleteTagEnum;
刘基明's avatar
刘基明 committed
17
import com.tanpu.community.api.enums.StatusEnum;
刘基明's avatar
刘基明 committed
18
import com.tanpu.community.api.enums.ThemeTypeEnum;
刘基明's avatar
刘基明 committed
19
import com.tanpu.community.dao.entity.community.ThemeEntity;
刘基明's avatar
刘基明 committed
20
import com.tanpu.community.dao.entity.community.TimesCountEntity;
刘基明's avatar
刘基明 committed
21
import com.tanpu.community.dao.entity.community.TopicEntity;
刘基明's avatar
刘基明 committed
22
import com.tanpu.community.dao.entity.community.VisitLogEntity;
刘基明's avatar
刘基明 committed
23
import com.tanpu.community.dao.mapper.community.ThemeMapper;
刘基明's avatar
刘基明 committed
24
import com.tanpu.community.dao.mapper.community.TopicMapper;
刘基明's avatar
刘基明 committed
25 26
import com.tanpu.community.dao.mapper.community.VisitLogMapper;
import com.tanpu.community.util.ConvertUtil;
刘基明's avatar
刘基明 committed
27
import com.tanpu.community.util.TimeUtils;
刘基明's avatar
刘基明 committed
28
import org.apache.commons.collections4.CollectionUtils;
刘基明's avatar
刘基明 committed
29
import org.apache.commons.lang3.StringUtils;
刘基明's avatar
刘基明 committed
30
import org.springframework.stereotype.Service;
刘基明's avatar
刘基明 committed
31
import org.springframework.transaction.annotation.Transactional;
刘基明's avatar
刘基明 committed
32

刘基明's avatar
刘基明 committed
33
import javax.annotation.Resource;
刘基明's avatar
刘基明 committed
34
import java.time.ZoneOffset;
刘基明's avatar
刘基明 committed
35 36 37 38 39 40 41 42
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
刘基明's avatar
刘基明 committed
43
import java.util.stream.Collectors;
刘基明's avatar
刘基明 committed
44

刘基明's avatar
刘基明 committed
45 46 47
@Service
public class ThemeService {

刘基明's avatar
刘基明 committed
48
    @Resource
刘基明's avatar
刘基明 committed
49
    private ThemeMapper themeMapper;
刘基明's avatar
刘基明 committed
50

刘基明's avatar
刘基明 committed
51
    @Resource
刘基明's avatar
刘基明 committed
52 53
    private UuidGenHelper uuidGenHelper;

刘基明's avatar
刘基明 committed
54
    @Resource
刘基明's avatar
刘基明 committed
55
    private TopicMapper topicMapper;
刘基明's avatar
刘基明 committed
56 57
    @Resource
    private VisitLogMapper visitLogMapper;
刘基明's avatar
刘基明 committed
58 59
    @Resource
    private FeignService feignService;
张辰's avatar
张辰 committed
60

刘基明's avatar
刘基明 committed
61
    @Transactional
刘基明's avatar
刘基明 committed
62
    public void insertTheme(ThemeEntity themeEntity) {
刘基明's avatar
刘基明 committed
63
        if (StringUtils.isBlank(themeEntity.getThemeId())) {
刘基明's avatar
刘基明 committed
64 65 66
            themeEntity.setThemeId(uuidGenHelper.getUuidStr());
        }

刘基明's avatar
刘基明 committed
67 68 69
        themeMapper.insert(themeEntity);
    }

刘基明's avatar
刘基明 committed
70
    @Transactional
刘基明's avatar
刘基明 committed
71 72
    public void update(ThemeEntity themeEntity, String themeId) {
        themeMapper.update(themeEntity, new LambdaUpdateWrapper<ThemeEntity>().eq(ThemeEntity::getThemeId, themeId));
刘基明's avatar
刘基明 committed
73 74
    }

张辰's avatar
张辰 committed
75
    //n天内发表的所有主题
刘基明's avatar
刘基明 committed
76
    public List<ThemeEntity> queryRecentdaysOrHasTopic(Integer days) {
77

刘基明's avatar
刘基明 committed
78
        return themeMapper.queryRecentdaysOrHasTopic(DeleteTagEnum.NOT_DELETED.getCode(), TimeUtils.getDaysBefore(days), "");
79 80 81 82 83 84 85 86
    }

    //最新的n条主题
    public List<ThemeEntity> queryLatestThemes(Integer n) {
        LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
                .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
                .last("limit " + n)
                .orderByDesc(ThemeEntity::getId);
刘基明's avatar
刘基明 committed
87 88 89 90

        return themeMapper.selectList(queryWrapper);
    }

刘基明's avatar
刘基明 committed
91
    //根据id返回主题详情(未删)
刘基明's avatar
刘基明 committed
92
    public ThemeEntity queryByThemeId(String themeId) {
刘基明's avatar
刘基明 committed
93
        return themeMapper.selectOne(new LambdaQueryWrapper<ThemeEntity>()
刘基明's avatar
刘基明 committed
94 95
                .eq(ThemeEntity::getThemeId, themeId)
                .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
刘基明's avatar
刘基明 committed
96 97
    }

张辰's avatar
张辰 committed
98 99
    //根据id返回主题详情(未删)
    public ThemeEntity queryByThemeIdIgnoreDelete(String themeId) {
刘基明's avatar
刘基明 committed
100
        ThemeEntity themeEntity = themeMapper.selectOne(new LambdaQueryWrapper<ThemeEntity>()
张辰's avatar
张辰 committed
101
                .eq(ThemeEntity::getThemeId, themeId));
刘基明's avatar
刘基明 committed
102
        return themeEntity;
张辰's avatar
张辰 committed
103 104
    }

105
    //根据用户id查询主题list
刘基明's avatar
刘基明 committed
106
    public List<ThemeEntity> queryThemesByUserIdCreateDesc(String userId, String lastId, Integer pageSize, Set<String> userPermitTopics) {
刘基明's avatar
刘基明 committed
107 108
        LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
                .eq(ThemeEntity::getAuthorId, userId)
109
                .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
刘基明's avatar
刘基明 committed
110
                .in(ThemeEntity::getTopicId, userPermitTopics)
111
                .orderByDesc(ThemeEntity::getCreateTime);
刘基明's avatar
刘基明 committed
112 113
        if (StringUtils.isNotEmpty(lastId)) {
            ThemeEntity lastEntity = queryByThemeId(lastId);
刘基明's avatar
刘基明 committed
114
            if (lastEntity == null) throw new BizException("主题未找到,id:" + lastId);
115
            queryWrapper.lt(ThemeEntity::getCreateTime, lastEntity.getCreateTime());
刘基明's avatar
刘基明 committed
116
        }
刘基明's avatar
刘基明 committed
117
        if (pageSize != null) {
张辰's avatar
张辰 committed
118
            queryWrapper.last("limit " + pageSize);
刘基明's avatar
刘基明 committed
119 120 121 122
        }
        return themeMapper.selectList(queryWrapper);
    }

刘基明's avatar
刘基明 committed
123
    //根据ids返回主题详情,带分页
刘基明's avatar
刘基明 committed
124
    public List<ThemeEntity> queryByThemeIds(List<String> themeIds, String lastId, Integer pageSize) {
125
        if (CollectionUtils.isEmpty(themeIds)) {
刘基明's avatar
刘基明 committed
126 127
            return Collections.emptyList();
        }
刘基明's avatar
刘基明 committed
128 129 130 131 132
        LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
                .in(ThemeEntity::getThemeId, themeIds)
                .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
        if (StringUtils.isNotEmpty(lastId)) {
            ThemeEntity lastEntity = queryByThemeId(lastId);
刘基明's avatar
刘基明 committed
133
            if (lastEntity == null) throw new BizException("主题未找到,id:" + lastId);
134
            queryWrapper.lt(ThemeEntity::getCreateTime, lastEntity.getCreateTime());
刘基明's avatar
刘基明 committed
135
        }
刘基明's avatar
刘基明 committed
136 137
        if (pageSize != null) {
            queryWrapper.last("limit " + pageSize);
刘基明's avatar
刘基明 committed
138 139
        }
        return themeMapper.selectList(queryWrapper);
刘基明's avatar
刘基明 committed
140 141
    }

刘基明's avatar
刘基明 committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
    //根据ids返回主题详情,带分页
    public List<ThemeEntity> queryByThemeIds(List<String> themeIds, String lastId, Integer pageSize, Set<String> userPermitTopics) {
        if (CollectionUtils.isEmpty(themeIds)) {
            return Collections.emptyList();
        }
        LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
                .in(ThemeEntity::getThemeId, themeIds)
                .in(ThemeEntity::getTopicId, userPermitTopics)
                .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
        if (StringUtils.isNotEmpty(lastId)) {
            ThemeEntity lastEntity = queryByThemeId(lastId);
            if (lastEntity == null) throw new BizException("主题未找到,id:" + lastId);
            queryWrapper.lt(ThemeEntity::getCreateTime, lastEntity.getCreateTime());
        }
        if (pageSize != null) {
            queryWrapper.last("limit " + pageSize);
        }
        return themeMapper.selectList(queryWrapper);
    }

刘基明's avatar
刘基明 committed
162 163
    /**
     * 根据主题Id查询列表
164
     *
刘基明's avatar
刘基明 committed
165 166 167
     * @param themeIds
     * @return
     */
刘基明's avatar
刘基明 committed
168
    public List<ThemeEntity> queryByThemeIds(List<String> themeIds) {
169
        if (CollectionUtils.isEmpty(themeIds)) {
刘基明's avatar
刘基明 committed
170 171
            return Collections.emptyList();
        }
刘基明's avatar
刘基明 committed
172 173 174 175
        LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
                .in(ThemeEntity::getThemeId, themeIds)
                .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());

刘基明's avatar
刘基明 committed
176 177
        List<ThemeEntity> themeEntities = themeMapper.selectList(queryWrapper);
        return themeEntities;
刘基明's avatar
刘基明 committed
178 179
    }

刘基明's avatar
刘基明 committed
180

刘基明's avatar
刘基明 committed
181
    /**
刘基明's avatar
刘基明 committed
182
     * 根据话题查询最新主题(可分页)
刘基明's avatar
刘基明 committed
183 184
     *
     * @param topidId  话题Id
刘基明's avatar
刘基明 committed
185 186 187
     * @param pageSize 查询数量
     * @return
     */
刘基明's avatar
刘基明 committed
188
    public List<ThemeEntity> queryNewestByTopic(String topidId, Integer pageStart, Integer pageSize, List<String> excludeIds) {
刘基明's avatar
刘基明 committed
189
        LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
张辰's avatar
张辰 committed
190 191 192 193
                .eq(ThemeEntity::getTopicId, topidId);
        if (!excludeIds.isEmpty()) {
            queryWrapper.notIn(ThemeEntity::getThemeId, excludeIds);
        }
刘基明's avatar
刘基明 committed
194
        queryWrapper.last("limit " + pageStart + ", " + pageSize)
195 196
                .orderByDesc(ThemeEntity::getCreateTime)
                .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
刘基明's avatar
刘基明 committed
197
        return themeMapper.selectList(queryWrapper);
刘基明's avatar
刘基明 committed
198
    }
刘基明's avatar
刘基明 committed
199

刘基明's avatar
刘基明 committed
200
    //根据话题查询所有的主题Id,包括已删除的主题
刘基明's avatar
刘基明 committed
201
    public List<String> queryThemeIdsByTopic(String topidId) {
刘基明's avatar
刘基明 committed
202
        if (StringUtils.isEmpty(topidId)) {
刘基明's avatar
刘基明 committed
203 204
            return Collections.emptyList();
        }
刘基明's avatar
刘基明 committed
205 206 207 208 209 210
        LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
                .eq(ThemeEntity::getTopicId, topidId);
        queryWrapper.select(ThemeEntity::getThemeId);
        return themeMapper.selectList(queryWrapper).stream().map(ThemeEntity::getThemeId).collect(Collectors.toList());
    }

张辰's avatar
张辰 committed
211 212 213 214 215 216 217 218 219 220
    public List<String> queryThemeIdsByTopic(String topidId, Date startDate, Date endDate) {
        if (StringUtils.isEmpty(topidId)) {
            return Collections.emptyList();
        }
        LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
                .eq(ThemeEntity::getTopicId, topidId).gt(ThemeEntity::getCreateTime, startDate).lt(ThemeEntity::getCreateTime, endDate);
        queryWrapper.select(ThemeEntity::getThemeId);
        return themeMapper.selectList(queryWrapper).stream().map(ThemeEntity::getThemeId).collect(Collectors.toList());
    }

刘基明's avatar
刘基明 committed
221
    /**
刘基明's avatar
刘基明 committed
222
     * 根据作者查询主题分页列表
刘基明's avatar
刘基明 committed
223
     *
刘基明's avatar
刘基明 committed
224
     * @param userIds
刘基明's avatar
刘基明 committed
225
     * @param pageStart
刘基明's avatar
刘基明 committed
226
     * @param pageSize
刘基明's avatar
刘基明 committed
227
     * @param userFollowTopics
刘基明's avatar
刘基明 committed
228 229
     * @return
     */
刘基明's avatar
刘基明 committed
230 231
    public List<ThemeEntity> queryByUserIdsCreateDesc(List<String> userIds, Integer pageStart, Integer pageSize, Set<String> userFollowTopics) {
        if (CollectionUtils.isEmpty(userIds) && CollectionUtils.isEmpty(userFollowTopics)) {
刘基明's avatar
刘基明 committed
232 233
            return Collections.emptyList();
        }
刘基明's avatar
刘基明 committed
234 235
        userFollowTopics.remove("");
        return themeMapper.queryFollowList(userIds, userFollowTopics, pageStart, pageSize);
刘基明's avatar
刘基明 committed
236 237 238

    }

刘基明's avatar
刘基明 committed
239 240
    public Integer getForwardCountById(String themeId) {
        return themeMapper.selectCount(new LambdaQueryWrapper<ThemeEntity>()
刘基明's avatar
刘基明 committed
241
                .eq(ThemeEntity::getFormerThemeId, themeId)
刘基明's avatar
刘基明 committed
242 243
                .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED));
    }
刘基明's avatar
刘基明 committed
244

刘基明's avatar
刘基明 committed
245
    public boolean judgeForwardByUser(String themeId, String userId) {
刘基明's avatar
刘基明 committed
246 247 248
        return themeMapper.selectCount(new LambdaQueryWrapper<ThemeEntity>()
                .eq(ThemeEntity::getFormerThemeId, themeId)
                .eq(ThemeEntity::getAuthorId, userId)
刘基明's avatar
刘基明 committed
249
                .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED)) > 0;
刘基明's avatar
刘基明 committed
250 251 252
    }

    public Set<String> getForwardUsers(List<String> themeIds) {
刘基明's avatar
刘基明 committed
253
        if (CollectionUtils.isEmpty(themeIds)) {
刘基明's avatar
刘基明 committed
254 255
            return new HashSet<>();
        }
刘基明's avatar
刘基明 committed
256 257 258 259
        return themeMapper.selectList(new LambdaQueryWrapper<ThemeEntity>()
                .in(ThemeEntity::getFormerThemeId, themeIds)
                .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED))
                .stream().map(ThemeEntity::getAuthorId).collect(Collectors.toSet());
刘基明's avatar
刘基明 committed
260
    }
刘基明's avatar
刘基明 committed
261

刘基明's avatar
刘基明 committed
262

刘基明's avatar
刘基明 committed
263
    @Transactional
刘基明's avatar
刘基明 committed
264
    public void deleteById(String themeId, String userId) {
刘基明's avatar
刘基明 committed
265 266
        ThemeEntity themeEntity = themeMapper.selectOne(new LambdaQueryWrapper<ThemeEntity>()
                .eq(ThemeEntity::getThemeId, themeId));
刘基明's avatar
刘基明 committed
267
        if (themeEntity == null || !themeEntity.getAuthorId().equals(userId)) {
刘基明's avatar
刘基明 committed
268
            throw new BizException("主题与用户不匹配,id:" + themeId + ",userId" + userId);
刘基明's avatar
刘基明 committed
269 270 271 272
        }
        themeEntity.setDeleteTag(DeleteTagEnum.DELETED.getCode());
        themeMapper.updateById(themeEntity);
    }
刘基明's avatar
刘基明 committed
273

刘基明's avatar
刘基明 committed
274 275
    /**
     * 查询更新节点后的用户新建主题数
276
     *
刘基明's avatar
刘基明 committed
277 278
     * @param userIds 用户ids
     * @param lastId  更新时间节点
刘基明's avatar
刘基明 committed
279 280
     * @return
     */
张辰's avatar
张辰 committed
281
    public Integer queryCountFromLastId(List<String> userIds, Long lastId) {
刘基明's avatar
刘基明 committed
282 283 284 285 286
        if (CollectionUtils.isEmpty(userIds)) {
            return 0;
        }
        LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
                .in(ThemeEntity::getAuthorId, userIds)
张辰's avatar
张辰 committed
287
                .gt(ThemeEntity::getId, lastId)
刘基明's avatar
刘基明 committed
288 289 290
                .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
        return themeMapper.selectCount(queryWrapper);
    }
刘基明's avatar
刘基明 committed
291 292


293 294 295
    public void updateReportStatus(String themeId) {
        ThemeEntity themeEntity = queryByThemeId(themeId);
        if (themeEntity == null) {
刘基明's avatar
刘基明 committed
296
            throw new BizException("主题未找到,id:" + themeId);
297 298 299 300
        }
        themeEntity.setReportStatus(ReportStatusEnum.REPORTED.getCode());
        themeMapper.updateById(themeEntity);
    }
刘基明's avatar
刘基明 committed
301 302 303

    //统计主题集合的浏览量
    public Map<String, Integer> getForwardCountMap(List<String> themeIds) {
刘基明's avatar
刘基明 committed
304
        if (CollectionUtils.isEmpty(themeIds)) {
刘基明's avatar
刘基明 committed
305 306
            return new HashMap<String, Integer>();
        }
刘基明's avatar
刘基明 committed
307 308
        LambdaQueryWrapper<ThemeEntity> wrapper = new LambdaQueryWrapper<ThemeEntity>()
                .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED)
刘基明's avatar
刘基明 committed
309
                .in(ThemeEntity::getFormerThemeId, themeIds)
刘基明's avatar
刘基明 committed
310 311 312 313 314
                .groupBy(ThemeEntity::getFormerThemeId);
        return themeMapper.selectCountByThemeIds(wrapper).stream()
                .collect(Collectors.toMap(TimesCountEntity::getId, TimesCountEntity::getTimes));
    }

刘基明's avatar
刘基明 committed
315 316 317
    public List<ThemeEntity> queryAllForward() {
        return themeMapper.selectList(new LambdaQueryWrapper<ThemeEntity>()
                .eq(ThemeEntity::getThemeType, ThemeTypeEnum.FORWARD.getCode())
刘基明's avatar
刘基明 committed
318
                .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
刘基明's avatar
刘基明 committed
319 320
                .orderByAsc(ThemeEntity::getCreateTime));
    }
321 322

    public String commentSyncForward(CreateCommentReq req, String userId) {
刘基明's avatar
刘基明 committed
323 324

        checkForwardSpecialPermission(req.getThemeId());
325 326 327 328 329 330 331 332 333 334 335 336 337
        // 评论构造theme content
        List<ThemeContentReq> themeContentReqs = Arrays.asList(ThemeContentReq.builder().type(RelTypeEnum.TEXT.type).value(req.getComment()).build());
        ThemeContentReq.builder().type(RelTypeEnum.TEXT.type).value(req.getComment()).build();
        ThemeEntity themeEntity = ThemeEntity.builder()
                .content(JsonUtil.toJson(themeContentReqs))
                .topicId("")
                .formerThemeId(req.getThemeId())
                .authorId(userId)
                .themeType(ThemeTypeEnum.FORWARD.getCode())
                .build();
        this.insertTheme(themeEntity);
        return themeEntity.getThemeId();
    }
刘基明's avatar
刘基明 committed
338

刘基明's avatar
刘基明 committed
339 340 341 342 343 344 345 346 347 348 349 350 351
    /**
     * 专属话题不允许转发
     */
    public void checkForwardSpecialPermission(String themeId) {
        ThemeEntity themeEntity = queryByThemeId(themeId);
        if (themeEntity!=null && StringUtils.isNotBlank(themeEntity.getTopicId())){
            TopicEntity topicEntity = topicMapper.selectOne(new LambdaQueryWrapper<TopicEntity>().eq(TopicEntity::getTopicId, themeEntity.getTopicId()));
            if (topicEntity!=null && topicEntity.getSpecialPermission()==1){
                throw new BizException(ErrorCodeConstant.TOPIC_FORWARD_ABORT.getCode(),"专属话题不允许转发");
            }
        }
    }

刘基明's avatar
刘基明 committed
352 353 354 355 356 357 358 359 360 361

    public void queryCommentForTopic(List<TopicFollowQo> topicQos, String userId) {


        for (TopicFollowQo topic : topicQos) {
            String topicId = topic.getTopicId();
            // 最近的一条讨论
            ThemeEntity themeEntity = themeMapper.queryOneByTopicIdOrderByUpdateTimeDesc(topicId);
            if (themeEntity != null) {
                ThemeQo themeQo = ConvertUtil.themeEntityToQo(themeEntity);
刘基明's avatar
刘基明 committed
362

刘基明's avatar
刘基明 committed
363
                topic.setLastTheme(getUserName(themeQo.getAuthorId()) + ":" + themeQo.content.get(0).getValue());
刘基明's avatar
刘基明 committed
364
                topic.setLastThemeTime(TimeUtils.formatTopicListTime(themeEntity.getUpdateTime()));
刘基明's avatar
刘基明 committed
365
                topic.setLastThemeSecond(themeEntity.getUpdateTime().toEpochSecond(ZoneOffset.of("+8")));
刘基明's avatar
刘基明 committed
366 367 368 369 370

            }

            // 查询更新条数
            VisitLogEntity visitLogEntity = visitLogMapper.queryLastByVisitorIdAndRefId(userId, topicId);
刘基明's avatar
刘基明 committed
371
            Integer updates;
刘基明's avatar
刘基明 committed
372
            if (visitLogEntity != null) {
刘基明's avatar
刘基明 committed
373
                updates = themeMapper.countByTopicIdAndCreateTimeAfter(topicId, visitLogEntity.getUpdateTime());
刘基明's avatar
刘基明 committed
374
            } else {
刘基明's avatar
刘基明 committed
375
                updates = themeMapper.countByTopicIdAndCreateTimeAfter(topicId, null);
刘基明's avatar
刘基明 committed
376
            }
刘基明's avatar
刘基明 committed
377
            topic.setUpdateCount(updates);
刘基明's avatar
刘基明 committed
378 379 380 381

        }

    }
刘基明's avatar
刘基明 committed
382 383

    private String getUserName(String authorId) {
刘基明's avatar
刘基明 committed
384
        UserInfoResp userInfoById = feignService.getUserInfoById(authorId);
刘基明's avatar
刘基明 committed
385
        if (StringUtils.isNotBlank(userInfoById.getNickName())) {
刘基明's avatar
刘基明 committed
386 387 388
            return userInfoById.getNickName();
        }
        return "理财师";
刘基明's avatar
刘基明 committed
389
    }
刘基明's avatar
刘基明 committed
390 391 392 393 394

    public List<ThemeEntity> queryTopByTopic(String topicId) {
        LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
                .eq(ThemeEntity::getTopicId, topicId)
                .eq(ThemeEntity::getDeleteTag, StatusEnum.FALSE.getCode())
刘基明's avatar
刘基明 committed
395
                .eq(ThemeEntity::getIsTop, StatusEnum.TRUE.getCode())
刘基明's avatar
刘基明 committed
396 397 398
                .orderByDesc(ThemeEntity::getSetTopTime);
        return themeMapper.selectList(queryWrapper);
    }
刘基明's avatar
刘基明 committed
399
}