CustomerConvert.java
3.98 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
package cn.com.glsx.entmicro.convert.outbound;
import cn.com.glsx.entmicro.enums.outbound.EndTypeReasonEnum;
import cn.com.glsx.entmicro.model.response.outbound.OutBoundTaskCustomerExportResponse;
import cn.com.glsx.entmicro.model.response.outbound.OutBoundTaskCustomerRpcResponse;
import cn.com.glsx.entmicro.response.outbound.OutBoundTaskCustomerRopResponse;
import cn.com.glsx.entmicro.utils.Pagination;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import org.apache.commons.lang.StringUtils;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author yelq
* @Version 1.0
* @Description:
* @Date 2023/6/6 11:08
*/
public class CustomerConvert {
private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
/**
* 分页转化
* @param page
* @return
*/
public static Pagination<OutBoundTaskCustomerRopResponse> toPage(RpcPagination<OutBoundTaskCustomerRpcResponse> page){
Pagination<OutBoundTaskCustomerRopResponse> pagination = new Pagination<>();
pagination.setPageNum(page.getPageNum());
pagination.setPageSize(page.getPageSize());
pagination.setData(toOutBoundTaskCustomerRopResponses(page.getList()));
pagination.setCount((int)page.getTotal());
pagination.setPageSize(page.getPageSize());
return pagination;
}
/**
* 列表转化
*
* @param list
* @return
*/
public static List<OutBoundTaskCustomerRopResponse> toOutBoundTaskCustomerRopResponses(List<OutBoundTaskCustomerRpcResponse> list) {
if (list == null) {
return null;
} else if (list.isEmpty()) {
return new ArrayList<>();
}
return list.stream().map(CustomerConvert::toOutBoundTaskCustomerRopResponse).collect(Collectors.toList());
}
/**
* 客户返回对象转化为导出对象
*
* @param source
* @return
*/
public static OutBoundTaskCustomerRopResponse toOutBoundTaskCustomerRopResponse(OutBoundTaskCustomerRpcResponse source) {
if (source == null) {
return null;
}
return OutBoundTaskCustomerRopResponse.builder()
.phone(source.getPhone())
.answer(source.getTalkingTimeLen() != null && source.getTalkingTimeLen() > 0 ? "已接听" : source.getTalkingTimeLen() == null ? null : ("未接听(" + EndTypeReasonEnum.getMsg(source.getEndTypeReason()) + ")"))
.startTime(createStartTime(source.getStartTime()))
.reCallTimes(source.getCallTimes() == null || source.getCallTimes() == 0 ? 0 : source.getCallTimes() - 1)
.talkingTimeLen(source.getTalkingTimeLen() == null ? "0s" : source.getTalkingTimeLen() + "s")
.talkingTimeLeng(source.getTalkingTimeLeng() == null ? "0分钟" : source.getTalkingTimeLeng() + "分钟")
.intent(StringUtils.isBlank(source.getIntent()) ? "否" : "是")
.carNumber(source.getCarNumber())
.lastInsuranceCompany(source.getLastInsuranceCompany())
.insuranceEndTime(changeDate(source.getInsuranceEndTime()))
.build();
}
private static String changeDate(Date insuranceEndTime) {
if (insuranceEndTime == null) {
return null;
}
try {
return sdf.format(insuranceEndTime);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 转换开始时间
*
* @param source
* @return
*/
private static String createStartTime(Long source) {
if (source == null) {
return null;
}
try {
return simpleDateFormat.format(new Date(source));
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}