| | |
| | | import com.ard.sample.annotation.service.IAnnotationDirectoryService; |
| | | import com.ard.sample.annotation.service.IAnnotationService; |
| | | import com.ard.sample.annotation.util.JsonSerializeUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ard.sample.annotation.mapper.AnnotationDirectoryMapper; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | * 新增:修改目录显示状态 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) // 事务控制:目录和标注修改要么都成功,要么都回滚 |
| | | public boolean updateDirectoryVisible(String id, Boolean isTrue) { |
| | | // 1. 参数校验 |
| | | if (id == null || id.isEmpty() || isTrue == null) { |
| | | log.error("修改目录显示状态失败:参数非法,id={}, isTrue={}", id, isTrue); |
| | | return false; |
| | | } |
| | | AnnotationDirectoryEntity entity = new AnnotationDirectoryEntity(); |
| | | entity.setId(id); |
| | | entity.setIsTrue(isTrue); |
| | | return updateById(entity); |
| | | // 2. 修改目录自身的可见状态 |
| | | AnnotationDirectoryEntity directoryEntity = new AnnotationDirectoryEntity(); |
| | | directoryEntity.setId(id); |
| | | directoryEntity.setIsTrue(isTrue); |
| | | boolean dirUpdateResult = updateById(directoryEntity); |
| | | if (!dirUpdateResult) { |
| | | log.error("修改目录{}显示状态失败", id); |
| | | return false; |
| | | } |
| | | // 3. 批量修改该目录下所有标注的可见状态(核心新增逻辑) |
| | | LambdaUpdateWrapper<AnnotationEntity> annotationUpdateWrapper = new LambdaUpdateWrapper<>(); |
| | | annotationUpdateWrapper.eq(AnnotationEntity::getDirectoryId, id) // 匹配目录ID |
| | | .set(AnnotationEntity::getIsTrue, isTrue); // 同步设置相同的可见状态 |
| | | boolean annotationUpdateResult = annotationService.update(annotationUpdateWrapper); |
| | | // 简化日志:只记录操作结果 |
| | | log.info("目录{}显示状态修改成功(状态:{}),下属标注状态同步修改结果:{}", |
| | | id, isTrue, annotationUpdateResult); |
| | | |
| | | // 4. 返回最终结果(目录修改成功且标注修改成功,或标注无数据时返回目录修改结果) |
| | | return dirUpdateResult; |
| | | } |
| | | |
| | | @Override |