package logic import ( "context" "time" "bj_power_mes/ent/dailyplan" "bj_power_mes/ent/workorder" ) // bumpWorkOrderProgress 增加工单已完成数量(由完工动作驱动) func (s *Service) bumpWorkOrderProgress(ctx context.Context, orderNo, sn string) { wo, err := s.ctx.EntClient.WorkOrder.Query().Where(workorder.WorkOrderNo(orderNo)).First(ctx) if err != nil || wo == nil { return } if wo.FinishedNum >= wo.Quantity { return } _, _ = s.ctx.EntClient.WorkOrder.UpdateOneID(wo.ID). SetFinishedNum(wo.FinishedNum + 1). SetStatus("IN_PROGRESS").Save(ctx) } // bumpDailyPlanCompleted 工单完工联动当日排产:completedQty+1,达到 planQty 置 DONE。 // 当天没有匹配排产则跳过(不做自动建单)。仅由真正的完工事件调用。 func (s *Service) bumpDailyPlanCompleted(ctx context.Context, orderNo string, t time.Time) { date := t.Format("2006-01-02") plans, err := s.ctx.EntClient.DailyPlan.Query(). Where(dailyplan.OrderNo(orderNo), dailyplan.PlanDate(date)). Where(dailyplan.StatusIn("PENDING", "PROCESSING", "DONE")).All(ctx) if err != nil || len(plans) == 0 { return } for _, p := range plans { if p.CompletedQty >= p.PlanQty { continue } newQty := p.CompletedQty + 1 st := p.Status if newQty >= p.PlanQty { st = "DONE" } else if st == "PENDING" { st = "PROCESSING" } _, _ = s.ctx.EntClient.DailyPlan.UpdateOneID(p.ID). SetCompletedQty(newQty).SetStatus(st).Save(ctx) } }