f
This commit is contained in:
70
app/main/api/internal/logic/agent/offlinefeaturelogic.go
Normal file
70
app/main/api/internal/logic/agent/offlinefeaturelogic.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"qnc-server/app/main/api/internal/svc"
|
||||
"qnc-server/app/main/api/internal/types"
|
||||
"qnc-server/common/ctxdata"
|
||||
"qnc-server/common/xerr"
|
||||
)
|
||||
|
||||
type OfflineFeatureLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewOfflineFeatureLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OfflineFeatureLogic {
|
||||
return &OfflineFeatureLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *OfflineFeatureLogic) OfflineFeature(req *types.OfflineFeatureReq) (resp *types.OfflineFeatureResp, err error) {
|
||||
userID, err := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取用户信息失败, %v", err)
|
||||
}
|
||||
if req.FeatureApiId == "" || req.QueryId == "" {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("模块标识和查询记录ID不能为空"), "")
|
||||
}
|
||||
// 从 Query 获取 id_card
|
||||
query, err := l.svcCtx.QueryModel.FindOne(l.ctx, req.QueryId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询记录不存在或查询失败, %v", err)
|
||||
}
|
||||
idCard := ""
|
||||
if query.QueryParams != "" {
|
||||
var params map[string]interface{}
|
||||
if e := json.Unmarshal([]byte(query.QueryParams), ¶ms); e == nil {
|
||||
if v, ok := params["id_card"]; ok {
|
||||
if s, ok := v.(string); ok {
|
||||
idCard = s
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if idCard == "" {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("无法从查询记录中获取身份证号"), "")
|
||||
}
|
||||
needPay, amount, whitelistCreated, err := l.svcCtx.WhitelistService.ProcessOfflineFeature(l.ctx, nil, idCard, req.FeatureApiId, userID, req.QueryId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if whitelistCreated && !needPay {
|
||||
if err := l.svcCtx.WhitelistService.DeleteFeatureFromQueryData(l.ctx, nil, req.QueryId, req.FeatureApiId); err != nil {
|
||||
logx.Errorf("从报告数据中删除模块失败: %v", err)
|
||||
}
|
||||
return &types.OfflineFeatureResp{Success: true, NeedPay: false, Amount: 0}, nil
|
||||
}
|
||||
if needPay {
|
||||
return &types.OfflineFeatureResp{Success: false, NeedPay: true, Amount: amount}, nil
|
||||
}
|
||||
return &types.OfflineFeatureResp{Success: true, NeedPay: false, Amount: 0}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user