feat(mes/wms/终端): 工位终端状态感知 + 全厂统一账号 + 单号短号规则 + 退料SN逐颗核对闭环(2026-11-26~28 现场整改)
【MES · 工位终端状态感知(11-28 第十三节拍板)】 - 新增 station_terminal_state / station_terminal_event 两表:当前状态镜像 + 状态变化流水 - 在线判定走既有 SSE 长连接存活:建连/断连/30s ping 心跳,90s 无心跳判离线,零 HTTP 轮询 - 登录/退出/暂停/恢复由终端事件驱动上报;新增「终端状态」管理页(produce.terminalstate,仅超级管理员):看在线/登录/操作人/接单/下班判定/心跳,抽屉看状态流水 - 库管代退料前置条件②「工人已下班」据此判定:未登录或终端离线任一即下班 【工位终端 · 全厂统一账号(11-28 拍板)】 - 删除本地账号表与 seed,登录直连 MES 用户表;本地 SQLite 只剩操作日志+登录态,断网不能换人 - SSE 客户端携带本机固定工位号,MES 据连接存活映射该工位在线状态 【单号短号规则(11-27 拍板)】 - 叫料单 MR / 叫料包 PK / 转产退库 TR / 配送单 DL:改「前缀+YYMMDD+3位当天序号」,每天从 001 归零、超 999 进 4 位 - MR 与 TR 同列不同前缀独立计数不撞号;进程内互斥分配 + DB 唯一索引兜底;历史时间戳号一律不动 【退料闭环(11-28)】 - 退库单新增 sn_list:工位提交的待退 SN 清单落库,收货逐颗扫码核对(不按批次分组、允许跨批次混合,所属批次系统按 SN 带出,库管不必填) - 收货改大数量必须有实物依据:SN 件以精确扫描的最终清单为准(条数相等且不重复);批次件必须落到真实启用的四级库位,禁止凭空加库存 - 余量参考值口径定稿(N4):应剩余量 = 实际备料 − 已消耗 − 已退 − 已损耗 - 损耗台账取消「后审核批注」:删 status/comment/commenter/commented_at 字段,WMS 确认收货当场落账闭环,MES 台账只读 【日排产 · 两种 PENDING 区分(11-26 口径定稿)】 - daily_plan 新增 discarded 废弃标记:停用打标、新建不打标;额度只算 CONFIRMED + 未废弃 PENDING - 工单管「要干几台」、日排产管「按天从哪个工位领多少料」,两张账不合并不互倒推;排产合计可小于工单数(缺口靠借料/补料审批摆出,不自动兜底) 【其他】 - SN 查询大小写脱敏(11-27):存储原样不强制大小写,匹配 LOWER(sn)=LOWER(?),扫 ABC-0001 与 abc-0001 命中同一件 - 拧紧枪人工跳过链路:设备未连接时人工跳过上报,「拧紧跳过(设备未连接)」前缀单独列示,不写 torque_record 绝不冒充设备结果 - 单据流转提示规则表全量 35 条(MES 18 + WMS 17):常驻提示条、单号可复制;单号字段逐条对后端响应实测,取不到不显示复制按钮 - PLC 快照缓存/对账、产线清线、绩效与拧紧枪配置页同步修正 【文档】 - 新增《临时结束.md》2026-11-26 日排产/叫料/完工口径大讨论定稿(含状态专项结论与被推翻旧说法留档);问题临时.md 全量更新
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -15,8 +16,8 @@ import (
|
||||
"bj_power_mes/ent/processflow"
|
||||
"bj_power_mes/ent/processstep"
|
||||
"bj_power_mes/ent/station"
|
||||
"bj_power_mes/ent/stepcriterion"
|
||||
"bj_power_mes/ent/workorder"
|
||||
"bj_power_mes/ent/workpiecelifecyclelog"
|
||||
"bj_power_mes/ent/workpieceprocess"
|
||||
"bj_power_mes/internal/verr"
|
||||
|
||||
@@ -196,7 +197,7 @@ func (s *Service) SaveFlow(ctx context.Context, req FlowReq, operator string) er
|
||||
if st.Name == "" {
|
||||
continue
|
||||
}
|
||||
rec, err := s.ctx.EntClient.ProcessStep.Create().
|
||||
_, err := s.ctx.EntClient.ProcessStep.Create().
|
||||
SetFlowId(flowID).SetSeq(st.Seq).SetName(st.Name).
|
||||
SetCollectType(st.CollectType).SetNeedCheck(st.NeedCheck).
|
||||
SetNeedOperatorSign(st.NeedOperatorSign).SetNeedInspectorSign(st.NeedInspectorSign).
|
||||
@@ -204,23 +205,7 @@ func (s *Service) SaveFlow(ctx context.Context, req FlowReq, operator string) er
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, _ = s.ctx.EntClient.StepCriterion.Delete().Where(stepcriterion.StepId(rec.ID)).Exec(ctx)
|
||||
for _, c := range st.Criteria {
|
||||
if c.Name == "" || c.Logic == "" || c.Logic == "NONE" {
|
||||
continue
|
||||
}
|
||||
b := s.ctx.EntClient.StepCriterion.Create().
|
||||
SetStepId(rec.ID).SetName(c.Name).SetUnit(c.Unit).SetLogic(c.Logic).SetTarget(c.Target)
|
||||
if c.Min != nil {
|
||||
b = b.SetMin(*c.Min)
|
||||
}
|
||||
if c.Max != nil {
|
||||
b = b.SetMax(*c.Max)
|
||||
}
|
||||
if err := b.Exec(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// 2026-11-26:考核标准整体撤销,不再写 step_criterion;历史数据挂起不删,保留供追溯
|
||||
}
|
||||
s.ctx.EventLog.Write(ctx, "process.flow.save", "", operator, "process_flow", "", "维护工艺流程",
|
||||
map[string]any{"flowId": flowID, "stations": stations, "steps": len(req.Steps)})
|
||||
@@ -263,14 +248,6 @@ func (s *Service) flowSteps(ctx context.Context, flowId int) []*ProcessStepTempl
|
||||
NeedOperatorSign: st.NeedOperatorSign, NeedInspectorSign: st.NeedInspectorSign,
|
||||
Remark: st.Remark, Attachment: st.Attachment, Criteria: []CriterionVO{},
|
||||
}
|
||||
crits, _ := s.ctx.EntClient.StepCriterion.Query().
|
||||
Where(stepcriterion.StepId(st.ID)).All(ctx)
|
||||
for _, c := range crits {
|
||||
t.Criteria = append(t.Criteria, CriterionVO{
|
||||
ID: c.ID, Name: c.Name, Unit: c.Unit, Logic: c.Logic,
|
||||
Target: c.Target, Min: c.Min, Max: c.Max,
|
||||
})
|
||||
}
|
||||
out = append(out, t)
|
||||
}
|
||||
return out
|
||||
@@ -341,10 +318,12 @@ func (s *Service) ListStations(ctx context.Context) ([]*StationVO, error) {
|
||||
// 内置工位(种子/初始化数据,is_builtin=true)需连 PLC 并必须按工位号顺序流转,
|
||||
// 不允许手动更改工位类型;页面新增的工位一律为非内置,可改类型、可删除。
|
||||
// 接驳台为独立主数据(MES dock 表),一个工位可绑定多个接驳台,关系以 dock.station_no 为准,页面不维护。
|
||||
// stationHasActiveWorkOrder 工位是否正被"进行中"工单的生产路线引用(flow_combination 含该 stationNo)。
|
||||
// 进行中 = IN_PROGRESS(执行中) / PAUSED(已暂停) / RELEASED(残量已下发待开工):这些状态下路线已固定,禁止改绑定。
|
||||
// stationHasActiveWorkOrder 工位是否正被"执行中"工单的生产路线引用(flow_combination 含该 stationNo)。
|
||||
// 2026-11-27 用户拍板:「暂停=清线=让位」——PAUSED 已从占用名单移除,暂停的工单不再拦工位改绑/换绑,
|
||||
// 好让产线清线后接其它工单。占用名单只留 IN_PROGRESS(执行中) / RELEASED(残量已下发待开工,马上要干,路线不能中途改)。
|
||||
// 开工时路线核对统一压到 SetWorkOrderStatus(PAUSED→IN_PROGRESS) 里做 ValidateFlowCombinationCollect。
|
||||
func (s *Service) stationHasActiveWorkOrder(ctx context.Context, stationNo int) (bool, error) {
|
||||
active := []string{"IN_PROGRESS", "PAUSED", "RELEASED"}
|
||||
active := []string{"IN_PROGRESS", "RELEASED"}
|
||||
orders, err := s.ctx.EntClient.WorkOrder.Query().Where(workorder.StatusIn(active...)).All(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -689,6 +668,10 @@ type WorkloadRow struct {
|
||||
DoneCount int `json:"doneCount"`
|
||||
OkCount int `json:"okCount"`
|
||||
NgCount int `json:"ngCount"`
|
||||
// 工位维度只读实绩(2026-11-26 拍板):实际报工数=工位上 workpiece_process 的报工行数;
|
||||
// 实际完工数=工件级完工流水(action=DONE)按工位归属、同一 SN 去重。不加计划列、不加差额、不加红黄。
|
||||
ReportCount int `json:"reportCount"`
|
||||
FinishedCount int `json:"finishedCount"`
|
||||
// Item M 绩效效率:作业时长取自 workpiece_process.duration_sec
|
||||
TotalDurationSec int `json:"totalDurationSec"` // 累计作业时长(秒)
|
||||
AvgDurationSec int `json:"avgDurationSec"` // 平均作业时长(秒)=累计/完成数
|
||||
@@ -872,6 +855,47 @@ func (s *Service) Workload(ctx context.Context, operator, stationNo, orderNo, fr
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 工位维度「实际完工数」:工件级完工流水(action=DONE)按工位归属,同一 SN 暂存重上线可能多次 DONE,
|
||||
// 按 工位|SN 去重。stationNo 是 int:正常完工=末道工艺工位,强行完工=0(不归入任何工位)。
|
||||
finishedByStation := map[string]int{}
|
||||
{
|
||||
lq := s.ctx.EntClient.WorkpieceLifecycleLog.Query().Where(workpiecelifecyclelog.ActionEQ("DONE"))
|
||||
if from != "" {
|
||||
if f, perr := time.Parse("2006-01-02", from); perr == nil {
|
||||
lq = lq.Where(workpiecelifecyclelog.CreatedAtGTE(f))
|
||||
}
|
||||
}
|
||||
if to != "" {
|
||||
if t, perr := time.Parse("2006-01-02", to); perr == nil {
|
||||
lq = lq.Where(workpiecelifecyclelog.CreatedAtLT(t.Add(24 * time.Hour)))
|
||||
}
|
||||
}
|
||||
if orderNo != "" {
|
||||
lq = lq.Where(workpiecelifecyclelog.WorkOrderNoContainsFold(orderNo))
|
||||
}
|
||||
if stationNo != "" {
|
||||
if n, cerr := strconv.Atoi(stationNo); cerr == nil {
|
||||
lq = lq.Where(workpiecelifecyclelog.StationNo(n))
|
||||
} else {
|
||||
lq = lq.Where(workpiecelifecyclelog.StationNo(-1))
|
||||
}
|
||||
}
|
||||
logs, lerr := lq.All(ctx)
|
||||
if lerr == nil {
|
||||
seen := map[string]bool{}
|
||||
for _, lg := range logs {
|
||||
if lg.StationNo <= 0 {
|
||||
continue
|
||||
}
|
||||
k := strconv.Itoa(lg.StationNo) + "|" + lg.Sn
|
||||
if seen[k] {
|
||||
continue
|
||||
}
|
||||
seen[k] = true
|
||||
finishedByStation[strconv.Itoa(lg.StationNo)]++
|
||||
}
|
||||
}
|
||||
}
|
||||
type key struct {
|
||||
op, station, date string
|
||||
code int
|
||||
@@ -958,6 +982,9 @@ func (s *Service) Workload(ctx context.Context, operator, stationNo, orderNo, fr
|
||||
sort.Slice(byOpList, func(i, j int) bool { return byOpList[i].Operator < byOpList[j].Operator })
|
||||
byStList := make([]*WorkloadRow, 0, len(byStAgg))
|
||||
for _, v := range byStAgg {
|
||||
// 实际报工数沿用报工行数;实际完工数按工件级完工流水归到末道工位
|
||||
v.ReportCount = v.DoneCount
|
||||
v.FinishedCount = finishedByStation[v.StationNo]
|
||||
finalizeWorkloadRow(v)
|
||||
byStList = append(byStList, v)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user