| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package space.anyi.serve.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import space.anyi.serve.entity.profile.UserProfile;
- import space.anyi.serve.entity.realname.RealnameAuth;
- import space.anyi.serve.mapper.RealnameAuthMapper;
- import space.anyi.serve.mapper.UserProfileMapper;
- import space.anyi.serve.service.NotificationService;
- import space.anyi.serve.service.RealnameAuthService;
- import java.time.LocalDateTime;
- @Service
- public class RealnameAuthServiceImpl extends ServiceImpl<RealnameAuthMapper, RealnameAuth> implements RealnameAuthService {
- private final UserProfileMapper userProfileMapper;
- private final NotificationService notificationService;
- public RealnameAuthServiceImpl(UserProfileMapper userProfileMapper, NotificationService notificationService) {
- this.userProfileMapper = userProfileMapper;
- this.notificationService = notificationService;
- }
- @Override
- public RealnameAuth getByUserId(Long userId) {
- return getOne(new LambdaQueryWrapper<RealnameAuth>().eq(RealnameAuth::getUserId, userId));
- }
- @Override
- @Transactional
- public void submit(Long userId, String realName, String idCard, String idCardFront, String idCardBack) {
- RealnameAuth existing = getByUserId(userId);
- if (existing != null) throw new IllegalArgumentException("已提交过实名认证");
- RealnameAuth auth = new RealnameAuth();
- auth.setUserId(userId);
- auth.setRealName(realName);
- auth.setIdCard(idCard);
- auth.setIdCardFront(idCardFront);
- auth.setIdCardBack(idCardBack);
- auth.setStatus("pending");
- auth.setCreatedAt(LocalDateTime.now());
- auth.setUpdatedAt(LocalDateTime.now());
- save(auth);
- }
- @Override
- @Transactional
- public void review(Long id, boolean approved, String rejectReason) {
- RealnameAuth auth = getById(id);
- if (auth == null) throw new IllegalArgumentException("认证记录不存在");
- if (!"pending".equals(auth.getStatus())) throw new IllegalArgumentException("已审核");
- if (approved) {
- auth.setStatus("approved");
- UserProfile profile = userProfileMapper.selectOne(
- new LambdaQueryWrapper<UserProfile>().eq(UserProfile::getUserId, auth.getUserId()));
- if (profile != null) {
- profile.setIsRealname(true);
- profile.setUpdatedAt(LocalDateTime.now());
- userProfileMapper.updateById(profile);
- }
- notificationService.createNotification(auth.getUserId(), "system", "实名认证通过",
- "您的实名认证已通过");
- } else {
- auth.setStatus("rejected");
- auth.setRejectReason(rejectReason);
- notificationService.createNotification(auth.getUserId(), "system", "实名认证驳回",
- "实名认证被驳回" + (rejectReason != null ? ",原因:" + rejectReason : ""));
- }
- auth.setReviewTime(LocalDateTime.now());
- auth.setUpdatedAt(LocalDateTime.now());
- updateById(auth);
- }
- }
|