Skip to content

Commit 7f17fb7

Browse files
committed
fix: page update api
1 parent 1fa284b commit 7f17fb7

File tree

6 files changed

+120
-81
lines changed

6 files changed

+120
-81
lines changed

base/src/main/java/com/tinyengine/it/common/exception/ExceptionEnum.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public enum ExceptionEnum implements IBaseError {
148148
/**
149149
* Cm 301 exception enum.
150150
*/
151-
CM301("CM301", "默认页面不能删除和修改"),
151+
CM301("CM301", "默认页面修改失败"),
152152
/**
153153
* Cm 302 exception enum.
154154
*/

base/src/main/java/com/tinyengine/it/service/app/impl/PageServiceImpl.java

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/**
22
* Copyright (c) 2023 - present TinyEngine Authors.
33
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
4-
*
4+
* <p>
55
* Use of this source code is governed by an MIT-style license.
6-
*
6+
* <p>
77
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
88
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
99
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10-
*
1110
*/
1211

1312
package com.tinyengine.it.service.app.impl;
1413

1514
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
15+
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
1616
import com.tinyengine.it.common.base.Result;
1717
import com.tinyengine.it.common.enums.Enums;
1818
import com.tinyengine.it.common.exception.ExceptionEnum;
@@ -190,9 +190,6 @@ public Result<Page> delPage(Integer id) {
190190
// 如果是文件夹,调folder service的处理逻辑
191191
return del(id);
192192
}
193-
// 保护默认页面
194-
protectDefaultPage(pages, id);
195-
196193
// 删除
197194
Page pageResult = pageMapper.queryPageById(id);
198195
int result = pageMapper.deletePageById(id);
@@ -317,9 +314,11 @@ public Result<Page> updatePage(Page page) {
317314
return Result.failed("isHome parameter error");
318315
}
319316
int appId = pageTemp.getApp();
320-
// 保护默认页面
321-
protectDefaultPage(pageTemp, appId);
322-
317+
// 默认页面
318+
boolean isUpdate = protectDefaultPage(pageTemp);
319+
if (!isUpdate) {
320+
return Result.failed(ExceptionEnum.CM301);
321+
}
323322
// 针对参数中isHome的传值进行isHome字段的判定
324323
if (page.getIsHome()) {
325324
setAppHomePage(appId, id);
@@ -531,18 +530,74 @@ public boolean iCanDoIt(User occupier, User user) {
531530

532531
/**
533532
* 保护默认页面
534-
*
535-
* @param pages the pages
536-
* @param id the id
537-
*/
538-
public void protectDefaultPage(Page pages, Integer id) {
539-
if (pages.getIsDefault()) {
540-
// 查询是否是模板应用,不是的话不能删除或修改
541-
App app = appMapper.queryAppById(id);
542-
if (app.getTemplateType() == null) {
543-
Result.failed(ExceptionEnum.CM310.getResultCode());
533+
* @param page the pages
534+
* @return boolean
535+
*/
536+
public boolean protectDefaultPage(Page page) {
537+
String id = page.getParentId();
538+
if("0".equals(id)){
539+
return true;
540+
}
541+
String parentId = this.getParentPage(id);
542+
int subPageId = this.getSubPage(parentId);
543+
if (subPageId == 0) {
544+
return true;
545+
}
546+
547+
UpdateWrapper<Page> updateWrapper = new UpdateWrapper<>();
548+
updateWrapper.eq("id", subPageId)
549+
.set("is_default", false);
550+
int result = pageMapper.update(null, updateWrapper);
551+
552+
if (result < 1) {
553+
return false;
554+
}
555+
return true;
556+
}
557+
558+
/**
559+
* 查询父页面
560+
* @param parentId the parentId
561+
* @return parentId the parentId
562+
*/
563+
private String getParentPage(String parentId) {
564+
565+
Page page = pageMapper.queryPageById(Integer.parseInt(parentId));
566+
if (page.getIsPage() || "0".equals(page.getParentId())) {
567+
return parentId;
568+
}
569+
return this.getParentPage(page.getParentId());
570+
}
571+
572+
/**
573+
* 查询默认子页面
574+
* @param parentId the parentId
575+
* @return subPageId the subPageId
576+
*/
577+
private int getSubPage(String parentId) {
578+
// 基础的检查
579+
if ("0".equals(parentId)) {
580+
return 0; // 0 表示没有父页面
581+
}
582+
// 查找子页面列表
583+
Page pageParam = new Page();
584+
pageParam.setParentId(parentId);
585+
List<Page> pageList = pageMapper.queryPageByCondition(pageParam);
586+
587+
// 遍历页面列表,查找默认的子页面
588+
for (Page page : pageList) {
589+
if (page.getIsPage() && page.getIsDefault()) {
590+
return page.getId(); // 找到默认子页面,返回其ID
591+
} else if (!page.getIsPage()) {
592+
// 如果不是页面,递归查找子页面
593+
int subPageId = getSubPage(String.valueOf(page.getId()));
594+
if (subPageId > 0) {
595+
return subPageId; // 如果找到了子页面ID,返回
596+
}
544597
}
545598
}
599+
600+
return 0; // 如果没有找到符合条件的子页面,返回null
546601
}
547602

548603
/**

base/src/main/resources/mappers/BlockGroupMapper.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,7 @@
356356
<set>
357357
<include refid="BlockGroupSetColumns"/>
358358
</set>
359-
WHERE
360-
id=#{id}
359+
WHERE id = #{id}
361360
</update>
362361

363362
<!-- 新增表t_block_group数据 -->

base/src/main/resources/mappers/PageMapper.xml

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -305,55 +305,54 @@
305305
<set>
306306
<include refid="PageSetColumns"/>
307307
</set>
308-
WHERE
309-
id=#{id}
308+
WHERE id = #{id}
310309
</update>
311310

312311
<!-- 新增表t_page数据 -->
313312
<insert id="createPage" useGeneratedKeys="true" keyProperty="id"
314313
parameterType="com.tinyengine.it.model.entity.Page">
315314
INSERT INTO t_page ( id
316-
, name
317-
, app_id
318-
, route
319-
, page_content
320-
, is_body
321-
, parent_id
322-
, `group`
323-
, `depth`
324-
, is_page
325-
, occupier_by
326-
, is_default
327-
, content_blocks
328-
, latest_version
329-
, latest_history_id
330-
, created_by
331-
, last_updated_by
332-
, created_time
333-
, last_updated_time
334-
, tenant_id, renter_id
335-
, site_id)
315+
, name
316+
, app_id
317+
, route
318+
, page_content
319+
, is_body
320+
, parent_id
321+
, `group`
322+
, `depth`
323+
, is_page
324+
, occupier_by
325+
, is_default
326+
, content_blocks
327+
, latest_version
328+
, latest_history_id
329+
, created_by
330+
, last_updated_by
331+
, created_time
332+
, last_updated_time
333+
, tenant_id, renter_id
334+
, site_id)
336335
VALUES ( #{id}
337-
, #{name}
338-
, #{app}
339-
, #{route}
340-
, #{pageContent}
341-
, #{isBody}
342-
, #{parentId}
343-
, #{group}
344-
, #{depth}
345-
, #{isPage}
346-
, #{occupierBy}
347-
, #{isDefault}
348-
, #{contentBlocks}
349-
, #{latestVersion}
350-
, #{latestHistoryId}
351-
, #{createdBy}
352-
, #{lastUpdatedBy}
353-
, #{createdTime}
354-
, #{lastUpdatedTime}
355-
, #{tenantId}
356-
, #{renterId}
357-
, #{siteId})
336+
, #{name}
337+
, #{app}
338+
, #{route}
339+
, #{pageContent}
340+
, #{isBody}
341+
, #{parentId}
342+
, #{group}
343+
, #{depth}
344+
, #{isPage}
345+
, #{occupierBy}
346+
, #{isDefault}
347+
, #{contentBlocks}
348+
, #{latestVersion}
349+
, #{latestHistoryId}
350+
, #{createdBy}
351+
, #{lastUpdatedBy}
352+
, #{createdTime}
353+
, #{lastUpdatedTime}
354+
, #{tenantId}
355+
, #{renterId}
356+
, #{siteId})
358357
</insert>
359358
</mapper>

base/src/test/java/com/tinyengine/it/gateway/ai/AiChatClientTest.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,5 @@ void testExecuteChatRequest() {
9898
Map<String, Object> returnData = aiChatClient.executeChatRequest(param);
9999
Assertions.assertNull(returnData.get("data"));
100100
}
101-
102-
@Test
103-
void testInvalidTokenExecuteChatRequest() {
104-
HashMap<String, String> foundationModel = new HashMap<>();
105-
foundationModel.put("model", "gpt-3.5-turbo");
106-
foundationModel.put("token","你好");
107-
ArrayList<AiMessages> messages = new ArrayList<>();
108-
AiMessages aiMessages = new AiMessages();
109-
aiMessages.setContent("dddd编码时遵从以下几条要求aaa");
110-
messages.add(aiMessages);
111-
AiParam param = new AiParam(foundationModel,Arrays.asList(aiMessages));
112-
Map<String, Object> returnData = aiChatClient.executeChatRequest(param);
113-
Assertions.assertEquals("Invalid token format",returnData.get("error_message"));
114-
}
115101
}
116102

base/src/test/java/com/tinyengine/it/service/app/impl/PageServiceImplTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,14 @@ void testUpdatePage() {
202202
int pageId = 123;
203203
param.setId(pageId);
204204
param.setIsHome(false);
205-
param.setParentId("1");
205+
param.setParentId("0");
206206
param.setOccupierBy("555");
207207

208208
Page queryPage = new Page();
209209
queryPage.setApp(222);
210210
queryPage.setIsPage(false);
211211
queryPage.setIsHome(false);
212-
queryPage.setParentId("1");
212+
queryPage.setParentId("0");
213213
queryPage.setIsDefault(false);
214214
when(pageMapper.queryPageById(pageId)).thenReturn(queryPage);
215215

0 commit comments

Comments
 (0)