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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.TopicStatusEnum;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.dao.mapper.community.TopicMapper;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
@EnableCaching
public class TopicService {
@Resource
private TopicMapper topicMapper;
public List<TopicEntity> queryAll() {
return topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>()
.eq(TopicEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
}
public void addTopic(String topicTitle, String userId) {
TopicEntity entity = TopicEntity.builder()
.topicTitle(topicTitle)
.createBy(userId)
.updateBy(userId)
.isTop(TopicStatusEnum.FALSE.getCode())
.isConceal(TopicStatusEnum.FALSE.getCode())
.build();
topicMapper.insert(entity);
}
public void updateTopicToTop(String topicId) {
TopicEntity topicEntity = new TopicEntity();
topicEntity.setIsTop(TopicStatusEnum.TRUE.getCode());
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getId, topicId));
}
public void updateTopicNotTop(String topicId) {
TopicEntity topicEntity = new TopicEntity();
topicEntity.setIsTop(TopicStatusEnum.FALSE.getCode());
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getId, topicId));
}
public void updateTopicToConceal(String topicId) {
TopicEntity topicEntity = new TopicEntity();
topicEntity.setIsConceal(TopicStatusEnum.TRUE.getCode());
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getId, topicId));
}
public void updateTopicNotConceal(String topicId) {
TopicEntity topicEntity = new TopicEntity();
topicEntity.setIsConceal(TopicStatusEnum.FALSE.getCode());
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getId, topicId));
}
public TopicEntity queryById(String topicId) {
return topicMapper.selectById(topicId);
}
public void modifyViewAmount(String topicId, long amount) {
TopicEntity topicEntity = topicMapper.selectById(topicId);
Long oldAmount = topicEntity.getViewAmountModify();
topicEntity.setViewAmountModify(topicEntity.getViewAmountModify() + amount);
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getViewAmountModify, oldAmount));
return;
}
public TopicEntity queryByTitile(String topicTitle) {
return topicMapper.selectOne(new LambdaQueryWrapper<TopicEntity>().eq(TopicEntity::getTopicTitle, topicTitle));
}
}