docs: 统一修正全项目“SN管理”相关术语为“序列号”

本次 commit 统一修正了全项目范围内关于 SN 管理的术语表述,将原“SN管理”、“序列号件”、“批次件”等表述调整为“序列号”、“序列号=是”、“序列号=否”,同时同步更新了相关文档、代码注释、前端提示文本、数据库 schema 注释、API 文档等,确保全链路术语统一,消除理解歧义。
This commit is contained in:
SunYF
2026-10-10 15:58:59 +08:00
parent b032f47fc7
commit 8be6e03a15
335 changed files with 5742 additions and 1616 deletions
+49 -7
View File
@@ -3,6 +3,7 @@ package logic
import (
"context"
"errors"
"strings"
"time"
"bj_power_mes/ent"
@@ -11,18 +12,18 @@ import (
)
// CreateAlertRule 新增预警规则
func (s *Service) CreateAlertRule(ctx context.Context, name, typ string, threshold float64, receiver string, enabled bool, createdBy string) error {
func (s *Service) CreateAlertRule(ctx context.Context, name, typ, notifyChannels string, threshold float64, enabled bool, createdBy string) error {
if name == "" || typ == "" {
return errors.New("规则名称与类型必填")
}
_, err := s.ctx.EntClient.AlertRule.Create().
SetName(name).SetType(typ).SetThreshold(threshold).
SetReceiver(receiver).SetEnabled(enabled).SetCreatedBy(createdBy).Save(ctx)
SetNotifyChannels(notifyChannels).SetEnabled(enabled).SetCreatedBy(createdBy).Save(ctx)
return err
}
// UpdateAlertRule 修改预警规则
func (s *Service) UpdateAlertRule(ctx context.Context, id int, name, typ string, threshold float64, receiver string, enabled bool) error {
func (s *Service) UpdateAlertRule(ctx context.Context, id int, name, typ, notifyChannels string, threshold float64, enabled bool) error {
if id <= 0 {
return errors.New("规则ID无效")
}
@@ -31,7 +32,7 @@ func (s *Service) UpdateAlertRule(ctx context.Context, id int, name, typ string,
}
_, err := s.ctx.EntClient.AlertRule.UpdateOneID(id).
SetName(name).SetType(typ).SetThreshold(threshold).
SetReceiver(receiver).SetEnabled(enabled).Save(ctx)
SetNotifyChannels(notifyChannels).SetEnabled(enabled).Save(ctx)
return err
}
@@ -49,10 +50,11 @@ func (s *Service) ListAlertRules(ctx context.Context) ([]*ent.AlertRule, error)
Order(ent.Desc(alertrule.FieldCreatedAt), ent.Desc(alertrule.FieldID)).All(ctx)
}
// AlertQuery 预警查询条件:status/type 空=不限;from/to 为 YYYY-MM-DD(空=不限);page<=0 表示不分页。
// AlertQuery 预警查询条件:status/type/level 空=不限;from/to 为 YYYY-MM-DD(空=不限);page<=0 表示不分页。
type AlertQuery struct {
Status string
Type string
Level string // 级别筛选(遗留5):信息/警告/严重,空=不限
From string
To string
OrderNo string // 工单号(模糊,客户第12条:记录查看加一项看工单号查询)
@@ -60,7 +62,7 @@ type AlertQuery struct {
PageSize int
}
// ListAlerts 查询预警消息(支持状态/类型/时间范围筛选 + 分页),返回当前页数据与命中总数
// ListAlerts 查询预警消息(支持 级别/状态/类型/时间范围筛选 + 分页),返回当前页数据与命中总数
func (s *Service) ListAlerts(ctx context.Context, q AlertQuery) ([]*ent.Alert, int, error) {
query := s.ctx.EntClient.Alert.Query()
if q.Status != "" {
@@ -69,6 +71,9 @@ func (s *Service) ListAlerts(ctx context.Context, q AlertQuery) ([]*ent.Alert, i
if q.Type != "" {
query = query.Where(alert.Type(q.Type))
}
if q.Level != "" {
query = query.Where(alert.Level(q.Level))
}
if q.From != "" {
if f, err := time.Parse("2006-01-02", q.From); err == nil {
query = query.Where(alert.CreatedAtGTE(f))
@@ -111,6 +116,43 @@ func (s *Service) MarkAlertRead(ctx context.Context, id int) error {
return err
}
// CreateAlert 直写一条预警(遗留5 告警框架第一阶段,业务事件入口,不走规则阈值):
// CreateAlert(type, level, target, message)——type=业务类型(如 torque_ng)、
// level=级别(信息/警告/严重)、target=目标对象(工位/库房/SN)、message=预警内容。
// message 同时落 title(超长截断)与 content,状态 UNREAD,待预警中心处置。
func (s *Service) CreateAlert(ctx context.Context, typ, level, target, message string) error {
if strings.TrimSpace(typ) == "" || strings.TrimSpace(message) == "" {
return errors.New("预警类型与内容必填")
}
title := message
if r := []rune(message); len(r) > 120 {
title = string(r[:120])
}
_, err := s.ctx.EntClient.Alert.Create().
SetRuleId(0).SetType(typ).SetLevel(level).SetTarget(target).
SetTitle(title).SetContent(message).
SetStatus("UNREAD").Save(ctx)
return err
}
// ResolveAlert 处置预警(POST /alerts/:id/resolve):置 READ 并记录处置人与处置时间,
// 形成闭环(谁在何时处置);重复处置幂等(已处置直接成功)。
func (s *Service) ResolveAlert(ctx context.Context, id int, operator string) error {
if id <= 0 {
return errors.New("预警ID无效")
}
a, err := s.ctx.EntClient.Alert.Get(ctx, id)
if err != nil {
return errors.New("预警不存在")
}
if a.Status == "READ" {
return nil // 幂等:已处置
}
_, err = s.ctx.EntClient.Alert.UpdateOneID(id).
SetStatus("READ").SetResolvedAt(time.Now()).SetResolvedBy(operator).Save(ctx)
return err
}
// alertDirection 阈值比较方向:inventory_low 为 <=,其余为 >=
func alertDirection(typ string) int {
if typ == "inventory_low" {
@@ -134,7 +176,7 @@ func (s *Service) Evaluate(ctx context.Context, typ string, value float64, title
if !hit {
continue
}
_ = s.createAlert(ctx, r.ID, typ, title, content, refType, refId, orderNo, r.Receiver)
_ = s.createAlert(ctx, r.ID, typ, title, content, refType, refId, orderNo, r.NotifyChannels)
}
}