feat: 新增收集式校验错误弹窗及工位报警语音播报
新增 ErrorListDialog 组件用于统一展示结构化校验错误信息,实现报错一次收全;新增工位报警语音播报功能,通过浏览器 SpeechSynthesis 播放本工位相关报警;调整物料类别及序列号字段文案,移除「其他」类别;新增工单实际开始字段及采集方式配置;优化 AGV 及 PlcSend 页签刷新逻辑;新增看板物料追溯及工位报警接口;删除 PLC 强制写 M 位及相关测试代码;同步数据库字段注释及补丁。
This commit is contained in:
@@ -109,6 +109,23 @@ func ListAlertsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// StationAlertsInternalHandler GET /api/internal/station/alerts?stationNo=&minutes=
|
||||
// 工位终端「本工位相关报警」查询(谁受影响谁播报,2026-10-20):工位终端后端代理调用,
|
||||
// X-API-TOKEN 保护。返回最近 minutes 分钟内 UNREAD 且命中「工位N」的报警列表。
|
||||
func StationAlertsInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
stationNo := atoiDefault(q.Get("stationNo"), 0)
|
||||
minutes := atoiDefault(q.Get("minutes"), 10)
|
||||
list, err := logic.New(svcCtx).StationAlerts(r.Context(), stationNo, minutes)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3308, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, list)
|
||||
}
|
||||
}
|
||||
|
||||
// MarkAlertReadHandler POST /alert/read 标记已读 {id}
|
||||
func MarkAlertReadHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -91,34 +91,17 @@ func PlcMonitorManualWriteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// PlcMonitorForceBitHandler POST /plc/monitor/force-bit 强制置/复位单个 M 位(危险操作,需二次确认 + 操作日志)。
|
||||
func PlcMonitorForceBitHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
// PlcMonitorClearInTransitHandler POST /plc/monitor/clear-in-transit 强制清零在途指令(仅 §4.4 路由区 MW=0;越界拒绝)。
|
||||
func PlcMonitorClearInTransitHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req logic.ForceBitReq
|
||||
var req logic.ClearInTransitReq
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
res, err := logic.New(svcCtx).PlcMonitorForceBit(r.Context(), req, operator(r, ""))
|
||||
res, err := logic.New(svcCtx).PlcMonitorClearInTransit(r.Context(), req, operator(r, ""))
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3306, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, res)
|
||||
}
|
||||
}
|
||||
|
||||
// PlcMonitorWriteMwHandler POST /plc/monitor/write-mw 强制写 MW(危险操作,需二次确认 + 白名单校验 + 操作日志)。
|
||||
func PlcMonitorWriteMwHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req logic.ForceMWReq
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
res, err := logic.New(svcCtx).PlcMonitorWriteMw(r.Context(), req, operator(r, ""))
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3307, err.Error())
|
||||
httpx.Fail(w, 3312, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, res)
|
||||
|
||||
@@ -2,12 +2,14 @@ package production
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"bj_power_mes/common/httpx"
|
||||
"bj_power_mes/internal/logic"
|
||||
"bj_power_mes/internal/svc"
|
||||
"github.com/xuri/excelize/v2"
|
||||
)
|
||||
|
||||
// ---------- PLC 工序下发 ----------
|
||||
@@ -84,7 +86,7 @@ func TorqueRecordsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
q := r.URL.Query()
|
||||
from := parseTorqueTime(q.Get("from"), false)
|
||||
to := parseTorqueTime(q.Get("to"), true)
|
||||
data, err := logic.New(svcCtx).ListTorqueRecords(r.Context(), q.Get("sn"), q.Get("workOrderNo"), q.Get("stationNo"), from, to)
|
||||
data, err := logic.New(svcCtx).ListTorqueRecords(r.Context(), q.Get("sn"), q.Get("workOrderNo"), q.Get("stationNo"), q.Get("operator"), from, to)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3204, err.Error())
|
||||
return
|
||||
@@ -96,6 +98,42 @@ func TorqueRecordsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
// TorqueDispositionHandler 拧紧不合格人工处置(B6 最小闭环,质检/班组长确认放行):
|
||||
// 清标记 + 写 event_log(谁/何时/原因) + 置对应 torque_ng 预警 resolved。
|
||||
// 后端权限码 produce.torque:dispose(perm.go pathPermMap 兜底校验,仅 INSPECTOR/SUPER_ADMIN 持有)。
|
||||
// TorqueExportHandler GET /torque/export 拧紧数据独立导出(复用 excelize 范式)。
|
||||
// 与 /torque/records 同口径:支持 sn/workOrderNo/stationNo/operator/from/to 复合筛选。
|
||||
func TorqueExportHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
from := parseTorqueTime(q.Get("from"), false)
|
||||
to := parseTorqueTime(q.Get("to"), true)
|
||||
recs, err := logic.New(svcCtx).ListTorqueRecords(r.Context(), q.Get("sn"), q.Get("workOrderNo"), q.Get("stationNo"), q.Get("operator"), from, to)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3204, err.Error())
|
||||
return
|
||||
}
|
||||
f := excelize.NewFile()
|
||||
sheet := "拧紧数据"
|
||||
f.SetSheetName("Sheet1", sheet)
|
||||
headers := []string{"工单号", "SN", "工位", "螺丝号", "扭矩", "角度", "结果", "操作人", "时间"}
|
||||
for c, h := range headers {
|
||||
cell, _ := excelize.CoordinatesToCellName(c+1, 1)
|
||||
_ = f.SetCellValue(sheet, cell, h)
|
||||
}
|
||||
for i, rec := range recs {
|
||||
row := []any{
|
||||
rec.WorkOrderNo, rec.Sn, rec.StationNo, rec.ScrewNo, rec.Strain, rec.Angle, rec.Result, rec.Operator,
|
||||
rec.Time.Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
for c, v := range row {
|
||||
cell, _ := excelize.CoordinatesToCellName(c+1, i+2)
|
||||
_ = f.SetCellValue(sheet, cell, v)
|
||||
}
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
w.Header().Set("Content-Disposition", "attachment; filename*=UTF-8''"+url.PathEscape("拧紧数据.xlsx"))
|
||||
_, _ = f.WriteTo(w)
|
||||
}
|
||||
}
|
||||
|
||||
func TorqueDispositionHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req logic.TorqueDisposeReq
|
||||
|
||||
@@ -200,7 +200,7 @@ func WorkpieceReportInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
|
||||
func WorkpieceTraceInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
sn := r.URL.Query().Get("sn")
|
||||
trace, err := logic.New(svcCtx).Trace(r.Context(), sn)
|
||||
trace, err := logic.New(svcCtx).Trace(r.Context(), sn, r.URL.Query().Get("operator"))
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2003, err.Error())
|
||||
return
|
||||
@@ -335,3 +335,17 @@ func DashboardSnapshotInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFu
|
||||
httpx.Ok(w, data)
|
||||
}
|
||||
}
|
||||
|
||||
// DashboardMaterialQueryHandler 看板物料追溯查询入口(C7):转发 WMS 物料档案 + 库存。
|
||||
func DashboardMaterialQueryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
code := r.URL.Query().Get("code")
|
||||
batch := r.URL.Query().Get("batch")
|
||||
data, err := logic.New(svcCtx).DashboardMaterialQuery(r.Context(), code, batch)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2009, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package production
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"bj_power_mes/internal/svc"
|
||||
)
|
||||
|
||||
// StationAlertsStreamHandler GET /api/internal/station/alerts/stream(X-API-TOKEN 保护)
|
||||
// 工位终端「本工位相关报警」SSE 推送端点(谁受影响谁播报,2026-10-20 轮询改事件驱动):
|
||||
// 复用全局 SSE Hub(与看板快照同一广播中心),仅下发 station.alert 事件类型,其余事件(dashboard.*)不透传;
|
||||
// 每 15 秒写一行 SSE 注释心跳(": ping")防中间设备掐空闲长连接;客户端断开由 r.Context().Done() 感知。
|
||||
// 报警 JSON 全量下发、按「工位N」过滤由终端后端做(Hub 广播语义,唯一消费者=终端后端,无需 MES 逐连接过滤)。
|
||||
func StationAlertsStreamHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
fl, ok := w.(http.Flusher)
|
||||
if !ok {
|
||||
http.Error(w, "streaming unsupported", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/event-stream")
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
w.Header().Set("Connection", "keep-alive")
|
||||
ch := svcCtx.SSE.Add()
|
||||
defer svcCtx.SSE.Remove(ch)
|
||||
fl.Flush() // 立即冲刷响应头,客户端 EventSource 尽早进入 open 态
|
||||
|
||||
ticker := time.NewTicker(15 * time.Second)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case m := <-ch:
|
||||
if m.Type != "station.alert" {
|
||||
continue
|
||||
}
|
||||
if _, err := fmt.Fprintf(w, "event: %s\ndata: %s\n\n", m.Type, m.Data); err != nil {
|
||||
return
|
||||
}
|
||||
fl.Flush()
|
||||
case <-ticker.C:
|
||||
if _, err := fmt.Fprint(w, ": ping\n\n"); err != nil {
|
||||
return
|
||||
}
|
||||
fl.Flush()
|
||||
case <-r.Context().Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package production
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -165,11 +166,12 @@ func CreateWorkOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
// 组合顺序硬校验已并入 logic 收集式校验(2026-10-20):与归属/组合/来源工艺等问题一次列全返回
|
||||
if err := logic.New(svcCtx).CreateWorkOrder(r.Context(), req, operator(r, "")); err != nil {
|
||||
httpx.Fail(w, 3005, err.Error())
|
||||
httpx.FailErr(w, err)
|
||||
return
|
||||
}
|
||||
// 产品工艺偏差警告(仅提示不阻断):覆盖/顺序/个数与来源产品工艺不一致时返回 warnings
|
||||
// 产品工艺偏差柔性警告(仅覆盖/个数;顺序已硬拦截不会到这里)
|
||||
httpx.Ok(w, map[string]any{"warnings": logic.New(svcCtx).ComboDeviationWarnings(r.Context(), req.ProductProcessId, req.FlowCombination)})
|
||||
}
|
||||
}
|
||||
@@ -181,23 +183,31 @@ func UpdateWorkOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
// 组合顺序硬校验已并入 logic 收集式校验(2026-10-20):与归属/组合/来源工艺等问题一次列全返回
|
||||
if err := logic.New(svcCtx).UpdateWorkOrder(r.Context(), req, operator(r, "")); err != nil {
|
||||
httpx.Fail(w, 3006, err.Error())
|
||||
httpx.FailErr(w, err)
|
||||
return
|
||||
}
|
||||
// 产品工艺偏差警告(仅提示不阻断)
|
||||
// 产品工艺偏差柔性警告(仅覆盖/个数;顺序已硬拦截不会到这里)
|
||||
httpx.Ok(w, map[string]any{"warnings": logic.New(svcCtx).ComboDeviationWarnings(r.Context(), req.ProductProcessId, req.FlowCombination)})
|
||||
}
|
||||
}
|
||||
|
||||
func GetWorkOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
data, err := logic.New(svcCtx).GetWorkOrder(r.Context(), pathID(r))
|
||||
wo, err := logic.New(svcCtx).GetWorkOrder(r.Context(), pathID(r))
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3007, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, data)
|
||||
// 增补排产统计字段(2026-10-20):已排产量=ΣplanQty、剩余未排产量=工单总数−已排产量
|
||||
scheduled, _ := logic.New(svcCtx).ScheduledQtyOf(r.Context(), wo.WorkOrderNo)
|
||||
b, _ := json.Marshal(wo)
|
||||
m := map[string]any{}
|
||||
_ = json.Unmarshal(b, &m)
|
||||
m["scheduledQty"] = scheduled
|
||||
m["remainQty"] = wo.Quantity - scheduled
|
||||
httpx.Ok(w, m)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,7 +277,8 @@ func AutoSchedulePreviewHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
preview, err := logic.New(svcCtx).AutoSchedulePreview(r.Context(), req)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3011, err.Error())
|
||||
// 收集式校验(code=3015)经 FailErr 结构化输出,前端弹 ErrorListDialog 一次列全
|
||||
httpx.FailErr(w, err)
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, preview)
|
||||
@@ -283,7 +294,8 @@ func AutoScheduleApplyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
if err := logic.New(svcCtx).AutoScheduleApply(r.Context(), req, operator(r, "")); err != nil {
|
||||
httpx.Fail(w, 3011, err.Error())
|
||||
// 收集式校验(code=3015)经 FailErr 结构化输出,前端弹 ErrorListDialog 一次列全
|
||||
httpx.FailErr(w, err)
|
||||
return
|
||||
}
|
||||
httpx.OkMessage(w, "排产已确认(待人工启用)", nil)
|
||||
@@ -300,7 +312,8 @@ func SaveDailyPlanHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
if err := logic.New(svcCtx).SaveDailyPlan(r.Context(), req, operator(r, "")); err != nil {
|
||||
httpx.Fail(w, 3008, err.Error())
|
||||
// 收集式校验(code=3015)经 FailErr 结构化输出,前端弹 ErrorListDialog 一次列全
|
||||
httpx.FailErr(w, err)
|
||||
return
|
||||
}
|
||||
httpx.OkMessage(w, "保存成功", nil)
|
||||
@@ -347,6 +360,20 @@ func ListUnplannedWorkOrdersHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
|
||||
}
|
||||
}
|
||||
|
||||
// ForScheduleWorkOrdersHandler GET /work-orders/for-schedule 日排产工单号下拉过滤:
|
||||
// 仅返回"剩余可排 > 0"的工单(含部分排产),并附 总量/已排量/剩余可排。
|
||||
func ForScheduleWorkOrdersHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
kw := r.URL.Query().Get("keyword")
|
||||
data, err := logic.New(svcCtx).ListWorkOrdersForSchedule(r.Context(), kw)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3011, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, data)
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteDailyPlanHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
id, _ := strconv.Atoi(strings.TrimPrefix(r.URL.Path, "/api/v1/daily-plans/"))
|
||||
@@ -389,3 +416,38 @@ func InProcessHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.Ok(w, map[string]any{"list": data})
|
||||
}
|
||||
}
|
||||
|
||||
// ForceCompletePreviewHandler GET /work-orders/:id/force-complete/preview
|
||||
// 强制完工核对单(只读预览):剩余未完工/未完成排产/在途叫料/在制工件 四项清单。
|
||||
func ForceCompletePreviewHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
rep, err := logic.New(svcCtx).ForceCompletePreview(r.Context(), pathID(r))
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3013, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, rep)
|
||||
}
|
||||
}
|
||||
|
||||
// ForceCompleteHandler POST /work-orders/force-complete {id, reason}
|
||||
// 强制完工(方案 A,2026-10-20 拍板):在制工件>0 拒绝;未完成排产自动 CANCELLED;
|
||||
// PENDING 叫料自动取消;SHIPPED 列出人工处理;原因必填;落 event_log 四项快照。
|
||||
func ForceCompleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Id int `json:"id"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
rep, err := logic.New(svcCtx).ForceComplete(r.Context(), req.Id, req.Reason, operator(r, ""))
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3014, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, rep)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,18 +57,42 @@ func ListWorkpiecesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
limit = n
|
||||
}
|
||||
}
|
||||
data, err := logic.New(svcCtx).ListWorkpieces(r.Context(), q.Get("sn"), q.Get("orderNo"), limit)
|
||||
// page>0:后端 SQL 分页模式(工单详情 SN 列表用),按 SN 升序返回 {list,total,page,pageSize}
|
||||
page := 0
|
||||
if v := q.Get("page"); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil && n > 0 {
|
||||
page = n
|
||||
}
|
||||
}
|
||||
pageSize := 0
|
||||
if v := q.Get("pageSize"); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil && n > 0 {
|
||||
pageSize = n
|
||||
}
|
||||
}
|
||||
if page > 0 {
|
||||
rows, total, err := logic.New(svcCtx).ListWorkpieces(r.Context(),
|
||||
q.Get("sn"), q.Get("orderNo"), q.Get("status"), limit, page, pageSize)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3304, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"list": rows, "total": total, "page": page, "pageSize": pageSize})
|
||||
return
|
||||
}
|
||||
data, total, err := logic.New(svcCtx).ListWorkpieces(r.Context(), q.Get("sn"), q.Get("orderNo"), q.Get("status"), limit, 0, 0)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3304, err.Error())
|
||||
return
|
||||
}
|
||||
_ = total // 旧下拉/追溯调用方不分页,total 不外发
|
||||
httpx.Ok(w, data)
|
||||
}
|
||||
}
|
||||
|
||||
func TraceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
data, err := logic.New(svcCtx).Trace(r.Context(), r.URL.Query().Get("sn"))
|
||||
data, err := logic.New(svcCtx).Trace(r.Context(), r.URL.Query().Get("sn"), r.URL.Query().Get("operator"))
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3305, err.Error())
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user