package operate_log import ( "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/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) { tableName := domain.TableName(simple.Schema, &ValueObject{}) binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[Info]]{ Path: "/operateLog/query", SendResponseFunc: response.SendInfosResponse[Info], RequestParams: &QueryLogsQueryParams{}, ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (response.InfosData[Info], error) { errResponse := response.InfosData[Info]{ Infos: make([]Info, 0), } dbExecutor := i.DBExecutor() queryParams, err := request.ToConcrete[*QueryLogsQueryParams](params) if err != nil { return errResponse, err } conditions := sql.NewConditions() if strutils.IsStringNotEmpty(queryParams.Resource) { conditions.Like(ColumnResource, "%"+queryParams.Resource+"%") } if strutils.IsStringNotEmpty(queryParams.ResourceID) { conditions.Equal(ColumnResourceID, queryParams.ResourceID) } if strutils.IsStringNotEmpty(queryParams.Operate) { conditions.Like(ColumnOperate, "%"+queryParams.Operate+"%") } if strutils.IsStringNotEmpty(queryParams.OperatorName) { conditions.Like(ColumnOperatorName, "%"+queryParams.OperatorName+"%") } if strutils.IsStringNotEmpty(queryParams.StartOperateTime) { conditions.GreaterThanAndEqual(ColumnOperateTime, queryParams.StartOperateTime) } if strutils.IsStringNotEmpty(queryParams.EndOperateTime) { conditions.LessThanAndEqual(ColumnOperateTime, queryParams.EndOperateTime) } results, totalCount, err := database.Query(dbExecutor, &sql.QueryExecuteParams{ TableName: tableName, Conditions: conditions, PageNo: queryParams.PageNo, PageSize: queryParams.PageSize, }) if err != nil { return errResponse, err } infos := make([]Info, 0) err = sql.ParseSqlResult(results, &infos) if err != nil { return errResponse, err } return response.InfosData[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) }