DengBiao 11 months ago
parent
commit
b4ea6751e4
2 changed files with 182 additions and 0 deletions
  1. +167
    -0
      db/db_one_circles_user_watch_records.go
  2. +15
    -0
      db/model/one_circles_user_watch_records.go

+ 167
- 0
db/db_one_circles_user_watch_records.go View File

@@ -0,0 +1,167 @@
package db

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model"
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils"
zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx"
"errors"
"fmt"
"reflect"
"xorm.io/xorm"
)

// BatchSelectOneCirclesUserWatchRecordss 批量查询数据 TODO::和下面的方法重复了,建议采用下面的 `OneCirclesUserWatchRecordsFindByParams` 方法
func BatchSelectOneCirclesUserWatchRecordss(Db *xorm.Engine, params map[string]interface{}) (*[]model.OneCirclesUserWatchRecords, error) {
var OneCirclesUserWatchRecordsData []model.OneCirclesUserWatchRecords
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).
Find(&OneCirclesUserWatchRecordsData); err != nil {
return nil, zhios_order_relate_logx.Warn(err)
}
return &OneCirclesUserWatchRecordsData, nil
}

// OneCirclesUserWatchRecordsInsert 插入单条数据
func OneCirclesUserWatchRecordsInsert(Db *xorm.Engine, OneCirclesUserWatchRecords *model.OneCirclesUserWatchRecords) (int64, error) {
_, err := Db.InsertOne(OneCirclesUserWatchRecords)
if err != nil {
return 0, err
}
return OneCirclesUserWatchRecords.Id, nil
}

// BatchAddOneCirclesUserWatchRecordss 批量新增数据
func BatchAddOneCirclesUserWatchRecordss(Db *xorm.Engine, OneCirclesUserWatchRecordsData []*model.OneCirclesUserWatchRecords) (int64, error) {
affected, err := Db.Insert(OneCirclesUserWatchRecordsData)
if err != nil {
return 0, err
}
return affected, nil
}

func GetOneCirclesUserWatchRecordsCount(Db *xorm.Engine) int {
var OneCirclesUserWatchRecords model.OneCirclesUserWatchRecords
session := Db.Where("")
count, err := session.Count(&OneCirclesUserWatchRecords)
if err != nil {
return 0
}
return int(count)
}

// OneCirclesUserWatchRecordsDelete 删除记录
func OneCirclesUserWatchRecordsDelete(Db *xorm.Engine, id interface{}) (int64, error) {
if reflect.TypeOf(id).Kind() == reflect.Slice {
return Db.In("id", id).Delete(model.OneCirclesUserWatchRecords{})
} else {
return Db.Where("id = ?", id).Delete(model.OneCirclesUserWatchRecords{})
}
}

// OneCirclesUserWatchRecordsUpdate 更新记录
func OneCirclesUserWatchRecordsUpdate(session *xorm.Session, id interface{}, OneCirclesUserWatchRecords *model.OneCirclesUserWatchRecords, forceColums ...string) (int64, error) {
var (
affected int64
err error
)
if forceColums != nil {
affected, err = session.Where("id=?", id).Cols(forceColums...).Update(OneCirclesUserWatchRecords)
} else {
affected, err = session.Where("id=?", id).Update(OneCirclesUserWatchRecords)
}
if err != nil {
return 0, err
}
return affected, nil
}

// OneCirclesUserWatchRecordsGetOneByParamsBySession 通过传入的参数查询数据(单条)
func OneCirclesUserWatchRecordsGetOneByParamsBySession(session *xorm.Session, params map[string]interface{}) (*model.OneCirclesUserWatchRecords, error) {
var m model.OneCirclesUserWatchRecords
var query = fmt.Sprintf("%s =?", params["key"])
has, err := session.Where(query, params["value"]).Get(&m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
if has == false {
return nil, errors.New("未查询到相应的 block_star_chain 记录")
}
return &m, nil
}

// OneCirclesUserWatchRecordsGetOneByParams 通过传入的参数查询数据(单条)
func OneCirclesUserWatchRecordsGetOneByParams(Db *xorm.Engine, params map[string]interface{}) (*model.OneCirclesUserWatchRecords, error) {
var m model.OneCirclesUserWatchRecords
var query = fmt.Sprintf("%s =?", params["key"])
if has, err := Db.Where(query, params["value"]).Get(&m); err != nil || has == false {
return nil, zhios_order_relate_logx.Error(err)
}
return &m, nil
}

// OneCirclesUserWatchRecordsFindByParams 通过传入的参数查询数据(多条)
func OneCirclesUserWatchRecordsFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.OneCirclesUserWatchRecords, error) {
var m []model.OneCirclesUserWatchRecords
if params["value"] == nil {
return nil, errors.New("参数有误")
}
if params["key"] == nil {
//查询全部数据
err := Db.Find(&m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
return &m, nil
} else {
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice {
//指定In查询
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil {
return nil, zhios_order_relate_logx.Warn(err)
}
return &m, nil
} else {
var query = fmt.Sprintf("%s =?", params["key"])
err := Db.Where(query, params["value"]).Find(&m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
return &m, nil
}

}
}

func OneCirclesUserWatchRecordsFindByParamsByPage(Db *xorm.Engine, params map[string]interface{}, page, pageSize int) (*[]model.OneCirclesUserWatchRecords, error) {
var m []model.OneCirclesUserWatchRecords
if params["value"] == nil {
return nil, errors.New("参数有误")
}
if page == 0 && pageSize == 0 {
page = 1
pageSize = 10
}

if params["key"] == nil {
//查询全部数据
err := Db.Limit(pageSize, (page-1)*pageSize).Find(&m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
return &m, nil
} else {
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice {
//指定In查询
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Limit(pageSize, (page-1)*pageSize).Find(&m); err != nil {
return nil, zhios_order_relate_logx.Warn(err)
}
return &m, nil
} else {
var query = fmt.Sprintf("%s =?", params["key"])
err := Db.Where(query, params["value"]).Limit(pageSize, (page-1)*pageSize).Find(&m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
return &m, nil
}

}
}

+ 15
- 0
db/model/one_circles_user_watch_records.go View File

@@ -0,0 +1,15 @@
package model

import (
"time"
)

type OneCirclesUserWatchRecords struct {
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"`
Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"`
NextWatchAdDate time.Time `json:"next_watch_ad_date" xorm:"not null default 'CURRENT_TIMESTAMP' comment('下一轮观看视屏时间') DATETIME"`
LastRoundWatchAdTotal int `json:"last_round_watch_ad_total" xorm:"not null default 0 comment('上一轮观看视屏总数') INT(11)"`
ResidueWatchAdNum int `json:"residue_watch_ad_num" xorm:"not null default 0 comment('剩余观看视屏数') INT(11)"`
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
}

Loading…
Cancel
Save