| | |
| | | package com.tourguide.modules.user.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.tourguide.common.api.PageResponse; |
| | | import com.tourguide.common.exception.BusinessException; |
| | |
| | | } |
| | | |
| | | private void anonymizeCancelledGuide(GuideUser user) { |
| | | userMapper.update(null, new LambdaUpdateWrapper<GuideUser>() |
| | | .eq(GuideUser::getId, user.getId()) |
| | | .set(GuideUser::getUsername, "deleted_" + UUID.randomUUID().toString().replace("-", "").substring(0, 24)) |
| | | .set(GuideUser::getMobile, null) |
| | | .set(GuideUser::getCertificateNo, null) |
| | | .set(GuideUser::getIdCardNo, null)); |
| | | String deletedUsername = "deleted_" + UUID.randomUUID().toString().replace("-", "").substring(0, 24); |
| | | userMapper.anonymizeCancelledGuide(user.getId(), deletedUsername); |
| | | } |
| | | |
| | | private void ensureUniqueGuideIdentity(GuideApplication application, GuideUser existingUser) { |
| | | if (StringUtils.hasText(application.getIdCardNo())) { |
| | | String idCardNo = application.getIdCardNo().trim().toUpperCase(); |
| | | // 兼容旧注销数据:释放已注销账号占用的身份证唯一索引。 |
| | | userMapper.clearCancelledIdentityByIdCard(idCardNo); |
| | | // 兼容旧驳回数据:释放待审核账号占用的身份证唯一索引,避免其阻塞重新注册。 |
| | | userMapper.clearPendingIdentityByIdCard(idCardNo); |
| | | } |
| | | if (StringUtils.hasText(application.getCertificateNo()) |
| | | && userMapper.selectCount(new LambdaQueryWrapper<GuideUser>() |
| | | .eq(GuideUser::getCertificateNo, application.getCertificateNo()) |
| | | .ne(GuideUser::getStatus, STATUS_CANCELLED) |
| | | .ne(existingUser != null && existingUser.getId() != null, |
| | | GuideUser::getId, existingUser == null ? null : existingUser.getId())) > 0) { |
| | | throw new BusinessException(409, "该导游证号已存在导游账号"); |
| | | } |
| | | if (StringUtils.hasText(application.getIdCardNo()) |
| | | && userMapper.selectCount(new LambdaQueryWrapper<GuideUser>() |
| | | .eq(GuideUser::getIdCardNo, application.getIdCardNo()) |
| | | .eq(GuideUser::getIdCardNo, application.getIdCardNo().trim().toUpperCase()) |
| | | .ne(GuideUser::getStatus, STATUS_CANCELLED) |
| | | .ne(existingUser != null && existingUser.getId() != null, |
| | | GuideUser::getId, existingUser == null ? null : existingUser.getId())) > 0) { |
| | | throw new BusinessException(409, "该身份证号已存在导游账号"); |
| | | } |
| | | } |
| | | |
| | | /** 申请被驳回后释放待审核账号占用的身份证/导游证唯一索引,避免其阻塞重新注册。 */ |
| | | public void releaseIdentityForRejectedApplication(String mobile) { |
| | | if (!StringUtils.hasText(mobile)) return; |
| | | GuideUser user = findByPhone(mobile); |
| | | if (user != null && Integer.valueOf(STATUS_PENDING).equals(user.getStatus())) { |
| | | userMapper.releasePendingIdentity(user.getId()); |
| | | } |
| | | } |
| | | |
| | | private void copyApplicationProfile(GuideUser user, GuideApplication application) { |
| | | user.setRealName(application.getRealName()); |
| | | user.setMobile(application.getMobile()); |