feat: 新增工序签字功能,移除移料指令模块

新增操作工/检验员工序签字功能,支持工艺步骤配置签字要求;删除移料指令相关代码,将移料页签重命名为产线点位(上料/下料);新增成品入库功能及相关权限;优化备料单状态、质量状态逻辑,新增批次序号字段;修复AGV取消后备料单回退状态问题。
This commit is contained in:
SunYF
2026-10-05 20:15:38 +08:00
parent c33acab9c8
commit f1cf57e9b2
181 changed files with 9785 additions and 9699 deletions
-127
View File
@@ -9,7 +9,6 @@ import (
"bj_power_mes/ent"
"bj_power_mes/ent/linepoint"
"bj_power_mes/ent/plcmovecmd"
)
// ============ 产线点位台账(产线布局说明·修正版) ============
@@ -79,132 +78,6 @@ func (s *Service) ListPoints(ctx context.Context) ([]map[string]any, error) {
return out, nil
}
// IssueMove 上位机下发移料指令(PLC 只执行,不判断)
func (s *Service) IssueMove(ctx context.Context, sn, fromPoint, toPoint, orderNo, operator string) (map[string]any, error) {
if sn == "" || fromPoint == "" || toPoint == "" {
return nil, errors.New("工件SN、起点位、目标点位必填")
}
if fromPoint == toPoint {
return nil, errors.New("起点位与目标点位相同")
}
from, err := s.ctx.EntClient.LinePoint.Query().Where(linepoint.PointNo(fromPoint)).First(ctx)
if err != nil {
return nil, errors.New("起点位不存在:" + fromPoint)
}
to, err := s.ctx.EntClient.LinePoint.Query().Where(linepoint.PointNo(toPoint)).First(ctx)
if err != nil {
return nil, errors.New("目标点位不存在:" + toPoint)
}
if !from.Occupied || from.CurrentSn != sn {
return nil, errors.New("起点位当前不是该工件,无法移出")
}
if to.Occupied {
return nil, errors.New("目标点位被占用:" + toPoint)
}
if operator == "" {
operator = "SYSTEM"
}
// 工位停单(只认当天):目标工位停单 → 不下发流转指令 + 报警(工件实际滞留于当前点位)
if to.StationNo > 0 && s.GetStationPaused(ctx, to.StationNo) {
_, _ = s.ctx.EntClient.Alert.Create().
SetRuleId(0).SetType("workpiece_unreachable").SetTitle("工件目的地不可达").
SetContent(fmt.Sprintf("目标工位%d已停止接单,指令不下发,工件 %s 滞留于 %s", to.StationNo, sn, fromPoint)).
SetRefType("line_point").SetRefId(fmt.Sprintf("%d", to.ID)).SetOrderNo(orderNo).SetReceiver("").SetStatus("UNREAD").Save(ctx)
s.ctx.EventLog.Write(ctx, "workpiece.unreachable", orderNo, operator, "line_point", toPoint,
fmt.Sprintf("目标工位%d已停止接单,工件 %s 滞留", to.StationNo, sn),
map[string]any{"sn": sn, "fromPoint": fromPoint, "toPoint": toPoint, "stationNo": to.StationNo})
return nil, fmt.Errorf("工位%d已停止接单,工件滞留", to.StationNo)
}
cmdNo := fmt.Sprintf("MV%d", time.Now().UnixNano())
cmd, err := s.ctx.EntClient.PlcMoveCmd.Create().
SetCmdNo(cmdNo).SetSn(sn).SetOrderNo(orderNo).
SetFromPoint(fromPoint).SetToPoint(toPoint).
SetStatus("ISSUED").SetOperator(operator).Save(ctx)
if err != nil {
return nil, err
}
s.ctx.EventLog.Write(ctx, "line.move.issue", sn, operator, "plc_move_cmd", cmdNo,
"下发移料指令 "+fromPoint+" → "+toPoint, map[string]any{"sn": sn, "orderNo": orderNo})
return map[string]any{"id": cmd.ID, "cmdNo": cmd.CmdNo, "status": cmd.Status}, nil
}
// AckMove PLC 应答指令
func (s *Service) AckMove(ctx context.Context, cmdNo string) error {
cmd, err := s.ctx.EntClient.PlcMoveCmd.Query().Where(plcmovecmd.CmdNo(cmdNo)).First(ctx)
if err != nil {
return errors.New("指令不存在")
}
if cmd.Status != "ISSUED" {
return errors.New("当前状态不允许应答:" + cmd.Status)
}
return s.ctx.EntClient.PlcMoveCmd.UpdateOneID(cmd.ID).SetStatus("ACK").Exec(ctx)
}
// ArriveMove 工件到位:回写点位台账(起点清空、目标写入),指令闭环
func (s *Service) ArriveMove(ctx context.Context, cmdNo string) error {
cmd, err := s.ctx.EntClient.PlcMoveCmd.Query().Where(plcmovecmd.CmdNo(cmdNo)).First(ctx)
if err != nil {
return errors.New("指令不存在")
}
if cmd.Status != "ISSUED" && cmd.Status != "ACK" {
return errors.New("当前状态不允许到位:" + cmd.Status)
}
tx, err := s.ctx.EntClient.Tx(ctx)
if err != nil {
return err
}
committed := false
defer func() {
if !committed {
_ = tx.Rollback()
}
}()
_, _ = tx.LinePoint.Update().Where(linepoint.PointNo(cmd.FromPoint)).
SetCurrentSn("").SetOrderNo("").SetOccupied(false).Save(ctx)
_, _ = tx.LinePoint.Update().Where(linepoint.PointNo(cmd.ToPoint)).
SetCurrentSn(cmd.Sn).SetOrderNo(cmd.OrderNo).SetOccupied(true).Save(ctx)
if err := tx.PlcMoveCmd.UpdateOneID(cmd.ID).SetStatus("ARRIVED").Exec(ctx); err != nil {
return err
}
_ = tx.PlcMoveCmd.UpdateOneID(cmd.ID).SetStatus("CLOSED").Exec(ctx)
if err := tx.Commit(); err != nil {
return err
}
committed = true
s.ctx.EventLog.Write(ctx, "line.move.arrive", cmd.Sn, cmd.Operator, "plc_move_cmd", cmdNo,
"移料到位 "+cmd.FromPoint+" → "+cmd.ToPoint, map[string]any{"sn": cmd.Sn, "orderNo": cmd.OrderNo})
s.notifyDashboard()
return nil
}
// ListMoveCmds 查询移料指令(可按状态/工件过滤)
func (s *Service) ListMoveCmds(ctx context.Context, status, sn string, limit int) ([]map[string]any, error) {
q := s.ctx.EntClient.PlcMoveCmd.Query().Order(ent.Desc(plcmovecmd.FieldID))
if status != "" {
q = q.Where(plcmovecmd.Status(status))
}
if sn != "" {
q = q.Where(plcmovecmd.Sn(sn))
}
if limit <= 0 || limit > 200 {
limit = 50
}
cmds, err := q.Limit(limit).All(ctx)
if err != nil {
return nil, err
}
out := make([]map[string]any, 0, len(cmds))
for _, c := range cmds {
out = append(out, map[string]any{
"id": c.ID, "cmdNo": c.CmdNo, "sn": c.Sn, "orderNo": c.OrderNo,
"fromPoint": c.FromPoint, "toPoint": c.ToPoint, "status": c.Status,
"operator": c.Operator, "message": c.Message, "createdAt": c.CreatedAt,
})
}
return out, nil
}
// CallMaterialItem 叫料明细
type CallMaterialItem struct {
MaterialCode string `json:"materialCode"`