Commit 28642621 authored by 刘基明's avatar 刘基明

ConvertUtil

parent 8ef1fbcd
...@@ -2,12 +2,12 @@ package com.tanpu.community.controller; ...@@ -2,12 +2,12 @@ package com.tanpu.community.controller;
import com.tanpu.community.api.beans.TopicBriefInfoDTO; import com.tanpu.community.api.beans.TopicBriefInfoDTO;
import com.tanpu.community.api.beans.TopicDTO; import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.controller.convert.TopicConverter;
import com.tanpu.community.dao.entity.community.TopicEntity; import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.manager.TopicManager; import com.tanpu.community.manager.TopicManager;
import com.tanpu.community.model.req.topic.TopicConcealReq; import com.tanpu.community.model.req.topic.TopicConcealReq;
import com.tanpu.community.model.req.topic.TopicModifyMountReq; import com.tanpu.community.model.req.topic.TopicModifyMountReq;
import com.tanpu.community.model.req.topic.TopicTopReq; import com.tanpu.community.model.req.topic.TopicTopReq;
import com.tanpu.community.util.ConvertUtil;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -40,7 +40,7 @@ public class TopicController { ...@@ -40,7 +40,7 @@ public class TopicController {
@ResponseBody @ResponseBody
public List<TopicDTO> getAllTopicList(){ public List<TopicDTO> getAllTopicList(){
List<TopicEntity> allTopic = topicManager.getAllTopic(); List<TopicEntity> allTopic = topicManager.getAllTopic();
List<TopicDTO> topicDTOS = TopicConverter.convertToDTOs(allTopic); List<TopicDTO> topicDTOS = ConvertUtil.topicEntitiesToDTOs(allTopic);
//获取浏览数据:浏览、发帖、回帖 //获取浏览数据:浏览、发帖、回帖
return topicDTOS; return topicDTOS;
} }
......
...@@ -4,7 +4,8 @@ import com.tanpu.community.api.beans.ThemeDTO; ...@@ -4,7 +4,8 @@ import com.tanpu.community.api.beans.ThemeDTO;
import com.tanpu.community.api.constants.BlockTypeEnum; import com.tanpu.community.api.constants.BlockTypeEnum;
import com.tanpu.community.api.constants.CollectionTypeEnum; import com.tanpu.community.api.constants.CollectionTypeEnum;
import com.tanpu.community.api.constants.CommentTypeEnum; import com.tanpu.community.api.constants.CommentTypeEnum;
import com.tanpu.community.controller.convert.ThemeConvert; import com.tanpu.community.util.ConvertUtil;
import com.tanpu.community.util.ThemeConvert;
import com.tanpu.community.dao.entity.community.BlackListEntity; import com.tanpu.community.dao.entity.community.BlackListEntity;
import com.tanpu.community.dao.entity.community.CommentEntity; import com.tanpu.community.dao.entity.community.CommentEntity;
import com.tanpu.community.dao.entity.community.FansRelEntity; import com.tanpu.community.dao.entity.community.FansRelEntity;
...@@ -44,7 +45,7 @@ public class ThemeManager { ...@@ -44,7 +45,7 @@ public class ThemeManager {
public List<ThemeDTO> selectHotThemes(){ public List<ThemeDTO> selectHotThemes(){
//TODO:根据算法计算推荐主题 //TODO:根据算法计算推荐主题
List<ThemeEntity> themeEntities = themeService.selectAll(); List<ThemeEntity> themeEntities = themeService.selectAll();
List<ThemeDTO> themeDTOS = ThemeConvert.convertToDTOs(themeEntities); List<ThemeDTO> themeDTOS = ConvertUtil.themeEntitiesToDTOs(themeEntities);
for (ThemeDTO themeDTO : themeDTOS) { for (ThemeDTO themeDTO : themeDTOS) {
themeDTO.setUpToNowTime(calUpToNowTime(themeDTO.getCreateTime())); themeDTO.setUpToNowTime(calUpToNowTime(themeDTO.getCreateTime()));
...@@ -57,7 +58,7 @@ public class ThemeManager { ...@@ -57,7 +58,7 @@ public class ThemeManager {
public List<ThemeDTO> selectInterestThemes(String userId){ public List<ThemeDTO> selectInterestThemes(String userId){
List<String> fansList = fansRelService.queryFansByFollowerId(userId).stream().map(FansRelEntity::getIdolId).collect(Collectors.toList()); List<String> fansList = fansRelService.queryFansByFollowerId(userId).stream().map(FansRelEntity::getIdolId).collect(Collectors.toList());
List<ThemeEntity> themeEntities = themeService.selectByFans(fansList); List<ThemeEntity> themeEntities = themeService.selectByFans(fansList);
List<ThemeDTO> themeDTOS = ThemeConvert.convertToDTOs(themeEntities); List<ThemeDTO> themeDTOS = ConvertUtil.themeEntitiesToDTOs(themeEntities);
for (ThemeDTO themeDTO : themeDTOS) { for (ThemeDTO themeDTO : themeDTOS) {
themeDTO.setUpToNowTime(calUpToNowTime(themeDTO.getCreateTime())); themeDTO.setUpToNowTime(calUpToNowTime(themeDTO.getCreateTime()));
......
...@@ -5,10 +5,10 @@ import com.tanpu.community.api.beans.TopicBriefInfoDTO; ...@@ -5,10 +5,10 @@ import com.tanpu.community.api.beans.TopicBriefInfoDTO;
import com.tanpu.community.api.beans.TopicDTO; import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.api.constants.RedisKeyConstant; import com.tanpu.community.api.constants.RedisKeyConstant;
import com.tanpu.community.api.constants.TopicStatusEnum; import com.tanpu.community.api.constants.TopicStatusEnum;
import com.tanpu.community.controller.convert.TopicConverter;
import com.tanpu.community.dao.entity.community.ThemeEntity; import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.entity.community.TopicEntity; import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.service.*; import com.tanpu.community.service.*;
import com.tanpu.community.util.ConvertUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -74,7 +74,7 @@ public class TopicManager { ...@@ -74,7 +74,7 @@ public class TopicManager {
public TopicDTO getDetail(String topicId) { public TopicDTO getDetail(String topicId) {
TopicEntity topicEntity = topicService.queryById(topicId); TopicEntity topicEntity = topicService.queryById(topicId);
TopicDTO topicDTO = TopicConverter.convertToDTO(topicEntity); TopicDTO topicDTO = ConvertUtil.topicEntityToDTO(topicEntity);
//TODO:添加实时数据(浏览量,点赞量,评论量,收藏量) //TODO:添加实时数据(浏览量,点赞量,评论量,收藏量)
topicDTO.setViewAmount(redisService.getLong(RedisKeyConstant.TOPIC_VIEW_AMOUNT_+topicId)); topicDTO.setViewAmount(redisService.getLong(RedisKeyConstant.TOPIC_VIEW_AMOUNT_+topicId));
topicDTO.setLikeAmount(redisService.getLong(RedisKeyConstant.TOPIC_LIKE_AMOUNT_+topicId)); topicDTO.setLikeAmount(redisService.getLong(RedisKeyConstant.TOPIC_LIKE_AMOUNT_+topicId));
...@@ -114,3 +114,4 @@ public class TopicManager { ...@@ -114,3 +114,4 @@ public class TopicManager {
} }
} }
package com.tanpu.community.util;
import com.tanpu.community.api.beans.ThemeDTO;
import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.entity.community.TopicEntity;
import org.springframework.beans.BeanUtils;
import java.util.List;
import java.util.stream.Collectors;
public class ConvertUtil {
public static ThemeDTO themeEntityToDTO(ThemeEntity themeEntity){
ThemeDTO themeDTO = new ThemeDTO();
BeanUtils.copyProperties(themeEntity, themeDTO);
return themeDTO;
}
public static ThemeEntity themeDTOToEntity(ThemeDTO themeDTO){
ThemeEntity themeEntity = new ThemeEntity();
BeanUtils.copyProperties(themeDTO,themeEntity);
return themeEntity;
}
public static List<ThemeDTO> themeEntitiesToDTOs(List<ThemeEntity> themeEntities){
return themeEntities.stream().map(ConvertUtil::themeEntityToDTO).collect(Collectors.toList());
}
public static List<ThemeEntity> themeDTOSToEntitys(List<ThemeDTO> themeDTOS){
return themeDTOS.stream().map(ConvertUtil::themeDTOToEntity).collect(Collectors.toList());
}
public static TopicDTO topicEntityToDTO(TopicEntity topicEntity){
TopicDTO topicDTO = new TopicDTO();
BeanUtils.copyProperties(topicEntity,topicDTO);
return topicDTO;
}
public static List<TopicDTO> topicEntitiesToDTOs(List<TopicEntity> topicEntities){
return topicEntities.stream().map(ConvertUtil::topicEntityToDTO).collect(Collectors.toList());
}
}
package com.tanpu.community.controller.convert; package com.tanpu.community.util;
import com.tanpu.community.api.beans.ThemeDTO; import com.tanpu.community.api.beans.ThemeDTO;
import com.tanpu.community.dao.entity.community.ThemeEntity; import com.tanpu.community.dao.entity.community.ThemeEntity;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import java.util.List;
import java.util.stream.Collectors;
public class ThemeConvert { public class ThemeConvert {
public static ThemeDTO convertToDTO(ThemeEntity themeEntity){ public static ThemeDTO convertToDTO(ThemeEntity themeEntity){
ThemeDTO themeDTO = new ThemeDTO(); ThemeDTO themeDTO = new ThemeDTO();
...@@ -45,11 +42,4 @@ public class ThemeConvert { ...@@ -45,11 +42,4 @@ public class ThemeConvert {
return themeEntity; return themeEntity;
} }
public static List<ThemeDTO> convertToEntitys(List<ThemeEntity> topicEntities){
return topicEntities.stream().map(ThemeConvert::convertToDTO).collect(Collectors.toList());
}
public static List<ThemeDTO> convertToDTOs(List<ThemeEntity> topicEntities){
return topicEntities.stream().map(ThemeConvert::convertToDTO).collect(Collectors.toList());
}
} }
package com.tanpu.community.controller.convert; package com.tanpu.community.util;
import com.tanpu.community.api.beans.TopicDTO; import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.dao.entity.community.TopicEntity; import com.tanpu.community.dao.entity.community.TopicEntity;
import java.util.List;
import java.util.stream.Collectors;
public class TopicConverter { public class TopicConverter {
...@@ -22,8 +19,4 @@ public class TopicConverter { ...@@ -22,8 +19,4 @@ public class TopicConverter {
topicDTO.setDeleteTag(topicEntity.getDeleteTag()); topicDTO.setDeleteTag(topicEntity.getDeleteTag());
return topicDTO; return topicDTO;
} }
public static List<TopicDTO> convertToDTOs(List<TopicEntity> topicEntities){
return topicEntities.stream().map(TopicConverter::convertToDTO).collect(Collectors.toList());
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment