MassDetailStaffConvert.java
7.17 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package cn.com.glsx.entmicro.converter;
import cn.com.glsx.entmicro.dto.mass.MassCustomerSenderItemDTO;
import cn.com.glsx.entmicro.dto.mass.MassGroupDetailSenderDTO;
import cn.com.glsx.entmicro.dto.mass.MassStaffSenderItemDTO;
import cn.com.glsx.entmicro.entity.Mass;
import cn.com.glsx.entmicro.entity.MassDetailStaff;
import cn.com.glsx.entmicro.entity.mass.MassChatItemEntity;
import cn.com.glsx.entmicro.entity.mass.MassCustomerItemEntity;
import cn.com.glsx.entmicro.model.response.CustomerInfoResponse;
import cn.com.glsx.entmicro.model.response.EntmicroStaffResponse;
import cn.com.glsx.entmicro.model.response.MassDetailStaffResponse;
import cn.com.glsx.entmicro.util.DateFormatUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author wangxw
* @version 1.0.0
* @ClassName MassDetailStaffConvert.java
* @description: ${description}
* @createTime 2021年11月16日 14:18:00
*/
public class MassDetailStaffConvert {
public static List<MassDetailStaffResponse> convertStaffList(List<MassDetailStaff> massDetailList) {
if (CollectionUtils.isEmpty(massDetailList)) {
return null;
}
List<MassDetailStaffResponse> massDetailStaffResponseList = new ArrayList<>();
for (MassDetailStaff staff : massDetailList) {
massDetailStaffResponseList.add(convertStaff(staff));
}
return massDetailStaffResponseList;
}
private static MassDetailStaffResponse convertStaff(MassDetailStaff staff) {
MassDetailStaffResponse massDetailStaffResponse = new MassDetailStaffResponse();
BeanUtils.copyProperties(staff, massDetailStaffResponse);
return massDetailStaffResponse;
}
public static List<MassStaffSenderItemDTO> convertToMassStaffDetailList(List<MassDetailStaffResponse> staffResponseList, Map<Integer, EntmicroStaffResponse> staffMapper) {
if (CollectionUtils.isEmpty(staffResponseList)) {
return null;
}
List<MassStaffSenderItemDTO> massStaffSenderItemDTOList = new ArrayList<>();
for (MassDetailStaffResponse massDetail:staffResponseList) {
massStaffSenderItemDTOList.add(convertToMassStaffDetail(massDetail, staffMapper.get(massDetail.getStaffId())));
}
return massStaffSenderItemDTOList;
}
private static MassStaffSenderItemDTO convertToMassStaffDetail(MassDetailStaffResponse massDetail, EntmicroStaffResponse entmicroStaffResponse) {
MassStaffSenderItemDTO massStaffSenderItemDTO = new MassStaffSenderItemDTO();
massStaffSenderItemDTO.setId(massDetail.getId());
massStaffSenderItemDTO.setStaffId(massDetail.getStaffId());
massStaffSenderItemDTO.setCustomerCount(massDetail.getCustomerNum());
massStaffSenderItemDTO.setStatus(massDetail.getStatus());
if (entmicroStaffResponse!=null) {
massStaffSenderItemDTO.setStaffName(entmicroStaffResponse.getStaffName());
massStaffSenderItemDTO.setAvatar(entmicroStaffResponse.getThumbAvatar());
}
return massStaffSenderItemDTO;
}
public static List<MassCustomerSenderItemDTO> convertCustomerList(List<MassCustomerItemEntity> massDetailCustomerList, Map<Integer, EntmicroStaffResponse> staffMapper, Map<Integer, CustomerInfoResponse> customerMapper) {
if (CollectionUtils.isEmpty(massDetailCustomerList)) {
return null;
}
List<MassCustomerSenderItemDTO> massCustomerSenderItemDTOList = new ArrayList<>();
for (MassCustomerItemEntity customerItem:massDetailCustomerList) {
massCustomerSenderItemDTOList.add(convertCustomerItem(customerItem, staffMapper.get(customerItem.getStaffId()), customerMapper.get(customerItem.getCustomerId())));
}
return massCustomerSenderItemDTOList;
}
private static MassCustomerSenderItemDTO convertCustomerItem(MassCustomerItemEntity customerItem, EntmicroStaffResponse entmicroStaffResponse, CustomerInfoResponse customerInfoResponse) {
MassCustomerSenderItemDTO massCustomerSenderItemDTO = new MassCustomerSenderItemDTO();
massCustomerSenderItemDTO.setCustomerId(customerItem.getCustomerId());
massCustomerSenderItemDTO.setStatus(customerItem.getStatus());
if (customerInfoResponse!=null) {
massCustomerSenderItemDTO.setAvatar(customerInfoResponse.getAvatar());
massCustomerSenderItemDTO.setCustomerName(customerInfoResponse.getCustomerName());
}
if (entmicroStaffResponse!=null) {
massCustomerSenderItemDTO.setStaffName(entmicroStaffResponse.getStaffName());
}
return massCustomerSenderItemDTO;
}
/**
*
* @param massChatDetailList
* @param staffMapper
* @return
*/
public static List<MassGroupDetailSenderDTO> convertChatList(List<MassChatItemEntity> massChatDetailList, Map<Integer, EntmicroStaffResponse> staffMapper) {
if (CollectionUtils.isEmpty(massChatDetailList)) {
return null;
}
List<MassGroupDetailSenderDTO> groupDetailSenderDTOList = new ArrayList<>();
for (MassChatItemEntity chatItem:massChatDetailList) {
groupDetailSenderDTOList.add(convertChatItem(chatItem, staffMapper.get(chatItem.getStaffId())));
}
return groupDetailSenderDTOList;
}
private static MassGroupDetailSenderDTO convertChatItem(MassChatItemEntity chatItem, EntmicroStaffResponse entmicroStaffResponse) {
MassGroupDetailSenderDTO massGroupDetailSenderDTO = new MassGroupDetailSenderDTO();
BeanUtils.copyProperties(chatItem, massGroupDetailSenderDTO);
massGroupDetailSenderDTO.setSenderTime((chatItem.getSendTime()!=null)? DateFormatUtil.toString(chatItem.getSendTime(), DateFormatUtil.pattern19):"");
if (entmicroStaffResponse!=null) {
massGroupDetailSenderDTO.setStaffName(entmicroStaffResponse.getStaffName());
massGroupDetailSenderDTO.setDepartmentName(entmicroStaffResponse.getDepartmentName());
}
return massGroupDetailSenderDTO;
}
public static List<MassGroupDetailSenderDTO> convertToMassGroupDetailSenderDTO(List<MassChatItemEntity> massChatDetailList, Mass mass) {
if (massChatDetailList==null||massChatDetailList.isEmpty()){
return new ArrayList<>();
}
List<MassGroupDetailSenderDTO> list = new ArrayList<>(massChatDetailList.size());
for (MassChatItemEntity massChatItemEntity : massChatDetailList) {
MassGroupDetailSenderDTO senderDTO = new MassGroupDetailSenderDTO();
senderDTO.setId(mass.getId());
senderDTO.setSenderTime((massChatItemEntity.getSendTime()!=null)? DateFormatUtil.toString(massChatItemEntity.getSendTime(), DateFormatUtil.pattern19):"");
senderDTO.setStaffRelationId(massChatItemEntity.getStaffRelationId());
senderDTO.setGroupName(massChatItemEntity.getGroupName());
senderDTO.setStaffId(massChatItemEntity.getStaffId());
senderDTO.setCustomerCount(massChatItemEntity.getCustomerCount());
senderDTO.setStatus(massChatItemEntity.getStatus());
list.add(senderDTO);
}
return list;
}
}