f
This commit is contained in:
@@ -7,12 +7,15 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"qnc-server/app/main/api/internal/service"
|
||||
"qnc-server/app/main/model"
|
||||
"qnc-server/common/ctxdata"
|
||||
"qnc-server/common/xerr"
|
||||
"qnc-server/pkg/lzkit/crypto"
|
||||
"qnc-server/pkg/lzkit/lzUtils"
|
||||
"qnc-server/pkg/lzkit/validator"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
|
||||
@@ -107,6 +110,11 @@ func (l *QueryServiceLogic) ProcessMarriageLogic(req *types.QueryServiceReq) (*t
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
// 插入业务操作记录
|
||||
if insertErr := l.InsertQueryUserRecord(params, "marriage", cacheNo, userID); insertErr != nil {
|
||||
logx.Errorf("插入查询用户记录失败: %v", insertErr)
|
||||
// 记录失败不影响主流程,只记录日志
|
||||
}
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %v", err)
|
||||
@@ -167,7 +175,11 @@ func (l *QueryServiceLogic) ProcessHomeServiceLogic(req *types.QueryServiceReq)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
// 插入业务操作记录
|
||||
if insertErr := l.InsertQueryUserRecord(params, "homeservice", cacheNo, userID); insertErr != nil {
|
||||
logx.Errorf("插入查询用户记录失败: %v", insertErr)
|
||||
// 记录失败不影响主流程,只记录日志
|
||||
}
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
@@ -228,7 +240,11 @@ func (l *QueryServiceLogic) ProcessRiskAssessmentLogic(req *types.QueryServiceRe
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
// 插入业务操作记录
|
||||
if insertErr := l.InsertQueryUserRecord(params, "riskassessment", cacheNo, userID); insertErr != nil {
|
||||
logx.Errorf("插入查询用户记录失败: %v", insertErr)
|
||||
// 记录失败不影响主流程,只记录日志
|
||||
}
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
@@ -288,7 +304,11 @@ func (l *QueryServiceLogic) ProcessCompanyInfoLogic(req *types.QueryServiceReq)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
// 插入业务操作记录
|
||||
if insertErr := l.InsertQueryUserRecord(params, "companyinfo", cacheNo, userID); insertErr != nil {
|
||||
logx.Errorf("插入查询用户记录失败: %v", insertErr)
|
||||
// 记录失败不影响主流程,只记录日志
|
||||
}
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
@@ -349,7 +369,11 @@ func (l *QueryServiceLogic) ProcessRentalInfoLogic(req *types.QueryServiceReq) (
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
// 插入业务操作记录
|
||||
if insertErr := l.InsertQueryUserRecord(params, "rentalinfo", cacheNo, userID); insertErr != nil {
|
||||
logx.Errorf("插入查询用户记录失败: %v", insertErr)
|
||||
// 记录失败不影响主流程,只记录日志
|
||||
}
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
@@ -410,7 +434,11 @@ func (l *QueryServiceLogic) ProcessPreLoanBackgroundCheckLogic(req *types.QueryS
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
// 插入业务操作记录
|
||||
if insertErr := l.InsertQueryUserRecord(params, "preloanbackgroundcheck", cacheNo, userID); insertErr != nil {
|
||||
logx.Errorf("插入查询用户记录失败: %v", insertErr)
|
||||
// 记录失败不影响主流程,只记录日志
|
||||
}
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
@@ -470,7 +498,11 @@ func (l *QueryServiceLogic) ProcessBackgroundCheckLogic(req *types.QueryServiceR
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
// 插入业务操作记录
|
||||
if insertErr := l.InsertQueryUserRecord(params, "backgroundcheck", cacheNo, userID); insertErr != nil {
|
||||
logx.Errorf("插入查询用户记录失败: %v", insertErr)
|
||||
// 记录失败不影响主流程,只记录日志
|
||||
}
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
@@ -528,7 +560,11 @@ func (l *QueryServiceLogic) ProcessPersonalDataLogic(req *types.QueryServiceReq)
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
// 插入业务操作记录
|
||||
if insertErr := l.InsertQueryUserRecord(params, "personalData", cacheNo, userID); insertErr != nil {
|
||||
logx.Errorf("插入查询用户记录失败: %v", insertErr)
|
||||
// 记录失败不影响主流程,只记录日志
|
||||
}
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
@@ -586,7 +622,11 @@ func (l *QueryServiceLogic) ProcessConsumerFinanceReportLogic(req *types.QuerySe
|
||||
if cacheDataErr != nil {
|
||||
return nil, cacheDataErr
|
||||
}
|
||||
|
||||
// 插入业务操作记录
|
||||
if insertErr := l.InsertQueryUserRecord(params, "consumerFinanceReport", cacheNo, userID); insertErr != nil {
|
||||
logx.Errorf("插入查询用户记录失败: %v", insertErr)
|
||||
// 记录失败不影响主流程,只记录日志
|
||||
}
|
||||
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID)
|
||||
@@ -734,3 +774,61 @@ func (l *QueryServiceLogic) GetOrCreateUser() (string, error) {
|
||||
|
||||
return userID, nil
|
||||
}
|
||||
|
||||
// InsertQueryUserRecord 插入查询用户记录到 query_user_record 表
|
||||
// 业务场景:用户提交查询时,记录用户输入的姓名、身份证、手机号等信息
|
||||
func (l *QueryServiceLogic) InsertQueryUserRecord(params map[string]interface{}, product string, queryNo string, userID string) error {
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
key, decodeErr := hex.DecodeString(secretKey)
|
||||
if decodeErr != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "插入查询用户记录, 获取AES秘钥失败: %+v", decodeErr)
|
||||
}
|
||||
|
||||
// 获取姓名、身份证、手机号
|
||||
name, _ := params["name"].(string)
|
||||
idCard, _ := params["id_card"].(string)
|
||||
mobile, _ := params["mobile"].(string)
|
||||
|
||||
// 加密敏感字段
|
||||
encryptedName, err := crypto.AesEcbEncrypt([]byte(name), key)
|
||||
if err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "插入查询用户记录, 加密姓名失败: %+v", err)
|
||||
}
|
||||
|
||||
encryptedIdCard, err := crypto.EncryptIDCard(idCard, key)
|
||||
if err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "插入查询用户记录, 加密身份证号失败: %+v", err)
|
||||
}
|
||||
|
||||
encryptedMobile, err := crypto.EncryptMobile(mobile, secretKey)
|
||||
if err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "插入查询用户记录, 加密手机号失败: %+v", err)
|
||||
}
|
||||
|
||||
// 获取代理标识
|
||||
agentIdentifier, _ := l.ctx.Value("agentIdentifier").(string)
|
||||
|
||||
// 创建记录
|
||||
record := &model.QueryUserRecord{
|
||||
Id: uuid.NewString(), // 生成 UUID
|
||||
UserId: userID, // user_id 是 UUID 字符串
|
||||
Name: encryptedName,
|
||||
IdCard: encryptedIdCard,
|
||||
Mobile: encryptedMobile,
|
||||
Product: product,
|
||||
QueryNo: queryNo,
|
||||
OrderId: lzUtils.StringToNullString(""), // 初始为 NULL,创建订单后更新
|
||||
PlatformOrderId: lzUtils.StringToNullString(""), // 初始为空,支付成功后更新
|
||||
AgentIdentifier: lzUtils.StringToNullString(agentIdentifier),
|
||||
DelState: 0,
|
||||
Version: 0,
|
||||
}
|
||||
|
||||
// 插入数据库
|
||||
_, err = l.svcCtx.QueryUserRecordModel.Insert(l.ctx, nil, record)
|
||||
if err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "插入查询用户记录失败: %+v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user