feat: 新增装机绑定功能与权限、BOM工序配置

1.  新增装机绑定实体与相关CRUD逻辑,支持工件工序物料绑定/解绑
2.  为BOM物料新增装配工序字段,支持按工序校验绑定
3.  扩展权限表,新增父权限码字段支持菜单按钮关联
4.  统一各页面帮助弹窗参数,新增角色管理帮助文档
5.  新增公共格式化工具函数,优化侧边栏菜单展开逻辑
6.  新增工位终端绑定代理接口与MES内部绑定API
7.  修复主入口数据库连接与schema初始化逻辑,新增一键迁移工具
This commit is contained in:
SunYF
2026-09-07 11:58:19 +08:00
parent 92f0439d89
commit 6ee131a4bd
70 changed files with 6966 additions and 365 deletions
@@ -10,6 +10,15 @@ export const getConfig = () => request.get('/api/config')
export const getTaskCurrent = (stationNo) =>
request.get('/api/task/current', { params: { stationNo } })
// 装机绑定面板(代理 MES):sn+processCode → 应绑/已绑清单
export const getBindPanel = (params) => request.get('/api/bind/panel', { params })
// 装机绑定一条(代理 MES):{sn, processCode, stationNo, items:[{materialCode, bindValue}]}
export const bindRecord = (data) => request.post('/api/bind/record', data)
// 撤销一条绑定(代理 MES):{sn, processCode, materialCode, bindValue}
export const bindRemove = (data) => request.post('/api/bind/remove', data)
// 我的工作量(代理 MES,按当前登录人查询)
export const getWorkload = (params) => request.get('/api/workload', { params })
@@ -40,6 +40,42 @@
<span class="screw-progress">已拧 {{ tightRows.length }} </span>
</section>
<!-- 装机绑定卡扫工件后自动拉取本工序应装物料扫一个绑一个精密件必须扫码SN齐套后可报工 -->
<section v-if="bindShow" class="card bind-card">
<div class="bind-head">
<h3 class="card-title">工序 {{ processCodeText }} 装机绑定装配物料</h3>
<el-tag v-if="bindPanel && bindPanel.enabled && bindPanel.complete" type="success" size="large" effect="dark">已绑齐 </el-tag>
<el-tag v-else-if="bindPanel && bindPanel.enabled" type="danger" size="large" effect="dark">未绑齐{{ bindPanel.missing || '缺料' }}</el-tag>
<el-tag v-else type="info" size="large">该产品本工序未配置需绑物料</el-tag>
</div>
<div v-if="bindPanel && bindPanel.required && bindPanel.required.length" class="bind-list">
<div v-for="r in bindPanel.required" :key="r.materialCode" class="bind-item">
<div class="bind-meta">
<span class="bind-name">{{ r.materialName || r.materialCode }}</span>
<span class="bind-code">{{ r.materialCode }}</span>
<el-tag size="small" :type="r.manageMode === '2' ? 'primary' : 'warning'">
{{ r.manageMode === '2' ? '精密件·扫码SN' : '结构件·批次' }}
</el-tag>
<span class="bind-count" :class="r.complete ? 'ok' : 'ng'">{{ r.boundCount }}/{{ r.need }}</span>
</div>
<div class="bind-bound">
<el-tag v-for="b in r.bound" :key="b" size="small" closable @close="removeBind(r, b)">{{ b }}</el-tag>
<span v-if="!r.bound.length" style="color:#909399">未绑定</span>
</div>
<div class="bind-input-row">
<el-input
v-model.trim="bindInputs[r.materialCode]"
size="large"
:placeholder="r.manageMode === '2' ? '扫描精密件SN(必扫)' : '扫描/输入批次号'"
clearable
@keyup.enter="doBind(r)"
/>
<el-button type="primary" size="large" :loading="binding" @click="doBind(r)">绑定</el-button>
</div>
</div>
</div>
</section>
<!-- 三区布局A 任务卡 / C 步骤采集 / 拧紧结果 -->
<main class="content">
<!-- A. 左侧任务卡流程名 + 工序号 + 工单号 + 工艺PDF -->
@@ -222,6 +258,9 @@ import {
getTaskCurrent,
getTighteningList,
getWorkload,
getBindPanel,
bindRecord,
bindRemove,
pdfOpenUrl,
reportProcessDone,
reportTempStore,
@@ -299,9 +338,77 @@ function onScan() {
currentSn.value = sn
scanInput.value = ''
loadTight()
loadBindPanel()
focusScan()
}
// ---------- 装机绑定(装配物料:精密件必须扫码SN / 结构件扫批次) ----------
const bindShow = ref(false)
const bindPanel = ref(null)
const bindInputs = reactive({})
const binding = ref(false)
function loadBindPanel() {
const code = Number(processCode.value)
if (!currentSn.value || !code) {
bindShow.value = false
bindPanel.value = null
return
}
bindShow.value = true
getBindPanel({ sn: currentSn.value, processCode: code })
.then((p) => {
bindPanel.value = p
// 预填各料输入框为空
;(p?.required || []).forEach((r) => { if (bindInputs[r.materialCode] === undefined) bindInputs[r.materialCode] = '' })
})
.catch(() => {
bindPanel.value = null
})
}
async function doBind(r) {
const v = (bindInputs[r.materialCode] || '').trim()
if (!v) return ElMessage.warning('请先扫描/输入' + (r.manageMode === '2' ? '精密件SN' : '批次号'))
if (!currentSn.value) return ElMessage.warning('请先扫描工件SN')
binding.value = true
try {
await bindRecord({
sn: currentSn.value,
orderNo: orderNo.value || '',
processCode: Number(processCode.value),
stationNo: stationNo.value,
items: [{ materialCode: r.materialCode, bindValue: v }]
})
ElMessage.success(`绑定成功:${r.materialName || r.materialCode}`)
bindInputs[r.materialCode] = ''
loadBindPanel()
} catch (e) {
/* 错误已提示:SN重复/料不匹配/离线等 */
}
binding.value = false
}
async function removeBind(r, b) {
try {
await ElMessageBox.confirm(`撤销绑定「${b}」?`, '撤销绑定', { type: 'warning' })
} catch {
return
}
try {
await bindRemove({
sn: currentSn.value,
processCode: Number(processCode.value),
materialCode: r.materialCode,
bindValue: b
})
ElMessage.success('已撤销')
loadBindPanel()
} catch (e) {
/* 错误已提示(报工后不可撤销) */
}
}
// ---------- 步骤采集与判定 ----------
const stepValues = reactive({})
@@ -451,6 +558,11 @@ async function onProcessDone() {
ElMessage.warning('请选择工单号')
return
}
// 强校验:本工序装配物料须绑齐(精密件按用量逐颗SN、结构件至少一批次)
if (bindPanel.value && bindPanel.value.enabled && !bindPanel.value.complete) {
ElMessage.warning('装配物料未绑齐,不能上报:' + (bindPanel.value.missing || '缺料'))
return
}
const allOk = !manualNg.value && !autoNg.value
if (!allOk) {
try {
@@ -477,6 +589,8 @@ async function onProcessDone() {
} else {
ElMessage.success(allOk ? '工序完成上报成功' : '工序完成上报成功(含NG')
}
bindPanel.value = null
bindShow.value = false
loadTask()
loadStats()
} catch (e) {
@@ -1073,6 +1187,64 @@ onBeforeUnmount(() => {
.big-btn.success { background: #2aa861; }
.big-btn.success:hover { background: #239154; }
/* ---- 装机绑定卡 ---- */
.bind-card {
flex-shrink: 0;
margin: 0 20px 12px;
padding: 14px 18px;
background: #fff;
border: 2px solid #d9e4ff;
border-radius: 12px;
}
.bind-head {
display: flex;
align-items: center;
gap: 14px;
margin-bottom: 8px;
}
.bind-head .card-title { margin: 0; }
.bind-list {
display: flex;
flex-direction: column;
gap: 10px;
max-height: 150px;
overflow-y: auto;
}
.bind-item {
display: flex;
align-items: center;
gap: 14px;
padding: 8px 10px;
background: #f7f9fc;
border-radius: 8px;
}
.bind-meta {
display: flex;
align-items: center;
gap: 8px;
min-width: 300px;
flex-wrap: wrap;
}
.bind-name { font-size: 17px; font-weight: bold; color: #16324f; }
.bind-code { color: #909399; font-size: 13px; }
.bind-count { font-size: 16px; font-weight: bold; }
.bind-count.ok { color: #2aa861; }
.bind-count.ng { color: #d80f16; }
.bind-bound {
display: flex;
align-items: center;
gap: 4px;
flex: 1;
min-width: 140px;
flex-wrap: wrap;
}
.bind-input-row {
display: flex;
gap: 6px;
min-width: 300px;
}
.bind-input-row .el-input { flex: 1; }
/* ---- 我的工作量弹窗 ---- */
.wl-stat { text-align: center; }
.wl-label { color: #909399; font-size: 14px; margin-bottom: 6px; }
@@ -0,0 +1,81 @@
package handler
import (
"encoding/json"
"io"
"net/http"
"net/url"
"strings"
"bj_power_workstation/internal/svc"
)
// bindPanelHandler 代理 MES GET /api/internal/workpiece/bind-panel?sn=&processCode=。
// 工位终端扫码工件后拉取本工序应装/已装物料清单(装机绑定引导),响应原样透传。
func bindPanelHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
sn := strings.TrimSpace(r.URL.Query().Get("sn"))
processCode := strings.TrimSpace(r.URL.Query().Get("processCode"))
if sn == "" || processCode == "" {
fail(w, http.StatusBadRequest, "缺少 sn / processCode 参数")
return
}
body, _, err := ctx.Mes.Get("/api/internal/workpiece/bind-panel",
url.Values{"sn": {sn}, "processCode": {processCode}})
if err != nil {
fail(w, http.StatusBadGateway, "MES 服务不可达:"+errString(err))
return
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusOK)
_, _ = w.Write(body)
}
}
// bindRecordHandler POST /api/bind/record —— 工位扫/录一个物料(SN/批次)→ MES 装机绑定。
// 透传原 body,MES 负责校验(料是否属于本产品本工序 / 精密件SN防重 / 幂等)。
func bindRecordHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
payload, err := io.ReadAll(r.Body)
if err != nil {
fail(w, http.StatusBadRequest, "请求体读取失败")
return
}
var probe struct {
Sn string `json:"sn"`
ProcessCode int `json:"processCode"`
}
_ = json.Unmarshal(payload, &probe)
if probe.Sn == "" || probe.ProcessCode <= 0 {
fail(w, http.StatusBadRequest, "sn / processCode 必填")
return
}
body, _, err := ctx.Mes.Post("/api/internal/workpiece/binds", json.RawMessage(payload))
if err != nil {
fail(w, http.StatusBadGateway, "MES 服务不可达:"+errString(err))
return
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusOK)
_, _ = w.Write(body)
}
}
// bindRemoveHandler POST /api/bind/remove —— 撤销误绑(未报工前)
func bindRemoveHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
payload, err := io.ReadAll(r.Body)
if err != nil {
fail(w, http.StatusBadRequest, "请求体读取失败")
return
}
body, _, err := ctx.Mes.Post("/api/internal/workpiece/binds/remove", json.RawMessage(payload))
if err != nil {
fail(w, http.StatusBadGateway, "MES 服务不可达:"+errString(err))
return
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusOK)
_, _ = w.Write(body)
}
}
@@ -2,6 +2,7 @@ package handler
import (
"encoding/json"
"fmt"
"net/http"
"bj_power_workstation/internal/svc"
@@ -9,10 +10,35 @@ import (
"github.com/zeromicro/go-zero/core/logx"
)
// mesRespCode 解析 MES 统一响应 {code,message}。
// MES 业务失败约定为 HTTP 200 + code!=0httpx.Fail),HTTP 层无法区分,必须显式解析业务码。
// code==0 返回空串;code!=0 返回 message(供调用方直接透传给前端)。
func mesRespCode(respBody []byte) string {
if len(respBody) == 0 {
return ""
}
var mr struct {
Code int `json:"code"`
Message string `json:"message"`
}
if err := json.Unmarshal(respBody, &mr); err != nil {
return ""
}
if mr.Code == 0 {
return ""
}
if mr.Message != "" {
return mr.Message
}
return fmt.Sprintf("MES 拒绝本次操作(业务码 %d)", mr.Code)
}
// processDoneHandler POST /api/report/process-done
// {sn, processCode, stationNo, steps:[{stepId,name,value,text}]}
// {sn, orderNo, processCode, stationNo, steps:[{stepId,name,value,text}], binds:[{materialCode,bindValue}], operator}
// 流程:先冲刷一轮积压 → 实时报 MES /api/internal/station/report
// MES 不可达则写入 report_queue(kind=process_done) 并返回 data.queued=true(离线缓存稍后自动重传)
// MES 不可达则写入 report_queue(kind=process_done) 并返回 data.queued=true(离线缓存稍后自动重传)
// MES 业务拒绝(HTTP200+code!=0,如装配物料未绑齐/精密件SN重复)直接失败回前端,绝不入离线队。
// binds 为本次工序的装机绑定(结构件批次/精密件SN),MES 端落库 + 齐套强校验;离线重传时原样携带。
func processDoneHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
@@ -26,6 +52,10 @@ func processDoneHandler(ctx *svc.ServiceContext) http.HandlerFunc {
Value float64 `json:"value"`
Text string `json:"text"`
} `json:"steps"`
Binds []struct {
MaterialCode string `json:"materialCode"`
BindValue string `json:"bindValue"`
} `json:"binds"`
Operator string `json:"operator"`
}
if err := parseJSON(r, &req); err != nil {
@@ -48,12 +78,16 @@ func processDoneHandler(ctx *svc.ServiceContext) http.HandlerFunc {
"steps": req.Steps,
"operator": req.Operator,
}
if len(req.Binds) > 0 {
body["binds"] = req.Binds
}
payloadBytes, _ := json.Marshal(body)
ctx.Store.AddEventLog(req.OrderNo, req.Operator, "process_done",
"工序完成上报 sn="+req.Sn+" stationNo="+itoa(req.StationNo)+" processCode="+itoa(req.ProcessCode))
"工序完成上报 sn="+req.Sn+" stationNo="+itoa(req.StationNo)+" processCode="+itoa(req.ProcessCode)+" binds="+itoa(len(req.Binds)))
if _, _, err := ctx.Mes.Post("/api/internal/station/report", json.RawMessage(payloadBytes)); err != nil {
respBody, _, err := ctx.Mes.Post("/api/internal/station/report", json.RawMessage(payloadBytes))
if err != nil {
if qerr := ctx.Store.InsertQueueItem("process_done", string(payloadBytes)); qerr != nil {
fail(w, http.StatusInternalServerError, "上报失败且离线队列写入失败:"+qerr.Error())
return
@@ -62,6 +96,12 @@ func processDoneHandler(ctx *svc.ServiceContext) http.HandlerFunc {
ok(w, map[string]any{"queued": true})
return
}
// MES 业务拒绝(HTTP200+code!=0):缺料/SN冲突等,直接失败,不入队
if msg := mesRespCode(respBody); msg != "" {
logx.Errorf("工序完成上报被 MES 拒绝: %s", msg)
fail(w, http.StatusConflict, msg)
return
}
ok(w, map[string]any{"queued": false})
}
@@ -103,7 +143,8 @@ func tempStoreHandler(ctx *svc.ServiceContext) http.HandlerFunc {
ctx.Store.AddEventLog(req.OrderNo, req.Operator, "temp_store",
"暂存/退回库房 sn="+req.Sn+" stationNo="+itoa(req.StationNo))
if _, _, err := ctx.Mes.Post("/api/internal/station/checkin", json.RawMessage(payloadBytes)); err != nil {
respBody, _, err := ctx.Mes.Post("/api/internal/station/checkin", json.RawMessage(payloadBytes))
if err != nil {
if qerr := ctx.Store.InsertQueueItem("temp_store", string(payloadBytes)); qerr != nil {
fail(w, http.StatusInternalServerError, "上报失败且离线队列写入失败:"+qerr.Error())
return
@@ -112,6 +153,12 @@ func tempStoreHandler(ctx *svc.ServiceContext) http.HandlerFunc {
ok(w, map[string]any{"queued": true})
return
}
// MES 业务拒绝(HTTP200+code!=0)→ 直接失败,不入队
if msg := mesRespCode(respBody); msg != "" {
logx.Errorf("暂存退库被 MES 拒绝: %s", msg)
fail(w, http.StatusConflict, msg)
return
}
ok(w, map[string]any{"queued": false})
}
@@ -29,6 +29,9 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{Method: http.MethodGet, Path: "/api/task/current", Handler: taskCurrentHandler(ctx)},
{Method: http.MethodGet, Path: "/api/bind/panel", Handler: bindPanelHandler(ctx)},
{Method: http.MethodPost, Path: "/api/bind/record", Handler: bindRecordHandler(ctx)},
{Method: http.MethodPost, Path: "/api/bind/remove", Handler: bindRemoveHandler(ctx)},
{Method: http.MethodGet, Path: "/api/workload", Handler: workloadHandler(ctx)},
{Method: http.MethodGet, Path: "/api/pdf", Handler: pdfQueryHandler(ctx)},
{Method: http.MethodGet, Path: "/pdfopen/:name", Handler: pdfOpenHandler(ctx)},
+1 -1
View File
@@ -6,7 +6,7 @@
<title>工位终端</title>
<!-- 系统图标:工位终端屏(内联 SVG,避免依赖外部文件) -->
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><rect width='32' height='32' rx='6' fill='%231668dc'/><rect x='6' y='7' width='20' height='14' rx='2' fill='none' stroke='%23fff' stroke-width='2'/><path d='M12 25h8M16 21v4' stroke='%23fff' stroke-width='2' stroke-linecap='round'/></svg>">
<script type="module" crossorigin src="/assets/index-PF1EWCik.js"></script>
<script type="module" crossorigin src="/assets/index-B40M7DT5.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-Dz4RGjfJ.css">
</head>
<body>