1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.ard.sample.annotation.service.impl;
 
import com.ard.sample.annotation.mapper.AnnotationMapper;
import com.ard.sample.annotation.model.entity.AnnotationEntity;
import com.ard.sample.annotation.service.IAnnotationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.List;
 
@Slf4j
@Service
@RequiredArgsConstructor
public class AnnotationServiceImpl extends ServiceImpl<AnnotationMapper, AnnotationEntity>
        implements IAnnotationService {
 
    @Override
    public boolean addAnnotation(AnnotationEntity entity) {
        return save(entity);
    }
 
    @Override
    public boolean editAnnotation(AnnotationEntity entity) {
        if (entity.getId() == null) {
            log.error("修改标记失败:ID为空");
            return false;
        }
        return updateById(entity);
    }
 
    /**
     * 新增:修改标注显示状态
     */
    @Override
    public boolean updateAnnotationVisible(String id, Boolean isTrue) {
        if (id == null || id.isEmpty() || isTrue == null) {
            log.error("修改标注显示状态失败:参数非法,id={}, isTrue={}", id, isTrue);
            return false;
        }
        AnnotationEntity entity = new AnnotationEntity();
        entity.setId(id);
        entity.setIsTrue(isTrue);
        return updateById(entity);
    }
 
    @Override
    public boolean deleteAnnotation(String id) {
        if (id == null) {
            log.error("删除标记失败:ID为空");
            return false;
        }
        boolean result = removeById(id);
        log.info("删除标记{},结果:{}", id, result);
        return result;
    }
 
    @Override
    public boolean batchDeleteAnnotation(List<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            log.error("批量删除标记失败:ID列表为空");
            return false;
        }
        boolean result = removeByIds(ids);
        log.info("批量删除标记{},结果:{}", ids, result);
        return result;
    }
 
    @Override
    public List<AnnotationEntity> listByDirectoryId(String directoryId) {
        if (directoryId == null) {
            log.error("按目录查询标记失败:目录ID为空");
            return List.of();
        }
        return lambdaQuery().eq(AnnotationEntity::getDirectoryId, directoryId).list();
    }
 
    /**
     * 按标注ID获取详细信息(核心实现)
     */
    @Override
    public AnnotationEntity getAnnotationById(String id) {
        // 1. 参数校验
        if (id == null || id.isEmpty()) {
            log.error("按ID查询标注失败:标注ID为空");
            return null;
        }
        // 2. MyBatis-Plus通用查询(根据主键ID查询)
        return getById(id);
    }
}