chore: 批量完成项目多模块迭代优化

1. 废弃半成品库存表并统一库存主表
2. 修复列表排序与搜索大小写不敏感问题
3. 新增用户最近登录时间、工单BOM名称字段
4. 完善角色管理、工位选择器功能
5. 增加拧紧数据补录、成品自动回流WMS能力
6. 统一导出时间范围校验规则
7. 丰富物料/备料单筛选条件
8. 调整菜单与权限命名适配产品型号业务
This commit is contained in:
SunYF
2026-09-08 11:44:04 +08:00
parent 06689970e2
commit e852c7cd37
96 changed files with 4528 additions and 542 deletions
+41 -7
View File
@@ -4,16 +4,31 @@ import (
"context"
"encoding/json"
"errors"
"strings"
"time"
"bj_power_mes/ent"
"bj_power_mes/ent/inspectionrecord"
)
// FlexStr 兼容客户端把数字字段传成 number 或 string(前端 stationNo 用数字,
// 标准 JSON 反序列化进 string 会报错 → 400 请求体解析失败)
type FlexStr string
func (f *FlexStr) UnmarshalJSON(b []byte) error {
s := strings.TrimSpace(string(b))
s = strings.Trim(s, `"`)
if s == "null" {
s = ""
}
*f = FlexStr(s)
return nil
}
// InspectionReq 巡检记录请求(PAD 巡检终端,块8)
type InspectionReq struct {
Category string `json:"category"` // CHECKIN/POINT/PROCESS/DONE/ALARM
StationNo string `json:"stationNo"`
StationNo FlexStr `json:"stationNo"`
Shift string `json:"shift"` // 早/中/晚
OrderNo string `json:"orderNo"` // 工单号
Sn string `json:"sn"` // 工件SN
@@ -42,7 +57,7 @@ func (s *Service) CreateInspection(ctx context.Context, req InspectionReq, opera
}
_, err := s.ctx.EntClient.InspectionRecord.Create().
SetCategory(category).
SetStationNo(req.StationNo).
SetStationNo(string(req.StationNo)).
SetShift(req.Shift).
SetOrderNo(req.OrderNo).
SetSn(req.Sn).
@@ -56,7 +71,7 @@ func (s *Service) CreateInspection(ctx context.Context, req InspectionReq, opera
return err
}
s.ctx.EventLog.Write(ctx, "inspection."+category, req.OrderNo, req.Operator, "inspection_record",
req.Sn, "巡检终端提交", map[string]any{"category": category, "stationNo": req.StationNo, "result": result})
req.Sn, "巡检终端提交", map[string]any{"category": category, "stationNo": string(req.StationNo), "result": result})
if category == "ALARM" {
// 触发看板报警:SSE 推送 + 使 Redis 看板报警缓存失效
@@ -64,7 +79,7 @@ func (s *Service) CreateInspection(ctx context.Context, req InspectionReq, opera
"level": "CRITICAL",
"type": "inspection_alarm",
"message": "巡检异常上报:" + req.Remark,
"station": req.StationNo,
"station": string(req.StationNo),
"time": time.Now().Format("2006-01-02 15:04:05"),
})
if s.ctx.SSE != nil {
@@ -78,12 +93,25 @@ func (s *Service) CreateInspection(ctx context.Context, req InspectionReq, opera
return nil
}
// ListInspections 查询巡检记录
// ListInspections 查询巡检记录(不分页,供内部/导出用,封顶 1000)
func (s *Service) ListInspections(ctx context.Context, category, operator, from, to string) ([]*ent.InspectionRecord, error) {
q := s.ctx.EntClient.InspectionRecord.Query().Order(ent.Desc(inspectionrecord.FieldID))
rows, _, err := s.ListInspectionsPaged(ctx, category, operator, from, to, "", "", 1, 1000)
return rows, err
}
// ListInspectionsPaged 分页查询巡检记录,返回 {rows, total};排序 id desc 最新置顶
// orderNo/stationNo2026-09-08 补充筛选(大小写不敏感)
func (s *Service) ListInspectionsPaged(ctx context.Context, category, operator, from, to, orderNo, stationNo string, page, pageSize int) ([]*ent.InspectionRecord, int, error) {
q := s.ctx.EntClient.InspectionRecord.Query()
if category != "" {
q = q.Where(inspectionrecord.Category(category))
}
if orderNo != "" {
q = q.Where(inspectionrecord.OrderNoEqualFold(orderNo))
}
if stationNo != "" {
q = q.Where(inspectionrecord.StationNoEqualFold(stationNo))
}
if operator != "" {
q = q.Where(inspectionrecord.Operator(operator))
}
@@ -97,7 +125,13 @@ func (s *Service) ListInspections(ctx context.Context, category, operator, from,
q = q.Where(inspectionrecord.CreatedAtLT(t.Add(24 * time.Hour)))
}
}
return q.Limit(1000).All(ctx)
total, err := q.Count(ctx)
if err != nil {
return nil, 0, err
}
rows, err := q.Order(ent.Desc(inspectionrecord.FieldID)).
Offset((page - 1) * pageSize).Limit(pageSize).All(ctx)
return rows, total, err
}
func oneOf(v string, items ...string) bool {