feat: 全端体验与稳定性整改(帮助文档清理/收集式报错/操作列统一/托盘与WS通知/物料同步重推)
- 移除 bj_power_dashboard 旧 React 大屏源码(迁移至 2D SVG 方案) - MES/WMS/工位终端前端:清理 help.js 与 PageHelp 帮助文档,统一操作列与布局,接入请求拦截器 - 新增收集式校验错误弹窗(ErrorListDialog 统一拦截 3015,逐条列现象+建议) - 新增托盘程序(tray)与 WebSocket(ws) 实时通知模块(三端共用) - MES/WMS 物料档案新增同步状态字段,补齐双向失败重推与默认角色 seed - 工单/产能/产品工艺/日排产逻辑调整;拧紧枪按工位配置 - 新增迁移 SQL:扭矩按工位、sysconfig 序列修复 - 更新 技术约束/案例/部署手册/项目说明 等文档
This commit is contained in:
@@ -17,7 +17,7 @@ var pathPermMap = map[string]string{
|
||||
"DELETE:/api/v1/product-types/*": "produce.product:delete",
|
||||
"POST:/api/v1/product-types/import": "produce.product:add",
|
||||
"POST:/api/v1/product-types/import/preview": "produce.product:add",
|
||||
"GET:/api/v1/product-types/template": "produce.product:edit",
|
||||
"GET:/api/v1/product-types/template": "produce.product:add",
|
||||
"POST:/api/v1/work-orders": "produce.workorder:add",
|
||||
"PUT:/api/v1/work-orders": "produce.workorder:edit",
|
||||
"POST:/api/v1/work-orders/status": "produce.workorder:edit",
|
||||
@@ -76,6 +76,12 @@ var pathPermMap = map[string]string{
|
||||
"POST:/api/v1/permissions": "sys.role:perm",
|
||||
"PUT:/api/v1/permissions": "sys.role:perm",
|
||||
"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",
|
||||
}
|
||||
|
||||
// userHasPerm 校验当前登录用户是否拥有某权限码(SUPER_ADMIN 或 * 放行)。
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package production
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"bj_power_mes/common/httpx"
|
||||
"bj_power_mes/internal/logic"
|
||||
"bj_power_mes/internal/svc"
|
||||
|
||||
"github.com/xuri/excelize/v2"
|
||||
)
|
||||
|
||||
// DailyPlanCompareHandler GET /daily-plans/compare?start=&end= 日排产历史对比
|
||||
func DailyPlanCompareHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
res, err := logic.New(svcCtx).DailyPlanCompare(r.Context(), q.Get("start"), q.Get("end"))
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3601, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, res)
|
||||
}
|
||||
}
|
||||
|
||||
// DailyPlanCompareExportHandler GET /daily-plans/compare/export?start=&end= 直出 xlsx
|
||||
func DailyPlanCompareExportHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
res, err := logic.New(svcCtx).DailyPlanCompare(r.Context(), q.Get("start"), q.Get("end"))
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3602, err.Error())
|
||||
return
|
||||
}
|
||||
f := excelize.NewFile()
|
||||
const sheet = "日排产历史对比"
|
||||
_ = f.SetSheetName("Sheet1", sheet)
|
||||
headers := []interface{}{"工单号", "成品编码", "计划数量", "已完成", "差异", "排产日期", "状态"}
|
||||
_ = f.SetSheetRow(sheet, "A1", &headers)
|
||||
for i, it := range res.Items {
|
||||
row := []interface{}{
|
||||
it.WorkOrderNo, it.ProductCode, it.PlanQty, it.CompletedQty,
|
||||
it.Diff, it.PlanDate, it.Status,
|
||||
}
|
||||
_ = f.SetSheetRow(sheet, "A"+strconv.Itoa(i+2), &row)
|
||||
}
|
||||
buf, e := f.WriteToBuffer()
|
||||
_ = f.Close()
|
||||
if e != nil {
|
||||
httpx.Fail(w, 3602, "生成 Excel 失败:"+e.Error())
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
// 中文文件名:filename*=UTF-8'' 与 filename= 双写(ASCII 回退名不含中文,兼容老浏览器)
|
||||
w.Header().Set("Content-Disposition",
|
||||
"attachment; filename=\"daily_plan_compare.xlsx\"; filename*=UTF-8''"+url.PathEscape("日排产历史对比.xlsx"))
|
||||
_, _ = w.Write(buf.Bytes())
|
||||
}
|
||||
}
|
||||
@@ -215,12 +215,19 @@ type orderRow struct {
|
||||
ProductSnMode int `json:"productSnMode"` // 产品型号/物料档案 sn_mode:0未选择/1序列号=是/2序列号=否
|
||||
}
|
||||
|
||||
// OrderQueryInternalHandler GET /api/internal/order/query?orderNo=
|
||||
// OrderQueryInternalHandler GET /api/internal/order/query?orderNo=&keyword=&status=&limit=
|
||||
// 返回工单列表并附 productSnMode(按工单产品编码查 MES 本地物料档案;档案缺失/未选择=0)。
|
||||
// 2026-11-10:支持 keyword 远程搜索 + limit 截断(工位终端工单下拉防内存炸弹)。
|
||||
func OrderQueryInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
orderNo := r.URL.Query().Get("orderNo")
|
||||
list, err := logic.New(svcCtx).ListWorkOrders(r.Context(), orderNo, "", "", "", "", "", "", 0)
|
||||
keyword := r.URL.Query().Get("keyword")
|
||||
status := r.URL.Query().Get("status")
|
||||
limit := 0
|
||||
if n, e := strconv.Atoi(r.URL.Query().Get("limit")); e == nil && n > 0 {
|
||||
limit = n
|
||||
}
|
||||
list, err := logic.New(svcCtx).ListWorkOrders(r.Context(), orderNo, status, "", "", "", "", keyword, limit)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2004, err.Error())
|
||||
return
|
||||
@@ -326,7 +333,7 @@ func OrderUsageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
// ---------- 看板内部接口 ----------
|
||||
|
||||
// DashboardSnapshotInternalHandler 看板全量快照。
|
||||
// 结构与本项目看板前端 src/types.ts 严格对齐(见 internal/logic/dashboard_front.go),
|
||||
// 结构与 MES /board 看板页前端数据契约严格对齐(见 internal/logic/dashboard_front.go),
|
||||
// 由 DashboardSnapshotInternalHandler 一次性返回,前端不再分接口拼装。
|
||||
func DashboardSnapshotInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -339,7 +346,7 @@ func DashboardSnapshotInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFu
|
||||
}
|
||||
}
|
||||
|
||||
// DashboardConfigInternalHandler 门口看板(项目A)启动配置:标题文字 + 语音播报开关。
|
||||
// DashboardConfigInternalHandler 门口看板(MES /board 页)启动配置:标题文字 + 语音播报开关。
|
||||
// 基础设置页(dashboard.board.title / dashboard.board.voice)维护,保存即生效;看板端轮询跟随。
|
||||
func DashboardConfigInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -348,7 +355,13 @@ func DashboardConfigInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
|
||||
httpx.Fail(w, 2010, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"title": vo.DashboardTitle, "voiceOn": vo.DashboardVoice})
|
||||
httpx.Ok(w, map[string]any{
|
||||
"title": vo.DashboardTitle,
|
||||
"voiceOn": vo.DashboardVoice,
|
||||
"kpiVisible": vo.DashboardKpiVisible, // JSON 数组字符串(前端 boardService 两种都兼容)
|
||||
"animationLevel": vo.DashboardAnimationLevel, // full/simple/off
|
||||
"titleScroll": vo.DashboardBoardTitleScroll, // 0/1
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
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"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
res, err := logic.New(svcCtx).ApplyStationTemplate(r.Context(), req.Name, req.TargetProductCode, operator(r, ""))
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3504, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, res)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package production
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"bj_power_mes/common/httpx"
|
||||
tokenx "bj_power_mes/common/token"
|
||||
"bj_power_mes/internal/logic"
|
||||
"bj_power_mes/internal/svc"
|
||||
"bj_power_mes/internal/ws"
|
||||
)
|
||||
|
||||
var (
|
||||
todoHubOnce sync.Once
|
||||
todoHub *ws.TodoHub
|
||||
)
|
||||
|
||||
func globalTodoHub(svcCtx *svc.ServiceContext) *ws.TodoHub {
|
||||
todoHubOnce.Do(func() {
|
||||
todoHub = ws.NewTodoHub(svcCtx)
|
||||
})
|
||||
return todoHub
|
||||
}
|
||||
|
||||
// TodoStatsHandler GET /todos/stats 待办统计快照 {items:[{menuCode,count}],total}
|
||||
func TodoStatsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
items, total, err := logic.New(svcCtx).TodoStats(r.Context())
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3701, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"items": items, "total": total})
|
||||
}
|
||||
}
|
||||
|
||||
// TodoWsHandler GET /todos/ws?token=<JWT> 待办变化 WebSocket 推送。
|
||||
// 浏览器 new WebSocket(url) 无法携带 Authorization 头,故 token 走 query;
|
||||
// 校验复用与 StationSessionAuth 同源同密钥的 tokenx.Parse(非空 + 签名有效 + 未过期),
|
||||
// 不采用空鉴权。校验通过后交由 TodoHub 升级并管理连接。
|
||||
func TodoWsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
tok := strings.TrimSpace(r.URL.Query().Get("token"))
|
||||
if tok == "" {
|
||||
httpx.Unauthorized(w, "缺少登录凭证,请重新登录")
|
||||
return
|
||||
}
|
||||
claims, err := tokenx.Parse(svcCtx.Config.Auth.AccessSecret, tok)
|
||||
if err != nil || claims == nil || claims.ExpiresAt == nil || time.Until(claims.ExpiresAt.Time) <= 0 {
|
||||
httpx.Unauthorized(w, "登录凭证无效或已过期,请重新登录")
|
||||
return
|
||||
}
|
||||
globalTodoHub(svcCtx).Handle(w, r)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package production
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -8,10 +9,12 @@ import (
|
||||
"strings"
|
||||
|
||||
"bj_power_mes/common/httpx"
|
||||
ent "bj_power_mes/ent"
|
||||
"bj_power_mes/ent/workorder"
|
||||
"bj_power_mes/internal/logic"
|
||||
"bj_power_mes/internal/svc"
|
||||
|
||||
"github.com/xuri/excelize/v2"
|
||||
"github.com/zeromicro/go-zero/rest/pathvar"
|
||||
)
|
||||
|
||||
@@ -21,6 +24,77 @@ func pathID(r *http.Request) int {
|
||||
return n
|
||||
}
|
||||
|
||||
// ---------- 「物料编码」字段(materials.material_code,普通字段,不参与业务/校验)----------
|
||||
// 列由 db.go schemaPatchSQL 幂等 ALTER 创建;列表/新建/编辑/导入统一由 logic 层 ent 读写;
|
||||
// 导出 xlsx 按「图号」用本地值回填同名列(WMS 导出已带该列时覆盖,不重复追加)。
|
||||
|
||||
// materialCodeByCode 读本地 materials.material_code,按图号 code 索引。
|
||||
func materialCodeByCode(r *http.Request, svcCtx *svc.ServiceContext) map[string]string {
|
||||
m := map[string]string{}
|
||||
rows, err := svcCtx.SQLDB.QueryContext(r.Context(), `SELECT code, COALESCE(material_code, '') FROM materials`)
|
||||
if err != nil {
|
||||
return m
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var code, mc string
|
||||
if rows.Scan(&code, &mc) == nil {
|
||||
m[code] = mc
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// appendMaterialCodeColumn 用 MES 本地值回填导出 xlsx 的「物料编码」列。
|
||||
// WMS 导出首列为 ID、第 3 列为同名「物料编码」:按表头定位「图号」与「物料编码」列,
|
||||
// 同名列已存在则覆盖、不存在才追加,避免出现两个「物料编码」列或把 ID 当图号。
|
||||
// WMS 返回非合法 xlsx 时原样透传。
|
||||
func appendMaterialCodeColumn(r *http.Request, svcCtx *svc.ServiceContext, b []byte) []byte {
|
||||
f, err := excelize.OpenReader(bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return b
|
||||
}
|
||||
defer f.Close()
|
||||
sheet := f.GetSheetName(0)
|
||||
rows, err := f.GetRows(sheet)
|
||||
if err != nil || len(rows) == 0 {
|
||||
return b
|
||||
}
|
||||
codeCol, mcCol := -1, -1
|
||||
for i, h := range rows[0] {
|
||||
switch strings.TrimSpace(h) {
|
||||
case "图号":
|
||||
codeCol = i
|
||||
case "物料编码":
|
||||
mcCol = i
|
||||
}
|
||||
}
|
||||
if codeCol < 0 {
|
||||
return b
|
||||
}
|
||||
if mcCol < 0 {
|
||||
mcCol = len(rows[0])
|
||||
if cell, e := excelize.CoordinatesToCellName(mcCol+1, 1); e == nil {
|
||||
_ = f.SetCellValue(sheet, cell, "物料编码")
|
||||
}
|
||||
}
|
||||
codes := materialCodeByCode(r, svcCtx)
|
||||
for i := 1; i < len(rows); i++ {
|
||||
code := ""
|
||||
if codeCol < len(rows[i]) {
|
||||
code = strings.TrimSpace(rows[i][codeCol])
|
||||
}
|
||||
if cell, e := excelize.CoordinatesToCellName(mcCol+1, i+1); e == nil {
|
||||
_ = f.SetCellValue(sheet, cell, codes[code])
|
||||
}
|
||||
}
|
||||
buf, err := f.WriteToBuffer()
|
||||
if err != nil {
|
||||
return b
|
||||
}
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
// ---------- 产品型号 ----------
|
||||
|
||||
func ListProductTypesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
@@ -51,7 +125,8 @@ func ListProductTypesPageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{
|
||||
"total": total, "list": list, "page": page, "pageSize": pageSize, "wmsOnline": wmsOnline,
|
||||
"total": total, "list": list,
|
||||
"page": page, "pageSize": pageSize, "wmsOnline": wmsOnline,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -140,6 +215,8 @@ func ExportProductTypesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.Fail(w, 3002, "导出失败(WMS 不可达):"+err.Error())
|
||||
return
|
||||
}
|
||||
// 导出列追加「物料编码」(首列图号关联本地库回填)
|
||||
b = appendMaterialCodeColumn(r, svcCtx, b)
|
||||
w.Header().Set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
w.Header().Set("Content-Disposition", "attachment; filename*=UTF-8''"+url.PathEscape("物料档案.xlsx"))
|
||||
_, _ = w.Write(b)
|
||||
@@ -166,10 +243,26 @@ func ListWorkOrdersHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
httpx.Fail(w, 3004, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, data)
|
||||
// 列表回填产品序号前缀(前端 openEdit 回填用)
|
||||
prefixes := logic.New(svcCtx).SNPrefixesOf(r.Context(), data)
|
||||
httpx.Ok(w, workOrdersWithSNPrefix(data, prefixes))
|
||||
}
|
||||
}
|
||||
|
||||
// workOrdersWithSNPrefix 把工单实体列表转成带 snPrefix 的响应行(保留全部原有字段)。
|
||||
func workOrdersWithSNPrefix(rows []*ent.WorkOrder, prefixes map[int]string) []map[string]any {
|
||||
b, _ := json.Marshal(rows)
|
||||
var out []map[string]any
|
||||
_ = json.Unmarshal(b, &out)
|
||||
for i := range out {
|
||||
out[i]["snPrefix"] = prefixes[rows[i].ID]
|
||||
}
|
||||
if out == nil {
|
||||
out = []map[string]any{}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func CreateWorkOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req logic.WorkOrderReq
|
||||
@@ -218,10 +311,32 @@ func GetWorkOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
_ = json.Unmarshal(b, &m)
|
||||
m["scheduledQty"] = scheduled
|
||||
m["remainQty"] = wo.Quantity - scheduled
|
||||
// 详情回填产品序号前缀(前端 openEdit 回填用)
|
||||
m["snPrefix"] = logic.New(svcCtx).SNPrefixesOf(r.Context(), []*ent.WorkOrder{wo})[wo.ID]
|
||||
httpx.Ok(w, m)
|
||||
}
|
||||
}
|
||||
|
||||
// SnPrefixHandler POST /work-orders/sn-prefix 重设产品序号前缀并重新生成全部 SN(仅 CREATED 可改)。
|
||||
func SnPrefixHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Id int `json:"id"`
|
||||
SnPrefix string `json:"snPrefix"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
n, err := logic.New(svcCtx).RegenerateSNPrefix(r.Context(), req.Id, req.SnPrefix, operator(r, ""))
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3008, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"ok": true, "regenerated": n})
|
||||
}
|
||||
}
|
||||
|
||||
// WorkOrderInternalHandler GET /api/internal/work-orders/:no
|
||||
// 供 WMS 解析工单归属(A2 半成品入库归属继承产线工单):返回工单号、归属编号(contractNo)、
|
||||
// 归属类型(ownershipType: workorder=合同号/project=科技项目号/other=其他)。
|
||||
|
||||
@@ -576,6 +576,20 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
{Method: http.MethodGet, Path: "/sync-failures", Handler: SyncFailureListHandler(serverCtx)},
|
||||
{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)},
|
||||
// ---------- 工单 SN 前缀(问题5):仅 CREATED 可改,事务重生成全部 SN ----------
|
||||
{Method: http.MethodPost, Path: "/work-orders/sn-prefix", Handler: production.SnPrefixHandler(serverCtx)},
|
||||
// ---------- 待办统计快照(问题8):WebSocket 长连接见下方单独注册 ----------
|
||||
{Method: http.MethodGet, Path: "/todos/stats", Handler: production.TodoStatsHandler(serverCtx)},
|
||||
}
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares([]rest.Middleware{permissionGuard(serverCtx)}, jwtRoutes...),
|
||||
@@ -586,6 +600,13 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
rest.WithMaxBytes(maxUploadBytes(serverCtx.Config.Upload.MaxMB, serverCtx.Config.Upload.MaxSize)),
|
||||
)
|
||||
|
||||
// ---------- 待办变化 WebSocket(问题8):长连接,脱离 WithJwt 分组单独注册 ----------
|
||||
// 浏览器 new WebSocket 无法携带 Authorization 头,token 走 query,由 TodoWsHandler 用
|
||||
// tokenx.Parse 自校验(非空 + 签名有效 + 未过期),故不挂 WithJwt;放宽超时避免 5s 断连。
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/v1/todos/ws", Handler: production.TodoWsHandler(serverCtx),
|
||||
}, rest.WithTimeout(3600_000_000_000))
|
||||
|
||||
// ---------- 海康 RCS-Lite SPI 主动回调(文档 2.2.1 任务执行通知 agvCallback) ----------
|
||||
// 注意:RCS 回调不携带我方鉴权头;生产环境必须以防火墙 / IP 白名单隔离该端点(待与 RCS 方确认鉴权方式)。
|
||||
// RCS-Lite 后台需将上层回调地址配置为本端点(路径遵循文档 /xxx/agv/agvCallbackService/agvCallback)。
|
||||
|
||||
Reference in New Issue
Block a user