feat: 菜单按业务域重排为7组 + 预警中心更名异常告警 + AGV独立权限码与齐套测算分账明细
This commit is contained in:
@@ -152,7 +152,7 @@ func SeedHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 用户管理 ----------
|
||||
// ---------- 账号管理 ----------
|
||||
|
||||
func ListUsersHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -84,6 +84,15 @@ var pathPermMap = map[string]string{
|
||||
"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",
|
||||
// AGV 两个菜单拆码后各自独立校验:
|
||||
// produce.agv = AGV管理(三段链确认 / 取消 / 重试);produce.agv.manual = 人工派车(用车生命周期)。
|
||||
// 两边共用的只读点位与刷新接口(/agv/points、/agv/refresh)不映射,避免互相挡住。
|
||||
"POST:/api/v1/agv/confirm": "produce.agv",
|
||||
"POST:/api/v1/agv/cancel": "produce.agv",
|
||||
"POST:/api/v1/agv/retry": "produce.agv",
|
||||
"POST:/api/v1/agv/free-dispatch": "produce.agv.manual",
|
||||
"POST:/api/v1/agv/chain/next": "produce.agv.manual",
|
||||
"POST:/api/v1/agv/chain/end": "produce.agv.manual",
|
||||
}
|
||||
|
||||
// userHasPerm 校验当前登录用户是否拥有某权限码(SUPER_ADMIN 或 * 放行)。
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package production
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"bj_power_mes/common/httpx"
|
||||
"bj_power_mes/internal/logic"
|
||||
"bj_power_mes/internal/svc"
|
||||
)
|
||||
|
||||
// LinePointSensorInternalHandler GET /api/internal/line/point-sensor?pointNo=
|
||||
// 建档前实物核对(只读):按所选点位读 PLC 传感器实时是否有货,不触发下流、不写台账。
|
||||
// 返回 {pointNo, hasGoods, plcOk, code}:plcOk=false 表示 PLC 不可达/模拟/无法映射/位不存在,
|
||||
// 前端降级为人工确认提示;code 为映射到的 PLC 位(无法映射时空串)。
|
||||
func LinePointSensorInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
pointNo := strings.TrimSpace(r.URL.Query().Get("pointNo"))
|
||||
if pointNo == "" {
|
||||
httpx.BadRequest(w, "请先选择工件当前位置")
|
||||
return
|
||||
}
|
||||
hasGoods, plcOk, err := logic.New(svcCtx).PointSensorCheck(r.Context(), pointNo)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3010, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{
|
||||
"pointNo": pointNo,
|
||||
"hasGoods": hasGoods,
|
||||
"plcOk": plcOk,
|
||||
"code": logic.PointNoToPlcCode(pointNo),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,10 @@ package production
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"bj_power_mes/common/httpx"
|
||||
"bj_power_mes/ent/material"
|
||||
"bj_power_mes/internal/logic"
|
||||
"bj_power_mes/internal/svc"
|
||||
)
|
||||
@@ -17,6 +19,8 @@ func ShortageOnBehalfInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFun
|
||||
var req struct {
|
||||
StationNo int `json:"stationNo"`
|
||||
MaterialCode string `json:"materialCode"`
|
||||
MaterialName string `json:"materialName"`
|
||||
Unit string `json:"unit"`
|
||||
Qty int `json:"qty"`
|
||||
Reason string `json:"reason"`
|
||||
Operator string `json:"operator"`
|
||||
@@ -32,8 +36,22 @@ func ShortageOnBehalfInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFun
|
||||
if op == "" {
|
||||
op = "system"
|
||||
}
|
||||
// 物料名称/单位:WMS 未带出时按物料编码从 MES 物料档案回填,
|
||||
// 避免主管在「补料审批」看到只有图号、不知道补的是什么料和按什么计量单位补。
|
||||
materialName, unit := strings.TrimSpace(req.MaterialName), strings.TrimSpace(req.Unit)
|
||||
if materialName == "" || unit == "" {
|
||||
if m, merr := svcCtx.EntClient.Material.Query().
|
||||
Where(material.CodeEQ(strings.TrimSpace(req.MaterialCode))).Only(r.Context()); merr == nil && m != nil {
|
||||
if materialName == "" {
|
||||
materialName = m.Name
|
||||
}
|
||||
if unit == "" {
|
||||
unit = m.Unit
|
||||
}
|
||||
}
|
||||
}
|
||||
row, err := logic.New(svcCtx).CreateShortage(r.Context(), req.StationNo,
|
||||
req.MaterialCode, "", "", req.Qty, req.Reason, op)
|
||||
req.MaterialCode, materialName, unit, req.Qty, req.Reason, op)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 500, err.Error())
|
||||
return
|
||||
|
||||
@@ -240,6 +240,10 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/line/points", Handler: internal(ListPointsHandler(serverCtx)),
|
||||
})
|
||||
// 建档前点位传感器实物核对(只读,不触发下流;PLC 不可达/模拟/无法映射时前端降级人工确认)
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/line/point-sensor", Handler: internal(production.LinePointSensorInternalHandler(serverCtx)),
|
||||
})
|
||||
// ---------- 叫料(B5,供工位终端/WMS 仓库端调用,X-API-TOKEN 保护)----------
|
||||
// 工位端点:StationSessionAuth 登录态鉴权(操作人/工位号可信注入)
|
||||
server.AddRoute(rest.Route{
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// PointSensorCheck 建档前实物核对:按点位编号查该位置 PLC 传感器实时是否有货。
|
||||
// 这是只读核对——不触发下流、不写任何表、不改点位台账占用;真正的流转仍按扫码/报工推进。
|
||||
// 映射规则(点表见 internal/plc/tcp.go):
|
||||
// - C1~C15(主线 STOP/CACHE)→ PLC "C"+n,落在 BitsGroup.Main;
|
||||
// - 纯数字 1~12(工位 STATION)→ PLC "G"+n,落在 BitsGroup.Station;
|
||||
// - END-U → G11、END-D → G12(末端下料检测位对应工位 11/12);
|
||||
// - 其它(含历史 DOCK)无法映射,plcOk=false 降级。
|
||||
// PLC 为 nil / 模拟 / 读不到 / 模拟数据 / 无法映射 / 位不存在时,统一返回 plcOk=false、err=nil,
|
||||
// 由前端降级为人工确认提示;模拟数据不能当作实物凭证,读不到不阻断建档。
|
||||
func (s *Service) PointSensorCheck(ctx context.Context, pointNo string) (hasGoods bool, plcOk bool, err error) {
|
||||
p := strings.TrimSpace(pointNo)
|
||||
if p == "" {
|
||||
return false, false, nil
|
||||
}
|
||||
code := PointNoToPlcCode(p)
|
||||
if code == "" {
|
||||
return false, false, nil
|
||||
}
|
||||
// 模拟数据或 PLC 未接入:不作为实物凭证
|
||||
if s.ctx.PLC == nil || s.ctx.PLC.IsMock() {
|
||||
return false, false, nil
|
||||
}
|
||||
g, e := s.PlcMonitorBits(ctx)
|
||||
if e != nil || g.Mock {
|
||||
// 读不到 / 模拟:降级,不阻断
|
||||
return false, false, nil
|
||||
}
|
||||
for _, b := range g.Station {
|
||||
if b.Code == code {
|
||||
return b.Has, true, nil
|
||||
}
|
||||
}
|
||||
for _, b := range g.Main {
|
||||
if b.Code == code {
|
||||
return b.Has, true, nil
|
||||
}
|
||||
}
|
||||
return false, false, nil
|
||||
}
|
||||
|
||||
// PointNoToPlcCode 把点位编号映射成 PLC 位 code(禁用正则,固定格式用 HasPrefix / slice / Atoi 解析)。
|
||||
// 无法映射返回空串(前端据此降级为人工确认)。
|
||||
func PointNoToPlcCode(p string) string {
|
||||
// C 开头且后接 1~15 → "C"+n
|
||||
if strings.HasPrefix(p, "C") {
|
||||
n, e := strconv.Atoi(p[1:])
|
||||
if e != nil || n < 1 || n > 15 {
|
||||
return ""
|
||||
}
|
||||
return "C" + strconv.Itoa(n)
|
||||
}
|
||||
// 末端下料检测位 → 工位 11/12
|
||||
if p == "END-U" {
|
||||
return "G11"
|
||||
}
|
||||
if p == "END-D" {
|
||||
return "G12"
|
||||
}
|
||||
// 纯数字 1~12(工位 STATION)→ "G"+n
|
||||
n, e := strconv.Atoi(p)
|
||||
if e != nil || n < 1 || n > 12 {
|
||||
return ""
|
||||
}
|
||||
return "G" + strconv.Itoa(n)
|
||||
}
|
||||
@@ -10,7 +10,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/dailyplan"
|
||||
"bj_power_mes/ent/flowmaterial"
|
||||
"bj_power_mes/ent/productprocessmaterial"
|
||||
"bj_power_mes/ent/workorder"
|
||||
"bj_power_mes/internal/wmsclient"
|
||||
)
|
||||
@@ -50,6 +53,7 @@ type ProducibleDailyRow struct {
|
||||
Consumed float64 `json:"consumed"` // 当日消耗(当日该物料需求台数 × 单台含损耗用量)
|
||||
Before float64 `json:"before"` // 当日扣减前可用量
|
||||
Remain float64 `json:"remain"` // 当日扣减后剩余量
|
||||
Source string `json:"source"` // 账目来源:产品工艺分账 / 工序总账(无分账回退)
|
||||
}
|
||||
|
||||
// ProducibleOrderRow 单工单逐日模拟结果(按工单逐个模拟消耗)
|
||||
@@ -61,6 +65,22 @@ type ProducibleOrderRow struct {
|
||||
SupportUntil string `json:"supportUntil"`
|
||||
SupportDays int `json:"supportDays"`
|
||||
DailyRows []ProducibleDailyRow `json:"dailyRows"`
|
||||
UsageBreakdown []ProducibleUsageRow `json:"usageBreakdown"`
|
||||
}
|
||||
|
||||
// ProducibleUsageRow 抽屉里的「物料账目来源」明细:按产品工艺分账逐工序列出的单台用量。
|
||||
// 宏观测算与逐日消耗仍走工序总账口径,本结构只用于展示账目来源,不参与计算。
|
||||
type ProducibleUsageRow struct {
|
||||
Seq int `json:"seq"` // 工单工艺组合中的第几道工序
|
||||
FlowId int `json:"flowId"`
|
||||
FlowName string `json:"flowName"`
|
||||
MaterialCode string `json:"materialCode"`
|
||||
MaterialName string `json:"materialName"`
|
||||
Unit string `json:"unit"`
|
||||
UnitQty float64 `json:"unitQty"` // 单台净用量
|
||||
LossRate float64 `json:"lossRate"` // 损耗率%(展示口径,取工序总账)
|
||||
EffQty float64 `json:"effQty"` // 单台含损耗用量
|
||||
Source string `json:"source"` // 产品工艺分账 / 工序总账(无分账回退)
|
||||
}
|
||||
|
||||
// ProducibleBottleneck 总支撑瓶颈:最早见底那个工单
|
||||
@@ -361,9 +381,119 @@ func (s *Service) ComputeProducibleSupport(ctx context.Context) (*ProducibleSupp
|
||||
codeByOrder[it.OrderNo] = it.ProductCode
|
||||
}
|
||||
res.Orders, res.Bottleneck = s.simulateSupportByOrder(ctx, usageByOrder, base.Avail, qtyByOrder, codeByOrder)
|
||||
|
||||
// 逐工单补「物料账目来源」明细:宏观汇总与逐日消耗口径不变(工序总账),
|
||||
// 明细区另按产品工艺分账逐工序展示实际领料量,点进抽屉即可核到账目来源。
|
||||
breakdownByOrder := s.loadUsageBreakdown(ctx, orderNosOf(base.Items))
|
||||
for i := range res.Orders {
|
||||
rows := breakdownByOrder[res.Orders[i].WorkOrderNo]
|
||||
res.Orders[i].UsageBreakdown = rows
|
||||
srcByCode := map[string]string{}
|
||||
for _, r := range rows {
|
||||
if _, has := srcByCode[r.MaterialCode]; !has || r.Source == "产品工艺分账" {
|
||||
srcByCode[r.MaterialCode] = r.Source
|
||||
}
|
||||
}
|
||||
for j := range res.Orders[i].DailyRows {
|
||||
src := srcByCode[res.Orders[i].DailyRows[j].MaterialCode]
|
||||
if src == "" {
|
||||
src = "工序总账"
|
||||
}
|
||||
res.Orders[i].DailyRows[j].Source = src
|
||||
}
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// loadUsageBreakdown 批量加载工单的「物料账目来源」明细(工单号 → 分账明细行)。
|
||||
func (s *Service) loadUsageBreakdown(ctx context.Context, orderNos []string) map[string][]ProducibleUsageRow {
|
||||
out := map[string][]ProducibleUsageRow{}
|
||||
if len(orderNos) == 0 {
|
||||
return out
|
||||
}
|
||||
wos, err := s.ctx.EntClient.WorkOrder.Query().
|
||||
Where(workorder.WorkOrderNoIn(orderNos...)).All(ctx)
|
||||
if err != nil {
|
||||
return out
|
||||
}
|
||||
for _, wo := range wos {
|
||||
out[wo.WorkOrderNo] = s.orderUsageBreakdown(ctx, wo)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// orderUsageBreakdown 按产品工艺分账(product_process_material)逐工序列出单台用量:
|
||||
// ① 该工序在分账里有行 → 用分账行的单台净用量,损耗率取工序总账同名物料,来源标「产品工艺分账」;
|
||||
// ② 该工序无分账行 → 回退 flow_material 工序总账,来源标「工序总账(无分账回退)」;
|
||||
// ③ 工单无来源产品工艺 → 全部回退总账。
|
||||
// 与 MaterialsByFlowForWO(叫料/备料/装机绑定的算料口径)同源,仅用于抽屉展示,不参与上方宏观测算。
|
||||
func (s *Service) orderUsageBreakdown(ctx context.Context, wo *ent.WorkOrder) []ProducibleUsageRow {
|
||||
if wo == nil || s.ctx.EntClient == nil {
|
||||
return []ProducibleUsageRow{}
|
||||
}
|
||||
items, _ := RouteStationsFromWO(ctx, s.ctx.EntClient, wo)
|
||||
seen := map[int]bool{}
|
||||
flowIDs := make([]int, 0, len(items))
|
||||
for _, it := range items {
|
||||
if it.FlowId > 0 && !seen[it.FlowId] {
|
||||
seen[it.FlowId] = true
|
||||
flowIDs = append(flowIDs, it.FlowId)
|
||||
}
|
||||
}
|
||||
if len(flowIDs) == 0 {
|
||||
return []ProducibleUsageRow{}
|
||||
}
|
||||
flowName := map[int]string{}
|
||||
for _, fid := range flowIDs {
|
||||
if f, err := s.ctx.EntClient.ProcessFlow.Get(ctx, fid); err == nil {
|
||||
flowName[fid] = f.Name
|
||||
}
|
||||
}
|
||||
allocByFlow := map[int][]*ent.ProductProcessMaterial{}
|
||||
if wo.ProductProcessId > 0 {
|
||||
if rows, err := s.ctx.EntClient.ProductProcessMaterial.Query().
|
||||
Where(productprocessmaterial.ProductProcessId(wo.ProductProcessId)).All(ctx); err == nil {
|
||||
for _, r := range rows {
|
||||
allocByFlow[r.FlowId] = append(allocByFlow[r.FlowId], r)
|
||||
}
|
||||
}
|
||||
}
|
||||
fms, _ := s.ctx.EntClient.FlowMaterial.Query().
|
||||
Where(flowmaterial.FlowIdIn(flowIDs...)).All(ctx)
|
||||
lossByCode := map[string]float64{}
|
||||
fmByFlow := map[int][]*ent.FlowMaterial{}
|
||||
for _, fm := range fms {
|
||||
lossByCode[fm.MaterialCode] = fm.LossRate
|
||||
fmByFlow[fm.FlowId] = append(fmByFlow[fm.FlowId], fm)
|
||||
}
|
||||
out := make([]ProducibleUsageRow, 0, len(fms))
|
||||
for seq, fid := range flowIDs {
|
||||
rows := allocByFlow[fid]
|
||||
if len(rows) > 0 {
|
||||
sort.SliceStable(rows, func(i, j int) bool { return rows[i].Seq < rows[j].Seq })
|
||||
for _, r := range rows {
|
||||
loss := lossByCode[r.MaterialCode]
|
||||
out = append(out, ProducibleUsageRow{
|
||||
Seq: seq + 1, FlowId: fid, FlowName: flowName[fid],
|
||||
MaterialCode: r.MaterialCode, MaterialName: r.MaterialName, Unit: r.Unit,
|
||||
UnitQty: r.UnitQty, LossRate: loss,
|
||||
EffQty: r.UnitQty * (1 + loss/100), Source: "产品工艺分账",
|
||||
})
|
||||
}
|
||||
continue
|
||||
}
|
||||
for _, fm := range fmByFlow[fid] {
|
||||
out = append(out, ProducibleUsageRow{
|
||||
Seq: seq + 1, FlowId: fid, FlowName: flowName[fid],
|
||||
MaterialCode: fm.MaterialCode, MaterialName: fm.MaterialName, Unit: fm.Unit,
|
||||
UnitQty: fm.UnitQty, LossRate: fm.LossRate,
|
||||
EffQty: fm.UnitQty * (1 + fm.LossRate/100), Source: "工序总账(无分账回退)",
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// orderNosOf 从可生产结果提取工单号(保持顺序)
|
||||
func orderNosOf(items []wmsclient.ProducibleItem) []string {
|
||||
out := make([]string, 0, len(items))
|
||||
|
||||
@@ -248,14 +248,21 @@ func (s *Service) SaveProcessAllocations(ctx context.Context, productProcessID i
|
||||
return nil
|
||||
}
|
||||
|
||||
// saveAllocations 分账整表覆盖(跟随产品工艺保存,同一事务语义外但按先删后插保证幂等)。
|
||||
// saveAllocations 分账整表覆盖(跟随产品工艺保存):先删后插放在同一事务里,
|
||||
// 中途任一条插入失败整批回滚,不留下「旧账已删、新账只插一半」的半套账
|
||||
// (叫料/备料/装机绑定都按分账算量,半套账会直接漏料)。
|
||||
func (s *Service) saveAllocations(ctx context.Context, productProcessID int, allocs []BOMAllocation) error {
|
||||
if _, err := s.ctx.EntClient.ProductProcessMaterial.Delete().
|
||||
tx, err := s.ctx.EntClient.Tx(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if _, err := tx.ProductProcessMaterial.Delete().
|
||||
Where(productprocessmaterial.ProductProcessId(productProcessID)).Exec(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, a := range allocs {
|
||||
if err := s.ctx.EntClient.ProductProcessMaterial.Create().
|
||||
if err := tx.ProductProcessMaterial.Create().
|
||||
SetProductProcessId(productProcessID).SetSeq(a.Seq).SetFlowId(a.FlowId).
|
||||
SetMaterialCode(strings.TrimSpace(a.MaterialCode)).
|
||||
SetMaterialName(a.MaterialName).SetUnit(a.Unit).SetUnitQty(a.UnitQty).
|
||||
@@ -263,7 +270,7 @@ func (s *Service) saveAllocations(ctx context.Context, productProcessID int, all
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
// MaterialsByFlowForWO 叫料/备料/装机绑定的物料口径(2026-11-13「总分制」拍板:叫料必须按工序分账的量去叫):
|
||||
|
||||
@@ -35,7 +35,7 @@ func (s *Service) Seed(ctx context.Context) error {
|
||||
// PLC 手动监控(只读点位/在途 + 手动下发,仅菜单权限,不另设操作权限码)
|
||||
"produce.plc.monitor",
|
||||
// 产线管理(块 E:4 tab,含工件位置纠正)与 AGV 配送(AGV 真源已在 MES):仅菜单权限
|
||||
"produce.line.manage", "produce.agv",
|
||||
"produce.line.manage", "produce.agv", "produce.agv.manual",
|
||||
// 产品工艺(产品级工艺定义,2026-10-09)+ 待审核签字
|
||||
"produce.productprocess", "produce.audit",
|
||||
// 按钮级权限(块2)
|
||||
@@ -45,7 +45,7 @@ func (s *Service) Seed(ctx context.Context) error {
|
||||
"produce.processflow:add", "produce.processflow:edit", "produce.processflow:delete",
|
||||
"produce.processflow:upload", "produce.station:edit", "produce.station:add", "produce.station:delete",
|
||||
"produce.productprocess:add", "produce.productprocess:edit", "produce.productprocess:delete",
|
||||
// 预警中心 / 附件中心(含归档清理按钮)
|
||||
// 异常告警 / 附件中心(含归档清理按钮)
|
||||
"sys.alert", "sys.attachment", "sys.attachment:manage",
|
||||
// 数量不符处理(上报在工位终端,处理在本页)
|
||||
"produce.qty", "produce.qty:handle",
|
||||
@@ -94,27 +94,28 @@ func (s *Service) Seed(ctx context.Context) error {
|
||||
menus := []struct{ code, name, typ, path string }{
|
||||
{"produce.workorder", "工单管理", "MENU", "/work-order"},
|
||||
{"produce.dailyplan", "日排产", "MENU", "/daily-plan"},
|
||||
{"produce.producible", "排产支撑", "MENU", "/producible-support"},
|
||||
{"produce.producible", "齐套测算", "MENU", "/producible-support"},
|
||||
{"produce.material", "叫料单", "MENU", "/material-request"},
|
||||
{"produce.qty", "收料差异登记", "MENU", "/qty-report"},
|
||||
{"produce.plc", "工位下发", "MENU", "/plc-send"},
|
||||
{"produce.plc.monitor", "PLC管理", "MENU", "/plc-monitor"},
|
||||
{"produce.processflow", "工艺", "MENU", "/process-flow"},
|
||||
{"produce.processflow", "产品工艺", "MENU", "/process-flow"},
|
||||
{"produce.station", "工位管理", "MENU", "/station"}, {"produce.performance", "绩效报表", "MENU", "/performance"},
|
||||
// 产线管理(块 E):顶部 4 tab = 工位状态 / 缓存状态 / 接驳台维护 / 工件位置纠正。
|
||||
// 原独立「接驳台维护」菜单并入本页 tab3,不再单独授权(produce.dock 已退役)。
|
||||
{"produce.line.manage", "产线管理", "MENU", "/line-management"},
|
||||
// AGV 配送(块 E.1):AGV 唯一真源在 MES,「AGV配送」页自 WMS 迁入(操作+状态合并)
|
||||
{"produce.agv", "AGV配送", "MENU", "/agv"},
|
||||
// AGV 管理(块 E.1):AGV 唯一真源在 MES,「AGV管理」页自 WMS 迁入(操作+状态合并)
|
||||
{"produce.agv", "AGV管理", "MENU", "/agv"},
|
||||
{"produce.agv.manual", "人工派车", "MENU", "/agv-manual"},
|
||||
{"produce.trace", "工件追溯", "MENU", "/trace"},
|
||||
{"produce.wip", "在制品", "MENU", "/wip"},
|
||||
{"produce.wip", "在制品追踪", "MENU", "/wip"},
|
||||
// 2026-11-10 补登:前端 MainLayout 已有菜单码、此前 seed 漏登,导致无法授权给任何角色
|
||||
{"produce.transfer", "转产退料", "MENU", "/transfer-return"},
|
||||
{"produce.shortage", "补料管理", "MENU", "/shortage"},
|
||||
{"produce.transfer", "生产退料", "MENU", "/transfer-return"},
|
||||
{"produce.shortage", "补料审批", "MENU", "/shortage"},
|
||||
{"produce.loss", "损耗台账", "MENU", "/loss-ledger"},
|
||||
{"produce.processcard", "生产流程卡", "MENU", "/process-card"},
|
||||
{"produce.audit", "待审核签字", "MENU", "/audit-pending"},
|
||||
{"produce.product", "物料档案", "MENU", "/product-type"},
|
||||
{"produce.audit", "签字复核", "MENU", "/audit-pending"},
|
||||
{"produce.product", "成品档案", "MENU", "/product-type"},
|
||||
{"produce.quality", "质量检验", "MENU", "/quality"},
|
||||
{"sys.inspect", "巡检终端", "MENU", "/inspect"},
|
||||
{"sys.eventlog", "操作日志", "MENU", "/event-log"},
|
||||
@@ -125,11 +126,11 @@ func (s *Service) Seed(ctx context.Context) error {
|
||||
{"sys.settings", "基础设置", "MENU", "/settings"},
|
||||
// 拧紧枪配置(2026-11-09):控制器地址 + 枪1/2/3 通道号仅展示,不参与拧紧数据收集
|
||||
{"sys.torqueconfig", "拧紧枪配置", "MENU", "/torque-gun-config"},
|
||||
// 预警中心 / 附件中心此前只有前端菜单码(MainLayout menuGroups)、权限表未登记,
|
||||
// 异常告警 / 附件中心此前只有前端菜单码(MainLayout menuGroups)、权限表未登记,
|
||||
// 导致这两个菜单无法授权给任何角色(只有 SUPER_ADMIN 靠 roleCode 旁路可见),2026-09-19 补齐。
|
||||
{"sys.alert", "预警中心", "MENU", "/alert-center"},
|
||||
// 2026-11-10 补登:预警规则页菜单码此前 seed 漏登
|
||||
{"sys.alertrule", "预警规则", "MENU", "/alert-rule"},
|
||||
{"sys.alert", "异常告警", "MENU", "/alert-center"},
|
||||
// 2026-11-10 补登:告警配置页菜单码此前 seed 漏登
|
||||
{"sys.alertrule", "告警配置", "MENU", "/alert-rule"},
|
||||
// 同步失败台账(2026-11-08):跨系统通知失败人工重试,不自动重传
|
||||
{"sys.syncfailure", "同步失败台账", "MENU", "/sync-failure"},
|
||||
{"sys.attachment", "附件中心", "MENU", "/attachment"},
|
||||
@@ -231,9 +232,9 @@ func (s *Service) Seed(ctx context.Context) error {
|
||||
// 同步失败台账(2026-11-08):人工重试/标记已处理,与 perm.go 的 POST 路径映射同码
|
||||
{"sys.syncfailure:retry", "同步失败台账-重试/标记已处理", "BUTTON", "", "sys.syncfailure"},
|
||||
// PLC↔MES 对账结果「忽略确认」(#8 T7,管理员级):仅超级管理员(*)持有,操作员不给;
|
||||
// 前端入口在预警中心(sys.alert),parent 挂 sys.alert。
|
||||
// 前端入口在异常告警(sys.alert),parent 挂 sys.alert。
|
||||
{"produce.plc.mismatch:override", "PLC对账-忽略确认", "BUTTON", "", "sys.alert"},
|
||||
// 拧紧不合格人工处置(B6 最小闭环):质检/班组长确认放行,入口在工件追溯页与预警中心(torque_ng 项);
|
||||
// 拧紧不合格人工处置(B6 最小闭环):质检/班组长确认放行,入口在工件追溯页与异常告警(torque_ng 项);
|
||||
// parent 挂 sys.alert(与 override 同源)。
|
||||
{"produce.torque:dispose", "拧紧不合格-确认放行", "BUTTON", "", "sys.alert"},
|
||||
// 工件报废/人工取走(2026-11-03 断头路补全):工件被人工从产线取走(报废/丢失/损伤)时的
|
||||
@@ -276,14 +277,18 @@ func (s *Service) Seed(ctx context.Context) error {
|
||||
// 摘掉存量角色里的旧码、删除旧权限定义行(幂等)。
|
||||
migrateLegacyQualityEdit(ctx, s)
|
||||
|
||||
// 3.8 「人工派车」从 AGV管理 拆出独立菜单码:存量角色里凡持 produce.agv 的,
|
||||
// 一律补授 produce.agv.manual,避免拆码后菜单消失或接口 403(幂等)。
|
||||
migrateSplitAgvManual(ctx, s)
|
||||
|
||||
// 4. 初始化产线工位(内置只读主数据);工艺流程/工序步骤由用户在「工艺流程」页自建,不预置
|
||||
seedStations(ctx, s)
|
||||
// 5. 接驳台主数据(真源在 MES,2026-09-21 自 WMS 迁入;2026-10-17 块 E.2 起可在「产线管理」页维护)
|
||||
seedDocks(ctx, s)
|
||||
// 5.1 AGV 点位真源(硬件内置):接驳台点位与 dock 一一对应 + 少量纯待命/充电点位
|
||||
seedAgvPoints(ctx, s)
|
||||
// 6. 预警规则常用占位(遗留5 告警框架第一阶段):只插缺失行,enabled=false / threshold=0,
|
||||
// 即"占位不启用"——由实施在预警中心按需改阈值/启用,绝不默认触发
|
||||
// 6. 告警配置常用占位(遗留5 告警框架第一阶段):只插缺失行,enabled=false / threshold=0,
|
||||
// 即"占位不启用"——由实施在异常告警按需改阈值/启用,绝不默认触发
|
||||
seedAlertRules(ctx, s)
|
||||
// 7. 叫料池全量重算(B5):按启用状态日排产派生 (工位×物料) 四数账;seed/migrate 后一键对齐
|
||||
if n, err := s.RecomputePoolAll(ctx); err != nil {
|
||||
@@ -312,11 +317,11 @@ func (s *Service) Seed(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// seedAlertRules 预警规则占位(幂等):按 type 幂等插入,已有行(含人工改过的阈值/启用态)一律不动。
|
||||
// seedAlertRules 告警配置占位(幂等):按 type 幂等插入,已有行(含人工改过的阈值/启用态)一律不动。
|
||||
// 常用类型:inspection_ng=检验不合格 / inventory_low=库存低于阈值 / task_overdue=任务超期。
|
||||
func seedAlertRules(ctx context.Context, s *Service) {
|
||||
// 存量 torque_ng 规则保留历史但置为禁用:拧紧报警已改由基础配置 torque.ng.alert.enabled 开关控制(B2.2),
|
||||
// 不再走预警规则表;不删除,便于追溯。
|
||||
// 不再走告警配置表;不删除,便于追溯。
|
||||
if _, err := s.ctx.EntClient.AlertRule.Update().
|
||||
Where(alertrule.Type("torque_ng")).SetEnabled(false).Save(ctx); err != nil {
|
||||
_ = err // 表为空时影响 0 行属正常,非致命
|
||||
@@ -511,6 +516,30 @@ func seedStations(ctx context.Context, s *Service) {
|
||||
// 上下线由工位终端「页签」配置(station.visibleTabs)驱动,可在任意授权工位执行,不绑定特定工位号。
|
||||
}
|
||||
|
||||
// migrateSplitAgvManual 「人工派车」拆码迁移(幂等):
|
||||
// 旧 produce.agv 一码两用,同时控制「AGV管理」与「人工派车」两个菜单;拆开后
|
||||
// produce.agv 只管 AGV管理,produce.agv.manual 管人工派车(含按钮与后端接口)。
|
||||
// 凡存量角色持 produce.agv 且无新码的,一律补授 produce.agv.manual,
|
||||
// 保证管理员/操作员/自建角色拆码后原有菜单不消失、已有操作不报 403。
|
||||
func migrateSplitAgvManual(ctx context.Context, s *Service) {
|
||||
roleList, _ := s.ctx.EntClient.Role.Query().All(ctx)
|
||||
for _, rl := range roleList {
|
||||
hasOld, hasNew := false, false
|
||||
for _, c := range rl.PermissionCodes {
|
||||
if c == "produce.agv" {
|
||||
hasOld = true
|
||||
} else if c == "produce.agv.manual" {
|
||||
hasNew = true
|
||||
}
|
||||
}
|
||||
if !hasOld || hasNew {
|
||||
continue
|
||||
}
|
||||
_ = s.ctx.EntClient.Role.UpdateOneID(rl.ID).
|
||||
SetPermissionCodes(mergeCodes(rl.PermissionCodes, []string{"produce.agv.manual"})).Exec(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
// mergeCodes 合并两份权限码列表(去重、保序)
|
||||
func mergeCodes(a, b []string) []string {
|
||||
seen := map[string]bool{}
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/alert"
|
||||
"bj_power_mes/ent/callpool"
|
||||
"bj_power_mes/ent/flowmaterial"
|
||||
)
|
||||
|
||||
// 断料预警(2026-11-14 用户拍板铁律 1,用户原话「他点击报工,才触发,所以,就去这次报工的即可」):
|
||||
@@ -16,6 +16,8 @@ import (
|
||||
// 剩余物料取本工位叫料池四数账(可用 = req + adj − sent − reserved,与叫料页同口径),
|
||||
// 按工艺物料清单单台用量换算「还能再做几台 / 约可支撑多少分钟」,低于阈值即落预警——
|
||||
// 工位终端经报警流实时弹播(alert.go 谁受影响谁播报)、预警中心可查。
|
||||
// 单台用量与叫料池需求同源,统一走 MaterialsByFlowForWO(分账优先、无分账逐工序回退旧口径),
|
||||
// 存量工单不会因未维护分账而失去预警。
|
||||
// 不新增定时器、不改 SN 编码规则、不动多工位互斥(preferFreeStation 既有空闲优先即拍板口径)。
|
||||
|
||||
// 断料预警阈值:按当次节拍推算「还能再做台数」≤ 该值时预警(2 = 本班内大概率断料)。
|
||||
@@ -25,8 +27,10 @@ const shortagePredictThreshold = 2
|
||||
const shortagePredictCooldown = 30 * time.Minute
|
||||
|
||||
// evaluateShortageAfterReport 报工成功后的断料推算(由 ReportProcess 在事务提交后调用)。
|
||||
// 单台用量按工单来源产品工艺的工序分账取(无分账逐工序回退旧口径),与叫料池需求同源:
|
||||
// 统一走 MaterialsByFlowForWO,存量工单(ppId=0)不会因未维护分账而失去预警。
|
||||
// 推算失败/无数据一律静默跳过(推算是提示能力,绝不影响报工结果)。
|
||||
func (s *Service) evaluateShortageAfterReport(ctx context.Context, stationNo, flowId, durationSec int, operator string) {
|
||||
func (s *Service) evaluateShortageAfterReport(ctx context.Context, stationNo, flowId, durationSec int, wo *ent.WorkOrder) {
|
||||
defer func() { _ = recover() }() // 提示能力不拖垮报工主链路
|
||||
if stationNo <= 0 || flowId <= 0 || durationSec <= 0 {
|
||||
return // 无有效节拍(时长采集缺失/为 0)不推算
|
||||
@@ -36,13 +40,16 @@ func (s *Service) evaluateShortageAfterReport(ctx context.Context, stationNo, fl
|
||||
if err != nil || len(pools) == 0 {
|
||||
return
|
||||
}
|
||||
fms, err := s.ctx.EntClient.FlowMaterial.Query().
|
||||
Where(flowmaterial.FlowIdEQ(flowId)).All(ctx)
|
||||
if err != nil {
|
||||
fmByFlow, merr := s.MaterialsByFlowForWO(ctx, s.ctx.EntClient, wo, []int{flowId})
|
||||
if merr != nil {
|
||||
return
|
||||
}
|
||||
rows := fmByFlow[flowId]
|
||||
if len(rows) == 0 {
|
||||
return
|
||||
}
|
||||
unitQty := map[string]float64{}
|
||||
for _, fm := range fms {
|
||||
for _, fm := range rows {
|
||||
if fm.UnitQty > 0 {
|
||||
unitQty[fm.MaterialCode] = fm.UnitQty
|
||||
}
|
||||
|
||||
@@ -69,13 +69,17 @@ func (s *Service) RegisterTrial(ctx context.Context, sn, result, reason, operato
|
||||
if s.ctx.Wms == nil {
|
||||
return nil, errors.New("WMS 库房不可达,无法核验成品序列号是否已入库,请稍后重试")
|
||||
}
|
||||
exists, werr := s.ctx.Wms.FinishedSnExists(ctx, sn)
|
||||
exists, wmsMaterialCode, werr := s.ctx.Wms.FinishedSnExists(ctx, sn)
|
||||
if werr != nil {
|
||||
return nil, errors.New("WMS 库房不可达,无法核验成品序列号是否已入库,请稍后重试")
|
||||
}
|
||||
if !exists {
|
||||
return nil, errors.New("该序列号未入库,无法试验,请先在 WMS 完成成品入库")
|
||||
}
|
||||
// 核销定位以 WMS 实际库存行编码为准;WMS 未带出时回退工单产品编码(不臆造编码)。
|
||||
if wmsMaterialCode != "" {
|
||||
materialCode = wmsMaterialCode
|
||||
}
|
||||
|
||||
// 报废/返修:联动 WMS 库存处置核销(失败不阻断登记)
|
||||
wmsMsg := ""
|
||||
|
||||
@@ -618,8 +618,8 @@ func (s *Service) ReportProcess(ctx context.Context, req ReportProcessReq, opera
|
||||
s.ctx.EventLog.Write(ctx, "workpiece.process.report", wp.OrderNo, operator, "workpiece", req.Sn,
|
||||
"工位报工", map[string]any{"flowId": flowId, "stationNo": req.StationNo, "result": result})
|
||||
// 断料预警(2026-11-14 用户拍板铁律 1):报工成功即以「本次报工实际耗时」为节拍推算
|
||||
// 本工位剩余物料可支撑台数/时长,低于阈值落预警(工位终端实时弹播;推算失败静默不阻断)。
|
||||
s.evaluateShortageAfterReport(ctx, req.StationNo, flowId, durationSec, operator)
|
||||
// 本工位剩余物料可支撑台数/时长,低于阈值落预警(工位终端实时弹播;推算失败静默不阻断);单台用量按工单来源产品工艺的工序分账取(无分账回退旧口径)。
|
||||
s.evaluateShortageAfterReport(ctx, req.StationNo, flowId, durationSec, wo)
|
||||
s.notifyDashboard()
|
||||
// 报工后自动流转连锁(triggerFlowChain,2026-11-11 拍板):异步推进工件物理位置
|
||||
// (送下一道工序候选工位 / 下游被占按缓存策略进缓存或滞留 / 层层拉入上游腾位)。
|
||||
|
||||
@@ -60,17 +60,20 @@ func (c *Client) Ping(ctx context.Context) error {
|
||||
|
||||
// FinishedSnExists 核验成品序列号是否已在 WMS 成品库入库(MES「成品试验」登记前校验)。
|
||||
// GET /api/internal/inventory/sn-exists?sn= → 复用 c.get 解析 WMS 统一 {code,data} 响应取 found。
|
||||
// 同时带出该库存行真实的 materialCode:报废/返修核销必须用它定位 WMS 库存行,
|
||||
// 不能用工单产品编码猜(完工回流的编码与工单编码可能不一致)。
|
||||
// found=false 表示未入库;网络异常或业务码非 0 返回中文业务错误,由调用方拒绝登记(不放行)。
|
||||
func (c *Client) FinishedSnExists(ctx context.Context, sn string) (bool, error) {
|
||||
func (c *Client) FinishedSnExists(ctx context.Context, sn string) (bool, string, error) {
|
||||
q := url.Values{}
|
||||
q.Set("sn", sn)
|
||||
var out struct {
|
||||
Found bool `json:"found"`
|
||||
Found bool `json:"found"`
|
||||
MaterialCode string `json:"materialCode"`
|
||||
}
|
||||
if err := c.get(ctx, "/api/internal/inventory/sn-exists?"+q.Encode(), &out); err != nil {
|
||||
return false, errors.New("WMS 库房不可达,无法核验成品序列号")
|
||||
return false, "", errors.New("WMS 库房不可达,无法核验成品序列号")
|
||||
}
|
||||
return out.Found, nil
|
||||
return out.Found, out.MaterialCode, nil
|
||||
}
|
||||
|
||||
// SemiPayload MES→WMS 在制品入库/出库载荷。
|
||||
|
||||
Reference in New Issue
Block a user