云
2026-09-29 f87ce86307056f63f79312178037cc8714eb2b13
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package cn.iocoder.yudao.module.archive.dal.mysql.document;
 
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.archive.controller.admin.document.vo.ArchiveDocumentPageReqVO;
import cn.iocoder.yudao.module.archive.controller.admin.stat.vo.ArchiveStatCategoryVO;
import cn.iocoder.yudao.module.archive.controller.admin.stat.vo.ArchiveStatValueVO;
import cn.iocoder.yudao.module.archive.dal.dataobject.document.ArchiveDocumentDO;
import cn.iocoder.yudao.module.archive.enums.ArchiveDocumentStatusEnum;
import cn.iocoder.yudao.module.archive.enums.ArchiveSecretLevelEnum;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
 
import java.util.List;
 
@Mapper
public interface ArchiveDocumentMapper extends BaseMapperX<ArchiveDocumentDO> {
 
    /**
     * 按来源单据查询档案(归档联动幂等判断用)
     */
    default ArchiveDocumentDO selectBySource(Integer sourceType, Long sourceId) {
        return selectFirstOne(ArchiveDocumentDO::getSourceType, sourceType,
                ArchiveDocumentDO::getSourceId, sourceId);
    }
 
    /** 分类下档案数量(分类删除守卫用) */
    default Long selectCountByCategoryId(Long categoryId) {
        return selectCount(ArchiveDocumentDO::getCategoryId, categoryId);
    }
 
    /**
     * 档案分页查询
     *
     * @param excludeSensitive true=当前用户无敏感档案权限,强制排除「保密」档案
     */
    default PageResult<ArchiveDocumentDO> selectPage(ArchiveDocumentPageReqVO reqVO, boolean excludeSensitive) {
        return selectPage(reqVO, buildQuery(reqVO, excludeSensitive));
    }
 
    /**
     * 档案列表查询(导出用,不分页)
     *
     * @param excludeSensitive true=当前用户无敏感档案权限,强制排除「保密」档案
     */
    default List<ArchiveDocumentDO> selectList(ArchiveDocumentPageReqVO reqVO, boolean excludeSensitive) {
        return selectList(buildQuery(reqVO, excludeSensitive));
    }
 
    /**
     * 构建档案查询条件。敏感档案过滤统一走此方法,禁止在其它入口重复拼接。
     */
    default LambdaQueryWrapperX<ArchiveDocumentDO> buildQuery(ArchiveDocumentPageReqVO reqVO, boolean excludeSensitive) {
        LambdaQueryWrapperX<ArchiveDocumentDO> query = new LambdaQueryWrapperX<ArchiveDocumentDO>()
                .likeIfPresent(ArchiveDocumentDO::getNo, reqVO.getNo())
                .likeIfPresent(ArchiveDocumentDO::getTitle, reqVO.getTitle())
                .eqIfPresent(ArchiveDocumentDO::getCategoryId, reqVO.getCategoryId())
                .eqIfPresent(ArchiveDocumentDO::getSecretLevel, reqVO.getSecretLevel())
                .eqIfPresent(ArchiveDocumentDO::getCarrierType, reqVO.getCarrierType())
                .eqIfPresent(ArchiveDocumentDO::getSourceType, reqVO.getSourceType())
                .likeIfPresent(ArchiveDocumentDO::getSourceNo, reqVO.getSourceNo())
                .likeIfPresent(ArchiveDocumentDO::getTags, reqVO.getTags())
                .eqIfPresent(ArchiveDocumentDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(ArchiveDocumentDO::getArchiveDate, reqVO.getArchiveDate())
                .orderByDesc(ArchiveDocumentDO::getId);
        if (excludeSensitive) {
            query.ne(ArchiveDocumentDO::getSecretLevel, ArchiveSecretLevelEnum.SECRET.getLevel());
        }
        return query;
    }
 
    /** 档案总数 */
    default Long selectTotalCount() {
        return selectCount();
    }
 
    /** 按档案状态统计数量 */
    default Long selectCountByStatus(Integer status) {
        return selectCount(ArchiveDocumentDO::getStatus, status);
    }
 
    /** 在库档案数量 */
    default Long selectInStockCount() {
        return selectCountByStatus(ArchiveDocumentStatusEnum.IN_STOCK.getStatus());
    }
 
    /** 借出中档案数量 */
    default Long selectBorrowedCount() {
        return selectCountByStatus(ArchiveDocumentStatusEnum.BORROWED.getStatus());
    }
 
    /**
     * 按分类聚合档案数量(含 0 条的分类,便于前端展示全部分类)
     */
    @Select("SELECT c.id AS categoryId, c.name AS name, COUNT(d.id) AS total "
            + "FROM archive_category c LEFT JOIN archive_document d ON d.category_id = c.id AND d.deleted = 0 "
            + "WHERE c.deleted = 0 GROUP BY c.id, c.name ORDER BY c.sort ASC, c.id ASC")
    List<ArchiveStatCategoryVO> selectCountGroupByCategory();
 
    /** 按密级聚合档案数量 */
    @Select("SELECT secret_level AS value, COUNT(id) AS total FROM archive_document WHERE deleted = 0 "
            + "GROUP BY secret_level ORDER BY secret_level ASC")
    List<ArchiveStatValueVO> selectCountGroupBySecretLevel();
 
    /** 按载体聚合档案数量 */
    @Select("SELECT carrier_type AS value, COUNT(id) AS total FROM archive_document WHERE deleted = 0 "
            + "GROUP BY carrier_type ORDER BY carrier_type ASC")
    List<ArchiveStatValueVO> selectCountGroupByCarrierType();
 
}