diff --git a/bj_power_mes/bj_power_mes.go b/bj_power_mes/bj_power_mes.go index e594e4b..7b2fccf 100644 --- a/bj_power_mes/bj_power_mes.go +++ b/bj_power_mes/bj_power_mes.go @@ -33,6 +33,7 @@ import ( "bj_power_mes/internal/scanbridge" "bj_power_mes/internal/svc" "bj_power_mes/internal/tray" + "bj_power_mes/internal/wmsclient" "golang.org/x/sys/windows" winsvc "golang.org/x/sys/windows/svc" @@ -713,6 +714,30 @@ func runServe(c config.Config, asService bool) { } }) + // PLC 通讯失败预警(2026-11-16):连续失败首次沿触发(持续断连不重复触发), + // 预警侧 10 分钟窗口去重兜底防风暴;恢复后下次再断会重新触发。 + ctx.PLC.SetOnFail(func(failCtx context.Context, failErr error) { + fc, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + _, aerr := logic.New(ctx).CreateAlertDedup(fc, "plc_offline", "严重", "PLC", + "PLC 通讯失败:产线控制信号读写异常,点位状态可能与台账不一致,请检查 PLC 网络与电源。详情:"+failErr.Error(), 10) + if aerr != nil { + gologx.Errorf("PLC 通讯失败落预警异常: %v", aerr) + } + }) + + // WMS 通讯失败预警(2026-11-16):MES→WMS 传输层失败(连不上/超时)触发, + // 10 分钟窗口去重;HTTP 业务错误(服务在但拒绝)不算通讯异常、不触发。 + wmsclient.FailHook = func(hookCtx context.Context, method, url string, hookErr error) { + fc, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + _, aerr := logic.New(ctx).CreateAlertDedup(fc, "wms_unreachable", "警告", "WMS", + fmt.Sprintf("WMS 通讯失败:%s %s(%v),在制品/成品库存联动将失败,请检查 WMS 服务。", method, url, hookErr), 10) + if aerr != nil { + gologx.Errorf("WMS 通讯失败落预警异常: %v", aerr) + } + } + // 断电恢复启动对账(#8 T8,2026-11-03 补全):服务(含产线断电重启后)冷启动时, // 若 PLC 首连即成功则没有"失败→成功沿",T6 不会触发——这里延迟 15 秒补一次全量对账, // 比对 PLC 托盘位实读与 MES 在制工件记录,命中落预警中心(trigger=boot),不阻断启动。 diff --git a/bj_power_mes/etc/bj_power_mes-api.yaml b/bj_power_mes/etc/bj_power_mes-api.yaml index c7593d0..52ffb25 100644 --- a/bj_power_mes/etc/bj_power_mes-api.yaml +++ b/bj_power_mes/etc/bj_power_mes-api.yaml @@ -54,8 +54,8 @@ Plc: # 海康 AGV(RCS-Lite V1.5) 对接(2026-10-17 由 RCS-2000 改为 RCS-Lite 1.5):无签名鉴权 # 未接真实 RCS-Lite 前保持 mock(EnableMock: true);现场对接时填 EnableMock: false + BaseURL(默认端口 8182,含 /rCMS/services/rest/hikRpcService) Agv: - EnableMock: true - BaseURL: "" + EnableMock: false + BaseURL: "http://192.168.22.13:8182/rCMS/services/rest/hikRpcService" CarrierCode: "" MapCode: "" Priority: "1" diff --git a/bj_power_mes/frontend/src/help.js b/bj_power_mes/frontend/src/help.js index ba7b93d..29739e3 100644 --- a/bj_power_mes/frontend/src/help.js +++ b/bj_power_mes/frontend/src/help.js @@ -14,7 +14,7 @@ export const helpProductType = P('成品档案', '这里是成品型号的源头 { k: 'confuse', t: '三个编号别混', text: '产品工号是工单号(一批一个);产品编码是成品型号(多个工单可以是同一个型号);产品序号(SN) 是每台工件自己的号。MES 页面叫「成品档案」,不显示「图号」——成品没有图号,也没有物料编码;这两个字段属于原材料,是 WMS 物料档案的事。改产品编码会让已建工单找不到原来的型号,追溯也跟着断。' }, { k: 'states', t: '停用不是删除', text: '停用后新建工单的下拉里选不到它,但已经建好的工单、库存、追溯记录都还在,也还能查。这是唯一的下架方式,系统不物理删型号。' }, { k: 'confuse', t: '「序列号=是」决定什么', text: '它决定这台工件是按批次数量记账,还是一台一个号逐件扫。选「是」时,上线建档必须扫已在 WMS 入库登记过的来料 SN,不能让系统发号。产品分类只是个默认值,跟这件事没有绑定关系。新建成品时不需要选「类型」,表虽然和原材料共用,页面上不做这个选择。' }, - { k: 'complex', t: '同步失败时两种表现不一样', text: '单条建档或编辑即使 WMS 暂时不通,本系统也会先保存下来、标上待同步,之后点「重推」补上;Excel 批量导入则是整批一起成功或一起失败,不会出现半张表进去了的情况。导入模板和模板说明与 WMS 完全同款,改模板必须两端一起改。' }, + { k: 'complex', t: '同步失败时两种表现不一样', text: '单条建档或编辑即使 WMS 暂时不通,本系统也会先保存下来、标上待同步,之后点「重推」补上;Excel 批量导入则是整批一起成功或一起失败,不会出现半张表进去了的情况。导入模板与 WMS 大体同款(MES 无「类型」列、列名一致,均按表头名识别),改模板必须两端一起改。' }, { k: 'links', t: '上游下游', text: '上游是 WMS 物料档案(按编码互推);下游是产品工艺、工单管理、成品试验和工件追溯。' } ], [ { name: '产品工艺', path: '/process-flow', hint: '给型号定工序' }, @@ -49,16 +49,20 @@ export const helpWorkOrder = P('工单管理', '一张工单从建单到收尾 export const helpDailyPlan = P('日排产', '排产是算料和叫料的开关,不是一张待办清单。', [ { k: 'role', t: '这页解决什么', text: '把工单总台数摊到每一天,系统据此算「今天该领多少料」并生成叫料需求。没排产的工单不参与算料。' }, - { k: 'states', t: '排产状态与「已启用」', items: [ - 'PENDING 未确认 → CONFIRMED 已确认 → PROCESSING 执行中 → DONE 已完成;CANCELLED 是已取消。', - '「已启用」是算料开关:只有已确认/执行中的排产会参与备料清单和叫料需求计算。未启用不等于已取消,只是暂时不算料。', - '列表默认筛「未完成(排除已完成/已取消)」,是为了只看还要干活的日子,不是把历史数据删了。' + { k: 'states', t: '执行状态各值的意思', items: [ + '全部:不过滤,所有排产都显示。', + '未完成:不是一种状态,是组合筛选——「已完成」和「已取消」以外的都算(未启用/已启用/执行中都会显示)。列表默认选它,是为了只看还要干活的日子。', + '未启用(PENDING):新建或批量排产后的初始状态,只是计划,不参与算料。', + '已启用(CONFIRMED):人工点「启用」且工单已在进行中才能到这一态;只有已启用的排产参与备料清单和叫料需求计算。', + '执行中(PROCESSING):工单开工或当天首台完工后自动进入;工位终端能看到这一天的活,但目前不参与叫料需求计算。', + '已完成(DONE):这一天计划量做满,或所属工单完工且足额。', + '已取消(CANCELLED):工单取消,或工单已完工但这天没排满。' ] }, { k: 'confuse', t: '「显示历史」和状态筛选各管各的', text: '默认只看今天起 30 天。想看过去,勾「显示历史」并把日期范围清空;状态选「全部」才不会被「未完成」过滤掉。两个筛选互不影响,只改一个会以为没数据。' }, { k: 'confuse', t: '送达接驳台为什么显示中文', text: '列里显示的是「左 / 右」这样的中文接驳台名称,不是 DOCK 编码。工位 2、4、6、8、10 的左右按操作员「背向主线」的视角统一,和图纸上顺向看是反的,这是现场约定。' }, { k: 'irreversible', t: '停用 vs 删除', text: '停用只是让这一天不参与算料;删除会把这一天从计划里拿掉,已生成的备料与叫料需求会跟着变。调整前先看这一天的备料单是否已经发出。' }, { k: 'confuse', t: '数量为什么加不上去', text: '同一张工单各天的计划数量加起来不能超过工单总台数,系统会按累计量卡住。要加量得先改工单数量或补料审批,不是在排产里硬填。排产量可以大于当前库存,系统只预警不拦截。' }, - { k: 'complex', t: '历史透视与对比', text: '历史排产也能透视、能导出,导出的规划可以和历史规划做对比;「逐日消耗模拟」和「各工单排产支撑」都带分页,逐日消耗按实时库存变化算,别拿一次导出当永久快照。' } + { k: 'complex', t: '透视与对比目前只覆盖未完成', text: '「按日期透视」和「按工单折叠」强制只显示未完成的工单,已完工/已取消的历史排产进不了透视;「对比/导出差异」算的是计划数与已完成数的差额账,不是两份规划快照的对比。想看历史完工情况,把日期范围调到过去、状态选「全部」看列表。历史排产的整体透视、规划导出与规划对比尚未实现,属待实现需求。「逐日消耗模拟」和「各工单排产支撑」都带分页,逐日消耗按实时库存变化算,别拿一次导出当永久快照。' } ], [ { name: '工单管理', path: '/work-order' }, { name: '叫料单', path: '/material-request', hint: '排产算出来的需求' }, @@ -322,7 +326,7 @@ export const helpPlc = P('工位下发', '把某张工单要经过的工位组 export const helpPlcMonitor = P('PLC管理', '本页手动写点位,按钮按下去就真下发给 PLC 了。', [ { k: 'role', t: '这页解决什么', text: '设备联调、异常处置时给维护人员一个直接读写 PLC 点位、看在途指令的入口。日常生产不需要在这里操作。' }, { k: 'states', t: '在途与模拟数据', text: '在途=MW 寄存器非 0,同一工位有在途指令时新的手动下发会被互斥挡掉。页面标了「模拟数据」时,看到的是 mock 点位状态,别拿它判断现场实物。本页不自动刷新,要看最新状态得手动刷新。' }, - { k: 'irreversible', t: '强制清零', text: '二次确认 + 勾选现场安全后才执行,只清 PLC 的在途标记,不回滚 MES 台账、不撤销已经报过的工。清零之前务必在实物上确认工件位置。' }, + { k: 'irreversible', t: '强制清零到底动了什么', text: '它改的是 PLC 内存里的一条「搬运任务便签」:把约定好的在途指令寄存器(M 区一个字)写成 0,不是删 PLC 程序、不动 DB 块和传感器位,PLC 不会因此停机或损坏;MES 侧只留一条操作日志,不回滚台账、不撤销已报的工。真正的危险是清早了——托盘还在搬运中就把它清零,上位机会误判这趟搬运已完成,可能接着下发新指令,两个动作撞在一起。所以必须现场确认工件真卡住、PLC 已经不动作了再点。矫正对象是 PLC 本身,不是 MES 数据库;越界地址一律拒绝,只允许清约定范围内的在途指令字。' }, { k: 'complex', t: '被拦下来时先分清是谁拦的', text: '「已有在途指令」和「多工单缓存策略=严格隔离」是两道不同的检查。前一种无论哪种策略都会先拦,看起来像策略问题其实不是。' }, { k: 'complex', t: '多工单缓存策略在这页会看到什么', text: '这个策略除了管报工后的自动流转(详见「基础设置」帮助),也管本页手动下发:目标必须是 C 类主线位置、而且是可缓存位(C2/C3/C5/C6/C8/C9/C11/C12/C14),MES 台账显示被别的工单占着时,严格隔离会拒绝这次下发并报出占用的 SN 和工单号。切回物理优先就能下发,改完立刻生效。' } ], [ diff --git a/bj_power_mes/frontend/src/pages/DailyPlan.vue b/bj_power_mes/frontend/src/pages/DailyPlan.vue index 8a8d0bc..df3fda6 100644 --- a/bj_power_mes/frontend/src/pages/DailyPlan.vue +++ b/bj_power_mes/frontend/src/pages/DailyPlan.vue @@ -22,7 +22,7 @@ - + @@ -58,6 +58,7 @@ 查询 重置 对比 + 计划vs实际 新建排产 @@ -303,6 +304,31 @@ 计划合计:{{ compare.summary.planTotal ?? 0 }} 完成合计:{{ compare.summary.doneTotal ?? 0 }} 差异合计:{{ compare.summary.diffTotal ?? 0 }} 工单数:{{ compare.summary.orderCount ?? 0 }} + + +
+ + 查询 + 导出 + 实际完成=完工流水(与生产流程卡同源)按天聚合;负差异=欠产 +
+ + + + + + + + + + + + +
@@ -316,6 +342,7 @@ diff --git a/bj_power_mes/frontend/src/pages/ProductType.vue b/bj_power_mes/frontend/src/pages/ProductType.vue index a871dc5..2ea6e3b 100644 --- a/bj_power_mes/frontend/src/pages/ProductType.vue +++ b/bj_power_mes/frontend/src/pages/ProductType.vue @@ -1,7 +1,6 @@
-
一、字段说明(成品档案模板 9 列;Excel 首行表头按名称识别,请勿改动表头文字)
+
一、字段说明(成品档案模板 7 列;Excel 首行表头按名称识别,请勿改动表头文字)
- - - - - - - - - - + + + + + + +
列字段必填格式说明
1图号是字符串,唯一物料唯一标识(两库同步业务键);成品可留空自动生成 PROD-YYYYMMDD-流水,原材料必填
2物料编码否字符串普通档案字段(如 WL-0001),不参与业务与必填校验
3名称是字符串物料名称
4规格是字符串规格型号
5单位是字符串如「个」「件」「套」
6类别否成品/原材料默认成品(MES 口径;WMS 侧叫「物料类别」,留空默认原材料)
7序列号否是/否成品强制是,原材料可选(WMS 导入忽略本列,按类型自动派生)
8启用否是/否默认是(WMS 导入忽略本列,默认启用)
9说明否字符串备注
1名称是字符串物料名称
2规格是字符串规格型号
3单位是字符串如「个」「件」「套」
4类别否成品只能填「成品」;原材料请在 WMS 物料档案维护(不在本端导入)
5序列号否—成品强制「是」,无需填写
6启用否是/否默认是
7说明否字符串备注
-
下载模板含 2 行示例数据(导入前请删除)与「填写说明」页逐列说明。
+
成品编码(图号)由系统自动生成(PROD-年月日-流水,递增且唯一),物料编码统一为空,均无需填写。下载模板含 1 行示例数据(导入前请删除)与「填写说明」页逐列说明。
二、常见错误
- · 图号重复:系统中已存在相同图号,该行被拒绝
+ · 类别填了「原材料」:MES 成品导入仅限成品,请在 WMS 物料档案维护原材料
· 物料类型不出现在模板中:系统一律按成品逻辑默认(类型=其他、序列号=是)
- · 类别不在枚举内:只能填「成品」或「原材料」
· 名称/规格/单位为空:必填列不可为空;任一行出错则整批回退,一行不写
· WMS 不可达:本端导入先逐行写 WMS,WMS 失败整批取消
@@ -60,8 +58,7 @@ - - + @@ -103,32 +100,13 @@ - - - - - + - - - - - - - - - - - 是 - 否 - - 是=逐件录序列号,否=按数量(不录序列号) - @@ -166,16 +144,13 @@ const list = ref([]) const total = ref(0) const page = ref(1) const pageSize = ref(20) -const filters = reactive({ code: '', name: '', spec: '', isActive: '', manageMode: '', snMode: '', startDate: '', endDate: '' }) -// 类型(manageMode)与是否逐件SN管理(snMode)解耦(2026-09-30): -// snMode 必选(0=未选择不可保存);选类型自动带默认(电气件→序列号=是,结构件/其他→序列号=否),可手改 -const dialog = reactive({ show: false, id: 0, name: '', code: '', materialCode: '', spec: '', unit: '', manageMode: 3, snMode: 1, description: '', isActive: true }) +const filters = reactive({ name: '', spec: '', isActive: '', startDate: '', endDate: '' }) +// 2026-11-16 用户定案:界面不再出现图号/物料编码/类型/序列号,全部由后端注入或自动生成 +//(类型=3 其他、序列号=是、编码留空由 genProductTypeCode 生成 PROD-YYYYMMDD-流水、物料编码强制空串)。 +// dialog.code 仅保留用于附件挂靠(biz-id=编码)。 +const dialog = reactive({ show: false, id: 0, name: '', code: '', spec: '', unit: '', description: '', isActive: true }) const attachDrawer = reactive({ visible: false, code: '', name: '' }) -function onTypeChange(v) { - dialog.snMode = v === 2 ? 1 : 2 -} - function defaultRange() { const d = new Date() const p = (n) => String(n).padStart(2, '0') @@ -186,18 +161,15 @@ function defaultRange() { } Object.assign(filters, defaultRange()) -// 2026-09-08 禁止关键字混搜:编码/名称各筛选框独立传参,后端各自模糊匹配 +// 禁止关键字混搜:名称/规格各筛选框独立传参,后端各自模糊匹配 function trim(s) { return (s || '').trim() } async function load() { const params = { page: page.value, pageSize: pageSize.value, - code: trim(filters.code), name: trim(filters.name), spec: trim(filters.spec), - manageMode: filters.manageMode, - snMode: filters.snMode, isActive: filters.isActive, startDate: filters.startDate, endDate: filters.endDate @@ -224,34 +196,32 @@ async function retrySync(row) { } function resetFilters() { - Object.assign(filters, { code: '', name: '', spec: '', isActive: '', manageMode: '', snMode: '' }, defaultRange()) + Object.assign(filters, { name: '', spec: '', isActive: '' }, defaultRange()) page.value = 1 load() } async function openAdd() { - Object.assign(dialog, { show: true, id: 0, name: '', code: '', materialCode: '', spec: '', unit: '', manageMode: 3, snMode: 1, description: '', isActive: true }) + Object.assign(dialog, { show: true, id: 0, name: '', code: '', spec: '', unit: '', description: '', isActive: true }) } function openEdit(row) { Object.assign(dialog, { - show: true, id: row.id, name: row.name, code: row.code, materialCode: row.materialCode || '', spec: row.spec || '', unit: row.unit || '', - manageMode: row.manageMode ?? 0, snMode: row.snMode ?? 0, description: row.description || '', isActive: row.isActive + show: true, id: row.id, name: row.name, code: row.code, spec: row.spec || '', unit: row.unit || '', + description: row.description || '', isActive: row.isActive }) } async function save() { - // 必填口径:名称/规格/单位/图号(图号仅新建必填、编辑不可改;MES 图号不允许为空,与 WMS 成品可空自动生成不同)+ 类型 + 序列号(序列号=是/否) + // 必填口径(2026-11-16 用户定案):仅名称/规格/单位必填;编码由后端留空自动生成(logic/product.go:117-123), + // 类型/序列号由后端按成品注入默认值(logic/product.go:108-113);物料编码强制空字符串(不参与两库互推,product_import.go:307)。 if (!trim(dialog.name)) return ElMessage.warning('名称为必填项') if (!trim(dialog.spec)) return ElMessage.warning('规格型号为必填项') if (!trim(dialog.unit)) return ElMessage.warning('单位为必填项') - if (!dialog.id && !trim(dialog.code)) return ElMessage.warning('图号为必填项(创建后不可改)') - if (![1, 2, 3].includes(dialog.manageMode)) return ElMessage.warning('请选择类型') - if (dialog.snMode !== 1 && dialog.snMode !== 2) return ElMessage.warning('请选择序列号(是=逐件录序列号 / 否=按数量(不录序列号))') const body = { name: trim(dialog.name), spec: trim(dialog.spec), unit: trim(dialog.unit), description: dialog.description, - materialCode: dialog.materialCode, manageMode: dialog.manageMode, snMode: dialog.snMode, isActive: dialog.isActive + materialCode: '', manageMode: 3, snMode: 1, isActive: dialog.isActive } if (dialog.id) await request.put('/product-types', { id: dialog.id, ...body }) - else await request.post('/product-types', { code: trim(dialog.code), ...body }) + else await request.post('/product-types', body) ElMessage.success('保存成功') dialog.show = false load() @@ -346,7 +316,7 @@ async function exportXlsx() { filters.endDate = r.end } const params = { - code: trim(filters.code), name: trim(filters.name), + name: trim(filters.name), spec: trim(filters.spec), isActive: filters.isActive, startDate: filters.startDate, endDate: filters.endDate diff --git a/bj_power_mes/frontend/vite.config.js b/bj_power_mes/frontend/vite.config.js index e654356..9f80da1 100644 --- a/bj_power_mes/frontend/vite.config.js +++ b/bj_power_mes/frontend/vite.config.js @@ -1,5 +1,22 @@ import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' +import fs from 'node:fs' +import path from 'node:path' + +// 后端端口单一真源:读后端 yaml 顶层 Port(改端口只改 etc/*.yaml 一处,开发态 proxy 自动联动)。 +// 仅 npm run dev 时生效;npm run build 产物与 Go 网关同源,proxy 不参与。读不到时回退 fallback(行为不变)。 +function backendPort(yamlRel, fallback) { + try { + const yamlPath = path.resolve(process.cwd(), yamlRel) + const m = fs.readFileSync(yamlPath, 'utf-8').match(/^Port:\s*(\d+)\s*$/m) + if (m) return Number(m[1]) + } catch (e) { + console.warn(`[vite.config] 未读到 ${yamlRel} 的 Port,proxy 回退 ${fallback}`) + } + return fallback +} + +const apiTarget = `http://localhost:${backendPort('../etc/bj_power_mes-api.yaml', 8888)}` // 构建产物直接写入 Go 嵌入静态目录(main.go go:embed public) export default defineConfig({ @@ -17,9 +34,9 @@ export default defineConfig({ host: true, proxy: { '/api': { - target: 'http://localhost:8888', + target: apiTarget, changeOrigin: true } } } -}) \ No newline at end of file +}) diff --git a/bj_power_mes/internal/agv/client.go b/bj_power_mes/internal/agv/client.go index 3178a36..b946786 100644 --- a/bj_power_mes/internal/agv/client.go +++ b/bj_power_mes/internal/agv/client.go @@ -16,6 +16,7 @@ import ( "time" "github.com/google/uuid" + "github.com/zeromicro/go-zero/core/logx" "bj_power_mes/internal/config" ) @@ -106,21 +107,29 @@ func (c *realClient) call(ctx context.Context, path string, payload map[string]a if err != nil { return err } - req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.url(path), bytes.NewReader(body)) + reqURL := c.url(path) + // 2026-11-16 联调:AGV 全量 HTTP 交互落日志(请求 URL/报文 + 响应状态/响应体),grep "[AGV]" 可见。 + logx.WithContext(ctx).Infof("[AGV] --> POST %s payload=%s", reqURL, string(body)) + + req, err := http.NewRequestWithContext(ctx, http.MethodPost, reqURL, bytes.NewReader(body)) if err != nil { + logx.WithContext(ctx).Errorf("[AGV] <-- build request error url=%s err=%v", reqURL, err) return err } req.Header.Set("Content-Type", "application/json;charset=UTF-8") resp, err := c.hc.Do(req) if err != nil { + logx.WithContext(ctx).Errorf("[AGV] <-- transport error url=%s err=%v", reqURL, err) return err } defer resp.Body.Close() raw, err := io.ReadAll(resp.Body) if err != nil { + logx.WithContext(ctx).Errorf("[AGV] <-- read body error url=%s httpStatus=%d err=%v", reqURL, resp.StatusCode, err) return err } + logx.WithContext(ctx).Infof("[AGV] <-- HTTP %d url=%s body=%s", resp.StatusCode, reqURL, string(raw)) if resp.StatusCode >= 400 { return fmt.Errorf("agv http %d: %s", resp.StatusCode, string(raw)) } @@ -130,6 +139,7 @@ func (c *realClient) call(ctx context.Context, path string, payload map[string]a } // 成功码固定字符串 "0"(§1.5 结果码定义) if env.Code != "0" { + logx.WithContext(ctx).Errorf("[AGV] <-- biz error url=%s code=%s message=%s reqCode=%v", reqURL, env.Code, env.Message, payload["reqCode"]) return fmt.Errorf("agv code=%s message=%s", env.Code, env.Message) } if out != nil && len(env.Data) > 0 { @@ -290,20 +300,24 @@ func newMockClient() *mockClient { return &mockClient{} } func (m *mockClient) SubmitTask(ctx context.Context, taskCode, fromDock, toDock, carrierCode, templateType, agvCode string) (string, error) { // 模拟立即成功下发,返回我方 taskCode(与真实客户端一致,HikTaskCode=taskNo) + logx.WithContext(ctx).Infof("[AGV][MOCK] SubmitTask taskCode=%s %s->%s template=%s agvCode=%s(模拟下发成功,未发真实 HTTP)", taskCode, fromDock, toDock, templateType, agvCode) return taskCode, nil } func (m *mockClient) QueryTask(ctx context.Context, taskCode string) (string, string, error) { // 模拟:MOCK 任务一律视为已结束,便于离线联调观察"待搬运→已到位";模拟模式无真实分车,agvCode 为空 + logx.WithContext(ctx).Infof("[AGV][MOCK] QueryTask taskCode=%s(模拟返回已结束)", taskCode) return "9", "", nil } func (m *mockClient) CancelTask(ctx context.Context, taskCode, reason string) error { + logx.WithContext(ctx).Infof("[AGV][MOCK] CancelTask taskCode=%s reason=%s(模拟取消成功)", taskCode, reason) return nil } // QueryAgvStatus Mock:返回两台示例车(一台空闲、一台执行中),便于联调展示。 func (m *mockClient) QueryAgvStatus(ctx context.Context) ([]AgvVehicle, error) { + logx.WithContext(ctx).Infof("[AGV][MOCK] QueryAgvStatus(模拟返回样例车 9001/9002)") return []AgvVehicle{ {RobotCode: "9001", Battery: 99, Status: "4", PodCode: "0", PosX: 20000, PosY: 20000, Stop: false}, {RobotCode: "9002", Battery: 78, Status: "2", PodCode: "100001", PosX: 35000, PosY: 12000, Stop: false}, diff --git a/bj_power_mes/internal/handler/production/dailyplan_compare.go b/bj_power_mes/internal/handler/production/dailyplan_compare.go index 1a5bed0..4f6d6d8 100644 --- a/bj_power_mes/internal/handler/production/dailyplan_compare.go +++ b/bj_power_mes/internal/handler/production/dailyplan_compare.go @@ -59,3 +59,47 @@ func DailyPlanCompareExportHandler(svcCtx *svc.ServiceContext) http.HandlerFunc _, _ = w.Write(buf.Bytes()) } } + +// DailyPlanAttainmentHandler GET /daily-plans/attainment?start=&end= 计划 vs 实际(完工流水汇聚,2026-11-16)。 +func DailyPlanAttainmentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + q := r.URL.Query() + res, err := logic.New(svcCtx).DailyPlanAttainment(r.Context(), q.Get("start"), q.Get("end")) + if err != nil { + httpx.Fail(w, 3603, err.Error()) + return + } + httpx.Ok(w, res) + } +} + +// DailyPlanAttainmentExportHandler GET /daily-plans/attainment/export?start=&end= 直出 xlsx。 +func DailyPlanAttainmentExportHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + q := r.URL.Query() + res, err := logic.New(svcCtx).DailyPlanAttainment(r.Context(), q.Get("start"), q.Get("end")) + if err != nil { + httpx.Fail(w, 3604, err.Error()) + return + } + f := excelize.NewFile() + const sheet = "计划vs实际" + _ = f.SetSheetName("Sheet1", sheet) + headers := []interface{}{"日期", "工单号", "计划数量", "实际完成", "差异"} + _ = f.SetSheetRow(sheet, "A1", &headers) + for i, it := range res { + row := []interface{}{it.Date, it.OrderNo, it.PlanQty, it.DoneQty, it.Diff} + _ = f.SetSheetRow(sheet, "A"+strconv.Itoa(i+2), &row) + } + buf, e := f.WriteToBuffer() + _ = f.Close() + if e != nil { + httpx.Fail(w, 3604, "生成 Excel 失败:"+e.Error()) + return + } + w.Header().Set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") + w.Header().Set("Content-Disposition", + "attachment; filename=\"daily_plan_attainment.xlsx\"; filename*=UTF-8''"+url.PathEscape("日排产计划vs实际.xlsx")) + _, _ = w.Write(buf.Bytes()) + } +} diff --git a/bj_power_mes/internal/handler/production/production.go b/bj_power_mes/internal/handler/production/production.go index a84d37e..2a6bc64 100644 --- a/bj_power_mes/internal/handler/production/production.go +++ b/bj_power_mes/internal/handler/production/production.go @@ -226,11 +226,16 @@ func OrderQueryInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { orderNo := r.URL.Query().Get("orderNo") keyword := r.URL.Query().Get("keyword") status := r.URL.Query().Get("status") + // firstStation(2026-11-16 上线建档下拉专用):>0 时只返回第1道工序候选工位含该工位的工单 + firstStation := 0 + if n, e := strconv.Atoi(r.URL.Query().Get("stationNo")); e == nil && n > 0 { + firstStation = n + } limit := 0 if n, e := strconv.Atoi(r.URL.Query().Get("limit")); e == nil && n > 0 { limit = n } - list, err := logic.New(svcCtx).ListWorkOrders(r.Context(), orderNo, status, "", "", "", "", keyword, limit, 0) + list, err := logic.New(svcCtx).ListWorkOrders(r.Context(), orderNo, status, "", "", "", "", keyword, limit, 0, firstStation) if err != nil { httpx.Fail(w, 2004, err.Error()) return diff --git a/bj_power_mes/internal/handler/production/workorder.go b/bj_power_mes/internal/handler/production/workorder.go index 7ec5cb7..0275754 100644 --- a/bj_power_mes/internal/handler/production/workorder.go +++ b/bj_power_mes/internal/handler/production/workorder.go @@ -244,7 +244,7 @@ func ListWorkOrdersHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { data, err := logic.New(svcCtx).ListWorkOrders(r.Context(), q.Get("orderNo"), q.Get("status"), q.Get("productCode"), q.Get("productName"), q.Get("contractNo"), q.Get("ownershipType"), - q.Get("keyword"), limit, offset) + q.Get("keyword"), limit, offset, 0) if err != nil { httpx.Fail(w, 3004, err.Error()) return diff --git a/bj_power_mes/internal/handler/routes_production.go b/bj_power_mes/internal/handler/routes_production.go index 245328e..97879ac 100644 --- a/bj_power_mes/internal/handler/routes_production.go +++ b/bj_power_mes/internal/handler/routes_production.go @@ -628,6 +628,9 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext // ---------- 日排产历史对比(问题4):查询 + xlsx 导出 ---------- {Method: http.MethodGet, Path: "/daily-plans/compare", Handler: production.DailyPlanCompareHandler(serverCtx)}, {Method: http.MethodGet, Path: "/daily-plans/compare/export", Handler: production.DailyPlanCompareExportHandler(serverCtx)}, + // ---------- 计划 vs 实际(2026-11-16 死结6:完工流水汇聚,不建新表) ---------- + {Method: http.MethodGet, Path: "/daily-plans/attainment", Handler: production.DailyPlanAttainmentHandler(serverCtx)}, + {Method: http.MethodGet, Path: "/daily-plans/attainment/export", Handler: production.DailyPlanAttainmentExportHandler(serverCtx)}, // ---------- 工单 SN 前缀(问题5):仅 CREATED 可改,事务重生成全部 SN ---------- {Method: http.MethodPost, Path: "/work-orders/sn-prefix", Handler: production.SnPrefixHandler(serverCtx)}, // ---------- 待办统计快照(问题8):WebSocket 长连接见下方单独注册 ---------- diff --git a/bj_power_mes/internal/logic/agv.go b/bj_power_mes/internal/logic/agv.go index a1f12f6..6b4f7b7 100644 --- a/bj_power_mes/internal/logic/agv.go +++ b/bj_power_mes/internal/logic/agv.go @@ -193,6 +193,7 @@ func (s *Service) SubmitAgv(ctx context.Context, req AgvSubmitRequest, operator } // 第一段不指定车(用户拍板):RCS 自由派车,到位后回写 agv_code 作为本链锁定车 if _, aerr := s.ctx.Agv.SubmitTask(ctx, taskNo, source, r.phys, "", submitTmpl, ""); aerr != nil { + s.agvRcsCommFail(ctx, "下发 "+source+"→"+r.phys, aerr) s.ctx.EntClient.AgvTask.UpdateOneID(t.ID). SetStatus("FAILED").SetRemark("RCS下发失败: " + aerr.Error()).Exec(ctx) failed = append(failed, target) @@ -282,6 +283,17 @@ func (s *Service) DispatchCallAgv(ctx context.Context, requestNo, operator strin return s.DispatchAgvForCall(ctx, mr, operator) } +// agvRcsCommFail AGV↔RCS 通讯失败统一落预警(2026-11-16): +// 下发/查询/取消任一环节传输失败都算通讯异常,落「agv_rcs_fail」预警(10 分钟窗口去重防轮询风暴)。 +// target 固定 "AGV"(预警中心按对象归集);best-effort,落预警失败仅打日志不阻断主流程。 +func (s *Service) agvRcsCommFail(ctx context.Context, where string, err error) { + _, aerr := s.CreateAlertDedup(ctx, "agv_rcs_fail", "警告", "AGV", + "AGV 调度系统(RCS)通讯失败【"+where+"】:"+err.Error()+",请检查 RCS 服务与网络。", 10) + if aerr != nil { + fmt.Println("AGV 通讯失败落预警异常:", aerr) + } +} + // DispatchAgvForCall 业务配送单派车(2026-11-13 拍板:独立「手动派车/叫料派车」入口下线, // 只由仓库备料完成等业务配送链路触发;前端不再有可直调的手动派车路由): // 由库管在 WMS 叫料队列点「送货」(DispatchCallAgv)调用——生成「空车前往装货点(JBT21)」段 @@ -441,6 +453,8 @@ func (s *Service) RefreshAgvTasks(ctx context.Context) (int, error) { for _, t := range list { st, agvCode, qerr := s.ctx.Agv.QueryTask(ctx, t.TaskNo) if qerr != nil { + // 2026-11-16:查询失败不再静默,落通讯预警(去重窗口防轮询风暴) + s.agvRcsCommFail(ctx, "查询任务 "+t.TaskNo, qerr) continue } // 工位专用接驳台取货:GO_LOAD 到工位后直接装车并送回库房,工位侧零确认。 @@ -587,6 +601,7 @@ func (s *Service) RetryAgvTask(ctx context.Context, taskNo, operator string) err // 指定车重试(同段同车):任务行已回写 agv_code 时沿用,未回写传空由 RCS 自由派 _, aerr := s.ctx.Agv.SubmitTask(ctx, taskNo, t.SourceDock, t.TargetDock, "", submitTmpl, t.AgvCode) if aerr != nil { + s.agvRcsCommFail(ctx, "重试下发 "+t.SourceDock+"→"+t.TargetDock, aerr) s.ctx.EntClient.AgvTask.UpdateOneID(t.ID). SetStatus("FAILED").SetRemark("RCS重试下发失败: " + aerr.Error()).Exec(ctx) return fmt.Errorf("RCS 重试下发失败: %w", aerr) @@ -804,6 +819,7 @@ func (s *Service) dispatchAgvSegment(ctx context.Context, in agvSegInput) (strin if tmpl == "LIFT" { submitTmpl = s.CfgStr(ctx, CfgAgvTaskTypLift, "B01") } else { submitTmpl = s.CfgStr(ctx, CfgAgvTaskTypPlain, "B02") } _, aerr := s.ctx.Agv.SubmitTask(ctx, taskNo, in.Source, in.Target, "", submitTmpl, in.AgvCode) if aerr != nil { + s.agvRcsCommFail(ctx, "下发 "+in.Source+"→"+in.Target, aerr) s.ctx.EntClient.AgvTask.UpdateOneID(t.ID). SetStatus("FAILED").SetRemark("RCS下发失败: " + aerr.Error()).Exec(ctx) return "", aerr diff --git a/bj_power_mes/internal/logic/alert.go b/bj_power_mes/internal/logic/alert.go index 88e974f..3ba9513 100644 --- a/bj_power_mes/internal/logic/alert.go +++ b/bj_power_mes/internal/logic/alert.go @@ -141,6 +141,32 @@ func (s *Service) CreateAlert(ctx context.Context, typ, level, target, message s return err } +// CreateAlertDedup 带时间窗去重的预警创建(2026-11-16 通信类预警专用): +// 同 type+target 在 windowMin 分钟内已有 UNREAD 预警时跳过,防轮询场景刷爆预警中心。 +// 返回 (true, nil)=实际落库;(false, nil)=窗口内已有同款被去重。 +func (s *Service) CreateAlertDedup(ctx context.Context, typ, level, target, message string, windowMin int) (bool, error) { + if windowMin <= 0 { + windowMin = 10 + } + if windowMin > 1440 { + windowMin = 1440 // 上限 1 天,防误传超长窗口永久吞预警 + } + since := time.Now().Add(-time.Duration(windowMin) * time.Minute) + cnt, cerr := s.ctx.EntClient.Alert.Query().Where( + alert.TypeEQ(typ), + alert.StatusEQ("UNREAD"), + alert.TargetEQ(target), + alert.CreatedAtGTE(since), + ).Count(ctx) + if cerr == nil && cnt > 0 { + return false, nil + } + if err := s.CreateAlert(ctx, typ, level, target, message); err != nil { + return false, err + } + return true, nil +} + // publishStationAlert 报警写入成功后经 SSE Hub 广播 station.alert 事件(载荷=报警 JSON)。 // 终端侧按「工位N」自行过滤(Hub 是广播语义,按工位点对点过滤交给唯一消费者=终端后端)。 func (s *Service) publishStationAlert(a *ent.Alert) { diff --git a/bj_power_mes/internal/logic/dailyplan.go b/bj_power_mes/internal/logic/dailyplan.go index 6af65cf..5c95b86 100644 --- a/bj_power_mes/internal/logic/dailyplan.go +++ b/bj_power_mes/internal/logic/dailyplan.go @@ -261,15 +261,15 @@ func (s *Service) SuggestedDockCodes(ctx context.Context, orderNo string) []stri } // syncPlansByOrderStatus 工单状态联动日排产: -// - 工单 → IN_PROGRESS:该工单 PENDING 排产置 PROCESSING(开始执行) -// - 工单 → DONE:已足额完工(completedQty>=planQty)的排产置 DONE;其余未完成排产置 CANCELLED -// - 工单 → CANCELLED:该工单未完成(PENDING/PROCESSING)排产全部置 CANCELLED +// - 工单 → IN_PROGRESS:该工单 PENDING 排产置 PROCESSING(开始执行);CONFIRMED 保持不变(算料开关语义,2026-11-16) +// - 工单 → DONE:已足额完工(completedQty>=planQty)的排产置 DONE;其余未完成排产置 CANCELLED(含 CONFIRMED) +// - 工单 → CANCELLED:该工单未完成(PENDING/CONFIRMED/PROCESSING)排产全部置 CANCELLED func (s *Service) syncPlansByOrderStatus(ctx context.Context, orderNo, woStatus, operator string) { if orderNo == "" { return } plans, err := s.ctx.EntClient.DailyPlan.Query(). - Where(dailyplan.OrderNo(orderNo), dailyplan.StatusIn("PENDING", "PROCESSING")).All(ctx) + Where(dailyplan.OrderNo(orderNo), dailyplan.StatusIn("PENDING", "CONFIRMED", "PROCESSING")).All(ctx) if err != nil { return } @@ -278,6 +278,9 @@ func (s *Service) syncPlansByOrderStatus(ctx context.Context, orderNo, woStatus, for _, p := range plans { switch woStatus { case "IN_PROGRESS": + if p.Status == "CONFIRMED" { + continue // 已启用排产不随工单开工转 PROCESSING,保持算料参与资格 + } to = "PROCESSING" case "DONE": if p.CompletedQty >= p.PlanQty { @@ -435,7 +438,7 @@ type ForScheduleWorkOrder struct { // ListWorkOrdersForSchedule 返回未排满(剩余可排 > 0)的工单,供日排产工单号下拉过滤。 // 与 /daily-plans/unplanned("完全未排产"横幅入口)区分:本接口包含"部分排产"的工单。 func (s *Service) ListWorkOrdersForSchedule(ctx context.Context, keyword string) ([]*ForScheduleWorkOrder, error) { - wos, err := s.ListWorkOrders(ctx, "", "", "", "", "", "", keyword, 0, 0) + wos, err := s.ListWorkOrders(ctx, "", "", "", "", "", "", keyword, 0, 0, 0) if err != nil { return nil, err } diff --git a/bj_power_mes/internal/logic/dailyplan_attainment.go b/bj_power_mes/internal/logic/dailyplan_attainment.go new file mode 100644 index 0000000..2f6046e --- /dev/null +++ b/bj_power_mes/internal/logic/dailyplan_attainment.go @@ -0,0 +1,95 @@ +package logic + +import ( + "context" + "errors" + "sort" + "time" + + "bj_power_mes/ent/dailyplan" + "bj_power_mes/ent/workpiecelifecyclelog" +) + +// DailyPlanAttainmentRow 计划 vs 实际对比行(2026-11-16 死结6 定案)。 +// 用户口径:不是历史排产对比,是「排了 10 个,那天实际做出了几个」的实际执行结果; +// 维度=现有日排产字段(排产日期/工单/计划数/实际数/差异),要看明细跳生产流程卡。 +type DailyPlanAttainmentRow struct { + Date string `json:"date"` // 排产/完工日期 + OrderNo string `json:"orderNo"` // 工单号(产品工号) + PlanQty int `json:"planQty"` // 该日期该工单排产计划合计 + DoneQty int `json:"doneQty"` // 该日期该工单实际完工台数(完工流水聚合) + Diff int `json:"diff"` // 实际 - 计划(负=欠产,正=超产) +} + +// DailyPlanAttainment 计划 vs 实际(不建新表,直接汇聚,2026-11-16): +// - 计划 = daily_plan 各状态排产行按 (plan_date, order_no) 合计 plan_qty(含已完成/已取消,看的是历史全量); +// - 实际 = workpiece_lifecycle_log(action=DONE) 完工流水按 (完工当天, work_order_no) 聚合计数。 +// +// 实际口径取完工流水而非 daily_plan.completed_qty:流水与生产流程卡同源(真流水), +// 不受「当天无排产行实绩漏记」影响(bumpDailyPlanCompleted 只往匹配到的排产行累加)。 +// 窗口上限 92 天,防全表扫描。 +func (s *Service) DailyPlanAttainment(ctx context.Context, start, end string) ([]DailyPlanAttainmentRow, error) { + if start == "" || end == "" { + return nil, errors.New("请选择日期范围") + } + st, e1 := time.Parse("2006-01-02", start) + en, e2 := time.Parse("2006-01-02", end) + if e1 != nil || e2 != nil { + return nil, errors.New("日期格式应为 YYYY-MM-DD") + } + if en.Before(st) { + return nil, errors.New("结束日期不能早于开始日期") + } + if en.Sub(st).Hours() > 92*24 { + return nil, errors.New("对比窗口最长 92 天,请缩小日期范围") + } + + rows := map[string]*DailyPlanAttainmentRow{} + outOrder := make([]string, 0, 64) + touch := func(date, orderNo string) *DailyPlanAttainmentRow { + key := date + "|" + orderNo + r, ok := rows[key] + if !ok { + r = &DailyPlanAttainmentRow{Date: date, OrderNo: orderNo} + rows[key] = r + outOrder = append(outOrder, key) + } + return r + } + + // 计划:排产行合计(全状态,历史全量) + plans, err := s.ctx.EntClient.DailyPlan.Query(). + Where(dailyplan.PlanDateGTE(start), dailyplan.PlanDateLTE(end)).All(ctx) + if err != nil { + return nil, err + } + for _, p := range plans { + touch(p.PlanDate, p.OrderNo).PlanQty += p.PlanQty + } + + // 实际:完工流水(action=DONE)按完工当天聚合 + logs, err := s.ctx.EntClient.WorkpieceLifecycleLog.Query(). + Where(workpiecelifecyclelog.ActionEQ("DONE"), + workpiecelifecyclelog.CreatedAtGTE(st), + workpiecelifecyclelog.CreatedAtLT(en.Add(24*time.Hour))).All(ctx) + if err != nil { + return nil, err + } + for _, l := range logs { + touch(l.CreatedAt.Format("2006-01-02"), l.WorkOrderNo).DoneQty++ + } + + out := make([]DailyPlanAttainmentRow, 0, len(rows)) + for _, key := range outOrder { + r := rows[key] + r.Diff = r.DoneQty - r.PlanQty + out = append(out, *r) + } + sort.Slice(out, func(i, j int) bool { + if out[i].Date != out[j].Date { + return out[i].Date < out[j].Date + } + return out[i].OrderNo < out[j].OrderNo + }) + return out, nil +} diff --git a/bj_power_mes/internal/logic/flow_chain.go b/bj_power_mes/internal/logic/flow_chain.go index 62e6c81..7c62664 100644 --- a/bj_power_mes/internal/logic/flow_chain.go +++ b/bj_power_mes/internal/logic/flow_chain.go @@ -82,13 +82,26 @@ func (s *Service) flowStationPoint(ctx context.Context, stationNo int) (*ent.Lin return pts[0], true } -// flowStationBusy 该工位/末端是否被其他在制工件占用(按工件台账 atStationNo 判定, -// 口径与 plc_monitor 位置核对一致;DONE/SCRAPPED 不算占用)。 -func (s *Service) flowStationBusy(ctx context.Context, stationNo int) bool { - exist, err := s.ctx.EntClient.Workpiece.Query(). +// flowStationBusyBy 工位台面占用判定(2026-11-16 工位物理互斥): +// 滚筒线单件流,工位台面同一时间只能放一个工件。按工件台账 atStationNo 判定, +// 口径与 plc_monitor 位置核对一致;DONE/SCRAPPED 不算占用。 +// 返回:台面是否被占、占用件所属工单号。占用件属于其他工单 → 本件不准流入,在缓存位排队。 +func (s *Service) flowStationBusyBy(ctx context.Context, stationNo int, orderNo string) (bool, string, error) { + wps, err := s.ctx.EntClient.Workpiece.Query(). Where(workpiece.AtStationNoEQ(stationNo), workpiece.StatusNotIn("DONE", "SCRAPPED")). - Exist(ctx) - return err == nil && exist + All(ctx) + if err != nil { + return false, "", err + } + for _, w := range wps { + if w.OrderNo != orderNo { + return true, w.OrderNo, nil + } + } + if len(wps) > 0 { + return true, "", nil // 台面被本工单在制件占用,同样放不进第二件 + } + return false, "", nil } // flowSend 按 §4.4 路由表下发流转指令,返回执行方式: @@ -191,8 +204,11 @@ func (s *Service) flowMoveOnce(ctx context.Context, sn, operator string) (*FlowM } // 目标选择:真实候选工位优先(升序,首个「台账空闲 + 无其他在制工件」者); // 无台账行=虚拟工位(负数前段工位)仅作兜底。 + // 2026-11-16 工位物理互斥:滚筒线单件流,工位台面被其他工单在制件占用 → 不准流入, + // 件留在缓存位/原地排队(下游 flowToCacheOrStay / stay)。末端下料位(END)豁免互斥。 var virtualCand *int occupiedHit := false + occupiedHint := "" for _, cand := range cands { pt, has := s.flowStationPoint(ctx, cand) if !has { @@ -200,10 +216,21 @@ func (s *Service) flowMoveOnce(ctx context.Context, sn, operator string) (*FlowM virtualCand = &c continue } - if pt.Occupied || s.flowStationBusy(ctx, cand) { + if pt.Occupied { occupiedHit = true continue } + if pt.PointType != "END" { + busy, otherOrder, err := s.flowStationBusyBy(ctx, cand, wp.OrderNo) + if err == nil && busy { + occupiedHit = true + if otherOrder != "" { + occupiedHint = "工位" + strconv.Itoa(cand) + "正在加工工单" + otherOrder + + "的工件,须等其流转走后本件才能进入,已在缓存位排队等待" + } + continue + } + } return s.flowExecMove(ctx, src, wp, sn, srcType, srcNo, pt, operator, doneAll) } if virtualCand != nil { @@ -213,6 +240,9 @@ func (s *Service) flowMoveOnce(ctx context.Context, sn, operator string) (*FlowM if occupiedHit && srcType == plc.SrcStation && !doneAll { return s.flowToCacheOrStay(ctx, src, wp, sn, operator, srcNo) } + if occupiedHint != "" { + return stay(occupiedHint) + } return stay("下一道工序候选工位均不可达/不可用,滞留原地") } diff --git a/bj_power_mes/internal/logic/processflow.go b/bj_power_mes/internal/logic/processflow.go index 0fdfeb0..19cab01 100644 --- a/bj_power_mes/internal/logic/processflow.go +++ b/bj_power_mes/internal/logic/processflow.go @@ -9,7 +9,6 @@ import ( "time" "bj_power_mes/ent" - "bj_power_mes/ent/dailyplan" "bj_power_mes/ent/flowmaterial" "bj_power_mes/ent/inspectionrecord" "bj_power_mes/ent/lossledger" @@ -600,27 +599,19 @@ func (s *Service) StationTask(ctx context.Context, stationNo int) (map[string]an if err != nil { return nil, errors.New("工位不存在或未配置") } - // 工位终端可见工单 = 今日已启用排产(CONFIRMED/执行中)且工单已下发并开工(IN_PROGRESS)。 - // 与状态机对齐(方案 A):工单「下发并开工」=批准生产、排产启用=排进某一天;未开工或未排进今天的工单,终端一律不显示。 + // 工位终端可见工单(2026-11-16 死结7 定案):不限排产日期,所有进行中(IN_PROGRESS)工单, + // 且工艺组合必须包含本工位——干不了的单不给选(此前整线单都可见,选了报工才被拒)。 + // 「昨天没干完的、想提前干明天的」都能选;PAUSED 暂停单不显示(恢复后可见)。 orderNos := []string{} - today := time.Now().Format("2006-01-02") - plans, _ := s.ctx.EntClient.DailyPlan.Query(). - Where(dailyplan.PlanDate(today), dailyplan.StatusIn("CONFIRMED", "PROCESSING")). - Order(ent.Asc(dailyplan.FieldID)).All(ctx) - nos := make([]string, 0, len(plans)) - seen := map[string]bool{} - for _, p := range plans { - if !seen[p.OrderNo] { - seen[p.OrderNo] = true - nos = append(nos, p.OrderNo) - } - } - if len(nos) > 0 { - wos, _ := s.ctx.EntClient.WorkOrder.Query(). - Where(workorder.WorkOrderNoIn(nos...), workorder.StatusIn("IN_PROGRESS")). - Order(ent.Asc(workorder.FieldID)).All(ctx) - for _, w := range wos { - orderNos = append(orderNos, w.WorkOrderNo) + wos, _ := s.ctx.EntClient.WorkOrder.Query(). + Where(workorder.StatusIn("IN_PROGRESS")). + Order(ent.Asc(workorder.FieldID)).All(ctx) + for _, w := range wos { + for _, item := range w.FlowCombination { + if item["stationNo"] == stationNo { + orderNos = append(orderNos, w.WorkOrderNo) + break + } } } // M4:工位终端按「本工位绑定的工艺流程」驱动。 diff --git a/bj_power_mes/internal/logic/product_import.go b/bj_power_mes/internal/logic/product_import.go index c5de804..21cbf98 100644 --- a/bj_power_mes/internal/logic/product_import.go +++ b/bj_power_mes/internal/logic/product_import.go @@ -13,20 +13,19 @@ import ( "github.com/xuri/excelize/v2" ) -// 物料档案 Excel 导入模板表头(2026-11-10 与 WMS 模板统一:同一组列、同一顺序、同一列名)。 -// 图号留空则系统按 PROD-YYYYMMDD-流水 自动生成;成品(类别=成品)序列号强制=是。 -// 「物料编码」为普通字段,选填、不参与业务与必填校验,导入后写 materials.material_code。 -// 解析一律按表头名匹配(列顺序可变、可含多余列),两端都用同一套列名,避免两库模板错位。 -// E5(2026-11-03 拍板):类别列——成品/原材料均可导入;原材料(图号必填、序列号是/否可选) -// 两库同步,导入后可在 WMS 物料档案查看。 +// 物料档案 Excel 导入模板表头(MES 成品导入,仅限成品;2026-11-16 拍板删除「图号」「物料编码」两列)。 +// 成品编码由系统按 PROD-YYYYMMDD-流水 自动生成;物料编码统一为空字符串。 +// 原材料不在本端导入(原材料图号是两库同步业务键,须人工填写),统一在 WMS 物料档案维护。 +// 解析一律按表头名匹配(列顺序可变、可含多余列),避免两库模板错位。 // 2026-11-05 拍板修订:导入顺序改为「探测 WMS 可达 → 先推 WMS → WMS 成功后 MES 再落库」; // WMS 不可达或任一行推送失败则整批取消,MES 不写任何数据(物料档案两库对等双向同步: // 按 code 幂等互推;本流程先推 WMS 保证两侧一致,库存真源在 WMS)。 -// 统一列顺序(2026-11-10 与 WMS 模板完全一致,除业务差异列由各自说明页注明): -// 图号 | 物料编码 | 名称 | 规格 | 单位 | 类型 | 类别 | 序列号 | 启用 | 说明 // 2026-11-13 拍板:成品档案导入模板不允许出现「物料类型」列,全部按成品逻辑默认 -// (类型=其他3、序列号=是1);模板 9 列。旧模板含「类型」列也仍可导入(按表头名识别,多余列忽略)。 -var productTypeTemplateHeaders = []string{"图号", "物料编码", "名称", "规格", "单位", "类别", "序列号", "启用", "说明"} +// (类型=其他3、序列号=是1)。旧模板含「类型」列也仍可导入(按表头名识别,多余列忽略)。 +// 2026-11-16 拍板(用户):模板删除「图号」「物料编码」两列——成品编码由系统自动生成 +// (PROD-YYYYMMDD-流水递增)、物料编码统一为空字符串;MES 成品导入仅限成品, +// 原材料统一在 WMS 物料档案维护(原材料图号是两库同步业务键,须人工填写,不在本端导入)。 +var productTypeTemplateHeaders = []string{"名称", "规格", "单位", "类别", "序列号", "启用", "说明"} // ProductTypeImportResult 单行导入结果汇总。 type ProductTypeImportResult struct { @@ -52,41 +51,37 @@ func (s *Service) BuildProductTypeTemplate() ([]byte, error) { if err := f.SetSheetRow(sheet, "A1", &productTypeTemplateHeaders); err != nil { return nil, err } - // 示例行与 WMS 完全一致(material.go:832-833) - example := []interface{}{"DX100-001", "WL-0001", "示例成品", "300x200x150", "台", "结构件", "成品", "是", "是", "示例行,导入前请删除"} + // 示例行:仅成品(2026-11-16 起原材料不在本端导入) + example := []interface{}{"示例成品", "300x200x150", "台", "结构件", "是", "是", "示例行,导入前请删除"} if err := f.SetSheetRow(sheet, "A2", &example); err != nil { return nil, err } - exampleRaw := []interface{}{"M-BEARING-6204", "WL-0002", "示例原材料-轴承6204", "6204-RS", "个", "结构件", "原材料", "否", "是", "示例行,导入前请删除"} - if err := f.SetSheetRow(sheet, "A3", &exampleRaw); err != nil { - return nil, err - } - // 列宽 - widths := map[int]float64{1: 20, 2: 16, 3: 18, 4: 18, 5: 10, 6: 12, 7: 10, 8: 10, 9: 10, 10: 24} + // 列宽(7 列) + widths := map[int]float64{1: 18, 2: 18, 3: 10, 4: 12, 5: 10, 6: 10, 7: 24} for col, w := range widths { if cell, err := excelize.ColumnNumberToName(col); err == nil { _ = f.SetColWidth(sheet, cell, cell, w) } } - // 填写说明页(结构对齐 WMS:列顺序 + 逐条说明;2/6/7/8 按两端各自生效口径注明) + // 填写说明页 const guide = "填写说明" if _, err := f.NewSheet(guide); err != nil { return nil, err } guides := []string{ - "【列顺序】图号 | 物料编码 | 名称 | 规格 | 单位 | 类别 | 序列号 | 启用 | 说明(成品档案模板,按表头名识别,请勿改动表头文字)", - "1. 仅保留第一个「Sheet1」数据页,「填写说明」页请勿删除或填入数据;第2/3行是示例,正式导入前请删除。", - "2. 图号:必填且唯一,物料唯一标识(两库同步业务键);成品可留空(留空自动生成 PROD-YYYYMMDD-流水),原材料必填;已有相同图号的行会被拒绝。", - "3. 物料编码:选填,普通档案字段(如 WL-0001),不参与业务与必填校验。", + "【列顺序】名称 | 规格 | 单位 | 类别 | 序列号 | 启用 | 说明(成品档案模板,按表头名识别,请勿改动表头文字)", + "1. 仅保留第一个「Sheet1」数据页,「填写说明」页请勿删除或填入数据;第2行是示例,正式导入前请删除。", + "2. 成品编码(图号)无需填写:系统自动生成(PROD-年月日-流水,递增且唯一)。", + "3. 物料编码无需填写:统一为空。", "4. 名称 / 规格 / 单位:必填,不可为空。", - "5. 物料类型:本模板不提供此列,系统一律按成品逻辑默认(类型=其他、序列号=是);原材料请在 WMS 物料档案维护。", - "6. 类别:填「原材料」或「成品」,默认成品(MES 口径;WMS 侧叫「物料类别」,留空默认原材料)。", - "7. 序列号:填「是」「否」或 1/2;成品强制为「是」,原材料可按实际选是/否(WMS 导入忽略本列,按类型自动派生)。", - "8. 启用:填「是」「否」或 true/false,默认「是」(WMS 导入忽略本列,默认启用)。", + "5. 类别:只能填「成品」;原材料请在 WMS 物料档案维护(不在本端导入)。", + "6. 物料类型:本模板不提供此列,系统一律按成品逻辑默认(类型=其他、序列号=是)。", + "7. 序列号:本模板不提供此列,成品强制为「是」。", + "8. 启用:填「是」「否」或 true/false,默认「是」。", "9. 说明:可空,备注信息。", "10. 首行为表头,从第二行开始为数据;整批校验,任一行出错则一行不写(可在导入前点「预检」先看错误明细)。", - "【MES 业务差异】本端导入会先探测 WMS 可达并逐行先写 WMS,WMS 失败则整批取消;「类别/序列号/启用」按 MES 口径生效。", + "【MES 业务差异】本端导入会先探测 WMS 可达并逐行先写 WMS,WMS 失败则整批取消。", } for i, g := range guides { if err := f.SetSheetRow(guide, fmt.Sprintf("A%d", i+1), &[]interface{}{g}); err != nil { @@ -153,16 +148,17 @@ func parseProductImportRows(data []byte) ([]productImportRow, []ProductTypeRowEr errs = append(errs, ProductTypeRowErr{Row: line, Message: "名称/规格/单位 均为必填"}) continue } - // E5(2026-11-03 拍板):类别列——成品(默认)/原材料;原材料行落 materials(itemType=1) 并推 WMS + // E5 类别列:本端导入仅限成品(2026-11-16 拍板)——原材料行直接拒绝,统一在 WMS 物料档案维护 itemType := 3 if v := get(r, "类别"); v != "" { switch v { case "成品", "3": itemType = 3 case "原材料", "1": - itemType = 1 + errs = append(errs, ProductTypeRowErr{Row: line, Message: "MES 成品导入仅限成品;原材料请在 WMS 物料档案维护"}) + continue default: - errs = append(errs, ProductTypeRowErr{Row: line, Message: fmt.Sprintf("类别须为 成品/原材料,当前为「%s」", v)}) + errs = append(errs, ProductTypeRowErr{Row: line, Message: fmt.Sprintf("类别须为 成品,当前为「%s」", v)}) continue } } @@ -195,27 +191,17 @@ func parseProductImportRows(data []byte) ([]productImportRow, []ProductTypeRowEr isActive = ia } } - code := get(r, "图号") - if itemType == 1 { - if code == "" { - errs = append(errs, ProductTypeRowErr{Row: line, Message: "原材料图号必填(原材料为两库同步业务键,不自动生成编码)"}) - continue - } - if e := validateTypeAndSnMode(mm, snMode); e != nil { - errs = append(errs, ProductTypeRowErr{Row: line, Message: e.Error()}) - continue - } - } + // 2026-11-16 拍板:模板无「图号」「物料编码」列——成品编码写入阶段自动生成、物料编码统一为空 plans = append(plans, productImportRow{ line: line, itemType: itemType, req: ProductTypeReq{ - Code: code, + Code: "", Name: name, Spec: spec, Unit: unit, Description: get(r, "说明"), - MaterialCode: get(r, "物料编码"), + MaterialCode: "", ManageMode: mm, SnMode: snMode, IsActive: isActive, @@ -361,7 +347,7 @@ func (s *Service) createProductImportRowTx(ctx context.Context, tx *ent.Tx, p pr SetSpec(req.Spec). SetUnit(req.Unit). SetDescription(req.Description). - SetMaterialCode(strings.TrimSpace(req.MaterialCode)). + SetMaterialCode(""). SetItemType(p.itemType). SetManageMode(req.ManageMode). SetSnMode(snMode). diff --git a/bj_power_mes/internal/logic/scan.go b/bj_power_mes/internal/logic/scan.go index cfc27c4..5404bdb 100644 --- a/bj_power_mes/internal/logic/scan.go +++ b/bj_power_mes/internal/logic/scan.go @@ -24,11 +24,13 @@ func (s *Service) bumpWorkOrderProgress(ctx context.Context, orderNo, sn string) // bumpDailyPlanCompleted 工单完工联动当日排产:completedQty+1,达到 planQty 置 DONE。 // 当天没有匹配排产则跳过(不做自动建单)。仅由真正的完工事件调用。 +// 2026-11-16 修复:状态过滤补入 CONFIRMED——已启用排产此前完工不累计实绩(恒 0、diff 恒等于计划量)。 +// CONFIRMED 未足额时保持 CONFIRMED(算料开关语义不变,不转 PROCESSING),足额仍置 DONE。 func (s *Service) bumpDailyPlanCompleted(ctx context.Context, orderNo string, t time.Time) { date := t.Format("2006-01-02") plans, err := s.ctx.EntClient.DailyPlan.Query(). Where(dailyplan.OrderNo(orderNo), dailyplan.PlanDate(date)). - Where(dailyplan.StatusIn("PENDING", "PROCESSING", "DONE")).All(ctx) + Where(dailyplan.StatusIn("PENDING", "CONFIRMED", "PROCESSING", "DONE")).All(ctx) if err != nil || len(plans) == 0 { return } diff --git a/bj_power_mes/internal/logic/workorder.go b/bj_power_mes/internal/logic/workorder.go index 2f04429..c2c596d 100644 --- a/bj_power_mes/internal/logic/workorder.go +++ b/bj_power_mes/internal/logic/workorder.go @@ -47,25 +47,34 @@ func (s *Service) CreateWorkOrder(ctx context.Context, req WorkOrderReq, operato // 2026-11-13 拍板:排产/建工单必须读取「当前产线在用的混产模板」并校验产品范围。 // 同模板内多工单(多成品)混产直接放行;模板外新产品必须先清线并切换当前模板, // 不允许排产偷偷把新产品塞进不属于它的产线配置里。 + // 2026-11-16 fail-close 收口:无在用模板 / 成品编码缺失一律拒绝,堵住"没配模板就跳过校验"的旁路。 tplName, products, tErr := s.ActiveMixProducts(ctx) if tErr != nil { return tErr } - if tplName != "" && strings.TrimSpace(req.ProductCode) != "" { + // 收集式校验(报错一次收全 + 每条带怎么办,2026-10-20):字段问题全部列出、一次性返回,不再串行 return + ve := verr.New() + if tplName == "" { + ve.Add("mixTemplate", "当前产线没有设置「在用」混产模板,无法创建工单", + "先到「工位管理」配置工位工艺绑定并保存为混产模板,再到混产模板页将其设为当前在用模板") + } + pc := strings.TrimSpace(req.ProductCode) + if pc == "" { + ve.Add("productCode", "工单缺少成品编码,无法校验混产范围", + "请先确认所选产品型号档案已生成成品编码,再创建工单") + } else if tplName != "" { allowed := false for _, c := range products { - if c == strings.TrimSpace(req.ProductCode) { + if c == pc { allowed = true break } } if !allowed { - return fmt.Errorf("当前产线在用混产模板「%s」不含成品 %s;跨模板引入新产品需先清线,再到「工位管理 → 保存当前绑定为模板」切换当前模板", - tplName, req.ProductCode) + ve.Add("productCode", fmt.Sprintf("当前产线在用混产模板「%s」不含成品 %s", tplName, pc), + "跨模板引入新产品需先清线,再到「工位管理 → 保存当前绑定为模板」切换当前模板") } } - // 收集式校验(报错一次收全 + 每条带怎么办,2026-10-20):字段问题全部列出、一次性返回,不再串行 return - ve := verr.New() if req.ProductTypeId == 0 { ve.Add("productTypeId", "请选择产品型号", "在「产品型号」下拉中选择本次要生产的产品") } @@ -374,8 +383,10 @@ func (s *Service) UpdateWorkOrder(ctx context.Context, req WorkOrderReq, operato // 工程编号查询已随编号体系改造移除,字段保留仅防历史迁移)。 // keyword:跨字段模糊(工单号/产品编码/产品名称/合同号 任一命中),供下拉远程搜索用; // limit:>0 时启用截断(封顶 200),仅下拉搜索场景传参,列表页不传=全量,行为向后兼容; -// offset:>0 时跳过前 N 条,配合 limit 供下拉滚动分页(不传=0,行为向后兼容)。 -func (s *Service) ListWorkOrders(ctx context.Context, orderNo, status, productCode, productName, contractNo, ownershipType, keyword string, limit, offset int) ([]*ent.WorkOrder, error) { +// offset:>0 时跳过前 N 条,配合 limit 供下拉滚动分页(不传=0,行为向后兼容); +// firstStation:>0 时只返回「第1道工序候选工位含该工位」的工单(2026-11-16 上线建档下拉专用, +// 与建档落点资格校验同口径),0=不过滤,行为向后兼容。 +func (s *Service) ListWorkOrders(ctx context.Context, orderNo, status, productCode, productName, contractNo, ownershipType, keyword string, limit, offset int, firstStation int) ([]*ent.WorkOrder, error) { q := s.ctx.EntClient.WorkOrder.Query() if orderNo != "" { q = q.Where(workorder.WorkOrderNoContainsFold(orderNo)) @@ -409,14 +420,36 @@ func (s *Service) ListWorkOrders(ctx context.Context, orderNo, status, productCo if offset > 0 { q = q.Offset(offset) } - // limit 截断(封顶 200):仅下拉搜索场景启用,防数据炸弹 - if limit > 0 { - if limit > 200 { - limit = 200 - } - q = q.Limit(limit) + q = q.Order(ent.Desc(workorder.FieldCreatedAt), ent.Desc(workorder.FieldID)) + rows, err := q.All(ctx) + if err != nil { + return nil, err } - return q.Order(ent.Desc(workorder.FieldCreatedAt), ent.Desc(workorder.FieldID)).All(ctx) + if limit > 200 { + limit = 200 + } + // 首道候选工位过滤:需取回后在内存按工艺组合计算(截断前过滤会漏),命中即收,达 limit 早停 + if firstStation > 0 { + out := make([]*ent.WorkOrder, 0, len(rows)) + for _, w := range rows { + items, _ := RouteStationsFromWO(ctx, s.ctx.EntClient, w) + if len(items) == 0 { + continue + } + route := groupFlowRoute(items) + if len(route) > 0 && intsContains(route[0].Stations, firstStation) { + out = append(out, w) + } + if limit > 0 && len(out) >= limit { + break + } + } + return out, nil + } + if limit > 0 && len(rows) > limit { + rows = rows[:limit] + } + return rows, nil } // ListProcessCards 流程卡列表(分页):每个工单=一张生产流程卡。 diff --git a/bj_power_mes/internal/logic/workpiece.go b/bj_power_mes/internal/logic/workpiece.go index 7ccdaee..06a198e 100644 --- a/bj_power_mes/internal/logic/workpiece.go +++ b/bj_power_mes/internal/logic/workpiece.go @@ -213,7 +213,7 @@ func (s *Service) OnlineWorkpiece(ctx context.Context, req OnlineReq, operator s return "", nil, errors.New("sn 不能为空") } default: // 0=未选择(档案缺失/未配置) - return "", nil, errors.New("请先在产品型号/物料档案选择序列号管理方式(序列号=是/否)") + return "", nil, errors.New("请先在成品档案设置序列号管理方式(序列号=是/否)") } if err := s.ctx.EntClient.Workpiece.Create(). SetSn(req.Sn).SetOrderNo(req.OrderNo).SetWorkOrderId(req.WorkOrderId). @@ -264,6 +264,13 @@ func (s *Service) onlineNewWorkpiece(ctx context.Context, wp *ent.Workpiece, req return "", nil, fmt.Errorf("新件建档必须落在第1道工序的候选工位(%s)之一,当前落点工位%d不符合资格", joinIntsLocal(firstStations), req.StationNo) } + // 工位物理互斥(2026-11-16):滚筒线单件流,落点工位台面被其他工单在制件占用 → 拒绝建档, + // 该件须等占用件流转走(或改落其他空闲候选工位)。 + busy, otherOrder, err := s.flowStationBusyBy(ctx, req.StationNo, wp.OrderNo) + if err == nil && busy && otherOrder != "" { + return "", nil, fmt.Errorf("建档落点工位%d正在加工工单%s的工件(工位互斥,一次只干一个工单),请等其流转走或改落其他空闲候选工位", + req.StationNo, otherOrder) + } station := req.StationNo if _, e := s.ctx.EntClient.Workpiece.UpdateOneID(wp.ID). SetStatus("ONLINE").SetOnlineAt(time.Now()).SetAtStationNo(station).Save(ctx); e != nil { @@ -409,6 +416,9 @@ func (s *Service) workpieceWorkOrder(ctx context.Context, wp *ent.Workpiece) *en type ReportProcessReq struct { Sn string `json:"sn"` + // OrderNo 终端当前作业工单(2026-11-16 错单强拦截):与扫码件归属工单不一致直接拒绝, + // 禁止把工单B的件静默记到工单A(工位互斥配套防呆)。 + OrderNo string `json:"orderNo"` FlowId int `json:"flowId"` // 报工工艺(缺省回退工位当前绑定的工艺) StationNo int `json:"stationNo"` Operator string `json:"operator"` // 操作工(工位终端登录人注入;内部接口无 JWT 时作为操作人来源,杜绝「system」伪造留痕) @@ -477,6 +487,12 @@ func (s *Service) ReportProcess(ctx context.Context, req ReportProcessReq, opera if err != nil || wo == nil { return errors.New("工件所属工单不存在") } + // 2026-11-16 错单强拦截(工位物理互斥配套):终端当前作业工单必须与扫码件归属工单一致, + // 不一致直接拒绝,杜绝"扫到工单B的件静默记到工单A"的错账。 + if req.OrderNo != "" && req.OrderNo != wo.WorkOrderNo { + return fmt.Errorf("扫码件 %s 属于工单 %s,与当前作业工单 %s 不一致,已拒绝报工;请先在作业页切换到工单 %s,或核对手中工件", + req.Sn, wo.WorkOrderNo, req.OrderNo, wo.WorkOrderNo) + } // 并行候选工位模型(2026-11-02):同工序可配置多个候选工位,工件在任一候选工位报工一次即完成该工序; // 不可跳工序(须按工序顺序),同工序已报工则不可重复报工。 route, _ := FlowRouteOfWO(ctx, s.ctx.EntClient, wo) diff --git a/bj_power_mes/internal/plc/logging.go b/bj_power_mes/internal/plc/logging.go new file mode 100644 index 0000000..2c5467d --- /dev/null +++ b/bj_power_mes/internal/plc/logging.go @@ -0,0 +1,114 @@ +// logging.go PLC 全量交互日志装饰器(2026-11-16 联调)。 +// 包装 Client 接口全部方法:调用参数、返回值、错误统一落 logx(前缀 [PLC])。 +// 在 NewManager 处包一层,mock / 真实 S7(tcp.go) / tcp 自定义协议全部覆盖; +// tcp.go 为保护文件不做改动,日志在此层完成。 +package plc + +import ( + "context" + "fmt" + + "github.com/zeromicro/go-zero/core/logx" +) + +// logClient 日志装饰器:inner 为真实实现(s7Real / tcpClient / mock)。 +type logClient struct{ inner Client } + +func newLogClient(inner Client) *logClient { return &logClient{inner: inner} } + +func (l *logClient) SendProcessCode(ctx context.Context, combination string) ([]int, error) { + logx.WithContext(ctx).Infof("[PLC] --> SendProcessCode combination=%s", combination) + codes, err := l.inner.SendProcessCode(ctx, combination) + if err != nil { + logx.WithContext(ctx).Errorf("[PLC] <-- SendProcessCode err=%v", err) + } else { + logx.WithContext(ctx).Infof("[PLC] <-- SendProcessCode codes=%v", codes) + } + return codes, err +} + +func (l *logClient) QueryDone(ctx context.Context) (bool, error) { + done, err := l.inner.QueryDone(ctx) + if err != nil { + logx.WithContext(ctx).Errorf("[PLC] <-- QueryDone err=%v", err) + } else { + logx.WithContext(ctx).Infof("[PLC] <-- QueryDone done=%v", done) + } + return done, err +} + +func (l *logClient) AckDone(ctx context.Context, ok bool) { + logx.WithContext(ctx).Infof("[PLC] AckDone ok=%v", ok) + l.inner.AckDone(ctx, ok) +} + +func (l *logClient) QueryDockPallet(ctx context.Context, dockCode string) (bool, error) { + has, err := l.inner.QueryDockPallet(ctx, dockCode) + if err != nil { + logx.WithContext(ctx).Errorf("[PLC] <-- QueryDockPallet dock=%s err=%v", dockCode, err) + } else { + logx.WithContext(ctx).Infof("[PLC] <-- QueryDockPallet dock=%s hasPallet=%v", dockCode, has) + } + return has, err +} + +func (l *logClient) QueryStationPallet(ctx context.Context, stationNo int) (bool, error) { + has, err := l.inner.QueryStationPallet(ctx, stationNo) + if err != nil { + logx.WithContext(ctx).Errorf("[PLC] <-- QueryStationPallet station=%d err=%v", stationNo, err) + } else { + logx.WithContext(ctx).Infof("[PLC] <-- QueryStationPallet station=%d hasPallet=%v", stationNo, has) + } + return has, err +} + +func (l *logClient) ReadBits(ctx context.Context) ([]bool, error) { + bits, err := l.inner.ReadBits(ctx) + if err != nil { + logx.WithContext(ctx).Errorf("[PLC] <-- ReadBits err=%v", err) + } else { + // 48 位压成 0/1 字符串,一行可读 + s := make([]byte, len(bits)) + for i, b := range bits { + if b { + s[i] = '1' + } else { + s[i] = '0' + } + } + logx.WithContext(ctx).Infof("[PLC] <-- ReadBits bits=%s", string(s)) + } + return bits, err +} + +func (l *logClient) ReadMW(ctx context.Context, addr int) (int, error) { + v, err := l.inner.ReadMW(ctx, addr) + if err != nil { + logx.WithContext(ctx).Errorf("[PLC] <-- ReadMW MW%d err=%v", addr, err) + } else { + logx.WithContext(ctx).Infof("[PLC] <-- ReadMW MW%d=%d", addr, v) + } + return v, err +} + +func (l *logClient) ReadMWBlock(ctx context.Context, start, count int) ([]int, error) { + vals, err := l.inner.ReadMWBlock(ctx, start, count) + if err != nil { + logx.WithContext(ctx).Errorf("[PLC] <-- ReadMWBlock MW%d..MW%d err=%v", start, start+count-1, err) + } else { + logx.WithContext(ctx).Infof("[PLC] <-- ReadMWBlock MW%d..MW%d vals=%v", start, start+count-1, vals) + } + return vals, err +} + +func (l *logClient) WriteMW(ctx context.Context, addr, value int) error { + logx.WithContext(ctx).Infof("[PLC] --> WriteMW MW%d=%d", addr, value) + err := l.inner.WriteMW(ctx, addr, value) + if err != nil { + logx.WithContext(ctx).Errorf("[PLC] <-- WriteMW MW%d=%d err=%v", addr, value, err) + } + return err +} + +// String 满足调试打印。 +func (l *logClient) String() string { return fmt.Sprintf("logClient(%T)", l.inner) } diff --git a/bj_power_mes/internal/plc/plc.go b/bj_power_mes/internal/plc/plc.go index 78c0c2a..d8ee7df 100644 --- a/bj_power_mes/internal/plc/plc.go +++ b/bj_power_mes/internal/plc/plc.go @@ -51,6 +51,7 @@ type Manager struct { client Client mock bool onRecover func(ctx context.Context) + onFail func(ctx context.Context, err error) // 2026-11-16:连续失败首次沿触发(通信异常预警),恢复后重置 mu sync.Mutex consecFails int mockOffline bool // mock 模式:模拟 PLC 离线(拍板2 联调/自测用,真实 PLC 忽略) @@ -59,9 +60,9 @@ type Manager struct { func NewManager(c config.PlcConf, mock bool) (*Manager, error) { m := &Manager{mock: mock} if mock { - m.client = newMockClient() + m.client = newLogClient(newMockClient()) } else { - m.client = newTcpClient(c) + m.client = newLogClient(newTcpClient(c)) } return m, nil } @@ -78,6 +79,14 @@ func (m *Manager) SetOnRecover(f func(ctx context.Context)) { m.mu.Unlock() } +// SetOnFail 设置 PLC 通讯失败回调(2026-11-16):连续失败首次沿触发一次(落预警中心), +// 恢复成功后重置——下次再断再触发;持续断连期间不重复触发(防轮询风暴,预警侧另有窗口去重)。 +func (m *Manager) SetOnFail(f func(ctx context.Context, err error)) { + m.mu.Lock() + m.onFail = f + m.mu.Unlock() +} + // QueryStationPallet 读工位托盘位(带恢复检测):查询成功且此前发生过失败 → 触发 OnRecover(T6)。 // mock 模式下可经 SetMockOffline 模拟离线(读失败),验证拍板2「PLC 离线提示+人工强行确认」链路。 func (m *Manager) QueryStationPallet(ctx context.Context, stationNo int) (bool, error) { @@ -128,6 +137,12 @@ func (m *Manager) track(err error) { defer m.mu.Unlock() if err != nil { m.consecFails++ + // 2026-11-16:连续失败首次沿触发 onFail(通信异常落预警);持续断连不重复触发。 + if m.consecFails == 1 && m.onFail != nil { + f := m.onFail + failErr := err + go f(context.Background(), failErr) + } return } if m.consecFails > 0 { diff --git a/bj_power_mes/internal/wmsclient/client.go b/bj_power_mes/internal/wmsclient/client.go index 6033178..1bf4138 100644 --- a/bj_power_mes/internal/wmsclient/client.go +++ b/bj_power_mes/internal/wmsclient/client.go @@ -30,7 +30,7 @@ const defaultBaseURL = "http://127.0.0.1:9091" func New(baseURL, token string) *Client { c := &Client{ token: token, - hc: &http.Client{Timeout: 5 * time.Second}, + hc: &http.Client{Timeout: 5 * time.Second, Transport: newLoggingTransport()}, } c.SetBaseURL(baseURL) return c diff --git a/bj_power_mes/internal/wmsclient/transport_logging.go b/bj_power_mes/internal/wmsclient/transport_logging.go new file mode 100644 index 0000000..c48bbcf --- /dev/null +++ b/bj_power_mes/internal/wmsclient/transport_logging.go @@ -0,0 +1,78 @@ +// transport_logging.go MES→WMS 全量 HTTP 交互日志(2026-11-16 联调)。 +// 用 http.RoundTripper 装饰器实现:挂在 Client.hc 上后,所有出口函数 +// (post/get/postSemi/ExportProductTypes 等)的每次请求自动落日志,无需逐点插桩。 +// 记录:请求方法/完整URL/请求体(截断 2000 字节)、响应状态码/响应体(截断 2000 字节)、传输错误。 +// 前缀 [MES→WMS],grep 即可定位;响应体读出后用 NopCloser 回填,不影响调用方解析。 +package wmsclient + +import ( + "bytes" + "context" + "io" + "net/http" + + "github.com/zeromicro/go-zero/core/logx" +) + +// loggingTransport 日志装饰 transport。 +type loggingTransport struct{ base http.RoundTripper } + +// FailHook WMS 通讯失败钩子(2026-11-16):仅【传输层失败】(连不上/超时/断连)触发, +// HTTP 非 2xx 与业务码非 0 属正常业务响应不触发。main 启动时装配(落预警中心),包外勿随意设置。 +// 去重由回调实现方负责(CreateAlertDedup 窗口去重),本层只负责在错误发生时通知。 +var FailHook func(ctx context.Context, method, url string, err error) + +func newLoggingTransport() *loggingTransport { + return &loggingTransport{base: http.DefaultTransport} +} + +func (t *loggingTransport) RoundTrip(req *http.Request) (*http.Response, error) { + u := req.URL.String() + var reqBody []byte + if req.Body != nil { + reqBody, _ = io.ReadAll(req.Body) + _ = req.Body.Close() + req.Body = io.NopCloser(bytes.NewReader(reqBody)) + } + logx.WithContext(req.Context()).Infof("[MES→WMS] --> %s %s body=%s", req.Method, u, truncateLogBytes(reqBody)) + + resp, err := t.base.RoundTrip(req) + if err != nil { + logx.WithContext(req.Context()).Errorf("[MES→WMS] <-- transport error %s err=%v", u, err) + if FailHook != nil { + FailHook(req.Context(), req.Method, u, err) + } + return resp, err + } + raw, rerr := io.ReadAll(resp.Body) + _ = resp.Body.Close() + if rerr != nil { + logx.WithContext(req.Context()).Errorf("[MES→WMS] <-- read body error %s status=%d err=%v", u, resp.StatusCode, rerr) + } + resp.Body = io.NopCloser(bytes.NewReader(raw)) + logx.WithContext(req.Context()).Infof("[MES→WMS] <-- HTTP %d %s body=%s", resp.StatusCode, u, truncateLogBytes(raw)) + return resp, nil +} + +// truncateLogBytes 日志防刷爆:超 2000 字节截断(xlsx 导出等大响应只记头段)。 +func truncateLogBytes(b []byte) string { + const max = 2000 + if len(b) <= max { + return string(b) + } + return string(b[:max]) + "...(截断,共" + itoaLen(len(b)) + "字节)" +} + +func itoaLen(n int) string { + if n == 0 { + return "0" + } + var buf [20]byte + i := len(buf) + for n > 0 { + i-- + buf[i] = byte('0' + n%10) + n /= 10 + } + return string(buf[i:]) +} diff --git a/bj_power_mes/public/index.html b/bj_power_mes/public/index.html index 0708ba8..4c0ba30 100644 --- a/bj_power_mes/public/index.html +++ b/bj_power_mes/public/index.html @@ -6,7 +6,7 @@ MES 产线控制 - + diff --git a/bj_power_wms/bj_power_wms.go b/bj_power_wms/bj_power_wms.go index 7140378..c572122 100644 --- a/bj_power_wms/bj_power_wms.go +++ b/bj_power_wms/bj_power_wms.go @@ -29,12 +29,14 @@ import ( "bj_power_wms/internal/eventlog" "bj_power_wms/internal/handler" "bj_power_wms/internal/logdaily" + "bj_power_wms/internal/mesclient" "bj_power_wms/internal/scanbridge" "bj_power_wms/internal/svc" "bj_power_wms/internal/tray" "golang.org/x/crypto/bcrypt" "golang.org/x/sys/windows" + "bj_power_wms/ent/alert" "bj_power_wms/ent/user" "github.com/zeromicro/go-zero/core/conf" "github.com/zeromicro/go-zero/core/logx" @@ -713,6 +715,31 @@ func runServeWMS(c config.Config) { ctx := svc.NewServiceContext(c) + // MES 通讯失败预警(2026-11-16):WMS→MES 传输层失败(连不上/超时)触发, + // 10 分钟窗口去重防轮询风暴;HTTP 业务错误(服务在但拒绝)不算通讯异常、不触发。 + mesclient.FailHook = func(hookCtx context.Context, method, url string, hookErr error) { + fc, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + since := time.Now().Add(-10 * time.Minute) + cnt, cerr := ctx.EntClient.Alert.Query().Where( + alert.RuleCodeEQ("mes_unreachable"), + alert.StatusEQ("unread"), + alert.TargetEQ("MES"), + alert.CreatedAtGTE(since.Unix()), + ).Count(fc) + if cerr == nil && cnt > 0 { + return + } + _, aerr := ctx.EntClient.Alert.Create(). + SetRuleCode("mes_unreachable").SetLevel("warning").SetTarget("MES"). + SetTitle("MES 通讯失败:" + hookErr.Error()). + SetContent(fmt.Sprintf("WMS→MES %s %s(%v),备料回写/工单查询/成品反查将失败,请检查 MES 服务。", method, url, hookErr)). + SetStatus("unread").Save(fc) + if aerr != nil { + logx.Errorf("MES 通讯失败落预警异常: %v", aerr) + } + } + // 扫码中间件(键盘 HID 注入):Enable=true 时随 WMS 启动监听 7757,接收网络型扫码枪推送并模拟键盘注入当前光标窗口。 // 7757 被占用时仅记日志、不影响主程序(与 MES 同机同开时谁先启动谁监听,后到的只记日志)。 if c.Scanner.Enabled { diff --git a/bj_power_wms/ent/client.go b/bj_power_wms/ent/client.go index 13bc2a1..81b8b6a 100644 --- a/bj_power_wms/ent/client.go +++ b/bj_power_wms/ent/client.go @@ -20,6 +20,7 @@ import ( "bj_power_wms/ent/eventlog" "bj_power_wms/ent/inbounddetail" "bj_power_wms/ent/inboundorder" + "bj_power_wms/ent/inspectiondisposalitem" "bj_power_wms/ent/inspectionrecord" "bj_power_wms/ent/inventory" "bj_power_wms/ent/inventorylock" @@ -67,6 +68,8 @@ type Client struct { InboundDetail *InboundDetailClient // InboundOrder is the client for interacting with the InboundOrder builders. InboundOrder *InboundOrderClient + // InspectionDisposalItem is the client for interacting with the InspectionDisposalItem builders. + InspectionDisposalItem *InspectionDisposalItemClient // InspectionRecord is the client for interacting with the InspectionRecord builders. InspectionRecord *InspectionRecordClient // Inventory is the client for interacting with the Inventory builders. @@ -123,6 +126,7 @@ func (c *Client) init() { c.EventLog = NewEventLogClient(c.config) c.InboundDetail = NewInboundDetailClient(c.config) c.InboundOrder = NewInboundOrderClient(c.config) + c.InspectionDisposalItem = NewInspectionDisposalItemClient(c.config) c.InspectionRecord = NewInspectionRecordClient(c.config) c.Inventory = NewInventoryClient(c.config) c.InventoryLock = NewInventoryLockClient(c.config) @@ -231,35 +235,36 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { cfg := c.config cfg.driver = tx return &Tx{ - ctx: ctx, - config: cfg, - Alert: NewAlertClient(cfg), - AlertRule: NewAlertRuleClient(cfg), - Attachment: NewAttachmentClient(cfg), - BackupRecord: NewBackupRecordClient(cfg), - DeliveryOrder: NewDeliveryOrderClient(cfg), - DeliveryOrderItem: NewDeliveryOrderItemClient(cfg), - EventLog: NewEventLogClient(cfg), - InboundDetail: NewInboundDetailClient(cfg), - InboundOrder: NewInboundOrderClient(cfg), - InspectionRecord: NewInspectionRecordClient(cfg), - Inventory: NewInventoryClient(cfg), - InventoryLock: NewInventoryLockClient(cfg), - Material: NewMaterialClient(cfg), - MaterialDemand: NewMaterialDemandClient(cfg), - OrderMaterialLedger: NewOrderMaterialLedgerClient(cfg), - OutboundDetail: NewOutboundDetailClient(cfg), - OutboundOrder: NewOutboundOrderClient(cfg), - Permission: NewPermissionClient(cfg), - ReturnOrder: NewReturnOrderClient(cfg), - Role: NewRoleClient(cfg), - SemiFinished: NewSemiFinishedClient(cfg), - StocktakeItem: NewStocktakeItemClient(cfg), - StocktakeOrder: NewStocktakeOrderClient(cfg), - SyncFailure: NewSyncFailureClient(cfg), - SysConfig: NewSysConfigClient(cfg), - User: NewUserClient(cfg), - Zone: NewZoneClient(cfg), + ctx: ctx, + config: cfg, + Alert: NewAlertClient(cfg), + AlertRule: NewAlertRuleClient(cfg), + Attachment: NewAttachmentClient(cfg), + BackupRecord: NewBackupRecordClient(cfg), + DeliveryOrder: NewDeliveryOrderClient(cfg), + DeliveryOrderItem: NewDeliveryOrderItemClient(cfg), + EventLog: NewEventLogClient(cfg), + InboundDetail: NewInboundDetailClient(cfg), + InboundOrder: NewInboundOrderClient(cfg), + InspectionDisposalItem: NewInspectionDisposalItemClient(cfg), + InspectionRecord: NewInspectionRecordClient(cfg), + Inventory: NewInventoryClient(cfg), + InventoryLock: NewInventoryLockClient(cfg), + Material: NewMaterialClient(cfg), + MaterialDemand: NewMaterialDemandClient(cfg), + OrderMaterialLedger: NewOrderMaterialLedgerClient(cfg), + OutboundDetail: NewOutboundDetailClient(cfg), + OutboundOrder: NewOutboundOrderClient(cfg), + Permission: NewPermissionClient(cfg), + ReturnOrder: NewReturnOrderClient(cfg), + Role: NewRoleClient(cfg), + SemiFinished: NewSemiFinishedClient(cfg), + StocktakeItem: NewStocktakeItemClient(cfg), + StocktakeOrder: NewStocktakeOrderClient(cfg), + SyncFailure: NewSyncFailureClient(cfg), + SysConfig: NewSysConfigClient(cfg), + User: NewUserClient(cfg), + Zone: NewZoneClient(cfg), }, nil } @@ -277,35 +282,36 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) cfg := c.config cfg.driver = &txDriver{tx: tx, drv: c.driver} return &Tx{ - ctx: ctx, - config: cfg, - Alert: NewAlertClient(cfg), - AlertRule: NewAlertRuleClient(cfg), - Attachment: NewAttachmentClient(cfg), - BackupRecord: NewBackupRecordClient(cfg), - DeliveryOrder: NewDeliveryOrderClient(cfg), - DeliveryOrderItem: NewDeliveryOrderItemClient(cfg), - EventLog: NewEventLogClient(cfg), - InboundDetail: NewInboundDetailClient(cfg), - InboundOrder: NewInboundOrderClient(cfg), - InspectionRecord: NewInspectionRecordClient(cfg), - Inventory: NewInventoryClient(cfg), - InventoryLock: NewInventoryLockClient(cfg), - Material: NewMaterialClient(cfg), - MaterialDemand: NewMaterialDemandClient(cfg), - OrderMaterialLedger: NewOrderMaterialLedgerClient(cfg), - OutboundDetail: NewOutboundDetailClient(cfg), - OutboundOrder: NewOutboundOrderClient(cfg), - Permission: NewPermissionClient(cfg), - ReturnOrder: NewReturnOrderClient(cfg), - Role: NewRoleClient(cfg), - SemiFinished: NewSemiFinishedClient(cfg), - StocktakeItem: NewStocktakeItemClient(cfg), - StocktakeOrder: NewStocktakeOrderClient(cfg), - SyncFailure: NewSyncFailureClient(cfg), - SysConfig: NewSysConfigClient(cfg), - User: NewUserClient(cfg), - Zone: NewZoneClient(cfg), + ctx: ctx, + config: cfg, + Alert: NewAlertClient(cfg), + AlertRule: NewAlertRuleClient(cfg), + Attachment: NewAttachmentClient(cfg), + BackupRecord: NewBackupRecordClient(cfg), + DeliveryOrder: NewDeliveryOrderClient(cfg), + DeliveryOrderItem: NewDeliveryOrderItemClient(cfg), + EventLog: NewEventLogClient(cfg), + InboundDetail: NewInboundDetailClient(cfg), + InboundOrder: NewInboundOrderClient(cfg), + InspectionDisposalItem: NewInspectionDisposalItemClient(cfg), + InspectionRecord: NewInspectionRecordClient(cfg), + Inventory: NewInventoryClient(cfg), + InventoryLock: NewInventoryLockClient(cfg), + Material: NewMaterialClient(cfg), + MaterialDemand: NewMaterialDemandClient(cfg), + OrderMaterialLedger: NewOrderMaterialLedgerClient(cfg), + OutboundDetail: NewOutboundDetailClient(cfg), + OutboundOrder: NewOutboundOrderClient(cfg), + Permission: NewPermissionClient(cfg), + ReturnOrder: NewReturnOrderClient(cfg), + Role: NewRoleClient(cfg), + SemiFinished: NewSemiFinishedClient(cfg), + StocktakeItem: NewStocktakeItemClient(cfg), + StocktakeOrder: NewStocktakeOrderClient(cfg), + SyncFailure: NewSyncFailureClient(cfg), + SysConfig: NewSysConfigClient(cfg), + User: NewUserClient(cfg), + Zone: NewZoneClient(cfg), }, nil } @@ -337,10 +343,10 @@ func (c *Client) Use(hooks ...Hook) { for _, n := range []interface{ Use(...Hook) }{ c.Alert, c.AlertRule, c.Attachment, c.BackupRecord, c.DeliveryOrder, c.DeliveryOrderItem, c.EventLog, c.InboundDetail, c.InboundOrder, - 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.SyncFailure, c.SysConfig, c.User, c.Zone, + c.InspectionDisposalItem, 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.SyncFailure, c.SysConfig, c.User, c.Zone, } { n.Use(hooks...) } @@ -352,10 +358,10 @@ func (c *Client) Intercept(interceptors ...Interceptor) { for _, n := range []interface{ Intercept(...Interceptor) }{ c.Alert, c.AlertRule, c.Attachment, c.BackupRecord, c.DeliveryOrder, c.DeliveryOrderItem, c.EventLog, c.InboundDetail, c.InboundOrder, - 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.SyncFailure, c.SysConfig, c.User, c.Zone, + c.InspectionDisposalItem, 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.SyncFailure, c.SysConfig, c.User, c.Zone, } { n.Intercept(interceptors...) } @@ -382,6 +388,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.InboundDetail.mutate(ctx, m) case *InboundOrderMutation: return c.InboundOrder.mutate(ctx, m) + case *InspectionDisposalItemMutation: + return c.InspectionDisposalItem.mutate(ctx, m) case *InspectionRecordMutation: return c.InspectionRecord.mutate(ctx, m) case *InventoryMutation: @@ -1620,6 +1628,139 @@ func (c *InboundOrderClient) mutate(ctx context.Context, m *InboundOrderMutation } } +// InspectionDisposalItemClient is a client for the InspectionDisposalItem schema. +type InspectionDisposalItemClient struct { + config +} + +// NewInspectionDisposalItemClient returns a client for the InspectionDisposalItem from the given config. +func NewInspectionDisposalItemClient(c config) *InspectionDisposalItemClient { + return &InspectionDisposalItemClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `inspectiondisposalitem.Hooks(f(g(h())))`. +func (c *InspectionDisposalItemClient) Use(hooks ...Hook) { + c.hooks.InspectionDisposalItem = append(c.hooks.InspectionDisposalItem, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `inspectiondisposalitem.Intercept(f(g(h())))`. +func (c *InspectionDisposalItemClient) Intercept(interceptors ...Interceptor) { + c.inters.InspectionDisposalItem = append(c.inters.InspectionDisposalItem, interceptors...) +} + +// Create returns a builder for creating a InspectionDisposalItem entity. +func (c *InspectionDisposalItemClient) Create() *InspectionDisposalItemCreate { + mutation := newInspectionDisposalItemMutation(c.config, OpCreate) + return &InspectionDisposalItemCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of InspectionDisposalItem entities. +func (c *InspectionDisposalItemClient) CreateBulk(builders ...*InspectionDisposalItemCreate) *InspectionDisposalItemCreateBulk { + return &InspectionDisposalItemCreateBulk{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 *InspectionDisposalItemClient) MapCreateBulk(slice any, setFunc func(*InspectionDisposalItemCreate, int)) *InspectionDisposalItemCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &InspectionDisposalItemCreateBulk{err: fmt.Errorf("calling to InspectionDisposalItemClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*InspectionDisposalItemCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &InspectionDisposalItemCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for InspectionDisposalItem. +func (c *InspectionDisposalItemClient) Update() *InspectionDisposalItemUpdate { + mutation := newInspectionDisposalItemMutation(c.config, OpUpdate) + return &InspectionDisposalItemUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *InspectionDisposalItemClient) UpdateOne(_m *InspectionDisposalItem) *InspectionDisposalItemUpdateOne { + mutation := newInspectionDisposalItemMutation(c.config, OpUpdateOne, withInspectionDisposalItem(_m)) + return &InspectionDisposalItemUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *InspectionDisposalItemClient) UpdateOneID(id int) *InspectionDisposalItemUpdateOne { + mutation := newInspectionDisposalItemMutation(c.config, OpUpdateOne, withInspectionDisposalItemID(id)) + return &InspectionDisposalItemUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for InspectionDisposalItem. +func (c *InspectionDisposalItemClient) Delete() *InspectionDisposalItemDelete { + mutation := newInspectionDisposalItemMutation(c.config, OpDelete) + return &InspectionDisposalItemDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *InspectionDisposalItemClient) DeleteOne(_m *InspectionDisposalItem) *InspectionDisposalItemDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *InspectionDisposalItemClient) DeleteOneID(id int) *InspectionDisposalItemDeleteOne { + builder := c.Delete().Where(inspectiondisposalitem.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &InspectionDisposalItemDeleteOne{builder} +} + +// Query returns a query builder for InspectionDisposalItem. +func (c *InspectionDisposalItemClient) Query() *InspectionDisposalItemQuery { + return &InspectionDisposalItemQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeInspectionDisposalItem}, + inters: c.Interceptors(), + } +} + +// Get returns a InspectionDisposalItem entity by its id. +func (c *InspectionDisposalItemClient) Get(ctx context.Context, id int) (*InspectionDisposalItem, error) { + return c.Query().Where(inspectiondisposalitem.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *InspectionDisposalItemClient) GetX(ctx context.Context, id int) *InspectionDisposalItem { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *InspectionDisposalItemClient) Hooks() []Hook { + return c.hooks.InspectionDisposalItem +} + +// Interceptors returns the client interceptors. +func (c *InspectionDisposalItemClient) Interceptors() []Interceptor { + return c.inters.InspectionDisposalItem +} + +func (c *InspectionDisposalItemClient) mutate(ctx context.Context, m *InspectionDisposalItemMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&InspectionDisposalItemCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&InspectionDisposalItemUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&InspectionDisposalItemUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&InspectionDisposalItemDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown InspectionDisposalItem mutation op: %q", m.Op()) + } +} + // InspectionRecordClient is a client for the InspectionRecord schema. type InspectionRecordClient struct { config @@ -4018,16 +4159,18 @@ func (c *ZoneClient) mutate(ctx context.Context, m *ZoneMutation) (Value, error) type ( hooks struct { Alert, AlertRule, Attachment, BackupRecord, DeliveryOrder, DeliveryOrderItem, - EventLog, InboundDetail, InboundOrder, InspectionRecord, Inventory, - InventoryLock, Material, MaterialDemand, OrderMaterialLedger, OutboundDetail, - OutboundOrder, Permission, ReturnOrder, Role, SemiFinished, StocktakeItem, - StocktakeOrder, SyncFailure, SysConfig, User, Zone []ent.Hook + EventLog, InboundDetail, InboundOrder, InspectionDisposalItem, + InspectionRecord, Inventory, InventoryLock, Material, MaterialDemand, + OrderMaterialLedger, OutboundDetail, OutboundOrder, Permission, ReturnOrder, + Role, SemiFinished, StocktakeItem, 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, SyncFailure, SysConfig, User, Zone []ent.Interceptor + EventLog, InboundDetail, InboundOrder, InspectionDisposalItem, + InspectionRecord, Inventory, InventoryLock, Material, MaterialDemand, + OrderMaterialLedger, OutboundDetail, OutboundOrder, Permission, ReturnOrder, + Role, SemiFinished, StocktakeItem, StocktakeOrder, SyncFailure, SysConfig, + User, Zone []ent.Interceptor } ) diff --git a/bj_power_wms/ent/ent.go b/bj_power_wms/ent/ent.go index 22772bf..a41ed63 100644 --- a/bj_power_wms/ent/ent.go +++ b/bj_power_wms/ent/ent.go @@ -12,6 +12,7 @@ import ( "bj_power_wms/ent/eventlog" "bj_power_wms/ent/inbounddetail" "bj_power_wms/ent/inboundorder" + "bj_power_wms/ent/inspectiondisposalitem" "bj_power_wms/ent/inspectionrecord" "bj_power_wms/ent/inventory" "bj_power_wms/ent/inventorylock" @@ -99,33 +100,34 @@ var ( func checkColumn(t, c string) error { initCheck.Do(func() { columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ - alert.Table: alert.ValidColumn, - alertrule.Table: alertrule.ValidColumn, - attachment.Table: attachment.ValidColumn, - backuprecord.Table: backuprecord.ValidColumn, - deliveryorder.Table: deliveryorder.ValidColumn, - deliveryorderitem.Table: deliveryorderitem.ValidColumn, - eventlog.Table: eventlog.ValidColumn, - inbounddetail.Table: inbounddetail.ValidColumn, - inboundorder.Table: inboundorder.ValidColumn, - inspectionrecord.Table: inspectionrecord.ValidColumn, - inventory.Table: inventory.ValidColumn, - inventorylock.Table: inventorylock.ValidColumn, - material.Table: material.ValidColumn, - materialdemand.Table: materialdemand.ValidColumn, - ordermaterialledger.Table: ordermaterialledger.ValidColumn, - outbounddetail.Table: outbounddetail.ValidColumn, - outboundorder.Table: outboundorder.ValidColumn, - permission.Table: permission.ValidColumn, - returnorder.Table: returnorder.ValidColumn, - role.Table: role.ValidColumn, - 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, + alert.Table: alert.ValidColumn, + alertrule.Table: alertrule.ValidColumn, + attachment.Table: attachment.ValidColumn, + backuprecord.Table: backuprecord.ValidColumn, + deliveryorder.Table: deliveryorder.ValidColumn, + deliveryorderitem.Table: deliveryorderitem.ValidColumn, + eventlog.Table: eventlog.ValidColumn, + inbounddetail.Table: inbounddetail.ValidColumn, + inboundorder.Table: inboundorder.ValidColumn, + inspectiondisposalitem.Table: inspectiondisposalitem.ValidColumn, + inspectionrecord.Table: inspectionrecord.ValidColumn, + inventory.Table: inventory.ValidColumn, + inventorylock.Table: inventorylock.ValidColumn, + material.Table: material.ValidColumn, + materialdemand.Table: materialdemand.ValidColumn, + ordermaterialledger.Table: ordermaterialledger.ValidColumn, + outbounddetail.Table: outbounddetail.ValidColumn, + outboundorder.Table: outboundorder.ValidColumn, + permission.Table: permission.ValidColumn, + returnorder.Table: returnorder.ValidColumn, + role.Table: role.ValidColumn, + 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, }) }) return columnCheck(t, c) diff --git a/bj_power_wms/ent/hook/hook.go b/bj_power_wms/ent/hook/hook.go index 3df78f2..3ac4b7f 100644 --- a/bj_power_wms/ent/hook/hook.go +++ b/bj_power_wms/ent/hook/hook.go @@ -116,6 +116,18 @@ func (f InboundOrderFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.InboundOrderMutation", m) } +// The InspectionDisposalItemFunc type is an adapter to allow the use of ordinary +// function as InspectionDisposalItem mutator. +type InspectionDisposalItemFunc func(context.Context, *ent.InspectionDisposalItemMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f InspectionDisposalItemFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.InspectionDisposalItemMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.InspectionDisposalItemMutation", m) +} + // The InspectionRecordFunc type is an adapter to allow the use of ordinary // function as InspectionRecord mutator. type InspectionRecordFunc func(context.Context, *ent.InspectionRecordMutation) (ent.Value, error) diff --git a/bj_power_wms/ent/inspectiondisposalitem.go b/bj_power_wms/ent/inspectiondisposalitem.go new file mode 100644 index 0000000..f8ae2e3 --- /dev/null +++ b/bj_power_wms/ent/inspectiondisposalitem.go @@ -0,0 +1,158 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_wms/ent/inspectiondisposalitem" + "fmt" + "strings" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" +) + +// InspectionDisposalItem 不合格品处置明细(按数量分退货/返修/报废) +type InspectionDisposalItem struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // 父检验记录ID(inspection_records.id) + RecordID int64 `json:"recordId,omitempty"` + // 处置方式 RETURN/REWORK/SCRAP + DisposeType string `json:"disposeType,omitempty"` + // 本行处置数量(合计=记录不合格数) + Qty int `json:"qty,omitempty"` + // 处置备注(非必填;退货物流信息也填此处) + Remark string `json:"remark,omitempty"` + // 操作人 + Operator string `json:"operator,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt int64 `json:"createdAt,omitempty"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*InspectionDisposalItem) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case inspectiondisposalitem.FieldID, inspectiondisposalitem.FieldRecordID, inspectiondisposalitem.FieldQty, inspectiondisposalitem.FieldCreatedAt: + values[i] = new(sql.NullInt64) + case inspectiondisposalitem.FieldDisposeType, inspectiondisposalitem.FieldRemark, inspectiondisposalitem.FieldOperator: + 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 InspectionDisposalItem fields. +func (_m *InspectionDisposalItem) 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 inspectiondisposalitem.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 inspectiondisposalitem.FieldRecordID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field record_id", values[i]) + } else if value.Valid { + _m.RecordID = value.Int64 + } + case inspectiondisposalitem.FieldDisposeType: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field dispose_type", values[i]) + } else if value.Valid { + _m.DisposeType = value.String + } + case inspectiondisposalitem.FieldQty: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field qty", values[i]) + } else if value.Valid { + _m.Qty = int(value.Int64) + } + case inspectiondisposalitem.FieldRemark: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field remark", values[i]) + } else if value.Valid { + _m.Remark = value.String + } + case inspectiondisposalitem.FieldOperator: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field operator", values[i]) + } else if value.Valid { + _m.Operator = value.String + } + case inspectiondisposalitem.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 + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the InspectionDisposalItem. +// This includes values selected through modifiers, order, etc. +func (_m *InspectionDisposalItem) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// Update returns a builder for updating this InspectionDisposalItem. +// Note that you need to call InspectionDisposalItem.Unwrap() before calling this method if this InspectionDisposalItem +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *InspectionDisposalItem) Update() *InspectionDisposalItemUpdateOne { + return NewInspectionDisposalItemClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the InspectionDisposalItem 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 *InspectionDisposalItem) Unwrap() *InspectionDisposalItem { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: InspectionDisposalItem is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *InspectionDisposalItem) String() string { + var builder strings.Builder + builder.WriteString("InspectionDisposalItem(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("record_id=") + builder.WriteString(fmt.Sprintf("%v", _m.RecordID)) + builder.WriteString(", ") + builder.WriteString("dispose_type=") + builder.WriteString(_m.DisposeType) + builder.WriteString(", ") + builder.WriteString("qty=") + builder.WriteString(fmt.Sprintf("%v", _m.Qty)) + builder.WriteString(", ") + builder.WriteString("remark=") + builder.WriteString(_m.Remark) + builder.WriteString(", ") + builder.WriteString("operator=") + builder.WriteString(_m.Operator) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(fmt.Sprintf("%v", _m.CreatedAt)) + builder.WriteByte(')') + return builder.String() +} + +// InspectionDisposalItems is a parsable slice of InspectionDisposalItem. +type InspectionDisposalItems []*InspectionDisposalItem diff --git a/bj_power_wms/ent/inspectiondisposalitem/inspectiondisposalitem.go b/bj_power_wms/ent/inspectiondisposalitem/inspectiondisposalitem.go new file mode 100644 index 0000000..b0c675d --- /dev/null +++ b/bj_power_wms/ent/inspectiondisposalitem/inspectiondisposalitem.go @@ -0,0 +1,96 @@ +// Code generated by ent, DO NOT EDIT. + +package inspectiondisposalitem + +import ( + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the inspectiondisposalitem type in the database. + Label = "inspection_disposal_item" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldRecordID holds the string denoting the record_id field in the database. + FieldRecordID = "record_id" + // FieldDisposeType holds the string denoting the dispose_type field in the database. + FieldDisposeType = "dispose_type" + // FieldQty holds the string denoting the qty field in the database. + FieldQty = "qty" + // FieldRemark holds the string denoting the remark field in the database. + FieldRemark = "remark" + // FieldOperator holds the string denoting the operator field in the database. + FieldOperator = "operator" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // Table holds the table name of the inspectiondisposalitem in the database. + Table = "inspection_disposal_items" +) + +// Columns holds all SQL columns for inspectiondisposalitem fields. +var Columns = []string{ + FieldID, + FieldRecordID, + FieldDisposeType, + FieldQty, + FieldRemark, + FieldOperator, + FieldCreatedAt, +} + +// 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 ( + // QtyValidator is a validator for the "qty" field. It is called by the builders before save. + QtyValidator func(int) error + // DefaultOperator holds the default value on creation for the "operator" field. + DefaultOperator string + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() int64 +) + +// OrderOption defines the ordering options for the InspectionDisposalItem 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() +} + +// ByRecordID orders the results by the record_id field. +func ByRecordID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRecordID, opts...).ToFunc() +} + +// ByDisposeType orders the results by the dispose_type field. +func ByDisposeType(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDisposeType, opts...).ToFunc() +} + +// ByQty orders the results by the qty field. +func ByQty(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldQty, opts...).ToFunc() +} + +// ByRemark orders the results by the remark field. +func ByRemark(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRemark, opts...).ToFunc() +} + +// ByOperator orders the results by the operator field. +func ByOperator(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldOperator, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} diff --git a/bj_power_wms/ent/inspectiondisposalitem/where.go b/bj_power_wms/ent/inspectiondisposalitem/where.go new file mode 100644 index 0000000..73763b0 --- /dev/null +++ b/bj_power_wms/ent/inspectiondisposalitem/where.go @@ -0,0 +1,424 @@ +// Code generated by ent, DO NOT EDIT. + +package inspectiondisposalitem + +import ( + "bj_power_wms/ent/predicate" + + "entgo.io/ent/dialect/sql" +) + +// ID filters vertices based on their ID field. +func ID(id int) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldLTE(FieldID, id)) +} + +// RecordID applies equality check predicate on the "record_id" field. It's identical to RecordIDEQ. +func RecordID(v int64) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldEQ(FieldRecordID, v)) +} + +// DisposeType applies equality check predicate on the "dispose_type" field. It's identical to DisposeTypeEQ. +func DisposeType(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldEQ(FieldDisposeType, v)) +} + +// Qty applies equality check predicate on the "qty" field. It's identical to QtyEQ. +func Qty(v int) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldEQ(FieldQty, v)) +} + +// Remark applies equality check predicate on the "remark" field. It's identical to RemarkEQ. +func Remark(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldEQ(FieldRemark, v)) +} + +// Operator applies equality check predicate on the "operator" field. It's identical to OperatorEQ. +func Operator(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldEQ(FieldOperator, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v int64) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldEQ(FieldCreatedAt, v)) +} + +// RecordIDEQ applies the EQ predicate on the "record_id" field. +func RecordIDEQ(v int64) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldEQ(FieldRecordID, v)) +} + +// RecordIDNEQ applies the NEQ predicate on the "record_id" field. +func RecordIDNEQ(v int64) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldNEQ(FieldRecordID, v)) +} + +// RecordIDIn applies the In predicate on the "record_id" field. +func RecordIDIn(vs ...int64) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldIn(FieldRecordID, vs...)) +} + +// RecordIDNotIn applies the NotIn predicate on the "record_id" field. +func RecordIDNotIn(vs ...int64) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldNotIn(FieldRecordID, vs...)) +} + +// RecordIDGT applies the GT predicate on the "record_id" field. +func RecordIDGT(v int64) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldGT(FieldRecordID, v)) +} + +// RecordIDGTE applies the GTE predicate on the "record_id" field. +func RecordIDGTE(v int64) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldGTE(FieldRecordID, v)) +} + +// RecordIDLT applies the LT predicate on the "record_id" field. +func RecordIDLT(v int64) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldLT(FieldRecordID, v)) +} + +// RecordIDLTE applies the LTE predicate on the "record_id" field. +func RecordIDLTE(v int64) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldLTE(FieldRecordID, v)) +} + +// DisposeTypeEQ applies the EQ predicate on the "dispose_type" field. +func DisposeTypeEQ(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldEQ(FieldDisposeType, v)) +} + +// DisposeTypeNEQ applies the NEQ predicate on the "dispose_type" field. +func DisposeTypeNEQ(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldNEQ(FieldDisposeType, v)) +} + +// DisposeTypeIn applies the In predicate on the "dispose_type" field. +func DisposeTypeIn(vs ...string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldIn(FieldDisposeType, vs...)) +} + +// DisposeTypeNotIn applies the NotIn predicate on the "dispose_type" field. +func DisposeTypeNotIn(vs ...string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldNotIn(FieldDisposeType, vs...)) +} + +// DisposeTypeGT applies the GT predicate on the "dispose_type" field. +func DisposeTypeGT(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldGT(FieldDisposeType, v)) +} + +// DisposeTypeGTE applies the GTE predicate on the "dispose_type" field. +func DisposeTypeGTE(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldGTE(FieldDisposeType, v)) +} + +// DisposeTypeLT applies the LT predicate on the "dispose_type" field. +func DisposeTypeLT(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldLT(FieldDisposeType, v)) +} + +// DisposeTypeLTE applies the LTE predicate on the "dispose_type" field. +func DisposeTypeLTE(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldLTE(FieldDisposeType, v)) +} + +// DisposeTypeContains applies the Contains predicate on the "dispose_type" field. +func DisposeTypeContains(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldContains(FieldDisposeType, v)) +} + +// DisposeTypeHasPrefix applies the HasPrefix predicate on the "dispose_type" field. +func DisposeTypeHasPrefix(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldHasPrefix(FieldDisposeType, v)) +} + +// DisposeTypeHasSuffix applies the HasSuffix predicate on the "dispose_type" field. +func DisposeTypeHasSuffix(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldHasSuffix(FieldDisposeType, v)) +} + +// DisposeTypeEqualFold applies the EqualFold predicate on the "dispose_type" field. +func DisposeTypeEqualFold(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldEqualFold(FieldDisposeType, v)) +} + +// DisposeTypeContainsFold applies the ContainsFold predicate on the "dispose_type" field. +func DisposeTypeContainsFold(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldContainsFold(FieldDisposeType, v)) +} + +// QtyEQ applies the EQ predicate on the "qty" field. +func QtyEQ(v int) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldEQ(FieldQty, v)) +} + +// QtyNEQ applies the NEQ predicate on the "qty" field. +func QtyNEQ(v int) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldNEQ(FieldQty, v)) +} + +// QtyIn applies the In predicate on the "qty" field. +func QtyIn(vs ...int) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldIn(FieldQty, vs...)) +} + +// QtyNotIn applies the NotIn predicate on the "qty" field. +func QtyNotIn(vs ...int) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldNotIn(FieldQty, vs...)) +} + +// QtyGT applies the GT predicate on the "qty" field. +func QtyGT(v int) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldGT(FieldQty, v)) +} + +// QtyGTE applies the GTE predicate on the "qty" field. +func QtyGTE(v int) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldGTE(FieldQty, v)) +} + +// QtyLT applies the LT predicate on the "qty" field. +func QtyLT(v int) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldLT(FieldQty, v)) +} + +// QtyLTE applies the LTE predicate on the "qty" field. +func QtyLTE(v int) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldLTE(FieldQty, v)) +} + +// RemarkEQ applies the EQ predicate on the "remark" field. +func RemarkEQ(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldEQ(FieldRemark, v)) +} + +// RemarkNEQ applies the NEQ predicate on the "remark" field. +func RemarkNEQ(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldNEQ(FieldRemark, v)) +} + +// RemarkIn applies the In predicate on the "remark" field. +func RemarkIn(vs ...string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldIn(FieldRemark, vs...)) +} + +// RemarkNotIn applies the NotIn predicate on the "remark" field. +func RemarkNotIn(vs ...string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldNotIn(FieldRemark, vs...)) +} + +// RemarkGT applies the GT predicate on the "remark" field. +func RemarkGT(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldGT(FieldRemark, v)) +} + +// RemarkGTE applies the GTE predicate on the "remark" field. +func RemarkGTE(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldGTE(FieldRemark, v)) +} + +// RemarkLT applies the LT predicate on the "remark" field. +func RemarkLT(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldLT(FieldRemark, v)) +} + +// RemarkLTE applies the LTE predicate on the "remark" field. +func RemarkLTE(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldLTE(FieldRemark, v)) +} + +// RemarkContains applies the Contains predicate on the "remark" field. +func RemarkContains(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldContains(FieldRemark, v)) +} + +// RemarkHasPrefix applies the HasPrefix predicate on the "remark" field. +func RemarkHasPrefix(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldHasPrefix(FieldRemark, v)) +} + +// RemarkHasSuffix applies the HasSuffix predicate on the "remark" field. +func RemarkHasSuffix(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldHasSuffix(FieldRemark, v)) +} + +// RemarkIsNil applies the IsNil predicate on the "remark" field. +func RemarkIsNil() predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldIsNull(FieldRemark)) +} + +// RemarkNotNil applies the NotNil predicate on the "remark" field. +func RemarkNotNil() predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldNotNull(FieldRemark)) +} + +// RemarkEqualFold applies the EqualFold predicate on the "remark" field. +func RemarkEqualFold(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldEqualFold(FieldRemark, v)) +} + +// RemarkContainsFold applies the ContainsFold predicate on the "remark" field. +func RemarkContainsFold(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldContainsFold(FieldRemark, v)) +} + +// OperatorEQ applies the EQ predicate on the "operator" field. +func OperatorEQ(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldEQ(FieldOperator, v)) +} + +// OperatorNEQ applies the NEQ predicate on the "operator" field. +func OperatorNEQ(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldNEQ(FieldOperator, v)) +} + +// OperatorIn applies the In predicate on the "operator" field. +func OperatorIn(vs ...string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldIn(FieldOperator, vs...)) +} + +// OperatorNotIn applies the NotIn predicate on the "operator" field. +func OperatorNotIn(vs ...string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldNotIn(FieldOperator, vs...)) +} + +// OperatorGT applies the GT predicate on the "operator" field. +func OperatorGT(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldGT(FieldOperator, v)) +} + +// OperatorGTE applies the GTE predicate on the "operator" field. +func OperatorGTE(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldGTE(FieldOperator, v)) +} + +// OperatorLT applies the LT predicate on the "operator" field. +func OperatorLT(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldLT(FieldOperator, v)) +} + +// OperatorLTE applies the LTE predicate on the "operator" field. +func OperatorLTE(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldLTE(FieldOperator, v)) +} + +// OperatorContains applies the Contains predicate on the "operator" field. +func OperatorContains(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldContains(FieldOperator, v)) +} + +// OperatorHasPrefix applies the HasPrefix predicate on the "operator" field. +func OperatorHasPrefix(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldHasPrefix(FieldOperator, v)) +} + +// OperatorHasSuffix applies the HasSuffix predicate on the "operator" field. +func OperatorHasSuffix(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldHasSuffix(FieldOperator, v)) +} + +// OperatorEqualFold applies the EqualFold predicate on the "operator" field. +func OperatorEqualFold(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldEqualFold(FieldOperator, v)) +} + +// OperatorContainsFold applies the ContainsFold predicate on the "operator" field. +func OperatorContainsFold(v string) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldContainsFold(FieldOperator, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v int64) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v int64) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...int64) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...int64) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v int64) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v int64) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v int64) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v int64) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.FieldLTE(FieldCreatedAt, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.InspectionDisposalItem) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.InspectionDisposalItem) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.InspectionDisposalItem) predicate.InspectionDisposalItem { + return predicate.InspectionDisposalItem(sql.NotPredicates(p)) +} diff --git a/bj_power_wms/ent/inspectiondisposalitem_create.go b/bj_power_wms/ent/inspectiondisposalitem_create.go new file mode 100644 index 0000000..4203b46 --- /dev/null +++ b/bj_power_wms/ent/inspectiondisposalitem_create.go @@ -0,0 +1,839 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_wms/ent/inspectiondisposalitem" + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// InspectionDisposalItemCreate is the builder for creating a InspectionDisposalItem entity. +type InspectionDisposalItemCreate struct { + config + mutation *InspectionDisposalItemMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetRecordID sets the "record_id" field. +func (_c *InspectionDisposalItemCreate) SetRecordID(v int64) *InspectionDisposalItemCreate { + _c.mutation.SetRecordID(v) + return _c +} + +// SetDisposeType sets the "dispose_type" field. +func (_c *InspectionDisposalItemCreate) SetDisposeType(v string) *InspectionDisposalItemCreate { + _c.mutation.SetDisposeType(v) + return _c +} + +// SetQty sets the "qty" field. +func (_c *InspectionDisposalItemCreate) SetQty(v int) *InspectionDisposalItemCreate { + _c.mutation.SetQty(v) + return _c +} + +// SetRemark sets the "remark" field. +func (_c *InspectionDisposalItemCreate) SetRemark(v string) *InspectionDisposalItemCreate { + _c.mutation.SetRemark(v) + return _c +} + +// SetNillableRemark sets the "remark" field if the given value is not nil. +func (_c *InspectionDisposalItemCreate) SetNillableRemark(v *string) *InspectionDisposalItemCreate { + if v != nil { + _c.SetRemark(*v) + } + return _c +} + +// SetOperator sets the "operator" field. +func (_c *InspectionDisposalItemCreate) SetOperator(v string) *InspectionDisposalItemCreate { + _c.mutation.SetOperator(v) + return _c +} + +// SetNillableOperator sets the "operator" field if the given value is not nil. +func (_c *InspectionDisposalItemCreate) SetNillableOperator(v *string) *InspectionDisposalItemCreate { + if v != nil { + _c.SetOperator(*v) + } + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *InspectionDisposalItemCreate) SetCreatedAt(v int64) *InspectionDisposalItemCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *InspectionDisposalItemCreate) SetNillableCreatedAt(v *int64) *InspectionDisposalItemCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// Mutation returns the InspectionDisposalItemMutation object of the builder. +func (_c *InspectionDisposalItemCreate) Mutation() *InspectionDisposalItemMutation { + return _c.mutation +} + +// Save creates the InspectionDisposalItem in the database. +func (_c *InspectionDisposalItemCreate) Save(ctx context.Context) (*InspectionDisposalItem, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *InspectionDisposalItemCreate) SaveX(ctx context.Context) *InspectionDisposalItem { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *InspectionDisposalItemCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *InspectionDisposalItemCreate) 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 *InspectionDisposalItemCreate) defaults() { + if _, ok := _c.mutation.Operator(); !ok { + v := inspectiondisposalitem.DefaultOperator + _c.mutation.SetOperator(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := inspectiondisposalitem.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *InspectionDisposalItemCreate) check() error { + if _, ok := _c.mutation.RecordID(); !ok { + return &ValidationError{Name: "record_id", err: errors.New(`ent: missing required field "InspectionDisposalItem.record_id"`)} + } + if _, ok := _c.mutation.DisposeType(); !ok { + return &ValidationError{Name: "dispose_type", err: errors.New(`ent: missing required field "InspectionDisposalItem.dispose_type"`)} + } + if _, ok := _c.mutation.Qty(); !ok { + return &ValidationError{Name: "qty", err: errors.New(`ent: missing required field "InspectionDisposalItem.qty"`)} + } + if v, ok := _c.mutation.Qty(); ok { + if err := inspectiondisposalitem.QtyValidator(v); err != nil { + return &ValidationError{Name: "qty", err: fmt.Errorf(`ent: validator failed for field "InspectionDisposalItem.qty": %w`, err)} + } + } + if _, ok := _c.mutation.Operator(); !ok { + return &ValidationError{Name: "operator", err: errors.New(`ent: missing required field "InspectionDisposalItem.operator"`)} + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "InspectionDisposalItem.created_at"`)} + } + return nil +} + +func (_c *InspectionDisposalItemCreate) sqlSave(ctx context.Context) (*InspectionDisposalItem, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + id := _spec.ID.Value.(int64) + _node.ID = int(id) + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *InspectionDisposalItemCreate) createSpec() (*InspectionDisposalItem, *sqlgraph.CreateSpec) { + var ( + _node = &InspectionDisposalItem{config: _c.config} + _spec = sqlgraph.NewCreateSpec(inspectiondisposalitem.Table, sqlgraph.NewFieldSpec(inspectiondisposalitem.FieldID, field.TypeInt)) + ) + _spec.OnConflict = _c.conflict + if value, ok := _c.mutation.RecordID(); ok { + _spec.SetField(inspectiondisposalitem.FieldRecordID, field.TypeInt64, value) + _node.RecordID = value + } + if value, ok := _c.mutation.DisposeType(); ok { + _spec.SetField(inspectiondisposalitem.FieldDisposeType, field.TypeString, value) + _node.DisposeType = value + } + if value, ok := _c.mutation.Qty(); ok { + _spec.SetField(inspectiondisposalitem.FieldQty, field.TypeInt, value) + _node.Qty = value + } + if value, ok := _c.mutation.Remark(); ok { + _spec.SetField(inspectiondisposalitem.FieldRemark, field.TypeString, value) + _node.Remark = value + } + if value, ok := _c.mutation.Operator(); ok { + _spec.SetField(inspectiondisposalitem.FieldOperator, field.TypeString, value) + _node.Operator = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(inspectiondisposalitem.FieldCreatedAt, field.TypeInt64, value) + _node.CreatedAt = value + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.InspectionDisposalItem.Create(). +// SetRecordID(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.InspectionDisposalItemUpsert) { +// SetRecordID(v+v). +// }). +// Exec(ctx) +func (_c *InspectionDisposalItemCreate) OnConflict(opts ...sql.ConflictOption) *InspectionDisposalItemUpsertOne { + _c.conflict = opts + return &InspectionDisposalItemUpsertOne{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.InspectionDisposalItem.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *InspectionDisposalItemCreate) OnConflictColumns(columns ...string) *InspectionDisposalItemUpsertOne { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &InspectionDisposalItemUpsertOne{ + create: _c, + } +} + +type ( + // InspectionDisposalItemUpsertOne is the builder for "upsert"-ing + // one InspectionDisposalItem node. + InspectionDisposalItemUpsertOne struct { + create *InspectionDisposalItemCreate + } + + // InspectionDisposalItemUpsert is the "OnConflict" setter. + InspectionDisposalItemUpsert struct { + *sql.UpdateSet + } +) + +// SetRecordID sets the "record_id" field. +func (u *InspectionDisposalItemUpsert) SetRecordID(v int64) *InspectionDisposalItemUpsert { + u.Set(inspectiondisposalitem.FieldRecordID, v) + return u +} + +// UpdateRecordID sets the "record_id" field to the value that was provided on create. +func (u *InspectionDisposalItemUpsert) UpdateRecordID() *InspectionDisposalItemUpsert { + u.SetExcluded(inspectiondisposalitem.FieldRecordID) + return u +} + +// AddRecordID adds v to the "record_id" field. +func (u *InspectionDisposalItemUpsert) AddRecordID(v int64) *InspectionDisposalItemUpsert { + u.Add(inspectiondisposalitem.FieldRecordID, v) + return u +} + +// SetDisposeType sets the "dispose_type" field. +func (u *InspectionDisposalItemUpsert) SetDisposeType(v string) *InspectionDisposalItemUpsert { + u.Set(inspectiondisposalitem.FieldDisposeType, v) + return u +} + +// UpdateDisposeType sets the "dispose_type" field to the value that was provided on create. +func (u *InspectionDisposalItemUpsert) UpdateDisposeType() *InspectionDisposalItemUpsert { + u.SetExcluded(inspectiondisposalitem.FieldDisposeType) + return u +} + +// SetQty sets the "qty" field. +func (u *InspectionDisposalItemUpsert) SetQty(v int) *InspectionDisposalItemUpsert { + u.Set(inspectiondisposalitem.FieldQty, v) + return u +} + +// UpdateQty sets the "qty" field to the value that was provided on create. +func (u *InspectionDisposalItemUpsert) UpdateQty() *InspectionDisposalItemUpsert { + u.SetExcluded(inspectiondisposalitem.FieldQty) + return u +} + +// AddQty adds v to the "qty" field. +func (u *InspectionDisposalItemUpsert) AddQty(v int) *InspectionDisposalItemUpsert { + u.Add(inspectiondisposalitem.FieldQty, v) + return u +} + +// SetRemark sets the "remark" field. +func (u *InspectionDisposalItemUpsert) SetRemark(v string) *InspectionDisposalItemUpsert { + u.Set(inspectiondisposalitem.FieldRemark, v) + return u +} + +// UpdateRemark sets the "remark" field to the value that was provided on create. +func (u *InspectionDisposalItemUpsert) UpdateRemark() *InspectionDisposalItemUpsert { + u.SetExcluded(inspectiondisposalitem.FieldRemark) + return u +} + +// ClearRemark clears the value of the "remark" field. +func (u *InspectionDisposalItemUpsert) ClearRemark() *InspectionDisposalItemUpsert { + u.SetNull(inspectiondisposalitem.FieldRemark) + return u +} + +// SetOperator sets the "operator" field. +func (u *InspectionDisposalItemUpsert) SetOperator(v string) *InspectionDisposalItemUpsert { + u.Set(inspectiondisposalitem.FieldOperator, v) + return u +} + +// UpdateOperator sets the "operator" field to the value that was provided on create. +func (u *InspectionDisposalItemUpsert) UpdateOperator() *InspectionDisposalItemUpsert { + u.SetExcluded(inspectiondisposalitem.FieldOperator) + return u +} + +// SetCreatedAt sets the "created_at" field. +func (u *InspectionDisposalItemUpsert) SetCreatedAt(v int64) *InspectionDisposalItemUpsert { + u.Set(inspectiondisposalitem.FieldCreatedAt, v) + return u +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *InspectionDisposalItemUpsert) UpdateCreatedAt() *InspectionDisposalItemUpsert { + u.SetExcluded(inspectiondisposalitem.FieldCreatedAt) + return u +} + +// AddCreatedAt adds v to the "created_at" field. +func (u *InspectionDisposalItemUpsert) AddCreatedAt(v int64) *InspectionDisposalItemUpsert { + u.Add(inspectiondisposalitem.FieldCreatedAt, v) + return u +} + +// UpdateNewValues updates the mutable fields using the new values that were set on create. +// Using this option is equivalent to using: +// +// client.InspectionDisposalItem.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// ). +// Exec(ctx) +func (u *InspectionDisposalItemUpsertOne) UpdateNewValues() *InspectionDisposalItemUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.InspectionDisposalItem.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *InspectionDisposalItemUpsertOne) Ignore() *InspectionDisposalItemUpsertOne { + 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 *InspectionDisposalItemUpsertOne) DoNothing() *InspectionDisposalItemUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the InspectionDisposalItemCreate.OnConflict +// documentation for more info. +func (u *InspectionDisposalItemUpsertOne) Update(set func(*InspectionDisposalItemUpsert)) *InspectionDisposalItemUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&InspectionDisposalItemUpsert{UpdateSet: update}) + })) + return u +} + +// SetRecordID sets the "record_id" field. +func (u *InspectionDisposalItemUpsertOne) SetRecordID(v int64) *InspectionDisposalItemUpsertOne { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.SetRecordID(v) + }) +} + +// AddRecordID adds v to the "record_id" field. +func (u *InspectionDisposalItemUpsertOne) AddRecordID(v int64) *InspectionDisposalItemUpsertOne { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.AddRecordID(v) + }) +} + +// UpdateRecordID sets the "record_id" field to the value that was provided on create. +func (u *InspectionDisposalItemUpsertOne) UpdateRecordID() *InspectionDisposalItemUpsertOne { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.UpdateRecordID() + }) +} + +// SetDisposeType sets the "dispose_type" field. +func (u *InspectionDisposalItemUpsertOne) SetDisposeType(v string) *InspectionDisposalItemUpsertOne { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.SetDisposeType(v) + }) +} + +// UpdateDisposeType sets the "dispose_type" field to the value that was provided on create. +func (u *InspectionDisposalItemUpsertOne) UpdateDisposeType() *InspectionDisposalItemUpsertOne { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.UpdateDisposeType() + }) +} + +// SetQty sets the "qty" field. +func (u *InspectionDisposalItemUpsertOne) SetQty(v int) *InspectionDisposalItemUpsertOne { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.SetQty(v) + }) +} + +// AddQty adds v to the "qty" field. +func (u *InspectionDisposalItemUpsertOne) AddQty(v int) *InspectionDisposalItemUpsertOne { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.AddQty(v) + }) +} + +// UpdateQty sets the "qty" field to the value that was provided on create. +func (u *InspectionDisposalItemUpsertOne) UpdateQty() *InspectionDisposalItemUpsertOne { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.UpdateQty() + }) +} + +// SetRemark sets the "remark" field. +func (u *InspectionDisposalItemUpsertOne) SetRemark(v string) *InspectionDisposalItemUpsertOne { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.SetRemark(v) + }) +} + +// UpdateRemark sets the "remark" field to the value that was provided on create. +func (u *InspectionDisposalItemUpsertOne) UpdateRemark() *InspectionDisposalItemUpsertOne { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.UpdateRemark() + }) +} + +// ClearRemark clears the value of the "remark" field. +func (u *InspectionDisposalItemUpsertOne) ClearRemark() *InspectionDisposalItemUpsertOne { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.ClearRemark() + }) +} + +// SetOperator sets the "operator" field. +func (u *InspectionDisposalItemUpsertOne) SetOperator(v string) *InspectionDisposalItemUpsertOne { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.SetOperator(v) + }) +} + +// UpdateOperator sets the "operator" field to the value that was provided on create. +func (u *InspectionDisposalItemUpsertOne) UpdateOperator() *InspectionDisposalItemUpsertOne { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.UpdateOperator() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *InspectionDisposalItemUpsertOne) SetCreatedAt(v int64) *InspectionDisposalItemUpsertOne { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.SetCreatedAt(v) + }) +} + +// AddCreatedAt adds v to the "created_at" field. +func (u *InspectionDisposalItemUpsertOne) AddCreatedAt(v int64) *InspectionDisposalItemUpsertOne { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.AddCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *InspectionDisposalItemUpsertOne) UpdateCreatedAt() *InspectionDisposalItemUpsertOne { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.UpdateCreatedAt() + }) +} + +// Exec executes the query. +func (u *InspectionDisposalItemUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for InspectionDisposalItemCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *InspectionDisposalItemUpsertOne) 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 *InspectionDisposalItemUpsertOne) 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 *InspectionDisposalItemUpsertOne) IDX(ctx context.Context) int { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// InspectionDisposalItemCreateBulk is the builder for creating many InspectionDisposalItem entities in bulk. +type InspectionDisposalItemCreateBulk struct { + config + err error + builders []*InspectionDisposalItemCreate + conflict []sql.ConflictOption +} + +// Save creates the InspectionDisposalItem entities in the database. +func (_c *InspectionDisposalItemCreateBulk) Save(ctx context.Context) ([]*InspectionDisposalItem, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*InspectionDisposalItem, 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.(*InspectionDisposalItemMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + spec.OnConflict = _c.conflict + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + if specs[i].ID.Value != nil { + id := specs[i].ID.Value.(int64) + nodes[i].ID = 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 *InspectionDisposalItemCreateBulk) SaveX(ctx context.Context) []*InspectionDisposalItem { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *InspectionDisposalItemCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *InspectionDisposalItemCreateBulk) 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.InspectionDisposalItem.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.InspectionDisposalItemUpsert) { +// SetRecordID(v+v). +// }). +// Exec(ctx) +func (_c *InspectionDisposalItemCreateBulk) OnConflict(opts ...sql.ConflictOption) *InspectionDisposalItemUpsertBulk { + _c.conflict = opts + return &InspectionDisposalItemUpsertBulk{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.InspectionDisposalItem.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *InspectionDisposalItemCreateBulk) OnConflictColumns(columns ...string) *InspectionDisposalItemUpsertBulk { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &InspectionDisposalItemUpsertBulk{ + create: _c, + } +} + +// InspectionDisposalItemUpsertBulk is the builder for "upsert"-ing +// a bulk of InspectionDisposalItem nodes. +type InspectionDisposalItemUpsertBulk struct { + create *InspectionDisposalItemCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.InspectionDisposalItem.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// ). +// Exec(ctx) +func (u *InspectionDisposalItemUpsertBulk) UpdateNewValues() *InspectionDisposalItemUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.InspectionDisposalItem.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *InspectionDisposalItemUpsertBulk) Ignore() *InspectionDisposalItemUpsertBulk { + 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 *InspectionDisposalItemUpsertBulk) DoNothing() *InspectionDisposalItemUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the InspectionDisposalItemCreateBulk.OnConflict +// documentation for more info. +func (u *InspectionDisposalItemUpsertBulk) Update(set func(*InspectionDisposalItemUpsert)) *InspectionDisposalItemUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&InspectionDisposalItemUpsert{UpdateSet: update}) + })) + return u +} + +// SetRecordID sets the "record_id" field. +func (u *InspectionDisposalItemUpsertBulk) SetRecordID(v int64) *InspectionDisposalItemUpsertBulk { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.SetRecordID(v) + }) +} + +// AddRecordID adds v to the "record_id" field. +func (u *InspectionDisposalItemUpsertBulk) AddRecordID(v int64) *InspectionDisposalItemUpsertBulk { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.AddRecordID(v) + }) +} + +// UpdateRecordID sets the "record_id" field to the value that was provided on create. +func (u *InspectionDisposalItemUpsertBulk) UpdateRecordID() *InspectionDisposalItemUpsertBulk { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.UpdateRecordID() + }) +} + +// SetDisposeType sets the "dispose_type" field. +func (u *InspectionDisposalItemUpsertBulk) SetDisposeType(v string) *InspectionDisposalItemUpsertBulk { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.SetDisposeType(v) + }) +} + +// UpdateDisposeType sets the "dispose_type" field to the value that was provided on create. +func (u *InspectionDisposalItemUpsertBulk) UpdateDisposeType() *InspectionDisposalItemUpsertBulk { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.UpdateDisposeType() + }) +} + +// SetQty sets the "qty" field. +func (u *InspectionDisposalItemUpsertBulk) SetQty(v int) *InspectionDisposalItemUpsertBulk { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.SetQty(v) + }) +} + +// AddQty adds v to the "qty" field. +func (u *InspectionDisposalItemUpsertBulk) AddQty(v int) *InspectionDisposalItemUpsertBulk { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.AddQty(v) + }) +} + +// UpdateQty sets the "qty" field to the value that was provided on create. +func (u *InspectionDisposalItemUpsertBulk) UpdateQty() *InspectionDisposalItemUpsertBulk { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.UpdateQty() + }) +} + +// SetRemark sets the "remark" field. +func (u *InspectionDisposalItemUpsertBulk) SetRemark(v string) *InspectionDisposalItemUpsertBulk { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.SetRemark(v) + }) +} + +// UpdateRemark sets the "remark" field to the value that was provided on create. +func (u *InspectionDisposalItemUpsertBulk) UpdateRemark() *InspectionDisposalItemUpsertBulk { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.UpdateRemark() + }) +} + +// ClearRemark clears the value of the "remark" field. +func (u *InspectionDisposalItemUpsertBulk) ClearRemark() *InspectionDisposalItemUpsertBulk { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.ClearRemark() + }) +} + +// SetOperator sets the "operator" field. +func (u *InspectionDisposalItemUpsertBulk) SetOperator(v string) *InspectionDisposalItemUpsertBulk { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.SetOperator(v) + }) +} + +// UpdateOperator sets the "operator" field to the value that was provided on create. +func (u *InspectionDisposalItemUpsertBulk) UpdateOperator() *InspectionDisposalItemUpsertBulk { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.UpdateOperator() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *InspectionDisposalItemUpsertBulk) SetCreatedAt(v int64) *InspectionDisposalItemUpsertBulk { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.SetCreatedAt(v) + }) +} + +// AddCreatedAt adds v to the "created_at" field. +func (u *InspectionDisposalItemUpsertBulk) AddCreatedAt(v int64) *InspectionDisposalItemUpsertBulk { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.AddCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *InspectionDisposalItemUpsertBulk) UpdateCreatedAt() *InspectionDisposalItemUpsertBulk { + return u.Update(func(s *InspectionDisposalItemUpsert) { + s.UpdateCreatedAt() + }) +} + +// Exec executes the query. +func (u *InspectionDisposalItemUpsertBulk) 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 InspectionDisposalItemCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for InspectionDisposalItemCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *InspectionDisposalItemUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_wms/ent/inspectiondisposalitem_delete.go b/bj_power_wms/ent/inspectiondisposalitem_delete.go new file mode 100644 index 0000000..2318f35 --- /dev/null +++ b/bj_power_wms/ent/inspectiondisposalitem_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_wms/ent/inspectiondisposalitem" + "bj_power_wms/ent/predicate" + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// InspectionDisposalItemDelete is the builder for deleting a InspectionDisposalItem entity. +type InspectionDisposalItemDelete struct { + config + hooks []Hook + mutation *InspectionDisposalItemMutation +} + +// Where appends a list predicates to the InspectionDisposalItemDelete builder. +func (_d *InspectionDisposalItemDelete) Where(ps ...predicate.InspectionDisposalItem) *InspectionDisposalItemDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *InspectionDisposalItemDelete) 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 *InspectionDisposalItemDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *InspectionDisposalItemDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(inspectiondisposalitem.Table, sqlgraph.NewFieldSpec(inspectiondisposalitem.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 +} + +// InspectionDisposalItemDeleteOne is the builder for deleting a single InspectionDisposalItem entity. +type InspectionDisposalItemDeleteOne struct { + _d *InspectionDisposalItemDelete +} + +// Where appends a list predicates to the InspectionDisposalItemDelete builder. +func (_d *InspectionDisposalItemDeleteOne) Where(ps ...predicate.InspectionDisposalItem) *InspectionDisposalItemDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *InspectionDisposalItemDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{inspectiondisposalitem.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *InspectionDisposalItemDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_wms/ent/inspectiondisposalitem_query.go b/bj_power_wms/ent/inspectiondisposalitem_query.go new file mode 100644 index 0000000..6955748 --- /dev/null +++ b/bj_power_wms/ent/inspectiondisposalitem_query.go @@ -0,0 +1,527 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_wms/ent/inspectiondisposalitem" + "bj_power_wms/ent/predicate" + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// InspectionDisposalItemQuery is the builder for querying InspectionDisposalItem entities. +type InspectionDisposalItemQuery struct { + config + ctx *QueryContext + order []inspectiondisposalitem.OrderOption + inters []Interceptor + predicates []predicate.InspectionDisposalItem + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the InspectionDisposalItemQuery builder. +func (_q *InspectionDisposalItemQuery) Where(ps ...predicate.InspectionDisposalItem) *InspectionDisposalItemQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *InspectionDisposalItemQuery) Limit(limit int) *InspectionDisposalItemQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *InspectionDisposalItemQuery) Offset(offset int) *InspectionDisposalItemQuery { + _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 *InspectionDisposalItemQuery) Unique(unique bool) *InspectionDisposalItemQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *InspectionDisposalItemQuery) Order(o ...inspectiondisposalitem.OrderOption) *InspectionDisposalItemQuery { + _q.order = append(_q.order, o...) + return _q +} + +// First returns the first InspectionDisposalItem entity from the query. +// Returns a *NotFoundError when no InspectionDisposalItem was found. +func (_q *InspectionDisposalItemQuery) First(ctx context.Context) (*InspectionDisposalItem, 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{inspectiondisposalitem.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *InspectionDisposalItemQuery) FirstX(ctx context.Context) *InspectionDisposalItem { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first InspectionDisposalItem ID from the query. +// Returns a *NotFoundError when no InspectionDisposalItem ID was found. +func (_q *InspectionDisposalItemQuery) 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{inspectiondisposalitem.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *InspectionDisposalItemQuery) FirstIDX(ctx context.Context) int { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single InspectionDisposalItem entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one InspectionDisposalItem entity is found. +// Returns a *NotFoundError when no InspectionDisposalItem entities are found. +func (_q *InspectionDisposalItemQuery) Only(ctx context.Context) (*InspectionDisposalItem, 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{inspectiondisposalitem.Label} + default: + return nil, &NotSingularError{inspectiondisposalitem.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *InspectionDisposalItemQuery) OnlyX(ctx context.Context) *InspectionDisposalItem { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only InspectionDisposalItem ID in the query. +// Returns a *NotSingularError when more than one InspectionDisposalItem ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *InspectionDisposalItemQuery) 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{inspectiondisposalitem.Label} + default: + err = &NotSingularError{inspectiondisposalitem.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *InspectionDisposalItemQuery) 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 InspectionDisposalItems. +func (_q *InspectionDisposalItemQuery) All(ctx context.Context) ([]*InspectionDisposalItem, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*InspectionDisposalItem, *InspectionDisposalItemQuery]() + return withInterceptors[[]*InspectionDisposalItem](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *InspectionDisposalItemQuery) AllX(ctx context.Context) []*InspectionDisposalItem { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of InspectionDisposalItem IDs. +func (_q *InspectionDisposalItemQuery) 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(inspectiondisposalitem.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *InspectionDisposalItemQuery) 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 *InspectionDisposalItemQuery) 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[*InspectionDisposalItemQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *InspectionDisposalItemQuery) 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 *InspectionDisposalItemQuery) 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 *InspectionDisposalItemQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the InspectionDisposalItemQuery 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 *InspectionDisposalItemQuery) Clone() *InspectionDisposalItemQuery { + if _q == nil { + return nil + } + return &InspectionDisposalItemQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]inspectiondisposalitem.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.InspectionDisposalItem{}, _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 { +// RecordID int64 `json:"recordId,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.InspectionDisposalItem.Query(). +// GroupBy(inspectiondisposalitem.FieldRecordID). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *InspectionDisposalItemQuery) GroupBy(field string, fields ...string) *InspectionDisposalItemGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &InspectionDisposalItemGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = inspectiondisposalitem.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 { +// RecordID int64 `json:"recordId,omitempty"` +// } +// +// client.InspectionDisposalItem.Query(). +// Select(inspectiondisposalitem.FieldRecordID). +// Scan(ctx, &v) +func (_q *InspectionDisposalItemQuery) Select(fields ...string) *InspectionDisposalItemSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &InspectionDisposalItemSelect{InspectionDisposalItemQuery: _q} + sbuild.label = inspectiondisposalitem.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a InspectionDisposalItemSelect configured with the given aggregations. +func (_q *InspectionDisposalItemQuery) Aggregate(fns ...AggregateFunc) *InspectionDisposalItemSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *InspectionDisposalItemQuery) 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 !inspectiondisposalitem.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 *InspectionDisposalItemQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*InspectionDisposalItem, error) { + var ( + nodes = []*InspectionDisposalItem{} + _spec = _q.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*InspectionDisposalItem).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &InspectionDisposalItem{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 *InspectionDisposalItemQuery) 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 *InspectionDisposalItemQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(inspectiondisposalitem.Table, inspectiondisposalitem.Columns, sqlgraph.NewFieldSpec(inspectiondisposalitem.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, inspectiondisposalitem.FieldID) + for i := range fields { + if fields[i] != inspectiondisposalitem.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 *InspectionDisposalItemQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(inspectiondisposalitem.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = inspectiondisposalitem.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 +} + +// InspectionDisposalItemGroupBy is the group-by builder for InspectionDisposalItem entities. +type InspectionDisposalItemGroupBy struct { + selector + build *InspectionDisposalItemQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *InspectionDisposalItemGroupBy) Aggregate(fns ...AggregateFunc) *InspectionDisposalItemGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *InspectionDisposalItemGroupBy) 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[*InspectionDisposalItemQuery, *InspectionDisposalItemGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *InspectionDisposalItemGroupBy) sqlScan(ctx context.Context, root *InspectionDisposalItemQuery, 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) +} + +// InspectionDisposalItemSelect is the builder for selecting fields of InspectionDisposalItem entities. +type InspectionDisposalItemSelect struct { + *InspectionDisposalItemQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *InspectionDisposalItemSelect) Aggregate(fns ...AggregateFunc) *InspectionDisposalItemSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *InspectionDisposalItemSelect) 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[*InspectionDisposalItemQuery, *InspectionDisposalItemSelect](ctx, _s.InspectionDisposalItemQuery, _s, _s.inters, v) +} + +func (_s *InspectionDisposalItemSelect) sqlScan(ctx context.Context, root *InspectionDisposalItemQuery, 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/inspectiondisposalitem_update.go b/bj_power_wms/ent/inspectiondisposalitem_update.go new file mode 100644 index 0000000..8b46c20 --- /dev/null +++ b/bj_power_wms/ent/inspectiondisposalitem_update.go @@ -0,0 +1,483 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_wms/ent/inspectiondisposalitem" + "bj_power_wms/ent/predicate" + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// InspectionDisposalItemUpdate is the builder for updating InspectionDisposalItem entities. +type InspectionDisposalItemUpdate struct { + config + hooks []Hook + mutation *InspectionDisposalItemMutation +} + +// Where appends a list predicates to the InspectionDisposalItemUpdate builder. +func (_u *InspectionDisposalItemUpdate) Where(ps ...predicate.InspectionDisposalItem) *InspectionDisposalItemUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetRecordID sets the "record_id" field. +func (_u *InspectionDisposalItemUpdate) SetRecordID(v int64) *InspectionDisposalItemUpdate { + _u.mutation.ResetRecordID() + _u.mutation.SetRecordID(v) + return _u +} + +// SetNillableRecordID sets the "record_id" field if the given value is not nil. +func (_u *InspectionDisposalItemUpdate) SetNillableRecordID(v *int64) *InspectionDisposalItemUpdate { + if v != nil { + _u.SetRecordID(*v) + } + return _u +} + +// AddRecordID adds value to the "record_id" field. +func (_u *InspectionDisposalItemUpdate) AddRecordID(v int64) *InspectionDisposalItemUpdate { + _u.mutation.AddRecordID(v) + return _u +} + +// SetDisposeType sets the "dispose_type" field. +func (_u *InspectionDisposalItemUpdate) SetDisposeType(v string) *InspectionDisposalItemUpdate { + _u.mutation.SetDisposeType(v) + return _u +} + +// SetNillableDisposeType sets the "dispose_type" field if the given value is not nil. +func (_u *InspectionDisposalItemUpdate) SetNillableDisposeType(v *string) *InspectionDisposalItemUpdate { + if v != nil { + _u.SetDisposeType(*v) + } + return _u +} + +// SetQty sets the "qty" field. +func (_u *InspectionDisposalItemUpdate) SetQty(v int) *InspectionDisposalItemUpdate { + _u.mutation.ResetQty() + _u.mutation.SetQty(v) + return _u +} + +// SetNillableQty sets the "qty" field if the given value is not nil. +func (_u *InspectionDisposalItemUpdate) SetNillableQty(v *int) *InspectionDisposalItemUpdate { + if v != nil { + _u.SetQty(*v) + } + return _u +} + +// AddQty adds value to the "qty" field. +func (_u *InspectionDisposalItemUpdate) AddQty(v int) *InspectionDisposalItemUpdate { + _u.mutation.AddQty(v) + return _u +} + +// SetRemark sets the "remark" field. +func (_u *InspectionDisposalItemUpdate) SetRemark(v string) *InspectionDisposalItemUpdate { + _u.mutation.SetRemark(v) + return _u +} + +// SetNillableRemark sets the "remark" field if the given value is not nil. +func (_u *InspectionDisposalItemUpdate) SetNillableRemark(v *string) *InspectionDisposalItemUpdate { + if v != nil { + _u.SetRemark(*v) + } + return _u +} + +// ClearRemark clears the value of the "remark" field. +func (_u *InspectionDisposalItemUpdate) ClearRemark() *InspectionDisposalItemUpdate { + _u.mutation.ClearRemark() + return _u +} + +// SetOperator sets the "operator" field. +func (_u *InspectionDisposalItemUpdate) SetOperator(v string) *InspectionDisposalItemUpdate { + _u.mutation.SetOperator(v) + return _u +} + +// SetNillableOperator sets the "operator" field if the given value is not nil. +func (_u *InspectionDisposalItemUpdate) SetNillableOperator(v *string) *InspectionDisposalItemUpdate { + if v != nil { + _u.SetOperator(*v) + } + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *InspectionDisposalItemUpdate) SetCreatedAt(v int64) *InspectionDisposalItemUpdate { + _u.mutation.ResetCreatedAt() + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *InspectionDisposalItemUpdate) SetNillableCreatedAt(v *int64) *InspectionDisposalItemUpdate { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// AddCreatedAt adds value to the "created_at" field. +func (_u *InspectionDisposalItemUpdate) AddCreatedAt(v int64) *InspectionDisposalItemUpdate { + _u.mutation.AddCreatedAt(v) + return _u +} + +// Mutation returns the InspectionDisposalItemMutation object of the builder. +func (_u *InspectionDisposalItemUpdate) Mutation() *InspectionDisposalItemMutation { + return _u.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *InspectionDisposalItemUpdate) 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 *InspectionDisposalItemUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *InspectionDisposalItemUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *InspectionDisposalItemUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *InspectionDisposalItemUpdate) check() error { + if v, ok := _u.mutation.Qty(); ok { + if err := inspectiondisposalitem.QtyValidator(v); err != nil { + return &ValidationError{Name: "qty", err: fmt.Errorf(`ent: validator failed for field "InspectionDisposalItem.qty": %w`, err)} + } + } + return nil +} + +func (_u *InspectionDisposalItemUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(inspectiondisposalitem.Table, inspectiondisposalitem.Columns, sqlgraph.NewFieldSpec(inspectiondisposalitem.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.RecordID(); ok { + _spec.SetField(inspectiondisposalitem.FieldRecordID, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedRecordID(); ok { + _spec.AddField(inspectiondisposalitem.FieldRecordID, field.TypeInt64, value) + } + if value, ok := _u.mutation.DisposeType(); ok { + _spec.SetField(inspectiondisposalitem.FieldDisposeType, field.TypeString, value) + } + if value, ok := _u.mutation.Qty(); ok { + _spec.SetField(inspectiondisposalitem.FieldQty, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedQty(); ok { + _spec.AddField(inspectiondisposalitem.FieldQty, field.TypeInt, value) + } + if value, ok := _u.mutation.Remark(); ok { + _spec.SetField(inspectiondisposalitem.FieldRemark, field.TypeString, value) + } + if _u.mutation.RemarkCleared() { + _spec.ClearField(inspectiondisposalitem.FieldRemark, field.TypeString) + } + if value, ok := _u.mutation.Operator(); ok { + _spec.SetField(inspectiondisposalitem.FieldOperator, field.TypeString, value) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(inspectiondisposalitem.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedCreatedAt(); ok { + _spec.AddField(inspectiondisposalitem.FieldCreatedAt, field.TypeInt64, value) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{inspectiondisposalitem.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// InspectionDisposalItemUpdateOne is the builder for updating a single InspectionDisposalItem entity. +type InspectionDisposalItemUpdateOne struct { + config + fields []string + hooks []Hook + mutation *InspectionDisposalItemMutation +} + +// SetRecordID sets the "record_id" field. +func (_u *InspectionDisposalItemUpdateOne) SetRecordID(v int64) *InspectionDisposalItemUpdateOne { + _u.mutation.ResetRecordID() + _u.mutation.SetRecordID(v) + return _u +} + +// SetNillableRecordID sets the "record_id" field if the given value is not nil. +func (_u *InspectionDisposalItemUpdateOne) SetNillableRecordID(v *int64) *InspectionDisposalItemUpdateOne { + if v != nil { + _u.SetRecordID(*v) + } + return _u +} + +// AddRecordID adds value to the "record_id" field. +func (_u *InspectionDisposalItemUpdateOne) AddRecordID(v int64) *InspectionDisposalItemUpdateOne { + _u.mutation.AddRecordID(v) + return _u +} + +// SetDisposeType sets the "dispose_type" field. +func (_u *InspectionDisposalItemUpdateOne) SetDisposeType(v string) *InspectionDisposalItemUpdateOne { + _u.mutation.SetDisposeType(v) + return _u +} + +// SetNillableDisposeType sets the "dispose_type" field if the given value is not nil. +func (_u *InspectionDisposalItemUpdateOne) SetNillableDisposeType(v *string) *InspectionDisposalItemUpdateOne { + if v != nil { + _u.SetDisposeType(*v) + } + return _u +} + +// SetQty sets the "qty" field. +func (_u *InspectionDisposalItemUpdateOne) SetQty(v int) *InspectionDisposalItemUpdateOne { + _u.mutation.ResetQty() + _u.mutation.SetQty(v) + return _u +} + +// SetNillableQty sets the "qty" field if the given value is not nil. +func (_u *InspectionDisposalItemUpdateOne) SetNillableQty(v *int) *InspectionDisposalItemUpdateOne { + if v != nil { + _u.SetQty(*v) + } + return _u +} + +// AddQty adds value to the "qty" field. +func (_u *InspectionDisposalItemUpdateOne) AddQty(v int) *InspectionDisposalItemUpdateOne { + _u.mutation.AddQty(v) + return _u +} + +// SetRemark sets the "remark" field. +func (_u *InspectionDisposalItemUpdateOne) SetRemark(v string) *InspectionDisposalItemUpdateOne { + _u.mutation.SetRemark(v) + return _u +} + +// SetNillableRemark sets the "remark" field if the given value is not nil. +func (_u *InspectionDisposalItemUpdateOne) SetNillableRemark(v *string) *InspectionDisposalItemUpdateOne { + if v != nil { + _u.SetRemark(*v) + } + return _u +} + +// ClearRemark clears the value of the "remark" field. +func (_u *InspectionDisposalItemUpdateOne) ClearRemark() *InspectionDisposalItemUpdateOne { + _u.mutation.ClearRemark() + return _u +} + +// SetOperator sets the "operator" field. +func (_u *InspectionDisposalItemUpdateOne) SetOperator(v string) *InspectionDisposalItemUpdateOne { + _u.mutation.SetOperator(v) + return _u +} + +// SetNillableOperator sets the "operator" field if the given value is not nil. +func (_u *InspectionDisposalItemUpdateOne) SetNillableOperator(v *string) *InspectionDisposalItemUpdateOne { + if v != nil { + _u.SetOperator(*v) + } + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *InspectionDisposalItemUpdateOne) SetCreatedAt(v int64) *InspectionDisposalItemUpdateOne { + _u.mutation.ResetCreatedAt() + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *InspectionDisposalItemUpdateOne) SetNillableCreatedAt(v *int64) *InspectionDisposalItemUpdateOne { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// AddCreatedAt adds value to the "created_at" field. +func (_u *InspectionDisposalItemUpdateOne) AddCreatedAt(v int64) *InspectionDisposalItemUpdateOne { + _u.mutation.AddCreatedAt(v) + return _u +} + +// Mutation returns the InspectionDisposalItemMutation object of the builder. +func (_u *InspectionDisposalItemUpdateOne) Mutation() *InspectionDisposalItemMutation { + return _u.mutation +} + +// Where appends a list predicates to the InspectionDisposalItemUpdate builder. +func (_u *InspectionDisposalItemUpdateOne) Where(ps ...predicate.InspectionDisposalItem) *InspectionDisposalItemUpdateOne { + _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 *InspectionDisposalItemUpdateOne) Select(field string, fields ...string) *InspectionDisposalItemUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated InspectionDisposalItem entity. +func (_u *InspectionDisposalItemUpdateOne) Save(ctx context.Context) (*InspectionDisposalItem, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *InspectionDisposalItemUpdateOne) SaveX(ctx context.Context) *InspectionDisposalItem { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *InspectionDisposalItemUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *InspectionDisposalItemUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *InspectionDisposalItemUpdateOne) check() error { + if v, ok := _u.mutation.Qty(); ok { + if err := inspectiondisposalitem.QtyValidator(v); err != nil { + return &ValidationError{Name: "qty", err: fmt.Errorf(`ent: validator failed for field "InspectionDisposalItem.qty": %w`, err)} + } + } + return nil +} + +func (_u *InspectionDisposalItemUpdateOne) sqlSave(ctx context.Context) (_node *InspectionDisposalItem, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(inspectiondisposalitem.Table, inspectiondisposalitem.Columns, sqlgraph.NewFieldSpec(inspectiondisposalitem.FieldID, field.TypeInt)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "InspectionDisposalItem.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, inspectiondisposalitem.FieldID) + for _, f := range fields { + if !inspectiondisposalitem.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != inspectiondisposalitem.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.RecordID(); ok { + _spec.SetField(inspectiondisposalitem.FieldRecordID, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedRecordID(); ok { + _spec.AddField(inspectiondisposalitem.FieldRecordID, field.TypeInt64, value) + } + if value, ok := _u.mutation.DisposeType(); ok { + _spec.SetField(inspectiondisposalitem.FieldDisposeType, field.TypeString, value) + } + if value, ok := _u.mutation.Qty(); ok { + _spec.SetField(inspectiondisposalitem.FieldQty, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedQty(); ok { + _spec.AddField(inspectiondisposalitem.FieldQty, field.TypeInt, value) + } + if value, ok := _u.mutation.Remark(); ok { + _spec.SetField(inspectiondisposalitem.FieldRemark, field.TypeString, value) + } + if _u.mutation.RemarkCleared() { + _spec.ClearField(inspectiondisposalitem.FieldRemark, field.TypeString) + } + if value, ok := _u.mutation.Operator(); ok { + _spec.SetField(inspectiondisposalitem.FieldOperator, field.TypeString, value) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(inspectiondisposalitem.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedCreatedAt(); ok { + _spec.AddField(inspectiondisposalitem.FieldCreatedAt, field.TypeInt64, value) + } + _node = &InspectionDisposalItem{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{inspectiondisposalitem.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/inspectionrecord.go b/bj_power_wms/ent/inspectionrecord.go index 22aa10c..2a67aeb 100644 --- a/bj_power_wms/ent/inspectionrecord.go +++ b/bj_power_wms/ent/inspectionrecord.go @@ -60,16 +60,10 @@ type InspectionRecord struct { ReportNo string `json:"reportNo,omitempty"` // 检验结论 合格/不合格/待检/挑选(与处置方式正交) InspectionConclusion string `json:"inspectionConclusion,omitempty"` - // 不合格品处置状态 待处置/退货中/已退货/返修中/已返修/已报废/已处置 + // 不合格品处置状态 待处置/已处置 DisposalStatus string `json:"disposalStatus,omitempty"` // 拆行来源检验记录ID(不合格隔离行回挂原单) ParentRecordID int64 `json:"parentRecordId,omitempty"` - // 不合格部分处置 NONE/RETURN/SCRAP/PARTIAL/REWORK - DisposalType string `json:"disposalType,omitempty"` - // 处置说明(报废/退货原因) - DisposalRemark string `json:"disposalRemark,omitempty"` - // 退货货运单号 - ReturnTrackingNo string `json:"returnTrackingNo,omitempty"` // 备注 Remark string `json:"remark,omitempty"` // CreatedAt holds the value of the "created_at" field. @@ -86,7 +80,7 @@ func (*InspectionRecord) scanValues(columns []string) ([]any, error) { switch columns[i] { case inspectionrecord.FieldID, inspectionrecord.FieldInspectQty, inspectionrecord.FieldPassQty, inspectionrecord.FieldBatchSeq, inspectionrecord.FieldBatchTotal, inspectionrecord.FieldRejectQty, inspectionrecord.FieldParentRecordID, inspectionrecord.FieldCreatedAt, inspectionrecord.FieldUpdatedAt: values[i] = new(sql.NullInt64) - case inspectionrecord.FieldTargetType, inspectionrecord.FieldTargetID, inspectionrecord.FieldMaterialCode, inspectionrecord.FieldMaterialName, inspectionrecord.FieldOwnershipType, inspectionrecord.FieldOwnershipNo, inspectionrecord.FieldProductWorkNo, inspectionrecord.FieldRelatedStandard, inspectionrecord.FieldManufacturer, inspectionrecord.FieldInspectionType, inspectionrecord.FieldStatus, inspectionrecord.FieldResultValue, inspectionrecord.FieldCheckDesc, inspectionrecord.FieldInspector, inspectionrecord.FieldInspectionNo, inspectionrecord.FieldReportNo, inspectionrecord.FieldInspectionConclusion, inspectionrecord.FieldDisposalStatus, inspectionrecord.FieldDisposalType, inspectionrecord.FieldDisposalRemark, inspectionrecord.FieldReturnTrackingNo, inspectionrecord.FieldRemark: + case inspectionrecord.FieldTargetType, inspectionrecord.FieldTargetID, inspectionrecord.FieldMaterialCode, inspectionrecord.FieldMaterialName, inspectionrecord.FieldOwnershipType, inspectionrecord.FieldOwnershipNo, inspectionrecord.FieldProductWorkNo, inspectionrecord.FieldRelatedStandard, inspectionrecord.FieldManufacturer, inspectionrecord.FieldInspectionType, inspectionrecord.FieldStatus, inspectionrecord.FieldResultValue, inspectionrecord.FieldCheckDesc, inspectionrecord.FieldInspector, inspectionrecord.FieldInspectionNo, inspectionrecord.FieldReportNo, inspectionrecord.FieldInspectionConclusion, inspectionrecord.FieldDisposalStatus, inspectionrecord.FieldRemark: values[i] = new(sql.NullString) default: values[i] = new(sql.UnknownType) @@ -253,24 +247,6 @@ func (_m *InspectionRecord) assignValues(columns []string, values []any) error { } else if value.Valid { _m.ParentRecordID = value.Int64 } - case inspectionrecord.FieldDisposalType: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field disposal_type", values[i]) - } else if value.Valid { - _m.DisposalType = value.String - } - case inspectionrecord.FieldDisposalRemark: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field disposal_remark", values[i]) - } else if value.Valid { - _m.DisposalRemark = value.String - } - case inspectionrecord.FieldReturnTrackingNo: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field return_tracking_no", values[i]) - } else if value.Valid { - _m.ReturnTrackingNo = value.String - } case inspectionrecord.FieldRemark: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field remark", values[i]) @@ -397,15 +373,6 @@ func (_m *InspectionRecord) String() string { builder.WriteString("parent_record_id=") builder.WriteString(fmt.Sprintf("%v", _m.ParentRecordID)) builder.WriteString(", ") - builder.WriteString("disposal_type=") - builder.WriteString(_m.DisposalType) - builder.WriteString(", ") - builder.WriteString("disposal_remark=") - builder.WriteString(_m.DisposalRemark) - builder.WriteString(", ") - builder.WriteString("return_tracking_no=") - builder.WriteString(_m.ReturnTrackingNo) - builder.WriteString(", ") builder.WriteString("remark=") builder.WriteString(_m.Remark) builder.WriteString(", ") diff --git a/bj_power_wms/ent/inspectionrecord/inspectionrecord.go b/bj_power_wms/ent/inspectionrecord/inspectionrecord.go index 0b387fd..e9a6e59 100644 --- a/bj_power_wms/ent/inspectionrecord/inspectionrecord.go +++ b/bj_power_wms/ent/inspectionrecord/inspectionrecord.go @@ -59,12 +59,6 @@ const ( FieldDisposalStatus = "disposal_status" // FieldParentRecordID holds the string denoting the parent_record_id field in the database. FieldParentRecordID = "parent_record_id" - // FieldDisposalType holds the string denoting the disposal_type field in the database. - FieldDisposalType = "disposal_type" - // FieldDisposalRemark holds the string denoting the disposal_remark field in the database. - FieldDisposalRemark = "disposal_remark" - // FieldReturnTrackingNo holds the string denoting the return_tracking_no field in the database. - FieldReturnTrackingNo = "return_tracking_no" // FieldRemark holds the string denoting the remark field in the database. FieldRemark = "remark" // FieldCreatedAt holds the string denoting the created_at field in the database. @@ -102,9 +96,6 @@ var Columns = []string{ FieldInspectionConclusion, FieldDisposalStatus, FieldParentRecordID, - FieldDisposalType, - FieldDisposalRemark, - FieldReturnTrackingNo, FieldRemark, FieldCreatedAt, FieldUpdatedAt, @@ -141,8 +132,6 @@ var ( DefaultDisposalStatus string // DefaultParentRecordID holds the default value on creation for the "parent_record_id" field. DefaultParentRecordID int64 - // DefaultDisposalType holds the default value on creation for the "disposal_type" field. - DefaultDisposalType string // DefaultCreatedAt holds the default value on creation for the "created_at" field. DefaultCreatedAt func() int64 // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. @@ -277,21 +266,6 @@ func ByParentRecordID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldParentRecordID, opts...).ToFunc() } -// ByDisposalType orders the results by the disposal_type field. -func ByDisposalType(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldDisposalType, opts...).ToFunc() -} - -// ByDisposalRemark orders the results by the disposal_remark field. -func ByDisposalRemark(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldDisposalRemark, opts...).ToFunc() -} - -// ByReturnTrackingNo orders the results by the return_tracking_no field. -func ByReturnTrackingNo(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldReturnTrackingNo, opts...).ToFunc() -} - // ByRemark orders the results by the remark field. func ByRemark(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldRemark, opts...).ToFunc() diff --git a/bj_power_wms/ent/inspectionrecord/where.go b/bj_power_wms/ent/inspectionrecord/where.go index e8b0d36..392f69e 100644 --- a/bj_power_wms/ent/inspectionrecord/where.go +++ b/bj_power_wms/ent/inspectionrecord/where.go @@ -173,21 +173,6 @@ func ParentRecordID(v int64) predicate.InspectionRecord { return predicate.InspectionRecord(sql.FieldEQ(FieldParentRecordID, v)) } -// DisposalType applies equality check predicate on the "disposal_type" field. It's identical to DisposalTypeEQ. -func DisposalType(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldEQ(FieldDisposalType, v)) -} - -// DisposalRemark applies equality check predicate on the "disposal_remark" field. It's identical to DisposalRemarkEQ. -func DisposalRemark(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldEQ(FieldDisposalRemark, v)) -} - -// ReturnTrackingNo applies equality check predicate on the "return_tracking_no" field. It's identical to ReturnTrackingNoEQ. -func ReturnTrackingNo(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldEQ(FieldReturnTrackingNo, v)) -} - // Remark applies equality check predicate on the "remark" field. It's identical to RemarkEQ. func Remark(v string) predicate.InspectionRecord { return predicate.InspectionRecord(sql.FieldEQ(FieldRemark, v)) @@ -1723,221 +1708,6 @@ func ParentRecordIDLTE(v int64) predicate.InspectionRecord { return predicate.InspectionRecord(sql.FieldLTE(FieldParentRecordID, v)) } -// DisposalTypeEQ applies the EQ predicate on the "disposal_type" field. -func DisposalTypeEQ(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldEQ(FieldDisposalType, v)) -} - -// DisposalTypeNEQ applies the NEQ predicate on the "disposal_type" field. -func DisposalTypeNEQ(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldNEQ(FieldDisposalType, v)) -} - -// DisposalTypeIn applies the In predicate on the "disposal_type" field. -func DisposalTypeIn(vs ...string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldIn(FieldDisposalType, vs...)) -} - -// DisposalTypeNotIn applies the NotIn predicate on the "disposal_type" field. -func DisposalTypeNotIn(vs ...string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldNotIn(FieldDisposalType, vs...)) -} - -// DisposalTypeGT applies the GT predicate on the "disposal_type" field. -func DisposalTypeGT(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldGT(FieldDisposalType, v)) -} - -// DisposalTypeGTE applies the GTE predicate on the "disposal_type" field. -func DisposalTypeGTE(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldGTE(FieldDisposalType, v)) -} - -// DisposalTypeLT applies the LT predicate on the "disposal_type" field. -func DisposalTypeLT(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldLT(FieldDisposalType, v)) -} - -// DisposalTypeLTE applies the LTE predicate on the "disposal_type" field. -func DisposalTypeLTE(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldLTE(FieldDisposalType, v)) -} - -// DisposalTypeContains applies the Contains predicate on the "disposal_type" field. -func DisposalTypeContains(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldContains(FieldDisposalType, v)) -} - -// DisposalTypeHasPrefix applies the HasPrefix predicate on the "disposal_type" field. -func DisposalTypeHasPrefix(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldHasPrefix(FieldDisposalType, v)) -} - -// DisposalTypeHasSuffix applies the HasSuffix predicate on the "disposal_type" field. -func DisposalTypeHasSuffix(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldHasSuffix(FieldDisposalType, v)) -} - -// DisposalTypeEqualFold applies the EqualFold predicate on the "disposal_type" field. -func DisposalTypeEqualFold(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldEqualFold(FieldDisposalType, v)) -} - -// DisposalTypeContainsFold applies the ContainsFold predicate on the "disposal_type" field. -func DisposalTypeContainsFold(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldContainsFold(FieldDisposalType, v)) -} - -// DisposalRemarkEQ applies the EQ predicate on the "disposal_remark" field. -func DisposalRemarkEQ(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldEQ(FieldDisposalRemark, v)) -} - -// DisposalRemarkNEQ applies the NEQ predicate on the "disposal_remark" field. -func DisposalRemarkNEQ(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldNEQ(FieldDisposalRemark, v)) -} - -// DisposalRemarkIn applies the In predicate on the "disposal_remark" field. -func DisposalRemarkIn(vs ...string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldIn(FieldDisposalRemark, vs...)) -} - -// DisposalRemarkNotIn applies the NotIn predicate on the "disposal_remark" field. -func DisposalRemarkNotIn(vs ...string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldNotIn(FieldDisposalRemark, vs...)) -} - -// DisposalRemarkGT applies the GT predicate on the "disposal_remark" field. -func DisposalRemarkGT(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldGT(FieldDisposalRemark, v)) -} - -// DisposalRemarkGTE applies the GTE predicate on the "disposal_remark" field. -func DisposalRemarkGTE(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldGTE(FieldDisposalRemark, v)) -} - -// DisposalRemarkLT applies the LT predicate on the "disposal_remark" field. -func DisposalRemarkLT(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldLT(FieldDisposalRemark, v)) -} - -// DisposalRemarkLTE applies the LTE predicate on the "disposal_remark" field. -func DisposalRemarkLTE(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldLTE(FieldDisposalRemark, v)) -} - -// DisposalRemarkContains applies the Contains predicate on the "disposal_remark" field. -func DisposalRemarkContains(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldContains(FieldDisposalRemark, v)) -} - -// DisposalRemarkHasPrefix applies the HasPrefix predicate on the "disposal_remark" field. -func DisposalRemarkHasPrefix(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldHasPrefix(FieldDisposalRemark, v)) -} - -// DisposalRemarkHasSuffix applies the HasSuffix predicate on the "disposal_remark" field. -func DisposalRemarkHasSuffix(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldHasSuffix(FieldDisposalRemark, v)) -} - -// DisposalRemarkIsNil applies the IsNil predicate on the "disposal_remark" field. -func DisposalRemarkIsNil() predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldIsNull(FieldDisposalRemark)) -} - -// DisposalRemarkNotNil applies the NotNil predicate on the "disposal_remark" field. -func DisposalRemarkNotNil() predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldNotNull(FieldDisposalRemark)) -} - -// DisposalRemarkEqualFold applies the EqualFold predicate on the "disposal_remark" field. -func DisposalRemarkEqualFold(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldEqualFold(FieldDisposalRemark, v)) -} - -// DisposalRemarkContainsFold applies the ContainsFold predicate on the "disposal_remark" field. -func DisposalRemarkContainsFold(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldContainsFold(FieldDisposalRemark, v)) -} - -// ReturnTrackingNoEQ applies the EQ predicate on the "return_tracking_no" field. -func ReturnTrackingNoEQ(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldEQ(FieldReturnTrackingNo, v)) -} - -// ReturnTrackingNoNEQ applies the NEQ predicate on the "return_tracking_no" field. -func ReturnTrackingNoNEQ(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldNEQ(FieldReturnTrackingNo, v)) -} - -// ReturnTrackingNoIn applies the In predicate on the "return_tracking_no" field. -func ReturnTrackingNoIn(vs ...string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldIn(FieldReturnTrackingNo, vs...)) -} - -// ReturnTrackingNoNotIn applies the NotIn predicate on the "return_tracking_no" field. -func ReturnTrackingNoNotIn(vs ...string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldNotIn(FieldReturnTrackingNo, vs...)) -} - -// ReturnTrackingNoGT applies the GT predicate on the "return_tracking_no" field. -func ReturnTrackingNoGT(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldGT(FieldReturnTrackingNo, v)) -} - -// ReturnTrackingNoGTE applies the GTE predicate on the "return_tracking_no" field. -func ReturnTrackingNoGTE(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldGTE(FieldReturnTrackingNo, v)) -} - -// ReturnTrackingNoLT applies the LT predicate on the "return_tracking_no" field. -func ReturnTrackingNoLT(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldLT(FieldReturnTrackingNo, v)) -} - -// ReturnTrackingNoLTE applies the LTE predicate on the "return_tracking_no" field. -func ReturnTrackingNoLTE(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldLTE(FieldReturnTrackingNo, v)) -} - -// ReturnTrackingNoContains applies the Contains predicate on the "return_tracking_no" field. -func ReturnTrackingNoContains(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldContains(FieldReturnTrackingNo, v)) -} - -// ReturnTrackingNoHasPrefix applies the HasPrefix predicate on the "return_tracking_no" field. -func ReturnTrackingNoHasPrefix(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldHasPrefix(FieldReturnTrackingNo, v)) -} - -// ReturnTrackingNoHasSuffix applies the HasSuffix predicate on the "return_tracking_no" field. -func ReturnTrackingNoHasSuffix(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldHasSuffix(FieldReturnTrackingNo, v)) -} - -// ReturnTrackingNoIsNil applies the IsNil predicate on the "return_tracking_no" field. -func ReturnTrackingNoIsNil() predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldIsNull(FieldReturnTrackingNo)) -} - -// ReturnTrackingNoNotNil applies the NotNil predicate on the "return_tracking_no" field. -func ReturnTrackingNoNotNil() predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldNotNull(FieldReturnTrackingNo)) -} - -// ReturnTrackingNoEqualFold applies the EqualFold predicate on the "return_tracking_no" field. -func ReturnTrackingNoEqualFold(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldEqualFold(FieldReturnTrackingNo, v)) -} - -// ReturnTrackingNoContainsFold applies the ContainsFold predicate on the "return_tracking_no" field. -func ReturnTrackingNoContainsFold(v string) predicate.InspectionRecord { - return predicate.InspectionRecord(sql.FieldContainsFold(FieldReturnTrackingNo, v)) -} - // RemarkEQ applies the EQ predicate on the "remark" field. func RemarkEQ(v string) predicate.InspectionRecord { return predicate.InspectionRecord(sql.FieldEQ(FieldRemark, v)) diff --git a/bj_power_wms/ent/inspectionrecord_create.go b/bj_power_wms/ent/inspectionrecord_create.go index eba57f0..9859030 100644 --- a/bj_power_wms/ent/inspectionrecord_create.go +++ b/bj_power_wms/ent/inspectionrecord_create.go @@ -333,48 +333,6 @@ func (_c *InspectionRecordCreate) SetNillableParentRecordID(v *int64) *Inspectio return _c } -// SetDisposalType sets the "disposal_type" field. -func (_c *InspectionRecordCreate) SetDisposalType(v string) *InspectionRecordCreate { - _c.mutation.SetDisposalType(v) - return _c -} - -// SetNillableDisposalType sets the "disposal_type" field if the given value is not nil. -func (_c *InspectionRecordCreate) SetNillableDisposalType(v *string) *InspectionRecordCreate { - if v != nil { - _c.SetDisposalType(*v) - } - return _c -} - -// SetDisposalRemark sets the "disposal_remark" field. -func (_c *InspectionRecordCreate) SetDisposalRemark(v string) *InspectionRecordCreate { - _c.mutation.SetDisposalRemark(v) - return _c -} - -// SetNillableDisposalRemark sets the "disposal_remark" field if the given value is not nil. -func (_c *InspectionRecordCreate) SetNillableDisposalRemark(v *string) *InspectionRecordCreate { - if v != nil { - _c.SetDisposalRemark(*v) - } - return _c -} - -// SetReturnTrackingNo sets the "return_tracking_no" field. -func (_c *InspectionRecordCreate) SetReturnTrackingNo(v string) *InspectionRecordCreate { - _c.mutation.SetReturnTrackingNo(v) - return _c -} - -// SetNillableReturnTrackingNo sets the "return_tracking_no" field if the given value is not nil. -func (_c *InspectionRecordCreate) SetNillableReturnTrackingNo(v *string) *InspectionRecordCreate { - if v != nil { - _c.SetReturnTrackingNo(*v) - } - return _c -} - // SetRemark sets the "remark" field. func (_c *InspectionRecordCreate) SetRemark(v string) *InspectionRecordCreate { _c.mutation.SetRemark(v) @@ -492,10 +450,6 @@ func (_c *InspectionRecordCreate) defaults() { v := inspectionrecord.DefaultParentRecordID _c.mutation.SetParentRecordID(v) } - if _, ok := _c.mutation.DisposalType(); !ok { - v := inspectionrecord.DefaultDisposalType - _c.mutation.SetDisposalType(v) - } if _, ok := _c.mutation.CreatedAt(); !ok { v := inspectionrecord.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) @@ -547,9 +501,6 @@ func (_c *InspectionRecordCreate) check() error { if _, ok := _c.mutation.ParentRecordID(); !ok { return &ValidationError{Name: "parent_record_id", err: errors.New(`ent: missing required field "InspectionRecord.parent_record_id"`)} } - if _, ok := _c.mutation.DisposalType(); !ok { - return &ValidationError{Name: "disposal_type", err: errors.New(`ent: missing required field "InspectionRecord.disposal_type"`)} - } if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "InspectionRecord.created_at"`)} } @@ -679,18 +630,6 @@ func (_c *InspectionRecordCreate) createSpec() (*InspectionRecord, *sqlgraph.Cre _spec.SetField(inspectionrecord.FieldParentRecordID, field.TypeInt64, value) _node.ParentRecordID = value } - if value, ok := _c.mutation.DisposalType(); ok { - _spec.SetField(inspectionrecord.FieldDisposalType, field.TypeString, value) - _node.DisposalType = value - } - if value, ok := _c.mutation.DisposalRemark(); ok { - _spec.SetField(inspectionrecord.FieldDisposalRemark, field.TypeString, value) - _node.DisposalRemark = value - } - if value, ok := _c.mutation.ReturnTrackingNo(); ok { - _spec.SetField(inspectionrecord.FieldReturnTrackingNo, field.TypeString, value) - _node.ReturnTrackingNo = value - } if value, ok := _c.mutation.Remark(); ok { _spec.SetField(inspectionrecord.FieldRemark, field.TypeString, value) _node.Remark = value @@ -1145,54 +1084,6 @@ func (u *InspectionRecordUpsert) AddParentRecordID(v int64) *InspectionRecordUps return u } -// SetDisposalType sets the "disposal_type" field. -func (u *InspectionRecordUpsert) SetDisposalType(v string) *InspectionRecordUpsert { - u.Set(inspectionrecord.FieldDisposalType, v) - return u -} - -// UpdateDisposalType sets the "disposal_type" field to the value that was provided on create. -func (u *InspectionRecordUpsert) UpdateDisposalType() *InspectionRecordUpsert { - u.SetExcluded(inspectionrecord.FieldDisposalType) - return u -} - -// SetDisposalRemark sets the "disposal_remark" field. -func (u *InspectionRecordUpsert) SetDisposalRemark(v string) *InspectionRecordUpsert { - u.Set(inspectionrecord.FieldDisposalRemark, v) - return u -} - -// UpdateDisposalRemark sets the "disposal_remark" field to the value that was provided on create. -func (u *InspectionRecordUpsert) UpdateDisposalRemark() *InspectionRecordUpsert { - u.SetExcluded(inspectionrecord.FieldDisposalRemark) - return u -} - -// ClearDisposalRemark clears the value of the "disposal_remark" field. -func (u *InspectionRecordUpsert) ClearDisposalRemark() *InspectionRecordUpsert { - u.SetNull(inspectionrecord.FieldDisposalRemark) - return u -} - -// SetReturnTrackingNo sets the "return_tracking_no" field. -func (u *InspectionRecordUpsert) SetReturnTrackingNo(v string) *InspectionRecordUpsert { - u.Set(inspectionrecord.FieldReturnTrackingNo, v) - return u -} - -// UpdateReturnTrackingNo sets the "return_tracking_no" field to the value that was provided on create. -func (u *InspectionRecordUpsert) UpdateReturnTrackingNo() *InspectionRecordUpsert { - u.SetExcluded(inspectionrecord.FieldReturnTrackingNo) - return u -} - -// ClearReturnTrackingNo clears the value of the "return_tracking_no" field. -func (u *InspectionRecordUpsert) ClearReturnTrackingNo() *InspectionRecordUpsert { - u.SetNull(inspectionrecord.FieldReturnTrackingNo) - return u -} - // SetRemark sets the "remark" field. func (u *InspectionRecordUpsert) SetRemark(v string) *InspectionRecordUpsert { u.Set(inspectionrecord.FieldRemark, v) @@ -1742,62 +1633,6 @@ func (u *InspectionRecordUpsertOne) UpdateParentRecordID() *InspectionRecordUpse }) } -// SetDisposalType sets the "disposal_type" field. -func (u *InspectionRecordUpsertOne) SetDisposalType(v string) *InspectionRecordUpsertOne { - return u.Update(func(s *InspectionRecordUpsert) { - s.SetDisposalType(v) - }) -} - -// UpdateDisposalType sets the "disposal_type" field to the value that was provided on create. -func (u *InspectionRecordUpsertOne) UpdateDisposalType() *InspectionRecordUpsertOne { - return u.Update(func(s *InspectionRecordUpsert) { - s.UpdateDisposalType() - }) -} - -// SetDisposalRemark sets the "disposal_remark" field. -func (u *InspectionRecordUpsertOne) SetDisposalRemark(v string) *InspectionRecordUpsertOne { - return u.Update(func(s *InspectionRecordUpsert) { - s.SetDisposalRemark(v) - }) -} - -// UpdateDisposalRemark sets the "disposal_remark" field to the value that was provided on create. -func (u *InspectionRecordUpsertOne) UpdateDisposalRemark() *InspectionRecordUpsertOne { - return u.Update(func(s *InspectionRecordUpsert) { - s.UpdateDisposalRemark() - }) -} - -// ClearDisposalRemark clears the value of the "disposal_remark" field. -func (u *InspectionRecordUpsertOne) ClearDisposalRemark() *InspectionRecordUpsertOne { - return u.Update(func(s *InspectionRecordUpsert) { - s.ClearDisposalRemark() - }) -} - -// SetReturnTrackingNo sets the "return_tracking_no" field. -func (u *InspectionRecordUpsertOne) SetReturnTrackingNo(v string) *InspectionRecordUpsertOne { - return u.Update(func(s *InspectionRecordUpsert) { - s.SetReturnTrackingNo(v) - }) -} - -// UpdateReturnTrackingNo sets the "return_tracking_no" field to the value that was provided on create. -func (u *InspectionRecordUpsertOne) UpdateReturnTrackingNo() *InspectionRecordUpsertOne { - return u.Update(func(s *InspectionRecordUpsert) { - s.UpdateReturnTrackingNo() - }) -} - -// ClearReturnTrackingNo clears the value of the "return_tracking_no" field. -func (u *InspectionRecordUpsertOne) ClearReturnTrackingNo() *InspectionRecordUpsertOne { - return u.Update(func(s *InspectionRecordUpsert) { - s.ClearReturnTrackingNo() - }) -} - // SetRemark sets the "remark" field. func (u *InspectionRecordUpsertOne) SetRemark(v string) *InspectionRecordUpsertOne { return u.Update(func(s *InspectionRecordUpsert) { @@ -2520,62 +2355,6 @@ func (u *InspectionRecordUpsertBulk) UpdateParentRecordID() *InspectionRecordUps }) } -// SetDisposalType sets the "disposal_type" field. -func (u *InspectionRecordUpsertBulk) SetDisposalType(v string) *InspectionRecordUpsertBulk { - return u.Update(func(s *InspectionRecordUpsert) { - s.SetDisposalType(v) - }) -} - -// UpdateDisposalType sets the "disposal_type" field to the value that was provided on create. -func (u *InspectionRecordUpsertBulk) UpdateDisposalType() *InspectionRecordUpsertBulk { - return u.Update(func(s *InspectionRecordUpsert) { - s.UpdateDisposalType() - }) -} - -// SetDisposalRemark sets the "disposal_remark" field. -func (u *InspectionRecordUpsertBulk) SetDisposalRemark(v string) *InspectionRecordUpsertBulk { - return u.Update(func(s *InspectionRecordUpsert) { - s.SetDisposalRemark(v) - }) -} - -// UpdateDisposalRemark sets the "disposal_remark" field to the value that was provided on create. -func (u *InspectionRecordUpsertBulk) UpdateDisposalRemark() *InspectionRecordUpsertBulk { - return u.Update(func(s *InspectionRecordUpsert) { - s.UpdateDisposalRemark() - }) -} - -// ClearDisposalRemark clears the value of the "disposal_remark" field. -func (u *InspectionRecordUpsertBulk) ClearDisposalRemark() *InspectionRecordUpsertBulk { - return u.Update(func(s *InspectionRecordUpsert) { - s.ClearDisposalRemark() - }) -} - -// SetReturnTrackingNo sets the "return_tracking_no" field. -func (u *InspectionRecordUpsertBulk) SetReturnTrackingNo(v string) *InspectionRecordUpsertBulk { - return u.Update(func(s *InspectionRecordUpsert) { - s.SetReturnTrackingNo(v) - }) -} - -// UpdateReturnTrackingNo sets the "return_tracking_no" field to the value that was provided on create. -func (u *InspectionRecordUpsertBulk) UpdateReturnTrackingNo() *InspectionRecordUpsertBulk { - return u.Update(func(s *InspectionRecordUpsert) { - s.UpdateReturnTrackingNo() - }) -} - -// ClearReturnTrackingNo clears the value of the "return_tracking_no" field. -func (u *InspectionRecordUpsertBulk) ClearReturnTrackingNo() *InspectionRecordUpsertBulk { - return u.Update(func(s *InspectionRecordUpsert) { - s.ClearReturnTrackingNo() - }) -} - // SetRemark sets the "remark" field. func (u *InspectionRecordUpsertBulk) SetRemark(v string) *InspectionRecordUpsertBulk { return u.Update(func(s *InspectionRecordUpsert) { diff --git a/bj_power_wms/ent/inspectionrecord_update.go b/bj_power_wms/ent/inspectionrecord_update.go index 49ef0c2..95145e9 100644 --- a/bj_power_wms/ent/inspectionrecord_update.go +++ b/bj_power_wms/ent/inspectionrecord_update.go @@ -471,60 +471,6 @@ func (_u *InspectionRecordUpdate) AddParentRecordID(v int64) *InspectionRecordUp return _u } -// SetDisposalType sets the "disposal_type" field. -func (_u *InspectionRecordUpdate) SetDisposalType(v string) *InspectionRecordUpdate { - _u.mutation.SetDisposalType(v) - return _u -} - -// SetNillableDisposalType sets the "disposal_type" field if the given value is not nil. -func (_u *InspectionRecordUpdate) SetNillableDisposalType(v *string) *InspectionRecordUpdate { - if v != nil { - _u.SetDisposalType(*v) - } - return _u -} - -// SetDisposalRemark sets the "disposal_remark" field. -func (_u *InspectionRecordUpdate) SetDisposalRemark(v string) *InspectionRecordUpdate { - _u.mutation.SetDisposalRemark(v) - return _u -} - -// SetNillableDisposalRemark sets the "disposal_remark" field if the given value is not nil. -func (_u *InspectionRecordUpdate) SetNillableDisposalRemark(v *string) *InspectionRecordUpdate { - if v != nil { - _u.SetDisposalRemark(*v) - } - return _u -} - -// ClearDisposalRemark clears the value of the "disposal_remark" field. -func (_u *InspectionRecordUpdate) ClearDisposalRemark() *InspectionRecordUpdate { - _u.mutation.ClearDisposalRemark() - return _u -} - -// SetReturnTrackingNo sets the "return_tracking_no" field. -func (_u *InspectionRecordUpdate) SetReturnTrackingNo(v string) *InspectionRecordUpdate { - _u.mutation.SetReturnTrackingNo(v) - return _u -} - -// SetNillableReturnTrackingNo sets the "return_tracking_no" field if the given value is not nil. -func (_u *InspectionRecordUpdate) SetNillableReturnTrackingNo(v *string) *InspectionRecordUpdate { - if v != nil { - _u.SetReturnTrackingNo(*v) - } - return _u -} - -// ClearReturnTrackingNo clears the value of the "return_tracking_no" field. -func (_u *InspectionRecordUpdate) ClearReturnTrackingNo() *InspectionRecordUpdate { - _u.mutation.ClearReturnTrackingNo() - return _u -} - // SetRemark sets the "remark" field. func (_u *InspectionRecordUpdate) SetRemark(v string) *InspectionRecordUpdate { _u.mutation.SetRemark(v) @@ -751,21 +697,6 @@ func (_u *InspectionRecordUpdate) sqlSave(ctx context.Context) (_node int, err e if value, ok := _u.mutation.AddedParentRecordID(); ok { _spec.AddField(inspectionrecord.FieldParentRecordID, field.TypeInt64, value) } - if value, ok := _u.mutation.DisposalType(); ok { - _spec.SetField(inspectionrecord.FieldDisposalType, field.TypeString, value) - } - if value, ok := _u.mutation.DisposalRemark(); ok { - _spec.SetField(inspectionrecord.FieldDisposalRemark, field.TypeString, value) - } - if _u.mutation.DisposalRemarkCleared() { - _spec.ClearField(inspectionrecord.FieldDisposalRemark, field.TypeString) - } - if value, ok := _u.mutation.ReturnTrackingNo(); ok { - _spec.SetField(inspectionrecord.FieldReturnTrackingNo, field.TypeString, value) - } - if _u.mutation.ReturnTrackingNoCleared() { - _spec.ClearField(inspectionrecord.FieldReturnTrackingNo, field.TypeString) - } if value, ok := _u.mutation.Remark(); ok { _spec.SetField(inspectionrecord.FieldRemark, field.TypeString, value) } @@ -1248,60 +1179,6 @@ func (_u *InspectionRecordUpdateOne) AddParentRecordID(v int64) *InspectionRecor return _u } -// SetDisposalType sets the "disposal_type" field. -func (_u *InspectionRecordUpdateOne) SetDisposalType(v string) *InspectionRecordUpdateOne { - _u.mutation.SetDisposalType(v) - return _u -} - -// SetNillableDisposalType sets the "disposal_type" field if the given value is not nil. -func (_u *InspectionRecordUpdateOne) SetNillableDisposalType(v *string) *InspectionRecordUpdateOne { - if v != nil { - _u.SetDisposalType(*v) - } - return _u -} - -// SetDisposalRemark sets the "disposal_remark" field. -func (_u *InspectionRecordUpdateOne) SetDisposalRemark(v string) *InspectionRecordUpdateOne { - _u.mutation.SetDisposalRemark(v) - return _u -} - -// SetNillableDisposalRemark sets the "disposal_remark" field if the given value is not nil. -func (_u *InspectionRecordUpdateOne) SetNillableDisposalRemark(v *string) *InspectionRecordUpdateOne { - if v != nil { - _u.SetDisposalRemark(*v) - } - return _u -} - -// ClearDisposalRemark clears the value of the "disposal_remark" field. -func (_u *InspectionRecordUpdateOne) ClearDisposalRemark() *InspectionRecordUpdateOne { - _u.mutation.ClearDisposalRemark() - return _u -} - -// SetReturnTrackingNo sets the "return_tracking_no" field. -func (_u *InspectionRecordUpdateOne) SetReturnTrackingNo(v string) *InspectionRecordUpdateOne { - _u.mutation.SetReturnTrackingNo(v) - return _u -} - -// SetNillableReturnTrackingNo sets the "return_tracking_no" field if the given value is not nil. -func (_u *InspectionRecordUpdateOne) SetNillableReturnTrackingNo(v *string) *InspectionRecordUpdateOne { - if v != nil { - _u.SetReturnTrackingNo(*v) - } - return _u -} - -// ClearReturnTrackingNo clears the value of the "return_tracking_no" field. -func (_u *InspectionRecordUpdateOne) ClearReturnTrackingNo() *InspectionRecordUpdateOne { - _u.mutation.ClearReturnTrackingNo() - return _u -} - // SetRemark sets the "remark" field. func (_u *InspectionRecordUpdateOne) SetRemark(v string) *InspectionRecordUpdateOne { _u.mutation.SetRemark(v) @@ -1558,21 +1435,6 @@ func (_u *InspectionRecordUpdateOne) sqlSave(ctx context.Context) (_node *Inspec if value, ok := _u.mutation.AddedParentRecordID(); ok { _spec.AddField(inspectionrecord.FieldParentRecordID, field.TypeInt64, value) } - if value, ok := _u.mutation.DisposalType(); ok { - _spec.SetField(inspectionrecord.FieldDisposalType, field.TypeString, value) - } - if value, ok := _u.mutation.DisposalRemark(); ok { - _spec.SetField(inspectionrecord.FieldDisposalRemark, field.TypeString, value) - } - if _u.mutation.DisposalRemarkCleared() { - _spec.ClearField(inspectionrecord.FieldDisposalRemark, field.TypeString) - } - if value, ok := _u.mutation.ReturnTrackingNo(); ok { - _spec.SetField(inspectionrecord.FieldReturnTrackingNo, field.TypeString, value) - } - if _u.mutation.ReturnTrackingNoCleared() { - _spec.ClearField(inspectionrecord.FieldReturnTrackingNo, field.TypeString) - } if value, ok := _u.mutation.Remark(); ok { _spec.SetField(inspectionrecord.FieldRemark, field.TypeString, value) } diff --git a/bj_power_wms/ent/migrate/schema.go b/bj_power_wms/ent/migrate/schema.go index 21c342d..9220bc0 100644 --- a/bj_power_wms/ent/migrate/schema.go +++ b/bj_power_wms/ent/migrate/schema.go @@ -336,6 +336,30 @@ var ( }, }, } + // InspectionDisposalItemsColumns holds the columns for the "inspection_disposal_items" table. + InspectionDisposalItemsColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "record_id", Type: field.TypeInt64, Comment: "父检验记录ID(inspection_records.id)"}, + {Name: "dispose_type", Type: field.TypeString, Comment: "处置方式 RETURN/REWORK/SCRAP"}, + {Name: "qty", Type: field.TypeInt, Comment: "本行处置数量(合计=记录不合格数)"}, + {Name: "remark", Type: field.TypeString, Nullable: true, Comment: "处置备注(非必填;退货物流信息也填此处)"}, + {Name: "operator", Type: field.TypeString, Comment: "操作人", Default: ""}, + {Name: "created_at", Type: field.TypeInt64}, + } + // InspectionDisposalItemsTable holds the schema information for the "inspection_disposal_items" table. + InspectionDisposalItemsTable = &schema.Table{ + Name: "inspection_disposal_items", + Comment: "InspectionDisposalItem 不合格品处置明细(按数量分退货/返修/报废)", + Columns: InspectionDisposalItemsColumns, + PrimaryKey: []*schema.Column{InspectionDisposalItemsColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "inspectiondisposalitem_record_id", + Unique: false, + Columns: []*schema.Column{InspectionDisposalItemsColumns[1]}, + }, + }, + } // InspectionRecordsColumns holds the columns for the "inspection_records" table. InspectionRecordsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, @@ -361,11 +385,8 @@ var ( {Name: "inspection_no", Type: field.TypeString, Nullable: true, Comment: "检测单号(检验报告单号)"}, {Name: "report_no", Type: field.TypeString, Nullable: true, Comment: "报检单号(生产报检关联)"}, {Name: "inspection_conclusion", Type: field.TypeString, Comment: "检验结论 合格/不合格/待检/挑选(与处置方式正交)", Default: ""}, - {Name: "disposal_status", Type: field.TypeString, Comment: "不合格品处置状态 待处置/退货中/已退货/返修中/已返修/已报废/已处置", Default: ""}, + {Name: "disposal_status", Type: field.TypeString, Comment: "不合格品处置状态 待处置/已处置", Default: ""}, {Name: "parent_record_id", Type: field.TypeInt64, Comment: "拆行来源检验记录ID(不合格隔离行回挂原单)", Default: 0}, - {Name: "disposal_type", Type: field.TypeString, Comment: "不合格部分处置 NONE/RETURN/SCRAP/PARTIAL/REWORK", Default: "NONE"}, - {Name: "disposal_remark", Type: field.TypeString, Nullable: true, Comment: "处置说明(报废/退货原因)"}, - {Name: "return_tracking_no", Type: field.TypeString, Nullable: true, Comment: "退货货运单号"}, {Name: "remark", Type: field.TypeString, Nullable: true, Comment: "备注"}, {Name: "created_at", Type: field.TypeInt64}, {Name: "updated_at", Type: field.TypeInt64}, @@ -1053,6 +1074,7 @@ var ( EventLogTable, InboundDetailsTable, InboundOrdersTable, + InspectionDisposalItemsTable, InspectionRecordsTable, InventoriesTable, InventoryLocksTable, @@ -1102,6 +1124,9 @@ func init() { InboundOrdersTable.Annotation = &entsql.Annotation{ Table: "inbound_orders", } + InspectionDisposalItemsTable.Annotation = &entsql.Annotation{ + Table: "inspection_disposal_items", + } InspectionRecordsTable.Annotation = &entsql.Annotation{ Table: "inspection_records", } diff --git a/bj_power_wms/ent/mutation.go b/bj_power_wms/ent/mutation.go index c821e5b..c746e97 100644 --- a/bj_power_wms/ent/mutation.go +++ b/bj_power_wms/ent/mutation.go @@ -12,6 +12,7 @@ import ( "bj_power_wms/ent/eventlog" "bj_power_wms/ent/inbounddetail" "bj_power_wms/ent/inboundorder" + "bj_power_wms/ent/inspectiondisposalitem" "bj_power_wms/ent/inspectionrecord" "bj_power_wms/ent/inventory" "bj_power_wms/ent/inventorylock" @@ -50,33 +51,34 @@ const ( OpUpdateOne = ent.OpUpdateOne // Node types. - TypeAlert = "Alert" - TypeAlertRule = "AlertRule" - TypeAttachment = "Attachment" - TypeBackupRecord = "BackupRecord" - TypeDeliveryOrder = "DeliveryOrder" - TypeDeliveryOrderItem = "DeliveryOrderItem" - TypeEventLog = "EventLog" - TypeInboundDetail = "InboundDetail" - TypeInboundOrder = "InboundOrder" - TypeInspectionRecord = "InspectionRecord" - TypeInventory = "Inventory" - TypeInventoryLock = "InventoryLock" - TypeMaterial = "Material" - TypeMaterialDemand = "MaterialDemand" - TypeOrderMaterialLedger = "OrderMaterialLedger" - TypeOutboundDetail = "OutboundDetail" - TypeOutboundOrder = "OutboundOrder" - TypePermission = "Permission" - TypeReturnOrder = "ReturnOrder" - TypeRole = "Role" - TypeSemiFinished = "SemiFinished" - TypeStocktakeItem = "StocktakeItem" - TypeStocktakeOrder = "StocktakeOrder" - TypeSyncFailure = "SyncFailure" - TypeSysConfig = "SysConfig" - TypeUser = "User" - TypeZone = "Zone" + TypeAlert = "Alert" + TypeAlertRule = "AlertRule" + TypeAttachment = "Attachment" + TypeBackupRecord = "BackupRecord" + TypeDeliveryOrder = "DeliveryOrder" + TypeDeliveryOrderItem = "DeliveryOrderItem" + TypeEventLog = "EventLog" + TypeInboundDetail = "InboundDetail" + TypeInboundOrder = "InboundOrder" + TypeInspectionDisposalItem = "InspectionDisposalItem" + TypeInspectionRecord = "InspectionRecord" + TypeInventory = "Inventory" + TypeInventoryLock = "InventoryLock" + TypeMaterial = "Material" + TypeMaterialDemand = "MaterialDemand" + TypeOrderMaterialLedger = "OrderMaterialLedger" + TypeOutboundDetail = "OutboundDetail" + TypeOutboundOrder = "OutboundOrder" + TypePermission = "Permission" + TypeReturnOrder = "ReturnOrder" + TypeRole = "Role" + TypeSemiFinished = "SemiFinished" + TypeStocktakeItem = "StocktakeItem" + TypeStocktakeOrder = "StocktakeOrder" + TypeSyncFailure = "SyncFailure" + TypeSysConfig = "SysConfig" + TypeUser = "User" + TypeZone = "Zone" ) // AlertMutation represents an operation that mutates the Alert nodes in the graph. @@ -9493,6 +9495,726 @@ func (m *InboundOrderMutation) ResetEdge(name string) error { return fmt.Errorf("unknown InboundOrder edge %s", name) } +// InspectionDisposalItemMutation represents an operation that mutates the InspectionDisposalItem nodes in the graph. +type InspectionDisposalItemMutation struct { + config + op Op + typ string + id *int + record_id *int64 + addrecord_id *int64 + dispose_type *string + qty *int + addqty *int + remark *string + operator *string + created_at *int64 + addcreated_at *int64 + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*InspectionDisposalItem, error) + predicates []predicate.InspectionDisposalItem +} + +var _ ent.Mutation = (*InspectionDisposalItemMutation)(nil) + +// inspectiondisposalitemOption allows management of the mutation configuration using functional options. +type inspectiondisposalitemOption func(*InspectionDisposalItemMutation) + +// newInspectionDisposalItemMutation creates new mutation for the InspectionDisposalItem entity. +func newInspectionDisposalItemMutation(c config, op Op, opts ...inspectiondisposalitemOption) *InspectionDisposalItemMutation { + m := &InspectionDisposalItemMutation{ + config: c, + op: op, + typ: TypeInspectionDisposalItem, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withInspectionDisposalItemID sets the ID field of the mutation. +func withInspectionDisposalItemID(id int) inspectiondisposalitemOption { + return func(m *InspectionDisposalItemMutation) { + var ( + err error + once sync.Once + value *InspectionDisposalItem + ) + m.oldValue = func(ctx context.Context) (*InspectionDisposalItem, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().InspectionDisposalItem.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withInspectionDisposalItem sets the old InspectionDisposalItem of the mutation. +func withInspectionDisposalItem(node *InspectionDisposalItem) inspectiondisposalitemOption { + return func(m *InspectionDisposalItemMutation) { + m.oldValue = func(context.Context) (*InspectionDisposalItem, 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 InspectionDisposalItemMutation) 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 InspectionDisposalItemMutation) 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 +} + +// 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 *InspectionDisposalItemMutation) 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 *InspectionDisposalItemMutation) 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().InspectionDisposalItem.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetRecordID sets the "record_id" field. +func (m *InspectionDisposalItemMutation) SetRecordID(i int64) { + m.record_id = &i + m.addrecord_id = nil +} + +// RecordID returns the value of the "record_id" field in the mutation. +func (m *InspectionDisposalItemMutation) RecordID() (r int64, exists bool) { + v := m.record_id + if v == nil { + return + } + return *v, true +} + +// OldRecordID returns the old "record_id" field's value of the InspectionDisposalItem entity. +// If the InspectionDisposalItem 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 *InspectionDisposalItemMutation) OldRecordID(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRecordID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRecordID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRecordID: %w", err) + } + return oldValue.RecordID, nil +} + +// AddRecordID adds i to the "record_id" field. +func (m *InspectionDisposalItemMutation) AddRecordID(i int64) { + if m.addrecord_id != nil { + *m.addrecord_id += i + } else { + m.addrecord_id = &i + } +} + +// AddedRecordID returns the value that was added to the "record_id" field in this mutation. +func (m *InspectionDisposalItemMutation) AddedRecordID() (r int64, exists bool) { + v := m.addrecord_id + if v == nil { + return + } + return *v, true +} + +// ResetRecordID resets all changes to the "record_id" field. +func (m *InspectionDisposalItemMutation) ResetRecordID() { + m.record_id = nil + m.addrecord_id = nil +} + +// SetDisposeType sets the "dispose_type" field. +func (m *InspectionDisposalItemMutation) SetDisposeType(s string) { + m.dispose_type = &s +} + +// DisposeType returns the value of the "dispose_type" field in the mutation. +func (m *InspectionDisposalItemMutation) DisposeType() (r string, exists bool) { + v := m.dispose_type + if v == nil { + return + } + return *v, true +} + +// OldDisposeType returns the old "dispose_type" field's value of the InspectionDisposalItem entity. +// If the InspectionDisposalItem 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 *InspectionDisposalItemMutation) OldDisposeType(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDisposeType is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDisposeType requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDisposeType: %w", err) + } + return oldValue.DisposeType, nil +} + +// ResetDisposeType resets all changes to the "dispose_type" field. +func (m *InspectionDisposalItemMutation) ResetDisposeType() { + m.dispose_type = nil +} + +// SetQty sets the "qty" field. +func (m *InspectionDisposalItemMutation) SetQty(i int) { + m.qty = &i + m.addqty = nil +} + +// Qty returns the value of the "qty" field in the mutation. +func (m *InspectionDisposalItemMutation) Qty() (r int, exists bool) { + v := m.qty + if v == nil { + return + } + return *v, true +} + +// OldQty returns the old "qty" field's value of the InspectionDisposalItem entity. +// If the InspectionDisposalItem 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 *InspectionDisposalItemMutation) OldQty(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldQty is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldQty requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldQty: %w", err) + } + return oldValue.Qty, nil +} + +// AddQty adds i to the "qty" field. +func (m *InspectionDisposalItemMutation) AddQty(i int) { + if m.addqty != nil { + *m.addqty += i + } else { + m.addqty = &i + } +} + +// AddedQty returns the value that was added to the "qty" field in this mutation. +func (m *InspectionDisposalItemMutation) AddedQty() (r int, exists bool) { + v := m.addqty + if v == nil { + return + } + return *v, true +} + +// ResetQty resets all changes to the "qty" field. +func (m *InspectionDisposalItemMutation) ResetQty() { + m.qty = nil + m.addqty = nil +} + +// SetRemark sets the "remark" field. +func (m *InspectionDisposalItemMutation) SetRemark(s string) { + m.remark = &s +} + +// Remark returns the value of the "remark" field in the mutation. +func (m *InspectionDisposalItemMutation) Remark() (r string, exists bool) { + v := m.remark + if v == nil { + return + } + return *v, true +} + +// OldRemark returns the old "remark" field's value of the InspectionDisposalItem entity. +// If the InspectionDisposalItem 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 *InspectionDisposalItemMutation) OldRemark(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRemark is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRemark requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRemark: %w", err) + } + return oldValue.Remark, nil +} + +// ClearRemark clears the value of the "remark" field. +func (m *InspectionDisposalItemMutation) ClearRemark() { + m.remark = nil + m.clearedFields[inspectiondisposalitem.FieldRemark] = struct{}{} +} + +// RemarkCleared returns if the "remark" field was cleared in this mutation. +func (m *InspectionDisposalItemMutation) RemarkCleared() bool { + _, ok := m.clearedFields[inspectiondisposalitem.FieldRemark] + return ok +} + +// ResetRemark resets all changes to the "remark" field. +func (m *InspectionDisposalItemMutation) ResetRemark() { + m.remark = nil + delete(m.clearedFields, inspectiondisposalitem.FieldRemark) +} + +// SetOperator sets the "operator" field. +func (m *InspectionDisposalItemMutation) SetOperator(s string) { + m.operator = &s +} + +// Operator returns the value of the "operator" field in the mutation. +func (m *InspectionDisposalItemMutation) Operator() (r string, exists bool) { + v := m.operator + if v == nil { + return + } + return *v, true +} + +// OldOperator returns the old "operator" field's value of the InspectionDisposalItem entity. +// If the InspectionDisposalItem 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 *InspectionDisposalItemMutation) OldOperator(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldOperator is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldOperator requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldOperator: %w", err) + } + return oldValue.Operator, nil +} + +// ResetOperator resets all changes to the "operator" field. +func (m *InspectionDisposalItemMutation) ResetOperator() { + m.operator = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *InspectionDisposalItemMutation) 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 *InspectionDisposalItemMutation) 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 InspectionDisposalItem entity. +// If the InspectionDisposalItem 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 *InspectionDisposalItemMutation) 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 *InspectionDisposalItemMutation) 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 *InspectionDisposalItemMutation) 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 *InspectionDisposalItemMutation) ResetCreatedAt() { + m.created_at = nil + m.addcreated_at = nil +} + +// Where appends a list predicates to the InspectionDisposalItemMutation builder. +func (m *InspectionDisposalItemMutation) Where(ps ...predicate.InspectionDisposalItem) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the InspectionDisposalItemMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *InspectionDisposalItemMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.InspectionDisposalItem, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *InspectionDisposalItemMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *InspectionDisposalItemMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (InspectionDisposalItem). +func (m *InspectionDisposalItemMutation) 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 *InspectionDisposalItemMutation) Fields() []string { + fields := make([]string, 0, 6) + if m.record_id != nil { + fields = append(fields, inspectiondisposalitem.FieldRecordID) + } + if m.dispose_type != nil { + fields = append(fields, inspectiondisposalitem.FieldDisposeType) + } + if m.qty != nil { + fields = append(fields, inspectiondisposalitem.FieldQty) + } + if m.remark != nil { + fields = append(fields, inspectiondisposalitem.FieldRemark) + } + if m.operator != nil { + fields = append(fields, inspectiondisposalitem.FieldOperator) + } + if m.created_at != nil { + fields = append(fields, inspectiondisposalitem.FieldCreatedAt) + } + 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 *InspectionDisposalItemMutation) Field(name string) (ent.Value, bool) { + switch name { + case inspectiondisposalitem.FieldRecordID: + return m.RecordID() + case inspectiondisposalitem.FieldDisposeType: + return m.DisposeType() + case inspectiondisposalitem.FieldQty: + return m.Qty() + case inspectiondisposalitem.FieldRemark: + return m.Remark() + case inspectiondisposalitem.FieldOperator: + return m.Operator() + case inspectiondisposalitem.FieldCreatedAt: + return m.CreatedAt() + } + 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 *InspectionDisposalItemMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case inspectiondisposalitem.FieldRecordID: + return m.OldRecordID(ctx) + case inspectiondisposalitem.FieldDisposeType: + return m.OldDisposeType(ctx) + case inspectiondisposalitem.FieldQty: + return m.OldQty(ctx) + case inspectiondisposalitem.FieldRemark: + return m.OldRemark(ctx) + case inspectiondisposalitem.FieldOperator: + return m.OldOperator(ctx) + case inspectiondisposalitem.FieldCreatedAt: + return m.OldCreatedAt(ctx) + } + return nil, fmt.Errorf("unknown InspectionDisposalItem 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 *InspectionDisposalItemMutation) SetField(name string, value ent.Value) error { + switch name { + case inspectiondisposalitem.FieldRecordID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRecordID(v) + return nil + case inspectiondisposalitem.FieldDisposeType: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDisposeType(v) + return nil + case inspectiondisposalitem.FieldQty: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetQty(v) + return nil + case inspectiondisposalitem.FieldRemark: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRemark(v) + return nil + case inspectiondisposalitem.FieldOperator: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetOperator(v) + return nil + case inspectiondisposalitem.FieldCreatedAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + } + return fmt.Errorf("unknown InspectionDisposalItem field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *InspectionDisposalItemMutation) AddedFields() []string { + var fields []string + if m.addrecord_id != nil { + fields = append(fields, inspectiondisposalitem.FieldRecordID) + } + if m.addqty != nil { + fields = append(fields, inspectiondisposalitem.FieldQty) + } + if m.addcreated_at != nil { + fields = append(fields, inspectiondisposalitem.FieldCreatedAt) + } + 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 *InspectionDisposalItemMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case inspectiondisposalitem.FieldRecordID: + return m.AddedRecordID() + case inspectiondisposalitem.FieldQty: + return m.AddedQty() + case inspectiondisposalitem.FieldCreatedAt: + return m.AddedCreatedAt() + } + 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 *InspectionDisposalItemMutation) AddField(name string, value ent.Value) error { + switch name { + case inspectiondisposalitem.FieldRecordID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddRecordID(v) + return nil + case inspectiondisposalitem.FieldQty: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddQty(v) + return nil + case inspectiondisposalitem.FieldCreatedAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddCreatedAt(v) + return nil + } + return fmt.Errorf("unknown InspectionDisposalItem numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *InspectionDisposalItemMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(inspectiondisposalitem.FieldRemark) { + fields = append(fields, inspectiondisposalitem.FieldRemark) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *InspectionDisposalItemMutation) 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 *InspectionDisposalItemMutation) ClearField(name string) error { + switch name { + case inspectiondisposalitem.FieldRemark: + m.ClearRemark() + return nil + } + return fmt.Errorf("unknown InspectionDisposalItem 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 *InspectionDisposalItemMutation) ResetField(name string) error { + switch name { + case inspectiondisposalitem.FieldRecordID: + m.ResetRecordID() + return nil + case inspectiondisposalitem.FieldDisposeType: + m.ResetDisposeType() + return nil + case inspectiondisposalitem.FieldQty: + m.ResetQty() + return nil + case inspectiondisposalitem.FieldRemark: + m.ResetRemark() + return nil + case inspectiondisposalitem.FieldOperator: + m.ResetOperator() + return nil + case inspectiondisposalitem.FieldCreatedAt: + m.ResetCreatedAt() + return nil + } + return fmt.Errorf("unknown InspectionDisposalItem field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *InspectionDisposalItemMutation) 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 *InspectionDisposalItemMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *InspectionDisposalItemMutation) 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 *InspectionDisposalItemMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *InspectionDisposalItemMutation) 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 *InspectionDisposalItemMutation) 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 *InspectionDisposalItemMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown InspectionDisposalItem 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 *InspectionDisposalItemMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown InspectionDisposalItem edge %s", name) +} + // InspectionRecordMutation represents an operation that mutates the InspectionRecord nodes in the graph. type InspectionRecordMutation struct { config @@ -9529,9 +10251,6 @@ type InspectionRecordMutation struct { disposal_status *string parent_record_id *int64 addparent_record_id *int64 - disposal_type *string - disposal_remark *string - return_tracking_no *string remark *string created_at *int64 addcreated_at *int64 @@ -10768,140 +11487,6 @@ func (m *InspectionRecordMutation) ResetParentRecordID() { m.addparent_record_id = nil } -// SetDisposalType sets the "disposal_type" field. -func (m *InspectionRecordMutation) SetDisposalType(s string) { - m.disposal_type = &s -} - -// DisposalType returns the value of the "disposal_type" field in the mutation. -func (m *InspectionRecordMutation) DisposalType() (r string, exists bool) { - v := m.disposal_type - if v == nil { - return - } - return *v, true -} - -// OldDisposalType returns the old "disposal_type" field's value of the InspectionRecord entity. -// If the InspectionRecord 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 *InspectionRecordMutation) OldDisposalType(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDisposalType is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDisposalType requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDisposalType: %w", err) - } - return oldValue.DisposalType, nil -} - -// ResetDisposalType resets all changes to the "disposal_type" field. -func (m *InspectionRecordMutation) ResetDisposalType() { - m.disposal_type = nil -} - -// SetDisposalRemark sets the "disposal_remark" field. -func (m *InspectionRecordMutation) SetDisposalRemark(s string) { - m.disposal_remark = &s -} - -// DisposalRemark returns the value of the "disposal_remark" field in the mutation. -func (m *InspectionRecordMutation) DisposalRemark() (r string, exists bool) { - v := m.disposal_remark - if v == nil { - return - } - return *v, true -} - -// OldDisposalRemark returns the old "disposal_remark" field's value of the InspectionRecord entity. -// If the InspectionRecord 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 *InspectionRecordMutation) OldDisposalRemark(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDisposalRemark is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDisposalRemark requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDisposalRemark: %w", err) - } - return oldValue.DisposalRemark, nil -} - -// ClearDisposalRemark clears the value of the "disposal_remark" field. -func (m *InspectionRecordMutation) ClearDisposalRemark() { - m.disposal_remark = nil - m.clearedFields[inspectionrecord.FieldDisposalRemark] = struct{}{} -} - -// DisposalRemarkCleared returns if the "disposal_remark" field was cleared in this mutation. -func (m *InspectionRecordMutation) DisposalRemarkCleared() bool { - _, ok := m.clearedFields[inspectionrecord.FieldDisposalRemark] - return ok -} - -// ResetDisposalRemark resets all changes to the "disposal_remark" field. -func (m *InspectionRecordMutation) ResetDisposalRemark() { - m.disposal_remark = nil - delete(m.clearedFields, inspectionrecord.FieldDisposalRemark) -} - -// SetReturnTrackingNo sets the "return_tracking_no" field. -func (m *InspectionRecordMutation) SetReturnTrackingNo(s string) { - m.return_tracking_no = &s -} - -// ReturnTrackingNo returns the value of the "return_tracking_no" field in the mutation. -func (m *InspectionRecordMutation) ReturnTrackingNo() (r string, exists bool) { - v := m.return_tracking_no - if v == nil { - return - } - return *v, true -} - -// OldReturnTrackingNo returns the old "return_tracking_no" field's value of the InspectionRecord entity. -// If the InspectionRecord 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 *InspectionRecordMutation) OldReturnTrackingNo(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldReturnTrackingNo is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldReturnTrackingNo requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldReturnTrackingNo: %w", err) - } - return oldValue.ReturnTrackingNo, nil -} - -// ClearReturnTrackingNo clears the value of the "return_tracking_no" field. -func (m *InspectionRecordMutation) ClearReturnTrackingNo() { - m.return_tracking_no = nil - m.clearedFields[inspectionrecord.FieldReturnTrackingNo] = struct{}{} -} - -// ReturnTrackingNoCleared returns if the "return_tracking_no" field was cleared in this mutation. -func (m *InspectionRecordMutation) ReturnTrackingNoCleared() bool { - _, ok := m.clearedFields[inspectionrecord.FieldReturnTrackingNo] - return ok -} - -// ResetReturnTrackingNo resets all changes to the "return_tracking_no" field. -func (m *InspectionRecordMutation) ResetReturnTrackingNo() { - m.return_tracking_no = nil - delete(m.clearedFields, inspectionrecord.FieldReturnTrackingNo) -} - // SetRemark sets the "remark" field. func (m *InspectionRecordMutation) SetRemark(s string) { m.remark = &s @@ -11097,7 +11682,7 @@ func (m *InspectionRecordMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *InspectionRecordMutation) Fields() []string { - fields := make([]string, 0, 30) + fields := make([]string, 0, 27) if m.target_type != nil { fields = append(fields, inspectionrecord.FieldTargetType) } @@ -11170,15 +11755,6 @@ func (m *InspectionRecordMutation) Fields() []string { if m.parent_record_id != nil { fields = append(fields, inspectionrecord.FieldParentRecordID) } - if m.disposal_type != nil { - fields = append(fields, inspectionrecord.FieldDisposalType) - } - if m.disposal_remark != nil { - fields = append(fields, inspectionrecord.FieldDisposalRemark) - } - if m.return_tracking_no != nil { - fields = append(fields, inspectionrecord.FieldReturnTrackingNo) - } if m.remark != nil { fields = append(fields, inspectionrecord.FieldRemark) } @@ -11244,12 +11820,6 @@ func (m *InspectionRecordMutation) Field(name string) (ent.Value, bool) { return m.DisposalStatus() case inspectionrecord.FieldParentRecordID: return m.ParentRecordID() - case inspectionrecord.FieldDisposalType: - return m.DisposalType() - case inspectionrecord.FieldDisposalRemark: - return m.DisposalRemark() - case inspectionrecord.FieldReturnTrackingNo: - return m.ReturnTrackingNo() case inspectionrecord.FieldRemark: return m.Remark() case inspectionrecord.FieldCreatedAt: @@ -11313,12 +11883,6 @@ func (m *InspectionRecordMutation) OldField(ctx context.Context, name string) (e return m.OldDisposalStatus(ctx) case inspectionrecord.FieldParentRecordID: return m.OldParentRecordID(ctx) - case inspectionrecord.FieldDisposalType: - return m.OldDisposalType(ctx) - case inspectionrecord.FieldDisposalRemark: - return m.OldDisposalRemark(ctx) - case inspectionrecord.FieldReturnTrackingNo: - return m.OldReturnTrackingNo(ctx) case inspectionrecord.FieldRemark: return m.OldRemark(ctx) case inspectionrecord.FieldCreatedAt: @@ -11502,27 +12066,6 @@ func (m *InspectionRecordMutation) SetField(name string, value ent.Value) error } m.SetParentRecordID(v) return nil - case inspectionrecord.FieldDisposalType: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetDisposalType(v) - return nil - case inspectionrecord.FieldDisposalRemark: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetDisposalRemark(v) - return nil - case inspectionrecord.FieldReturnTrackingNo: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetReturnTrackingNo(v) - return nil case inspectionrecord.FieldRemark: v, ok := value.(string) if !ok { @@ -11706,12 +12249,6 @@ func (m *InspectionRecordMutation) ClearedFields() []string { if m.FieldCleared(inspectionrecord.FieldReportNo) { fields = append(fields, inspectionrecord.FieldReportNo) } - if m.FieldCleared(inspectionrecord.FieldDisposalRemark) { - fields = append(fields, inspectionrecord.FieldDisposalRemark) - } - if m.FieldCleared(inspectionrecord.FieldReturnTrackingNo) { - fields = append(fields, inspectionrecord.FieldReturnTrackingNo) - } if m.FieldCleared(inspectionrecord.FieldRemark) { fields = append(fields, inspectionrecord.FieldRemark) } @@ -11762,12 +12299,6 @@ func (m *InspectionRecordMutation) ClearField(name string) error { case inspectionrecord.FieldReportNo: m.ClearReportNo() return nil - case inspectionrecord.FieldDisposalRemark: - m.ClearDisposalRemark() - return nil - case inspectionrecord.FieldReturnTrackingNo: - m.ClearReturnTrackingNo() - return nil case inspectionrecord.FieldRemark: m.ClearRemark() return nil @@ -11851,15 +12382,6 @@ func (m *InspectionRecordMutation) ResetField(name string) error { case inspectionrecord.FieldParentRecordID: m.ResetParentRecordID() return nil - case inspectionrecord.FieldDisposalType: - m.ResetDisposalType() - return nil - case inspectionrecord.FieldDisposalRemark: - m.ResetDisposalRemark() - return nil - case inspectionrecord.FieldReturnTrackingNo: - m.ResetReturnTrackingNo() - return nil case inspectionrecord.FieldRemark: m.ResetRemark() return nil diff --git a/bj_power_wms/ent/predicate/predicate.go b/bj_power_wms/ent/predicate/predicate.go index 2fdc99f..0e7b596 100644 --- a/bj_power_wms/ent/predicate/predicate.go +++ b/bj_power_wms/ent/predicate/predicate.go @@ -33,6 +33,9 @@ type InboundDetail func(*sql.Selector) // InboundOrder is the predicate function for inboundorder builders. type InboundOrder func(*sql.Selector) +// InspectionDisposalItem is the predicate function for inspectiondisposalitem builders. +type InspectionDisposalItem func(*sql.Selector) + // InspectionRecord is the predicate function for inspectionrecord builders. type InspectionRecord func(*sql.Selector) diff --git a/bj_power_wms/ent/runtime.go b/bj_power_wms/ent/runtime.go index 094891a..f9c0cde 100644 --- a/bj_power_wms/ent/runtime.go +++ b/bj_power_wms/ent/runtime.go @@ -12,6 +12,7 @@ import ( "bj_power_wms/ent/eventlog" "bj_power_wms/ent/inbounddetail" "bj_power_wms/ent/inboundorder" + "bj_power_wms/ent/inspectiondisposalitem" "bj_power_wms/ent/inspectionrecord" "bj_power_wms/ent/inventory" "bj_power_wms/ent/inventorylock" @@ -332,6 +333,20 @@ func init() { inboundorderDescCreatedAt := inboundorderFields[23].Descriptor() // inboundorder.DefaultCreatedAt holds the default value on creation for the created_at field. inboundorder.DefaultCreatedAt = inboundorderDescCreatedAt.Default.(func() int64) + inspectiondisposalitemFields := schema.InspectionDisposalItem{}.Fields() + _ = inspectiondisposalitemFields + // inspectiondisposalitemDescQty is the schema descriptor for qty field. + inspectiondisposalitemDescQty := inspectiondisposalitemFields[2].Descriptor() + // inspectiondisposalitem.QtyValidator is a validator for the "qty" field. It is called by the builders before save. + inspectiondisposalitem.QtyValidator = inspectiondisposalitemDescQty.Validators[0].(func(int) error) + // inspectiondisposalitemDescOperator is the schema descriptor for operator field. + inspectiondisposalitemDescOperator := inspectiondisposalitemFields[4].Descriptor() + // inspectiondisposalitem.DefaultOperator holds the default value on creation for the operator field. + inspectiondisposalitem.DefaultOperator = inspectiondisposalitemDescOperator.Default.(string) + // inspectiondisposalitemDescCreatedAt is the schema descriptor for created_at field. + inspectiondisposalitemDescCreatedAt := inspectiondisposalitemFields[5].Descriptor() + // inspectiondisposalitem.DefaultCreatedAt holds the default value on creation for the created_at field. + inspectiondisposalitem.DefaultCreatedAt = inspectiondisposalitemDescCreatedAt.Default.(func() int64) inspectionrecordFields := schema.InspectionRecord{}.Fields() _ = inspectionrecordFields // inspectionrecordDescInspectionType is the schema descriptor for inspection_type field. @@ -374,16 +389,12 @@ func init() { inspectionrecordDescParentRecordID := inspectionrecordFields[23].Descriptor() // inspectionrecord.DefaultParentRecordID holds the default value on creation for the parent_record_id field. inspectionrecord.DefaultParentRecordID = inspectionrecordDescParentRecordID.Default.(int64) - // inspectionrecordDescDisposalType is the schema descriptor for disposal_type field. - inspectionrecordDescDisposalType := inspectionrecordFields[24].Descriptor() - // inspectionrecord.DefaultDisposalType holds the default value on creation for the disposal_type field. - inspectionrecord.DefaultDisposalType = inspectionrecordDescDisposalType.Default.(string) // inspectionrecordDescCreatedAt is the schema descriptor for created_at field. - inspectionrecordDescCreatedAt := inspectionrecordFields[28].Descriptor() + inspectionrecordDescCreatedAt := inspectionrecordFields[25].Descriptor() // inspectionrecord.DefaultCreatedAt holds the default value on creation for the created_at field. inspectionrecord.DefaultCreatedAt = inspectionrecordDescCreatedAt.Default.(func() int64) // inspectionrecordDescUpdatedAt is the schema descriptor for updated_at field. - inspectionrecordDescUpdatedAt := inspectionrecordFields[29].Descriptor() + inspectionrecordDescUpdatedAt := inspectionrecordFields[26].Descriptor() // inspectionrecord.DefaultUpdatedAt holds the default value on creation for the updated_at field. inspectionrecord.DefaultUpdatedAt = inspectionrecordDescUpdatedAt.Default.(func() int64) inventoryFields := schema.Inventory{}.Fields() diff --git a/bj_power_wms/ent/tx.go b/bj_power_wms/ent/tx.go index 56fb6a8..7de10ec 100644 --- a/bj_power_wms/ent/tx.go +++ b/bj_power_wms/ent/tx.go @@ -30,6 +30,8 @@ type Tx struct { InboundDetail *InboundDetailClient // InboundOrder is the client for interacting with the InboundOrder builders. InboundOrder *InboundOrderClient + // InspectionDisposalItem is the client for interacting with the InspectionDisposalItem builders. + InspectionDisposalItem *InspectionDisposalItemClient // InspectionRecord is the client for interacting with the InspectionRecord builders. InspectionRecord *InspectionRecordClient // Inventory is the client for interacting with the Inventory builders. @@ -206,6 +208,7 @@ func (tx *Tx) init() { tx.EventLog = NewEventLogClient(tx.config) tx.InboundDetail = NewInboundDetailClient(tx.config) tx.InboundOrder = NewInboundOrderClient(tx.config) + tx.InspectionDisposalItem = NewInspectionDisposalItemClient(tx.config) tx.InspectionRecord = NewInspectionRecordClient(tx.config) tx.Inventory = NewInventoryClient(tx.config) tx.InventoryLock = NewInventoryLockClient(tx.config) diff --git a/bj_power_wms/frontend/src/components/InboundEntry.vue b/bj_power_wms/frontend/src/components/InboundEntry.vue index 1fb3691..85e4c0d 100644 --- a/bj_power_wms/frontend/src/components/InboundEntry.vue +++ b/bj_power_wms/frontend/src/components/InboundEntry.vue @@ -331,7 +331,7 @@ onMounted(() => loadZones())
-
未找到对应的工单,请确认产品工号是否正确
+
未在 MES 找到该产品工号对应的工单;产品工号可留空,不影响入库,如手填请核对是否与 MES 工单号一致
网络异常,未能校验工单号,请稍后确认
diff --git a/bj_power_wms/frontend/src/help.js b/bj_power_wms/frontend/src/help.js index 5605be5..058e613 100644 --- a/bj_power_wms/frontend/src/help.js +++ b/bj_power_wms/frontend/src/help.js @@ -34,12 +34,12 @@ export const helpInspection = Q('来料检验', '判定一旦写下去就不能 { q: '判定之后还能改结论吗?', a: '不能。复检是新增一条记录覆盖判定,原记录保留可查。' }, { q: '「清空」会丢什么?', a: '会丢已经选好但还没送检的清单;切换入库单时也会清空已选。选好了就别中途切单。' }, { q: '一次能送多少?', a: '单次上限 100 条,多了分批送。待检明细的条数是动态生成的,按实际件数来。' }, - { q: '部分入库到底怎么记?', a: '一次部分入库只能针对单批次。不合格的那部分会自动拆成带 -NG 后缀的待处置行,跟合格部分不是同一条账;要先想清楚「处置方式」再提交,不然不合格品会悬在那里没有去向。' } + { q: '不合格部分怎么处置?', a: '2026-11-16 起处置按明细行记:判「不合格」后逐行填退货 / 返修 / 报废并拆数量,多行数量合计必须等于不合格数;备注可空,退货的物流单号等信息填备注。提交时按行执行库存动作(退货→待退、返修→不合格隔离、报废→报废)。' } ], ['判定合格/不合格会直接改变这批货能不能出库。'], [ { t: '功能定位', text: 'WMS 只做来料检验;过程检、完工检属于 MES,两边不要互相找记录。' }, { t: '必填与选填', items: [ - '必填 11 项:至少 1 条待检项;目标类型(批次 / SN / 其他);归属类型;归属编号(归属为合同号 / 科技项目时必填);每条待检编号;记录人;处置方式(有不合格时必填);退货运单号(处置=退货时必填);第几批 / 共几件(批次行、序列号=否,均 ≥1);合格数守恒(≤ 检验数,判合格时相等);部分入库限单批次。', - '选填 5 项:检测单号、报检单号、生产厂家、相关标准、相关标准说明,表单里都标了「可空」。' + '必填:至少 1 条待检项;目标类型(批次 / SN / 其他);归属类型;归属编号(归属为合同号 / 科技项目时必填);每条待检编号;记录人;处置明细行(有不合格时必填,退货 / 返修 / 报废按数量拆分,多行合计=不合格数);合格数守恒(≤ 检验数,判合格时相等)。', + '选填:检测单号、报检单号、生产厂家、相关标准、相关标准说明、处置备注,表单里都标了「可空」;退货运单号概念已废除,物流信息填备注。' ] }, { t: '异常场景', text: '检验结论还没录机、系统里查不到检测单号时不会报错,实物检验责任仍在库管;记录补进来之后会自动关联。' } ], [ diff --git a/bj_power_wms/frontend/src/pages/DefectReturn.vue b/bj_power_wms/frontend/src/pages/DefectReturn.vue index 4349085..8da58f6 100644 --- a/bj_power_wms/frontend/src/pages/DefectReturn.vue +++ b/bj_power_wms/frontend/src/pages/DefectReturn.vue @@ -224,7 +224,7 @@ onMounted(() => { diff --git a/bj_power_wms/frontend/src/pages/Inspection.vue b/bj_power_wms/frontend/src/pages/Inspection.vue index 5115b69..23f65cd 100644 --- a/bj_power_wms/frontend/src/pages/Inspection.vue +++ b/bj_power_wms/frontend/src/pages/Inspection.vue @@ -36,8 +36,6 @@ const ownershipType = ref('other') const ownershipNo = ref('') const relatedStandard = ref('') const manufacturer = ref('') -const disposalType = ref('NONE') -const returnTrackingNo = ref('') // 待检编号列表(逐个判定:每条独立结论/检验数/合格数) const items = ref([]) // { targetId, status, inspectQty, passQty, snMode, batchSeq, batchTotal } @@ -113,7 +111,7 @@ function addItem(targetId, qty, materialCode = '', materialName = '', inboundNo if (!targetId) return if (items.value.some((i) => i.targetId === targetId)) return const iq = Number(snMode) !== 1 ? (Number(qty) || 1) : 1 - items.value.push({ targetId, materialCode, materialName, inboundNo, snMode, status: '合格', inspectQty: iq, passQty: iq, batchSeq: null, batchTotal: null }) + items.value.push({ targetId, materialCode, materialName, inboundNo, snMode, status: '合格', inspectQty: iq, passQty: iq, disposals: [], batchSeq: null, batchTotal: null }) } async function addFromInput() { if (sourceInboundNo.value) { @@ -163,7 +161,19 @@ function clearAll() { items.value = [] sourceInboundNo.value = '' // 解除入库单绑定,回到自由录入模式 } -// 结论变化:SN/其他 自动定检验数=1、合格数随结论;批次合格时合格数=检验数 +// 结论变化:SN/其他 自动定检验数=1、合格数随结论;批次合格时合格数=检验数。 +// 2026-11-16 拍板:处置下放明细行——行判「不合格」时初始化一条处置明细(默认全量退货), +// 可按数量拆分为退货/返修/报废多行;运单号概念废除,物流信息填备注。 +function rejectQtyOfRow(row) { + return Math.max(0, (Number(row.inspectQty) || 0) - (Number(row.passQty) || 0)) +} +function disposalSum(row) { + return (row.disposals || []).reduce((s, d) => s + (Number(d.qty) || 0), 0) +} +function addDisposalLine(row) { + if (!row.disposals) row.disposals = [] + row.disposals.push({ type: 'RETURN', qty: Math.max(1, rejectQtyOfRow(row) - disposalSum(row)), remark: '' }) +} function onItemStatus(row) { if (!isRowBatch(row)) { row.inspectQty = 1 @@ -171,6 +181,13 @@ function onItemStatus(row) { } else if (row.status === '合格') { row.passQty = row.inspectQty } + if (row.status === '不合格') { + if (!row.disposals || !row.disposals.length) { + row.disposals = [{ type: 'RETURN', qty: rejectQtyOfRow(row) || 1, remark: '' }] + } + } else { + row.disposals = [] + } } function onTargetTypeChange() { clearAll() @@ -232,18 +249,24 @@ async function submitInspection() { ElMessage.warning('请填写记录人') return } - const hasFail = items.value.some((i) => i.status === '不合格') - if (hasFail && disposalType.value === 'NONE') { - ElMessage.warning('有不合格项时必须选择处置方式(退货 / 换修 / 报废 / 部分入库)') - return - } - if (hasFail && disposalType.value === 'RETURN' && !returnTrackingNo.value.trim()) { - ElMessage.warning('退货处置必须填写货运单号') - return - } - if (hasFail && disposalType.value === 'PARTIAL' && (items.value.length !== 1 || !isRowBatch(items[0]))) { - ElMessage.warning('「部分入库」一次只能处理 1 个批次,请分开提交') - return + // 处置明细校验(2026-11-16 拍板):不合格行必须带处置明细,Σqty=不合格数,逐行数量>0; + // 运单号概念废除,退货物流信息填备注(可空) + for (const it of items.value) { + if (it.status !== '不合格') continue + if (!it.disposals || !it.disposals.length) { + ElMessage.warning(`批次/SN「${it.targetId}」判定不合格,请至少填写一条处置明细(退货 / 返修 / 报废)`) + return + } + const rq = rejectQtyOfRow(it) + const sum = disposalSum(it) + if (it.disposals.some((d) => (Number(d.qty) || 0) <= 0)) { + ElMessage.warning(`批次/SN「${it.targetId}」处置明细行数量必须大于 0`) + return + } + if (sum !== rq) { + ElMessage.warning(`批次/SN「${it.targetId}」处置明细数量合计(${sum})必须等于不合格数量(${rq})`) + return + } } // 报检数守恒校验(批次:合格数 ≤ 检验数;合格时两者相等) for (const it of items.value) { @@ -265,9 +288,9 @@ async function submitInspection() { status: it.status, inspectQty: Number(it.inspectQty) || 0, passQty: Number(it.passQty) || 0, - disposalType: it.status === '不合格' ? disposalType.value : 'NONE', - returnTrackingNo: returnTrackingNo.value.trim(), - disposalRemark: '', + disposals: it.status === '不合格' + ? (it.disposals || []).map((d) => ({ type: d.type, qty: Number(d.qty) || 0, remark: (d.remark || '').trim() })) + : [], ownershipType: ownershipType.value, ownershipNo: ownershipNo.value.trim(), relatedStandard: relatedStandard.value.trim(), @@ -286,17 +309,15 @@ async function submitInspection() { if (!allPass) { // 2026-11-14:文案统一取规则表第 19 条,菜单路径按对象域「物料 → 通用出库」。 showNextStep(manualPayload(19, { - title: `已登记 ${n} 条检验记录,不合格部分挂「待处置」`, + title: `已登记 ${n} 条检验记录,不合格部分已按处置明细隔离`, primaryNo: passedNo || '', - tip: '处置为退货时再去「物料 → 通用出库」按退货运单号出库;刷新本页后此提示消失。' + tip: '退货明细的物料随后在「物料 → 通用出库」按批次出库退回供应商;刷新本页后此提示消失。' })) } clearAll() checkDesc.value = '' reportNo.value = '' inspectionNo.value = '' - disposalType.value = 'NONE' - returnTrackingNo.value = '' ownershipType.value = 'other' ownershipNo.value = '' relatedStandard.value = '' @@ -435,24 +456,20 @@ function sendSelectedFromDrawer() { } /* ===================== 不合格处置 ===================== */ -const disposeDialog = reactive({ visible: false, row: null, type: 'RETURN', remark: '', trackingNo: '' }) +const disposeDialog = reactive({ visible: false, row: null, type: 'RETURN', remark: '' }) function openDispose(row) { if (row.status !== '不合格') { ElMessage.warning('仅「不合格」记录可执行处置') return } - Object.assign(disposeDialog, { visible: true, row, type: 'RETURN', remark: '', trackingNo: '' }) + Object.assign(disposeDialog, { visible: true, row, type: 'RETURN', remark: '' }) } async function submitDispose() { - if (disposeDialog.type === 'RETURN' && !disposeDialog.trackingNo.trim()) { - ElMessage.warning('退货必须填写货运单号') - return - } await request.post('/inspection/dispose', { recordId: disposeDialog.row.id, disposalType: disposeDialog.type, disposalRemark: disposeDialog.remark.trim(), - returnTrackingNo: disposeDialog.trackingNo.trim(), + operator: getRealName(), }) ElMessage.success('处置完成') disposeDialog.visible = false @@ -497,9 +514,14 @@ function targetTypeLabel(t) { return t === 'SN' ? '序列号' : t === 'BATCH' ? '批次' : t === 'OTHER' ? '其他' : (t || '-') } function disposalLabel(t) { - const m = { RETURN: '退货', SCRAP: '报废', PARTIAL: '部分入库', REWORK: '换修' } + const m = { RETURN: '退货', SCRAP: '报废', REWORK: '返修' } return m[t] || '未处置' } +// 2026-11-16 拍板:处置明细子表行文本(后端 query/export 附加 disposalLines:"退货×5(备注);返修×5") +function disposalLinesText(row) { + if (!row || !row.disposalLines) return '' + return String(row.disposalLines) +} // 三维度之三:不合格品处置状态(独立于检验结论与数量拆分) function rejectQtyOf(row) { if (!row) return 0 @@ -692,17 +714,6 @@ onMounted(() => { 其他 (辅料·工装·试验设备) - - - 退货 - 换修 - 报废 - 部分入库 - - - - - @@ -801,6 +812,30 @@ onMounted(() => { + + + + - + @@ -946,8 +981,8 @@ onMounted(() => { @@ -1010,7 +1045,7 @@ onMounted(() => {
- + @@ -1024,7 +1059,7 @@ onMounted(() => { - = 检验数 − 合格数;这部分不会进入合格库存,需在本弹窗完成处置 + = 检验数 − 合格数;这部分不会进入合格库存,本弹窗一次性完成处置 @@ -1034,16 +1069,14 @@ onMounted(() => { 退货 - 换修 + 返修 报废 - 部分入库 - - + + -