From 27070fd8ad5215fe058aba044212beec3d7e148b Mon Sep 17 00:00:00 2001 From: YBP Date: Wed, 11 Feb 2026 15:37:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AE=B0=E5=BD=95=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E6=9B=B4=E6=96=B0-=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/qms/enums/ErrorCodeConstants.java | 1 + .../RecordCategoryController.java | 2 +- .../RecordCategoryServiceImpl.java | 99 +++++++++++++------ 3 files changed, 71 insertions(+), 31 deletions(-) diff --git a/zt-module-qms/zt-module-qms-api/src/main/java/com/zt/plat/module/qms/enums/ErrorCodeConstants.java b/zt-module-qms/zt-module-qms-api/src/main/java/com/zt/plat/module/qms/enums/ErrorCodeConstants.java index c5428561..06f6d6e1 100644 --- a/zt-module-qms/zt-module-qms-api/src/main/java/com/zt/plat/module/qms/enums/ErrorCodeConstants.java +++ b/zt-module-qms/zt-module-qms-api/src/main/java/com/zt/plat/module/qms/enums/ErrorCodeConstants.java @@ -233,4 +233,5 @@ public interface ErrorCodeConstants { ErrorCode RECORD_PERMISSION_NOT_EXISTS = new ErrorCode(1_032_350_000, "记录权限不存在"); ErrorCode RECORD_RECORD_NOT_EXISTS = new ErrorCode(1_032_350_000, "文件、模板、记录不存在"); ErrorCode RECORD_RELATION_NOT_EXISTS = new ErrorCode(1_032_350_000, "文件记录关系不存在"); + ErrorCode RECORD_FILE_EXISTS = new ErrorCode(1_032_350_000, "文件记录目录存在文件"); } diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/record/controller/admin/recordcategory/RecordCategoryController.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/record/controller/admin/recordcategory/RecordCategoryController.java index 5f03bbfb..ce50f900 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/record/controller/admin/recordcategory/RecordCategoryController.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/record/controller/admin/recordcategory/RecordCategoryController.java @@ -40,7 +40,7 @@ import com.zt.plat.module.qms.resource.record.service.recordcategory.RecordCateg @Tag(name = "管理后台 - 文件记录分类") @RestController -@RequestMapping("/qms/record-category") +@RequestMapping("/qms/resource/record-category") @Validated @DeptDataPermissionIgnore(enable = "true") @FileUploadController(source = "qms.recordcategory") diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/record/service/recordcategory/RecordCategoryServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/record/service/recordcategory/RecordCategoryServiceImpl.java index 07e8cac8..0ddf61e8 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/record/service/recordcategory/RecordCategoryServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/record/service/recordcategory/RecordCategoryServiceImpl.java @@ -12,21 +12,25 @@ import com.zt.plat.module.qms.resource.record.controller.admin.recordcategory.vo import com.zt.plat.module.qms.resource.record.dal.dao.recordcategory.RecordCategoryMapper; import com.zt.plat.module.qms.resource.record.dal.dataobject.recordcategory.RecordCategoryDO; import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import org.springframework.validation.annotation.Validated; +import java.util.ArrayList; import java.util.List; import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception; import static com.zt.plat.module.qms.enums.ErrorCodeConstants.RECORD_CATEGORY_NOT_EXISTS; +import static com.zt.plat.module.qms.enums.ErrorCodeConstants.RECORD_FILE_EXISTS; /** * 文件记录分类 Service 实现类 * * @author 后台管理 */ +@Slf4j @Service @Validated public class RecordCategoryServiceImpl implements RecordCategoryService { @@ -68,27 +72,59 @@ public class RecordCategoryServiceImpl implements RecordCategoryService { public void updateRecordCategory(RecordCategorySaveReqVO updateReqVO) { // 校验存在 validateRecordCategoryExists(updateReqVO.getId()); + + // 获取更新前的旧数据 + RecordCategoryDO oldObj = recordCategoryMapper.selectById(updateReqVO.getId()); + String oldIdPath = oldObj.getIdPath(); + // 更新 RecordCategoryDO updateObj = BeanUtils.toBean(updateReqVO, RecordCategoryDO.class); Long parentId = updateObj.getParentId(); - // 更新所有的 - // 查询父节点是否存在 -// if (parentId != 0L) { -// RecordCategoryDO recordCategoryDO = recordCategoryMapper.selectById(parentId); -// if (ObjectUtils.isEmpty(recordCategoryDO)) throw exception(RECORD_CATEGORY_NOT_EXISTS); -// String idPath = recordCategoryDO.getIdPath(); -// updateObj.setIdPath("/" + idPath + "/" + parentId + "//" + updateObj.getId() + "/"); -// recordCategoryMapper.updateById(updateObj); -// }else { - // parentId 设为0 , 子节点转换成父节点 - // TODO - updateAllIdPath(updateObj.getId(), 1); - // 更新树结构 - // 1.根据父节点查询所以关联节点 - - //2.更新ID_Path - -// } + + // 构建新的idPath + if (parentId == null || parentId == 0L) { + // 父节点为null或0,则变成根节点 + updateObj.setParentId(0L); + updateObj.setIdPath("/0//" + updateObj.getId() + "/"); + } else { + // 查询父节点 + RecordCategoryDO parentCategory = recordCategoryMapper.selectById(parentId); + if (ObjectUtils.isEmpty(parentCategory)) { + // 父节点不存在,设置为根节点 + updateObj.setParentId(0L); + updateObj.setIdPath("/0//" + updateObj.getId() + "/"); + } else { + // 父节点存在,构建新的idPath + updateObj.setIdPath(parentCategory.getIdPath() + updateObj.getId() + "/"); + } + } + + // 更新当前数据 + recordCategoryMapper.updateById(updateObj); + + // 更新当前数据的子节点 + String currentNodePattern = "/" + updateObj.getId() + "/"; + LambdaQueryWrapper query = new LambdaQueryWrapper<>(); + query.like(RecordCategoryDO::getIdPath, "%" + currentNodePattern + "%"); + query.ne(RecordCategoryDO::getId, updateObj.getId()); // 排除当前节点本身 + List childList = recordCategoryMapper.selectList(query); + + if (!childList.isEmpty()) { + List recordCategoryList = new ArrayList<>(); + for (RecordCategoryDO childCategory : childList) { + String childIdPath = childCategory.getIdPath(); + // 替换旧的idPath为新的idPath + if (childIdPath.contains(oldIdPath)) { + String newChildIdPath = childIdPath.replace(oldIdPath, updateObj.getIdPath()); + childCategory.setIdPath(newChildIdPath); + recordCategoryList.add(childCategory); + } + } + if (!recordCategoryList.isEmpty()) { + // 批量更新所有子节点 + recordCategoryMapper.updateBatch(recordCategoryList); + } + } } public RecordCategoryDO getDeviceProduct(Long id) { @@ -103,19 +139,19 @@ public class RecordCategoryServiceImpl implements RecordCategoryService { } public CommonResult updateAllIdPath(Long parentId, Integer level) { - if(level > id_path_update_level_limit) - return CommonResult.success("更新完成(超出层数限制:"+id_path_update_level_limit+")"); + if (level > id_path_update_level_limit) + return CommonResult.success("更新完成(超出层数限制:" + id_path_update_level_limit + ")"); List list = listByParId(parentId); RecordCategoryDO parEntity = this.getDeviceProduct(parentId); - if(list.isEmpty()) + if (list.isEmpty()) return CommonResult.success(""); String parIdPath = "/0/"; - if(parEntity != null) + if (parEntity != null) parIdPath = parEntity.getIdPath(); - for(RecordCategoryDO entity : list){ + for (RecordCategoryDO entity : list) { entity.setIdPath(parIdPath + "/" + entity.getId() + "/"); - recordCategoryMapper.updateById( entity); - updateAllIdPath(entity.getId(),level+1); + recordCategoryMapper.updateById(entity); + updateAllIdPath(entity.getId(), level + 1); } return CommonResult.success(""); } @@ -131,8 +167,9 @@ public class RecordCategoryServiceImpl implements RecordCategoryService { RecordCategoryDO recordCategoryDO = new RecordCategoryDO(); recordCategoryDO.setId(id); recordCategoryDO.setDeleted(true); - recordCategoryMapper.updateById(recordCategoryDO); -// recordCategoryMapper.deleteById(id); + //TODO +// recordCategoryMapper.updateById(recordCategoryDO); + recordCategoryMapper.deleteById(id); } @Override @@ -146,10 +183,11 @@ public class RecordCategoryServiceImpl implements RecordCategoryService { // 验证删除的节点是否存在字节点,如果存在字节点,则不允许删除 public void validateRecordCategoryHasChildNode(Long id) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - List list = recordCategoryMapper.selectList( - queryWrapper.like(RecordCategoryDO::getIdPath, id)); + queryWrapper.eq(RecordCategoryDO::getDeleted, 0);// 没有删除的数据 + queryWrapper.like(RecordCategoryDO::getParentId, id); + List list = recordCategoryMapper.selectList(queryWrapper); if (CollUtil.isNotEmpty(list)) { - throw exception(RECORD_CATEGORY_NOT_EXISTS); + throw exception(RECORD_FILE_EXISTS); } } @@ -182,6 +220,7 @@ public class RecordCategoryServiceImpl implements RecordCategoryService { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); if (!ObjectUtils.isEmpty(name)) { queryWrapper.eq(RecordCategoryDO::getName, name); + queryWrapper.eq(RecordCategoryDO::getDeleted, 0); queryWrapper.orderByAsc(RecordCategoryDO::getSortNo); // 升序 } return recordCategoryMapper.selectList(queryWrapper);