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
package com.tanpu.community.util;
import com.tanpu.community.api.beans.qo.FollowQo;
import com.tanpu.community.api.beans.req.CreateThemeReq;
import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.TopicBriefInfoDTO;
import com.tanpu.community.api.beans.TopicDTO;
import com.tanpu.community.api.constants.DeleteTagEnum;
import com.tanpu.community.dao.entity.community.HomePageEntity;
import com.tanpu.community.dao.entity.community.ThemeAttachmentEntity;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.entity.community.TopicEntity;
import org.springframework.beans.BeanUtils;
import java.util.ArrayList;
import java.util.Collections;
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 TopicDTO topicEntityToDTO(TopicEntity topicEntity) {
TopicDTO topicDTO = new TopicDTO();
BeanUtils.copyProperties(topicEntity, topicDTO);
return topicDTO;
}
public static TopicBriefInfoDTO topicToBriefInfoDTO(TopicEntity topicEntity) {
TopicBriefInfoDTO topicBriefInfoDTO = new TopicBriefInfoDTO();
BeanUtils.copyProperties(topicEntity, topicBriefInfoDTO);
return topicBriefInfoDTO;
}
public static List<TopicDTO> topicEntitiesToDTOs(List<TopicEntity> topicEntities) {
return topicEntities.stream().map(ConvertUtil::topicEntityToDTO).collect(Collectors.toList());
}
public static List<TopicBriefInfoDTO> 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) {
if (req == null || req.getAttachment() == null || req.getAttachment().size() == 0) {
return Collections.emptyList();
}
List<ThemeAttachmentEntity> list = new ArrayList<>();
req.getAttachment().forEach((k, v) -> {
list.add(ThemeAttachmentEntity.builder()
.attachType(Integer.valueOf(k))
.attchId(v)
.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;
}
}