Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 334d597f9a | |||
| 98eb15f4e4 | |||
| 3a2e679b85 | |||
| 921192a914 | |||
| 107b472cf7 | |||
| 14108f6ba3 | |||
| a22f559889 | |||
| ececfa344d | |||
| 5ba9e38e1a | |||
| 6eb4bc6d8a | |||
| 17e6c0a789 | |||
| f067ed2ad0 | |||
| 7bfc7a58ab |
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"likedream-goframe/internal/application/cpdaily/login"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
)
|
||||
|
||||
func main() {
|
||||
const testSmsPhoneNumber = ""
|
||||
handler := login.SmsLoginHandler{}
|
||||
ctx := gctx.GetInitCtx()
|
||||
sendSmsData := handler.SendSms(ctx, testSmsPhoneNumber)
|
||||
// 读取验证码手动输入
|
||||
var code string
|
||||
println("请输入收到的验证码:")
|
||||
_, _ = fmt.Scanln(&code)
|
||||
loginData := handler.LoginByCode(ctx, testSmsPhoneNumber, code, sendSmsData.CookieJar)
|
||||
handler.SetLoginCookie(ctx, sendSmsData.CookieJar, loginData)
|
||||
}
|
||||
+4
-2
@@ -3,7 +3,7 @@ url = "https://devocr.likedream.xyz"
|
||||
|
||||
[database]
|
||||
type = "mysql"
|
||||
dsn = "test_likedream_go:EpXckXmxawDEQGxJ@tcp(database.out:3306)/test_likedream_go?parseTime=true"
|
||||
dsn = "test_likedream_go:EpXckXmxawDEQGxJ@tcp(database.out:3306)/test_likedream_go?parseTime=true&loc=Asia%2FShanghai"
|
||||
dsn2 = "host=database.out user=dev password=JPmKjmpcaG3EYAJZ dbname=dev port=5432 sslmode=disable TimeZone=Asia/Shanghai"
|
||||
# host=localhost user=gorm password=gorm dbname=gorm port=9920 sslmode=disable TimeZone=Asia/Shanghai
|
||||
[server]
|
||||
@@ -51,6 +51,8 @@ sliderIds = ["1018764144934965", "sdhyxy", "hqdx"]
|
||||
|
||||
|
||||
[basePoint]
|
||||
cpdaily = "0.5"
|
||||
cpdailyTask = "0.5"
|
||||
cpdailyLeave = "4"
|
||||
cpdailyPhone = "0.25"
|
||||
[task]
|
||||
concurrency = 20
|
||||
@@ -4,8 +4,10 @@ import (
|
||||
"context"
|
||||
"likedream-goframe/internal/common/cst"
|
||||
"likedream-goframe/internal/controller/agent"
|
||||
"likedream-goframe/internal/controller/balance"
|
||||
"likedream-goframe/internal/controller/card"
|
||||
"likedream-goframe/internal/controller/common"
|
||||
"likedream-goframe/internal/controller/config"
|
||||
"likedream-goframe/internal/controller/course"
|
||||
"likedream-goframe/internal/controller/cpdaily"
|
||||
"likedream-goframe/internal/controller/menu"
|
||||
@@ -41,10 +43,12 @@ func StartServer(ctx context.Context) {
|
||||
systemGroup.Bind(role.NewV1())
|
||||
systemGroup.Bind(menu.NewV1())
|
||||
systemGroup.Bind(user.NewUserCtrlV1())
|
||||
systemGroup.Bind(config.NewConfigCtrlV1())
|
||||
//systemGroup.Bind(agent.NewV1())
|
||||
// 用户信息路由
|
||||
userGroup := group.Group("/user").Middleware(middleware.AuthHandler, middleware.PermissionHandler)
|
||||
userGroup.Bind(user_login.NewUserInfoV1())
|
||||
userGroup.Bind(balance.NewBalanceCtrlV1())
|
||||
// 代理信息路由
|
||||
agentGroup := group.Group("/agent").Middleware(middleware.AuthHandler, middleware.PermissionHandler)
|
||||
agentGroup.Bind(agent.NewV1())
|
||||
@@ -55,6 +59,7 @@ func StartServer(ctx context.Context) {
|
||||
cpdailyGroup.Bind(cpdaily.NewCpTaskCtrlV1())
|
||||
cpdailyGroup.Bind(cpdaily.NewCpImageCtrlV1())
|
||||
cpdailyGroup.Bind(cpdaily.NewCpTaskLogCtrlV1())
|
||||
cpdailyGroup.Bind(cpdaily.NewCpLeaveCtrlV1())
|
||||
// 娱乐
|
||||
musicGroup := group.Group("/music").Middleware(middleware.AuthHandler, middleware.PermissionHandler)
|
||||
musicGroup.Bind(music.NewMusicCtrlV1())
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package v1
|
||||
|
||||
import "github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
type BalanceRecordListReq struct {
|
||||
g.Meta `path:"/balance/records" method:"get" tags:"Balance" summary:"获取用户余额变动记录列表"`
|
||||
Type string `json:"type" dc:"变动类型: increase-增加, decrease-减少"`
|
||||
Page int `json:"page" d:"1"`
|
||||
Size int `json:"size" d:"10"`
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type ConfigGetReq struct {
|
||||
g.Meta `path:"/config/{key}" method:"get" tags:"Config" summary:"获取配置"`
|
||||
Key string `json:"key" v:"required#配置键不能为空"`
|
||||
}
|
||||
|
||||
type ConfigUpdateReq struct {
|
||||
g.Meta `path:"/config/{key}" method:"put" tags:"Config" summary:"更新配置" permission:"sys:config:edit"`
|
||||
Key string `json:"key" v:"required#配置键不能为空"`
|
||||
Value string `json:"value" v:"required#配置值不能为空"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
type ConfigListReq struct {
|
||||
g.Meta `path:"/config" method:"get" tags:"Config" summary:"获取配置列表"`
|
||||
Key string `json:"key"`
|
||||
Page int `json:"page" d:"1"`
|
||||
Size int `json:"size" d:"10"`
|
||||
}
|
||||
|
||||
type ConfigPublicGetReq struct {
|
||||
g.Meta `path:"/config/public/{key}" method:"get" tags:"Config" summary:"获取公开配置(无需认证)"`
|
||||
Key string `json:"key" v:"required#配置键不能为空"`
|
||||
}
|
||||
@@ -30,10 +30,13 @@ type LoginGetCode struct {
|
||||
|
||||
type AddByCode struct {
|
||||
g.Meta `path:"/user/addByCode" method:"post" tags:"CpUser" summary:"手机号登录"`
|
||||
Id int64 `json:"id"`
|
||||
CaptchaKey string `json:"captchaKey" v:"required#验证码不能不能为空"`
|
||||
Dots []captcha.ConfirmData `json:"dots" v:"required#验证码不能为空"`
|
||||
Mobile string `json:"mobile" v:"required#手机号不能为空"`
|
||||
SchoolId string `json:"school_id"`
|
||||
Code string `json:"code"`
|
||||
Email string `json:"email" v:"email|regex:^.*@qq\\.com$#邮箱格式不正确|必须是QQ邮箱"`
|
||||
}
|
||||
|
||||
type CpUserConfirmAddReq struct {
|
||||
|
||||
@@ -62,12 +62,17 @@ func (c *CpdailyReportApp) GetLeaveList() []leavetype.LeaveListOne {
|
||||
|
||||
var listList []leavetype.LeaveListOne
|
||||
for _, row := range rows.Array() {
|
||||
// 已完成
|
||||
if row.Get("status").String() == "4" {
|
||||
continue
|
||||
}
|
||||
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(),
|
||||
Reason: row.Get("leaveReason").String(),
|
||||
AceEndTime: row.Get("actEndTime").String(),
|
||||
Status: row.Get("status").String(),
|
||||
}
|
||||
listList = append(listList, leaveOne)
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
package login
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"likedream-goframe/internal/application/cpdaily/cryptoutil"
|
||||
"likedream-goframe/internal/application/httpclient"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"resty.dev/v3"
|
||||
)
|
||||
|
||||
type CpdailyCodeLogin struct {
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
func NewCode(ctx context.Context) *CpdailyCodeLogin {
|
||||
return &CpdailyCodeLogin{
|
||||
client: httpclient.NewCpdailyClient(),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CpdailyCodeLogin) GetLoginCode(mobile string) {
|
||||
mobileBytes := cryptoutil.AesEncrypt([]byte(mobile))
|
||||
mobile = base64.StdEncoding.EncodeToString(mobileBytes)
|
||||
c.client.R().SetBody(map[string]string{
|
||||
"a": mobile,
|
||||
"b": "first_v4",
|
||||
}).Post("https://mobile.campushoy.com/app/auth/authentication/mobile/messageCode/v-8222")
|
||||
}
|
||||
|
||||
func (c *CpdailyCodeLogin) LoginByCode(mobile, code string) {
|
||||
type loginStruct struct {
|
||||
C string `json:"c"`
|
||||
D string `json:"d"`
|
||||
E string `json:"e"`
|
||||
F string `json:"f"`
|
||||
}
|
||||
data := loginStruct{
|
||||
C: mobile,
|
||||
D: code,
|
||||
E: "CPDAILY",
|
||||
F: "86",
|
||||
}
|
||||
marshal, _ := sonic.Marshal(data)
|
||||
marshalBytes := cryptoutil.AesEncrypt(marshal)
|
||||
c.client.R().SetBody(map[string]string{
|
||||
"a": base64.StdEncoding.EncodeToString(marshalBytes),
|
||||
"b": "first_v4",
|
||||
}).Post("https://mobile.campushoy.com/app/auth/authentication/mobileLogin/v-8222")
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"likedream-goframe/internal/application/cookiejar"
|
||||
"likedream-goframe/internal/application/httpclient"
|
||||
"likedream-goframe/internal/common/errors"
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/utils"
|
||||
"strings"
|
||||
|
||||
@@ -86,7 +87,7 @@ func ActivateSession(ctx context.Context, host string, client *resty.Client) {
|
||||
client.SetRedirectPolicy(resty.NoRedirectPolicy())
|
||||
}
|
||||
|
||||
func CookieEnabled(ctx context.Context, host string, client *resty.Client) bool {
|
||||
func CookieEnabled(ctx context.Context, host string, client *resty.Client, loginType cpuser.LoginType) bool {
|
||||
client.SetRedirectPolicy(resty.NoRedirectPolicy())
|
||||
host = strings.TrimSuffix(host, "/")
|
||||
sessionResponse, err := client.R().
|
||||
@@ -95,7 +96,11 @@ func CookieEnabled(ctx context.Context, host string, client *resty.Client) bool
|
||||
Post(fmt.Sprintf("%s/wec-counselor-attendance-apps/student/attendance/getStuAttendacesInOneDay", host))
|
||||
|
||||
utils.OkOrPanic(err)
|
||||
return sessionResponse.StatusCode() != 302
|
||||
needLogin := sessionResponse.StatusCode() == 302
|
||||
if needLogin && loginType == cpuser.LoginTypePhone {
|
||||
utils.OkOrPanic(errors.NewBusinessError(500, "登录信息失效,请重新通过短信验证码登录"))
|
||||
}
|
||||
return !needLogin
|
||||
}
|
||||
|
||||
func GetClient(ctx context.Context, cookie string) *resty.Client {
|
||||
|
||||
@@ -0,0 +1,280 @@
|
||||
package login
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/application/cookiejar"
|
||||
"likedream-goframe/internal/application/cpdaily/cryptoutil"
|
||||
"likedream-goframe/internal/application/cpdaily/school"
|
||||
"likedream-goframe/internal/application/httpclient"
|
||||
"likedream-goframe/internal/common/cst"
|
||||
"likedream-goframe/internal/common/errors"
|
||||
"likedream-goframe/internal/utils"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/samber/oops"
|
||||
"resty.dev/v3"
|
||||
)
|
||||
|
||||
type cpdailySmsCommonResponse[T any] struct {
|
||||
ErrCode int `json:"errCode"`
|
||||
ErrMsg string `json:"errMsg"`
|
||||
Data T `json:"data"`
|
||||
}
|
||||
|
||||
func (c *cpdailySmsCommonResponse[T]) EnsureSuccess() {
|
||||
if c.ErrCode != 0 {
|
||||
utils.OkOrPanic(errors.NewBusinessError(503, c.ErrMsg))
|
||||
}
|
||||
}
|
||||
|
||||
type CpdailySmsSendSmsData struct {
|
||||
Countdown int `json:"countdown"`
|
||||
TipMsg string `json:"tipMsg"`
|
||||
Status int `json:"status"`
|
||||
CookieJar *cookiejar.PersistCookieJar `json:"-"`
|
||||
}
|
||||
|
||||
type CpdailySmsLoginByCodeData struct {
|
||||
AuthID string `json:"authId"`
|
||||
AuthStatus string `json:"authStatus"`
|
||||
CompleteUserInfoStatus string `json:"completeUserInfoStatus"`
|
||||
DeviceExceptionMsg string `json:"deviceExceptionMsg"`
|
||||
DeviceStatus string `json:"deviceStatus"`
|
||||
FirstLogin bool `json:"firstLogin"`
|
||||
Mobile string `json:"mobile"`
|
||||
MsgTip string `json:"msgTip"`
|
||||
Name string `json:"name"`
|
||||
OpenID string `json:"openId"`
|
||||
PersonID string `json:"personId"`
|
||||
SessionToken string `json:"sessionToken"`
|
||||
Status string `json:"status"`
|
||||
TenantID string `json:"tenantId"`
|
||||
TenantName string `json:"tenantName"`
|
||||
Tgc string `json:"tgc"`
|
||||
TgcStatus string `json:"tgcStatus"`
|
||||
UserID string `json:"userId"`
|
||||
UserType string `json:"userType"`
|
||||
}
|
||||
|
||||
func NewSms(deviceID string) *SmsLoginHandler {
|
||||
return &SmsLoginHandler{
|
||||
deviceID: deviceID,
|
||||
}
|
||||
}
|
||||
|
||||
func NewSmsWithoutDeviceID() *SmsLoginHandler {
|
||||
return &SmsLoginHandler{
|
||||
deviceID: "",
|
||||
}
|
||||
}
|
||||
|
||||
type SmsLoginHandler struct {
|
||||
deviceID string
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
func (s *SmsLoginHandler) SendSms(ctx context.Context, phone string) *CpdailySmsSendSmsData {
|
||||
jar := cookiejar.NewPersistCookieJar()
|
||||
|
||||
phoneEncrypted := base64.StdEncoding.EncodeToString(cryptoutil.AesEncrypt([]byte(phone)))
|
||||
s.client = httpclient.NewCpdailyClient()
|
||||
req := s.client.
|
||||
SetCookieJar(jar).
|
||||
R().
|
||||
SetContext(utils.NewCpdailySmsContextBuilder().
|
||||
WithDeviceID(s.deviceID).
|
||||
Build(ctx)).
|
||||
SetBody(map[string]string{
|
||||
"a": phoneEncrypted,
|
||||
"b": cryptoutil.EncryptVersion,
|
||||
})
|
||||
|
||||
setSmsRequestHeaders(ctx, req)
|
||||
|
||||
resp, e := req.
|
||||
Post("https://mobile.campushoy.com/app/auth/authentication/mobile/messageCode/v-8222")
|
||||
utils.OkOrPanic(e, oops.WithContext(ctx).Wrap)
|
||||
|
||||
respJson := utils.ReadJson[cpdailySmsCommonResponse[CpdailySmsSendSmsData]](resp.Body)
|
||||
respJson.EnsureSuccess()
|
||||
|
||||
respJson.Data.CookieJar = jar
|
||||
|
||||
return &respJson.Data
|
||||
}
|
||||
|
||||
func (s *SmsLoginHandler) LoginByCode(ctx context.Context, phone, code string, jar http.CookieJar) *CpdailySmsLoginByCodeData {
|
||||
payload := map[string]any{
|
||||
"d": code,
|
||||
"e": "CPDAILY",
|
||||
"c": phone,
|
||||
"f": "86",
|
||||
}
|
||||
|
||||
payloadString, e := sonic.Marshal(payload)
|
||||
utils.OkOrPanic(e, oops.WithContext(ctx).Wrap)
|
||||
|
||||
encryptedPayload := cryptoutil.AesEncrypt(payloadString)
|
||||
encodedPayload := base64.StdEncoding.EncodeToString(encryptedPayload)
|
||||
|
||||
payload = map[string]any{
|
||||
"a": encodedPayload,
|
||||
"b": cryptoutil.EncryptVersion,
|
||||
}
|
||||
s.client = httpclient.NewCpdailyClient()
|
||||
s.client.SetCookieJar(jar)
|
||||
req := s.client.R().
|
||||
SetBody(payload).
|
||||
SetContext(utils.NewCpdailySmsContextBuilder().
|
||||
WithDeviceID(s.deviceID).
|
||||
Build(ctx))
|
||||
setSmsRequestHeaders(ctx, req)
|
||||
|
||||
resp, e := req.
|
||||
Post("https://mobile.campushoy.com/app/auth/authentication/mobileLogin/v-8222")
|
||||
utils.OkOrPanic(e, oops.WithContext(ctx).Wrap)
|
||||
|
||||
respJson := utils.ReadJson[cpdailySmsCommonResponse[string]](resp.Body)
|
||||
respJson.EnsureSuccess()
|
||||
|
||||
data := decodeData[CpdailySmsLoginByCodeData](respJson.Data)
|
||||
|
||||
return &data
|
||||
}
|
||||
|
||||
func (s *SmsLoginHandler) SetLoginCookie(ctx context.Context, jar http.CookieJar, loginData *CpdailySmsLoginByCodeData) {
|
||||
detail := school.GetSchoolDetail(ctx, loginData.TenantID)
|
||||
|
||||
getCookieUrl := fmt.Sprintf("%s%s", detail.WecloudUrl, "/wec-im-group/group/imUserToken/getImUserToken")
|
||||
|
||||
cookieMap := map[string]any{
|
||||
"AMP2": []map[string]any{
|
||||
{
|
||||
"path": "/",
|
||||
"value": loginData.SessionToken,
|
||||
"domain": "",
|
||||
"name": "sessionToken",
|
||||
},
|
||||
},
|
||||
"AMP1": []map[string]any{
|
||||
{
|
||||
"path": "/",
|
||||
"value": loginData.SessionToken,
|
||||
"domain": "",
|
||||
"name": "sessionToken",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
ampTokenString, e := sonic.Marshal(cookieMap)
|
||||
utils.OkOrPanic(e, oops.WithContext(ctx).Wrap)
|
||||
|
||||
ampTokenEncrypted := cryptoutil.DesEncrypt(ampTokenString, cryptoutil.Normal)
|
||||
ampToken := base64.StdEncoding.EncodeToString(ampTokenEncrypted)
|
||||
|
||||
// 设置cookie到jar: clientType=cpdaily_student; tenantId=ahnu; standAlone=0; sessionToken=5e55bfa7-d17e-4f5a-a06d-99a649855521;
|
||||
targetSchoolUrl, e := url.Parse(detail.WecloudUrl)
|
||||
utils.OkOrPanic(e, oops.WithContext(ctx).Wrap)
|
||||
targetApiUrl, e := url.Parse("https://api.campushoy.com")
|
||||
utils.OkOrPanic(e, oops.WithContext(ctx).Wrap)
|
||||
|
||||
cookieNameValues := map[string]string{
|
||||
"clientType": "cpdaily_student",
|
||||
"tenantId": detail.Id,
|
||||
"standAlone": "0",
|
||||
"sessionToken": loginData.SessionToken,
|
||||
}
|
||||
|
||||
for name, value := range cookieNameValues {
|
||||
cookie := &http.Cookie{
|
||||
Name: name,
|
||||
Value: value,
|
||||
}
|
||||
|
||||
jar.SetCookies(targetSchoolUrl, []*http.Cookie{cookie})
|
||||
jar.SetCookies(targetApiUrl, []*http.Cookie{cookie})
|
||||
}
|
||||
s.client.SetRedirectPolicy(resty.FlexibleRedirectPolicy(50))
|
||||
req := s.client.R().
|
||||
SetHeader("AmpCookies", ampToken).
|
||||
SetContext(ctx)
|
||||
|
||||
ctx = utils.NewCpdailySmsContextBuilder().
|
||||
WithDeviceID(s.deviceID).
|
||||
WithTenantID(detail.Id).
|
||||
WithSessionToken(loginData.SessionToken).
|
||||
Build(ctx)
|
||||
|
||||
setSmsRequestHeaders(ctx, req)
|
||||
|
||||
resp, e := req.
|
||||
Get(getCookieUrl)
|
||||
utils.OkOrPanic(e, oops.WithContext(ctx).Wrap)
|
||||
|
||||
respJson := utils.ReadJson[cpdailySmsCommonResponse[any]](resp.Body)
|
||||
respJson.EnsureSuccess()
|
||||
}
|
||||
|
||||
func decodeData[T any](encodedData string) T {
|
||||
decodedBytes, e := base64.StdEncoding.DecodeString(encodedData)
|
||||
utils.OkOrPanic(e)
|
||||
|
||||
decryptedBytes := cryptoutil.AesDecrypt(decodedBytes)
|
||||
|
||||
result := utils.ReadJson[T](bytes.NewReader(decryptedBytes))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func setSmsRequestHeaders(ctx context.Context, request *resty.Request) {
|
||||
sessionToken, ok := ctx.Value(cst.CtxCpdailySessionToken).(string)
|
||||
if ok {
|
||||
encryptedSessionToken := cryptoutil.DesEncrypt([]byte(sessionToken), cryptoutil.Normal)
|
||||
encodedSessionToken := base64.StdEncoding.EncodeToString(encryptedSessionToken)
|
||||
request.SetHeader("SessionToken", encodedSessionToken)
|
||||
request.SetHeader("sessionTokenKey", encodedSessionToken)
|
||||
} else {
|
||||
request.SetHeader("SessionToken", sessionToken)
|
||||
request.SetHeader("sessionTokenKey", sessionToken)
|
||||
}
|
||||
|
||||
deviceId, _ := ctx.Value(cst.CtxCpdailyDeviceID).(string)
|
||||
|
||||
cpdailyInfoDetail := map[string]any{
|
||||
"deviceId": deviceId,
|
||||
"systemName": "android",
|
||||
"userId": "",
|
||||
"appVersion": "9.8.8",
|
||||
"model": "Unknown",
|
||||
"lon": "0",
|
||||
"lat": "0",
|
||||
"cpdailyVersion": "9.8.8",
|
||||
"systemVersion": "11",
|
||||
}
|
||||
|
||||
cpdailyInfoStr, e := sonic.Marshal(cpdailyInfoDetail)
|
||||
utils.OkOrPanic(e, oops.WithContext(ctx).Wrap)
|
||||
|
||||
encryptedCpdailyInfo := cryptoutil.DesEncrypt(cpdailyInfoStr, cryptoutil.Normal)
|
||||
encodedCpdailyInfo := base64.StdEncoding.EncodeToString(encryptedCpdailyInfo)
|
||||
|
||||
request.SetHeaders(map[string]string{
|
||||
"clientType": "cpdaily_student",
|
||||
"deviceType": "1",
|
||||
"CpdailyClientType": "CPDAILY",
|
||||
"CpdailyStandAlone": "0",
|
||||
"User-Agent": "Mozilla/5.0 (Linux; Android 11; Redmi Note 8 Pro Build/RP1A.230805.003; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/83.0.4103.106 Mobile Safari/537.36 cpdaily/9.8.8 wisedu/9.8.8",
|
||||
"CpdailyInfo": encodedCpdailyInfo,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *SmsLoginHandler) GetCookieString() string {
|
||||
cookieJar := s.client.CookieJar()
|
||||
serializableJar := cookieJar.(*cookiejar.PersistCookieJar)
|
||||
return serializableJar.Serialize()
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package login
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/application/cookiejar"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
)
|
||||
|
||||
const (
|
||||
testSmsPhoneNumber = ""
|
||||
testSmsCode = ""
|
||||
)
|
||||
|
||||
func TestSmsLoginHandler_SendSms(t *testing.T) {
|
||||
handler := SmsLoginHandler{}
|
||||
data := handler.SendSms(context.Background(), testSmsPhoneNumber)
|
||||
|
||||
t.Logf("SendSms Data: %+v", data)
|
||||
}
|
||||
|
||||
func TestSmsLoginHandler_LoginByCode(t *testing.T) {
|
||||
handler := SmsLoginHandler{}
|
||||
jar := cookiejar.NewPersistCookieJar()
|
||||
data := handler.LoginByCode(context.Background(), testSmsPhoneNumber, testSmsCode, jar)
|
||||
t.Logf("LoginByCode Data: %+v", data)
|
||||
|
||||
handler.SetLoginCookie(context.Background(), jar, data)
|
||||
}
|
||||
|
||||
func TestLogin(t *testing.T) {
|
||||
handler := SmsLoginHandler{}
|
||||
ctx := gctx.GetInitCtx()
|
||||
sendSmsData := handler.SendSms(ctx, testSmsPhoneNumber)
|
||||
// 读取验证码手动输入
|
||||
var code string
|
||||
println("请输入收到的验证码:")
|
||||
_, _ = fmt.Scanln(&code)
|
||||
loginData := handler.LoginByCode(ctx, testSmsPhoneNumber, code, sendSmsData.CookieJar)
|
||||
handler.SetLoginCookie(ctx, sendSmsData.CookieJar, loginData)
|
||||
}
|
||||
@@ -59,13 +59,15 @@ func GetSchoolList(ctx context.Context) []CpdailySchoolBriefInfo {
|
||||
func GetSchoolDetail(ctx context.Context, tenantId string) SchoolDetailInfo {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
client := redis.GetClient()
|
||||
redisResult := client.Get(ctx, cst2.RedisSchoolInfo+tenantId)
|
||||
if redisResult.Err() == nil {
|
||||
var ret SchoolDetailInfo
|
||||
err := sonic.Unmarshal([]byte(redisResult.Val()), &ret)
|
||||
utils.OkOrPanic(err)
|
||||
return parseSpecialSchool(ret)
|
||||
if !utils.IsDebug() {
|
||||
client := redis.GetClient()
|
||||
redisResult := client.Get(ctx, cst2.RedisSchoolInfo+tenantId)
|
||||
if redisResult.Err() == nil {
|
||||
var ret SchoolDetailInfo
|
||||
err := sonic.Unmarshal([]byte(redisResult.Val()), &ret)
|
||||
utils.OkOrPanic(err)
|
||||
return parseSpecialSchool(ret)
|
||||
}
|
||||
}
|
||||
response, err := httpclient.Cpdaily.Clone(ctx).R().
|
||||
SetHeaders(map[string]string{
|
||||
@@ -104,7 +106,10 @@ func GetSchoolDetail(ctx context.Context, tenantId string) SchoolDetailInfo {
|
||||
WithContext(ctx).
|
||||
Wrap(errors.NewBusinessError(503, "学校ID不存在").Decorate("empty school detail")))
|
||||
}
|
||||
client.Set(ctx, cst2.RedisSchoolInfo+tenantId, ret[0], time.Duration(cst2.RedisSchoolInfoExpire)*time.Second)
|
||||
if !utils.IsDebug() {
|
||||
client := redis.GetClient()
|
||||
client.Set(ctx, cst2.RedisSchoolInfo+tenantId, ret[0], time.Duration(cst2.RedisSchoolInfoExpire)*time.Second)
|
||||
}
|
||||
return parseSpecialSchool(ret[0])
|
||||
}
|
||||
|
||||
|
||||
@@ -6,4 +6,5 @@ type LeaveListOne struct {
|
||||
CreateTime string `json:"createTime"`
|
||||
AceEndTime string `json:"aceEndTime"`
|
||||
Reason string `json:"reason"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
@@ -693,3 +693,18 @@ func (c *CpdailySleepCheckTask) Submit(ctx context.Context, form map[string]*gva
|
||||
utils.OkOrPanic(errors.NewBusinessError(503, responseJSON.Get("message").String()), oops.WithContext(ctx).Wrap)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CpdailySleepCheckTask) GetYearAndMonth(ctx context.Context) (string, string) {
|
||||
// Get current time in Shanghai timezone
|
||||
timeNow := time.Now().In(cst.TimeZoneShangHai)
|
||||
|
||||
// Check if current day is within first 2 days of the month
|
||||
if timeNow.Day() <= 2 {
|
||||
// Return previous month
|
||||
prevTime := timeNow.AddDate(0, -1, 0)
|
||||
return strconv.Itoa(prevTime.Year()), strconv.Itoa(int(prevTime.Month()))
|
||||
} else {
|
||||
// Return current month
|
||||
return strconv.Itoa(timeNow.Year()), strconv.Itoa(int(timeNow.Month()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
package task
|
||||
|
||||
import (
|
||||
"context"
|
||||
"likedream-goframe/internal/testutil"
|
||||
"testing"
|
||||
|
||||
"github.com/joomcode/errorx"
|
||||
)
|
||||
|
||||
func TestCpdailySleepCheckTask_QueryFormByTitle(t *testing.T) {
|
||||
loginClient, schoolDetail := testutil.LoginTestUser()
|
||||
|
||||
task := NewSleepCheckTask(loginClient, schoolDetail.WecloudUrl)
|
||||
tasks := task.QueryFormByTitle(context.Background(), "查寝")
|
||||
|
||||
if len(tasks) == 0 {
|
||||
t.Error("未查询到查寝任务")
|
||||
} else {
|
||||
t.Logf("查询到查寝任务: %v", tasks)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCpdailySleepCheckTask_GetRecentTaskTitle(t *testing.T) {
|
||||
loginClient, schoolDetail := testutil.LoginTestUser()
|
||||
|
||||
task := NewSleepCheckTask(loginClient, schoolDetail.WecloudUrl)
|
||||
|
||||
titles := task.GetRecentTaskTitle(context.Background())
|
||||
|
||||
if len(titles) == 0 {
|
||||
t.Error("未查询到查寝任务标题")
|
||||
} else {
|
||||
t.Logf("查询到查寝任务标题: %v", titles)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCpdailySleepCheckTask_QueryFormByYearMonth(t *testing.T) {
|
||||
loginClient, schoolDetail := testutil.LoginTestUser()
|
||||
|
||||
task := NewSleepCheckTask(loginClient, schoolDetail.WecloudUrl)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
titleGlob string
|
||||
year string
|
||||
month string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "查询当前月份查寝任务",
|
||||
titleGlob: "查寝",
|
||||
year: "2025",
|
||||
month: "6",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "查询单数字月份查寝任务",
|
||||
titleGlob: "查寝",
|
||||
year: "2025",
|
||||
month: "6", // 将会被格式化为 "06"
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "使用通配符模式匹配",
|
||||
titleGlob: "*查寝*",
|
||||
year: "2025",
|
||||
month: "6",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "查询不存在的任务",
|
||||
titleGlob: "不存在的任务",
|
||||
year: "2025",
|
||||
month: "6",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
oopsError, _ := errorx.ErrorFromPanic(r)
|
||||
if !tt.wantErr {
|
||||
t.Errorf("QueryFormByYearMonth() 意外的panic: %+v", oopsError)
|
||||
} else {
|
||||
t.Logf("预期的错误: %+v", oopsError)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
form := task.QueryFormByYearMonth(context.Background(), tt.titleGlob, tt.year, tt.month)
|
||||
|
||||
if tt.wantErr {
|
||||
t.Error("预期应该出现错误,但没有出现")
|
||||
return
|
||||
}
|
||||
|
||||
if form == nil {
|
||||
t.Error("未查询到查寝任务表单")
|
||||
return
|
||||
}
|
||||
|
||||
// 验证返回结果的结构
|
||||
if realTitle := form["realTitle"].String(); realTitle == "" {
|
||||
t.Error("返回结果中缺少 realTitle 或 realTitle 为空")
|
||||
} else {
|
||||
t.Logf("任务真实标题: %s", realTitle)
|
||||
}
|
||||
|
||||
if taskInfo := form["taskInfo"].Map(); taskInfo == nil {
|
||||
t.Error("返回结果中缺少 taskInfo 或 taskInfo 为空")
|
||||
} else {
|
||||
t.Logf("任务信息包含字段: %d", len(taskInfo))
|
||||
|
||||
// 验证关键字段是否存在
|
||||
requiredFields := []string{"taskName", "signWid", "signInstanceWid"}
|
||||
for _, field := range requiredFields {
|
||||
if _, exists := taskInfo[field]; !exists {
|
||||
t.Errorf("taskInfo 中缺少必要字段: %s", field)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if rows := form["rows"].Map(); rows == nil {
|
||||
t.Error("返回结果中缺少 rows 或 rows 为空")
|
||||
} else {
|
||||
t.Logf("表单数据包含字段: %d", len(rows))
|
||||
}
|
||||
|
||||
t.Logf("查询到查寝任务表单,标题: %v", form["realTitle"])
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package task
|
||||
|
||||
import (
|
||||
"context"
|
||||
"likedream-goframe/internal/testutil"
|
||||
"testing"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
)
|
||||
|
||||
func TestGetHistoryForm(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
loginClient, schoolDetail := testutil.LoginTestUser()
|
||||
task := NewSleepCheckTask(loginClient, schoolDetail.WecloudUrl)
|
||||
y, m := task.GetYearAndMonth(ctx)
|
||||
month := task.QueryFormByYearMonth(ctx, "晚查寝", y, m)
|
||||
marshal, _ := sonic.Marshal(month)
|
||||
t.Log(string(marshal))
|
||||
}
|
||||
@@ -10,8 +10,16 @@ import (
|
||||
"resty.dev/v3"
|
||||
)
|
||||
|
||||
var transport = &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
MinVersion: tls.VersionTLS10,
|
||||
},
|
||||
TLSHandshakeTimeout: 15 * time.Second,
|
||||
}
|
||||
|
||||
func init() {
|
||||
os.Setenv("GODEBUG", "tlsrsakex=1")
|
||||
_ = os.Setenv("GODEBUG", "tlsrsakex=1")
|
||||
}
|
||||
|
||||
var Cpdaily = resty.New().
|
||||
@@ -34,13 +42,6 @@ func init() {
|
||||
// NewCpdailyClient 创建一个全新的独立 client 实例,避免 Clone 可能的浅拷贝问题
|
||||
// 每个实例都是完全独立的,适用于并发场景,不会共享状态
|
||||
func NewCpdailyClient() *resty.Client {
|
||||
transport := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
MinVersion: tls.VersionTLS10,
|
||||
},
|
||||
TLSHandshakeTimeout: 15 * time.Second,
|
||||
}
|
||||
client := resty.New().
|
||||
SetCookieJar(nil).
|
||||
SetTimeout(30*time.Second).
|
||||
|
||||
@@ -62,44 +62,33 @@ type XueXiTCourse struct {
|
||||
CourseID string `json:"courseId"` // 课程ID
|
||||
ChatID string `json:"chatId"`
|
||||
CourseTeacher string `json:"courseTeacher"` // 课程老师
|
||||
CourseName string `json:"courseName"` //课程名
|
||||
CourseName string `json:"courseName"` // 课程名
|
||||
CourseImage string `json:"courseImage"`
|
||||
// 两个标识 暂时不知道有什么用
|
||||
CourseDataID int `json:"courseDataId"`
|
||||
ContentID int `json:"ContentID"`
|
||||
IsStart bool `json:"isstart"` //是否开课了,开课了为true,没开课为false。一般来说开课才能刷,不然刷不了的
|
||||
State int `json:"state"` //课程状态,0为正常,1为课程已经结束
|
||||
IsStart bool `json:"isstart"` // 是否开课了,开课了为true,没开课为false
|
||||
State int `json:"state"` // 课程状态,0为正常,1为课程已经结束
|
||||
}
|
||||
|
||||
// XueXiTCourseChapter 课程章节信息
|
||||
type XueXiTCourseChapter struct {
|
||||
ID string `json:"id"` // 章节ID
|
||||
ID int `json:"id"` // 章节ID
|
||||
Name string `json:"name"` // 章节名称
|
||||
ParentNodeID string `json:"parentnodeid"` // 父节点ID
|
||||
ParentNodeID int `json:"parentnodeid"` // 父节点ID
|
||||
Layer int `json:"layer"` // 层级
|
||||
Label string `json:"label"` // 标签
|
||||
IndexOrder int `json:"indexOrder"` // 排序索引
|
||||
JobCount int `json:"jobcount"` // 任务点数量
|
||||
Status int `json:"status"` // 状态
|
||||
Status string `json:"status"` // 状态
|
||||
IsReview int `json:"isReview"` // 是否复习
|
||||
BeginTime int64 `json:"begintime"` // 开始时间
|
||||
EndTime int64 `json:"endtime"` // 结束时间
|
||||
Attachment []XueXiTAttachment `json:"attachment"` // 附件列表
|
||||
PointTotal int `json:"pointTotal"` // 总任务点
|
||||
PointFinish int `json:"pointFinish"` // 已完成任务点
|
||||
Knowledge []XueXiTCourseChapter `json:"knowledge"` // 子章节列表
|
||||
}
|
||||
|
||||
// XueXiTAttachment 附件信息
|
||||
type XueXiTAttachment struct {
|
||||
ID string `json:"id"` // 附件ID
|
||||
Type string `json:"type"` // 附件类型(video/document等)
|
||||
ObjectID string `json:"objectid"` // 对象ID
|
||||
Extension string `json:"extension"` // 扩展信息
|
||||
JobID string `json:"jobid"` // 任务ID
|
||||
Property string `json:"property"` // 属性
|
||||
Name string `json:"name"` // 附件名称
|
||||
IsPassed bool `json:"isPassed"` // 是否已完成
|
||||
}
|
||||
|
||||
// ChapterData 章节数据响应
|
||||
type ChapterData struct {
|
||||
Data []struct {
|
||||
@@ -133,20 +122,7 @@ type ChapterData struct {
|
||||
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"`
|
||||
Data []KnowledgeData `json:"data"`
|
||||
} `json:"knowledge"`
|
||||
} `json:"data"`
|
||||
} `json:"course"`
|
||||
@@ -157,152 +133,15 @@ type ChapterData struct {
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
// Card 任务点卡片信息
|
||||
type Card struct {
|
||||
ID string `json:"id"` // 卡片ID
|
||||
Title string `json:"title"` // 标题
|
||||
Description string `json:"description"` // 描述
|
||||
KnowledgeID string `json:"knowledgeid"` // 知识点ID
|
||||
Type string `json:"type"` // 类型(video/document/work等)
|
||||
IsPassed bool `json:"isPassed"` // 是否完成
|
||||
ObjectID string `json:"objectid"` // 对象ID
|
||||
JobID string `json:"jobid"` // 任务ID
|
||||
ResourceID string `json:"resourceid"` // 资源ID
|
||||
Attachment *IframeAttributes `json:"attachment,omitempty"` // iframe属性
|
||||
}
|
||||
|
||||
// IframeAttributes iframe属性
|
||||
type IframeAttributes struct {
|
||||
Src string `json:"src"` // iframe地址
|
||||
Module string `json:"module"` // 模块名
|
||||
ModToken string `json:"modtoken"` // 模块token
|
||||
Width string `json:"width"` // 宽度
|
||||
Height string `json:"height"` // 高度
|
||||
Scrolling string `json:"scrolling"` // 滚动
|
||||
ClassID string `json:"classid"` // 课程ID
|
||||
ObjectID string `json:"objectid"` // 对象ID
|
||||
Enc string `json:"enc"` // 加密参数
|
||||
UtEnc string `json:"utenc"` // ut加密参数
|
||||
OtherInfo string `json:"otherinfo"` // 其他信息
|
||||
JobID string `json:"jobid"` // 任务ID
|
||||
KnowledgeID string `json:"knowledgeid"` // 知识点ID
|
||||
CourseFaceCheck int `json:"coursefacecheck"` // 人脸识别
|
||||
}
|
||||
|
||||
// DataItem 任务点数据项
|
||||
type DataItem struct {
|
||||
ID string `json:"id"`
|
||||
IndexOrder int `json:"indexorder"`
|
||||
KnowledgeID string `json:"knowledgeid"`
|
||||
Attachment struct {
|
||||
ObjectID string `json:"objectid"`
|
||||
Property struct {
|
||||
Name string `json:"name"`
|
||||
IsPassed bool `json:"ispassed"`
|
||||
JobID string `json:"jobid"`
|
||||
} `json:"property"`
|
||||
Type string `json:"type"`
|
||||
} `json:"attachment"`
|
||||
PointList []interface{} `json:"pointList"`
|
||||
JobCount int `json:"jobcount"`
|
||||
Duration int64 `json:"duration"`
|
||||
ClazzID string `json:"clazzid"`
|
||||
CourseID string `json:"courseid"`
|
||||
Module string `json:"module"`
|
||||
}
|
||||
|
||||
// VideoDto 视频信息
|
||||
type VideoDto struct {
|
||||
VideoPath string `json:"videoPath"` // 视频路径
|
||||
ObjectID string `json:"objectid"` // 对象ID
|
||||
OtherInfo string `json:"otherInfo"` // 其他信息
|
||||
JobID string `json:"jobid"` // 任务ID
|
||||
Duration int `json:"duration"` // 时长(秒)
|
||||
DToken string `json:"dtoken"` // dtoken
|
||||
IsAudio bool `json:"isAudio"` // 是否是音频
|
||||
IsPassed bool `json:"isPassed"` // 是否已完成
|
||||
}
|
||||
|
||||
// DocumentDto 文档信息
|
||||
type DocumentDto struct {
|
||||
ObjectID string `json:"objectid"` // 对象ID
|
||||
JobID string `json:"jobid"` // 任务ID
|
||||
OtherInfo string `json:"otherInfo"` // 其他信息
|
||||
JToken string `json:"jtoken"` // jtoken
|
||||
PageCount int `json:"pageCount"` // 页数
|
||||
IsPassed bool `json:"isPassed"` // 是否已完成
|
||||
}
|
||||
|
||||
// FaceQRCodeResponse 人脸识别二维码响应
|
||||
type FaceQRCodeResponse struct {
|
||||
Status bool `json:"status"`
|
||||
Msg string `json:"msg"`
|
||||
QR string `json:"qr"` // 二维码base64数据
|
||||
Enc string `json:"enc"` // 加密参数
|
||||
}
|
||||
|
||||
// FaceTokenResponse 人脸识别上传令牌响应
|
||||
type FaceTokenResponse struct {
|
||||
Result int `json:"result"`
|
||||
UploadToken string `json:"uploadtoken"`
|
||||
}
|
||||
|
||||
// FaceUploadResponse 人脸识别上传响应
|
||||
type FaceUploadResponse struct {
|
||||
Result bool `json:"result"`
|
||||
Msg string `json:"msg"`
|
||||
Data struct {
|
||||
FileID string `json:"fileId"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
// FaceVerifyResponse 人脸识别验证响应
|
||||
type FaceVerifyResponse struct {
|
||||
Status bool `json:"status"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
// WorkDto 作业信息
|
||||
type WorkDto struct {
|
||||
WorkID string `json:"workid"` // 作业ID
|
||||
CourseID string `json:"courseid"` // 课程ID
|
||||
ClassID string `json:"classid"` // 班级ID
|
||||
KnowledgeID string `json:"knowledgeid"` // 知识点ID
|
||||
JobID string `json:"jobid"` // 任务ID
|
||||
Enc string `json:"enc"` // 加密参数
|
||||
UTEnc string `json:"utenc"` // UT加密参数
|
||||
Title string `json:"title"` // 作业标题
|
||||
IsPassed bool `json:"isPassed"` // 是否已完成
|
||||
Questions []WorkQuestion `json:"questions"` // 题目列表
|
||||
}
|
||||
|
||||
// WorkQuestion 作业题目
|
||||
type WorkQuestion struct {
|
||||
QuestionID string `json:"questionId"` // 题目ID
|
||||
Type int `json:"type"` // 题目类型: 0单选 1多选 2判断 3填空 4简答
|
||||
Title string `json:"title"` // 题目标题
|
||||
Description string `json:"description"` // 题目描述
|
||||
Options []string `json:"options"` // 选项列表(单选/多选/判断)
|
||||
Answer string `json:"answer"` // 答案
|
||||
Score float64 `json:"score"` // 分值
|
||||
}
|
||||
|
||||
// WorkSubmitRequest 作业提交请求
|
||||
type WorkSubmitRequest struct {
|
||||
WorkID string `json:"workid"`
|
||||
TotalScore string `json:"totalScore"`
|
||||
AnswerList []WorkAnswerItem `json:"answerlist"`
|
||||
UserId string `json:"userId"`
|
||||
ClassId string `json:"classId"`
|
||||
CourseId string `json:"courseId"`
|
||||
KnowledgeId string `json:"knowledgeid"`
|
||||
JobId string `json:"jobid"`
|
||||
Enc string `json:"enc"`
|
||||
UTEnc string `json:"utenc"`
|
||||
}
|
||||
|
||||
// WorkAnswerItem 作业答案项
|
||||
type WorkAnswerItem struct {
|
||||
QuestionID string `json:"questionId"`
|
||||
Answer string `json:"answer"`
|
||||
// KnowledgeData 章节知识点数据
|
||||
type KnowledgeData struct {
|
||||
Jobcount int `json:"jobcount"`
|
||||
Isreview int `json:"isreview"`
|
||||
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"`
|
||||
}
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
package entity
|
||||
|
||||
// PointType 任务点类型
|
||||
type PointType string
|
||||
|
||||
const (
|
||||
PointTypeVideo PointType = "insertvideo"
|
||||
PointTypeDocument PointType = "insertdoc"
|
||||
PointTypeDocument2 PointType = "document"
|
||||
PointTypeBook PointType = "insertbook"
|
||||
PointTypeWork PointType = "insertwork"
|
||||
PointTypeHyperlink PointType = "insertlink"
|
||||
PointTypeLive PointType = "insertlive"
|
||||
)
|
||||
|
||||
// PointVideoDto 视频任务点
|
||||
type PointVideoDto struct {
|
||||
CardIndex int
|
||||
CourseID string
|
||||
ClassID string
|
||||
KnowledgeID int
|
||||
Cpi string
|
||||
ObjectID string
|
||||
// 从SSR视图中获取
|
||||
IsPassed bool
|
||||
FID int
|
||||
DToken string
|
||||
PlayTime int
|
||||
Duration int
|
||||
JobID string
|
||||
OtherInfo string
|
||||
Title string
|
||||
RT float64
|
||||
VideoFaceCaptureEnc string
|
||||
RandomCaptureTime string
|
||||
AttDurationEnc string
|
||||
Enc string
|
||||
Mid string
|
||||
}
|
||||
|
||||
// PointDocumentDto 文档查看任务点
|
||||
type PointDocumentDto struct {
|
||||
CardIndex int
|
||||
CourseID string
|
||||
ClassID string
|
||||
KnowledgeID int
|
||||
Cpi string
|
||||
ObjectID string
|
||||
Title string
|
||||
JobID string
|
||||
Jtoken string
|
||||
IsJob bool // 是否是任务点
|
||||
Type string // document / insertbook
|
||||
}
|
||||
|
||||
// PointWorkDto 测验/作业任务点
|
||||
type PointWorkDto struct {
|
||||
CardIndex int
|
||||
CourseID string
|
||||
ClassID string
|
||||
KnowledgeID int
|
||||
Cpi string
|
||||
WorkID string
|
||||
SchoolID string
|
||||
JobID string
|
||||
PUID string
|
||||
KToken string
|
||||
Enc string
|
||||
Title string
|
||||
IsPassed bool
|
||||
}
|
||||
|
||||
// PointHyperlinkDto 外链任务点
|
||||
type PointHyperlinkDto struct {
|
||||
CardIndex int
|
||||
CourseID string
|
||||
ClassID string
|
||||
KnowledgeID int
|
||||
Cpi string
|
||||
ObjectID string
|
||||
Title string
|
||||
JobID string
|
||||
Jtoken string
|
||||
LinkType int // 外链类型
|
||||
IsJob bool // 是否是任务点
|
||||
}
|
||||
|
||||
// PointLiveDto 直播任务点
|
||||
type PointLiveDto struct {
|
||||
CardIndex int
|
||||
CourseID string
|
||||
ClassID string
|
||||
KnowledgeID int
|
||||
Cpi string
|
||||
UserId string // 用户ID
|
||||
Live bool
|
||||
LiveId string // 直播ID
|
||||
Vdoid string
|
||||
Mid string
|
||||
Title string // 直播标题
|
||||
JobID string
|
||||
StreamName string // 直播流名称
|
||||
LiveStatusStr string // 直播状态文字
|
||||
LiveStatusCode int // 直播状态码 0=未开始
|
||||
VideoDuration int // 视频时长
|
||||
Aid string
|
||||
Module string // 类型
|
||||
IsJob bool // 是否为任务点
|
||||
AuthEnc string
|
||||
LiveDragEnc string
|
||||
LiveSetEnc string
|
||||
OtherInfo string
|
||||
Enc string
|
||||
LiveSwDsEnc string
|
||||
VideoCompletePercent float64 // 观看进度
|
||||
}
|
||||
|
||||
// Card 任务点卡片信息
|
||||
type Card struct {
|
||||
ID int `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
CardOrder int `json:"cardorder"`
|
||||
KnowledgeID int `json:"knowledgeid"`
|
||||
}
|
||||
|
||||
// CardAPIResponse 卡片API响应
|
||||
type CardAPIResponse struct {
|
||||
Data []CardDataItem `json:"data"`
|
||||
}
|
||||
|
||||
// CardDataItem 卡片数据项
|
||||
type CardDataItem struct {
|
||||
ClickCount int `json:"clickcount"`
|
||||
Createtime int64 `json:"createtime"`
|
||||
OpenLock int `json:"openlock"`
|
||||
IndexOrder int `json:"indexorder"`
|
||||
Name string `json:"name"`
|
||||
LastModifyTime int64 `json:"lastmodifytime"`
|
||||
ID int `json:"id"`
|
||||
Label string `json:"label"`
|
||||
Layer int `json:"layer"`
|
||||
Card struct {
|
||||
Data []Card `json:"data"`
|
||||
} `json:"card"`
|
||||
ParentNodeID int `json:"parentnodeid"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// IframeAttributes iframe 的属性
|
||||
type IframeAttributes struct {
|
||||
Data map[string]interface{} `json:"data"`
|
||||
Other map[string]string
|
||||
HasData bool
|
||||
}
|
||||
|
||||
// ChapterPointStatus 章节任务点状态
|
||||
type ChapterPointStatus map[string]struct {
|
||||
ClickCount int `json:"clickcount"`
|
||||
FinishCount int `json:"finishcount"`
|
||||
TotalCount int `json:"totalcount"`
|
||||
OpenLock int `json:"openlock"`
|
||||
UnFinishCount int `json:"unfinishcount"`
|
||||
}
|
||||
|
||||
// AttachmentSetting 附件设置(从页面JS中解析)
|
||||
type AttachmentSetting struct {
|
||||
Attachments []map[string]interface{} `json:"attachments"`
|
||||
Defaults map[string]interface{} `json:"defaults"`
|
||||
}
|
||||
|
||||
// ChapterPoints 章节所有任务点集合
|
||||
type ChapterPoints struct {
|
||||
Videos []PointVideoDto
|
||||
Documents []PointDocumentDto
|
||||
Works []PointWorkDto
|
||||
Hyperlinks []PointHyperlinkDto
|
||||
Lives []PointLiveDto
|
||||
}
|
||||
|
||||
// QuestionType 题目类型
|
||||
type QuestionType int
|
||||
|
||||
const (
|
||||
QuestionTypeSingleChoice QuestionType = 0 // 单选题
|
||||
QuestionTypeMultipleChoice QuestionType = 1 // 多选题
|
||||
QuestionTypeFillBlank QuestionType = 2 // 填空题
|
||||
QuestionTypeTrueFalse QuestionType = 3 // 判断题
|
||||
QuestionTypeShortAnswer QuestionType = 4 // 简答题
|
||||
)
|
||||
|
||||
// WorkQuestion 作业题目
|
||||
type WorkQuestion struct {
|
||||
Qid string `json:"qid"` // 题目ID
|
||||
Type QuestionType `json:"type"` // 题目类型
|
||||
Text string `json:"text"` // 题目内容
|
||||
Options map[string]string `json:"options"` // 选项 (A: xxx, B: xxx)
|
||||
Answers []string `json:"answers"` // 答案
|
||||
BlankCount int `json:"blankCount"` // 填空题空格数量
|
||||
BlankAnswer map[string]string `json:"blankAnswer"` // 填空题答案 (第1空: xxx)
|
||||
}
|
||||
|
||||
// WorkDto 作业详情
|
||||
type WorkDto struct {
|
||||
Title string `json:"title"` // 作业标题
|
||||
Cpi string `json:"cpi"` // cpi
|
||||
JobId string `json:"jobId"` // 任务ID
|
||||
WorkId string `json:"workId"` // 作业ID
|
||||
ClassId string `json:"classId"` // 班级ID
|
||||
CourseId string `json:"courseId"` // 课程ID
|
||||
KnowledgeId string `json:"knowledgeId"` // 知识点ID
|
||||
UserId string `json:"userId"` // 用户ID
|
||||
FullScore string `json:"fullScore"` // 满分
|
||||
OldWorkId string `json:"oldWorkId"` // 原始作业ID
|
||||
OldSchoolId string `json:"oldSchoolId"` // 原始学校ID
|
||||
Api string `json:"api"` // API值
|
||||
WorkRelationId string `json:"workRelationId"` // 作业关联ID
|
||||
EncWork string `json:"encWork"` // 加密参数
|
||||
WorkAnswerId string `json:"workAnswerId"` // 作业答案ID
|
||||
AnswerId string `json:"answerId"` // 答案ID
|
||||
TotalQuestionNum string `json:"totalQuestionNum"` // 题目总数
|
||||
Questions []WorkQuestion `json:"questions"` // 题目列表
|
||||
}
|
||||
@@ -9,10 +9,8 @@ import (
|
||||
"resty.dev/v3"
|
||||
)
|
||||
|
||||
var randChar []string = []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "A", "B", "C", "D", "E", "F"}
|
||||
|
||||
// ApiVerifyCodeBytes 获取学习通验证码图片
|
||||
func ApiVerifyCodeBytes(client *resty.Client) ([]byte, error) {
|
||||
|
||||
urlStr := "https://mooc1-api.chaoxing.com/processVerifyPng.ac?t=" + fmt.Sprintf("%d", time.Now().UnixMilli())
|
||||
|
||||
req := client.R()
|
||||
@@ -32,8 +30,9 @@ func ApiVerifyCodeBytes(client *resty.Client) ([]byte, error) {
|
||||
return all, nil
|
||||
}
|
||||
|
||||
func ApiPassVerifyCode(client *resty.Client, code string, retry int) bool {
|
||||
if retry < 0 {
|
||||
// ApiPassVerifyCode 提交学习通验证码
|
||||
func ApiPassVerifyCode(client *resty.Client, code string, retryCount int) bool {
|
||||
if retryCount < 0 {
|
||||
return false
|
||||
}
|
||||
urlStr := "https://mooc1-api.chaoxing.com/html/processVerify.ac"
|
||||
@@ -47,7 +46,7 @@ func ApiPassVerifyCode(client *resty.Client, code string, retry int) bool {
|
||||
req.Header.Add("Connection", "keep-alive")
|
||||
res, err := req.Post(urlStr)
|
||||
if err != nil {
|
||||
return ApiPassVerifyCode(client, code, retry-1)
|
||||
return ApiPassVerifyCode(client, code, retryCount-1)
|
||||
}
|
||||
client.SetRedirectPolicy(resty.FlexibleRedirectPolicy(20))
|
||||
return res.StatusCode() == 302
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,11 +2,27 @@ package xuexitong
|
||||
|
||||
import (
|
||||
"context"
|
||||
"likedream-goframe/internal/application/xuexitong/entity"
|
||||
"likedream-goframe/internal/framework/errors"
|
||||
"likedream-goframe/internal/utils"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSchedule(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
xuexitongLogin := NewXuexitongLogin(ctx)
|
||||
err := xuexitongLogin.Login(context.Background(), "13151832241", "yyz@083422", 5)
|
||||
utils.OkOrPanic(err)
|
||||
|
||||
client := xuexitongLogin.GetClient()
|
||||
courseService := NewXuexitongCourse(client)
|
||||
|
||||
// 人人必修的人工智能课
|
||||
err = courseService.AutoStudyByCourseID(ctx, "258109701")
|
||||
if err != nil {
|
||||
utils.OkOrPanic(errors.NewBusinessErrorWithDetail(503, "刷课失败", err))
|
||||
}
|
||||
}
|
||||
|
||||
func TestXuexitongLogin(t *testing.T) {
|
||||
xuexitongLogin := NewXuexitongLogin(context.Background())
|
||||
err := xuexitongLogin.Login(context.Background(), "13551503012", "xiaozhi520", 5)
|
||||
@@ -39,7 +55,7 @@ func TestPullChapter(t *testing.T) {
|
||||
}
|
||||
|
||||
// 获取第一个课程的章节
|
||||
chapters := courseAction.PullCourseChapterList(context.Background(), courseList[0].CourseID)
|
||||
chapters := courseAction.PullCourseChapterList(context.Background(), courseList[0])
|
||||
t.Logf("课程 %s 的章节数量: %d", courseList[0].CourseName, len(chapters))
|
||||
|
||||
for _, chapter := range chapters {
|
||||
@@ -64,147 +80,48 @@ func TestFetchChapterCards(t *testing.T) {
|
||||
course := courseList[0]
|
||||
|
||||
// 获取章节列表
|
||||
chapters := courseAction.PullCourseChapterList(context.Background(), course.CourseID)
|
||||
chapters := courseAction.PullCourseChapterList(context.Background(), course)
|
||||
if len(chapters) == 0 {
|
||||
t.Fatal("没有找到章节")
|
||||
}
|
||||
|
||||
// 找一个有任务点的章节
|
||||
var targetChapter *entity.XueXiTCourseChapter
|
||||
for i := range chapters {
|
||||
if chapters[i].JobCount > 0 {
|
||||
targetChapter = &chapters[i]
|
||||
var targetChapterID int
|
||||
for _, ch := range chapters {
|
||||
if ch.JobCount > 0 {
|
||||
targetChapterID = ch.ID
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if targetChapter == nil {
|
||||
if targetChapterID == 0 {
|
||||
t.Fatal("没有找到有任务点的章节")
|
||||
}
|
||||
|
||||
// 获取任务点卡片
|
||||
cards, err := courseAction.FetchChapterCards(context.Background(), course, targetChapter.ID, targetChapter.ID)
|
||||
cards, points, err := courseAction.FetchChapterCards(context.Background(), course, targetChapterID)
|
||||
utils.OkOrPanic(err)
|
||||
|
||||
t.Logf("章节 %s 的任务点数量: %d", targetChapter.Name, len(cards))
|
||||
t.Logf("卡片数量: %d", len(cards))
|
||||
if points != nil {
|
||||
t.Logf("视频数量: %d, 文档数量: %d, 作业数量: %d, 外链数量: %d, 直播数量: %d",
|
||||
len(points.Videos), len(points.Documents), len(points.Works),
|
||||
len(points.Hyperlinks), len(points.Lives))
|
||||
|
||||
for _, card := range cards {
|
||||
t.Logf("任务点: 类型=%s, JobID=%s, ObjectID=%s", card.Type, card.JobID, card.ObjectID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAutoPlayVideo(t *testing.T) {
|
||||
xuexitongLogin := NewXuexitongLogin(context.Background())
|
||||
err := xuexitongLogin.Login(context.Background(), "13551503012", "xiaozhi520", 5)
|
||||
utils.OkOrPanic(err)
|
||||
|
||||
client := xuexitongLogin.GetClient()
|
||||
courseAction := NewXuexitongCourse(client)
|
||||
|
||||
// 获取课程列表
|
||||
courseList := courseAction.PullCourseList(context.Background())
|
||||
if len(courseList) == 0 {
|
||||
t.Fatal("没有找到课程")
|
||||
}
|
||||
|
||||
course := courseList[0]
|
||||
|
||||
// 获取章节列表
|
||||
chapters := courseAction.PullCourseChapterList(context.Background(), course.CourseID)
|
||||
if len(chapters) == 0 {
|
||||
t.Fatal("没有找到章节")
|
||||
}
|
||||
|
||||
// 找一个有任务点的章节
|
||||
var targetChapter *entity.XueXiTCourseChapter
|
||||
for i := range chapters {
|
||||
if chapters[i].JobCount > 0 {
|
||||
targetChapter = &chapters[i]
|
||||
break
|
||||
for _, video := range points.Videos {
|
||||
t.Logf("视频任务点: JobID=%s, ObjectID=%s", video.JobID, video.ObjectID)
|
||||
}
|
||||
}
|
||||
|
||||
if targetChapter == nil {
|
||||
t.Fatal("没有找到有任务点的章节")
|
||||
}
|
||||
|
||||
// 获取任务点卡片
|
||||
cards, err := courseAction.FetchChapterCards(context.Background(), course, targetChapter.ID, targetChapter.ID)
|
||||
utils.OkOrPanic(err)
|
||||
|
||||
// 找视频任务点
|
||||
for _, card := range cards {
|
||||
if card.Type == "video" {
|
||||
t.Logf("开始处理视频任务点: %s", card.JobID)
|
||||
|
||||
// 获取视频信息
|
||||
videoDto, err := courseAction.FetchVideoDto(context.Background(), card.ObjectID, "", card.JobID)
|
||||
utils.OkOrPanic(err)
|
||||
|
||||
// 自动播放视频
|
||||
err = courseAction.AutoPlayVideo(context.Background(), course, card, videoDto)
|
||||
utils.OkOrPanic(err)
|
||||
|
||||
t.Logf("视频任务点完成: %s", card.JobID)
|
||||
break // 只测试一个视频
|
||||
for _, doc := range points.Documents {
|
||||
t.Logf("文档任务点: JobID=%s, Type=%s", doc.JobID, doc.Type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAutoReadDocument(t *testing.T) {
|
||||
xuexitongLogin := NewXuexitongLogin(context.Background())
|
||||
err := xuexitongLogin.Login(context.Background(), "13551503012", "xiaozhi520", 5)
|
||||
utils.OkOrPanic(err)
|
||||
|
||||
client := xuexitongLogin.GetClient()
|
||||
courseAction := NewXuexitongCourse(client)
|
||||
|
||||
// 获取课程列表
|
||||
courseList := courseAction.PullCourseList(context.Background())
|
||||
if len(courseList) == 0 {
|
||||
t.Fatal("没有找到课程")
|
||||
}
|
||||
|
||||
course := courseList[0]
|
||||
|
||||
// 获取章节列表
|
||||
chapters := courseAction.PullCourseChapterList(context.Background(), course.CourseID)
|
||||
if len(chapters) == 0 {
|
||||
t.Fatal("没有找到章节")
|
||||
}
|
||||
|
||||
// 找一个有任务点的章节
|
||||
var targetChapter *entity.XueXiTCourseChapter
|
||||
for i := range chapters {
|
||||
if chapters[i].JobCount > 0 {
|
||||
targetChapter = &chapters[i]
|
||||
break
|
||||
for _, work := range points.Works {
|
||||
t.Logf("作业任务点: JobID=%s, WorkID=%s", work.JobID, work.WorkID)
|
||||
}
|
||||
}
|
||||
|
||||
if targetChapter == nil {
|
||||
t.Fatal("没有找到有任务点的章节")
|
||||
}
|
||||
|
||||
// 获取任务点卡片
|
||||
cards, err := courseAction.FetchChapterCards(context.Background(), course, targetChapter.ID, targetChapter.ID)
|
||||
utils.OkOrPanic(err)
|
||||
|
||||
// 找文档任务点
|
||||
for _, card := range cards {
|
||||
if card.Type == "document" {
|
||||
t.Logf("开始处理文档任务点: %s", card.JobID)
|
||||
|
||||
// 获取文档信息
|
||||
documentDto, err := courseAction.FetchDocumentDto(context.Background(), card.ObjectID, "", card.JobID)
|
||||
utils.OkOrPanic(err)
|
||||
|
||||
// 自动阅读文档
|
||||
err = courseAction.AutoReadDocument(context.Background(), course, card, documentDto)
|
||||
utils.OkOrPanic(err)
|
||||
|
||||
t.Logf("文档任务点完成: %s", card.JobID)
|
||||
break // 只测试一个文档
|
||||
for _, link := range points.Hyperlinks {
|
||||
t.Logf("外链任务点: JobID=%s", link.JobID)
|
||||
}
|
||||
for _, live := range points.Lives {
|
||||
t.Logf("直播任务点: JobID=%s, LiveId=%s, Title=%s", live.JobID, live.LiveId, live.Title)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ package xuexitong
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
crand "crypto/rand"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -34,7 +34,7 @@ func GetUA(uaType string) string {
|
||||
|
||||
return strings.Join([]string{
|
||||
fmt.Sprintf("Mozilla/5.0 (Linux; %s; %s Build/OPM1.171019.019; wv)", ANDROID_VERSION, DEVICE_VENDOR),
|
||||
fmt.Sprintf("AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36"),
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36",
|
||||
fmt.Sprintf("(schild:%s)", MobileUASign(DEVICE_VENDOR, "zh_CN", APP_VERSION, BUILD, IMEI)),
|
||||
fmt.Sprintf("(device:%s)", DEVICE_VENDOR),
|
||||
"Language/zh_CN",
|
||||
@@ -48,15 +48,14 @@ func GetUA(uaType string) string {
|
||||
}
|
||||
}
|
||||
|
||||
// 用于生成IMEI
|
||||
func TokenHex(len int) string {
|
||||
b := make([]byte, 16)
|
||||
_, err := rand.Read(b)
|
||||
// TokenHex 用于生成IMEI
|
||||
func TokenHex(length int) string {
|
||||
b := make([]byte, length)
|
||||
_, err := crand.Read(b)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
token := hex.EncodeToString(b)
|
||||
return token
|
||||
return hex.EncodeToString(b)
|
||||
}
|
||||
|
||||
func MobileUASign(model, locale, version, build, imei string) string {
|
||||
|
||||
@@ -37,7 +37,9 @@ const (
|
||||
ConfigEmailFromName = "email.fromName"
|
||||
|
||||
// 基础积分配置
|
||||
ConfigBasePointCpdaily = "basePoint.cpdaily"
|
||||
ConfigBasePointCpdailyTask = "basePoint.cpdailyTask"
|
||||
ConfigBasePointCpdailyLeave = "basePoint.cpdailyLeave"
|
||||
ConfigBasePointCpdailyPhone = "basePoint.cpdailyPhone"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -3,4 +3,8 @@ package cst
|
||||
const (
|
||||
CtxUserInfo = "ctx_user_info"
|
||||
CtxPermissionList = "ctx_permission_list"
|
||||
|
||||
CtxCpdailyDeviceID = "cpdaily_device_id"
|
||||
CtxCpdailySessionToken = "cpdaily_session_token"
|
||||
CtxCpdailyTenantID = "cpdaily_tenant_id"
|
||||
)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package balance
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/service"
|
||||
"likedream-goframe/internal/utils"
|
||||
)
|
||||
|
||||
type BalanceCtrlV1 struct {
|
||||
}
|
||||
|
||||
func NewBalanceCtrlV1() IBalanceCtrlV1 {
|
||||
return &BalanceCtrlV1{}
|
||||
}
|
||||
|
||||
func (b BalanceCtrlV1) List(ctx context.Context, req *v1.BalanceRecordListReq) (res *utils.Response[[]*ent.SysBalanceRecord], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.Balance.List(ctx, req), nil
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package balance
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/utils"
|
||||
)
|
||||
|
||||
type IBalanceCtrlV1 interface {
|
||||
List(ctx context.Context, req *v1.BalanceRecordListReq) (res *utils.Response[[]*ent.SysBalanceRecord], err error)
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/service"
|
||||
"likedream-goframe/internal/utils"
|
||||
)
|
||||
|
||||
type ConfigCtrlV1 struct {
|
||||
}
|
||||
|
||||
func (c ConfigCtrlV1) Get(ctx context.Context, req *v1.ConfigGetReq) (res *utils.Response[*ent.SysConfig], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.Config.Get(ctx, req), nil
|
||||
}
|
||||
|
||||
func (c ConfigCtrlV1) PublicGet(ctx context.Context, req *v1.ConfigPublicGetReq) (res *utils.Response[*ent.SysConfig], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.Config.PublicGet(ctx, req), nil
|
||||
}
|
||||
|
||||
func (c ConfigCtrlV1) List(ctx context.Context, req *v1.ConfigListReq) (res *utils.Response[[]*ent.SysConfig], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.Config.List(ctx, req), nil
|
||||
}
|
||||
|
||||
func (c ConfigCtrlV1) Update(ctx context.Context, req *v1.ConfigUpdateReq) (res *utils.Response[any], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.Config.Update(ctx, req), nil
|
||||
}
|
||||
|
||||
func NewConfigCtrlV1() IConfigCtrlV1 {
|
||||
return &ConfigCtrlV1{}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/utils"
|
||||
)
|
||||
|
||||
type IConfigCtrlV1 interface {
|
||||
Get(ctx context.Context, req *v1.ConfigGetReq) (*utils.Response[*ent.SysConfig], error)
|
||||
PublicGet(ctx context.Context, req *v1.ConfigPublicGetReq) (*utils.Response[*ent.SysConfig], error)
|
||||
List(ctx context.Context, req *v1.ConfigListReq) (*utils.Response[[]*ent.SysConfig], error)
|
||||
Update(ctx context.Context, req *v1.ConfigUpdateReq) (*utils.Response[any], error)
|
||||
}
|
||||
@@ -4,8 +4,12 @@ import (
|
||||
"context"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/framework/captcha"
|
||||
"likedream-goframe/internal/framework/redis"
|
||||
"likedream-goframe/internal/service"
|
||||
"likedream-goframe/internal/utils"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
)
|
||||
|
||||
type CpUserCtrlV1 struct {
|
||||
@@ -68,10 +72,32 @@ func (c CpUserCtrlV1) AuthorizeRandom(ctx context.Context, req *v1.CpUserAuthori
|
||||
}
|
||||
func (c CpUserCtrlV1) LoginGetCode(ctx context.Context, req *v1.LoginGetCode) (res *utils.Response[any], err error) {
|
||||
defer utils.Pass(&err)
|
||||
client := redis.GetClient()
|
||||
dotsStr := client.GetDel(ctx, req.CaptchaKey).Val()
|
||||
if dotsStr == "" {
|
||||
return utils.Fail(10003, "验证码错误"), nil
|
||||
}
|
||||
var dots captcha.ConfirmData
|
||||
err = sonic.Unmarshal([]byte(dotsStr), &dots)
|
||||
utils.OkOrPanic(err)
|
||||
if !captcha.VerifyCaptcha(dots, req.Dots) {
|
||||
return utils.Fail(10003, "验证码错误"), nil
|
||||
}
|
||||
return service.Global.CpUser.LoginGetCode(ctx, req), nil
|
||||
}
|
||||
|
||||
func (c CpUserCtrlV1) AddByCode(ctx context.Context, req *v1.AddByCode) (res *utils.Response[any], err error) {
|
||||
defer utils.Pass(&err)
|
||||
client := redis.GetClient()
|
||||
dotsStr := client.GetDel(ctx, req.CaptchaKey).Val()
|
||||
if dotsStr == "" {
|
||||
return utils.Fail(10003, "验证码错误"), nil
|
||||
}
|
||||
var dots captcha.ConfirmData
|
||||
err = sonic.Unmarshal([]byte(dotsStr), &dots)
|
||||
utils.OkOrPanic(err)
|
||||
if !captcha.VerifyCaptcha(dots, req.Dots) {
|
||||
return utils.Fail(10003, "验证码错误"), nil
|
||||
}
|
||||
return service.Global.CpUser.AddByCode(ctx, req), nil
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/framework/captcha"
|
||||
"likedream-goframe/internal/framework/errors"
|
||||
"likedream-goframe/internal/framework/redis"
|
||||
"likedream-goframe/internal/service"
|
||||
"likedream-goframe/internal/utils"
|
||||
@@ -46,6 +47,7 @@ func (c *UserLoginV1) Login(ctx context.Context, req *v1.UserLoginReq) (res *uti
|
||||
if !captcha.VerifyCaptcha(dots, req.Dots) {
|
||||
return utils.Fail(10003, "验证码错误"), nil
|
||||
}
|
||||
|
||||
return service.Global.UserLogin.Login(ctx, req), nil
|
||||
}
|
||||
|
||||
@@ -62,6 +64,7 @@ func (c *UserLoginV1) Register(ctx context.Context, req *v1.UserRegisterReq) (re
|
||||
if !captcha.VerifyCaptcha(dots, req.Dots) {
|
||||
return utils.Fail(10003, "验证码错误"), nil
|
||||
}
|
||||
utils.OkOrPanic(errors.NewBusinessError(400, "注册功能暂时关闭,请等待重新开放"))
|
||||
return service.Global.UserLogin.Register(ctx, req), nil
|
||||
}
|
||||
|
||||
|
||||
+360
-34
@@ -19,7 +19,9 @@ import (
|
||||
"likedream-goframe/internal/ent/cptasklog"
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/ent/sysagent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysconfig"
|
||||
"likedream-goframe/internal/ent/sysmenu"
|
||||
"likedream-goframe/internal/ent/sysrole"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
@@ -55,8 +57,12 @@ type Client struct {
|
||||
CpUser *CpUserClient
|
||||
// SysAgent is the client for interacting with the SysAgent builders.
|
||||
SysAgent *SysAgentClient
|
||||
// SysBalanceRecord is the client for interacting with the SysBalanceRecord builders.
|
||||
SysBalanceRecord *SysBalanceRecordClient
|
||||
// SysCard is the client for interacting with the SysCard builders.
|
||||
SysCard *SysCardClient
|
||||
// SysConfig is the client for interacting with the SysConfig builders.
|
||||
SysConfig *SysConfigClient
|
||||
// SysMenu is the client for interacting with the SysMenu builders.
|
||||
SysMenu *SysMenuClient
|
||||
// SysRole is the client for interacting with the SysRole builders.
|
||||
@@ -84,7 +90,9 @@ func (c *Client) init() {
|
||||
c.CpTaskLog = NewCpTaskLogClient(c.config)
|
||||
c.CpUser = NewCpUserClient(c.config)
|
||||
c.SysAgent = NewSysAgentClient(c.config)
|
||||
c.SysBalanceRecord = NewSysBalanceRecordClient(c.config)
|
||||
c.SysCard = NewSysCardClient(c.config)
|
||||
c.SysConfig = NewSysConfigClient(c.config)
|
||||
c.SysMenu = NewSysMenuClient(c.config)
|
||||
c.SysRole = NewSysRoleClient(c.config)
|
||||
c.SysUser = NewSysUserClient(c.config)
|
||||
@@ -181,21 +189,23 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||
cfg := c.config
|
||||
cfg.driver = tx
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
CourseEntity: NewCourseEntityClient(cfg),
|
||||
CpImage: NewCpImageClient(cfg),
|
||||
CpLeave: NewCpLeaveClient(cfg),
|
||||
CpSchool: NewCpSchoolClient(cfg),
|
||||
CpTask: NewCpTaskClient(cfg),
|
||||
CpTaskLog: NewCpTaskLogClient(cfg),
|
||||
CpUser: NewCpUserClient(cfg),
|
||||
SysAgent: NewSysAgentClient(cfg),
|
||||
SysCard: NewSysCardClient(cfg),
|
||||
SysMenu: NewSysMenuClient(cfg),
|
||||
SysRole: NewSysRoleClient(cfg),
|
||||
SysUser: NewSysUserClient(cfg),
|
||||
SysUserLog: NewSysUserLogClient(cfg),
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
CourseEntity: NewCourseEntityClient(cfg),
|
||||
CpImage: NewCpImageClient(cfg),
|
||||
CpLeave: NewCpLeaveClient(cfg),
|
||||
CpSchool: NewCpSchoolClient(cfg),
|
||||
CpTask: NewCpTaskClient(cfg),
|
||||
CpTaskLog: NewCpTaskLogClient(cfg),
|
||||
CpUser: NewCpUserClient(cfg),
|
||||
SysAgent: NewSysAgentClient(cfg),
|
||||
SysBalanceRecord: NewSysBalanceRecordClient(cfg),
|
||||
SysCard: NewSysCardClient(cfg),
|
||||
SysConfig: NewSysConfigClient(cfg),
|
||||
SysMenu: NewSysMenuClient(cfg),
|
||||
SysRole: NewSysRoleClient(cfg),
|
||||
SysUser: NewSysUserClient(cfg),
|
||||
SysUserLog: NewSysUserLogClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -213,21 +223,23 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
cfg := c.config
|
||||
cfg.driver = &txDriver{tx: tx, drv: c.driver}
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
CourseEntity: NewCourseEntityClient(cfg),
|
||||
CpImage: NewCpImageClient(cfg),
|
||||
CpLeave: NewCpLeaveClient(cfg),
|
||||
CpSchool: NewCpSchoolClient(cfg),
|
||||
CpTask: NewCpTaskClient(cfg),
|
||||
CpTaskLog: NewCpTaskLogClient(cfg),
|
||||
CpUser: NewCpUserClient(cfg),
|
||||
SysAgent: NewSysAgentClient(cfg),
|
||||
SysCard: NewSysCardClient(cfg),
|
||||
SysMenu: NewSysMenuClient(cfg),
|
||||
SysRole: NewSysRoleClient(cfg),
|
||||
SysUser: NewSysUserClient(cfg),
|
||||
SysUserLog: NewSysUserLogClient(cfg),
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
CourseEntity: NewCourseEntityClient(cfg),
|
||||
CpImage: NewCpImageClient(cfg),
|
||||
CpLeave: NewCpLeaveClient(cfg),
|
||||
CpSchool: NewCpSchoolClient(cfg),
|
||||
CpTask: NewCpTaskClient(cfg),
|
||||
CpTaskLog: NewCpTaskLogClient(cfg),
|
||||
CpUser: NewCpUserClient(cfg),
|
||||
SysAgent: NewSysAgentClient(cfg),
|
||||
SysBalanceRecord: NewSysBalanceRecordClient(cfg),
|
||||
SysCard: NewSysCardClient(cfg),
|
||||
SysConfig: NewSysConfigClient(cfg),
|
||||
SysMenu: NewSysMenuClient(cfg),
|
||||
SysRole: NewSysRoleClient(cfg),
|
||||
SysUser: NewSysUserClient(cfg),
|
||||
SysUserLog: NewSysUserLogClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -258,7 +270,8 @@ func (c *Client) Close() error {
|
||||
func (c *Client) Use(hooks ...Hook) {
|
||||
for _, n := range []interface{ Use(...Hook) }{
|
||||
c.CourseEntity, c.CpImage, c.CpLeave, c.CpSchool, c.CpTask, c.CpTaskLog,
|
||||
c.CpUser, c.SysAgent, c.SysCard, c.SysMenu, c.SysRole, c.SysUser, c.SysUserLog,
|
||||
c.CpUser, c.SysAgent, c.SysBalanceRecord, c.SysCard, c.SysConfig, c.SysMenu,
|
||||
c.SysRole, c.SysUser, c.SysUserLog,
|
||||
} {
|
||||
n.Use(hooks...)
|
||||
}
|
||||
@@ -269,7 +282,8 @@ func (c *Client) Use(hooks ...Hook) {
|
||||
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||
for _, n := range []interface{ Intercept(...Interceptor) }{
|
||||
c.CourseEntity, c.CpImage, c.CpLeave, c.CpSchool, c.CpTask, c.CpTaskLog,
|
||||
c.CpUser, c.SysAgent, c.SysCard, c.SysMenu, c.SysRole, c.SysUser, c.SysUserLog,
|
||||
c.CpUser, c.SysAgent, c.SysBalanceRecord, c.SysCard, c.SysConfig, c.SysMenu,
|
||||
c.SysRole, c.SysUser, c.SysUserLog,
|
||||
} {
|
||||
n.Intercept(interceptors...)
|
||||
}
|
||||
@@ -294,8 +308,12 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
return c.CpUser.mutate(ctx, m)
|
||||
case *SysAgentMutation:
|
||||
return c.SysAgent.mutate(ctx, m)
|
||||
case *SysBalanceRecordMutation:
|
||||
return c.SysBalanceRecord.mutate(ctx, m)
|
||||
case *SysCardMutation:
|
||||
return c.SysCard.mutate(ctx, m)
|
||||
case *SysConfigMutation:
|
||||
return c.SysConfig.mutate(ctx, m)
|
||||
case *SysMenuMutation:
|
||||
return c.SysMenu.mutate(ctx, m)
|
||||
case *SysRoleMutation:
|
||||
@@ -1704,6 +1722,159 @@ func (c *SysAgentClient) mutate(ctx context.Context, m *SysAgentMutation) (Value
|
||||
}
|
||||
}
|
||||
|
||||
// SysBalanceRecordClient is a client for the SysBalanceRecord schema.
|
||||
type SysBalanceRecordClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewSysBalanceRecordClient returns a client for the SysBalanceRecord from the given config.
|
||||
func NewSysBalanceRecordClient(c config) *SysBalanceRecordClient {
|
||||
return &SysBalanceRecordClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `sysbalancerecord.Hooks(f(g(h())))`.
|
||||
func (c *SysBalanceRecordClient) Use(hooks ...Hook) {
|
||||
c.hooks.SysBalanceRecord = append(c.hooks.SysBalanceRecord, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `sysbalancerecord.Intercept(f(g(h())))`.
|
||||
func (c *SysBalanceRecordClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.SysBalanceRecord = append(c.inters.SysBalanceRecord, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a SysBalanceRecord entity.
|
||||
func (c *SysBalanceRecordClient) Create() *SysBalanceRecordCreate {
|
||||
mutation := newSysBalanceRecordMutation(c.config, OpCreate)
|
||||
return &SysBalanceRecordCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of SysBalanceRecord entities.
|
||||
func (c *SysBalanceRecordClient) CreateBulk(builders ...*SysBalanceRecordCreate) *SysBalanceRecordCreateBulk {
|
||||
return &SysBalanceRecordCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *SysBalanceRecordClient) MapCreateBulk(slice any, setFunc func(*SysBalanceRecordCreate, int)) *SysBalanceRecordCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &SysBalanceRecordCreateBulk{err: fmt.Errorf("calling to SysBalanceRecordClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*SysBalanceRecordCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &SysBalanceRecordCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for SysBalanceRecord.
|
||||
func (c *SysBalanceRecordClient) Update() *SysBalanceRecordUpdate {
|
||||
mutation := newSysBalanceRecordMutation(c.config, OpUpdate)
|
||||
return &SysBalanceRecordUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *SysBalanceRecordClient) UpdateOne(_m *SysBalanceRecord) *SysBalanceRecordUpdateOne {
|
||||
mutation := newSysBalanceRecordMutation(c.config, OpUpdateOne, withSysBalanceRecord(_m))
|
||||
return &SysBalanceRecordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *SysBalanceRecordClient) UpdateOneID(id int64) *SysBalanceRecordUpdateOne {
|
||||
mutation := newSysBalanceRecordMutation(c.config, OpUpdateOne, withSysBalanceRecordID(id))
|
||||
return &SysBalanceRecordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for SysBalanceRecord.
|
||||
func (c *SysBalanceRecordClient) Delete() *SysBalanceRecordDelete {
|
||||
mutation := newSysBalanceRecordMutation(c.config, OpDelete)
|
||||
return &SysBalanceRecordDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *SysBalanceRecordClient) DeleteOne(_m *SysBalanceRecord) *SysBalanceRecordDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *SysBalanceRecordClient) DeleteOneID(id int64) *SysBalanceRecordDeleteOne {
|
||||
builder := c.Delete().Where(sysbalancerecord.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &SysBalanceRecordDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for SysBalanceRecord.
|
||||
func (c *SysBalanceRecordClient) Query() *SysBalanceRecordQuery {
|
||||
return &SysBalanceRecordQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeSysBalanceRecord},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a SysBalanceRecord entity by its id.
|
||||
func (c *SysBalanceRecordClient) Get(ctx context.Context, id int64) (*SysBalanceRecord, error) {
|
||||
return c.Query().Where(sysbalancerecord.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *SysBalanceRecordClient) GetX(ctx context.Context, id int64) *SysBalanceRecord {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryUser queries the user edge of a SysBalanceRecord.
|
||||
func (c *SysBalanceRecordClient) QueryUser(_m *SysBalanceRecord) *SysUserQuery {
|
||||
query := (&SysUserClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(sysbalancerecord.Table, sysbalancerecord.FieldID, id),
|
||||
sqlgraph.To(sysuser.Table, sysuser.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, sysbalancerecord.UserTable, sysbalancerecord.UserColumn),
|
||||
)
|
||||
schemaConfig := _m.schemaConfig
|
||||
step.To.Schema = schemaConfig.SysUser
|
||||
step.Edge.Schema = schemaConfig.SysBalanceRecord
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *SysBalanceRecordClient) Hooks() []Hook {
|
||||
hooks := c.hooks.SysBalanceRecord
|
||||
return append(hooks[:len(hooks):len(hooks)], sysbalancerecord.Hooks[:]...)
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *SysBalanceRecordClient) Interceptors() []Interceptor {
|
||||
return c.inters.SysBalanceRecord
|
||||
}
|
||||
|
||||
func (c *SysBalanceRecordClient) mutate(ctx context.Context, m *SysBalanceRecordMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&SysBalanceRecordCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&SysBalanceRecordUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&SysBalanceRecordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&SysBalanceRecordDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown SysBalanceRecord mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// SysCardClient is a client for the SysCard schema.
|
||||
type SysCardClient struct {
|
||||
config
|
||||
@@ -1895,6 +2066,140 @@ func (c *SysCardClient) mutate(ctx context.Context, m *SysCardMutation) (Value,
|
||||
}
|
||||
}
|
||||
|
||||
// SysConfigClient is a client for the SysConfig schema.
|
||||
type SysConfigClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewSysConfigClient returns a client for the SysConfig from the given config.
|
||||
func NewSysConfigClient(c config) *SysConfigClient {
|
||||
return &SysConfigClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `sysconfig.Hooks(f(g(h())))`.
|
||||
func (c *SysConfigClient) Use(hooks ...Hook) {
|
||||
c.hooks.SysConfig = append(c.hooks.SysConfig, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `sysconfig.Intercept(f(g(h())))`.
|
||||
func (c *SysConfigClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.SysConfig = append(c.inters.SysConfig, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a SysConfig entity.
|
||||
func (c *SysConfigClient) Create() *SysConfigCreate {
|
||||
mutation := newSysConfigMutation(c.config, OpCreate)
|
||||
return &SysConfigCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of SysConfig entities.
|
||||
func (c *SysConfigClient) CreateBulk(builders ...*SysConfigCreate) *SysConfigCreateBulk {
|
||||
return &SysConfigCreateBulk{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 *SysConfigClient) MapCreateBulk(slice any, setFunc func(*SysConfigCreate, int)) *SysConfigCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &SysConfigCreateBulk{err: fmt.Errorf("calling to SysConfigClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*SysConfigCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &SysConfigCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for SysConfig.
|
||||
func (c *SysConfigClient) Update() *SysConfigUpdate {
|
||||
mutation := newSysConfigMutation(c.config, OpUpdate)
|
||||
return &SysConfigUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *SysConfigClient) UpdateOne(_m *SysConfig) *SysConfigUpdateOne {
|
||||
mutation := newSysConfigMutation(c.config, OpUpdateOne, withSysConfig(_m))
|
||||
return &SysConfigUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *SysConfigClient) UpdateOneID(id int64) *SysConfigUpdateOne {
|
||||
mutation := newSysConfigMutation(c.config, OpUpdateOne, withSysConfigID(id))
|
||||
return &SysConfigUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for SysConfig.
|
||||
func (c *SysConfigClient) Delete() *SysConfigDelete {
|
||||
mutation := newSysConfigMutation(c.config, OpDelete)
|
||||
return &SysConfigDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *SysConfigClient) DeleteOne(_m *SysConfig) *SysConfigDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *SysConfigClient) DeleteOneID(id int64) *SysConfigDeleteOne {
|
||||
builder := c.Delete().Where(sysconfig.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &SysConfigDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for SysConfig.
|
||||
func (c *SysConfigClient) Query() *SysConfigQuery {
|
||||
return &SysConfigQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeSysConfig},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a SysConfig entity by its id.
|
||||
func (c *SysConfigClient) Get(ctx context.Context, id int64) (*SysConfig, error) {
|
||||
return c.Query().Where(sysconfig.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *SysConfigClient) GetX(ctx context.Context, id int64) *SysConfig {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *SysConfigClient) Hooks() []Hook {
|
||||
hooks := c.hooks.SysConfig
|
||||
return append(hooks[:len(hooks):len(hooks)], sysconfig.Hooks[:]...)
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *SysConfigClient) Interceptors() []Interceptor {
|
||||
return c.inters.SysConfig
|
||||
}
|
||||
|
||||
func (c *SysConfigClient) mutate(ctx context.Context, m *SysConfigMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&SysConfigCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&SysConfigUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&SysConfigUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&SysConfigDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown SysConfig mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// SysMenuClient is a client for the SysMenu schema.
|
||||
type SysMenuClient struct {
|
||||
config
|
||||
@@ -2613,6 +2918,25 @@ func (c *SysUserClient) QueryCashbackCards(_m *SysUser) *SysCardQuery {
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryBalanceRecords queries the balance_records edge of a SysUser.
|
||||
func (c *SysUserClient) QueryBalanceRecords(_m *SysUser) *SysBalanceRecordQuery {
|
||||
query := (&SysBalanceRecordClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(sysuser.Table, sysuser.FieldID, id),
|
||||
sqlgraph.To(sysbalancerecord.Table, sysbalancerecord.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, sysuser.BalanceRecordsTable, sysuser.BalanceRecordsColumn),
|
||||
)
|
||||
schemaConfig := _m.schemaConfig
|
||||
step.To.Schema = schemaConfig.SysBalanceRecord
|
||||
step.Edge.Schema = schemaConfig.SysBalanceRecord
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *SysUserClient) Hooks() []Hook {
|
||||
hooks := c.hooks.SysUser
|
||||
@@ -2776,11 +3100,13 @@ func (c *SysUserLogClient) mutate(ctx context.Context, m *SysUserLogMutation) (V
|
||||
type (
|
||||
hooks struct {
|
||||
CourseEntity, CpImage, CpLeave, CpSchool, CpTask, CpTaskLog, CpUser, SysAgent,
|
||||
SysCard, SysMenu, SysRole, SysUser, SysUserLog []ent.Hook
|
||||
SysBalanceRecord, SysCard, SysConfig, SysMenu, SysRole, SysUser,
|
||||
SysUserLog []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
CourseEntity, CpImage, CpLeave, CpSchool, CpTask, CpTaskLog, CpUser, SysAgent,
|
||||
SysCard, SysMenu, SysRole, SysUser, SysUserLog []ent.Interceptor
|
||||
SysBalanceRecord, SysCard, SysConfig, SysMenu, SysRole, SysUser,
|
||||
SysUserLog []ent.Interceptor
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
+12
-1
@@ -39,6 +39,8 @@ type CpUser struct {
|
||||
Cookie string `json:"cookie,omitempty"`
|
||||
// MobileType holds the value of the "mobile_type" field.
|
||||
MobileType cpuser.MobileType `json:"mobile_type,omitempty"`
|
||||
// LoginType holds the value of the "login_type" field.
|
||||
LoginType cpuser.LoginType `json:"login_type,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the CpUserQuery when eager-loading is set.
|
||||
Edges CpUserEdges `json:"edges"`
|
||||
@@ -123,7 +125,7 @@ func (*CpUser) scanValues(columns []string) ([]any, error) {
|
||||
values[i] = new(ent2.CustomTime)
|
||||
case cpuser.FieldID, cpuser.FieldUserID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case cpuser.FieldUsername, cpuser.FieldPassword, cpuser.FieldSchoolID, cpuser.FieldEmail, cpuser.FieldMobileCode, cpuser.FieldCookie, cpuser.FieldMobileType:
|
||||
case cpuser.FieldUsername, cpuser.FieldPassword, cpuser.FieldSchoolID, cpuser.FieldEmail, cpuser.FieldMobileCode, cpuser.FieldCookie, cpuser.FieldMobileType, cpuser.FieldLoginType:
|
||||
values[i] = new(sql.NullString)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
@@ -206,6 +208,12 @@ func (_m *CpUser) assignValues(columns []string, values []any) error {
|
||||
} else if value.Valid {
|
||||
_m.MobileType = cpuser.MobileType(value.String)
|
||||
}
|
||||
case cpuser.FieldLoginType:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field login_type", values[i])
|
||||
} else if value.Valid {
|
||||
_m.LoginType = cpuser.LoginType(value.String)
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
@@ -296,6 +304,9 @@ func (_m *CpUser) String() string {
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("mobile_type=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.MobileType))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("login_type=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.LoginType))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ const (
|
||||
FieldCookie = "cookie"
|
||||
// FieldMobileType holds the string denoting the mobile_type field in the database.
|
||||
FieldMobileType = "mobile_type"
|
||||
// FieldLoginType holds the string denoting the login_type field in the database.
|
||||
FieldLoginType = "login_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.
|
||||
@@ -98,6 +100,7 @@ var Columns = []string{
|
||||
FieldMobileCode,
|
||||
FieldCookie,
|
||||
FieldMobileType,
|
||||
FieldLoginType,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
@@ -123,8 +126,6 @@ var (
|
||||
DefaultUpdateTime func() *ent2.CustomTime
|
||||
// UsernameValidator is a validator for the "username" field. It is called by the builders before save.
|
||||
UsernameValidator func(string) error
|
||||
// PasswordValidator is a validator for the "password" field. It is called by the builders before save.
|
||||
PasswordValidator func(string) error
|
||||
// SchoolIDValidator is a validator for the "school_id" field. It is called by the builders before save.
|
||||
SchoolIDValidator func(string) error
|
||||
)
|
||||
@@ -152,6 +153,32 @@ func MobileTypeValidator(mt MobileType) error {
|
||||
}
|
||||
}
|
||||
|
||||
// LoginType defines the type for the "login_type" enum field.
|
||||
type LoginType string
|
||||
|
||||
// LoginTypeAccount is the default value of the LoginType enum.
|
||||
const DefaultLoginType = LoginTypeAccount
|
||||
|
||||
// LoginType values.
|
||||
const (
|
||||
LoginTypeAccount LoginType = "account"
|
||||
LoginTypePhone LoginType = "phone"
|
||||
)
|
||||
|
||||
func (lt LoginType) String() string {
|
||||
return string(lt)
|
||||
}
|
||||
|
||||
// LoginTypeValidator is a validator for the "login_type" field enum values. It is called by the builders before save.
|
||||
func LoginTypeValidator(lt LoginType) error {
|
||||
switch lt {
|
||||
case LoginTypeAccount, LoginTypePhone:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("cpuser: invalid enum value for login_type field: %q", lt)
|
||||
}
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the CpUser queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
@@ -210,6 +237,11 @@ func ByMobileType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldMobileType, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByLoginType orders the results by the login_type field.
|
||||
func ByLoginType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldLoginType, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCptasksCount orders the results by cptasks count.
|
||||
func ByCptasksCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
|
||||
@@ -381,6 +381,16 @@ func PasswordHasSuffix(v string) predicate.CpUser {
|
||||
return predicate.CpUser(sql.FieldHasSuffix(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordIsNil applies the IsNil predicate on the "password" field.
|
||||
func PasswordIsNil() predicate.CpUser {
|
||||
return predicate.CpUser(sql.FieldIsNull(FieldPassword))
|
||||
}
|
||||
|
||||
// PasswordNotNil applies the NotNil predicate on the "password" field.
|
||||
func PasswordNotNil() predicate.CpUser {
|
||||
return predicate.CpUser(sql.FieldNotNull(FieldPassword))
|
||||
}
|
||||
|
||||
// PasswordEqualFold applies the EqualFold predicate on the "password" field.
|
||||
func PasswordEqualFold(v string) predicate.CpUser {
|
||||
return predicate.CpUser(sql.FieldEqualFold(FieldPassword, v))
|
||||
@@ -701,6 +711,26 @@ func MobileTypeNotIn(vs ...MobileType) predicate.CpUser {
|
||||
return predicate.CpUser(sql.FieldNotIn(FieldMobileType, vs...))
|
||||
}
|
||||
|
||||
// LoginTypeEQ applies the EQ predicate on the "login_type" field.
|
||||
func LoginTypeEQ(v LoginType) predicate.CpUser {
|
||||
return predicate.CpUser(sql.FieldEQ(FieldLoginType, v))
|
||||
}
|
||||
|
||||
// LoginTypeNEQ applies the NEQ predicate on the "login_type" field.
|
||||
func LoginTypeNEQ(v LoginType) predicate.CpUser {
|
||||
return predicate.CpUser(sql.FieldNEQ(FieldLoginType, v))
|
||||
}
|
||||
|
||||
// LoginTypeIn applies the In predicate on the "login_type" field.
|
||||
func LoginTypeIn(vs ...LoginType) predicate.CpUser {
|
||||
return predicate.CpUser(sql.FieldIn(FieldLoginType, vs...))
|
||||
}
|
||||
|
||||
// LoginTypeNotIn applies the NotIn predicate on the "login_type" field.
|
||||
func LoginTypeNotIn(vs ...LoginType) predicate.CpUser {
|
||||
return predicate.CpUser(sql.FieldNotIn(FieldLoginType, vs...))
|
||||
}
|
||||
|
||||
// HasCptasks applies the HasEdge predicate on the "cptasks" edge.
|
||||
func HasCptasks() predicate.CpUser {
|
||||
return predicate.CpUser(func(s *sql.Selector) {
|
||||
|
||||
@@ -57,6 +57,14 @@ func (_c *CpUserCreate) SetPassword(v string) *CpUserCreate {
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillablePassword sets the "password" field if the given value is not nil.
|
||||
func (_c *CpUserCreate) SetNillablePassword(v *string) *CpUserCreate {
|
||||
if v != nil {
|
||||
_c.SetPassword(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetSchoolID sets the "school_id" field.
|
||||
func (_c *CpUserCreate) SetSchoolID(v string) *CpUserCreate {
|
||||
_c.mutation.SetSchoolID(v)
|
||||
@@ -111,6 +119,20 @@ func (_c *CpUserCreate) SetMobileType(v cpuser.MobileType) *CpUserCreate {
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetLoginType sets the "login_type" field.
|
||||
func (_c *CpUserCreate) SetLoginType(v cpuser.LoginType) *CpUserCreate {
|
||||
_c.mutation.SetLoginType(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableLoginType sets the "login_type" field if the given value is not nil.
|
||||
func (_c *CpUserCreate) SetNillableLoginType(v *cpuser.LoginType) *CpUserCreate {
|
||||
if v != nil {
|
||||
_c.SetLoginType(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddCptaskIDs adds the "cptasks" edge to the CpTask entity by IDs.
|
||||
func (_c *CpUserCreate) AddCptaskIDs(ids ...int64) *CpUserCreate {
|
||||
_c.mutation.AddCptaskIDs(ids...)
|
||||
@@ -223,6 +245,10 @@ func (_c *CpUserCreate) defaults() error {
|
||||
v := cpuser.DefaultUpdateTime()
|
||||
_c.mutation.SetUpdateTime(v)
|
||||
}
|
||||
if _, ok := _c.mutation.LoginType(); !ok {
|
||||
v := cpuser.DefaultLoginType
|
||||
_c.mutation.SetLoginType(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -245,14 +271,6 @@ func (_c *CpUserCreate) check() error {
|
||||
return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "CpUser.username": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.Password(); !ok {
|
||||
return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "CpUser.password"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.Password(); ok {
|
||||
if err := cpuser.PasswordValidator(v); err != nil {
|
||||
return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "CpUser.password": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.SchoolID(); !ok {
|
||||
return &ValidationError{Name: "school_id", err: errors.New(`ent: missing required field "CpUser.school_id"`)}
|
||||
}
|
||||
@@ -269,6 +287,14 @@ func (_c *CpUserCreate) check() error {
|
||||
return &ValidationError{Name: "mobile_type", err: fmt.Errorf(`ent: validator failed for field "CpUser.mobile_type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.LoginType(); !ok {
|
||||
return &ValidationError{Name: "login_type", err: errors.New(`ent: missing required field "CpUser.login_type"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.LoginType(); ok {
|
||||
if err := cpuser.LoginTypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "login_type", err: fmt.Errorf(`ent: validator failed for field "CpUser.login_type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if len(_c.mutation.SysuserIDs()) == 0 {
|
||||
return &ValidationError{Name: "sysuser", err: errors.New(`ent: missing required edge "CpUser.sysuser"`)}
|
||||
}
|
||||
@@ -335,6 +361,10 @@ func (_c *CpUserCreate) createSpec() (*CpUser, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(cpuser.FieldMobileType, field.TypeEnum, value)
|
||||
_node.MobileType = value
|
||||
}
|
||||
if value, ok := _c.mutation.LoginType(); ok {
|
||||
_spec.SetField(cpuser.FieldLoginType, field.TypeEnum, value)
|
||||
_node.LoginType = value
|
||||
}
|
||||
if nodes := _c.mutation.CptasksIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
@@ -522,6 +552,12 @@ func (u *CpUserUpsert) UpdatePassword() *CpUserUpsert {
|
||||
return u
|
||||
}
|
||||
|
||||
// ClearPassword clears the value of the "password" field.
|
||||
func (u *CpUserUpsert) ClearPassword() *CpUserUpsert {
|
||||
u.SetNull(cpuser.FieldPassword)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetSchoolID sets the "school_id" field.
|
||||
func (u *CpUserUpsert) SetSchoolID(v string) *CpUserUpsert {
|
||||
u.Set(cpuser.FieldSchoolID, v)
|
||||
@@ -600,6 +636,18 @@ func (u *CpUserUpsert) UpdateMobileType() *CpUserUpsert {
|
||||
return u
|
||||
}
|
||||
|
||||
// SetLoginType sets the "login_type" field.
|
||||
func (u *CpUserUpsert) SetLoginType(v cpuser.LoginType) *CpUserUpsert {
|
||||
u.Set(cpuser.FieldLoginType, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateLoginType sets the "login_type" field to the value that was provided on create.
|
||||
func (u *CpUserUpsert) UpdateLoginType() *CpUserUpsert {
|
||||
u.SetExcluded(cpuser.FieldLoginType)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
@@ -701,6 +749,13 @@ func (u *CpUserUpsertOne) UpdatePassword() *CpUserUpsertOne {
|
||||
})
|
||||
}
|
||||
|
||||
// ClearPassword clears the value of the "password" field.
|
||||
func (u *CpUserUpsertOne) ClearPassword() *CpUserUpsertOne {
|
||||
return u.Update(func(s *CpUserUpsert) {
|
||||
s.ClearPassword()
|
||||
})
|
||||
}
|
||||
|
||||
// SetSchoolID sets the "school_id" field.
|
||||
func (u *CpUserUpsertOne) SetSchoolID(v string) *CpUserUpsertOne {
|
||||
return u.Update(func(s *CpUserUpsert) {
|
||||
@@ -792,6 +847,20 @@ func (u *CpUserUpsertOne) UpdateMobileType() *CpUserUpsertOne {
|
||||
})
|
||||
}
|
||||
|
||||
// SetLoginType sets the "login_type" field.
|
||||
func (u *CpUserUpsertOne) SetLoginType(v cpuser.LoginType) *CpUserUpsertOne {
|
||||
return u.Update(func(s *CpUserUpsert) {
|
||||
s.SetLoginType(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateLoginType sets the "login_type" field to the value that was provided on create.
|
||||
func (u *CpUserUpsertOne) UpdateLoginType() *CpUserUpsertOne {
|
||||
return u.Update(func(s *CpUserUpsert) {
|
||||
s.UpdateLoginType()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *CpUserUpsertOne) Exec(ctx context.Context) error {
|
||||
if len(u.create.conflict) == 0 {
|
||||
@@ -1059,6 +1128,13 @@ func (u *CpUserUpsertBulk) UpdatePassword() *CpUserUpsertBulk {
|
||||
})
|
||||
}
|
||||
|
||||
// ClearPassword clears the value of the "password" field.
|
||||
func (u *CpUserUpsertBulk) ClearPassword() *CpUserUpsertBulk {
|
||||
return u.Update(func(s *CpUserUpsert) {
|
||||
s.ClearPassword()
|
||||
})
|
||||
}
|
||||
|
||||
// SetSchoolID sets the "school_id" field.
|
||||
func (u *CpUserUpsertBulk) SetSchoolID(v string) *CpUserUpsertBulk {
|
||||
return u.Update(func(s *CpUserUpsert) {
|
||||
@@ -1150,6 +1226,20 @@ func (u *CpUserUpsertBulk) UpdateMobileType() *CpUserUpsertBulk {
|
||||
})
|
||||
}
|
||||
|
||||
// SetLoginType sets the "login_type" field.
|
||||
func (u *CpUserUpsertBulk) SetLoginType(v cpuser.LoginType) *CpUserUpsertBulk {
|
||||
return u.Update(func(s *CpUserUpsert) {
|
||||
s.SetLoginType(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateLoginType sets the "login_type" field to the value that was provided on create.
|
||||
func (u *CpUserUpsertBulk) UpdateLoginType() *CpUserUpsertBulk {
|
||||
return u.Update(func(s *CpUserUpsert) {
|
||||
s.UpdateLoginType()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *CpUserUpsertBulk) Exec(ctx context.Context) error {
|
||||
if u.create.err != nil {
|
||||
|
||||
@@ -83,6 +83,12 @@ func (_u *CpUserUpdate) SetNillablePassword(v *string) *CpUserUpdate {
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearPassword clears the value of the "password" field.
|
||||
func (_u *CpUserUpdate) ClearPassword() *CpUserUpdate {
|
||||
_u.mutation.ClearPassword()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetSchoolID sets the "school_id" field.
|
||||
func (_u *CpUserUpdate) SetSchoolID(v string) *CpUserUpdate {
|
||||
_u.mutation.SetSchoolID(v)
|
||||
@@ -171,6 +177,20 @@ func (_u *CpUserUpdate) SetNillableMobileType(v *cpuser.MobileType) *CpUserUpdat
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetLoginType sets the "login_type" field.
|
||||
func (_u *CpUserUpdate) SetLoginType(v cpuser.LoginType) *CpUserUpdate {
|
||||
_u.mutation.SetLoginType(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableLoginType sets the "login_type" field if the given value is not nil.
|
||||
func (_u *CpUserUpdate) SetNillableLoginType(v *cpuser.LoginType) *CpUserUpdate {
|
||||
if v != nil {
|
||||
_u.SetLoginType(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddCptaskIDs adds the "cptasks" edge to the CpTask entity by IDs.
|
||||
func (_u *CpUserUpdate) AddCptaskIDs(ids ...int64) *CpUserUpdate {
|
||||
_u.mutation.AddCptaskIDs(ids...)
|
||||
@@ -346,11 +366,6 @@ func (_u *CpUserUpdate) check() error {
|
||||
return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "CpUser.username": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Password(); ok {
|
||||
if err := cpuser.PasswordValidator(v); err != nil {
|
||||
return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "CpUser.password": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.SchoolID(); ok {
|
||||
if err := cpuser.SchoolIDValidator(v); err != nil {
|
||||
return &ValidationError{Name: "school_id", err: fmt.Errorf(`ent: validator failed for field "CpUser.school_id": %w`, err)}
|
||||
@@ -361,6 +376,11 @@ func (_u *CpUserUpdate) check() error {
|
||||
return &ValidationError{Name: "mobile_type", err: fmt.Errorf(`ent: validator failed for field "CpUser.mobile_type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.LoginType(); ok {
|
||||
if err := cpuser.LoginTypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "login_type", err: fmt.Errorf(`ent: validator failed for field "CpUser.login_type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _u.mutation.SysuserCleared() && len(_u.mutation.SysuserIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "CpUser.sysuser"`)
|
||||
}
|
||||
@@ -397,6 +417,9 @@ func (_u *CpUserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if value, ok := _u.mutation.Password(); ok {
|
||||
_spec.SetField(cpuser.FieldPassword, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.PasswordCleared() {
|
||||
_spec.ClearField(cpuser.FieldPassword, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Email(); ok {
|
||||
_spec.SetField(cpuser.FieldEmail, field.TypeString, value)
|
||||
}
|
||||
@@ -418,6 +441,9 @@ func (_u *CpUserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if value, ok := _u.mutation.MobileType(); ok {
|
||||
_spec.SetField(cpuser.FieldMobileType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.LoginType(); ok {
|
||||
_spec.SetField(cpuser.FieldLoginType, field.TypeEnum, value)
|
||||
}
|
||||
if _u.mutation.CptasksCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
@@ -696,6 +722,12 @@ func (_u *CpUserUpdateOne) SetNillablePassword(v *string) *CpUserUpdateOne {
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearPassword clears the value of the "password" field.
|
||||
func (_u *CpUserUpdateOne) ClearPassword() *CpUserUpdateOne {
|
||||
_u.mutation.ClearPassword()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetSchoolID sets the "school_id" field.
|
||||
func (_u *CpUserUpdateOne) SetSchoolID(v string) *CpUserUpdateOne {
|
||||
_u.mutation.SetSchoolID(v)
|
||||
@@ -784,6 +816,20 @@ func (_u *CpUserUpdateOne) SetNillableMobileType(v *cpuser.MobileType) *CpUserUp
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetLoginType sets the "login_type" field.
|
||||
func (_u *CpUserUpdateOne) SetLoginType(v cpuser.LoginType) *CpUserUpdateOne {
|
||||
_u.mutation.SetLoginType(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableLoginType sets the "login_type" field if the given value is not nil.
|
||||
func (_u *CpUserUpdateOne) SetNillableLoginType(v *cpuser.LoginType) *CpUserUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetLoginType(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddCptaskIDs adds the "cptasks" edge to the CpTask entity by IDs.
|
||||
func (_u *CpUserUpdateOne) AddCptaskIDs(ids ...int64) *CpUserUpdateOne {
|
||||
_u.mutation.AddCptaskIDs(ids...)
|
||||
@@ -972,11 +1018,6 @@ func (_u *CpUserUpdateOne) check() error {
|
||||
return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "CpUser.username": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Password(); ok {
|
||||
if err := cpuser.PasswordValidator(v); err != nil {
|
||||
return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "CpUser.password": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.SchoolID(); ok {
|
||||
if err := cpuser.SchoolIDValidator(v); err != nil {
|
||||
return &ValidationError{Name: "school_id", err: fmt.Errorf(`ent: validator failed for field "CpUser.school_id": %w`, err)}
|
||||
@@ -987,6 +1028,11 @@ func (_u *CpUserUpdateOne) check() error {
|
||||
return &ValidationError{Name: "mobile_type", err: fmt.Errorf(`ent: validator failed for field "CpUser.mobile_type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.LoginType(); ok {
|
||||
if err := cpuser.LoginTypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "login_type", err: fmt.Errorf(`ent: validator failed for field "CpUser.login_type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _u.mutation.SysuserCleared() && len(_u.mutation.SysuserIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "CpUser.sysuser"`)
|
||||
}
|
||||
@@ -1040,6 +1086,9 @@ func (_u *CpUserUpdateOne) sqlSave(ctx context.Context) (_node *CpUser, err erro
|
||||
if value, ok := _u.mutation.Password(); ok {
|
||||
_spec.SetField(cpuser.FieldPassword, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.PasswordCleared() {
|
||||
_spec.ClearField(cpuser.FieldPassword, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Email(); ok {
|
||||
_spec.SetField(cpuser.FieldEmail, field.TypeString, value)
|
||||
}
|
||||
@@ -1061,6 +1110,9 @@ func (_u *CpUserUpdateOne) sqlSave(ctx context.Context) (_node *CpUser, err erro
|
||||
if value, ok := _u.mutation.MobileType(); ok {
|
||||
_spec.SetField(cpuser.FieldMobileType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.LoginType(); ok {
|
||||
_spec.SetField(cpuser.FieldLoginType, field.TypeEnum, value)
|
||||
}
|
||||
if _u.mutation.CptasksCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
|
||||
+17
-13
@@ -14,7 +14,9 @@ import (
|
||||
"likedream-goframe/internal/ent/cptasklog"
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/ent/sysagent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysconfig"
|
||||
"likedream-goframe/internal/ent/sysmenu"
|
||||
"likedream-goframe/internal/ent/sysrole"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
@@ -85,19 +87,21 @@ var (
|
||||
func checkColumn(t, c string) error {
|
||||
initCheck.Do(func() {
|
||||
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||
courseentity.Table: courseentity.ValidColumn,
|
||||
cpimage.Table: cpimage.ValidColumn,
|
||||
cpleave.Table: cpleave.ValidColumn,
|
||||
cpschool.Table: cpschool.ValidColumn,
|
||||
cptask.Table: cptask.ValidColumn,
|
||||
cptasklog.Table: cptasklog.ValidColumn,
|
||||
cpuser.Table: cpuser.ValidColumn,
|
||||
sysagent.Table: sysagent.ValidColumn,
|
||||
syscard.Table: syscard.ValidColumn,
|
||||
sysmenu.Table: sysmenu.ValidColumn,
|
||||
sysrole.Table: sysrole.ValidColumn,
|
||||
sysuser.Table: sysuser.ValidColumn,
|
||||
sysuserlog.Table: sysuserlog.ValidColumn,
|
||||
courseentity.Table: courseentity.ValidColumn,
|
||||
cpimage.Table: cpimage.ValidColumn,
|
||||
cpleave.Table: cpleave.ValidColumn,
|
||||
cpschool.Table: cpschool.ValidColumn,
|
||||
cptask.Table: cptask.ValidColumn,
|
||||
cptasklog.Table: cptasklog.ValidColumn,
|
||||
cpuser.Table: cpuser.ValidColumn,
|
||||
sysagent.Table: sysagent.ValidColumn,
|
||||
sysbalancerecord.Table: sysbalancerecord.ValidColumn,
|
||||
syscard.Table: syscard.ValidColumn,
|
||||
sysconfig.Table: sysconfig.ValidColumn,
|
||||
sysmenu.Table: sysmenu.ValidColumn,
|
||||
sysrole.Table: sysrole.ValidColumn,
|
||||
sysuser.Table: sysuser.ValidColumn,
|
||||
sysuserlog.Table: sysuserlog.ValidColumn,
|
||||
})
|
||||
})
|
||||
return columnCheck(t, c)
|
||||
|
||||
+260
-10
@@ -12,7 +12,9 @@ import (
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysagent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysconfig"
|
||||
"likedream-goframe/internal/ent/sysmenu"
|
||||
"likedream-goframe/internal/ent/sysrole"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
@@ -26,7 +28,7 @@ import (
|
||||
|
||||
// schemaGraph holds a representation of ent/schema at runtime.
|
||||
var schemaGraph = func() *sqlgraph.Schema {
|
||||
graph := &sqlgraph.Schema{Nodes: make([]*sqlgraph.Node, 13)}
|
||||
graph := &sqlgraph.Schema{Nodes: make([]*sqlgraph.Node, 15)}
|
||||
graph.Nodes[0] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: courseentity.Table,
|
||||
@@ -188,6 +190,7 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
cpuser.FieldMobileCode: {Type: field.TypeString, Column: cpuser.FieldMobileCode},
|
||||
cpuser.FieldCookie: {Type: field.TypeString, Column: cpuser.FieldCookie},
|
||||
cpuser.FieldMobileType: {Type: field.TypeEnum, Column: cpuser.FieldMobileType},
|
||||
cpuser.FieldLoginType: {Type: field.TypeEnum, Column: cpuser.FieldLoginType},
|
||||
},
|
||||
}
|
||||
graph.Nodes[7] = &sqlgraph.Node{
|
||||
@@ -208,6 +211,27 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
},
|
||||
}
|
||||
graph.Nodes[8] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: sysbalancerecord.Table,
|
||||
Columns: sysbalancerecord.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Column: sysbalancerecord.FieldID,
|
||||
},
|
||||
},
|
||||
Type: "SysBalanceRecord",
|
||||
Fields: map[string]*sqlgraph.FieldSpec{
|
||||
sysbalancerecord.FieldCreateTime: {Type: field.TypeString, Column: sysbalancerecord.FieldCreateTime},
|
||||
sysbalancerecord.FieldUpdateTime: {Type: field.TypeString, Column: sysbalancerecord.FieldUpdateTime},
|
||||
sysbalancerecord.FieldUserID: {Type: field.TypeInt64, Column: sysbalancerecord.FieldUserID},
|
||||
sysbalancerecord.FieldType: {Type: field.TypeEnum, Column: sysbalancerecord.FieldType},
|
||||
sysbalancerecord.FieldAmount: {Type: field.TypeString, Column: sysbalancerecord.FieldAmount},
|
||||
sysbalancerecord.FieldReason: {Type: field.TypeString, Column: sysbalancerecord.FieldReason},
|
||||
sysbalancerecord.FieldBalanceBefore: {Type: field.TypeString, Column: sysbalancerecord.FieldBalanceBefore},
|
||||
sysbalancerecord.FieldBalanceAfter: {Type: field.TypeString, Column: sysbalancerecord.FieldBalanceAfter},
|
||||
},
|
||||
}
|
||||
graph.Nodes[9] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: syscard.Table,
|
||||
Columns: syscard.Columns,
|
||||
@@ -229,7 +253,26 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
syscard.FieldCashValue: {Type: field.TypeString, Column: syscard.FieldCashValue},
|
||||
},
|
||||
}
|
||||
graph.Nodes[9] = &sqlgraph.Node{
|
||||
graph.Nodes[10] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: sysconfig.Table,
|
||||
Columns: sysconfig.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Column: sysconfig.FieldID,
|
||||
},
|
||||
},
|
||||
Type: "SysConfig",
|
||||
Fields: map[string]*sqlgraph.FieldSpec{
|
||||
sysconfig.FieldCreateTime: {Type: field.TypeString, Column: sysconfig.FieldCreateTime},
|
||||
sysconfig.FieldUpdateTime: {Type: field.TypeString, Column: sysconfig.FieldUpdateTime},
|
||||
sysconfig.FieldKey: {Type: field.TypeString, Column: sysconfig.FieldKey},
|
||||
sysconfig.FieldValue: {Type: field.TypeString, Column: sysconfig.FieldValue},
|
||||
sysconfig.FieldDescription: {Type: field.TypeString, Column: sysconfig.FieldDescription},
|
||||
sysconfig.FieldType: {Type: field.TypeString, Column: sysconfig.FieldType},
|
||||
},
|
||||
}
|
||||
graph.Nodes[11] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: sysmenu.Table,
|
||||
Columns: sysmenu.Columns,
|
||||
@@ -255,7 +298,7 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
sysmenu.FieldOrder: {Type: field.TypeUint, Column: sysmenu.FieldOrder},
|
||||
},
|
||||
}
|
||||
graph.Nodes[10] = &sqlgraph.Node{
|
||||
graph.Nodes[12] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: sysrole.Table,
|
||||
Columns: sysrole.Columns,
|
||||
@@ -274,7 +317,7 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
sysrole.FieldOrder: {Type: field.TypeUint, Column: sysrole.FieldOrder},
|
||||
},
|
||||
}
|
||||
graph.Nodes[11] = &sqlgraph.Node{
|
||||
graph.Nodes[13] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: sysuser.Table,
|
||||
Columns: sysuser.Columns,
|
||||
@@ -297,7 +340,7 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
sysuser.FieldInviteCashback: {Type: field.TypeString, Column: sysuser.FieldInviteCashback},
|
||||
},
|
||||
}
|
||||
graph.Nodes[12] = &sqlgraph.Node{
|
||||
graph.Nodes[14] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: sysuserlog.Table,
|
||||
Columns: sysuserlog.Columns,
|
||||
@@ -513,6 +556,18 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
"SysAgent",
|
||||
"SysUser",
|
||||
)
|
||||
graph.MustAddE(
|
||||
"user",
|
||||
&sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: sysbalancerecord.UserTable,
|
||||
Columns: []string{sysbalancerecord.UserColumn},
|
||||
Bidi: false,
|
||||
},
|
||||
"SysBalanceRecord",
|
||||
"SysUser",
|
||||
)
|
||||
graph.MustAddE(
|
||||
"creator",
|
||||
&sqlgraph.EdgeSpec{
|
||||
@@ -765,6 +820,18 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
"SysUser",
|
||||
"SysCard",
|
||||
)
|
||||
graph.MustAddE(
|
||||
"balance_records",
|
||||
&sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.BalanceRecordsTable,
|
||||
Columns: []string{sysuser.BalanceRecordsColumn},
|
||||
Bidi: false,
|
||||
},
|
||||
"SysUser",
|
||||
"SysBalanceRecord",
|
||||
)
|
||||
return graph
|
||||
}()
|
||||
|
||||
@@ -1568,6 +1635,11 @@ func (f *CpUserFilter) WhereMobileType(p entql.StringP) {
|
||||
f.Where(p.Field(cpuser.FieldMobileType))
|
||||
}
|
||||
|
||||
// WhereLoginType applies the entql string predicate on the login_type field.
|
||||
func (f *CpUserFilter) WhereLoginType(p entql.StringP) {
|
||||
f.Where(p.Field(cpuser.FieldLoginType))
|
||||
}
|
||||
|
||||
// WhereHasCptasks applies a predicate to check if query has an edge cptasks.
|
||||
func (f *CpUserFilter) WhereHasCptasks() {
|
||||
f.Where(entql.HasEdge("cptasks"))
|
||||
@@ -1712,6 +1784,100 @@ func (f *SysAgentFilter) WhereHasUsersWith(preds ...predicate.SysUser) {
|
||||
})))
|
||||
}
|
||||
|
||||
// addPredicate implements the predicateAdder interface.
|
||||
func (_q *SysBalanceRecordQuery) addPredicate(pred func(s *sql.Selector)) {
|
||||
_q.predicates = append(_q.predicates, pred)
|
||||
}
|
||||
|
||||
// Filter returns a Filter implementation to apply filters on the SysBalanceRecordQuery builder.
|
||||
func (_q *SysBalanceRecordQuery) Filter() *SysBalanceRecordFilter {
|
||||
return &SysBalanceRecordFilter{config: _q.config, predicateAdder: _q}
|
||||
}
|
||||
|
||||
// addPredicate implements the predicateAdder interface.
|
||||
func (m *SysBalanceRecordMutation) addPredicate(pred func(s *sql.Selector)) {
|
||||
m.predicates = append(m.predicates, pred)
|
||||
}
|
||||
|
||||
// Filter returns an entql.Where implementation to apply filters on the SysBalanceRecordMutation builder.
|
||||
func (m *SysBalanceRecordMutation) Filter() *SysBalanceRecordFilter {
|
||||
return &SysBalanceRecordFilter{config: m.config, predicateAdder: m}
|
||||
}
|
||||
|
||||
// SysBalanceRecordFilter provides a generic filtering capability at runtime for SysBalanceRecordQuery.
|
||||
type SysBalanceRecordFilter struct {
|
||||
predicateAdder
|
||||
config
|
||||
}
|
||||
|
||||
// Where applies the entql predicate on the query filter.
|
||||
func (f *SysBalanceRecordFilter) Where(p entql.P) {
|
||||
f.addPredicate(func(s *sql.Selector) {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[8].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// WhereID applies the entql int64 predicate on the id field.
|
||||
func (f *SysBalanceRecordFilter) WhereID(p entql.Int64P) {
|
||||
f.Where(p.Field(sysbalancerecord.FieldID))
|
||||
}
|
||||
|
||||
// WhereCreateTime applies the entql string predicate on the create_time field.
|
||||
func (f *SysBalanceRecordFilter) WhereCreateTime(p entql.StringP) {
|
||||
f.Where(p.Field(sysbalancerecord.FieldCreateTime))
|
||||
}
|
||||
|
||||
// WhereUpdateTime applies the entql string predicate on the update_time field.
|
||||
func (f *SysBalanceRecordFilter) WhereUpdateTime(p entql.StringP) {
|
||||
f.Where(p.Field(sysbalancerecord.FieldUpdateTime))
|
||||
}
|
||||
|
||||
// WhereUserID applies the entql int64 predicate on the user_id field.
|
||||
func (f *SysBalanceRecordFilter) WhereUserID(p entql.Int64P) {
|
||||
f.Where(p.Field(sysbalancerecord.FieldUserID))
|
||||
}
|
||||
|
||||
// WhereType applies the entql string predicate on the type field.
|
||||
func (f *SysBalanceRecordFilter) WhereType(p entql.StringP) {
|
||||
f.Where(p.Field(sysbalancerecord.FieldType))
|
||||
}
|
||||
|
||||
// WhereAmount applies the entql string predicate on the amount field.
|
||||
func (f *SysBalanceRecordFilter) WhereAmount(p entql.StringP) {
|
||||
f.Where(p.Field(sysbalancerecord.FieldAmount))
|
||||
}
|
||||
|
||||
// WhereReason applies the entql string predicate on the reason field.
|
||||
func (f *SysBalanceRecordFilter) WhereReason(p entql.StringP) {
|
||||
f.Where(p.Field(sysbalancerecord.FieldReason))
|
||||
}
|
||||
|
||||
// WhereBalanceBefore applies the entql string predicate on the balance_before field.
|
||||
func (f *SysBalanceRecordFilter) WhereBalanceBefore(p entql.StringP) {
|
||||
f.Where(p.Field(sysbalancerecord.FieldBalanceBefore))
|
||||
}
|
||||
|
||||
// WhereBalanceAfter applies the entql string predicate on the balance_after field.
|
||||
func (f *SysBalanceRecordFilter) WhereBalanceAfter(p entql.StringP) {
|
||||
f.Where(p.Field(sysbalancerecord.FieldBalanceAfter))
|
||||
}
|
||||
|
||||
// WhereHasUser applies a predicate to check if query has an edge user.
|
||||
func (f *SysBalanceRecordFilter) WhereHasUser() {
|
||||
f.Where(entql.HasEdge("user"))
|
||||
}
|
||||
|
||||
// WhereHasUserWith applies a predicate to check if query has an edge user with a given conditions (other predicates).
|
||||
func (f *SysBalanceRecordFilter) WhereHasUserWith(preds ...predicate.SysUser) {
|
||||
f.Where(entql.HasEdgeWith("user", sqlgraph.WrapFunc(func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})))
|
||||
}
|
||||
|
||||
// addPredicate implements the predicateAdder interface.
|
||||
func (_q *SysCardQuery) addPredicate(pred func(s *sql.Selector)) {
|
||||
_q.predicates = append(_q.predicates, pred)
|
||||
@@ -1741,7 +1907,7 @@ type SysCardFilter struct {
|
||||
// Where applies the entql predicate on the query filter.
|
||||
func (f *SysCardFilter) Where(p entql.P) {
|
||||
f.addPredicate(func(s *sql.Selector) {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[8].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[9].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -1839,6 +2005,76 @@ func (f *SysCardFilter) WhereHasCashUserWith(preds ...predicate.SysUser) {
|
||||
})))
|
||||
}
|
||||
|
||||
// addPredicate implements the predicateAdder interface.
|
||||
func (_q *SysConfigQuery) addPredicate(pred func(s *sql.Selector)) {
|
||||
_q.predicates = append(_q.predicates, pred)
|
||||
}
|
||||
|
||||
// Filter returns a Filter implementation to apply filters on the SysConfigQuery builder.
|
||||
func (_q *SysConfigQuery) Filter() *SysConfigFilter {
|
||||
return &SysConfigFilter{config: _q.config, predicateAdder: _q}
|
||||
}
|
||||
|
||||
// addPredicate implements the predicateAdder interface.
|
||||
func (m *SysConfigMutation) addPredicate(pred func(s *sql.Selector)) {
|
||||
m.predicates = append(m.predicates, pred)
|
||||
}
|
||||
|
||||
// Filter returns an entql.Where implementation to apply filters on the SysConfigMutation builder.
|
||||
func (m *SysConfigMutation) Filter() *SysConfigFilter {
|
||||
return &SysConfigFilter{config: m.config, predicateAdder: m}
|
||||
}
|
||||
|
||||
// SysConfigFilter provides a generic filtering capability at runtime for SysConfigQuery.
|
||||
type SysConfigFilter struct {
|
||||
predicateAdder
|
||||
config
|
||||
}
|
||||
|
||||
// Where applies the entql predicate on the query filter.
|
||||
func (f *SysConfigFilter) Where(p entql.P) {
|
||||
f.addPredicate(func(s *sql.Selector) {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[10].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// WhereID applies the entql int64 predicate on the id field.
|
||||
func (f *SysConfigFilter) WhereID(p entql.Int64P) {
|
||||
f.Where(p.Field(sysconfig.FieldID))
|
||||
}
|
||||
|
||||
// WhereCreateTime applies the entql string predicate on the create_time field.
|
||||
func (f *SysConfigFilter) WhereCreateTime(p entql.StringP) {
|
||||
f.Where(p.Field(sysconfig.FieldCreateTime))
|
||||
}
|
||||
|
||||
// WhereUpdateTime applies the entql string predicate on the update_time field.
|
||||
func (f *SysConfigFilter) WhereUpdateTime(p entql.StringP) {
|
||||
f.Where(p.Field(sysconfig.FieldUpdateTime))
|
||||
}
|
||||
|
||||
// WhereKey applies the entql string predicate on the key field.
|
||||
func (f *SysConfigFilter) WhereKey(p entql.StringP) {
|
||||
f.Where(p.Field(sysconfig.FieldKey))
|
||||
}
|
||||
|
||||
// WhereValue applies the entql string predicate on the value field.
|
||||
func (f *SysConfigFilter) WhereValue(p entql.StringP) {
|
||||
f.Where(p.Field(sysconfig.FieldValue))
|
||||
}
|
||||
|
||||
// WhereDescription applies the entql string predicate on the description field.
|
||||
func (f *SysConfigFilter) WhereDescription(p entql.StringP) {
|
||||
f.Where(p.Field(sysconfig.FieldDescription))
|
||||
}
|
||||
|
||||
// WhereType applies the entql string predicate on the type field.
|
||||
func (f *SysConfigFilter) WhereType(p entql.StringP) {
|
||||
f.Where(p.Field(sysconfig.FieldType))
|
||||
}
|
||||
|
||||
// addPredicate implements the predicateAdder interface.
|
||||
func (_q *SysMenuQuery) addPredicate(pred func(s *sql.Selector)) {
|
||||
_q.predicates = append(_q.predicates, pred)
|
||||
@@ -1868,7 +2104,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[9].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[11].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -2015,7 +2251,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[10].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[12].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -2113,7 +2349,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[11].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[13].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -2356,6 +2592,20 @@ func (f *SysUserFilter) WhereHasCashbackCardsWith(preds ...predicate.SysCard) {
|
||||
})))
|
||||
}
|
||||
|
||||
// WhereHasBalanceRecords applies a predicate to check if query has an edge balance_records.
|
||||
func (f *SysUserFilter) WhereHasBalanceRecords() {
|
||||
f.Where(entql.HasEdge("balance_records"))
|
||||
}
|
||||
|
||||
// WhereHasBalanceRecordsWith applies a predicate to check if query has an edge balance_records with a given conditions (other predicates).
|
||||
func (f *SysUserFilter) WhereHasBalanceRecordsWith(preds ...predicate.SysBalanceRecord) {
|
||||
f.Where(entql.HasEdgeWith("balance_records", sqlgraph.WrapFunc(func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})))
|
||||
}
|
||||
|
||||
// addPredicate implements the predicateAdder interface.
|
||||
func (_q *SysUserLogQuery) addPredicate(pred func(s *sql.Selector)) {
|
||||
_q.predicates = append(_q.predicates, pred)
|
||||
@@ -2385,7 +2635,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[12].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[14].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -104,6 +104,18 @@ func (f SysAgentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, er
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SysAgentMutation", m)
|
||||
}
|
||||
|
||||
// The SysBalanceRecordFunc type is an adapter to allow the use of ordinary
|
||||
// function as SysBalanceRecord mutator.
|
||||
type SysBalanceRecordFunc func(context.Context, *ent.SysBalanceRecordMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f SysBalanceRecordFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.SysBalanceRecordMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SysBalanceRecordMutation", m)
|
||||
}
|
||||
|
||||
// The SysCardFunc type is an adapter to allow the use of ordinary
|
||||
// function as SysCard mutator.
|
||||
type SysCardFunc func(context.Context, *ent.SysCardMutation) (ent.Value, error)
|
||||
@@ -116,6 +128,18 @@ func (f SysCardFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, err
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SysCardMutation", m)
|
||||
}
|
||||
|
||||
// The SysConfigFunc type is an adapter to allow the use of ordinary
|
||||
// function as SysConfig mutator.
|
||||
type SysConfigFunc func(context.Context, *ent.SysConfigMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f SysConfigFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.SysConfigMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SysConfigMutation", m)
|
||||
}
|
||||
|
||||
// The SysMenuFunc type is an adapter to allow the use of ordinary
|
||||
// function as SysMenu mutator.
|
||||
type SysMenuFunc func(context.Context, *ent.SysMenuMutation) (ent.Value, error)
|
||||
|
||||
@@ -16,7 +16,9 @@ import (
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysagent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysconfig"
|
||||
"likedream-goframe/internal/ent/sysmenu"
|
||||
"likedream-goframe/internal/ent/sysrole"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
@@ -297,6 +299,33 @@ func (f TraverseSysAgent) Traverse(ctx context.Context, q ent.Query) error {
|
||||
return fmt.Errorf("unexpected query type %T. expect *ent.SysAgentQuery", q)
|
||||
}
|
||||
|
||||
// The SysBalanceRecordFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||
type SysBalanceRecordFunc func(context.Context, *ent.SysBalanceRecordQuery) (ent.Value, error)
|
||||
|
||||
// Query calls f(ctx, q).
|
||||
func (f SysBalanceRecordFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
|
||||
if q, ok := q.(*ent.SysBalanceRecordQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected query type %T. expect *ent.SysBalanceRecordQuery", q)
|
||||
}
|
||||
|
||||
// The TraverseSysBalanceRecord type is an adapter to allow the use of ordinary function as Traverser.
|
||||
type TraverseSysBalanceRecord func(context.Context, *ent.SysBalanceRecordQuery) error
|
||||
|
||||
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
|
||||
func (f TraverseSysBalanceRecord) Intercept(next ent.Querier) ent.Querier {
|
||||
return next
|
||||
}
|
||||
|
||||
// Traverse calls f(ctx, q).
|
||||
func (f TraverseSysBalanceRecord) Traverse(ctx context.Context, q ent.Query) error {
|
||||
if q, ok := q.(*ent.SysBalanceRecordQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return fmt.Errorf("unexpected query type %T. expect *ent.SysBalanceRecordQuery", q)
|
||||
}
|
||||
|
||||
// The SysCardFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||
type SysCardFunc func(context.Context, *ent.SysCardQuery) (ent.Value, error)
|
||||
|
||||
@@ -324,6 +353,33 @@ func (f TraverseSysCard) Traverse(ctx context.Context, q ent.Query) error {
|
||||
return fmt.Errorf("unexpected query type %T. expect *ent.SysCardQuery", q)
|
||||
}
|
||||
|
||||
// The SysConfigFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||
type SysConfigFunc func(context.Context, *ent.SysConfigQuery) (ent.Value, error)
|
||||
|
||||
// Query calls f(ctx, q).
|
||||
func (f SysConfigFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
|
||||
if q, ok := q.(*ent.SysConfigQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected query type %T. expect *ent.SysConfigQuery", q)
|
||||
}
|
||||
|
||||
// The TraverseSysConfig type is an adapter to allow the use of ordinary function as Traverser.
|
||||
type TraverseSysConfig func(context.Context, *ent.SysConfigQuery) error
|
||||
|
||||
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
|
||||
func (f TraverseSysConfig) Intercept(next ent.Querier) ent.Querier {
|
||||
return next
|
||||
}
|
||||
|
||||
// Traverse calls f(ctx, q).
|
||||
func (f TraverseSysConfig) Traverse(ctx context.Context, q ent.Query) error {
|
||||
if q, ok := q.(*ent.SysConfigQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return fmt.Errorf("unexpected query type %T. expect *ent.SysConfigQuery", q)
|
||||
}
|
||||
|
||||
// The SysMenuFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||
type SysMenuFunc func(context.Context, *ent.SysMenuQuery) (ent.Value, error)
|
||||
|
||||
@@ -451,8 +507,12 @@ func NewQuery(q ent.Query) (Query, error) {
|
||||
return &query[*ent.CpUserQuery, predicate.CpUser, cpuser.OrderOption]{typ: ent.TypeCpUser, tq: q}, nil
|
||||
case *ent.SysAgentQuery:
|
||||
return &query[*ent.SysAgentQuery, predicate.SysAgent, sysagent.OrderOption]{typ: ent.TypeSysAgent, tq: q}, nil
|
||||
case *ent.SysBalanceRecordQuery:
|
||||
return &query[*ent.SysBalanceRecordQuery, predicate.SysBalanceRecord, sysbalancerecord.OrderOption]{typ: ent.TypeSysBalanceRecord, tq: q}, nil
|
||||
case *ent.SysCardQuery:
|
||||
return &query[*ent.SysCardQuery, predicate.SysCard, syscard.OrderOption]{typ: ent.TypeSysCard, tq: q}, nil
|
||||
case *ent.SysConfigQuery:
|
||||
return &query[*ent.SysConfigQuery, predicate.SysConfig, sysconfig.OrderOption]{typ: ent.TypeSysConfig, tq: q}, nil
|
||||
case *ent.SysMenuQuery:
|
||||
return &query[*ent.SysMenuQuery, predicate.SysMenu, sysmenu.OrderOption]{typ: ent.TypeSysMenu, tq: q}, nil
|
||||
case *ent.SysRoleQuery:
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -7,21 +7,23 @@ import "context"
|
||||
// SchemaConfig represents alternative schema names for all tables
|
||||
// that can be passed at runtime.
|
||||
type SchemaConfig struct {
|
||||
CourseEntity string // CourseEntity table.
|
||||
CpImage string // CpImage table.
|
||||
CpLeave string // CpLeave table.
|
||||
CpSchool string // CpSchool table.
|
||||
CpTask string // CpTask table.
|
||||
CpTaskLog string // CpTaskLog table.
|
||||
CpUser string // CpUser table.
|
||||
SysAgent string // SysAgent table.
|
||||
SysCard string // SysCard table.
|
||||
SysMenu string // SysMenu table.
|
||||
SysRole string // SysRole table.
|
||||
SysRoleMenus string // SysRole-menus->SysMenu table.
|
||||
SysUser string // SysUser table.
|
||||
SysUserRoles string // SysUser-roles->SysRole table.
|
||||
SysUserLog string // SysUserLog table.
|
||||
CourseEntity string // CourseEntity table.
|
||||
CpImage string // CpImage table.
|
||||
CpLeave string // CpLeave table.
|
||||
CpSchool string // CpSchool table.
|
||||
CpTask string // CpTask table.
|
||||
CpTaskLog string // CpTaskLog table.
|
||||
CpUser string // CpUser table.
|
||||
SysAgent string // SysAgent table.
|
||||
SysBalanceRecord string // SysBalanceRecord table.
|
||||
SysCard string // SysCard table.
|
||||
SysConfig string // SysConfig table.
|
||||
SysMenu string // SysMenu table.
|
||||
SysRole string // SysRole table.
|
||||
SysRoleMenus string // SysRole-menus->SysMenu table.
|
||||
SysUser string // SysUser table.
|
||||
SysUserRoles string // SysUser-roles->SysRole table.
|
||||
SysUserLog string // SysUserLog table.
|
||||
}
|
||||
|
||||
type schemaCtxKey struct{}
|
||||
|
||||
@@ -201,11 +201,12 @@ var (
|
||||
{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: "username", Type: field.TypeString},
|
||||
{Name: "password", Type: field.TypeString},
|
||||
{Name: "password", Type: field.TypeString, Nullable: true},
|
||||
{Name: "email", Type: field.TypeString, Nullable: true},
|
||||
{Name: "mobile_code", Type: field.TypeString, Nullable: true},
|
||||
{Name: "cookie", Type: field.TypeString, Nullable: true, Size: 2147483647},
|
||||
{Name: "mobile_type", Type: field.TypeEnum, Enums: []string{"random", "authorize"}},
|
||||
{Name: "login_type", Type: field.TypeEnum, Enums: []string{"account", "phone"}, Default: "account"},
|
||||
{Name: "school_id", Type: field.TypeString},
|
||||
{Name: "user_id", Type: field.TypeInt64},
|
||||
}
|
||||
@@ -217,13 +218,13 @@ var (
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "cp_users_cp_schools_cpusers",
|
||||
Columns: []*schema.Column{CpUsersColumns[9]},
|
||||
Columns: []*schema.Column{CpUsersColumns[10]},
|
||||
RefColumns: []*schema.Column{CpSchoolsColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
{
|
||||
Symbol: "cp_users_sys_user_cpuser",
|
||||
Columns: []*schema.Column{CpUsersColumns[10]},
|
||||
Columns: []*schema.Column{CpUsersColumns[11]},
|
||||
RefColumns: []*schema.Column{SysUserColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
@@ -252,6 +253,32 @@ var (
|
||||
},
|
||||
},
|
||||
}
|
||||
// SysBalanceRecordColumns holds the columns for the "sys_balance_record" table.
|
||||
SysBalanceRecordColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "create_time", Type: field.TypeString, SchemaType: map[string]string{"mysql": "datetime", "postgres": "timestamp", "sqlite3": "datetime"}},
|
||||
{Name: "update_time", Type: field.TypeString, SchemaType: map[string]string{"mysql": "datetime", "postgres": "timestamp", "sqlite3": "datetime"}},
|
||||
{Name: "type", Type: field.TypeEnum, Enums: []string{"increase", "decrease"}},
|
||||
{Name: "amount", Type: field.TypeString, SchemaType: map[string]string{"mysql": "decimal(10,2)", "postgres": "numeric(10,2)"}},
|
||||
{Name: "reason", Type: field.TypeString},
|
||||
{Name: "balance_before", Type: field.TypeString, SchemaType: map[string]string{"mysql": "decimal(10,2)", "postgres": "numeric(10,2)"}},
|
||||
{Name: "balance_after", Type: field.TypeString, SchemaType: map[string]string{"mysql": "decimal(10,2)", "postgres": "numeric(10,2)"}},
|
||||
{Name: "user_id", Type: field.TypeInt64},
|
||||
}
|
||||
// SysBalanceRecordTable holds the schema information for the "sys_balance_record" table.
|
||||
SysBalanceRecordTable = &schema.Table{
|
||||
Name: "sys_balance_record",
|
||||
Columns: SysBalanceRecordColumns,
|
||||
PrimaryKey: []*schema.Column{SysBalanceRecordColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "sys_balance_record_sys_user_balance_records",
|
||||
Columns: []*schema.Column{SysBalanceRecordColumns[8]},
|
||||
RefColumns: []*schema.Column{SysUserColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
},
|
||||
}
|
||||
// SysCardColumns holds the columns for the "sys_card" table.
|
||||
SysCardColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
@@ -291,6 +318,22 @@ var (
|
||||
},
|
||||
},
|
||||
}
|
||||
// SysConfigColumns holds the columns for the "sys_config" table.
|
||||
SysConfigColumns = []*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: "key", Type: field.TypeString, Unique: true},
|
||||
{Name: "value", Type: field.TypeString, Size: 2147483647},
|
||||
{Name: "description", Type: field.TypeString, Nullable: true},
|
||||
{Name: "type", Type: field.TypeString, Default: "string"},
|
||||
}
|
||||
// SysConfigTable holds the schema information for the "sys_config" table.
|
||||
SysConfigTable = &schema.Table{
|
||||
Name: "sys_config",
|
||||
Columns: SysConfigColumns,
|
||||
PrimaryKey: []*schema.Column{SysConfigColumns[0]},
|
||||
}
|
||||
// SysMenuColumns holds the columns for the "sys_menu" table.
|
||||
SysMenuColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
@@ -438,7 +481,9 @@ var (
|
||||
CpTaskLogsTable,
|
||||
CpUsersTable,
|
||||
SysAgentTable,
|
||||
SysBalanceRecordTable,
|
||||
SysCardTable,
|
||||
SysConfigTable,
|
||||
SysMenuTable,
|
||||
SysRoleTable,
|
||||
SysUserTable,
|
||||
@@ -470,12 +515,19 @@ func init() {
|
||||
SysAgentTable.Annotation = &entsql.Annotation{
|
||||
Table: "sys_agent",
|
||||
}
|
||||
SysBalanceRecordTable.ForeignKeys[0].RefTable = SysUserTable
|
||||
SysBalanceRecordTable.Annotation = &entsql.Annotation{
|
||||
Table: "sys_balance_record",
|
||||
}
|
||||
SysCardTable.ForeignKeys[0].RefTable = SysUserTable
|
||||
SysCardTable.ForeignKeys[1].RefTable = SysUserTable
|
||||
SysCardTable.ForeignKeys[2].RefTable = SysUserTable
|
||||
SysCardTable.Annotation = &entsql.Annotation{
|
||||
Table: "sys_card",
|
||||
}
|
||||
SysConfigTable.Annotation = &entsql.Annotation{
|
||||
Table: "sys_config",
|
||||
}
|
||||
SysMenuTable.ForeignKeys[0].RefTable = SysMenuTable
|
||||
SysMenuTable.Annotation = &entsql.Annotation{
|
||||
Table: "sys_menu",
|
||||
|
||||
+1610
-71
File diff suppressed because it is too large
Load Diff
@@ -30,9 +30,15 @@ type CpUser func(*sql.Selector)
|
||||
// SysAgent is the predicate function for sysagent builders.
|
||||
type SysAgent func(*sql.Selector)
|
||||
|
||||
// SysBalanceRecord is the predicate function for sysbalancerecord builders.
|
||||
type SysBalanceRecord func(*sql.Selector)
|
||||
|
||||
// SysCard is the predicate function for syscard builders.
|
||||
type SysCard func(*sql.Selector)
|
||||
|
||||
// SysConfig is the predicate function for sysconfig builders.
|
||||
type SysConfig func(*sql.Selector)
|
||||
|
||||
// SysMenu is the predicate function for sysmenu builders.
|
||||
type SysMenu func(*sql.Selector)
|
||||
|
||||
|
||||
@@ -303,6 +303,30 @@ func (f SysAgentMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutati
|
||||
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.SysAgentMutation", m)
|
||||
}
|
||||
|
||||
// The SysBalanceRecordQueryRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a query rule.
|
||||
type SysBalanceRecordQueryRuleFunc func(context.Context, *ent.SysBalanceRecordQuery) error
|
||||
|
||||
// EvalQuery return f(ctx, q).
|
||||
func (f SysBalanceRecordQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||
if q, ok := q.(*ent.SysBalanceRecordQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected query type %T, expect *ent.SysBalanceRecordQuery", q)
|
||||
}
|
||||
|
||||
// The SysBalanceRecordMutationRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a mutation rule.
|
||||
type SysBalanceRecordMutationRuleFunc func(context.Context, *ent.SysBalanceRecordMutation) error
|
||||
|
||||
// EvalMutation calls f(ctx, m).
|
||||
func (f SysBalanceRecordMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||
if m, ok := m.(*ent.SysBalanceRecordMutation); ok {
|
||||
return f(ctx, m)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.SysBalanceRecordMutation", m)
|
||||
}
|
||||
|
||||
// The SysCardQueryRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a query rule.
|
||||
type SysCardQueryRuleFunc func(context.Context, *ent.SysCardQuery) error
|
||||
@@ -327,6 +351,30 @@ func (f SysCardMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutatio
|
||||
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.SysCardMutation", m)
|
||||
}
|
||||
|
||||
// The SysConfigQueryRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a query rule.
|
||||
type SysConfigQueryRuleFunc func(context.Context, *ent.SysConfigQuery) error
|
||||
|
||||
// EvalQuery return f(ctx, q).
|
||||
func (f SysConfigQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||
if q, ok := q.(*ent.SysConfigQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected query type %T, expect *ent.SysConfigQuery", q)
|
||||
}
|
||||
|
||||
// The SysConfigMutationRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a mutation rule.
|
||||
type SysConfigMutationRuleFunc func(context.Context, *ent.SysConfigMutation) error
|
||||
|
||||
// EvalMutation calls f(ctx, m).
|
||||
func (f SysConfigMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||
if m, ok := m.(*ent.SysConfigMutation); ok {
|
||||
return f(ctx, m)
|
||||
}
|
||||
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.SysConfigMutation", m)
|
||||
}
|
||||
|
||||
// The SysMenuQueryRuleFunc type is an adapter to allow the use of ordinary
|
||||
// functions as a query rule.
|
||||
type SysMenuQueryRuleFunc func(context.Context, *ent.SysMenuQuery) error
|
||||
@@ -474,8 +522,12 @@ func queryFilter(q ent.Query) (Filter, error) {
|
||||
return q.Filter(), nil
|
||||
case *ent.SysAgentQuery:
|
||||
return q.Filter(), nil
|
||||
case *ent.SysBalanceRecordQuery:
|
||||
return q.Filter(), nil
|
||||
case *ent.SysCardQuery:
|
||||
return q.Filter(), nil
|
||||
case *ent.SysConfigQuery:
|
||||
return q.Filter(), nil
|
||||
case *ent.SysMenuQuery:
|
||||
return q.Filter(), nil
|
||||
case *ent.SysRoleQuery:
|
||||
@@ -507,8 +559,12 @@ func mutationFilter(m ent.Mutation) (Filter, error) {
|
||||
return m.Filter(), nil
|
||||
case *ent.SysAgentMutation:
|
||||
return m.Filter(), nil
|
||||
case *ent.SysBalanceRecordMutation:
|
||||
return m.Filter(), nil
|
||||
case *ent.SysCardMutation:
|
||||
return m.Filter(), nil
|
||||
case *ent.SysConfigMutation:
|
||||
return m.Filter(), nil
|
||||
case *ent.SysMenuMutation:
|
||||
return m.Filter(), nil
|
||||
case *ent.SysRoleMutation:
|
||||
|
||||
@@ -12,7 +12,9 @@ import (
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/ent/schema"
|
||||
"likedream-goframe/internal/ent/sysagent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysconfig"
|
||||
"likedream-goframe/internal/ent/sysmenu"
|
||||
"likedream-goframe/internal/ent/sysrole"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
@@ -183,10 +185,6 @@ func init() {
|
||||
cpuserDescUsername := cpuserFields[1].Descriptor()
|
||||
// cpuser.UsernameValidator is a validator for the "username" field. It is called by the builders before save.
|
||||
cpuser.UsernameValidator = cpuserDescUsername.Validators[0].(func(string) error)
|
||||
// cpuserDescPassword is the schema descriptor for password field.
|
||||
cpuserDescPassword := cpuserFields[2].Descriptor()
|
||||
// cpuser.PasswordValidator is a validator for the "password" field. It is called by the builders before save.
|
||||
cpuser.PasswordValidator = cpuserDescPassword.Validators[0].(func(string) error)
|
||||
// cpuserDescSchoolID is the schema descriptor for school_id field.
|
||||
cpuserDescSchoolID := cpuserFields[3].Descriptor()
|
||||
// cpuser.SchoolIDValidator is a validator for the "school_id" field. It is called by the builders before save.
|
||||
@@ -206,6 +204,21 @@ func init() {
|
||||
sysagentDescUpdateTime := sysagentMixinFields0[1].Descriptor()
|
||||
// sysagent.DefaultUpdateTime holds the default value on creation for the update_time field.
|
||||
sysagent.DefaultUpdateTime = sysagentDescUpdateTime.Default.(func() *ent2.CustomTime)
|
||||
sysbalancerecordMixin := schema.SysBalanceRecord{}.Mixin()
|
||||
sysbalancerecordMixinHooks0 := sysbalancerecordMixin[0].Hooks()
|
||||
sysbalancerecord.Hooks[0] = sysbalancerecordMixinHooks0[0]
|
||||
sysbalancerecordMixinFields0 := sysbalancerecordMixin[0].Fields()
|
||||
_ = sysbalancerecordMixinFields0
|
||||
sysbalancerecordFields := schema.SysBalanceRecord{}.Fields()
|
||||
_ = sysbalancerecordFields
|
||||
// sysbalancerecordDescCreateTime is the schema descriptor for create_time field.
|
||||
sysbalancerecordDescCreateTime := sysbalancerecordMixinFields0[0].Descriptor()
|
||||
// sysbalancerecord.DefaultCreateTime holds the default value on creation for the create_time field.
|
||||
sysbalancerecord.DefaultCreateTime = sysbalancerecordDescCreateTime.Default.(func() *ent2.CustomTime)
|
||||
// sysbalancerecordDescUpdateTime is the schema descriptor for update_time field.
|
||||
sysbalancerecordDescUpdateTime := sysbalancerecordMixinFields0[1].Descriptor()
|
||||
// sysbalancerecord.DefaultUpdateTime holds the default value on creation for the update_time field.
|
||||
sysbalancerecord.DefaultUpdateTime = sysbalancerecordDescUpdateTime.Default.(func() *ent2.CustomTime)
|
||||
syscardMixin := schema.SysCard{}.Mixin()
|
||||
syscardMixinHooks0 := syscardMixin[0].Hooks()
|
||||
syscard.Hooks[0] = syscardMixinHooks0[0]
|
||||
@@ -225,6 +238,25 @@ func init() {
|
||||
syscardDescCashValue := syscardFields[6].Descriptor()
|
||||
// syscard.DefaultCashValue holds the default value on creation for the cash_value field.
|
||||
syscard.DefaultCashValue = syscardDescCashValue.Default.(func() decimal.Decimal)
|
||||
sysconfigMixin := schema.SysConfig{}.Mixin()
|
||||
sysconfigMixinHooks0 := sysconfigMixin[0].Hooks()
|
||||
sysconfig.Hooks[0] = sysconfigMixinHooks0[0]
|
||||
sysconfigMixinFields0 := sysconfigMixin[0].Fields()
|
||||
_ = sysconfigMixinFields0
|
||||
sysconfigFields := schema.SysConfig{}.Fields()
|
||||
_ = sysconfigFields
|
||||
// sysconfigDescCreateTime is the schema descriptor for create_time field.
|
||||
sysconfigDescCreateTime := sysconfigMixinFields0[0].Descriptor()
|
||||
// sysconfig.DefaultCreateTime holds the default value on creation for the create_time field.
|
||||
sysconfig.DefaultCreateTime = sysconfigDescCreateTime.Default.(func() *ent2.CustomTime)
|
||||
// sysconfigDescUpdateTime is the schema descriptor for update_time field.
|
||||
sysconfigDescUpdateTime := sysconfigMixinFields0[1].Descriptor()
|
||||
// sysconfig.DefaultUpdateTime holds the default value on creation for the update_time field.
|
||||
sysconfig.DefaultUpdateTime = sysconfigDescUpdateTime.Default.(func() *ent2.CustomTime)
|
||||
// sysconfigDescType is the schema descriptor for type field.
|
||||
sysconfigDescType := sysconfigFields[3].Descriptor()
|
||||
// sysconfig.DefaultType holds the default value on creation for the type field.
|
||||
sysconfig.DefaultType = sysconfigDescType.Default.(string)
|
||||
sysmenuMixin := schema.SysMenu{}.Mixin()
|
||||
sysmenuMixinHooks0 := sysmenuMixin[0].Hooks()
|
||||
sysmenu.Hooks[0] = sysmenuMixinHooks0[0]
|
||||
|
||||
@@ -19,12 +19,13 @@ func (CpUser) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int64("user_id"),
|
||||
field.String("username").NotEmpty(),
|
||||
field.String("password").NotEmpty(),
|
||||
field.String("password").Optional(),
|
||||
field.String("school_id").NotEmpty(),
|
||||
field.String("email").Optional(),
|
||||
field.String("mobile_code").Optional(),
|
||||
field.Text("cookie").Optional(),
|
||||
field.Enum("mobile_type").Values("random", "authorize"),
|
||||
field.Enum("login_type").Values("account", "phone").Default("account"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,15 +49,12 @@ func (MixinTime) Hooks() []ent.Hook {
|
||||
return []ent.Hook{
|
||||
func(next ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
// 只处理Create和Update操作
|
||||
if !m.Op().Is(ent.OpUpdate | ent.OpUpdateOne) {
|
||||
return next.Mutate(ctx, m)
|
||||
}
|
||||
|
||||
// 设置update_time(创建和更新时)
|
||||
if _, exists := m.Field("update_time"); !exists {
|
||||
if e := m.SetField("update_time", ent2.NewCustomTime(time.Now())); e != nil {
|
||||
return nil, e
|
||||
// 只在Update和UpdateOne操作时设置update_time
|
||||
if m.Op().Is(ent.OpUpdate | ent.OpUpdateOne) {
|
||||
if _, exists := m.Field("update_time"); !exists {
|
||||
if e := m.SetField("update_time", ent2.NewCustomTime(time.Now())); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"likedream-goframe/internal/ent/schema/mix"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// SysBalanceRecord holds the schema definition for the SysBalanceRecord entity.
|
||||
type SysBalanceRecord struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the SysBalanceRecord.
|
||||
func (SysBalanceRecord) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int64("user_id").Comment("用户ID"),
|
||||
field.Enum("type").Values("increase", "decrease").Comment("变动类型:increase增加,decrease减少"),
|
||||
field.String("amount").GoType(decimal.Decimal{}).SchemaType(map[string]string{
|
||||
dialect.MySQL: "decimal(10,2)",
|
||||
dialect.Postgres: "numeric(10,2)",
|
||||
}).Comment("变动金额"),
|
||||
field.String("reason").Comment("变动原因"),
|
||||
field.String("balance_before").GoType(decimal.Decimal{}).SchemaType(map[string]string{
|
||||
dialect.MySQL: "decimal(10,2)",
|
||||
dialect.Postgres: "numeric(10,2)",
|
||||
}).Comment("变动前余额"),
|
||||
field.String("balance_after").GoType(decimal.Decimal{}).SchemaType(map[string]string{
|
||||
dialect.MySQL: "decimal(10,2)",
|
||||
dialect.Postgres: "numeric(10,2)",
|
||||
}).Comment("变动后余额"),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the SysBalanceRecord.
|
||||
func (SysBalanceRecord) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("user", SysUser.Type).
|
||||
Ref("balance_records").
|
||||
Field("user_id").
|
||||
Unique().
|
||||
Required(),
|
||||
}
|
||||
}
|
||||
|
||||
func (SysBalanceRecord) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
entsql.Annotation{Table: "sys_balance_record"},
|
||||
}
|
||||
}
|
||||
|
||||
func (SysBalanceRecord) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mix.MixinTime{},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"likedream-goframe/internal/ent/schema/mix"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
type SysConfig struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the SysConfig.
|
||||
func (SysConfig) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("key").
|
||||
Unique().
|
||||
Comment("配置键,如:system.announcement"),
|
||||
field.Text("value").
|
||||
Comment("配置值"),
|
||||
field.String("description").
|
||||
Optional().
|
||||
Comment("配置描述"),
|
||||
field.String("type").
|
||||
Default("string").
|
||||
Comment("值类型:string, number, boolean, json, markdown"),
|
||||
}
|
||||
}
|
||||
|
||||
// Mixin of the SysConfig
|
||||
func (SysConfig) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mix.MixinTime{},
|
||||
}
|
||||
}
|
||||
|
||||
func (SysConfig) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
entsql.Annotation{Table: "sys_config"},
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,7 @@ func (SysUser) Edges() []ent.Edge {
|
||||
edge.To("created_cards", SysCard.Type), // 用户创建的卡
|
||||
edge.To("used_cards", SysCard.Type), // 用户使用的卡
|
||||
edge.To("cashback_cards", SysCard.Type),
|
||||
edge.To("balance_records", SysBalanceRecord.Type).Annotations(entsql.OnDelete(entsql.Cascade)), // 用户余额变动记录
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package sysannouncement
|
||||
|
||||
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 sysannouncement type in the database.
|
||||
Label = "sys_announcement"
|
||||
// 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"
|
||||
// FieldTitle holds the string denoting the title field in the database.
|
||||
FieldTitle = "title"
|
||||
// FieldContent holds the string denoting the content field in the database.
|
||||
FieldContent = "content"
|
||||
// FieldStatus holds the string denoting the status field in the database.
|
||||
FieldStatus = "status"
|
||||
// FieldPinned holds the string denoting the pinned field in the database.
|
||||
FieldPinned = "pinned"
|
||||
// FieldOrder holds the string denoting the order field in the database.
|
||||
FieldOrder = "order"
|
||||
// FieldCreatorID holds the string denoting the creator_id field in the database.
|
||||
FieldCreatorID = "creator_id"
|
||||
// EdgeCreator holds the string denoting the creator edge name in mutations.
|
||||
EdgeCreator = "creator"
|
||||
// Table holds the table name of the sysannouncement in the database.
|
||||
Table = "sys_announcement"
|
||||
// CreatorTable is the table that holds the creator relation/edge.
|
||||
CreatorTable = "sys_announcement"
|
||||
// CreatorInverseTable is the table name for the SysUser entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "sysuser" package.
|
||||
CreatorInverseTable = "sys_user"
|
||||
// CreatorColumn is the table column denoting the creator relation/edge.
|
||||
CreatorColumn = "creator_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for sysannouncement fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldCreateTime,
|
||||
FieldUpdateTime,
|
||||
FieldTitle,
|
||||
FieldContent,
|
||||
FieldStatus,
|
||||
FieldPinned,
|
||||
FieldOrder,
|
||||
FieldCreatorID,
|
||||
}
|
||||
|
||||
// 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
|
||||
// DefaultPinned holds the default value on creation for the "pinned" field.
|
||||
DefaultPinned bool
|
||||
// DefaultOrder holds the default value on creation for the "order" field.
|
||||
DefaultOrder uint
|
||||
)
|
||||
|
||||
// Status defines the type for the "status" enum field.
|
||||
type Status string
|
||||
|
||||
// StatusDraft is the default value of the Status enum.
|
||||
const DefaultStatus = StatusDraft
|
||||
|
||||
// Status values.
|
||||
const (
|
||||
StatusDraft Status = "draft"
|
||||
StatusPublished Status = "published"
|
||||
StatusArchived Status = "archived"
|
||||
)
|
||||
|
||||
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 StatusDraft, StatusPublished, StatusArchived:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("sysannouncement: invalid enum value for status field: %q", s)
|
||||
}
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the SysAnnouncement 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()
|
||||
}
|
||||
|
||||
// ByTitle orders the results by the title field.
|
||||
func ByTitle(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTitle, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByContent orders the results by the content field.
|
||||
func ByContent(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldContent, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByStatus orders the results by the status field.
|
||||
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByPinned orders the results by the pinned field.
|
||||
func ByPinned(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldPinned, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByOrder orders the results by the order field.
|
||||
func ByOrder(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldOrder, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatorID orders the results by the creator_id field.
|
||||
func ByCreatorID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatorID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatorField orders the results by creator field.
|
||||
func ByCreatorField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newCreatorStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newCreatorStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(CreatorInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, CreatorTable, CreatorColumn),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,496 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package sysannouncement
|
||||
|
||||
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.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int64) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int64) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int64) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int64) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int64) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int64) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int64) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int64) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(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.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(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.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// Title applies equality check predicate on the "title" field. It's identical to TitleEQ.
|
||||
func Title(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldEQ(FieldTitle, v))
|
||||
}
|
||||
|
||||
// Content applies equality check predicate on the "content" field. It's identical to ContentEQ.
|
||||
func Content(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldEQ(FieldContent, v))
|
||||
}
|
||||
|
||||
// Pinned applies equality check predicate on the "pinned" field. It's identical to PinnedEQ.
|
||||
func Pinned(v bool) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldEQ(FieldPinned, v))
|
||||
}
|
||||
|
||||
// Order applies equality check predicate on the "order" field. It's identical to OrderEQ.
|
||||
func Order(v uint) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldEQ(FieldOrder, v))
|
||||
}
|
||||
|
||||
// CreatorID applies equality check predicate on the "creator_id" field. It's identical to CreatorIDEQ.
|
||||
func CreatorID(v int64) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldEQ(FieldCreatorID, v))
|
||||
}
|
||||
|
||||
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||
func CreateTimeEQ(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||
func CreateTimeNEQ(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldNEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||
func CreateTimeIn(vs ...*ent2.CustomTime) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||
func CreateTimeNotIn(vs ...*ent2.CustomTime) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldNotIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||
func CreateTimeGT(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldGT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||
func CreateTimeGTE(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldGTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||
func CreateTimeLT(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldLT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||
func CreateTimeLTE(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldLTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeContains applies the Contains predicate on the "create_time" field.
|
||||
func CreateTimeContains(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
vc := v.String()
|
||||
return predicate.SysAnnouncement(sql.FieldContains(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeHasPrefix applies the HasPrefix predicate on the "create_time" field.
|
||||
func CreateTimeHasPrefix(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
vc := v.String()
|
||||
return predicate.SysAnnouncement(sql.FieldHasPrefix(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeHasSuffix applies the HasSuffix predicate on the "create_time" field.
|
||||
func CreateTimeHasSuffix(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
vc := v.String()
|
||||
return predicate.SysAnnouncement(sql.FieldHasSuffix(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeEqualFold applies the EqualFold predicate on the "create_time" field.
|
||||
func CreateTimeEqualFold(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
vc := v.String()
|
||||
return predicate.SysAnnouncement(sql.FieldEqualFold(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeContainsFold applies the ContainsFold predicate on the "create_time" field.
|
||||
func CreateTimeContainsFold(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
vc := v.String()
|
||||
return predicate.SysAnnouncement(sql.FieldContainsFold(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeEQ applies the EQ predicate on the "update_time" field.
|
||||
func UpdateTimeEQ(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeNEQ applies the NEQ predicate on the "update_time" field.
|
||||
func UpdateTimeNEQ(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldNEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeIn applies the In predicate on the "update_time" field.
|
||||
func UpdateTimeIn(vs ...*ent2.CustomTime) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldIn(FieldUpdateTime, vs...))
|
||||
}
|
||||
|
||||
// UpdateTimeNotIn applies the NotIn predicate on the "update_time" field.
|
||||
func UpdateTimeNotIn(vs ...*ent2.CustomTime) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldNotIn(FieldUpdateTime, vs...))
|
||||
}
|
||||
|
||||
// UpdateTimeGT applies the GT predicate on the "update_time" field.
|
||||
func UpdateTimeGT(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldGT(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeGTE applies the GTE predicate on the "update_time" field.
|
||||
func UpdateTimeGTE(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldGTE(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeLT applies the LT predicate on the "update_time" field.
|
||||
func UpdateTimeLT(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldLT(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeLTE applies the LTE predicate on the "update_time" field.
|
||||
func UpdateTimeLTE(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldLTE(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeContains applies the Contains predicate on the "update_time" field.
|
||||
func UpdateTimeContains(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
vc := v.String()
|
||||
return predicate.SysAnnouncement(sql.FieldContains(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeHasPrefix applies the HasPrefix predicate on the "update_time" field.
|
||||
func UpdateTimeHasPrefix(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
vc := v.String()
|
||||
return predicate.SysAnnouncement(sql.FieldHasPrefix(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeHasSuffix applies the HasSuffix predicate on the "update_time" field.
|
||||
func UpdateTimeHasSuffix(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
vc := v.String()
|
||||
return predicate.SysAnnouncement(sql.FieldHasSuffix(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeEqualFold applies the EqualFold predicate on the "update_time" field.
|
||||
func UpdateTimeEqualFold(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
vc := v.String()
|
||||
return predicate.SysAnnouncement(sql.FieldEqualFold(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeContainsFold applies the ContainsFold predicate on the "update_time" field.
|
||||
func UpdateTimeContainsFold(v *ent2.CustomTime) predicate.SysAnnouncement {
|
||||
vc := v.String()
|
||||
return predicate.SysAnnouncement(sql.FieldContainsFold(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// TitleEQ applies the EQ predicate on the "title" field.
|
||||
func TitleEQ(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldEQ(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleNEQ applies the NEQ predicate on the "title" field.
|
||||
func TitleNEQ(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldNEQ(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleIn applies the In predicate on the "title" field.
|
||||
func TitleIn(vs ...string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldIn(FieldTitle, vs...))
|
||||
}
|
||||
|
||||
// TitleNotIn applies the NotIn predicate on the "title" field.
|
||||
func TitleNotIn(vs ...string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldNotIn(FieldTitle, vs...))
|
||||
}
|
||||
|
||||
// TitleGT applies the GT predicate on the "title" field.
|
||||
func TitleGT(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldGT(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleGTE applies the GTE predicate on the "title" field.
|
||||
func TitleGTE(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldGTE(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleLT applies the LT predicate on the "title" field.
|
||||
func TitleLT(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldLT(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleLTE applies the LTE predicate on the "title" field.
|
||||
func TitleLTE(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldLTE(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleContains applies the Contains predicate on the "title" field.
|
||||
func TitleContains(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldContains(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleHasPrefix applies the HasPrefix predicate on the "title" field.
|
||||
func TitleHasPrefix(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldHasPrefix(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleHasSuffix applies the HasSuffix predicate on the "title" field.
|
||||
func TitleHasSuffix(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldHasSuffix(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleEqualFold applies the EqualFold predicate on the "title" field.
|
||||
func TitleEqualFold(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldEqualFold(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleContainsFold applies the ContainsFold predicate on the "title" field.
|
||||
func TitleContainsFold(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldContainsFold(FieldTitle, v))
|
||||
}
|
||||
|
||||
// ContentEQ applies the EQ predicate on the "content" field.
|
||||
func ContentEQ(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldEQ(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentNEQ applies the NEQ predicate on the "content" field.
|
||||
func ContentNEQ(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldNEQ(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentIn applies the In predicate on the "content" field.
|
||||
func ContentIn(vs ...string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldIn(FieldContent, vs...))
|
||||
}
|
||||
|
||||
// ContentNotIn applies the NotIn predicate on the "content" field.
|
||||
func ContentNotIn(vs ...string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldNotIn(FieldContent, vs...))
|
||||
}
|
||||
|
||||
// ContentGT applies the GT predicate on the "content" field.
|
||||
func ContentGT(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldGT(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentGTE applies the GTE predicate on the "content" field.
|
||||
func ContentGTE(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldGTE(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentLT applies the LT predicate on the "content" field.
|
||||
func ContentLT(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldLT(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentLTE applies the LTE predicate on the "content" field.
|
||||
func ContentLTE(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldLTE(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentContains applies the Contains predicate on the "content" field.
|
||||
func ContentContains(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldContains(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentHasPrefix applies the HasPrefix predicate on the "content" field.
|
||||
func ContentHasPrefix(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldHasPrefix(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentHasSuffix applies the HasSuffix predicate on the "content" field.
|
||||
func ContentHasSuffix(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldHasSuffix(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentEqualFold applies the EqualFold predicate on the "content" field.
|
||||
func ContentEqualFold(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldEqualFold(FieldContent, v))
|
||||
}
|
||||
|
||||
// ContentContainsFold applies the ContainsFold predicate on the "content" field.
|
||||
func ContentContainsFold(v string) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldContainsFold(FieldContent, v))
|
||||
}
|
||||
|
||||
// StatusEQ applies the EQ predicate on the "status" field.
|
||||
func StatusEQ(v Status) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldEQ(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusNEQ applies the NEQ predicate on the "status" field.
|
||||
func StatusNEQ(v Status) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldNEQ(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusIn applies the In predicate on the "status" field.
|
||||
func StatusIn(vs ...Status) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldIn(FieldStatus, vs...))
|
||||
}
|
||||
|
||||
// StatusNotIn applies the NotIn predicate on the "status" field.
|
||||
func StatusNotIn(vs ...Status) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldNotIn(FieldStatus, vs...))
|
||||
}
|
||||
|
||||
// PinnedEQ applies the EQ predicate on the "pinned" field.
|
||||
func PinnedEQ(v bool) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldEQ(FieldPinned, v))
|
||||
}
|
||||
|
||||
// PinnedNEQ applies the NEQ predicate on the "pinned" field.
|
||||
func PinnedNEQ(v bool) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldNEQ(FieldPinned, v))
|
||||
}
|
||||
|
||||
// OrderEQ applies the EQ predicate on the "order" field.
|
||||
func OrderEQ(v uint) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldEQ(FieldOrder, v))
|
||||
}
|
||||
|
||||
// OrderNEQ applies the NEQ predicate on the "order" field.
|
||||
func OrderNEQ(v uint) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldNEQ(FieldOrder, v))
|
||||
}
|
||||
|
||||
// OrderIn applies the In predicate on the "order" field.
|
||||
func OrderIn(vs ...uint) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldIn(FieldOrder, vs...))
|
||||
}
|
||||
|
||||
// OrderNotIn applies the NotIn predicate on the "order" field.
|
||||
func OrderNotIn(vs ...uint) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldNotIn(FieldOrder, vs...))
|
||||
}
|
||||
|
||||
// OrderGT applies the GT predicate on the "order" field.
|
||||
func OrderGT(v uint) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldGT(FieldOrder, v))
|
||||
}
|
||||
|
||||
// OrderGTE applies the GTE predicate on the "order" field.
|
||||
func OrderGTE(v uint) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldGTE(FieldOrder, v))
|
||||
}
|
||||
|
||||
// OrderLT applies the LT predicate on the "order" field.
|
||||
func OrderLT(v uint) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldLT(FieldOrder, v))
|
||||
}
|
||||
|
||||
// OrderLTE applies the LTE predicate on the "order" field.
|
||||
func OrderLTE(v uint) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldLTE(FieldOrder, v))
|
||||
}
|
||||
|
||||
// CreatorIDEQ applies the EQ predicate on the "creator_id" field.
|
||||
func CreatorIDEQ(v int64) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldEQ(FieldCreatorID, v))
|
||||
}
|
||||
|
||||
// CreatorIDNEQ applies the NEQ predicate on the "creator_id" field.
|
||||
func CreatorIDNEQ(v int64) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldNEQ(FieldCreatorID, v))
|
||||
}
|
||||
|
||||
// CreatorIDIn applies the In predicate on the "creator_id" field.
|
||||
func CreatorIDIn(vs ...int64) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldIn(FieldCreatorID, vs...))
|
||||
}
|
||||
|
||||
// CreatorIDNotIn applies the NotIn predicate on the "creator_id" field.
|
||||
func CreatorIDNotIn(vs ...int64) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.FieldNotIn(FieldCreatorID, vs...))
|
||||
}
|
||||
|
||||
// HasCreator applies the HasEdge predicate on the "creator" edge.
|
||||
func HasCreator() predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, CreatorTable, CreatorColumn),
|
||||
)
|
||||
schemaConfig := internal.SchemaConfigFromContext(s.Context())
|
||||
step.To.Schema = schemaConfig.SysUser
|
||||
step.Edge.Schema = schemaConfig.SysAnnouncement
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasCreatorWith applies the HasEdge predicate on the "creator" edge with a given conditions (other predicates).
|
||||
func HasCreatorWith(preds ...predicate.SysUser) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(func(s *sql.Selector) {
|
||||
step := newCreatorStep()
|
||||
schemaConfig := internal.SchemaConfigFromContext(s.Context())
|
||||
step.To.Schema = schemaConfig.SysUser
|
||||
step.Edge.Schema = schemaConfig.SysAnnouncement
|
||||
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.SysAnnouncement) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.SysAnnouncement) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.SysAnnouncement) predicate.SysAnnouncement {
|
||||
return predicate.SysAnnouncement(sql.NotPredicates(p))
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// SysBalanceRecord is the model entity for the SysBalanceRecord schema.
|
||||
type SysBalanceRecord struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int64 `json:"id,omitempty"`
|
||||
// CreateTime holds the value of the "create_time" field.
|
||||
CreateTime *ent2.CustomTime `json:"createTime"`
|
||||
// UpdateTime holds the value of the "update_time" field.
|
||||
UpdateTime *ent2.CustomTime `json:"updateTime"`
|
||||
// 用户ID
|
||||
UserID int64 `json:"user_id,omitempty"`
|
||||
// 变动类型:increase增加,decrease减少
|
||||
Type sysbalancerecord.Type `json:"type,omitempty"`
|
||||
// 变动金额
|
||||
Amount decimal.Decimal `json:"amount,omitempty"`
|
||||
// 变动原因
|
||||
Reason string `json:"reason,omitempty"`
|
||||
// 变动前余额
|
||||
BalanceBefore decimal.Decimal `json:"balance_before,omitempty"`
|
||||
// 变动后余额
|
||||
BalanceAfter decimal.Decimal `json:"balance_after,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the SysBalanceRecordQuery when eager-loading is set.
|
||||
Edges SysBalanceRecordEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// SysBalanceRecordEdges holds the relations/edges for other nodes in the graph.
|
||||
type SysBalanceRecordEdges struct {
|
||||
// User holds the value of the user edge.
|
||||
User *SysUser `json:"user,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// UserOrErr returns the User value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e SysBalanceRecordEdges) UserOrErr() (*SysUser, error) {
|
||||
if e.User != nil {
|
||||
return e.User, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: sysuser.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "user"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*SysBalanceRecord) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case sysbalancerecord.FieldAmount, sysbalancerecord.FieldBalanceBefore, sysbalancerecord.FieldBalanceAfter:
|
||||
values[i] = new(decimal.Decimal)
|
||||
case sysbalancerecord.FieldCreateTime, sysbalancerecord.FieldUpdateTime:
|
||||
values[i] = new(ent2.CustomTime)
|
||||
case sysbalancerecord.FieldID, sysbalancerecord.FieldUserID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case sysbalancerecord.FieldType, sysbalancerecord.FieldReason:
|
||||
values[i] = new(sql.NullString)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the SysBalanceRecord fields.
|
||||
func (_m *SysBalanceRecord) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case sysbalancerecord.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = int64(value.Int64)
|
||||
case sysbalancerecord.FieldCreateTime:
|
||||
if value, ok := values[i].(*ent2.CustomTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field create_time", values[i])
|
||||
} else if value != nil {
|
||||
_m.CreateTime = value
|
||||
}
|
||||
case sysbalancerecord.FieldUpdateTime:
|
||||
if value, ok := values[i].(*ent2.CustomTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field update_time", values[i])
|
||||
} else if value != nil {
|
||||
_m.UpdateTime = value
|
||||
}
|
||||
case sysbalancerecord.FieldUserID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field user_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.UserID = value.Int64
|
||||
}
|
||||
case sysbalancerecord.FieldType:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field type", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Type = sysbalancerecord.Type(value.String)
|
||||
}
|
||||
case sysbalancerecord.FieldAmount:
|
||||
if value, ok := values[i].(*decimal.Decimal); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field amount", values[i])
|
||||
} else if value != nil {
|
||||
_m.Amount = *value
|
||||
}
|
||||
case sysbalancerecord.FieldReason:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field reason", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Reason = value.String
|
||||
}
|
||||
case sysbalancerecord.FieldBalanceBefore:
|
||||
if value, ok := values[i].(*decimal.Decimal); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field balance_before", values[i])
|
||||
} else if value != nil {
|
||||
_m.BalanceBefore = *value
|
||||
}
|
||||
case sysbalancerecord.FieldBalanceAfter:
|
||||
if value, ok := values[i].(*decimal.Decimal); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field balance_after", values[i])
|
||||
} else if value != nil {
|
||||
_m.BalanceAfter = *value
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the SysBalanceRecord.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *SysBalanceRecord) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryUser queries the "user" edge of the SysBalanceRecord entity.
|
||||
func (_m *SysBalanceRecord) QueryUser() *SysUserQuery {
|
||||
return NewSysBalanceRecordClient(_m.config).QueryUser(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this SysBalanceRecord.
|
||||
// Note that you need to call SysBalanceRecord.Unwrap() before calling this method if this SysBalanceRecord
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *SysBalanceRecord) Update() *SysBalanceRecordUpdateOne {
|
||||
return NewSysBalanceRecordClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the SysBalanceRecord entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (_m *SysBalanceRecord) Unwrap() *SysBalanceRecord {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: SysBalanceRecord is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *SysBalanceRecord) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("SysBalanceRecord(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("create_time=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.CreateTime))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("update_time=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.UpdateTime))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("user_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.UserID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("type=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Type))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("amount=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Amount))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("reason=")
|
||||
builder.WriteString(_m.Reason)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("balance_before=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.BalanceBefore))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("balance_after=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.BalanceAfter))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// SysBalanceRecords is a parsable slice of SysBalanceRecord.
|
||||
type SysBalanceRecords []*SysBalanceRecord
|
||||
@@ -0,0 +1,167 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package sysbalancerecord
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the sysbalancerecord type in the database.
|
||||
Label = "sys_balance_record"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldCreateTime holds the string denoting the create_time field in the database.
|
||||
FieldCreateTime = "create_time"
|
||||
// FieldUpdateTime holds the string denoting the update_time field in the database.
|
||||
FieldUpdateTime = "update_time"
|
||||
// FieldUserID holds the string denoting the user_id field in the database.
|
||||
FieldUserID = "user_id"
|
||||
// FieldType holds the string denoting the type field in the database.
|
||||
FieldType = "type"
|
||||
// FieldAmount holds the string denoting the amount field in the database.
|
||||
FieldAmount = "amount"
|
||||
// FieldReason holds the string denoting the reason field in the database.
|
||||
FieldReason = "reason"
|
||||
// FieldBalanceBefore holds the string denoting the balance_before field in the database.
|
||||
FieldBalanceBefore = "balance_before"
|
||||
// FieldBalanceAfter holds the string denoting the balance_after field in the database.
|
||||
FieldBalanceAfter = "balance_after"
|
||||
// EdgeUser holds the string denoting the user edge name in mutations.
|
||||
EdgeUser = "user"
|
||||
// Table holds the table name of the sysbalancerecord in the database.
|
||||
Table = "sys_balance_record"
|
||||
// UserTable is the table that holds the user relation/edge.
|
||||
UserTable = "sys_balance_record"
|
||||
// UserInverseTable is the table name for the SysUser entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "sysuser" package.
|
||||
UserInverseTable = "sys_user"
|
||||
// UserColumn is the table column denoting the user relation/edge.
|
||||
UserColumn = "user_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for sysbalancerecord fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldCreateTime,
|
||||
FieldUpdateTime,
|
||||
FieldUserID,
|
||||
FieldType,
|
||||
FieldAmount,
|
||||
FieldReason,
|
||||
FieldBalanceBefore,
|
||||
FieldBalanceAfter,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Note that the variables below are initialized by the runtime
|
||||
// package on the initialization of the application. Therefore,
|
||||
// it should be imported in the main as follows:
|
||||
//
|
||||
// import _ "likedream-goframe/internal/ent/runtime"
|
||||
var (
|
||||
Hooks [1]ent.Hook
|
||||
// DefaultCreateTime holds the default value on creation for the "create_time" field.
|
||||
DefaultCreateTime func() *ent2.CustomTime
|
||||
// DefaultUpdateTime holds the default value on creation for the "update_time" field.
|
||||
DefaultUpdateTime func() *ent2.CustomTime
|
||||
)
|
||||
|
||||
// Type defines the type for the "type" enum field.
|
||||
type Type string
|
||||
|
||||
// Type values.
|
||||
const (
|
||||
TypeIncrease Type = "increase"
|
||||
TypeDecrease Type = "decrease"
|
||||
)
|
||||
|
||||
func (_type Type) String() string {
|
||||
return string(_type)
|
||||
}
|
||||
|
||||
// TypeValidator is a validator for the "type" field enum values. It is called by the builders before save.
|
||||
func TypeValidator(_type Type) error {
|
||||
switch _type {
|
||||
case TypeIncrease, TypeDecrease:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("sysbalancerecord: invalid enum value for type field: %q", _type)
|
||||
}
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the SysBalanceRecord queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreateTime orders the results by the create_time field.
|
||||
func ByCreateTime(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreateTime, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdateTime orders the results by the update_time field.
|
||||
func ByUpdateTime(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdateTime, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUserID orders the results by the user_id field.
|
||||
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUserID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByType orders the results by the type field.
|
||||
func ByType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldType, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAmount orders the results by the amount field.
|
||||
func ByAmount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldAmount, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByReason orders the results by the reason field.
|
||||
func ByReason(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldReason, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByBalanceBefore orders the results by the balance_before field.
|
||||
func ByBalanceBefore(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldBalanceBefore, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByBalanceAfter orders the results by the balance_after field.
|
||||
func ByBalanceAfter(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldBalanceAfter, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUserField orders the results by user field.
|
||||
func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newUserStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(UserInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,592 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package sysbalancerecord
|
||||
|
||||
import (
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ.
|
||||
func CreateTime(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTime applies equality check predicate on the "update_time" field. It's identical to UpdateTimeEQ.
|
||||
func UpdateTime(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
|
||||
func UserID(v int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// Amount applies equality check predicate on the "amount" field. It's identical to AmountEQ.
|
||||
func Amount(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldAmount, v))
|
||||
}
|
||||
|
||||
// Reason applies equality check predicate on the "reason" field. It's identical to ReasonEQ.
|
||||
func Reason(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldReason, v))
|
||||
}
|
||||
|
||||
// BalanceBefore applies equality check predicate on the "balance_before" field. It's identical to BalanceBeforeEQ.
|
||||
func BalanceBefore(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldBalanceBefore, v))
|
||||
}
|
||||
|
||||
// BalanceAfter applies equality check predicate on the "balance_after" field. It's identical to BalanceAfterEQ.
|
||||
func BalanceAfter(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldBalanceAfter, v))
|
||||
}
|
||||
|
||||
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||
func CreateTimeEQ(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||
func CreateTimeNEQ(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||
func CreateTimeIn(vs ...*ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||
func CreateTimeNotIn(vs ...*ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNotIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||
func CreateTimeGT(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||
func CreateTimeGTE(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||
func CreateTimeLT(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||
func CreateTimeLTE(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeContains applies the Contains predicate on the "create_time" field.
|
||||
func CreateTimeContains(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContains(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeHasPrefix applies the HasPrefix predicate on the "create_time" field.
|
||||
func CreateTimeHasPrefix(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasPrefix(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeHasSuffix applies the HasSuffix predicate on the "create_time" field.
|
||||
func CreateTimeHasSuffix(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasSuffix(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeEqualFold applies the EqualFold predicate on the "create_time" field.
|
||||
func CreateTimeEqualFold(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldEqualFold(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeContainsFold applies the ContainsFold predicate on the "create_time" field.
|
||||
func CreateTimeContainsFold(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContainsFold(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeEQ applies the EQ predicate on the "update_time" field.
|
||||
func UpdateTimeEQ(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeNEQ applies the NEQ predicate on the "update_time" field.
|
||||
func UpdateTimeNEQ(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeIn applies the In predicate on the "update_time" field.
|
||||
func UpdateTimeIn(vs ...*ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldIn(FieldUpdateTime, vs...))
|
||||
}
|
||||
|
||||
// UpdateTimeNotIn applies the NotIn predicate on the "update_time" field.
|
||||
func UpdateTimeNotIn(vs ...*ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNotIn(FieldUpdateTime, vs...))
|
||||
}
|
||||
|
||||
// UpdateTimeGT applies the GT predicate on the "update_time" field.
|
||||
func UpdateTimeGT(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGT(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeGTE applies the GTE predicate on the "update_time" field.
|
||||
func UpdateTimeGTE(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGTE(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeLT applies the LT predicate on the "update_time" field.
|
||||
func UpdateTimeLT(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLT(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeLTE applies the LTE predicate on the "update_time" field.
|
||||
func UpdateTimeLTE(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLTE(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeContains applies the Contains predicate on the "update_time" field.
|
||||
func UpdateTimeContains(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContains(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeHasPrefix applies the HasPrefix predicate on the "update_time" field.
|
||||
func UpdateTimeHasPrefix(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasPrefix(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeHasSuffix applies the HasSuffix predicate on the "update_time" field.
|
||||
func UpdateTimeHasSuffix(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasSuffix(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeEqualFold applies the EqualFold predicate on the "update_time" field.
|
||||
func UpdateTimeEqualFold(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldEqualFold(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeContainsFold applies the ContainsFold predicate on the "update_time" field.
|
||||
func UpdateTimeContainsFold(v *ent2.CustomTime) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContainsFold(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UserIDEQ applies the EQ predicate on the "user_id" field.
|
||||
func UserIDEQ(v int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
|
||||
func UserIDNEQ(v int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDIn applies the In predicate on the "user_id" field.
|
||||
func UserIDIn(vs ...int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
|
||||
func UserIDNotIn(vs ...int64) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNotIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// TypeEQ applies the EQ predicate on the "type" field.
|
||||
func TypeEQ(v Type) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeNEQ applies the NEQ predicate on the "type" field.
|
||||
func TypeNEQ(v Type) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeIn applies the In predicate on the "type" field.
|
||||
func TypeIn(vs ...Type) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// TypeNotIn applies the NotIn predicate on the "type" field.
|
||||
func TypeNotIn(vs ...Type) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNotIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// AmountEQ applies the EQ predicate on the "amount" field.
|
||||
func AmountEQ(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldAmount, v))
|
||||
}
|
||||
|
||||
// AmountNEQ applies the NEQ predicate on the "amount" field.
|
||||
func AmountNEQ(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNEQ(FieldAmount, v))
|
||||
}
|
||||
|
||||
// AmountIn applies the In predicate on the "amount" field.
|
||||
func AmountIn(vs ...decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldIn(FieldAmount, vs...))
|
||||
}
|
||||
|
||||
// AmountNotIn applies the NotIn predicate on the "amount" field.
|
||||
func AmountNotIn(vs ...decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNotIn(FieldAmount, vs...))
|
||||
}
|
||||
|
||||
// AmountGT applies the GT predicate on the "amount" field.
|
||||
func AmountGT(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGT(FieldAmount, v))
|
||||
}
|
||||
|
||||
// AmountGTE applies the GTE predicate on the "amount" field.
|
||||
func AmountGTE(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGTE(FieldAmount, v))
|
||||
}
|
||||
|
||||
// AmountLT applies the LT predicate on the "amount" field.
|
||||
func AmountLT(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLT(FieldAmount, v))
|
||||
}
|
||||
|
||||
// AmountLTE applies the LTE predicate on the "amount" field.
|
||||
func AmountLTE(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLTE(FieldAmount, v))
|
||||
}
|
||||
|
||||
// AmountContains applies the Contains predicate on the "amount" field.
|
||||
func AmountContains(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContains(FieldAmount, vc))
|
||||
}
|
||||
|
||||
// AmountHasPrefix applies the HasPrefix predicate on the "amount" field.
|
||||
func AmountHasPrefix(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasPrefix(FieldAmount, vc))
|
||||
}
|
||||
|
||||
// AmountHasSuffix applies the HasSuffix predicate on the "amount" field.
|
||||
func AmountHasSuffix(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasSuffix(FieldAmount, vc))
|
||||
}
|
||||
|
||||
// AmountEqualFold applies the EqualFold predicate on the "amount" field.
|
||||
func AmountEqualFold(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldEqualFold(FieldAmount, vc))
|
||||
}
|
||||
|
||||
// AmountContainsFold applies the ContainsFold predicate on the "amount" field.
|
||||
func AmountContainsFold(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContainsFold(FieldAmount, vc))
|
||||
}
|
||||
|
||||
// ReasonEQ applies the EQ predicate on the "reason" field.
|
||||
func ReasonEQ(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonNEQ applies the NEQ predicate on the "reason" field.
|
||||
func ReasonNEQ(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNEQ(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonIn applies the In predicate on the "reason" field.
|
||||
func ReasonIn(vs ...string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldIn(FieldReason, vs...))
|
||||
}
|
||||
|
||||
// ReasonNotIn applies the NotIn predicate on the "reason" field.
|
||||
func ReasonNotIn(vs ...string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNotIn(FieldReason, vs...))
|
||||
}
|
||||
|
||||
// ReasonGT applies the GT predicate on the "reason" field.
|
||||
func ReasonGT(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGT(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonGTE applies the GTE predicate on the "reason" field.
|
||||
func ReasonGTE(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGTE(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonLT applies the LT predicate on the "reason" field.
|
||||
func ReasonLT(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLT(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonLTE applies the LTE predicate on the "reason" field.
|
||||
func ReasonLTE(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLTE(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonContains applies the Contains predicate on the "reason" field.
|
||||
func ReasonContains(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldContains(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonHasPrefix applies the HasPrefix predicate on the "reason" field.
|
||||
func ReasonHasPrefix(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldHasPrefix(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonHasSuffix applies the HasSuffix predicate on the "reason" field.
|
||||
func ReasonHasSuffix(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldHasSuffix(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonEqualFold applies the EqualFold predicate on the "reason" field.
|
||||
func ReasonEqualFold(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEqualFold(FieldReason, v))
|
||||
}
|
||||
|
||||
// ReasonContainsFold applies the ContainsFold predicate on the "reason" field.
|
||||
func ReasonContainsFold(v string) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldContainsFold(FieldReason, v))
|
||||
}
|
||||
|
||||
// BalanceBeforeEQ applies the EQ predicate on the "balance_before" field.
|
||||
func BalanceBeforeEQ(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldBalanceBefore, v))
|
||||
}
|
||||
|
||||
// BalanceBeforeNEQ applies the NEQ predicate on the "balance_before" field.
|
||||
func BalanceBeforeNEQ(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNEQ(FieldBalanceBefore, v))
|
||||
}
|
||||
|
||||
// BalanceBeforeIn applies the In predicate on the "balance_before" field.
|
||||
func BalanceBeforeIn(vs ...decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldIn(FieldBalanceBefore, vs...))
|
||||
}
|
||||
|
||||
// BalanceBeforeNotIn applies the NotIn predicate on the "balance_before" field.
|
||||
func BalanceBeforeNotIn(vs ...decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNotIn(FieldBalanceBefore, vs...))
|
||||
}
|
||||
|
||||
// BalanceBeforeGT applies the GT predicate on the "balance_before" field.
|
||||
func BalanceBeforeGT(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGT(FieldBalanceBefore, v))
|
||||
}
|
||||
|
||||
// BalanceBeforeGTE applies the GTE predicate on the "balance_before" field.
|
||||
func BalanceBeforeGTE(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGTE(FieldBalanceBefore, v))
|
||||
}
|
||||
|
||||
// BalanceBeforeLT applies the LT predicate on the "balance_before" field.
|
||||
func BalanceBeforeLT(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLT(FieldBalanceBefore, v))
|
||||
}
|
||||
|
||||
// BalanceBeforeLTE applies the LTE predicate on the "balance_before" field.
|
||||
func BalanceBeforeLTE(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLTE(FieldBalanceBefore, v))
|
||||
}
|
||||
|
||||
// BalanceBeforeContains applies the Contains predicate on the "balance_before" field.
|
||||
func BalanceBeforeContains(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContains(FieldBalanceBefore, vc))
|
||||
}
|
||||
|
||||
// BalanceBeforeHasPrefix applies the HasPrefix predicate on the "balance_before" field.
|
||||
func BalanceBeforeHasPrefix(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasPrefix(FieldBalanceBefore, vc))
|
||||
}
|
||||
|
||||
// BalanceBeforeHasSuffix applies the HasSuffix predicate on the "balance_before" field.
|
||||
func BalanceBeforeHasSuffix(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasSuffix(FieldBalanceBefore, vc))
|
||||
}
|
||||
|
||||
// BalanceBeforeEqualFold applies the EqualFold predicate on the "balance_before" field.
|
||||
func BalanceBeforeEqualFold(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldEqualFold(FieldBalanceBefore, vc))
|
||||
}
|
||||
|
||||
// BalanceBeforeContainsFold applies the ContainsFold predicate on the "balance_before" field.
|
||||
func BalanceBeforeContainsFold(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContainsFold(FieldBalanceBefore, vc))
|
||||
}
|
||||
|
||||
// BalanceAfterEQ applies the EQ predicate on the "balance_after" field.
|
||||
func BalanceAfterEQ(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldEQ(FieldBalanceAfter, v))
|
||||
}
|
||||
|
||||
// BalanceAfterNEQ applies the NEQ predicate on the "balance_after" field.
|
||||
func BalanceAfterNEQ(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNEQ(FieldBalanceAfter, v))
|
||||
}
|
||||
|
||||
// BalanceAfterIn applies the In predicate on the "balance_after" field.
|
||||
func BalanceAfterIn(vs ...decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldIn(FieldBalanceAfter, vs...))
|
||||
}
|
||||
|
||||
// BalanceAfterNotIn applies the NotIn predicate on the "balance_after" field.
|
||||
func BalanceAfterNotIn(vs ...decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldNotIn(FieldBalanceAfter, vs...))
|
||||
}
|
||||
|
||||
// BalanceAfterGT applies the GT predicate on the "balance_after" field.
|
||||
func BalanceAfterGT(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGT(FieldBalanceAfter, v))
|
||||
}
|
||||
|
||||
// BalanceAfterGTE applies the GTE predicate on the "balance_after" field.
|
||||
func BalanceAfterGTE(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldGTE(FieldBalanceAfter, v))
|
||||
}
|
||||
|
||||
// BalanceAfterLT applies the LT predicate on the "balance_after" field.
|
||||
func BalanceAfterLT(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLT(FieldBalanceAfter, v))
|
||||
}
|
||||
|
||||
// BalanceAfterLTE applies the LTE predicate on the "balance_after" field.
|
||||
func BalanceAfterLTE(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.FieldLTE(FieldBalanceAfter, v))
|
||||
}
|
||||
|
||||
// BalanceAfterContains applies the Contains predicate on the "balance_after" field.
|
||||
func BalanceAfterContains(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContains(FieldBalanceAfter, vc))
|
||||
}
|
||||
|
||||
// BalanceAfterHasPrefix applies the HasPrefix predicate on the "balance_after" field.
|
||||
func BalanceAfterHasPrefix(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasPrefix(FieldBalanceAfter, vc))
|
||||
}
|
||||
|
||||
// BalanceAfterHasSuffix applies the HasSuffix predicate on the "balance_after" field.
|
||||
func BalanceAfterHasSuffix(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldHasSuffix(FieldBalanceAfter, vc))
|
||||
}
|
||||
|
||||
// BalanceAfterEqualFold applies the EqualFold predicate on the "balance_after" field.
|
||||
func BalanceAfterEqualFold(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldEqualFold(FieldBalanceAfter, vc))
|
||||
}
|
||||
|
||||
// BalanceAfterContainsFold applies the ContainsFold predicate on the "balance_after" field.
|
||||
func BalanceAfterContainsFold(v decimal.Decimal) predicate.SysBalanceRecord {
|
||||
vc := v.String()
|
||||
return predicate.SysBalanceRecord(sql.FieldContainsFold(FieldBalanceAfter, vc))
|
||||
}
|
||||
|
||||
// HasUser applies the HasEdge predicate on the "user" edge.
|
||||
func HasUser() predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||
)
|
||||
schemaConfig := internal.SchemaConfigFromContext(s.Context())
|
||||
step.To.Schema = schemaConfig.SysUser
|
||||
step.Edge.Schema = schemaConfig.SysBalanceRecord
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates).
|
||||
func HasUserWith(preds ...predicate.SysUser) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(func(s *sql.Selector) {
|
||||
step := newUserStep()
|
||||
schemaConfig := internal.SchemaConfigFromContext(s.Context())
|
||||
step.To.Schema = schemaConfig.SysUser
|
||||
step.Edge.Schema = schemaConfig.SysBalanceRecord
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.SysBalanceRecord) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.SysBalanceRecord) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.SysBalanceRecord) predicate.SysBalanceRecord {
|
||||
return predicate.SysBalanceRecord(sql.NotPredicates(p))
|
||||
}
|
||||
@@ -0,0 +1,851 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// SysBalanceRecordCreate is the builder for creating a SysBalanceRecord entity.
|
||||
type SysBalanceRecordCreate struct {
|
||||
config
|
||||
mutation *SysBalanceRecordMutation
|
||||
hooks []Hook
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// SetCreateTime sets the "create_time" field.
|
||||
func (_c *SysBalanceRecordCreate) SetCreateTime(v *ent2.CustomTime) *SysBalanceRecordCreate {
|
||||
_c.mutation.SetCreateTime(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (_c *SysBalanceRecordCreate) SetUpdateTime(v *ent2.CustomTime) *SysBalanceRecordCreate {
|
||||
_c.mutation.SetUpdateTime(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (_c *SysBalanceRecordCreate) SetUserID(v int64) *SysBalanceRecordCreate {
|
||||
_c.mutation.SetUserID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (_c *SysBalanceRecordCreate) SetType(v sysbalancerecord.Type) *SysBalanceRecordCreate {
|
||||
_c.mutation.SetType(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetAmount sets the "amount" field.
|
||||
func (_c *SysBalanceRecordCreate) SetAmount(v decimal.Decimal) *SysBalanceRecordCreate {
|
||||
_c.mutation.SetAmount(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetReason sets the "reason" field.
|
||||
func (_c *SysBalanceRecordCreate) SetReason(v string) *SysBalanceRecordCreate {
|
||||
_c.mutation.SetReason(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetBalanceBefore sets the "balance_before" field.
|
||||
func (_c *SysBalanceRecordCreate) SetBalanceBefore(v decimal.Decimal) *SysBalanceRecordCreate {
|
||||
_c.mutation.SetBalanceBefore(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetBalanceAfter sets the "balance_after" field.
|
||||
func (_c *SysBalanceRecordCreate) SetBalanceAfter(v decimal.Decimal) *SysBalanceRecordCreate {
|
||||
_c.mutation.SetBalanceAfter(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the SysUser entity.
|
||||
func (_c *SysBalanceRecordCreate) SetUser(v *SysUser) *SysBalanceRecordCreate {
|
||||
return _c.SetUserID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the SysBalanceRecordMutation object of the builder.
|
||||
func (_c *SysBalanceRecordCreate) Mutation() *SysBalanceRecordMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the SysBalanceRecord in the database.
|
||||
func (_c *SysBalanceRecordCreate) Save(ctx context.Context) (*SysBalanceRecord, error) {
|
||||
if err := _c.defaults(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *SysBalanceRecordCreate) SaveX(ctx context.Context) *SysBalanceRecord {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *SysBalanceRecordCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *SysBalanceRecordCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_c *SysBalanceRecordCreate) defaults() error {
|
||||
if _, ok := _c.mutation.CreateTime(); !ok {
|
||||
if sysbalancerecord.DefaultCreateTime == nil {
|
||||
return fmt.Errorf("ent: uninitialized sysbalancerecord.DefaultCreateTime (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := sysbalancerecord.DefaultCreateTime()
|
||||
_c.mutation.SetCreateTime(v)
|
||||
}
|
||||
if _, ok := _c.mutation.UpdateTime(); !ok {
|
||||
if sysbalancerecord.DefaultUpdateTime == nil {
|
||||
return fmt.Errorf("ent: uninitialized sysbalancerecord.DefaultUpdateTime (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := sysbalancerecord.DefaultUpdateTime()
|
||||
_c.mutation.SetUpdateTime(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *SysBalanceRecordCreate) check() error {
|
||||
if _, ok := _c.mutation.CreateTime(); !ok {
|
||||
return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "SysBalanceRecord.create_time"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UpdateTime(); !ok {
|
||||
return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "SysBalanceRecord.update_time"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "SysBalanceRecord.user_id"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.GetType(); !ok {
|
||||
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "SysBalanceRecord.type"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.GetType(); ok {
|
||||
if err := sysbalancerecord.TypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "SysBalanceRecord.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.Amount(); !ok {
|
||||
return &ValidationError{Name: "amount", err: errors.New(`ent: missing required field "SysBalanceRecord.amount"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Reason(); !ok {
|
||||
return &ValidationError{Name: "reason", err: errors.New(`ent: missing required field "SysBalanceRecord.reason"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.BalanceBefore(); !ok {
|
||||
return &ValidationError{Name: "balance_before", err: errors.New(`ent: missing required field "SysBalanceRecord.balance_before"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.BalanceAfter(); !ok {
|
||||
return &ValidationError{Name: "balance_after", err: errors.New(`ent: missing required field "SysBalanceRecord.balance_after"`)}
|
||||
}
|
||||
if len(_c.mutation.UserIDs()) == 0 {
|
||||
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "SysBalanceRecord.user"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *SysBalanceRecordCreate) sqlSave(ctx context.Context) (*SysBalanceRecord, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := _c.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int64(id)
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *SysBalanceRecordCreate) createSpec() (*SysBalanceRecord, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &SysBalanceRecord{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(sysbalancerecord.Table, sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64))
|
||||
)
|
||||
_spec.Schema = _c.schemaConfig.SysBalanceRecord
|
||||
_spec.OnConflict = _c.conflict
|
||||
if value, ok := _c.mutation.CreateTime(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldCreateTime, field.TypeString, value)
|
||||
_node.CreateTime = value
|
||||
}
|
||||
if value, ok := _c.mutation.UpdateTime(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldUpdateTime, field.TypeString, value)
|
||||
_node.UpdateTime = value
|
||||
}
|
||||
if value, ok := _c.mutation.GetType(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldType, field.TypeEnum, value)
|
||||
_node.Type = value
|
||||
}
|
||||
if value, ok := _c.mutation.Amount(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldAmount, field.TypeString, value)
|
||||
_node.Amount = value
|
||||
}
|
||||
if value, ok := _c.mutation.Reason(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldReason, field.TypeString, value)
|
||||
_node.Reason = value
|
||||
}
|
||||
if value, ok := _c.mutation.BalanceBefore(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldBalanceBefore, field.TypeString, value)
|
||||
_node.BalanceBefore = value
|
||||
}
|
||||
if value, ok := _c.mutation.BalanceAfter(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldBalanceAfter, field.TypeString, value)
|
||||
_node.BalanceAfter = value
|
||||
}
|
||||
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: sysbalancerecord.UserTable,
|
||||
Columns: []string{sysbalancerecord.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _c.schemaConfig.SysBalanceRecord
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.UserID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||
// of the `INSERT` statement. For example:
|
||||
//
|
||||
// client.SysBalanceRecord.Create().
|
||||
// SetCreateTime(v).
|
||||
// OnConflict(
|
||||
// // Update the row with the new values
|
||||
// // the was proposed for insertion.
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// // Override some of the fields with custom
|
||||
// // update values.
|
||||
// Update(func(u *ent.SysBalanceRecordUpsert) {
|
||||
// SetCreateTime(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (_c *SysBalanceRecordCreate) OnConflict(opts ...sql.ConflictOption) *SysBalanceRecordUpsertOne {
|
||||
_c.conflict = opts
|
||||
return &SysBalanceRecordUpsertOne{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||
// as conflict target. Using this option is equivalent to using:
|
||||
//
|
||||
// client.SysBalanceRecord.Create().
|
||||
// OnConflict(sql.ConflictColumns(columns...)).
|
||||
// Exec(ctx)
|
||||
func (_c *SysBalanceRecordCreate) OnConflictColumns(columns ...string) *SysBalanceRecordUpsertOne {
|
||||
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||||
return &SysBalanceRecordUpsertOne{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
type (
|
||||
// SysBalanceRecordUpsertOne is the builder for "upsert"-ing
|
||||
// one SysBalanceRecord node.
|
||||
SysBalanceRecordUpsertOne struct {
|
||||
create *SysBalanceRecordCreate
|
||||
}
|
||||
|
||||
// SysBalanceRecordUpsert is the "OnConflict" setter.
|
||||
SysBalanceRecordUpsert struct {
|
||||
*sql.UpdateSet
|
||||
}
|
||||
)
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (u *SysBalanceRecordUpsert) SetUpdateTime(v *ent2.CustomTime) *SysBalanceRecordUpsert {
|
||||
u.Set(sysbalancerecord.FieldUpdateTime, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsert) UpdateUpdateTime() *SysBalanceRecordUpsert {
|
||||
u.SetExcluded(sysbalancerecord.FieldUpdateTime)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (u *SysBalanceRecordUpsert) SetUserID(v int64) *SysBalanceRecordUpsert {
|
||||
u.Set(sysbalancerecord.FieldUserID, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsert) UpdateUserID() *SysBalanceRecordUpsert {
|
||||
u.SetExcluded(sysbalancerecord.FieldUserID)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (u *SysBalanceRecordUpsert) SetType(v sysbalancerecord.Type) *SysBalanceRecordUpsert {
|
||||
u.Set(sysbalancerecord.FieldType, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateType sets the "type" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsert) UpdateType() *SysBalanceRecordUpsert {
|
||||
u.SetExcluded(sysbalancerecord.FieldType)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetAmount sets the "amount" field.
|
||||
func (u *SysBalanceRecordUpsert) SetAmount(v decimal.Decimal) *SysBalanceRecordUpsert {
|
||||
u.Set(sysbalancerecord.FieldAmount, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateAmount sets the "amount" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsert) UpdateAmount() *SysBalanceRecordUpsert {
|
||||
u.SetExcluded(sysbalancerecord.FieldAmount)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetReason sets the "reason" field.
|
||||
func (u *SysBalanceRecordUpsert) SetReason(v string) *SysBalanceRecordUpsert {
|
||||
u.Set(sysbalancerecord.FieldReason, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateReason sets the "reason" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsert) UpdateReason() *SysBalanceRecordUpsert {
|
||||
u.SetExcluded(sysbalancerecord.FieldReason)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetBalanceBefore sets the "balance_before" field.
|
||||
func (u *SysBalanceRecordUpsert) SetBalanceBefore(v decimal.Decimal) *SysBalanceRecordUpsert {
|
||||
u.Set(sysbalancerecord.FieldBalanceBefore, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateBalanceBefore sets the "balance_before" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsert) UpdateBalanceBefore() *SysBalanceRecordUpsert {
|
||||
u.SetExcluded(sysbalancerecord.FieldBalanceBefore)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetBalanceAfter sets the "balance_after" field.
|
||||
func (u *SysBalanceRecordUpsert) SetBalanceAfter(v decimal.Decimal) *SysBalanceRecordUpsert {
|
||||
u.Set(sysbalancerecord.FieldBalanceAfter, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateBalanceAfter sets the "balance_after" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsert) UpdateBalanceAfter() *SysBalanceRecordUpsert {
|
||||
u.SetExcluded(sysbalancerecord.FieldBalanceAfter)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.SysBalanceRecord.Create().
|
||||
// OnConflict(
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// Exec(ctx)
|
||||
func (u *SysBalanceRecordUpsertOne) UpdateNewValues() *SysBalanceRecordUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||
if _, exists := u.create.mutation.CreateTime(); exists {
|
||||
s.SetIgnore(sysbalancerecord.FieldCreateTime)
|
||||
}
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// Ignore sets each column to itself in case of conflict.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.SysBalanceRecord.Create().
|
||||
// OnConflict(sql.ResolveWithIgnore()).
|
||||
// Exec(ctx)
|
||||
func (u *SysBalanceRecordUpsertOne) Ignore() *SysBalanceRecordUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||
return u
|
||||
}
|
||||
|
||||
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||
// Supported only by SQLite and PostgreSQL.
|
||||
func (u *SysBalanceRecordUpsertOne) DoNothing() *SysBalanceRecordUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||
return u
|
||||
}
|
||||
|
||||
// Update allows overriding fields `UPDATE` values. See the SysBalanceRecordCreate.OnConflict
|
||||
// documentation for more info.
|
||||
func (u *SysBalanceRecordUpsertOne) Update(set func(*SysBalanceRecordUpsert)) *SysBalanceRecordUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||
set(&SysBalanceRecordUpsert{UpdateSet: update})
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (u *SysBalanceRecordUpsertOne) SetUpdateTime(v *ent2.CustomTime) *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetUpdateTime(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertOne) UpdateUpdateTime() *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateUpdateTime()
|
||||
})
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (u *SysBalanceRecordUpsertOne) SetUserID(v int64) *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetUserID(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertOne) UpdateUserID() *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateUserID()
|
||||
})
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (u *SysBalanceRecordUpsertOne) SetType(v sysbalancerecord.Type) *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetType(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateType sets the "type" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertOne) UpdateType() *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateType()
|
||||
})
|
||||
}
|
||||
|
||||
// SetAmount sets the "amount" field.
|
||||
func (u *SysBalanceRecordUpsertOne) SetAmount(v decimal.Decimal) *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetAmount(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateAmount sets the "amount" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertOne) UpdateAmount() *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateAmount()
|
||||
})
|
||||
}
|
||||
|
||||
// SetReason sets the "reason" field.
|
||||
func (u *SysBalanceRecordUpsertOne) SetReason(v string) *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetReason(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateReason sets the "reason" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertOne) UpdateReason() *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateReason()
|
||||
})
|
||||
}
|
||||
|
||||
// SetBalanceBefore sets the "balance_before" field.
|
||||
func (u *SysBalanceRecordUpsertOne) SetBalanceBefore(v decimal.Decimal) *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetBalanceBefore(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateBalanceBefore sets the "balance_before" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertOne) UpdateBalanceBefore() *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateBalanceBefore()
|
||||
})
|
||||
}
|
||||
|
||||
// SetBalanceAfter sets the "balance_after" field.
|
||||
func (u *SysBalanceRecordUpsertOne) SetBalanceAfter(v decimal.Decimal) *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetBalanceAfter(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateBalanceAfter sets the "balance_after" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertOne) UpdateBalanceAfter() *SysBalanceRecordUpsertOne {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateBalanceAfter()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *SysBalanceRecordUpsertOne) Exec(ctx context.Context) error {
|
||||
if len(u.create.conflict) == 0 {
|
||||
return errors.New("ent: missing options for SysBalanceRecordCreate.OnConflict")
|
||||
}
|
||||
return u.create.Exec(ctx)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (u *SysBalanceRecordUpsertOne) ExecX(ctx context.Context) {
|
||||
if err := u.create.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Exec executes the UPSERT query and returns the inserted/updated ID.
|
||||
func (u *SysBalanceRecordUpsertOne) ID(ctx context.Context) (id int64, err error) {
|
||||
node, err := u.create.Save(ctx)
|
||||
if err != nil {
|
||||
return id, err
|
||||
}
|
||||
return node.ID, nil
|
||||
}
|
||||
|
||||
// IDX is like ID, but panics if an error occurs.
|
||||
func (u *SysBalanceRecordUpsertOne) IDX(ctx context.Context) int64 {
|
||||
id, err := u.ID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// SysBalanceRecordCreateBulk is the builder for creating many SysBalanceRecord entities in bulk.
|
||||
type SysBalanceRecordCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*SysBalanceRecordCreate
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// Save creates the SysBalanceRecord entities in the database.
|
||||
func (_c *SysBalanceRecordCreateBulk) Save(ctx context.Context) ([]*SysBalanceRecord, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*SysBalanceRecord, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*SysBalanceRecordMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
spec.OnConflict = _c.conflict
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int64(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *SysBalanceRecordCreateBulk) SaveX(ctx context.Context) []*SysBalanceRecord {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *SysBalanceRecordCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *SysBalanceRecordCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||
// of the `INSERT` statement. For example:
|
||||
//
|
||||
// client.SysBalanceRecord.CreateBulk(builders...).
|
||||
// OnConflict(
|
||||
// // Update the row with the new values
|
||||
// // the was proposed for insertion.
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// // Override some of the fields with custom
|
||||
// // update values.
|
||||
// Update(func(u *ent.SysBalanceRecordUpsert) {
|
||||
// SetCreateTime(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (_c *SysBalanceRecordCreateBulk) OnConflict(opts ...sql.ConflictOption) *SysBalanceRecordUpsertBulk {
|
||||
_c.conflict = opts
|
||||
return &SysBalanceRecordUpsertBulk{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||
// as conflict target. Using this option is equivalent to using:
|
||||
//
|
||||
// client.SysBalanceRecord.Create().
|
||||
// OnConflict(sql.ConflictColumns(columns...)).
|
||||
// Exec(ctx)
|
||||
func (_c *SysBalanceRecordCreateBulk) OnConflictColumns(columns ...string) *SysBalanceRecordUpsertBulk {
|
||||
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||||
return &SysBalanceRecordUpsertBulk{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
// SysBalanceRecordUpsertBulk is the builder for "upsert"-ing
|
||||
// a bulk of SysBalanceRecord nodes.
|
||||
type SysBalanceRecordUpsertBulk struct {
|
||||
create *SysBalanceRecordCreateBulk
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that
|
||||
// were set on create. Using this option is equivalent to using:
|
||||
//
|
||||
// client.SysBalanceRecord.Create().
|
||||
// OnConflict(
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// Exec(ctx)
|
||||
func (u *SysBalanceRecordUpsertBulk) UpdateNewValues() *SysBalanceRecordUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||
for _, b := range u.create.builders {
|
||||
if _, exists := b.mutation.CreateTime(); exists {
|
||||
s.SetIgnore(sysbalancerecord.FieldCreateTime)
|
||||
}
|
||||
}
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// Ignore sets each column to itself in case of conflict.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.SysBalanceRecord.Create().
|
||||
// OnConflict(sql.ResolveWithIgnore()).
|
||||
// Exec(ctx)
|
||||
func (u *SysBalanceRecordUpsertBulk) Ignore() *SysBalanceRecordUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||
return u
|
||||
}
|
||||
|
||||
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||
// Supported only by SQLite and PostgreSQL.
|
||||
func (u *SysBalanceRecordUpsertBulk) DoNothing() *SysBalanceRecordUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||
return u
|
||||
}
|
||||
|
||||
// Update allows overriding fields `UPDATE` values. See the SysBalanceRecordCreateBulk.OnConflict
|
||||
// documentation for more info.
|
||||
func (u *SysBalanceRecordUpsertBulk) Update(set func(*SysBalanceRecordUpsert)) *SysBalanceRecordUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||
set(&SysBalanceRecordUpsert{UpdateSet: update})
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (u *SysBalanceRecordUpsertBulk) SetUpdateTime(v *ent2.CustomTime) *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetUpdateTime(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertBulk) UpdateUpdateTime() *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateUpdateTime()
|
||||
})
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (u *SysBalanceRecordUpsertBulk) SetUserID(v int64) *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetUserID(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertBulk) UpdateUserID() *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateUserID()
|
||||
})
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (u *SysBalanceRecordUpsertBulk) SetType(v sysbalancerecord.Type) *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetType(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateType sets the "type" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertBulk) UpdateType() *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateType()
|
||||
})
|
||||
}
|
||||
|
||||
// SetAmount sets the "amount" field.
|
||||
func (u *SysBalanceRecordUpsertBulk) SetAmount(v decimal.Decimal) *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetAmount(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateAmount sets the "amount" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertBulk) UpdateAmount() *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateAmount()
|
||||
})
|
||||
}
|
||||
|
||||
// SetReason sets the "reason" field.
|
||||
func (u *SysBalanceRecordUpsertBulk) SetReason(v string) *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetReason(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateReason sets the "reason" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertBulk) UpdateReason() *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateReason()
|
||||
})
|
||||
}
|
||||
|
||||
// SetBalanceBefore sets the "balance_before" field.
|
||||
func (u *SysBalanceRecordUpsertBulk) SetBalanceBefore(v decimal.Decimal) *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetBalanceBefore(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateBalanceBefore sets the "balance_before" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertBulk) UpdateBalanceBefore() *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateBalanceBefore()
|
||||
})
|
||||
}
|
||||
|
||||
// SetBalanceAfter sets the "balance_after" field.
|
||||
func (u *SysBalanceRecordUpsertBulk) SetBalanceAfter(v decimal.Decimal) *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.SetBalanceAfter(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateBalanceAfter sets the "balance_after" field to the value that was provided on create.
|
||||
func (u *SysBalanceRecordUpsertBulk) UpdateBalanceAfter() *SysBalanceRecordUpsertBulk {
|
||||
return u.Update(func(s *SysBalanceRecordUpsert) {
|
||||
s.UpdateBalanceAfter()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *SysBalanceRecordUpsertBulk) Exec(ctx context.Context) error {
|
||||
if u.create.err != nil {
|
||||
return u.create.err
|
||||
}
|
||||
for i, b := range u.create.builders {
|
||||
if len(b.conflict) != 0 {
|
||||
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the SysBalanceRecordCreateBulk instead", i)
|
||||
}
|
||||
}
|
||||
if len(u.create.conflict) == 0 {
|
||||
return errors.New("ent: missing options for SysBalanceRecordCreateBulk.OnConflict")
|
||||
}
|
||||
return u.create.Exec(ctx)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (u *SysBalanceRecordUpsertBulk) ExecX(ctx context.Context) {
|
||||
if err := u.create.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// SysBalanceRecordDelete is the builder for deleting a SysBalanceRecord entity.
|
||||
type SysBalanceRecordDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SysBalanceRecordMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SysBalanceRecordDelete builder.
|
||||
func (_d *SysBalanceRecordDelete) Where(ps ...predicate.SysBalanceRecord) *SysBalanceRecordDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *SysBalanceRecordDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *SysBalanceRecordDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *SysBalanceRecordDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(sysbalancerecord.Table, sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64))
|
||||
_spec.Node.Schema = _d.schemaConfig.SysBalanceRecord
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _d.schemaConfig)
|
||||
if ps := _d.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
_d.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// SysBalanceRecordDeleteOne is the builder for deleting a single SysBalanceRecord entity.
|
||||
type SysBalanceRecordDeleteOne struct {
|
||||
_d *SysBalanceRecordDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SysBalanceRecordDelete builder.
|
||||
func (_d *SysBalanceRecordDeleteOne) Where(ps ...predicate.SysBalanceRecord) *SysBalanceRecordDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *SysBalanceRecordDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{sysbalancerecord.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *SysBalanceRecordDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,667 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// SysBalanceRecordQuery is the builder for querying SysBalanceRecord entities.
|
||||
type SysBalanceRecordQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []sysbalancerecord.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.SysBalanceRecord
|
||||
withUser *SysUserQuery
|
||||
modifiers []func(*sql.Selector)
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the SysBalanceRecordQuery builder.
|
||||
func (_q *SysBalanceRecordQuery) Where(ps ...predicate.SysBalanceRecord) *SysBalanceRecordQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *SysBalanceRecordQuery) Limit(limit int) *SysBalanceRecordQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *SysBalanceRecordQuery) Offset(offset int) *SysBalanceRecordQuery {
|
||||
_q.ctx.Offset = &offset
|
||||
return _q
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (_q *SysBalanceRecordQuery) Unique(unique bool) *SysBalanceRecordQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *SysBalanceRecordQuery) Order(o ...sysbalancerecord.OrderOption) *SysBalanceRecordQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryUser chains the current query on the "user" edge.
|
||||
func (_q *SysBalanceRecordQuery) QueryUser() *SysUserQuery {
|
||||
query := (&SysUserClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(sysbalancerecord.Table, sysbalancerecord.FieldID, selector),
|
||||
sqlgraph.To(sysuser.Table, sysuser.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, sysbalancerecord.UserTable, sysbalancerecord.UserColumn),
|
||||
)
|
||||
schemaConfig := _q.schemaConfig
|
||||
step.To.Schema = schemaConfig.SysUser
|
||||
step.Edge.Schema = schemaConfig.SysBalanceRecord
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first SysBalanceRecord entity from the query.
|
||||
// Returns a *NotFoundError when no SysBalanceRecord was found.
|
||||
func (_q *SysBalanceRecordQuery) First(ctx context.Context) (*SysBalanceRecord, error) {
|
||||
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{sysbalancerecord.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *SysBalanceRecordQuery) FirstX(ctx context.Context) *SysBalanceRecord {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first SysBalanceRecord ID from the query.
|
||||
// Returns a *NotFoundError when no SysBalanceRecord ID was found.
|
||||
func (_q *SysBalanceRecordQuery) FirstID(ctx context.Context) (id int64, err error) {
|
||||
var ids []int64
|
||||
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{sysbalancerecord.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *SysBalanceRecordQuery) FirstIDX(ctx context.Context) int64 {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single SysBalanceRecord entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one SysBalanceRecord entity is found.
|
||||
// Returns a *NotFoundError when no SysBalanceRecord entities are found.
|
||||
func (_q *SysBalanceRecordQuery) Only(ctx context.Context) (*SysBalanceRecord, error) {
|
||||
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{sysbalancerecord.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{sysbalancerecord.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *SysBalanceRecordQuery) OnlyX(ctx context.Context) *SysBalanceRecord {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only SysBalanceRecord ID in the query.
|
||||
// Returns a *NotSingularError when more than one SysBalanceRecord ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *SysBalanceRecordQuery) OnlyID(ctx context.Context) (id int64, err error) {
|
||||
var ids []int64
|
||||
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{sysbalancerecord.Label}
|
||||
default:
|
||||
err = &NotSingularError{sysbalancerecord.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *SysBalanceRecordQuery) OnlyIDX(ctx context.Context) int64 {
|
||||
id, err := _q.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of SysBalanceRecords.
|
||||
func (_q *SysBalanceRecordQuery) All(ctx context.Context) ([]*SysBalanceRecord, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*SysBalanceRecord, *SysBalanceRecordQuery]()
|
||||
return withInterceptors[[]*SysBalanceRecord](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *SysBalanceRecordQuery) AllX(ctx context.Context) []*SysBalanceRecord {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of SysBalanceRecord IDs.
|
||||
func (_q *SysBalanceRecordQuery) IDs(ctx context.Context) (ids []int64, err error) {
|
||||
if _q.ctx.Unique == nil && _q.path != nil {
|
||||
_q.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||
if err = _q.Select(sysbalancerecord.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *SysBalanceRecordQuery) IDsX(ctx context.Context) []int64 {
|
||||
ids, err := _q.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (_q *SysBalanceRecordQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, _q, querierCount[*SysBalanceRecordQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *SysBalanceRecordQuery) CountX(ctx context.Context) int {
|
||||
count, err := _q.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (_q *SysBalanceRecordQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
|
||||
switch _, err := _q.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *SysBalanceRecordQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the SysBalanceRecordQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (_q *SysBalanceRecordQuery) Clone() *SysBalanceRecordQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &SysBalanceRecordQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]sysbalancerecord.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.SysBalanceRecord{}, _q.predicates...),
|
||||
withUser: _q.withUser.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
modifiers: append([]func(*sql.Selector){}, _q.modifiers...),
|
||||
}
|
||||
}
|
||||
|
||||
// WithUser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *SysBalanceRecordQuery) WithUser(opts ...func(*SysUserQuery)) *SysBalanceRecordQuery {
|
||||
query := (&SysUserClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withUser = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreateTime *ent2.CustomTime `json:"createTime"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.SysBalanceRecord.Query().
|
||||
// GroupBy(sysbalancerecord.FieldCreateTime).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *SysBalanceRecordQuery) GroupBy(field string, fields ...string) *SysBalanceRecordGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &SysBalanceRecordGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = sysbalancerecord.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreateTime *ent2.CustomTime `json:"createTime"`
|
||||
// }
|
||||
//
|
||||
// client.SysBalanceRecord.Query().
|
||||
// Select(sysbalancerecord.FieldCreateTime).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *SysBalanceRecordQuery) Select(fields ...string) *SysBalanceRecordSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &SysBalanceRecordSelect{SysBalanceRecordQuery: _q}
|
||||
sbuild.label = sysbalancerecord.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a SysBalanceRecordSelect configured with the given aggregations.
|
||||
func (_q *SysBalanceRecordQuery) Aggregate(fns ...AggregateFunc) *SysBalanceRecordSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *SysBalanceRecordQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !sysbalancerecord.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if _q.path != nil {
|
||||
prev, err := _q.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_q.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *SysBalanceRecordQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysBalanceRecord, error) {
|
||||
var (
|
||||
nodes = []*SysBalanceRecord{}
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
_q.withUser != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*SysBalanceRecord).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &SysBalanceRecord{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
_spec.Node.Schema = _q.schemaConfig.SysBalanceRecord
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _q.schemaConfig)
|
||||
if len(_q.modifiers) > 0 {
|
||||
_spec.Modifiers = _q.modifiers
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := _q.withUser; query != nil {
|
||||
if err := _q.loadUser(ctx, query, nodes, nil,
|
||||
func(n *SysBalanceRecord, e *SysUser) { n.Edges.User = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *SysBalanceRecordQuery) loadUser(ctx context.Context, query *SysUserQuery, nodes []*SysBalanceRecord, init func(*SysBalanceRecord), assign func(*SysBalanceRecord, *SysUser)) error {
|
||||
ids := make([]int64, 0, len(nodes))
|
||||
nodeids := make(map[int64][]*SysBalanceRecord)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].UserID
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(sysuser.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "user_id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *SysBalanceRecordQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
_spec.Node.Schema = _q.schemaConfig.SysBalanceRecord
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _q.schemaConfig)
|
||||
if len(_q.modifiers) > 0 {
|
||||
_spec.Modifiers = _q.modifiers
|
||||
}
|
||||
_spec.Node.Columns = _q.ctx.Fields
|
||||
if len(_q.ctx.Fields) > 0 {
|
||||
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
|
||||
}
|
||||
|
||||
func (_q *SysBalanceRecordQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(sysbalancerecord.Table, sysbalancerecord.Columns, sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64))
|
||||
_spec.From = _q.sql
|
||||
if unique := _q.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if _q.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, sysbalancerecord.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != sysbalancerecord.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
if _q.withUser != nil {
|
||||
_spec.Node.AddColumnOnce(sysbalancerecord.FieldUserID)
|
||||
}
|
||||
}
|
||||
if ps := _q.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := _q.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (_q *SysBalanceRecordQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(sysbalancerecord.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = sysbalancerecord.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if _q.sql != nil {
|
||||
selector = _q.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
t1.Schema(_q.schemaConfig.SysBalanceRecord)
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _q.schemaConfig)
|
||||
selector.WithContext(ctx)
|
||||
for _, m := range _q.modifiers {
|
||||
m(selector)
|
||||
}
|
||||
for _, p := range _q.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range _q.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
|
||||
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
|
||||
// either committed or rolled-back.
|
||||
func (_q *SysBalanceRecordQuery) ForUpdate(opts ...sql.LockOption) *SysBalanceRecordQuery {
|
||||
if _q.driver.Dialect() == dialect.Postgres {
|
||||
_q.Unique(false)
|
||||
}
|
||||
_q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
|
||||
s.ForUpdate(opts...)
|
||||
})
|
||||
return _q
|
||||
}
|
||||
|
||||
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
|
||||
// on any rows that are read. Other sessions can read the rows, but cannot modify them
|
||||
// until your transaction commits.
|
||||
func (_q *SysBalanceRecordQuery) ForShare(opts ...sql.LockOption) *SysBalanceRecordQuery {
|
||||
if _q.driver.Dialect() == dialect.Postgres {
|
||||
_q.Unique(false)
|
||||
}
|
||||
_q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
|
||||
s.ForShare(opts...)
|
||||
})
|
||||
return _q
|
||||
}
|
||||
|
||||
// Modify adds a query modifier for attaching custom logic to queries.
|
||||
func (_q *SysBalanceRecordQuery) Modify(modifiers ...func(s *sql.Selector)) *SysBalanceRecordSelect {
|
||||
_q.modifiers = append(_q.modifiers, modifiers...)
|
||||
return _q.Select()
|
||||
}
|
||||
|
||||
// SysBalanceRecordGroupBy is the group-by builder for SysBalanceRecord entities.
|
||||
type SysBalanceRecordGroupBy struct {
|
||||
selector
|
||||
build *SysBalanceRecordQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *SysBalanceRecordGroupBy) Aggregate(fns ...AggregateFunc) *SysBalanceRecordGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *SysBalanceRecordGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*SysBalanceRecordQuery, *SysBalanceRecordGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *SysBalanceRecordGroupBy) sqlScan(ctx context.Context, root *SysBalanceRecordQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(_g.fns))
|
||||
for _, fn := range _g.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||
for _, f := range *_g.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// SysBalanceRecordSelect is the builder for selecting fields of SysBalanceRecord entities.
|
||||
type SysBalanceRecordSelect struct {
|
||||
*SysBalanceRecordQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *SysBalanceRecordSelect) Aggregate(fns ...AggregateFunc) *SysBalanceRecordSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *SysBalanceRecordSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||
if err := _s.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*SysBalanceRecordQuery, *SysBalanceRecordSelect](ctx, _s.SysBalanceRecordQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *SysBalanceRecordSelect) sqlScan(ctx context.Context, root *SysBalanceRecordQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*_s.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// Modify adds a query modifier for attaching custom logic to queries.
|
||||
func (_s *SysBalanceRecordSelect) Modify(modifiers ...func(s *sql.Selector)) *SysBalanceRecordSelect {
|
||||
_s.modifiers = append(_s.modifiers, modifiers...)
|
||||
return _s
|
||||
}
|
||||
@@ -0,0 +1,531 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// SysBalanceRecordUpdate is the builder for updating SysBalanceRecord entities.
|
||||
type SysBalanceRecordUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SysBalanceRecordMutation
|
||||
modifiers []func(*sql.UpdateBuilder)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SysBalanceRecordUpdate builder.
|
||||
func (_u *SysBalanceRecordUpdate) Where(ps ...predicate.SysBalanceRecord) *SysBalanceRecordUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (_u *SysBalanceRecordUpdate) SetUpdateTime(v *ent2.CustomTime) *SysBalanceRecordUpdate {
|
||||
_u.mutation.SetUpdateTime(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (_u *SysBalanceRecordUpdate) SetUserID(v int64) *SysBalanceRecordUpdate {
|
||||
_u.mutation.SetUserID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdate) SetNillableUserID(v *int64) *SysBalanceRecordUpdate {
|
||||
if v != nil {
|
||||
_u.SetUserID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (_u *SysBalanceRecordUpdate) SetType(v sysbalancerecord.Type) *SysBalanceRecordUpdate {
|
||||
_u.mutation.SetType(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdate) SetNillableType(v *sysbalancerecord.Type) *SysBalanceRecordUpdate {
|
||||
if v != nil {
|
||||
_u.SetType(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetAmount sets the "amount" field.
|
||||
func (_u *SysBalanceRecordUpdate) SetAmount(v decimal.Decimal) *SysBalanceRecordUpdate {
|
||||
_u.mutation.SetAmount(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableAmount sets the "amount" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdate) SetNillableAmount(v *decimal.Decimal) *SysBalanceRecordUpdate {
|
||||
if v != nil {
|
||||
_u.SetAmount(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetReason sets the "reason" field.
|
||||
func (_u *SysBalanceRecordUpdate) SetReason(v string) *SysBalanceRecordUpdate {
|
||||
_u.mutation.SetReason(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableReason sets the "reason" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdate) SetNillableReason(v *string) *SysBalanceRecordUpdate {
|
||||
if v != nil {
|
||||
_u.SetReason(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetBalanceBefore sets the "balance_before" field.
|
||||
func (_u *SysBalanceRecordUpdate) SetBalanceBefore(v decimal.Decimal) *SysBalanceRecordUpdate {
|
||||
_u.mutation.SetBalanceBefore(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableBalanceBefore sets the "balance_before" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdate) SetNillableBalanceBefore(v *decimal.Decimal) *SysBalanceRecordUpdate {
|
||||
if v != nil {
|
||||
_u.SetBalanceBefore(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetBalanceAfter sets the "balance_after" field.
|
||||
func (_u *SysBalanceRecordUpdate) SetBalanceAfter(v decimal.Decimal) *SysBalanceRecordUpdate {
|
||||
_u.mutation.SetBalanceAfter(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableBalanceAfter sets the "balance_after" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdate) SetNillableBalanceAfter(v *decimal.Decimal) *SysBalanceRecordUpdate {
|
||||
if v != nil {
|
||||
_u.SetBalanceAfter(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the SysUser entity.
|
||||
func (_u *SysBalanceRecordUpdate) SetUser(v *SysUser) *SysBalanceRecordUpdate {
|
||||
return _u.SetUserID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the SysBalanceRecordMutation object of the builder.
|
||||
func (_u *SysBalanceRecordUpdate) Mutation() *SysBalanceRecordMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the SysUser entity.
|
||||
func (_u *SysBalanceRecordUpdate) ClearUser() *SysBalanceRecordUpdate {
|
||||
_u.mutation.ClearUser()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *SysBalanceRecordUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *SysBalanceRecordUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *SysBalanceRecordUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *SysBalanceRecordUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *SysBalanceRecordUpdate) check() error {
|
||||
if v, ok := _u.mutation.GetType(); ok {
|
||||
if err := sysbalancerecord.TypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "SysBalanceRecord.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "SysBalanceRecord.user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
||||
func (_u *SysBalanceRecordUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *SysBalanceRecordUpdate {
|
||||
_u.modifiers = append(_u.modifiers, modifiers...)
|
||||
return _u
|
||||
}
|
||||
|
||||
func (_u *SysBalanceRecordUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(sysbalancerecord.Table, sysbalancerecord.Columns, sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64))
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.UpdateTime(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldUpdateTime, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.GetType(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Amount(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldAmount, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Reason(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldReason, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.BalanceBefore(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldBalanceBefore, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.BalanceAfter(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldBalanceAfter, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.UserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: sysbalancerecord.UserTable,
|
||||
Columns: []string{sysbalancerecord.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: sysbalancerecord.UserTable,
|
||||
Columns: []string{sysbalancerecord.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_spec.Node.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _u.schemaConfig)
|
||||
_spec.AddModifiers(_u.modifiers...)
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{sysbalancerecord.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// SysBalanceRecordUpdateOne is the builder for updating a single SysBalanceRecord entity.
|
||||
type SysBalanceRecordUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *SysBalanceRecordMutation
|
||||
modifiers []func(*sql.UpdateBuilder)
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetUpdateTime(v *ent2.CustomTime) *SysBalanceRecordUpdateOne {
|
||||
_u.mutation.SetUpdateTime(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetUserID(v int64) *SysBalanceRecordUpdateOne {
|
||||
_u.mutation.SetUserID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetNillableUserID(v *int64) *SysBalanceRecordUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUserID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetType(v sysbalancerecord.Type) *SysBalanceRecordUpdateOne {
|
||||
_u.mutation.SetType(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetNillableType(v *sysbalancerecord.Type) *SysBalanceRecordUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetType(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetAmount sets the "amount" field.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetAmount(v decimal.Decimal) *SysBalanceRecordUpdateOne {
|
||||
_u.mutation.SetAmount(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableAmount sets the "amount" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetNillableAmount(v *decimal.Decimal) *SysBalanceRecordUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetAmount(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetReason sets the "reason" field.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetReason(v string) *SysBalanceRecordUpdateOne {
|
||||
_u.mutation.SetReason(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableReason sets the "reason" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetNillableReason(v *string) *SysBalanceRecordUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetReason(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetBalanceBefore sets the "balance_before" field.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetBalanceBefore(v decimal.Decimal) *SysBalanceRecordUpdateOne {
|
||||
_u.mutation.SetBalanceBefore(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableBalanceBefore sets the "balance_before" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetNillableBalanceBefore(v *decimal.Decimal) *SysBalanceRecordUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetBalanceBefore(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetBalanceAfter sets the "balance_after" field.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetBalanceAfter(v decimal.Decimal) *SysBalanceRecordUpdateOne {
|
||||
_u.mutation.SetBalanceAfter(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableBalanceAfter sets the "balance_after" field if the given value is not nil.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetNillableBalanceAfter(v *decimal.Decimal) *SysBalanceRecordUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetBalanceAfter(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the SysUser entity.
|
||||
func (_u *SysBalanceRecordUpdateOne) SetUser(v *SysUser) *SysBalanceRecordUpdateOne {
|
||||
return _u.SetUserID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the SysBalanceRecordMutation object of the builder.
|
||||
func (_u *SysBalanceRecordUpdateOne) Mutation() *SysBalanceRecordMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the SysUser entity.
|
||||
func (_u *SysBalanceRecordUpdateOne) ClearUser() *SysBalanceRecordUpdateOne {
|
||||
_u.mutation.ClearUser()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SysBalanceRecordUpdate builder.
|
||||
func (_u *SysBalanceRecordUpdateOne) Where(ps ...predicate.SysBalanceRecord) *SysBalanceRecordUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (_u *SysBalanceRecordUpdateOne) Select(field string, fields ...string) *SysBalanceRecordUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated SysBalanceRecord entity.
|
||||
func (_u *SysBalanceRecordUpdateOne) Save(ctx context.Context) (*SysBalanceRecord, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *SysBalanceRecordUpdateOne) SaveX(ctx context.Context) *SysBalanceRecord {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *SysBalanceRecordUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *SysBalanceRecordUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *SysBalanceRecordUpdateOne) check() error {
|
||||
if v, ok := _u.mutation.GetType(); ok {
|
||||
if err := sysbalancerecord.TypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "SysBalanceRecord.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "SysBalanceRecord.user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
||||
func (_u *SysBalanceRecordUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *SysBalanceRecordUpdateOne {
|
||||
_u.modifiers = append(_u.modifiers, modifiers...)
|
||||
return _u
|
||||
}
|
||||
|
||||
func (_u *SysBalanceRecordUpdateOne) sqlSave(ctx context.Context) (_node *SysBalanceRecord, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(sysbalancerecord.Table, sysbalancerecord.Columns, sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SysBalanceRecord.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, sysbalancerecord.FieldID)
|
||||
for _, f := range fields {
|
||||
if !sysbalancerecord.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != sysbalancerecord.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.UpdateTime(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldUpdateTime, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.GetType(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Amount(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldAmount, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Reason(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldReason, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.BalanceBefore(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldBalanceBefore, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.BalanceAfter(); ok {
|
||||
_spec.SetField(sysbalancerecord.FieldBalanceAfter, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.UserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: sysbalancerecord.UserTable,
|
||||
Columns: []string{sysbalancerecord.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: sysbalancerecord.UserTable,
|
||||
Columns: []string{sysbalancerecord.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_spec.Node.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _u.schemaConfig)
|
||||
_spec.AddModifiers(_u.modifiers...)
|
||||
_node = &SysBalanceRecord{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{sysbalancerecord.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/sysconfig"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// SysConfig is the model entity for the SysConfig schema.
|
||||
type SysConfig 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"`
|
||||
// 配置键,如:system.announcement
|
||||
Key string `json:"key,omitempty"`
|
||||
// 配置值
|
||||
Value string `json:"value,omitempty"`
|
||||
// 配置描述
|
||||
Description string `json:"description,omitempty"`
|
||||
// 值类型:string, number, boolean, json, markdown
|
||||
Type string `json:"type,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*SysConfig) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case sysconfig.FieldCreateTime, sysconfig.FieldUpdateTime:
|
||||
values[i] = new(ent2.CustomTime)
|
||||
case sysconfig.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case sysconfig.FieldKey, sysconfig.FieldValue, sysconfig.FieldDescription, sysconfig.FieldType:
|
||||
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 SysConfig fields.
|
||||
func (_m *SysConfig) 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 sysconfig.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 sysconfig.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 sysconfig.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 sysconfig.FieldKey:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field key", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Key = value.String
|
||||
}
|
||||
case sysconfig.FieldValue:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field value", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Value = value.String
|
||||
}
|
||||
case sysconfig.FieldDescription:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field description", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Description = value.String
|
||||
}
|
||||
case sysconfig.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 = value.String
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetValue returns the ent.Value that was dynamically selected and assigned to the SysConfig.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *SysConfig) GetValue(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this SysConfig.
|
||||
// Note that you need to call SysConfig.Unwrap() before calling this method if this SysConfig
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *SysConfig) Update() *SysConfigUpdateOne {
|
||||
return NewSysConfigClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the SysConfig 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 *SysConfig) Unwrap() *SysConfig {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: SysConfig is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *SysConfig) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("SysConfig(")
|
||||
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("key=")
|
||||
builder.WriteString(_m.Key)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("value=")
|
||||
builder.WriteString(_m.Value)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("description=")
|
||||
builder.WriteString(_m.Description)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("type=")
|
||||
builder.WriteString(_m.Type)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// SysConfigs is a parsable slice of SysConfig.
|
||||
type SysConfigs []*SysConfig
|
||||
@@ -0,0 +1,105 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package sysconfig
|
||||
|
||||
import (
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the sysconfig type in the database.
|
||||
Label = "sys_config"
|
||||
// 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"
|
||||
// FieldKey holds the string denoting the key field in the database.
|
||||
FieldKey = "key"
|
||||
// FieldValue holds the string denoting the value field in the database.
|
||||
FieldValue = "value"
|
||||
// FieldDescription holds the string denoting the description field in the database.
|
||||
FieldDescription = "description"
|
||||
// FieldType holds the string denoting the type field in the database.
|
||||
FieldType = "type"
|
||||
// Table holds the table name of the sysconfig in the database.
|
||||
Table = "sys_config"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for sysconfig fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldCreateTime,
|
||||
FieldUpdateTime,
|
||||
FieldKey,
|
||||
FieldValue,
|
||||
FieldDescription,
|
||||
FieldType,
|
||||
}
|
||||
|
||||
// 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
|
||||
// DefaultType holds the default value on creation for the "type" field.
|
||||
DefaultType string
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the SysConfig 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()
|
||||
}
|
||||
|
||||
// ByKey orders the results by the key field.
|
||||
func ByKey(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldKey, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByValue orders the results by the value field.
|
||||
func ByValue(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldValue, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByDescription orders the results by the description field.
|
||||
func ByDescription(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDescription, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByType orders the results by the type field.
|
||||
func ByType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldType, opts...).ToFunc()
|
||||
}
|
||||
@@ -0,0 +1,510 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package sysconfig
|
||||
|
||||
import (
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int64) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int64) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int64) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int64) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int64) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int64) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int64) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int64) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int64) predicate.SysConfig {
|
||||
return predicate.SysConfig(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.SysConfig {
|
||||
return predicate.SysConfig(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.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// Key applies equality check predicate on the "key" field. It's identical to KeyEQ.
|
||||
func Key(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldEQ(FieldKey, v))
|
||||
}
|
||||
|
||||
// Value applies equality check predicate on the "value" field. It's identical to ValueEQ.
|
||||
func Value(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldEQ(FieldValue, v))
|
||||
}
|
||||
|
||||
// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ.
|
||||
func Description(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldEQ(FieldDescription, v))
|
||||
}
|
||||
|
||||
// Type applies equality check predicate on the "type" field. It's identical to TypeEQ.
|
||||
func Type(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||
func CreateTimeEQ(v *ent2.CustomTime) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||
func CreateTimeNEQ(v *ent2.CustomTime) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldNEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||
func CreateTimeIn(vs ...*ent2.CustomTime) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||
func CreateTimeNotIn(vs ...*ent2.CustomTime) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldNotIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||
func CreateTimeGT(v *ent2.CustomTime) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldGT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||
func CreateTimeGTE(v *ent2.CustomTime) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldGTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||
func CreateTimeLT(v *ent2.CustomTime) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldLT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||
func CreateTimeLTE(v *ent2.CustomTime) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldLTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeContains applies the Contains predicate on the "create_time" field.
|
||||
func CreateTimeContains(v *ent2.CustomTime) predicate.SysConfig {
|
||||
vc := v.String()
|
||||
return predicate.SysConfig(sql.FieldContains(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeHasPrefix applies the HasPrefix predicate on the "create_time" field.
|
||||
func CreateTimeHasPrefix(v *ent2.CustomTime) predicate.SysConfig {
|
||||
vc := v.String()
|
||||
return predicate.SysConfig(sql.FieldHasPrefix(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeHasSuffix applies the HasSuffix predicate on the "create_time" field.
|
||||
func CreateTimeHasSuffix(v *ent2.CustomTime) predicate.SysConfig {
|
||||
vc := v.String()
|
||||
return predicate.SysConfig(sql.FieldHasSuffix(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeEqualFold applies the EqualFold predicate on the "create_time" field.
|
||||
func CreateTimeEqualFold(v *ent2.CustomTime) predicate.SysConfig {
|
||||
vc := v.String()
|
||||
return predicate.SysConfig(sql.FieldEqualFold(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeContainsFold applies the ContainsFold predicate on the "create_time" field.
|
||||
func CreateTimeContainsFold(v *ent2.CustomTime) predicate.SysConfig {
|
||||
vc := v.String()
|
||||
return predicate.SysConfig(sql.FieldContainsFold(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeEQ applies the EQ predicate on the "update_time" field.
|
||||
func UpdateTimeEQ(v *ent2.CustomTime) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeNEQ applies the NEQ predicate on the "update_time" field.
|
||||
func UpdateTimeNEQ(v *ent2.CustomTime) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldNEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeIn applies the In predicate on the "update_time" field.
|
||||
func UpdateTimeIn(vs ...*ent2.CustomTime) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldIn(FieldUpdateTime, vs...))
|
||||
}
|
||||
|
||||
// UpdateTimeNotIn applies the NotIn predicate on the "update_time" field.
|
||||
func UpdateTimeNotIn(vs ...*ent2.CustomTime) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldNotIn(FieldUpdateTime, vs...))
|
||||
}
|
||||
|
||||
// UpdateTimeGT applies the GT predicate on the "update_time" field.
|
||||
func UpdateTimeGT(v *ent2.CustomTime) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldGT(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeGTE applies the GTE predicate on the "update_time" field.
|
||||
func UpdateTimeGTE(v *ent2.CustomTime) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldGTE(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeLT applies the LT predicate on the "update_time" field.
|
||||
func UpdateTimeLT(v *ent2.CustomTime) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldLT(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeLTE applies the LTE predicate on the "update_time" field.
|
||||
func UpdateTimeLTE(v *ent2.CustomTime) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldLTE(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeContains applies the Contains predicate on the "update_time" field.
|
||||
func UpdateTimeContains(v *ent2.CustomTime) predicate.SysConfig {
|
||||
vc := v.String()
|
||||
return predicate.SysConfig(sql.FieldContains(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeHasPrefix applies the HasPrefix predicate on the "update_time" field.
|
||||
func UpdateTimeHasPrefix(v *ent2.CustomTime) predicate.SysConfig {
|
||||
vc := v.String()
|
||||
return predicate.SysConfig(sql.FieldHasPrefix(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeHasSuffix applies the HasSuffix predicate on the "update_time" field.
|
||||
func UpdateTimeHasSuffix(v *ent2.CustomTime) predicate.SysConfig {
|
||||
vc := v.String()
|
||||
return predicate.SysConfig(sql.FieldHasSuffix(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeEqualFold applies the EqualFold predicate on the "update_time" field.
|
||||
func UpdateTimeEqualFold(v *ent2.CustomTime) predicate.SysConfig {
|
||||
vc := v.String()
|
||||
return predicate.SysConfig(sql.FieldEqualFold(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeContainsFold applies the ContainsFold predicate on the "update_time" field.
|
||||
func UpdateTimeContainsFold(v *ent2.CustomTime) predicate.SysConfig {
|
||||
vc := v.String()
|
||||
return predicate.SysConfig(sql.FieldContainsFold(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// KeyEQ applies the EQ predicate on the "key" field.
|
||||
func KeyEQ(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldEQ(FieldKey, v))
|
||||
}
|
||||
|
||||
// KeyNEQ applies the NEQ predicate on the "key" field.
|
||||
func KeyNEQ(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldNEQ(FieldKey, v))
|
||||
}
|
||||
|
||||
// KeyIn applies the In predicate on the "key" field.
|
||||
func KeyIn(vs ...string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldIn(FieldKey, vs...))
|
||||
}
|
||||
|
||||
// KeyNotIn applies the NotIn predicate on the "key" field.
|
||||
func KeyNotIn(vs ...string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldNotIn(FieldKey, vs...))
|
||||
}
|
||||
|
||||
// KeyGT applies the GT predicate on the "key" field.
|
||||
func KeyGT(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldGT(FieldKey, v))
|
||||
}
|
||||
|
||||
// KeyGTE applies the GTE predicate on the "key" field.
|
||||
func KeyGTE(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldGTE(FieldKey, v))
|
||||
}
|
||||
|
||||
// KeyLT applies the LT predicate on the "key" field.
|
||||
func KeyLT(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldLT(FieldKey, v))
|
||||
}
|
||||
|
||||
// KeyLTE applies the LTE predicate on the "key" field.
|
||||
func KeyLTE(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldLTE(FieldKey, v))
|
||||
}
|
||||
|
||||
// KeyContains applies the Contains predicate on the "key" field.
|
||||
func KeyContains(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldContains(FieldKey, v))
|
||||
}
|
||||
|
||||
// KeyHasPrefix applies the HasPrefix predicate on the "key" field.
|
||||
func KeyHasPrefix(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldHasPrefix(FieldKey, v))
|
||||
}
|
||||
|
||||
// KeyHasSuffix applies the HasSuffix predicate on the "key" field.
|
||||
func KeyHasSuffix(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldHasSuffix(FieldKey, v))
|
||||
}
|
||||
|
||||
// KeyEqualFold applies the EqualFold predicate on the "key" field.
|
||||
func KeyEqualFold(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldEqualFold(FieldKey, v))
|
||||
}
|
||||
|
||||
// KeyContainsFold applies the ContainsFold predicate on the "key" field.
|
||||
func KeyContainsFold(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldContainsFold(FieldKey, v))
|
||||
}
|
||||
|
||||
// ValueEQ applies the EQ predicate on the "value" field.
|
||||
func ValueEQ(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldEQ(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueNEQ applies the NEQ predicate on the "value" field.
|
||||
func ValueNEQ(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldNEQ(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueIn applies the In predicate on the "value" field.
|
||||
func ValueIn(vs ...string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldIn(FieldValue, vs...))
|
||||
}
|
||||
|
||||
// ValueNotIn applies the NotIn predicate on the "value" field.
|
||||
func ValueNotIn(vs ...string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldNotIn(FieldValue, vs...))
|
||||
}
|
||||
|
||||
// ValueGT applies the GT predicate on the "value" field.
|
||||
func ValueGT(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldGT(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueGTE applies the GTE predicate on the "value" field.
|
||||
func ValueGTE(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldGTE(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueLT applies the LT predicate on the "value" field.
|
||||
func ValueLT(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldLT(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueLTE applies the LTE predicate on the "value" field.
|
||||
func ValueLTE(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldLTE(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueContains applies the Contains predicate on the "value" field.
|
||||
func ValueContains(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldContains(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueHasPrefix applies the HasPrefix predicate on the "value" field.
|
||||
func ValueHasPrefix(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldHasPrefix(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueHasSuffix applies the HasSuffix predicate on the "value" field.
|
||||
func ValueHasSuffix(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldHasSuffix(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueEqualFold applies the EqualFold predicate on the "value" field.
|
||||
func ValueEqualFold(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldEqualFold(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueContainsFold applies the ContainsFold predicate on the "value" field.
|
||||
func ValueContainsFold(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldContainsFold(FieldValue, v))
|
||||
}
|
||||
|
||||
// DescriptionEQ applies the EQ predicate on the "description" field.
|
||||
func DescriptionEQ(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldEQ(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionNEQ applies the NEQ predicate on the "description" field.
|
||||
func DescriptionNEQ(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldNEQ(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionIn applies the In predicate on the "description" field.
|
||||
func DescriptionIn(vs ...string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldIn(FieldDescription, vs...))
|
||||
}
|
||||
|
||||
// DescriptionNotIn applies the NotIn predicate on the "description" field.
|
||||
func DescriptionNotIn(vs ...string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldNotIn(FieldDescription, vs...))
|
||||
}
|
||||
|
||||
// DescriptionGT applies the GT predicate on the "description" field.
|
||||
func DescriptionGT(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldGT(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionGTE applies the GTE predicate on the "description" field.
|
||||
func DescriptionGTE(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldGTE(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionLT applies the LT predicate on the "description" field.
|
||||
func DescriptionLT(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldLT(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionLTE applies the LTE predicate on the "description" field.
|
||||
func DescriptionLTE(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldLTE(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionContains applies the Contains predicate on the "description" field.
|
||||
func DescriptionContains(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldContains(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field.
|
||||
func DescriptionHasPrefix(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldHasPrefix(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field.
|
||||
func DescriptionHasSuffix(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldHasSuffix(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionIsNil applies the IsNil predicate on the "description" field.
|
||||
func DescriptionIsNil() predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldIsNull(FieldDescription))
|
||||
}
|
||||
|
||||
// DescriptionNotNil applies the NotNil predicate on the "description" field.
|
||||
func DescriptionNotNil() predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldNotNull(FieldDescription))
|
||||
}
|
||||
|
||||
// DescriptionEqualFold applies the EqualFold predicate on the "description" field.
|
||||
func DescriptionEqualFold(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldEqualFold(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionContainsFold applies the ContainsFold predicate on the "description" field.
|
||||
func DescriptionContainsFold(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldContainsFold(FieldDescription, v))
|
||||
}
|
||||
|
||||
// TypeEQ applies the EQ predicate on the "type" field.
|
||||
func TypeEQ(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeNEQ applies the NEQ predicate on the "type" field.
|
||||
func TypeNEQ(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldNEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeIn applies the In predicate on the "type" field.
|
||||
func TypeIn(vs ...string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// TypeNotIn applies the NotIn predicate on the "type" field.
|
||||
func TypeNotIn(vs ...string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldNotIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// TypeGT applies the GT predicate on the "type" field.
|
||||
func TypeGT(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldGT(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeGTE applies the GTE predicate on the "type" field.
|
||||
func TypeGTE(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldGTE(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeLT applies the LT predicate on the "type" field.
|
||||
func TypeLT(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldLT(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeLTE applies the LTE predicate on the "type" field.
|
||||
func TypeLTE(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldLTE(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeContains applies the Contains predicate on the "type" field.
|
||||
func TypeContains(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldContains(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeHasPrefix applies the HasPrefix predicate on the "type" field.
|
||||
func TypeHasPrefix(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldHasPrefix(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeHasSuffix applies the HasSuffix predicate on the "type" field.
|
||||
func TypeHasSuffix(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldHasSuffix(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeEqualFold applies the EqualFold predicate on the "type" field.
|
||||
func TypeEqualFold(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldEqualFold(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeContainsFold applies the ContainsFold predicate on the "type" field.
|
||||
func TypeContainsFold(v string) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.FieldContainsFold(FieldType, v))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.SysConfig) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.SysConfig) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.SysConfig) predicate.SysConfig {
|
||||
return predicate.SysConfig(sql.NotPredicates(p))
|
||||
}
|
||||
@@ -0,0 +1,753 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/sysconfig"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// SysConfigCreate is the builder for creating a SysConfig entity.
|
||||
type SysConfigCreate struct {
|
||||
config
|
||||
mutation *SysConfigMutation
|
||||
hooks []Hook
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// SetCreateTime sets the "create_time" field.
|
||||
func (_c *SysConfigCreate) SetCreateTime(v *ent2.CustomTime) *SysConfigCreate {
|
||||
_c.mutation.SetCreateTime(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (_c *SysConfigCreate) SetUpdateTime(v *ent2.CustomTime) *SysConfigCreate {
|
||||
_c.mutation.SetUpdateTime(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetKey sets the "key" field.
|
||||
func (_c *SysConfigCreate) SetKey(v string) *SysConfigCreate {
|
||||
_c.mutation.SetKey(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (_c *SysConfigCreate) SetValue(v string) *SysConfigCreate {
|
||||
_c.mutation.SetValue(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetDescription sets the "description" field.
|
||||
func (_c *SysConfigCreate) SetDescription(v string) *SysConfigCreate {
|
||||
_c.mutation.SetDescription(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||
func (_c *SysConfigCreate) SetNillableDescription(v *string) *SysConfigCreate {
|
||||
if v != nil {
|
||||
_c.SetDescription(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (_c *SysConfigCreate) SetType(v string) *SysConfigCreate {
|
||||
_c.mutation.SetType(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (_c *SysConfigCreate) SetNillableType(v *string) *SysConfigCreate {
|
||||
if v != nil {
|
||||
_c.SetType(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the SysConfigMutation object of the builder.
|
||||
func (_c *SysConfigCreate) Mutation() *SysConfigMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the SysConfig in the database.
|
||||
func (_c *SysConfigCreate) Save(ctx context.Context) (*SysConfig, 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 *SysConfigCreate) SaveX(ctx context.Context) *SysConfig {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *SysConfigCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *SysConfigCreate) 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 *SysConfigCreate) defaults() error {
|
||||
if _, ok := _c.mutation.CreateTime(); !ok {
|
||||
if sysconfig.DefaultCreateTime == nil {
|
||||
return fmt.Errorf("ent: uninitialized sysconfig.DefaultCreateTime (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := sysconfig.DefaultCreateTime()
|
||||
_c.mutation.SetCreateTime(v)
|
||||
}
|
||||
if _, ok := _c.mutation.UpdateTime(); !ok {
|
||||
if sysconfig.DefaultUpdateTime == nil {
|
||||
return fmt.Errorf("ent: uninitialized sysconfig.DefaultUpdateTime (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := sysconfig.DefaultUpdateTime()
|
||||
_c.mutation.SetUpdateTime(v)
|
||||
}
|
||||
if _, ok := _c.mutation.GetType(); !ok {
|
||||
v := sysconfig.DefaultType
|
||||
_c.mutation.SetType(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *SysConfigCreate) check() error {
|
||||
if _, ok := _c.mutation.CreateTime(); !ok {
|
||||
return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "SysConfig.create_time"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UpdateTime(); !ok {
|
||||
return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "SysConfig.update_time"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Key(); !ok {
|
||||
return &ValidationError{Name: "key", err: errors.New(`ent: missing required field "SysConfig.key"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Value(); !ok {
|
||||
return &ValidationError{Name: "value", err: errors.New(`ent: missing required field "SysConfig.value"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.GetType(); !ok {
|
||||
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "SysConfig.type"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *SysConfigCreate) sqlSave(ctx context.Context) (*SysConfig, 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 *SysConfigCreate) createSpec() (*SysConfig, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &SysConfig{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(sysconfig.Table, sqlgraph.NewFieldSpec(sysconfig.FieldID, field.TypeInt64))
|
||||
)
|
||||
_spec.Schema = _c.schemaConfig.SysConfig
|
||||
_spec.OnConflict = _c.conflict
|
||||
if value, ok := _c.mutation.CreateTime(); ok {
|
||||
_spec.SetField(sysconfig.FieldCreateTime, field.TypeString, value)
|
||||
_node.CreateTime = value
|
||||
}
|
||||
if value, ok := _c.mutation.UpdateTime(); ok {
|
||||
_spec.SetField(sysconfig.FieldUpdateTime, field.TypeString, value)
|
||||
_node.UpdateTime = value
|
||||
}
|
||||
if value, ok := _c.mutation.Key(); ok {
|
||||
_spec.SetField(sysconfig.FieldKey, field.TypeString, value)
|
||||
_node.Key = value
|
||||
}
|
||||
if value, ok := _c.mutation.Value(); ok {
|
||||
_spec.SetField(sysconfig.FieldValue, field.TypeString, value)
|
||||
_node.Value = value
|
||||
}
|
||||
if value, ok := _c.mutation.Description(); ok {
|
||||
_spec.SetField(sysconfig.FieldDescription, field.TypeString, value)
|
||||
_node.Description = value
|
||||
}
|
||||
if value, ok := _c.mutation.GetType(); ok {
|
||||
_spec.SetField(sysconfig.FieldType, field.TypeString, value)
|
||||
_node.Type = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||
// of the `INSERT` statement. For example:
|
||||
//
|
||||
// client.SysConfig.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.SysConfigUpsert) {
|
||||
// SetCreateTime(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (_c *SysConfigCreate) OnConflict(opts ...sql.ConflictOption) *SysConfigUpsertOne {
|
||||
_c.conflict = opts
|
||||
return &SysConfigUpsertOne{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||
// as conflict target. Using this option is equivalent to using:
|
||||
//
|
||||
// client.SysConfig.Create().
|
||||
// OnConflict(sql.ConflictColumns(columns...)).
|
||||
// Exec(ctx)
|
||||
func (_c *SysConfigCreate) OnConflictColumns(columns ...string) *SysConfigUpsertOne {
|
||||
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||||
return &SysConfigUpsertOne{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
type (
|
||||
// SysConfigUpsertOne is the builder for "upsert"-ing
|
||||
// one SysConfig node.
|
||||
SysConfigUpsertOne struct {
|
||||
create *SysConfigCreate
|
||||
}
|
||||
|
||||
// SysConfigUpsert is the "OnConflict" setter.
|
||||
SysConfigUpsert struct {
|
||||
*sql.UpdateSet
|
||||
}
|
||||
)
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (u *SysConfigUpsert) SetUpdateTime(v *ent2.CustomTime) *SysConfigUpsert {
|
||||
u.Set(sysconfig.FieldUpdateTime, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||
func (u *SysConfigUpsert) UpdateUpdateTime() *SysConfigUpsert {
|
||||
u.SetExcluded(sysconfig.FieldUpdateTime)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetKey sets the "key" field.
|
||||
func (u *SysConfigUpsert) SetKey(v string) *SysConfigUpsert {
|
||||
u.Set(sysconfig.FieldKey, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateKey sets the "key" field to the value that was provided on create.
|
||||
func (u *SysConfigUpsert) UpdateKey() *SysConfigUpsert {
|
||||
u.SetExcluded(sysconfig.FieldKey)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (u *SysConfigUpsert) SetValue(v string) *SysConfigUpsert {
|
||||
u.Set(sysconfig.FieldValue, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateValue sets the "value" field to the value that was provided on create.
|
||||
func (u *SysConfigUpsert) UpdateValue() *SysConfigUpsert {
|
||||
u.SetExcluded(sysconfig.FieldValue)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetDescription sets the "description" field.
|
||||
func (u *SysConfigUpsert) SetDescription(v string) *SysConfigUpsert {
|
||||
u.Set(sysconfig.FieldDescription, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateDescription sets the "description" field to the value that was provided on create.
|
||||
func (u *SysConfigUpsert) UpdateDescription() *SysConfigUpsert {
|
||||
u.SetExcluded(sysconfig.FieldDescription)
|
||||
return u
|
||||
}
|
||||
|
||||
// ClearDescription clears the value of the "description" field.
|
||||
func (u *SysConfigUpsert) ClearDescription() *SysConfigUpsert {
|
||||
u.SetNull(sysconfig.FieldDescription)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (u *SysConfigUpsert) SetType(v string) *SysConfigUpsert {
|
||||
u.Set(sysconfig.FieldType, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateType sets the "type" field to the value that was provided on create.
|
||||
func (u *SysConfigUpsert) UpdateType() *SysConfigUpsert {
|
||||
u.SetExcluded(sysconfig.FieldType)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.SysConfig.Create().
|
||||
// OnConflict(
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// Exec(ctx)
|
||||
func (u *SysConfigUpsertOne) UpdateNewValues() *SysConfigUpsertOne {
|
||||
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(sysconfig.FieldCreateTime)
|
||||
}
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// Ignore sets each column to itself in case of conflict.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.SysConfig.Create().
|
||||
// OnConflict(sql.ResolveWithIgnore()).
|
||||
// Exec(ctx)
|
||||
func (u *SysConfigUpsertOne) Ignore() *SysConfigUpsertOne {
|
||||
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 *SysConfigUpsertOne) DoNothing() *SysConfigUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||
return u
|
||||
}
|
||||
|
||||
// Update allows overriding fields `UPDATE` values. See the SysConfigCreate.OnConflict
|
||||
// documentation for more info.
|
||||
func (u *SysConfigUpsertOne) Update(set func(*SysConfigUpsert)) *SysConfigUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||
set(&SysConfigUpsert{UpdateSet: update})
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (u *SysConfigUpsertOne) SetUpdateTime(v *ent2.CustomTime) *SysConfigUpsertOne {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.SetUpdateTime(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||
func (u *SysConfigUpsertOne) UpdateUpdateTime() *SysConfigUpsertOne {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.UpdateUpdateTime()
|
||||
})
|
||||
}
|
||||
|
||||
// SetKey sets the "key" field.
|
||||
func (u *SysConfigUpsertOne) SetKey(v string) *SysConfigUpsertOne {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.SetKey(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateKey sets the "key" field to the value that was provided on create.
|
||||
func (u *SysConfigUpsertOne) UpdateKey() *SysConfigUpsertOne {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.UpdateKey()
|
||||
})
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (u *SysConfigUpsertOne) SetValue(v string) *SysConfigUpsertOne {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.SetValue(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateValue sets the "value" field to the value that was provided on create.
|
||||
func (u *SysConfigUpsertOne) UpdateValue() *SysConfigUpsertOne {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.UpdateValue()
|
||||
})
|
||||
}
|
||||
|
||||
// SetDescription sets the "description" field.
|
||||
func (u *SysConfigUpsertOne) SetDescription(v string) *SysConfigUpsertOne {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.SetDescription(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateDescription sets the "description" field to the value that was provided on create.
|
||||
func (u *SysConfigUpsertOne) UpdateDescription() *SysConfigUpsertOne {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.UpdateDescription()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearDescription clears the value of the "description" field.
|
||||
func (u *SysConfigUpsertOne) ClearDescription() *SysConfigUpsertOne {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.ClearDescription()
|
||||
})
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (u *SysConfigUpsertOne) SetType(v string) *SysConfigUpsertOne {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.SetType(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateType sets the "type" field to the value that was provided on create.
|
||||
func (u *SysConfigUpsertOne) UpdateType() *SysConfigUpsertOne {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.UpdateType()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *SysConfigUpsertOne) Exec(ctx context.Context) error {
|
||||
if len(u.create.conflict) == 0 {
|
||||
return errors.New("ent: missing options for SysConfigCreate.OnConflict")
|
||||
}
|
||||
return u.create.Exec(ctx)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (u *SysConfigUpsertOne) 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 *SysConfigUpsertOne) 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 *SysConfigUpsertOne) IDX(ctx context.Context) int64 {
|
||||
id, err := u.ID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// SysConfigCreateBulk is the builder for creating many SysConfig entities in bulk.
|
||||
type SysConfigCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*SysConfigCreate
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// Save creates the SysConfig entities in the database.
|
||||
func (_c *SysConfigCreateBulk) Save(ctx context.Context) ([]*SysConfig, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*SysConfig, 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.(*SysConfigMutation)
|
||||
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 *SysConfigCreateBulk) SaveX(ctx context.Context) []*SysConfig {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *SysConfigCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *SysConfigCreateBulk) 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.SysConfig.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.SysConfigUpsert) {
|
||||
// SetCreateTime(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (_c *SysConfigCreateBulk) OnConflict(opts ...sql.ConflictOption) *SysConfigUpsertBulk {
|
||||
_c.conflict = opts
|
||||
return &SysConfigUpsertBulk{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||
// as conflict target. Using this option is equivalent to using:
|
||||
//
|
||||
// client.SysConfig.Create().
|
||||
// OnConflict(sql.ConflictColumns(columns...)).
|
||||
// Exec(ctx)
|
||||
func (_c *SysConfigCreateBulk) OnConflictColumns(columns ...string) *SysConfigUpsertBulk {
|
||||
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||||
return &SysConfigUpsertBulk{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
// SysConfigUpsertBulk is the builder for "upsert"-ing
|
||||
// a bulk of SysConfig nodes.
|
||||
type SysConfigUpsertBulk struct {
|
||||
create *SysConfigCreateBulk
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that
|
||||
// were set on create. Using this option is equivalent to using:
|
||||
//
|
||||
// client.SysConfig.Create().
|
||||
// OnConflict(
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// Exec(ctx)
|
||||
func (u *SysConfigUpsertBulk) UpdateNewValues() *SysConfigUpsertBulk {
|
||||
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(sysconfig.FieldCreateTime)
|
||||
}
|
||||
}
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// Ignore sets each column to itself in case of conflict.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.SysConfig.Create().
|
||||
// OnConflict(sql.ResolveWithIgnore()).
|
||||
// Exec(ctx)
|
||||
func (u *SysConfigUpsertBulk) Ignore() *SysConfigUpsertBulk {
|
||||
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 *SysConfigUpsertBulk) DoNothing() *SysConfigUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||
return u
|
||||
}
|
||||
|
||||
// Update allows overriding fields `UPDATE` values. See the SysConfigCreateBulk.OnConflict
|
||||
// documentation for more info.
|
||||
func (u *SysConfigUpsertBulk) Update(set func(*SysConfigUpsert)) *SysConfigUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||
set(&SysConfigUpsert{UpdateSet: update})
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (u *SysConfigUpsertBulk) SetUpdateTime(v *ent2.CustomTime) *SysConfigUpsertBulk {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.SetUpdateTime(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||
func (u *SysConfigUpsertBulk) UpdateUpdateTime() *SysConfigUpsertBulk {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.UpdateUpdateTime()
|
||||
})
|
||||
}
|
||||
|
||||
// SetKey sets the "key" field.
|
||||
func (u *SysConfigUpsertBulk) SetKey(v string) *SysConfigUpsertBulk {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.SetKey(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateKey sets the "key" field to the value that was provided on create.
|
||||
func (u *SysConfigUpsertBulk) UpdateKey() *SysConfigUpsertBulk {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.UpdateKey()
|
||||
})
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (u *SysConfigUpsertBulk) SetValue(v string) *SysConfigUpsertBulk {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.SetValue(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateValue sets the "value" field to the value that was provided on create.
|
||||
func (u *SysConfigUpsertBulk) UpdateValue() *SysConfigUpsertBulk {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.UpdateValue()
|
||||
})
|
||||
}
|
||||
|
||||
// SetDescription sets the "description" field.
|
||||
func (u *SysConfigUpsertBulk) SetDescription(v string) *SysConfigUpsertBulk {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.SetDescription(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateDescription sets the "description" field to the value that was provided on create.
|
||||
func (u *SysConfigUpsertBulk) UpdateDescription() *SysConfigUpsertBulk {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.UpdateDescription()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearDescription clears the value of the "description" field.
|
||||
func (u *SysConfigUpsertBulk) ClearDescription() *SysConfigUpsertBulk {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.ClearDescription()
|
||||
})
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (u *SysConfigUpsertBulk) SetType(v string) *SysConfigUpsertBulk {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.SetType(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateType sets the "type" field to the value that was provided on create.
|
||||
func (u *SysConfigUpsertBulk) UpdateType() *SysConfigUpsertBulk {
|
||||
return u.Update(func(s *SysConfigUpsert) {
|
||||
s.UpdateType()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *SysConfigUpsertBulk) 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 SysConfigCreateBulk instead", i)
|
||||
}
|
||||
}
|
||||
if len(u.create.conflict) == 0 {
|
||||
return errors.New("ent: missing options for SysConfigCreateBulk.OnConflict")
|
||||
}
|
||||
return u.create.Exec(ctx)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (u *SysConfigUpsertBulk) ExecX(ctx context.Context) {
|
||||
if err := u.create.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysconfig"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// SysConfigDelete is the builder for deleting a SysConfig entity.
|
||||
type SysConfigDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SysConfigMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SysConfigDelete builder.
|
||||
func (_d *SysConfigDelete) Where(ps ...predicate.SysConfig) *SysConfigDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *SysConfigDelete) 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 *SysConfigDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *SysConfigDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(sysconfig.Table, sqlgraph.NewFieldSpec(sysconfig.FieldID, field.TypeInt64))
|
||||
_spec.Node.Schema = _d.schemaConfig.SysConfig
|
||||
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
|
||||
}
|
||||
|
||||
// SysConfigDeleteOne is the builder for deleting a single SysConfig entity.
|
||||
type SysConfigDeleteOne struct {
|
||||
_d *SysConfigDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SysConfigDelete builder.
|
||||
func (_d *SysConfigDeleteOne) Where(ps ...predicate.SysConfig) *SysConfigDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *SysConfigDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{sysconfig.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *SysConfigDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,585 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysconfig"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// SysConfigQuery is the builder for querying SysConfig entities.
|
||||
type SysConfigQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []sysconfig.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.SysConfig
|
||||
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 SysConfigQuery builder.
|
||||
func (_q *SysConfigQuery) Where(ps ...predicate.SysConfig) *SysConfigQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *SysConfigQuery) Limit(limit int) *SysConfigQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *SysConfigQuery) Offset(offset int) *SysConfigQuery {
|
||||
_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 *SysConfigQuery) Unique(unique bool) *SysConfigQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *SysConfigQuery) Order(o ...sysconfig.OrderOption) *SysConfigQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// First returns the first SysConfig entity from the query.
|
||||
// Returns a *NotFoundError when no SysConfig was found.
|
||||
func (_q *SysConfigQuery) First(ctx context.Context) (*SysConfig, 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{sysconfig.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *SysConfigQuery) FirstX(ctx context.Context) *SysConfig {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first SysConfig ID from the query.
|
||||
// Returns a *NotFoundError when no SysConfig ID was found.
|
||||
func (_q *SysConfigQuery) 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{sysconfig.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *SysConfigQuery) FirstIDX(ctx context.Context) int64 {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single SysConfig entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one SysConfig entity is found.
|
||||
// Returns a *NotFoundError when no SysConfig entities are found.
|
||||
func (_q *SysConfigQuery) Only(ctx context.Context) (*SysConfig, 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{sysconfig.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{sysconfig.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *SysConfigQuery) OnlyX(ctx context.Context) *SysConfig {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only SysConfig ID in the query.
|
||||
// Returns a *NotSingularError when more than one SysConfig ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *SysConfigQuery) 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{sysconfig.Label}
|
||||
default:
|
||||
err = &NotSingularError{sysconfig.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *SysConfigQuery) 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 SysConfigs.
|
||||
func (_q *SysConfigQuery) All(ctx context.Context) ([]*SysConfig, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*SysConfig, *SysConfigQuery]()
|
||||
return withInterceptors[[]*SysConfig](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *SysConfigQuery) AllX(ctx context.Context) []*SysConfig {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of SysConfig IDs.
|
||||
func (_q *SysConfigQuery) 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(sysconfig.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *SysConfigQuery) 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 *SysConfigQuery) 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[*SysConfigQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *SysConfigQuery) 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 *SysConfigQuery) 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 *SysConfigQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the SysConfigQuery 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 *SysConfigQuery) Clone() *SysConfigQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &SysConfigQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]sysconfig.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.SysConfig{}, _q.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
modifiers: append([]func(*sql.Selector){}, _q.modifiers...),
|
||||
}
|
||||
}
|
||||
|
||||
// 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.SysConfig.Query().
|
||||
// GroupBy(sysconfig.FieldCreateTime).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *SysConfigQuery) GroupBy(field string, fields ...string) *SysConfigGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &SysConfigGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = sysconfig.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.SysConfig.Query().
|
||||
// Select(sysconfig.FieldCreateTime).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *SysConfigQuery) Select(fields ...string) *SysConfigSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &SysConfigSelect{SysConfigQuery: _q}
|
||||
sbuild.label = sysconfig.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a SysConfigSelect configured with the given aggregations.
|
||||
func (_q *SysConfigQuery) Aggregate(fns ...AggregateFunc) *SysConfigSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *SysConfigQuery) 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 !sysconfig.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 *SysConfigQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysConfig, error) {
|
||||
var (
|
||||
nodes = []*SysConfig{}
|
||||
_spec = _q.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*SysConfig).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &SysConfig{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
_spec.Node.Schema = _q.schemaConfig.SysConfig
|
||||
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
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *SysConfigQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
_spec.Node.Schema = _q.schemaConfig.SysConfig
|
||||
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 *SysConfigQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(sysconfig.Table, sysconfig.Columns, sqlgraph.NewFieldSpec(sysconfig.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, sysconfig.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != sysconfig.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _q.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := _q.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (_q *SysConfigQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(sysconfig.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = sysconfig.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.SysConfig)
|
||||
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 *SysConfigQuery) ForUpdate(opts ...sql.LockOption) *SysConfigQuery {
|
||||
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 *SysConfigQuery) ForShare(opts ...sql.LockOption) *SysConfigQuery {
|
||||
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 *SysConfigQuery) Modify(modifiers ...func(s *sql.Selector)) *SysConfigSelect {
|
||||
_q.modifiers = append(_q.modifiers, modifiers...)
|
||||
return _q.Select()
|
||||
}
|
||||
|
||||
// SysConfigGroupBy is the group-by builder for SysConfig entities.
|
||||
type SysConfigGroupBy struct {
|
||||
selector
|
||||
build *SysConfigQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *SysConfigGroupBy) Aggregate(fns ...AggregateFunc) *SysConfigGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *SysConfigGroupBy) 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[*SysConfigQuery, *SysConfigGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *SysConfigGroupBy) sqlScan(ctx context.Context, root *SysConfigQuery, 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)
|
||||
}
|
||||
|
||||
// SysConfigSelect is the builder for selecting fields of SysConfig entities.
|
||||
type SysConfigSelect struct {
|
||||
*SysConfigQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *SysConfigSelect) Aggregate(fns ...AggregateFunc) *SysConfigSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *SysConfigSelect) 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[*SysConfigQuery, *SysConfigSelect](ctx, _s.SysConfigQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *SysConfigSelect) sqlScan(ctx context.Context, root *SysConfigQuery, 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 *SysConfigSelect) Modify(modifiers ...func(s *sql.Selector)) *SysConfigSelect {
|
||||
_s.modifiers = append(_s.modifiers, modifiers...)
|
||||
return _s
|
||||
}
|
||||
@@ -0,0 +1,369 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysconfig"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// SysConfigUpdate is the builder for updating SysConfig entities.
|
||||
type SysConfigUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SysConfigMutation
|
||||
modifiers []func(*sql.UpdateBuilder)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SysConfigUpdate builder.
|
||||
func (_u *SysConfigUpdate) Where(ps ...predicate.SysConfig) *SysConfigUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (_u *SysConfigUpdate) SetUpdateTime(v *ent2.CustomTime) *SysConfigUpdate {
|
||||
_u.mutation.SetUpdateTime(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetKey sets the "key" field.
|
||||
func (_u *SysConfigUpdate) SetKey(v string) *SysConfigUpdate {
|
||||
_u.mutation.SetKey(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableKey sets the "key" field if the given value is not nil.
|
||||
func (_u *SysConfigUpdate) SetNillableKey(v *string) *SysConfigUpdate {
|
||||
if v != nil {
|
||||
_u.SetKey(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (_u *SysConfigUpdate) SetValue(v string) *SysConfigUpdate {
|
||||
_u.mutation.SetValue(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableValue sets the "value" field if the given value is not nil.
|
||||
func (_u *SysConfigUpdate) SetNillableValue(v *string) *SysConfigUpdate {
|
||||
if v != nil {
|
||||
_u.SetValue(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetDescription sets the "description" field.
|
||||
func (_u *SysConfigUpdate) SetDescription(v string) *SysConfigUpdate {
|
||||
_u.mutation.SetDescription(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||
func (_u *SysConfigUpdate) SetNillableDescription(v *string) *SysConfigUpdate {
|
||||
if v != nil {
|
||||
_u.SetDescription(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearDescription clears the value of the "description" field.
|
||||
func (_u *SysConfigUpdate) ClearDescription() *SysConfigUpdate {
|
||||
_u.mutation.ClearDescription()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (_u *SysConfigUpdate) SetType(v string) *SysConfigUpdate {
|
||||
_u.mutation.SetType(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (_u *SysConfigUpdate) SetNillableType(v *string) *SysConfigUpdate {
|
||||
if v != nil {
|
||||
_u.SetType(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the SysConfigMutation object of the builder.
|
||||
func (_u *SysConfigUpdate) Mutation() *SysConfigMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *SysConfigUpdate) 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 *SysConfigUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *SysConfigUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *SysConfigUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
||||
func (_u *SysConfigUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *SysConfigUpdate {
|
||||
_u.modifiers = append(_u.modifiers, modifiers...)
|
||||
return _u
|
||||
}
|
||||
|
||||
func (_u *SysConfigUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(sysconfig.Table, sysconfig.Columns, sqlgraph.NewFieldSpec(sysconfig.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(sysconfig.FieldUpdateTime, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Key(); ok {
|
||||
_spec.SetField(sysconfig.FieldKey, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Value(); ok {
|
||||
_spec.SetField(sysconfig.FieldValue, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Description(); ok {
|
||||
_spec.SetField(sysconfig.FieldDescription, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.DescriptionCleared() {
|
||||
_spec.ClearField(sysconfig.FieldDescription, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.GetType(); ok {
|
||||
_spec.SetField(sysconfig.FieldType, field.TypeString, value)
|
||||
}
|
||||
_spec.Node.Schema = _u.schemaConfig.SysConfig
|
||||
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{sysconfig.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// SysConfigUpdateOne is the builder for updating a single SysConfig entity.
|
||||
type SysConfigUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *SysConfigMutation
|
||||
modifiers []func(*sql.UpdateBuilder)
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (_u *SysConfigUpdateOne) SetUpdateTime(v *ent2.CustomTime) *SysConfigUpdateOne {
|
||||
_u.mutation.SetUpdateTime(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetKey sets the "key" field.
|
||||
func (_u *SysConfigUpdateOne) SetKey(v string) *SysConfigUpdateOne {
|
||||
_u.mutation.SetKey(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableKey sets the "key" field if the given value is not nil.
|
||||
func (_u *SysConfigUpdateOne) SetNillableKey(v *string) *SysConfigUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetKey(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (_u *SysConfigUpdateOne) SetValue(v string) *SysConfigUpdateOne {
|
||||
_u.mutation.SetValue(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableValue sets the "value" field if the given value is not nil.
|
||||
func (_u *SysConfigUpdateOne) SetNillableValue(v *string) *SysConfigUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetValue(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetDescription sets the "description" field.
|
||||
func (_u *SysConfigUpdateOne) SetDescription(v string) *SysConfigUpdateOne {
|
||||
_u.mutation.SetDescription(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||
func (_u *SysConfigUpdateOne) SetNillableDescription(v *string) *SysConfigUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetDescription(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearDescription clears the value of the "description" field.
|
||||
func (_u *SysConfigUpdateOne) ClearDescription() *SysConfigUpdateOne {
|
||||
_u.mutation.ClearDescription()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (_u *SysConfigUpdateOne) SetType(v string) *SysConfigUpdateOne {
|
||||
_u.mutation.SetType(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (_u *SysConfigUpdateOne) SetNillableType(v *string) *SysConfigUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetType(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the SysConfigMutation object of the builder.
|
||||
func (_u *SysConfigUpdateOne) Mutation() *SysConfigMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SysConfigUpdate builder.
|
||||
func (_u *SysConfigUpdateOne) Where(ps ...predicate.SysConfig) *SysConfigUpdateOne {
|
||||
_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 *SysConfigUpdateOne) Select(field string, fields ...string) *SysConfigUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated SysConfig entity.
|
||||
func (_u *SysConfigUpdateOne) Save(ctx context.Context) (*SysConfig, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *SysConfigUpdateOne) SaveX(ctx context.Context) *SysConfig {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *SysConfigUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *SysConfigUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
||||
func (_u *SysConfigUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *SysConfigUpdateOne {
|
||||
_u.modifiers = append(_u.modifiers, modifiers...)
|
||||
return _u
|
||||
}
|
||||
|
||||
func (_u *SysConfigUpdateOne) sqlSave(ctx context.Context) (_node *SysConfig, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(sysconfig.Table, sysconfig.Columns, sqlgraph.NewFieldSpec(sysconfig.FieldID, field.TypeInt64))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SysConfig.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, sysconfig.FieldID)
|
||||
for _, f := range fields {
|
||||
if !sysconfig.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != sysconfig.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(sysconfig.FieldUpdateTime, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Key(); ok {
|
||||
_spec.SetField(sysconfig.FieldKey, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Value(); ok {
|
||||
_spec.SetField(sysconfig.FieldValue, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Description(); ok {
|
||||
_spec.SetField(sysconfig.FieldDescription, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.DescriptionCleared() {
|
||||
_spec.ClearField(sysconfig.FieldDescription, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.GetType(); ok {
|
||||
_spec.SetField(sysconfig.FieldType, field.TypeString, value)
|
||||
}
|
||||
_spec.Node.Schema = _u.schemaConfig.SysConfig
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _u.schemaConfig)
|
||||
_spec.AddModifiers(_u.modifiers...)
|
||||
_node = &SysConfig{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{sysconfig.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
+53
-12
@@ -74,20 +74,23 @@ type SysUserEdges struct {
|
||||
UsedCards []*SysCard `json:"used_cards,omitempty"`
|
||||
// CashbackCards holds the value of the cashback_cards edge.
|
||||
CashbackCards []*SysCard `json:"cashback_cards,omitempty"`
|
||||
// BalanceRecords holds the value of the balance_records edge.
|
||||
BalanceRecords []*SysBalanceRecord `json:"balance_records,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [13]bool
|
||||
namedChildren map[string][]*SysUser
|
||||
namedRoles map[string][]*SysRole
|
||||
namedImages map[string][]*CpImage
|
||||
namedCpuser map[string][]*CpUser
|
||||
namedCpTask map[string][]*CpTask
|
||||
namedCpLeave map[string][]*CpLeave
|
||||
namedCourseEntity map[string][]*CourseEntity
|
||||
namedCpTaskLogs map[string][]*CpTaskLog
|
||||
namedCreatedCards map[string][]*SysCard
|
||||
namedUsedCards map[string][]*SysCard
|
||||
namedCashbackCards map[string][]*SysCard
|
||||
loadedTypes [14]bool
|
||||
namedChildren map[string][]*SysUser
|
||||
namedRoles map[string][]*SysRole
|
||||
namedImages map[string][]*CpImage
|
||||
namedCpuser map[string][]*CpUser
|
||||
namedCpTask map[string][]*CpTask
|
||||
namedCpLeave map[string][]*CpLeave
|
||||
namedCourseEntity map[string][]*CourseEntity
|
||||
namedCpTaskLogs map[string][]*CpTaskLog
|
||||
namedCreatedCards map[string][]*SysCard
|
||||
namedUsedCards map[string][]*SysCard
|
||||
namedCashbackCards map[string][]*SysCard
|
||||
namedBalanceRecords map[string][]*SysBalanceRecord
|
||||
}
|
||||
|
||||
// ParentOrErr returns the Parent value or an error if the edge
|
||||
@@ -211,6 +214,15 @@ func (e SysUserEdges) CashbackCardsOrErr() ([]*SysCard, error) {
|
||||
return nil, &NotLoadedError{edge: "cashback_cards"}
|
||||
}
|
||||
|
||||
// BalanceRecordsOrErr returns the BalanceRecords value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e SysUserEdges) BalanceRecordsOrErr() ([]*SysBalanceRecord, error) {
|
||||
if e.loadedTypes[13] {
|
||||
return e.BalanceRecords, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "balance_records"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*SysUser) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
@@ -394,6 +406,11 @@ func (_m *SysUser) QueryCashbackCards() *SysCardQuery {
|
||||
return NewSysUserClient(_m.config).QueryCashbackCards(_m)
|
||||
}
|
||||
|
||||
// QueryBalanceRecords queries the "balance_records" edge of the SysUser entity.
|
||||
func (_m *SysUser) QueryBalanceRecords() *SysBalanceRecordQuery {
|
||||
return NewSysUserClient(_m.config).QueryBalanceRecords(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this SysUser.
|
||||
// Note that you need to call SysUser.Unwrap() before calling this method if this SysUser
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
@@ -713,5 +730,29 @@ func (_m *SysUser) appendNamedCashbackCards(name string, edges ...*SysCard) {
|
||||
}
|
||||
}
|
||||
|
||||
// NamedBalanceRecords returns the BalanceRecords named value or an error if the edge was not
|
||||
// loaded in eager-loading with this name.
|
||||
func (_m *SysUser) NamedBalanceRecords(name string) ([]*SysBalanceRecord, error) {
|
||||
if _m.Edges.namedBalanceRecords == nil {
|
||||
return nil, &NotLoadedError{edge: name}
|
||||
}
|
||||
nodes, ok := _m.Edges.namedBalanceRecords[name]
|
||||
if !ok {
|
||||
return nil, &NotLoadedError{edge: name}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_m *SysUser) appendNamedBalanceRecords(name string, edges ...*SysBalanceRecord) {
|
||||
if _m.Edges.namedBalanceRecords == nil {
|
||||
_m.Edges.namedBalanceRecords = make(map[string][]*SysBalanceRecord)
|
||||
}
|
||||
if len(edges) == 0 {
|
||||
_m.Edges.namedBalanceRecords[name] = []*SysBalanceRecord{}
|
||||
} else {
|
||||
_m.Edges.namedBalanceRecords[name] = append(_m.Edges.namedBalanceRecords[name], edges...)
|
||||
}
|
||||
}
|
||||
|
||||
// SysUsers is a parsable slice of SysUser.
|
||||
type SysUsers []*SysUser
|
||||
|
||||
@@ -62,6 +62,8 @@ const (
|
||||
EdgeUsedCards = "used_cards"
|
||||
// EdgeCashbackCards holds the string denoting the cashback_cards edge name in mutations.
|
||||
EdgeCashbackCards = "cashback_cards"
|
||||
// EdgeBalanceRecords holds the string denoting the balance_records edge name in mutations.
|
||||
EdgeBalanceRecords = "balance_records"
|
||||
// Table holds the table name of the sysuser in the database.
|
||||
Table = "sys_user"
|
||||
// ParentTable is the table that holds the parent relation/edge.
|
||||
@@ -147,6 +149,13 @@ const (
|
||||
CashbackCardsInverseTable = "sys_card"
|
||||
// CashbackCardsColumn is the table column denoting the cashback_cards relation/edge.
|
||||
CashbackCardsColumn = "cash_user_id"
|
||||
// BalanceRecordsTable is the table that holds the balance_records relation/edge.
|
||||
BalanceRecordsTable = "sys_balance_record"
|
||||
// BalanceRecordsInverseTable is the table name for the SysBalanceRecord entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "sysbalancerecord" package.
|
||||
BalanceRecordsInverseTable = "sys_balance_record"
|
||||
// BalanceRecordsColumn is the table column denoting the balance_records relation/edge.
|
||||
BalanceRecordsColumn = "user_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for sysuser fields.
|
||||
@@ -439,6 +448,20 @@ func ByCashbackCards(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
sqlgraph.OrderByNeighborTerms(s, newCashbackCardsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByBalanceRecordsCount orders the results by balance_records count.
|
||||
func ByBalanceRecordsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newBalanceRecordsStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByBalanceRecords orders the results by balance_records terms.
|
||||
func ByBalanceRecords(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newBalanceRecordsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
func newParentStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
@@ -530,3 +553,10 @@ func newCashbackCardsStep() *sqlgraph.Step {
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, CashbackCardsTable, CashbackCardsColumn),
|
||||
)
|
||||
}
|
||||
func newBalanceRecordsStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(BalanceRecordsInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, BalanceRecordsTable, BalanceRecordsColumn),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1054,6 +1054,35 @@ func HasCashbackCardsWith(preds ...predicate.SysCard) predicate.SysUser {
|
||||
})
|
||||
}
|
||||
|
||||
// HasBalanceRecords applies the HasEdge predicate on the "balance_records" edge.
|
||||
func HasBalanceRecords() predicate.SysUser {
|
||||
return predicate.SysUser(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, BalanceRecordsTable, BalanceRecordsColumn),
|
||||
)
|
||||
schemaConfig := internal.SchemaConfigFromContext(s.Context())
|
||||
step.To.Schema = schemaConfig.SysBalanceRecord
|
||||
step.Edge.Schema = schemaConfig.SysBalanceRecord
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasBalanceRecordsWith applies the HasEdge predicate on the "balance_records" edge with a given conditions (other predicates).
|
||||
func HasBalanceRecordsWith(preds ...predicate.SysBalanceRecord) predicate.SysUser {
|
||||
return predicate.SysUser(func(s *sql.Selector) {
|
||||
step := newBalanceRecordsStep()
|
||||
schemaConfig := internal.SchemaConfigFromContext(s.Context())
|
||||
step.To.Schema = schemaConfig.SysBalanceRecord
|
||||
step.Edge.Schema = schemaConfig.SysBalanceRecord
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.SysUser) predicate.SysUser {
|
||||
return predicate.SysUser(sql.AndPredicates(predicates...))
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"likedream-goframe/internal/ent/cptasklog"
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/ent/sysagent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysrole"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
@@ -335,6 +336,21 @@ func (_c *SysUserCreate) AddCashbackCards(v ...*SysCard) *SysUserCreate {
|
||||
return _c.AddCashbackCardIDs(ids...)
|
||||
}
|
||||
|
||||
// AddBalanceRecordIDs adds the "balance_records" edge to the SysBalanceRecord entity by IDs.
|
||||
func (_c *SysUserCreate) AddBalanceRecordIDs(ids ...int64) *SysUserCreate {
|
||||
_c.mutation.AddBalanceRecordIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddBalanceRecords adds the "balance_records" edges to the SysBalanceRecord entity.
|
||||
func (_c *SysUserCreate) AddBalanceRecords(v ...*SysBalanceRecord) *SysUserCreate {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddBalanceRecordIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the SysUserMutation object of the builder.
|
||||
func (_c *SysUserCreate) Mutation() *SysUserMutation {
|
||||
return _c.mutation
|
||||
@@ -735,6 +751,23 @@ func (_c *SysUserCreate) createSpec() (*SysUser, *sqlgraph.CreateSpec) {
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.BalanceRecordsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.BalanceRecordsTable,
|
||||
Columns: []string{sysuser.BalanceRecordsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _c.schemaConfig.SysBalanceRecord
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
|
||||
+158
-49
@@ -15,6 +15,7 @@ import (
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysagent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysrole"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
@@ -30,36 +31,38 @@ import (
|
||||
// SysUserQuery is the builder for querying SysUser entities.
|
||||
type SysUserQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []sysuser.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.SysUser
|
||||
withParent *SysUserQuery
|
||||
withChildren *SysUserQuery
|
||||
withRoles *SysRoleQuery
|
||||
withAgent *SysAgentQuery
|
||||
withImages *CpImageQuery
|
||||
withCpuser *CpUserQuery
|
||||
withCpTask *CpTaskQuery
|
||||
withCpLeave *CpLeaveQuery
|
||||
withCourseEntity *CourseEntityQuery
|
||||
withCpTaskLogs *CpTaskLogQuery
|
||||
withCreatedCards *SysCardQuery
|
||||
withUsedCards *SysCardQuery
|
||||
withCashbackCards *SysCardQuery
|
||||
withFKs bool
|
||||
modifiers []func(*sql.Selector)
|
||||
withNamedChildren map[string]*SysUserQuery
|
||||
withNamedRoles map[string]*SysRoleQuery
|
||||
withNamedImages map[string]*CpImageQuery
|
||||
withNamedCpuser map[string]*CpUserQuery
|
||||
withNamedCpTask map[string]*CpTaskQuery
|
||||
withNamedCpLeave map[string]*CpLeaveQuery
|
||||
withNamedCourseEntity map[string]*CourseEntityQuery
|
||||
withNamedCpTaskLogs map[string]*CpTaskLogQuery
|
||||
withNamedCreatedCards map[string]*SysCardQuery
|
||||
withNamedUsedCards map[string]*SysCardQuery
|
||||
withNamedCashbackCards map[string]*SysCardQuery
|
||||
ctx *QueryContext
|
||||
order []sysuser.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.SysUser
|
||||
withParent *SysUserQuery
|
||||
withChildren *SysUserQuery
|
||||
withRoles *SysRoleQuery
|
||||
withAgent *SysAgentQuery
|
||||
withImages *CpImageQuery
|
||||
withCpuser *CpUserQuery
|
||||
withCpTask *CpTaskQuery
|
||||
withCpLeave *CpLeaveQuery
|
||||
withCourseEntity *CourseEntityQuery
|
||||
withCpTaskLogs *CpTaskLogQuery
|
||||
withCreatedCards *SysCardQuery
|
||||
withUsedCards *SysCardQuery
|
||||
withCashbackCards *SysCardQuery
|
||||
withBalanceRecords *SysBalanceRecordQuery
|
||||
withFKs bool
|
||||
modifiers []func(*sql.Selector)
|
||||
withNamedChildren map[string]*SysUserQuery
|
||||
withNamedRoles map[string]*SysRoleQuery
|
||||
withNamedImages map[string]*CpImageQuery
|
||||
withNamedCpuser map[string]*CpUserQuery
|
||||
withNamedCpTask map[string]*CpTaskQuery
|
||||
withNamedCpLeave map[string]*CpLeaveQuery
|
||||
withNamedCourseEntity map[string]*CourseEntityQuery
|
||||
withNamedCpTaskLogs map[string]*CpTaskLogQuery
|
||||
withNamedCreatedCards map[string]*SysCardQuery
|
||||
withNamedUsedCards map[string]*SysCardQuery
|
||||
withNamedCashbackCards map[string]*SysCardQuery
|
||||
withNamedBalanceRecords map[string]*SysBalanceRecordQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
@@ -421,6 +424,31 @@ func (_q *SysUserQuery) QueryCashbackCards() *SysCardQuery {
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryBalanceRecords chains the current query on the "balance_records" edge.
|
||||
func (_q *SysUserQuery) QueryBalanceRecords() *SysBalanceRecordQuery {
|
||||
query := (&SysBalanceRecordClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(sysuser.Table, sysuser.FieldID, selector),
|
||||
sqlgraph.To(sysbalancerecord.Table, sysbalancerecord.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, sysuser.BalanceRecordsTable, sysuser.BalanceRecordsColumn),
|
||||
)
|
||||
schemaConfig := _q.schemaConfig
|
||||
step.To.Schema = schemaConfig.SysBalanceRecord
|
||||
step.Edge.Schema = schemaConfig.SysBalanceRecord
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first SysUser entity from the query.
|
||||
// Returns a *NotFoundError when no SysUser was found.
|
||||
func (_q *SysUserQuery) First(ctx context.Context) (*SysUser, error) {
|
||||
@@ -608,24 +636,25 @@ func (_q *SysUserQuery) Clone() *SysUserQuery {
|
||||
return nil
|
||||
}
|
||||
return &SysUserQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]sysuser.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.SysUser{}, _q.predicates...),
|
||||
withParent: _q.withParent.Clone(),
|
||||
withChildren: _q.withChildren.Clone(),
|
||||
withRoles: _q.withRoles.Clone(),
|
||||
withAgent: _q.withAgent.Clone(),
|
||||
withImages: _q.withImages.Clone(),
|
||||
withCpuser: _q.withCpuser.Clone(),
|
||||
withCpTask: _q.withCpTask.Clone(),
|
||||
withCpLeave: _q.withCpLeave.Clone(),
|
||||
withCourseEntity: _q.withCourseEntity.Clone(),
|
||||
withCpTaskLogs: _q.withCpTaskLogs.Clone(),
|
||||
withCreatedCards: _q.withCreatedCards.Clone(),
|
||||
withUsedCards: _q.withUsedCards.Clone(),
|
||||
withCashbackCards: _q.withCashbackCards.Clone(),
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]sysuser.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.SysUser{}, _q.predicates...),
|
||||
withParent: _q.withParent.Clone(),
|
||||
withChildren: _q.withChildren.Clone(),
|
||||
withRoles: _q.withRoles.Clone(),
|
||||
withAgent: _q.withAgent.Clone(),
|
||||
withImages: _q.withImages.Clone(),
|
||||
withCpuser: _q.withCpuser.Clone(),
|
||||
withCpTask: _q.withCpTask.Clone(),
|
||||
withCpLeave: _q.withCpLeave.Clone(),
|
||||
withCourseEntity: _q.withCourseEntity.Clone(),
|
||||
withCpTaskLogs: _q.withCpTaskLogs.Clone(),
|
||||
withCreatedCards: _q.withCreatedCards.Clone(),
|
||||
withUsedCards: _q.withUsedCards.Clone(),
|
||||
withCashbackCards: _q.withCashbackCards.Clone(),
|
||||
withBalanceRecords: _q.withBalanceRecords.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
@@ -776,6 +805,17 @@ func (_q *SysUserQuery) WithCashbackCards(opts ...func(*SysCardQuery)) *SysUserQ
|
||||
return _q
|
||||
}
|
||||
|
||||
// WithBalanceRecords tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "balance_records" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *SysUserQuery) WithBalanceRecords(opts ...func(*SysBalanceRecordQuery)) *SysUserQuery {
|
||||
query := (&SysBalanceRecordClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withBalanceRecords = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
@@ -855,7 +895,7 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
|
||||
nodes = []*SysUser{}
|
||||
withFKs = _q.withFKs
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [13]bool{
|
||||
loadedTypes = [14]bool{
|
||||
_q.withParent != nil,
|
||||
_q.withChildren != nil,
|
||||
_q.withRoles != nil,
|
||||
@@ -869,6 +909,7 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
|
||||
_q.withCreatedCards != nil,
|
||||
_q.withUsedCards != nil,
|
||||
_q.withCashbackCards != nil,
|
||||
_q.withBalanceRecords != nil,
|
||||
}
|
||||
)
|
||||
if _q.withParent != nil {
|
||||
@@ -1044,6 +1085,18 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := _q.withBalanceRecords; query != nil {
|
||||
if err := _q.loadBalanceRecords(ctx, query, nodes,
|
||||
func(n *SysUser) { n.Edges.BalanceRecords = []*SysBalanceRecord{} },
|
||||
func(n *SysUser, e *SysBalanceRecord) {
|
||||
n.Edges.BalanceRecords = append(n.Edges.BalanceRecords, e)
|
||||
if !e.Edges.loadedTypes[0] {
|
||||
e.Edges.User = n
|
||||
}
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
for name, query := range _q.withNamedChildren {
|
||||
if err := _q.loadChildren(ctx, query, nodes,
|
||||
func(n *SysUser) { n.appendNamedChildren(name) },
|
||||
@@ -1171,6 +1224,18 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
for name, query := range _q.withNamedBalanceRecords {
|
||||
if err := _q.loadBalanceRecords(ctx, query, nodes,
|
||||
func(n *SysUser) { n.appendNamedBalanceRecords(name) },
|
||||
func(n *SysUser, e *SysBalanceRecord) {
|
||||
n.appendNamedBalanceRecords(name, e)
|
||||
if !e.Edges.loadedTypes[0] {
|
||||
e.Edges.User = n
|
||||
}
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
@@ -1597,6 +1662,36 @@ func (_q *SysUserQuery) loadCashbackCards(ctx context.Context, query *SysCardQue
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (_q *SysUserQuery) loadBalanceRecords(ctx context.Context, query *SysBalanceRecordQuery, nodes []*SysUser, init func(*SysUser), assign func(*SysUser, *SysBalanceRecord)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int64]*SysUser)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
if len(query.ctx.Fields) > 0 {
|
||||
query.ctx.AppendFieldOnce(sysbalancerecord.FieldUserID)
|
||||
}
|
||||
query.Where(predicate.SysBalanceRecord(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(sysuser.BalanceRecordsColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.UserID
|
||||
node, ok := nodeids[fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "user_id" returned %v for node %v`, fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *SysUserQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
@@ -1876,6 +1971,20 @@ func (_q *SysUserQuery) WithNamedCashbackCards(name string, opts ...func(*SysCar
|
||||
return _q
|
||||
}
|
||||
|
||||
// WithNamedBalanceRecords tells the query-builder to eager-load the nodes that are connected to the "balance_records"
|
||||
// edge with the given name. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *SysUserQuery) WithNamedBalanceRecords(name string, opts ...func(*SysBalanceRecordQuery)) *SysUserQuery {
|
||||
query := (&SysBalanceRecordClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
if _q.withNamedBalanceRecords == nil {
|
||||
_q.withNamedBalanceRecords = make(map[string]*SysBalanceRecordQuery)
|
||||
}
|
||||
_q.withNamedBalanceRecords[name] = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// SysUserGroupBy is the group-by builder for SysUser entities.
|
||||
type SysUserGroupBy struct {
|
||||
selector
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysagent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysrole"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
@@ -367,6 +368,21 @@ func (_u *SysUserUpdate) AddCashbackCards(v ...*SysCard) *SysUserUpdate {
|
||||
return _u.AddCashbackCardIDs(ids...)
|
||||
}
|
||||
|
||||
// AddBalanceRecordIDs adds the "balance_records" edge to the SysBalanceRecord entity by IDs.
|
||||
func (_u *SysUserUpdate) AddBalanceRecordIDs(ids ...int64) *SysUserUpdate {
|
||||
_u.mutation.AddBalanceRecordIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddBalanceRecords adds the "balance_records" edges to the SysBalanceRecord entity.
|
||||
func (_u *SysUserUpdate) AddBalanceRecords(v ...*SysBalanceRecord) *SysUserUpdate {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddBalanceRecordIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the SysUserMutation object of the builder.
|
||||
func (_u *SysUserUpdate) Mutation() *SysUserMutation {
|
||||
return _u.mutation
|
||||
@@ -615,6 +631,27 @@ func (_u *SysUserUpdate) RemoveCashbackCards(v ...*SysCard) *SysUserUpdate {
|
||||
return _u.RemoveCashbackCardIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearBalanceRecords clears all "balance_records" edges to the SysBalanceRecord entity.
|
||||
func (_u *SysUserUpdate) ClearBalanceRecords() *SysUserUpdate {
|
||||
_u.mutation.ClearBalanceRecords()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveBalanceRecordIDs removes the "balance_records" edge to SysBalanceRecord entities by IDs.
|
||||
func (_u *SysUserUpdate) RemoveBalanceRecordIDs(ids ...int64) *SysUserUpdate {
|
||||
_u.mutation.RemoveBalanceRecordIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveBalanceRecords removes "balance_records" edges to SysBalanceRecord entities.
|
||||
func (_u *SysUserUpdate) RemoveBalanceRecords(v ...*SysBalanceRecord) *SysUserUpdate {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveBalanceRecordIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *SysUserUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
@@ -1290,6 +1327,54 @@ func (_u *SysUserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.BalanceRecordsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.BalanceRecordsTable,
|
||||
Columns: []string{sysuser.BalanceRecordsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedBalanceRecordsIDs(); len(nodes) > 0 && !_u.mutation.BalanceRecordsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.BalanceRecordsTable,
|
||||
Columns: []string{sysuser.BalanceRecordsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.BalanceRecordsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.BalanceRecordsTable,
|
||||
Columns: []string{sysuser.BalanceRecordsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_spec.Node.Schema = _u.schemaConfig.SysUser
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _u.schemaConfig)
|
||||
_spec.AddModifiers(_u.modifiers...)
|
||||
@@ -1641,6 +1726,21 @@ func (_u *SysUserUpdateOne) AddCashbackCards(v ...*SysCard) *SysUserUpdateOne {
|
||||
return _u.AddCashbackCardIDs(ids...)
|
||||
}
|
||||
|
||||
// AddBalanceRecordIDs adds the "balance_records" edge to the SysBalanceRecord entity by IDs.
|
||||
func (_u *SysUserUpdateOne) AddBalanceRecordIDs(ids ...int64) *SysUserUpdateOne {
|
||||
_u.mutation.AddBalanceRecordIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddBalanceRecords adds the "balance_records" edges to the SysBalanceRecord entity.
|
||||
func (_u *SysUserUpdateOne) AddBalanceRecords(v ...*SysBalanceRecord) *SysUserUpdateOne {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddBalanceRecordIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the SysUserMutation object of the builder.
|
||||
func (_u *SysUserUpdateOne) Mutation() *SysUserMutation {
|
||||
return _u.mutation
|
||||
@@ -1889,6 +1989,27 @@ func (_u *SysUserUpdateOne) RemoveCashbackCards(v ...*SysCard) *SysUserUpdateOne
|
||||
return _u.RemoveCashbackCardIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearBalanceRecords clears all "balance_records" edges to the SysBalanceRecord entity.
|
||||
func (_u *SysUserUpdateOne) ClearBalanceRecords() *SysUserUpdateOne {
|
||||
_u.mutation.ClearBalanceRecords()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveBalanceRecordIDs removes the "balance_records" edge to SysBalanceRecord entities by IDs.
|
||||
func (_u *SysUserUpdateOne) RemoveBalanceRecordIDs(ids ...int64) *SysUserUpdateOne {
|
||||
_u.mutation.RemoveBalanceRecordIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveBalanceRecords removes "balance_records" edges to SysBalanceRecord entities.
|
||||
func (_u *SysUserUpdateOne) RemoveBalanceRecords(v ...*SysBalanceRecord) *SysUserUpdateOne {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveBalanceRecordIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SysUserUpdate builder.
|
||||
func (_u *SysUserUpdateOne) Where(ps ...predicate.SysUser) *SysUserUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
@@ -2594,6 +2715,54 @@ func (_u *SysUserUpdateOne) sqlSave(ctx context.Context) (_node *SysUser, err er
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.BalanceRecordsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.BalanceRecordsTable,
|
||||
Columns: []string{sysuser.BalanceRecordsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedBalanceRecordsIDs(); len(nodes) > 0 && !_u.mutation.BalanceRecordsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.BalanceRecordsTable,
|
||||
Columns: []string{sysuser.BalanceRecordsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.BalanceRecordsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.BalanceRecordsTable,
|
||||
Columns: []string{sysuser.BalanceRecordsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.SysBalanceRecord
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_spec.Node.Schema = _u.schemaConfig.SysUser
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _u.schemaConfig)
|
||||
_spec.AddModifiers(_u.modifiers...)
|
||||
|
||||
@@ -30,8 +30,12 @@ type Tx struct {
|
||||
CpUser *CpUserClient
|
||||
// SysAgent is the client for interacting with the SysAgent builders.
|
||||
SysAgent *SysAgentClient
|
||||
// SysBalanceRecord is the client for interacting with the SysBalanceRecord builders.
|
||||
SysBalanceRecord *SysBalanceRecordClient
|
||||
// SysCard is the client for interacting with the SysCard builders.
|
||||
SysCard *SysCardClient
|
||||
// SysConfig is the client for interacting with the SysConfig builders.
|
||||
SysConfig *SysConfigClient
|
||||
// SysMenu is the client for interacting with the SysMenu builders.
|
||||
SysMenu *SysMenuClient
|
||||
// SysRole is the client for interacting with the SysRole builders.
|
||||
@@ -179,7 +183,9 @@ func (tx *Tx) init() {
|
||||
tx.CpTaskLog = NewCpTaskLogClient(tx.config)
|
||||
tx.CpUser = NewCpUserClient(tx.config)
|
||||
tx.SysAgent = NewSysAgentClient(tx.config)
|
||||
tx.SysBalanceRecord = NewSysBalanceRecordClient(tx.config)
|
||||
tx.SysCard = NewSysCardClient(tx.config)
|
||||
tx.SysConfig = NewSysConfigClient(tx.config)
|
||||
tx.SysMenu = NewSysMenuClient(tx.config)
|
||||
tx.SysRole = NewSysRoleClient(tx.config)
|
||||
tx.SysUser = NewSysUserClient(tx.config)
|
||||
|
||||
@@ -94,7 +94,7 @@ func (c *CpdailyTaskHandler) ProcessTask(ctx context.Context, task *asynq.Task)
|
||||
schoolDetail := school.GetSchoolDetail(ctx, targetTask.Edges.CpUser.SchoolID)
|
||||
cookie := targetTask.Edges.CpUser.Cookie
|
||||
restyClient := login.GetClient(ctx, cookie)
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, restyClient) {
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, restyClient, targetTask.Edges.CpUser.LoginType) {
|
||||
loginExecutor := login.GetCpdailyLoginBySchoolInfo(ctx, &schoolDetail)
|
||||
loginExecutor.Login(ctx, &schoolDetail, targetTask.Edges.CpUser.Username, targetTask.Edges.CpUser.Password)
|
||||
cookie = loginExecutor.GetCookieString()
|
||||
@@ -209,8 +209,8 @@ func (c *CpdailyTaskHandler) sendTaskNotificationEmail(ctx context.Context, task
|
||||
emailAddr = task.Edges.CpUser.Email
|
||||
}
|
||||
case cptask.NotificationTypeSystemUserEmail:
|
||||
if task.Edges.CpUser != nil && task.Edges.CpUser.Edges.Sysuser != nil && task.Edges.CpUser.Edges.Sysuser.Email != "" {
|
||||
emailAddr = task.Edges.CpUser.Edges.Sysuser.Email
|
||||
if task.Edges.CpUser != nil && task.Edges.SysUser != nil && task.Edges.SysUser.Email != "" {
|
||||
emailAddr = task.Edges.SysUser.Email
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"likedream-goframe/internal/framework/logger"
|
||||
"likedream-goframe/internal/framework/model/email"
|
||||
"likedream-goframe/internal/utils"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/hibiken/asynq"
|
||||
"github.com/samber/oops"
|
||||
@@ -19,8 +20,15 @@ type EmailTaskHandler struct {
|
||||
|
||||
func (h *EmailTaskHandler) ProcessTask(ctx context.Context, task *asynq.Task) (err error) {
|
||||
defer utils.Pass(&err)
|
||||
|
||||
var payload email.SendPayload
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
// 打印日志
|
||||
logger.Logger.Error("邮件发送失败", zap.String("邮箱", payload.To), zap.Error(r.(error)), zap.Stack(string(debug.Stack())))
|
||||
// 重新抛出相同的 panic
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
|
||||
e := gob.NewDecoder(bytes.NewReader(task.Payload())).Decode(&payload)
|
||||
utils.OkOrPanic(e, oops.WithContext(ctx).Wrap)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"encoding/gob"
|
||||
"likedream-goframe/internal/application/xuexitong"
|
||||
"likedream-goframe/internal/application/xuexitong/entity"
|
||||
"likedream-goframe/internal/common/db"
|
||||
errors2 "likedream-goframe/internal/common/errors"
|
||||
"likedream-goframe/internal/ent"
|
||||
@@ -105,13 +106,25 @@ func (h *XuexitongTaskHandler) ProcessTask(ctx context.Context, task *asynq.Task
|
||||
// 刷课完成后,统计任务情况
|
||||
g.Log().Infof(ctx, "刷课完成,正在统计任务情况...")
|
||||
|
||||
// 获取章节列表
|
||||
chapters := courseService.PullCourseChapterList(ctx, targetCourse.CourseID)
|
||||
// 先获取课程列表找到目标课程
|
||||
courseList := courseService.PullCourseList(ctx)
|
||||
var course *entity.XueXiTCourse
|
||||
for _, c := range courseList {
|
||||
if c.CourseID == targetCourse.CourseID {
|
||||
course = &c
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// 统计总任务数(累加所有章节的JobCount)
|
||||
totalTasks := 0
|
||||
for _, chapter := range chapters {
|
||||
totalTasks += chapter.JobCount
|
||||
if course != nil {
|
||||
// 获取章节列表
|
||||
chapters := courseService.PullCourseChapterList(ctx, *course)
|
||||
|
||||
// 统计总任务数(累加所有章节的JobCount)
|
||||
for _, chapter := range chapters {
|
||||
totalTasks += chapter.JobCount
|
||||
}
|
||||
}
|
||||
|
||||
g.Log().Infof(ctx, "课程 %s 统计完成: 总任务点 %d", targetCourse.CourseName, totalTasks)
|
||||
|
||||
@@ -90,10 +90,10 @@ func (s *AgentServiceV1) Recharge(ctx context.Context, req *v1.AgentRechargeReq)
|
||||
return utils.FailParam("非法的下级代理参数")
|
||||
}
|
||||
needBalance := utils.NeedBalance(parent.Edges.Agent.Rate, req.Amount, user.Edges.Agent.Rate)
|
||||
balance.BalanceService.ChangeUserBalance(ctx, parent.ID, needBalance.Neg())
|
||||
balance.BalanceService.ChangeUserBalance(ctx, parent.ID, needBalance.Neg(), "代理给下级充值")
|
||||
|
||||
}
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, req.Amount)
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, req.Amount, "代理充值")
|
||||
return utils.SuccessWithMsg("操作成功")
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ func (s *AgentServiceV1) AgentPutInfoReq(ctx context.Context, req *v1.AgentPutIn
|
||||
newBalance := utils.TransformBalance(oldBalance, req.Rate)
|
||||
// 6. 更新用户余额(如果更新了费率或者第一次改为代理)
|
||||
if user.Edges.Agent == nil || !user.Edges.Agent.Rate.Equal(req.Rate) {
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, newBalance.Sub(user.Balance))
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, newBalance.Sub(user.Balance), "代理费率调整")
|
||||
}
|
||||
utils.OkOrPanic(err, func(err error) error {
|
||||
return oops.
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package balance
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/common/db"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/utils"
|
||||
)
|
||||
|
||||
type BalanceRecordServiceV1 struct{}
|
||||
|
||||
func NewBalanceRecordServiceV1() *BalanceRecordServiceV1 {
|
||||
return &BalanceRecordServiceV1{}
|
||||
}
|
||||
|
||||
func (s *BalanceRecordServiceV1) List(ctx context.Context, req *v1.BalanceRecordListReq) *utils.Response[[]*ent.SysBalanceRecord] {
|
||||
user := utils.GetUserInfoFromCtx(ctx)
|
||||
|
||||
query := db.Global.SysBalanceRecord.Query().
|
||||
Where(sysbalancerecord.HasUserWith(sysuser.ID(user.ID))).
|
||||
Order(ent.Desc(sysbalancerecord.FieldCreateTime))
|
||||
|
||||
// 根据类型过滤
|
||||
if req.Type != "" {
|
||||
query.Where(sysbalancerecord.TypeEQ(sysbalancerecord.Type(req.Type)))
|
||||
}
|
||||
|
||||
// 查询总数
|
||||
total := query.CountX(ctx)
|
||||
var data []*ent.SysBalanceRecord
|
||||
if total > 0 {
|
||||
query.Limit(req.Size).Offset((req.Page - 1) * req.Size)
|
||||
data = query.AllX(ctx)
|
||||
}
|
||||
|
||||
return utils.SuccessWithTotal[[]*ent.SysBalanceRecord](data, total)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"likedream-goframe/internal/common/db"
|
||||
"likedream-goframe/internal/common/errors"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/ent/sysbalancerecord"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/utils"
|
||||
|
||||
@@ -16,7 +17,10 @@ var BalanceService = &BalanceServiceV1{}
|
||||
type BalanceServiceV1 struct {
|
||||
}
|
||||
|
||||
func (v *BalanceServiceV1) ChangeUserBalance(ctx context.Context, userId int64, balance decimal.Decimal) {
|
||||
func (v *BalanceServiceV1) ChangeUserBalance(ctx context.Context, userId int64, balance decimal.Decimal, reason string) {
|
||||
if decimal.Zero.Equal(balance) {
|
||||
return
|
||||
}
|
||||
err := db.WithTx(ctx, func(c context.Context, tx *ent.Tx) {
|
||||
// 使用 SELECT ... FOR UPDATE 锁定用户记录
|
||||
user, err := tx.SysUser.Query().
|
||||
@@ -32,6 +36,28 @@ func (v *BalanceServiceV1) ChangeUserBalance(ctx context.Context, userId int64,
|
||||
utils.OkOrPanic(errors.NewBusinessError(400, "余额不足"))
|
||||
}
|
||||
|
||||
// 异步创建余额变动记录
|
||||
go func(userId int64, balanceChange decimal.Decimal, reason string, balanceBefore, balanceAfter decimal.Decimal) {
|
||||
recordCtx := context.Background()
|
||||
// 确定记录类型
|
||||
recordType := sysbalancerecord.TypeIncrease
|
||||
recordAmount := balanceChange
|
||||
if balanceChange.IsNegative() {
|
||||
recordType = sysbalancerecord.TypeDecrease
|
||||
recordAmount = balanceChange.Abs()
|
||||
}
|
||||
|
||||
// 创建余额变动记录
|
||||
db.Global.SysBalanceRecord.Create().
|
||||
SetUserID(userId).
|
||||
SetType(recordType).
|
||||
SetAmount(recordAmount).
|
||||
SetReason(reason).
|
||||
SetBalanceBefore(balanceBefore).
|
||||
SetBalanceAfter(balanceAfter).
|
||||
Save(recordCtx)
|
||||
}(userId, balance, reason, user.Balance, newBalance)
|
||||
|
||||
// 更新余额
|
||||
tx.SysUser.Update().
|
||||
Where(sysuser.ID(userId)).
|
||||
|
||||
@@ -54,7 +54,7 @@ func (v CardServiceV1) Add(ctx context.Context, req *v1.CardAddReq) *utils.Respo
|
||||
// 消费积分
|
||||
consumeBalance := decimal.Zero.Sub(utils.ConsumeBalance(user.Edges.Agent.Rate, pointTotal))
|
||||
// 扣除余额
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, consumeBalance)
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, consumeBalance, "生成卡密")
|
||||
// 添加卡密
|
||||
var cards []*ent.SysCardCreate
|
||||
for range req.Length {
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/common/db"
|
||||
errors2 "likedream-goframe/internal/common/errors"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/ent/sysconfig"
|
||||
"likedream-goframe/internal/utils"
|
||||
)
|
||||
|
||||
type ConfigServiceV1 struct {
|
||||
}
|
||||
|
||||
func NewV1() *ConfigServiceV1 {
|
||||
return &ConfigServiceV1{}
|
||||
}
|
||||
|
||||
// Get 获取配置
|
||||
func (s *ConfigServiceV1) Get(ctx context.Context, req *v1.ConfigGetReq) *utils.Response[*ent.SysConfig] {
|
||||
config, err := db.Global.SysConfig.Query().
|
||||
Where(sysconfig.KeyEQ(req.Key)).
|
||||
Only(ctx)
|
||||
|
||||
if err != nil {
|
||||
if ent.IsNotFound(err) {
|
||||
utils.OkOrPanic(errors2.NewBusinessError(404, "配置不存在"))
|
||||
}
|
||||
utils.OkOrPanic(err)
|
||||
}
|
||||
|
||||
return utils.SuccessWithData[*ent.SysConfig](config)
|
||||
}
|
||||
|
||||
// PublicGet 获取公开配置(无需认证)
|
||||
func (s *ConfigServiceV1) PublicGet(ctx context.Context, req *v1.ConfigPublicGetReq) *utils.Response[*ent.SysConfig] {
|
||||
// 只允许获取特定的公开配置
|
||||
allowedKeys := []string{"system.announcement"}
|
||||
|
||||
allowed := false
|
||||
for _, key := range allowedKeys {
|
||||
if req.Key == key {
|
||||
allowed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !allowed {
|
||||
utils.OkOrPanic(errors2.NewBusinessError(403, "该配置不允许公开访问"))
|
||||
}
|
||||
|
||||
config, err := db.Global.SysConfig.Query().
|
||||
Where(sysconfig.KeyEQ(req.Key)).
|
||||
Only(ctx)
|
||||
|
||||
if err != nil {
|
||||
if ent.IsNotFound(err) {
|
||||
// 如果配置不存在,返回空值
|
||||
return utils.SuccessWithData[*ent.SysConfig](nil)
|
||||
}
|
||||
utils.OkOrPanic(err)
|
||||
}
|
||||
|
||||
return utils.SuccessWithData[*ent.SysConfig](config)
|
||||
}
|
||||
|
||||
// List 获取配置列表
|
||||
func (s *ConfigServiceV1) List(ctx context.Context, req *v1.ConfigListReq) *utils.Response[[]*ent.SysConfig] {
|
||||
query := db.Global.SysConfig.Query().
|
||||
Order(ent.Asc(sysconfig.FieldKey))
|
||||
|
||||
if req.Key != "" {
|
||||
query.Where(sysconfig.KeyContains(req.Key))
|
||||
}
|
||||
|
||||
total := query.CountX(ctx)
|
||||
var data []*ent.SysConfig
|
||||
if total > 0 {
|
||||
query.Limit(req.Size).Offset((req.Page - 1) * req.Size)
|
||||
data = query.AllX(ctx)
|
||||
}
|
||||
return utils.SuccessWithTotal[[]*ent.SysConfig](data, total)
|
||||
}
|
||||
|
||||
// Update 更新配置
|
||||
func (s *ConfigServiceV1) Update(ctx context.Context, req *v1.ConfigUpdateReq) *utils.Response[any] {
|
||||
// 检查配置是否存在
|
||||
config, err := db.Global.SysConfig.Query().
|
||||
Where(sysconfig.KeyEQ(req.Key)).
|
||||
Only(ctx)
|
||||
|
||||
if err != nil {
|
||||
if ent.IsNotFound(err) {
|
||||
// 如果不存在,创建新配置
|
||||
db.Global.SysConfig.Create().
|
||||
SetKey(req.Key).
|
||||
SetValue(req.Value).
|
||||
SetDescription(req.Description).
|
||||
SetType("markdown"). // 默认为 markdown 类型
|
||||
SaveX(ctx)
|
||||
return utils.SuccessWithMsg("配置创建成功")
|
||||
}
|
||||
utils.OkOrPanic(err)
|
||||
}
|
||||
|
||||
// 更新配置
|
||||
db.Global.SysConfig.UpdateOne(config).
|
||||
SetValue(req.Value).
|
||||
SetDescription(req.Description).
|
||||
ExecX(ctx)
|
||||
|
||||
return utils.SuccessWithMsg("配置更新成功")
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/logger"
|
||||
"likedream-goframe/internal/utils"
|
||||
"strconv"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"go.uber.org/zap"
|
||||
@@ -78,9 +79,19 @@ func (s CourseServiceV1) AddCourse(ctx context.Context, req *v1.AddCourseReq) *u
|
||||
|
||||
client := loginClient.GetClient()
|
||||
courseService := xuexitong.NewXuexitongCourse(client)
|
||||
|
||||
var targetCourse *entity.XueXiTCourse
|
||||
// 获取课程章节列表
|
||||
chapters := courseService.PullCourseChapterList(ctx, req.CourseID)
|
||||
courseList := courseService.PullCourseList(ctx)
|
||||
for _, course := range courseList {
|
||||
if course.CourseID == req.CourseID {
|
||||
targetCourse = &course
|
||||
break
|
||||
}
|
||||
}
|
||||
if targetCourse == nil {
|
||||
utils.OkOrPanic(errors2.NewBusinessError(400, "未找到该课程"))
|
||||
}
|
||||
chapters := courseService.PullCourseChapterList(ctx, *targetCourse)
|
||||
|
||||
// 定义节点信息结构
|
||||
type NodeInfo struct {
|
||||
@@ -94,46 +105,79 @@ func (s CourseServiceV1) AddCourse(ctx context.Context, req *v1.AddCourseReq) *u
|
||||
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)
|
||||
cards, points, err := courseService.FetchChapterCards(ctx, *targetCourse, chapter.ID)
|
||||
if err != nil {
|
||||
logger.Logger.Warn("获取章节任务点失败", zap.String("chapter", chapter.Name), zap.Error(err))
|
||||
} else {
|
||||
for _, card := range cards {
|
||||
} else if points != nil {
|
||||
chapterIDStr := strconv.Itoa(chapter.ID)
|
||||
// 统计视频任务点
|
||||
for _, video := range points.Videos {
|
||||
nodeInfo := NodeInfo{
|
||||
ChapterID: chapter.ID,
|
||||
ChapterID: chapterIDStr,
|
||||
ChapterName: chapter.Name,
|
||||
CardID: card.ID,
|
||||
CardTitle: card.Title,
|
||||
CardType: card.Type,
|
||||
CardID: video.JobID,
|
||||
CardTitle: video.Title,
|
||||
CardType: "video",
|
||||
}
|
||||
allNodes = append(allNodes, nodeInfo)
|
||||
|
||||
// 检查是否已完成
|
||||
if card.IsPassed {
|
||||
nodeKey := chapter.ID + ":" + card.ID
|
||||
completedNodes = append(completedNodes, nodeKey)
|
||||
if video.IsPassed {
|
||||
completedNodes = append(completedNodes, chapterIDStr+":"+video.JobID)
|
||||
}
|
||||
}
|
||||
// 统计文档任务点
|
||||
for _, doc := range points.Documents {
|
||||
nodeInfo := NodeInfo{
|
||||
ChapterID: chapterIDStr,
|
||||
ChapterName: chapter.Name,
|
||||
CardID: doc.JobID,
|
||||
CardTitle: doc.Title,
|
||||
CardType: "document",
|
||||
}
|
||||
allNodes = append(allNodes, nodeInfo)
|
||||
}
|
||||
// 统计作业任务点
|
||||
for _, work := range points.Works {
|
||||
nodeInfo := NodeInfo{
|
||||
ChapterID: chapterIDStr,
|
||||
ChapterName: chapter.Name,
|
||||
CardID: work.JobID,
|
||||
CardTitle: work.Title,
|
||||
CardType: "work",
|
||||
}
|
||||
allNodes = append(allNodes, nodeInfo)
|
||||
if work.IsPassed {
|
||||
completedNodes = append(completedNodes, chapterIDStr+":"+work.JobID)
|
||||
}
|
||||
}
|
||||
// 统计外链任务点
|
||||
for _, link := range points.Hyperlinks {
|
||||
nodeInfo := NodeInfo{
|
||||
ChapterID: chapterIDStr,
|
||||
ChapterName: chapter.Name,
|
||||
CardID: link.JobID,
|
||||
CardTitle: link.Title,
|
||||
CardType: "hyperlink",
|
||||
}
|
||||
allNodes = append(allNodes, nodeInfo)
|
||||
}
|
||||
// 统计直播任务点
|
||||
for _, live := range points.Lives {
|
||||
nodeInfo := NodeInfo{
|
||||
ChapterID: chapterIDStr,
|
||||
ChapterName: chapter.Name,
|
||||
CardID: live.JobID,
|
||||
CardTitle: live.Title,
|
||||
CardType: "live",
|
||||
}
|
||||
allNodes = append(allNodes, nodeInfo)
|
||||
}
|
||||
_ = cards // cards 暂时不使用
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ func (v CpLeaveServiceV1) GetLeaveListFromSystem(ctx context.Context, req *v1.Ge
|
||||
client := login.GetClient(ctx, cookie)
|
||||
|
||||
// 检查cookie是否有效
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, client) {
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, client, cpUser.LoginType) {
|
||||
loginExecutor := login.GetCpdailyLoginBySchoolInfo(ctx, &schoolDetail)
|
||||
loginExecutor.Login(ctx, &schoolDetail, cpUser.Username, cpUser.Password)
|
||||
cookie = loginExecutor.GetCookieString()
|
||||
@@ -120,14 +120,14 @@ func (v CpLeaveServiceV1) Report(ctx context.Context, req *v1.CpLeaveReportReq)
|
||||
}
|
||||
|
||||
// 计算扣款金额
|
||||
basePoint, err := decimal.NewFromString(g.Cfg().MustGet(ctx, cst2.ConfigBasePointCpdaily).String())
|
||||
basePoint, err := decimal.NewFromString(g.Cfg().MustGet(ctx, cst2.ConfigBasePointCpdailyLeave).String())
|
||||
utils.OkOrPanic(err)
|
||||
if user.Edges.Agent != nil {
|
||||
basePoint = basePoint.Mul(user.Edges.Agent.Rate)
|
||||
}
|
||||
|
||||
// 先扣款
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, basePoint.Neg())
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, basePoint.Neg(), "今日校园销假")
|
||||
|
||||
// 创建销假记录
|
||||
leaveRecord := db2.Global.CpLeave.Create().
|
||||
@@ -144,7 +144,7 @@ func (v CpLeaveServiceV1) Report(ctx context.Context, req *v1.CpLeaveReportReq)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
// 如果业务执行失败,退回扣款
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, basePoint)
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, basePoint, "销假失败退款")
|
||||
// 更新记录状态为失败,并记录失败原因
|
||||
desc := fmt.Sprintf("销假失败: %v", r)
|
||||
db2.Global.CpLeave.UpdateOne(leaveRecord).
|
||||
@@ -161,7 +161,7 @@ func (v CpLeaveServiceV1) Report(ctx context.Context, req *v1.CpLeaveReportReq)
|
||||
client := login.GetClient(ctx, cookie)
|
||||
|
||||
// 检查cookie是否有效
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, client) {
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, client, cpUser.LoginType) {
|
||||
loginExecutor := login.GetCpdailyLoginBySchoolInfo(ctx, &schoolDetail)
|
||||
loginExecutor.Login(ctx, &schoolDetail, cpUser.Username, cpUser.Password)
|
||||
cookie = loginExecutor.GetCookieString()
|
||||
|
||||
@@ -43,7 +43,7 @@ func (v CpTaskServiceV1) GetRecentTasks(ctx context.Context, req *v1.GetRecentTa
|
||||
}
|
||||
schoolDetail := school.GetSchoolDetail(ctx, cpUser.SchoolID)
|
||||
client := login.GetClient(ctx, cpUser.Cookie)
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, client) {
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, client, cpUser.LoginType) {
|
||||
loginExecutor := login.GetCpdailyLoginBySchoolInfo(ctx, &schoolDetail)
|
||||
loginExecutor.Login(ctx, &schoolDetail, cpUser.Username, cpUser.Password)
|
||||
cookie := loginExecutor.GetCookieString()
|
||||
@@ -118,7 +118,7 @@ func (v CpTaskServiceV1) TaskFormData(ctx context.Context, req *v1.GetCpTaskForm
|
||||
schoolDetail := school.GetSchoolDetail(ctx, cpTask.Edges.CpUser.SchoolID)
|
||||
cookie := cpUser.Cookie
|
||||
client := login.GetClient(ctx, cookie)
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, client) {
|
||||
if !login.CookieEnabled(ctx, schoolDetail.WecloudUrl, client, cpUser.LoginType) {
|
||||
loginExecutor := login.GetCpdailyLoginBySchoolInfo(ctx, &schoolDetail)
|
||||
loginExecutor.Login(ctx, &schoolDetail, cpUser.Username, cpUser.Password)
|
||||
cookie = loginExecutor.GetCookieString()
|
||||
@@ -180,13 +180,13 @@ func (v CpTaskServiceV1) PostExecute(ctx context.Context, req *v1.PostCpTaskExec
|
||||
}
|
||||
|
||||
//扣积分
|
||||
basePoint, err := decimal.NewFromString(g.Cfg().MustGet(ctx, cst2.ConfigBasePointCpdaily).String())
|
||||
basePoint, err := decimal.NewFromString(g.Cfg().MustGet(ctx, cst2.ConfigBasePointCpdailyTask).String())
|
||||
utils.OkOrPanic(err)
|
||||
if user.Edges.Agent != nil {
|
||||
basePoint = basePoint.Mul(user.Edges.Agent.Rate)
|
||||
}
|
||||
needPoint := basePoint.Mul(decimal.NewFromInt(int64(consume)))
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, needPoint.Neg())
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, needPoint.Neg(), "今日校园任务")
|
||||
// 更新任务
|
||||
e := db2.WithTx(ctx, func(ctx context.Context, tx *ent.Tx) {
|
||||
update := db2.Global.CpTask.UpdateOne(cpTask).
|
||||
|
||||
@@ -3,6 +3,7 @@ package cpdaily
|
||||
import (
|
||||
"context"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/application/cookiejar"
|
||||
"likedream-goframe/internal/application/cpdaily/login"
|
||||
"likedream-goframe/internal/application/cpdaily/school"
|
||||
"likedream-goframe/internal/common/cst"
|
||||
@@ -12,12 +13,15 @@ import (
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/redis"
|
||||
"likedream-goframe/internal/service/balance"
|
||||
"likedream-goframe/internal/utils"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/samber/oops"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
type CpUserServiceV1 struct {
|
||||
@@ -66,6 +70,7 @@ func (v CpUserServiceV1) ConfirmAdd(ctx context.Context, req *v1.CpUserConfirmAd
|
||||
SetMobileType(cpuser.MobileTypeRandom).
|
||||
SetSchoolID(sc.Id).
|
||||
SetSysuserID(user.ID).
|
||||
SetLoginType(cpuser.LoginTypeAccount).
|
||||
SaveX(ctx)
|
||||
return utils.SuccessWithMsg("添加成功")
|
||||
}
|
||||
@@ -88,6 +93,7 @@ func (v CpUserServiceV1) List(ctx context.Context, req *v1.CpUserListReq) *utils
|
||||
// 忽略密码
|
||||
for _, v := range data {
|
||||
v.Password = ""
|
||||
v.Cookie = ""
|
||||
}
|
||||
return utils.SuccessWithTotal[[]*ent.CpUser](data, total)
|
||||
}
|
||||
@@ -174,11 +180,53 @@ func (v CpUserServiceV1) AuthorizeRandom(ctx context.Context, req *v1.CpUserAuth
|
||||
}
|
||||
|
||||
func (v CpUserServiceV1) LoginGetCode(ctx context.Context, req *v1.LoginGetCode) *utils.Response[any] {
|
||||
return utils.SuccessWithMsg("")
|
||||
user := utils.GetUserInfoFromCtx(ctx)
|
||||
// 扣费
|
||||
basePoint, err := decimal.NewFromString(g.Cfg().MustGet(ctx, cst.ConfigBasePointCpdailyPhone).String())
|
||||
utils.OkOrPanic(err)
|
||||
if user.Edges.Agent != nil {
|
||||
basePoint = basePoint.Mul(user.Edges.Agent.Rate)
|
||||
}
|
||||
if user.Balance.Sub(basePoint).IsNegative() {
|
||||
return utils.Fail(400, "余额不足")
|
||||
}
|
||||
loginExecutor := login.NewSmsWithoutDeviceID()
|
||||
loginExecutor.SendSms(ctx, req.Mobile)
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, basePoint.Neg(), "手机号登录 - 验证码")
|
||||
return utils.SuccessWithMsg("发送成功")
|
||||
}
|
||||
|
||||
func (v CpUserServiceV1) AddByCode(ctx context.Context, req *v1.AddByCode) *utils.Response[any] {
|
||||
return utils.SuccessWithMsg("")
|
||||
user := utils.GetUserInfoFromCtx(ctx)
|
||||
jar := cookiejar.NewPersistCookieJar()
|
||||
loginExecutor := login.NewSmsWithoutDeviceID()
|
||||
data := loginExecutor.LoginByCode(context.Background(), req.Mobile, req.Code, jar)
|
||||
loginExecutor.SetLoginCookie(context.Background(), jar, data)
|
||||
// 扣费
|
||||
basePoint, err := decimal.NewFromString(g.Cfg().MustGet(ctx, cst.ConfigBasePointCpdailyPhone).String())
|
||||
utils.OkOrPanic(err)
|
||||
if user.Edges.Agent != nil {
|
||||
basePoint = basePoint.Mul(user.Edges.Agent.Rate)
|
||||
}
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, basePoint.Neg(), "手机号登录 - 登录")
|
||||
if req.Id == 0 {
|
||||
db.Global.CpUser.Create().
|
||||
SetUsername(req.Mobile).
|
||||
SetEmail(req.Email).
|
||||
SetSchoolID(req.SchoolId).
|
||||
SetCookie(loginExecutor.GetCookieString()).
|
||||
SetMobileCode(utils.UUID()).
|
||||
SetMobileType(cpuser.MobileTypeRandom).
|
||||
SetSysuserID(user.ID).
|
||||
SetLoginType(cpuser.LoginTypePhone).
|
||||
SaveX(ctx)
|
||||
return utils.SuccessWithMsg("添加成功")
|
||||
} else {
|
||||
db.Global.CpUser.UpdateOneID(req.Id).
|
||||
SetCookie(loginExecutor.GetCookieString()).
|
||||
ExecX(ctx)
|
||||
return utils.SuccessWithMsg("更新成功")
|
||||
}
|
||||
}
|
||||
|
||||
func (v CpUserServiceV1) LoginUrl(ctx context.Context, req *v1.CpUserLoginUrlReq) *utils.Response[any] {
|
||||
|
||||
@@ -2,7 +2,9 @@ package service
|
||||
|
||||
import (
|
||||
"likedream-goframe/internal/service/agent"
|
||||
"likedream-goframe/internal/service/balance"
|
||||
"likedream-goframe/internal/service/card"
|
||||
"likedream-goframe/internal/service/config"
|
||||
"likedream-goframe/internal/service/course"
|
||||
"likedream-goframe/internal/service/cpdaily"
|
||||
"likedream-goframe/internal/service/email"
|
||||
@@ -27,6 +29,8 @@ type globalService struct {
|
||||
CpLeave *cpdaily.CpLeaveServiceV1
|
||||
Card *card.CardServiceV1
|
||||
Course *course.CourseServiceV1
|
||||
Config *config.ConfigServiceV1
|
||||
Balance *balance.BalanceRecordServiceV1
|
||||
}
|
||||
|
||||
var Global = globalService{
|
||||
@@ -44,4 +48,6 @@ var Global = globalService{
|
||||
CpLeave: cpdaily.NewCpLeaveServiceV1(),
|
||||
Card: card.NewCardServiceV1(),
|
||||
Course: course.NewCourseServiceV1(),
|
||||
Config: config.NewV1(),
|
||||
Balance: balance.NewBalanceRecordServiceV1(),
|
||||
}
|
||||
|
||||
@@ -152,9 +152,9 @@ func (s *UserInfoServiceV1) CardRecharge(ctx context.Context, req *v1.CardRechar
|
||||
tx.SysCard.UpdateOneID(card.ID).SetStatus(syscard.StatusUsed).SetUsedID(user.ID).ExecX(ctx)
|
||||
}
|
||||
err = tx.Commit()
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, decimal.NewFromUint64(card.Value))
|
||||
balance.BalanceService.ChangeUserBalance(ctx, user.ID, decimal.NewFromUint64(card.Value), "卡密充值")
|
||||
if parent != nil {
|
||||
balance.BalanceService.ChangeUserBalance(ctx, parent.ID, cashbackValue)
|
||||
balance.BalanceService.ChangeUserBalance(ctx, parent.ID, cashbackValue, "邀请返现")
|
||||
}
|
||||
utils.OkOrPanic(err, func(err error) error {
|
||||
return oops.
|
||||
@@ -366,14 +366,14 @@ func (s *UserInfoServiceV1) BalanceMigrate(ctx context.Context, req *v1.BalanceM
|
||||
}
|
||||
// 缩小5倍,新系统按1:1比例的 老系统是1:5
|
||||
b = b.Div(decimal.NewFromInt32(5))
|
||||
balance.BalanceService.ChangeUserBalance(ctx, newUser.ID, b)
|
||||
balance.BalanceService.ChangeUserBalance(ctx, newUser.ID, b, "积分迁移")
|
||||
|
||||
// 清空旧系统积分
|
||||
err = db.GlobalGorm.Table("AspNetUsers").Where("email = ?", oldSystemEmail).Update("balance", 0).Error
|
||||
if err != nil {
|
||||
// 旧系统更新失败,记录日志但不影响返回结果(因为新系统已经转移成功)
|
||||
// 回滚
|
||||
balance.BalanceService.ChangeUserBalance(ctx, newUser.ID, b.Neg())
|
||||
balance.BalanceService.ChangeUserBalance(ctx, newUser.ID, b.Neg(), "积分迁移失败回滚")
|
||||
// 这里可以考虑回滚新系统的操作,但为了简化流程暂时保留新系统的更新
|
||||
return utils.FailBusiness("旧系统积分清空失败,请联系管理员")
|
||||
}
|
||||
|
||||
@@ -4,14 +4,17 @@ import (
|
||||
"context"
|
||||
"likedream-goframe/internal/application/cpdaily/login"
|
||||
"likedream-goframe/internal/application/cpdaily/school"
|
||||
"likedream-goframe/internal/framework/redis"
|
||||
|
||||
"resty.dev/v3"
|
||||
)
|
||||
|
||||
const testUsername = "22302204227"
|
||||
const testPassword = "Yuki030616."
|
||||
const testSchoolId = "fzfu"
|
||||
const testUsername = "20241070187"
|
||||
const testPassword = "Xqihan2006."
|
||||
const testSchoolId = "1020481510696504"
|
||||
|
||||
func LoginTestUser() (*resty.Client, *school.SchoolDetailInfo) {
|
||||
redis.Init(context.Background())
|
||||
schoolDetail := school.GetSchoolDetail(context.Background(), testSchoolId)
|
||||
loginExecutor := login.GetCpdailyLoginBySchoolInfo(context.Background(), &schoolDetail)
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"likedream-goframe/internal/common/cst"
|
||||
)
|
||||
|
||||
type CpdailySmsContextBuilder struct {
|
||||
deviceID string
|
||||
sessionToken string
|
||||
tenantID string
|
||||
}
|
||||
|
||||
func NewCpdailySmsContextBuilder() *CpdailySmsContextBuilder {
|
||||
return &CpdailySmsContextBuilder{}
|
||||
}
|
||||
|
||||
func (b *CpdailySmsContextBuilder) WithDeviceID(deviceID string) *CpdailySmsContextBuilder {
|
||||
b.deviceID = deviceID
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *CpdailySmsContextBuilder) WithSessionToken(sessionToken string) *CpdailySmsContextBuilder {
|
||||
b.sessionToken = sessionToken
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *CpdailySmsContextBuilder) WithTenantID(tenantID string) *CpdailySmsContextBuilder {
|
||||
b.tenantID = tenantID
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *CpdailySmsContextBuilder) Build(ctx context.Context) context.Context {
|
||||
ctx = context.WithValue(ctx, cst.CtxCpdailyDeviceID, b.deviceID)
|
||||
ctx = context.WithValue(ctx, cst.CtxCpdailySessionToken, b.sessionToken)
|
||||
ctx = context.WithValue(ctx, cst.CtxCpdailyTenantID, b.tenantID)
|
||||
return ctx
|
||||
}
|
||||
Reference in New Issue
Block a user