VoiceListResponseDTO.java
2.56 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
package com.xly.tts.bean;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
/**
* 语音列表响应数据传输对象
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class VoiceListResponseDTO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 语音列表
*/
private List<VoiceInfoDTO> voices;
/**
* 当前页码
*/
private Integer currentPage;
/**
* 每页大小
*/
private Integer pageSize;
/**
* 总记录数
*/
private Long totalCount;
/**
* 总页数
*/
private Integer totalPages;
/**
* 是否有下一页
*/
private Boolean hasNext;
/**
* 是否有上一页
*/
private Boolean hasPrevious;
/**
* 查询条件
*/
private VoiceQueryDTO query;
/**
* 按语言分组的数据
*/
private List<VoiceGroupDTO> groups;
/**
* 推荐的默认语音
*/
private VoiceInfoDTO defaultVoice;
/**
* 时间戳
*/
private Long timestamp;
/**
* 状态码
*/
@Builder.Default
private Integer code = 200;
/**
* 状态消息
*/
@Builder.Default
private String message = "success";
/**
* 创建成功响应
*/
public static VoiceListResponseDTO success(List<VoiceInfoDTO> voices, VoiceQueryDTO query,
Long totalCount) {
int pageSize = query != null ? query.getPageSize() : 20;
int currentPage = query != null ? query.getPage() : 1;
int totalPages = (int) Math.ceil((double) totalCount / pageSize);
return VoiceListResponseDTO.builder()
.voices(voices)
.currentPage(currentPage)
.pageSize(pageSize)
.totalCount(totalCount)
.totalPages(totalPages)
.hasNext(currentPage < totalPages)
.hasPrevious(currentPage > 1)
.query(query)
.timestamp(System.currentTimeMillis())
.code(200)
.message("获取成功")
.build();
}
/**
* 创建失败响应
*/
public static VoiceListResponseDTO error(String message) {
return VoiceListResponseDTO.builder()
.code(500)
.message(message)
.timestamp(System.currentTimeMillis())
.build();
}
}