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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.tanpu.community.util;
import com.tanpu.community.api.beans.TopicDO;
import com.tanpu.community.api.beans.qo.*;
import com.tanpu.community.api.beans.req.theme.CreateThemeReq;
import com.tanpu.community.api.beans.req.theme.ThemeContentReq;
import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.RelTypeEnum;
import com.tanpu.community.dao.entity.community.*;
import org.springframework.beans.BeanUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class ConvertUtil {
public static ThemeQo themeEntityToDTO(ThemeEntity themeEntity) {
ThemeQo themeQO = new ThemeQo();
BeanUtils.copyProperties(themeEntity, themeQO);
return themeQO;
}
public static ThemeEntity themeDTOToEntity(ThemeQo themeQO) {
ThemeEntity themeEntity = new ThemeEntity();
BeanUtils.copyProperties(themeQO, themeEntity);
return themeEntity;
}
public static List<ThemeQo> themeEntitiesToDTOs(List<ThemeEntity> themeEntities) {
return themeEntities.stream().map(ConvertUtil::themeEntityToDTO).collect(Collectors.toList());
}
public static List<ThemeEntity> themeDTOSToEntitys(List<ThemeQo> themeQos) {
return themeQos.stream().map(ConvertUtil::themeDTOToEntity).collect(Collectors.toList());
}
public static TopicDO topicEntityToDTO(TopicEntity topicEntity) {
TopicDO topicDO = new TopicDO();
BeanUtils.copyProperties(topicEntity, topicDO);
return topicDO;
}
public static TopicTitileQo topicToBriefInfoDTO(TopicEntity topicEntity) {
TopicTitileQo topicTitileQo = new TopicTitileQo();
BeanUtils.copyProperties(topicEntity, topicTitileQo);
return topicTitileQo;
}
public static CommentQo commentEntity2Qo(CommentEntity entity) {
CommentQo qo = new CommentQo();
BeanUtils.copyProperties(entity, qo);
return qo;
}
public static List<CommentQo> commentEntity2Qos(List<CommentEntity> entities){
return entities.stream().map(ConvertUtil::commentEntity2Qo).collect(Collectors.toList());
}
public static CommentLv2Qo commentLv2Entity2Qo(CommentEntity entity) {
CommentLv2Qo qo = new CommentLv2Qo();
BeanUtils.copyProperties(entity, qo);
return qo;
}
public static List<CommentLv2Qo> commentLv2Entity2Qos(List<CommentEntity> entities){
return entities.stream().map(ConvertUtil::commentLv2Entity2Qo).collect(Collectors.toList());
}
public static List<TopicDO> topicEntitiesToDTOs(List<TopicEntity> topicEntities) {
return topicEntities.stream().map(ConvertUtil::topicEntityToDTO).collect(Collectors.toList());
}
public static List<TopicTitileQo> topicEntitiesToBriefDTOs(List<TopicEntity> topicEntities) {
return topicEntities.stream().map(ConvertUtil::topicToBriefInfoDTO).collect(Collectors.toList());
}
public static DeleteTagEnum deleteTagShift(DeleteTagEnum deleteTagEnum) {
if (deleteTagEnum.getCode().equals(DeleteTagEnum.NOT_DELETED.getCode())) {
return DeleteTagEnum.DELETED;
} else {
return DeleteTagEnum.NOT_DELETED;
}
}
public static Integer deleteTagShift(Integer deleteTag) {
if (deleteTag.equals(DeleteTagEnum.NOT_DELETED.getCode())) {
return DeleteTagEnum.DELETED.getCode();
} else {
return DeleteTagEnum.NOT_DELETED.getCode();
}
}
public static List<ThemeAttachmentEntity> themeReqToAttachmentList(CreateThemeReq req, String themeId) {
List<ThemeContentReq> contents = req.getContent();
List<ThemeAttachmentEntity> list = new ArrayList<>();
for (ThemeContentReq content : contents) {
if (!RelTypeEnum.TEXT.type.equals(content.getType())){
list.add(ThemeAttachmentEntity.builder()
.attachType(Integer.valueOf(content.getType()))
.attachId(content.getValue())
.themeId(themeId)
.build());
}
}
return list;
}
public static FollowQo homePageEntity2FollowQo(HomePageEntity entity) {
if (entity == null) {
return null;
}
FollowQo followQo = new FollowQo();
BeanUtils.copyProperties(entity, followQo);
return followQo;
}
}