40 lines
1.5 KiB
Go
40 lines
1.5 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
|
|
"36wisdom/biz/consts"
|
|
"36wisdom/biz/dao"
|
|
)
|
|
|
|
type nodeOption struct{}
|
|
|
|
var NodeOption = &nodeOption{}
|
|
|
|
// GetInNode 节点下启用选项(按选项 id + 节点 id 精确查询)。
|
|
func (s *nodeOption) GetInNode(ctx context.Context, optionId, nodeId int64) (gdb.Record, error) {
|
|
return dao.NodeOption.Model().Ctx(ctx).Cache(contentCache(ctx)).
|
|
Where("id", optionId).Where("node_id", nodeId).Where("status", consts.StatusEnabled).One()
|
|
}
|
|
|
|
// ListEnabledByNode 节点下启用选项,按 sort_order 升序(内容缓存)。
|
|
func (s *nodeOption) ListEnabledByNode(ctx context.Context, nodeId int64) ([]gdb.Record, error) {
|
|
return dao.NodeOption.Model().Ctx(ctx).Cache(contentCache(ctx)).
|
|
Where("node_id", nodeId).Where("status", consts.StatusEnabled).
|
|
Order("sort_order ASC").All()
|
|
}
|
|
|
|
// ListEnabledByNodeIds 批量节点下启用选项,按 sort_order 升序(内容缓存)。
|
|
func (s *nodeOption) ListEnabledByNodeIds(ctx context.Context, nodeIds []int64) ([]gdb.Record, error) {
|
|
return dao.NodeOption.Model().Ctx(ctx).Cache(contentCache(ctx)).
|
|
WhereIn("node_id", nodeIds).Where("status", consts.StatusEnabled).
|
|
Order("sort_order ASC").All()
|
|
}
|
|
|
|
// ListByOptionIds 按选项 id 批量取(终局判定用,不缓存)。
|
|
func (s *nodeOption) ListByOptionIds(ctx context.Context, optionIds []int64) ([]gdb.Record, error) {
|
|
return dao.NodeOption.Model().Ctx(ctx).WhereIn("id", optionIds).All()
|
|
}
|