add f
This commit is contained in:
@@ -1029,44 +1029,19 @@ func (s *CertificationApplicationServiceImpl) AdminApproveSubmitRecord(ctx conte
|
||||
|
||||
// AdminRejectSubmitRecord 管理端审核拒绝
|
||||
func (s *CertificationApplicationServiceImpl) AdminRejectSubmitRecord(ctx context.Context, recordID, adminID, remark string) error {
|
||||
if remark == "" {
|
||||
return fmt.Errorf("拒绝时必须填写审核备注")
|
||||
}
|
||||
record, err := s.enterpriseInfoSubmitRecordRepo.FindByID(ctx, recordID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("获取提交记录失败: %w", err)
|
||||
}
|
||||
if record.Status != "verified" {
|
||||
return fmt.Errorf("该条提交记录未通过前置校验或已失败,无法从后台拒绝(请查看历史失败原因)")
|
||||
}
|
||||
cert, err := s.aggregateService.LoadCertificationByUserID(ctx, record.UserID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("加载认证信息失败: %w", err)
|
||||
}
|
||||
|
||||
// 幂等:认证已处于拒绝或后续状态,无需重复拒绝
|
||||
switch cert.Status {
|
||||
case enums.StatusInfoRejected,
|
||||
enums.StatusEnterpriseVerified,
|
||||
enums.StatusContractApplied,
|
||||
enums.StatusContractSigned,
|
||||
enums.StatusCompleted,
|
||||
enums.StatusContractRejected,
|
||||
enums.StatusContractExpired:
|
||||
return nil
|
||||
if cert.UserID != record.UserID {
|
||||
return fmt.Errorf("提交记录与认证用户不匹配,无法拒绝")
|
||||
}
|
||||
if cert.Status != enums.StatusInfoPendingReview {
|
||||
return fmt.Errorf("认证状态不是待审核,当前: %s", enums.GetStatusName(cert.Status))
|
||||
}
|
||||
if err := cert.RejectEnterpriseInfoReview(adminID, remark); err != nil {
|
||||
return fmt.Errorf("更新认证状态失败: %w", err)
|
||||
}
|
||||
if err := s.aggregateService.SaveCertification(ctx, cert); err != nil {
|
||||
return fmt.Errorf("保存认证信息失败: %w", err)
|
||||
}
|
||||
record.MarkManualRejected(adminID, remark)
|
||||
if err := s.enterpriseInfoSubmitRecordService.Save(ctx, record); err != nil {
|
||||
return fmt.Errorf("保存企业信息提交记录失败: %w", err)
|
||||
if err := s.rejectEnterpriseInfoWithCleanup(ctx, cert, record, adminID, remark); err != nil {
|
||||
return err
|
||||
}
|
||||
s.logger.Info("管理员审核拒绝企业信息", zap.String("record_id", recordID), zap.String("admin_id", adminID))
|
||||
return nil
|
||||
@@ -1137,23 +1112,19 @@ func (s *CertificationApplicationServiceImpl) AdminTransitionCertificationStatus
|
||||
s.logger.Info("管理端变更认证状态为通过", zap.String("user_id", cmd.UserID), zap.String("admin_id", cmd.AdminID))
|
||||
return nil
|
||||
case string(enums.StatusInfoRejected):
|
||||
// 审核拒绝
|
||||
if cmd.Remark == "" {
|
||||
return fmt.Errorf("拒绝时必须填写审核备注")
|
||||
}
|
||||
if cert.Status == enums.StatusInfoRejected || cert.Status == enums.StatusEnterpriseVerified ||
|
||||
cert.Status == enums.StatusContractApplied || cert.Status == enums.StatusContractSigned || cert.Status == enums.StatusCompleted {
|
||||
return nil
|
||||
}
|
||||
if cert.Status != enums.StatusInfoPendingReview {
|
||||
return fmt.Errorf("认证状态不是待审核,当前: %s", enums.GetStatusName(cert.Status))
|
||||
verifiedRecord, verr := s.enterpriseInfoSubmitRecordRepo.FindLatestVerifiedByUserID(ctx, cert.UserID)
|
||||
if verr != nil {
|
||||
return fmt.Errorf("查找该用户有效的企业信息提交记录失败: %w", verr)
|
||||
}
|
||||
if err := cert.RejectEnterpriseInfoReview(cmd.AdminID, cmd.Remark); err != nil {
|
||||
return fmt.Errorf("更新认证状态失败: %w", err)
|
||||
}
|
||||
if err := s.aggregateService.SaveCertification(ctx, cert); err != nil {
|
||||
return fmt.Errorf("保存认证信息失败: %w", err)
|
||||
}
|
||||
record.MarkManualRejected(cmd.AdminID, cmd.Remark)
|
||||
if err := s.enterpriseInfoSubmitRecordService.Save(ctx, record); err != nil {
|
||||
return fmt.Errorf("保存企业信息提交记录失败: %w", err)
|
||||
if err := s.rejectEnterpriseInfoWithCleanup(ctx, cert, verifiedRecord, cmd.AdminID, cmd.Remark); err != nil {
|
||||
return err
|
||||
}
|
||||
s.logger.Info("管理端变更认证状态为拒绝", zap.String("user_id", cmd.UserID), zap.String("admin_id", cmd.AdminID))
|
||||
return nil
|
||||
@@ -1164,6 +1135,51 @@ func (s *CertificationApplicationServiceImpl) AdminTransitionCertificationStatus
|
||||
|
||||
// ================ 辅助方法 ================
|
||||
|
||||
// rejectEnterpriseInfoWithCleanup 管理员拒绝企业信息:同步更新认证状态与提交记录(仅释放该用户自己的 USCC 占用)
|
||||
func (s *CertificationApplicationServiceImpl) rejectEnterpriseInfoWithCleanup(
|
||||
ctx context.Context,
|
||||
cert *entities.Certification,
|
||||
record *entities.EnterpriseInfoSubmitRecord,
|
||||
adminID, remark string,
|
||||
) error {
|
||||
if remark == "" {
|
||||
return fmt.Errorf("拒绝时必须填写审核备注")
|
||||
}
|
||||
if record.UserID != cert.UserID {
|
||||
return fmt.Errorf("提交记录与认证用户不匹配,无法拒绝")
|
||||
}
|
||||
if record.Status != "verified" {
|
||||
return fmt.Errorf("该条提交记录未通过前置校验或已失败,无法从后台拒绝(请查看历史失败原因)")
|
||||
}
|
||||
switch cert.Status {
|
||||
case enums.StatusInfoRejected,
|
||||
enums.StatusEnterpriseVerified,
|
||||
enums.StatusContractApplied,
|
||||
enums.StatusContractSigned,
|
||||
enums.StatusCompleted,
|
||||
enums.StatusContractRejected,
|
||||
enums.StatusContractExpired:
|
||||
return nil
|
||||
}
|
||||
if !enums.CanAdminRejectEnterpriseInfoPhase(cert.Status) {
|
||||
return fmt.Errorf("当前认证已进入企业认证/合同阶段,不可拒绝企业信息")
|
||||
}
|
||||
if err := cert.RejectEnterpriseInfoReview(adminID, remark); err != nil {
|
||||
return fmt.Errorf("更新认证状态失败: %w", err)
|
||||
}
|
||||
if err := s.aggregateService.SaveCertification(ctx, cert); err != nil {
|
||||
return fmt.Errorf("保存认证信息失败: %w", err)
|
||||
}
|
||||
updated, err := s.enterpriseInfoSubmitRecordRepo.MarkRejectedAndFailedForUser(ctx, record.ID, cert.UserID, adminID, remark)
|
||||
if err != nil {
|
||||
return fmt.Errorf("保存企业信息提交记录失败: %w", err)
|
||||
}
|
||||
if !updated {
|
||||
return fmt.Errorf("未找到该用户对应的有效提交记录,USCC 占用未释放")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// convertToResponse 转换实体为响应DTO
|
||||
func (s *CertificationApplicationServiceImpl) convertToResponse(cert *entities.Certification) *responses.CertificationResponse {
|
||||
response := &responses.CertificationResponse{
|
||||
|
||||
Reference in New Issue
Block a user