Skip to content

feat: Component library API #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 72 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
b97583e
fix: update page history bug
lu-yg Dec 26, 2024
d30877c
fix: format code and fix style issue
lu-yg Jan 7, 2025
33316bf
Merge branch 'develop' of github.com:lu-yg/tiny-engine-backend-java i…
lu-yg Jan 7, 2025
7fc6507
fix: modify page histiry entity
lu-yg Jan 7, 2025
64be7b4
Merge branch 'opentiny:develop' into develop
lu-yg Jan 9, 2025
24474b8
feat: add code submission rules
lu-yg Jan 9, 2025
9745b66
Merge branch 'develop' of github.com:lu-yg/tiny-engine-backend-java i…
lu-yg Jan 9, 2025
239c624
Merge branch 'opentiny:develop' into develop
lu-yg Jan 9, 2025
b77f2f4
fix: modify app schema for test
lu-yg Jan 9, 2025
feeb8f7
Merge branch 'develop' of github.com:lu-yg/tiny-engine-backend-java i…
lu-yg Jan 9, 2025
7d52937
fix: modify block group
lu-yg Jan 22, 2025
6559bec
fix: modify t_i18n_entry u_idx_i18n_entity
lu-yg Jan 22, 2025
2a7fc44
Merge branch 'opentiny:develop' into develop
lu-yg Jan 22, 2025
656a4a1
fix: modify t_i18n_entry u_idx_i18n_entity
lu-yg Jan 22, 2025
9de10c5
Merge branch 'develop' of github.com:lu-yg/tiny-engine-backend-java i…
lu-yg Jan 22, 2025
e9aa592
fix: modify block update api
lu-yg Jan 23, 2025
aff95bb
Merge branch 'opentiny:develop' into develop
lu-yg Jan 23, 2025
02607e4
Merge branch 'develop' of github.com:lu-yg/tiny-engine-backend-java i…
lu-yg Jan 23, 2025
ed7483d
fix: Modify code format
lu-yg Jan 23, 2025
48267d6
fix: Modify code format
lu-yg Jan 23, 2025
cabb309
fix: Modify code format
lu-yg Jan 23, 2025
83cb48a
fix: Modify code format
lu-yg Jan 24, 2025
486944b
fix: Modify code format
lu-yg Jan 24, 2025
751f331
Merge branch 'opentiny:develop' into develop
lu-yg Jan 26, 2025
48645e1
fix: modify block group api
lu-yg Jan 26, 2025
d2f2406
fix: modify block group mapper
lu-yg Jan 26, 2025
e24d0ec
Merge branch 'develop' of github.com:lu-yg/tiny-engine-backend-java i…
lu-yg Jan 26, 2025
ee8219f
fix: modify workflows
lu-yg Jan 26, 2025
efad29b
fix: Update checkstyle.yml
lu-yg Jan 26, 2025
6868add
fix: modify workflows
lu-yg Jan 26, 2025
2e131ff
fix: Modify block create and update api
lu-yg Jan 27, 2025
9c1225a
Merge branch 'opentiny:develop' into develop
lu-yg Jan 27, 2025
8cc8ca5
fix: Modify code format
lu-yg Jan 27, 2025
4ba0818
fix: Modify code format
lu-yg Jan 27, 2025
6d978f1
fix: Modify block group
lu-yg Feb 6, 2025
b3f35a0
fix: Modify block group
lu-yg Feb 6, 2025
9717200
fix: Modify block group
lu-yg Feb 6, 2025
e757b29
fix: Modify block group
lu-yg Feb 6, 2025
7d90c86
fix: Modify block group api
lu-yg Feb 13, 2025
d6856ba
Merge branch 'opentiny:develop' into develop
lu-yg Feb 13, 2025
8a89475
Merge branch 'develop' of github.com:lu-yg/tiny-engine-backend-java i…
lu-yg Feb 13, 2025
baa4eeb
fix: Modify block group api
lu-yg Feb 13, 2025
654da8b
fix: Modify block group api
lu-yg Feb 13, 2025
a230c24
feat: add code check
lu-yg Feb 27, 2025
6966946
Merge branch 'opentiny:develop' into develop
lu-yg Feb 27, 2025
d503c96
Merge branch 'develop' of github.com:lu-yg/tiny-engine-backend-java i…
lu-yg Feb 27, 2025
7f9b378
feat: add code check
lu-yg Feb 27, 2025
2bdf54c
feat: add code check
lu-yg Feb 27, 2025
bef4adc
Merge branch 'opentiny:develop' into develop
lu-yg Feb 28, 2025
88dec60
feat: add code check
lu-yg Feb 28, 2025
63efa3c
Merge branch 'opentiny:develop' into develop
lu-yg Feb 28, 2025
f05a3ef
fix: Fix code check
lu-yg Feb 28, 2025
dbc910c
Merge branch 'opentiny:develop' into develop
lu-yg Mar 6, 2025
8a4041c
fix: Cross domain configuration
lu-yg Mar 6, 2025
57fd35a
fix: Cross domain configuration
lu-yg Mar 6, 2025
bff62cc
fix: i18n file upload
lu-yg Mar 7, 2025
ededae7
fix: i18n file upload
lu-yg Mar 7, 2025
1fa284b
Merge branch 'opentiny:develop' into develop
lu-yg Mar 20, 2025
7f17fb7
fix: page update api
lu-yg Mar 20, 2025
934130f
fix: page update api
lu-yg Mar 20, 2025
a920283
feat: material history api
lu-yg Apr 1, 2025
b1e0f83
feat: component library api
lu-yg Apr 2, 2025
5d244ba
Merge branch 'develop' of github.com:lu-yg/tiny-engine-backend-java i…
lu-yg Apr 2, 2025
05f4473
feat: component library api
lu-yg Apr 7, 2025
58ed56b
Merge branch 'develop' of github.com:lu-yg/tiny-engine-backend-java i…
lu-yg Apr 7, 2025
6a5269d
feat: component library api
lu-yg Apr 7, 2025
2f31f88
feat: component library api
lu-yg Apr 7, 2025
9ee1ef1
feat: component library api
lu-yg Apr 7, 2025
59c6ddc
feat: component library api
lu-yg Apr 7, 2025
8373484
feat: component library api
lu-yg Apr 7, 2025
fb123c6
feat: component library api
lu-yg Apr 7, 2025
0875559
feat: component library api
lu-yg Apr 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ create table `t_block_carriers_relation`
(
`id` int not null auto_increment comment '主键id',
`block_id` int not null comment '区块id',
`host_id` int not null comment '类型id',
`host_id` int not null comment '类型id',
`host_type` varchar(60) comment '类型:blockGroup,materialHistory',
`version` varchar(60) not null comment '区块当前使用版本',
`tenant_id` varchar(60) not null comment '租户id',
Expand All @@ -642,4 +642,36 @@ create table `r_block_group_block`
`block_group_id` int not null comment '区块分组id',
primary key (`id`) using btree,
unique index `u_idx_block_group_block` (block_id, block_group_id) using btree
) engine = innodb comment = '区块分组和区块关系表';
) engine = innodb comment = '区块分组和区块关系表';

drop table if exists `t_component_library`;

create table `t_component_library`
(
`id` int not null auto_increment comment '主键id',
`version` varchar(255) not null comment '版本',
`name` varchar(255) not null comment '名称',
`package` varchar(255) not null comment '包名',
`registry` varchar(255) comment '注册',
`framework` varchar(255) not null comment '技术栈',
`description` varchar(2000) comment '描述',
`script` varchar(255) comment '脚本地址',
`css` varchar(255) comment '样式地址',
`bundle` varchar(255) comment 'bundle.json地址',
`dependencies` longtext comment '依赖',
`others` longtext comment '其他',
`thumbnail` varchar(255) comment '略图',
`public` int comment '公开状态:0,1,2',
`is_started` tinyint(1) comment '是否启用',
`is_official` tinyint(1) comment '是否是官方',
`is_default` tinyint(1) comment '是否是默认',
`tenant_id` varchar(60) not null comment '租户id',
`renter_id` varchar(60) comment '业务租户id',
`site_id` varchar(60) comment '站点id,设计预留字段',
`created_by` varchar(60) not null comment '创建人',
`created_time` timestamp not null default current_timestamp comment '创建时间',
`last_updated_by` varchar(60) not null comment '最后修改人',
`last_updated_time` timestamp not null default current_timestamp comment '更新时间',
primary key (`id`) using btree,
unique index `u_idx_component_library` (`tenant_id`, `name`, `version`) using btree
) engine = innodb comment = '组件库表';
17 changes: 15 additions & 2 deletions base/src/main/java/com/tinyengine/it/common/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,11 @@ public static Result<JsonFile> parseJsonFileStream(MultipartFile file) {
// 使用 try-with-resources 自动管理输入流
byte[] fileBytes = Utils.readAllBytes(file.getInputStream());
String jsonContent = new String(fileBytes, StandardCharsets.UTF_8);

String jsonString = removeBOM(jsonContent);
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> jsonData =
objectMapper.readValue(jsonContent, new TypeReference<Map<String, Object>>() {
objectMapper.readValue(jsonString, new TypeReference<Map<String, Object>>() {
});

jsonFile.setFileName(fileName);
Expand All @@ -398,7 +400,18 @@ public static Result<JsonFile> parseJsonFileStream(MultipartFile file) {
log.info("Successfully parsed JSON file: {}", fileName);
return Result.success(jsonFile);
}

/**
* 去除文件BOM字符
*
* @param input the inpu
* @return input the input
*/
public static String removeBOM(String input) {
if (input != null && input.startsWith("\uFEFF")) {
return input.substring(1);
}
return input;
}
/**
* 校验文件流合法性
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
import com.tinyengine.it.common.base.Result;
import com.tinyengine.it.common.exception.ExceptionEnum;
import com.tinyengine.it.common.log.SystemControllerLog;
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.model.entity.Component;
import com.tinyengine.it.service.material.ComponentService;

import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -28,11 +31,15 @@
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;

import javax.validation.Valid;
import java.util.List;

/**
* 组件api
*
Expand All @@ -43,9 +50,33 @@
@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);
}
// 返回插入和更新的条数
return componentService.readFileAndBulkCreate(file);
}

/**
* 上传bunled.json文件处理自定义组件
*
Expand All @@ -58,12 +89,29 @@ public class ComponentController {
content = @Content(mediaType = "application/json", schema = @Schema())),
@ApiResponse(responseCode = "400", description = "请求失败")})
@SystemControllerLog(description = "上传bunled.json文件处理自定义组件")
@PostMapping("/component/custom/create")
public Result<FileResult> createCustComponent(@RequestParam MultipartFile file) {
@PostMapping("/component/bundle/split")
public Result<BundleResultDto> bundleSplit(@RequestParam MultipartFile file) {
if (file.isEmpty()) {
return Result.failed(ExceptionEnum.CM307);
}
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.readFileAndBulkCreate(file);
return componentService.custComponentBatchCreate(custComponentDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/**
* 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.log.SystemControllerLog;
import com.tinyengine.it.model.entity.ComponentLibrary;
import com.tinyengine.it.service.material.ComponentLibraryService;
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.DeleteMapping;
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.RestController;

import javax.validation.Valid;
import java.util.List;

/**
* 组件库API
*
* @since 2025-4-02
*/
@Validated
@RestController
@RequestMapping("/material-center/api")
@Tag(name = "组件库")
public class ComponentLibraryController {
/**
* The ComponentLibrary service.
*/
@Autowired
private ComponentLibraryService componentLibraryService;

/**
* 查询表ComponentLibrary信息列表
*
* @return ComponentLibrary信息 all componentLibrary
*/
@Operation(summary = "查询表ComponentLibrary信息列表",
description = "查询表ComponentLibrary信息列表",
responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ComponentLibrary.class))),
@ApiResponse(responseCode = "400", description = "请求失败")})
@SystemControllerLog(description = "查询表ComponentLibrary信息列表")
@GetMapping("/component-library/list")
public Result<List<ComponentLibrary>> getAllComponentLibrary() {
List<ComponentLibrary> componentLibraryHistoryList = componentLibraryService.queryAllComponentLibrary();
return Result.success(componentLibraryHistoryList);
}

/**
* 创建ComponentLibrary
*
* @param componentLibrary the componentLibrary
* @return ComponentLibrary信息 result
*/
@Operation(summary = "创建ComponentLibrary",
description = "创建ComponentLibrary",
parameters = {
@Parameter(name = "ComponentLibrary", description = "ComponentLibrary入参对象")
},
responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ComponentLibrary.class))),
@ApiResponse(responseCode = "400", description = "请求失败")}
)
@SystemControllerLog(description = "创建ComponentLibrary")
@PostMapping("/component-library/create")
public Result<ComponentLibrary> createComponentLibrary(@Valid @RequestBody ComponentLibrary componentLibrary) {
return componentLibraryService.createComponentLibrary(componentLibrary);
}

/**
* 修改ComponentLibrary信息
*
* @param id the id
* @param componentLibrary the componentLibrary
* @return ComponentLibrary信息 result
*/
@Operation(summary = "修改单个ComponentLibrary信息", description = "修改单个ComponentLibrary信息", parameters = {
@Parameter(name = "id", description = "appId"),
@Parameter(name = "ComponentLibrary", description = "入参对象")}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ComponentLibrary.class))),
@ApiResponse(responseCode = "400", description = "请求失败")})
@SystemControllerLog(description = "修改单个ComponentLibrary信息")
@PostMapping("/component-library/update/{id}")
public Result<ComponentLibrary> updateComponentLibrary(@PathVariable Integer id, @RequestBody ComponentLibrary componentLibrary) {
componentLibrary.setId(id);
return componentLibraryService.updateComponentLibraryById(componentLibrary);
}

/**
* 删除ComponentLibrary信息
*
* @param id the id
* @return ComponentLibrary信息 result
*/
@Operation(summary = "删除ComponentLibrary信息",
description = "删除ComponentLibrary信息",
parameters = {
@Parameter(name = "id", description = "ComponentLibrary主键id")
},
responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ComponentLibrary.class))),
@ApiResponse(responseCode = "400", description = "请求失败")}
)
@SystemControllerLog(description = "删除ComponentLibrary信息")
@DeleteMapping("/component-library/delete/{id}")
public Result<ComponentLibrary> deleteComponentLibrary(@PathVariable Integer id) {
return componentLibraryService.deleteComponentLibraryById(id);
}

/**
* 获取ComponentLibrary信息详情
*
* @param id the id
* @return the result
*/
@Operation(summary = "获取ComponentLibrary信息详情", description = "获取ComponentLibrary信息详情", parameters = {
@Parameter(name = "id", description = "appId")}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = ComponentLibrary.class))),
@ApiResponse(responseCode = "400", description = "请求失败")})
@SystemControllerLog(description = "获取ComponentLibrary信息详情")
@GetMapping("/component-library/detail/{id}")
public Result<ComponentLibrary> detail(@PathVariable Integer id) {
return componentLibraryService.queryComponentLibraryById(id);
}
}
Loading
Loading