优化mongo,封装count逻辑,处理objectId
This commit is contained in:
@@ -12,14 +12,13 @@ import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
var (
|
||||
Strategy = strategyService{}
|
||||
)
|
||||
type strategy struct{}
|
||||
|
||||
type strategyService struct{}
|
||||
// Strategy 策略服务
|
||||
var Strategy = new(strategy)
|
||||
|
||||
// CreateStrategy 创建策略
|
||||
func (s *strategyService) CreateStrategy(ctx context.Context, req *dto.CreateStrategyReq) (id int64, err error) {
|
||||
func (s *strategy) CreateStrategy(ctx context.Context, req *dto.CreateStrategyReq) (id int64, err error) {
|
||||
// 检查策略名称是否已存在
|
||||
existingStrategy, err := dao.Strategy.GetByName(ctx, req.Name)
|
||||
if err != nil {
|
||||
@@ -63,7 +62,7 @@ func (s *strategyService) CreateStrategy(ctx context.Context, req *dto.CreateStr
|
||||
}
|
||||
|
||||
// UpdateStrategy 更新策略
|
||||
func (s *strategyService) UpdateStrategy(ctx context.Context, req *dto.UpdateStrategyReq) (affected int64, err error) {
|
||||
func (s *strategy) UpdateStrategy(ctx context.Context, req *dto.UpdateStrategyReq) (affected int64, err error) {
|
||||
// 检查策略是否存在
|
||||
existingStrategy, err := dao.Strategy.GetByID(ctx, strconv.FormatInt(req.Id, 10))
|
||||
if err != nil {
|
||||
@@ -112,7 +111,7 @@ func (s *strategyService) UpdateStrategy(ctx context.Context, req *dto.UpdateStr
|
||||
}
|
||||
|
||||
// DeleteStrategy 删除策略
|
||||
func (s *strategyService) DeleteStrategy(ctx context.Context, id int64) (affected int64, err error) {
|
||||
func (s *strategy) DeleteStrategy(ctx context.Context, id int64) (affected int64, err error) {
|
||||
// 检查策略是否存在
|
||||
existingStrategy, err := dao.Strategy.GetByID(ctx, strconv.FormatInt(id, 10))
|
||||
if err != nil {
|
||||
@@ -126,7 +125,7 @@ func (s *strategyService) DeleteStrategy(ctx context.Context, id int64) (affecte
|
||||
}
|
||||
|
||||
// GetStrategyByID 根据ID获取策略
|
||||
func (s *strategyService) GetStrategyByID(ctx context.Context, id int64) (strategy *dto.StrategyRes, err error) {
|
||||
func (s *strategy) GetStrategyByID(ctx context.Context, id int64) (strategy *dto.StrategyRes, err error) {
|
||||
entity, err := dao.Strategy.GetByID(ctx, strconv.FormatInt(id, 10))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -169,7 +168,7 @@ func (s *strategyService) GetStrategyByID(ctx context.Context, id int64) (strate
|
||||
}
|
||||
|
||||
// GetStrategyList 获取策略列表
|
||||
func (s *strategyService) GetStrategyList(ctx context.Context, req *dto.GetStrategyListReq) (res *dto.GetStrategyListRes, err error) {
|
||||
func (s *strategy) GetStrategyList(ctx context.Context, req *dto.GetStrategyListReq) (res *dto.GetStrategyListRes, err error) {
|
||||
list, total, err := dao.Strategy.GetList(ctx, req.Page, req.Size, req.TenantLevel, req.Status)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -220,6 +219,6 @@ func (s *strategyService) GetStrategyList(ctx context.Context, req *dto.GetStrat
|
||||
}
|
||||
|
||||
// GetStrategyByTenantLevel 根据租户级别获取策略
|
||||
func (s *strategyService) GetStrategyByTenantLevel(ctx context.Context, tenantLevel string) (strategy *entity.Strategy, err error) {
|
||||
func (s *strategy) GetStrategyByTenantLevel(ctx context.Context, tenantLevel string) (strategy *entity.Strategy, err error) {
|
||||
return dao.Strategy.GetByTenantLevel(ctx, tenantLevel)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user