package services import ( "cron_admin/app/constants/errorcode" "cron_admin/app/http/entities" "cron_admin/app/http/entities/backend" "cron_admin/app/models/cronreportchannelmodel" "cron_admin/app/repository" ) func ReportChannelCreate(param *cronreportchannelmodel.CronReportChannel) (err error) { var ( repo = repository.NewCommonRepo[cronreportchannelmodel.CronReportChannel]() ) _, err = repo.InsertOne(param) return } func ReportChannelList(param backend.ReportChannelList) (list []cronreportchannelmodel.CronReportChannel, total int64, err error) { var ( repo = repository.NewReportChannelRepo() opts = make([]repository.DBOption, 0) ) opts = append(opts, repo.WithDesc("report_channel_id")) if param.ReportChannelId > 0 { opts = append(opts, repo.WithByID(uint(param.ReportChannelId))) } if param.Status > 0 { opts = append(opts, repo.WithByStatus(param.Status)) } if param.Page > 0 || param.Limit > 0 { opts = append(opts, repo.WithPage(param.PageRequest)) } if param.ClientKey != "" { opts = append(opts, repo.WithLikeClientKey(param.ClientKey)) } if param.ClientSecret != "" { opts = append(opts, repo.WithLikeClientSecret(param.ClientSecret)) } if len(param.UpdateTime) == 2 { opts = append(opts, repo.WithByUpdateDate(param.UpdateTime[0], param.UpdateTime[1])) } if len(param.CreateTime) == 2 { opts = append(opts, repo.WithByDate(param.CreateTime[0], param.CreateTime[1])) } total, err = repo.FindAndCount(&list, opts...) return } func ReportChannelUpdate(param *cronreportchannelmodel.CronReportChannel) (total int64, err error) { var ( repo = repository.NewReportChannelRepo() opts = make([]repository.DBOption, 0) ) if param.ReportChannelId > 0 { opts = append(opts, repo.WithByID(param.ReportChannelId)) } total, err = repo.Update(param, opts...) return } func ReportChannelDelete(param entities.IdRequest) (total int64, err error) { var ( repo = repository.NewReportChannelRepo() opts = make([]repository.DBOption, 0) ) if param.Id > 0 { opts = append(opts, repo.WithByID(param.Id)) } else { return 0, errorcode.ReportChannelNotfound } total, err = repo.Delete(new(cronreportchannelmodel.CronReportChannel), opts...) return }