This commit is contained in:
2026-01-13 18:30:10 +08:00
parent 0206710e29
commit 04df8460a4
29 changed files with 2472 additions and 111 deletions

View File

@@ -67,6 +67,23 @@ type (
TodayProfitRate float64 `json:"today_profit_rate"` // 今日利润率
MonthProfitRate float64 `json:"month_profit_rate"` // 当月利润率
TotalProfitRate float64 `json:"total_profit_rate"` // 总利润率
// 今日明细
TodayDetail AdminProfitDetail `json:"today_detail"`
// 当月明细
MonthDetail AdminProfitDetail `json:"month_detail"`
// 总计明细
TotalDetail AdminProfitDetail `json:"total_detail"`
}
// 利润明细
AdminProfitDetail {
Revenue float64 `json:"revenue"` // 营收
Commission float64 `json:"commission"` // 佣金
Rebate float64 `json:"rebate"` // 返利
CompanyTax float64 `json:"company_tax"` // 税务成本
ApiCost float64 `json:"api_cost"` // API调用成本
TaxIncome float64 `json:"tax_income"` // 提现收税
Profit float64 `json:"profit"` // 利润
ProfitRate float64 `json:"profit_rate"` // 利润率
}
// 趋势数据
AdminTrendData {

View File

@@ -279,6 +279,10 @@ service main {
// 下架单个模块(创建订单并支付)
@handler OfflineFeature
post /whitelist/offline (OfflineFeatureReq) returns (OfflineFeatureResp)
// 检查订单是否属于当前代理推广
@handler CheckOrderAgent
get /order/agent (CheckOrderAgentReq) returns (CheckOrderAgentResp)
}
type (
@@ -683,16 +687,16 @@ type (
}
// 检查模块白名单状态请求
CheckFeatureWhitelistStatusReq {
IdCard string `form:"id_card"` // 身份证号
IdCard string `form:"id_card"` // 身份证号
FeatureApiId string `form:"feature_api_id"` // Feature的API标识
QueryId string `form:"query_id,optional"` // 查询记录ID可选用于检查报告数据是否已删除
}
// 检查模块白名单状态响应
CheckFeatureWhitelistStatusResp {
IsWhitelisted bool `json:"is_whitelisted"` // 是否在白名单中
IsWhitelisted bool `json:"is_whitelisted"` // 是否在白名单中
WhitelistPrice float64 `json:"whitelist_price"` // 屏蔽价格单位如果为0表示不支持下架
FeatureId string `json:"feature_id"` // Feature的UUID
DataDeleted bool `json:"data_deleted"` // 报告数据是否已删除仅当提供了query_id时有效
FeatureId string `json:"feature_id"` // Feature的UUID
DataDeleted bool `json:"data_deleted"` // 报告数据是否已删除仅当提供了query_id时有效
}
// 下架单个模块请求
OfflineFeatureReq {
@@ -705,6 +709,14 @@ type (
NeedPay bool `json:"need_pay"` // 是否需要发起支付
Amount float64 `json:"amount"` // 需要支付的金额单位0表示无需支付
}
// 检查订单是否属于当前代理请求
CheckOrderAgentReq {
OrderId string `form:"order_id"` // 订单ID
}
// 检查订单是否属于当前代理响应
CheckOrderAgentResp {
IsAgentOrder bool `json:"is_agent_order"` // 是否是当前代理推广的订单
}
)
// ============================================

View File

@@ -0,0 +1,29 @@
package agent
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"ycc-server/app/main/api/internal/logic/agent"
"ycc-server/app/main/api/internal/svc"
"ycc-server/app/main/api/internal/types"
"ycc-server/common/result"
"ycc-server/pkg/lzkit/validator"
)
func CheckOrderAgentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CheckOrderAgentReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
if err := validator.Validate(req); err != nil {
result.ParamValidateErrorResult(r, w, err)
return
}
l := agent.NewCheckOrderAgentLogic(r.Context(), svcCtx)
resp, err := l.CheckOrderAgent(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@@ -715,6 +715,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/level/privilege",
Handler: agent.GetLevelPrivilegeHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/order/agent",
Handler: agent.CheckOrderAgentHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/product_config",

View File

@@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
"ycc-server/app/main/api/internal/service"
"ycc-server/app/main/api/internal/svc"
"ycc-server/app/main/api/internal/types"
@@ -224,7 +225,7 @@ func (l *AdminGetDashboardStatisticsLogic) calculateAgentStatistics(todayStart,
func (l *AdminGetDashboardStatisticsLogic) calculateProfitStatistics(todayStart, todayEnd, monthStart, monthEnd time.Time, revenueStats types.AdminRevenueStatistics) (types.AdminProfitStatistics, error) {
var stats types.AdminProfitStatistics
// 公司交税比例6%
// 税务成本比例6%
const companyTaxRate = 0.06
// 今日利润计算
@@ -244,20 +245,44 @@ func (l *AdminGetDashboardStatisticsLogic) calculateProfitStatistics(todayStart,
if err != nil {
return stats, err
}
// 今日公司交订单金额的6%
// 今日税务成本订单金额的6%
todayCompanyTax := todayRevenue * companyTaxRate
// 今日平台收入agent_withdrawal_tax表中tax_status=2的tax_amount总和
// 今日提现收agent_withdrawal_tax表中tax_status=2的tax_amount总和
todayTaxIncomeBuilder := l.svcCtx.AgentWithdrawalTaxModel.SelectBuilder().
Where("del_state = ? AND tax_status = ? AND create_time >= ? AND create_time < ?", globalkey.DelStateNo, 2, todayStart, todayEnd)
todayTaxIncome, err := l.svcCtx.AgentWithdrawalTaxModel.FindSum(l.ctx, todayTaxIncomeBuilder, "tax_amount")
if err != nil {
return stats, err
}
// 今日利润 = 营收 - 佣金 - 返利 - 公司交税 + 平台收入税
stats.TodayProfit = todayRevenue - todayCommission - todayRebate - todayCompanyTax + todayTaxIncome
// 今日API调用成本
todayApiCost := 0.0
if l.svcCtx.TianyuanapiCallLogService != nil {
todayApiStats, err := l.svcCtx.TianyuanapiCallLogService.GetStatistics(l.ctx, service.StatisticsFilter{
StartDate: todayStart,
EndDate: todayEnd,
})
if err != nil {
logx.Errorf("获取今日API调用成本失败: %v", err)
} else {
todayApiCost = todayApiStats.TotalCost
}
}
// 今日利润 = 营收 - 佣金 - 返利 - 税务成本 - API调用成本 + 提现收税
stats.TodayProfit = todayRevenue - todayCommission - todayRebate - todayCompanyTax - todayApiCost + todayTaxIncome
if todayRevenue > 0 {
stats.TodayProfitRate = stats.TodayProfit / todayRevenue * 100
}
// 今日明细
stats.TodayDetail = types.AdminProfitDetail{
Revenue: todayRevenue,
Commission: todayCommission,
Rebate: todayRebate,
CompanyTax: todayCompanyTax,
ApiCost: todayApiCost,
TaxIncome: todayTaxIncome,
Profit: stats.TodayProfit,
ProfitRate: stats.TodayProfitRate,
}
// 当月利润计算
// 当月营收
@@ -276,20 +301,44 @@ func (l *AdminGetDashboardStatisticsLogic) calculateProfitStatistics(todayStart,
if err != nil {
return stats, err
}
// 当月公司交
// 当月税务成本
monthCompanyTax := monthRevenue * companyTaxRate
// 当月平台收入
// 当月提现收
monthTaxIncomeBuilder := l.svcCtx.AgentWithdrawalTaxModel.SelectBuilder().
Where("del_state = ? AND tax_status = ? AND create_time >= ? AND create_time < ?", globalkey.DelStateNo, 2, monthStart, monthEnd)
monthTaxIncome, err := l.svcCtx.AgentWithdrawalTaxModel.FindSum(l.ctx, monthTaxIncomeBuilder, "tax_amount")
if err != nil {
return stats, err
}
// 当月API调用成本
monthApiCost := 0.0
if l.svcCtx.TianyuanapiCallLogService != nil {
monthApiStats, err := l.svcCtx.TianyuanapiCallLogService.GetStatistics(l.ctx, service.StatisticsFilter{
StartDate: monthStart,
EndDate: monthEnd,
})
if err != nil {
logx.Errorf("获取当月API调用成本失败: %v", err)
} else {
monthApiCost = monthApiStats.TotalCost
}
}
// 当月利润
stats.MonthProfit = monthRevenue - monthCommission - monthRebate - monthCompanyTax + monthTaxIncome
stats.MonthProfit = monthRevenue - monthCommission - monthRebate - monthCompanyTax - monthApiCost + monthTaxIncome
if monthRevenue > 0 {
stats.MonthProfitRate = stats.MonthProfit / monthRevenue * 100
}
// 当月明细
stats.MonthDetail = types.AdminProfitDetail{
Revenue: monthRevenue,
Commission: monthCommission,
Rebate: monthRebate,
CompanyTax: monthCompanyTax,
ApiCost: monthApiCost,
TaxIncome: monthTaxIncome,
Profit: stats.MonthProfit,
ProfitRate: stats.MonthProfitRate,
}
// 总利润计算
// 总营收
@@ -303,25 +352,46 @@ func (l *AdminGetDashboardStatisticsLogic) calculateProfitStatistics(todayStart,
}
// 总返利
totalRebateBuilder := l.svcCtx.AgentRebateModel.SelectBuilder().
Where("del_state = ? AND status != ?", globalkey.DelStateNo, 3)
Where("status != ?", 3)
totalRebate, err := l.svcCtx.AgentRebateModel.FindSum(l.ctx, totalRebateBuilder, "rebate_amount")
if err != nil {
return stats, err
}
// 总公司交
// 总税务成本
totalCompanyTax := totalRevenue * companyTaxRate
// 总平台收入
// 总提现收
totalTaxIncomeBuilder := l.svcCtx.AgentWithdrawalTaxModel.SelectBuilder().
Where("del_state = ? AND tax_status = ?", globalkey.DelStateNo, 2)
Where("tax_status = ?", 2)
totalTaxIncome, err := l.svcCtx.AgentWithdrawalTaxModel.FindSum(l.ctx, totalTaxIncomeBuilder, "tax_amount")
if err != nil {
return stats, err
}
// 总API调用成本
totalApiCost := 0.0
if l.svcCtx.TianyuanapiCallLogService != nil {
totalApiStats, err := l.svcCtx.TianyuanapiCallLogService.GetStatistics(l.ctx, service.StatisticsFilter{})
if err != nil {
logx.Errorf("获取总API调用成本失败: %v", err)
} else {
totalApiCost = totalApiStats.TotalCost
}
}
// 总利润
stats.TotalProfit = totalRevenue - totalCommission - totalRebate - totalCompanyTax + totalTaxIncome
stats.TotalProfit = totalRevenue - totalCommission - totalRebate - totalCompanyTax - totalApiCost + totalTaxIncome
if totalRevenue > 0 {
stats.TotalProfitRate = stats.TotalProfit / totalRevenue * 100
}
// 总计明细
stats.TotalDetail = types.AdminProfitDetail{
Revenue: totalRevenue,
Commission: totalCommission,
Rebate: totalRebate,
CompanyTax: totalCompanyTax,
ApiCost: totalApiCost,
TaxIncome: totalTaxIncome,
Profit: stats.TotalProfit,
ProfitRate: stats.TotalProfitRate,
}
return stats, nil
}

View File

@@ -0,0 +1,46 @@
package agent
import (
"context"
"ycc-server/app/main/api/internal/logic/query"
"ycc-server/app/main/api/internal/svc"
"ycc-server/app/main/api/internal/types"
"github.com/pkg/errors"
"ycc-server/common/ctxdata"
"ycc-server/common/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
type CheckOrderAgentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCheckOrderAgentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckOrderAgentLogic {
return &CheckOrderAgentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CheckOrderAgentLogic) CheckOrderAgent(req *types.CheckOrderAgentReq) (resp *types.CheckOrderAgentResp, err error) {
// 获取当前用户ID
userId, err := ctxdata.GetUidFromCtx(l.ctx)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取用户ID失败: %v", err)
}
// 检查订单是否属于当前代理推广
isAgent, err := query.IsOrderAgent(l.ctx, l.svcCtx, userId, req.OrderId)
if err != nil {
return nil, err
}
return &types.CheckOrderAgentResp{
IsAgentOrder: isAgent,
}, nil
}

View File

@@ -36,7 +36,7 @@ func (l *QuerySingleTestLogic) QuerySingleTest(req *types.QuerySingleTestReq) (r
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "单查测试, 序列化参数失败 : %d", err)
}
apiResp, err := l.svcCtx.ApiRequestService.PreprocessRequestApi(marshalParams, req.Api)
apiResp, err := l.svcCtx.ApiRequestService.PreprocessRequestApi(l.ctx, marshalParams, req.Api)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "单查测试, 获取接口失败 : %d", err)
}

View File

@@ -158,7 +158,7 @@ func (l *PaySuccessNotifyUserHandler) ProcessTask(ctx context.Context, t *asynq.
encryptData = encryptedEmptyData
} else {
// 正常模式调用API请求服务
combinedResponse, err := l.svcCtx.ApiRequestService.ProcessRequests(decryptData, product.Id)
combinedResponse, err := l.svcCtx.ApiRequestService.ProcessRequests(ctx, decryptData, product.Id)
if err != nil {
return l.handleError(ctx, err, order, query)
}

View File

@@ -32,6 +32,61 @@ func generateAuthDateRange() string {
return fmt.Sprintf("%s-%s", start, end)
}
// callTianyuanApiWithLog 调用天元API并记录日志
func (a *ApiRequestService) callTianyuanApiWithLog(ctx context.Context, featureID, apiID string, params map[string]interface{}) (*tianyuanapi.Response, error) {
startTime := time.Now()
resp, err := a.tianyuanapi.CallInterface(apiID, params)
responseTime := time.Since(startTime).Milliseconds()
// 如果没有提供featureID尝试从缓存中获取
if featureID == "" {
a.apiFeatureMapMutex.RLock()
featureID = a.apiFeatureMapCache[apiID]
a.apiFeatureMapMutex.RUnlock()
}
// 构建调用记录选项
callStatus := int64(0) // 默认失败
errorCode := ""
errorMessage := ""
responseData := interface{}(nil)
transactionID := ""
if err != nil {
// 调用失败
errorMessage = err.Error()
// 尝试从错误信息中提取错误码
if code := tianyuanapi.GetCodeByError(err); code != -1 {
errorCode = fmt.Sprintf("%d", code)
}
} else {
// 调用成功
callStatus = 1
responseData = resp.Data
transactionID = resp.TransactionID
}
// 异步记录调用日志(避免影响主流程)
go func() {
logOpts := CallLogOptions{
FeatureID: featureID,
ApiID: apiID,
CallStatus: callStatus,
ResponseTime: responseTime,
ErrorCode: errorCode,
ErrorMessage: errorMessage,
RequestParams: params,
ResponseData: responseData,
TransactionID: transactionID,
}
if recordErr := a.tianyuanapiCallLogService.RecordCall(context.Background(), logOpts); recordErr != nil {
logx.Errorf("记录天元API调用日志失败api_id=%s, err=%v", apiID, recordErr)
}
}()
return resp, err
}
type ApiRequestService struct {
config config.Config
featureModel model.FeatureModel
@@ -39,16 +94,22 @@ type ApiRequestService struct {
userFeatureWhitelistModel model.UserFeatureWhitelistModel
whitelistService *WhitelistService
tianyuanapi *tianyuanapi.Client
tianyuanapiCallLogService *TianyuanapiCallLogService
apiFeatureMapCache map[string]string // apiID -> featureID 缓存
apiFeatureMapMutex sync.RWMutex
}
// NewApiRequestService 是一个构造函数,用于初始化 ApiRequestService
func NewApiRequestService(c config.Config, featureModel model.FeatureModel, productFeatureModel model.ProductFeatureModel, userFeatureWhitelistModel model.UserFeatureWhitelistModel, tianyuanapi *tianyuanapi.Client) *ApiRequestService {
func NewApiRequestService(c config.Config, featureModel model.FeatureModel, productFeatureModel model.ProductFeatureModel, userFeatureWhitelistModel model.UserFeatureWhitelistModel, tianyuanapi *tianyuanapi.Client, tianyuanapiCallLogService *TianyuanapiCallLogService, whitelistService *WhitelistService) *ApiRequestService {
return &ApiRequestService{
config: c,
featureModel: featureModel,
productFeatureModel: productFeatureModel,
userFeatureWhitelistModel: userFeatureWhitelistModel,
tianyuanapi: tianyuanapi,
tianyuanapiCallLogService: tianyuanapiCallLogService,
whitelistService: whitelistService,
apiFeatureMapCache: make(map[string]string),
}
}
@@ -61,15 +122,21 @@ type APIResponseData struct {
}
// ProcessRequests 处理请求
func (a *ApiRequestService) ProcessRequests(params []byte, productID string) ([]byte, error) {
var ctx, cancel = context.WithCancel(context.Background())
func (a *ApiRequestService) ProcessRequests(ctx context.Context, params []byte, productID string) ([]byte, error) {
var cancel context.CancelFunc
ctx, cancel = context.WithCancel(ctx)
defer cancel()
// 从params中提取id_card用于白名单检查
idCard := gjson.GetBytes(params, "id_card").String()
// 查询白名单如果提供了id_card集中由 WhitelistService 处理
whitelistedFeatureApiIds, _ := a.whitelistService.GetWhitelistedFeatureApisByIdCard(ctx, idCard)
var whitelistedFeatureApiIds map[string]bool
if a.whitelistService != nil {
whitelistedFeatureApiIds, _ = a.whitelistService.GetWhitelistedFeatureApisByIdCard(ctx, idCard)
} else {
whitelistedFeatureApiIds = make(map[string]bool)
}
build := a.productFeatureModel.SelectBuilder().Where(squirrel.Eq{
"product_id": productID,
@@ -95,6 +162,13 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID string) ([]
if len(featureList) == 0 {
return nil, errors.New("处理请求错误,产品无对应接口功能")
}
// 缓存apiID到featureID的映射关系供后续调用记录使用
a.apiFeatureMapMutex.Lock()
for _, feature := range featureList {
a.apiFeatureMapCache[feature.ApiId] = feature.Id
}
a.apiFeatureMapMutex.Unlock()
var (
wg sync.WaitGroup
resultsCh = make(chan APIResponseData, len(featureList))
@@ -140,7 +214,7 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID string) ([]
tryCount := 0
for {
tryCount++
resp, preprocessErr = a.PreprocessRequestApi(params, feature.ApiId)
resp, preprocessErr = a.PreprocessRequestApi(ctx, params, feature.ApiId)
if preprocessErr == nil {
break
}
@@ -197,7 +271,7 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID string) ([]
}
// ------------------------------------请求处理器--------------------------
var requestProcessors = map[string]func(*ApiRequestService, []byte) ([]byte, error){
var requestProcessors = map[string]func(*ApiRequestService, context.Context, []byte) ([]byte, error){
"PersonEnterprisePro": (*ApiRequestService).ProcessPersonEnterpriseProRequest,
"BehaviorRiskScan": (*ApiRequestService).ProcessBehaviorRiskScanRequest,
"YYSYBE08": (*ApiRequestService).ProcessYYSYBE08Request,
@@ -232,16 +306,16 @@ var requestProcessors = map[string]func(*ApiRequestService, []byte) ([]byte, err
}
// PreprocessRequestApi 调用指定的请求处理函数
func (a *ApiRequestService) PreprocessRequestApi(params []byte, apiID string) ([]byte, error) {
func (a *ApiRequestService) PreprocessRequestApi(ctx context.Context, params []byte, apiID string) ([]byte, error) {
if processor, exists := requestProcessors[apiID]; exists {
return processor(a, params) // 调用 ApiRequestService 方法
return processor(a, ctx, params) // 调用 ApiRequestService 方法
}
return nil, errors.New("api请求, 未找到相应的处理程序")
}
// PersonEnterprisePro 人企业关系加强版
func (a *ApiRequestService) ProcessPersonEnterpriseProRequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessPersonEnterpriseProRequest(ctx context.Context, params []byte) ([]byte, error) {
idCard := gjson.GetBytes(params, "id_card")
// 设置最大调用次数上限
maxApiCalls := 20 // 允许最多查询20个企业
@@ -250,7 +324,7 @@ func (a *ApiRequestService) ProcessPersonEnterpriseProRequest(params []byte) ([]
return nil, errors.New("api请求, PersonEnterprisePro, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("QYGLB4C0", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "QYGLB4C0", map[string]interface{}{
"id_card": idCard.String(),
})
if err != nil {
@@ -452,7 +526,7 @@ func (a *ApiRequestService) ProcessPersonEnterpriseProRequest(params []byte) ([]
}
// 调用QYGL8271接口获取企业涉诉信息
lawsuitResp, err := a.tianyuanapi.CallInterface("QYGL8271", map[string]interface{}{
lawsuitResp, err := a.callTianyuanApiWithLog(ctx, "", "QYGL8271", map[string]interface{}{
"ent_name": orgName.String(),
"ent_code": creditCode.String(),
"auth_date": generateAuthDateRange(),
@@ -576,14 +650,14 @@ func (a *ApiRequestService) ProcessPersonEnterpriseProRequest(params []byte) ([]
}
// ProcesFLXG0V4BRequest 个人司法涉诉(详版)
func (a *ApiRequestService) ProcessFLXG0V4BRequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessFLXG0V4BRequest(ctx context.Context, params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
if !name.Exists() || !idCard.Exists() {
return nil, errors.New("api请求, FLXG0V4B, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("FLXG0V4B", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "FLXG0V4B", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"auth_date": generateAuthDateRange(),
@@ -599,13 +673,13 @@ func (a *ApiRequestService) ProcessFLXG0V4BRequest(params []byte) ([]byte, error
}
// ProcessFLXG0687Request 反诈反赌核验
func (a *ApiRequestService) ProcessFLXG0687Request(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessFLXG0687Request(ctx context.Context, params []byte) ([]byte, error) {
idCard := gjson.GetBytes(params, "id_card")
if !idCard.Exists() {
return nil, errors.New("api请求, FLXG0687, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("FLXG0687", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "FLXG0687", map[string]interface{}{
"id_card": idCard.String(),
})
@@ -627,7 +701,7 @@ func (a *ApiRequestService) ProcessFLXG0687Request(params []byte) ([]byte, error
}
// ProcessFLXG3D56Request 违约失信
func (a *ApiRequestService) ProcessFLXG3D56Request(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessFLXG3D56Request(ctx context.Context, params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
mobile := gjson.GetBytes(params, "mobile")
@@ -635,7 +709,7 @@ func (a *ApiRequestService) ProcessFLXG3D56Request(params []byte) ([]byte, error
return nil, errors.New("api请求, FLXG3D56, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("FLXG3D56", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "FLXG3D56", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"mobile_no": mobile.String(),
@@ -682,14 +756,14 @@ func (a *ApiRequestService) ProcessFLXG3D56Request(params []byte) ([]byte, error
}
// ProcessIVYZ5733Request 婚姻状况
func (a *ApiRequestService) ProcessIVYZ5733Request(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessIVYZ5733Request(ctx context.Context, params []byte) ([]byte, error) {
idCard := gjson.GetBytes(params, "id_card")
name := gjson.GetBytes(params, "name")
if !idCard.Exists() || !name.Exists() {
return nil, errors.New("api请求, IVYZ5733, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("IVYZ5733", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "IVYZ5733", map[string]interface{}{
"id_card": idCard.String(),
"name": name.String(),
})
@@ -738,14 +812,14 @@ func (a *ApiRequestService) ProcessIVYZ5733Request(params []byte) ([]byte, error
}
// ProcessIVYZ9A2BRequest 学历查询
func (a *ApiRequestService) ProcessIVYZ9A2BRequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessIVYZ9A2BRequest(ctx context.Context, params []byte) ([]byte, error) {
idCard := gjson.GetBytes(params, "id_card")
name := gjson.GetBytes(params, "name")
if !idCard.Exists() || !name.Exists() {
return nil, errors.New("api请求, IVYZ9A2B, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("IVYZ9A2B", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "IVYZ9A2B", map[string]interface{}{
"id_card": idCard.String(),
"name": name.String(),
})
@@ -809,14 +883,14 @@ func (a *ApiRequestService) ProcessIVYZ9A2BRequest(params []byte) ([]byte, error
}
// ProcessYYSYBE08Request 二要素
func (a *ApiRequestService) ProcessYYSYBE08Request(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessYYSYBE08Request(ctx context.Context, params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
if !name.Exists() || !idCard.Exists() {
return nil, errors.New("api请求, YYSYBE08, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("YYSYBE08", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "YYSYBE08", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
})
@@ -850,7 +924,7 @@ func (a *ApiRequestService) ProcessYYSYBE08Request(params []byte) ([]byte, error
}
// ProcessJRZQ0A03Request 借贷申请
func (a *ApiRequestService) ProcessJRZQ0A03Request(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessJRZQ0A03Request(ctx context.Context, params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
mobile := gjson.GetBytes(params, "mobile")
@@ -858,7 +932,7 @@ func (a *ApiRequestService) ProcessJRZQ0A03Request(params []byte) ([]byte, error
return nil, errors.New("api请求, JRZQ0A03, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("JRZQ0A03", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "JRZQ0A03", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"mobile_no": mobile.String(),
@@ -907,7 +981,7 @@ func (a *ApiRequestService) ProcessJRZQ0A03Request(params []byte) ([]byte, error
}
// ProcessJRZQ8203Request 借贷行为
func (a *ApiRequestService) ProcessJRZQ8203Request(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessJRZQ8203Request(ctx context.Context, params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
mobile := gjson.GetBytes(params, "mobile")
@@ -915,7 +989,7 @@ func (a *ApiRequestService) ProcessJRZQ8203Request(params []byte) ([]byte, error
return nil, errors.New("api请求, JRZQ8203, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("JRZQ8203", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "JRZQ8203", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"mobile_no": mobile.String(),
@@ -964,7 +1038,7 @@ func (a *ApiRequestService) ProcessJRZQ8203Request(params []byte) ([]byte, error
}
// ProcessJRZQ4AA8Request 还款压力
func (a *ApiRequestService) ProcessJRZQ4AA8Request(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessJRZQ4AA8Request(ctx context.Context, params []byte) ([]byte, error) {
idCard := gjson.GetBytes(params, "id_card")
name := gjson.GetBytes(params, "name")
mobile := gjson.GetBytes(params, "mobile")
@@ -972,7 +1046,7 @@ func (a *ApiRequestService) ProcessJRZQ4AA8Request(params []byte) ([]byte, error
return nil, errors.New("api请求, JRZQ4AA8, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("JRZQ4AA8", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "JRZQ4AA8", map[string]interface{}{
"id_card": idCard.String(),
"name": name.String(),
"mobile_no": mobile.String(),
@@ -1013,7 +1087,7 @@ func (a *ApiRequestService) ProcessJRZQ4AA8Request(params []byte) ([]byte, error
}
// ProcessQYGL8271Request 企业涉诉
func (a *ApiRequestService) ProcessQYGL8271Request(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessQYGL8271Request(ctx context.Context, params []byte) ([]byte, error) {
entName := gjson.GetBytes(params, "ent_name")
entCode := gjson.GetBytes(params, "ent_code")
@@ -1021,7 +1095,7 @@ func (a *ApiRequestService) ProcessQYGL8271Request(params []byte) ([]byte, error
return nil, errors.New("api请求, QYGL8271, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("QYGL8271", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "QYGL8271", map[string]interface{}{
"ent_name": entName.String(),
"ent_code": entCode.String(),
})
@@ -1073,13 +1147,13 @@ func (a *ApiRequestService) ProcessQYGL8271Request(params []byte) ([]byte, error
}
// ProcessQYGL6F2DRequest 人企关联
func (a *ApiRequestService) ProcessQYGL6F2DRequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessQYGL6F2DRequest(ctx context.Context, params []byte) ([]byte, error) {
idCard := gjson.GetBytes(params, "id_card")
if !idCard.Exists() {
return nil, errors.New("api请求, QYGL6F2D, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("QYGL6F2D", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "QYGL6F2D", map[string]interface{}{
"id_card": idCard.String(),
})
@@ -1114,13 +1188,13 @@ func (a *ApiRequestService) ProcessQYGL6F2DRequest(params []byte) ([]byte, error
}
// ProcessQCXG7A2BRequest 名下车辆
func (a *ApiRequestService) ProcessQCXG7A2BRequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessQCXG7A2BRequest(ctx context.Context, params []byte) ([]byte, error) {
idCard := gjson.GetBytes(params, "id_card")
if !idCard.Exists() {
return nil, errors.New("api请求, QCXG7A2B, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("QCXG7A2B", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "QCXG7A2B", map[string]interface{}{
"id_card": idCard.String(),
})
@@ -1132,7 +1206,7 @@ func (a *ApiRequestService) ProcessQCXG7A2BRequest(params []byte) ([]byte, error
}
// ProcessYYSY09CDRequest 三要素
func (a *ApiRequestService) ProcessYYSY09CDRequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessYYSY09CDRequest(ctx context.Context, params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
mobile := gjson.GetBytes(params, "mobile")
@@ -1140,7 +1214,7 @@ func (a *ApiRequestService) ProcessYYSY09CDRequest(params []byte) ([]byte, error
return nil, errors.New("api请求, YYSY09CD, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("YYSY09CD", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "YYSY09CD", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"mobile_no": mobile.String(),
@@ -1175,7 +1249,7 @@ func (a *ApiRequestService) ProcessYYSY09CDRequest(params []byte) ([]byte, error
}
// ProcessBehaviorRiskScanRequest 行为风险扫描
func (a *ApiRequestService) ProcessBehaviorRiskScanRequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessBehaviorRiskScanRequest(ctx context.Context, params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
@@ -1197,7 +1271,7 @@ func (a *ApiRequestService) ProcessBehaviorRiskScanRequest(params []byte) ([]byt
// 反赌反诈
go func() {
defer wg.Done()
respBytes, err := a.ProcessFLXG0687Request(params)
respBytes, err := a.ProcessFLXG0687Request(ctx, params)
results <- apiResult{name: "anti_fraud_gaming", data: respBytes, err: err}
}()
@@ -1242,7 +1316,7 @@ func (a *ApiRequestService) ProcessBehaviorRiskScanRequest(params []byte) ([]byt
}
// ProcessDWBG8B4DRequest 谛听多维报告
func (a *ApiRequestService) ProcessDWBG8B4DRequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessDWBG8B4DRequest(ctx context.Context, params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
mobile := gjson.GetBytes(params, "mobile")
@@ -1251,7 +1325,7 @@ func (a *ApiRequestService) ProcessDWBG8B4DRequest(params []byte) ([]byte, error
return nil, errors.New("api请求, DWBG8B4D, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("DWBG8B4D", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "DWBG8B4D", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"mobile_no": mobile.String(),
@@ -1267,7 +1341,7 @@ func (a *ApiRequestService) ProcessDWBG8B4DRequest(params []byte) ([]byte, error
}
// ProcessDWBG6A2CRequest 司南报告服务
func (a *ApiRequestService) ProcessDWBG6A2CRequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessDWBG6A2CRequest(ctx context.Context, params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
mobile := gjson.GetBytes(params, "mobile")
@@ -1276,7 +1350,7 @@ func (a *ApiRequestService) ProcessDWBG6A2CRequest(params []byte) ([]byte, error
return nil, errors.New("api请求, DWBG6A2C, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("DWBG6A2C", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "DWBG6A2C", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"mobile_no": mobile.String(),
@@ -1292,7 +1366,7 @@ func (a *ApiRequestService) ProcessDWBG6A2CRequest(params []byte) ([]byte, error
}
// ProcessJRZQ4B6CRequest 探针C风险评估
func (a *ApiRequestService) ProcessJRZQ4B6CRequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessJRZQ4B6CRequest(ctx context.Context, params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
mobile := gjson.GetBytes(params, "mobile")
@@ -1300,7 +1374,7 @@ func (a *ApiRequestService) ProcessJRZQ4B6CRequest(params []byte) ([]byte, error
return nil, errors.New("api请求, JRZQ4B6C, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("JRZQ4B6C", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "JRZQ4B6C", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"mobile_no": mobile.String(),
@@ -1316,7 +1390,7 @@ func (a *ApiRequestService) ProcessJRZQ4B6CRequest(params []byte) ([]byte, error
}
// ProcessJRZQ09J8Request 收入评估
func (a *ApiRequestService) ProcessJRZQ09J8Request(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessJRZQ09J8Request(ctx context.Context, params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
mobile := gjson.GetBytes(params, "mobile")
@@ -1324,7 +1398,7 @@ func (a *ApiRequestService) ProcessJRZQ09J8Request(params []byte) ([]byte, error
return nil, errors.New("api请求, JRZQ09J8, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("JRZQ09J8", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "JRZQ09J8", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"mobile_no": mobile.String(),
@@ -1340,7 +1414,7 @@ func (a *ApiRequestService) ProcessJRZQ09J8Request(params []byte) ([]byte, error
}
// ProcessJRZQ5E9FRequest 借选指数
func (a *ApiRequestService) ProcessJRZQ5E9FRequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessJRZQ5E9FRequest(ctx context.Context, params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
mobile := gjson.GetBytes(params, "mobile")
@@ -1348,7 +1422,7 @@ func (a *ApiRequestService) ProcessJRZQ5E9FRequest(params []byte) ([]byte, error
return nil, errors.New("api请求, JRZQ5E9F, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("JRZQ5E9F", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "JRZQ5E9F", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"mobile_no": mobile.String(),
@@ -1364,13 +1438,13 @@ func (a *ApiRequestService) ProcessJRZQ5E9FRequest(params []byte) ([]byte, error
}
// ProcessQYGL3F8ERequest 人企关系加强版2
func (a *ApiRequestService) ProcessQYGL3F8ERequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessQYGL3F8ERequest(ctx context.Context, params []byte) ([]byte, error) {
idCard := gjson.GetBytes(params, "id_card")
if !idCard.Exists() {
return nil, errors.New("api请求, QYGL3F8E, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("QYGL3F8E", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "QYGL3F8E", map[string]interface{}{
"id_card": idCard.String(),
})
@@ -1383,14 +1457,14 @@ func (a *ApiRequestService) ProcessQYGL3F8ERequest(params []byte) ([]byte, error
}
// ProcessIVYZ81NCRequest 婚姻,登记时间版
func (a *ApiRequestService) ProcessIVYZ81NCRequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessIVYZ81NCRequest(ctx context.Context, params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
if !name.Exists() || !idCard.Exists() {
return nil, errors.New("api请求, IVYZ81NC, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("IVYZ81NC", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "IVYZ81NC", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
})
@@ -1404,14 +1478,14 @@ func (a *ApiRequestService) ProcessIVYZ81NCRequest(params []byte) ([]byte, error
}
// ProcessIVYZ7F3ARequest 学历查询版B
func (a *ApiRequestService) ProcessIVYZ7F3ARequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessIVYZ7F3ARequest(ctx context.Context, params []byte) ([]byte, error) {
idCard := gjson.GetBytes(params, "id_card")
name := gjson.GetBytes(params, "name")
if !idCard.Exists() || !name.Exists() {
return nil, errors.New("api请求, IVYZ7F3A, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("IVYZ7F3A", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "IVYZ7F3A", map[string]interface{}{
"id_card": idCard.String(),
"name": name.String(),
"authorized": "1",
@@ -1426,7 +1500,7 @@ func (a *ApiRequestService) ProcessIVYZ7F3ARequest(params []byte) ([]byte, error
}
// ProcessDWBG7F3ARequest 多头借贷行业风险版
func (a *ApiRequestService) ProcessDWBG7F3ARequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessDWBG7F3ARequest(ctx context.Context, params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
mobile := gjson.GetBytes(params, "mobile")
@@ -1434,7 +1508,7 @@ func (a *ApiRequestService) ProcessDWBG7F3ARequest(params []byte) ([]byte, error
return nil, errors.New("api请求, DWBG7F3A, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("DWBG7F3A", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "DWBG7F3A", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"mobile_no": mobile.String(),
@@ -1449,7 +1523,7 @@ func (a *ApiRequestService) ProcessDWBG7F3ARequest(params []byte) ([]byte, error
}
// ProcessJRZQ8A2DRequest 特殊名单验证B
func (a *ApiRequestService) ProcessJRZQ8A2DRequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessJRZQ8A2DRequest(ctx context.Context, params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
mobile := gjson.GetBytes(params, "mobile")
@@ -1457,7 +1531,7 @@ func (a *ApiRequestService) ProcessJRZQ8A2DRequest(params []byte) ([]byte, error
return nil, errors.New("api请求, JRZQ8A2D, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("JRZQ8A2D", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "JRZQ8A2D", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"mobile_no": mobile.String(),
@@ -1473,13 +1547,13 @@ func (a *ApiRequestService) ProcessJRZQ8A2DRequest(params []byte) ([]byte, error
}
// ProcessYYSY8B1CRequest 手机在网时长B
func (a *ApiRequestService) ProcessYYSY8B1CRequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessYYSY8B1CRequest(ctx context.Context, params []byte) ([]byte, error) {
mobile := gjson.GetBytes(params, "mobile")
if !mobile.Exists() {
return nil, errors.New("api请求, YYSY8B1C, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("YYSY8B1C", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "YYSY8B1C", map[string]interface{}{
"mobile_no": mobile.String(),
})
@@ -1492,13 +1566,13 @@ func (a *ApiRequestService) ProcessYYSY8B1CRequest(params []byte) ([]byte, error
}
// ProcessYYSY7D3ERequest 携号转网查询
func (a *ApiRequestService) ProcessYYSY7D3ERequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessYYSY7D3ERequest(ctx context.Context, params []byte) ([]byte, error) {
mobile := gjson.GetBytes(params, "mobile")
if !mobile.Exists() {
return nil, errors.New("api请求, YYSY7D3E, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("YYSY7D3E", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "YYSY7D3E", map[string]interface{}{
"mobile_no": mobile.String(),
})
@@ -1511,7 +1585,7 @@ func (a *ApiRequestService) ProcessYYSY7D3ERequest(params []byte) ([]byte, error
}
// ProcessFLXG7E8FRequest 个人司法涉诉查询
func (a *ApiRequestService) ProcessFLXG7E8FRequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessFLXG7E8FRequest(ctx context.Context, params []byte) ([]byte, error) {
idCard := gjson.GetBytes(params, "id_card")
name := gjson.GetBytes(params, "name")
mobile := gjson.GetBytes(params, "mobile")
@@ -1519,7 +1593,7 @@ func (a *ApiRequestService) ProcessFLXG7E8FRequest(params []byte) ([]byte, error
return nil, errors.New("api请求, FLXG7E8F, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("FLXG7E8F", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "FLXG7E8F", map[string]interface{}{
"id_card": idCard.String(),
"name": name.String(),
"mobile_no": mobile.String(),
@@ -1534,7 +1608,7 @@ func (a *ApiRequestService) ProcessFLXG7E8FRequest(params []byte) ([]byte, error
}
// ProcessIVYZ8I9JRequest 互联网行为推测
func (a *ApiRequestService) ProcessIVYZ8I9JRequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessIVYZ8I9JRequest(ctx context.Context, params []byte) ([]byte, error) {
idCard := gjson.GetBytes(params, "id_card")
name := gjson.GetBytes(params, "name")
mobile := gjson.GetBytes(params, "mobile")
@@ -1542,7 +1616,7 @@ func (a *ApiRequestService) ProcessIVYZ8I9JRequest(params []byte) ([]byte, error
return nil, errors.New("api请求, IVYZ8I9J, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("IVYZ8I9J", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "IVYZ8I9J", map[string]interface{}{
"id_card": idCard.String(),
"name": name.String(),
"mobile_no": mobile.String(),
@@ -1557,7 +1631,7 @@ func (a *ApiRequestService) ProcessIVYZ8I9JRequest(params []byte) ([]byte, error
}
// ProcessJRZQ7F1ARequest 全景雷达
func (a *ApiRequestService) ProcessJRZQ7F1ARequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessJRZQ7F1ARequest(ctx context.Context, params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
mobile := gjson.GetBytes(params, "mobile")
@@ -1565,7 +1639,7 @@ func (a *ApiRequestService) ProcessJRZQ7F1ARequest(params []byte) ([]byte, error
return nil, errors.New("api请求, JRZQ7F1A, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("JRZQ7F1A", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "JRZQ7F1A", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"mobile_no": mobile.String(),
@@ -1581,14 +1655,14 @@ func (a *ApiRequestService) ProcessJRZQ7F1ARequest(params []byte) ([]byte, error
}
// ProcessIVYZ3P9MRequest 学历实时查询
func (a *ApiRequestService) ProcessIVYZ3P9MRequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessIVYZ3P9MRequest(ctx context.Context, params []byte) ([]byte, error) {
idCard := gjson.GetBytes(params, "id_card")
name := gjson.GetBytes(params, "name")
if !idCard.Exists() || !name.Exists() {
return nil, errors.New("api请求, IVYZ3P9M, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("IVYZ3P9M", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "IVYZ3P9M", map[string]interface{}{
"id_card": idCard.String(),
"name": name.String(),
})
@@ -1601,7 +1675,7 @@ func (a *ApiRequestService) ProcessIVYZ3P9MRequest(params []byte) ([]byte, error
}
// ProcessJRZQ6F2ARequest 借贷申请
func (a *ApiRequestService) ProcessJRZQ6F2ARequest(params []byte) ([]byte, error) {
func (a *ApiRequestService) ProcessJRZQ6F2ARequest(ctx context.Context, params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
mobile := gjson.GetBytes(params, "mobile")
@@ -1609,7 +1683,7 @@ func (a *ApiRequestService) ProcessJRZQ6F2ARequest(params []byte) ([]byte, error
return nil, errors.New("api请求, JRZQ6F2A, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("JRZQ6F2A", map[string]interface{}{
resp, err := a.callTianyuanApiWithLog(ctx, "", "JRZQ6F2A", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"mobile_no": mobile.String(),

View File

@@ -0,0 +1,201 @@
package service
import (
"context"
"database/sql"
"encoding/json"
"fmt"
"time"
"ycc-server/app/main/model"
"github.com/Masterminds/squirrel"
"github.com/zeromicro/go-zero/core/logx"
)
// TianyuanapiCallLogService 天元API调用记录服务
type TianyuanapiCallLogService struct {
tianyuanapiCallLogModel model.TianyuanapiCallLogModel
featureModel model.FeatureModel
}
// NewTianyuanapiCallLogService 创建天元API调用记录服务
func NewTianyuanapiCallLogService(
tianyuanapiCallLogModel model.TianyuanapiCallLogModel,
featureModel model.FeatureModel,
) *TianyuanapiCallLogService {
return &TianyuanapiCallLogService{
tianyuanapiCallLogModel: tianyuanapiCallLogModel,
featureModel: featureModel,
}
}
// CallLogOptions 调用记录选项
type CallLogOptions struct {
FeatureID string // 功能ID
ApiID string // API标识YYSYBE08
OrderID string // 订单ID可选
QueryID string // 查询ID可选
CallStatus int64 // 调用状态0=失败1=成功
ResponseTime int64 // 响应耗时(毫秒)
ErrorCode string // 错误码(失败时)
ErrorMessage string // 错误信息(失败时)
RequestParams interface{} // 请求参数(可选)
ResponseData interface{} // 响应数据(可选)
TransactionID string // 天元API流水号
}
// RecordCall 记录天元API调用
func (s *TianyuanapiCallLogService) RecordCall(ctx context.Context, opts CallLogOptions) error {
// 1. 获取feature的成本价
costPrice := 0.00
if opts.CallStatus == 1 { // 只有成功才计算成本
feature, err := s.featureModel.FindOne(ctx, opts.FeatureID)
if err == nil {
costPrice = feature.CostPrice
} else {
logx.Errorf("查询feature成本价失败feature_id=%s, err=%v", opts.FeatureID, err)
}
}
// 2. 转换参数和响应为JSON字符串
var requestParamsStr, responseDataStr *string
if opts.RequestParams != nil {
if bytes, err := json.Marshal(opts.RequestParams); err == nil {
jsonStr := string(bytes)
requestParamsStr = &jsonStr
}
}
if opts.ResponseData != nil {
// 只记录响应数据的前1000个字符避免存储过大
if bytes, err := json.Marshal(opts.ResponseData); err == nil {
jsonStr := string(bytes)
if len(jsonStr) > 1000 {
jsonStr = jsonStr[:1000] + "...[truncated]"
}
responseDataStr = &jsonStr
}
}
// 3. 构建调用记录
callTime := time.Now()
deleteTime := sql.NullTime{}
callLog := &model.TianyuanapiCallLog{
FeatureId: opts.FeatureID,
ApiId: opts.ApiID,
OrderId: sql.NullString{},
QueryId: sql.NullString{},
CallStatus: opts.CallStatus,
CallTime: callTime,
ResponseTime: sql.NullInt64{},
CostPrice: costPrice,
ErrorCode: sql.NullString{},
ErrorMessage: sql.NullString{},
RequestParams: sql.NullString{},
ResponseData: sql.NullString{},
TransactionId: sql.NullString{},
CreateTime: callTime,
UpdateTime: callTime,
DeleteTime: deleteTime,
DelState: 0,
Version: 0,
}
// 4. 填充可选字段
if opts.OrderID != "" {
callLog.OrderId = sql.NullString{String: opts.OrderID, Valid: true}
}
if opts.QueryID != "" {
callLog.QueryId = sql.NullString{String: opts.QueryID, Valid: true}
}
if opts.ResponseTime > 0 {
callLog.ResponseTime = sql.NullInt64{Int64: opts.ResponseTime, Valid: true}
}
if opts.ErrorCode != "" {
callLog.ErrorCode = sql.NullString{String: opts.ErrorCode, Valid: true}
}
if opts.ErrorMessage != "" {
callLog.ErrorMessage = sql.NullString{String: opts.ErrorMessage, Valid: true}
}
if requestParamsStr != nil {
callLog.RequestParams = sql.NullString{String: *requestParamsStr, Valid: true}
}
if responseDataStr != nil {
callLog.ResponseData = sql.NullString{String: *responseDataStr, Valid: true}
}
if opts.TransactionID != "" {
callLog.TransactionId = sql.NullString{String: opts.TransactionID, Valid: true}
}
// 5. 插入记录
_, err := s.tianyuanapiCallLogModel.Insert(ctx, nil, callLog)
if err != nil {
logx.Errorf("插入天元API调用记录失败feature_id=%s, api_id=%s, err=%v", opts.FeatureID, opts.ApiID, err)
return fmt.Errorf("插入调用记录失败: %w", err)
}
return nil
}
// GetStatistics 获取统计信息
type StatisticsFilter struct {
FeatureID string // 功能ID
ApiID string // API标识
StartDate time.Time // 开始日期
EndDate time.Time // 结束日期
}
// Statistics 统计信息
type Statistics struct {
TotalCalls int64 // 总调用次数
SuccessCalls int64 // 成功次数
FailedCalls int64 // 失败次数
TotalCost float64 // 总成本(成功调用的成本之和)
}
// GetStatistics 获取统计信息
func (s *TianyuanapiCallLogService) GetStatistics(ctx context.Context, filter StatisticsFilter) (*Statistics, error) {
builder := s.tianyuanapiCallLogModel.SelectBuilder()
// 添加过滤条件
if filter.FeatureID != "" {
builder = builder.Where(squirrel.Eq{"feature_id": filter.FeatureID})
}
if filter.ApiID != "" {
builder = builder.Where(squirrel.Eq{"api_id": filter.ApiID})
}
if !filter.StartDate.IsZero() {
builder = builder.Where(squirrel.GtOrEq{"call_time": filter.StartDate})
}
if !filter.EndDate.IsZero() {
builder = builder.Where(squirrel.Lt{"call_time": filter.EndDate})
}
// 统计总调用次数
totalCalls, err := s.tianyuanapiCallLogModel.FindCount(ctx, builder, "id")
if err != nil {
return nil, fmt.Errorf("统计总调用次数失败: %w", err)
}
// 统计成功次数
successBuilder := builder.Where(squirrel.Eq{"call_status": 1})
successCalls, err := s.tianyuanapiCallLogModel.FindCount(ctx, successBuilder, "id")
if err != nil {
return nil, fmt.Errorf("统计成功次数失败: %w", err)
}
// 统计失败次数
failedCalls := totalCalls - successCalls
// 统计总成本(仅成功调用)
totalCost, err := s.tianyuanapiCallLogModel.FindSum(ctx, successBuilder, "cost_price")
if err != nil {
return nil, fmt.Errorf("统计总成本失败: %w", err)
}
return &Statistics{
TotalCalls: totalCalls,
SuccessCalls: successCalls,
FailedCalls: failedCalls,
TotalCost: totalCost,
}, nil
}

View File

@@ -134,6 +134,9 @@ func (s *WhitelistService) GetWhitelistedFeatureApisByIdCard(
idCard string,
) (map[string]bool, error) {
result := make(map[string]bool)
if s == nil {
return result, nil
}
if idCard == "" {
return result, nil
}

View File

@@ -34,6 +34,10 @@ type ServiceContext struct {
FeatureModel model.FeatureModel
ProductFeatureModel model.ProductFeatureModel
// 天元API调用记录模型
TianyuanapiCallLogModel model.TianyuanapiCallLogModel
TianyuanapiCallLogService *service.TianyuanapiCallLogService
// 白名单相关模型
UserFeatureWhitelistModel model.UserFeatureWhitelistModel
WhitelistOrderModel model.WhitelistOrderModel
@@ -128,6 +132,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
featureModel := model.NewFeatureModel(db, cacheConf)
productFeatureModel := model.NewProductFeatureModel(db, cacheConf)
// ============================== 天元API调用记录模型 ==============================
tianyuanapiCallLogModel := model.NewTianyuanapiCallLogModel(db, cacheConf)
// ============================== 白名单相关模型 ==============================
userFeatureWhitelistModel := model.NewUserFeatureWhitelistModel(db, cacheConf)
whitelistOrderModel := model.NewWhitelistOrderModel(db, cacheConf)
@@ -196,8 +203,10 @@ func NewServiceContext(c config.Config) *ServiceContext {
alipayService := service.NewAliPayService(c)
wechatPayService := service.NewWechatPayService(c, userAuthModel, service.InitTypeWxPayPubKey)
applePayService := service.NewApplePayService(c)
apiRequestService := service.NewApiRequestService(c, featureModel, productFeatureModel, userFeatureWhitelistModel, tianyuanapi)
tianyuanapiCallLogService := service.NewTianyuanapiCallLogService(tianyuanapiCallLogModel, featureModel)
// 注意whitelistService 需要在 apiRequestService 之前创建,因为 apiRequestService 依赖它
whitelistService := service.NewWhitelistService(c, userFeatureWhitelistModel, whitelistOrderModel, whitelistOrderItemModel, queryModel, featureModel)
apiRequestService := service.NewApiRequestService(c, featureModel, productFeatureModel, userFeatureWhitelistModel, tianyuanapi, tianyuanapiCallLogService, whitelistService)
verificationService := service.NewVerificationService(c, tianyuanapi, apiRequestService)
asynqService := service.NewAsynqService(c)
agentService := service.NewAgentService(c, orderModel, agentModel, agentWalletModel,

View File

@@ -80,6 +80,14 @@ type CheckFeatureWhitelistStatusResp struct {
DataDeleted bool `json:"data_deleted"` // 报告数据是否已删除仅当提供了query_id时有效
}
type CheckOrderAgentReq struct {
OrderId string `form:"order_id"` // 订单ID
}
type CheckOrderAgentResp struct {
IsAgentOrder bool `json:"is_agent_order"` // 是否是当前代理推广的订单
}
type ConversionRateResp struct {
MyConversionRate ConversionRateData `json:"my_conversion_rate"` // 我的转化率
SubordinateConversionRate ConversionRateData `json:"subordinate_conversion_rate"` // 我的下级转化率

View File

@@ -37,13 +37,27 @@ type AdminOrderStatistics struct {
ChangeRate float64 `json:"change_rate"` // 变化率(百分比)
}
type AdminProfitDetail struct {
Revenue float64 `json:"revenue"` // 营收
Commission float64 `json:"commission"` // 佣金
Rebate float64 `json:"rebate"` // 返利
CompanyTax float64 `json:"company_tax"` // 税务成本
ApiCost float64 `json:"api_cost"` // API调用成本
TaxIncome float64 `json:"tax_income"` // 提现收税
Profit float64 `json:"profit"` // 利润
ProfitRate float64 `json:"profit_rate"` // 利润率
}
type AdminProfitStatistics struct {
TodayProfit float64 `json:"today_profit"` // 今日利润
MonthProfit float64 `json:"month_profit"` // 当月利润
TotalProfit float64 `json:"total_profit"` // 总利润
TodayProfitRate float64 `json:"today_profit_rate"` // 今日利润率
MonthProfitRate float64 `json:"month_profit_rate"` // 当月利润率
TotalProfitRate float64 `json:"total_profit_rate"` // 总利润率
TodayProfit float64 `json:"today_profit"` // 今日利润
MonthProfit float64 `json:"month_profit"` // 当月利润
TotalProfit float64 `json:"total_profit"` // 总利润
TodayProfitRate float64 `json:"today_profit_rate"` // 今日利润率
MonthProfitRate float64 `json:"month_profit_rate"` // 当月利润率
TotalProfitRate float64 `json:"total_profit_rate"` // 总利润率
TodayDetail AdminProfitDetail `json:"today_detail"`
MonthDetail AdminProfitDetail `json:"month_detail"`
TotalDetail AdminProfitDetail `json:"total_detail"`
}
type AdminQueryItem struct {

View File

@@ -67,6 +67,7 @@ type (
ApiId string `db:"api_id"` // API标识
Name string `db:"name"` // 描述
WhitelistPrice float64 `db:"whitelist_price"` // 白名单屏蔽价格(单位:元)
CostPrice float64 `db:"cost_price"` // 天远API调用成本价单位
}
)
@@ -83,11 +84,11 @@ func (m *defaultFeatureModel) Insert(ctx context.Context, session sqlx.Session,
yccFeatureApiIdKey := fmt.Sprintf("%s%v", cacheYccFeatureApiIdPrefix, data.ApiId)
yccFeatureIdKey := fmt.Sprintf("%s%v", cacheYccFeatureIdPrefix, data.Id)
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, featureRowsExpectAutoSet)
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, featureRowsExpectAutoSet)
if session != nil {
return session.ExecCtx(ctx, query, data.Id, data.DeleteTime, data.DelState, data.Version, data.ApiId, data.Name, data.WhitelistPrice)
return session.ExecCtx(ctx, query, data.Id, data.DeleteTime, data.DelState, data.Version, data.ApiId, data.Name, data.WhitelistPrice, data.CostPrice)
}
return conn.ExecCtx(ctx, query, data.Id, data.DeleteTime, data.DelState, data.Version, data.ApiId, data.Name, data.WhitelistPrice)
return conn.ExecCtx(ctx, query, data.Id, data.DeleteTime, data.DelState, data.Version, data.ApiId, data.Name, data.WhitelistPrice, data.CostPrice)
}, yccFeatureApiIdKey, yccFeatureIdKey)
}
func (m *defaultFeatureModel) insertUUID(data *Feature) {
@@ -154,9 +155,9 @@ func (m *defaultFeatureModel) Update(ctx context.Context, session sqlx.Session,
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, featureRowsWithPlaceHolder)
if session != nil {
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.WhitelistPrice, newData.Id)
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.WhitelistPrice, newData.CostPrice, newData.Id)
}
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.WhitelistPrice, newData.Id)
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.WhitelistPrice, newData.CostPrice, newData.Id)
}, yccFeatureApiIdKey, yccFeatureIdKey)
}
@@ -177,9 +178,9 @@ func (m *defaultFeatureModel) UpdateWithVersion(ctx context.Context, session sql
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, featureRowsWithPlaceHolder)
if session != nil {
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.WhitelistPrice, newData.Id, oldVersion)
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.WhitelistPrice, newData.CostPrice, newData.Id, oldVersion)
}
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.WhitelistPrice, newData.Id, oldVersion)
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.WhitelistPrice, newData.CostPrice, newData.Id, oldVersion)
}, yccFeatureApiIdKey, yccFeatureIdKey)
if err != nil {
return err

View File

@@ -0,0 +1,27 @@
package model
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ TianyuanapiCallLogModel = (*customTianyuanapiCallLogModel)(nil)
type (
// TianyuanapiCallLogModel is an interface to be customized, add more methods here,
// and implement the added methods in customTianyuanapiCallLogModel.
TianyuanapiCallLogModel interface {
tianyuanapiCallLogModel
}
customTianyuanapiCallLogModel struct {
*defaultTianyuanapiCallLogModel
}
)
// NewTianyuanapiCallLogModel returns a model for the database table.
func NewTianyuanapiCallLogModel(conn sqlx.SqlConn, c cache.CacheConf) TianyuanapiCallLogModel {
return &customTianyuanapiCallLogModel{
defaultTianyuanapiCallLogModel: newTianyuanapiCallLogModel(conn, c),
}
}

View File

@@ -0,0 +1,398 @@
// Code generated by goctl. DO NOT EDIT!
package model
import (
"context"
"database/sql"
"fmt"
"strings"
"reflect"
"time"
"github.com/Masterminds/squirrel"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
"ycc-server/common/globalkey"
)
var (
tianyuanapiCallLogFieldNames = builder.RawFieldNames(&TianyuanapiCallLog{})
tianyuanapiCallLogRows = strings.Join(tianyuanapiCallLogFieldNames, ",")
tianyuanapiCallLogRowsExpectAutoSet = strings.Join(stringx.Remove(tianyuanapiCallLogFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
tianyuanapiCallLogRowsWithPlaceHolder = strings.Join(stringx.Remove(tianyuanapiCallLogFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
cacheYccTianyuanapiCallLogIdPrefix = "cache:ycc:tianyuanapiCallLog:id:"
)
type (
tianyuanapiCallLogModel interface {
Insert(ctx context.Context, session sqlx.Session, data *TianyuanapiCallLog) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*TianyuanapiCallLog, error)
Update(ctx context.Context, session sqlx.Session, data *TianyuanapiCallLog) (sql.Result, error)
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *TianyuanapiCallLog) error
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
SelectBuilder() squirrel.SelectBuilder
DeleteSoft(ctx context.Context, session sqlx.Session, data *TianyuanapiCallLog) error
FindSum(ctx context.Context, sumBuilder squirrel.SelectBuilder, field string) (float64, error)
FindCount(ctx context.Context, countBuilder squirrel.SelectBuilder, field string) (int64, error)
FindAll(ctx context.Context, rowBuilder squirrel.SelectBuilder, orderBy string) ([]*TianyuanapiCallLog, error)
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*TianyuanapiCallLog, error)
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*TianyuanapiCallLog, int64, error)
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*TianyuanapiCallLog, error)
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*TianyuanapiCallLog, error)
Delete(ctx context.Context, session sqlx.Session, id int64) error
}
defaultTianyuanapiCallLogModel struct {
sqlc.CachedConn
table string
}
TianyuanapiCallLog struct {
Id int64 `db:"id"` // 主键ID
FeatureId string `db:"feature_id"` // 功能ID关联feature表
ApiId string `db:"api_id"` // API标识YYSYBE08
OrderId sql.NullString `db:"order_id"` // 订单ID关联order表
QueryId sql.NullString `db:"query_id"` // 查询ID关联query表
CallStatus int64 `db:"call_status"` // 调用状态0=失败1=成功
CallTime time.Time `db:"call_time"` // 调用时间
ResponseTime sql.NullInt64 `db:"response_time"` // 响应耗时(毫秒)
CostPrice float64 `db:"cost_price"` // 本次调用成本成功时从feature.cost_price获取失败时为0
ErrorCode sql.NullString `db:"error_code"` // 错误码(失败时记录)
ErrorMessage sql.NullString `db:"error_message"` // 错误信息(失败时记录)
RequestParams sql.NullString `db:"request_params"` // 请求参数JSON格式
ResponseData sql.NullString `db:"response_data"` // 响应数据JSON格式仅记录关键信息
TransactionId sql.NullString `db:"transaction_id"` // 天远API流水号
CreateTime time.Time `db:"create_time"` // 创建时间
UpdateTime time.Time `db:"update_time"` // 更新时间
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
DelState int64 `db:"del_state"` // 删除状态0=未删除1=已删除
Version int64 `db:"version"` // 版本号(乐观锁)
}
)
func newTianyuanapiCallLogModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultTianyuanapiCallLogModel {
return &defaultTianyuanapiCallLogModel{
CachedConn: sqlc.NewConn(conn, c),
table: "`tianyuanapi_call_log`",
}
}
func (m *defaultTianyuanapiCallLogModel) Insert(ctx context.Context, session sqlx.Session, data *TianyuanapiCallLog) (sql.Result, error) {
data.DelState = globalkey.DelStateNo
m.insertUUID(data)
yccTianyuanapiCallLogIdKey := fmt.Sprintf("%s%v", cacheYccTianyuanapiCallLogIdPrefix, data.Id)
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, tianyuanapiCallLogRowsExpectAutoSet)
if session != nil {
return session.ExecCtx(ctx, query, data.FeatureId, data.ApiId, data.OrderId, data.QueryId, data.CallStatus, data.CallTime, data.ResponseTime, data.CostPrice, data.ErrorCode, data.ErrorMessage, data.RequestParams, data.ResponseData, data.TransactionId, data.DeleteTime, data.DelState, data.Version)
}
return conn.ExecCtx(ctx, query, data.FeatureId, data.ApiId, data.OrderId, data.QueryId, data.CallStatus, data.CallTime, data.ResponseTime, data.CostPrice, data.ErrorCode, data.ErrorMessage, data.RequestParams, data.ResponseData, data.TransactionId, data.DeleteTime, data.DelState, data.Version)
}, yccTianyuanapiCallLogIdKey)
}
func (m *defaultTianyuanapiCallLogModel) insertUUID(data *TianyuanapiCallLog) {
t := reflect.TypeOf(data).Elem()
v := reflect.ValueOf(data).Elem()
for i := 0; i < t.NumField(); i++ {
sf := t.Field(i)
if sf.Tag.Get("db") == "id" {
f := v.Field(i)
if f.IsValid() && f.CanSet() && f.Kind() == reflect.String {
if f.String() == "" {
f.SetString(uuid.NewString())
}
}
break
}
}
}
func (m *defaultTianyuanapiCallLogModel) FindOne(ctx context.Context, id int64) (*TianyuanapiCallLog, error) {
yccTianyuanapiCallLogIdKey := fmt.Sprintf("%s%v", cacheYccTianyuanapiCallLogIdPrefix, id)
var resp TianyuanapiCallLog
err := m.QueryRowCtx(ctx, &resp, yccTianyuanapiCallLogIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", tianyuanapiCallLogRows, m.table)
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
})
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultTianyuanapiCallLogModel) Update(ctx context.Context, session sqlx.Session, data *TianyuanapiCallLog) (sql.Result, error) {
yccTianyuanapiCallLogIdKey := fmt.Sprintf("%s%v", cacheYccTianyuanapiCallLogIdPrefix, data.Id)
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, tianyuanapiCallLogRowsWithPlaceHolder)
if session != nil {
return session.ExecCtx(ctx, query, data.FeatureId, data.ApiId, data.OrderId, data.QueryId, data.CallStatus, data.CallTime, data.ResponseTime, data.CostPrice, data.ErrorCode, data.ErrorMessage, data.RequestParams, data.ResponseData, data.TransactionId, data.DeleteTime, data.DelState, data.Version, data.Id)
}
return conn.ExecCtx(ctx, query, data.FeatureId, data.ApiId, data.OrderId, data.QueryId, data.CallStatus, data.CallTime, data.ResponseTime, data.CostPrice, data.ErrorCode, data.ErrorMessage, data.RequestParams, data.ResponseData, data.TransactionId, data.DeleteTime, data.DelState, data.Version, data.Id)
}, yccTianyuanapiCallLogIdKey)
}
func (m *defaultTianyuanapiCallLogModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *TianyuanapiCallLog) error {
oldVersion := data.Version
data.Version += 1
var sqlResult sql.Result
var err error
yccTianyuanapiCallLogIdKey := fmt.Sprintf("%s%v", cacheYccTianyuanapiCallLogIdPrefix, data.Id)
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, tianyuanapiCallLogRowsWithPlaceHolder)
if session != nil {
return session.ExecCtx(ctx, query, data.FeatureId, data.ApiId, data.OrderId, data.QueryId, data.CallStatus, data.CallTime, data.ResponseTime, data.CostPrice, data.ErrorCode, data.ErrorMessage, data.RequestParams, data.ResponseData, data.TransactionId, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
}
return conn.ExecCtx(ctx, query, data.FeatureId, data.ApiId, data.OrderId, data.QueryId, data.CallStatus, data.CallTime, data.ResponseTime, data.CostPrice, data.ErrorCode, data.ErrorMessage, data.RequestParams, data.ResponseData, data.TransactionId, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
}, yccTianyuanapiCallLogIdKey)
if err != nil {
return err
}
updateCount, err := sqlResult.RowsAffected()
if err != nil {
return err
}
if updateCount == 0 {
return ErrNoRowsUpdate
}
return nil
}
func (m *defaultTianyuanapiCallLogModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *TianyuanapiCallLog) error {
data.DelState = globalkey.DelStateYes
data.DeleteTime = sql.NullTime{Time: time.Now(), Valid: true}
if err := m.UpdateWithVersion(ctx, session, data); err != nil {
return errors.Wrapf(errors.New("delete soft failed "), "TianyuanapiCallLogModel delete err : %+v", err)
}
return nil
}
func (m *defaultTianyuanapiCallLogModel) FindSum(ctx context.Context, builder squirrel.SelectBuilder, field string) (float64, error) {
if len(field) == 0 {
return 0, errors.Wrapf(errors.New("FindSum Least One Field"), "FindSum Least One Field")
}
builder = builder.Columns("IFNULL(SUM(" + field + "),0)")
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
if err != nil {
return 0, err
}
var resp float64
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
switch err {
case nil:
return resp, nil
default:
return 0, err
}
}
func (m *defaultTianyuanapiCallLogModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder, field string) (int64, error) {
if len(field) == 0 {
return 0, errors.Wrapf(errors.New("FindCount Least One Field"), "FindCount Least One Field")
}
builder = builder.Columns("COUNT(" + field + ")")
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
if err != nil {
return 0, err
}
var resp int64
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
switch err {
case nil:
return resp, nil
default:
return 0, err
}
}
func (m *defaultTianyuanapiCallLogModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*TianyuanapiCallLog, error) {
builder = builder.Columns(tianyuanapiCallLogRows)
if orderBy == "" {
builder = builder.OrderBy("id DESC")
} else {
builder = builder.OrderBy(orderBy)
}
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
if err != nil {
return nil, err
}
var resp []*TianyuanapiCallLog
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
switch err {
case nil:
return resp, nil
default:
return nil, err
}
}
func (m *defaultTianyuanapiCallLogModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*TianyuanapiCallLog, error) {
builder = builder.Columns(tianyuanapiCallLogRows)
if orderBy == "" {
builder = builder.OrderBy("id DESC")
} else {
builder = builder.OrderBy(orderBy)
}
if page < 1 {
page = 1
}
offset := (page - 1) * pageSize
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
if err != nil {
return nil, err
}
var resp []*TianyuanapiCallLog
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
switch err {
case nil:
return resp, nil
default:
return nil, err
}
}
func (m *defaultTianyuanapiCallLogModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*TianyuanapiCallLog, int64, error) {
total, err := m.FindCount(ctx, builder, "id")
if err != nil {
return nil, 0, err
}
builder = builder.Columns(tianyuanapiCallLogRows)
if orderBy == "" {
builder = builder.OrderBy("id DESC")
} else {
builder = builder.OrderBy(orderBy)
}
if page < 1 {
page = 1
}
offset := (page - 1) * pageSize
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
if err != nil {
return nil, total, err
}
var resp []*TianyuanapiCallLog
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
switch err {
case nil:
return resp, total, nil
default:
return nil, total, err
}
}
func (m *defaultTianyuanapiCallLogModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*TianyuanapiCallLog, error) {
builder = builder.Columns(tianyuanapiCallLogRows)
if preMinId > 0 {
builder = builder.Where(" id < ? ", preMinId)
}
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id DESC").Limit(uint64(pageSize)).ToSql()
if err != nil {
return nil, err
}
var resp []*TianyuanapiCallLog
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
switch err {
case nil:
return resp, nil
default:
return nil, err
}
}
func (m *defaultTianyuanapiCallLogModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*TianyuanapiCallLog, error) {
builder = builder.Columns(tianyuanapiCallLogRows)
if preMaxId > 0 {
builder = builder.Where(" id > ? ", preMaxId)
}
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id ASC").Limit(uint64(pageSize)).ToSql()
if err != nil {
return nil, err
}
var resp []*TianyuanapiCallLog
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
switch err {
case nil:
return resp, nil
default:
return nil, err
}
}
func (m *defaultTianyuanapiCallLogModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
return fn(ctx, session)
})
}
func (m *defaultTianyuanapiCallLogModel) SelectBuilder() squirrel.SelectBuilder {
return squirrel.Select().From(m.table)
}
func (m *defaultTianyuanapiCallLogModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
yccTianyuanapiCallLogIdKey := fmt.Sprintf("%s%v", cacheYccTianyuanapiCallLogIdPrefix, id)
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
if session != nil {
return session.ExecCtx(ctx, query, id)
}
return conn.ExecCtx(ctx, query, id)
}, yccTianyuanapiCallLogIdKey)
return err
}
func (m *defaultTianyuanapiCallLogModel) formatPrimary(primary interface{}) string {
return fmt.Sprintf("%s%v", cacheYccTianyuanapiCallLogIdPrefix, primary)
}
func (m *defaultTianyuanapiCallLogModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", tianyuanapiCallLogRows, m.table)
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
}
func (m *defaultTianyuanapiCallLogModel) tableName() string {
return m.table
}