Skip to content

Commit 2de54a8

Browse files
authored
fix: page update api (#195)
1 parent 850b804 commit 2de54a8

File tree

6 files changed

+118
-78
lines changed

6 files changed

+118
-78
lines changed

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

+1-1
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

+72-16
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package com.tinyengine.it.service.app.impl;
1414

1515
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
16+
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
1617
import com.tinyengine.it.common.base.Result;
1718
import com.tinyengine.it.common.enums.Enums;
1819
import com.tinyengine.it.common.exception.ExceptionEnum;
@@ -190,9 +191,6 @@ public Result<Page> delPage(Integer id) {
190191
// 如果是文件夹,调folder service的处理逻辑
191192
return del(id);
192193
}
193-
// 保护默认页面
194-
protectDefaultPage(pages, id);
195-
196194
// 删除
197195
Page pageResult = pageMapper.queryPageById(id);
198196
int result = pageMapper.deletePageById(id);
@@ -317,9 +315,11 @@ public Result<Page> updatePage(Page page) {
317315
return Result.failed("isHome parameter error");
318316
}
319317
int appId = pageTemp.getApp();
320-
// 保护默认页面
321-
protectDefaultPage(pageTemp, appId);
322-
318+
// 默认页面
319+
boolean isUpdate = protectDefaultPage(pageTemp);
320+
if (!isUpdate) {
321+
return Result.failed(ExceptionEnum.CM301);
322+
}
323323
// 针对参数中isHome的传值进行isHome字段的判定
324324
if (page.getIsHome()) {
325325
setAppHomePage(appId, id);
@@ -531,18 +531,74 @@ public boolean iCanDoIt(User occupier, User user) {
531531

532532
/**
533533
* 保护默认页面
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());
534+
* @param page the pages
535+
* @return boolean
536+
*/
537+
public boolean protectDefaultPage(Page page) {
538+
String id = page.getParentId();
539+
if("0".equals(id)){
540+
return true;
541+
}
542+
String parentId = this.getParentPage(id);
543+
int subPageId = this.getSubPage(parentId);
544+
if (subPageId == 0) {
545+
return true;
546+
}
547+
548+
UpdateWrapper<Page> updateWrapper = new UpdateWrapper<>();
549+
updateWrapper.eq("id", subPageId)
550+
.set("is_default", false);
551+
int result = pageMapper.update(null, updateWrapper);
552+
553+
if (result < 1) {
554+
return false;
555+
}
556+
return true;
557+
}
558+
559+
/**
560+
* 查询父页面
561+
* @param parentId the parentId
562+
* @return parentId the parentId
563+
*/
564+
private String getParentPage(String parentId) {
565+
566+
Page page = pageMapper.queryPageById(Integer.parseInt(parentId));
567+
if (page.getIsPage() || "0".equals(page.getParentId())) {
568+
return parentId;
569+
}
570+
return this.getParentPage(page.getParentId());
571+
}
572+
573+
/**
574+
* 查询默认子页面
575+
* @param parentId the parentId
576+
* @return subPageId the subPageId
577+
*/
578+
private int getSubPage(String parentId) {
579+
// 基础的检查
580+
if ("0".equals(parentId)) {
581+
return 0; // 0 表示没有父页面
582+
}
583+
// 查找子页面列表
584+
Page pageParam = new Page();
585+
pageParam.setParentId(parentId);
586+
List<Page> pageList = pageMapper.queryPageByCondition(pageParam);
587+
588+
// 遍历页面列表,查找默认的子页面
589+
for (Page page : pageList) {
590+
if (page.getIsPage() && page.getIsDefault()) {
591+
return page.getId(); // 找到默认子页面,返回其ID
592+
} else if (!page.getIsPage()) {
593+
// 如果不是页面,递归查找子页面
594+
int subPageId = getSubPage(String.valueOf(page.getId()));
595+
if (subPageId > 0) {
596+
return subPageId; // 如果找到了子页面ID,返回
597+
}
544598
}
545599
}
600+
601+
return 0; // 如果没有找到符合条件的子页面,返回null
546602
}
547603

548604
/**

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

+1-2
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

+42-43
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

-14
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

+2-2
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)