:sparkles:cp_school & 登录对接

This commit is contained in:
sugarBecomer
2025-10-26 18:47:13 +08:00
parent 78c934f131
commit dfb914dd31
42 changed files with 3896 additions and 231 deletions
+1
View File
@@ -48,6 +48,7 @@ func StartServer(ctx context.Context) {
// 今日校园
cpdailyGroup := group.Group("/cpdaily").Middleware(middleware.AuthHandler, middleware.PermissionHandler)
cpdailyGroup.Bind(cpdaily.NewCpUserCtrlV1())
cpdailyGroup.Bind(cpdaily.NewCpTaskCtrlV1())
})
s.SetPort(port.Int())
+48
View File
@@ -0,0 +1,48 @@
package v1
import "github.com/gogf/gf/v2/frame/g"
type GetRecentTasksReq struct {
g.Meta `path:"/task/recent" method:"get" tags:"CpTask" summary:"获取最近任务"`
UserId int64 `json:"userId"`
Type string `json:"type"`
}
type AddTaskReq struct {
g.Meta `path:"/task" method:"post" tags:"CpTask" summary:"添加任务"`
UserId int64 `json:"userId"`
Type string `json:"type"`
Title string `json:"title"`
}
type CpTaskListReq struct {
g.Meta `path:"/task" method:"get" tags:"CpTask" summary:"获取cp任务列表"`
Title string `json:"title"`
Username string `json:"username"`
Page int `json:"page" d:"1"`
Size int `json:"size" d:"10"`
}
type GetCpTaskFormReq struct {
g.Meta `path:"/task" method:"get" tags:"CpTask" summary:"获取任务表单"`
Id int64 `json:"id"`
}
type UpdateCpTaskFormReq struct {
g.Meta `path:"/task" method:"put" tags:"CpTask" summary:"更新任务表单"`
Id int64 `json:"id"`
}
type GetCoTaskExecuteReq struct {
g.Meta `path:"/task/execute" method:"get" tags:"CpTask" summary:"执行任务参数"`
Id int64 `json:"id"`
}
type UpdateCpTaskExecuteReq struct {
g.Meta `path:"/task/execute" method:"put" tags:"CpTask" summary:"更新执行任务参数"`
Id int64 `json:"id"`
}
type DeleteTaskReq struct {
g.Meta `path:"/task" method:"delete" tags:"CpTask" summary:"删除任务"`
Id int64 `json:"id"`
}
+31
View File
@@ -0,0 +1,31 @@
package task
import (
"context"
"likedream-goframe/internal/application/cookiejar"
"likedream-goframe/internal/application/cpdaily/school"
"likedream-goframe/internal/application/httpclient"
errors2 "likedream-goframe/internal/common/errors"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/utils"
)
func GetCpdailyTaskService(ctx context.Context, Type string, cookie string, schoolId string) CpdailyTask {
detail := school.GetSchoolDetail(ctx, schoolId)
cookieJar := cookiejar.NewPersistCookieJar()
cookieJar.Deserialize(cookie)
client := httpclient.Cpdaily.Clone(ctx)
client.SetCookieJar(cookieJar)
//todo 验证cookie是否有效
switch cptask.TaskType(Type) {
case cptask.TaskTypeCollection:
return NewCollectionTask(client, detail.WecloudUrl)
case cptask.TaskTypeSign:
return NewAutoSignTask(client, detail.WecloudUrl)
case cptask.TaskTypeSleepCheck:
return NewSleepCheckTask(client, detail.WecloudUrl)
default:
utils.OkOrPanic(errors2.NewBusinessError(400, "不支持的任务类型"))
}
return nil
}
@@ -0,0 +1,31 @@
package cpdaily
import (
"context"
v1 "likedream-goframe/internal/api/v1"
"likedream-goframe/internal/ent"
"likedream-goframe/internal/service"
"likedream-goframe/internal/utils"
)
type CpTaskServiceV1 struct {
}
func (c CpTaskServiceV1) List(ctx context.Context, req *v1.CpTaskListReq) (res *utils.Response[[]*ent.CpTask], err error) {
defer utils.Pass(&err)
return service.Global.CpTask.List(ctx, req), nil
}
func (c CpTaskServiceV1) GetRecentTasks(ctx context.Context, req *v1.GetRecentTasksReq) (res *utils.Response[[]string], err error) {
defer utils.Pass(&err)
return service.Global.CpTask.GetRecentTasks(ctx, req), nil
}
func (c CpTaskServiceV1) AddTask(ctx context.Context, req *v1.AddTaskReq) (res *utils.Response[any], err error) {
defer utils.Pass(&err)
return service.Global.CpTask.AddTask(ctx, req), nil
}
func NewCpTaskCtrlV1() ICpTaskCtrlV1 {
return &CpTaskServiceV1{}
}
@@ -0,0 +1,15 @@
package cpdaily
import (
"context"
v1 "likedream-goframe/internal/api/v1"
"likedream-goframe/internal/ent"
"likedream-goframe/internal/utils"
)
type ICpTaskCtrlV1 interface {
GetRecentTasks(ctx context.Context, req *v1.GetRecentTasksReq) (*utils.Response[[]string], error)
AddTask(ctx context.Context, req *v1.AddTaskReq) (res *utils.Response[any], err error)
List(ctx context.Context, req *v1.CpTaskListReq) (res *utils.Response[[]*ent.CpTask], err error)
TaskFormData(ctx context.Context, req *v1.TaskFormDataReq) (res *utils.Response[any], err error)
}
+5 -4
View File
@@ -2,14 +2,15 @@ package db
import (
"context"
_ "github.com/go-sql-driver/mysql"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"go.uber.org/zap"
"likedream-goframe/internal/cst"
"likedream-goframe/internal/ent"
"likedream-goframe/internal/framework/logger"
"likedream-goframe/internal/utils"
_ "github.com/go-sql-driver/mysql"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"go.uber.org/zap"
)
var Global *ent.Client
+68 -4
View File
@@ -499,7 +499,7 @@ func (c *CpSchoolClient) UpdateOne(_m *CpSchool) *CpSchoolUpdateOne {
}
// UpdateOneID returns an update builder for the given id.
func (c *CpSchoolClient) UpdateOneID(id int64) *CpSchoolUpdateOne {
func (c *CpSchoolClient) UpdateOneID(id string) *CpSchoolUpdateOne {
mutation := newCpSchoolMutation(c.config, OpUpdateOne, withCpSchoolID(id))
return &CpSchoolUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
@@ -516,7 +516,7 @@ func (c *CpSchoolClient) DeleteOne(_m *CpSchool) *CpSchoolDeleteOne {
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *CpSchoolClient) DeleteOneID(id int64) *CpSchoolDeleteOne {
func (c *CpSchoolClient) DeleteOneID(id string) *CpSchoolDeleteOne {
builder := c.Delete().Where(cpschool.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
@@ -533,12 +533,12 @@ func (c *CpSchoolClient) Query() *CpSchoolQuery {
}
// Get returns a CpSchool entity by its id.
func (c *CpSchoolClient) Get(ctx context.Context, id int64) (*CpSchool, error) {
func (c *CpSchoolClient) Get(ctx context.Context, id string) (*CpSchool, error) {
return c.Query().Where(cpschool.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *CpSchoolClient) GetX(ctx context.Context, id int64) *CpSchool {
func (c *CpSchoolClient) GetX(ctx context.Context, id string) *CpSchool {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
@@ -546,6 +546,22 @@ func (c *CpSchoolClient) GetX(ctx context.Context, id int64) *CpSchool {
return obj
}
// QueryCpusers queries the cpusers edge of a CpSchool.
func (c *CpSchoolClient) QueryCpusers(_m *CpSchool) *CpUserQuery {
query := (&CpUserClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(cpschool.Table, cpschool.FieldID, id),
sqlgraph.To(cpuser.Table, cpuser.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, cpschool.CpusersTable, cpschool.CpusersColumn),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *CpSchoolClient) Hooks() []Hook {
return c.hooks.CpSchool
@@ -695,6 +711,22 @@ func (c *CpTaskClient) QueryCpUser(_m *CpTask) *CpUserQuery {
return query
}
// QuerySysUser queries the sys_user edge of a CpTask.
func (c *CpTaskClient) QuerySysUser(_m *CpTask) *SysUserQuery {
query := (&SysUserClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(cptask.Table, cptask.FieldID, id),
sqlgraph.To(sysuser.Table, sysuser.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, cptask.SysUserTable, cptask.SysUserColumn),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryCpTaskLogs queries the cp_task_logs edge of a CpTask.
func (c *CpTaskClient) QueryCpTaskLogs(_m *CpTask) *CpTaskLogQuery {
query := (&CpTaskLogClient{config: c.config}).Query()
@@ -1073,6 +1105,22 @@ func (c *CpUserClient) QueryCpTaskLogs(_m *CpUser) *CpTaskLogQuery {
return query
}
// QuerySchool queries the school edge of a CpUser.
func (c *CpUserClient) QuerySchool(_m *CpUser) *CpSchoolQuery {
query := (&CpSchoolClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(cpuser.Table, cpuser.FieldID, id),
sqlgraph.To(cpschool.Table, cpschool.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, cpuser.SchoolTable, cpuser.SchoolColumn),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *CpUserClient) Hooks() []Hook {
return c.hooks.CpUser
@@ -1982,6 +2030,22 @@ func (c *SysUserClient) QueryCpuser(_m *SysUser) *CpUserQuery {
return query
}
// QueryCpTask queries the cp_task edge of a SysUser.
func (c *SysUserClient) QueryCpTask(_m *SysUser) *CpTaskQuery {
query := (&CpTaskClient{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(cptask.Table, cptask.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, sysuser.CpTaskTable, sysuser.CpTaskColumn),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryCpTaskLogs queries the cp_task_logs edge of a SysUser.
func (c *SysUserClient) QueryCpTaskLogs(_m *SysUser) *CpTaskLogQuery {
query := (&CpTaskLogClient{config: c.config}).Query()
+149
View File
@@ -0,0 +1,149 @@
// ENT数据库文件,请勿编辑。
package ent
import (
"fmt"
"likedream-goframe/internal/ent/cpschool"
"strings"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
// CpSchool is the model entity for the CpSchool schema.
type CpSchool struct {
config `json:"-"`
// ID of the ent.
ID string `json:"id,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// NamePinyin holds the value of the "name_pinyin" field.
NamePinyin string `json:"name_pinyin,omitempty"`
// IconImg holds the value of the "icon_img" field.
IconImg string `json:"icon_img,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the CpSchoolQuery when eager-loading is set.
Edges CpSchoolEdges `json:"edges"`
selectValues sql.SelectValues
}
// CpSchoolEdges holds the relations/edges for other nodes in the graph.
type CpSchoolEdges struct {
// Cpusers holds the value of the cpusers edge.
Cpusers []*CpUser `json:"cpusers,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// CpusersOrErr returns the Cpusers value or an error if the edge
// was not loaded in eager-loading.
func (e CpSchoolEdges) CpusersOrErr() ([]*CpUser, error) {
if e.loadedTypes[0] {
return e.Cpusers, nil
}
return nil, &NotLoadedError{edge: "cpusers"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*CpSchool) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case cpschool.FieldID, cpschool.FieldName, cpschool.FieldNamePinyin, cpschool.FieldIconImg:
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 CpSchool fields.
func (_m *CpSchool) 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 cpschool.FieldID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value.Valid {
_m.ID = value.String
}
case cpschool.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
_m.Name = value.String
}
case cpschool.FieldNamePinyin:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name_pinyin", values[i])
} else if value.Valid {
_m.NamePinyin = value.String
}
case cpschool.FieldIconImg:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field icon_img", values[i])
} else if value.Valid {
_m.IconImg = value.String
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the CpSchool.
// This includes values selected through modifiers, order, etc.
func (_m *CpSchool) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryCpusers queries the "cpusers" edge of the CpSchool entity.
func (_m *CpSchool) QueryCpusers() *CpUserQuery {
return NewCpSchoolClient(_m.config).QueryCpusers(_m)
}
// Update returns a builder for updating this CpSchool.
// Note that you need to call CpSchool.Unwrap() before calling this method if this CpSchool
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *CpSchool) Update() *CpSchoolUpdateOne {
return NewCpSchoolClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the CpSchool 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 *CpSchool) Unwrap() *CpSchool {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: CpSchool is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *CpSchool) String() string {
var builder strings.Builder
builder.WriteString("CpSchool(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("name=")
builder.WriteString(_m.Name)
builder.WriteString(", ")
builder.WriteString("name_pinyin=")
builder.WriteString(_m.NamePinyin)
builder.WriteString(", ")
builder.WriteString("icon_img=")
builder.WriteString(_m.IconImg)
builder.WriteByte(')')
return builder.String()
}
// CpSchools is a parsable slice of CpSchool.
type CpSchools []*CpSchool
+94
View File
@@ -0,0 +1,94 @@
// ENT数据库文件,请勿编辑。
package cpschool
import (
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const (
// Label holds the string label denoting the cpschool type in the database.
Label = "cp_school"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// FieldNamePinyin holds the string denoting the name_pinyin field in the database.
FieldNamePinyin = "name_pinyin"
// FieldIconImg holds the string denoting the icon_img field in the database.
FieldIconImg = "icon_img"
// EdgeCpusers holds the string denoting the cpusers edge name in mutations.
EdgeCpusers = "cpusers"
// Table holds the table name of the cpschool in the database.
Table = "cp_schools"
// CpusersTable is the table that holds the cpusers relation/edge.
CpusersTable = "cp_users"
// CpusersInverseTable is the table name for the CpUser entity.
// It exists in this package in order to avoid circular dependency with the "cpuser" package.
CpusersInverseTable = "cp_users"
// CpusersColumn is the table column denoting the cpusers relation/edge.
CpusersColumn = "school_id"
)
// Columns holds all SQL columns for cpschool fields.
var Columns = []string{
FieldID,
FieldName,
FieldNamePinyin,
FieldIconImg,
}
// 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
}
// OrderOption defines the ordering options for the CpSchool 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()
}
// ByName orders the results by the name field.
func ByName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldName, opts...).ToFunc()
}
// ByNamePinyin orders the results by the name_pinyin field.
func ByNamePinyin(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldNamePinyin, opts...).ToFunc()
}
// ByIconImg orders the results by the icon_img field.
func ByIconImg(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldIconImg, opts...).ToFunc()
}
// ByCpusersCount orders the results by cpusers count.
func ByCpusersCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newCpusersStep(), opts...)
}
}
// ByCpusers orders the results by cpusers terms.
func ByCpusers(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newCpusersStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
func newCpusersStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(CpusersInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, CpusersTable, CpusersColumn),
)
}
+323
View File
@@ -0,0 +1,323 @@
// ENT数据库文件,请勿编辑。
package cpschool
import (
"likedream-goframe/internal/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
// ID filters vertices based on their ID field.
func ID(id string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldLTE(FieldID, id))
}
// IDEqualFold applies the EqualFold predicate on the ID field.
func IDEqualFold(id string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldEqualFold(FieldID, id))
}
// IDContainsFold applies the ContainsFold predicate on the ID field.
func IDContainsFold(id string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldContainsFold(FieldID, id))
}
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
func Name(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldEQ(FieldName, v))
}
// NamePinyin applies equality check predicate on the "name_pinyin" field. It's identical to NamePinyinEQ.
func NamePinyin(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldEQ(FieldNamePinyin, v))
}
// IconImg applies equality check predicate on the "icon_img" field. It's identical to IconImgEQ.
func IconImg(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldEQ(FieldIconImg, v))
}
// NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldEQ(FieldName, v))
}
// NameNEQ applies the NEQ predicate on the "name" field.
func NameNEQ(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldNEQ(FieldName, v))
}
// NameIn applies the In predicate on the "name" field.
func NameIn(vs ...string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldIn(FieldName, vs...))
}
// NameNotIn applies the NotIn predicate on the "name" field.
func NameNotIn(vs ...string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldNotIn(FieldName, vs...))
}
// NameGT applies the GT predicate on the "name" field.
func NameGT(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldGT(FieldName, v))
}
// NameGTE applies the GTE predicate on the "name" field.
func NameGTE(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldGTE(FieldName, v))
}
// NameLT applies the LT predicate on the "name" field.
func NameLT(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldLT(FieldName, v))
}
// NameLTE applies the LTE predicate on the "name" field.
func NameLTE(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldLTE(FieldName, v))
}
// NameContains applies the Contains predicate on the "name" field.
func NameContains(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldContains(FieldName, v))
}
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
func NameHasPrefix(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldHasPrefix(FieldName, v))
}
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
func NameHasSuffix(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldHasSuffix(FieldName, v))
}
// NameEqualFold applies the EqualFold predicate on the "name" field.
func NameEqualFold(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldEqualFold(FieldName, v))
}
// NameContainsFold applies the ContainsFold predicate on the "name" field.
func NameContainsFold(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldContainsFold(FieldName, v))
}
// NamePinyinEQ applies the EQ predicate on the "name_pinyin" field.
func NamePinyinEQ(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldEQ(FieldNamePinyin, v))
}
// NamePinyinNEQ applies the NEQ predicate on the "name_pinyin" field.
func NamePinyinNEQ(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldNEQ(FieldNamePinyin, v))
}
// NamePinyinIn applies the In predicate on the "name_pinyin" field.
func NamePinyinIn(vs ...string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldIn(FieldNamePinyin, vs...))
}
// NamePinyinNotIn applies the NotIn predicate on the "name_pinyin" field.
func NamePinyinNotIn(vs ...string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldNotIn(FieldNamePinyin, vs...))
}
// NamePinyinGT applies the GT predicate on the "name_pinyin" field.
func NamePinyinGT(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldGT(FieldNamePinyin, v))
}
// NamePinyinGTE applies the GTE predicate on the "name_pinyin" field.
func NamePinyinGTE(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldGTE(FieldNamePinyin, v))
}
// NamePinyinLT applies the LT predicate on the "name_pinyin" field.
func NamePinyinLT(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldLT(FieldNamePinyin, v))
}
// NamePinyinLTE applies the LTE predicate on the "name_pinyin" field.
func NamePinyinLTE(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldLTE(FieldNamePinyin, v))
}
// NamePinyinContains applies the Contains predicate on the "name_pinyin" field.
func NamePinyinContains(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldContains(FieldNamePinyin, v))
}
// NamePinyinHasPrefix applies the HasPrefix predicate on the "name_pinyin" field.
func NamePinyinHasPrefix(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldHasPrefix(FieldNamePinyin, v))
}
// NamePinyinHasSuffix applies the HasSuffix predicate on the "name_pinyin" field.
func NamePinyinHasSuffix(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldHasSuffix(FieldNamePinyin, v))
}
// NamePinyinEqualFold applies the EqualFold predicate on the "name_pinyin" field.
func NamePinyinEqualFold(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldEqualFold(FieldNamePinyin, v))
}
// NamePinyinContainsFold applies the ContainsFold predicate on the "name_pinyin" field.
func NamePinyinContainsFold(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldContainsFold(FieldNamePinyin, v))
}
// IconImgEQ applies the EQ predicate on the "icon_img" field.
func IconImgEQ(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldEQ(FieldIconImg, v))
}
// IconImgNEQ applies the NEQ predicate on the "icon_img" field.
func IconImgNEQ(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldNEQ(FieldIconImg, v))
}
// IconImgIn applies the In predicate on the "icon_img" field.
func IconImgIn(vs ...string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldIn(FieldIconImg, vs...))
}
// IconImgNotIn applies the NotIn predicate on the "icon_img" field.
func IconImgNotIn(vs ...string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldNotIn(FieldIconImg, vs...))
}
// IconImgGT applies the GT predicate on the "icon_img" field.
func IconImgGT(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldGT(FieldIconImg, v))
}
// IconImgGTE applies the GTE predicate on the "icon_img" field.
func IconImgGTE(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldGTE(FieldIconImg, v))
}
// IconImgLT applies the LT predicate on the "icon_img" field.
func IconImgLT(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldLT(FieldIconImg, v))
}
// IconImgLTE applies the LTE predicate on the "icon_img" field.
func IconImgLTE(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldLTE(FieldIconImg, v))
}
// IconImgContains applies the Contains predicate on the "icon_img" field.
func IconImgContains(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldContains(FieldIconImg, v))
}
// IconImgHasPrefix applies the HasPrefix predicate on the "icon_img" field.
func IconImgHasPrefix(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldHasPrefix(FieldIconImg, v))
}
// IconImgHasSuffix applies the HasSuffix predicate on the "icon_img" field.
func IconImgHasSuffix(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldHasSuffix(FieldIconImg, v))
}
// IconImgIsNil applies the IsNil predicate on the "icon_img" field.
func IconImgIsNil() predicate.CpSchool {
return predicate.CpSchool(sql.FieldIsNull(FieldIconImg))
}
// IconImgNotNil applies the NotNil predicate on the "icon_img" field.
func IconImgNotNil() predicate.CpSchool {
return predicate.CpSchool(sql.FieldNotNull(FieldIconImg))
}
// IconImgEqualFold applies the EqualFold predicate on the "icon_img" field.
func IconImgEqualFold(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldEqualFold(FieldIconImg, v))
}
// IconImgContainsFold applies the ContainsFold predicate on the "icon_img" field.
func IconImgContainsFold(v string) predicate.CpSchool {
return predicate.CpSchool(sql.FieldContainsFold(FieldIconImg, v))
}
// HasCpusers applies the HasEdge predicate on the "cpusers" edge.
func HasCpusers() predicate.CpSchool {
return predicate.CpSchool(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, CpusersTable, CpusersColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasCpusersWith applies the HasEdge predicate on the "cpusers" edge with a given conditions (other predicates).
func HasCpusersWith(preds ...predicate.CpUser) predicate.CpSchool {
return predicate.CpSchool(func(s *sql.Selector) {
step := newCpusersStep()
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.CpSchool) predicate.CpSchool {
return predicate.CpSchool(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.CpSchool) predicate.CpSchool {
return predicate.CpSchool(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.CpSchool) predicate.CpSchool {
return predicate.CpSchool(sql.NotPredicates(p))
}
+652
View File
@@ -0,0 +1,652 @@
// ENT数据库文件,请勿编辑。
package ent
import (
"context"
"errors"
"fmt"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/cpuser"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// CpSchoolCreate is the builder for creating a CpSchool entity.
type CpSchoolCreate struct {
config
mutation *CpSchoolMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetName sets the "name" field.
func (_c *CpSchoolCreate) SetName(v string) *CpSchoolCreate {
_c.mutation.SetName(v)
return _c
}
// SetNamePinyin sets the "name_pinyin" field.
func (_c *CpSchoolCreate) SetNamePinyin(v string) *CpSchoolCreate {
_c.mutation.SetNamePinyin(v)
return _c
}
// SetIconImg sets the "icon_img" field.
func (_c *CpSchoolCreate) SetIconImg(v string) *CpSchoolCreate {
_c.mutation.SetIconImg(v)
return _c
}
// SetNillableIconImg sets the "icon_img" field if the given value is not nil.
func (_c *CpSchoolCreate) SetNillableIconImg(v *string) *CpSchoolCreate {
if v != nil {
_c.SetIconImg(*v)
}
return _c
}
// SetID sets the "id" field.
func (_c *CpSchoolCreate) SetID(v string) *CpSchoolCreate {
_c.mutation.SetID(v)
return _c
}
// AddCpuserIDs adds the "cpusers" edge to the CpUser entity by IDs.
func (_c *CpSchoolCreate) AddCpuserIDs(ids ...int64) *CpSchoolCreate {
_c.mutation.AddCpuserIDs(ids...)
return _c
}
// AddCpusers adds the "cpusers" edges to the CpUser entity.
func (_c *CpSchoolCreate) AddCpusers(v ...*CpUser) *CpSchoolCreate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddCpuserIDs(ids...)
}
// Mutation returns the CpSchoolMutation object of the builder.
func (_c *CpSchoolCreate) Mutation() *CpSchoolMutation {
return _c.mutation
}
// Save creates the CpSchool in the database.
func (_c *CpSchoolCreate) Save(ctx context.Context) (*CpSchool, error) {
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *CpSchoolCreate) SaveX(ctx context.Context) *CpSchool {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *CpSchoolCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *CpSchoolCreate) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *CpSchoolCreate) check() error {
if _, ok := _c.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "CpSchool.name"`)}
}
if _, ok := _c.mutation.NamePinyin(); !ok {
return &ValidationError{Name: "name_pinyin", err: errors.New(`ent: missing required field "CpSchool.name_pinyin"`)}
}
return nil
}
func (_c *CpSchoolCreate) sqlSave(ctx context.Context) (*CpSchool, 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
}
if _spec.ID.Value != nil {
if id, ok := _spec.ID.Value.(string); ok {
_node.ID = id
} else {
return nil, fmt.Errorf("unexpected CpSchool.ID type: %T", _spec.ID.Value)
}
}
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
func (_c *CpSchoolCreate) createSpec() (*CpSchool, *sqlgraph.CreateSpec) {
var (
_node = &CpSchool{config: _c.config}
_spec = sqlgraph.NewCreateSpec(cpschool.Table, sqlgraph.NewFieldSpec(cpschool.FieldID, field.TypeString))
)
_spec.OnConflict = _c.conflict
if id, ok := _c.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = id
}
if value, ok := _c.mutation.Name(); ok {
_spec.SetField(cpschool.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := _c.mutation.NamePinyin(); ok {
_spec.SetField(cpschool.FieldNamePinyin, field.TypeString, value)
_node.NamePinyin = value
}
if value, ok := _c.mutation.IconImg(); ok {
_spec.SetField(cpschool.FieldIconImg, field.TypeString, value)
_node.IconImg = value
}
if nodes := _c.mutation.CpusersIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpschool.CpusersTable,
Columns: []string{cpschool.CpusersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_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.CpSchool.Create().
// SetName(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.CpSchoolUpsert) {
// SetName(v+v).
// }).
// Exec(ctx)
func (_c *CpSchoolCreate) OnConflict(opts ...sql.ConflictOption) *CpSchoolUpsertOne {
_c.conflict = opts
return &CpSchoolUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.CpSchool.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *CpSchoolCreate) OnConflictColumns(columns ...string) *CpSchoolUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &CpSchoolUpsertOne{
create: _c,
}
}
type (
// CpSchoolUpsertOne is the builder for "upsert"-ing
// one CpSchool node.
CpSchoolUpsertOne struct {
create *CpSchoolCreate
}
// CpSchoolUpsert is the "OnConflict" setter.
CpSchoolUpsert struct {
*sql.UpdateSet
}
)
// SetName sets the "name" field.
func (u *CpSchoolUpsert) SetName(v string) *CpSchoolUpsert {
u.Set(cpschool.FieldName, v)
return u
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *CpSchoolUpsert) UpdateName() *CpSchoolUpsert {
u.SetExcluded(cpschool.FieldName)
return u
}
// SetNamePinyin sets the "name_pinyin" field.
func (u *CpSchoolUpsert) SetNamePinyin(v string) *CpSchoolUpsert {
u.Set(cpschool.FieldNamePinyin, v)
return u
}
// UpdateNamePinyin sets the "name_pinyin" field to the value that was provided on create.
func (u *CpSchoolUpsert) UpdateNamePinyin() *CpSchoolUpsert {
u.SetExcluded(cpschool.FieldNamePinyin)
return u
}
// SetIconImg sets the "icon_img" field.
func (u *CpSchoolUpsert) SetIconImg(v string) *CpSchoolUpsert {
u.Set(cpschool.FieldIconImg, v)
return u
}
// UpdateIconImg sets the "icon_img" field to the value that was provided on create.
func (u *CpSchoolUpsert) UpdateIconImg() *CpSchoolUpsert {
u.SetExcluded(cpschool.FieldIconImg)
return u
}
// ClearIconImg clears the value of the "icon_img" field.
func (u *CpSchoolUpsert) ClearIconImg() *CpSchoolUpsert {
u.SetNull(cpschool.FieldIconImg)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
// Using this option is equivalent to using:
//
// client.CpSchool.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(cpschool.FieldID)
// }),
// ).
// Exec(ctx)
func (u *CpSchoolUpsertOne) UpdateNewValues() *CpSchoolUpsertOne {
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.ID(); exists {
s.SetIgnore(cpschool.FieldID)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.CpSchool.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *CpSchoolUpsertOne) Ignore() *CpSchoolUpsertOne {
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 *CpSchoolUpsertOne) DoNothing() *CpSchoolUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the CpSchoolCreate.OnConflict
// documentation for more info.
func (u *CpSchoolUpsertOne) Update(set func(*CpSchoolUpsert)) *CpSchoolUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&CpSchoolUpsert{UpdateSet: update})
}))
return u
}
// SetName sets the "name" field.
func (u *CpSchoolUpsertOne) SetName(v string) *CpSchoolUpsertOne {
return u.Update(func(s *CpSchoolUpsert) {
s.SetName(v)
})
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *CpSchoolUpsertOne) UpdateName() *CpSchoolUpsertOne {
return u.Update(func(s *CpSchoolUpsert) {
s.UpdateName()
})
}
// SetNamePinyin sets the "name_pinyin" field.
func (u *CpSchoolUpsertOne) SetNamePinyin(v string) *CpSchoolUpsertOne {
return u.Update(func(s *CpSchoolUpsert) {
s.SetNamePinyin(v)
})
}
// UpdateNamePinyin sets the "name_pinyin" field to the value that was provided on create.
func (u *CpSchoolUpsertOne) UpdateNamePinyin() *CpSchoolUpsertOne {
return u.Update(func(s *CpSchoolUpsert) {
s.UpdateNamePinyin()
})
}
// SetIconImg sets the "icon_img" field.
func (u *CpSchoolUpsertOne) SetIconImg(v string) *CpSchoolUpsertOne {
return u.Update(func(s *CpSchoolUpsert) {
s.SetIconImg(v)
})
}
// UpdateIconImg sets the "icon_img" field to the value that was provided on create.
func (u *CpSchoolUpsertOne) UpdateIconImg() *CpSchoolUpsertOne {
return u.Update(func(s *CpSchoolUpsert) {
s.UpdateIconImg()
})
}
// ClearIconImg clears the value of the "icon_img" field.
func (u *CpSchoolUpsertOne) ClearIconImg() *CpSchoolUpsertOne {
return u.Update(func(s *CpSchoolUpsert) {
s.ClearIconImg()
})
}
// Exec executes the query.
func (u *CpSchoolUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for CpSchoolCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *CpSchoolUpsertOne) 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 *CpSchoolUpsertOne) ID(ctx context.Context) (id string, err error) {
if u.create.driver.Dialect() == dialect.MySQL {
// In case of "ON CONFLICT", there is no way to get back non-numeric ID
// fields from the database since MySQL does not support the RETURNING clause.
return id, errors.New("ent: CpSchoolUpsertOne.ID is not supported by MySQL driver. Use CpSchoolUpsertOne.Exec instead")
}
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 *CpSchoolUpsertOne) IDX(ctx context.Context) string {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// CpSchoolCreateBulk is the builder for creating many CpSchool entities in bulk.
type CpSchoolCreateBulk struct {
config
err error
builders []*CpSchoolCreate
conflict []sql.ConflictOption
}
// Save creates the CpSchool entities in the database.
func (_c *CpSchoolCreateBulk) Save(ctx context.Context) ([]*CpSchool, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*CpSchool, len(_c.builders))
mutators := make([]Mutator, len(_c.builders))
for i := range _c.builders {
func(i int, root context.Context) {
builder := _c.builders[i]
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*CpSchoolMutation)
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
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 *CpSchoolCreateBulk) SaveX(ctx context.Context) []*CpSchool {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *CpSchoolCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *CpSchoolCreateBulk) 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.CpSchool.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.CpSchoolUpsert) {
// SetName(v+v).
// }).
// Exec(ctx)
func (_c *CpSchoolCreateBulk) OnConflict(opts ...sql.ConflictOption) *CpSchoolUpsertBulk {
_c.conflict = opts
return &CpSchoolUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.CpSchool.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *CpSchoolCreateBulk) OnConflictColumns(columns ...string) *CpSchoolUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &CpSchoolUpsertBulk{
create: _c,
}
}
// CpSchoolUpsertBulk is the builder for "upsert"-ing
// a bulk of CpSchool nodes.
type CpSchoolUpsertBulk struct {
create *CpSchoolCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.CpSchool.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(cpschool.FieldID)
// }),
// ).
// Exec(ctx)
func (u *CpSchoolUpsertBulk) UpdateNewValues() *CpSchoolUpsertBulk {
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.ID(); exists {
s.SetIgnore(cpschool.FieldID)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.CpSchool.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *CpSchoolUpsertBulk) Ignore() *CpSchoolUpsertBulk {
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 *CpSchoolUpsertBulk) DoNothing() *CpSchoolUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the CpSchoolCreateBulk.OnConflict
// documentation for more info.
func (u *CpSchoolUpsertBulk) Update(set func(*CpSchoolUpsert)) *CpSchoolUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&CpSchoolUpsert{UpdateSet: update})
}))
return u
}
// SetName sets the "name" field.
func (u *CpSchoolUpsertBulk) SetName(v string) *CpSchoolUpsertBulk {
return u.Update(func(s *CpSchoolUpsert) {
s.SetName(v)
})
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *CpSchoolUpsertBulk) UpdateName() *CpSchoolUpsertBulk {
return u.Update(func(s *CpSchoolUpsert) {
s.UpdateName()
})
}
// SetNamePinyin sets the "name_pinyin" field.
func (u *CpSchoolUpsertBulk) SetNamePinyin(v string) *CpSchoolUpsertBulk {
return u.Update(func(s *CpSchoolUpsert) {
s.SetNamePinyin(v)
})
}
// UpdateNamePinyin sets the "name_pinyin" field to the value that was provided on create.
func (u *CpSchoolUpsertBulk) UpdateNamePinyin() *CpSchoolUpsertBulk {
return u.Update(func(s *CpSchoolUpsert) {
s.UpdateNamePinyin()
})
}
// SetIconImg sets the "icon_img" field.
func (u *CpSchoolUpsertBulk) SetIconImg(v string) *CpSchoolUpsertBulk {
return u.Update(func(s *CpSchoolUpsert) {
s.SetIconImg(v)
})
}
// UpdateIconImg sets the "icon_img" field to the value that was provided on create.
func (u *CpSchoolUpsertBulk) UpdateIconImg() *CpSchoolUpsertBulk {
return u.Update(func(s *CpSchoolUpsert) {
s.UpdateIconImg()
})
}
// ClearIconImg clears the value of the "icon_img" field.
func (u *CpSchoolUpsertBulk) ClearIconImg() *CpSchoolUpsertBulk {
return u.Update(func(s *CpSchoolUpsert) {
s.ClearIconImg()
})
}
// Exec executes the query.
func (u *CpSchoolUpsertBulk) 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 CpSchoolCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for CpSchoolCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *CpSchoolUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
+88
View File
@@ -0,0 +1,88 @@
// ENT数据库文件,请勿编辑。
package ent
import (
"context"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// CpSchoolDelete is the builder for deleting a CpSchool entity.
type CpSchoolDelete struct {
config
hooks []Hook
mutation *CpSchoolMutation
}
// Where appends a list predicates to the CpSchoolDelete builder.
func (_d *CpSchoolDelete) Where(ps ...predicate.CpSchool) *CpSchoolDelete {
_d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (_d *CpSchoolDelete) 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 *CpSchoolDelete) ExecX(ctx context.Context) int {
n, err := _d.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (_d *CpSchoolDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(cpschool.Table, sqlgraph.NewFieldSpec(cpschool.FieldID, field.TypeString))
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
}
// CpSchoolDeleteOne is the builder for deleting a single CpSchool entity.
type CpSchoolDeleteOne struct {
_d *CpSchoolDelete
}
// Where appends a list predicates to the CpSchoolDelete builder.
func (_d *CpSchoolDeleteOne) Where(ps ...predicate.CpSchool) *CpSchoolDeleteOne {
_d._d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query.
func (_d *CpSchoolDeleteOne) Exec(ctx context.Context) error {
n, err := _d._d.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{cpschool.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *CpSchoolDeleteOne) ExecX(ctx context.Context) {
if err := _d.Exec(ctx); err != nil {
panic(err)
}
}
+606
View File
@@ -0,0 +1,606 @@
// ENT数据库文件,请勿编辑。
package ent
import (
"context"
"database/sql/driver"
"fmt"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/predicate"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// CpSchoolQuery is the builder for querying CpSchool entities.
type CpSchoolQuery struct {
config
ctx *QueryContext
order []cpschool.OrderOption
inters []Interceptor
predicates []predicate.CpSchool
withCpusers *CpUserQuery
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the CpSchoolQuery builder.
func (_q *CpSchoolQuery) Where(ps ...predicate.CpSchool) *CpSchoolQuery {
_q.predicates = append(_q.predicates, ps...)
return _q
}
// Limit the number of records to be returned by this query.
func (_q *CpSchoolQuery) Limit(limit int) *CpSchoolQuery {
_q.ctx.Limit = &limit
return _q
}
// Offset to start from.
func (_q *CpSchoolQuery) Offset(offset int) *CpSchoolQuery {
_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 *CpSchoolQuery) Unique(unique bool) *CpSchoolQuery {
_q.ctx.Unique = &unique
return _q
}
// Order specifies how the records should be ordered.
func (_q *CpSchoolQuery) Order(o ...cpschool.OrderOption) *CpSchoolQuery {
_q.order = append(_q.order, o...)
return _q
}
// QueryCpusers chains the current query on the "cpusers" edge.
func (_q *CpSchoolQuery) QueryCpusers() *CpUserQuery {
query := (&CpUserClient{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(cpschool.Table, cpschool.FieldID, selector),
sqlgraph.To(cpuser.Table, cpuser.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, cpschool.CpusersTable, cpschool.CpusersColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first CpSchool entity from the query.
// Returns a *NotFoundError when no CpSchool was found.
func (_q *CpSchoolQuery) First(ctx context.Context) (*CpSchool, 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{cpschool.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (_q *CpSchoolQuery) FirstX(ctx context.Context) *CpSchool {
node, err := _q.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first CpSchool ID from the query.
// Returns a *NotFoundError when no CpSchool ID was found.
func (_q *CpSchoolQuery) FirstID(ctx context.Context) (id string, err error) {
var ids []string
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{cpschool.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (_q *CpSchoolQuery) FirstIDX(ctx context.Context) string {
id, err := _q.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single CpSchool entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one CpSchool entity is found.
// Returns a *NotFoundError when no CpSchool entities are found.
func (_q *CpSchoolQuery) Only(ctx context.Context) (*CpSchool, 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{cpschool.Label}
default:
return nil, &NotSingularError{cpschool.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (_q *CpSchoolQuery) OnlyX(ctx context.Context) *CpSchool {
node, err := _q.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only CpSchool ID in the query.
// Returns a *NotSingularError when more than one CpSchool ID is found.
// Returns a *NotFoundError when no entities are found.
func (_q *CpSchoolQuery) OnlyID(ctx context.Context) (id string, err error) {
var ids []string
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{cpschool.Label}
default:
err = &NotSingularError{cpschool.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (_q *CpSchoolQuery) OnlyIDX(ctx context.Context) string {
id, err := _q.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of CpSchools.
func (_q *CpSchoolQuery) All(ctx context.Context) ([]*CpSchool, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*CpSchool, *CpSchoolQuery]()
return withInterceptors[[]*CpSchool](ctx, _q, qr, _q.inters)
}
// AllX is like All, but panics if an error occurs.
func (_q *CpSchoolQuery) AllX(ctx context.Context) []*CpSchool {
nodes, err := _q.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of CpSchool IDs.
func (_q *CpSchoolQuery) IDs(ctx context.Context) (ids []string, err error) {
if _q.ctx.Unique == nil && _q.path != nil {
_q.Unique(true)
}
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
if err = _q.Select(cpschool.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (_q *CpSchoolQuery) IDsX(ctx context.Context) []string {
ids, err := _q.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (_q *CpSchoolQuery) 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[*CpSchoolQuery](), _q.inters)
}
// CountX is like Count, but panics if an error occurs.
func (_q *CpSchoolQuery) 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 *CpSchoolQuery) 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 *CpSchoolQuery) ExistX(ctx context.Context) bool {
exist, err := _q.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the CpSchoolQuery 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 *CpSchoolQuery) Clone() *CpSchoolQuery {
if _q == nil {
return nil
}
return &CpSchoolQuery{
config: _q.config,
ctx: _q.ctx.Clone(),
order: append([]cpschool.OrderOption{}, _q.order...),
inters: append([]Interceptor{}, _q.inters...),
predicates: append([]predicate.CpSchool{}, _q.predicates...),
withCpusers: _q.withCpusers.Clone(),
// clone intermediate query.
sql: _q.sql.Clone(),
path: _q.path,
}
}
// WithCpusers tells the query-builder to eager-load the nodes that are connected to
// the "cpusers" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *CpSchoolQuery) WithCpusers(opts ...func(*CpUserQuery)) *CpSchoolQuery {
query := (&CpUserClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withCpusers = 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 {
// Name string `json:"name,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.CpSchool.Query().
// GroupBy(cpschool.FieldName).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (_q *CpSchoolQuery) GroupBy(field string, fields ...string) *CpSchoolGroupBy {
_q.ctx.Fields = append([]string{field}, fields...)
grbuild := &CpSchoolGroupBy{build: _q}
grbuild.flds = &_q.ctx.Fields
grbuild.label = cpschool.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 {
// Name string `json:"name,omitempty"`
// }
//
// client.CpSchool.Query().
// Select(cpschool.FieldName).
// Scan(ctx, &v)
func (_q *CpSchoolQuery) Select(fields ...string) *CpSchoolSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
sbuild := &CpSchoolSelect{CpSchoolQuery: _q}
sbuild.label = cpschool.Label
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a CpSchoolSelect configured with the given aggregations.
func (_q *CpSchoolQuery) Aggregate(fns ...AggregateFunc) *CpSchoolSelect {
return _q.Select().Aggregate(fns...)
}
func (_q *CpSchoolQuery) 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 !cpschool.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 *CpSchoolQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CpSchool, error) {
var (
nodes = []*CpSchool{}
_spec = _q.querySpec()
loadedTypes = [1]bool{
_q.withCpusers != nil,
}
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*CpSchool).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &CpSchool{config: _q.config}
nodes = append(nodes, node)
node.Edges.loadedTypes = loadedTypes
return node.assignValues(columns, values)
}
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.withCpusers; query != nil {
if err := _q.loadCpusers(ctx, query, nodes,
func(n *CpSchool) { n.Edges.Cpusers = []*CpUser{} },
func(n *CpSchool, e *CpUser) { n.Edges.Cpusers = append(n.Edges.Cpusers, e) }); err != nil {
return nil, err
}
}
return nodes, nil
}
func (_q *CpSchoolQuery) loadCpusers(ctx context.Context, query *CpUserQuery, nodes []*CpSchool, init func(*CpSchool), assign func(*CpSchool, *CpUser)) error {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[string]*CpSchool)
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(cpuser.FieldSchoolID)
}
query.Where(predicate.CpUser(func(s *sql.Selector) {
s.Where(sql.InValues(s.C(cpschool.CpusersColumn), fks...))
}))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
fk := n.SchoolID
node, ok := nodeids[fk]
if !ok {
return fmt.Errorf(`unexpected referenced foreign-key "school_id" returned %v for node %v`, fk, n.ID)
}
assign(node, n)
}
return nil
}
func (_q *CpSchoolQuery) sqlCount(ctx context.Context) (int, error) {
_spec := _q.querySpec()
_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 *CpSchoolQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(cpschool.Table, cpschool.Columns, sqlgraph.NewFieldSpec(cpschool.FieldID, field.TypeString))
_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, cpschool.FieldID)
for i := range fields {
if fields[i] != cpschool.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
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 *CpSchoolQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(_q.driver.Dialect())
t1 := builder.Table(cpschool.Table)
columns := _q.ctx.Fields
if len(columns) == 0 {
columns = cpschool.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()
}
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
}
// CpSchoolGroupBy is the group-by builder for CpSchool entities.
type CpSchoolGroupBy struct {
selector
build *CpSchoolQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (_g *CpSchoolGroupBy) Aggregate(fns ...AggregateFunc) *CpSchoolGroupBy {
_g.fns = append(_g.fns, fns...)
return _g
}
// Scan applies the selector query and scans the result into the given value.
func (_g *CpSchoolGroupBy) 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[*CpSchoolQuery, *CpSchoolGroupBy](ctx, _g.build, _g, _g.build.inters, v)
}
func (_g *CpSchoolGroupBy) sqlScan(ctx context.Context, root *CpSchoolQuery, 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)
}
// CpSchoolSelect is the builder for selecting fields of CpSchool entities.
type CpSchoolSelect struct {
*CpSchoolQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (_s *CpSchoolSelect) Aggregate(fns ...AggregateFunc) *CpSchoolSelect {
_s.fns = append(_s.fns, fns...)
return _s
}
// Scan applies the selector query and scans the result into the given value.
func (_s *CpSchoolSelect) 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[*CpSchoolQuery, *CpSchoolSelect](ctx, _s.CpSchoolQuery, _s, _s.inters, v)
}
func (_s *CpSchoolSelect) sqlScan(ctx context.Context, root *CpSchoolQuery, 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)
}
+458
View File
@@ -0,0 +1,458 @@
// ENT数据库文件,请勿编辑。
package ent
import (
"context"
"errors"
"fmt"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// CpSchoolUpdate is the builder for updating CpSchool entities.
type CpSchoolUpdate struct {
config
hooks []Hook
mutation *CpSchoolMutation
}
// Where appends a list predicates to the CpSchoolUpdate builder.
func (_u *CpSchoolUpdate) Where(ps ...predicate.CpSchool) *CpSchoolUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetName sets the "name" field.
func (_u *CpSchoolUpdate) SetName(v string) *CpSchoolUpdate {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *CpSchoolUpdate) SetNillableName(v *string) *CpSchoolUpdate {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetNamePinyin sets the "name_pinyin" field.
func (_u *CpSchoolUpdate) SetNamePinyin(v string) *CpSchoolUpdate {
_u.mutation.SetNamePinyin(v)
return _u
}
// SetNillableNamePinyin sets the "name_pinyin" field if the given value is not nil.
func (_u *CpSchoolUpdate) SetNillableNamePinyin(v *string) *CpSchoolUpdate {
if v != nil {
_u.SetNamePinyin(*v)
}
return _u
}
// SetIconImg sets the "icon_img" field.
func (_u *CpSchoolUpdate) SetIconImg(v string) *CpSchoolUpdate {
_u.mutation.SetIconImg(v)
return _u
}
// SetNillableIconImg sets the "icon_img" field if the given value is not nil.
func (_u *CpSchoolUpdate) SetNillableIconImg(v *string) *CpSchoolUpdate {
if v != nil {
_u.SetIconImg(*v)
}
return _u
}
// ClearIconImg clears the value of the "icon_img" field.
func (_u *CpSchoolUpdate) ClearIconImg() *CpSchoolUpdate {
_u.mutation.ClearIconImg()
return _u
}
// AddCpuserIDs adds the "cpusers" edge to the CpUser entity by IDs.
func (_u *CpSchoolUpdate) AddCpuserIDs(ids ...int64) *CpSchoolUpdate {
_u.mutation.AddCpuserIDs(ids...)
return _u
}
// AddCpusers adds the "cpusers" edges to the CpUser entity.
func (_u *CpSchoolUpdate) AddCpusers(v ...*CpUser) *CpSchoolUpdate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddCpuserIDs(ids...)
}
// Mutation returns the CpSchoolMutation object of the builder.
func (_u *CpSchoolUpdate) Mutation() *CpSchoolMutation {
return _u.mutation
}
// ClearCpusers clears all "cpusers" edges to the CpUser entity.
func (_u *CpSchoolUpdate) ClearCpusers() *CpSchoolUpdate {
_u.mutation.ClearCpusers()
return _u
}
// RemoveCpuserIDs removes the "cpusers" edge to CpUser entities by IDs.
func (_u *CpSchoolUpdate) RemoveCpuserIDs(ids ...int64) *CpSchoolUpdate {
_u.mutation.RemoveCpuserIDs(ids...)
return _u
}
// RemoveCpusers removes "cpusers" edges to CpUser entities.
func (_u *CpSchoolUpdate) RemoveCpusers(v ...*CpUser) *CpSchoolUpdate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveCpuserIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *CpSchoolUpdate) 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 *CpSchoolUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *CpSchoolUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *CpSchoolUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
func (_u *CpSchoolUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(cpschool.Table, cpschool.Columns, sqlgraph.NewFieldSpec(cpschool.FieldID, field.TypeString))
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.Name(); ok {
_spec.SetField(cpschool.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.NamePinyin(); ok {
_spec.SetField(cpschool.FieldNamePinyin, field.TypeString, value)
}
if value, ok := _u.mutation.IconImg(); ok {
_spec.SetField(cpschool.FieldIconImg, field.TypeString, value)
}
if _u.mutation.IconImgCleared() {
_spec.ClearField(cpschool.FieldIconImg, field.TypeString)
}
if _u.mutation.CpusersCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpschool.CpusersTable,
Columns: []string{cpschool.CpusersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedCpusersIDs(); len(nodes) > 0 && !_u.mutation.CpusersCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpschool.CpusersTable,
Columns: []string{cpschool.CpusersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.CpusersIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpschool.CpusersTable,
Columns: []string{cpschool.CpusersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{cpschool.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// CpSchoolUpdateOne is the builder for updating a single CpSchool entity.
type CpSchoolUpdateOne struct {
config
fields []string
hooks []Hook
mutation *CpSchoolMutation
}
// SetName sets the "name" field.
func (_u *CpSchoolUpdateOne) SetName(v string) *CpSchoolUpdateOne {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *CpSchoolUpdateOne) SetNillableName(v *string) *CpSchoolUpdateOne {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetNamePinyin sets the "name_pinyin" field.
func (_u *CpSchoolUpdateOne) SetNamePinyin(v string) *CpSchoolUpdateOne {
_u.mutation.SetNamePinyin(v)
return _u
}
// SetNillableNamePinyin sets the "name_pinyin" field if the given value is not nil.
func (_u *CpSchoolUpdateOne) SetNillableNamePinyin(v *string) *CpSchoolUpdateOne {
if v != nil {
_u.SetNamePinyin(*v)
}
return _u
}
// SetIconImg sets the "icon_img" field.
func (_u *CpSchoolUpdateOne) SetIconImg(v string) *CpSchoolUpdateOne {
_u.mutation.SetIconImg(v)
return _u
}
// SetNillableIconImg sets the "icon_img" field if the given value is not nil.
func (_u *CpSchoolUpdateOne) SetNillableIconImg(v *string) *CpSchoolUpdateOne {
if v != nil {
_u.SetIconImg(*v)
}
return _u
}
// ClearIconImg clears the value of the "icon_img" field.
func (_u *CpSchoolUpdateOne) ClearIconImg() *CpSchoolUpdateOne {
_u.mutation.ClearIconImg()
return _u
}
// AddCpuserIDs adds the "cpusers" edge to the CpUser entity by IDs.
func (_u *CpSchoolUpdateOne) AddCpuserIDs(ids ...int64) *CpSchoolUpdateOne {
_u.mutation.AddCpuserIDs(ids...)
return _u
}
// AddCpusers adds the "cpusers" edges to the CpUser entity.
func (_u *CpSchoolUpdateOne) AddCpusers(v ...*CpUser) *CpSchoolUpdateOne {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddCpuserIDs(ids...)
}
// Mutation returns the CpSchoolMutation object of the builder.
func (_u *CpSchoolUpdateOne) Mutation() *CpSchoolMutation {
return _u.mutation
}
// ClearCpusers clears all "cpusers" edges to the CpUser entity.
func (_u *CpSchoolUpdateOne) ClearCpusers() *CpSchoolUpdateOne {
_u.mutation.ClearCpusers()
return _u
}
// RemoveCpuserIDs removes the "cpusers" edge to CpUser entities by IDs.
func (_u *CpSchoolUpdateOne) RemoveCpuserIDs(ids ...int64) *CpSchoolUpdateOne {
_u.mutation.RemoveCpuserIDs(ids...)
return _u
}
// RemoveCpusers removes "cpusers" edges to CpUser entities.
func (_u *CpSchoolUpdateOne) RemoveCpusers(v ...*CpUser) *CpSchoolUpdateOne {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveCpuserIDs(ids...)
}
// Where appends a list predicates to the CpSchoolUpdate builder.
func (_u *CpSchoolUpdateOne) Where(ps ...predicate.CpSchool) *CpSchoolUpdateOne {
_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 *CpSchoolUpdateOne) Select(field string, fields ...string) *CpSchoolUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated CpSchool entity.
func (_u *CpSchoolUpdateOne) Save(ctx context.Context) (*CpSchool, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *CpSchoolUpdateOne) SaveX(ctx context.Context) *CpSchool {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *CpSchoolUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *CpSchoolUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
func (_u *CpSchoolUpdateOne) sqlSave(ctx context.Context) (_node *CpSchool, err error) {
_spec := sqlgraph.NewUpdateSpec(cpschool.Table, cpschool.Columns, sqlgraph.NewFieldSpec(cpschool.FieldID, field.TypeString))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "CpSchool.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, cpschool.FieldID)
for _, f := range fields {
if !cpschool.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != cpschool.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.Name(); ok {
_spec.SetField(cpschool.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.NamePinyin(); ok {
_spec.SetField(cpschool.FieldNamePinyin, field.TypeString, value)
}
if value, ok := _u.mutation.IconImg(); ok {
_spec.SetField(cpschool.FieldIconImg, field.TypeString, value)
}
if _u.mutation.IconImgCleared() {
_spec.ClearField(cpschool.FieldIconImg, field.TypeString)
}
if _u.mutation.CpusersCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpschool.CpusersTable,
Columns: []string{cpschool.CpusersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedCpusersIDs(); len(nodes) > 0 && !_u.mutation.CpusersCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpschool.CpusersTable,
Columns: []string{cpschool.CpusersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.CpusersIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpschool.CpusersTable,
Columns: []string{cpschool.CpusersColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &CpSchool{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{cpschool.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}
+21 -2
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/sysuser"
"strings"
"entgo.io/ent"
@@ -53,11 +54,13 @@ type CpTask struct {
type CpTaskEdges struct {
// CpUser holds the value of the cp_user edge.
CpUser *CpUser `json:"cp_user,omitempty"`
// SysUser holds the value of the sys_user edge.
SysUser *SysUser `json:"sys_user,omitempty"`
// CpTaskLogs holds the value of the cp_task_logs edge.
CpTaskLogs []*CpTaskLog `json:"cp_task_logs,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
loadedTypes [3]bool
}
// CpUserOrErr returns the CpUser value or an error if the edge
@@ -71,10 +74,21 @@ func (e CpTaskEdges) CpUserOrErr() (*CpUser, error) {
return nil, &NotLoadedError{edge: "cp_user"}
}
// SysUserOrErr returns the SysUser value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e CpTaskEdges) SysUserOrErr() (*SysUser, error) {
if e.SysUser != nil {
return e.SysUser, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: sysuser.Label}
}
return nil, &NotLoadedError{edge: "sys_user"}
}
// CpTaskLogsOrErr returns the CpTaskLogs value or an error if the edge
// was not loaded in eager-loading.
func (e CpTaskEdges) CpTaskLogsOrErr() ([]*CpTaskLog, error) {
if e.loadedTypes[1] {
if e.loadedTypes[2] {
return e.CpTaskLogs, nil
}
return nil, &NotLoadedError{edge: "cp_task_logs"}
@@ -209,6 +223,11 @@ func (_m *CpTask) QueryCpUser() *CpUserQuery {
return NewCpTaskClient(_m.config).QueryCpUser(_m)
}
// QuerySysUser queries the "sys_user" edge of the CpTask entity.
func (_m *CpTask) QuerySysUser() *SysUserQuery {
return NewCpTaskClient(_m.config).QuerySysUser(_m)
}
// QueryCpTaskLogs queries the "cp_task_logs" edge of the CpTask entity.
func (_m *CpTask) QueryCpTaskLogs() *CpTaskLogQuery {
return NewCpTaskClient(_m.config).QueryCpTaskLogs(_m)
+25
View File
@@ -42,6 +42,8 @@ const (
FieldNextExecuteTime = "next_execute_time"
// EdgeCpUser holds the string denoting the cp_user edge name in mutations.
EdgeCpUser = "cp_user"
// EdgeSysUser holds the string denoting the sys_user edge name in mutations.
EdgeSysUser = "sys_user"
// EdgeCpTaskLogs holds the string denoting the cp_task_logs edge name in mutations.
EdgeCpTaskLogs = "cp_task_logs"
// Table holds the table name of the cptask in the database.
@@ -53,6 +55,13 @@ const (
CpUserInverseTable = "cp_users"
// CpUserColumn is the table column denoting the cp_user relation/edge.
CpUserColumn = "cp_user_id"
// SysUserTable is the table that holds the sys_user relation/edge.
SysUserTable = "cp_tasks"
// SysUserInverseTable is the table name for the SysUser entity.
// It exists in this package in order to avoid circular dependency with the "sysuser" package.
SysUserInverseTable = "sys_user"
// SysUserColumn is the table column denoting the sys_user relation/edge.
SysUserColumn = "user_id"
// CpTaskLogsTable is the table that holds the cp_task_logs relation/edge.
CpTaskLogsTable = "cp_task_logs"
// CpTaskLogsInverseTable is the table name for the CpTaskLog entity.
@@ -93,6 +102,8 @@ func ValidColumn(column string) bool {
var (
// TitleValidator is a validator for the "title" field. It is called by the builders before save.
TitleValidator func(string) error
// DefaultFrequency holds the default value on creation for the "frequency" field.
DefaultFrequency int
// DefaultSuccessCount holds the default value on creation for the "success_count" field.
DefaultSuccessCount int
)
@@ -275,6 +286,13 @@ func ByCpUserField(field string, opts ...sql.OrderTermOption) OrderOption {
}
}
// BySysUserField orders the results by sys_user field.
func BySysUserField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newSysUserStep(), sql.OrderByField(field, opts...))
}
}
// ByCpTaskLogsCount orders the results by cp_task_logs count.
func ByCpTaskLogsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
@@ -295,6 +313,13 @@ func newCpUserStep() *sqlgraph.Step {
sqlgraph.Edge(sqlgraph.M2O, true, CpUserTable, CpUserColumn),
)
}
func newSysUserStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(SysUserInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, SysUserTable, SysUserColumn),
)
}
func newCpTaskLogsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
+23 -20
View File
@@ -139,26 +139,6 @@ func UserIDNotIn(vs ...int64) predicate.CpTask {
return predicate.CpTask(sql.FieldNotIn(FieldUserID, vs...))
}
// UserIDGT applies the GT predicate on the "user_id" field.
func UserIDGT(v int64) predicate.CpTask {
return predicate.CpTask(sql.FieldGT(FieldUserID, v))
}
// UserIDGTE applies the GTE predicate on the "user_id" field.
func UserIDGTE(v int64) predicate.CpTask {
return predicate.CpTask(sql.FieldGTE(FieldUserID, v))
}
// UserIDLT applies the LT predicate on the "user_id" field.
func UserIDLT(v int64) predicate.CpTask {
return predicate.CpTask(sql.FieldLT(FieldUserID, v))
}
// UserIDLTE applies the LTE predicate on the "user_id" field.
func UserIDLTE(v int64) predicate.CpTask {
return predicate.CpTask(sql.FieldLTE(FieldUserID, v))
}
// TaskTypeEQ applies the EQ predicate on the "task_type" field.
func TaskTypeEQ(v TaskType) predicate.CpTask {
return predicate.CpTask(sql.FieldEQ(FieldTaskType, v))
@@ -632,6 +612,29 @@ func HasCpUserWith(preds ...predicate.CpUser) predicate.CpTask {
})
}
// HasSysUser applies the HasEdge predicate on the "sys_user" edge.
func HasSysUser() predicate.CpTask {
return predicate.CpTask(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, SysUserTable, SysUserColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasSysUserWith applies the HasEdge predicate on the "sys_user" edge with a given conditions (other predicates).
func HasSysUserWith(preds ...predicate.SysUser) predicate.CpTask {
return predicate.CpTask(func(s *sql.Selector) {
step := newSysUserStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasCpTaskLogs applies the HasEdge predicate on the "cp_task_logs" edge.
func HasCpTaskLogs() predicate.CpTask {
return predicate.CpTask(func(s *sql.Selector) {
+44 -24
View File
@@ -9,6 +9,7 @@ import (
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/sysuser"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
@@ -53,6 +54,14 @@ func (_c *CpTaskCreate) SetFrequency(v int) *CpTaskCreate {
return _c
}
// SetNillableFrequency sets the "frequency" field if the given value is not nil.
func (_c *CpTaskCreate) SetNillableFrequency(v *int) *CpTaskCreate {
if v != nil {
_c.SetFrequency(*v)
}
return _c
}
// SetTaskStatus sets the "task_status" field.
func (_c *CpTaskCreate) SetTaskStatus(v cptask.TaskStatus) *CpTaskCreate {
_c.mutation.SetTaskStatus(v)
@@ -146,6 +155,17 @@ func (_c *CpTaskCreate) SetCpUser(v *CpUser) *CpTaskCreate {
return _c.SetCpUserID(v.ID)
}
// SetSysUserID sets the "sys_user" edge to the SysUser entity by ID.
func (_c *CpTaskCreate) SetSysUserID(id int64) *CpTaskCreate {
_c.mutation.SetSysUserID(id)
return _c
}
// SetSysUser sets the "sys_user" edge to the SysUser entity.
func (_c *CpTaskCreate) SetSysUser(v *SysUser) *CpTaskCreate {
return _c.SetSysUserID(v.ID)
}
// AddCpTaskLogIDs adds the "cp_task_logs" edge to the CpTaskLog entity by IDs.
func (_c *CpTaskCreate) AddCpTaskLogIDs(ids ...int64) *CpTaskCreate {
_c.mutation.AddCpTaskLogIDs(ids...)
@@ -196,6 +216,10 @@ func (_c *CpTaskCreate) ExecX(ctx context.Context) {
// defaults sets the default values of the builder before save.
func (_c *CpTaskCreate) defaults() {
if _, ok := _c.mutation.Frequency(); !ok {
v := cptask.DefaultFrequency
_c.mutation.SetFrequency(v)
}
if _, ok := _c.mutation.SuccessCount(); !ok {
v := cptask.DefaultSuccessCount
_c.mutation.SetSuccessCount(v)
@@ -259,6 +283,9 @@ func (_c *CpTaskCreate) check() error {
if len(_c.mutation.CpUserIDs()) == 0 {
return &ValidationError{Name: "cp_user", err: errors.New(`ent: missing required edge "CpTask.cp_user"`)}
}
if len(_c.mutation.SysUserIDs()) == 0 {
return &ValidationError{Name: "sys_user", err: errors.New(`ent: missing required edge "CpTask.sys_user"`)}
}
return nil
}
@@ -286,10 +313,6 @@ func (_c *CpTaskCreate) createSpec() (*CpTask, *sqlgraph.CreateSpec) {
_spec = sqlgraph.NewCreateSpec(cptask.Table, sqlgraph.NewFieldSpec(cptask.FieldID, field.TypeInt64))
)
_spec.OnConflict = _c.conflict
if value, ok := _c.mutation.UserID(); ok {
_spec.SetField(cptask.FieldUserID, field.TypeInt64, value)
_node.UserID = value
}
if value, ok := _c.mutation.TaskType(); ok {
_spec.SetField(cptask.FieldTaskType, field.TypeEnum, value)
_node.TaskType = value
@@ -351,6 +374,23 @@ func (_c *CpTaskCreate) createSpec() (*CpTask, *sqlgraph.CreateSpec) {
_node.CpUserID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.SysUserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cptask.SysUserTable,
Columns: []string{cptask.SysUserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.UserID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.CpTaskLogsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
@@ -443,12 +483,6 @@ func (u *CpTaskUpsert) UpdateUserID() *CpTaskUpsert {
return u
}
// AddUserID adds v to the "user_id" field.
func (u *CpTaskUpsert) AddUserID(v int64) *CpTaskUpsert {
u.Add(cptask.FieldUserID, v)
return u
}
// SetTaskType sets the "task_type" field.
func (u *CpTaskUpsert) SetTaskType(v cptask.TaskType) *CpTaskUpsert {
u.Set(cptask.FieldTaskType, v)
@@ -696,13 +730,6 @@ func (u *CpTaskUpsertOne) SetUserID(v int64) *CpTaskUpsertOne {
})
}
// AddUserID adds v to the "user_id" field.
func (u *CpTaskUpsertOne) AddUserID(v int64) *CpTaskUpsertOne {
return u.Update(func(s *CpTaskUpsert) {
s.AddUserID(v)
})
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *CpTaskUpsertOne) UpdateUserID() *CpTaskUpsertOne {
return u.Update(func(s *CpTaskUpsert) {
@@ -1152,13 +1179,6 @@ func (u *CpTaskUpsertBulk) SetUserID(v int64) *CpTaskUpsertBulk {
})
}
// AddUserID adds v to the "user_id" field.
func (u *CpTaskUpsertBulk) AddUserID(v int64) *CpTaskUpsertBulk {
return u.Update(func(s *CpTaskUpsert) {
s.AddUserID(v)
})
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *CpTaskUpsertBulk) UpdateUserID() *CpTaskUpsertBulk {
return u.Update(func(s *CpTaskUpsert) {
+76 -1
View File
@@ -10,6 +10,7 @@ import (
"likedream-goframe/internal/ent/cptasklog"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/predicate"
"likedream-goframe/internal/ent/sysuser"
"math"
"entgo.io/ent"
@@ -26,6 +27,7 @@ type CpTaskQuery struct {
inters []Interceptor
predicates []predicate.CpTask
withCpUser *CpUserQuery
withSysUser *SysUserQuery
withCpTaskLogs *CpTaskLogQuery
// intermediate query (i.e. traversal path).
sql *sql.Selector
@@ -85,6 +87,28 @@ func (_q *CpTaskQuery) QueryCpUser() *CpUserQuery {
return query
}
// QuerySysUser chains the current query on the "sys_user" edge.
func (_q *CpTaskQuery) QuerySysUser() *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(cptask.Table, cptask.FieldID, selector),
sqlgraph.To(sysuser.Table, sysuser.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, cptask.SysUserTable, cptask.SysUserColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryCpTaskLogs chains the current query on the "cp_task_logs" edge.
func (_q *CpTaskQuery) QueryCpTaskLogs() *CpTaskLogQuery {
query := (&CpTaskLogClient{config: _q.config}).Query()
@@ -300,6 +324,7 @@ func (_q *CpTaskQuery) Clone() *CpTaskQuery {
inters: append([]Interceptor{}, _q.inters...),
predicates: append([]predicate.CpTask{}, _q.predicates...),
withCpUser: _q.withCpUser.Clone(),
withSysUser: _q.withSysUser.Clone(),
withCpTaskLogs: _q.withCpTaskLogs.Clone(),
// clone intermediate query.
sql: _q.sql.Clone(),
@@ -318,6 +343,17 @@ func (_q *CpTaskQuery) WithCpUser(opts ...func(*CpUserQuery)) *CpTaskQuery {
return _q
}
// WithSysUser tells the query-builder to eager-load the nodes that are connected to
// the "sys_user" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *CpTaskQuery) WithSysUser(opts ...func(*SysUserQuery)) *CpTaskQuery {
query := (&SysUserClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withSysUser = query
return _q
}
// WithCpTaskLogs tells the query-builder to eager-load the nodes that are connected to
// the "cp_task_logs" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *CpTaskQuery) WithCpTaskLogs(opts ...func(*CpTaskLogQuery)) *CpTaskQuery {
@@ -407,8 +443,9 @@ func (_q *CpTaskQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CpTas
var (
nodes = []*CpTask{}
_spec = _q.querySpec()
loadedTypes = [2]bool{
loadedTypes = [3]bool{
_q.withCpUser != nil,
_q.withSysUser != nil,
_q.withCpTaskLogs != nil,
}
)
@@ -436,6 +473,12 @@ func (_q *CpTaskQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CpTas
return nil, err
}
}
if query := _q.withSysUser; query != nil {
if err := _q.loadSysUser(ctx, query, nodes, nil,
func(n *CpTask, e *SysUser) { n.Edges.SysUser = e }); err != nil {
return nil, err
}
}
if query := _q.withCpTaskLogs; query != nil {
if err := _q.loadCpTaskLogs(ctx, query, nodes,
func(n *CpTask) { n.Edges.CpTaskLogs = []*CpTaskLog{} },
@@ -475,6 +518,35 @@ func (_q *CpTaskQuery) loadCpUser(ctx context.Context, query *CpUserQuery, nodes
}
return nil
}
func (_q *CpTaskQuery) loadSysUser(ctx context.Context, query *SysUserQuery, nodes []*CpTask, init func(*CpTask), assign func(*CpTask, *SysUser)) error {
ids := make([]int64, 0, len(nodes))
nodeids := make(map[int64][]*CpTask)
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 *CpTaskQuery) loadCpTaskLogs(ctx context.Context, query *CpTaskLogQuery, nodes []*CpTask, init func(*CpTask), assign func(*CpTask, *CpTaskLog)) error {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[int64]*CpTask)
@@ -534,6 +606,9 @@ func (_q *CpTaskQuery) querySpec() *sqlgraph.QuerySpec {
if _q.withCpUser != nil {
_spec.Node.AddColumnOnce(cptask.FieldCpUserID)
}
if _q.withSysUser != nil {
_spec.Node.AddColumnOnce(cptask.FieldUserID)
}
}
if ps := _q.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
+99 -26
View File
@@ -10,6 +10,7 @@ import (
"likedream-goframe/internal/ent/cptasklog"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/predicate"
"likedream-goframe/internal/ent/sysuser"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
@@ -45,7 +46,6 @@ func (_u *CpTaskUpdate) SetNillableCpUserID(v *int64) *CpTaskUpdate {
// SetUserID sets the "user_id" field.
func (_u *CpTaskUpdate) SetUserID(v int64) *CpTaskUpdate {
_u.mutation.ResetUserID()
_u.mutation.SetUserID(v)
return _u
}
@@ -58,12 +58,6 @@ func (_u *CpTaskUpdate) SetNillableUserID(v *int64) *CpTaskUpdate {
return _u
}
// AddUserID adds value to the "user_id" field.
func (_u *CpTaskUpdate) AddUserID(v int64) *CpTaskUpdate {
_u.mutation.AddUserID(v)
return _u
}
// SetTaskType sets the "task_type" field.
func (_u *CpTaskUpdate) SetTaskType(v cptask.TaskType) *CpTaskUpdate {
_u.mutation.SetTaskType(v)
@@ -282,6 +276,17 @@ func (_u *CpTaskUpdate) SetCpUser(v *CpUser) *CpTaskUpdate {
return _u.SetCpUserID(v.ID)
}
// SetSysUserID sets the "sys_user" edge to the SysUser entity by ID.
func (_u *CpTaskUpdate) SetSysUserID(id int64) *CpTaskUpdate {
_u.mutation.SetSysUserID(id)
return _u
}
// SetSysUser sets the "sys_user" edge to the SysUser entity.
func (_u *CpTaskUpdate) SetSysUser(v *SysUser) *CpTaskUpdate {
return _u.SetSysUserID(v.ID)
}
// AddCpTaskLogIDs adds the "cp_task_logs" edge to the CpTaskLog entity by IDs.
func (_u *CpTaskUpdate) AddCpTaskLogIDs(ids ...int64) *CpTaskUpdate {
_u.mutation.AddCpTaskLogIDs(ids...)
@@ -308,6 +313,12 @@ func (_u *CpTaskUpdate) ClearCpUser() *CpTaskUpdate {
return _u
}
// ClearSysUser clears the "sys_user" edge to the SysUser entity.
func (_u *CpTaskUpdate) ClearSysUser() *CpTaskUpdate {
_u.mutation.ClearSysUser()
return _u
}
// ClearCpTaskLogs clears all "cp_task_logs" edges to the CpTaskLog entity.
func (_u *CpTaskUpdate) ClearCpTaskLogs() *CpTaskUpdate {
_u.mutation.ClearCpTaskLogs()
@@ -386,6 +397,9 @@ func (_u *CpTaskUpdate) check() error {
if _u.mutation.CpUserCleared() && len(_u.mutation.CpUserIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "CpTask.cp_user"`)
}
if _u.mutation.SysUserCleared() && len(_u.mutation.SysUserIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "CpTask.sys_user"`)
}
return nil
}
@@ -401,12 +415,6 @@ func (_u *CpTaskUpdate) sqlSave(ctx context.Context) (_node int, err error) {
}
}
}
if value, ok := _u.mutation.UserID(); ok {
_spec.SetField(cptask.FieldUserID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedUserID(); ok {
_spec.AddField(cptask.FieldUserID, field.TypeInt64, value)
}
if value, ok := _u.mutation.TaskType(); ok {
_spec.SetField(cptask.FieldTaskType, field.TypeEnum, value)
}
@@ -496,6 +504,35 @@ func (_u *CpTaskUpdate) sqlSave(ctx context.Context) (_node int, err error) {
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SysUserCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cptask.SysUserTable,
Columns: []string{cptask.SysUserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.SysUserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cptask.SysUserTable,
Columns: []string{cptask.SysUserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.CpTaskLogsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
@@ -577,7 +614,6 @@ func (_u *CpTaskUpdateOne) SetNillableCpUserID(v *int64) *CpTaskUpdateOne {
// SetUserID sets the "user_id" field.
func (_u *CpTaskUpdateOne) SetUserID(v int64) *CpTaskUpdateOne {
_u.mutation.ResetUserID()
_u.mutation.SetUserID(v)
return _u
}
@@ -590,12 +626,6 @@ func (_u *CpTaskUpdateOne) SetNillableUserID(v *int64) *CpTaskUpdateOne {
return _u
}
// AddUserID adds value to the "user_id" field.
func (_u *CpTaskUpdateOne) AddUserID(v int64) *CpTaskUpdateOne {
_u.mutation.AddUserID(v)
return _u
}
// SetTaskType sets the "task_type" field.
func (_u *CpTaskUpdateOne) SetTaskType(v cptask.TaskType) *CpTaskUpdateOne {
_u.mutation.SetTaskType(v)
@@ -814,6 +844,17 @@ func (_u *CpTaskUpdateOne) SetCpUser(v *CpUser) *CpTaskUpdateOne {
return _u.SetCpUserID(v.ID)
}
// SetSysUserID sets the "sys_user" edge to the SysUser entity by ID.
func (_u *CpTaskUpdateOne) SetSysUserID(id int64) *CpTaskUpdateOne {
_u.mutation.SetSysUserID(id)
return _u
}
// SetSysUser sets the "sys_user" edge to the SysUser entity.
func (_u *CpTaskUpdateOne) SetSysUser(v *SysUser) *CpTaskUpdateOne {
return _u.SetSysUserID(v.ID)
}
// AddCpTaskLogIDs adds the "cp_task_logs" edge to the CpTaskLog entity by IDs.
func (_u *CpTaskUpdateOne) AddCpTaskLogIDs(ids ...int64) *CpTaskUpdateOne {
_u.mutation.AddCpTaskLogIDs(ids...)
@@ -840,6 +881,12 @@ func (_u *CpTaskUpdateOne) ClearCpUser() *CpTaskUpdateOne {
return _u
}
// ClearSysUser clears the "sys_user" edge to the SysUser entity.
func (_u *CpTaskUpdateOne) ClearSysUser() *CpTaskUpdateOne {
_u.mutation.ClearSysUser()
return _u
}
// ClearCpTaskLogs clears all "cp_task_logs" edges to the CpTaskLog entity.
func (_u *CpTaskUpdateOne) ClearCpTaskLogs() *CpTaskUpdateOne {
_u.mutation.ClearCpTaskLogs()
@@ -931,6 +978,9 @@ func (_u *CpTaskUpdateOne) check() error {
if _u.mutation.CpUserCleared() && len(_u.mutation.CpUserIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "CpTask.cp_user"`)
}
if _u.mutation.SysUserCleared() && len(_u.mutation.SysUserIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "CpTask.sys_user"`)
}
return nil
}
@@ -963,12 +1013,6 @@ func (_u *CpTaskUpdateOne) sqlSave(ctx context.Context) (_node *CpTask, err erro
}
}
}
if value, ok := _u.mutation.UserID(); ok {
_spec.SetField(cptask.FieldUserID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedUserID(); ok {
_spec.AddField(cptask.FieldUserID, field.TypeInt64, value)
}
if value, ok := _u.mutation.TaskType(); ok {
_spec.SetField(cptask.FieldTaskType, field.TypeEnum, value)
}
@@ -1058,6 +1102,35 @@ func (_u *CpTaskUpdateOne) sqlSave(ctx context.Context) (_node *CpTask, err erro
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SysUserCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cptask.SysUserTable,
Columns: []string{cptask.SysUserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.SysUserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cptask.SysUserTable,
Columns: []string{cptask.SysUserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.CpTaskLogsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
+20 -1
View File
@@ -4,6 +4,7 @@ package ent
import (
"fmt"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/sysuser"
"strings"
@@ -47,9 +48,11 @@ type CpUserEdges struct {
Sysuser *SysUser `json:"sysuser,omitempty"`
// CpTaskLogs holds the value of the cp_task_logs edge.
CpTaskLogs []*CpTaskLog `json:"cp_task_logs,omitempty"`
// School holds the value of the school edge.
School *CpSchool `json:"school,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [3]bool
loadedTypes [4]bool
}
// CptasksOrErr returns the Cptasks value or an error if the edge
@@ -81,6 +84,17 @@ func (e CpUserEdges) CpTaskLogsOrErr() ([]*CpTaskLog, error) {
return nil, &NotLoadedError{edge: "cp_task_logs"}
}
// SchoolOrErr returns the School value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e CpUserEdges) SchoolOrErr() (*CpSchool, error) {
if e.School != nil {
return e.School, nil
} else if e.loadedTypes[3] {
return nil, &NotFoundError{label: cpschool.Label}
}
return nil, &NotLoadedError{edge: "school"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*CpUser) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
@@ -187,6 +201,11 @@ func (_m *CpUser) QueryCpTaskLogs() *CpTaskLogQuery {
return NewCpUserClient(_m.config).QueryCpTaskLogs(_m)
}
// QuerySchool queries the "school" edge of the CpUser entity.
func (_m *CpUser) QuerySchool() *CpSchoolQuery {
return NewCpUserClient(_m.config).QuerySchool(_m)
}
// Update returns a builder for updating this CpUser.
// Note that you need to call CpUser.Unwrap() before calling this method if this CpUser
// was returned from a transaction, and the transaction was committed or rolled back.
+23
View File
@@ -36,6 +36,8 @@ const (
EdgeSysuser = "sysuser"
// EdgeCpTaskLogs holds the string denoting the cp_task_logs edge name in mutations.
EdgeCpTaskLogs = "cp_task_logs"
// EdgeSchool holds the string denoting the school edge name in mutations.
EdgeSchool = "school"
// Table holds the table name of the cpuser in the database.
Table = "cp_users"
// CptasksTable is the table that holds the cptasks relation/edge.
@@ -59,6 +61,13 @@ const (
CpTaskLogsInverseTable = "cp_task_logs"
// CpTaskLogsColumn is the table column denoting the cp_task_logs relation/edge.
CpTaskLogsColumn = "cp_user_id"
// SchoolTable is the table that holds the school relation/edge.
SchoolTable = "cp_users"
// SchoolInverseTable is the table name for the CpSchool entity.
// It exists in this package in order to avoid circular dependency with the "cpschool" package.
SchoolInverseTable = "cp_schools"
// SchoolColumn is the table column denoting the school relation/edge.
SchoolColumn = "school_id"
)
// Columns holds all SQL columns for cpuser fields.
@@ -198,6 +207,13 @@ func ByCpTaskLogs(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
sqlgraph.OrderByNeighborTerms(s, newCpTaskLogsStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
// BySchoolField orders the results by school field.
func BySchoolField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newSchoolStep(), sql.OrderByField(field, opts...))
}
}
func newCptasksStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
@@ -219,3 +235,10 @@ func newCpTaskLogsStep() *sqlgraph.Step {
sqlgraph.Edge(sqlgraph.O2M, false, CpTaskLogsTable, CpTaskLogsColumn),
)
}
func newSchoolStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(SchoolInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, SchoolTable, SchoolColumn),
)
}
+23
View File
@@ -618,6 +618,29 @@ func HasCpTaskLogsWith(preds ...predicate.CpTaskLog) predicate.CpUser {
})
}
// HasSchool applies the HasEdge predicate on the "school" edge.
func HasSchool() predicate.CpUser {
return predicate.CpUser(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, SchoolTable, SchoolColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasSchoolWith applies the HasEdge predicate on the "school" edge with a given conditions (other predicates).
func HasSchoolWith(preds ...predicate.CpSchool) predicate.CpUser {
return predicate.CpUser(func(s *sql.Selector) {
step := newSchoolStep()
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.CpUser) predicate.CpUser {
return predicate.CpUser(sql.AndPredicates(predicates...))
+26 -4
View File
@@ -6,6 +6,7 @@ import (
"context"
"errors"
"fmt"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
"likedream-goframe/internal/ent/cpuser"
@@ -137,6 +138,11 @@ func (_c *CpUserCreate) AddCpTaskLogs(v ...*CpTaskLog) *CpUserCreate {
return _c.AddCpTaskLogIDs(ids...)
}
// SetSchool sets the "school" edge to the CpSchool entity.
func (_c *CpUserCreate) SetSchool(v *CpSchool) *CpUserCreate {
return _c.SetSchoolID(v.ID)
}
// Mutation returns the CpUserMutation object of the builder.
func (_c *CpUserCreate) Mutation() *CpUserMutation {
return _c.mutation
@@ -209,6 +215,9 @@ func (_c *CpUserCreate) check() error {
if len(_c.mutation.SysuserIDs()) == 0 {
return &ValidationError{Name: "sysuser", err: errors.New(`ent: missing required edge "CpUser.sysuser"`)}
}
if len(_c.mutation.SchoolIDs()) == 0 {
return &ValidationError{Name: "school", err: errors.New(`ent: missing required edge "CpUser.school"`)}
}
return nil
}
@@ -244,10 +253,6 @@ func (_c *CpUserCreate) createSpec() (*CpUser, *sqlgraph.CreateSpec) {
_spec.SetField(cpuser.FieldPassword, field.TypeString, value)
_node.Password = value
}
if value, ok := _c.mutation.SchoolID(); ok {
_spec.SetField(cpuser.FieldSchoolID, field.TypeString, value)
_node.SchoolID = value
}
if value, ok := _c.mutation.Email(); ok {
_spec.SetField(cpuser.FieldEmail, field.TypeString, value)
_node.Email = value
@@ -313,6 +318,23 @@ func (_c *CpUserCreate) createSpec() (*CpUser, *sqlgraph.CreateSpec) {
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.SchoolIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cpuser.SchoolTable,
Columns: []string{cpuser.SchoolColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpschool.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.SchoolID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}
+76 -1
View File
@@ -6,6 +6,7 @@ import (
"context"
"database/sql/driver"
"fmt"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
"likedream-goframe/internal/ent/cpuser"
@@ -29,6 +30,7 @@ type CpUserQuery struct {
withCptasks *CpTaskQuery
withSysuser *SysUserQuery
withCpTaskLogs *CpTaskLogQuery
withSchool *CpSchoolQuery
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
@@ -131,6 +133,28 @@ func (_q *CpUserQuery) QueryCpTaskLogs() *CpTaskLogQuery {
return query
}
// QuerySchool chains the current query on the "school" edge.
func (_q *CpUserQuery) QuerySchool() *CpSchoolQuery {
query := (&CpSchoolClient{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(cpuser.Table, cpuser.FieldID, selector),
sqlgraph.To(cpschool.Table, cpschool.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, cpuser.SchoolTable, cpuser.SchoolColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first CpUser entity from the query.
// Returns a *NotFoundError when no CpUser was found.
func (_q *CpUserQuery) First(ctx context.Context) (*CpUser, error) {
@@ -326,6 +350,7 @@ func (_q *CpUserQuery) Clone() *CpUserQuery {
withCptasks: _q.withCptasks.Clone(),
withSysuser: _q.withSysuser.Clone(),
withCpTaskLogs: _q.withCpTaskLogs.Clone(),
withSchool: _q.withSchool.Clone(),
// clone intermediate query.
sql: _q.sql.Clone(),
path: _q.path,
@@ -365,6 +390,17 @@ func (_q *CpUserQuery) WithCpTaskLogs(opts ...func(*CpTaskLogQuery)) *CpUserQuer
return _q
}
// WithSchool tells the query-builder to eager-load the nodes that are connected to
// the "school" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *CpUserQuery) WithSchool(opts ...func(*CpSchoolQuery)) *CpUserQuery {
query := (&CpSchoolClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withSchool = 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.
//
@@ -443,10 +479,11 @@ func (_q *CpUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CpUse
var (
nodes = []*CpUser{}
_spec = _q.querySpec()
loadedTypes = [3]bool{
loadedTypes = [4]bool{
_q.withCptasks != nil,
_q.withSysuser != nil,
_q.withCpTaskLogs != nil,
_q.withSchool != nil,
}
)
_spec.ScanValues = func(columns []string) ([]any, error) {
@@ -487,6 +524,12 @@ func (_q *CpUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CpUse
return nil, err
}
}
if query := _q.withSchool; query != nil {
if err := _q.loadSchool(ctx, query, nodes, nil,
func(n *CpUser, e *CpSchool) { n.Edges.School = e }); err != nil {
return nil, err
}
}
return nodes, nil
}
@@ -579,6 +622,35 @@ func (_q *CpUserQuery) loadCpTaskLogs(ctx context.Context, query *CpTaskLogQuery
}
return nil
}
func (_q *CpUserQuery) loadSchool(ctx context.Context, query *CpSchoolQuery, nodes []*CpUser, init func(*CpUser), assign func(*CpUser, *CpSchool)) error {
ids := make([]string, 0, len(nodes))
nodeids := make(map[string][]*CpUser)
for i := range nodes {
fk := nodes[i].SchoolID
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(cpschool.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 "school_id" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (_q *CpUserQuery) sqlCount(ctx context.Context) (int, error) {
_spec := _q.querySpec()
@@ -608,6 +680,9 @@ func (_q *CpUserQuery) querySpec() *sqlgraph.QuerySpec {
if _q.withSysuser != nil {
_spec.Node.AddColumnOnce(cpuser.FieldUserID)
}
if _q.withSchool != nil {
_spec.Node.AddColumnOnce(cpuser.FieldSchoolID)
}
}
if ps := _q.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
+87 -6
View File
@@ -6,6 +6,7 @@ import (
"context"
"errors"
"fmt"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
"likedream-goframe/internal/ent/cpuser"
@@ -201,6 +202,11 @@ func (_u *CpUserUpdate) AddCpTaskLogs(v ...*CpTaskLog) *CpUserUpdate {
return _u.AddCpTaskLogIDs(ids...)
}
// SetSchool sets the "school" edge to the CpSchool entity.
func (_u *CpUserUpdate) SetSchool(v *CpSchool) *CpUserUpdate {
return _u.SetSchoolID(v.ID)
}
// Mutation returns the CpUserMutation object of the builder.
func (_u *CpUserUpdate) Mutation() *CpUserMutation {
return _u.mutation
@@ -254,6 +260,12 @@ func (_u *CpUserUpdate) RemoveCpTaskLogs(v ...*CpTaskLog) *CpUserUpdate {
return _u.RemoveCpTaskLogIDs(ids...)
}
// ClearSchool clears the "school" edge to the CpSchool entity.
func (_u *CpUserUpdate) ClearSchool() *CpUserUpdate {
_u.mutation.ClearSchool()
return _u
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *CpUserUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
@@ -306,6 +318,9 @@ func (_u *CpUserUpdate) check() error {
if _u.mutation.SysuserCleared() && len(_u.mutation.SysuserIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "CpUser.sysuser"`)
}
if _u.mutation.SchoolCleared() && len(_u.mutation.SchoolIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "CpUser.school"`)
}
return nil
}
@@ -327,9 +342,6 @@ func (_u *CpUserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if value, ok := _u.mutation.Password(); ok {
_spec.SetField(cpuser.FieldPassword, field.TypeString, value)
}
if value, ok := _u.mutation.SchoolID(); ok {
_spec.SetField(cpuser.FieldSchoolID, field.TypeString, value)
}
if value, ok := _u.mutation.Email(); ok {
_spec.SetField(cpuser.FieldEmail, field.TypeString, value)
}
@@ -470,6 +482,35 @@ func (_u *CpUserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SchoolCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cpuser.SchoolTable,
Columns: []string{cpuser.SchoolColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpschool.FieldID, field.TypeString),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.SchoolIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cpuser.SchoolTable,
Columns: []string{cpuser.SchoolColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpschool.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{cpuser.Label}
@@ -661,6 +702,11 @@ func (_u *CpUserUpdateOne) AddCpTaskLogs(v ...*CpTaskLog) *CpUserUpdateOne {
return _u.AddCpTaskLogIDs(ids...)
}
// SetSchool sets the "school" edge to the CpSchool entity.
func (_u *CpUserUpdateOne) SetSchool(v *CpSchool) *CpUserUpdateOne {
return _u.SetSchoolID(v.ID)
}
// Mutation returns the CpUserMutation object of the builder.
func (_u *CpUserUpdateOne) Mutation() *CpUserMutation {
return _u.mutation
@@ -714,6 +760,12 @@ func (_u *CpUserUpdateOne) RemoveCpTaskLogs(v ...*CpTaskLog) *CpUserUpdateOne {
return _u.RemoveCpTaskLogIDs(ids...)
}
// ClearSchool clears the "school" edge to the CpSchool entity.
func (_u *CpUserUpdateOne) ClearSchool() *CpUserUpdateOne {
_u.mutation.ClearSchool()
return _u
}
// Where appends a list predicates to the CpUserUpdate builder.
func (_u *CpUserUpdateOne) Where(ps ...predicate.CpUser) *CpUserUpdateOne {
_u.mutation.Where(ps...)
@@ -779,6 +831,9 @@ func (_u *CpUserUpdateOne) check() error {
if _u.mutation.SysuserCleared() && len(_u.mutation.SysuserIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "CpUser.sysuser"`)
}
if _u.mutation.SchoolCleared() && len(_u.mutation.SchoolIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "CpUser.school"`)
}
return nil
}
@@ -817,9 +872,6 @@ func (_u *CpUserUpdateOne) sqlSave(ctx context.Context) (_node *CpUser, err erro
if value, ok := _u.mutation.Password(); ok {
_spec.SetField(cpuser.FieldPassword, field.TypeString, value)
}
if value, ok := _u.mutation.SchoolID(); ok {
_spec.SetField(cpuser.FieldSchoolID, field.TypeString, value)
}
if value, ok := _u.mutation.Email(); ok {
_spec.SetField(cpuser.FieldEmail, field.TypeString, value)
}
@@ -960,6 +1012,35 @@ func (_u *CpUserUpdateOne) sqlSave(ctx context.Context) (_node *CpUser, err erro
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SchoolCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cpuser.SchoolTable,
Columns: []string{cpuser.SchoolColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpschool.FieldID, field.TypeString),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.SchoolIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cpuser.SchoolTable,
Columns: []string{cpuser.SchoolColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpschool.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &CpUser{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
+21 -8
View File
@@ -36,11 +36,10 @@ var (
}
// CpSchoolsColumns holds the columns for the "cp_schools" table.
CpSchoolsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "id", Type: field.TypeString, Unique: true},
{Name: "name", Type: field.TypeString},
{Name: "name_pinyin", Type: field.TypeString},
{Name: "icon_img", Type: field.TypeString, Nullable: true},
{Name: "tenant_id", Type: field.TypeString},
}
// CpSchoolsTable holds the schema information for the "cp_schools" table.
CpSchoolsTable = &schema.Table{
@@ -51,10 +50,9 @@ var (
// CpTasksColumns holds the columns for the "cp_tasks" table.
CpTasksColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "user_id", Type: field.TypeInt64},
{Name: "task_type", Type: field.TypeEnum, Enums: []string{"collection", "sign", "sleep_check"}},
{Name: "title", Type: field.TypeString},
{Name: "frequency", Type: field.TypeInt},
{Name: "frequency", Type: field.TypeInt, Default: 0},
{Name: "task_status", Type: field.TypeEnum, Enums: []string{"not_start", "doing", "done", "fail", "unknown"}},
{Name: "success_count", Type: field.TypeInt, Default: 0},
{Name: "form_data", Type: field.TypeString, Nullable: true},
@@ -64,6 +62,7 @@ var (
{Name: "execute_minute", Type: field.TypeInt, Nullable: true},
{Name: "next_execute_time", Type: field.TypeInt64, Nullable: true},
{Name: "cp_user_id", Type: field.TypeInt64},
{Name: "user_id", Type: field.TypeInt64},
}
// CpTasksTable holds the schema information for the "cp_tasks" table.
CpTasksTable = &schema.Table{
@@ -73,10 +72,16 @@ var (
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "cp_tasks_cp_users_cptasks",
Columns: []*schema.Column{CpTasksColumns[13]},
Columns: []*schema.Column{CpTasksColumns[12]},
RefColumns: []*schema.Column{CpUsersColumns[0]},
OnDelete: schema.NoAction,
},
{
Symbol: "cp_tasks_sys_user_cp_task",
Columns: []*schema.Column{CpTasksColumns[13]},
RefColumns: []*schema.Column{SysUserColumns[0]},
OnDelete: schema.NoAction,
},
},
}
// CpTaskLogsColumns holds the columns for the "cp_task_logs" table.
@@ -120,11 +125,11 @@ var (
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "username", Type: field.TypeString},
{Name: "password", Type: field.TypeString},
{Name: "school_id", Type: field.TypeString},
{Name: "email", Type: field.TypeString, Nullable: true},
{Name: "mobile_code", Type: field.TypeString, Nullable: true},
{Name: "cookie", Type: field.TypeString, Nullable: true},
{Name: "cookie", Type: field.TypeString, Nullable: true, Size: 2147483647},
{Name: "mobile_type", Type: field.TypeEnum, Enums: []string{"random", "authorize"}},
{Name: "school_id", Type: field.TypeString},
{Name: "user_id", Type: field.TypeInt64},
}
// CpUsersTable holds the schema information for the "cp_users" table.
@@ -133,6 +138,12 @@ var (
Columns: CpUsersColumns,
PrimaryKey: []*schema.Column{CpUsersColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "cp_users_cp_schools_cpusers",
Columns: []*schema.Column{CpUsersColumns[7]},
RefColumns: []*schema.Column{CpSchoolsColumns[0]},
OnDelete: schema.NoAction,
},
{
Symbol: "cp_users_sys_user_cpuser",
Columns: []*schema.Column{CpUsersColumns[8]},
@@ -363,10 +374,12 @@ func init() {
Table: "cp_image",
}
CpTasksTable.ForeignKeys[0].RefTable = CpUsersTable
CpTasksTable.ForeignKeys[1].RefTable = SysUserTable
CpTaskLogsTable.ForeignKeys[0].RefTable = CpTasksTable
CpTaskLogsTable.ForeignKeys[1].RefTable = CpUsersTable
CpTaskLogsTable.ForeignKeys[2].RefTable = SysUserTable
CpUsersTable.ForeignKeys[0].RefTable = SysUserTable
CpUsersTable.ForeignKeys[0].RefTable = CpSchoolsTable
CpUsersTable.ForeignKeys[1].RefTable = SysUserTable
SysAgentTable.ForeignKeys[0].RefTable = SysUserTable
SysAgentTable.Annotation = &entsql.Annotation{
Table: "sys_agent",
+305 -105
View File
@@ -793,12 +793,14 @@ type CpSchoolMutation struct {
config
op Op
typ string
id *int64
id *string
name *string
name_pinyin *string
icon_img *string
tenantId *string
clearedFields map[string]struct{}
cpusers map[int64]struct{}
removedcpusers map[int64]struct{}
clearedcpusers bool
done bool
oldValue func(context.Context) (*CpSchool, error)
predicates []predicate.CpSchool
@@ -824,7 +826,7 @@ func newCpSchoolMutation(c config, op Op, opts ...cpschoolOption) *CpSchoolMutat
}
// withCpSchoolID sets the ID field of the mutation.
func withCpSchoolID(id int64) cpschoolOption {
func withCpSchoolID(id string) cpschoolOption {
return func(m *CpSchoolMutation) {
var (
err error
@@ -874,9 +876,15 @@ func (m CpSchoolMutation) Tx() (*Tx, error) {
return tx, nil
}
// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of CpSchool entities.
func (m *CpSchoolMutation) SetID(id string) {
m.id = &id
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *CpSchoolMutation) ID() (id int64, exists bool) {
func (m *CpSchoolMutation) ID() (id string, exists bool) {
if m.id == nil {
return
}
@@ -887,12 +895,12 @@ func (m *CpSchoolMutation) ID() (id int64, exists bool) {
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *CpSchoolMutation) IDs(ctx context.Context) ([]int64, error) {
func (m *CpSchoolMutation) IDs(ctx context.Context) ([]string, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
return []string{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
@@ -1023,40 +1031,58 @@ func (m *CpSchoolMutation) ResetIconImg() {
delete(m.clearedFields, cpschool.FieldIconImg)
}
// SetTenantId sets the "tenantId" field.
func (m *CpSchoolMutation) SetTenantId(s string) {
m.tenantId = &s
// AddCpuserIDs adds the "cpusers" edge to the CpUser entity by ids.
func (m *CpSchoolMutation) AddCpuserIDs(ids ...int64) {
if m.cpusers == nil {
m.cpusers = make(map[int64]struct{})
}
for i := range ids {
m.cpusers[ids[i]] = struct{}{}
}
}
// TenantId returns the value of the "tenantId" field in the mutation.
func (m *CpSchoolMutation) TenantId() (r string, exists bool) {
v := m.tenantId
if v == nil {
// ClearCpusers clears the "cpusers" edge to the CpUser entity.
func (m *CpSchoolMutation) ClearCpusers() {
m.clearedcpusers = true
}
// CpusersCleared reports if the "cpusers" edge to the CpUser entity was cleared.
func (m *CpSchoolMutation) CpusersCleared() bool {
return m.clearedcpusers
}
// RemoveCpuserIDs removes the "cpusers" edge to the CpUser entity by IDs.
func (m *CpSchoolMutation) RemoveCpuserIDs(ids ...int64) {
if m.removedcpusers == nil {
m.removedcpusers = make(map[int64]struct{})
}
for i := range ids {
delete(m.cpusers, ids[i])
m.removedcpusers[ids[i]] = struct{}{}
}
}
// RemovedCpusers returns the removed IDs of the "cpusers" edge to the CpUser entity.
func (m *CpSchoolMutation) RemovedCpusersIDs() (ids []int64) {
for id := range m.removedcpusers {
ids = append(ids, id)
}
return
}
return *v, true
}
// OldTenantId returns the old "tenantId" field's value of the CpSchool entity.
// If the CpSchool object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *CpSchoolMutation) OldTenantId(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldTenantId is only allowed on UpdateOne operations")
// CpusersIDs returns the "cpusers" edge IDs in the mutation.
func (m *CpSchoolMutation) CpusersIDs() (ids []int64) {
for id := range m.cpusers {
ids = append(ids, id)
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldTenantId requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTenantId: %w", err)
}
return oldValue.TenantId, nil
return
}
// ResetTenantId resets all changes to the "tenantId" field.
func (m *CpSchoolMutation) ResetTenantId() {
m.tenantId = nil
// ResetCpusers resets all changes to the "cpusers" edge.
func (m *CpSchoolMutation) ResetCpusers() {
m.cpusers = nil
m.clearedcpusers = false
m.removedcpusers = nil
}
// Where appends a list predicates to the CpSchoolMutation builder.
@@ -1093,7 +1119,7 @@ func (m *CpSchoolMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *CpSchoolMutation) Fields() []string {
fields := make([]string, 0, 4)
fields := make([]string, 0, 3)
if m.name != nil {
fields = append(fields, cpschool.FieldName)
}
@@ -1103,9 +1129,6 @@ func (m *CpSchoolMutation) Fields() []string {
if m.icon_img != nil {
fields = append(fields, cpschool.FieldIconImg)
}
if m.tenantId != nil {
fields = append(fields, cpschool.FieldTenantId)
}
return fields
}
@@ -1120,8 +1143,6 @@ func (m *CpSchoolMutation) Field(name string) (ent.Value, bool) {
return m.NamePinyin()
case cpschool.FieldIconImg:
return m.IconImg()
case cpschool.FieldTenantId:
return m.TenantId()
}
return nil, false
}
@@ -1137,8 +1158,6 @@ func (m *CpSchoolMutation) OldField(ctx context.Context, name string) (ent.Value
return m.OldNamePinyin(ctx)
case cpschool.FieldIconImg:
return m.OldIconImg(ctx)
case cpschool.FieldTenantId:
return m.OldTenantId(ctx)
}
return nil, fmt.Errorf("unknown CpSchool field %s", name)
}
@@ -1169,13 +1188,6 @@ func (m *CpSchoolMutation) SetField(name string, value ent.Value) error {
}
m.SetIconImg(v)
return nil
case cpschool.FieldTenantId:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetTenantId(v)
return nil
}
return fmt.Errorf("unknown CpSchool field %s", name)
}
@@ -1243,58 +1255,91 @@ func (m *CpSchoolMutation) ResetField(name string) error {
case cpschool.FieldIconImg:
m.ResetIconImg()
return nil
case cpschool.FieldTenantId:
m.ResetTenantId()
return nil
}
return fmt.Errorf("unknown CpSchool field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *CpSchoolMutation) AddedEdges() []string {
edges := make([]string, 0, 0)
edges := make([]string, 0, 1)
if m.cpusers != nil {
edges = append(edges, cpschool.EdgeCpusers)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *CpSchoolMutation) AddedIDs(name string) []ent.Value {
switch name {
case cpschool.EdgeCpusers:
ids := make([]ent.Value, 0, len(m.cpusers))
for id := range m.cpusers {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *CpSchoolMutation) RemovedEdges() []string {
edges := make([]string, 0, 0)
edges := make([]string, 0, 1)
if m.removedcpusers != nil {
edges = append(edges, cpschool.EdgeCpusers)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *CpSchoolMutation) RemovedIDs(name string) []ent.Value {
switch name {
case cpschool.EdgeCpusers:
ids := make([]ent.Value, 0, len(m.removedcpusers))
for id := range m.removedcpusers {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *CpSchoolMutation) ClearedEdges() []string {
edges := make([]string, 0, 0)
edges := make([]string, 0, 1)
if m.clearedcpusers {
edges = append(edges, cpschool.EdgeCpusers)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *CpSchoolMutation) EdgeCleared(name string) bool {
switch name {
case cpschool.EdgeCpusers:
return m.clearedcpusers
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *CpSchoolMutation) ClearEdge(name string) error {
switch name {
}
return fmt.Errorf("unknown CpSchool unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *CpSchoolMutation) ResetEdge(name string) error {
switch name {
case cpschool.EdgeCpusers:
m.ResetCpusers()
return nil
}
return fmt.Errorf("unknown CpSchool edge %s", name)
}
@@ -1304,8 +1349,6 @@ type CpTaskMutation struct {
op Op
typ string
id *int64
user_id *int64
adduser_id *int64
task_type *cptask.TaskType
title *string
frequency *int
@@ -1325,6 +1368,8 @@ type CpTaskMutation struct {
clearedFields map[string]struct{}
cp_user *int64
clearedcp_user bool
sys_user *int64
clearedsys_user bool
cp_task_logs map[int64]struct{}
removedcp_task_logs map[int64]struct{}
clearedcp_task_logs bool
@@ -1469,13 +1514,12 @@ func (m *CpTaskMutation) ResetCpUserID() {
// SetUserID sets the "user_id" field.
func (m *CpTaskMutation) SetUserID(i int64) {
m.user_id = &i
m.adduser_id = nil
m.sys_user = &i
}
// UserID returns the value of the "user_id" field in the mutation.
func (m *CpTaskMutation) UserID() (r int64, exists bool) {
v := m.user_id
v := m.sys_user
if v == nil {
return
}
@@ -1499,28 +1543,9 @@ func (m *CpTaskMutation) OldUserID(ctx context.Context) (v int64, err error) {
return oldValue.UserID, nil
}
// AddUserID adds i to the "user_id" field.
func (m *CpTaskMutation) AddUserID(i int64) {
if m.adduser_id != nil {
*m.adduser_id += i
} else {
m.adduser_id = &i
}
}
// AddedUserID returns the value that was added to the "user_id" field in this mutation.
func (m *CpTaskMutation) AddedUserID() (r int64, exists bool) {
v := m.adduser_id
if v == nil {
return
}
return *v, true
}
// ResetUserID resets all changes to the "user_id" field.
func (m *CpTaskMutation) ResetUserID() {
m.user_id = nil
m.adduser_id = nil
m.sys_user = nil
}
// SetTaskType sets the "task_type" field.
@@ -2101,6 +2126,46 @@ func (m *CpTaskMutation) ResetCpUser() {
m.clearedcp_user = false
}
// SetSysUserID sets the "sys_user" edge to the SysUser entity by id.
func (m *CpTaskMutation) SetSysUserID(id int64) {
m.sys_user = &id
}
// ClearSysUser clears the "sys_user" edge to the SysUser entity.
func (m *CpTaskMutation) ClearSysUser() {
m.clearedsys_user = true
m.clearedFields[cptask.FieldUserID] = struct{}{}
}
// SysUserCleared reports if the "sys_user" edge to the SysUser entity was cleared.
func (m *CpTaskMutation) SysUserCleared() bool {
return m.clearedsys_user
}
// SysUserID returns the "sys_user" edge ID in the mutation.
func (m *CpTaskMutation) SysUserID() (id int64, exists bool) {
if m.sys_user != nil {
return *m.sys_user, true
}
return
}
// SysUserIDs returns the "sys_user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// SysUserID instead. It exists only for internal usage by the builders.
func (m *CpTaskMutation) SysUserIDs() (ids []int64) {
if id := m.sys_user; id != nil {
ids = append(ids, *id)
}
return
}
// ResetSysUser resets all changes to the "sys_user" edge.
func (m *CpTaskMutation) ResetSysUser() {
m.sys_user = nil
m.clearedsys_user = false
}
// AddCpTaskLogIDs adds the "cp_task_logs" edge to the CpTaskLog entity by ids.
func (m *CpTaskMutation) AddCpTaskLogIDs(ids ...int64) {
if m.cp_task_logs == nil {
@@ -2193,7 +2258,7 @@ func (m *CpTaskMutation) Fields() []string {
if m.cp_user != nil {
fields = append(fields, cptask.FieldCpUserID)
}
if m.user_id != nil {
if m.sys_user != nil {
fields = append(fields, cptask.FieldUserID)
}
if m.task_type != nil {
@@ -2406,9 +2471,6 @@ func (m *CpTaskMutation) SetField(name string, value ent.Value) error {
// this mutation.
func (m *CpTaskMutation) AddedFields() []string {
var fields []string
if m.adduser_id != nil {
fields = append(fields, cptask.FieldUserID)
}
if m.addfrequency != nil {
fields = append(fields, cptask.FieldFrequency)
}
@@ -2432,8 +2494,6 @@ func (m *CpTaskMutation) AddedFields() []string {
// was not set, or was not defined in the schema.
func (m *CpTaskMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case cptask.FieldUserID:
return m.AddedUserID()
case cptask.FieldFrequency:
return m.AddedFrequency()
case cptask.FieldSuccessCount:
@@ -2453,13 +2513,6 @@ func (m *CpTaskMutation) AddedField(name string) (ent.Value, bool) {
// type.
func (m *CpTaskMutation) AddField(name string, value ent.Value) error {
switch name {
case cptask.FieldUserID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddUserID(v)
return nil
case cptask.FieldFrequency:
v, ok := value.(int)
if !ok {
@@ -2594,10 +2647,13 @@ func (m *CpTaskMutation) ResetField(name string) error {
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *CpTaskMutation) AddedEdges() []string {
edges := make([]string, 0, 2)
edges := make([]string, 0, 3)
if m.cp_user != nil {
edges = append(edges, cptask.EdgeCpUser)
}
if m.sys_user != nil {
edges = append(edges, cptask.EdgeSysUser)
}
if m.cp_task_logs != nil {
edges = append(edges, cptask.EdgeCpTaskLogs)
}
@@ -2612,6 +2668,10 @@ func (m *CpTaskMutation) AddedIDs(name string) []ent.Value {
if id := m.cp_user; id != nil {
return []ent.Value{*id}
}
case cptask.EdgeSysUser:
if id := m.sys_user; id != nil {
return []ent.Value{*id}
}
case cptask.EdgeCpTaskLogs:
ids := make([]ent.Value, 0, len(m.cp_task_logs))
for id := range m.cp_task_logs {
@@ -2624,7 +2684,7 @@ func (m *CpTaskMutation) AddedIDs(name string) []ent.Value {
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *CpTaskMutation) RemovedEdges() []string {
edges := make([]string, 0, 2)
edges := make([]string, 0, 3)
if m.removedcp_task_logs != nil {
edges = append(edges, cptask.EdgeCpTaskLogs)
}
@@ -2647,10 +2707,13 @@ func (m *CpTaskMutation) RemovedIDs(name string) []ent.Value {
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *CpTaskMutation) ClearedEdges() []string {
edges := make([]string, 0, 2)
edges := make([]string, 0, 3)
if m.clearedcp_user {
edges = append(edges, cptask.EdgeCpUser)
}
if m.clearedsys_user {
edges = append(edges, cptask.EdgeSysUser)
}
if m.clearedcp_task_logs {
edges = append(edges, cptask.EdgeCpTaskLogs)
}
@@ -2663,6 +2726,8 @@ func (m *CpTaskMutation) EdgeCleared(name string) bool {
switch name {
case cptask.EdgeCpUser:
return m.clearedcp_user
case cptask.EdgeSysUser:
return m.clearedsys_user
case cptask.EdgeCpTaskLogs:
return m.clearedcp_task_logs
}
@@ -2676,6 +2741,9 @@ func (m *CpTaskMutation) ClearEdge(name string) error {
case cptask.EdgeCpUser:
m.ClearCpUser()
return nil
case cptask.EdgeSysUser:
m.ClearSysUser()
return nil
}
return fmt.Errorf("unknown CpTask unique edge %s", name)
}
@@ -2687,6 +2755,9 @@ func (m *CpTaskMutation) ResetEdge(name string) error {
case cptask.EdgeCpUser:
m.ResetCpUser()
return nil
case cptask.EdgeSysUser:
m.ResetSysUser()
return nil
case cptask.EdgeCpTaskLogs:
m.ResetCpTaskLogs()
return nil
@@ -3488,7 +3559,6 @@ type CpUserMutation struct {
id *int64
username *string
password *string
school_id *string
email *string
mobile_code *string
cookie *string
@@ -3502,6 +3572,8 @@ type CpUserMutation struct {
cp_task_logs map[int64]struct{}
removedcp_task_logs map[int64]struct{}
clearedcp_task_logs bool
school *string
clearedschool bool
done bool
oldValue func(context.Context) (*CpUser, error)
predicates []predicate.CpUser
@@ -3715,12 +3787,12 @@ func (m *CpUserMutation) ResetPassword() {
// SetSchoolID sets the "school_id" field.
func (m *CpUserMutation) SetSchoolID(s string) {
m.school_id = &s
m.school = &s
}
// SchoolID returns the value of the "school_id" field in the mutation.
func (m *CpUserMutation) SchoolID() (r string, exists bool) {
v := m.school_id
v := m.school
if v == nil {
return
}
@@ -3746,7 +3818,7 @@ func (m *CpUserMutation) OldSchoolID(ctx context.Context) (v string, err error)
// ResetSchoolID resets all changes to the "school_id" field.
func (m *CpUserMutation) ResetSchoolID() {
m.school_id = nil
m.school = nil
}
// SetEmail sets the "email" field.
@@ -4080,6 +4152,33 @@ func (m *CpUserMutation) ResetCpTaskLogs() {
m.removedcp_task_logs = nil
}
// ClearSchool clears the "school" edge to the CpSchool entity.
func (m *CpUserMutation) ClearSchool() {
m.clearedschool = true
m.clearedFields[cpuser.FieldSchoolID] = struct{}{}
}
// SchoolCleared reports if the "school" edge to the CpSchool entity was cleared.
func (m *CpUserMutation) SchoolCleared() bool {
return m.clearedschool
}
// SchoolIDs returns the "school" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// SchoolID instead. It exists only for internal usage by the builders.
func (m *CpUserMutation) SchoolIDs() (ids []string) {
if id := m.school; id != nil {
ids = append(ids, *id)
}
return
}
// ResetSchool resets all changes to the "school" edge.
func (m *CpUserMutation) ResetSchool() {
m.school = nil
m.clearedschool = false
}
// Where appends a list predicates to the CpUserMutation builder.
func (m *CpUserMutation) Where(ps ...predicate.CpUser) {
m.predicates = append(m.predicates, ps...)
@@ -4124,7 +4223,7 @@ func (m *CpUserMutation) Fields() []string {
if m.password != nil {
fields = append(fields, cpuser.FieldPassword)
}
if m.school_id != nil {
if m.school != nil {
fields = append(fields, cpuser.FieldSchoolID)
}
if m.email != nil {
@@ -4356,7 +4455,7 @@ func (m *CpUserMutation) ResetField(name string) error {
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *CpUserMutation) AddedEdges() []string {
edges := make([]string, 0, 3)
edges := make([]string, 0, 4)
if m.cptasks != nil {
edges = append(edges, cpuser.EdgeCptasks)
}
@@ -4366,6 +4465,9 @@ func (m *CpUserMutation) AddedEdges() []string {
if m.cp_task_logs != nil {
edges = append(edges, cpuser.EdgeCpTaskLogs)
}
if m.school != nil {
edges = append(edges, cpuser.EdgeSchool)
}
return edges
}
@@ -4389,13 +4491,17 @@ func (m *CpUserMutation) AddedIDs(name string) []ent.Value {
ids = append(ids, id)
}
return ids
case cpuser.EdgeSchool:
if id := m.school; id != nil {
return []ent.Value{*id}
}
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *CpUserMutation) RemovedEdges() []string {
edges := make([]string, 0, 3)
edges := make([]string, 0, 4)
if m.removedcptasks != nil {
edges = append(edges, cpuser.EdgeCptasks)
}
@@ -4427,7 +4533,7 @@ func (m *CpUserMutation) RemovedIDs(name string) []ent.Value {
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *CpUserMutation) ClearedEdges() []string {
edges := make([]string, 0, 3)
edges := make([]string, 0, 4)
if m.clearedcptasks {
edges = append(edges, cpuser.EdgeCptasks)
}
@@ -4437,6 +4543,9 @@ func (m *CpUserMutation) ClearedEdges() []string {
if m.clearedcp_task_logs {
edges = append(edges, cpuser.EdgeCpTaskLogs)
}
if m.clearedschool {
edges = append(edges, cpuser.EdgeSchool)
}
return edges
}
@@ -4450,6 +4559,8 @@ func (m *CpUserMutation) EdgeCleared(name string) bool {
return m.clearedsysuser
case cpuser.EdgeCpTaskLogs:
return m.clearedcp_task_logs
case cpuser.EdgeSchool:
return m.clearedschool
}
return false
}
@@ -4461,6 +4572,9 @@ func (m *CpUserMutation) ClearEdge(name string) error {
case cpuser.EdgeSysuser:
m.ClearSysuser()
return nil
case cpuser.EdgeSchool:
m.ClearSchool()
return nil
}
return fmt.Errorf("unknown CpUser unique edge %s", name)
}
@@ -4478,6 +4592,9 @@ func (m *CpUserMutation) ResetEdge(name string) error {
case cpuser.EdgeCpTaskLogs:
m.ResetCpTaskLogs()
return nil
case cpuser.EdgeSchool:
m.ResetSchool()
return nil
}
return fmt.Errorf("unknown CpUser edge %s", name)
}
@@ -8211,6 +8328,9 @@ type SysUserMutation struct {
cpuser map[int64]struct{}
removedcpuser map[int64]struct{}
clearedcpuser bool
cp_task map[int64]struct{}
removedcp_task map[int64]struct{}
clearedcp_task bool
cp_task_logs map[int64]struct{}
removedcp_task_logs map[int64]struct{}
clearedcp_task_logs bool
@@ -8993,6 +9113,60 @@ func (m *SysUserMutation) ResetCpuser() {
m.removedcpuser = nil
}
// AddCpTaskIDs adds the "cp_task" edge to the CpTask entity by ids.
func (m *SysUserMutation) AddCpTaskIDs(ids ...int64) {
if m.cp_task == nil {
m.cp_task = make(map[int64]struct{})
}
for i := range ids {
m.cp_task[ids[i]] = struct{}{}
}
}
// ClearCpTask clears the "cp_task" edge to the CpTask entity.
func (m *SysUserMutation) ClearCpTask() {
m.clearedcp_task = true
}
// CpTaskCleared reports if the "cp_task" edge to the CpTask entity was cleared.
func (m *SysUserMutation) CpTaskCleared() bool {
return m.clearedcp_task
}
// RemoveCpTaskIDs removes the "cp_task" edge to the CpTask entity by IDs.
func (m *SysUserMutation) RemoveCpTaskIDs(ids ...int64) {
if m.removedcp_task == nil {
m.removedcp_task = make(map[int64]struct{})
}
for i := range ids {
delete(m.cp_task, ids[i])
m.removedcp_task[ids[i]] = struct{}{}
}
}
// RemovedCpTask returns the removed IDs of the "cp_task" edge to the CpTask entity.
func (m *SysUserMutation) RemovedCpTaskIDs() (ids []int64) {
for id := range m.removedcp_task {
ids = append(ids, id)
}
return
}
// CpTaskIDs returns the "cp_task" edge IDs in the mutation.
func (m *SysUserMutation) CpTaskIDs() (ids []int64) {
for id := range m.cp_task {
ids = append(ids, id)
}
return
}
// ResetCpTask resets all changes to the "cp_task" edge.
func (m *SysUserMutation) ResetCpTask() {
m.cp_task = nil
m.clearedcp_task = false
m.removedcp_task = nil
}
// AddCpTaskLogIDs adds the "cp_task_logs" edge to the CpTaskLog entity by ids.
func (m *SysUserMutation) AddCpTaskLogIDs(ids ...int64) {
if m.cp_task_logs == nil {
@@ -9504,7 +9678,7 @@ func (m *SysUserMutation) ResetField(name string) error {
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *SysUserMutation) AddedEdges() []string {
edges := make([]string, 0, 10)
edges := make([]string, 0, 11)
if m.parent != nil {
edges = append(edges, sysuser.EdgeParent)
}
@@ -9523,6 +9697,9 @@ func (m *SysUserMutation) AddedEdges() []string {
if m.cpuser != nil {
edges = append(edges, sysuser.EdgeCpuser)
}
if m.cp_task != nil {
edges = append(edges, sysuser.EdgeCpTask)
}
if m.cp_task_logs != nil {
edges = append(edges, sysuser.EdgeCpTaskLogs)
}
@@ -9574,6 +9751,12 @@ func (m *SysUserMutation) AddedIDs(name string) []ent.Value {
ids = append(ids, id)
}
return ids
case sysuser.EdgeCpTask:
ids := make([]ent.Value, 0, len(m.cp_task))
for id := range m.cp_task {
ids = append(ids, id)
}
return ids
case sysuser.EdgeCpTaskLogs:
ids := make([]ent.Value, 0, len(m.cp_task_logs))
for id := range m.cp_task_logs {
@@ -9604,7 +9787,7 @@ func (m *SysUserMutation) AddedIDs(name string) []ent.Value {
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *SysUserMutation) RemovedEdges() []string {
edges := make([]string, 0, 10)
edges := make([]string, 0, 11)
if m.removedchildren != nil {
edges = append(edges, sysuser.EdgeChildren)
}
@@ -9617,6 +9800,9 @@ func (m *SysUserMutation) RemovedEdges() []string {
if m.removedcpuser != nil {
edges = append(edges, sysuser.EdgeCpuser)
}
if m.removedcp_task != nil {
edges = append(edges, sysuser.EdgeCpTask)
}
if m.removedcp_task_logs != nil {
edges = append(edges, sysuser.EdgeCpTaskLogs)
}
@@ -9660,6 +9846,12 @@ func (m *SysUserMutation) RemovedIDs(name string) []ent.Value {
ids = append(ids, id)
}
return ids
case sysuser.EdgeCpTask:
ids := make([]ent.Value, 0, len(m.removedcp_task))
for id := range m.removedcp_task {
ids = append(ids, id)
}
return ids
case sysuser.EdgeCpTaskLogs:
ids := make([]ent.Value, 0, len(m.removedcp_task_logs))
for id := range m.removedcp_task_logs {
@@ -9690,7 +9882,7 @@ func (m *SysUserMutation) RemovedIDs(name string) []ent.Value {
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *SysUserMutation) ClearedEdges() []string {
edges := make([]string, 0, 10)
edges := make([]string, 0, 11)
if m.clearedparent {
edges = append(edges, sysuser.EdgeParent)
}
@@ -9709,6 +9901,9 @@ func (m *SysUserMutation) ClearedEdges() []string {
if m.clearedcpuser {
edges = append(edges, sysuser.EdgeCpuser)
}
if m.clearedcp_task {
edges = append(edges, sysuser.EdgeCpTask)
}
if m.clearedcp_task_logs {
edges = append(edges, sysuser.EdgeCpTaskLogs)
}
@@ -9740,6 +9935,8 @@ func (m *SysUserMutation) EdgeCleared(name string) bool {
return m.clearedimages
case sysuser.EdgeCpuser:
return m.clearedcpuser
case sysuser.EdgeCpTask:
return m.clearedcp_task
case sysuser.EdgeCpTaskLogs:
return m.clearedcp_task_logs
case sysuser.EdgeCreatedCards:
@@ -9788,6 +9985,9 @@ func (m *SysUserMutation) ResetEdge(name string) error {
case sysuser.EdgeCpuser:
m.ResetCpuser()
return nil
case sysuser.EdgeCpTask:
m.ResetCpTask()
return nil
case sysuser.EdgeCpTaskLogs:
m.ResetCpTaskLogs()
return nil
+4
View File
@@ -58,6 +58,10 @@ func init() {
cptaskDescTitle := cptaskFields[3].Descriptor()
// cptask.TitleValidator is a validator for the "title" field. It is called by the builders before save.
cptask.TitleValidator = cptaskDescTitle.Validators[0].(func(string) error)
// cptaskDescFrequency is the schema descriptor for frequency field.
cptaskDescFrequency := cptaskFields[4].Descriptor()
// cptask.DefaultFrequency holds the default value on creation for the frequency field.
cptask.DefaultFrequency = cptaskDescFrequency.Default.(int)
// cptaskDescSuccessCount is the schema descriptor for success_count field.
cptaskDescSuccessCount := cptaskFields[6].Descriptor()
// cptask.DefaultSuccessCount holds the default value on creation for the success_count field.
+9 -1
View File
@@ -2,6 +2,7 @@ package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
@@ -15,6 +16,13 @@ func (CpSchool) Fields() []ent.Field {
field.String("name"),
field.String("name_pinyin"),
field.String("icon_img").Optional(),
field.String("tenantId"),
field.String("id").Unique(),
}
}
// Edges of the CpSchool.
func (CpSchool) Edges() []ent.Edge {
return []ent.Edge{
edge.To("cpusers", CpUser.Type),
}
}
+2 -1
View File
@@ -19,7 +19,7 @@ func (CpTask) Fields() []ent.Field {
field.Int64("user_id"),
field.Enum("task_type").Values("collection", "sign", "sleep_check"),
field.String("title").NotEmpty(),
field.Int("frequency"),
field.Int("frequency").Default(0),
field.Enum("task_status").Values("not_start", "doing", "done", "fail", "unknown"),
field.Int("success_count").Default(0),
field.String("form_data").Optional(),
@@ -35,6 +35,7 @@ func (CpTask) Fields() []ent.Field {
func (CpTask) Edges() []ent.Edge {
return []ent.Edge{
edge.From("cp_user", CpUser.Type).Ref("cptasks").Field("cp_user_id").Unique().Required().Annotations(entsql.OnDelete(entsql.Cascade)),
edge.From("sys_user", SysUser.Type).Ref("cp_task").Field("user_id").Unique().Required().Annotations(entsql.OnDelete(entsql.Cascade)),
edge.To("cp_task_logs", CpTaskLog.Type), // 任务拥有的cp任务日志
}
}
+6 -1
View File
@@ -21,7 +21,7 @@ func (CpUser) Fields() []ent.Field {
field.String("school_id").NotEmpty(),
field.String("email").Optional(),
field.String("mobile_code").Optional(),
field.String("cookie").Optional(),
field.Text("cookie").Optional(),
field.Enum("mobile_type").Values("random", "authorize"),
}
}
@@ -32,5 +32,10 @@ func (CpUser) Edges() []ent.Edge {
edge.To("cptasks", CpTask.Type),
edge.From("sysuser", SysUser.Type).Unique().Required().Field("user_id").Ref("cpuser").Annotations(entsql.OnDelete(entsql.Cascade)),
edge.To("cp_task_logs", CpTaskLog.Type), // 用户拥有的cp任务日志
edge.From("school", CpSchool.Type).
Ref("cpusers").
Field("school_id").
Unique().
Required(),
}
}
+1
View File
@@ -50,6 +50,7 @@ func (SysUser) Edges() []ent.Edge {
edge.To("agent", SysAgent.Type).Unique(), // 用户拥有代理
edge.To("images", CpImage.Type), // 用户拥有的图片
edge.To("cpuser", CpUser.Type), // 用户拥有的cp用户
edge.To("cp_task", CpTask.Type),
edge.To("cp_task_logs", CpTaskLog.Type), // 用户拥有的cp任务日志
edge.To("created_cards", SysCard.Type), // 用户创建的卡
edge.To("used_cards", SysCard.Type), // 用户使用的卡
+21 -5
View File
@@ -60,6 +60,8 @@ type SysUserEdges struct {
Images []*CpImage `json:"images,omitempty"`
// Cpuser holds the value of the cpuser edge.
Cpuser []*CpUser `json:"cpuser,omitempty"`
// CpTask holds the value of the cp_task edge.
CpTask []*CpTask `json:"cp_task,omitempty"`
// CpTaskLogs holds the value of the cp_task_logs edge.
CpTaskLogs []*CpTaskLog `json:"cp_task_logs,omitempty"`
// CreatedCards holds the value of the created_cards edge.
@@ -70,7 +72,7 @@ type SysUserEdges struct {
CashbackCards []*SysCard `json:"cashback_cards,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [10]bool
loadedTypes [11]bool
}
// ParentOrErr returns the Parent value or an error if the edge
@@ -131,10 +133,19 @@ func (e SysUserEdges) CpuserOrErr() ([]*CpUser, error) {
return nil, &NotLoadedError{edge: "cpuser"}
}
// CpTaskOrErr returns the CpTask value or an error if the edge
// was not loaded in eager-loading.
func (e SysUserEdges) CpTaskOrErr() ([]*CpTask, error) {
if e.loadedTypes[6] {
return e.CpTask, nil
}
return nil, &NotLoadedError{edge: "cp_task"}
}
// CpTaskLogsOrErr returns the CpTaskLogs value or an error if the edge
// was not loaded in eager-loading.
func (e SysUserEdges) CpTaskLogsOrErr() ([]*CpTaskLog, error) {
if e.loadedTypes[6] {
if e.loadedTypes[7] {
return e.CpTaskLogs, nil
}
return nil, &NotLoadedError{edge: "cp_task_logs"}
@@ -143,7 +154,7 @@ func (e SysUserEdges) CpTaskLogsOrErr() ([]*CpTaskLog, error) {
// CreatedCardsOrErr returns the CreatedCards value or an error if the edge
// was not loaded in eager-loading.
func (e SysUserEdges) CreatedCardsOrErr() ([]*SysCard, error) {
if e.loadedTypes[7] {
if e.loadedTypes[8] {
return e.CreatedCards, nil
}
return nil, &NotLoadedError{edge: "created_cards"}
@@ -152,7 +163,7 @@ func (e SysUserEdges) CreatedCardsOrErr() ([]*SysCard, error) {
// UsedCardsOrErr returns the UsedCards value or an error if the edge
// was not loaded in eager-loading.
func (e SysUserEdges) UsedCardsOrErr() ([]*SysCard, error) {
if e.loadedTypes[8] {
if e.loadedTypes[9] {
return e.UsedCards, nil
}
return nil, &NotLoadedError{edge: "used_cards"}
@@ -161,7 +172,7 @@ func (e SysUserEdges) UsedCardsOrErr() ([]*SysCard, error) {
// CashbackCardsOrErr returns the CashbackCards value or an error if the edge
// was not loaded in eager-loading.
func (e SysUserEdges) CashbackCardsOrErr() ([]*SysCard, error) {
if e.loadedTypes[9] {
if e.loadedTypes[10] {
return e.CashbackCards, nil
}
return nil, &NotLoadedError{edge: "cashback_cards"}
@@ -315,6 +326,11 @@ func (_m *SysUser) QueryCpuser() *CpUserQuery {
return NewSysUserClient(_m.config).QueryCpuser(_m)
}
// QueryCpTask queries the "cp_task" edge of the SysUser entity.
func (_m *SysUser) QueryCpTask() *CpTaskQuery {
return NewSysUserClient(_m.config).QueryCpTask(_m)
}
// QueryCpTaskLogs queries the "cp_task_logs" edge of the SysUser entity.
func (_m *SysUser) QueryCpTaskLogs() *CpTaskLogQuery {
return NewSysUserClient(_m.config).QueryCpTaskLogs(_m)
+30
View File
@@ -48,6 +48,8 @@ const (
EdgeImages = "images"
// EdgeCpuser holds the string denoting the cpuser edge name in mutations.
EdgeCpuser = "cpuser"
// EdgeCpTask holds the string denoting the cp_task edge name in mutations.
EdgeCpTask = "cp_task"
// EdgeCpTaskLogs holds the string denoting the cp_task_logs edge name in mutations.
EdgeCpTaskLogs = "cp_task_logs"
// EdgeCreatedCards holds the string denoting the created_cards edge name in mutations.
@@ -92,6 +94,13 @@ const (
CpuserInverseTable = "cp_users"
// CpuserColumn is the table column denoting the cpuser relation/edge.
CpuserColumn = "user_id"
// CpTaskTable is the table that holds the cp_task relation/edge.
CpTaskTable = "cp_tasks"
// CpTaskInverseTable is the table name for the CpTask entity.
// It exists in this package in order to avoid circular dependency with the "cptask" package.
CpTaskInverseTable = "cp_tasks"
// CpTaskColumn is the table column denoting the cp_task relation/edge.
CpTaskColumn = "user_id"
// CpTaskLogsTable is the table that holds the cp_task_logs relation/edge.
CpTaskLogsTable = "cp_task_logs"
// CpTaskLogsInverseTable is the table name for the CpTaskLog entity.
@@ -315,6 +324,20 @@ func ByCpuser(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
}
}
// ByCpTaskCount orders the results by cp_task count.
func ByCpTaskCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newCpTaskStep(), opts...)
}
}
// ByCpTask orders the results by cp_task terms.
func ByCpTask(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newCpTaskStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
// ByCpTaskLogsCount orders the results by cp_task_logs count.
func ByCpTaskLogsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
@@ -412,6 +435,13 @@ func newCpuserStep() *sqlgraph.Step {
sqlgraph.Edge(sqlgraph.O2M, false, CpuserTable, CpuserColumn),
)
}
func newCpTaskStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(CpTaskInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, CpTaskTable, CpTaskColumn),
)
}
func newCpTaskLogsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
+23
View File
@@ -814,6 +814,29 @@ func HasCpuserWith(preds ...predicate.CpUser) predicate.SysUser {
})
}
// HasCpTask applies the HasEdge predicate on the "cp_task" edge.
func HasCpTask() predicate.SysUser {
return predicate.SysUser(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, CpTaskTable, CpTaskColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasCpTaskWith applies the HasEdge predicate on the "cp_task" edge with a given conditions (other predicates).
func HasCpTaskWith(preds ...predicate.CpTask) predicate.SysUser {
return predicate.SysUser(func(s *sql.Selector) {
step := newCpTaskStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasCpTaskLogs applies the HasEdge predicate on the "cp_task_logs" edge.
func HasCpTaskLogs() predicate.SysUser {
return predicate.SysUser(func(s *sql.Selector) {
+32
View File
@@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"likedream-goframe/internal/ent/cpimage"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/sysagent"
@@ -227,6 +228,21 @@ func (_c *SysUserCreate) AddCpuser(v ...*CpUser) *SysUserCreate {
return _c.AddCpuserIDs(ids...)
}
// AddCpTaskIDs adds the "cp_task" edge to the CpTask entity by IDs.
func (_c *SysUserCreate) AddCpTaskIDs(ids ...int64) *SysUserCreate {
_c.mutation.AddCpTaskIDs(ids...)
return _c
}
// AddCpTask adds the "cp_task" edges to the CpTask entity.
func (_c *SysUserCreate) AddCpTask(v ...*CpTask) *SysUserCreate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddCpTaskIDs(ids...)
}
// AddCpTaskLogIDs adds the "cp_task_logs" edge to the CpTaskLog entity by IDs.
func (_c *SysUserCreate) AddCpTaskLogIDs(ids ...int64) *SysUserCreate {
_c.mutation.AddCpTaskLogIDs(ids...)
@@ -561,6 +577,22 @@ func (_c *SysUserCreate) createSpec() (*SysUser, *sqlgraph.CreateSpec) {
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.CpTaskIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: sysuser.CpTaskTable,
Columns: []string{sysuser.CpTaskColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cptask.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.CpTaskLogsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
+75 -1
View File
@@ -7,6 +7,7 @@ import (
"database/sql/driver"
"fmt"
"likedream-goframe/internal/ent/cpimage"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/predicate"
@@ -35,6 +36,7 @@ type SysUserQuery struct {
withAgent *SysAgentQuery
withImages *CpImageQuery
withCpuser *CpUserQuery
withCpTask *CpTaskQuery
withCpTaskLogs *CpTaskLogQuery
withCreatedCards *SysCardQuery
withUsedCards *SysCardQuery
@@ -208,6 +210,28 @@ func (_q *SysUserQuery) QueryCpuser() *CpUserQuery {
return query
}
// QueryCpTask chains the current query on the "cp_task" edge.
func (_q *SysUserQuery) QueryCpTask() *CpTaskQuery {
query := (&CpTaskClient{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(cptask.Table, cptask.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, sysuser.CpTaskTable, sysuser.CpTaskColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryCpTaskLogs chains the current query on the "cp_task_logs" edge.
func (_q *SysUserQuery) QueryCpTaskLogs() *CpTaskLogQuery {
query := (&CpTaskLogClient{config: _q.config}).Query()
@@ -494,6 +518,7 @@ func (_q *SysUserQuery) Clone() *SysUserQuery {
withAgent: _q.withAgent.Clone(),
withImages: _q.withImages.Clone(),
withCpuser: _q.withCpuser.Clone(),
withCpTask: _q.withCpTask.Clone(),
withCpTaskLogs: _q.withCpTaskLogs.Clone(),
withCreatedCards: _q.withCreatedCards.Clone(),
withUsedCards: _q.withUsedCards.Clone(),
@@ -570,6 +595,17 @@ func (_q *SysUserQuery) WithCpuser(opts ...func(*CpUserQuery)) *SysUserQuery {
return _q
}
// WithCpTask tells the query-builder to eager-load the nodes that are connected to
// the "cp_task" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *SysUserQuery) WithCpTask(opts ...func(*CpTaskQuery)) *SysUserQuery {
query := (&CpTaskClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withCpTask = query
return _q
}
// WithCpTaskLogs tells the query-builder to eager-load the nodes that are connected to
// the "cp_task_logs" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *SysUserQuery) WithCpTaskLogs(opts ...func(*CpTaskLogQuery)) *SysUserQuery {
@@ -693,13 +729,14 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
nodes = []*SysUser{}
withFKs = _q.withFKs
_spec = _q.querySpec()
loadedTypes = [10]bool{
loadedTypes = [11]bool{
_q.withParent != nil,
_q.withChildren != nil,
_q.withRoles != nil,
_q.withAgent != nil,
_q.withImages != nil,
_q.withCpuser != nil,
_q.withCpTask != nil,
_q.withCpTaskLogs != nil,
_q.withCreatedCards != nil,
_q.withUsedCards != nil,
@@ -770,6 +807,13 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
return nil, err
}
}
if query := _q.withCpTask; query != nil {
if err := _q.loadCpTask(ctx, query, nodes,
func(n *SysUser) { n.Edges.CpTask = []*CpTask{} },
func(n *SysUser, e *CpTask) { n.Edges.CpTask = append(n.Edges.CpTask, e) }); err != nil {
return nil, err
}
}
if query := _q.withCpTaskLogs; query != nil {
if err := _q.loadCpTaskLogs(ctx, query, nodes,
func(n *SysUser) { n.Edges.CpTaskLogs = []*CpTaskLog{} },
@@ -1013,6 +1057,36 @@ func (_q *SysUserQuery) loadCpuser(ctx context.Context, query *CpUserQuery, node
}
return nil
}
func (_q *SysUserQuery) loadCpTask(ctx context.Context, query *CpTaskQuery, nodes []*SysUser, init func(*SysUser), assign func(*SysUser, *CpTask)) 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(cptask.FieldUserID)
}
query.Where(predicate.CpTask(func(s *sql.Selector) {
s.Where(sql.InValues(s.C(sysuser.CpTaskColumn), 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) loadCpTaskLogs(ctx context.Context, query *CpTaskLogQuery, nodes []*SysUser, init func(*SysUser), assign func(*SysUser, *CpTaskLog)) error {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[int64]*SysUser)
+163
View File
@@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"likedream-goframe/internal/ent/cpimage"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/predicate"
@@ -257,6 +258,21 @@ func (_u *SysUserUpdate) AddCpuser(v ...*CpUser) *SysUserUpdate {
return _u.AddCpuserIDs(ids...)
}
// AddCpTaskIDs adds the "cp_task" edge to the CpTask entity by IDs.
func (_u *SysUserUpdate) AddCpTaskIDs(ids ...int64) *SysUserUpdate {
_u.mutation.AddCpTaskIDs(ids...)
return _u
}
// AddCpTask adds the "cp_task" edges to the CpTask entity.
func (_u *SysUserUpdate) AddCpTask(v ...*CpTask) *SysUserUpdate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddCpTaskIDs(ids...)
}
// AddCpTaskLogIDs adds the "cp_task_logs" edge to the CpTaskLog entity by IDs.
func (_u *SysUserUpdate) AddCpTaskLogIDs(ids ...int64) *SysUserUpdate {
_u.mutation.AddCpTaskLogIDs(ids...)
@@ -418,6 +434,27 @@ func (_u *SysUserUpdate) RemoveCpuser(v ...*CpUser) *SysUserUpdate {
return _u.RemoveCpuserIDs(ids...)
}
// ClearCpTask clears all "cp_task" edges to the CpTask entity.
func (_u *SysUserUpdate) ClearCpTask() *SysUserUpdate {
_u.mutation.ClearCpTask()
return _u
}
// RemoveCpTaskIDs removes the "cp_task" edge to CpTask entities by IDs.
func (_u *SysUserUpdate) RemoveCpTaskIDs(ids ...int64) *SysUserUpdate {
_u.mutation.RemoveCpTaskIDs(ids...)
return _u
}
// RemoveCpTask removes "cp_task" edges to CpTask entities.
func (_u *SysUserUpdate) RemoveCpTask(v ...*CpTask) *SysUserUpdate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveCpTaskIDs(ids...)
}
// ClearCpTaskLogs clears all "cp_task_logs" edges to the CpTaskLog entity.
func (_u *SysUserUpdate) ClearCpTaskLogs() *SysUserUpdate {
_u.mutation.ClearCpTaskLogs()
@@ -819,6 +856,51 @@ func (_u *SysUserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.CpTaskCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: sysuser.CpTaskTable,
Columns: []string{sysuser.CpTaskColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cptask.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedCpTaskIDs(); len(nodes) > 0 && !_u.mutation.CpTaskCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: sysuser.CpTaskTable,
Columns: []string{sysuser.CpTaskColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cptask.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.CpTaskIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: sysuser.CpTaskTable,
Columns: []string{sysuser.CpTaskColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cptask.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.CpTaskLogsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
@@ -1241,6 +1323,21 @@ func (_u *SysUserUpdateOne) AddCpuser(v ...*CpUser) *SysUserUpdateOne {
return _u.AddCpuserIDs(ids...)
}
// AddCpTaskIDs adds the "cp_task" edge to the CpTask entity by IDs.
func (_u *SysUserUpdateOne) AddCpTaskIDs(ids ...int64) *SysUserUpdateOne {
_u.mutation.AddCpTaskIDs(ids...)
return _u
}
// AddCpTask adds the "cp_task" edges to the CpTask entity.
func (_u *SysUserUpdateOne) AddCpTask(v ...*CpTask) *SysUserUpdateOne {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddCpTaskIDs(ids...)
}
// AddCpTaskLogIDs adds the "cp_task_logs" edge to the CpTaskLog entity by IDs.
func (_u *SysUserUpdateOne) AddCpTaskLogIDs(ids ...int64) *SysUserUpdateOne {
_u.mutation.AddCpTaskLogIDs(ids...)
@@ -1402,6 +1499,27 @@ func (_u *SysUserUpdateOne) RemoveCpuser(v ...*CpUser) *SysUserUpdateOne {
return _u.RemoveCpuserIDs(ids...)
}
// ClearCpTask clears all "cp_task" edges to the CpTask entity.
func (_u *SysUserUpdateOne) ClearCpTask() *SysUserUpdateOne {
_u.mutation.ClearCpTask()
return _u
}
// RemoveCpTaskIDs removes the "cp_task" edge to CpTask entities by IDs.
func (_u *SysUserUpdateOne) RemoveCpTaskIDs(ids ...int64) *SysUserUpdateOne {
_u.mutation.RemoveCpTaskIDs(ids...)
return _u
}
// RemoveCpTask removes "cp_task" edges to CpTask entities.
func (_u *SysUserUpdateOne) RemoveCpTask(v ...*CpTask) *SysUserUpdateOne {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveCpTaskIDs(ids...)
}
// ClearCpTaskLogs clears all "cp_task_logs" edges to the CpTaskLog entity.
func (_u *SysUserUpdateOne) ClearCpTaskLogs() *SysUserUpdateOne {
_u.mutation.ClearCpTaskLogs()
@@ -1833,6 +1951,51 @@ func (_u *SysUserUpdateOne) sqlSave(ctx context.Context) (_node *SysUser, err er
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.CpTaskCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: sysuser.CpTaskTable,
Columns: []string{sysuser.CpTaskColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cptask.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedCpTaskIDs(); len(nodes) > 0 && !_u.mutation.CpTaskCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: sysuser.CpTaskTable,
Columns: []string{sysuser.CpTaskColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cptask.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.CpTaskIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: sysuser.CpTaskTable,
Columns: []string{sysuser.CpTaskColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cptask.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.CpTaskLogsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
+74
View File
@@ -0,0 +1,74 @@
package cpdaily
import (
"context"
v1 "likedream-goframe/internal/api/v1"
"likedream-goframe/internal/application/cpdaily/task"
errors2 "likedream-goframe/internal/common/errors"
"likedream-goframe/internal/db"
"likedream-goframe/internal/ent"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/sysuser"
"likedream-goframe/internal/utils"
)
type CpTaskServiceV1 struct {
}
func (v CpTaskServiceV1) GetRecentTasks(ctx context.Context, req *v1.GetRecentTasksReq) *utils.Response[[]string] {
user := utils.GetUserInfoFromCtx(ctx)
// 检测是否属于自己的cpuser
cpUser := db.Global.CpUser.Query().Where(cpuser.ID(req.UserId)).WithSysuser().OnlyX(ctx)
if cpUser.Edges.Sysuser == nil || cpUser.Edges.Sysuser.ID != user.ID {
utils.OkOrPanic(errors2.NewBusinessError(400, "非法的今日校园账号"))
}
taskService := task.GetCpdailyTaskService(ctx, req.Type, cpUser.Cookie, cpUser.SchoolID)
titleList := taskService.GetRecentTaskTitle(ctx)
return utils.SuccessWithData[[]string](titleList)
}
func (v CpTaskServiceV1) AddTask(ctx context.Context, req *v1.AddTaskReq) *utils.Response[any] {
user := utils.GetUserInfoFromCtx(ctx)
// 检测是否属于自己的cpuser
cpUser := db.Global.CpUser.Query().Where(cpuser.ID(req.UserId)).WithSysuser().OnlyX(ctx)
if cpUser.Edges.Sysuser == nil || cpUser.Edges.Sysuser.ID != user.ID {
utils.OkOrPanic(errors2.NewBusinessError(400, "非法的今日校园账号"))
}
db.Global.CpTask.Create().
SetCpUserID(req.UserId).
SetTaskType(cptask.TaskType(req.Type)).
SetTitle(req.Title).
SetStep(cptask.StepForm).
SetTaskStatus(cptask.TaskStatusUnknown).
SetNotificationType(cptask.NotificationTypeNone).
SetUserID(user.ID).
SaveX(ctx)
return utils.SuccessWithMsg("添加成功")
}
func (v CpTaskServiceV1) List(ctx context.Context, req *v1.CpTaskListReq) *utils.Response[[]*ent.CpTask] {
user := utils.GetUserInfoFromCtx(ctx)
query := db.Global.CpTask.Query().Where(cptask.HasSysUserWith(sysuser.ID(user.ID))).WithCpUser()
if req.Title != "" {
query.Where(cptask.TitleContains(req.Title))
}
if req.Username != "" {
query.Where(cptask.HasCpUserWith(cpuser.UsernameContains(req.Username)))
}
total := query.CountX(ctx)
var data []*ent.CpTask
if total > 0 {
query.Limit(req.Size).Offset((req.Page - 1) * req.Size)
data = query.AllX(ctx)
for _, item := range data {
item.Edges.CpUser.Password = ""
item.Edges.CpUser.Cookie = ""
}
}
return utils.SuccessWithTotal[[]*ent.CpTask](data, total)
}
func NewCpTaskServiceV1() *CpTaskServiceV1 {
return &CpTaskServiceV1{}
}
+2 -2
View File
@@ -73,7 +73,7 @@ func (v CpUserServiceV1) ConfirmAdd(ctx context.Context, req *v1.CpUserConfirmAd
func (v CpUserServiceV1) List(ctx context.Context, req *v1.CpUserListReq) *utils.Response[[]*ent.CpUser] {
user := utils.GetUserInfoFromCtx(ctx)
query := db.Global.CpUser.Query().Where(cpuser.HasSysuserWith(sysuser.ID(user.ID)))
query := db.Global.CpUser.Query().Where(cpuser.HasSysuserWith(sysuser.ID(user.ID))).WithSchool()
if req.Email != "" {
query.Where(cpuser.EmailContains(req.Email))
}
@@ -118,7 +118,7 @@ func (v CpUserServiceV1) SchoolList(ctx context.Context, req *v1.CpSchoolListReq
list := school.GetSchoolList(ctx)
var schoolList []*ent.CpSchoolCreate
for _, v := range list {
schoolList = append(schoolList, db.Global.CpSchool.Create().SetName(v.Name).SetIconImg(v.Img).SetTenantId(v.Id).SetNamePinyin(v.NamePinYin))
schoolList = append(schoolList, db.Global.CpSchool.Create().SetName(v.Name).SetIconImg(v.Img).SetID(v.Id).SetNamePinyin(v.NamePinYin))
}
db.Global.CpSchool.CreateBulk(schoolList...).OnConflict().UpdateNewValues().ExecX(ctx)
}
+2
View File
@@ -19,6 +19,7 @@ type globalService struct {
Email *email.EmailServiceV1
User *user.UserServiceV1
CpUser *cpdaily.CpUserServiceV1
CpTask *cpdaily.CpTaskServiceV1
}
var Global = globalService{
@@ -30,4 +31,5 @@ var Global = globalService{
Email: email.NewV1(),
User: user.NewV1(),
CpUser: cpdaily.NewCpUserServiceV1(),
CpTask: cpdaily.NewCpTaskServiceV1(),
}