From b1e05e03349ca08258ea68a72d424802923c5a14 Mon Sep 17 00:00:00 2001 From: FBODC Date: Tue, 22 Apr 2025 16:59:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=83=E7=B4=A0=E5=BA=93=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=A2=9E=E5=88=A0=E6=94=B9=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/controller/UiElementController.java | 110 ++++++++++++++ .../java/com/test/test/domain/UiElement.java | 136 ++++++++++++++++++ .../com/test/test/domain/qo/UiElementQO.java | 30 ++++ .../com/test/test/mapper/TestGroupMapper.java | 5 + .../com/test/test/mapper/UiElementMapper.java | 78 ++++++++++ .../test/test/service/ITestGroupService.java | 14 ++ .../test/test/service/IUiElementService.java | 72 ++++++++++ .../service/impl/TestGroupServiceImpl.java | 78 ++++++++++ .../service/impl/UiElementServiceImpl.java | 130 +++++++++++++++++ .../resources/mapper/test/TestGroupMapper.xml | 7 + .../resources/mapper/test/UiElementMapper.xml | 123 ++++++++++++++++ 11 files changed, 783 insertions(+) create mode 100644 test-test/src/main/java/com/test/test/controller/UiElementController.java create mode 100644 test-test/src/main/java/com/test/test/domain/UiElement.java create mode 100644 test-test/src/main/java/com/test/test/domain/qo/UiElementQO.java create mode 100644 test-test/src/main/java/com/test/test/mapper/UiElementMapper.java create mode 100644 test-test/src/main/java/com/test/test/service/IUiElementService.java create mode 100644 test-test/src/main/java/com/test/test/service/impl/UiElementServiceImpl.java create mode 100644 test-test/src/main/resources/mapper/test/UiElementMapper.xml diff --git a/test-test/src/main/java/com/test/test/controller/UiElementController.java b/test-test/src/main/java/com/test/test/controller/UiElementController.java new file mode 100644 index 0000000..0ea414a --- /dev/null +++ b/test-test/src/main/java/com/test/test/controller/UiElementController.java @@ -0,0 +1,110 @@ +package com.test.test.controller; + +import java.util.List; + +import com.test.test.domain.UiElement; +import com.test.test.domain.qo.UiElementQO; +import com.test.test.service.IUiElementService; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.test.common.annotation.Log; +import com.test.common.core.controller.BaseController; +import com.test.common.core.domain.AjaxResult; +import com.test.common.enums.BusinessType; +import com.test.common.utils.poi.ExcelUtil; +import com.test.common.core.page.TableDataInfo; + +/** + * ui元素Controller + * + * @author test + * @date 2025-04-22 + */ +@RestController +@RequestMapping("/test/element") +public class UiElementController extends BaseController +{ + @Autowired + private IUiElementService uiElementService; + + /** + * 查询ui元素列表 + */ +// @PreAuthorize("@ss.hasPermi('system:element:list')") + @GetMapping("/list") + public TableDataInfo list(UiElementQO uiElement) + { + startPage(); + List list = uiElementService.selectUiElementListNew(uiElement); + return getDataTable(list); + } + + + + /** + * 获取ui元素详细信息 + */ +// @PreAuthorize("@ss.hasPermi('system:element:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(uiElementService.selectUiElementById(id)); + } + + /** + * 新增ui元素 + */ +// @PreAuthorize("@ss.hasPermi('system:element:add')") + @Log(title = "ui元素", businessType = BusinessType.INSERT) + @PostMapping("/add") + public AjaxResult add(@RequestBody UiElement uiElement) + { + return toAjax(uiElementService.insertUiElement(uiElement)); + } + + /** + * 修改ui元素 + */ +// @PreAuthorize("@ss.hasPermi('system:element:edit')") + @Log(title = "ui元素", businessType = BusinessType.UPDATE) + @PutMapping("/update") + public AjaxResult edit(@RequestBody UiElement uiElement) + { + return toAjax(uiElementService.updateUiElement(uiElement)); + } + + /** + * 删除ui元素 + */ +// @PreAuthorize("@ss.hasPermi('system:element:remove')") + @Log(title = "ui元素", businessType = BusinessType.UPDATE) + @PutMapping("delete/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(uiElementService.deleteUiElementByIds(ids)); + } + + + + // /** +// * 导出ui元素列表 +// */ +// @PreAuthorize("@ss.hasPermi('system:element:export')") +// @Log(title = "ui元素", businessType = BusinessType.EXPORT) +// @PostMapping("/export") +// public void export(HttpServletResponse response, UiElement uiElement) +// { +// List list = uiElementService.selectUiElementList(uiElement); +// ExcelUtil util = new ExcelUtil(UiElement.class); +// util.exportExcel(response, list, "ui元素数据"); +// } +} diff --git a/test-test/src/main/java/com/test/test/domain/UiElement.java b/test-test/src/main/java/com/test/test/domain/UiElement.java new file mode 100644 index 0000000..f0781c4 --- /dev/null +++ b/test-test/src/main/java/com/test/test/domain/UiElement.java @@ -0,0 +1,136 @@ +package com.test.test.domain; + +import com.test.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.test.common.annotation.Excel; + +/** + * ui元素对象 ui_element + * + * @author test + * @date 2025-04-22 + */ +public class UiElement extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** */ + private Long id; + + /** 组id */ + @Excel(name = "组id") + private Long groupId; + + /** 名称 */ + @Excel(name = "名称") + private String name; + + /** 定位类型 id name className tagName linkText partialLinkText css xpath label value index */ + @Excel(name = "定位类型 id name className tagName linkText partialLinkText css xpath label value index") + private String locType; + + /** 元素定位 */ + @Excel(name = "元素定位") + private String elementLoc; + + /** 描述 */ + @Excel(name = "描述") + private String description; + + /** 状态 0正常 1删除 */ + private String delFlag; + + /** 组路径名称(如"全部元素/测试") */ + private String groupNamePath; + + // getter和setter + public String getGroupNamePath() { + return groupNamePath; + } + + public void setGroupNamePath(String groupNamePath) { + this.groupNamePath = groupNamePath; + } + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + public void setGroupId(Long elementGroupId) + { + this.groupId = elementGroupId; + } + + public Long getGroupId() + { + return groupId; + } + public void setName(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } + public void setLocType(String locType) + { + this.locType = locType; + } + + public String getLocType() + { + return locType; + } + public void setElementLoc(String elementLoc) + { + this.elementLoc = elementLoc; + } + + public String getElementLoc() + { + return elementLoc; + } + public void setDescription(String description) + { + this.description = description; + } + + public String getDescription() + { + return description; + } + public void setDelFlag(String delFlag) + { + this.delFlag = delFlag; + } + + public String getDelFlag() + { + return delFlag; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("groupId", getGroupId()) + .append("name", getName()) + .append("locType", getLocType()) + .append("elementLoc", getElementLoc()) + .append("description", getDescription()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("delFlag", getDelFlag()) + .toString(); + } +} diff --git a/test-test/src/main/java/com/test/test/domain/qo/UiElementQO.java b/test-test/src/main/java/com/test/test/domain/qo/UiElementQO.java new file mode 100644 index 0000000..f9133aa --- /dev/null +++ b/test-test/src/main/java/com/test/test/domain/qo/UiElementQO.java @@ -0,0 +1,30 @@ +package com.test.test.domain.qo; + +import com.test.common.annotation.Excel; +import com.test.common.core.domain.BaseEntity; +import jakarta.validation.constraints.NotNull; +import lombok.Data; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.List; + +/** + * ui元素对象 ui_element + * + * @author test + * @date 2025-04-22 + */ +@Data +public class UiElementQO +{ + /** 名称 */ + private String name; + /** 状态 0正常 1删除 */ + private String delFlag; + @NotNull(message = "节点id不能为空") + private Long groupId; + + private List groupIds; + +} diff --git a/test-test/src/main/java/com/test/test/mapper/TestGroupMapper.java b/test-test/src/main/java/com/test/test/mapper/TestGroupMapper.java index 856a20a..2c9b25a 100644 --- a/test-test/src/main/java/com/test/test/mapper/TestGroupMapper.java +++ b/test-test/src/main/java/com/test/test/mapper/TestGroupMapper.java @@ -13,6 +13,11 @@ public interface TestGroupMapper */ List selectTestGroupList(String type); + /** + * 查询节点(文件夹)列表 + */ + TestGroup selectTestGroupById(Long id); + /** * 查询节点(文件夹)列表 */ diff --git a/test-test/src/main/java/com/test/test/mapper/UiElementMapper.java b/test-test/src/main/java/com/test/test/mapper/UiElementMapper.java new file mode 100644 index 0000000..4ef730f --- /dev/null +++ b/test-test/src/main/java/com/test/test/mapper/UiElementMapper.java @@ -0,0 +1,78 @@ +package com.test.test.mapper; + +import com.test.test.domain.UiElement; +import com.test.test.domain.qo.UiElementQO; + +import java.util.List; + +/** + * ui元素Mapper接口 + * + * @author test + * @date 2025-04-22 + */ +public interface UiElementMapper +{ + /** + * 查询ui元素 + * + * @param id ui元素主键 + * @return ui元素 + */ + public UiElement selectUiElementById(Long id); + + /** + * 查询ui元素列表 + * + * @param uiElement ui元素 + * @return ui元素集合 + */ + public List selectUiElementList(UiElement uiElement); + + + /** + * 查询ui元素列表 + * @param uiElement + * @return + */ + List selectUiElementListNew(UiElementQO uiElement); + + /** + * 新增ui元素 + * + * @param uiElement ui元素 + * @return 结果 + */ + public int insertUiElement(UiElement uiElement); + + /** + * 修改ui元素 + * + * @param uiElement ui元素 + * @return 结果 + */ + public int updateUiElement(UiElement uiElement); + + /** + * 删除ui元素 + * + * @param id ui元素主键 + * @return 结果 + */ + public int deleteUiElementById(Long id); + + /** + * 批量删除ui元素 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteUiElementByIds(Long[] ids); + + /** + * 批量删除 + * @param ids + * @return + */ + int deleteUiElementByGroupIds(List ids); +} diff --git a/test-test/src/main/java/com/test/test/service/ITestGroupService.java b/test-test/src/main/java/com/test/test/service/ITestGroupService.java index 9b6f744..1c2ea77 100644 --- a/test-test/src/main/java/com/test/test/service/ITestGroupService.java +++ b/test-test/src/main/java/com/test/test/service/ITestGroupService.java @@ -35,4 +35,18 @@ public interface ITestGroupService { * 删除节点(文件夹)信息 */ int deleteTestGroupById(GroupDelectQO qo) throws Exception; + + /** + * 查询子节点 + * @param id + * @return + */ + List getAllChildIds(Long id); + + /** + * 获取模块名 + * @param groupId + * @return + */ + String buildGroupPath(Long groupId); } diff --git a/test-test/src/main/java/com/test/test/service/IUiElementService.java b/test-test/src/main/java/com/test/test/service/IUiElementService.java new file mode 100644 index 0000000..dee550d --- /dev/null +++ b/test-test/src/main/java/com/test/test/service/IUiElementService.java @@ -0,0 +1,72 @@ +package com.test.test.service; + +import com.test.test.domain.UiElement; +import com.test.test.domain.qo.UiElementQO; + +import java.util.List; + +/** + * ui元素Service接口 + * + * @author test + * @date 2025-04-22 + */ +public interface IUiElementService +{ + /** + * 查询ui元素 + * + * @param id ui元素主键 + * @return ui元素 + */ + public UiElement selectUiElementById(Long id); + + /** + * 查询ui元素列表 + * + * @param uiElement ui元素 + * @return ui元素集合 + */ + public List selectUiElementList(UiElement uiElement); + + + /** + * 查询ui元素列表 + * + * @param uiElement ui元素 + * @return ui元素集合 + */ + public List selectUiElementListNew(UiElementQO uiElement); + + /** + * 新增ui元素 + * + * @param uiElement ui元素 + * @return 结果 + */ + public int insertUiElement(UiElement uiElement); + + /** + * 修改ui元素 + * + * @param uiElement ui元素 + * @return 结果 + */ + public int updateUiElement(UiElement uiElement); + + /** + * 批量删除ui元素 + * + * @param ids 需要删除的ui元素主键集合 + * @return 结果 + */ + public int deleteUiElementByIds(Long[] ids); + + /** + * 删除ui元素信息 + * + * @param id ui元素主键 + * @return 结果 + */ + public int deleteUiElementById(Long id); +} diff --git a/test-test/src/main/java/com/test/test/service/impl/TestGroupServiceImpl.java b/test-test/src/main/java/com/test/test/service/impl/TestGroupServiceImpl.java index c5259a7..151f025 100644 --- a/test-test/src/main/java/com/test/test/service/impl/TestGroupServiceImpl.java +++ b/test-test/src/main/java/com/test/test/service/impl/TestGroupServiceImpl.java @@ -1,12 +1,15 @@ package com.test.test.service.impl; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import com.test.common.utils.DateUtils; import com.test.common.utils.StringUtils; import com.test.test.domain.qo.GroupDelectQO; +import com.test.test.mapper.UiElementMapper; +import com.test.test.service.IUiElementService; import jakarta.annotation.Resource; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; @@ -30,6 +33,9 @@ public class TestGroupServiceImpl implements ITestGroupService { @Lazy private TestApiServiceImpl testApiServiceImpl; + @Resource + private UiElementMapper uiElementMapper; + /** * 查询节点(文件夹)列表 */ @@ -82,6 +88,9 @@ public class TestGroupServiceImpl implements ITestGroupService { case "task": System.out.println("task"); break; + case "ui": + uiElementMapper.deleteUiElementByGroupIds(idList); + break; default: throw new Exception(StringUtils.format("文件夹类型({})非法。 ", qo.getType())); } @@ -98,4 +107,73 @@ public class TestGroupServiceImpl implements ITestGroupService { } return idList; } + + /** + * 根据ID获取所有子元素ID(包括自身) + * @param id 要查询的ID + * @return 所有子元素ID集合(包含自身ID) + */ + public List getAllChildIds(Long id) { + List allGroups = selectTestGroupList("ui"); + List result = new ArrayList<>(); + + // 如果传入的是根节点(parentId=0),则查询所有数据 + if (id != null && id == 0L) { + return allGroups.stream() + .map(TestGroup::getId) + .collect(Collectors.toList()); + } + + // 添加自身ID + result.add(id); + // 递归查找子节点 + findChildrenIds(id, allGroups, result); + + return result; + } + + /** + * 构建组路径名称 + * @param groupId 组ID + * @return 如"全部元素/测试" + */ + public String buildGroupPath(Long groupId) { + List names = new ArrayList<>(); + + // 递归查找父组 + Long currentId = groupId; + while (currentId != null && currentId != 0L) { + TestGroup group = testGroupMapper.selectTestGroupById(currentId); + if (group != null) { + names.add(group.getName()); + currentId = group.getParentId(); + } else { + break; + } + } + + // 反转列表,使父组在前 + Collections.reverse(names); + + return String.join("/", names); + } + + /** + * 递归查找所有子节点ID + * @param parentId 父节点ID + * @param allGroups 所有数据 + * @param result 结果集合 + */ + private void findChildrenIds(Long parentId, List allGroups, List result) { + for (TestGroup group : allGroups) { + if (parentId.equals(group.getParentId())) { + result.add(group.getId()); + findChildrenIds(group.getId(), allGroups, result); + } + } + } + + + + } diff --git a/test-test/src/main/java/com/test/test/service/impl/UiElementServiceImpl.java b/test-test/src/main/java/com/test/test/service/impl/UiElementServiceImpl.java new file mode 100644 index 0000000..05089ab --- /dev/null +++ b/test-test/src/main/java/com/test/test/service/impl/UiElementServiceImpl.java @@ -0,0 +1,130 @@ +package com.test.test.service.impl; + +import java.util.List; +import com.test.common.utils.DateUtils; +import com.test.common.utils.SecurityUtils; +import com.test.test.domain.UiElement; +import com.test.test.domain.qo.UiElementQO; +import com.test.test.mapper.TestGroupMapper; +import com.test.test.mapper.UiElementMapper; +import com.test.test.service.ITestGroupService; +import com.test.test.service.IUiElementService; +import jakarta.annotation.Resource; +import org.checkerframework.checker.units.qual.A; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + + +/** + * ui元素Service业务层处理 + * + * @author test + * @date 2025-04-22 + */ +@Service +public class UiElementServiceImpl implements IUiElementService +{ + @Resource + private UiElementMapper uiElementMapper; + @Resource + private ITestGroupService testGroupService; + + /** + * 查询ui元素 + * + * @param id ui元素主键 + * @return ui元素 + */ + @Override + public UiElement selectUiElementById(Long id) + { + return uiElementMapper.selectUiElementById(id); + } + + /** + * 查询ui元素列表 + * + * @param uiElement ui元素 + * @return ui元素 + */ + @Override + public List selectUiElementList(UiElement uiElement) + { + uiElement.setDelFlag("0"); + return uiElementMapper.selectUiElementList(uiElement); + } + + @Override + public List selectUiElementListNew(UiElementQO uiElement) { + uiElement.setDelFlag("0"); + //这里要递归查询子元素 + Long groupId = uiElement.getGroupId(); + List allChildIds = testGroupService.getAllChildIds(groupId); + uiElement.setGroupIds(allChildIds); + // 查询元素列表 + List elements = uiElementMapper.selectUiElementListNew(uiElement); + + // 为每个元素设置groupNamePath + for (UiElement element : elements) { + String path = testGroupService.buildGroupPath(element.getGroupId()); + element.setGroupNamePath(path); + } + + return elements; + } + + /** + * 新增ui元素 + * + * @param uiElement ui元素 + * @return 结果 + */ + @Override + public int insertUiElement(UiElement uiElement) + { + uiElement.setDelFlag("0"); + uiElement.setCreateBy(SecurityUtils.getUsername()); + uiElement.setCreateTime(DateUtils.getNowDate()); + uiElement.setUpdateBy(SecurityUtils.getUsername()); + uiElement.setUpdateTime(DateUtils.getNowDate()); + return uiElementMapper.insertUiElement(uiElement); + } + + /** + * 修改ui元素 + * + * @param uiElement ui元素 + * @return 结果 + */ + @Override + public int updateUiElement(UiElement uiElement) + { + uiElement.setUpdateBy(SecurityUtils.getUsername()); + uiElement.setUpdateTime(DateUtils.getNowDate()); + return uiElementMapper.updateUiElement(uiElement); + } + + /** + * 批量删除ui元素 + * + * @param ids 需要删除的ui元素主键 + * @return 结果 + */ + @Override + public int deleteUiElementByIds(Long[] ids) + { + return uiElementMapper.deleteUiElementByIds(ids); + } + + /** + * 删除ui元素信息 + * + * @param id ui元素主键 + * @return 结果 + */ + @Override + public int deleteUiElementById(Long id) + { + return uiElementMapper.deleteUiElementById(id); + } +} diff --git a/test-test/src/main/resources/mapper/test/TestGroupMapper.xml b/test-test/src/main/resources/mapper/test/TestGroupMapper.xml index f8c562c..a724355 100644 --- a/test-test/src/main/resources/mapper/test/TestGroupMapper.xml +++ b/test-test/src/main/resources/mapper/test/TestGroupMapper.xml @@ -36,6 +36,13 @@ + + + + + + + and group_id in + + #{groupId} + + + and name like concat('%', #{name}, '%') + and del_flag = #{delFlag} + + + + + + + + + + insert into ui_element + + group_id, + name, + loc_type, + element_loc, + description, + create_by, + create_time, + update_by, + update_time, + del_flag, + + + #{groupId}, + #{name}, + #{locType}, + #{elementLoc}, + #{description}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{delFlag}, + + + + + update ui_element + + group_id = #{groupId}, + name = #{name}, + loc_type = #{locType}, + element_loc = #{elementLoc}, + description = #{description}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + del_flag = #{delFlag}, + + where id = #{id} + + + + update ui_element set del_flag = '1' where id = #{id} + + + + update ui_element set del_flag = '1' where id in + + #{id} + + + + + + update ui_element + set del_flag = '1' + where group_id in + + #{id} + + + \ No newline at end of file