package services import ( "cron_admin/app/http/entities/backend" "cron_admin/app/models/cronreportlogsmodel" "xorm.io/builder" ) func CronReportLogsList(request *backend.CronReportLogsListRequest, page int, limit int) (count int64, listInfo []cronreportlogsmodel.CronReportLogs, err error) { conn := builder.NewCond() if request.FuncLogId != 0 { conn = conn.And(builder.Eq{"func_log_id": request.FuncLogId}) } if request.CmdId != 0 { conn = conn.And(builder.Eq{"cmd_id": request.CmdId}) } if request.Status != 0 { conn = conn.And(builder.Eq{"status": request.Status}) } // 使用FIND_IN_SET 函数 if request.UserId != 0 { conn = conn.And(builder.Expr("FIND_IN_SET(?, user_id)", request.UserId)) } session := cronreportlogsmodel.GetInstance().GetDb().Where(conn) if page != 0 && limit != 0 { session = session.OrderBy("create_time desc").Limit(limit, (page-1)*limit) } count, err = session.FindAndCount(&listInfo) if err != nil { return } return }