| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774 |
- // ==========================================================================
- // This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
- // ==========================================================================
- package internal
- import (
- "context"
- "database/sql"
- "github.com/gogf/gf/container/garray"
- "github.com/gogf/gf/database/gdb"
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/frame/gmvc"
- "github.com/gogf/gf/util/gconv"
- "strings"
- "time"
- "dashoo.cn/micro/app/model"
- )
- // SysMessageDao is the manager for logic model data accessing and custom defined data operations functions management.
- type SysMessageDao struct {
- gmvc.M // M is the core and embedded struct that inherits all chaining operations from gdb.Model.
- C sysMessageColumns // C is the short type for Columns, which contains all the column names of Table for convenient usage.
- DB gdb.DB // DB is the raw underlying database management object.
- Table string // Table is the underlying table name of the DAO.
- TableAs string // TableAs is the underlying table alias name of the DAO.
- }
- // SysMessageColumns defines and stores column names for table sys_message.
- type sysMessageColumns struct {
- Id string // 主键
- MsgTitle string // 消息标题
- MsgContent string // 消息内容
- MsgType string // 消息类别(10公告20消息30审批)
- MsgStatus string // 消息状态(10正常20关闭)
- RecvUserIds string // 接收用户
- SendType string // 发送方式 默认10 websocket推送
- OpnUrl string // 操作链接
- IsRead string // 是否已读(10否20是)
- ReadTime string // 已读时间
- Remark string // 备注
- CreatedBy string // 创建者
- CreatedName string // 创建人
- CreatedTime string // 创建时间
- UpdatedBy string // 更新者
- UpdatedName string // 更新人
- UpdatedTime string // 更新时间
- DeletedTime string // 删除时间
- }
- var (
- // SysMessage is globally public accessible object for table sys_message operations.
- SysMessage = SysMessageDao{
- M: g.DB("default").Model("sys_message").Safe(),
- DB: g.DB("default"),
- Table: "sys_message",
- C: sysMessageColumns{
- Id: "id",
- MsgTitle: "msg_title",
- MsgContent: "msg_content",
- MsgType: "msg_type",
- MsgStatus: "msg_status",
- RecvUserIds: "recv_user_ids",
- SendType: "send_type",
- OpnUrl: "opn_url",
- IsRead: "is_read",
- ReadTime: "read_time",
- Remark: "remark",
- CreatedBy: "created_by",
- CreatedName: "created_name",
- CreatedTime: "created_time",
- UpdatedBy: "updated_by",
- UpdatedName: "updated_name",
- UpdatedTime: "updated_time",
- DeletedTime: "deleted_time",
- },
- }
- )
- func NewSysMessageDao(tenant string) SysMessageDao {
- var dao SysMessageDao
- dao = SysMessageDao{
- M: g.DB(tenant).Model("sys_message").Safe(),
- DB: g.DB(tenant),
- Table: "sys_message",
- C: sysMessageColumns{
- Id: "id",
- MsgTitle: "msg_title",
- MsgContent: "msg_content",
- MsgType: "msg_type",
- MsgStatus: "msg_status",
- RecvUserIds: "recv_user_ids",
- SendType: "send_type",
- OpnUrl: "opn_url",
- IsRead: "is_read",
- ReadTime: "read_time",
- Remark: "remark",
- CreatedBy: "created_by",
- CreatedName: "created_name",
- CreatedTime: "created_time",
- UpdatedBy: "updated_by",
- UpdatedName: "updated_name",
- UpdatedTime: "updated_time",
- DeletedTime: "deleted_time",
- },
- }
- return dao
- }
- // Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
- // of current DB object and with given context in it.
- // Note that this returned DB object can be used only once, so do not assign it to
- // a global or package variable for long using.
- func (d *SysMessageDao) Ctx(ctx context.Context) *SysMessageDao {
- return &SysMessageDao{M: d.M.Ctx(ctx), Table: d.Table, TableAs: d.TableAs}
- }
- // GetCtx returns the context for current Model.
- // It returns "context.Background() i"s there's no context previously set.
- func (d *SysMessageDao) GetCtx() context.Context {
- return d.M.GetCtx()
- }
- // As sets an alias name for current table.
- func (d *SysMessageDao) As(as string) *SysMessageDao {
- return &SysMessageDao{M: d.M.As(as), Table: d.Table, TableAs: as}
- }
- // TX sets the transaction for current operation.
- func (d *SysMessageDao) TX(tx *gdb.TX) *SysMessageDao {
- return &SysMessageDao{M: d.M.TX(tx), Table: d.Table, TableAs: d.TableAs}
- }
- // Master marks the following operation on master node.
- func (d *SysMessageDao) Master() *SysMessageDao {
- return &SysMessageDao{M: d.M.Master(), Table: d.Table, TableAs: d.TableAs}
- }
- // Slave marks the following operation on slave node.
- // Note that it makes sense only if there's any slave node configured.
- func (d *SysMessageDao) Slave() *SysMessageDao {
- return &SysMessageDao{M: d.M.Slave(), Table: d.Table, TableAs: d.TableAs}
- }
- // Args sets custom arguments for model operation.
- func (d *SysMessageDao) Args(args ...interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.Args(args...), Table: d.Table, TableAs: d.TableAs}
- }
- // Handler calls each of "handlers" on current Model and returns a new Model.
- // ModelHandler is a function that handles given Model and returns a new Model that is custom modified.
- func (d *SysMessageDao) Handler(handlers ...gdb.ModelHandler) *SysMessageDao {
- return &SysMessageDao{M: d.M.Handler(handlers...), Table: d.Table, TableAs: d.TableAs}
- }
- // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
- // The parameter <table> can be joined table and its joined condition,
- // and also with its alias name, like:
- // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
- // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
- func (d *SysMessageDao) LeftJoin(table ...string) *SysMessageDao {
- return &SysMessageDao{M: d.M.LeftJoin(table...), Table: d.Table, TableAs: d.TableAs}
- }
- // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
- // The parameter <table> can be joined table and its joined condition,
- // and also with its alias name, like:
- // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
- // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
- func (d *SysMessageDao) RightJoin(table ...string) *SysMessageDao {
- return &SysMessageDao{M: d.M.RightJoin(table...), Table: d.Table, TableAs: d.TableAs}
- }
- // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
- // The parameter <table> can be joined table and its joined condition,
- // and also with its alias name, like:
- // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
- // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
- func (d *SysMessageDao) InnerJoin(table ...string) *SysMessageDao {
- return &SysMessageDao{M: d.M.InnerJoin(table...), Table: d.Table, TableAs: d.TableAs}
- }
- // Fields sets the operation fields of the model, multiple fields joined using char ','.
- // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
- func (d *SysMessageDao) Fields(fieldNamesOrMapStruct ...interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.Fields(fieldNamesOrMapStruct...), Table: d.Table, TableAs: d.TableAs}
- }
- // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
- // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
- func (d *SysMessageDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...), Table: d.Table, TableAs: d.TableAs}
- }
- // FieldCount formats and appends commonly used field "COUNT(column)" to the select fields of model.
- func (d *SysMessageDao) FieldCount(column string, as ...string) *SysMessageDao {
- return &SysMessageDao{M: d.M.FieldCount(column, as...), Table: d.Table, TableAs: d.TableAs}
- }
- // FieldSum formats and appends commonly used field "SUM(column)" to the select fields of model.
- func (d *SysMessageDao) FieldSum(column string, as ...string) *SysMessageDao {
- return &SysMessageDao{M: d.M.FieldSum(column, as...), Table: d.Table, TableAs: d.TableAs}
- }
- // FieldMin formats and appends commonly used field "MIN(column)" to the select fields of model.
- func (d *SysMessageDao) FieldMin(column string, as ...string) *SysMessageDao {
- return &SysMessageDao{M: d.M.FieldMin(column, as...), Table: d.Table, TableAs: d.TableAs}
- }
- // FieldMax formats and appends commonly used field "MAX(column)" to the select fields of model.
- func (d *SysMessageDao) FieldMax(column string, as ...string) *SysMessageDao {
- return &SysMessageDao{M: d.M.FieldMax(column, as...), Table: d.Table, TableAs: d.TableAs}
- }
- // FieldAvg formats and appends commonly used field "AVG(column)" to the select fields of model.
- func (d *SysMessageDao) FieldAvg(column string, as ...string) *SysMessageDao {
- return &SysMessageDao{M: d.M.FieldAvg(column, as...), Table: d.Table, TableAs: d.TableAs}
- }
- // Option adds extra operation option for the model.
- // Deprecated, use separate operations instead.
- func (d *SysMessageDao) Option(option int) *SysMessageDao {
- return &SysMessageDao{M: d.M.Option(option), Table: d.Table, TableAs: d.TableAs}
- }
- // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
- // the data and where attributes for empty values.
- func (d *SysMessageDao) OmitEmpty() *SysMessageDao {
- return &SysMessageDao{M: d.M.OmitEmpty(), Table: d.Table, TableAs: d.TableAs}
- }
- // OmitEmptyWhere sets optionOmitEmptyWhere option for the model, which automatically filers
- // the Where/Having parameters for "empty" values.
- func (d *SysMessageDao) OmitEmptyWhere() *SysMessageDao {
- return &SysMessageDao{M: d.M.OmitEmptyWhere(), Table: d.Table, TableAs: d.TableAs}
- }
- // OmitEmptyData sets optionOmitEmptyData option for the model, which automatically filers
- // the Data parameters for "empty" values.
- func (d *SysMessageDao) OmitEmptyData() *SysMessageDao {
- return &SysMessageDao{M: d.M.OmitEmptyData(), Table: d.Table, TableAs: d.TableAs}
- }
- // OmitNil sets optionOmitNil option for the model, which automatically filers
- // the data and where parameters for "nil" values.
- func (d *SysMessageDao) OmitNil() *SysMessageDao {
- return &SysMessageDao{M: d.M.OmitNil(), Table: d.Table, TableAs: d.TableAs}
- }
- // OmitNilWhere sets optionOmitNilWhere option for the model, which automatically filers
- // the Where/Having parameters for "nil" values.
- func (d *SysMessageDao) OmitNilWhere() *SysMessageDao {
- return &SysMessageDao{M: d.M.OmitNilWhere(), Table: d.Table, TableAs: d.TableAs}
- }
- // OmitNilData sets optionOmitNilData option for the model, which automatically filers
- // the Data parameters for "nil" values.
- func (d *SysMessageDao) OmitNilData() *SysMessageDao {
- return &SysMessageDao{M: d.M.OmitNilData(), Table: d.Table, TableAs: d.TableAs}
- }
- // Filter marks filtering the fields which does not exist in the fields of the operated table.
- // Note that this function supports only single table operations.
- // Deprecated, filter feature is automatically enabled from GoFrame v1.16.0, it is so no longer used.
- func (d *SysMessageDao) Filter() *SysMessageDao {
- return &SysMessageDao{M: d.M.Filter(), Table: d.Table, TableAs: d.TableAs}
- }
- // Where sets the condition statement for the model. The parameter <where> can be type of
- // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
- // multiple conditions will be joined into where statement using "AND".
- // Eg:
- // Where("uid=10000")
- // Where("uid", 10000)
- // Where("money>? AND name like ?", 99999, "vip_%")
- // Where("uid", 1).Where("name", "john")
- // Where("status IN (?)", g.Slice{1,2,3})
- // Where("age IN(?,?)", 18, 50)
- // Where(User{ Id : 1, UserName : "john"})
- func (d *SysMessageDao) Where(where interface{}, args ...interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.Where(where, args...), Table: d.Table, TableAs: d.TableAs}
- }
- // WherePri does the same logic as M.Where except that if the parameter <where>
- // is a single condition like int/string/float/slice, it treats the condition as the primary
- // key value. That is, if primary key is "id" and given <where> parameter as "123", the
- // WherePri function treats the condition as "id=123", but M.Where treats the condition
- // as string "123".
- func (d *SysMessageDao) WherePri(where interface{}, args ...interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WherePri(where, args...), Table: d.Table, TableAs: d.TableAs}
- }
- // Having sets the having statement for the model.
- // The parameters of this function usage are as the same as function Where.
- // See Where.
- func (d *SysMessageDao) Having(having interface{}, args ...interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.Having(having, args...), Table: d.Table, TableAs: d.TableAs}
- }
- // Wheref builds condition string using fmt.Sprintf and arguments.
- // Note that if the number of "args" is more than the place holder in "format",
- // the extra "args" will be used as the where condition arguments of the Model.
- func (d *SysMessageDao) Wheref(format string, args ...interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.Wheref(format, args...), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereLT builds "column < value" statement.
- func (d *SysMessageDao) WhereLT(column string, value interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereLT(column, value), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereLTE builds "column <= value" statement.
- func (d *SysMessageDao) WhereLTE(column string, value interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereLTE(column, value), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereGT builds "column > value" statement.
- func (d *SysMessageDao) WhereGT(column string, value interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereGT(column, value), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereGTE builds "column >= value" statement.
- func (d *SysMessageDao) WhereGTE(column string, value interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereGTE(column, value), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereBetween builds "column BETWEEN min AND max" statement.
- func (d *SysMessageDao) WhereBetween(column string, min, max interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereLike builds "column LIKE like" statement.
- func (d *SysMessageDao) WhereLike(column string, like interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereLike(column, like), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereIn builds "column IN (in)" statement.
- func (d *SysMessageDao) WhereIn(column string, in interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereIn(column, in), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereNull builds "columns[0] IS NULL AND columns[1] IS NULL ..." statement.
- func (d *SysMessageDao) WhereNull(columns ...string) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereNull(columns...), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereNotBetween builds "column NOT BETWEEN min AND max" statement.
- func (d *SysMessageDao) WhereNotBetween(column string, min, max interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereNotBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereNotLike builds "column NOT LIKE like" statement.
- func (d *SysMessageDao) WhereNotLike(column string, like interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereNotLike(column, like), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereNot builds "column != value" statement.
- func (d *SysMessageDao) WhereNot(column string, value interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereNot(column, value), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereNotIn builds "column NOT IN (in)" statement.
- func (d *SysMessageDao) WhereNotIn(column string, in interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereNotIn(column, in), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereNotNull builds "columns[0] IS NOT NULL AND columns[1] IS NOT NULL ..." statement.
- func (d *SysMessageDao) WhereNotNull(columns ...string) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereNotNull(columns...), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereOr adds "OR" condition to the where statement.
- func (d *SysMessageDao) WhereOr(where interface{}, args ...interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereOr(where, args...), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereOrf builds "OR" condition string using fmt.Sprintf and arguments.
- func (d *SysMessageDao) WhereOrf(format string, args ...interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereOrf(format, args...), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereOrLT builds "column < value" statement in "OR" conditions..
- func (d *SysMessageDao) WhereOrLT(column string, value interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereOrLT(column, value), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereOrLTE builds "column <= value" statement in "OR" conditions..
- func (d *SysMessageDao) WhereOrLTE(column string, value interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereOrLTE(column, value), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereOrGT builds "column > value" statement in "OR" conditions..
- func (d *SysMessageDao) WhereOrGT(column string, value interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereOrGT(column, value), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereOrGTE builds "column >= value" statement in "OR" conditions..
- func (d *SysMessageDao) WhereOrGTE(column string, value interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereOrGTE(column, value), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereOrBetween builds "column BETWEEN min AND max" statement in "OR" conditions.
- func (d *SysMessageDao) WhereOrBetween(column string, min, max interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereOrBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereOrLike builds "column LIKE like" statement in "OR" conditions.
- func (d *SysMessageDao) WhereOrLike(column string, like interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereOrLike(column, like), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereOrIn builds "column IN (in)" statement in "OR" conditions.
- func (d *SysMessageDao) WhereOrIn(column string, in interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereOrIn(column, in), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereOrNull builds "columns[0] IS NULL OR columns[1] IS NULL ..." statement in "OR" conditions.
- func (d *SysMessageDao) WhereOrNull(columns ...string) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereOrNull(columns...), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereOrNotBetween builds "column NOT BETWEEN min AND max" statement in "OR" conditions.
- func (d *SysMessageDao) WhereOrNotBetween(column string, min, max interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereOrNotBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereOrNotLike builds "column NOT LIKE like" statement in "OR" conditions.
- func (d *SysMessageDao) WhereOrNotLike(column string, like interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereOrNotLike(column, like), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereOrNotIn builds "column NOT IN (in)" statement.
- func (d *SysMessageDao) WhereOrNotIn(column string, in interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereOrNotIn(column, in), Table: d.Table, TableAs: d.TableAs}
- }
- // WhereOrNotNull builds "columns[0] IS NOT NULL OR columns[1] IS NOT NULL ..." statement in "OR" conditions.
- func (d *SysMessageDao) WhereOrNotNull(columns ...string) *SysMessageDao {
- return &SysMessageDao{M: d.M.WhereOrNotNull(columns...), Table: d.Table, TableAs: d.TableAs}
- }
- // Group sets the "GROUP BY" statement for the model.
- func (d *SysMessageDao) Group(groupBy ...string) *SysMessageDao {
- return &SysMessageDao{M: d.M.Group(groupBy...), Table: d.Table, TableAs: d.TableAs}
- }
- // And adds "AND" condition to the where statement.
- // Deprecated, use Where instead.
- func (d *SysMessageDao) And(where interface{}, args ...interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.And(where, args...), Table: d.Table, TableAs: d.TableAs}
- }
- // Or adds "OR" condition to the where statement.
- // Deprecated, use WhereOr instead.
- func (d *SysMessageDao) Or(where interface{}, args ...interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.Or(where, args...), Table: d.Table, TableAs: d.TableAs}
- }
- // GroupBy sets the "GROUP BY" statement for the model.
- func (d *SysMessageDao) GroupBy(groupBy string) *SysMessageDao {
- return &SysMessageDao{M: d.M.Group(groupBy), Table: d.Table, TableAs: d.TableAs}
- }
- // Order sets the "ORDER BY" statement for the model.
- func (d *SysMessageDao) Order(orderBy ...string) *SysMessageDao {
- return &SysMessageDao{M: d.M.Order(orderBy...), Table: d.Table, TableAs: d.TableAs}
- }
- // OrderAsc sets the "ORDER BY xxx ASC" statement for the model.
- func (d *SysMessageDao) OrderAsc(column string) *SysMessageDao {
- return &SysMessageDao{M: d.M.OrderAsc(column), Table: d.Table, TableAs: d.TableAs}
- }
- // OrderDesc sets the "ORDER BY xxx DESC" statement for the model.
- func (d *SysMessageDao) OrderDesc(column string) *SysMessageDao {
- return &SysMessageDao{M: d.M.OrderDesc(column), Table: d.Table, TableAs: d.TableAs}
- }
- // OrderRandom sets the "ORDER BY RANDOM()" statement for the model.
- func (d *SysMessageDao) OrderRandom() *SysMessageDao {
- return &SysMessageDao{M: d.M.OrderRandom(), Table: d.Table, TableAs: d.TableAs}
- }
- // OrderBy is alias of Model.Order.
- // See Model.Order.
- // Deprecated, use Order instead.
- func (d *SysMessageDao) OrderBy(orderBy string) *SysMessageDao {
- return &SysMessageDao{M: d.M.Order(orderBy), Table: d.Table, TableAs: d.TableAs}
- }
- // Limit sets the "LIMIT" statement for the model.
- // The parameter <limit> can be either one or two number, if passed two number is passed,
- // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
- // statement.
- func (d *SysMessageDao) Limit(limit ...int) *SysMessageDao {
- return &SysMessageDao{M: d.M.Limit(limit...), Table: d.Table, TableAs: d.TableAs}
- }
- // Offset sets the "OFFSET" statement for the model.
- // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
- func (d *SysMessageDao) Offset(offset int) *SysMessageDao {
- return &SysMessageDao{M: d.M.Offset(offset), Table: d.Table, TableAs: d.TableAs}
- }
- // Distinct forces the query to only return distinct results.
- func (d *SysMessageDao) Distinct() *SysMessageDao {
- return &SysMessageDao{M: d.M.Distinct(), Table: d.Table, TableAs: d.TableAs}
- }
- // Page sets the paging number for the model.
- // The parameter <page> is started from 1 for paging.
- // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
- func (d *SysMessageDao) Page(page, limit int) *SysMessageDao {
- return &SysMessageDao{M: d.M.Page(page, limit), Table: d.Table, TableAs: d.TableAs}
- }
- // Batch sets the batch operation number for the model.
- func (d *SysMessageDao) Batch(batch int) *SysMessageDao {
- return &SysMessageDao{M: d.M.Batch(batch), Table: d.Table, TableAs: d.TableAs}
- }
- // Cache sets the cache feature for the model. It caches the result of the sql, which means
- // if there's another same sql request, it just reads and returns the result from cache, it
- // but not committed and executed into the database.
- //
- // If the parameter <duration> < 0, which means it clear the cache with given <name>.
- // If the parameter <duration> = 0, which means it never expires.
- // If the parameter <duration> > 0, which means it expires after <duration>.
- //
- // The optional parameter <name> is used to bind a name to the cache, which means you can later
- // control the cache like changing the <duration> or clearing the cache with specified <name>.
- //
- // Note that, the cache feature is disabled if the model is operating on a transaction.
- func (d *SysMessageDao) Cache(duration time.Duration, name ...string) *SysMessageDao {
- return &SysMessageDao{M: d.M.Cache(duration, name...), Table: d.Table, TableAs: d.TableAs}
- }
- // Data sets the operation data for the model.
- // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
- // Eg:
- // Data("uid=10000")
- // Data("uid", 10000)
- // Data(g.Map{"uid": 10000, "name":"john"})
- // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
- func (d *SysMessageDao) Data(data ...interface{}) *SysMessageDao {
- return &SysMessageDao{M: d.M.Data(data...), Table: d.Table, TableAs: d.TableAs}
- }
- // All does "SELECT FROM ..." statement for the model.
- // It retrieves the records from table and returns the result as []*model.SysMessage.
- // It returns nil if there's no record retrieved with the given conditions from table.
- //
- // The optional parameter <where> is the same as the parameter of M.Where function,
- // see M.Where.
- func (d *SysMessageDao) All(where ...interface{}) ([]*model.SysMessage, error) {
- all, err := d.M.All(where...)
- if err != nil {
- return nil, err
- }
- var entities []*model.SysMessage
- if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
- return nil, err
- }
- return entities, nil
- }
- // One retrieves one record from table and returns the result as *model.SysMessage.
- // It returns nil if there's no record retrieved with the given conditions from table.
- //
- // The optional parameter <where> is the same as the parameter of M.Where function,
- // see M.Where.
- func (d *SysMessageDao) One(where ...interface{}) (*model.SysMessage, error) {
- one, err := d.M.One(where...)
- if err != nil {
- return nil, err
- }
- var entity *model.SysMessage
- if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
- return nil, err
- }
- return entity, nil
- }
- // FindOne retrieves and returns a single Record by M.WherePri and M.One.
- // Also see M.WherePri and M.One.
- func (d *SysMessageDao) FindOne(where ...interface{}) (*model.SysMessage, error) {
- one, err := d.M.FindOne(where...)
- if err != nil {
- return nil, err
- }
- var entity *model.SysMessage
- if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
- return nil, err
- }
- return entity, nil
- }
- // FindAll retrieves and returns Result by by M.WherePri and M.All.
- // Also see M.WherePri and M.All.
- func (d *SysMessageDao) FindAll(where ...interface{}) ([]*model.SysMessage, error) {
- all, err := d.M.FindAll(where...)
- if err != nil {
- return nil, err
- }
- var entities []*model.SysMessage
- if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
- return nil, err
- }
- return entities, nil
- }
- // Struct retrieves one record from table and converts it into given struct.
- // The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
- // it can create the struct internally during converting.
- //
- // The optional parameter <where> is the same as the parameter of Model.Where function,
- // see Model.Where.
- //
- // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
- // from table and <pointer> is not nil.
- //
- // Eg:
- // user := new(User)
- // err := dao.User.Where("id", 1).Struct(user)
- //
- // user := (*User)(nil)
- // err := dao.User.Where("id", 1).Struct(&user)
- func (d *SysMessageDao) Struct(pointer interface{}, where ...interface{}) error {
- return d.M.Struct(pointer, where...)
- }
- // Structs retrieves records from table and converts them into given struct slice.
- // The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
- // slice internally during converting.
- //
- // The optional parameter <where> is the same as the parameter of Model.Where function,
- // see Model.Where.
- //
- // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
- // from table and <pointer> is not empty.
- //
- // Eg:
- // users := ([]User)(nil)
- // err := dao.User.Structs(&users)
- //
- // users := ([]*User)(nil)
- // err := dao.User.Structs(&users)
- func (d *SysMessageDao) Structs(pointer interface{}, where ...interface{}) error {
- return d.M.Structs(pointer, where...)
- }
- // Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
- // It calls function Struct if <pointer> is type of *struct/**struct.
- // It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
- //
- // The optional parameter <where> is the same as the parameter of Model.Where function,
- // see Model.Where.
- //
- // Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
- //
- // Eg:
- // user := new(User)
- // err := dao.User.Where("id", 1).Scan(user)
- //
- // user := (*User)(nil)
- // err := dao.User.Where("id", 1).Scan(&user)
- //
- // users := ([]User)(nil)
- // err := dao.User.Scan(&users)
- //
- // users := ([]*User)(nil)
- // err := dao.User.Scan(&users)
- func (d *SysMessageDao) Scan(pointer interface{}, where ...interface{}) error {
- return d.M.Scan(pointer, where...)
- }
- // Chunk iterates the table with given size and callback function.
- func (d *SysMessageDao) Chunk(limit int, callback func(entities []*model.SysMessage, err error) bool) {
- d.M.Chunk(limit, func(result gdb.Result, err error) bool {
- var entities []*model.SysMessage
- err = result.Structs(&entities)
- if err == sql.ErrNoRows {
- return false
- }
- return callback(entities, err)
- })
- }
- // LockUpdate sets the lock for update for current operation.
- func (d *SysMessageDao) LockUpdate() *SysMessageDao {
- return &SysMessageDao{M: d.M.LockUpdate(), Table: d.Table, TableAs: d.TableAs}
- }
- // LockShared sets the lock in share mode for current operation.
- func (d *SysMessageDao) LockShared() *SysMessageDao {
- return &SysMessageDao{M: d.M.LockShared(), Table: d.Table, TableAs: d.TableAs}
- }
- // Unscoped enables/disables the soft deleting feature.
- func (d *SysMessageDao) Unscoped() *SysMessageDao {
- return &SysMessageDao{M: d.M.Unscoped(), Table: d.Table, TableAs: d.TableAs}
- }
- // DataScope enables the DataScope feature.
- func (d *SysMessageDao) DataScope(ctx context.Context, args ...interface{}) *SysMessageDao {
- cs := ctx.Value("contextService")
- dataScope := gconv.Map(gconv.String(gconv.Map(cs)["dataScope"]))
- if dataScope != nil {
- var specialFlag bool
- var tableAs string
- if d.TableAs != "" && len(args) <= 1 {
- tableAs = d.TableAs + "."
- }
- if len(args) > 1 {
- specialFlag = true
- if val, ok := args[1].(string); ok {
- tableAs = val + "."
- }
- }
- userIds, ok := dataScope["userIds"]
- delete(dataScope, "userIds")
- var orColumns []string
- var orValues []interface{}
- if ok && userIds != "-1" {
- column := "created_by"
- if len(args) > 0 {
- column = args[0].(string)
- }
- if ok, _ := d.M.HasField(column); ok || specialFlag {
- orColumns = append(orColumns, tableAs+column+" IN (?) ")
- orValues = append(orValues, userIds)
- }
- }
- // 销售工程师判断
- var salesEngineerFlag bool
- if roles, ok := dataScope["roles"]; ok {
- delete(dataScope, "roles")
- delete(dataScope, "posts")
- arr := garray.NewArrayFrom(roles.([]interface{}), true)
- if arr.Len() == 1 && arr.Contains("SalesEngineer") {
- salesEngineerFlag = true
- }
- }
- // 非销售工程师权限加成
- if !salesEngineerFlag {
- bigColumns := "is_big"
- if ok, _ := d.M.HasField("is_big"); ok || specialFlag {
- if val, ok := dataScope[bigColumns]; ok && val != "" {
- orColumns = append(orColumns, tableAs+bigColumns+" = ? ")
- orValues = append(orValues, val)
- }
- delete(dataScope, bigColumns)
- }
- var andColumns []string
- var andValues []interface{}
- for k, v := range dataScope {
- if ok, _ := d.M.HasField(k); ok || specialFlag {
- andColumns = append(andColumns, tableAs+k+" IN (?) ")
- andValues = append(andValues, v)
- }
- }
- if len(andColumns) > 0 {
- andWhereSql := strings.Join(andColumns, " AND ")
- orColumns = append(orColumns, "("+andWhereSql+")")
- orValues = append(orValues, andValues...)
- }
- }
- whereSql := strings.Join(orColumns, " OR ")
- return &SysMessageDao{M: d.M.Where(whereSql, orValues...).Ctx(ctx), Table: d.Table, TableAs: d.TableAs}
- }
- return d
- }
|