|
13 | 13 | package com.tinyengine.it.service.app.impl;
|
14 | 14 |
|
15 | 15 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
| 16 | +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
16 | 17 | import com.tinyengine.it.common.base.Result;
|
17 | 18 | import com.tinyengine.it.common.enums.Enums;
|
18 | 19 | import com.tinyengine.it.common.exception.ExceptionEnum;
|
@@ -190,9 +191,6 @@ public Result<Page> delPage(Integer id) {
|
190 | 191 | // 如果是文件夹,调folder service的处理逻辑
|
191 | 192 | return del(id);
|
192 | 193 | }
|
193 |
| - // 保护默认页面 |
194 |
| - protectDefaultPage(pages, id); |
195 |
| - |
196 | 194 | // 删除
|
197 | 195 | Page pageResult = pageMapper.queryPageById(id);
|
198 | 196 | int result = pageMapper.deletePageById(id);
|
@@ -317,9 +315,11 @@ public Result<Page> updatePage(Page page) {
|
317 | 315 | return Result.failed("isHome parameter error");
|
318 | 316 | }
|
319 | 317 | 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 | + } |
323 | 323 | // 针对参数中isHome的传值进行isHome字段的判定
|
324 | 324 | if (page.getIsHome()) {
|
325 | 325 | setAppHomePage(appId, id);
|
@@ -531,18 +531,74 @@ public boolean iCanDoIt(User occupier, User user) {
|
531 | 531 |
|
532 | 532 | /**
|
533 | 533 | * 保护默认页面
|
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 | + } |
544 | 598 | }
|
545 | 599 | }
|
| 600 | + |
| 601 | + return 0; // 如果没有找到符合条件的子页面,返回null |
546 | 602 | }
|
547 | 603 |
|
548 | 604 | /**
|
|
0 commit comments