ThemeService.java 16.8 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 35 36 37 38 39 40 41
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
42
import java.util.stream.Collectors;
刘基明's avatar
刘基明 committed
43

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

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

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

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

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

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

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

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

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

    //最新的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
86 87 88 89

        return themeMapper.selectList(queryWrapper);
    }

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

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

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

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

刘基明's avatar
刘基明 committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
    //根据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
161 162
    /**
     * 根据主题Id查询列表
163
     *
刘基明's avatar
刘基明 committed
164 165 166
     * @param themeIds
     * @return
     */
刘基明's avatar
刘基明 committed
167
    public List<ThemeEntity> queryByThemeIds(List<String> themeIds) {
168
        if (CollectionUtils.isEmpty(themeIds)) {
刘基明's avatar
刘基明 committed
169 170
            return Collections.emptyList();
        }
刘基明's avatar
刘基明 committed
171 172 173 174
        LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
                .in(ThemeEntity::getThemeId, themeIds)
                .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());

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

刘基明's avatar
刘基明 committed
179

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

刘基明's avatar
刘基明 committed
199
    //根据话题查询所有的主题Id,包括已删除的主题
刘基明's avatar
刘基明 committed
200
    public List<String> queryThemeIdsByTopic(String topidId) {
刘基明's avatar
刘基明 committed
201
        if (StringUtils.isEmpty(topidId)) {
刘基明's avatar
刘基明 committed
202 203
            return Collections.emptyList();
        }
刘基明's avatar
刘基明 committed
204 205 206 207 208 209
        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
210 211 212 213 214 215 216 217 218 219
    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
220
    /**
刘基明's avatar
刘基明 committed
221
     * 根据作者查询主题分页列表
刘基明's avatar
刘基明 committed
222
     *
刘基明's avatar
刘基明 committed
223
     * @param userIds
刘基明's avatar
刘基明 committed
224
     * @param pageStart
刘基明's avatar
刘基明 committed
225
     * @param pageSize
刘基明's avatar
刘基明 committed
226
     * @param userPermitTopics
刘基明's avatar
刘基明 committed
227 228
     * @return
     */
刘基明's avatar
刘基明 committed
229
    public List<ThemeEntity> queryByUserIdsCreateDesc(List<String> userIds, Integer pageStart, Integer pageSize, Set<String> userPermitTopics) {
230
        if (CollectionUtils.isEmpty(userIds) && CollectionUtils.isEmpty(userPermitTopics)) {
刘基明's avatar
刘基明 committed
231 232
            return Collections.emptyList();
        }
刘基明's avatar
刘基明 committed
233
        userPermitTopics.remove("");
刘基明's avatar
刘基明 committed
234
        return themeMapper.queryFollowList(userIds, userPermitTopics, pageStart, pageSize);
刘基明's avatar
刘基明 committed
235 236 237

    }

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

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

    public Set<String> getForwardUsers(List<String> themeIds) {
刘基明's avatar
刘基明 committed
252
        if (CollectionUtils.isEmpty(themeIds)) {
刘基明's avatar
刘基明 committed
253 254
            return new HashSet<>();
        }
刘基明's avatar
刘基明 committed
255 256 257 258
        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
259
    }
刘基明's avatar
刘基明 committed
260

刘基明's avatar
刘基明 committed
261

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

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


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

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

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

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

        checkForwardSpecialPermission(req.getThemeId());
324 325 326 327 328 329 330 331 332 333 334 335 336
        // 评论构造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
337

刘基明's avatar
刘基明 committed
338 339 340 341 342 343 344 345 346 347 348 349 350
    /**
     * 专属话题不允许转发
     */
    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
351 352 353 354 355 356 357 358 359 360

    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
361

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

            }

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

        }

    }
刘基明's avatar
刘基明 committed
380 381

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

    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
393
                .eq(ThemeEntity::getIsTop, StatusEnum.TRUE.getCode())
刘基明's avatar
刘基明 committed
394 395 396
                .orderByDesc(ThemeEntity::getSetTopTime);
        return themeMapper.selectList(queryWrapper);
    }
刘基明's avatar
刘基明 committed
397
}