package task_runner import ( "git.sxidc.com/go-framework/baize/convenient/domain/task_runner/task" "git.sxidc.com/go-framework/baize/framework/binding" "git.sxidc.com/go-framework/baize/framework/core/api" "git.sxidc.com/go-framework/baize/framework/core/api/request" "git.sxidc.com/go-framework/baize/framework/core/api/response" "git.sxidc.com/go-framework/baize/framework/core/application" "git.sxidc.com/go-framework/baize/framework/core/domain" "git.sxidc.com/go-framework/baize/framework/core/domain/entity" "git.sxidc.com/go-framework/baize/framework/core/infrastructure" "git.sxidc.com/go-framework/baize/framework/core/infrastructure/database" "git.sxidc.com/go-framework/baize/framework/core/infrastructure/database/sql" "git.sxidc.com/go-tools/utils/strutils" ) // Simple Bind参数 type Simple struct { // schema Schema string } func (simple *Simple) bind(binder *binding.Binder) { binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[task.Info]]{ Path: "/task/get", SendResponseFunc: response.SendInfosResponse[task.Info], RequestParams: &task.GetTaskQueryParams{}, Objects: []domain.Object{&task.Entity{}}, ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (response.InfosData[task.Info], error) { errResponse := response.InfosData[task.Info]{ Infos: make([]task.Info, 0), TotalCount: 0, PageNo: 0, } queryParams, err := request.ToConcrete[*task.GetTaskQueryParams](params) if err != nil { return errResponse, err } conditions := sql.NewConditions() if strutils.IsStringNotEmpty(queryParams.Group) { conditions.Equal(task.ColumnGroup, queryParams.Group) } if strutils.IsStringNotEmpty(queryParams.Status) { e := task.Entity{Status: queryParams.Status} err := e.TransferStatus2StatusCode() if err != nil { return errResponse, err } conditions.Equal(task.ColumnStatusCode, e.StatusCode) } if strutils.IsStringNotEmpty(queryParams.StartCreatedTime) { conditions.GreaterThanAndEqual(entity.ColumnCreatedTime, queryParams.StartCreatedTime) } if strutils.IsStringNotEmpty(queryParams.EndCreatedTime) { conditions.LessThanAndEqual(entity.ColumnCreatedTime, queryParams.EndCreatedTime) } results, totalCount, err := database.Query(i.DBExecutor(), &sql.QueryExecuteParams{ TableName: domain.TableName(simple.Schema, &task.Entity{}), Conditions: conditions, PageNo: queryParams.PageNo, PageSize: queryParams.PageSize, }) if err != nil { return errResponse, err } infos, err := task.FormInfos(results) if err != nil { return errResponse, err } return response.InfosData[task.Info]{ Infos: infos, TotalCount: totalCount, PageNo: queryParams.PageNo, }, nil }, }) } func Bind(app *application.App, simple *Simple) { binder := binding.NewBinder(app.Api().ChooseRouter(api.RouterPrefix, ""), app.Infrastructure()) simple.bind(binder) }