1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.common.uuid.UuidGenHelper;
import com.tanpu.community.api.enums.StatusEnum;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.dao.mapper.community.TopicMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Service
@EnableCaching
public class TopicService {
@Resource
private TopicMapper topicMapper;
@Autowired
private UuidGenHelper uuidGenHelper;
public List<TopicEntity> queryAll() {
List<TopicEntity> retList = new ArrayList<>();
Long lastId = 0L;
while (true) {
List<TopicEntity> tmpList = topicMapper.selectGtIdPageable(lastId, 100);
if (tmpList.isEmpty()) {
break;
}
retList.addAll(tmpList);
lastId = tmpList.stream().map(TopicEntity::getId).max(Long::compareTo).get();
}
return retList;
}
public TopicEntity queryById(String topicId) {
return topicMapper.selectOne(new LambdaQueryWrapper<TopicEntity>()
.eq(TopicEntity::getTopicId, topicId)
.eq(TopicEntity::getIsConceal, StatusEnum.FALSE)
.eq(TopicEntity::getDeleteTag, StatusEnum.FALSE));
}
// 根据话题id查询title,(包括已删除)
public String queryTitleById(String topicId) {
TopicEntity topicEntity = topicMapper.selectOne(new LambdaQueryWrapper<TopicEntity>()
.eq(TopicEntity::getTopicId, topicId));
return topicEntity!=null?topicEntity.getTopicTitle():null;
}
public List<TopicEntity> queryByIds(List<String> topicIds) {
if (CollectionUtils.isEmpty(topicIds)) {
return Collections.emptyList();
}
return topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>().in(TopicEntity::getTopicId, topicIds));
}
}