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();
|
|
}
|