feat: 移除工位模板、AGV 链路增强与产品BOM/混产模板完善

- 移除工位模板体系(handler/logic 全删),同步路由与 seed
- AGV 链路增强:点位锁、车辆状态、退料派车调整,新增海康 RCS Postman 调试集合
- MES 产品BOM/混产模板完善:新增 ProductBOMDialog 组件,调整 handler/logic;日排产达成对比调整
- WMS 业务完善:出入库、检验、备料、退料、成品入库、缺料代报等 handler 与前端页面调整
- 前端通用:双端新增 RemotePageSelect 组件,统一 nextStep 规则/帮助文档/布局/请求拦截
- 文档:更新产线API/案例/部署手册/问题记录等
This commit is contained in:
SunYF
2026-11-18 09:53:42 +08:00
parent 5c9a7e32d2
commit f8482b18f6
122 changed files with 3381 additions and 2004 deletions
+26 -30
View File
@@ -29,23 +29,23 @@ var pathPermMap = map[string]string{
// T2 收货差异确认损耗(2026-11-04):人工核实后落损耗台账,归数量不符处理权限(同链路操作者)
"POST:/api/v1/material-requests/confirm-loss": "produce.qty:handle",
// 数量不符处理(produce.qty 菜单下:补发/退库/调整关闭)
"POST:/api/v1/qty-reports/handle": "produce.qty:handle",
"POST:/api/v1/plc/send-process": "produce.plc:send",
"POST:/api/v1/qty-reports/handle": "produce.qty:handle",
"POST:/api/v1/plc/send-process": "produce.plc:send",
// 报工后自动流转连锁的手动全线扫描(2026-11-11):与工位下发同级操作权限
"POST:/api/v1/plc/flow-scan": "produce.plc:send",
"POST:/api/v1/plc/flow-scan": "produce.plc:send",
"POST:/api/v1/plc/mismatch/override": "produce.plc.mismatch:override",
"POST:/api/v1/torque/dispose": "produce.torque:dispose",
"POST:/api/v1/process-flows": "produce.processflow:add",
"POST:/api/v1/process-flows/status": "produce.processflow:edit",
"DELETE:/api/v1/process-flows/*": "produce.processflow:delete",
"POST:/api/v1/process-flows/upload": "produce.processflow:upload",
"POST:/api/v1/process-steps": "produce.processflow:edit",
"POST:/api/v1/stations": "produce.station:edit",
"DELETE:/api/v1/stations/*": "produce.station:delete",
"POST:/api/v1/torque/dispose": "produce.torque:dispose",
"POST:/api/v1/process-flows": "produce.processflow:add",
"POST:/api/v1/process-flows/status": "produce.processflow:edit",
"DELETE:/api/v1/process-flows/*": "produce.processflow:delete",
"POST:/api/v1/process-flows/upload": "produce.processflow:upload",
"POST:/api/v1/process-steps": "produce.processflow:edit",
"POST:/api/v1/stations": "produce.station:edit",
"DELETE:/api/v1/stations/*": "produce.station:delete",
// 产品工艺(produce.productprocess 菜单下):保存/复制走编辑权限
"POST:/api/v1/product-processes": "produce.productprocess:edit",
"PUT:/api/v1/product-processes": "produce.productprocess:edit",
"POST:/api/v1/product-processes/copy": "produce.productprocess:edit",
"POST:/api/v1/product-processes": "produce.productprocess:edit",
"PUT:/api/v1/product-processes": "produce.productprocess:edit",
"POST:/api/v1/product-processes/copy": "produce.productprocess:edit",
// 基础设置(WMS 地址/需求窗口/外推参数/日志保留)
"PUT:/api/v1/settings": "sys.settings:edit",
// 同步失败台账(2026-11-08):人工重试/标记已处理
@@ -61,12 +61,12 @@ var pathPermMap = map[string]string{
// 列表/预览/下载不设按钮门槛(有菜单权限即可查阅)
// 2026-10-28 生命周期重构:清理工作台(归档页)动作归 sys.attachment:manage;
// /remove 上传人本人撤回、/delete-precheck 只读预检不设权限门槛。
"POST:/api/v1/attachment/delete": "sys.attachment:manage",
"POST:/api/v1/attachment/purge": "sys.attachment:manage",
"POST:/api/v1/attachment/restore": "sys.attachment:manage",
"GET:/api/v1/attachment/orphans": "sys.attachment:manage",
"POST:/api/v1/attachment/orphans/purge": "sys.attachment:manage",
"POST:/api/v1/attachment/purge-deleted": "sys.attachment:manage",
"POST:/api/v1/attachment/delete": "sys.attachment:manage",
"POST:/api/v1/attachment/purge": "sys.attachment:manage",
"POST:/api/v1/attachment/restore": "sys.attachment:manage",
"GET:/api/v1/attachment/orphans": "sys.attachment:manage",
"POST:/api/v1/attachment/orphans/purge": "sys.attachment:manage",
"POST:/api/v1/attachment/purge-deleted": "sys.attachment:manage",
// 账号管理(拆分自原 sys.rbac:user;sys.account 菜单下增/改/删)
"POST:/api/v1/users": "sys.account:add",
"PUT:/api/v1/users": "sys.account:edit",
@@ -80,19 +80,15 @@ var pathPermMap = map[string]string{
"DELETE:/api/v1/permissions/*": "sys.role:perm",
// 工单 SN 前缀(问题5):仅 CREATED 可改,归工单编辑权限
"POST:/api/v1/work-orders/sn-prefix": "produce.workorder:edit",
// 工位模板保存/删除/应用(问题2):写工位绑定,归工位编辑权限
"POST:/api/v1/station-templates": "produce.station:edit",
"POST:/api/v1/station-templates/delete": "produce.station:edit",
"POST:/api/v1/stations/apply-template": "produce.station:edit",
// AGV 两个菜单拆码后各自独立校验:
// produce.agv = AGV管理(三段链确认 / 取消 / 重试);produce.agv.manual = 人工派车(用车生命周期)。
// 两边共用的只读点位与刷新接口(/agv/points、/agv/refresh)不映射,避免互相挡住。
"POST:/api/v1/agv/confirm": "produce.agv",
"POST:/api/v1/agv/cancel": "produce.agv",
"POST:/api/v1/agv/retry": "produce.agv",
"POST:/api/v1/agv/free-dispatch": "produce.agv.manual",
"POST:/api/v1/agv/chain/next": "produce.agv.manual",
"POST:/api/v1/agv/chain/end": "produce.agv.manual",
"POST:/api/v1/agv/confirm": "produce.agv",
"POST:/api/v1/agv/cancel": "produce.agv",
"POST:/api/v1/agv/cancel-by-code": "produce.agv",
"POST:/api/v1/agv/free-dispatch": "produce.agv.manual",
"POST:/api/v1/agv/chain/next": "produce.agv.manual",
"POST:/api/v1/agv/chain/end": "produce.agv.manual",
}
// userHasPerm 校验当前登录用户是否拥有某权限码(SUPER_ADMIN 或 * 放行)。
+66 -12
View File
@@ -4,6 +4,7 @@ import (
"encoding/json"
"net/http"
"strconv"
"strings"
"bj_power_mes/common/httpx"
"bj_power_mes/internal/logic"
@@ -86,25 +87,27 @@ func CancelAgvTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
}
// RetryAgvTaskHandler POST /agv/retry 重试失败/卡住的 AGV 任务(重新向 RCS 下发)。
func RetryAgvTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
// CancelRcsTaskByCodeHandler POST /agv/cancel-by-code —— 按海康 taskCode 取消任意任务
// (含非 MES 下发、遗留死锁在海康后台的任务)。用户诉求:"后台任务我取消不了"。
func CancelRcsTaskByCodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
TaskNo string `json:"taskNo"`
TaskCode string `json:"taskCode"`
Reason string `json:"reason"`
}
if err := httpx.ParseJSON(r, &req); err != nil || req.TaskNo == "" {
httpx.BadRequest(w, "缺少任务号")
if err := httpx.ParseJSON(r, &req); err != nil || strings.TrimSpace(req.TaskCode) == "" {
httpx.BadRequest(w, "缺少海康任务号")
return
}
operator := r.Header.Get("X-Username")
if operator == "" {
operator = "dispatcher"
}
if err := logic.New(svcCtx).RetryAgvTask(r.Context(), req.TaskNo, operator); err != nil {
httpx.Fail(w, 3310, err.Error())
if err := logic.New(svcCtx).CancelRcsTaskByCode(r.Context(), req.TaskCode, req.Reason, operator); err != nil {
httpx.Fail(w, 3320, err.Error())
return
}
httpx.OkMessage(w, "已重试派车", nil)
httpx.OkMessage(w, "已通知海康取消任务", nil)
}
}
@@ -188,24 +191,75 @@ func UpdateAgvPointHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
// AgvCallbackHandler POST /api/spi/agv/agvCallbackService/agvCallback 海康 RCS-Lite SPI 任务状态回调(文档 2.2.1)。
// 回调体含 taskCode(当前任务单号) 与 method(start/outbin/end/cancel),据此驱动任务状态。
// 回调体含 taskCode(当前任务单号) 与 method(车开始动=start / 车从储位开出来=outbin / 到达终点=end / 任务取消=cancel),据此驱动任务状态。
// 注意:RCS 回调不带我方鉴权头,生产环境必须以防火墙/IP 白名单隔离该端点(待与 RCS 方确认鉴权方式)。
// 2026-11-17 修复:响应按文档 2.2.1 回 {code,message,reqCode} 三件套——此前漏回 reqCode 回显(文档要求必填),
// 海康若严格校验响应会判回调失败并反复重试同一条通知。
func AgvCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
// agvCallbackResp 文档 2.2.1 响应三件套;code 用数字 0(海康自家接口也返回数字 0,保持同构)
type agvCallbackResp struct {
Code int `json:"code"`
Message string `json:"message"`
ReqCode string `json:"reqCode"`
}
return func(w http.ResponseWriter, r *http.Request) {
var body struct {
ReqCode string `json:"reqCode"` // 文档选填,响应必须原样回显
TaskCode string `json:"taskCode"`
Method string `json:"method"`
RobotCode string `json:"robotCode"` // 文档 2.2.1 必填 AGV 编号,用于绑定任务与载货台账
}
write := func(code int, msg string) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusOK)
_ = json.NewEncoder(w).Encode(agvCallbackResp{Code: code, Message: msg, ReqCode: body.ReqCode})
}
if err := httpx.ParseJSON(r, &body); err != nil {
httpx.BadRequest(w, "回调报文解析失败")
write(3307, "回调报文解析失败")
return
}
if err := logic.New(svcCtx).ApplyAgvCallback(r.Context(), body.TaskCode, body.Method, body.RobotCode); err != nil {
httpx.Fail(w, 3307, err.Error())
write(3307, err.Error())
return
}
httpx.OkMessage(w, "ok", nil)
write(0, "ok")
}
}
// AgvWarnCallbackHandler POST /api/spi/agv/warnCallbackService/warnCallback
// 海康 RCS-Lite 严重告警推送(文档 §3.1.8,10 秒一次,含急停/安全告警等致停车事件)。
// 响应沿用 SPI 三件套(code/message/reqCode),解析失败也回 200+非零 code,避免海康反复重试。
func AgvWarnCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
type warnResp struct {
Code int `json:"code"`
Message string `json:"message"`
ReqCode string `json:"reqCode"`
}
return func(w http.ResponseWriter, r *http.Request) {
var body struct {
ReqCode string `json:"reqCode"`
AgvCode string `json:"agvCode"`
MainCode string `json:"mainCode"`
MainName string `json:"mainName"`
SubCode string `json:"subCode"`
SubName string `json:"subName"`
BeginTime string `json:"beginTime"`
}
write := func(code int, msg string) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusOK)
_ = json.NewEncoder(w).Encode(warnResp{code, msg, body.ReqCode})
}
if err := httpx.ParseJSON(r, &body); err != nil {
write(3307, "告警报文解析失败")
return
}
if err := logic.New(svcCtx).ApplyAgvWarnCallback(r.Context(), body.AgvCode, body.MainCode,
body.MainName, body.SubCode, body.SubName, body.BeginTime); err != nil {
write(3307, err.Error())
return
}
write(0, "ok")
}
}
@@ -72,6 +72,9 @@ func ConfirmAgvHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
switch req.Action {
case "load_go":
err = lg.ConfirmLoadAndGo(r.Context(), req.TaskNo, req.NextDock, op, req.ConfirmForcePick)
case "line_load_confirm":
// 2026-11-17:工位接驳台车到位后须人工确认才装车回库(车不会自己离开)
err = lg.ConfirmLineDockLoad(r.Context(), req.TaskNo, op)
case "unload_release":
err = lg.ConfirmUnloadRelease(r.Context(), req.TaskNo, op)
case "finish_return":
@@ -37,7 +37,7 @@ func DailyPlanCompareExportHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
f := excelize.NewFile()
const sheet = "日排产历史对比"
_ = f.SetSheetName("Sheet1", sheet)
headers := []interface{}{"工单号", "成品编码", "计划数量", "已完成", "差异", "排产日期", "状态"}
headers := []interface{}{"工单号", "产品编码", "计划数量", "已完成", "差异", "排产日期", "状态"}
_ = f.SetSheetRow(sheet, "A1", &headers)
for i, it := range res.Items {
row := []interface{}{
@@ -33,6 +33,11 @@ func ListMaterialsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
limit = l
}
query := svcCtx.EntClient.Material.Query()
// 2026-11-17:可选 item_type 过滤(1原材料/3成品)。物料清单总账只选原材料,
// 传 itemType=1 避免成品混进下拉;不传则维持原行为(全部物料),兼容工艺页/工单页。
if it, err := strconv.Atoi(q.Get("itemType")); err == nil && it > 0 {
query = query.Where(material.ItemTypeEQ(it))
}
if keyword != "" {
query = query.Where(material.Or(
material.CodeContains(keyword),
@@ -10,7 +10,7 @@ import (
"bj_power_mes/internal/svc"
)
// ListMixTemplatesHandler GET /mix-templates 混产模板列表(圈定哪几个成品可混线生产,带 isActive)。
// ListMixTemplatesHandler GET /mix-templates 混产模板列表(圈定哪几个产品可混线生产,带 isActive)。
func ListMixTemplatesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
rows, err := logic.New(svcCtx).ListMixTemplates(r.Context())
@@ -22,7 +22,7 @@ func ListMixTemplatesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
}
// SaveMixTemplateHandler POST /mix-templates/save 新增/编辑混产模板(即「保存当前绑定为模板」)。
// SaveMixTemplateHandler POST /mix-templates/save 新增/编辑混产模板(圈定哪几个产品可混线生产)。
func SaveMixTemplateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
@@ -29,7 +29,7 @@ func MaterialDemandInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
}
// ProducibleSupportHandler 用户态接口:MES「排产支撑」视图。
// 返回逐成品可生产套数 + 整体还能满产多少天/支撑到哪天/最先告罄短板物料。
// 返回逐产品可生产套数 + 整体还能满产多少天/支撑到哪天/最先告罄短板物料。
func ProducibleSupportHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
res, err := logic.New(svcCtx).ComputeProducibleSupport(r.Context())
@@ -11,11 +11,11 @@ import (
"bj_power_mes/internal/svc"
)
// ============ 成品 BOM 总账 / 分账(2026-11-13 拍板「总分制」) ============
// 总账挂在成品下、分账挂在产品工艺下;P10:物料清单与工艺配置分离、各自独立保存。
// ============ 产品 BOM 总账 / 分账(2026-11-13 拍板「总分制」) ============
// 总账挂在产品下、分账挂在产品工艺下;P10:物料清单与工艺配置分离、各自独立保存。
// 硬校验:Σ分账 = 总账、分账物料是总账子集、分账工序在工艺路线内;改总账会回校已有分账。
// ListProductBOMHandler GET /product-boms?productCode= 读取某成品的总账。
// ListProductBOMHandler GET /product-boms?productCode= 读取某产品的总账。
func ListProductBOMHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
code := strings.TrimSpace(r.URL.Query().Get("productCode"))
@@ -36,7 +36,7 @@ func ListProductBOMHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
func SaveProductBOMHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
ProductCode string `json:"productCode"`
ProductCode string `json:"productCode"`
Rows []logic.BOMRow `json:"rows"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
@@ -77,7 +77,7 @@ func ListProcessAllocationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
func SaveProcessAllocationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
ProductProcessId int `json:"productProcessId"`
ProductProcessId int `json:"productProcessId"`
Rows []logic.BOMAllocation `json:"rows"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
@@ -99,3 +99,47 @@ func SaveProcessAllocationsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
httpx.Ok(w, map[string]any{"ok": true, "rows": len(req.Rows)})
}
}
// PreviewReallocateHandler POST /product-boms/reallocate-preview 一键重分配预览(不改库)。
func PreviewReallocateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
ProductCode string `json:"productCode"`
Rows []logic.BOMRow `json:"rows"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
httpx.BadRequest(w, "参数错误: "+err.Error())
return
}
res, err := logic.New(svcCtx).PreviewReallocate(r.Context(), req.ProductCode, req.Rows)
if err != nil {
httpx.Fail(w, 400, err.Error())
return
}
httpx.Ok(w, res)
}
}
// ApplyReallocateHandler POST /product-boms/reallocate 按确认方案落库(总账+各工艺分账,跳过锁定工艺)。
func ApplyReallocateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
ProductCode string `json:"productCode"`
Rows []logic.BOMRow `json:"rows"`
Plans []logic.ReallocApplyPlan `json:"plans"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
httpx.BadRequest(w, "参数错误: "+err.Error())
return
}
op := r.Header.Get("X-Username")
if op == "" {
op = "system"
}
if err := logic.New(svcCtx).ApplyReallocate(r.Context(), req.ProductCode, req.Rows, req.Plans, op); err != nil {
httpx.Fail(w, 400, err.Error())
return
}
httpx.Ok(w, map[string]any{"ok": true})
}
}
@@ -361,7 +361,7 @@ func WorkpieceLookupInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
// FinishedLookupInternalHandler GET /api/internal/finished/lookup?sn=
// 2026-11-13 拍板:WMS「成品入库」扫 SN 自动带出工单;图号/产品名称/产品状态/归属全部由 MES 透传,
// WMS 只读展示、禁止库管手选。MES 侧没有「产品型号/SN 档案字段」这类臆造概念——SN 属于工件(workpiece.sn),
// 成品档案只存名称与系统生成的唯一码(图号),本接口把两者关联起来。
// 产品档案只存名称与系统生成的唯一码(图号),本接口把两者关联起来。
// 仅 WMS 手工成品入库调用;物料入库(/api/inbound/*)不依赖 MES,故 MES 宕机不影响物料入库。
func FinishedLookupInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
@@ -13,7 +13,7 @@ import (
// ShortageOnBehalfInternalHandler POST /api/internal/shortage/on-behalf
// WMS 库管代工位提交补料申请:复用现有补料申请 logic.CreateShortage,只生成 PENDING 待审批单,
// 不审批、不调增叫料池额度——审批仍由主管在 MES「补料审批」完成,WMS 不绕过审批。
// 请求结构与 /api/v1/shortages 同款;shortage_requests 无「产品工号」列,产品工号由 WMS 附在补料原因里带过来。
// 请求结构与 /api/v1/shortages 同款;shortage_requests 无「工单号」列,工单号由 WMS 附在补料原因里带过来。
func ShortageOnBehalfInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
@@ -1,97 +0,0 @@
package production
import (
"net/http"
"bj_power_mes/common/httpx"
"bj_power_mes/internal/logic"
"bj_power_mes/internal/svc"
)
// ListStationTemplatesHandler GET /station-templates 工位绑定模板列表
func ListStationTemplatesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
list, err := logic.New(svcCtx).ListStationTemplates(r.Context())
if err != nil {
httpx.Fail(w, 3501, err.Error())
return
}
httpx.Ok(w, map[string]any{"list": list})
}
}
// SaveStationTemplateHandler POST /station-templates 保存模板(同名覆盖,最多20条)
func SaveStationTemplateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req logic.StationTemplate
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
return
}
if err := logic.New(svcCtx).SaveStationTemplate(r.Context(), req, operator(r, "")); err != nil {
httpx.Fail(w, 3502, err.Error())
return
}
httpx.Ok(w, map[string]any{"ok": true})
}
}
// DeleteStationTemplateHandler POST /station-templates/delete 删除模板
func DeleteStationTemplateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
Name string `json:"name"`
}
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
return
}
if err := logic.New(svcCtx).DeleteStationTemplate(r.Context(), req.Name, operator(r, "")); err != nil {
httpx.Fail(w, 3503, err.Error())
return
}
httpx.Ok(w, map[string]any{"ok": true})
}
}
// PrecheckStationTemplateHandler POST /stations/apply-template/precheck 只读预检冲突清单
func PrecheckStationTemplateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
Name string `json:"name"`
TargetProductCode string `json:"targetProductCode"`
}
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
return
}
res, err := logic.New(svcCtx).PrecheckStationTemplate(r.Context(), req.Name, req.TargetProductCode)
if err != nil {
httpx.Fail(w, 3503, err.Error())
return
}
httpx.Ok(w, res)
}
}
// ApplyStationTemplateHandler POST /stations/apply-template 套用模板
func ApplyStationTemplateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
Name string `json:"name"`
TargetProductCode string `json:"targetProductCode"`
Confirmed []string `json:"confirmed"` // 清线确认单逐项打勾/人工放行
}
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
return
}
res, err := logic.New(svcCtx).ApplyStationTemplateWithConfirm(r.Context(),
req.Name, req.TargetProductCode, operator(r, ""), req.Confirmed)
if err != nil {
httpx.Fail(w, 3504, err.Error())
return
}
httpx.Ok(w, res)
}
}
@@ -28,6 +28,19 @@ func ListProductProcessesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
}
// ProductProcessOverviewHandler GET /product-processes/overview?productCode=
// 产品档案工艺抽屉:按产品聚合当前启用 + 历史版本 + 每套工艺关联的工单号。
func ProductProcessOverviewHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
data, err := logic.New(svcCtx).ProductProcessOverview(r.Context(), r.URL.Query().Get("productCode"))
if err != nil {
httpx.Fail(w, 2233, err.Error())
return
}
httpx.Ok(w, data)
}
}
// DeriveProductProcessHandler GET /product-processes/derive?productCode=&id=
// 建单自动推导:每道工艺带出全部启用的绑定工位,返回 {productProcessId,name,items,combination,warnings}
func DeriveProductProcessHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
@@ -459,7 +459,7 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
{Method: http.MethodGet, Path: "/agv/tasks", Handler: production.ListAgvTasksHandler(serverCtx)},
{Method: http.MethodPost, Path: "/agv/refresh", Handler: production.RefreshAgvTasksHandler(serverCtx)},
{Method: http.MethodPost, Path: "/agv/cancel", Handler: production.CancelAgvTaskHandler(serverCtx)},
{Method: http.MethodPost, Path: "/agv/retry", Handler: production.RetryAgvTaskHandler(serverCtx)},
{Method: http.MethodPost, Path: "/agv/cancel-by-code", Handler: production.CancelRcsTaskByCodeHandler(serverCtx)},
// 手动多段链(2026-11-06 拍板):逐节点人工推进,全程锁同一台车
{Method: http.MethodPost, Path: "/agv/chain/next", Handler: production.AgvChainNextHandler(serverCtx)},
{Method: http.MethodPost, Path: "/agv/chain/end", Handler: production.AgvChainEndHandler(serverCtx)},
@@ -562,6 +562,7 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
// ---------- 产品工艺(2026-10-09 定稿:产品级工艺定义,有序工艺集合不绑工位;建单时推导工位) ----------
// derive 需注册在 :id 语义之外(无 GET /:id 路由,无冲突)
{Method: http.MethodGet, Path: "/product-processes", Handler: ListProductProcessesHandler(serverCtx)},
{Method: http.MethodGet, Path: "/product-processes/overview", Handler: ProductProcessOverviewHandler(serverCtx)},
{Method: http.MethodGet, Path: "/product-processes/derive", Handler: DeriveProductProcessHandler(serverCtx)},
{Method: http.MethodGet, Path: "/product-processes/card", Handler: ProductProcessCardHandler(serverCtx)},
{Method: http.MethodPost, Path: "/product-processes", Handler: SaveProductProcessHandler(serverCtx)},
@@ -569,12 +570,15 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
{Method: http.MethodPost, Path: "/product-processes/status", Handler: SetProductProcessStatusHandler(serverCtx)},
{Method: http.MethodDelete, Path: "/product-processes/:id", Handler: DeleteProductProcessHandler(serverCtx)},
{Method: http.MethodPost, Path: "/product-processes/copy", Handler: CopyProductProcessHandler(serverCtx)},
// 2026-11-13 拍板「总分制」:成品BOM总账 + 产品工艺把总账物料分配到各工序(分账)
// 2026-11-13 拍板「总分制」:产品BOM总账 + 产品工艺把总账物料分配到各工序(分账)
{Method: http.MethodGet, Path: "/product-boms", Handler: production.ListProductBOMHandler(serverCtx)},
{Method: http.MethodPost, Path: "/product-boms/save", Handler: production.SaveProductBOMHandler(serverCtx)},
// 2026-11-17 透明化:一键按新总账重新分配分账(预览可改 + 人工确认,杜绝黑盒)
{Method: http.MethodPost, Path: "/product-boms/reallocate-preview", Handler: production.PreviewReallocateHandler(serverCtx)},
{Method: http.MethodPost, Path: "/product-boms/reallocate", Handler: production.ApplyReallocateHandler(serverCtx)},
{Method: http.MethodGet, Path: "/product-process-materials", Handler: production.ListProcessAllocationsHandler(serverCtx)},
{Method: http.MethodPost, Path: "/product-process-materials/save", Handler: production.SaveProcessAllocationsHandler(serverCtx)},
// 2026-11-13 拍板:混产模板(多工单多成品混线)+ 模板外新产品的清线门禁
// 2026-11-13 拍板:混产模板(多工单多产品混线)+ 模板外新产品的清线门禁
{Method: http.MethodGet, Path: "/mix-templates", Handler: production.ListMixTemplatesHandler(serverCtx)},
{Method: http.MethodPost, Path: "/mix-templates/save", Handler: production.SaveMixTemplateHandler(serverCtx)},
{Method: http.MethodPost, Path: "/mix-templates/active", Handler: production.SetActiveMixTemplateHandler(serverCtx)},
@@ -634,12 +638,6 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
{Method: http.MethodPost, Path: "/sync-failures/retry", Handler: SyncFailureRetryHandler(serverCtx)},
{Method: http.MethodPost, Path: "/sync-failures/ignore", Handler: SyncFailureIgnoreHandler(serverCtx)},
// ---------- 工位模板(问题2):sys_config 一模板一键,apply 收集式跳过冲突工位 ----------
{Method: http.MethodGet, Path: "/station-templates", Handler: production.ListStationTemplatesHandler(serverCtx)},
{Method: http.MethodPost, Path: "/station-templates", Handler: production.SaveStationTemplateHandler(serverCtx)},
{Method: http.MethodPost, Path: "/station-templates/delete", Handler: production.DeleteStationTemplateHandler(serverCtx)},
{Method: http.MethodPost, Path: "/stations/apply-template", Handler: production.ApplyStationTemplateHandler(serverCtx)},
{Method: http.MethodPost, Path: "/stations/apply-template/precheck", Handler: production.PrecheckStationTemplateHandler(serverCtx)},
// ---------- 日排产历史对比(问题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)},
@@ -679,6 +677,11 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/spi/agv/agvCallbackService/agvCallback", Handler: production.AgvCallbackHandler(serverCtx),
})
// 海康严重告警推送(文档 §3.1.8 warnCallback,急停/安全告警等致停车事件,10 秒一次)。
// RCS 后台需另配该告警回调地址;MES 落预警中心(30 分钟去重)+ event_log 留痕。
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/spi/agv/warnCallbackService/warnCallback", Handler: production.AgvWarnCallbackHandler(serverCtx),
})
// ---------- 公开文件访问(免 JWT) ----------
// <img>/el-image 发起的图片请求无法携带 Authorization 头,走 JWT 组会 401