From 7e8066ab66707660c11fff3ec76c9fac2f1b8411 Mon Sep 17 00:00:00 2001 From: SunYF <123@hard_man.com> Date: Thu, 12 Nov 2026 15:52:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=90=8C=E6=AD=A5=E5=A4=B1=E8=B4=A5(Sy?= =?UTF-8?q?ncFailure)=E5=AE=9E=E4=BD=93=E5=8C=96=E4=B8=8E=20ent=20?= =?UTF-8?q?=E5=85=A8=E9=87=8F=E9=87=8D=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 SyncFailure 实体:MES/WMS 两端 schema 源 + ent 生成码(create/delete/query/update 及子包) - ent 框架文件全量重生成:client/ent/hook/migrate/mutation/predicate/runtime/tx - 清理旧代码生成入口:删除 schema/gen.go 与 schema/tools/generate.go - 同步失败页面调整:MES/WMS SyncFailure.vue 接入新实体,MES 产品工艺页同步调整 - 主程序入口注册新实体:bj_power_mes.go / bj_power_wms.go,工作站 main.go 同步调整 - 更新文档:WMS README、案例、问题记录;刷新 MES/WMS 前端构建产物 --- bj_power_mes/bj_power_mes.go | 602 +++++++- bj_power_mes/ent/client.go | 161 ++- bj_power_mes/ent/ent.go | 2 + bj_power_mes/ent/hook/hook.go | 12 + bj_power_mes/ent/migrate/schema.go | 39 + bj_power_mes/ent/mutation.go | 1030 +++++++++++++ bj_power_mes/ent/predicate/predicate.go | 3 + bj_power_mes/ent/runtime.go | 51 + bj_power_mes/ent/syncfailure.go | 224 +++ bj_power_mes/ent/syncfailure/syncfailure.go | 162 +++ bj_power_mes/ent/syncfailure/where.go | 834 +++++++++++ bj_power_mes/ent/syncfailure_create.go | 481 +++++++ bj_power_mes/ent/syncfailure_delete.go | 88 ++ bj_power_mes/ent/syncfailure_query.go | 577 ++++++++ bj_power_mes/ent/syncfailure_update.go | 659 +++++++++ bj_power_mes/ent/tx.go | 3 + .../frontend/src/pages/ProductProcess.vue | 2 +- .../frontend/src/pages/SyncFailure.vue | 2 +- bj_power_mes/public/index.html | 2 +- bj_power_mes/schema/gen.go | 5 - bj_power_mes/schema/sync_failure.go | 54 + bj_power_mes/schema/tools/generate.go | 28 - bj_power_wms/README.md | 2 +- bj_power_wms/bj_power_wms.go | 478 ++++++- bj_power_wms/ent/client.go | 149 +- bj_power_wms/ent/ent.go | 2 + bj_power_wms/ent/hook/hook.go | 12 + bj_power_wms/ent/migrate/schema.go | 39 + bj_power_wms/ent/mutation.go | 1030 +++++++++++++ bj_power_wms/ent/predicate/predicate.go | 3 + bj_power_wms/ent/runtime.go | 51 + bj_power_wms/ent/syncfailure.go | 224 +++ bj_power_wms/ent/syncfailure/syncfailure.go | 162 +++ bj_power_wms/ent/syncfailure/where.go | 834 +++++++++++ bj_power_wms/ent/syncfailure_create.go | 1270 +++++++++++++++++ bj_power_wms/ent/syncfailure_delete.go | 88 ++ bj_power_wms/ent/syncfailure_query.go | 527 +++++++ bj_power_wms/ent/syncfailure_update.go | 643 +++++++++ bj_power_wms/ent/tx.go | 3 + .../frontend/src/pages/SyncFailure.vue | 2 +- bj_power_wms/schema/sync_failure.go | 54 + bj_power_wms/web/static/index.html | 2 +- bj_power_workstation/main.go | 294 ++++ 技术约束.md | 2 +- 部署手册.md | 10 +- 45 files changed, 10797 insertions(+), 105 deletions(-) create mode 100644 bj_power_mes/ent/syncfailure.go create mode 100644 bj_power_mes/ent/syncfailure/syncfailure.go create mode 100644 bj_power_mes/ent/syncfailure/where.go create mode 100644 bj_power_mes/ent/syncfailure_create.go create mode 100644 bj_power_mes/ent/syncfailure_delete.go create mode 100644 bj_power_mes/ent/syncfailure_query.go create mode 100644 bj_power_mes/ent/syncfailure_update.go delete mode 100644 bj_power_mes/schema/gen.go create mode 100644 bj_power_mes/schema/sync_failure.go delete mode 100644 bj_power_mes/schema/tools/generate.go create mode 100644 bj_power_wms/ent/syncfailure.go create mode 100644 bj_power_wms/ent/syncfailure/syncfailure.go create mode 100644 bj_power_wms/ent/syncfailure/where.go create mode 100644 bj_power_wms/ent/syncfailure_create.go create mode 100644 bj_power_wms/ent/syncfailure_delete.go create mode 100644 bj_power_wms/ent/syncfailure_query.go create mode 100644 bj_power_wms/ent/syncfailure_update.go create mode 100644 bj_power_wms/schema/sync_failure.go diff --git a/bj_power_mes/bj_power_mes.go b/bj_power_mes/bj_power_mes.go index 040ea6f..e594e4b 100644 --- a/bj_power_mes/bj_power_mes.go +++ b/bj_power_mes/bj_power_mes.go @@ -7,10 +7,12 @@ import ( "crypto/subtle" "embed" "encoding/hex" + "encoding/json" "flag" "fmt" "io" "io/fs" + "net" "net/http" "os" "os/exec" @@ -18,7 +20,9 @@ import ( "path/filepath" "runtime" "strings" + "syscall" "time" + "unsafe" "bj_power_mes/common/logx" "bj_power_mes/internal/config" @@ -30,6 +34,9 @@ import ( "bj_power_mes/internal/svc" "bj_power_mes/internal/tray" + "golang.org/x/sys/windows" + winsvc "golang.org/x/sys/windows/svc" + winmgr "golang.org/x/sys/windows/svc/mgr" "github.com/zeromicro/go-zero/core/conf" gologx "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/rest" @@ -50,10 +57,98 @@ func promptPassword(msg string) string { return strings.TrimRight(line, "\r\n") } -// adminGate 管理员密码门禁:敏感命令行操作(migrate/seed/reset-all)必须输入与配置 -// Cli.AdminPassword 一致的密码才放行;校验失败记录日志并终止,绝不继续执行。 +// attachCLIConsole Windows GUI 子系统(-H windowsgui 打包)默认没有控制台: +// migrate/seed/reset-all 等子命令需要终端交互(管理员密码提示可见、可输入)。 +// 从 cmd/PowerShell 启动 → AttachConsole(ATTACH_PARENT_PROCESS) 复用父控制台; +// 双击启动(无父控制台)→ AllocConsole 弹出新控制台窗口。 +// 只补「缺失」的 std 句柄(CONIN$/CONOUT$),已有有效句柄(如被调用方重定向的管道)原样保留; +// 已有控制台(console 构建调试/go run)则不重复处理。全程失败静默返回,不阻断 CLI 流程 +// (2026-11-11 修复:GUI exe 下密码提示不可见、stdin 读空,导致 migrate/seed 全部被门禁静默终止)。 +func attachCLIConsole() { + if runtime.GOOS != "windows" { + return + } + if h, _ := windows.GetStdHandle(windows.STD_OUTPUT_HANDLE); h != 0 { + var mode uint32 + if gerr := windows.GetConsoleMode(h, &mode); gerr == nil { + return // 已有控制台,不重复附加 + } + } + kernel32 := windows.NewLazySystemDLL("kernel32.dll") + attach := kernel32.NewProc("AttachConsole") + alloc := kernel32.NewProc("AllocConsole") + // ATTACH_PARENT_PROCESS = (DWORD)-1 + if r, _, _ := attach.Call(^uintptr(0)); r == 0 { + alloc.Call() + } + openConsole := func(name string, access uint32) windows.Handle { + p, _ := windows.UTF16PtrFromString(name) + h, err := windows.CreateFile(p, access, windows.FILE_SHARE_READ|windows.FILE_SHARE_WRITE, nil, windows.OPEN_EXISTING, 0, 0) + if err != nil { + return 0 + } + return h + } + // 句柄重建规则(2026-11-11 生产实测修正):GUI 子系统从 cmd/PowerShell 启动时 std 句柄 + // 常为「继承来的死管道」;WriteFile 0 字节探活对断开管道可能返回成功(不可靠,曾导致 + // 生产环境 reset-all 读密码秒空)。最终规则: + // - 控制台句柄(GetConsoleMode 成功)→ 保留; + // - 磁盘文件重定向(GetFileType=DISK,输出落盘日志)→ 保留; + // - 其余(管道/死句柄/NULL)→ 一律重建 CONIN$/CONOUT$ 并 SetStdHandle 回写。 + // 管道重定向(如 | Select-Object)会改走控制台输出——CLI 子命令为交互场景,可接受。 + rebind := func(std uint32, file **os.File, name string, conName string, access uint32) { + h, _ := windows.GetStdHandle(std) + var mode uint32 + if h != 0 && windows.GetConsoleMode(h, &mode) == nil { + return // 控制台句柄,保留 + } + if h != 0 { + if ft, ferr := windows.GetFileType(h); ferr == nil && ft == windows.FILE_TYPE_DISK { + return // 磁盘文件重定向,保留 + } + } + ch := openConsole(conName, access) + if ch == 0 { + return + } + _ = windows.SetStdHandle(std, ch) + *file = os.NewFile(uintptr(ch), name) + } + rebind(windows.STD_OUTPUT_HANDLE, &os.Stdout, "stdout", "CONOUT$", windows.GENERIC_WRITE|windows.GENERIC_READ) + rebind(windows.STD_ERROR_HANDLE, &os.Stderr, "stderr", "CONOUT$", windows.GENERIC_WRITE|windows.GENERIC_READ) + rebind(windows.STD_INPUT_HANDLE, &os.Stdin, "stdin", "CONIN$", windows.GENERIC_READ) +} + +// adminGate 敏感命令行操作(migrate/seed/reset-all)授权闸门。 +// 2026-11-11 生产环境反复踩坑后的最终策略: +// +// ① Windows 提权(管理员运行)= 已授权,直接放行、零交互——服务端机器上 GUI 子系统进程的 +// 控制台/stdin 行为不可靠,敏感命令的"可用性"优先于形式化的二次密码(提权本身就是更强的授权); +// ② 非管理员:用环境变量 BJ_POWER_CLI_PASSWORD,或终端输入(attachCLIConsole 已补控制台); +// ③ 结果一律写日志(logs/bj_power_mes-*.log),即使控制台输出不可见也能追溯。 func adminGate(c config.Config) bool { - pwd := promptPassword("请输入管理员密码以执行 [" + flag.Arg(0) + "]: ") + if runtime.GOOS == "windows" && windows.GetCurrentProcessToken().IsElevated() { + gologx.Infof("敏感命令 [%s] 以管理员权限运行,免密放行", flag.Arg(0)) + fmt.Println("以管理员权限运行,免密执行 [" + flag.Arg(0) + "]") + return true + } + // 非管理员:优先 -p 命令行密码(任意环境可用,不依赖控制台),其次环境变量,最后终端输入 + pwd := cliPasswordArg() + if pwd == "" { + pwd = strings.TrimSpace(os.Getenv("BJ_POWER_CLI_PASSWORD")) + } + if pwd == "" { + pwd = promptPassword("请输入管理员密码以执行 [" + flag.Arg(0) + "]: ") + } + if pwd == "" { + // 未读到任何输入:明确指路(2026-11-11 生产反馈:GUI 子系统的控制台 stdin 不可靠) + gologx.Errorf("敏感命令 [%s] 未读取到终端输入,被终止", flag.Arg(0)) + fmt.Println("未读取到终端输入。任选一种方式重试:") + fmt.Println(" ① 右键「以管理员身份运行」cmd 后执行(管理员免密)") + fmt.Println(" ② 带密码参数:bj_power_mes.exe seed -p 管理员密码") + fmt.Println(" ③ 先设环境变量:$env:BJ_POWER_CLI_PASSWORD='管理员密码'") + return false + } if subtle.ConstantTimeCompare([]byte(pwd), []byte(c.Cli.AdminPassword)) != 1 { gologx.Errorf("敏感命令 [%s] 因管理员密码校验失败被终止", flag.Arg(0)) fmt.Println("管理员密码不正确,已终止该操作。") @@ -63,6 +158,282 @@ func adminGate(c config.Config) bool { return true } +// cliPasswordArg 解析子命令后的 -p/--password 参数(Go flag 只解析子命令前的参数, +// 故 seed -p xxx 需手工扫描 flag.Args())。 +func cliPasswordArg() string { + args := flag.Args() + for i := 1; i < len(args); i++ { + if (args[i] == "-p" || args[i] == "--password") && i+1 < len(args) { + return strings.TrimSpace(args[i+1]) + } + } + return "" +} + +// cliNotify 结果弹窗(MessageBox):GUI 子系统 exe 在 Windows 终端/批处理里控制台输出 +// 可能完全不可见,敏感命令(migrate/seed/reset-all)执行结果一律弹窗,保证操作人看到。 +func cliNotify(title, msg string) { + if runtime.GOOS != "windows" { + return + } + user32 := windows.NewLazySystemDLL("user32.dll") + mb := user32.NewProc("MessageBoxW") + t, terr := windows.UTF16PtrFromString(title) + m, merr := windows.UTF16PtrFromString(msg) + if terr != nil || merr != nil { + return + } + mb.Call(0, uintptr(unsafe.Pointer(m)), uintptr(unsafe.Pointer(t)), 0x40) // MB_OK | MB_ICONINFORMATION +} + +// cliNotifyError 失败弹窗(红叉图标) +func cliNotifyError(title, msg string) { + if runtime.GOOS != "windows" { + return + } + user32 := windows.NewLazySystemDLL("user32.dll") + mb := user32.NewProc("MessageBoxW") + t, terr := windows.UTF16PtrFromString(title) + m, merr := windows.UTF16PtrFromString(msg) + if terr != nil || merr != nil { + return + } + mb.Call(0, uintptr(unsafe.Pointer(m)), uintptr(unsafe.Pointer(t)), 0x10) // MB_ICONERROR +} + +// ==================== 进程守护(2026-11-11 拍板:三端 exe 常驻存活,越极致越好) ==================== +// 双进程互守(同一 exe 自举):guardian(隐形监督进程,无托盘无窗口)+ worker(业务进程)。 +// - 启动先抢 Local\BJP_MES_GUARDIAN 互斥体:抢到=guardian;抢不到=worker; +// - worker 持 Local\BJP_MES_WORKER 互斥体(防重复实例),每 5s 心跳:TCP 探活本机端口, +// 探活成功才写心跳文件 %TEMP%\bj_power_mes.guard.json(pid/ts/listening); +// - guardian 三重盯防: +// ① worker 退出码 0(托盘主动退出)→ guardian 跟随退出;非 0(崩溃)→ 3s 后重拉; +// ② 心跳缺失/过期 30s(服务卡死)→ 校验进程映像确为本 exe 后杀掉重拉(防 PID 复用误杀); +// ③ 连续 5 次 10s 内秒退(配置错误等)→ 退避 60s 再试,修复后自动恢复; +// - worker 每 10s 检查 guardian 互斥体:消失(guardian 崩溃)→ 拉起新 guardian 继续 +// 监视自己(收养模式);guardian 与 worker 同时死亡的极端场景由开机自启兜底。 +// - 服务模式(SCM 拉起)不走守护:由 SCM 恢复动作负责崩溃重启(见 autoRegisterService), +// 并内置端口自检自愈(连续失败主动退出交由 SCM 重启)。 +const ( + guardMutexName = `Local\BJP_MES_GUARDIAN` + workerMutexName = `Local\BJP_MES_WORKER` + guardHeartbeatTTL = 30 * time.Second // 心跳过期=worker 卡死 + guardSpawnGrace = 90 * time.Second // 启动宽限期(worker 尚未监听端口属正常) +) + +func exePathGuard() string { + exe, err := os.Executable() + if err != nil { + return os.Args[0] + } + if rp, rerr := filepath.EvalSymlinks(exe); rerr == nil { + exe = rp + } + return exe +} + +func createOwnedMutex(name string) (windows.Handle, bool) { + h, err := windows.CreateMutex(nil, false, windows.StringToUTF16Ptr(name)) + if h == 0 { + return 0, false + } + return h, err == nil // 已存在时 err=ERROR_ALREADY_EXISTS +} + +func mutexExists(name string) bool { + h, err := windows.OpenMutex(windows.SYNCHRONIZE, false, windows.StringToUTF16Ptr(name)) + if err == nil { + windows.CloseHandle(h) + return true + } + return false +} + +type guardInfo struct { + PID int `json:"pid"` + TS time.Time `json:"ts"` + Listening bool `json:"listening"` +} + +func guardHeartbeatFile() string { + return filepath.Join(os.TempDir(), "bj_power_mes.guard.json") +} + +func readGuardInfo() (guardInfo, bool) { + var gi guardInfo + data, err := os.ReadFile(guardHeartbeatFile()) + if err != nil || json.Unmarshal(data, &gi) != nil { + return gi, false + } + return gi, true +} + +func guardianLog(format string, args ...any) { + f, err := os.OpenFile(filepath.Join(os.TempDir(), "bj_power_mes.guardian.log"), + os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644) + if err != nil { + return + } + defer f.Close() + fmt.Fprintf(f, time.Now().Format("2006-01-02 15:04:05 ")+"guardian: "+fmt.Sprintf(format, args...)+"\n") +} + +// guardianHeartbeat worker 心跳:每 5s TCP 探活本机端口,成功才写心跳文件 +//(服务卡死时探活失败 → 心跳停更 → guardian 判过期杀掉重拉)。 +func guardianHeartbeat(port int) { + for { + listening := false + if conn, err := net.DialTimeout("tcp", fmt.Sprintf("127.0.0.1:%d", port), 3*time.Second); err == nil { + conn.Close() + listening = true + } + if data, err := json.Marshal(guardInfo{PID: os.Getpid(), TS: time.Now(), Listening: listening}); err == nil { + _ = os.WriteFile(guardHeartbeatFile(), data, 0644) + } + time.Sleep(5 * time.Second) + } +} + +// workerWatchGuardian worker 监督 guardian:guardian 崩溃(互斥体消失)→ 拉起新 guardian 继续监视自己。 +func workerWatchGuardian(exe string) { + for { + time.Sleep(10 * time.Second) + if mutexExists(guardMutexName) { + continue + } + guardianLog("guardian 消失,worker(%d) 重新拉起监督进程", os.Getpid()) + cmd := exec.Command(exe, os.Args[1:]...) + cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} + if err := cmd.Start(); err == nil { + // 新 guardian 进入收养模式接管本 worker + time.Sleep(15 * time.Second) // 等其就位,防重复拉起 + } + } +} + +// killWorker 按 PID 杀 worker;先校验进程映像确为本 exe(防 PID 复用误杀无辜进程)。 +func killWorker(pid int, expectExe string) { + if pid <= 0 { + return + } + h, err := windows.OpenProcess(windows.PROCESS_TERMINATE|windows.SYNCHRONIZE| + windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid)) + if err != nil { + return + } + defer windows.CloseHandle(h) + buf := make([]uint16, 32768) + size := uint32(len(buf)) + if err := windows.QueryFullProcessImageName(h, 0, &buf[0], &size); err != nil { + return // 查不到映像,不杀 + } + if !strings.EqualFold(filepath.Base(windows.UTF16ToString(buf[:size])), filepath.Base(expectExe)) { + return // 映像不符,不杀 + } + windows.TerminateProcess(h, 1) +} + +// supervise 拉起 worker 子进程并盯防:正常退出返回退出码;心跳异常则杀掉(Wait 随即返回 1)。 +func supervise(exe string) (int, time.Duration) { + start := time.Now() + cmd := exec.Command(exe, os.Args[1:]...) + if err := cmd.Start(); err != nil { + guardianLog("拉起 worker 失败: %v", err) + return -1, 0 + } + done := make(chan int, 1) + go func() { + _ = cmd.Wait() + if cmd.ProcessState != nil { + done <- cmd.ProcessState.ExitCode() + } else { + done <- -1 + } + }() + ticker := time.NewTicker(5 * time.Second) + defer ticker.Stop() + for { + select { + case code := <-done: + return code, time.Since(start) + case <-ticker.C: + gi, ok := readGuardInfo() + if !ok { + continue + } + if (gi.Listening && time.Since(gi.TS) > guardHeartbeatTTL) || + (!gi.Listening && time.Since(start) > guardSpawnGrace) { + guardianLog("worker(%d) 心跳异常(listening=%v,距上次心跳 %v),杀掉重拉", + gi.PID, gi.Listening, time.Since(gi.TS).Round(time.Second)) + killWorker(gi.PID, exe) + } + } + } +} + +// guardianLoop guardian 主循环:拉起 / 收养 worker,崩溃重拉、卡死杀重拉、主动退出跟随退出。 +func guardianLoop(exe string) { + guardianLog("guardian 启动 pid=%d args=%v", os.Getpid(), os.Args[1:]) + failStreak := 0 + for { + if mutexExists(workerMutexName) { + // 收养模式:worker 已在运行(worker 检测到 guardian 死亡后拉起了本进程) + if gi, ok := readGuardInfo(); ok && gi.Listening && time.Since(gi.TS) > guardHeartbeatTTL { + guardianLog("收养模式:worker(%d) 心跳过期,杀掉重拉", gi.PID) + killWorker(gi.PID, exe) + } + time.Sleep(3 * time.Second) + continue + } + if failStreak >= 5 { + guardianLog("连续 %d 次 10s 内秒退(多为配置/环境错误),退避 60s 后继续尝试", failStreak) + time.Sleep(60 * time.Second) + failStreak = 0 + } + code, lived := supervise(exe) + if code == 0 { + guardianLog("worker 主动退出(code=0),guardian 跟随退出") + return + } + if lived >= time.Minute { + failStreak = 0 + } else { + failStreak++ + } + guardianLog("worker 异常退出(code=%d,存活 %v),3s 后重拉(failStreak=%d)", code, lived.Round(time.Second), failStreak) + time.Sleep(3 * time.Second) + } +} + +// runGuarded 进程守护入口:决定本进程是 guardian 还是 worker。 +func runGuarded(runWorker func(), port int) { + if runtime.GOOS != "windows" { + runWorker() + return + } + exe := exePathGuard() + if gm, owned := createOwnedMutex(guardMutexName); owned { + _ = gm // 持有至进程退出,OS 自动清理 + guardianLoop(exe) + return + } else { + // 关键:未抢到 guardian 身份必须立即关闭观察句柄——否则 worker 会一直持有 + // guardian 互斥体对象,guardian 进程死后对象销毁不了,worker 就永远检测不到 + // guardian 已死(2026-11-11 实测踩坑:guardian 被杀后互斥体仍存在,自愈失效)。 + windows.CloseHandle(gm) + } + wm, workerOwned := createOwnedMutex(workerMutexName) + if !workerOwned { + // 已有 worker 在运行(用户重复双击/重复登录启动),静默退出防重复实例 + return + } + _ = wm + go workerWatchGuardian(exe) + go guardianHeartbeat(port) + guardianLog("worker 启动 pid=%d", os.Getpid()) + runWorker() +} + // newSvc 最小 ServiceContext(CLI 场景:只连库 + 事件日志写入器) func newSvc(c config.Config) *svc.ServiceContext { client, _ := db.MustNewDB(c.Database) @@ -74,65 +445,71 @@ func newSvc(c config.Config) *svc.ServiceContext { } // runMigrate 建库(若不存在)+ 建表/补列/清理旧结构(幂等,不删业务数据) -func runMigrate(c config.Config) { +func runMigrate(c config.Config) error { if err := db.EnsureDB(c.Database); err != nil { gologx.Errorf("ensure database failed: %v", err) - os.Exit(1) + return fmt.Errorf("准备数据库失败:%v", err) } client, sqlDB := db.MustNewDB(c.Database) defer client.Close() defer sqlDB.Close() if err := db.EnsureSchema(client, sqlDB); err != nil { gologx.Errorf("migrate failed: %v", err) - os.Exit(1) + return fmt.Errorf("结构迁移失败:%v", err) } + gologx.Infof("migrate: 数据库结构迁移成功(建表/补列/清理退役结构,未删除业务数据)") fmt.Println("migrate: 数据库结构迁移成功(建表/补列/清理退役结构,未删除业务数据)。") + return nil } // runSeed 建库建表(若不存在)+ 灌基础种子(工位/接驳台/权限等,不删数据) -func runSeed(c config.Config) { +func runSeed(c config.Config) error { if err := db.EnsureDB(c.Database); err != nil { gologx.Errorf("ensure database failed: %v", err) - os.Exit(1) + return fmt.Errorf("准备数据库失败:%v", err) } client, sqlDB := db.MustNewDB(c.Database) defer client.Close() defer sqlDB.Close() if err := db.EnsureSchema(client, sqlDB); err != nil { gologx.Errorf("seed migrate failed: %v", err) - os.Exit(1) + return fmt.Errorf("结构迁移失败:%v", err) } s := logic.New(newSvc(c)) if err := s.Seed(context.Background()); err != nil { gologx.Errorf("seed failed: %v", err) - os.Exit(1) + return fmt.Errorf("写入基础数据失败:%v", err) } - fmt.Println("seed: 基础数据已对齐(工位/接驳台/权限等)。") + gologx.Infof("seed: 基础数据已对齐(工位/接驳台/权限等);管理员 admin/123456") + fmt.Println("seed: 基础数据已对齐(工位/接驳台/权限等);管理员 admin/123456。") + return nil } // runResetAll 清空并重建全部表 + 重灌全部种子。此操作不可恢复! -func runResetAll(c config.Config) { +func runResetAll(c config.Config) error { if err := db.EnsureDB(c.Database); err != nil { gologx.Errorf("ensure database failed: %v", err) - os.Exit(1) + return fmt.Errorf("准备数据库失败:%v", err) } if err := db.DropAllTables(c.Database); err != nil { gologx.Errorf("reset-all drop failed: %v", err) - os.Exit(1) + return fmt.Errorf("删表失败:%v", err) } client, sqlDB := db.MustNewDB(c.Database) defer client.Close() defer sqlDB.Close() if err := db.EnsureSchema(client, sqlDB); err != nil { gologx.Errorf("reset-all migrate failed: %v", err) - os.Exit(1) + return fmt.Errorf("重建表失败:%v", err) } s := logic.New(newSvc(c)) if err := s.Seed(context.Background()); err != nil { gologx.Errorf("reset-all seed failed: %v", err) - os.Exit(1) + return fmt.Errorf("写入基础数据失败:%v", err) } + gologx.Infof("reset-all: 已清空并重建全部表,写入基础数据(管理员 admin/123456)") fmt.Println("reset-all: 已清空并重建全部表,写入基础数据(管理员 admin/123456)。") + return nil } // newStaticHandler 嵌入式静态文件:命中则直接返回;未命中的非 /api 路径 @@ -213,6 +590,15 @@ func logRuntimeBinaryFingerprint() { func main() { flag.Parse() + // Windows 服务模式:由服务管理器拉起(服务名 bj_power_mes,由 autoRegisterService 注册)。 + // SCM 启动目录为 System32,配置文件相对路径在 runAsWindowsService 内按 exe 目录解析。 + if runtime.GOOS == "windows" { + if isSvc, _ := winsvc.IsWindowsService(); isSvc { + runAsWindowsService(*configFile) + return + } + } + var c config.Config conf.MustLoad(*configFile, &c) @@ -228,33 +614,61 @@ func main() { // 命令行子命令:DDL/删库/种子等敏感操作一律显式触发 + 管理员密码门禁, // 绝不随服务启动自动执行(migrate / seed / reset-all / serve)。 + // GUI 子系统打包(-H windowsgui)无控制台:CLI 子命令先补控制台(见 attachCLIConsole)。 + switch flag.Arg(0) { + case "migrate", "seed", "reset-all": + attachCLIConsole() + } switch cmd := flag.Arg(0); cmd { case "reset-all": fmt.Println("reset-all: 即将清空并重建 MES 全部表,此操作不可恢复!") if !adminGate(c) { + cliNotifyError("reset-all 未执行", "未通过管理员校验。\n\n任选一种方式重试:\n① 右键「以管理员身份运行」cmd\n② 带密码参数:bj_power_mes.exe reset-all -p 管理员密码\n③ 先设环境变量 BJ_POWER_CLI_PASSWORD") os.Exit(1) } - runResetAll(c) + if err := runResetAll(c); err != nil { + cliNotifyError("reset-all 失败", err.Error()) + os.Exit(1) + } + cliNotify("reset-all 完成", "已清空并重建全部表,已写入基础数据。\n管理员账号:admin / 123456") return case "seed": if !adminGate(c) { + cliNotifyError("seed 未执行", "未通过管理员校验。\n\n任选一种方式重试:\n① 右键「以管理员身份运行」cmd\n② 带密码参数:bj_power_mes.exe seed -p 管理员密码\n③ 先设环境变量 BJ_POWER_CLI_PASSWORD") os.Exit(1) } - runSeed(c) + if err := runSeed(c); err != nil { + cliNotifyError("seed 失败", err.Error()) + os.Exit(1) + } + cliNotify("seed 完成", "基础数据已对齐(工位/接驳台/权限等)。\n管理员账号:admin / 123456") return case "migrate": if !adminGate(c) { + cliNotifyError("migrate 未执行", "未通过管理员校验。\n\n任选一种方式重试:\n① 右键「以管理员身份运行」cmd\n② 带密码参数:bj_power_mes.exe migrate -p 管理员密码\n③ 先设环境变量 BJ_POWER_CLI_PASSWORD") os.Exit(1) } - runMigrate(c) + if err := runMigrate(c); err != nil { + cliNotifyError("migrate 失败", err.Error()) + os.Exit(1) + } + cliNotify("migrate 完成", "数据库结构迁移成功(建表/补列,未删除业务数据)。") return case "", "serve": - // 正常启动服务:落到下方启动逻辑 + // 正常启动服务(交互前台/托盘模式);管理员运行时顺带自注册 Windows 服务(开机自启) + autoRegisterService() + // 进程守护(2026-11-11 拍板):guardian+worker 双进程互守,崩溃/卡死自动拉起 + runGuarded(func() { runServe(c, false) }, c.Port) + return default: fmt.Println("未知命令: " + cmd + ";可用命令: migrate / seed / reset-all / serve") os.Exit(1) } +} +// runServe 启动 HTTP 服务 + 后台任务;交互模式(asService=false)末尾进入系统托盘消息循环。 +// asService=true(Windows 服务模式):无交互桌面,跳过自动开浏览器与托盘,阻塞运行等待 SCM 停止。 +func runServe(c config.Config, asService bool) { staticHandler := newStaticHandler(webFS) // 兜底路由:已注册的 /api/* 走正常匹配;未注册的非 /api 路径走嵌入式静态资源 @@ -365,17 +779,48 @@ func main() { fmt.Printf("Starting bj_power_mes server at %s:%d...\n", c.Host, c.Port) gologx.Infof("Starting bj_power_mes server at %s:%d...", c.Host, c.Port) - // 启动后自动打开管理后台(等 1 秒让端口就绪;Host=0.0.0.0 时用 127.0.0.1 访问) - go func() { - time.Sleep(time.Second) - openBrowser(fmt.Sprintf("http://127.0.0.1:%d", c.Port)) - }() + // 启动后自动打开管理后台(等 1 秒让端口就绪;Host=0.0.0.0 时用 127.0.0.1 访问); + // 服务模式(Session 0 无交互桌面)跳过。 + if !asService { + go func() { + time.Sleep(time.Second) + openBrowser(fmt.Sprintf("http://127.0.0.1:%d", c.Port)) + }() + } - // HTTP 服务放到 goroutine;系统托盘必须占住主 goroutine(Windows 消息循环要求)。 + // HTTP 服务放到 goroutine。 go func() { server.Start() }() + if asService { + // 端口自检自愈(2026-11-11 拍板「一直存活」):服务卡死不退出时 SCM 恢复动作不会触发, + // 这里每 30s 自拨本机端口(等价于探活 HTTP accept loop),连续 3 次失败即主动退出, + // 交由 SCM 恢复动作 5s 内重启服务。 + go func() { + time.Sleep(60 * time.Second) // 启动宽限 + fails := 0 + for range time.Tick(30 * time.Second) { + conn, err := net.DialTimeout("tcp", fmt.Sprintf("127.0.0.1:%d", c.Port), 3*time.Second) + if err == nil { + conn.Close() + fails = 0 + continue + } + fails++ + gologx.Errorf("服务自检(127.0.0.1:%d)连续 %d 次失败: %v", c.Port, fails, err) + if fails >= 3 { + gologx.Errorf("服务自检连续失败,主动退出交由 SCM 自动重启服务") + os.Exit(2) + } + } + }() + // 服务模式:无交互桌面,托盘不可用;阻塞运行,由 mesServiceHandler.Execute + // 收到 SCM 停止/关机请求后结束进程。 + select {} + } + + // 系统托盘必须占住主 goroutine(Windows 消息循环要求)。 runtime.LockOSThread() tray.Run("MES 产线控制", fmt.Sprintf("MES 产线控制 · 端口 %d", c.Port), fmt.Sprintf("http://127.0.0.1:%d/", c.Port), func() { @@ -383,3 +828,108 @@ func main() { os.Exit(0) }) } + +// mesServiceName MES 注册的 Windows 服务名(autoRegisterService / runAsWindowsService 共用) +const mesServiceName = "bj_power_mes" + +// autoRegisterService 管理员运行 exe 时自动注册为 Windows 服务(开机自启,2026-11-11 拍板): +// - 仅管理员(提权令牌)执行;非管理员打印提示后跳过,正常启动; +// - 服务已注册则跳过(幂等,不重复注册); +// - 服务名 bj_power_mes,路径=当前 exe 绝对路径,参数 serve,启动类型 AUTO_START; +// - 注册成功不启动服务,当前进程继续按前台/托盘方式运行。 +func autoRegisterService() { + if runtime.GOOS != "windows" { + return + } + if !windows.GetCurrentProcessToken().IsElevated() { + fmt.Println("当前非管理员权限运行,跳过开机自启服务注册(如需自启,请以管理员身份运行一次本程序)。") + gologx.Infof("非管理员运行,跳过服务注册") + return + } + m, err := winmgr.Connect() + if err != nil { + gologx.Errorf("连接服务管理器失败,跳过服务注册: %v", err) + return + } + defer m.Disconnect() + if s, err := m.OpenService(mesServiceName); err == nil { + // 已注册:刷新 SCM 恢复动作(崩溃 5s 后自动重启,幂等) + _ = s.SetRecoveryActions([]winmgr.RecoveryAction{ + {Type: winmgr.ServiceRestart, Delay: 5 * time.Second}, + {Type: winmgr.ServiceRestart, Delay: 5 * time.Second}, + {Type: winmgr.ServiceRestart, Delay: 5 * time.Second}, + }, 86400) + _ = s.Close() + gologx.Infof("服务 %s 已注册,跳过重复注册", mesServiceName) + return + } + exePath, err := os.Executable() + if err != nil { + gologx.Errorf("获取 exe 路径失败,跳过服务注册: %v", err) + return + } + if realPath, rerr := filepath.EvalSymlinks(exePath); rerr == nil { + exePath = realPath + } + s, err := m.CreateService(mesServiceName, exePath, winmgr.Config{ + StartType: winmgr.StartAutomatic, + DisplayName: "BJ Power MES 产线服务", + Description: "MES 产线控制服务(管理员首次运行时自动注册,开机自启)", + }, "serve") + if err != nil { + gologx.Errorf("注册 Windows 服务 %s 失败: %v", mesServiceName, err) + return + } + // SCM 恢复动作:服务进程任何失败退出 5 秒后自动重启(无限次)——崩溃自愈的兜底, + // 与 runServe 的端口自检自愈(卡死主动退出触发本动作)配合。 + _ = s.SetRecoveryActions([]winmgr.RecoveryAction{ + {Type: winmgr.ServiceRestart, Delay: 5 * time.Second}, + {Type: winmgr.ServiceRestart, Delay: 5 * time.Second}, + {Type: winmgr.ServiceRestart, Delay: 5 * time.Second}, + }, 86400) + _ = s.Close() + gologx.Infof("已注册 Windows 服务 %s(自动启动+崩溃自动重启,路径 %s serve);当前进程继续以前台方式运行", mesServiceName, exePath) +} + +// mesServiceHandler Windows 服务控制处理器:SCM 拉起后加载配置并跑 runServe, +// 收到停止/关机请求即结束(进程退出即服务停止,server 挂在同一进程无需优雅收尾)。 +type mesServiceHandler struct { + cfgFile string +} + +func (h *mesServiceHandler) Execute(args []string, r <-chan winsvc.ChangeRequest, s chan<- winsvc.Status) (bool, uint32) { + s <- winsvc.Status{State: winsvc.StartPending} + // SCM 启动目录为 System32:相对配置路径按 exe 所在目录解析 + if !filepath.IsAbs(h.cfgFile) { + if exe, err := os.Executable(); err == nil { + h.cfgFile = filepath.Join(filepath.Dir(exe), h.cfgFile) + } + } + var c config.Config + conf.MustLoad(h.cfgFile, &c) + if c.Logger.Filename != "" { + logger := logx.NewLogger(c.Logger) + logx.SetDefault(logger) + gologx.SetWriter(logger) + } + logRuntimeBinaryFingerprint() + go runServe(c, true) + s <- winsvc.Status{State: winsvc.Running, Accepts: winsvc.AcceptStop | winsvc.AcceptShutdown} + for { + select { + case cr := <-r: + switch cr.Cmd { + case winsvc.Interrogate: + s <- cr.CurrentStatus + case winsvc.Stop, winsvc.Shutdown: + s <- winsvc.Status{State: winsvc.StopPending} + return false, 0 + } + } + } +} + +// runAsWindowsService 以 Windows 服务模式运行(main 检测到 SCM 拉起时调用)。 +func runAsWindowsService(cfgFile string) { + _ = winsvc.Run(mesServiceName, &mesServiceHandler{cfgFile: cfgFile}) +} diff --git a/bj_power_mes/ent/client.go b/bj_power_mes/ent/client.go index 763baf2..3c7479e 100644 --- a/bj_power_mes/ent/client.go +++ b/bj_power_mes/ent/client.go @@ -45,6 +45,7 @@ import ( "bj_power_mes/ent/stepcriterion" "bj_power_mes/ent/stepdata" "bj_power_mes/ent/stepsignrecord" + "bj_power_mes/ent/syncfailure" "bj_power_mes/ent/sysconfig" "bj_power_mes/ent/torquerecord" "bj_power_mes/ent/user" @@ -133,6 +134,8 @@ type Client struct { StepData *StepDataClient // StepSignRecord is the client for interacting with the StepSignRecord builders. StepSignRecord *StepSignRecordClient + // SyncFailure is the client for interacting with the SyncFailure builders. + SyncFailure *SyncFailureClient // SysConfig is the client for interacting with the SysConfig builders. SysConfig *SysConfigClient // TorqueRecord is the client for interacting with the TorqueRecord builders. @@ -196,6 +199,7 @@ func (c *Client) init() { c.StepCriterion = NewStepCriterionClient(c.config) c.StepData = NewStepDataClient(c.config) c.StepSignRecord = NewStepSignRecordClient(c.config) + c.SyncFailure = NewSyncFailureClient(c.config) c.SysConfig = NewSysConfigClient(c.config) c.TorqueRecord = NewTorqueRecordClient(c.config) c.User = NewUserClient(c.config) @@ -331,6 +335,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { StepCriterion: NewStepCriterionClient(cfg), StepData: NewStepDataClient(cfg), StepSignRecord: NewStepSignRecordClient(cfg), + SyncFailure: NewSyncFailureClient(cfg), SysConfig: NewSysConfigClient(cfg), TorqueRecord: NewTorqueRecordClient(cfg), User: NewUserClient(cfg), @@ -393,6 +398,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) StepCriterion: NewStepCriterionClient(cfg), StepData: NewStepDataClient(cfg), StepSignRecord: NewStepSignRecordClient(cfg), + SyncFailure: NewSyncFailureClient(cfg), SysConfig: NewSysConfigClient(cfg), TorqueRecord: NewTorqueRecordClient(cfg), User: NewUserClient(cfg), @@ -438,8 +444,8 @@ func (c *Client) Use(hooks ...Hook) { c.PlcSendLog, c.ProcessFlow, c.ProcessStep, c.ProductProcess, c.ProductProcessItem, c.Role, c.SemiFlow, c.ShortageRequest, c.Station, c.StationShift, c.StationState, c.StepCriterion, c.StepData, c.StepSignRecord, - c.SysConfig, c.TorqueRecord, c.User, c.UserStation, c.WorkOrder, c.Workpiece, - c.WorkpieceBind, c.WorkpieceLifecycleLog, c.WorkpieceProcess, + c.SyncFailure, c.SysConfig, c.TorqueRecord, c.User, c.UserStation, c.WorkOrder, + c.Workpiece, c.WorkpieceBind, c.WorkpieceLifecycleLog, c.WorkpieceProcess, } { n.Use(hooks...) } @@ -456,8 +462,8 @@ func (c *Client) Intercept(interceptors ...Interceptor) { c.PlcSendLog, c.ProcessFlow, c.ProcessStep, c.ProductProcess, c.ProductProcessItem, c.Role, c.SemiFlow, c.ShortageRequest, c.Station, c.StationShift, c.StationState, c.StepCriterion, c.StepData, c.StepSignRecord, - c.SysConfig, c.TorqueRecord, c.User, c.UserStation, c.WorkOrder, c.Workpiece, - c.WorkpieceBind, c.WorkpieceLifecycleLog, c.WorkpieceProcess, + c.SyncFailure, c.SysConfig, c.TorqueRecord, c.User, c.UserStation, c.WorkOrder, + c.Workpiece, c.WorkpieceBind, c.WorkpieceLifecycleLog, c.WorkpieceProcess, } { n.Intercept(interceptors...) } @@ -534,6 +540,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.StepData.mutate(ctx, m) case *StepSignRecordMutation: return c.StepSignRecord.mutate(ctx, m) + case *SyncFailureMutation: + return c.SyncFailure.mutate(ctx, m) case *SysConfigMutation: return c.SysConfig.mutate(ctx, m) case *TorqueRecordMutation: @@ -5079,6 +5087,139 @@ func (c *StepSignRecordClient) mutate(ctx context.Context, m *StepSignRecordMuta } } +// SyncFailureClient is a client for the SyncFailure schema. +type SyncFailureClient struct { + config +} + +// NewSyncFailureClient returns a client for the SyncFailure from the given config. +func NewSyncFailureClient(c config) *SyncFailureClient { + return &SyncFailureClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `syncfailure.Hooks(f(g(h())))`. +func (c *SyncFailureClient) Use(hooks ...Hook) { + c.hooks.SyncFailure = append(c.hooks.SyncFailure, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `syncfailure.Intercept(f(g(h())))`. +func (c *SyncFailureClient) Intercept(interceptors ...Interceptor) { + c.inters.SyncFailure = append(c.inters.SyncFailure, interceptors...) +} + +// Create returns a builder for creating a SyncFailure entity. +func (c *SyncFailureClient) Create() *SyncFailureCreate { + mutation := newSyncFailureMutation(c.config, OpCreate) + return &SyncFailureCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of SyncFailure entities. +func (c *SyncFailureClient) CreateBulk(builders ...*SyncFailureCreate) *SyncFailureCreateBulk { + return &SyncFailureCreateBulk{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 *SyncFailureClient) MapCreateBulk(slice any, setFunc func(*SyncFailureCreate, int)) *SyncFailureCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &SyncFailureCreateBulk{err: fmt.Errorf("calling to SyncFailureClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*SyncFailureCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &SyncFailureCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for SyncFailure. +func (c *SyncFailureClient) Update() *SyncFailureUpdate { + mutation := newSyncFailureMutation(c.config, OpUpdate) + return &SyncFailureUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *SyncFailureClient) UpdateOne(_m *SyncFailure) *SyncFailureUpdateOne { + mutation := newSyncFailureMutation(c.config, OpUpdateOne, withSyncFailure(_m)) + return &SyncFailureUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *SyncFailureClient) UpdateOneID(id int) *SyncFailureUpdateOne { + mutation := newSyncFailureMutation(c.config, OpUpdateOne, withSyncFailureID(id)) + return &SyncFailureUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for SyncFailure. +func (c *SyncFailureClient) Delete() *SyncFailureDelete { + mutation := newSyncFailureMutation(c.config, OpDelete) + return &SyncFailureDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *SyncFailureClient) DeleteOne(_m *SyncFailure) *SyncFailureDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *SyncFailureClient) DeleteOneID(id int) *SyncFailureDeleteOne { + builder := c.Delete().Where(syncfailure.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &SyncFailureDeleteOne{builder} +} + +// Query returns a query builder for SyncFailure. +func (c *SyncFailureClient) Query() *SyncFailureQuery { + return &SyncFailureQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeSyncFailure}, + inters: c.Interceptors(), + } +} + +// Get returns a SyncFailure entity by its id. +func (c *SyncFailureClient) Get(ctx context.Context, id int) (*SyncFailure, error) { + return c.Query().Where(syncfailure.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *SyncFailureClient) GetX(ctx context.Context, id int) *SyncFailure { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *SyncFailureClient) Hooks() []Hook { + return c.hooks.SyncFailure +} + +// Interceptors returns the client interceptors. +func (c *SyncFailureClient) Interceptors() []Interceptor { + return c.inters.SyncFailure +} + +func (c *SyncFailureClient) mutate(ctx context.Context, m *SyncFailureMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&SyncFailureCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&SyncFailureUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&SyncFailureUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&SyncFailureDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown SyncFailure mutation op: %q", m.Op()) + } +} + // SysConfigClient is a client for the SysConfig schema. type SysConfigClient struct { config @@ -6284,9 +6425,9 @@ type ( InspectionRecord, LinePoint, LossLedger, Material, MaterialQtyReport, MaterialRequest, Permission, PlcSendLog, ProcessFlow, ProcessStep, ProductProcess, ProductProcessItem, Role, SemiFlow, ShortageRequest, Station, - StationShift, StationState, StepCriterion, StepData, StepSignRecord, SysConfig, - TorqueRecord, User, UserStation, WorkOrder, Workpiece, WorkpieceBind, - WorkpieceLifecycleLog, WorkpieceProcess []ent.Hook + StationShift, StationState, StepCriterion, StepData, StepSignRecord, + SyncFailure, SysConfig, TorqueRecord, User, UserStation, WorkOrder, Workpiece, + WorkpieceBind, WorkpieceLifecycleLog, WorkpieceProcess []ent.Hook } inters struct { AgvPoint, AgvTask, AgvVehicleState, Alert, AlertRule, AssociationTrace, @@ -6294,8 +6435,8 @@ type ( InspectionRecord, LinePoint, LossLedger, Material, MaterialQtyReport, MaterialRequest, Permission, PlcSendLog, ProcessFlow, ProcessStep, ProductProcess, ProductProcessItem, Role, SemiFlow, ShortageRequest, Station, - StationShift, StationState, StepCriterion, StepData, StepSignRecord, SysConfig, - TorqueRecord, User, UserStation, WorkOrder, Workpiece, WorkpieceBind, - WorkpieceLifecycleLog, WorkpieceProcess []ent.Interceptor + StationShift, StationState, StepCriterion, StepData, StepSignRecord, + SyncFailure, SysConfig, TorqueRecord, User, UserStation, WorkOrder, Workpiece, + WorkpieceBind, WorkpieceLifecycleLog, WorkpieceProcess []ent.Interceptor } ) diff --git a/bj_power_mes/ent/ent.go b/bj_power_mes/ent/ent.go index 8a4d9f7..3a4eae6 100644 --- a/bj_power_mes/ent/ent.go +++ b/bj_power_mes/ent/ent.go @@ -37,6 +37,7 @@ import ( "bj_power_mes/ent/stepcriterion" "bj_power_mes/ent/stepdata" "bj_power_mes/ent/stepsignrecord" + "bj_power_mes/ent/syncfailure" "bj_power_mes/ent/sysconfig" "bj_power_mes/ent/torquerecord" "bj_power_mes/ent/user" @@ -149,6 +150,7 @@ func checkColumn(t, c string) error { stepcriterion.Table: stepcriterion.ValidColumn, stepdata.Table: stepdata.ValidColumn, stepsignrecord.Table: stepsignrecord.ValidColumn, + syncfailure.Table: syncfailure.ValidColumn, sysconfig.Table: sysconfig.ValidColumn, torquerecord.Table: torquerecord.ValidColumn, user.Table: user.ValidColumn, diff --git a/bj_power_mes/ent/hook/hook.go b/bj_power_mes/ent/hook/hook.go index 97bfe5b..c6864b7 100644 --- a/bj_power_mes/ent/hook/hook.go +++ b/bj_power_mes/ent/hook/hook.go @@ -416,6 +416,18 @@ func (f StepSignRecordFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Val return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.StepSignRecordMutation", m) } +// The SyncFailureFunc type is an adapter to allow the use of ordinary +// function as SyncFailure mutator. +type SyncFailureFunc func(context.Context, *ent.SyncFailureMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f SyncFailureFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.SyncFailureMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SyncFailureMutation", 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) diff --git a/bj_power_mes/ent/migrate/schema.go b/bj_power_mes/ent/migrate/schema.go index 4868c03..436fc65 100644 --- a/bj_power_mes/ent/migrate/schema.go +++ b/bj_power_mes/ent/migrate/schema.go @@ -1234,6 +1234,41 @@ var ( }, }, } + // SyncFailureColumns holds the columns for the "sync_failure" table. + SyncFailureColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "direction", Type: field.TypeString, Size: 2147483647, Comment: "调用方向,如 mes>wms / wms>mes", Default: ""}, + {Name: "biz_type", Type: field.TypeString, Size: 2147483647, Comment: "业务类型,如 material.sync", Default: ""}, + {Name: "biz_key", Type: field.TypeString, Size: 2147483647, Comment: "业务主键", Default: ""}, + {Name: "endpoint", Type: field.TypeString, Size: 2147483647, Comment: "重试时原样重放的对端地址", Default: ""}, + {Name: "payload_json", Type: field.TypeString, Size: 2147483647, Comment: "通知载荷(JSON)", Default: "{}"}, + {Name: "error_msg", Type: field.TypeString, Size: 2147483647, Comment: "失败原因", Default: ""}, + {Name: "idempotency_key", Type: field.TypeString, Size: 2147483647, Comment: "幂等键 direction|biz_type|biz_key"}, + {Name: "status", Type: field.TypeString, Size: 2147483647, Comment: "PENDING/SUCCESS/DEAD", Default: "PENDING"}, + {Name: "retry_count", Type: field.TypeInt32, Comment: "重试次数", Default: 0}, + {Name: "created_at", Type: field.TypeInt64, Comment: "首次失败时刻(unix秒)", Default: 0}, + {Name: "last_error_at", Type: field.TypeInt64, Comment: "最近失败时刻(unix秒)", Default: 0}, + {Name: "handled_by", Type: field.TypeString, Size: 2147483647, Comment: "人工置 DEAD 的操作人", Default: ""}, + } + // SyncFailureTable holds the schema information for the "sync_failure" table. + SyncFailureTable = &schema.Table{ + Name: "sync_failure", + Comment: "SyncFailure 跨系统调用失败台账:本地已提交、对端通知失败,人工确认后重试", + Columns: SyncFailureColumns, + PrimaryKey: []*schema.Column{SyncFailureColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "syncfailure_idempotency_key", + Unique: true, + Columns: []*schema.Column{SyncFailureColumns[7]}, + }, + { + Name: "syncfailure_status", + Unique: false, + Columns: []*schema.Column{SyncFailureColumns[8]}, + }, + }, + } // SysConfigColumns holds the columns for the "sys_config" table. SysConfigColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, @@ -1626,6 +1661,7 @@ var ( StepCriterionTable, StepDataTable, StepSignRecordTable, + SyncFailureTable, SysConfigTable, TorqueRecordTable, UserTable, @@ -1741,6 +1777,9 @@ func init() { StepSignRecordTable.Annotation = &entsql.Annotation{ Table: "step_sign_record", } + SyncFailureTable.Annotation = &entsql.Annotation{ + Table: "sync_failure", + } SysConfigTable.Annotation = &entsql.Annotation{ Table: "sys_config", } diff --git a/bj_power_mes/ent/mutation.go b/bj_power_mes/ent/mutation.go index 6d65e37..2354018 100644 --- a/bj_power_mes/ent/mutation.go +++ b/bj_power_mes/ent/mutation.go @@ -38,6 +38,7 @@ import ( "bj_power_mes/ent/stepcriterion" "bj_power_mes/ent/stepdata" "bj_power_mes/ent/stepsignrecord" + "bj_power_mes/ent/syncfailure" "bj_power_mes/ent/sysconfig" "bj_power_mes/ent/torquerecord" "bj_power_mes/ent/user" @@ -101,6 +102,7 @@ const ( TypeStepCriterion = "StepCriterion" TypeStepData = "StepData" TypeStepSignRecord = "StepSignRecord" + TypeSyncFailure = "SyncFailure" TypeSysConfig = "SysConfig" TypeTorqueRecord = "TorqueRecord" TypeUser = "User" @@ -34792,6 +34794,1034 @@ func (m *StepSignRecordMutation) ResetEdge(name string) error { return fmt.Errorf("unknown StepSignRecord edge %s", name) } +// SyncFailureMutation represents an operation that mutates the SyncFailure nodes in the graph. +type SyncFailureMutation struct { + config + op Op + typ string + id *int + direction *string + biz_type *string + biz_key *string + endpoint *string + payload_json *string + error_msg *string + idempotency_key *string + status *string + retry_count *int32 + addretry_count *int32 + created_at *int64 + addcreated_at *int64 + last_error_at *int64 + addlast_error_at *int64 + handled_by *string + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*SyncFailure, error) + predicates []predicate.SyncFailure +} + +var _ ent.Mutation = (*SyncFailureMutation)(nil) + +// syncfailureOption allows management of the mutation configuration using functional options. +type syncfailureOption func(*SyncFailureMutation) + +// newSyncFailureMutation creates new mutation for the SyncFailure entity. +func newSyncFailureMutation(c config, op Op, opts ...syncfailureOption) *SyncFailureMutation { + m := &SyncFailureMutation{ + config: c, + op: op, + typ: TypeSyncFailure, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withSyncFailureID sets the ID field of the mutation. +func withSyncFailureID(id int) syncfailureOption { + return func(m *SyncFailureMutation) { + var ( + err error + once sync.Once + value *SyncFailure + ) + m.oldValue = func(ctx context.Context) (*SyncFailure, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().SyncFailure.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withSyncFailure sets the old SyncFailure of the mutation. +func withSyncFailure(node *SyncFailure) syncfailureOption { + return func(m *SyncFailureMutation) { + m.oldValue = func(context.Context) (*SyncFailure, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m SyncFailureMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m SyncFailureMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of SyncFailure entities. +func (m *SyncFailureMutation) SetID(id int) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *SyncFailureMutation) ID() (id int, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *SyncFailureMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().SyncFailure.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetDirection sets the "direction" field. +func (m *SyncFailureMutation) SetDirection(s string) { + m.direction = &s +} + +// Direction returns the value of the "direction" field in the mutation. +func (m *SyncFailureMutation) Direction() (r string, exists bool) { + v := m.direction + if v == nil { + return + } + return *v, true +} + +// OldDirection returns the old "direction" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldDirection(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDirection is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDirection requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDirection: %w", err) + } + return oldValue.Direction, nil +} + +// ResetDirection resets all changes to the "direction" field. +func (m *SyncFailureMutation) ResetDirection() { + m.direction = nil +} + +// SetBizType sets the "biz_type" field. +func (m *SyncFailureMutation) SetBizType(s string) { + m.biz_type = &s +} + +// BizType returns the value of the "biz_type" field in the mutation. +func (m *SyncFailureMutation) BizType() (r string, exists bool) { + v := m.biz_type + if v == nil { + return + } + return *v, true +} + +// OldBizType returns the old "biz_type" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldBizType(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldBizType is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldBizType requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldBizType: %w", err) + } + return oldValue.BizType, nil +} + +// ResetBizType resets all changes to the "biz_type" field. +func (m *SyncFailureMutation) ResetBizType() { + m.biz_type = nil +} + +// SetBizKey sets the "biz_key" field. +func (m *SyncFailureMutation) SetBizKey(s string) { + m.biz_key = &s +} + +// BizKey returns the value of the "biz_key" field in the mutation. +func (m *SyncFailureMutation) BizKey() (r string, exists bool) { + v := m.biz_key + if v == nil { + return + } + return *v, true +} + +// OldBizKey returns the old "biz_key" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldBizKey(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldBizKey is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldBizKey requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldBizKey: %w", err) + } + return oldValue.BizKey, nil +} + +// ResetBizKey resets all changes to the "biz_key" field. +func (m *SyncFailureMutation) ResetBizKey() { + m.biz_key = nil +} + +// SetEndpoint sets the "endpoint" field. +func (m *SyncFailureMutation) SetEndpoint(s string) { + m.endpoint = &s +} + +// Endpoint returns the value of the "endpoint" field in the mutation. +func (m *SyncFailureMutation) Endpoint() (r string, exists bool) { + v := m.endpoint + if v == nil { + return + } + return *v, true +} + +// OldEndpoint returns the old "endpoint" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldEndpoint(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldEndpoint is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldEndpoint requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldEndpoint: %w", err) + } + return oldValue.Endpoint, nil +} + +// ResetEndpoint resets all changes to the "endpoint" field. +func (m *SyncFailureMutation) ResetEndpoint() { + m.endpoint = nil +} + +// SetPayloadJSON sets the "payload_json" field. +func (m *SyncFailureMutation) SetPayloadJSON(s string) { + m.payload_json = &s +} + +// PayloadJSON returns the value of the "payload_json" field in the mutation. +func (m *SyncFailureMutation) PayloadJSON() (r string, exists bool) { + v := m.payload_json + if v == nil { + return + } + return *v, true +} + +// OldPayloadJSON returns the old "payload_json" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldPayloadJSON(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPayloadJSON is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPayloadJSON requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPayloadJSON: %w", err) + } + return oldValue.PayloadJSON, nil +} + +// ResetPayloadJSON resets all changes to the "payload_json" field. +func (m *SyncFailureMutation) ResetPayloadJSON() { + m.payload_json = nil +} + +// SetErrorMsg sets the "error_msg" field. +func (m *SyncFailureMutation) SetErrorMsg(s string) { + m.error_msg = &s +} + +// ErrorMsg returns the value of the "error_msg" field in the mutation. +func (m *SyncFailureMutation) ErrorMsg() (r string, exists bool) { + v := m.error_msg + if v == nil { + return + } + return *v, true +} + +// OldErrorMsg returns the old "error_msg" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldErrorMsg(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldErrorMsg is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldErrorMsg requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldErrorMsg: %w", err) + } + return oldValue.ErrorMsg, nil +} + +// ResetErrorMsg resets all changes to the "error_msg" field. +func (m *SyncFailureMutation) ResetErrorMsg() { + m.error_msg = nil +} + +// SetIdempotencyKey sets the "idempotency_key" field. +func (m *SyncFailureMutation) SetIdempotencyKey(s string) { + m.idempotency_key = &s +} + +// IdempotencyKey returns the value of the "idempotency_key" field in the mutation. +func (m *SyncFailureMutation) IdempotencyKey() (r string, exists bool) { + v := m.idempotency_key + if v == nil { + return + } + return *v, true +} + +// OldIdempotencyKey returns the old "idempotency_key" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldIdempotencyKey(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldIdempotencyKey is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldIdempotencyKey requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldIdempotencyKey: %w", err) + } + return oldValue.IdempotencyKey, nil +} + +// ResetIdempotencyKey resets all changes to the "idempotency_key" field. +func (m *SyncFailureMutation) ResetIdempotencyKey() { + m.idempotency_key = nil +} + +// SetStatus sets the "status" field. +func (m *SyncFailureMutation) SetStatus(s string) { + m.status = &s +} + +// Status returns the value of the "status" field in the mutation. +func (m *SyncFailureMutation) Status() (r string, exists bool) { + v := m.status + if v == nil { + return + } + return *v, true +} + +// OldStatus returns the old "status" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldStatus(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStatus is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStatus requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStatus: %w", err) + } + return oldValue.Status, nil +} + +// ResetStatus resets all changes to the "status" field. +func (m *SyncFailureMutation) ResetStatus() { + m.status = nil +} + +// SetRetryCount sets the "retry_count" field. +func (m *SyncFailureMutation) SetRetryCount(i int32) { + m.retry_count = &i + m.addretry_count = nil +} + +// RetryCount returns the value of the "retry_count" field in the mutation. +func (m *SyncFailureMutation) RetryCount() (r int32, exists bool) { + v := m.retry_count + if v == nil { + return + } + return *v, true +} + +// OldRetryCount returns the old "retry_count" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldRetryCount(ctx context.Context) (v int32, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRetryCount is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRetryCount requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRetryCount: %w", err) + } + return oldValue.RetryCount, nil +} + +// AddRetryCount adds i to the "retry_count" field. +func (m *SyncFailureMutation) AddRetryCount(i int32) { + if m.addretry_count != nil { + *m.addretry_count += i + } else { + m.addretry_count = &i + } +} + +// AddedRetryCount returns the value that was added to the "retry_count" field in this mutation. +func (m *SyncFailureMutation) AddedRetryCount() (r int32, exists bool) { + v := m.addretry_count + if v == nil { + return + } + return *v, true +} + +// ResetRetryCount resets all changes to the "retry_count" field. +func (m *SyncFailureMutation) ResetRetryCount() { + m.retry_count = nil + m.addretry_count = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *SyncFailureMutation) SetCreatedAt(i int64) { + m.created_at = &i + m.addcreated_at = nil +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *SyncFailureMutation) CreatedAt() (r int64, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldCreatedAt(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// AddCreatedAt adds i to the "created_at" field. +func (m *SyncFailureMutation) AddCreatedAt(i int64) { + if m.addcreated_at != nil { + *m.addcreated_at += i + } else { + m.addcreated_at = &i + } +} + +// AddedCreatedAt returns the value that was added to the "created_at" field in this mutation. +func (m *SyncFailureMutation) AddedCreatedAt() (r int64, exists bool) { + v := m.addcreated_at + if v == nil { + return + } + return *v, true +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *SyncFailureMutation) ResetCreatedAt() { + m.created_at = nil + m.addcreated_at = nil +} + +// SetLastErrorAt sets the "last_error_at" field. +func (m *SyncFailureMutation) SetLastErrorAt(i int64) { + m.last_error_at = &i + m.addlast_error_at = nil +} + +// LastErrorAt returns the value of the "last_error_at" field in the mutation. +func (m *SyncFailureMutation) LastErrorAt() (r int64, exists bool) { + v := m.last_error_at + if v == nil { + return + } + return *v, true +} + +// OldLastErrorAt returns the old "last_error_at" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldLastErrorAt(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldLastErrorAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldLastErrorAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldLastErrorAt: %w", err) + } + return oldValue.LastErrorAt, nil +} + +// AddLastErrorAt adds i to the "last_error_at" field. +func (m *SyncFailureMutation) AddLastErrorAt(i int64) { + if m.addlast_error_at != nil { + *m.addlast_error_at += i + } else { + m.addlast_error_at = &i + } +} + +// AddedLastErrorAt returns the value that was added to the "last_error_at" field in this mutation. +func (m *SyncFailureMutation) AddedLastErrorAt() (r int64, exists bool) { + v := m.addlast_error_at + if v == nil { + return + } + return *v, true +} + +// ResetLastErrorAt resets all changes to the "last_error_at" field. +func (m *SyncFailureMutation) ResetLastErrorAt() { + m.last_error_at = nil + m.addlast_error_at = nil +} + +// SetHandledBy sets the "handled_by" field. +func (m *SyncFailureMutation) SetHandledBy(s string) { + m.handled_by = &s +} + +// HandledBy returns the value of the "handled_by" field in the mutation. +func (m *SyncFailureMutation) HandledBy() (r string, exists bool) { + v := m.handled_by + if v == nil { + return + } + return *v, true +} + +// OldHandledBy returns the old "handled_by" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldHandledBy(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldHandledBy is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldHandledBy requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldHandledBy: %w", err) + } + return oldValue.HandledBy, nil +} + +// ResetHandledBy resets all changes to the "handled_by" field. +func (m *SyncFailureMutation) ResetHandledBy() { + m.handled_by = nil +} + +// Where appends a list predicates to the SyncFailureMutation builder. +func (m *SyncFailureMutation) Where(ps ...predicate.SyncFailure) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the SyncFailureMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *SyncFailureMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.SyncFailure, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *SyncFailureMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *SyncFailureMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (SyncFailure). +func (m *SyncFailureMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *SyncFailureMutation) Fields() []string { + fields := make([]string, 0, 12) + if m.direction != nil { + fields = append(fields, syncfailure.FieldDirection) + } + if m.biz_type != nil { + fields = append(fields, syncfailure.FieldBizType) + } + if m.biz_key != nil { + fields = append(fields, syncfailure.FieldBizKey) + } + if m.endpoint != nil { + fields = append(fields, syncfailure.FieldEndpoint) + } + if m.payload_json != nil { + fields = append(fields, syncfailure.FieldPayloadJSON) + } + if m.error_msg != nil { + fields = append(fields, syncfailure.FieldErrorMsg) + } + if m.idempotency_key != nil { + fields = append(fields, syncfailure.FieldIdempotencyKey) + } + if m.status != nil { + fields = append(fields, syncfailure.FieldStatus) + } + if m.retry_count != nil { + fields = append(fields, syncfailure.FieldRetryCount) + } + if m.created_at != nil { + fields = append(fields, syncfailure.FieldCreatedAt) + } + if m.last_error_at != nil { + fields = append(fields, syncfailure.FieldLastErrorAt) + } + if m.handled_by != nil { + fields = append(fields, syncfailure.FieldHandledBy) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *SyncFailureMutation) Field(name string) (ent.Value, bool) { + switch name { + case syncfailure.FieldDirection: + return m.Direction() + case syncfailure.FieldBizType: + return m.BizType() + case syncfailure.FieldBizKey: + return m.BizKey() + case syncfailure.FieldEndpoint: + return m.Endpoint() + case syncfailure.FieldPayloadJSON: + return m.PayloadJSON() + case syncfailure.FieldErrorMsg: + return m.ErrorMsg() + case syncfailure.FieldIdempotencyKey: + return m.IdempotencyKey() + case syncfailure.FieldStatus: + return m.Status() + case syncfailure.FieldRetryCount: + return m.RetryCount() + case syncfailure.FieldCreatedAt: + return m.CreatedAt() + case syncfailure.FieldLastErrorAt: + return m.LastErrorAt() + case syncfailure.FieldHandledBy: + return m.HandledBy() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *SyncFailureMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case syncfailure.FieldDirection: + return m.OldDirection(ctx) + case syncfailure.FieldBizType: + return m.OldBizType(ctx) + case syncfailure.FieldBizKey: + return m.OldBizKey(ctx) + case syncfailure.FieldEndpoint: + return m.OldEndpoint(ctx) + case syncfailure.FieldPayloadJSON: + return m.OldPayloadJSON(ctx) + case syncfailure.FieldErrorMsg: + return m.OldErrorMsg(ctx) + case syncfailure.FieldIdempotencyKey: + return m.OldIdempotencyKey(ctx) + case syncfailure.FieldStatus: + return m.OldStatus(ctx) + case syncfailure.FieldRetryCount: + return m.OldRetryCount(ctx) + case syncfailure.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case syncfailure.FieldLastErrorAt: + return m.OldLastErrorAt(ctx) + case syncfailure.FieldHandledBy: + return m.OldHandledBy(ctx) + } + return nil, fmt.Errorf("unknown SyncFailure field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *SyncFailureMutation) SetField(name string, value ent.Value) error { + switch name { + case syncfailure.FieldDirection: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDirection(v) + return nil + case syncfailure.FieldBizType: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetBizType(v) + return nil + case syncfailure.FieldBizKey: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetBizKey(v) + return nil + case syncfailure.FieldEndpoint: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetEndpoint(v) + return nil + case syncfailure.FieldPayloadJSON: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPayloadJSON(v) + return nil + case syncfailure.FieldErrorMsg: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetErrorMsg(v) + return nil + case syncfailure.FieldIdempotencyKey: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetIdempotencyKey(v) + return nil + case syncfailure.FieldStatus: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStatus(v) + return nil + case syncfailure.FieldRetryCount: + v, ok := value.(int32) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRetryCount(v) + return nil + case syncfailure.FieldCreatedAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case syncfailure.FieldLastErrorAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetLastErrorAt(v) + return nil + case syncfailure.FieldHandledBy: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetHandledBy(v) + return nil + } + return fmt.Errorf("unknown SyncFailure field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *SyncFailureMutation) AddedFields() []string { + var fields []string + if m.addretry_count != nil { + fields = append(fields, syncfailure.FieldRetryCount) + } + if m.addcreated_at != nil { + fields = append(fields, syncfailure.FieldCreatedAt) + } + if m.addlast_error_at != nil { + fields = append(fields, syncfailure.FieldLastErrorAt) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *SyncFailureMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case syncfailure.FieldRetryCount: + return m.AddedRetryCount() + case syncfailure.FieldCreatedAt: + return m.AddedCreatedAt() + case syncfailure.FieldLastErrorAt: + return m.AddedLastErrorAt() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *SyncFailureMutation) AddField(name string, value ent.Value) error { + switch name { + case syncfailure.FieldRetryCount: + v, ok := value.(int32) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddRetryCount(v) + return nil + case syncfailure.FieldCreatedAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddCreatedAt(v) + return nil + case syncfailure.FieldLastErrorAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddLastErrorAt(v) + return nil + } + return fmt.Errorf("unknown SyncFailure numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *SyncFailureMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *SyncFailureMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *SyncFailureMutation) ClearField(name string) error { + return fmt.Errorf("unknown SyncFailure nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *SyncFailureMutation) ResetField(name string) error { + switch name { + case syncfailure.FieldDirection: + m.ResetDirection() + return nil + case syncfailure.FieldBizType: + m.ResetBizType() + return nil + case syncfailure.FieldBizKey: + m.ResetBizKey() + return nil + case syncfailure.FieldEndpoint: + m.ResetEndpoint() + return nil + case syncfailure.FieldPayloadJSON: + m.ResetPayloadJSON() + return nil + case syncfailure.FieldErrorMsg: + m.ResetErrorMsg() + return nil + case syncfailure.FieldIdempotencyKey: + m.ResetIdempotencyKey() + return nil + case syncfailure.FieldStatus: + m.ResetStatus() + return nil + case syncfailure.FieldRetryCount: + m.ResetRetryCount() + return nil + case syncfailure.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case syncfailure.FieldLastErrorAt: + m.ResetLastErrorAt() + return nil + case syncfailure.FieldHandledBy: + m.ResetHandledBy() + return nil + } + return fmt.Errorf("unknown SyncFailure field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *SyncFailureMutation) AddedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *SyncFailureMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *SyncFailureMutation) RemovedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *SyncFailureMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *SyncFailureMutation) ClearedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *SyncFailureMutation) EdgeCleared(name string) bool { + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *SyncFailureMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown SyncFailure unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *SyncFailureMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown SyncFailure edge %s", name) +} + // SysConfigMutation represents an operation that mutates the SysConfig nodes in the graph. type SysConfigMutation struct { config diff --git a/bj_power_mes/ent/predicate/predicate.go b/bj_power_mes/ent/predicate/predicate.go index 79aeebd..fd12d79 100644 --- a/bj_power_mes/ent/predicate/predicate.go +++ b/bj_power_mes/ent/predicate/predicate.go @@ -108,6 +108,9 @@ type StepData func(*sql.Selector) // StepSignRecord is the predicate function for stepsignrecord builders. type StepSignRecord func(*sql.Selector) +// SyncFailure is the predicate function for syncfailure builders. +type SyncFailure func(*sql.Selector) + // SysConfig is the predicate function for sysconfig builders. type SysConfig func(*sql.Selector) diff --git a/bj_power_mes/ent/runtime.go b/bj_power_mes/ent/runtime.go index 67ad4c6..75e8be9 100644 --- a/bj_power_mes/ent/runtime.go +++ b/bj_power_mes/ent/runtime.go @@ -37,6 +37,7 @@ import ( "bj_power_mes/ent/stepcriterion" "bj_power_mes/ent/stepdata" "bj_power_mes/ent/stepsignrecord" + "bj_power_mes/ent/syncfailure" "bj_power_mes/ent/sysconfig" "bj_power_mes/ent/torquerecord" "bj_power_mes/ent/user" @@ -1990,6 +1991,56 @@ func init() { stepsignrecordDescID := stepsignrecordFields[0].Descriptor() // stepsignrecord.IDValidator is a validator for the "id" field. It is called by the builders before save. stepsignrecord.IDValidator = stepsignrecordDescID.Validators[0].(func(int) error) + syncfailureFields := schema.SyncFailure{}.Fields() + _ = syncfailureFields + // syncfailureDescDirection is the schema descriptor for direction field. + syncfailureDescDirection := syncfailureFields[1].Descriptor() + // syncfailure.DefaultDirection holds the default value on creation for the direction field. + syncfailure.DefaultDirection = syncfailureDescDirection.Default.(string) + // syncfailureDescBizType is the schema descriptor for biz_type field. + syncfailureDescBizType := syncfailureFields[2].Descriptor() + // syncfailure.DefaultBizType holds the default value on creation for the biz_type field. + syncfailure.DefaultBizType = syncfailureDescBizType.Default.(string) + // syncfailureDescBizKey is the schema descriptor for biz_key field. + syncfailureDescBizKey := syncfailureFields[3].Descriptor() + // syncfailure.DefaultBizKey holds the default value on creation for the biz_key field. + syncfailure.DefaultBizKey = syncfailureDescBizKey.Default.(string) + // syncfailureDescEndpoint is the schema descriptor for endpoint field. + syncfailureDescEndpoint := syncfailureFields[4].Descriptor() + // syncfailure.DefaultEndpoint holds the default value on creation for the endpoint field. + syncfailure.DefaultEndpoint = syncfailureDescEndpoint.Default.(string) + // syncfailureDescPayloadJSON is the schema descriptor for payload_json field. + syncfailureDescPayloadJSON := syncfailureFields[5].Descriptor() + // syncfailure.DefaultPayloadJSON holds the default value on creation for the payload_json field. + syncfailure.DefaultPayloadJSON = syncfailureDescPayloadJSON.Default.(string) + // syncfailureDescErrorMsg is the schema descriptor for error_msg field. + syncfailureDescErrorMsg := syncfailureFields[6].Descriptor() + // syncfailure.DefaultErrorMsg holds the default value on creation for the error_msg field. + syncfailure.DefaultErrorMsg = syncfailureDescErrorMsg.Default.(string) + // syncfailureDescStatus is the schema descriptor for status field. + syncfailureDescStatus := syncfailureFields[8].Descriptor() + // syncfailure.DefaultStatus holds the default value on creation for the status field. + syncfailure.DefaultStatus = syncfailureDescStatus.Default.(string) + // syncfailureDescRetryCount is the schema descriptor for retry_count field. + syncfailureDescRetryCount := syncfailureFields[9].Descriptor() + // syncfailure.DefaultRetryCount holds the default value on creation for the retry_count field. + syncfailure.DefaultRetryCount = syncfailureDescRetryCount.Default.(int32) + // syncfailureDescCreatedAt is the schema descriptor for created_at field. + syncfailureDescCreatedAt := syncfailureFields[10].Descriptor() + // syncfailure.DefaultCreatedAt holds the default value on creation for the created_at field. + syncfailure.DefaultCreatedAt = syncfailureDescCreatedAt.Default.(int64) + // syncfailureDescLastErrorAt is the schema descriptor for last_error_at field. + syncfailureDescLastErrorAt := syncfailureFields[11].Descriptor() + // syncfailure.DefaultLastErrorAt holds the default value on creation for the last_error_at field. + syncfailure.DefaultLastErrorAt = syncfailureDescLastErrorAt.Default.(int64) + // syncfailureDescHandledBy is the schema descriptor for handled_by field. + syncfailureDescHandledBy := syncfailureFields[12].Descriptor() + // syncfailure.DefaultHandledBy holds the default value on creation for the handled_by field. + syncfailure.DefaultHandledBy = syncfailureDescHandledBy.Default.(string) + // syncfailureDescID is the schema descriptor for id field. + syncfailureDescID := syncfailureFields[0].Descriptor() + // syncfailure.IDValidator is a validator for the "id" field. It is called by the builders before save. + syncfailure.IDValidator = syncfailureDescID.Validators[0].(func(int) error) sysconfigFields := schema.SysConfig{}.Fields() _ = sysconfigFields // sysconfigDescKey is the schema descriptor for key field. diff --git a/bj_power_mes/ent/syncfailure.go b/bj_power_mes/ent/syncfailure.go new file mode 100644 index 0000000..ce18095 --- /dev/null +++ b/bj_power_mes/ent/syncfailure.go @@ -0,0 +1,224 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/syncfailure" + "fmt" + "strings" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" +) + +// SyncFailure 跨系统调用失败台账:本地已提交、对端通知失败,人工确认后重试 +type SyncFailure struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // 调用方向,如 mes>wms / wms>mes + Direction string `json:"direction,omitempty"` + // 业务类型,如 material.sync + BizType string `json:"biz_type,omitempty"` + // 业务主键 + BizKey string `json:"biz_key,omitempty"` + // 重试时原样重放的对端地址 + Endpoint string `json:"endpoint,omitempty"` + // 通知载荷(JSON) + PayloadJSON string `json:"payload_json,omitempty"` + // 失败原因 + ErrorMsg string `json:"error_msg,omitempty"` + // 幂等键 direction|biz_type|biz_key + IdempotencyKey string `json:"idempotency_key,omitempty"` + // PENDING/SUCCESS/DEAD + Status string `json:"status,omitempty"` + // 重试次数 + RetryCount int32 `json:"retry_count,omitempty"` + // 首次失败时刻(unix秒) + CreatedAt int64 `json:"created_at,omitempty"` + // 最近失败时刻(unix秒) + LastErrorAt int64 `json:"last_error_at,omitempty"` + // 人工置 DEAD 的操作人 + HandledBy string `json:"handled_by,omitempty"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*SyncFailure) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case syncfailure.FieldID, syncfailure.FieldRetryCount, syncfailure.FieldCreatedAt, syncfailure.FieldLastErrorAt: + values[i] = new(sql.NullInt64) + case syncfailure.FieldDirection, syncfailure.FieldBizType, syncfailure.FieldBizKey, syncfailure.FieldEndpoint, syncfailure.FieldPayloadJSON, syncfailure.FieldErrorMsg, syncfailure.FieldIdempotencyKey, syncfailure.FieldStatus, syncfailure.FieldHandledBy: + 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 SyncFailure fields. +func (_m *SyncFailure) 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 syncfailure.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + _m.ID = int(value.Int64) + case syncfailure.FieldDirection: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field direction", values[i]) + } else if value.Valid { + _m.Direction = value.String + } + case syncfailure.FieldBizType: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field biz_type", values[i]) + } else if value.Valid { + _m.BizType = value.String + } + case syncfailure.FieldBizKey: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field biz_key", values[i]) + } else if value.Valid { + _m.BizKey = value.String + } + case syncfailure.FieldEndpoint: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field endpoint", values[i]) + } else if value.Valid { + _m.Endpoint = value.String + } + case syncfailure.FieldPayloadJSON: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field payload_json", values[i]) + } else if value.Valid { + _m.PayloadJSON = value.String + } + case syncfailure.FieldErrorMsg: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field error_msg", values[i]) + } else if value.Valid { + _m.ErrorMsg = value.String + } + case syncfailure.FieldIdempotencyKey: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field idempotency_key", values[i]) + } else if value.Valid { + _m.IdempotencyKey = value.String + } + case syncfailure.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 = value.String + } + case syncfailure.FieldRetryCount: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field retry_count", values[i]) + } else if value.Valid { + _m.RetryCount = int32(value.Int64) + } + case syncfailure.FieldCreatedAt: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + _m.CreatedAt = value.Int64 + } + case syncfailure.FieldLastErrorAt: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field last_error_at", values[i]) + } else if value.Valid { + _m.LastErrorAt = value.Int64 + } + case syncfailure.FieldHandledBy: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field handled_by", values[i]) + } else if value.Valid { + _m.HandledBy = 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 SyncFailure. +// This includes values selected through modifiers, order, etc. +func (_m *SyncFailure) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// Update returns a builder for updating this SyncFailure. +// Note that you need to call SyncFailure.Unwrap() before calling this method if this SyncFailure +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *SyncFailure) Update() *SyncFailureUpdateOne { + return NewSyncFailureClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the SyncFailure 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 *SyncFailure) Unwrap() *SyncFailure { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: SyncFailure is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *SyncFailure) String() string { + var builder strings.Builder + builder.WriteString("SyncFailure(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("direction=") + builder.WriteString(_m.Direction) + builder.WriteString(", ") + builder.WriteString("biz_type=") + builder.WriteString(_m.BizType) + builder.WriteString(", ") + builder.WriteString("biz_key=") + builder.WriteString(_m.BizKey) + builder.WriteString(", ") + builder.WriteString("endpoint=") + builder.WriteString(_m.Endpoint) + builder.WriteString(", ") + builder.WriteString("payload_json=") + builder.WriteString(_m.PayloadJSON) + builder.WriteString(", ") + builder.WriteString("error_msg=") + builder.WriteString(_m.ErrorMsg) + builder.WriteString(", ") + builder.WriteString("idempotency_key=") + builder.WriteString(_m.IdempotencyKey) + builder.WriteString(", ") + builder.WriteString("status=") + builder.WriteString(_m.Status) + builder.WriteString(", ") + builder.WriteString("retry_count=") + builder.WriteString(fmt.Sprintf("%v", _m.RetryCount)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(fmt.Sprintf("%v", _m.CreatedAt)) + builder.WriteString(", ") + builder.WriteString("last_error_at=") + builder.WriteString(fmt.Sprintf("%v", _m.LastErrorAt)) + builder.WriteString(", ") + builder.WriteString("handled_by=") + builder.WriteString(_m.HandledBy) + builder.WriteByte(')') + return builder.String() +} + +// SyncFailures is a parsable slice of SyncFailure. +type SyncFailures []*SyncFailure diff --git a/bj_power_mes/ent/syncfailure/syncfailure.go b/bj_power_mes/ent/syncfailure/syncfailure.go new file mode 100644 index 0000000..3dd02a5 --- /dev/null +++ b/bj_power_mes/ent/syncfailure/syncfailure.go @@ -0,0 +1,162 @@ +// Code generated by ent, DO NOT EDIT. + +package syncfailure + +import ( + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the syncfailure type in the database. + Label = "sync_failure" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldDirection holds the string denoting the direction field in the database. + FieldDirection = "direction" + // FieldBizType holds the string denoting the biz_type field in the database. + FieldBizType = "biz_type" + // FieldBizKey holds the string denoting the biz_key field in the database. + FieldBizKey = "biz_key" + // FieldEndpoint holds the string denoting the endpoint field in the database. + FieldEndpoint = "endpoint" + // FieldPayloadJSON holds the string denoting the payload_json field in the database. + FieldPayloadJSON = "payload_json" + // FieldErrorMsg holds the string denoting the error_msg field in the database. + FieldErrorMsg = "error_msg" + // FieldIdempotencyKey holds the string denoting the idempotency_key field in the database. + FieldIdempotencyKey = "idempotency_key" + // FieldStatus holds the string denoting the status field in the database. + FieldStatus = "status" + // FieldRetryCount holds the string denoting the retry_count field in the database. + FieldRetryCount = "retry_count" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldLastErrorAt holds the string denoting the last_error_at field in the database. + FieldLastErrorAt = "last_error_at" + // FieldHandledBy holds the string denoting the handled_by field in the database. + FieldHandledBy = "handled_by" + // Table holds the table name of the syncfailure in the database. + Table = "sync_failure" +) + +// Columns holds all SQL columns for syncfailure fields. +var Columns = []string{ + FieldID, + FieldDirection, + FieldBizType, + FieldBizKey, + FieldEndpoint, + FieldPayloadJSON, + FieldErrorMsg, + FieldIdempotencyKey, + FieldStatus, + FieldRetryCount, + FieldCreatedAt, + FieldLastErrorAt, + FieldHandledBy, +} + +// 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 +} + +var ( + // DefaultDirection holds the default value on creation for the "direction" field. + DefaultDirection string + // DefaultBizType holds the default value on creation for the "biz_type" field. + DefaultBizType string + // DefaultBizKey holds the default value on creation for the "biz_key" field. + DefaultBizKey string + // DefaultEndpoint holds the default value on creation for the "endpoint" field. + DefaultEndpoint string + // DefaultPayloadJSON holds the default value on creation for the "payload_json" field. + DefaultPayloadJSON string + // DefaultErrorMsg holds the default value on creation for the "error_msg" field. + DefaultErrorMsg string + // DefaultStatus holds the default value on creation for the "status" field. + DefaultStatus string + // DefaultRetryCount holds the default value on creation for the "retry_count" field. + DefaultRetryCount int32 + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt int64 + // DefaultLastErrorAt holds the default value on creation for the "last_error_at" field. + DefaultLastErrorAt int64 + // DefaultHandledBy holds the default value on creation for the "handled_by" field. + DefaultHandledBy string + // IDValidator is a validator for the "id" field. It is called by the builders before save. + IDValidator func(int) error +) + +// OrderOption defines the ordering options for the SyncFailure 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() +} + +// ByDirection orders the results by the direction field. +func ByDirection(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDirection, opts...).ToFunc() +} + +// ByBizType orders the results by the biz_type field. +func ByBizType(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldBizType, opts...).ToFunc() +} + +// ByBizKey orders the results by the biz_key field. +func ByBizKey(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldBizKey, opts...).ToFunc() +} + +// ByEndpoint orders the results by the endpoint field. +func ByEndpoint(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldEndpoint, opts...).ToFunc() +} + +// ByPayloadJSON orders the results by the payload_json field. +func ByPayloadJSON(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPayloadJSON, opts...).ToFunc() +} + +// ByErrorMsg orders the results by the error_msg field. +func ByErrorMsg(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldErrorMsg, opts...).ToFunc() +} + +// ByIdempotencyKey orders the results by the idempotency_key field. +func ByIdempotencyKey(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIdempotencyKey, opts...).ToFunc() +} + +// ByStatus orders the results by the status field. +func ByStatus(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStatus, opts...).ToFunc() +} + +// ByRetryCount orders the results by the retry_count field. +func ByRetryCount(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRetryCount, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByLastErrorAt orders the results by the last_error_at field. +func ByLastErrorAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldLastErrorAt, opts...).ToFunc() +} + +// ByHandledBy orders the results by the handled_by field. +func ByHandledBy(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldHandledBy, opts...).ToFunc() +} diff --git a/bj_power_mes/ent/syncfailure/where.go b/bj_power_mes/ent/syncfailure/where.go new file mode 100644 index 0000000..b9cd283 --- /dev/null +++ b/bj_power_mes/ent/syncfailure/where.go @@ -0,0 +1,834 @@ +// Code generated by ent, DO NOT EDIT. + +package syncfailure + +import ( + "bj_power_mes/ent/predicate" + + "entgo.io/ent/dialect/sql" +) + +// ID filters vertices based on their ID field. +func ID(id int) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldID, id)) +} + +// Direction applies equality check predicate on the "direction" field. It's identical to DirectionEQ. +func Direction(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldDirection, v)) +} + +// BizType applies equality check predicate on the "biz_type" field. It's identical to BizTypeEQ. +func BizType(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldBizType, v)) +} + +// BizKey applies equality check predicate on the "biz_key" field. It's identical to BizKeyEQ. +func BizKey(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldBizKey, v)) +} + +// Endpoint applies equality check predicate on the "endpoint" field. It's identical to EndpointEQ. +func Endpoint(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldEndpoint, v)) +} + +// PayloadJSON applies equality check predicate on the "payload_json" field. It's identical to PayloadJSONEQ. +func PayloadJSON(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldPayloadJSON, v)) +} + +// ErrorMsg applies equality check predicate on the "error_msg" field. It's identical to ErrorMsgEQ. +func ErrorMsg(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldErrorMsg, v)) +} + +// IdempotencyKey applies equality check predicate on the "idempotency_key" field. It's identical to IdempotencyKeyEQ. +func IdempotencyKey(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldIdempotencyKey, v)) +} + +// Status applies equality check predicate on the "status" field. It's identical to StatusEQ. +func Status(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldStatus, v)) +} + +// RetryCount applies equality check predicate on the "retry_count" field. It's identical to RetryCountEQ. +func RetryCount(v int32) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldRetryCount, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldCreatedAt, v)) +} + +// LastErrorAt applies equality check predicate on the "last_error_at" field. It's identical to LastErrorAtEQ. +func LastErrorAt(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldLastErrorAt, v)) +} + +// HandledBy applies equality check predicate on the "handled_by" field. It's identical to HandledByEQ. +func HandledBy(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldHandledBy, v)) +} + +// DirectionEQ applies the EQ predicate on the "direction" field. +func DirectionEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldDirection, v)) +} + +// DirectionNEQ applies the NEQ predicate on the "direction" field. +func DirectionNEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldDirection, v)) +} + +// DirectionIn applies the In predicate on the "direction" field. +func DirectionIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldDirection, vs...)) +} + +// DirectionNotIn applies the NotIn predicate on the "direction" field. +func DirectionNotIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldDirection, vs...)) +} + +// DirectionGT applies the GT predicate on the "direction" field. +func DirectionGT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldDirection, v)) +} + +// DirectionGTE applies the GTE predicate on the "direction" field. +func DirectionGTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldDirection, v)) +} + +// DirectionLT applies the LT predicate on the "direction" field. +func DirectionLT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldDirection, v)) +} + +// DirectionLTE applies the LTE predicate on the "direction" field. +func DirectionLTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldDirection, v)) +} + +// DirectionContains applies the Contains predicate on the "direction" field. +func DirectionContains(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContains(FieldDirection, v)) +} + +// DirectionHasPrefix applies the HasPrefix predicate on the "direction" field. +func DirectionHasPrefix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasPrefix(FieldDirection, v)) +} + +// DirectionHasSuffix applies the HasSuffix predicate on the "direction" field. +func DirectionHasSuffix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasSuffix(FieldDirection, v)) +} + +// DirectionEqualFold applies the EqualFold predicate on the "direction" field. +func DirectionEqualFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEqualFold(FieldDirection, v)) +} + +// DirectionContainsFold applies the ContainsFold predicate on the "direction" field. +func DirectionContainsFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContainsFold(FieldDirection, v)) +} + +// BizTypeEQ applies the EQ predicate on the "biz_type" field. +func BizTypeEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldBizType, v)) +} + +// BizTypeNEQ applies the NEQ predicate on the "biz_type" field. +func BizTypeNEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldBizType, v)) +} + +// BizTypeIn applies the In predicate on the "biz_type" field. +func BizTypeIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldBizType, vs...)) +} + +// BizTypeNotIn applies the NotIn predicate on the "biz_type" field. +func BizTypeNotIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldBizType, vs...)) +} + +// BizTypeGT applies the GT predicate on the "biz_type" field. +func BizTypeGT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldBizType, v)) +} + +// BizTypeGTE applies the GTE predicate on the "biz_type" field. +func BizTypeGTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldBizType, v)) +} + +// BizTypeLT applies the LT predicate on the "biz_type" field. +func BizTypeLT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldBizType, v)) +} + +// BizTypeLTE applies the LTE predicate on the "biz_type" field. +func BizTypeLTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldBizType, v)) +} + +// BizTypeContains applies the Contains predicate on the "biz_type" field. +func BizTypeContains(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContains(FieldBizType, v)) +} + +// BizTypeHasPrefix applies the HasPrefix predicate on the "biz_type" field. +func BizTypeHasPrefix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasPrefix(FieldBizType, v)) +} + +// BizTypeHasSuffix applies the HasSuffix predicate on the "biz_type" field. +func BizTypeHasSuffix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasSuffix(FieldBizType, v)) +} + +// BizTypeEqualFold applies the EqualFold predicate on the "biz_type" field. +func BizTypeEqualFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEqualFold(FieldBizType, v)) +} + +// BizTypeContainsFold applies the ContainsFold predicate on the "biz_type" field. +func BizTypeContainsFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContainsFold(FieldBizType, v)) +} + +// BizKeyEQ applies the EQ predicate on the "biz_key" field. +func BizKeyEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldBizKey, v)) +} + +// BizKeyNEQ applies the NEQ predicate on the "biz_key" field. +func BizKeyNEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldBizKey, v)) +} + +// BizKeyIn applies the In predicate on the "biz_key" field. +func BizKeyIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldBizKey, vs...)) +} + +// BizKeyNotIn applies the NotIn predicate on the "biz_key" field. +func BizKeyNotIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldBizKey, vs...)) +} + +// BizKeyGT applies the GT predicate on the "biz_key" field. +func BizKeyGT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldBizKey, v)) +} + +// BizKeyGTE applies the GTE predicate on the "biz_key" field. +func BizKeyGTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldBizKey, v)) +} + +// BizKeyLT applies the LT predicate on the "biz_key" field. +func BizKeyLT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldBizKey, v)) +} + +// BizKeyLTE applies the LTE predicate on the "biz_key" field. +func BizKeyLTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldBizKey, v)) +} + +// BizKeyContains applies the Contains predicate on the "biz_key" field. +func BizKeyContains(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContains(FieldBizKey, v)) +} + +// BizKeyHasPrefix applies the HasPrefix predicate on the "biz_key" field. +func BizKeyHasPrefix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasPrefix(FieldBizKey, v)) +} + +// BizKeyHasSuffix applies the HasSuffix predicate on the "biz_key" field. +func BizKeyHasSuffix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasSuffix(FieldBizKey, v)) +} + +// BizKeyEqualFold applies the EqualFold predicate on the "biz_key" field. +func BizKeyEqualFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEqualFold(FieldBizKey, v)) +} + +// BizKeyContainsFold applies the ContainsFold predicate on the "biz_key" field. +func BizKeyContainsFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContainsFold(FieldBizKey, v)) +} + +// EndpointEQ applies the EQ predicate on the "endpoint" field. +func EndpointEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldEndpoint, v)) +} + +// EndpointNEQ applies the NEQ predicate on the "endpoint" field. +func EndpointNEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldEndpoint, v)) +} + +// EndpointIn applies the In predicate on the "endpoint" field. +func EndpointIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldEndpoint, vs...)) +} + +// EndpointNotIn applies the NotIn predicate on the "endpoint" field. +func EndpointNotIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldEndpoint, vs...)) +} + +// EndpointGT applies the GT predicate on the "endpoint" field. +func EndpointGT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldEndpoint, v)) +} + +// EndpointGTE applies the GTE predicate on the "endpoint" field. +func EndpointGTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldEndpoint, v)) +} + +// EndpointLT applies the LT predicate on the "endpoint" field. +func EndpointLT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldEndpoint, v)) +} + +// EndpointLTE applies the LTE predicate on the "endpoint" field. +func EndpointLTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldEndpoint, v)) +} + +// EndpointContains applies the Contains predicate on the "endpoint" field. +func EndpointContains(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContains(FieldEndpoint, v)) +} + +// EndpointHasPrefix applies the HasPrefix predicate on the "endpoint" field. +func EndpointHasPrefix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasPrefix(FieldEndpoint, v)) +} + +// EndpointHasSuffix applies the HasSuffix predicate on the "endpoint" field. +func EndpointHasSuffix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasSuffix(FieldEndpoint, v)) +} + +// EndpointEqualFold applies the EqualFold predicate on the "endpoint" field. +func EndpointEqualFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEqualFold(FieldEndpoint, v)) +} + +// EndpointContainsFold applies the ContainsFold predicate on the "endpoint" field. +func EndpointContainsFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContainsFold(FieldEndpoint, v)) +} + +// PayloadJSONEQ applies the EQ predicate on the "payload_json" field. +func PayloadJSONEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldPayloadJSON, v)) +} + +// PayloadJSONNEQ applies the NEQ predicate on the "payload_json" field. +func PayloadJSONNEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldPayloadJSON, v)) +} + +// PayloadJSONIn applies the In predicate on the "payload_json" field. +func PayloadJSONIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldPayloadJSON, vs...)) +} + +// PayloadJSONNotIn applies the NotIn predicate on the "payload_json" field. +func PayloadJSONNotIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldPayloadJSON, vs...)) +} + +// PayloadJSONGT applies the GT predicate on the "payload_json" field. +func PayloadJSONGT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldPayloadJSON, v)) +} + +// PayloadJSONGTE applies the GTE predicate on the "payload_json" field. +func PayloadJSONGTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldPayloadJSON, v)) +} + +// PayloadJSONLT applies the LT predicate on the "payload_json" field. +func PayloadJSONLT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldPayloadJSON, v)) +} + +// PayloadJSONLTE applies the LTE predicate on the "payload_json" field. +func PayloadJSONLTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldPayloadJSON, v)) +} + +// PayloadJSONContains applies the Contains predicate on the "payload_json" field. +func PayloadJSONContains(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContains(FieldPayloadJSON, v)) +} + +// PayloadJSONHasPrefix applies the HasPrefix predicate on the "payload_json" field. +func PayloadJSONHasPrefix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasPrefix(FieldPayloadJSON, v)) +} + +// PayloadJSONHasSuffix applies the HasSuffix predicate on the "payload_json" field. +func PayloadJSONHasSuffix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasSuffix(FieldPayloadJSON, v)) +} + +// PayloadJSONEqualFold applies the EqualFold predicate on the "payload_json" field. +func PayloadJSONEqualFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEqualFold(FieldPayloadJSON, v)) +} + +// PayloadJSONContainsFold applies the ContainsFold predicate on the "payload_json" field. +func PayloadJSONContainsFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContainsFold(FieldPayloadJSON, v)) +} + +// ErrorMsgEQ applies the EQ predicate on the "error_msg" field. +func ErrorMsgEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldErrorMsg, v)) +} + +// ErrorMsgNEQ applies the NEQ predicate on the "error_msg" field. +func ErrorMsgNEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldErrorMsg, v)) +} + +// ErrorMsgIn applies the In predicate on the "error_msg" field. +func ErrorMsgIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldErrorMsg, vs...)) +} + +// ErrorMsgNotIn applies the NotIn predicate on the "error_msg" field. +func ErrorMsgNotIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldErrorMsg, vs...)) +} + +// ErrorMsgGT applies the GT predicate on the "error_msg" field. +func ErrorMsgGT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldErrorMsg, v)) +} + +// ErrorMsgGTE applies the GTE predicate on the "error_msg" field. +func ErrorMsgGTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldErrorMsg, v)) +} + +// ErrorMsgLT applies the LT predicate on the "error_msg" field. +func ErrorMsgLT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldErrorMsg, v)) +} + +// ErrorMsgLTE applies the LTE predicate on the "error_msg" field. +func ErrorMsgLTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldErrorMsg, v)) +} + +// ErrorMsgContains applies the Contains predicate on the "error_msg" field. +func ErrorMsgContains(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContains(FieldErrorMsg, v)) +} + +// ErrorMsgHasPrefix applies the HasPrefix predicate on the "error_msg" field. +func ErrorMsgHasPrefix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasPrefix(FieldErrorMsg, v)) +} + +// ErrorMsgHasSuffix applies the HasSuffix predicate on the "error_msg" field. +func ErrorMsgHasSuffix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasSuffix(FieldErrorMsg, v)) +} + +// ErrorMsgEqualFold applies the EqualFold predicate on the "error_msg" field. +func ErrorMsgEqualFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEqualFold(FieldErrorMsg, v)) +} + +// ErrorMsgContainsFold applies the ContainsFold predicate on the "error_msg" field. +func ErrorMsgContainsFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContainsFold(FieldErrorMsg, v)) +} + +// IdempotencyKeyEQ applies the EQ predicate on the "idempotency_key" field. +func IdempotencyKeyEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyNEQ applies the NEQ predicate on the "idempotency_key" field. +func IdempotencyKeyNEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyIn applies the In predicate on the "idempotency_key" field. +func IdempotencyKeyIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldIdempotencyKey, vs...)) +} + +// IdempotencyKeyNotIn applies the NotIn predicate on the "idempotency_key" field. +func IdempotencyKeyNotIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldIdempotencyKey, vs...)) +} + +// IdempotencyKeyGT applies the GT predicate on the "idempotency_key" field. +func IdempotencyKeyGT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyGTE applies the GTE predicate on the "idempotency_key" field. +func IdempotencyKeyGTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyLT applies the LT predicate on the "idempotency_key" field. +func IdempotencyKeyLT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyLTE applies the LTE predicate on the "idempotency_key" field. +func IdempotencyKeyLTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyContains applies the Contains predicate on the "idempotency_key" field. +func IdempotencyKeyContains(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContains(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyHasPrefix applies the HasPrefix predicate on the "idempotency_key" field. +func IdempotencyKeyHasPrefix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasPrefix(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyHasSuffix applies the HasSuffix predicate on the "idempotency_key" field. +func IdempotencyKeyHasSuffix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasSuffix(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyEqualFold applies the EqualFold predicate on the "idempotency_key" field. +func IdempotencyKeyEqualFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEqualFold(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyContainsFold applies the ContainsFold predicate on the "idempotency_key" field. +func IdempotencyKeyContainsFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContainsFold(FieldIdempotencyKey, v)) +} + +// StatusEQ applies the EQ predicate on the "status" field. +func StatusEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldStatus, v)) +} + +// StatusNEQ applies the NEQ predicate on the "status" field. +func StatusNEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldStatus, v)) +} + +// StatusIn applies the In predicate on the "status" field. +func StatusIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldStatus, vs...)) +} + +// StatusNotIn applies the NotIn predicate on the "status" field. +func StatusNotIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldStatus, vs...)) +} + +// StatusGT applies the GT predicate on the "status" field. +func StatusGT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldStatus, v)) +} + +// StatusGTE applies the GTE predicate on the "status" field. +func StatusGTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldStatus, v)) +} + +// StatusLT applies the LT predicate on the "status" field. +func StatusLT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldStatus, v)) +} + +// StatusLTE applies the LTE predicate on the "status" field. +func StatusLTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldStatus, v)) +} + +// StatusContains applies the Contains predicate on the "status" field. +func StatusContains(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContains(FieldStatus, v)) +} + +// StatusHasPrefix applies the HasPrefix predicate on the "status" field. +func StatusHasPrefix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasPrefix(FieldStatus, v)) +} + +// StatusHasSuffix applies the HasSuffix predicate on the "status" field. +func StatusHasSuffix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasSuffix(FieldStatus, v)) +} + +// StatusEqualFold applies the EqualFold predicate on the "status" field. +func StatusEqualFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEqualFold(FieldStatus, v)) +} + +// StatusContainsFold applies the ContainsFold predicate on the "status" field. +func StatusContainsFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContainsFold(FieldStatus, v)) +} + +// RetryCountEQ applies the EQ predicate on the "retry_count" field. +func RetryCountEQ(v int32) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldRetryCount, v)) +} + +// RetryCountNEQ applies the NEQ predicate on the "retry_count" field. +func RetryCountNEQ(v int32) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldRetryCount, v)) +} + +// RetryCountIn applies the In predicate on the "retry_count" field. +func RetryCountIn(vs ...int32) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldRetryCount, vs...)) +} + +// RetryCountNotIn applies the NotIn predicate on the "retry_count" field. +func RetryCountNotIn(vs ...int32) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldRetryCount, vs...)) +} + +// RetryCountGT applies the GT predicate on the "retry_count" field. +func RetryCountGT(v int32) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldRetryCount, v)) +} + +// RetryCountGTE applies the GTE predicate on the "retry_count" field. +func RetryCountGTE(v int32) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldRetryCount, v)) +} + +// RetryCountLT applies the LT predicate on the "retry_count" field. +func RetryCountLT(v int32) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldRetryCount, v)) +} + +// RetryCountLTE applies the LTE predicate on the "retry_count" field. +func RetryCountLTE(v int32) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldRetryCount, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldCreatedAt, v)) +} + +// LastErrorAtEQ applies the EQ predicate on the "last_error_at" field. +func LastErrorAtEQ(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldLastErrorAt, v)) +} + +// LastErrorAtNEQ applies the NEQ predicate on the "last_error_at" field. +func LastErrorAtNEQ(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldLastErrorAt, v)) +} + +// LastErrorAtIn applies the In predicate on the "last_error_at" field. +func LastErrorAtIn(vs ...int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldLastErrorAt, vs...)) +} + +// LastErrorAtNotIn applies the NotIn predicate on the "last_error_at" field. +func LastErrorAtNotIn(vs ...int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldLastErrorAt, vs...)) +} + +// LastErrorAtGT applies the GT predicate on the "last_error_at" field. +func LastErrorAtGT(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldLastErrorAt, v)) +} + +// LastErrorAtGTE applies the GTE predicate on the "last_error_at" field. +func LastErrorAtGTE(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldLastErrorAt, v)) +} + +// LastErrorAtLT applies the LT predicate on the "last_error_at" field. +func LastErrorAtLT(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldLastErrorAt, v)) +} + +// LastErrorAtLTE applies the LTE predicate on the "last_error_at" field. +func LastErrorAtLTE(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldLastErrorAt, v)) +} + +// HandledByEQ applies the EQ predicate on the "handled_by" field. +func HandledByEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldHandledBy, v)) +} + +// HandledByNEQ applies the NEQ predicate on the "handled_by" field. +func HandledByNEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldHandledBy, v)) +} + +// HandledByIn applies the In predicate on the "handled_by" field. +func HandledByIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldHandledBy, vs...)) +} + +// HandledByNotIn applies the NotIn predicate on the "handled_by" field. +func HandledByNotIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldHandledBy, vs...)) +} + +// HandledByGT applies the GT predicate on the "handled_by" field. +func HandledByGT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldHandledBy, v)) +} + +// HandledByGTE applies the GTE predicate on the "handled_by" field. +func HandledByGTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldHandledBy, v)) +} + +// HandledByLT applies the LT predicate on the "handled_by" field. +func HandledByLT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldHandledBy, v)) +} + +// HandledByLTE applies the LTE predicate on the "handled_by" field. +func HandledByLTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldHandledBy, v)) +} + +// HandledByContains applies the Contains predicate on the "handled_by" field. +func HandledByContains(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContains(FieldHandledBy, v)) +} + +// HandledByHasPrefix applies the HasPrefix predicate on the "handled_by" field. +func HandledByHasPrefix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasPrefix(FieldHandledBy, v)) +} + +// HandledByHasSuffix applies the HasSuffix predicate on the "handled_by" field. +func HandledByHasSuffix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasSuffix(FieldHandledBy, v)) +} + +// HandledByEqualFold applies the EqualFold predicate on the "handled_by" field. +func HandledByEqualFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEqualFold(FieldHandledBy, v)) +} + +// HandledByContainsFold applies the ContainsFold predicate on the "handled_by" field. +func HandledByContainsFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContainsFold(FieldHandledBy, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.SyncFailure) predicate.SyncFailure { + return predicate.SyncFailure(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.SyncFailure) predicate.SyncFailure { + return predicate.SyncFailure(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.SyncFailure) predicate.SyncFailure { + return predicate.SyncFailure(sql.NotPredicates(p)) +} diff --git a/bj_power_mes/ent/syncfailure_create.go b/bj_power_mes/ent/syncfailure_create.go new file mode 100644 index 0000000..fc14c4c --- /dev/null +++ b/bj_power_mes/ent/syncfailure_create.go @@ -0,0 +1,481 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/syncfailure" + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// SyncFailureCreate is the builder for creating a SyncFailure entity. +type SyncFailureCreate struct { + config + mutation *SyncFailureMutation + hooks []Hook +} + +// SetDirection sets the "direction" field. +func (_c *SyncFailureCreate) SetDirection(v string) *SyncFailureCreate { + _c.mutation.SetDirection(v) + return _c +} + +// SetNillableDirection sets the "direction" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableDirection(v *string) *SyncFailureCreate { + if v != nil { + _c.SetDirection(*v) + } + return _c +} + +// SetBizType sets the "biz_type" field. +func (_c *SyncFailureCreate) SetBizType(v string) *SyncFailureCreate { + _c.mutation.SetBizType(v) + return _c +} + +// SetNillableBizType sets the "biz_type" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableBizType(v *string) *SyncFailureCreate { + if v != nil { + _c.SetBizType(*v) + } + return _c +} + +// SetBizKey sets the "biz_key" field. +func (_c *SyncFailureCreate) SetBizKey(v string) *SyncFailureCreate { + _c.mutation.SetBizKey(v) + return _c +} + +// SetNillableBizKey sets the "biz_key" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableBizKey(v *string) *SyncFailureCreate { + if v != nil { + _c.SetBizKey(*v) + } + return _c +} + +// SetEndpoint sets the "endpoint" field. +func (_c *SyncFailureCreate) SetEndpoint(v string) *SyncFailureCreate { + _c.mutation.SetEndpoint(v) + return _c +} + +// SetNillableEndpoint sets the "endpoint" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableEndpoint(v *string) *SyncFailureCreate { + if v != nil { + _c.SetEndpoint(*v) + } + return _c +} + +// SetPayloadJSON sets the "payload_json" field. +func (_c *SyncFailureCreate) SetPayloadJSON(v string) *SyncFailureCreate { + _c.mutation.SetPayloadJSON(v) + return _c +} + +// SetNillablePayloadJSON sets the "payload_json" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillablePayloadJSON(v *string) *SyncFailureCreate { + if v != nil { + _c.SetPayloadJSON(*v) + } + return _c +} + +// SetErrorMsg sets the "error_msg" field. +func (_c *SyncFailureCreate) SetErrorMsg(v string) *SyncFailureCreate { + _c.mutation.SetErrorMsg(v) + return _c +} + +// SetNillableErrorMsg sets the "error_msg" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableErrorMsg(v *string) *SyncFailureCreate { + if v != nil { + _c.SetErrorMsg(*v) + } + return _c +} + +// SetIdempotencyKey sets the "idempotency_key" field. +func (_c *SyncFailureCreate) SetIdempotencyKey(v string) *SyncFailureCreate { + _c.mutation.SetIdempotencyKey(v) + return _c +} + +// SetStatus sets the "status" field. +func (_c *SyncFailureCreate) SetStatus(v string) *SyncFailureCreate { + _c.mutation.SetStatus(v) + return _c +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableStatus(v *string) *SyncFailureCreate { + if v != nil { + _c.SetStatus(*v) + } + return _c +} + +// SetRetryCount sets the "retry_count" field. +func (_c *SyncFailureCreate) SetRetryCount(v int32) *SyncFailureCreate { + _c.mutation.SetRetryCount(v) + return _c +} + +// SetNillableRetryCount sets the "retry_count" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableRetryCount(v *int32) *SyncFailureCreate { + if v != nil { + _c.SetRetryCount(*v) + } + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *SyncFailureCreate) SetCreatedAt(v int64) *SyncFailureCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableCreatedAt(v *int64) *SyncFailureCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetLastErrorAt sets the "last_error_at" field. +func (_c *SyncFailureCreate) SetLastErrorAt(v int64) *SyncFailureCreate { + _c.mutation.SetLastErrorAt(v) + return _c +} + +// SetNillableLastErrorAt sets the "last_error_at" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableLastErrorAt(v *int64) *SyncFailureCreate { + if v != nil { + _c.SetLastErrorAt(*v) + } + return _c +} + +// SetHandledBy sets the "handled_by" field. +func (_c *SyncFailureCreate) SetHandledBy(v string) *SyncFailureCreate { + _c.mutation.SetHandledBy(v) + return _c +} + +// SetNillableHandledBy sets the "handled_by" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableHandledBy(v *string) *SyncFailureCreate { + if v != nil { + _c.SetHandledBy(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *SyncFailureCreate) SetID(v int) *SyncFailureCreate { + _c.mutation.SetID(v) + return _c +} + +// Mutation returns the SyncFailureMutation object of the builder. +func (_c *SyncFailureCreate) Mutation() *SyncFailureMutation { + return _c.mutation +} + +// Save creates the SyncFailure in the database. +func (_c *SyncFailureCreate) Save(ctx context.Context) (*SyncFailure, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *SyncFailureCreate) SaveX(ctx context.Context) *SyncFailure { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *SyncFailureCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *SyncFailureCreate) 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 *SyncFailureCreate) defaults() { + if _, ok := _c.mutation.Direction(); !ok { + v := syncfailure.DefaultDirection + _c.mutation.SetDirection(v) + } + if _, ok := _c.mutation.BizType(); !ok { + v := syncfailure.DefaultBizType + _c.mutation.SetBizType(v) + } + if _, ok := _c.mutation.BizKey(); !ok { + v := syncfailure.DefaultBizKey + _c.mutation.SetBizKey(v) + } + if _, ok := _c.mutation.Endpoint(); !ok { + v := syncfailure.DefaultEndpoint + _c.mutation.SetEndpoint(v) + } + if _, ok := _c.mutation.PayloadJSON(); !ok { + v := syncfailure.DefaultPayloadJSON + _c.mutation.SetPayloadJSON(v) + } + if _, ok := _c.mutation.ErrorMsg(); !ok { + v := syncfailure.DefaultErrorMsg + _c.mutation.SetErrorMsg(v) + } + if _, ok := _c.mutation.Status(); !ok { + v := syncfailure.DefaultStatus + _c.mutation.SetStatus(v) + } + if _, ok := _c.mutation.RetryCount(); !ok { + v := syncfailure.DefaultRetryCount + _c.mutation.SetRetryCount(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := syncfailure.DefaultCreatedAt + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.LastErrorAt(); !ok { + v := syncfailure.DefaultLastErrorAt + _c.mutation.SetLastErrorAt(v) + } + if _, ok := _c.mutation.HandledBy(); !ok { + v := syncfailure.DefaultHandledBy + _c.mutation.SetHandledBy(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *SyncFailureCreate) check() error { + if _, ok := _c.mutation.Direction(); !ok { + return &ValidationError{Name: "direction", err: errors.New(`ent: missing required field "SyncFailure.direction"`)} + } + if _, ok := _c.mutation.BizType(); !ok { + return &ValidationError{Name: "biz_type", err: errors.New(`ent: missing required field "SyncFailure.biz_type"`)} + } + if _, ok := _c.mutation.BizKey(); !ok { + return &ValidationError{Name: "biz_key", err: errors.New(`ent: missing required field "SyncFailure.biz_key"`)} + } + if _, ok := _c.mutation.Endpoint(); !ok { + return &ValidationError{Name: "endpoint", err: errors.New(`ent: missing required field "SyncFailure.endpoint"`)} + } + if _, ok := _c.mutation.PayloadJSON(); !ok { + return &ValidationError{Name: "payload_json", err: errors.New(`ent: missing required field "SyncFailure.payload_json"`)} + } + if _, ok := _c.mutation.ErrorMsg(); !ok { + return &ValidationError{Name: "error_msg", err: errors.New(`ent: missing required field "SyncFailure.error_msg"`)} + } + if _, ok := _c.mutation.IdempotencyKey(); !ok { + return &ValidationError{Name: "idempotency_key", err: errors.New(`ent: missing required field "SyncFailure.idempotency_key"`)} + } + if _, ok := _c.mutation.Status(); !ok { + return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "SyncFailure.status"`)} + } + if _, ok := _c.mutation.RetryCount(); !ok { + return &ValidationError{Name: "retry_count", err: errors.New(`ent: missing required field "SyncFailure.retry_count"`)} + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "SyncFailure.created_at"`)} + } + if _, ok := _c.mutation.LastErrorAt(); !ok { + return &ValidationError{Name: "last_error_at", err: errors.New(`ent: missing required field "SyncFailure.last_error_at"`)} + } + if _, ok := _c.mutation.HandledBy(); !ok { + return &ValidationError{Name: "handled_by", err: errors.New(`ent: missing required field "SyncFailure.handled_by"`)} + } + if v, ok := _c.mutation.ID(); ok { + if err := syncfailure.IDValidator(v); err != nil { + return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "SyncFailure.id": %w`, err)} + } + } + return nil +} + +func (_c *SyncFailureCreate) sqlSave(ctx context.Context) (*SyncFailure, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != _node.ID { + id := _spec.ID.Value.(int64) + _node.ID = int(id) + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *SyncFailureCreate) createSpec() (*SyncFailure, *sqlgraph.CreateSpec) { + var ( + _node = &SyncFailure{config: _c.config} + _spec = sqlgraph.NewCreateSpec(syncfailure.Table, sqlgraph.NewFieldSpec(syncfailure.FieldID, field.TypeInt)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } + if value, ok := _c.mutation.Direction(); ok { + _spec.SetField(syncfailure.FieldDirection, field.TypeString, value) + _node.Direction = value + } + if value, ok := _c.mutation.BizType(); ok { + _spec.SetField(syncfailure.FieldBizType, field.TypeString, value) + _node.BizType = value + } + if value, ok := _c.mutation.BizKey(); ok { + _spec.SetField(syncfailure.FieldBizKey, field.TypeString, value) + _node.BizKey = value + } + if value, ok := _c.mutation.Endpoint(); ok { + _spec.SetField(syncfailure.FieldEndpoint, field.TypeString, value) + _node.Endpoint = value + } + if value, ok := _c.mutation.PayloadJSON(); ok { + _spec.SetField(syncfailure.FieldPayloadJSON, field.TypeString, value) + _node.PayloadJSON = value + } + if value, ok := _c.mutation.ErrorMsg(); ok { + _spec.SetField(syncfailure.FieldErrorMsg, field.TypeString, value) + _node.ErrorMsg = value + } + if value, ok := _c.mutation.IdempotencyKey(); ok { + _spec.SetField(syncfailure.FieldIdempotencyKey, field.TypeString, value) + _node.IdempotencyKey = value + } + if value, ok := _c.mutation.Status(); ok { + _spec.SetField(syncfailure.FieldStatus, field.TypeString, value) + _node.Status = value + } + if value, ok := _c.mutation.RetryCount(); ok { + _spec.SetField(syncfailure.FieldRetryCount, field.TypeInt32, value) + _node.RetryCount = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(syncfailure.FieldCreatedAt, field.TypeInt64, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.LastErrorAt(); ok { + _spec.SetField(syncfailure.FieldLastErrorAt, field.TypeInt64, value) + _node.LastErrorAt = value + } + if value, ok := _c.mutation.HandledBy(); ok { + _spec.SetField(syncfailure.FieldHandledBy, field.TypeString, value) + _node.HandledBy = value + } + return _node, _spec +} + +// SyncFailureCreateBulk is the builder for creating many SyncFailure entities in bulk. +type SyncFailureCreateBulk struct { + config + err error + builders []*SyncFailureCreate +} + +// Save creates the SyncFailure entities in the database. +func (_c *SyncFailureCreateBulk) Save(ctx context.Context) ([]*SyncFailure, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*SyncFailure, 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.(*SyncFailureMutation) + 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} + // 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 && nodes[i].ID == 0 { + id := specs[i].ID.Value.(int64) + nodes[i].ID = int(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 *SyncFailureCreateBulk) SaveX(ctx context.Context) []*SyncFailure { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *SyncFailureCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *SyncFailureCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_mes/ent/syncfailure_delete.go b/bj_power_mes/ent/syncfailure_delete.go new file mode 100644 index 0000000..8b9904e --- /dev/null +++ b/bj_power_mes/ent/syncfailure_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/predicate" + "bj_power_mes/ent/syncfailure" + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// SyncFailureDelete is the builder for deleting a SyncFailure entity. +type SyncFailureDelete struct { + config + hooks []Hook + mutation *SyncFailureMutation +} + +// Where appends a list predicates to the SyncFailureDelete builder. +func (_d *SyncFailureDelete) Where(ps ...predicate.SyncFailure) *SyncFailureDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *SyncFailureDelete) 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 *SyncFailureDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *SyncFailureDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(syncfailure.Table, sqlgraph.NewFieldSpec(syncfailure.FieldID, field.TypeInt)) + 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 +} + +// SyncFailureDeleteOne is the builder for deleting a single SyncFailure entity. +type SyncFailureDeleteOne struct { + _d *SyncFailureDelete +} + +// Where appends a list predicates to the SyncFailureDelete builder. +func (_d *SyncFailureDeleteOne) Where(ps ...predicate.SyncFailure) *SyncFailureDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *SyncFailureDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{syncfailure.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *SyncFailureDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_mes/ent/syncfailure_query.go b/bj_power_mes/ent/syncfailure_query.go new file mode 100644 index 0000000..a386cb4 --- /dev/null +++ b/bj_power_mes/ent/syncfailure_query.go @@ -0,0 +1,577 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/predicate" + "bj_power_mes/ent/syncfailure" + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// SyncFailureQuery is the builder for querying SyncFailure entities. +type SyncFailureQuery struct { + config + ctx *QueryContext + order []syncfailure.OrderOption + inters []Interceptor + predicates []predicate.SyncFailure + 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 SyncFailureQuery builder. +func (_q *SyncFailureQuery) Where(ps ...predicate.SyncFailure) *SyncFailureQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *SyncFailureQuery) Limit(limit int) *SyncFailureQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *SyncFailureQuery) Offset(offset int) *SyncFailureQuery { + _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 *SyncFailureQuery) Unique(unique bool) *SyncFailureQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *SyncFailureQuery) Order(o ...syncfailure.OrderOption) *SyncFailureQuery { + _q.order = append(_q.order, o...) + return _q +} + +// First returns the first SyncFailure entity from the query. +// Returns a *NotFoundError when no SyncFailure was found. +func (_q *SyncFailureQuery) First(ctx context.Context) (*SyncFailure, 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{syncfailure.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *SyncFailureQuery) FirstX(ctx context.Context) *SyncFailure { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first SyncFailure ID from the query. +// Returns a *NotFoundError when no SyncFailure ID was found. +func (_q *SyncFailureQuery) FirstID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{syncfailure.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *SyncFailureQuery) FirstIDX(ctx context.Context) int { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single SyncFailure entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one SyncFailure entity is found. +// Returns a *NotFoundError when no SyncFailure entities are found. +func (_q *SyncFailureQuery) Only(ctx context.Context) (*SyncFailure, 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{syncfailure.Label} + default: + return nil, &NotSingularError{syncfailure.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *SyncFailureQuery) OnlyX(ctx context.Context) *SyncFailure { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only SyncFailure ID in the query. +// Returns a *NotSingularError when more than one SyncFailure ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *SyncFailureQuery) OnlyID(ctx context.Context) (id int, err error) { + var ids []int + 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{syncfailure.Label} + default: + err = &NotSingularError{syncfailure.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *SyncFailureQuery) OnlyIDX(ctx context.Context) int { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of SyncFailures. +func (_q *SyncFailureQuery) All(ctx context.Context) ([]*SyncFailure, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*SyncFailure, *SyncFailureQuery]() + return withInterceptors[[]*SyncFailure](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *SyncFailureQuery) AllX(ctx context.Context) []*SyncFailure { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of SyncFailure IDs. +func (_q *SyncFailureQuery) IDs(ctx context.Context) (ids []int, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(syncfailure.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *SyncFailureQuery) IDsX(ctx context.Context) []int { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *SyncFailureQuery) 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[*SyncFailureQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *SyncFailureQuery) 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 *SyncFailureQuery) 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 *SyncFailureQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the SyncFailureQuery 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 *SyncFailureQuery) Clone() *SyncFailureQuery { + if _q == nil { + return nil + } + return &SyncFailureQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]syncfailure.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.SyncFailure{}, _q.predicates...), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + modifiers: append([]func(*sql.Selector){}, _q.modifiers...), + } +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// Direction string `json:"direction,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.SyncFailure.Query(). +// GroupBy(syncfailure.FieldDirection). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *SyncFailureQuery) GroupBy(field string, fields ...string) *SyncFailureGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &SyncFailureGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = syncfailure.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 { +// Direction string `json:"direction,omitempty"` +// } +// +// client.SyncFailure.Query(). +// Select(syncfailure.FieldDirection). +// Scan(ctx, &v) +func (_q *SyncFailureQuery) Select(fields ...string) *SyncFailureSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &SyncFailureSelect{SyncFailureQuery: _q} + sbuild.label = syncfailure.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a SyncFailureSelect configured with the given aggregations. +func (_q *SyncFailureQuery) Aggregate(fns ...AggregateFunc) *SyncFailureSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *SyncFailureQuery) 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 !syncfailure.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 *SyncFailureQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SyncFailure, error) { + var ( + nodes = []*SyncFailure{} + _spec = _q.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*SyncFailure).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &SyncFailure{config: _q.config} + nodes = append(nodes, node) + return node.assignValues(columns, values) + } + if len(_q.modifiers) > 0 { + _spec.Modifiers = _q.modifiers + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + return nodes, nil +} + +func (_q *SyncFailureQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + 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 *SyncFailureQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(syncfailure.Table, syncfailure.Columns, sqlgraph.NewFieldSpec(syncfailure.FieldID, field.TypeInt)) + _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, syncfailure.FieldID) + for i := range fields { + if fields[i] != syncfailure.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *SyncFailureQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(syncfailure.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = syncfailure.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, 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 *SyncFailureQuery) ForUpdate(opts ...sql.LockOption) *SyncFailureQuery { + 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 *SyncFailureQuery) ForShare(opts ...sql.LockOption) *SyncFailureQuery { + 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 *SyncFailureQuery) Modify(modifiers ...func(s *sql.Selector)) *SyncFailureSelect { + _q.modifiers = append(_q.modifiers, modifiers...) + return _q.Select() +} + +// SyncFailureGroupBy is the group-by builder for SyncFailure entities. +type SyncFailureGroupBy struct { + selector + build *SyncFailureQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *SyncFailureGroupBy) Aggregate(fns ...AggregateFunc) *SyncFailureGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *SyncFailureGroupBy) 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[*SyncFailureQuery, *SyncFailureGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *SyncFailureGroupBy) sqlScan(ctx context.Context, root *SyncFailureQuery, 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) +} + +// SyncFailureSelect is the builder for selecting fields of SyncFailure entities. +type SyncFailureSelect struct { + *SyncFailureQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *SyncFailureSelect) Aggregate(fns ...AggregateFunc) *SyncFailureSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *SyncFailureSelect) 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[*SyncFailureQuery, *SyncFailureSelect](ctx, _s.SyncFailureQuery, _s, _s.inters, v) +} + +func (_s *SyncFailureSelect) sqlScan(ctx context.Context, root *SyncFailureQuery, 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 *SyncFailureSelect) Modify(modifiers ...func(s *sql.Selector)) *SyncFailureSelect { + _s.modifiers = append(_s.modifiers, modifiers...) + return _s +} diff --git a/bj_power_mes/ent/syncfailure_update.go b/bj_power_mes/ent/syncfailure_update.go new file mode 100644 index 0000000..2d3039c --- /dev/null +++ b/bj_power_mes/ent/syncfailure_update.go @@ -0,0 +1,659 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/predicate" + "bj_power_mes/ent/syncfailure" + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// SyncFailureUpdate is the builder for updating SyncFailure entities. +type SyncFailureUpdate struct { + config + hooks []Hook + mutation *SyncFailureMutation + modifiers []func(*sql.UpdateBuilder) +} + +// Where appends a list predicates to the SyncFailureUpdate builder. +func (_u *SyncFailureUpdate) Where(ps ...predicate.SyncFailure) *SyncFailureUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetDirection sets the "direction" field. +func (_u *SyncFailureUpdate) SetDirection(v string) *SyncFailureUpdate { + _u.mutation.SetDirection(v) + return _u +} + +// SetNillableDirection sets the "direction" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableDirection(v *string) *SyncFailureUpdate { + if v != nil { + _u.SetDirection(*v) + } + return _u +} + +// SetBizType sets the "biz_type" field. +func (_u *SyncFailureUpdate) SetBizType(v string) *SyncFailureUpdate { + _u.mutation.SetBizType(v) + return _u +} + +// SetNillableBizType sets the "biz_type" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableBizType(v *string) *SyncFailureUpdate { + if v != nil { + _u.SetBizType(*v) + } + return _u +} + +// SetBizKey sets the "biz_key" field. +func (_u *SyncFailureUpdate) SetBizKey(v string) *SyncFailureUpdate { + _u.mutation.SetBizKey(v) + return _u +} + +// SetNillableBizKey sets the "biz_key" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableBizKey(v *string) *SyncFailureUpdate { + if v != nil { + _u.SetBizKey(*v) + } + return _u +} + +// SetEndpoint sets the "endpoint" field. +func (_u *SyncFailureUpdate) SetEndpoint(v string) *SyncFailureUpdate { + _u.mutation.SetEndpoint(v) + return _u +} + +// SetNillableEndpoint sets the "endpoint" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableEndpoint(v *string) *SyncFailureUpdate { + if v != nil { + _u.SetEndpoint(*v) + } + return _u +} + +// SetPayloadJSON sets the "payload_json" field. +func (_u *SyncFailureUpdate) SetPayloadJSON(v string) *SyncFailureUpdate { + _u.mutation.SetPayloadJSON(v) + return _u +} + +// SetNillablePayloadJSON sets the "payload_json" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillablePayloadJSON(v *string) *SyncFailureUpdate { + if v != nil { + _u.SetPayloadJSON(*v) + } + return _u +} + +// SetErrorMsg sets the "error_msg" field. +func (_u *SyncFailureUpdate) SetErrorMsg(v string) *SyncFailureUpdate { + _u.mutation.SetErrorMsg(v) + return _u +} + +// SetNillableErrorMsg sets the "error_msg" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableErrorMsg(v *string) *SyncFailureUpdate { + if v != nil { + _u.SetErrorMsg(*v) + } + return _u +} + +// SetIdempotencyKey sets the "idempotency_key" field. +func (_u *SyncFailureUpdate) SetIdempotencyKey(v string) *SyncFailureUpdate { + _u.mutation.SetIdempotencyKey(v) + return _u +} + +// SetNillableIdempotencyKey sets the "idempotency_key" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableIdempotencyKey(v *string) *SyncFailureUpdate { + if v != nil { + _u.SetIdempotencyKey(*v) + } + return _u +} + +// SetStatus sets the "status" field. +func (_u *SyncFailureUpdate) SetStatus(v string) *SyncFailureUpdate { + _u.mutation.SetStatus(v) + return _u +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableStatus(v *string) *SyncFailureUpdate { + if v != nil { + _u.SetStatus(*v) + } + return _u +} + +// SetRetryCount sets the "retry_count" field. +func (_u *SyncFailureUpdate) SetRetryCount(v int32) *SyncFailureUpdate { + _u.mutation.ResetRetryCount() + _u.mutation.SetRetryCount(v) + return _u +} + +// SetNillableRetryCount sets the "retry_count" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableRetryCount(v *int32) *SyncFailureUpdate { + if v != nil { + _u.SetRetryCount(*v) + } + return _u +} + +// AddRetryCount adds value to the "retry_count" field. +func (_u *SyncFailureUpdate) AddRetryCount(v int32) *SyncFailureUpdate { + _u.mutation.AddRetryCount(v) + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *SyncFailureUpdate) SetCreatedAt(v int64) *SyncFailureUpdate { + _u.mutation.ResetCreatedAt() + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableCreatedAt(v *int64) *SyncFailureUpdate { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// AddCreatedAt adds value to the "created_at" field. +func (_u *SyncFailureUpdate) AddCreatedAt(v int64) *SyncFailureUpdate { + _u.mutation.AddCreatedAt(v) + return _u +} + +// SetLastErrorAt sets the "last_error_at" field. +func (_u *SyncFailureUpdate) SetLastErrorAt(v int64) *SyncFailureUpdate { + _u.mutation.ResetLastErrorAt() + _u.mutation.SetLastErrorAt(v) + return _u +} + +// SetNillableLastErrorAt sets the "last_error_at" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableLastErrorAt(v *int64) *SyncFailureUpdate { + if v != nil { + _u.SetLastErrorAt(*v) + } + return _u +} + +// AddLastErrorAt adds value to the "last_error_at" field. +func (_u *SyncFailureUpdate) AddLastErrorAt(v int64) *SyncFailureUpdate { + _u.mutation.AddLastErrorAt(v) + return _u +} + +// SetHandledBy sets the "handled_by" field. +func (_u *SyncFailureUpdate) SetHandledBy(v string) *SyncFailureUpdate { + _u.mutation.SetHandledBy(v) + return _u +} + +// SetNillableHandledBy sets the "handled_by" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableHandledBy(v *string) *SyncFailureUpdate { + if v != nil { + _u.SetHandledBy(*v) + } + return _u +} + +// Mutation returns the SyncFailureMutation object of the builder. +func (_u *SyncFailureUpdate) Mutation() *SyncFailureMutation { + return _u.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *SyncFailureUpdate) 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 *SyncFailureUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *SyncFailureUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *SyncFailureUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *SyncFailureUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *SyncFailureUpdate { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *SyncFailureUpdate) sqlSave(ctx context.Context) (_node int, err error) { + _spec := sqlgraph.NewUpdateSpec(syncfailure.Table, syncfailure.Columns, sqlgraph.NewFieldSpec(syncfailure.FieldID, field.TypeInt)) + 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.Direction(); ok { + _spec.SetField(syncfailure.FieldDirection, field.TypeString, value) + } + if value, ok := _u.mutation.BizType(); ok { + _spec.SetField(syncfailure.FieldBizType, field.TypeString, value) + } + if value, ok := _u.mutation.BizKey(); ok { + _spec.SetField(syncfailure.FieldBizKey, field.TypeString, value) + } + if value, ok := _u.mutation.Endpoint(); ok { + _spec.SetField(syncfailure.FieldEndpoint, field.TypeString, value) + } + if value, ok := _u.mutation.PayloadJSON(); ok { + _spec.SetField(syncfailure.FieldPayloadJSON, field.TypeString, value) + } + if value, ok := _u.mutation.ErrorMsg(); ok { + _spec.SetField(syncfailure.FieldErrorMsg, field.TypeString, value) + } + if value, ok := _u.mutation.IdempotencyKey(); ok { + _spec.SetField(syncfailure.FieldIdempotencyKey, field.TypeString, value) + } + if value, ok := _u.mutation.Status(); ok { + _spec.SetField(syncfailure.FieldStatus, field.TypeString, value) + } + if value, ok := _u.mutation.RetryCount(); ok { + _spec.SetField(syncfailure.FieldRetryCount, field.TypeInt32, value) + } + if value, ok := _u.mutation.AddedRetryCount(); ok { + _spec.AddField(syncfailure.FieldRetryCount, field.TypeInt32, value) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(syncfailure.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedCreatedAt(); ok { + _spec.AddField(syncfailure.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.LastErrorAt(); ok { + _spec.SetField(syncfailure.FieldLastErrorAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedLastErrorAt(); ok { + _spec.AddField(syncfailure.FieldLastErrorAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.HandledBy(); ok { + _spec.SetField(syncfailure.FieldHandledBy, field.TypeString, value) + } + _spec.AddModifiers(_u.modifiers...) + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{syncfailure.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// SyncFailureUpdateOne is the builder for updating a single SyncFailure entity. +type SyncFailureUpdateOne struct { + config + fields []string + hooks []Hook + mutation *SyncFailureMutation + modifiers []func(*sql.UpdateBuilder) +} + +// SetDirection sets the "direction" field. +func (_u *SyncFailureUpdateOne) SetDirection(v string) *SyncFailureUpdateOne { + _u.mutation.SetDirection(v) + return _u +} + +// SetNillableDirection sets the "direction" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableDirection(v *string) *SyncFailureUpdateOne { + if v != nil { + _u.SetDirection(*v) + } + return _u +} + +// SetBizType sets the "biz_type" field. +func (_u *SyncFailureUpdateOne) SetBizType(v string) *SyncFailureUpdateOne { + _u.mutation.SetBizType(v) + return _u +} + +// SetNillableBizType sets the "biz_type" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableBizType(v *string) *SyncFailureUpdateOne { + if v != nil { + _u.SetBizType(*v) + } + return _u +} + +// SetBizKey sets the "biz_key" field. +func (_u *SyncFailureUpdateOne) SetBizKey(v string) *SyncFailureUpdateOne { + _u.mutation.SetBizKey(v) + return _u +} + +// SetNillableBizKey sets the "biz_key" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableBizKey(v *string) *SyncFailureUpdateOne { + if v != nil { + _u.SetBizKey(*v) + } + return _u +} + +// SetEndpoint sets the "endpoint" field. +func (_u *SyncFailureUpdateOne) SetEndpoint(v string) *SyncFailureUpdateOne { + _u.mutation.SetEndpoint(v) + return _u +} + +// SetNillableEndpoint sets the "endpoint" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableEndpoint(v *string) *SyncFailureUpdateOne { + if v != nil { + _u.SetEndpoint(*v) + } + return _u +} + +// SetPayloadJSON sets the "payload_json" field. +func (_u *SyncFailureUpdateOne) SetPayloadJSON(v string) *SyncFailureUpdateOne { + _u.mutation.SetPayloadJSON(v) + return _u +} + +// SetNillablePayloadJSON sets the "payload_json" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillablePayloadJSON(v *string) *SyncFailureUpdateOne { + if v != nil { + _u.SetPayloadJSON(*v) + } + return _u +} + +// SetErrorMsg sets the "error_msg" field. +func (_u *SyncFailureUpdateOne) SetErrorMsg(v string) *SyncFailureUpdateOne { + _u.mutation.SetErrorMsg(v) + return _u +} + +// SetNillableErrorMsg sets the "error_msg" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableErrorMsg(v *string) *SyncFailureUpdateOne { + if v != nil { + _u.SetErrorMsg(*v) + } + return _u +} + +// SetIdempotencyKey sets the "idempotency_key" field. +func (_u *SyncFailureUpdateOne) SetIdempotencyKey(v string) *SyncFailureUpdateOne { + _u.mutation.SetIdempotencyKey(v) + return _u +} + +// SetNillableIdempotencyKey sets the "idempotency_key" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableIdempotencyKey(v *string) *SyncFailureUpdateOne { + if v != nil { + _u.SetIdempotencyKey(*v) + } + return _u +} + +// SetStatus sets the "status" field. +func (_u *SyncFailureUpdateOne) SetStatus(v string) *SyncFailureUpdateOne { + _u.mutation.SetStatus(v) + return _u +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableStatus(v *string) *SyncFailureUpdateOne { + if v != nil { + _u.SetStatus(*v) + } + return _u +} + +// SetRetryCount sets the "retry_count" field. +func (_u *SyncFailureUpdateOne) SetRetryCount(v int32) *SyncFailureUpdateOne { + _u.mutation.ResetRetryCount() + _u.mutation.SetRetryCount(v) + return _u +} + +// SetNillableRetryCount sets the "retry_count" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableRetryCount(v *int32) *SyncFailureUpdateOne { + if v != nil { + _u.SetRetryCount(*v) + } + return _u +} + +// AddRetryCount adds value to the "retry_count" field. +func (_u *SyncFailureUpdateOne) AddRetryCount(v int32) *SyncFailureUpdateOne { + _u.mutation.AddRetryCount(v) + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *SyncFailureUpdateOne) SetCreatedAt(v int64) *SyncFailureUpdateOne { + _u.mutation.ResetCreatedAt() + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableCreatedAt(v *int64) *SyncFailureUpdateOne { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// AddCreatedAt adds value to the "created_at" field. +func (_u *SyncFailureUpdateOne) AddCreatedAt(v int64) *SyncFailureUpdateOne { + _u.mutation.AddCreatedAt(v) + return _u +} + +// SetLastErrorAt sets the "last_error_at" field. +func (_u *SyncFailureUpdateOne) SetLastErrorAt(v int64) *SyncFailureUpdateOne { + _u.mutation.ResetLastErrorAt() + _u.mutation.SetLastErrorAt(v) + return _u +} + +// SetNillableLastErrorAt sets the "last_error_at" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableLastErrorAt(v *int64) *SyncFailureUpdateOne { + if v != nil { + _u.SetLastErrorAt(*v) + } + return _u +} + +// AddLastErrorAt adds value to the "last_error_at" field. +func (_u *SyncFailureUpdateOne) AddLastErrorAt(v int64) *SyncFailureUpdateOne { + _u.mutation.AddLastErrorAt(v) + return _u +} + +// SetHandledBy sets the "handled_by" field. +func (_u *SyncFailureUpdateOne) SetHandledBy(v string) *SyncFailureUpdateOne { + _u.mutation.SetHandledBy(v) + return _u +} + +// SetNillableHandledBy sets the "handled_by" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableHandledBy(v *string) *SyncFailureUpdateOne { + if v != nil { + _u.SetHandledBy(*v) + } + return _u +} + +// Mutation returns the SyncFailureMutation object of the builder. +func (_u *SyncFailureUpdateOne) Mutation() *SyncFailureMutation { + return _u.mutation +} + +// Where appends a list predicates to the SyncFailureUpdate builder. +func (_u *SyncFailureUpdateOne) Where(ps ...predicate.SyncFailure) *SyncFailureUpdateOne { + _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 *SyncFailureUpdateOne) Select(field string, fields ...string) *SyncFailureUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated SyncFailure entity. +func (_u *SyncFailureUpdateOne) Save(ctx context.Context) (*SyncFailure, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *SyncFailureUpdateOne) SaveX(ctx context.Context) *SyncFailure { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *SyncFailureUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *SyncFailureUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *SyncFailureUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *SyncFailureUpdateOne { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *SyncFailureUpdateOne) sqlSave(ctx context.Context) (_node *SyncFailure, err error) { + _spec := sqlgraph.NewUpdateSpec(syncfailure.Table, syncfailure.Columns, sqlgraph.NewFieldSpec(syncfailure.FieldID, field.TypeInt)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SyncFailure.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, syncfailure.FieldID) + for _, f := range fields { + if !syncfailure.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != syncfailure.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.Direction(); ok { + _spec.SetField(syncfailure.FieldDirection, field.TypeString, value) + } + if value, ok := _u.mutation.BizType(); ok { + _spec.SetField(syncfailure.FieldBizType, field.TypeString, value) + } + if value, ok := _u.mutation.BizKey(); ok { + _spec.SetField(syncfailure.FieldBizKey, field.TypeString, value) + } + if value, ok := _u.mutation.Endpoint(); ok { + _spec.SetField(syncfailure.FieldEndpoint, field.TypeString, value) + } + if value, ok := _u.mutation.PayloadJSON(); ok { + _spec.SetField(syncfailure.FieldPayloadJSON, field.TypeString, value) + } + if value, ok := _u.mutation.ErrorMsg(); ok { + _spec.SetField(syncfailure.FieldErrorMsg, field.TypeString, value) + } + if value, ok := _u.mutation.IdempotencyKey(); ok { + _spec.SetField(syncfailure.FieldIdempotencyKey, field.TypeString, value) + } + if value, ok := _u.mutation.Status(); ok { + _spec.SetField(syncfailure.FieldStatus, field.TypeString, value) + } + if value, ok := _u.mutation.RetryCount(); ok { + _spec.SetField(syncfailure.FieldRetryCount, field.TypeInt32, value) + } + if value, ok := _u.mutation.AddedRetryCount(); ok { + _spec.AddField(syncfailure.FieldRetryCount, field.TypeInt32, value) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(syncfailure.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedCreatedAt(); ok { + _spec.AddField(syncfailure.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.LastErrorAt(); ok { + _spec.SetField(syncfailure.FieldLastErrorAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedLastErrorAt(); ok { + _spec.AddField(syncfailure.FieldLastErrorAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.HandledBy(); ok { + _spec.SetField(syncfailure.FieldHandledBy, field.TypeString, value) + } + _spec.AddModifiers(_u.modifiers...) + _node = &SyncFailure{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{syncfailure.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/bj_power_mes/ent/tx.go b/bj_power_mes/ent/tx.go index 7109fee..d4c83cf 100644 --- a/bj_power_mes/ent/tx.go +++ b/bj_power_mes/ent/tx.go @@ -80,6 +80,8 @@ type Tx struct { StepData *StepDataClient // StepSignRecord is the client for interacting with the StepSignRecord builders. StepSignRecord *StepSignRecordClient + // SyncFailure is the client for interacting with the SyncFailure builders. + SyncFailure *SyncFailureClient // SysConfig is the client for interacting with the SysConfig builders. SysConfig *SysConfigClient // TorqueRecord is the client for interacting with the TorqueRecord builders. @@ -263,6 +265,7 @@ func (tx *Tx) init() { tx.StepCriterion = NewStepCriterionClient(tx.config) tx.StepData = NewStepDataClient(tx.config) tx.StepSignRecord = NewStepSignRecordClient(tx.config) + tx.SyncFailure = NewSyncFailureClient(tx.config) tx.SysConfig = NewSysConfigClient(tx.config) tx.TorqueRecord = NewTorqueRecordClient(tx.config) tx.User = NewUserClient(tx.config) diff --git a/bj_power_mes/frontend/src/pages/ProductProcess.vue b/bj_power_mes/frontend/src/pages/ProductProcess.vue index c06978d..d3ed4bd 100644 --- a/bj_power_mes/frontend/src/pages/ProductProcess.vue +++ b/bj_power_mes/frontend/src/pages/ProductProcess.vue @@ -271,7 +271,7 @@ +
diff --git a/bj_power_mes/schema/gen.go b/bj_power_mes/schema/gen.go deleted file mode 100644 index 817b31b..0000000 --- a/bj_power_mes/schema/gen.go +++ /dev/null @@ -1,5 +0,0 @@ -package schema - -import _ "entgo.io/ent/entc" - -//go:generate go run ./tools/generate.go diff --git a/bj_power_mes/schema/sync_failure.go b/bj_power_mes/schema/sync_failure.go new file mode 100644 index 0000000..2ea5e7b --- /dev/null +++ b/bj_power_mes/schema/sync_failure.go @@ -0,0 +1,54 @@ +package schema + +import ( + "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" +) + +// SyncFailure 跨系统调用失败台账:只记录「本地事务已提交、对端通知失败」的回调, +// 供人工在「同步失败台账」页确认对端状态后重试;系统不自动重试(2026-11-05 拍板)。 +// +// 本表由 internal/syncfailure 用原生 SQL 读写,故列名必须与 +// sql/pending/2026-11-09_sync_failure.sql 严格一致(全部 snake_case)。 +// 加进 ent schema 的目的仅是新装库 / reset-all 时由 Schema.Create 自动建表, +// 不再依赖部署时手工执行迁移 SQL;运行库既有表的读写方式不变。 +type SyncFailure struct { + ent.Schema +} + +func (SyncFailure) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "sync_failure"}, + entsql.WithComments(true), + schema.Comment("SyncFailure 跨系统调用失败台账:本地已提交、对端通知失败,人工确认后重试"), + } +} + +func (SyncFailure) Fields() []ent.Field { + return []ent.Field{ + field.Int("id").Positive(), + field.Text("direction").Default("").Comment("调用方向,如 mes>wms / wms>mes"), + field.Text("biz_type").Default("").Comment("业务类型,如 material.sync"), + field.Text("biz_key").Default("").Comment("业务主键"), + field.Text("endpoint").Default("").Comment("重试时原样重放的对端地址"), + field.Text("payload_json").Default("{}").Comment("通知载荷(JSON)"), + field.Text("error_msg").Default("").Comment("失败原因"), + // 非空且无默认值,与运行库结构一致;Record 的 ON CONFLICT 依赖其唯一索引。 + field.Text("idempotency_key").Comment("幂等键 direction|biz_type|biz_key"), + field.Text("status").Default("PENDING").Comment("PENDING/SUCCESS/DEAD"), + field.Int32("retry_count").Default(0).Comment("重试次数"), + field.Int64("created_at").Default(0).Comment("首次失败时刻(unix秒)"), + field.Int64("last_error_at").Default(0).Comment("最近失败时刻(unix秒)"), + field.Text("handled_by").Default("").Comment("人工置 DEAD 的操作人"), + } +} + +func (SyncFailure) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("idempotency_key").Unique(), + index.Fields("status"), + } +} diff --git a/bj_power_mes/schema/tools/generate.go b/bj_power_mes/schema/tools/generate.go deleted file mode 100644 index d3c0bb4..0000000 --- a/bj_power_mes/schema/tools/generate.go +++ /dev/null @@ -1,28 +0,0 @@ -//go:build ignore - -package main - -import ( - "log" - - "entgo.io/ent/entc" - "entgo.io/ent/entc/gen" -) - -func main() { - if err := entc.Generate( - ".", - &gen.Config{ - Target: "../ent", - Package: "bj_power_mes/ent", - Features: []gen.Feature{ - gen.FeatureExecQuery, - gen.FeatureLock, - gen.FeatureModifier, - gen.FeatureNamedEdges, - }, - }); err != nil { - log.Fatal("running ent codegen:", err) - } - log.Println("ent code generated successfully!") -} \ No newline at end of file diff --git a/bj_power_wms/README.md b/bj_power_wms/README.md index 76c73ec..c0fedc7 100644 --- a/bj_power_wms/README.md +++ b/bj_power_wms/README.md @@ -42,7 +42,7 @@ bj_power_wms/ ```bash # 生成 ent 代码(修改 schema 后执行) -go run tools/generate.go +go run -tags entgenerate ./tools/generate.go # 启动服务 go run bj_power_wms.go -f etc/bj_power_wms-api.yaml diff --git a/bj_power_wms/bj_power_wms.go b/bj_power_wms/bj_power_wms.go index c2001ab..7140378 100644 --- a/bj_power_wms/bj_power_wms.go +++ b/bj_power_wms/bj_power_wms.go @@ -7,10 +7,12 @@ import ( "crypto/subtle" "embed" "encoding/hex" + "encoding/json" "flag" "fmt" "io" "io/fs" + "net" "net/http" "os" "os/exec" @@ -18,7 +20,9 @@ import ( "path/filepath" "runtime" "strings" + "syscall" "time" + "unsafe" "bj_power_wms/internal/config" "bj_power_wms/internal/db" @@ -29,6 +33,9 @@ import ( "bj_power_wms/internal/svc" "bj_power_wms/internal/tray" + "golang.org/x/crypto/bcrypt" + "golang.org/x/sys/windows" + "bj_power_wms/ent/user" "github.com/zeromicro/go-zero/core/conf" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/rest" @@ -88,10 +95,82 @@ func promptPassword(msg string) string { return strings.TrimRight(line, "\r\n") } -// adminGate 管理员密码门禁:敏感命令行操作(migrate/seed/reset-all)必须输入与配置 -// Cli.AdminPassword 一致的密码才放行;校验失败记录日志并终止,绝不继续执行(对齐 MES)。 +// attachCLIConsole Windows GUI 子系统(-H windowsgui 打包)默认没有控制台: +// migrate/seed/reset-all 等子命令需要终端交互(管理员密码提示可见、可输入)。 +// 从 cmd/PowerShell 启动 → AttachConsole(ATTACH_PARENT_PROCESS) 复用父控制台; +// 双击启动(无父控制台)→ AllocConsole 弹出新控制台窗口。只补缺失的 std 句柄, +// 已有控制台不重复处理,失败静默返回不阻断 CLI 流程(2026-11-11 修复,对齐 MES)。 +func attachCLIConsole() { + if runtime.GOOS != "windows" { + return + } + if h, _ := windows.GetStdHandle(windows.STD_OUTPUT_HANDLE); h != 0 { + var mode uint32 + if gerr := windows.GetConsoleMode(h, &mode); gerr == nil { + return // 已有控制台,不重复附加 + } + } + kernel32 := windows.NewLazySystemDLL("kernel32.dll") + attach := kernel32.NewProc("AttachConsole") + alloc := kernel32.NewProc("AllocConsole") + // ATTACH_PARENT_PROCESS = (DWORD)-1 + if r, _, _ := attach.Call(^uintptr(0)); r == 0 { + alloc.Call() + } + openConsole := func(name string, access uint32) windows.Handle { + p, _ := windows.UTF16PtrFromString(name) + h, err := windows.CreateFile(p, access, windows.FILE_SHARE_READ|windows.FILE_SHARE_WRITE, nil, windows.OPEN_EXISTING, 0, 0) + if err != nil { + return 0 + } + return h + } + // 句柄判活(2026-11-11 修复,对齐 MES):GUI 子系统从 cmd/PowerShell 启动时 std 句柄常为 + // 「继承来的死管道」(GetFileType 仍报 PIPE)。 + // - stdin:非控制台一律重建 CONIN$;stdout/stderr:WriteFile 0 字节探活,死管道重建 CONOUT$。 + consoleStd := func(h windows.Handle) bool { + var mode uint32 + return h != 0 && windows.GetConsoleMode(h, &mode) == nil + } + rebind := func(std uint32, file **os.File, name string, conName string, access uint32, probe func(windows.Handle) bool) { + h, _ := windows.GetStdHandle(std) + if consoleStd(h) || (probe != nil && probe(h)) { + return + } + ch := openConsole(conName, access) + if ch == 0 { + return + } + _ = windows.SetStdHandle(std, ch) + *file = os.NewFile(uintptr(ch), name) + } + writeProbe := func(h windows.Handle) bool { + if h == 0 { + return false + } + var n uint32 + return windows.WriteFile(h, nil, &n, nil) == nil + } + rebind(windows.STD_OUTPUT_HANDLE, &os.Stdout, "stdout", "CONOUT$", windows.GENERIC_WRITE|windows.GENERIC_READ, writeProbe) + rebind(windows.STD_ERROR_HANDLE, &os.Stderr, "stderr", "CONOUT$", windows.GENERIC_WRITE|windows.GENERIC_READ, writeProbe) + rebind(windows.STD_INPUT_HANDLE, &os.Stdin, "stdin", "CONIN$", windows.GENERIC_READ, nil) +} + +// adminGate 敏感命令行操作(migrate/seed/reset-all)授权闸门(对齐 MES,2026-11-11 最终策略): +// 管理员权限运行免密放行(提权即授权,零交互);非管理员走 BJ_POWER_CLI_PASSWORD 或终端输入。 func adminGate(c config.Config) bool { - pwd := promptPassword("请输入管理员密码以执行 [" + flag.Arg(0) + "]: ") + if runtime.GOOS == "windows" && windows.GetCurrentProcessToken().IsElevated() { + logx.Infof("敏感命令 [%s] 以管理员权限运行,免密放行", flag.Arg(0)) + fmt.Println("以管理员权限运行,免密执行 [" + flag.Arg(0) + "]") + return true + } + pwd := cliPasswordArg() + if pwd == "" { + pwd = strings.TrimSpace(os.Getenv("BJ_POWER_CLI_PASSWORD")) + } + if pwd == "" { + pwd = promptPassword("请输入管理员密码以执行 [" + flag.Arg(0) + "]: ") + } if subtle.ConstantTimeCompare([]byte(pwd), []byte(c.Cli.AdminPassword)) != 1 { logx.Errorf("敏感命令 [%s] 因管理员密码校验失败被终止", flag.Arg(0)) fmt.Println("管理员密码不正确,已终止该操作。") @@ -101,6 +180,47 @@ func adminGate(c config.Config) bool { return true } +// cliPasswordArg 解析子命令后的 -p/--password 参数(Go flag 只解析子命令前的参数)。 +func cliPasswordArg() string { + args := flag.Args() + for i := 1; i < len(args); i++ { + if (args[i] == "-p" || args[i] == "--password") && i+1 < len(args) { + return strings.TrimSpace(args[i+1]) + } + } + return "" +} + +// cliNotify 结果弹窗(MessageBox):GUI exe 在终端里控制台输出可能不可见,敏感命令结果一律弹窗。 +func cliNotify(title, msg string) { + if runtime.GOOS != "windows" { + return + } + user32 := windows.NewLazySystemDLL("user32.dll") + mb := user32.NewProc("MessageBoxW") + t, terr := windows.UTF16PtrFromString(title) + m, merr := windows.UTF16PtrFromString(msg) + if terr != nil || merr != nil { + return + } + mb.Call(0, uintptr(unsafe.Pointer(m)), uintptr(unsafe.Pointer(t)), 0x40) // MB_OK | MB_ICONINFORMATION +} + +// cliNotifyError 失败弹窗(红叉图标) +func cliNotifyError(title, msg string) { + if runtime.GOOS != "windows" { + return + } + user32 := windows.NewLazySystemDLL("user32.dll") + mb := user32.NewProc("MessageBoxW") + t, terr := windows.UTF16PtrFromString(title) + m, merr := windows.UTF16PtrFromString(msg) + if terr != nil || merr != nil { + return + } + mb.Call(0, uintptr(unsafe.Pointer(m)), uintptr(unsafe.Pointer(t)), 0x10) // MB_ICONERROR +} + // dbConf 从服务配置构造数据库连接配置 func dbConf(c config.Config) db.DatabaseConf { return db.DatabaseConf{ @@ -112,69 +232,360 @@ func dbConf(c config.Config) db.DatabaseConf { } } +// autoRegisterShortcuts 管理员运行 exe 时自动注册开机自启 + 桌面快捷方式(2026-11-11 拍板): +// WMS 依赖系统托盘与浏览器会话,不注册为 Windows 服务,走「公共启动文件夹 + 公共桌面」。 +// 幂等:快捷方式已存在则跳过;非管理员跳过并提示,正常启动不影响业务。 +func autoRegisterShortcuts(name, arguments string) { + if runtime.GOOS != "windows" { + return + } + if !windows.GetCurrentProcessToken().IsElevated() { + fmt.Println("当前非管理员权限运行,跳过开机自启/桌面快捷方式注册(如需自启,请以管理员身份运行一次本程序)。") + logx.Infof("非管理员运行,跳过自启动注册") + return + } + exe, err := os.Executable() + if err != nil { + logx.Errorf("获取 exe 路径失败,跳过自启动注册: %v", err) + return + } + if realPath, rerr := filepath.EvalSymlinks(exe); rerr == nil { + exe = realPath + } + workDir := filepath.Dir(exe) + startupDir := filepath.Join(os.Getenv("ProgramData"), "Microsoft", "Windows", "Start Menu", "Programs", "StartUp") + desktopDir := filepath.Join(os.Getenv("PUBLIC"), "Desktop") + targets := map[string]string{ + filepath.Join(startupDir, name+".lnk"): "开机自启快捷方式", + filepath.Join(desktopDir, name+".lnk"): "桌面快捷方式", + } + for lnk, kind := range targets { + if _, err := os.Stat(lnk); err == nil { + logx.Infof("%s 已存在,跳过重复创建:%s", kind, lnk) + continue + } + if err := createShortcut(lnk, exe, arguments, workDir); err != nil { + logx.Errorf("创建%s失败 %s: %v", kind, lnk, err) + continue + } + logx.Infof("已创建%s:%s → %s %s", kind, lnk, exe, arguments) + } +} + +// createShortcut 用 PowerShell(WScript.Shell COM)创建 .lnk 快捷方式(不引第三方依赖)。 +// HideWindow 避免从 GUI 程序拉起 powershell 时闪黑框。 +func createShortcut(linkPath, targetPath, arguments, workDir string) error { + script := fmt.Sprintf( + `$s=(New-Object -ComObject WScript.Shell).CreateShortcut('%s'); $s.TargetPath='%s'; $s.Arguments='%s'; $s.WorkingDirectory='%s'; $s.Save()`, + linkPath, targetPath, arguments, workDir) + cmd := exec.Command("powershell", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", script) + cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} + out, err := cmd.CombinedOutput() + if err != nil { + return fmt.Errorf("%v: %s", err, strings.TrimSpace(string(out))) + } + return nil +} + +// ==================== 进程守护(2026-11-11 拍板:三端 exe 常驻存活) ==================== +// 双进程互守(同一 exe 自举):guardian(隐形监督进程)+ worker(业务进程)。 +// - 启动先抢 Local\BJP_WMS_GUARDIAN 互斥体:抢到=guardian;抢不到=worker; +// - worker 持 Local\BJP_WMS_WORKER 互斥体(防重复实例),每 5s TCP 探活本机端口, +// 探活成功才写心跳文件 %TEMP%\bj_power_wms.guard.json(pid/ts/listening); +// - guardian:worker 退出码 0(托盘主动退出)→ 跟随退出;非 0(崩溃)→ 3s 后重拉; +// 心跳过期 30s(卡死)→ 校验进程映像后杀掉重拉;连续 5 次秒退 → 退避 60s; +// - worker 每 10s 检查 guardian 互斥体:消失 → 拉起新 guardian 继续监视自己(收养模式)。 +const ( + guardMutexName = `Local\BJP_WMS_GUARDIAN` + workerMutexName = `Local\BJP_WMS_WORKER` + guardHeartbeatTTL = 30 * time.Second + guardSpawnGrace = 90 * time.Second +) + +func exePathGuard() string { + exe, err := os.Executable() + if err != nil { + return os.Args[0] + } + if rp, rerr := filepath.EvalSymlinks(exe); rerr == nil { + exe = rp + } + return exe +} + +func createOwnedMutex(name string) (windows.Handle, bool) { + h, err := windows.CreateMutex(nil, false, windows.StringToUTF16Ptr(name)) + if h == 0 { + return 0, false + } + return h, err == nil // 已存在时 err=ERROR_ALREADY_EXISTS +} + +func mutexExists(name string) bool { + h, err := windows.OpenMutex(windows.SYNCHRONIZE, false, windows.StringToUTF16Ptr(name)) + if err == nil { + windows.CloseHandle(h) + return true + } + return false +} + +type guardInfo struct { + PID int `json:"pid"` + TS time.Time `json:"ts"` + Listening bool `json:"listening"` +} + +func guardHeartbeatFile() string { + return filepath.Join(os.TempDir(), "bj_power_wms.guard.json") +} + +func readGuardInfo() (guardInfo, bool) { + var gi guardInfo + data, err := os.ReadFile(guardHeartbeatFile()) + if err != nil || json.Unmarshal(data, &gi) != nil { + return gi, false + } + return gi, true +} + +func guardianLog(format string, args ...any) { + f, err := os.OpenFile(filepath.Join(os.TempDir(), "bj_power_wms.guardian.log"), + os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644) + if err != nil { + return + } + defer f.Close() + fmt.Fprintf(f, time.Now().Format("2006-01-02 15:04:05 ")+"guardian: "+fmt.Sprintf(format, args...)+"\n") +} + +// guardianHeartbeat worker 心跳:每 5s TCP 探活本机端口,成功才写心跳文件。 +func guardianHeartbeat(port int) { + for { + listening := false + if conn, err := net.DialTimeout("tcp", fmt.Sprintf("127.0.0.1:%d", port), 3*time.Second); err == nil { + conn.Close() + listening = true + } + if data, err := json.Marshal(guardInfo{PID: os.Getpid(), TS: time.Now(), Listening: listening}); err == nil { + _ = os.WriteFile(guardHeartbeatFile(), data, 0644) + } + time.Sleep(5 * time.Second) + } +} + +// workerWatchGuardian worker 监督 guardian:guardian 崩溃 → 拉起新 guardian 继续监视自己。 +func workerWatchGuardian(exe string) { + for { + time.Sleep(10 * time.Second) + if mutexExists(guardMutexName) { + continue + } + guardianLog("guardian 消失,worker(%d) 重新拉起监督进程", os.Getpid()) + cmd := exec.Command(exe, os.Args[1:]...) + cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} + if err := cmd.Start(); err == nil { + time.Sleep(15 * time.Second) // 等新 guardian 就位(收养模式),防重复拉起 + } + } +} + +// killWorker 按 PID 杀 worker;先校验进程映像确为本 exe(防 PID 复用误杀)。 +func killWorker(pid int, expectExe string) { + if pid <= 0 { + return + } + h, err := windows.OpenProcess(windows.PROCESS_TERMINATE|windows.SYNCHRONIZE| + windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid)) + if err != nil { + return + } + defer windows.CloseHandle(h) + buf := make([]uint16, 32768) + size := uint32(len(buf)) + if err := windows.QueryFullProcessImageName(h, 0, &buf[0], &size); err != nil { + return + } + if !strings.EqualFold(filepath.Base(windows.UTF16ToString(buf[:size])), filepath.Base(expectExe)) { + return + } + windows.TerminateProcess(h, 1) +} + +// supervise 拉起 worker 子进程并盯防:正常退出返回退出码;心跳异常则杀掉。 +func supervise(exe string) (int, time.Duration) { + start := time.Now() + cmd := exec.Command(exe, os.Args[1:]...) + if err := cmd.Start(); err != nil { + guardianLog("拉起 worker 失败: %v", err) + return -1, 0 + } + done := make(chan int, 1) + go func() { + _ = cmd.Wait() + if cmd.ProcessState != nil { + done <- cmd.ProcessState.ExitCode() + } else { + done <- -1 + } + }() + ticker := time.NewTicker(5 * time.Second) + defer ticker.Stop() + for { + select { + case code := <-done: + return code, time.Since(start) + case <-ticker.C: + gi, ok := readGuardInfo() + if !ok { + continue + } + if (gi.Listening && time.Since(gi.TS) > guardHeartbeatTTL) || + (!gi.Listening && time.Since(start) > guardSpawnGrace) { + guardianLog("worker(%d) 心跳异常(listening=%v,距上次心跳 %v),杀掉重拉", + gi.PID, gi.Listening, time.Since(gi.TS).Round(time.Second)) + killWorker(gi.PID, exe) + } + } + } +} + +// guardianLoop guardian 主循环。 +func guardianLoop(exe string) { + guardianLog("guardian 启动 pid=%d args=%v", os.Getpid(), os.Args[1:]) + failStreak := 0 + for { + if mutexExists(workerMutexName) { + // 收养模式:worker 已在运行(worker 检测到 guardian 死亡后拉起了本进程) + if gi, ok := readGuardInfo(); ok && gi.Listening && time.Since(gi.TS) > guardHeartbeatTTL { + guardianLog("收养模式:worker(%d) 心跳过期,杀掉重拉", gi.PID) + killWorker(gi.PID, exe) + } + time.Sleep(3 * time.Second) + continue + } + if failStreak >= 5 { + guardianLog("连续 %d 次 10s 内秒退(多为配置/环境错误),退避 60s 后继续尝试", failStreak) + time.Sleep(60 * time.Second) + failStreak = 0 + } + code, lived := supervise(exe) + if code == 0 { + guardianLog("worker 主动退出(code=0),guardian 跟随退出") + return + } + if lived >= time.Minute { + failStreak = 0 + } else { + failStreak++ + } + guardianLog("worker 异常退出(code=%d,存活 %v),3s 后重拉(failStreak=%d)", code, lived.Round(time.Second), failStreak) + time.Sleep(3 * time.Second) + } +} + +// runGuarded 进程守护入口:决定本进程是 guardian 还是 worker。 +func runGuarded(runWorker func(), port int) { + if runtime.GOOS != "windows" { + runWorker() + return + } + exe := exePathGuard() + if gm, owned := createOwnedMutex(guardMutexName); owned { + _ = gm + guardianLoop(exe) + return + } else { + // 关键:未抢到 guardian 身份必须立即关闭观察句柄,否则 worker 会一直持有 + // guardian 互斥体对象,guardian 死后自愈检测失效(2026-11-11 实测踩坑,对齐 MES)。 + windows.CloseHandle(gm) + } + wm, workerOwned := createOwnedMutex(workerMutexName) + if !workerOwned { + return // 已有 worker 在运行,静默退出防重复实例 + } + _ = wm + go workerWatchGuardian(exe) + go guardianHeartbeat(port) + guardianLog("worker 启动 pid=%d", os.Getpid()) + runWorker() +} + // runMigrate 仅建表/补列(只增,不删任何数据) -func runMigrate(c config.Config) { +func runMigrate(c config.Config) error { dbc := dbConf(c) if err := db.EnsureDB(dbc); err != nil { logx.Errorf("ensure database failed: %v", err) - os.Exit(1) + return fmt.Errorf("准备数据库失败:%v", err) } client := db.MustNewDB(dbc) defer client.Close() if err := db.AutoMigrate(client); err != nil { logx.Errorf("migrate failed: %v", err) - os.Exit(1) + return fmt.Errorf("结构迁移失败:%v", err) } fmt.Println("migrate: 数据库结构迁移成功(只增/补列,未删除任何数据)。") + return nil } // runSeed 对齐基础主数据 + 权限角色(不删数据;表不存在则先建) -func runSeed(c config.Config) { +func runSeed(c config.Config) error { dbc := dbConf(c) if err := db.EnsureDB(dbc); err != nil { logx.Errorf("ensure database failed: %v", err) - os.Exit(1) + return fmt.Errorf("准备数据库失败:%v", err) } client := db.MustNewDB(dbc) defer client.Close() if err := db.AutoMigrate(client); err != nil { logx.Errorf("seed migrate failed: %v", err) - os.Exit(1) + return fmt.Errorf("结构迁移失败:%v", err) } if err := db.SeedIfEmpty(client); err != nil { logx.Errorf("seed failed: %v", err) - os.Exit(1) + return fmt.Errorf("写入基础数据失败:%v", err) } svcCtx := &svc.ServiceContext{EntClient: client, EventLog: eventlog.NewWriter(client)} p, r, b := handler.SeedRBAC(svcCtx, "system") - fmt.Printf("seed: 基础数据与权限已对齐(新增权限 %d、角色 %d、绑定用户 %d)。\n", p, r, b) + // 与 MES 对齐(2026-11-11):生产已有库的 admin 密码失忆时,跑 seed 即可重置回 + // admin/123456——只重置 admin 账号本身,不动其他用户与任何业务数据(对齐 MES seed.go:79-87)。 + adminHash, _ := bcrypt.GenerateFromPassword([]byte("123456"), bcrypt.DefaultCost) + if n, err := client.User.Update().Where(user.Username("admin")).SetPassword(string(adminHash)).Save(context.Background()); err != nil { + logx.Errorf("重置 admin 密码失败: %v", err) + } else if n > 0 { + fmt.Println("seed: 已重置 admin 账号密码为 123456(仅 admin 账号,不动业务数据)。") + } + logx.Infof("seed: 基础数据与权限已对齐(新增权限 %d、角色 %d、绑定用户 %d);管理员 admin/123456", p, r, b) + fmt.Printf("seed: 基础数据与权限已对齐(新增权限 %d、角色 %d、绑定用户 %d);管理员 admin/123456。\n", p, r, b) + return nil } // runResetAll 清空并重建全部表 + 重灌全部种子(基础主数据 + 权限角色)。此操作不可恢复! -func runResetAll(c config.Config) { +func runResetAll(c config.Config) error { dbc := dbConf(c) if err := db.EnsureDB(dbc); err != nil { logx.Errorf("ensure database failed: %v", err) - os.Exit(1) + return fmt.Errorf("准备数据库失败:%v", err) } if err := db.DropAllTables(dbc); err != nil { logx.Errorf("reset-all drop failed: %v", err) - os.Exit(1) + return fmt.Errorf("删表失败:%v", err) } client := db.MustNewDB(dbc) defer client.Close() if err := db.AutoMigrate(client); err != nil { logx.Errorf("reset-all migrate failed: %v", err) - os.Exit(1) + return fmt.Errorf("重建表失败:%v", err) } if err := db.SeedIfEmpty(client); err != nil { logx.Errorf("reset-all seed failed: %v", err) - os.Exit(1) + return fmt.Errorf("写入基础数据失败:%v", err) } svcCtx := &svc.ServiceContext{EntClient: client, EventLog: eventlog.NewWriter(client)} p, r, b := handler.SeedRBAC(svcCtx, "system") logx.Infof("reset-all 完成:新增权限 %d、角色 %d、绑定用户 %d", p, r, b) fmt.Println("reset-all: 已清空并重建全部表,写入基础主数据与权限(管理员 admin/123456)。") + return nil } // logRuntimeBinaryFingerprint 在启动早期打印当前运行 EXE 的指纹(真实路径/大小/MD5/修改时间), @@ -231,33 +642,60 @@ func main() { // 命令行子命令:DDL/删库/种子等敏感操作一律显式触发 + 管理员密码门禁, // 绝不随服务启动自动执行(对齐 MES:migrate / seed / reset-all / serve)。 + // GUI 子系统打包(-H windowsgui)无控制台:CLI 子命令先补控制台(见 attachCLIConsole)。 + switch flag.Arg(0) { + case "migrate", "seed", "reset-all": + attachCLIConsole() + } switch cmd := flag.Arg(0); cmd { case "reset-all": fmt.Println("reset-all: 即将清空并重建 WMS 全部表,此操作不可恢复!") if !adminGate(c) { + cliNotifyError("reset-all 未执行", "未通过管理员校验。\n\n任选一种方式重试:\n① 右键「以管理员身份运行」cmd\n② 带密码参数:bj_power_wms.exe reset-all -p 管理员密码\n③ 先设环境变量 BJ_POWER_CLI_PASSWORD") os.Exit(1) } - runResetAll(c) + if err := runResetAll(c); err != nil { + cliNotifyError("reset-all 失败", err.Error()) + os.Exit(1) + } + cliNotify("reset-all 完成", "已清空并重建全部表,已写入基础主数据。\n管理员账号:admin / 123456") return case "seed": if !adminGate(c) { + cliNotifyError("seed 未执行", "未通过管理员校验。\n\n任选一种方式重试:\n① 右键「以管理员身份运行」cmd\n② 带密码参数:bj_power_wms.exe seed -p 管理员密码\n③ 先设环境变量 BJ_POWER_CLI_PASSWORD") os.Exit(1) } - runSeed(c) + if err := runSeed(c); err != nil { + cliNotifyError("seed 失败", err.Error()) + os.Exit(1) + } + cliNotify("seed 完成", "基础数据与权限已对齐;admin 密码已重置为 123456。") return case "migrate": if !adminGate(c) { + cliNotifyError("migrate 未执行", "未通过管理员校验。\n\n任选一种方式重试:\n① 右键「以管理员身份运行」cmd\n② 带密码参数:bj_power_wms.exe migrate -p 管理员密码\n③ 先设环境变量 BJ_POWER_CLI_PASSWORD") os.Exit(1) } - runMigrate(c) + if err := runMigrate(c); err != nil { + cliNotifyError("migrate 失败", err.Error()) + os.Exit(1) + } + cliNotify("migrate 完成", "数据库结构迁移成功(只增/补列,未删除任何数据)。") return case "", "serve": - // 正常启动服务:落到下方启动逻辑 + // 正常启动服务:管理员运行时先自注册开机自启 + 桌面快捷方式(见 autoRegisterShortcuts) + autoRegisterShortcuts("BJ Power WMS", "serve") + // 进程守护(2026-11-11 拍板):guardian+worker 双进程互守,崩溃/卡死自动拉起 + runGuarded(func() { runServeWMS(c) }, c.Port) + return default: fmt.Println("未知命令: " + cmd + ";可用命令: migrate / seed / reset-all / serve") os.Exit(1) } +} +// runServeWMS 启动 WMS 服务 + 托盘(由 runGuarded 的 worker 调用)。 +func runServeWMS(c config.Config) { staticHandler := newStaticHandler(webFS) // 兜底路由:已注册的 /api/* 走正常匹配;未注册的非 /api 路径走嵌入式静态资源 diff --git a/bj_power_wms/ent/client.go b/bj_power_wms/ent/client.go index f69b66b..13bc2a1 100644 --- a/bj_power_wms/ent/client.go +++ b/bj_power_wms/ent/client.go @@ -34,6 +34,7 @@ import ( "bj_power_wms/ent/semifinished" "bj_power_wms/ent/stocktakeitem" "bj_power_wms/ent/stocktakeorder" + "bj_power_wms/ent/syncfailure" "bj_power_wms/ent/sysconfig" "bj_power_wms/ent/user" "bj_power_wms/ent/zone" @@ -94,6 +95,8 @@ type Client struct { StocktakeItem *StocktakeItemClient // StocktakeOrder is the client for interacting with the StocktakeOrder builders. StocktakeOrder *StocktakeOrderClient + // SyncFailure is the client for interacting with the SyncFailure builders. + SyncFailure *SyncFailureClient // SysConfig is the client for interacting with the SysConfig builders. SysConfig *SysConfigClient // User is the client for interacting with the User builders. @@ -134,6 +137,7 @@ func (c *Client) init() { c.SemiFinished = NewSemiFinishedClient(c.config) c.StocktakeItem = NewStocktakeItemClient(c.config) c.StocktakeOrder = NewStocktakeOrderClient(c.config) + c.SyncFailure = NewSyncFailureClient(c.config) c.SysConfig = NewSysConfigClient(c.config) c.User = NewUserClient(c.config) c.Zone = NewZoneClient(c.config) @@ -252,6 +256,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { SemiFinished: NewSemiFinishedClient(cfg), StocktakeItem: NewStocktakeItemClient(cfg), StocktakeOrder: NewStocktakeOrderClient(cfg), + SyncFailure: NewSyncFailureClient(cfg), SysConfig: NewSysConfigClient(cfg), User: NewUserClient(cfg), Zone: NewZoneClient(cfg), @@ -297,6 +302,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) SemiFinished: NewSemiFinishedClient(cfg), StocktakeItem: NewStocktakeItemClient(cfg), StocktakeOrder: NewStocktakeOrderClient(cfg), + SyncFailure: NewSyncFailureClient(cfg), SysConfig: NewSysConfigClient(cfg), User: NewUserClient(cfg), Zone: NewZoneClient(cfg), @@ -334,7 +340,7 @@ func (c *Client) Use(hooks ...Hook) { c.InspectionRecord, c.Inventory, c.InventoryLock, c.Material, c.MaterialDemand, c.OrderMaterialLedger, c.OutboundDetail, c.OutboundOrder, c.Permission, c.ReturnOrder, c.Role, c.SemiFinished, c.StocktakeItem, c.StocktakeOrder, - c.SysConfig, c.User, c.Zone, + c.SyncFailure, c.SysConfig, c.User, c.Zone, } { n.Use(hooks...) } @@ -349,7 +355,7 @@ func (c *Client) Intercept(interceptors ...Interceptor) { c.InspectionRecord, c.Inventory, c.InventoryLock, c.Material, c.MaterialDemand, c.OrderMaterialLedger, c.OutboundDetail, c.OutboundOrder, c.Permission, c.ReturnOrder, c.Role, c.SemiFinished, c.StocktakeItem, c.StocktakeOrder, - c.SysConfig, c.User, c.Zone, + c.SyncFailure, c.SysConfig, c.User, c.Zone, } { n.Intercept(interceptors...) } @@ -404,6 +410,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.StocktakeItem.mutate(ctx, m) case *StocktakeOrderMutation: return c.StocktakeOrder.mutate(ctx, m) + case *SyncFailureMutation: + return c.SyncFailure.mutate(ctx, m) case *SysConfigMutation: return c.SysConfig.mutate(ctx, m) case *UserMutation: @@ -3474,6 +3482,139 @@ func (c *StocktakeOrderClient) mutate(ctx context.Context, m *StocktakeOrderMuta } } +// SyncFailureClient is a client for the SyncFailure schema. +type SyncFailureClient struct { + config +} + +// NewSyncFailureClient returns a client for the SyncFailure from the given config. +func NewSyncFailureClient(c config) *SyncFailureClient { + return &SyncFailureClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `syncfailure.Hooks(f(g(h())))`. +func (c *SyncFailureClient) Use(hooks ...Hook) { + c.hooks.SyncFailure = append(c.hooks.SyncFailure, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `syncfailure.Intercept(f(g(h())))`. +func (c *SyncFailureClient) Intercept(interceptors ...Interceptor) { + c.inters.SyncFailure = append(c.inters.SyncFailure, interceptors...) +} + +// Create returns a builder for creating a SyncFailure entity. +func (c *SyncFailureClient) Create() *SyncFailureCreate { + mutation := newSyncFailureMutation(c.config, OpCreate) + return &SyncFailureCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of SyncFailure entities. +func (c *SyncFailureClient) CreateBulk(builders ...*SyncFailureCreate) *SyncFailureCreateBulk { + return &SyncFailureCreateBulk{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 *SyncFailureClient) MapCreateBulk(slice any, setFunc func(*SyncFailureCreate, int)) *SyncFailureCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &SyncFailureCreateBulk{err: fmt.Errorf("calling to SyncFailureClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*SyncFailureCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &SyncFailureCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for SyncFailure. +func (c *SyncFailureClient) Update() *SyncFailureUpdate { + mutation := newSyncFailureMutation(c.config, OpUpdate) + return &SyncFailureUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *SyncFailureClient) UpdateOne(_m *SyncFailure) *SyncFailureUpdateOne { + mutation := newSyncFailureMutation(c.config, OpUpdateOne, withSyncFailure(_m)) + return &SyncFailureUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *SyncFailureClient) UpdateOneID(id int) *SyncFailureUpdateOne { + mutation := newSyncFailureMutation(c.config, OpUpdateOne, withSyncFailureID(id)) + return &SyncFailureUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for SyncFailure. +func (c *SyncFailureClient) Delete() *SyncFailureDelete { + mutation := newSyncFailureMutation(c.config, OpDelete) + return &SyncFailureDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *SyncFailureClient) DeleteOne(_m *SyncFailure) *SyncFailureDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *SyncFailureClient) DeleteOneID(id int) *SyncFailureDeleteOne { + builder := c.Delete().Where(syncfailure.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &SyncFailureDeleteOne{builder} +} + +// Query returns a query builder for SyncFailure. +func (c *SyncFailureClient) Query() *SyncFailureQuery { + return &SyncFailureQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeSyncFailure}, + inters: c.Interceptors(), + } +} + +// Get returns a SyncFailure entity by its id. +func (c *SyncFailureClient) Get(ctx context.Context, id int) (*SyncFailure, error) { + return c.Query().Where(syncfailure.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *SyncFailureClient) GetX(ctx context.Context, id int) *SyncFailure { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *SyncFailureClient) Hooks() []Hook { + return c.hooks.SyncFailure +} + +// Interceptors returns the client interceptors. +func (c *SyncFailureClient) Interceptors() []Interceptor { + return c.inters.SyncFailure +} + +func (c *SyncFailureClient) mutate(ctx context.Context, m *SyncFailureMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&SyncFailureCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&SyncFailureUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&SyncFailureUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&SyncFailureDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown SyncFailure mutation op: %q", m.Op()) + } +} + // SysConfigClient is a client for the SysConfig schema. type SysConfigClient struct { config @@ -3880,13 +4021,13 @@ type ( EventLog, InboundDetail, InboundOrder, InspectionRecord, Inventory, InventoryLock, Material, MaterialDemand, OrderMaterialLedger, OutboundDetail, OutboundOrder, Permission, ReturnOrder, Role, SemiFinished, StocktakeItem, - StocktakeOrder, SysConfig, User, Zone []ent.Hook + StocktakeOrder, SyncFailure, SysConfig, User, Zone []ent.Hook } inters struct { Alert, AlertRule, Attachment, BackupRecord, DeliveryOrder, DeliveryOrderItem, EventLog, InboundDetail, InboundOrder, InspectionRecord, Inventory, InventoryLock, Material, MaterialDemand, OrderMaterialLedger, OutboundDetail, OutboundOrder, Permission, ReturnOrder, Role, SemiFinished, StocktakeItem, - StocktakeOrder, SysConfig, User, Zone []ent.Interceptor + StocktakeOrder, SyncFailure, SysConfig, User, Zone []ent.Interceptor } ) diff --git a/bj_power_wms/ent/ent.go b/bj_power_wms/ent/ent.go index 472f6d1..22772bf 100644 --- a/bj_power_wms/ent/ent.go +++ b/bj_power_wms/ent/ent.go @@ -26,6 +26,7 @@ import ( "bj_power_wms/ent/semifinished" "bj_power_wms/ent/stocktakeitem" "bj_power_wms/ent/stocktakeorder" + "bj_power_wms/ent/syncfailure" "bj_power_wms/ent/sysconfig" "bj_power_wms/ent/user" "bj_power_wms/ent/zone" @@ -121,6 +122,7 @@ func checkColumn(t, c string) error { semifinished.Table: semifinished.ValidColumn, stocktakeitem.Table: stocktakeitem.ValidColumn, stocktakeorder.Table: stocktakeorder.ValidColumn, + syncfailure.Table: syncfailure.ValidColumn, sysconfig.Table: sysconfig.ValidColumn, user.Table: user.ValidColumn, zone.Table: zone.ValidColumn, diff --git a/bj_power_wms/ent/hook/hook.go b/bj_power_wms/ent/hook/hook.go index a8f6230..3df78f2 100644 --- a/bj_power_wms/ent/hook/hook.go +++ b/bj_power_wms/ent/hook/hook.go @@ -284,6 +284,18 @@ func (f StocktakeOrderFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Val return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.StocktakeOrderMutation", m) } +// The SyncFailureFunc type is an adapter to allow the use of ordinary +// function as SyncFailure mutator. +type SyncFailureFunc func(context.Context, *ent.SyncFailureMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f SyncFailureFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.SyncFailureMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SyncFailureMutation", 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) diff --git a/bj_power_wms/ent/migrate/schema.go b/bj_power_wms/ent/migrate/schema.go index 6c1dac5..e66bc4e 100644 --- a/bj_power_wms/ent/migrate/schema.go +++ b/bj_power_wms/ent/migrate/schema.go @@ -935,6 +935,41 @@ var ( }, }, } + // SyncFailureColumns holds the columns for the "sync_failure" table. + SyncFailureColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "direction", Type: field.TypeString, Size: 2147483647, Comment: "调用方向,如 mes>wms / wms>mes", Default: ""}, + {Name: "biz_type", Type: field.TypeString, Size: 2147483647, Comment: "业务类型,如 material.sync", Default: ""}, + {Name: "biz_key", Type: field.TypeString, Size: 2147483647, Comment: "业务主键", Default: ""}, + {Name: "endpoint", Type: field.TypeString, Size: 2147483647, Comment: "重试时原样重放的对端地址", Default: ""}, + {Name: "payload_json", Type: field.TypeString, Size: 2147483647, Comment: "通知载荷(JSON)", Default: "{}"}, + {Name: "error_msg", Type: field.TypeString, Size: 2147483647, Comment: "失败原因", Default: ""}, + {Name: "idempotency_key", Type: field.TypeString, Size: 2147483647, Comment: "幂等键 direction|biz_type|biz_key"}, + {Name: "status", Type: field.TypeString, Size: 2147483647, Comment: "PENDING/SUCCESS/DEAD", Default: "PENDING"}, + {Name: "retry_count", Type: field.TypeInt32, Comment: "重试次数", Default: 0}, + {Name: "created_at", Type: field.TypeInt64, Comment: "首次失败时刻(unix秒)", Default: 0}, + {Name: "last_error_at", Type: field.TypeInt64, Comment: "最近失败时刻(unix秒)", Default: 0}, + {Name: "handled_by", Type: field.TypeString, Size: 2147483647, Comment: "人工置 DEAD 的操作人", Default: ""}, + } + // SyncFailureTable holds the schema information for the "sync_failure" table. + SyncFailureTable = &schema.Table{ + Name: "sync_failure", + Comment: "SyncFailure 跨系统调用失败台账:本地已提交、对端通知失败,人工确认后重试", + Columns: SyncFailureColumns, + PrimaryKey: []*schema.Column{SyncFailureColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "syncfailure_idempotency_key", + Unique: true, + Columns: []*schema.Column{SyncFailureColumns[7]}, + }, + { + Name: "syncfailure_status", + Unique: false, + Columns: []*schema.Column{SyncFailureColumns[8]}, + }, + }, + } // SysConfigColumns holds the columns for the "sys_config" table. SysConfigColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, @@ -1028,6 +1063,7 @@ var ( SemiFinishedsTable, StocktakeItemsTable, StocktakeOrdersTable, + SyncFailureTable, SysConfigTable, UsersTable, ZonesTable, @@ -1104,6 +1140,9 @@ func init() { StocktakeOrdersTable.Annotation = &entsql.Annotation{ Table: "stocktake_orders", } + SyncFailureTable.Annotation = &entsql.Annotation{ + Table: "sync_failure", + } SysConfigTable.Annotation = &entsql.Annotation{ Table: "sys_config", } diff --git a/bj_power_wms/ent/mutation.go b/bj_power_wms/ent/mutation.go index c01ab94..279a854 100644 --- a/bj_power_wms/ent/mutation.go +++ b/bj_power_wms/ent/mutation.go @@ -27,6 +27,7 @@ import ( "bj_power_wms/ent/semifinished" "bj_power_wms/ent/stocktakeitem" "bj_power_wms/ent/stocktakeorder" + "bj_power_wms/ent/syncfailure" "bj_power_wms/ent/sysconfig" "bj_power_wms/ent/user" "bj_power_wms/ent/zone" @@ -72,6 +73,7 @@ const ( TypeSemiFinished = "SemiFinished" TypeStocktakeItem = "StocktakeItem" TypeStocktakeOrder = "StocktakeOrder" + TypeSyncFailure = "SyncFailure" TypeSysConfig = "SysConfig" TypeUser = "User" TypeZone = "Zone" @@ -29522,6 +29524,1034 @@ func (m *StocktakeOrderMutation) ResetEdge(name string) error { return fmt.Errorf("unknown StocktakeOrder edge %s", name) } +// SyncFailureMutation represents an operation that mutates the SyncFailure nodes in the graph. +type SyncFailureMutation struct { + config + op Op + typ string + id *int + direction *string + biz_type *string + biz_key *string + endpoint *string + payload_json *string + error_msg *string + idempotency_key *string + status *string + retry_count *int32 + addretry_count *int32 + created_at *int64 + addcreated_at *int64 + last_error_at *int64 + addlast_error_at *int64 + handled_by *string + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*SyncFailure, error) + predicates []predicate.SyncFailure +} + +var _ ent.Mutation = (*SyncFailureMutation)(nil) + +// syncfailureOption allows management of the mutation configuration using functional options. +type syncfailureOption func(*SyncFailureMutation) + +// newSyncFailureMutation creates new mutation for the SyncFailure entity. +func newSyncFailureMutation(c config, op Op, opts ...syncfailureOption) *SyncFailureMutation { + m := &SyncFailureMutation{ + config: c, + op: op, + typ: TypeSyncFailure, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withSyncFailureID sets the ID field of the mutation. +func withSyncFailureID(id int) syncfailureOption { + return func(m *SyncFailureMutation) { + var ( + err error + once sync.Once + value *SyncFailure + ) + m.oldValue = func(ctx context.Context) (*SyncFailure, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().SyncFailure.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withSyncFailure sets the old SyncFailure of the mutation. +func withSyncFailure(node *SyncFailure) syncfailureOption { + return func(m *SyncFailureMutation) { + m.oldValue = func(context.Context) (*SyncFailure, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m SyncFailureMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m SyncFailureMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of SyncFailure entities. +func (m *SyncFailureMutation) SetID(id int) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *SyncFailureMutation) ID() (id int, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *SyncFailureMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().SyncFailure.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetDirection sets the "direction" field. +func (m *SyncFailureMutation) SetDirection(s string) { + m.direction = &s +} + +// Direction returns the value of the "direction" field in the mutation. +func (m *SyncFailureMutation) Direction() (r string, exists bool) { + v := m.direction + if v == nil { + return + } + return *v, true +} + +// OldDirection returns the old "direction" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldDirection(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDirection is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDirection requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDirection: %w", err) + } + return oldValue.Direction, nil +} + +// ResetDirection resets all changes to the "direction" field. +func (m *SyncFailureMutation) ResetDirection() { + m.direction = nil +} + +// SetBizType sets the "biz_type" field. +func (m *SyncFailureMutation) SetBizType(s string) { + m.biz_type = &s +} + +// BizType returns the value of the "biz_type" field in the mutation. +func (m *SyncFailureMutation) BizType() (r string, exists bool) { + v := m.biz_type + if v == nil { + return + } + return *v, true +} + +// OldBizType returns the old "biz_type" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldBizType(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldBizType is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldBizType requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldBizType: %w", err) + } + return oldValue.BizType, nil +} + +// ResetBizType resets all changes to the "biz_type" field. +func (m *SyncFailureMutation) ResetBizType() { + m.biz_type = nil +} + +// SetBizKey sets the "biz_key" field. +func (m *SyncFailureMutation) SetBizKey(s string) { + m.biz_key = &s +} + +// BizKey returns the value of the "biz_key" field in the mutation. +func (m *SyncFailureMutation) BizKey() (r string, exists bool) { + v := m.biz_key + if v == nil { + return + } + return *v, true +} + +// OldBizKey returns the old "biz_key" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldBizKey(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldBizKey is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldBizKey requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldBizKey: %w", err) + } + return oldValue.BizKey, nil +} + +// ResetBizKey resets all changes to the "biz_key" field. +func (m *SyncFailureMutation) ResetBizKey() { + m.biz_key = nil +} + +// SetEndpoint sets the "endpoint" field. +func (m *SyncFailureMutation) SetEndpoint(s string) { + m.endpoint = &s +} + +// Endpoint returns the value of the "endpoint" field in the mutation. +func (m *SyncFailureMutation) Endpoint() (r string, exists bool) { + v := m.endpoint + if v == nil { + return + } + return *v, true +} + +// OldEndpoint returns the old "endpoint" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldEndpoint(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldEndpoint is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldEndpoint requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldEndpoint: %w", err) + } + return oldValue.Endpoint, nil +} + +// ResetEndpoint resets all changes to the "endpoint" field. +func (m *SyncFailureMutation) ResetEndpoint() { + m.endpoint = nil +} + +// SetPayloadJSON sets the "payload_json" field. +func (m *SyncFailureMutation) SetPayloadJSON(s string) { + m.payload_json = &s +} + +// PayloadJSON returns the value of the "payload_json" field in the mutation. +func (m *SyncFailureMutation) PayloadJSON() (r string, exists bool) { + v := m.payload_json + if v == nil { + return + } + return *v, true +} + +// OldPayloadJSON returns the old "payload_json" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldPayloadJSON(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPayloadJSON is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPayloadJSON requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPayloadJSON: %w", err) + } + return oldValue.PayloadJSON, nil +} + +// ResetPayloadJSON resets all changes to the "payload_json" field. +func (m *SyncFailureMutation) ResetPayloadJSON() { + m.payload_json = nil +} + +// SetErrorMsg sets the "error_msg" field. +func (m *SyncFailureMutation) SetErrorMsg(s string) { + m.error_msg = &s +} + +// ErrorMsg returns the value of the "error_msg" field in the mutation. +func (m *SyncFailureMutation) ErrorMsg() (r string, exists bool) { + v := m.error_msg + if v == nil { + return + } + return *v, true +} + +// OldErrorMsg returns the old "error_msg" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldErrorMsg(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldErrorMsg is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldErrorMsg requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldErrorMsg: %w", err) + } + return oldValue.ErrorMsg, nil +} + +// ResetErrorMsg resets all changes to the "error_msg" field. +func (m *SyncFailureMutation) ResetErrorMsg() { + m.error_msg = nil +} + +// SetIdempotencyKey sets the "idempotency_key" field. +func (m *SyncFailureMutation) SetIdempotencyKey(s string) { + m.idempotency_key = &s +} + +// IdempotencyKey returns the value of the "idempotency_key" field in the mutation. +func (m *SyncFailureMutation) IdempotencyKey() (r string, exists bool) { + v := m.idempotency_key + if v == nil { + return + } + return *v, true +} + +// OldIdempotencyKey returns the old "idempotency_key" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldIdempotencyKey(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldIdempotencyKey is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldIdempotencyKey requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldIdempotencyKey: %w", err) + } + return oldValue.IdempotencyKey, nil +} + +// ResetIdempotencyKey resets all changes to the "idempotency_key" field. +func (m *SyncFailureMutation) ResetIdempotencyKey() { + m.idempotency_key = nil +} + +// SetStatus sets the "status" field. +func (m *SyncFailureMutation) SetStatus(s string) { + m.status = &s +} + +// Status returns the value of the "status" field in the mutation. +func (m *SyncFailureMutation) Status() (r string, exists bool) { + v := m.status + if v == nil { + return + } + return *v, true +} + +// OldStatus returns the old "status" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldStatus(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStatus is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStatus requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStatus: %w", err) + } + return oldValue.Status, nil +} + +// ResetStatus resets all changes to the "status" field. +func (m *SyncFailureMutation) ResetStatus() { + m.status = nil +} + +// SetRetryCount sets the "retry_count" field. +func (m *SyncFailureMutation) SetRetryCount(i int32) { + m.retry_count = &i + m.addretry_count = nil +} + +// RetryCount returns the value of the "retry_count" field in the mutation. +func (m *SyncFailureMutation) RetryCount() (r int32, exists bool) { + v := m.retry_count + if v == nil { + return + } + return *v, true +} + +// OldRetryCount returns the old "retry_count" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldRetryCount(ctx context.Context) (v int32, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRetryCount is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRetryCount requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRetryCount: %w", err) + } + return oldValue.RetryCount, nil +} + +// AddRetryCount adds i to the "retry_count" field. +func (m *SyncFailureMutation) AddRetryCount(i int32) { + if m.addretry_count != nil { + *m.addretry_count += i + } else { + m.addretry_count = &i + } +} + +// AddedRetryCount returns the value that was added to the "retry_count" field in this mutation. +func (m *SyncFailureMutation) AddedRetryCount() (r int32, exists bool) { + v := m.addretry_count + if v == nil { + return + } + return *v, true +} + +// ResetRetryCount resets all changes to the "retry_count" field. +func (m *SyncFailureMutation) ResetRetryCount() { + m.retry_count = nil + m.addretry_count = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *SyncFailureMutation) SetCreatedAt(i int64) { + m.created_at = &i + m.addcreated_at = nil +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *SyncFailureMutation) CreatedAt() (r int64, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldCreatedAt(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// AddCreatedAt adds i to the "created_at" field. +func (m *SyncFailureMutation) AddCreatedAt(i int64) { + if m.addcreated_at != nil { + *m.addcreated_at += i + } else { + m.addcreated_at = &i + } +} + +// AddedCreatedAt returns the value that was added to the "created_at" field in this mutation. +func (m *SyncFailureMutation) AddedCreatedAt() (r int64, exists bool) { + v := m.addcreated_at + if v == nil { + return + } + return *v, true +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *SyncFailureMutation) ResetCreatedAt() { + m.created_at = nil + m.addcreated_at = nil +} + +// SetLastErrorAt sets the "last_error_at" field. +func (m *SyncFailureMutation) SetLastErrorAt(i int64) { + m.last_error_at = &i + m.addlast_error_at = nil +} + +// LastErrorAt returns the value of the "last_error_at" field in the mutation. +func (m *SyncFailureMutation) LastErrorAt() (r int64, exists bool) { + v := m.last_error_at + if v == nil { + return + } + return *v, true +} + +// OldLastErrorAt returns the old "last_error_at" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldLastErrorAt(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldLastErrorAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldLastErrorAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldLastErrorAt: %w", err) + } + return oldValue.LastErrorAt, nil +} + +// AddLastErrorAt adds i to the "last_error_at" field. +func (m *SyncFailureMutation) AddLastErrorAt(i int64) { + if m.addlast_error_at != nil { + *m.addlast_error_at += i + } else { + m.addlast_error_at = &i + } +} + +// AddedLastErrorAt returns the value that was added to the "last_error_at" field in this mutation. +func (m *SyncFailureMutation) AddedLastErrorAt() (r int64, exists bool) { + v := m.addlast_error_at + if v == nil { + return + } + return *v, true +} + +// ResetLastErrorAt resets all changes to the "last_error_at" field. +func (m *SyncFailureMutation) ResetLastErrorAt() { + m.last_error_at = nil + m.addlast_error_at = nil +} + +// SetHandledBy sets the "handled_by" field. +func (m *SyncFailureMutation) SetHandledBy(s string) { + m.handled_by = &s +} + +// HandledBy returns the value of the "handled_by" field in the mutation. +func (m *SyncFailureMutation) HandledBy() (r string, exists bool) { + v := m.handled_by + if v == nil { + return + } + return *v, true +} + +// OldHandledBy returns the old "handled_by" field's value of the SyncFailure entity. +// If the SyncFailure object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SyncFailureMutation) OldHandledBy(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldHandledBy is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldHandledBy requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldHandledBy: %w", err) + } + return oldValue.HandledBy, nil +} + +// ResetHandledBy resets all changes to the "handled_by" field. +func (m *SyncFailureMutation) ResetHandledBy() { + m.handled_by = nil +} + +// Where appends a list predicates to the SyncFailureMutation builder. +func (m *SyncFailureMutation) Where(ps ...predicate.SyncFailure) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the SyncFailureMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *SyncFailureMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.SyncFailure, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *SyncFailureMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *SyncFailureMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (SyncFailure). +func (m *SyncFailureMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *SyncFailureMutation) Fields() []string { + fields := make([]string, 0, 12) + if m.direction != nil { + fields = append(fields, syncfailure.FieldDirection) + } + if m.biz_type != nil { + fields = append(fields, syncfailure.FieldBizType) + } + if m.biz_key != nil { + fields = append(fields, syncfailure.FieldBizKey) + } + if m.endpoint != nil { + fields = append(fields, syncfailure.FieldEndpoint) + } + if m.payload_json != nil { + fields = append(fields, syncfailure.FieldPayloadJSON) + } + if m.error_msg != nil { + fields = append(fields, syncfailure.FieldErrorMsg) + } + if m.idempotency_key != nil { + fields = append(fields, syncfailure.FieldIdempotencyKey) + } + if m.status != nil { + fields = append(fields, syncfailure.FieldStatus) + } + if m.retry_count != nil { + fields = append(fields, syncfailure.FieldRetryCount) + } + if m.created_at != nil { + fields = append(fields, syncfailure.FieldCreatedAt) + } + if m.last_error_at != nil { + fields = append(fields, syncfailure.FieldLastErrorAt) + } + if m.handled_by != nil { + fields = append(fields, syncfailure.FieldHandledBy) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *SyncFailureMutation) Field(name string) (ent.Value, bool) { + switch name { + case syncfailure.FieldDirection: + return m.Direction() + case syncfailure.FieldBizType: + return m.BizType() + case syncfailure.FieldBizKey: + return m.BizKey() + case syncfailure.FieldEndpoint: + return m.Endpoint() + case syncfailure.FieldPayloadJSON: + return m.PayloadJSON() + case syncfailure.FieldErrorMsg: + return m.ErrorMsg() + case syncfailure.FieldIdempotencyKey: + return m.IdempotencyKey() + case syncfailure.FieldStatus: + return m.Status() + case syncfailure.FieldRetryCount: + return m.RetryCount() + case syncfailure.FieldCreatedAt: + return m.CreatedAt() + case syncfailure.FieldLastErrorAt: + return m.LastErrorAt() + case syncfailure.FieldHandledBy: + return m.HandledBy() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *SyncFailureMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case syncfailure.FieldDirection: + return m.OldDirection(ctx) + case syncfailure.FieldBizType: + return m.OldBizType(ctx) + case syncfailure.FieldBizKey: + return m.OldBizKey(ctx) + case syncfailure.FieldEndpoint: + return m.OldEndpoint(ctx) + case syncfailure.FieldPayloadJSON: + return m.OldPayloadJSON(ctx) + case syncfailure.FieldErrorMsg: + return m.OldErrorMsg(ctx) + case syncfailure.FieldIdempotencyKey: + return m.OldIdempotencyKey(ctx) + case syncfailure.FieldStatus: + return m.OldStatus(ctx) + case syncfailure.FieldRetryCount: + return m.OldRetryCount(ctx) + case syncfailure.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case syncfailure.FieldLastErrorAt: + return m.OldLastErrorAt(ctx) + case syncfailure.FieldHandledBy: + return m.OldHandledBy(ctx) + } + return nil, fmt.Errorf("unknown SyncFailure field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *SyncFailureMutation) SetField(name string, value ent.Value) error { + switch name { + case syncfailure.FieldDirection: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDirection(v) + return nil + case syncfailure.FieldBizType: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetBizType(v) + return nil + case syncfailure.FieldBizKey: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetBizKey(v) + return nil + case syncfailure.FieldEndpoint: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetEndpoint(v) + return nil + case syncfailure.FieldPayloadJSON: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPayloadJSON(v) + return nil + case syncfailure.FieldErrorMsg: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetErrorMsg(v) + return nil + case syncfailure.FieldIdempotencyKey: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetIdempotencyKey(v) + return nil + case syncfailure.FieldStatus: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStatus(v) + return nil + case syncfailure.FieldRetryCount: + v, ok := value.(int32) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRetryCount(v) + return nil + case syncfailure.FieldCreatedAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case syncfailure.FieldLastErrorAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetLastErrorAt(v) + return nil + case syncfailure.FieldHandledBy: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetHandledBy(v) + return nil + } + return fmt.Errorf("unknown SyncFailure field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *SyncFailureMutation) AddedFields() []string { + var fields []string + if m.addretry_count != nil { + fields = append(fields, syncfailure.FieldRetryCount) + } + if m.addcreated_at != nil { + fields = append(fields, syncfailure.FieldCreatedAt) + } + if m.addlast_error_at != nil { + fields = append(fields, syncfailure.FieldLastErrorAt) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *SyncFailureMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case syncfailure.FieldRetryCount: + return m.AddedRetryCount() + case syncfailure.FieldCreatedAt: + return m.AddedCreatedAt() + case syncfailure.FieldLastErrorAt: + return m.AddedLastErrorAt() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *SyncFailureMutation) AddField(name string, value ent.Value) error { + switch name { + case syncfailure.FieldRetryCount: + v, ok := value.(int32) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddRetryCount(v) + return nil + case syncfailure.FieldCreatedAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddCreatedAt(v) + return nil + case syncfailure.FieldLastErrorAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddLastErrorAt(v) + return nil + } + return fmt.Errorf("unknown SyncFailure numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *SyncFailureMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *SyncFailureMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *SyncFailureMutation) ClearField(name string) error { + return fmt.Errorf("unknown SyncFailure nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *SyncFailureMutation) ResetField(name string) error { + switch name { + case syncfailure.FieldDirection: + m.ResetDirection() + return nil + case syncfailure.FieldBizType: + m.ResetBizType() + return nil + case syncfailure.FieldBizKey: + m.ResetBizKey() + return nil + case syncfailure.FieldEndpoint: + m.ResetEndpoint() + return nil + case syncfailure.FieldPayloadJSON: + m.ResetPayloadJSON() + return nil + case syncfailure.FieldErrorMsg: + m.ResetErrorMsg() + return nil + case syncfailure.FieldIdempotencyKey: + m.ResetIdempotencyKey() + return nil + case syncfailure.FieldStatus: + m.ResetStatus() + return nil + case syncfailure.FieldRetryCount: + m.ResetRetryCount() + return nil + case syncfailure.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case syncfailure.FieldLastErrorAt: + m.ResetLastErrorAt() + return nil + case syncfailure.FieldHandledBy: + m.ResetHandledBy() + return nil + } + return fmt.Errorf("unknown SyncFailure field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *SyncFailureMutation) AddedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *SyncFailureMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *SyncFailureMutation) RemovedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *SyncFailureMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *SyncFailureMutation) ClearedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *SyncFailureMutation) EdgeCleared(name string) bool { + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *SyncFailureMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown SyncFailure unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *SyncFailureMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown SyncFailure edge %s", name) +} + // SysConfigMutation represents an operation that mutates the SysConfig nodes in the graph. type SysConfigMutation struct { config diff --git a/bj_power_wms/ent/predicate/predicate.go b/bj_power_wms/ent/predicate/predicate.go index 9990b05..2fdc99f 100644 --- a/bj_power_wms/ent/predicate/predicate.go +++ b/bj_power_wms/ent/predicate/predicate.go @@ -75,6 +75,9 @@ type StocktakeItem func(*sql.Selector) // StocktakeOrder is the predicate function for stocktakeorder builders. type StocktakeOrder func(*sql.Selector) +// SyncFailure is the predicate function for syncfailure builders. +type SyncFailure func(*sql.Selector) + // SysConfig is the predicate function for sysconfig builders. type SysConfig func(*sql.Selector) diff --git a/bj_power_wms/ent/runtime.go b/bj_power_wms/ent/runtime.go index 23db167..52a93bb 100644 --- a/bj_power_wms/ent/runtime.go +++ b/bj_power_wms/ent/runtime.go @@ -26,6 +26,7 @@ import ( "bj_power_wms/ent/semifinished" "bj_power_wms/ent/stocktakeitem" "bj_power_wms/ent/stocktakeorder" + "bj_power_wms/ent/syncfailure" "bj_power_wms/ent/sysconfig" "bj_power_wms/ent/user" "bj_power_wms/ent/zone" @@ -825,6 +826,56 @@ func init() { stocktakeorderDescCreatedAt := stocktakeorderFields[11].Descriptor() // stocktakeorder.DefaultCreatedAt holds the default value on creation for the created_at field. stocktakeorder.DefaultCreatedAt = stocktakeorderDescCreatedAt.Default.(func() int64) + syncfailureFields := schema.SyncFailure{}.Fields() + _ = syncfailureFields + // syncfailureDescDirection is the schema descriptor for direction field. + syncfailureDescDirection := syncfailureFields[1].Descriptor() + // syncfailure.DefaultDirection holds the default value on creation for the direction field. + syncfailure.DefaultDirection = syncfailureDescDirection.Default.(string) + // syncfailureDescBizType is the schema descriptor for biz_type field. + syncfailureDescBizType := syncfailureFields[2].Descriptor() + // syncfailure.DefaultBizType holds the default value on creation for the biz_type field. + syncfailure.DefaultBizType = syncfailureDescBizType.Default.(string) + // syncfailureDescBizKey is the schema descriptor for biz_key field. + syncfailureDescBizKey := syncfailureFields[3].Descriptor() + // syncfailure.DefaultBizKey holds the default value on creation for the biz_key field. + syncfailure.DefaultBizKey = syncfailureDescBizKey.Default.(string) + // syncfailureDescEndpoint is the schema descriptor for endpoint field. + syncfailureDescEndpoint := syncfailureFields[4].Descriptor() + // syncfailure.DefaultEndpoint holds the default value on creation for the endpoint field. + syncfailure.DefaultEndpoint = syncfailureDescEndpoint.Default.(string) + // syncfailureDescPayloadJSON is the schema descriptor for payload_json field. + syncfailureDescPayloadJSON := syncfailureFields[5].Descriptor() + // syncfailure.DefaultPayloadJSON holds the default value on creation for the payload_json field. + syncfailure.DefaultPayloadJSON = syncfailureDescPayloadJSON.Default.(string) + // syncfailureDescErrorMsg is the schema descriptor for error_msg field. + syncfailureDescErrorMsg := syncfailureFields[6].Descriptor() + // syncfailure.DefaultErrorMsg holds the default value on creation for the error_msg field. + syncfailure.DefaultErrorMsg = syncfailureDescErrorMsg.Default.(string) + // syncfailureDescStatus is the schema descriptor for status field. + syncfailureDescStatus := syncfailureFields[8].Descriptor() + // syncfailure.DefaultStatus holds the default value on creation for the status field. + syncfailure.DefaultStatus = syncfailureDescStatus.Default.(string) + // syncfailureDescRetryCount is the schema descriptor for retry_count field. + syncfailureDescRetryCount := syncfailureFields[9].Descriptor() + // syncfailure.DefaultRetryCount holds the default value on creation for the retry_count field. + syncfailure.DefaultRetryCount = syncfailureDescRetryCount.Default.(int32) + // syncfailureDescCreatedAt is the schema descriptor for created_at field. + syncfailureDescCreatedAt := syncfailureFields[10].Descriptor() + // syncfailure.DefaultCreatedAt holds the default value on creation for the created_at field. + syncfailure.DefaultCreatedAt = syncfailureDescCreatedAt.Default.(int64) + // syncfailureDescLastErrorAt is the schema descriptor for last_error_at field. + syncfailureDescLastErrorAt := syncfailureFields[11].Descriptor() + // syncfailure.DefaultLastErrorAt holds the default value on creation for the last_error_at field. + syncfailure.DefaultLastErrorAt = syncfailureDescLastErrorAt.Default.(int64) + // syncfailureDescHandledBy is the schema descriptor for handled_by field. + syncfailureDescHandledBy := syncfailureFields[12].Descriptor() + // syncfailure.DefaultHandledBy holds the default value on creation for the handled_by field. + syncfailure.DefaultHandledBy = syncfailureDescHandledBy.Default.(string) + // syncfailureDescID is the schema descriptor for id field. + syncfailureDescID := syncfailureFields[0].Descriptor() + // syncfailure.IDValidator is a validator for the "id" field. It is called by the builders before save. + syncfailure.IDValidator = syncfailureDescID.Validators[0].(func(int) error) sysconfigFields := schema.SysConfig{}.Fields() _ = sysconfigFields // sysconfigDescKey is the schema descriptor for key field. diff --git a/bj_power_wms/ent/syncfailure.go b/bj_power_wms/ent/syncfailure.go new file mode 100644 index 0000000..1441167 --- /dev/null +++ b/bj_power_wms/ent/syncfailure.go @@ -0,0 +1,224 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_wms/ent/syncfailure" + "fmt" + "strings" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" +) + +// SyncFailure 跨系统调用失败台账:本地已提交、对端通知失败,人工确认后重试 +type SyncFailure struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // 调用方向,如 mes>wms / wms>mes + Direction string `json:"direction,omitempty"` + // 业务类型,如 material.sync + BizType string `json:"bizType,omitempty"` + // 业务主键 + BizKey string `json:"bizKey,omitempty"` + // 重试时原样重放的对端地址 + Endpoint string `json:"endpoint,omitempty"` + // 通知载荷(JSON) + PayloadJSON string `json:"payloadJson,omitempty"` + // 失败原因 + ErrorMsg string `json:"errorMsg,omitempty"` + // 幂等键 direction|biz_type|biz_key + IdempotencyKey string `json:"idempotencyKey,omitempty"` + // PENDING/SUCCESS/DEAD + Status string `json:"status,omitempty"` + // 重试次数 + RetryCount int32 `json:"retryCount,omitempty"` + // 首次失败时刻(unix秒) + CreatedAt int64 `json:"createdAt,omitempty"` + // 最近失败时刻(unix秒) + LastErrorAt int64 `json:"lastErrorAt,omitempty"` + // 人工置 DEAD 的操作人 + HandledBy string `json:"handledBy,omitempty"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*SyncFailure) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case syncfailure.FieldID, syncfailure.FieldRetryCount, syncfailure.FieldCreatedAt, syncfailure.FieldLastErrorAt: + values[i] = new(sql.NullInt64) + case syncfailure.FieldDirection, syncfailure.FieldBizType, syncfailure.FieldBizKey, syncfailure.FieldEndpoint, syncfailure.FieldPayloadJSON, syncfailure.FieldErrorMsg, syncfailure.FieldIdempotencyKey, syncfailure.FieldStatus, syncfailure.FieldHandledBy: + 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 SyncFailure fields. +func (_m *SyncFailure) 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 syncfailure.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + _m.ID = int(value.Int64) + case syncfailure.FieldDirection: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field direction", values[i]) + } else if value.Valid { + _m.Direction = value.String + } + case syncfailure.FieldBizType: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field biz_type", values[i]) + } else if value.Valid { + _m.BizType = value.String + } + case syncfailure.FieldBizKey: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field biz_key", values[i]) + } else if value.Valid { + _m.BizKey = value.String + } + case syncfailure.FieldEndpoint: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field endpoint", values[i]) + } else if value.Valid { + _m.Endpoint = value.String + } + case syncfailure.FieldPayloadJSON: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field payload_json", values[i]) + } else if value.Valid { + _m.PayloadJSON = value.String + } + case syncfailure.FieldErrorMsg: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field error_msg", values[i]) + } else if value.Valid { + _m.ErrorMsg = value.String + } + case syncfailure.FieldIdempotencyKey: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field idempotency_key", values[i]) + } else if value.Valid { + _m.IdempotencyKey = value.String + } + case syncfailure.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 = value.String + } + case syncfailure.FieldRetryCount: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field retry_count", values[i]) + } else if value.Valid { + _m.RetryCount = int32(value.Int64) + } + case syncfailure.FieldCreatedAt: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + _m.CreatedAt = value.Int64 + } + case syncfailure.FieldLastErrorAt: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field last_error_at", values[i]) + } else if value.Valid { + _m.LastErrorAt = value.Int64 + } + case syncfailure.FieldHandledBy: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field handled_by", values[i]) + } else if value.Valid { + _m.HandledBy = 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 SyncFailure. +// This includes values selected through modifiers, order, etc. +func (_m *SyncFailure) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// Update returns a builder for updating this SyncFailure. +// Note that you need to call SyncFailure.Unwrap() before calling this method if this SyncFailure +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *SyncFailure) Update() *SyncFailureUpdateOne { + return NewSyncFailureClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the SyncFailure 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 *SyncFailure) Unwrap() *SyncFailure { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: SyncFailure is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *SyncFailure) String() string { + var builder strings.Builder + builder.WriteString("SyncFailure(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("direction=") + builder.WriteString(_m.Direction) + builder.WriteString(", ") + builder.WriteString("biz_type=") + builder.WriteString(_m.BizType) + builder.WriteString(", ") + builder.WriteString("biz_key=") + builder.WriteString(_m.BizKey) + builder.WriteString(", ") + builder.WriteString("endpoint=") + builder.WriteString(_m.Endpoint) + builder.WriteString(", ") + builder.WriteString("payload_json=") + builder.WriteString(_m.PayloadJSON) + builder.WriteString(", ") + builder.WriteString("error_msg=") + builder.WriteString(_m.ErrorMsg) + builder.WriteString(", ") + builder.WriteString("idempotency_key=") + builder.WriteString(_m.IdempotencyKey) + builder.WriteString(", ") + builder.WriteString("status=") + builder.WriteString(_m.Status) + builder.WriteString(", ") + builder.WriteString("retry_count=") + builder.WriteString(fmt.Sprintf("%v", _m.RetryCount)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(fmt.Sprintf("%v", _m.CreatedAt)) + builder.WriteString(", ") + builder.WriteString("last_error_at=") + builder.WriteString(fmt.Sprintf("%v", _m.LastErrorAt)) + builder.WriteString(", ") + builder.WriteString("handled_by=") + builder.WriteString(_m.HandledBy) + builder.WriteByte(')') + return builder.String() +} + +// SyncFailures is a parsable slice of SyncFailure. +type SyncFailures []*SyncFailure diff --git a/bj_power_wms/ent/syncfailure/syncfailure.go b/bj_power_wms/ent/syncfailure/syncfailure.go new file mode 100644 index 0000000..3dd02a5 --- /dev/null +++ b/bj_power_wms/ent/syncfailure/syncfailure.go @@ -0,0 +1,162 @@ +// Code generated by ent, DO NOT EDIT. + +package syncfailure + +import ( + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the syncfailure type in the database. + Label = "sync_failure" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldDirection holds the string denoting the direction field in the database. + FieldDirection = "direction" + // FieldBizType holds the string denoting the biz_type field in the database. + FieldBizType = "biz_type" + // FieldBizKey holds the string denoting the biz_key field in the database. + FieldBizKey = "biz_key" + // FieldEndpoint holds the string denoting the endpoint field in the database. + FieldEndpoint = "endpoint" + // FieldPayloadJSON holds the string denoting the payload_json field in the database. + FieldPayloadJSON = "payload_json" + // FieldErrorMsg holds the string denoting the error_msg field in the database. + FieldErrorMsg = "error_msg" + // FieldIdempotencyKey holds the string denoting the idempotency_key field in the database. + FieldIdempotencyKey = "idempotency_key" + // FieldStatus holds the string denoting the status field in the database. + FieldStatus = "status" + // FieldRetryCount holds the string denoting the retry_count field in the database. + FieldRetryCount = "retry_count" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldLastErrorAt holds the string denoting the last_error_at field in the database. + FieldLastErrorAt = "last_error_at" + // FieldHandledBy holds the string denoting the handled_by field in the database. + FieldHandledBy = "handled_by" + // Table holds the table name of the syncfailure in the database. + Table = "sync_failure" +) + +// Columns holds all SQL columns for syncfailure fields. +var Columns = []string{ + FieldID, + FieldDirection, + FieldBizType, + FieldBizKey, + FieldEndpoint, + FieldPayloadJSON, + FieldErrorMsg, + FieldIdempotencyKey, + FieldStatus, + FieldRetryCount, + FieldCreatedAt, + FieldLastErrorAt, + FieldHandledBy, +} + +// 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 +} + +var ( + // DefaultDirection holds the default value on creation for the "direction" field. + DefaultDirection string + // DefaultBizType holds the default value on creation for the "biz_type" field. + DefaultBizType string + // DefaultBizKey holds the default value on creation for the "biz_key" field. + DefaultBizKey string + // DefaultEndpoint holds the default value on creation for the "endpoint" field. + DefaultEndpoint string + // DefaultPayloadJSON holds the default value on creation for the "payload_json" field. + DefaultPayloadJSON string + // DefaultErrorMsg holds the default value on creation for the "error_msg" field. + DefaultErrorMsg string + // DefaultStatus holds the default value on creation for the "status" field. + DefaultStatus string + // DefaultRetryCount holds the default value on creation for the "retry_count" field. + DefaultRetryCount int32 + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt int64 + // DefaultLastErrorAt holds the default value on creation for the "last_error_at" field. + DefaultLastErrorAt int64 + // DefaultHandledBy holds the default value on creation for the "handled_by" field. + DefaultHandledBy string + // IDValidator is a validator for the "id" field. It is called by the builders before save. + IDValidator func(int) error +) + +// OrderOption defines the ordering options for the SyncFailure 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() +} + +// ByDirection orders the results by the direction field. +func ByDirection(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDirection, opts...).ToFunc() +} + +// ByBizType orders the results by the biz_type field. +func ByBizType(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldBizType, opts...).ToFunc() +} + +// ByBizKey orders the results by the biz_key field. +func ByBizKey(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldBizKey, opts...).ToFunc() +} + +// ByEndpoint orders the results by the endpoint field. +func ByEndpoint(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldEndpoint, opts...).ToFunc() +} + +// ByPayloadJSON orders the results by the payload_json field. +func ByPayloadJSON(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPayloadJSON, opts...).ToFunc() +} + +// ByErrorMsg orders the results by the error_msg field. +func ByErrorMsg(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldErrorMsg, opts...).ToFunc() +} + +// ByIdempotencyKey orders the results by the idempotency_key field. +func ByIdempotencyKey(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIdempotencyKey, opts...).ToFunc() +} + +// ByStatus orders the results by the status field. +func ByStatus(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStatus, opts...).ToFunc() +} + +// ByRetryCount orders the results by the retry_count field. +func ByRetryCount(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRetryCount, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByLastErrorAt orders the results by the last_error_at field. +func ByLastErrorAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldLastErrorAt, opts...).ToFunc() +} + +// ByHandledBy orders the results by the handled_by field. +func ByHandledBy(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldHandledBy, opts...).ToFunc() +} diff --git a/bj_power_wms/ent/syncfailure/where.go b/bj_power_wms/ent/syncfailure/where.go new file mode 100644 index 0000000..5f1a308 --- /dev/null +++ b/bj_power_wms/ent/syncfailure/where.go @@ -0,0 +1,834 @@ +// Code generated by ent, DO NOT EDIT. + +package syncfailure + +import ( + "bj_power_wms/ent/predicate" + + "entgo.io/ent/dialect/sql" +) + +// ID filters vertices based on their ID field. +func ID(id int) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldID, id)) +} + +// Direction applies equality check predicate on the "direction" field. It's identical to DirectionEQ. +func Direction(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldDirection, v)) +} + +// BizType applies equality check predicate on the "biz_type" field. It's identical to BizTypeEQ. +func BizType(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldBizType, v)) +} + +// BizKey applies equality check predicate on the "biz_key" field. It's identical to BizKeyEQ. +func BizKey(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldBizKey, v)) +} + +// Endpoint applies equality check predicate on the "endpoint" field. It's identical to EndpointEQ. +func Endpoint(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldEndpoint, v)) +} + +// PayloadJSON applies equality check predicate on the "payload_json" field. It's identical to PayloadJSONEQ. +func PayloadJSON(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldPayloadJSON, v)) +} + +// ErrorMsg applies equality check predicate on the "error_msg" field. It's identical to ErrorMsgEQ. +func ErrorMsg(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldErrorMsg, v)) +} + +// IdempotencyKey applies equality check predicate on the "idempotency_key" field. It's identical to IdempotencyKeyEQ. +func IdempotencyKey(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldIdempotencyKey, v)) +} + +// Status applies equality check predicate on the "status" field. It's identical to StatusEQ. +func Status(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldStatus, v)) +} + +// RetryCount applies equality check predicate on the "retry_count" field. It's identical to RetryCountEQ. +func RetryCount(v int32) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldRetryCount, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldCreatedAt, v)) +} + +// LastErrorAt applies equality check predicate on the "last_error_at" field. It's identical to LastErrorAtEQ. +func LastErrorAt(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldLastErrorAt, v)) +} + +// HandledBy applies equality check predicate on the "handled_by" field. It's identical to HandledByEQ. +func HandledBy(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldHandledBy, v)) +} + +// DirectionEQ applies the EQ predicate on the "direction" field. +func DirectionEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldDirection, v)) +} + +// DirectionNEQ applies the NEQ predicate on the "direction" field. +func DirectionNEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldDirection, v)) +} + +// DirectionIn applies the In predicate on the "direction" field. +func DirectionIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldDirection, vs...)) +} + +// DirectionNotIn applies the NotIn predicate on the "direction" field. +func DirectionNotIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldDirection, vs...)) +} + +// DirectionGT applies the GT predicate on the "direction" field. +func DirectionGT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldDirection, v)) +} + +// DirectionGTE applies the GTE predicate on the "direction" field. +func DirectionGTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldDirection, v)) +} + +// DirectionLT applies the LT predicate on the "direction" field. +func DirectionLT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldDirection, v)) +} + +// DirectionLTE applies the LTE predicate on the "direction" field. +func DirectionLTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldDirection, v)) +} + +// DirectionContains applies the Contains predicate on the "direction" field. +func DirectionContains(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContains(FieldDirection, v)) +} + +// DirectionHasPrefix applies the HasPrefix predicate on the "direction" field. +func DirectionHasPrefix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasPrefix(FieldDirection, v)) +} + +// DirectionHasSuffix applies the HasSuffix predicate on the "direction" field. +func DirectionHasSuffix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasSuffix(FieldDirection, v)) +} + +// DirectionEqualFold applies the EqualFold predicate on the "direction" field. +func DirectionEqualFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEqualFold(FieldDirection, v)) +} + +// DirectionContainsFold applies the ContainsFold predicate on the "direction" field. +func DirectionContainsFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContainsFold(FieldDirection, v)) +} + +// BizTypeEQ applies the EQ predicate on the "biz_type" field. +func BizTypeEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldBizType, v)) +} + +// BizTypeNEQ applies the NEQ predicate on the "biz_type" field. +func BizTypeNEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldBizType, v)) +} + +// BizTypeIn applies the In predicate on the "biz_type" field. +func BizTypeIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldBizType, vs...)) +} + +// BizTypeNotIn applies the NotIn predicate on the "biz_type" field. +func BizTypeNotIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldBizType, vs...)) +} + +// BizTypeGT applies the GT predicate on the "biz_type" field. +func BizTypeGT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldBizType, v)) +} + +// BizTypeGTE applies the GTE predicate on the "biz_type" field. +func BizTypeGTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldBizType, v)) +} + +// BizTypeLT applies the LT predicate on the "biz_type" field. +func BizTypeLT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldBizType, v)) +} + +// BizTypeLTE applies the LTE predicate on the "biz_type" field. +func BizTypeLTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldBizType, v)) +} + +// BizTypeContains applies the Contains predicate on the "biz_type" field. +func BizTypeContains(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContains(FieldBizType, v)) +} + +// BizTypeHasPrefix applies the HasPrefix predicate on the "biz_type" field. +func BizTypeHasPrefix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasPrefix(FieldBizType, v)) +} + +// BizTypeHasSuffix applies the HasSuffix predicate on the "biz_type" field. +func BizTypeHasSuffix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasSuffix(FieldBizType, v)) +} + +// BizTypeEqualFold applies the EqualFold predicate on the "biz_type" field. +func BizTypeEqualFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEqualFold(FieldBizType, v)) +} + +// BizTypeContainsFold applies the ContainsFold predicate on the "biz_type" field. +func BizTypeContainsFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContainsFold(FieldBizType, v)) +} + +// BizKeyEQ applies the EQ predicate on the "biz_key" field. +func BizKeyEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldBizKey, v)) +} + +// BizKeyNEQ applies the NEQ predicate on the "biz_key" field. +func BizKeyNEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldBizKey, v)) +} + +// BizKeyIn applies the In predicate on the "biz_key" field. +func BizKeyIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldBizKey, vs...)) +} + +// BizKeyNotIn applies the NotIn predicate on the "biz_key" field. +func BizKeyNotIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldBizKey, vs...)) +} + +// BizKeyGT applies the GT predicate on the "biz_key" field. +func BizKeyGT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldBizKey, v)) +} + +// BizKeyGTE applies the GTE predicate on the "biz_key" field. +func BizKeyGTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldBizKey, v)) +} + +// BizKeyLT applies the LT predicate on the "biz_key" field. +func BizKeyLT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldBizKey, v)) +} + +// BizKeyLTE applies the LTE predicate on the "biz_key" field. +func BizKeyLTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldBizKey, v)) +} + +// BizKeyContains applies the Contains predicate on the "biz_key" field. +func BizKeyContains(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContains(FieldBizKey, v)) +} + +// BizKeyHasPrefix applies the HasPrefix predicate on the "biz_key" field. +func BizKeyHasPrefix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasPrefix(FieldBizKey, v)) +} + +// BizKeyHasSuffix applies the HasSuffix predicate on the "biz_key" field. +func BizKeyHasSuffix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasSuffix(FieldBizKey, v)) +} + +// BizKeyEqualFold applies the EqualFold predicate on the "biz_key" field. +func BizKeyEqualFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEqualFold(FieldBizKey, v)) +} + +// BizKeyContainsFold applies the ContainsFold predicate on the "biz_key" field. +func BizKeyContainsFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContainsFold(FieldBizKey, v)) +} + +// EndpointEQ applies the EQ predicate on the "endpoint" field. +func EndpointEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldEndpoint, v)) +} + +// EndpointNEQ applies the NEQ predicate on the "endpoint" field. +func EndpointNEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldEndpoint, v)) +} + +// EndpointIn applies the In predicate on the "endpoint" field. +func EndpointIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldEndpoint, vs...)) +} + +// EndpointNotIn applies the NotIn predicate on the "endpoint" field. +func EndpointNotIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldEndpoint, vs...)) +} + +// EndpointGT applies the GT predicate on the "endpoint" field. +func EndpointGT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldEndpoint, v)) +} + +// EndpointGTE applies the GTE predicate on the "endpoint" field. +func EndpointGTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldEndpoint, v)) +} + +// EndpointLT applies the LT predicate on the "endpoint" field. +func EndpointLT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldEndpoint, v)) +} + +// EndpointLTE applies the LTE predicate on the "endpoint" field. +func EndpointLTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldEndpoint, v)) +} + +// EndpointContains applies the Contains predicate on the "endpoint" field. +func EndpointContains(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContains(FieldEndpoint, v)) +} + +// EndpointHasPrefix applies the HasPrefix predicate on the "endpoint" field. +func EndpointHasPrefix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasPrefix(FieldEndpoint, v)) +} + +// EndpointHasSuffix applies the HasSuffix predicate on the "endpoint" field. +func EndpointHasSuffix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasSuffix(FieldEndpoint, v)) +} + +// EndpointEqualFold applies the EqualFold predicate on the "endpoint" field. +func EndpointEqualFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEqualFold(FieldEndpoint, v)) +} + +// EndpointContainsFold applies the ContainsFold predicate on the "endpoint" field. +func EndpointContainsFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContainsFold(FieldEndpoint, v)) +} + +// PayloadJSONEQ applies the EQ predicate on the "payload_json" field. +func PayloadJSONEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldPayloadJSON, v)) +} + +// PayloadJSONNEQ applies the NEQ predicate on the "payload_json" field. +func PayloadJSONNEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldPayloadJSON, v)) +} + +// PayloadJSONIn applies the In predicate on the "payload_json" field. +func PayloadJSONIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldPayloadJSON, vs...)) +} + +// PayloadJSONNotIn applies the NotIn predicate on the "payload_json" field. +func PayloadJSONNotIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldPayloadJSON, vs...)) +} + +// PayloadJSONGT applies the GT predicate on the "payload_json" field. +func PayloadJSONGT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldPayloadJSON, v)) +} + +// PayloadJSONGTE applies the GTE predicate on the "payload_json" field. +func PayloadJSONGTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldPayloadJSON, v)) +} + +// PayloadJSONLT applies the LT predicate on the "payload_json" field. +func PayloadJSONLT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldPayloadJSON, v)) +} + +// PayloadJSONLTE applies the LTE predicate on the "payload_json" field. +func PayloadJSONLTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldPayloadJSON, v)) +} + +// PayloadJSONContains applies the Contains predicate on the "payload_json" field. +func PayloadJSONContains(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContains(FieldPayloadJSON, v)) +} + +// PayloadJSONHasPrefix applies the HasPrefix predicate on the "payload_json" field. +func PayloadJSONHasPrefix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasPrefix(FieldPayloadJSON, v)) +} + +// PayloadJSONHasSuffix applies the HasSuffix predicate on the "payload_json" field. +func PayloadJSONHasSuffix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasSuffix(FieldPayloadJSON, v)) +} + +// PayloadJSONEqualFold applies the EqualFold predicate on the "payload_json" field. +func PayloadJSONEqualFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEqualFold(FieldPayloadJSON, v)) +} + +// PayloadJSONContainsFold applies the ContainsFold predicate on the "payload_json" field. +func PayloadJSONContainsFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContainsFold(FieldPayloadJSON, v)) +} + +// ErrorMsgEQ applies the EQ predicate on the "error_msg" field. +func ErrorMsgEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldErrorMsg, v)) +} + +// ErrorMsgNEQ applies the NEQ predicate on the "error_msg" field. +func ErrorMsgNEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldErrorMsg, v)) +} + +// ErrorMsgIn applies the In predicate on the "error_msg" field. +func ErrorMsgIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldErrorMsg, vs...)) +} + +// ErrorMsgNotIn applies the NotIn predicate on the "error_msg" field. +func ErrorMsgNotIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldErrorMsg, vs...)) +} + +// ErrorMsgGT applies the GT predicate on the "error_msg" field. +func ErrorMsgGT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldErrorMsg, v)) +} + +// ErrorMsgGTE applies the GTE predicate on the "error_msg" field. +func ErrorMsgGTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldErrorMsg, v)) +} + +// ErrorMsgLT applies the LT predicate on the "error_msg" field. +func ErrorMsgLT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldErrorMsg, v)) +} + +// ErrorMsgLTE applies the LTE predicate on the "error_msg" field. +func ErrorMsgLTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldErrorMsg, v)) +} + +// ErrorMsgContains applies the Contains predicate on the "error_msg" field. +func ErrorMsgContains(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContains(FieldErrorMsg, v)) +} + +// ErrorMsgHasPrefix applies the HasPrefix predicate on the "error_msg" field. +func ErrorMsgHasPrefix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasPrefix(FieldErrorMsg, v)) +} + +// ErrorMsgHasSuffix applies the HasSuffix predicate on the "error_msg" field. +func ErrorMsgHasSuffix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasSuffix(FieldErrorMsg, v)) +} + +// ErrorMsgEqualFold applies the EqualFold predicate on the "error_msg" field. +func ErrorMsgEqualFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEqualFold(FieldErrorMsg, v)) +} + +// ErrorMsgContainsFold applies the ContainsFold predicate on the "error_msg" field. +func ErrorMsgContainsFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContainsFold(FieldErrorMsg, v)) +} + +// IdempotencyKeyEQ applies the EQ predicate on the "idempotency_key" field. +func IdempotencyKeyEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyNEQ applies the NEQ predicate on the "idempotency_key" field. +func IdempotencyKeyNEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyIn applies the In predicate on the "idempotency_key" field. +func IdempotencyKeyIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldIdempotencyKey, vs...)) +} + +// IdempotencyKeyNotIn applies the NotIn predicate on the "idempotency_key" field. +func IdempotencyKeyNotIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldIdempotencyKey, vs...)) +} + +// IdempotencyKeyGT applies the GT predicate on the "idempotency_key" field. +func IdempotencyKeyGT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyGTE applies the GTE predicate on the "idempotency_key" field. +func IdempotencyKeyGTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyLT applies the LT predicate on the "idempotency_key" field. +func IdempotencyKeyLT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyLTE applies the LTE predicate on the "idempotency_key" field. +func IdempotencyKeyLTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyContains applies the Contains predicate on the "idempotency_key" field. +func IdempotencyKeyContains(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContains(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyHasPrefix applies the HasPrefix predicate on the "idempotency_key" field. +func IdempotencyKeyHasPrefix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasPrefix(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyHasSuffix applies the HasSuffix predicate on the "idempotency_key" field. +func IdempotencyKeyHasSuffix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasSuffix(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyEqualFold applies the EqualFold predicate on the "idempotency_key" field. +func IdempotencyKeyEqualFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEqualFold(FieldIdempotencyKey, v)) +} + +// IdempotencyKeyContainsFold applies the ContainsFold predicate on the "idempotency_key" field. +func IdempotencyKeyContainsFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContainsFold(FieldIdempotencyKey, v)) +} + +// StatusEQ applies the EQ predicate on the "status" field. +func StatusEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldStatus, v)) +} + +// StatusNEQ applies the NEQ predicate on the "status" field. +func StatusNEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldStatus, v)) +} + +// StatusIn applies the In predicate on the "status" field. +func StatusIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldStatus, vs...)) +} + +// StatusNotIn applies the NotIn predicate on the "status" field. +func StatusNotIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldStatus, vs...)) +} + +// StatusGT applies the GT predicate on the "status" field. +func StatusGT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldStatus, v)) +} + +// StatusGTE applies the GTE predicate on the "status" field. +func StatusGTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldStatus, v)) +} + +// StatusLT applies the LT predicate on the "status" field. +func StatusLT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldStatus, v)) +} + +// StatusLTE applies the LTE predicate on the "status" field. +func StatusLTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldStatus, v)) +} + +// StatusContains applies the Contains predicate on the "status" field. +func StatusContains(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContains(FieldStatus, v)) +} + +// StatusHasPrefix applies the HasPrefix predicate on the "status" field. +func StatusHasPrefix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasPrefix(FieldStatus, v)) +} + +// StatusHasSuffix applies the HasSuffix predicate on the "status" field. +func StatusHasSuffix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasSuffix(FieldStatus, v)) +} + +// StatusEqualFold applies the EqualFold predicate on the "status" field. +func StatusEqualFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEqualFold(FieldStatus, v)) +} + +// StatusContainsFold applies the ContainsFold predicate on the "status" field. +func StatusContainsFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContainsFold(FieldStatus, v)) +} + +// RetryCountEQ applies the EQ predicate on the "retry_count" field. +func RetryCountEQ(v int32) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldRetryCount, v)) +} + +// RetryCountNEQ applies the NEQ predicate on the "retry_count" field. +func RetryCountNEQ(v int32) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldRetryCount, v)) +} + +// RetryCountIn applies the In predicate on the "retry_count" field. +func RetryCountIn(vs ...int32) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldRetryCount, vs...)) +} + +// RetryCountNotIn applies the NotIn predicate on the "retry_count" field. +func RetryCountNotIn(vs ...int32) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldRetryCount, vs...)) +} + +// RetryCountGT applies the GT predicate on the "retry_count" field. +func RetryCountGT(v int32) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldRetryCount, v)) +} + +// RetryCountGTE applies the GTE predicate on the "retry_count" field. +func RetryCountGTE(v int32) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldRetryCount, v)) +} + +// RetryCountLT applies the LT predicate on the "retry_count" field. +func RetryCountLT(v int32) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldRetryCount, v)) +} + +// RetryCountLTE applies the LTE predicate on the "retry_count" field. +func RetryCountLTE(v int32) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldRetryCount, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldCreatedAt, v)) +} + +// LastErrorAtEQ applies the EQ predicate on the "last_error_at" field. +func LastErrorAtEQ(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldLastErrorAt, v)) +} + +// LastErrorAtNEQ applies the NEQ predicate on the "last_error_at" field. +func LastErrorAtNEQ(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldLastErrorAt, v)) +} + +// LastErrorAtIn applies the In predicate on the "last_error_at" field. +func LastErrorAtIn(vs ...int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldLastErrorAt, vs...)) +} + +// LastErrorAtNotIn applies the NotIn predicate on the "last_error_at" field. +func LastErrorAtNotIn(vs ...int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldLastErrorAt, vs...)) +} + +// LastErrorAtGT applies the GT predicate on the "last_error_at" field. +func LastErrorAtGT(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldLastErrorAt, v)) +} + +// LastErrorAtGTE applies the GTE predicate on the "last_error_at" field. +func LastErrorAtGTE(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldLastErrorAt, v)) +} + +// LastErrorAtLT applies the LT predicate on the "last_error_at" field. +func LastErrorAtLT(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldLastErrorAt, v)) +} + +// LastErrorAtLTE applies the LTE predicate on the "last_error_at" field. +func LastErrorAtLTE(v int64) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldLastErrorAt, v)) +} + +// HandledByEQ applies the EQ predicate on the "handled_by" field. +func HandledByEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEQ(FieldHandledBy, v)) +} + +// HandledByNEQ applies the NEQ predicate on the "handled_by" field. +func HandledByNEQ(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNEQ(FieldHandledBy, v)) +} + +// HandledByIn applies the In predicate on the "handled_by" field. +func HandledByIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldIn(FieldHandledBy, vs...)) +} + +// HandledByNotIn applies the NotIn predicate on the "handled_by" field. +func HandledByNotIn(vs ...string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldNotIn(FieldHandledBy, vs...)) +} + +// HandledByGT applies the GT predicate on the "handled_by" field. +func HandledByGT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGT(FieldHandledBy, v)) +} + +// HandledByGTE applies the GTE predicate on the "handled_by" field. +func HandledByGTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldGTE(FieldHandledBy, v)) +} + +// HandledByLT applies the LT predicate on the "handled_by" field. +func HandledByLT(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLT(FieldHandledBy, v)) +} + +// HandledByLTE applies the LTE predicate on the "handled_by" field. +func HandledByLTE(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldLTE(FieldHandledBy, v)) +} + +// HandledByContains applies the Contains predicate on the "handled_by" field. +func HandledByContains(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContains(FieldHandledBy, v)) +} + +// HandledByHasPrefix applies the HasPrefix predicate on the "handled_by" field. +func HandledByHasPrefix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasPrefix(FieldHandledBy, v)) +} + +// HandledByHasSuffix applies the HasSuffix predicate on the "handled_by" field. +func HandledByHasSuffix(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldHasSuffix(FieldHandledBy, v)) +} + +// HandledByEqualFold applies the EqualFold predicate on the "handled_by" field. +func HandledByEqualFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldEqualFold(FieldHandledBy, v)) +} + +// HandledByContainsFold applies the ContainsFold predicate on the "handled_by" field. +func HandledByContainsFold(v string) predicate.SyncFailure { + return predicate.SyncFailure(sql.FieldContainsFold(FieldHandledBy, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.SyncFailure) predicate.SyncFailure { + return predicate.SyncFailure(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.SyncFailure) predicate.SyncFailure { + return predicate.SyncFailure(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.SyncFailure) predicate.SyncFailure { + return predicate.SyncFailure(sql.NotPredicates(p)) +} diff --git a/bj_power_wms/ent/syncfailure_create.go b/bj_power_wms/ent/syncfailure_create.go new file mode 100644 index 0000000..fe14350 --- /dev/null +++ b/bj_power_wms/ent/syncfailure_create.go @@ -0,0 +1,1270 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_wms/ent/syncfailure" + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// SyncFailureCreate is the builder for creating a SyncFailure entity. +type SyncFailureCreate struct { + config + mutation *SyncFailureMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetDirection sets the "direction" field. +func (_c *SyncFailureCreate) SetDirection(v string) *SyncFailureCreate { + _c.mutation.SetDirection(v) + return _c +} + +// SetNillableDirection sets the "direction" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableDirection(v *string) *SyncFailureCreate { + if v != nil { + _c.SetDirection(*v) + } + return _c +} + +// SetBizType sets the "biz_type" field. +func (_c *SyncFailureCreate) SetBizType(v string) *SyncFailureCreate { + _c.mutation.SetBizType(v) + return _c +} + +// SetNillableBizType sets the "biz_type" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableBizType(v *string) *SyncFailureCreate { + if v != nil { + _c.SetBizType(*v) + } + return _c +} + +// SetBizKey sets the "biz_key" field. +func (_c *SyncFailureCreate) SetBizKey(v string) *SyncFailureCreate { + _c.mutation.SetBizKey(v) + return _c +} + +// SetNillableBizKey sets the "biz_key" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableBizKey(v *string) *SyncFailureCreate { + if v != nil { + _c.SetBizKey(*v) + } + return _c +} + +// SetEndpoint sets the "endpoint" field. +func (_c *SyncFailureCreate) SetEndpoint(v string) *SyncFailureCreate { + _c.mutation.SetEndpoint(v) + return _c +} + +// SetNillableEndpoint sets the "endpoint" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableEndpoint(v *string) *SyncFailureCreate { + if v != nil { + _c.SetEndpoint(*v) + } + return _c +} + +// SetPayloadJSON sets the "payload_json" field. +func (_c *SyncFailureCreate) SetPayloadJSON(v string) *SyncFailureCreate { + _c.mutation.SetPayloadJSON(v) + return _c +} + +// SetNillablePayloadJSON sets the "payload_json" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillablePayloadJSON(v *string) *SyncFailureCreate { + if v != nil { + _c.SetPayloadJSON(*v) + } + return _c +} + +// SetErrorMsg sets the "error_msg" field. +func (_c *SyncFailureCreate) SetErrorMsg(v string) *SyncFailureCreate { + _c.mutation.SetErrorMsg(v) + return _c +} + +// SetNillableErrorMsg sets the "error_msg" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableErrorMsg(v *string) *SyncFailureCreate { + if v != nil { + _c.SetErrorMsg(*v) + } + return _c +} + +// SetIdempotencyKey sets the "idempotency_key" field. +func (_c *SyncFailureCreate) SetIdempotencyKey(v string) *SyncFailureCreate { + _c.mutation.SetIdempotencyKey(v) + return _c +} + +// SetStatus sets the "status" field. +func (_c *SyncFailureCreate) SetStatus(v string) *SyncFailureCreate { + _c.mutation.SetStatus(v) + return _c +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableStatus(v *string) *SyncFailureCreate { + if v != nil { + _c.SetStatus(*v) + } + return _c +} + +// SetRetryCount sets the "retry_count" field. +func (_c *SyncFailureCreate) SetRetryCount(v int32) *SyncFailureCreate { + _c.mutation.SetRetryCount(v) + return _c +} + +// SetNillableRetryCount sets the "retry_count" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableRetryCount(v *int32) *SyncFailureCreate { + if v != nil { + _c.SetRetryCount(*v) + } + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *SyncFailureCreate) SetCreatedAt(v int64) *SyncFailureCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableCreatedAt(v *int64) *SyncFailureCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetLastErrorAt sets the "last_error_at" field. +func (_c *SyncFailureCreate) SetLastErrorAt(v int64) *SyncFailureCreate { + _c.mutation.SetLastErrorAt(v) + return _c +} + +// SetNillableLastErrorAt sets the "last_error_at" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableLastErrorAt(v *int64) *SyncFailureCreate { + if v != nil { + _c.SetLastErrorAt(*v) + } + return _c +} + +// SetHandledBy sets the "handled_by" field. +func (_c *SyncFailureCreate) SetHandledBy(v string) *SyncFailureCreate { + _c.mutation.SetHandledBy(v) + return _c +} + +// SetNillableHandledBy sets the "handled_by" field if the given value is not nil. +func (_c *SyncFailureCreate) SetNillableHandledBy(v *string) *SyncFailureCreate { + if v != nil { + _c.SetHandledBy(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *SyncFailureCreate) SetID(v int) *SyncFailureCreate { + _c.mutation.SetID(v) + return _c +} + +// Mutation returns the SyncFailureMutation object of the builder. +func (_c *SyncFailureCreate) Mutation() *SyncFailureMutation { + return _c.mutation +} + +// Save creates the SyncFailure in the database. +func (_c *SyncFailureCreate) Save(ctx context.Context) (*SyncFailure, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *SyncFailureCreate) SaveX(ctx context.Context) *SyncFailure { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *SyncFailureCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *SyncFailureCreate) 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 *SyncFailureCreate) defaults() { + if _, ok := _c.mutation.Direction(); !ok { + v := syncfailure.DefaultDirection + _c.mutation.SetDirection(v) + } + if _, ok := _c.mutation.BizType(); !ok { + v := syncfailure.DefaultBizType + _c.mutation.SetBizType(v) + } + if _, ok := _c.mutation.BizKey(); !ok { + v := syncfailure.DefaultBizKey + _c.mutation.SetBizKey(v) + } + if _, ok := _c.mutation.Endpoint(); !ok { + v := syncfailure.DefaultEndpoint + _c.mutation.SetEndpoint(v) + } + if _, ok := _c.mutation.PayloadJSON(); !ok { + v := syncfailure.DefaultPayloadJSON + _c.mutation.SetPayloadJSON(v) + } + if _, ok := _c.mutation.ErrorMsg(); !ok { + v := syncfailure.DefaultErrorMsg + _c.mutation.SetErrorMsg(v) + } + if _, ok := _c.mutation.Status(); !ok { + v := syncfailure.DefaultStatus + _c.mutation.SetStatus(v) + } + if _, ok := _c.mutation.RetryCount(); !ok { + v := syncfailure.DefaultRetryCount + _c.mutation.SetRetryCount(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := syncfailure.DefaultCreatedAt + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.LastErrorAt(); !ok { + v := syncfailure.DefaultLastErrorAt + _c.mutation.SetLastErrorAt(v) + } + if _, ok := _c.mutation.HandledBy(); !ok { + v := syncfailure.DefaultHandledBy + _c.mutation.SetHandledBy(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *SyncFailureCreate) check() error { + if _, ok := _c.mutation.Direction(); !ok { + return &ValidationError{Name: "direction", err: errors.New(`ent: missing required field "SyncFailure.direction"`)} + } + if _, ok := _c.mutation.BizType(); !ok { + return &ValidationError{Name: "biz_type", err: errors.New(`ent: missing required field "SyncFailure.biz_type"`)} + } + if _, ok := _c.mutation.BizKey(); !ok { + return &ValidationError{Name: "biz_key", err: errors.New(`ent: missing required field "SyncFailure.biz_key"`)} + } + if _, ok := _c.mutation.Endpoint(); !ok { + return &ValidationError{Name: "endpoint", err: errors.New(`ent: missing required field "SyncFailure.endpoint"`)} + } + if _, ok := _c.mutation.PayloadJSON(); !ok { + return &ValidationError{Name: "payload_json", err: errors.New(`ent: missing required field "SyncFailure.payload_json"`)} + } + if _, ok := _c.mutation.ErrorMsg(); !ok { + return &ValidationError{Name: "error_msg", err: errors.New(`ent: missing required field "SyncFailure.error_msg"`)} + } + if _, ok := _c.mutation.IdempotencyKey(); !ok { + return &ValidationError{Name: "idempotency_key", err: errors.New(`ent: missing required field "SyncFailure.idempotency_key"`)} + } + if _, ok := _c.mutation.Status(); !ok { + return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "SyncFailure.status"`)} + } + if _, ok := _c.mutation.RetryCount(); !ok { + return &ValidationError{Name: "retry_count", err: errors.New(`ent: missing required field "SyncFailure.retry_count"`)} + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "SyncFailure.created_at"`)} + } + if _, ok := _c.mutation.LastErrorAt(); !ok { + return &ValidationError{Name: "last_error_at", err: errors.New(`ent: missing required field "SyncFailure.last_error_at"`)} + } + if _, ok := _c.mutation.HandledBy(); !ok { + return &ValidationError{Name: "handled_by", err: errors.New(`ent: missing required field "SyncFailure.handled_by"`)} + } + if v, ok := _c.mutation.ID(); ok { + if err := syncfailure.IDValidator(v); err != nil { + return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "SyncFailure.id": %w`, err)} + } + } + return nil +} + +func (_c *SyncFailureCreate) sqlSave(ctx context.Context) (*SyncFailure, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != _node.ID { + id := _spec.ID.Value.(int64) + _node.ID = int(id) + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *SyncFailureCreate) createSpec() (*SyncFailure, *sqlgraph.CreateSpec) { + var ( + _node = &SyncFailure{config: _c.config} + _spec = sqlgraph.NewCreateSpec(syncfailure.Table, sqlgraph.NewFieldSpec(syncfailure.FieldID, field.TypeInt)) + ) + _spec.OnConflict = _c.conflict + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } + if value, ok := _c.mutation.Direction(); ok { + _spec.SetField(syncfailure.FieldDirection, field.TypeString, value) + _node.Direction = value + } + if value, ok := _c.mutation.BizType(); ok { + _spec.SetField(syncfailure.FieldBizType, field.TypeString, value) + _node.BizType = value + } + if value, ok := _c.mutation.BizKey(); ok { + _spec.SetField(syncfailure.FieldBizKey, field.TypeString, value) + _node.BizKey = value + } + if value, ok := _c.mutation.Endpoint(); ok { + _spec.SetField(syncfailure.FieldEndpoint, field.TypeString, value) + _node.Endpoint = value + } + if value, ok := _c.mutation.PayloadJSON(); ok { + _spec.SetField(syncfailure.FieldPayloadJSON, field.TypeString, value) + _node.PayloadJSON = value + } + if value, ok := _c.mutation.ErrorMsg(); ok { + _spec.SetField(syncfailure.FieldErrorMsg, field.TypeString, value) + _node.ErrorMsg = value + } + if value, ok := _c.mutation.IdempotencyKey(); ok { + _spec.SetField(syncfailure.FieldIdempotencyKey, field.TypeString, value) + _node.IdempotencyKey = value + } + if value, ok := _c.mutation.Status(); ok { + _spec.SetField(syncfailure.FieldStatus, field.TypeString, value) + _node.Status = value + } + if value, ok := _c.mutation.RetryCount(); ok { + _spec.SetField(syncfailure.FieldRetryCount, field.TypeInt32, value) + _node.RetryCount = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(syncfailure.FieldCreatedAt, field.TypeInt64, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.LastErrorAt(); ok { + _spec.SetField(syncfailure.FieldLastErrorAt, field.TypeInt64, value) + _node.LastErrorAt = value + } + if value, ok := _c.mutation.HandledBy(); ok { + _spec.SetField(syncfailure.FieldHandledBy, field.TypeString, value) + _node.HandledBy = value + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.SyncFailure.Create(). +// SetDirection(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.SyncFailureUpsert) { +// SetDirection(v+v). +// }). +// Exec(ctx) +func (_c *SyncFailureCreate) OnConflict(opts ...sql.ConflictOption) *SyncFailureUpsertOne { + _c.conflict = opts + return &SyncFailureUpsertOne{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.SyncFailure.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *SyncFailureCreate) OnConflictColumns(columns ...string) *SyncFailureUpsertOne { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &SyncFailureUpsertOne{ + create: _c, + } +} + +type ( + // SyncFailureUpsertOne is the builder for "upsert"-ing + // one SyncFailure node. + SyncFailureUpsertOne struct { + create *SyncFailureCreate + } + + // SyncFailureUpsert is the "OnConflict" setter. + SyncFailureUpsert struct { + *sql.UpdateSet + } +) + +// SetDirection sets the "direction" field. +func (u *SyncFailureUpsert) SetDirection(v string) *SyncFailureUpsert { + u.Set(syncfailure.FieldDirection, v) + return u +} + +// UpdateDirection sets the "direction" field to the value that was provided on create. +func (u *SyncFailureUpsert) UpdateDirection() *SyncFailureUpsert { + u.SetExcluded(syncfailure.FieldDirection) + return u +} + +// SetBizType sets the "biz_type" field. +func (u *SyncFailureUpsert) SetBizType(v string) *SyncFailureUpsert { + u.Set(syncfailure.FieldBizType, v) + return u +} + +// UpdateBizType sets the "biz_type" field to the value that was provided on create. +func (u *SyncFailureUpsert) UpdateBizType() *SyncFailureUpsert { + u.SetExcluded(syncfailure.FieldBizType) + return u +} + +// SetBizKey sets the "biz_key" field. +func (u *SyncFailureUpsert) SetBizKey(v string) *SyncFailureUpsert { + u.Set(syncfailure.FieldBizKey, v) + return u +} + +// UpdateBizKey sets the "biz_key" field to the value that was provided on create. +func (u *SyncFailureUpsert) UpdateBizKey() *SyncFailureUpsert { + u.SetExcluded(syncfailure.FieldBizKey) + return u +} + +// SetEndpoint sets the "endpoint" field. +func (u *SyncFailureUpsert) SetEndpoint(v string) *SyncFailureUpsert { + u.Set(syncfailure.FieldEndpoint, v) + return u +} + +// UpdateEndpoint sets the "endpoint" field to the value that was provided on create. +func (u *SyncFailureUpsert) UpdateEndpoint() *SyncFailureUpsert { + u.SetExcluded(syncfailure.FieldEndpoint) + return u +} + +// SetPayloadJSON sets the "payload_json" field. +func (u *SyncFailureUpsert) SetPayloadJSON(v string) *SyncFailureUpsert { + u.Set(syncfailure.FieldPayloadJSON, v) + return u +} + +// UpdatePayloadJSON sets the "payload_json" field to the value that was provided on create. +func (u *SyncFailureUpsert) UpdatePayloadJSON() *SyncFailureUpsert { + u.SetExcluded(syncfailure.FieldPayloadJSON) + return u +} + +// SetErrorMsg sets the "error_msg" field. +func (u *SyncFailureUpsert) SetErrorMsg(v string) *SyncFailureUpsert { + u.Set(syncfailure.FieldErrorMsg, v) + return u +} + +// UpdateErrorMsg sets the "error_msg" field to the value that was provided on create. +func (u *SyncFailureUpsert) UpdateErrorMsg() *SyncFailureUpsert { + u.SetExcluded(syncfailure.FieldErrorMsg) + return u +} + +// SetIdempotencyKey sets the "idempotency_key" field. +func (u *SyncFailureUpsert) SetIdempotencyKey(v string) *SyncFailureUpsert { + u.Set(syncfailure.FieldIdempotencyKey, v) + return u +} + +// UpdateIdempotencyKey sets the "idempotency_key" field to the value that was provided on create. +func (u *SyncFailureUpsert) UpdateIdempotencyKey() *SyncFailureUpsert { + u.SetExcluded(syncfailure.FieldIdempotencyKey) + return u +} + +// SetStatus sets the "status" field. +func (u *SyncFailureUpsert) SetStatus(v string) *SyncFailureUpsert { + u.Set(syncfailure.FieldStatus, v) + return u +} + +// UpdateStatus sets the "status" field to the value that was provided on create. +func (u *SyncFailureUpsert) UpdateStatus() *SyncFailureUpsert { + u.SetExcluded(syncfailure.FieldStatus) + return u +} + +// SetRetryCount sets the "retry_count" field. +func (u *SyncFailureUpsert) SetRetryCount(v int32) *SyncFailureUpsert { + u.Set(syncfailure.FieldRetryCount, v) + return u +} + +// UpdateRetryCount sets the "retry_count" field to the value that was provided on create. +func (u *SyncFailureUpsert) UpdateRetryCount() *SyncFailureUpsert { + u.SetExcluded(syncfailure.FieldRetryCount) + return u +} + +// AddRetryCount adds v to the "retry_count" field. +func (u *SyncFailureUpsert) AddRetryCount(v int32) *SyncFailureUpsert { + u.Add(syncfailure.FieldRetryCount, v) + return u +} + +// SetCreatedAt sets the "created_at" field. +func (u *SyncFailureUpsert) SetCreatedAt(v int64) *SyncFailureUpsert { + u.Set(syncfailure.FieldCreatedAt, v) + return u +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *SyncFailureUpsert) UpdateCreatedAt() *SyncFailureUpsert { + u.SetExcluded(syncfailure.FieldCreatedAt) + return u +} + +// AddCreatedAt adds v to the "created_at" field. +func (u *SyncFailureUpsert) AddCreatedAt(v int64) *SyncFailureUpsert { + u.Add(syncfailure.FieldCreatedAt, v) + return u +} + +// SetLastErrorAt sets the "last_error_at" field. +func (u *SyncFailureUpsert) SetLastErrorAt(v int64) *SyncFailureUpsert { + u.Set(syncfailure.FieldLastErrorAt, v) + return u +} + +// UpdateLastErrorAt sets the "last_error_at" field to the value that was provided on create. +func (u *SyncFailureUpsert) UpdateLastErrorAt() *SyncFailureUpsert { + u.SetExcluded(syncfailure.FieldLastErrorAt) + return u +} + +// AddLastErrorAt adds v to the "last_error_at" field. +func (u *SyncFailureUpsert) AddLastErrorAt(v int64) *SyncFailureUpsert { + u.Add(syncfailure.FieldLastErrorAt, v) + return u +} + +// SetHandledBy sets the "handled_by" field. +func (u *SyncFailureUpsert) SetHandledBy(v string) *SyncFailureUpsert { + u.Set(syncfailure.FieldHandledBy, v) + return u +} + +// UpdateHandledBy sets the "handled_by" field to the value that was provided on create. +func (u *SyncFailureUpsert) UpdateHandledBy() *SyncFailureUpsert { + u.SetExcluded(syncfailure.FieldHandledBy) + return u +} + +// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field. +// Using this option is equivalent to using: +// +// client.SyncFailure.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(syncfailure.FieldID) +// }), +// ). +// Exec(ctx) +func (u *SyncFailureUpsertOne) UpdateNewValues() *SyncFailureUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { + if _, exists := u.create.mutation.ID(); exists { + s.SetIgnore(syncfailure.FieldID) + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.SyncFailure.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *SyncFailureUpsertOne) Ignore() *SyncFailureUpsertOne { + 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 *SyncFailureUpsertOne) DoNothing() *SyncFailureUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the SyncFailureCreate.OnConflict +// documentation for more info. +func (u *SyncFailureUpsertOne) Update(set func(*SyncFailureUpsert)) *SyncFailureUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&SyncFailureUpsert{UpdateSet: update}) + })) + return u +} + +// SetDirection sets the "direction" field. +func (u *SyncFailureUpsertOne) SetDirection(v string) *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.SetDirection(v) + }) +} + +// UpdateDirection sets the "direction" field to the value that was provided on create. +func (u *SyncFailureUpsertOne) UpdateDirection() *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateDirection() + }) +} + +// SetBizType sets the "biz_type" field. +func (u *SyncFailureUpsertOne) SetBizType(v string) *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.SetBizType(v) + }) +} + +// UpdateBizType sets the "biz_type" field to the value that was provided on create. +func (u *SyncFailureUpsertOne) UpdateBizType() *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateBizType() + }) +} + +// SetBizKey sets the "biz_key" field. +func (u *SyncFailureUpsertOne) SetBizKey(v string) *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.SetBizKey(v) + }) +} + +// UpdateBizKey sets the "biz_key" field to the value that was provided on create. +func (u *SyncFailureUpsertOne) UpdateBizKey() *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateBizKey() + }) +} + +// SetEndpoint sets the "endpoint" field. +func (u *SyncFailureUpsertOne) SetEndpoint(v string) *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.SetEndpoint(v) + }) +} + +// UpdateEndpoint sets the "endpoint" field to the value that was provided on create. +func (u *SyncFailureUpsertOne) UpdateEndpoint() *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateEndpoint() + }) +} + +// SetPayloadJSON sets the "payload_json" field. +func (u *SyncFailureUpsertOne) SetPayloadJSON(v string) *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.SetPayloadJSON(v) + }) +} + +// UpdatePayloadJSON sets the "payload_json" field to the value that was provided on create. +func (u *SyncFailureUpsertOne) UpdatePayloadJSON() *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdatePayloadJSON() + }) +} + +// SetErrorMsg sets the "error_msg" field. +func (u *SyncFailureUpsertOne) SetErrorMsg(v string) *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.SetErrorMsg(v) + }) +} + +// UpdateErrorMsg sets the "error_msg" field to the value that was provided on create. +func (u *SyncFailureUpsertOne) UpdateErrorMsg() *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateErrorMsg() + }) +} + +// SetIdempotencyKey sets the "idempotency_key" field. +func (u *SyncFailureUpsertOne) SetIdempotencyKey(v string) *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.SetIdempotencyKey(v) + }) +} + +// UpdateIdempotencyKey sets the "idempotency_key" field to the value that was provided on create. +func (u *SyncFailureUpsertOne) UpdateIdempotencyKey() *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateIdempotencyKey() + }) +} + +// SetStatus sets the "status" field. +func (u *SyncFailureUpsertOne) SetStatus(v string) *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.SetStatus(v) + }) +} + +// UpdateStatus sets the "status" field to the value that was provided on create. +func (u *SyncFailureUpsertOne) UpdateStatus() *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateStatus() + }) +} + +// SetRetryCount sets the "retry_count" field. +func (u *SyncFailureUpsertOne) SetRetryCount(v int32) *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.SetRetryCount(v) + }) +} + +// AddRetryCount adds v to the "retry_count" field. +func (u *SyncFailureUpsertOne) AddRetryCount(v int32) *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.AddRetryCount(v) + }) +} + +// UpdateRetryCount sets the "retry_count" field to the value that was provided on create. +func (u *SyncFailureUpsertOne) UpdateRetryCount() *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateRetryCount() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *SyncFailureUpsertOne) SetCreatedAt(v int64) *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.SetCreatedAt(v) + }) +} + +// AddCreatedAt adds v to the "created_at" field. +func (u *SyncFailureUpsertOne) AddCreatedAt(v int64) *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.AddCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *SyncFailureUpsertOne) UpdateCreatedAt() *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetLastErrorAt sets the "last_error_at" field. +func (u *SyncFailureUpsertOne) SetLastErrorAt(v int64) *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.SetLastErrorAt(v) + }) +} + +// AddLastErrorAt adds v to the "last_error_at" field. +func (u *SyncFailureUpsertOne) AddLastErrorAt(v int64) *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.AddLastErrorAt(v) + }) +} + +// UpdateLastErrorAt sets the "last_error_at" field to the value that was provided on create. +func (u *SyncFailureUpsertOne) UpdateLastErrorAt() *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateLastErrorAt() + }) +} + +// SetHandledBy sets the "handled_by" field. +func (u *SyncFailureUpsertOne) SetHandledBy(v string) *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.SetHandledBy(v) + }) +} + +// UpdateHandledBy sets the "handled_by" field to the value that was provided on create. +func (u *SyncFailureUpsertOne) UpdateHandledBy() *SyncFailureUpsertOne { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateHandledBy() + }) +} + +// Exec executes the query. +func (u *SyncFailureUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for SyncFailureCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *SyncFailureUpsertOne) 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 *SyncFailureUpsertOne) ID(ctx context.Context) (id int, 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 *SyncFailureUpsertOne) IDX(ctx context.Context) int { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// SyncFailureCreateBulk is the builder for creating many SyncFailure entities in bulk. +type SyncFailureCreateBulk struct { + config + err error + builders []*SyncFailureCreate + conflict []sql.ConflictOption +} + +// Save creates the SyncFailure entities in the database. +func (_c *SyncFailureCreateBulk) Save(ctx context.Context) ([]*SyncFailure, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*SyncFailure, 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.(*SyncFailureMutation) + 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 && nodes[i].ID == 0 { + id := specs[i].ID.Value.(int64) + nodes[i].ID = int(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 *SyncFailureCreateBulk) SaveX(ctx context.Context) []*SyncFailure { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *SyncFailureCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *SyncFailureCreateBulk) 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.SyncFailure.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.SyncFailureUpsert) { +// SetDirection(v+v). +// }). +// Exec(ctx) +func (_c *SyncFailureCreateBulk) OnConflict(opts ...sql.ConflictOption) *SyncFailureUpsertBulk { + _c.conflict = opts + return &SyncFailureUpsertBulk{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.SyncFailure.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *SyncFailureCreateBulk) OnConflictColumns(columns ...string) *SyncFailureUpsertBulk { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &SyncFailureUpsertBulk{ + create: _c, + } +} + +// SyncFailureUpsertBulk is the builder for "upsert"-ing +// a bulk of SyncFailure nodes. +type SyncFailureUpsertBulk struct { + create *SyncFailureCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.SyncFailure.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(syncfailure.FieldID) +// }), +// ). +// Exec(ctx) +func (u *SyncFailureUpsertBulk) UpdateNewValues() *SyncFailureUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { + for _, b := range u.create.builders { + if _, exists := b.mutation.ID(); exists { + s.SetIgnore(syncfailure.FieldID) + } + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.SyncFailure.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *SyncFailureUpsertBulk) Ignore() *SyncFailureUpsertBulk { + 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 *SyncFailureUpsertBulk) DoNothing() *SyncFailureUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the SyncFailureCreateBulk.OnConflict +// documentation for more info. +func (u *SyncFailureUpsertBulk) Update(set func(*SyncFailureUpsert)) *SyncFailureUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&SyncFailureUpsert{UpdateSet: update}) + })) + return u +} + +// SetDirection sets the "direction" field. +func (u *SyncFailureUpsertBulk) SetDirection(v string) *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.SetDirection(v) + }) +} + +// UpdateDirection sets the "direction" field to the value that was provided on create. +func (u *SyncFailureUpsertBulk) UpdateDirection() *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateDirection() + }) +} + +// SetBizType sets the "biz_type" field. +func (u *SyncFailureUpsertBulk) SetBizType(v string) *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.SetBizType(v) + }) +} + +// UpdateBizType sets the "biz_type" field to the value that was provided on create. +func (u *SyncFailureUpsertBulk) UpdateBizType() *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateBizType() + }) +} + +// SetBizKey sets the "biz_key" field. +func (u *SyncFailureUpsertBulk) SetBizKey(v string) *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.SetBizKey(v) + }) +} + +// UpdateBizKey sets the "biz_key" field to the value that was provided on create. +func (u *SyncFailureUpsertBulk) UpdateBizKey() *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateBizKey() + }) +} + +// SetEndpoint sets the "endpoint" field. +func (u *SyncFailureUpsertBulk) SetEndpoint(v string) *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.SetEndpoint(v) + }) +} + +// UpdateEndpoint sets the "endpoint" field to the value that was provided on create. +func (u *SyncFailureUpsertBulk) UpdateEndpoint() *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateEndpoint() + }) +} + +// SetPayloadJSON sets the "payload_json" field. +func (u *SyncFailureUpsertBulk) SetPayloadJSON(v string) *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.SetPayloadJSON(v) + }) +} + +// UpdatePayloadJSON sets the "payload_json" field to the value that was provided on create. +func (u *SyncFailureUpsertBulk) UpdatePayloadJSON() *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdatePayloadJSON() + }) +} + +// SetErrorMsg sets the "error_msg" field. +func (u *SyncFailureUpsertBulk) SetErrorMsg(v string) *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.SetErrorMsg(v) + }) +} + +// UpdateErrorMsg sets the "error_msg" field to the value that was provided on create. +func (u *SyncFailureUpsertBulk) UpdateErrorMsg() *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateErrorMsg() + }) +} + +// SetIdempotencyKey sets the "idempotency_key" field. +func (u *SyncFailureUpsertBulk) SetIdempotencyKey(v string) *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.SetIdempotencyKey(v) + }) +} + +// UpdateIdempotencyKey sets the "idempotency_key" field to the value that was provided on create. +func (u *SyncFailureUpsertBulk) UpdateIdempotencyKey() *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateIdempotencyKey() + }) +} + +// SetStatus sets the "status" field. +func (u *SyncFailureUpsertBulk) SetStatus(v string) *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.SetStatus(v) + }) +} + +// UpdateStatus sets the "status" field to the value that was provided on create. +func (u *SyncFailureUpsertBulk) UpdateStatus() *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateStatus() + }) +} + +// SetRetryCount sets the "retry_count" field. +func (u *SyncFailureUpsertBulk) SetRetryCount(v int32) *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.SetRetryCount(v) + }) +} + +// AddRetryCount adds v to the "retry_count" field. +func (u *SyncFailureUpsertBulk) AddRetryCount(v int32) *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.AddRetryCount(v) + }) +} + +// UpdateRetryCount sets the "retry_count" field to the value that was provided on create. +func (u *SyncFailureUpsertBulk) UpdateRetryCount() *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateRetryCount() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *SyncFailureUpsertBulk) SetCreatedAt(v int64) *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.SetCreatedAt(v) + }) +} + +// AddCreatedAt adds v to the "created_at" field. +func (u *SyncFailureUpsertBulk) AddCreatedAt(v int64) *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.AddCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *SyncFailureUpsertBulk) UpdateCreatedAt() *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetLastErrorAt sets the "last_error_at" field. +func (u *SyncFailureUpsertBulk) SetLastErrorAt(v int64) *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.SetLastErrorAt(v) + }) +} + +// AddLastErrorAt adds v to the "last_error_at" field. +func (u *SyncFailureUpsertBulk) AddLastErrorAt(v int64) *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.AddLastErrorAt(v) + }) +} + +// UpdateLastErrorAt sets the "last_error_at" field to the value that was provided on create. +func (u *SyncFailureUpsertBulk) UpdateLastErrorAt() *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateLastErrorAt() + }) +} + +// SetHandledBy sets the "handled_by" field. +func (u *SyncFailureUpsertBulk) SetHandledBy(v string) *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.SetHandledBy(v) + }) +} + +// UpdateHandledBy sets the "handled_by" field to the value that was provided on create. +func (u *SyncFailureUpsertBulk) UpdateHandledBy() *SyncFailureUpsertBulk { + return u.Update(func(s *SyncFailureUpsert) { + s.UpdateHandledBy() + }) +} + +// Exec executes the query. +func (u *SyncFailureUpsertBulk) 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 SyncFailureCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for SyncFailureCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *SyncFailureUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_wms/ent/syncfailure_delete.go b/bj_power_wms/ent/syncfailure_delete.go new file mode 100644 index 0000000..44d83e5 --- /dev/null +++ b/bj_power_wms/ent/syncfailure_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_wms/ent/predicate" + "bj_power_wms/ent/syncfailure" + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// SyncFailureDelete is the builder for deleting a SyncFailure entity. +type SyncFailureDelete struct { + config + hooks []Hook + mutation *SyncFailureMutation +} + +// Where appends a list predicates to the SyncFailureDelete builder. +func (_d *SyncFailureDelete) Where(ps ...predicate.SyncFailure) *SyncFailureDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *SyncFailureDelete) 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 *SyncFailureDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *SyncFailureDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(syncfailure.Table, sqlgraph.NewFieldSpec(syncfailure.FieldID, field.TypeInt)) + 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 +} + +// SyncFailureDeleteOne is the builder for deleting a single SyncFailure entity. +type SyncFailureDeleteOne struct { + _d *SyncFailureDelete +} + +// Where appends a list predicates to the SyncFailureDelete builder. +func (_d *SyncFailureDeleteOne) Where(ps ...predicate.SyncFailure) *SyncFailureDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *SyncFailureDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{syncfailure.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *SyncFailureDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_wms/ent/syncfailure_query.go b/bj_power_wms/ent/syncfailure_query.go new file mode 100644 index 0000000..18e4387 --- /dev/null +++ b/bj_power_wms/ent/syncfailure_query.go @@ -0,0 +1,527 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_wms/ent/predicate" + "bj_power_wms/ent/syncfailure" + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// SyncFailureQuery is the builder for querying SyncFailure entities. +type SyncFailureQuery struct { + config + ctx *QueryContext + order []syncfailure.OrderOption + inters []Interceptor + predicates []predicate.SyncFailure + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the SyncFailureQuery builder. +func (_q *SyncFailureQuery) Where(ps ...predicate.SyncFailure) *SyncFailureQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *SyncFailureQuery) Limit(limit int) *SyncFailureQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *SyncFailureQuery) Offset(offset int) *SyncFailureQuery { + _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 *SyncFailureQuery) Unique(unique bool) *SyncFailureQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *SyncFailureQuery) Order(o ...syncfailure.OrderOption) *SyncFailureQuery { + _q.order = append(_q.order, o...) + return _q +} + +// First returns the first SyncFailure entity from the query. +// Returns a *NotFoundError when no SyncFailure was found. +func (_q *SyncFailureQuery) First(ctx context.Context) (*SyncFailure, 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{syncfailure.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *SyncFailureQuery) FirstX(ctx context.Context) *SyncFailure { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first SyncFailure ID from the query. +// Returns a *NotFoundError when no SyncFailure ID was found. +func (_q *SyncFailureQuery) FirstID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{syncfailure.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *SyncFailureQuery) FirstIDX(ctx context.Context) int { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single SyncFailure entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one SyncFailure entity is found. +// Returns a *NotFoundError when no SyncFailure entities are found. +func (_q *SyncFailureQuery) Only(ctx context.Context) (*SyncFailure, 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{syncfailure.Label} + default: + return nil, &NotSingularError{syncfailure.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *SyncFailureQuery) OnlyX(ctx context.Context) *SyncFailure { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only SyncFailure ID in the query. +// Returns a *NotSingularError when more than one SyncFailure ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *SyncFailureQuery) OnlyID(ctx context.Context) (id int, err error) { + var ids []int + 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{syncfailure.Label} + default: + err = &NotSingularError{syncfailure.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *SyncFailureQuery) OnlyIDX(ctx context.Context) int { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of SyncFailures. +func (_q *SyncFailureQuery) All(ctx context.Context) ([]*SyncFailure, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*SyncFailure, *SyncFailureQuery]() + return withInterceptors[[]*SyncFailure](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *SyncFailureQuery) AllX(ctx context.Context) []*SyncFailure { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of SyncFailure IDs. +func (_q *SyncFailureQuery) IDs(ctx context.Context) (ids []int, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(syncfailure.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *SyncFailureQuery) IDsX(ctx context.Context) []int { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *SyncFailureQuery) 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[*SyncFailureQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *SyncFailureQuery) 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 *SyncFailureQuery) 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 *SyncFailureQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the SyncFailureQuery 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 *SyncFailureQuery) Clone() *SyncFailureQuery { + if _q == nil { + return nil + } + return &SyncFailureQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]syncfailure.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.SyncFailure{}, _q.predicates...), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + } +} + +// 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 { +// Direction string `json:"direction,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.SyncFailure.Query(). +// GroupBy(syncfailure.FieldDirection). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *SyncFailureQuery) GroupBy(field string, fields ...string) *SyncFailureGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &SyncFailureGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = syncfailure.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 { +// Direction string `json:"direction,omitempty"` +// } +// +// client.SyncFailure.Query(). +// Select(syncfailure.FieldDirection). +// Scan(ctx, &v) +func (_q *SyncFailureQuery) Select(fields ...string) *SyncFailureSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &SyncFailureSelect{SyncFailureQuery: _q} + sbuild.label = syncfailure.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a SyncFailureSelect configured with the given aggregations. +func (_q *SyncFailureQuery) Aggregate(fns ...AggregateFunc) *SyncFailureSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *SyncFailureQuery) 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 !syncfailure.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 *SyncFailureQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SyncFailure, error) { + var ( + nodes = []*SyncFailure{} + _spec = _q.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*SyncFailure).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &SyncFailure{config: _q.config} + nodes = append(nodes, node) + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + return nodes, nil +} + +func (_q *SyncFailureQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *SyncFailureQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(syncfailure.Table, syncfailure.Columns, sqlgraph.NewFieldSpec(syncfailure.FieldID, field.TypeInt)) + _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, syncfailure.FieldID) + for i := range fields { + if fields[i] != syncfailure.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *SyncFailureQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(syncfailure.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = syncfailure.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// SyncFailureGroupBy is the group-by builder for SyncFailure entities. +type SyncFailureGroupBy struct { + selector + build *SyncFailureQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *SyncFailureGroupBy) Aggregate(fns ...AggregateFunc) *SyncFailureGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *SyncFailureGroupBy) 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[*SyncFailureQuery, *SyncFailureGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *SyncFailureGroupBy) sqlScan(ctx context.Context, root *SyncFailureQuery, 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) +} + +// SyncFailureSelect is the builder for selecting fields of SyncFailure entities. +type SyncFailureSelect struct { + *SyncFailureQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *SyncFailureSelect) Aggregate(fns ...AggregateFunc) *SyncFailureSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *SyncFailureSelect) 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[*SyncFailureQuery, *SyncFailureSelect](ctx, _s.SyncFailureQuery, _s, _s.inters, v) +} + +func (_s *SyncFailureSelect) sqlScan(ctx context.Context, root *SyncFailureQuery, 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) +} diff --git a/bj_power_wms/ent/syncfailure_update.go b/bj_power_wms/ent/syncfailure_update.go new file mode 100644 index 0000000..03697d6 --- /dev/null +++ b/bj_power_wms/ent/syncfailure_update.go @@ -0,0 +1,643 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_wms/ent/predicate" + "bj_power_wms/ent/syncfailure" + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// SyncFailureUpdate is the builder for updating SyncFailure entities. +type SyncFailureUpdate struct { + config + hooks []Hook + mutation *SyncFailureMutation +} + +// Where appends a list predicates to the SyncFailureUpdate builder. +func (_u *SyncFailureUpdate) Where(ps ...predicate.SyncFailure) *SyncFailureUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetDirection sets the "direction" field. +func (_u *SyncFailureUpdate) SetDirection(v string) *SyncFailureUpdate { + _u.mutation.SetDirection(v) + return _u +} + +// SetNillableDirection sets the "direction" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableDirection(v *string) *SyncFailureUpdate { + if v != nil { + _u.SetDirection(*v) + } + return _u +} + +// SetBizType sets the "biz_type" field. +func (_u *SyncFailureUpdate) SetBizType(v string) *SyncFailureUpdate { + _u.mutation.SetBizType(v) + return _u +} + +// SetNillableBizType sets the "biz_type" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableBizType(v *string) *SyncFailureUpdate { + if v != nil { + _u.SetBizType(*v) + } + return _u +} + +// SetBizKey sets the "biz_key" field. +func (_u *SyncFailureUpdate) SetBizKey(v string) *SyncFailureUpdate { + _u.mutation.SetBizKey(v) + return _u +} + +// SetNillableBizKey sets the "biz_key" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableBizKey(v *string) *SyncFailureUpdate { + if v != nil { + _u.SetBizKey(*v) + } + return _u +} + +// SetEndpoint sets the "endpoint" field. +func (_u *SyncFailureUpdate) SetEndpoint(v string) *SyncFailureUpdate { + _u.mutation.SetEndpoint(v) + return _u +} + +// SetNillableEndpoint sets the "endpoint" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableEndpoint(v *string) *SyncFailureUpdate { + if v != nil { + _u.SetEndpoint(*v) + } + return _u +} + +// SetPayloadJSON sets the "payload_json" field. +func (_u *SyncFailureUpdate) SetPayloadJSON(v string) *SyncFailureUpdate { + _u.mutation.SetPayloadJSON(v) + return _u +} + +// SetNillablePayloadJSON sets the "payload_json" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillablePayloadJSON(v *string) *SyncFailureUpdate { + if v != nil { + _u.SetPayloadJSON(*v) + } + return _u +} + +// SetErrorMsg sets the "error_msg" field. +func (_u *SyncFailureUpdate) SetErrorMsg(v string) *SyncFailureUpdate { + _u.mutation.SetErrorMsg(v) + return _u +} + +// SetNillableErrorMsg sets the "error_msg" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableErrorMsg(v *string) *SyncFailureUpdate { + if v != nil { + _u.SetErrorMsg(*v) + } + return _u +} + +// SetIdempotencyKey sets the "idempotency_key" field. +func (_u *SyncFailureUpdate) SetIdempotencyKey(v string) *SyncFailureUpdate { + _u.mutation.SetIdempotencyKey(v) + return _u +} + +// SetNillableIdempotencyKey sets the "idempotency_key" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableIdempotencyKey(v *string) *SyncFailureUpdate { + if v != nil { + _u.SetIdempotencyKey(*v) + } + return _u +} + +// SetStatus sets the "status" field. +func (_u *SyncFailureUpdate) SetStatus(v string) *SyncFailureUpdate { + _u.mutation.SetStatus(v) + return _u +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableStatus(v *string) *SyncFailureUpdate { + if v != nil { + _u.SetStatus(*v) + } + return _u +} + +// SetRetryCount sets the "retry_count" field. +func (_u *SyncFailureUpdate) SetRetryCount(v int32) *SyncFailureUpdate { + _u.mutation.ResetRetryCount() + _u.mutation.SetRetryCount(v) + return _u +} + +// SetNillableRetryCount sets the "retry_count" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableRetryCount(v *int32) *SyncFailureUpdate { + if v != nil { + _u.SetRetryCount(*v) + } + return _u +} + +// AddRetryCount adds value to the "retry_count" field. +func (_u *SyncFailureUpdate) AddRetryCount(v int32) *SyncFailureUpdate { + _u.mutation.AddRetryCount(v) + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *SyncFailureUpdate) SetCreatedAt(v int64) *SyncFailureUpdate { + _u.mutation.ResetCreatedAt() + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableCreatedAt(v *int64) *SyncFailureUpdate { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// AddCreatedAt adds value to the "created_at" field. +func (_u *SyncFailureUpdate) AddCreatedAt(v int64) *SyncFailureUpdate { + _u.mutation.AddCreatedAt(v) + return _u +} + +// SetLastErrorAt sets the "last_error_at" field. +func (_u *SyncFailureUpdate) SetLastErrorAt(v int64) *SyncFailureUpdate { + _u.mutation.ResetLastErrorAt() + _u.mutation.SetLastErrorAt(v) + return _u +} + +// SetNillableLastErrorAt sets the "last_error_at" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableLastErrorAt(v *int64) *SyncFailureUpdate { + if v != nil { + _u.SetLastErrorAt(*v) + } + return _u +} + +// AddLastErrorAt adds value to the "last_error_at" field. +func (_u *SyncFailureUpdate) AddLastErrorAt(v int64) *SyncFailureUpdate { + _u.mutation.AddLastErrorAt(v) + return _u +} + +// SetHandledBy sets the "handled_by" field. +func (_u *SyncFailureUpdate) SetHandledBy(v string) *SyncFailureUpdate { + _u.mutation.SetHandledBy(v) + return _u +} + +// SetNillableHandledBy sets the "handled_by" field if the given value is not nil. +func (_u *SyncFailureUpdate) SetNillableHandledBy(v *string) *SyncFailureUpdate { + if v != nil { + _u.SetHandledBy(*v) + } + return _u +} + +// Mutation returns the SyncFailureMutation object of the builder. +func (_u *SyncFailureUpdate) Mutation() *SyncFailureMutation { + return _u.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *SyncFailureUpdate) 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 *SyncFailureUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *SyncFailureUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *SyncFailureUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +func (_u *SyncFailureUpdate) sqlSave(ctx context.Context) (_node int, err error) { + _spec := sqlgraph.NewUpdateSpec(syncfailure.Table, syncfailure.Columns, sqlgraph.NewFieldSpec(syncfailure.FieldID, field.TypeInt)) + 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.Direction(); ok { + _spec.SetField(syncfailure.FieldDirection, field.TypeString, value) + } + if value, ok := _u.mutation.BizType(); ok { + _spec.SetField(syncfailure.FieldBizType, field.TypeString, value) + } + if value, ok := _u.mutation.BizKey(); ok { + _spec.SetField(syncfailure.FieldBizKey, field.TypeString, value) + } + if value, ok := _u.mutation.Endpoint(); ok { + _spec.SetField(syncfailure.FieldEndpoint, field.TypeString, value) + } + if value, ok := _u.mutation.PayloadJSON(); ok { + _spec.SetField(syncfailure.FieldPayloadJSON, field.TypeString, value) + } + if value, ok := _u.mutation.ErrorMsg(); ok { + _spec.SetField(syncfailure.FieldErrorMsg, field.TypeString, value) + } + if value, ok := _u.mutation.IdempotencyKey(); ok { + _spec.SetField(syncfailure.FieldIdempotencyKey, field.TypeString, value) + } + if value, ok := _u.mutation.Status(); ok { + _spec.SetField(syncfailure.FieldStatus, field.TypeString, value) + } + if value, ok := _u.mutation.RetryCount(); ok { + _spec.SetField(syncfailure.FieldRetryCount, field.TypeInt32, value) + } + if value, ok := _u.mutation.AddedRetryCount(); ok { + _spec.AddField(syncfailure.FieldRetryCount, field.TypeInt32, value) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(syncfailure.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedCreatedAt(); ok { + _spec.AddField(syncfailure.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.LastErrorAt(); ok { + _spec.SetField(syncfailure.FieldLastErrorAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedLastErrorAt(); ok { + _spec.AddField(syncfailure.FieldLastErrorAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.HandledBy(); ok { + _spec.SetField(syncfailure.FieldHandledBy, field.TypeString, value) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{syncfailure.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// SyncFailureUpdateOne is the builder for updating a single SyncFailure entity. +type SyncFailureUpdateOne struct { + config + fields []string + hooks []Hook + mutation *SyncFailureMutation +} + +// SetDirection sets the "direction" field. +func (_u *SyncFailureUpdateOne) SetDirection(v string) *SyncFailureUpdateOne { + _u.mutation.SetDirection(v) + return _u +} + +// SetNillableDirection sets the "direction" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableDirection(v *string) *SyncFailureUpdateOne { + if v != nil { + _u.SetDirection(*v) + } + return _u +} + +// SetBizType sets the "biz_type" field. +func (_u *SyncFailureUpdateOne) SetBizType(v string) *SyncFailureUpdateOne { + _u.mutation.SetBizType(v) + return _u +} + +// SetNillableBizType sets the "biz_type" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableBizType(v *string) *SyncFailureUpdateOne { + if v != nil { + _u.SetBizType(*v) + } + return _u +} + +// SetBizKey sets the "biz_key" field. +func (_u *SyncFailureUpdateOne) SetBizKey(v string) *SyncFailureUpdateOne { + _u.mutation.SetBizKey(v) + return _u +} + +// SetNillableBizKey sets the "biz_key" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableBizKey(v *string) *SyncFailureUpdateOne { + if v != nil { + _u.SetBizKey(*v) + } + return _u +} + +// SetEndpoint sets the "endpoint" field. +func (_u *SyncFailureUpdateOne) SetEndpoint(v string) *SyncFailureUpdateOne { + _u.mutation.SetEndpoint(v) + return _u +} + +// SetNillableEndpoint sets the "endpoint" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableEndpoint(v *string) *SyncFailureUpdateOne { + if v != nil { + _u.SetEndpoint(*v) + } + return _u +} + +// SetPayloadJSON sets the "payload_json" field. +func (_u *SyncFailureUpdateOne) SetPayloadJSON(v string) *SyncFailureUpdateOne { + _u.mutation.SetPayloadJSON(v) + return _u +} + +// SetNillablePayloadJSON sets the "payload_json" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillablePayloadJSON(v *string) *SyncFailureUpdateOne { + if v != nil { + _u.SetPayloadJSON(*v) + } + return _u +} + +// SetErrorMsg sets the "error_msg" field. +func (_u *SyncFailureUpdateOne) SetErrorMsg(v string) *SyncFailureUpdateOne { + _u.mutation.SetErrorMsg(v) + return _u +} + +// SetNillableErrorMsg sets the "error_msg" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableErrorMsg(v *string) *SyncFailureUpdateOne { + if v != nil { + _u.SetErrorMsg(*v) + } + return _u +} + +// SetIdempotencyKey sets the "idempotency_key" field. +func (_u *SyncFailureUpdateOne) SetIdempotencyKey(v string) *SyncFailureUpdateOne { + _u.mutation.SetIdempotencyKey(v) + return _u +} + +// SetNillableIdempotencyKey sets the "idempotency_key" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableIdempotencyKey(v *string) *SyncFailureUpdateOne { + if v != nil { + _u.SetIdempotencyKey(*v) + } + return _u +} + +// SetStatus sets the "status" field. +func (_u *SyncFailureUpdateOne) SetStatus(v string) *SyncFailureUpdateOne { + _u.mutation.SetStatus(v) + return _u +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableStatus(v *string) *SyncFailureUpdateOne { + if v != nil { + _u.SetStatus(*v) + } + return _u +} + +// SetRetryCount sets the "retry_count" field. +func (_u *SyncFailureUpdateOne) SetRetryCount(v int32) *SyncFailureUpdateOne { + _u.mutation.ResetRetryCount() + _u.mutation.SetRetryCount(v) + return _u +} + +// SetNillableRetryCount sets the "retry_count" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableRetryCount(v *int32) *SyncFailureUpdateOne { + if v != nil { + _u.SetRetryCount(*v) + } + return _u +} + +// AddRetryCount adds value to the "retry_count" field. +func (_u *SyncFailureUpdateOne) AddRetryCount(v int32) *SyncFailureUpdateOne { + _u.mutation.AddRetryCount(v) + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *SyncFailureUpdateOne) SetCreatedAt(v int64) *SyncFailureUpdateOne { + _u.mutation.ResetCreatedAt() + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableCreatedAt(v *int64) *SyncFailureUpdateOne { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// AddCreatedAt adds value to the "created_at" field. +func (_u *SyncFailureUpdateOne) AddCreatedAt(v int64) *SyncFailureUpdateOne { + _u.mutation.AddCreatedAt(v) + return _u +} + +// SetLastErrorAt sets the "last_error_at" field. +func (_u *SyncFailureUpdateOne) SetLastErrorAt(v int64) *SyncFailureUpdateOne { + _u.mutation.ResetLastErrorAt() + _u.mutation.SetLastErrorAt(v) + return _u +} + +// SetNillableLastErrorAt sets the "last_error_at" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableLastErrorAt(v *int64) *SyncFailureUpdateOne { + if v != nil { + _u.SetLastErrorAt(*v) + } + return _u +} + +// AddLastErrorAt adds value to the "last_error_at" field. +func (_u *SyncFailureUpdateOne) AddLastErrorAt(v int64) *SyncFailureUpdateOne { + _u.mutation.AddLastErrorAt(v) + return _u +} + +// SetHandledBy sets the "handled_by" field. +func (_u *SyncFailureUpdateOne) SetHandledBy(v string) *SyncFailureUpdateOne { + _u.mutation.SetHandledBy(v) + return _u +} + +// SetNillableHandledBy sets the "handled_by" field if the given value is not nil. +func (_u *SyncFailureUpdateOne) SetNillableHandledBy(v *string) *SyncFailureUpdateOne { + if v != nil { + _u.SetHandledBy(*v) + } + return _u +} + +// Mutation returns the SyncFailureMutation object of the builder. +func (_u *SyncFailureUpdateOne) Mutation() *SyncFailureMutation { + return _u.mutation +} + +// Where appends a list predicates to the SyncFailureUpdate builder. +func (_u *SyncFailureUpdateOne) Where(ps ...predicate.SyncFailure) *SyncFailureUpdateOne { + _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 *SyncFailureUpdateOne) Select(field string, fields ...string) *SyncFailureUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated SyncFailure entity. +func (_u *SyncFailureUpdateOne) Save(ctx context.Context) (*SyncFailure, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *SyncFailureUpdateOne) SaveX(ctx context.Context) *SyncFailure { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *SyncFailureUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *SyncFailureUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +func (_u *SyncFailureUpdateOne) sqlSave(ctx context.Context) (_node *SyncFailure, err error) { + _spec := sqlgraph.NewUpdateSpec(syncfailure.Table, syncfailure.Columns, sqlgraph.NewFieldSpec(syncfailure.FieldID, field.TypeInt)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SyncFailure.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, syncfailure.FieldID) + for _, f := range fields { + if !syncfailure.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != syncfailure.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.Direction(); ok { + _spec.SetField(syncfailure.FieldDirection, field.TypeString, value) + } + if value, ok := _u.mutation.BizType(); ok { + _spec.SetField(syncfailure.FieldBizType, field.TypeString, value) + } + if value, ok := _u.mutation.BizKey(); ok { + _spec.SetField(syncfailure.FieldBizKey, field.TypeString, value) + } + if value, ok := _u.mutation.Endpoint(); ok { + _spec.SetField(syncfailure.FieldEndpoint, field.TypeString, value) + } + if value, ok := _u.mutation.PayloadJSON(); ok { + _spec.SetField(syncfailure.FieldPayloadJSON, field.TypeString, value) + } + if value, ok := _u.mutation.ErrorMsg(); ok { + _spec.SetField(syncfailure.FieldErrorMsg, field.TypeString, value) + } + if value, ok := _u.mutation.IdempotencyKey(); ok { + _spec.SetField(syncfailure.FieldIdempotencyKey, field.TypeString, value) + } + if value, ok := _u.mutation.Status(); ok { + _spec.SetField(syncfailure.FieldStatus, field.TypeString, value) + } + if value, ok := _u.mutation.RetryCount(); ok { + _spec.SetField(syncfailure.FieldRetryCount, field.TypeInt32, value) + } + if value, ok := _u.mutation.AddedRetryCount(); ok { + _spec.AddField(syncfailure.FieldRetryCount, field.TypeInt32, value) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(syncfailure.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedCreatedAt(); ok { + _spec.AddField(syncfailure.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.LastErrorAt(); ok { + _spec.SetField(syncfailure.FieldLastErrorAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedLastErrorAt(); ok { + _spec.AddField(syncfailure.FieldLastErrorAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.HandledBy(); ok { + _spec.SetField(syncfailure.FieldHandledBy, field.TypeString, value) + } + _node = &SyncFailure{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{syncfailure.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/bj_power_wms/ent/tx.go b/bj_power_wms/ent/tx.go index 55a2ac7..56fb6a8 100644 --- a/bj_power_wms/ent/tx.go +++ b/bj_power_wms/ent/tx.go @@ -58,6 +58,8 @@ type Tx struct { StocktakeItem *StocktakeItemClient // StocktakeOrder is the client for interacting with the StocktakeOrder builders. StocktakeOrder *StocktakeOrderClient + // SyncFailure is the client for interacting with the SyncFailure builders. + SyncFailure *SyncFailureClient // SysConfig is the client for interacting with the SysConfig builders. SysConfig *SysConfigClient // User is the client for interacting with the User builders. @@ -218,6 +220,7 @@ func (tx *Tx) init() { tx.SemiFinished = NewSemiFinishedClient(tx.config) tx.StocktakeItem = NewStocktakeItemClient(tx.config) tx.StocktakeOrder = NewStocktakeOrderClient(tx.config) + tx.SyncFailure = NewSyncFailureClient(tx.config) tx.SysConfig = NewSysConfigClient(tx.config) tx.User = NewUserClient(tx.config) tx.Zone = NewZoneClient(tx.config) diff --git a/bj_power_wms/frontend/src/pages/SyncFailure.vue b/bj_power_wms/frontend/src/pages/SyncFailure.vue index 932c957..95eb302 100644 --- a/bj_power_wms/frontend/src/pages/SyncFailure.vue +++ b/bj_power_wms/frontend/src/pages/SyncFailure.vue @@ -2,7 +2,7 @@