74 lines
2.4 KiB
Go
74 lines
2.4 KiB
Go
package logic
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"bj_power_mes/ent/materialqtyreport"
|
||
|
|
"bj_power_mes/ent/materialrequest"
|
||
|
|
"bj_power_mes/ent/shortagerequest"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
|
)
|
||
|
|
|
||
|
|
// TodoItem 单个菜单的待办数量
|
||
|
|
type TodoItem struct {
|
||
|
|
MenuCode string `json:"menuCode"`
|
||
|
|
Count int `json:"count"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// todoMenus 固定的 6 类待办菜单(前端 MainLayout 按已渲染菜单显示角标)
|
||
|
|
var todoMenus = []string{
|
||
|
|
"produce.call", // 叫料待处理
|
||
|
|
"produce.return", // 退料待确认
|
||
|
|
"produce.shortage", // 补料待审批
|
||
|
|
"produce.qtyreport", // 数量不符待处理
|
||
|
|
"produce.sign", // 待审核签字
|
||
|
|
"produce.alert", // 异常预警
|
||
|
|
}
|
||
|
|
|
||
|
|
// TodoStats 统计 6 类待办数量。任一查询失败记 0 并用 logx 记日志后继续,不整体失败。
|
||
|
|
func (s *Service) TodoStats(ctx context.Context) ([]TodoItem, int, error) {
|
||
|
|
counts := map[string]int{}
|
||
|
|
count := func(code string, n int, err error) {
|
||
|
|
if err != nil {
|
||
|
|
logx.Errorf("待办统计[%s]失败,按 0 计:%v", code, err)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
counts[code] = n
|
||
|
|
}
|
||
|
|
// 叫料待处理:material_request.status = PENDING
|
||
|
|
n, err := s.ctx.EntClient.MaterialRequest.Query().
|
||
|
|
Where(materialrequest.Status("PENDING")).Count(ctx)
|
||
|
|
count("produce.call", n, err)
|
||
|
|
// 退料待确认:material_request.status = RETURNING
|
||
|
|
n, err = s.ctx.EntClient.MaterialRequest.Query().
|
||
|
|
Where(materialrequest.Status("RETURNING")).Count(ctx)
|
||
|
|
count("produce.return", n, err)
|
||
|
|
// 补料待审批:shortage_request.status = PENDING
|
||
|
|
n, err = s.ctx.EntClient.ShortageRequest.Query().
|
||
|
|
Where(shortagerequest.Status("PENDING")).Count(ctx)
|
||
|
|
count("produce.shortage", n, err)
|
||
|
|
// 数量不符待处理:material_qty_report.status IN (PENDING, PROCESSING)
|
||
|
|
n, err = s.ctx.EntClient.MaterialQtyReport.Query().
|
||
|
|
Where(materialqtyreport.StatusIn("PENDING", "PROCESSING")).Count(ctx)
|
||
|
|
count("produce.qtyreport", n, err)
|
||
|
|
// 待审核签字:复用 PendingAudits 的 step_sign_record 聚合口径,取总数
|
||
|
|
_, n, err = s.PendingAudits(ctx, PendingAuditFilter{})
|
||
|
|
count("produce.sign", n, err)
|
||
|
|
// 异常预警:alert.status = UNREAD
|
||
|
|
n, err = s.UnreadAlertCount(ctx)
|
||
|
|
count("produce.alert", n, err)
|
||
|
|
|
||
|
|
items := make([]TodoItem, 0, len(todoMenus))
|
||
|
|
total := 0
|
||
|
|
for _, code := range todoMenus {
|
||
|
|
c := counts[code]
|
||
|
|
if c < 0 {
|
||
|
|
c = 0
|
||
|
|
}
|
||
|
|
items = append(items, TodoItem{MenuCode: code, Count: c})
|
||
|
|
total += c
|
||
|
|
}
|
||
|
|
return items, total, nil
|
||
|
|
}
|