This commit is contained in:
2025-05-11 01:22:25 +08:00
parent d7f8e9c090
commit 1ecac19098
100 changed files with 1233 additions and 467 deletions

View File

@@ -52,10 +52,15 @@ func (l *QueryDetailByOrderIdLogic) QueryDetailByOrderId(req *types.QueryDetailB
}
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找报告错误: %v", err)
}
// 安全验证:确保订单属于当前用户
if order.UserId != userId {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.LOGIC_QUERY_NOT_FOUND), "无权查看此订单报告")
user, err := l.svcCtx.UserModel.FindOne(l.ctx, userId)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告查询, 查找用户错误: %v", err)
}
if user.Inside != 1 {
// 安全验证:确保订单属于当前用户
if order.UserId != userId {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.LOGIC_QUERY_NOT_FOUND), "无权查看此订单报告")
}
}
// 创建渐进式延迟策略实例
@@ -232,7 +237,6 @@ func (l *QueryDetailByOrderIdLogic) UpdateFeatureAndProductFeature(productID int
if pf.FeatureId == feature.Id { // 确保和 Feature 关联
sort = int(pf.Sort)
break // 找到第一个符合条件的就退出循环
}
}
featureData = map[string]interface{}{

View File

@@ -195,7 +195,6 @@ func (l *QueryDetailByOrderNoLogic) UpdateFeatureAndProductFeature(productID int
if pf.FeatureId == feature.Id { // 确保和 Feature 关联
sort = int(pf.Sort)
break // 找到第一个符合条件的就退出循环
}
}
featureData = map[string]interface{}{

View File

@@ -4,12 +4,13 @@ import (
"context"
"encoding/hex"
"encoding/json"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"tydata-server/common/xerr"
"tydata-server/pkg/lzkit/crypto"
"tydata-server/pkg/lzkit/lzUtils"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"tydata-server/app/user/cmd/api/internal/svc"
"tydata-server/app/user/cmd/api/internal/types"

View File

@@ -0,0 +1,152 @@
package query
// import (
// "context"
// "encoding/hex"
// "fmt"
// "tydata-server/app/user/cmd/api/internal/svc"
// "tydata-server/app/user/cmd/api/internal/types"
// "tydata-server/common/xerr"
// "github.com/jinzhu/copier"
// "github.com/pkg/errors"
// "github.com/zeromicro/go-zero/core/logx"
// )
// type QueryExampleLogic struct {
// logx.Logger
// ctx context.Context
// svcCtx *svc.ServiceContext
// }
// func NewQueryExampleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryExampleLogic {
// return &QueryExampleLogic{
// Logger: logx.WithContext(ctx),
// ctx: ctx,
// svcCtx: svcCtx,
// }
// }
// func (l *QueryExampleLogic) QueryExample(req *types.QueryExampleReq) (resp *types.QueryExampleResp, err error) {
// var exampleID int64
// switch req.Feature {
// case "backgroundcheck":
// exampleID = 508
// case "companyinfo":
// exampleID = 506
// case "homeservice":
// exampleID = 504
// case "marriage":
// exampleID = 501
// case "preloanbackgroundcheck":
// exampleID = 509
// case "rentalinfo":
// exampleID = 505
// case "riskassessment":
// exampleID = 503
// default:
// return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "示例报告, 获取示例报告失败: %v", err)
// }
// queryModel, err := l.svcCtx.QueryModel.FindOne(l.ctx, exampleID)
// if err != nil {
// return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "示例报告, 获取示例报告失败: %v", err)
// }
// var query types.Query
// query.CreateTime = queryModel.CreateTime.Format("2006-01-02 15:04:05")
// query.UpdateTime = queryModel.UpdateTime.Format("2006-01-02 15:04:05")
// // 解密查询数据
// secretKey := l.svcCtx.Config.Encrypt.SecretKey
// key, decodeErr := hex.DecodeString(secretKey)
// if decodeErr != nil {
// return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 获取AES解密解药失败, %v", err)
// }
// processParamsErr := ProcessQueryParams(queryModel.QueryParams, &query.QueryParams, key)
// if processParamsErr != nil {
// return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 报告参数处理失败: %v", processParamsErr)
// }
// processErr := ProcessQueryData(queryModel.QueryData, &query.QueryData, key)
// if processErr != nil {
// return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 报告结果处理失败: %v", processErr)
// }
// updateFeatureAndProductFeatureErr := l.UpdateFeatureAndProductFeature(queryModel.ProductId, &query.QueryData)
// if updateFeatureAndProductFeatureErr != nil {
// return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结果处理失败: %v", updateFeatureAndProductFeatureErr)
// }
// // 复制报告数据
// err = copier.Copy(&query, queryModel)
// if err != nil {
// return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 报告结构体复制失败, %v", err)
// }
// product, err := l.svcCtx.ProductModel.FindOne(l.ctx, queryModel.ProductId)
// if err != nil {
// return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "示例报告, 获取商品信息失败, %v", err)
// }
// query.ProductName = product.ProductName
// return &types.QueryExampleResp{
// Query: query,
// }, nil
// }
// func (l *QueryExampleLogic) UpdateFeatureAndProductFeature(productID int64, target *[]types.QueryItem) error {
// // 遍历 target 数组,使用倒序遍历,以便删除元素时不影响索引
// for i := len(*target) - 1; i >= 0; i-- {
// queryItem := &(*target)[i]
// // 确保 Data 为 map 类型
// data, ok := queryItem.Data.(map[string]interface{})
// if !ok {
// return fmt.Errorf("queryItem.Data 必须是 map[string]interface{} 类型")
// }
// // 从 Data 中获取 apiID
// apiID, ok := data["apiID"].(string)
// if !ok {
// return fmt.Errorf("queryItem.Data 中的 apiID 必须是字符串类型")
// }
// // 查询 Feature
// feature, err := l.svcCtx.FeatureModel.FindOneByApiId(l.ctx, apiID)
// if err != nil {
// // 如果 Feature 查不到,也要删除当前 QueryItem
// *target = append((*target)[:i], (*target)[i+1:]...)
// continue
// }
// // 查询 ProductFeatureModel
// builder := l.svcCtx.ProductFeatureModel.SelectBuilder().Where("product_id = ?", productID)
// productFeatures, err := l.svcCtx.ProductFeatureModel.FindAll(l.ctx, builder, "")
// if err != nil {
// return fmt.Errorf("查询 ProductFeatureModel 错误: %v", err)
// }
// // 遍历 productFeatures找到与 feature.ID 关联且 enable == 1 的项
// var featureData map[string]interface{}
// foundFeature := false
// for _, pf := range productFeatures {
// if pf.FeatureId == feature.Id { // 确保和 Feature 关联
// foundFeature = true
// if pf.Enable == 1 {
// featureData = map[string]interface{}{
// "featureName": feature.Name,
// "sort": pf.Sort,
// }
// break // 找到第一个符合条件的就退出循环
// }
// }
// }
// // 如果没有符合条件的 feature 或者 featureData 为空,则删除当前 queryItem
// if !foundFeature || featureData == nil {
// *target = append((*target)[:i], (*target)[i+1:]...)
// continue
// }
// // 更新 queryItem 的 Feature 字段(不是数组)
// queryItem.Feature = featureData
// }
// return nil
// }

View File

@@ -4,13 +4,14 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"tydata-server/app/user/cmd/api/internal/svc"
"tydata-server/app/user/cmd/api/internal/types"
"tydata-server/common/ctxdata"
"tydata-server/common/xerr"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/zeromicro/go-zero/core/logx"
)

View File

@@ -2,9 +2,10 @@ package query
import (
"context"
"github.com/pkg/errors"
"tydata-server/common/xerr"
"github.com/pkg/errors"
"tydata-server/app/user/cmd/api/internal/svc"
"tydata-server/app/user/cmd/api/internal/types"

View File

@@ -2,6 +2,7 @@ package query
import (
"context"
"database/sql"
"encoding/hex"
"encoding/json"
"fmt"
@@ -1380,8 +1381,8 @@ func (l *QueryServiceLogic) CacheData(params map[string]interface{}, Product str
if marshalErr != nil {
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询服务, 序列化参数失败: %+v", marshalErr)
}
outTradeNo := l.svcCtx.AlipayService.GenerateOutTradeNo()
redisKey := fmt.Sprintf("%d:%s", userID, outTradeNo)
outTradeNo := "Q_" + l.svcCtx.AlipayService.GenerateOutTradeNo()
redisKey := fmt.Sprintf(types.QueryCacheKey, userID, outTradeNo)
cacheErr := l.svcCtx.Redis.SetexCtx(l.ctx, redisKey, string(jsonData), int(2*time.Hour))
if cacheErr != nil {
return "", cacheErr
@@ -1401,16 +1402,16 @@ func (l *QueryServiceLogic) GetOrCreateUser(mobile string) (int64, error) {
return userID, nil
}
userModel, err := l.svcCtx.UserModel.FindOneByMobile(l.ctx, mobile)
userModel, err := l.svcCtx.UserModel.FindOneByMobile(l.ctx, sql.NullString{String: mobile, Valid: true})
if err != nil && !errors.Is(err, model.ErrNotFound) {
return 0, err
}
// 没有则创建账号
if userModel == nil {
userModel = &model.User{Mobile: mobile}
if len(userModel.Nickname) == 0 {
userModel.Nickname = mobile
}
userModel = &model.User{Mobile: sql.NullString{String: mobile, Valid: true}}
// if len(userModel.Nickname) == 0 {
// userModel.Nickname = mobile
// }
if transErr := l.svcCtx.UserModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
insertResult, userInsertErr := l.svcCtx.UserModel.Insert(ctx, session, userModel)
if userInsertErr != nil {

View File

@@ -3,9 +3,10 @@ package query
import (
"context"
"encoding/json"
"github.com/pkg/errors"
"tydata-server/common/xerr"
"github.com/pkg/errors"
"tydata-server/app/user/cmd/api/internal/svc"
"tydata-server/app/user/cmd/api/internal/types"