65 Star 397 Fork 128

admpub/nging

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
CollectorExportLog.go 10.45 KB
一键复制 编辑 原始数据 按行查看 历史
admpub 提交于 2019-10-10 22:12 . improved
// @generated Do not edit this file, which is automatically generated by the generator.
package dbschema
import (
"fmt"
"time"
"github.com/webx-top/db"
"github.com/webx-top/db/lib/factory"
"github.com/webx-top/echo"
"github.com/webx-top/echo/param"
)
type Slice_CollectorExportLog []*CollectorExportLog
func (s Slice_CollectorExportLog) Range(fn func(m factory.Model) error) error {
for _, v := range s {
if err := fn(v); err != nil {
return err
}
}
return nil
}
func (s Slice_CollectorExportLog) RangeRaw(fn func(m *CollectorExportLog) error) error {
for _, v := range s {
if err := fn(v); err != nil {
return err
}
}
return nil
}
// CollectorExportLog 导出日志
type CollectorExportLog struct {
base factory.Base
objects []*CollectorExportLog
Id uint64 `db:"id,omitempty,pk" bson:"id,omitempty" comment:"ID" json:"id" xml:"id"`
PageId uint `db:"page_id" bson:"page_id" comment:"页面规则ID" json:"page_id" xml:"page_id"`
ExportId uint `db:"export_id" bson:"export_id" comment:"导出方案ID" json:"export_id" xml:"export_id"`
Result string `db:"result" bson:"result" comment:"结果" json:"result" xml:"result"`
Status string `db:"status" bson:"status" comment:"状态" json:"status" xml:"status"`
Created uint `db:"created" bson:"created" comment:"创建时间" json:"created" xml:"created"`
}
// - base function
func (a *CollectorExportLog) Trans() *factory.Transaction {
return a.base.Trans()
}
func (a *CollectorExportLog) Use(trans *factory.Transaction) factory.Model {
a.base.Use(trans)
return a
}
func (a *CollectorExportLog) SetContext(ctx echo.Context) factory.Model {
a.base.SetContext(ctx)
return a
}
func (a *CollectorExportLog) Context() echo.Context {
return a.base.Context()
}
func (a *CollectorExportLog) SetConnID(connID int) factory.Model {
a.base.SetConnID(connID)
return a
}
func (a *CollectorExportLog) SetNamer(namer func(string) string) factory.Model {
a.base.SetNamer(namer)
return a
}
func (a *CollectorExportLog) Namer() func(string) string {
return a.base.Namer()
}
func (a *CollectorExportLog) SetParam(param *factory.Param) factory.Model {
a.base.SetParam(param)
return a
}
func (a *CollectorExportLog) Param(mw func(db.Result) db.Result, args ...interface{}) *factory.Param {
if a.base.Param() == nil {
return a.NewParam().SetMiddleware(mw).SetArgs(args...)
}
return a.base.Param().SetMiddleware(mw).SetArgs(args...)
}
// - current function
func (a *CollectorExportLog) New(structName string, connID ...int) factory.Model {
if len(connID) > 0 {
return factory.NewModel(structName, connID[0]).Use(a.base.Trans())
}
return factory.NewModel(structName, a.base.ConnID()).Use(a.base.Trans())
}
func (a *CollectorExportLog) Objects() []*CollectorExportLog {
if a.objects == nil {
return nil
}
return a.objects[:]
}
func (a *CollectorExportLog) NewObjects() factory.Ranger {
return &Slice_CollectorExportLog{}
}
func (a *CollectorExportLog) InitObjects() *[]*CollectorExportLog {
a.objects = []*CollectorExportLog{}
return &a.objects
}
func (a *CollectorExportLog) NewParam() *factory.Param {
return factory.NewParam(factory.DefaultFactory).SetIndex(a.base.ConnID()).SetTrans(a.base.Trans()).SetCollection(a.Name_()).SetModel(a)
}
func (a *CollectorExportLog) Short_() string {
return "collector_export_log"
}
func (a *CollectorExportLog) Struct_() string {
return "CollectorExportLog"
}
func (a *CollectorExportLog) Name_() string {
if a.base.Namer() != nil {
return WithPrefix(a.base.Namer()(a.Short_()))
}
return WithPrefix(factory.TableNamerGet(a.Short_())(a))
}
func (a *CollectorExportLog) CPAFrom(source factory.Model) factory.Model {
a.SetContext(source.Context())
a.Use(source.Trans())
a.SetNamer(source.Namer())
return a
}
func (a *CollectorExportLog) Get(mw func(db.Result) db.Result, args ...interface{}) error {
base := a.base
err := a.Param(mw, args...).SetRecv(a).One()
a.base = base
return err
}
func (a *CollectorExportLog) List(recv interface{}, mw func(db.Result) db.Result, page, size int, args ...interface{}) (func() int64, error) {
if recv == nil {
recv = a.InitObjects()
}
return a.Param(mw, args...).SetPage(page).SetSize(size).SetRecv(recv).List()
}
func (a *CollectorExportLog) GroupBy(keyField string, inputRows ...[]*CollectorExportLog) map[string][]*CollectorExportLog {
var rows []*CollectorExportLog
if len(inputRows) > 0 {
rows = inputRows[0]
} else {
rows = a.Objects()
}
r := map[string][]*CollectorExportLog{}
for _, row := range rows {
dmap := row.AsMap()
vkey := fmt.Sprint(dmap[keyField])
if _, y := r[vkey]; !y {
r[vkey] = []*CollectorExportLog{}
}
r[vkey] = append(r[vkey], row)
}
return r
}
func (a *CollectorExportLog) KeyBy(keyField string, inputRows ...[]*CollectorExportLog) map[string]*CollectorExportLog {
var rows []*CollectorExportLog
if len(inputRows) > 0 {
rows = inputRows[0]
} else {
rows = a.Objects()
}
r := map[string]*CollectorExportLog{}
for _, row := range rows {
dmap := row.AsMap()
vkey := fmt.Sprint(dmap[keyField])
r[vkey] = row
}
return r
}
func (a *CollectorExportLog) AsKV(keyField string, valueField string, inputRows ...[]*CollectorExportLog) map[string]interface{} {
var rows []*CollectorExportLog
if len(inputRows) > 0 {
rows = inputRows[0]
} else {
rows = a.Objects()
}
r := map[string]interface{}{}
for _, row := range rows {
dmap := row.AsMap()
vkey := fmt.Sprint(dmap[keyField])
r[vkey] = dmap[valueField]
}
return r
}
func (a *CollectorExportLog) ListByOffset(recv interface{}, mw func(db.Result) db.Result, offset, size int, args ...interface{}) (func() int64, error) {
if recv == nil {
recv = a.InitObjects()
}
return a.Param(mw, args...).SetOffset(offset).SetSize(size).SetRecv(recv).List()
}
func (a *CollectorExportLog) Add() (pk interface{}, err error) {
a.Created = uint(time.Now().Unix())
a.Id = 0
if len(a.Status) == 0 {
a.Status = "idle"
}
err = DBI.Fire("creating", a, nil)
if err != nil {
return
}
pk, err = a.Param(nil).SetSend(a).Insert()
if err == nil && pk != nil {
if v, y := pk.(uint64); y {
a.Id = v
} else if v, y := pk.(int64); y {
a.Id = uint64(v)
}
}
if err == nil {
err = DBI.Fire("created", a, nil)
}
return
}
func (a *CollectorExportLog) Edit(mw func(db.Result) db.Result, args ...interface{}) (err error) {
if len(a.Status) == 0 {
a.Status = "idle"
}
if err = DBI.Fire("updating", a, mw, args...); err != nil {
return
}
if err = a.Param(mw, args...).SetSend(a).Update(); err != nil {
return
}
return DBI.Fire("updated", a, mw, args...)
}
func (a *CollectorExportLog) SetField(mw func(db.Result) db.Result, field string, value interface{}, args ...interface{}) (err error) {
return a.SetFields(mw, map[string]interface{}{
field: value,
}, args...)
}
func (a *CollectorExportLog) SetFields(mw func(db.Result) db.Result, kvset map[string]interface{}, args ...interface{}) (err error) {
if val, ok := kvset["status"]; ok && val != nil {
if v, ok := val.(string); ok && len(v) == 0 {
kvset["status"] = "idle"
}
}
m := *a
m.FromRow(kvset)
var editColumns []string
for column := range kvset {
editColumns = append(editColumns, column)
}
if err = DBI.FireUpdate("updating", &m, editColumns, mw, args...); err != nil {
return
}
if err = a.Param(mw, args...).SetSend(kvset).Update(); err != nil {
return
}
return DBI.FireUpdate("updated", &m, editColumns, mw, args...)
}
func (a *CollectorExportLog) Upsert(mw func(db.Result) db.Result, args ...interface{}) (pk interface{}, err error) {
pk, err = a.Param(mw, args...).SetSend(a).Upsert(func() error {
if len(a.Status) == 0 {
a.Status = "idle"
}
return DBI.Fire("updating", a, mw, args...)
}, func() error {
a.Created = uint(time.Now().Unix())
a.Id = 0
if len(a.Status) == 0 {
a.Status = "idle"
}
return DBI.Fire("creating", a, nil)
})
if err == nil && pk != nil {
if v, y := pk.(uint64); y {
a.Id = v
} else if v, y := pk.(int64); y {
a.Id = uint64(v)
}
}
if err == nil {
if pk == nil {
err = DBI.Fire("updated", a, mw, args...)
} else {
err = DBI.Fire("created", a, nil)
}
}
return
}
func (a *CollectorExportLog) Delete(mw func(db.Result) db.Result, args ...interface{}) (err error) {
if err = DBI.Fire("deleting", a, mw, args...); err != nil {
return
}
if err = a.Param(mw, args...).Delete(); err != nil {
return
}
return DBI.Fire("deleted", a, mw, args...)
}
func (a *CollectorExportLog) Count(mw func(db.Result) db.Result, args ...interface{}) (int64, error) {
return a.Param(mw, args...).Count()
}
func (a *CollectorExportLog) Reset() *CollectorExportLog {
a.Id = 0
a.PageId = 0
a.ExportId = 0
a.Result = ``
a.Status = ``
a.Created = 0
return a
}
func (a *CollectorExportLog) AsMap() map[string]interface{} {
r := map[string]interface{}{}
r["Id"] = a.Id
r["PageId"] = a.PageId
r["ExportId"] = a.ExportId
r["Result"] = a.Result
r["Status"] = a.Status
r["Created"] = a.Created
return r
}
func (a *CollectorExportLog) FromRow(row map[string]interface{}) {
for key, value := range row {
switch key {
case "id":
a.Id = param.AsUint64(value)
case "page_id":
a.PageId = param.AsUint(value)
case "export_id":
a.ExportId = param.AsUint(value)
case "result":
a.Result = param.AsString(value)
case "status":
a.Status = param.AsString(value)
case "created":
a.Created = param.AsUint(value)
}
}
}
func (a *CollectorExportLog) Set(key interface{}, value ...interface{}) {
switch k := key.(type) {
case map[string]interface{}:
for kk, vv := range k {
a.Set(kk, vv)
}
default:
var (
kk string
vv interface{}
)
if k, y := key.(string); y {
kk = k
} else {
kk = fmt.Sprint(key)
}
if len(value) > 0 {
vv = value[0]
}
switch kk {
case "Id":
a.Id = param.AsUint64(vv)
case "PageId":
a.PageId = param.AsUint(vv)
case "ExportId":
a.ExportId = param.AsUint(vv)
case "Result":
a.Result = param.AsString(vv)
case "Status":
a.Status = param.AsString(vv)
case "Created":
a.Created = param.AsUint(vv)
}
}
}
func (a *CollectorExportLog) AsRow() map[string]interface{} {
r := map[string]interface{}{}
r["id"] = a.Id
r["page_id"] = a.PageId
r["export_id"] = a.ExportId
r["result"] = a.Result
r["status"] = a.Status
r["created"] = a.Created
return r
}
func (a *CollectorExportLog) BatchValidate(kvset map[string]interface{}) error {
if kvset == nil {
kvset = a.AsRow()
}
return factory.BatchValidate(a.Short_(), kvset)
}
func (a *CollectorExportLog) Validate(field string, value interface{}) error {
return factory.Validate(a.Short_(), field, value)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/admpub/nging.git
git@gitee.com:admpub/nging.git
admpub
nging
nging
v2.0.6

搜索帮助