Compare commits
2 Commits
v1.0.3
...
v1.0.4.beta1
| Author | SHA1 | Date | |
|---|---|---|---|
| 14108f6ba3 | |||
| a22f559889 |
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"likedream-goframe/internal/common/cst"
|
||||
"likedream-goframe/internal/controller/agent"
|
||||
"likedream-goframe/internal/controller/balance"
|
||||
"likedream-goframe/internal/controller/card"
|
||||
"likedream-goframe/internal/controller/common"
|
||||
"likedream-goframe/internal/controller/config"
|
||||
@@ -47,6 +48,7 @@ func StartServer(ctx context.Context) {
|
||||
// 用户信息路由
|
||||
userGroup := group.Group("/user").Middleware(middleware.AuthHandler, middleware.PermissionHandler)
|
||||
userGroup.Bind(user_login.NewUserInfoV1())
|
||||
userGroup.Bind(balance.NewBalanceCtrlV1())
|
||||
// 代理信息路由
|
||||
agentGroup := group.Group("/agent").Middleware(middleware.AuthHandler, middleware.PermissionHandler)
|
||||
agentGroup.Bind(agent.NewV1())
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package v1
|
||||
|
||||
import "github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
type BalanceRecordListReq struct {
|
||||
g.Meta `path:"/balance/records" method:"get" tags:"Balance" summary:"获取用户余额变动记录列表"`
|
||||
Type string `json:"type" dc:"变动类型: increase-增加, decrease-减少"`
|
||||
Page int `json:"page" d:"1"`
|
||||
Size int `json:"size" d:"10"`
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package balance
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/service"
|
||||
"likedream-goframe/internal/utils"
|
||||
)
|
||||
|
||||
type BalanceCtrlV1 struct {
|
||||
}
|
||||
|
||||
func NewBalanceCtrlV1() IBalanceCtrlV1 {
|
||||
return &BalanceCtrlV1{}
|
||||
}
|
||||
|
||||
func (b BalanceCtrlV1) List(ctx context.Context, req *v1.BalanceRecordListReq) (res *utils.Response[[]*ent.SysBalanceRecord], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.Balance.List(ctx, req), nil
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package balance
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/utils"
|
||||
)
|
||||
|
||||
type IBalanceCtrlV1 interface {
|
||||
List(ctx context.Context, req *v1.BalanceRecordListReq) (res *utils.Response[[]*ent.SysBalanceRecord], err error)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/framework/captcha"
|
||||
"likedream-goframe/internal/framework/errors"
|
||||
"likedream-goframe/internal/framework/redis"
|
||||
"likedream-goframe/internal/service"
|
||||
"likedream-goframe/internal/utils"
|
||||
@@ -46,6 +47,7 @@ func (c *UserLoginV1) Login(ctx context.Context, req *v1.UserLoginReq) (res *uti
|
||||
if !captcha.VerifyCaptcha(dots, req.Dots) {
|
||||
return utils.Fail(10003, "验证码错误"), nil
|
||||
}
|
||||
utils.OkOrPanic(errors.NewBusinessError(400, "注册功能暂时关闭,请等待重新开放"))
|
||||
return service.Global.UserLogin.Login(ctx, req), nil
|
||||
}
|
||||
|
||||
|
||||
+220
-38
@@ -19,6 +19,7 @@ import (
|
||||
"likedream-goframe/internal/ent/cptasklog"
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/ent/sysagent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysconfig"
|
||||
"likedream-goframe/internal/ent/sysmenu"
|
||||
@@ -56,6 +57,8 @@ type Client struct {
|
||||
CpUser *CpUserClient
|
||||
// SysAgent is the client for interacting with the SysAgent builders.
|
||||
SysAgent *SysAgentClient
|
||||
// SysBalanceRecord is the client for interacting with the SysBalanceRecord builders.
|
||||
SysBalanceRecord *SysBalanceRecordClient
|
||||
// SysCard is the client for interacting with the SysCard builders.
|
||||
SysCard *SysCardClient
|
||||
// SysConfig is the client for interacting with the SysConfig builders.
|
||||
@@ -87,6 +90,7 @@ func (c *Client) init() {
|
||||
c.CpTaskLog = NewCpTaskLogClient(c.config)
|
||||
c.CpUser = NewCpUserClient(c.config)
|
||||
c.SysAgent = NewSysAgentClient(c.config)
|
||||
c.SysBalanceRecord = NewSysBalanceRecordClient(c.config)
|
||||
c.SysCard = NewSysCardClient(c.config)
|
||||
c.SysConfig = NewSysConfigClient(c.config)
|
||||
c.SysMenu = NewSysMenuClient(c.config)
|
||||
@@ -185,22 +189,23 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||
cfg := c.config
|
||||
cfg.driver = tx
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
CourseEntity: NewCourseEntityClient(cfg),
|
||||
CpImage: NewCpImageClient(cfg),
|
||||
CpLeave: NewCpLeaveClient(cfg),
|
||||
CpSchool: NewCpSchoolClient(cfg),
|
||||
CpTask: NewCpTaskClient(cfg),
|
||||
CpTaskLog: NewCpTaskLogClient(cfg),
|
||||
CpUser: NewCpUserClient(cfg),
|
||||
SysAgent: NewSysAgentClient(cfg),
|
||||
SysCard: NewSysCardClient(cfg),
|
||||
SysConfig: NewSysConfigClient(cfg),
|
||||
SysMenu: NewSysMenuClient(cfg),
|
||||
SysRole: NewSysRoleClient(cfg),
|
||||
SysUser: NewSysUserClient(cfg),
|
||||
SysUserLog: NewSysUserLogClient(cfg),
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
CourseEntity: NewCourseEntityClient(cfg),
|
||||
CpImage: NewCpImageClient(cfg),
|
||||
CpLeave: NewCpLeaveClient(cfg),
|
||||
CpSchool: NewCpSchoolClient(cfg),
|
||||
CpTask: NewCpTaskClient(cfg),
|
||||
CpTaskLog: NewCpTaskLogClient(cfg),
|
||||
CpUser: NewCpUserClient(cfg),
|
||||
SysAgent: NewSysAgentClient(cfg),
|
||||
SysBalanceRecord: NewSysBalanceRecordClient(cfg),
|
||||
SysCard: NewSysCardClient(cfg),
|
||||
SysConfig: NewSysConfigClient(cfg),
|
||||
SysMenu: NewSysMenuClient(cfg),
|
||||
SysRole: NewSysRoleClient(cfg),
|
||||
SysUser: NewSysUserClient(cfg),
|
||||
SysUserLog: NewSysUserLogClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -218,22 +223,23 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
cfg := c.config
|
||||
cfg.driver = &txDriver{tx: tx, drv: c.driver}
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
CourseEntity: NewCourseEntityClient(cfg),
|
||||
CpImage: NewCpImageClient(cfg),
|
||||
CpLeave: NewCpLeaveClient(cfg),
|
||||
CpSchool: NewCpSchoolClient(cfg),
|
||||
CpTask: NewCpTaskClient(cfg),
|
||||
CpTaskLog: NewCpTaskLogClient(cfg),
|
||||
CpUser: NewCpUserClient(cfg),
|
||||
SysAgent: NewSysAgentClient(cfg),
|
||||
SysCard: NewSysCardClient(cfg),
|
||||
SysConfig: NewSysConfigClient(cfg),
|
||||
SysMenu: NewSysMenuClient(cfg),
|
||||
SysRole: NewSysRoleClient(cfg),
|
||||
SysUser: NewSysUserClient(cfg),
|
||||
SysUserLog: NewSysUserLogClient(cfg),
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
CourseEntity: NewCourseEntityClient(cfg),
|
||||
CpImage: NewCpImageClient(cfg),
|
||||
CpLeave: NewCpLeaveClient(cfg),
|
||||
CpSchool: NewCpSchoolClient(cfg),
|
||||
CpTask: NewCpTaskClient(cfg),
|
||||
CpTaskLog: NewCpTaskLogClient(cfg),
|
||||
CpUser: NewCpUserClient(cfg),
|
||||
SysAgent: NewSysAgentClient(cfg),
|
||||
SysBalanceRecord: NewSysBalanceRecordClient(cfg),
|
||||
SysCard: NewSysCardClient(cfg),
|
||||
SysConfig: NewSysConfigClient(cfg),
|
||||
SysMenu: NewSysMenuClient(cfg),
|
||||
SysRole: NewSysRoleClient(cfg),
|
||||
SysUser: NewSysUserClient(cfg),
|
||||
SysUserLog: NewSysUserLogClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -264,8 +270,8 @@ func (c *Client) Close() error {
|
||||
func (c *Client) Use(hooks ...Hook) {
|
||||
for _, n := range []interface{ Use(...Hook) }{
|
||||
c.CourseEntity, c.CpImage, c.CpLeave, c.CpSchool, c.CpTask, c.CpTaskLog,
|
||||
c.CpUser, c.SysAgent, c.SysCard, c.SysConfig, c.SysMenu, c.SysRole, c.SysUser,
|
||||
c.SysUserLog,
|
||||
c.CpUser, c.SysAgent, c.SysBalanceRecord, c.SysCard, c.SysConfig, c.SysMenu,
|
||||
c.SysRole, c.SysUser, c.SysUserLog,
|
||||
} {
|
||||
n.Use(hooks...)
|
||||
}
|
||||
@@ -276,8 +282,8 @@ func (c *Client) Use(hooks ...Hook) {
|
||||
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||
for _, n := range []interface{ Intercept(...Interceptor) }{
|
||||
c.CourseEntity, c.CpImage, c.CpLeave, c.CpSchool, c.CpTask, c.CpTaskLog,
|
||||
c.CpUser, c.SysAgent, c.SysCard, c.SysConfig, c.SysMenu, c.SysRole, c.SysUser,
|
||||
c.SysUserLog,
|
||||
c.CpUser, c.SysAgent, c.SysBalanceRecord, c.SysCard, c.SysConfig, c.SysMenu,
|
||||
c.SysRole, c.SysUser, c.SysUserLog,
|
||||
} {
|
||||
n.Intercept(interceptors...)
|
||||
}
|
||||
@@ -302,6 +308,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
return c.CpUser.mutate(ctx, m)
|
||||
case *SysAgentMutation:
|
||||
return c.SysAgent.mutate(ctx, m)
|
||||
case *SysBalanceRecordMutation:
|
||||
return c.SysBalanceRecord.mutate(ctx, m)
|
||||
case *SysCardMutation:
|
||||
return c.SysCard.mutate(ctx, m)
|
||||
case *SysConfigMutation:
|
||||
@@ -1714,6 +1722,159 @@ func (c *SysAgentClient) mutate(ctx context.Context, m *SysAgentMutation) (Value
|
||||
}
|
||||
}
|
||||
|
||||
// SysBalanceRecordClient is a client for the SysBalanceRecord schema.
|
||||
type SysBalanceRecordClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewSysBalanceRecordClient returns a client for the SysBalanceRecord from the given config.
|
||||
func NewSysBalanceRecordClient(c config) *SysBalanceRecordClient {
|
||||
return &SysBalanceRecordClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `sysbalancerecord.Hooks(f(g(h())))`.
|
||||
func (c *SysBalanceRecordClient) Use(hooks ...Hook) {
|
||||
c.hooks.SysBalanceRecord = append(c.hooks.SysBalanceRecord, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `sysbalancerecord.Intercept(f(g(h())))`.
|
||||
func (c *SysBalanceRecordClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.SysBalanceRecord = append(c.inters.SysBalanceRecord, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a SysBalanceRecord entity.
|
||||
func (c *SysBalanceRecordClient) Create() *SysBalanceRecordCreate {
|
||||
mutation := newSysBalanceRecordMutation(c.config, OpCreate)
|
||||
return &SysBalanceRecordCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of SysBalanceRecord entities.
|
||||
func (c *SysBalanceRecordClient) CreateBulk(builders ...*SysBalanceRecordCreate) *SysBalanceRecordCreateBulk {
|
||||
return &SysBalanceRecordCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *SysBalanceRecordClient) MapCreateBulk(slice any, setFunc func(*SysBalanceRecordCreate, int)) *SysBalanceRecordCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &SysBalanceRecordCreateBulk{err: fmt.Errorf("calling to SysBalanceRecordClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*SysBalanceRecordCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &SysBalanceRecordCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for SysBalanceRecord.
|
||||
func (c *SysBalanceRecordClient) Update() *SysBalanceRecordUpdate {
|
||||
mutation := newSysBalanceRecordMutation(c.config, OpUpdate)
|
||||
return &SysBalanceRecordUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *SysBalanceRecordClient) UpdateOne(_m *SysBalanceRecord) *SysBalanceRecordUpdateOne {
|
||||
mutation := newSysBalanceRecordMutation(c.config, OpUpdateOne, withSysBalanceRecord(_m))
|
||||
return &SysBalanceRecordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *SysBalanceRecordClient) UpdateOneID(id int64) *SysBalanceRecordUpdateOne {
|
||||
mutation := newSysBalanceRecordMutation(c.config, OpUpdateOne, withSysBalanceRecordID(id))
|
||||
return &SysBalanceRecordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for SysBalanceRecord.
|
||||
func (c *SysBalanceRecordClient) Delete() *SysBalanceRecordDelete {
|
||||
mutation := newSysBalanceRecordMutation(c.config, OpDelete)
|
||||
return &SysBalanceRecordDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *SysBalanceRecordClient) DeleteOne(_m *SysBalanceRecord) *SysBalanceRecordDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *SysBalanceRecordClient) DeleteOneID(id int64) *SysBalanceRecordDeleteOne {
|
||||
builder := c.Delete().Where(sysbalancerecord.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &SysBalanceRecordDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for SysBalanceRecord.
|
||||
func (c *SysBalanceRecordClient) Query() *SysBalanceRecordQuery {
|
||||
return &SysBalanceRecordQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeSysBalanceRecord},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a SysBalanceRecord entity by its id.
|
||||
func (c *SysBalanceRecordClient) Get(ctx context.Context, id int64) (*SysBalanceRecord, error) {
|
||||
return c.Query().Where(sysbalancerecord.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *SysBalanceRecordClient) GetX(ctx context.Context, id int64) *SysBalanceRecord {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryUser queries the user edge of a SysBalanceRecord.
|
||||
func (c *SysBalanceRecordClient) QueryUser(_m *SysBalanceRecord) *SysUserQuery {
|
||||
query := (&SysUserClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(sysbalancerecord.Table, sysbalancerecord.FieldID, id),
|
||||
sqlgraph.To(sysuser.Table, sysuser.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, sysbalancerecord.UserTable, sysbalancerecord.UserColumn),
|
||||
)
|
||||
schemaConfig := _m.schemaConfig
|
||||
step.To.Schema = schemaConfig.SysUser
|
||||
step.Edge.Schema = schemaConfig.SysBalanceRecord
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *SysBalanceRecordClient) Hooks() []Hook {
|
||||
hooks := c.hooks.SysBalanceRecord
|
||||
return append(hooks[:len(hooks):len(hooks)], sysbalancerecord.Hooks[:]...)
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *SysBalanceRecordClient) Interceptors() []Interceptor {
|
||||
return c.inters.SysBalanceRecord
|
||||
}
|
||||
|
||||
func (c *SysBalanceRecordClient) mutate(ctx context.Context, m *SysBalanceRecordMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&SysBalanceRecordCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&SysBalanceRecordUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&SysBalanceRecordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&SysBalanceRecordDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown SysBalanceRecord mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// SysCardClient is a client for the SysCard schema.
|
||||
type SysCardClient struct {
|
||||
config
|
||||
@@ -2757,6 +2918,25 @@ func (c *SysUserClient) QueryCashbackCards(_m *SysUser) *SysCardQuery {
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryBalanceRecords queries the balance_records edge of a SysUser.
|
||||
func (c *SysUserClient) QueryBalanceRecords(_m *SysUser) *SysBalanceRecordQuery {
|
||||
query := (&SysBalanceRecordClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(sysuser.Table, sysuser.FieldID, id),
|
||||
sqlgraph.To(sysbalancerecord.Table, sysbalancerecord.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, sysuser.BalanceRecordsTable, sysuser.BalanceRecordsColumn),
|
||||
)
|
||||
schemaConfig := _m.schemaConfig
|
||||
step.To.Schema = schemaConfig.SysBalanceRecord
|
||||
step.Edge.Schema = schemaConfig.SysBalanceRecord
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *SysUserClient) Hooks() []Hook {
|
||||
hooks := c.hooks.SysUser
|
||||
@@ -2920,11 +3100,13 @@ func (c *SysUserLogClient) mutate(ctx context.Context, m *SysUserLogMutation) (V
|
||||
type (
|
||||
hooks struct {
|
||||
CourseEntity, CpImage, CpLeave, CpSchool, CpTask, CpTaskLog, CpUser, SysAgent,
|
||||
SysCard, SysConfig, SysMenu, SysRole, SysUser, SysUserLog []ent.Hook
|
||||
SysBalanceRecord, SysCard, SysConfig, SysMenu, SysRole, SysUser,
|
||||
SysUserLog []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
CourseEntity, CpImage, CpLeave, CpSchool, CpTask, CpTaskLog, CpUser, SysAgent,
|
||||
SysCard, SysConfig, SysMenu, SysRole, SysUser, SysUserLog []ent.Interceptor
|
||||
SysBalanceRecord, SysCard, SysConfig, SysMenu, SysRole, SysUser,
|
||||
SysUserLog []ent.Interceptor
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
+16
-14
@@ -14,6 +14,7 @@ import (
|
||||
"likedream-goframe/internal/ent/cptasklog"
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/ent/sysagent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysconfig"
|
||||
"likedream-goframe/internal/ent/sysmenu"
|
||||
@@ -86,20 +87,21 @@ var (
|
||||
func checkColumn(t, c string) error {
|
||||
initCheck.Do(func() {
|
||||
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||
courseentity.Table: courseentity.ValidColumn,
|
||||
cpimage.Table: cpimage.ValidColumn,
|
||||
cpleave.Table: cpleave.ValidColumn,
|
||||
cpschool.Table: cpschool.ValidColumn,
|
||||
cptask.Table: cptask.ValidColumn,
|
||||
cptasklog.Table: cptasklog.ValidColumn,
|
||||
cpuser.Table: cpuser.ValidColumn,
|
||||
sysagent.Table: sysagent.ValidColumn,
|
||||
syscard.Table: syscard.ValidColumn,
|
||||
sysconfig.Table: sysconfig.ValidColumn,
|
||||
sysmenu.Table: sysmenu.ValidColumn,
|
||||
sysrole.Table: sysrole.ValidColumn,
|
||||
sysuser.Table: sysuser.ValidColumn,
|
||||
sysuserlog.Table: sysuserlog.ValidColumn,
|
||||
courseentity.Table: courseentity.ValidColumn,
|
||||
cpimage.Table: cpimage.ValidColumn,
|
||||
cpleave.Table: cpleave.ValidColumn,
|
||||
cpschool.Table: cpschool.ValidColumn,
|
||||
cptask.Table: cptask.ValidColumn,
|
||||
cptasklog.Table: cptasklog.ValidColumn,
|
||||
cpuser.Table: cpuser.ValidColumn,
|
||||
sysagent.Table: sysagent.ValidColumn,
|
||||
sysbalancerecord.Table: sysbalancerecord.ValidColumn,
|
||||
syscard.Table: syscard.ValidColumn,
|
||||
sysconfig.Table: sysconfig.ValidColumn,
|
||||
sysmenu.Table: sysmenu.ValidColumn,
|
||||
sysrole.Table: sysrole.ValidColumn,
|
||||
sysuser.Table: sysuser.ValidColumn,
|
||||
sysuserlog.Table: sysuserlog.ValidColumn,
|
||||
})
|
||||
})
|
||||
return columnCheck(t, c)
|
||||
|
||||
+166
-12
@@ -12,6 +12,7 @@ import (
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysagent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysconfig"
|
||||
"likedream-goframe/internal/ent/sysmenu"
|
||||
@@ -27,7 +28,7 @@ import (
|
||||
|
||||
// schemaGraph holds a representation of ent/schema at runtime.
|
||||
var schemaGraph = func() *sqlgraph.Schema {
|
||||
graph := &sqlgraph.Schema{Nodes: make([]*sqlgraph.Node, 14)}
|
||||
graph := &sqlgraph.Schema{Nodes: make([]*sqlgraph.Node, 15)}
|
||||
graph.Nodes[0] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: courseentity.Table,
|
||||
@@ -209,6 +210,27 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
},
|
||||
}
|
||||
graph.Nodes[8] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: sysbalancerecord.Table,
|
||||
Columns: sysbalancerecord.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Column: sysbalancerecord.FieldID,
|
||||
},
|
||||
},
|
||||
Type: "SysBalanceRecord",
|
||||
Fields: map[string]*sqlgraph.FieldSpec{
|
||||
sysbalancerecord.FieldCreateTime: {Type: field.TypeString, Column: sysbalancerecord.FieldCreateTime},
|
||||
sysbalancerecord.FieldUpdateTime: {Type: field.TypeString, Column: sysbalancerecord.FieldUpdateTime},
|
||||
sysbalancerecord.FieldUserID: {Type: field.TypeInt64, Column: sysbalancerecord.FieldUserID},
|
||||
sysbalancerecord.FieldType: {Type: field.TypeEnum, Column: sysbalancerecord.FieldType},
|
||||
sysbalancerecord.FieldAmount: {Type: field.TypeString, Column: sysbalancerecord.FieldAmount},
|
||||
sysbalancerecord.FieldReason: {Type: field.TypeString, Column: sysbalancerecord.FieldReason},
|
||||
sysbalancerecord.FieldBalanceBefore: {Type: field.TypeString, Column: sysbalancerecord.FieldBalanceBefore},
|
||||
sysbalancerecord.FieldBalanceAfter: {Type: field.TypeString, Column: sysbalancerecord.FieldBalanceAfter},
|
||||
},
|
||||
}
|
||||
graph.Nodes[9] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: syscard.Table,
|
||||
Columns: syscard.Columns,
|
||||
@@ -230,7 +252,7 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
syscard.FieldCashValue: {Type: field.TypeString, Column: syscard.FieldCashValue},
|
||||
},
|
||||
}
|
||||
graph.Nodes[9] = &sqlgraph.Node{
|
||||
graph.Nodes[10] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: sysconfig.Table,
|
||||
Columns: sysconfig.Columns,
|
||||
@@ -249,7 +271,7 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
sysconfig.FieldType: {Type: field.TypeString, Column: sysconfig.FieldType},
|
||||
},
|
||||
}
|
||||
graph.Nodes[10] = &sqlgraph.Node{
|
||||
graph.Nodes[11] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: sysmenu.Table,
|
||||
Columns: sysmenu.Columns,
|
||||
@@ -275,7 +297,7 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
sysmenu.FieldOrder: {Type: field.TypeUint, Column: sysmenu.FieldOrder},
|
||||
},
|
||||
}
|
||||
graph.Nodes[11] = &sqlgraph.Node{
|
||||
graph.Nodes[12] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: sysrole.Table,
|
||||
Columns: sysrole.Columns,
|
||||
@@ -294,7 +316,7 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
sysrole.FieldOrder: {Type: field.TypeUint, Column: sysrole.FieldOrder},
|
||||
},
|
||||
}
|
||||
graph.Nodes[12] = &sqlgraph.Node{
|
||||
graph.Nodes[13] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: sysuser.Table,
|
||||
Columns: sysuser.Columns,
|
||||
@@ -317,7 +339,7 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
sysuser.FieldInviteCashback: {Type: field.TypeString, Column: sysuser.FieldInviteCashback},
|
||||
},
|
||||
}
|
||||
graph.Nodes[13] = &sqlgraph.Node{
|
||||
graph.Nodes[14] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: sysuserlog.Table,
|
||||
Columns: sysuserlog.Columns,
|
||||
@@ -533,6 +555,18 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
"SysAgent",
|
||||
"SysUser",
|
||||
)
|
||||
graph.MustAddE(
|
||||
"user",
|
||||
&sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: sysbalancerecord.UserTable,
|
||||
Columns: []string{sysbalancerecord.UserColumn},
|
||||
Bidi: false,
|
||||
},
|
||||
"SysBalanceRecord",
|
||||
"SysUser",
|
||||
)
|
||||
graph.MustAddE(
|
||||
"creator",
|
||||
&sqlgraph.EdgeSpec{
|
||||
@@ -785,6 +819,18 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
"SysUser",
|
||||
"SysCard",
|
||||
)
|
||||
graph.MustAddE(
|
||||
"balance_records",
|
||||
&sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.BalanceRecordsTable,
|
||||
Columns: []string{sysuser.BalanceRecordsColumn},
|
||||
Bidi: false,
|
||||
},
|
||||
"SysUser",
|
||||
"SysBalanceRecord",
|
||||
)
|
||||
return graph
|
||||
}()
|
||||
|
||||
@@ -1732,6 +1778,100 @@ func (f *SysAgentFilter) WhereHasUsersWith(preds ...predicate.SysUser) {
|
||||
})))
|
||||
}
|
||||
|
||||
// addPredicate implements the predicateAdder interface.
|
||||
func (_q *SysBalanceRecordQuery) addPredicate(pred func(s *sql.Selector)) {
|
||||
_q.predicates = append(_q.predicates, pred)
|
||||
}
|
||||
|
||||
// Filter returns a Filter implementation to apply filters on the SysBalanceRecordQuery builder.
|
||||
func (_q *SysBalanceRecordQuery) Filter() *SysBalanceRecordFilter {
|
||||
return &SysBalanceRecordFilter{config: _q.config, predicateAdder: _q}
|
||||
}
|
||||
|
||||
// addPredicate implements the predicateAdder interface.
|
||||
func (m *SysBalanceRecordMutation) addPredicate(pred func(s *sql.Selector)) {
|
||||
m.predicates = append(m.predicates, pred)
|
||||
}
|
||||
|
||||
// Filter returns an entql.Where implementation to apply filters on the SysBalanceRecordMutation builder.
|
||||
func (m *SysBalanceRecordMutation) Filter() *SysBalanceRecordFilter {
|
||||
return &SysBalanceRecordFilter{config: m.config, predicateAdder: m}
|
||||
}
|
||||
|
||||
// SysBalanceRecordFilter provides a generic filtering capability at runtime for SysBalanceRecordQuery.
|
||||
type SysBalanceRecordFilter struct {
|
||||
predicateAdder
|
||||
config
|
||||
}
|
||||
|
||||
// Where applies the entql predicate on the query filter.
|
||||
func (f *SysBalanceRecordFilter) Where(p entql.P) {
|
||||
f.addPredicate(func(s *sql.Selector) {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[8].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// WhereID applies the entql int64 predicate on the id field.
|
||||
func (f *SysBalanceRecordFilter) WhereID(p entql.Int64P) {
|
||||
f.Where(p.Field(sysbalancerecord.FieldID))
|
||||
}
|
||||
|
||||
// WhereCreateTime applies the entql string predicate on the create_time field.
|
||||
func (f *SysBalanceRecordFilter) WhereCreateTime(p entql.StringP) {
|
||||
f.Where(p.Field(sysbalancerecord.FieldCreateTime))
|
||||
}
|
||||
|
||||
// WhereUpdateTime applies the entql string predicate on the update_time field.
|
||||
func (f *SysBalanceRecordFilter) WhereUpdateTime(p entql.StringP) {
|
||||
f.Where(p.Field(sysbalancerecord.FieldUpdateTime))
|
||||
}
|
||||
|
||||
// WhereUserID applies the entql int64 predicate on the user_id field.
|
||||
func (f *SysBalanceRecordFilter) WhereUserID(p entql.Int64P) {
|
||||
f.Where(p.Field(sysbalancerecord.FieldUserID))
|
||||
}
|
||||
|
||||
// WhereType applies the entql string predicate on the type field.
|
||||
func (f *SysBalanceRecordFilter) WhereType(p entql.StringP) {
|
||||
f.Where(p.Field(sysbalancerecord.FieldType))
|
||||
}
|
||||
|
||||
// WhereAmount applies the entql string predicate on the amount field.
|
||||
func (f *SysBalanceRecordFilter) WhereAmount(p entql.StringP) {
|
||||
f.Where(p.Field(sysbalancerecord.FieldAmount))
|
||||
}
|
||||
|
||||
// WhereReason applies the entql string predicate on the reason field.
|
||||
func (f *SysBalanceRecordFilter) WhereReason(p entql.StringP) {
|
||||
f.Where(p.Field(sysbalancerecord.FieldReason))
|
||||
}
|
||||
|
||||
// WhereBalanceBefore applies the entql string predicate on the balance_before field.
|
||||
func (f *SysBalanceRecordFilter) WhereBalanceBefore(p entql.StringP) {
|
||||
f.Where(p.Field(sysbalancerecord.FieldBalanceBefore))
|
||||
}
|
||||
|
||||
// WhereBalanceAfter applies the entql string predicate on the balance_after field.
|
||||
func (f *SysBalanceRecordFilter) WhereBalanceAfter(p entql.StringP) {
|
||||
f.Where(p.Field(sysbalancerecord.FieldBalanceAfter))
|
||||
}
|
||||
|
||||
// WhereHasUser applies a predicate to check if query has an edge user.
|
||||
func (f *SysBalanceRecordFilter) WhereHasUser() {
|
||||
f.Where(entql.HasEdge("user"))
|
||||
}
|
||||
|
||||
// WhereHasUserWith applies a predicate to check if query has an edge user with a given conditions (other predicates).
|
||||
func (f *SysBalanceRecordFilter) WhereHasUserWith(preds ...predicate.SysUser) {
|
||||
f.Where(entql.HasEdgeWith("user", sqlgraph.WrapFunc(func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})))
|
||||
}
|
||||
|
||||
// addPredicate implements the predicateAdder interface.
|
||||
func (_q *SysCardQuery) addPredicate(pred func(s *sql.Selector)) {
|
||||
_q.predicates = append(_q.predicates, pred)
|
||||
@@ -1761,7 +1901,7 @@ type SysCardFilter struct {
|
||||
// Where applies the entql predicate on the query filter.
|
||||
func (f *SysCardFilter) Where(p entql.P) {
|
||||
f.addPredicate(func(s *sql.Selector) {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[8].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[9].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -1888,7 +2028,7 @@ type SysConfigFilter struct {
|
||||
// Where applies the entql predicate on the query filter.
|
||||
func (f *SysConfigFilter) Where(p entql.P) {
|
||||
f.addPredicate(func(s *sql.Selector) {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[9].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[10].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -1958,7 +2098,7 @@ type SysMenuFilter struct {
|
||||
// Where applies the entql predicate on the query filter.
|
||||
func (f *SysMenuFilter) Where(p entql.P) {
|
||||
f.addPredicate(func(s *sql.Selector) {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[10].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[11].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -2105,7 +2245,7 @@ type SysRoleFilter struct {
|
||||
// Where applies the entql predicate on the query filter.
|
||||
func (f *SysRoleFilter) Where(p entql.P) {
|
||||
f.addPredicate(func(s *sql.Selector) {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[11].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[12].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -2203,7 +2343,7 @@ type SysUserFilter struct {
|
||||
// Where applies the entql predicate on the query filter.
|
||||
func (f *SysUserFilter) Where(p entql.P) {
|
||||
f.addPredicate(func(s *sql.Selector) {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[12].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[13].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -2446,6 +2586,20 @@ func (f *SysUserFilter) WhereHasCashbackCardsWith(preds ...predicate.SysCard) {
|
||||
})))
|
||||
}
|
||||
|
||||
// WhereHasBalanceRecords applies a predicate to check if query has an edge balance_records.
|
||||
func (f *SysUserFilter) WhereHasBalanceRecords() {
|
||||
f.Where(entql.HasEdge("balance_records"))
|
||||
}
|
||||
|
||||
// WhereHasBalanceRecordsWith applies a predicate to check if query has an edge balance_records with a given conditions (other predicates).
|
||||
func (f *SysUserFilter) WhereHasBalanceRecordsWith(preds ...predicate.SysBalanceRecord) {
|
||||
f.Where(entql.HasEdgeWith("balance_records", sqlgraph.WrapFunc(func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})))
|
||||
}
|
||||
|
||||
// addPredicate implements the predicateAdder interface.
|
||||
func (_q *SysUserLogQuery) addPredicate(pred func(s *sql.Selector)) {
|
||||
_q.predicates = append(_q.predicates, pred)
|
||||
@@ -2475,7 +2629,7 @@ type SysUserLogFilter struct {
|
||||
// Where applies the entql predicate on the query filter.
|
||||
func (f *SysUserLogFilter) Where(p entql.P) {
|
||||
f.addPredicate(func(s *sql.Selector) {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[13].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[14].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -104,6 +104,18 @@ func (f SysAgentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, er
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SysAgentMutation", m)
|
||||
}
|
||||
|
||||
// The SysBalanceRecordFunc type is an adapter to allow the use of ordinary
|
||||
// function as SysBalanceRecord mutator.
|
||||
type SysBalanceRecordFunc func(context.Context, *ent.SysBalanceRecordMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f SysBalanceRecordFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.SysBalanceRecordMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SysBalanceRecordMutation", m)
|
||||
}
|
||||
|
||||
// The SysCardFunc type is an adapter to allow the use of ordinary
|
||||
// function as SysCard mutator.
|
||||
type SysCardFunc func(context.Context, *ent.SysCardMutation) (ent.Value, error)
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysagent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysconfig"
|
||||
"likedream-goframe/internal/ent/sysmenu"
|
||||
@@ -298,6 +299,33 @@ func (f TraverseSysAgent) Traverse(ctx context.Context, q ent.Query) error {
|
||||
return fmt.Errorf("unexpected query type %T. expect *ent.SysAgentQuery", q)
|
||||
}
|
||||
|
||||
// The SysBalanceRecordFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||
type SysBalanceRecordFunc func(context.Context, *ent.SysBalanceRecordQuery) (ent.Value, error)
|
||||
|
||||
// Query calls f(ctx, q).
|
||||
func (f SysBalanceRecordFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
|
||||
if q, ok := q.(*ent.SysBalanceRecordQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected query type %T. expect *ent.SysBalanceRecordQuery", q)
|
||||
}
|
||||
|
||||
// The TraverseSysBalanceRecord type is an adapter to allow the use of ordinary function as Traverser.
|
||||
type TraverseSysBalanceRecord func(context.Context, *ent.SysBalanceRecordQuery) error
|
||||
|
||||
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
|
||||
func (f TraverseSysBalanceRecord) Intercept(next ent.Querier) ent.Querier {
|
||||
return next
|
||||
}
|
||||
|
||||
// Traverse calls f(ctx, q).
|
||||
func (f TraverseSysBalanceRecord) Traverse(ctx context.Context, q ent.Query) error {
|
||||
if q, ok := q.(*ent.SysBalanceRecordQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return fmt.Errorf("unexpected query type %T. expect *ent.SysBalanceRecordQuery", q)
|
||||
}
|
||||
|
||||
// The SysCardFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||
type SysCardFunc func(context.Context, *ent.SysCardQuery) (ent.Value, error)
|
||||
|
||||
@@ -479,6 +507,8 @@ func NewQuery(q ent.Query) (Query, error) {
|
||||
return &query[*ent.CpUserQuery, predicate.CpUser, cpuser.OrderOption]{typ: ent.TypeCpUser, tq: q}, nil
|
||||
case *ent.SysAgentQuery:
|
||||
return &query[*ent.SysAgentQuery, predicate.SysAgent, sysagent.OrderOption]{typ: ent.TypeSysAgent, tq: q}, nil
|
||||
case *ent.SysBalanceRecordQuery:
|
||||
return &query[*ent.SysBalanceRecordQuery, predicate.SysBalanceRecord, sysbalancerecord.OrderOption]{typ: ent.TypeSysBalanceRecord, tq: q}, nil
|
||||
case *ent.SysCardQuery:
|
||||
return &query[*ent.SysCardQuery, predicate.SysCard, syscard.OrderOption]{typ: ent.TypeSysCard, tq: q}, nil
|
||||
case *ent.SysConfigQuery:
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -7,22 +7,23 @@ import "context"
|
||||
// SchemaConfig represents alternative schema names for all tables
|
||||
// that can be passed at runtime.
|
||||
type SchemaConfig struct {
|
||||
CourseEntity string // CourseEntity table.
|
||||
CpImage string // CpImage table.
|
||||
CpLeave string // CpLeave table.
|
||||
CpSchool string // CpSchool table.
|
||||
CpTask string // CpTask table.
|
||||
CpTaskLog string // CpTaskLog table.
|
||||
CpUser string // CpUser table.
|
||||
SysAgent string // SysAgent table.
|
||||
SysCard string // SysCard table.
|
||||
SysConfig string // SysConfig table.
|
||||
SysMenu string // SysMenu table.
|
||||
SysRole string // SysRole table.
|
||||
SysRoleMenus string // SysRole-menus->SysMenu table.
|
||||
SysUser string // SysUser table.
|
||||
SysUserRoles string // SysUser-roles->SysRole table.
|
||||
SysUserLog string // SysUserLog table.
|
||||
CourseEntity string // CourseEntity table.
|
||||
CpImage string // CpImage table.
|
||||
CpLeave string // CpLeave table.
|
||||
CpSchool string // CpSchool table.
|
||||
CpTask string // CpTask table.
|
||||
CpTaskLog string // CpTaskLog table.
|
||||
CpUser string // CpUser table.
|
||||
SysAgent string // SysAgent table.
|
||||
SysBalanceRecord string // SysBalanceRecord table.
|
||||
SysCard string // SysCard table.
|
||||
SysConfig string // SysConfig table.
|
||||
SysMenu string // SysMenu table.
|
||||
SysRole string // SysRole table.
|
||||
SysRoleMenus string // SysRole-menus->SysMenu table.
|
||||
SysUser string // SysUser table.
|
||||
SysUserRoles string // SysUser-roles->SysRole table.
|
||||
SysUserLog string // SysUserLog table.
|
||||
}
|
||||
|
||||
type schemaCtxKey struct{}
|
||||
|
||||
@@ -252,6 +252,32 @@ var (
|
||||
},
|
||||
},
|
||||
}
|
||||
// SysBalanceRecordColumns holds the columns for the "sys_balance_record" table.
|
||||
SysBalanceRecordColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "create_time", Type: field.TypeString, SchemaType: map[string]string{"mysql": "datetime", "postgres": "timestamp", "sqlite3": "datetime"}},
|
||||
{Name: "update_time", Type: field.TypeString, SchemaType: map[string]string{"mysql": "datetime", "postgres": "timestamp", "sqlite3": "datetime"}},
|
||||
{Name: "type", Type: field.TypeEnum, Enums: []string{"increase", "decrease"}},
|
||||
{Name: "amount", Type: field.TypeString, SchemaType: map[string]string{"mysql": "decimal(10,2)", "postgres": "numeric(10,2)"}},
|
||||
{Name: "reason", Type: field.TypeString},
|
||||
{Name: "balance_before", Type: field.TypeString, SchemaType: map[string]string{"mysql": "decimal(10,2)", "postgres": "numeric(10,2)"}},
|
||||
{Name: "balance_after", Type: field.TypeString, SchemaType: map[string]string{"mysql": "decimal(10,2)", "postgres": "numeric(10,2)"}},
|
||||
{Name: "user_id", Type: field.TypeInt64},
|
||||
}
|
||||
// SysBalanceRecordTable holds the schema information for the "sys_balance_record" table.
|
||||
SysBalanceRecordTable = &schema.Table{
|
||||
Name: "sys_balance_record",
|
||||
Columns: SysBalanceRecordColumns,
|
||||
PrimaryKey: []*schema.Column{SysBalanceRecordColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "sys_balance_record_sys_user_balance_records",
|
||||
Columns: []*schema.Column{SysBalanceRecordColumns[8]},
|
||||
RefColumns: []*schema.Column{SysUserColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
},
|
||||
}
|
||||
// SysCardColumns holds the columns for the "sys_card" table.
|
||||
SysCardColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
@@ -454,6 +480,7 @@ var (
|
||||
CpTaskLogsTable,
|
||||
CpUsersTable,
|
||||
SysAgentTable,
|
||||
SysBalanceRecordTable,
|
||||
SysCardTable,
|
||||
SysConfigTable,
|
||||
SysMenuTable,
|
||||
@@ -487,6 +514,10 @@ func init() {
|
||||
SysAgentTable.Annotation = &entsql.Annotation{
|
||||
Table: "sys_agent",
|
||||
}
|
||||
SysBalanceRecordTable.ForeignKeys[0].RefTable = SysUserTable
|
||||
SysBalanceRecordTable.Annotation = &entsql.Annotation{
|
||||
Table: "sys_balance_record",
|
||||
}
|
||||
SysCardTable.ForeignKeys[0].RefTable = SysUserTable
|
||||
SysCardTable.ForeignKeys[1].RefTable = SysUserTable
|
||||
SysCardTable.ForeignKeys[2].RefTable = SysUserTable
|
||||
|
||||
+917
-71
File diff suppressed because it is too large
Load Diff
@@ -30,6 +30,9 @@ type CpUser func(*sql.Selector)
|
||||
// SysAgent is the predicate function for sysagent builders.
|
||||
type SysAgent func(*sql.Selector)
|
||||
|
||||
// SysBalanceRecord is the predicate function for sysbalancerecord builders.
|
||||
type SysBalanceRecord func(*sql.Selector)
|
||||
|
||||
// SysCard is the predicate function for syscard builders.
|
||||
type SysCard func(*sql.Selector)
|
||||
|
||||
|
||||
@@ -303,6 +303,30 @@ func (f SysAgentMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutati
|
||||
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.SysAgentMutation", m)
|
||||
}
|
||||
|
||||
// The SysBalanceRecordQueryRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a query rule.
|
||||
type SysBalanceRecordQueryRuleFunc func(context.Context, *ent.SysBalanceRecordQuery) error
|
||||
|
||||
// EvalQuery return f(ctx, q).
|
||||
func (f SysBalanceRecordQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||
if q, ok := q.(*ent.SysBalanceRecordQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected query type %T, expect *ent.SysBalanceRecordQuery", q)
|
||||
}
|
||||
|
||||
// The SysBalanceRecordMutationRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a mutation rule.
|
||||
type SysBalanceRecordMutationRuleFunc func(context.Context, *ent.SysBalanceRecordMutation) error
|
||||
|
||||
// EvalMutation calls f(ctx, m).
|
||||
func (f SysBalanceRecordMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||
if m, ok := m.(*ent.SysBalanceRecordMutation); ok {
|
||||
return f(ctx, m)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.SysBalanceRecordMutation", m)
|
||||
}
|
||||
|
||||
// The SysCardQueryRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a query rule.
|
||||
type SysCardQueryRuleFunc func(context.Context, *ent.SysCardQuery) error
|
||||
@@ -498,6 +522,8 @@ func queryFilter(q ent.Query) (Filter, error) {
|
||||
return q.Filter(), nil
|
||||
case *ent.SysAgentQuery:
|
||||
return q.Filter(), nil
|
||||
case *ent.SysBalanceRecordQuery:
|
||||
return q.Filter(), nil
|
||||
case *ent.SysCardQuery:
|
||||
return q.Filter(), nil
|
||||
case *ent.SysConfigQuery:
|
||||
@@ -533,6 +559,8 @@ func mutationFilter(m ent.Mutation) (Filter, error) {
|
||||
return m.Filter(), nil
|
||||
case *ent.SysAgentMutation:
|
||||
return m.Filter(), nil
|
||||
case *ent.SysBalanceRecordMutation:
|
||||
return m.Filter(), nil
|
||||
case *ent.SysCardMutation:
|
||||
return m.Filter(), nil
|
||||
case *ent.SysConfigMutation:
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/ent/schema"
|
||||
"likedream-goframe/internal/ent/sysagent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysconfig"
|
||||
"likedream-goframe/internal/ent/sysmenu"
|
||||
@@ -207,6 +208,21 @@ func init() {
|
||||
sysagentDescUpdateTime := sysagentMixinFields0[1].Descriptor()
|
||||
// sysagent.DefaultUpdateTime holds the default value on creation for the update_time field.
|
||||
sysagent.DefaultUpdateTime = sysagentDescUpdateTime.Default.(func() *ent2.CustomTime)
|
||||
sysbalancerecordMixin := schema.SysBalanceRecord{}.Mixin()
|
||||
sysbalancerecordMixinHooks0 := sysbalancerecordMixin[0].Hooks()
|
||||
sysbalancerecord.Hooks[0] = sysbalancerecordMixinHooks0[0]
|
||||
sysbalancerecordMixinFields0 := sysbalancerecordMixin[0].Fields()
|
||||
_ = sysbalancerecordMixinFields0
|
||||
sysbalancerecordFields := schema.SysBalanceRecord{}.Fields()
|
||||
_ = sysbalancerecordFields
|
||||
// sysbalancerecordDescCreateTime is the schema descriptor for create_time field.
|
||||
sysbalancerecordDescCreateTime := sysbalancerecordMixinFields0[0].Descriptor()
|
||||
// sysbalancerecord.DefaultCreateTime holds the default value on creation for the create_time field.
|
||||
sysbalancerecord.DefaultCreateTime = sysbalancerecordDescCreateTime.Default.(func() *ent2.CustomTime)
|
||||
// sysbalancerecordDescUpdateTime is the schema descriptor for update_time field.
|
||||
sysbalancerecordDescUpdateTime := sysbalancerecordMixinFields0[1].Descriptor()
|
||||
// sysbalancerecord.DefaultUpdateTime holds the default value on creation for the update_time field.
|
||||
sysbalancerecord.DefaultUpdateTime = sysbalancerecordDescUpdateTime.Default.(func() *ent2.CustomTime)
|
||||
syscardMixin := schema.SysCard{}.Mixin()
|
||||
syscardMixinHooks0 := syscardMixin[0].Hooks()
|
||||
syscard.Hooks[0] = syscardMixinHooks0[0]
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"likedream-goframe/internal/ent/schema/mix"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// SysBalanceRecord holds the schema definition for the SysBalanceRecord entity.
|
||||
type SysBalanceRecord struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the SysBalanceRecord.
|
||||
func (SysBalanceRecord) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int64("user_id").Comment("用户ID"),
|
||||
field.Enum("type").Values("increase", "decrease").Comment("变动类型:increase增加,decrease减少"),
|
||||
field.String("amount").GoType(decimal.Decimal{}).SchemaType(map[string]string{
|
||||
dialect.MySQL: "decimal(10,2)",
|
||||
dialect.Postgres: "numeric(10,2)",
|
||||
}).Comment("变动金额"),
|
||||
field.String("reason").Comment("变动原因"),
|
||||
field.String("balance_before").GoType(decimal.Decimal{}).SchemaType(map[string]string{
|
||||
dialect.MySQL: "decimal(10,2)",
|
||||
dialect.Postgres: "numeric(10,2)",
|
||||
}).Comment("变动前余额"),
|
||||
field.String("balance_after").GoType(decimal.Decimal{}).SchemaType(map[string]string{
|
||||
dialect.MySQL: "decimal(10,2)",
|
||||
dialect.Postgres: "numeric(10,2)",
|
||||
}).Comment("变动后余额"),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the SysBalanceRecord.
|
||||
func (SysBalanceRecord) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("user", SysUser.Type).
|
||||
Ref("balance_records").
|
||||
Field("user_id").
|
||||
Unique().
|
||||
Required(),
|
||||
}
|
||||
}
|
||||
|
||||
func (SysBalanceRecord) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
entsql.Annotation{Table: "sys_balance_record"},
|
||||
}
|
||||
}
|
||||
|
||||
func (SysBalanceRecord) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mix.MixinTime{},
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,7 @@ func (SysUser) Edges() []ent.Edge {
|
||||
edge.To("created_cards", SysCard.Type), // 用户创建的卡
|
||||
edge.To("used_cards", SysCard.Type), // 用户使用的卡
|
||||
edge.To("cashback_cards", SysCard.Type),
|
||||
edge.To("balance_records", SysBalanceRecord.Type).Annotations(entsql.OnDelete(entsql.Cascade)), // 用户余额变动记录
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// SysBalanceRecord is the model entity for the SysBalanceRecord schema.
|
||||
type SysBalanceRecord struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int64 `json:"id,omitempty"`
|
||||
// CreateTime holds the value of the "create_time" field.
|
||||
CreateTime *ent2.CustomTime `json:"createTime"`
|
||||
// UpdateTime holds the value of the "update_time" field.
|
||||
UpdateTime *ent2.CustomTime `json:"updateTime"`
|
||||
// 用户ID
|
||||
UserID int64 `json:"user_id,omitempty"`
|
||||
// 变动类型:increase增加,decrease减少
|
||||
Type sysbalancerecord.Type `json:"type,omitempty"`
|
||||
// 变动金额
|
||||
Amount decimal.Decimal `json:"amount,omitempty"`
|
||||
// 变动原因
|
||||
Reason string `json:"reason,omitempty"`
|
||||
// 变动前余额
|
||||
BalanceBefore decimal.Decimal `json:"balance_before,omitempty"`
|
||||
// 变动后余额
|
||||
BalanceAfter decimal.Decimal `json:"balance_after,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the SysBalanceRecordQuery when eager-loading is set.
|
||||
Edges SysBalanceRecordEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// SysBalanceRecordEdges holds the relations/edges for other nodes in the graph.
|
||||
type SysBalanceRecordEdges struct {
|
||||
// User holds the value of the user edge.
|
||||
User *SysUser `json:"user,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// UserOrErr returns the User value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e SysBalanceRecordEdges) UserOrErr() (*SysUser, error) {
|
||||
if e.User != nil {
|
||||
return e.User, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: sysuser.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "user"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*SysBalanceRecord) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case sysbalancerecord.FieldAmount, sysbalancerecord.FieldBalanceBefore, sysbalancerecord.FieldBalanceAfter:
|
||||
values[i] = new(decimal.Decimal)
|
||||
case sysbalancerecord.FieldCreateTime, sysbalancerecord.FieldUpdateTime:
|
||||
values[i] = new(ent2.CustomTime)
|
||||
case sysbalancerecord.FieldID, sysbalancerecord.FieldUserID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case sysbalancerecord.FieldType, sysbalancerecord.FieldReason:
|
||||
values[i] = new(sql.NullString)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the SysBalanceRecord fields.
|
||||
func (_m *SysBalanceRecord) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case sysbalancerecord.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = int64(value.Int64)
|
||||
case sysbalancerecord.FieldCreateTime:
|
||||
if value, ok := values[i].(*ent2.CustomTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field create_time", values[i])
|
||||
} else if value != nil {
|
||||
_m.CreateTime = value
|
||||
}
|
||||
case sysbalancerecord.FieldUpdateTime:
|
||||
if value, ok := values[i].(*ent2.CustomTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field update_time", values[i])
|
||||
} else if value != nil {
|
||||
_m.UpdateTime = value
|
||||
}
|
||||
case sysbalancerecord.FieldUserID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field user_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.UserID = value.Int64
|
||||
}
|
||||
case sysbalancerecord.FieldType:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field type", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Type = sysbalancerecord.Type(value.String)
|
||||
}
|
||||
case sysbalancerecord.FieldAmount:
|
||||
if value, ok := values[i].(*decimal.Decimal); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field amount", values[i])
|
||||
} else if value != nil {
|
||||
_m.Amount = *value
|
||||
}
|
||||
case sysbalancerecord.FieldReason:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field reason", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Reason = value.String
|
||||
}
|
||||
case sysbalancerecord.FieldBalanceBefore:
|
||||
if value, ok := values[i].(*decimal.Decimal); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field balance_before", values[i])
|
||||
} else if value != nil {
|
||||
_m.BalanceBefore = *value
|
||||
}
|
||||
case sysbalancerecord.FieldBalanceAfter:
|
||||
if value, ok := values[i].(*decimal.Decimal); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field balance_after", values[i])
|
||||
} else if value != nil {
|
||||
_m.BalanceAfter = *value
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the SysBalanceRecord.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *SysBalanceRecord) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryUser queries the "user" edge of the SysBalanceRecord entity.
|
||||
func (_m *SysBalanceRecord) QueryUser() *SysUserQuery {
|
||||
return NewSysBalanceRecordClient(_m.config).QueryUser(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this SysBalanceRecord.
|
||||
// Note that you need to call SysBalanceRecord.Unwrap() before calling this method if this SysBalanceRecord
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *SysBalanceRecord) Update() *SysBalanceRecordUpdateOne {
|
||||
return NewSysBalanceRecordClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the SysBalanceRecord entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (_m *SysBalanceRecord) Unwrap() *SysBalanceRecord {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: SysBalanceRecord is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *SysBalanceRecord) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("SysBalanceRecord(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("create_time=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.CreateTime))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("update_time=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.UpdateTime))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("user_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.UserID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("type=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Type))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("amount=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Amount))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("reason=")
|
||||
builder.WriteString(_m.Reason)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("balance_before=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.BalanceBefore))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("balance_after=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.BalanceAfter))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// SysBalanceRecords is a parsable slice of SysBalanceRecord.
|
||||
type SysBalanceRecords []*SysBalanceRecord
|
||||
@@ -0,0 +1,167 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package sysbalancerecord
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the sysbalancerecord type in the database.
|
||||
Label = "sys_balance_record"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldCreateTime holds the string denoting the create_time field in the database.
|
||||
FieldCreateTime = "create_time"
|
||||
// FieldUpdateTime holds the string denoting the update_time field in the database.
|
||||
FieldUpdateTime = "update_time"
|
||||
// FieldUserID holds the string denoting the user_id field in the database.
|
||||
FieldUserID = "user_id"
|
||||
// FieldType holds the string denoting the type field in the database.
|
||||
FieldType = "type"
|
||||
// FieldAmount holds the string denoting the amount field in the database.
|
||||
FieldAmount = "amount"
|
||||
// FieldReason holds the string denoting the reason field in the database.
|
||||
FieldReason = "reason"
|
||||
// FieldBalanceBefore holds the string denoting the balance_before field in the database.
|
||||
FieldBalanceBefore = "balance_before"
|
||||
// FieldBalanceAfter holds the string denoting the balance_after field in the database.
|
||||
FieldBalanceAfter = "balance_after"
|
||||
// EdgeUser holds the string denoting the user edge name in mutations.
|
||||
EdgeUser = "user"
|
||||
// Table holds the table name of the sysbalancerecord in the database.
|
||||
Table = "sys_balance_record"
|
||||
// UserTable is the table that holds the user relation/edge.
|
||||
UserTable = "sys_balance_record"
|
||||
// UserInverseTable is the table name for the SysUser entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "sysuser" package.
|
||||
UserInverseTable = "sys_user"
|
||||
// UserColumn is the table column denoting the user relation/edge.
|
||||
UserColumn = "user_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for sysbalancerecord fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldCreateTime,
|
||||
FieldUpdateTime,
|
||||
FieldUserID,
|
||||
FieldType,
|
||||
FieldAmount,
|
||||
FieldReason,
|
||||
FieldBalanceBefore,
|
||||
FieldBalanceAfter,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Note that the variables below are initialized by the runtime
|
||||
// package on the initialization of the application. Therefore,
|
||||
// it should be imported in the main as follows:
|
||||
//
|
||||
// import _ "likedream-goframe/internal/ent/runtime"
|
||||
var (
|
||||
Hooks [1]ent.Hook
|
||||
// DefaultCreateTime holds the default value on creation for the "create_time" field.
|
||||
DefaultCreateTime func() *ent2.CustomTime
|
||||
// DefaultUpdateTime holds the default value on creation for the "update_time" field.
|
||||
DefaultUpdateTime func() *ent2.CustomTime
|
||||
)
|
||||
|
||||
// Type defines the type for the "type" enum field.
|
||||
type Type string
|
||||
|
||||
// Type values.
|
||||
const (
|
||||
TypeIncrease Type = "increase"
|
||||
TypeDecrease Type = "decrease"
|
||||
)
|
||||
|
||||
func (_type Type) String() string {
|
||||
return string(_type)
|
||||
}
|
||||
|
||||
// TypeValidator is a validator for the "type" field enum values. It is called by the builders before save.
|
||||
func TypeValidator(_type Type) error {
|
||||
switch _type {
|
||||
case TypeIncrease, TypeDecrease:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("sysbalancerecord: invalid enum value for type field: %q", _type)
|
||||
}
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the SysBalanceRecord queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreateTime orders the results by the create_time field.
|
||||
func ByCreateTime(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreateTime, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdateTime orders the results by the update_time field.
|
||||
func ByUpdateTime(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdateTime, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUserID orders the results by the user_id field.
|
||||
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUserID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByType orders the results by the type field.
|
||||
func ByType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldType, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAmount orders the results by the amount field.
|
||||
func ByAmount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldAmount, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByReason orders the results by the reason field.
|
||||
func ByReason(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldReason, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByBalanceBefore orders the results by the balance_before field.
|
||||
func ByBalanceBefore(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldBalanceBefore, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByBalanceAfter orders the results by the balance_after field.
|
||||
func ByBalanceAfter(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldBalanceAfter, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUserField orders the results by user field.
|
||||
func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newUserStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(UserInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,592 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package sysbalancerecord
|
||||
|
||||
import (
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ.
|
||||
func CreateTime(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTime applies equality check predicate on the "update_time" field. It's identical to UpdateTimeEQ.
|
||||
func UpdateTime(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
|
||||
func UserID(v int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// Amount applies equality check predicate on the "amount" field. It's identical to AmountEQ.
|
||||
func Amount(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldAmount, v))
|
||||
}
|
||||
|
||||
// Reason applies equality check predicate on the "reason" field. It's identical to ReasonEQ.
|
||||
func Reason(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldReason, v))
|
||||
}
|
||||
|
||||
// BalanceBefore applies equality check predicate on the "balance_before" field. It's identical to BalanceBeforeEQ.
|
||||
func BalanceBefore(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldBalanceBefore, v))
|
||||
}
|
||||
|
||||
// BalanceAfter applies equality check predicate on the "balance_after" field. It's identical to BalanceAfterEQ.
|
||||
func BalanceAfter(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldBalanceAfter, v))
|
||||
}
|
||||
|
||||
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||
func CreateTimeEQ(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||
func CreateTimeNEQ(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||
func CreateTimeIn(vs ...*ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||
func CreateTimeNotIn(vs ...*ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNotIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||
func CreateTimeGT(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||
func CreateTimeGTE(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||
func CreateTimeLT(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||
func CreateTimeLTE(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeContains applies the Contains predicate on the "create_time" field.
|
||||
func CreateTimeContains(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContains(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeHasPrefix applies the HasPrefix predicate on the "create_time" field.
|
||||
func CreateTimeHasPrefix(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasPrefix(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeHasSuffix applies the HasSuffix predicate on the "create_time" field.
|
||||
func CreateTimeHasSuffix(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasSuffix(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeEqualFold applies the EqualFold predicate on the "create_time" field.
|
||||
func CreateTimeEqualFold(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldEqualFold(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeContainsFold applies the ContainsFold predicate on the "create_time" field.
|
||||
func CreateTimeContainsFold(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContainsFold(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeEQ applies the EQ predicate on the "update_time" field.
|
||||
func UpdateTimeEQ(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeNEQ applies the NEQ predicate on the "update_time" field.
|
||||
func UpdateTimeNEQ(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeIn applies the In predicate on the "update_time" field.
|
||||
func UpdateTimeIn(vs ...*ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldIn(FieldUpdateTime, vs...))
|
||||
}
|
||||
|
||||
// UpdateTimeNotIn applies the NotIn predicate on the "update_time" field.
|
||||
func UpdateTimeNotIn(vs ...*ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNotIn(FieldUpdateTime, vs...))
|
||||
}
|
||||
|
||||
// UpdateTimeGT applies the GT predicate on the "update_time" field.
|
||||
func UpdateTimeGT(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGT(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeGTE applies the GTE predicate on the "update_time" field.
|
||||
func UpdateTimeGTE(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGTE(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeLT applies the LT predicate on the "update_time" field.
|
||||
func UpdateTimeLT(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLT(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeLTE applies the LTE predicate on the "update_time" field.
|
||||
func UpdateTimeLTE(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLTE(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeContains applies the Contains predicate on the "update_time" field.
|
||||
func UpdateTimeContains(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContains(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeHasPrefix applies the HasPrefix predicate on the "update_time" field.
|
||||
func UpdateTimeHasPrefix(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasPrefix(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeHasSuffix applies the HasSuffix predicate on the "update_time" field.
|
||||
func UpdateTimeHasSuffix(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasSuffix(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeEqualFold applies the EqualFold predicate on the "update_time" field.
|
||||
func UpdateTimeEqualFold(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldEqualFold(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeContainsFold applies the ContainsFold predicate on the "update_time" field.
|
||||
func UpdateTimeContainsFold(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContainsFold(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UserIDEQ applies the EQ predicate on the "user_id" field.
|
||||
func UserIDEQ(v int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
|
||||
func UserIDNEQ(v int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDIn applies the In predicate on the "user_id" field.
|
||||
func UserIDIn(vs ...int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
|
||||
func UserIDNotIn(vs ...int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNotIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// TypeEQ applies the EQ predicate on the "type" field.
|
||||
func TypeEQ(v Type) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeNEQ applies the NEQ predicate on the "type" field.
|
||||
func TypeNEQ(v Type) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeIn applies the In predicate on the "type" field.
|
||||
func TypeIn(vs ...Type) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// TypeNotIn applies the NotIn predicate on the "type" field.
|
||||
func TypeNotIn(vs ...Type) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNotIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// AmountEQ applies the EQ predicate on the "amount" field.
|
||||
func AmountEQ(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldAmount, v))
|
||||
}
|
||||
|
||||
// AmountNEQ applies the NEQ predicate on the "amount" field.
|
||||
func AmountNEQ(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNEQ(FieldAmount, v))
|
||||
}
|
||||
|
||||
// AmountIn applies the In predicate on the "amount" field.
|
||||
func AmountIn(vs ...decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldIn(FieldAmount, vs...))
|
||||
}
|
||||
|
||||
// AmountNotIn applies the NotIn predicate on the "amount" field.
|
||||
func AmountNotIn(vs ...decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNotIn(FieldAmount, vs...))
|
||||
}
|
||||
|
||||
// AmountGT applies the GT predicate on the "amount" field.
|
||||
func AmountGT(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGT(FieldAmount, v))
|
||||
}
|
||||
|
||||
// AmountGTE applies the GTE predicate on the "amount" field.
|
||||
func AmountGTE(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGTE(FieldAmount, v))
|
||||
}
|
||||
|
||||
// AmountLT applies the LT predicate on the "amount" field.
|
||||
func AmountLT(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLT(FieldAmount, v))
|
||||
}
|
||||
|
||||
// AmountLTE applies the LTE predicate on the "amount" field.
|
||||
func AmountLTE(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLTE(FieldAmount, v))
|
||||
}
|
||||
|
||||
// AmountContains applies the Contains predicate on the "amount" field.
|
||||
func AmountContains(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContains(FieldAmount, vc))
|
||||
}
|
||||
|
||||
// AmountHasPrefix applies the HasPrefix predicate on the "amount" field.
|
||||
func AmountHasPrefix(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasPrefix(FieldAmount, vc))
|
||||
}
|
||||
|
||||
// AmountHasSuffix applies the HasSuffix predicate on the "amount" field.
|
||||
func AmountHasSuffix(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasSuffix(FieldAmount, vc))
|
||||
}
|
||||
|
||||
// AmountEqualFold applies the EqualFold predicate on the "amount" field.
|
||||
func AmountEqualFold(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldEqualFold(FieldAmount, vc))
|
||||
}
|
||||
|
||||
// AmountContainsFold applies the ContainsFold predicate on the "amount" field.
|
||||
func AmountContainsFold(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContainsFold(FieldAmount, vc))
|
||||
}
|
||||
|
||||
// ReasonEQ applies the EQ predicate on the "reason" field.
|
||||
func ReasonEQ(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonNEQ applies the NEQ predicate on the "reason" field.
|
||||
func ReasonNEQ(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNEQ(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonIn applies the In predicate on the "reason" field.
|
||||
func ReasonIn(vs ...string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldIn(FieldReason, vs...))
|
||||
}
|
||||
|
||||
// ReasonNotIn applies the NotIn predicate on the "reason" field.
|
||||
func ReasonNotIn(vs ...string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNotIn(FieldReason, vs...))
|
||||
}
|
||||
|
||||
// ReasonGT applies the GT predicate on the "reason" field.
|
||||
func ReasonGT(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGT(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonGTE applies the GTE predicate on the "reason" field.
|
||||
func ReasonGTE(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGTE(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonLT applies the LT predicate on the "reason" field.
|
||||
func ReasonLT(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLT(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonLTE applies the LTE predicate on the "reason" field.
|
||||
func ReasonLTE(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLTE(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonContains applies the Contains predicate on the "reason" field.
|
||||
func ReasonContains(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldContains(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonHasPrefix applies the HasPrefix predicate on the "reason" field.
|
||||
func ReasonHasPrefix(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldHasPrefix(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonHasSuffix applies the HasSuffix predicate on the "reason" field.
|
||||
func ReasonHasSuffix(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldHasSuffix(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonEqualFold applies the EqualFold predicate on the "reason" field.
|
||||
func ReasonEqualFold(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEqualFold(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonContainsFold applies the ContainsFold predicate on the "reason" field.
|
||||
func ReasonContainsFold(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldContainsFold(FieldReason, v))
|
||||
}
|
||||
|
||||
// BalanceBeforeEQ applies the EQ predicate on the "balance_before" field.
|
||||
func BalanceBeforeEQ(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldBalanceBefore, v))
|
||||
}
|
||||
|
||||
// BalanceBeforeNEQ applies the NEQ predicate on the "balance_before" field.
|
||||
func BalanceBeforeNEQ(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNEQ(FieldBalanceBefore, v))
|
||||
}
|
||||
|
||||
// BalanceBeforeIn applies the In predicate on the "balance_before" field.
|
||||
func BalanceBeforeIn(vs ...decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldIn(FieldBalanceBefore, vs...))
|
||||
}
|
||||
|
||||
// BalanceBeforeNotIn applies the NotIn predicate on the "balance_before" field.
|
||||
func BalanceBeforeNotIn(vs ...decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNotIn(FieldBalanceBefore, vs...))
|
||||
}
|
||||
|
||||
// BalanceBeforeGT applies the GT predicate on the "balance_before" field.
|
||||
func BalanceBeforeGT(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGT(FieldBalanceBefore, v))
|
||||
}
|
||||
|
||||
// BalanceBeforeGTE applies the GTE predicate on the "balance_before" field.
|
||||
func BalanceBeforeGTE(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGTE(FieldBalanceBefore, v))
|
||||
}
|
||||
|
||||
// BalanceBeforeLT applies the LT predicate on the "balance_before" field.
|
||||
func BalanceBeforeLT(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLT(FieldBalanceBefore, v))
|
||||
}
|
||||
|
||||
// BalanceBeforeLTE applies the LTE predicate on the "balance_before" field.
|
||||
func BalanceBeforeLTE(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLTE(FieldBalanceBefore, v))
|
||||
}
|
||||
|
||||
// BalanceBeforeContains applies the Contains predicate on the "balance_before" field.
|
||||
func BalanceBeforeContains(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContains(FieldBalanceBefore, vc))
|
||||
}
|
||||
|
||||
// BalanceBeforeHasPrefix applies the HasPrefix predicate on the "balance_before" field.
|
||||
func BalanceBeforeHasPrefix(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasPrefix(FieldBalanceBefore, vc))
|
||||
}
|
||||
|
||||
// BalanceBeforeHasSuffix applies the HasSuffix predicate on the "balance_before" field.
|
||||
func BalanceBeforeHasSuffix(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasSuffix(FieldBalanceBefore, vc))
|
||||
}
|
||||
|
||||
// BalanceBeforeEqualFold applies the EqualFold predicate on the "balance_before" field.
|
||||
func BalanceBeforeEqualFold(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldEqualFold(FieldBalanceBefore, vc))
|
||||
}
|
||||
|
||||
// BalanceBeforeContainsFold applies the ContainsFold predicate on the "balance_before" field.
|
||||
func BalanceBeforeContainsFold(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContainsFold(FieldBalanceBefore, vc))
|
||||
}
|
||||
|
||||
// BalanceAfterEQ applies the EQ predicate on the "balance_after" field.
|
||||
func BalanceAfterEQ(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldBalanceAfter, v))
|
||||
}
|
||||
|
||||
// BalanceAfterNEQ applies the NEQ predicate on the "balance_after" field.
|
||||
func BalanceAfterNEQ(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNEQ(FieldBalanceAfter, v))
|
||||
}
|
||||
|
||||
// BalanceAfterIn applies the In predicate on the "balance_after" field.
|
||||
func BalanceAfterIn(vs ...decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldIn(FieldBalanceAfter, vs...))
|
||||
}
|
||||
|
||||
// BalanceAfterNotIn applies the NotIn predicate on the "balance_after" field.
|
||||
func BalanceAfterNotIn(vs ...decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNotIn(FieldBalanceAfter, vs...))
|
||||
}
|
||||
|
||||
// BalanceAfterGT applies the GT predicate on the "balance_after" field.
|
||||
func BalanceAfterGT(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGT(FieldBalanceAfter, v))
|
||||
}
|
||||
|
||||
// BalanceAfterGTE applies the GTE predicate on the "balance_after" field.
|
||||
func BalanceAfterGTE(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGTE(FieldBalanceAfter, v))
|
||||
}
|
||||
|
||||
// BalanceAfterLT applies the LT predicate on the "balance_after" field.
|
||||
func BalanceAfterLT(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLT(FieldBalanceAfter, v))
|
||||
}
|
||||
|
||||
// BalanceAfterLTE applies the LTE predicate on the "balance_after" field.
|
||||
func BalanceAfterLTE(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLTE(FieldBalanceAfter, v))
|
||||
}
|
||||
|
||||
// BalanceAfterContains applies the Contains predicate on the "balance_after" field.
|
||||
func BalanceAfterContains(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContains(FieldBalanceAfter, vc))
|
||||
}
|
||||
|
||||
// BalanceAfterHasPrefix applies the HasPrefix predicate on the "balance_after" field.
|
||||
func BalanceAfterHasPrefix(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasPrefix(FieldBalanceAfter, vc))
|
||||
}
|
||||
|
||||
// BalanceAfterHasSuffix applies the HasSuffix predicate on the "balance_after" field.
|
||||
func BalanceAfterHasSuffix(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasSuffix(FieldBalanceAfter, vc))
|
||||
}
|
||||
|
||||
// BalanceAfterEqualFold applies the EqualFold predicate on the "balance_after" field.
|
||||
func BalanceAfterEqualFold(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldEqualFold(FieldBalanceAfter, vc))
|
||||
}
|
||||
|
||||
// BalanceAfterContainsFold applies the ContainsFold predicate on the "balance_after" field.
|
||||
func BalanceAfterContainsFold(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContainsFold(FieldBalanceAfter, vc))
|
||||
}
|
||||
|
||||
// HasUser applies the HasEdge predicate on the "user" edge.
|
||||
func HasUser() predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||
)
|
||||
schemaConfig := internal.SchemaConfigFromContext(s.Context())
|
||||
step.To.Schema = schemaConfig.SysUser
|
||||
step.Edge.Schema = schemaConfig.SysBalanceRecord
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates).
|
||||
func HasUserWith(preds ...predicate.SysUser) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(func(s *sql.Selector) {
|
||||
step := newUserStep()
|
||||
schemaConfig := internal.SchemaConfigFromContext(s.Context())
|
||||
step.To.Schema = schemaConfig.SysUser
|
||||
step.Edge.Schema = schemaConfig.SysBalanceRecord
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.SysBalanceRecord) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.SysBalanceRecord) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.SysBalanceRecord) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.NotPredicates(p))
|
||||
}
|
||||
@@ -0,0 +1,851 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// SysBalanceRecordCreate is the builder for creating a SysBalanceRecord entity.
|
||||
type SysBalanceRecordCreate struct {
|
||||
config
|
||||
mutation *SysBalanceRecordMutation
|
||||
hooks []Hook
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// SetCreateTime sets the "create_time" field.
|
||||
func (_c *SysBalanceRecordCreate) SetCreateTime(v *ent2.CustomTime) *SysBalanceRecordCreate {
|
||||
_c.mutation.SetCreateTime(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (_c *SysBalanceRecordCreate) SetUpdateTime(v *ent2.CustomTime) *SysBalanceRecordCreate {
|
||||
_c.mutation.SetUpdateTime(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (_c *SysBalanceRecordCreate) SetUserID(v int64) *SysBalanceRecordCreate {
|
||||
_c.mutation.SetUserID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (_c *SysBalanceRecordCreate) SetType(v sysbalancerecord.Type) *SysBalanceRecordCreate {
|
||||
_c.mutation.SetType(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetAmount sets the "amount" field.
|
||||
func (_c *SysBalanceRecordCreate) SetAmount(v decimal.Decimal) *SysBalanceRecordCreate {
|
||||
_c.mutation.SetAmount(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetReason sets the "reason" field.
|
||||
func (_c *SysBalanceRecordCreate) SetReason(v string) *SysBalanceRecordCreate {
|
||||
_c.mutation.SetReason(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetBalanceBefore sets the "balance_before" field.
|
||||
func (_c *SysBalanceRecordCreate) SetBalanceBefore(v decimal.Decimal) *SysBalanceRecordCreate {
|
||||
_c.mutation.SetBalanceBefore(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetBalanceAfter sets the "balance_after" field.
|
||||
func (_c *SysBalanceRecordCreate) SetBalanceAfter(v decimal.Decimal) *SysBalanceRecordCreate {
|
||||
_c.mutation.SetBalanceAfter(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the SysUser entity.
|
||||
func (_c *SysBalanceRecordCreate) SetUser(v *SysUser) *SysBalanceRecordCreate {
|
||||
return _c.SetUserID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the SysBalanceRecordMutation object of the builder.
|
||||
func (_c *SysBalanceRecordCreate) Mutation() *SysBalanceRecordMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the SysBalanceRecord in the database.
|
||||
func (_c *SysBalanceRecordCreate) Save(ctx context.Context) (*SysBalanceRecord, error) {
|
||||
if err := _c.defaults(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *SysBalanceRecordCreate) SaveX(ctx context.Context) *SysBalanceRecord {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *SysBalanceRecordCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *SysBalanceRecordCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_c *SysBalanceRecordCreate) defaults() error {
|
||||
if _, ok := _c.mutation.CreateTime(); !ok {
|
||||
if sysbalancerecord.DefaultCreateTime == nil {
|
||||
return fmt.Errorf("ent: uninitialized sysbalancerecord.DefaultCreateTime (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := sysbalancerecord.DefaultCreateTime()
|
||||
_c.mutation.SetCreateTime(v)
|
||||
}
|
||||
if _, ok := _c.mutation.UpdateTime(); !ok {
|
||||
if sysbalancerecord.DefaultUpdateTime == nil {
|
||||
return fmt.Errorf("ent: uninitialized sysbalancerecord.DefaultUpdateTime (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := sysbalancerecord.DefaultUpdateTime()
|
||||
_c.mutation.SetUpdateTime(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *SysBalanceRecordCreate) check() error {
|
||||
if _, ok := _c.mutation.CreateTime(); !ok {
|
||||
return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "SysBalanceRecord.create_time"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UpdateTime(); !ok {
|
||||
return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "SysBalanceRecord.update_time"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "SysBalanceRecord.user_id"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.GetType(); !ok {
|
||||
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "SysBalanceRecord.type"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.GetType(); ok {
|
||||
if err := sysbalancerecord.TypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "SysBalanceRecord.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.Amount(); !ok {
|
||||
return &ValidationError{Name: "amount", err: errors.New(`ent: missing required field "SysBalanceRecord.amount"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Reason(); !ok {
|
||||
return &ValidationError{Name: "reason", err: errors.New(`ent: missing required field "SysBalanceRecord.reason"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.BalanceBefore(); !ok {
|
||||
return &ValidationError{Name: "balance_before", err: errors.New(`ent: missing required field "SysBalanceRecord.balance_before"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.BalanceAfter(); !ok {
|
||||
return &ValidationError{Name: "balance_after", err: errors.New(`ent: missing required field "SysBalanceRecord.balance_after"`)}
|
||||
}
|
||||
if len(_c.mutation.UserIDs()) == 0 {
|
||||
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "SysBalanceRecord.user"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *SysBalanceRecordCreate) sqlSave(ctx context.Context) (*SysBalanceRecord, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := _c.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int64(id)
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *SysBalanceRecordCreate) createSpec() (*SysBalanceRecord, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &SysBalanceRecord{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(sysbalancerecord.Table, sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64))
|
||||
)
|
||||
_spec.Schema = _c.schemaConfig.SysBalanceRecord
|
||||
_spec.OnConflict = _c.conflict
|
||||
if value, ok := _c.mutation.CreateTime(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldCreateTime, field.TypeString, value)
|
||||
_node.CreateTime = value
|
||||
}
|
||||
if value, ok := _c.mutation.UpdateTime(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldUpdateTime, field.TypeString, value)
|
||||
_node.UpdateTime = value
|
||||
}
|
||||
if value, ok := _c.mutation.GetType(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldType, field.TypeEnum, value)
|
||||
_node.Type = value
|
||||
}
|
||||
if value, ok := _c.mutation.Amount(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldAmount, field.TypeString, value)
|
||||
_node.Amount = value
|
||||
}
|
||||
if value, ok := _c.mutation.Reason(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldReason, field.TypeString, value)
|
||||
_node.Reason = value
|
||||
}
|
||||
if value, ok := _c.mutation.BalanceBefore(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldBalanceBefore, field.TypeString, value)
|
||||
_node.BalanceBefore = value
|
||||
}
|
||||
if value, ok := _c.mutation.BalanceAfter(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldBalanceAfter, field.TypeString, value)
|
||||
_node.BalanceAfter = value
|
||||
}
|
||||
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: sysbalancerecord.UserTable,
|
||||
Columns: []string{sysbalancerecord.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _c.schemaConfig.SysBalanceRecord
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.UserID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||
// of the `INSERT` statement. For example:
|
||||
//
|
||||
// client.SysBalanceRecord.Create().
|
||||
// SetCreateTime(v).
|
||||
// OnConflict(
|
||||
// // Update the row with the new values
|
||||
// // the was proposed for insertion.
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// // Override some of the fields with custom
|
||||
// // update values.
|
||||
// Update(func(u *ent.SysBalanceRecordUpsert) {
|
||||
// SetCreateTime(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (_c *SysBalanceRecordCreate) OnConflict(opts ...sql.ConflictOption) *SysBalanceRecordUpsertOne {
|
||||
_c.conflict = opts
|
||||
return &SysBalanceRecordUpsertOne{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||
// as conflict target. Using this option is equivalent to using:
|
||||
//
|
||||
// client.SysBalanceRecord.Create().
|
||||
// OnConflict(sql.ConflictColumns(columns...)).
|
||||
// Exec(ctx)
|
||||
func (_c *SysBalanceRecordCreate) OnConflictColumns(columns ...string) *SysBalanceRecordUpsertOne {
|
||||
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||||
return &SysBalanceRecordUpsertOne{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
type (
|
||||
// SysBalanceRecordUpsertOne is the builder for "upsert"-ing
|
||||
// one SysBalanceRecord node.
|
||||
SysBalanceRecordUpsertOne struct {
|
||||
create *SysBalanceRecordCreate
|
||||
}
|
||||
|
||||
// SysBalanceRecordUpsert is the "OnConflict" setter.
|
||||
SysBalanceRecordUpsert struct {
|
||||
*sql.UpdateSet
|
||||
}
|
||||
)
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (u *SysBalanceRecordUpsert) SetUpdateTime(v *ent2.CustomTime) *SysBalanceRecordUpsert {
|
||||
u.Set(sysbalancerecord.FieldUpdateTime, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsert) UpdateUpdateTime() *SysBalanceRecordUpsert {
|
||||
u.SetExcluded(sysbalancerecord.FieldUpdateTime)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (u *SysBalanceRecordUpsert) SetUserID(v int64) *SysBalanceRecordUpsert {
|
||||
u.Set(sysbalancerecord.FieldUserID, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsert) UpdateUserID() *SysBalanceRecordUpsert {
|
||||
u.SetExcluded(sysbalancerecord.FieldUserID)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (u *SysBalanceRecordUpsert) SetType(v sysbalancerecord.Type) *SysBalanceRecordUpsert {
|
||||
u.Set(sysbalancerecord.FieldType, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateType sets the "type" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsert) UpdateType() *SysBalanceRecordUpsert {
|
||||
u.SetExcluded(sysbalancerecord.FieldType)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetAmount sets the "amount" field.
|
||||
func (u *SysBalanceRecordUpsert) SetAmount(v decimal.Decimal) *SysBalanceRecordUpsert {
|
||||
u.Set(sysbalancerecord.FieldAmount, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateAmount sets the "amount" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsert) UpdateAmount() *SysBalanceRecordUpsert {
|
||||
u.SetExcluded(sysbalancerecord.FieldAmount)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetReason sets the "reason" field.
|
||||
func (u *SysBalanceRecordUpsert) SetReason(v string) *SysBalanceRecordUpsert {
|
||||
u.Set(sysbalancerecord.FieldReason, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateReason sets the "reason" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsert) UpdateReason() *SysBalanceRecordUpsert {
|
||||
u.SetExcluded(sysbalancerecord.FieldReason)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetBalanceBefore sets the "balance_before" field.
|
||||
func (u *SysBalanceRecordUpsert) SetBalanceBefore(v decimal.Decimal) *SysBalanceRecordUpsert {
|
||||
u.Set(sysbalancerecord.FieldBalanceBefore, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateBalanceBefore sets the "balance_before" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsert) UpdateBalanceBefore() *SysBalanceRecordUpsert {
|
||||
u.SetExcluded(sysbalancerecord.FieldBalanceBefore)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetBalanceAfter sets the "balance_after" field.
|
||||
func (u *SysBalanceRecordUpsert) SetBalanceAfter(v decimal.Decimal) *SysBalanceRecordUpsert {
|
||||
u.Set(sysbalancerecord.FieldBalanceAfter, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateBalanceAfter sets the "balance_after" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsert) UpdateBalanceAfter() *SysBalanceRecordUpsert {
|
||||
u.SetExcluded(sysbalancerecord.FieldBalanceAfter)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.SysBalanceRecord.Create().
|
||||
// OnConflict(
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// Exec(ctx)
|
||||
func (u *SysBalanceRecordUpsertOne) UpdateNewValues() *SysBalanceRecordUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||
if _, exists := u.create.mutation.CreateTime(); exists {
|
||||
s.SetIgnore(sysbalancerecord.FieldCreateTime)
|
||||
}
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// Ignore sets each column to itself in case of conflict.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.SysBalanceRecord.Create().
|
||||
// OnConflict(sql.ResolveWithIgnore()).
|
||||
// Exec(ctx)
|
||||
func (u *SysBalanceRecordUpsertOne) Ignore() *SysBalanceRecordUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||
return u
|
||||
}
|
||||
|
||||
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||
// Supported only by SQLite and PostgreSQL.
|
||||
func (u *SysBalanceRecordUpsertOne) DoNothing() *SysBalanceRecordUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||
return u
|
||||
}
|
||||
|
||||
// Update allows overriding fields `UPDATE` values. See the SysBalanceRecordCreate.OnConflict
|
||||
// documentation for more info.
|
||||
func (u *SysBalanceRecordUpsertOne) Update(set func(*SysBalanceRecordUpsert)) *SysBalanceRecordUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||
set(&SysBalanceRecordUpsert{UpdateSet: update})
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (u *SysBalanceRecordUpsertOne) SetUpdateTime(v *ent2.CustomTime) *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetUpdateTime(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertOne) UpdateUpdateTime() *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateUpdateTime()
|
||||
})
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (u *SysBalanceRecordUpsertOne) SetUserID(v int64) *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetUserID(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertOne) UpdateUserID() *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateUserID()
|
||||
})
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (u *SysBalanceRecordUpsertOne) SetType(v sysbalancerecord.Type) *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetType(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateType sets the "type" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertOne) UpdateType() *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateType()
|
||||
})
|
||||
}
|
||||
|
||||
// SetAmount sets the "amount" field.
|
||||
func (u *SysBalanceRecordUpsertOne) SetAmount(v decimal.Decimal) *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetAmount(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateAmount sets the "amount" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertOne) UpdateAmount() *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateAmount()
|
||||
})
|
||||
}
|
||||
|
||||
// SetReason sets the "reason" field.
|
||||
func (u *SysBalanceRecordUpsertOne) SetReason(v string) *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetReason(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateReason sets the "reason" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertOne) UpdateReason() *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateReason()
|
||||
})
|
||||
}
|
||||
|
||||
// SetBalanceBefore sets the "balance_before" field.
|
||||
func (u *SysBalanceRecordUpsertOne) SetBalanceBefore(v decimal.Decimal) *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetBalanceBefore(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateBalanceBefore sets the "balance_before" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertOne) UpdateBalanceBefore() *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateBalanceBefore()
|
||||
})
|
||||
}
|
||||
|
||||
// SetBalanceAfter sets the "balance_after" field.
|
||||
func (u *SysBalanceRecordUpsertOne) SetBalanceAfter(v decimal.Decimal) *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetBalanceAfter(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateBalanceAfter sets the "balance_after" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertOne) UpdateBalanceAfter() *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateBalanceAfter()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *SysBalanceRecordUpsertOne) Exec(ctx context.Context) error {
|
||||
if len(u.create.conflict) == 0 {
|
||||
return errors.New("ent: missing options for SysBalanceRecordCreate.OnConflict")
|
||||
}
|
||||
return u.create.Exec(ctx)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (u *SysBalanceRecordUpsertOne) ExecX(ctx context.Context) {
|
||||
if err := u.create.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Exec executes the UPSERT query and returns the inserted/updated ID.
|
||||
func (u *SysBalanceRecordUpsertOne) ID(ctx context.Context) (id int64, err error) {
|
||||
node, err := u.create.Save(ctx)
|
||||
if err != nil {
|
||||
return id, err
|
||||
}
|
||||
return node.ID, nil
|
||||
}
|
||||
|
||||
// IDX is like ID, but panics if an error occurs.
|
||||
func (u *SysBalanceRecordUpsertOne) IDX(ctx context.Context) int64 {
|
||||
id, err := u.ID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// SysBalanceRecordCreateBulk is the builder for creating many SysBalanceRecord entities in bulk.
|
||||
type SysBalanceRecordCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*SysBalanceRecordCreate
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// Save creates the SysBalanceRecord entities in the database.
|
||||
func (_c *SysBalanceRecordCreateBulk) Save(ctx context.Context) ([]*SysBalanceRecord, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*SysBalanceRecord, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*SysBalanceRecordMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
spec.OnConflict = _c.conflict
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int64(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *SysBalanceRecordCreateBulk) SaveX(ctx context.Context) []*SysBalanceRecord {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *SysBalanceRecordCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *SysBalanceRecordCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||
// of the `INSERT` statement. For example:
|
||||
//
|
||||
// client.SysBalanceRecord.CreateBulk(builders...).
|
||||
// OnConflict(
|
||||
// // Update the row with the new values
|
||||
// // the was proposed for insertion.
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// // Override some of the fields with custom
|
||||
// // update values.
|
||||
// Update(func(u *ent.SysBalanceRecordUpsert) {
|
||||
// SetCreateTime(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (_c *SysBalanceRecordCreateBulk) OnConflict(opts ...sql.ConflictOption) *SysBalanceRecordUpsertBulk {
|
||||
_c.conflict = opts
|
||||
return &SysBalanceRecordUpsertBulk{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||
// as conflict target. Using this option is equivalent to using:
|
||||
//
|
||||
// client.SysBalanceRecord.Create().
|
||||
// OnConflict(sql.ConflictColumns(columns...)).
|
||||
// Exec(ctx)
|
||||
func (_c *SysBalanceRecordCreateBulk) OnConflictColumns(columns ...string) *SysBalanceRecordUpsertBulk {
|
||||
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||||
return &SysBalanceRecordUpsertBulk{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
// SysBalanceRecordUpsertBulk is the builder for "upsert"-ing
|
||||
// a bulk of SysBalanceRecord nodes.
|
||||
type SysBalanceRecordUpsertBulk struct {
|
||||
create *SysBalanceRecordCreateBulk
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that
|
||||
// were set on create. Using this option is equivalent to using:
|
||||
//
|
||||
// client.SysBalanceRecord.Create().
|
||||
// OnConflict(
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// Exec(ctx)
|
||||
func (u *SysBalanceRecordUpsertBulk) UpdateNewValues() *SysBalanceRecordUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||
for _, b := range u.create.builders {
|
||||
if _, exists := b.mutation.CreateTime(); exists {
|
||||
s.SetIgnore(sysbalancerecord.FieldCreateTime)
|
||||
}
|
||||
}
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// Ignore sets each column to itself in case of conflict.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.SysBalanceRecord.Create().
|
||||
// OnConflict(sql.ResolveWithIgnore()).
|
||||
// Exec(ctx)
|
||||
func (u *SysBalanceRecordUpsertBulk) Ignore() *SysBalanceRecordUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||
return u
|
||||
}
|
||||
|
||||
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||
// Supported only by SQLite and PostgreSQL.
|
||||
func (u *SysBalanceRecordUpsertBulk) DoNothing() *SysBalanceRecordUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||
return u
|
||||
}
|
||||
|
||||
// Update allows overriding fields `UPDATE` values. See the SysBalanceRecordCreateBulk.OnConflict
|
||||
// documentation for more info.
|
||||
func (u *SysBalanceRecordUpsertBulk) Update(set func(*SysBalanceRecordUpsert)) *SysBalanceRecordUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||
set(&SysBalanceRecordUpsert{UpdateSet: update})
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (u *SysBalanceRecordUpsertBulk) SetUpdateTime(v *ent2.CustomTime) *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetUpdateTime(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertBulk) UpdateUpdateTime() *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateUpdateTime()
|
||||
})
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (u *SysBalanceRecordUpsertBulk) SetUserID(v int64) *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetUserID(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertBulk) UpdateUserID() *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateUserID()
|
||||
})
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (u *SysBalanceRecordUpsertBulk) SetType(v sysbalancerecord.Type) *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetType(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateType sets the "type" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertBulk) UpdateType() *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateType()
|
||||
})
|
||||
}
|
||||
|
||||
// SetAmount sets the "amount" field.
|
||||
func (u *SysBalanceRecordUpsertBulk) SetAmount(v decimal.Decimal) *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetAmount(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateAmount sets the "amount" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertBulk) UpdateAmount() *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateAmount()
|
||||
})
|
||||
}
|
||||
|
||||
// SetReason sets the "reason" field.
|
||||
func (u *SysBalanceRecordUpsertBulk) SetReason(v string) *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetReason(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateReason sets the "reason" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertBulk) UpdateReason() *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateReason()
|
||||
})
|
||||
}
|
||||
|
||||
// SetBalanceBefore sets the "balance_before" field.
|
||||
func (u *SysBalanceRecordUpsertBulk) SetBalanceBefore(v decimal.Decimal) *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetBalanceBefore(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateBalanceBefore sets the "balance_before" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertBulk) UpdateBalanceBefore() *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateBalanceBefore()
|
||||
})
|
||||
}
|
||||
|
||||
// SetBalanceAfter sets the "balance_after" field.
|
||||
func (u *SysBalanceRecordUpsertBulk) SetBalanceAfter(v decimal.Decimal) *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetBalanceAfter(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateBalanceAfter sets the "balance_after" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertBulk) UpdateBalanceAfter() *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateBalanceAfter()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *SysBalanceRecordUpsertBulk) Exec(ctx context.Context) error {
|
||||
if u.create.err != nil {
|
||||
return u.create.err
|
||||
}
|
||||
for i, b := range u.create.builders {
|
||||
if len(b.conflict) != 0 {
|
||||
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the SysBalanceRecordCreateBulk instead", i)
|
||||
}
|
||||
}
|
||||
if len(u.create.conflict) == 0 {
|
||||
return errors.New("ent: missing options for SysBalanceRecordCreateBulk.OnConflict")
|
||||
}
|
||||
return u.create.Exec(ctx)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (u *SysBalanceRecordUpsertBulk) ExecX(ctx context.Context) {
|
||||
if err := u.create.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// SysBalanceRecordDelete is the builder for deleting a SysBalanceRecord entity.
|
||||
type SysBalanceRecordDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SysBalanceRecordMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SysBalanceRecordDelete builder.
|
||||
func (_d *SysBalanceRecordDelete) Where(ps ...predicate.SysBalanceRecord) *SysBalanceRecordDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *SysBalanceRecordDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *SysBalanceRecordDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *SysBalanceRecordDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(sysbalancerecord.Table, sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64))
|
||||
_spec.Node.Schema = _d.schemaConfig.SysBalanceRecord
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _d.schemaConfig)
|
||||
if ps := _d.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
_d.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// SysBalanceRecordDeleteOne is the builder for deleting a single SysBalanceRecord entity.
|
||||
type SysBalanceRecordDeleteOne struct {
|
||||
_d *SysBalanceRecordDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SysBalanceRecordDelete builder.
|
||||
func (_d *SysBalanceRecordDeleteOne) Where(ps ...predicate.SysBalanceRecord) *SysBalanceRecordDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *SysBalanceRecordDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{sysbalancerecord.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *SysBalanceRecordDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,667 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// SysBalanceRecordQuery is the builder for querying SysBalanceRecord entities.
|
||||
type SysBalanceRecordQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []sysbalancerecord.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.SysBalanceRecord
|
||||
withUser *SysUserQuery
|
||||
modifiers []func(*sql.Selector)
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the SysBalanceRecordQuery builder.
|
||||
func (_q *SysBalanceRecordQuery) Where(ps ...predicate.SysBalanceRecord) *SysBalanceRecordQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *SysBalanceRecordQuery) Limit(limit int) *SysBalanceRecordQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *SysBalanceRecordQuery) Offset(offset int) *SysBalanceRecordQuery {
|
||||
_q.ctx.Offset = &offset
|
||||
return _q
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (_q *SysBalanceRecordQuery) Unique(unique bool) *SysBalanceRecordQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *SysBalanceRecordQuery) Order(o ...sysbalancerecord.OrderOption) *SysBalanceRecordQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryUser chains the current query on the "user" edge.
|
||||
func (_q *SysBalanceRecordQuery) QueryUser() *SysUserQuery {
|
||||
query := (&SysUserClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(sysbalancerecord.Table, sysbalancerecord.FieldID, selector),
|
||||
sqlgraph.To(sysuser.Table, sysuser.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, sysbalancerecord.UserTable, sysbalancerecord.UserColumn),
|
||||
)
|
||||
schemaConfig := _q.schemaConfig
|
||||
step.To.Schema = schemaConfig.SysUser
|
||||
step.Edge.Schema = schemaConfig.SysBalanceRecord
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first SysBalanceRecord entity from the query.
|
||||
// Returns a *NotFoundError when no SysBalanceRecord was found.
|
||||
func (_q *SysBalanceRecordQuery) First(ctx context.Context) (*SysBalanceRecord, error) {
|
||||
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{sysbalancerecord.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *SysBalanceRecordQuery) FirstX(ctx context.Context) *SysBalanceRecord {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first SysBalanceRecord ID from the query.
|
||||
// Returns a *NotFoundError when no SysBalanceRecord ID was found.
|
||||
func (_q *SysBalanceRecordQuery) FirstID(ctx context.Context) (id int64, err error) {
|
||||
var ids []int64
|
||||
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{sysbalancerecord.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *SysBalanceRecordQuery) FirstIDX(ctx context.Context) int64 {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single SysBalanceRecord entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one SysBalanceRecord entity is found.
|
||||
// Returns a *NotFoundError when no SysBalanceRecord entities are found.
|
||||
func (_q *SysBalanceRecordQuery) Only(ctx context.Context) (*SysBalanceRecord, error) {
|
||||
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{sysbalancerecord.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{sysbalancerecord.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *SysBalanceRecordQuery) OnlyX(ctx context.Context) *SysBalanceRecord {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only SysBalanceRecord ID in the query.
|
||||
// Returns a *NotSingularError when more than one SysBalanceRecord ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *SysBalanceRecordQuery) OnlyID(ctx context.Context) (id int64, err error) {
|
||||
var ids []int64
|
||||
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{sysbalancerecord.Label}
|
||||
default:
|
||||
err = &NotSingularError{sysbalancerecord.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *SysBalanceRecordQuery) OnlyIDX(ctx context.Context) int64 {
|
||||
id, err := _q.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of SysBalanceRecords.
|
||||
func (_q *SysBalanceRecordQuery) All(ctx context.Context) ([]*SysBalanceRecord, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*SysBalanceRecord, *SysBalanceRecordQuery]()
|
||||
return withInterceptors[[]*SysBalanceRecord](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *SysBalanceRecordQuery) AllX(ctx context.Context) []*SysBalanceRecord {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of SysBalanceRecord IDs.
|
||||
func (_q *SysBalanceRecordQuery) IDs(ctx context.Context) (ids []int64, err error) {
|
||||
if _q.ctx.Unique == nil && _q.path != nil {
|
||||
_q.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||
if err = _q.Select(sysbalancerecord.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *SysBalanceRecordQuery) IDsX(ctx context.Context) []int64 {
|
||||
ids, err := _q.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (_q *SysBalanceRecordQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, _q, querierCount[*SysBalanceRecordQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *SysBalanceRecordQuery) CountX(ctx context.Context) int {
|
||||
count, err := _q.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (_q *SysBalanceRecordQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
|
||||
switch _, err := _q.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *SysBalanceRecordQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the SysBalanceRecordQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (_q *SysBalanceRecordQuery) Clone() *SysBalanceRecordQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &SysBalanceRecordQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]sysbalancerecord.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.SysBalanceRecord{}, _q.predicates...),
|
||||
withUser: _q.withUser.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
modifiers: append([]func(*sql.Selector){}, _q.modifiers...),
|
||||
}
|
||||
}
|
||||
|
||||
// WithUser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *SysBalanceRecordQuery) WithUser(opts ...func(*SysUserQuery)) *SysBalanceRecordQuery {
|
||||
query := (&SysUserClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withUser = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreateTime *ent2.CustomTime `json:"createTime"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.SysBalanceRecord.Query().
|
||||
// GroupBy(sysbalancerecord.FieldCreateTime).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *SysBalanceRecordQuery) GroupBy(field string, fields ...string) *SysBalanceRecordGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &SysBalanceRecordGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = sysbalancerecord.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreateTime *ent2.CustomTime `json:"createTime"`
|
||||
// }
|
||||
//
|
||||
// client.SysBalanceRecord.Query().
|
||||
// Select(sysbalancerecord.FieldCreateTime).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *SysBalanceRecordQuery) Select(fields ...string) *SysBalanceRecordSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &SysBalanceRecordSelect{SysBalanceRecordQuery: _q}
|
||||
sbuild.label = sysbalancerecord.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a SysBalanceRecordSelect configured with the given aggregations.
|
||||
func (_q *SysBalanceRecordQuery) Aggregate(fns ...AggregateFunc) *SysBalanceRecordSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *SysBalanceRecordQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !sysbalancerecord.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if _q.path != nil {
|
||||
prev, err := _q.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_q.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *SysBalanceRecordQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysBalanceRecord, error) {
|
||||
var (
|
||||
nodes = []*SysBalanceRecord{}
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
_q.withUser != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*SysBalanceRecord).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &SysBalanceRecord{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
_spec.Node.Schema = _q.schemaConfig.SysBalanceRecord
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _q.schemaConfig)
|
||||
if len(_q.modifiers) > 0 {
|
||||
_spec.Modifiers = _q.modifiers
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := _q.withUser; query != nil {
|
||||
if err := _q.loadUser(ctx, query, nodes, nil,
|
||||
func(n *SysBalanceRecord, e *SysUser) { n.Edges.User = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *SysBalanceRecordQuery) loadUser(ctx context.Context, query *SysUserQuery, nodes []*SysBalanceRecord, init func(*SysBalanceRecord), assign func(*SysBalanceRecord, *SysUser)) error {
|
||||
ids := make([]int64, 0, len(nodes))
|
||||
nodeids := make(map[int64][]*SysBalanceRecord)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].UserID
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(sysuser.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "user_id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *SysBalanceRecordQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
_spec.Node.Schema = _q.schemaConfig.SysBalanceRecord
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _q.schemaConfig)
|
||||
if len(_q.modifiers) > 0 {
|
||||
_spec.Modifiers = _q.modifiers
|
||||
}
|
||||
_spec.Node.Columns = _q.ctx.Fields
|
||||
if len(_q.ctx.Fields) > 0 {
|
||||
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
|
||||
}
|
||||
|
||||
func (_q *SysBalanceRecordQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(sysbalancerecord.Table, sysbalancerecord.Columns, sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64))
|
||||
_spec.From = _q.sql
|
||||
if unique := _q.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if _q.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, sysbalancerecord.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != sysbalancerecord.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
if _q.withUser != nil {
|
||||
_spec.Node.AddColumnOnce(sysbalancerecord.FieldUserID)
|
||||
}
|
||||
}
|
||||
if ps := _q.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := _q.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (_q *SysBalanceRecordQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(sysbalancerecord.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = sysbalancerecord.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if _q.sql != nil {
|
||||
selector = _q.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
t1.Schema(_q.schemaConfig.SysBalanceRecord)
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _q.schemaConfig)
|
||||
selector.WithContext(ctx)
|
||||
for _, m := range _q.modifiers {
|
||||
m(selector)
|
||||
}
|
||||
for _, p := range _q.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range _q.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
|
||||
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
|
||||
// either committed or rolled-back.
|
||||
func (_q *SysBalanceRecordQuery) ForUpdate(opts ...sql.LockOption) *SysBalanceRecordQuery {
|
||||
if _q.driver.Dialect() == dialect.Postgres {
|
||||
_q.Unique(false)
|
||||
}
|
||||
_q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
|
||||
s.ForUpdate(opts...)
|
||||
})
|
||||
return _q
|
||||
}
|
||||
|
||||
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
|
||||
// on any rows that are read. Other sessions can read the rows, but cannot modify them
|
||||
// until your transaction commits.
|
||||
func (_q *SysBalanceRecordQuery) ForShare(opts ...sql.LockOption) *SysBalanceRecordQuery {
|
||||
if _q.driver.Dialect() == dialect.Postgres {
|
||||
_q.Unique(false)
|
||||
}
|
||||
_q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
|
||||
s.ForShare(opts...)
|
||||
})
|
||||
return _q
|
||||
}
|
||||
|
||||
// Modify adds a query modifier for attaching custom logic to queries.
|
||||
func (_q *SysBalanceRecordQuery) Modify(modifiers ...func(s *sql.Selector)) *SysBalanceRecordSelect {
|
||||
_q.modifiers = append(_q.modifiers, modifiers...)
|
||||
return _q.Select()
|
||||
}
|
||||
|
||||
// SysBalanceRecordGroupBy is the group-by builder for SysBalanceRecord entities.
|
||||
type SysBalanceRecordGroupBy struct {
|
||||
selector
|
||||
build *SysBalanceRecordQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *SysBalanceRecordGroupBy) Aggregate(fns ...AggregateFunc) *SysBalanceRecordGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *SysBalanceRecordGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*SysBalanceRecordQuery, *SysBalanceRecordGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *SysBalanceRecordGroupBy) sqlScan(ctx context.Context, root *SysBalanceRecordQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(_g.fns))
|
||||
for _, fn := range _g.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||
for _, f := range *_g.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// SysBalanceRecordSelect is the builder for selecting fields of SysBalanceRecord entities.
|
||||
type SysBalanceRecordSelect struct {
|
||||
*SysBalanceRecordQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *SysBalanceRecordSelect) Aggregate(fns ...AggregateFunc) *SysBalanceRecordSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *SysBalanceRecordSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||
if err := _s.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*SysBalanceRecordQuery, *SysBalanceRecordSelect](ctx, _s.SysBalanceRecordQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *SysBalanceRecordSelect) sqlScan(ctx context.Context, root *SysBalanceRecordQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*_s.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// Modify adds a query modifier for attaching custom logic to queries.
|
||||
func (_s *SysBalanceRecordSelect) Modify(modifiers ...func(s *sql.Selector)) *SysBalanceRecordSelect {
|
||||
_s.modifiers = append(_s.modifiers, modifiers...)
|
||||
return _s
|
||||
}
|
||||
@@ -0,0 +1,531 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// SysBalanceRecordUpdate is the builder for updating SysBalanceRecord entities.
|
||||
type SysBalanceRecordUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SysBalanceRecordMutation
|
||||
modifiers []func(*sql.UpdateBuilder)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SysBalanceRecordUpdate builder.
|
||||
func (_u *SysBalanceRecordUpdate) Where(ps ...predicate.SysBalanceRecord) *SysBalanceRecordUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (_u *SysBalanceRecordUpdate) SetUpdateTime(v *ent2.CustomTime) *SysBalanceRecordUpdate {
|
||||
_u.mutation.SetUpdateTime(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (_u *SysBalanceRecordUpdate) SetUserID(v int64) *SysBalanceRecordUpdate {
|
||||
_u.mutation.SetUserID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdate) SetNillableUserID(v *int64) *SysBalanceRecordUpdate {
|
||||
if v != nil {
|
||||
_u.SetUserID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (_u *SysBalanceRecordUpdate) SetType(v sysbalancerecord.Type) *SysBalanceRecordUpdate {
|
||||
_u.mutation.SetType(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdate) SetNillableType(v *sysbalancerecord.Type) *SysBalanceRecordUpdate {
|
||||
if v != nil {
|
||||
_u.SetType(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetAmount sets the "amount" field.
|
||||
func (_u *SysBalanceRecordUpdate) SetAmount(v decimal.Decimal) *SysBalanceRecordUpdate {
|
||||
_u.mutation.SetAmount(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableAmount sets the "amount" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdate) SetNillableAmount(v *decimal.Decimal) *SysBalanceRecordUpdate {
|
||||
if v != nil {
|
||||
_u.SetAmount(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetReason sets the "reason" field.
|
||||
func (_u *SysBalanceRecordUpdate) SetReason(v string) *SysBalanceRecordUpdate {
|
||||
_u.mutation.SetReason(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableReason sets the "reason" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdate) SetNillableReason(v *string) *SysBalanceRecordUpdate {
|
||||
if v != nil {
|
||||
_u.SetReason(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetBalanceBefore sets the "balance_before" field.
|
||||
func (_u *SysBalanceRecordUpdate) SetBalanceBefore(v decimal.Decimal) *SysBalanceRecordUpdate {
|
||||
_u.mutation.SetBalanceBefore(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableBalanceBefore sets the "balance_before" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdate) SetNillableBalanceBefore(v *decimal.Decimal) *SysBalanceRecordUpdate {
|
||||
if v != nil {
|
||||
_u.SetBalanceBefore(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetBalanceAfter sets the "balance_after" field.
|
||||
func (_u *SysBalanceRecordUpdate) SetBalanceAfter(v decimal.Decimal) *SysBalanceRecordUpdate {
|
||||
_u.mutation.SetBalanceAfter(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableBalanceAfter sets the "balance_after" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdate) SetNillableBalanceAfter(v *decimal.Decimal) *SysBalanceRecordUpdate {
|
||||
if v != nil {
|
||||
_u.SetBalanceAfter(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the SysUser entity.
|
||||
func (_u *SysBalanceRecordUpdate) SetUser(v *SysUser) *SysBalanceRecordUpdate {
|
||||
return _u.SetUserID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the SysBalanceRecordMutation object of the builder.
|
||||
func (_u *SysBalanceRecordUpdate) Mutation() *SysBalanceRecordMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the SysUser entity.
|
||||
func (_u *SysBalanceRecordUpdate) ClearUser() *SysBalanceRecordUpdate {
|
||||
_u.mutation.ClearUser()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *SysBalanceRecordUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *SysBalanceRecordUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *SysBalanceRecordUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *SysBalanceRecordUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *SysBalanceRecordUpdate) check() error {
|
||||
if v, ok := _u.mutation.GetType(); ok {
|
||||
if err := sysbalancerecord.TypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "SysBalanceRecord.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "SysBalanceRecord.user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
||||
func (_u *SysBalanceRecordUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *SysBalanceRecordUpdate {
|
||||
_u.modifiers = append(_u.modifiers, modifiers...)
|
||||
return _u
|
||||
}
|
||||
|
||||
func (_u *SysBalanceRecordUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(sysbalancerecord.Table, sysbalancerecord.Columns, sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64))
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.UpdateTime(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldUpdateTime, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.GetType(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Amount(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldAmount, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Reason(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldReason, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.BalanceBefore(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldBalanceBefore, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.BalanceAfter(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldBalanceAfter, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.UserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: sysbalancerecord.UserTable,
|
||||
Columns: []string{sysbalancerecord.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: sysbalancerecord.UserTable,
|
||||
Columns: []string{sysbalancerecord.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_spec.Node.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _u.schemaConfig)
|
||||
_spec.AddModifiers(_u.modifiers...)
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{sysbalancerecord.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// SysBalanceRecordUpdateOne is the builder for updating a single SysBalanceRecord entity.
|
||||
type SysBalanceRecordUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *SysBalanceRecordMutation
|
||||
modifiers []func(*sql.UpdateBuilder)
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetUpdateTime(v *ent2.CustomTime) *SysBalanceRecordUpdateOne {
|
||||
_u.mutation.SetUpdateTime(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetUserID(v int64) *SysBalanceRecordUpdateOne {
|
||||
_u.mutation.SetUserID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetNillableUserID(v *int64) *SysBalanceRecordUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUserID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetType(v sysbalancerecord.Type) *SysBalanceRecordUpdateOne {
|
||||
_u.mutation.SetType(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetNillableType(v *sysbalancerecord.Type) *SysBalanceRecordUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetType(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetAmount sets the "amount" field.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetAmount(v decimal.Decimal) *SysBalanceRecordUpdateOne {
|
||||
_u.mutation.SetAmount(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableAmount sets the "amount" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetNillableAmount(v *decimal.Decimal) *SysBalanceRecordUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetAmount(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetReason sets the "reason" field.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetReason(v string) *SysBalanceRecordUpdateOne {
|
||||
_u.mutation.SetReason(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableReason sets the "reason" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetNillableReason(v *string) *SysBalanceRecordUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetReason(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetBalanceBefore sets the "balance_before" field.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetBalanceBefore(v decimal.Decimal) *SysBalanceRecordUpdateOne {
|
||||
_u.mutation.SetBalanceBefore(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableBalanceBefore sets the "balance_before" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetNillableBalanceBefore(v *decimal.Decimal) *SysBalanceRecordUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetBalanceBefore(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetBalanceAfter sets the "balance_after" field.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetBalanceAfter(v decimal.Decimal) *SysBalanceRecordUpdateOne {
|
||||
_u.mutation.SetBalanceAfter(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableBalanceAfter sets the "balance_after" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetNillableBalanceAfter(v *decimal.Decimal) *SysBalanceRecordUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetBalanceAfter(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the SysUser entity.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetUser(v *SysUser) *SysBalanceRecordUpdateOne {
|
||||
return _u.SetUserID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the SysBalanceRecordMutation object of the builder.
|
||||
func (_u *SysBalanceRecordUpdateOne) Mutation() *SysBalanceRecordMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the SysUser entity.
|
||||
func (_u *SysBalanceRecordUpdateOne) ClearUser() *SysBalanceRecordUpdateOne {
|
||||
_u.mutation.ClearUser()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SysBalanceRecordUpdate builder.
|
||||
func (_u *SysBalanceRecordUpdateOne) Where(ps ...predicate.SysBalanceRecord) *SysBalanceRecordUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (_u *SysBalanceRecordUpdateOne) Select(field string, fields ...string) *SysBalanceRecordUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated SysBalanceRecord entity.
|
||||
func (_u *SysBalanceRecordUpdateOne) Save(ctx context.Context) (*SysBalanceRecord, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *SysBalanceRecordUpdateOne) SaveX(ctx context.Context) *SysBalanceRecord {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *SysBalanceRecordUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *SysBalanceRecordUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *SysBalanceRecordUpdateOne) check() error {
|
||||
if v, ok := _u.mutation.GetType(); ok {
|
||||
if err := sysbalancerecord.TypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "SysBalanceRecord.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "SysBalanceRecord.user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
||||
func (_u *SysBalanceRecordUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *SysBalanceRecordUpdateOne {
|
||||
_u.modifiers = append(_u.modifiers, modifiers...)
|
||||
return _u
|
||||
}
|
||||
|
||||
func (_u *SysBalanceRecordUpdateOne) sqlSave(ctx context.Context) (_node *SysBalanceRecord, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(sysbalancerecord.Table, sysbalancerecord.Columns, sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SysBalanceRecord.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, sysbalancerecord.FieldID)
|
||||
for _, f := range fields {
|
||||
if !sysbalancerecord.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != sysbalancerecord.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.UpdateTime(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldUpdateTime, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.GetType(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Amount(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldAmount, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Reason(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldReason, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.BalanceBefore(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldBalanceBefore, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.BalanceAfter(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldBalanceAfter, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.UserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: sysbalancerecord.UserTable,
|
||||
Columns: []string{sysbalancerecord.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: sysbalancerecord.UserTable,
|
||||
Columns: []string{sysbalancerecord.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_spec.Node.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _u.schemaConfig)
|
||||
_spec.AddModifiers(_u.modifiers...)
|
||||
_node = &SysBalanceRecord{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{sysbalancerecord.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
+53
-12
@@ -74,20 +74,23 @@ type SysUserEdges struct {
|
||||
UsedCards []*SysCard `json:"used_cards,omitempty"`
|
||||
// CashbackCards holds the value of the cashback_cards edge.
|
||||
CashbackCards []*SysCard `json:"cashback_cards,omitempty"`
|
||||
// BalanceRecords holds the value of the balance_records edge.
|
||||
BalanceRecords []*SysBalanceRecord `json:"balance_records,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [13]bool
|
||||
namedChildren map[string][]*SysUser
|
||||
namedRoles map[string][]*SysRole
|
||||
namedImages map[string][]*CpImage
|
||||
namedCpuser map[string][]*CpUser
|
||||
namedCpTask map[string][]*CpTask
|
||||
namedCpLeave map[string][]*CpLeave
|
||||
namedCourseEntity map[string][]*CourseEntity
|
||||
namedCpTaskLogs map[string][]*CpTaskLog
|
||||
namedCreatedCards map[string][]*SysCard
|
||||
namedUsedCards map[string][]*SysCard
|
||||
namedCashbackCards map[string][]*SysCard
|
||||
loadedTypes [14]bool
|
||||
namedChildren map[string][]*SysUser
|
||||
namedRoles map[string][]*SysRole
|
||||
namedImages map[string][]*CpImage
|
||||
namedCpuser map[string][]*CpUser
|
||||
namedCpTask map[string][]*CpTask
|
||||
namedCpLeave map[string][]*CpLeave
|
||||
namedCourseEntity map[string][]*CourseEntity
|
||||
namedCpTaskLogs map[string][]*CpTaskLog
|
||||
namedCreatedCards map[string][]*SysCard
|
||||
namedUsedCards map[string][]*SysCard
|
||||
namedCashbackCards map[string][]*SysCard
|
||||
namedBalanceRecords map[string][]*SysBalanceRecord
|
||||
}
|
||||
|
||||
// ParentOrErr returns the Parent value or an error if the edge
|
||||
@@ -211,6 +214,15 @@ func (e SysUserEdges) CashbackCardsOrErr() ([]*SysCard, error) {
|
||||
return nil, &NotLoadedError{edge: "cashback_cards"}
|
||||
}
|
||||
|
||||
// BalanceRecordsOrErr returns the BalanceRecords value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e SysUserEdges) BalanceRecordsOrErr() ([]*SysBalanceRecord, error) {
|
||||
if e.loadedTypes[13] {
|
||||
return e.BalanceRecords, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "balance_records"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*SysUser) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
@@ -394,6 +406,11 @@ func (_m *SysUser) QueryCashbackCards() *SysCardQuery {
|
||||
return NewSysUserClient(_m.config).QueryCashbackCards(_m)
|
||||
}
|
||||
|
||||
// QueryBalanceRecords queries the "balance_records" edge of the SysUser entity.
|
||||
func (_m *SysUser) QueryBalanceRecords() *SysBalanceRecordQuery {
|
||||
return NewSysUserClient(_m.config).QueryBalanceRecords(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this SysUser.
|
||||
// Note that you need to call SysUser.Unwrap() before calling this method if this SysUser
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
@@ -713,5 +730,29 @@ func (_m *SysUser) appendNamedCashbackCards(name string, edges ...*SysCard) {
|
||||
}
|
||||
}
|
||||
|
||||
// NamedBalanceRecords returns the BalanceRecords named value or an error if the edge was not
|
||||
// loaded in eager-loading with this name.
|
||||
func (_m *SysUser) NamedBalanceRecords(name string) ([]*SysBalanceRecord, error) {
|
||||
if _m.Edges.namedBalanceRecords == nil {
|
||||
return nil, &NotLoadedError{edge: name}
|
||||
}
|
||||
nodes, ok := _m.Edges.namedBalanceRecords[name]
|
||||
if !ok {
|
||||
return nil, &NotLoadedError{edge: name}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_m *SysUser) appendNamedBalanceRecords(name string, edges ...*SysBalanceRecord) {
|
||||
if _m.Edges.namedBalanceRecords == nil {
|
||||
_m.Edges.namedBalanceRecords = make(map[string][]*SysBalanceRecord)
|
||||
}
|
||||
if len(edges) == 0 {
|
||||
_m.Edges.namedBalanceRecords[name] = []*SysBalanceRecord{}
|
||||
} else {
|
||||
_m.Edges.namedBalanceRecords[name] = append(_m.Edges.namedBalanceRecords[name], edges...)
|
||||
}
|
||||
}
|
||||
|
||||
// SysUsers is a parsable slice of SysUser.
|
||||
type SysUsers []*SysUser
|
||||
|
||||
@@ -62,6 +62,8 @@ const (
|
||||
EdgeUsedCards = "used_cards"
|
||||
// EdgeCashbackCards holds the string denoting the cashback_cards edge name in mutations.
|
||||
EdgeCashbackCards = "cashback_cards"
|
||||
// EdgeBalanceRecords holds the string denoting the balance_records edge name in mutations.
|
||||
EdgeBalanceRecords = "balance_records"
|
||||
// Table holds the table name of the sysuser in the database.
|
||||
Table = "sys_user"
|
||||
// ParentTable is the table that holds the parent relation/edge.
|
||||
@@ -147,6 +149,13 @@ const (
|
||||
CashbackCardsInverseTable = "sys_card"
|
||||
// CashbackCardsColumn is the table column denoting the cashback_cards relation/edge.
|
||||
CashbackCardsColumn = "cash_user_id"
|
||||
// BalanceRecordsTable is the table that holds the balance_records relation/edge.
|
||||
BalanceRecordsTable = "sys_balance_record"
|
||||
// BalanceRecordsInverseTable is the table name for the SysBalanceRecord entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "sysbalancerecord" package.
|
||||
BalanceRecordsInverseTable = "sys_balance_record"
|
||||
// BalanceRecordsColumn is the table column denoting the balance_records relation/edge.
|
||||
BalanceRecordsColumn = "user_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for sysuser fields.
|
||||
@@ -439,6 +448,20 @@ func ByCashbackCards(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
sqlgraph.OrderByNeighborTerms(s, newCashbackCardsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByBalanceRecordsCount orders the results by balance_records count.
|
||||
func ByBalanceRecordsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newBalanceRecordsStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByBalanceRecords orders the results by balance_records terms.
|
||||
func ByBalanceRecords(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newBalanceRecordsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
func newParentStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
@@ -530,3 +553,10 @@ func newCashbackCardsStep() *sqlgraph.Step {
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, CashbackCardsTable, CashbackCardsColumn),
|
||||
)
|
||||
}
|
||||
func newBalanceRecordsStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(BalanceRecordsInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, BalanceRecordsTable, BalanceRecordsColumn),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1054,6 +1054,35 @@ func HasCashbackCardsWith(preds ...predicate.SysCard) predicate.SysUser {
|
||||
})
|
||||
}
|
||||
|
||||
// HasBalanceRecords applies the HasEdge predicate on the "balance_records" edge.
|
||||
func HasBalanceRecords() predicate.SysUser {
|
||||
return predicate.SysUser(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, BalanceRecordsTable, BalanceRecordsColumn),
|
||||
)
|
||||
schemaConfig := internal.SchemaConfigFromContext(s.Context())
|
||||
step.To.Schema = schemaConfig.SysBalanceRecord
|
||||
step.Edge.Schema = schemaConfig.SysBalanceRecord
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasBalanceRecordsWith applies the HasEdge predicate on the "balance_records" edge with a given conditions (other predicates).
|
||||
func HasBalanceRecordsWith(preds ...predicate.SysBalanceRecord) predicate.SysUser {
|
||||
return predicate.SysUser(func(s *sql.Selector) {
|
||||
step := newBalanceRecordsStep()
|
||||
schemaConfig := internal.SchemaConfigFromContext(s.Context())
|
||||
step.To.Schema = schemaConfig.SysBalanceRecord
|
||||
step.Edge.Schema = schemaConfig.SysBalanceRecord
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.SysUser) predicate.SysUser {
|
||||
return predicate.SysUser(sql.AndPredicates(predicates...))
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"likedream-goframe/internal/ent/cptasklog"
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/ent/sysagent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysrole"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
@@ -335,6 +336,21 @@ func (_c *SysUserCreate) AddCashbackCards(v ...*SysCard) *SysUserCreate {
|
||||
return _c.AddCashbackCardIDs(ids...)
|
||||
}
|
||||
|
||||
// AddBalanceRecordIDs adds the "balance_records" edge to the SysBalanceRecord entity by IDs.
|
||||
func (_c *SysUserCreate) AddBalanceRecordIDs(ids ...int64) *SysUserCreate {
|
||||
_c.mutation.AddBalanceRecordIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddBalanceRecords adds the "balance_records" edges to the SysBalanceRecord entity.
|
||||
func (_c *SysUserCreate) AddBalanceRecords(v ...*SysBalanceRecord) *SysUserCreate {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddBalanceRecordIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the SysUserMutation object of the builder.
|
||||
func (_c *SysUserCreate) Mutation() *SysUserMutation {
|
||||
return _c.mutation
|
||||
@@ -735,6 +751,23 @@ func (_c *SysUserCreate) createSpec() (*SysUser, *sqlgraph.CreateSpec) {
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.BalanceRecordsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.BalanceRecordsTable,
|
||||
Columns: []string{sysuser.BalanceRecordsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _c.schemaConfig.SysBalanceRecord
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
|
||||
+158
-49
@@ -15,6 +15,7 @@ import (
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysagent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysrole"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
@@ -30,36 +31,38 @@ import (
|
||||
// SysUserQuery is the builder for querying SysUser entities.
|
||||
type SysUserQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []sysuser.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.SysUser
|
||||
withParent *SysUserQuery
|
||||
withChildren *SysUserQuery
|
||||
withRoles *SysRoleQuery
|
||||
withAgent *SysAgentQuery
|
||||
withImages *CpImageQuery
|
||||
withCpuser *CpUserQuery
|
||||
withCpTask *CpTaskQuery
|
||||
withCpLeave *CpLeaveQuery
|
||||
withCourseEntity *CourseEntityQuery
|
||||
withCpTaskLogs *CpTaskLogQuery
|
||||
withCreatedCards *SysCardQuery
|
||||
withUsedCards *SysCardQuery
|
||||
withCashbackCards *SysCardQuery
|
||||
withFKs bool
|
||||
modifiers []func(*sql.Selector)
|
||||
withNamedChildren map[string]*SysUserQuery
|
||||
withNamedRoles map[string]*SysRoleQuery
|
||||
withNamedImages map[string]*CpImageQuery
|
||||
withNamedCpuser map[string]*CpUserQuery
|
||||
withNamedCpTask map[string]*CpTaskQuery
|
||||
withNamedCpLeave map[string]*CpLeaveQuery
|
||||
withNamedCourseEntity map[string]*CourseEntityQuery
|
||||
withNamedCpTaskLogs map[string]*CpTaskLogQuery
|
||||
withNamedCreatedCards map[string]*SysCardQuery
|
||||
withNamedUsedCards map[string]*SysCardQuery
|
||||
withNamedCashbackCards map[string]*SysCardQuery
|
||||
ctx *QueryContext
|
||||
order []sysuser.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.SysUser
|
||||
withParent *SysUserQuery
|
||||
withChildren *SysUserQuery
|
||||
withRoles *SysRoleQuery
|
||||
withAgent *SysAgentQuery
|
||||
withImages *CpImageQuery
|
||||
withCpuser *CpUserQuery
|
||||
withCpTask *CpTaskQuery
|
||||
withCpLeave *CpLeaveQuery
|
||||
withCourseEntity *CourseEntityQuery
|
||||
withCpTaskLogs *CpTaskLogQuery
|
||||
withCreatedCards *SysCardQuery
|
||||
withUsedCards *SysCardQuery
|
||||
withCashbackCards *SysCardQuery
|
||||
withBalanceRecords *SysBalanceRecordQuery
|
||||
withFKs bool
|
||||
modifiers []func(*sql.Selector)
|
||||
withNamedChildren map[string]*SysUserQuery
|
||||
withNamedRoles map[string]*SysRoleQuery
|
||||
withNamedImages map[string]*CpImageQuery
|
||||
withNamedCpuser map[string]*CpUserQuery
|
||||
withNamedCpTask map[string]*CpTaskQuery
|
||||
withNamedCpLeave map[string]*CpLeaveQuery
|
||||
withNamedCourseEntity map[string]*CourseEntityQuery
|
||||
withNamedCpTaskLogs map[string]*CpTaskLogQuery
|
||||
withNamedCreatedCards map[string]*SysCardQuery
|
||||
withNamedUsedCards map[string]*SysCardQuery
|
||||
withNamedCashbackCards map[string]*SysCardQuery
|
||||
withNamedBalanceRecords map[string]*SysBalanceRecordQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
@@ -421,6 +424,31 @@ func (_q *SysUserQuery) QueryCashbackCards() *SysCardQuery {
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryBalanceRecords chains the current query on the "balance_records" edge.
|
||||
func (_q *SysUserQuery) QueryBalanceRecords() *SysBalanceRecordQuery {
|
||||
query := (&SysBalanceRecordClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(sysuser.Table, sysuser.FieldID, selector),
|
||||
sqlgraph.To(sysbalancerecord.Table, sysbalancerecord.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, sysuser.BalanceRecordsTable, sysuser.BalanceRecordsColumn),
|
||||
)
|
||||
schemaConfig := _q.schemaConfig
|
||||
step.To.Schema = schemaConfig.SysBalanceRecord
|
||||
step.Edge.Schema = schemaConfig.SysBalanceRecord
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first SysUser entity from the query.
|
||||
// Returns a *NotFoundError when no SysUser was found.
|
||||
func (_q *SysUserQuery) First(ctx context.Context) (*SysUser, error) {
|
||||
@@ -608,24 +636,25 @@ func (_q *SysUserQuery) Clone() *SysUserQuery {
|
||||
return nil
|
||||
}
|
||||
return &SysUserQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]sysuser.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.SysUser{}, _q.predicates...),
|
||||
withParent: _q.withParent.Clone(),
|
||||
withChildren: _q.withChildren.Clone(),
|
||||
withRoles: _q.withRoles.Clone(),
|
||||
withAgent: _q.withAgent.Clone(),
|
||||
withImages: _q.withImages.Clone(),
|
||||
withCpuser: _q.withCpuser.Clone(),
|
||||
withCpTask: _q.withCpTask.Clone(),
|
||||
withCpLeave: _q.withCpLeave.Clone(),
|
||||
withCourseEntity: _q.withCourseEntity.Clone(),
|
||||
withCpTaskLogs: _q.withCpTaskLogs.Clone(),
|
||||
withCreatedCards: _q.withCreatedCards.Clone(),
|
||||
withUsedCards: _q.withUsedCards.Clone(),
|
||||
withCashbackCards: _q.withCashbackCards.Clone(),
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]sysuser.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.SysUser{}, _q.predicates...),
|
||||
withParent: _q.withParent.Clone(),
|
||||
withChildren: _q.withChildren.Clone(),
|
||||
withRoles: _q.withRoles.Clone(),
|
||||
withAgent: _q.withAgent.Clone(),
|
||||
withImages: _q.withImages.Clone(),
|
||||
withCpuser: _q.withCpuser.Clone(),
|
||||
withCpTask: _q.withCpTask.Clone(),
|
||||
withCpLeave: _q.withCpLeave.Clone(),
|
||||
withCourseEntity: _q.withCourseEntity.Clone(),
|
||||
withCpTaskLogs: _q.withCpTaskLogs.Clone(),
|
||||
withCreatedCards: _q.withCreatedCards.Clone(),
|
||||
withUsedCards: _q.withUsedCards.Clone(),
|
||||
withCashbackCards: _q.withCashbackCards.Clone(),
|
||||
withBalanceRecords: _q.withBalanceRecords.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
@@ -776,6 +805,17 @@ func (_q *SysUserQuery) WithCashbackCards(opts ...func(*SysCardQuery)) *SysUserQ
|
||||
return _q
|
||||
}
|
||||
|
||||
// WithBalanceRecords tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "balance_records" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *SysUserQuery) WithBalanceRecords(opts ...func(*SysBalanceRecordQuery)) *SysUserQuery {
|
||||
query := (&SysBalanceRecordClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withBalanceRecords = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
@@ -855,7 +895,7 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
|
||||
nodes = []*SysUser{}
|
||||
withFKs = _q.withFKs
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [13]bool{
|
||||
loadedTypes = [14]bool{
|
||||
_q.withParent != nil,
|
||||
_q.withChildren != nil,
|
||||
_q.withRoles != nil,
|
||||
@@ -869,6 +909,7 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
|
||||
_q.withCreatedCards != nil,
|
||||
_q.withUsedCards != nil,
|
||||
_q.withCashbackCards != nil,
|
||||
_q.withBalanceRecords != nil,
|
||||
}
|
||||
)
|
||||
if _q.withParent != nil {
|
||||
@@ -1044,6 +1085,18 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := _q.withBalanceRecords; query != nil {
|
||||
if err := _q.loadBalanceRecords(ctx, query, nodes,
|
||||
func(n *SysUser) { n.Edges.BalanceRecords = []*SysBalanceRecord{} },
|
||||
func(n *SysUser, e *SysBalanceRecord) {
|
||||
n.Edges.BalanceRecords = append(n.Edges.BalanceRecords, e)
|
||||
if !e.Edges.loadedTypes[0] {
|
||||
e.Edges.User = n
|
||||
}
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
for name, query := range _q.withNamedChildren {
|
||||
if err := _q.loadChildren(ctx, query, nodes,
|
||||
func(n *SysUser) { n.appendNamedChildren(name) },
|
||||
@@ -1171,6 +1224,18 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
for name, query := range _q.withNamedBalanceRecords {
|
||||
if err := _q.loadBalanceRecords(ctx, query, nodes,
|
||||
func(n *SysUser) { n.appendNamedBalanceRecords(name) },
|
||||
func(n *SysUser, e *SysBalanceRecord) {
|
||||
n.appendNamedBalanceRecords(name, e)
|
||||
if !e.Edges.loadedTypes[0] {
|
||||
e.Edges.User = n
|
||||
}
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
@@ -1597,6 +1662,36 @@ func (_q *SysUserQuery) loadCashbackCards(ctx context.Context, query *SysCardQue
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (_q *SysUserQuery) loadBalanceRecords(ctx context.Context, query *SysBalanceRecordQuery, nodes []*SysUser, init func(*SysUser), assign func(*SysUser, *SysBalanceRecord)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int64]*SysUser)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
if len(query.ctx.Fields) > 0 {
|
||||
query.ctx.AppendFieldOnce(sysbalancerecord.FieldUserID)
|
||||
}
|
||||
query.Where(predicate.SysBalanceRecord(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(sysuser.BalanceRecordsColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.UserID
|
||||
node, ok := nodeids[fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "user_id" returned %v for node %v`, fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *SysUserQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
@@ -1876,6 +1971,20 @@ func (_q *SysUserQuery) WithNamedCashbackCards(name string, opts ...func(*SysCar
|
||||
return _q
|
||||
}
|
||||
|
||||
// WithNamedBalanceRecords tells the query-builder to eager-load the nodes that are connected to the "balance_records"
|
||||
// edge with the given name. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *SysUserQuery) WithNamedBalanceRecords(name string, opts ...func(*SysBalanceRecordQuery)) *SysUserQuery {
|
||||
query := (&SysBalanceRecordClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
if _q.withNamedBalanceRecords == nil {
|
||||
_q.withNamedBalanceRecords = make(map[string]*SysBalanceRecordQuery)
|
||||
}
|
||||
_q.withNamedBalanceRecords[name] = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// SysUserGroupBy is the group-by builder for SysUser entities.
|
||||
type SysUserGroupBy struct {
|
||||
selector
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysagent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysrole"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
@@ -367,6 +368,21 @@ func (_u *SysUserUpdate) AddCashbackCards(v ...*SysCard) *SysUserUpdate {
|
||||
return _u.AddCashbackCardIDs(ids...)
|
||||
}
|
||||
|
||||
// AddBalanceRecordIDs adds the "balance_records" edge to the SysBalanceRecord entity by IDs.
|
||||
func (_u *SysUserUpdate) AddBalanceRecordIDs(ids ...int64) *SysUserUpdate {
|
||||
_u.mutation.AddBalanceRecordIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddBalanceRecords adds the "balance_records" edges to the SysBalanceRecord entity.
|
||||
func (_u *SysUserUpdate) AddBalanceRecords(v ...*SysBalanceRecord) *SysUserUpdate {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddBalanceRecordIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the SysUserMutation object of the builder.
|
||||
func (_u *SysUserUpdate) Mutation() *SysUserMutation {
|
||||
return _u.mutation
|
||||
@@ -615,6 +631,27 @@ func (_u *SysUserUpdate) RemoveCashbackCards(v ...*SysCard) *SysUserUpdate {
|
||||
return _u.RemoveCashbackCardIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearBalanceRecords clears all "balance_records" edges to the SysBalanceRecord entity.
|
||||
func (_u *SysUserUpdate) ClearBalanceRecords() *SysUserUpdate {
|
||||
_u.mutation.ClearBalanceRecords()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveBalanceRecordIDs removes the "balance_records" edge to SysBalanceRecord entities by IDs.
|
||||
func (_u *SysUserUpdate) RemoveBalanceRecordIDs(ids ...int64) *SysUserUpdate {
|
||||
_u.mutation.RemoveBalanceRecordIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveBalanceRecords removes "balance_records" edges to SysBalanceRecord entities.
|
||||
func (_u *SysUserUpdate) RemoveBalanceRecords(v ...*SysBalanceRecord) *SysUserUpdate {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveBalanceRecordIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *SysUserUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
@@ -1290,6 +1327,54 @@ func (_u *SysUserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.BalanceRecordsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.BalanceRecordsTable,
|
||||
Columns: []string{sysuser.BalanceRecordsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedBalanceRecordsIDs(); len(nodes) > 0 && !_u.mutation.BalanceRecordsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.BalanceRecordsTable,
|
||||
Columns: []string{sysuser.BalanceRecordsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.BalanceRecordsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.BalanceRecordsTable,
|
||||
Columns: []string{sysuser.BalanceRecordsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_spec.Node.Schema = _u.schemaConfig.SysUser
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _u.schemaConfig)
|
||||
_spec.AddModifiers(_u.modifiers...)
|
||||
@@ -1641,6 +1726,21 @@ func (_u *SysUserUpdateOne) AddCashbackCards(v ...*SysCard) *SysUserUpdateOne {
|
||||
return _u.AddCashbackCardIDs(ids...)
|
||||
}
|
||||
|
||||
// AddBalanceRecordIDs adds the "balance_records" edge to the SysBalanceRecord entity by IDs.
|
||||
func (_u *SysUserUpdateOne) AddBalanceRecordIDs(ids ...int64) *SysUserUpdateOne {
|
||||
_u.mutation.AddBalanceRecordIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddBalanceRecords adds the "balance_records" edges to the SysBalanceRecord entity.
|
||||
func (_u *SysUserUpdateOne) AddBalanceRecords(v ...*SysBalanceRecord) *SysUserUpdateOne {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddBalanceRecordIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the SysUserMutation object of the builder.
|
||||
func (_u *SysUserUpdateOne) Mutation() *SysUserMutation {
|
||||
return _u.mutation
|
||||
@@ -1889,6 +1989,27 @@ func (_u *SysUserUpdateOne) RemoveCashbackCards(v ...*SysCard) *SysUserUpdateOne
|
||||
return _u.RemoveCashbackCardIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearBalanceRecords clears all "balance_records" edges to the SysBalanceRecord entity.
|
||||
func (_u *SysUserUpdateOne) ClearBalanceRecords() *SysUserUpdateOne {
|
||||
_u.mutation.ClearBalanceRecords()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveBalanceRecordIDs removes the "balance_records" edge to SysBalanceRecord entities by IDs.
|
||||
func (_u *SysUserUpdateOne) RemoveBalanceRecordIDs(ids ...int64) *SysUserUpdateOne {
|
||||
_u.mutation.RemoveBalanceRecordIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveBalanceRecords removes "balance_records" edges to SysBalanceRecord entities.
|
||||
func (_u *SysUserUpdateOne) RemoveBalanceRecords(v ...*SysBalanceRecord) *SysUserUpdateOne {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveBalanceRecordIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SysUserUpdate builder.
|
||||
func (_u *SysUserUpdateOne) Where(ps ...predicate.SysUser) *SysUserUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
@@ -2594,6 +2715,54 @@ func (_u *SysUserUpdateOne) sqlSave(ctx context.Context) (_node *SysUser, err er
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.BalanceRecordsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.BalanceRecordsTable,
|
||||
Columns: []string{sysuser.BalanceRecordsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedBalanceRecordsIDs(); len(nodes) > 0 && !_u.mutation.BalanceRecordsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.BalanceRecordsTable,
|
||||
Columns: []string{sysuser.BalanceRecordsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.BalanceRecordsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.BalanceRecordsTable,
|
||||
Columns: []string{sysuser.BalanceRecordsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_spec.Node.Schema = _u.schemaConfig.SysUser
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _u.schemaConfig)
|
||||
_spec.AddModifiers(_u.modifiers...)
|
||||
|
||||
@@ -30,6 +30,8 @@ type Tx struct {
|
||||
CpUser *CpUserClient
|
||||
// SysAgent is the client for interacting with the SysAgent builders.
|
||||
SysAgent *SysAgentClient
|
||||
// SysBalanceRecord is the client for interacting with the SysBalanceRecord builders.
|
||||
SysBalanceRecord *SysBalanceRecordClient
|
||||
// SysCard is the client for interacting with the SysCard builders.
|
||||
SysCard *SysCardClient
|
||||
// SysConfig is the client for interacting with the SysConfig builders.
|
||||
@@ -181,6 +183,7 @@ func (tx *Tx) init() {
|
||||
tx.CpTaskLog = NewCpTaskLogClient(tx.config)
|
||||
tx.CpUser = NewCpUserClient(tx.config)
|
||||
tx.SysAgent = NewSysAgentClient(tx.config)
|
||||
tx.SysBalanceRecord = NewSysBalanceRecordClient(tx.config)
|
||||
tx.SysCard = NewSysCardClient(tx.config)
|
||||
tx.SysConfig = NewSysConfigClient(tx.config)
|
||||
tx.SysMenu = NewSysMenuClient(tx.config)
|
||||
|
||||
@@ -90,10 +90,10 @@ func (s *AgentServiceV1) Recharge(ctx context.Context, req *v1.AgentRechargeReq)
|
||||
return utils.FailParam("非法的下级代理参数")
|
||||
}
|
||||
needBalance := utils.NeedBalance(parent.Edges.Agent.Rate, req.Amount, user.Edges.Agent.Rate)
|
||||
balance.BalanceService.ChangeUserBalance(ctx, parent.ID, needBalance.Neg())
|
||||
balance.BalanceService.ChangeUserBalance(ctx, parent.ID, needBalance.Neg(), "代理给下级充值")
|
||||
|
||||
}
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, req.Amount)
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, req.Amount, "代理充值")
|
||||
return utils.SuccessWithMsg("操作成功")
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ func (s *AgentServiceV1) AgentPutInfoReq(ctx context.Context, req *v1.AgentPutIn
|
||||
newBalance := utils.TransformBalance(oldBalance, req.Rate)
|
||||
// 6. 更新用户余额(如果更新了费率或者第一次改为代理)
|
||||
if user.Edges.Agent == nil || !user.Edges.Agent.Rate.Equal(req.Rate) {
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, newBalance.Sub(user.Balance))
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, newBalance.Sub(user.Balance), "代理费率调整")
|
||||
}
|
||||
utils.OkOrPanic(err, func(err error) error {
|
||||
return oops.
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package balance
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/common/db"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/utils"
|
||||
)
|
||||
|
||||
type BalanceRecordServiceV1 struct{}
|
||||
|
||||
func NewBalanceRecordServiceV1() *BalanceRecordServiceV1 {
|
||||
return &BalanceRecordServiceV1{}
|
||||
}
|
||||
|
||||
func (s *BalanceRecordServiceV1) List(ctx context.Context, req *v1.BalanceRecordListReq) *utils.Response[[]*ent.SysBalanceRecord] {
|
||||
user := utils.GetUserInfoFromCtx(ctx)
|
||||
|
||||
query := db.Global.SysBalanceRecord.Query().
|
||||
Where(sysbalancerecord.HasUserWith(sysuser.ID(user.ID))).
|
||||
Order(ent.Desc(sysbalancerecord.FieldCreateTime))
|
||||
|
||||
// 根据类型过滤
|
||||
if req.Type != "" {
|
||||
query.Where(sysbalancerecord.TypeEQ(sysbalancerecord.Type(req.Type)))
|
||||
}
|
||||
|
||||
// 查询总数
|
||||
total := query.CountX(ctx)
|
||||
var data []*ent.SysBalanceRecord
|
||||
if total > 0 {
|
||||
query.Limit(req.Size).Offset((req.Page - 1) * req.Size)
|
||||
data = query.AllX(ctx)
|
||||
}
|
||||
|
||||
return utils.SuccessWithTotal[[]*ent.SysBalanceRecord](data, total)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"likedream-goframe/internal/common/db"
|
||||
"likedream-goframe/internal/common/errors"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/utils"
|
||||
|
||||
@@ -16,7 +17,7 @@ var BalanceService = &BalanceServiceV1{}
|
||||
type BalanceServiceV1 struct {
|
||||
}
|
||||
|
||||
func (v *BalanceServiceV1) ChangeUserBalance(ctx context.Context, userId int64, balance decimal.Decimal) {
|
||||
func (v *BalanceServiceV1) ChangeUserBalance(ctx context.Context, userId int64, balance decimal.Decimal, reason string) {
|
||||
err := db.WithTx(ctx, func(c context.Context, tx *ent.Tx) {
|
||||
// 使用 SELECT ... FOR UPDATE 锁定用户记录
|
||||
user, err := tx.SysUser.Query().
|
||||
@@ -32,6 +33,28 @@ func (v *BalanceServiceV1) ChangeUserBalance(ctx context.Context, userId int64,
|
||||
utils.OkOrPanic(errors.NewBusinessError(400, "余额不足"))
|
||||
}
|
||||
|
||||
// 异步创建余额变动记录
|
||||
go func(userId int64, balanceChange decimal.Decimal, reason string, balanceBefore, balanceAfter decimal.Decimal) {
|
||||
recordCtx := context.Background()
|
||||
// 确定记录类型
|
||||
recordType := sysbalancerecord.TypeIncrease
|
||||
recordAmount := balanceChange
|
||||
if balanceChange.IsNegative() {
|
||||
recordType = sysbalancerecord.TypeDecrease
|
||||
recordAmount = balanceChange.Abs()
|
||||
}
|
||||
|
||||
// 创建余额变动记录
|
||||
db.Global.SysBalanceRecord.Create().
|
||||
SetUserID(userId).
|
||||
SetType(recordType).
|
||||
SetAmount(recordAmount).
|
||||
SetReason(reason).
|
||||
SetBalanceBefore(balanceBefore).
|
||||
SetBalanceAfter(balanceAfter).
|
||||
Save(recordCtx)
|
||||
}(userId, balance, reason, user.Balance, newBalance)
|
||||
|
||||
// 更新余额
|
||||
tx.SysUser.Update().
|
||||
Where(sysuser.ID(userId)).
|
||||
|
||||
@@ -54,7 +54,7 @@ func (v CardServiceV1) Add(ctx context.Context, req *v1.CardAddReq) *utils.Respo
|
||||
// 消费积分
|
||||
consumeBalance := decimal.Zero.Sub(utils.ConsumeBalance(user.Edges.Agent.Rate, pointTotal))
|
||||
// 扣除余额
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, consumeBalance)
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, consumeBalance, "生成卡密")
|
||||
// 添加卡密
|
||||
var cards []*ent.SysCardCreate
|
||||
for range req.Length {
|
||||
|
||||
@@ -127,7 +127,7 @@ func (v CpLeaveServiceV1) Report(ctx context.Context, req *v1.CpLeaveReportReq)
|
||||
}
|
||||
|
||||
// 先扣款
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, basePoint.Neg())
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, basePoint.Neg(), "销假")
|
||||
|
||||
// 创建销假记录
|
||||
leaveRecord := db2.Global.CpLeave.Create().
|
||||
@@ -144,7 +144,7 @@ func (v CpLeaveServiceV1) Report(ctx context.Context, req *v1.CpLeaveReportReq)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
// 如果业务执行失败,退回扣款
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, basePoint)
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, basePoint, "销假失败退款")
|
||||
// 更新记录状态为失败,并记录失败原因
|
||||
desc := fmt.Sprintf("销假失败: %v", r)
|
||||
db2.Global.CpLeave.UpdateOne(leaveRecord).
|
||||
|
||||
@@ -186,7 +186,7 @@ func (v CpTaskServiceV1) PostExecute(ctx context.Context, req *v1.PostCpTaskExec
|
||||
basePoint = basePoint.Mul(user.Edges.Agent.Rate)
|
||||
}
|
||||
needPoint := basePoint.Mul(decimal.NewFromInt(int64(consume)))
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, needPoint.Neg())
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, needPoint.Neg(), "今日校园任务")
|
||||
// 更新任务
|
||||
e := db2.WithTx(ctx, func(ctx context.Context, tx *ent.Tx) {
|
||||
update := db2.Global.CpTask.UpdateOne(cpTask).
|
||||
|
||||
@@ -2,6 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"likedream-goframe/internal/service/agent"
|
||||
"likedream-goframe/internal/service/balance"
|
||||
"likedream-goframe/internal/service/card"
|
||||
"likedream-goframe/internal/service/config"
|
||||
"likedream-goframe/internal/service/course"
|
||||
@@ -29,6 +30,7 @@ type globalService struct {
|
||||
Card *card.CardServiceV1
|
||||
Course *course.CourseServiceV1
|
||||
Config *config.ConfigServiceV1
|
||||
Balance *balance.BalanceRecordServiceV1
|
||||
}
|
||||
|
||||
var Global = globalService{
|
||||
@@ -47,4 +49,5 @@ var Global = globalService{
|
||||
Card: card.NewCardServiceV1(),
|
||||
Course: course.NewCourseServiceV1(),
|
||||
Config: config.NewV1(),
|
||||
Balance: balance.NewBalanceRecordServiceV1(),
|
||||
}
|
||||
|
||||
@@ -152,9 +152,9 @@ func (s *UserInfoServiceV1) CardRecharge(ctx context.Context, req *v1.CardRechar
|
||||
tx.SysCard.UpdateOneID(card.ID).SetStatus(syscard.StatusUsed).SetUsedID(user.ID).ExecX(ctx)
|
||||
}
|
||||
err = tx.Commit()
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, decimal.NewFromUint64(card.Value))
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, decimal.NewFromUint64(card.Value), "卡密充值")
|
||||
if parent != nil {
|
||||
balance.BalanceService.ChangeUserBalance(ctx, parent.ID, cashbackValue)
|
||||
balance.BalanceService.ChangeUserBalance(ctx, parent.ID, cashbackValue, "邀请返现")
|
||||
}
|
||||
utils.OkOrPanic(err, func(err error) error {
|
||||
return oops.
|
||||
@@ -366,14 +366,14 @@ func (s *UserInfoServiceV1) BalanceMigrate(ctx context.Context, req *v1.BalanceM
|
||||
}
|
||||
// 缩小5倍,新系统按1:1比例的 老系统是1:5
|
||||
b = b.Div(decimal.NewFromInt32(5))
|
||||
balance.BalanceService.ChangeUserBalance(ctx, newUser.ID, b)
|
||||
balance.BalanceService.ChangeUserBalance(ctx, newUser.ID, b, "积分迁移")
|
||||
|
||||
// 清空旧系统积分
|
||||
err = db.GlobalGorm.Table("AspNetUsers").Where("email = ?", oldSystemEmail).Update("balance", 0).Error
|
||||
if err != nil {
|
||||
// 旧系统更新失败,记录日志但不影响返回结果(因为新系统已经转移成功)
|
||||
// 回滚
|
||||
balance.BalanceService.ChangeUserBalance(ctx, newUser.ID, b.Neg())
|
||||
balance.BalanceService.ChangeUserBalance(ctx, newUser.ID, b.Neg(), "积分迁移失败回滚")
|
||||
// 这里可以考虑回滚新系统的操作,但为了简化流程暂时保留新系统的更新
|
||||
return utils.FailBusiness("旧系统积分清空失败,请联系管理员")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user