forked from opentiny/tiny-engine-backend-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI18nEntryController.java
More file actions
294 lines (277 loc) · 13 KB
/
I18nEntryController.java
File metadata and controls
294 lines (277 loc) · 13 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/
package com.tinyengine.it.controller;
import com.tinyengine.it.common.base.Result;
import com.tinyengine.it.common.exception.ExceptionEnum;
import com.tinyengine.it.common.exception.ServiceException;
import com.tinyengine.it.common.log.SystemControllerLog;
import com.tinyengine.it.common.utils.SecurityFileCheckUtil;
import com.tinyengine.it.model.dto.DeleteI18nEntry;
import com.tinyengine.it.model.dto.FileResult;
import com.tinyengine.it.model.dto.I18nEntryDto;
import com.tinyengine.it.model.dto.I18nEntryListResult;
import com.tinyengine.it.model.dto.OperateI18nBatchEntries;
import com.tinyengine.it.model.dto.OperateI18nEntries;
import com.tinyengine.it.model.entity.I18nEntry;
import com.tinyengine.it.service.app.I18nEntryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.validation.Valid;
/**
* <p>
* 国际化词条
* </p>
*
* @author zhangjuncao
* @since 2024-10-20
*/
@Validated
@RestController
@RequestMapping("/app-center/api")
@Tag(name = "国际化")
public class I18nEntryController {
/**
* The 18 n entry service.
*/
@Autowired
private I18nEntryService i18nEntryService;
/**
* Gets all i 18 n entries by app.
*
* @return 获取国际化词条列表 i 18 n entries
*/
@Operation(summary = "通过app获取国际化词条列表", description = "通过app获取国际化词条列表", responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json", schema = @Schema())),
@ApiResponse(responseCode = "400", description = "请求失败")
})
@SystemControllerLog(description = "获取国际化词条列表")
@GetMapping("/i18n/entries")
public Result<I18nEntryListResult> getI18nEntriesByApp( @RequestParam(value = "host", required = false) Integer host,
@RequestParam(value = "host_type", required = false) String hostType) {
I18nEntryListResult i18nEntriesList = i18nEntryService.findI18nEntryByApp(host, hostType);
return Result.success(i18nEntriesList);
}
/**
* 获取国际化语言的详情。
*
* @param id 国际化语言id
* @return 国际化语言详情 i 18 n entries by id
*/
@Operation(summary = "获取国际化语言的详情", description = "获取国际化语言的详情", parameters = {
@Parameter(name = "id", description = "I18nEntries主键id")
}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = I18nEntry.class))),
@ApiResponse(responseCode = "400", description = "请求失败")
})
@SystemControllerLog(description = "获取国际化语言的详情")
@GetMapping("/i18n/entries/{id}")
public Result<I18nEntryDto> getI18nEntriesById(@Valid @PathVariable Integer id) {
I18nEntryDto i18nEntry = i18nEntryService.findI18nEntryById(id);
return Result.success(i18nEntry);
}
/**
* 创建国际化多语言词条
*
* @param operateI18nEntries the operate i 18 n entries
* @return result
*/
@Operation(summary = "创建国际化多语言词条", description = "创建国际化多语言词条", parameters = {
@Parameter(name = "OperateI18nEntries", description = "入参对象")
}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = I18nEntry.class))),
@ApiResponse(responseCode = "400", description = "请求失败")
})
@SystemControllerLog(description = "创建国际化多语言词条")
@PostMapping("/i18n/entries/create")
public Result<List<I18nEntry>> createI18nEntries(@Valid @RequestBody OperateI18nEntries operateI18nEntries) {
List<I18nEntry> i18nEntriesList = new ArrayList<>();
i18nEntriesList = i18nEntryService.create(operateI18nEntries);
return Result.success(i18nEntriesList);
}
/**
* 批量创建国际化多语言词条
*
* @param operateI18nBatchEntries the operate i 18 n batch entries
* @return the result
*/
@Operation(summary = "批量创建国际化多语言词条", description = "批量创建国际化多语言词条", parameters = {
@Parameter(name = "operateI18nBatchEntries", description = "入参对象")
}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = I18nEntry.class))),
@ApiResponse(responseCode = "400", description = "请求失败")
})
@SystemControllerLog(description = "批量创建国际化多语言词条")
@PostMapping("/i18n/entries/batch/create")
public Result<List<I18nEntry>> batchCreateEntries(
@Valid @RequestBody OperateI18nBatchEntries operateI18nBatchEntries) {
// map中有host、host_type、entries
List<I18nEntry> i18nEntriesList = i18nEntryService.bulkCreate(operateI18nBatchEntries);
return Result.success(i18nEntriesList);
}
/**
* Update i 18 n entries result.
*
* @param id the id
* @param i18nEntries the 18 n entries
* @return the result
*/
@Operation(summary = "修改国际化单语言词条", description = "修改国际化单语言词条", parameters = {
@Parameter(name = "id", description = "I18nEntries主键id"),
@Parameter(name = "i18nEntries", description = "入参对象")
}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = I18nEntry.class))),
@ApiResponse(responseCode = "400", description = "请求失败")
})
@SystemControllerLog(description = "修改国际化单语言词条")
@PostMapping("/i18n/entries/update/{id}")
public Result<I18nEntryDto> updateI18nEntries(@PathVariable Integer id,
@RequestBody I18nEntry i18nEntries) {
i18nEntries.setId(id);
i18nEntryService.updateI18nEntryById(i18nEntries);
I18nEntryDto i18nEntryDto = i18nEntryService.findI18nEntryById(id);
return Result.success(i18nEntryDto);
}
/**
* 修改国际化多语言词条
*
* @param operateI18nEntries the operate i 18 n entries
* @return 修改成功信息 result
*/
@Operation(summary = "修改国际化多语言词条", description = "修改国际化多语言词条", parameters = {
@Parameter(name = "operateI18nEntries", description = "入参对象")
}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = I18nEntry.class))),
@ApiResponse(responseCode = "400", description = "请求失败")
})
@SystemControllerLog(description = "修改国际化多语言词条")
@PostMapping("/i18n/entries/update")
public Result<List<I18nEntry>> updateEntry(@Valid @RequestBody OperateI18nEntries operateI18nEntries) {
// bulkUpdate
List<I18nEntry> i18nEntriesList = new ArrayList<>();
i18nEntriesList = i18nEntryService.bulkUpdate(operateI18nEntries);
return Result.success(i18nEntriesList);
}
/**
* 删除多语言词条
*
* @param deleteI18nEntry the delete i 18 n entry
* @return result
* @throws ServiceException the service exception
*/
@Operation(summary = "删除多语言词条", description = "删除多语言词条", parameters = {
@Parameter(name = "iDeleteI18nEntry", description = "入参对象")
}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = I18nEntry.class))),
@ApiResponse(responseCode = "400", description = "请求失败")
})
@SystemControllerLog(description = "删除多语言词条")
@PostMapping("/i18n/entries/bulk/delete")
public Result<List<I18nEntryDto>> deleteI18nEntries(@RequestBody DeleteI18nEntry deleteI18nEntry)
throws ServiceException {
List<I18nEntryDto> i18nEntriesList = i18nEntryService
.deleteI18nEntriesByHostAndHostTypeAndKey(deleteI18nEntry);
return Result.success(i18nEntriesList);
}
/**
* 应用下上传单文件处理国际化词条
*
* @param id the id
* @param filesMap the files map
* @return result
* @throws Exception the exception
*/
@Operation(summary = "应用下上传单文件处理国际化词条", description = "应用下上传单文件处理国际化词条", parameters = {
@Parameter(name = "id", description = "appId"),
@Parameter(name = "filesMap", description = "文件参数对象")
}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json", schema = @Schema())),
@ApiResponse(responseCode = "400", description = "请求失败")
})
@SystemControllerLog(description = "应用下上传单文件处理国际化词条")
@PostMapping("/apps/{id}/i18n/entries/update")
public Result<FileResult> updateI18nSingleFile(
@PathVariable Integer id,
@RequestParam Map<String, MultipartFile> filesMap) throws Exception {
Result<FileResult> result = new Result<>();
for (Map.Entry<String, MultipartFile> entry : filesMap.entrySet()) {
// 获取对应的文件
MultipartFile file = entry.getValue();
if (file.isEmpty()) {
return Result.failed(ExceptionEnum.CM307);
}
SecurityFileCheckUtil.validFileName(file.getOriginalFilename());
// 返回插入和更新的条数
result = i18nEntryService.readSingleFileAndBulkCreate(file, id);
}
return result;
}
/**
* 应用下批量上传国际化词条文件
*
* @param id id
* @param filesMap filesMap
* @return the result
* @throws Exception exception
*/
@Operation(summary = "应用下批量上传国际化词条文件", description = "应用下批量上传国际化词条文件", parameters = {
@Parameter(name = "id", description = "appId"),
@Parameter(name = "filesMap", description = "文件参数对象")
}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json", schema = @Schema())),
@ApiResponse(responseCode = "400", description = "请求失败")
})
@SystemControllerLog(description = "应用下批量上传国际化词条文件")
@PostMapping("/apps/{id}/i18n/entries/multiUpdate")
public Result<FileResult> updateI18nMultiFile(
@PathVariable Integer id,
@RequestParam Map<String, MultipartFile> filesMap) throws Exception {
Result<FileResult> result = new Result<>();
// 处理上传的文件
for (Map.Entry<String, MultipartFile> entry : filesMap.entrySet()) {
String key = entry.getKey(); // 获取动态的参数名
MultipartFile file = entry.getValue(); // 获取对应的文件
if (file.isEmpty()) {
return Result.failed(ExceptionEnum.CM307);
}
SecurityFileCheckUtil.validFileName(file.getOriginalFilename());
// 返回插入和更新的条数
result = i18nEntryService.readFilesAndbulkCreate(key, file, id);
}
return result;
}
}