Compare commits

...

8 Commits

Author SHA1 Message Date
sugarBecomer 1ad0c285f2 🐛 学习通完善 2025-11-29 11:34:48 +08:00
sugarBecomer 498c51c585 🐛 学校信息 2025-11-29 10:48:25 +08:00
sugarBecomer 6a6716655b ✨ 销假相关 2025-11-29 08:54:44 +08:00
sugarBecomer ddc0949e56 ✨ 销假相关 2025-11-28 21:13:45 +08:00
sugarBecomer a723733562 ✨ 销假相关 2025-11-28 21:13:21 +08:00
sugarBecomer e7307182dd ✨ 学习通 临时提交 2025-11-28 21:12:56 +08:00
sugarBecomer 92ccebfa4e ✨ 学习通 临时提交 2025-11-28 21:12:18 +08:00
sugarBecomer 30dd8a8dfe 🐛 长春大学 登录 2025-11-27 23:26:49 +08:00
64 changed files with 7566 additions and 126 deletions
+26
View File
@@ -0,0 +1,26 @@
package v1
import (
"github.com/gogf/gf/v2/frame/g"
)
type CpLeaveListReq struct {
g.Meta `path:"/leave" method:"get" tags:"CpLeave" summary:"获取销假记录列表"`
CpUserId int64 `json:"cpUserId"`
Username string `json:"username"`
Status string `json:"status"`
Page int `json:"page" d:"1"`
Size int `json:"size" d:"10"`
}
type GetLeaveListFromSystemReq struct {
g.Meta `path:"/leave/system/{cpUserId}" method:"get" tags:"CpLeave" summary:"获取今日校园系统中的请假列表"`
CpUserId int64 `json:"cpUserId" v:"required#今日校园账号ID不能为空"`
}
type CpLeaveReportReq struct {
g.Meta `path:"/leave/report" method:"post" tags:"CpLeave" summary:"执行销假"`
CpUserId int64 `json:"cpUserId" v:"required#今日校园账号ID不能为空"`
LeaveId string `json:"leaveId" v:"required#请假记录ID不能为空"`
Title string `json:"title" v:"required#请假记录标题不能为空"`
}
+4 -1
View File
@@ -10,7 +10,10 @@ type CpSchoolListReq struct {
g.Meta `path:"/school" method:"get" tags:"CpSchool" summary:"获取cp学校列表"`
Name string `json:"name"`
}
type CpUserLoginUrlReq struct {
g.Meta `path:"/loginUrl" method:"get" tags:"CpUser" summary:"获取登录url" auth:"false"`
Name string `json:"name"`
}
type CpUserAddReq struct {
g.Meta `path:"/user" method:"post" tags:"CpUser" summary:"添加cp用户"`
Username string `json:"username" v:"required"`
@@ -2,14 +2,14 @@ package cryptoutil
import (
"encoding/base64"
"strings"
"testing"
)
func TestAesDecrypt(t *testing.T) {
str := "szFn6zAbjjU="
str := "6XkC1UAk07fK0uTaGPUu77i/+r7j/o1JQ/XygRxee2LMiX5H+w/BOqOB6e7W o9kHDZMb1pqZNN43k1tjl0ephbPLEi8g9C1EqBw0suzxX74j3dUdCf6dd/0W 8KvntNXwju96Vy5B2oD2ZosLmUdB1m0xX5rxAdLJ//cTft87XDWoLM0fuasu fGvR4XXXYZN071x8F03+qqR52fD1UQGgn0uGkSa/nrUho32Sg7DNJzF/JBCk 6/z0lu0XmIPo1SDIVjOtYAmyUDMZGl/ZvSAu2w=="
str = strings.ReplaceAll(str, " ", "")
decodeString, _ := base64.StdEncoding.DecodeString(str)
decrypt := AesDecrypt(decodeString)
decrypt := DesDecrypt(decodeString, Cat)
t.Log(string(decrypt))
encrypt := AesEncrypt([]byte("c9fe4f05-e1ed-4c15-aeb4-b05fa9bfb16f"))
t.Log(base64.StdEncoding.EncodeToString(encrypt))
}
@@ -0,0 +1,172 @@
package leave
import (
"context"
"fmt"
"likedream-goframe/internal/application/cpdaily"
"likedream-goframe/internal/application/cpdaily/cryptoutil"
"likedream-goframe/internal/application/cpdaily/task/leavetype"
"likedream-goframe/internal/application/cpdaily/taskhelper"
"likedream-goframe/internal/common/errors"
"likedream-goframe/internal/utils"
"github.com/gogf/gf/v2/container/gvar"
"github.com/google/uuid"
"github.com/samber/oops"
"github.com/tidwall/gjson"
"resty.dev/v3"
)
/**
* @Description: 销假相关功能
*/
type CpdailyReportApp struct {
client *resty.Client
host string
}
func NewCpdailyReportApp(client *resty.Client, host string) *CpdailyReportApp {
return &CpdailyReportApp{
client: client,
host: host,
}
}
// 获取请假记录
func (c *CpdailyReportApp) GetLeaveList() []leavetype.LeaveListOne {
// https://fzfu.campusphere.net/wec-counselor-leave-apps/leave/stu/listOther
post, err := c.client.R().SetBody(map[string]int{
"pageNumber": 1,
"pageSize": 20,
"needApproval": 1,
}).Post(fmt.Sprintf("%s/wec-counselor-leave-apps/leave/stu/listOther", c.host))
utils.OkOrPanic(err, func(err error) error {
return oops.
With("host", c.host).
In("CpdailyReport.GetLeaveList").
Wrap(err)
})
responseJSON := utils.ReadGjsonResult(post.Body)
rows := responseJSON.Get("datas.rows")
if !rows.Exists() {
utils.OkOrPanic(errors.NewBusinessError(503, "没有获取到待销假信息"), func(err error) error {
return oops.
With("host", c.host).
In("CpdailyReport.GetLeaveList").
Wrap(err)
})
}
var listList []leavetype.LeaveListOne
for _, row := range rows.Array() {
leaveOne := leavetype.LeaveListOne{
Id: row.Get("id").String(),
LeaveType: row.Get("leaveType").String(),
CreateTime: row.Get("createTime").String(),
Reason: row.Get("reason").String(),
AceEndTime: row.Get("aceEndTime").String(),
}
listList = append(listList, leaveOne)
}
return listList
}
func (c *CpdailyReportApp) LeaveDetail(leaveId string) gjson.Result {
// https://fzfu.campusphere.net/wec-counselor-leave-apps/leave/stu/detailOther
post, err := c.client.R().SetBody(map[string]any{
"id": leaveId,
"needApproval": 1,
"uaIsCpadaily": "true",
}).Post(fmt.Sprintf("%s/wec-counselor-leave-apps/leave/stu/detailOther", c.host))
utils.OkOrPanic(err, func(err error) error {
return oops.
With("host", c.host).
In("CpdailyReport.LeaveDetail").
Wrap(err)
})
datas := utils.ReadGjsonResult(post.Body).Get("datas")
if !datas.Exists() {
utils.OkOrPanic(errors.NewBusinessError(503, "没有获取到待销假详情信息"), func(err error) error {
return oops.
With("host", c.host).
In("CpdailyReport.LeaveDetail").
Wrap(err)
})
}
return datas
}
func (c *CpdailyReportApp) FillReportForm(detail gjson.Result) map[string]*gvar.Var {
resultForm := make(map[string]*gvar.Var)
resultForm["id"] = gvar.New(detail.Get("detail.id").String())
resultForm["needApproval"] = gvar.New(1)
resultForm["leaveType"] = gvar.New(detail.Get("leaveType.code").Int())
resultForm["reportLocation"] = gvar.New(detail.Get("detail.applyLocation.address").String())
resultForm["approverWid"] = gvar.New("")
resultForm["reportApplyExplain"] = gvar.New(nil)
resultForm["reportAttach"] = gvar.New(detail.Get("detail.applyAttach").Array())
resultForm["uaIsCpadaily"] = gvar.New(true)
return resultForm
}
func (c *CpdailyReportApp) GetLocation(detail gjson.Result) (lon, lat string) {
applyLocation := detail.Get("detail.applyLocation")
lon = applyLocation.Get("longitude").String()
lat = applyLocation.Get("latitude").String()
return
}
func (c *CpdailyReportApp) SubmitReport(ctx context.Context, form map[string]*gvar.Var, lon, lat, username, deviceId string) {
cpdailyInfo := cpdaily.GetInfo(ctx)
extensionForm := map[string]*gvar.Var{
"lon": gvar.New(lon),
"lat": gvar.New(lat),
"model": gvar.New(uuid.New().String()),
"appVersion": gvar.New(cpdailyInfo.AppVersion),
"systemVersion": gvar.New(cpdailyInfo.SystemVersion),
"userId": gvar.New(username),
"systemName": gvar.New("android"),
"deviceId": gvar.New(deviceId),
}
extensionString := taskhelper.GetCpdailyExtension(ctx, extensionForm)
bodyString := taskhelper.GetBodyString(ctx, form)
// 构造提交数据
submitData := map[string]*gvar.Var{
"lon": gvar.New(lon),
"version": gvar.New(cryptoutil.EncryptVersion),
"calVersion": gvar.New(cpdailyInfo.CalVersion),
"deviceId": extensionForm["deviceId"],
//"userId": gvar.New(username),
"systemName": gvar.New("android"),
"bodyString": gvar.New(bodyString),
"lat": gvar.New(lat),
"systemVersion": gvar.New(cpdailyInfo.SystemVersion),
"appVersion": gvar.New(cpdailyInfo.AppVersion),
"model": extensionForm["model"],
}
// https://fzfu.campusphere.net/wec-counselor-leave-apps/leave/report
response, e := c.client.R().
SetBody(submitData).
WithContext(ctx).
SetHeader("Cpdaily-Extension", extensionString).
Post(fmt.Sprintf("%s/wec-counselor-leave-apps/leave/report", c.host))
utils.OkOrPanic(e, func(err error) error {
return oops.
With("host", c.host).
With("username", username).
With("deviceId", deviceId).
In("CpdailySleepCheckTask.Submit").
Wrap(err)
})
responseJSON := utils.ReadGjsonResult(response.Body)
if responseJSON.Get("code").String() != "0" {
utils.OkOrPanic(errors.NewBusinessError(503, responseJSON.Get("message").String()), oops.WithContext(ctx).Wrap)
}
}
@@ -16,6 +16,9 @@ func GetCpdailyLoginBySchoolInfo(ctx context.Context, info *school.SchoolDetailI
// 南宁师范大学
case "2ba0ea59-a764-4482-bb2b-c924b726b04c":
return NewNnnu(ctx)
// 长春大学
case "ccu":
fallthrough
// 河北石油职业技术大学
case "01e270d1-00e2-4ce9-b0af-5d5fbd462b8a":
return NewIap(ctx)
+11 -10
View File
@@ -45,16 +45,17 @@ func (c *CpdailyIapLogin) Login(ctx context.Context, schoolDetail *school.School
preLoginUrl := loginUrl + "/portal/login"
c.client.SetRedirectPolicy(resty.FlexibleRedirectPolicy(20))
loginRedirectResponse, err := c.client.R().Get(preLoginUrl)
utils.OkOrPanic(err, func(err error) error {
return oops.
In("CpdailyIapLogin.Login").
With("schoolDetail", schoolDetail).
With("username", username).
With("password", password).
Wrap(err)
})
u := loginRedirectResponse.RawResponse.Request.URL
oldLt := strings.Split(u.String(), "=")[1]
oldLt := ""
// 部分学校无法直接访问登录页
if err == nil {
u := loginRedirectResponse.RawResponse.Request.URL
oldLt = strings.Split(u.String(), "=")[1]
c.client.SetRedirectPolicy(resty.NoRedirectPolicy())
} else {
preLoginUrl = loginUrl + "/iap/login/mobile.html"
c.client.SetRedirectPolicy(resty.FlexibleRedirectPolicy(20))
loginRedirectResponse, err = c.client.R().Get(preLoginUrl)
}
c.client.SetRedirectPolicy(resty.NoRedirectPolicy())
ltInfoResponse, err := c.client.R().
WithContext(ctx).
@@ -0,0 +1,9 @@
package leavetype
type LeaveListOne struct {
Id string `json:"id"`
LeaveType string `json:"leaveType"`
CreateTime string `json:"createTime"`
AceEndTime string `json:"aceEndTime"`
Reason string `json:"reason"`
}
@@ -102,38 +102,59 @@ type XueXiTAttachment struct {
// ChapterData 章节数据响应
type ChapterData struct {
ID string `json:"id"`
BbsID string `json:"bbsid"`
ClassScore int `json:"classscore"`
IsStart int `json:"isstart"`
AllowDownload int `json:"allowdownload"`
ChatID string `json:"chatid"`
Name string `json:"name"`
State int `json:"state"`
IsFiled int `json:"isfiled"`
VisibleScore int `json:"visiblescore"`
HideClazz int `json:"hideclazz"`
BeginDate int64 `json:"begindate"`
CourseSetting struct {
ID string `json:"id"`
CourseID string `json:"courseid"`
HiddenCourseCover int `json:"hiddencoursecover"`
CourseFaceCheck int `json:"coursefacecheck"`
} `json:"coursesetting"`
Course struct {
ID string `json:"id"`
BelongSchoolID string `json:"belongschoolid"`
Name string `json:"name"`
InfoContent string `json:"infocontent"`
ObjectID string `json:"objectid"`
App int `json:"app"`
BulletFormat string `json:"bulletformat"`
MappingCourseID string `json:"mappingcourseid"`
ImageURL string `json:"imageurl"`
TeacherFactor string `json:"teacherfactor"`
JobCount int `json:"jobcount"`
Knowledge []XueXiTCourseChapter `json:"knowledge"`
} `json:"course"`
Data []struct {
Hideclazz int `json:"hideclazz"`
Allowdownload int `json:"allowdownload"`
Chatid string `json:"chatid"`
Isfiled int `json:"isfiled"`
Forbidintoclazz int `json:"forbidintoclazz"`
Coursesetting struct {
Data []struct {
Coursefacecheck int `json:"coursefacecheck"`
Hiddencoursecover int `json:"hiddencoursecover"`
ID int `json:"id"`
Courseid int `json:"courseid"`
} `json:"data"`
} `json:"coursesetting"`
Isstart bool `json:"isstart"`
Visiblescore int `json:"visiblescore"`
Name string `json:"name"`
Course struct {
Data []struct {
App int `json:"app"`
Teacherfactor string `json:"teacherfactor"`
Jobcount int `json:"jobcount"`
Infocontent string `json:"infocontent"`
Bulletformat string `json:"bulletformat"`
Mappingcourseid int `json:"mappingcourseid"`
Imageurl string `json:"imageurl"`
Name string `json:"name"`
ID int `json:"id"`
Belongschoolid string `json:"belongschoolid"`
Objectid string `json:"objectid"`
Knowledge struct {
Data []struct {
Jobcount int `json:"jobcount"`
Isreview int `json:"isreview"`
Attachment struct {
Data []interface{} `json:"data"`
} `json:"attachment"`
Indexorder int `json:"indexorder"`
Name string `json:"name"`
ID int `json:"id"`
Label string `json:"label"`
Layer int `json:"layer"`
Parentnodeid int `json:"parentnodeid"`
Status string `json:"status"`
} `json:"data"`
} `json:"knowledge"`
} `json:"data"`
} `json:"course"`
ID int `json:"id"`
State int `json:"state"`
Bbsid string `json:"bbsid"`
Classscore int `json:"classscore"`
} `json:"data"`
}
// Card 任务点卡片信息
@@ -5,11 +5,13 @@ import (
"likedream-goframe/internal/application/cookiejar"
"likedream-goframe/internal/application/httpclient"
"likedream-goframe/internal/application/xuexitong/cryptoutil"
"likedream-goframe/internal/framework/errors"
"likedream-goframe/internal/framework/logger"
"net/http"
"strings"
"time"
"github.com/tidwall/gjson"
"go.uber.org/zap"
"resty.dev/v3"
)
@@ -62,6 +64,9 @@ func (c *XuexitongLogin) Login(ctx context.Context, username, password string, r
time.Sleep(time.Duration(retry*5) * time.Second)
return c.Login(ctx, username, password, retry-1)
}
if !gjson.Get(body, "status").Bool() {
return errors.NewBusinessErrorWithDetail(401, "登录失败", gjson.Get(body, "msg2").String())
}
return nil
}
@@ -189,7 +189,31 @@ func (c *XuexitongCourse) PullCourseChapterList(ctx context.Context, courseId st
utils.OkOrPanic(errors2.NewBusinessError(503, "解析章节数据失败").WithInnerError(err), oops.WithContext(ctx).Wrap)
}
return chapterData.Course.Knowledge
// 从新的结构中提取章节列表
var chapters []entity.XueXiTCourseChapter
if len(chapterData.Data) > 0 && len(chapterData.Data[0].Course.Data) > 0 {
knowledgeData := chapterData.Data[0].Course.Data[0].Knowledge.Data
for _, kd := range knowledgeData {
chapter := entity.XueXiTCourseChapter{
ID: strconv.Itoa(kd.ID),
Name: kd.Name,
ParentNodeID: strconv.Itoa(kd.Parentnodeid),
Layer: kd.Layer,
Label: kd.Label,
IndexOrder: kd.Indexorder,
JobCount: kd.Jobcount,
Status: 0, // Status字段在API响应中是string,这里设为默认值
IsReview: kd.Isreview,
BeginTime: 0,
EndTime: 0,
Attachment: []entity.XueXiTAttachment{},
Knowledge: []entity.XueXiTCourseChapter{}, // 子章节暂时为空,需要递归获取
}
chapters = append(chapters, chapter)
}
}
return chapters
}
// EnterChapterForwardCall 进入章节前的前置调用,防止0任务点章节出现问题
+10 -6
View File
@@ -1,13 +1,17 @@
package cst
const (
TaskCpdaily = "task:cpdaily"
TaskEmail = "task:email"
TaskResetDaily = "task:reset:daily"
TaskCpdaily = "task:cpdaily"
TaskEmail = "task:email"
TaskResetDaily = "task:reset:daily"
TaskXuexitong = "task:xuexitong"
TaskXuexitongVio = "task:xuexitong:violence"
TaskCpdailyId = "cpdaily:task:schedule:%d"
TaskQueueCpdaily = "queue:cpdaily"
TaskQueueEmail = "queue:email"
TaskQueueDefault = "default"
TaskQueueCpdaily = "queue:cpdaily"
TaskQueueEmail = "queue:email"
TaskQueueXuexitong = "queue:xuexitong"
TaskQueueXuexitongVio = "queue:xuexitong:violence"
TaskQueueDefault = "default"
)
@@ -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 CpLeaveCtrlV1 struct {
}
func (c CpLeaveCtrlV1) GetLeaveListFromSystem(ctx context.Context, req *v1.GetLeaveListFromSystemReq) (res *utils.Response[any], err error) {
defer utils.Pass(&err)
return service.Global.CpLeave.GetLeaveListFromSystem(ctx, req), nil
}
func (c CpLeaveCtrlV1) List(ctx context.Context, req *v1.CpLeaveListReq) (res *utils.Response[[]*ent.CpLeave], err error) {
defer utils.Pass(&err)
return service.Global.CpLeave.List(ctx, req), nil
}
func (c CpLeaveCtrlV1) Report(ctx context.Context, req *v1.CpLeaveReportReq) (res *utils.Response[any], err error) {
defer utils.Pass(&err)
return service.Global.CpLeave.Report(ctx, req), nil
}
func NewCpLeaveCtrlV1() ICpLeaveCtrlV1 {
return &CpLeaveCtrlV1{}
}
@@ -15,6 +15,11 @@ func NewCpUserCtrlV1() ICpUserCtrlV1 {
return &CpUserCtrlV1{}
}
func (c CpUserCtrlV1) LoginUrl(ctx context.Context, req *v1.CpUserLoginUrlReq) (res *utils.Response[any], err error) {
defer utils.Pass(&err)
return service.Global.CpUser.LoginUrl(ctx, req), nil
}
func (c CpUserCtrlV1) Add(ctx context.Context, req *v1.CpUserAddReq) (res *utils.Response[any], err error) {
defer utils.Pass(&err)
return service.Global.CpUser.Add(ctx, req), nil
@@ -0,0 +1,14 @@
package cpdaily
import (
"context"
v1 "likedream-goframe/internal/api/v1"
"likedream-goframe/internal/ent"
"likedream-goframe/internal/utils"
)
type ICpLeaveCtrlV1 interface {
GetLeaveListFromSystem(ctx context.Context, req *v1.GetLeaveListFromSystemReq) (*utils.Response[any], error)
List(ctx context.Context, req *v1.CpLeaveListReq) (*utils.Response[[]*ent.CpLeave], error)
Report(ctx context.Context, req *v1.CpLeaveReportReq) (*utils.Response[any], error)
}
@@ -8,6 +8,8 @@ import (
)
type ICpUserCtrlV1 interface {
LoginUrl(ctx context.Context, req *v1.CpUserLoginUrlReq) (res *utils.Response[any], err error)
SchoolList(ctx context.Context, req *v1.CpSchoolListReq) (*utils.Response[[]*ent.CpSchool], error)
// 添加用户
Add(ctx context.Context, req *v1.CpUserAddReq) (*utils.Response[any], error)
+226 -8
View File
@@ -13,6 +13,7 @@ import (
"likedream-goframe/internal/ent/courseentity"
"likedream-goframe/internal/ent/cpimage"
"likedream-goframe/internal/ent/cpleave"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
@@ -42,6 +43,8 @@ type Client struct {
CourseEntity *CourseEntityClient
// CpImage is the client for interacting with the CpImage builders.
CpImage *CpImageClient
// CpLeave is the client for interacting with the CpLeave builders.
CpLeave *CpLeaveClient
// CpSchool is the client for interacting with the CpSchool builders.
CpSchool *CpSchoolClient
// CpTask is the client for interacting with the CpTask builders.
@@ -75,6 +78,7 @@ func (c *Client) init() {
c.Schema = migrate.NewSchema(c.driver)
c.CourseEntity = NewCourseEntityClient(c.config)
c.CpImage = NewCpImageClient(c.config)
c.CpLeave = NewCpLeaveClient(c.config)
c.CpSchool = NewCpSchoolClient(c.config)
c.CpTask = NewCpTaskClient(c.config)
c.CpTaskLog = NewCpTaskLogClient(c.config)
@@ -181,6 +185,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
config: cfg,
CourseEntity: NewCourseEntityClient(cfg),
CpImage: NewCpImageClient(cfg),
CpLeave: NewCpLeaveClient(cfg),
CpSchool: NewCpSchoolClient(cfg),
CpTask: NewCpTaskClient(cfg),
CpTaskLog: NewCpTaskLogClient(cfg),
@@ -212,6 +217,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
config: cfg,
CourseEntity: NewCourseEntityClient(cfg),
CpImage: NewCpImageClient(cfg),
CpLeave: NewCpLeaveClient(cfg),
CpSchool: NewCpSchoolClient(cfg),
CpTask: NewCpTaskClient(cfg),
CpTaskLog: NewCpTaskLogClient(cfg),
@@ -251,8 +257,8 @@ func (c *Client) Close() error {
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
func (c *Client) Use(hooks ...Hook) {
for _, n := range []interface{ Use(...Hook) }{
c.CourseEntity, c.CpImage, c.CpSchool, c.CpTask, c.CpTaskLog, c.CpUser,
c.SysAgent, c.SysCard, c.SysMenu, c.SysRole, c.SysUser, c.SysUserLog,
c.CourseEntity, c.CpImage, c.CpLeave, c.CpSchool, c.CpTask, c.CpTaskLog,
c.CpUser, c.SysAgent, c.SysCard, c.SysMenu, c.SysRole, c.SysUser, c.SysUserLog,
} {
n.Use(hooks...)
}
@@ -262,8 +268,8 @@ func (c *Client) Use(hooks ...Hook) {
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
func (c *Client) Intercept(interceptors ...Interceptor) {
for _, n := range []interface{ Intercept(...Interceptor) }{
c.CourseEntity, c.CpImage, c.CpSchool, c.CpTask, c.CpTaskLog, c.CpUser,
c.SysAgent, c.SysCard, c.SysMenu, c.SysRole, c.SysUser, c.SysUserLog,
c.CourseEntity, c.CpImage, c.CpLeave, c.CpSchool, c.CpTask, c.CpTaskLog,
c.CpUser, c.SysAgent, c.SysCard, c.SysMenu, c.SysRole, c.SysUser, c.SysUserLog,
} {
n.Intercept(interceptors...)
}
@@ -276,6 +282,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
return c.CourseEntity.mutate(ctx, m)
case *CpImageMutation:
return c.CpImage.mutate(ctx, m)
case *CpLeaveMutation:
return c.CpLeave.mutate(ctx, m)
case *CpSchoolMutation:
return c.CpSchool.mutate(ctx, m)
case *CpTaskMutation:
@@ -607,6 +615,178 @@ func (c *CpImageClient) mutate(ctx context.Context, m *CpImageMutation) (Value,
}
}
// CpLeaveClient is a client for the CpLeave schema.
type CpLeaveClient struct {
config
}
// NewCpLeaveClient returns a client for the CpLeave from the given config.
func NewCpLeaveClient(c config) *CpLeaveClient {
return &CpLeaveClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `cpleave.Hooks(f(g(h())))`.
func (c *CpLeaveClient) Use(hooks ...Hook) {
c.hooks.CpLeave = append(c.hooks.CpLeave, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `cpleave.Intercept(f(g(h())))`.
func (c *CpLeaveClient) Intercept(interceptors ...Interceptor) {
c.inters.CpLeave = append(c.inters.CpLeave, interceptors...)
}
// Create returns a builder for creating a CpLeave entity.
func (c *CpLeaveClient) Create() *CpLeaveCreate {
mutation := newCpLeaveMutation(c.config, OpCreate)
return &CpLeaveCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of CpLeave entities.
func (c *CpLeaveClient) CreateBulk(builders ...*CpLeaveCreate) *CpLeaveCreateBulk {
return &CpLeaveCreateBulk{config: c.config, builders: builders}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *CpLeaveClient) MapCreateBulk(slice any, setFunc func(*CpLeaveCreate, int)) *CpLeaveCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &CpLeaveCreateBulk{err: fmt.Errorf("calling to CpLeaveClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*CpLeaveCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &CpLeaveCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for CpLeave.
func (c *CpLeaveClient) Update() *CpLeaveUpdate {
mutation := newCpLeaveMutation(c.config, OpUpdate)
return &CpLeaveUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *CpLeaveClient) UpdateOne(_m *CpLeave) *CpLeaveUpdateOne {
mutation := newCpLeaveMutation(c.config, OpUpdateOne, withCpLeave(_m))
return &CpLeaveUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *CpLeaveClient) UpdateOneID(id int64) *CpLeaveUpdateOne {
mutation := newCpLeaveMutation(c.config, OpUpdateOne, withCpLeaveID(id))
return &CpLeaveUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for CpLeave.
func (c *CpLeaveClient) Delete() *CpLeaveDelete {
mutation := newCpLeaveMutation(c.config, OpDelete)
return &CpLeaveDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *CpLeaveClient) DeleteOne(_m *CpLeave) *CpLeaveDeleteOne {
return c.DeleteOneID(_m.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *CpLeaveClient) DeleteOneID(id int64) *CpLeaveDeleteOne {
builder := c.Delete().Where(cpleave.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &CpLeaveDeleteOne{builder}
}
// Query returns a query builder for CpLeave.
func (c *CpLeaveClient) Query() *CpLeaveQuery {
return &CpLeaveQuery{
config: c.config,
ctx: &QueryContext{Type: TypeCpLeave},
inters: c.Interceptors(),
}
}
// Get returns a CpLeave entity by its id.
func (c *CpLeaveClient) Get(ctx context.Context, id int64) (*CpLeave, error) {
return c.Query().Where(cpleave.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *CpLeaveClient) GetX(ctx context.Context, id int64) *CpLeave {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// QueryCpUser queries the cp_user edge of a CpLeave.
func (c *CpLeaveClient) QueryCpUser(_m *CpLeave) *CpUserQuery {
query := (&CpUserClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(cpleave.Table, cpleave.FieldID, id),
sqlgraph.To(cpuser.Table, cpuser.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, cpleave.CpUserTable, cpleave.CpUserColumn),
)
schemaConfig := _m.schemaConfig
step.To.Schema = schemaConfig.CpUser
step.Edge.Schema = schemaConfig.CpLeave
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QuerySysUser queries the sys_user edge of a CpLeave.
func (c *CpLeaveClient) QuerySysUser(_m *CpLeave) *SysUserQuery {
query := (&SysUserClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(cpleave.Table, cpleave.FieldID, id),
sqlgraph.To(sysuser.Table, sysuser.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, cpleave.SysUserTable, cpleave.SysUserColumn),
)
schemaConfig := _m.schemaConfig
step.To.Schema = schemaConfig.SysUser
step.Edge.Schema = schemaConfig.CpLeave
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *CpLeaveClient) Hooks() []Hook {
hooks := c.hooks.CpLeave
return append(hooks[:len(hooks):len(hooks)], cpleave.Hooks[:]...)
}
// Interceptors returns the client interceptors.
func (c *CpLeaveClient) Interceptors() []Interceptor {
return c.inters.CpLeave
}
func (c *CpLeaveClient) mutate(ctx context.Context, m *CpLeaveMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&CpLeaveCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&CpLeaveUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&CpLeaveUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&CpLeaveDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown CpLeave mutation op: %q", m.Op())
}
}
// CpSchoolClient is a client for the CpSchool schema.
type CpSchoolClient struct {
config
@@ -1269,6 +1449,25 @@ func (c *CpUserClient) QueryCptasks(_m *CpUser) *CpTaskQuery {
return query
}
// QueryCpLeave queries the cp_leave edge of a CpUser.
func (c *CpUserClient) QueryCpLeave(_m *CpUser) *CpLeaveQuery {
query := (&CpLeaveClient{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(cpleave.Table, cpleave.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, cpuser.CpLeaveTable, cpuser.CpLeaveColumn),
)
schemaConfig := _m.schemaConfig
step.To.Schema = schemaConfig.CpLeave
step.Edge.Schema = schemaConfig.CpLeave
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QuerySysuser queries the sysuser edge of a CpUser.
func (c *CpUserClient) QuerySysuser(_m *CpUser) *SysUserQuery {
query := (&SysUserClient{config: c.config}).Query()
@@ -2300,6 +2499,25 @@ func (c *SysUserClient) QueryCpTask(_m *SysUser) *CpTaskQuery {
return query
}
// QueryCpLeave queries the cp_leave edge of a SysUser.
func (c *SysUserClient) QueryCpLeave(_m *SysUser) *CpLeaveQuery {
query := (&CpLeaveClient{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(cpleave.Table, cpleave.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, sysuser.CpLeaveTable, sysuser.CpLeaveColumn),
)
schemaConfig := _m.schemaConfig
step.To.Schema = schemaConfig.CpLeave
step.Edge.Schema = schemaConfig.CpLeave
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// QueryCourseEntity queries the course_entity edge of a SysUser.
func (c *SysUserClient) QueryCourseEntity(_m *SysUser) *CourseEntityQuery {
query := (&CourseEntityClient{config: c.config}).Query()
@@ -2557,12 +2775,12 @@ func (c *SysUserLogClient) mutate(ctx context.Context, m *SysUserLogMutation) (V
// hooks and interceptors per client, for fast access.
type (
hooks struct {
CourseEntity, CpImage, CpSchool, CpTask, CpTaskLog, CpUser, SysAgent, SysCard,
SysMenu, SysRole, SysUser, SysUserLog []ent.Hook
CourseEntity, CpImage, CpLeave, CpSchool, CpTask, CpTaskLog, CpUser, SysAgent,
SysCard, SysMenu, SysRole, SysUser, SysUserLog []ent.Hook
}
inters struct {
CourseEntity, CpImage, CpSchool, CpTask, CpTaskLog, CpUser, SysAgent, SysCard,
SysMenu, SysRole, SysUser, SysUserLog []ent.Interceptor
CourseEntity, CpImage, CpLeave, CpSchool, CpTask, CpTaskLog, CpUser, SysAgent,
SysCard, SysMenu, SysRole, SysUser, SysUserLog []ent.Interceptor
}
)
+23 -1
View File
@@ -46,6 +46,10 @@ type CourseEntity struct {
ExamState courseentity.ExamState `json:"exam_state,omitempty"`
// Violence holds the value of the "violence" field.
Violence courseentity.Violence `json:"violence,omitempty"`
// Nodes holds the value of the "nodes" field.
Nodes string `json:"nodes,omitempty"`
// CompletedNodes holds the value of the "completed_nodes" field.
CompletedNodes string `json:"completed_nodes,omitempty"`
// Desc holds the value of the "desc" field.
Desc string `json:"desc,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
@@ -83,7 +87,7 @@ func (*CourseEntity) scanValues(columns []string) ([]any, error) {
values[i] = new(ent2.CustomTime)
case courseentity.FieldID, courseentity.FieldUserID, courseentity.FieldTaskCount, courseentity.FieldSuccessCount:
values[i] = new(sql.NullInt64)
case courseentity.FieldUsername, courseentity.FieldPassword, courseentity.FieldType, courseentity.FieldCourseName, courseentity.FieldCourseID, courseentity.FieldNeed, courseentity.FieldStatus, courseentity.FieldExamState, courseentity.FieldViolence, courseentity.FieldDesc:
case courseentity.FieldUsername, courseentity.FieldPassword, courseentity.FieldType, courseentity.FieldCourseName, courseentity.FieldCourseID, courseentity.FieldNeed, courseentity.FieldStatus, courseentity.FieldExamState, courseentity.FieldViolence, courseentity.FieldNodes, courseentity.FieldCompletedNodes, courseentity.FieldDesc:
values[i] = new(sql.NullString)
default:
values[i] = new(sql.UnknownType)
@@ -190,6 +194,18 @@ func (_m *CourseEntity) assignValues(columns []string, values []any) error {
} else if value.Valid {
_m.Violence = courseentity.Violence(value.String)
}
case courseentity.FieldNodes:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field nodes", values[i])
} else if value.Valid {
_m.Nodes = value.String
}
case courseentity.FieldCompletedNodes:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field completed_nodes", values[i])
} else if value.Valid {
_m.CompletedNodes = value.String
}
case courseentity.FieldDesc:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field desc", values[i])
@@ -278,6 +294,12 @@ func (_m *CourseEntity) String() string {
builder.WriteString("violence=")
builder.WriteString(fmt.Sprintf("%v", _m.Violence))
builder.WriteString(", ")
builder.WriteString("nodes=")
builder.WriteString(_m.Nodes)
builder.WriteString(", ")
builder.WriteString("completed_nodes=")
builder.WriteString(_m.CompletedNodes)
builder.WriteString(", ")
builder.WriteString("desc=")
builder.WriteString(_m.Desc)
builder.WriteByte(')')
+16
View File
@@ -44,6 +44,10 @@ const (
FieldExamState = "exam_state"
// FieldViolence holds the string denoting the violence field in the database.
FieldViolence = "violence"
// FieldNodes holds the string denoting the nodes field in the database.
FieldNodes = "nodes"
// FieldCompletedNodes holds the string denoting the completed_nodes field in the database.
FieldCompletedNodes = "completed_nodes"
// FieldDesc holds the string denoting the desc field in the database.
FieldDesc = "desc"
// EdgeSysUser holds the string denoting the sys_user edge name in mutations.
@@ -76,6 +80,8 @@ var Columns = []string{
FieldSuccessCount,
FieldExamState,
FieldViolence,
FieldNodes,
FieldCompletedNodes,
FieldDesc,
}
@@ -315,6 +321,16 @@ func ByViolence(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldViolence, opts...).ToFunc()
}
// ByNodes orders the results by the nodes field.
func ByNodes(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldNodes, opts...).ToFunc()
}
// ByCompletedNodes orders the results by the completed_nodes field.
func ByCompletedNodes(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCompletedNodes, opts...).ToFunc()
}
// ByDesc orders the results by the desc field.
func ByDesc(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDesc, opts...).ToFunc()
+160
View File
@@ -101,6 +101,16 @@ func SuccessCount(v int) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldEQ(FieldSuccessCount, v))
}
// Nodes applies equality check predicate on the "nodes" field. It's identical to NodesEQ.
func Nodes(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldEQ(FieldNodes, v))
}
// CompletedNodes applies equality check predicate on the "completed_nodes" field. It's identical to CompletedNodesEQ.
func CompletedNodes(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldEQ(FieldCompletedNodes, v))
}
// Desc applies equality check predicate on the "desc" field. It's identical to DescEQ.
func Desc(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldEQ(FieldDesc, v))
@@ -706,6 +716,156 @@ func ViolenceNotIn(vs ...Violence) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldNotIn(FieldViolence, vs...))
}
// NodesEQ applies the EQ predicate on the "nodes" field.
func NodesEQ(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldEQ(FieldNodes, v))
}
// NodesNEQ applies the NEQ predicate on the "nodes" field.
func NodesNEQ(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldNEQ(FieldNodes, v))
}
// NodesIn applies the In predicate on the "nodes" field.
func NodesIn(vs ...string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldIn(FieldNodes, vs...))
}
// NodesNotIn applies the NotIn predicate on the "nodes" field.
func NodesNotIn(vs ...string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldNotIn(FieldNodes, vs...))
}
// NodesGT applies the GT predicate on the "nodes" field.
func NodesGT(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldGT(FieldNodes, v))
}
// NodesGTE applies the GTE predicate on the "nodes" field.
func NodesGTE(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldGTE(FieldNodes, v))
}
// NodesLT applies the LT predicate on the "nodes" field.
func NodesLT(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldLT(FieldNodes, v))
}
// NodesLTE applies the LTE predicate on the "nodes" field.
func NodesLTE(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldLTE(FieldNodes, v))
}
// NodesContains applies the Contains predicate on the "nodes" field.
func NodesContains(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldContains(FieldNodes, v))
}
// NodesHasPrefix applies the HasPrefix predicate on the "nodes" field.
func NodesHasPrefix(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldHasPrefix(FieldNodes, v))
}
// NodesHasSuffix applies the HasSuffix predicate on the "nodes" field.
func NodesHasSuffix(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldHasSuffix(FieldNodes, v))
}
// NodesIsNil applies the IsNil predicate on the "nodes" field.
func NodesIsNil() predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldIsNull(FieldNodes))
}
// NodesNotNil applies the NotNil predicate on the "nodes" field.
func NodesNotNil() predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldNotNull(FieldNodes))
}
// NodesEqualFold applies the EqualFold predicate on the "nodes" field.
func NodesEqualFold(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldEqualFold(FieldNodes, v))
}
// NodesContainsFold applies the ContainsFold predicate on the "nodes" field.
func NodesContainsFold(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldContainsFold(FieldNodes, v))
}
// CompletedNodesEQ applies the EQ predicate on the "completed_nodes" field.
func CompletedNodesEQ(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldEQ(FieldCompletedNodes, v))
}
// CompletedNodesNEQ applies the NEQ predicate on the "completed_nodes" field.
func CompletedNodesNEQ(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldNEQ(FieldCompletedNodes, v))
}
// CompletedNodesIn applies the In predicate on the "completed_nodes" field.
func CompletedNodesIn(vs ...string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldIn(FieldCompletedNodes, vs...))
}
// CompletedNodesNotIn applies the NotIn predicate on the "completed_nodes" field.
func CompletedNodesNotIn(vs ...string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldNotIn(FieldCompletedNodes, vs...))
}
// CompletedNodesGT applies the GT predicate on the "completed_nodes" field.
func CompletedNodesGT(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldGT(FieldCompletedNodes, v))
}
// CompletedNodesGTE applies the GTE predicate on the "completed_nodes" field.
func CompletedNodesGTE(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldGTE(FieldCompletedNodes, v))
}
// CompletedNodesLT applies the LT predicate on the "completed_nodes" field.
func CompletedNodesLT(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldLT(FieldCompletedNodes, v))
}
// CompletedNodesLTE applies the LTE predicate on the "completed_nodes" field.
func CompletedNodesLTE(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldLTE(FieldCompletedNodes, v))
}
// CompletedNodesContains applies the Contains predicate on the "completed_nodes" field.
func CompletedNodesContains(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldContains(FieldCompletedNodes, v))
}
// CompletedNodesHasPrefix applies the HasPrefix predicate on the "completed_nodes" field.
func CompletedNodesHasPrefix(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldHasPrefix(FieldCompletedNodes, v))
}
// CompletedNodesHasSuffix applies the HasSuffix predicate on the "completed_nodes" field.
func CompletedNodesHasSuffix(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldHasSuffix(FieldCompletedNodes, v))
}
// CompletedNodesIsNil applies the IsNil predicate on the "completed_nodes" field.
func CompletedNodesIsNil() predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldIsNull(FieldCompletedNodes))
}
// CompletedNodesNotNil applies the NotNil predicate on the "completed_nodes" field.
func CompletedNodesNotNil() predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldNotNull(FieldCompletedNodes))
}
// CompletedNodesEqualFold applies the EqualFold predicate on the "completed_nodes" field.
func CompletedNodesEqualFold(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldEqualFold(FieldCompletedNodes, v))
}
// CompletedNodesContainsFold applies the ContainsFold predicate on the "completed_nodes" field.
func CompletedNodesContainsFold(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldContainsFold(FieldCompletedNodes, v))
}
// DescEQ applies the EQ predicate on the "desc" field.
func DescEQ(v string) predicate.CourseEntity {
return predicate.CourseEntity(sql.FieldEQ(FieldDesc, v))
+156
View File
@@ -147,6 +147,34 @@ func (_c *CourseEntityCreate) SetNillableViolence(v *courseentity.Violence) *Cou
return _c
}
// SetNodes sets the "nodes" field.
func (_c *CourseEntityCreate) SetNodes(v string) *CourseEntityCreate {
_c.mutation.SetNodes(v)
return _c
}
// SetNillableNodes sets the "nodes" field if the given value is not nil.
func (_c *CourseEntityCreate) SetNillableNodes(v *string) *CourseEntityCreate {
if v != nil {
_c.SetNodes(*v)
}
return _c
}
// SetCompletedNodes sets the "completed_nodes" field.
func (_c *CourseEntityCreate) SetCompletedNodes(v string) *CourseEntityCreate {
_c.mutation.SetCompletedNodes(v)
return _c
}
// SetNillableCompletedNodes sets the "completed_nodes" field if the given value is not nil.
func (_c *CourseEntityCreate) SetNillableCompletedNodes(v *string) *CourseEntityCreate {
if v != nil {
_c.SetCompletedNodes(*v)
}
return _c
}
// SetDesc sets the "desc" field.
func (_c *CourseEntityCreate) SetDesc(v string) *CourseEntityCreate {
_c.mutation.SetDesc(v)
@@ -398,6 +426,14 @@ func (_c *CourseEntityCreate) createSpec() (*CourseEntity, *sqlgraph.CreateSpec)
_spec.SetField(courseentity.FieldViolence, field.TypeEnum, value)
_node.Violence = value
}
if value, ok := _c.mutation.Nodes(); ok {
_spec.SetField(courseentity.FieldNodes, field.TypeString, value)
_node.Nodes = value
}
if value, ok := _c.mutation.CompletedNodes(); ok {
_spec.SetField(courseentity.FieldCompletedNodes, field.TypeString, value)
_node.CompletedNodes = value
}
if value, ok := _c.mutation.Desc(); ok {
_spec.SetField(courseentity.FieldDesc, field.TypeString, value)
_node.Desc = value
@@ -640,6 +676,42 @@ func (u *CourseEntityUpsert) UpdateViolence() *CourseEntityUpsert {
return u
}
// SetNodes sets the "nodes" field.
func (u *CourseEntityUpsert) SetNodes(v string) *CourseEntityUpsert {
u.Set(courseentity.FieldNodes, v)
return u
}
// UpdateNodes sets the "nodes" field to the value that was provided on create.
func (u *CourseEntityUpsert) UpdateNodes() *CourseEntityUpsert {
u.SetExcluded(courseentity.FieldNodes)
return u
}
// ClearNodes clears the value of the "nodes" field.
func (u *CourseEntityUpsert) ClearNodes() *CourseEntityUpsert {
u.SetNull(courseentity.FieldNodes)
return u
}
// SetCompletedNodes sets the "completed_nodes" field.
func (u *CourseEntityUpsert) SetCompletedNodes(v string) *CourseEntityUpsert {
u.Set(courseentity.FieldCompletedNodes, v)
return u
}
// UpdateCompletedNodes sets the "completed_nodes" field to the value that was provided on create.
func (u *CourseEntityUpsert) UpdateCompletedNodes() *CourseEntityUpsert {
u.SetExcluded(courseentity.FieldCompletedNodes)
return u
}
// ClearCompletedNodes clears the value of the "completed_nodes" field.
func (u *CourseEntityUpsert) ClearCompletedNodes() *CourseEntityUpsert {
u.SetNull(courseentity.FieldCompletedNodes)
return u
}
// SetDesc sets the "desc" field.
func (u *CourseEntityUpsert) SetDesc(v string) *CourseEntityUpsert {
u.Set(courseentity.FieldDesc, v)
@@ -899,6 +971,48 @@ func (u *CourseEntityUpsertOne) UpdateViolence() *CourseEntityUpsertOne {
})
}
// SetNodes sets the "nodes" field.
func (u *CourseEntityUpsertOne) SetNodes(v string) *CourseEntityUpsertOne {
return u.Update(func(s *CourseEntityUpsert) {
s.SetNodes(v)
})
}
// UpdateNodes sets the "nodes" field to the value that was provided on create.
func (u *CourseEntityUpsertOne) UpdateNodes() *CourseEntityUpsertOne {
return u.Update(func(s *CourseEntityUpsert) {
s.UpdateNodes()
})
}
// ClearNodes clears the value of the "nodes" field.
func (u *CourseEntityUpsertOne) ClearNodes() *CourseEntityUpsertOne {
return u.Update(func(s *CourseEntityUpsert) {
s.ClearNodes()
})
}
// SetCompletedNodes sets the "completed_nodes" field.
func (u *CourseEntityUpsertOne) SetCompletedNodes(v string) *CourseEntityUpsertOne {
return u.Update(func(s *CourseEntityUpsert) {
s.SetCompletedNodes(v)
})
}
// UpdateCompletedNodes sets the "completed_nodes" field to the value that was provided on create.
func (u *CourseEntityUpsertOne) UpdateCompletedNodes() *CourseEntityUpsertOne {
return u.Update(func(s *CourseEntityUpsert) {
s.UpdateCompletedNodes()
})
}
// ClearCompletedNodes clears the value of the "completed_nodes" field.
func (u *CourseEntityUpsertOne) ClearCompletedNodes() *CourseEntityUpsertOne {
return u.Update(func(s *CourseEntityUpsert) {
s.ClearCompletedNodes()
})
}
// SetDesc sets the "desc" field.
func (u *CourseEntityUpsertOne) SetDesc(v string) *CourseEntityUpsertOne {
return u.Update(func(s *CourseEntityUpsert) {
@@ -1327,6 +1441,48 @@ func (u *CourseEntityUpsertBulk) UpdateViolence() *CourseEntityUpsertBulk {
})
}
// SetNodes sets the "nodes" field.
func (u *CourseEntityUpsertBulk) SetNodes(v string) *CourseEntityUpsertBulk {
return u.Update(func(s *CourseEntityUpsert) {
s.SetNodes(v)
})
}
// UpdateNodes sets the "nodes" field to the value that was provided on create.
func (u *CourseEntityUpsertBulk) UpdateNodes() *CourseEntityUpsertBulk {
return u.Update(func(s *CourseEntityUpsert) {
s.UpdateNodes()
})
}
// ClearNodes clears the value of the "nodes" field.
func (u *CourseEntityUpsertBulk) ClearNodes() *CourseEntityUpsertBulk {
return u.Update(func(s *CourseEntityUpsert) {
s.ClearNodes()
})
}
// SetCompletedNodes sets the "completed_nodes" field.
func (u *CourseEntityUpsertBulk) SetCompletedNodes(v string) *CourseEntityUpsertBulk {
return u.Update(func(s *CourseEntityUpsert) {
s.SetCompletedNodes(v)
})
}
// UpdateCompletedNodes sets the "completed_nodes" field to the value that was provided on create.
func (u *CourseEntityUpsertBulk) UpdateCompletedNodes() *CourseEntityUpsertBulk {
return u.Update(func(s *CourseEntityUpsert) {
s.UpdateCompletedNodes()
})
}
// ClearCompletedNodes clears the value of the "completed_nodes" field.
func (u *CourseEntityUpsertBulk) ClearCompletedNodes() *CourseEntityUpsertBulk {
return u.Update(func(s *CourseEntityUpsert) {
s.ClearCompletedNodes()
})
}
// SetDesc sets the "desc" field.
func (u *CourseEntityUpsertBulk) SetDesc(v string) *CourseEntityUpsertBulk {
return u.Update(func(s *CourseEntityUpsert) {
+104
View File
@@ -219,6 +219,46 @@ func (_u *CourseEntityUpdate) SetNillableViolence(v *courseentity.Violence) *Cou
return _u
}
// SetNodes sets the "nodes" field.
func (_u *CourseEntityUpdate) SetNodes(v string) *CourseEntityUpdate {
_u.mutation.SetNodes(v)
return _u
}
// SetNillableNodes sets the "nodes" field if the given value is not nil.
func (_u *CourseEntityUpdate) SetNillableNodes(v *string) *CourseEntityUpdate {
if v != nil {
_u.SetNodes(*v)
}
return _u
}
// ClearNodes clears the value of the "nodes" field.
func (_u *CourseEntityUpdate) ClearNodes() *CourseEntityUpdate {
_u.mutation.ClearNodes()
return _u
}
// SetCompletedNodes sets the "completed_nodes" field.
func (_u *CourseEntityUpdate) SetCompletedNodes(v string) *CourseEntityUpdate {
_u.mutation.SetCompletedNodes(v)
return _u
}
// SetNillableCompletedNodes sets the "completed_nodes" field if the given value is not nil.
func (_u *CourseEntityUpdate) SetNillableCompletedNodes(v *string) *CourseEntityUpdate {
if v != nil {
_u.SetCompletedNodes(*v)
}
return _u
}
// ClearCompletedNodes clears the value of the "completed_nodes" field.
func (_u *CourseEntityUpdate) ClearCompletedNodes() *CourseEntityUpdate {
_u.mutation.ClearCompletedNodes()
return _u
}
// SetDesc sets the "desc" field.
func (_u *CourseEntityUpdate) SetDesc(v string) *CourseEntityUpdate {
_u.mutation.SetDesc(v)
@@ -381,6 +421,18 @@ func (_u *CourseEntityUpdate) sqlSave(ctx context.Context) (_node int, err error
if value, ok := _u.mutation.Violence(); ok {
_spec.SetField(courseentity.FieldViolence, field.TypeEnum, value)
}
if value, ok := _u.mutation.Nodes(); ok {
_spec.SetField(courseentity.FieldNodes, field.TypeString, value)
}
if _u.mutation.NodesCleared() {
_spec.ClearField(courseentity.FieldNodes, field.TypeString)
}
if value, ok := _u.mutation.CompletedNodes(); ok {
_spec.SetField(courseentity.FieldCompletedNodes, field.TypeString, value)
}
if _u.mutation.CompletedNodesCleared() {
_spec.ClearField(courseentity.FieldCompletedNodes, field.TypeString)
}
if value, ok := _u.mutation.Desc(); ok {
_spec.SetField(courseentity.FieldDesc, field.TypeString, value)
}
@@ -630,6 +682,46 @@ func (_u *CourseEntityUpdateOne) SetNillableViolence(v *courseentity.Violence) *
return _u
}
// SetNodes sets the "nodes" field.
func (_u *CourseEntityUpdateOne) SetNodes(v string) *CourseEntityUpdateOne {
_u.mutation.SetNodes(v)
return _u
}
// SetNillableNodes sets the "nodes" field if the given value is not nil.
func (_u *CourseEntityUpdateOne) SetNillableNodes(v *string) *CourseEntityUpdateOne {
if v != nil {
_u.SetNodes(*v)
}
return _u
}
// ClearNodes clears the value of the "nodes" field.
func (_u *CourseEntityUpdateOne) ClearNodes() *CourseEntityUpdateOne {
_u.mutation.ClearNodes()
return _u
}
// SetCompletedNodes sets the "completed_nodes" field.
func (_u *CourseEntityUpdateOne) SetCompletedNodes(v string) *CourseEntityUpdateOne {
_u.mutation.SetCompletedNodes(v)
return _u
}
// SetNillableCompletedNodes sets the "completed_nodes" field if the given value is not nil.
func (_u *CourseEntityUpdateOne) SetNillableCompletedNodes(v *string) *CourseEntityUpdateOne {
if v != nil {
_u.SetCompletedNodes(*v)
}
return _u
}
// ClearCompletedNodes clears the value of the "completed_nodes" field.
func (_u *CourseEntityUpdateOne) ClearCompletedNodes() *CourseEntityUpdateOne {
_u.mutation.ClearCompletedNodes()
return _u
}
// SetDesc sets the "desc" field.
func (_u *CourseEntityUpdateOne) SetDesc(v string) *CourseEntityUpdateOne {
_u.mutation.SetDesc(v)
@@ -822,6 +914,18 @@ func (_u *CourseEntityUpdateOne) sqlSave(ctx context.Context) (_node *CourseEnti
if value, ok := _u.mutation.Violence(); ok {
_spec.SetField(courseentity.FieldViolence, field.TypeEnum, value)
}
if value, ok := _u.mutation.Nodes(); ok {
_spec.SetField(courseentity.FieldNodes, field.TypeString, value)
}
if _u.mutation.NodesCleared() {
_spec.ClearField(courseentity.FieldNodes, field.TypeString)
}
if value, ok := _u.mutation.CompletedNodes(); ok {
_spec.SetField(courseentity.FieldCompletedNodes, field.TypeString, value)
}
if _u.mutation.CompletedNodesCleared() {
_spec.ClearField(courseentity.FieldCompletedNodes, field.TypeString)
}
if value, ok := _u.mutation.Desc(); ok {
_spec.SetField(courseentity.FieldDesc, field.TypeString, value)
}
+242
View File
@@ -0,0 +1,242 @@
// ENT数据库文件,请勿编辑。
package ent
import (
"fmt"
"likedream-goframe/internal/ent/cpleave"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/sysuser"
"likedream-goframe/internal/framework/ent2"
"strings"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
// CpLeave is the model entity for the CpLeave schema.
type CpLeave struct {
config `json:"-"`
// ID of the ent.
ID int64 `json:"id,omitempty"`
// CreateTime holds the value of the "create_time" field.
CreateTime *ent2.CustomTime `json:"createTime"`
// UpdateTime holds the value of the "update_time" field.
UpdateTime *ent2.CustomTime `json:"updateTime"`
// CpUserID holds the value of the "cp_user_id" field.
CpUserID int64 `json:"cp_user_id,omitempty"`
// UserID holds the value of the "user_id" field.
UserID int64 `json:"user_id,omitempty"`
// LeaveID holds the value of the "leave_id" field.
LeaveID string `json:"leave_id,omitempty"`
// Title holds the value of the "title" field.
Title string `json:"title,omitempty"`
// Status holds the value of the "status" field.
Status cpleave.Status `json:"status,omitempty"`
// Type holds the value of the "type" field.
Type cpleave.Type `json:"type,omitempty"`
// Desc holds the value of the "desc" field.
Desc string `json:"desc,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the CpLeaveQuery when eager-loading is set.
Edges CpLeaveEdges `json:"edges"`
selectValues sql.SelectValues
}
// CpLeaveEdges holds the relations/edges for other nodes in the graph.
type CpLeaveEdges 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"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
}
// CpUserOrErr returns the CpUser value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e CpLeaveEdges) CpUserOrErr() (*CpUser, error) {
if e.CpUser != nil {
return e.CpUser, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: cpuser.Label}
}
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 CpLeaveEdges) 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"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*CpLeave) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case cpleave.FieldCreateTime, cpleave.FieldUpdateTime:
values[i] = new(ent2.CustomTime)
case cpleave.FieldID, cpleave.FieldCpUserID, cpleave.FieldUserID:
values[i] = new(sql.NullInt64)
case cpleave.FieldLeaveID, cpleave.FieldTitle, cpleave.FieldStatus, cpleave.FieldType, cpleave.FieldDesc:
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 CpLeave fields.
func (_m *CpLeave) 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 cpleave.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
_m.ID = int64(value.Int64)
case cpleave.FieldCreateTime:
if value, ok := values[i].(*ent2.CustomTime); !ok {
return fmt.Errorf("unexpected type %T for field create_time", values[i])
} else if value != nil {
_m.CreateTime = value
}
case cpleave.FieldUpdateTime:
if value, ok := values[i].(*ent2.CustomTime); !ok {
return fmt.Errorf("unexpected type %T for field update_time", values[i])
} else if value != nil {
_m.UpdateTime = value
}
case cpleave.FieldCpUserID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field cp_user_id", values[i])
} else if value.Valid {
_m.CpUserID = value.Int64
}
case cpleave.FieldUserID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field user_id", values[i])
} else if value.Valid {
_m.UserID = value.Int64
}
case cpleave.FieldLeaveID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field leave_id", values[i])
} else if value.Valid {
_m.LeaveID = value.String
}
case cpleave.FieldTitle:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field title", values[i])
} else if value.Valid {
_m.Title = value.String
}
case cpleave.FieldStatus:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field status", values[i])
} else if value.Valid {
_m.Status = cpleave.Status(value.String)
}
case cpleave.FieldType:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field type", values[i])
} else if value.Valid {
_m.Type = cpleave.Type(value.String)
}
case cpleave.FieldDesc:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field desc", values[i])
} else if value.Valid {
_m.Desc = 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 CpLeave.
// This includes values selected through modifiers, order, etc.
func (_m *CpLeave) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryCpUser queries the "cp_user" edge of the CpLeave entity.
func (_m *CpLeave) QueryCpUser() *CpUserQuery {
return NewCpLeaveClient(_m.config).QueryCpUser(_m)
}
// QuerySysUser queries the "sys_user" edge of the CpLeave entity.
func (_m *CpLeave) QuerySysUser() *SysUserQuery {
return NewCpLeaveClient(_m.config).QuerySysUser(_m)
}
// Update returns a builder for updating this CpLeave.
// Note that you need to call CpLeave.Unwrap() before calling this method if this CpLeave
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *CpLeave) Update() *CpLeaveUpdateOne {
return NewCpLeaveClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the CpLeave 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 *CpLeave) Unwrap() *CpLeave {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: CpLeave is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *CpLeave) String() string {
var builder strings.Builder
builder.WriteString("CpLeave(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("create_time=")
builder.WriteString(fmt.Sprintf("%v", _m.CreateTime))
builder.WriteString(", ")
builder.WriteString("update_time=")
builder.WriteString(fmt.Sprintf("%v", _m.UpdateTime))
builder.WriteString(", ")
builder.WriteString("cp_user_id=")
builder.WriteString(fmt.Sprintf("%v", _m.CpUserID))
builder.WriteString(", ")
builder.WriteString("user_id=")
builder.WriteString(fmt.Sprintf("%v", _m.UserID))
builder.WriteString(", ")
builder.WriteString("leave_id=")
builder.WriteString(_m.LeaveID)
builder.WriteString(", ")
builder.WriteString("title=")
builder.WriteString(_m.Title)
builder.WriteString(", ")
builder.WriteString("status=")
builder.WriteString(fmt.Sprintf("%v", _m.Status))
builder.WriteString(", ")
builder.WriteString("type=")
builder.WriteString(fmt.Sprintf("%v", _m.Type))
builder.WriteString(", ")
builder.WriteString("desc=")
builder.WriteString(_m.Desc)
builder.WriteByte(')')
return builder.String()
}
// CpLeaves is a parsable slice of CpLeave.
type CpLeaves []*CpLeave
+224
View File
@@ -0,0 +1,224 @@
// ENT数据库文件,请勿编辑。
package cpleave
import (
"fmt"
"likedream-goframe/internal/framework/ent2"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const (
// Label holds the string label denoting the cpleave type in the database.
Label = "cp_leave"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldCreateTime holds the string denoting the create_time field in the database.
FieldCreateTime = "create_time"
// FieldUpdateTime holds the string denoting the update_time field in the database.
FieldUpdateTime = "update_time"
// FieldCpUserID holds the string denoting the cp_user_id field in the database.
FieldCpUserID = "cp_user_id"
// FieldUserID holds the string denoting the user_id field in the database.
FieldUserID = "user_id"
// FieldLeaveID holds the string denoting the leave_id field in the database.
FieldLeaveID = "leave_id"
// FieldTitle holds the string denoting the title field in the database.
FieldTitle = "title"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// FieldType holds the string denoting the type field in the database.
FieldType = "type"
// FieldDesc holds the string denoting the desc field in the database.
FieldDesc = "desc"
// 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"
// Table holds the table name of the cpleave in the database.
Table = "cp_leaves"
// CpUserTable is the table that holds the cp_user relation/edge.
CpUserTable = "cp_leaves"
// CpUserInverseTable is the table name for the CpUser entity.
// It exists in this package in order to avoid circular dependency with the "cpuser" package.
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_leaves"
// 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"
)
// Columns holds all SQL columns for cpleave fields.
var Columns = []string{
FieldID,
FieldCreateTime,
FieldUpdateTime,
FieldCpUserID,
FieldUserID,
FieldLeaveID,
FieldTitle,
FieldStatus,
FieldType,
FieldDesc,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
// Note that the variables below are initialized by the runtime
// package on the initialization of the application. Therefore,
// it should be imported in the main as follows:
//
// import _ "likedream-goframe/internal/ent/runtime"
var (
Hooks [1]ent.Hook
// DefaultCreateTime holds the default value on creation for the "create_time" field.
DefaultCreateTime func() *ent2.CustomTime
// DefaultUpdateTime holds the default value on creation for the "update_time" field.
DefaultUpdateTime func() *ent2.CustomTime
// LeaveIDValidator is a validator for the "leave_id" field. It is called by the builders before save.
LeaveIDValidator func(string) error
// TitleValidator is a validator for the "title" field. It is called by the builders before save.
TitleValidator func(string) error
)
// Status defines the type for the "status" enum field.
type Status string
// Status values.
const (
StatusDone Status = "done"
StatusFail Status = "fail"
)
func (s Status) String() string {
return string(s)
}
// StatusValidator is a validator for the "status" field enum values. It is called by the builders before save.
func StatusValidator(s Status) error {
switch s {
case StatusDone, StatusFail:
return nil
default:
return fmt.Errorf("cpleave: invalid enum value for status field: %q", s)
}
}
// Type defines the type for the "type" enum field.
type Type string
// Type values.
const (
TypeReport Type = "report"
)
func (_type Type) String() string {
return string(_type)
}
// TypeValidator is a validator for the "type" field enum values. It is called by the builders before save.
func TypeValidator(_type Type) error {
switch _type {
case TypeReport:
return nil
default:
return fmt.Errorf("cpleave: invalid enum value for type field: %q", _type)
}
}
// OrderOption defines the ordering options for the CpLeave queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByCreateTime orders the results by the create_time field.
func ByCreateTime(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreateTime, opts...).ToFunc()
}
// ByUpdateTime orders the results by the update_time field.
func ByUpdateTime(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdateTime, opts...).ToFunc()
}
// ByCpUserID orders the results by the cp_user_id field.
func ByCpUserID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCpUserID, opts...).ToFunc()
}
// ByUserID orders the results by the user_id field.
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUserID, opts...).ToFunc()
}
// ByLeaveID orders the results by the leave_id field.
func ByLeaveID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldLeaveID, opts...).ToFunc()
}
// ByTitle orders the results by the title field.
func ByTitle(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldTitle, opts...).ToFunc()
}
// ByStatus orders the results by the status field.
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStatus, opts...).ToFunc()
}
// ByType orders the results by the type field.
func ByType(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldType, opts...).ToFunc()
}
// ByDesc orders the results by the desc field.
func ByDesc(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDesc, opts...).ToFunc()
}
// ByCpUserField orders the results by cp_user field.
func ByCpUserField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newCpUserStep(), sql.OrderByField(field, opts...))
}
}
// 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...))
}
}
func newCpUserStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(CpUserInverseTable, FieldID),
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),
)
}
+590
View File
@@ -0,0 +1,590 @@
// ENT数据库文件,请勿编辑。
package cpleave
import (
"likedream-goframe/internal/ent/internal"
"likedream-goframe/internal/ent/predicate"
"likedream-goframe/internal/framework/ent2"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
// ID filters vertices based on their ID field.
func ID(id int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldLTE(FieldID, id))
}
// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ.
func CreateTime(v *ent2.CustomTime) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEQ(FieldCreateTime, v))
}
// UpdateTime applies equality check predicate on the "update_time" field. It's identical to UpdateTimeEQ.
func UpdateTime(v *ent2.CustomTime) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEQ(FieldUpdateTime, v))
}
// CpUserID applies equality check predicate on the "cp_user_id" field. It's identical to CpUserIDEQ.
func CpUserID(v int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEQ(FieldCpUserID, v))
}
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
func UserID(v int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEQ(FieldUserID, v))
}
// LeaveID applies equality check predicate on the "leave_id" field. It's identical to LeaveIDEQ.
func LeaveID(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEQ(FieldLeaveID, v))
}
// Title applies equality check predicate on the "title" field. It's identical to TitleEQ.
func Title(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEQ(FieldTitle, v))
}
// Desc applies equality check predicate on the "desc" field. It's identical to DescEQ.
func Desc(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEQ(FieldDesc, v))
}
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
func CreateTimeEQ(v *ent2.CustomTime) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEQ(FieldCreateTime, v))
}
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
func CreateTimeNEQ(v *ent2.CustomTime) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNEQ(FieldCreateTime, v))
}
// CreateTimeIn applies the In predicate on the "create_time" field.
func CreateTimeIn(vs ...*ent2.CustomTime) predicate.CpLeave {
return predicate.CpLeave(sql.FieldIn(FieldCreateTime, vs...))
}
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
func CreateTimeNotIn(vs ...*ent2.CustomTime) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNotIn(FieldCreateTime, vs...))
}
// CreateTimeGT applies the GT predicate on the "create_time" field.
func CreateTimeGT(v *ent2.CustomTime) predicate.CpLeave {
return predicate.CpLeave(sql.FieldGT(FieldCreateTime, v))
}
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
func CreateTimeGTE(v *ent2.CustomTime) predicate.CpLeave {
return predicate.CpLeave(sql.FieldGTE(FieldCreateTime, v))
}
// CreateTimeLT applies the LT predicate on the "create_time" field.
func CreateTimeLT(v *ent2.CustomTime) predicate.CpLeave {
return predicate.CpLeave(sql.FieldLT(FieldCreateTime, v))
}
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
func CreateTimeLTE(v *ent2.CustomTime) predicate.CpLeave {
return predicate.CpLeave(sql.FieldLTE(FieldCreateTime, v))
}
// CreateTimeContains applies the Contains predicate on the "create_time" field.
func CreateTimeContains(v *ent2.CustomTime) predicate.CpLeave {
vc := v.String()
return predicate.CpLeave(sql.FieldContains(FieldCreateTime, vc))
}
// CreateTimeHasPrefix applies the HasPrefix predicate on the "create_time" field.
func CreateTimeHasPrefix(v *ent2.CustomTime) predicate.CpLeave {
vc := v.String()
return predicate.CpLeave(sql.FieldHasPrefix(FieldCreateTime, vc))
}
// CreateTimeHasSuffix applies the HasSuffix predicate on the "create_time" field.
func CreateTimeHasSuffix(v *ent2.CustomTime) predicate.CpLeave {
vc := v.String()
return predicate.CpLeave(sql.FieldHasSuffix(FieldCreateTime, vc))
}
// CreateTimeEqualFold applies the EqualFold predicate on the "create_time" field.
func CreateTimeEqualFold(v *ent2.CustomTime) predicate.CpLeave {
vc := v.String()
return predicate.CpLeave(sql.FieldEqualFold(FieldCreateTime, vc))
}
// CreateTimeContainsFold applies the ContainsFold predicate on the "create_time" field.
func CreateTimeContainsFold(v *ent2.CustomTime) predicate.CpLeave {
vc := v.String()
return predicate.CpLeave(sql.FieldContainsFold(FieldCreateTime, vc))
}
// UpdateTimeEQ applies the EQ predicate on the "update_time" field.
func UpdateTimeEQ(v *ent2.CustomTime) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEQ(FieldUpdateTime, v))
}
// UpdateTimeNEQ applies the NEQ predicate on the "update_time" field.
func UpdateTimeNEQ(v *ent2.CustomTime) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNEQ(FieldUpdateTime, v))
}
// UpdateTimeIn applies the In predicate on the "update_time" field.
func UpdateTimeIn(vs ...*ent2.CustomTime) predicate.CpLeave {
return predicate.CpLeave(sql.FieldIn(FieldUpdateTime, vs...))
}
// UpdateTimeNotIn applies the NotIn predicate on the "update_time" field.
func UpdateTimeNotIn(vs ...*ent2.CustomTime) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNotIn(FieldUpdateTime, vs...))
}
// UpdateTimeGT applies the GT predicate on the "update_time" field.
func UpdateTimeGT(v *ent2.CustomTime) predicate.CpLeave {
return predicate.CpLeave(sql.FieldGT(FieldUpdateTime, v))
}
// UpdateTimeGTE applies the GTE predicate on the "update_time" field.
func UpdateTimeGTE(v *ent2.CustomTime) predicate.CpLeave {
return predicate.CpLeave(sql.FieldGTE(FieldUpdateTime, v))
}
// UpdateTimeLT applies the LT predicate on the "update_time" field.
func UpdateTimeLT(v *ent2.CustomTime) predicate.CpLeave {
return predicate.CpLeave(sql.FieldLT(FieldUpdateTime, v))
}
// UpdateTimeLTE applies the LTE predicate on the "update_time" field.
func UpdateTimeLTE(v *ent2.CustomTime) predicate.CpLeave {
return predicate.CpLeave(sql.FieldLTE(FieldUpdateTime, v))
}
// UpdateTimeContains applies the Contains predicate on the "update_time" field.
func UpdateTimeContains(v *ent2.CustomTime) predicate.CpLeave {
vc := v.String()
return predicate.CpLeave(sql.FieldContains(FieldUpdateTime, vc))
}
// UpdateTimeHasPrefix applies the HasPrefix predicate on the "update_time" field.
func UpdateTimeHasPrefix(v *ent2.CustomTime) predicate.CpLeave {
vc := v.String()
return predicate.CpLeave(sql.FieldHasPrefix(FieldUpdateTime, vc))
}
// UpdateTimeHasSuffix applies the HasSuffix predicate on the "update_time" field.
func UpdateTimeHasSuffix(v *ent2.CustomTime) predicate.CpLeave {
vc := v.String()
return predicate.CpLeave(sql.FieldHasSuffix(FieldUpdateTime, vc))
}
// UpdateTimeEqualFold applies the EqualFold predicate on the "update_time" field.
func UpdateTimeEqualFold(v *ent2.CustomTime) predicate.CpLeave {
vc := v.String()
return predicate.CpLeave(sql.FieldEqualFold(FieldUpdateTime, vc))
}
// UpdateTimeContainsFold applies the ContainsFold predicate on the "update_time" field.
func UpdateTimeContainsFold(v *ent2.CustomTime) predicate.CpLeave {
vc := v.String()
return predicate.CpLeave(sql.FieldContainsFold(FieldUpdateTime, vc))
}
// CpUserIDEQ applies the EQ predicate on the "cp_user_id" field.
func CpUserIDEQ(v int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEQ(FieldCpUserID, v))
}
// CpUserIDNEQ applies the NEQ predicate on the "cp_user_id" field.
func CpUserIDNEQ(v int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNEQ(FieldCpUserID, v))
}
// CpUserIDIn applies the In predicate on the "cp_user_id" field.
func CpUserIDIn(vs ...int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldIn(FieldCpUserID, vs...))
}
// CpUserIDNotIn applies the NotIn predicate on the "cp_user_id" field.
func CpUserIDNotIn(vs ...int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNotIn(FieldCpUserID, vs...))
}
// UserIDEQ applies the EQ predicate on the "user_id" field.
func UserIDEQ(v int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEQ(FieldUserID, v))
}
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
func UserIDNEQ(v int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNEQ(FieldUserID, v))
}
// UserIDIn applies the In predicate on the "user_id" field.
func UserIDIn(vs ...int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldIn(FieldUserID, vs...))
}
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
func UserIDNotIn(vs ...int64) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNotIn(FieldUserID, vs...))
}
// LeaveIDEQ applies the EQ predicate on the "leave_id" field.
func LeaveIDEQ(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEQ(FieldLeaveID, v))
}
// LeaveIDNEQ applies the NEQ predicate on the "leave_id" field.
func LeaveIDNEQ(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNEQ(FieldLeaveID, v))
}
// LeaveIDIn applies the In predicate on the "leave_id" field.
func LeaveIDIn(vs ...string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldIn(FieldLeaveID, vs...))
}
// LeaveIDNotIn applies the NotIn predicate on the "leave_id" field.
func LeaveIDNotIn(vs ...string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNotIn(FieldLeaveID, vs...))
}
// LeaveIDGT applies the GT predicate on the "leave_id" field.
func LeaveIDGT(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldGT(FieldLeaveID, v))
}
// LeaveIDGTE applies the GTE predicate on the "leave_id" field.
func LeaveIDGTE(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldGTE(FieldLeaveID, v))
}
// LeaveIDLT applies the LT predicate on the "leave_id" field.
func LeaveIDLT(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldLT(FieldLeaveID, v))
}
// LeaveIDLTE applies the LTE predicate on the "leave_id" field.
func LeaveIDLTE(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldLTE(FieldLeaveID, v))
}
// LeaveIDContains applies the Contains predicate on the "leave_id" field.
func LeaveIDContains(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldContains(FieldLeaveID, v))
}
// LeaveIDHasPrefix applies the HasPrefix predicate on the "leave_id" field.
func LeaveIDHasPrefix(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldHasPrefix(FieldLeaveID, v))
}
// LeaveIDHasSuffix applies the HasSuffix predicate on the "leave_id" field.
func LeaveIDHasSuffix(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldHasSuffix(FieldLeaveID, v))
}
// LeaveIDEqualFold applies the EqualFold predicate on the "leave_id" field.
func LeaveIDEqualFold(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEqualFold(FieldLeaveID, v))
}
// LeaveIDContainsFold applies the ContainsFold predicate on the "leave_id" field.
func LeaveIDContainsFold(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldContainsFold(FieldLeaveID, v))
}
// TitleEQ applies the EQ predicate on the "title" field.
func TitleEQ(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEQ(FieldTitle, v))
}
// TitleNEQ applies the NEQ predicate on the "title" field.
func TitleNEQ(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNEQ(FieldTitle, v))
}
// TitleIn applies the In predicate on the "title" field.
func TitleIn(vs ...string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldIn(FieldTitle, vs...))
}
// TitleNotIn applies the NotIn predicate on the "title" field.
func TitleNotIn(vs ...string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNotIn(FieldTitle, vs...))
}
// TitleGT applies the GT predicate on the "title" field.
func TitleGT(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldGT(FieldTitle, v))
}
// TitleGTE applies the GTE predicate on the "title" field.
func TitleGTE(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldGTE(FieldTitle, v))
}
// TitleLT applies the LT predicate on the "title" field.
func TitleLT(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldLT(FieldTitle, v))
}
// TitleLTE applies the LTE predicate on the "title" field.
func TitleLTE(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldLTE(FieldTitle, v))
}
// TitleContains applies the Contains predicate on the "title" field.
func TitleContains(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldContains(FieldTitle, v))
}
// TitleHasPrefix applies the HasPrefix predicate on the "title" field.
func TitleHasPrefix(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldHasPrefix(FieldTitle, v))
}
// TitleHasSuffix applies the HasSuffix predicate on the "title" field.
func TitleHasSuffix(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldHasSuffix(FieldTitle, v))
}
// TitleEqualFold applies the EqualFold predicate on the "title" field.
func TitleEqualFold(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEqualFold(FieldTitle, v))
}
// TitleContainsFold applies the ContainsFold predicate on the "title" field.
func TitleContainsFold(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldContainsFold(FieldTitle, v))
}
// StatusEQ applies the EQ predicate on the "status" field.
func StatusEQ(v Status) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEQ(FieldStatus, v))
}
// StatusNEQ applies the NEQ predicate on the "status" field.
func StatusNEQ(v Status) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNEQ(FieldStatus, v))
}
// StatusIn applies the In predicate on the "status" field.
func StatusIn(vs ...Status) predicate.CpLeave {
return predicate.CpLeave(sql.FieldIn(FieldStatus, vs...))
}
// StatusNotIn applies the NotIn predicate on the "status" field.
func StatusNotIn(vs ...Status) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNotIn(FieldStatus, vs...))
}
// TypeEQ applies the EQ predicate on the "type" field.
func TypeEQ(v Type) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEQ(FieldType, v))
}
// TypeNEQ applies the NEQ predicate on the "type" field.
func TypeNEQ(v Type) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNEQ(FieldType, v))
}
// TypeIn applies the In predicate on the "type" field.
func TypeIn(vs ...Type) predicate.CpLeave {
return predicate.CpLeave(sql.FieldIn(FieldType, vs...))
}
// TypeNotIn applies the NotIn predicate on the "type" field.
func TypeNotIn(vs ...Type) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNotIn(FieldType, vs...))
}
// DescEQ applies the EQ predicate on the "desc" field.
func DescEQ(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEQ(FieldDesc, v))
}
// DescNEQ applies the NEQ predicate on the "desc" field.
func DescNEQ(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNEQ(FieldDesc, v))
}
// DescIn applies the In predicate on the "desc" field.
func DescIn(vs ...string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldIn(FieldDesc, vs...))
}
// DescNotIn applies the NotIn predicate on the "desc" field.
func DescNotIn(vs ...string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldNotIn(FieldDesc, vs...))
}
// DescGT applies the GT predicate on the "desc" field.
func DescGT(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldGT(FieldDesc, v))
}
// DescGTE applies the GTE predicate on the "desc" field.
func DescGTE(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldGTE(FieldDesc, v))
}
// DescLT applies the LT predicate on the "desc" field.
func DescLT(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldLT(FieldDesc, v))
}
// DescLTE applies the LTE predicate on the "desc" field.
func DescLTE(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldLTE(FieldDesc, v))
}
// DescContains applies the Contains predicate on the "desc" field.
func DescContains(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldContains(FieldDesc, v))
}
// DescHasPrefix applies the HasPrefix predicate on the "desc" field.
func DescHasPrefix(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldHasPrefix(FieldDesc, v))
}
// DescHasSuffix applies the HasSuffix predicate on the "desc" field.
func DescHasSuffix(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldHasSuffix(FieldDesc, v))
}
// DescIsNil applies the IsNil predicate on the "desc" field.
func DescIsNil() predicate.CpLeave {
return predicate.CpLeave(sql.FieldIsNull(FieldDesc))
}
// DescNotNil applies the NotNil predicate on the "desc" field.
func DescNotNil() predicate.CpLeave {
return predicate.CpLeave(sql.FieldNotNull(FieldDesc))
}
// DescEqualFold applies the EqualFold predicate on the "desc" field.
func DescEqualFold(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldEqualFold(FieldDesc, v))
}
// DescContainsFold applies the ContainsFold predicate on the "desc" field.
func DescContainsFold(v string) predicate.CpLeave {
return predicate.CpLeave(sql.FieldContainsFold(FieldDesc, v))
}
// HasCpUser applies the HasEdge predicate on the "cp_user" edge.
func HasCpUser() predicate.CpLeave {
return predicate.CpLeave(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, CpUserTable, CpUserColumn),
)
schemaConfig := internal.SchemaConfigFromContext(s.Context())
step.To.Schema = schemaConfig.CpUser
step.Edge.Schema = schemaConfig.CpLeave
sqlgraph.HasNeighbors(s, step)
})
}
// HasCpUserWith applies the HasEdge predicate on the "cp_user" edge with a given conditions (other predicates).
func HasCpUserWith(preds ...predicate.CpUser) predicate.CpLeave {
return predicate.CpLeave(func(s *sql.Selector) {
step := newCpUserStep()
schemaConfig := internal.SchemaConfigFromContext(s.Context())
step.To.Schema = schemaConfig.CpUser
step.Edge.Schema = schemaConfig.CpLeave
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasSysUser applies the HasEdge predicate on the "sys_user" edge.
func HasSysUser() predicate.CpLeave {
return predicate.CpLeave(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, SysUserTable, SysUserColumn),
)
schemaConfig := internal.SchemaConfigFromContext(s.Context())
step.To.Schema = schemaConfig.SysUser
step.Edge.Schema = schemaConfig.CpLeave
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.CpLeave {
return predicate.CpLeave(func(s *sql.Selector) {
step := newSysUserStep()
schemaConfig := internal.SchemaConfigFromContext(s.Context())
step.To.Schema = schemaConfig.SysUser
step.Edge.Schema = schemaConfig.CpLeave
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.CpLeave) predicate.CpLeave {
return predicate.CpLeave(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.CpLeave) predicate.CpLeave {
return predicate.CpLeave(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.CpLeave) predicate.CpLeave {
return predicate.CpLeave(sql.NotPredicates(p))
}
+972
View File
@@ -0,0 +1,972 @@
// ENT数据库文件,请勿编辑。
package ent
import (
"context"
"errors"
"fmt"
"likedream-goframe/internal/ent/cpleave"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/sysuser"
"likedream-goframe/internal/framework/ent2"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// CpLeaveCreate is the builder for creating a CpLeave entity.
type CpLeaveCreate struct {
config
mutation *CpLeaveMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetCreateTime sets the "create_time" field.
func (_c *CpLeaveCreate) SetCreateTime(v *ent2.CustomTime) *CpLeaveCreate {
_c.mutation.SetCreateTime(v)
return _c
}
// SetUpdateTime sets the "update_time" field.
func (_c *CpLeaveCreate) SetUpdateTime(v *ent2.CustomTime) *CpLeaveCreate {
_c.mutation.SetUpdateTime(v)
return _c
}
// SetCpUserID sets the "cp_user_id" field.
func (_c *CpLeaveCreate) SetCpUserID(v int64) *CpLeaveCreate {
_c.mutation.SetCpUserID(v)
return _c
}
// SetUserID sets the "user_id" field.
func (_c *CpLeaveCreate) SetUserID(v int64) *CpLeaveCreate {
_c.mutation.SetUserID(v)
return _c
}
// SetLeaveID sets the "leave_id" field.
func (_c *CpLeaveCreate) SetLeaveID(v string) *CpLeaveCreate {
_c.mutation.SetLeaveID(v)
return _c
}
// SetTitle sets the "title" field.
func (_c *CpLeaveCreate) SetTitle(v string) *CpLeaveCreate {
_c.mutation.SetTitle(v)
return _c
}
// SetStatus sets the "status" field.
func (_c *CpLeaveCreate) SetStatus(v cpleave.Status) *CpLeaveCreate {
_c.mutation.SetStatus(v)
return _c
}
// SetType sets the "type" field.
func (_c *CpLeaveCreate) SetType(v cpleave.Type) *CpLeaveCreate {
_c.mutation.SetType(v)
return _c
}
// SetDesc sets the "desc" field.
func (_c *CpLeaveCreate) SetDesc(v string) *CpLeaveCreate {
_c.mutation.SetDesc(v)
return _c
}
// SetNillableDesc sets the "desc" field if the given value is not nil.
func (_c *CpLeaveCreate) SetNillableDesc(v *string) *CpLeaveCreate {
if v != nil {
_c.SetDesc(*v)
}
return _c
}
// SetCpUser sets the "cp_user" edge to the CpUser entity.
func (_c *CpLeaveCreate) SetCpUser(v *CpUser) *CpLeaveCreate {
return _c.SetCpUserID(v.ID)
}
// SetSysUserID sets the "sys_user" edge to the SysUser entity by ID.
func (_c *CpLeaveCreate) SetSysUserID(id int64) *CpLeaveCreate {
_c.mutation.SetSysUserID(id)
return _c
}
// SetSysUser sets the "sys_user" edge to the SysUser entity.
func (_c *CpLeaveCreate) SetSysUser(v *SysUser) *CpLeaveCreate {
return _c.SetSysUserID(v.ID)
}
// Mutation returns the CpLeaveMutation object of the builder.
func (_c *CpLeaveCreate) Mutation() *CpLeaveMutation {
return _c.mutation
}
// Save creates the CpLeave in the database.
func (_c *CpLeaveCreate) Save(ctx context.Context) (*CpLeave, error) {
if err := _c.defaults(); err != nil {
return nil, err
}
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *CpLeaveCreate) SaveX(ctx context.Context) *CpLeave {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *CpLeaveCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *CpLeaveCreate) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_c *CpLeaveCreate) defaults() error {
if _, ok := _c.mutation.CreateTime(); !ok {
if cpleave.DefaultCreateTime == nil {
return fmt.Errorf("ent: uninitialized cpleave.DefaultCreateTime (forgotten import ent/runtime?)")
}
v := cpleave.DefaultCreateTime()
_c.mutation.SetCreateTime(v)
}
if _, ok := _c.mutation.UpdateTime(); !ok {
if cpleave.DefaultUpdateTime == nil {
return fmt.Errorf("ent: uninitialized cpleave.DefaultUpdateTime (forgotten import ent/runtime?)")
}
v := cpleave.DefaultUpdateTime()
_c.mutation.SetUpdateTime(v)
}
return nil
}
// check runs all checks and user-defined validators on the builder.
func (_c *CpLeaveCreate) check() error {
if _, ok := _c.mutation.CreateTime(); !ok {
return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "CpLeave.create_time"`)}
}
if _, ok := _c.mutation.UpdateTime(); !ok {
return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "CpLeave.update_time"`)}
}
if _, ok := _c.mutation.CpUserID(); !ok {
return &ValidationError{Name: "cp_user_id", err: errors.New(`ent: missing required field "CpLeave.cp_user_id"`)}
}
if _, ok := _c.mutation.UserID(); !ok {
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "CpLeave.user_id"`)}
}
if _, ok := _c.mutation.LeaveID(); !ok {
return &ValidationError{Name: "leave_id", err: errors.New(`ent: missing required field "CpLeave.leave_id"`)}
}
if v, ok := _c.mutation.LeaveID(); ok {
if err := cpleave.LeaveIDValidator(v); err != nil {
return &ValidationError{Name: "leave_id", err: fmt.Errorf(`ent: validator failed for field "CpLeave.leave_id": %w`, err)}
}
}
if _, ok := _c.mutation.Title(); !ok {
return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "CpLeave.title"`)}
}
if v, ok := _c.mutation.Title(); ok {
if err := cpleave.TitleValidator(v); err != nil {
return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "CpLeave.title": %w`, err)}
}
}
if _, ok := _c.mutation.Status(); !ok {
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "CpLeave.status"`)}
}
if v, ok := _c.mutation.Status(); ok {
if err := cpleave.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "CpLeave.status": %w`, err)}
}
}
if _, ok := _c.mutation.GetType(); !ok {
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "CpLeave.type"`)}
}
if v, ok := _c.mutation.GetType(); ok {
if err := cpleave.TypeValidator(v); err != nil {
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "CpLeave.type": %w`, err)}
}
}
if len(_c.mutation.CpUserIDs()) == 0 {
return &ValidationError{Name: "cp_user", err: errors.New(`ent: missing required edge "CpLeave.cp_user"`)}
}
if len(_c.mutation.SysUserIDs()) == 0 {
return &ValidationError{Name: "sys_user", err: errors.New(`ent: missing required edge "CpLeave.sys_user"`)}
}
return nil
}
func (_c *CpLeaveCreate) sqlSave(ctx context.Context) (*CpLeave, error) {
if err := _c.check(); err != nil {
return nil, err
}
_node, _spec := _c.createSpec()
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
id := _spec.ID.Value.(int64)
_node.ID = int64(id)
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
func (_c *CpLeaveCreate) createSpec() (*CpLeave, *sqlgraph.CreateSpec) {
var (
_node = &CpLeave{config: _c.config}
_spec = sqlgraph.NewCreateSpec(cpleave.Table, sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64))
)
_spec.Schema = _c.schemaConfig.CpLeave
_spec.OnConflict = _c.conflict
if value, ok := _c.mutation.CreateTime(); ok {
_spec.SetField(cpleave.FieldCreateTime, field.TypeString, value)
_node.CreateTime = value
}
if value, ok := _c.mutation.UpdateTime(); ok {
_spec.SetField(cpleave.FieldUpdateTime, field.TypeString, value)
_node.UpdateTime = value
}
if value, ok := _c.mutation.LeaveID(); ok {
_spec.SetField(cpleave.FieldLeaveID, field.TypeString, value)
_node.LeaveID = value
}
if value, ok := _c.mutation.Title(); ok {
_spec.SetField(cpleave.FieldTitle, field.TypeString, value)
_node.Title = value
}
if value, ok := _c.mutation.Status(); ok {
_spec.SetField(cpleave.FieldStatus, field.TypeEnum, value)
_node.Status = value
}
if value, ok := _c.mutation.GetType(); ok {
_spec.SetField(cpleave.FieldType, field.TypeEnum, value)
_node.Type = value
}
if value, ok := _c.mutation.Desc(); ok {
_spec.SetField(cpleave.FieldDesc, field.TypeString, value)
_node.Desc = value
}
if nodes := _c.mutation.CpUserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cpleave.CpUserTable,
Columns: []string{cpleave.CpUserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
},
}
edge.Schema = _c.schemaConfig.CpLeave
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_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: cpleave.SysUserTable,
Columns: []string{cpleave.SysUserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
},
}
edge.Schema = _c.schemaConfig.CpLeave
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.UserID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.CpLeave.Create().
// SetCreateTime(v).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.CpLeaveUpsert) {
// SetCreateTime(v+v).
// }).
// Exec(ctx)
func (_c *CpLeaveCreate) OnConflict(opts ...sql.ConflictOption) *CpLeaveUpsertOne {
_c.conflict = opts
return &CpLeaveUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.CpLeave.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *CpLeaveCreate) OnConflictColumns(columns ...string) *CpLeaveUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &CpLeaveUpsertOne{
create: _c,
}
}
type (
// CpLeaveUpsertOne is the builder for "upsert"-ing
// one CpLeave node.
CpLeaveUpsertOne struct {
create *CpLeaveCreate
}
// CpLeaveUpsert is the "OnConflict" setter.
CpLeaveUpsert struct {
*sql.UpdateSet
}
)
// SetUpdateTime sets the "update_time" field.
func (u *CpLeaveUpsert) SetUpdateTime(v *ent2.CustomTime) *CpLeaveUpsert {
u.Set(cpleave.FieldUpdateTime, v)
return u
}
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
func (u *CpLeaveUpsert) UpdateUpdateTime() *CpLeaveUpsert {
u.SetExcluded(cpleave.FieldUpdateTime)
return u
}
// SetCpUserID sets the "cp_user_id" field.
func (u *CpLeaveUpsert) SetCpUserID(v int64) *CpLeaveUpsert {
u.Set(cpleave.FieldCpUserID, v)
return u
}
// UpdateCpUserID sets the "cp_user_id" field to the value that was provided on create.
func (u *CpLeaveUpsert) UpdateCpUserID() *CpLeaveUpsert {
u.SetExcluded(cpleave.FieldCpUserID)
return u
}
// SetUserID sets the "user_id" field.
func (u *CpLeaveUpsert) SetUserID(v int64) *CpLeaveUpsert {
u.Set(cpleave.FieldUserID, v)
return u
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *CpLeaveUpsert) UpdateUserID() *CpLeaveUpsert {
u.SetExcluded(cpleave.FieldUserID)
return u
}
// SetLeaveID sets the "leave_id" field.
func (u *CpLeaveUpsert) SetLeaveID(v string) *CpLeaveUpsert {
u.Set(cpleave.FieldLeaveID, v)
return u
}
// UpdateLeaveID sets the "leave_id" field to the value that was provided on create.
func (u *CpLeaveUpsert) UpdateLeaveID() *CpLeaveUpsert {
u.SetExcluded(cpleave.FieldLeaveID)
return u
}
// SetTitle sets the "title" field.
func (u *CpLeaveUpsert) SetTitle(v string) *CpLeaveUpsert {
u.Set(cpleave.FieldTitle, v)
return u
}
// UpdateTitle sets the "title" field to the value that was provided on create.
func (u *CpLeaveUpsert) UpdateTitle() *CpLeaveUpsert {
u.SetExcluded(cpleave.FieldTitle)
return u
}
// SetStatus sets the "status" field.
func (u *CpLeaveUpsert) SetStatus(v cpleave.Status) *CpLeaveUpsert {
u.Set(cpleave.FieldStatus, v)
return u
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *CpLeaveUpsert) UpdateStatus() *CpLeaveUpsert {
u.SetExcluded(cpleave.FieldStatus)
return u
}
// SetType sets the "type" field.
func (u *CpLeaveUpsert) SetType(v cpleave.Type) *CpLeaveUpsert {
u.Set(cpleave.FieldType, v)
return u
}
// UpdateType sets the "type" field to the value that was provided on create.
func (u *CpLeaveUpsert) UpdateType() *CpLeaveUpsert {
u.SetExcluded(cpleave.FieldType)
return u
}
// SetDesc sets the "desc" field.
func (u *CpLeaveUpsert) SetDesc(v string) *CpLeaveUpsert {
u.Set(cpleave.FieldDesc, v)
return u
}
// UpdateDesc sets the "desc" field to the value that was provided on create.
func (u *CpLeaveUpsert) UpdateDesc() *CpLeaveUpsert {
u.SetExcluded(cpleave.FieldDesc)
return u
}
// ClearDesc clears the value of the "desc" field.
func (u *CpLeaveUpsert) ClearDesc() *CpLeaveUpsert {
u.SetNull(cpleave.FieldDesc)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.CpLeave.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *CpLeaveUpsertOne) UpdateNewValues() *CpLeaveUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
if _, exists := u.create.mutation.CreateTime(); exists {
s.SetIgnore(cpleave.FieldCreateTime)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.CpLeave.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *CpLeaveUpsertOne) Ignore() *CpLeaveUpsertOne {
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 *CpLeaveUpsertOne) DoNothing() *CpLeaveUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the CpLeaveCreate.OnConflict
// documentation for more info.
func (u *CpLeaveUpsertOne) Update(set func(*CpLeaveUpsert)) *CpLeaveUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&CpLeaveUpsert{UpdateSet: update})
}))
return u
}
// SetUpdateTime sets the "update_time" field.
func (u *CpLeaveUpsertOne) SetUpdateTime(v *ent2.CustomTime) *CpLeaveUpsertOne {
return u.Update(func(s *CpLeaveUpsert) {
s.SetUpdateTime(v)
})
}
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
func (u *CpLeaveUpsertOne) UpdateUpdateTime() *CpLeaveUpsertOne {
return u.Update(func(s *CpLeaveUpsert) {
s.UpdateUpdateTime()
})
}
// SetCpUserID sets the "cp_user_id" field.
func (u *CpLeaveUpsertOne) SetCpUserID(v int64) *CpLeaveUpsertOne {
return u.Update(func(s *CpLeaveUpsert) {
s.SetCpUserID(v)
})
}
// UpdateCpUserID sets the "cp_user_id" field to the value that was provided on create.
func (u *CpLeaveUpsertOne) UpdateCpUserID() *CpLeaveUpsertOne {
return u.Update(func(s *CpLeaveUpsert) {
s.UpdateCpUserID()
})
}
// SetUserID sets the "user_id" field.
func (u *CpLeaveUpsertOne) SetUserID(v int64) *CpLeaveUpsertOne {
return u.Update(func(s *CpLeaveUpsert) {
s.SetUserID(v)
})
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *CpLeaveUpsertOne) UpdateUserID() *CpLeaveUpsertOne {
return u.Update(func(s *CpLeaveUpsert) {
s.UpdateUserID()
})
}
// SetLeaveID sets the "leave_id" field.
func (u *CpLeaveUpsertOne) SetLeaveID(v string) *CpLeaveUpsertOne {
return u.Update(func(s *CpLeaveUpsert) {
s.SetLeaveID(v)
})
}
// UpdateLeaveID sets the "leave_id" field to the value that was provided on create.
func (u *CpLeaveUpsertOne) UpdateLeaveID() *CpLeaveUpsertOne {
return u.Update(func(s *CpLeaveUpsert) {
s.UpdateLeaveID()
})
}
// SetTitle sets the "title" field.
func (u *CpLeaveUpsertOne) SetTitle(v string) *CpLeaveUpsertOne {
return u.Update(func(s *CpLeaveUpsert) {
s.SetTitle(v)
})
}
// UpdateTitle sets the "title" field to the value that was provided on create.
func (u *CpLeaveUpsertOne) UpdateTitle() *CpLeaveUpsertOne {
return u.Update(func(s *CpLeaveUpsert) {
s.UpdateTitle()
})
}
// SetStatus sets the "status" field.
func (u *CpLeaveUpsertOne) SetStatus(v cpleave.Status) *CpLeaveUpsertOne {
return u.Update(func(s *CpLeaveUpsert) {
s.SetStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *CpLeaveUpsertOne) UpdateStatus() *CpLeaveUpsertOne {
return u.Update(func(s *CpLeaveUpsert) {
s.UpdateStatus()
})
}
// SetType sets the "type" field.
func (u *CpLeaveUpsertOne) SetType(v cpleave.Type) *CpLeaveUpsertOne {
return u.Update(func(s *CpLeaveUpsert) {
s.SetType(v)
})
}
// UpdateType sets the "type" field to the value that was provided on create.
func (u *CpLeaveUpsertOne) UpdateType() *CpLeaveUpsertOne {
return u.Update(func(s *CpLeaveUpsert) {
s.UpdateType()
})
}
// SetDesc sets the "desc" field.
func (u *CpLeaveUpsertOne) SetDesc(v string) *CpLeaveUpsertOne {
return u.Update(func(s *CpLeaveUpsert) {
s.SetDesc(v)
})
}
// UpdateDesc sets the "desc" field to the value that was provided on create.
func (u *CpLeaveUpsertOne) UpdateDesc() *CpLeaveUpsertOne {
return u.Update(func(s *CpLeaveUpsert) {
s.UpdateDesc()
})
}
// ClearDesc clears the value of the "desc" field.
func (u *CpLeaveUpsertOne) ClearDesc() *CpLeaveUpsertOne {
return u.Update(func(s *CpLeaveUpsert) {
s.ClearDesc()
})
}
// Exec executes the query.
func (u *CpLeaveUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for CpLeaveCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *CpLeaveUpsertOne) 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 *CpLeaveUpsertOne) ID(ctx context.Context) (id int64, err error) {
node, err := u.create.Save(ctx)
if err != nil {
return id, err
}
return node.ID, nil
}
// IDX is like ID, but panics if an error occurs.
func (u *CpLeaveUpsertOne) IDX(ctx context.Context) int64 {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// CpLeaveCreateBulk is the builder for creating many CpLeave entities in bulk.
type CpLeaveCreateBulk struct {
config
err error
builders []*CpLeaveCreate
conflict []sql.ConflictOption
}
// Save creates the CpLeave entities in the database.
func (_c *CpLeaveCreateBulk) Save(ctx context.Context) ([]*CpLeave, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*CpLeave, len(_c.builders))
mutators := make([]Mutator, len(_c.builders))
for i := range _c.builders {
func(i int, root context.Context) {
builder := _c.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*CpLeaveMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err := builder.check(); err != nil {
return nil, err
}
builder.mutation = mutation
var err error
nodes[i], specs[i] = builder.createSpec()
if i < len(mutators)-1 {
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
spec.OnConflict = _c.conflict
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
}
}
if err != nil {
return nil, err
}
mutation.id = &nodes[i].ID
if specs[i].ID.Value != nil {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int64(id)
}
mutation.done = true
return nodes[i], nil
})
for i := len(builder.hooks) - 1; i >= 0; i-- {
mut = builder.hooks[i](mut)
}
mutators[i] = mut
}(i, ctx)
}
if len(mutators) > 0 {
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (_c *CpLeaveCreateBulk) SaveX(ctx context.Context) []*CpLeave {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *CpLeaveCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *CpLeaveCreateBulk) 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.CpLeave.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.CpLeaveUpsert) {
// SetCreateTime(v+v).
// }).
// Exec(ctx)
func (_c *CpLeaveCreateBulk) OnConflict(opts ...sql.ConflictOption) *CpLeaveUpsertBulk {
_c.conflict = opts
return &CpLeaveUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.CpLeave.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *CpLeaveCreateBulk) OnConflictColumns(columns ...string) *CpLeaveUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &CpLeaveUpsertBulk{
create: _c,
}
}
// CpLeaveUpsertBulk is the builder for "upsert"-ing
// a bulk of CpLeave nodes.
type CpLeaveUpsertBulk struct {
create *CpLeaveCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.CpLeave.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *CpLeaveUpsertBulk) UpdateNewValues() *CpLeaveUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
for _, b := range u.create.builders {
if _, exists := b.mutation.CreateTime(); exists {
s.SetIgnore(cpleave.FieldCreateTime)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.CpLeave.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *CpLeaveUpsertBulk) Ignore() *CpLeaveUpsertBulk {
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 *CpLeaveUpsertBulk) DoNothing() *CpLeaveUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the CpLeaveCreateBulk.OnConflict
// documentation for more info.
func (u *CpLeaveUpsertBulk) Update(set func(*CpLeaveUpsert)) *CpLeaveUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&CpLeaveUpsert{UpdateSet: update})
}))
return u
}
// SetUpdateTime sets the "update_time" field.
func (u *CpLeaveUpsertBulk) SetUpdateTime(v *ent2.CustomTime) *CpLeaveUpsertBulk {
return u.Update(func(s *CpLeaveUpsert) {
s.SetUpdateTime(v)
})
}
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
func (u *CpLeaveUpsertBulk) UpdateUpdateTime() *CpLeaveUpsertBulk {
return u.Update(func(s *CpLeaveUpsert) {
s.UpdateUpdateTime()
})
}
// SetCpUserID sets the "cp_user_id" field.
func (u *CpLeaveUpsertBulk) SetCpUserID(v int64) *CpLeaveUpsertBulk {
return u.Update(func(s *CpLeaveUpsert) {
s.SetCpUserID(v)
})
}
// UpdateCpUserID sets the "cp_user_id" field to the value that was provided on create.
func (u *CpLeaveUpsertBulk) UpdateCpUserID() *CpLeaveUpsertBulk {
return u.Update(func(s *CpLeaveUpsert) {
s.UpdateCpUserID()
})
}
// SetUserID sets the "user_id" field.
func (u *CpLeaveUpsertBulk) SetUserID(v int64) *CpLeaveUpsertBulk {
return u.Update(func(s *CpLeaveUpsert) {
s.SetUserID(v)
})
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *CpLeaveUpsertBulk) UpdateUserID() *CpLeaveUpsertBulk {
return u.Update(func(s *CpLeaveUpsert) {
s.UpdateUserID()
})
}
// SetLeaveID sets the "leave_id" field.
func (u *CpLeaveUpsertBulk) SetLeaveID(v string) *CpLeaveUpsertBulk {
return u.Update(func(s *CpLeaveUpsert) {
s.SetLeaveID(v)
})
}
// UpdateLeaveID sets the "leave_id" field to the value that was provided on create.
func (u *CpLeaveUpsertBulk) UpdateLeaveID() *CpLeaveUpsertBulk {
return u.Update(func(s *CpLeaveUpsert) {
s.UpdateLeaveID()
})
}
// SetTitle sets the "title" field.
func (u *CpLeaveUpsertBulk) SetTitle(v string) *CpLeaveUpsertBulk {
return u.Update(func(s *CpLeaveUpsert) {
s.SetTitle(v)
})
}
// UpdateTitle sets the "title" field to the value that was provided on create.
func (u *CpLeaveUpsertBulk) UpdateTitle() *CpLeaveUpsertBulk {
return u.Update(func(s *CpLeaveUpsert) {
s.UpdateTitle()
})
}
// SetStatus sets the "status" field.
func (u *CpLeaveUpsertBulk) SetStatus(v cpleave.Status) *CpLeaveUpsertBulk {
return u.Update(func(s *CpLeaveUpsert) {
s.SetStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *CpLeaveUpsertBulk) UpdateStatus() *CpLeaveUpsertBulk {
return u.Update(func(s *CpLeaveUpsert) {
s.UpdateStatus()
})
}
// SetType sets the "type" field.
func (u *CpLeaveUpsertBulk) SetType(v cpleave.Type) *CpLeaveUpsertBulk {
return u.Update(func(s *CpLeaveUpsert) {
s.SetType(v)
})
}
// UpdateType sets the "type" field to the value that was provided on create.
func (u *CpLeaveUpsertBulk) UpdateType() *CpLeaveUpsertBulk {
return u.Update(func(s *CpLeaveUpsert) {
s.UpdateType()
})
}
// SetDesc sets the "desc" field.
func (u *CpLeaveUpsertBulk) SetDesc(v string) *CpLeaveUpsertBulk {
return u.Update(func(s *CpLeaveUpsert) {
s.SetDesc(v)
})
}
// UpdateDesc sets the "desc" field to the value that was provided on create.
func (u *CpLeaveUpsertBulk) UpdateDesc() *CpLeaveUpsertBulk {
return u.Update(func(s *CpLeaveUpsert) {
s.UpdateDesc()
})
}
// ClearDesc clears the value of the "desc" field.
func (u *CpLeaveUpsertBulk) ClearDesc() *CpLeaveUpsertBulk {
return u.Update(func(s *CpLeaveUpsert) {
s.ClearDesc()
})
}
// Exec executes the query.
func (u *CpLeaveUpsertBulk) 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 CpLeaveCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for CpLeaveCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *CpLeaveUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
+91
View File
@@ -0,0 +1,91 @@
// ENT数据库文件,请勿编辑。
package ent
import (
"context"
"likedream-goframe/internal/ent/cpleave"
"likedream-goframe/internal/ent/internal"
"likedream-goframe/internal/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// CpLeaveDelete is the builder for deleting a CpLeave entity.
type CpLeaveDelete struct {
config
hooks []Hook
mutation *CpLeaveMutation
}
// Where appends a list predicates to the CpLeaveDelete builder.
func (_d *CpLeaveDelete) Where(ps ...predicate.CpLeave) *CpLeaveDelete {
_d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (_d *CpLeaveDelete) 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 *CpLeaveDelete) ExecX(ctx context.Context) int {
n, err := _d.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (_d *CpLeaveDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(cpleave.Table, sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64))
_spec.Node.Schema = _d.schemaConfig.CpLeave
ctx = internal.NewSchemaConfigContext(ctx, _d.schemaConfig)
if ps := _d.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
_d.mutation.done = true
return affected, err
}
// CpLeaveDeleteOne is the builder for deleting a single CpLeave entity.
type CpLeaveDeleteOne struct {
_d *CpLeaveDelete
}
// Where appends a list predicates to the CpLeaveDelete builder.
func (_d *CpLeaveDeleteOne) Where(ps ...predicate.CpLeave) *CpLeaveDeleteOne {
_d._d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query.
func (_d *CpLeaveDeleteOne) Exec(ctx context.Context) error {
n, err := _d._d.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{cpleave.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *CpLeaveDeleteOne) ExecX(ctx context.Context) {
if err := _d.Exec(ctx); err != nil {
panic(err)
}
}
+745
View File
@@ -0,0 +1,745 @@
// ENT数据库文件,请勿编辑。
package ent
import (
"context"
"fmt"
"likedream-goframe/internal/ent/cpleave"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/internal"
"likedream-goframe/internal/ent/predicate"
"likedream-goframe/internal/ent/sysuser"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// CpLeaveQuery is the builder for querying CpLeave entities.
type CpLeaveQuery struct {
config
ctx *QueryContext
order []cpleave.OrderOption
inters []Interceptor
predicates []predicate.CpLeave
withCpUser *CpUserQuery
withSysUser *SysUserQuery
modifiers []func(*sql.Selector)
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the CpLeaveQuery builder.
func (_q *CpLeaveQuery) Where(ps ...predicate.CpLeave) *CpLeaveQuery {
_q.predicates = append(_q.predicates, ps...)
return _q
}
// Limit the number of records to be returned by this query.
func (_q *CpLeaveQuery) Limit(limit int) *CpLeaveQuery {
_q.ctx.Limit = &limit
return _q
}
// Offset to start from.
func (_q *CpLeaveQuery) Offset(offset int) *CpLeaveQuery {
_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 *CpLeaveQuery) Unique(unique bool) *CpLeaveQuery {
_q.ctx.Unique = &unique
return _q
}
// Order specifies how the records should be ordered.
func (_q *CpLeaveQuery) Order(o ...cpleave.OrderOption) *CpLeaveQuery {
_q.order = append(_q.order, o...)
return _q
}
// QueryCpUser chains the current query on the "cp_user" edge.
func (_q *CpLeaveQuery) QueryCpUser() *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(cpleave.Table, cpleave.FieldID, selector),
sqlgraph.To(cpuser.Table, cpuser.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, cpleave.CpUserTable, cpleave.CpUserColumn),
)
schemaConfig := _q.schemaConfig
step.To.Schema = schemaConfig.CpUser
step.Edge.Schema = schemaConfig.CpLeave
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QuerySysUser chains the current query on the "sys_user" edge.
func (_q *CpLeaveQuery) 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(cpleave.Table, cpleave.FieldID, selector),
sqlgraph.To(sysuser.Table, sysuser.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, cpleave.SysUserTable, cpleave.SysUserColumn),
)
schemaConfig := _q.schemaConfig
step.To.Schema = schemaConfig.SysUser
step.Edge.Schema = schemaConfig.CpLeave
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first CpLeave entity from the query.
// Returns a *NotFoundError when no CpLeave was found.
func (_q *CpLeaveQuery) First(ctx context.Context) (*CpLeave, 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{cpleave.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (_q *CpLeaveQuery) FirstX(ctx context.Context) *CpLeave {
node, err := _q.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first CpLeave ID from the query.
// Returns a *NotFoundError when no CpLeave ID was found.
func (_q *CpLeaveQuery) FirstID(ctx context.Context) (id int64, err error) {
var ids []int64
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{cpleave.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (_q *CpLeaveQuery) FirstIDX(ctx context.Context) int64 {
id, err := _q.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single CpLeave entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one CpLeave entity is found.
// Returns a *NotFoundError when no CpLeave entities are found.
func (_q *CpLeaveQuery) Only(ctx context.Context) (*CpLeave, 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{cpleave.Label}
default:
return nil, &NotSingularError{cpleave.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (_q *CpLeaveQuery) OnlyX(ctx context.Context) *CpLeave {
node, err := _q.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only CpLeave ID in the query.
// Returns a *NotSingularError when more than one CpLeave ID is found.
// Returns a *NotFoundError when no entities are found.
func (_q *CpLeaveQuery) OnlyID(ctx context.Context) (id int64, err error) {
var ids []int64
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{cpleave.Label}
default:
err = &NotSingularError{cpleave.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (_q *CpLeaveQuery) OnlyIDX(ctx context.Context) int64 {
id, err := _q.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of CpLeaves.
func (_q *CpLeaveQuery) All(ctx context.Context) ([]*CpLeave, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*CpLeave, *CpLeaveQuery]()
return withInterceptors[[]*CpLeave](ctx, _q, qr, _q.inters)
}
// AllX is like All, but panics if an error occurs.
func (_q *CpLeaveQuery) AllX(ctx context.Context) []*CpLeave {
nodes, err := _q.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of CpLeave IDs.
func (_q *CpLeaveQuery) IDs(ctx context.Context) (ids []int64, err error) {
if _q.ctx.Unique == nil && _q.path != nil {
_q.Unique(true)
}
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
if err = _q.Select(cpleave.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (_q *CpLeaveQuery) IDsX(ctx context.Context) []int64 {
ids, err := _q.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (_q *CpLeaveQuery) 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[*CpLeaveQuery](), _q.inters)
}
// CountX is like Count, but panics if an error occurs.
func (_q *CpLeaveQuery) 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 *CpLeaveQuery) 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 *CpLeaveQuery) ExistX(ctx context.Context) bool {
exist, err := _q.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the CpLeaveQuery 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 *CpLeaveQuery) Clone() *CpLeaveQuery {
if _q == nil {
return nil
}
return &CpLeaveQuery{
config: _q.config,
ctx: _q.ctx.Clone(),
order: append([]cpleave.OrderOption{}, _q.order...),
inters: append([]Interceptor{}, _q.inters...),
predicates: append([]predicate.CpLeave{}, _q.predicates...),
withCpUser: _q.withCpUser.Clone(),
withSysUser: _q.withSysUser.Clone(),
// clone intermediate query.
sql: _q.sql.Clone(),
path: _q.path,
modifiers: append([]func(*sql.Selector){}, _q.modifiers...),
}
}
// WithCpUser tells the query-builder to eager-load the nodes that are connected to
// the "cp_user" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *CpLeaveQuery) WithCpUser(opts ...func(*CpUserQuery)) *CpLeaveQuery {
query := (&CpUserClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withCpUser = query
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 *CpLeaveQuery) WithSysUser(opts ...func(*SysUserQuery)) *CpLeaveQuery {
query := (&SysUserClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withSysUser = query
return _q
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// CreateTime *ent2.CustomTime `json:"createTime"`
// Count int `json:"count,omitempty"`
// }
//
// client.CpLeave.Query().
// GroupBy(cpleave.FieldCreateTime).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (_q *CpLeaveQuery) GroupBy(field string, fields ...string) *CpLeaveGroupBy {
_q.ctx.Fields = append([]string{field}, fields...)
grbuild := &CpLeaveGroupBy{build: _q}
grbuild.flds = &_q.ctx.Fields
grbuild.label = cpleave.Label
grbuild.scan = grbuild.Scan
return grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// CreateTime *ent2.CustomTime `json:"createTime"`
// }
//
// client.CpLeave.Query().
// Select(cpleave.FieldCreateTime).
// Scan(ctx, &v)
func (_q *CpLeaveQuery) Select(fields ...string) *CpLeaveSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
sbuild := &CpLeaveSelect{CpLeaveQuery: _q}
sbuild.label = cpleave.Label
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a CpLeaveSelect configured with the given aggregations.
func (_q *CpLeaveQuery) Aggregate(fns ...AggregateFunc) *CpLeaveSelect {
return _q.Select().Aggregate(fns...)
}
func (_q *CpLeaveQuery) 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 !cpleave.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 *CpLeaveQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CpLeave, error) {
var (
nodes = []*CpLeave{}
_spec = _q.querySpec()
loadedTypes = [2]bool{
_q.withCpUser != nil,
_q.withSysUser != nil,
}
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*CpLeave).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &CpLeave{config: _q.config}
nodes = append(nodes, node)
node.Edges.loadedTypes = loadedTypes
return node.assignValues(columns, values)
}
_spec.Node.Schema = _q.schemaConfig.CpLeave
ctx = internal.NewSchemaConfigContext(ctx, _q.schemaConfig)
if len(_q.modifiers) > 0 {
_spec.Modifiers = _q.modifiers
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
if query := _q.withCpUser; query != nil {
if err := _q.loadCpUser(ctx, query, nodes, nil,
func(n *CpLeave, e *CpUser) { n.Edges.CpUser = e }); err != nil {
return nil, err
}
}
if query := _q.withSysUser; query != nil {
if err := _q.loadSysUser(ctx, query, nodes, nil,
func(n *CpLeave, e *SysUser) { n.Edges.SysUser = e }); err != nil {
return nil, err
}
}
return nodes, nil
}
func (_q *CpLeaveQuery) loadCpUser(ctx context.Context, query *CpUserQuery, nodes []*CpLeave, init func(*CpLeave), assign func(*CpLeave, *CpUser)) error {
ids := make([]int64, 0, len(nodes))
nodeids := make(map[int64][]*CpLeave)
for i := range nodes {
fk := nodes[i].CpUserID
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(cpuser.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 "cp_user_id" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (_q *CpLeaveQuery) loadSysUser(ctx context.Context, query *SysUserQuery, nodes []*CpLeave, init func(*CpLeave), assign func(*CpLeave, *SysUser)) error {
ids := make([]int64, 0, len(nodes))
nodeids := make(map[int64][]*CpLeave)
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 *CpLeaveQuery) sqlCount(ctx context.Context) (int, error) {
_spec := _q.querySpec()
_spec.Node.Schema = _q.schemaConfig.CpLeave
ctx = internal.NewSchemaConfigContext(ctx, _q.schemaConfig)
if len(_q.modifiers) > 0 {
_spec.Modifiers = _q.modifiers
}
_spec.Node.Columns = _q.ctx.Fields
if len(_q.ctx.Fields) > 0 {
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
}
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
}
func (_q *CpLeaveQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(cpleave.Table, cpleave.Columns, sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64))
_spec.From = _q.sql
if unique := _q.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if _q.path != nil {
_spec.Unique = true
}
if fields := _q.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, cpleave.FieldID)
for i := range fields {
if fields[i] != cpleave.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
if _q.withCpUser != nil {
_spec.Node.AddColumnOnce(cpleave.FieldCpUserID)
}
if _q.withSysUser != nil {
_spec.Node.AddColumnOnce(cpleave.FieldUserID)
}
}
if ps := _q.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := _q.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := _q.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := _q.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (_q *CpLeaveQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(_q.driver.Dialect())
t1 := builder.Table(cpleave.Table)
columns := _q.ctx.Fields
if len(columns) == 0 {
columns = cpleave.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if _q.sql != nil {
selector = _q.sql
selector.Select(selector.Columns(columns...)...)
}
if _q.ctx.Unique != nil && *_q.ctx.Unique {
selector.Distinct()
}
t1.Schema(_q.schemaConfig.CpLeave)
ctx = internal.NewSchemaConfigContext(ctx, _q.schemaConfig)
selector.WithContext(ctx)
for _, m := range _q.modifiers {
m(selector)
}
for _, p := range _q.predicates {
p(selector)
}
for _, p := range _q.order {
p(selector)
}
if offset := _q.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := _q.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
// either committed or rolled-back.
func (_q *CpLeaveQuery) ForUpdate(opts ...sql.LockOption) *CpLeaveQuery {
if _q.driver.Dialect() == dialect.Postgres {
_q.Unique(false)
}
_q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
s.ForUpdate(opts...)
})
return _q
}
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
// on any rows that are read. Other sessions can read the rows, but cannot modify them
// until your transaction commits.
func (_q *CpLeaveQuery) ForShare(opts ...sql.LockOption) *CpLeaveQuery {
if _q.driver.Dialect() == dialect.Postgres {
_q.Unique(false)
}
_q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
s.ForShare(opts...)
})
return _q
}
// Modify adds a query modifier for attaching custom logic to queries.
func (_q *CpLeaveQuery) Modify(modifiers ...func(s *sql.Selector)) *CpLeaveSelect {
_q.modifiers = append(_q.modifiers, modifiers...)
return _q.Select()
}
// CpLeaveGroupBy is the group-by builder for CpLeave entities.
type CpLeaveGroupBy struct {
selector
build *CpLeaveQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (_g *CpLeaveGroupBy) Aggregate(fns ...AggregateFunc) *CpLeaveGroupBy {
_g.fns = append(_g.fns, fns...)
return _g
}
// Scan applies the selector query and scans the result into the given value.
func (_g *CpLeaveGroupBy) 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[*CpLeaveQuery, *CpLeaveGroupBy](ctx, _g.build, _g, _g.build.inters, v)
}
func (_g *CpLeaveGroupBy) sqlScan(ctx context.Context, root *CpLeaveQuery, 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)
}
// CpLeaveSelect is the builder for selecting fields of CpLeave entities.
type CpLeaveSelect struct {
*CpLeaveQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (_s *CpLeaveSelect) Aggregate(fns ...AggregateFunc) *CpLeaveSelect {
_s.fns = append(_s.fns, fns...)
return _s
}
// Scan applies the selector query and scans the result into the given value.
func (_s *CpLeaveSelect) 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[*CpLeaveQuery, *CpLeaveSelect](ctx, _s.CpLeaveQuery, _s, _s.inters, v)
}
func (_s *CpLeaveSelect) sqlScan(ctx context.Context, root *CpLeaveQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(_s.fns))
for _, fn := range _s.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*_s.selector.flds); {
case n == 0 && len(aggregation) > 0:
selector.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
selector.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// Modify adds a query modifier for attaching custom logic to queries.
func (_s *CpLeaveSelect) Modify(modifiers ...func(s *sql.Selector)) *CpLeaveSelect {
_s.modifiers = append(_s.modifiers, modifiers...)
return _s
}
+709
View File
@@ -0,0 +1,709 @@
// ENT数据库文件,请勿编辑。
package ent
import (
"context"
"errors"
"fmt"
"likedream-goframe/internal/ent/cpleave"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/internal"
"likedream-goframe/internal/ent/predicate"
"likedream-goframe/internal/ent/sysuser"
"likedream-goframe/internal/framework/ent2"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// CpLeaveUpdate is the builder for updating CpLeave entities.
type CpLeaveUpdate struct {
config
hooks []Hook
mutation *CpLeaveMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the CpLeaveUpdate builder.
func (_u *CpLeaveUpdate) Where(ps ...predicate.CpLeave) *CpLeaveUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetUpdateTime sets the "update_time" field.
func (_u *CpLeaveUpdate) SetUpdateTime(v *ent2.CustomTime) *CpLeaveUpdate {
_u.mutation.SetUpdateTime(v)
return _u
}
// SetCpUserID sets the "cp_user_id" field.
func (_u *CpLeaveUpdate) SetCpUserID(v int64) *CpLeaveUpdate {
_u.mutation.SetCpUserID(v)
return _u
}
// SetNillableCpUserID sets the "cp_user_id" field if the given value is not nil.
func (_u *CpLeaveUpdate) SetNillableCpUserID(v *int64) *CpLeaveUpdate {
if v != nil {
_u.SetCpUserID(*v)
}
return _u
}
// SetUserID sets the "user_id" field.
func (_u *CpLeaveUpdate) SetUserID(v int64) *CpLeaveUpdate {
_u.mutation.SetUserID(v)
return _u
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_u *CpLeaveUpdate) SetNillableUserID(v *int64) *CpLeaveUpdate {
if v != nil {
_u.SetUserID(*v)
}
return _u
}
// SetLeaveID sets the "leave_id" field.
func (_u *CpLeaveUpdate) SetLeaveID(v string) *CpLeaveUpdate {
_u.mutation.SetLeaveID(v)
return _u
}
// SetNillableLeaveID sets the "leave_id" field if the given value is not nil.
func (_u *CpLeaveUpdate) SetNillableLeaveID(v *string) *CpLeaveUpdate {
if v != nil {
_u.SetLeaveID(*v)
}
return _u
}
// SetTitle sets the "title" field.
func (_u *CpLeaveUpdate) SetTitle(v string) *CpLeaveUpdate {
_u.mutation.SetTitle(v)
return _u
}
// SetNillableTitle sets the "title" field if the given value is not nil.
func (_u *CpLeaveUpdate) SetNillableTitle(v *string) *CpLeaveUpdate {
if v != nil {
_u.SetTitle(*v)
}
return _u
}
// SetStatus sets the "status" field.
func (_u *CpLeaveUpdate) SetStatus(v cpleave.Status) *CpLeaveUpdate {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *CpLeaveUpdate) SetNillableStatus(v *cpleave.Status) *CpLeaveUpdate {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetType sets the "type" field.
func (_u *CpLeaveUpdate) SetType(v cpleave.Type) *CpLeaveUpdate {
_u.mutation.SetType(v)
return _u
}
// SetNillableType sets the "type" field if the given value is not nil.
func (_u *CpLeaveUpdate) SetNillableType(v *cpleave.Type) *CpLeaveUpdate {
if v != nil {
_u.SetType(*v)
}
return _u
}
// SetDesc sets the "desc" field.
func (_u *CpLeaveUpdate) SetDesc(v string) *CpLeaveUpdate {
_u.mutation.SetDesc(v)
return _u
}
// SetNillableDesc sets the "desc" field if the given value is not nil.
func (_u *CpLeaveUpdate) SetNillableDesc(v *string) *CpLeaveUpdate {
if v != nil {
_u.SetDesc(*v)
}
return _u
}
// ClearDesc clears the value of the "desc" field.
func (_u *CpLeaveUpdate) ClearDesc() *CpLeaveUpdate {
_u.mutation.ClearDesc()
return _u
}
// SetCpUser sets the "cp_user" edge to the CpUser entity.
func (_u *CpLeaveUpdate) SetCpUser(v *CpUser) *CpLeaveUpdate {
return _u.SetCpUserID(v.ID)
}
// SetSysUserID sets the "sys_user" edge to the SysUser entity by ID.
func (_u *CpLeaveUpdate) SetSysUserID(id int64) *CpLeaveUpdate {
_u.mutation.SetSysUserID(id)
return _u
}
// SetSysUser sets the "sys_user" edge to the SysUser entity.
func (_u *CpLeaveUpdate) SetSysUser(v *SysUser) *CpLeaveUpdate {
return _u.SetSysUserID(v.ID)
}
// Mutation returns the CpLeaveMutation object of the builder.
func (_u *CpLeaveUpdate) Mutation() *CpLeaveMutation {
return _u.mutation
}
// ClearCpUser clears the "cp_user" edge to the CpUser entity.
func (_u *CpLeaveUpdate) ClearCpUser() *CpLeaveUpdate {
_u.mutation.ClearCpUser()
return _u
}
// ClearSysUser clears the "sys_user" edge to the SysUser entity.
func (_u *CpLeaveUpdate) ClearSysUser() *CpLeaveUpdate {
_u.mutation.ClearSysUser()
return _u
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *CpLeaveUpdate) 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 *CpLeaveUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *CpLeaveUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *CpLeaveUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *CpLeaveUpdate) check() error {
if v, ok := _u.mutation.LeaveID(); ok {
if err := cpleave.LeaveIDValidator(v); err != nil {
return &ValidationError{Name: "leave_id", err: fmt.Errorf(`ent: validator failed for field "CpLeave.leave_id": %w`, err)}
}
}
if v, ok := _u.mutation.Title(); ok {
if err := cpleave.TitleValidator(v); err != nil {
return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "CpLeave.title": %w`, err)}
}
}
if v, ok := _u.mutation.Status(); ok {
if err := cpleave.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "CpLeave.status": %w`, err)}
}
}
if v, ok := _u.mutation.GetType(); ok {
if err := cpleave.TypeValidator(v); err != nil {
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "CpLeave.type": %w`, err)}
}
}
if _u.mutation.CpUserCleared() && len(_u.mutation.CpUserIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "CpLeave.cp_user"`)
}
if _u.mutation.SysUserCleared() && len(_u.mutation.SysUserIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "CpLeave.sys_user"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *CpLeaveUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *CpLeaveUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *CpLeaveUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(cpleave.Table, cpleave.Columns, sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.UpdateTime(); ok {
_spec.SetField(cpleave.FieldUpdateTime, field.TypeString, value)
}
if value, ok := _u.mutation.LeaveID(); ok {
_spec.SetField(cpleave.FieldLeaveID, field.TypeString, value)
}
if value, ok := _u.mutation.Title(); ok {
_spec.SetField(cpleave.FieldTitle, field.TypeString, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(cpleave.FieldStatus, field.TypeEnum, value)
}
if value, ok := _u.mutation.GetType(); ok {
_spec.SetField(cpleave.FieldType, field.TypeEnum, value)
}
if value, ok := _u.mutation.Desc(); ok {
_spec.SetField(cpleave.FieldDesc, field.TypeString, value)
}
if _u.mutation.DescCleared() {
_spec.ClearField(cpleave.FieldDesc, field.TypeString)
}
if _u.mutation.CpUserCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cpleave.CpUserTable,
Columns: []string{cpleave.CpUserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.CpUserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cpleave.CpUserTable,
Columns: []string{cpleave.CpUserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SysUserCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cpleave.SysUserTable,
Columns: []string{cpleave.SysUserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
_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: cpleave.SysUserTable,
Columns: []string{cpleave.SysUserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.Node.Schema = _u.schemaConfig.CpLeave
ctx = internal.NewSchemaConfigContext(ctx, _u.schemaConfig)
_spec.AddModifiers(_u.modifiers...)
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{cpleave.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// CpLeaveUpdateOne is the builder for updating a single CpLeave entity.
type CpLeaveUpdateOne struct {
config
fields []string
hooks []Hook
mutation *CpLeaveMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetUpdateTime sets the "update_time" field.
func (_u *CpLeaveUpdateOne) SetUpdateTime(v *ent2.CustomTime) *CpLeaveUpdateOne {
_u.mutation.SetUpdateTime(v)
return _u
}
// SetCpUserID sets the "cp_user_id" field.
func (_u *CpLeaveUpdateOne) SetCpUserID(v int64) *CpLeaveUpdateOne {
_u.mutation.SetCpUserID(v)
return _u
}
// SetNillableCpUserID sets the "cp_user_id" field if the given value is not nil.
func (_u *CpLeaveUpdateOne) SetNillableCpUserID(v *int64) *CpLeaveUpdateOne {
if v != nil {
_u.SetCpUserID(*v)
}
return _u
}
// SetUserID sets the "user_id" field.
func (_u *CpLeaveUpdateOne) SetUserID(v int64) *CpLeaveUpdateOne {
_u.mutation.SetUserID(v)
return _u
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_u *CpLeaveUpdateOne) SetNillableUserID(v *int64) *CpLeaveUpdateOne {
if v != nil {
_u.SetUserID(*v)
}
return _u
}
// SetLeaveID sets the "leave_id" field.
func (_u *CpLeaveUpdateOne) SetLeaveID(v string) *CpLeaveUpdateOne {
_u.mutation.SetLeaveID(v)
return _u
}
// SetNillableLeaveID sets the "leave_id" field if the given value is not nil.
func (_u *CpLeaveUpdateOne) SetNillableLeaveID(v *string) *CpLeaveUpdateOne {
if v != nil {
_u.SetLeaveID(*v)
}
return _u
}
// SetTitle sets the "title" field.
func (_u *CpLeaveUpdateOne) SetTitle(v string) *CpLeaveUpdateOne {
_u.mutation.SetTitle(v)
return _u
}
// SetNillableTitle sets the "title" field if the given value is not nil.
func (_u *CpLeaveUpdateOne) SetNillableTitle(v *string) *CpLeaveUpdateOne {
if v != nil {
_u.SetTitle(*v)
}
return _u
}
// SetStatus sets the "status" field.
func (_u *CpLeaveUpdateOne) SetStatus(v cpleave.Status) *CpLeaveUpdateOne {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *CpLeaveUpdateOne) SetNillableStatus(v *cpleave.Status) *CpLeaveUpdateOne {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetType sets the "type" field.
func (_u *CpLeaveUpdateOne) SetType(v cpleave.Type) *CpLeaveUpdateOne {
_u.mutation.SetType(v)
return _u
}
// SetNillableType sets the "type" field if the given value is not nil.
func (_u *CpLeaveUpdateOne) SetNillableType(v *cpleave.Type) *CpLeaveUpdateOne {
if v != nil {
_u.SetType(*v)
}
return _u
}
// SetDesc sets the "desc" field.
func (_u *CpLeaveUpdateOne) SetDesc(v string) *CpLeaveUpdateOne {
_u.mutation.SetDesc(v)
return _u
}
// SetNillableDesc sets the "desc" field if the given value is not nil.
func (_u *CpLeaveUpdateOne) SetNillableDesc(v *string) *CpLeaveUpdateOne {
if v != nil {
_u.SetDesc(*v)
}
return _u
}
// ClearDesc clears the value of the "desc" field.
func (_u *CpLeaveUpdateOne) ClearDesc() *CpLeaveUpdateOne {
_u.mutation.ClearDesc()
return _u
}
// SetCpUser sets the "cp_user" edge to the CpUser entity.
func (_u *CpLeaveUpdateOne) SetCpUser(v *CpUser) *CpLeaveUpdateOne {
return _u.SetCpUserID(v.ID)
}
// SetSysUserID sets the "sys_user" edge to the SysUser entity by ID.
func (_u *CpLeaveUpdateOne) SetSysUserID(id int64) *CpLeaveUpdateOne {
_u.mutation.SetSysUserID(id)
return _u
}
// SetSysUser sets the "sys_user" edge to the SysUser entity.
func (_u *CpLeaveUpdateOne) SetSysUser(v *SysUser) *CpLeaveUpdateOne {
return _u.SetSysUserID(v.ID)
}
// Mutation returns the CpLeaveMutation object of the builder.
func (_u *CpLeaveUpdateOne) Mutation() *CpLeaveMutation {
return _u.mutation
}
// ClearCpUser clears the "cp_user" edge to the CpUser entity.
func (_u *CpLeaveUpdateOne) ClearCpUser() *CpLeaveUpdateOne {
_u.mutation.ClearCpUser()
return _u
}
// ClearSysUser clears the "sys_user" edge to the SysUser entity.
func (_u *CpLeaveUpdateOne) ClearSysUser() *CpLeaveUpdateOne {
_u.mutation.ClearSysUser()
return _u
}
// Where appends a list predicates to the CpLeaveUpdate builder.
func (_u *CpLeaveUpdateOne) Where(ps ...predicate.CpLeave) *CpLeaveUpdateOne {
_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 *CpLeaveUpdateOne) Select(field string, fields ...string) *CpLeaveUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated CpLeave entity.
func (_u *CpLeaveUpdateOne) Save(ctx context.Context) (*CpLeave, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *CpLeaveUpdateOne) SaveX(ctx context.Context) *CpLeave {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *CpLeaveUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *CpLeaveUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *CpLeaveUpdateOne) check() error {
if v, ok := _u.mutation.LeaveID(); ok {
if err := cpleave.LeaveIDValidator(v); err != nil {
return &ValidationError{Name: "leave_id", err: fmt.Errorf(`ent: validator failed for field "CpLeave.leave_id": %w`, err)}
}
}
if v, ok := _u.mutation.Title(); ok {
if err := cpleave.TitleValidator(v); err != nil {
return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "CpLeave.title": %w`, err)}
}
}
if v, ok := _u.mutation.Status(); ok {
if err := cpleave.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "CpLeave.status": %w`, err)}
}
}
if v, ok := _u.mutation.GetType(); ok {
if err := cpleave.TypeValidator(v); err != nil {
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "CpLeave.type": %w`, err)}
}
}
if _u.mutation.CpUserCleared() && len(_u.mutation.CpUserIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "CpLeave.cp_user"`)
}
if _u.mutation.SysUserCleared() && len(_u.mutation.SysUserIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "CpLeave.sys_user"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *CpLeaveUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *CpLeaveUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *CpLeaveUpdateOne) sqlSave(ctx context.Context) (_node *CpLeave, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(cpleave.Table, cpleave.Columns, sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "CpLeave.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, cpleave.FieldID)
for _, f := range fields {
if !cpleave.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != cpleave.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.UpdateTime(); ok {
_spec.SetField(cpleave.FieldUpdateTime, field.TypeString, value)
}
if value, ok := _u.mutation.LeaveID(); ok {
_spec.SetField(cpleave.FieldLeaveID, field.TypeString, value)
}
if value, ok := _u.mutation.Title(); ok {
_spec.SetField(cpleave.FieldTitle, field.TypeString, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(cpleave.FieldStatus, field.TypeEnum, value)
}
if value, ok := _u.mutation.GetType(); ok {
_spec.SetField(cpleave.FieldType, field.TypeEnum, value)
}
if value, ok := _u.mutation.Desc(); ok {
_spec.SetField(cpleave.FieldDesc, field.TypeString, value)
}
if _u.mutation.DescCleared() {
_spec.ClearField(cpleave.FieldDesc, field.TypeString)
}
if _u.mutation.CpUserCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cpleave.CpUserTable,
Columns: []string{cpleave.CpUserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.CpUserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cpleave.CpUserTable,
Columns: []string{cpleave.CpUserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SysUserCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cpleave.SysUserTable,
Columns: []string{cpleave.SysUserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
_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: cpleave.SysUserTable,
Columns: []string{cpleave.SysUserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.Node.Schema = _u.schemaConfig.CpLeave
ctx = internal.NewSchemaConfigContext(ctx, _u.schemaConfig)
_spec.AddModifiers(_u.modifiers...)
_node = &CpLeave{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{cpleave.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}
+2 -2
View File
@@ -411,7 +411,7 @@ func (_q *CpSchoolQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CpS
func(n *CpSchool) { n.Edges.Cpusers = []*CpUser{} },
func(n *CpSchool, e *CpUser) {
n.Edges.Cpusers = append(n.Edges.Cpusers, e)
if !e.Edges.loadedTypes[3] {
if !e.Edges.loadedTypes[4] {
e.Edges.School = n
}
}); err != nil {
@@ -423,7 +423,7 @@ func (_q *CpSchoolQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CpS
func(n *CpSchool) { n.appendNamedCpusers(name) },
func(n *CpSchool, e *CpUser) {
n.appendNamedCpusers(name, e)
if !e.Edges.loadedTypes[3] {
if !e.Edges.loadedTypes[4] {
e.Edges.School = n
}
}); err != nil {
+45 -4
View File
@@ -49,6 +49,8 @@ type CpUser struct {
type CpUserEdges struct {
// Cptasks holds the value of the cptasks edge.
Cptasks []*CpTask `json:"cptasks,omitempty"`
// CpLeave holds the value of the cp_leave edge.
CpLeave []*CpLeave `json:"cp_leave,omitempty"`
// Sysuser holds the value of the sysuser edge.
Sysuser *SysUser `json:"sysuser,omitempty"`
// CpTaskLogs holds the value of the cp_task_logs edge.
@@ -57,8 +59,9 @@ type CpUserEdges struct {
School *CpSchool `json:"school,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [4]bool
loadedTypes [5]bool
namedCptasks map[string][]*CpTask
namedCpLeave map[string][]*CpLeave
namedCpTaskLogs map[string][]*CpTaskLog
}
@@ -71,12 +74,21 @@ func (e CpUserEdges) CptasksOrErr() ([]*CpTask, error) {
return nil, &NotLoadedError{edge: "cptasks"}
}
// CpLeaveOrErr returns the CpLeave value or an error if the edge
// was not loaded in eager-loading.
func (e CpUserEdges) CpLeaveOrErr() ([]*CpLeave, error) {
if e.loadedTypes[1] {
return e.CpLeave, nil
}
return nil, &NotLoadedError{edge: "cp_leave"}
}
// 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 CpUserEdges) SysuserOrErr() (*SysUser, error) {
if e.Sysuser != nil {
return e.Sysuser, nil
} else if e.loadedTypes[1] {
} else if e.loadedTypes[2] {
return nil, &NotFoundError{label: sysuser.Label}
}
return nil, &NotLoadedError{edge: "sysuser"}
@@ -85,7 +97,7 @@ func (e CpUserEdges) SysuserOrErr() (*SysUser, error) {
// CpTaskLogsOrErr returns the CpTaskLogs value or an error if the edge
// was not loaded in eager-loading.
func (e CpUserEdges) CpTaskLogsOrErr() ([]*CpTaskLog, error) {
if e.loadedTypes[2] {
if e.loadedTypes[3] {
return e.CpTaskLogs, nil
}
return nil, &NotLoadedError{edge: "cp_task_logs"}
@@ -96,7 +108,7 @@ func (e CpUserEdges) CpTaskLogsOrErr() ([]*CpTaskLog, error) {
func (e CpUserEdges) SchoolOrErr() (*CpSchool, error) {
if e.School != nil {
return e.School, nil
} else if e.loadedTypes[3] {
} else if e.loadedTypes[4] {
return nil, &NotFoundError{label: cpschool.Label}
}
return nil, &NotLoadedError{edge: "school"}
@@ -212,6 +224,11 @@ func (_m *CpUser) QueryCptasks() *CpTaskQuery {
return NewCpUserClient(_m.config).QueryCptasks(_m)
}
// QueryCpLeave queries the "cp_leave" edge of the CpUser entity.
func (_m *CpUser) QueryCpLeave() *CpLeaveQuery {
return NewCpUserClient(_m.config).QueryCpLeave(_m)
}
// QuerySysuser queries the "sysuser" edge of the CpUser entity.
func (_m *CpUser) QuerySysuser() *SysUserQuery {
return NewCpUserClient(_m.config).QuerySysuser(_m)
@@ -307,6 +324,30 @@ func (_m *CpUser) appendNamedCptasks(name string, edges ...*CpTask) {
}
}
// NamedCpLeave returns the CpLeave named value or an error if the edge was not
// loaded in eager-loading with this name.
func (_m *CpUser) NamedCpLeave(name string) ([]*CpLeave, error) {
if _m.Edges.namedCpLeave == nil {
return nil, &NotLoadedError{edge: name}
}
nodes, ok := _m.Edges.namedCpLeave[name]
if !ok {
return nil, &NotLoadedError{edge: name}
}
return nodes, nil
}
func (_m *CpUser) appendNamedCpLeave(name string, edges ...*CpLeave) {
if _m.Edges.namedCpLeave == nil {
_m.Edges.namedCpLeave = make(map[string][]*CpLeave)
}
if len(edges) == 0 {
_m.Edges.namedCpLeave[name] = []*CpLeave{}
} else {
_m.Edges.namedCpLeave[name] = append(_m.Edges.namedCpLeave[name], edges...)
}
}
// NamedCpTaskLogs returns the CpTaskLogs named value or an error if the edge was not
// loaded in eager-loading with this name.
func (_m *CpUser) NamedCpTaskLogs(name string) ([]*CpTaskLog, error) {
+30
View File
@@ -38,6 +38,8 @@ const (
FieldMobileType = "mobile_type"
// EdgeCptasks holds the string denoting the cptasks edge name in mutations.
EdgeCptasks = "cptasks"
// EdgeCpLeave holds the string denoting the cp_leave edge name in mutations.
EdgeCpLeave = "cp_leave"
// EdgeSysuser holds the string denoting the sysuser edge name in mutations.
EdgeSysuser = "sysuser"
// EdgeCpTaskLogs holds the string denoting the cp_task_logs edge name in mutations.
@@ -53,6 +55,13 @@ const (
CptasksInverseTable = "cp_tasks"
// CptasksColumn is the table column denoting the cptasks relation/edge.
CptasksColumn = "cp_user_id"
// CpLeaveTable is the table that holds the cp_leave relation/edge.
CpLeaveTable = "cp_leaves"
// CpLeaveInverseTable is the table name for the CpLeave entity.
// It exists in this package in order to avoid circular dependency with the "cpleave" package.
CpLeaveInverseTable = "cp_leaves"
// CpLeaveColumn is the table column denoting the cp_leave relation/edge.
CpLeaveColumn = "cp_user_id"
// SysuserTable is the table that holds the sysuser relation/edge.
SysuserTable = "cp_users"
// SysuserInverseTable is the table name for the SysUser entity.
@@ -215,6 +224,20 @@ func ByCptasks(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
}
}
// ByCpLeaveCount orders the results by cp_leave count.
func ByCpLeaveCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newCpLeaveStep(), opts...)
}
}
// ByCpLeave orders the results by cp_leave terms.
func ByCpLeave(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newCpLeaveStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
// BySysuserField orders the results by sysuser field.
func BySysuserField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
@@ -249,6 +272,13 @@ func newCptasksStep() *sqlgraph.Step {
sqlgraph.Edge(sqlgraph.O2M, false, CptasksTable, CptasksColumn),
)
}
func newCpLeaveStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(CpLeaveInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, CpLeaveTable, CpLeaveColumn),
)
}
func newSysuserStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
+29
View File
@@ -730,6 +730,35 @@ func HasCptasksWith(preds ...predicate.CpTask) predicate.CpUser {
})
}
// HasCpLeave applies the HasEdge predicate on the "cp_leave" edge.
func HasCpLeave() predicate.CpUser {
return predicate.CpUser(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, CpLeaveTable, CpLeaveColumn),
)
schemaConfig := internal.SchemaConfigFromContext(s.Context())
step.To.Schema = schemaConfig.CpLeave
step.Edge.Schema = schemaConfig.CpLeave
sqlgraph.HasNeighbors(s, step)
})
}
// HasCpLeaveWith applies the HasEdge predicate on the "cp_leave" edge with a given conditions (other predicates).
func HasCpLeaveWith(preds ...predicate.CpLeave) predicate.CpUser {
return predicate.CpUser(func(s *sql.Selector) {
step := newCpLeaveStep()
schemaConfig := internal.SchemaConfigFromContext(s.Context())
step.To.Schema = schemaConfig.CpLeave
step.Edge.Schema = schemaConfig.CpLeave
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasSysuser applies the HasEdge predicate on the "sysuser" edge.
func HasSysuser() predicate.CpUser {
return predicate.CpUser(func(s *sql.Selector) {
+33
View File
@@ -6,6 +6,7 @@ import (
"context"
"errors"
"fmt"
"likedream-goframe/internal/ent/cpleave"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
@@ -125,6 +126,21 @@ func (_c *CpUserCreate) AddCptasks(v ...*CpTask) *CpUserCreate {
return _c.AddCptaskIDs(ids...)
}
// AddCpLeaveIDs adds the "cp_leave" edge to the CpLeave entity by IDs.
func (_c *CpUserCreate) AddCpLeaveIDs(ids ...int64) *CpUserCreate {
_c.mutation.AddCpLeaveIDs(ids...)
return _c
}
// AddCpLeave adds the "cp_leave" edges to the CpLeave entity.
func (_c *CpUserCreate) AddCpLeave(v ...*CpLeave) *CpUserCreate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddCpLeaveIDs(ids...)
}
// SetSysuserID sets the "sysuser" edge to the SysUser entity by ID.
func (_c *CpUserCreate) SetSysuserID(id int64) *CpUserCreate {
_c.mutation.SetSysuserID(id)
@@ -336,6 +352,23 @@ func (_c *CpUserCreate) createSpec() (*CpUser, *sqlgraph.CreateSpec) {
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.CpLeaveIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpuser.CpLeaveTable,
Columns: []string{cpuser.CpLeaveColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
},
}
edge.Schema = _c.schemaConfig.CpLeave
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.SysuserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
+110 -1
View File
@@ -6,6 +6,7 @@ import (
"context"
"database/sql/driver"
"fmt"
"likedream-goframe/internal/ent/cpleave"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
@@ -30,11 +31,13 @@ type CpUserQuery struct {
inters []Interceptor
predicates []predicate.CpUser
withCptasks *CpTaskQuery
withCpLeave *CpLeaveQuery
withSysuser *SysUserQuery
withCpTaskLogs *CpTaskLogQuery
withSchool *CpSchoolQuery
modifiers []func(*sql.Selector)
withNamedCptasks map[string]*CpTaskQuery
withNamedCpLeave map[string]*CpLeaveQuery
withNamedCpTaskLogs map[string]*CpTaskLogQuery
// intermediate query (i.e. traversal path).
sql *sql.Selector
@@ -97,6 +100,31 @@ func (_q *CpUserQuery) QueryCptasks() *CpTaskQuery {
return query
}
// QueryCpLeave chains the current query on the "cp_leave" edge.
func (_q *CpUserQuery) QueryCpLeave() *CpLeaveQuery {
query := (&CpLeaveClient{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(cpleave.Table, cpleave.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, cpuser.CpLeaveTable, cpuser.CpLeaveColumn),
)
schemaConfig := _q.schemaConfig
step.To.Schema = schemaConfig.CpLeave
step.Edge.Schema = schemaConfig.CpLeave
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QuerySysuser chains the current query on the "sysuser" edge.
func (_q *CpUserQuery) QuerySysuser() *SysUserQuery {
query := (&SysUserClient{config: _q.config}).Query()
@@ -365,6 +393,7 @@ func (_q *CpUserQuery) Clone() *CpUserQuery {
inters: append([]Interceptor{}, _q.inters...),
predicates: append([]predicate.CpUser{}, _q.predicates...),
withCptasks: _q.withCptasks.Clone(),
withCpLeave: _q.withCpLeave.Clone(),
withSysuser: _q.withSysuser.Clone(),
withCpTaskLogs: _q.withCpTaskLogs.Clone(),
withSchool: _q.withSchool.Clone(),
@@ -386,6 +415,17 @@ func (_q *CpUserQuery) WithCptasks(opts ...func(*CpTaskQuery)) *CpUserQuery {
return _q
}
// WithCpLeave tells the query-builder to eager-load the nodes that are connected to
// the "cp_leave" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *CpUserQuery) WithCpLeave(opts ...func(*CpLeaveQuery)) *CpUserQuery {
query := (&CpLeaveClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withCpLeave = query
return _q
}
// WithSysuser tells the query-builder to eager-load the nodes that are connected to
// the "sysuser" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *CpUserQuery) WithSysuser(opts ...func(*SysUserQuery)) *CpUserQuery {
@@ -497,8 +537,9 @@ func (_q *CpUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CpUse
var (
nodes = []*CpUser{}
_spec = _q.querySpec()
loadedTypes = [4]bool{
loadedTypes = [5]bool{
_q.withCptasks != nil,
_q.withCpLeave != nil,
_q.withSysuser != nil,
_q.withCpTaskLogs != nil,
_q.withSchool != nil,
@@ -539,6 +580,18 @@ func (_q *CpUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CpUse
return nil, err
}
}
if query := _q.withCpLeave; query != nil {
if err := _q.loadCpLeave(ctx, query, nodes,
func(n *CpUser) { n.Edges.CpLeave = []*CpLeave{} },
func(n *CpUser, e *CpLeave) {
n.Edges.CpLeave = append(n.Edges.CpLeave, e)
if !e.Edges.loadedTypes[0] {
e.Edges.CpUser = n
}
}); err != nil {
return nil, err
}
}
if query := _q.withSysuser; query != nil {
if err := _q.loadSysuser(ctx, query, nodes, nil,
func(n *CpUser, e *SysUser) { n.Edges.Sysuser = e }); err != nil {
@@ -575,6 +628,18 @@ func (_q *CpUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CpUse
return nil, err
}
}
for name, query := range _q.withNamedCpLeave {
if err := _q.loadCpLeave(ctx, query, nodes,
func(n *CpUser) { n.appendNamedCpLeave(name) },
func(n *CpUser, e *CpLeave) {
n.appendNamedCpLeave(name, e)
if !e.Edges.loadedTypes[0] {
e.Edges.CpUser = n
}
}); err != nil {
return nil, err
}
}
for name, query := range _q.withNamedCpTaskLogs {
if err := _q.loadCpTaskLogs(ctx, query, nodes,
func(n *CpUser) { n.appendNamedCpTaskLogs(name) },
@@ -620,6 +685,36 @@ func (_q *CpUserQuery) loadCptasks(ctx context.Context, query *CpTaskQuery, node
}
return nil
}
func (_q *CpUserQuery) loadCpLeave(ctx context.Context, query *CpLeaveQuery, nodes []*CpUser, init func(*CpUser), assign func(*CpUser, *CpLeave)) error {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[int64]*CpUser)
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(cpleave.FieldCpUserID)
}
query.Where(predicate.CpLeave(func(s *sql.Selector) {
s.Where(sql.InValues(s.C(cpuser.CpLeaveColumn), fks...))
}))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
fk := n.CpUserID
node, ok := nodeids[fk]
if !ok {
return fmt.Errorf(`unexpected referenced foreign-key "cp_user_id" returned %v for node %v`, fk, n.ID)
}
assign(node, n)
}
return nil
}
func (_q *CpUserQuery) loadSysuser(ctx context.Context, query *SysUserQuery, nodes []*CpUser, init func(*CpUser), assign func(*CpUser, *SysUser)) error {
ids := make([]int64, 0, len(nodes))
nodeids := make(map[int64][]*CpUser)
@@ -853,6 +948,20 @@ func (_q *CpUserQuery) WithNamedCptasks(name string, opts ...func(*CpTaskQuery))
return _q
}
// WithNamedCpLeave tells the query-builder to eager-load the nodes that are connected to the "cp_leave"
// edge with the given name. The optional arguments are used to configure the query builder of the edge.
func (_q *CpUserQuery) WithNamedCpLeave(name string, opts ...func(*CpLeaveQuery)) *CpUserQuery {
query := (&CpLeaveClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
if _q.withNamedCpLeave == nil {
_q.withNamedCpLeave = make(map[string]*CpLeaveQuery)
}
_q.withNamedCpLeave[name] = query
return _q
}
// WithNamedCpTaskLogs tells the query-builder to eager-load the nodes that are connected to the "cp_task_logs"
// edge with the given name. The optional arguments are used to configure the query builder of the edge.
func (_q *CpUserQuery) WithNamedCpTaskLogs(name string, opts ...func(*CpTaskLogQuery)) *CpUserQuery {
+169
View File
@@ -6,6 +6,7 @@ import (
"context"
"errors"
"fmt"
"likedream-goframe/internal/ent/cpleave"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
@@ -185,6 +186,21 @@ func (_u *CpUserUpdate) AddCptasks(v ...*CpTask) *CpUserUpdate {
return _u.AddCptaskIDs(ids...)
}
// AddCpLeaveIDs adds the "cp_leave" edge to the CpLeave entity by IDs.
func (_u *CpUserUpdate) AddCpLeaveIDs(ids ...int64) *CpUserUpdate {
_u.mutation.AddCpLeaveIDs(ids...)
return _u
}
// AddCpLeave adds the "cp_leave" edges to the CpLeave entity.
func (_u *CpUserUpdate) AddCpLeave(v ...*CpLeave) *CpUserUpdate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddCpLeaveIDs(ids...)
}
// SetSysuserID sets the "sysuser" edge to the SysUser entity by ID.
func (_u *CpUserUpdate) SetSysuserID(id int64) *CpUserUpdate {
_u.mutation.SetSysuserID(id)
@@ -242,6 +258,27 @@ func (_u *CpUserUpdate) RemoveCptasks(v ...*CpTask) *CpUserUpdate {
return _u.RemoveCptaskIDs(ids...)
}
// ClearCpLeave clears all "cp_leave" edges to the CpLeave entity.
func (_u *CpUserUpdate) ClearCpLeave() *CpUserUpdate {
_u.mutation.ClearCpLeave()
return _u
}
// RemoveCpLeaveIDs removes the "cp_leave" edge to CpLeave entities by IDs.
func (_u *CpUserUpdate) RemoveCpLeaveIDs(ids ...int64) *CpUserUpdate {
_u.mutation.RemoveCpLeaveIDs(ids...)
return _u
}
// RemoveCpLeave removes "cp_leave" edges to CpLeave entities.
func (_u *CpUserUpdate) RemoveCpLeave(v ...*CpLeave) *CpUserUpdate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveCpLeaveIDs(ids...)
}
// ClearSysuser clears the "sysuser" edge to the SysUser entity.
func (_u *CpUserUpdate) ClearSysuser() *CpUserUpdate {
_u.mutation.ClearSysuser()
@@ -429,6 +466,54 @@ func (_u *CpUserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.CpLeaveCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpuser.CpLeaveTable,
Columns: []string{cpuser.CpLeaveColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedCpLeaveIDs(); len(nodes) > 0 && !_u.mutation.CpLeaveCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpuser.CpLeaveTable,
Columns: []string{cpuser.CpLeaveColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.CpLeaveIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpuser.CpLeaveTable,
Columns: []string{cpuser.CpLeaveColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SysuserCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
@@ -714,6 +799,21 @@ func (_u *CpUserUpdateOne) AddCptasks(v ...*CpTask) *CpUserUpdateOne {
return _u.AddCptaskIDs(ids...)
}
// AddCpLeaveIDs adds the "cp_leave" edge to the CpLeave entity by IDs.
func (_u *CpUserUpdateOne) AddCpLeaveIDs(ids ...int64) *CpUserUpdateOne {
_u.mutation.AddCpLeaveIDs(ids...)
return _u
}
// AddCpLeave adds the "cp_leave" edges to the CpLeave entity.
func (_u *CpUserUpdateOne) AddCpLeave(v ...*CpLeave) *CpUserUpdateOne {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddCpLeaveIDs(ids...)
}
// SetSysuserID sets the "sysuser" edge to the SysUser entity by ID.
func (_u *CpUserUpdateOne) SetSysuserID(id int64) *CpUserUpdateOne {
_u.mutation.SetSysuserID(id)
@@ -771,6 +871,27 @@ func (_u *CpUserUpdateOne) RemoveCptasks(v ...*CpTask) *CpUserUpdateOne {
return _u.RemoveCptaskIDs(ids...)
}
// ClearCpLeave clears all "cp_leave" edges to the CpLeave entity.
func (_u *CpUserUpdateOne) ClearCpLeave() *CpUserUpdateOne {
_u.mutation.ClearCpLeave()
return _u
}
// RemoveCpLeaveIDs removes the "cp_leave" edge to CpLeave entities by IDs.
func (_u *CpUserUpdateOne) RemoveCpLeaveIDs(ids ...int64) *CpUserUpdateOne {
_u.mutation.RemoveCpLeaveIDs(ids...)
return _u
}
// RemoveCpLeave removes "cp_leave" edges to CpLeave entities.
func (_u *CpUserUpdateOne) RemoveCpLeave(v ...*CpLeave) *CpUserUpdateOne {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveCpLeaveIDs(ids...)
}
// ClearSysuser clears the "sysuser" edge to the SysUser entity.
func (_u *CpUserUpdateOne) ClearSysuser() *CpUserUpdateOne {
_u.mutation.ClearSysuser()
@@ -988,6 +1109,54 @@ func (_u *CpUserUpdateOne) sqlSave(ctx context.Context) (_node *CpUser, err erro
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.CpLeaveCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpuser.CpLeaveTable,
Columns: []string{cpuser.CpLeaveColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedCpLeaveIDs(); len(nodes) > 0 && !_u.mutation.CpLeaveCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpuser.CpLeaveTable,
Columns: []string{cpuser.CpLeaveColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.CpLeaveIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpuser.CpLeaveTable,
Columns: []string{cpuser.CpLeaveColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SysuserCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
+2
View File
@@ -8,6 +8,7 @@ import (
"fmt"
"likedream-goframe/internal/ent/courseentity"
"likedream-goframe/internal/ent/cpimage"
"likedream-goframe/internal/ent/cpleave"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
@@ -86,6 +87,7 @@ func checkColumn(t, c string) error {
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
courseentity.Table: courseentity.ValidColumn,
cpimage.Table: cpimage.ValidColumn,
cpleave.Table: cpleave.ValidColumn,
cpschool.Table: cpschool.ValidColumn,
cptask.Table: cptask.ValidColumn,
cptasklog.Table: cptasklog.ValidColumn,
+259 -35
View File
@@ -5,6 +5,7 @@ package ent
import (
"likedream-goframe/internal/ent/courseentity"
"likedream-goframe/internal/ent/cpimage"
"likedream-goframe/internal/ent/cpleave"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
@@ -25,7 +26,7 @@ import (
// schemaGraph holds a representation of ent/schema at runtime.
var schemaGraph = func() *sqlgraph.Schema {
graph := &sqlgraph.Schema{Nodes: make([]*sqlgraph.Node, 12)}
graph := &sqlgraph.Schema{Nodes: make([]*sqlgraph.Node, 13)}
graph.Nodes[0] = &sqlgraph.Node{
NodeSpec: sqlgraph.NodeSpec{
Table: courseentity.Table,
@@ -37,21 +38,23 @@ var schemaGraph = func() *sqlgraph.Schema {
},
Type: "CourseEntity",
Fields: map[string]*sqlgraph.FieldSpec{
courseentity.FieldCreateTime: {Type: field.TypeString, Column: courseentity.FieldCreateTime},
courseentity.FieldUpdateTime: {Type: field.TypeString, Column: courseentity.FieldUpdateTime},
courseentity.FieldUserID: {Type: field.TypeInt64, Column: courseentity.FieldUserID},
courseentity.FieldUsername: {Type: field.TypeString, Column: courseentity.FieldUsername},
courseentity.FieldPassword: {Type: field.TypeString, Column: courseentity.FieldPassword},
courseentity.FieldType: {Type: field.TypeEnum, Column: courseentity.FieldType},
courseentity.FieldCourseName: {Type: field.TypeString, Column: courseentity.FieldCourseName},
courseentity.FieldCourseID: {Type: field.TypeString, Column: courseentity.FieldCourseID},
courseentity.FieldNeed: {Type: field.TypeEnum, Column: courseentity.FieldNeed},
courseentity.FieldStatus: {Type: field.TypeEnum, Column: courseentity.FieldStatus},
courseentity.FieldTaskCount: {Type: field.TypeInt, Column: courseentity.FieldTaskCount},
courseentity.FieldSuccessCount: {Type: field.TypeInt, Column: courseentity.FieldSuccessCount},
courseentity.FieldExamState: {Type: field.TypeEnum, Column: courseentity.FieldExamState},
courseentity.FieldViolence: {Type: field.TypeEnum, Column: courseentity.FieldViolence},
courseentity.FieldDesc: {Type: field.TypeString, Column: courseentity.FieldDesc},
courseentity.FieldCreateTime: {Type: field.TypeString, Column: courseentity.FieldCreateTime},
courseentity.FieldUpdateTime: {Type: field.TypeString, Column: courseentity.FieldUpdateTime},
courseentity.FieldUserID: {Type: field.TypeInt64, Column: courseentity.FieldUserID},
courseentity.FieldUsername: {Type: field.TypeString, Column: courseentity.FieldUsername},
courseentity.FieldPassword: {Type: field.TypeString, Column: courseentity.FieldPassword},
courseentity.FieldType: {Type: field.TypeEnum, Column: courseentity.FieldType},
courseentity.FieldCourseName: {Type: field.TypeString, Column: courseentity.FieldCourseName},
courseentity.FieldCourseID: {Type: field.TypeString, Column: courseentity.FieldCourseID},
courseentity.FieldNeed: {Type: field.TypeEnum, Column: courseentity.FieldNeed},
courseentity.FieldStatus: {Type: field.TypeEnum, Column: courseentity.FieldStatus},
courseentity.FieldTaskCount: {Type: field.TypeInt, Column: courseentity.FieldTaskCount},
courseentity.FieldSuccessCount: {Type: field.TypeInt, Column: courseentity.FieldSuccessCount},
courseentity.FieldExamState: {Type: field.TypeEnum, Column: courseentity.FieldExamState},
courseentity.FieldViolence: {Type: field.TypeEnum, Column: courseentity.FieldViolence},
courseentity.FieldNodes: {Type: field.TypeString, Column: courseentity.FieldNodes},
courseentity.FieldCompletedNodes: {Type: field.TypeString, Column: courseentity.FieldCompletedNodes},
courseentity.FieldDesc: {Type: field.TypeString, Column: courseentity.FieldDesc},
},
}
graph.Nodes[1] = &sqlgraph.Node{
@@ -75,6 +78,28 @@ var schemaGraph = func() *sqlgraph.Schema {
},
}
graph.Nodes[2] = &sqlgraph.Node{
NodeSpec: sqlgraph.NodeSpec{
Table: cpleave.Table,
Columns: cpleave.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt64,
Column: cpleave.FieldID,
},
},
Type: "CpLeave",
Fields: map[string]*sqlgraph.FieldSpec{
cpleave.FieldCreateTime: {Type: field.TypeString, Column: cpleave.FieldCreateTime},
cpleave.FieldUpdateTime: {Type: field.TypeString, Column: cpleave.FieldUpdateTime},
cpleave.FieldCpUserID: {Type: field.TypeInt64, Column: cpleave.FieldCpUserID},
cpleave.FieldUserID: {Type: field.TypeInt64, Column: cpleave.FieldUserID},
cpleave.FieldLeaveID: {Type: field.TypeString, Column: cpleave.FieldLeaveID},
cpleave.FieldTitle: {Type: field.TypeString, Column: cpleave.FieldTitle},
cpleave.FieldStatus: {Type: field.TypeEnum, Column: cpleave.FieldStatus},
cpleave.FieldType: {Type: field.TypeEnum, Column: cpleave.FieldType},
cpleave.FieldDesc: {Type: field.TypeString, Column: cpleave.FieldDesc},
},
}
graph.Nodes[3] = &sqlgraph.Node{
NodeSpec: sqlgraph.NodeSpec{
Table: cpschool.Table,
Columns: cpschool.Columns,
@@ -92,7 +117,7 @@ var schemaGraph = func() *sqlgraph.Schema {
cpschool.FieldIconImg: {Type: field.TypeString, Column: cpschool.FieldIconImg},
},
}
graph.Nodes[3] = &sqlgraph.Node{
graph.Nodes[4] = &sqlgraph.Node{
NodeSpec: sqlgraph.NodeSpec{
Table: cptask.Table,
Columns: cptask.Columns,
@@ -121,7 +146,7 @@ var schemaGraph = func() *sqlgraph.Schema {
cptask.FieldNextExecuteTime: {Type: field.TypeInt64, Column: cptask.FieldNextExecuteTime},
},
}
graph.Nodes[4] = &sqlgraph.Node{
graph.Nodes[5] = &sqlgraph.Node{
NodeSpec: sqlgraph.NodeSpec{
Table: cptasklog.Table,
Columns: cptasklog.Columns,
@@ -142,7 +167,7 @@ var schemaGraph = func() *sqlgraph.Schema {
cptasklog.FieldRealName: {Type: field.TypeString, Column: cptasklog.FieldRealName},
},
}
graph.Nodes[5] = &sqlgraph.Node{
graph.Nodes[6] = &sqlgraph.Node{
NodeSpec: sqlgraph.NodeSpec{
Table: cpuser.Table,
Columns: cpuser.Columns,
@@ -165,7 +190,7 @@ var schemaGraph = func() *sqlgraph.Schema {
cpuser.FieldMobileType: {Type: field.TypeEnum, Column: cpuser.FieldMobileType},
},
}
graph.Nodes[6] = &sqlgraph.Node{
graph.Nodes[7] = &sqlgraph.Node{
NodeSpec: sqlgraph.NodeSpec{
Table: sysagent.Table,
Columns: sysagent.Columns,
@@ -182,7 +207,7 @@ var schemaGraph = func() *sqlgraph.Schema {
sysagent.FieldRate: {Type: field.TypeString, Column: sysagent.FieldRate},
},
}
graph.Nodes[7] = &sqlgraph.Node{
graph.Nodes[8] = &sqlgraph.Node{
NodeSpec: sqlgraph.NodeSpec{
Table: syscard.Table,
Columns: syscard.Columns,
@@ -204,7 +229,7 @@ var schemaGraph = func() *sqlgraph.Schema {
syscard.FieldCashValue: {Type: field.TypeString, Column: syscard.FieldCashValue},
},
}
graph.Nodes[8] = &sqlgraph.Node{
graph.Nodes[9] = &sqlgraph.Node{
NodeSpec: sqlgraph.NodeSpec{
Table: sysmenu.Table,
Columns: sysmenu.Columns,
@@ -230,7 +255,7 @@ var schemaGraph = func() *sqlgraph.Schema {
sysmenu.FieldOrder: {Type: field.TypeUint, Column: sysmenu.FieldOrder},
},
}
graph.Nodes[9] = &sqlgraph.Node{
graph.Nodes[10] = &sqlgraph.Node{
NodeSpec: sqlgraph.NodeSpec{
Table: sysrole.Table,
Columns: sysrole.Columns,
@@ -249,7 +274,7 @@ var schemaGraph = func() *sqlgraph.Schema {
sysrole.FieldOrder: {Type: field.TypeUint, Column: sysrole.FieldOrder},
},
}
graph.Nodes[10] = &sqlgraph.Node{
graph.Nodes[11] = &sqlgraph.Node{
NodeSpec: sqlgraph.NodeSpec{
Table: sysuser.Table,
Columns: sysuser.Columns,
@@ -272,7 +297,7 @@ var schemaGraph = func() *sqlgraph.Schema {
sysuser.FieldInviteCashback: {Type: field.TypeString, Column: sysuser.FieldInviteCashback},
},
}
graph.Nodes[11] = &sqlgraph.Node{
graph.Nodes[12] = &sqlgraph.Node{
NodeSpec: sqlgraph.NodeSpec{
Table: sysuserlog.Table,
Columns: sysuserlog.Columns,
@@ -308,6 +333,30 @@ var schemaGraph = func() *sqlgraph.Schema {
"CpImage",
"SysUser",
)
graph.MustAddE(
"cp_user",
&sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cpleave.CpUserTable,
Columns: []string{cpleave.CpUserColumn},
Bidi: false,
},
"CpLeave",
"CpUser",
)
graph.MustAddE(
"sys_user",
&sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: cpleave.SysUserTable,
Columns: []string{cpleave.SysUserColumn},
Bidi: false,
},
"CpLeave",
"SysUser",
)
graph.MustAddE(
"cpusers",
&sqlgraph.EdgeSpec{
@@ -404,6 +453,18 @@ var schemaGraph = func() *sqlgraph.Schema {
"CpUser",
"CpTask",
)
graph.MustAddE(
"cp_leave",
&sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: cpuser.CpLeaveTable,
Columns: []string{cpuser.CpLeaveColumn},
Bidi: false,
},
"CpUser",
"CpLeave",
)
graph.MustAddE(
"sysuser",
&sqlgraph.EdgeSpec{
@@ -632,6 +693,18 @@ var schemaGraph = func() *sqlgraph.Schema {
"SysUser",
"CpTask",
)
graph.MustAddE(
"cp_leave",
&sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: sysuser.CpLeaveTable,
Columns: []string{sysuser.CpLeaveColumn},
Bidi: false,
},
"SysUser",
"CpLeave",
)
graph.MustAddE(
"course_entity",
&sqlgraph.EdgeSpec{
@@ -811,6 +884,16 @@ func (f *CourseEntityFilter) WhereViolence(p entql.StringP) {
f.Where(p.Field(courseentity.FieldViolence))
}
// WhereNodes applies the entql string predicate on the nodes field.
func (f *CourseEntityFilter) WhereNodes(p entql.StringP) {
f.Where(p.Field(courseentity.FieldNodes))
}
// WhereCompletedNodes applies the entql string predicate on the completed_nodes field.
func (f *CourseEntityFilter) WhereCompletedNodes(p entql.StringP) {
f.Where(p.Field(courseentity.FieldCompletedNodes))
}
// WhereDesc applies the entql string predicate on the desc field.
func (f *CourseEntityFilter) WhereDesc(p entql.StringP) {
f.Where(p.Field(courseentity.FieldDesc))
@@ -919,6 +1002,119 @@ func (f *CpImageFilter) WhereHasUserWith(preds ...predicate.SysUser) {
})))
}
// addPredicate implements the predicateAdder interface.
func (_q *CpLeaveQuery) addPredicate(pred func(s *sql.Selector)) {
_q.predicates = append(_q.predicates, pred)
}
// Filter returns a Filter implementation to apply filters on the CpLeaveQuery builder.
func (_q *CpLeaveQuery) Filter() *CpLeaveFilter {
return &CpLeaveFilter{config: _q.config, predicateAdder: _q}
}
// addPredicate implements the predicateAdder interface.
func (m *CpLeaveMutation) addPredicate(pred func(s *sql.Selector)) {
m.predicates = append(m.predicates, pred)
}
// Filter returns an entql.Where implementation to apply filters on the CpLeaveMutation builder.
func (m *CpLeaveMutation) Filter() *CpLeaveFilter {
return &CpLeaveFilter{config: m.config, predicateAdder: m}
}
// CpLeaveFilter provides a generic filtering capability at runtime for CpLeaveQuery.
type CpLeaveFilter struct {
predicateAdder
config
}
// Where applies the entql predicate on the query filter.
func (f *CpLeaveFilter) Where(p entql.P) {
f.addPredicate(func(s *sql.Selector) {
if err := schemaGraph.EvalP(schemaGraph.Nodes[2].Type, p, s); err != nil {
s.AddError(err)
}
})
}
// WhereID applies the entql int64 predicate on the id field.
func (f *CpLeaveFilter) WhereID(p entql.Int64P) {
f.Where(p.Field(cpleave.FieldID))
}
// WhereCreateTime applies the entql string predicate on the create_time field.
func (f *CpLeaveFilter) WhereCreateTime(p entql.StringP) {
f.Where(p.Field(cpleave.FieldCreateTime))
}
// WhereUpdateTime applies the entql string predicate on the update_time field.
func (f *CpLeaveFilter) WhereUpdateTime(p entql.StringP) {
f.Where(p.Field(cpleave.FieldUpdateTime))
}
// WhereCpUserID applies the entql int64 predicate on the cp_user_id field.
func (f *CpLeaveFilter) WhereCpUserID(p entql.Int64P) {
f.Where(p.Field(cpleave.FieldCpUserID))
}
// WhereUserID applies the entql int64 predicate on the user_id field.
func (f *CpLeaveFilter) WhereUserID(p entql.Int64P) {
f.Where(p.Field(cpleave.FieldUserID))
}
// WhereLeaveID applies the entql string predicate on the leave_id field.
func (f *CpLeaveFilter) WhereLeaveID(p entql.StringP) {
f.Where(p.Field(cpleave.FieldLeaveID))
}
// WhereTitle applies the entql string predicate on the title field.
func (f *CpLeaveFilter) WhereTitle(p entql.StringP) {
f.Where(p.Field(cpleave.FieldTitle))
}
// WhereStatus applies the entql string predicate on the status field.
func (f *CpLeaveFilter) WhereStatus(p entql.StringP) {
f.Where(p.Field(cpleave.FieldStatus))
}
// WhereType applies the entql string predicate on the type field.
func (f *CpLeaveFilter) WhereType(p entql.StringP) {
f.Where(p.Field(cpleave.FieldType))
}
// WhereDesc applies the entql string predicate on the desc field.
func (f *CpLeaveFilter) WhereDesc(p entql.StringP) {
f.Where(p.Field(cpleave.FieldDesc))
}
// WhereHasCpUser applies a predicate to check if query has an edge cp_user.
func (f *CpLeaveFilter) WhereHasCpUser() {
f.Where(entql.HasEdge("cp_user"))
}
// WhereHasCpUserWith applies a predicate to check if query has an edge cp_user with a given conditions (other predicates).
func (f *CpLeaveFilter) WhereHasCpUserWith(preds ...predicate.CpUser) {
f.Where(entql.HasEdgeWith("cp_user", sqlgraph.WrapFunc(func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})))
}
// WhereHasSysUser applies a predicate to check if query has an edge sys_user.
func (f *CpLeaveFilter) WhereHasSysUser() {
f.Where(entql.HasEdge("sys_user"))
}
// WhereHasSysUserWith applies a predicate to check if query has an edge sys_user with a given conditions (other predicates).
func (f *CpLeaveFilter) WhereHasSysUserWith(preds ...predicate.SysUser) {
f.Where(entql.HasEdgeWith("sys_user", sqlgraph.WrapFunc(func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})))
}
// addPredicate implements the predicateAdder interface.
func (_q *CpSchoolQuery) addPredicate(pred func(s *sql.Selector)) {
_q.predicates = append(_q.predicates, pred)
@@ -948,7 +1144,7 @@ type CpSchoolFilter struct {
// Where applies the entql predicate on the query filter.
func (f *CpSchoolFilter) Where(p entql.P) {
f.addPredicate(func(s *sql.Selector) {
if err := schemaGraph.EvalP(schemaGraph.Nodes[2].Type, p, s); err != nil {
if err := schemaGraph.EvalP(schemaGraph.Nodes[3].Type, p, s); err != nil {
s.AddError(err)
}
})
@@ -1027,7 +1223,7 @@ type CpTaskFilter struct {
// Where applies the entql predicate on the query filter.
func (f *CpTaskFilter) Where(p entql.P) {
f.addPredicate(func(s *sql.Selector) {
if err := schemaGraph.EvalP(schemaGraph.Nodes[3].Type, p, s); err != nil {
if err := schemaGraph.EvalP(schemaGraph.Nodes[4].Type, p, s); err != nil {
s.AddError(err)
}
})
@@ -1189,7 +1385,7 @@ type CpTaskLogFilter struct {
// Where applies the entql predicate on the query filter.
func (f *CpTaskLogFilter) Where(p entql.P) {
f.addPredicate(func(s *sql.Selector) {
if err := schemaGraph.EvalP(schemaGraph.Nodes[4].Type, p, s); err != nil {
if err := schemaGraph.EvalP(schemaGraph.Nodes[5].Type, p, s); err != nil {
s.AddError(err)
}
})
@@ -1311,7 +1507,7 @@ type CpUserFilter struct {
// Where applies the entql predicate on the query filter.
func (f *CpUserFilter) Where(p entql.P) {
f.addPredicate(func(s *sql.Selector) {
if err := schemaGraph.EvalP(schemaGraph.Nodes[5].Type, p, s); err != nil {
if err := schemaGraph.EvalP(schemaGraph.Nodes[6].Type, p, s); err != nil {
s.AddError(err)
}
})
@@ -1386,6 +1582,20 @@ func (f *CpUserFilter) WhereHasCptasksWith(preds ...predicate.CpTask) {
})))
}
// WhereHasCpLeave applies a predicate to check if query has an edge cp_leave.
func (f *CpUserFilter) WhereHasCpLeave() {
f.Where(entql.HasEdge("cp_leave"))
}
// WhereHasCpLeaveWith applies a predicate to check if query has an edge cp_leave with a given conditions (other predicates).
func (f *CpUserFilter) WhereHasCpLeaveWith(preds ...predicate.CpLeave) {
f.Where(entql.HasEdgeWith("cp_leave", sqlgraph.WrapFunc(func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})))
}
// WhereHasSysuser applies a predicate to check if query has an edge sysuser.
func (f *CpUserFilter) WhereHasSysuser() {
f.Where(entql.HasEdge("sysuser"))
@@ -1457,7 +1667,7 @@ type SysAgentFilter struct {
// Where applies the entql predicate on the query filter.
func (f *SysAgentFilter) Where(p entql.P) {
f.addPredicate(func(s *sql.Selector) {
if err := schemaGraph.EvalP(schemaGraph.Nodes[6].Type, p, s); err != nil {
if err := schemaGraph.EvalP(schemaGraph.Nodes[7].Type, p, s); err != nil {
s.AddError(err)
}
})
@@ -1531,7 +1741,7 @@ type SysCardFilter struct {
// Where applies the entql predicate on the query filter.
func (f *SysCardFilter) Where(p entql.P) {
f.addPredicate(func(s *sql.Selector) {
if err := schemaGraph.EvalP(schemaGraph.Nodes[7].Type, p, s); err != nil {
if err := schemaGraph.EvalP(schemaGraph.Nodes[8].Type, p, s); err != nil {
s.AddError(err)
}
})
@@ -1658,7 +1868,7 @@ type SysMenuFilter struct {
// Where applies the entql predicate on the query filter.
func (f *SysMenuFilter) Where(p entql.P) {
f.addPredicate(func(s *sql.Selector) {
if err := schemaGraph.EvalP(schemaGraph.Nodes[8].Type, p, s); err != nil {
if err := schemaGraph.EvalP(schemaGraph.Nodes[9].Type, p, s); err != nil {
s.AddError(err)
}
})
@@ -1805,7 +2015,7 @@ type SysRoleFilter struct {
// Where applies the entql predicate on the query filter.
func (f *SysRoleFilter) Where(p entql.P) {
f.addPredicate(func(s *sql.Selector) {
if err := schemaGraph.EvalP(schemaGraph.Nodes[9].Type, p, s); err != nil {
if err := schemaGraph.EvalP(schemaGraph.Nodes[10].Type, p, s); err != nil {
s.AddError(err)
}
})
@@ -1903,7 +2113,7 @@ type SysUserFilter struct {
// Where applies the entql predicate on the query filter.
func (f *SysUserFilter) Where(p entql.P) {
f.addPredicate(func(s *sql.Selector) {
if err := schemaGraph.EvalP(schemaGraph.Nodes[10].Type, p, s); err != nil {
if err := schemaGraph.EvalP(schemaGraph.Nodes[11].Type, p, s); err != nil {
s.AddError(err)
}
})
@@ -2062,6 +2272,20 @@ func (f *SysUserFilter) WhereHasCpTaskWith(preds ...predicate.CpTask) {
})))
}
// WhereHasCpLeave applies a predicate to check if query has an edge cp_leave.
func (f *SysUserFilter) WhereHasCpLeave() {
f.Where(entql.HasEdge("cp_leave"))
}
// WhereHasCpLeaveWith applies a predicate to check if query has an edge cp_leave with a given conditions (other predicates).
func (f *SysUserFilter) WhereHasCpLeaveWith(preds ...predicate.CpLeave) {
f.Where(entql.HasEdgeWith("cp_leave", sqlgraph.WrapFunc(func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})))
}
// WhereHasCourseEntity applies a predicate to check if query has an edge course_entity.
func (f *SysUserFilter) WhereHasCourseEntity() {
f.Where(entql.HasEdge("course_entity"))
@@ -2161,7 +2385,7 @@ type SysUserLogFilter struct {
// Where applies the entql predicate on the query filter.
func (f *SysUserLogFilter) Where(p entql.P) {
f.addPredicate(func(s *sql.Selector) {
if err := schemaGraph.EvalP(schemaGraph.Nodes[11].Type, p, s); err != nil {
if err := schemaGraph.EvalP(schemaGraph.Nodes[12].Type, p, s); err != nil {
s.AddError(err)
}
})
+12
View File
@@ -32,6 +32,18 @@ func (f CpImageFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, err
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CpImageMutation", m)
}
// The CpLeaveFunc type is an adapter to allow the use of ordinary
// function as CpLeave mutator.
type CpLeaveFunc func(context.Context, *ent.CpLeaveMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f CpLeaveFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.CpLeaveMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CpLeaveMutation", m)
}
// The CpSchoolFunc type is an adapter to allow the use of ordinary
// function as CpSchool mutator.
type CpSchoolFunc func(context.Context, *ent.CpSchoolMutation) (ent.Value, error)
+30
View File
@@ -9,6 +9,7 @@ import (
"likedream-goframe/internal/ent"
"likedream-goframe/internal/ent/courseentity"
"likedream-goframe/internal/ent/cpimage"
"likedream-goframe/internal/ent/cpleave"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
@@ -134,6 +135,33 @@ func (f TraverseCpImage) Traverse(ctx context.Context, q ent.Query) error {
return fmt.Errorf("unexpected query type %T. expect *ent.CpImageQuery", q)
}
// The CpLeaveFunc type is an adapter to allow the use of ordinary function as a Querier.
type CpLeaveFunc func(context.Context, *ent.CpLeaveQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f CpLeaveFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.CpLeaveQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.CpLeaveQuery", q)
}
// The TraverseCpLeave type is an adapter to allow the use of ordinary function as Traverser.
type TraverseCpLeave func(context.Context, *ent.CpLeaveQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseCpLeave) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseCpLeave) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.CpLeaveQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.CpLeaveQuery", q)
}
// The CpSchoolFunc type is an adapter to allow the use of ordinary function as a Querier.
type CpSchoolFunc func(context.Context, *ent.CpSchoolQuery) (ent.Value, error)
@@ -411,6 +439,8 @@ func NewQuery(q ent.Query) (Query, error) {
return &query[*ent.CourseEntityQuery, predicate.CourseEntity, courseentity.OrderOption]{typ: ent.TypeCourseEntity, tq: q}, nil
case *ent.CpImageQuery:
return &query[*ent.CpImageQuery, predicate.CpImage, cpimage.OrderOption]{typ: ent.TypeCpImage, tq: q}, nil
case *ent.CpLeaveQuery:
return &query[*ent.CpLeaveQuery, predicate.CpLeave, cpleave.OrderOption]{typ: ent.TypeCpLeave, tq: q}, nil
case *ent.CpSchoolQuery:
return &query[*ent.CpSchoolQuery, predicate.CpSchool, cpschool.OrderOption]{typ: ent.TypeCpSchool, tq: q}, nil
case *ent.CpTaskQuery:
File diff suppressed because one or more lines are too long
+1
View File
@@ -9,6 +9,7 @@ import "context"
type SchemaConfig struct {
CourseEntity string // CourseEntity table.
CpImage string // CpImage table.
CpLeave string // CpLeave table.
CpSchool string // CpSchool table.
CpTask string // CpTask table.
CpTaskLog string // CpTaskLog table.
+39 -1
View File
@@ -25,6 +25,8 @@ var (
{Name: "success_count", Type: field.TypeInt, Default: 0},
{Name: "exam_state", Type: field.TypeEnum, Enums: []string{"not_start", "waiting", "doing", "done", "fail"}, Default: "not_start"},
{Name: "violence", Type: field.TypeEnum, Enums: []string{"no", "yes"}, Default: "no"},
{Name: "nodes", Type: field.TypeString, Nullable: true, Size: 2147483647},
{Name: "completed_nodes", Type: field.TypeString, Nullable: true, Size: 2147483647},
{Name: "desc", Type: field.TypeString, Nullable: true},
{Name: "user_id", Type: field.TypeInt64},
}
@@ -36,7 +38,7 @@ var (
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "course_entity_sys_user_course_entity",
Columns: []*schema.Column{CourseEntityColumns[15]},
Columns: []*schema.Column{CourseEntityColumns[17]},
RefColumns: []*schema.Column{SysUserColumns[0]},
OnDelete: schema.Cascade,
},
@@ -67,6 +69,39 @@ var (
},
},
}
// CpLeavesColumns holds the columns for the "cp_leaves" table.
CpLeavesColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "create_time", Type: field.TypeString, SchemaType: map[string]string{"mysql": "datetime", "postgres": "timestamp", "sqlite3": "datetime"}},
{Name: "update_time", Type: field.TypeString, SchemaType: map[string]string{"mysql": "datetime", "postgres": "timestamp", "sqlite3": "datetime"}},
{Name: "leave_id", Type: field.TypeString},
{Name: "title", Type: field.TypeString},
{Name: "status", Type: field.TypeEnum, Enums: []string{"done", "fail"}},
{Name: "type", Type: field.TypeEnum, Enums: []string{"report"}},
{Name: "desc", Type: field.TypeString, Nullable: true, Size: 2147483647},
{Name: "cp_user_id", Type: field.TypeInt64},
{Name: "user_id", Type: field.TypeInt64},
}
// CpLeavesTable holds the schema information for the "cp_leaves" table.
CpLeavesTable = &schema.Table{
Name: "cp_leaves",
Columns: CpLeavesColumns,
PrimaryKey: []*schema.Column{CpLeavesColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "cp_leaves_cp_users_cp_leave",
Columns: []*schema.Column{CpLeavesColumns[8]},
RefColumns: []*schema.Column{CpUsersColumns[0]},
OnDelete: schema.Cascade,
},
{
Symbol: "cp_leaves_sys_user_cp_leave",
Columns: []*schema.Column{CpLeavesColumns[9]},
RefColumns: []*schema.Column{SysUserColumns[0]},
OnDelete: schema.Cascade,
},
},
}
// CpSchoolsColumns holds the columns for the "cp_schools" table.
CpSchoolsColumns = []*schema.Column{
{Name: "id", Type: field.TypeString, Unique: true},
@@ -397,6 +432,7 @@ var (
Tables = []*schema.Table{
CourseEntityTable,
CpImageTable,
CpLeavesTable,
CpSchoolsTable,
CpTasksTable,
CpTaskLogsTable,
@@ -421,6 +457,8 @@ func init() {
CpImageTable.Annotation = &entsql.Annotation{
Table: "cp_image",
}
CpLeavesTable.ForeignKeys[0].RefTable = CpUsersTable
CpLeavesTable.ForeignKeys[1].RefTable = SysUserTable
CpTasksTable.ForeignKeys[0].RefTable = CpUsersTable
CpTasksTable.ForeignKeys[1].RefTable = SysUserTable
CpTaskLogsTable.ForeignKeys[0].RefTable = CpTasksTable
+1217 -7
View File
File diff suppressed because it is too large Load Diff
+3
View File
@@ -12,6 +12,9 @@ type CourseEntity func(*sql.Selector)
// CpImage is the predicate function for cpimage builders.
type CpImage func(*sql.Selector)
// CpLeave is the predicate function for cpleave builders.
type CpLeave func(*sql.Selector)
// CpSchool is the predicate function for cpschool builders.
type CpSchool func(*sql.Selector)
+28
View File
@@ -159,6 +159,30 @@ func (f CpImageMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutatio
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CpImageMutation", m)
}
// The CpLeaveQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type CpLeaveQueryRuleFunc func(context.Context, *ent.CpLeaveQuery) error
// EvalQuery return f(ctx, q).
func (f CpLeaveQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.CpLeaveQuery); ok {
return f(ctx, q)
}
return Denyf("ent/privacy: unexpected query type %T, expect *ent.CpLeaveQuery", q)
}
// The CpLeaveMutationRuleFunc type is an adapter to allow the use of ordinary
// functions as a mutation rule.
type CpLeaveMutationRuleFunc func(context.Context, *ent.CpLeaveMutation) error
// EvalMutation calls f(ctx, m).
func (f CpLeaveMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error {
if m, ok := m.(*ent.CpLeaveMutation); ok {
return f(ctx, m)
}
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CpLeaveMutation", m)
}
// The CpSchoolQueryRuleFunc type is an adapter to allow the use of ordinary
// functions as a query rule.
type CpSchoolQueryRuleFunc func(context.Context, *ent.CpSchoolQuery) error
@@ -438,6 +462,8 @@ func queryFilter(q ent.Query) (Filter, error) {
return q.Filter(), nil
case *ent.CpImageQuery:
return q.Filter(), nil
case *ent.CpLeaveQuery:
return q.Filter(), nil
case *ent.CpSchoolQuery:
return q.Filter(), nil
case *ent.CpTaskQuery:
@@ -469,6 +495,8 @@ func mutationFilter(m ent.Mutation) (Filter, error) {
return m.Filter(), nil
case *ent.CpImageMutation:
return m.Filter(), nil
case *ent.CpLeaveMutation:
return m.Filter(), nil
case *ent.CpSchoolMutation:
return m.Filter(), nil
case *ent.CpTaskMutation:
+24
View File
@@ -5,6 +5,7 @@ package runtime
import (
"likedream-goframe/internal/ent/courseentity"
"likedream-goframe/internal/ent/cpimage"
"likedream-goframe/internal/ent/cpleave"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
@@ -83,6 +84,29 @@ func init() {
cpimageDescContentLength := cpimageFields[4].Descriptor()
// cpimage.ContentLengthValidator is a validator for the "content_length" field. It is called by the builders before save.
cpimage.ContentLengthValidator = cpimageDescContentLength.Validators[0].(func(int64) error)
cpleaveMixin := schema.CpLeave{}.Mixin()
cpleaveMixinHooks0 := cpleaveMixin[0].Hooks()
cpleave.Hooks[0] = cpleaveMixinHooks0[0]
cpleaveMixinFields0 := cpleaveMixin[0].Fields()
_ = cpleaveMixinFields0
cpleaveFields := schema.CpLeave{}.Fields()
_ = cpleaveFields
// cpleaveDescCreateTime is the schema descriptor for create_time field.
cpleaveDescCreateTime := cpleaveMixinFields0[0].Descriptor()
// cpleave.DefaultCreateTime holds the default value on creation for the create_time field.
cpleave.DefaultCreateTime = cpleaveDescCreateTime.Default.(func() *ent2.CustomTime)
// cpleaveDescUpdateTime is the schema descriptor for update_time field.
cpleaveDescUpdateTime := cpleaveMixinFields0[1].Descriptor()
// cpleave.DefaultUpdateTime holds the default value on creation for the update_time field.
cpleave.DefaultUpdateTime = cpleaveDescUpdateTime.Default.(func() *ent2.CustomTime)
// cpleaveDescLeaveID is the schema descriptor for leave_id field.
cpleaveDescLeaveID := cpleaveFields[2].Descriptor()
// cpleave.LeaveIDValidator is a validator for the "leave_id" field. It is called by the builders before save.
cpleave.LeaveIDValidator = cpleaveDescLeaveID.Validators[0].(func(string) error)
// cpleaveDescTitle is the schema descriptor for title field.
cpleaveDescTitle := cpleaveFields[3].Descriptor()
// cpleave.TitleValidator is a validator for the "title" field. It is called by the builders before save.
cpleave.TitleValidator = cpleaveDescTitle.Validators[0].(func(string) error)
cpschoolMixin := schema.CpSchool{}.Mixin()
cpschoolMixinHooks0 := cpschoolMixin[0].Hooks()
cpschool.Hooks[0] = cpschoolMixinHooks0[0]
+2
View File
@@ -29,6 +29,8 @@ func (CourseEntity) Fields() []ent.Field {
field.Int("success_count").Default(0), // 成功数量
field.Enum("exam_state").Values("not_start", "waiting", "doing", "done", "fail").Default("not_start"), // 考试状态
field.Enum("violence").Values("no", "yes").Default("no"), // 是否暴力刷课
field.Text("nodes").Optional(), // 所有节点信息(JSON格式)
field.Text("completed_nodes").Optional(), // 已完成的节点ID列表(JSON格式)
field.String("desc").Optional(),
}
}
+41
View File
@@ -0,0 +1,41 @@
package schema
import (
"likedream-goframe/internal/ent/schema/mix"
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// CpLeave holds the schema definition for the CpLeave entity.
type CpLeave struct {
ent.Schema
}
// Fields of the CpLeave.
func (CpLeave) Fields() []ent.Field {
return []ent.Field{
field.Int64("cp_user_id"),
field.Int64("user_id"),
field.String("leave_id").NotEmpty(),
field.String("title").NotEmpty(),
field.Enum("status").Values("done", "fail"),
field.Enum("type").Values("report"),
field.Text("desc").Optional(),
}
}
// Edges of the CpTask.
func (CpLeave) Edges() []ent.Edge {
return []ent.Edge{
edge.From("cp_user", CpUser.Type).Ref("cp_leave").Field("cp_user_id").Unique().Required(),
edge.From("sys_user", SysUser.Type).Ref("cp_leave").Field("user_id").Unique().Required(),
}
}
func (CpLeave) Mixin() []ent.Mixin {
return []ent.Mixin{
mix.MixinTime{},
}
}
+1
View File
@@ -32,6 +32,7 @@ func (CpUser) Fields() []ent.Field {
func (CpUser) Edges() []ent.Edge {
return []ent.Edge{
edge.To("cptasks", CpTask.Type).Annotations(entsql.OnDelete(entsql.Cascade)),
edge.To("cp_leave", CpLeave.Type).Annotations(entsql.OnDelete(entsql.Cascade)),
edge.From("sysuser", SysUser.Type).Unique().Required().Field("user_id").Ref("cpuser"),
edge.To("cp_task_logs", CpTaskLog.Type).Annotations(entsql.OnDelete(entsql.Cascade)), // 用户拥有的cp任务日志
edge.From("school", CpSchool.Type).
+1
View File
@@ -51,6 +51,7 @@ func (SysUser) Edges() []ent.Edge {
edge.To("images", CpImage.Type).Annotations(entsql.OnDelete(entsql.Cascade)), // 用户拥有的图片
edge.To("cpuser", CpUser.Type).Annotations(entsql.OnDelete(entsql.Cascade)), // 用户拥有的cp用户
edge.To("cp_task", CpTask.Type).Annotations(entsql.OnDelete(entsql.Cascade)), // 用户拥有的cp任务
edge.To("cp_leave", CpLeave.Type).Annotations(entsql.OnDelete(entsql.Cascade)), // 用户拥有的cp销假任务
edge.To("course_entity", CourseEntity.Type).Annotations(entsql.OnDelete(entsql.Cascade)), // 用户拥有的刷课课程
edge.To("cp_task_logs", CpTaskLog.Type).Annotations(entsql.OnDelete(entsql.Cascade)), // 用户拥有的cp任务日志
edge.To("created_cards", SysCard.Type), // 用户创建的卡
+47 -6
View File
@@ -62,6 +62,8 @@ type SysUserEdges struct {
Cpuser []*CpUser `json:"cpuser,omitempty"`
// CpTask holds the value of the cp_task edge.
CpTask []*CpTask `json:"cp_task,omitempty"`
// CpLeave holds the value of the cp_leave edge.
CpLeave []*CpLeave `json:"cp_leave,omitempty"`
// CourseEntity holds the value of the course_entity edge.
CourseEntity []*CourseEntity `json:"course_entity,omitempty"`
// CpTaskLogs holds the value of the cp_task_logs edge.
@@ -74,12 +76,13 @@ 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 [12]bool
loadedTypes [13]bool
namedChildren map[string][]*SysUser
namedRoles map[string][]*SysRole
namedImages map[string][]*CpImage
namedCpuser map[string][]*CpUser
namedCpTask map[string][]*CpTask
namedCpLeave map[string][]*CpLeave
namedCourseEntity map[string][]*CourseEntity
namedCpTaskLogs map[string][]*CpTaskLog
namedCreatedCards map[string][]*SysCard
@@ -154,10 +157,19 @@ func (e SysUserEdges) CpTaskOrErr() ([]*CpTask, error) {
return nil, &NotLoadedError{edge: "cp_task"}
}
// CpLeaveOrErr returns the CpLeave value or an error if the edge
// was not loaded in eager-loading.
func (e SysUserEdges) CpLeaveOrErr() ([]*CpLeave, error) {
if e.loadedTypes[7] {
return e.CpLeave, nil
}
return nil, &NotLoadedError{edge: "cp_leave"}
}
// CourseEntityOrErr returns the CourseEntity value or an error if the edge
// was not loaded in eager-loading.
func (e SysUserEdges) CourseEntityOrErr() ([]*CourseEntity, error) {
if e.loadedTypes[7] {
if e.loadedTypes[8] {
return e.CourseEntity, nil
}
return nil, &NotLoadedError{edge: "course_entity"}
@@ -166,7 +178,7 @@ func (e SysUserEdges) CourseEntityOrErr() ([]*CourseEntity, error) {
// 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[8] {
if e.loadedTypes[9] {
return e.CpTaskLogs, nil
}
return nil, &NotLoadedError{edge: "cp_task_logs"}
@@ -175,7 +187,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[9] {
if e.loadedTypes[10] {
return e.CreatedCards, nil
}
return nil, &NotLoadedError{edge: "created_cards"}
@@ -184,7 +196,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[10] {
if e.loadedTypes[11] {
return e.UsedCards, nil
}
return nil, &NotLoadedError{edge: "used_cards"}
@@ -193,7 +205,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[11] {
if e.loadedTypes[12] {
return e.CashbackCards, nil
}
return nil, &NotLoadedError{edge: "cashback_cards"}
@@ -352,6 +364,11 @@ func (_m *SysUser) QueryCpTask() *CpTaskQuery {
return NewSysUserClient(_m.config).QueryCpTask(_m)
}
// QueryCpLeave queries the "cp_leave" edge of the SysUser entity.
func (_m *SysUser) QueryCpLeave() *CpLeaveQuery {
return NewSysUserClient(_m.config).QueryCpLeave(_m)
}
// QueryCourseEntity queries the "course_entity" edge of the SysUser entity.
func (_m *SysUser) QueryCourseEntity() *CourseEntityQuery {
return NewSysUserClient(_m.config).QueryCourseEntity(_m)
@@ -552,6 +569,30 @@ func (_m *SysUser) appendNamedCpTask(name string, edges ...*CpTask) {
}
}
// NamedCpLeave returns the CpLeave named value or an error if the edge was not
// loaded in eager-loading with this name.
func (_m *SysUser) NamedCpLeave(name string) ([]*CpLeave, error) {
if _m.Edges.namedCpLeave == nil {
return nil, &NotLoadedError{edge: name}
}
nodes, ok := _m.Edges.namedCpLeave[name]
if !ok {
return nil, &NotLoadedError{edge: name}
}
return nodes, nil
}
func (_m *SysUser) appendNamedCpLeave(name string, edges ...*CpLeave) {
if _m.Edges.namedCpLeave == nil {
_m.Edges.namedCpLeave = make(map[string][]*CpLeave)
}
if len(edges) == 0 {
_m.Edges.namedCpLeave[name] = []*CpLeave{}
} else {
_m.Edges.namedCpLeave[name] = append(_m.Edges.namedCpLeave[name], edges...)
}
}
// NamedCourseEntity returns the CourseEntity named value or an error if the edge was not
// loaded in eager-loading with this name.
func (_m *SysUser) NamedCourseEntity(name string) ([]*CourseEntity, error) {
+30
View File
@@ -50,6 +50,8 @@ const (
EdgeCpuser = "cpuser"
// EdgeCpTask holds the string denoting the cp_task edge name in mutations.
EdgeCpTask = "cp_task"
// EdgeCpLeave holds the string denoting the cp_leave edge name in mutations.
EdgeCpLeave = "cp_leave"
// EdgeCourseEntity holds the string denoting the course_entity edge name in mutations.
EdgeCourseEntity = "course_entity"
// EdgeCpTaskLogs holds the string denoting the cp_task_logs edge name in mutations.
@@ -103,6 +105,13 @@ const (
CpTaskInverseTable = "cp_tasks"
// CpTaskColumn is the table column denoting the cp_task relation/edge.
CpTaskColumn = "user_id"
// CpLeaveTable is the table that holds the cp_leave relation/edge.
CpLeaveTable = "cp_leaves"
// CpLeaveInverseTable is the table name for the CpLeave entity.
// It exists in this package in order to avoid circular dependency with the "cpleave" package.
CpLeaveInverseTable = "cp_leaves"
// CpLeaveColumn is the table column denoting the cp_leave relation/edge.
CpLeaveColumn = "user_id"
// CourseEntityTable is the table that holds the course_entity relation/edge.
CourseEntityTable = "course_entity"
// CourseEntityInverseTable is the table name for the CourseEntity entity.
@@ -347,6 +356,20 @@ func ByCpTask(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
}
}
// ByCpLeaveCount orders the results by cp_leave count.
func ByCpLeaveCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newCpLeaveStep(), opts...)
}
}
// ByCpLeave orders the results by cp_leave terms.
func ByCpLeave(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newCpLeaveStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
// ByCourseEntityCount orders the results by course_entity count.
func ByCourseEntityCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
@@ -465,6 +488,13 @@ func newCpTaskStep() *sqlgraph.Step {
sqlgraph.Edge(sqlgraph.O2M, false, CpTaskTable, CpTaskColumn),
)
}
func newCpLeaveStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(CpLeaveInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, CpLeaveTable, CpLeaveColumn),
)
}
func newCourseEntityStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
+29
View File
@@ -880,6 +880,35 @@ func HasCpTaskWith(preds ...predicate.CpTask) predicate.SysUser {
})
}
// HasCpLeave applies the HasEdge predicate on the "cp_leave" edge.
func HasCpLeave() predicate.SysUser {
return predicate.SysUser(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, CpLeaveTable, CpLeaveColumn),
)
schemaConfig := internal.SchemaConfigFromContext(s.Context())
step.To.Schema = schemaConfig.CpLeave
step.Edge.Schema = schemaConfig.CpLeave
sqlgraph.HasNeighbors(s, step)
})
}
// HasCpLeaveWith applies the HasEdge predicate on the "cp_leave" edge with a given conditions (other predicates).
func HasCpLeaveWith(preds ...predicate.CpLeave) predicate.SysUser {
return predicate.SysUser(func(s *sql.Selector) {
step := newCpLeaveStep()
schemaConfig := internal.SchemaConfigFromContext(s.Context())
step.To.Schema = schemaConfig.CpLeave
step.Edge.Schema = schemaConfig.CpLeave
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasCourseEntity applies the HasEdge predicate on the "course_entity" edge.
func HasCourseEntity() predicate.SysUser {
return predicate.SysUser(func(s *sql.Selector) {
+33
View File
@@ -8,6 +8,7 @@ import (
"fmt"
"likedream-goframe/internal/ent/courseentity"
"likedream-goframe/internal/ent/cpimage"
"likedream-goframe/internal/ent/cpleave"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
"likedream-goframe/internal/ent/cpuser"
@@ -244,6 +245,21 @@ func (_c *SysUserCreate) AddCpTask(v ...*CpTask) *SysUserCreate {
return _c.AddCpTaskIDs(ids...)
}
// AddCpLeaveIDs adds the "cp_leave" edge to the CpLeave entity by IDs.
func (_c *SysUserCreate) AddCpLeaveIDs(ids ...int64) *SysUserCreate {
_c.mutation.AddCpLeaveIDs(ids...)
return _c
}
// AddCpLeave adds the "cp_leave" edges to the CpLeave entity.
func (_c *SysUserCreate) AddCpLeave(v ...*CpLeave) *SysUserCreate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddCpLeaveIDs(ids...)
}
// AddCourseEntityIDs adds the "course_entity" edge to the CourseEntity entity by IDs.
func (_c *SysUserCreate) AddCourseEntityIDs(ids ...int64) *SysUserCreate {
_c.mutation.AddCourseEntityIDs(ids...)
@@ -617,6 +633,23 @@ func (_c *SysUserCreate) createSpec() (*SysUser, *sqlgraph.CreateSpec) {
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.CpLeaveIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: sysuser.CpLeaveTable,
Columns: []string{sysuser.CpLeaveColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
},
}
edge.Schema = _c.schemaConfig.CpLeave
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.CourseEntityIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
+112 -3
View File
@@ -8,6 +8,7 @@ import (
"fmt"
"likedream-goframe/internal/ent/courseentity"
"likedream-goframe/internal/ent/cpimage"
"likedream-goframe/internal/ent/cpleave"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
"likedream-goframe/internal/ent/cpuser"
@@ -40,6 +41,7 @@ type SysUserQuery struct {
withImages *CpImageQuery
withCpuser *CpUserQuery
withCpTask *CpTaskQuery
withCpLeave *CpLeaveQuery
withCourseEntity *CourseEntityQuery
withCpTaskLogs *CpTaskLogQuery
withCreatedCards *SysCardQuery
@@ -52,6 +54,7 @@ type SysUserQuery struct {
withNamedImages map[string]*CpImageQuery
withNamedCpuser map[string]*CpUserQuery
withNamedCpTask map[string]*CpTaskQuery
withNamedCpLeave map[string]*CpLeaveQuery
withNamedCourseEntity map[string]*CourseEntityQuery
withNamedCpTaskLogs map[string]*CpTaskLogQuery
withNamedCreatedCards map[string]*SysCardQuery
@@ -268,6 +271,31 @@ func (_q *SysUserQuery) QueryCpTask() *CpTaskQuery {
return query
}
// QueryCpLeave chains the current query on the "cp_leave" edge.
func (_q *SysUserQuery) QueryCpLeave() *CpLeaveQuery {
query := (&CpLeaveClient{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(cpleave.Table, cpleave.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, sysuser.CpLeaveTable, sysuser.CpLeaveColumn),
)
schemaConfig := _q.schemaConfig
step.To.Schema = schemaConfig.CpLeave
step.Edge.Schema = schemaConfig.CpLeave
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryCourseEntity chains the current query on the "course_entity" edge.
func (_q *SysUserQuery) QueryCourseEntity() *CourseEntityQuery {
query := (&CourseEntityClient{config: _q.config}).Query()
@@ -592,6 +620,7 @@ func (_q *SysUserQuery) Clone() *SysUserQuery {
withImages: _q.withImages.Clone(),
withCpuser: _q.withCpuser.Clone(),
withCpTask: _q.withCpTask.Clone(),
withCpLeave: _q.withCpLeave.Clone(),
withCourseEntity: _q.withCourseEntity.Clone(),
withCpTaskLogs: _q.withCpTaskLogs.Clone(),
withCreatedCards: _q.withCreatedCards.Clone(),
@@ -681,6 +710,17 @@ func (_q *SysUserQuery) WithCpTask(opts ...func(*CpTaskQuery)) *SysUserQuery {
return _q
}
// WithCpLeave tells the query-builder to eager-load the nodes that are connected to
// the "cp_leave" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *SysUserQuery) WithCpLeave(opts ...func(*CpLeaveQuery)) *SysUserQuery {
query := (&CpLeaveClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withCpLeave = query
return _q
}
// WithCourseEntity tells the query-builder to eager-load the nodes that are connected to
// the "course_entity" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *SysUserQuery) WithCourseEntity(opts ...func(*CourseEntityQuery)) *SysUserQuery {
@@ -815,7 +855,7 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
nodes = []*SysUser{}
withFKs = _q.withFKs
_spec = _q.querySpec()
loadedTypes = [12]bool{
loadedTypes = [13]bool{
_q.withParent != nil,
_q.withChildren != nil,
_q.withRoles != nil,
@@ -823,6 +863,7 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
_q.withImages != nil,
_q.withCpuser != nil,
_q.withCpTask != nil,
_q.withCpLeave != nil,
_q.withCourseEntity != nil,
_q.withCpTaskLogs != nil,
_q.withCreatedCards != nil,
@@ -912,7 +953,7 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
func(n *SysUser) { n.Edges.Cpuser = []*CpUser{} },
func(n *SysUser, e *CpUser) {
n.Edges.Cpuser = append(n.Edges.Cpuser, e)
if !e.Edges.loadedTypes[1] {
if !e.Edges.loadedTypes[2] {
e.Edges.Sysuser = n
}
}); err != nil {
@@ -931,6 +972,18 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
return nil, err
}
}
if query := _q.withCpLeave; query != nil {
if err := _q.loadCpLeave(ctx, query, nodes,
func(n *SysUser) { n.Edges.CpLeave = []*CpLeave{} },
func(n *SysUser, e *CpLeave) {
n.Edges.CpLeave = append(n.Edges.CpLeave, e)
if !e.Edges.loadedTypes[1] {
e.Edges.SysUser = n
}
}); err != nil {
return nil, err
}
}
if query := _q.withCourseEntity; query != nil {
if err := _q.loadCourseEntity(ctx, query, nodes,
func(n *SysUser) { n.Edges.CourseEntity = []*CourseEntity{} },
@@ -1027,7 +1080,7 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
func(n *SysUser) { n.appendNamedCpuser(name) },
func(n *SysUser, e *CpUser) {
n.appendNamedCpuser(name, e)
if !e.Edges.loadedTypes[1] {
if !e.Edges.loadedTypes[2] {
e.Edges.Sysuser = n
}
}); err != nil {
@@ -1046,6 +1099,18 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
return nil, err
}
}
for name, query := range _q.withNamedCpLeave {
if err := _q.loadCpLeave(ctx, query, nodes,
func(n *SysUser) { n.appendNamedCpLeave(name) },
func(n *SysUser, e *CpLeave) {
n.appendNamedCpLeave(name, e)
if !e.Edges.loadedTypes[1] {
e.Edges.SysUser = n
}
}); err != nil {
return nil, err
}
}
for name, query := range _q.withNamedCourseEntity {
if err := _q.loadCourseEntity(ctx, query, nodes,
func(n *SysUser) { n.appendNamedCourseEntity(name) },
@@ -1352,6 +1417,36 @@ func (_q *SysUserQuery) loadCpTask(ctx context.Context, query *CpTaskQuery, node
}
return nil
}
func (_q *SysUserQuery) loadCpLeave(ctx context.Context, query *CpLeaveQuery, nodes []*SysUser, init func(*SysUser), assign func(*SysUser, *CpLeave)) 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(cpleave.FieldUserID)
}
query.Where(predicate.CpLeave(func(s *sql.Selector) {
s.Where(sql.InValues(s.C(sysuser.CpLeaveColumn), 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) loadCourseEntity(ctx context.Context, query *CourseEntityQuery, nodes []*SysUser, init func(*SysUser), assign func(*SysUser, *CourseEntity)) error {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[int64]*SysUser)
@@ -1697,6 +1792,20 @@ func (_q *SysUserQuery) WithNamedCpTask(name string, opts ...func(*CpTaskQuery))
return _q
}
// WithNamedCpLeave tells the query-builder to eager-load the nodes that are connected to the "cp_leave"
// edge with the given name. The optional arguments are used to configure the query builder of the edge.
func (_q *SysUserQuery) WithNamedCpLeave(name string, opts ...func(*CpLeaveQuery)) *SysUserQuery {
query := (&CpLeaveClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
if _q.withNamedCpLeave == nil {
_q.withNamedCpLeave = make(map[string]*CpLeaveQuery)
}
_q.withNamedCpLeave[name] = query
return _q
}
// WithNamedCourseEntity tells the query-builder to eager-load the nodes that are connected to the "course_entity"
// edge with the given name. The optional arguments are used to configure the query builder of the edge.
func (_q *SysUserQuery) WithNamedCourseEntity(name string, opts ...func(*CourseEntityQuery)) *SysUserQuery {
+169
View File
@@ -8,6 +8,7 @@ import (
"fmt"
"likedream-goframe/internal/ent/courseentity"
"likedream-goframe/internal/ent/cpimage"
"likedream-goframe/internal/ent/cpleave"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
"likedream-goframe/internal/ent/cpuser"
@@ -276,6 +277,21 @@ func (_u *SysUserUpdate) AddCpTask(v ...*CpTask) *SysUserUpdate {
return _u.AddCpTaskIDs(ids...)
}
// AddCpLeaveIDs adds the "cp_leave" edge to the CpLeave entity by IDs.
func (_u *SysUserUpdate) AddCpLeaveIDs(ids ...int64) *SysUserUpdate {
_u.mutation.AddCpLeaveIDs(ids...)
return _u
}
// AddCpLeave adds the "cp_leave" edges to the CpLeave entity.
func (_u *SysUserUpdate) AddCpLeave(v ...*CpLeave) *SysUserUpdate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddCpLeaveIDs(ids...)
}
// AddCourseEntityIDs adds the "course_entity" edge to the CourseEntity entity by IDs.
func (_u *SysUserUpdate) AddCourseEntityIDs(ids ...int64) *SysUserUpdate {
_u.mutation.AddCourseEntityIDs(ids...)
@@ -473,6 +489,27 @@ func (_u *SysUserUpdate) RemoveCpTask(v ...*CpTask) *SysUserUpdate {
return _u.RemoveCpTaskIDs(ids...)
}
// ClearCpLeave clears all "cp_leave" edges to the CpLeave entity.
func (_u *SysUserUpdate) ClearCpLeave() *SysUserUpdate {
_u.mutation.ClearCpLeave()
return _u
}
// RemoveCpLeaveIDs removes the "cp_leave" edge to CpLeave entities by IDs.
func (_u *SysUserUpdate) RemoveCpLeaveIDs(ids ...int64) *SysUserUpdate {
_u.mutation.RemoveCpLeaveIDs(ids...)
return _u
}
// RemoveCpLeave removes "cp_leave" edges to CpLeave entities.
func (_u *SysUserUpdate) RemoveCpLeave(v ...*CpLeave) *SysUserUpdate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveCpLeaveIDs(ids...)
}
// ClearCourseEntity clears all "course_entity" edges to the CourseEntity entity.
func (_u *SysUserUpdate) ClearCourseEntity() *SysUserUpdate {
_u.mutation.ClearCourseEntity()
@@ -965,6 +1002,54 @@ func (_u *SysUserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.CpLeaveCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: sysuser.CpLeaveTable,
Columns: []string{sysuser.CpLeaveColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedCpLeaveIDs(); len(nodes) > 0 && !_u.mutation.CpLeaveCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: sysuser.CpLeaveTable,
Columns: []string{sysuser.CpLeaveColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.CpLeaveIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: sysuser.CpLeaveTable,
Columns: []string{sysuser.CpLeaveColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.CourseEntityCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
@@ -1466,6 +1551,21 @@ func (_u *SysUserUpdateOne) AddCpTask(v ...*CpTask) *SysUserUpdateOne {
return _u.AddCpTaskIDs(ids...)
}
// AddCpLeaveIDs adds the "cp_leave" edge to the CpLeave entity by IDs.
func (_u *SysUserUpdateOne) AddCpLeaveIDs(ids ...int64) *SysUserUpdateOne {
_u.mutation.AddCpLeaveIDs(ids...)
return _u
}
// AddCpLeave adds the "cp_leave" edges to the CpLeave entity.
func (_u *SysUserUpdateOne) AddCpLeave(v ...*CpLeave) *SysUserUpdateOne {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddCpLeaveIDs(ids...)
}
// AddCourseEntityIDs adds the "course_entity" edge to the CourseEntity entity by IDs.
func (_u *SysUserUpdateOne) AddCourseEntityIDs(ids ...int64) *SysUserUpdateOne {
_u.mutation.AddCourseEntityIDs(ids...)
@@ -1663,6 +1763,27 @@ func (_u *SysUserUpdateOne) RemoveCpTask(v ...*CpTask) *SysUserUpdateOne {
return _u.RemoveCpTaskIDs(ids...)
}
// ClearCpLeave clears all "cp_leave" edges to the CpLeave entity.
func (_u *SysUserUpdateOne) ClearCpLeave() *SysUserUpdateOne {
_u.mutation.ClearCpLeave()
return _u
}
// RemoveCpLeaveIDs removes the "cp_leave" edge to CpLeave entities by IDs.
func (_u *SysUserUpdateOne) RemoveCpLeaveIDs(ids ...int64) *SysUserUpdateOne {
_u.mutation.RemoveCpLeaveIDs(ids...)
return _u
}
// RemoveCpLeave removes "cp_leave" edges to CpLeave entities.
func (_u *SysUserUpdateOne) RemoveCpLeave(v ...*CpLeave) *SysUserUpdateOne {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveCpLeaveIDs(ids...)
}
// ClearCourseEntity clears all "course_entity" edges to the CourseEntity entity.
func (_u *SysUserUpdateOne) ClearCourseEntity() *SysUserUpdateOne {
_u.mutation.ClearCourseEntity()
@@ -2185,6 +2306,54 @@ func (_u *SysUserUpdateOne) sqlSave(ctx context.Context) (_node *SysUser, err er
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.CpLeaveCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: sysuser.CpLeaveTable,
Columns: []string{sysuser.CpLeaveColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedCpLeaveIDs(); len(nodes) > 0 && !_u.mutation.CpLeaveCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: sysuser.CpLeaveTable,
Columns: []string{sysuser.CpLeaveColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.CpLeaveIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: sysuser.CpLeaveTable,
Columns: []string{sysuser.CpLeaveColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
},
}
edge.Schema = _u.schemaConfig.CpLeave
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.CourseEntityCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
+3
View File
@@ -18,6 +18,8 @@ type Tx struct {
CourseEntity *CourseEntityClient
// CpImage is the client for interacting with the CpImage builders.
CpImage *CpImageClient
// CpLeave is the client for interacting with the CpLeave builders.
CpLeave *CpLeaveClient
// CpSchool is the client for interacting with the CpSchool builders.
CpSchool *CpSchoolClient
// CpTask is the client for interacting with the CpTask builders.
@@ -171,6 +173,7 @@ func (tx *Tx) Client() *Client {
func (tx *Tx) init() {
tx.CourseEntity = NewCourseEntityClient(tx.config)
tx.CpImage = NewCpImageClient(tx.config)
tx.CpLeave = NewCpLeaveClient(tx.config)
tx.CpSchool = NewCpSchoolClient(tx.config)
tx.CpTask = NewCpTaskClient(tx.config)
tx.CpTaskLog = NewCpTaskLogClient(tx.config)
+4
View File
@@ -3,3 +3,7 @@ package schedule
type CpdailyTaskPayload struct {
CpTaskID int64 `json:"cpTaskId"`
}
type XuexitongTaskPayload struct {
CourseID int64 `json:"courseId"`
}
+9 -3
View File
@@ -29,9 +29,11 @@ func initServer(ctx context.Context) {
DelayedTaskCheckInterval: 2 * time.Second,
ErrorHandler: taskErrorHandler{},
Queues: map[string]int{
cst2.TaskQueueEmail: 2,
cst2.TaskQueueCpdaily: 10,
cst2.TaskQueueDefault: 1,
cst2.TaskQueueEmail: 2,
cst2.TaskQueueCpdaily: 10,
cst2.TaskQueueXuexitong: 5,
cst2.TaskQueueXuexitongVio: 8,
cst2.TaskQueueDefault: 1,
},
})
@@ -40,6 +42,8 @@ func initServer(ctx context.Context) {
mux.Handle(cst2.TaskCpdaily, &CpdailyTaskHandler{})
mux.Handle(cst2.TaskEmail, &EmailTaskHandler{})
mux.Handle(cst2.TaskResetDaily, &ResetTaskHandler{})
mux.Handle(cst2.TaskXuexitong, &XuexitongTaskHandler{})
mux.Handle(cst2.TaskXuexitongVio, &XuexitongTaskHandler{})
e := globalServer.Start(mux)
utils.OkOrPanic(e)
@@ -51,5 +55,7 @@ type taskErrorHandler struct {
func (t taskErrorHandler) HandleError(ctx context.Context, task *asynq.Task, err error) {
if task.Type() == cst2.TaskCpdaily {
g.Log().Errorf(ctx, "今日校园任务执行失败: %+v", err)
} else if task.Type() == cst2.TaskXuexitong || task.Type() == cst2.TaskXuexitongVio {
g.Log().Errorf(ctx, "学习通任务执行失败: %+v", err)
}
}
@@ -0,0 +1,128 @@
package schedule
import (
"bytes"
"context"
"encoding/gob"
"likedream-goframe/internal/application/xuexitong"
"likedream-goframe/internal/common/db"
errors2 "likedream-goframe/internal/common/errors"
"likedream-goframe/internal/ent"
"likedream-goframe/internal/ent/courseentity"
"likedream-goframe/internal/framework/errors"
"likedream-goframe/internal/utils"
"time"
"github.com/gogf/gf/v2/frame/g"
"github.com/hibiken/asynq"
"github.com/samber/oops"
)
type XuexitongTaskHandler struct{}
func (h *XuexitongTaskHandler) ProcessTask(ctx context.Context, task *asynq.Task) (err error) {
defer utils.Pass(&err)
// 解码payload
var taskPayload XuexitongTaskPayload
e := gob.NewDecoder(bytes.NewReader(task.Payload())).Decode(&taskPayload)
utils.OkOrPanic(e, oops.WithContext(ctx).With("payload", task.Payload(), "type", task.Type()).In("XuexitongTask.DecodePayload").Wrap)
// 查询课程信息
targetCourse, e := db.Global.CourseEntity.Query().Where(courseentity.ID(taskPayload.CourseID)).First(ctx)
if ent.IsNotFound(e) {
utils.OkOrPanic(oops.WithContext(ctx).With("course_id", taskPayload.CourseID).In("XuexitongTask.ProcessTask").Wrap(e))
}
utils.OkOrPanic(e, oops.WithContext(ctx).With("course_id", taskPayload.CourseID).In("XuexitongTask.ProcessTask").Wrap)
// 检查是否暂停
if targetCourse.Status == courseentity.StatusPause {
g.Log().Debugf(ctx, "课程ID %d 已暂停,跳过执行", targetCourse.ID)
return nil
}
// 检查时间限制(非暴力模式)
if targetCourse.Violence == courseentity.ViolenceNo {
currentTime := time.Now()
currentHour := currentTime.Hour()
currentMinute := currentTime.Minute()
// 只在 8:30-17:30 之间执行
startTime := 8*60 + 30 // 8:30
endTime := 17*60 + 30 // 17:30
currentMinutes := currentHour*60 + currentMinute
if currentMinutes < startTime || currentMinutes >= endTime {
g.Log().Debugf(ctx, "课程ID %d 非暴力模式,当前时间 %02d:%02d 不在执行时间范围内(8:30-17:30),跳过执行",
targetCourse.ID, currentHour, currentMinute)
return nil
}
}
// 更新状态为执行中
db.Global.CourseEntity.UpdateOneID(taskPayload.CourseID).SetStatus(courseentity.StatusDoing).ExecX(ctx)
defer utils.HandleError(func(err error) {
// 执行失败更新状态
e := db.Global.CourseEntity.UpdateOneID(taskPayload.CourseID).SetStatus(courseentity.StatusFail).Exec(ctx)
utils.LogError(ctx, "设置课程状态失败", oops.With("course_id", taskPayload.CourseID).Wrap(e))
var errorMessage string
if e1, ok := utils.Of[*errors.BusinessError](err); ok {
errorMessage = e1.Message()
} else if e1, ok := utils.Of[*errors2.BusinessError](err); ok {
errorMessage = e1.Message
} else {
errorMessage = "未知的错误导致任务执行失败: " + err.Error()
}
g.Log().Errorf(ctx, "学习通刷课失败 - 课程: %s, 错误: %s", targetCourse.CourseName, errorMessage)
panic(err)
})
// 创建学习通登录客户端
loginClient := xuexitong.NewXuexitongLogin(ctx)
// 登录学习通
err = loginClient.Login(ctx, targetCourse.Username, targetCourse.Password, 3)
if err != nil {
utils.OkOrPanic(errors.NewBusinessErrorWithDetail(400, "登录失败,请检查账号密码", err))
}
// 获取客户端
client := loginClient.GetClient()
// 创建课程服务
courseService := xuexitong.NewXuexitongCourse(client)
// 执行刷课
err = courseService.AutoStudyByCourseID(ctx, targetCourse.CourseID)
if err != nil {
utils.OkOrPanic(errors.NewBusinessErrorWithDetail(503, "刷课失败", err))
}
// 刷课完成后,统计任务情况
g.Log().Infof(ctx, "刷课完成,正在统计任务情况...")
// 获取章节列表
chapters := courseService.PullCourseChapterList(ctx, targetCourse.CourseID)
// 统计总任务数(累加所有章节的JobCount)
totalTasks := 0
for _, chapter := range chapters {
totalTasks += chapter.JobCount
}
g.Log().Infof(ctx, "课程 %s 统计完成: 总任务点 %d", targetCourse.CourseName, totalTasks)
// 更新数据库(暂时不统计完成数,只统计总数)
db.Global.CourseEntity.UpdateOneID(taskPayload.CourseID).
SetStatus(courseentity.StatusDone).
SetTaskCount(totalTasks).
ExecX(ctx)
g.Log().Infof(ctx, "学习通刷课完成 - 课程: %s", targetCourse.CourseName)
return nil
}
+86
View File
@@ -14,6 +14,7 @@ import (
"likedream-goframe/internal/framework/logger"
"likedream-goframe/internal/utils"
"github.com/bytedance/sonic"
"go.uber.org/zap"
"resty.dev/v3"
)
@@ -68,6 +69,87 @@ func (s CourseServiceV1) AddCourse(ctx context.Context, req *v1.AddCourseReq) *u
utils.OkOrPanic(errors2.NewBusinessError(400, "该课程已存在刷课任务"))
}
// 登录学习通获取节点信息
loginClient := xuexitong.NewXuexitongLogin(ctx)
err := loginClient.Login(ctx, req.Username, req.Password, 3)
if err != nil {
utils.OkOrPanic(errors2.NewBusinessError(400, "登录失败,请检查账号密码").WithInnerError(err))
}
client := loginClient.GetClient()
courseService := xuexitong.NewXuexitongCourse(client)
// 获取课程章节列表
chapters := courseService.PullCourseChapterList(ctx, req.CourseID)
// 定义节点信息结构
type NodeInfo struct {
ChapterID string `json:"chapter_id"`
ChapterName string `json:"chapter_name"`
CardID string `json:"card_id"`
CardTitle string `json:"card_title"`
CardType string `json:"card_type"`
}
var allNodes []NodeInfo
var completedNodes []string
// 获取课程信息用于API调用
courses := courseService.PullCourseList(ctx)
var targetCourse *entity.XueXiTCourse
for _, c := range courses {
if c.CourseID == req.CourseID {
targetCourse = &c
break
}
}
if targetCourse == nil {
utils.OkOrPanic(errors2.NewBusinessError(400, "未找到该课程"))
}
// 递归获取所有章节的任务点
var collectNodes func(chapters []entity.XueXiTCourseChapter)
collectNodes = func(chapters []entity.XueXiTCourseChapter) {
for _, chapter := range chapters {
// 如果有任务点,获取卡片信息
if chapter.JobCount > 0 {
cards, err := courseService.FetchChapterCards(ctx, *targetCourse, chapter.ID, chapter.ID)
if err != nil {
logger.Logger.Warn("获取章节任务点失败", zap.String("chapter", chapter.Name), zap.Error(err))
} else {
for _, card := range cards {
nodeInfo := NodeInfo{
ChapterID: chapter.ID,
ChapterName: chapter.Name,
CardID: card.ID,
CardTitle: card.Title,
CardType: card.Type,
}
allNodes = append(allNodes, nodeInfo)
// 检查是否已完成
if card.IsPassed {
nodeKey := chapter.ID + ":" + card.ID
completedNodes = append(completedNodes, nodeKey)
}
}
}
}
// 递归处理子章节
if len(chapter.Knowledge) > 0 {
collectNodes(chapter.Knowledge)
}
}
}
collectNodes(chapters)
// 将节点信息序列化为JSON
nodesJSON, _ := sonic.MarshalString(allNodes)
completedNodesJSON, _ := sonic.MarshalString(completedNodes)
db2.Global.CourseEntity.Create().
SetUserID(user.ID).
SetUsername(req.Username).
@@ -79,6 +161,10 @@ func (s CourseServiceV1) AddCourse(ctx context.Context, req *v1.AddCourseReq) *u
SetViolence(req.Violence).
SetNillableDesc(&req.Desc).
SetStatus(courseentity.StatusNotStart).
SetTaskCount(len(allNodes)).
SetSuccessCount(len(completedNodes)).
SetNodes(nodesJSON).
SetCompletedNodes(completedNodesJSON).
SaveX(ctx)
return utils.SuccessWithMsg("添加成功")
+198
View File
@@ -0,0 +1,198 @@
package cpdaily
import (
"context"
"fmt"
v1 "likedream-goframe/internal/api/v1"
"likedream-goframe/internal/application/cpdaily/leave"
"likedream-goframe/internal/application/cpdaily/login"
"likedream-goframe/internal/application/cpdaily/school"
cst2 "likedream-goframe/internal/common/cst"
db2 "likedream-goframe/internal/common/db"
errors2 "likedream-goframe/internal/common/errors"
"likedream-goframe/internal/ent"
"likedream-goframe/internal/ent/cpleave"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/sysuser"
"likedream-goframe/internal/service/balance"
"likedream-goframe/internal/utils"
"github.com/gogf/gf/v2/frame/g"
"github.com/shopspring/decimal"
)
type CpLeaveServiceV1 struct {
}
// GetLeaveListFromSystem 获取今日校园系统中的请假列表
func (v CpLeaveServiceV1) GetLeaveListFromSystem(ctx context.Context, req *v1.GetLeaveListFromSystemReq) *utils.Response[any] {
user := utils.GetUserInfoFromCtx(ctx)
// 检测是否属于自己的cpuser
cpUser := db2.Global.CpUser.Query().
Where(cpuser.ID(req.CpUserId), cpuser.HasSysuserWith(sysuser.ID(user.ID))).
WithSysuser().
WithSchool().
OnlyX(ctx)
if cpUser.Edges.Sysuser == nil {
utils.OkOrPanic(errors2.NewBusinessError(400, "非法的今日校园账号"))
}
// 获取学校详情
schoolDetail := school.GetSchoolDetail(ctx, cpUser.SchoolID)
cookie := cpUser.Cookie
client := login.GetClient(ctx, cookie)
// 检查cookie是否有效
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, client) {
loginExecutor := login.GetCpdailyLoginBySchoolInfo(ctx, &schoolDetail)
loginExecutor.Login(ctx, &schoolDetail, cpUser.Username, cpUser.Password)
cookie = loginExecutor.GetCookieString()
db2.Global.CpUser.UpdateOneID(cpUser.ID).SetCookie(cookie).ExecX(ctx)
client = login.GetClient(ctx, cookie)
}
// 创建销假服务
reportApp := leave.NewCpdailyReportApp(client, schoolDetail.WecloudUrl)
// 获取请假列表
leaveList := reportApp.GetLeaveList()
return utils.SuccessWithData[any](leaveList)
}
// List 获取销假记录列表
func (v CpLeaveServiceV1) List(ctx context.Context, req *v1.CpLeaveListReq) *utils.Response[[]*ent.CpLeave] {
user := utils.GetUserInfoFromCtx(ctx)
query := db2.Global.CpLeave.Query().
Where(cpleave.HasSysUserWith(sysuser.ID(user.ID))).
WithCpUser().
Order(ent.Desc(cpleave.FieldCreateTime))
if req.CpUserId > 0 {
query.Where(cpleave.CpUserIDEQ(req.CpUserId))
}
if req.Username != "" {
query.Where(cpleave.HasCpUserWith(cpuser.UsernameContains(req.Username)))
}
if req.Status != "" {
query.Where(cpleave.StatusEQ(cpleave.Status(req.Status)))
}
total := query.CountX(ctx)
var data []*ent.CpLeave
if total > 0 {
query.Limit(req.Size).Offset((req.Page - 1) * req.Size)
data = query.AllX(ctx)
for _, item := range data {
if item.Edges.CpUser != nil {
item.Edges.CpUser.Password = ""
item.Edges.CpUser.Cookie = ""
}
}
}
return utils.SuccessWithTotal[[]*ent.CpLeave](data, total)
}
// Report 执行销假
func (v CpLeaveServiceV1) Report(ctx context.Context, req *v1.CpLeaveReportReq) *utils.Response[any] {
user := utils.GetUserInfoFromCtx(ctx)
// 检测是否属于自己的cpuser
cpUser := db2.Global.CpUser.Query().
Where(cpuser.ID(req.CpUserId), cpuser.HasSysuserWith(sysuser.ID(user.ID))).
WithSysuser().
WithSchool().
OnlyX(ctx)
if cpUser.Edges.Sysuser == nil {
utils.OkOrPanic(errors2.NewBusinessError(400, "非法的今日校园账号"))
}
// 检查是否已经存在该销假记录
existLeave, _ := db2.Global.CpLeave.Query().
Where(cpleave.LeaveIDEQ(req.LeaveId), cpleave.CpUserIDEQ(req.CpUserId)).
First(ctx)
if existLeave != nil {
utils.OkOrPanic(errors2.NewBusinessError(400, fmt.Sprintf("该请假记录已处理,状态:%s", existLeave.Status)))
}
// 计算扣款金额
basePoint, err := decimal.NewFromString(g.Cfg().MustGet(ctx, cst2.ConfigBasePointCpdaily).String())
utils.OkOrPanic(err)
if user.Edges.Agent != nil {
basePoint = basePoint.Mul(user.Edges.Agent.Rate)
}
// 先扣款
balance.BalanceService.ChangeUserBalance(ctx, user.ID, basePoint.Neg())
// 创建销假记录
leaveRecord := db2.Global.CpLeave.Create().
SetCpUserID(req.CpUserId).
SetUserID(user.ID).
SetLeaveID(req.LeaveId).
SetTitle(req.Title).
SetStatus(cpleave.StatusFail).
SetType(cpleave.TypeReport).
SetDesc("正在处理中...").
SaveX(ctx)
// 执行业务逻辑
defer func() {
if r := recover(); r != nil {
// 如果业务执行失败,退回扣款
balance.BalanceService.ChangeUserBalance(ctx, user.ID, basePoint)
// 更新记录状态为失败,并记录失败原因
desc := fmt.Sprintf("销假失败: %v", r)
db2.Global.CpLeave.UpdateOne(leaveRecord).
SetStatus(cpleave.StatusFail).
SetDesc(desc).
ExecX(ctx)
utils.OkOrPanic(errors2.NewBusinessError(500, desc))
}
}()
// 获取学校详情
schoolDetail := school.GetSchoolDetail(ctx, cpUser.SchoolID)
cookie := cpUser.Cookie
client := login.GetClient(ctx, cookie)
// 检查cookie是否有效
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, client) {
loginExecutor := login.GetCpdailyLoginBySchoolInfo(ctx, &schoolDetail)
loginExecutor.Login(ctx, &schoolDetail, cpUser.Username, cpUser.Password)
cookie = loginExecutor.GetCookieString()
db2.Global.CpUser.UpdateOneID(cpUser.ID).SetCookie(cookie).ExecX(ctx)
client = login.GetClient(ctx, cookie)
}
// 创建销假服务
reportApp := leave.NewCpdailyReportApp(client, schoolDetail.WecloudUrl)
// 获取请假详情
detail := reportApp.LeaveDetail(req.LeaveId)
// 填充表单
form := reportApp.FillReportForm(detail)
// 获取位置信息
lon, lat := reportApp.GetLocation(detail)
// 提交销假
reportApp.SubmitReport(ctx, form, lon, lat, cpUser.Username, cpUser.MobileCode)
// 如果执行成功,更新记录状态
db2.Global.CpLeave.UpdateOne(leaveRecord).
SetStatus(cpleave.StatusDone).
SetDesc("已提交").
ExecX(ctx)
return utils.SuccessWithMsg("销假成功")
}
func NewCpLeaveServiceV1() *CpLeaveServiceV1 {
return &CpLeaveServiceV1{}
}
+5
View File
@@ -180,3 +180,8 @@ func (v CpUserServiceV1) LoginGetCode(ctx context.Context, req *v1.LoginGetCode)
func (v CpUserServiceV1) AddByCode(ctx context.Context, req *v1.AddByCode) *utils.Response[any] {
return utils.SuccessWithMsg("")
}
func (v CpUserServiceV1) LoginUrl(ctx context.Context, req *v1.CpUserLoginUrlReq) *utils.Response[any] {
sc := db.Global.CpSchool.Query().Where(cpschool.NameEQ(req.Name)).Limit(1).OnlyX(ctx)
return utils.SuccessWithData[any](school.GetSchoolDetail(ctx, sc.ID))
}
+2
View File
@@ -24,6 +24,7 @@ type globalService struct {
CpTask *cpdaily.CpTaskServiceV1
CpImage *cpdaily.CpImageServiceV1
CpTaskLog *cpdaily.CpTaskLogServiceV1
CpLeave *cpdaily.CpLeaveServiceV1
Card *card.CardServiceV1
Course *course.CourseServiceV1
}
@@ -40,6 +41,7 @@ var Global = globalService{
CpTask: cpdaily.NewCpTaskServiceV1(),
CpImage: cpdaily.NewCpImageServiceV1(),
CpTaskLog: cpdaily.NewCpTaskLogServiceV1(),
CpLeave: cpdaily.NewCpLeaveServiceV1(),
Card: card.NewCardServiceV1(),
Course: course.NewCourseServiceV1(),
}