This commit is contained in:
2025-09-09 11:13:36 +08:00
parent cf50a9f1fa
commit fcd35c78e5
60 changed files with 2753 additions and 2196 deletions
@@ -5,9 +5,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.emotion.common.BasePageRequest;
import com.emotion.common.PageResult;
import com.emotion.dto.request.growth.GrowthTopicCreateRequest;
import com.emotion.dto.request.growth.GrowthTopicUpdateRequest;
import com.emotion.dto.response.growth.GrowthTopicResponse;
import com.emotion.entity.GrowthTopic;
import com.emotion.mapper.GrowthTopicMapper;
import com.emotion.service.GrowthTopicService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@@ -15,12 +20,13 @@ import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* 成长话题服务实现类
*
* @author emotion-museum
* @date 2025-07-24
* @date 2025-09-08
*/
@Service
public class GrowthTopicServiceImpl extends ServiceImpl<GrowthTopicMapper, GrowthTopic> implements GrowthTopicService {
@@ -53,149 +59,31 @@ public class GrowthTopicServiceImpl extends ServiceImpl<GrowthTopicMapper, Growt
}
@Override
public List<GrowthTopic> getByCategory(String category) {
LambdaQueryWrapper<GrowthTopic> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GrowthTopic::getCategory, category)
.eq(GrowthTopic::getIsDeleted, 0)
.orderByDesc(GrowthTopic::getCreateTime);
return this.list(wrapper);
public PageResult<GrowthTopicResponse> getPageWithResponse(BasePageRequest request) {
IPage<GrowthTopic> page = getPage(request);
List<GrowthTopicResponse> responses = page.getRecords().stream()
.map(this::convertToResponse)
.collect(Collectors.toList());
PageResult<GrowthTopicResponse> pageResult = new PageResult<>();
pageResult.setRecords(responses);
pageResult.setCurrent(page.getCurrent());
pageResult.setSize(page.getSize());
pageResult.setTotal(page.getTotal());
pageResult.setPages(page.getPages());
return pageResult;
}
@Override
public List<GrowthTopic> getByDifficultyLevel(String difficultyLevel) {
LambdaQueryWrapper<GrowthTopic> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GrowthTopic::getDifficulty, difficultyLevel)
.eq(GrowthTopic::getIsDeleted, 0)
.orderByDesc(GrowthTopic::getCreateTime);
return this.list(wrapper);
public GrowthTopicResponse getGrowthTopicResponseById(String id) {
GrowthTopic topic = this.getById(id);
if (topic == null || topic.getIsDeleted() == 1) {
return null;
}
return convertToResponse(topic);
}
@Override
public List<GrowthTopic> getByStatus(String status) {
// GrowthTopic实体中没有status字段,暂时返回空列表
return Collections.emptyList();
}
@Override
public List<GrowthTopic> getRecommendedTopics(Integer limit) {
// GrowthTopic实体中没有isRecommended字段,暂时返回最新话题
LambdaQueryWrapper<GrowthTopic> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GrowthTopic::getIsDeleted, 0)
.orderByDesc(GrowthTopic::getCreateTime)
.last("LIMIT " + limit);
return this.list(wrapper);
}
@Override
public List<GrowthTopic> getPopularTopics(Integer limit) {
// GrowthTopic实体中没有participantCount字段,暂时返回最新话题
LambdaQueryWrapper<GrowthTopic> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GrowthTopic::getIsDeleted, 0)
.orderByDesc(GrowthTopic::getCreateTime)
.last("LIMIT " + limit);
return this.list(wrapper);
}
@Override
public List<GrowthTopic> getLatestTopics(Integer limit) {
LambdaQueryWrapper<GrowthTopic> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GrowthTopic::getIsDeleted, 0)
.orderByDesc(GrowthTopic::getCreateTime)
.last("LIMIT " + limit);
return this.list(wrapper);
}
@Override
public List<GrowthTopic> getByParticipantRange(Integer minParticipants, Integer maxParticipants) {
// GrowthTopic实体中没有participantCount字段,暂时返回空列表
return Collections.emptyList();
}
@Override
public List<GrowthTopic> getByTimeRange(LocalDateTime startTime, LocalDateTime endTime) {
LambdaQueryWrapper<GrowthTopic> wrapper = new LambdaQueryWrapper<>();
wrapper.between(GrowthTopic::getCreateTime, startTime, endTime)
.eq(GrowthTopic::getIsDeleted, 0)
.orderByDesc(GrowthTopic::getCreateTime);
return this.list(wrapper);
}
@Override
public Long countByCategory(String category) {
LambdaQueryWrapper<GrowthTopic> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GrowthTopic::getCategory, category)
.eq(GrowthTopic::getIsDeleted, 0);
return this.count(wrapper);
}
@Override
public Long countByStatus(String status) {
// GrowthTopic实体中没有status字段,暂时返回0
return 0L;
}
@Override
public Long countByDifficultyLevel(String difficultyLevel) {
LambdaQueryWrapper<GrowthTopic> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GrowthTopic::getDifficulty, difficultyLevel)
.eq(GrowthTopic::getIsDeleted, 0);
return this.count(wrapper);
}
@Override
public Double getAvgParticipantCount() {
// 这里需要自定义SQL查询平均值,暂时返回0
return 0.0;
}
@Override
public Double getAvgParticipantCountByCategory(String category) {
// 这里需要自定义SQL查询平均值,暂时返回0
return 0.0;
}
@Override
public List<GrowthTopic> searchByTags(String tags) {
// GrowthTopic实体中没有tags字段,暂时返回空列表
return Collections.emptyList();
}
@Override
public List<GrowthTopic> searchByKeyword(String keyword) {
LambdaQueryWrapper<GrowthTopic> wrapper = new LambdaQueryWrapper<>();
wrapper.and(w -> w.like(GrowthTopic::getTitle, keyword)
.or().like(GrowthTopic::getDescription, keyword))
.eq(GrowthTopic::getIsDeleted, 0)
.orderByDesc(GrowthTopic::getCreateTime);
return this.list(wrapper);
}
@Override
public boolean updateParticipantCount(String id, Integer increment) {
// GrowthTopic实体中没有participantCount字段,暂时返回false
return false;
}
@Override
public boolean updateStatus(String id, String status) {
// GrowthTopic实体中没有status字段,暂时返回false
return false;
}
@Override
public List<GrowthTopic> getEndingSoonTopics(Integer days) {
// GrowthTopic实体中没有endTime字段,暂时返回空列表
return Collections.emptyList();
}
@Override
public List<GrowthTopic> getLongTermTopics() {
// GrowthTopic实体中没有endTime字段,暂时返回空列表
return Collections.emptyList();
}
@Override
public GrowthTopic createGrowthTopic(String title, String description, String category,
public GrowthTopic createGrowthTopic(String title, String description, String category,
String difficultyLevel, String tags, LocalDateTime endTime) {
GrowthTopic topic = new GrowthTopic();
topic.setTitle(title);
@@ -211,4 +99,80 @@ public class GrowthTopicServiceImpl extends ServiceImpl<GrowthTopicMapper, Growt
this.save(topic);
return topic;
}
@Override
public GrowthTopicResponse createGrowthTopicWithResponse(GrowthTopicCreateRequest request) {
GrowthTopic topic = createGrowthTopic(
request.getTitle(),
request.getDescription(),
request.getCategory(),
request.getDifficultyLevel(),
request.getTags(),
request.getEndTime());
return convertToResponse(topic);
}
@Override
public GrowthTopicResponse updateGrowthTopicWithResponse(GrowthTopicUpdateRequest request) {
GrowthTopic topic = this.getById(request.getId());
if (topic == null || topic.getIsDeleted() == 1) {
return null;
}
// 只更新非空字段
if (StringUtils.hasText(request.getTitle())) {
topic.setTitle(request.getTitle());
}
if (StringUtils.hasText(request.getDescription())) {
topic.setDescription(request.getDescription());
topic.setContent(request.getDescription());
}
if (StringUtils.hasText(request.getCategory())) {
topic.setCategory(request.getCategory());
}
if (StringUtils.hasText(request.getDifficultyLevel())) {
topic.setDifficulty(request.getDifficultyLevel());
}
if (StringUtils.hasText(request.getTags())) {
// GrowthTopic实体中没有tags字段,暂时忽略
}
if (request.getEndTime() != null) {
// GrowthTopic实体中没有endTime字段,暂时忽略
}
this.updateById(topic);
return convertToResponse(topic);
}
@Override
public boolean deleteGrowthTopic(String id) {
GrowthTopic topic = this.getById(id);
if (topic == null || topic.getIsDeleted() == 1) {
return false;
}
// 逻辑删除
topic.setIsDeleted(1);
return this.updateById(topic);
}
/**
* 将实体转换为响应对象
*/
private GrowthTopicResponse convertToResponse(GrowthTopic topic) {
if (topic == null) {
return null;
}
GrowthTopicResponse response = new GrowthTopicResponse();
BeanUtils.copyProperties(topic, response);
response.setId(topic.getId());
if (topic.getCreateTime() != null) {
response.setCreateTime(topic.getCreateTime().toString());
}
if (topic.getUpdateTime() != null) {
response.setUpdateTime(topic.getUpdateTime().toString());
}
return response;
}
}