feat: 多系统新增扫码中间件与 AGV 对接,优化拧紧与退库流程
新增扫码中间件支持网络型扫码枪键盘注入,AGV 对接从 WMS 迁至 MES 统一管理;新增拧紧不合格人工处置与 PLC 对账机制,优化退库单关联与工位终端功能,同时清理旧 AGV 任务表,完善数据库与配置项。
This commit is contained in:
@@ -3,11 +3,13 @@ package logic
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/alert"
|
||||
"bj_power_mes/ent/processstep"
|
||||
"bj_power_mes/ent/station"
|
||||
"bj_power_mes/ent/stepcriterion"
|
||||
@@ -92,6 +94,14 @@ func (s *Service) evaluateTorqueCriterion(ctx context.Context, sn, stationNo str
|
||||
if wp, e := s.ctx.EntClient.Workpiece.Query().Where(workpiece.Sn(sn)).First(ctx); e == nil {
|
||||
orderNo = wp.OrderNo
|
||||
}
|
||||
// B6 拧紧闭环:NG 立即标记该件「待人工处置」,阻断后续报工(ReportProcess)/下线完工(DoneWorkpiece)。
|
||||
// 注意:本函数仅在 NG 分支写标记,返工重拧合格不自动清标记——唯一清除入口=质检/班组长确认放行
|
||||
// (DisposeTorqueNg),避免"重拧即放行"绕过人工处置。标记失败仅记日志不阻断拧紧落库。
|
||||
if _, e := s.ctx.EntClient.Workpiece.Update().
|
||||
Where(workpiece.Sn(sn)).
|
||||
SetTorqueNgPending(true).SetTorqueNgAt(time.Now()).SetTorqueNgBy(operator).Save(ctx); e != nil {
|
||||
log.Printf("[torque] 置拧紧不合格标记失败 sn=%s: %v", sn, e)
|
||||
}
|
||||
s.Evaluate(ctx, "torque_ng", 1, "拧紧扭矩不合格", "SN="+sn+" 工位"+stationNo, "torque_record", sn, orderNo)
|
||||
}
|
||||
}
|
||||
@@ -155,6 +165,43 @@ func (s *Service) ListTorqueRecords(ctx context.Context, sn, workOrderNo, statio
|
||||
return q.Order(ent.Desc(torquerecord.FieldTime)).Limit(500).All(ctx)
|
||||
}
|
||||
|
||||
// TorqueDisposeReq 拧紧不合格人工处置请求(质检/班组长确认放行)
|
||||
type TorqueDisposeReq struct {
|
||||
Sn string `json:"sn"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
|
||||
// DisposeTorqueNg 拧紧不合格人工处置(B6 最小闭环):质检/班组长确认放行。
|
||||
// 校验该件确有待处置项后:清标记 + 写 event_log(谁/何时/原因) + 置对应 torque_ng 预警 resolved(READ)。
|
||||
// 不实现返修工单流程(线下处理);处置仅放行,NG 数据永久保留于 step_data/torque_record 供追溯。
|
||||
func (s *Service) DisposeTorqueNg(ctx context.Context, req TorqueDisposeReq, operator string) error {
|
||||
if req.Sn == "" {
|
||||
return errors.New("sn 必填")
|
||||
}
|
||||
wp, err := s.ctx.EntClient.Workpiece.Query().Where(workpiece.Sn(req.Sn)).First(ctx)
|
||||
if err != nil {
|
||||
return errors.New("工件不存在")
|
||||
}
|
||||
if !wp.TorqueNgPending {
|
||||
return errors.New("该工件无待处置的拧紧不合格项")
|
||||
}
|
||||
now := time.Now()
|
||||
if _, err := s.ctx.EntClient.Workpiece.UpdateOneID(wp.ID).
|
||||
SetTorqueNgPending(false).ClearTorqueNgAt().ClearTorqueNgBy().Save(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
// 留痕:谁/何时/原因
|
||||
s.ctx.EventLog.Write(ctx, "torque.disposition", wp.OrderNo, operator, "workpiece", req.Sn,
|
||||
"拧紧不合格人工处置-确认放行", map[string]any{"reason": req.Reason, "disposedBy": operator, "disposedAt": now.Format(time.RFC3339)})
|
||||
// 置对应 torque_ng 预警 resolved(状态变更 READ,不删行);幂等(已处置直接成功)。
|
||||
alerts, _ := s.ctx.EntClient.Alert.Query().
|
||||
Where(alert.Type("torque_ng"), alert.RefId(req.Sn), alert.Status("UNREAD")).All(ctx)
|
||||
for _, a := range alerts {
|
||||
_ = s.ResolveAlert(ctx, a.ID, operator)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProcessStepTemplate 下发给前端渲染的参数采集模板
|
||||
type ProcessStepTemplate struct {
|
||||
ID int `json:"id"`
|
||||
|
||||
Reference in New Issue
Block a user