gomod引用
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"gitee.com/red-future---jilin-g/common/utils"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
@@ -41,20 +40,6 @@ func (s *strategyService) CreateStrategy(ctx context.Context, req *dto.CreateStr
|
||||
return 0, gerror.Wrap(err, "权重配置序列化失败")
|
||||
}
|
||||
|
||||
// 获取当前用户信息
|
||||
userInfo, err := utils.GetUserInfo(ctx)
|
||||
if err != nil {
|
||||
return 0, gerror.Wrap(err, "获取用户信息失败")
|
||||
}
|
||||
|
||||
// 将UserName转换为int64,如果失败则使用0
|
||||
var userId int64
|
||||
if uid, ok := userInfo.UserName.(string); ok {
|
||||
if parsedId, err := strconv.ParseInt(uid, 10, 64); err == nil {
|
||||
userId = parsedId
|
||||
}
|
||||
}
|
||||
|
||||
strategy := &entity.Strategy{
|
||||
Name: req.Name,
|
||||
Description: req.Description,
|
||||
@@ -64,22 +49,15 @@ func (s *strategyService) CreateStrategy(ctx context.Context, req *dto.CreateStr
|
||||
MaxAdsPerReq: req.MaxAdsPerReq,
|
||||
Priority: req.Priority,
|
||||
Status: req.Status,
|
||||
CreatedBy: userId,
|
||||
UpdatedBy: userId,
|
||||
}
|
||||
|
||||
idStr, err := dao.Strategy.Create(ctx, strategy)
|
||||
_, err = dao.Strategy.Create(ctx, strategy)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 将字符串ID转换为int64
|
||||
parsedId, err := strconv.ParseInt(idStr, 10, 64)
|
||||
if err != nil {
|
||||
return 0, gerror.Wrap(err, "ID转换失败")
|
||||
}
|
||||
|
||||
return parsedId, nil
|
||||
// MongoDB使用ObjectId,创建成功后返回成功状态
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
// UpdateStrategy 更新策略
|
||||
@@ -115,22 +93,7 @@ func (s *strategyService) UpdateStrategy(ctx context.Context, req *dto.UpdateStr
|
||||
return 0, gerror.Wrap(err, "权重配置序列化失败")
|
||||
}
|
||||
|
||||
// 获取当前用户信息
|
||||
userInfo, err := utils.GetUserInfo(ctx)
|
||||
if err != nil {
|
||||
return 0, gerror.Wrap(err, "获取用户信息失败")
|
||||
}
|
||||
|
||||
// 将UserName转换为int64,如果失败则使用0
|
||||
var userId int64
|
||||
if uid, ok := userInfo.UserName.(string); ok {
|
||||
if parsedId, err := strconv.ParseInt(uid, 10, 64); err == nil {
|
||||
userId = parsedId
|
||||
}
|
||||
}
|
||||
|
||||
strategy := &entity.Strategy{
|
||||
Id: req.Id,
|
||||
Name: req.Name,
|
||||
Description: req.Description,
|
||||
MinConversion: req.MinConversion,
|
||||
@@ -139,7 +102,6 @@ func (s *strategyService) UpdateStrategy(ctx context.Context, req *dto.UpdateStr
|
||||
MaxAdsPerReq: req.MaxAdsPerReq,
|
||||
Priority: req.Priority,
|
||||
Status: req.Status,
|
||||
UpdatedBy: userId,
|
||||
}
|
||||
|
||||
return dao.Strategy.Update(ctx, strategy)
|
||||
@@ -178,8 +140,14 @@ func (s *strategyService) GetStrategyByID(ctx context.Context, id int64) (strate
|
||||
}
|
||||
}
|
||||
|
||||
// 将ObjectId的十六进制字符串转换为int64,如果失败则使用0
|
||||
var idInt64 int64
|
||||
if id, err := strconv.ParseInt(entity.Id.Hex(), 16, 64); err == nil {
|
||||
idInt64 = id
|
||||
}
|
||||
|
||||
return &dto.StrategyRes{
|
||||
Id: entity.Id,
|
||||
Id: idInt64,
|
||||
Name: entity.Name,
|
||||
Description: entity.Description,
|
||||
TenantLevel: "", // Strategy实体中没有TenantLevel字段,暂时设为空字符串
|
||||
@@ -191,8 +159,8 @@ func (s *strategyService) GetStrategyByID(ctx context.Context, id int64) (strate
|
||||
Status: entity.Status,
|
||||
CreatedAt: entity.CreatedAt.String(),
|
||||
UpdatedAt: entity.UpdatedAt.String(),
|
||||
CreatedBy: entity.CreatedBy,
|
||||
UpdatedBy: entity.UpdatedBy,
|
||||
CreatedBy: 0, // 这些字段在MongoBaseDO中不存在,暂时设为0
|
||||
UpdatedBy: 0,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -215,8 +183,14 @@ func (s *strategyService) GetStrategyList(ctx context.Context, req *dto.GetStrat
|
||||
}
|
||||
}
|
||||
|
||||
// 将ObjectId的十六进制字符串转换为int64,如果失败则使用0
|
||||
var idInt64 int64
|
||||
if id, err := strconv.ParseInt(entity.Id.Hex(), 16, 64); err == nil {
|
||||
idInt64 = id
|
||||
}
|
||||
|
||||
strategyList = append(strategyList, &dto.StrategyRes{
|
||||
Id: entity.Id,
|
||||
Id: idInt64,
|
||||
Name: entity.Name,
|
||||
Description: entity.Description,
|
||||
TenantLevel: "", // Strategy实体中没有TenantLevel字段,暂时设为空字符串
|
||||
@@ -228,8 +202,8 @@ func (s *strategyService) GetStrategyList(ctx context.Context, req *dto.GetStrat
|
||||
Status: entity.Status,
|
||||
CreatedAt: entity.CreatedAt.String(),
|
||||
UpdatedAt: entity.UpdatedAt.String(),
|
||||
CreatedBy: entity.CreatedBy,
|
||||
UpdatedBy: entity.UpdatedBy,
|
||||
CreatedBy: 0, // 这些字段在MongoBaseDO中不存在,暂时设为0
|
||||
UpdatedBy: 0,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user