feat: 新增预警与附件模块,优化工位派工功能
1. 新增预警规则、预警消息、业务附件数据库表与CRUD逻辑 2. 为拧紧记录添加审核人、审核时间字段及审核留痕功能 3. 优化产线点位类型与编号描述,更新工位组合下发菜单名称为工艺路线派工 4. 新增上传文件获取原文件名与大小的工具方法 5. 在系统管理菜单新增预警中心与附件中心入口
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/station"
|
||||
"bj_power_mes/ent/stepcriterion"
|
||||
"bj_power_mes/ent/torqueauditlog"
|
||||
"bj_power_mes/ent/torquerecord"
|
||||
"bj_power_mes/ent/workpieceprocess"
|
||||
)
|
||||
@@ -63,6 +64,7 @@ func (s *Service) ReportTorque(ctx context.Context, req TorqueReq, operator stri
|
||||
func (s *Service) evaluateTorqueCriterion(ctx context.Context, sn, stationNo string, strain, angle float64, operator string) {
|
||||
q := s.ctx.EntClient.StepCriterion.Query().Where(stepcriterion.Name("扭矩"))
|
||||
crits, _ := q.All(ctx)
|
||||
ng := false
|
||||
for _, c := range crits {
|
||||
if c.Logic != "RANGE" {
|
||||
continue
|
||||
@@ -78,6 +80,12 @@ func (s *Service) evaluateTorqueCriterion(ctx context.Context, sn, stationNo str
|
||||
SetSn(sn).SetStepId(c.StepId).SetCriterionId(c.ID).
|
||||
SetCriterionName(c.Name).SetCriterionLogic(c.Logic).
|
||||
SetValue(strain).SetIsOK(ok).SetOperator(operator).Save(ctx)
|
||||
if !ok {
|
||||
ng = true
|
||||
}
|
||||
}
|
||||
if ng {
|
||||
s.Evaluate(ctx, "torque_ng", 1, "拧紧扭矩不合格", "SN="+sn+" 工位"+stationNo, "torque_record", sn)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +114,7 @@ func (s *Service) AddTorqueRecord(ctx context.Context, sn, workOrderNo, screwNo,
|
||||
result = "OK"
|
||||
}
|
||||
now := time.Now()
|
||||
_, err := s.ctx.EntClient.TorqueRecord.Create().
|
||||
rec, err := s.ctx.EntClient.TorqueRecord.Create().
|
||||
SetSn(sn).SetWorkOrderNo(workOrderNo).SetScrewNo(screwNo).SetStationNo(stationNo).
|
||||
SetStrain(strain).SetTorque(strain).SetAngle(angle).
|
||||
SetResult(result).SetOperator(operator + "(补录)").SetTime(now).
|
||||
@@ -114,11 +122,41 @@ func (s *Service) AddTorqueRecord(ctx context.Context, sn, workOrderNo, screwNo,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, _ = s.ctx.EntClient.TorqueAuditLog.Create().
|
||||
SetTorqueRecordId(rec.ID).SetAction("补录").SetOperator(operator).
|
||||
SetRemark(reason).SetNewVal(result).Save(ctx)
|
||||
s.ctx.EventLog.Write(ctx, "torque.manual.add", workOrderNo, operator, "torque_record", sn,
|
||||
"拧紧数据补录 "+workOrderNo+" "+sn, map[string]any{"reason": reason, "result": result, "screwNo": screwNo, "stationNo": stationNo})
|
||||
return nil
|
||||
}
|
||||
|
||||
// AuditTorqueRecord 拧紧记录审核签字:标记审核人/时间并写留痕
|
||||
func (s *Service) AuditTorqueRecord(ctx context.Context, recordId int, remark, operator string) error {
|
||||
rec, err := s.ctx.EntClient.TorqueRecord.Get(ctx, recordId)
|
||||
if err != nil {
|
||||
return errors.New("拧紧记录不存在")
|
||||
}
|
||||
if rec.AuditBy != "" {
|
||||
return errors.New("该记录已审核,不可重复审核")
|
||||
}
|
||||
_, err = rec.Update().SetAuditBy(operator).SetAuditAt(time.Now()).Save(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, _ = s.ctx.EntClient.TorqueAuditLog.Create().
|
||||
SetTorqueRecordId(rec.ID).SetAction("审核").SetOperator(operator).
|
||||
SetRemark(remark).SetOldVal(rec.AuditBy).SetNewVal(operator).Save(ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListTorqueAuditLog 查询某拧紧记录的修改留痕
|
||||
func (s *Service) ListTorqueAuditLog(ctx context.Context, recordId int) ([]*ent.TorqueAuditLog, error) {
|
||||
return s.ctx.EntClient.TorqueAuditLog.Query().
|
||||
Where(torqueauditlog.TorqueRecordId(recordId)).
|
||||
Order(ent.Desc(torqueauditlog.FieldCreatedAt)).All(ctx)
|
||||
}
|
||||
|
||||
|
||||
// 计算一块工件某工序的扭矩步骤是否已报
|
||||
func (s *Service) hasWorkpieceProcess(ctx context.Context, sn string, processCode int) bool {
|
||||
cnt, _ := s.ctx.EntClient.WorkpieceProcess.Query().
|
||||
|
||||
Reference in New Issue
Block a user