feat: 新增收集式校验错误弹窗及工位报警语音播报
新增 ErrorListDialog 组件用于统一展示结构化校验错误信息,实现报错一次收全;新增工位报警语音播报功能,通过浏览器 SpeechSynthesis 播放本工位相关报警;调整物料类别及序列号字段文案,移除「其他」类别;新增工单实际开始字段及采集方式配置;优化 AGV 及 PlcSend 页签刷新逻辑;新增看板物料追溯及工位报警接口;删除 PLC 强制写 M 位及相关测试代码;同步数据库字段注释及补丁。
This commit is contained in:
@@ -34,6 +34,10 @@ var pathPermMap = map[string]string{
|
||||
"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",
|
||||
// 基础设置(WMS 地址/需求窗口/外推参数/日志保留)
|
||||
"PUT:/api/v1/settings": "sys.settings:edit",
|
||||
// 过程巡检汇总生成《工序间检验记录》(巡检终端操作域)
|
||||
|
||||
@@ -56,6 +56,7 @@ type workOrderCard struct {
|
||||
PlanEnd string `json:"planEnd"`
|
||||
ActualStart string `json:"actualStart"`
|
||||
ActualFinish string `json:"actualFinish"`
|
||||
CompletedAt string `json:"completedAt"`
|
||||
ProcessSeqNote string `json:"processSeqNote"`
|
||||
GeneratedAt string `json:"generatedAt"`
|
||||
ProcessSteps []woProcessStep `json:"processSteps"`
|
||||
@@ -68,6 +69,7 @@ type workOrderCard struct {
|
||||
type woProcessStep struct {
|
||||
Seq int `json:"seq"`
|
||||
ProcessName string `json:"processName"`
|
||||
CollectCN string `json:"collectCN"`
|
||||
StationNo int `json:"stationNo"`
|
||||
PlanHours string `json:"planHours"`
|
||||
ActualStart string `json:"actualStart"`
|
||||
@@ -337,6 +339,9 @@ func buildWorkOrderCard(ctx context.Context, svcCtx *svc.ServiceContext, workOrd
|
||||
if wo.PlanEnd != nil {
|
||||
card.PlanEnd = wo.PlanEnd.Format("2006-01-02 15:04")
|
||||
}
|
||||
if wo.CompletedAt != nil {
|
||||
card.CompletedAt = wo.CompletedAt.Format("2006-01-02 15:04")
|
||||
}
|
||||
|
||||
// 路线:工单工艺组合 → 工位顺序;未配置则全产线已配置工位
|
||||
seq := []int{}
|
||||
@@ -441,7 +446,7 @@ func buildWorkOrderCard(ctx context.Context, svcCtx *svc.ServiceContext, workOrd
|
||||
}
|
||||
for _, s := range stepsByFlow[st.FlowId] {
|
||||
key := fmt.Sprintf("%d|%s", st.FlowId, s.Name)
|
||||
ps := woProcessStep{Seq: s.Seq, ProcessName: s.Name, StationNo: no, PlanHours: "-",
|
||||
ps := woProcessStep{Seq: s.Seq, ProcessName: s.Name, CollectCN: ppCollectCN(s.CollectType), StationNo: no, PlanHours: "-",
|
||||
NeedCheck: s.NeedCheck, NeedAudit: s.NeedAudit, AuditRole: s.AuditRole}
|
||||
a := actByKey[key]
|
||||
if a != nil && a.hasRecord {
|
||||
@@ -814,8 +819,9 @@ func renderWorkOrderCard(c *workOrderCard) (string, error) {
|
||||
</div>
|
||||
<div class="meta">
|
||||
<span>计划开始:<b>{{.PlanStart}}</b></span>
|
||||
<span>计划结束:<b>{{.PlanEnd}}</b></span>
|
||||
<span>计划完成:<b>{{.PlanEnd}}</b></span>
|
||||
<span>实际开始:<b>{{.ActualStart}}</b></span>
|
||||
<span>实际完成:<b>{{.CompletedAt}}</b></span>
|
||||
<span>实际结束:<b>{{.ActualFinish}}</b></span>
|
||||
<span>生成时间:<b>{{.GeneratedAt}}</b></span>
|
||||
</div>
|
||||
@@ -823,11 +829,11 @@ func renderWorkOrderCard(c *workOrderCard) (string, error) {
|
||||
<h2>一、工序实绩</h2>
|
||||
{{if .ProcessSteps}}
|
||||
<table>
|
||||
<thead><tr><th>序号</th><th>工序</th><th>工位</th><th>计划工时</th><th>实绩开始</th><th>实绩结束</th><th>操作人</th><th>状态</th><th>审核人</th><th>审核时间</th></tr></thead>
|
||||
<thead><tr><th>序号</th><th>工序</th><th>采集方式</th><th>工位</th><th>计划工时</th><th>实绩开始</th><th>实绩结束</th><th>操作人</th><th>状态</th><th>审核人</th><th>审核时间</th></tr></thead>
|
||||
<tbody>
|
||||
{{range .ProcessSteps}}
|
||||
<tr>
|
||||
<td>{{.Seq}}</td><td class="left">{{.ProcessName}}</td><td>{{.StationNo}}</td><td>{{.PlanHours}}</td>
|
||||
<td>{{.Seq}}</td><td class="left">{{.ProcessName}}</td><td>{{.CollectCN}}</td><td>{{.StationNo}}</td><td>{{.PlanHours}}</td>
|
||||
<td>{{.ActualStart}}</td><td>{{.ActualEnd}}</td><td>{{.Operators}}</td>
|
||||
<td>{{if eq .Status "完成"}}<span class="ok">完成</span>{{else}}{{.Status}}{{end}}</td>
|
||||
<td>{{if .Auditor}}{{.Auditor}}{{if .AuditRole}}({{.AuditRole}}){{end}}{{else}}<span class="off">-</span>{{end}}</td>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"bj_power_mes/common/httpx"
|
||||
@@ -116,7 +117,13 @@ func SaveStationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
if err := logic.New(svcCtx).SaveStation(r.Context(), req, operator(r, "")); err != nil {
|
||||
httpx.Fail(w, 2206, err.Error())
|
||||
// 规则3:PLC 离线未二次确认 → 哨兵错误映射为 code=3021,前端弹「已现场确认,继续」二次确认后重发
|
||||
if errors.Is(err, logic.ErrPlcOfflineConfirmRequired) {
|
||||
httpx.Fail(w, 3021, err.Error())
|
||||
return
|
||||
}
|
||||
// 收集式校验(code=3015)经 FailErr 结构化输出,前端弹 ErrorListDialog 一次列全
|
||||
httpx.FailErr(w, err)
|
||||
return
|
||||
}
|
||||
httpx.OkMessage(w, "工位绑定已保存", nil)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -50,7 +50,8 @@ func SaveProductProcessHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
if err := logic.New(svcCtx).SaveProductProcess(r.Context(), req, operator(r, "")); err != nil {
|
||||
httpx.Fail(w, 2233, err.Error())
|
||||
// 收集式校验(code=3015)经 FailErr 结构化输出,前端弹 ErrorListDialog 一次列全
|
||||
httpx.FailErr(w, err)
|
||||
return
|
||||
}
|
||||
httpx.OkMessage(w, "产品工艺已保存", nil)
|
||||
@@ -86,3 +87,20 @@ func DeleteProductProcessHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.OkMessage(w, "产品工艺已删除", nil)
|
||||
}
|
||||
}
|
||||
|
||||
// CopyProductProcessHandler POST /product-processes/copy(深拷贝:主表+明细步骤;默认名"源名-副本")
|
||||
func CopyProductProcessHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req logic.CopyProductProcessReq
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
id, err := logic.New(svcCtx).CopyProductProcess(r.Context(), req, operator(r, ""))
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2236, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"id": id})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ type ppCardStep struct {
|
||||
Seq int `json:"seq"`
|
||||
Name string `json:"name"`
|
||||
CollectCN string `json:"collectCN"`
|
||||
IsTorque bool `json:"isTorque"`
|
||||
NeedCheck bool `json:"needCheck"`
|
||||
NeedOperatorSign bool `json:"needOperatorSign"`
|
||||
NeedInspectorSign bool `json:"needInspectorSign"`
|
||||
@@ -83,6 +82,8 @@ func ppCollectCN(v string) string {
|
||||
return "拧紧枪自动"
|
||||
case "MANUAL":
|
||||
return "手填"
|
||||
case "SCAN":
|
||||
return "扫码"
|
||||
case "NONE":
|
||||
return "仅记录"
|
||||
}
|
||||
@@ -129,7 +130,7 @@ func buildProductProcessCard(ctx context.Context, svcCtx *svc.ServiceContext, id
|
||||
for _, st := range steps {
|
||||
row.Steps = append(row.Steps, ppCardStep{
|
||||
Seq: st.Seq, Name: st.Name, CollectCN: ppCollectCN(st.CollectType),
|
||||
IsTorque: st.IsTorque, NeedCheck: st.NeedCheck,
|
||||
NeedCheck: st.NeedCheck,
|
||||
NeedOperatorSign: st.NeedOperatorSign, NeedInspectorSign: st.NeedInspectorSign,
|
||||
NeedAudit: st.NeedAudit, AuditRole: st.AuditRole, Remark: st.Remark,
|
||||
})
|
||||
@@ -263,12 +264,11 @@ func renderProductProcessCard(c *ppCardData) (string, error) {
|
||||
<p class="sub" style="margin:8px 0 4px">第{{.Seq}}道 · {{.FlowName}}</p>
|
||||
{{if .Steps}}
|
||||
<table>
|
||||
<thead><tr><th>序号</th><th>步骤</th><th>采集方式</th><th>拧紧</th><th>检测确认</th><th>操作工签</th><th>检验员签</th><th>审核</th><th>备注</th></tr></thead>
|
||||
<thead><tr><th>序号</th><th>步骤</th><th>采集方式</th><th>检测确认</th><th>操作工签</th><th>检验员签</th><th>审核</th><th>备注</th></tr></thead>
|
||||
<tbody>
|
||||
{{range .Steps}}
|
||||
<tr>
|
||||
<td>{{.Seq}}</td><td class="left">{{.Name}}</td><td>{{.CollectCN}}</td>
|
||||
<td>{{if .IsTorque}}<span class="flag">是</span>{{else}}<span class="off">-</span>{{end}}</td>
|
||||
<td>{{if .NeedCheck}}<span class="flag">需检验</span>{{else}}<span class="off">-</span>{{end}}</td>
|
||||
<td>{{if .NeedOperatorSign}}<span class="flag">需签</span>{{else}}<span class="off">-</span>{{end}}</td>
|
||||
<td>{{if .NeedInspectorSign}}<span class="flag">需签</span>{{else}}<span class="off">-</span>{{end}}</td>
|
||||
|
||||
@@ -44,6 +44,9 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/dashboard/snapshot", Handler: internal(production.DashboardSnapshotInternalHandler(serverCtx)),
|
||||
})
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/dashboard/material-query", Handler: internal(production.DashboardMaterialQueryHandler(serverCtx)),
|
||||
})
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/dashboard/stream", Handler: internal(serverCtx.SSE.Handler),
|
||||
}, rest.WithTimeout(3600_000_000_000))
|
||||
@@ -179,6 +182,14 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodPost, Path: "/api/internal/plc/mismatch/check", Handler: internal(PlcMismatchCheckInternalHandler(serverCtx)),
|
||||
})
|
||||
// 工位终端「本工位相关报警」查询(谁受影响谁播报,2026-10-20):终端轮询代理(X-API-TOKEN 保护)。
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/station/alerts", Handler: internal(production.StationAlertsInternalHandler(serverCtx)),
|
||||
})
|
||||
// 工位终端「本工位相关报警」SSE 推送(2026-10-20 轮询改事件驱动):CreateAlert 写入成功即广播。
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/station/alerts/stream", Handler: internal(production.StationAlertsStreamHandler(serverCtx)),
|
||||
})
|
||||
|
||||
// ---------- AGV 调度(2026-10-14 迁 MES 为唯一真源,海康 RCS) ----------
|
||||
// WMS 仓库端「AGV配送」页透明代理到本组(X-API-TOKEN 保护);MES 是 AGV 任务与 RCS 客户端唯一真源。
|
||||
@@ -217,6 +228,10 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
{Method: http.MethodPost, Path: "/work-orders", Handler: production.CreateWorkOrderHandler(serverCtx)},
|
||||
{Method: http.MethodPut, Path: "/work-orders", Handler: production.UpdateWorkOrderHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/work-orders/status", Handler: production.SetWorkOrderStatusHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/work-orders/for-schedule", Handler: production.ForScheduleWorkOrdersHandler(serverCtx)},
|
||||
// 强制完工(方案 A,2026-10-20):核对单预览 + 执行(原因必填、在制>0 拒绝)
|
||||
{Method: http.MethodGet, Path: "/work-orders/:id/force-complete/preview", Handler: production.ForceCompletePreviewHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/work-orders/force-complete", Handler: production.ForceCompleteHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/work-orders/:id", Handler: production.GetWorkOrderHandler(serverCtx)},
|
||||
{Method: http.MethodDelete, Path: "/work-orders/:id", Handler: production.DeleteWorkOrderHandler(serverCtx)},
|
||||
// 排产预览/确认(M9:预览逐日可调、Σ==应排总数才能确认)
|
||||
@@ -259,9 +274,8 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
{Method: http.MethodGet, Path: "/plc/monitor/targets", Handler: production.PlcMonitorTargetsHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/plc/monitor/preview", Handler: production.PlcMonitorPreviewHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/plc/monitor/manual-write", Handler: production.PlcMonitorManualWriteHandler(serverCtx)},
|
||||
// 强制写入(块 D:危险操作;未勾选二次确认 / 越界白名单一律拒绝;写 event_log type=plc_manual_force)
|
||||
{Method: http.MethodPost, Path: "/plc/monitor/force-bit", Handler: production.PlcMonitorForceBitHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/plc/monitor/write-mw", Handler: production.PlcMonitorWriteMwHandler(serverCtx)},
|
||||
// 在途指令强制清零(仅 §4.4 路由区 MW=0;越界/控制区一律拒绝;写 event_log type=plc_in_transit_clear)
|
||||
{Method: http.MethodPost, Path: "/plc/monitor/clear-in-transit", Handler: production.PlcMonitorClearInTransitHandler(serverCtx)},
|
||||
// 工件位置核对/纠正(块 E:产线管理页 tab4;MES 记录有、PLC 实际无 → 清为不在工位)
|
||||
{Method: http.MethodGet, Path: "/plc/monitor/position-check", Handler: production.PlcPositionCheckHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/plc/monitor/position-correct", Handler: production.PlcPositionCorrectHandler(serverCtx)},
|
||||
@@ -285,6 +299,8 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
|
||||
{Method: http.MethodPost, Path: "/torque/report", Handler: production.TorqueReportHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/torque/records", Handler: production.TorqueRecordsHandler(serverCtx)},
|
||||
// 拧紧数据独立导出(A4):复用 /torque/records 同口径筛选,输出 Excel
|
||||
{Method: http.MethodGet, Path: "/torque/export", Handler: production.TorqueExportHandler(serverCtx)},
|
||||
// 拧紧不合格人工处置(质检/班组长确认放行):清标记 + 写 event_log + 置预警 resolved。权限码 produce.torque:dispose。
|
||||
{Method: http.MethodPost, Path: "/torque/dispose", Handler: production.TorqueDispositionHandler(serverCtx)},
|
||||
|
||||
@@ -335,9 +351,9 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
{Method: http.MethodPost, Path: "/process-flows/status", Handler: SetFlowStatusHandler(serverCtx)},
|
||||
{Method: http.MethodDelete, Path: "/process-flows/:id", Handler: DeleteProcessFlowHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/process-flows/upload", Handler: UploadPdfHandler(serverCtx)},
|
||||
// 统一存储深路径文件 URL(年/月/日/文件类型/uuid.ext,如 /api/v1/files/2026/09/22/PROCESS_PDF/xxx.pdf),
|
||||
// 上传接口返回的 url 即此格式,未注册前直接访问 404
|
||||
{Method: http.MethodGet, Path: "/files/:y/:m/:d/:t/:f", Handler: FileDeepPathHandler(serverCtx)},
|
||||
// 统一存储深路径文件 URL(年/月/日/文件类型/uuid.ext,如 /api/v1/files/2026/09/22/PROCESS_PDF/xxx.pdf)
|
||||
// 已移至下方公开组(免 JWT):工艺 PDF/巡检照片经 window.open/iframe 预览无法携带
|
||||
// Authorization 头,注册在 JWT 组会 401「登录已过期」(2026-10-19 修复)
|
||||
{Method: http.MethodGet, Path: "/stations", Handler: ListStationsHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/stations", Handler: SaveStationHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/stations/status", Handler: SetStationStatusHandler(serverCtx)},
|
||||
@@ -352,6 +368,7 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
{Method: http.MethodPut, Path: "/product-processes", Handler: SaveProductProcessHandler(serverCtx)},
|
||||
{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)},
|
||||
{Method: http.MethodGet, Path: "/line/points", Handler: ListPointsHandler(serverCtx)},
|
||||
|
||||
// ---------- PAD 巡检终端(块8) ----------
|
||||
@@ -420,6 +437,9 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
fileRoutes := []rest.Route{
|
||||
{Method: http.MethodGet, Path: "/files", Handler: FileDownloadHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/files/:date/:name", Handler: FilePathHandler(serverCtx)},
|
||||
// 统一存储深路径(年/月/日/文件类型/uuid.ext,固定 5 段显式声明;go-zero 无多段通配)。
|
||||
// 工艺 PDF 预览(ProcessFlow.vue window.open)、巡检/装配照片均为此格式,必须免鉴权。
|
||||
{Method: http.MethodGet, Path: "/files/:y/:m/:d/:t/:f", Handler: FileDeepPathHandler(serverCtx)},
|
||||
}
|
||||
server.AddRoutes(
|
||||
fileRoutes,
|
||||
|
||||
Reference in New Issue
Block a user