Compare commits
41 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 98eb15f4e4 | |||
| 3a2e679b85 | |||
| 921192a914 | |||
| 107b472cf7 | |||
| 14108f6ba3 | |||
| a22f559889 | |||
| ececfa344d | |||
| 5ba9e38e1a | |||
| 6eb4bc6d8a | |||
| 17e6c0a789 | |||
| f067ed2ad0 | |||
| 7bfc7a58ab | |||
| 1ad0c285f2 | |||
| 498c51c585 | |||
| 6a6716655b | |||
| ddc0949e56 | |||
| a723733562 | |||
| e7307182dd | |||
| 92ccebfa4e | |||
| 30dd8a8dfe | |||
| 788f1f4de7 | |||
| 54d81b5ba8 | |||
| 4912a27348 | |||
| 085820892f | |||
| 391a4c2ccb | |||
| 92363c8185 | |||
| 73b6c01cf9 | |||
| f703344485 | |||
| d9049095e3 | |||
| b2f0f91712 | |||
| ac93a5385e | |||
| 644ceed436 | |||
| 77ea55eda2 | |||
| 0f83cfc9b9 | |||
| 83749fc647 | |||
| bd5f8a9b15 | |||
| 8889be8ca2 | |||
| 6d58222143 | |||
| c3019b741c | |||
| b5b2103372 | |||
| b234c87048 |
@@ -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)
|
||||
}
|
||||
+7
-1
@@ -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]
|
||||
@@ -46,7 +46,13 @@ bucket = "likedream"
|
||||
appVersion = "9.7.2"
|
||||
systemVersion = "iOS 17"
|
||||
calVersion = "firstv"
|
||||
sliderIds = ["1018764144934965", "sdhyxy", "hqdx"]
|
||||
|
||||
|
||||
|
||||
[basePoint]
|
||||
cpdailyTask = "0.5"
|
||||
cpdailyLeave = "4"
|
||||
cpdailyPhone = "0.25"
|
||||
[task]
|
||||
concurrency = 20
|
||||
@@ -0,0 +1,403 @@
|
||||
# 刷课接口文档
|
||||
|
||||
## 接口列表
|
||||
|
||||
### 1. 获取刷课列表
|
||||
|
||||
**接口地址**: `GET /course`
|
||||
|
||||
**请求参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| type | string | 否 | 类型,可选值:`xxt`(学习通) |
|
||||
| username | string | 否 | 账号(模糊搜索) |
|
||||
| status | string | 否 | 状态,可选值:`not_start`(未开始)、`waiting`(等待中)、`doing`(进行中)、`done`(已完成)、`fail`(失败)、`pause`(暂停) |
|
||||
| page | int | 否 | 页码,默认 1 |
|
||||
| size | int | 否 | 每页数量,默认 10 |
|
||||
|
||||
**返回示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": [
|
||||
{
|
||||
"id": 1,
|
||||
"user_id": 1,
|
||||
"username": "学习通账号",
|
||||
"password": "",
|
||||
"type": "xxt",
|
||||
"course_name": "大学英语",
|
||||
"course_id": "123456",
|
||||
"need": "task",
|
||||
"status": "waiting",
|
||||
"task_count": 10,
|
||||
"success_count": 5,
|
||||
"exam_state": "not_start",
|
||||
"violence": "no",
|
||||
"desc": "备注信息",
|
||||
"create_time": "2024-01-01T00:00:00Z",
|
||||
"update_time": "2024-01-01T00:00:00Z"
|
||||
}
|
||||
],
|
||||
"total": 100
|
||||
}
|
||||
```
|
||||
|
||||
**字段说明**:
|
||||
|
||||
- `type`: 类型 - `xxt`(学习通)
|
||||
- `need`: 需要刷的内容 - `task`(任务点)、`exam`(考试)、`all`(全部)
|
||||
- `status`: 状态 - `not_start`(未开始)、`waiting`(等待中)、`doing`(进行中)、`done`(已完成)、`fail`(失败)、`pause`(暂停)
|
||||
- `exam_state`: 考试状态 - `not_start`(未开始)、`waiting`(等待中)、`doing`(进行中)、`done`(已完成)、`fail`(失败)
|
||||
- `violence`: 是否暴力刷课 - `no`(否)、`yes`(是)
|
||||
|
||||
---
|
||||
|
||||
### 2. 查询课程列表
|
||||
|
||||
**接口地址**: `POST /course/query`
|
||||
|
||||
**说明**: 通过学习通账号密码查询当前可选的课程列表,用于在添加刷课前选择课程。
|
||||
|
||||
**请求参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| username | string | 是 | 学习通账号 |
|
||||
| password | string | 是 | 学习通密码 |
|
||||
|
||||
**请求示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"username": "学习通账号",
|
||||
"password": "学习通密码"
|
||||
}
|
||||
```
|
||||
|
||||
**返回示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": [
|
||||
{
|
||||
"cpi": 123456,
|
||||
"key": "234567",
|
||||
"courseId": "345678",
|
||||
"chatId": "456789",
|
||||
"courseTeacher": "张老师",
|
||||
"courseName": "大学英语",
|
||||
"courseImage": "https://example.com/image.jpg",
|
||||
"courseImageBase64": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAA...",
|
||||
"courseDataId": 567890,
|
||||
"ContentID": 678901,
|
||||
"isstart": true,
|
||||
"state": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**字段说明**:
|
||||
|
||||
- `cpi`: 用户唯一标识
|
||||
- `key`: 课程班级ID(classId)
|
||||
- `courseId`: 课程ID(**添加刷课时需要使用**)
|
||||
- `chatId`: 聊天ID
|
||||
- `courseTeacher`: 授课教师
|
||||
- `courseName`: 课程名称(**添加刷课时需要使用**)
|
||||
- `courseImage`: 课程封面图片URL
|
||||
- `courseImageBase64`: 课程封面图片Base64编码(包含Data URL前缀,可直接用于img标签的src属性)
|
||||
- `courseDataId`: 课程数据ID
|
||||
- `ContentID`: 内容ID
|
||||
- `isstart`: 是否已开课(true:已开课,false:未开课)
|
||||
- `state`: 课程状态(0:正常,1:已结束)
|
||||
|
||||
**注意事项**:
|
||||
|
||||
- `courseImageBase64` 字段已经包含了 Data URL 前缀(如 `data:image/jpeg;base64,`),可以直接设置到 `<img>` 标签的 `src` 属性
|
||||
- 如果图片下载失败,`courseImageBase64` 字段将为空字符串,此时可以使用 `courseImage` URL 作为备用
|
||||
|
||||
**错误示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 400,
|
||||
"message": "登录失败,请检查账号密码",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3. 添加刷课
|
||||
|
||||
**接口地址**: `POST /course`
|
||||
|
||||
**请求参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| username | string | 是 | 学习通账号 |
|
||||
| password | string | 是 | 学习通密码 |
|
||||
| type | string | 是 | 类型,目前只支持 `xxt`(学习通) |
|
||||
| course_name | string | 是 | 课程名称 |
|
||||
| course_id | string | 是 | 课程ID |
|
||||
| need | string | 是 | 需要刷的内容,可选值:`task`(任务点)、`exam`(考试)、`all`(全部) |
|
||||
| violence | string | 否 | 是否暴力刷课,可选值:`no`(否,默认)、`yes`(是) |
|
||||
| desc | string | 否 | 备注信息 |
|
||||
|
||||
**请求示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"username": "学习通账号",
|
||||
"password": "学习通密码",
|
||||
"type": "xxt",
|
||||
"course_name": "大学英语",
|
||||
"course_id": "123456",
|
||||
"need": "task",
|
||||
"violence": "no",
|
||||
"desc": "备注信息"
|
||||
}
|
||||
```
|
||||
|
||||
**返回示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "添加成功",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
**错误示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 400,
|
||||
"message": "该课程已存在刷课任务",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 4. 修改刷课密码
|
||||
|
||||
**接口地址**: `PUT /course/password/{id}`
|
||||
|
||||
**路径参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| id | int64 | 是 | 刷课任务ID |
|
||||
|
||||
**请求参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| password | string | 是 | 新密码 |
|
||||
|
||||
**请求示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"password": "新密码"
|
||||
}
|
||||
```
|
||||
|
||||
**返回示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "密码修改成功",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
**错误示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 400,
|
||||
"message": "课程不存在或无权限操作",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 5. 重刷课程
|
||||
|
||||
**接口地址**: `POST /course/restart/{id}`
|
||||
|
||||
**路径参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| id | int64 | 是 | 刷课任务ID |
|
||||
|
||||
**说明**: 只有状态为 `done`(已完成)的课程才能重刷,重刷后会重置课程状态、任务数量、成功数量和考试状态。
|
||||
|
||||
**返回示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "重刷成功",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
**错误示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 400,
|
||||
"message": "只有已完成的课程才能重刷",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 6. 暂停/恢复刷课
|
||||
|
||||
**接口地址**: `POST /course/pause/{id}`
|
||||
|
||||
**路径参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| id | int64 | 是 | 刷课任务ID |
|
||||
|
||||
**说明**: 该接口会在暂停和恢复之间切换:
|
||||
- 如果当前状态是 `pause`(暂停),则恢复为 `waiting`(等待中)
|
||||
- 如果当前状态不是暂停,则设置为 `pause`(暂停)
|
||||
|
||||
**返回示例(暂停)**:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "已暂停刷课",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
**返回示例(恢复)**:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "已恢复刷课",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 7. 删除刷课
|
||||
|
||||
**接口地址**: `DELETE /course/{id}`
|
||||
|
||||
**路径参数**:
|
||||
|
||||
| 参数名 | 类型 | 必填 | 说明 |
|
||||
|--------|------|------|------|
|
||||
| id | int64 | 是 | 刷课任务ID |
|
||||
|
||||
**返回示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "删除成功",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
**错误示例**:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 400,
|
||||
"message": "课程不存在或无权限操作",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 枚举值说明
|
||||
|
||||
### 类型 (type)
|
||||
|
||||
| 值 | 说明 |
|
||||
|-----|------|
|
||||
| xxt | 学习通 |
|
||||
|
||||
### 需要刷的内容 (need)
|
||||
|
||||
| 值 | 说明 |
|
||||
|-----|------|
|
||||
| task | 任务点 |
|
||||
| exam | 考试 |
|
||||
| all | 全部 |
|
||||
|
||||
### 状态 (status)
|
||||
|
||||
| 值 | 说明 |
|
||||
|-----|------|
|
||||
| not_start | 未开始 |
|
||||
| waiting | 等待中 |
|
||||
| doing | 进行中 |
|
||||
| done | 已完成 |
|
||||
| fail | 失败 |
|
||||
| pause | 暂停 |
|
||||
|
||||
### 考试状态 (exam_state)
|
||||
|
||||
| 值 | 说明 |
|
||||
|-----|------|
|
||||
| not_start | 未开始 |
|
||||
| waiting | 等待中 |
|
||||
| doing | 进行中 |
|
||||
| done | 已完成 |
|
||||
| fail | 失败 |
|
||||
|
||||
### 是否暴力刷课 (violence)
|
||||
|
||||
| 值 | 说明 |
|
||||
|-----|------|
|
||||
| no | 否 |
|
||||
| yes | 是 |
|
||||
|
||||
---
|
||||
|
||||
## 通用说明
|
||||
|
||||
### 认证
|
||||
|
||||
所有接口都需要用户认证,需要在请求头中携带认证信息(具体认证方式根据项目配置)。
|
||||
|
||||
### 权限
|
||||
|
||||
用户只能操作自己创建的刷课任务,无法访问或修改其他用户的数据。
|
||||
|
||||
### 错误码
|
||||
|
||||
| 错误码 | 说明 |
|
||||
|--------|------|
|
||||
| 200 | 成功 |
|
||||
| 400 | 业务错误(如参数错误、权限不足等) |
|
||||
| 401 | 未认证 |
|
||||
| 500 | 服务器错误 |
|
||||
@@ -4,8 +4,11 @@ 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"
|
||||
"likedream-goframe/internal/controller/music"
|
||||
@@ -40,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())
|
||||
@@ -54,8 +59,13 @@ 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())
|
||||
// 网课
|
||||
courseGroup := group.Group("/course").Middleware(middleware.AuthHandler, middleware.PermissionHandler)
|
||||
courseGroup.Bind(course.NewXxtCtrlV1())
|
||||
})
|
||||
|
||||
s.SetPort(port.Int())
|
||||
|
||||
@@ -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#配置键不能为空"`
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"likedream-goframe/internal/ent/courseentity"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type CourseListReq struct {
|
||||
g.Meta `path:"/course" method:"get" tags:"Course" summary:"获取刷课列表"`
|
||||
Type courseentity.Type `json:"type"`
|
||||
Username string `json:"username"`
|
||||
Status courseentity.Status `json:"status"`
|
||||
Page int `json:"page" d:"1"`
|
||||
Size int `json:"size" d:"10"`
|
||||
}
|
||||
|
||||
type AddCourseReq struct {
|
||||
g.Meta `path:"/course" method:"post" tags:"Course" summary:"添加刷课"`
|
||||
Username string `json:"username" v:"required#账号不能为空"`
|
||||
Password string `json:"password" v:"required#密码不能为空"`
|
||||
Type courseentity.Type `json:"type" v:"required#类型不能为空"`
|
||||
CourseName string `json:"course_name" v:"required#课程名称不能为空"`
|
||||
CourseID string `json:"course_id" v:"required#课程ID不能为空"`
|
||||
Need courseentity.Need `json:"need" v:"required#需要刷的内容不能为空"`
|
||||
Violence courseentity.Violence `json:"violence" d:"no"`
|
||||
Desc string `json:"desc"`
|
||||
}
|
||||
|
||||
type UpdateCoursePasswordReq struct {
|
||||
g.Meta `path:"/course/password/{id}" method:"put" tags:"Course" summary:"修改刷课密码"`
|
||||
ID int64 `json:"id"`
|
||||
Password string `json:"password" v:"required#密码不能为空"`
|
||||
}
|
||||
|
||||
type RestartCourseReq struct {
|
||||
g.Meta `path:"/course/restart/{id}" method:"post" tags:"Course" summary:"重刷课程"`
|
||||
ID int64 `json:"id"`
|
||||
}
|
||||
|
||||
type PauseCourseReq struct {
|
||||
g.Meta `path:"/course/pause/{id}" method:"post" tags:"Course" summary:"暂停刷课"`
|
||||
ID int64 `json:"id"`
|
||||
}
|
||||
|
||||
type DeleteCourseReq struct {
|
||||
g.Meta `path:"/course/{id}" method:"delete" tags:"Course" summary:"删除刷课"`
|
||||
ID int64 `json:"id"`
|
||||
}
|
||||
|
||||
type QueryCourseReq struct {
|
||||
g.Meta `path:"/course/query" method:"post" tags:"Course" summary:"查询课程列表"`
|
||||
Username string `json:"username" v:"required#账号不能为空"`
|
||||
Password string `json:"password" v:"required#密码不能为空"`
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package v1
|
||||
|
||||
// TaskStatisticsItem 每日任务统计项
|
||||
type TaskStatisticsItem struct {
|
||||
Date string `json:"date"` // 日期 格式:2006-01-02
|
||||
PendingTask int `json:"pendingTask"` // 需要完成的任务数
|
||||
SuccessTask int `json:"successTask"` // 成功执行的任务数
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type CpLeaveListReq struct {
|
||||
g.Meta `path:"/leave" method:"get" tags:"CpLeave" summary:"获取销假记录列表"`
|
||||
CpUserId int64 `json:"cpUserId"`
|
||||
Username string `json:"username"`
|
||||
Status string `json:"status"`
|
||||
Page int `json:"page" d:"1"`
|
||||
Size int `json:"size" d:"10"`
|
||||
}
|
||||
|
||||
type GetLeaveListFromSystemReq struct {
|
||||
g.Meta `path:"/leave/system/{cpUserId}" method:"get" tags:"CpLeave" summary:"获取今日校园系统中的请假列表"`
|
||||
CpUserId int64 `json:"cpUserId" v:"required#今日校园账号ID不能为空"`
|
||||
}
|
||||
|
||||
type CpLeaveReportReq struct {
|
||||
g.Meta `path:"/leave/report" method:"post" tags:"CpLeave" summary:"执行销假"`
|
||||
CpUserId int64 `json:"cpUserId" v:"required#今日校园账号ID不能为空"`
|
||||
LeaveId string `json:"leaveId" v:"required#请假记录ID不能为空"`
|
||||
Title string `json:"title" v:"required#请假记录标题不能为空"`
|
||||
}
|
||||
@@ -67,3 +67,12 @@ type PauseTaskReq struct {
|
||||
g.Meta `path:"/task/pause/{id}" method:"post" tags:"CpTask" summary:"暂停任务"`
|
||||
Id int64 `json:"id"`
|
||||
}
|
||||
|
||||
type FindLocationReq struct {
|
||||
g.Meta `path:"/task/location" method:"get" tags:"CpTask" summary:"查找地址"`
|
||||
Address string `json:"address"`
|
||||
}
|
||||
|
||||
type GetTaskStatisticsReq struct {
|
||||
g.Meta `path:"/task/statistics" method:"get" tags:"CpTask" summary:"获取近七日任务统计数据"`
|
||||
}
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
package v1
|
||||
|
||||
import "github.com/gogf/gf/v2/frame/g"
|
||||
import (
|
||||
"likedream-goframe/internal/framework/captcha"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type CpSchoolListReq struct {
|
||||
g.Meta `path:"/school" method:"get" tags:"CpSchool" summary:"获取cp学校列表"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type CpUserLoginUrlReq struct {
|
||||
g.Meta `path:"/loginUrl" method:"get" tags:"CpUser" summary:"获取登录url" auth:"false"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
type CpUserAddReq struct {
|
||||
g.Meta `path:"/user" method:"post" tags:"CpUser" summary:"添加cp用户"`
|
||||
Username string `json:"username" v:"required"`
|
||||
@@ -14,6 +21,24 @@ type CpUserAddReq struct {
|
||||
SchoolId string `json:"school_id"`
|
||||
Email string `json:"email" v:"email|regex:^.*@qq\\.com$#邮箱格式不正确|必须是QQ邮箱"`
|
||||
}
|
||||
type LoginGetCode struct {
|
||||
g.Meta `path:"/user/getCode" method:"post" tags:"CpUser" summary:"获取手机号登录验证码"`
|
||||
Mobile string `json:"mobile" v:"required#手机号不能为空"`
|
||||
CaptchaKey string `json:"captchaKey" v:"required#验证码不能不能为空"`
|
||||
Dots []captcha.ConfirmData `json:"dots" v:"required#验证码不能为空"`
|
||||
}
|
||||
|
||||
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 {
|
||||
g.Meta `path:"/user/confirm" method:"post" tags:"CpUser" summary:"多因子确认添加cp用户"`
|
||||
Key string `json:"key"`
|
||||
|
||||
@@ -1,3 +1,56 @@
|
||||
package captcha
|
||||
|
||||
func ApiSemiOCRVerification() {}
|
||||
import (
|
||||
"encoding/base64"
|
||||
"likedream-goframe/internal/application/httpclient"
|
||||
"likedream-goframe/internal/common/cst"
|
||||
"likedream-goframe/internal/utils"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/samber/oops"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func ApiSemiOCRVerification(bytes []byte, shape1, shape2 int64) string {
|
||||
data := Bytes2Base64(bytes)
|
||||
ctx := gctx.GetInitCtx()
|
||||
baseUrl := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaBaseUrl).String() + "/semiOcr"
|
||||
client := httpclient.Cpdaily.Clone(ctx)
|
||||
client.SetDoNotParseResponse(false)
|
||||
post, err := client.R().SetBody(map[string]any{
|
||||
"base64": data,
|
||||
"shape1": shape1,
|
||||
"shape2": shape2,
|
||||
}).Post(baseUrl)
|
||||
utils.OkOrPanic(err, func(err error) error {
|
||||
return oops.
|
||||
With("SemiOCRVerification", baseUrl).
|
||||
WithContext(ctx).
|
||||
Wrap(err)
|
||||
})
|
||||
result := post.String()
|
||||
return gjson.Get(result, "data").String()
|
||||
}
|
||||
|
||||
func ApiAutoOCRVerification(bytes []byte) string {
|
||||
data := Bytes2Base64(bytes)
|
||||
ctx := gctx.GetInitCtx()
|
||||
baseUrl := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaBaseUrl).String() + "/ocr"
|
||||
client := httpclient.Cpdaily.Clone(ctx)
|
||||
client.SetDoNotParseResponse(false)
|
||||
post, err := client.R().SetBody(map[string]any{
|
||||
"base64": data,
|
||||
}).Post(baseUrl)
|
||||
utils.OkOrPanic(err, func(err error) error {
|
||||
return oops.
|
||||
With("AutoOCRVerification", baseUrl).
|
||||
WithContext(ctx).
|
||||
Wrap(err)
|
||||
})
|
||||
result := post.String()
|
||||
return gjson.Get(result, "data").String()
|
||||
}
|
||||
func Bytes2Base64(data []byte) string {
|
||||
return base64.StdEncoding.EncodeToString(data)
|
||||
}
|
||||
|
||||
@@ -8,20 +8,21 @@ import (
|
||||
"likedream-goframe/internal/utils"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type domainMap map[string]cookieMap
|
||||
|
||||
// AllSavePersistCookieJar 支持泛域名的 Cookie Jar
|
||||
// 不同的二级域名会共享相同主域名的 cookies
|
||||
// 例如: passport2.chaoxing.com 和 mooc1-api.chaoxing.com 共享 .chaoxing.com 的 cookies
|
||||
// AllSavePersistCookieJar 完全无限制的 Cookie Jar
|
||||
// 所有域名的 cookies 都保存在一起,访问任何域名都返回所有 cookies
|
||||
// 不检查域名、路径等限制,适用于需要跨域共享 session 的场景
|
||||
type AllSavePersistCookieJar struct {
|
||||
domainMap domainMap
|
||||
*sync.RWMutex
|
||||
}
|
||||
|
||||
const globalDomain = "*" // 使用全局域名存储所有 cookies
|
||||
|
||||
func NewAllSavePersistCookieJar() *AllSavePersistCookieJar {
|
||||
return &AllSavePersistCookieJar{
|
||||
domainMap: make(domainMap),
|
||||
@@ -29,47 +30,22 @@ func NewAllSavePersistCookieJar() *AllSavePersistCookieJar {
|
||||
}
|
||||
}
|
||||
|
||||
// extractMainDomain 提取主域名
|
||||
// 例如: passport2.chaoxing.com -> chaoxing.com
|
||||
//
|
||||
// mooc1-api.chaoxing.com -> chaoxing.com
|
||||
// www.example.co.uk -> example.co.uk
|
||||
func extractMainDomain(host string) string {
|
||||
// 移除端口号
|
||||
if colonIndex := strings.Index(host, ":"); colonIndex != -1 {
|
||||
host = host[:colonIndex]
|
||||
}
|
||||
|
||||
parts := strings.Split(host, ".")
|
||||
if len(parts) <= 2 {
|
||||
// 已经是主域名或单级域名
|
||||
return host
|
||||
}
|
||||
|
||||
// 处理特殊的二级顶级域名,如 .co.uk, .com.cn 等
|
||||
// 简化处理:取最后两部分
|
||||
// 更复杂的情况可以使用 publicsuffix 包
|
||||
return strings.Join(parts[len(parts)-2:], ".")
|
||||
}
|
||||
|
||||
func (a *AllSavePersistCookieJar) SetCookies(u *url.URL, cookies []*http.Cookie) {
|
||||
a.Lock()
|
||||
defer a.Unlock()
|
||||
|
||||
// 提取主域名
|
||||
mainDomain := extractMainDomain(u.Host)
|
||||
|
||||
if _, exists := a.domainMap[mainDomain]; !exists {
|
||||
a.domainMap[mainDomain] = make(cookieMap)
|
||||
// 使用全局域名,所有 cookies 保存在一起
|
||||
if _, exists := a.domainMap[globalDomain]; !exists {
|
||||
a.domainMap[globalDomain] = make(cookieMap)
|
||||
}
|
||||
|
||||
for _, cookie := range cookies {
|
||||
if a.domainMap[mainDomain] == nil {
|
||||
a.domainMap[mainDomain] = make(cookieMap)
|
||||
if a.domainMap[globalDomain] == nil {
|
||||
a.domainMap[globalDomain] = make(cookieMap)
|
||||
}
|
||||
|
||||
// 查找是否存在相同 name, path 和 domain 的 cookie
|
||||
existingCookies := a.domainMap[mainDomain][cookie.Name]
|
||||
// 查找是否存在相同 name 的 cookie(忽略 path 和 domain)
|
||||
existingCookies := a.domainMap[globalDomain][cookie.Name]
|
||||
found := false
|
||||
for i, existing := range existingCookies {
|
||||
if existing.Path == cookie.Path && existing.Domain == cookie.Domain {
|
||||
@@ -82,7 +58,7 @@ func (a *AllSavePersistCookieJar) SetCookies(u *url.URL, cookies []*http.Cookie)
|
||||
|
||||
if !found {
|
||||
// 没有找到匹配的,添加新的 cookie
|
||||
a.domainMap[mainDomain][cookie.Name] = append(a.domainMap[mainDomain][cookie.Name], cookie)
|
||||
a.domainMap[globalDomain][cookie.Name] = append(a.domainMap[globalDomain][cookie.Name], cookie)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,15 +67,9 @@ func (a *AllSavePersistCookieJar) Cookies(u *url.URL) []*http.Cookie {
|
||||
a.RLock()
|
||||
defer a.RUnlock()
|
||||
|
||||
// 提取主域名
|
||||
mainDomain := extractMainDomain(u.Host)
|
||||
|
||||
if cookiesList, exists := a.domainMap[mainDomain]; exists {
|
||||
// 直接返回全局域名下的所有 cookies,不检查域名和路径
|
||||
if cookiesList, exists := a.domainMap[globalDomain]; exists {
|
||||
result := make([]*http.Cookie, 0, len(cookiesList))
|
||||
requestPath := u.Path
|
||||
if requestPath == "" {
|
||||
requestPath = "/"
|
||||
}
|
||||
|
||||
for _, cookies := range cookiesList {
|
||||
// 如果只有一个 cookie,直接返回
|
||||
@@ -108,28 +78,9 @@ func (a *AllSavePersistCookieJar) Cookies(u *url.URL) []*http.Cookie {
|
||||
continue
|
||||
}
|
||||
|
||||
// 有多个同名 cookie,选择最匹配的(path 最长且匹配请求路径的)
|
||||
var bestMatch *http.Cookie
|
||||
bestMatchLen := -1
|
||||
|
||||
for _, cookie := range cookies {
|
||||
cookiePath := cookie.Path
|
||||
if cookiePath == "" {
|
||||
cookiePath = "/"
|
||||
}
|
||||
|
||||
// 检查 path 是否匹配
|
||||
if pathMatch(requestPath, cookiePath) {
|
||||
if len(cookiePath) > bestMatchLen {
|
||||
bestMatch = cookie
|
||||
bestMatchLen = len(cookiePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果找到匹配的,添加到结果中
|
||||
if bestMatch != nil {
|
||||
result = append(result, bestMatch)
|
||||
// 有多个同名 cookie,返回最后设置的那个(列表最后一个)
|
||||
if len(cookies) > 0 {
|
||||
result = append(result, cookies[len(cookies)-1])
|
||||
}
|
||||
}
|
||||
return result
|
||||
|
||||
@@ -43,6 +43,11 @@ func (p *PersistCookieJar) SetCookies(u *url.URL, cookies []*http.Cookie) {
|
||||
p.hostMap[host] = make(cookieMap)
|
||||
}
|
||||
|
||||
// 检查并删除全局 cookie 中同名的 cookie
|
||||
if globalCookies, exists := p.hostMap[""]; exists {
|
||||
delete(globalCookies, cookie.Name)
|
||||
}
|
||||
|
||||
// 查找是否存在相同 name, path 和 domain 的 cookie
|
||||
existingCookies := p.hostMap[host][cookie.Name]
|
||||
found := false
|
||||
@@ -68,17 +73,21 @@ func (p *PersistCookieJar) Cookies(u *url.URL) []*http.Cookie {
|
||||
defer p.RUnlock()
|
||||
|
||||
host := u.Host
|
||||
if cookiesList, exists := p.hostMap[host]; exists {
|
||||
result := make([]*http.Cookie, 0, len(cookiesList))
|
||||
requestPath := u.Path
|
||||
if requestPath == "" {
|
||||
requestPath = "/"
|
||||
}
|
||||
requestPath := u.Path
|
||||
if requestPath == "" {
|
||||
requestPath = "/"
|
||||
}
|
||||
|
||||
for _, cookies := range cookiesList {
|
||||
result := make([]*http.Cookie, 0)
|
||||
addedNames := make(map[string]bool)
|
||||
|
||||
// 先添加匹配 host 的 cookie
|
||||
if cookiesList, exists := p.hostMap[host]; exists {
|
||||
for cookieName, cookies := range cookiesList {
|
||||
// 如果只有一个 cookie,直接返回
|
||||
if len(cookies) == 1 {
|
||||
result = append(result, cookies[0])
|
||||
addedNames[cookieName] = true
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -104,11 +113,50 @@ func (p *PersistCookieJar) Cookies(u *url.URL) []*http.Cookie {
|
||||
// 如果找到匹配的,添加到结果中
|
||||
if bestMatch != nil {
|
||||
result = append(result, bestMatch)
|
||||
addedNames[cookieName] = true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
return nil
|
||||
|
||||
// 再添加没有 host 的全局 cookie(避免重复)
|
||||
if globalCookies, exists := p.hostMap[""]; exists {
|
||||
for cookieName, cookies := range globalCookies {
|
||||
// 如果该名称的 cookie 已经从 host 中添加了,跳过
|
||||
if addedNames[cookieName] {
|
||||
continue
|
||||
}
|
||||
|
||||
// 如果只有一个 cookie,直接返回
|
||||
if len(cookies) == 1 {
|
||||
result = append(result, cookies[0])
|
||||
continue
|
||||
}
|
||||
|
||||
// 有多个同名 cookie,选择最匹配的
|
||||
var bestMatch *http.Cookie
|
||||
bestMatchLen := -1
|
||||
|
||||
for _, cookie := range cookies {
|
||||
cookiePath := cookie.Path
|
||||
if cookiePath == "" {
|
||||
cookiePath = "/"
|
||||
}
|
||||
|
||||
if pathMatch(requestPath, cookiePath) {
|
||||
if len(cookiePath) > bestMatchLen {
|
||||
bestMatch = cookie
|
||||
bestMatchLen = len(cookiePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if bestMatch != nil {
|
||||
result = append(result, bestMatch)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// pathMatch 检查请求路径是否匹配 cookie 的 path
|
||||
@@ -275,3 +323,30 @@ func (p *PersistCookieJar) DeserializeReader(reader io.Reader) {
|
||||
|
||||
p.hostMap = hostMap
|
||||
}
|
||||
|
||||
// RemoveCookieInfo 将所有 host 的 cookie 移除 host 信息,存储为全局 cookie
|
||||
func (p *PersistCookieJar) RemoveCookieInfo() {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
||||
// 确保全局 cookie map 存在
|
||||
if _, exists := p.hostMap[""]; !exists {
|
||||
p.hostMap[""] = make(cookieMap)
|
||||
}
|
||||
|
||||
// 将所有 host 的 cookie 移动到全局
|
||||
for host, hostCookies := range p.hostMap {
|
||||
// 跳过全局 cookie 本身
|
||||
if host == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// 将该 host 的所有 cookie 移动到全局
|
||||
for cookieName, cookies := range hostCookies {
|
||||
p.hostMap[""][cookieName] = cookies
|
||||
}
|
||||
|
||||
// 删除该 host 的 cookie
|
||||
delete(p.hostMap, host)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package cryptoutil
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAesDecrypt(t *testing.T) {
|
||||
str := "6XkC1UAk07fK0uTaGPUu77i/+r7j/o1JQ/XygRxee2LMiX5H+w/BOqOB6e7W o9kHDZMb1pqZNN43k1tjl0ephbPLEi8g9C1EqBw0suzxX74j3dUdCf6dd/0W 8KvntNXwju96Vy5B2oD2ZosLmUdB1m0xX5rxAdLJ//cTft87XDWoLM0fuasu fGvR4XXXYZN071x8F03+qqR52fD1UQGgn0uGkSa/nrUho32Sg7DNJzF/JBCk 6/z0lu0XmIPo1SDIVjOtYAmyUDMZGl/ZvSAu2w=="
|
||||
str = strings.ReplaceAll(str, " ", "")
|
||||
decodeString, _ := base64.StdEncoding.DecodeString(str)
|
||||
decrypt := DesDecrypt(decodeString, Cat)
|
||||
t.Log(string(decrypt))
|
||||
}
|
||||
@@ -0,0 +1,838 @@
|
||||
package cryptoutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// RSA Constants
|
||||
const (
|
||||
biRadixBits = 16
|
||||
bitsPerDigit = biRadixBits
|
||||
biRadix = 1 << 16 // 65536
|
||||
biHalfRadix = biRadix >> 1
|
||||
biRadixSquared = biRadix * biRadix
|
||||
maxDigitVal = biRadix - 1
|
||||
maxInteger = 9999999999999998
|
||||
dpl10 = 15
|
||||
)
|
||||
|
||||
var (
|
||||
maxDigits int
|
||||
zeroArray []int
|
||||
bigZero *BigInt
|
||||
bigOne *BigInt
|
||||
lr10 *BigInt
|
||||
highBitMasks = []int{0x0000, 0x8000, 0xC000, 0xE000, 0xF000, 0xF800,
|
||||
0xFC00, 0xFE00, 0xFF00, 0xFF80, 0xFFC0, 0xFFE0,
|
||||
0xFFF0, 0xFFF8, 0xFFFC, 0xFFFE, 0xFFFF}
|
||||
lowBitMasks = []int{0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F,
|
||||
0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF,
|
||||
0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF}
|
||||
hexToChar = []byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f'}
|
||||
hexatrigesimalToChar = []byte{
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
|
||||
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
|
||||
'u', 'v', 'w', 'x', 'y', 'z'}
|
||||
)
|
||||
|
||||
// BigInt represents a big integer
|
||||
type BigInt struct {
|
||||
digits []int
|
||||
isNeg bool
|
||||
}
|
||||
|
||||
// NewBigInt creates a new BigInt
|
||||
func NewBigInt() *BigInt {
|
||||
digits := make([]int, len(zeroArray))
|
||||
copy(digits, zeroArray)
|
||||
return &BigInt{
|
||||
digits: digits,
|
||||
isNeg: false,
|
||||
}
|
||||
}
|
||||
|
||||
// NewBigIntEmpty creates an empty BigInt
|
||||
func NewBigIntEmpty() *BigInt {
|
||||
return &BigInt{
|
||||
digits: nil,
|
||||
isNeg: false,
|
||||
}
|
||||
}
|
||||
|
||||
// SetMaxDigits sets the maximum number of digits
|
||||
func SetMaxDigits(value int) {
|
||||
maxDigits = value
|
||||
zeroArray = make([]int, maxDigits)
|
||||
bigZero = NewBigInt()
|
||||
bigOne = NewBigInt()
|
||||
bigOne.digits[0] = 1
|
||||
lr10 = BiFromNumber(1000000000000000)
|
||||
}
|
||||
|
||||
// BiFromNumber creates a BigInt from a number
|
||||
func BiFromNumber(i int64) *BigInt {
|
||||
result := NewBigInt()
|
||||
result.isNeg = i < 0
|
||||
i = int64(math.Abs(float64(i)))
|
||||
j := 0
|
||||
for i > 0 {
|
||||
result.digits[j] = int(i & maxDigitVal)
|
||||
j++
|
||||
i = i / biRadix
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// BiFromDecimal creates a BigInt from a decimal string
|
||||
func BiFromDecimal(s string) *BigInt {
|
||||
isNeg := len(s) > 0 && s[0] == '-'
|
||||
i := 0
|
||||
if isNeg {
|
||||
i = 1
|
||||
}
|
||||
|
||||
// Skip leading zeros
|
||||
for i < len(s) && s[i] == '0' {
|
||||
i++
|
||||
}
|
||||
|
||||
if i == len(s) {
|
||||
return NewBigInt()
|
||||
}
|
||||
|
||||
digitCount := len(s) - i
|
||||
fgl := digitCount % dpl10
|
||||
if fgl == 0 {
|
||||
fgl = dpl10
|
||||
}
|
||||
|
||||
num := parseNumber(s[i : i+fgl])
|
||||
result := BiFromNumber(num)
|
||||
i += fgl
|
||||
|
||||
for i < len(s) {
|
||||
result = BiAdd(BiMultiply(result, lr10), BiFromNumber(parseNumber(s[i:min(i+dpl10, len(s))])))
|
||||
i += dpl10
|
||||
}
|
||||
|
||||
result.isNeg = isNeg
|
||||
return result
|
||||
}
|
||||
|
||||
// BiCopy copies a BigInt
|
||||
func BiCopy(bi *BigInt) *BigInt {
|
||||
result := NewBigIntEmpty()
|
||||
result.digits = make([]int, len(bi.digits))
|
||||
copy(result.digits, bi.digits)
|
||||
result.isNeg = bi.isNeg
|
||||
return result
|
||||
}
|
||||
|
||||
// ReverseStr reverses a string
|
||||
func ReverseStr(s string) string {
|
||||
runes := []rune(s)
|
||||
for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
|
||||
runes[i], runes[j] = runes[j], runes[i]
|
||||
}
|
||||
return string(runes)
|
||||
}
|
||||
|
||||
// BiToString converts BigInt to string with given radix
|
||||
func BiToString(x *BigInt, radix int) string {
|
||||
b := NewBigInt()
|
||||
b.digits[0] = radix
|
||||
qr := BiDivideModulo(x, b)
|
||||
result := string(hexatrigesimalToChar[qr[1].digits[0]])
|
||||
|
||||
for BiCompare(qr[0], bigZero) == 1 {
|
||||
qr = BiDivideModulo(qr[0], b)
|
||||
result += string(hexatrigesimalToChar[qr[1].digits[0]])
|
||||
}
|
||||
|
||||
prefix := ""
|
||||
if x.isNeg {
|
||||
prefix = "-"
|
||||
}
|
||||
return prefix + ReverseStr(result)
|
||||
}
|
||||
|
||||
// BiToDecimal converts BigInt to decimal string
|
||||
func BiToDecimal(x *BigInt) string {
|
||||
b := NewBigInt()
|
||||
b.digits[0] = 10
|
||||
qr := BiDivideModulo(x, b)
|
||||
result := fmt.Sprintf("%d", qr[1].digits[0])
|
||||
|
||||
for BiCompare(qr[0], bigZero) == 1 {
|
||||
qr = BiDivideModulo(qr[0], b)
|
||||
result += fmt.Sprintf("%d", qr[1].digits[0])
|
||||
}
|
||||
|
||||
prefix := ""
|
||||
if x.isNeg {
|
||||
prefix = "-"
|
||||
}
|
||||
return prefix + ReverseStr(result)
|
||||
}
|
||||
|
||||
// DigitToHex converts a digit to hex string
|
||||
func DigitToHex(n int) string {
|
||||
mask := 0xf
|
||||
result := ""
|
||||
for i := 0; i < 4; i++ {
|
||||
result += string(hexToChar[n&mask])
|
||||
n >>= 4
|
||||
}
|
||||
return ReverseStr(result)
|
||||
}
|
||||
|
||||
// BiToHex converts BigInt to hex string
|
||||
func BiToHex(x *BigInt) string {
|
||||
result := ""
|
||||
for i := BiHighIndex(x); i > -1; i-- {
|
||||
result += DigitToHex(x.digits[i])
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// CharToHex converts a character code to hex value
|
||||
func CharToHex(c byte) int {
|
||||
const (
|
||||
ZERO = 48
|
||||
NINE = ZERO + 9
|
||||
littleA = 97
|
||||
littleZ = littleA + 25
|
||||
bigA = 65
|
||||
bigZ = 65 + 25
|
||||
)
|
||||
|
||||
if c >= ZERO && c <= NINE {
|
||||
return int(c - ZERO)
|
||||
} else if c >= bigA && c <= bigZ {
|
||||
return 10 + int(c-bigA)
|
||||
} else if c >= littleA && c <= littleZ {
|
||||
return 10 + int(c-littleA)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// HexToDigit converts hex string to digit
|
||||
func HexToDigit(s string) int {
|
||||
result := 0
|
||||
sl := min(len(s), 4)
|
||||
for i := 0; i < sl; i++ {
|
||||
result <<= 4
|
||||
result |= CharToHex(s[i])
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// BiFromHex creates BigInt from hex string
|
||||
func BiFromHex(s string) *BigInt {
|
||||
result := NewBigInt()
|
||||
sl := len(s)
|
||||
for i, j := sl, 0; i > 0; i, j = i-4, j+1 {
|
||||
start := max(i-4, 0)
|
||||
length := min(i, 4)
|
||||
if start+length > sl {
|
||||
length = sl - start
|
||||
}
|
||||
result.digits[j] = HexToDigit(s[start : start+length])
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// BiFromString creates BigInt from string with given radix
|
||||
func BiFromString(s string, radix int) *BigInt {
|
||||
isNeg := len(s) > 0 && s[0] == '-'
|
||||
istop := 0
|
||||
if isNeg {
|
||||
istop = 1
|
||||
}
|
||||
|
||||
result := NewBigInt()
|
||||
place := NewBigInt()
|
||||
place.digits[0] = 1
|
||||
|
||||
for i := len(s) - 1; i >= istop; i-- {
|
||||
c := s[i]
|
||||
digit := CharToHex(c)
|
||||
biDigit := BiMultiplyDigit(place, digit)
|
||||
result = BiAdd(result, biDigit)
|
||||
place = BiMultiplyDigit(place, radix)
|
||||
}
|
||||
|
||||
result.isNeg = isNeg
|
||||
return result
|
||||
}
|
||||
|
||||
// BiAdd adds two BigInts
|
||||
func BiAdd(x, y *BigInt) *BigInt {
|
||||
var result *BigInt
|
||||
|
||||
if x.isNeg != y.isNeg {
|
||||
y.isNeg = !y.isNeg
|
||||
result = BiSubtract(x, y)
|
||||
y.isNeg = !y.isNeg
|
||||
} else {
|
||||
result = NewBigInt()
|
||||
c := 0
|
||||
for i := 0; i < len(x.digits); i++ {
|
||||
n := x.digits[i] + y.digits[i] + c
|
||||
result.digits[i] = n % biRadix
|
||||
if n >= biRadix {
|
||||
c = 1
|
||||
} else {
|
||||
c = 0
|
||||
}
|
||||
}
|
||||
result.isNeg = x.isNeg
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// BiSubtract subtracts two BigInts
|
||||
func BiSubtract(x, y *BigInt) *BigInt {
|
||||
var result *BigInt
|
||||
|
||||
if x.isNeg != y.isNeg {
|
||||
y.isNeg = !y.isNeg
|
||||
result = BiAdd(x, y)
|
||||
y.isNeg = !y.isNeg
|
||||
} else {
|
||||
result = NewBigInt()
|
||||
c := 0
|
||||
|
||||
for i := 0; i < len(x.digits); i++ {
|
||||
n := x.digits[i] - y.digits[i] + c
|
||||
result.digits[i] = n % biRadix
|
||||
if result.digits[i] < 0 {
|
||||
result.digits[i] += biRadix
|
||||
}
|
||||
if n < 0 {
|
||||
c = -1
|
||||
} else {
|
||||
c = 0
|
||||
}
|
||||
}
|
||||
|
||||
if c == -1 {
|
||||
c = 0
|
||||
for i := 0; i < len(x.digits); i++ {
|
||||
n := 0 - result.digits[i] + c
|
||||
result.digits[i] = n % biRadix
|
||||
if result.digits[i] < 0 {
|
||||
result.digits[i] += biRadix
|
||||
}
|
||||
if n < 0 {
|
||||
c = -1
|
||||
} else {
|
||||
c = 0
|
||||
}
|
||||
}
|
||||
result.isNeg = !x.isNeg
|
||||
} else {
|
||||
result.isNeg = x.isNeg
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// BiHighIndex returns the highest non-zero digit index
|
||||
func BiHighIndex(x *BigInt) int {
|
||||
result := len(x.digits) - 1
|
||||
for result > 0 && x.digits[result] == 0 {
|
||||
result--
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// BiNumBits returns the number of bits
|
||||
func BiNumBits(x *BigInt) int {
|
||||
n := BiHighIndex(x)
|
||||
d := x.digits[n]
|
||||
m := (n + 1) * bitsPerDigit
|
||||
result := m
|
||||
for result > m-bitsPerDigit {
|
||||
if (d & 0x8000) != 0 {
|
||||
break
|
||||
}
|
||||
d <<= 1
|
||||
result--
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// BiMultiply multiplies two BigInts
|
||||
func BiMultiply(x, y *BigInt) *BigInt {
|
||||
result := NewBigInt()
|
||||
n := BiHighIndex(x)
|
||||
t := BiHighIndex(y)
|
||||
|
||||
for i := 0; i <= t; i++ {
|
||||
c := 0
|
||||
k := i
|
||||
for j := 0; j <= n; j, k = j+1, k+1 {
|
||||
uv := result.digits[k] + x.digits[j]*y.digits[i] + c
|
||||
result.digits[k] = uv & maxDigitVal
|
||||
c = uv >> biRadixBits
|
||||
}
|
||||
result.digits[i+n+1] = c
|
||||
}
|
||||
|
||||
result.isNeg = x.isNeg != y.isNeg
|
||||
return result
|
||||
}
|
||||
|
||||
// BiMultiplyDigit multiplies BigInt by a digit
|
||||
func BiMultiplyDigit(x *BigInt, y int) *BigInt {
|
||||
result := NewBigInt()
|
||||
n := BiHighIndex(x)
|
||||
c := 0
|
||||
|
||||
for j := 0; j <= n; j++ {
|
||||
uv := result.digits[j] + x.digits[j]*y + c
|
||||
result.digits[j] = uv & maxDigitVal
|
||||
c = uv >> biRadixBits
|
||||
}
|
||||
result.digits[1+n] = c
|
||||
return result
|
||||
}
|
||||
|
||||
// ArrayCopy copies array elements
|
||||
func ArrayCopy(src []int, srcStart int, dest []int, destStart int, n int) {
|
||||
m := min(srcStart+n, len(src))
|
||||
for i, j := srcStart, destStart; i < m; i, j = i+1, j+1 {
|
||||
dest[j] = src[i]
|
||||
}
|
||||
}
|
||||
|
||||
// BiShiftLeft shifts BigInt left by n bits
|
||||
func BiShiftLeft(x *BigInt, n int) *BigInt {
|
||||
digitCount := n / bitsPerDigit
|
||||
result := NewBigInt()
|
||||
ArrayCopy(x.digits, 0, result.digits, digitCount, len(result.digits)-digitCount)
|
||||
|
||||
bits := n % bitsPerDigit
|
||||
rightBits := bitsPerDigit - bits
|
||||
|
||||
for i, i1 := len(result.digits)-1, len(result.digits)-2; i > 0; i, i1 = i-1, i1-1 {
|
||||
result.digits[i] = ((result.digits[i] << bits) & maxDigitVal) |
|
||||
((result.digits[i1] & highBitMasks[bits]) >> rightBits)
|
||||
}
|
||||
result.digits[0] = ((result.digits[0] << bits) & maxDigitVal)
|
||||
result.isNeg = x.isNeg
|
||||
return result
|
||||
}
|
||||
|
||||
// BiShiftRight shifts BigInt right by n bits
|
||||
func BiShiftRight(x *BigInt, n int) *BigInt {
|
||||
digitCount := n / bitsPerDigit
|
||||
result := NewBigInt()
|
||||
ArrayCopy(x.digits, digitCount, result.digits, 0, len(x.digits)-digitCount)
|
||||
|
||||
bits := n % bitsPerDigit
|
||||
leftBits := bitsPerDigit - bits
|
||||
|
||||
for i, i1 := 0, 1; i < len(result.digits)-1; i, i1 = i+1, i1+1 {
|
||||
result.digits[i] = (result.digits[i] >> bits) |
|
||||
((result.digits[i1] & lowBitMasks[bits]) << leftBits)
|
||||
}
|
||||
result.digits[len(result.digits)-1] >>= bits
|
||||
result.isNeg = x.isNeg
|
||||
return result
|
||||
}
|
||||
|
||||
// BiMultiplyByRadixPower multiplies BigInt by radix^n
|
||||
func BiMultiplyByRadixPower(x *BigInt, n int) *BigInt {
|
||||
result := NewBigInt()
|
||||
ArrayCopy(x.digits, 0, result.digits, n, len(result.digits)-n)
|
||||
return result
|
||||
}
|
||||
|
||||
// BiDivideByRadixPower divides BigInt by radix^n
|
||||
func BiDivideByRadixPower(x *BigInt, n int) *BigInt {
|
||||
result := NewBigInt()
|
||||
ArrayCopy(x.digits, n, result.digits, 0, len(result.digits)-n)
|
||||
return result
|
||||
}
|
||||
|
||||
// BiModuloByRadixPower computes BigInt mod radix^n
|
||||
func BiModuloByRadixPower(x *BigInt, n int) *BigInt {
|
||||
result := NewBigInt()
|
||||
ArrayCopy(x.digits, 0, result.digits, 0, n)
|
||||
return result
|
||||
}
|
||||
|
||||
// BiCompare compares two BigInts
|
||||
func BiCompare(x, y *BigInt) int {
|
||||
if x.isNeg != y.isNeg {
|
||||
if x.isNeg {
|
||||
return -1
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
for i := len(x.digits) - 1; i >= 0; i-- {
|
||||
if x.digits[i] != y.digits[i] {
|
||||
if x.isNeg {
|
||||
if x.digits[i] > y.digits[i] {
|
||||
return -1
|
||||
}
|
||||
return 1
|
||||
} else {
|
||||
if x.digits[i] < y.digits[i] {
|
||||
return -1
|
||||
}
|
||||
return 1
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// BiDivideModulo divides two BigInts and returns quotient and remainder
|
||||
func BiDivideModulo(x, y *BigInt) []*BigInt {
|
||||
nb := BiNumBits(x)
|
||||
tb := BiNumBits(y)
|
||||
origYIsNeg := y.isNeg
|
||||
var q, r *BigInt
|
||||
|
||||
if nb < tb {
|
||||
if x.isNeg {
|
||||
q = BiCopy(bigOne)
|
||||
q.isNeg = !y.isNeg
|
||||
x.isNeg = false
|
||||
y.isNeg = false
|
||||
r = BiSubtract(y, x)
|
||||
x.isNeg = true
|
||||
y.isNeg = origYIsNeg
|
||||
} else {
|
||||
q = NewBigInt()
|
||||
r = BiCopy(x)
|
||||
}
|
||||
return []*BigInt{q, r}
|
||||
}
|
||||
|
||||
q = NewBigInt()
|
||||
r = x
|
||||
|
||||
t := int(math.Ceil(float64(tb)/float64(bitsPerDigit))) - 1
|
||||
lambda := 0
|
||||
for y.digits[t] < biHalfRadix {
|
||||
y = BiShiftLeft(y, 1)
|
||||
lambda++
|
||||
tb++
|
||||
t = int(math.Ceil(float64(tb)/float64(bitsPerDigit))) - 1
|
||||
}
|
||||
|
||||
r = BiShiftLeft(r, lambda)
|
||||
nb += lambda
|
||||
n := int(math.Ceil(float64(nb)/float64(bitsPerDigit))) - 1
|
||||
|
||||
b := BiMultiplyByRadixPower(y, n-t)
|
||||
for BiCompare(r, b) != -1 {
|
||||
q.digits[n-t]++
|
||||
r = BiSubtract(r, b)
|
||||
}
|
||||
|
||||
for i := n; i > t; i-- {
|
||||
ri := 0
|
||||
if i < len(r.digits) {
|
||||
ri = r.digits[i]
|
||||
}
|
||||
ri1 := 0
|
||||
if i-1 < len(r.digits) {
|
||||
ri1 = r.digits[i-1]
|
||||
}
|
||||
ri2 := 0
|
||||
if i-2 < len(r.digits) {
|
||||
ri2 = r.digits[i-2]
|
||||
}
|
||||
yt := 0
|
||||
if t < len(y.digits) {
|
||||
yt = y.digits[t]
|
||||
}
|
||||
yt1 := 0
|
||||
if t-1 < len(y.digits) {
|
||||
yt1 = y.digits[t-1]
|
||||
}
|
||||
|
||||
if ri == yt {
|
||||
q.digits[i-t-1] = maxDigitVal
|
||||
} else {
|
||||
q.digits[i-t-1] = (ri*biRadix + ri1) / yt
|
||||
}
|
||||
|
||||
c1 := q.digits[i-t-1] * ((yt * biRadix) + yt1)
|
||||
c2 := (ri * biRadixSquared) + ((ri1 * biRadix) + ri2)
|
||||
|
||||
for c1 > c2 {
|
||||
q.digits[i-t-1]--
|
||||
c1 = q.digits[i-t-1] * ((yt * biRadix) | yt1)
|
||||
c2 = (ri * biRadix * biRadix) + ((ri1 * biRadix) + ri2)
|
||||
}
|
||||
|
||||
b = BiMultiplyByRadixPower(y, i-t-1)
|
||||
r = BiSubtract(r, BiMultiplyDigit(b, q.digits[i-t-1]))
|
||||
if r.isNeg {
|
||||
r = BiAdd(r, b)
|
||||
q.digits[i-t-1]--
|
||||
}
|
||||
}
|
||||
|
||||
r = BiShiftRight(r, lambda)
|
||||
q.isNeg = x.isNeg != origYIsNeg
|
||||
|
||||
if x.isNeg {
|
||||
if origYIsNeg {
|
||||
q = BiAdd(q, bigOne)
|
||||
} else {
|
||||
q = BiSubtract(q, bigOne)
|
||||
}
|
||||
y = BiShiftRight(y, lambda)
|
||||
r = BiSubtract(y, r)
|
||||
}
|
||||
|
||||
if r.digits[0] == 0 && BiHighIndex(r) == 0 {
|
||||
r.isNeg = false
|
||||
}
|
||||
|
||||
return []*BigInt{q, r}
|
||||
}
|
||||
|
||||
// BiDivide divides two BigInts
|
||||
func BiDivide(x, y *BigInt) *BigInt {
|
||||
return BiDivideModulo(x, y)[0]
|
||||
}
|
||||
|
||||
// BiModulo computes x mod y
|
||||
func BiModulo(x, y *BigInt) *BigInt {
|
||||
return BiDivideModulo(x, y)[1]
|
||||
}
|
||||
|
||||
// BiMultiplyMod computes (x * y) mod m
|
||||
func BiMultiplyMod(x, y, m *BigInt) *BigInt {
|
||||
return BiModulo(BiMultiply(x, y), m)
|
||||
}
|
||||
|
||||
// BiPowMod computes x^y mod m
|
||||
func BiPowMod(x, y, m *BigInt) *BigInt {
|
||||
result := BiCopy(bigOne)
|
||||
a := x
|
||||
k := y
|
||||
|
||||
for {
|
||||
if (k.digits[0] & 1) != 0 {
|
||||
result = BiMultiplyMod(result, a, m)
|
||||
}
|
||||
k = BiShiftRight(k, 1)
|
||||
if k.digits[0] == 0 && BiHighIndex(k) == 0 {
|
||||
break
|
||||
}
|
||||
a = BiMultiplyMod(a, a, m)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// BarrettMu represents Barrett reduction
|
||||
type BarrettMu struct {
|
||||
modulus *BigInt
|
||||
k int
|
||||
mu *BigInt
|
||||
bkplus1 *BigInt
|
||||
}
|
||||
|
||||
// NewBarrettMu creates a new BarrettMu
|
||||
func NewBarrettMu(m *BigInt) *BarrettMu {
|
||||
bm := &BarrettMu{
|
||||
modulus: BiCopy(m),
|
||||
k: BiHighIndex(m) + 1,
|
||||
}
|
||||
|
||||
b2k := NewBigInt()
|
||||
if 2*bm.k < len(b2k.digits) {
|
||||
b2k.digits[2*bm.k] = 1
|
||||
}
|
||||
bm.mu = BiDivide(b2k, bm.modulus)
|
||||
|
||||
bm.bkplus1 = NewBigInt()
|
||||
if bm.k+1 < len(bm.bkplus1.digits) {
|
||||
bm.bkplus1.digits[bm.k+1] = 1
|
||||
}
|
||||
|
||||
return bm
|
||||
}
|
||||
|
||||
// Modulo performs Barrett modulo
|
||||
func (bm *BarrettMu) Modulo(x *BigInt) *BigInt {
|
||||
q1 := BiDivideByRadixPower(x, bm.k-1)
|
||||
q2 := BiMultiply(q1, bm.mu)
|
||||
q3 := BiDivideByRadixPower(q2, bm.k+1)
|
||||
r1 := BiModuloByRadixPower(x, bm.k+1)
|
||||
r2term := BiMultiply(q3, bm.modulus)
|
||||
r2 := BiModuloByRadixPower(r2term, bm.k+1)
|
||||
r := BiSubtract(r1, r2)
|
||||
|
||||
if r.isNeg {
|
||||
r = BiAdd(r, bm.bkplus1)
|
||||
}
|
||||
|
||||
for BiCompare(r, bm.modulus) >= 0 {
|
||||
r = BiSubtract(r, bm.modulus)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// MultiplyMod performs modular multiplication
|
||||
func (bm *BarrettMu) MultiplyMod(x, y *BigInt) *BigInt {
|
||||
xy := BiMultiply(x, y)
|
||||
return bm.Modulo(xy)
|
||||
}
|
||||
|
||||
// PowMod performs modular exponentiation
|
||||
func (bm *BarrettMu) PowMod(x, y *BigInt) *BigInt {
|
||||
result := NewBigInt()
|
||||
result.digits[0] = 1
|
||||
a := x
|
||||
k := y
|
||||
|
||||
for {
|
||||
if (k.digits[0] & 1) != 0 {
|
||||
result = bm.MultiplyMod(result, a)
|
||||
}
|
||||
k = BiShiftRight(k, 1)
|
||||
if k.digits[0] == 0 && BiHighIndex(k) == 0 {
|
||||
break
|
||||
}
|
||||
a = bm.MultiplyMod(a, a)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// NutRSAKeyPair represents an RSA key pair
|
||||
type NutRSAKeyPair struct {
|
||||
e *BigInt
|
||||
d *BigInt
|
||||
m *BigInt
|
||||
chunkSize int
|
||||
radix int
|
||||
barrett *BarrettMu
|
||||
}
|
||||
|
||||
// NewNutRSAKeyPair creates a new RSA key pair
|
||||
func NewNutRSAKeyPair(encryptionExponent, decryptionExponent, modulus string) *NutRSAKeyPair {
|
||||
kp := &NutRSAKeyPair{
|
||||
e: BiFromHex(encryptionExponent),
|
||||
d: BiFromHex(decryptionExponent),
|
||||
m: BiFromHex(modulus),
|
||||
radix: 16,
|
||||
}
|
||||
kp.chunkSize = 2 * BiHighIndex(kp.m)
|
||||
kp.barrett = NewBarrettMu(kp.m)
|
||||
return kp
|
||||
}
|
||||
|
||||
// EncryptedString encrypts a string
|
||||
func (kp *NutRSAKeyPair) EncryptedString(s string) string {
|
||||
a := make([]int, 0)
|
||||
for i := 0; i < len(s); i++ {
|
||||
a = append(a, int(s[i]))
|
||||
}
|
||||
|
||||
// Padding
|
||||
for len(a)%kp.chunkSize != 0 {
|
||||
a = append(a, 0)
|
||||
}
|
||||
|
||||
result := ""
|
||||
for i := 0; i < len(a); i += kp.chunkSize {
|
||||
block := NewBigInt()
|
||||
j := 0
|
||||
for k := i; k < i+kp.chunkSize; j++ {
|
||||
if k < len(a) {
|
||||
block.digits[j] = a[k]
|
||||
k++
|
||||
}
|
||||
if k < len(a) {
|
||||
block.digits[j] += a[k] << 8
|
||||
k++
|
||||
}
|
||||
}
|
||||
crypt := kp.barrett.PowMod(block, kp.e)
|
||||
var text string
|
||||
if kp.radix == 16 {
|
||||
text = BiToHex(crypt)
|
||||
} else {
|
||||
text = BiToString(crypt, kp.radix)
|
||||
}
|
||||
result += text + " "
|
||||
}
|
||||
|
||||
if len(result) > 0 {
|
||||
return result[:len(result)-1]
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// DecryptedString decrypts a string
|
||||
func (kp *NutRSAKeyPair) DecryptedString(s string) string {
|
||||
blocks := strings.Split(s, " ")
|
||||
result := ""
|
||||
|
||||
for i := 0; i < len(blocks); i++ {
|
||||
var bi *BigInt
|
||||
if kp.radix == 16 {
|
||||
bi = BiFromHex(blocks[i])
|
||||
} else {
|
||||
bi = BiFromString(blocks[i], kp.radix)
|
||||
}
|
||||
block := kp.barrett.PowMod(bi, kp.d)
|
||||
|
||||
for j := 0; j <= BiHighIndex(block); j++ {
|
||||
result += string(rune(block.digits[j] & 255))
|
||||
result += string(rune(block.digits[j] >> 8))
|
||||
}
|
||||
}
|
||||
|
||||
// Remove trailing null
|
||||
if len(result) > 0 && result[len(result)-1] == 0 {
|
||||
result = result[:len(result)-1]
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Helper functions
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func max(a, b int) int {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func parseNumber(s string) int64 {
|
||||
var result int64
|
||||
fmt.Sscanf(s, "%d", &result)
|
||||
return result
|
||||
}
|
||||
|
||||
func init() {
|
||||
SetMaxDigits(130)
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
package leave
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/application/cpdaily"
|
||||
"likedream-goframe/internal/application/cpdaily/cryptoutil"
|
||||
"likedream-goframe/internal/application/cpdaily/task/leavetype"
|
||||
"likedream-goframe/internal/application/cpdaily/taskhelper"
|
||||
"likedream-goframe/internal/common/errors"
|
||||
"likedream-goframe/internal/utils"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/google/uuid"
|
||||
"github.com/samber/oops"
|
||||
"github.com/tidwall/gjson"
|
||||
"resty.dev/v3"
|
||||
)
|
||||
|
||||
/**
|
||||
* @Description: 销假相关功能
|
||||
*/
|
||||
type CpdailyReportApp struct {
|
||||
client *resty.Client
|
||||
host string
|
||||
}
|
||||
|
||||
func NewCpdailyReportApp(client *resty.Client, host string) *CpdailyReportApp {
|
||||
|
||||
return &CpdailyReportApp{
|
||||
client: client,
|
||||
host: host,
|
||||
}
|
||||
}
|
||||
|
||||
// 获取请假记录
|
||||
func (c *CpdailyReportApp) GetLeaveList() []leavetype.LeaveListOne {
|
||||
// https://fzfu.campusphere.net/wec-counselor-leave-apps/leave/stu/listOther
|
||||
post, err := c.client.R().SetBody(map[string]int{
|
||||
"pageNumber": 1,
|
||||
"pageSize": 20,
|
||||
"needApproval": 1,
|
||||
}).Post(fmt.Sprintf("%s/wec-counselor-leave-apps/leave/stu/listOther", c.host))
|
||||
|
||||
utils.OkOrPanic(err, func(err error) error {
|
||||
return oops.
|
||||
With("host", c.host).
|
||||
In("CpdailyReport.GetLeaveList").
|
||||
Wrap(err)
|
||||
})
|
||||
responseJSON := utils.ReadGjsonResult(post.Body)
|
||||
rows := responseJSON.Get("datas.rows")
|
||||
|
||||
if !rows.Exists() {
|
||||
utils.OkOrPanic(errors.NewBusinessError(503, "没有获取到待销假信息"), func(err error) error {
|
||||
return oops.
|
||||
With("host", c.host).
|
||||
In("CpdailyReport.GetLeaveList").
|
||||
Wrap(err)
|
||||
})
|
||||
}
|
||||
|
||||
var listList []leavetype.LeaveListOne
|
||||
for _, row := range rows.Array() {
|
||||
// 已完成
|
||||
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("leaveReason").String(),
|
||||
AceEndTime: row.Get("actEndTime").String(),
|
||||
Status: row.Get("status").String(),
|
||||
}
|
||||
listList = append(listList, leaveOne)
|
||||
}
|
||||
return listList
|
||||
}
|
||||
|
||||
func (c *CpdailyReportApp) LeaveDetail(leaveId string) gjson.Result {
|
||||
// https://fzfu.campusphere.net/wec-counselor-leave-apps/leave/stu/detailOther
|
||||
post, err := c.client.R().SetBody(map[string]any{
|
||||
"id": leaveId,
|
||||
"needApproval": 1,
|
||||
"uaIsCpadaily": "true",
|
||||
}).Post(fmt.Sprintf("%s/wec-counselor-leave-apps/leave/stu/detailOther", c.host))
|
||||
utils.OkOrPanic(err, func(err error) error {
|
||||
return oops.
|
||||
With("host", c.host).
|
||||
In("CpdailyReport.LeaveDetail").
|
||||
Wrap(err)
|
||||
})
|
||||
datas := utils.ReadGjsonResult(post.Body).Get("datas")
|
||||
if !datas.Exists() {
|
||||
utils.OkOrPanic(errors.NewBusinessError(503, "没有获取到待销假详情信息"), func(err error) error {
|
||||
return oops.
|
||||
With("host", c.host).
|
||||
In("CpdailyReport.LeaveDetail").
|
||||
Wrap(err)
|
||||
})
|
||||
}
|
||||
return datas
|
||||
}
|
||||
|
||||
func (c *CpdailyReportApp) FillReportForm(detail gjson.Result) map[string]*gvar.Var {
|
||||
resultForm := make(map[string]*gvar.Var)
|
||||
resultForm["id"] = gvar.New(detail.Get("detail.id").String())
|
||||
resultForm["needApproval"] = gvar.New(1)
|
||||
resultForm["leaveType"] = gvar.New(detail.Get("leaveType.code").Int())
|
||||
resultForm["reportLocation"] = gvar.New(detail.Get("detail.applyLocation.address").String())
|
||||
resultForm["approverWid"] = gvar.New("")
|
||||
resultForm["reportApplyExplain"] = gvar.New(nil)
|
||||
resultForm["reportAttach"] = gvar.New(detail.Get("detail.applyAttach").Array())
|
||||
resultForm["uaIsCpadaily"] = gvar.New(true)
|
||||
return resultForm
|
||||
}
|
||||
|
||||
func (c *CpdailyReportApp) GetLocation(detail gjson.Result) (lon, lat string) {
|
||||
applyLocation := detail.Get("detail.applyLocation")
|
||||
lon = applyLocation.Get("longitude").String()
|
||||
lat = applyLocation.Get("latitude").String()
|
||||
return
|
||||
}
|
||||
func (c *CpdailyReportApp) SubmitReport(ctx context.Context, form map[string]*gvar.Var, lon, lat, username, deviceId string) {
|
||||
cpdailyInfo := cpdaily.GetInfo(ctx)
|
||||
|
||||
extensionForm := map[string]*gvar.Var{
|
||||
"lon": gvar.New(lon),
|
||||
"lat": gvar.New(lat),
|
||||
"model": gvar.New(uuid.New().String()),
|
||||
"appVersion": gvar.New(cpdailyInfo.AppVersion),
|
||||
"systemVersion": gvar.New(cpdailyInfo.SystemVersion),
|
||||
"userId": gvar.New(username),
|
||||
"systemName": gvar.New("android"),
|
||||
"deviceId": gvar.New(deviceId),
|
||||
}
|
||||
|
||||
extensionString := taskhelper.GetCpdailyExtension(ctx, extensionForm)
|
||||
bodyString := taskhelper.GetBodyString(ctx, form)
|
||||
// 构造提交数据
|
||||
submitData := map[string]*gvar.Var{
|
||||
"lon": gvar.New(lon),
|
||||
"version": gvar.New(cryptoutil.EncryptVersion),
|
||||
"calVersion": gvar.New(cpdailyInfo.CalVersion),
|
||||
"deviceId": extensionForm["deviceId"],
|
||||
//"userId": gvar.New(username),
|
||||
"systemName": gvar.New("android"),
|
||||
"bodyString": gvar.New(bodyString),
|
||||
"lat": gvar.New(lat),
|
||||
"systemVersion": gvar.New(cpdailyInfo.SystemVersion),
|
||||
"appVersion": gvar.New(cpdailyInfo.AppVersion),
|
||||
"model": extensionForm["model"],
|
||||
}
|
||||
// https://fzfu.campusphere.net/wec-counselor-leave-apps/leave/report
|
||||
response, e := c.client.R().
|
||||
SetBody(submitData).
|
||||
WithContext(ctx).
|
||||
SetHeader("Cpdaily-Extension", extensionString).
|
||||
Post(fmt.Sprintf("%s/wec-counselor-leave-apps/leave/report", c.host))
|
||||
|
||||
utils.OkOrPanic(e, func(err error) error {
|
||||
return oops.
|
||||
With("host", c.host).
|
||||
With("username", username).
|
||||
With("deviceId", deviceId).
|
||||
In("CpdailySleepCheckTask.Submit").
|
||||
Wrap(err)
|
||||
})
|
||||
|
||||
responseJSON := utils.ReadGjsonResult(response.Body)
|
||||
|
||||
if responseJSON.Get("code").String() != "0" {
|
||||
utils.OkOrPanic(errors.NewBusinessError(503, responseJSON.Get("message").String()), oops.WithContext(ctx).Wrap)
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,15 @@ func GetCpdailyLoginBySchoolInfo(ctx context.Context, info *school.SchoolDetailI
|
||||
// 安徽建筑大学
|
||||
case "ahjzu":
|
||||
return NewAhjzu(ctx)
|
||||
// 南宁师范大学
|
||||
case "2ba0ea59-a764-4482-bb2b-c924b726b04c":
|
||||
return NewNnnu(ctx)
|
||||
// 长春大学
|
||||
case "ccu":
|
||||
fallthrough
|
||||
// 河北石油职业技术大学
|
||||
case "01e270d1-00e2-4ce9-b0af-5d5fbd462b8a":
|
||||
return NewIap(ctx)
|
||||
default:
|
||||
if info.IsIap() {
|
||||
return NewIap(ctx)
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/avast/retry-go/v4"
|
||||
"github.com/deatil/go-cryptobin/cryptobin/crypto"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/samber/oops"
|
||||
"github.com/tidwall/gjson"
|
||||
"resty.dev/v3"
|
||||
@@ -192,7 +193,8 @@ func (c *CpdailyCasLogin) Login(ctx context.Context, schoolDetail *school.School
|
||||
}
|
||||
|
||||
// 声明需要滑块验证码的学校id
|
||||
var SliderCaptchaIds = []string{"1018764144934965", "sdhyxy"}
|
||||
var SliderCaptchaIds = g.Cfg().MustGet(ctx, cst.ConfigSliderSchoolIds).Strings()
|
||||
// []string{"1018764144934965", "sdhyxy", "hqdx"}
|
||||
// 判断是否需要验证码
|
||||
if isCasNeedCaptcha(ctx, loginResponseUrl, loginType, username, c.client) {
|
||||
// 如果是滑块验证码
|
||||
@@ -389,6 +391,10 @@ func handleCasLoginSuccess(ctx context.Context, response *resty.Response, school
|
||||
utils.OkOrPanic(errors.NewBusinessError(201, "多因子验证码认证").WithData(key))
|
||||
// 否则应该是登录成功
|
||||
} else if statusCode == 200 || statusCode == 404 {
|
||||
all, _ := io.ReadAll(verifyResponse.Body)
|
||||
if strings.Contains(string(all), "完善资料") || strings.Contains(string(all), "为了你的帐号安全") {
|
||||
utils.OkOrPanic(errors.NewBusinessError(503, "请手动学工号登录完善信息,修改密码").WithData(schoolInfo.WecloudUrl))
|
||||
}
|
||||
ActivateSession(ctx, schoolInfo.WecloudUrl, client)
|
||||
} else {
|
||||
utils.OkOrPanic(errors.NewBusinessError(503, "未知错误导致今日校园登录失败"),
|
||||
@@ -450,6 +456,12 @@ func submitCasKickOut(ctx context.Context, requestUrl string, doc *goquery.Docum
|
||||
}
|
||||
|
||||
func getCasValidLoginUrl(info *school.SchoolDetailInfo) string {
|
||||
// 特殊学校单独处理
|
||||
// 甘肃农业大学 西安体育学院
|
||||
ids := []string{"gsau", "ddf0639d-394d-48a2-a166-07ed84b7e6f0"}
|
||||
if slices.Contains(ids, info.Id) {
|
||||
return info.IdsUrl
|
||||
}
|
||||
if strings.Contains(info.AmpUrl, "campusphere") || strings.Contains(info.AmpUrl, "wec-portal-mobile") {
|
||||
return info.AmpUrl
|
||||
} else if strings.Contains(info.AmpUrl2, "campusphere") || strings.Contains(info.AmpUrl2, "wec-portal-mobile") {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -14,6 +15,11 @@ import (
|
||||
)
|
||||
|
||||
func ActivateSession(ctx context.Context, host string, client *resty.Client) {
|
||||
// 处理cookie,干掉path
|
||||
jar := client.CookieJar()
|
||||
realJar := jar.(*cookiejar.PersistCookieJar)
|
||||
realJar.RemoveCookieInfo()
|
||||
client.SetCookieJar(realJar)
|
||||
client.SetRedirectPolicy(resty.FlexibleRedirectPolicy(20))
|
||||
|
||||
host = strings.TrimSuffix(host, "/")
|
||||
@@ -27,7 +33,7 @@ func ActivateSession(ctx context.Context, host string, client *resty.Client) {
|
||||
|
||||
defer sessionResponse.Body.Close()
|
||||
|
||||
if !sessionResponse.IsSuccess() {
|
||||
if !sessionResponse.IsSuccess() && sessionResponse.StatusCode() != 502 {
|
||||
utils.OkOrPanic(errors.NewBusinessError(503, "Session激活失败"),
|
||||
func(err error) error {
|
||||
return oops.
|
||||
@@ -81,11 +87,8 @@ 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 {
|
||||
client.SetRedirectPolicy(resty.FlexibleRedirectPolicy(20))
|
||||
defer func() {
|
||||
client.SetRedirectPolicy(resty.NoRedirectPolicy())
|
||||
}()
|
||||
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().
|
||||
WithContext(ctx).
|
||||
@@ -93,13 +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)
|
||||
defer sessionResponse.Body.Close()
|
||||
|
||||
if !sessionResponse.IsSuccess() {
|
||||
return sessionResponse.StatusCode() == 405
|
||||
needLogin := sessionResponse.StatusCode() == 302
|
||||
if needLogin && loginType == cpuser.LoginTypePhone {
|
||||
utils.OkOrPanic(errors.NewBusinessError(500, "登录信息失效,请重新通过短信验证码登录"))
|
||||
}
|
||||
responseContentType := sessionResponse.Header().Get("Content-Type")
|
||||
return strings.Contains(responseContentType, "json")
|
||||
return !needLogin
|
||||
}
|
||||
|
||||
func GetClient(ctx context.Context, cookie string) *resty.Client {
|
||||
|
||||
@@ -45,16 +45,17 @@ func (c *CpdailyIapLogin) Login(ctx context.Context, schoolDetail *school.School
|
||||
preLoginUrl := loginUrl + "/portal/login"
|
||||
c.client.SetRedirectPolicy(resty.FlexibleRedirectPolicy(20))
|
||||
loginRedirectResponse, err := c.client.R().Get(preLoginUrl)
|
||||
utils.OkOrPanic(err, func(err error) error {
|
||||
return oops.
|
||||
In("CpdailyIapLogin.Login").
|
||||
With("schoolDetail", schoolDetail).
|
||||
With("username", username).
|
||||
With("password", password).
|
||||
Wrap(err)
|
||||
})
|
||||
u := loginRedirectResponse.RawResponse.Request.URL
|
||||
oldLt := strings.Split(u.String(), "=")[1]
|
||||
oldLt := ""
|
||||
// 部分学校无法直接访问登录页
|
||||
if err == nil {
|
||||
u := loginRedirectResponse.RawResponse.Request.URL
|
||||
oldLt = strings.Split(u.String(), "=")[1]
|
||||
c.client.SetRedirectPolicy(resty.NoRedirectPolicy())
|
||||
} else {
|
||||
preLoginUrl = loginUrl + "/iap/login/mobile.html"
|
||||
c.client.SetRedirectPolicy(resty.FlexibleRedirectPolicy(20))
|
||||
loginRedirectResponse, err = c.client.R().Get(preLoginUrl)
|
||||
}
|
||||
c.client.SetRedirectPolicy(resty.NoRedirectPolicy())
|
||||
ltInfoResponse, err := c.client.R().
|
||||
WithContext(ctx).
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
package login
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"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/errors"
|
||||
"likedream-goframe/internal/utils"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/samber/oops"
|
||||
"resty.dev/v3"
|
||||
)
|
||||
|
||||
// 南宁师范大学登录实现
|
||||
type CpdailyNnnuLogin struct {
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
func (c CpdailyNnnuLogin) Login(ctx context.Context, schoolDetail *school.SchoolDetailInfo, username, password string) {
|
||||
jar := cookiejar.NewPersistCookieJar()
|
||||
|
||||
c.client.SetCookieJar(jar).SetRedirectPolicy(resty.FlexibleRedirectPolicy(20))
|
||||
|
||||
// 获取合法的登录URL
|
||||
loginUrl := getCasValidLoginUrl(schoolDetail)
|
||||
|
||||
// 请求登录页面并获取真正的登录URL
|
||||
loginPageResponse, err := c.client.R().
|
||||
WithContext(ctx).
|
||||
Get(loginUrl)
|
||||
|
||||
defer loginPageResponse.Body.Close()
|
||||
loginPageBytes, err := io.ReadAll(loginPageResponse.Body)
|
||||
utils.OkOrPanic(err)
|
||||
loginResponseUrl := loginPageResponse.RawResponse.Request.URL
|
||||
// 关闭client的重定向
|
||||
c.client.SetRedirectPolicy(resty.NoRedirectPolicy())
|
||||
// 解析登录页面
|
||||
loginPage, err := goquery.NewDocumentFromReader(bytes.NewReader(loginPageBytes))
|
||||
utils.OkOrPanic(err)
|
||||
// 判断登录类型
|
||||
var (
|
||||
allInputs = map[string]string{}
|
||||
form = loginPage.Find("form").First()
|
||||
)
|
||||
inputs := form.Find("input")
|
||||
|
||||
for _, input := range inputs.EachIter() {
|
||||
name, exists := input.Attr("name")
|
||||
if !exists {
|
||||
continue
|
||||
}
|
||||
value, _ := input.Attr("value")
|
||||
allInputs[name] = value
|
||||
}
|
||||
|
||||
allInputs["username"] = username
|
||||
|
||||
// 处理密码
|
||||
allInputs["password"] = cryptoutil.MD5(password)
|
||||
|
||||
// 解决常规图片验证码
|
||||
captchaUrl := getAhjzuCaptchaUrl(loginResponseUrl)
|
||||
captchaResult := ResolveOcrCaptcha(ctx, captchaUrl, c.client)
|
||||
|
||||
allInputs["validateCode"] = captchaResult
|
||||
|
||||
// 登录提交
|
||||
loginPostResponse, err := c.client.R().
|
||||
SetFormData(allInputs).
|
||||
WithContext(ctx).
|
||||
Post(loginResponseUrl.String())
|
||||
|
||||
utils.OkOrPanic(err, func(err error) error {
|
||||
return oops.
|
||||
WithContext(ctx).
|
||||
With("loginResponseUrl", loginResponseUrl).
|
||||
With("allInputs", allInputs).
|
||||
Wrap(err)
|
||||
})
|
||||
|
||||
defer loginPostResponse.Body.Close()
|
||||
|
||||
switch loginPostResponse.StatusCode() {
|
||||
case 302:
|
||||
handleCasLoginSuccess(ctx, loginPostResponse, schoolDetail, username, password, c.client)
|
||||
case 200:
|
||||
fallthrough
|
||||
case 401:
|
||||
doc, err := goquery.NewDocumentFromReader(loginPostResponse.Body)
|
||||
utils.OkOrPanic(err, func(err error) error {
|
||||
return oops.
|
||||
WithContext(ctx).
|
||||
With("loginResponseUrl", loginResponseUrl).
|
||||
With("allInputs", allInputs).
|
||||
Wrap(err)
|
||||
})
|
||||
|
||||
if isCasNeedKickOut(doc) {
|
||||
kickoutResponse := submitCasKickOut(ctx, loginResponseUrl.String(), doc, c.client)
|
||||
handleCasLoginSuccess(ctx, kickoutResponse, schoolDetail, username, password, c.client)
|
||||
return
|
||||
}
|
||||
|
||||
message := getCasErrorMessage(doc)
|
||||
|
||||
utils.OkOrPanic(errors.NewBusinessError(503, fmt.Sprintf("今日校园登录失败: %s", message)), func(err error) error {
|
||||
return oops.
|
||||
WithContext(ctx).
|
||||
With("loginResponseUrl", loginResponseUrl).
|
||||
With("allInputs", allInputs).
|
||||
With("errorMessage", message).
|
||||
Wrap(errors.NewBusinessError(503, message))
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func getNuuuCaptchaUrl(url *url.URL) string {
|
||||
return fmt.Sprintf("%s://%s/sso/code/code.jsp", url.Scheme, url.Host)
|
||||
}
|
||||
|
||||
func (c CpdailyNnnuLogin) GetCookieJar() http.CookieJar {
|
||||
return c.client.CookieJar()
|
||||
}
|
||||
|
||||
func (c CpdailyNnnuLogin) GetCookieString() string {
|
||||
cookieJar := c.GetCookieJar()
|
||||
serializableJar := cookieJar.(*cookiejar.PersistCookieJar)
|
||||
return serializableJar.Serialize()
|
||||
}
|
||||
|
||||
func (c CpdailyNnnuLogin) GetClient() *resty.Client {
|
||||
return c.client
|
||||
}
|
||||
|
||||
func NewNnnu(ctx context.Context) CpdailyLogin {
|
||||
return &CpdailyNnnuLogin{
|
||||
client: httpclient.NewCpdailyClient(),
|
||||
}
|
||||
}
|
||||
@@ -81,10 +81,8 @@ func (c CpdailyNutLogin) Login(ctx context.Context, schoolDetail *school.SchoolD
|
||||
pubKeyBytes, err := io.ReadAll(pubKeyResponse.Body)
|
||||
utils.OkOrPanic(err)
|
||||
sonic.Unmarshal(pubKeyBytes, &pubKey)
|
||||
pair, err := cryptoutil.NewRSAKeyPair(pubKey.Exponent, "", pubKey.Modulus)
|
||||
utils.OkOrPanic(err)
|
||||
password, err = pair.Encrypt(reverseStringASCII(password))
|
||||
utils.OkOrPanic(err)
|
||||
rsa := cryptoutil.NewNutRSAKeyPair(pubKey.Exponent, "", pubKey.Modulus)
|
||||
password = rsa.EncryptedString(reverseStringASCII(password))
|
||||
allInputs["password"] = password
|
||||
if isNutNeedCaptcha(ctx, loginResponseUrl, c.client) {
|
||||
// 解决常规图片验证码
|
||||
|
||||
@@ -1,56 +1,18 @@
|
||||
package login
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"image"
|
||||
"io"
|
||||
"likedream-goframe/internal/application/httpclient"
|
||||
"likedream-goframe/internal/common/cst"
|
||||
"likedream-goframe/internal/application/captcha"
|
||||
"likedream-goframe/internal/utils"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/samber/oops"
|
||||
"github.com/tidwall/gjson"
|
||||
"resty.dev/v3"
|
||||
)
|
||||
|
||||
func ResolveOcrCaptcha(ctx context.Context, url string, client *resty.Client) string {
|
||||
byteData := DownCode2Byte(ctx, url, client)
|
||||
//img, err := BytesToImage(byteData)
|
||||
//utils.OkOrPanic(err, func(err error) error {
|
||||
// return oops.
|
||||
// With("BytesToImage", url).
|
||||
// WithContext(ctx).
|
||||
// Wrap(err)
|
||||
//})
|
||||
//data := ddddocr.AutoOCRVerification(img)
|
||||
//return data
|
||||
return ApiAutoOCRVerification(Bytes2Base64(byteData))
|
||||
}
|
||||
|
||||
func Bytes2Base64(data []byte) string {
|
||||
return base64.StdEncoding.EncodeToString(data)
|
||||
}
|
||||
|
||||
func ApiAutoOCRVerification(data string) string {
|
||||
ctx := gctx.GetInitCtx()
|
||||
baseUrl := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaBaseUrl).String() + "/ocr"
|
||||
client := httpclient.Cpdaily.Clone(ctx)
|
||||
client.SetDoNotParseResponse(false)
|
||||
post, err := client.R().SetBody(map[string]any{
|
||||
"base64": data,
|
||||
}).Post(baseUrl)
|
||||
utils.OkOrPanic(err, func(err error) error {
|
||||
return oops.
|
||||
With("AutoOCRVerification", baseUrl).
|
||||
WithContext(ctx).
|
||||
Wrap(err)
|
||||
})
|
||||
result := post.String()
|
||||
return gjson.Get(result, "data").String()
|
||||
return captcha.ApiAutoOCRVerification(byteData)
|
||||
}
|
||||
|
||||
func DownCode2Byte(ctx context.Context, url string, client *resty.Client) []byte {
|
||||
@@ -73,12 +35,3 @@ func DownCode2Byte(ctx context.Context, url string, client *resty.Client) []byte
|
||||
})
|
||||
return all
|
||||
}
|
||||
|
||||
// 通用解码函数,自动检测格式
|
||||
func BytesToImage(imgBytes []byte) (image.Image, error) {
|
||||
img, _, err := image.Decode(bytes.NewReader(imgBytes))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return img, nil
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package map_info
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/application/httpclient"
|
||||
"likedream-goframe/internal/common/errors"
|
||||
"likedream-goframe/internal/utils"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/samber/oops"
|
||||
)
|
||||
|
||||
func SearchAddressLongitudeAndLatitude(ctx context.Context, address string) []MapPoi {
|
||||
client := httpclient.Cpdaily.Clone(ctx).SetDoNotParseResponse(false)
|
||||
// 首先访问获取ak
|
||||
response, err := client.R().Get("https://lbsyun.baidu.com/jsdemo/demo/webgl0_5.htm")
|
||||
utils.OkOrPanic(err, func(err error) error {
|
||||
return oops.WithContext(ctx).With("url", "https://lbsyun.baidu.com/jsdemo/demo/webgl0_5.htm").In("SearchAddressLongitudeAndLatitude.GetAk").Wrap(err)
|
||||
})
|
||||
ak := ParseAkString(response.String())
|
||||
timestamp := fmt.Sprintf("%d", time.Now().UnixMilli())
|
||||
mapResponse, err := client.R().
|
||||
SetQueryParams(map[string]string{
|
||||
"qt": "placesug",
|
||||
"query": address,
|
||||
"callback": "BMapGL._rd._cbk25241",
|
||||
"region": "131",
|
||||
"city_limit": "false",
|
||||
"t": timestamp,
|
||||
"from": "jsapi",
|
||||
"ak": ak,
|
||||
"v": "gl",
|
||||
"timeStamp": timestamp,
|
||||
}).
|
||||
SetHeaders(map[string]string{
|
||||
"Accept": "*/*",
|
||||
"Accept-Language": "zh-CN,zh;q=0.9",
|
||||
"Connection": "keep-alive",
|
||||
"Referer": "https://lbsyun.baidu.com/",
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36",
|
||||
}).
|
||||
Get("https://api.map.baidu.com/")
|
||||
utils.OkOrPanic(err, func(err error) error {
|
||||
return oops.WithContext(ctx).With("address", address).In("SearchAddressLongitudeAndLatitude.QueryMap").Wrap(err)
|
||||
})
|
||||
|
||||
// 从JSONP响应中提取JSON数据
|
||||
str := ParseJsonpToJson(mapResponse.String())
|
||||
var jsonData MapJSONData
|
||||
sonic.Unmarshal([]byte(str), &jsonData)
|
||||
return jsonData.Result.PoiList
|
||||
}
|
||||
|
||||
// 正则提取ak // <script type="text/javascript" src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=E4805d16520de693a3fe707cdc962045"></script>
|
||||
func ParseAkString(data string) string {
|
||||
reg := regexp.MustCompile(`ak=([^"]+)`)
|
||||
matches := reg.FindStringSubmatch(data)
|
||||
if len(matches) < 2 {
|
||||
utils.OkOrPanic(errors.NewBusinessError(500, "获取ak出错"))
|
||||
}
|
||||
return matches[1]
|
||||
}
|
||||
|
||||
// 从JSONP响应中提取JSON数据
|
||||
// 输入: /**/BMapGL._rd._cbk25241 && BMapGL._rd._cbk25241({...})
|
||||
// 输出: {...}
|
||||
func ParseJsonpToJson(jsonpData string) string {
|
||||
// 匹配 callback(json) 格式,提取括号中的内容
|
||||
reg := regexp.MustCompile(`\((\{.*\})\)`)
|
||||
matches := reg.FindStringSubmatch(jsonpData)
|
||||
if len(matches) < 2 {
|
||||
utils.OkOrPanic(errors.NewBusinessError(500, "解析JSONP数据出错"))
|
||||
}
|
||||
return matches[1]
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package map_info
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
)
|
||||
|
||||
func TestMapSearch(t *testing.T) {
|
||||
res := SearchAddressLongitudeAndLatitude(gctx.New(), "河北石油职业技术大学c座")
|
||||
marshal, _ := json.Marshal(res)
|
||||
t.Log(string(marshal))
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package map_info
|
||||
|
||||
type MapJSONData struct {
|
||||
Status int `json:"status"`
|
||||
Message string `json:"message"`
|
||||
Result MapResult `json:"result"`
|
||||
}
|
||||
type MapLocation struct {
|
||||
Lat float64 `json:"lat"`
|
||||
Lng float64 `json:"lng"`
|
||||
}
|
||||
type MapPoi struct {
|
||||
Name string `json:"name"`
|
||||
Location MapLocation `json:"location"`
|
||||
UID string `json:"uid"`
|
||||
Province string `json:"province"`
|
||||
City string `json:"city"`
|
||||
District string `json:"district"`
|
||||
Business string `json:"business"`
|
||||
Cityid string `json:"cityid"`
|
||||
Tag string `json:"tag"`
|
||||
Address string `json:"address"`
|
||||
Children []interface{} `json:"children"`
|
||||
Adcode string `json:"adcode"`
|
||||
}
|
||||
type MapResult struct {
|
||||
Q string `json:"q"`
|
||||
PoiList []MapPoi `json:"poi_list"`
|
||||
}
|
||||
@@ -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 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,6 +106,17 @@ 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)
|
||||
return ret[0]
|
||||
if !utils.IsDebug() {
|
||||
client := redis.GetClient()
|
||||
client.Set(ctx, cst2.RedisSchoolInfo+tenantId, ret[0], time.Duration(cst2.RedisSchoolInfoExpire)*time.Second)
|
||||
}
|
||||
return parseSpecialSchool(ret[0])
|
||||
}
|
||||
|
||||
func parseSpecialSchool(s SchoolDetailInfo) SchoolDetailInfo {
|
||||
// 甘肃农业大学
|
||||
if s.Id == "gsau" {
|
||||
s.WecloudUrl = "https://fdm.gsau.edu.cn"
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -42,9 +42,7 @@ type ApiResponse struct {
|
||||
type ITStarResponse struct {
|
||||
Code json.Number `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data struct {
|
||||
SuccCode []string `json:"succCode"`
|
||||
} `json:"data"`
|
||||
Data []string `json:"data"`
|
||||
}
|
||||
|
||||
type SubmitCaptchaResolver interface {
|
||||
|
||||
@@ -145,10 +145,7 @@ func (r *NormalSubmitCaptchaResolver) getResultFromItStar(rawResponse json.RawMe
|
||||
err := sonic.Unmarshal(rawResponse, &responseMap)
|
||||
utils.OkOrPanic(err)
|
||||
|
||||
responseMap["authKey"] = "ITStarYYDS"
|
||||
|
||||
itstarUrl := strings.TrimSuffix(r.getITStarUrl(), "/")
|
||||
url := itstarUrl + "/captcha/unLimitValidate"
|
||||
url := r.getITStarUrl()
|
||||
|
||||
resp, err := r.client.R().
|
||||
SetBody(responseMap).
|
||||
@@ -161,7 +158,7 @@ func (r *NormalSubmitCaptchaResolver) getResultFromItStar(rawResponse json.RawMe
|
||||
utils.OkOrPanic(errors.NewBusinessError(503, fmt.Sprintf("验证码识别出错: %s", itstarResp.Msg)))
|
||||
}
|
||||
|
||||
return itstarResp.Data.SuccCode
|
||||
return itstarResp.Data
|
||||
}
|
||||
|
||||
// submitCaptcha 提交验证码
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
func TestRuoliSubmitCaptchaResolver_GetCaptchaTicket(t *testing.T) {
|
||||
loginClient, detail := testutil.LoginTestUser()
|
||||
|
||||
resolver := NewRuoliResolver(loginClient, detail.WecloudUrl, "abcdefg", types.TaskTypeSleepCheck)
|
||||
resolver := NewNormalResolver(loginClient, detail.WecloudUrl, "abcdefg", types.TaskTypeSleepCheck)
|
||||
|
||||
info := resolver.GetValidationInfo(context.Background())
|
||||
|
||||
|
||||
@@ -15,4 +15,5 @@ type CpTaskFormItem struct {
|
||||
Sort uint `json:"sort,omitempty"`
|
||||
CacheKey string `json:"cacheKey,omitempty"`
|
||||
Show bool `json:"show,omitempty"`
|
||||
Tip string `json:"tip,omitempty"`
|
||||
}
|
||||
|
||||
@@ -8,4 +8,5 @@ const (
|
||||
ItemTypeMulti
|
||||
ItemTypeImage
|
||||
ItemTypeAddress
|
||||
ItemTypeLatAndLon
|
||||
)
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package leavetype
|
||||
|
||||
type LeaveListOne struct {
|
||||
Id string `json:"id"`
|
||||
LeaveType string `json:"leaveType"`
|
||||
CreateTime string `json:"createTime"`
|
||||
AceEndTime string `json:"aceEndTime"`
|
||||
Reason string `json:"reason"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
@@ -359,19 +359,27 @@ func (c *CpdailyAutoSignTask) ParseFormJson(ctx context.Context, rawJson map[str
|
||||
var list []*formtype.CpTaskFormItem
|
||||
|
||||
// 经纬度
|
||||
//dto := &formtype.CpTaskFormItem{
|
||||
// Title: "经度",
|
||||
// ColName: "lon",
|
||||
// Type: formtype.ItemTypeInput,
|
||||
// Required: true,
|
||||
//}
|
||||
//list = append(list, dto)
|
||||
//
|
||||
//dto = &formtype.CpTaskFormItem{
|
||||
// Title: "纬度",
|
||||
// ColName: "lat",
|
||||
// Type: formtype.ItemTypeInput,
|
||||
// Required: true,
|
||||
//}
|
||||
//list = append(list, dto)
|
||||
dto := &formtype.CpTaskFormItem{
|
||||
Title: "经度",
|
||||
ColName: "lon",
|
||||
Type: formtype.ItemTypeInput,
|
||||
Required: true,
|
||||
}
|
||||
list = append(list, dto)
|
||||
|
||||
dto = &formtype.CpTaskFormItem{
|
||||
Title: "纬度",
|
||||
ColName: "lat",
|
||||
Type: formtype.ItemTypeInput,
|
||||
Title: "经纬度",
|
||||
ColName: "latAndLon",
|
||||
Type: formtype.ItemTypeLatAndLon,
|
||||
Required: true,
|
||||
Tip: "您可以通过地址搜索签到经纬度,如果觉得不够准确可以自行修改",
|
||||
}
|
||||
list = append(list, dto)
|
||||
|
||||
@@ -380,6 +388,7 @@ func (c *CpdailyAutoSignTask) ParseFormJson(ctx context.Context, rawJson map[str
|
||||
ColName: "address",
|
||||
Type: formtype.ItemTypeInput,
|
||||
Required: true,
|
||||
Tip: "这个就是指签到完毕后查看时最底部那个最详细的地址信息哦",
|
||||
}
|
||||
list = append(list, dto)
|
||||
|
||||
@@ -389,6 +398,7 @@ func (c *CpdailyAutoSignTask) ParseFormJson(ctx context.Context, rawJson map[str
|
||||
ColName: "signImg",
|
||||
Type: formtype.ItemTypeImage,
|
||||
Required: true,
|
||||
Tip: "您可以上传多张图片,会顺序轮换更新的哦~",
|
||||
}
|
||||
list = append(list, dto)
|
||||
}
|
||||
@@ -410,6 +420,7 @@ func (c *CpdailyAutoSignTask) ParseFormJson(ctx context.Context, rawJson map[str
|
||||
IsOtherItems: false,
|
||||
},
|
||||
},
|
||||
Tip: "一般在学校就是选否,如果在外实习、请假之类的才选是",
|
||||
}
|
||||
list = append(list, dto)
|
||||
|
||||
@@ -484,6 +495,11 @@ func (c *CpdailyAutoSignTask) FillCustomForm(ctx context.Context, form map[strin
|
||||
lon = v.Content
|
||||
case "address":
|
||||
address = v.Content
|
||||
case "latAndLon":
|
||||
{
|
||||
res := strings.Split(v.Content, ",")
|
||||
lat, lon = res[1], res[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -435,19 +435,27 @@ func (c *CpdailySleepCheckTask) ParseFormJson(ctx context.Context, rawJson map[s
|
||||
var list []*formtype.CpTaskFormItem
|
||||
|
||||
// 经纬度
|
||||
//dto := &formtype.CpTaskFormItem{
|
||||
// Title: "经度",
|
||||
// ColName: "lon",
|
||||
// Type: formtype.ItemTypeInput,
|
||||
// Required: true,
|
||||
//}
|
||||
//list = append(list, dto)
|
||||
//
|
||||
//dto = &formtype.CpTaskFormItem{
|
||||
// Title: "纬度",
|
||||
// ColName: "lat",
|
||||
// Type: formtype.ItemTypeInput,
|
||||
// Required: true,
|
||||
//}
|
||||
//list = append(list, dto)
|
||||
dto := &formtype.CpTaskFormItem{
|
||||
Title: "经度",
|
||||
ColName: "lon",
|
||||
Type: formtype.ItemTypeInput,
|
||||
Required: true,
|
||||
}
|
||||
list = append(list, dto)
|
||||
|
||||
dto = &formtype.CpTaskFormItem{
|
||||
Title: "纬度",
|
||||
ColName: "lat",
|
||||
Type: formtype.ItemTypeInput,
|
||||
Title: "经纬度",
|
||||
ColName: "latAndLon",
|
||||
Type: formtype.ItemTypeLatAndLon,
|
||||
Required: true,
|
||||
Tip: "您可以通过地址搜索签到经纬度,如果觉得不够准确可以自行修改",
|
||||
}
|
||||
list = append(list, dto)
|
||||
dto = &formtype.CpTaskFormItem{
|
||||
@@ -455,6 +463,7 @@ func (c *CpdailySleepCheckTask) ParseFormJson(ctx context.Context, rawJson map[s
|
||||
ColName: "address",
|
||||
Type: formtype.ItemTypeInput,
|
||||
Required: true,
|
||||
Tip: "这个就是指签到完毕后查看时最底部那个最详细的地址信息哦",
|
||||
}
|
||||
list = append(list, dto)
|
||||
|
||||
@@ -464,6 +473,7 @@ func (c *CpdailySleepCheckTask) ParseFormJson(ctx context.Context, rawJson map[s
|
||||
ColName: "signImg",
|
||||
Type: formtype.ItemTypeImage,
|
||||
Required: true,
|
||||
Tip: "您可以上传多张图片,会顺序轮换更新的哦~",
|
||||
}
|
||||
list = append(list, dto)
|
||||
|
||||
@@ -486,6 +496,7 @@ func (c *CpdailySleepCheckTask) ParseFormJson(ctx context.Context, rawJson map[s
|
||||
IsOtherItems: false,
|
||||
},
|
||||
},
|
||||
Tip: "一般在学校就是选否,如果在外实习、请假之类的才选是",
|
||||
}
|
||||
list = append(list, dto)
|
||||
|
||||
@@ -514,6 +525,12 @@ func (c *CpdailySleepCheckTask) FillCustomForm(ctx context.Context, form map[str
|
||||
lon = v.Content
|
||||
case "address":
|
||||
address = v.Content
|
||||
case "latAndLon":
|
||||
{
|
||||
res := strings.Split(v.Content, ",")
|
||||
lat, lon = res[1], res[0]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,7 +551,7 @@ func (c *CpdailySleepCheckTask) FillCustomForm(ctx context.Context, form map[str
|
||||
return utils.Catch(func() {
|
||||
ticket = submitCaptchaResolver.GetCaptchaTicket(ctx, captchaInfo)
|
||||
})
|
||||
}, retry.Delay(15*time.Second), retry.Attempts(5), retry.Context(ctx))
|
||||
}, retry.Delay(10*time.Second), retry.Attempts(5), retry.Context(ctx))
|
||||
if e != nil {
|
||||
utils.OkOrPanic(errors.NewBusinessError(503, "提交验证码识别失败").WithInnerError(e), oops.WithContext(ctx).Wrap)
|
||||
}
|
||||
@@ -676,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))
|
||||
}
|
||||
@@ -3,11 +3,25 @@ package httpclient
|
||||
import (
|
||||
"crypto/tls"
|
||||
"likedream-goframe/internal/utils"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"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")
|
||||
}
|
||||
|
||||
var Cpdaily = resty.New().
|
||||
SetCookieJar(nil).
|
||||
SetTimeout(30*time.Second).
|
||||
@@ -32,9 +46,7 @@ func NewCpdailyClient() *resty.Client {
|
||||
SetCookieJar(nil).
|
||||
SetTimeout(30*time.Second).
|
||||
SetDoNotParseResponse(true).
|
||||
SetTLSClientConfig(&tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
}).
|
||||
SetTransport(transport).
|
||||
SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36")
|
||||
|
||||
// 根据调试模式设置代理和调试选项
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package httpclient
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"likedream-goframe/internal/utils"
|
||||
"time"
|
||||
|
||||
"resty.dev/v3"
|
||||
)
|
||||
|
||||
func NewMogudingClient() *resty.Client {
|
||||
client := resty.New().
|
||||
SetCookieJar(nil).
|
||||
SetTimeout(30*time.Second).
|
||||
SetDoNotParseResponse(false).
|
||||
SetTLSClientConfig(&tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
}).
|
||||
SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36")
|
||||
|
||||
// 根据调试模式设置代理和调试选项
|
||||
if !utils.IsDebug() {
|
||||
client.SetDebug(false)
|
||||
} else {
|
||||
client.SetProxy("http://127.0.0.1:9000")
|
||||
}
|
||||
|
||||
return client
|
||||
}
|
||||
@@ -31,7 +31,7 @@ func NewXuexitongClient() *resty.Client {
|
||||
client := resty.New().
|
||||
SetCookieJar(nil).
|
||||
SetTimeout(30*time.Second).
|
||||
SetDoNotParseResponse(true).
|
||||
SetDoNotParseResponse(false).
|
||||
SetTLSClientConfig(&tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
}).
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package cryptoutil
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
const (
|
||||
// AES 密钥
|
||||
Secret = "23DbtQHR2UMbH6mJ"
|
||||
// MD5 签名后缀
|
||||
SignSuffix = "3478cbbc33f84bd00d75d7dfa69e0daa"
|
||||
)
|
||||
|
||||
// Encrypt 使用 AES ECB PKCS7 加密并返回十六进制字符串
|
||||
func Encrypt(plaintext string) (string, error) {
|
||||
key := []byte(Secret)
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// PKCS7 填充
|
||||
plainBytes := []byte(plaintext)
|
||||
padding := aes.BlockSize - len(plainBytes)%aes.BlockSize
|
||||
padText := make([]byte, len(plainBytes)+padding)
|
||||
copy(padText, plainBytes)
|
||||
for i := len(plainBytes); i < len(padText); i++ {
|
||||
padText[i] = byte(padding)
|
||||
}
|
||||
|
||||
// ECB 模式加密
|
||||
encrypted := make([]byte, len(padText))
|
||||
for i := 0; i < len(padText); i += aes.BlockSize {
|
||||
block.Encrypt(encrypted[i:i+aes.BlockSize], padText[i:i+aes.BlockSize])
|
||||
}
|
||||
|
||||
return hex.EncodeToString(encrypted), nil
|
||||
}
|
||||
|
||||
// Sign2 MD5 签名
|
||||
func Sign2(str string) string {
|
||||
str += SignSuffix
|
||||
hash := md5.Sum([]byte(str))
|
||||
return hex.EncodeToString(hash[:])
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package entity
|
||||
|
||||
// MogudingUser 蘑菇钉用户实体
|
||||
type MogudingUser struct {
|
||||
Username string `json:"username"` // 账号
|
||||
Password string `json:"password"` // 密码
|
||||
UserId string `json:"userId"`
|
||||
Token string `json:"token"`
|
||||
UserType string `json:"userType"`
|
||||
PlanId string `json:"planId"`
|
||||
PlanName string `json:"planName"`
|
||||
}
|
||||
|
||||
// LoginDto 登录请求 DTO
|
||||
type LoginDto struct {
|
||||
Phone string `json:"phone"`
|
||||
Password string `json:"password"`
|
||||
Captcha string `json:"captcha"`
|
||||
LoginType string `json:"loginType"`
|
||||
Uuid string `json:"uuid"`
|
||||
Device string `json:"device"`
|
||||
Version string `json:"version"`
|
||||
T string `json:"t"`
|
||||
}
|
||||
|
||||
// LoginResponse 登录响应
|
||||
type LoginResponse struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data struct {
|
||||
UserId string `json:"userId"`
|
||||
Token string `json:"token"`
|
||||
UserType string `json:"userType"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
// PlanResponse 获取 PlanId 响应
|
||||
type PlanResponse struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data []struct {
|
||||
PlanId string `json:"planId"`
|
||||
PlanName string `json:"planName"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
// SignRequest 签到请求
|
||||
type SignRequest struct {
|
||||
Country string `json:"country"`
|
||||
Address string `json:"address"`
|
||||
Province string `json:"province"`
|
||||
City string `json:"city"`
|
||||
State string `json:"state"`
|
||||
Area string `json:"area"`
|
||||
Latitude string `json:"latitude"`
|
||||
Longitude string `json:"longitude"`
|
||||
Description string `json:"description"`
|
||||
PlanId string `json:"planId"`
|
||||
Type string `json:"type"` // START 或 END
|
||||
Device string `json:"device"`
|
||||
}
|
||||
|
||||
// SignResponse 签到响应
|
||||
type SignResponse struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data any `json:"data"`
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
package moguding
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/application/httpclient"
|
||||
"likedream-goframe/internal/application/moguding/cryptoutil"
|
||||
"likedream-goframe/internal/application/moguding/entity"
|
||||
"likedream-goframe/internal/framework/logger"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"resty.dev/v3"
|
||||
)
|
||||
|
||||
const (
|
||||
// API 基础地址
|
||||
ApiBase = "https://api.moguding.net:9000"
|
||||
// 登录接口
|
||||
ApiLogin = ApiBase + "/session/user/v6/login"
|
||||
// 获取实习计划接口
|
||||
ApiGetPlan = ApiBase + "/practice/plan/v3/getPlanByStu"
|
||||
// 打卡签到接口
|
||||
ApiSign = ApiBase + "/attendence/clock/v4/save"
|
||||
)
|
||||
|
||||
type MogudingClient struct {
|
||||
client *resty.Client
|
||||
user *entity.MogudingUser
|
||||
}
|
||||
|
||||
// NewMogudingClient 创建蘑菇钉客户端
|
||||
func NewMogudingClient(ctx context.Context) *MogudingClient {
|
||||
client := httpclient.NewMogudingClient()
|
||||
|
||||
return &MogudingClient{
|
||||
client: client,
|
||||
user: &entity.MogudingUser{},
|
||||
}
|
||||
}
|
||||
|
||||
// Login 登录
|
||||
func (c *MogudingClient) Login(ctx context.Context, username, password string) error {
|
||||
if username == "" || password == "" {
|
||||
return fmt.Errorf("账号或密码不能为空")
|
||||
}
|
||||
|
||||
// 加密账号密码
|
||||
encryptedPhone, err := cryptoutil.Encrypt(username)
|
||||
if err != nil {
|
||||
logger.Logger.Error("加密账号失败", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
encryptedPassword, err := cryptoutil.Encrypt(password)
|
||||
if err != nil {
|
||||
logger.Logger.Error("加密密码失败", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
// 加密时间戳
|
||||
timestamp := fmt.Sprintf("%d", time.Now().UnixMilli())
|
||||
encryptedTime, err := cryptoutil.Encrypt(timestamp)
|
||||
if err != nil {
|
||||
logger.Logger.Error("加密时间戳失败", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
// 构造登录请求
|
||||
loginDto := entity.LoginDto{
|
||||
Phone: encryptedPhone,
|
||||
Password: encryptedPassword,
|
||||
T: encryptedTime,
|
||||
LoginType: "android",
|
||||
}
|
||||
|
||||
// 发送登录请求
|
||||
resp, err := c.client.R().
|
||||
SetBody(loginDto).
|
||||
Post(ApiLogin)
|
||||
|
||||
if err != nil {
|
||||
logger.Logger.Error("登录请求失败", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
// 解析响应
|
||||
var loginResp entity.LoginResponse
|
||||
if err := json.Unmarshal(resp.Bytes(), &loginResp); err != nil {
|
||||
logger.Logger.Error("解析登录响应失败", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
if loginResp.Code != 200 {
|
||||
return fmt.Errorf("登录失败:%s", loginResp.Msg)
|
||||
}
|
||||
|
||||
// 保存用户信息
|
||||
c.user.Username = username
|
||||
c.user.Password = password
|
||||
c.user.UserId = loginResp.Data.UserId
|
||||
c.user.Token = loginResp.Data.Token
|
||||
c.user.UserType = loginResp.Data.UserType
|
||||
|
||||
logger.Logger.Info("登录成功",
|
||||
zap.String("userId", c.user.UserId),
|
||||
zap.String("userType", c.user.UserType))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetPlanId 获取实习计划 ID
|
||||
func (c *MogudingClient) GetPlanId(ctx context.Context) error {
|
||||
if c.user.Token == "" {
|
||||
return fmt.Errorf("请先登录")
|
||||
}
|
||||
|
||||
// 计算签名
|
||||
signStr := c.user.UserId + c.user.UserType
|
||||
sign := cryptoutil.Sign2(signStr)
|
||||
|
||||
// 发送请求
|
||||
resp, err := c.client.R().
|
||||
SetHeaders(map[string]string{
|
||||
"roleKey": c.user.UserType,
|
||||
"sign": sign,
|
||||
"authorization": c.user.Token,
|
||||
}).
|
||||
SetBody(map[string]string{"state": ""}).
|
||||
Post(ApiGetPlan)
|
||||
|
||||
if err != nil {
|
||||
logger.Logger.Error("获取 PlanId 请求失败", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
// 解析响应
|
||||
var planResp entity.PlanResponse
|
||||
if err := json.Unmarshal(resp.Bytes(), &planResp); err != nil {
|
||||
logger.Logger.Error("解析 PlanId 响应失败", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
if planResp.Code != 200 {
|
||||
return fmt.Errorf("获取 PlanId 失败:%s", planResp.Msg)
|
||||
}
|
||||
|
||||
if len(planResp.Data) == 0 {
|
||||
return fmt.Errorf("未找到实习计划")
|
||||
}
|
||||
|
||||
// 保存第一个计划信息
|
||||
c.user.PlanId = planResp.Data[0].PlanId
|
||||
c.user.PlanName = planResp.Data[0].PlanName
|
||||
|
||||
logger.Logger.Info("获取 PlanId 成功",
|
||||
zap.String("planId", c.user.PlanId),
|
||||
zap.String("planName", c.user.PlanName))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Sign 打卡签到
|
||||
func (c *MogudingClient) Sign(ctx context.Context, signReq *entity.SignRequest) error {
|
||||
if c.user.Token == "" {
|
||||
return fmt.Errorf("请先登录")
|
||||
}
|
||||
|
||||
if c.user.PlanId == "" {
|
||||
return fmt.Errorf("请先获取实习计划")
|
||||
}
|
||||
|
||||
// 设置默认值
|
||||
if signReq.PlanId == "" {
|
||||
signReq.PlanId = c.user.PlanId
|
||||
}
|
||||
if signReq.Device == "" {
|
||||
signReq.Device = "Android"
|
||||
}
|
||||
if signReq.Type == "" {
|
||||
signReq.Type = "START"
|
||||
}
|
||||
|
||||
// 计算签名
|
||||
signStr := signReq.Device + signReq.Type + signReq.PlanId + c.user.UserId + signReq.Address
|
||||
sign := cryptoutil.Sign2(signStr)
|
||||
|
||||
// 发送请求
|
||||
resp, err := c.client.R().
|
||||
SetHeaders(map[string]string{
|
||||
"roleKey": c.user.UserType,
|
||||
"sign": sign,
|
||||
"authorization": c.user.Token,
|
||||
}).
|
||||
SetBody(signReq).
|
||||
Post(ApiSign)
|
||||
|
||||
if err != nil {
|
||||
logger.Logger.Error("签到请求失败", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
// 解析响应
|
||||
var signResp entity.SignResponse
|
||||
if err := json.Unmarshal(resp.Bytes(), &signResp); err != nil {
|
||||
logger.Logger.Error("解析签到响应失败", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
if signResp.Code != 200 {
|
||||
return fmt.Errorf("签到失败:%s", signResp.Msg)
|
||||
}
|
||||
|
||||
logger.Logger.Info("签到成功",
|
||||
zap.String("type", signReq.Type),
|
||||
zap.String("address", signReq.Address))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetUser 获取用户信息
|
||||
func (c *MogudingClient) GetUser() *entity.MogudingUser {
|
||||
return c.user
|
||||
}
|
||||
|
||||
// SetUser 设置用户信息(用于恢复登录状态)
|
||||
func (c *MogudingClient) SetUser(user *entity.MogudingUser) {
|
||||
c.user = user
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package moguding
|
||||
|
||||
import (
|
||||
"context"
|
||||
"likedream-goframe/internal/application/moguding/entity"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMogudingLogin(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
client := NewMogudingClient(ctx)
|
||||
|
||||
// 替换为实际的测试账号
|
||||
username := "13307425047"
|
||||
password := "wgz2021322L"
|
||||
|
||||
err := client.Login(ctx, username, password)
|
||||
if err != nil {
|
||||
t.Fatalf("登录失败: %v", err)
|
||||
}
|
||||
|
||||
t.Logf("登录成功,UserId: %s, Token: %s", client.user.UserId, client.user.Token)
|
||||
}
|
||||
|
||||
func TestMogudingGetPlanId(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
client := NewMogudingClient(ctx)
|
||||
|
||||
// 先登录
|
||||
username := "your_username"
|
||||
password := "your_password"
|
||||
|
||||
err := client.Login(ctx, username, password)
|
||||
if err != nil {
|
||||
t.Fatalf("登录失败: %v", err)
|
||||
}
|
||||
|
||||
// 获取 PlanId
|
||||
err = client.GetPlanId(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("获取 PlanId 失败: %v", err)
|
||||
}
|
||||
|
||||
t.Logf("获取 PlanId 成功,PlanId: %s, PlanName: %s", client.user.PlanId, client.user.PlanName)
|
||||
}
|
||||
|
||||
func TestMogudingSign(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
client := NewMogudingClient(ctx)
|
||||
|
||||
// 先登录
|
||||
username := "your_username"
|
||||
password := "your_password"
|
||||
|
||||
err := client.Login(ctx, username, password)
|
||||
if err != nil {
|
||||
t.Fatalf("登录失败: %v", err)
|
||||
}
|
||||
|
||||
// 获取 PlanId
|
||||
err = client.GetPlanId(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("获取 PlanId 失败: %v", err)
|
||||
}
|
||||
|
||||
// 打卡签到
|
||||
signReq := &entity.SignRequest{
|
||||
Country: "中国",
|
||||
Address: "四川省 · 成都市 · 武侯区 · 咕噜咕噜",
|
||||
Province: "四川省",
|
||||
City: "成都市",
|
||||
State: "1",
|
||||
Area: "武侯区",
|
||||
Latitude: "33.100039",
|
||||
Longitude: "101.987848",
|
||||
Description: "测试打卡",
|
||||
Type: "START", // START 表示上班打卡,END 表示下班打卡
|
||||
Device: "Android",
|
||||
}
|
||||
|
||||
err = client.Sign(ctx, signReq)
|
||||
if err != nil {
|
||||
t.Fatalf("打卡失败: %v", err)
|
||||
}
|
||||
|
||||
t.Logf("打卡成功")
|
||||
}
|
||||
|
||||
func TestMogudingFullProcess(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
client := NewMogudingClient(ctx)
|
||||
|
||||
// 1. 登录
|
||||
username := "your_username"
|
||||
password := "your_password"
|
||||
|
||||
t.Log("步骤1: 登录")
|
||||
err := client.Login(ctx, username, password)
|
||||
if err != nil {
|
||||
t.Fatalf("登录失败: %v", err)
|
||||
}
|
||||
t.Logf("登录成功,UserId: %s", client.user.UserId)
|
||||
|
||||
// 2. 获取 PlanId
|
||||
t.Log("步骤2: 获取实习计划")
|
||||
err = client.GetPlanId(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("获取 PlanId 失败: %v", err)
|
||||
}
|
||||
t.Logf("获取 PlanId 成功,PlanId: %s, PlanName: %s", client.user.PlanId, client.user.PlanName)
|
||||
|
||||
// 3. 上班打卡
|
||||
t.Log("步骤3: 上班打卡")
|
||||
signInReq := &entity.SignRequest{
|
||||
Country: "中国",
|
||||
Address: "四川省 · 成都市 · 武侯区 · 咕噜咕噜",
|
||||
Province: "四川省",
|
||||
City: "成都市",
|
||||
State: "1",
|
||||
Area: "武侯区",
|
||||
Latitude: "33.100039",
|
||||
Longitude: "101.987848",
|
||||
Description: "上班打卡",
|
||||
Type: "START",
|
||||
Device: "Android",
|
||||
}
|
||||
|
||||
err = client.Sign(ctx, signInReq)
|
||||
if err != nil {
|
||||
t.Fatalf("上班打卡失败: %v", err)
|
||||
}
|
||||
t.Log("上班打卡成功")
|
||||
|
||||
// 4. 下班打卡(可选)
|
||||
t.Log("步骤4: 下班打卡")
|
||||
signOutReq := &entity.SignRequest{
|
||||
Country: "中国",
|
||||
Address: "四川省 · 成都市 · 武侯区 · 咕噜咕噜",
|
||||
Province: "四川省",
|
||||
City: "成都市",
|
||||
State: "1",
|
||||
Area: "武侯区",
|
||||
Latitude: "33.100039",
|
||||
Longitude: "101.987848",
|
||||
Description: "下班打卡",
|
||||
Type: "END",
|
||||
Device: "Android",
|
||||
}
|
||||
|
||||
err = client.Sign(ctx, signOutReq)
|
||||
if err != nil {
|
||||
t.Fatalf("下班打卡失败: %v", err)
|
||||
}
|
||||
t.Log("下班打卡成功")
|
||||
|
||||
t.Log("完整流程测试通过!")
|
||||
}
|
||||
@@ -62,11 +62,86 @@ 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 int `json:"id"` // 章节ID
|
||||
Name string `json:"name"` // 章节名称
|
||||
ParentNodeID int `json:"parentnodeid"` // 父节点ID
|
||||
Layer int `json:"layer"` // 层级
|
||||
Label string `json:"label"` // 标签
|
||||
IndexOrder int `json:"indexOrder"` // 排序索引
|
||||
JobCount int `json:"jobcount"` // 任务点数量
|
||||
Status string `json:"status"` // 状态
|
||||
IsReview int `json:"isReview"` // 是否复习
|
||||
BeginTime int64 `json:"begintime"` // 开始时间
|
||||
EndTime int64 `json:"endtime"` // 结束时间
|
||||
PointTotal int `json:"pointTotal"` // 总任务点
|
||||
PointFinish int `json:"pointFinish"` // 已完成任务点
|
||||
Knowledge []XueXiTCourseChapter `json:"knowledge"` // 子章节列表
|
||||
}
|
||||
|
||||
// ChapterData 章节数据响应
|
||||
type ChapterData struct {
|
||||
Data []struct {
|
||||
Hideclazz int `json:"hideclazz"`
|
||||
Allowdownload int `json:"allowdownload"`
|
||||
Chatid string `json:"chatid"`
|
||||
Isfiled int `json:"isfiled"`
|
||||
Forbidintoclazz int `json:"forbidintoclazz"`
|
||||
Coursesetting struct {
|
||||
Data []struct {
|
||||
Coursefacecheck int `json:"coursefacecheck"`
|
||||
Hiddencoursecover int `json:"hiddencoursecover"`
|
||||
ID int `json:"id"`
|
||||
Courseid int `json:"courseid"`
|
||||
} `json:"data"`
|
||||
} `json:"coursesetting"`
|
||||
Isstart bool `json:"isstart"`
|
||||
Visiblescore int `json:"visiblescore"`
|
||||
Name string `json:"name"`
|
||||
Course struct {
|
||||
Data []struct {
|
||||
App int `json:"app"`
|
||||
Teacherfactor string `json:"teacherfactor"`
|
||||
Jobcount int `json:"jobcount"`
|
||||
Infocontent string `json:"infocontent"`
|
||||
Bulletformat string `json:"bulletformat"`
|
||||
Mappingcourseid int `json:"mappingcourseid"`
|
||||
Imageurl string `json:"imageurl"`
|
||||
Name string `json:"name"`
|
||||
ID int `json:"id"`
|
||||
Belongschoolid string `json:"belongschoolid"`
|
||||
Objectid string `json:"objectid"`
|
||||
Knowledge struct {
|
||||
Data []KnowledgeData `json:"data"`
|
||||
} `json:"knowledge"`
|
||||
} `json:"data"`
|
||||
} `json:"course"`
|
||||
ID int `json:"id"`
|
||||
State int `json:"state"`
|
||||
Bbsid string `json:"bbsid"`
|
||||
Classscore int `json:"classscore"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
// 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"` // 题目列表
|
||||
}
|
||||
@@ -5,11 +5,13 @@ import (
|
||||
"likedream-goframe/internal/application/cookiejar"
|
||||
"likedream-goframe/internal/application/httpclient"
|
||||
"likedream-goframe/internal/application/xuexitong/cryptoutil"
|
||||
"likedream-goframe/internal/framework/errors"
|
||||
"likedream-goframe/internal/framework/logger"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
"go.uber.org/zap"
|
||||
"resty.dev/v3"
|
||||
)
|
||||
@@ -28,6 +30,8 @@ func NewXuexitongLogin(ctx context.Context) *XuexitongLogin {
|
||||
}
|
||||
}
|
||||
func (c *XuexitongLogin) Login(ctx context.Context, username, password string, retry int) (err error) {
|
||||
jar := cookiejar.NewAllSavePersistCookieJar()
|
||||
c.client.SetCookieJar(jar)
|
||||
usernameEncrypted, err := cryptoutil.LoginEncrypt(username)
|
||||
if err != nil {
|
||||
logger.Logger.Error("LoginEncrypt err:", zap.Error(err))
|
||||
@@ -60,6 +64,9 @@ func (c *XuexitongLogin) Login(ctx context.Context, username, password string, r
|
||||
time.Sleep(time.Duration(retry*5) * time.Second)
|
||||
return c.Login(ctx, username, password, retry-1)
|
||||
}
|
||||
if !gjson.Get(body, "status").Bool() {
|
||||
return errors.NewBusinessErrorWithDetail(401, "登录失败", gjson.Get(body, "msg2").String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -3,22 +3,14 @@ package xuexitong
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"likedream-goframe/internal/utils"
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"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"}
|
||||
|
||||
func ApiVerifyCode(client *resty.Client, retry int) (string, error) {
|
||||
if retry < 0 {
|
||||
return "", fmt.Errorf("retry limit exceeded")
|
||||
}
|
||||
// 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()
|
||||
@@ -28,44 +20,19 @@ func ApiVerifyCode(client *resty.Client, retry int) (string, error) {
|
||||
req.Header.Add("Connection", "keep-alive")
|
||||
res, err := req.Get(urlStr)
|
||||
if err != nil {
|
||||
if retry > 0 {
|
||||
return ApiVerifyCode(client, retry-1)
|
||||
} else {
|
||||
return res.String(), err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
codeFileName := "code" + randChar[rand.Intn(len(randChar))] //生成验证码文件名称
|
||||
for i := 0; i < 10; i++ {
|
||||
codeFileName += randChar[rand.Intn(len(randChar))]
|
||||
}
|
||||
codeFileName += ".png"
|
||||
utils.PathExistForCreate("./assets/code/") //检测是否存在路径,如果不存在则创建
|
||||
filepath := fmt.Sprintf("./assets/code/%s", codeFileName)
|
||||
file, err := os.Create(filepath)
|
||||
defer res.Body.Close()
|
||||
all, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
res.Body.Close() //立即释放
|
||||
log.Println(err)
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = io.Copy(file, res.Body)
|
||||
if err != nil {
|
||||
res.Body.Close() //立即释放
|
||||
log.Println(err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
file.Close()
|
||||
if utils.IsBadImg(filepath) {
|
||||
res.Body.Close() //立即释放
|
||||
utils.DeleteFile(filepath) //删除坏的文件
|
||||
return ApiVerifyCode(client, retry-1)
|
||||
}
|
||||
return filepath, nil
|
||||
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"
|
||||
@@ -79,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,10 +2,27 @@ package xuexitong
|
||||
|
||||
import (
|
||||
"context"
|
||||
"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)
|
||||
@@ -18,7 +35,136 @@ func TestPullCourse(t *testing.T) {
|
||||
utils.OkOrPanic(err)
|
||||
client := xuexitongLogin.GetClient()
|
||||
courseAction := NewXuexitongCourse(client)
|
||||
list, err := courseAction.PullCourseList(context.Background(), 5)
|
||||
list := courseAction.PullCourseList(context.Background())
|
||||
utils.OkOrPanic(err)
|
||||
t.Log(list)
|
||||
}
|
||||
|
||||
func TestPullChapter(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("没有找到课程")
|
||||
}
|
||||
|
||||
// 获取第一个课程的章节
|
||||
chapters := courseAction.PullCourseChapterList(context.Background(), courseList[0])
|
||||
t.Logf("课程 %s 的章节数量: %d", courseList[0].CourseName, len(chapters))
|
||||
|
||||
for _, chapter := range chapters {
|
||||
t.Logf("章节: %s, 任务点数量: %d", chapter.Name, chapter.JobCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFetchChapterCards(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)
|
||||
if len(chapters) == 0 {
|
||||
t.Fatal("没有找到章节")
|
||||
}
|
||||
|
||||
// 找一个有任务点的章节
|
||||
var targetChapterID int
|
||||
for _, ch := range chapters {
|
||||
if ch.JobCount > 0 {
|
||||
targetChapterID = ch.ID
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if targetChapterID == 0 {
|
||||
t.Fatal("没有找到有任务点的章节")
|
||||
}
|
||||
|
||||
// 获取任务点卡片
|
||||
cards, points, err := courseAction.FetchChapterCards(context.Background(), course, targetChapterID)
|
||||
utils.OkOrPanic(err)
|
||||
|
||||
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 _, video := range points.Videos {
|
||||
t.Logf("视频任务点: JobID=%s, ObjectID=%s", video.JobID, video.ObjectID)
|
||||
}
|
||||
for _, doc := range points.Documents {
|
||||
t.Logf("文档任务点: JobID=%s, Type=%s", doc.JobID, doc.Type)
|
||||
}
|
||||
for _, work := range points.Works {
|
||||
t.Logf("作业任务点: JobID=%s, WorkID=%s", work.JobID, work.WorkID)
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestAutoStudyByCourseID 测试通过课程ID刷课(定时任务使用)
|
||||
func TestAutoStudyByCourseID(t *testing.T) {
|
||||
// 登录
|
||||
xuexitongLogin := NewXuexitongLogin(context.Background())
|
||||
err := xuexitongLogin.Login(context.Background(), "13551503012", "xiaozhi520", 5)
|
||||
utils.OkOrPanic(err)
|
||||
|
||||
// 创建课程实例
|
||||
courseAction := NewXuexitongCourse(xuexitongLogin.GetClient())
|
||||
|
||||
// 先获取课程列表,拿到第一个课程的ID
|
||||
courseList := courseAction.PullCourseList(context.Background())
|
||||
if len(courseList) == 0 {
|
||||
t.Fatal("没有找到课程")
|
||||
}
|
||||
|
||||
courseID := courseList[0].CourseID
|
||||
t.Logf("准备刷课程ID: %s", courseID)
|
||||
|
||||
// 一键刷指定课程的所有任务(定时任务就调用这一个方法)
|
||||
err = courseAction.AutoStudyByCourseID(context.Background(), courseID)
|
||||
utils.OkOrPanic(err)
|
||||
|
||||
t.Log("指定课程刷课完成")
|
||||
}
|
||||
|
||||
// TestAutoStudyAllCourses 测试自动刷所有课程
|
||||
func TestAutoStudyAllCourses(t *testing.T) {
|
||||
// 登录
|
||||
xuexitongLogin := NewXuexitongLogin(context.Background())
|
||||
err := xuexitongLogin.Login(context.Background(), "13551503012", "xiaozhi520", 5)
|
||||
utils.OkOrPanic(err)
|
||||
|
||||
// 创建课程实例
|
||||
courseAction := NewXuexitongCourse(xuexitongLogin.GetClient())
|
||||
|
||||
// 一键刷所有课程
|
||||
err = courseAction.AutoStudyAllCourses(context.Background())
|
||||
utils.OkOrPanic(err)
|
||||
|
||||
t.Log("所有课程刷课完成")
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -22,6 +22,7 @@ const (
|
||||
ConfigCpdailyAppVersion = "cpdaily.appVersion"
|
||||
ConfigCpdailySystemVersion = "cpdaily.systemVersion"
|
||||
ConfigCpdailyCalVersion = "cpdaily.calVersion"
|
||||
ConfigSliderSchoolIds = "cpdaily.sliderIds"
|
||||
|
||||
ConfigRedisUrl = "redis.url"
|
||||
|
||||
@@ -34,6 +35,11 @@ const (
|
||||
ConfigEmailSMTPPassword = "email.smtpPassword"
|
||||
ConfigEmailFromEmail = "email.fromEmail"
|
||||
ConfigEmailFromName = "email.fromName"
|
||||
|
||||
// 基础积分配置
|
||||
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"
|
||||
)
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
package cst
|
||||
|
||||
const (
|
||||
TaskCpdaily = "task:cpdaily"
|
||||
TaskEmail = "task:email"
|
||||
TaskResetDaily = "task:reset:daily"
|
||||
TaskCpdaily = "task:cpdaily"
|
||||
TaskEmail = "task:email"
|
||||
TaskResetDaily = "task:reset:daily"
|
||||
TaskXuexitong = "task:xuexitong"
|
||||
TaskXuexitongVio = "task:xuexitong:violence"
|
||||
|
||||
TaskCpdailyId = "cpdaily:task:schedule:%d"
|
||||
|
||||
TaskQueueCpdaily = "queue:cpdaily"
|
||||
TaskQueueEmail = "queue:email"
|
||||
TaskQueueDefault = "default"
|
||||
TaskQueueCpdaily = "queue:cpdaily"
|
||||
TaskQueueEmail = "queue:email"
|
||||
TaskQueueXuexitong = "queue:xuexitong"
|
||||
TaskQueueXuexitongVio = "queue:xuexitong:violence"
|
||||
TaskQueueDefault = "default"
|
||||
)
|
||||
|
||||
@@ -0,0 +1,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)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package course
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/application/xuexitong/entity"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/utils"
|
||||
)
|
||||
|
||||
type IXxtCtrlV1 interface {
|
||||
List(ctx context.Context, req *v1.CourseListReq) (*utils.Response[[]*ent.CourseEntity], error)
|
||||
AddCourse(ctx context.Context, req *v1.AddCourseReq) (*utils.Response[any], error)
|
||||
UpdatePassword(ctx context.Context, req *v1.UpdateCoursePasswordReq) (*utils.Response[any], error)
|
||||
RestartCourse(ctx context.Context, req *v1.RestartCourseReq) (*utils.Response[any], error)
|
||||
PauseCourse(ctx context.Context, req *v1.PauseCourseReq) (*utils.Response[any], error)
|
||||
DeleteCourse(ctx context.Context, req *v1.DeleteCourseReq) (*utils.Response[any], error)
|
||||
QueryCourses(ctx context.Context, req *v1.QueryCourseReq) (*utils.Response[[]entity.XueXiTCourse], error)
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package course
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/application/xuexitong/entity"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/service"
|
||||
"likedream-goframe/internal/utils"
|
||||
)
|
||||
|
||||
type XxtCtrlV1 struct {
|
||||
}
|
||||
|
||||
// List 获取刷课列表
|
||||
func (c XxtCtrlV1) List(ctx context.Context, req *v1.CourseListReq) (res *utils.Response[[]*ent.CourseEntity], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.Course.List(ctx, req), nil
|
||||
}
|
||||
|
||||
// AddCourse 添加刷课
|
||||
func (c XxtCtrlV1) AddCourse(ctx context.Context, req *v1.AddCourseReq) (res *utils.Response[any], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.Course.AddCourse(ctx, req), nil
|
||||
}
|
||||
|
||||
// UpdatePassword 修改刷课密码
|
||||
func (c XxtCtrlV1) UpdatePassword(ctx context.Context, req *v1.UpdateCoursePasswordReq) (res *utils.Response[any], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.Course.UpdatePassword(ctx, req), nil
|
||||
}
|
||||
|
||||
// RestartCourse 重刷课程
|
||||
func (c XxtCtrlV1) RestartCourse(ctx context.Context, req *v1.RestartCourseReq) (res *utils.Response[any], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.Course.RestartCourse(ctx, req), nil
|
||||
}
|
||||
|
||||
// PauseCourse 暂停刷课
|
||||
func (c XxtCtrlV1) PauseCourse(ctx context.Context, req *v1.PauseCourseReq) (res *utils.Response[any], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.Course.PauseCourse(ctx, req), nil
|
||||
}
|
||||
|
||||
// DeleteCourse 删除刷课
|
||||
func (c XxtCtrlV1) DeleteCourse(ctx context.Context, req *v1.DeleteCourseReq) (res *utils.Response[any], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.Course.DeleteCourse(ctx, req), nil
|
||||
}
|
||||
|
||||
// QueryCourses 查询课程列表
|
||||
func (c XxtCtrlV1) QueryCourses(ctx context.Context, req *v1.QueryCourseReq) (res *utils.Response[[]entity.XueXiTCourse], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.Course.QueryCourses(ctx, req), nil
|
||||
}
|
||||
|
||||
func NewXxtCtrlV1() IXxtCtrlV1 {
|
||||
return &XxtCtrlV1{}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package cpdaily
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/service"
|
||||
"likedream-goframe/internal/utils"
|
||||
)
|
||||
|
||||
type CpLeaveCtrlV1 struct {
|
||||
}
|
||||
|
||||
func (c CpLeaveCtrlV1) GetLeaveListFromSystem(ctx context.Context, req *v1.GetLeaveListFromSystemReq) (res *utils.Response[any], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.CpLeave.GetLeaveListFromSystem(ctx, req), nil
|
||||
}
|
||||
|
||||
func (c CpLeaveCtrlV1) List(ctx context.Context, req *v1.CpLeaveListReq) (res *utils.Response[[]*ent.CpLeave], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.CpLeave.List(ctx, req), nil
|
||||
}
|
||||
|
||||
func (c CpLeaveCtrlV1) Report(ctx context.Context, req *v1.CpLeaveReportReq) (res *utils.Response[any], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.CpLeave.Report(ctx, req), nil
|
||||
}
|
||||
|
||||
func NewCpLeaveCtrlV1() ICpLeaveCtrlV1 {
|
||||
return &CpLeaveCtrlV1{}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package cpdaily
|
||||
import (
|
||||
"context"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/application/cpdaily/map_info"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/service"
|
||||
"likedream-goframe/internal/utils"
|
||||
@@ -11,6 +12,11 @@ import (
|
||||
type CpTaskCtrlV1 struct {
|
||||
}
|
||||
|
||||
func (c CpTaskCtrlV1) FindLocation(ctx context.Context, req *v1.FindLocationReq) (res *utils.Response[any], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return utils.SuccessWithData[any](map_info.SearchAddressLongitudeAndLatitude(ctx, req.Address)), nil
|
||||
}
|
||||
|
||||
func (c CpTaskCtrlV1) List(ctx context.Context, req *v1.CpTaskListReq) (res *utils.Response[[]*ent.CpTask], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.CpTask.List(ctx, req), nil
|
||||
@@ -59,6 +65,12 @@ func (c CpTaskCtrlV1) PauseTask(ctx context.Context, req *v1.PauseTaskReq) (res
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.CpTask.PauseTask(ctx, req), nil
|
||||
}
|
||||
|
||||
func (c CpTaskCtrlV1) GetTaskStatistics(ctx context.Context, req *v1.GetTaskStatisticsReq) (res *utils.Response[[]*v1.TaskStatisticsItem], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.CpTask.GetTaskStatistics(ctx, req), nil
|
||||
}
|
||||
|
||||
func NewCpTaskCtrlV1() ICpTaskCtrlV1 {
|
||||
return &CpTaskCtrlV1{}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
@@ -15,6 +19,11 @@ func NewCpUserCtrlV1() ICpUserCtrlV1 {
|
||||
return &CpUserCtrlV1{}
|
||||
}
|
||||
|
||||
func (c CpUserCtrlV1) LoginUrl(ctx context.Context, req *v1.CpUserLoginUrlReq) (res *utils.Response[any], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.CpUser.LoginUrl(ctx, req), nil
|
||||
}
|
||||
|
||||
func (c CpUserCtrlV1) Add(ctx context.Context, req *v1.CpUserAddReq) (res *utils.Response[any], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.CpUser.Add(ctx, req), nil
|
||||
@@ -61,3 +70,34 @@ func (c CpUserCtrlV1) AuthorizeRandom(ctx context.Context, req *v1.CpUserAuthori
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.CpUser.AuthorizeRandom(ctx, req), nil
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package cpdaily
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/utils"
|
||||
)
|
||||
|
||||
type ICpLeaveCtrlV1 interface {
|
||||
GetLeaveListFromSystem(ctx context.Context, req *v1.GetLeaveListFromSystemReq) (*utils.Response[any], error)
|
||||
List(ctx context.Context, req *v1.CpLeaveListReq) (*utils.Response[[]*ent.CpLeave], error)
|
||||
Report(ctx context.Context, req *v1.CpLeaveReportReq) (*utils.Response[any], error)
|
||||
}
|
||||
@@ -18,4 +18,6 @@ type ICpTaskCtrlV1 interface {
|
||||
Delete(ctx context.Context, req *v1.DeleteTaskReq) (res *utils.Response[any], err error)
|
||||
ExecuteNow(ctx context.Context, req *v1.ExecuteNowReq) (res *utils.Response[any], err error)
|
||||
PauseTask(ctx context.Context, req *v1.PauseTaskReq) (res *utils.Response[any], err error)
|
||||
FindLocation(ctx context.Context, req *v1.FindLocationReq) (res *utils.Response[any], err error)
|
||||
GetTaskStatistics(ctx context.Context, req *v1.GetTaskStatisticsReq) (res *utils.Response[[]*v1.TaskStatisticsItem], err error)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
)
|
||||
|
||||
type ICpUserCtrlV1 interface {
|
||||
LoginUrl(ctx context.Context, req *v1.CpUserLoginUrlReq) (res *utils.Response[any], err error)
|
||||
|
||||
SchoolList(ctx context.Context, req *v1.CpSchoolListReq) (*utils.Response[[]*ent.CpSchool], error)
|
||||
// 添加用户
|
||||
Add(ctx context.Context, req *v1.CpUserAddReq) (*utils.Response[any], error)
|
||||
@@ -25,4 +27,8 @@ type ICpUserCtrlV1 interface {
|
||||
AuthorizeConfirm(ctx context.Context, req *v1.CpUserAuthorizeConfirmReq) (*utils.Response[any], error)
|
||||
// 随机授权
|
||||
AuthorizeRandom(ctx context.Context, req *v1.CpUserAuthorizeRandomReq) (res *utils.Response[any], err error)
|
||||
|
||||
// 手机登录获取验证码
|
||||
LoginGetCode(ctx context.Context, req *v1.LoginGetCode) (*utils.Response[any], error)
|
||||
AddByCode(ctx context.Context, req *v1.AddByCode) (*utils.Response[any], error)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/framework/captcha"
|
||||
"likedream-goframe/internal/framework/errors"
|
||||
"likedream-goframe/internal/framework/redis"
|
||||
"likedream-goframe/internal/service"
|
||||
"likedream-goframe/internal/utils"
|
||||
@@ -46,6 +47,7 @@ func (c *UserLoginV1) Login(ctx context.Context, req *v1.UserLoginReq) (res *uti
|
||||
if !captcha.VerifyCaptcha(dots, req.Dots) {
|
||||
return utils.Fail(10003, "验证码错误"), nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
+759
-35
@@ -11,13 +11,17 @@ import (
|
||||
|
||||
"likedream-goframe/internal/ent/migrate"
|
||||
|
||||
"likedream-goframe/internal/ent/courseentity"
|
||||
"likedream-goframe/internal/ent/cpimage"
|
||||
"likedream-goframe/internal/ent/cpleave"
|
||||
"likedream-goframe/internal/ent/cpschool"
|
||||
"likedream-goframe/internal/ent/cptask"
|
||||
"likedream-goframe/internal/ent/cptasklog"
|
||||
"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"
|
||||
@@ -37,8 +41,12 @@ type Client struct {
|
||||
config
|
||||
// Schema is the client for creating, migrating and dropping schema.
|
||||
Schema *migrate.Schema
|
||||
// CourseEntity is the client for interacting with the CourseEntity builders.
|
||||
CourseEntity *CourseEntityClient
|
||||
// CpImage is the client for interacting with the CpImage builders.
|
||||
CpImage *CpImageClient
|
||||
// CpLeave is the client for interacting with the CpLeave builders.
|
||||
CpLeave *CpLeaveClient
|
||||
// CpSchool is the client for interacting with the CpSchool builders.
|
||||
CpSchool *CpSchoolClient
|
||||
// CpTask is the client for interacting with the CpTask builders.
|
||||
@@ -49,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.
|
||||
@@ -70,13 +82,17 @@ func NewClient(opts ...Option) *Client {
|
||||
|
||||
func (c *Client) init() {
|
||||
c.Schema = migrate.NewSchema(c.driver)
|
||||
c.CourseEntity = NewCourseEntityClient(c.config)
|
||||
c.CpImage = NewCpImageClient(c.config)
|
||||
c.CpLeave = NewCpLeaveClient(c.config)
|
||||
c.CpSchool = NewCpSchoolClient(c.config)
|
||||
c.CpTask = NewCpTaskClient(c.config)
|
||||
c.CpTaskLog = NewCpTaskLogClient(c.config)
|
||||
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)
|
||||
@@ -173,19 +189,23 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||
cfg := c.config
|
||||
cfg.driver = tx
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
CpImage: NewCpImageClient(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
|
||||
}
|
||||
|
||||
@@ -203,26 +223,30 @@ 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,
|
||||
CpImage: NewCpImageClient(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
|
||||
}
|
||||
|
||||
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||
//
|
||||
// client.Debug().
|
||||
// CpImage.
|
||||
// CourseEntity.
|
||||
// Query().
|
||||
// Count(ctx)
|
||||
func (c *Client) Debug() *Client {
|
||||
@@ -245,8 +269,9 @@ func (c *Client) Close() error {
|
||||
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
||||
func (c *Client) Use(hooks ...Hook) {
|
||||
for _, n := range []interface{ Use(...Hook) }{
|
||||
c.CpImage, c.CpSchool, c.CpTask, c.CpTaskLog, c.CpUser, c.SysAgent, c.SysCard,
|
||||
c.SysMenu, c.SysRole, c.SysUser, c.SysUserLog,
|
||||
c.CourseEntity, c.CpImage, c.CpLeave, c.CpSchool, c.CpTask, c.CpTaskLog,
|
||||
c.CpUser, c.SysAgent, c.SysBalanceRecord, c.SysCard, c.SysConfig, c.SysMenu,
|
||||
c.SysRole, c.SysUser, c.SysUserLog,
|
||||
} {
|
||||
n.Use(hooks...)
|
||||
}
|
||||
@@ -256,8 +281,9 @@ func (c *Client) Use(hooks ...Hook) {
|
||||
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
||||
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||
for _, n := range []interface{ Intercept(...Interceptor) }{
|
||||
c.CpImage, c.CpSchool, c.CpTask, c.CpTaskLog, c.CpUser, c.SysAgent, c.SysCard,
|
||||
c.SysMenu, c.SysRole, c.SysUser, c.SysUserLog,
|
||||
c.CourseEntity, c.CpImage, c.CpLeave, c.CpSchool, c.CpTask, c.CpTaskLog,
|
||||
c.CpUser, c.SysAgent, c.SysBalanceRecord, c.SysCard, c.SysConfig, c.SysMenu,
|
||||
c.SysRole, c.SysUser, c.SysUserLog,
|
||||
} {
|
||||
n.Intercept(interceptors...)
|
||||
}
|
||||
@@ -266,8 +292,12 @@ func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||
// Mutate implements the ent.Mutator interface.
|
||||
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
switch m := m.(type) {
|
||||
case *CourseEntityMutation:
|
||||
return c.CourseEntity.mutate(ctx, m)
|
||||
case *CpImageMutation:
|
||||
return c.CpImage.mutate(ctx, m)
|
||||
case *CpLeaveMutation:
|
||||
return c.CpLeave.mutate(ctx, m)
|
||||
case *CpSchoolMutation:
|
||||
return c.CpSchool.mutate(ctx, m)
|
||||
case *CpTaskMutation:
|
||||
@@ -278,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:
|
||||
@@ -293,6 +327,159 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// CourseEntityClient is a client for the CourseEntity schema.
|
||||
type CourseEntityClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewCourseEntityClient returns a client for the CourseEntity from the given config.
|
||||
func NewCourseEntityClient(c config) *CourseEntityClient {
|
||||
return &CourseEntityClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `courseentity.Hooks(f(g(h())))`.
|
||||
func (c *CourseEntityClient) Use(hooks ...Hook) {
|
||||
c.hooks.CourseEntity = append(c.hooks.CourseEntity, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `courseentity.Intercept(f(g(h())))`.
|
||||
func (c *CourseEntityClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.CourseEntity = append(c.inters.CourseEntity, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a CourseEntity entity.
|
||||
func (c *CourseEntityClient) Create() *CourseEntityCreate {
|
||||
mutation := newCourseEntityMutation(c.config, OpCreate)
|
||||
return &CourseEntityCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of CourseEntity entities.
|
||||
func (c *CourseEntityClient) CreateBulk(builders ...*CourseEntityCreate) *CourseEntityCreateBulk {
|
||||
return &CourseEntityCreateBulk{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 *CourseEntityClient) MapCreateBulk(slice any, setFunc func(*CourseEntityCreate, int)) *CourseEntityCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &CourseEntityCreateBulk{err: fmt.Errorf("calling to CourseEntityClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*CourseEntityCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &CourseEntityCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for CourseEntity.
|
||||
func (c *CourseEntityClient) Update() *CourseEntityUpdate {
|
||||
mutation := newCourseEntityMutation(c.config, OpUpdate)
|
||||
return &CourseEntityUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *CourseEntityClient) UpdateOne(_m *CourseEntity) *CourseEntityUpdateOne {
|
||||
mutation := newCourseEntityMutation(c.config, OpUpdateOne, withCourseEntity(_m))
|
||||
return &CourseEntityUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *CourseEntityClient) UpdateOneID(id int64) *CourseEntityUpdateOne {
|
||||
mutation := newCourseEntityMutation(c.config, OpUpdateOne, withCourseEntityID(id))
|
||||
return &CourseEntityUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for CourseEntity.
|
||||
func (c *CourseEntityClient) Delete() *CourseEntityDelete {
|
||||
mutation := newCourseEntityMutation(c.config, OpDelete)
|
||||
return &CourseEntityDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *CourseEntityClient) DeleteOne(_m *CourseEntity) *CourseEntityDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *CourseEntityClient) DeleteOneID(id int64) *CourseEntityDeleteOne {
|
||||
builder := c.Delete().Where(courseentity.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &CourseEntityDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for CourseEntity.
|
||||
func (c *CourseEntityClient) Query() *CourseEntityQuery {
|
||||
return &CourseEntityQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeCourseEntity},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a CourseEntity entity by its id.
|
||||
func (c *CourseEntityClient) Get(ctx context.Context, id int64) (*CourseEntity, error) {
|
||||
return c.Query().Where(courseentity.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *CourseEntityClient) GetX(ctx context.Context, id int64) *CourseEntity {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QuerySysUser queries the sys_user edge of a CourseEntity.
|
||||
func (c *CourseEntityClient) QuerySysUser(_m *CourseEntity) *SysUserQuery {
|
||||
query := (&SysUserClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(courseentity.Table, courseentity.FieldID, id),
|
||||
sqlgraph.To(sysuser.Table, sysuser.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, courseentity.SysUserTable, courseentity.SysUserColumn),
|
||||
)
|
||||
schemaConfig := _m.schemaConfig
|
||||
step.To.Schema = schemaConfig.SysUser
|
||||
step.Edge.Schema = schemaConfig.CourseEntity
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *CourseEntityClient) Hooks() []Hook {
|
||||
hooks := c.hooks.CourseEntity
|
||||
return append(hooks[:len(hooks):len(hooks)], courseentity.Hooks[:]...)
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *CourseEntityClient) Interceptors() []Interceptor {
|
||||
return c.inters.CourseEntity
|
||||
}
|
||||
|
||||
func (c *CourseEntityClient) mutate(ctx context.Context, m *CourseEntityMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&CourseEntityCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&CourseEntityUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&CourseEntityUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&CourseEntityDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown CourseEntity mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// CpImageClient is a client for the CpImage schema.
|
||||
type CpImageClient struct {
|
||||
config
|
||||
@@ -446,6 +633,178 @@ func (c *CpImageClient) mutate(ctx context.Context, m *CpImageMutation) (Value,
|
||||
}
|
||||
}
|
||||
|
||||
// CpLeaveClient is a client for the CpLeave schema.
|
||||
type CpLeaveClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewCpLeaveClient returns a client for the CpLeave from the given config.
|
||||
func NewCpLeaveClient(c config) *CpLeaveClient {
|
||||
return &CpLeaveClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `cpleave.Hooks(f(g(h())))`.
|
||||
func (c *CpLeaveClient) Use(hooks ...Hook) {
|
||||
c.hooks.CpLeave = append(c.hooks.CpLeave, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `cpleave.Intercept(f(g(h())))`.
|
||||
func (c *CpLeaveClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.CpLeave = append(c.inters.CpLeave, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a CpLeave entity.
|
||||
func (c *CpLeaveClient) Create() *CpLeaveCreate {
|
||||
mutation := newCpLeaveMutation(c.config, OpCreate)
|
||||
return &CpLeaveCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of CpLeave entities.
|
||||
func (c *CpLeaveClient) CreateBulk(builders ...*CpLeaveCreate) *CpLeaveCreateBulk {
|
||||
return &CpLeaveCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *CpLeaveClient) MapCreateBulk(slice any, setFunc func(*CpLeaveCreate, int)) *CpLeaveCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &CpLeaveCreateBulk{err: fmt.Errorf("calling to CpLeaveClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*CpLeaveCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &CpLeaveCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for CpLeave.
|
||||
func (c *CpLeaveClient) Update() *CpLeaveUpdate {
|
||||
mutation := newCpLeaveMutation(c.config, OpUpdate)
|
||||
return &CpLeaveUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *CpLeaveClient) UpdateOne(_m *CpLeave) *CpLeaveUpdateOne {
|
||||
mutation := newCpLeaveMutation(c.config, OpUpdateOne, withCpLeave(_m))
|
||||
return &CpLeaveUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *CpLeaveClient) UpdateOneID(id int64) *CpLeaveUpdateOne {
|
||||
mutation := newCpLeaveMutation(c.config, OpUpdateOne, withCpLeaveID(id))
|
||||
return &CpLeaveUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for CpLeave.
|
||||
func (c *CpLeaveClient) Delete() *CpLeaveDelete {
|
||||
mutation := newCpLeaveMutation(c.config, OpDelete)
|
||||
return &CpLeaveDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *CpLeaveClient) DeleteOne(_m *CpLeave) *CpLeaveDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *CpLeaveClient) DeleteOneID(id int64) *CpLeaveDeleteOne {
|
||||
builder := c.Delete().Where(cpleave.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &CpLeaveDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for CpLeave.
|
||||
func (c *CpLeaveClient) Query() *CpLeaveQuery {
|
||||
return &CpLeaveQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeCpLeave},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a CpLeave entity by its id.
|
||||
func (c *CpLeaveClient) Get(ctx context.Context, id int64) (*CpLeave, error) {
|
||||
return c.Query().Where(cpleave.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *CpLeaveClient) GetX(ctx context.Context, id int64) *CpLeave {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryCpUser queries the cp_user edge of a CpLeave.
|
||||
func (c *CpLeaveClient) QueryCpUser(_m *CpLeave) *CpUserQuery {
|
||||
query := (&CpUserClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(cpleave.Table, cpleave.FieldID, id),
|
||||
sqlgraph.To(cpuser.Table, cpuser.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, cpleave.CpUserTable, cpleave.CpUserColumn),
|
||||
)
|
||||
schemaConfig := _m.schemaConfig
|
||||
step.To.Schema = schemaConfig.CpUser
|
||||
step.Edge.Schema = schemaConfig.CpLeave
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QuerySysUser queries the sys_user edge of a CpLeave.
|
||||
func (c *CpLeaveClient) QuerySysUser(_m *CpLeave) *SysUserQuery {
|
||||
query := (&SysUserClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(cpleave.Table, cpleave.FieldID, id),
|
||||
sqlgraph.To(sysuser.Table, sysuser.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, cpleave.SysUserTable, cpleave.SysUserColumn),
|
||||
)
|
||||
schemaConfig := _m.schemaConfig
|
||||
step.To.Schema = schemaConfig.SysUser
|
||||
step.Edge.Schema = schemaConfig.CpLeave
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *CpLeaveClient) Hooks() []Hook {
|
||||
hooks := c.hooks.CpLeave
|
||||
return append(hooks[:len(hooks):len(hooks)], cpleave.Hooks[:]...)
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *CpLeaveClient) Interceptors() []Interceptor {
|
||||
return c.inters.CpLeave
|
||||
}
|
||||
|
||||
func (c *CpLeaveClient) mutate(ctx context.Context, m *CpLeaveMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&CpLeaveCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&CpLeaveUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&CpLeaveUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&CpLeaveDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown CpLeave mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// CpSchoolClient is a client for the CpSchool schema.
|
||||
type CpSchoolClient struct {
|
||||
config
|
||||
@@ -1108,6 +1467,25 @@ func (c *CpUserClient) QueryCptasks(_m *CpUser) *CpTaskQuery {
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryCpLeave queries the cp_leave edge of a CpUser.
|
||||
func (c *CpUserClient) QueryCpLeave(_m *CpUser) *CpLeaveQuery {
|
||||
query := (&CpLeaveClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(cpuser.Table, cpuser.FieldID, id),
|
||||
sqlgraph.To(cpleave.Table, cpleave.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, cpuser.CpLeaveTable, cpuser.CpLeaveColumn),
|
||||
)
|
||||
schemaConfig := _m.schemaConfig
|
||||
step.To.Schema = schemaConfig.CpLeave
|
||||
step.Edge.Schema = schemaConfig.CpLeave
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QuerySysuser queries the sysuser edge of a CpUser.
|
||||
func (c *CpUserClient) QuerySysuser(_m *CpUser) *SysUserQuery {
|
||||
query := (&SysUserClient{config: c.config}).Query()
|
||||
@@ -1344,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
|
||||
@@ -1535,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
|
||||
@@ -2139,6 +2804,44 @@ func (c *SysUserClient) QueryCpTask(_m *SysUser) *CpTaskQuery {
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryCpLeave queries the cp_leave edge of a SysUser.
|
||||
func (c *SysUserClient) QueryCpLeave(_m *SysUser) *CpLeaveQuery {
|
||||
query := (&CpLeaveClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(sysuser.Table, sysuser.FieldID, id),
|
||||
sqlgraph.To(cpleave.Table, cpleave.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, sysuser.CpLeaveTable, sysuser.CpLeaveColumn),
|
||||
)
|
||||
schemaConfig := _m.schemaConfig
|
||||
step.To.Schema = schemaConfig.CpLeave
|
||||
step.Edge.Schema = schemaConfig.CpLeave
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryCourseEntity queries the course_entity edge of a SysUser.
|
||||
func (c *SysUserClient) QueryCourseEntity(_m *SysUser) *CourseEntityQuery {
|
||||
query := (&CourseEntityClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(sysuser.Table, sysuser.FieldID, id),
|
||||
sqlgraph.To(courseentity.Table, courseentity.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, sysuser.CourseEntityTable, sysuser.CourseEntityColumn),
|
||||
)
|
||||
schemaConfig := _m.schemaConfig
|
||||
step.To.Schema = schemaConfig.CourseEntity
|
||||
step.Edge.Schema = schemaConfig.CourseEntity
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryCpTaskLogs queries the cp_task_logs edge of a SysUser.
|
||||
func (c *SysUserClient) QueryCpTaskLogs(_m *SysUser) *CpTaskLogQuery {
|
||||
query := (&CpTaskLogClient{config: c.config}).Query()
|
||||
@@ -2215,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
|
||||
@@ -2377,12 +3099,14 @@ func (c *SysUserLogClient) mutate(ctx context.Context, m *SysUserLogMutation) (V
|
||||
// hooks and interceptors per client, for fast access.
|
||||
type (
|
||||
hooks struct {
|
||||
CpImage, CpSchool, CpTask, CpTaskLog, CpUser, SysAgent, SysCard, SysMenu,
|
||||
SysRole, SysUser, SysUserLog []ent.Hook
|
||||
CourseEntity, CpImage, CpLeave, CpSchool, CpTask, CpTaskLog, CpUser, SysAgent,
|
||||
SysBalanceRecord, SysCard, SysConfig, SysMenu, SysRole, SysUser,
|
||||
SysUserLog []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
CpImage, CpSchool, CpTask, CpTaskLog, CpUser, SysAgent, SysCard, SysMenu,
|
||||
SysRole, SysUser, SysUserLog []ent.Interceptor
|
||||
CourseEntity, CpImage, CpLeave, CpSchool, CpTask, CpTaskLog, CpUser, SysAgent,
|
||||
SysBalanceRecord, SysCard, SysConfig, SysMenu, SysRole, SysUser,
|
||||
SysUserLog []ent.Interceptor
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,310 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/courseentity"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// CourseEntity is the model entity for the CourseEntity schema.
|
||||
type CourseEntity 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"`
|
||||
// UserID holds the value of the "user_id" field.
|
||||
UserID int64 `json:"user_id,omitempty"`
|
||||
// Username holds the value of the "username" field.
|
||||
Username string `json:"username,omitempty"`
|
||||
// Password holds the value of the "password" field.
|
||||
Password string `json:"-"`
|
||||
// Type holds the value of the "type" field.
|
||||
Type courseentity.Type `json:"type,omitempty"`
|
||||
// CourseName holds the value of the "course_name" field.
|
||||
CourseName string `json:"course_name,omitempty"`
|
||||
// CourseID holds the value of the "course_id" field.
|
||||
CourseID string `json:"course_id,omitempty"`
|
||||
// Need holds the value of the "need" field.
|
||||
Need courseentity.Need `json:"need,omitempty"`
|
||||
// Status holds the value of the "status" field.
|
||||
Status courseentity.Status `json:"status,omitempty"`
|
||||
// TaskCount holds the value of the "task_count" field.
|
||||
TaskCount int `json:"task_count,omitempty"`
|
||||
// SuccessCount holds the value of the "success_count" field.
|
||||
SuccessCount int `json:"success_count,omitempty"`
|
||||
// ExamState holds the value of the "exam_state" field.
|
||||
ExamState courseentity.ExamState `json:"exam_state,omitempty"`
|
||||
// Violence holds the value of the "violence" field.
|
||||
Violence courseentity.Violence `json:"violence,omitempty"`
|
||||
// Nodes holds the value of the "nodes" field.
|
||||
Nodes string `json:"nodes,omitempty"`
|
||||
// CompletedNodes holds the value of the "completed_nodes" field.
|
||||
CompletedNodes string `json:"completed_nodes,omitempty"`
|
||||
// Desc holds the value of the "desc" field.
|
||||
Desc string `json:"desc,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the CourseEntityQuery when eager-loading is set.
|
||||
Edges CourseEntityEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// CourseEntityEdges holds the relations/edges for other nodes in the graph.
|
||||
type CourseEntityEdges struct {
|
||||
// SysUser holds the value of the sys_user edge.
|
||||
SysUser *SysUser `json:"sys_user,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// SysUserOrErr returns the SysUser value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e CourseEntityEdges) SysUserOrErr() (*SysUser, error) {
|
||||
if e.SysUser != nil {
|
||||
return e.SysUser, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: sysuser.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "sys_user"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*CourseEntity) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case courseentity.FieldCreateTime, courseentity.FieldUpdateTime:
|
||||
values[i] = new(ent2.CustomTime)
|
||||
case courseentity.FieldID, courseentity.FieldUserID, courseentity.FieldTaskCount, courseentity.FieldSuccessCount:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case courseentity.FieldUsername, courseentity.FieldPassword, courseentity.FieldType, courseentity.FieldCourseName, courseentity.FieldCourseID, courseentity.FieldNeed, courseentity.FieldStatus, courseentity.FieldExamState, courseentity.FieldViolence, courseentity.FieldNodes, courseentity.FieldCompletedNodes, courseentity.FieldDesc:
|
||||
values[i] = new(sql.NullString)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the CourseEntity fields.
|
||||
func (_m *CourseEntity) 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 courseentity.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 courseentity.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 courseentity.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 courseentity.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 courseentity.FieldUsername:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field username", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Username = value.String
|
||||
}
|
||||
case courseentity.FieldPassword:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field password", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Password = value.String
|
||||
}
|
||||
case courseentity.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 = courseentity.Type(value.String)
|
||||
}
|
||||
case courseentity.FieldCourseName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field course_name", values[i])
|
||||
} else if value.Valid {
|
||||
_m.CourseName = value.String
|
||||
}
|
||||
case courseentity.FieldCourseID:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field course_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.CourseID = value.String
|
||||
}
|
||||
case courseentity.FieldNeed:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field need", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Need = courseentity.Need(value.String)
|
||||
}
|
||||
case courseentity.FieldStatus:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field status", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Status = courseentity.Status(value.String)
|
||||
}
|
||||
case courseentity.FieldTaskCount:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field task_count", values[i])
|
||||
} else if value.Valid {
|
||||
_m.TaskCount = int(value.Int64)
|
||||
}
|
||||
case courseentity.FieldSuccessCount:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field success_count", values[i])
|
||||
} else if value.Valid {
|
||||
_m.SuccessCount = int(value.Int64)
|
||||
}
|
||||
case courseentity.FieldExamState:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field exam_state", values[i])
|
||||
} else if value.Valid {
|
||||
_m.ExamState = courseentity.ExamState(value.String)
|
||||
}
|
||||
case courseentity.FieldViolence:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field violence", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Violence = courseentity.Violence(value.String)
|
||||
}
|
||||
case courseentity.FieldNodes:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field nodes", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Nodes = value.String
|
||||
}
|
||||
case courseentity.FieldCompletedNodes:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field completed_nodes", values[i])
|
||||
} else if value.Valid {
|
||||
_m.CompletedNodes = value.String
|
||||
}
|
||||
case courseentity.FieldDesc:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field desc", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Desc = value.String
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the CourseEntity.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *CourseEntity) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QuerySysUser queries the "sys_user" edge of the CourseEntity entity.
|
||||
func (_m *CourseEntity) QuerySysUser() *SysUserQuery {
|
||||
return NewCourseEntityClient(_m.config).QuerySysUser(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this CourseEntity.
|
||||
// Note that you need to call CourseEntity.Unwrap() before calling this method if this CourseEntity
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *CourseEntity) Update() *CourseEntityUpdateOne {
|
||||
return NewCourseEntityClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the CourseEntity 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 *CourseEntity) Unwrap() *CourseEntity {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: CourseEntity is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *CourseEntity) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("CourseEntity(")
|
||||
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("username=")
|
||||
builder.WriteString(_m.Username)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("password=<sensitive>")
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("type=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Type))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("course_name=")
|
||||
builder.WriteString(_m.CourseName)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("course_id=")
|
||||
builder.WriteString(_m.CourseID)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("need=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Need))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("status=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Status))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("task_count=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.TaskCount))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("success_count=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.SuccessCount))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("exam_state=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.ExamState))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("violence=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Violence))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("nodes=")
|
||||
builder.WriteString(_m.Nodes)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("completed_nodes=")
|
||||
builder.WriteString(_m.CompletedNodes)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("desc=")
|
||||
builder.WriteString(_m.Desc)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// CourseEntities is a parsable slice of CourseEntity.
|
||||
type CourseEntities []*CourseEntity
|
||||
@@ -0,0 +1,351 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package courseentity
|
||||
|
||||
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 courseentity type in the database.
|
||||
Label = "course_entity"
|
||||
// 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"
|
||||
// FieldUsername holds the string denoting the username field in the database.
|
||||
FieldUsername = "username"
|
||||
// FieldPassword holds the string denoting the password field in the database.
|
||||
FieldPassword = "password"
|
||||
// FieldType holds the string denoting the type field in the database.
|
||||
FieldType = "type"
|
||||
// FieldCourseName holds the string denoting the course_name field in the database.
|
||||
FieldCourseName = "course_name"
|
||||
// FieldCourseID holds the string denoting the course_id field in the database.
|
||||
FieldCourseID = "course_id"
|
||||
// FieldNeed holds the string denoting the need field in the database.
|
||||
FieldNeed = "need"
|
||||
// FieldStatus holds the string denoting the status field in the database.
|
||||
FieldStatus = "status"
|
||||
// FieldTaskCount holds the string denoting the task_count field in the database.
|
||||
FieldTaskCount = "task_count"
|
||||
// FieldSuccessCount holds the string denoting the success_count field in the database.
|
||||
FieldSuccessCount = "success_count"
|
||||
// FieldExamState holds the string denoting the exam_state field in the database.
|
||||
FieldExamState = "exam_state"
|
||||
// FieldViolence holds the string denoting the violence field in the database.
|
||||
FieldViolence = "violence"
|
||||
// FieldNodes holds the string denoting the nodes field in the database.
|
||||
FieldNodes = "nodes"
|
||||
// FieldCompletedNodes holds the string denoting the completed_nodes field in the database.
|
||||
FieldCompletedNodes = "completed_nodes"
|
||||
// FieldDesc holds the string denoting the desc field in the database.
|
||||
FieldDesc = "desc"
|
||||
// EdgeSysUser holds the string denoting the sys_user edge name in mutations.
|
||||
EdgeSysUser = "sys_user"
|
||||
// Table holds the table name of the courseentity in the database.
|
||||
Table = "course_entity"
|
||||
// SysUserTable is the table that holds the sys_user relation/edge.
|
||||
SysUserTable = "course_entity"
|
||||
// SysUserInverseTable is the table name for the SysUser entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "sysuser" package.
|
||||
SysUserInverseTable = "sys_user"
|
||||
// SysUserColumn is the table column denoting the sys_user relation/edge.
|
||||
SysUserColumn = "user_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for courseentity fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldCreateTime,
|
||||
FieldUpdateTime,
|
||||
FieldUserID,
|
||||
FieldUsername,
|
||||
FieldPassword,
|
||||
FieldType,
|
||||
FieldCourseName,
|
||||
FieldCourseID,
|
||||
FieldNeed,
|
||||
FieldStatus,
|
||||
FieldTaskCount,
|
||||
FieldSuccessCount,
|
||||
FieldExamState,
|
||||
FieldViolence,
|
||||
FieldNodes,
|
||||
FieldCompletedNodes,
|
||||
FieldDesc,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Note that the variables below are initialized by the runtime
|
||||
// package on the initialization of the application. Therefore,
|
||||
// it should be imported in the main as follows:
|
||||
//
|
||||
// import _ "likedream-goframe/internal/ent/runtime"
|
||||
var (
|
||||
Hooks [1]ent.Hook
|
||||
// DefaultCreateTime holds the default value on creation for the "create_time" field.
|
||||
DefaultCreateTime func() *ent2.CustomTime
|
||||
// DefaultUpdateTime holds the default value on creation for the "update_time" field.
|
||||
DefaultUpdateTime func() *ent2.CustomTime
|
||||
// DefaultTaskCount holds the default value on creation for the "task_count" field.
|
||||
DefaultTaskCount int
|
||||
// DefaultSuccessCount holds the default value on creation for the "success_count" field.
|
||||
DefaultSuccessCount int
|
||||
)
|
||||
|
||||
// Type defines the type for the "type" enum field.
|
||||
type Type string
|
||||
|
||||
// Type values.
|
||||
const (
|
||||
TypeXxt Type = "xxt"
|
||||
)
|
||||
|
||||
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 TypeXxt:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("courseentity: invalid enum value for type field: %q", _type)
|
||||
}
|
||||
}
|
||||
|
||||
// Need defines the type for the "need" enum field.
|
||||
type Need string
|
||||
|
||||
// Need values.
|
||||
const (
|
||||
NeedTask Need = "task"
|
||||
NeedExam Need = "exam"
|
||||
NeedAll Need = "all"
|
||||
)
|
||||
|
||||
func (n Need) String() string {
|
||||
return string(n)
|
||||
}
|
||||
|
||||
// NeedValidator is a validator for the "need" field enum values. It is called by the builders before save.
|
||||
func NeedValidator(n Need) error {
|
||||
switch n {
|
||||
case NeedTask, NeedExam, NeedAll:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("courseentity: invalid enum value for need field: %q", n)
|
||||
}
|
||||
}
|
||||
|
||||
// Status defines the type for the "status" enum field.
|
||||
type Status string
|
||||
|
||||
// StatusNotStart is the default value of the Status enum.
|
||||
const DefaultStatus = StatusNotStart
|
||||
|
||||
// Status values.
|
||||
const (
|
||||
StatusNotStart Status = "not_start"
|
||||
StatusWaiting Status = "waiting"
|
||||
StatusDoing Status = "doing"
|
||||
StatusDone Status = "done"
|
||||
StatusFail Status = "fail"
|
||||
StatusPause Status = "pause"
|
||||
)
|
||||
|
||||
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 StatusNotStart, StatusWaiting, StatusDoing, StatusDone, StatusFail, StatusPause:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("courseentity: invalid enum value for status field: %q", s)
|
||||
}
|
||||
}
|
||||
|
||||
// ExamState defines the type for the "exam_state" enum field.
|
||||
type ExamState string
|
||||
|
||||
// ExamStateNotStart is the default value of the ExamState enum.
|
||||
const DefaultExamState = ExamStateNotStart
|
||||
|
||||
// ExamState values.
|
||||
const (
|
||||
ExamStateNotStart ExamState = "not_start"
|
||||
ExamStateWaiting ExamState = "waiting"
|
||||
ExamStateDoing ExamState = "doing"
|
||||
ExamStateDone ExamState = "done"
|
||||
ExamStateFail ExamState = "fail"
|
||||
)
|
||||
|
||||
func (es ExamState) String() string {
|
||||
return string(es)
|
||||
}
|
||||
|
||||
// ExamStateValidator is a validator for the "exam_state" field enum values. It is called by the builders before save.
|
||||
func ExamStateValidator(es ExamState) error {
|
||||
switch es {
|
||||
case ExamStateNotStart, ExamStateWaiting, ExamStateDoing, ExamStateDone, ExamStateFail:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("courseentity: invalid enum value for exam_state field: %q", es)
|
||||
}
|
||||
}
|
||||
|
||||
// Violence defines the type for the "violence" enum field.
|
||||
type Violence string
|
||||
|
||||
// ViolenceNo is the default value of the Violence enum.
|
||||
const DefaultViolence = ViolenceNo
|
||||
|
||||
// Violence values.
|
||||
const (
|
||||
ViolenceNo Violence = "no"
|
||||
ViolenceYes Violence = "yes"
|
||||
)
|
||||
|
||||
func (v Violence) String() string {
|
||||
return string(v)
|
||||
}
|
||||
|
||||
// ViolenceValidator is a validator for the "violence" field enum values. It is called by the builders before save.
|
||||
func ViolenceValidator(v Violence) error {
|
||||
switch v {
|
||||
case ViolenceNo, ViolenceYes:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("courseentity: invalid enum value for violence field: %q", v)
|
||||
}
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the CourseEntity 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()
|
||||
}
|
||||
|
||||
// ByUsername orders the results by the username field.
|
||||
func ByUsername(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUsername, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByPassword orders the results by the password field.
|
||||
func ByPassword(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldPassword, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByType orders the results by the type field.
|
||||
func ByType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldType, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCourseName orders the results by the course_name field.
|
||||
func ByCourseName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCourseName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCourseID orders the results by the course_id field.
|
||||
func ByCourseID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCourseID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByNeed orders the results by the need field.
|
||||
func ByNeed(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldNeed, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByStatus orders the results by the status field.
|
||||
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByTaskCount orders the results by the task_count field.
|
||||
func ByTaskCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTaskCount, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// BySuccessCount orders the results by the success_count field.
|
||||
func BySuccessCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldSuccessCount, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByExamState orders the results by the exam_state field.
|
||||
func ByExamState(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldExamState, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByViolence orders the results by the violence field.
|
||||
func ByViolence(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldViolence, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByNodes orders the results by the nodes field.
|
||||
func ByNodes(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldNodes, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCompletedNodes orders the results by the completed_nodes field.
|
||||
func ByCompletedNodes(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCompletedNodes, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByDesc orders the results by the desc field.
|
||||
func ByDesc(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDesc, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// BySysUserField orders the results by sys_user field.
|
||||
func BySysUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newSysUserStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newSysUserStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(SysUserInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, SysUserTable, SysUserColumn),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,986 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package courseentity
|
||||
|
||||
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.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int64) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int64) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int64) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int64) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int64) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int64) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int64) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int64) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(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.CourseEntity {
|
||||
return predicate.CourseEntity(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.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
|
||||
func UserID(v int64) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// Username applies equality check predicate on the "username" field. It's identical to UsernameEQ.
|
||||
func Username(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldUsername, v))
|
||||
}
|
||||
|
||||
// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ.
|
||||
func Password(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldPassword, v))
|
||||
}
|
||||
|
||||
// CourseName applies equality check predicate on the "course_name" field. It's identical to CourseNameEQ.
|
||||
func CourseName(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldCourseName, v))
|
||||
}
|
||||
|
||||
// CourseID applies equality check predicate on the "course_id" field. It's identical to CourseIDEQ.
|
||||
func CourseID(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldCourseID, v))
|
||||
}
|
||||
|
||||
// TaskCount applies equality check predicate on the "task_count" field. It's identical to TaskCountEQ.
|
||||
func TaskCount(v int) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldTaskCount, v))
|
||||
}
|
||||
|
||||
// SuccessCount applies equality check predicate on the "success_count" field. It's identical to SuccessCountEQ.
|
||||
func SuccessCount(v int) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldSuccessCount, v))
|
||||
}
|
||||
|
||||
// Nodes applies equality check predicate on the "nodes" field. It's identical to NodesEQ.
|
||||
func Nodes(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldNodes, v))
|
||||
}
|
||||
|
||||
// CompletedNodes applies equality check predicate on the "completed_nodes" field. It's identical to CompletedNodesEQ.
|
||||
func CompletedNodes(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldCompletedNodes, v))
|
||||
}
|
||||
|
||||
// Desc applies equality check predicate on the "desc" field. It's identical to DescEQ.
|
||||
func Desc(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldDesc, v))
|
||||
}
|
||||
|
||||
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||
func CreateTimeEQ(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||
func CreateTimeNEQ(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||
func CreateTimeIn(vs ...*ent2.CustomTime) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||
func CreateTimeNotIn(vs ...*ent2.CustomTime) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||
func CreateTimeGT(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||
func CreateTimeGTE(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||
func CreateTimeLT(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||
func CreateTimeLTE(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeContains applies the Contains predicate on the "create_time" field.
|
||||
func CreateTimeContains(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
vc := v.String()
|
||||
return predicate.CourseEntity(sql.FieldContains(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeHasPrefix applies the HasPrefix predicate on the "create_time" field.
|
||||
func CreateTimeHasPrefix(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
vc := v.String()
|
||||
return predicate.CourseEntity(sql.FieldHasPrefix(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeHasSuffix applies the HasSuffix predicate on the "create_time" field.
|
||||
func CreateTimeHasSuffix(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
vc := v.String()
|
||||
return predicate.CourseEntity(sql.FieldHasSuffix(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeEqualFold applies the EqualFold predicate on the "create_time" field.
|
||||
func CreateTimeEqualFold(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
vc := v.String()
|
||||
return predicate.CourseEntity(sql.FieldEqualFold(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeContainsFold applies the ContainsFold predicate on the "create_time" field.
|
||||
func CreateTimeContainsFold(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
vc := v.String()
|
||||
return predicate.CourseEntity(sql.FieldContainsFold(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeEQ applies the EQ predicate on the "update_time" field.
|
||||
func UpdateTimeEQ(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeNEQ applies the NEQ predicate on the "update_time" field.
|
||||
func UpdateTimeNEQ(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeIn applies the In predicate on the "update_time" field.
|
||||
func UpdateTimeIn(vs ...*ent2.CustomTime) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIn(FieldUpdateTime, vs...))
|
||||
}
|
||||
|
||||
// UpdateTimeNotIn applies the NotIn predicate on the "update_time" field.
|
||||
func UpdateTimeNotIn(vs ...*ent2.CustomTime) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotIn(FieldUpdateTime, vs...))
|
||||
}
|
||||
|
||||
// UpdateTimeGT applies the GT predicate on the "update_time" field.
|
||||
func UpdateTimeGT(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGT(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeGTE applies the GTE predicate on the "update_time" field.
|
||||
func UpdateTimeGTE(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGTE(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeLT applies the LT predicate on the "update_time" field.
|
||||
func UpdateTimeLT(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLT(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeLTE applies the LTE predicate on the "update_time" field.
|
||||
func UpdateTimeLTE(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLTE(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeContains applies the Contains predicate on the "update_time" field.
|
||||
func UpdateTimeContains(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
vc := v.String()
|
||||
return predicate.CourseEntity(sql.FieldContains(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeHasPrefix applies the HasPrefix predicate on the "update_time" field.
|
||||
func UpdateTimeHasPrefix(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
vc := v.String()
|
||||
return predicate.CourseEntity(sql.FieldHasPrefix(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeHasSuffix applies the HasSuffix predicate on the "update_time" field.
|
||||
func UpdateTimeHasSuffix(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
vc := v.String()
|
||||
return predicate.CourseEntity(sql.FieldHasSuffix(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeEqualFold applies the EqualFold predicate on the "update_time" field.
|
||||
func UpdateTimeEqualFold(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
vc := v.String()
|
||||
return predicate.CourseEntity(sql.FieldEqualFold(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeContainsFold applies the ContainsFold predicate on the "update_time" field.
|
||||
func UpdateTimeContainsFold(v *ent2.CustomTime) predicate.CourseEntity {
|
||||
vc := v.String()
|
||||
return predicate.CourseEntity(sql.FieldContainsFold(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UserIDEQ applies the EQ predicate on the "user_id" field.
|
||||
func UserIDEQ(v int64) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
|
||||
func UserIDNEQ(v int64) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDIn applies the In predicate on the "user_id" field.
|
||||
func UserIDIn(vs ...int64) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
|
||||
func UserIDNotIn(vs ...int64) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// UsernameEQ applies the EQ predicate on the "username" field.
|
||||
func UsernameEQ(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameNEQ applies the NEQ predicate on the "username" field.
|
||||
func UsernameNEQ(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNEQ(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameIn applies the In predicate on the "username" field.
|
||||
func UsernameIn(vs ...string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIn(FieldUsername, vs...))
|
||||
}
|
||||
|
||||
// UsernameNotIn applies the NotIn predicate on the "username" field.
|
||||
func UsernameNotIn(vs ...string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotIn(FieldUsername, vs...))
|
||||
}
|
||||
|
||||
// UsernameGT applies the GT predicate on the "username" field.
|
||||
func UsernameGT(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGT(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameGTE applies the GTE predicate on the "username" field.
|
||||
func UsernameGTE(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGTE(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameLT applies the LT predicate on the "username" field.
|
||||
func UsernameLT(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLT(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameLTE applies the LTE predicate on the "username" field.
|
||||
func UsernameLTE(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLTE(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameContains applies the Contains predicate on the "username" field.
|
||||
func UsernameContains(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldContains(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameHasPrefix applies the HasPrefix predicate on the "username" field.
|
||||
func UsernameHasPrefix(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldHasPrefix(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameHasSuffix applies the HasSuffix predicate on the "username" field.
|
||||
func UsernameHasSuffix(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldHasSuffix(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameEqualFold applies the EqualFold predicate on the "username" field.
|
||||
func UsernameEqualFold(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEqualFold(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameContainsFold applies the ContainsFold predicate on the "username" field.
|
||||
func UsernameContainsFold(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldContainsFold(FieldUsername, v))
|
||||
}
|
||||
|
||||
// PasswordEQ applies the EQ predicate on the "password" field.
|
||||
func PasswordEQ(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordNEQ applies the NEQ predicate on the "password" field.
|
||||
func PasswordNEQ(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNEQ(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordIn applies the In predicate on the "password" field.
|
||||
func PasswordIn(vs ...string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIn(FieldPassword, vs...))
|
||||
}
|
||||
|
||||
// PasswordNotIn applies the NotIn predicate on the "password" field.
|
||||
func PasswordNotIn(vs ...string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotIn(FieldPassword, vs...))
|
||||
}
|
||||
|
||||
// PasswordGT applies the GT predicate on the "password" field.
|
||||
func PasswordGT(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGT(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordGTE applies the GTE predicate on the "password" field.
|
||||
func PasswordGTE(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGTE(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordLT applies the LT predicate on the "password" field.
|
||||
func PasswordLT(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLT(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordLTE applies the LTE predicate on the "password" field.
|
||||
func PasswordLTE(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLTE(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordContains applies the Contains predicate on the "password" field.
|
||||
func PasswordContains(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldContains(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordHasPrefix applies the HasPrefix predicate on the "password" field.
|
||||
func PasswordHasPrefix(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldHasPrefix(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordHasSuffix applies the HasSuffix predicate on the "password" field.
|
||||
func PasswordHasSuffix(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldHasSuffix(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordEqualFold applies the EqualFold predicate on the "password" field.
|
||||
func PasswordEqualFold(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEqualFold(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordContainsFold applies the ContainsFold predicate on the "password" field.
|
||||
func PasswordContainsFold(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldContainsFold(FieldPassword, v))
|
||||
}
|
||||
|
||||
// TypeEQ applies the EQ predicate on the "type" field.
|
||||
func TypeEQ(v Type) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeNEQ applies the NEQ predicate on the "type" field.
|
||||
func TypeNEQ(v Type) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeIn applies the In predicate on the "type" field.
|
||||
func TypeIn(vs ...Type) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// TypeNotIn applies the NotIn predicate on the "type" field.
|
||||
func TypeNotIn(vs ...Type) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// CourseNameEQ applies the EQ predicate on the "course_name" field.
|
||||
func CourseNameEQ(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldCourseName, v))
|
||||
}
|
||||
|
||||
// CourseNameNEQ applies the NEQ predicate on the "course_name" field.
|
||||
func CourseNameNEQ(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNEQ(FieldCourseName, v))
|
||||
}
|
||||
|
||||
// CourseNameIn applies the In predicate on the "course_name" field.
|
||||
func CourseNameIn(vs ...string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIn(FieldCourseName, vs...))
|
||||
}
|
||||
|
||||
// CourseNameNotIn applies the NotIn predicate on the "course_name" field.
|
||||
func CourseNameNotIn(vs ...string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotIn(FieldCourseName, vs...))
|
||||
}
|
||||
|
||||
// CourseNameGT applies the GT predicate on the "course_name" field.
|
||||
func CourseNameGT(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGT(FieldCourseName, v))
|
||||
}
|
||||
|
||||
// CourseNameGTE applies the GTE predicate on the "course_name" field.
|
||||
func CourseNameGTE(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGTE(FieldCourseName, v))
|
||||
}
|
||||
|
||||
// CourseNameLT applies the LT predicate on the "course_name" field.
|
||||
func CourseNameLT(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLT(FieldCourseName, v))
|
||||
}
|
||||
|
||||
// CourseNameLTE applies the LTE predicate on the "course_name" field.
|
||||
func CourseNameLTE(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLTE(FieldCourseName, v))
|
||||
}
|
||||
|
||||
// CourseNameContains applies the Contains predicate on the "course_name" field.
|
||||
func CourseNameContains(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldContains(FieldCourseName, v))
|
||||
}
|
||||
|
||||
// CourseNameHasPrefix applies the HasPrefix predicate on the "course_name" field.
|
||||
func CourseNameHasPrefix(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldHasPrefix(FieldCourseName, v))
|
||||
}
|
||||
|
||||
// CourseNameHasSuffix applies the HasSuffix predicate on the "course_name" field.
|
||||
func CourseNameHasSuffix(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldHasSuffix(FieldCourseName, v))
|
||||
}
|
||||
|
||||
// CourseNameEqualFold applies the EqualFold predicate on the "course_name" field.
|
||||
func CourseNameEqualFold(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEqualFold(FieldCourseName, v))
|
||||
}
|
||||
|
||||
// CourseNameContainsFold applies the ContainsFold predicate on the "course_name" field.
|
||||
func CourseNameContainsFold(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldContainsFold(FieldCourseName, v))
|
||||
}
|
||||
|
||||
// CourseIDEQ applies the EQ predicate on the "course_id" field.
|
||||
func CourseIDEQ(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldCourseID, v))
|
||||
}
|
||||
|
||||
// CourseIDNEQ applies the NEQ predicate on the "course_id" field.
|
||||
func CourseIDNEQ(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNEQ(FieldCourseID, v))
|
||||
}
|
||||
|
||||
// CourseIDIn applies the In predicate on the "course_id" field.
|
||||
func CourseIDIn(vs ...string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIn(FieldCourseID, vs...))
|
||||
}
|
||||
|
||||
// CourseIDNotIn applies the NotIn predicate on the "course_id" field.
|
||||
func CourseIDNotIn(vs ...string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotIn(FieldCourseID, vs...))
|
||||
}
|
||||
|
||||
// CourseIDGT applies the GT predicate on the "course_id" field.
|
||||
func CourseIDGT(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGT(FieldCourseID, v))
|
||||
}
|
||||
|
||||
// CourseIDGTE applies the GTE predicate on the "course_id" field.
|
||||
func CourseIDGTE(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGTE(FieldCourseID, v))
|
||||
}
|
||||
|
||||
// CourseIDLT applies the LT predicate on the "course_id" field.
|
||||
func CourseIDLT(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLT(FieldCourseID, v))
|
||||
}
|
||||
|
||||
// CourseIDLTE applies the LTE predicate on the "course_id" field.
|
||||
func CourseIDLTE(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLTE(FieldCourseID, v))
|
||||
}
|
||||
|
||||
// CourseIDContains applies the Contains predicate on the "course_id" field.
|
||||
func CourseIDContains(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldContains(FieldCourseID, v))
|
||||
}
|
||||
|
||||
// CourseIDHasPrefix applies the HasPrefix predicate on the "course_id" field.
|
||||
func CourseIDHasPrefix(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldHasPrefix(FieldCourseID, v))
|
||||
}
|
||||
|
||||
// CourseIDHasSuffix applies the HasSuffix predicate on the "course_id" field.
|
||||
func CourseIDHasSuffix(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldHasSuffix(FieldCourseID, v))
|
||||
}
|
||||
|
||||
// CourseIDEqualFold applies the EqualFold predicate on the "course_id" field.
|
||||
func CourseIDEqualFold(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEqualFold(FieldCourseID, v))
|
||||
}
|
||||
|
||||
// CourseIDContainsFold applies the ContainsFold predicate on the "course_id" field.
|
||||
func CourseIDContainsFold(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldContainsFold(FieldCourseID, v))
|
||||
}
|
||||
|
||||
// NeedEQ applies the EQ predicate on the "need" field.
|
||||
func NeedEQ(v Need) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldNeed, v))
|
||||
}
|
||||
|
||||
// NeedNEQ applies the NEQ predicate on the "need" field.
|
||||
func NeedNEQ(v Need) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNEQ(FieldNeed, v))
|
||||
}
|
||||
|
||||
// NeedIn applies the In predicate on the "need" field.
|
||||
func NeedIn(vs ...Need) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIn(FieldNeed, vs...))
|
||||
}
|
||||
|
||||
// NeedNotIn applies the NotIn predicate on the "need" field.
|
||||
func NeedNotIn(vs ...Need) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotIn(FieldNeed, vs...))
|
||||
}
|
||||
|
||||
// StatusEQ applies the EQ predicate on the "status" field.
|
||||
func StatusEQ(v Status) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusNEQ applies the NEQ predicate on the "status" field.
|
||||
func StatusNEQ(v Status) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNEQ(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusIn applies the In predicate on the "status" field.
|
||||
func StatusIn(vs ...Status) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIn(FieldStatus, vs...))
|
||||
}
|
||||
|
||||
// StatusNotIn applies the NotIn predicate on the "status" field.
|
||||
func StatusNotIn(vs ...Status) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotIn(FieldStatus, vs...))
|
||||
}
|
||||
|
||||
// TaskCountEQ applies the EQ predicate on the "task_count" field.
|
||||
func TaskCountEQ(v int) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldTaskCount, v))
|
||||
}
|
||||
|
||||
// TaskCountNEQ applies the NEQ predicate on the "task_count" field.
|
||||
func TaskCountNEQ(v int) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNEQ(FieldTaskCount, v))
|
||||
}
|
||||
|
||||
// TaskCountIn applies the In predicate on the "task_count" field.
|
||||
func TaskCountIn(vs ...int) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIn(FieldTaskCount, vs...))
|
||||
}
|
||||
|
||||
// TaskCountNotIn applies the NotIn predicate on the "task_count" field.
|
||||
func TaskCountNotIn(vs ...int) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotIn(FieldTaskCount, vs...))
|
||||
}
|
||||
|
||||
// TaskCountGT applies the GT predicate on the "task_count" field.
|
||||
func TaskCountGT(v int) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGT(FieldTaskCount, v))
|
||||
}
|
||||
|
||||
// TaskCountGTE applies the GTE predicate on the "task_count" field.
|
||||
func TaskCountGTE(v int) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGTE(FieldTaskCount, v))
|
||||
}
|
||||
|
||||
// TaskCountLT applies the LT predicate on the "task_count" field.
|
||||
func TaskCountLT(v int) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLT(FieldTaskCount, v))
|
||||
}
|
||||
|
||||
// TaskCountLTE applies the LTE predicate on the "task_count" field.
|
||||
func TaskCountLTE(v int) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLTE(FieldTaskCount, v))
|
||||
}
|
||||
|
||||
// SuccessCountEQ applies the EQ predicate on the "success_count" field.
|
||||
func SuccessCountEQ(v int) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldSuccessCount, v))
|
||||
}
|
||||
|
||||
// SuccessCountNEQ applies the NEQ predicate on the "success_count" field.
|
||||
func SuccessCountNEQ(v int) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNEQ(FieldSuccessCount, v))
|
||||
}
|
||||
|
||||
// SuccessCountIn applies the In predicate on the "success_count" field.
|
||||
func SuccessCountIn(vs ...int) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIn(FieldSuccessCount, vs...))
|
||||
}
|
||||
|
||||
// SuccessCountNotIn applies the NotIn predicate on the "success_count" field.
|
||||
func SuccessCountNotIn(vs ...int) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotIn(FieldSuccessCount, vs...))
|
||||
}
|
||||
|
||||
// SuccessCountGT applies the GT predicate on the "success_count" field.
|
||||
func SuccessCountGT(v int) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGT(FieldSuccessCount, v))
|
||||
}
|
||||
|
||||
// SuccessCountGTE applies the GTE predicate on the "success_count" field.
|
||||
func SuccessCountGTE(v int) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGTE(FieldSuccessCount, v))
|
||||
}
|
||||
|
||||
// SuccessCountLT applies the LT predicate on the "success_count" field.
|
||||
func SuccessCountLT(v int) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLT(FieldSuccessCount, v))
|
||||
}
|
||||
|
||||
// SuccessCountLTE applies the LTE predicate on the "success_count" field.
|
||||
func SuccessCountLTE(v int) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLTE(FieldSuccessCount, v))
|
||||
}
|
||||
|
||||
// ExamStateEQ applies the EQ predicate on the "exam_state" field.
|
||||
func ExamStateEQ(v ExamState) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldExamState, v))
|
||||
}
|
||||
|
||||
// ExamStateNEQ applies the NEQ predicate on the "exam_state" field.
|
||||
func ExamStateNEQ(v ExamState) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNEQ(FieldExamState, v))
|
||||
}
|
||||
|
||||
// ExamStateIn applies the In predicate on the "exam_state" field.
|
||||
func ExamStateIn(vs ...ExamState) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIn(FieldExamState, vs...))
|
||||
}
|
||||
|
||||
// ExamStateNotIn applies the NotIn predicate on the "exam_state" field.
|
||||
func ExamStateNotIn(vs ...ExamState) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotIn(FieldExamState, vs...))
|
||||
}
|
||||
|
||||
// ViolenceEQ applies the EQ predicate on the "violence" field.
|
||||
func ViolenceEQ(v Violence) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldViolence, v))
|
||||
}
|
||||
|
||||
// ViolenceNEQ applies the NEQ predicate on the "violence" field.
|
||||
func ViolenceNEQ(v Violence) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNEQ(FieldViolence, v))
|
||||
}
|
||||
|
||||
// ViolenceIn applies the In predicate on the "violence" field.
|
||||
func ViolenceIn(vs ...Violence) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIn(FieldViolence, vs...))
|
||||
}
|
||||
|
||||
// ViolenceNotIn applies the NotIn predicate on the "violence" field.
|
||||
func ViolenceNotIn(vs ...Violence) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotIn(FieldViolence, vs...))
|
||||
}
|
||||
|
||||
// NodesEQ applies the EQ predicate on the "nodes" field.
|
||||
func NodesEQ(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldNodes, v))
|
||||
}
|
||||
|
||||
// NodesNEQ applies the NEQ predicate on the "nodes" field.
|
||||
func NodesNEQ(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNEQ(FieldNodes, v))
|
||||
}
|
||||
|
||||
// NodesIn applies the In predicate on the "nodes" field.
|
||||
func NodesIn(vs ...string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIn(FieldNodes, vs...))
|
||||
}
|
||||
|
||||
// NodesNotIn applies the NotIn predicate on the "nodes" field.
|
||||
func NodesNotIn(vs ...string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotIn(FieldNodes, vs...))
|
||||
}
|
||||
|
||||
// NodesGT applies the GT predicate on the "nodes" field.
|
||||
func NodesGT(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGT(FieldNodes, v))
|
||||
}
|
||||
|
||||
// NodesGTE applies the GTE predicate on the "nodes" field.
|
||||
func NodesGTE(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGTE(FieldNodes, v))
|
||||
}
|
||||
|
||||
// NodesLT applies the LT predicate on the "nodes" field.
|
||||
func NodesLT(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLT(FieldNodes, v))
|
||||
}
|
||||
|
||||
// NodesLTE applies the LTE predicate on the "nodes" field.
|
||||
func NodesLTE(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLTE(FieldNodes, v))
|
||||
}
|
||||
|
||||
// NodesContains applies the Contains predicate on the "nodes" field.
|
||||
func NodesContains(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldContains(FieldNodes, v))
|
||||
}
|
||||
|
||||
// NodesHasPrefix applies the HasPrefix predicate on the "nodes" field.
|
||||
func NodesHasPrefix(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldHasPrefix(FieldNodes, v))
|
||||
}
|
||||
|
||||
// NodesHasSuffix applies the HasSuffix predicate on the "nodes" field.
|
||||
func NodesHasSuffix(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldHasSuffix(FieldNodes, v))
|
||||
}
|
||||
|
||||
// NodesIsNil applies the IsNil predicate on the "nodes" field.
|
||||
func NodesIsNil() predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIsNull(FieldNodes))
|
||||
}
|
||||
|
||||
// NodesNotNil applies the NotNil predicate on the "nodes" field.
|
||||
func NodesNotNil() predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotNull(FieldNodes))
|
||||
}
|
||||
|
||||
// NodesEqualFold applies the EqualFold predicate on the "nodes" field.
|
||||
func NodesEqualFold(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEqualFold(FieldNodes, v))
|
||||
}
|
||||
|
||||
// NodesContainsFold applies the ContainsFold predicate on the "nodes" field.
|
||||
func NodesContainsFold(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldContainsFold(FieldNodes, v))
|
||||
}
|
||||
|
||||
// CompletedNodesEQ applies the EQ predicate on the "completed_nodes" field.
|
||||
func CompletedNodesEQ(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldCompletedNodes, v))
|
||||
}
|
||||
|
||||
// CompletedNodesNEQ applies the NEQ predicate on the "completed_nodes" field.
|
||||
func CompletedNodesNEQ(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNEQ(FieldCompletedNodes, v))
|
||||
}
|
||||
|
||||
// CompletedNodesIn applies the In predicate on the "completed_nodes" field.
|
||||
func CompletedNodesIn(vs ...string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIn(FieldCompletedNodes, vs...))
|
||||
}
|
||||
|
||||
// CompletedNodesNotIn applies the NotIn predicate on the "completed_nodes" field.
|
||||
func CompletedNodesNotIn(vs ...string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotIn(FieldCompletedNodes, vs...))
|
||||
}
|
||||
|
||||
// CompletedNodesGT applies the GT predicate on the "completed_nodes" field.
|
||||
func CompletedNodesGT(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGT(FieldCompletedNodes, v))
|
||||
}
|
||||
|
||||
// CompletedNodesGTE applies the GTE predicate on the "completed_nodes" field.
|
||||
func CompletedNodesGTE(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGTE(FieldCompletedNodes, v))
|
||||
}
|
||||
|
||||
// CompletedNodesLT applies the LT predicate on the "completed_nodes" field.
|
||||
func CompletedNodesLT(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLT(FieldCompletedNodes, v))
|
||||
}
|
||||
|
||||
// CompletedNodesLTE applies the LTE predicate on the "completed_nodes" field.
|
||||
func CompletedNodesLTE(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLTE(FieldCompletedNodes, v))
|
||||
}
|
||||
|
||||
// CompletedNodesContains applies the Contains predicate on the "completed_nodes" field.
|
||||
func CompletedNodesContains(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldContains(FieldCompletedNodes, v))
|
||||
}
|
||||
|
||||
// CompletedNodesHasPrefix applies the HasPrefix predicate on the "completed_nodes" field.
|
||||
func CompletedNodesHasPrefix(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldHasPrefix(FieldCompletedNodes, v))
|
||||
}
|
||||
|
||||
// CompletedNodesHasSuffix applies the HasSuffix predicate on the "completed_nodes" field.
|
||||
func CompletedNodesHasSuffix(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldHasSuffix(FieldCompletedNodes, v))
|
||||
}
|
||||
|
||||
// CompletedNodesIsNil applies the IsNil predicate on the "completed_nodes" field.
|
||||
func CompletedNodesIsNil() predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIsNull(FieldCompletedNodes))
|
||||
}
|
||||
|
||||
// CompletedNodesNotNil applies the NotNil predicate on the "completed_nodes" field.
|
||||
func CompletedNodesNotNil() predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotNull(FieldCompletedNodes))
|
||||
}
|
||||
|
||||
// CompletedNodesEqualFold applies the EqualFold predicate on the "completed_nodes" field.
|
||||
func CompletedNodesEqualFold(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEqualFold(FieldCompletedNodes, v))
|
||||
}
|
||||
|
||||
// CompletedNodesContainsFold applies the ContainsFold predicate on the "completed_nodes" field.
|
||||
func CompletedNodesContainsFold(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldContainsFold(FieldCompletedNodes, v))
|
||||
}
|
||||
|
||||
// DescEQ applies the EQ predicate on the "desc" field.
|
||||
func DescEQ(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEQ(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescNEQ applies the NEQ predicate on the "desc" field.
|
||||
func DescNEQ(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNEQ(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescIn applies the In predicate on the "desc" field.
|
||||
func DescIn(vs ...string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIn(FieldDesc, vs...))
|
||||
}
|
||||
|
||||
// DescNotIn applies the NotIn predicate on the "desc" field.
|
||||
func DescNotIn(vs ...string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotIn(FieldDesc, vs...))
|
||||
}
|
||||
|
||||
// DescGT applies the GT predicate on the "desc" field.
|
||||
func DescGT(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGT(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescGTE applies the GTE predicate on the "desc" field.
|
||||
func DescGTE(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldGTE(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescLT applies the LT predicate on the "desc" field.
|
||||
func DescLT(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLT(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescLTE applies the LTE predicate on the "desc" field.
|
||||
func DescLTE(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldLTE(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescContains applies the Contains predicate on the "desc" field.
|
||||
func DescContains(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldContains(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescHasPrefix applies the HasPrefix predicate on the "desc" field.
|
||||
func DescHasPrefix(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldHasPrefix(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescHasSuffix applies the HasSuffix predicate on the "desc" field.
|
||||
func DescHasSuffix(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldHasSuffix(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescIsNil applies the IsNil predicate on the "desc" field.
|
||||
func DescIsNil() predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldIsNull(FieldDesc))
|
||||
}
|
||||
|
||||
// DescNotNil applies the NotNil predicate on the "desc" field.
|
||||
func DescNotNil() predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldNotNull(FieldDesc))
|
||||
}
|
||||
|
||||
// DescEqualFold applies the EqualFold predicate on the "desc" field.
|
||||
func DescEqualFold(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldEqualFold(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescContainsFold applies the ContainsFold predicate on the "desc" field.
|
||||
func DescContainsFold(v string) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.FieldContainsFold(FieldDesc, v))
|
||||
}
|
||||
|
||||
// HasSysUser applies the HasEdge predicate on the "sys_user" edge.
|
||||
func HasSysUser() predicate.CourseEntity {
|
||||
return predicate.CourseEntity(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, SysUserTable, SysUserColumn),
|
||||
)
|
||||
schemaConfig := internal.SchemaConfigFromContext(s.Context())
|
||||
step.To.Schema = schemaConfig.SysUser
|
||||
step.Edge.Schema = schemaConfig.CourseEntity
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasSysUserWith applies the HasEdge predicate on the "sys_user" edge with a given conditions (other predicates).
|
||||
func HasSysUserWith(preds ...predicate.SysUser) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(func(s *sql.Selector) {
|
||||
step := newSysUserStep()
|
||||
schemaConfig := internal.SchemaConfigFromContext(s.Context())
|
||||
step.To.Schema = schemaConfig.SysUser
|
||||
step.Edge.Schema = schemaConfig.CourseEntity
|
||||
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.CourseEntity) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.CourseEntity) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.CourseEntity) predicate.CourseEntity {
|
||||
return predicate.CourseEntity(sql.NotPredicates(p))
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,91 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"likedream-goframe/internal/ent/courseentity"
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CourseEntityDelete is the builder for deleting a CourseEntity entity.
|
||||
type CourseEntityDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *CourseEntityMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CourseEntityDelete builder.
|
||||
func (_d *CourseEntityDelete) Where(ps ...predicate.CourseEntity) *CourseEntityDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *CourseEntityDelete) 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 *CourseEntityDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *CourseEntityDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(courseentity.Table, sqlgraph.NewFieldSpec(courseentity.FieldID, field.TypeInt64))
|
||||
_spec.Node.Schema = _d.schemaConfig.CourseEntity
|
||||
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
|
||||
}
|
||||
|
||||
// CourseEntityDeleteOne is the builder for deleting a single CourseEntity entity.
|
||||
type CourseEntityDeleteOne struct {
|
||||
_d *CourseEntityDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CourseEntityDelete builder.
|
||||
func (_d *CourseEntityDeleteOne) Where(ps ...predicate.CourseEntity) *CourseEntityDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *CourseEntityDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{courseentity.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *CourseEntityDeleteOne) 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/courseentity"
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CourseEntityQuery is the builder for querying CourseEntity entities.
|
||||
type CourseEntityQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []courseentity.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.CourseEntity
|
||||
withSysUser *SysUserQuery
|
||||
modifiers []func(*sql.Selector)
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the CourseEntityQuery builder.
|
||||
func (_q *CourseEntityQuery) Where(ps ...predicate.CourseEntity) *CourseEntityQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *CourseEntityQuery) Limit(limit int) *CourseEntityQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *CourseEntityQuery) Offset(offset int) *CourseEntityQuery {
|
||||
_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 *CourseEntityQuery) Unique(unique bool) *CourseEntityQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *CourseEntityQuery) Order(o ...courseentity.OrderOption) *CourseEntityQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QuerySysUser chains the current query on the "sys_user" edge.
|
||||
func (_q *CourseEntityQuery) QuerySysUser() *SysUserQuery {
|
||||
query := (&SysUserClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(courseentity.Table, courseentity.FieldID, selector),
|
||||
sqlgraph.To(sysuser.Table, sysuser.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, courseentity.SysUserTable, courseentity.SysUserColumn),
|
||||
)
|
||||
schemaConfig := _q.schemaConfig
|
||||
step.To.Schema = schemaConfig.SysUser
|
||||
step.Edge.Schema = schemaConfig.CourseEntity
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first CourseEntity entity from the query.
|
||||
// Returns a *NotFoundError when no CourseEntity was found.
|
||||
func (_q *CourseEntityQuery) First(ctx context.Context) (*CourseEntity, 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{courseentity.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *CourseEntityQuery) FirstX(ctx context.Context) *CourseEntity {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first CourseEntity ID from the query.
|
||||
// Returns a *NotFoundError when no CourseEntity ID was found.
|
||||
func (_q *CourseEntityQuery) 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{courseentity.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *CourseEntityQuery) FirstIDX(ctx context.Context) int64 {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single CourseEntity entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one CourseEntity entity is found.
|
||||
// Returns a *NotFoundError when no CourseEntity entities are found.
|
||||
func (_q *CourseEntityQuery) Only(ctx context.Context) (*CourseEntity, 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{courseentity.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{courseentity.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *CourseEntityQuery) OnlyX(ctx context.Context) *CourseEntity {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only CourseEntity ID in the query.
|
||||
// Returns a *NotSingularError when more than one CourseEntity ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *CourseEntityQuery) 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{courseentity.Label}
|
||||
default:
|
||||
err = &NotSingularError{courseentity.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *CourseEntityQuery) 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 CourseEntities.
|
||||
func (_q *CourseEntityQuery) All(ctx context.Context) ([]*CourseEntity, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*CourseEntity, *CourseEntityQuery]()
|
||||
return withInterceptors[[]*CourseEntity](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *CourseEntityQuery) AllX(ctx context.Context) []*CourseEntity {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of CourseEntity IDs.
|
||||
func (_q *CourseEntityQuery) 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(courseentity.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *CourseEntityQuery) 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 *CourseEntityQuery) 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[*CourseEntityQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *CourseEntityQuery) 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 *CourseEntityQuery) 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 *CourseEntityQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the CourseEntityQuery 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 *CourseEntityQuery) Clone() *CourseEntityQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &CourseEntityQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]courseentity.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.CourseEntity{}, _q.predicates...),
|
||||
withSysUser: _q.withSysUser.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
modifiers: append([]func(*sql.Selector){}, _q.modifiers...),
|
||||
}
|
||||
}
|
||||
|
||||
// WithSysUser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "sys_user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *CourseEntityQuery) WithSysUser(opts ...func(*SysUserQuery)) *CourseEntityQuery {
|
||||
query := (&SysUserClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withSysUser = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreateTime *ent2.CustomTime `json:"createTime"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.CourseEntity.Query().
|
||||
// GroupBy(courseentity.FieldCreateTime).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *CourseEntityQuery) GroupBy(field string, fields ...string) *CourseEntityGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &CourseEntityGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = courseentity.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.CourseEntity.Query().
|
||||
// Select(courseentity.FieldCreateTime).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *CourseEntityQuery) Select(fields ...string) *CourseEntitySelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &CourseEntitySelect{CourseEntityQuery: _q}
|
||||
sbuild.label = courseentity.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a CourseEntitySelect configured with the given aggregations.
|
||||
func (_q *CourseEntityQuery) Aggregate(fns ...AggregateFunc) *CourseEntitySelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *CourseEntityQuery) 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 !courseentity.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 *CourseEntityQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CourseEntity, error) {
|
||||
var (
|
||||
nodes = []*CourseEntity{}
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
_q.withSysUser != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*CourseEntity).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &CourseEntity{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
_spec.Node.Schema = _q.schemaConfig.CourseEntity
|
||||
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.withSysUser; query != nil {
|
||||
if err := _q.loadSysUser(ctx, query, nodes, nil,
|
||||
func(n *CourseEntity, e *SysUser) { n.Edges.SysUser = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *CourseEntityQuery) loadSysUser(ctx context.Context, query *SysUserQuery, nodes []*CourseEntity, init func(*CourseEntity), assign func(*CourseEntity, *SysUser)) error {
|
||||
ids := make([]int64, 0, len(nodes))
|
||||
nodeids := make(map[int64][]*CourseEntity)
|
||||
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 *CourseEntityQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
_spec.Node.Schema = _q.schemaConfig.CourseEntity
|
||||
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 *CourseEntityQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(courseentity.Table, courseentity.Columns, sqlgraph.NewFieldSpec(courseentity.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, courseentity.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != courseentity.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
if _q.withSysUser != nil {
|
||||
_spec.Node.AddColumnOnce(courseentity.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 *CourseEntityQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(courseentity.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = courseentity.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.CourseEntity)
|
||||
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 *CourseEntityQuery) ForUpdate(opts ...sql.LockOption) *CourseEntityQuery {
|
||||
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 *CourseEntityQuery) ForShare(opts ...sql.LockOption) *CourseEntityQuery {
|
||||
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 *CourseEntityQuery) Modify(modifiers ...func(s *sql.Selector)) *CourseEntitySelect {
|
||||
_q.modifiers = append(_q.modifiers, modifiers...)
|
||||
return _q.Select()
|
||||
}
|
||||
|
||||
// CourseEntityGroupBy is the group-by builder for CourseEntity entities.
|
||||
type CourseEntityGroupBy struct {
|
||||
selector
|
||||
build *CourseEntityQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *CourseEntityGroupBy) Aggregate(fns ...AggregateFunc) *CourseEntityGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *CourseEntityGroupBy) 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[*CourseEntityQuery, *CourseEntityGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *CourseEntityGroupBy) sqlScan(ctx context.Context, root *CourseEntityQuery, 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)
|
||||
}
|
||||
|
||||
// CourseEntitySelect is the builder for selecting fields of CourseEntity entities.
|
||||
type CourseEntitySelect struct {
|
||||
*CourseEntityQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *CourseEntitySelect) Aggregate(fns ...AggregateFunc) *CourseEntitySelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *CourseEntitySelect) 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[*CourseEntityQuery, *CourseEntitySelect](ctx, _s.CourseEntityQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *CourseEntitySelect) sqlScan(ctx context.Context, root *CourseEntityQuery, 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 *CourseEntitySelect) Modify(modifiers ...func(s *sql.Selector)) *CourseEntitySelect {
|
||||
_s.modifiers = append(_s.modifiers, modifiers...)
|
||||
return _s
|
||||
}
|
||||
@@ -0,0 +1,982 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/courseentity"
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CourseEntityUpdate is the builder for updating CourseEntity entities.
|
||||
type CourseEntityUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *CourseEntityMutation
|
||||
modifiers []func(*sql.UpdateBuilder)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CourseEntityUpdate builder.
|
||||
func (_u *CourseEntityUpdate) Where(ps ...predicate.CourseEntity) *CourseEntityUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (_u *CourseEntityUpdate) SetUpdateTime(v *ent2.CustomTime) *CourseEntityUpdate {
|
||||
_u.mutation.SetUpdateTime(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (_u *CourseEntityUpdate) SetUserID(v int64) *CourseEntityUpdate {
|
||||
_u.mutation.SetUserID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdate) SetNillableUserID(v *int64) *CourseEntityUpdate {
|
||||
if v != nil {
|
||||
_u.SetUserID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUsername sets the "username" field.
|
||||
func (_u *CourseEntityUpdate) SetUsername(v string) *CourseEntityUpdate {
|
||||
_u.mutation.SetUsername(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUsername sets the "username" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdate) SetNillableUsername(v *string) *CourseEntityUpdate {
|
||||
if v != nil {
|
||||
_u.SetUsername(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetPassword sets the "password" field.
|
||||
func (_u *CourseEntityUpdate) SetPassword(v string) *CourseEntityUpdate {
|
||||
_u.mutation.SetPassword(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillablePassword sets the "password" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdate) SetNillablePassword(v *string) *CourseEntityUpdate {
|
||||
if v != nil {
|
||||
_u.SetPassword(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (_u *CourseEntityUpdate) SetType(v courseentity.Type) *CourseEntityUpdate {
|
||||
_u.mutation.SetType(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdate) SetNillableType(v *courseentity.Type) *CourseEntityUpdate {
|
||||
if v != nil {
|
||||
_u.SetType(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCourseName sets the "course_name" field.
|
||||
func (_u *CourseEntityUpdate) SetCourseName(v string) *CourseEntityUpdate {
|
||||
_u.mutation.SetCourseName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCourseName sets the "course_name" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdate) SetNillableCourseName(v *string) *CourseEntityUpdate {
|
||||
if v != nil {
|
||||
_u.SetCourseName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCourseID sets the "course_id" field.
|
||||
func (_u *CourseEntityUpdate) SetCourseID(v string) *CourseEntityUpdate {
|
||||
_u.mutation.SetCourseID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCourseID sets the "course_id" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdate) SetNillableCourseID(v *string) *CourseEntityUpdate {
|
||||
if v != nil {
|
||||
_u.SetCourseID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNeed sets the "need" field.
|
||||
func (_u *CourseEntityUpdate) SetNeed(v courseentity.Need) *CourseEntityUpdate {
|
||||
_u.mutation.SetNeed(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableNeed sets the "need" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdate) SetNillableNeed(v *courseentity.Need) *CourseEntityUpdate {
|
||||
if v != nil {
|
||||
_u.SetNeed(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_u *CourseEntityUpdate) SetStatus(v courseentity.Status) *CourseEntityUpdate {
|
||||
_u.mutation.SetStatus(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdate) SetNillableStatus(v *courseentity.Status) *CourseEntityUpdate {
|
||||
if v != nil {
|
||||
_u.SetStatus(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetTaskCount sets the "task_count" field.
|
||||
func (_u *CourseEntityUpdate) SetTaskCount(v int) *CourseEntityUpdate {
|
||||
_u.mutation.ResetTaskCount()
|
||||
_u.mutation.SetTaskCount(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableTaskCount sets the "task_count" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdate) SetNillableTaskCount(v *int) *CourseEntityUpdate {
|
||||
if v != nil {
|
||||
_u.SetTaskCount(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddTaskCount adds value to the "task_count" field.
|
||||
func (_u *CourseEntityUpdate) AddTaskCount(v int) *CourseEntityUpdate {
|
||||
_u.mutation.AddTaskCount(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetSuccessCount sets the "success_count" field.
|
||||
func (_u *CourseEntityUpdate) SetSuccessCount(v int) *CourseEntityUpdate {
|
||||
_u.mutation.ResetSuccessCount()
|
||||
_u.mutation.SetSuccessCount(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableSuccessCount sets the "success_count" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdate) SetNillableSuccessCount(v *int) *CourseEntityUpdate {
|
||||
if v != nil {
|
||||
_u.SetSuccessCount(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddSuccessCount adds value to the "success_count" field.
|
||||
func (_u *CourseEntityUpdate) AddSuccessCount(v int) *CourseEntityUpdate {
|
||||
_u.mutation.AddSuccessCount(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetExamState sets the "exam_state" field.
|
||||
func (_u *CourseEntityUpdate) SetExamState(v courseentity.ExamState) *CourseEntityUpdate {
|
||||
_u.mutation.SetExamState(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableExamState sets the "exam_state" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdate) SetNillableExamState(v *courseentity.ExamState) *CourseEntityUpdate {
|
||||
if v != nil {
|
||||
_u.SetExamState(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetViolence sets the "violence" field.
|
||||
func (_u *CourseEntityUpdate) SetViolence(v courseentity.Violence) *CourseEntityUpdate {
|
||||
_u.mutation.SetViolence(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableViolence sets the "violence" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdate) SetNillableViolence(v *courseentity.Violence) *CourseEntityUpdate {
|
||||
if v != nil {
|
||||
_u.SetViolence(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNodes sets the "nodes" field.
|
||||
func (_u *CourseEntityUpdate) SetNodes(v string) *CourseEntityUpdate {
|
||||
_u.mutation.SetNodes(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableNodes sets the "nodes" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdate) SetNillableNodes(v *string) *CourseEntityUpdate {
|
||||
if v != nil {
|
||||
_u.SetNodes(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearNodes clears the value of the "nodes" field.
|
||||
func (_u *CourseEntityUpdate) ClearNodes() *CourseEntityUpdate {
|
||||
_u.mutation.ClearNodes()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCompletedNodes sets the "completed_nodes" field.
|
||||
func (_u *CourseEntityUpdate) SetCompletedNodes(v string) *CourseEntityUpdate {
|
||||
_u.mutation.SetCompletedNodes(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCompletedNodes sets the "completed_nodes" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdate) SetNillableCompletedNodes(v *string) *CourseEntityUpdate {
|
||||
if v != nil {
|
||||
_u.SetCompletedNodes(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearCompletedNodes clears the value of the "completed_nodes" field.
|
||||
func (_u *CourseEntityUpdate) ClearCompletedNodes() *CourseEntityUpdate {
|
||||
_u.mutation.ClearCompletedNodes()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetDesc sets the "desc" field.
|
||||
func (_u *CourseEntityUpdate) SetDesc(v string) *CourseEntityUpdate {
|
||||
_u.mutation.SetDesc(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableDesc sets the "desc" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdate) SetNillableDesc(v *string) *CourseEntityUpdate {
|
||||
if v != nil {
|
||||
_u.SetDesc(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearDesc clears the value of the "desc" field.
|
||||
func (_u *CourseEntityUpdate) ClearDesc() *CourseEntityUpdate {
|
||||
_u.mutation.ClearDesc()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetSysUserID sets the "sys_user" edge to the SysUser entity by ID.
|
||||
func (_u *CourseEntityUpdate) SetSysUserID(id int64) *CourseEntityUpdate {
|
||||
_u.mutation.SetSysUserID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetSysUser sets the "sys_user" edge to the SysUser entity.
|
||||
func (_u *CourseEntityUpdate) SetSysUser(v *SysUser) *CourseEntityUpdate {
|
||||
return _u.SetSysUserID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the CourseEntityMutation object of the builder.
|
||||
func (_u *CourseEntityUpdate) Mutation() *CourseEntityMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearSysUser clears the "sys_user" edge to the SysUser entity.
|
||||
func (_u *CourseEntityUpdate) ClearSysUser() *CourseEntityUpdate {
|
||||
_u.mutation.ClearSysUser()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *CourseEntityUpdate) 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 *CourseEntityUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *CourseEntityUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *CourseEntityUpdate) 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 *CourseEntityUpdate) check() error {
|
||||
if v, ok := _u.mutation.GetType(); ok {
|
||||
if err := courseentity.TypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "CourseEntity.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Need(); ok {
|
||||
if err := courseentity.NeedValidator(v); err != nil {
|
||||
return &ValidationError{Name: "need", err: fmt.Errorf(`ent: validator failed for field "CourseEntity.need": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Status(); ok {
|
||||
if err := courseentity.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "CourseEntity.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.ExamState(); ok {
|
||||
if err := courseentity.ExamStateValidator(v); err != nil {
|
||||
return &ValidationError{Name: "exam_state", err: fmt.Errorf(`ent: validator failed for field "CourseEntity.exam_state": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Violence(); ok {
|
||||
if err := courseentity.ViolenceValidator(v); err != nil {
|
||||
return &ValidationError{Name: "violence", err: fmt.Errorf(`ent: validator failed for field "CourseEntity.violence": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _u.mutation.SysUserCleared() && len(_u.mutation.SysUserIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "CourseEntity.sys_user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
||||
func (_u *CourseEntityUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *CourseEntityUpdate {
|
||||
_u.modifiers = append(_u.modifiers, modifiers...)
|
||||
return _u
|
||||
}
|
||||
|
||||
func (_u *CourseEntityUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(courseentity.Table, courseentity.Columns, sqlgraph.NewFieldSpec(courseentity.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(courseentity.FieldUpdateTime, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Username(); ok {
|
||||
_spec.SetField(courseentity.FieldUsername, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Password(); ok {
|
||||
_spec.SetField(courseentity.FieldPassword, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.GetType(); ok {
|
||||
_spec.SetField(courseentity.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.CourseName(); ok {
|
||||
_spec.SetField(courseentity.FieldCourseName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.CourseID(); ok {
|
||||
_spec.SetField(courseentity.FieldCourseID, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Need(); ok {
|
||||
_spec.SetField(courseentity.FieldNeed, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Status(); ok {
|
||||
_spec.SetField(courseentity.FieldStatus, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.TaskCount(); ok {
|
||||
_spec.SetField(courseentity.FieldTaskCount, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedTaskCount(); ok {
|
||||
_spec.AddField(courseentity.FieldTaskCount, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.SuccessCount(); ok {
|
||||
_spec.SetField(courseentity.FieldSuccessCount, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedSuccessCount(); ok {
|
||||
_spec.AddField(courseentity.FieldSuccessCount, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ExamState(); ok {
|
||||
_spec.SetField(courseentity.FieldExamState, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Violence(); ok {
|
||||
_spec.SetField(courseentity.FieldViolence, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Nodes(); ok {
|
||||
_spec.SetField(courseentity.FieldNodes, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.NodesCleared() {
|
||||
_spec.ClearField(courseentity.FieldNodes, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.CompletedNodes(); ok {
|
||||
_spec.SetField(courseentity.FieldCompletedNodes, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.CompletedNodesCleared() {
|
||||
_spec.ClearField(courseentity.FieldCompletedNodes, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Desc(); ok {
|
||||
_spec.SetField(courseentity.FieldDesc, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.DescCleared() {
|
||||
_spec.ClearField(courseentity.FieldDesc, field.TypeString)
|
||||
}
|
||||
if _u.mutation.SysUserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: courseentity.SysUserTable,
|
||||
Columns: []string{courseentity.SysUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.CourseEntity
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.SysUserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: courseentity.SysUserTable,
|
||||
Columns: []string{courseentity.SysUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.CourseEntity
|
||||
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.CourseEntity
|
||||
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{courseentity.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// CourseEntityUpdateOne is the builder for updating a single CourseEntity entity.
|
||||
type CourseEntityUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *CourseEntityMutation
|
||||
modifiers []func(*sql.UpdateBuilder)
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (_u *CourseEntityUpdateOne) SetUpdateTime(v *ent2.CustomTime) *CourseEntityUpdateOne {
|
||||
_u.mutation.SetUpdateTime(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (_u *CourseEntityUpdateOne) SetUserID(v int64) *CourseEntityUpdateOne {
|
||||
_u.mutation.SetUserID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdateOne) SetNillableUserID(v *int64) *CourseEntityUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUserID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUsername sets the "username" field.
|
||||
func (_u *CourseEntityUpdateOne) SetUsername(v string) *CourseEntityUpdateOne {
|
||||
_u.mutation.SetUsername(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUsername sets the "username" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdateOne) SetNillableUsername(v *string) *CourseEntityUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUsername(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetPassword sets the "password" field.
|
||||
func (_u *CourseEntityUpdateOne) SetPassword(v string) *CourseEntityUpdateOne {
|
||||
_u.mutation.SetPassword(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillablePassword sets the "password" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdateOne) SetNillablePassword(v *string) *CourseEntityUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetPassword(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (_u *CourseEntityUpdateOne) SetType(v courseentity.Type) *CourseEntityUpdateOne {
|
||||
_u.mutation.SetType(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdateOne) SetNillableType(v *courseentity.Type) *CourseEntityUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetType(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCourseName sets the "course_name" field.
|
||||
func (_u *CourseEntityUpdateOne) SetCourseName(v string) *CourseEntityUpdateOne {
|
||||
_u.mutation.SetCourseName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCourseName sets the "course_name" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdateOne) SetNillableCourseName(v *string) *CourseEntityUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetCourseName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCourseID sets the "course_id" field.
|
||||
func (_u *CourseEntityUpdateOne) SetCourseID(v string) *CourseEntityUpdateOne {
|
||||
_u.mutation.SetCourseID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCourseID sets the "course_id" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdateOne) SetNillableCourseID(v *string) *CourseEntityUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetCourseID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNeed sets the "need" field.
|
||||
func (_u *CourseEntityUpdateOne) SetNeed(v courseentity.Need) *CourseEntityUpdateOne {
|
||||
_u.mutation.SetNeed(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableNeed sets the "need" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdateOne) SetNillableNeed(v *courseentity.Need) *CourseEntityUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetNeed(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_u *CourseEntityUpdateOne) SetStatus(v courseentity.Status) *CourseEntityUpdateOne {
|
||||
_u.mutation.SetStatus(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdateOne) SetNillableStatus(v *courseentity.Status) *CourseEntityUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetStatus(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetTaskCount sets the "task_count" field.
|
||||
func (_u *CourseEntityUpdateOne) SetTaskCount(v int) *CourseEntityUpdateOne {
|
||||
_u.mutation.ResetTaskCount()
|
||||
_u.mutation.SetTaskCount(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableTaskCount sets the "task_count" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdateOne) SetNillableTaskCount(v *int) *CourseEntityUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetTaskCount(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddTaskCount adds value to the "task_count" field.
|
||||
func (_u *CourseEntityUpdateOne) AddTaskCount(v int) *CourseEntityUpdateOne {
|
||||
_u.mutation.AddTaskCount(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetSuccessCount sets the "success_count" field.
|
||||
func (_u *CourseEntityUpdateOne) SetSuccessCount(v int) *CourseEntityUpdateOne {
|
||||
_u.mutation.ResetSuccessCount()
|
||||
_u.mutation.SetSuccessCount(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableSuccessCount sets the "success_count" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdateOne) SetNillableSuccessCount(v *int) *CourseEntityUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetSuccessCount(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddSuccessCount adds value to the "success_count" field.
|
||||
func (_u *CourseEntityUpdateOne) AddSuccessCount(v int) *CourseEntityUpdateOne {
|
||||
_u.mutation.AddSuccessCount(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetExamState sets the "exam_state" field.
|
||||
func (_u *CourseEntityUpdateOne) SetExamState(v courseentity.ExamState) *CourseEntityUpdateOne {
|
||||
_u.mutation.SetExamState(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableExamState sets the "exam_state" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdateOne) SetNillableExamState(v *courseentity.ExamState) *CourseEntityUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetExamState(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetViolence sets the "violence" field.
|
||||
func (_u *CourseEntityUpdateOne) SetViolence(v courseentity.Violence) *CourseEntityUpdateOne {
|
||||
_u.mutation.SetViolence(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableViolence sets the "violence" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdateOne) SetNillableViolence(v *courseentity.Violence) *CourseEntityUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetViolence(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNodes sets the "nodes" field.
|
||||
func (_u *CourseEntityUpdateOne) SetNodes(v string) *CourseEntityUpdateOne {
|
||||
_u.mutation.SetNodes(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableNodes sets the "nodes" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdateOne) SetNillableNodes(v *string) *CourseEntityUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetNodes(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearNodes clears the value of the "nodes" field.
|
||||
func (_u *CourseEntityUpdateOne) ClearNodes() *CourseEntityUpdateOne {
|
||||
_u.mutation.ClearNodes()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCompletedNodes sets the "completed_nodes" field.
|
||||
func (_u *CourseEntityUpdateOne) SetCompletedNodes(v string) *CourseEntityUpdateOne {
|
||||
_u.mutation.SetCompletedNodes(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCompletedNodes sets the "completed_nodes" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdateOne) SetNillableCompletedNodes(v *string) *CourseEntityUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetCompletedNodes(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearCompletedNodes clears the value of the "completed_nodes" field.
|
||||
func (_u *CourseEntityUpdateOne) ClearCompletedNodes() *CourseEntityUpdateOne {
|
||||
_u.mutation.ClearCompletedNodes()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetDesc sets the "desc" field.
|
||||
func (_u *CourseEntityUpdateOne) SetDesc(v string) *CourseEntityUpdateOne {
|
||||
_u.mutation.SetDesc(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableDesc sets the "desc" field if the given value is not nil.
|
||||
func (_u *CourseEntityUpdateOne) SetNillableDesc(v *string) *CourseEntityUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetDesc(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearDesc clears the value of the "desc" field.
|
||||
func (_u *CourseEntityUpdateOne) ClearDesc() *CourseEntityUpdateOne {
|
||||
_u.mutation.ClearDesc()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetSysUserID sets the "sys_user" edge to the SysUser entity by ID.
|
||||
func (_u *CourseEntityUpdateOne) SetSysUserID(id int64) *CourseEntityUpdateOne {
|
||||
_u.mutation.SetSysUserID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetSysUser sets the "sys_user" edge to the SysUser entity.
|
||||
func (_u *CourseEntityUpdateOne) SetSysUser(v *SysUser) *CourseEntityUpdateOne {
|
||||
return _u.SetSysUserID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the CourseEntityMutation object of the builder.
|
||||
func (_u *CourseEntityUpdateOne) Mutation() *CourseEntityMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearSysUser clears the "sys_user" edge to the SysUser entity.
|
||||
func (_u *CourseEntityUpdateOne) ClearSysUser() *CourseEntityUpdateOne {
|
||||
_u.mutation.ClearSysUser()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CourseEntityUpdate builder.
|
||||
func (_u *CourseEntityUpdateOne) Where(ps ...predicate.CourseEntity) *CourseEntityUpdateOne {
|
||||
_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 *CourseEntityUpdateOne) Select(field string, fields ...string) *CourseEntityUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated CourseEntity entity.
|
||||
func (_u *CourseEntityUpdateOne) Save(ctx context.Context) (*CourseEntity, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *CourseEntityUpdateOne) SaveX(ctx context.Context) *CourseEntity {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *CourseEntityUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *CourseEntityUpdateOne) 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 *CourseEntityUpdateOne) check() error {
|
||||
if v, ok := _u.mutation.GetType(); ok {
|
||||
if err := courseentity.TypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "CourseEntity.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Need(); ok {
|
||||
if err := courseentity.NeedValidator(v); err != nil {
|
||||
return &ValidationError{Name: "need", err: fmt.Errorf(`ent: validator failed for field "CourseEntity.need": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Status(); ok {
|
||||
if err := courseentity.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "CourseEntity.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.ExamState(); ok {
|
||||
if err := courseentity.ExamStateValidator(v); err != nil {
|
||||
return &ValidationError{Name: "exam_state", err: fmt.Errorf(`ent: validator failed for field "CourseEntity.exam_state": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Violence(); ok {
|
||||
if err := courseentity.ViolenceValidator(v); err != nil {
|
||||
return &ValidationError{Name: "violence", err: fmt.Errorf(`ent: validator failed for field "CourseEntity.violence": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _u.mutation.SysUserCleared() && len(_u.mutation.SysUserIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "CourseEntity.sys_user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
||||
func (_u *CourseEntityUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *CourseEntityUpdateOne {
|
||||
_u.modifiers = append(_u.modifiers, modifiers...)
|
||||
return _u
|
||||
}
|
||||
|
||||
func (_u *CourseEntityUpdateOne) sqlSave(ctx context.Context) (_node *CourseEntity, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(courseentity.Table, courseentity.Columns, sqlgraph.NewFieldSpec(courseentity.FieldID, field.TypeInt64))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "CourseEntity.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, courseentity.FieldID)
|
||||
for _, f := range fields {
|
||||
if !courseentity.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != courseentity.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(courseentity.FieldUpdateTime, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Username(); ok {
|
||||
_spec.SetField(courseentity.FieldUsername, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Password(); ok {
|
||||
_spec.SetField(courseentity.FieldPassword, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.GetType(); ok {
|
||||
_spec.SetField(courseentity.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.CourseName(); ok {
|
||||
_spec.SetField(courseentity.FieldCourseName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.CourseID(); ok {
|
||||
_spec.SetField(courseentity.FieldCourseID, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Need(); ok {
|
||||
_spec.SetField(courseentity.FieldNeed, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Status(); ok {
|
||||
_spec.SetField(courseentity.FieldStatus, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.TaskCount(); ok {
|
||||
_spec.SetField(courseentity.FieldTaskCount, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedTaskCount(); ok {
|
||||
_spec.AddField(courseentity.FieldTaskCount, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.SuccessCount(); ok {
|
||||
_spec.SetField(courseentity.FieldSuccessCount, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedSuccessCount(); ok {
|
||||
_spec.AddField(courseentity.FieldSuccessCount, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ExamState(); ok {
|
||||
_spec.SetField(courseentity.FieldExamState, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Violence(); ok {
|
||||
_spec.SetField(courseentity.FieldViolence, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Nodes(); ok {
|
||||
_spec.SetField(courseentity.FieldNodes, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.NodesCleared() {
|
||||
_spec.ClearField(courseentity.FieldNodes, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.CompletedNodes(); ok {
|
||||
_spec.SetField(courseentity.FieldCompletedNodes, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.CompletedNodesCleared() {
|
||||
_spec.ClearField(courseentity.FieldCompletedNodes, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Desc(); ok {
|
||||
_spec.SetField(courseentity.FieldDesc, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.DescCleared() {
|
||||
_spec.ClearField(courseentity.FieldDesc, field.TypeString)
|
||||
}
|
||||
if _u.mutation.SysUserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: courseentity.SysUserTable,
|
||||
Columns: []string{courseentity.SysUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.CourseEntity
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.SysUserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: courseentity.SysUserTable,
|
||||
Columns: []string{courseentity.SysUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.CourseEntity
|
||||
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.CourseEntity
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _u.schemaConfig)
|
||||
_spec.AddModifiers(_u.modifiers...)
|
||||
_node = &CourseEntity{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{courseentity.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,242 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/cpleave"
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// CpLeave is the model entity for the CpLeave schema.
|
||||
type CpLeave struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int64 `json:"id,omitempty"`
|
||||
// CreateTime holds the value of the "create_time" field.
|
||||
CreateTime *ent2.CustomTime `json:"createTime"`
|
||||
// UpdateTime holds the value of the "update_time" field.
|
||||
UpdateTime *ent2.CustomTime `json:"updateTime"`
|
||||
// CpUserID holds the value of the "cp_user_id" field.
|
||||
CpUserID int64 `json:"cp_user_id,omitempty"`
|
||||
// UserID holds the value of the "user_id" field.
|
||||
UserID int64 `json:"user_id,omitempty"`
|
||||
// LeaveID holds the value of the "leave_id" field.
|
||||
LeaveID string `json:"leave_id,omitempty"`
|
||||
// Title holds the value of the "title" field.
|
||||
Title string `json:"title,omitempty"`
|
||||
// Status holds the value of the "status" field.
|
||||
Status cpleave.Status `json:"status,omitempty"`
|
||||
// Type holds the value of the "type" field.
|
||||
Type cpleave.Type `json:"type,omitempty"`
|
||||
// Desc holds the value of the "desc" field.
|
||||
Desc string `json:"desc,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the CpLeaveQuery when eager-loading is set.
|
||||
Edges CpLeaveEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// CpLeaveEdges holds the relations/edges for other nodes in the graph.
|
||||
type CpLeaveEdges struct {
|
||||
// CpUser holds the value of the cp_user edge.
|
||||
CpUser *CpUser `json:"cp_user,omitempty"`
|
||||
// SysUser holds the value of the sys_user edge.
|
||||
SysUser *SysUser `json:"sys_user,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [2]bool
|
||||
}
|
||||
|
||||
// CpUserOrErr returns the CpUser value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e CpLeaveEdges) CpUserOrErr() (*CpUser, error) {
|
||||
if e.CpUser != nil {
|
||||
return e.CpUser, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: cpuser.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "cp_user"}
|
||||
}
|
||||
|
||||
// SysUserOrErr returns the SysUser value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e CpLeaveEdges) SysUserOrErr() (*SysUser, error) {
|
||||
if e.SysUser != nil {
|
||||
return e.SysUser, nil
|
||||
} else if e.loadedTypes[1] {
|
||||
return nil, &NotFoundError{label: sysuser.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "sys_user"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*CpLeave) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case cpleave.FieldCreateTime, cpleave.FieldUpdateTime:
|
||||
values[i] = new(ent2.CustomTime)
|
||||
case cpleave.FieldID, cpleave.FieldCpUserID, cpleave.FieldUserID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case cpleave.FieldLeaveID, cpleave.FieldTitle, cpleave.FieldStatus, cpleave.FieldType, cpleave.FieldDesc:
|
||||
values[i] = new(sql.NullString)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the CpLeave fields.
|
||||
func (_m *CpLeave) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case cpleave.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = int64(value.Int64)
|
||||
case cpleave.FieldCreateTime:
|
||||
if value, ok := values[i].(*ent2.CustomTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field create_time", values[i])
|
||||
} else if value != nil {
|
||||
_m.CreateTime = value
|
||||
}
|
||||
case cpleave.FieldUpdateTime:
|
||||
if value, ok := values[i].(*ent2.CustomTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field update_time", values[i])
|
||||
} else if value != nil {
|
||||
_m.UpdateTime = value
|
||||
}
|
||||
case cpleave.FieldCpUserID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field cp_user_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.CpUserID = value.Int64
|
||||
}
|
||||
case cpleave.FieldUserID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field user_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.UserID = value.Int64
|
||||
}
|
||||
case cpleave.FieldLeaveID:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field leave_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.LeaveID = value.String
|
||||
}
|
||||
case cpleave.FieldTitle:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field title", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Title = value.String
|
||||
}
|
||||
case cpleave.FieldStatus:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field status", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Status = cpleave.Status(value.String)
|
||||
}
|
||||
case cpleave.FieldType:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field type", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Type = cpleave.Type(value.String)
|
||||
}
|
||||
case cpleave.FieldDesc:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field desc", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Desc = value.String
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the CpLeave.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *CpLeave) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryCpUser queries the "cp_user" edge of the CpLeave entity.
|
||||
func (_m *CpLeave) QueryCpUser() *CpUserQuery {
|
||||
return NewCpLeaveClient(_m.config).QueryCpUser(_m)
|
||||
}
|
||||
|
||||
// QuerySysUser queries the "sys_user" edge of the CpLeave entity.
|
||||
func (_m *CpLeave) QuerySysUser() *SysUserQuery {
|
||||
return NewCpLeaveClient(_m.config).QuerySysUser(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this CpLeave.
|
||||
// Note that you need to call CpLeave.Unwrap() before calling this method if this CpLeave
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *CpLeave) Update() *CpLeaveUpdateOne {
|
||||
return NewCpLeaveClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the CpLeave entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (_m *CpLeave) Unwrap() *CpLeave {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: CpLeave is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *CpLeave) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("CpLeave(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("create_time=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.CreateTime))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("update_time=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.UpdateTime))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("cp_user_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.CpUserID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("user_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.UserID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("leave_id=")
|
||||
builder.WriteString(_m.LeaveID)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("title=")
|
||||
builder.WriteString(_m.Title)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("status=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Status))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("type=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Type))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("desc=")
|
||||
builder.WriteString(_m.Desc)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// CpLeaves is a parsable slice of CpLeave.
|
||||
type CpLeaves []*CpLeave
|
||||
@@ -0,0 +1,224 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package cpleave
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the cpleave type in the database.
|
||||
Label = "cp_leave"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldCreateTime holds the string denoting the create_time field in the database.
|
||||
FieldCreateTime = "create_time"
|
||||
// FieldUpdateTime holds the string denoting the update_time field in the database.
|
||||
FieldUpdateTime = "update_time"
|
||||
// FieldCpUserID holds the string denoting the cp_user_id field in the database.
|
||||
FieldCpUserID = "cp_user_id"
|
||||
// FieldUserID holds the string denoting the user_id field in the database.
|
||||
FieldUserID = "user_id"
|
||||
// FieldLeaveID holds the string denoting the leave_id field in the database.
|
||||
FieldLeaveID = "leave_id"
|
||||
// FieldTitle holds the string denoting the title field in the database.
|
||||
FieldTitle = "title"
|
||||
// FieldStatus holds the string denoting the status field in the database.
|
||||
FieldStatus = "status"
|
||||
// FieldType holds the string denoting the type field in the database.
|
||||
FieldType = "type"
|
||||
// FieldDesc holds the string denoting the desc field in the database.
|
||||
FieldDesc = "desc"
|
||||
// EdgeCpUser holds the string denoting the cp_user edge name in mutations.
|
||||
EdgeCpUser = "cp_user"
|
||||
// EdgeSysUser holds the string denoting the sys_user edge name in mutations.
|
||||
EdgeSysUser = "sys_user"
|
||||
// Table holds the table name of the cpleave in the database.
|
||||
Table = "cp_leaves"
|
||||
// CpUserTable is the table that holds the cp_user relation/edge.
|
||||
CpUserTable = "cp_leaves"
|
||||
// CpUserInverseTable is the table name for the CpUser entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "cpuser" package.
|
||||
CpUserInverseTable = "cp_users"
|
||||
// CpUserColumn is the table column denoting the cp_user relation/edge.
|
||||
CpUserColumn = "cp_user_id"
|
||||
// SysUserTable is the table that holds the sys_user relation/edge.
|
||||
SysUserTable = "cp_leaves"
|
||||
// SysUserInverseTable is the table name for the SysUser entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "sysuser" package.
|
||||
SysUserInverseTable = "sys_user"
|
||||
// SysUserColumn is the table column denoting the sys_user relation/edge.
|
||||
SysUserColumn = "user_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for cpleave fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldCreateTime,
|
||||
FieldUpdateTime,
|
||||
FieldCpUserID,
|
||||
FieldUserID,
|
||||
FieldLeaveID,
|
||||
FieldTitle,
|
||||
FieldStatus,
|
||||
FieldType,
|
||||
FieldDesc,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Note that the variables below are initialized by the runtime
|
||||
// package on the initialization of the application. Therefore,
|
||||
// it should be imported in the main as follows:
|
||||
//
|
||||
// import _ "likedream-goframe/internal/ent/runtime"
|
||||
var (
|
||||
Hooks [1]ent.Hook
|
||||
// DefaultCreateTime holds the default value on creation for the "create_time" field.
|
||||
DefaultCreateTime func() *ent2.CustomTime
|
||||
// DefaultUpdateTime holds the default value on creation for the "update_time" field.
|
||||
DefaultUpdateTime func() *ent2.CustomTime
|
||||
// LeaveIDValidator is a validator for the "leave_id" field. It is called by the builders before save.
|
||||
LeaveIDValidator func(string) error
|
||||
// TitleValidator is a validator for the "title" field. It is called by the builders before save.
|
||||
TitleValidator func(string) error
|
||||
)
|
||||
|
||||
// Status defines the type for the "status" enum field.
|
||||
type Status string
|
||||
|
||||
// Status values.
|
||||
const (
|
||||
StatusDone Status = "done"
|
||||
StatusFail Status = "fail"
|
||||
)
|
||||
|
||||
func (s Status) String() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
// StatusValidator is a validator for the "status" field enum values. It is called by the builders before save.
|
||||
func StatusValidator(s Status) error {
|
||||
switch s {
|
||||
case StatusDone, StatusFail:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("cpleave: invalid enum value for status field: %q", s)
|
||||
}
|
||||
}
|
||||
|
||||
// Type defines the type for the "type" enum field.
|
||||
type Type string
|
||||
|
||||
// Type values.
|
||||
const (
|
||||
TypeReport Type = "report"
|
||||
)
|
||||
|
||||
func (_type Type) String() string {
|
||||
return string(_type)
|
||||
}
|
||||
|
||||
// TypeValidator is a validator for the "type" field enum values. It is called by the builders before save.
|
||||
func TypeValidator(_type Type) error {
|
||||
switch _type {
|
||||
case TypeReport:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("cpleave: invalid enum value for type field: %q", _type)
|
||||
}
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the CpLeave queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreateTime orders the results by the create_time field.
|
||||
func ByCreateTime(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreateTime, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdateTime orders the results by the update_time field.
|
||||
func ByUpdateTime(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdateTime, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCpUserID orders the results by the cp_user_id field.
|
||||
func ByCpUserID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCpUserID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUserID orders the results by the user_id field.
|
||||
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUserID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByLeaveID orders the results by the leave_id field.
|
||||
func ByLeaveID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldLeaveID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByTitle orders the results by the title field.
|
||||
func ByTitle(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTitle, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByStatus orders the results by the status field.
|
||||
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByType orders the results by the type field.
|
||||
func ByType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldType, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByDesc orders the results by the desc field.
|
||||
func ByDesc(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDesc, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCpUserField orders the results by cp_user field.
|
||||
func ByCpUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newCpUserStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
|
||||
// BySysUserField orders the results by sys_user field.
|
||||
func BySysUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newSysUserStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newCpUserStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(CpUserInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, CpUserTable, CpUserColumn),
|
||||
)
|
||||
}
|
||||
func newSysUserStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(SysUserInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, SysUserTable, SysUserColumn),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,590 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package cpleave
|
||||
|
||||
import (
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ.
|
||||
func CreateTime(v *ent2.CustomTime) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTime applies equality check predicate on the "update_time" field. It's identical to UpdateTimeEQ.
|
||||
func UpdateTime(v *ent2.CustomTime) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// CpUserID applies equality check predicate on the "cp_user_id" field. It's identical to CpUserIDEQ.
|
||||
func CpUserID(v int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEQ(FieldCpUserID, v))
|
||||
}
|
||||
|
||||
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
|
||||
func UserID(v int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// LeaveID applies equality check predicate on the "leave_id" field. It's identical to LeaveIDEQ.
|
||||
func LeaveID(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEQ(FieldLeaveID, v))
|
||||
}
|
||||
|
||||
// Title applies equality check predicate on the "title" field. It's identical to TitleEQ.
|
||||
func Title(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEQ(FieldTitle, v))
|
||||
}
|
||||
|
||||
// Desc applies equality check predicate on the "desc" field. It's identical to DescEQ.
|
||||
func Desc(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEQ(FieldDesc, v))
|
||||
}
|
||||
|
||||
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||
func CreateTimeEQ(v *ent2.CustomTime) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||
func CreateTimeNEQ(v *ent2.CustomTime) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||
func CreateTimeIn(vs ...*ent2.CustomTime) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||
func CreateTimeNotIn(vs ...*ent2.CustomTime) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNotIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||
func CreateTimeGT(v *ent2.CustomTime) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldGT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||
func CreateTimeGTE(v *ent2.CustomTime) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldGTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||
func CreateTimeLT(v *ent2.CustomTime) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldLT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||
func CreateTimeLTE(v *ent2.CustomTime) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldLTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeContains applies the Contains predicate on the "create_time" field.
|
||||
func CreateTimeContains(v *ent2.CustomTime) predicate.CpLeave {
|
||||
vc := v.String()
|
||||
return predicate.CpLeave(sql.FieldContains(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeHasPrefix applies the HasPrefix predicate on the "create_time" field.
|
||||
func CreateTimeHasPrefix(v *ent2.CustomTime) predicate.CpLeave {
|
||||
vc := v.String()
|
||||
return predicate.CpLeave(sql.FieldHasPrefix(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeHasSuffix applies the HasSuffix predicate on the "create_time" field.
|
||||
func CreateTimeHasSuffix(v *ent2.CustomTime) predicate.CpLeave {
|
||||
vc := v.String()
|
||||
return predicate.CpLeave(sql.FieldHasSuffix(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeEqualFold applies the EqualFold predicate on the "create_time" field.
|
||||
func CreateTimeEqualFold(v *ent2.CustomTime) predicate.CpLeave {
|
||||
vc := v.String()
|
||||
return predicate.CpLeave(sql.FieldEqualFold(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeContainsFold applies the ContainsFold predicate on the "create_time" field.
|
||||
func CreateTimeContainsFold(v *ent2.CustomTime) predicate.CpLeave {
|
||||
vc := v.String()
|
||||
return predicate.CpLeave(sql.FieldContainsFold(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeEQ applies the EQ predicate on the "update_time" field.
|
||||
func UpdateTimeEQ(v *ent2.CustomTime) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeNEQ applies the NEQ predicate on the "update_time" field.
|
||||
func UpdateTimeNEQ(v *ent2.CustomTime) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeIn applies the In predicate on the "update_time" field.
|
||||
func UpdateTimeIn(vs ...*ent2.CustomTime) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldIn(FieldUpdateTime, vs...))
|
||||
}
|
||||
|
||||
// UpdateTimeNotIn applies the NotIn predicate on the "update_time" field.
|
||||
func UpdateTimeNotIn(vs ...*ent2.CustomTime) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNotIn(FieldUpdateTime, vs...))
|
||||
}
|
||||
|
||||
// UpdateTimeGT applies the GT predicate on the "update_time" field.
|
||||
func UpdateTimeGT(v *ent2.CustomTime) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldGT(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeGTE applies the GTE predicate on the "update_time" field.
|
||||
func UpdateTimeGTE(v *ent2.CustomTime) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldGTE(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeLT applies the LT predicate on the "update_time" field.
|
||||
func UpdateTimeLT(v *ent2.CustomTime) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldLT(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeLTE applies the LTE predicate on the "update_time" field.
|
||||
func UpdateTimeLTE(v *ent2.CustomTime) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldLTE(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeContains applies the Contains predicate on the "update_time" field.
|
||||
func UpdateTimeContains(v *ent2.CustomTime) predicate.CpLeave {
|
||||
vc := v.String()
|
||||
return predicate.CpLeave(sql.FieldContains(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeHasPrefix applies the HasPrefix predicate on the "update_time" field.
|
||||
func UpdateTimeHasPrefix(v *ent2.CustomTime) predicate.CpLeave {
|
||||
vc := v.String()
|
||||
return predicate.CpLeave(sql.FieldHasPrefix(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeHasSuffix applies the HasSuffix predicate on the "update_time" field.
|
||||
func UpdateTimeHasSuffix(v *ent2.CustomTime) predicate.CpLeave {
|
||||
vc := v.String()
|
||||
return predicate.CpLeave(sql.FieldHasSuffix(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeEqualFold applies the EqualFold predicate on the "update_time" field.
|
||||
func UpdateTimeEqualFold(v *ent2.CustomTime) predicate.CpLeave {
|
||||
vc := v.String()
|
||||
return predicate.CpLeave(sql.FieldEqualFold(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeContainsFold applies the ContainsFold predicate on the "update_time" field.
|
||||
func UpdateTimeContainsFold(v *ent2.CustomTime) predicate.CpLeave {
|
||||
vc := v.String()
|
||||
return predicate.CpLeave(sql.FieldContainsFold(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// CpUserIDEQ applies the EQ predicate on the "cp_user_id" field.
|
||||
func CpUserIDEQ(v int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEQ(FieldCpUserID, v))
|
||||
}
|
||||
|
||||
// CpUserIDNEQ applies the NEQ predicate on the "cp_user_id" field.
|
||||
func CpUserIDNEQ(v int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNEQ(FieldCpUserID, v))
|
||||
}
|
||||
|
||||
// CpUserIDIn applies the In predicate on the "cp_user_id" field.
|
||||
func CpUserIDIn(vs ...int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldIn(FieldCpUserID, vs...))
|
||||
}
|
||||
|
||||
// CpUserIDNotIn applies the NotIn predicate on the "cp_user_id" field.
|
||||
func CpUserIDNotIn(vs ...int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNotIn(FieldCpUserID, vs...))
|
||||
}
|
||||
|
||||
// UserIDEQ applies the EQ predicate on the "user_id" field.
|
||||
func UserIDEQ(v int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
|
||||
func UserIDNEQ(v int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDIn applies the In predicate on the "user_id" field.
|
||||
func UserIDIn(vs ...int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
|
||||
func UserIDNotIn(vs ...int64) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNotIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// LeaveIDEQ applies the EQ predicate on the "leave_id" field.
|
||||
func LeaveIDEQ(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEQ(FieldLeaveID, v))
|
||||
}
|
||||
|
||||
// LeaveIDNEQ applies the NEQ predicate on the "leave_id" field.
|
||||
func LeaveIDNEQ(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNEQ(FieldLeaveID, v))
|
||||
}
|
||||
|
||||
// LeaveIDIn applies the In predicate on the "leave_id" field.
|
||||
func LeaveIDIn(vs ...string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldIn(FieldLeaveID, vs...))
|
||||
}
|
||||
|
||||
// LeaveIDNotIn applies the NotIn predicate on the "leave_id" field.
|
||||
func LeaveIDNotIn(vs ...string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNotIn(FieldLeaveID, vs...))
|
||||
}
|
||||
|
||||
// LeaveIDGT applies the GT predicate on the "leave_id" field.
|
||||
func LeaveIDGT(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldGT(FieldLeaveID, v))
|
||||
}
|
||||
|
||||
// LeaveIDGTE applies the GTE predicate on the "leave_id" field.
|
||||
func LeaveIDGTE(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldGTE(FieldLeaveID, v))
|
||||
}
|
||||
|
||||
// LeaveIDLT applies the LT predicate on the "leave_id" field.
|
||||
func LeaveIDLT(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldLT(FieldLeaveID, v))
|
||||
}
|
||||
|
||||
// LeaveIDLTE applies the LTE predicate on the "leave_id" field.
|
||||
func LeaveIDLTE(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldLTE(FieldLeaveID, v))
|
||||
}
|
||||
|
||||
// LeaveIDContains applies the Contains predicate on the "leave_id" field.
|
||||
func LeaveIDContains(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldContains(FieldLeaveID, v))
|
||||
}
|
||||
|
||||
// LeaveIDHasPrefix applies the HasPrefix predicate on the "leave_id" field.
|
||||
func LeaveIDHasPrefix(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldHasPrefix(FieldLeaveID, v))
|
||||
}
|
||||
|
||||
// LeaveIDHasSuffix applies the HasSuffix predicate on the "leave_id" field.
|
||||
func LeaveIDHasSuffix(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldHasSuffix(FieldLeaveID, v))
|
||||
}
|
||||
|
||||
// LeaveIDEqualFold applies the EqualFold predicate on the "leave_id" field.
|
||||
func LeaveIDEqualFold(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEqualFold(FieldLeaveID, v))
|
||||
}
|
||||
|
||||
// LeaveIDContainsFold applies the ContainsFold predicate on the "leave_id" field.
|
||||
func LeaveIDContainsFold(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldContainsFold(FieldLeaveID, v))
|
||||
}
|
||||
|
||||
// TitleEQ applies the EQ predicate on the "title" field.
|
||||
func TitleEQ(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEQ(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleNEQ applies the NEQ predicate on the "title" field.
|
||||
func TitleNEQ(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNEQ(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleIn applies the In predicate on the "title" field.
|
||||
func TitleIn(vs ...string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldIn(FieldTitle, vs...))
|
||||
}
|
||||
|
||||
// TitleNotIn applies the NotIn predicate on the "title" field.
|
||||
func TitleNotIn(vs ...string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNotIn(FieldTitle, vs...))
|
||||
}
|
||||
|
||||
// TitleGT applies the GT predicate on the "title" field.
|
||||
func TitleGT(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldGT(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleGTE applies the GTE predicate on the "title" field.
|
||||
func TitleGTE(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldGTE(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleLT applies the LT predicate on the "title" field.
|
||||
func TitleLT(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldLT(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleLTE applies the LTE predicate on the "title" field.
|
||||
func TitleLTE(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldLTE(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleContains applies the Contains predicate on the "title" field.
|
||||
func TitleContains(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldContains(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleHasPrefix applies the HasPrefix predicate on the "title" field.
|
||||
func TitleHasPrefix(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldHasPrefix(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleHasSuffix applies the HasSuffix predicate on the "title" field.
|
||||
func TitleHasSuffix(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldHasSuffix(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleEqualFold applies the EqualFold predicate on the "title" field.
|
||||
func TitleEqualFold(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEqualFold(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleContainsFold applies the ContainsFold predicate on the "title" field.
|
||||
func TitleContainsFold(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldContainsFold(FieldTitle, v))
|
||||
}
|
||||
|
||||
// StatusEQ applies the EQ predicate on the "status" field.
|
||||
func StatusEQ(v Status) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEQ(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusNEQ applies the NEQ predicate on the "status" field.
|
||||
func StatusNEQ(v Status) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNEQ(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusIn applies the In predicate on the "status" field.
|
||||
func StatusIn(vs ...Status) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldIn(FieldStatus, vs...))
|
||||
}
|
||||
|
||||
// StatusNotIn applies the NotIn predicate on the "status" field.
|
||||
func StatusNotIn(vs ...Status) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNotIn(FieldStatus, vs...))
|
||||
}
|
||||
|
||||
// TypeEQ applies the EQ predicate on the "type" field.
|
||||
func TypeEQ(v Type) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeNEQ applies the NEQ predicate on the "type" field.
|
||||
func TypeNEQ(v Type) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeIn applies the In predicate on the "type" field.
|
||||
func TypeIn(vs ...Type) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// TypeNotIn applies the NotIn predicate on the "type" field.
|
||||
func TypeNotIn(vs ...Type) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNotIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// DescEQ applies the EQ predicate on the "desc" field.
|
||||
func DescEQ(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEQ(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescNEQ applies the NEQ predicate on the "desc" field.
|
||||
func DescNEQ(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNEQ(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescIn applies the In predicate on the "desc" field.
|
||||
func DescIn(vs ...string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldIn(FieldDesc, vs...))
|
||||
}
|
||||
|
||||
// DescNotIn applies the NotIn predicate on the "desc" field.
|
||||
func DescNotIn(vs ...string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNotIn(FieldDesc, vs...))
|
||||
}
|
||||
|
||||
// DescGT applies the GT predicate on the "desc" field.
|
||||
func DescGT(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldGT(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescGTE applies the GTE predicate on the "desc" field.
|
||||
func DescGTE(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldGTE(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescLT applies the LT predicate on the "desc" field.
|
||||
func DescLT(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldLT(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescLTE applies the LTE predicate on the "desc" field.
|
||||
func DescLTE(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldLTE(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescContains applies the Contains predicate on the "desc" field.
|
||||
func DescContains(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldContains(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescHasPrefix applies the HasPrefix predicate on the "desc" field.
|
||||
func DescHasPrefix(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldHasPrefix(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescHasSuffix applies the HasSuffix predicate on the "desc" field.
|
||||
func DescHasSuffix(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldHasSuffix(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescIsNil applies the IsNil predicate on the "desc" field.
|
||||
func DescIsNil() predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldIsNull(FieldDesc))
|
||||
}
|
||||
|
||||
// DescNotNil applies the NotNil predicate on the "desc" field.
|
||||
func DescNotNil() predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldNotNull(FieldDesc))
|
||||
}
|
||||
|
||||
// DescEqualFold applies the EqualFold predicate on the "desc" field.
|
||||
func DescEqualFold(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldEqualFold(FieldDesc, v))
|
||||
}
|
||||
|
||||
// DescContainsFold applies the ContainsFold predicate on the "desc" field.
|
||||
func DescContainsFold(v string) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.FieldContainsFold(FieldDesc, v))
|
||||
}
|
||||
|
||||
// HasCpUser applies the HasEdge predicate on the "cp_user" edge.
|
||||
func HasCpUser() predicate.CpLeave {
|
||||
return predicate.CpLeave(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, CpUserTable, CpUserColumn),
|
||||
)
|
||||
schemaConfig := internal.SchemaConfigFromContext(s.Context())
|
||||
step.To.Schema = schemaConfig.CpUser
|
||||
step.Edge.Schema = schemaConfig.CpLeave
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasCpUserWith applies the HasEdge predicate on the "cp_user" edge with a given conditions (other predicates).
|
||||
func HasCpUserWith(preds ...predicate.CpUser) predicate.CpLeave {
|
||||
return predicate.CpLeave(func(s *sql.Selector) {
|
||||
step := newCpUserStep()
|
||||
schemaConfig := internal.SchemaConfigFromContext(s.Context())
|
||||
step.To.Schema = schemaConfig.CpUser
|
||||
step.Edge.Schema = schemaConfig.CpLeave
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasSysUser applies the HasEdge predicate on the "sys_user" edge.
|
||||
func HasSysUser() predicate.CpLeave {
|
||||
return predicate.CpLeave(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, SysUserTable, SysUserColumn),
|
||||
)
|
||||
schemaConfig := internal.SchemaConfigFromContext(s.Context())
|
||||
step.To.Schema = schemaConfig.SysUser
|
||||
step.Edge.Schema = schemaConfig.CpLeave
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasSysUserWith applies the HasEdge predicate on the "sys_user" edge with a given conditions (other predicates).
|
||||
func HasSysUserWith(preds ...predicate.SysUser) predicate.CpLeave {
|
||||
return predicate.CpLeave(func(s *sql.Selector) {
|
||||
step := newSysUserStep()
|
||||
schemaConfig := internal.SchemaConfigFromContext(s.Context())
|
||||
step.To.Schema = schemaConfig.SysUser
|
||||
step.Edge.Schema = schemaConfig.CpLeave
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.CpLeave) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.CpLeave) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.CpLeave) predicate.CpLeave {
|
||||
return predicate.CpLeave(sql.NotPredicates(p))
|
||||
}
|
||||
@@ -0,0 +1,972 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/cpleave"
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CpLeaveCreate is the builder for creating a CpLeave entity.
|
||||
type CpLeaveCreate struct {
|
||||
config
|
||||
mutation *CpLeaveMutation
|
||||
hooks []Hook
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// SetCreateTime sets the "create_time" field.
|
||||
func (_c *CpLeaveCreate) SetCreateTime(v *ent2.CustomTime) *CpLeaveCreate {
|
||||
_c.mutation.SetCreateTime(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (_c *CpLeaveCreate) SetUpdateTime(v *ent2.CustomTime) *CpLeaveCreate {
|
||||
_c.mutation.SetUpdateTime(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCpUserID sets the "cp_user_id" field.
|
||||
func (_c *CpLeaveCreate) SetCpUserID(v int64) *CpLeaveCreate {
|
||||
_c.mutation.SetCpUserID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (_c *CpLeaveCreate) SetUserID(v int64) *CpLeaveCreate {
|
||||
_c.mutation.SetUserID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetLeaveID sets the "leave_id" field.
|
||||
func (_c *CpLeaveCreate) SetLeaveID(v string) *CpLeaveCreate {
|
||||
_c.mutation.SetLeaveID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetTitle sets the "title" field.
|
||||
func (_c *CpLeaveCreate) SetTitle(v string) *CpLeaveCreate {
|
||||
_c.mutation.SetTitle(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_c *CpLeaveCreate) SetStatus(v cpleave.Status) *CpLeaveCreate {
|
||||
_c.mutation.SetStatus(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (_c *CpLeaveCreate) SetType(v cpleave.Type) *CpLeaveCreate {
|
||||
_c.mutation.SetType(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetDesc sets the "desc" field.
|
||||
func (_c *CpLeaveCreate) SetDesc(v string) *CpLeaveCreate {
|
||||
_c.mutation.SetDesc(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableDesc sets the "desc" field if the given value is not nil.
|
||||
func (_c *CpLeaveCreate) SetNillableDesc(v *string) *CpLeaveCreate {
|
||||
if v != nil {
|
||||
_c.SetDesc(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCpUser sets the "cp_user" edge to the CpUser entity.
|
||||
func (_c *CpLeaveCreate) SetCpUser(v *CpUser) *CpLeaveCreate {
|
||||
return _c.SetCpUserID(v.ID)
|
||||
}
|
||||
|
||||
// SetSysUserID sets the "sys_user" edge to the SysUser entity by ID.
|
||||
func (_c *CpLeaveCreate) SetSysUserID(id int64) *CpLeaveCreate {
|
||||
_c.mutation.SetSysUserID(id)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetSysUser sets the "sys_user" edge to the SysUser entity.
|
||||
func (_c *CpLeaveCreate) SetSysUser(v *SysUser) *CpLeaveCreate {
|
||||
return _c.SetSysUserID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the CpLeaveMutation object of the builder.
|
||||
func (_c *CpLeaveCreate) Mutation() *CpLeaveMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the CpLeave in the database.
|
||||
func (_c *CpLeaveCreate) Save(ctx context.Context) (*CpLeave, error) {
|
||||
if err := _c.defaults(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *CpLeaveCreate) SaveX(ctx context.Context) *CpLeave {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *CpLeaveCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *CpLeaveCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_c *CpLeaveCreate) defaults() error {
|
||||
if _, ok := _c.mutation.CreateTime(); !ok {
|
||||
if cpleave.DefaultCreateTime == nil {
|
||||
return fmt.Errorf("ent: uninitialized cpleave.DefaultCreateTime (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := cpleave.DefaultCreateTime()
|
||||
_c.mutation.SetCreateTime(v)
|
||||
}
|
||||
if _, ok := _c.mutation.UpdateTime(); !ok {
|
||||
if cpleave.DefaultUpdateTime == nil {
|
||||
return fmt.Errorf("ent: uninitialized cpleave.DefaultUpdateTime (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := cpleave.DefaultUpdateTime()
|
||||
_c.mutation.SetUpdateTime(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *CpLeaveCreate) check() error {
|
||||
if _, ok := _c.mutation.CreateTime(); !ok {
|
||||
return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "CpLeave.create_time"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UpdateTime(); !ok {
|
||||
return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "CpLeave.update_time"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.CpUserID(); !ok {
|
||||
return &ValidationError{Name: "cp_user_id", err: errors.New(`ent: missing required field "CpLeave.cp_user_id"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "CpLeave.user_id"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.LeaveID(); !ok {
|
||||
return &ValidationError{Name: "leave_id", err: errors.New(`ent: missing required field "CpLeave.leave_id"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.LeaveID(); ok {
|
||||
if err := cpleave.LeaveIDValidator(v); err != nil {
|
||||
return &ValidationError{Name: "leave_id", err: fmt.Errorf(`ent: validator failed for field "CpLeave.leave_id": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.Title(); !ok {
|
||||
return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "CpLeave.title"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.Title(); ok {
|
||||
if err := cpleave.TitleValidator(v); err != nil {
|
||||
return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "CpLeave.title": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.Status(); !ok {
|
||||
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "CpLeave.status"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.Status(); ok {
|
||||
if err := cpleave.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "CpLeave.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.GetType(); !ok {
|
||||
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "CpLeave.type"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.GetType(); ok {
|
||||
if err := cpleave.TypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "CpLeave.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if len(_c.mutation.CpUserIDs()) == 0 {
|
||||
return &ValidationError{Name: "cp_user", err: errors.New(`ent: missing required edge "CpLeave.cp_user"`)}
|
||||
}
|
||||
if len(_c.mutation.SysUserIDs()) == 0 {
|
||||
return &ValidationError{Name: "sys_user", err: errors.New(`ent: missing required edge "CpLeave.sys_user"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *CpLeaveCreate) sqlSave(ctx context.Context) (*CpLeave, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := _c.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int64(id)
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *CpLeaveCreate) createSpec() (*CpLeave, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &CpLeave{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(cpleave.Table, sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64))
|
||||
)
|
||||
_spec.Schema = _c.schemaConfig.CpLeave
|
||||
_spec.OnConflict = _c.conflict
|
||||
if value, ok := _c.mutation.CreateTime(); ok {
|
||||
_spec.SetField(cpleave.FieldCreateTime, field.TypeString, value)
|
||||
_node.CreateTime = value
|
||||
}
|
||||
if value, ok := _c.mutation.UpdateTime(); ok {
|
||||
_spec.SetField(cpleave.FieldUpdateTime, field.TypeString, value)
|
||||
_node.UpdateTime = value
|
||||
}
|
||||
if value, ok := _c.mutation.LeaveID(); ok {
|
||||
_spec.SetField(cpleave.FieldLeaveID, field.TypeString, value)
|
||||
_node.LeaveID = value
|
||||
}
|
||||
if value, ok := _c.mutation.Title(); ok {
|
||||
_spec.SetField(cpleave.FieldTitle, field.TypeString, value)
|
||||
_node.Title = value
|
||||
}
|
||||
if value, ok := _c.mutation.Status(); ok {
|
||||
_spec.SetField(cpleave.FieldStatus, field.TypeEnum, value)
|
||||
_node.Status = value
|
||||
}
|
||||
if value, ok := _c.mutation.GetType(); ok {
|
||||
_spec.SetField(cpleave.FieldType, field.TypeEnum, value)
|
||||
_node.Type = value
|
||||
}
|
||||
if value, ok := _c.mutation.Desc(); ok {
|
||||
_spec.SetField(cpleave.FieldDesc, field.TypeString, value)
|
||||
_node.Desc = value
|
||||
}
|
||||
if nodes := _c.mutation.CpUserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: cpleave.CpUserTable,
|
||||
Columns: []string{cpleave.CpUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _c.schemaConfig.CpLeave
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.CpUserID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.SysUserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: cpleave.SysUserTable,
|
||||
Columns: []string{cpleave.SysUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _c.schemaConfig.CpLeave
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.UserID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||
// of the `INSERT` statement. For example:
|
||||
//
|
||||
// client.CpLeave.Create().
|
||||
// SetCreateTime(v).
|
||||
// OnConflict(
|
||||
// // Update the row with the new values
|
||||
// // the was proposed for insertion.
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// // Override some of the fields with custom
|
||||
// // update values.
|
||||
// Update(func(u *ent.CpLeaveUpsert) {
|
||||
// SetCreateTime(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (_c *CpLeaveCreate) OnConflict(opts ...sql.ConflictOption) *CpLeaveUpsertOne {
|
||||
_c.conflict = opts
|
||||
return &CpLeaveUpsertOne{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||
// as conflict target. Using this option is equivalent to using:
|
||||
//
|
||||
// client.CpLeave.Create().
|
||||
// OnConflict(sql.ConflictColumns(columns...)).
|
||||
// Exec(ctx)
|
||||
func (_c *CpLeaveCreate) OnConflictColumns(columns ...string) *CpLeaveUpsertOne {
|
||||
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||||
return &CpLeaveUpsertOne{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
type (
|
||||
// CpLeaveUpsertOne is the builder for "upsert"-ing
|
||||
// one CpLeave node.
|
||||
CpLeaveUpsertOne struct {
|
||||
create *CpLeaveCreate
|
||||
}
|
||||
|
||||
// CpLeaveUpsert is the "OnConflict" setter.
|
||||
CpLeaveUpsert struct {
|
||||
*sql.UpdateSet
|
||||
}
|
||||
)
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (u *CpLeaveUpsert) SetUpdateTime(v *ent2.CustomTime) *CpLeaveUpsert {
|
||||
u.Set(cpleave.FieldUpdateTime, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsert) UpdateUpdateTime() *CpLeaveUpsert {
|
||||
u.SetExcluded(cpleave.FieldUpdateTime)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetCpUserID sets the "cp_user_id" field.
|
||||
func (u *CpLeaveUpsert) SetCpUserID(v int64) *CpLeaveUpsert {
|
||||
u.Set(cpleave.FieldCpUserID, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateCpUserID sets the "cp_user_id" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsert) UpdateCpUserID() *CpLeaveUpsert {
|
||||
u.SetExcluded(cpleave.FieldCpUserID)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (u *CpLeaveUpsert) SetUserID(v int64) *CpLeaveUpsert {
|
||||
u.Set(cpleave.FieldUserID, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsert) UpdateUserID() *CpLeaveUpsert {
|
||||
u.SetExcluded(cpleave.FieldUserID)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetLeaveID sets the "leave_id" field.
|
||||
func (u *CpLeaveUpsert) SetLeaveID(v string) *CpLeaveUpsert {
|
||||
u.Set(cpleave.FieldLeaveID, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateLeaveID sets the "leave_id" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsert) UpdateLeaveID() *CpLeaveUpsert {
|
||||
u.SetExcluded(cpleave.FieldLeaveID)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetTitle sets the "title" field.
|
||||
func (u *CpLeaveUpsert) SetTitle(v string) *CpLeaveUpsert {
|
||||
u.Set(cpleave.FieldTitle, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateTitle sets the "title" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsert) UpdateTitle() *CpLeaveUpsert {
|
||||
u.SetExcluded(cpleave.FieldTitle)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (u *CpLeaveUpsert) SetStatus(v cpleave.Status) *CpLeaveUpsert {
|
||||
u.Set(cpleave.FieldStatus, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateStatus sets the "status" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsert) UpdateStatus() *CpLeaveUpsert {
|
||||
u.SetExcluded(cpleave.FieldStatus)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (u *CpLeaveUpsert) SetType(v cpleave.Type) *CpLeaveUpsert {
|
||||
u.Set(cpleave.FieldType, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateType sets the "type" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsert) UpdateType() *CpLeaveUpsert {
|
||||
u.SetExcluded(cpleave.FieldType)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetDesc sets the "desc" field.
|
||||
func (u *CpLeaveUpsert) SetDesc(v string) *CpLeaveUpsert {
|
||||
u.Set(cpleave.FieldDesc, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateDesc sets the "desc" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsert) UpdateDesc() *CpLeaveUpsert {
|
||||
u.SetExcluded(cpleave.FieldDesc)
|
||||
return u
|
||||
}
|
||||
|
||||
// ClearDesc clears the value of the "desc" field.
|
||||
func (u *CpLeaveUpsert) ClearDesc() *CpLeaveUpsert {
|
||||
u.SetNull(cpleave.FieldDesc)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.CpLeave.Create().
|
||||
// OnConflict(
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// Exec(ctx)
|
||||
func (u *CpLeaveUpsertOne) UpdateNewValues() *CpLeaveUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||
if _, exists := u.create.mutation.CreateTime(); exists {
|
||||
s.SetIgnore(cpleave.FieldCreateTime)
|
||||
}
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// Ignore sets each column to itself in case of conflict.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.CpLeave.Create().
|
||||
// OnConflict(sql.ResolveWithIgnore()).
|
||||
// Exec(ctx)
|
||||
func (u *CpLeaveUpsertOne) Ignore() *CpLeaveUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||
return u
|
||||
}
|
||||
|
||||
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||
// Supported only by SQLite and PostgreSQL.
|
||||
func (u *CpLeaveUpsertOne) DoNothing() *CpLeaveUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||
return u
|
||||
}
|
||||
|
||||
// Update allows overriding fields `UPDATE` values. See the CpLeaveCreate.OnConflict
|
||||
// documentation for more info.
|
||||
func (u *CpLeaveUpsertOne) Update(set func(*CpLeaveUpsert)) *CpLeaveUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||
set(&CpLeaveUpsert{UpdateSet: update})
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (u *CpLeaveUpsertOne) SetUpdateTime(v *ent2.CustomTime) *CpLeaveUpsertOne {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.SetUpdateTime(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsertOne) UpdateUpdateTime() *CpLeaveUpsertOne {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.UpdateUpdateTime()
|
||||
})
|
||||
}
|
||||
|
||||
// SetCpUserID sets the "cp_user_id" field.
|
||||
func (u *CpLeaveUpsertOne) SetCpUserID(v int64) *CpLeaveUpsertOne {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.SetCpUserID(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateCpUserID sets the "cp_user_id" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsertOne) UpdateCpUserID() *CpLeaveUpsertOne {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.UpdateCpUserID()
|
||||
})
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (u *CpLeaveUpsertOne) SetUserID(v int64) *CpLeaveUpsertOne {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.SetUserID(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsertOne) UpdateUserID() *CpLeaveUpsertOne {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.UpdateUserID()
|
||||
})
|
||||
}
|
||||
|
||||
// SetLeaveID sets the "leave_id" field.
|
||||
func (u *CpLeaveUpsertOne) SetLeaveID(v string) *CpLeaveUpsertOne {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.SetLeaveID(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateLeaveID sets the "leave_id" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsertOne) UpdateLeaveID() *CpLeaveUpsertOne {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.UpdateLeaveID()
|
||||
})
|
||||
}
|
||||
|
||||
// SetTitle sets the "title" field.
|
||||
func (u *CpLeaveUpsertOne) SetTitle(v string) *CpLeaveUpsertOne {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.SetTitle(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTitle sets the "title" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsertOne) UpdateTitle() *CpLeaveUpsertOne {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.UpdateTitle()
|
||||
})
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (u *CpLeaveUpsertOne) SetStatus(v cpleave.Status) *CpLeaveUpsertOne {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.SetStatus(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateStatus sets the "status" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsertOne) UpdateStatus() *CpLeaveUpsertOne {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.UpdateStatus()
|
||||
})
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (u *CpLeaveUpsertOne) SetType(v cpleave.Type) *CpLeaveUpsertOne {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.SetType(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateType sets the "type" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsertOne) UpdateType() *CpLeaveUpsertOne {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.UpdateType()
|
||||
})
|
||||
}
|
||||
|
||||
// SetDesc sets the "desc" field.
|
||||
func (u *CpLeaveUpsertOne) SetDesc(v string) *CpLeaveUpsertOne {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.SetDesc(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateDesc sets the "desc" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsertOne) UpdateDesc() *CpLeaveUpsertOne {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.UpdateDesc()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearDesc clears the value of the "desc" field.
|
||||
func (u *CpLeaveUpsertOne) ClearDesc() *CpLeaveUpsertOne {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.ClearDesc()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *CpLeaveUpsertOne) Exec(ctx context.Context) error {
|
||||
if len(u.create.conflict) == 0 {
|
||||
return errors.New("ent: missing options for CpLeaveCreate.OnConflict")
|
||||
}
|
||||
return u.create.Exec(ctx)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (u *CpLeaveUpsertOne) ExecX(ctx context.Context) {
|
||||
if err := u.create.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Exec executes the UPSERT query and returns the inserted/updated ID.
|
||||
func (u *CpLeaveUpsertOne) ID(ctx context.Context) (id int64, err error) {
|
||||
node, err := u.create.Save(ctx)
|
||||
if err != nil {
|
||||
return id, err
|
||||
}
|
||||
return node.ID, nil
|
||||
}
|
||||
|
||||
// IDX is like ID, but panics if an error occurs.
|
||||
func (u *CpLeaveUpsertOne) IDX(ctx context.Context) int64 {
|
||||
id, err := u.ID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// CpLeaveCreateBulk is the builder for creating many CpLeave entities in bulk.
|
||||
type CpLeaveCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*CpLeaveCreate
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// Save creates the CpLeave entities in the database.
|
||||
func (_c *CpLeaveCreateBulk) Save(ctx context.Context) ([]*CpLeave, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*CpLeave, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*CpLeaveMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
spec.OnConflict = _c.conflict
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int64(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *CpLeaveCreateBulk) SaveX(ctx context.Context) []*CpLeave {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *CpLeaveCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *CpLeaveCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||
// of the `INSERT` statement. For example:
|
||||
//
|
||||
// client.CpLeave.CreateBulk(builders...).
|
||||
// OnConflict(
|
||||
// // Update the row with the new values
|
||||
// // the was proposed for insertion.
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// // Override some of the fields with custom
|
||||
// // update values.
|
||||
// Update(func(u *ent.CpLeaveUpsert) {
|
||||
// SetCreateTime(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (_c *CpLeaveCreateBulk) OnConflict(opts ...sql.ConflictOption) *CpLeaveUpsertBulk {
|
||||
_c.conflict = opts
|
||||
return &CpLeaveUpsertBulk{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||
// as conflict target. Using this option is equivalent to using:
|
||||
//
|
||||
// client.CpLeave.Create().
|
||||
// OnConflict(sql.ConflictColumns(columns...)).
|
||||
// Exec(ctx)
|
||||
func (_c *CpLeaveCreateBulk) OnConflictColumns(columns ...string) *CpLeaveUpsertBulk {
|
||||
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
||||
return &CpLeaveUpsertBulk{
|
||||
create: _c,
|
||||
}
|
||||
}
|
||||
|
||||
// CpLeaveUpsertBulk is the builder for "upsert"-ing
|
||||
// a bulk of CpLeave nodes.
|
||||
type CpLeaveUpsertBulk struct {
|
||||
create *CpLeaveCreateBulk
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that
|
||||
// were set on create. Using this option is equivalent to using:
|
||||
//
|
||||
// client.CpLeave.Create().
|
||||
// OnConflict(
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// Exec(ctx)
|
||||
func (u *CpLeaveUpsertBulk) UpdateNewValues() *CpLeaveUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||
for _, b := range u.create.builders {
|
||||
if _, exists := b.mutation.CreateTime(); exists {
|
||||
s.SetIgnore(cpleave.FieldCreateTime)
|
||||
}
|
||||
}
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// Ignore sets each column to itself in case of conflict.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.CpLeave.Create().
|
||||
// OnConflict(sql.ResolveWithIgnore()).
|
||||
// Exec(ctx)
|
||||
func (u *CpLeaveUpsertBulk) Ignore() *CpLeaveUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||
return u
|
||||
}
|
||||
|
||||
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||
// Supported only by SQLite and PostgreSQL.
|
||||
func (u *CpLeaveUpsertBulk) DoNothing() *CpLeaveUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||
return u
|
||||
}
|
||||
|
||||
// Update allows overriding fields `UPDATE` values. See the CpLeaveCreateBulk.OnConflict
|
||||
// documentation for more info.
|
||||
func (u *CpLeaveUpsertBulk) Update(set func(*CpLeaveUpsert)) *CpLeaveUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||
set(&CpLeaveUpsert{UpdateSet: update})
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (u *CpLeaveUpsertBulk) SetUpdateTime(v *ent2.CustomTime) *CpLeaveUpsertBulk {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.SetUpdateTime(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsertBulk) UpdateUpdateTime() *CpLeaveUpsertBulk {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.UpdateUpdateTime()
|
||||
})
|
||||
}
|
||||
|
||||
// SetCpUserID sets the "cp_user_id" field.
|
||||
func (u *CpLeaveUpsertBulk) SetCpUserID(v int64) *CpLeaveUpsertBulk {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.SetCpUserID(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateCpUserID sets the "cp_user_id" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsertBulk) UpdateCpUserID() *CpLeaveUpsertBulk {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.UpdateCpUserID()
|
||||
})
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (u *CpLeaveUpsertBulk) SetUserID(v int64) *CpLeaveUpsertBulk {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.SetUserID(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsertBulk) UpdateUserID() *CpLeaveUpsertBulk {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.UpdateUserID()
|
||||
})
|
||||
}
|
||||
|
||||
// SetLeaveID sets the "leave_id" field.
|
||||
func (u *CpLeaveUpsertBulk) SetLeaveID(v string) *CpLeaveUpsertBulk {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.SetLeaveID(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateLeaveID sets the "leave_id" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsertBulk) UpdateLeaveID() *CpLeaveUpsertBulk {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.UpdateLeaveID()
|
||||
})
|
||||
}
|
||||
|
||||
// SetTitle sets the "title" field.
|
||||
func (u *CpLeaveUpsertBulk) SetTitle(v string) *CpLeaveUpsertBulk {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.SetTitle(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateTitle sets the "title" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsertBulk) UpdateTitle() *CpLeaveUpsertBulk {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.UpdateTitle()
|
||||
})
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (u *CpLeaveUpsertBulk) SetStatus(v cpleave.Status) *CpLeaveUpsertBulk {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.SetStatus(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateStatus sets the "status" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsertBulk) UpdateStatus() *CpLeaveUpsertBulk {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.UpdateStatus()
|
||||
})
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (u *CpLeaveUpsertBulk) SetType(v cpleave.Type) *CpLeaveUpsertBulk {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.SetType(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateType sets the "type" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsertBulk) UpdateType() *CpLeaveUpsertBulk {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.UpdateType()
|
||||
})
|
||||
}
|
||||
|
||||
// SetDesc sets the "desc" field.
|
||||
func (u *CpLeaveUpsertBulk) SetDesc(v string) *CpLeaveUpsertBulk {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.SetDesc(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateDesc sets the "desc" field to the value that was provided on create.
|
||||
func (u *CpLeaveUpsertBulk) UpdateDesc() *CpLeaveUpsertBulk {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.UpdateDesc()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearDesc clears the value of the "desc" field.
|
||||
func (u *CpLeaveUpsertBulk) ClearDesc() *CpLeaveUpsertBulk {
|
||||
return u.Update(func(s *CpLeaveUpsert) {
|
||||
s.ClearDesc()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *CpLeaveUpsertBulk) Exec(ctx context.Context) error {
|
||||
if u.create.err != nil {
|
||||
return u.create.err
|
||||
}
|
||||
for i, b := range u.create.builders {
|
||||
if len(b.conflict) != 0 {
|
||||
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the CpLeaveCreateBulk instead", i)
|
||||
}
|
||||
}
|
||||
if len(u.create.conflict) == 0 {
|
||||
return errors.New("ent: missing options for CpLeaveCreateBulk.OnConflict")
|
||||
}
|
||||
return u.create.Exec(ctx)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (u *CpLeaveUpsertBulk) ExecX(ctx context.Context) {
|
||||
if err := u.create.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"likedream-goframe/internal/ent/cpleave"
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CpLeaveDelete is the builder for deleting a CpLeave entity.
|
||||
type CpLeaveDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *CpLeaveMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CpLeaveDelete builder.
|
||||
func (_d *CpLeaveDelete) Where(ps ...predicate.CpLeave) *CpLeaveDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *CpLeaveDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *CpLeaveDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *CpLeaveDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(cpleave.Table, sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64))
|
||||
_spec.Node.Schema = _d.schemaConfig.CpLeave
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _d.schemaConfig)
|
||||
if ps := _d.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
_d.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// CpLeaveDeleteOne is the builder for deleting a single CpLeave entity.
|
||||
type CpLeaveDeleteOne struct {
|
||||
_d *CpLeaveDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CpLeaveDelete builder.
|
||||
func (_d *CpLeaveDeleteOne) Where(ps ...predicate.CpLeave) *CpLeaveDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *CpLeaveDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{cpleave.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *CpLeaveDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,745 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/cpleave"
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CpLeaveQuery is the builder for querying CpLeave entities.
|
||||
type CpLeaveQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []cpleave.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.CpLeave
|
||||
withCpUser *CpUserQuery
|
||||
withSysUser *SysUserQuery
|
||||
modifiers []func(*sql.Selector)
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the CpLeaveQuery builder.
|
||||
func (_q *CpLeaveQuery) Where(ps ...predicate.CpLeave) *CpLeaveQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *CpLeaveQuery) Limit(limit int) *CpLeaveQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *CpLeaveQuery) Offset(offset int) *CpLeaveQuery {
|
||||
_q.ctx.Offset = &offset
|
||||
return _q
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (_q *CpLeaveQuery) Unique(unique bool) *CpLeaveQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *CpLeaveQuery) Order(o ...cpleave.OrderOption) *CpLeaveQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryCpUser chains the current query on the "cp_user" edge.
|
||||
func (_q *CpLeaveQuery) QueryCpUser() *CpUserQuery {
|
||||
query := (&CpUserClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(cpleave.Table, cpleave.FieldID, selector),
|
||||
sqlgraph.To(cpuser.Table, cpuser.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, cpleave.CpUserTable, cpleave.CpUserColumn),
|
||||
)
|
||||
schemaConfig := _q.schemaConfig
|
||||
step.To.Schema = schemaConfig.CpUser
|
||||
step.Edge.Schema = schemaConfig.CpLeave
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QuerySysUser chains the current query on the "sys_user" edge.
|
||||
func (_q *CpLeaveQuery) QuerySysUser() *SysUserQuery {
|
||||
query := (&SysUserClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(cpleave.Table, cpleave.FieldID, selector),
|
||||
sqlgraph.To(sysuser.Table, sysuser.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, cpleave.SysUserTable, cpleave.SysUserColumn),
|
||||
)
|
||||
schemaConfig := _q.schemaConfig
|
||||
step.To.Schema = schemaConfig.SysUser
|
||||
step.Edge.Schema = schemaConfig.CpLeave
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first CpLeave entity from the query.
|
||||
// Returns a *NotFoundError when no CpLeave was found.
|
||||
func (_q *CpLeaveQuery) First(ctx context.Context) (*CpLeave, error) {
|
||||
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{cpleave.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *CpLeaveQuery) FirstX(ctx context.Context) *CpLeave {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first CpLeave ID from the query.
|
||||
// Returns a *NotFoundError when no CpLeave ID was found.
|
||||
func (_q *CpLeaveQuery) FirstID(ctx context.Context) (id int64, err error) {
|
||||
var ids []int64
|
||||
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{cpleave.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *CpLeaveQuery) FirstIDX(ctx context.Context) int64 {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single CpLeave entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one CpLeave entity is found.
|
||||
// Returns a *NotFoundError when no CpLeave entities are found.
|
||||
func (_q *CpLeaveQuery) Only(ctx context.Context) (*CpLeave, error) {
|
||||
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{cpleave.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{cpleave.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *CpLeaveQuery) OnlyX(ctx context.Context) *CpLeave {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only CpLeave ID in the query.
|
||||
// Returns a *NotSingularError when more than one CpLeave ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *CpLeaveQuery) OnlyID(ctx context.Context) (id int64, err error) {
|
||||
var ids []int64
|
||||
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{cpleave.Label}
|
||||
default:
|
||||
err = &NotSingularError{cpleave.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *CpLeaveQuery) OnlyIDX(ctx context.Context) int64 {
|
||||
id, err := _q.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of CpLeaves.
|
||||
func (_q *CpLeaveQuery) All(ctx context.Context) ([]*CpLeave, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*CpLeave, *CpLeaveQuery]()
|
||||
return withInterceptors[[]*CpLeave](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *CpLeaveQuery) AllX(ctx context.Context) []*CpLeave {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of CpLeave IDs.
|
||||
func (_q *CpLeaveQuery) IDs(ctx context.Context) (ids []int64, err error) {
|
||||
if _q.ctx.Unique == nil && _q.path != nil {
|
||||
_q.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||
if err = _q.Select(cpleave.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *CpLeaveQuery) IDsX(ctx context.Context) []int64 {
|
||||
ids, err := _q.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (_q *CpLeaveQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, _q, querierCount[*CpLeaveQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *CpLeaveQuery) CountX(ctx context.Context) int {
|
||||
count, err := _q.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (_q *CpLeaveQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
|
||||
switch _, err := _q.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *CpLeaveQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the CpLeaveQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (_q *CpLeaveQuery) Clone() *CpLeaveQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &CpLeaveQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]cpleave.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.CpLeave{}, _q.predicates...),
|
||||
withCpUser: _q.withCpUser.Clone(),
|
||||
withSysUser: _q.withSysUser.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
modifiers: append([]func(*sql.Selector){}, _q.modifiers...),
|
||||
}
|
||||
}
|
||||
|
||||
// WithCpUser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "cp_user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *CpLeaveQuery) WithCpUser(opts ...func(*CpUserQuery)) *CpLeaveQuery {
|
||||
query := (&CpUserClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withCpUser = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// WithSysUser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "sys_user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *CpLeaveQuery) WithSysUser(opts ...func(*SysUserQuery)) *CpLeaveQuery {
|
||||
query := (&SysUserClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withSysUser = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreateTime *ent2.CustomTime `json:"createTime"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.CpLeave.Query().
|
||||
// GroupBy(cpleave.FieldCreateTime).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *CpLeaveQuery) GroupBy(field string, fields ...string) *CpLeaveGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &CpLeaveGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = cpleave.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreateTime *ent2.CustomTime `json:"createTime"`
|
||||
// }
|
||||
//
|
||||
// client.CpLeave.Query().
|
||||
// Select(cpleave.FieldCreateTime).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *CpLeaveQuery) Select(fields ...string) *CpLeaveSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &CpLeaveSelect{CpLeaveQuery: _q}
|
||||
sbuild.label = cpleave.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a CpLeaveSelect configured with the given aggregations.
|
||||
func (_q *CpLeaveQuery) Aggregate(fns ...AggregateFunc) *CpLeaveSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *CpLeaveQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !cpleave.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if _q.path != nil {
|
||||
prev, err := _q.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_q.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *CpLeaveQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CpLeave, error) {
|
||||
var (
|
||||
nodes = []*CpLeave{}
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [2]bool{
|
||||
_q.withCpUser != nil,
|
||||
_q.withSysUser != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*CpLeave).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &CpLeave{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
_spec.Node.Schema = _q.schemaConfig.CpLeave
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _q.schemaConfig)
|
||||
if len(_q.modifiers) > 0 {
|
||||
_spec.Modifiers = _q.modifiers
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := _q.withCpUser; query != nil {
|
||||
if err := _q.loadCpUser(ctx, query, nodes, nil,
|
||||
func(n *CpLeave, e *CpUser) { n.Edges.CpUser = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := _q.withSysUser; query != nil {
|
||||
if err := _q.loadSysUser(ctx, query, nodes, nil,
|
||||
func(n *CpLeave, e *SysUser) { n.Edges.SysUser = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *CpLeaveQuery) loadCpUser(ctx context.Context, query *CpUserQuery, nodes []*CpLeave, init func(*CpLeave), assign func(*CpLeave, *CpUser)) error {
|
||||
ids := make([]int64, 0, len(nodes))
|
||||
nodeids := make(map[int64][]*CpLeave)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].CpUserID
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(cpuser.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "cp_user_id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (_q *CpLeaveQuery) loadSysUser(ctx context.Context, query *SysUserQuery, nodes []*CpLeave, init func(*CpLeave), assign func(*CpLeave, *SysUser)) error {
|
||||
ids := make([]int64, 0, len(nodes))
|
||||
nodeids := make(map[int64][]*CpLeave)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].UserID
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(sysuser.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "user_id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *CpLeaveQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
_spec.Node.Schema = _q.schemaConfig.CpLeave
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _q.schemaConfig)
|
||||
if len(_q.modifiers) > 0 {
|
||||
_spec.Modifiers = _q.modifiers
|
||||
}
|
||||
_spec.Node.Columns = _q.ctx.Fields
|
||||
if len(_q.ctx.Fields) > 0 {
|
||||
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
|
||||
}
|
||||
|
||||
func (_q *CpLeaveQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(cpleave.Table, cpleave.Columns, sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64))
|
||||
_spec.From = _q.sql
|
||||
if unique := _q.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if _q.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, cpleave.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != cpleave.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
if _q.withCpUser != nil {
|
||||
_spec.Node.AddColumnOnce(cpleave.FieldCpUserID)
|
||||
}
|
||||
if _q.withSysUser != nil {
|
||||
_spec.Node.AddColumnOnce(cpleave.FieldUserID)
|
||||
}
|
||||
}
|
||||
if ps := _q.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := _q.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (_q *CpLeaveQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(cpleave.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = cpleave.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if _q.sql != nil {
|
||||
selector = _q.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
t1.Schema(_q.schemaConfig.CpLeave)
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _q.schemaConfig)
|
||||
selector.WithContext(ctx)
|
||||
for _, m := range _q.modifiers {
|
||||
m(selector)
|
||||
}
|
||||
for _, p := range _q.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range _q.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
|
||||
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
|
||||
// either committed or rolled-back.
|
||||
func (_q *CpLeaveQuery) ForUpdate(opts ...sql.LockOption) *CpLeaveQuery {
|
||||
if _q.driver.Dialect() == dialect.Postgres {
|
||||
_q.Unique(false)
|
||||
}
|
||||
_q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
|
||||
s.ForUpdate(opts...)
|
||||
})
|
||||
return _q
|
||||
}
|
||||
|
||||
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
|
||||
// on any rows that are read. Other sessions can read the rows, but cannot modify them
|
||||
// until your transaction commits.
|
||||
func (_q *CpLeaveQuery) ForShare(opts ...sql.LockOption) *CpLeaveQuery {
|
||||
if _q.driver.Dialect() == dialect.Postgres {
|
||||
_q.Unique(false)
|
||||
}
|
||||
_q.modifiers = append(_q.modifiers, func(s *sql.Selector) {
|
||||
s.ForShare(opts...)
|
||||
})
|
||||
return _q
|
||||
}
|
||||
|
||||
// Modify adds a query modifier for attaching custom logic to queries.
|
||||
func (_q *CpLeaveQuery) Modify(modifiers ...func(s *sql.Selector)) *CpLeaveSelect {
|
||||
_q.modifiers = append(_q.modifiers, modifiers...)
|
||||
return _q.Select()
|
||||
}
|
||||
|
||||
// CpLeaveGroupBy is the group-by builder for CpLeave entities.
|
||||
type CpLeaveGroupBy struct {
|
||||
selector
|
||||
build *CpLeaveQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *CpLeaveGroupBy) Aggregate(fns ...AggregateFunc) *CpLeaveGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *CpLeaveGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*CpLeaveQuery, *CpLeaveGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *CpLeaveGroupBy) sqlScan(ctx context.Context, root *CpLeaveQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(_g.fns))
|
||||
for _, fn := range _g.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||
for _, f := range *_g.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// CpLeaveSelect is the builder for selecting fields of CpLeave entities.
|
||||
type CpLeaveSelect struct {
|
||||
*CpLeaveQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *CpLeaveSelect) Aggregate(fns ...AggregateFunc) *CpLeaveSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *CpLeaveSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||
if err := _s.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*CpLeaveQuery, *CpLeaveSelect](ctx, _s.CpLeaveQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *CpLeaveSelect) sqlScan(ctx context.Context, root *CpLeaveQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*_s.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// Modify adds a query modifier for attaching custom logic to queries.
|
||||
func (_s *CpLeaveSelect) Modify(modifiers ...func(s *sql.Selector)) *CpLeaveSelect {
|
||||
_s.modifiers = append(_s.modifiers, modifiers...)
|
||||
return _s
|
||||
}
|
||||
@@ -0,0 +1,709 @@
|
||||
// ENT数据库文件,请勿编辑。
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/cpleave"
|
||||
"likedream-goframe/internal/ent/cpuser"
|
||||
"likedream-goframe/internal/ent/internal"
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CpLeaveUpdate is the builder for updating CpLeave entities.
|
||||
type CpLeaveUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *CpLeaveMutation
|
||||
modifiers []func(*sql.UpdateBuilder)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CpLeaveUpdate builder.
|
||||
func (_u *CpLeaveUpdate) Where(ps ...predicate.CpLeave) *CpLeaveUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (_u *CpLeaveUpdate) SetUpdateTime(v *ent2.CustomTime) *CpLeaveUpdate {
|
||||
_u.mutation.SetUpdateTime(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCpUserID sets the "cp_user_id" field.
|
||||
func (_u *CpLeaveUpdate) SetCpUserID(v int64) *CpLeaveUpdate {
|
||||
_u.mutation.SetCpUserID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCpUserID sets the "cp_user_id" field if the given value is not nil.
|
||||
func (_u *CpLeaveUpdate) SetNillableCpUserID(v *int64) *CpLeaveUpdate {
|
||||
if v != nil {
|
||||
_u.SetCpUserID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (_u *CpLeaveUpdate) SetUserID(v int64) *CpLeaveUpdate {
|
||||
_u.mutation.SetUserID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||
func (_u *CpLeaveUpdate) SetNillableUserID(v *int64) *CpLeaveUpdate {
|
||||
if v != nil {
|
||||
_u.SetUserID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetLeaveID sets the "leave_id" field.
|
||||
func (_u *CpLeaveUpdate) SetLeaveID(v string) *CpLeaveUpdate {
|
||||
_u.mutation.SetLeaveID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableLeaveID sets the "leave_id" field if the given value is not nil.
|
||||
func (_u *CpLeaveUpdate) SetNillableLeaveID(v *string) *CpLeaveUpdate {
|
||||
if v != nil {
|
||||
_u.SetLeaveID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetTitle sets the "title" field.
|
||||
func (_u *CpLeaveUpdate) SetTitle(v string) *CpLeaveUpdate {
|
||||
_u.mutation.SetTitle(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableTitle sets the "title" field if the given value is not nil.
|
||||
func (_u *CpLeaveUpdate) SetNillableTitle(v *string) *CpLeaveUpdate {
|
||||
if v != nil {
|
||||
_u.SetTitle(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_u *CpLeaveUpdate) SetStatus(v cpleave.Status) *CpLeaveUpdate {
|
||||
_u.mutation.SetStatus(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (_u *CpLeaveUpdate) SetNillableStatus(v *cpleave.Status) *CpLeaveUpdate {
|
||||
if v != nil {
|
||||
_u.SetStatus(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (_u *CpLeaveUpdate) SetType(v cpleave.Type) *CpLeaveUpdate {
|
||||
_u.mutation.SetType(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (_u *CpLeaveUpdate) SetNillableType(v *cpleave.Type) *CpLeaveUpdate {
|
||||
if v != nil {
|
||||
_u.SetType(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetDesc sets the "desc" field.
|
||||
func (_u *CpLeaveUpdate) SetDesc(v string) *CpLeaveUpdate {
|
||||
_u.mutation.SetDesc(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableDesc sets the "desc" field if the given value is not nil.
|
||||
func (_u *CpLeaveUpdate) SetNillableDesc(v *string) *CpLeaveUpdate {
|
||||
if v != nil {
|
||||
_u.SetDesc(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearDesc clears the value of the "desc" field.
|
||||
func (_u *CpLeaveUpdate) ClearDesc() *CpLeaveUpdate {
|
||||
_u.mutation.ClearDesc()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCpUser sets the "cp_user" edge to the CpUser entity.
|
||||
func (_u *CpLeaveUpdate) SetCpUser(v *CpUser) *CpLeaveUpdate {
|
||||
return _u.SetCpUserID(v.ID)
|
||||
}
|
||||
|
||||
// SetSysUserID sets the "sys_user" edge to the SysUser entity by ID.
|
||||
func (_u *CpLeaveUpdate) SetSysUserID(id int64) *CpLeaveUpdate {
|
||||
_u.mutation.SetSysUserID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetSysUser sets the "sys_user" edge to the SysUser entity.
|
||||
func (_u *CpLeaveUpdate) SetSysUser(v *SysUser) *CpLeaveUpdate {
|
||||
return _u.SetSysUserID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the CpLeaveMutation object of the builder.
|
||||
func (_u *CpLeaveUpdate) Mutation() *CpLeaveMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearCpUser clears the "cp_user" edge to the CpUser entity.
|
||||
func (_u *CpLeaveUpdate) ClearCpUser() *CpLeaveUpdate {
|
||||
_u.mutation.ClearCpUser()
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearSysUser clears the "sys_user" edge to the SysUser entity.
|
||||
func (_u *CpLeaveUpdate) ClearSysUser() *CpLeaveUpdate {
|
||||
_u.mutation.ClearSysUser()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *CpLeaveUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *CpLeaveUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *CpLeaveUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *CpLeaveUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *CpLeaveUpdate) check() error {
|
||||
if v, ok := _u.mutation.LeaveID(); ok {
|
||||
if err := cpleave.LeaveIDValidator(v); err != nil {
|
||||
return &ValidationError{Name: "leave_id", err: fmt.Errorf(`ent: validator failed for field "CpLeave.leave_id": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Title(); ok {
|
||||
if err := cpleave.TitleValidator(v); err != nil {
|
||||
return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "CpLeave.title": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Status(); ok {
|
||||
if err := cpleave.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "CpLeave.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.GetType(); ok {
|
||||
if err := cpleave.TypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "CpLeave.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _u.mutation.CpUserCleared() && len(_u.mutation.CpUserIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "CpLeave.cp_user"`)
|
||||
}
|
||||
if _u.mutation.SysUserCleared() && len(_u.mutation.SysUserIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "CpLeave.sys_user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
||||
func (_u *CpLeaveUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *CpLeaveUpdate {
|
||||
_u.modifiers = append(_u.modifiers, modifiers...)
|
||||
return _u
|
||||
}
|
||||
|
||||
func (_u *CpLeaveUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(cpleave.Table, cpleave.Columns, sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64))
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.UpdateTime(); ok {
|
||||
_spec.SetField(cpleave.FieldUpdateTime, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.LeaveID(); ok {
|
||||
_spec.SetField(cpleave.FieldLeaveID, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Title(); ok {
|
||||
_spec.SetField(cpleave.FieldTitle, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Status(); ok {
|
||||
_spec.SetField(cpleave.FieldStatus, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.GetType(); ok {
|
||||
_spec.SetField(cpleave.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Desc(); ok {
|
||||
_spec.SetField(cpleave.FieldDesc, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.DescCleared() {
|
||||
_spec.ClearField(cpleave.FieldDesc, field.TypeString)
|
||||
}
|
||||
if _u.mutation.CpUserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: cpleave.CpUserTable,
|
||||
Columns: []string{cpleave.CpUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.CpLeave
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.CpUserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: cpleave.CpUserTable,
|
||||
Columns: []string{cpleave.CpUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.CpLeave
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.SysUserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: cpleave.SysUserTable,
|
||||
Columns: []string{cpleave.SysUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.CpLeave
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.SysUserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: cpleave.SysUserTable,
|
||||
Columns: []string{cpleave.SysUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.CpLeave
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_spec.Node.Schema = _u.schemaConfig.CpLeave
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _u.schemaConfig)
|
||||
_spec.AddModifiers(_u.modifiers...)
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{cpleave.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// CpLeaveUpdateOne is the builder for updating a single CpLeave entity.
|
||||
type CpLeaveUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *CpLeaveMutation
|
||||
modifiers []func(*sql.UpdateBuilder)
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (_u *CpLeaveUpdateOne) SetUpdateTime(v *ent2.CustomTime) *CpLeaveUpdateOne {
|
||||
_u.mutation.SetUpdateTime(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCpUserID sets the "cp_user_id" field.
|
||||
func (_u *CpLeaveUpdateOne) SetCpUserID(v int64) *CpLeaveUpdateOne {
|
||||
_u.mutation.SetCpUserID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCpUserID sets the "cp_user_id" field if the given value is not nil.
|
||||
func (_u *CpLeaveUpdateOne) SetNillableCpUserID(v *int64) *CpLeaveUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetCpUserID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (_u *CpLeaveUpdateOne) SetUserID(v int64) *CpLeaveUpdateOne {
|
||||
_u.mutation.SetUserID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||
func (_u *CpLeaveUpdateOne) SetNillableUserID(v *int64) *CpLeaveUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUserID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetLeaveID sets the "leave_id" field.
|
||||
func (_u *CpLeaveUpdateOne) SetLeaveID(v string) *CpLeaveUpdateOne {
|
||||
_u.mutation.SetLeaveID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableLeaveID sets the "leave_id" field if the given value is not nil.
|
||||
func (_u *CpLeaveUpdateOne) SetNillableLeaveID(v *string) *CpLeaveUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetLeaveID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetTitle sets the "title" field.
|
||||
func (_u *CpLeaveUpdateOne) SetTitle(v string) *CpLeaveUpdateOne {
|
||||
_u.mutation.SetTitle(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableTitle sets the "title" field if the given value is not nil.
|
||||
func (_u *CpLeaveUpdateOne) SetNillableTitle(v *string) *CpLeaveUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetTitle(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_u *CpLeaveUpdateOne) SetStatus(v cpleave.Status) *CpLeaveUpdateOne {
|
||||
_u.mutation.SetStatus(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (_u *CpLeaveUpdateOne) SetNillableStatus(v *cpleave.Status) *CpLeaveUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetStatus(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (_u *CpLeaveUpdateOne) SetType(v cpleave.Type) *CpLeaveUpdateOne {
|
||||
_u.mutation.SetType(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (_u *CpLeaveUpdateOne) SetNillableType(v *cpleave.Type) *CpLeaveUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetType(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetDesc sets the "desc" field.
|
||||
func (_u *CpLeaveUpdateOne) SetDesc(v string) *CpLeaveUpdateOne {
|
||||
_u.mutation.SetDesc(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableDesc sets the "desc" field if the given value is not nil.
|
||||
func (_u *CpLeaveUpdateOne) SetNillableDesc(v *string) *CpLeaveUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetDesc(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearDesc clears the value of the "desc" field.
|
||||
func (_u *CpLeaveUpdateOne) ClearDesc() *CpLeaveUpdateOne {
|
||||
_u.mutation.ClearDesc()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCpUser sets the "cp_user" edge to the CpUser entity.
|
||||
func (_u *CpLeaveUpdateOne) SetCpUser(v *CpUser) *CpLeaveUpdateOne {
|
||||
return _u.SetCpUserID(v.ID)
|
||||
}
|
||||
|
||||
// SetSysUserID sets the "sys_user" edge to the SysUser entity by ID.
|
||||
func (_u *CpLeaveUpdateOne) SetSysUserID(id int64) *CpLeaveUpdateOne {
|
||||
_u.mutation.SetSysUserID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetSysUser sets the "sys_user" edge to the SysUser entity.
|
||||
func (_u *CpLeaveUpdateOne) SetSysUser(v *SysUser) *CpLeaveUpdateOne {
|
||||
return _u.SetSysUserID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the CpLeaveMutation object of the builder.
|
||||
func (_u *CpLeaveUpdateOne) Mutation() *CpLeaveMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearCpUser clears the "cp_user" edge to the CpUser entity.
|
||||
func (_u *CpLeaveUpdateOne) ClearCpUser() *CpLeaveUpdateOne {
|
||||
_u.mutation.ClearCpUser()
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearSysUser clears the "sys_user" edge to the SysUser entity.
|
||||
func (_u *CpLeaveUpdateOne) ClearSysUser() *CpLeaveUpdateOne {
|
||||
_u.mutation.ClearSysUser()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CpLeaveUpdate builder.
|
||||
func (_u *CpLeaveUpdateOne) Where(ps ...predicate.CpLeave) *CpLeaveUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (_u *CpLeaveUpdateOne) Select(field string, fields ...string) *CpLeaveUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated CpLeave entity.
|
||||
func (_u *CpLeaveUpdateOne) Save(ctx context.Context) (*CpLeave, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *CpLeaveUpdateOne) SaveX(ctx context.Context) *CpLeave {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *CpLeaveUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *CpLeaveUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *CpLeaveUpdateOne) check() error {
|
||||
if v, ok := _u.mutation.LeaveID(); ok {
|
||||
if err := cpleave.LeaveIDValidator(v); err != nil {
|
||||
return &ValidationError{Name: "leave_id", err: fmt.Errorf(`ent: validator failed for field "CpLeave.leave_id": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Title(); ok {
|
||||
if err := cpleave.TitleValidator(v); err != nil {
|
||||
return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "CpLeave.title": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Status(); ok {
|
||||
if err := cpleave.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "CpLeave.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.GetType(); ok {
|
||||
if err := cpleave.TypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "CpLeave.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _u.mutation.CpUserCleared() && len(_u.mutation.CpUserIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "CpLeave.cp_user"`)
|
||||
}
|
||||
if _u.mutation.SysUserCleared() && len(_u.mutation.SysUserIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "CpLeave.sys_user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
||||
func (_u *CpLeaveUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *CpLeaveUpdateOne {
|
||||
_u.modifiers = append(_u.modifiers, modifiers...)
|
||||
return _u
|
||||
}
|
||||
|
||||
func (_u *CpLeaveUpdateOne) sqlSave(ctx context.Context) (_node *CpLeave, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(cpleave.Table, cpleave.Columns, sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "CpLeave.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, cpleave.FieldID)
|
||||
for _, f := range fields {
|
||||
if !cpleave.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != cpleave.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.UpdateTime(); ok {
|
||||
_spec.SetField(cpleave.FieldUpdateTime, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.LeaveID(); ok {
|
||||
_spec.SetField(cpleave.FieldLeaveID, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Title(); ok {
|
||||
_spec.SetField(cpleave.FieldTitle, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Status(); ok {
|
||||
_spec.SetField(cpleave.FieldStatus, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.GetType(); ok {
|
||||
_spec.SetField(cpleave.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Desc(); ok {
|
||||
_spec.SetField(cpleave.FieldDesc, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.DescCleared() {
|
||||
_spec.ClearField(cpleave.FieldDesc, field.TypeString)
|
||||
}
|
||||
if _u.mutation.CpUserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: cpleave.CpUserTable,
|
||||
Columns: []string{cpleave.CpUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.CpLeave
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.CpUserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: cpleave.CpUserTable,
|
||||
Columns: []string{cpleave.CpUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cpuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.CpLeave
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.SysUserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: cpleave.SysUserTable,
|
||||
Columns: []string{cpleave.SysUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.CpLeave
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.SysUserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: cpleave.SysUserTable,
|
||||
Columns: []string{cpleave.SysUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.CpLeave
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_spec.Node.Schema = _u.schemaConfig.CpLeave
|
||||
ctx = internal.NewSchemaConfigContext(ctx, _u.schemaConfig)
|
||||
_spec.AddModifiers(_u.modifiers...)
|
||||
_node = &CpLeave{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{cpleave.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
@@ -411,7 +411,7 @@ func (_q *CpSchoolQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CpS
|
||||
func(n *CpSchool) { n.Edges.Cpusers = []*CpUser{} },
|
||||
func(n *CpSchool, e *CpUser) {
|
||||
n.Edges.Cpusers = append(n.Edges.Cpusers, e)
|
||||
if !e.Edges.loadedTypes[3] {
|
||||
if !e.Edges.loadedTypes[4] {
|
||||
e.Edges.School = n
|
||||
}
|
||||
}); err != nil {
|
||||
@@ -423,7 +423,7 @@ func (_q *CpSchoolQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CpS
|
||||
func(n *CpSchool) { n.appendNamedCpusers(name) },
|
||||
func(n *CpSchool, e *CpUser) {
|
||||
n.appendNamedCpusers(name, e)
|
||||
if !e.Edges.loadedTypes[3] {
|
||||
if !e.Edges.loadedTypes[4] {
|
||||
e.Edges.School = n
|
||||
}
|
||||
}); err != nil {
|
||||
|
||||
+57
-5
@@ -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"`
|
||||
@@ -49,6 +51,8 @@ type CpUser struct {
|
||||
type CpUserEdges struct {
|
||||
// Cptasks holds the value of the cptasks edge.
|
||||
Cptasks []*CpTask `json:"cptasks,omitempty"`
|
||||
// CpLeave holds the value of the cp_leave edge.
|
||||
CpLeave []*CpLeave `json:"cp_leave,omitempty"`
|
||||
// Sysuser holds the value of the sysuser edge.
|
||||
Sysuser *SysUser `json:"sysuser,omitempty"`
|
||||
// CpTaskLogs holds the value of the cp_task_logs edge.
|
||||
@@ -57,8 +61,9 @@ type CpUserEdges struct {
|
||||
School *CpSchool `json:"school,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [4]bool
|
||||
loadedTypes [5]bool
|
||||
namedCptasks map[string][]*CpTask
|
||||
namedCpLeave map[string][]*CpLeave
|
||||
namedCpTaskLogs map[string][]*CpTaskLog
|
||||
}
|
||||
|
||||
@@ -71,12 +76,21 @@ func (e CpUserEdges) CptasksOrErr() ([]*CpTask, error) {
|
||||
return nil, &NotLoadedError{edge: "cptasks"}
|
||||
}
|
||||
|
||||
// CpLeaveOrErr returns the CpLeave value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e CpUserEdges) CpLeaveOrErr() ([]*CpLeave, error) {
|
||||
if e.loadedTypes[1] {
|
||||
return e.CpLeave, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "cp_leave"}
|
||||
}
|
||||
|
||||
// SysuserOrErr returns the Sysuser value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e CpUserEdges) SysuserOrErr() (*SysUser, error) {
|
||||
if e.Sysuser != nil {
|
||||
return e.Sysuser, nil
|
||||
} else if e.loadedTypes[1] {
|
||||
} else if e.loadedTypes[2] {
|
||||
return nil, &NotFoundError{label: sysuser.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "sysuser"}
|
||||
@@ -85,7 +99,7 @@ func (e CpUserEdges) SysuserOrErr() (*SysUser, error) {
|
||||
// CpTaskLogsOrErr returns the CpTaskLogs value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e CpUserEdges) CpTaskLogsOrErr() ([]*CpTaskLog, error) {
|
||||
if e.loadedTypes[2] {
|
||||
if e.loadedTypes[3] {
|
||||
return e.CpTaskLogs, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "cp_task_logs"}
|
||||
@@ -96,7 +110,7 @@ func (e CpUserEdges) CpTaskLogsOrErr() ([]*CpTaskLog, error) {
|
||||
func (e CpUserEdges) SchoolOrErr() (*CpSchool, error) {
|
||||
if e.School != nil {
|
||||
return e.School, nil
|
||||
} else if e.loadedTypes[3] {
|
||||
} else if e.loadedTypes[4] {
|
||||
return nil, &NotFoundError{label: cpschool.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "school"}
|
||||
@@ -111,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)
|
||||
@@ -194,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])
|
||||
}
|
||||
@@ -212,6 +232,11 @@ func (_m *CpUser) QueryCptasks() *CpTaskQuery {
|
||||
return NewCpUserClient(_m.config).QueryCptasks(_m)
|
||||
}
|
||||
|
||||
// QueryCpLeave queries the "cp_leave" edge of the CpUser entity.
|
||||
func (_m *CpUser) QueryCpLeave() *CpLeaveQuery {
|
||||
return NewCpUserClient(_m.config).QueryCpLeave(_m)
|
||||
}
|
||||
|
||||
// QuerySysuser queries the "sysuser" edge of the CpUser entity.
|
||||
func (_m *CpUser) QuerySysuser() *SysUserQuery {
|
||||
return NewCpUserClient(_m.config).QuerySysuser(_m)
|
||||
@@ -279,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()
|
||||
}
|
||||
@@ -307,6 +335,30 @@ func (_m *CpUser) appendNamedCptasks(name string, edges ...*CpTask) {
|
||||
}
|
||||
}
|
||||
|
||||
// NamedCpLeave returns the CpLeave named value or an error if the edge was not
|
||||
// loaded in eager-loading with this name.
|
||||
func (_m *CpUser) NamedCpLeave(name string) ([]*CpLeave, error) {
|
||||
if _m.Edges.namedCpLeave == nil {
|
||||
return nil, &NotLoadedError{edge: name}
|
||||
}
|
||||
nodes, ok := _m.Edges.namedCpLeave[name]
|
||||
if !ok {
|
||||
return nil, &NotLoadedError{edge: name}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_m *CpUser) appendNamedCpLeave(name string, edges ...*CpLeave) {
|
||||
if _m.Edges.namedCpLeave == nil {
|
||||
_m.Edges.namedCpLeave = make(map[string][]*CpLeave)
|
||||
}
|
||||
if len(edges) == 0 {
|
||||
_m.Edges.namedCpLeave[name] = []*CpLeave{}
|
||||
} else {
|
||||
_m.Edges.namedCpLeave[name] = append(_m.Edges.namedCpLeave[name], edges...)
|
||||
}
|
||||
}
|
||||
|
||||
// NamedCpTaskLogs returns the CpTaskLogs named value or an error if the edge was not
|
||||
// loaded in eager-loading with this name.
|
||||
func (_m *CpUser) NamedCpTaskLogs(name string) ([]*CpTaskLog, error) {
|
||||
|
||||
@@ -36,8 +36,12 @@ 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.
|
||||
EdgeCpLeave = "cp_leave"
|
||||
// EdgeSysuser holds the string denoting the sysuser edge name in mutations.
|
||||
EdgeSysuser = "sysuser"
|
||||
// EdgeCpTaskLogs holds the string denoting the cp_task_logs edge name in mutations.
|
||||
@@ -53,6 +57,13 @@ const (
|
||||
CptasksInverseTable = "cp_tasks"
|
||||
// CptasksColumn is the table column denoting the cptasks relation/edge.
|
||||
CptasksColumn = "cp_user_id"
|
||||
// CpLeaveTable is the table that holds the cp_leave relation/edge.
|
||||
CpLeaveTable = "cp_leaves"
|
||||
// CpLeaveInverseTable is the table name for the CpLeave entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "cpleave" package.
|
||||
CpLeaveInverseTable = "cp_leaves"
|
||||
// CpLeaveColumn is the table column denoting the cp_leave relation/edge.
|
||||
CpLeaveColumn = "cp_user_id"
|
||||
// SysuserTable is the table that holds the sysuser relation/edge.
|
||||
SysuserTable = "cp_users"
|
||||
// SysuserInverseTable is the table name for the SysUser entity.
|
||||
@@ -89,6 +100,7 @@ var Columns = []string{
|
||||
FieldMobileCode,
|
||||
FieldCookie,
|
||||
FieldMobileType,
|
||||
FieldLoginType,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
@@ -114,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
|
||||
)
|
||||
@@ -143,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)
|
||||
|
||||
@@ -201,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) {
|
||||
@@ -215,6 +256,20 @@ func ByCptasks(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
}
|
||||
}
|
||||
|
||||
// ByCpLeaveCount orders the results by cp_leave count.
|
||||
func ByCpLeaveCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newCpLeaveStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByCpLeave orders the results by cp_leave terms.
|
||||
func ByCpLeave(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newCpLeaveStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
|
||||
// BySysuserField orders the results by sysuser field.
|
||||
func BySysuserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
@@ -249,6 +304,13 @@ func newCptasksStep() *sqlgraph.Step {
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, CptasksTable, CptasksColumn),
|
||||
)
|
||||
}
|
||||
func newCpLeaveStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(CpLeaveInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, CpLeaveTable, CpLeaveColumn),
|
||||
)
|
||||
}
|
||||
func newSysuserStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
|
||||
@@ -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) {
|
||||
@@ -730,6 +760,35 @@ func HasCptasksWith(preds ...predicate.CpTask) predicate.CpUser {
|
||||
})
|
||||
}
|
||||
|
||||
// HasCpLeave applies the HasEdge predicate on the "cp_leave" edge.
|
||||
func HasCpLeave() predicate.CpUser {
|
||||
return predicate.CpUser(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, CpLeaveTable, CpLeaveColumn),
|
||||
)
|
||||
schemaConfig := internal.SchemaConfigFromContext(s.Context())
|
||||
step.To.Schema = schemaConfig.CpLeave
|
||||
step.Edge.Schema = schemaConfig.CpLeave
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasCpLeaveWith applies the HasEdge predicate on the "cp_leave" edge with a given conditions (other predicates).
|
||||
func HasCpLeaveWith(preds ...predicate.CpLeave) predicate.CpUser {
|
||||
return predicate.CpUser(func(s *sql.Selector) {
|
||||
step := newCpLeaveStep()
|
||||
schemaConfig := internal.SchemaConfigFromContext(s.Context())
|
||||
step.To.Schema = schemaConfig.CpLeave
|
||||
step.Edge.Schema = schemaConfig.CpLeave
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasSysuser applies the HasEdge predicate on the "sysuser" edge.
|
||||
func HasSysuser() predicate.CpUser {
|
||||
return predicate.CpUser(func(s *sql.Selector) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/cpleave"
|
||||
"likedream-goframe/internal/ent/cpschool"
|
||||
"likedream-goframe/internal/ent/cptask"
|
||||
"likedream-goframe/internal/ent/cptasklog"
|
||||
@@ -56,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)
|
||||
@@ -110,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...)
|
||||
@@ -125,6 +148,21 @@ func (_c *CpUserCreate) AddCptasks(v ...*CpTask) *CpUserCreate {
|
||||
return _c.AddCptaskIDs(ids...)
|
||||
}
|
||||
|
||||
// AddCpLeaveIDs adds the "cp_leave" edge to the CpLeave entity by IDs.
|
||||
func (_c *CpUserCreate) AddCpLeaveIDs(ids ...int64) *CpUserCreate {
|
||||
_c.mutation.AddCpLeaveIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddCpLeave adds the "cp_leave" edges to the CpLeave entity.
|
||||
func (_c *CpUserCreate) AddCpLeave(v ...*CpLeave) *CpUserCreate {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddCpLeaveIDs(ids...)
|
||||
}
|
||||
|
||||
// SetSysuserID sets the "sysuser" edge to the SysUser entity by ID.
|
||||
func (_c *CpUserCreate) SetSysuserID(id int64) *CpUserCreate {
|
||||
_c.mutation.SetSysuserID(id)
|
||||
@@ -207,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
|
||||
}
|
||||
|
||||
@@ -229,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"`)}
|
||||
}
|
||||
@@ -253,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"`)}
|
||||
}
|
||||
@@ -319,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,
|
||||
@@ -336,6 +382,23 @@ func (_c *CpUserCreate) createSpec() (*CpUser, *sqlgraph.CreateSpec) {
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.CpLeaveIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: cpuser.CpLeaveTable,
|
||||
Columns: []string{cpuser.CpLeaveColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _c.schemaConfig.CpLeave
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.SysuserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
@@ -489,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)
|
||||
@@ -567,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:
|
||||
//
|
||||
@@ -668,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) {
|
||||
@@ -759,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 {
|
||||
@@ -1026,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) {
|
||||
@@ -1117,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 {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/cpleave"
|
||||
"likedream-goframe/internal/ent/cpschool"
|
||||
"likedream-goframe/internal/ent/cptask"
|
||||
"likedream-goframe/internal/ent/cptasklog"
|
||||
@@ -30,11 +31,13 @@ type CpUserQuery struct {
|
||||
inters []Interceptor
|
||||
predicates []predicate.CpUser
|
||||
withCptasks *CpTaskQuery
|
||||
withCpLeave *CpLeaveQuery
|
||||
withSysuser *SysUserQuery
|
||||
withCpTaskLogs *CpTaskLogQuery
|
||||
withSchool *CpSchoolQuery
|
||||
modifiers []func(*sql.Selector)
|
||||
withNamedCptasks map[string]*CpTaskQuery
|
||||
withNamedCpLeave map[string]*CpLeaveQuery
|
||||
withNamedCpTaskLogs map[string]*CpTaskLogQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
@@ -97,6 +100,31 @@ func (_q *CpUserQuery) QueryCptasks() *CpTaskQuery {
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryCpLeave chains the current query on the "cp_leave" edge.
|
||||
func (_q *CpUserQuery) QueryCpLeave() *CpLeaveQuery {
|
||||
query := (&CpLeaveClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(cpuser.Table, cpuser.FieldID, selector),
|
||||
sqlgraph.To(cpleave.Table, cpleave.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, cpuser.CpLeaveTable, cpuser.CpLeaveColumn),
|
||||
)
|
||||
schemaConfig := _q.schemaConfig
|
||||
step.To.Schema = schemaConfig.CpLeave
|
||||
step.Edge.Schema = schemaConfig.CpLeave
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QuerySysuser chains the current query on the "sysuser" edge.
|
||||
func (_q *CpUserQuery) QuerySysuser() *SysUserQuery {
|
||||
query := (&SysUserClient{config: _q.config}).Query()
|
||||
@@ -365,6 +393,7 @@ func (_q *CpUserQuery) Clone() *CpUserQuery {
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.CpUser{}, _q.predicates...),
|
||||
withCptasks: _q.withCptasks.Clone(),
|
||||
withCpLeave: _q.withCpLeave.Clone(),
|
||||
withSysuser: _q.withSysuser.Clone(),
|
||||
withCpTaskLogs: _q.withCpTaskLogs.Clone(),
|
||||
withSchool: _q.withSchool.Clone(),
|
||||
@@ -386,6 +415,17 @@ func (_q *CpUserQuery) WithCptasks(opts ...func(*CpTaskQuery)) *CpUserQuery {
|
||||
return _q
|
||||
}
|
||||
|
||||
// WithCpLeave tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "cp_leave" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *CpUserQuery) WithCpLeave(opts ...func(*CpLeaveQuery)) *CpUserQuery {
|
||||
query := (&CpLeaveClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withCpLeave = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// WithSysuser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "sysuser" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *CpUserQuery) WithSysuser(opts ...func(*SysUserQuery)) *CpUserQuery {
|
||||
@@ -497,8 +537,9 @@ func (_q *CpUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CpUse
|
||||
var (
|
||||
nodes = []*CpUser{}
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [4]bool{
|
||||
loadedTypes = [5]bool{
|
||||
_q.withCptasks != nil,
|
||||
_q.withCpLeave != nil,
|
||||
_q.withSysuser != nil,
|
||||
_q.withCpTaskLogs != nil,
|
||||
_q.withSchool != nil,
|
||||
@@ -539,6 +580,18 @@ func (_q *CpUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CpUse
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := _q.withCpLeave; query != nil {
|
||||
if err := _q.loadCpLeave(ctx, query, nodes,
|
||||
func(n *CpUser) { n.Edges.CpLeave = []*CpLeave{} },
|
||||
func(n *CpUser, e *CpLeave) {
|
||||
n.Edges.CpLeave = append(n.Edges.CpLeave, e)
|
||||
if !e.Edges.loadedTypes[0] {
|
||||
e.Edges.CpUser = n
|
||||
}
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := _q.withSysuser; query != nil {
|
||||
if err := _q.loadSysuser(ctx, query, nodes, nil,
|
||||
func(n *CpUser, e *SysUser) { n.Edges.Sysuser = e }); err != nil {
|
||||
@@ -575,6 +628,18 @@ func (_q *CpUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CpUse
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
for name, query := range _q.withNamedCpLeave {
|
||||
if err := _q.loadCpLeave(ctx, query, nodes,
|
||||
func(n *CpUser) { n.appendNamedCpLeave(name) },
|
||||
func(n *CpUser, e *CpLeave) {
|
||||
n.appendNamedCpLeave(name, e)
|
||||
if !e.Edges.loadedTypes[0] {
|
||||
e.Edges.CpUser = n
|
||||
}
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
for name, query := range _q.withNamedCpTaskLogs {
|
||||
if err := _q.loadCpTaskLogs(ctx, query, nodes,
|
||||
func(n *CpUser) { n.appendNamedCpTaskLogs(name) },
|
||||
@@ -620,6 +685,36 @@ func (_q *CpUserQuery) loadCptasks(ctx context.Context, query *CpTaskQuery, node
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (_q *CpUserQuery) loadCpLeave(ctx context.Context, query *CpLeaveQuery, nodes []*CpUser, init func(*CpUser), assign func(*CpUser, *CpLeave)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int64]*CpUser)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
if len(query.ctx.Fields) > 0 {
|
||||
query.ctx.AppendFieldOnce(cpleave.FieldCpUserID)
|
||||
}
|
||||
query.Where(predicate.CpLeave(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(cpuser.CpLeaveColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.CpUserID
|
||||
node, ok := nodeids[fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "cp_user_id" returned %v for node %v`, fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (_q *CpUserQuery) loadSysuser(ctx context.Context, query *SysUserQuery, nodes []*CpUser, init func(*CpUser), assign func(*CpUser, *SysUser)) error {
|
||||
ids := make([]int64, 0, len(nodes))
|
||||
nodeids := make(map[int64][]*CpUser)
|
||||
@@ -853,6 +948,20 @@ func (_q *CpUserQuery) WithNamedCptasks(name string, opts ...func(*CpTaskQuery))
|
||||
return _q
|
||||
}
|
||||
|
||||
// WithNamedCpLeave tells the query-builder to eager-load the nodes that are connected to the "cp_leave"
|
||||
// edge with the given name. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *CpUserQuery) WithNamedCpLeave(name string, opts ...func(*CpLeaveQuery)) *CpUserQuery {
|
||||
query := (&CpLeaveClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
if _q.withNamedCpLeave == nil {
|
||||
_q.withNamedCpLeave = make(map[string]*CpLeaveQuery)
|
||||
}
|
||||
_q.withNamedCpLeave[name] = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// WithNamedCpTaskLogs tells the query-builder to eager-load the nodes that are connected to the "cp_task_logs"
|
||||
// edge with the given name. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *CpUserQuery) WithNamedCpTaskLogs(name string, opts ...func(*CpTaskLogQuery)) *CpUserQuery {
|
||||
|
||||
+231
-10
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/cpleave"
|
||||
"likedream-goframe/internal/ent/cpschool"
|
||||
"likedream-goframe/internal/ent/cptask"
|
||||
"likedream-goframe/internal/ent/cptasklog"
|
||||
@@ -82,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)
|
||||
@@ -170,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...)
|
||||
@@ -185,6 +206,21 @@ func (_u *CpUserUpdate) AddCptasks(v ...*CpTask) *CpUserUpdate {
|
||||
return _u.AddCptaskIDs(ids...)
|
||||
}
|
||||
|
||||
// AddCpLeaveIDs adds the "cp_leave" edge to the CpLeave entity by IDs.
|
||||
func (_u *CpUserUpdate) AddCpLeaveIDs(ids ...int64) *CpUserUpdate {
|
||||
_u.mutation.AddCpLeaveIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddCpLeave adds the "cp_leave" edges to the CpLeave entity.
|
||||
func (_u *CpUserUpdate) AddCpLeave(v ...*CpLeave) *CpUserUpdate {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddCpLeaveIDs(ids...)
|
||||
}
|
||||
|
||||
// SetSysuserID sets the "sysuser" edge to the SysUser entity by ID.
|
||||
func (_u *CpUserUpdate) SetSysuserID(id int64) *CpUserUpdate {
|
||||
_u.mutation.SetSysuserID(id)
|
||||
@@ -242,6 +278,27 @@ func (_u *CpUserUpdate) RemoveCptasks(v ...*CpTask) *CpUserUpdate {
|
||||
return _u.RemoveCptaskIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearCpLeave clears all "cp_leave" edges to the CpLeave entity.
|
||||
func (_u *CpUserUpdate) ClearCpLeave() *CpUserUpdate {
|
||||
_u.mutation.ClearCpLeave()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveCpLeaveIDs removes the "cp_leave" edge to CpLeave entities by IDs.
|
||||
func (_u *CpUserUpdate) RemoveCpLeaveIDs(ids ...int64) *CpUserUpdate {
|
||||
_u.mutation.RemoveCpLeaveIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveCpLeave removes "cp_leave" edges to CpLeave entities.
|
||||
func (_u *CpUserUpdate) RemoveCpLeave(v ...*CpLeave) *CpUserUpdate {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveCpLeaveIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearSysuser clears the "sysuser" edge to the SysUser entity.
|
||||
func (_u *CpUserUpdate) ClearSysuser() *CpUserUpdate {
|
||||
_u.mutation.ClearSysuser()
|
||||
@@ -309,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)}
|
||||
@@ -324,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"`)
|
||||
}
|
||||
@@ -360,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)
|
||||
}
|
||||
@@ -381,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,
|
||||
@@ -429,6 +492,54 @@ func (_u *CpUserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.CpLeaveCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: cpuser.CpLeaveTable,
|
||||
Columns: []string{cpuser.CpLeaveColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.CpLeave
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedCpLeaveIDs(); len(nodes) > 0 && !_u.mutation.CpLeaveCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: cpuser.CpLeaveTable,
|
||||
Columns: []string{cpuser.CpLeaveColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.CpLeave
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.CpLeaveIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: cpuser.CpLeaveTable,
|
||||
Columns: []string{cpuser.CpLeaveColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.CpLeave
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.SysuserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
@@ -611,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)
|
||||
@@ -699,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...)
|
||||
@@ -714,6 +845,21 @@ func (_u *CpUserUpdateOne) AddCptasks(v ...*CpTask) *CpUserUpdateOne {
|
||||
return _u.AddCptaskIDs(ids...)
|
||||
}
|
||||
|
||||
// AddCpLeaveIDs adds the "cp_leave" edge to the CpLeave entity by IDs.
|
||||
func (_u *CpUserUpdateOne) AddCpLeaveIDs(ids ...int64) *CpUserUpdateOne {
|
||||
_u.mutation.AddCpLeaveIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddCpLeave adds the "cp_leave" edges to the CpLeave entity.
|
||||
func (_u *CpUserUpdateOne) AddCpLeave(v ...*CpLeave) *CpUserUpdateOne {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddCpLeaveIDs(ids...)
|
||||
}
|
||||
|
||||
// SetSysuserID sets the "sysuser" edge to the SysUser entity by ID.
|
||||
func (_u *CpUserUpdateOne) SetSysuserID(id int64) *CpUserUpdateOne {
|
||||
_u.mutation.SetSysuserID(id)
|
||||
@@ -771,6 +917,27 @@ func (_u *CpUserUpdateOne) RemoveCptasks(v ...*CpTask) *CpUserUpdateOne {
|
||||
return _u.RemoveCptaskIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearCpLeave clears all "cp_leave" edges to the CpLeave entity.
|
||||
func (_u *CpUserUpdateOne) ClearCpLeave() *CpUserUpdateOne {
|
||||
_u.mutation.ClearCpLeave()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveCpLeaveIDs removes the "cp_leave" edge to CpLeave entities by IDs.
|
||||
func (_u *CpUserUpdateOne) RemoveCpLeaveIDs(ids ...int64) *CpUserUpdateOne {
|
||||
_u.mutation.RemoveCpLeaveIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveCpLeave removes "cp_leave" edges to CpLeave entities.
|
||||
func (_u *CpUserUpdateOne) RemoveCpLeave(v ...*CpLeave) *CpUserUpdateOne {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveCpLeaveIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearSysuser clears the "sysuser" edge to the SysUser entity.
|
||||
func (_u *CpUserUpdateOne) ClearSysuser() *CpUserUpdateOne {
|
||||
_u.mutation.ClearSysuser()
|
||||
@@ -851,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)}
|
||||
@@ -866,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"`)
|
||||
}
|
||||
@@ -919,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)
|
||||
}
|
||||
@@ -940,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,
|
||||
@@ -988,6 +1161,54 @@ func (_u *CpUserUpdateOne) sqlSave(ctx context.Context) (_node *CpUser, err erro
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.CpLeaveCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: cpuser.CpLeaveTable,
|
||||
Columns: []string{cpuser.CpLeaveColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.CpLeave
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedCpLeaveIDs(); len(nodes) > 0 && !_u.mutation.CpLeaveCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: cpuser.CpLeaveTable,
|
||||
Columns: []string{cpuser.CpLeaveColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.CpLeave
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.CpLeaveIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: cpuser.CpLeaveTable,
|
||||
Columns: []string{cpuser.CpLeaveColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(cpleave.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
edge.Schema = _u.schemaConfig.CpLeave
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.SysuserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
|
||||
+19
-11
@@ -6,13 +6,17 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/courseentity"
|
||||
"likedream-goframe/internal/ent/cpimage"
|
||||
"likedream-goframe/internal/ent/cpleave"
|
||||
"likedream-goframe/internal/ent/cpschool"
|
||||
"likedream-goframe/internal/ent/cptask"
|
||||
"likedream-goframe/internal/ent/cptasklog"
|
||||
"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"
|
||||
@@ -83,17 +87,21 @@ var (
|
||||
func checkColumn(t, c string) error {
|
||||
initCheck.Do(func() {
|
||||
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||
cpimage.Table: cpimage.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)
|
||||
|
||||
+692
-22
@@ -3,14 +3,18 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"likedream-goframe/internal/ent/courseentity"
|
||||
"likedream-goframe/internal/ent/cpimage"
|
||||
"likedream-goframe/internal/ent/cpleave"
|
||||
"likedream-goframe/internal/ent/cpschool"
|
||||
"likedream-goframe/internal/ent/cptask"
|
||||
"likedream-goframe/internal/ent/cptasklog"
|
||||
"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"
|
||||
@@ -24,8 +28,38 @@ import (
|
||||
|
||||
// schemaGraph holds a representation of ent/schema at runtime.
|
||||
var schemaGraph = func() *sqlgraph.Schema {
|
||||
graph := &sqlgraph.Schema{Nodes: make([]*sqlgraph.Node, 11)}
|
||||
graph := &sqlgraph.Schema{Nodes: make([]*sqlgraph.Node, 15)}
|
||||
graph.Nodes[0] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: courseentity.Table,
|
||||
Columns: courseentity.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Column: courseentity.FieldID,
|
||||
},
|
||||
},
|
||||
Type: "CourseEntity",
|
||||
Fields: map[string]*sqlgraph.FieldSpec{
|
||||
courseentity.FieldCreateTime: {Type: field.TypeString, Column: courseentity.FieldCreateTime},
|
||||
courseentity.FieldUpdateTime: {Type: field.TypeString, Column: courseentity.FieldUpdateTime},
|
||||
courseentity.FieldUserID: {Type: field.TypeInt64, Column: courseentity.FieldUserID},
|
||||
courseentity.FieldUsername: {Type: field.TypeString, Column: courseentity.FieldUsername},
|
||||
courseentity.FieldPassword: {Type: field.TypeString, Column: courseentity.FieldPassword},
|
||||
courseentity.FieldType: {Type: field.TypeEnum, Column: courseentity.FieldType},
|
||||
courseentity.FieldCourseName: {Type: field.TypeString, Column: courseentity.FieldCourseName},
|
||||
courseentity.FieldCourseID: {Type: field.TypeString, Column: courseentity.FieldCourseID},
|
||||
courseentity.FieldNeed: {Type: field.TypeEnum, Column: courseentity.FieldNeed},
|
||||
courseentity.FieldStatus: {Type: field.TypeEnum, Column: courseentity.FieldStatus},
|
||||
courseentity.FieldTaskCount: {Type: field.TypeInt, Column: courseentity.FieldTaskCount},
|
||||
courseentity.FieldSuccessCount: {Type: field.TypeInt, Column: courseentity.FieldSuccessCount},
|
||||
courseentity.FieldExamState: {Type: field.TypeEnum, Column: courseentity.FieldExamState},
|
||||
courseentity.FieldViolence: {Type: field.TypeEnum, Column: courseentity.FieldViolence},
|
||||
courseentity.FieldNodes: {Type: field.TypeString, Column: courseentity.FieldNodes},
|
||||
courseentity.FieldCompletedNodes: {Type: field.TypeString, Column: courseentity.FieldCompletedNodes},
|
||||
courseentity.FieldDesc: {Type: field.TypeString, Column: courseentity.FieldDesc},
|
||||
},
|
||||
}
|
||||
graph.Nodes[1] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: cpimage.Table,
|
||||
Columns: cpimage.Columns,
|
||||
@@ -45,7 +79,29 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
cpimage.FieldContentLength: {Type: field.TypeInt64, Column: cpimage.FieldContentLength},
|
||||
},
|
||||
}
|
||||
graph.Nodes[1] = &sqlgraph.Node{
|
||||
graph.Nodes[2] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: cpleave.Table,
|
||||
Columns: cpleave.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Column: cpleave.FieldID,
|
||||
},
|
||||
},
|
||||
Type: "CpLeave",
|
||||
Fields: map[string]*sqlgraph.FieldSpec{
|
||||
cpleave.FieldCreateTime: {Type: field.TypeString, Column: cpleave.FieldCreateTime},
|
||||
cpleave.FieldUpdateTime: {Type: field.TypeString, Column: cpleave.FieldUpdateTime},
|
||||
cpleave.FieldCpUserID: {Type: field.TypeInt64, Column: cpleave.FieldCpUserID},
|
||||
cpleave.FieldUserID: {Type: field.TypeInt64, Column: cpleave.FieldUserID},
|
||||
cpleave.FieldLeaveID: {Type: field.TypeString, Column: cpleave.FieldLeaveID},
|
||||
cpleave.FieldTitle: {Type: field.TypeString, Column: cpleave.FieldTitle},
|
||||
cpleave.FieldStatus: {Type: field.TypeEnum, Column: cpleave.FieldStatus},
|
||||
cpleave.FieldType: {Type: field.TypeEnum, Column: cpleave.FieldType},
|
||||
cpleave.FieldDesc: {Type: field.TypeString, Column: cpleave.FieldDesc},
|
||||
},
|
||||
}
|
||||
graph.Nodes[3] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: cpschool.Table,
|
||||
Columns: cpschool.Columns,
|
||||
@@ -63,7 +119,7 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
cpschool.FieldIconImg: {Type: field.TypeString, Column: cpschool.FieldIconImg},
|
||||
},
|
||||
}
|
||||
graph.Nodes[2] = &sqlgraph.Node{
|
||||
graph.Nodes[4] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: cptask.Table,
|
||||
Columns: cptask.Columns,
|
||||
@@ -92,7 +148,7 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
cptask.FieldNextExecuteTime: {Type: field.TypeInt64, Column: cptask.FieldNextExecuteTime},
|
||||
},
|
||||
}
|
||||
graph.Nodes[3] = &sqlgraph.Node{
|
||||
graph.Nodes[5] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: cptasklog.Table,
|
||||
Columns: cptasklog.Columns,
|
||||
@@ -113,7 +169,7 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
cptasklog.FieldRealName: {Type: field.TypeString, Column: cptasklog.FieldRealName},
|
||||
},
|
||||
}
|
||||
graph.Nodes[4] = &sqlgraph.Node{
|
||||
graph.Nodes[6] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: cpuser.Table,
|
||||
Columns: cpuser.Columns,
|
||||
@@ -134,9 +190,10 @@ 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[5] = &sqlgraph.Node{
|
||||
graph.Nodes[7] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: sysagent.Table,
|
||||
Columns: sysagent.Columns,
|
||||
@@ -153,7 +210,28 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
sysagent.FieldRate: {Type: field.TypeString, Column: sysagent.FieldRate},
|
||||
},
|
||||
}
|
||||
graph.Nodes[6] = &sqlgraph.Node{
|
||||
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,
|
||||
@@ -175,7 +253,26 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
syscard.FieldCashValue: {Type: field.TypeString, Column: syscard.FieldCashValue},
|
||||
},
|
||||
}
|
||||
graph.Nodes[7] = &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,
|
||||
@@ -201,7 +298,7 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
sysmenu.FieldOrder: {Type: field.TypeUint, Column: sysmenu.FieldOrder},
|
||||
},
|
||||
}
|
||||
graph.Nodes[8] = &sqlgraph.Node{
|
||||
graph.Nodes[12] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: sysrole.Table,
|
||||
Columns: sysrole.Columns,
|
||||
@@ -220,7 +317,7 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
sysrole.FieldOrder: {Type: field.TypeUint, Column: sysrole.FieldOrder},
|
||||
},
|
||||
}
|
||||
graph.Nodes[9] = &sqlgraph.Node{
|
||||
graph.Nodes[13] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: sysuser.Table,
|
||||
Columns: sysuser.Columns,
|
||||
@@ -243,7 +340,7 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
sysuser.FieldInviteCashback: {Type: field.TypeString, Column: sysuser.FieldInviteCashback},
|
||||
},
|
||||
}
|
||||
graph.Nodes[10] = &sqlgraph.Node{
|
||||
graph.Nodes[14] = &sqlgraph.Node{
|
||||
NodeSpec: sqlgraph.NodeSpec{
|
||||
Table: sysuserlog.Table,
|
||||
Columns: sysuserlog.Columns,
|
||||
@@ -255,6 +352,18 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
Type: "SysUserLog",
|
||||
Fields: map[string]*sqlgraph.FieldSpec{},
|
||||
}
|
||||
graph.MustAddE(
|
||||
"sys_user",
|
||||
&sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: courseentity.SysUserTable,
|
||||
Columns: []string{courseentity.SysUserColumn},
|
||||
Bidi: false,
|
||||
},
|
||||
"CourseEntity",
|
||||
"SysUser",
|
||||
)
|
||||
graph.MustAddE(
|
||||
"user",
|
||||
&sqlgraph.EdgeSpec{
|
||||
@@ -267,6 +376,30 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
"CpImage",
|
||||
"SysUser",
|
||||
)
|
||||
graph.MustAddE(
|
||||
"cp_user",
|
||||
&sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: cpleave.CpUserTable,
|
||||
Columns: []string{cpleave.CpUserColumn},
|
||||
Bidi: false,
|
||||
},
|
||||
"CpLeave",
|
||||
"CpUser",
|
||||
)
|
||||
graph.MustAddE(
|
||||
"sys_user",
|
||||
&sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: cpleave.SysUserTable,
|
||||
Columns: []string{cpleave.SysUserColumn},
|
||||
Bidi: false,
|
||||
},
|
||||
"CpLeave",
|
||||
"SysUser",
|
||||
)
|
||||
graph.MustAddE(
|
||||
"cpusers",
|
||||
&sqlgraph.EdgeSpec{
|
||||
@@ -363,6 +496,18 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
"CpUser",
|
||||
"CpTask",
|
||||
)
|
||||
graph.MustAddE(
|
||||
"cp_leave",
|
||||
&sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: cpuser.CpLeaveTable,
|
||||
Columns: []string{cpuser.CpLeaveColumn},
|
||||
Bidi: false,
|
||||
},
|
||||
"CpUser",
|
||||
"CpLeave",
|
||||
)
|
||||
graph.MustAddE(
|
||||
"sysuser",
|
||||
&sqlgraph.EdgeSpec{
|
||||
@@ -411,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{
|
||||
@@ -591,6 +748,30 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
"SysUser",
|
||||
"CpTask",
|
||||
)
|
||||
graph.MustAddE(
|
||||
"cp_leave",
|
||||
&sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.CpLeaveTable,
|
||||
Columns: []string{sysuser.CpLeaveColumn},
|
||||
Bidi: false,
|
||||
},
|
||||
"SysUser",
|
||||
"CpLeave",
|
||||
)
|
||||
graph.MustAddE(
|
||||
"course_entity",
|
||||
&sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.CourseEntityTable,
|
||||
Columns: []string{sysuser.CourseEntityColumn},
|
||||
Bidi: false,
|
||||
},
|
||||
"SysUser",
|
||||
"CourseEntity",
|
||||
)
|
||||
graph.MustAddE(
|
||||
"cp_task_logs",
|
||||
&sqlgraph.EdgeSpec{
|
||||
@@ -639,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
|
||||
}()
|
||||
|
||||
@@ -648,6 +841,145 @@ type predicateAdder interface {
|
||||
addPredicate(func(s *sql.Selector))
|
||||
}
|
||||
|
||||
// addPredicate implements the predicateAdder interface.
|
||||
func (_q *CourseEntityQuery) addPredicate(pred func(s *sql.Selector)) {
|
||||
_q.predicates = append(_q.predicates, pred)
|
||||
}
|
||||
|
||||
// Filter returns a Filter implementation to apply filters on the CourseEntityQuery builder.
|
||||
func (_q *CourseEntityQuery) Filter() *CourseEntityFilter {
|
||||
return &CourseEntityFilter{config: _q.config, predicateAdder: _q}
|
||||
}
|
||||
|
||||
// addPredicate implements the predicateAdder interface.
|
||||
func (m *CourseEntityMutation) addPredicate(pred func(s *sql.Selector)) {
|
||||
m.predicates = append(m.predicates, pred)
|
||||
}
|
||||
|
||||
// Filter returns an entql.Where implementation to apply filters on the CourseEntityMutation builder.
|
||||
func (m *CourseEntityMutation) Filter() *CourseEntityFilter {
|
||||
return &CourseEntityFilter{config: m.config, predicateAdder: m}
|
||||
}
|
||||
|
||||
// CourseEntityFilter provides a generic filtering capability at runtime for CourseEntityQuery.
|
||||
type CourseEntityFilter struct {
|
||||
predicateAdder
|
||||
config
|
||||
}
|
||||
|
||||
// Where applies the entql predicate on the query filter.
|
||||
func (f *CourseEntityFilter) Where(p entql.P) {
|
||||
f.addPredicate(func(s *sql.Selector) {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[0].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// WhereID applies the entql int64 predicate on the id field.
|
||||
func (f *CourseEntityFilter) WhereID(p entql.Int64P) {
|
||||
f.Where(p.Field(courseentity.FieldID))
|
||||
}
|
||||
|
||||
// WhereCreateTime applies the entql string predicate on the create_time field.
|
||||
func (f *CourseEntityFilter) WhereCreateTime(p entql.StringP) {
|
||||
f.Where(p.Field(courseentity.FieldCreateTime))
|
||||
}
|
||||
|
||||
// WhereUpdateTime applies the entql string predicate on the update_time field.
|
||||
func (f *CourseEntityFilter) WhereUpdateTime(p entql.StringP) {
|
||||
f.Where(p.Field(courseentity.FieldUpdateTime))
|
||||
}
|
||||
|
||||
// WhereUserID applies the entql int64 predicate on the user_id field.
|
||||
func (f *CourseEntityFilter) WhereUserID(p entql.Int64P) {
|
||||
f.Where(p.Field(courseentity.FieldUserID))
|
||||
}
|
||||
|
||||
// WhereUsername applies the entql string predicate on the username field.
|
||||
func (f *CourseEntityFilter) WhereUsername(p entql.StringP) {
|
||||
f.Where(p.Field(courseentity.FieldUsername))
|
||||
}
|
||||
|
||||
// WherePassword applies the entql string predicate on the password field.
|
||||
func (f *CourseEntityFilter) WherePassword(p entql.StringP) {
|
||||
f.Where(p.Field(courseentity.FieldPassword))
|
||||
}
|
||||
|
||||
// WhereType applies the entql string predicate on the type field.
|
||||
func (f *CourseEntityFilter) WhereType(p entql.StringP) {
|
||||
f.Where(p.Field(courseentity.FieldType))
|
||||
}
|
||||
|
||||
// WhereCourseName applies the entql string predicate on the course_name field.
|
||||
func (f *CourseEntityFilter) WhereCourseName(p entql.StringP) {
|
||||
f.Where(p.Field(courseentity.FieldCourseName))
|
||||
}
|
||||
|
||||
// WhereCourseID applies the entql string predicate on the course_id field.
|
||||
func (f *CourseEntityFilter) WhereCourseID(p entql.StringP) {
|
||||
f.Where(p.Field(courseentity.FieldCourseID))
|
||||
}
|
||||
|
||||
// WhereNeed applies the entql string predicate on the need field.
|
||||
func (f *CourseEntityFilter) WhereNeed(p entql.StringP) {
|
||||
f.Where(p.Field(courseentity.FieldNeed))
|
||||
}
|
||||
|
||||
// WhereStatus applies the entql string predicate on the status field.
|
||||
func (f *CourseEntityFilter) WhereStatus(p entql.StringP) {
|
||||
f.Where(p.Field(courseentity.FieldStatus))
|
||||
}
|
||||
|
||||
// WhereTaskCount applies the entql int predicate on the task_count field.
|
||||
func (f *CourseEntityFilter) WhereTaskCount(p entql.IntP) {
|
||||
f.Where(p.Field(courseentity.FieldTaskCount))
|
||||
}
|
||||
|
||||
// WhereSuccessCount applies the entql int predicate on the success_count field.
|
||||
func (f *CourseEntityFilter) WhereSuccessCount(p entql.IntP) {
|
||||
f.Where(p.Field(courseentity.FieldSuccessCount))
|
||||
}
|
||||
|
||||
// WhereExamState applies the entql string predicate on the exam_state field.
|
||||
func (f *CourseEntityFilter) WhereExamState(p entql.StringP) {
|
||||
f.Where(p.Field(courseentity.FieldExamState))
|
||||
}
|
||||
|
||||
// WhereViolence applies the entql string predicate on the violence field.
|
||||
func (f *CourseEntityFilter) WhereViolence(p entql.StringP) {
|
||||
f.Where(p.Field(courseentity.FieldViolence))
|
||||
}
|
||||
|
||||
// WhereNodes applies the entql string predicate on the nodes field.
|
||||
func (f *CourseEntityFilter) WhereNodes(p entql.StringP) {
|
||||
f.Where(p.Field(courseentity.FieldNodes))
|
||||
}
|
||||
|
||||
// WhereCompletedNodes applies the entql string predicate on the completed_nodes field.
|
||||
func (f *CourseEntityFilter) WhereCompletedNodes(p entql.StringP) {
|
||||
f.Where(p.Field(courseentity.FieldCompletedNodes))
|
||||
}
|
||||
|
||||
// WhereDesc applies the entql string predicate on the desc field.
|
||||
func (f *CourseEntityFilter) WhereDesc(p entql.StringP) {
|
||||
f.Where(p.Field(courseentity.FieldDesc))
|
||||
}
|
||||
|
||||
// WhereHasSysUser applies a predicate to check if query has an edge sys_user.
|
||||
func (f *CourseEntityFilter) WhereHasSysUser() {
|
||||
f.Where(entql.HasEdge("sys_user"))
|
||||
}
|
||||
|
||||
// WhereHasSysUserWith applies a predicate to check if query has an edge sys_user with a given conditions (other predicates).
|
||||
func (f *CourseEntityFilter) WhereHasSysUserWith(preds ...predicate.SysUser) {
|
||||
f.Where(entql.HasEdgeWith("sys_user", sqlgraph.WrapFunc(func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})))
|
||||
}
|
||||
|
||||
// addPredicate implements the predicateAdder interface.
|
||||
func (_q *CpImageQuery) addPredicate(pred func(s *sql.Selector)) {
|
||||
_q.predicates = append(_q.predicates, pred)
|
||||
@@ -677,7 +1009,7 @@ type CpImageFilter struct {
|
||||
// Where applies the entql predicate on the query filter.
|
||||
func (f *CpImageFilter) Where(p entql.P) {
|
||||
f.addPredicate(func(s *sql.Selector) {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[0].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[1].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -737,6 +1069,119 @@ func (f *CpImageFilter) WhereHasUserWith(preds ...predicate.SysUser) {
|
||||
})))
|
||||
}
|
||||
|
||||
// addPredicate implements the predicateAdder interface.
|
||||
func (_q *CpLeaveQuery) addPredicate(pred func(s *sql.Selector)) {
|
||||
_q.predicates = append(_q.predicates, pred)
|
||||
}
|
||||
|
||||
// Filter returns a Filter implementation to apply filters on the CpLeaveQuery builder.
|
||||
func (_q *CpLeaveQuery) Filter() *CpLeaveFilter {
|
||||
return &CpLeaveFilter{config: _q.config, predicateAdder: _q}
|
||||
}
|
||||
|
||||
// addPredicate implements the predicateAdder interface.
|
||||
func (m *CpLeaveMutation) addPredicate(pred func(s *sql.Selector)) {
|
||||
m.predicates = append(m.predicates, pred)
|
||||
}
|
||||
|
||||
// Filter returns an entql.Where implementation to apply filters on the CpLeaveMutation builder.
|
||||
func (m *CpLeaveMutation) Filter() *CpLeaveFilter {
|
||||
return &CpLeaveFilter{config: m.config, predicateAdder: m}
|
||||
}
|
||||
|
||||
// CpLeaveFilter provides a generic filtering capability at runtime for CpLeaveQuery.
|
||||
type CpLeaveFilter struct {
|
||||
predicateAdder
|
||||
config
|
||||
}
|
||||
|
||||
// Where applies the entql predicate on the query filter.
|
||||
func (f *CpLeaveFilter) Where(p entql.P) {
|
||||
f.addPredicate(func(s *sql.Selector) {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[2].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// WhereID applies the entql int64 predicate on the id field.
|
||||
func (f *CpLeaveFilter) WhereID(p entql.Int64P) {
|
||||
f.Where(p.Field(cpleave.FieldID))
|
||||
}
|
||||
|
||||
// WhereCreateTime applies the entql string predicate on the create_time field.
|
||||
func (f *CpLeaveFilter) WhereCreateTime(p entql.StringP) {
|
||||
f.Where(p.Field(cpleave.FieldCreateTime))
|
||||
}
|
||||
|
||||
// WhereUpdateTime applies the entql string predicate on the update_time field.
|
||||
func (f *CpLeaveFilter) WhereUpdateTime(p entql.StringP) {
|
||||
f.Where(p.Field(cpleave.FieldUpdateTime))
|
||||
}
|
||||
|
||||
// WhereCpUserID applies the entql int64 predicate on the cp_user_id field.
|
||||
func (f *CpLeaveFilter) WhereCpUserID(p entql.Int64P) {
|
||||
f.Where(p.Field(cpleave.FieldCpUserID))
|
||||
}
|
||||
|
||||
// WhereUserID applies the entql int64 predicate on the user_id field.
|
||||
func (f *CpLeaveFilter) WhereUserID(p entql.Int64P) {
|
||||
f.Where(p.Field(cpleave.FieldUserID))
|
||||
}
|
||||
|
||||
// WhereLeaveID applies the entql string predicate on the leave_id field.
|
||||
func (f *CpLeaveFilter) WhereLeaveID(p entql.StringP) {
|
||||
f.Where(p.Field(cpleave.FieldLeaveID))
|
||||
}
|
||||
|
||||
// WhereTitle applies the entql string predicate on the title field.
|
||||
func (f *CpLeaveFilter) WhereTitle(p entql.StringP) {
|
||||
f.Where(p.Field(cpleave.FieldTitle))
|
||||
}
|
||||
|
||||
// WhereStatus applies the entql string predicate on the status field.
|
||||
func (f *CpLeaveFilter) WhereStatus(p entql.StringP) {
|
||||
f.Where(p.Field(cpleave.FieldStatus))
|
||||
}
|
||||
|
||||
// WhereType applies the entql string predicate on the type field.
|
||||
func (f *CpLeaveFilter) WhereType(p entql.StringP) {
|
||||
f.Where(p.Field(cpleave.FieldType))
|
||||
}
|
||||
|
||||
// WhereDesc applies the entql string predicate on the desc field.
|
||||
func (f *CpLeaveFilter) WhereDesc(p entql.StringP) {
|
||||
f.Where(p.Field(cpleave.FieldDesc))
|
||||
}
|
||||
|
||||
// WhereHasCpUser applies a predicate to check if query has an edge cp_user.
|
||||
func (f *CpLeaveFilter) WhereHasCpUser() {
|
||||
f.Where(entql.HasEdge("cp_user"))
|
||||
}
|
||||
|
||||
// WhereHasCpUserWith applies a predicate to check if query has an edge cp_user with a given conditions (other predicates).
|
||||
func (f *CpLeaveFilter) WhereHasCpUserWith(preds ...predicate.CpUser) {
|
||||
f.Where(entql.HasEdgeWith("cp_user", sqlgraph.WrapFunc(func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})))
|
||||
}
|
||||
|
||||
// WhereHasSysUser applies a predicate to check if query has an edge sys_user.
|
||||
func (f *CpLeaveFilter) WhereHasSysUser() {
|
||||
f.Where(entql.HasEdge("sys_user"))
|
||||
}
|
||||
|
||||
// WhereHasSysUserWith applies a predicate to check if query has an edge sys_user with a given conditions (other predicates).
|
||||
func (f *CpLeaveFilter) WhereHasSysUserWith(preds ...predicate.SysUser) {
|
||||
f.Where(entql.HasEdgeWith("sys_user", sqlgraph.WrapFunc(func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})))
|
||||
}
|
||||
|
||||
// addPredicate implements the predicateAdder interface.
|
||||
func (_q *CpSchoolQuery) addPredicate(pred func(s *sql.Selector)) {
|
||||
_q.predicates = append(_q.predicates, pred)
|
||||
@@ -766,7 +1211,7 @@ type CpSchoolFilter struct {
|
||||
// Where applies the entql predicate on the query filter.
|
||||
func (f *CpSchoolFilter) Where(p entql.P) {
|
||||
f.addPredicate(func(s *sql.Selector) {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[1].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[3].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -845,7 +1290,7 @@ type CpTaskFilter struct {
|
||||
// Where applies the entql predicate on the query filter.
|
||||
func (f *CpTaskFilter) Where(p entql.P) {
|
||||
f.addPredicate(func(s *sql.Selector) {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[2].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[4].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -1007,7 +1452,7 @@ type CpTaskLogFilter struct {
|
||||
// Where applies the entql predicate on the query filter.
|
||||
func (f *CpTaskLogFilter) Where(p entql.P) {
|
||||
f.addPredicate(func(s *sql.Selector) {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[3].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[5].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -1129,7 +1574,7 @@ type CpUserFilter struct {
|
||||
// Where applies the entql predicate on the query filter.
|
||||
func (f *CpUserFilter) Where(p entql.P) {
|
||||
f.addPredicate(func(s *sql.Selector) {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[4].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[6].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -1190,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"))
|
||||
@@ -1204,6 +1654,20 @@ func (f *CpUserFilter) WhereHasCptasksWith(preds ...predicate.CpTask) {
|
||||
})))
|
||||
}
|
||||
|
||||
// WhereHasCpLeave applies a predicate to check if query has an edge cp_leave.
|
||||
func (f *CpUserFilter) WhereHasCpLeave() {
|
||||
f.Where(entql.HasEdge("cp_leave"))
|
||||
}
|
||||
|
||||
// WhereHasCpLeaveWith applies a predicate to check if query has an edge cp_leave with a given conditions (other predicates).
|
||||
func (f *CpUserFilter) WhereHasCpLeaveWith(preds ...predicate.CpLeave) {
|
||||
f.Where(entql.HasEdgeWith("cp_leave", sqlgraph.WrapFunc(func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})))
|
||||
}
|
||||
|
||||
// WhereHasSysuser applies a predicate to check if query has an edge sysuser.
|
||||
func (f *CpUserFilter) WhereHasSysuser() {
|
||||
f.Where(entql.HasEdge("sysuser"))
|
||||
@@ -1275,7 +1739,7 @@ type SysAgentFilter struct {
|
||||
// Where applies the entql predicate on the query filter.
|
||||
func (f *SysAgentFilter) Where(p entql.P) {
|
||||
f.addPredicate(func(s *sql.Selector) {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[5].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[7].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -1320,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)
|
||||
@@ -1349,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[6].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[9].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -1447,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)
|
||||
@@ -1476,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[7].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[11].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -1623,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[8].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[12].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -1721,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[9].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[13].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
@@ -1880,6 +2508,34 @@ func (f *SysUserFilter) WhereHasCpTaskWith(preds ...predicate.CpTask) {
|
||||
})))
|
||||
}
|
||||
|
||||
// WhereHasCpLeave applies a predicate to check if query has an edge cp_leave.
|
||||
func (f *SysUserFilter) WhereHasCpLeave() {
|
||||
f.Where(entql.HasEdge("cp_leave"))
|
||||
}
|
||||
|
||||
// WhereHasCpLeaveWith applies a predicate to check if query has an edge cp_leave with a given conditions (other predicates).
|
||||
func (f *SysUserFilter) WhereHasCpLeaveWith(preds ...predicate.CpLeave) {
|
||||
f.Where(entql.HasEdgeWith("cp_leave", sqlgraph.WrapFunc(func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})))
|
||||
}
|
||||
|
||||
// WhereHasCourseEntity applies a predicate to check if query has an edge course_entity.
|
||||
func (f *SysUserFilter) WhereHasCourseEntity() {
|
||||
f.Where(entql.HasEdge("course_entity"))
|
||||
}
|
||||
|
||||
// WhereHasCourseEntityWith applies a predicate to check if query has an edge course_entity with a given conditions (other predicates).
|
||||
func (f *SysUserFilter) WhereHasCourseEntityWith(preds ...predicate.CourseEntity) {
|
||||
f.Where(entql.HasEdgeWith("course_entity", sqlgraph.WrapFunc(func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})))
|
||||
}
|
||||
|
||||
// WhereHasCpTaskLogs applies a predicate to check if query has an edge cp_task_logs.
|
||||
func (f *SysUserFilter) WhereHasCpTaskLogs() {
|
||||
f.Where(entql.HasEdge("cp_task_logs"))
|
||||
@@ -1936,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)
|
||||
@@ -1965,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[10].Type, p, s); err != nil {
|
||||
if err := schemaGraph.EvalP(schemaGraph.Nodes[14].Type, p, s); err != nil {
|
||||
s.AddError(err)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -8,6 +8,18 @@ import (
|
||||
"likedream-goframe/internal/ent"
|
||||
)
|
||||
|
||||
// The CourseEntityFunc type is an adapter to allow the use of ordinary
|
||||
// function as CourseEntity mutator.
|
||||
type CourseEntityFunc func(context.Context, *ent.CourseEntityMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f CourseEntityFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.CourseEntityMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CourseEntityMutation", m)
|
||||
}
|
||||
|
||||
// The CpImageFunc type is an adapter to allow the use of ordinary
|
||||
// function as CpImage mutator.
|
||||
type CpImageFunc func(context.Context, *ent.CpImageMutation) (ent.Value, error)
|
||||
@@ -20,6 +32,18 @@ func (f CpImageFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, err
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CpImageMutation", m)
|
||||
}
|
||||
|
||||
// The CpLeaveFunc type is an adapter to allow the use of ordinary
|
||||
// function as CpLeave mutator.
|
||||
type CpLeaveFunc func(context.Context, *ent.CpLeaveMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f CpLeaveFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.CpLeaveMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CpLeaveMutation", m)
|
||||
}
|
||||
|
||||
// The CpSchoolFunc type is an adapter to allow the use of ordinary
|
||||
// function as CpSchool mutator.
|
||||
type CpSchoolFunc func(context.Context, *ent.CpSchoolMutation) (ent.Value, error)
|
||||
@@ -80,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)
|
||||
@@ -92,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)
|
||||
|
||||
@@ -7,14 +7,18 @@ import (
|
||||
"fmt"
|
||||
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/ent/courseentity"
|
||||
"likedream-goframe/internal/ent/cpimage"
|
||||
"likedream-goframe/internal/ent/cpleave"
|
||||
"likedream-goframe/internal/ent/cpschool"
|
||||
"likedream-goframe/internal/ent/cptask"
|
||||
"likedream-goframe/internal/ent/cptasklog"
|
||||
"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"
|
||||
@@ -79,6 +83,33 @@ func (f TraverseFunc) Traverse(ctx context.Context, q ent.Query) error {
|
||||
return f(ctx, query)
|
||||
}
|
||||
|
||||
// The CourseEntityFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||
type CourseEntityFunc func(context.Context, *ent.CourseEntityQuery) (ent.Value, error)
|
||||
|
||||
// Query calls f(ctx, q).
|
||||
func (f CourseEntityFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
|
||||
if q, ok := q.(*ent.CourseEntityQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected query type %T. expect *ent.CourseEntityQuery", q)
|
||||
}
|
||||
|
||||
// The TraverseCourseEntity type is an adapter to allow the use of ordinary function as Traverser.
|
||||
type TraverseCourseEntity func(context.Context, *ent.CourseEntityQuery) error
|
||||
|
||||
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
|
||||
func (f TraverseCourseEntity) Intercept(next ent.Querier) ent.Querier {
|
||||
return next
|
||||
}
|
||||
|
||||
// Traverse calls f(ctx, q).
|
||||
func (f TraverseCourseEntity) Traverse(ctx context.Context, q ent.Query) error {
|
||||
if q, ok := q.(*ent.CourseEntityQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return fmt.Errorf("unexpected query type %T. expect *ent.CourseEntityQuery", q)
|
||||
}
|
||||
|
||||
// The CpImageFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||
type CpImageFunc func(context.Context, *ent.CpImageQuery) (ent.Value, error)
|
||||
|
||||
@@ -106,6 +137,33 @@ func (f TraverseCpImage) Traverse(ctx context.Context, q ent.Query) error {
|
||||
return fmt.Errorf("unexpected query type %T. expect *ent.CpImageQuery", q)
|
||||
}
|
||||
|
||||
// The CpLeaveFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||
type CpLeaveFunc func(context.Context, *ent.CpLeaveQuery) (ent.Value, error)
|
||||
|
||||
// Query calls f(ctx, q).
|
||||
func (f CpLeaveFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
|
||||
if q, ok := q.(*ent.CpLeaveQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected query type %T. expect *ent.CpLeaveQuery", q)
|
||||
}
|
||||
|
||||
// The TraverseCpLeave type is an adapter to allow the use of ordinary function as Traverser.
|
||||
type TraverseCpLeave func(context.Context, *ent.CpLeaveQuery) error
|
||||
|
||||
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
|
||||
func (f TraverseCpLeave) Intercept(next ent.Querier) ent.Querier {
|
||||
return next
|
||||
}
|
||||
|
||||
// Traverse calls f(ctx, q).
|
||||
func (f TraverseCpLeave) Traverse(ctx context.Context, q ent.Query) error {
|
||||
if q, ok := q.(*ent.CpLeaveQuery); ok {
|
||||
return f(ctx, q)
|
||||
}
|
||||
return fmt.Errorf("unexpected query type %T. expect *ent.CpLeaveQuery", q)
|
||||
}
|
||||
|
||||
// The CpSchoolFunc type is an adapter to allow the use of ordinary function as a Querier.
|
||||
type CpSchoolFunc func(context.Context, *ent.CpSchoolQuery) (ent.Value, error)
|
||||
|
||||
@@ -241,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)
|
||||
|
||||
@@ -268,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)
|
||||
|
||||
@@ -379,8 +491,12 @@ func (f TraverseSysUserLog) Traverse(ctx context.Context, q ent.Query) error {
|
||||
// NewQuery returns the generic Query interface for the given typed query.
|
||||
func NewQuery(q ent.Query) (Query, error) {
|
||||
switch q := q.(type) {
|
||||
case *ent.CourseEntityQuery:
|
||||
return &query[*ent.CourseEntityQuery, predicate.CourseEntity, courseentity.OrderOption]{typ: ent.TypeCourseEntity, tq: q}, nil
|
||||
case *ent.CpImageQuery:
|
||||
return &query[*ent.CpImageQuery, predicate.CpImage, cpimage.OrderOption]{typ: ent.TypeCpImage, tq: q}, nil
|
||||
case *ent.CpLeaveQuery:
|
||||
return &query[*ent.CpLeaveQuery, predicate.CpLeave, cpleave.OrderOption]{typ: ent.TypeCpLeave, tq: q}, nil
|
||||
case *ent.CpSchoolQuery:
|
||||
return &query[*ent.CpSchoolQuery, predicate.CpSchool, cpschool.OrderOption]{typ: ent.TypeCpSchool, tq: q}, nil
|
||||
case *ent.CpTaskQuery:
|
||||
@@ -391,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,19 +7,23 @@ import "context"
|
||||
// SchemaConfig represents alternative schema names for all tables
|
||||
// that can be passed at runtime.
|
||||
type SchemaConfig struct {
|
||||
CpImage string // CpImage 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{}
|
||||
|
||||
@@ -9,6 +9,41 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// CourseEntityColumns holds the columns for the "course_entity" table.
|
||||
CourseEntityColumns = []*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: "username", Type: field.TypeString},
|
||||
{Name: "password", Type: field.TypeString},
|
||||
{Name: "type", Type: field.TypeEnum, Enums: []string{"xxt"}},
|
||||
{Name: "course_name", Type: field.TypeString},
|
||||
{Name: "course_id", Type: field.TypeString},
|
||||
{Name: "need", Type: field.TypeEnum, Enums: []string{"task", "exam", "all"}},
|
||||
{Name: "status", Type: field.TypeEnum, Enums: []string{"not_start", "waiting", "doing", "done", "fail", "pause"}, Default: "not_start"},
|
||||
{Name: "task_count", Type: field.TypeInt, Default: 0},
|
||||
{Name: "success_count", Type: field.TypeInt, Default: 0},
|
||||
{Name: "exam_state", Type: field.TypeEnum, Enums: []string{"not_start", "waiting", "doing", "done", "fail"}, Default: "not_start"},
|
||||
{Name: "violence", Type: field.TypeEnum, Enums: []string{"no", "yes"}, Default: "no"},
|
||||
{Name: "nodes", Type: field.TypeString, Nullable: true, Size: 2147483647},
|
||||
{Name: "completed_nodes", Type: field.TypeString, Nullable: true, Size: 2147483647},
|
||||
{Name: "desc", Type: field.TypeString, Nullable: true},
|
||||
{Name: "user_id", Type: field.TypeInt64},
|
||||
}
|
||||
// CourseEntityTable holds the schema information for the "course_entity" table.
|
||||
CourseEntityTable = &schema.Table{
|
||||
Name: "course_entity",
|
||||
Columns: CourseEntityColumns,
|
||||
PrimaryKey: []*schema.Column{CourseEntityColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "course_entity_sys_user_course_entity",
|
||||
Columns: []*schema.Column{CourseEntityColumns[17]},
|
||||
RefColumns: []*schema.Column{SysUserColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
},
|
||||
}
|
||||
// CpImageColumns holds the columns for the "cp_image" table.
|
||||
CpImageColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
@@ -34,6 +69,39 @@ var (
|
||||
},
|
||||
},
|
||||
}
|
||||
// CpLeavesColumns holds the columns for the "cp_leaves" table.
|
||||
CpLeavesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "create_time", Type: field.TypeString, SchemaType: map[string]string{"mysql": "datetime", "postgres": "timestamp", "sqlite3": "datetime"}},
|
||||
{Name: "update_time", Type: field.TypeString, SchemaType: map[string]string{"mysql": "datetime", "postgres": "timestamp", "sqlite3": "datetime"}},
|
||||
{Name: "leave_id", Type: field.TypeString},
|
||||
{Name: "title", Type: field.TypeString},
|
||||
{Name: "status", Type: field.TypeEnum, Enums: []string{"done", "fail"}},
|
||||
{Name: "type", Type: field.TypeEnum, Enums: []string{"report"}},
|
||||
{Name: "desc", Type: field.TypeString, Nullable: true, Size: 2147483647},
|
||||
{Name: "cp_user_id", Type: field.TypeInt64},
|
||||
{Name: "user_id", Type: field.TypeInt64},
|
||||
}
|
||||
// CpLeavesTable holds the schema information for the "cp_leaves" table.
|
||||
CpLeavesTable = &schema.Table{
|
||||
Name: "cp_leaves",
|
||||
Columns: CpLeavesColumns,
|
||||
PrimaryKey: []*schema.Column{CpLeavesColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "cp_leaves_cp_users_cp_leave",
|
||||
Columns: []*schema.Column{CpLeavesColumns[8]},
|
||||
RefColumns: []*schema.Column{CpUsersColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
{
|
||||
Symbol: "cp_leaves_sys_user_cp_leave",
|
||||
Columns: []*schema.Column{CpLeavesColumns[9]},
|
||||
RefColumns: []*schema.Column{SysUserColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
},
|
||||
}
|
||||
// CpSchoolsColumns holds the columns for the "cp_schools" table.
|
||||
CpSchoolsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeString, Unique: true},
|
||||
@@ -133,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},
|
||||
}
|
||||
@@ -149,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,
|
||||
},
|
||||
@@ -184,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},
|
||||
@@ -223,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},
|
||||
@@ -362,13 +473,17 @@ var (
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
CourseEntityTable,
|
||||
CpImageTable,
|
||||
CpLeavesTable,
|
||||
CpSchoolsTable,
|
||||
CpTasksTable,
|
||||
CpTaskLogsTable,
|
||||
CpUsersTable,
|
||||
SysAgentTable,
|
||||
SysBalanceRecordTable,
|
||||
SysCardTable,
|
||||
SysConfigTable,
|
||||
SysMenuTable,
|
||||
SysRoleTable,
|
||||
SysUserTable,
|
||||
@@ -379,10 +494,16 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
CourseEntityTable.ForeignKeys[0].RefTable = SysUserTable
|
||||
CourseEntityTable.Annotation = &entsql.Annotation{
|
||||
Table: "course_entity",
|
||||
}
|
||||
CpImageTable.ForeignKeys[0].RefTable = SysUserTable
|
||||
CpImageTable.Annotation = &entsql.Annotation{
|
||||
Table: "cp_image",
|
||||
}
|
||||
CpLeavesTable.ForeignKeys[0].RefTable = CpUsersTable
|
||||
CpLeavesTable.ForeignKeys[1].RefTable = SysUserTable
|
||||
CpTasksTable.ForeignKeys[0].RefTable = CpUsersTable
|
||||
CpTasksTable.ForeignKeys[1].RefTable = SysUserTable
|
||||
CpTaskLogsTable.ForeignKeys[0].RefTable = CpTasksTable
|
||||
@@ -394,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",
|
||||
|
||||
+4140
-66
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user