diff --git a/dao/om/implments/WorkOrder.dao.impl.go b/dao/om/implments/WorkOrder.dao.impl.go index 213dd22..9799505 100644 --- a/dao/om/implments/WorkOrder.dao.impl.go +++ b/dao/om/implments/WorkOrder.dao.impl.go @@ -338,7 +338,7 @@ func (impl *WorkOrderDAOImplement) SelectStartedTasks(startTime, endTime time.Ti session := impl.session.Table(impl.meta.TableName) if err = session.Join("INNER", "OM_WorkOrderStatus", "OM_WorkOrderStatus.PlantNr = OM_WorkOrder.PlantNr and OM_WorkOrderStatus.WorkOrderId = OM_WorkOrder.WorkOrderId").Join("INNER", "OM_WorkOrderQty", - "OM_WorkOrderQty.PlantNr = OM_WorkOrder.PlantNr and OM_WorkOrderQty.WorkOrderId = OM_WorkOrder.WorkOrderId").Where("OM_WorkOrder.PlantNr = ? and OM_WorkOrderStatus.Status >= ? and (OM_WorkOrder.ActStartTime >= ? and OM_WorkOrder.ActEndTime < ?) or (OM_WorkOrder.ActStartTime >= ? and OM_WorkOrder.ActEndTime < ?)", impl.plantNr, common.WO_STATUS_INTERRUPT, startData, endData, startData, endData).Find(&vdatalst); err != nil { + "OM_WorkOrderQty.PlantNr = OM_WorkOrder.PlantNr and OM_WorkOrderQty.WorkOrderId = OM_WorkOrder.WorkOrderId").Where("OM_WorkOrder.PlantNr = ? and OM_WorkOrderStatus.Status >= ? and (OM_WorkOrder.ActStartTime <= ? and OM_WorkOrder.ActEndTime > ?) or (OM_WorkOrder.ActStartTime <= ? and OM_WorkOrder.ActEndTime > ?)", impl.plantNr, common.WO_STATUS_INTERRUPT, startData, startData, endData, endData).Find(&vdatalst); err != nil { return } fmt.Println(vdatalst) @@ -370,7 +370,7 @@ func (impl *WorkOrderDAOImplement) SelectPlannedTasks(startTime, endTime time.Ti session := impl.session.Table(impl.meta.TableName) if err = session.Join("INNER", "OM_WorkOrderStatus", "OM_WorkOrderStatus.PlantNr = OM_WorkOrder.PlantNr and OM_WorkOrderStatus.WorkOrderId = OM_WorkOrder.WorkOrderId").Join("INNER", "OM_WorkOrderQty", - "OM_WorkOrderQty.PlantNr = OM_WorkOrder.PlantNr and OM_WorkOrderQty.WorkOrderId = OM_WorkOrder.WorkOrderId").Where("OM_WorkOrder.PlantNr = ? and OM_WorkOrderStatus.Status >= ? and OM_WorkOrderStatus.Status < ? and (OM_WorkOrder.PlanStartTime >= ? and OM_WorkOrder.PlanEndTime < ?) or (OM_WorkOrder.PlanStartTime >= ? and OM_WorkOrder.PlanEndTime < ?)", impl.plantNr, common.WO_STATUS_PLANNED, common.WO_STATUS_INTERRUPT, startData, endData, startData, endData).Find(&vdatalst); err != nil { + "OM_WorkOrderQty.PlantNr = OM_WorkOrder.PlantNr and OM_WorkOrderQty.WorkOrderId = OM_WorkOrder.WorkOrderId").Where("OM_WorkOrder.PlantNr = ? and OM_WorkOrderStatus.Status >= ? and OM_WorkOrderStatus.Status < ? and (OM_WorkOrder.PlanStartTime <= ? and OM_WorkOrder.PlanEndTime > ?) or (OM_WorkOrder.PlanStartTime <= ? and OM_WorkOrder.PlanEndTime > ?)", impl.plantNr, common.WO_STATUS_PLANNED, common.WO_STATUS_INTERRUPT, startData, startData, endData, endData).Find(&vdatalst); err != nil { return } datalst = make([]model.WorkOrder, 0) @@ -512,8 +512,8 @@ func (impl *WorkOrderDAOImplement) SelectByPage(projectId, artId, start, end, wo * @Reference LAPP_GAAS_GFrame_BACKEND/dao/om/WorkOrderDAO.SelectLastModify * ******************************************************************************/ -func (impl *WorkOrderDAOImplement) SelectLastModify() (data model.WorkOrder,err error) { - ok, err := impl.session.Table(impl.meta.TableName).Where("PlantNr = ? ",impl.plantNr).Desc("LastModify").Limit(1).Get(&data) +func (impl *WorkOrderDAOImplement) SelectLastModify() (data model.WorkOrder, err error) { + ok, err := impl.session.Table(impl.meta.TableName).Where("PlantNr = ? ", impl.plantNr).Desc("LastModify").Limit(1).Get(&data) if err != nil { return data, grmi.NewDataBaseError(err) } @@ -544,7 +544,7 @@ func (impl *WorkOrderDAOImplement) SelectLockWorkOrder(workLineId string) ([]mod session = session.Join("LEFT", meta.WorkOrderStatus.TableName, statusCondition) session = session.Join("LEFT", meta.WorkOrderQty.TableName, qtyCondition) where := fmt.Sprintf("%s = ? and %s = ? and %s = ?", meta.WorkOrder_PlantNr.ColumnName, meta.WorkOrder_PlanResourceId.ColumnName, meta.WorkOrderStatus_Status.ColumnName) - err := session.Where(where, impl.plantNr,workLineId, common.WO_STATUS_LOCKED).Asc(meta.WorkOrder_PlanStartTime.ColumnName).Find(&data) + err := session.Where(where, impl.plantNr, workLineId, common.WO_STATUS_LOCKED).Asc(meta.WorkOrder_PlanStartTime.ColumnName).Find(&data) if err != nil { return nil, err } @@ -588,5 +588,3 @@ func (impl *WorkOrderDAOImplement) SelectOneJoin(workOrderId string) (*model.VOm } return &data, nil } - - diff --git a/services/schedule/Schedule_test.go b/services/schedule/Schedule_test.go index a14de08..1ca8f21 100644 --- a/services/schedule/Schedule_test.go +++ b/services/schedule/Schedule_test.go @@ -34,7 +34,7 @@ func TestScheduler(t *testing.T) { pathLogDir := filepath.Join(baseDir, "glog") fmt.Println(pathLogDir) glog.DefaultInit(true, pathLogDir) - + utils.TimezoneLocation, err = time.LoadLocation("Asia/Shanghai") glog.Infoln("启动日志", "InitDB return success") // 建立数据库连接 //加载配置 @@ -51,7 +51,7 @@ func TestScheduler(t *testing.T) { fmt.Println("数据库加载成功") // 初始化scheduler,默认从当天起计划5天 y1, m1, d1 = time.Now().Date() - startDate = time.Date(y1, m1, d1, 0, 0, 0, 0, time.UTC) + startDate = time.Date(y1, m1, d1, 0, 0, 0, 0, time.Local) endDate = startDate.Add(24 * 5 * time.Hour) fmt.Println() fmt.Println(startDate) diff --git a/services/schedule/Scheduler.Ctrl.go b/services/schedule/Scheduler.Ctrl.go index 9cc14cd..3142288 100644 --- a/services/schedule/Scheduler.Ctrl.go +++ b/services/schedule/Scheduler.Ctrl.go @@ -297,7 +297,7 @@ func (schedsrv *SchedulerSrv) ScheduleTask(worklineid string, task *TaskSrv) (er tlinesrv = TimeLineSrv{} switch task.Status { case common.WO_STATUS_UNPLANNED: - endTime = wlsrv.TimeCurve.CalEndTime(startTime, task.Duration) + startTime,endTime = wlsrv.TimeCurve.CalEndTime(startTime, task.Duration) tlinesrv.StartTime = startTime tlinesrv.EndTime = endTime task.SchedStartTime = startTime @@ -394,21 +394,21 @@ func (schedsrv *SchedulerSrv) RepairSchedule(worklineid string) (err error) { tlinesrv = TimeLineSrv{} switch wlsrv.SchedTaskArray[i].Status { case common.WO_STATUS_UNPLANNED: - wlsrv.SchedTaskArray[i].SchedEndTime = wlsrv.TimeCurve.CalEndTime(wlsrv.SchedTaskArray[i].SchedStartTime, wlsrv.SchedTaskArray[i].Duration) + wlsrv.SchedTaskArray[i].SchedStartTime,wlsrv.SchedTaskArray[i].SchedEndTime = wlsrv.TimeCurve.CalEndTime(wlsrv.SchedTaskArray[i].SchedStartTime, wlsrv.SchedTaskArray[i].Duration) tlinesrv.StartTime = wlsrv.SchedTaskArray[i].SchedStartTime tlinesrv.EndTime = wlsrv.SchedTaskArray[i].SchedEndTime case common.WO_STATUS_PLANNED: - wlsrv.SchedTaskArray[i].SchedEndTime = wlsrv.TimeCurve.CalEndTime(wlsrv.SchedTaskArray[i].SchedStartTime, wlsrv.SchedTaskArray[i].Duration) + wlsrv.SchedTaskArray[i].SchedStartTime,wlsrv.SchedTaskArray[i].SchedEndTime = wlsrv.TimeCurve.CalEndTime(wlsrv.SchedTaskArray[i].SchedStartTime, wlsrv.SchedTaskArray[i].Duration) tlinesrv.StartTime = wlsrv.SchedTaskArray[i].SchedStartTime tlinesrv.EndTime = wlsrv.SchedTaskArray[i].SchedEndTime case common.WO_STATUS_RELEASED: - wlsrv.SchedTaskArray[i].SchedEndTime = wlsrv.TimeCurve.CalEndTime(wlsrv.SchedTaskArray[i].SchedStartTime, wlsrv.SchedTaskArray[i].Duration) + wlsrv.SchedTaskArray[i].SchedStartTime,wlsrv.SchedTaskArray[i].SchedEndTime = wlsrv.TimeCurve.CalEndTime(wlsrv.SchedTaskArray[i].SchedStartTime, wlsrv.SchedTaskArray[i].Duration) tlinesrv.StartTime = wlsrv.SchedTaskArray[i].SchedStartTime tlinesrv.EndTime = wlsrv.SchedTaskArray[i].SchedEndTime case common.WO_STATUS_RUNNING: percent := (wlsrv.SchedTaskArray[i].PlanQty - wlsrv.SchedTaskArray[i].FinishedQty) / wlsrv.SchedTaskArray[i].PlanQty seconds := wlsrv.SchedTaskArray[i].Duration.Seconds() * percent - wlsrv.SchedTaskArray[i].SchedEndTime = wlsrv.TimeCurve.CalEndTime(time.Now(), time.Duration(seconds)*time.Second) + wlsrv.SchedTaskArray[i].SchedStartTime,wlsrv.SchedTaskArray[i].SchedEndTime = wlsrv.TimeCurve.CalEndTime(time.Now(), time.Duration(seconds)*time.Second) tlinesrv.StartTime = wlsrv.SchedTaskArray[i].ActStartTime tlinesrv.EndTime = wlsrv.SchedTaskArray[i].SchedEndTime case common.WO_STATUS_FINISHED: diff --git a/services/schedule/TimeCurve.Ctrl.go b/services/schedule/TimeCurve.Ctrl.go index 19ea0ac..6d564f3 100644 --- a/services/schedule/TimeCurve.Ctrl.go +++ b/services/schedule/TimeCurve.Ctrl.go @@ -1,6 +1,7 @@ package schedule import ( + "LAPP_GAAS_GFrame_BACKEND/utils" "container/list" "time" ) @@ -507,10 +508,10 @@ func (tcs *TimeCurveSrv) SubTimeLine(subtlsrv TimeLineSrv) (err error) { } // 基于起始时间点和Duration计算在当前时间曲线上的结束时间点 -func (tcs *TimeCurveSrv) CalEndTime(startTime time.Time, duration time.Duration) (endTime time.Time) { +func (tcs *TimeCurveSrv) CalEndTime(startTime time.Time, duration time.Duration) (sTime time.Time ,endTime time.Time) { var ( - i int - calDuration, totalDuration time.Duration + i int + zeroDuration, calDuration, totalDuration time.Duration ) // 处理临界条件 if duration <= 0 { @@ -540,17 +541,40 @@ func (tcs *TimeCurveSrv) CalEndTime(startTime time.Time, duration time.Duration) return } totalDuration = 0 + zeroDuration = 0 + /************ + * / ------ / *** ------***----- / + * / -----*** ------***--- / + * 0 1 2 3 + * 横线代表可用时间,*代表不可用时间 + *问题: 求出时间2 的时间节点? 已知 时间1和时间3的节点,0-3的可用时间间隔,1-2的可用时间间隔 + *逻辑: 求出 0-1的时间间隔, 用0-3的时间间隔 减去(0-1)减去(1-2) 计算出(2-3)间隔 ,用3点时间点减去(2-3)时间间隔得出时间2的时间点 + **********************/ + startbool := true + sTime = startTime for i = 0; i < len(tcs.TimeLineArray); i++ { if startTime.Unix() >= tcs.TimeLineArray[i].EndTime.Unix() { continue } + + if startbool { + //记录时间0的节点 + zeroStartTime := tcs.TimeLineArray[i].StartTime + //计算0-1时间间隔 + zeroDuration = utils.GetDuration(zeroStartTime, startTime, tcs.TimeLineArray[i].EffFactor) + //如果开始时间落到中断时间区间内,则开始时间变成可用时间的开始时间 + if startTime.Unix() < tcs.TimeLineArray[i].StartTime.Unix(){ + sTime = tcs.TimeLineArray[i].StartTime + } + startbool = false + } totalDuration = totalDuration + tcs.TimeLineArray[i].Duration - if totalDuration >= calDuration { - endTime = tcs.TimeLineArray[i].GetEndTimeByDuration(totalDuration - calDuration) + if (totalDuration - zeroDuration) >= calDuration { + endTime = tcs.TimeLineArray[i].GetEndTimeByDuration(totalDuration - calDuration - zeroDuration) return } - endTime = tcs.TimeLineArray[i].EndTime.Add(calDuration - totalDuration) - return + + //endTime = tcs.TimeLineArray[i].EndTime.Add(calDuration - totalDuration) } return } diff --git a/services/schedule/TimeLine.Ctrl.go b/services/schedule/TimeLine.Ctrl.go index d0f0858..d455784 100644 --- a/services/schedule/TimeLine.Ctrl.go +++ b/services/schedule/TimeLine.Ctrl.go @@ -67,7 +67,7 @@ func (tlsrv *TimeLineSrv)GetEndTimeByDuration(duration time.Duration)(endTime ti tlsrv.EffFactor = 1.0 } seconds = duration.Seconds() / tlsrv.EffFactor - endTime = tlsrv.StartTime.Add(time.Duration(seconds) * time.Second) + endTime = tlsrv.EndTime.Add(-time.Duration(seconds) * time.Second) return } return diff --git a/services/schedule/WorkLine.Ctrl.go b/services/schedule/WorkLine.Ctrl.go index 2206a42..4fe7792 100644 --- a/services/schedule/WorkLine.Ctrl.go +++ b/services/schedule/WorkLine.Ctrl.go @@ -219,7 +219,7 @@ func(wlsrv *WorklineSrv)CalDailyWorkload(){ // 基于指定的时间区间按天遍历 crossDays = utils.GetCrossDays(wlsrv.TimeCurve.StartTime, wlsrv.TimeCurve.EndTime) y1,m1,d1 = wlsrv.TimeCurve.StartTime.Date() - startTime = time.Date(y1, m1, d1, 0, 0, 0, 0, time.UTC) + startTime = time.Date(y1, m1, d1, 0, 0, 0, 0, time.Local) for i = 0; i < crossDays; i++ { t1 = startTime.Add(time.Duration(i*24)*time.Hour) t2 = t1.Add(24*time.Hour) diff --git a/services/schedule/WorkLoad.Ctrl.go b/services/schedule/WorkLoad.Ctrl.go index bf15003..f0adaa1 100644 --- a/services/schedule/WorkLoad.Ctrl.go +++ b/services/schedule/WorkLoad.Ctrl.go @@ -1,6 +1,8 @@ package schedule -import "time" +import ( + "time" +) type WorkLoadSrv struct { LoadType string diff --git a/utils/time.go b/utils/time.go index b4fd3e3..3e60f94 100644 --- a/utils/time.go +++ b/utils/time.go @@ -347,4 +347,19 @@ func ParseWeekIndex(date time.Time) int { } } return 0 +} + +// 获取线段上两个时间点之间的Duration +func GetDuration(startTime, endTime time.Time,EffFactor float64)(duration time.Duration){ + var seconds float64 + if endTime.Unix() <= startTime.Unix(){ + duration = 0 + return + } + if EffFactor <= 0{ + EffFactor = 1 + } + seconds = endTime.Sub(startTime).Seconds() * EffFactor + duration = time.Duration(seconds) * time.Second + return } \ No newline at end of file