重命名资源套餐相关结构体和数据库表,新增长效套餐类型
This commit is contained in:
@@ -43,11 +43,11 @@ func main() {
|
||||
// 生成模型
|
||||
customs := make(map[string]any)
|
||||
|
||||
resourcePss := g.GenerateModel("resource_pss", common...)
|
||||
customs["resource_pss"] = resourcePss
|
||||
resourceShort := g.GenerateModel("resource_short", common...)
|
||||
customs["resource_short"] = resourceShort
|
||||
|
||||
resource := g.GenerateModel("resource", append(common,
|
||||
gen.FieldRelate(field.HasOne, "Pss", resourcePss, &field.RelateConfig{
|
||||
gen.FieldRelate(field.HasOne, "Short", resourceShort, &field.RelateConfig{
|
||||
RelatePointer: true,
|
||||
GORMTag: field.GormTag{
|
||||
"foreignKey": []string{"ResourceID"},
|
||||
|
||||
@@ -733,14 +733,14 @@ comment on column resource.id is '套餐ID';
|
||||
comment on column resource.user_id is '用户ID';
|
||||
comment on column resource.resource_no is '套餐编号';
|
||||
comment on column resource.active is '套餐状态';
|
||||
comment on column resource.type is '套餐类型:1-动态,2-隧道,3-独享';
|
||||
comment on column resource.type is '套餐类型:1-短效动态,2-长效动态';
|
||||
comment on column resource.created_at is '创建时间';
|
||||
comment on column resource.updated_at is '更新时间';
|
||||
comment on column resource.deleted_at is '删除时间';
|
||||
|
||||
-- resource_pss
|
||||
drop table if exists resource_pss cascade;
|
||||
create table resource_pss (
|
||||
-- resource_short
|
||||
drop table if exists resource_short cascade;
|
||||
create table resource_short (
|
||||
id serial primary key,
|
||||
resource_id int not null references resource (id)
|
||||
on update cascade
|
||||
@@ -754,58 +754,51 @@ create table resource_pss (
|
||||
daily_used int not null default 0,
|
||||
daily_last timestamp
|
||||
);
|
||||
create index resource_pss_resource_id_index on resource_pss (resource_id);
|
||||
create index resource_short_resource_id_index on resource_short (resource_id);
|
||||
|
||||
-- resource_pss表字段注释
|
||||
comment on table resource_pss is '动态代理套餐表';
|
||||
comment on column resource_pss.id is 'ID';
|
||||
comment on column resource_pss.resource_id is '套餐ID';
|
||||
comment on column resource_pss.type is '套餐类型:1-包时,2-包量';
|
||||
comment on column resource_pss.live is '可用时长(秒)';
|
||||
comment on column resource_pss.quota is '配额数量';
|
||||
comment on column resource_pss.used is '已用数量';
|
||||
comment on column resource_pss.expire is '过期时间';
|
||||
comment on column resource_pss.daily_limit is '每日限制';
|
||||
comment on column resource_pss.daily_used is '今日已用数量';
|
||||
comment on column resource_pss.daily_last is '今日最后使用时间';
|
||||
-- resource_short表字段注释
|
||||
comment on table resource_short is '短效动态套餐表';
|
||||
comment on column resource_short.id is 'ID';
|
||||
comment on column resource_short.resource_id is '套餐ID';
|
||||
comment on column resource_short.type is '套餐类型:1-包时,2-包量';
|
||||
comment on column resource_short.live is '可用时长(秒)';
|
||||
comment on column resource_short.quota is '配额数量';
|
||||
comment on column resource_short.used is '已用数量';
|
||||
comment on column resource_short.expire is '过期时间';
|
||||
comment on column resource_short.daily_limit is '每日限制';
|
||||
comment on column resource_short.daily_used is '今日已用数量';
|
||||
comment on column resource_short.daily_last is '今日最后使用时间';
|
||||
|
||||
-- resource_psr
|
||||
drop table if exists resource_psr cascade;
|
||||
create table resource_psr (
|
||||
-- resource_long
|
||||
drop table if exists resource_long cascade;
|
||||
create table resource_long (
|
||||
id serial primary key,
|
||||
resource_id int not null references resource (id)
|
||||
on update cascade
|
||||
on delete cascade,
|
||||
type int,
|
||||
live int,
|
||||
conn int,
|
||||
expire timestamp,
|
||||
used bool
|
||||
quota int,
|
||||
used int not null default 0,
|
||||
daily_limit int not null default 0,
|
||||
daily_used int not null default 0,
|
||||
daily_last timestamp
|
||||
);
|
||||
create index resource_psr_resource_id_index on resource_psr (resource_id);
|
||||
create index resource_long_resource_id_index on resource_long (resource_id);
|
||||
|
||||
-- resource_psr表字段注释
|
||||
comment on table resource_psr is '隧道代理套餐表';
|
||||
comment on column resource_psr.id is 'ID';
|
||||
comment on column resource_psr.resource_id is '套餐ID';
|
||||
comment on column resource_psr.live is '轮换周期(秒)';
|
||||
comment on column resource_psr.conn is '最大连接数';
|
||||
comment on column resource_psr.expire is '过期时间';
|
||||
comment on column resource_psr.used is '是否已使用';
|
||||
|
||||
-- resource_pps
|
||||
drop table if exists resource_pps cascade;
|
||||
create table resource_pps (
|
||||
id serial primary key,
|
||||
resource_id int not null references resource (id)
|
||||
on update cascade
|
||||
on delete cascade
|
||||
);
|
||||
create index resource_pps_resource_id_index on resource_pps (resource_id);
|
||||
|
||||
-- resource_pps表字段注释
|
||||
comment on table resource_pps is '独享代理套餐表';
|
||||
comment on column resource_pps.id is 'ID';
|
||||
comment on column resource_pps.resource_id is '套餐ID';
|
||||
-- resource_long表字段注释
|
||||
comment on table resource_long is '长效动态套餐表';
|
||||
comment on column resource_long.id is 'ID';
|
||||
comment on column resource_long.resource_id is '套餐ID';
|
||||
comment on column resource_long.type is '套餐类型:1-包时,2-包量';
|
||||
comment on column resource_long.live is '可用时长(秒)';
|
||||
comment on column resource_long.quota is '配额数量';
|
||||
comment on column resource_long.used is '已用数量';
|
||||
comment on column resource_long.expire is '过期时间';
|
||||
comment on column resource_long.daily_limit is '每日限制';
|
||||
comment on column resource_long.daily_used is '今日已用数量';
|
||||
comment on column resource_long.daily_last is '今日最后使用时间';
|
||||
|
||||
-- endregion
|
||||
|
||||
|
||||
@@ -3,14 +3,13 @@ package resource
|
||||
type Type int32
|
||||
|
||||
const (
|
||||
TypeDynamic Type = iota + 1 // 动态
|
||||
TypeTunnel // 隧道
|
||||
TypePrivate // 私有
|
||||
TypeShort Type = iota + 1 // 短效动态
|
||||
TypeLong // 长效动态
|
||||
)
|
||||
|
||||
type PssType int32
|
||||
type Mode int32
|
||||
|
||||
const (
|
||||
PssTypeTime PssType = iota + 1 // 包时
|
||||
PssTypeCount // 包量
|
||||
ModeTime Mode = iota + 1 // 包时
|
||||
ModeCount // 包量
|
||||
)
|
||||
|
||||
@@ -53,7 +53,7 @@ func ListBill(c *fiber.Ctx) error {
|
||||
|
||||
bills, err := q.Bill.Where(do).
|
||||
Preload(q.Bill.Resource, q.Bill.Trade, q.Bill.Refund).
|
||||
Preload(q.Bill.Resource.Pss).
|
||||
Preload(q.Bill.Resource.Short).
|
||||
Order(q.Bill.CreatedAt.Desc()).
|
||||
Offset(req.GetOffset()).
|
||||
Limit(req.GetLimit()).
|
||||
|
||||
@@ -36,9 +36,9 @@ func OnlineEdge(c *fiber.Ctx) (err error) {
|
||||
|
||||
// 挑选合适的转发服务
|
||||
var fwd *m.Proxy
|
||||
fwd, err = q.Proxy.Debug().
|
||||
fwd, err = q.Proxy.
|
||||
LeftJoin(q.Edge, q.Edge.ProxyID.EqCol(q.Proxy.ID), q.Edge.Status.Eq(1)).
|
||||
Select(q.Proxy.ALL, q.Edge.ALL.Count().As("count")).
|
||||
LeftJoin(q.Edge, q.Edge.ProxyID.EqCol(q.Proxy.ID)).
|
||||
Where(q.Proxy.Type.Eq(int32(proxy2.TypeSelfHosted))).
|
||||
Group(q.Proxy.ID).
|
||||
Order(field.NewField("", "count").Desc()).
|
||||
|
||||
@@ -14,9 +14,9 @@ import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
// region ListResourcePss
|
||||
// region ListResourceShort
|
||||
|
||||
type ListResourcePssReq struct {
|
||||
type ListResourceShortReq struct {
|
||||
core.PageReq
|
||||
ResourceNo *string `json:"resource_no"`
|
||||
Active *bool `json:"active"`
|
||||
@@ -27,8 +27,8 @@ type ListResourcePssReq struct {
|
||||
ExpireBefore *time.Time `json:"expire_before"`
|
||||
}
|
||||
|
||||
// ListResourcePss 获取套餐列表
|
||||
func ListResourcePss(c *fiber.Ctx) error {
|
||||
// ListResourceShort 获取套餐列表
|
||||
func ListResourceShort(c *fiber.Ctx) error {
|
||||
// 检查权限
|
||||
authContext, err := auth.Protect(c, []auth.PayloadType{auth.PayloadUser}, []string{})
|
||||
if err != nil {
|
||||
@@ -36,7 +36,7 @@ func ListResourcePss(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// 解析请求参数
|
||||
req := new(ListResourcePssReq)
|
||||
req := new(ListResourceShortReq)
|
||||
if err := c.BodyParser(req); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -51,7 +51,7 @@ func ListResourcePss(c *fiber.Ctx) error {
|
||||
do.Where(q.Resource.Active.Is(*req.Active))
|
||||
}
|
||||
if req.Type != nil {
|
||||
do.Where(q.ResourcePss.As(q.Resource.Pss.Name()).Type.Eq(int32(*req.Type)))
|
||||
do.Where(q.ResourceShort.As(q.Resource.Short.Name()).Type.Eq(int32(*req.Type)))
|
||||
}
|
||||
if req.CreateAfter != nil {
|
||||
do.Where(q.Resource.CreatedAt.Gte(orm.LocalDateTime(*req.CreateAfter)))
|
||||
@@ -60,14 +60,14 @@ func ListResourcePss(c *fiber.Ctx) error {
|
||||
do.Where(q.Resource.CreatedAt.Lte(orm.LocalDateTime(*req.CreateBefore)))
|
||||
}
|
||||
if req.ExpireAfter != nil {
|
||||
do.Where(q.ResourcePss.As(q.Resource.Pss.Name()).Expire.Gte(orm.LocalDateTime(*req.ExpireAfter)))
|
||||
do.Where(q.ResourceShort.As(q.Resource.Short.Name()).Expire.Gte(orm.LocalDateTime(*req.ExpireAfter)))
|
||||
}
|
||||
if req.ExpireBefore != nil {
|
||||
do.Where(q.ResourcePss.As(q.Resource.Pss.Name()).Expire.Lte(orm.LocalDateTime(*req.ExpireBefore)))
|
||||
do.Where(q.ResourceShort.As(q.Resource.Short.Name()).Expire.Lte(orm.LocalDateTime(*req.ExpireBefore)))
|
||||
}
|
||||
|
||||
resource, err := q.Resource.Where(do).
|
||||
Joins(q.Resource.Pss).
|
||||
Joins(q.Resource.Short).
|
||||
Order(q.Resource.CreatedAt.Desc()).
|
||||
Offset(req.GetOffset()).
|
||||
Limit(req.GetLimit()).
|
||||
@@ -111,23 +111,23 @@ func AllResource(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// 查询套餐列表
|
||||
pss := q.ResourcePss.As(q.Resource.Pss.Name())
|
||||
short := q.ResourceShort.As(q.Resource.Short.Name())
|
||||
do := q.Resource.
|
||||
Joins(q.Resource.Pss).
|
||||
Joins(q.Resource.Short).
|
||||
Where(
|
||||
q.Resource.UserID.Eq(authContext.Payload.Id),
|
||||
q.Resource.Active.Is(true),
|
||||
q.Resource.Where(
|
||||
pss.Type.Eq(int32(resource2.PssTypeTime)),
|
||||
pss.Expire.Gte(orm.LocalDateTime(time.Now())),
|
||||
short.Type.Eq(int32(resource2.ModeTime)),
|
||||
short.Expire.Gte(orm.LocalDateTime(time.Now())),
|
||||
).Or(
|
||||
pss.Type.Eq(int32(resource2.PssTypeCount)),
|
||||
pss.Quota.GtCol(pss.Used),
|
||||
short.Type.Eq(int32(resource2.ModeCount)),
|
||||
short.Quota.GtCol(short.Used),
|
||||
),
|
||||
q.Resource.Where(
|
||||
pss.DailyLast.Lt(orm.LocalDateTime(u.Today())),
|
||||
short.DailyLast.Lt(orm.LocalDateTime(u.Today())),
|
||||
).Or(
|
||||
pss.DailyUsed.LtCol(pss.DailyLimit),
|
||||
short.DailyUsed.LtCol(short.DailyLimit),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ type Resource struct {
|
||||
CreatedAt orm.LocalDateTime `gorm:"column:created_at;default:CURRENT_TIMESTAMP;comment:创建时间" json:"created_at"` // 创建时间
|
||||
UpdatedAt orm.LocalDateTime `gorm:"column:updated_at;default:CURRENT_TIMESTAMP;comment:更新时间" json:"updated_at"` // 更新时间
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:删除时间" json:"deleted_at"` // 删除时间
|
||||
Pss *ResourcePss `gorm:"foreignKey:ResourceID;references:ID" json:"pss"`
|
||||
Short *ResourceShort `gorm:"foreignKey:ResourceID;references:ID" json:"short"`
|
||||
}
|
||||
|
||||
// TableName Resource's table name
|
||||
|
||||
@@ -6,10 +6,10 @@ package models
|
||||
|
||||
import "platform/web/globals/orm"
|
||||
|
||||
const TableNameResourcePss = "resource_pss"
|
||||
const TableNameResourceLong = "resource_long"
|
||||
|
||||
// ResourcePss mapped from table <resource_pss>
|
||||
type ResourcePss struct {
|
||||
// ResourceLong mapped from table <resource_long>
|
||||
type ResourceLong struct {
|
||||
ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:ID" json:"id"` // ID
|
||||
ResourceID int32 `gorm:"column:resource_id;not null;comment:套餐ID" json:"resource_id"` // 套餐ID
|
||||
Type int32 `gorm:"column:type;comment:套餐类型:1-包时,2-包量" json:"type"` // 套餐类型:1-包时,2-包量
|
||||
@@ -22,7 +22,7 @@ type ResourcePss struct {
|
||||
DailyLast orm.LocalDateTime `gorm:"column:daily_last;comment:今日最后使用时间" json:"daily_last"` // 今日最后使用时间
|
||||
}
|
||||
|
||||
// TableName ResourcePss's table name
|
||||
func (*ResourcePss) TableName() string {
|
||||
return TableNameResourcePss
|
||||
// TableName ResourceLong's table name
|
||||
func (*ResourceLong) TableName() string {
|
||||
return TableNameResourceLong
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
const TableNameResourcePps = "resource_pps"
|
||||
|
||||
// ResourcePps mapped from table <resource_pps>
|
||||
type ResourcePps struct {
|
||||
ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:ID" json:"id"` // ID
|
||||
ResourceID int32 `gorm:"column:resource_id;not null;comment:套餐ID" json:"resource_id"` // 套餐ID
|
||||
}
|
||||
|
||||
// TableName ResourcePps's table name
|
||||
func (*ResourcePps) TableName() string {
|
||||
return TableNameResourcePps
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import "platform/web/globals/orm"
|
||||
|
||||
const TableNameResourcePsr = "resource_psr"
|
||||
|
||||
// ResourcePsr mapped from table <resource_psr>
|
||||
type ResourcePsr struct {
|
||||
ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:ID" json:"id"` // ID
|
||||
ResourceID int32 `gorm:"column:resource_id;not null;comment:套餐ID" json:"resource_id"` // 套餐ID
|
||||
Live int32 `gorm:"column:live;comment:轮换周期(秒)" json:"live"` // 轮换周期(秒)
|
||||
Conn int32 `gorm:"column:conn;comment:最大连接数" json:"conn"` // 最大连接数
|
||||
Expire orm.LocalDateTime `gorm:"column:expire;comment:过期时间" json:"expire"` // 过期时间
|
||||
Used bool `gorm:"column:used;comment:是否已使用" json:"used"` // 是否已使用
|
||||
}
|
||||
|
||||
// TableName ResourcePsr's table name
|
||||
func (*ResourcePsr) TableName() string {
|
||||
return TableNameResourcePsr
|
||||
}
|
||||
28
web/models/resource_short.gen.go
Normal file
28
web/models/resource_short.gen.go
Normal file
@@ -0,0 +1,28 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import "platform/web/globals/orm"
|
||||
|
||||
const TableNameResourceShort = "resource_short"
|
||||
|
||||
// ResourceShort mapped from table <resource_short>
|
||||
type ResourceShort struct {
|
||||
ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:ID" json:"id"` // ID
|
||||
ResourceID int32 `gorm:"column:resource_id;not null;comment:套餐ID" json:"resource_id"` // 套餐ID
|
||||
Type int32 `gorm:"column:type;comment:套餐类型:1-包时,2-包量" json:"type"` // 套餐类型:1-包时,2-包量
|
||||
Live int32 `gorm:"column:live;comment:可用时长(秒)" json:"live"` // 可用时长(秒)
|
||||
Expire orm.LocalDateTime `gorm:"column:expire;comment:过期时间" json:"expire"` // 过期时间
|
||||
Quota int32 `gorm:"column:quota;comment:配额数量" json:"quota"` // 配额数量
|
||||
Used int32 `gorm:"column:used;not null;comment:已用数量" json:"used"` // 已用数量
|
||||
DailyLimit int32 `gorm:"column:daily_limit;not null;comment:每日限制" json:"daily_limit"` // 每日限制
|
||||
DailyUsed int32 `gorm:"column:daily_used;not null;comment:今日已用数量" json:"daily_used"` // 今日已用数量
|
||||
DailyLast orm.LocalDateTime `gorm:"column:daily_last;comment:今日最后使用时间" json:"daily_last"` // 今日最后使用时间
|
||||
}
|
||||
|
||||
// TableName ResourceShort's table name
|
||||
func (*ResourceShort) TableName() string {
|
||||
return TableNameResourceShort
|
||||
}
|
||||
@@ -55,10 +55,10 @@ func newBill(db *gorm.DB, opts ...gen.DOOption) bill {
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Resource", "models.Resource"),
|
||||
Pss: struct {
|
||||
Short: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Resource.Pss", "models.ResourcePss"),
|
||||
RelationField: field.NewRelation("Resource.Short", "models.ResourceShort"),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ type billBelongsToResource struct {
|
||||
|
||||
field.RelationField
|
||||
|
||||
Pss struct {
|
||||
Short struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,9 +34,8 @@ var (
|
||||
Proxy *proxy
|
||||
Refund *refund
|
||||
Resource *resource
|
||||
ResourcePps *resourcePps
|
||||
ResourcePsr *resourcePsr
|
||||
ResourcePss *resourcePss
|
||||
ResourceLong *resourceLong
|
||||
ResourceShort *resourceShort
|
||||
Session *session
|
||||
Trade *trade
|
||||
User *user
|
||||
@@ -65,9 +64,8 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
Proxy = &Q.Proxy
|
||||
Refund = &Q.Refund
|
||||
Resource = &Q.Resource
|
||||
ResourcePps = &Q.ResourcePps
|
||||
ResourcePsr = &Q.ResourcePsr
|
||||
ResourcePss = &Q.ResourcePss
|
||||
ResourceLong = &Q.ResourceLong
|
||||
ResourceShort = &Q.ResourceShort
|
||||
Session = &Q.Session
|
||||
Trade = &Q.Trade
|
||||
User = &Q.User
|
||||
@@ -97,9 +95,8 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
Proxy: newProxy(db, opts...),
|
||||
Refund: newRefund(db, opts...),
|
||||
Resource: newResource(db, opts...),
|
||||
ResourcePps: newResourcePps(db, opts...),
|
||||
ResourcePsr: newResourcePsr(db, opts...),
|
||||
ResourcePss: newResourcePss(db, opts...),
|
||||
ResourceLong: newResourceLong(db, opts...),
|
||||
ResourceShort: newResourceShort(db, opts...),
|
||||
Session: newSession(db, opts...),
|
||||
Trade: newTrade(db, opts...),
|
||||
User: newUser(db, opts...),
|
||||
@@ -130,9 +127,8 @@ type Query struct {
|
||||
Proxy proxy
|
||||
Refund refund
|
||||
Resource resource
|
||||
ResourcePps resourcePps
|
||||
ResourcePsr resourcePsr
|
||||
ResourcePss resourcePss
|
||||
ResourceLong resourceLong
|
||||
ResourceShort resourceShort
|
||||
Session session
|
||||
Trade trade
|
||||
User user
|
||||
@@ -164,9 +160,8 @@ func (q *Query) clone(db *gorm.DB) *Query {
|
||||
Proxy: q.Proxy.clone(db),
|
||||
Refund: q.Refund.clone(db),
|
||||
Resource: q.Resource.clone(db),
|
||||
ResourcePps: q.ResourcePps.clone(db),
|
||||
ResourcePsr: q.ResourcePsr.clone(db),
|
||||
ResourcePss: q.ResourcePss.clone(db),
|
||||
ResourceLong: q.ResourceLong.clone(db),
|
||||
ResourceShort: q.ResourceShort.clone(db),
|
||||
Session: q.Session.clone(db),
|
||||
Trade: q.Trade.clone(db),
|
||||
User: q.User.clone(db),
|
||||
@@ -205,9 +200,8 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
Proxy: q.Proxy.replaceDB(db),
|
||||
Refund: q.Refund.replaceDB(db),
|
||||
Resource: q.Resource.replaceDB(db),
|
||||
ResourcePps: q.ResourcePps.replaceDB(db),
|
||||
ResourcePsr: q.ResourcePsr.replaceDB(db),
|
||||
ResourcePss: q.ResourcePss.replaceDB(db),
|
||||
ResourceLong: q.ResourceLong.replaceDB(db),
|
||||
ResourceShort: q.ResourceShort.replaceDB(db),
|
||||
Session: q.Session.replaceDB(db),
|
||||
Trade: q.Trade.replaceDB(db),
|
||||
User: q.User.replaceDB(db),
|
||||
@@ -236,9 +230,8 @@ type queryCtx struct {
|
||||
Proxy *proxyDo
|
||||
Refund *refundDo
|
||||
Resource *resourceDo
|
||||
ResourcePps *resourcePpsDo
|
||||
ResourcePsr *resourcePsrDo
|
||||
ResourcePss *resourcePssDo
|
||||
ResourceLong *resourceLongDo
|
||||
ResourceShort *resourceShortDo
|
||||
Session *sessionDo
|
||||
Trade *tradeDo
|
||||
User *userDo
|
||||
@@ -267,9 +260,8 @@ func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
Proxy: q.Proxy.WithContext(ctx),
|
||||
Refund: q.Refund.WithContext(ctx),
|
||||
Resource: q.Resource.WithContext(ctx),
|
||||
ResourcePps: q.ResourcePps.WithContext(ctx),
|
||||
ResourcePsr: q.ResourcePsr.WithContext(ctx),
|
||||
ResourcePss: q.ResourcePss.WithContext(ctx),
|
||||
ResourceLong: q.ResourceLong.WithContext(ctx),
|
||||
ResourceShort: q.ResourceShort.WithContext(ctx),
|
||||
Session: q.Session.WithContext(ctx),
|
||||
Trade: q.Trade.WithContext(ctx),
|
||||
User: q.User.WithContext(ctx),
|
||||
|
||||
@@ -35,10 +35,10 @@ func newResource(db *gorm.DB, opts ...gen.DOOption) resource {
|
||||
_resource.CreatedAt = field.NewField(tableName, "created_at")
|
||||
_resource.UpdatedAt = field.NewField(tableName, "updated_at")
|
||||
_resource.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_resource.Pss = resourceHasOnePss{
|
||||
_resource.Short = resourceHasOneShort{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Pss", "models.ResourcePss"),
|
||||
RelationField: field.NewRelation("Short", "models.ResourceShort"),
|
||||
}
|
||||
|
||||
_resource.fillFieldMap()
|
||||
@@ -58,7 +58,7 @@ type resource struct {
|
||||
CreatedAt field.Field // 创建时间
|
||||
UpdatedAt field.Field // 更新时间
|
||||
DeletedAt field.Field // 删除时间
|
||||
Pss resourceHasOnePss
|
||||
Short resourceHasOneShort
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
@@ -121,13 +121,13 @@ func (r resource) replaceDB(db *gorm.DB) resource {
|
||||
return r
|
||||
}
|
||||
|
||||
type resourceHasOnePss struct {
|
||||
type resourceHasOneShort struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a resourceHasOnePss) Where(conds ...field.Expr) *resourceHasOnePss {
|
||||
func (a resourceHasOneShort) Where(conds ...field.Expr) *resourceHasOneShort {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
@@ -140,27 +140,27 @@ func (a resourceHasOnePss) Where(conds ...field.Expr) *resourceHasOnePss {
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a resourceHasOnePss) WithContext(ctx context.Context) *resourceHasOnePss {
|
||||
func (a resourceHasOneShort) WithContext(ctx context.Context) *resourceHasOneShort {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a resourceHasOnePss) Session(session *gorm.Session) *resourceHasOnePss {
|
||||
func (a resourceHasOneShort) Session(session *gorm.Session) *resourceHasOneShort {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a resourceHasOnePss) Model(m *models.Resource) *resourceHasOnePssTx {
|
||||
return &resourceHasOnePssTx{a.db.Model(m).Association(a.Name())}
|
||||
func (a resourceHasOneShort) Model(m *models.Resource) *resourceHasOneShortTx {
|
||||
return &resourceHasOneShortTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type resourceHasOnePssTx struct{ tx *gorm.Association }
|
||||
type resourceHasOneShortTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a resourceHasOnePssTx) Find() (result *models.ResourcePss, err error) {
|
||||
func (a resourceHasOneShortTx) Find() (result *models.ResourceShort, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a resourceHasOnePssTx) Append(values ...*models.ResourcePss) (err error) {
|
||||
func (a resourceHasOneShortTx) Append(values ...*models.ResourceShort) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
@@ -168,7 +168,7 @@ func (a resourceHasOnePssTx) Append(values ...*models.ResourcePss) (err error) {
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a resourceHasOnePssTx) Replace(values ...*models.ResourcePss) (err error) {
|
||||
func (a resourceHasOneShortTx) Replace(values ...*models.ResourceShort) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
@@ -176,7 +176,7 @@ func (a resourceHasOnePssTx) Replace(values ...*models.ResourcePss) (err error)
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a resourceHasOnePssTx) Delete(values ...*models.ResourcePss) (err error) {
|
||||
func (a resourceHasOneShortTx) Delete(values ...*models.ResourceShort) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
@@ -184,11 +184,11 @@ func (a resourceHasOnePssTx) Delete(values ...*models.ResourcePss) (err error) {
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a resourceHasOnePssTx) Clear() error {
|
||||
func (a resourceHasOneShortTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a resourceHasOnePssTx) Count() int64 {
|
||||
func (a resourceHasOneShortTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
|
||||
355
web/queries/resource_long.gen.go
Normal file
355
web/queries/resource_long.gen.go
Normal file
@@ -0,0 +1,355 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"platform/web/models"
|
||||
)
|
||||
|
||||
func newResourceLong(db *gorm.DB, opts ...gen.DOOption) resourceLong {
|
||||
_resourceLong := resourceLong{}
|
||||
|
||||
_resourceLong.resourceLongDo.UseDB(db, opts...)
|
||||
_resourceLong.resourceLongDo.UseModel(&models.ResourceLong{})
|
||||
|
||||
tableName := _resourceLong.resourceLongDo.TableName()
|
||||
_resourceLong.ALL = field.NewAsterisk(tableName)
|
||||
_resourceLong.ID = field.NewInt32(tableName, "id")
|
||||
_resourceLong.ResourceID = field.NewInt32(tableName, "resource_id")
|
||||
_resourceLong.Type = field.NewInt32(tableName, "type")
|
||||
_resourceLong.Live = field.NewInt32(tableName, "live")
|
||||
_resourceLong.Expire = field.NewField(tableName, "expire")
|
||||
_resourceLong.Quota = field.NewInt32(tableName, "quota")
|
||||
_resourceLong.Used = field.NewInt32(tableName, "used")
|
||||
_resourceLong.DailyLimit = field.NewInt32(tableName, "daily_limit")
|
||||
_resourceLong.DailyUsed = field.NewInt32(tableName, "daily_used")
|
||||
_resourceLong.DailyLast = field.NewField(tableName, "daily_last")
|
||||
|
||||
_resourceLong.fillFieldMap()
|
||||
|
||||
return _resourceLong
|
||||
}
|
||||
|
||||
type resourceLong struct {
|
||||
resourceLongDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int32 // ID
|
||||
ResourceID field.Int32 // 套餐ID
|
||||
Type field.Int32 // 套餐类型:1-包时,2-包量
|
||||
Live field.Int32 // 可用时长(秒)
|
||||
Expire field.Field // 过期时间
|
||||
Quota field.Int32 // 配额数量
|
||||
Used field.Int32 // 已用数量
|
||||
DailyLimit field.Int32 // 每日限制
|
||||
DailyUsed field.Int32 // 今日已用数量
|
||||
DailyLast field.Field // 今日最后使用时间
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (r resourceLong) Table(newTableName string) *resourceLong {
|
||||
r.resourceLongDo.UseTable(newTableName)
|
||||
return r.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (r resourceLong) As(alias string) *resourceLong {
|
||||
r.resourceLongDo.DO = *(r.resourceLongDo.As(alias).(*gen.DO))
|
||||
return r.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (r *resourceLong) updateTableName(table string) *resourceLong {
|
||||
r.ALL = field.NewAsterisk(table)
|
||||
r.ID = field.NewInt32(table, "id")
|
||||
r.ResourceID = field.NewInt32(table, "resource_id")
|
||||
r.Type = field.NewInt32(table, "type")
|
||||
r.Live = field.NewInt32(table, "live")
|
||||
r.Expire = field.NewField(table, "expire")
|
||||
r.Quota = field.NewInt32(table, "quota")
|
||||
r.Used = field.NewInt32(table, "used")
|
||||
r.DailyLimit = field.NewInt32(table, "daily_limit")
|
||||
r.DailyUsed = field.NewInt32(table, "daily_used")
|
||||
r.DailyLast = field.NewField(table, "daily_last")
|
||||
|
||||
r.fillFieldMap()
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *resourceLong) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := r.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (r *resourceLong) fillFieldMap() {
|
||||
r.fieldMap = make(map[string]field.Expr, 10)
|
||||
r.fieldMap["id"] = r.ID
|
||||
r.fieldMap["resource_id"] = r.ResourceID
|
||||
r.fieldMap["type"] = r.Type
|
||||
r.fieldMap["live"] = r.Live
|
||||
r.fieldMap["expire"] = r.Expire
|
||||
r.fieldMap["quota"] = r.Quota
|
||||
r.fieldMap["used"] = r.Used
|
||||
r.fieldMap["daily_limit"] = r.DailyLimit
|
||||
r.fieldMap["daily_used"] = r.DailyUsed
|
||||
r.fieldMap["daily_last"] = r.DailyLast
|
||||
}
|
||||
|
||||
func (r resourceLong) clone(db *gorm.DB) resourceLong {
|
||||
r.resourceLongDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r resourceLong) replaceDB(db *gorm.DB) resourceLong {
|
||||
r.resourceLongDo.ReplaceDB(db)
|
||||
return r
|
||||
}
|
||||
|
||||
type resourceLongDo struct{ gen.DO }
|
||||
|
||||
func (r resourceLongDo) Debug() *resourceLongDo {
|
||||
return r.withDO(r.DO.Debug())
|
||||
}
|
||||
|
||||
func (r resourceLongDo) WithContext(ctx context.Context) *resourceLongDo {
|
||||
return r.withDO(r.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) ReadDB() *resourceLongDo {
|
||||
return r.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (r resourceLongDo) WriteDB() *resourceLongDo {
|
||||
return r.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Session(config *gorm.Session) *resourceLongDo {
|
||||
return r.withDO(r.DO.Session(config))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Clauses(conds ...clause.Expression) *resourceLongDo {
|
||||
return r.withDO(r.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Returning(value interface{}, columns ...string) *resourceLongDo {
|
||||
return r.withDO(r.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Not(conds ...gen.Condition) *resourceLongDo {
|
||||
return r.withDO(r.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Or(conds ...gen.Condition) *resourceLongDo {
|
||||
return r.withDO(r.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Select(conds ...field.Expr) *resourceLongDo {
|
||||
return r.withDO(r.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Where(conds ...gen.Condition) *resourceLongDo {
|
||||
return r.withDO(r.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Order(conds ...field.Expr) *resourceLongDo {
|
||||
return r.withDO(r.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Distinct(cols ...field.Expr) *resourceLongDo {
|
||||
return r.withDO(r.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Omit(cols ...field.Expr) *resourceLongDo {
|
||||
return r.withDO(r.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Join(table schema.Tabler, on ...field.Expr) *resourceLongDo {
|
||||
return r.withDO(r.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) LeftJoin(table schema.Tabler, on ...field.Expr) *resourceLongDo {
|
||||
return r.withDO(r.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) RightJoin(table schema.Tabler, on ...field.Expr) *resourceLongDo {
|
||||
return r.withDO(r.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Group(cols ...field.Expr) *resourceLongDo {
|
||||
return r.withDO(r.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Having(conds ...gen.Condition) *resourceLongDo {
|
||||
return r.withDO(r.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Limit(limit int) *resourceLongDo {
|
||||
return r.withDO(r.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Offset(offset int) *resourceLongDo {
|
||||
return r.withDO(r.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *resourceLongDo {
|
||||
return r.withDO(r.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Unscoped() *resourceLongDo {
|
||||
return r.withDO(r.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Create(values ...*models.ResourceLong) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Create(values)
|
||||
}
|
||||
|
||||
func (r resourceLongDo) CreateInBatches(values []*models.ResourceLong, batchSize int) error {
|
||||
return r.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 (r resourceLongDo) Save(values ...*models.ResourceLong) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Save(values)
|
||||
}
|
||||
|
||||
func (r resourceLongDo) First() (*models.ResourceLong, error) {
|
||||
if result, err := r.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourceLong), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Take() (*models.ResourceLong, error) {
|
||||
if result, err := r.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourceLong), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Last() (*models.ResourceLong, error) {
|
||||
if result, err := r.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourceLong), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Find() ([]*models.ResourceLong, error) {
|
||||
result, err := r.DO.Find()
|
||||
return result.([]*models.ResourceLong), err
|
||||
}
|
||||
|
||||
func (r resourceLongDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.ResourceLong, err error) {
|
||||
buf := make([]*models.ResourceLong, 0, batchSize)
|
||||
err = r.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 (r resourceLongDo) FindInBatches(result *[]*models.ResourceLong, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return r.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Attrs(attrs ...field.AssignExpr) *resourceLongDo {
|
||||
return r.withDO(r.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Assign(attrs ...field.AssignExpr) *resourceLongDo {
|
||||
return r.withDO(r.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Joins(fields ...field.RelationField) *resourceLongDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Joins(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Preload(fields ...field.RelationField) *resourceLongDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Preload(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r resourceLongDo) FirstOrInit() (*models.ResourceLong, error) {
|
||||
if result, err := r.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourceLong), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourceLongDo) FirstOrCreate() (*models.ResourceLong, error) {
|
||||
if result, err := r.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourceLong), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourceLongDo) FindByPage(offset int, limit int) (result []*models.ResourceLong, count int64, err error) {
|
||||
result, err = r.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 = r.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (r resourceLongDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = r.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = r.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Scan(result interface{}) (err error) {
|
||||
return r.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (r resourceLongDo) Delete(models ...*models.ResourceLong) (result gen.ResultInfo, err error) {
|
||||
return r.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (r *resourceLongDo) withDO(do gen.Dao) *resourceLongDo {
|
||||
r.DO = *do.(*gen.DO)
|
||||
return r
|
||||
}
|
||||
@@ -1,323 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"platform/web/models"
|
||||
)
|
||||
|
||||
func newResourcePps(db *gorm.DB, opts ...gen.DOOption) resourcePps {
|
||||
_resourcePps := resourcePps{}
|
||||
|
||||
_resourcePps.resourcePpsDo.UseDB(db, opts...)
|
||||
_resourcePps.resourcePpsDo.UseModel(&models.ResourcePps{})
|
||||
|
||||
tableName := _resourcePps.resourcePpsDo.TableName()
|
||||
_resourcePps.ALL = field.NewAsterisk(tableName)
|
||||
_resourcePps.ID = field.NewInt32(tableName, "id")
|
||||
_resourcePps.ResourceID = field.NewInt32(tableName, "resource_id")
|
||||
|
||||
_resourcePps.fillFieldMap()
|
||||
|
||||
return _resourcePps
|
||||
}
|
||||
|
||||
type resourcePps struct {
|
||||
resourcePpsDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int32 // ID
|
||||
ResourceID field.Int32 // 套餐ID
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (r resourcePps) Table(newTableName string) *resourcePps {
|
||||
r.resourcePpsDo.UseTable(newTableName)
|
||||
return r.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (r resourcePps) As(alias string) *resourcePps {
|
||||
r.resourcePpsDo.DO = *(r.resourcePpsDo.As(alias).(*gen.DO))
|
||||
return r.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (r *resourcePps) updateTableName(table string) *resourcePps {
|
||||
r.ALL = field.NewAsterisk(table)
|
||||
r.ID = field.NewInt32(table, "id")
|
||||
r.ResourceID = field.NewInt32(table, "resource_id")
|
||||
|
||||
r.fillFieldMap()
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *resourcePps) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := r.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (r *resourcePps) fillFieldMap() {
|
||||
r.fieldMap = make(map[string]field.Expr, 2)
|
||||
r.fieldMap["id"] = r.ID
|
||||
r.fieldMap["resource_id"] = r.ResourceID
|
||||
}
|
||||
|
||||
func (r resourcePps) clone(db *gorm.DB) resourcePps {
|
||||
r.resourcePpsDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r resourcePps) replaceDB(db *gorm.DB) resourcePps {
|
||||
r.resourcePpsDo.ReplaceDB(db)
|
||||
return r
|
||||
}
|
||||
|
||||
type resourcePpsDo struct{ gen.DO }
|
||||
|
||||
func (r resourcePpsDo) Debug() *resourcePpsDo {
|
||||
return r.withDO(r.DO.Debug())
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) WithContext(ctx context.Context) *resourcePpsDo {
|
||||
return r.withDO(r.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) ReadDB() *resourcePpsDo {
|
||||
return r.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) WriteDB() *resourcePpsDo {
|
||||
return r.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Session(config *gorm.Session) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Session(config))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Clauses(conds ...clause.Expression) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Returning(value interface{}, columns ...string) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Not(conds ...gen.Condition) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Or(conds ...gen.Condition) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Select(conds ...field.Expr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Where(conds ...gen.Condition) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Order(conds ...field.Expr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Distinct(cols ...field.Expr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Omit(cols ...field.Expr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Join(table schema.Tabler, on ...field.Expr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) LeftJoin(table schema.Tabler, on ...field.Expr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) RightJoin(table schema.Tabler, on ...field.Expr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Group(cols ...field.Expr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Having(conds ...gen.Condition) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Limit(limit int) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Offset(offset int) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Unscoped() *resourcePpsDo {
|
||||
return r.withDO(r.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Create(values ...*models.ResourcePps) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Create(values)
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) CreateInBatches(values []*models.ResourcePps, batchSize int) error {
|
||||
return r.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 (r resourcePpsDo) Save(values ...*models.ResourcePps) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Save(values)
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) First() (*models.ResourcePps, error) {
|
||||
if result, err := r.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePps), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Take() (*models.ResourcePps, error) {
|
||||
if result, err := r.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePps), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Last() (*models.ResourcePps, error) {
|
||||
if result, err := r.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePps), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Find() ([]*models.ResourcePps, error) {
|
||||
result, err := r.DO.Find()
|
||||
return result.([]*models.ResourcePps), err
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.ResourcePps, err error) {
|
||||
buf := make([]*models.ResourcePps, 0, batchSize)
|
||||
err = r.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 (r resourcePpsDo) FindInBatches(result *[]*models.ResourcePps, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return r.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Attrs(attrs ...field.AssignExpr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Assign(attrs ...field.AssignExpr) *resourcePpsDo {
|
||||
return r.withDO(r.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Joins(fields ...field.RelationField) *resourcePpsDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Joins(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Preload(fields ...field.RelationField) *resourcePpsDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Preload(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) FirstOrInit() (*models.ResourcePps, error) {
|
||||
if result, err := r.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePps), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) FirstOrCreate() (*models.ResourcePps, error) {
|
||||
if result, err := r.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePps), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) FindByPage(offset int, limit int) (result []*models.ResourcePps, count int64, err error) {
|
||||
result, err = r.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 = r.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = r.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = r.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Scan(result interface{}) (err error) {
|
||||
return r.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (r resourcePpsDo) Delete(models ...*models.ResourcePps) (result gen.ResultInfo, err error) {
|
||||
return r.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (r *resourcePpsDo) withDO(do gen.Dao) *resourcePpsDo {
|
||||
r.DO = *do.(*gen.DO)
|
||||
return r
|
||||
}
|
||||
@@ -1,339 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"platform/web/models"
|
||||
)
|
||||
|
||||
func newResourcePsr(db *gorm.DB, opts ...gen.DOOption) resourcePsr {
|
||||
_resourcePsr := resourcePsr{}
|
||||
|
||||
_resourcePsr.resourcePsrDo.UseDB(db, opts...)
|
||||
_resourcePsr.resourcePsrDo.UseModel(&models.ResourcePsr{})
|
||||
|
||||
tableName := _resourcePsr.resourcePsrDo.TableName()
|
||||
_resourcePsr.ALL = field.NewAsterisk(tableName)
|
||||
_resourcePsr.ID = field.NewInt32(tableName, "id")
|
||||
_resourcePsr.ResourceID = field.NewInt32(tableName, "resource_id")
|
||||
_resourcePsr.Live = field.NewInt32(tableName, "live")
|
||||
_resourcePsr.Conn = field.NewInt32(tableName, "conn")
|
||||
_resourcePsr.Expire = field.NewField(tableName, "expire")
|
||||
_resourcePsr.Used = field.NewBool(tableName, "used")
|
||||
|
||||
_resourcePsr.fillFieldMap()
|
||||
|
||||
return _resourcePsr
|
||||
}
|
||||
|
||||
type resourcePsr struct {
|
||||
resourcePsrDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int32 // ID
|
||||
ResourceID field.Int32 // 套餐ID
|
||||
Live field.Int32 // 轮换周期(秒)
|
||||
Conn field.Int32 // 最大连接数
|
||||
Expire field.Field // 过期时间
|
||||
Used field.Bool // 是否已使用
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (r resourcePsr) Table(newTableName string) *resourcePsr {
|
||||
r.resourcePsrDo.UseTable(newTableName)
|
||||
return r.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (r resourcePsr) As(alias string) *resourcePsr {
|
||||
r.resourcePsrDo.DO = *(r.resourcePsrDo.As(alias).(*gen.DO))
|
||||
return r.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (r *resourcePsr) updateTableName(table string) *resourcePsr {
|
||||
r.ALL = field.NewAsterisk(table)
|
||||
r.ID = field.NewInt32(table, "id")
|
||||
r.ResourceID = field.NewInt32(table, "resource_id")
|
||||
r.Live = field.NewInt32(table, "live")
|
||||
r.Conn = field.NewInt32(table, "conn")
|
||||
r.Expire = field.NewField(table, "expire")
|
||||
r.Used = field.NewBool(table, "used")
|
||||
|
||||
r.fillFieldMap()
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *resourcePsr) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := r.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (r *resourcePsr) fillFieldMap() {
|
||||
r.fieldMap = make(map[string]field.Expr, 6)
|
||||
r.fieldMap["id"] = r.ID
|
||||
r.fieldMap["resource_id"] = r.ResourceID
|
||||
r.fieldMap["live"] = r.Live
|
||||
r.fieldMap["conn"] = r.Conn
|
||||
r.fieldMap["expire"] = r.Expire
|
||||
r.fieldMap["used"] = r.Used
|
||||
}
|
||||
|
||||
func (r resourcePsr) clone(db *gorm.DB) resourcePsr {
|
||||
r.resourcePsrDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r resourcePsr) replaceDB(db *gorm.DB) resourcePsr {
|
||||
r.resourcePsrDo.ReplaceDB(db)
|
||||
return r
|
||||
}
|
||||
|
||||
type resourcePsrDo struct{ gen.DO }
|
||||
|
||||
func (r resourcePsrDo) Debug() *resourcePsrDo {
|
||||
return r.withDO(r.DO.Debug())
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) WithContext(ctx context.Context) *resourcePsrDo {
|
||||
return r.withDO(r.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) ReadDB() *resourcePsrDo {
|
||||
return r.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) WriteDB() *resourcePsrDo {
|
||||
return r.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Session(config *gorm.Session) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Session(config))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Clauses(conds ...clause.Expression) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Returning(value interface{}, columns ...string) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Not(conds ...gen.Condition) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Or(conds ...gen.Condition) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Select(conds ...field.Expr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Where(conds ...gen.Condition) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Order(conds ...field.Expr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Distinct(cols ...field.Expr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Omit(cols ...field.Expr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Join(table schema.Tabler, on ...field.Expr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) LeftJoin(table schema.Tabler, on ...field.Expr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) RightJoin(table schema.Tabler, on ...field.Expr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Group(cols ...field.Expr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Having(conds ...gen.Condition) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Limit(limit int) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Offset(offset int) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Unscoped() *resourcePsrDo {
|
||||
return r.withDO(r.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Create(values ...*models.ResourcePsr) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Create(values)
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) CreateInBatches(values []*models.ResourcePsr, batchSize int) error {
|
||||
return r.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 (r resourcePsrDo) Save(values ...*models.ResourcePsr) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Save(values)
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) First() (*models.ResourcePsr, error) {
|
||||
if result, err := r.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePsr), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Take() (*models.ResourcePsr, error) {
|
||||
if result, err := r.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePsr), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Last() (*models.ResourcePsr, error) {
|
||||
if result, err := r.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePsr), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Find() ([]*models.ResourcePsr, error) {
|
||||
result, err := r.DO.Find()
|
||||
return result.([]*models.ResourcePsr), err
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.ResourcePsr, err error) {
|
||||
buf := make([]*models.ResourcePsr, 0, batchSize)
|
||||
err = r.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 (r resourcePsrDo) FindInBatches(result *[]*models.ResourcePsr, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return r.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Attrs(attrs ...field.AssignExpr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Assign(attrs ...field.AssignExpr) *resourcePsrDo {
|
||||
return r.withDO(r.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Joins(fields ...field.RelationField) *resourcePsrDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Joins(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Preload(fields ...field.RelationField) *resourcePsrDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Preload(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) FirstOrInit() (*models.ResourcePsr, error) {
|
||||
if result, err := r.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePsr), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) FirstOrCreate() (*models.ResourcePsr, error) {
|
||||
if result, err := r.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePsr), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) FindByPage(offset int, limit int) (result []*models.ResourcePsr, count int64, err error) {
|
||||
result, err = r.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 = r.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = r.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = r.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Scan(result interface{}) (err error) {
|
||||
return r.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (r resourcePsrDo) Delete(models ...*models.ResourcePsr) (result gen.ResultInfo, err error) {
|
||||
return r.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (r *resourcePsrDo) withDO(do gen.Dao) *resourcePsrDo {
|
||||
r.DO = *do.(*gen.DO)
|
||||
return r
|
||||
}
|
||||
@@ -1,355 +0,0 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"platform/web/models"
|
||||
)
|
||||
|
||||
func newResourcePss(db *gorm.DB, opts ...gen.DOOption) resourcePss {
|
||||
_resourcePss := resourcePss{}
|
||||
|
||||
_resourcePss.resourcePssDo.UseDB(db, opts...)
|
||||
_resourcePss.resourcePssDo.UseModel(&models.ResourcePss{})
|
||||
|
||||
tableName := _resourcePss.resourcePssDo.TableName()
|
||||
_resourcePss.ALL = field.NewAsterisk(tableName)
|
||||
_resourcePss.ID = field.NewInt32(tableName, "id")
|
||||
_resourcePss.ResourceID = field.NewInt32(tableName, "resource_id")
|
||||
_resourcePss.Type = field.NewInt32(tableName, "type")
|
||||
_resourcePss.Live = field.NewInt32(tableName, "live")
|
||||
_resourcePss.Expire = field.NewField(tableName, "expire")
|
||||
_resourcePss.Quota = field.NewInt32(tableName, "quota")
|
||||
_resourcePss.Used = field.NewInt32(tableName, "used")
|
||||
_resourcePss.DailyLimit = field.NewInt32(tableName, "daily_limit")
|
||||
_resourcePss.DailyUsed = field.NewInt32(tableName, "daily_used")
|
||||
_resourcePss.DailyLast = field.NewField(tableName, "daily_last")
|
||||
|
||||
_resourcePss.fillFieldMap()
|
||||
|
||||
return _resourcePss
|
||||
}
|
||||
|
||||
type resourcePss struct {
|
||||
resourcePssDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int32 // ID
|
||||
ResourceID field.Int32 // 套餐ID
|
||||
Type field.Int32 // 套餐类型:1-包时,2-包量
|
||||
Live field.Int32 // 可用时长(秒)
|
||||
Expire field.Field // 过期时间
|
||||
Quota field.Int32 // 配额数量
|
||||
Used field.Int32 // 已用数量
|
||||
DailyLimit field.Int32 // 每日限制
|
||||
DailyUsed field.Int32 // 今日已用数量
|
||||
DailyLast field.Field // 今日最后使用时间
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (r resourcePss) Table(newTableName string) *resourcePss {
|
||||
r.resourcePssDo.UseTable(newTableName)
|
||||
return r.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (r resourcePss) As(alias string) *resourcePss {
|
||||
r.resourcePssDo.DO = *(r.resourcePssDo.As(alias).(*gen.DO))
|
||||
return r.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (r *resourcePss) updateTableName(table string) *resourcePss {
|
||||
r.ALL = field.NewAsterisk(table)
|
||||
r.ID = field.NewInt32(table, "id")
|
||||
r.ResourceID = field.NewInt32(table, "resource_id")
|
||||
r.Type = field.NewInt32(table, "type")
|
||||
r.Live = field.NewInt32(table, "live")
|
||||
r.Expire = field.NewField(table, "expire")
|
||||
r.Quota = field.NewInt32(table, "quota")
|
||||
r.Used = field.NewInt32(table, "used")
|
||||
r.DailyLimit = field.NewInt32(table, "daily_limit")
|
||||
r.DailyUsed = field.NewInt32(table, "daily_used")
|
||||
r.DailyLast = field.NewField(table, "daily_last")
|
||||
|
||||
r.fillFieldMap()
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *resourcePss) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := r.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (r *resourcePss) fillFieldMap() {
|
||||
r.fieldMap = make(map[string]field.Expr, 10)
|
||||
r.fieldMap["id"] = r.ID
|
||||
r.fieldMap["resource_id"] = r.ResourceID
|
||||
r.fieldMap["type"] = r.Type
|
||||
r.fieldMap["live"] = r.Live
|
||||
r.fieldMap["expire"] = r.Expire
|
||||
r.fieldMap["quota"] = r.Quota
|
||||
r.fieldMap["used"] = r.Used
|
||||
r.fieldMap["daily_limit"] = r.DailyLimit
|
||||
r.fieldMap["daily_used"] = r.DailyUsed
|
||||
r.fieldMap["daily_last"] = r.DailyLast
|
||||
}
|
||||
|
||||
func (r resourcePss) clone(db *gorm.DB) resourcePss {
|
||||
r.resourcePssDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r resourcePss) replaceDB(db *gorm.DB) resourcePss {
|
||||
r.resourcePssDo.ReplaceDB(db)
|
||||
return r
|
||||
}
|
||||
|
||||
type resourcePssDo struct{ gen.DO }
|
||||
|
||||
func (r resourcePssDo) Debug() *resourcePssDo {
|
||||
return r.withDO(r.DO.Debug())
|
||||
}
|
||||
|
||||
func (r resourcePssDo) WithContext(ctx context.Context) *resourcePssDo {
|
||||
return r.withDO(r.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) ReadDB() *resourcePssDo {
|
||||
return r.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (r resourcePssDo) WriteDB() *resourcePssDo {
|
||||
return r.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Session(config *gorm.Session) *resourcePssDo {
|
||||
return r.withDO(r.DO.Session(config))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Clauses(conds ...clause.Expression) *resourcePssDo {
|
||||
return r.withDO(r.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Returning(value interface{}, columns ...string) *resourcePssDo {
|
||||
return r.withDO(r.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Not(conds ...gen.Condition) *resourcePssDo {
|
||||
return r.withDO(r.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Or(conds ...gen.Condition) *resourcePssDo {
|
||||
return r.withDO(r.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Select(conds ...field.Expr) *resourcePssDo {
|
||||
return r.withDO(r.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Where(conds ...gen.Condition) *resourcePssDo {
|
||||
return r.withDO(r.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Order(conds ...field.Expr) *resourcePssDo {
|
||||
return r.withDO(r.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Distinct(cols ...field.Expr) *resourcePssDo {
|
||||
return r.withDO(r.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Omit(cols ...field.Expr) *resourcePssDo {
|
||||
return r.withDO(r.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Join(table schema.Tabler, on ...field.Expr) *resourcePssDo {
|
||||
return r.withDO(r.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) LeftJoin(table schema.Tabler, on ...field.Expr) *resourcePssDo {
|
||||
return r.withDO(r.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) RightJoin(table schema.Tabler, on ...field.Expr) *resourcePssDo {
|
||||
return r.withDO(r.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Group(cols ...field.Expr) *resourcePssDo {
|
||||
return r.withDO(r.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Having(conds ...gen.Condition) *resourcePssDo {
|
||||
return r.withDO(r.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Limit(limit int) *resourcePssDo {
|
||||
return r.withDO(r.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Offset(offset int) *resourcePssDo {
|
||||
return r.withDO(r.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *resourcePssDo {
|
||||
return r.withDO(r.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Unscoped() *resourcePssDo {
|
||||
return r.withDO(r.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Create(values ...*models.ResourcePss) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Create(values)
|
||||
}
|
||||
|
||||
func (r resourcePssDo) CreateInBatches(values []*models.ResourcePss, batchSize int) error {
|
||||
return r.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 (r resourcePssDo) Save(values ...*models.ResourcePss) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Save(values)
|
||||
}
|
||||
|
||||
func (r resourcePssDo) First() (*models.ResourcePss, error) {
|
||||
if result, err := r.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePss), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Take() (*models.ResourcePss, error) {
|
||||
if result, err := r.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePss), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Last() (*models.ResourcePss, error) {
|
||||
if result, err := r.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePss), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Find() ([]*models.ResourcePss, error) {
|
||||
result, err := r.DO.Find()
|
||||
return result.([]*models.ResourcePss), err
|
||||
}
|
||||
|
||||
func (r resourcePssDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.ResourcePss, err error) {
|
||||
buf := make([]*models.ResourcePss, 0, batchSize)
|
||||
err = r.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 (r resourcePssDo) FindInBatches(result *[]*models.ResourcePss, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return r.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Attrs(attrs ...field.AssignExpr) *resourcePssDo {
|
||||
return r.withDO(r.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Assign(attrs ...field.AssignExpr) *resourcePssDo {
|
||||
return r.withDO(r.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Joins(fields ...field.RelationField) *resourcePssDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Joins(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Preload(fields ...field.RelationField) *resourcePssDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Preload(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r resourcePssDo) FirstOrInit() (*models.ResourcePss, error) {
|
||||
if result, err := r.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePss), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePssDo) FirstOrCreate() (*models.ResourcePss, error) {
|
||||
if result, err := r.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourcePss), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourcePssDo) FindByPage(offset int, limit int) (result []*models.ResourcePss, count int64, err error) {
|
||||
result, err = r.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 = r.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (r resourcePssDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = r.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = r.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Scan(result interface{}) (err error) {
|
||||
return r.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (r resourcePssDo) Delete(models ...*models.ResourcePss) (result gen.ResultInfo, err error) {
|
||||
return r.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (r *resourcePssDo) withDO(do gen.Dao) *resourcePssDo {
|
||||
r.DO = *do.(*gen.DO)
|
||||
return r
|
||||
}
|
||||
355
web/queries/resource_short.gen.go
Normal file
355
web/queries/resource_short.gen.go
Normal file
@@ -0,0 +1,355 @@
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"platform/web/models"
|
||||
)
|
||||
|
||||
func newResourceShort(db *gorm.DB, opts ...gen.DOOption) resourceShort {
|
||||
_resourceShort := resourceShort{}
|
||||
|
||||
_resourceShort.resourceShortDo.UseDB(db, opts...)
|
||||
_resourceShort.resourceShortDo.UseModel(&models.ResourceShort{})
|
||||
|
||||
tableName := _resourceShort.resourceShortDo.TableName()
|
||||
_resourceShort.ALL = field.NewAsterisk(tableName)
|
||||
_resourceShort.ID = field.NewInt32(tableName, "id")
|
||||
_resourceShort.ResourceID = field.NewInt32(tableName, "resource_id")
|
||||
_resourceShort.Type = field.NewInt32(tableName, "type")
|
||||
_resourceShort.Live = field.NewInt32(tableName, "live")
|
||||
_resourceShort.Expire = field.NewField(tableName, "expire")
|
||||
_resourceShort.Quota = field.NewInt32(tableName, "quota")
|
||||
_resourceShort.Used = field.NewInt32(tableName, "used")
|
||||
_resourceShort.DailyLimit = field.NewInt32(tableName, "daily_limit")
|
||||
_resourceShort.DailyUsed = field.NewInt32(tableName, "daily_used")
|
||||
_resourceShort.DailyLast = field.NewField(tableName, "daily_last")
|
||||
|
||||
_resourceShort.fillFieldMap()
|
||||
|
||||
return _resourceShort
|
||||
}
|
||||
|
||||
type resourceShort struct {
|
||||
resourceShortDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int32 // ID
|
||||
ResourceID field.Int32 // 套餐ID
|
||||
Type field.Int32 // 套餐类型:1-包时,2-包量
|
||||
Live field.Int32 // 可用时长(秒)
|
||||
Expire field.Field // 过期时间
|
||||
Quota field.Int32 // 配额数量
|
||||
Used field.Int32 // 已用数量
|
||||
DailyLimit field.Int32 // 每日限制
|
||||
DailyUsed field.Int32 // 今日已用数量
|
||||
DailyLast field.Field // 今日最后使用时间
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (r resourceShort) Table(newTableName string) *resourceShort {
|
||||
r.resourceShortDo.UseTable(newTableName)
|
||||
return r.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (r resourceShort) As(alias string) *resourceShort {
|
||||
r.resourceShortDo.DO = *(r.resourceShortDo.As(alias).(*gen.DO))
|
||||
return r.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (r *resourceShort) updateTableName(table string) *resourceShort {
|
||||
r.ALL = field.NewAsterisk(table)
|
||||
r.ID = field.NewInt32(table, "id")
|
||||
r.ResourceID = field.NewInt32(table, "resource_id")
|
||||
r.Type = field.NewInt32(table, "type")
|
||||
r.Live = field.NewInt32(table, "live")
|
||||
r.Expire = field.NewField(table, "expire")
|
||||
r.Quota = field.NewInt32(table, "quota")
|
||||
r.Used = field.NewInt32(table, "used")
|
||||
r.DailyLimit = field.NewInt32(table, "daily_limit")
|
||||
r.DailyUsed = field.NewInt32(table, "daily_used")
|
||||
r.DailyLast = field.NewField(table, "daily_last")
|
||||
|
||||
r.fillFieldMap()
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *resourceShort) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := r.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (r *resourceShort) fillFieldMap() {
|
||||
r.fieldMap = make(map[string]field.Expr, 10)
|
||||
r.fieldMap["id"] = r.ID
|
||||
r.fieldMap["resource_id"] = r.ResourceID
|
||||
r.fieldMap["type"] = r.Type
|
||||
r.fieldMap["live"] = r.Live
|
||||
r.fieldMap["expire"] = r.Expire
|
||||
r.fieldMap["quota"] = r.Quota
|
||||
r.fieldMap["used"] = r.Used
|
||||
r.fieldMap["daily_limit"] = r.DailyLimit
|
||||
r.fieldMap["daily_used"] = r.DailyUsed
|
||||
r.fieldMap["daily_last"] = r.DailyLast
|
||||
}
|
||||
|
||||
func (r resourceShort) clone(db *gorm.DB) resourceShort {
|
||||
r.resourceShortDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r resourceShort) replaceDB(db *gorm.DB) resourceShort {
|
||||
r.resourceShortDo.ReplaceDB(db)
|
||||
return r
|
||||
}
|
||||
|
||||
type resourceShortDo struct{ gen.DO }
|
||||
|
||||
func (r resourceShortDo) Debug() *resourceShortDo {
|
||||
return r.withDO(r.DO.Debug())
|
||||
}
|
||||
|
||||
func (r resourceShortDo) WithContext(ctx context.Context) *resourceShortDo {
|
||||
return r.withDO(r.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) ReadDB() *resourceShortDo {
|
||||
return r.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (r resourceShortDo) WriteDB() *resourceShortDo {
|
||||
return r.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Session(config *gorm.Session) *resourceShortDo {
|
||||
return r.withDO(r.DO.Session(config))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Clauses(conds ...clause.Expression) *resourceShortDo {
|
||||
return r.withDO(r.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Returning(value interface{}, columns ...string) *resourceShortDo {
|
||||
return r.withDO(r.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Not(conds ...gen.Condition) *resourceShortDo {
|
||||
return r.withDO(r.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Or(conds ...gen.Condition) *resourceShortDo {
|
||||
return r.withDO(r.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Select(conds ...field.Expr) *resourceShortDo {
|
||||
return r.withDO(r.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Where(conds ...gen.Condition) *resourceShortDo {
|
||||
return r.withDO(r.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Order(conds ...field.Expr) *resourceShortDo {
|
||||
return r.withDO(r.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Distinct(cols ...field.Expr) *resourceShortDo {
|
||||
return r.withDO(r.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Omit(cols ...field.Expr) *resourceShortDo {
|
||||
return r.withDO(r.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Join(table schema.Tabler, on ...field.Expr) *resourceShortDo {
|
||||
return r.withDO(r.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) LeftJoin(table schema.Tabler, on ...field.Expr) *resourceShortDo {
|
||||
return r.withDO(r.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) RightJoin(table schema.Tabler, on ...field.Expr) *resourceShortDo {
|
||||
return r.withDO(r.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Group(cols ...field.Expr) *resourceShortDo {
|
||||
return r.withDO(r.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Having(conds ...gen.Condition) *resourceShortDo {
|
||||
return r.withDO(r.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Limit(limit int) *resourceShortDo {
|
||||
return r.withDO(r.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Offset(offset int) *resourceShortDo {
|
||||
return r.withDO(r.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *resourceShortDo {
|
||||
return r.withDO(r.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Unscoped() *resourceShortDo {
|
||||
return r.withDO(r.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Create(values ...*models.ResourceShort) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Create(values)
|
||||
}
|
||||
|
||||
func (r resourceShortDo) CreateInBatches(values []*models.ResourceShort, batchSize int) error {
|
||||
return r.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 (r resourceShortDo) Save(values ...*models.ResourceShort) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return r.DO.Save(values)
|
||||
}
|
||||
|
||||
func (r resourceShortDo) First() (*models.ResourceShort, error) {
|
||||
if result, err := r.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourceShort), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Take() (*models.ResourceShort, error) {
|
||||
if result, err := r.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourceShort), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Last() (*models.ResourceShort, error) {
|
||||
if result, err := r.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourceShort), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Find() ([]*models.ResourceShort, error) {
|
||||
result, err := r.DO.Find()
|
||||
return result.([]*models.ResourceShort), err
|
||||
}
|
||||
|
||||
func (r resourceShortDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.ResourceShort, err error) {
|
||||
buf := make([]*models.ResourceShort, 0, batchSize)
|
||||
err = r.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 (r resourceShortDo) FindInBatches(result *[]*models.ResourceShort, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return r.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Attrs(attrs ...field.AssignExpr) *resourceShortDo {
|
||||
return r.withDO(r.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Assign(attrs ...field.AssignExpr) *resourceShortDo {
|
||||
return r.withDO(r.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Joins(fields ...field.RelationField) *resourceShortDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Joins(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Preload(fields ...field.RelationField) *resourceShortDo {
|
||||
for _, _f := range fields {
|
||||
r = *r.withDO(r.DO.Preload(_f))
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r resourceShortDo) FirstOrInit() (*models.ResourceShort, error) {
|
||||
if result, err := r.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourceShort), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourceShortDo) FirstOrCreate() (*models.ResourceShort, error) {
|
||||
if result, err := r.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*models.ResourceShort), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r resourceShortDo) FindByPage(offset int, limit int) (result []*models.ResourceShort, count int64, err error) {
|
||||
result, err = r.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 = r.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (r resourceShortDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = r.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = r.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Scan(result interface{}) (err error) {
|
||||
return r.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (r resourceShortDo) Delete(models ...*models.ResourceShort) (result gen.ResultInfo, err error) {
|
||||
return r.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (r *resourceShortDo) withDO(do gen.Dao) *resourceShortDo {
|
||||
r.DO = *do.(*gen.DO)
|
||||
return r
|
||||
}
|
||||
@@ -43,7 +43,7 @@ func ApplyRouters(app *fiber.App) {
|
||||
|
||||
// 套餐
|
||||
resource := api.Group("/resource")
|
||||
resource.Post("/list/pss", handlers.ListResourcePss)
|
||||
resource.Post("/list/short", handlers.ListResourceShort)
|
||||
resource.Post("/all", handlers.AllResource)
|
||||
resource.Post("/create/balance", handlers.CreateResourceByBalance)
|
||||
resource.Post("/prepare/alipay", handlers.PrepareResourceByAlipay)
|
||||
|
||||
@@ -286,13 +286,13 @@ func (s *channelService) CreateChannel(
|
||||
func findResource(q *q.Query, resourceId int32, authCtx *auth.Context, count int) (*ResourceInfo, error) {
|
||||
var resource = new(ResourceInfo)
|
||||
data := q.Resource.As("data")
|
||||
pss := q.ResourcePss.As("pss")
|
||||
short := q.ResourceShort.As("short")
|
||||
err := data.Scopes(orm.Alias(data)).
|
||||
Select(
|
||||
data.ID, data.UserID, data.Active,
|
||||
pss.Type, pss.Live, pss.DailyUsed, pss.DailyLimit, pss.DailyLast, pss.Quota, pss.Used, pss.Expire,
|
||||
short.Type, short.Live, short.DailyUsed, short.DailyLimit, short.DailyLast, short.Quota, short.Used, short.Expire,
|
||||
).
|
||||
LeftJoin(q.ResourcePss.As("pss"), pss.ResourceID.EqCol(data.ID)).
|
||||
LeftJoin(q.ResourceShort.As("short"), short.ResourceID.EqCol(data.ID)).
|
||||
Where(
|
||||
data.ID.Eq(resourceId),
|
||||
data.UserID.Eq(authCtx.Payload.Id),
|
||||
@@ -565,7 +565,7 @@ func calcChannels(
|
||||
}
|
||||
|
||||
func updateResource(rid string, resource *ResourceInfo, count int, now time.Time) (err error) {
|
||||
toUpdate := m.ResourcePss{
|
||||
toUpdate := m.ResourceShort{
|
||||
Used: resource.Used + int32(count),
|
||||
DailyLast: orm.LocalDateTime(now),
|
||||
}
|
||||
@@ -575,12 +575,12 @@ func updateResource(rid string, resource *ResourceInfo, count int, now time.Time
|
||||
} else {
|
||||
toUpdate.DailyUsed = resource.DailyUsed + int32(count)
|
||||
}
|
||||
_, err = q.ResourcePss.
|
||||
Where(q.ResourcePss.ResourceID.Eq(resource.Id)).
|
||||
_, err = q.ResourceShort.
|
||||
Where(q.ResourceShort.ResourceID.Eq(resource.Id)).
|
||||
Select(
|
||||
q.ResourcePss.Used,
|
||||
q.ResourcePss.DailyUsed,
|
||||
q.ResourcePss.DailyLast,
|
||||
q.ResourceShort.Used,
|
||||
q.ResourceShort.DailyUsed,
|
||||
q.ResourceShort.DailyLast,
|
||||
).
|
||||
Updates(toUpdate)
|
||||
if err != nil {
|
||||
|
||||
@@ -246,8 +246,8 @@ func createResource(q *q.Query, data *CreateResourceData, uid int32) (*m.Resourc
|
||||
UserID: uid,
|
||||
ResourceNo: ID.GenReadable("res"),
|
||||
Active: true,
|
||||
Type: int32(resource2.TypeDynamic),
|
||||
Pss: &m.ResourcePss{
|
||||
Type: int32(resource2.TypeShort),
|
||||
Short: &m.ResourceShort{
|
||||
Type: data.Type,
|
||||
Live: data.Live,
|
||||
Quota: data.Quota,
|
||||
|
||||
Reference in New Issue
Block a user