| | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.archive.api.document.ArchiveDocumentApi; |
| | | import cn.iocoder.yudao.module.archive.api.document.dto.ArchiveDocumentCreateReqDTO; |
| | | import cn.iocoder.yudao.module.archive.api.document.dto.ArchiveDocumentRespDTO; |
| | | import cn.iocoder.yudao.module.system.api.storage.StorageAttachmentApi; |
| | | import cn.iocoder.yudao.module.system.api.storage.dto.StorageBlobRespDTO; |
| | | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| | | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserCreateReqDTO; |
| | | import cn.iocoder.yudao.module.ums.controller.admin.member.vo.UmsMemberPageReqVO; |
| | |
| | | |
| | | import java.time.LocalDate; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.ums.enums.ErrorCodeConstants.*; |
| | |
| | | |
| | | public static final String MEMBER_RECORD_TYPE = "ums_member"; |
| | | |
| | | /** 会员状态:正常(可归档) */ |
| | | private static final Integer MEMBER_STATUS_NORMAL = 1; |
| | | |
| | | /** 归档来源类型:3-会员(对应 archive 模块 source_type) */ |
| | | private static final Integer ARCHIVE_SOURCE_TYPE_MEMBER = 3; |
| | | |
| | | /** 归档密级:2-内部 */ |
| | | private static final Integer ARCHIVE_SECRET_LEVEL_INTERNAL = 2; |
| | | |
| | | /** 会员档案分类编码(对应 archive_category.code) */ |
| | | private static final String ARCHIVE_CATEGORY_CODE_MEMBER = "member"; |
| | | |
| | | @Resource |
| | | private UmsMemberMapper memberMapper; |
| | | |
| | |
| | | |
| | | @Resource |
| | | private StorageAttachmentApi storageAttachmentApi; |
| | | |
| | | @Resource |
| | | private ArchiveDocumentApi archiveDocumentApi; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | return memberMapper.selectPage(pageReqVO); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public String archiveMember(Long id) { |
| | | // 1.1 校验会员存在 |
| | | UmsMemberDO member = validateMemberExists(id); |
| | | // 1.2 只有「正常」状态的会员才能归档 |
| | | if (!MEMBER_STATUS_NORMAL.equals(member.getStatus())) { |
| | | throw exception(MEMBER_ARCHIVE_FAIL_STATUS, member.getNo(), memberStatusName(member.getStatus())); |
| | | } |
| | | // 1.3 重复归档校验 |
| | | if (member.getArchiveDocumentId() != null) { |
| | | throw exception(MEMBER_ALREADY_ARCHIVED, member.getNo(), |
| | | StrUtil.blankToDefault(archiveNo(id), "未知")); |
| | | } |
| | | |
| | | // 2. 带入会员材料附件,按来源单据归档 |
| | | List<Long> blobIds = storageAttachmentApi.listAttachments(MEMBER_RECORD_TYPE, id).stream() |
| | | .map(StorageBlobRespDTO::getId).collect(Collectors.toList()); |
| | | Long archiveDocumentId = archiveDocumentApi.archiveBySource(new ArchiveDocumentCreateReqDTO() |
| | | .setSourceType(ARCHIVE_SOURCE_TYPE_MEMBER) |
| | | .setSourceId(id) |
| | | .setSourceNo(member.getNo()) |
| | | .setSourceTitle(member.getName()) |
| | | .setCategoryCode(ARCHIVE_CATEGORY_CODE_MEMBER) |
| | | .setSecretLevel(ARCHIVE_SECRET_LEVEL_INTERNAL) |
| | | .setSummary("会员材料归档") |
| | | .setBlobIds(blobIds)).getCheckedData(); |
| | | |
| | | // 3. 回写归档档案 ID(作为已归档硬标记) |
| | | memberMapper.updateById(new UmsMemberDO().setId(id).setArchiveDocumentId(archiveDocumentId)); |
| | | return StrUtil.blankToDefault(archiveNo(id), "未知"); |
| | | } |
| | | |
| | | // =================== 内部方法 =================== |
| | | |
| | | private Long createSystemUser(UmsApplicationDO application) { |
| | |
| | | return member; |
| | | } |
| | | |
| | | /** 会员状态中文名:1-正常 0-暂停(用于归档失败提示) */ |
| | | private String memberStatusName(Integer status) { |
| | | if (status == null) { |
| | | return "未知"; |
| | | } |
| | | return MEMBER_STATUS_NORMAL.equals(status) ? "正常" : "暂停"; |
| | | } |
| | | |
| | | /** 查询来源单据已生成的档案编号(未归档时返回 null) */ |
| | | private String archiveNo(Long memberId) { |
| | | ArchiveDocumentRespDTO archive = archiveDocumentApi |
| | | .getBySource(ARCHIVE_SOURCE_TYPE_MEMBER, memberId).getCheckedData(); |
| | | return archive != null ? archive.getNo() : null; |
| | | } |
| | | |
| | | } |