510 lines
16 KiB
Go
510 lines
16 KiB
Go
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||
|
||
package models
|
||
|
||
import (
|
||
"context"
|
||
|
||
"gorm.io/gorm"
|
||
"gorm.io/gorm/clause"
|
||
"gorm.io/gorm/schema"
|
||
|
||
"go.ipao.vip/gen"
|
||
"go.ipao.vip/gen/field"
|
||
|
||
"gorm.io/plugin/dbresolver"
|
||
)
|
||
|
||
func newContentReport(db *gorm.DB, opts ...gen.DOOption) contentReportQuery {
|
||
_contentReportQuery := contentReportQuery{}
|
||
|
||
_contentReportQuery.contentReportQueryDo.UseDB(db, opts...)
|
||
_contentReportQuery.contentReportQueryDo.UseModel(&ContentReport{})
|
||
|
||
tableName := _contentReportQuery.contentReportQueryDo.TableName()
|
||
_contentReportQuery.ALL = field.NewAsterisk(tableName)
|
||
_contentReportQuery.ID = field.NewInt64(tableName, "id")
|
||
_contentReportQuery.TenantID = field.NewInt64(tableName, "tenant_id")
|
||
_contentReportQuery.ContentID = field.NewInt64(tableName, "content_id")
|
||
_contentReportQuery.ReporterID = field.NewInt64(tableName, "reporter_id")
|
||
_contentReportQuery.Reason = field.NewString(tableName, "reason")
|
||
_contentReportQuery.Detail = field.NewString(tableName, "detail")
|
||
_contentReportQuery.Status = field.NewString(tableName, "status")
|
||
_contentReportQuery.HandledBy = field.NewInt64(tableName, "handled_by")
|
||
_contentReportQuery.HandledAction = field.NewString(tableName, "handled_action")
|
||
_contentReportQuery.HandledReason = field.NewString(tableName, "handled_reason")
|
||
_contentReportQuery.HandledAt = field.NewTime(tableName, "handled_at")
|
||
_contentReportQuery.CreatedAt = field.NewTime(tableName, "created_at")
|
||
_contentReportQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||
|
||
_contentReportQuery.fillFieldMap()
|
||
|
||
return _contentReportQuery
|
||
}
|
||
|
||
type contentReportQuery struct {
|
||
contentReportQueryDo contentReportQueryDo
|
||
|
||
ALL field.Asterisk
|
||
ID field.Int64 // 主键ID。
|
||
TenantID field.Int64 // 租户ID;用途:跨租户筛选与归属;约束:必须存在。
|
||
ContentID field.Int64 // 内容ID;用途:定位被举报内容;约束:必须存在。
|
||
ReporterID field.Int64 // 举报用户ID;用途:追溯举报来源;约束:必须存在。
|
||
Reason field.String // 举报原因;用途:快速分类;约束:建议前端枚举。
|
||
Detail field.String // 举报描述;用途:补充说明与证据描述;可为空字符串。
|
||
Status field.String // 处置状态;用途:pending/approved/rejected;约束:默认 pending。
|
||
HandledBy field.Int64 // 处理人ID;用途:审计追踪;默认 0 表示未处理。
|
||
HandledAction field.String // 处理动作;用途:记录处置动作如 block/unpublish/ignore;可为空字符串。
|
||
HandledReason field.String // 处理说明;用途:超管处理备注;可为空字符串。
|
||
HandledAt field.Time // 处理时间;用途:追踪处理时效;未处理为空。
|
||
CreatedAt field.Time // 创建时间;用途:统计与排序。
|
||
UpdatedAt field.Time // 更新时间;用途:状态变化追踪。
|
||
|
||
fieldMap map[string]field.Expr
|
||
}
|
||
|
||
func (c contentReportQuery) Table(newTableName string) *contentReportQuery {
|
||
c.contentReportQueryDo.UseTable(newTableName)
|
||
return c.updateTableName(newTableName)
|
||
}
|
||
|
||
func (c contentReportQuery) As(alias string) *contentReportQuery {
|
||
c.contentReportQueryDo.DO = *(c.contentReportQueryDo.As(alias).(*gen.DO))
|
||
return c.updateTableName(alias)
|
||
}
|
||
|
||
func (c *contentReportQuery) updateTableName(table string) *contentReportQuery {
|
||
c.ALL = field.NewAsterisk(table)
|
||
c.ID = field.NewInt64(table, "id")
|
||
c.TenantID = field.NewInt64(table, "tenant_id")
|
||
c.ContentID = field.NewInt64(table, "content_id")
|
||
c.ReporterID = field.NewInt64(table, "reporter_id")
|
||
c.Reason = field.NewString(table, "reason")
|
||
c.Detail = field.NewString(table, "detail")
|
||
c.Status = field.NewString(table, "status")
|
||
c.HandledBy = field.NewInt64(table, "handled_by")
|
||
c.HandledAction = field.NewString(table, "handled_action")
|
||
c.HandledReason = field.NewString(table, "handled_reason")
|
||
c.HandledAt = field.NewTime(table, "handled_at")
|
||
c.CreatedAt = field.NewTime(table, "created_at")
|
||
c.UpdatedAt = field.NewTime(table, "updated_at")
|
||
|
||
c.fillFieldMap()
|
||
|
||
return c
|
||
}
|
||
|
||
func (c *contentReportQuery) QueryContext(ctx context.Context) (*contentReportQuery, *contentReportQueryDo) {
|
||
return c, c.contentReportQueryDo.WithContext(ctx)
|
||
}
|
||
|
||
func (c *contentReportQuery) WithContext(ctx context.Context) *contentReportQueryDo {
|
||
return c.contentReportQueryDo.WithContext(ctx)
|
||
}
|
||
|
||
func (c contentReportQuery) TableName() string { return c.contentReportQueryDo.TableName() }
|
||
|
||
func (c contentReportQuery) Alias() string { return c.contentReportQueryDo.Alias() }
|
||
|
||
func (c contentReportQuery) Columns(cols ...field.Expr) gen.Columns {
|
||
return c.contentReportQueryDo.Columns(cols...)
|
||
}
|
||
|
||
func (c *contentReportQuery) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||
_f, ok := c.fieldMap[fieldName]
|
||
if !ok || _f == nil {
|
||
return nil, false
|
||
}
|
||
_oe, ok := _f.(field.OrderExpr)
|
||
return _oe, ok
|
||
}
|
||
|
||
func (c *contentReportQuery) fillFieldMap() {
|
||
c.fieldMap = make(map[string]field.Expr, 13)
|
||
c.fieldMap["id"] = c.ID
|
||
c.fieldMap["tenant_id"] = c.TenantID
|
||
c.fieldMap["content_id"] = c.ContentID
|
||
c.fieldMap["reporter_id"] = c.ReporterID
|
||
c.fieldMap["reason"] = c.Reason
|
||
c.fieldMap["detail"] = c.Detail
|
||
c.fieldMap["status"] = c.Status
|
||
c.fieldMap["handled_by"] = c.HandledBy
|
||
c.fieldMap["handled_action"] = c.HandledAction
|
||
c.fieldMap["handled_reason"] = c.HandledReason
|
||
c.fieldMap["handled_at"] = c.HandledAt
|
||
c.fieldMap["created_at"] = c.CreatedAt
|
||
c.fieldMap["updated_at"] = c.UpdatedAt
|
||
}
|
||
|
||
func (c contentReportQuery) clone(db *gorm.DB) contentReportQuery {
|
||
c.contentReportQueryDo.ReplaceConnPool(db.Statement.ConnPool)
|
||
return c
|
||
}
|
||
|
||
func (c contentReportQuery) replaceDB(db *gorm.DB) contentReportQuery {
|
||
c.contentReportQueryDo.ReplaceDB(db)
|
||
return c
|
||
}
|
||
|
||
type contentReportQueryDo struct{ gen.DO }
|
||
|
||
func (c contentReportQueryDo) Debug() *contentReportQueryDo {
|
||
return c.withDO(c.DO.Debug())
|
||
}
|
||
|
||
func (c contentReportQueryDo) WithContext(ctx context.Context) *contentReportQueryDo {
|
||
return c.withDO(c.DO.WithContext(ctx))
|
||
}
|
||
|
||
func (c contentReportQueryDo) ReadDB() *contentReportQueryDo {
|
||
return c.Clauses(dbresolver.Read)
|
||
}
|
||
|
||
func (c contentReportQueryDo) WriteDB() *contentReportQueryDo {
|
||
return c.Clauses(dbresolver.Write)
|
||
}
|
||
|
||
func (c contentReportQueryDo) Session(config *gorm.Session) *contentReportQueryDo {
|
||
return c.withDO(c.DO.Session(config))
|
||
}
|
||
|
||
func (c contentReportQueryDo) Clauses(conds ...clause.Expression) *contentReportQueryDo {
|
||
return c.withDO(c.DO.Clauses(conds...))
|
||
}
|
||
|
||
func (c contentReportQueryDo) Returning(value interface{}, columns ...string) *contentReportQueryDo {
|
||
return c.withDO(c.DO.Returning(value, columns...))
|
||
}
|
||
|
||
func (c contentReportQueryDo) Not(conds ...gen.Condition) *contentReportQueryDo {
|
||
return c.withDO(c.DO.Not(conds...))
|
||
}
|
||
|
||
func (c contentReportQueryDo) Or(conds ...gen.Condition) *contentReportQueryDo {
|
||
return c.withDO(c.DO.Or(conds...))
|
||
}
|
||
|
||
func (c contentReportQueryDo) Select(conds ...field.Expr) *contentReportQueryDo {
|
||
return c.withDO(c.DO.Select(conds...))
|
||
}
|
||
|
||
func (c contentReportQueryDo) Where(conds ...gen.Condition) *contentReportQueryDo {
|
||
return c.withDO(c.DO.Where(conds...))
|
||
}
|
||
|
||
func (c contentReportQueryDo) Order(conds ...field.Expr) *contentReportQueryDo {
|
||
return c.withDO(c.DO.Order(conds...))
|
||
}
|
||
|
||
func (c contentReportQueryDo) Distinct(cols ...field.Expr) *contentReportQueryDo {
|
||
return c.withDO(c.DO.Distinct(cols...))
|
||
}
|
||
|
||
func (c contentReportQueryDo) Omit(cols ...field.Expr) *contentReportQueryDo {
|
||
return c.withDO(c.DO.Omit(cols...))
|
||
}
|
||
|
||
func (c contentReportQueryDo) Join(table schema.Tabler, on ...field.Expr) *contentReportQueryDo {
|
||
return c.withDO(c.DO.Join(table, on...))
|
||
}
|
||
|
||
func (c contentReportQueryDo) LeftJoin(table schema.Tabler, on ...field.Expr) *contentReportQueryDo {
|
||
return c.withDO(c.DO.LeftJoin(table, on...))
|
||
}
|
||
|
||
func (c contentReportQueryDo) RightJoin(table schema.Tabler, on ...field.Expr) *contentReportQueryDo {
|
||
return c.withDO(c.DO.RightJoin(table, on...))
|
||
}
|
||
|
||
func (c contentReportQueryDo) Group(cols ...field.Expr) *contentReportQueryDo {
|
||
return c.withDO(c.DO.Group(cols...))
|
||
}
|
||
|
||
func (c contentReportQueryDo) Having(conds ...gen.Condition) *contentReportQueryDo {
|
||
return c.withDO(c.DO.Having(conds...))
|
||
}
|
||
|
||
func (c contentReportQueryDo) Limit(limit int) *contentReportQueryDo {
|
||
return c.withDO(c.DO.Limit(limit))
|
||
}
|
||
|
||
func (c contentReportQueryDo) Offset(offset int) *contentReportQueryDo {
|
||
return c.withDO(c.DO.Offset(offset))
|
||
}
|
||
|
||
func (c contentReportQueryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *contentReportQueryDo {
|
||
return c.withDO(c.DO.Scopes(funcs...))
|
||
}
|
||
|
||
func (c contentReportQueryDo) Unscoped() *contentReportQueryDo {
|
||
return c.withDO(c.DO.Unscoped())
|
||
}
|
||
|
||
func (c contentReportQueryDo) Create(values ...*ContentReport) error {
|
||
if len(values) == 0 {
|
||
return nil
|
||
}
|
||
return c.DO.Create(values)
|
||
}
|
||
|
||
func (c contentReportQueryDo) CreateInBatches(values []*ContentReport, batchSize int) error {
|
||
return c.DO.CreateInBatches(values, batchSize)
|
||
}
|
||
|
||
// Save : !!! underlying implementation is different with GORM
|
||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||
func (c contentReportQueryDo) Save(values ...*ContentReport) error {
|
||
if len(values) == 0 {
|
||
return nil
|
||
}
|
||
return c.DO.Save(values)
|
||
}
|
||
|
||
func (c contentReportQueryDo) First() (*ContentReport, error) {
|
||
if result, err := c.DO.First(); err != nil {
|
||
return nil, err
|
||
} else {
|
||
return result.(*ContentReport), nil
|
||
}
|
||
}
|
||
|
||
func (c contentReportQueryDo) Take() (*ContentReport, error) {
|
||
if result, err := c.DO.Take(); err != nil {
|
||
return nil, err
|
||
} else {
|
||
return result.(*ContentReport), nil
|
||
}
|
||
}
|
||
|
||
func (c contentReportQueryDo) Last() (*ContentReport, error) {
|
||
if result, err := c.DO.Last(); err != nil {
|
||
return nil, err
|
||
} else {
|
||
return result.(*ContentReport), nil
|
||
}
|
||
}
|
||
|
||
func (c contentReportQueryDo) Find() ([]*ContentReport, error) {
|
||
result, err := c.DO.Find()
|
||
return result.([]*ContentReport), err
|
||
}
|
||
|
||
func (c contentReportQueryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*ContentReport, err error) {
|
||
buf := make([]*ContentReport, 0, batchSize)
|
||
err = c.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||
defer func() { results = append(results, buf...) }()
|
||
return fc(tx, batch)
|
||
})
|
||
return results, err
|
||
}
|
||
|
||
func (c contentReportQueryDo) FindInBatches(result *[]*ContentReport, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||
return c.DO.FindInBatches(result, batchSize, fc)
|
||
}
|
||
|
||
func (c contentReportQueryDo) Attrs(attrs ...field.AssignExpr) *contentReportQueryDo {
|
||
return c.withDO(c.DO.Attrs(attrs...))
|
||
}
|
||
|
||
func (c contentReportQueryDo) Assign(attrs ...field.AssignExpr) *contentReportQueryDo {
|
||
return c.withDO(c.DO.Assign(attrs...))
|
||
}
|
||
|
||
func (c contentReportQueryDo) Joins(fields ...field.RelationField) *contentReportQueryDo {
|
||
for _, _f := range fields {
|
||
c = *c.withDO(c.DO.Joins(_f))
|
||
}
|
||
return &c
|
||
}
|
||
|
||
func (c contentReportQueryDo) Preload(fields ...field.RelationField) *contentReportQueryDo {
|
||
for _, _f := range fields {
|
||
c = *c.withDO(c.DO.Preload(_f))
|
||
}
|
||
return &c
|
||
}
|
||
|
||
func (c contentReportQueryDo) FirstOrInit() (*ContentReport, error) {
|
||
if result, err := c.DO.FirstOrInit(); err != nil {
|
||
return nil, err
|
||
} else {
|
||
return result.(*ContentReport), nil
|
||
}
|
||
}
|
||
|
||
func (c contentReportQueryDo) FirstOrCreate() (*ContentReport, error) {
|
||
if result, err := c.DO.FirstOrCreate(); err != nil {
|
||
return nil, err
|
||
} else {
|
||
return result.(*ContentReport), nil
|
||
}
|
||
}
|
||
|
||
func (c contentReportQueryDo) FindByPage(offset int, limit int) (result []*ContentReport, count int64, err error) {
|
||
result, err = c.Offset(offset).Limit(limit).Find()
|
||
if err != nil {
|
||
return
|
||
}
|
||
|
||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||
count = int64(size + offset)
|
||
return
|
||
}
|
||
|
||
count, err = c.Offset(-1).Limit(-1).Count()
|
||
return
|
||
}
|
||
|
||
func (c contentReportQueryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||
count, err = c.Count()
|
||
if err != nil {
|
||
return
|
||
}
|
||
|
||
err = c.Offset(offset).Limit(limit).Scan(result)
|
||
return
|
||
}
|
||
|
||
func (c contentReportQueryDo) Scan(result interface{}) (err error) {
|
||
return c.DO.Scan(result)
|
||
}
|
||
|
||
func (c contentReportQueryDo) Delete(models ...*ContentReport) (result gen.ResultInfo, err error) {
|
||
return c.DO.Delete(models)
|
||
}
|
||
|
||
// ForceDelete performs a permanent delete (ignores soft-delete) for current scope.
|
||
func (c contentReportQueryDo) ForceDelete() (gen.ResultInfo, error) {
|
||
return c.Unscoped().Delete()
|
||
}
|
||
|
||
// Inc increases the given column by step for current scope.
|
||
func (c contentReportQueryDo) Inc(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||
// column = column + step
|
||
e := field.NewUnsafeFieldRaw("?+?", column.RawExpr(), step)
|
||
return c.DO.UpdateColumn(column, e)
|
||
}
|
||
|
||
// Dec decreases the given column by step for current scope.
|
||
func (c contentReportQueryDo) Dec(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||
// column = column - step
|
||
e := field.NewUnsafeFieldRaw("?-?", column.RawExpr(), step)
|
||
return c.DO.UpdateColumn(column, e)
|
||
}
|
||
|
||
// Sum returns SUM(column) for current scope.
|
||
func (c contentReportQueryDo) Sum(column field.Expr) (float64, error) {
|
||
var _v float64
|
||
agg := field.NewUnsafeFieldRaw("SUM(?)", column.RawExpr())
|
||
if err := c.Select(agg).Scan(&_v); err != nil {
|
||
return 0, err
|
||
}
|
||
return _v, nil
|
||
}
|
||
|
||
// Avg returns AVG(column) for current scope.
|
||
func (c contentReportQueryDo) Avg(column field.Expr) (float64, error) {
|
||
var _v float64
|
||
agg := field.NewUnsafeFieldRaw("AVG(?)", column.RawExpr())
|
||
if err := c.Select(agg).Scan(&_v); err != nil {
|
||
return 0, err
|
||
}
|
||
return _v, nil
|
||
}
|
||
|
||
// Min returns MIN(column) for current scope.
|
||
func (c contentReportQueryDo) Min(column field.Expr) (float64, error) {
|
||
var _v float64
|
||
agg := field.NewUnsafeFieldRaw("MIN(?)", column.RawExpr())
|
||
if err := c.Select(agg).Scan(&_v); err != nil {
|
||
return 0, err
|
||
}
|
||
return _v, nil
|
||
}
|
||
|
||
// Max returns MAX(column) for current scope.
|
||
func (c contentReportQueryDo) Max(column field.Expr) (float64, error) {
|
||
var _v float64
|
||
agg := field.NewUnsafeFieldRaw("MAX(?)", column.RawExpr())
|
||
if err := c.Select(agg).Scan(&_v); err != nil {
|
||
return 0, err
|
||
}
|
||
return _v, nil
|
||
}
|
||
|
||
// PluckMap returns a map[key]value for selected key/value expressions within current scope.
|
||
func (c contentReportQueryDo) PluckMap(key, val field.Expr) (map[interface{}]interface{}, error) {
|
||
do := c.Select(key, val)
|
||
rows, err := do.DO.Rows()
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
defer rows.Close()
|
||
mm := make(map[interface{}]interface{})
|
||
for rows.Next() {
|
||
var k interface{}
|
||
var v interface{}
|
||
if err := rows.Scan(&k, &v); err != nil {
|
||
return nil, err
|
||
}
|
||
mm[k] = v
|
||
}
|
||
return mm, rows.Err()
|
||
}
|
||
|
||
// Exists returns true if any record matches the given conditions.
|
||
func (c contentReportQueryDo) Exists(conds ...gen.Condition) (bool, error) {
|
||
cnt, err := c.Where(conds...).Count()
|
||
if err != nil {
|
||
return false, err
|
||
}
|
||
return cnt > 0, nil
|
||
}
|
||
|
||
// PluckIDs returns all primary key values under current scope.
|
||
func (c contentReportQueryDo) PluckIDs() ([]int64, error) {
|
||
ids := make([]int64, 0, 16)
|
||
pk := field.NewInt64(c.TableName(), "id")
|
||
if err := c.DO.Pluck(pk, &ids); err != nil {
|
||
return nil, err
|
||
}
|
||
return ids, nil
|
||
}
|
||
|
||
// GetByID finds a single record by primary key.
|
||
func (c contentReportQueryDo) GetByID(id int64) (*ContentReport, error) {
|
||
pk := field.NewInt64(c.TableName(), "id")
|
||
return c.Where(pk.Eq(id)).First()
|
||
}
|
||
|
||
// GetByIDs finds records by primary key list.
|
||
func (c contentReportQueryDo) GetByIDs(ids ...int64) ([]*ContentReport, error) {
|
||
if len(ids) == 0 {
|
||
return []*ContentReport{}, nil
|
||
}
|
||
pk := field.NewInt64(c.TableName(), "id")
|
||
return c.Where(pk.In(ids...)).Find()
|
||
}
|
||
|
||
// DeleteByID deletes records by primary key.
|
||
func (c contentReportQueryDo) DeleteByID(id int64) (gen.ResultInfo, error) {
|
||
pk := field.NewInt64(c.TableName(), "id")
|
||
return c.Where(pk.Eq(id)).Delete()
|
||
}
|
||
|
||
// DeleteByIDs deletes records by a list of primary keys.
|
||
func (c contentReportQueryDo) DeleteByIDs(ids ...int64) (gen.ResultInfo, error) {
|
||
if len(ids) == 0 {
|
||
return gen.ResultInfo{RowsAffected: 0, Error: nil}, nil
|
||
}
|
||
pk := field.NewInt64(c.TableName(), "id")
|
||
return c.Where(pk.In(ids...)).Delete()
|
||
}
|
||
|
||
func (c *contentReportQueryDo) withDO(do gen.Dao) *contentReportQueryDo {
|
||
c.DO = *do.(*gen.DO)
|
||
return c
|
||
}
|