From 67f02ece9366aa9a64ae1a0686b28f0e4c6e1d04 Mon Sep 17 00:00:00 2001 From: liangzai <2440983361@qq.com> Date: Thu, 19 Jun 2025 17:51:25 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81add=20queryservice=202=E3=80=81fix=20?= =?UTF-8?q?docker=20compose=20port?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/logic/query/queryservicelogic.go | 120 ++++++++++++++++++ app/main/api/internal/types/query.go | 41 +----- docker-compose.yml | 8 +- 3 files changed, 126 insertions(+), 43 deletions(-) diff --git a/app/main/api/internal/logic/query/queryservicelogic.go b/app/main/api/internal/logic/query/queryservicelogic.go index 140f675..cd1117a 100644 --- a/app/main/api/internal/logic/query/queryservicelogic.go +++ b/app/main/api/internal/logic/query/queryservicelogic.go @@ -53,6 +53,8 @@ var productProcessors = map[string]func(*QueryServiceLogic, *types.QueryServiceR "rentalinfo": (*QueryServiceLogic).ProcessRentalInfoLogic, "preloanbackgroundcheck": (*QueryServiceLogic).ProcessPreLoanBackgroundCheckLogic, "backgroundcheck": (*QueryServiceLogic).ProcessBackgroundCheckLogic, + "personalLawsuit": (*QueryServiceLogic).ProcessPersonalLawsuitLogic, + "enterpriseLawsuit": (*QueryServiceLogic).ProcessEnterpriseLawsuitLogic, } func (l *QueryServiceLogic) PreprocessLogic(req *types.QueryServiceReq, product string) (*types.QueryServiceResp, error) { @@ -483,6 +485,124 @@ func (l *QueryServiceLogic) ProcessBackgroundCheckLogic(req *types.QueryServiceR RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter, }, nil } + +func (l *QueryServiceLogic) ProcessPersonalLawsuitLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) { + // AES解密 + decryptData, DecryptDataErr := l.DecryptData(req.Data) + if DecryptDataErr != nil { + return nil, DecryptDataErr + } + + // 校验参数 + var data types.PersonalLawsuitReq + if unmarshalErr := json.Unmarshal(decryptData, &data); unmarshalErr != nil { + return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %+v", unmarshalErr) + } + + if validatorErr := validator.Validate(data); validatorErr != nil { + return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.PARAM_VERIFICATION_ERROR, validatorErr.Error()), "查询服务, 参数不正确: %+v", validatorErr) + } + + // 校验验证码 + verifyCodeErr := l.VerifyCode(data.Mobile, data.Code) + if verifyCodeErr != nil { + return nil, verifyCodeErr + } + + twoVerification := service.TwoFactorVerificationRequest{ + Name: data.Name, + IDCard: data.IDCard, + } + verification, err := l.svcCtx.VerificationService.TwoFactorVerificationWest(twoVerification) + if err != nil { + return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "二要素验证失败: %v", err) + } + if !verification.Passed { + return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "二要素验证不通过: %v", err) + } + + // 缓存 + params := map[string]interface{}{ + "name": data.Name, + "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) + } + cacheNo, cacheDataErr := l.CacheData(params, "personallawsuit", userID) + if cacheDataErr != nil { + return nil, cacheDataErr + } + + token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal) + if err != nil { + return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID) + } + + // 获取当前时间戳 + now := time.Now().Unix() + return &types.QueryServiceResp{ + Id: cacheNo, + AccessToken: token, + AccessExpire: now + l.svcCtx.Config.JwtAuth.AccessExpire, + RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter, + }, nil +} + +func (l *QueryServiceLogic) ProcessEnterpriseLawsuitLogic(req *types.QueryServiceReq) (*types.QueryServiceResp, error) { + // AES解密 + decryptData, DecryptDataErr := l.DecryptData(req.Data) + if DecryptDataErr != nil { + return nil, DecryptDataErr + } + + // 校验参数 + var data types.EntLawsuitReq + if unmarshalErr := json.Unmarshal(decryptData, &data); unmarshalErr != nil { + return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 解密后的数据格式不正确: %+v", unmarshalErr) + } + + if validatorErr := validator.Validate(data); validatorErr != nil { + return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.PARAM_VERIFICATION_ERROR, validatorErr.Error()), "查询服务, 参数不正确: %+v", validatorErr) + } + + // 校验验证码 + verifyCodeErr := l.VerifyCode(data.Mobile, data.Code) + if verifyCodeErr != nil { + return nil, verifyCodeErr + } + + // 缓存 + params := map[string]interface{}{ + "ent_name": data.EntName, + "ent_code": data.EntCode, + } + userID, err := l.GetOrCreateUser() + if err != nil { + return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 处理用户失败: %v", err) + } + cacheNo, cacheDataErr := l.CacheData(params, "enterpriselawsuit", userID) + if cacheDataErr != nil { + return nil, cacheDataErr + } + + token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal) + if err != nil { + return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 生成token失败 : %d", userID) + } + + // 获取当前时间戳 + now := time.Now().Unix() + return &types.QueryServiceResp{ + Id: cacheNo, + AccessToken: token, + AccessExpire: now + l.svcCtx.Config.JwtAuth.AccessExpire, + RefreshAfter: now + l.svcCtx.Config.JwtAuth.RefreshAfter, + }, nil +} + func (l *QueryServiceLogic) DecryptData(data string) ([]byte, error) { secretKey := l.svcCtx.Config.Encrypt.SecretKey key, decodeErr := hex.DecodeString(secretKey) diff --git a/app/main/api/internal/types/query.go b/app/main/api/internal/types/query.go index 5687f34..2bfea91 100644 --- a/app/main/api/internal/types/query.go +++ b/app/main/api/internal/types/query.go @@ -58,48 +58,11 @@ type EntLawsuitReq struct { Mobile string `json:"mobile" validate:"required,mobile"` Code string `json:"code" validate:"required"` } -type TocPhoneThreeElements struct { +type PersonalLawsuitReq struct { Name string `json:"name" validate:"required,name"` IDCard string `json:"id_card" validate:"required,idCard"` Mobile string `json:"mobile" validate:"required,mobile"` -} -type TocPhoneTwoElements struct { - Name string `json:"name" validate:"required,name"` - Mobile string `json:"mobile" validate:"required,mobile"` -} -type TocIDCardTwoElements struct { - Name string `json:"name" validate:"required,name"` - IDCard string `json:"id_card" validate:"required,idCard"` -} -type TocDualMarriage struct { - NameMan string `json:"name_man" validate:"required,name"` - IDCardMan string `json:"id_card_man" validate:"required,idCard"` - NameWoman string `json:"name_woman" validate:"required,name"` - IDCardWoman string `json:"id_card_woman" validate:"required,idCard"` -} -type TocPersonVehicleVerification struct { - Name string `json:"name" validate:"required,name"` - CarType string `json:"car_type" validate:"required"` - CarLicense string `json:"car_license" validate:"required"` -} - -// 银行卡黑名单 -type TocBankCardBlacklist struct { - Name string `json:"name" validate:"required,name"` - IDCard string `json:"id_card" validate:"required,idCard"` - Mobile string `json:"mobile" validate:"required,mobile"` - BankCard string `json:"bank_card" validate:"required"` -} - -// 手机号码风险 -type TocPhoneNumberRisk struct { - Mobile string `json:"mobile" validate:"required,mobile"` -} - -// 手机二次卡 -type TocPhoneSecondaryCard struct { - Mobile string `json:"mobile" validate:"required,mobile"` - StartDate string `json:"start_date" validate:"required"` + Code string `json:"code" validate:"required"` } type AgentQueryData struct { diff --git a/docker-compose.yml b/docker-compose.yml index 8d823de..18f2e8d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,7 +13,7 @@ services: MYSQL_USER: ycc MYSQL_PASSWORD: 5vg67b3UNHu8 ports: - - "21001:3306" + - "25001:3306" volumes: # 数据挂载 - Data mounting - ./data/mysql/data:/var/lib/mysql @@ -36,7 +36,7 @@ services: image: redis:7.4.0 container_name: ycc_redis ports: - - "21002:6379" + - "25002:6379" environment: # 时区上海 - Time zone Shanghai (Change if needed) TZ: Asia/Shanghai @@ -53,7 +53,7 @@ services: image: hibiken/asynqmon:latest container_name: ycc_asynqmon ports: - - "21003:8080" + - "25003:8080" environment: - TZ=Asia/Shanghai command: @@ -71,7 +71,7 @@ services: context: . dockerfile: app/main/api/Dockerfile ports: - - "21004:8888" + - "25004:8888" environment: - TZ=Asia/Shanghai - ENV=production