Skip to content

Commit 05f4473

Browse files
committed
feat: component library api
1 parent 5d244ba commit 05f4473

22 files changed

+495
-176
lines changed

app/src/main/resources/sql/h2/add_is_started_column_to_t_material_history.h2.sql

Lines changed: 0 additions & 2 deletions
This file was deleted.

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

Lines changed: 0 additions & 2 deletions
This file was deleted.

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

Lines changed: 15 additions & 2 deletions
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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
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.CustComponentDto;
1819
import com.tinyengine.it.model.dto.FileResult;
20+
import com.tinyengine.it.model.entity.Component;
1921
import com.tinyengine.it.service.material.ComponentService;
2022

2123
import io.swagger.v3.oas.annotations.Operation;
@@ -33,6 +35,8 @@
3335
import org.springframework.web.bind.annotation.RestController;
3436
import org.springframework.web.multipart.MultipartFile;
3537

38+
import java.util.List;
39+
3640
/**
3741
* 组件api
3842
*
@@ -43,6 +47,9 @@
4347
@RequestMapping("/material-center/api")
4448
@Tag(name = "组件")
4549
public class ComponentController {
50+
/**
51+
* The component service.
52+
*/
4653
@Autowired
4754
private ComponentService componentService;
4855

@@ -58,12 +65,30 @@ public class ComponentController {
5865
content = @Content(mediaType = "application/json", schema = @Schema())),
5966
@ApiResponse(responseCode = "400", description = "请求失败")})
6067
@SystemControllerLog(description = "上传bunled.json文件处理自定义组件")
61-
@PostMapping("/component/custom/create")
62-
public Result<FileResult> createCustComponent(@RequestParam MultipartFile file) {
68+
@PostMapping("/component/bundle/split")
69+
public Result<FileResult> bundleSplit(@RequestParam MultipartFile file) {
6370
if (file.isEmpty()) {
6471
return Result.failed(ExceptionEnum.CM307);
6572
}
6673
// 返回插入和更新的条数
6774
return componentService.readFileAndBulkCreate(file);
6875
}
76+
77+
/**
78+
* 批量创建自定义组件
79+
*
80+
* @param custComponentDto the custComponentDto
81+
* @return result
82+
*/
83+
@Operation(summary = "批量创建自定义组件", description = "批量创建自定义组件", parameters = {
84+
@Parameter(name = "file", description = "文件参数对象")}, responses = {
85+
@ApiResponse(responseCode = "200", description = "返回信息",
86+
content = @Content(mediaType = "application/json", schema = @Schema())),
87+
@ApiResponse(responseCode = "400", description = "请求失败")})
88+
@SystemControllerLog(description = "批量创建自定义组件")
89+
@PostMapping("/component/batch/create")
90+
public Result<FileResult> createCustComponent(@RequestParam CustComponentDto custComponentDto) {
91+
// 返回插入和更新的条数
92+
return componentService.custComponentBatchCreate(custComponentDto);
93+
}
6994
}

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
*/
4242
@Validated
4343
@RestController
44-
@RequestMapping("/componentLibrary-center/api")
44+
@RequestMapping("/material-center/api")
4545
@Tag(name = "组件库")
4646
public class ComponentLibraryController {
4747
/**
@@ -51,19 +51,19 @@ public class ComponentLibraryController {
5151
private ComponentLibraryService componentLibraryService;
5252

5353
/**
54-
* 查询表ComponentLibrary信息
54+
* 查询表ComponentLibrary信息列表
5555
*
5656
* @return ComponentLibrary信息 all componentLibrary
5757
*/
58-
@Operation(summary = "查询表ComponentLibrary信息",
59-
description = "查询表ComponentLibrary信息",
58+
@Operation(summary = "查询表ComponentLibrary信息列表",
59+
description = "查询表ComponentLibrary信息列表",
6060
responses = {
6161
@ApiResponse(responseCode = "200", description = "返回信息",
6262
content = @Content(mediaType = "application/json",
6363
schema = @Schema(implementation = ComponentLibrary.class))),
6464
@ApiResponse(responseCode = "400", description = "请求失败")})
65-
@SystemControllerLog(description = "查询表ComponentLibrary信息")
66-
@GetMapping("/componentLibrary/list")
65+
@SystemControllerLog(description = "查询表ComponentLibrary信息列表")
66+
@GetMapping("/component-library/list")
6767
public Result<List<ComponentLibrary>> getAllComponentLibrary() {
6868
List<ComponentLibrary> componentLibraryHistoryList = componentLibraryService.queryAllComponentLibrary();
6969
return Result.success(componentLibraryHistoryList);
@@ -117,10 +117,10 @@ public Result<ComponentLibrary> updateComponentLibrary(@PathVariable Integer id,
117117
* 删除ComponentLibrary信息
118118
*
119119
* @param id the id
120-
* @return app信息 result
120+
* @return ComponentLibrary信息 result
121121
*/
122-
@Operation(summary = "删除app信息",
123-
description = "删除app信息",
122+
@Operation(summary = "删除ComponentLibrary信息",
123+
description = "删除ComponentLibrary信息",
124124
parameters = {
125125
@Parameter(name = "id", description = "ComponentLibrary主键id")
126126
},
@@ -130,25 +130,25 @@ public Result<ComponentLibrary> updateComponentLibrary(@PathVariable Integer id,
130130
schema = @Schema(implementation = ComponentLibrary.class))),
131131
@ApiResponse(responseCode = "400", description = "请求失败")}
132132
)
133-
@SystemControllerLog(description = "删除app信息")
133+
@SystemControllerLog(description = "删除ComponentLibrary信息")
134134
@GetMapping("/component-library/delete/{id}")
135135
public Result<ComponentLibrary> deleteComponentLibrary(@PathVariable Integer id) {
136136
return componentLibraryService.deleteComponentLibraryById(id);
137137
}
138138

139139
/**
140-
* 获取应用信息详情
140+
* 获取ComponentLibrary信息详情
141141
*
142142
* @param id the id
143143
* @return the result
144144
*/
145-
@Operation(summary = "获取应用信息详情", description = "获取应用信息详情", parameters = {
145+
@Operation(summary = "获取ComponentLibrary信息详情", description = "获取ComponentLibrary信息详情", parameters = {
146146
@Parameter(name = "id", description = "appId")}, responses = {
147147
@ApiResponse(responseCode = "200", description = "返回信息",
148148
content = @Content(mediaType = "application/json",
149149
schema = @Schema(implementation = ComponentLibrary.class))),
150150
@ApiResponse(responseCode = "400", description = "请求失败")})
151-
@SystemControllerLog(description = "获取应用信息详情")
151+
@SystemControllerLog(description = "获取ComponentLibrary信息详情")
152152
@GetMapping("/component-library/detail/{id}")
153153
public Result<ComponentLibrary> detail(@PathVariable Integer id) {
154154
return componentLibraryService.queryComponentLibraryById(id);

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ public class MaterialController {
5555
*
5656
* @return Material信息 all material
5757
*/
58-
@Operation(summary = "查询表Material信息",
59-
description = "查询表Material信息",
58+
@Operation(summary = "查询表Material信息列表",
59+
description = "查询表Material信息列表",
6060
responses = {
6161
@ApiResponse(responseCode = "200", description = "返回信息",
6262
content = @Content(mediaType = "application/json",
6363
schema = @Schema(implementation = Material.class))),
6464
@ApiResponse(responseCode = "400", description = "请求失败")})
65-
@SystemControllerLog(description = "查询表Material信息")
65+
@SystemControllerLog(description = "查询表Material信息列表")
6666
@GetMapping("/material/list")
6767
public Result<List<Material>> getAllMaterial() {
6868
List<Material> materialHistoryList = materialService.queryAllMaterial();
@@ -119,8 +119,8 @@ public Result<Material> updateMaterial(@PathVariable Integer id, @RequestBody Ma
119119
* @param id the id
120120
* @return app信息 result
121121
*/
122-
@Operation(summary = "删除app信息",
123-
description = "删除app信息",
122+
@Operation(summary = "删除Material信息",
123+
description = "删除Material信息",
124124
parameters = {
125125
@Parameter(name = "id", description = "Material主键id")
126126
},
@@ -130,25 +130,25 @@ public Result<Material> updateMaterial(@PathVariable Integer id, @RequestBody Ma
130130
schema = @Schema(implementation = Material.class))),
131131
@ApiResponse(responseCode = "400", description = "请求失败")}
132132
)
133-
@SystemControllerLog(description = "删除app信息")
133+
@SystemControllerLog(description = "删除Material信息")
134134
@GetMapping("/material/delete/{id}")
135135
public Result<Material> deleteMaterial(@PathVariable Integer id) {
136136
return materialService.deleteMaterialById(id);
137137
}
138138

139139
/**
140-
* 获取应用信息详情
140+
* 获取Material信息详情
141141
*
142142
* @param id the id
143143
* @return the result
144144
*/
145-
@Operation(summary = "获取应用信息详情", description = "获取应用信息详情", parameters = {
145+
@Operation(summary = "获取Material信息详情", description = "获取Material信息详情", parameters = {
146146
@Parameter(name = "id", description = "appId")}, responses = {
147147
@ApiResponse(responseCode = "200", description = "返回信息",
148148
content = @Content(mediaType = "application/json",
149149
schema = @Schema(implementation = Material.class))),
150150
@ApiResponse(responseCode = "400", description = "请求失败")})
151-
@SystemControllerLog(description = "获取应用信息详情")
151+
@SystemControllerLog(description = "获取Material信息详情")
152152
@GetMapping("/material/detail/{id}")
153153
public Result<Material> detail(@PathVariable Integer id) {
154154
return materialService.queryMaterialById(id);

base/src/main/java/com/tinyengine/it/mapper/ComponentLibraryMapper.java

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
1616
import com.tinyengine.it.model.entity.ComponentLibrary;
1717

18-
import org.apache.ibatis.annotations.Insert;
1918
import org.apache.ibatis.annotations.Param;
2019

2120
import java.util.List;
@@ -44,10 +43,10 @@ public interface ComponentLibraryMapper extends BaseMapper<ComponentLibrary> {
4443
/**
4544
* 根据条件查询表t_component_library数据
4645
*
47-
* @param component the component
46+
* @param componentLibrary the componentLibrary
4847
* @return the list
4948
*/
50-
List<ComponentLibrary> queryComponentLibraryByCondition(ComponentLibrary component);
49+
List<ComponentLibrary> queryComponentLibraryByCondition(ComponentLibrary componentLibrary);
5150

5251
/**
5352
* 根据主键id删除表t_component_library数据
@@ -60,45 +59,16 @@ public interface ComponentLibraryMapper extends BaseMapper<ComponentLibrary> {
6059
/**
6160
* 根据主键id更新表t_component_library数据
6261
*
63-
* @param component the component
62+
* @param componentLibrary the componentLibrary
6463
* @return the integer
6564
*/
66-
Integer updateComponentLibraryById(ComponentLibrary component);
65+
Integer updateComponentLibraryById(ComponentLibrary componentLibrary);
6766

6867
/**
6968
* 新增表t_component_library数据
7069
*
71-
* @param component the component
70+
* @param componentLibrary the componentLibrary
7271
* @return the integer
7372
*/
74-
Integer createComponentLibrary(ComponentLibrary component);
75-
76-
/**
77-
* Find user components by material history id list.
78-
*
79-
* @param id the id
80-
* @return the list
81-
*/
82-
List<ComponentLibrary> findUserComponentLibrarysByMaterialHistoryId(@Param("id") Integer id);
83-
84-
/**
85-
* 新增表r_material_component数据
86-
*
87-
* @param materialComponentLibrary the materialComponentLibrary
88-
* @return the integer
89-
*/
90-
@Insert("INSERT INTO r_material_component (id,material_id,component_id )"
91-
+ "values (#{id},#{materialId},#{componentId})")
92-
Integer createMaterialComponentLibrary(MaterialComponentLibrary materialComponentLibrary);
93-
94-
95-
/**
96-
* 新增表r_material_component数据
97-
*
98-
* @param materialHistoryComponentLibrary the materialHistoryComponentLibrary
99-
* @return the integer
100-
*/
101-
@Insert("INSERT INTO r_material_history_component (id,material_history_id,component_id )"
102-
+ "values (#{id},#{materialHistoryId},#{componentId})")
103-
Integer createMaterialHistoryComponentLibrary(MaterialHistoryComponentLibrary materialHistoryComponentLibrary);
73+
Integer createComponentLibrary(ComponentLibrary componentLibrary);
10474
}

base/src/main/java/com/tinyengine/it/model/dto/BundleMaterial.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
/**
2121
* BundleMaterial
2222
*
23-
* @since 2024-11-13
23+
* @since 2025-04-02
2424
*/
2525
@Data
2626
public class BundleMaterial {
2727
private List<Map<String, Object>> components;
2828
private List<Child> snippets;
2929
private List<Map<String, Object>> blocks;
30+
private List<Map<String, Object>> packages;
3031
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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.model.dto;
14+
15+
import com.tinyengine.it.model.entity.Component;
16+
import com.tinyengine.it.model.entity.ComponentLibrary;
17+
import lombok.Data;
18+
19+
import java.util.List;
20+
21+
/**
22+
* BundleResultDto
23+
*
24+
* @since 2025-04-02
25+
*/
26+
@Data
27+
public class BundleResultDto {
28+
private List<ComponentLibrary> packageList;
29+
private List<Component> componentList;
30+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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.model.dto;
14+
15+
import com.tinyengine.it.model.entity.Component;
16+
import lombok.Data;
17+
18+
import java.util.List;
19+
20+
/**
21+
* CustComponentDto
22+
*
23+
* @since 2025-04-03
24+
*/
25+
@Data
26+
public class CustComponentDto {
27+
private List<Component> components;
28+
private Integer componentLibraryId;
29+
}

0 commit comments

Comments
 (0)