diff --git a/base/src/main/java/com/tinyengine/it/common/exception/ExceptionEnum.java b/base/src/main/java/com/tinyengine/it/common/exception/ExceptionEnum.java index c9abc0d7..12a791a4 100644 --- a/base/src/main/java/com/tinyengine/it/common/exception/ExceptionEnum.java +++ b/base/src/main/java/com/tinyengine/it/common/exception/ExceptionEnum.java @@ -148,7 +148,7 @@ public enum ExceptionEnum implements IBaseError { /** * Cm 301 exception enum. */ - CM301("CM301", "默认页面不能删除和修改"), + CM301("CM301", "默认页面修改失败"), /** * Cm 302 exception enum. */ 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 7cc60cc8..19b62506 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 @@ -13,6 +13,7 @@ package com.tinyengine.it.service.app.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.tinyengine.it.common.base.Result; import com.tinyengine.it.common.enums.Enums; import com.tinyengine.it.common.exception.ExceptionEnum; @@ -190,9 +191,6 @@ public Result delPage(Integer id) { // 如果是文件夹,调folder service的处理逻辑 return del(id); } - // 保护默认页面 - protectDefaultPage(pages, id); - // 删除 Page pageResult = pageMapper.queryPageById(id); int result = pageMapper.deletePageById(id); @@ -317,9 +315,11 @@ public Result updatePage(Page page) { return Result.failed("isHome parameter error"); } int appId = pageTemp.getApp(); - // 保护默认页面 - protectDefaultPage(pageTemp, appId); - + // 默认页面 + boolean isUpdate = protectDefaultPage(pageTemp); + if (!isUpdate) { + return Result.failed(ExceptionEnum.CM301); + } // 针对参数中isHome的传值进行isHome字段的判定 if (page.getIsHome()) { setAppHomePage(appId, id); @@ -531,18 +531,74 @@ public boolean iCanDoIt(User occupier, User user) { /** * 保护默认页面 - * - * @param pages the pages - * @param id the id - */ - public void protectDefaultPage(Page pages, Integer id) { - if (pages.getIsDefault()) { - // 查询是否是模板应用,不是的话不能删除或修改 - App app = appMapper.queryAppById(id); - if (app.getTemplateType() == null) { - Result.failed(ExceptionEnum.CM310.getResultCode()); + * @param page the pages + * @return boolean + */ + public boolean protectDefaultPage(Page page) { + String id = page.getParentId(); + if("0".equals(id)){ + return true; + } + String parentId = this.getParentPage(id); + int subPageId = this.getSubPage(parentId); + if (subPageId == 0) { + return true; + } + + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.eq("id", subPageId) + .set("is_default", false); + int result = pageMapper.update(null, updateWrapper); + + if (result < 1) { + return false; + } + return true; + } + + /** + * 查询父页面 + * @param parentId the parentId + * @return parentId the parentId + */ + private String getParentPage(String parentId) { + + Page page = pageMapper.queryPageById(Integer.parseInt(parentId)); + if (page.getIsPage() || "0".equals(page.getParentId())) { + return parentId; + } + return this.getParentPage(page.getParentId()); + } + + /** + * 查询默认子页面 + * @param parentId the parentId + * @return subPageId the subPageId + */ + private int getSubPage(String parentId) { + // 基础的检查 + if ("0".equals(parentId)) { + return 0; // 0 表示没有父页面 + } + // 查找子页面列表 + Page pageParam = new Page(); + pageParam.setParentId(parentId); + List pageList = pageMapper.queryPageByCondition(pageParam); + + // 遍历页面列表,查找默认的子页面 + for (Page page : pageList) { + if (page.getIsPage() && page.getIsDefault()) { + return page.getId(); // 找到默认子页面,返回其ID + } else if (!page.getIsPage()) { + // 如果不是页面,递归查找子页面 + int subPageId = getSubPage(String.valueOf(page.getId())); + if (subPageId > 0) { + return subPageId; // 如果找到了子页面ID,返回 + } } } + + return 0; // 如果没有找到符合条件的子页面,返回null } /** diff --git a/base/src/main/resources/mappers/BlockGroupMapper.xml b/base/src/main/resources/mappers/BlockGroupMapper.xml index 9cca31c0..2823700f 100644 --- a/base/src/main/resources/mappers/BlockGroupMapper.xml +++ b/base/src/main/resources/mappers/BlockGroupMapper.xml @@ -356,8 +356,7 @@ - WHERE - id=#{id} + WHERE id = #{id} diff --git a/base/src/main/resources/mappers/PageMapper.xml b/base/src/main/resources/mappers/PageMapper.xml index ffd8fded..b79a7a29 100644 --- a/base/src/main/resources/mappers/PageMapper.xml +++ b/base/src/main/resources/mappers/PageMapper.xml @@ -305,55 +305,54 @@ - WHERE - id=#{id} + WHERE id = #{id} INSERT INTO t_page ( id - , name - , app_id - , route - , page_content - , is_body - , parent_id - , `group` - , `depth` - , is_page - , occupier_by - , is_default - , content_blocks - , latest_version - , latest_history_id - , created_by - , last_updated_by - , created_time - , last_updated_time - , tenant_id, renter_id - , site_id) + , name + , app_id + , route + , page_content + , is_body + , parent_id + , `group` + , `depth` + , is_page + , occupier_by + , is_default + , content_blocks + , latest_version + , latest_history_id + , created_by + , last_updated_by + , created_time + , last_updated_time + , tenant_id, renter_id + , site_id) VALUES ( #{id} - , #{name} - , #{app} - , #{route} - , #{pageContent} - , #{isBody} - , #{parentId} - , #{group} - , #{depth} - , #{isPage} - , #{occupierBy} - , #{isDefault} - , #{contentBlocks} - , #{latestVersion} - , #{latestHistoryId} - , #{createdBy} - , #{lastUpdatedBy} - , #{createdTime} - , #{lastUpdatedTime} - , #{tenantId} - , #{renterId} - , #{siteId}) + , #{name} + , #{app} + , #{route} + , #{pageContent} + , #{isBody} + , #{parentId} + , #{group} + , #{depth} + , #{isPage} + , #{occupierBy} + , #{isDefault} + , #{contentBlocks} + , #{latestVersion} + , #{latestHistoryId} + , #{createdBy} + , #{lastUpdatedBy} + , #{createdTime} + , #{lastUpdatedTime} + , #{tenantId} + , #{renterId} + , #{siteId}) diff --git a/base/src/test/java/com/tinyengine/it/gateway/ai/AiChatClientTest.java b/base/src/test/java/com/tinyengine/it/gateway/ai/AiChatClientTest.java index 3f0c71fb..a59e7d12 100644 --- a/base/src/test/java/com/tinyengine/it/gateway/ai/AiChatClientTest.java +++ b/base/src/test/java/com/tinyengine/it/gateway/ai/AiChatClientTest.java @@ -98,19 +98,5 @@ void testExecuteChatRequest() { Map returnData = aiChatClient.executeChatRequest(param); Assertions.assertNull(returnData.get("data")); } - - @Test - void testInvalidTokenExecuteChatRequest() { - HashMap foundationModel = new HashMap<>(); - foundationModel.put("model", "gpt-3.5-turbo"); - foundationModel.put("token","你好"); - ArrayList messages = new ArrayList<>(); - AiMessages aiMessages = new AiMessages(); - aiMessages.setContent("dddd编码时遵从以下几条要求aaa"); - messages.add(aiMessages); - AiParam param = new AiParam(foundationModel,Arrays.asList(aiMessages)); - Map returnData = aiChatClient.executeChatRequest(param); - Assertions.assertEquals("Invalid token format",returnData.get("error_message")); - } } diff --git a/base/src/test/java/com/tinyengine/it/service/app/impl/PageServiceImplTest.java b/base/src/test/java/com/tinyengine/it/service/app/impl/PageServiceImplTest.java index 25a09d3d..2d98e7ff 100644 --- a/base/src/test/java/com/tinyengine/it/service/app/impl/PageServiceImplTest.java +++ b/base/src/test/java/com/tinyengine/it/service/app/impl/PageServiceImplTest.java @@ -202,14 +202,14 @@ void testUpdatePage() { int pageId = 123; param.setId(pageId); param.setIsHome(false); - param.setParentId("1"); + param.setParentId("0"); param.setOccupierBy("555"); Page queryPage = new Page(); queryPage.setApp(222); queryPage.setIsPage(false); queryPage.setIsHome(false); - queryPage.setParentId("1"); + queryPage.setParentId("0"); queryPage.setIsDefault(false); when(pageMapper.queryPageById(pageId)).thenReturn(queryPage);