Files
bl/modules/config/service/spt.go
昔念 5967414da4
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
1
2026-04-18 17:50:42 +08:00

78 lines
1.6 KiB
Go

package service
import (
"blazing/cool"
"blazing/modules/config/model"
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
)
type SptService struct {
*cool.Service
}
func NewSptService() *SptService {
return &SptService{
&cool.Service{
Model: model.NewSptConfig(),
ListQueryOp: &cool.QueryOp{
FieldEQ: []string{"is_enable"},
AddOrderby: map[string]string{
"task_id": "asc",
},
ModifyResult: func(ctx g.Ctx, data interface{}) interface{} {
return syncSptAcquireByEnable(data)
},
},
PageQueryOp: &cool.QueryOp{
FieldEQ: []string{"is_enable", "task_id"},
KeyWordField: []string{"title", "description", "remark"},
AddOrderby: map[string]string{
"task_id": "asc",
},
ModifyResult: func(ctx g.Ctx, data interface{}) interface{} {
return syncSptAcquireByEnable(data)
},
},
},
}
}
func (s *SptService) ModifyBefore(ctx context.Context, method string, param g.MapStrAny) (err error) {
switch method {
case "Add", "Update":
if isEnable, ok := param["is_enable"]; ok {
enableVal := gconv.Int32(isEnable)
param["online"] = enableVal
}
}
return nil
}
func syncSptAcquireByEnable(data interface{}) interface{} {
if data == nil {
return data
}
if pageMap, ok := data.(g.Map); ok {
if rawList, hasList := pageMap["list"]; hasList {
pageMap["list"] = syncSptRows(rawList)
}
return pageMap
}
return syncSptRows(data)
}
func syncSptRows(raw interface{}) interface{} {
rows := gconv.SliceMap(raw)
for _, row := range rows {
enableVal := gconv.Int32(row["is_enable"])
row["online"] = enableVal
row["can_get"] = enableVal
}
return rows
}