Files
bj_power/bj_power_workstation/internal/handler/report.go
T
SunYF a2afd2f6dc feat: 五项目业务实现并对接完成
- MES(B): 工单/BOM/备料/工序字典/PLC下发/拧紧/扫码报工/半成品/AGV/追溯逻辑,WMS与海康RCS客户端,看板Redis缓存API(概览/设备/进度/报警/趋势)+SSE
- WMS(C): JWT滑动续签、Excel导入、盘点、内部API、种子数据、独立Postgres配置
- WMS客户端(E): Go网关8891反向代理+内嵌Vue3十页
- 工位终端(D): SQLite本地缓存+模拟拧紧源+内嵌Vue3页面
- Dashboard(A): 看板数据改接MES内部缓存API,SSE实时刷新+vite代理
- 清理各项目球形磨遗留代码,新增部署手册.md
2026-08-27 19:50:57 +08:00

105 lines
3.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package handler
import (
"encoding/json"
"net/http"
"bj_power_workstation/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
// processDoneHandler POST /api/report/process-done
// {dockCode, orderNo, sn, processCode, operator}
// 流程:先冲刷一轮积压 → 实时报 MES /api/internal/station/done
// MES 不可达则写入 report_queue(kind=process_done) 并返回 data.queued=true(离线缓存稍后自动重传)。
func processDoneHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
DockCode string `json:"dockCode"`
OrderNo string `json:"orderNo"`
Sn string `json:"sn"`
ProcessCode string `json:"processCode"`
Operator string `json:"operator"`
}
if err := parseJSON(r, &req); err != nil {
fail(w, http.StatusBadRequest, "参数错误")
return
}
if req.DockCode == "" {
fail(w, http.StatusBadRequest, "缺少 dockCode")
return
}
// 先尽力冲刷历史积压,失败不影响本次上报
ctx.Syncer.RunOnce(r.Context())
body := map[string]any{
"dockCode": req.DockCode,
"orderNo": req.OrderNo,
"sn": req.Sn,
"processCode": req.ProcessCode,
"operator": req.Operator,
}
payloadBytes, _ := json.Marshal(body)
if _, _, err := ctx.Mes.Post("/api/internal/station/done", json.RawMessage(payloadBytes)); err != nil {
if qerr := ctx.Store.InsertQueueItem("process_done", string(payloadBytes)); qerr != nil {
fail(w, http.StatusInternalServerError, "上报失败且离线队列写入失败:"+qerr.Error())
return
}
logx.Errorf("工序完成上报失败已离线排队: %v", err)
ok(w, map[string]any{"queued": true})
return
}
ok(w, map[string]any{"queued": false})
}
}
// tempStoreHandler POST /api/report/temp-store
// {dockCode, orderNo, sn, operator} → 调 MES /api/internal/station/checkin
// body 附带 type=temp_store;不可达时以同样 payload 写入 report_queue(kind=temp_store)。
func tempStoreHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
DockCode string `json:"dockCode"`
OrderNo string `json:"orderNo"`
Sn string `json:"sn"`
Operator string `json:"operator"`
}
if err := parseJSON(r, &req); err != nil {
fail(w, http.StatusBadRequest, "参数错误")
return
}
if req.DockCode == "" {
fail(w, http.StatusBadRequest, "缺少 dockCode")
return
}
// 先尽力冲刷历史积压,失败不影响本次上报
ctx.Syncer.RunOnce(r.Context())
body := map[string]any{
"type": "temp_store", // checkin 类型标识:暂存退库(随 payload 一并透传重传)
"dockCode": req.DockCode,
"orderNo": req.OrderNo,
"sn": req.Sn,
"operator": req.Operator,
}
payloadBytes, _ := json.Marshal(body)
if _, _, err := ctx.Mes.Post("/api/internal/station/checkin", json.RawMessage(payloadBytes)); err != nil {
if qerr := ctx.Store.InsertQueueItem("temp_store", string(payloadBytes)); qerr != nil {
fail(w, http.StatusInternalServerError, "上报失败且离线队列写入失败:"+qerr.Error())
return
}
logx.Errorf("暂存退库上报失败已离线排队: %v", err)
ok(w, map[string]any{"queued": true})
return
}
ok(w, map[string]any{"queued": false})
}
}