2026-08-28 15:06:01 +08:00
|
|
|
package logic
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"time"
|
|
|
|
|
|
2026-11-19 08:31:05 +08:00
|
|
|
"bj_power_mes/ent"
|
2026-09-04 14:18:53 +08:00
|
|
|
"bj_power_mes/ent/dailyplan"
|
2026-08-28 15:06:01 +08:00
|
|
|
"bj_power_mes/ent/workorder"
|
|
|
|
|
)
|
|
|
|
|
|
2026-11-19 08:31:05 +08:00
|
|
|
// bumpWorkOrderProgress 增加工单已完成数量(由完工动作驱动)。
|
|
|
|
|
// client 传调用方事务 client(自动完工与报工同事务)时,完工计数随事务一起提交/回滚。
|
|
|
|
|
func (s *Service) bumpWorkOrderProgress(ctx context.Context, client *ent.Client, orderNo, sn string) {
|
|
|
|
|
wo, err := client.WorkOrder.Query().Where(workorder.WorkOrderNo(orderNo)).First(ctx)
|
2026-08-28 15:06:01 +08:00
|
|
|
if err != nil || wo == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if wo.FinishedNum >= wo.Quantity {
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-11-19 08:31:05 +08:00
|
|
|
_, _ = client.WorkOrder.UpdateOneID(wo.ID).
|
2026-08-28 15:06:01 +08:00
|
|
|
SetFinishedNum(wo.FinishedNum + 1).
|
|
|
|
|
SetStatus("IN_PROGRESS").Save(ctx)
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-26 17:18:58 +08:00
|
|
|
// bumpDailyPlanCompleted 工单完工联动当日排产:只累计 completedQty,不动排产状态。
|
2026-09-04 14:18:53 +08:00
|
|
|
// 当天没有匹配排产则跳过(不做自动建单)。仅由真正的完工事件调用。
|
2026-11-26 17:18:58 +08:00
|
|
|
// 2026-11-26 C 方案:排产状态只表示启用开关,执行进度从工单派生,旧的 DONE/PROCESSING 状态不再写。
|
2026-11-19 08:31:05 +08:00
|
|
|
func (s *Service) bumpDailyPlanCompleted(ctx context.Context, client *ent.Client, orderNo string, t time.Time) {
|
2026-09-04 14:18:53 +08:00
|
|
|
date := t.Format("2006-01-02")
|
2026-11-19 08:31:05 +08:00
|
|
|
plans, err := client.DailyPlan.Query().
|
2026-09-04 14:18:53 +08:00
|
|
|
Where(dailyplan.OrderNo(orderNo), dailyplan.PlanDate(date)).
|
2026-11-26 17:18:58 +08:00
|
|
|
Where(dailyplan.StatusIn("PENDING", "CONFIRMED")).All(ctx)
|
2026-09-04 14:18:53 +08:00
|
|
|
if err != nil || len(plans) == 0 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
for _, p := range plans {
|
|
|
|
|
if p.CompletedQty >= p.PlanQty {
|
|
|
|
|
continue
|
|
|
|
|
}
|
2026-11-19 08:31:05 +08:00
|
|
|
_, _ = client.DailyPlan.UpdateOneID(p.ID).
|
2026-11-26 17:18:58 +08:00
|
|
|
SetCompletedQty(p.CompletedQty + 1).Save(ctx)
|
2026-09-04 14:18:53 +08:00
|
|
|
}
|
|
|
|
|
}
|