forked from opentiny/tiny-engine-backend-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComponentController.java
More file actions
136 lines (128 loc) · 5.75 KB
/
ComponentController.java
File metadata and controls
136 lines (128 loc) · 5.75 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
/**
* 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.enums.Enums;
import com.tinyengine.it.common.exception.ExceptionEnum;
import com.tinyengine.it.common.log.SystemControllerLog;
import com.tinyengine.it.common.utils.SecurityFileCheckUtil;
import com.tinyengine.it.model.dto.BundleResultDto;
import com.tinyengine.it.model.dto.CustComponentDto;
import com.tinyengine.it.model.dto.FileResult;
import com.tinyengine.it.service.material.ComponentService;
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 jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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;
/**
* 组件api
*
* @since 2024-11-13
*/
@Validated
@RestController
@RequestMapping("/material-center/api")
@Tag(name = "组件")
public class ComponentController {
/**
* The component service.
*/
@Autowired
private ComponentService componentService;
/**
* 上传bunled.json文件处理自定义组件
*
* @param file the file
* @return result
*/
@Operation(summary = "上传bunled.json文件创建组件", description = "上传bunled.json文件创建组件", parameters = {
@Parameter(name = "file", description = "文件参数对象")
}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json", schema = @Schema())),
@ApiResponse(responseCode = "400", description = "请求失败")
})
@SystemControllerLog(description = "上传bunled.json文件创建组件")
@PostMapping("/component/bundle/create")
public Result<FileResult> bundleCreateComponent(@RequestParam MultipartFile file) {
if (file.isEmpty()) {
return Result.failed(ExceptionEnum.CM307);
}
SecurityFileCheckUtil.validFileName(file.getOriginalFilename());
boolean checkFileType = SecurityFileCheckUtil.checkFileType(file, Enums.FileNameEnd.JSON.getValue(),
Enums.FileType.JSON.getValue());
if (!checkFileType) {
return Result.failed(ExceptionEnum.CM308);
}
SecurityFileCheckUtil.isValidJson(file);
// 返回插入和更新的条数
return componentService.readFileAndBulkCreate(file);
}
/**
* 上传bunled.json文件处理自定义组件
*
* @param file the file
* @return result
*/
@Operation(summary = "上传bunled.json文件处理自定义组件", description = "上传bunled.json文件处理自定义组件", parameters = {
@Parameter(name = "file", description = "文件参数对象")
}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json", schema = @Schema())),
@ApiResponse(responseCode = "400", description = "请求失败")
})
@SystemControllerLog(description = "上传bunled.json文件处理自定义组件")
@PostMapping("/component/bundle/split")
public Result<BundleResultDto> bundleSplit(@RequestParam MultipartFile file) {
if (file.isEmpty()) {
return Result.failed(ExceptionEnum.CM307);
}
SecurityFileCheckUtil.validFileName(file.getOriginalFilename());
boolean checkFileType = SecurityFileCheckUtil.checkFileType(file, Enums.FileNameEnd.JSON.getValue(),
Enums.FileType.JSON.getValue());
if (!checkFileType) {
return Result.failed(ExceptionEnum.CM308);
}
SecurityFileCheckUtil.isValidJson(file);
return componentService.bundleSplit(file);
}
/**
* 批量创建自定义组件
*
* @param custComponentDto the custComponentDto
* @return result
*/
@Operation(summary = "批量创建自定义组件", description = "批量创建自定义组件", parameters = {
@Parameter(name = "custComponentDto", description = "自定义组件对象")
}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json", schema = @Schema())),
@ApiResponse(responseCode = "400", description = "请求失败")
})
@SystemControllerLog(description = "批量创建自定义组件")
@PostMapping("/component/batch/create")
public Result<FileResult> createCustComponent(@Valid @RequestBody CustComponentDto custComponentDto) {
// 返回插入和更新的条数
return componentService.custComponentBatchCreate(custComponentDto);
}
}