Skip to content

Commit 365901a

Browse files
committed
fix schedule
1 parent 4bac969 commit 365901a

File tree

2 files changed

+50
-60
lines changed

2 files changed

+50
-60
lines changed

src/ProdScheduler/SchedulerComputeTrait.php

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ public function compute()
1212
{
1313
foreach ($this->list as $k => $item) {
1414
$itemQty = $item['item_qty'];
15-
$itemPhaseMaxCostTime = $item['phase_max_cost'];
16-
$reverseComputePhases = $item['phases_reverse'];
17-
$forwardComputePhases = $item['phases_forward'];
15+
$itemPhaseMaxCostTime = $this->list[$k]['phase_max_cost'];
16+
$reverseComputePhases = $this->list[$k]['phases_reverse'];
17+
$forwardComputePhases = $this->list[$k]['phases_forward'];
1818

1919
$reverseComputePhasesCnt = count($reverseComputePhases);
2020
if (!empty($reverseComputePhasesCnt)) {
@@ -34,7 +34,7 @@ public function compute()
3434
$originStart = $start = $this->list[$k - 1]['phases_forward'][0]['start'];
3535
}
3636
} else {
37-
$nextPhase = $reverseComputePhases[$i + 1];
37+
$nextPhase = $this->list[$k]['phases_reverse'][$i + 1];
3838
$originStart = $start = $nextPhase['start'];
3939
$start -= ($itemPhase['dead_time'] + $itemPhase['ahead_time']);
4040
if ($itemPhase['out_time'] > 0) {
@@ -61,7 +61,7 @@ public function compute()
6161
}
6262
}
6363

64-
$initialPhase = $reverseComputePhases[$reverseComputePhasesCnt - 1];
64+
$initialPhase = $this->list[$k]['phases_reverse'][$reverseComputePhasesCnt - 1];
6565
if (isset($initialPhase)) {
6666
foreach ($forwardComputePhases as $i => $itemPhase) {
6767
$workerNum = $itemPhase['worker_num'];
@@ -72,7 +72,7 @@ public function compute()
7272
$originStart = $initialPhase['start'];
7373
$start = $originStart + $initialPhase['dead_time'] + $initialPhase['ahead_time'];
7474
} else {
75-
$prevItem = $forwardComputePhases[$i - 1];
75+
$prevItem = $this->list[$k]['phases_forward'][$i - 1];
7676
if ($prevItem['out_time'] > 0) {
7777
$originStart = $start = $prevItem['end'];
7878
} else {
@@ -102,20 +102,21 @@ public function compute()
102102

103103
private function initialStartTimeCompute(): int
104104
{
105+
$initialScheduleDate = date(self::SCHEDULER_DATE_FORMAT, $this->ISTS);
105106
$dayCalendar = $this->getDayCalendar($this->ISTS);
106107

107-
$initialScheduleDate = date(self::SCHEDULER_DATE_FORMAT, $this->ISTS);
108108
if ($this->computeDirection === 1) {
109109
if (empty($dayCalendar)) {
110110
$dayCalendarStartTime = $this->getDayCalendarStartTime($this->defaultDayCalendar);
111111

112112
$this->ISDT = $initialScheduleDate . " " . $dayCalendarStartTime;
113113
} else {
114-
foreach ($dayCalendar as $k => $day) {
114+
$monthCalendar = $this->getMonthCalendar();
115+
foreach ($monthCalendar as $k => $day) {
115116
if ($initialScheduleDate === $day['date']) {
116117
if ($day['is_rest'] === 1) {
117-
if ($k !== count($dayCalendar)) {
118-
$nextDayCalendar = $dayCalendar[$k + 1];
118+
if ($k !== count($monthCalendar)) {
119+
$nextDayCalendar = $monthCalendar[$k + 1];
119120
if ($nextDayCalendar['is_rest'] === 1) {
120121
continue;
121122
} else {
@@ -194,44 +195,40 @@ private function phaseTimeWithCalendarCompute(int $originStart, int &$start, boo
194195
$dayDuration = $calendar['dayDuration'];
195196
}
196197

197-
foreach ($calendar as $c) {
198-
if ($start >= $dayStart && $start <= $dayEnd) {
199-
$times = $c['rest'];
200-
foreach ($times as $t) {
201-
$restStart = strtotime("{$originStartDate} {$t['start']}");
202-
$restEnd = strtotime("{$originStartDate} {$t['end']}");
198+
if ($start >= $dayStart && $start <= $dayEnd) {
199+
$times = $calendar['rest'];
200+
foreach ($times as $t) {
201+
$restStart = strtotime("{$originStartDate} {$t['start']}");
202+
$restEnd = strtotime("{$originStartDate} {$t['end']}");
203203

204-
if ($start >= $restStart && $start < $restEnd) {
204+
if ($start >= $restStart && $start < $restEnd) {
205+
if ($isReverse) {
206+
$start -= $t['duration'];
207+
} else {
208+
$start += $t['duration'];
209+
}
210+
} else {
211+
$cycle = 10 * 60;
212+
$cycleCount = ceil($diff / $cycle);
213+
$_start = $originStart;
214+
for ($i = 1; $i <= $cycleCount; $i++) {
205215
if ($isReverse) {
206-
$start -= $t['duration'];
216+
$_start -= $cycle * $i;
217+
218+
if ($_start >= $restStart && $_start < $restEnd) {
219+
$start -= $t['duration'];
220+
break;
221+
}
207222
} else {
208-
$start += $t['duration'];
209-
}
210-
} else {
211-
$cycle = 10 * 60;
212-
$cycleCount = ceil($diff / $cycle);
213-
$_start = $originStart;
214-
for ($i = 1; $i <= $cycleCount; $i++) {
215-
if ($isReverse) {
216-
$_start -= $cycle * $i;
217-
218-
if ($_start >= $restStart && $_start < $restEnd) {
219-
$start -= $t['duration'];
220-
break;
221-
}
222-
} else {
223-
$_start += $cycle * $i;
223+
$_start += $cycle * $i;
224224

225-
if ($_start >= $restStart && $_start < $restEnd) {
226-
$start += $t['duration'];
227-
break;
228-
}
225+
if ($_start >= $restStart && $_start < $restEnd) {
226+
$start += $t['duration'];
227+
break;
229228
}
230229
}
231230
}
232231
}
233-
} else {
234-
break;
235232
}
236233
}
237234

@@ -279,7 +276,7 @@ private function phaseTimeWithCalendarCompute(int $originStart, int &$start, boo
279276

280277
private function phaseTimeWithRestDayCompute(int &$time, bool $isReverse = false): int
281278
{
282-
$calendar = $this->getDayCalendar();
279+
$calendar = $this->getMonthCalendar();
283280

284281
foreach ($calendar as $c) {
285282
if (strtotime($c['date']) < $time && $c['is_rest'] === 1) {

src/ProdScheduler/SchedulerConfigTrait.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ private function parseConfig(array $config)
5555
$this->computeDirection = $config['computeDirection'];
5656
$this->ISDT = $config['start'];
5757
$this->ISTS = strtotime($config['start']);
58-
$this->list = $this->parseList($config['list']);
58+
$this->initialPhase = $config['initialPhase'];
5959
$this->listPhase = $config['listPhase'];
60-
$this->defaultDayCalendar = $this->parseCalendar($config['calendar']);
6160
$this->EDQ = $config['edq'];
61+
$this->list = $this->parseList($config['list']);
62+
$this->defaultDayCalendar = $this->parseCalendar($config['calendar']);
6263
$this->monthCalendar = $this->parseCalendars($config['monthCalendar']);
6364
$this->nextMonthCalendar = $this->parseCalendars($config['nextMonthCalendar']);
6465
$this->prevMonthCalendar = $this->parseCalendars($config['prevMonthCalendar']);
65-
$this->initialPhase = $config['initialPhase'];
6666

6767
$this->initialStartTimeCompute();
6868
}
@@ -201,35 +201,26 @@ function ($e) {
201201
return [$maxCostTime, $reversePhase, $forwardPhase];
202202
}
203203

204-
return [];
204+
return [[], [], []];
205205
}
206206

207207
private function getDayCalendarStartTime(array $calendar): string
208208
{
209209
$dayCalendarStartTime = '';
210-
if (isset($calendar['profile']) && count($calendar['profile']) > 0) {
211-
$profile = $calendar['profile'][0];
212-
if (isset($profile['dayStart'])) {
213-
$dayCalendarStartTime = $profile['dayStart'];
210+
if (isset($calendar['profile']) && isset($calendar['profile']['times']) && count($calendar['profile']['times']) > 0) {
211+
$profile = $calendar['profile']['times'][0];
212+
213+
if (isset($profile['start'])) {
214+
$dayCalendarStartTime = $profile['start'];
214215
} elseif (isset($profile['times']) && count($profile['times']) > 0) {
215216
if ($profile['times'][0]['start']) {
216217
$dayCalendarStartTime = $profile['times'][0]['start'];
217218
}
218219
}
219220
}
220-
221221
if (empty($dayCalendarStartTime)) {
222222
$defaultDayCalendar = $this->getDefaultDayCalendar();
223-
if (isset($defaultDayCalendar['profile']) && count($defaultDayCalendar['profile']) > 0) {
224-
$profile = $defaultDayCalendar['profile'][0];
225-
if (isset($profile['dayStart'])) {
226-
$dayCalendarStartTime = $profile['dayStart'];
227-
} elseif (isset($profile['times']) && count($profile['times']) > 0) {
228-
if ($profile['times'][0]['start']) {
229-
$dayCalendarStartTime = $profile['times'][0]['start'];
230-
}
231-
}
232-
}
223+
$dayCalendarStartTime = $this->getDayCalendarStartTime($defaultDayCalendar);
233224
}
234225

235226
return $dayCalendarStartTime;
@@ -345,6 +336,8 @@ public function getDayCalendar(int $ts = 0): array
345336
}
346337
}
347338

339+
$c['profile']['date'] = $date;
340+
348341
return $c['profile'];
349342
}
350343

0 commit comments

Comments
 (0)