Skip to content

Commit b1370f0

Browse files
authored
feat: Component library API (#203)
* feat: component library api
1 parent 49944ef commit b1370f0

33 files changed

+1684
-111
lines changed

app/src/main/resources/sql/mysql/create_all_tables_ddl_v1.mysql.sql

+34-2
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ create table `t_block_carriers_relation`
619619
(
620620
`id` int not null auto_increment comment '主键id',
621621
`block_id` int not null comment '区块id',
622-
`host_id` int not null comment '类型id',
622+
`host_id` int not null comment '类型id',
623623
`host_type` varchar(60) comment '类型:blockGroup,materialHistory',
624624
`version` varchar(60) not null comment '区块当前使用版本',
625625
`tenant_id` varchar(60) not null comment '租户id',
@@ -642,4 +642,36 @@ create table `r_block_group_block`
642642
`block_group_id` int not null comment '区块分组id',
643643
primary key (`id`) using btree,
644644
unique index `u_idx_block_group_block` (block_id, block_group_id) using btree
645-
) engine = innodb comment = '区块分组和区块关系表';
645+
) engine = innodb comment = '区块分组和区块关系表';
646+
647+
drop table if exists `t_component_library`;
648+
649+
create table `t_component_library`
650+
(
651+
`id` int not null auto_increment comment '主键id',
652+
`version` varchar(255) not null comment '版本',
653+
`name` varchar(255) not null comment '名称',
654+
`package` varchar(255) not null comment '包名',
655+
`registry` varchar(255) comment '注册',
656+
`framework` varchar(255) not null comment '技术栈',
657+
`description` varchar(2000) comment '描述',
658+
`script` varchar(255) comment '脚本地址',
659+
`css` varchar(255) comment '样式地址',
660+
`bundle` varchar(255) comment 'bundle.json地址',
661+
`dependencies` longtext comment '依赖',
662+
`others` longtext comment '其他',
663+
`thumbnail` varchar(255) comment '略图',
664+
`public` int comment '公开状态:0,1,2',
665+
`is_started` tinyint(1) comment '是否启用',
666+
`is_official` tinyint(1) comment '是否是官方',
667+
`is_default` tinyint(1) comment '是否是默认',
668+
`tenant_id` varchar(60) not null comment '租户id',
669+
`renter_id` varchar(60) comment '业务租户id',
670+
`site_id` varchar(60) comment '站点id,设计预留字段',
671+
`created_by` varchar(60) not null comment '创建人',
672+
`created_time` timestamp not null default current_timestamp comment '创建时间',
673+
`last_updated_by` varchar(60) not null comment '最后修改人',
674+
`last_updated_time` timestamp not null default current_timestamp comment '更新时间',
675+
primary key (`id`) using btree,
676+
unique index `u_idx_component_library` (`tenant_id`, `name`, `version`) using btree
677+
) engine = innodb comment = '组件库表';

base/src/main/java/com/tinyengine/it/common/utils/Utils.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,11 @@ public static Result<JsonFile> parseJsonFileStream(MultipartFile file) {
384384
// 使用 try-with-resources 自动管理输入流
385385
byte[] fileBytes = Utils.readAllBytes(file.getInputStream());
386386
String jsonContent = new String(fileBytes, StandardCharsets.UTF_8);
387+
388+
String jsonString = removeBOM(jsonContent);
387389
ObjectMapper objectMapper = new ObjectMapper();
388390
Map<String, Object> jsonData =
389-
objectMapper.readValue(jsonContent, new TypeReference<Map<String, Object>>() {
391+
objectMapper.readValue(jsonString, new TypeReference<Map<String, Object>>() {
390392
});
391393

392394
jsonFile.setFileName(fileName);
@@ -398,7 +400,18 @@ public static Result<JsonFile> parseJsonFileStream(MultipartFile file) {
398400
log.info("Successfully parsed JSON file: {}", fileName);
399401
return Result.success(jsonFile);
400402
}
401-
403+
/**
404+
* 去除文件BOM字符
405+
*
406+
* @param input the inpu
407+
* @return input the input
408+
*/
409+
public static String removeBOM(String input) {
410+
if (input != null && input.startsWith("\uFEFF")) {
411+
return input.substring(1);
412+
}
413+
return input;
414+
}
402415
/**
403416
* 校验文件流合法性
404417
*

base/src/main/java/com/tinyengine/it/controller/ComponentController.java

+51-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
import com.tinyengine.it.common.base.Result;
1616
import com.tinyengine.it.common.exception.ExceptionEnum;
1717
import com.tinyengine.it.common.log.SystemControllerLog;
18+
import com.tinyengine.it.model.dto.BundleResultDto;
19+
import com.tinyengine.it.model.dto.CustComponentDto;
1820
import com.tinyengine.it.model.dto.FileResult;
21+
import com.tinyengine.it.model.entity.Component;
1922
import com.tinyengine.it.service.material.ComponentService;
2023

2124
import io.swagger.v3.oas.annotations.Operation;
@@ -28,11 +31,15 @@
2831
import org.springframework.beans.factory.annotation.Autowired;
2932
import org.springframework.validation.annotation.Validated;
3033
import org.springframework.web.bind.annotation.PostMapping;
34+
import org.springframework.web.bind.annotation.RequestBody;
3135
import org.springframework.web.bind.annotation.RequestMapping;
3236
import org.springframework.web.bind.annotation.RequestParam;
3337
import org.springframework.web.bind.annotation.RestController;
3438
import org.springframework.web.multipart.MultipartFile;
3539

40+
import javax.validation.Valid;
41+
import java.util.List;
42+
3643
/**
3744
* 组件api
3845
*
@@ -43,9 +50,33 @@
4350
@RequestMapping("/material-center/api")
4451
@Tag(name = "组件")
4552
public class ComponentController {
53+
/**
54+
* The component service.
55+
*/
4656
@Autowired
4757
private ComponentService componentService;
4858

59+
/**
60+
* 上传bunled.json文件处理自定义组件
61+
*
62+
* @param file the file
63+
* @return result
64+
*/
65+
@Operation(summary = "上传bunled.json文件创建组件", description = "上传bunled.json文件创建组件", parameters = {
66+
@Parameter(name = "file", description = "文件参数对象")}, responses = {
67+
@ApiResponse(responseCode = "200", description = "返回信息",
68+
content = @Content(mediaType = "application/json", schema = @Schema())),
69+
@ApiResponse(responseCode = "400", description = "请求失败")})
70+
@SystemControllerLog(description = "上传bunled.json文件创建组件")
71+
@PostMapping("/component/bundle/create")
72+
public Result<FileResult> bundleCreateComponent(@RequestParam MultipartFile file) {
73+
if (file.isEmpty()) {
74+
return Result.failed(ExceptionEnum.CM307);
75+
}
76+
// 返回插入和更新的条数
77+
return componentService.readFileAndBulkCreate(file);
78+
}
79+
4980
/**
5081
* 上传bunled.json文件处理自定义组件
5182
*
@@ -58,12 +89,29 @@ public class ComponentController {
5889
content = @Content(mediaType = "application/json", schema = @Schema())),
5990
@ApiResponse(responseCode = "400", description = "请求失败")})
6091
@SystemControllerLog(description = "上传bunled.json文件处理自定义组件")
61-
@PostMapping("/component/custom/create")
62-
public Result<FileResult> createCustComponent(@RequestParam MultipartFile file) {
92+
@PostMapping("/component/bundle/split")
93+
public Result<BundleResultDto> bundleSplit(@RequestParam MultipartFile file) {
6394
if (file.isEmpty()) {
6495
return Result.failed(ExceptionEnum.CM307);
6596
}
97+
return componentService.bundleSplit(file);
98+
}
99+
100+
/**
101+
* 批量创建自定义组件
102+
*
103+
* @param custComponentDto the custComponentDto
104+
* @return result
105+
*/
106+
@Operation(summary = "批量创建自定义组件", description = "批量创建自定义组件", parameters = {
107+
@Parameter(name = "custComponentDto", description = "自定义组件对象")}, responses = {
108+
@ApiResponse(responseCode = "200", description = "返回信息",
109+
content = @Content(mediaType = "application/json", schema = @Schema())),
110+
@ApiResponse(responseCode = "400", description = "请求失败")})
111+
@SystemControllerLog(description = "批量创建自定义组件")
112+
@PostMapping("/component/batch/create")
113+
public Result<FileResult> createCustComponent(@Valid @RequestBody CustComponentDto custComponentDto) {
66114
// 返回插入和更新的条数
67-
return componentService.readFileAndBulkCreate(file);
115+
return componentService.custComponentBatchCreate(custComponentDto);
68116
}
69117
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/**
2+
* Copyright (c) 2023 - present TinyEngine Authors.
3+
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
4+
*
5+
* Use of this source code is governed by an MIT-style license.
6+
*
7+
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8+
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9+
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10+
*
11+
*/
12+
13+
package com.tinyengine.it.controller;
14+
15+
import com.tinyengine.it.common.base.Result;
16+
import com.tinyengine.it.common.log.SystemControllerLog;
17+
import com.tinyengine.it.model.entity.ComponentLibrary;
18+
import com.tinyengine.it.service.material.ComponentLibraryService;
19+
import io.swagger.v3.oas.annotations.Operation;
20+
import io.swagger.v3.oas.annotations.Parameter;
21+
import io.swagger.v3.oas.annotations.media.Content;
22+
import io.swagger.v3.oas.annotations.media.Schema;
23+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
24+
import io.swagger.v3.oas.annotations.tags.Tag;
25+
import org.springframework.beans.factory.annotation.Autowired;
26+
import org.springframework.validation.annotation.Validated;
27+
import org.springframework.web.bind.annotation.DeleteMapping;
28+
import org.springframework.web.bind.annotation.GetMapping;
29+
import org.springframework.web.bind.annotation.PathVariable;
30+
import org.springframework.web.bind.annotation.PostMapping;
31+
import org.springframework.web.bind.annotation.RequestBody;
32+
import org.springframework.web.bind.annotation.RequestMapping;
33+
import org.springframework.web.bind.annotation.RestController;
34+
35+
import javax.validation.Valid;
36+
import java.util.List;
37+
38+
/**
39+
* 组件库API
40+
*
41+
* @since 2025-4-02
42+
*/
43+
@Validated
44+
@RestController
45+
@RequestMapping("/material-center/api")
46+
@Tag(name = "组件库")
47+
public class ComponentLibraryController {
48+
/**
49+
* The ComponentLibrary service.
50+
*/
51+
@Autowired
52+
private ComponentLibraryService componentLibraryService;
53+
54+
/**
55+
* 查询表ComponentLibrary信息列表
56+
*
57+
* @return ComponentLibrary信息 all componentLibrary
58+
*/
59+
@Operation(summary = "查询表ComponentLibrary信息列表",
60+
description = "查询表ComponentLibrary信息列表",
61+
responses = {
62+
@ApiResponse(responseCode = "200", description = "返回信息",
63+
content = @Content(mediaType = "application/json",
64+
schema = @Schema(implementation = ComponentLibrary.class))),
65+
@ApiResponse(responseCode = "400", description = "请求失败")})
66+
@SystemControllerLog(description = "查询表ComponentLibrary信息列表")
67+
@GetMapping("/component-library/list")
68+
public Result<List<ComponentLibrary>> getAllComponentLibrary() {
69+
List<ComponentLibrary> componentLibraryHistoryList = componentLibraryService.queryAllComponentLibrary();
70+
return Result.success(componentLibraryHistoryList);
71+
}
72+
73+
/**
74+
* 创建ComponentLibrary
75+
*
76+
* @param componentLibrary the componentLibrary
77+
* @return ComponentLibrary信息 result
78+
*/
79+
@Operation(summary = "创建ComponentLibrary",
80+
description = "创建ComponentLibrary",
81+
parameters = {
82+
@Parameter(name = "ComponentLibrary", description = "ComponentLibrary入参对象")
83+
},
84+
responses = {
85+
@ApiResponse(responseCode = "200", description = "返回信息",
86+
content = @Content(mediaType = "application/json",
87+
schema = @Schema(implementation = ComponentLibrary.class))),
88+
@ApiResponse(responseCode = "400", description = "请求失败")}
89+
)
90+
@SystemControllerLog(description = "创建ComponentLibrary")
91+
@PostMapping("/component-library/create")
92+
public Result<ComponentLibrary> createComponentLibrary(@Valid @RequestBody ComponentLibrary componentLibrary) {
93+
return componentLibraryService.createComponentLibrary(componentLibrary);
94+
}
95+
96+
/**
97+
* 修改ComponentLibrary信息
98+
*
99+
* @param id the id
100+
* @param componentLibrary the componentLibrary
101+
* @return ComponentLibrary信息 result
102+
*/
103+
@Operation(summary = "修改单个ComponentLibrary信息", description = "修改单个ComponentLibrary信息", parameters = {
104+
@Parameter(name = "id", description = "appId"),
105+
@Parameter(name = "ComponentLibrary", description = "入参对象")}, responses = {
106+
@ApiResponse(responseCode = "200", description = "返回信息",
107+
content = @Content(mediaType = "application/json",
108+
schema = @Schema(implementation = ComponentLibrary.class))),
109+
@ApiResponse(responseCode = "400", description = "请求失败")})
110+
@SystemControllerLog(description = "修改单个ComponentLibrary信息")
111+
@PostMapping("/component-library/update/{id}")
112+
public Result<ComponentLibrary> updateComponentLibrary(@PathVariable Integer id, @RequestBody ComponentLibrary componentLibrary) {
113+
componentLibrary.setId(id);
114+
return componentLibraryService.updateComponentLibraryById(componentLibrary);
115+
}
116+
117+
/**
118+
* 删除ComponentLibrary信息
119+
*
120+
* @param id the id
121+
* @return ComponentLibrary信息 result
122+
*/
123+
@Operation(summary = "删除ComponentLibrary信息",
124+
description = "删除ComponentLibrary信息",
125+
parameters = {
126+
@Parameter(name = "id", description = "ComponentLibrary主键id")
127+
},
128+
responses = {
129+
@ApiResponse(responseCode = "200", description = "返回信息",
130+
content = @Content(mediaType = "application/json",
131+
schema = @Schema(implementation = ComponentLibrary.class))),
132+
@ApiResponse(responseCode = "400", description = "请求失败")}
133+
)
134+
@SystemControllerLog(description = "删除ComponentLibrary信息")
135+
@DeleteMapping("/component-library/delete/{id}")
136+
public Result<ComponentLibrary> deleteComponentLibrary(@PathVariable Integer id) {
137+
return componentLibraryService.deleteComponentLibraryById(id);
138+
}
139+
140+
/**
141+
* 获取ComponentLibrary信息详情
142+
*
143+
* @param id the id
144+
* @return the result
145+
*/
146+
@Operation(summary = "获取ComponentLibrary信息详情", description = "获取ComponentLibrary信息详情", parameters = {
147+
@Parameter(name = "id", description = "appId")}, responses = {
148+
@ApiResponse(responseCode = "200", description = "返回信息",
149+
content = @Content(mediaType = "application/json",
150+
schema = @Schema(implementation = ComponentLibrary.class))),
151+
@ApiResponse(responseCode = "400", description = "请求失败")})
152+
@SystemControllerLog(description = "获取ComponentLibrary信息详情")
153+
@GetMapping("/component-library/detail/{id}")
154+
public Result<ComponentLibrary> detail(@PathVariable Integer id) {
155+
return componentLibraryService.queryComponentLibraryById(id);
156+
}
157+
}

0 commit comments

Comments
 (0)