v1.1
This commit is contained in:
@@ -100,17 +100,17 @@ func (l *QueryServiceLogic) ProcessMarriageLogic(req *types.QueryServiceReq) (*t
|
||||
"id_card": data.IDCard,
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
userID, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
userID, userType, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "marriage", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, userType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %v", err)
|
||||
}
|
||||
|
||||
// 获取当前时间戳
|
||||
@@ -160,16 +160,16 @@ func (l *QueryServiceLogic) ProcessHomeServiceLogic(req *types.QueryServiceReq)
|
||||
"id_card": data.IDCard,
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
userID, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
userID, userType, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "homeservice", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, userType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
}
|
||||
@@ -221,16 +221,16 @@ func (l *QueryServiceLogic) ProcessRiskAssessmentLogic(req *types.QueryServiceRe
|
||||
"id_card": data.IDCard,
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
userID, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
userID, userType, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "riskassessment", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, userType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
}
|
||||
@@ -281,16 +281,16 @@ func (l *QueryServiceLogic) ProcessCompanyInfoLogic(req *types.QueryServiceReq)
|
||||
"id_card": data.IDCard,
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
userID, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
userID, userType, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "companyinfo", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, userType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
}
|
||||
@@ -342,16 +342,16 @@ func (l *QueryServiceLogic) ProcessRentalInfoLogic(req *types.QueryServiceReq) (
|
||||
"id_card": data.IDCard,
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
userID, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
userID, userType, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "rentalinfo", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, userType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
}
|
||||
@@ -403,16 +403,16 @@ func (l *QueryServiceLogic) ProcessPreLoanBackgroundCheckLogic(req *types.QueryS
|
||||
"id_card": data.IDCard,
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
userID, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
userID, userType, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "preloanbackgroundcheck", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, userType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
}
|
||||
@@ -463,16 +463,16 @@ func (l *QueryServiceLogic) ProcessBackgroundCheckLogic(req *types.QueryServiceR
|
||||
"id_card": data.IDCard,
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
userID, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
userID, userType, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "backgroundcheck", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, userType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
}
|
||||
@@ -521,16 +521,16 @@ func (l *QueryServiceLogic) ProcessPersonalDataLogic(req *types.QueryServiceReq)
|
||||
"id_card": data.IDCard,
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
userID, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
userID, userType, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "personalData", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, userType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
}
|
||||
@@ -579,16 +579,16 @@ func (l *QueryServiceLogic) ProcessConsumerFinanceReportLogic(req *types.QuerySe
|
||||
"id_card": data.IDCard,
|
||||
"mobile": data.Mobile,
|
||||
}
|
||||
userID, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
userID, userType, err := l.GetOrCreateUser()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err)
|
||||
}
|
||||
cacheNo, cacheDataErr := l.CacheData(params, "consumerFinanceReport", userID)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, userType)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
}
|
||||
@@ -677,7 +677,7 @@ func (l *QueryServiceLogic) Verify(Name string, IDCard string, Mobile string) er
|
||||
}
|
||||
|
||||
// 缓存
|
||||
func (l *QueryServiceLogic) CacheData(params map[string]interface{}, Product string, userID int64) (string, error) {
|
||||
func (l *QueryServiceLogic) CacheData(params map[string]interface{}, Product string, userID string) (string, error) {
|
||||
agentIdentifier, _ := l.ctx.Value("agentIdentifier").(string)
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
key, decodeErr := hex.DecodeString(secretKey)
|
||||
@@ -714,34 +714,14 @@ func (l *QueryServiceLogic) CacheData(params map[string]interface{}, Product str
|
||||
// 1. 如果上下文中已有用户ID,直接返回
|
||||
// 2. 如果是代理查询或APP请求,创建新用户
|
||||
// 3. 其他情况返回未登录错误
|
||||
func (l *QueryServiceLogic) GetOrCreateUser() (int64, error) {
|
||||
// 尝试获取用户ID
|
||||
claims, err := ctxdata.GetClaimsFromCtx(l.ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
userID := claims.UserId
|
||||
return userID, nil
|
||||
|
||||
// // 如果不是未登录错误,说明是其他错误,直接返回
|
||||
// if !ctxdata.IsNoUserIdError(err) {
|
||||
// return 0, err
|
||||
// }
|
||||
|
||||
// // 检查是否是代理查询或APP请求
|
||||
// isAgentQuery := false
|
||||
// if agentID, ok := l.ctx.Value("agentIdentifier").(string); ok && agentID != "" {
|
||||
// isAgentQuery = true
|
||||
// }
|
||||
// if app, ok := l.ctx.Value("app").(bool); ok && app {
|
||||
// isAgentQuery = true
|
||||
// }
|
||||
|
||||
// // 如果不是代理查询或APP请求,返回未登录错误
|
||||
// if !isAgentQuery {
|
||||
// return 0, ctxdata.ErrNoUserIdInCtx
|
||||
// }
|
||||
|
||||
// // 创建新用户
|
||||
// return l.svcCtx.UserService.RegisterUUIDUser(l.ctx)
|
||||
func (l *QueryServiceLogic) GetOrCreateUser() (string, int64, error) {
|
||||
claims, err := ctxdata.GetClaimsFromCtx(l.ctx)
|
||||
if err == nil && claims != nil {
|
||||
return claims.UserId, claims.UserType, nil
|
||||
}
|
||||
userID, regErr := l.svcCtx.UserService.RegisterUUIDUser(l.ctx)
|
||||
if regErr != nil {
|
||||
return "", 0, regErr
|
||||
}
|
||||
return userID, model.UserTypeTemp, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user