feat: 移除工位模板、AGV 链路增强与产品BOM/混产模板完善
- 移除工位模板体系(handler/logic 全删),同步路由与 seed - AGV 链路增强:点位锁、车辆状态、退料派车调整,新增海康 RCS Postman 调试集合 - MES 产品BOM/混产模板完善:新增 ProductBOMDialog 组件,调整 handler/logic;日排产达成对比调整 - WMS 业务完善:出入库、检验、备料、退料、成品入库、缺料代报等 handler 与前端页面调整 - 前端通用:双端新增 RemotePageSelect 组件,统一 nextStep 规则/帮助文档/布局/请求拦截 - 文档:更新产线API/案例/部署手册/问题记录等
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user