diff --git a/app/src/main/resources/sql/h2/create_all_tables_ddl_v1.h2.sql b/app/src/main/resources/sql/h2/create_all_tables_ddl_v1.h2.sql index dbd8f3aa..07ce9bd1 100644 --- a/app/src/main/resources/sql/h2/create_all_tables_ddl_v1.h2.sql +++ b/app/src/main/resources/sql/h2/create_all_tables_ddl_v1.h2.sql @@ -41,11 +41,11 @@ create table `t_platform_history` `ref_id` int not null comment '关联主表id', `version` varchar(255) not null comment '版本', `name` varchar(255) not null comment '名称', - `publish_url` varchar(255) not null comment '设计器静态资源托管地址', + `publish_url` varchar(255) comment '设计器静态资源托管地址', `description` varchar(2000) comment '描述', `vscode_url` varchar(255) comment '设计预留字段', `material_history_id` int not null comment '关联物料包历史id', - `sub_count` int not null comment '设计预留字段', + `sub_count` int comment '设计预留字段', `material_pkg_name` varchar(255) comment '物料包名称', `material_version` varchar(255) comment '物料包版本', `image_url` varchar(255) comment '封面图地址', diff --git a/app/src/main/resources/sql/h2/update_all_tables_ddl.sql b/app/src/main/resources/sql/h2/update_all_tables_ddl.sql index d6f9c5d1..1e59d2a8 100644 --- a/app/src/main/resources/sql/h2/update_all_tables_ddl.sql +++ b/app/src/main/resources/sql/h2/update_all_tables_ddl.sql @@ -1,2 +1,8 @@ ALTER TABLE t_component DROP INDEX u_idx_component; -ALTER TABLE t_component ADD INDEX u_idx_component (tenant_id, name_en, version, library_id); \ No newline at end of file +ALTER TABLE t_component ADD INDEX u_idx_component (tenant_id, name_en, version, library_id); + +ALTER TABLE t_datasource DROP INDEX u_idx_datasource; +ALTER TABLE t_datasource ADD INDEX u_idx_datasource (`tenant_id`, `platform_id`, `name`, `app_id`); + +ALTER TABLE t_platform_history MODIFY sub_count int NULL; +ALTER TABLE t_platform_history MODIFY publish_url varchar(255) NULL; \ No newline at end of file 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 a4cfa649..bccbab33 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 @@ -41,11 +41,11 @@ create table `t_platform_history` `ref_id` int not null comment '关联主表id', `version` varchar(255) not null comment '版本', `name` varchar(255) not null comment '名称', - `publish_url` varchar(255) not null comment '设计器静态资源托管地址', + `publish_url` varchar(255) comment '设计器静态资源托管地址', `description` varchar(2000) comment '描述', - `vscode_url` varchar(255) comment '设计预留字段', + `vscode_url` varchar(255) comment '设计预留字段', `material_history_id` int not null comment '关联物料包历史id', - `sub_count` int not null comment '设计预留字段', + `sub_count` int comment '设计预留字段', `material_pkg_name` varchar(255) comment '物料包名称', `material_version` varchar(255) comment '物料包版本', `image_url` varchar(255) comment '封面图地址', diff --git a/app/src/main/resources/sql/mysql/update_all_tables_ddl.sql b/app/src/main/resources/sql/mysql/update_all_tables_ddl.sql index d6f9c5d1..1e59d2a8 100644 --- a/app/src/main/resources/sql/mysql/update_all_tables_ddl.sql +++ b/app/src/main/resources/sql/mysql/update_all_tables_ddl.sql @@ -1,2 +1,8 @@ ALTER TABLE t_component DROP INDEX u_idx_component; -ALTER TABLE t_component ADD INDEX u_idx_component (tenant_id, name_en, version, library_id); \ No newline at end of file +ALTER TABLE t_component ADD INDEX u_idx_component (tenant_id, name_en, version, library_id); + +ALTER TABLE t_datasource DROP INDEX u_idx_datasource; +ALTER TABLE t_datasource ADD INDEX u_idx_datasource (`tenant_id`, `platform_id`, `name`, `app_id`); + +ALTER TABLE t_platform_history MODIFY sub_count int NULL; +ALTER TABLE t_platform_history MODIFY publish_url varchar(255) NULL; \ No newline at end of file diff --git a/base/src/main/java/com/tinyengine/it/common/exception/ExceptionEnum.java b/base/src/main/java/com/tinyengine/it/common/exception/ExceptionEnum.java index 12a791a4..3e604e12 100644 --- a/base/src/main/java/com/tinyengine/it/common/exception/ExceptionEnum.java +++ b/base/src/main/java/com/tinyengine/it/common/exception/ExceptionEnum.java @@ -235,7 +235,22 @@ public enum ExceptionEnum implements IBaseError { /** * Cm 322 exception enum. */ - CM322("CM322", "调用接口失败"); + CM322("CM322", "调用接口失败"), + + /** + * Cm 323 exception enum. + */ + CM323("CM323", "文件名长度范围为1-100,以数字或字母开头"), + + /** + * Cm 324 exception enum. + */ + CM324("CM324","文件名或路径无效"), + + /** + * Cm 325 exception enum. + */ + CM325("CM325","文件校验失败"); /** * 错误码 diff --git a/base/src/main/java/com/tinyengine/it/common/utils/SecurityFileCheckUtil.java b/base/src/main/java/com/tinyengine/it/common/utils/SecurityFileCheckUtil.java new file mode 100644 index 00000000..444cb188 --- /dev/null +++ b/base/src/main/java/com/tinyengine/it/common/utils/SecurityFileCheckUtil.java @@ -0,0 +1,178 @@ +/** + * 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.common.utils; + +import cn.hutool.core.util.ObjectUtil; +import com.tinyengine.it.common.exception.ExceptionEnum; +import com.tinyengine.it.common.exception.ServiceException; +import org.springframework.util.StringUtils; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.util.Map; +import java.util.Objects; +import java.util.regex.Pattern; + +/** + * The file check Utils. + * + * @since 2025-05-13 + */ +public class SecurityFileCheckUtil { + + private static final String REGX_FILE_NAME = "^[a-z0-9A-Z][^\\\\/:*<>|]+$"; + private static final Pattern PATTERN_FILE_NAME = Pattern.compile(REGX_FILE_NAME); + + /** + * Determine whether the file has cross path connections. + * + * @param dirOrFileName the dirOrFileName + * @return true or false + */ + public static boolean checkPathHasCrossDir(String dirOrFileName) { + if (!dirOrFileName.contains("../") && !dirOrFileName.contains("/..")) { + if (!dirOrFileName.contains("..\\") && !dirOrFileName.contains("\\..")) { + return dirOrFileName.contains("./") || dirOrFileName.contains(".\\.\\") || dirOrFileName.contains("%00"); + } else { + return true; + } + } else { + return true; + } + } + + /** + * Type of inspection document. + * + * @param file the file + * @param fileTypeMap the fileTypeMap + * @return true or false + */ + public static boolean checkFileType(MultipartFile file, Map fileTypeMap) { + if (Objects.isNull(file) || fileTypeMap.isEmpty()) { + throw new ServiceException(ExceptionEnum.CM307.getResultCode(), ExceptionEnum.CM307.getResultMsg()); + } + String originalFileName = file.getOriginalFilename(); + for (Map.Entry entry : fileTypeMap.entrySet()) { + if (originalFileName.endsWith(entry.getKey())) { + return checkFileType(file, entry.getKey(), entry.getValue()); + } + } + return false; + } + + /** + * Type of inspection document. + * + * @param file the file + * @param fileNameEnd the fileNameEnd + * @param fileType the fileType + * @return true or false + */ + public static boolean checkFileType(MultipartFile file, String fileNameEnd, String fileType) { + String originalFileName = file.getOriginalFilename(); + String contentType = file.getContentType(); + if (ObjectUtil.isEmpty(originalFileName) || ObjectUtil.isEmpty(contentType)) { + return false; + } + if (!originalFileName.endsWith(fileNameEnd)) { + return false; + } + if (!contentType.equalsIgnoreCase(fileType)) { + return false; + } + return true; + } + + /** + * Inspection file name. + * + * @param fileName the fileName + */ + public static void validFileName(String fileName) { + if (!StringUtils.hasText(fileName)) { + throw new ServiceException(ExceptionEnum.CM320.getResultCode(), ExceptionEnum.CM320.getResultMsg()); + } + if (!checkFileNameLength(fileName, 1, 100)) { + throw new ServiceException(ExceptionEnum.CM323.getResultCode(), ExceptionEnum.CM323.getResultMsg()); + } + if (!filePathIsValid(fileName)) { + throw new ServiceException(ExceptionEnum.CM324.getResultCode(), ExceptionEnum.CM324.getResultMsg()); + } + String fullFileName = getFileName(fileName); + if (!PATTERN_FILE_NAME.matcher(fullFileName).matches()) { + throw new ServiceException(ExceptionEnum.CM324.getResultCode(), ExceptionEnum.CM324.getResultMsg()); + } + } + + /** + * Check if the file name length is within the specified range. + * + * @param fileName the fileName + * @param min the min + * @param max the max + * @return true or false + */ + public static boolean checkFileNameLength(String fileName, int min, int max) { + if (!StringUtils.hasText(fileName)) { + return min <= 0; + } + String temp = fileName.replaceAll("[^\\x00-\\xff]", "**"); + return temp.length() <= max; + } + + /** + * Verify file path. + * + * @param fileName the fileName + * @return true or false + */ + public static boolean filePathIsValid(String fileName) { + if (fileName == null || fileName.trim().isEmpty()) { + return false; + } + + // 获取当前操作系统的名称 + String os = System.getProperty("os.name").toLowerCase(); + + // 定义通用的非法字符 + String illegalChars = ""; + + if (os.contains("win")) { + // 针对Windows的非法字符 + illegalChars = "[<>:\"/\\|?*]"; + } else if (os.contains("nix") || os.contains("nux") || os.contains("mac")) { + // 针对Linux和macOS的非法字符(一般来说,Linux和macOS对文件名的限制较少,但有一些常见的非法字符) + illegalChars = "[/]"; // Linux和macOS的路径不能包含斜杠 '/' + } + // 检查路径中是否包含非法字符 + if (fileName.matches(".*" + illegalChars + ".*")) { + return false; + } + // 检查路径是否超过文件系统允许的最大长度(例如,Windows上的路径限制通常为260个字符) + if (fileName.length() > 260) { + return false; + } + + // 检查路径中是否包含空格或其他特殊字符,视需要进行定制 + // 如果需要你也可以根据不同操作系统做不同的检查 + + return true; + } + + private static String getFileName(String filePath) { + File file = new File(filePath); + return file.getName(); + } + + +} 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 390d5be2..5408fa3f 100644 --- a/base/src/main/java/com/tinyengine/it/controller/ComponentController.java +++ b/base/src/main/java/com/tinyengine/it/controller/ComponentController.java @@ -15,6 +15,7 @@ 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.common.utils.SecurityFileCheckUtil; import com.tinyengine.it.model.dto.BundleResultDto; import com.tinyengine.it.model.dto.CustComponentDto; import com.tinyengine.it.model.dto.FileResult; @@ -71,6 +72,7 @@ public Result bundleCreateComponent(@RequestParam MultipartFile file if (file.isEmpty()) { return Result.failed(ExceptionEnum.CM307); } + SecurityFileCheckUtil.validFileName(file.getOriginalFilename()); // 返回插入和更新的条数 return componentService.readFileAndBulkCreate(file); } @@ -92,6 +94,7 @@ public Result bundleSplit(@RequestParam MultipartFile file) { if (file.isEmpty()) { return Result.failed(ExceptionEnum.CM307); } + SecurityFileCheckUtil.validFileName(file.getOriginalFilename()); return componentService.bundleSplit(file); } diff --git a/base/src/main/java/com/tinyengine/it/controller/I18nEntryController.java b/base/src/main/java/com/tinyengine/it/controller/I18nEntryController.java index 87987848..2375ee98 100644 --- a/base/src/main/java/com/tinyengine/it/controller/I18nEntryController.java +++ b/base/src/main/java/com/tinyengine/it/controller/I18nEntryController.java @@ -16,6 +16,7 @@ import com.tinyengine.it.common.exception.ExceptionEnum; import com.tinyengine.it.common.exception.ServiceException; import com.tinyengine.it.common.log.SystemControllerLog; +import com.tinyengine.it.common.utils.SecurityFileCheckUtil; import com.tinyengine.it.model.dto.DeleteI18nEntry; import com.tinyengine.it.model.dto.FileResult; import com.tinyengine.it.model.dto.I18nEntryDto; @@ -234,10 +235,10 @@ public Result updateI18nSingleFile( for (Map.Entry entry : filesMap.entrySet()) { // 获取对应的文件 MultipartFile file = entry.getValue(); - if (file.isEmpty()) { return Result.failed(ExceptionEnum.CM307); } + SecurityFileCheckUtil.validFileName(file.getOriginalFilename()); // 返回插入和更新的条数 result = i18nEntryService.readSingleFileAndBulkCreate(file, id); } @@ -274,10 +275,10 @@ public Result updateI18nMultiFile( for (Map.Entry entry : filesMap.entrySet()) { String key = entry.getKey(); // 获取动态的参数名 MultipartFile file = entry.getValue(); // 获取对应的文件 - if (file.isEmpty()) { return Result.failed(ExceptionEnum.CM307); } + SecurityFileCheckUtil.validFileName(file.getOriginalFilename()); // 返回插入和更新的条数 result = i18nEntryService.readFilesAndbulkCreate(key, file, id); } diff --git a/base/src/main/java/com/tinyengine/it/controller/PlatformController.java b/base/src/main/java/com/tinyengine/it/controller/PlatformController.java new file mode 100644 index 00000000..4fe4dd6d --- /dev/null +++ b/base/src/main/java/com/tinyengine/it/controller/PlatformController.java @@ -0,0 +1,180 @@ +/** + * 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.Platform; +import com.tinyengine.it.service.platform.PlatformService; +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 2024-10-20 + */ +@Validated +@RestController +@RequestMapping("/platform-center/api") +@Tag(name = "设计器") +public class PlatformController { + /** + * The Platform service. + */ + @Autowired + private PlatformService platformService; + + /** + * 查询表Platform信息 + * + * @return Platform信息 all app + */ + @Operation(summary = "查询表Platform信息", + description = "查询表Platform信息", + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Platform.class))), + @ApiResponse(responseCode = "400", description = "请求失败")}) + @SystemControllerLog(description = "查询表Platform信息") + @GetMapping("/platform/list") + public Result> getAllPlatform() { + List appList = platformService.queryAllPlatform(); + return Result.success(appList); + } + + /** + * 根据id查询表Platform信息 + * + * @param id the id + * @return Platform信息 app by id + */ + @Operation(summary = "根据id查询表Platform信息", + description = "根据id查询表Platform信息", + parameters = { + @Parameter(name = "id", description = "Platform主键id") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Platform.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "根据id查询表Platform信息") + @GetMapping("/platform/{id}") + public Result getPlatformById(@PathVariable Integer id) { + Platform platform = platformService.queryPlatformById(id); + return Result.success(platform); + } + + /** + * 创建Platform + * + * @param platform the platform + * @return Platform信息 result + */ + @Operation(summary = "创建platform", + description = "创建platform", + parameters = { + @Parameter(name = "platform", description = "Platform入参对象") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Platform.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "创建platform") + @PostMapping("/platform/create") + public Result createPlatform(@Valid @RequestBody Platform platform) { + return platformService.createPlatform(platform); + } + + /** + * 修改Platform信息 + * + * @param id the id + * @param platform the platform + * @return Platform信息 result + */ + @Operation(summary = "修改单个Platform信息", description = "修改单个Platform信息", parameters = { + @Parameter(name = "id", description = "appId"), + @Parameter(name = "Platform", description = "入参对象")}, responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Platform.class))), + @ApiResponse(responseCode = "400", description = "请求失败")}) + @SystemControllerLog(description = "修改单个Platform信息") + @PostMapping("/platform/update/{id}") + public Result updatePlatform(@PathVariable Integer id, @RequestBody Platform platform) { + platform.setId(id); + return platformService.updatePlatformById(platform); + } + + /** + * 删除Platform信息 + * + * @param id the id + * @return platform信息 result + */ + @Operation(summary = "删除platform信息,与js同路由", + description = "删除platform信息,与js同路由", + parameters = { + @Parameter(name = "id", description = "Platform主键id") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Platform.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "删除platform信息,与js同路由") + @GetMapping("/platform/delete/{id}") + public Result delete(@PathVariable Integer id) { + return platformService.deletePlatformById(id); + } + + @Operation(summary = "删除platform信息", + description = "删除platform信息", + parameters = { + @Parameter(name = "id", description = "Platform主键id") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Platform.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "删除platform信息") + @DeleteMapping("/platform/delete/{id}") + public Result deletePlatform(@PathVariable Integer id) { + return platformService.deletePlatformById(id); + } +} diff --git a/base/src/main/java/com/tinyengine/it/controller/PlatformHistoryController.java b/base/src/main/java/com/tinyengine/it/controller/PlatformHistoryController.java new file mode 100644 index 00000000..96808480 --- /dev/null +++ b/base/src/main/java/com/tinyengine/it/controller/PlatformHistoryController.java @@ -0,0 +1,164 @@ +/** + * 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.PlatformHistory; +import com.tinyengine.it.service.platform.PlatformHistoryService; +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.PutMapping; +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 2024-10-20 + */ +@Validated +@RestController +@RequestMapping("/platform-center/api") +@Tag(name = "设计器历史") +public class PlatformHistoryController { + /** + * The PlatformHistory service. + */ + @Autowired + private PlatformHistoryService platformHistoryService; + + /** + * 查询表PlatformHistory信息 + * + * @return PlatformHistory信息 all app + */ + @Operation(summary = "查询表PlatformHistory信息", + description = "查询表PlatformHistory信息", + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = PlatformHistory.class))), + @ApiResponse(responseCode = "400", description = "请求失败")}) + @SystemControllerLog(description = "查询表PlatformHistory信息") + @GetMapping("/platform-history/list") + public Result> getAllPlatformHistory() { + List appList = platformHistoryService.queryAllPlatformHistory(); + return Result.success(appList); + } + + /** + * 根据id查询表PlatformHistory信息 + * + * @param id the id + * @return PlatformHistory信息 app by id + */ + @Operation(summary = "根据id查询表PlatformHistory信息", + description = "根据id查询表PlatformHistory信息", + parameters = { + @Parameter(name = "id", description = "PlatformHistory主键id") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = PlatformHistory.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "根据id查询表PlatformHistory信息") + @GetMapping("/platform-history/{id}") + public Result getPlatformHistoryById(@PathVariable Integer id) { + PlatformHistory platformHistory = platformHistoryService.queryPlatformHistoryById(id); + return Result.success(platformHistory); + } + + /** + * 创建PlatformHistory + * + * @param platformHistory the platformHistory + * @return PlatformHistory信息 result + */ + @Operation(summary = "创建platformHistory", + description = "创建platformHistory", + parameters = { + @Parameter(name = "platformHistory", description = "PlatformHistory入参对象") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = PlatformHistory.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "创建platformHistory") + @PostMapping("/platform-history/create") + public Result createPlatformHistory(@Valid @RequestBody PlatformHistory platformHistory) { + return platformHistoryService.createPlatformHistory(platformHistory); + } + + /** + * 修改PlatformHistory信息 + * + * @param id the id + * @param platformHistory the platformHistory + * @return PlatformHistory信息 result + */ + @Operation(summary = "修改单个PlatformHistory信息", description = "修改单个PlatformHistory信息", parameters = { + @Parameter(name = "id", description = "appId"), + @Parameter(name = "PlatformHistory", description = "入参对象")}, responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = PlatformHistory.class))), + @ApiResponse(responseCode = "400", description = "请求失败")}) + @SystemControllerLog(description = "修改单个PlatformHistory信息") + @PutMapping("/platform-history/update/{id}") + public Result updatePlatformHistory(@PathVariable Integer id, @RequestBody PlatformHistory platformHistory) { + platformHistory.setId(id); + return platformHistoryService.updatePlatformHistoryById(platformHistory); + } + + /** + * 删除PlatformHistory信息 + * + * @param id the id + * @return platformHistory信息 result + */ + @Operation(summary = "删除platformHistory信息", + description = "删除platformHistory信息", + parameters = { + @Parameter(name = "id", description = "PlatformHistory主键id") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = PlatformHistory.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "删除platformHistory信息") + @DeleteMapping("/platform-history/delete/{id}") + public Result deletePlatformHistory(@PathVariable Integer id) { + return platformHistoryService.deletePlatformHistoryById(id); + } +} diff --git a/base/src/main/java/com/tinyengine/it/mapper/PlatformHistoryMapper.java b/base/src/main/java/com/tinyengine/it/mapper/PlatformHistoryMapper.java new file mode 100644 index 00000000..837d95e7 --- /dev/null +++ b/base/src/main/java/com/tinyengine/it/mapper/PlatformHistoryMapper.java @@ -0,0 +1,75 @@ +/** + * 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.Platform; + +import com.tinyengine.it.model.entity.PlatformHistory; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * The interface Platform history mapper. + * + * @since 2025-05-09 + */ +public interface PlatformHistoryMapper extends BaseMapper { + /** + * 查询表t_platform_history所有信息 + * + * @return the list + */ + List queryAllPlatformHistory(); + + /** + * 根据主键id查询表t_platform_history数据 + * + * @param id the id + * @return the platform + */ + PlatformHistory queryPlatformHistoryById(Integer id); + + /** + * 根据条件查询表t_platform_history数据 + * + * @param platformHistory the platformHistory + * @return the list + */ + List queryPlatformHistoryByCondition(PlatformHistory platformHistory); + + /** + * 根据主键id删除表t_platform_history数据 + * + * @param id the id + * @return the integer + */ + Integer deletePlatformHistoryById(@Param("id") Integer id); + + /** + * 根据主键id更新表t_platform_history数据 + * + * @param platformHistory the platformHistory + * @return the integer + */ + Integer updatePlatformHistoryById(PlatformHistory platformHistory); + + /** + * 新增表t_platform_history数据 + * + * @param platformHistory the platformHistory + * @return the integer + */ + Integer createPlatformHistory(PlatformHistory platformHistory); +} diff --git a/base/src/main/java/com/tinyengine/it/model/entity/Platform.java b/base/src/main/java/com/tinyengine/it/model/entity/Platform.java index 39444d0d..acae4205 100644 --- a/base/src/main/java/com/tinyengine/it/model/entity/Platform.java +++ b/base/src/main/java/com/tinyengine/it/model/entity/Platform.java @@ -14,6 +14,7 @@ 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.ListTypeHandler; import com.tinyengine.it.common.handler.MapTypeHandler; @@ -42,6 +43,7 @@ public class Platform extends BaseEntity { private String name; @Schema(name = "published", description = "是否发布:1是,0否") + @JsonProperty("published") private Boolean isPublish; @Schema(name = "lastBuildInfo", description = "最后构建信息") diff --git a/base/src/main/java/com/tinyengine/it/model/entity/PlatformHistory.java b/base/src/main/java/com/tinyengine/it/model/entity/PlatformHistory.java new file mode 100644 index 00000000..1bfeab23 --- /dev/null +++ b/base/src/main/java/com/tinyengine/it/model/entity/PlatformHistory.java @@ -0,0 +1,64 @@ +/** + * 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.TableName; +import com.tinyengine.it.common.base.BaseEntity; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.Setter; + +/** + * + * 设计器历史表 + * + * @since 2025-05-09 + */ +@Getter +@Setter +@TableName("t_platform_history") +@Schema(name = "PlatformHistory", description = "设计器历史表") +public class PlatformHistory extends BaseEntity { + @Schema(name = "refId", description = "设计器id") + private Integer refId; + + @Schema(name = "name", description = "名称") + private String name; + + @Schema(name = "publishUrl", description = "设计器静态资源托管地址") + private String publishUrl; + + @Schema(name = "description", description = "描述") + private String description; + + @Schema(name = "version", description = "当前历史记录表版本") + private String version; + + @Schema(name = "subCount", description = "设计预留字段") + private Integer subCount; + + @Schema(name = "materialHistoryId", description = "关联物料包历史ID") + private Integer materialHistoryId; + + @Schema(name = "imageUrl", description = "设计器截图地址") + private String imageUrl; + + @Schema(name = "materialPkgName", description = "物料包名称") + private String materialPkgName; + + @Schema(name = "materialVersion", description = "物料包版本") + private String materialVersion; + + @Schema(name = "vscodeUrl", description = "*设计预留字段*") + private String vscodeUrl; +} 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 4e6680f1..6f4d32a9 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 @@ -15,6 +15,7 @@ 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.SecurityFileCheckUtil; import com.tinyengine.it.common.utils.Utils; import com.tinyengine.it.mapper.ComponentLibraryMapper; import com.tinyengine.it.mapper.ComponentMapper; @@ -140,8 +141,10 @@ public Integer createComponent(Component component) { @SystemServiceLog(description = "readFileAndBulkCreate 创建组件库及组件实现方法") @Override public Result readFileAndBulkCreate(MultipartFile file) { - List componentList = this.bundleSplit(file).getData().getComponentList(); - List packageList = this.bundleSplit(file).getData().getPackageList(); + Result bundleResultDtoResult = this.bundleSplit(file); + BundleResultDto data = bundleResultDtoResult.getData(); + List componentList = data.getComponentList(); + List packageList = data.getPackageList(); if (null == packageList || packageList.isEmpty()) { return bulkCreate(componentList); } @@ -180,6 +183,11 @@ public Result readFileAndBulkCreate(MultipartFile file) { @Override @SystemServiceLog(description = "bundleSplit 拆分bundle.json实现方法") public Result bundleSplit(MultipartFile file) { + // 检验文件 + boolean isFileCheck = this.checkFile(file); + if (!isFileCheck){ + return Result.failed(ExceptionEnum.CM325); + } // 获取bundle.json数据 Result result = Utils.parseJsonFileStream(file); if (!result.isSuccess()) { @@ -317,10 +325,10 @@ public Result bulkCreate(List componentList) { List queryComponent = findComponentByCondition(componentParam); // 查询组件库id String packageName = null; - if(null!= component.getNpm() && null != component.getNpm().get("package")){ + if (null != component.getNpm() && null != component.getNpm().get("package")) { packageName = String.valueOf(component.getNpm().get("package")); } - if(null != packageName && !packageName.isEmpty()){ + if (null != packageName && !packageName.isEmpty()) { ComponentLibrary componentLibrary = new ComponentLibrary(); componentLibrary.setPackageName(String.valueOf(component.getNpm().get("package"))); componentLibrary.setVersion(component.getVersion()); @@ -379,4 +387,14 @@ private String toPascalCase(String input) { } return result.toString(); } + + public boolean checkFile(MultipartFile file) { + Map fileTypeMap = new HashMap<>(); + fileTypeMap.put(".json", "application/json"); + boolean isCheckFileType = SecurityFileCheckUtil.checkFileType(file, fileTypeMap); + if (!isCheckFileType) { + return false; + } + return true; + } } diff --git a/base/src/main/java/com/tinyengine/it/service/platform/PlatformHistoryService.java b/base/src/main/java/com/tinyengine/it/service/platform/PlatformHistoryService.java new file mode 100644 index 00000000..de5cc061 --- /dev/null +++ b/base/src/main/java/com/tinyengine/it/service/platform/PlatformHistoryService.java @@ -0,0 +1,73 @@ +/** + * 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.platform; + +import com.tinyengine.it.common.base.Result; +import com.tinyengine.it.model.entity.PlatformHistory; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * The interface platform history service. + * + * @since 2025-05-09 + */ +public interface PlatformHistoryService { + /** + * 查询表t_platform_history所有信息 + * + * @return the list + */ + List queryAllPlatformHistory(); + + /** + * 根据主键id查询表t_platform_history信息 + * + * @param id the id + * @return the platformHistory + */ + PlatformHistory queryPlatformHistoryById(@Param("id") Integer id); + + /** + * 根据条件查询表t_platform_history信息 + * + * @param platformHistory the platformHistory + * @return the list + */ + List queryPlatformHistoryByCondition(PlatformHistory platformHistory); + + /** + * 根据主键id删除t_platform_history数据 + * + * @param id the id + * @return the Result + */ + Result deletePlatformHistoryById(@Param("id") Integer id); + + /** + * 根据主键id更新表t_platform_history信息 + * + * @param platformHistory the platformHistory + * @return the Result + */ + Result updatePlatformHistoryById(PlatformHistory platformHistory); + + /** + * 新增表t_platform_history数据 + * + * @param platformHistory the platformHistory + * @return the Result + */ + Result createPlatformHistory(PlatformHistory platformHistory); +} diff --git a/base/src/main/java/com/tinyengine/it/service/platform/PlatformService.java b/base/src/main/java/com/tinyengine/it/service/platform/PlatformService.java index 8163d7ff..552b9e7a 100644 --- a/base/src/main/java/com/tinyengine/it/service/platform/PlatformService.java +++ b/base/src/main/java/com/tinyengine/it/service/platform/PlatformService.java @@ -12,6 +12,7 @@ package com.tinyengine.it.service.platform; +import com.tinyengine.it.common.base.Result; import com.tinyengine.it.model.entity.Platform; import org.apache.ibatis.annotations.Param; @@ -51,23 +52,23 @@ public interface PlatformService { * 根据主键id删除t_platform数据 * * @param id the id - * @return the integer + * @return the Result */ - Integer deletePlatformById(@Param("id") Integer id); + Result deletePlatformById(@Param("id") Integer id); /** * 根据主键id更新表t_platform信息 * * @param platform the platform - * @return the integer + * @return the Result */ - Integer updatePlatformById(Platform platform); + Result updatePlatformById(Platform platform); /** * 新增表t_platform数据 * * @param platform the platform - * @return the integer + * @return the Result */ - Integer createPlatform(Platform platform); + Result createPlatform(Platform platform); } diff --git a/base/src/main/java/com/tinyengine/it/service/platform/impl/PlatformHistoryServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/platform/impl/PlatformHistoryServiceImpl.java new file mode 100644 index 00000000..fd24b737 --- /dev/null +++ b/base/src/main/java/com/tinyengine/it/service/platform/impl/PlatformHistoryServiceImpl.java @@ -0,0 +1,136 @@ +/** + * Copyright (c) 2023 - present TinyEngine Authors. + * Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd. + * + * Use of this source code is governed by an MIT-style license. + * + * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, + * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR + * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS. + * + */ + +package com.tinyengine.it.service.platform.impl; + +import com.tinyengine.it.common.base.Result; +import com.tinyengine.it.common.exception.ExceptionEnum; +import com.tinyengine.it.mapper.PlatformHistoryMapper; +import com.tinyengine.it.model.entity.PlatformHistory; +import com.tinyengine.it.service.platform.PlatformHistoryService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * The interface platform history service. + * + * @since 2025-05-09 + */ +@Service +@Slf4j +public class PlatformHistoryServiceImpl implements PlatformHistoryService { + @Autowired + private PlatformHistoryMapper platformHistoryMapper; + + /** + * 查询表t_platform_history所有信息 + * + * @return the list + */ + @Override + public List queryAllPlatformHistory() { + return platformHistoryMapper.queryAllPlatformHistory(); + } + + /** + * 根据主键id查询表t_platform_history信息 + * + * @param id the id + * @return the platformHistory + */ + @Override + public PlatformHistory queryPlatformHistoryById(Integer id) { + return platformHistoryMapper.queryPlatformHistoryById(id); + } + + /** + * 根据条件查询表t_platform_history信息 + * + * @param platformHistory the platformHistory + * @return the list + */ + @Override + public List queryPlatformHistoryByCondition(PlatformHistory platformHistory) { + return platformHistoryMapper.queryPlatformHistoryByCondition(platformHistory); + } + + /** + * 根据主键id删除t_platform_history数据 + * + * @param id the id + * @return the Result + */ + @Override + public Result deletePlatformHistoryById(Integer id) { + PlatformHistory platformHistory = this.queryPlatformHistoryById(id); + if (platformHistory == null || platformHistory.getId() == null) { + return Result.success(); + } + int deleteResult = platformHistoryMapper.deletePlatformHistoryById(id); + if (deleteResult != 1) { + return Result.failed(ExceptionEnum.CM008); + } + return Result.success(platformHistory); + } + + /** + * 根据主键id更新表t_platform_history信息 + * + * @param platformHistory the platformHistory + * @return the Result + */ + @Override + public Result updatePlatformHistoryById(PlatformHistory platformHistory) { + if (platformHistory == null || platformHistory.getId() == null) { + return Result.failed(ExceptionEnum.CM002); + } + int updateResult = platformHistoryMapper.updatePlatformHistoryById(platformHistory); + if (updateResult != 1) { + return Result.failed(ExceptionEnum.CM008); + } + PlatformHistory platformHistoryResult = this.queryPlatformHistoryById(platformHistory.getId()); + return Result.success(platformHistoryResult); + } + + /** + * 新增表t_platform_history数据 + * + * @param platformHistory the platformHistory + * @return the Result + */ + @Override + public Result createPlatformHistory(PlatformHistory platformHistory) { + if (platformHistory == null) { + return Result.failed(ExceptionEnum.CM002); + } + if (platformHistory.getRefId() == null) { + return Result.failed(ExceptionEnum.CM002); + } + if (platformHistory.getName() == null || platformHistory.getName().isEmpty()) { + return Result.failed(ExceptionEnum.CM002); + } + if (platformHistory.getVersion() == null || platformHistory.getVersion().isEmpty()) { + return Result.failed(ExceptionEnum.CM002); + } + if (platformHistory.getMaterialHistoryId() == null) { + return Result.failed(ExceptionEnum.CM002); + } + int createResult = platformHistoryMapper.createPlatformHistory(platformHistory); + if (createResult != 1) { + return Result.failed(ExceptionEnum.CM008); + } + return Result.success(platformHistory); + } +} diff --git a/base/src/main/java/com/tinyengine/it/service/platform/impl/PlatformServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/platform/impl/PlatformServiceImpl.java index ee4d37d4..6046ee65 100644 --- a/base/src/main/java/com/tinyengine/it/service/platform/impl/PlatformServiceImpl.java +++ b/base/src/main/java/com/tinyengine/it/service/platform/impl/PlatformServiceImpl.java @@ -12,6 +12,8 @@ package com.tinyengine.it.service.platform.impl; +import com.tinyengine.it.common.base.Result; +import com.tinyengine.it.common.exception.ExceptionEnum; import com.tinyengine.it.mapper.PlatformMapper; import com.tinyengine.it.model.entity.Platform; import com.tinyengine.it.service.platform.PlatformService; @@ -71,32 +73,58 @@ public List queryPlatformByCondition(Platform platform) { * 根据主键id删除表t_platform数据 * * @param id id - * @return execute success data number + * @return Result */ @Override - public Integer deletePlatformById(@Param("id") Integer id) { - return platformMapper.deletePlatformById(id); + public Result deletePlatformById(@Param("id") Integer id) { + Platform platform = this.queryPlatformById(id); + if (platform == null || platform.getId() == null) { + return Result.success(); + } + int deleteResult = platformMapper.deletePlatformById(id); + if (deleteResult != 1) { + return Result.failed(ExceptionEnum.CM008); + } + return Result.success(platform); } /** * 根据主键id更新表t_platform数据 * * @param platform platform - * @return execute success data number + * @return Result */ @Override - public Integer updatePlatformById(Platform platform) { - return platformMapper.updatePlatformById(platform); + public Result updatePlatformById(Platform platform) { + if (platform == null || platform.getId() == null) { + return Result.failed(ExceptionEnum.CM002); + } + int updateResult = platformMapper.updatePlatformById(platform); + if (updateResult != 1) { + return Result.failed(ExceptionEnum.CM008); + } + Platform platformResult = platformMapper.queryPlatformById(platform.getId()); + return Result.success(platformResult); } /** * 新增表t_platform数据 * * @param platform platform - * @return execute success data number + * @return Result */ @Override - public Integer createPlatform(Platform platform) { - return platformMapper.createPlatform(platform); + public Result createPlatform(Platform platform) { + if (platform == null) { + return Result.failed(ExceptionEnum.CM002); + } + if (platform.getName() == null || platform.getName().isEmpty()) { + return Result.failed(ExceptionEnum.CM002); + } + int createResult = platformMapper.createPlatform(platform); + if (createResult != 1) { + return Result.failed(ExceptionEnum.CM008); + } + return Result.success(platform); } } diff --git a/base/src/main/resources/mappers/PlatformHistoryMapper.xml b/base/src/main/resources/mappers/PlatformHistoryMapper.xml new file mode 100644 index 00000000..cc4631c4 --- /dev/null +++ b/base/src/main/resources/mappers/PlatformHistoryMapper.xml @@ -0,0 +1,239 @@ + + + + + + + + + id, ref_id, name, version, publish_url, vscode_url, description, material_history_id, sub_count, material_pkg_name, + material_version, image_url, tenant_id, renter_id, site_id, created_by, last_updated_by, + created_time, last_updated_time + + + + + + AND ref_id = #{refId} + + + AND name = #{name} + + + AND publish_url = #{publishUrl} + + + AND version = #{version} + + + AND description = #{description} + + + AND vscode_url = #{vscodeUrl} + + + AND material_history_id = #{materialHistoryId} + + + AND image_url = #{imageUrl} + + + AND sub_count = #{subCount} + + + AND material_pkg_name = #{materialPkgName} + + + AND material_version = #{materialVersion} + + + AND tenant_id = #{tenantId} + + + AND renter_id = #{renterId} + + + AND site_id = #{siteId} + + + AND created_by = #{createdBy} + + + AND last_updated_by = #{lastUpdatedBy} + + + AND created_time = #{createdTime} + + + AND last_updated_time = #{lastUpdatedTime} + + + + + + + ref_id = #{refId}, + + + name = #{name}, + + + publish_url = #{publishUrl}, + + + version = #{version}, + + + description = #{description}, + + + vscode_url = #{vscodeUrl}, + + + material_history_id = #{materialHistoryId}, + + + image_url = #{imageUrl}, + + + sub_count = #{subCount}, + + + material_pkg_name = #{materialPkgName}, + + + material_version = #{materialVersion}, + + + tenant_id = #{tenantId}, + + + renter_id = #{renterId}, + + + site_id = #{siteId}, + + + created_by = #{createdBy}, + + + last_updated_by = #{lastUpdatedBy}, + + + created_time = #{createdTime}, + + + last_updated_time = #{lastUpdatedTime}, + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + DELETE + FROM t_platform_history + WHERE id = #{id} + + + + + UPDATE t_platform_history + + + + WHERE + id=#{id} + + + + + INSERT INTO t_platform_history ( id + , ref_id + , name + , version + , publish_url + , description + , sub_count + , material_history_id + , image_url + , material_pkg_name + , material_version + , vscode_url + , tenant_id + , renter_id + , site_id + , created_by + , last_updated_by + , created_time + , last_updated_time) + VALUES ( #{id} + , #{refId} + , #{name} + , #{version} + , #{publishUrl} + , #{description} + , #{subCount} + , #{materialHistoryId} + , #{imageUrl} + , #{materialPkgName} + , #{materialVersion} + , #{vscodeUrl} + , #{tenantId} + , #{renterId} + , #{siteId} + , #{createdBy} + , #{lastUpdatedBy} + , #{createdTime} + , #{lastUpdatedTime}) + + diff --git a/base/src/test/java/com/tinyengine/it/controller/I18nEntryControllerTest.java b/base/src/test/java/com/tinyengine/it/controller/I18nEntryControllerTest.java index 7e1e2777..3650b72f 100644 --- a/base/src/test/java/com/tinyengine/it/controller/I18nEntryControllerTest.java +++ b/base/src/test/java/com/tinyengine/it/controller/I18nEntryControllerTest.java @@ -131,6 +131,7 @@ void testUpdateI18nSingleFile() throws Exception { when(i18nEntryService.readSingleFileAndBulkCreate(any(MultipartFile.class), anyInt())) .thenReturn(mockData); MultipartFile file = Mockito.mock(MultipartFile.class); + when(file.getOriginalFilename()).thenReturn("example.json"); when(file.isEmpty()).thenReturn(false); HashMap filesMap = new HashMap() {{ put("filesMap", file); @@ -145,6 +146,7 @@ void testUpdateI18nMultiFile() throws Exception { when(i18nEntryService.readFilesAndbulkCreate(anyString(), any(MultipartFile.class), anyInt())) .thenReturn(new Result()); MultipartFile file = Mockito.mock(MultipartFile.class); + when(file.getOriginalFilename()).thenReturn("example.json"); when(file.isEmpty()).thenReturn(false); HashMap filesMap = new HashMap() {{ put("filesMap", file); diff --git a/base/src/test/java/com/tinyengine/it/service/app/impl/PageServiceImplTest.java b/base/src/test/java/com/tinyengine/it/service/app/impl/PageServiceImplTest.java index bc496654..286c60df 100644 --- a/base/src/test/java/com/tinyengine/it/service/app/impl/PageServiceImplTest.java +++ b/base/src/test/java/com/tinyengine/it/service/app/impl/PageServiceImplTest.java @@ -278,8 +278,7 @@ void testGetDepth() { when(pageMapper.queryPageById(1)).thenReturn(page); Result result = pageServiceImpl.getDepth("1"); - Assertions.assertFalse(result.isSuccess()); - assertEquals("Exceeded depth", result.getMessage()); + assertEquals(page.getDepth(), result.getData()); } @Test 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 1834486d..40954e5e 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 @@ -134,6 +134,8 @@ void testReadFileAndBulkCreate() { componentLibraryList.add(componentLibrary); when(componentLibraryMapper.queryComponentLibraryByCondition(componentLibrary)).thenReturn(componentLibraryList); MultipartFile file = mock(MultipartFile.class); + when(file.getOriginalFilename()).thenReturn("example.json"); + when(file.getContentType()).thenReturn("application/json"); HashMap fileContent = new HashMap<>(); BundleMaterial bundleMaterial = new BundleMaterial(); ArrayList> components = new ArrayList<>(); diff --git a/base/src/test/java/com/tinyengine/it/service/platform/impl/PlatformServiceImplTest.java b/base/src/test/java/com/tinyengine/it/service/platform/impl/PlatformServiceImplTest.java index 86990dee..9e9868fc 100644 --- a/base/src/test/java/com/tinyengine/it/service/platform/impl/PlatformServiceImplTest.java +++ b/base/src/test/java/com/tinyengine/it/service/platform/impl/PlatformServiceImplTest.java @@ -14,6 +14,7 @@ import static org.mockito.Mockito.when; +import com.tinyengine.it.common.base.Result; import com.tinyengine.it.mapper.PlatformMapper; import com.tinyengine.it.model.entity.Platform; @@ -73,27 +74,33 @@ void testQueryPlatformByCondition() { @Test void testDeletePlatformById() { - when(platformMapper.deletePlatformById(1)).thenReturn(2); + Platform mockData = new Platform(); + mockData.setId(1); + when(platformMapper.queryPlatformById(1)).thenReturn(mockData); + when(platformMapper.deletePlatformById(1)).thenReturn(1); - Integer result = platformServiceImpl.deletePlatformById(1); - Assertions.assertEquals(2, result); + Result result = platformServiceImpl.deletePlatformById(1); + Assertions.assertEquals(mockData, result.getData()); } @Test void testUpdatePlatformById() { Platform param = new Platform(); + param.setId(1); when(platformMapper.updatePlatformById(param)).thenReturn(1); - - Integer result = platformServiceImpl.updatePlatformById(param); - Assertions.assertEquals(1, result); + Platform mockData = new Platform(); + when(platformMapper.queryPlatformById(1)).thenReturn(mockData); + Result result = platformServiceImpl.updatePlatformById(param); + Assertions.assertEquals(mockData, result.getData()); } @Test void testCreatePlatform() { Platform param = new Platform(); + param.setName("testPlatform"); when(platformMapper.createPlatform(param)).thenReturn(1); - Integer result = platformServiceImpl.createPlatform(param); - Assertions.assertEquals(1, result); + Result result = platformServiceImpl.createPlatform(param); + Assertions.assertEquals(param, result.getData()); } } \ No newline at end of file