【MES · 工位终端状态感知(11-28 第十三节拍板)】 - 新增 station_terminal_state / station_terminal_event 两表:当前状态镜像 + 状态变化流水 - 在线判定走既有 SSE 长连接存活:建连/断连/30s ping 心跳,90s 无心跳判离线,零 HTTP 轮询 - 登录/退出/暂停/恢复由终端事件驱动上报;新增「终端状态」管理页(produce.terminalstate,仅超级管理员):看在线/登录/操作人/接单/下班判定/心跳,抽屉看状态流水 - 库管代退料前置条件②「工人已下班」据此判定:未登录或终端离线任一即下班 【工位终端 · 全厂统一账号(11-28 拍板)】 - 删除本地账号表与 seed,登录直连 MES 用户表;本地 SQLite 只剩操作日志+登录态,断网不能换人 - SSE 客户端携带本机固定工位号,MES 据连接存活映射该工位在线状态 【单号短号规则(11-27 拍板)】 - 叫料单 MR / 叫料包 PK / 转产退库 TR / 配送单 DL:改「前缀+YYMMDD+3位当天序号」,每天从 001 归零、超 999 进 4 位 - MR 与 TR 同列不同前缀独立计数不撞号;进程内互斥分配 + DB 唯一索引兜底;历史时间戳号一律不动 【退料闭环(11-28)】 - 退库单新增 sn_list:工位提交的待退 SN 清单落库,收货逐颗扫码核对(不按批次分组、允许跨批次混合,所属批次系统按 SN 带出,库管不必填) - 收货改大数量必须有实物依据:SN 件以精确扫描的最终清单为准(条数相等且不重复);批次件必须落到真实启用的四级库位,禁止凭空加库存 - 余量参考值口径定稿(N4):应剩余量 = 实际备料 − 已消耗 − 已退 − 已损耗 - 损耗台账取消「后审核批注」:删 status/comment/commenter/commented_at 字段,WMS 确认收货当场落账闭环,MES 台账只读 【日排产 · 两种 PENDING 区分(11-26 口径定稿)】 - daily_plan 新增 discarded 废弃标记:停用打标、新建不打标;额度只算 CONFIRMED + 未废弃 PENDING - 工单管「要干几台」、日排产管「按天从哪个工位领多少料」,两张账不合并不互倒推;排产合计可小于工单数(缺口靠借料/补料审批摆出,不自动兜底) 【其他】 - SN 查询大小写脱敏(11-27):存储原样不强制大小写,匹配 LOWER(sn)=LOWER(?),扫 ABC-0001 与 abc-0001 命中同一件 - 拧紧枪人工跳过链路:设备未连接时人工跳过上报,「拧紧跳过(设备未连接)」前缀单独列示,不写 torque_record 绝不冒充设备结果 - 单据流转提示规则表全量 35 条(MES 18 + WMS 17):常驻提示条、单号可复制;单号字段逐条对后端响应实测,取不到不显示复制按钮 - PLC 快照缓存/对账、产线清线、绩效与拧紧枪配置页同步修正 【文档】 - 新增《临时结束.md》2026-11-26 日排产/叫料/完工口径大讨论定稿(含状态专项结论与被推翻旧说法留档);问题临时.md 全量更新
120 lines
8.5 KiB
Go
120 lines
8.5 KiB
Go
package handler
|
||
|
||
import (
|
||
"net/http"
|
||
|
||
"bj_power_workstation/internal/auth"
|
||
"bj_power_workstation/internal/svc"
|
||
|
||
"github.com/zeromicro/go-zero/rest"
|
||
)
|
||
|
||
func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
|
||
// 免鉴权:健康检查 / 登录 / 工位配置
|
||
server.AddRoutes(
|
||
[]rest.Route{
|
||
{Method: http.MethodGet, Path: "/api/health", Handler: healthHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/server-time", Handler: serverTimeHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/auth/login", Handler: loginHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/config", Handler: configHandler(ctx)},
|
||
// 工位选项(免鉴权,登录前调用):未配置工位的终端登录页选择工位用(2026-11-09 拍板)
|
||
{Method: http.MethodGet, Path: "/api/station-options", Handler: stationOptionsHandler(ctx)},
|
||
// 工艺文件免鉴权直链(query 传名,支持日期子目录;供 iframe/window.open)
|
||
{Method: http.MethodGet, Path: "/pdfview", Handler: pdfViewHandler(ctx)},
|
||
// 本机工位报警 SSE(免鉴权:EventSource 无法携带 JWT;数据已按本机工位过滤,LAN 内低敏感)
|
||
{Method: http.MethodGet, Path: "/api/alerts/stream", Handler: alertsStreamHandler(ctx)},
|
||
// 前端静态托管
|
||
{Method: http.MethodGet, Path: "/", Handler: indexHandler(ctx.WebFS)},
|
||
{Method: http.MethodGet, Path: "/assets/:file", Handler: assetHandler(ctx.WebFS)},
|
||
},
|
||
)
|
||
|
||
// 登录鉴权中间件:白名单 /api/health、/api/auth/login、/api/config、/pdfopen/*
|
||
server.Use(auth.Interceptor(ctx.Config.Auth.AccessSecret, ctx.Config.Auth.AccessExpire))
|
||
|
||
// 业务接口(均需登录 JWT;PDF 代理除外——原样转发文件流)
|
||
server.AddRoutes(
|
||
[]rest.Route{
|
||
// 滑动续签(修订需求):任何人工触屏触发;touch 刷本地空闲计时,
|
||
// refresh-token 节流 30 秒换新 MES Bearer,作业中令牌不因固定有效期过期
|
||
{Method: http.MethodPost, Path: "/api/auth/touch", Handler: touchHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/auth/refresh-token", Handler: refreshTokenHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/task/current", Handler: taskCurrentHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/bind/panel", Handler: bindPanelHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/bind/record", Handler: bindRecordHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/bind/remove", Handler: bindRemoveHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/workload", Handler: workloadHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/stations", Handler: stationsHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/station/pause", Handler: stationPauseHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/station/state", Handler: stationStateHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/pdf", Handler: pdfQueryHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/pdfopen/:name", Handler: pdfOpenHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/tightening/record", Handler: tighteningRecordHandler(ctx)},
|
||
// 拧紧枪未连接时的人工跳过(单独留痕,不冒充设备结果)
|
||
{Method: http.MethodPost, Path: "/api/tightening/skip", Handler: tighteningSkipHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/tightening/live", Handler: tighteningLiveHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/tightening/consume", Handler: tighteningConsumeHandler(ctx)},
|
||
// 报工前同步 MES 的人工放行状态(NG 放行后解锁本地拧紧步骤)
|
||
{Method: http.MethodGet, Path: "/api/tightening/ng-pending", Handler: tighteningNgPendingHandler(ctx)},
|
||
// 拧紧枪控制器连接状态(页角小标识轮询用,2026-11-25 新增)
|
||
{Method: http.MethodGet, Path: "/api/tightening/status", Handler: tighteningStatusHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/report/process-done", Handler: processDoneHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/report/temp-store", Handler: tempStoreHandler(ctx)},
|
||
// 工件报废/人工取走(2026-11-03 补全):与暂存退库语义互斥,原因必填,不做离线排队
|
||
{Method: http.MethodPost, Path: "/api/report/scrap", Handler: scrapHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/station/logout", Handler: logoutHandler(ctx)},
|
||
|
||
// 产线点位 / 叫料(代理 MES 内部 API)
|
||
{Method: http.MethodGet, Path: "/api/line/points", Handler: linePointsHandler(ctx)},
|
||
// 建档前点位传感器实物核对(只读,不触发下流;PLC 读不到时前端降级人工确认)
|
||
{Method: http.MethodGet, Path: "/api/line/point-sensor", Handler: linePointSensorHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/line/occupy", Handler: lineOccupyHandler(ctx)},
|
||
// B5 叫料六端点(代理 MES 内部 API):池子/发起/列表/签收/取消/退库申请
|
||
{Method: http.MethodGet, Path: "/api/call/pool", Handler: callPoolHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/docks", Handler: docksHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/call/create", Handler: callCreateHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/call/list", Handler: callListHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/call/sign", Handler: callSignHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/call/cancel", Handler: callCancelHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/call/return", Handler: callReturnHandler(ctx)},
|
||
// 原因基础字典(2026-11-14 用户拍板:停机/不良原因改下拉,代理 MES 唯一真源)
|
||
{Method: http.MethodGet, Path: "/api/dict/reasons", Handler: reasonDictHandler(ctx)},
|
||
// 2026-11-05 叫料包拍板:需求明细(两类提示)/ 左右接驳台实时传感器 / 托盘回库 / 工位物料明细
|
||
{Method: http.MethodGet, Path: "/api/call/plan-detail", Handler: callPlanDetailHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/dock/station-pallets", Handler: stationDockPalletsHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/dock/pallet-return", Handler: palletReturnHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/call/material-detail", Handler: materialDetailHandler(ctx)},
|
||
|
||
// 巡检 / 应急呼叫 / 数量不符 / 退料(代理 MES 内部 API)
|
||
{Method: http.MethodPost, Path: "/api/inspection/submit", Handler: inspectionSubmitHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/emergency/call", Handler: emergencyCallHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/qty-report", Handler: qtyReportHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/return-material", Handler: returnMaterialHandler(ctx)},
|
||
// 退料单列表/取消/余量参考值(2026-11-04 口径定稿:工位可取消自己 PENDING 退料单)
|
||
{Method: http.MethodGet, Path: "/api/return-list", Handler: stationReturnListHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/return-cancel", Handler: stationReturnCancelHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/return-reference", Handler: stationReturnReferenceHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/returnable-sns", Handler: returnableSNsHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/return-retry-dispatch", Handler: stationReturnRetryDispatchHandler(ctx)},
|
||
// 下班/结束作业闭环(2026-11-03):查询班次(退出提示)+ 下班提交(自检接驳台剩余物料)
|
||
{Method: http.MethodGet, Path: "/api/shift", Handler: shiftGetHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/off-duty", Handler: offDutyHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/inspection/upload", Handler: inspectionUploadHandler(ctx)},
|
||
|
||
// 在制品 / 上下线建档 / 物料清单领料 / 追溯(代理 MES 内部 API)
|
||
{Method: http.MethodGet, Path: "/api/wip", Handler: wipHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/bom", Handler: bomHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/order/query", Handler: orderQueryHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/order/by-sn", Handler: snOrderLookupHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/trace", Handler: traceHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/workpiece/online", Handler: onlineHandler(ctx)},
|
||
|
||
// 本工位相关报警(谁受影响谁播报,2026-10-20):终端前端轮询 + 语音播报
|
||
{Method: http.MethodGet, Path: "/api/alerts/station", Handler: stationAlertsHandler(ctx)},
|
||
|
||
// PLC↔MES 对账(#8 T2/T3 终端事件驱动检查,不轮询):代理 MES 内部接口,MES 不可达静默跳过
|
||
{Method: http.MethodPost, Path: "/api/plc/mismatch/check", Handler: plcMismatchCheckHandler(ctx)},
|
||
},
|
||
)
|
||
}
|