From b97583e91a0f31c3e4951ea2d4906cd326b0fca2 Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Thu, 26 Dec 2024 00:15:51 -0800 Subject: [PATCH 01/43] fix: update page history bug --- .../it/controller/BlockController.java | 18 ++++++++++-------- .../it/service/material/BlockService.java | 7 ++++--- .../material/impl/BlockServiceImpl.java | 10 ++++++---- .../resources/mappers/PageHistoryMapper.xml | 2 +- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/base/src/main/java/com/tinyengine/it/controller/BlockController.java b/base/src/main/java/com/tinyengine/it/controller/BlockController.java index 5f503d15..2a79c98d 100644 --- a/base/src/main/java/com/tinyengine/it/controller/BlockController.java +++ b/base/src/main/java/com/tinyengine/it/controller/BlockController.java @@ -399,24 +399,26 @@ public Result updateBlocks(@Valid @RequestBody BlockDto blockDto, @Pat } /** - * 根据label查询区块详情 + * 通过lable和appId查询区块 * - * @param label the label + * @param label label + * @param appId appId * @return the result */ - @Operation(summary = "根据label查询区块详情", - description = "根据label查询区块详情", + @Operation(summary = "根据lable和appId查询区块详情", + description = "根据lable和appId查询区块详情", responses = { @ApiResponse(responseCode = "200", description = "返回信息", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Block.class))), @ApiResponse(responseCode = "400", description = "请求失败")} ) - @SystemControllerLog(description = "获取所有用户api") + @SystemControllerLog(description = "根据lable和appId查询区块详情api") @GetMapping("/block/label") - public Result getBlockByLabel(@RequestParam(value = "label") - String label) { - return blockService.getBlockByLabel(label); + public Result getBlockByLabel( + @RequestParam(value = "label") String label, + @RequestParam(value = "appId") Integer appId) { + return blockService.getBlockByLabel(label, appId); } /** diff --git a/base/src/main/java/com/tinyengine/it/service/material/BlockService.java b/base/src/main/java/com/tinyengine/it/service/material/BlockService.java index 459e33e4..20e675bf 100644 --- a/base/src/main/java/com/tinyengine/it/service/material/BlockService.java +++ b/base/src/main/java/com/tinyengine/it/service/material/BlockService.java @@ -130,12 +130,13 @@ public interface BlockService { /** - * 通过lable查询区块 + * 通过label和appId查询区块 * - * @param lable lable + * @param label label + * @param appId appId * @return the BlockDto */ - Result getBlockByLabel(String lable); + Result getBlockByLabel(String label, Integer appId); /** * block发布 diff --git a/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java index 73c5df3f..36c1b2a0 100644 --- a/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java +++ b/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java @@ -405,15 +405,17 @@ public List getNotInGroupBlocks(Integer groupId) { } /** - * 通过lable查询区块 + * 通过label和appId查询区块 * - * @param lable lable + * @param label label + * @param appId appId * @return the BlockDto */ @Override - public Result getBlockByLabel(String lable) { + public Result getBlockByLabel(String label, Integer appId) { Block block = new Block(); - block.setLabel(lable); + block.setLabel(label); + block.setAppId(appId); List blockList = blockMapper.queryBlockByCondition(block); if (blockList.isEmpty()) { return Result.success(); diff --git a/base/src/main/resources/mappers/PageHistoryMapper.xml b/base/src/main/resources/mappers/PageHistoryMapper.xml index 164db6fe..bafe37b3 100644 --- a/base/src/main/resources/mappers/PageHistoryMapper.xml +++ b/base/src/main/resources/mappers/PageHistoryMapper.xml @@ -193,7 +193,7 @@ FROM t_page_history - AND ref_id = #{id} + AND id = #{id} From d30877c880df7e4bf6b040921850f237af20473b Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Mon, 6 Jan 2025 17:53:06 -0800 Subject: [PATCH 02/43] fix: format code and fix style issue --- .../com/tinyengine/it/service/app/impl/PageServiceImpl.java | 6 ------ base/src/main/resources/mappers/PageHistoryMapper.xml | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) 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 1adcc94b..db2431c8 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 @@ -20,7 +20,6 @@ import com.tinyengine.it.common.log.SystemServiceLog; import com.tinyengine.it.mapper.AppExtensionMapper; import com.tinyengine.it.mapper.AppMapper; -import com.tinyengine.it.mapper.BlockHistoryMapper; import com.tinyengine.it.mapper.BlockMapper; import com.tinyengine.it.mapper.I18nEntryMapper; import com.tinyengine.it.mapper.PageMapper; @@ -107,11 +106,6 @@ public class PageServiceImpl implements PageService { @Autowired private AppV1ServiceImpl appV1ServiceImpl; - /** - * The Block history mapper. - */ - @Autowired - private BlockHistoryMapper blockHistoryMapper; /** * The App extension mapper. diff --git a/base/src/main/resources/mappers/PageHistoryMapper.xml b/base/src/main/resources/mappers/PageHistoryMapper.xml index bafe37b3..164db6fe 100644 --- a/base/src/main/resources/mappers/PageHistoryMapper.xml +++ b/base/src/main/resources/mappers/PageHistoryMapper.xml @@ -193,7 +193,7 @@ FROM t_page_history - AND id = #{id} + AND ref_id = #{id} From 7fc6507af5333696f946f819f42505a0b1d366ed Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Mon, 6 Jan 2025 18:06:45 -0800 Subject: [PATCH 03/43] fix: modify page histiry entity --- .../it/model/entity/PageHistory.java | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/base/src/main/java/com/tinyengine/it/model/entity/PageHistory.java b/base/src/main/java/com/tinyengine/it/model/entity/PageHistory.java index 17fc59f2..903980b5 100644 --- a/base/src/main/java/com/tinyengine/it/model/entity/PageHistory.java +++ b/base/src/main/java/com/tinyengine/it/model/entity/PageHistory.java @@ -12,10 +12,13 @@ package com.tinyengine.it.model.entity; +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; -import com.tinyengine.it.common.base.HistoryEntity; import com.tinyengine.it.common.handler.ListTypeHandler; import com.tinyengine.it.common.handler.MapTypeHandler; import com.tinyengine.it.model.dto.BlockVersionDto; @@ -24,6 +27,7 @@ import lombok.Getter; import lombok.Setter; +import java.time.LocalDateTime; import java.util.List; import java.util.Map; @@ -39,7 +43,11 @@ @Setter @TableName("t_page_history") @Schema(name = "PageHistory", description = "页面历史") -public class PageHistory extends HistoryEntity { +public class PageHistory { + @Schema(name = "id", description = "主键id") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + @Schema(name = "name", description = "名称") private String name; @@ -89,4 +97,36 @@ public class PageHistory extends HistoryEntity { @Schema(name = "contentBlocks", description = "*设计预留字段*") @TableField(typeHandler = ListTypeHandler.class) private List contentBlocks; + + + @TableField(fill = FieldFill.INSERT) + @Schema(name = "createdBy", description = "创建人") + private String createdBy; + + @TableField(fill = FieldFill.INSERT_UPDATE) + @Schema(name = "lastUpdatedBy", description = "最后修改人") + private String lastUpdatedBy; + + @TableField(fill = FieldFill.INSERT) + @Schema(name = "created_at", description = "创建时间") + @JsonProperty("created_at") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime createdTime; + + @TableField(fill = FieldFill.INSERT_UPDATE) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonProperty("updated_at") + @Schema(name = "updated_at", description = "更新时间") + private LocalDateTime lastUpdatedTime; + + @TableField(fill = FieldFill.INSERT) + @Schema(name = "tenantId", description = "租户ID") + private String tenantId; + + @TableField(fill = FieldFill.INSERT) + @Schema(name = "renterId", description = "业务租户ID") + private String renterId; + + @Schema(name = "siteId", description = "站点ID") + private String siteId; } From 24474b89c1387a4271e524ce622e8ac7e73ed624 Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Thu, 9 Jan 2025 00:16:05 -0800 Subject: [PATCH 04/43] feat: add code submission rules --- .github/ISSUE_TEMPLATE/bug-report.yml | 73 +++++++++++++++++++ .github/ISSUE_TEMPLATE/config.yml | 5 ++ .github/ISSUE_TEMPLATE/feature-request.yml | 23 ++++++ .github/PULL_REQUEST_TEMPLATE.md | 52 +++++++++++++ .../PULL_REQUEST_TEMPLATE.zh-CN.md | 52 +++++++++++++ .github/release.yml | 26 +++++++ .github/workflows/ai-code-review.yml | 23 ++++++ .github/workflows/issue-translator.yml | 18 +++++ app/src/main/resources/logback.xml | 2 +- pom.xml | 2 +- 10 files changed, 274 insertions(+), 2 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug-report.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature-request.yml create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/PULL_REQUEST_TEMPLATE/PULL_REQUEST_TEMPLATE.zh-CN.md create mode 100644 .github/release.yml create mode 100644 .github/workflows/ai-code-review.yml create mode 100644 .github/workflows/issue-translator.yml diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml new file mode 100644 index 00000000..00f3a624 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -0,0 +1,73 @@ +name: '🐛 Bug report' +description: Create a report to help us improve Tiny Engine +title: '🐛 [Bug]: ' +labels: ['🐛 bug'] +body: + - type: markdown + attributes: + value: | + Please fill out the following carefully in order to better fix the problem. + - type: input + id: Environment + attributes: + label: Environment + description: | + **Depending on your browser and operating system, websites may behave differently from one environment to another. Make sure your developers know your technical environment.** + placeholder: Please browser information. + validations: + required: true + - type: input + id: node-version + attributes: + label: Version + description: | + ### **Check if the issue is reproducible with the latest stable version.** + You can use the command `node -v` to view it + placeholder: latest + validations: + required: true + - type: input + id: tiny-vue-version + attributes: + label: Version + description: | + ### **Check if the issue is reproducible with the latest stable version.** + You can use the command `npm ls @opentiny/vue` to view it + placeholder: latest + validations: + required: true + - type: textarea + id: minimal-repo + attributes: + label: Link to minimal reproduction + description: | + **Provide a streamlined CodePen / CodeSandbox or GitHub repository link as much as possible. Please don't fill in a link randomly, it will only close your issue directly.** + placeholder: Please Input + validations: + required: true + - type: textarea + id: reproduce + attributes: + label: Step to reproduce + description: | + **After the replay is turned on, what actions do we need to perform to make the bug appear? Simple and clear steps can help us locate the problem more quickly. Please clearly describe the steps of reproducing the issue. Issues without clear reproducing steps will not be repaired. If the issue marked with 'need reproduction' does not provide relevant steps within 7 days, it will be closed directly.** + placeholder: Please Input + validations: + required: true + - type: textarea + id: expected + attributes: + label: What is expected + placeholder: Please Input + - type: textarea + id: actually + attributes: + label: What is actually happening + placeholder: Please Input + - type: textarea + id: additional-comments + attributes: + label: Any additional comments (optional) + description: | + **Some background / context of how you ran into this bug.** + placeholder: Please Input diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000..1f521648 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: true +contact_links: + - name: Questions or need help + url: https://github.com/opentiny/tiny-engine/discussions + about: Add this WeChat(opentiny), we will invite you to the WeChat discussion group later. diff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.yml new file mode 100644 index 00000000..d3be2079 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-request.yml @@ -0,0 +1,23 @@ +name: ✨ Feature Request +description: Propose new features to @opentiny/tiny-engine-backend-java to improve it. +title: '✨ [Feature]: ' +labels: ['✨ feature'] +body: + - type: textarea + id: feature-solve + attributes: + label: What problem does this feature solve + description: | + Explain your use case, context, and rationale behind this feature request. More importantly, what is the end user experience you are trying to build that led to the need for this feature? + placeholder: Please Input + validations: + required: true + - type: textarea + id: feature-api + attributes: + label: What does the proposed API look like + description: | + Describe how you propose to solve the problem and provide code samples of how the API would work once implemented. Note that you can use Markdown to format your code blocks. + placeholder: Please Input + validations: + required: true diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..617bddd1 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,52 @@ +English | [简体中文](https://github.com/opentiny/tiny-engine-backend-java/blob/main/.github/PULL_REQUEST_TEMPLATE/PULL_REQUEST_TEMPLATE.zh-CN.md) + +# PR + +## PR Checklist + +Please check if your PR fulfills the following requirements: + +- [ ] The commit message follows our [Commit Message Guidelines](https://github.com/opentiny/tiny-engine-backend-java/blob/main/CONTRIBUTING.md) +- [ ] Tests for the changes have been added (for bug fixes / features) +- [ ] Docs have been added / updated (for bug fixes / features) +- [ ] Built its own designer, fully self-validated + +## PR Type + +What kind of change does this PR introduce? + + + +- [ ] Bugfix +- [ ] Feature +- [ ] Code style update (formatting, local variables) +- [ ] Refactoring (no functional changes, no api changes) +- [ ] Build related changes +- [ ] CI related changes +- [ ] Documentation content changes +- [ ] Other... Please describe: + +## Background and solution + + +### What is the current behavior? + + + +Issue Number: N/A + +### What is the new behavior? + + +## Does this PR introduce a breaking change? + +- [ ] Yes +- [ ] No + + + +## Other information diff --git a/.github/PULL_REQUEST_TEMPLATE/PULL_REQUEST_TEMPLATE.zh-CN.md b/.github/PULL_REQUEST_TEMPLATE/PULL_REQUEST_TEMPLATE.zh-CN.md new file mode 100644 index 00000000..32916663 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/PULL_REQUEST_TEMPLATE.zh-CN.md @@ -0,0 +1,52 @@ +[English](https://github.com/opentiny/tiny-engine-backend-java/blob/main/.github/PULL_REQUEST_TEMPLATE.md) | 简体中文 + +# PR + +## PR Checklist + +请检查您的 PR 是否满足以下要求: + +- [ ] commit message遵循我们的[提交贡献指南](https://github.com/opentiny/tiny-engine-backend-java/blob/main/CONTRIBUTING.zh-CN.md) +- [ ] 添加了更改内容的测试用例(用于bugfix/功能) +- [ ] 文档已添加/更新(用于bugfix/功能) +- [ ] 是否构建了自己的设计器,经过了充分的自验证 + +## PR 类型 + +这个PR的类型是? + +- [ ] 日常 bug 修复 +- [ ] 新特性支持 +- [ ] 代码风格优化 +- [ ] 重构 +- [ ] 构建优化 +- [ ] 测试用例 +- [ ] 文档更新 +- [ ] 分支合并 +- [ ] 其他改动(请补充) + + +## 需求背景和解决方案 + + + + +Issue Number: N/A + +### 修改前 + + +### 修改后 + +## 此PR是否含有 breaking change? + +- [ ] 是 +- [ ] 否 + + + +## Other information diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 00000000..274543b2 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,26 @@ +changelog: + exclude: + labels: + - ignore-for-release + authors: + - allcontributors[bot] + categories: + - title: Breaking Changes 🛠 + labels: + - Semver-Major + - breaking-change + - title: Exciting New Features 🎉 + labels: + - Semver-Minor + - feature + - enhancement + - title: Bug Fixes 🐛 + labels: + - Semver-Patch + - bug + - title: Other Changes + labels: + - documentation + - refactoring + - unit-test + - ci diff --git a/.github/workflows/ai-code-review.yml b/.github/workflows/ai-code-review.yml new file mode 100644 index 00000000..29777ff3 --- /dev/null +++ b/.github/workflows/ai-code-review.yml @@ -0,0 +1,23 @@ +name: AI Code Review + +permissions: + contents: read + pull-requests: write + +on: + pull_request: + types: [opened, reopened, synchronize] + +jobs: + review: + runs-on: ubuntu-latest + steps: + - uses: anc95/ChatGPT-CodeReview@main + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + LANGUAGE: Chinese + OPENAI_API_ENDPOINT: https://api.openai.com/v1 + MODEL: gpt-3.5-turbo + MAX_TOKENS: 4096 + MAX_PATCH_LENGTH: 10000 diff --git a/.github/workflows/issue-translator.yml b/.github/workflows/issue-translator.yml new file mode 100644 index 00000000..8b3397bf --- /dev/null +++ b/.github/workflows/issue-translator.yml @@ -0,0 +1,18 @@ +name: 'issue-translator' +on: + issue_comment: + types: [created] + issues: + types: [opened] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: usthe/issues-translate-action@v2.7 + with: + IS_MODIFY_TITLE: false + # 非必须,决定是否需要修改issue标题内容 + # 若是true,则机器人账户@Issues-translate-bot必须拥有修改此仓库issue权限。可以通过邀请@Issues-translate-bot加入仓库协作者实现。 + CUSTOM_BOT_NOTE: Bot detected the issue body's language is not English, translate it automatically. + # 非必须,自定义机器人翻译的前缀开始内容。 diff --git a/app/src/main/resources/logback.xml b/app/src/main/resources/logback.xml index 7aa24fbe..be616676 100644 --- a/app/src/main/resources/logback.xml +++ b/app/src/main/resources/logback.xml @@ -1,7 +1,7 @@ - + diff --git a/pom.xml b/pom.xml index 39ed64e6..d33fc973 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ tiny-engine-service pom 1.0-SNAPSHOT - tiny-engine-webservice-java Maven Webapp + tiny-engine-backend-java Maven Webapp org.springframework.boot From b77f2f4a4caaf1144b43fb625b18a43631518bf7 Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Thu, 9 Jan 2025 00:58:33 -0800 Subject: [PATCH 05/43] fix: modify app schema for test --- .../tinyengine/it/service/app/impl/v1/AppV1ServiceImplTest.java | 2 ++ 1 file changed, 2 insertions(+) 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 6a87cc1c..0a7aa221 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 @@ -107,6 +107,7 @@ void testAppSchema() { int appId = 2; app.setId(appId); app.setHomePage(1); + app.setPlatformId(1); when(appMapper.queryAppById(anyInt())).thenReturn(app); Page page = new Page(); page.setIsPage(true); @@ -141,6 +142,7 @@ void testMergeEntries() { @Test void testGetMetaDto() { App app = new App(); + app.setPlatformId(1); when(appMapper.queryAppById(anyInt())).thenReturn(app); when(i18nEntryMapper.findI18nEntriesByHostandHostType(anyInt(), anyString())) .thenReturn(Arrays.asList(new I18nEntryDto())); From 6559becaa5b13bb46e430a885d84fde0c3a95fa2 Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Wed, 22 Jan 2025 00:52:04 -0800 Subject: [PATCH 06/43] fix: modify t_i18n_entry u_idx_i18n_entity --- .../main/resources/sql/mysql/create_all_tables_ddl_v1.mysql.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fb58b6f9..a4d5333f 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 @@ -511,7 +511,7 @@ create table `t_i18n_entry` `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_i18n_entity` (`key`, `host_id`, `host_type`) using btree + unique index `u_idx_i18n_entity` (`key`, `host_id`, `host_type`,`lang_id`) using btree ) engine = innodb comment = '国际化语言配置表'; drop table if exists `t_i18n_lang`; From 656a4a1c765f37a09152eda05e6160ce8b73431c Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Wed, 22 Jan 2025 03:06:39 -0800 Subject: [PATCH 07/43] fix: modify t_i18n_entry u_idx_i18n_entity --- .../material/impl/BlockGroupServiceImpl.java | 5 +-- .../material/impl/BlockServiceImpl.java | 31 ++++++++++++++++--- ...oupBlock.xml => BlockGroupBlockMapper.xml} | 0 .../resources/mappers/BlockGroupMapper.xml | 12 +++---- .../impl/BlockGroupServiceImplTest.java | 12 ++++++- .../material/impl/BlockServiceImplTest.java | 14 ++++----- 6 files changed, 53 insertions(+), 21 deletions(-) rename base/src/main/resources/mappers/{BlockGroupBlock.xml => BlockGroupBlockMapper.xml} (100%) diff --git a/base/src/main/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImpl.java index bbf8df11..24aef050 100644 --- a/base/src/main/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImpl.java +++ b/base/src/main/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImpl.java @@ -103,7 +103,6 @@ public Integer deleteBlockGroupById(@Param("id") Integer id) { public Integer updateBlockGroupById(BlockGroup blockGroup) { // 判断是对正常的分组修改,还是在分组下添加区块操作的修改 List blockList = blockGroup.getBlocks(); - List blockIds = blockList.stream().map(Block::getId).collect(Collectors.toList()); List blockGroupBlocks = blockGroupBlockMapper.findBlockGroupBlockByBlockGroupId(blockGroup.getId()); List groupBlockIds = blockGroupBlocks.stream().map(BlockGroupBlock::getBlockId).collect(Collectors.toList()); @@ -113,9 +112,11 @@ public Integer updateBlockGroupById(BlockGroup blockGroup) { // 删除区块分组与区块历史版本关系 blockCarriersRelationMapper.deleteBlockCarriersRelation(blockGroup.getId(), hostType, null); // 删除区块分组与区块关系 - return blockGroupBlockMapper.deleteBlockGroupBlockByGroupId(blockGroup.getId()); + blockGroupBlockMapper.deleteBlockGroupBlockByGroupId(blockGroup.getId()); + return blockGroupMapper.updateBlockGroupById(blockGroup); } // 处理参数分组区块 + List blockIds = blockList.stream().map(Block::getId).collect(Collectors.toList()); int result = getBlockGroupIds(groupBlockIds, blockIds, blockGroup.getId()); // 更新区块分组和区块历史关系表 List blockCarriersRelations = new ArrayList<>(); diff --git a/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java index 531cfcdd..90c47ed2 100644 --- a/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java +++ b/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java @@ -24,6 +24,7 @@ import com.tinyengine.it.common.exception.ExceptionEnum; import com.tinyengine.it.common.log.SystemServiceLog; import com.tinyengine.it.mapper.AppMapper; +import com.tinyengine.it.mapper.BlockGroupBlockMapper; import com.tinyengine.it.mapper.BlockGroupMapper; import com.tinyengine.it.mapper.BlockHistoryMapper; import com.tinyengine.it.mapper.BlockMapper; @@ -37,7 +38,9 @@ import com.tinyengine.it.model.dto.SchemaI18n; import com.tinyengine.it.model.entity.App; import com.tinyengine.it.model.entity.Block; +import com.tinyengine.it.model.entity.BlockCarriersRelation; import com.tinyengine.it.model.entity.BlockGroup; +import com.tinyengine.it.model.entity.BlockGroupBlock; import com.tinyengine.it.model.entity.BlockHistory; import com.tinyengine.it.model.entity.User; import com.tinyengine.it.service.app.I18nEntryService; @@ -88,6 +91,8 @@ public class BlockServiceImpl implements BlockService { private I18nEntryMapper i18nEntryMapper; @Autowired private BlockGroupMapper blockGroupMapper; + @Autowired + private BlockGroupBlockMapper blockGroupBlockMapper; /** * 查询表t_block所有数据 @@ -150,12 +155,19 @@ public Integer updateBlockById(BlockDto blockDto) { Block blocks = new Block(); BeanUtils.copyProperties(blockDto, blocks); blocks.setOccupierBy(String.valueOf(1)); - blocks.setLatestHistoryId(blockDto.getLatestHistoryId().getId()); + if(blockDto.getLatestHistoryId() != null){ + blocks.setLatestHistoryId(blockDto.getLatestHistoryId().getId()); + } // 处理区块截图 if (!blockDto.getScreenshot().isEmpty() && !blockDto.getLabel().isEmpty()) { // 图片上传,此处给默认值空字符 blocks.setScreenshot(""); } + + if(blockDto.getGroups().isEmpty()){ + return blockMapper.updateBlockById(blocks); + } + // 过滤出 Integer 类型的对象 // 转换为 Integer 类型 // 收集为 List; @@ -163,10 +175,13 @@ public Integer updateBlockById(BlockDto blockDto) { .filter(obj -> obj instanceof Integer) .map(obj -> (Integer) obj) .collect(Collectors.toList()); - if (!groups.isEmpty()) { + int groupId = groups.get(0); - blocks.setBlockGroupId(groupId); - } + BlockGroupBlock blockGroupBlock = new BlockGroupBlock(); + blockGroupBlock.setBlockGroupId(groupId); + blockGroupBlock.setBlockId(blockDto.getId()); + blockGroupBlockMapper.createBlockGroupBlock(blockGroupBlock); + return blockMapper.updateBlockById(blocks); } @@ -190,7 +205,10 @@ public Result createBlock(BlockDto blockDto) { List groups = blockDto.getGroups(); if (!groups.isEmpty() && groups.get(0) instanceof Integer) { Integer groupId = (Integer) groups.get(0); // 强制类型转换 - blocks.setBlockGroupId(groupId); + BlockGroupBlock blockGroupBlock = new BlockGroupBlock(); + blockGroupBlock.setBlockGroupId(groupId); + blockGroupBlock.setBlockId(blockDto.getId()); + blockGroupBlockMapper.createBlockGroupBlock(blockGroupBlock); } int result = blockMapper.createBlock(blocks); if (result < 1) { @@ -394,6 +412,9 @@ public List getNotInGroupBlocks(NotGroupDto notGroupDto) { int userId = 1; User user = userMapper.queryUserById(userId); List blocksList = blockMapper.findBlocksReturn(notGroupDto); + if(blocksList == null || blocksList.isEmpty()){ + return blocksList; + } for (BlockDto blockDto : blocksList) { List blockGroups = blockGroupMapper.findBlockGroupByBlockId(blockDto.getId()); List objectGroups = new ArrayList<>(blockGroups); diff --git a/base/src/main/resources/mappers/BlockGroupBlock.xml b/base/src/main/resources/mappers/BlockGroupBlockMapper.xml similarity index 100% rename from base/src/main/resources/mappers/BlockGroupBlock.xml rename to base/src/main/resources/mappers/BlockGroupBlockMapper.xml diff --git a/base/src/main/resources/mappers/BlockGroupMapper.xml b/base/src/main/resources/mappers/BlockGroupMapper.xml index 64fbc803..b7f2daaa 100644 --- a/base/src/main/resources/mappers/BlockGroupMapper.xml +++ b/base/src/main/resources/mappers/BlockGroupMapper.xml @@ -181,9 +181,9 @@ b.renter_id as block_renter_id, b.site_id as block_site_id FROM t_block_group bg - JOIN + LEFT JOIN r_block_group_block rbg ON rbg.block_group_id = bg.id - JOIN + LEFT JOIN t_block b ON b.id = rbg.block_id AND b.created_by = #{createdBy} @@ -240,9 +240,9 @@ b.renter_id as block_renter_id, b.site_id as block_site_id FROM t_block_group bg - JOIN + LEFT JOIN r_block_group_block rbg ON rbg.block_group_id = bg.id - JOIN + LEFT JOIN t_block b ON b.id = rbg.block_id AND b.created_by = #{createdBy} @@ -303,9 +303,9 @@ b.renter_id as block_renter_id, b.site_id as block_site_id FROM t_block_group bg - JOIN + LEFT JOIN r_block_group_block rbg ON rbg.block_group_id = bg.id - JOIN + LEFT JOIN t_block b ON b.id = rbg.block_id AND b.created_by = #{createdBy} 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 54f2dd36..9e92239d 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 @@ -16,6 +16,8 @@ import static org.mockito.Mockito.when; import com.tinyengine.it.common.base.Result; +import com.tinyengine.it.mapper.BlockCarriersRelationMapper; +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.BlockGroup; @@ -26,6 +28,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; import java.util.ArrayList; import java.util.Arrays; @@ -41,6 +44,10 @@ class BlockGroupServiceImplTest { private BlockGroupMapper blockGroupMapper; @InjectMocks private BlockGroupServiceImpl blockGroupServiceImpl; + @Mock + private BlockCarriersRelationMapper blockCarriersRelationMapper; + @Mock + private BlockGroupBlockMapper blockGroupBlockMapper; @BeforeEach void setUp() { @@ -86,8 +93,11 @@ void testDeleteBlockGroupById() { @Test void testUpdateBlockGroupById() { BlockGroup param = new BlockGroup(); + param.setId(1); + param.setBlocks(new ArrayList<>()); when(blockGroupMapper.updateBlockGroupById(param)).thenReturn(1); - + when(blockGroupBlockMapper.deleteBlockGroupBlockByGroupId(null)).thenReturn(1); + when(blockCarriersRelationMapper.deleteBlockCarriersRelation(null, null, null)).thenReturn(1); Integer result = blockGroupServiceImpl.updateBlockGroupById(param); Assertions.assertEquals(1, result); } diff --git a/base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java b/base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java index 725a46e4..256ede34 100644 --- a/base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java +++ b/base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java @@ -25,6 +25,7 @@ import com.tinyengine.it.common.base.Result; import com.tinyengine.it.common.enums.Enums; import com.tinyengine.it.mapper.AppMapper; +import com.tinyengine.it.mapper.BlockGroupMapper; import com.tinyengine.it.mapper.BlockMapper; import com.tinyengine.it.mapper.UserMapper; import com.tinyengine.it.model.dto.BlockDto; @@ -32,6 +33,7 @@ import com.tinyengine.it.model.dto.NotGroupDto; import com.tinyengine.it.model.entity.App; import com.tinyengine.it.model.entity.Block; +import com.tinyengine.it.model.entity.BlockGroup; import com.tinyengine.it.model.entity.User; import org.junit.jupiter.api.Assertions; @@ -63,6 +65,8 @@ class BlockServiceImplTest { private UserMapper userMapper; @Mock private AppMapper appMapper; + @Mock + private BlockGroupMapper blockGroupMapper; @BeforeEach void setUp() { @@ -118,7 +122,6 @@ void testCreateBlock() { blockDto.setFramework("cc"); blockDto.setPlatformId(1); blockDto.setAppId(1); - blockDto.setGroups(asList(1)); blockDto.setName("testBlock"); Result result = blockServiceImpl.createBlock(blockDto); Assertions.assertEquals("test", result.getData().getName()); @@ -238,18 +241,15 @@ void testAllTags() { @Test void testGetNotInGroupBlocks() { BlockDto blockDto = new BlockDto(); - blockDto.setLastBuildInfo(new HashMap<>()); - blockDto.setContent(new HashMap<>()); - blockDto.setAssets(new HashMap<>()); - blockDto.setPublicStatus(Enums.Scope.PUBLIC_IN_TENANTS.getValue()); List mockData = Arrays.asList(blockDto); NotGroupDto notGroupDto =new NotGroupDto(); - notGroupDto.setGroupId(1); + List blockGroups = new ArrayList<>(); when(blockMapper.findBlocksReturn(notGroupDto)).thenReturn(mockData); when(userMapper.queryUserById(anyInt())).thenReturn(new User()); + when(blockGroupMapper.findBlockGroupByBlockId(blockDto.getId())).thenReturn(blockGroups); List result = blockServiceImpl.getNotInGroupBlocks(notGroupDto); - Assertions.assertEquals(blockDto, result.get(0)); + Assertions.assertEquals(new ArrayList<>(), result); } @Test From e9aa592a066a8de5a6edacf874fc92c614e61297 Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Thu, 23 Jan 2025 00:35:13 -0800 Subject: [PATCH 08/43] fix: modify block update api --- .../exception/GlobalExceptionAdvice.java | 2 +- .../it/controller/BlockController.java | 10 +--- .../it/mapper/BlockGroupBlockMapper.java | 10 ++++ .../it/mapper/BlockGroupMapper.java | 7 ++- .../it/service/material/BlockService.java | 2 +- .../material/impl/BlockServiceImpl.java | 58 +++++++++++++------ .../mappers/BlockGroupBlockMapper.xml | 2 +- .../exception/GlobalExceptionAdviceTest.java | 5 +- .../it/controller/BlockControllerTest.java | 5 +- .../material/impl/BlockServiceImplTest.java | 17 +++--- 10 files changed, 74 insertions(+), 44 deletions(-) diff --git a/base/src/main/java/com/tinyengine/it/common/exception/GlobalExceptionAdvice.java b/base/src/main/java/com/tinyengine/it/common/exception/GlobalExceptionAdvice.java index d398d579..4e0e0f30 100644 --- a/base/src/main/java/com/tinyengine/it/common/exception/GlobalExceptionAdvice.java +++ b/base/src/main/java/com/tinyengine/it/common/exception/GlobalExceptionAdvice.java @@ -41,7 +41,7 @@ public class GlobalExceptionAdvice { * @param e the e * @return the result */ - @ResponseStatus(HttpStatus.OK) + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ExceptionHandler(Exception.class) public Result> handleException(Exception e) { // 修改为 log.error,传递异常对象以打印堆栈信息 diff --git a/base/src/main/java/com/tinyengine/it/controller/BlockController.java b/base/src/main/java/com/tinyengine/it/controller/BlockController.java index cc076582..1b737136 100644 --- a/base/src/main/java/com/tinyengine/it/controller/BlockController.java +++ b/base/src/main/java/com/tinyengine/it/controller/BlockController.java @@ -398,14 +398,10 @@ public Result> getBlockGroups( ) @SystemControllerLog(description = "区块修改api") @PostMapping("/block/update/{id}") - public Result updateBlocks(@Valid @RequestBody BlockDto blockDto, @PathVariable Integer id) { + public Result updateBlocks(@Valid @RequestBody BlockDto blockDto, @PathVariable Integer id, + @RequestParam(value = "appId", required = false) Integer appId) { blockDto.setId(id); - int result = blockService.updateBlockById(blockDto); - if (result < 1) { - return Result.failed(ExceptionEnum.CM001); - } - BlockDto blocksResult = blockService.queryBlockById(blockDto.getId()); - return Result.success(blocksResult); + return blockService.updateBlockById(blockDto,appId); } /** diff --git a/base/src/main/java/com/tinyengine/it/mapper/BlockGroupBlockMapper.java b/base/src/main/java/com/tinyengine/it/mapper/BlockGroupBlockMapper.java index 3add05c7..7eced891 100644 --- a/base/src/main/java/com/tinyengine/it/mapper/BlockGroupBlockMapper.java +++ b/base/src/main/java/com/tinyengine/it/mapper/BlockGroupBlockMapper.java @@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.tinyengine.it.model.entity.BlockGroupBlock; +import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; @@ -87,4 +88,13 @@ public interface BlockGroupBlockMapper extends BaseMapper { */ @Select("select * from r_block_group_block where block_group_id = #{blockGroupId}") List findBlockGroupBlockByBlockGroupId(Integer blockGroupId); + + /** + * 通过区块分组id查询分组下区块 + * @param blockId the block id + * @param groupId the block group id + * @return the list + */ + @Delete("delete from r_block_group_block where block_group_id = #{groupId} and block_id = #{blockId}") + Integer deleteByGroupIdAndBlockId(Integer groupId, Integer blockId); } diff --git a/base/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java b/base/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java index 91d25d28..9b92094b 100644 --- a/base/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java +++ b/base/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java @@ -139,12 +139,13 @@ public interface BlockGroupMapper extends BaseMapper { /** * 根据区块id查询区块分组信息 - * + * @param createdBy the user id * @param blockId the block id * @return the list */ @Select("select * from t_block_group bg " + "left join r_block_group_block bgb on bgb.block_group_id = bg.id " - + "where bgb.block_id = #{blockId}") - List findBlockGroupByBlockId(Integer blockId); + + "where bgb.block_id = #{blockId} and created_by = #{createdBy}") + List findBlockGroupByBlockId(Integer blockId,String createdBy); + } \ No newline at end of file diff --git a/base/src/main/java/com/tinyengine/it/service/material/BlockService.java b/base/src/main/java/com/tinyengine/it/service/material/BlockService.java index 1b3485dd..32cb4df7 100644 --- a/base/src/main/java/com/tinyengine/it/service/material/BlockService.java +++ b/base/src/main/java/com/tinyengine/it/service/material/BlockService.java @@ -69,7 +69,7 @@ public interface BlockService { * @param blockDto the block dto * @return the BlockDto */ - Integer updateBlockById(BlockDto blockDto); + Result updateBlockById(BlockDto blockDto, Integer appId); /** * 新增表t_block数据 diff --git a/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java index 90c47ed2..2e824198 100644 --- a/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java +++ b/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java @@ -38,7 +38,6 @@ import com.tinyengine.it.model.dto.SchemaI18n; import com.tinyengine.it.model.entity.App; import com.tinyengine.it.model.entity.Block; -import com.tinyengine.it.model.entity.BlockCarriersRelation; import com.tinyengine.it.model.entity.BlockGroup; import com.tinyengine.it.model.entity.BlockGroupBlock; import com.tinyengine.it.model.entity.BlockHistory; @@ -113,6 +112,9 @@ public List queryAllBlock() { @Override public BlockDto queryBlockById(@Param("id") Integer id) { BlockDto blockDto = blockMapper.findBlockAndGroupAndHistoByBlockId(id); + if (blockDto == null) { + return blockDto; + } boolean isPublished = blockDto.getLastBuildInfo() != null && blockDto.getLastBuildInfo().get("result") instanceof Boolean ? (Boolean) blockDto.getLastBuildInfo().get("result") : Boolean.FALSE; @@ -149,23 +151,28 @@ public Integer deleteBlockById(@Param("id") Integer id) { * @return blockDto */ @Override - public Integer updateBlockById(BlockDto blockDto) { - // public 不是部分公开, 则public_scope_tenants为空数组 + public Result updateBlockById(BlockDto blockDto, Integer appId) { + Block blockResult = blockMapper.queryBlockById(blockDto.getId()); + if (blockResult.getAppId() != appId) { + return Result.failed(ExceptionEnum.CM007); + } // 把前端传参赋值给实体 Block blocks = new Block(); BeanUtils.copyProperties(blockDto, blocks); blocks.setOccupierBy(String.valueOf(1)); - if(blockDto.getLatestHistoryId() != null){ + if (blockDto.getLatestHistoryId() != null) { blocks.setLatestHistoryId(blockDto.getLatestHistoryId().getId()); } // 处理区块截图 - if (!blockDto.getScreenshot().isEmpty() && !blockDto.getLabel().isEmpty()) { + if (blockDto.getScreenshot() != null && blockDto.getLabel() != null) { // 图片上传,此处给默认值空字符 blocks.setScreenshot(""); } - - if(blockDto.getGroups().isEmpty()){ - return blockMapper.updateBlockById(blocks); + Integer result; + if (blockDto.getGroups() == null || blockDto.getGroups().isEmpty()) { + blockMapper.updateBlockById(blocks); + BlockDto blockDtoResult = queryBlockById(blocks.getId()); + return Result.success(blockDtoResult); } // 过滤出 Integer 类型的对象 @@ -176,13 +183,29 @@ public Integer updateBlockById(BlockDto blockDto) { .map(obj -> (Integer) obj) .collect(Collectors.toList()); - int groupId = groups.get(0); + // 对接登录后获取用户id + String createdBy = "1"; + // 根据区块id获取区块所在分组 + List blockGroups = blockGroupMapper.findBlockGroupByBlockId(blocks.getId(), createdBy); + if (!blockGroups.isEmpty()) { + List blockGroupIds = blockGroups.stream().map(BlockGroup::getId).collect(Collectors.toList()); + for (Integer id : blockGroupIds) { + blockGroupBlockMapper.deleteByGroupIdAndBlockId(id, blocks.getId()); + } + } + + for (Integer groupId : groups) { BlockGroupBlock blockGroupBlock = new BlockGroupBlock(); - blockGroupBlock.setBlockGroupId(groupId); blockGroupBlock.setBlockId(blockDto.getId()); + blockGroupBlock.setBlockGroupId(groupId); blockGroupBlockMapper.createBlockGroupBlock(blockGroupBlock); + } + - return blockMapper.updateBlockById(blocks); + blockMapper.updateBlockById(blocks); + + BlockDto blockDtoResult = queryBlockById(blocks.getId()); + return Result.success(blockDtoResult); } /** @@ -412,11 +435,12 @@ public List getNotInGroupBlocks(NotGroupDto notGroupDto) { int userId = 1; User user = userMapper.queryUserById(userId); List blocksList = blockMapper.findBlocksReturn(notGroupDto); - if(blocksList == null || blocksList.isEmpty()){ + if (blocksList == null || blocksList.isEmpty()) { return blocksList; } + for (BlockDto blockDto : blocksList) { - List blockGroups = blockGroupMapper.findBlockGroupByBlockId(blockDto.getId()); + List blockGroups = blockGroupMapper.findBlockGroupByBlockId(blockDto.getId(), String.valueOf(userId)); List objectGroups = new ArrayList<>(blockGroups); blockDto.setGroups(objectGroups); } @@ -518,12 +542,8 @@ public Result deploy(BlockBuildDto blockBuildDto) { } blockDto.setLastBuildInfo(buildInfo); blockDto.setLatestHistoryId(blockHistory); - int blockResult = updateBlockById(blockDto); - if (blockResult < 1) { - return Result.failed(ExceptionEnum.CM008); - } - BlockDto result = queryBlockById(id); - return Result.success(result); + + return updateBlockById(blockDto, blockDto.getAppId()); } /** diff --git a/base/src/main/resources/mappers/BlockGroupBlockMapper.xml b/base/src/main/resources/mappers/BlockGroupBlockMapper.xml index 34df2193..1adf5c70 100644 --- a/base/src/main/resources/mappers/BlockGroupBlockMapper.xml +++ b/base/src/main/resources/mappers/BlockGroupBlockMapper.xml @@ -98,6 +98,6 @@ UPDATE block_id = VALUES (block_id), block_group_id = - VALUES (block_group_id) + VALUES (block_group_id); diff --git a/base/src/test/java/com/tinyengine/it/common/exception/GlobalExceptionAdviceTest.java b/base/src/test/java/com/tinyengine/it/common/exception/GlobalExceptionAdviceTest.java index 16ffb2bc..fb078966 100644 --- a/base/src/test/java/com/tinyengine/it/common/exception/GlobalExceptionAdviceTest.java +++ b/base/src/test/java/com/tinyengine/it/common/exception/GlobalExceptionAdviceTest.java @@ -36,8 +36,9 @@ class GlobalExceptionAdviceTest { @Test void testHandleException() { - Result> result = globalExceptionAdvice.handleException(new Exception("message", - new Throwable("message"))); + // 创建一个新的异常对象并传递给 handleException + Exception e = new Exception("message", new Throwable("message")); + Result> result = globalExceptionAdvice.handleException(e); Assertions.assertEquals(ExceptionEnum.CM001.getResultMsg(), result.getMessage()); Assertions.assertEquals(ExceptionEnum.CM001.getResultCode(), result.getCode()); } diff --git a/base/src/test/java/com/tinyengine/it/controller/BlockControllerTest.java b/base/src/test/java/com/tinyengine/it/controller/BlockControllerTest.java index 9dc2891c..ba0bb146 100644 --- a/base/src/test/java/com/tinyengine/it/controller/BlockControllerTest.java +++ b/base/src/test/java/com/tinyengine/it/controller/BlockControllerTest.java @@ -179,11 +179,12 @@ void testGetAllBlockCategories() { @Test void testUpdateBlocks() { - when(blockService.updateBlockById(any(BlockDto.class))).thenReturn(1); BlockDto returnData = new BlockDto(); + when(blockService.updateBlockById(any(BlockDto.class), anyInt())).thenReturn(Result.success(returnData)); + when(blockService.queryBlockById(anyInt())).thenReturn(returnData); - Result result = blockController.updateBlocks(returnData, Integer.valueOf(0)); + Result result = blockController.updateBlocks(returnData, Integer.valueOf(0), Integer.valueOf(1)); Assertions.assertEquals(returnData, result.getData()); } } diff --git a/base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java b/base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java index 256ede34..ee5d586d 100644 --- a/base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java +++ b/base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java @@ -129,14 +129,15 @@ void testCreateBlock() { @Test void testUpdateBlockById() { - when(blockMapper.updateBlockById(any())).thenReturn(1); BlockDto blockDto = new BlockDto(); - blockDto.setId(1); - blockDto.setName("BlockTest1"); - blockDto.setScreenshot("aa"); - blockDto.setLabel("bb"); - Integer result = blockServiceImpl.updateBlockById(blockDto); - Assertions.assertEquals(1, result); + when(blockMapper.updateBlockById(any())).thenReturn(1); + when(blockMapper.findBlockAndGroupAndHistoByBlockId(anyInt())).thenReturn(new BlockDto()); + Block block = new Block(); + block.setAppId(1); + when(blockMapper.queryBlockById(blockDto.getId())).thenReturn(block); + + Result result = blockServiceImpl.updateBlockById(blockDto,1); + Assertions.assertEquals(null, result.getData()); } @Test @@ -246,7 +247,7 @@ void testGetNotInGroupBlocks() { List blockGroups = new ArrayList<>(); when(blockMapper.findBlocksReturn(notGroupDto)).thenReturn(mockData); when(userMapper.queryUserById(anyInt())).thenReturn(new User()); - when(blockGroupMapper.findBlockGroupByBlockId(blockDto.getId())).thenReturn(blockGroups); + when(blockGroupMapper.findBlockGroupByBlockId(blockDto.getId(),blockDto.getCreatedBy())).thenReturn(blockGroups); List result = blockServiceImpl.getNotInGroupBlocks(notGroupDto); Assertions.assertEquals(new ArrayList<>(), result); From ed7483d1e4f0ec535278833039d55dde399043ad Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Thu, 23 Jan 2025 02:28:41 -0800 Subject: [PATCH 09/43] fix: Modify code format --- .../it/controller/BlockController.java | 2 -- .../mapper/BlockCarriersRelationMapper.java | 19 ++++++++----------- .../it/mapper/BlockGroupMapper.java | 2 +- .../it/model/dto/BlockGroupDto.java | 1 - .../tinyengine/it/model/dto/NotGroupDto.java | 2 -- .../service/app/impl/AiChatServiceImpl.java | 19 ++++++++++++++----- .../service/app/impl/v1/AppV1ServiceImpl.java | 1 - .../material/impl/BlockGroupServiceImpl.java | 14 +++++++------- .../material/impl/BlockServiceImpl.java | 2 +- .../impl/BlockGroupServiceImplTest.java | 1 - .../material/impl/BlockServiceImplTest.java | 7 +++---- 11 files changed, 34 insertions(+), 36 deletions(-) diff --git a/base/src/main/java/com/tinyengine/it/controller/BlockController.java b/base/src/main/java/com/tinyengine/it/controller/BlockController.java index 1b737136..1f1fdd18 100644 --- a/base/src/main/java/com/tinyengine/it/controller/BlockController.java +++ b/base/src/main/java/com/tinyengine/it/controller/BlockController.java @@ -14,7 +14,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage; 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.mapper.BlockMapper; import com.tinyengine.it.mapper.TenantMapper; @@ -46,7 +45,6 @@ import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; diff --git a/base/src/main/java/com/tinyengine/it/mapper/BlockCarriersRelationMapper.java b/base/src/main/java/com/tinyengine/it/mapper/BlockCarriersRelationMapper.java index 75be087a..7162a576 100644 --- a/base/src/main/java/com/tinyengine/it/mapper/BlockCarriersRelationMapper.java +++ b/base/src/main/java/com/tinyengine/it/mapper/BlockCarriersRelationMapper.java @@ -16,7 +16,6 @@ import com.tinyengine.it.model.entity.BlockCarriersRelation; import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; import java.util.List; @@ -44,10 +43,10 @@ public interface BlockCarriersRelationMapper extends BaseMapper queryBlockCarriersRelationByCondition(BlockCarriersRelation BlockCarriersRelation); + List queryBlockCarriersRelationByCondition(BlockCarriersRelation blockCarriersRelation); /** * 根据主键id删除表t_block_carriers_relation数据 @@ -60,31 +59,29 @@ public interface BlockCarriersRelationMapper extends BaseMapper { @Select("select * from t_block_group bg " + "left join r_block_group_block bgb on bgb.block_group_id = bg.id " + "where bgb.block_id = #{blockId} and created_by = #{createdBy}") - List findBlockGroupByBlockId(Integer blockId,String createdBy); + List findBlockGroupByBlockId(Integer blockId, String createdBy); } \ No newline at end of file diff --git a/base/src/main/java/com/tinyengine/it/model/dto/BlockGroupDto.java b/base/src/main/java/com/tinyengine/it/model/dto/BlockGroupDto.java index ee0887c8..cdd8819b 100644 --- a/base/src/main/java/com/tinyengine/it/model/dto/BlockGroupDto.java +++ b/base/src/main/java/com/tinyengine/it/model/dto/BlockGroupDto.java @@ -17,7 +17,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.tinyengine.it.common.base.BaseEntity; import com.tinyengine.it.model.entity.App; -import com.tinyengine.it.model.entity.Block; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/base/src/main/java/com/tinyengine/it/model/dto/NotGroupDto.java b/base/src/main/java/com/tinyengine/it/model/dto/NotGroupDto.java index 09bcca6b..451dd26e 100644 --- a/base/src/main/java/com/tinyengine/it/model/dto/NotGroupDto.java +++ b/base/src/main/java/com/tinyengine/it/model/dto/NotGroupDto.java @@ -15,8 +15,6 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import java.util.List; - /** *

* 条件查询不在区块分组参数 diff --git a/base/src/main/java/com/tinyengine/it/service/app/impl/AiChatServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/app/impl/AiChatServiceImpl.java index eb887956..97fc1434 100644 --- a/base/src/main/java/com/tinyengine/it/service/app/impl/AiChatServiceImpl.java +++ b/base/src/main/java/com/tinyengine/it/service/app/impl/AiChatServiceImpl.java @@ -14,6 +14,8 @@ import com.tinyengine.it.common.base.Result; import com.tinyengine.it.common.enums.Enums; +import com.tinyengine.it.common.exception.ExceptionEnum; +import com.tinyengine.it.common.exception.ServiceException; import com.tinyengine.it.common.log.SystemServiceLog; import com.tinyengine.it.gateway.ai.AiChatClient; import com.tinyengine.it.model.dto.AiMessages; @@ -89,15 +91,19 @@ public Result> getAnswerFromAi(AiParam aiParam) { } List> choices = (List>) data.get("choices"); Map message = (Map) choices.get(0).get("message"); - boolean isFinish = false; + String answerContent = ""; - isFinish = choices.get(0).get("finish_reason") != null || isFinish; + String isFinish = ""; + Object finishReason = choices.get(0).get("finish_reason"); + if (finishReason instanceof String) { + isFinish = (String) finishReason; + } if (!"length".equals(isFinish)) { answerContent = message.get("content"); } // 若内容被截断,继续请求AI - while (isFinish) { + while ("length".equals(isFinish)) { String prefix = message.get("content"); answerContent = answerContent + prefix; @@ -115,12 +121,15 @@ public Result> getAnswerFromAi(AiParam aiParam) { try { data = requestAnswerFromAi(aiParam.getMessages(), model).getData(); } catch (Exception e) { - e.printStackTrace(); + new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultMsg()); } choices = (List>) data.get("choices"); message = (Map) choices.get(0).get("message"); answerContent += message.get("content"); - isFinish = (boolean) choices.get(0).get("finish_reason"); + finishReason = choices.get(0).get("finish_reason"); + if (finishReason instanceof String) { + isFinish = (String) finishReason; + } } 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 e75bec94..05345f0b 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 @@ -32,7 +32,6 @@ 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.SchemaDataSource; import com.tinyengine.it.model.dto.SchemaDto; import com.tinyengine.it.model.dto.SchemaI18n; import com.tinyengine.it.model.dto.SchemaMeta; diff --git a/base/src/main/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImpl.java index 24aef050..e06537d4 100644 --- a/base/src/main/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImpl.java +++ b/base/src/main/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImpl.java @@ -187,17 +187,17 @@ public List getBlockGroupByIdsOrAppId(List ids, Integer app } // 对查询的结果的区块赋值current_version for (BlockGroup blockGroupTemp : blockGroupsListResult) { - for (Block block: blockGroupTemp.getBlocks()){ + for (Block block : blockGroupTemp.getBlocks()) { BlockCarriersRelation queryParam = new BlockCarriersRelation(); queryParam.setBlockId(block.getId()); queryParam.setHostId(blockGroup.getId()); queryParam.setHostType(Enums.BlockGroup.BLOCK_GROUP.getValue()); - List blockCarriersRelations = blockCarriersRelationMapper.queryBlockCarriersRelationByCondition(queryParam); - if (blockCarriersRelations.isEmpty()){ - continue; - } - String version = blockCarriersRelations.get(0).getVersion(); - block.setCurrentVersion(version); + List blockCarriersRelations = blockCarriersRelationMapper.queryBlockCarriersRelationByCondition(queryParam); + if (blockCarriersRelations.isEmpty()) { + continue; + } + String version = blockCarriersRelations.get(0).getVersion(); + block.setCurrentVersion(version); } } diff --git a/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java index 2e824198..464f1676 100644 --- a/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java +++ b/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java @@ -153,7 +153,7 @@ public Integer deleteBlockById(@Param("id") Integer id) { @Override public Result updateBlockById(BlockDto blockDto, Integer appId) { Block blockResult = blockMapper.queryBlockById(blockDto.getId()); - if (blockResult.getAppId() != appId) { + if (!Objects.equals(blockResult.getAppId(), appId)) { return Result.failed(ExceptionEnum.CM007); } // 把前端传参赋值给实体 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 9e92239d..99305c57 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 @@ -28,7 +28,6 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.springframework.beans.factory.annotation.Autowired; import java.util.ArrayList; import java.util.Arrays; diff --git a/base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java b/base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java index ee5d586d..7cabdb16 100644 --- a/base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java +++ b/base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java @@ -23,7 +23,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.fasterxml.jackson.core.JsonProcessingException; import com.tinyengine.it.common.base.Result; -import com.tinyengine.it.common.enums.Enums; import com.tinyengine.it.mapper.AppMapper; import com.tinyengine.it.mapper.BlockGroupMapper; import com.tinyengine.it.mapper.BlockMapper; @@ -136,7 +135,7 @@ void testUpdateBlockById() { block.setAppId(1); when(blockMapper.queryBlockById(blockDto.getId())).thenReturn(block); - Result result = blockServiceImpl.updateBlockById(blockDto,1); + Result result = blockServiceImpl.updateBlockById(blockDto, 1); Assertions.assertEquals(null, result.getData()); } @@ -243,11 +242,11 @@ void testAllTags() { void testGetNotInGroupBlocks() { BlockDto blockDto = new BlockDto(); List mockData = Arrays.asList(blockDto); - NotGroupDto notGroupDto =new NotGroupDto(); + NotGroupDto notGroupDto = new NotGroupDto(); List blockGroups = new ArrayList<>(); when(blockMapper.findBlocksReturn(notGroupDto)).thenReturn(mockData); when(userMapper.queryUserById(anyInt())).thenReturn(new User()); - when(blockGroupMapper.findBlockGroupByBlockId(blockDto.getId(),blockDto.getCreatedBy())).thenReturn(blockGroups); + when(blockGroupMapper.findBlockGroupByBlockId(blockDto.getId(), blockDto.getCreatedBy())).thenReturn(blockGroups); List result = blockServiceImpl.getNotInGroupBlocks(notGroupDto); Assertions.assertEquals(new ArrayList<>(), result); From cabb3093640b7c72d6e1638ec884e72e2c4f5750 Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Thu, 23 Jan 2025 02:36:13 -0800 Subject: [PATCH 10/43] fix: Modify code format --- .../src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java | 1 - 1 file changed, 1 deletion(-) diff --git a/base/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java b/base/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java index f632d886..9b92094b 100644 --- a/base/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java +++ b/base/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java @@ -146,7 +146,6 @@ public interface BlockGroupMapper extends BaseMapper { @Select("select * from t_block_group bg " + "left join r_block_group_block bgb on bgb.block_group_id = bg.id " + "where bgb.block_id = #{blockId} and created_by = #{createdBy}") - List findBlockGroupByBlockId(Integer blockId,String createdBy); } \ No newline at end of file From 83cb48a37581bf787c52c02315328f24f71af80c Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Thu, 23 Jan 2025 18:37:12 -0800 Subject: [PATCH 11/43] fix: Modify code format --- .../java/com/tinyengine/it/controller/BlockController.java | 2 +- .../main/java/com/tinyengine/it/mapper/BlockGroupMapper.java | 2 +- .../tinyengine/it/service/app/impl/AiChatServiceImpl.java | 5 +++-- .../it/service/app/impl/AiChatServiceImplTest.java | 2 +- .../it/service/material/impl/BlockServiceImplTest.java | 4 ++-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/base/src/main/java/com/tinyengine/it/controller/BlockController.java b/base/src/main/java/com/tinyengine/it/controller/BlockController.java index 1f1fdd18..54c15b1f 100644 --- a/base/src/main/java/com/tinyengine/it/controller/BlockController.java +++ b/base/src/main/java/com/tinyengine/it/controller/BlockController.java @@ -399,7 +399,7 @@ public Result> getBlockGroups( public Result updateBlocks(@Valid @RequestBody BlockDto blockDto, @PathVariable Integer id, @RequestParam(value = "appId", required = false) Integer appId) { blockDto.setId(id); - return blockService.updateBlockById(blockDto,appId); + return blockService.updateBlockById(blockDto, appId); } /** diff --git a/base/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java b/base/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java index 9b92094b..25790ccf 100644 --- a/base/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java +++ b/base/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java @@ -146,6 +146,6 @@ public interface BlockGroupMapper extends BaseMapper { @Select("select * from t_block_group bg " + "left join r_block_group_block bgb on bgb.block_group_id = bg.id " + "where bgb.block_id = #{blockId} and created_by = #{createdBy}") - List findBlockGroupByBlockId(Integer blockId,String createdBy); + List findBlockGroupByBlockId(Integer blockId, String createdBy); } \ No newline at end of file diff --git a/base/src/main/java/com/tinyengine/it/service/app/impl/AiChatServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/app/impl/AiChatServiceImpl.java index 97fc1434..08191e17 100644 --- a/base/src/main/java/com/tinyengine/it/service/app/impl/AiChatServiceImpl.java +++ b/base/src/main/java/com/tinyengine/it/service/app/impl/AiChatServiceImpl.java @@ -121,11 +121,12 @@ public Result> getAnswerFromAi(AiParam aiParam) { try { data = requestAnswerFromAi(aiParam.getMessages(), model).getData(); } catch (Exception e) { - new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultMsg()); + throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultMsg()); } choices = (List>) data.get("choices"); message = (Map) choices.get(0).get("message"); - answerContent += message.get("content"); + StringBuilder sb = new StringBuilder(); + answerContent = String.valueOf(sb.append(message.get("content"))); finishReason = choices.get(0).get("finish_reason"); if (finishReason instanceof String) { isFinish = (String) finishReason; diff --git a/base/src/test/java/com/tinyengine/it/service/app/impl/AiChatServiceImplTest.java b/base/src/test/java/com/tinyengine/it/service/app/impl/AiChatServiceImplTest.java index 92a01b1a..76ad7a7b 100644 --- a/base/src/test/java/com/tinyengine/it/service/app/impl/AiChatServiceImplTest.java +++ b/base/src/test/java/com/tinyengine/it/service/app/impl/AiChatServiceImplTest.java @@ -87,7 +87,7 @@ void testGetAnswerFromAi() { Map response = new HashMap<>(); response.put("data", dataMap); - response.put("result",(String) ""); + response.put("result", (String) ""); when(aiChatClient.executeChatRequest(any(OpenAiBodyDto.class))).thenReturn(response); Result> result = aiChatServiceImpl.getAnswerFromAi(aiParam); Map resultData = result.getData(); diff --git a/base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java b/base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java index c72031dc..7cabdb16 100644 --- a/base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java +++ b/base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java @@ -135,7 +135,7 @@ void testUpdateBlockById() { block.setAppId(1); when(blockMapper.queryBlockById(blockDto.getId())).thenReturn(block); - Result result = blockServiceImpl.updateBlockById(blockDto,1); + Result result = blockServiceImpl.updateBlockById(blockDto, 1); Assertions.assertEquals(null, result.getData()); } @@ -246,7 +246,7 @@ void testGetNotInGroupBlocks() { List blockGroups = new ArrayList<>(); when(blockMapper.findBlocksReturn(notGroupDto)).thenReturn(mockData); when(userMapper.queryUserById(anyInt())).thenReturn(new User()); - when(blockGroupMapper.findBlockGroupByBlockId(blockDto.getId(),blockDto.getCreatedBy())).thenReturn(blockGroups); + when(blockGroupMapper.findBlockGroupByBlockId(blockDto.getId(), blockDto.getCreatedBy())).thenReturn(blockGroups); List result = blockServiceImpl.getNotInGroupBlocks(notGroupDto); Assertions.assertEquals(new ArrayList<>(), result); From 48645e1f0f86b4ec8df6ebe1cf6537508d3883a8 Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Sun, 26 Jan 2025 00:14:37 -0800 Subject: [PATCH 12/43] fix: modify block group api --- .github/workflows/checkstyle.yml | 45 ++++ app/src/main/resources/checkstyle.xml | 226 ++++++++++++++++++ .../it/common/base/PageQueryVo.java | 2 +- .../it/controller/PageController.java | 4 +- .../it/mapper/BlockGroupMapper.java | 28 +-- .../it/mapper/BlockHistoryMapper.java | 4 +- .../com/tinyengine/it/mapper/BlockMapper.java | 19 +- .../com/tinyengine/it/model/dto/BlockDto.java | 4 - .../com/tinyengine/it/model/entity/Block.java | 4 - .../service/app/impl/v1/AppV1ServiceImpl.java | 2 +- .../material/impl/BlockGroupServiceImpl.java | 12 +- .../material/impl/BlockServiceImpl.java | 15 +- .../resources/mappers/BlockGroupMapper.xml | 29 ++- .../main/resources/mappers/BlockMapper.xml | 38 +-- .../impl/BlockGroupServiceImplTest.java | 6 +- .../material/impl/BlockServiceImplTest.java | 2 +- pom.xml | 31 ++- 17 files changed, 382 insertions(+), 89 deletions(-) create mode 100644 .github/workflows/checkstyle.yml create mode 100644 app/src/main/resources/checkstyle.xml diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml new file mode 100644 index 00000000..e1e7ad25 --- /dev/null +++ b/.github/workflows/checkstyle.yml @@ -0,0 +1,45 @@ +name: Checkstyle Code Quality + +on: + push: + branches: + - develop # 或者你想要检查的分支 + pull_request: + branches: + - develop # 你可以在 PR 时检查代码 + +jobs: + check: + runs-on: ubuntu-24.04 + + steps: + # 检出代码 + - name: Checkout code + uses: actions/checkout@v4 + + # 设置 JDK(如果是 Java 项目) + - name: Set up JDK 8.* + uses: actions/setup-java@v4 + with: + java-version: '8.*' + + # 安装 Checkstyle(如果你是用 Maven 或 Gradle) + - name: Install dependencies + run: | + ./mvnw install # 如果是 Maven 项目 + # 或者 + # ./gradlew build # 如果是 Gradle 项目 + + # 运行 Checkstyle + - name: Run Checkstyle + run: | + ./mvnw checkstyle:check # 如果是 Maven 项目 + # 或者 + # ./gradlew check # 如果是 Gradle 项目 + + # 查看 Checkstyle 检查报告 + - name: Upload Checkstyle report + uses: actions/upload-artifact@v4 + with: + name: checkstyle-report + path: target/checkstyle-result.xml # 如果是 Maven 项目 \ No newline at end of file diff --git a/app/src/main/resources/checkstyle.xml b/app/src/main/resources/checkstyle.xml new file mode 100644 index 00000000..c0d6cc9e --- /dev/null +++ b/app/src/main/resources/checkstyle.xml @@ -0,0 +1,226 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/base/src/main/java/com/tinyengine/it/common/base/PageQueryVo.java b/base/src/main/java/com/tinyengine/it/common/base/PageQueryVo.java index 551beae9..9eb6df88 100644 --- a/base/src/main/java/com/tinyengine/it/common/base/PageQueryVo.java +++ b/base/src/main/java/com/tinyengine/it/common/base/PageQueryVo.java @@ -96,7 +96,7 @@ public void setData(T data) { /** * 分页查询对象 - * + * @param 泛型类型参数 E,代表分页数据的类型 * @return page */ public Page getPage() { diff --git a/base/src/main/java/com/tinyengine/it/controller/PageController.java b/base/src/main/java/com/tinyengine/it/controller/PageController.java index d840cef0..8fefcb94 100644 --- a/base/src/main/java/com/tinyengine/it/controller/PageController.java +++ b/base/src/main/java/com/tinyengine/it/controller/PageController.java @@ -71,8 +71,8 @@ public class PageController { * @return allpage */ @Operation(summary = "获取页面列表", description = "获取页面列表", parameters = { - @Parameter(name = "aid", description = "appId")}, responses = { - @ApiResponse(responseCode = "200", description = "返回信息", + @Parameter(name = "aid", description = "appId")}, responses = { + @ApiResponse(responseCode = "200", description = "返回信息", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Page.class))), @ApiResponse(responseCode = "400", description = "请求失败")}) diff --git a/base/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java b/base/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java index 25790ccf..2ddca53d 100644 --- a/base/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java +++ b/base/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java @@ -33,11 +33,11 @@ public interface BlockGroupMapper extends BaseMapper { /** * 查询表t_block_group所有信息及关联的区块信息 - * - * @param createdBy createdBy + * @param blockCreatedBy the blockCreatedBy + * @param groupCreatedBy the groupCreatedBy * @return the list */ - List queryAllBlockGroupAndBlock(String createdBy); + List queryAllBlockGroupAndBlock(String blockCreatedBy, String groupCreatedBy); /** * 查询表t_block_group所有信息 @@ -51,10 +51,11 @@ public interface BlockGroupMapper extends BaseMapper { * 根据主键id查询表t_block_group数据 * * @param id the id - * @param createdBy createdBy + * @param blockCreatedBy the lockCreatedBy + * @param groupCreatedBy the groupCreatedBy * @return the block group */ - BlockGroup queryBlockGroupAndBlockById(@Param("id") Integer id, String createdBy); + BlockGroup queryBlockGroupAndBlockById(@Param("id") Integer id, String blockCreatedBy, String groupCreatedBy); /** * 通过ID查询分组信息 @@ -101,10 +102,11 @@ public interface BlockGroupMapper extends BaseMapper { * 通过appId和createdBy查区块分组关联的区块信息 * * @param appId the app id - * @param createdBy createdBy + * @param blockCreatedBy the blockCreatedBy + * @param groupCreatedBy the groupCreatedBy * @return the list */ - List queryBlockGroupByAppId(Integer appId, String createdBy); + List queryBlockGroupByAppId(Integer appId, String blockCreatedBy, String groupCreatedBy); /** * 通过appId获取分组信息 @@ -125,15 +127,13 @@ public interface BlockGroupMapper extends BaseMapper { @Result(column = "app", property = "appId"), @Result(column = "app", property = "app", one = @One(select = "com.tinyengine.it.mapper.AppMapper.queryAppById")), - @Result(column = "block_group_id", javaType = List.class, property = "blocks", - many = @Many(select = "com.tinyengine.it.mapper.BlockMapper.findBlocksByBlockGroupId")) + @Result(column = "id", javaType = List.class, property = "blocks", + many = @Many(select = "com.tinyengine.it.mapper.BlockMapper.findBlockByBlockGroupId")) }) - @Select("SELECT bg.*, bs.block_group_id as block_group_id, a.id as app " + @Select("SELECT bg.*, a.id as app " + "FROM t_block_group bg " + "left join t_app a on bg.app_id = a.id " - + "left join t_block bs on bg.id = bs.block_group_id " - + "WHERE bg.id = #{blockGroupId} " - + "GROUP BY bg.id") + + "WHERE bg.id = #{blockGroupId} ") List getBlockGroupsById(int blockGroupId); @@ -145,7 +145,7 @@ public interface BlockGroupMapper extends BaseMapper { */ @Select("select * from t_block_group bg " + "left join r_block_group_block bgb on bgb.block_group_id = bg.id " - + "where bgb.block_id = #{blockId} and created_by = #{createdBy}") + + "where bgb.block_id = #{blockId} and bg.created_by = #{createdBy}") List findBlockGroupByBlockId(Integer blockId, String createdBy); } \ No newline at end of file diff --git a/base/src/main/java/com/tinyengine/it/mapper/BlockHistoryMapper.java b/base/src/main/java/com/tinyengine/it/mapper/BlockHistoryMapper.java index 89f61550..1b6dcdfc 100644 --- a/base/src/main/java/com/tinyengine/it/mapper/BlockHistoryMapper.java +++ b/base/src/main/java/com/tinyengine/it/mapper/BlockHistoryMapper.java @@ -104,8 +104,10 @@ public interface BlockHistoryMapper extends BaseMapper { */ @Select({""}) List queryBlockAndVersion(@Param("ids") List ids, @Param("materialHistoryId") Integer materialHistoryId); diff --git a/base/src/main/java/com/tinyengine/it/mapper/BlockMapper.java b/base/src/main/java/com/tinyengine/it/mapper/BlockMapper.java index 6a449823..debca3cd 100644 --- a/base/src/main/java/com/tinyengine/it/mapper/BlockMapper.java +++ b/base/src/main/java/com/tinyengine/it/mapper/BlockMapper.java @@ -79,16 +79,6 @@ public interface BlockMapper extends BaseMapper { */ Integer createBlock(Block block); - /** - * 通过区块分组id获取区块信息 - * - * @param blockGroupId the block group id - * @return the list - */ - @Select("select b.* from t_block b " - + "where b.block_group_id = #{blockGroupId} ") - List findBlocksByBlockGroupId(int blockGroupId); - /** * 根据name或者description查询表t_block信息 * @@ -118,10 +108,7 @@ public interface BlockMapper extends BaseMapper { }) @Select("select b.*, b.id as block_id " + "from t_block b " - + "left join t_block_group bg on b.block_group_id = bg.id " - + "left join t_block_history bh on b.latest_history_id = bh.id " - + "where b.id = #{blockId} " - + "group by b.id") + + "where b.id = #{blockId} ") BlockDto findBlockAndGroupAndHistoByBlockId(Integer blockId); @@ -156,7 +143,7 @@ public interface BlockMapper extends BaseMapper { List findBlocksByBlockGroupIdAppId(int appId); /** - * 根据分组id返回对应的区块信息及关联分组信息 + * 根据条件返回对应的区块信息及关联分组信息 * * @return the list */ @@ -191,7 +178,5 @@ public interface BlockMapper extends BaseMapper { * @param createdBy createdBy * @return the list */ - @Select("select b.* from t_block b " - + "where b.block_group_id = #{blockGroupId} and b.created_by = #{createdBy}") List findBlockByBlockGroupId(int blockGroupId, String createdBy); } \ No newline at end of file diff --git a/base/src/main/java/com/tinyengine/it/model/dto/BlockDto.java b/base/src/main/java/com/tinyengine/it/model/dto/BlockDto.java index de9940e3..b0c0fc6e 100644 --- a/base/src/main/java/com/tinyengine/it/model/dto/BlockDto.java +++ b/base/src/main/java/com/tinyengine/it/model/dto/BlockDto.java @@ -123,10 +123,6 @@ public class BlockDto extends BaseEntity { @JsonProperty("platform_id") private Integer platformId; - @Schema(name = "blockGroupId", description = "区块分组id,关联t_block_group表id") - @JsonProperty("block_group_id") - private Integer blockGroupId; - @JsonProperty("occupier") @Schema(name = "occupierBy", description = "当前锁定人") private User occupier; diff --git a/base/src/main/java/com/tinyengine/it/model/entity/Block.java b/base/src/main/java/com/tinyengine/it/model/entity/Block.java index 37ceb6ed..dd063cd1 100644 --- a/base/src/main/java/com/tinyengine/it/model/entity/Block.java +++ b/base/src/main/java/com/tinyengine/it/model/entity/Block.java @@ -127,10 +127,6 @@ public class Block extends BaseEntity { @JsonProperty("content_blocks") private String contentBlocks; - @Schema(name = "blockGroupId", description = "区块分组id,关联t_block_group表id") - @JsonProperty("block_group_id") - private Integer blockGroupId; - @TableField(exist = false) @JsonProperty("public_scope_tenants") private List publicScopeTenants = new ArrayList<>(); 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 05345f0b..58270f05 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 @@ -362,7 +362,7 @@ public List getBlockHistoryIdBySemver(List blocksVersi historyMap.put(version, item.getHistoryId()); itemMap.put("historyMap", historyMap); itemMap.put("versions", versionList); - blocksVersionMap.put("blockId", itemMap); + blocksVersionMap.put(String.valueOf(item.getBlockId()), itemMap); } // 遍历区块历史记录 综合信息映射关系 diff --git a/base/src/main/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImpl.java index e06537d4..70e0eac0 100644 --- a/base/src/main/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImpl.java +++ b/base/src/main/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImpl.java @@ -164,22 +164,23 @@ public Result> createBlockGroup(BlockGroup blockGroup) { */ @Override public List getBlockGroupByIdsOrAppId(List ids, Integer appId, String from) { - String createdBy = "1"; // 获取登录用户信息 // 此接收到的两个参数不一定同时存在 List blockGroupsListResult = new ArrayList<>(); - createdBy = (Enums.BlockGroup.BLOCK.getValue()).equals(from) ? createdBy : null; // from值为block在区块管理处增加createdBy条件 + String groupCreatedBy = "1"; // 获取登录用户id + String blockCreatedBy = "1"; + blockCreatedBy = (Enums.BlockGroup.BLOCK.getValue()).equals(from) ? blockCreatedBy : null; // from值为block在区块管理处增加createdBy条件 BlockGroup blockGroup = new BlockGroup(); if (ids != null) { for (int blockgroupId : ids) { - blockGroup = blockGroupMapper.queryBlockGroupAndBlockById(blockgroupId, createdBy); + blockGroup = blockGroupMapper.queryBlockGroupAndBlockById(blockgroupId, blockCreatedBy, groupCreatedBy); blockGroupsListResult.add(blockGroup); } } if (appId != null) { - blockGroupsListResult = blockGroupMapper.queryBlockGroupByAppId(appId, createdBy); + blockGroupsListResult = blockGroupMapper.queryBlockGroupByAppId(appId, blockCreatedBy, groupCreatedBy); } if (ids == null && appId == null) { - blockGroupsListResult = blockGroupMapper.queryAllBlockGroupAndBlock(createdBy); + blockGroupsListResult = blockGroupMapper.queryAllBlockGroupAndBlock( blockCreatedBy, groupCreatedBy); } if (blockGroupsListResult.isEmpty()) { @@ -216,7 +217,6 @@ private Integer getBlockGroupIds(List groupBlockIds, List para int result = 0; if (groupBlockIds.size() > paramIds.size()) { Block block = new Block(); - block.setBlockGroupId(null); for (Integer blockId : groupBlockIds) { if (!paramIds.contains(blockId)) { result = blockId; diff --git a/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java b/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java index 11569c48..d2eb05b8 100644 --- a/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java +++ b/base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java @@ -226,20 +226,21 @@ public Result createBlock(BlockDto blockDto) { blocks.setIsDefault(false); blocks.setIsOfficial(false); blocks.setPlatformId(1); // 新建区块给默认值 + + int result = blockMapper.createBlock(blocks); + if (result < 1) { + return Result.failed(ExceptionEnum.CM001); + } + int id = blocks.getId(); + BlockDto blocksResult = queryBlockById(id); List groups = blockDto.getGroups(); if (!groups.isEmpty() && groups.get(0) instanceof Integer) { Integer groupId = (Integer) groups.get(0); // 强制类型转换 BlockGroupBlock blockGroupBlock = new BlockGroupBlock(); blockGroupBlock.setBlockGroupId(groupId); - blockGroupBlock.setBlockId(blockDto.getId()); + blockGroupBlock.setBlockId(id); blockGroupBlockMapper.createBlockGroupBlock(blockGroupBlock); } - int result = blockMapper.createBlock(blocks); - if (result < 1) { - return Result.failed(ExceptionEnum.CM001); - } - int id = blocks.getId(); - BlockDto blocksResult = queryBlockById(id); return Result.success(blocksResult); } diff --git a/base/src/main/resources/mappers/BlockGroupMapper.xml b/base/src/main/resources/mappers/BlockGroupMapper.xml index b7f2daaa..51eaad35 100644 --- a/base/src/main/resources/mappers/BlockGroupMapper.xml +++ b/base/src/main/resources/mappers/BlockGroupMapper.xml @@ -185,12 +185,17 @@ r_block_group_block rbg ON rbg.block_group_id = bg.id LEFT JOIN t_block b ON b.id = rbg.block_id - - AND b.created_by = #{createdBy} + + AND b.created_by = #{blockCreatedBy} - + AND b.last_build_info is not null and b.content is not null and b.assets is not null + + + AND bg.created_by = #{groupCreatedBy} + + @@ -244,16 +249,19 @@ r_block_group_block rbg ON rbg.block_group_id = bg.id LEFT JOIN t_block b ON b.id = rbg.block_id - - AND b.created_by = #{createdBy} + + AND b.created_by = #{blockCreatedBy} - + AND b.last_build_info is not null and b.content is not null and b.assets is not null AND bg.app_id = #{appId} + + AND bg.created_by = #{groupCreatedBy} + @@ -307,16 +315,19 @@ r_block_group_block rbg ON rbg.block_group_id = bg.id LEFT JOIN t_block b ON b.id = rbg.block_id - - AND b.created_by = #{createdBy} + + AND b.created_by = #{blockCreatedBy} - + AND b.last_build_info is not null and b.content is not null and b.assets is not null AND bg.id = #{id} + + AND bg.created_by = #{groupCreatedBy} + diff --git a/base/src/main/resources/mappers/BlockMapper.xml b/base/src/main/resources/mappers/BlockMapper.xml index 7d08fbf5..c6a8a47b 100644 --- a/base/src/main/resources/mappers/BlockMapper.xml +++ b/base/src/main/resources/mappers/BlockMapper.xml @@ -9,7 +9,7 @@ id , label, name, framework, content, assets, last_build_info, description, tags, latest_version, latest_history_id, screenshot, path, occupier_by, is_official, `public`, is_default, tiny_reserved, npm_name, - i18n, platform_id, app_id, content_blocks, block_group_id, created_by, last_updated_by, created_time, + i18n, platform_id, app_id, content_blocks, created_by, last_updated_by, created_time, last_updated_time, tenant_id, renter_id, site_id @@ -81,9 +81,6 @@ AND content_blocks = #{contentBlocks} - - AND block_group_id = #{blockGroupId} - AND created_by = #{createdBy} @@ -175,9 +172,6 @@ content_blocks = #{contentBlocks}, - - block_group_id = #{blockGroupId}, - created_by = #{createdBy}, @@ -227,7 +221,6 @@ - @@ -267,14 +260,27 @@ + - + + SELECT + + FROM t_component_library + + + + + + + + + + + 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..f91843aa 100644 --- a/base/src/main/resources/mappers/MaterialHistoryMapper.xml +++ b/base/src/main/resources/mappers/MaterialHistoryMapper.xml @@ -8,7 +8,7 @@ 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, + material_size, tgz_url, unzip_tgz_root_path_url, unzip_tgz_files, is_started, created_by, last_updated_by, created_time, last_updated_time, tenant_id, renter_id, site_id @@ -56,6 +56,9 @@ AND unzip_tgz_files = #{unzipTgzFiles} + + AND is_started = #{isStarted} + AND created_by = #{createdBy} @@ -123,6 +126,9 @@ unzip_tgz_files = #{unzipTgzFiles}, + + is_started = #{isStarted}, + created_by = #{createdBy}, @@ -164,6 +170,7 @@ + @@ -210,47 +217,49 @@ 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 + , is_started + , 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} + , #{isStarted} + , #{createdBy} + , #{lastUpdatedBy} + , #{createdTime} + , #{lastUpdatedTime} + , #{tenantId} + , #{renterId} + , #{siteId}) 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 9f425ef8..2b9503ad 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,13 +1,12 @@ /** * 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; @@ -75,11 +74,11 @@ void testFindMaterialHistoryByCondition() { @Test void testDeleteMaterialHistoryById() { MaterialHistory param = new MaterialHistory(); - Result.success(param); when(materialHistoryMapper.deleteMaterialHistoryById(1)).thenReturn(1); when(materialHistoryMapper.queryMaterialHistoryById(1)).thenReturn(param); + Result result = materialHistoryServiceImpl.deleteMaterialHistoryById(1); - Assertions.assertEquals( Result.success(param), result); + Assertions.assertEquals(Result.success(param), result); } @Test @@ -87,6 +86,7 @@ void testUpdateMaterialHistoryById() { MaterialHistory param = new MaterialHistory(); when(materialHistoryMapper.updateMaterialHistoryById(param)).thenReturn(1); when(materialHistoryMapper.queryMaterialHistoryById(1)).thenReturn(param); + Result result = materialHistoryServiceImpl.updateMaterialHistoryById(param); Assertions.assertEquals(Result.success(param), result); } @@ -94,9 +94,9 @@ void testUpdateMaterialHistoryById() { @Test void testCreateMaterialHistory() { MaterialHistory param = new MaterialHistory(); - Result.success(param); when(materialHistoryMapper.createMaterialHistory(param)).thenReturn(1); when(materialHistoryMapper.queryMaterialHistoryById(1)).thenReturn(param); + 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..99285deb 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; @@ -57,8 +58,8 @@ void testQueryMaterialById() { Material mockData = new Material(); 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 @@ -74,26 +75,30 @@ void testQueryMaterialByCondition() { @Test void testDeleteMaterialById() { when(materialMapper.deleteMaterialById(1)).thenReturn(2); + Material mockData = new Material(); + 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(); 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(); 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); } } From 05f4473e6b12c4f110dabd2183b8da8b43d74a25 Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Sun, 6 Apr 2025 19:05:24 -0700 Subject: [PATCH 36/43] feat: component library api --- ...tarted_column_to_t_material_history.h2.sql | 2 - ...ted_column_to_t_material_history.mysql.sql | 2 - .../com/tinyengine/it/common/utils/Utils.java | 17 +- .../it/controller/ComponentController.java | 29 ++- .../ComponentLibraryController.java | 26 +-- .../it/controller/MaterialController.java | 18 +- .../it/mapper/ComponentLibraryMapper.java | 42 +--- .../it/model/dto/BundleMaterial.java | 3 +- .../it/model/dto/BundleResultDto.java | 30 +++ .../it/model/dto/CustComponentDto.java | 29 +++ .../tinyengine/it/model/dto/PackagesDto.java | 36 +++ .../tinyengine/it/model/dto/SchemaDto.java | 1 + .../tinyengine/it/model/entity/Component.java | 4 +- .../it/model/entity/ComponentLibrary.java | 9 +- .../it/model/entity/MaterialHistory.java | 3 - .../service/app/impl/v1/AppV1ServiceImpl.java | 35 +++ .../it/service/material/ComponentService.java | 9 +- .../material/impl/ComponentServiceImpl.java | 135 ++++++++---- .../impl/MaterialHistoryServiceImpl.java | 11 +- .../mappers/ComponentLibraryMapper.xml | 208 +++++++++++++++--- .../mappers/MaterialHistoryMapper.xml | 11 +- .../app/impl/v1/AppV1ServiceImplTest.java | 11 +- 22 files changed, 495 insertions(+), 176 deletions(-) delete mode 100644 app/src/main/resources/sql/h2/add_is_started_column_to_t_material_history.h2.sql delete mode 100644 app/src/main/resources/sql/mysql/add_is_started_column_to_t_material_history.mysql.sql create mode 100644 base/src/main/java/com/tinyengine/it/model/dto/BundleResultDto.java create mode 100644 base/src/main/java/com/tinyengine/it/model/dto/CustComponentDto.java create mode 100644 base/src/main/java/com/tinyengine/it/model/dto/PackagesDto.java diff --git a/app/src/main/resources/sql/h2/add_is_started_column_to_t_material_history.h2.sql b/app/src/main/resources/sql/h2/add_is_started_column_to_t_material_history.h2.sql deleted file mode 100644 index 80ff1574..00000000 --- a/app/src/main/resources/sql/h2/add_is_started_column_to_t_material_history.h2.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE t_material_history - ADD COLUMN is_started TINYINT(1) DEFAULT 0; \ No newline at end of file diff --git a/app/src/main/resources/sql/mysql/add_is_started_column_to_t_material_history.mysql.sql b/app/src/main/resources/sql/mysql/add_is_started_column_to_t_material_history.mysql.sql deleted file mode 100644 index 80ff1574..00000000 --- a/app/src/main/resources/sql/mysql/add_is_started_column_to_t_material_history.mysql.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE t_material_history - ADD COLUMN is_started TINYINT(1) DEFAULT 0; \ No newline at end of file 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..44172583 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,9 @@ 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.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; @@ -33,6 +35,8 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import java.util.List; + /** * 组件api * @@ -43,6 +47,9 @@ @RequestMapping("/material-center/api") @Tag(name = "组件") public class ComponentController { + /** + * The component service. + */ @Autowired private ComponentService componentService; @@ -58,12 +65,30 @@ 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.readFileAndBulkCreate(file); } + + /** + * 批量创建自定义组件 + * + * @param custComponentDto the custComponentDto + * @return result + */ + @Operation(summary = "批量创建自定义组件", description = "批量创建自定义组件", parameters = { + @Parameter(name = "file", 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(@RequestParam CustComponentDto custComponentDto) { + // 返回插入和更新的条数 + 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 index d6282a67..64adb5c3 100644 --- a/base/src/main/java/com/tinyengine/it/controller/ComponentLibraryController.java +++ b/base/src/main/java/com/tinyengine/it/controller/ComponentLibraryController.java @@ -41,7 +41,7 @@ */ @Validated @RestController -@RequestMapping("/componentLibrary-center/api") +@RequestMapping("/material-center/api") @Tag(name = "组件库") public class ComponentLibraryController { /** @@ -51,19 +51,19 @@ public class ComponentLibraryController { private ComponentLibraryService componentLibraryService; /** - * 查询表ComponentLibrary信息 + * 查询表ComponentLibrary信息列表 * * @return ComponentLibrary信息 all componentLibrary */ - @Operation(summary = "查询表ComponentLibrary信息", - description = "查询表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("/componentLibrary/list") + @SystemControllerLog(description = "查询表ComponentLibrary信息列表") + @GetMapping("/component-library/list") public Result> getAllComponentLibrary() { List componentLibraryHistoryList = componentLibraryService.queryAllComponentLibrary(); return Result.success(componentLibraryHistoryList); @@ -117,10 +117,10 @@ public Result updateComponentLibrary(@PathVariable Integer id, * 删除ComponentLibrary信息 * * @param id the id - * @return app信息 result + * @return ComponentLibrary信息 result */ - @Operation(summary = "删除app信息", - description = "删除app信息", + @Operation(summary = "删除ComponentLibrary信息", + description = "删除ComponentLibrary信息", parameters = { @Parameter(name = "id", description = "ComponentLibrary主键id") }, @@ -130,25 +130,25 @@ public Result updateComponentLibrary(@PathVariable Integer id, schema = @Schema(implementation = ComponentLibrary.class))), @ApiResponse(responseCode = "400", description = "请求失败")} ) - @SystemControllerLog(description = "删除app信息") + @SystemControllerLog(description = "删除ComponentLibrary信息") @GetMapping("/component-library/delete/{id}") public Result deleteComponentLibrary(@PathVariable Integer id) { return componentLibraryService.deleteComponentLibraryById(id); } /** - * 获取应用信息详情 + * 获取ComponentLibrary信息详情 * * @param id the id * @return the result */ - @Operation(summary = "获取应用信息详情", description = "获取应用信息详情", parameters = { + @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 = "获取应用信息详情") + @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 index 6fbbde69..6c4f91bf 100644 --- a/base/src/main/java/com/tinyengine/it/controller/MaterialController.java +++ b/base/src/main/java/com/tinyengine/it/controller/MaterialController.java @@ -55,14 +55,14 @@ public class MaterialController { * * @return Material信息 all material */ - @Operation(summary = "查询表Material信息", - description = "查询表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信息") + @SystemControllerLog(description = "查询表Material信息列表") @GetMapping("/material/list") public Result> getAllMaterial() { List materialHistoryList = materialService.queryAllMaterial(); @@ -119,8 +119,8 @@ public Result updateMaterial(@PathVariable Integer id, @RequestBody Ma * @param id the id * @return app信息 result */ - @Operation(summary = "删除app信息", - description = "删除app信息", + @Operation(summary = "删除Material信息", + description = "删除Material信息", parameters = { @Parameter(name = "id", description = "Material主键id") }, @@ -130,25 +130,25 @@ public Result updateMaterial(@PathVariable Integer id, @RequestBody Ma schema = @Schema(implementation = Material.class))), @ApiResponse(responseCode = "400", description = "请求失败")} ) - @SystemControllerLog(description = "删除app信息") + @SystemControllerLog(description = "删除Material信息") @GetMapping("/material/delete/{id}") public Result deleteMaterial(@PathVariable Integer id) { return materialService.deleteMaterialById(id); } /** - * 获取应用信息详情 + * 获取Material信息详情 * * @param id the id * @return the result */ - @Operation(summary = "获取应用信息详情", description = "获取应用信息详情", parameters = { + @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 = "获取应用信息详情") + @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 index 8c1888d5..1de56202 100644 --- a/base/src/main/java/com/tinyengine/it/mapper/ComponentLibraryMapper.java +++ b/base/src/main/java/com/tinyengine/it/mapper/ComponentLibraryMapper.java @@ -15,7 +15,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.tinyengine.it.model.entity.ComponentLibrary; -import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -44,10 +43,10 @@ public interface ComponentLibraryMapper extends BaseMapper { /** * 根据条件查询表t_component_library数据 * - * @param component the component + * @param componentLibrary the componentLibrary * @return the list */ - List queryComponentLibraryByCondition(ComponentLibrary component); + List queryComponentLibraryByCondition(ComponentLibrary componentLibrary); /** * 根据主键id删除表t_component_library数据 @@ -60,45 +59,16 @@ public interface ComponentLibraryMapper extends BaseMapper { /** * 根据主键id更新表t_component_library数据 * - * @param component the component + * @param componentLibrary the componentLibrary * @return the integer */ - Integer updateComponentLibraryById(ComponentLibrary component); + Integer updateComponentLibraryById(ComponentLibrary componentLibrary); /** * 新增表t_component_library数据 * - * @param component the component + * @param componentLibrary the componentLibrary * @return the integer */ - Integer createComponentLibrary(ComponentLibrary component); - - /** - * Find user components by material history id list. - * - * @param id the id - * @return the list - */ - List findUserComponentLibrarysByMaterialHistoryId(@Param("id") Integer id); - - /** - * 新增表r_material_component数据 - * - * @param materialComponentLibrary the materialComponentLibrary - * @return the integer - */ - @Insert("INSERT INTO r_material_component (id,material_id,component_id )" - + "values (#{id},#{materialId},#{componentId})") - Integer createMaterialComponentLibrary(MaterialComponentLibrary materialComponentLibrary); - - - /** - * 新增表r_material_component数据 - * - * @param materialHistoryComponentLibrary the materialHistoryComponentLibrary - * @return the integer - */ - @Insert("INSERT INTO r_material_history_component (id,material_history_id,component_id )" - + "values (#{id},#{materialHistoryId},#{componentId})") - Integer createMaterialHistoryComponentLibrary(MaterialHistoryComponentLibrary materialHistoryComponentLibrary); + 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 9b46d989..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,9 +87,9 @@ public class Component extends BaseEntity { @Schema(name = "snippets", description = "schema片段") private List> snippets; - @JsonProperty("schema") + @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 index 79f04d88..86d16712 100644 --- a/base/src/main/java/com/tinyengine/it/model/entity/ComponentLibrary.java +++ b/base/src/main/java/com/tinyengine/it/model/entity/ComponentLibrary.java @@ -16,7 +16,6 @@ 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; import io.swagger.v3.oas.annotations.media.Schema; @@ -42,9 +41,8 @@ public class ComponentLibrary extends BaseEntity { @Schema(name = "version", description = "版本") private String version; - @TableField(typeHandler = MapTypeHandler.class) @Schema(name = "name", description = "名称") - private Map name; + private String name; @JsonProperty("package") @Schema(name = "package", description = "包名") @@ -84,11 +82,14 @@ public class ComponentLibrary extends BaseEntity { private Integer publicStatus; @Schema(name = "isStarted", description = "标识启用") - private Integer isStarted; + 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/model/entity/MaterialHistory.java b/base/src/main/java/com/tinyengine/it/model/entity/MaterialHistory.java index 205771db..6403debf 100644 --- a/base/src/main/java/com/tinyengine/it/model/entity/MaterialHistory.java +++ b/base/src/main/java/com/tinyengine/it/model/entity/MaterialHistory.java @@ -79,9 +79,6 @@ public class MaterialHistory extends HistoryEntity { @Schema(name = "unzipTgzFiles", description = "物料压缩包解压后文件地址") private String unzipTgzFiles; - @Schema(name = "isStarted", description = "是否启动") - private String isStarted; - @Schema(name = "components", description = "组件") private List components; } 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/ComponentService.java b/base/src/main/java/com/tinyengine/it/service/material/ComponentService.java index e7f4b330..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; @@ -88,16 +90,15 @@ public interface ComponentService { * @param file the file * @return result the result */ - Result> bundleSplit(MultipartFile file); + Result bundleSplit(MultipartFile file); /** * 批量创建component * - * @param componentList the componentList - * @param materialId the materialId + * @param custComponentDto the custComponentDto * @return result the result */ - Result custComponentBulkCreate(List componentList, Integer materialId); + Result custComponentBatchCreate(CustComponentDto custComponentDto); } 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 88d583ec..295fa127 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 @@ -1,31 +1,33 @@ /** * 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.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.mapper.MaterialHistoryMapper; -import com.tinyengine.it.mapper.MaterialMapper; 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.Material; +import com.tinyengine.it.model.entity.ComponentLibrary; import com.tinyengine.it.model.entity.MaterialComponent; -import com.tinyengine.it.model.entity.MaterialHistory; import com.tinyengine.it.model.entity.MaterialHistoryComponent; import com.tinyengine.it.service.material.ComponentService; @@ -33,7 +35,6 @@ import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.annotations.Param; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -52,10 +53,18 @@ @Service @Slf4j public class ComponentServiceImpl implements ComponentService { + /** + * The component mapper. + */ @Autowired private ComponentMapper componentMapper; - private MaterialMapper materialMapper; - private MaterialHistoryMapper materialHistoryMapper; + + /** + * The component library mapper. + */ + @Autowired + private ComponentLibraryMapper componentLibraryMapper; + /** * 查询表t_component所有数据 @@ -128,9 +137,33 @@ 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(); + List componentList = this.bundleSplit(file).getData().getComponentList(); + List packageList = this.bundleSplit(file).getData().getPackageList(); + 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); } @@ -141,7 +174,8 @@ public Result readFileAndBulkCreate(MultipartFile file) { * @return result the result */ @Override - public Result> bundleSplit(MultipartFile file) { + @SystemServiceLog(description = "bundleSplit 拆分bundle.json实现方法") + public Result bundleSplit(MultipartFile file) { // 获取bundle.json数据 Result result = Utils.parseJsonFileStream(file); if (!result.isSuccess()) { @@ -174,6 +208,10 @@ public Result> bundleSplit(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; @@ -194,36 +232,43 @@ public Result> bundleSplit(MultipartFile file) { } componentList.add(component); } - - return Result.success(componentList); + List> packages = bundleDto.getMaterials().getPackages(); + 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); + } + BundleResultDto bundleList = new BundleResultDto(); + bundleList.setComponentList(componentList); + bundleList.setPackageList(packageList); + return Result.success(bundleList); } /** * 批量创建component * - * @param componentList the componentList - * @param materialHistoryId the materialHistoryId + * @param custComponentDto the custComponentDto * @return result the result */ @Override - public Result custComponentBulkCreate(List componentList, Integer materialId) { + @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); // 插入新记录 - Integer result = createComponent(component); - if (result != 1) { - continue; - } - int materialHistoryId = this.createMaterialHistory(materialId); - if (materialHistoryId == 0) { - continue; - } - MaterialHistoryComponent materialHistoryComponent = new MaterialHistoryComponent(); - materialHistoryComponent.setComponentId(component.getId()); - materialHistoryComponent.setMaterialHistoryId(materialHistoryId); - componentMapper.createMaterialHistoryComponent(materialHistoryComponent); + createComponent(component); } addNum = addNum + 1; @@ -234,30 +279,13 @@ public Result custComponentBulkCreate(List componentList, return Result.success(fileResult); } - public int createMaterialHistory(Integer materialId) { - int materialHistoryId = 0; - Material material = materialMapper.queryMaterialById(materialId); - MaterialHistory materialHistory = new MaterialHistory(); - // 把material中的属性值赋值到materialHistories中 - BeanUtils.copyProperties(material, materialHistory); - materialHistory.setId(null); - materialHistory.setRefId(materialId); - materialHistory.setVersion(material.getLatestVersion()); - materialHistory.setContent(new HashMap<>()); - int result = materialHistoryMapper.createMaterialHistory(materialHistory); - if (result != 1) { - return materialHistoryId; - } - materialHistoryId = materialHistory.getId(); - return materialHistoryId; - } - /** * 批量创建组件 * * @param componentList the componentList * @return result the result */ + @SystemServiceLog(description = "bulkCreate 批量创建组件实现方法") public Result bulkCreate(List componentList) { int addNum = 0; int updateNum = 0; @@ -267,9 +295,20 @@ public 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 + 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 e28885f5..41e281d2 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 @@ -35,6 +35,9 @@ @Service @Slf4j public class MaterialHistoryServiceImpl implements MaterialHistoryService { + /** + * The material history mapper. + */ @Autowired private MaterialHistoryMapper materialHistoryMapper; @@ -57,7 +60,7 @@ public List findAllMaterialHistory() { @Override public Result findMaterialHistoryById(@Param("id") Integer id) { MaterialHistory materialHistory = materialHistoryMapper.queryMaterialHistoryById(id); - if(null == materialHistory.getId()){ + if (null == materialHistory.getId()) { return Result.failed(ExceptionEnum.CM009); } return Result.success(materialHistory); @@ -86,7 +89,7 @@ public List findMaterialHistoryByCondition(MaterialHistory mate public Result deleteMaterialHistoryById(@Param("id") Integer id) { Result result = this.findMaterialHistoryById(id); int deleteResult = materialHistoryMapper.deleteMaterialHistoryById(id); - if(deleteResult != 1){ + if (deleteResult != 1) { return Result.failed(ExceptionEnum.CM008); } return result; @@ -101,7 +104,7 @@ public Result deleteMaterialHistoryById(@Param("id") Integer id @Override public Result updateMaterialHistoryById(MaterialHistory materialHistory) { int updateResult = materialHistoryMapper.updateMaterialHistoryById(materialHistory); - if(updateResult != 1){ + if (updateResult != 1) { return Result.failed(ExceptionEnum.CM008); } Result result = this.findMaterialHistoryById(materialHistory.getId()); @@ -117,7 +120,7 @@ public Result updateMaterialHistoryById(MaterialHistory materia @Override public Result createMaterialHistory(MaterialHistory materialHistory) { int createResult = materialHistoryMapper.createMaterialHistory(materialHistory); - if(createResult != 1){ + if (createResult != 1) { return Result.failed(ExceptionEnum.CM008); } Result result = this.findMaterialHistoryById(materialHistory.getId()); diff --git a/base/src/main/resources/mappers/ComponentLibraryMapper.xml b/base/src/main/resources/mappers/ComponentLibraryMapper.xml index 6b65e50a..7b565887 100644 --- a/base/src/main/resources/mappers/ComponentLibraryMapper.xml +++ b/base/src/main/resources/mappers/ComponentLibraryMapper.xml @@ -7,7 +7,7 @@ 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, + , 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 @@ -17,7 +17,7 @@ AND version = #{version} - AND name = #{name} + AND `name` = #{name} AND package = #{packageName} @@ -84,74 +84,73 @@ - version = #{version} + version = #{version}, - name = #{name} + `name` = #{name}, - package = #{packageName} + `package` = #{packageName}, - registry = #{registry} + registry = #{registry}, - description = #{description} + description = #{description}, - framework = #{framework} + framework = #{framework}, - script = #{script} + script = #{script}, - css = #{css} + css = #{css}, - bundle = #{bundle} + bundle = #{bundle}, - `others` = #{others} + `others` = #{others}, - thumbnail = #{thumbnail} + thumbnail = #{thumbnail}, - `public` = #{publicStatus} + `public` = #{publicStatus}, - is_started = #{publicStatus} + is_started = #{isStarted}, - is_official = #{isOfficial} + is_official = #{isOfficial}, - is_default = #{isDefault} + is_default = #{isDefault}, - created_by = #{createdBy} + created_by = #{createdBy}, - last_updated_by = #{lastUpdatedBy} + last_updated_by = #{lastUpdatedBy}, - created_time = #{createdTime} + created_time = #{createdTime}, - last_updated_time = #{lastUpdatedTime} + last_updated_time = #{lastUpdatedTime}, - tenant_id = #{tenantId} + tenant_id = #{tenantId}, - renter_id = #{renterId} + renter_id = #{renterId}, - site_id = #{siteId} + site_id = #{siteId}, - @@ -177,23 +176,169 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -220,8 +365,7 @@ - WHERE - id=#{id} + WHERE id=#{id} diff --git a/base/src/main/resources/mappers/MaterialHistoryMapper.xml b/base/src/main/resources/mappers/MaterialHistoryMapper.xml index f91843aa..94720a4b 100644 --- a/base/src/main/resources/mappers/MaterialHistoryMapper.xml +++ b/base/src/main/resources/mappers/MaterialHistoryMapper.xml @@ -8,7 +8,7 @@ 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, is_started, created_by, last_updated_by, created_time, + 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 @@ -56,9 +56,6 @@ AND unzip_tgz_files = #{unzipTgzFiles} - - AND is_started = #{isStarted} - AND created_by = #{createdBy} @@ -126,9 +123,6 @@ unzip_tgz_files = #{unzipTgzFiles}, - - is_started = #{isStarted}, - created_by = #{createdBy}, @@ -170,7 +164,6 @@ - @@ -231,7 +224,6 @@ , tgz_url , unzip_tgz_root_path_url , unzip_tgz_files - , is_started , created_by , last_updated_by , created_time @@ -253,7 +245,6 @@ , #{tgzUrl} , #{unzipTgzRootPathUrl} , #{unzipTgzFiles} - , #{isStarted} , #{createdBy} , #{lastUpdatedBy} , #{createdTime} 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")); } From 6a5269dcfe1636446c9d15366683d076dc1aedf6 Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Sun, 6 Apr 2025 23:06:15 -0700 Subject: [PATCH 37/43] feat: component library api --- .../it/controller/ComponentController.java | 27 +++++++++++++-- .../service/app/impl/CanvasServiceImpl.java | 5 ++- .../material/ComponentLibraryService.java | 12 +++---- .../impl/ComponentLibraryServiceImpl.java | 22 ++++++------ .../material/impl/ComponentServiceImpl.java | 34 +++++++++++++------ .../handler/MyMetaObjectHandlerTest.java | 2 +- .../app/impl/CanvasServiceImplTest.java | 6 +++- .../impl/BlockGroupServiceImplTest.java | 6 ++++ .../impl/ComponentServiceImplTest.java | 11 +++++- .../impl/MaterialHistoryServiceImplTest.java | 4 +++ .../impl/MaterialServiceImplTest.java | 6 +++- 11 files changed, 100 insertions(+), 35 deletions(-) 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 44172583..06f29307 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.model.dto.BundleResultDto; import com.tinyengine.it.model.dto.CustComponentDto; import com.tinyengine.it.model.dto.FileResult; import com.tinyengine.it.model.entity.Component; @@ -53,6 +54,27 @@ public class ComponentController { @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/createComponent") + public Result bundleCreateComponent(@RequestParam MultipartFile file) { + if (file.isEmpty()) { + return Result.failed(ExceptionEnum.CM307); + } + // 返回插入和更新的条数 + return componentService.readFileAndBulkCreate(file); + } + /** * 上传bunled.json文件处理自定义组件 * @@ -66,12 +88,11 @@ public class ComponentController { @ApiResponse(responseCode = "400", description = "请求失败")}) @SystemControllerLog(description = "上传bunled.json文件处理自定义组件") @PostMapping("/component/bundle/split") - public Result bundleSplit(@RequestParam MultipartFile file) { + public Result bundleSplit(@RequestParam MultipartFile file) { if (file.isEmpty()) { return Result.failed(ExceptionEnum.CM307); } - // 返回插入和更新的条数 - return componentService.readFileAndBulkCreate(file); + return componentService.bundleSplit(file); } /** 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/material/ComponentLibraryService.java b/base/src/main/java/com/tinyengine/it/service/material/ComponentLibraryService.java index e09d273c..71f44294 100644 --- a/base/src/main/java/com/tinyengine/it/service/material/ComponentLibraryService.java +++ b/base/src/main/java/com/tinyengine/it/service/material/ComponentLibraryService.java @@ -43,10 +43,10 @@ public interface ComponentLibraryService { /** * 根据条件查询表t_component_library信息 * - * @param material the material + * @param componentLibrary the componentLibrary * @return the list */ - List queryComponentLibraryByCondition(ComponentLibrary material); + List queryComponentLibraryByCondition(ComponentLibrary componentLibrary); /** * 根据主键id删除t_component_library数据 @@ -59,16 +59,16 @@ public interface ComponentLibraryService { /** * 根据主键id更新表t_component_library信息 * - * @param material the material + * @param componentLibrary the componentLibrary * @return the integer */ - Result updateComponentLibraryById(ComponentLibrary material); + Result updateComponentLibraryById(ComponentLibrary componentLibrary); /** * 新增表t_component_library数据 * - * @param material the material + * @param componentLibrary the componentLibrary * @return the integer */ - Result createComponentLibrary(ComponentLibrary material); + Result createComponentLibrary(ComponentLibrary componentLibrary); } 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 index c0e12fb8..62902029 100644 --- 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 @@ -65,12 +65,12 @@ public Result queryComponentLibraryById(@Param("id") Integer i /** * 根据条件查询表t_component_library数据 * - * @param material material + * @param componentLibrary componentLibrary * @return query result */ @Override - public List queryComponentLibraryByCondition(ComponentLibrary material) { - return componentLibraryMapper.queryComponentLibraryByCondition(material); + public List queryComponentLibraryByCondition(ComponentLibrary componentLibrary) { + return componentLibraryMapper.queryComponentLibraryByCondition(componentLibrary); } /** @@ -93,32 +93,32 @@ public Result deleteComponentLibraryById(@Param("id") Integer /** * 根据主键id更新表t_component_library数据 * - * @param material material + * @param componentLibrary componentLibrary * @return execute success data number */ @Override - public Result updateComponentLibraryById(ComponentLibrary material) { - int updateResult = componentLibraryMapper.updateComponentLibraryById(material); + public Result updateComponentLibraryById(ComponentLibrary componentLibrary) { + int updateResult = componentLibraryMapper.updateComponentLibraryById(componentLibrary); if(updateResult != 1){ return Result.failed(ExceptionEnum.CM008); } - Result result = this.queryComponentLibraryById(material.getId()); + Result result = this.queryComponentLibraryById(componentLibrary.getId()); return result; } /** * 新增表t_component_library数据 * - * @param material material + * @param componentLibrary componentLibrary * @return execute success data number */ @Override - public Result createComponentLibrary(ComponentLibrary material) { - int createResult = componentLibraryMapper.createComponentLibrary(material); + public Result createComponentLibrary(ComponentLibrary componentLibrary) { + int createResult = componentLibraryMapper.createComponentLibrary(componentLibrary); if(createResult != 1){ return Result.failed(ExceptionEnum.CM008); } - Result result = this.queryComponentLibraryById(material.getId()); + 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 295fa127..bf2d3602 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 @@ -142,6 +142,9 @@ public Integer createComponent(Component component) { 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); @@ -233,6 +236,12 @@ public Result bundleSplit(MultipartFile file) { componentList.add(component); } List> packages = bundleDto.getMaterials().getPackages(); + + 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); @@ -240,8 +249,6 @@ public Result bundleSplit(MultipartFile file) { componentLibrary.setFramework("Vue"); packageList.add(componentLibrary); } - BundleResultDto bundleList = new BundleResultDto(); - bundleList.setComponentList(componentList); bundleList.setPackageList(packageList); return Result.success(bundleList); } @@ -298,15 +305,22 @@ public Result bulkCreate(List componentList) { componentParam.setVersion(component.getVersion()); List queryComponent = findComponentByCondition(componentParam); // 查询组件库id - 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(); + String packageName = null; + if(null!= component.getNpm() && null != component.getNpm().get("package")){ + packageName = String.valueOf(component.getNpm().get("package")); } - component.setLibraryId(componentLibraryId); + 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()) { // 插入新记录 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/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 2b9503ad..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 @@ -55,6 +55,7 @@ void testFindAllMaterialHistory() { @Test void testFindMaterialHistoryById() { MaterialHistory mockData = new MaterialHistory(); + mockData.setId(1); when(materialHistoryMapper.queryMaterialHistoryById(1)).thenReturn(mockData); Result result = materialHistoryServiceImpl.findMaterialHistoryById(1); @@ -74,6 +75,7 @@ void testFindMaterialHistoryByCondition() { @Test void testDeleteMaterialHistoryById() { MaterialHistory param = new MaterialHistory(); + param.setId(1); when(materialHistoryMapper.deleteMaterialHistoryById(1)).thenReturn(1); when(materialHistoryMapper.queryMaterialHistoryById(1)).thenReturn(param); @@ -84,6 +86,7 @@ void testDeleteMaterialHistoryById() { @Test void testUpdateMaterialHistoryById() { MaterialHistory param = new MaterialHistory(); + param.setId(1); when(materialHistoryMapper.updateMaterialHistoryById(param)).thenReturn(1); when(materialHistoryMapper.queryMaterialHistoryById(1)).thenReturn(param); @@ -94,6 +97,7 @@ void testUpdateMaterialHistoryById() { @Test void testCreateMaterialHistory() { MaterialHistory param = new MaterialHistory(); + param.setId(1); when(materialHistoryMapper.createMaterialHistory(param)).thenReturn(1); when(materialHistoryMapper.queryMaterialHistoryById(1)).thenReturn(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 99285deb..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 @@ -56,6 +56,7 @@ void testQueryAllMaterial() { @Test void testQueryMaterialById() { Material mockData = new Material(); + mockData.setId(1); when(materialMapper.queryMaterialById(1)).thenReturn(mockData); Result result = materialServiceImpl.queryMaterialById(1); @@ -74,8 +75,9 @@ 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); Result result = materialServiceImpl.deleteMaterialById(1); @@ -85,6 +87,7 @@ void testDeleteMaterialById() { @Test void testUpdateMaterialById() { Material param = new Material(); + param.setId(1); when(materialMapper.updateMaterialById(param)).thenReturn(1); when(materialMapper.queryMaterialById(1)).thenReturn(param); @@ -95,6 +98,7 @@ void testUpdateMaterialById() { @Test void testCreateMaterial() { Material param = new Material(); + param.setId(1); when(materialMapper.createMaterial(param)).thenReturn(1); when(materialMapper.queryMaterialById(1)).thenReturn(param); From 2f31f888194a278c58b973a270706f701982cc2a Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Sun, 6 Apr 2025 23:12:05 -0700 Subject: [PATCH 38/43] feat: component library api --- .../com/tinyengine/it/service/app/impl/PageServiceImpl.java | 6 ------ .../it/service/material/impl/ComponentServiceImpl.java | 3 ++- 2 files changed, 2 insertions(+), 7 deletions(-) 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 a094e362..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 @@ -574,10 +574,7 @@ public boolean protectDefaultPage(Page page) { /** * 查询父页面 -<<<<<<< HEAD -======= * ->>>>>>> 342bb06d8974b37e0637fb5d3512f713dccf595b * @param parentId the parentId * @return parentId the parentId */ @@ -592,10 +589,7 @@ private String getParentPage(String parentId) { /** * 查询默认子页面 -<<<<<<< HEAD -======= * ->>>>>>> 342bb06d8974b37e0637fb5d3512f713dccf595b * @param parentId the parentId * @return subPageId the subPageId */ 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 bf2d3602..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 @@ -313,7 +313,8 @@ public Result bulkCreate(List componentList) { ComponentLibrary componentLibrary = new ComponentLibrary(); componentLibrary.setPackageName(String.valueOf(component.getNpm().get("package"))); componentLibrary.setVersion(component.getVersion()); - List componentLibraryList = componentLibraryMapper.queryComponentLibraryByCondition(componentLibrary); + List componentLibraryList = componentLibraryMapper + .queryComponentLibraryByCondition(componentLibrary); Integer componentLibraryId = null; if (!componentLibraryList.isEmpty()) { componentLibraryId = componentLibraryList.get(0).getId(); From 9ee1ef1148f11797ec420b6640a4b0a8e7b7b60f Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Sun, 6 Apr 2025 23:20:13 -0700 Subject: [PATCH 39/43] feat: component library api --- .../java/com/tinyengine/it/controller/ComponentController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 06f29307..fda2a651 100644 --- a/base/src/main/java/com/tinyengine/it/controller/ComponentController.java +++ b/base/src/main/java/com/tinyengine/it/controller/ComponentController.java @@ -66,7 +66,7 @@ public class ComponentController { content = @Content(mediaType = "application/json", schema = @Schema())), @ApiResponse(responseCode = "400", description = "请求失败")}) @SystemControllerLog(description = "上传bunled.json文件创建组件") - @PostMapping("/component/bundle/createComponent") + @PostMapping("/component/bundle/create") public Result bundleCreateComponent(@RequestParam MultipartFile file) { if (file.isEmpty()) { return Result.failed(ExceptionEnum.CM307); From 59c6ddcb068922bceabb717bcc86ebddf34ff5a7 Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Sun, 6 Apr 2025 23:34:51 -0700 Subject: [PATCH 40/43] feat: component library api --- .../com/tinyengine/it/controller/ComponentController.java | 4 +++- .../tinyengine/it/controller/ComponentLibraryController.java | 3 ++- .../it/service/material/impl/ComponentLibraryServiceImpl.java | 3 --- .../it/service/material/impl/MaterialHistoryServiceImpl.java | 3 --- .../it/service/material/impl/MaterialServiceImpl.java | 3 --- 5 files changed, 5 insertions(+), 11 deletions(-) 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 fda2a651..1248f3b9 100644 --- a/base/src/main/java/com/tinyengine/it/controller/ComponentController.java +++ b/base/src/main/java/com/tinyengine/it/controller/ComponentController.java @@ -31,11 +31,13 @@ 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; /** @@ -108,7 +110,7 @@ public Result bundleSplit(@RequestParam MultipartFile file) { @ApiResponse(responseCode = "400", description = "请求失败")}) @SystemControllerLog(description = "批量创建自定义组件") @PostMapping("/component/batch/create") - public Result createCustComponent(@RequestParam CustComponentDto custComponentDto) { + public Result createCustComponent(@Valid @RequestBody CustComponentDto custComponentDto) { // 返回插入和更新的条数 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 index 64adb5c3..eabc5237 100644 --- a/base/src/main/java/com/tinyengine/it/controller/ComponentLibraryController.java +++ b/base/src/main/java/com/tinyengine/it/controller/ComponentLibraryController.java @@ -24,6 +24,7 @@ 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; @@ -131,7 +132,7 @@ public Result updateComponentLibrary(@PathVariable Integer id, @ApiResponse(responseCode = "400", description = "请求失败")} ) @SystemControllerLog(description = "删除ComponentLibrary信息") - @GetMapping("/component-library/delete/{id}") + @DeleteMapping("/component-library/delete/{id}") public Result deleteComponentLibrary(@PathVariable Integer id) { return componentLibraryService.deleteComponentLibraryById(id); } 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 index 62902029..3af1449e 100644 --- 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 @@ -56,9 +56,6 @@ public List queryAllComponentLibrary() { @Override public Result queryComponentLibraryById(@Param("id") Integer id) { ComponentLibrary material = componentLibraryMapper.queryComponentLibraryById(id); - if(null == material.getId()){ - return Result.failed(ExceptionEnum.CM009); - } return Result.success(material); } 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 41e281d2..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 @@ -60,9 +60,6 @@ public List findAllMaterialHistory() { @Override public Result findMaterialHistoryById(@Param("id") Integer id) { MaterialHistory materialHistory = materialHistoryMapper.queryMaterialHistoryById(id); - if (null == materialHistory.getId()) { - return Result.failed(ExceptionEnum.CM009); - } return Result.success(materialHistory); } 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 2750e61a..ef8638f2 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 @@ -57,9 +57,6 @@ public List queryAllMaterial() { @Override public Result queryMaterialById(@Param("id") Integer id) { Material material = materialMapper.queryMaterialById(id); - if(null == material.getId()){ - return Result.failed(ExceptionEnum.CM009); - } return Result.success(material); } From 8373484a55cb47d9d52df753603b5784bf7448e9 Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Sun, 6 Apr 2025 23:38:35 -0700 Subject: [PATCH 41/43] feat: component library api --- .../java/com/tinyengine/it/controller/MaterialController.java | 3 ++- .../it/service/material/impl/MaterialServiceImpl.java | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/base/src/main/java/com/tinyengine/it/controller/MaterialController.java b/base/src/main/java/com/tinyengine/it/controller/MaterialController.java index 6c4f91bf..374c9e98 100644 --- a/base/src/main/java/com/tinyengine/it/controller/MaterialController.java +++ b/base/src/main/java/com/tinyengine/it/controller/MaterialController.java @@ -24,6 +24,7 @@ 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; @@ -131,7 +132,7 @@ public Result updateMaterial(@PathVariable Integer id, @RequestBody Ma @ApiResponse(responseCode = "400", description = "请求失败")} ) @SystemControllerLog(description = "删除Material信息") - @GetMapping("/material/delete/{id}") + @DeleteMapping("/material/delete/{id}") public Result deleteMaterial(@PathVariable Integer id) { return materialService.deleteMaterialById(id); } 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 ef8638f2..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 @@ -16,7 +16,6 @@ import com.tinyengine.it.common.exception.ExceptionEnum; import com.tinyengine.it.mapper.MaterialMapper; import com.tinyengine.it.model.entity.Material; -import com.tinyengine.it.model.entity.MaterialHistory; import com.tinyengine.it.service.material.MaterialService; import lombok.extern.slf4j.Slf4j; From fb123c693d7f5e1828e17f5c08f6fa4d71a40022 Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Sun, 6 Apr 2025 23:47:55 -0700 Subject: [PATCH 42/43] feat: component library api --- .../com/tinyengine/it/controller/ComponentController.java | 2 +- .../service/material/impl/ComponentLibraryServiceImpl.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) 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 1248f3b9..3b7a6feb 100644 --- a/base/src/main/java/com/tinyengine/it/controller/ComponentController.java +++ b/base/src/main/java/com/tinyengine/it/controller/ComponentController.java @@ -104,7 +104,7 @@ public Result bundleSplit(@RequestParam MultipartFile file) { * @return result */ @Operation(summary = "批量创建自定义组件", description = "批量创建自定义组件", parameters = { - @Parameter(name = "file", description = "文件参数对象")}, responses = { + @Parameter(name = "custComponentDto", description = "自定义组件对象")}, responses = { @ApiResponse(responseCode = "200", description = "返回信息", content = @Content(mediaType = "application/json", schema = @Schema())), @ApiResponse(responseCode = "400", description = "请求失败")}) 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 index 3af1449e..c63f967f 100644 --- 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 @@ -78,11 +78,14 @@ public List queryComponentLibraryByCondition(ComponentLibrary */ @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); } - Result result = this.queryComponentLibraryById(id); return result; } From 0875559eaa0af38825c287b61849346ed65f4359 Mon Sep 17 00:00:00 2001 From: lu17301156525 Date: Sun, 6 Apr 2025 23:50:54 -0700 Subject: [PATCH 43/43] feat: component library api --- base/src/main/resources/mappers/ComponentLibraryMapper.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/src/main/resources/mappers/ComponentLibraryMapper.xml b/base/src/main/resources/mappers/ComponentLibraryMapper.xml index 7b565887..f6574ddf 100644 --- a/base/src/main/resources/mappers/ComponentLibraryMapper.xml +++ b/base/src/main/resources/mappers/ComponentLibraryMapper.xml @@ -50,7 +50,7 @@ AND `public` = #{publicStatus} - AND is_started = #{publicStatus} + AND is_started = #{isStarted} AND is_official = #{isOfficial}