diff --git a/app/src/main/resources/sql/mysql/create_all_tables_ddl_v1.mysql.sql b/app/src/main/resources/sql/mysql/create_all_tables_ddl_v1.mysql.sql index ee023852..a4cfa649 100644 --- a/app/src/main/resources/sql/mysql/create_all_tables_ddl_v1.mysql.sql +++ b/app/src/main/resources/sql/mysql/create_all_tables_ddl_v1.mysql.sql @@ -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', @@ -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 = '区块分组和区块关系表'; \ No newline at end of file +) 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 = '组件库表'; diff --git a/base/src/main/java/com/tinyengine/it/common/utils/Utils.java b/base/src/main/java/com/tinyengine/it/common/utils/Utils.java index 1d3b3eb0..bf173001 100644 --- a/base/src/main/java/com/tinyengine/it/common/utils/Utils.java +++ b/base/src/main/java/com/tinyengine/it/common/utils/Utils.java @@ -384,9 +384,11 @@ public static Result 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 jsonData = - objectMapper.readValue(jsonContent, new TypeReference>() { + objectMapper.readValue(jsonString, new TypeReference>() { }); jsonFile.setFileName(fileName); @@ -398,7 +400,18 @@ public static Result 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; + } /** * 校验文件流合法性 * diff --git a/base/src/main/java/com/tinyengine/it/controller/ComponentController.java b/base/src/main/java/com/tinyengine/it/controller/ComponentController.java index 631eaf5a..3b7a6feb 100644 --- a/base/src/main/java/com/tinyengine/it/controller/ComponentController.java +++ b/base/src/main/java/com/tinyengine/it/controller/ComponentController.java @@ -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; @@ -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 * @@ -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 bundleCreateComponent(@RequestParam MultipartFile file) { + if (file.isEmpty()) { + return Result.failed(ExceptionEnum.CM307); + } + // 返回插入和更新的条数 + return componentService.readFileAndBulkCreate(file); + } + /** * 上传bunled.json文件处理自定义组件 * @@ -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 createCustComponent(@RequestParam MultipartFile file) { + @PostMapping("/component/bundle/split") + public Result 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 createCustComponent(@Valid @RequestBody CustComponentDto custComponentDto) { // 返回插入和更新的条数 - return componentService.readFileAndBulkCreate(file); + return componentService.custComponentBatchCreate(custComponentDto); } } diff --git a/base/src/main/java/com/tinyengine/it/controller/ComponentLibraryController.java b/base/src/main/java/com/tinyengine/it/controller/ComponentLibraryController.java new file mode 100644 index 00000000..eabc5237 --- /dev/null +++ b/base/src/main/java/com/tinyengine/it/controller/ComponentLibraryController.java @@ -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> getAllComponentLibrary() { + List 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 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 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 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 detail(@PathVariable Integer id) { + return componentLibraryService.queryComponentLibraryById(id); + } +} diff --git a/base/src/main/java/com/tinyengine/it/controller/MaterialController.java b/base/src/main/java/com/tinyengine/it/controller/MaterialController.java new file mode 100644 index 00000000..374c9e98 --- /dev/null +++ b/base/src/main/java/com/tinyengine/it/controller/MaterialController.java @@ -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.Material; +import com.tinyengine.it.service.material.MaterialService; +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-1 + */ +@Validated +@RestController +@RequestMapping("/material-center/api") +@Tag(name = "物料历史") +public class MaterialController { + /** + * The Material service. + */ + @Autowired + private MaterialService materialService; + + /** + * 查询表Material信息 + * + * @return Material信息 all material + */ + @Operation(summary = "查询表Material信息列表", + description = "查询表Material信息列表", + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Material.class))), + @ApiResponse(responseCode = "400", description = "请求失败")}) + @SystemControllerLog(description = "查询表Material信息列表") + @GetMapping("/material/list") + public Result> getAllMaterial() { + List materialHistoryList = materialService.queryAllMaterial(); + return Result.success(materialHistoryList); + } + + /** + * 创建Material + * + * @param material the material + * @return Material信息 result + */ + @Operation(summary = "创建Material", + description = "创建Material", + parameters = { + @Parameter(name = "Material", description = "Material入参对象") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Material.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "创建Material") + @PostMapping("/material/create") + public Result createMaterial(@Valid @RequestBody Material material) { + return materialService.createMaterial(material); + } + + /** + * 修改Material信息 + * + * @param id the id + * @param material the material + * @return Material信息 result + */ + @Operation(summary = "修改单个Material信息", description = "修改单个Material信息", parameters = { + @Parameter(name = "id", description = "appId"), + @Parameter(name = "Material", description = "入参对象")}, responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Material.class))), + @ApiResponse(responseCode = "400", description = "请求失败")}) + @SystemControllerLog(description = "修改单个Material信息") + @PostMapping("/material/update/{id}") + public Result updateMaterial(@PathVariable Integer id, @RequestBody Material material) { + material.setId(id); + return materialService.updateMaterialById(material); + } + + /** + * 删除Material信息 + * + * @param id the id + * @return app信息 result + */ + @Operation(summary = "删除Material信息", + description = "删除Material信息", + parameters = { + @Parameter(name = "id", description = "Material主键id") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Material.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "删除Material信息") + @DeleteMapping("/material/delete/{id}") + public Result deleteMaterial(@PathVariable Integer id) { + return materialService.deleteMaterialById(id); + } + + /** + * 获取Material信息详情 + * + * @param id the id + * @return the result + */ + @Operation(summary = "获取Material信息详情", description = "获取Material信息详情", parameters = { + @Parameter(name = "id", description = "appId")}, responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Material.class))), + @ApiResponse(responseCode = "400", description = "请求失败")}) + @SystemControllerLog(description = "获取Material信息详情") + @GetMapping("/material/detail/{id}") + public Result detail(@PathVariable Integer id) { + return materialService.queryMaterialById(id); + } +} diff --git a/base/src/main/java/com/tinyengine/it/mapper/ComponentLibraryMapper.java b/base/src/main/java/com/tinyengine/it/mapper/ComponentLibraryMapper.java new file mode 100644 index 00000000..1de56202 --- /dev/null +++ b/base/src/main/java/com/tinyengine/it/mapper/ComponentLibraryMapper.java @@ -0,0 +1,74 @@ +/** + * 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.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.tinyengine.it.model.entity.ComponentLibrary; + +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * The interface ComponentLibrary mapper. + * + * @since 2025-4-02 + */ +public interface ComponentLibraryMapper extends BaseMapper { + /** + * 查询表t_component_library所有信息 + * + * @return the list + */ + List queryAllComponentLibrary(); + + /** + * 根据主键id查询表t_component_library数据 + * + * @param id the id + * @return the component + */ + ComponentLibrary queryComponentLibraryById(@Param("id") Integer id); + + /** + * 根据条件查询表t_component_library数据 + * + * @param componentLibrary the componentLibrary + * @return the list + */ + List queryComponentLibraryByCondition(ComponentLibrary componentLibrary); + + /** + * 根据主键id删除表t_component_library数据 + * + * @param id the id + * @return the integer + */ + Integer deleteComponentLibraryById(@Param("id") Integer id); + + /** + * 根据主键id更新表t_component_library数据 + * + * @param componentLibrary the componentLibrary + * @return the integer + */ + Integer updateComponentLibraryById(ComponentLibrary componentLibrary); + + /** + * 新增表t_component_library数据 + * + * @param componentLibrary the componentLibrary + * @return the integer + */ + Integer createComponentLibrary(ComponentLibrary componentLibrary); +} \ No newline at end of file diff --git a/base/src/main/java/com/tinyengine/it/model/dto/BundleMaterial.java b/base/src/main/java/com/tinyengine/it/model/dto/BundleMaterial.java index d2d3080d..f894b304 100644 --- a/base/src/main/java/com/tinyengine/it/model/dto/BundleMaterial.java +++ b/base/src/main/java/com/tinyengine/it/model/dto/BundleMaterial.java @@ -20,11 +20,12 @@ /** * BundleMaterial * - * @since 2024-11-13 + * @since 2025-04-02 */ @Data public class BundleMaterial { private List> components; private List snippets; private List> blocks; + private List> packages; } diff --git a/base/src/main/java/com/tinyengine/it/model/dto/BundleResultDto.java b/base/src/main/java/com/tinyengine/it/model/dto/BundleResultDto.java new file mode 100644 index 00000000..d5237fad --- /dev/null +++ b/base/src/main/java/com/tinyengine/it/model/dto/BundleResultDto.java @@ -0,0 +1,30 @@ +/** + * 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.model.dto; + +import com.tinyengine.it.model.entity.Component; +import com.tinyengine.it.model.entity.ComponentLibrary; +import lombok.Data; + +import java.util.List; + +/** + * BundleResultDto + * + * @since 2025-04-02 + */ +@Data +public class BundleResultDto { + private List packageList; + private List componentList; +} diff --git a/base/src/main/java/com/tinyengine/it/model/dto/CustComponentDto.java b/base/src/main/java/com/tinyengine/it/model/dto/CustComponentDto.java new file mode 100644 index 00000000..dccc870e --- /dev/null +++ b/base/src/main/java/com/tinyengine/it/model/dto/CustComponentDto.java @@ -0,0 +1,29 @@ +/** + * 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.model.dto; + +import com.tinyengine.it.model.entity.Component; +import lombok.Data; + +import java.util.List; + +/** + * CustComponentDto + * + * @since 2025-04-03 + */ +@Data +public class CustComponentDto { + private List components; + private Integer componentLibraryId; +} diff --git a/base/src/main/java/com/tinyengine/it/model/dto/PackagesDto.java b/base/src/main/java/com/tinyengine/it/model/dto/PackagesDto.java new file mode 100644 index 00000000..d511636f --- /dev/null +++ b/base/src/main/java/com/tinyengine/it/model/dto/PackagesDto.java @@ -0,0 +1,36 @@ +/** + * 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.model.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +import java.util.Map; + +/** + * PackagesDto + * + * @since 2025-04-03 + */ +@Setter +@Getter +public class PackagesDto { + private String name; + @JsonProperty("package") + private String packageName; + private String version; + private String script; + private String css; + private Map others; +} diff --git a/base/src/main/java/com/tinyengine/it/model/dto/SchemaDto.java b/base/src/main/java/com/tinyengine/it/model/dto/SchemaDto.java index 4b2eb6a7..76b20047 100644 --- a/base/src/main/java/com/tinyengine/it/model/dto/SchemaDto.java +++ b/base/src/main/java/com/tinyengine/it/model/dto/SchemaDto.java @@ -37,4 +37,5 @@ public class SchemaDto { private SchemaMeta meta; private List utils; private String version; + private List packages; } diff --git a/base/src/main/java/com/tinyengine/it/model/entity/Component.java b/base/src/main/java/com/tinyengine/it/model/entity/Component.java index 5e77aa32..01653160 100644 --- a/base/src/main/java/com/tinyengine/it/model/entity/Component.java +++ b/base/src/main/java/com/tinyengine/it/model/entity/Component.java @@ -87,8 +87,9 @@ public class Component extends BaseEntity { @Schema(name = "snippets", description = "schema片段") private List> snippets; + @TableField(typeHandler = MapTypeHandler.class) @Schema(name = "schemaFragment", description = "schema片段") - private String schemaFragment; + private Map schemaFragment; @Schema(name = "configure", description = "配置信息") @JsonProperty("configure") diff --git a/base/src/main/java/com/tinyengine/it/model/entity/ComponentLibrary.java b/base/src/main/java/com/tinyengine/it/model/entity/ComponentLibrary.java new file mode 100644 index 00000000..86d16712 --- /dev/null +++ b/base/src/main/java/com/tinyengine/it/model/entity/ComponentLibrary.java @@ -0,0 +1,95 @@ +/** + * 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.model.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.tinyengine.it.common.base.BaseEntity; +import com.tinyengine.it.common.handler.MapTypeHandler; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; +import java.util.Map; + +/** + *

+ * 组件表 + *

+ * + * @author lu -yg + * @since 2025-4-2 + */ +@Getter +@Setter +@TableName("t_component_library") +@Schema(name = "ComponentLibrary", description = "组件库表") +public class ComponentLibrary extends BaseEntity { + @Schema(name = "version", description = "版本") + private String version; + + @Schema(name = "name", description = "名称") + private String name; + + @JsonProperty("package") + @Schema(name = "package", description = "包名") + private String packageName; + + @Schema(name = "registry", description = "注册") + private String registry; + + @Schema(name = "description", description = "描述") + private String description; + + @Schema(name = "framework", description = "技术栈") + private String framework; + + @Schema(name = "script", description = "脚本地址") + private String script; + + @Schema(name = "css", description = "样式地址") + private String css; + + @Schema(name = "bundle", description = "bundle.json地址") + private String bundle; + + @TableField(typeHandler = MapTypeHandler.class) + @Schema(name = "dependencies", description = "依赖") + private Map dependencies; + + @TableField(typeHandler = MapTypeHandler.class) + @Schema(name = "others", description = "其他") + private Map others; + + @Schema(name = "thumbnail", description = "略图") + private String thumbnail; + + @JsonProperty("public") + @Schema(name = "public", description = "公开状态:0,1,2") + private Integer publicStatus; + + @Schema(name = "isStarted", description = "标识启用") + private Boolean isStarted; + + @Schema(name = "isOfficial", description = "标识官方组件") + private Boolean isOfficial; + + @Schema(name = "isDefault", description = "标识默认组件") + private Boolean isDefault; + + @Schema(name = "components", description = "组件库组件") + private List components; +} diff --git a/base/src/main/java/com/tinyengine/it/service/app/impl/CanvasServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/app/impl/CanvasServiceImpl.java index 206a16d4..344891db 100644 --- a/base/src/main/java/com/tinyengine/it/service/app/impl/CanvasServiceImpl.java +++ b/base/src/main/java/com/tinyengine/it/service/app/impl/CanvasServiceImpl.java @@ -13,6 +13,7 @@ package com.tinyengine.it.service.app.impl; import com.tinyengine.it.common.base.Result; +import com.tinyengine.it.common.context.LoginUserContext; import com.tinyengine.it.mapper.BlockMapper; import com.tinyengine.it.mapper.PageMapper; import com.tinyengine.it.mapper.UserMapper; @@ -38,12 +39,14 @@ public class CanvasServiceImpl implements CanvasService { private BlockMapper blockMapper; @Autowired private UserMapper userMapper; + @Autowired + private LoginUserContext loginUserContext; @Override public Result lockCanvas(Integer id, String state, String type) { int occupier; // needTODO 先试用mock数据,后续添加登录及权限后从session获取, - User user = userMapper.queryUserById(1); + User user = userMapper.queryUserById(Integer.parseInt(loginUserContext.getLoginUserId())); CanvasDto canvasDto = new CanvasDto(); if ("page".equals(type)) { Page page = pageMapper.queryPageById(id); diff --git a/base/src/main/java/com/tinyengine/it/service/app/impl/PageServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/app/impl/PageServiceImpl.java index 8ff5e693..d80963e9 100644 --- a/base/src/main/java/com/tinyengine/it/service/app/impl/PageServiceImpl.java +++ b/base/src/main/java/com/tinyengine/it/service/app/impl/PageServiceImpl.java @@ -1,12 +1,13 @@ /** * 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.service.app.impl; @@ -348,7 +349,7 @@ public Result updatePage(Page page) { // 保存成功,异步生成页面历史记录快照,不保证生成成功 PageHistory pageHistory = new PageHistory(); - // 把Pages中的属性值赋值到PagesHistories中en + // 把Pages中的属性值赋值到PagesHistories中 BeanUtils.copyProperties(page, pageHistory); pageHistory.setPage(pageTemp.getId()); pageHistory.setId(null); @@ -550,6 +551,7 @@ public boolean iCanDoIt(User occupier, User user) { */ public boolean protectDefaultPage(Page page) { String id = page.getParentId(); + if ("0".equals(id)) { return true; } diff --git a/base/src/main/java/com/tinyengine/it/service/app/impl/v1/AppV1ServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/app/impl/v1/AppV1ServiceImpl.java index 71545703..cf55c7c4 100644 --- a/base/src/main/java/com/tinyengine/it/service/app/impl/v1/AppV1ServiceImpl.java +++ b/base/src/main/java/com/tinyengine/it/service/app/impl/v1/AppV1ServiceImpl.java @@ -22,6 +22,7 @@ import com.tinyengine.it.mapper.AppMapper; import com.tinyengine.it.mapper.BlockGroupMapper; import com.tinyengine.it.mapper.BlockHistoryMapper; +import com.tinyengine.it.mapper.ComponentLibraryMapper; import com.tinyengine.it.mapper.DatasourceMapper; import com.tinyengine.it.mapper.I18nEntryMapper; import com.tinyengine.it.mapper.MaterialHistoryMapper; @@ -32,6 +33,7 @@ import com.tinyengine.it.model.dto.I18nEntryDto; import com.tinyengine.it.model.dto.MaterialHistoryMsg; import com.tinyengine.it.model.dto.MetaDto; +import com.tinyengine.it.model.dto.PackagesDto; import com.tinyengine.it.model.dto.SchemaDto; import com.tinyengine.it.model.dto.SchemaI18n; import com.tinyengine.it.model.dto.SchemaMeta; @@ -41,6 +43,7 @@ import com.tinyengine.it.model.entity.BlockGroup; import com.tinyengine.it.model.entity.BlockHistory; import com.tinyengine.it.model.entity.Component; +import com.tinyengine.it.model.entity.ComponentLibrary; import com.tinyengine.it.model.entity.Datasource; import com.tinyengine.it.model.entity.MaterialHistory; import com.tinyengine.it.model.entity.Page; @@ -52,6 +55,7 @@ import cn.hutool.core.bean.BeanUtil; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -133,6 +137,9 @@ public class AppV1ServiceImpl implements AppV1Service { @Autowired private PlatformService platformService; + @Autowired + private ComponentLibraryMapper componentLibraryMapper; + /** * 获取应用schema * @@ -163,6 +170,9 @@ public SchemaDto appSchema(Integer id) { List> componentsMap = getSchemaComponentsMap(metaDto); schema.setComponentsMap(componentsMap); + List packages = getPackages(); + schema.setPackages(packages); + // 单独处理混合了bridge和utils的extensions Map> extensions = getSchemaExtensions(metaDto.getExtension()); schema.setUtils(extensions.get("utils")); @@ -237,6 +247,24 @@ private SchemaMeta getSchemaMeta(MetaDto metaDto) { return BeanUtil.mapToBean(meta, SchemaMeta.class, true); } + /** + * 获取组件库信息 + * + * @return List the List + */ + private List getPackages(){ + List componentLibraryList = componentLibraryMapper.queryAllComponentLibrary(); + List packagesDtoList = new ArrayList<>(); + if(componentLibraryList.isEmpty()){ + return packagesDtoList; + } + for (ComponentLibrary componentLibrary: componentLibraryList){ + PackagesDto pakagesDto = new PackagesDto(); + BeanUtils.copyProperties(componentLibrary, pakagesDto); + packagesDtoList.add(pakagesDto); + } + return packagesDtoList; + } /** * 获取应用信息 * @@ -468,6 +496,13 @@ public List> getSchemaComponentsMap(MetaDto metaDto) { List> blocksSchema = getBlockSchema(blockHistories); // 转换组件数据为schema List components = materialHistory.getComponents(); + List componentLibraryList = componentLibraryMapper.queryAllComponentLibrary(); + if(!componentLibraryList.isEmpty()){ + List componentList = componentLibraryList.stream() + .flatMap(componentLibrary -> componentLibrary.getComponents().stream()) // 扁平化每个 List + .collect(Collectors.toList()); // 收集到一个新的 List + components.addAll(componentList); + } List> componentsSchema = getComponentSchema(components); // 合并两个 List List> componentsMap = new ArrayList<>(componentsSchema); diff --git a/base/src/main/java/com/tinyengine/it/service/material/ComponentLibraryService.java b/base/src/main/java/com/tinyengine/it/service/material/ComponentLibraryService.java new file mode 100644 index 00000000..71f44294 --- /dev/null +++ b/base/src/main/java/com/tinyengine/it/service/material/ComponentLibraryService.java @@ -0,0 +1,74 @@ +/** + * 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.service.material; + +import com.tinyengine.it.common.base.Result; +import com.tinyengine.it.model.entity.ComponentLibrary; + +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * The interface ComponentLibrary service. + * + * @since 2025-4-02 + */ +public interface ComponentLibraryService { + /** + * 查询表t_component_library所有信息 + * + * @return the list + */ + List queryAllComponentLibrary(); + + /** + * 根据主键id查询表t_component_library信息 + * + * @param id the id + * @return the material + */ + Result queryComponentLibraryById(@Param("id") Integer id); + + /** + * 根据条件查询表t_component_library信息 + * + * @param componentLibrary the componentLibrary + * @return the list + */ + List queryComponentLibraryByCondition(ComponentLibrary componentLibrary); + + /** + * 根据主键id删除t_component_library数据 + * + * @param id the id + * @return the integer + */ + Result deleteComponentLibraryById(@Param("id") Integer id); + + /** + * 根据主键id更新表t_component_library信息 + * + * @param componentLibrary the componentLibrary + * @return the integer + */ + Result updateComponentLibraryById(ComponentLibrary componentLibrary); + + /** + * 新增表t_component_library数据 + * + * @param componentLibrary the componentLibrary + * @return the integer + */ + Result createComponentLibrary(ComponentLibrary componentLibrary); +} diff --git a/base/src/main/java/com/tinyengine/it/service/material/ComponentService.java b/base/src/main/java/com/tinyengine/it/service/material/ComponentService.java index eca1e38e..4033bb1c 100644 --- a/base/src/main/java/com/tinyengine/it/service/material/ComponentService.java +++ b/base/src/main/java/com/tinyengine/it/service/material/ComponentService.java @@ -13,6 +13,8 @@ package com.tinyengine.it.service.material; import com.tinyengine.it.common.base.Result; +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; @@ -81,4 +83,22 @@ public interface ComponentService { * @return result the result */ Result readFileAndBulkCreate(MultipartFile file); + + /** + * 拆分bundle.json为component集合 + * + * @param file the file + * @return result the result + */ + Result bundleSplit(MultipartFile file); + + /** + * 批量创建component + * + * @param custComponentDto the custComponentDto + * @return result the result + */ + Result custComponentBatchCreate(CustComponentDto custComponentDto); + + } diff --git a/base/src/main/java/com/tinyengine/it/service/material/MaterialHistoryService.java b/base/src/main/java/com/tinyengine/it/service/material/MaterialHistoryService.java index 105234f4..54a508c6 100644 --- a/base/src/main/java/com/tinyengine/it/service/material/MaterialHistoryService.java +++ b/base/src/main/java/com/tinyengine/it/service/material/MaterialHistoryService.java @@ -12,6 +12,7 @@ package com.tinyengine.it.service.material; +import com.tinyengine.it.common.base.Result; import com.tinyengine.it.model.entity.MaterialHistory; import org.apache.ibatis.annotations.Param; @@ -37,7 +38,7 @@ public interface MaterialHistoryService { * @param id the id * @return the material history */ - MaterialHistory findMaterialHistoryById(@Param("id") Integer id); + Result findMaterialHistoryById(@Param("id") Integer id); /** * 根据条件查询表t_material_history信息 @@ -53,7 +54,7 @@ public interface MaterialHistoryService { * @param id the id * @return the integer */ - Integer deleteMaterialHistoryById(@Param("id") Integer id); + Result deleteMaterialHistoryById(@Param("id") Integer id); /** * 根据主键id更新表t_material_history信息 @@ -61,7 +62,7 @@ public interface MaterialHistoryService { * @param materialHistory the material history * @return the integer */ - Integer updateMaterialHistoryById(MaterialHistory materialHistory); + Result updateMaterialHistoryById(MaterialHistory materialHistory); /** * 新增表t_material_history数据 @@ -69,5 +70,5 @@ public interface MaterialHistoryService { * @param materialHistory the material history * @return the integer */ - Integer createMaterialHistory(MaterialHistory materialHistory); + Result createMaterialHistory(MaterialHistory materialHistory); } diff --git a/base/src/main/java/com/tinyengine/it/service/material/MaterialService.java b/base/src/main/java/com/tinyengine/it/service/material/MaterialService.java index 3374b648..14b53a1f 100644 --- a/base/src/main/java/com/tinyengine/it/service/material/MaterialService.java +++ b/base/src/main/java/com/tinyengine/it/service/material/MaterialService.java @@ -12,8 +12,10 @@ package com.tinyengine.it.service.material; +import com.tinyengine.it.common.base.Result; import com.tinyengine.it.model.entity.Material; +import com.tinyengine.it.model.entity.MaterialHistory; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -37,7 +39,7 @@ public interface MaterialService { * @param id the id * @return the material */ - Material queryMaterialById(@Param("id") Integer id); + Result queryMaterialById(@Param("id") Integer id); /** * 根据条件查询表t_material信息 @@ -53,7 +55,7 @@ public interface MaterialService { * @param id the id * @return the integer */ - Integer deleteMaterialById(@Param("id") Integer id); + Result deleteMaterialById(@Param("id") Integer id); /** * 根据主键id更新表t_material信息 @@ -61,7 +63,7 @@ public interface MaterialService { * @param material the material * @return the integer */ - Integer updateMaterialById(Material material); + Result updateMaterialById(Material material); /** * 新增表t_material数据 @@ -69,5 +71,5 @@ public interface MaterialService { * @param material the material * @return the integer */ - Integer createMaterial(Material material); + Result createMaterial(Material material); } diff --git a/base/src/main/java/com/tinyengine/it/service/material/impl/ComponentLibraryServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/material/impl/ComponentLibraryServiceImpl.java new file mode 100644 index 00000000..c63f967f --- /dev/null +++ b/base/src/main/java/com/tinyengine/it/service/material/impl/ComponentLibraryServiceImpl.java @@ -0,0 +1,124 @@ +/** + * 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.service.material.impl; + +import com.tinyengine.it.common.base.Result; +import com.tinyengine.it.common.exception.ExceptionEnum; +import com.tinyengine.it.mapper.ComponentLibraryMapper; +import com.tinyengine.it.model.entity.ComponentLibrary; +import com.tinyengine.it.service.material.ComponentLibraryService; + +import lombok.extern.slf4j.Slf4j; + +import org.apache.ibatis.annotations.Param; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * The type ComponentLibrary service. + * + * @since 2025-04-02 + */ +@Service +@Slf4j +public class ComponentLibraryServiceImpl implements ComponentLibraryService { + @Autowired + private ComponentLibraryMapper componentLibraryMapper; + + /** + * 查询表t_component_library所有数据 + * + * @return ComponentLibrary + */ + @Override + public List queryAllComponentLibrary() { + return componentLibraryMapper.queryAllComponentLibrary(); + } + + /** + * 根据主键id查询表t_component_library信息 + * + * @param id id + * @return query result + */ + @Override + public Result queryComponentLibraryById(@Param("id") Integer id) { + ComponentLibrary material = componentLibraryMapper.queryComponentLibraryById(id); + return Result.success(material); + } + + /** + * 根据条件查询表t_component_library数据 + * + * @param componentLibrary componentLibrary + * @return query result + */ + @Override + public List queryComponentLibraryByCondition(ComponentLibrary componentLibrary) { + return componentLibraryMapper.queryComponentLibraryByCondition(componentLibrary); + } + + /** + * 根据主键id删除表t_component_library数据 + * + * @param id id + * @return execute success data number + */ + @Override + public Result deleteComponentLibraryById(@Param("id") Integer id) { + Result result = this.queryComponentLibraryById(id); + if(result.getData() == null || result.getData().getId() == null){ + return Result.success(); + } + int deleteResult = componentLibraryMapper.deleteComponentLibraryById(id); + if(deleteResult != 1){ + return Result.failed(ExceptionEnum.CM008); + } + return result; + + } + + /** + * 根据主键id更新表t_component_library数据 + * + * @param componentLibrary componentLibrary + * @return execute success data number + */ + @Override + public Result updateComponentLibraryById(ComponentLibrary componentLibrary) { + int updateResult = componentLibraryMapper.updateComponentLibraryById(componentLibrary); + if(updateResult != 1){ + return Result.failed(ExceptionEnum.CM008); + } + Result result = this.queryComponentLibraryById(componentLibrary.getId()); + return result; + } + + /** + * 新增表t_component_library数据 + * + * @param componentLibrary componentLibrary + * @return execute success data number + */ + @Override + public Result createComponentLibrary(ComponentLibrary componentLibrary) { + int createResult = componentLibraryMapper.createComponentLibrary(componentLibrary); + if(createResult != 1){ + return Result.failed(ExceptionEnum.CM008); + } + Result result = this.queryComponentLibraryById(componentLibrary.getId()); + return result; + } +} diff --git a/base/src/main/java/com/tinyengine/it/service/material/impl/ComponentServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/material/impl/ComponentServiceImpl.java index 53f51bc0..b7ec01db 100644 --- a/base/src/main/java/com/tinyengine/it/service/material/impl/ComponentServiceImpl.java +++ b/base/src/main/java/com/tinyengine/it/service/material/impl/ComponentServiceImpl.java @@ -14,14 +14,19 @@ import com.tinyengine.it.common.base.Result; import com.tinyengine.it.common.exception.ExceptionEnum; +import com.tinyengine.it.common.log.SystemServiceLog; import com.tinyengine.it.common.utils.Utils; +import com.tinyengine.it.mapper.ComponentLibraryMapper; import com.tinyengine.it.mapper.ComponentMapper; import com.tinyengine.it.model.dto.BundleDto; +import com.tinyengine.it.model.dto.BundleResultDto; import com.tinyengine.it.model.dto.Child; +import com.tinyengine.it.model.dto.CustComponentDto; import com.tinyengine.it.model.dto.FileResult; import com.tinyengine.it.model.dto.JsonFile; import com.tinyengine.it.model.dto.Snippet; import com.tinyengine.it.model.entity.Component; +import com.tinyengine.it.model.entity.ComponentLibrary; import com.tinyengine.it.model.entity.MaterialComponent; import com.tinyengine.it.model.entity.MaterialHistoryComponent; import com.tinyengine.it.service.material.ComponentService; @@ -48,9 +53,19 @@ @Service @Slf4j public class ComponentServiceImpl implements ComponentService { + /** + * The component mapper. + */ @Autowired private ComponentMapper componentMapper; + /** + * The component library mapper. + */ + @Autowired + private ComponentLibraryMapper componentLibraryMapper; + + /** * 查询表t_component所有数据 * @@ -122,8 +137,48 @@ public Integer createComponent(Component component) { * @param file the file * @return result the result */ + @SystemServiceLog(description = "readFileAndBulkCreate 创建组件库及组件实现方法") @Override public Result readFileAndBulkCreate(MultipartFile file) { + List componentList = this.bundleSplit(file).getData().getComponentList(); + List packageList = this.bundleSplit(file).getData().getPackageList(); + if (null == packageList || packageList.isEmpty()) { + return bulkCreate(componentList); + } + for (ComponentLibrary componentLibrary : packageList) { + componentLibrary.setIsDefault(true); + componentLibrary.setIsStarted(true); + ComponentLibrary library = new ComponentLibrary(); + library.setName(componentLibrary.getName()); + library.setVersion(componentLibrary.getVersion()); + // 查询是否存在组件库 + List componentLibraryList = componentLibraryMapper.queryComponentLibraryByCondition(library); + int result = 0; + if (!componentLibraryList.isEmpty()) { + componentLibrary.setId(componentLibraryList.get(0).getId()); + result = componentLibraryMapper.updateComponentLibraryById(componentLibrary); + if (result != 1) { + return Result.failed(ExceptionEnum.CM008); + } + continue; + } + result = componentLibraryMapper.createComponentLibrary(componentLibrary); + if (result != 1) { + return Result.failed(ExceptionEnum.CM008); + } + } + return bulkCreate(componentList); + } + + /** + * 拆分bundle.json + * + * @param file the file + * @return result the result + */ + @Override + @SystemServiceLog(description = "bundleSplit 拆分bundle.json实现方法") + public Result bundleSplit(MultipartFile file) { // 获取bundle.json数据 Result result = Utils.parseJsonFileStream(file); if (!result.isSuccess()) { @@ -156,6 +211,10 @@ public Result readFileAndBulkCreate(MultipartFile file) { component.setFramework(bundleDto.getFramework()); component.setPublicStatus(1); component.setIsTinyReserved(false); + Object schemaObject = comp.get("schema"); + if (schemaObject instanceof Map) { + component.setSchemaFragment((Map) schemaObject); + } if (snippets == null || snippets.isEmpty()) { componentList.add(component); continue; @@ -176,11 +235,65 @@ public Result readFileAndBulkCreate(MultipartFile file) { } componentList.add(component); } + List> packages = bundleDto.getMaterials().getPackages(); - return bulkCreate(componentList); + BundleResultDto bundleList = new BundleResultDto(); + bundleList.setComponentList(componentList); + if (null == packages || packages.isEmpty()) { + return Result.success(bundleList); + } + List packageList = new ArrayList<>(); + for (Map library : packages) { + ComponentLibrary componentLibrary = BeanUtil.mapToBean(library, ComponentLibrary.class, true); + componentLibrary.setPackageName(String.valueOf(library.get("package"))); + componentLibrary.setFramework("Vue"); + packageList.add(componentLibrary); + } + bundleList.setPackageList(packageList); + return Result.success(bundleList); } - private Result bulkCreate(List componentList) { + /** + * 批量创建component + * + * @param custComponentDto the custComponentDto + * @return result the result + */ + @Override + @SystemServiceLog(description = "custComponentBatchCreate 批量新增自定义组件实现方法") + public Result custComponentBatchCreate(CustComponentDto custComponentDto) { + int addNum = 0; + int updateNum = 0; + List componentList = custComponentDto.getComponents(); + if (componentList.isEmpty()) { + return Result.failed(ExceptionEnum.CM002); + } + Integer id = custComponentDto.getComponentLibraryId(); + if (null == id) { + return Result.failed(ExceptionEnum.CM002); + } + for (Component component : componentList) { + component.setLibraryId(id); + // 插入新记录 + createComponent(component); + } + addNum = addNum + 1; + + // 构造返回插入和更新的条数 + FileResult fileResult = new FileResult(); + fileResult.setInsertNum(addNum); + fileResult.setUpdateNum(updateNum); + return Result.success(fileResult); + } + + /** + * 批量创建组件 + * + * @param componentList the componentList + * @return result the result + */ + @SystemServiceLog(description = "bulkCreate 批量创建组件实现方法") + public Result bulkCreate(List componentList) { int addNum = 0; int updateNum = 0; for (Component component : componentList) { @@ -189,9 +302,28 @@ private Result bulkCreate(List componentList) { Component componentParam = new Component(); componentParam.setComponent(component.getComponent()); componentParam.setName(component.getName()); + componentParam.setVersion(component.getVersion()); List queryComponent = findComponentByCondition(componentParam); + // 查询组件库id + String packageName = null; + if(null!= component.getNpm() && null != component.getNpm().get("package")){ + packageName = String.valueOf(component.getNpm().get("package")); + } + if(null != packageName && !packageName.isEmpty()){ + ComponentLibrary componentLibrary = new ComponentLibrary(); + componentLibrary.setPackageName(String.valueOf(component.getNpm().get("package"))); + componentLibrary.setVersion(component.getVersion()); + List componentLibraryList = componentLibraryMapper + .queryComponentLibraryByCondition(componentLibrary); + Integer componentLibraryId = null; + if (!componentLibraryList.isEmpty()) { + componentLibraryId = componentLibraryList.get(0).getId(); + } + component.setLibraryId(componentLibraryId); + } if (queryComponent.isEmpty()) { + // 插入新记录 Integer result = createComponent(component); if (result == 1) { diff --git a/base/src/main/java/com/tinyengine/it/service/material/impl/MaterialHistoryServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/material/impl/MaterialHistoryServiceImpl.java index 9365ed28..ee56dedb 100644 --- a/base/src/main/java/com/tinyengine/it/service/material/impl/MaterialHistoryServiceImpl.java +++ b/base/src/main/java/com/tinyengine/it/service/material/impl/MaterialHistoryServiceImpl.java @@ -12,6 +12,8 @@ package com.tinyengine.it.service.material.impl; +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.mapper.MaterialHistoryMapper; import com.tinyengine.it.model.entity.MaterialHistory; @@ -33,6 +35,9 @@ @Service @Slf4j public class MaterialHistoryServiceImpl implements MaterialHistoryService { + /** + * The material history mapper. + */ @Autowired private MaterialHistoryMapper materialHistoryMapper; @@ -53,8 +58,9 @@ public List findAllMaterialHistory() { * @return query result */ @Override - public MaterialHistory findMaterialHistoryById(@Param("id") Integer id) { - return materialHistoryMapper.queryMaterialHistoryById(id); + public Result findMaterialHistoryById(@Param("id") Integer id) { + MaterialHistory materialHistory = materialHistoryMapper.queryMaterialHistoryById(id); + return Result.success(materialHistory); } /** @@ -77,8 +83,13 @@ public List findMaterialHistoryByCondition(MaterialHistory mate * @return execute success data number */ @Override - public Integer deleteMaterialHistoryById(@Param("id") Integer id) { - return materialHistoryMapper.deleteMaterialHistoryById(id); + public Result deleteMaterialHistoryById(@Param("id") Integer id) { + Result result = this.findMaterialHistoryById(id); + int deleteResult = materialHistoryMapper.deleteMaterialHistoryById(id); + if (deleteResult != 1) { + return Result.failed(ExceptionEnum.CM008); + } + return result; } /** @@ -88,8 +99,13 @@ public Integer deleteMaterialHistoryById(@Param("id") Integer id) { * @return execute success data number */ @Override - public Integer updateMaterialHistoryById(MaterialHistory materialHistory) { - return materialHistoryMapper.updateMaterialHistoryById(materialHistory); + public Result updateMaterialHistoryById(MaterialHistory materialHistory) { + int updateResult = materialHistoryMapper.updateMaterialHistoryById(materialHistory); + if (updateResult != 1) { + return Result.failed(ExceptionEnum.CM008); + } + Result result = this.findMaterialHistoryById(materialHistory.getId()); + return result; } /** @@ -99,7 +115,12 @@ public Integer updateMaterialHistoryById(MaterialHistory materialHistory) { * @return execute success data number */ @Override - public Integer createMaterialHistory(MaterialHistory materialHistory) { - return materialHistoryMapper.createMaterialHistory(materialHistory); + public Result createMaterialHistory(MaterialHistory materialHistory) { + int createResult = materialHistoryMapper.createMaterialHistory(materialHistory); + if (createResult != 1) { + return Result.failed(ExceptionEnum.CM008); + } + Result result = this.findMaterialHistoryById(materialHistory.getId()); + return result; } } diff --git a/base/src/main/java/com/tinyengine/it/service/material/impl/MaterialServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/material/impl/MaterialServiceImpl.java index 3acb2e67..4e3ab51c 100644 --- a/base/src/main/java/com/tinyengine/it/service/material/impl/MaterialServiceImpl.java +++ b/base/src/main/java/com/tinyengine/it/service/material/impl/MaterialServiceImpl.java @@ -12,6 +12,8 @@ package com.tinyengine.it.service.material.impl; +import com.tinyengine.it.common.base.Result; +import com.tinyengine.it.common.exception.ExceptionEnum; import com.tinyengine.it.mapper.MaterialMapper; import com.tinyengine.it.model.entity.Material; import com.tinyengine.it.service.material.MaterialService; @@ -52,8 +54,9 @@ public List queryAllMaterial() { * @return query result */ @Override - public Material queryMaterialById(@Param("id") Integer id) { - return materialMapper.queryMaterialById(id); + public Result queryMaterialById(@Param("id") Integer id) { + Material material = materialMapper.queryMaterialById(id); + return Result.success(material); } /** @@ -74,8 +77,14 @@ public List queryMaterialByCondition(Material material) { * @return execute success data number */ @Override - public Integer deleteMaterialById(@Param("id") Integer id) { - return materialMapper.deleteMaterialById(id); + public Result deleteMaterialById(@Param("id") Integer id) { + int deleteResult = materialMapper.deleteMaterialById(id); + if(deleteResult != 1){ + return Result.failed(ExceptionEnum.CM008); + } + Result result = this.queryMaterialById(id); + return result; + } /** @@ -85,8 +94,13 @@ public Integer deleteMaterialById(@Param("id") Integer id) { * @return execute success data number */ @Override - public Integer updateMaterialById(Material material) { - return materialMapper.updateMaterialById(material); + public Result updateMaterialById(Material material) { + int updateResult = materialMapper.updateMaterialById(material); + if(updateResult != 1){ + return Result.failed(ExceptionEnum.CM008); + } + Result result = this.queryMaterialById(material.getId()); + return result; } /** @@ -96,7 +110,12 @@ public Integer updateMaterialById(Material material) { * @return execute success data number */ @Override - public Integer createMaterial(Material material) { - return materialMapper.createMaterial(material); + public Result createMaterial(Material material) { + int createResult = materialMapper.createMaterial(material); + if(createResult != 1){ + return Result.failed(ExceptionEnum.CM008); + } + Result result = this.queryMaterialById(material.getId()); + return result; } } diff --git a/base/src/main/resources/mappers/ComponentLibraryMapper.xml b/base/src/main/resources/mappers/ComponentLibraryMapper.xml new file mode 100644 index 00000000..f6574ddf --- /dev/null +++ b/base/src/main/resources/mappers/ComponentLibraryMapper.xml @@ -0,0 +1,423 @@ + + + + + + + + + id + , version, `name`, package, registry, framework, description, script, css, bundle, dependencies, `others`, thumbnail, `public`, is_started, is_official, is_default, created_by, last_updated_by, created_time, last_updated_time, + tenant_id, renter_id, site_id + + + + + + AND version = #{version} + + + AND `name` = #{name} + + + AND package = #{packageName} + + + AND registry = #{registry} + + + AND description = #{description} + + + AND framework = #{framework} + + + AND script = #{script} + + + AND css = #{css} + + + AND bundle = #{bundle} + + + AND `others` = #{others} + + + AND thumbnail = #{thumbnail} + + + AND `public` = #{publicStatus} + + + AND is_started = #{isStarted} + + + AND is_official = #{isOfficial} + + + AND is_default = #{isDefault} + + + AND created_by = #{createdBy} + + + AND last_updated_by = #{lastUpdatedBy} + + + AND created_time = #{createdTime} + + + AND last_updated_time = #{lastUpdatedTime} + + + AND tenant_id = #{tenantId} + + + AND renter_id = #{renterId} + + + AND site_id = #{siteId} + + + + + + + version = #{version}, + + + `name` = #{name}, + + + `package` = #{packageName}, + + + registry = #{registry}, + + + description = #{description}, + + + framework = #{framework}, + + + script = #{script}, + + + css = #{css}, + + + bundle = #{bundle}, + + + `others` = #{others}, + + + thumbnail = #{thumbnail}, + + + `public` = #{publicStatus}, + + + is_started = #{isStarted}, + + + is_official = #{isOfficial}, + + + is_default = #{isDefault}, + + + created_by = #{createdBy}, + + + last_updated_by = #{lastUpdatedBy}, + + + created_time = #{createdTime}, + + + last_updated_time = #{lastUpdatedTime}, + + + tenant_id = #{tenantId}, + + + renter_id = #{renterId}, + + + site_id = #{siteId}, + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + DELETE + FROM t_component_library + WHERE id = #{id} + + + + + UPDATE t_component_library + + + + WHERE id=#{id} + + + + + INSERT INTO t_component_library ( id + , version + , `name` + , package + , registry + , framework + , description + , script + , css + , bundle + , dependencies + , `others` + , thumbnail + , `public` + , is_started + , is_official + , is_default + , created_by + , last_updated_by + , created_time + , last_updated_time + , tenant_id + , renter_id + , site_id) + VALUES ( #{id} + , #{version} + , #{name} + , #{packageName} + , #{registry} + , #{framework} + , #{description} + , #{script} + , #{css} + , #{bundle} + , #{dependencies} + , #{others} + , #{thumbnail} + , #{publicStatus} + , #{isStarted} + , #{isOfficial} + , #{isDefault} + , #{createdBy} + , #{lastUpdatedBy} + , #{createdTime} + , #{lastUpdatedTime} + , #{tenantId} + , #{renterId} + , #{siteId}) + + diff --git a/base/src/main/resources/mappers/MaterialHistoryMapper.xml b/base/src/main/resources/mappers/MaterialHistoryMapper.xml index 889dab52..94720a4b 100644 --- a/base/src/main/resources/mappers/MaterialHistoryMapper.xml +++ b/base/src/main/resources/mappers/MaterialHistoryMapper.xml @@ -210,47 +210,47 @@ INSERT INTO t_material_history ( id - , ref_id - , version - , content - , name - , npm_name - , framework - , assets_url - , image_url - , build_info - , description - , material_size - , tgz_url - , unzip_tgz_root_path_url - , unzip_tgz_files - , created_by - , last_updated_by - , created_time - , last_updated_time - , tenant_id, renter_id - , site_id) + , ref_id + , version + , content + , name + , npm_name + , framework + , assets_url + , image_url + , build_info + , description + , material_size + , tgz_url + , unzip_tgz_root_path_url + , unzip_tgz_files + , created_by + , last_updated_by + , created_time + , last_updated_time + , tenant_id, renter_id + , site_id) VALUES ( #{id} - , #{refId} - , #{version} - , #{content} - , #{name} - , #{npmName} - , #{framework} - , #{assetsUrl} - , #{imageUrl} - , #{buildInfo} - , #{description} - , #{materialSize} - , #{tgzUrl} - , #{unzipTgzRootPathUrl} - , #{unzipTgzFiles} - , #{createdBy} - , #{lastUpdatedBy} - , #{createdTime} - , #{lastUpdatedTime} - , #{tenantId} - , #{renterId} - , #{siteId}) + , #{refId} + , #{version} + , #{content} + , #{name} + , #{npmName} + , #{framework} + , #{assetsUrl} + , #{imageUrl} + , #{buildInfo} + , #{description} + , #{materialSize} + , #{tgzUrl} + , #{unzipTgzRootPathUrl} + , #{unzipTgzFiles} + , #{createdBy} + , #{lastUpdatedBy} + , #{createdTime} + , #{lastUpdatedTime} + , #{tenantId} + , #{renterId} + , #{siteId}) diff --git a/base/src/test/java/com/tinyengine/it/common/handler/MyMetaObjectHandlerTest.java b/base/src/test/java/com/tinyengine/it/common/handler/MyMetaObjectHandlerTest.java index a713172c..d6b219e5 100644 --- a/base/src/test/java/com/tinyengine/it/common/handler/MyMetaObjectHandlerTest.java +++ b/base/src/test/java/com/tinyengine/it/common/handler/MyMetaObjectHandlerTest.java @@ -36,7 +36,7 @@ void testInsertFill() throws NoSuchFieldException, IllegalAccessException { when(param.hasSetter("tenantId")).thenReturn(true); TestUtil.setPrivateValue(myMetaObjectHandler, "loginUserContext", new MockUserContext()); myMetaObjectHandler.insertFill(param); - verify(param, times(6)).hasSetter(anyString()); + verify(param, times(8)).hasSetter(anyString()); } @Test diff --git a/base/src/test/java/com/tinyengine/it/service/app/impl/CanvasServiceImplTest.java b/base/src/test/java/com/tinyengine/it/service/app/impl/CanvasServiceImplTest.java index 59ece02d..c341592c 100644 --- a/base/src/test/java/com/tinyengine/it/service/app/impl/CanvasServiceImplTest.java +++ b/base/src/test/java/com/tinyengine/it/service/app/impl/CanvasServiceImplTest.java @@ -19,6 +19,7 @@ import static org.mockito.Mockito.when; import com.tinyengine.it.common.base.Result; +import com.tinyengine.it.common.context.LoginUserContext; import com.tinyengine.it.mapper.BlockMapper; import com.tinyengine.it.mapper.PageMapper; import com.tinyengine.it.mapper.UserMapper; @@ -46,6 +47,8 @@ class CanvasServiceImplTest { private BlockMapper blockMapper; @Mock private UserMapper userMapper; + @Mock + private LoginUserContext loginUserContext; @InjectMocks private CanvasServiceImpl canvasServiceImpl; @@ -67,7 +70,7 @@ void testLockCanvasTypePage() { User user = new User(); user.setId(userId); when(userMapper.queryUserById(1)).thenReturn(user); - + when(loginUserContext.getLoginUserId()).thenReturn("1"); Result result = canvasServiceImpl.lockCanvas(pageId, "occupy", "page"); verify(pageMapper, times(1)).updatePageById(any()); @@ -86,6 +89,7 @@ void testLockCanvasTypeIsNotPage() { User user = new User(); user.setId(userId); when(userMapper.queryUserById(1)).thenReturn(user); + when(loginUserContext.getLoginUserId()).thenReturn("1"); Result result = canvasServiceImpl.lockCanvas(pageId, "occupy", "other"); diff --git a/base/src/test/java/com/tinyengine/it/service/app/impl/v1/AppV1ServiceImplTest.java b/base/src/test/java/com/tinyengine/it/service/app/impl/v1/AppV1ServiceImplTest.java index 3351f0ba..cf4e50a9 100644 --- a/base/src/test/java/com/tinyengine/it/service/app/impl/v1/AppV1ServiceImplTest.java +++ b/base/src/test/java/com/tinyengine/it/service/app/impl/v1/AppV1ServiceImplTest.java @@ -23,6 +23,7 @@ import com.tinyengine.it.mapper.AppMapper; import com.tinyengine.it.mapper.BlockGroupMapper; import com.tinyengine.it.mapper.BlockHistoryMapper; +import com.tinyengine.it.mapper.ComponentLibraryMapper; import com.tinyengine.it.mapper.DatasourceMapper; import com.tinyengine.it.mapper.I18nEntryMapper; import com.tinyengine.it.mapper.MaterialHistoryMapper; @@ -39,6 +40,7 @@ import com.tinyengine.it.model.entity.AppExtension; import com.tinyengine.it.model.entity.BlockGroup; import com.tinyengine.it.model.entity.BlockHistory; +import com.tinyengine.it.model.entity.ComponentLibrary; import com.tinyengine.it.model.entity.Datasource; import com.tinyengine.it.model.entity.MaterialHistory; import com.tinyengine.it.model.entity.Page; @@ -53,6 +55,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import java.awt.*; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -94,7 +97,8 @@ class AppV1ServiceImplTest { @Mock private PlatformService platformService; - + @Mock + private ComponentLibraryMapper componentLibraryMapper; @InjectMocks private AppV1ServiceImpl appV1ServiceImpl; @@ -136,7 +140,8 @@ void testAppSchema() throws JsonProcessingException { platform.setMaterialHistoryId(3); when(platformService.queryPlatformById(any())).thenReturn(platform); - + List componentLibraryList = new ArrayList<>(); + when(componentLibraryMapper.queryAllComponentLibrary()).thenReturn(componentLibraryList); SchemaDto result = appV1ServiceImpl.appSchema(appId); Assertions.assertEquals("2", result.getMeta().getAppId()); } @@ -200,6 +205,8 @@ void testGetSchemaComponentsMap() { MaterialHistory materialHistory = new MaterialHistory(); materialHistory.setComponents(new ArrayList<>()); metaDto.setMaterialHistory(materialHistory); + List componentLibraryList = new ArrayList<>(); + when(componentLibraryMapper.queryAllComponentLibrary()).thenReturn(componentLibraryList); List> result = appV1ServiceImpl.getSchemaComponentsMap(metaDto); Assertions.assertEquals("v1", result.get(0).get("version")); } diff --git a/base/src/test/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImplTest.java b/base/src/test/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImplTest.java index 00592696..c98cf1e8 100644 --- a/base/src/test/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImplTest.java +++ b/base/src/test/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImplTest.java @@ -20,6 +20,7 @@ import com.tinyengine.it.mapper.BlockGroupBlockMapper; import com.tinyengine.it.mapper.BlockGroupMapper; import com.tinyengine.it.model.dto.BlockGroupDto; +import com.tinyengine.it.model.entity.Block; import com.tinyengine.it.model.entity.BlockGroup; import org.junit.jupiter.api.Assertions; @@ -107,8 +108,13 @@ void testUpdateBlockGroupById() { @Test void testCreateBlockGroup() { BlockGroup param = new BlockGroup(); + Block block = new Block(); + block.setId(1); + List blockList = new ArrayList<>(); + blockList.add(block); when(blockGroupMapper.createBlockGroup(param)).thenReturn(1); when(loginUserContext.getLoginUserId()).thenReturn("1"); + when(blockGroupMapper.queryBlockGroupAndBlockById(1, null, loginUserContext.getLoginUserId())).thenReturn(param); BlockGroup blockGroupParam = new BlockGroup(); blockGroupParam.setId(1); Result result = blockGroupServiceImpl.createBlockGroup(blockGroupParam); diff --git a/base/src/test/java/com/tinyengine/it/service/material/impl/ComponentServiceImplTest.java b/base/src/test/java/com/tinyengine/it/service/material/impl/ComponentServiceImplTest.java index 3d2db841..1834486d 100644 --- a/base/src/test/java/com/tinyengine/it/service/material/impl/ComponentServiceImplTest.java +++ b/base/src/test/java/com/tinyengine/it/service/material/impl/ComponentServiceImplTest.java @@ -18,11 +18,13 @@ import com.tinyengine.it.common.base.Result; import com.tinyengine.it.common.utils.Utils; +import com.tinyengine.it.mapper.ComponentLibraryMapper; import com.tinyengine.it.mapper.ComponentMapper; import com.tinyengine.it.model.dto.BundleMaterial; import com.tinyengine.it.model.dto.FileResult; import com.tinyengine.it.model.dto.JsonFile; import com.tinyengine.it.model.entity.Component; +import com.tinyengine.it.model.entity.ComponentLibrary; import com.tinyengine.it.model.entity.MaterialComponent; import com.tinyengine.it.model.entity.MaterialHistoryComponent; @@ -50,6 +52,8 @@ class ComponentServiceImplTest { @Mock private ComponentMapper componentMapper; + @Mock + private ComponentLibraryMapper componentLibraryMapper; @InjectMocks private ComponentServiceImpl componentServiceImpl; @@ -124,7 +128,11 @@ void testReadFileAndBulkCreate() { when(componentMapper.createMaterialComponent(any(MaterialComponent.class))).thenReturn(Integer.valueOf(0)); when(componentMapper.createMaterialHistoryComponent(any(MaterialHistoryComponent.class))) .thenReturn(Integer.valueOf(0)); - + ComponentLibrary componentLibrary = new ComponentLibrary(); + componentLibrary.setId(1); + List componentLibraryList = new ArrayList<>(); + componentLibraryList.add(componentLibrary); + when(componentLibraryMapper.queryComponentLibraryByCondition(componentLibrary)).thenReturn(componentLibraryList); MultipartFile file = mock(MultipartFile.class); HashMap fileContent = new HashMap<>(); BundleMaterial bundleMaterial = new BundleMaterial(); @@ -134,6 +142,7 @@ void testReadFileAndBulkCreate() { components.add(componentdata); bundleMaterial.setComponents(components); bundleMaterial.setSnippets(new ArrayList<>()); + bundleMaterial.setPackages(new ArrayList<>()); HashMap material = new HashMap<>(); material.put("framework", "Vue"); material.put("materials", bundleMaterial); diff --git a/base/src/test/java/com/tinyengine/it/service/material/impl/MaterialHistoryServiceImplTest.java b/base/src/test/java/com/tinyengine/it/service/material/impl/MaterialHistoryServiceImplTest.java index 715d0305..442ff2e4 100644 --- a/base/src/test/java/com/tinyengine/it/service/material/impl/MaterialHistoryServiceImplTest.java +++ b/base/src/test/java/com/tinyengine/it/service/material/impl/MaterialHistoryServiceImplTest.java @@ -1,19 +1,19 @@ /** * 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.service.material.impl; import static org.mockito.Mockito.when; +import com.tinyengine.it.common.base.Result; import com.tinyengine.it.mapper.MaterialHistoryMapper; import com.tinyengine.it.model.entity.MaterialHistory; @@ -55,10 +55,11 @@ void testFindAllMaterialHistory() { @Test void testFindMaterialHistoryById() { MaterialHistory mockData = new MaterialHistory(); + mockData.setId(1); when(materialHistoryMapper.queryMaterialHistoryById(1)).thenReturn(mockData); - MaterialHistory result = materialHistoryServiceImpl.findMaterialHistoryById(1); - Assertions.assertEquals(mockData, result); + Result result = materialHistoryServiceImpl.findMaterialHistoryById(1); + Assertions.assertEquals(mockData, result.getData()); } @Test @@ -73,27 +74,34 @@ void testFindMaterialHistoryByCondition() { @Test void testDeleteMaterialHistoryById() { - when(materialHistoryMapper.deleteMaterialHistoryById(1)).thenReturn(123); + MaterialHistory param = new MaterialHistory(); + param.setId(1); + when(materialHistoryMapper.deleteMaterialHistoryById(1)).thenReturn(1); + when(materialHistoryMapper.queryMaterialHistoryById(1)).thenReturn(param); - Integer result = materialHistoryServiceImpl.deleteMaterialHistoryById(1); - Assertions.assertEquals(123, result); + Result result = materialHistoryServiceImpl.deleteMaterialHistoryById(1); + Assertions.assertEquals(Result.success(param), result); } @Test void testUpdateMaterialHistoryById() { MaterialHistory param = new MaterialHistory(); - when(materialHistoryMapper.updateMaterialHistoryById(param)).thenReturn(123); + param.setId(1); + when(materialHistoryMapper.updateMaterialHistoryById(param)).thenReturn(1); + when(materialHistoryMapper.queryMaterialHistoryById(1)).thenReturn(param); - Integer result = materialHistoryServiceImpl.updateMaterialHistoryById(param); - Assertions.assertEquals(123, result); + Result result = materialHistoryServiceImpl.updateMaterialHistoryById(param); + Assertions.assertEquals(Result.success(param), result); } @Test void testCreateMaterialHistory() { MaterialHistory param = new MaterialHistory(); - when(materialHistoryMapper.createMaterialHistory(param)).thenReturn(123); + param.setId(1); + when(materialHistoryMapper.createMaterialHistory(param)).thenReturn(1); + when(materialHistoryMapper.queryMaterialHistoryById(1)).thenReturn(param); - Integer result = materialHistoryServiceImpl.createMaterialHistory(param); - Assertions.assertEquals(123, result); + Result result = materialHistoryServiceImpl.createMaterialHistory(param); + Assertions.assertEquals(result, Result.success(param)); } } diff --git a/base/src/test/java/com/tinyengine/it/service/material/impl/MaterialServiceImplTest.java b/base/src/test/java/com/tinyengine/it/service/material/impl/MaterialServiceImplTest.java index 3c50e8d6..2790414e 100644 --- a/base/src/test/java/com/tinyengine/it/service/material/impl/MaterialServiceImplTest.java +++ b/base/src/test/java/com/tinyengine/it/service/material/impl/MaterialServiceImplTest.java @@ -1,22 +1,23 @@ /** * 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.service.material.impl; import static org.mockito.Mockito.when; +import com.tinyengine.it.common.base.Result; import com.tinyengine.it.mapper.MaterialMapper; import com.tinyengine.it.model.entity.Material; +import com.tinyengine.it.model.entity.MaterialHistory; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -55,10 +56,11 @@ void testQueryAllMaterial() { @Test void testQueryMaterialById() { Material mockData = new Material(); + mockData.setId(1); when(materialMapper.queryMaterialById(1)).thenReturn(mockData); - Material result = materialServiceImpl.queryMaterialById(1); - Assertions.assertEquals(mockData, result); + Result result = materialServiceImpl.queryMaterialById(1); + Assertions.assertEquals(Result.success(mockData), result); } @Test @@ -73,27 +75,34 @@ void testQueryMaterialByCondition() { @Test void testDeleteMaterialById() { - when(materialMapper.deleteMaterialById(1)).thenReturn(2); + when(materialMapper.deleteMaterialById(1)).thenReturn(1); + Material mockData = new Material(); + mockData.setId(1); + when(materialMapper.queryMaterialById(1)).thenReturn(mockData); - Integer result = materialServiceImpl.deleteMaterialById(1); - Assertions.assertEquals(2, result); + Result result = materialServiceImpl.deleteMaterialById(1); + Assertions.assertEquals(Result.success(mockData), result); } @Test void testUpdateMaterialById() { Material param = new Material(); + param.setId(1); when(materialMapper.updateMaterialById(param)).thenReturn(1); + when(materialMapper.queryMaterialById(1)).thenReturn(param); - Integer result = materialServiceImpl.updateMaterialById(param); - Assertions.assertEquals(1, result); + Result result = materialServiceImpl.updateMaterialById(param); + Assertions.assertEquals(Result.success(param), result); } @Test void testCreateMaterial() { Material param = new Material(); + param.setId(1); when(materialMapper.createMaterial(param)).thenReturn(1); + when(materialMapper.queryMaterialById(1)).thenReturn(param); - Integer result = materialServiceImpl.createMaterial(param); - Assertions.assertEquals(1, result); + Result result = materialServiceImpl.createMaterial(param); + Assertions.assertEquals(Result.success(param), result); } }