- WMS 新增「检验处置项」实体(schema + ent 生成码),配套检验记录实体调整与复检接口,完善来料检/不良退货/入库检验前端 - MES 日排产:新增达成率统计与计划对比逻辑,调整日排产前端与流程卡/工序流 - 日志与传输:MES 新增 PLC 日志与 WMS 客户端传输日志,WMS 新增 MES 客户端传输日志 - MES 其他:扫码、工单/工件、AGV 客户端与告警、产品导入等逻辑完善及前端调整 - 工位终端:上线面板/作业面板、工件 handler 与 MES 客户端调整 - 配置与文档:更新 mes-api.yaml、三端构建产物与问题记录文档
96 lines
3.4 KiB
Go
96 lines
3.4 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"sort"
|
|
"time"
|
|
|
|
"bj_power_mes/ent/dailyplan"
|
|
"bj_power_mes/ent/workpiecelifecyclelog"
|
|
)
|
|
|
|
// DailyPlanAttainmentRow 计划 vs 实际对比行(2026-11-16 死结6 定案)。
|
|
// 用户口径:不是历史排产对比,是「排了 10 个,那天实际做出了几个」的实际执行结果;
|
|
// 维度=现有日排产字段(排产日期/工单/计划数/实际数/差异),要看明细跳生产流程卡。
|
|
type DailyPlanAttainmentRow struct {
|
|
Date string `json:"date"` // 排产/完工日期
|
|
OrderNo string `json:"orderNo"` // 工单号(产品工号)
|
|
PlanQty int `json:"planQty"` // 该日期该工单排产计划合计
|
|
DoneQty int `json:"doneQty"` // 该日期该工单实际完工台数(完工流水聚合)
|
|
Diff int `json:"diff"` // 实际 - 计划(负=欠产,正=超产)
|
|
}
|
|
|
|
// DailyPlanAttainment 计划 vs 实际(不建新表,直接汇聚,2026-11-16):
|
|
// - 计划 = daily_plan 各状态排产行按 (plan_date, order_no) 合计 plan_qty(含已完成/已取消,看的是历史全量);
|
|
// - 实际 = workpiece_lifecycle_log(action=DONE) 完工流水按 (完工当天, work_order_no) 聚合计数。
|
|
//
|
|
// 实际口径取完工流水而非 daily_plan.completed_qty:流水与生产流程卡同源(真流水),
|
|
// 不受「当天无排产行实绩漏记」影响(bumpDailyPlanCompleted 只往匹配到的排产行累加)。
|
|
// 窗口上限 92 天,防全表扫描。
|
|
func (s *Service) DailyPlanAttainment(ctx context.Context, start, end string) ([]DailyPlanAttainmentRow, error) {
|
|
if start == "" || end == "" {
|
|
return nil, errors.New("请选择日期范围")
|
|
}
|
|
st, e1 := time.Parse("2006-01-02", start)
|
|
en, e2 := time.Parse("2006-01-02", end)
|
|
if e1 != nil || e2 != nil {
|
|
return nil, errors.New("日期格式应为 YYYY-MM-DD")
|
|
}
|
|
if en.Before(st) {
|
|
return nil, errors.New("结束日期不能早于开始日期")
|
|
}
|
|
if en.Sub(st).Hours() > 92*24 {
|
|
return nil, errors.New("对比窗口最长 92 天,请缩小日期范围")
|
|
}
|
|
|
|
rows := map[string]*DailyPlanAttainmentRow{}
|
|
outOrder := make([]string, 0, 64)
|
|
touch := func(date, orderNo string) *DailyPlanAttainmentRow {
|
|
key := date + "|" + orderNo
|
|
r, ok := rows[key]
|
|
if !ok {
|
|
r = &DailyPlanAttainmentRow{Date: date, OrderNo: orderNo}
|
|
rows[key] = r
|
|
outOrder = append(outOrder, key)
|
|
}
|
|
return r
|
|
}
|
|
|
|
// 计划:排产行合计(全状态,历史全量)
|
|
plans, err := s.ctx.EntClient.DailyPlan.Query().
|
|
Where(dailyplan.PlanDateGTE(start), dailyplan.PlanDateLTE(end)).All(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for _, p := range plans {
|
|
touch(p.PlanDate, p.OrderNo).PlanQty += p.PlanQty
|
|
}
|
|
|
|
// 实际:完工流水(action=DONE)按完工当天聚合
|
|
logs, err := s.ctx.EntClient.WorkpieceLifecycleLog.Query().
|
|
Where(workpiecelifecyclelog.ActionEQ("DONE"),
|
|
workpiecelifecyclelog.CreatedAtGTE(st),
|
|
workpiecelifecyclelog.CreatedAtLT(en.Add(24*time.Hour))).All(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for _, l := range logs {
|
|
touch(l.CreatedAt.Format("2006-01-02"), l.WorkOrderNo).DoneQty++
|
|
}
|
|
|
|
out := make([]DailyPlanAttainmentRow, 0, len(rows))
|
|
for _, key := range outOrder {
|
|
r := rows[key]
|
|
r.Diff = r.DoneQty - r.PlanQty
|
|
out = append(out, *r)
|
|
}
|
|
sort.Slice(out, func(i, j int) bool {
|
|
if out[i].Date != out[j].Date {
|
|
return out[i].Date < out[j].Date
|
|
}
|
|
return out[i].OrderNo < out[j].OrderNo
|
|
})
|
|
return out, nil
|
|
}
|