|
1 | 1 | /** |
2 | 2 | * Copyright (c) 2023 - present TinyEngine Authors. |
3 | 3 | * Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd. |
4 | | - * |
| 4 | + * <p> |
5 | 5 | * Use of this source code is governed by an MIT-style license. |
6 | | - * |
| 6 | + * <p> |
7 | 7 | * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, |
8 | 8 | * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR |
9 | 9 | * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS. |
10 | | - * |
11 | 10 | */ |
12 | 11 |
|
13 | 12 | package com.tinyengine.it.service.app.impl; |
14 | 13 |
|
15 | 14 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| 15 | +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
16 | 16 | import com.tinyengine.it.common.base.Result; |
17 | 17 | import com.tinyengine.it.common.enums.Enums; |
18 | 18 | import com.tinyengine.it.common.exception.ExceptionEnum; |
@@ -190,9 +190,6 @@ public Result<Page> delPage(Integer id) { |
190 | 190 | // 如果是文件夹,调folder service的处理逻辑 |
191 | 191 | return del(id); |
192 | 192 | } |
193 | | - // 保护默认页面 |
194 | | - protectDefaultPage(pages, id); |
195 | | - |
196 | 193 | // 删除 |
197 | 194 | Page pageResult = pageMapper.queryPageById(id); |
198 | 195 | int result = pageMapper.deletePageById(id); |
@@ -317,9 +314,11 @@ public Result<Page> updatePage(Page page) { |
317 | 314 | return Result.failed("isHome parameter error"); |
318 | 315 | } |
319 | 316 | 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 | + } |
323 | 322 | // 针对参数中isHome的传值进行isHome字段的判定 |
324 | 323 | if (page.getIsHome()) { |
325 | 324 | setAppHomePage(appId, id); |
@@ -531,18 +530,74 @@ public boolean iCanDoIt(User occupier, User user) { |
531 | 530 |
|
532 | 531 | /** |
533 | 532 | * 保护默认页面 |
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 | + } |
544 | 597 | } |
545 | 598 | } |
| 599 | + |
| 600 | + return 0; // 如果没有找到符合条件的子页面,返回null |
546 | 601 | } |
547 | 602 |
|
548 | 603 | /** |
|
0 commit comments