From de37cbf8091c7fb8ec7911e0d9aaa7a7db256934 Mon Sep 17 00:00:00 2001 From: fomichev Date: Wed, 2 Jul 2025 12:23:59 +0300 Subject: [PATCH] =?utf8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?utf8?q?=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8=20=D1=80=D0=B0?= =?utf8?q?=D0=B1=D0=BE=D1=82=D1=8B=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/commands/CronController.php | 9 ++++-- erp24/controllers/CategoryPlanController.php | 27 ++++++++++++++--- erp24/views/category-plan/index.php | 2 ++ erp24/web/js/category-plan/index.js | 32 +++++++++++++------- 4 files changed, 51 insertions(+), 19 deletions(-) diff --git a/erp24/commands/CronController.php b/erp24/commands/CronController.php index 86680753..665b5bb1 100644 --- a/erp24/commands/CronController.php +++ b/erp24/commands/CronController.php @@ -1754,6 +1754,7 @@ class CronController extends Controller ->one(); if ($scriptLauncherLog && $scriptLauncherLog['active'] == 1 && $scriptLauncherLog['status'] == 1) { //$task = json_decode($scriptLauncherLog['context'], true ); + // $cache->delete($cacheKey); $this->stdout("Задача уже запущена {$task['startTime']}\n"); return ExitCode::OK; } @@ -1792,6 +1793,7 @@ class CronController extends Controller $log->year = (int)$task['year']; $log->month = (int)$task['month']; $log->active = 1; + $log->progress = 0; $log->status = 1; $log->date_start = date('Y-m-d H:i:s'); if (!$log->save()) { @@ -1913,21 +1915,22 @@ class CronController extends Controller $this->stdout("Сохранена автопланограмма для магазина {$storeId}\n", BaseConsole::FG_GREEN); - $task['status'] = 'done'; $task['progress'] = 100; $cache->set($cacheKey, $task); + $log->context = json_encode($task, JSON_UNESCAPED_UNICODE); $log->message = 'Finished successfully'; $log->progress = 100; $log->active = 0; + $log->progress = 100; $log->date_finish = date('Y-m-d H:i:s'); $log->status = 2; if (!$log->save()) { Yii::error(json_encode($log->getErrors(), JSON_UNESCAPED_UNICODE)); LogService::apiErrorLog(json_encode(["error_id" => 8, "error" => $log->getErrors()], JSON_UNESCAPED_UNICODE)); } - + $cache->delete($cacheKey); $this->stdout("Расчет для магазина {$storeId} закончен\n"); return ExitCode::OK; @@ -1947,7 +1950,7 @@ class CronController extends Controller Yii::error(json_encode($log->getErrors(), JSON_UNESCAPED_UNICODE)); LogService::apiErrorLog(json_encode(["error_id" => 8, "error" => $log->getErrors()], JSON_UNESCAPED_UNICODE)); } - Yii::$app->cache->delete("apRecalculateTask"); + $cache->delete($cacheKey); $this->stderr("Ошибка в ходе расчета: {$e->getMessage()}\n"); return ExitCode::UNSPECIFIED_ERROR; } diff --git a/erp24/controllers/CategoryPlanController.php b/erp24/controllers/CategoryPlanController.php index bc9dc24c..fef27425 100644 --- a/erp24/controllers/CategoryPlanController.php +++ b/erp24/controllers/CategoryPlanController.php @@ -596,7 +596,7 @@ class CategoryPlanController extends Controller { ->asArray() ->limit(1) ->one(); - if ($scriptLauncherLog && $scriptLauncherLog['active'] == 1) { + if ($scriptLauncherLog && $scriptLauncherLog['active'] == 1 && $scriptLauncherLog['status'] == 1) { return $this->asJson(['status' => 'running' ]); } else { $taskName = "apRecalculateTask"; @@ -621,12 +621,29 @@ class CategoryPlanController extends Controller { public function actionCheckTask() { $task = Yii::$app->cache->get('apRecalculateTask'); - if ($task && $task['status'] === 'done') { - Yii::$app->cache->delete("apRecalculateTask"); - } if (!$task) { + $scriptLauncherLog = ScriptLauncherLog::find() + ->andWhere(['name' => "taskApRecalculate"]) + ->orderBy(['created_at' => SORT_DESC]) + ->asArray() + ->limit(1) + ->one(); + + if (!$scriptLauncherLog) { + return $this->asJson(['status' => 'not_found']); + } - return $this->asJson(['status' => 'not_found']); + $dateFinish = $scriptLauncherLog['date_finish']; + $ageSeconds = $dateFinish + ? time() - strtotime($dateFinish) + : null; + + + if ($dateFinish === null || $ageSeconds <= 5) { + $task = json_decode($scriptLauncherLog['context'], true); + } else { + return $this->asJson(['status' => 'not_found']); + } } return $this->asJson([ diff --git a/erp24/views/category-plan/index.php b/erp24/views/category-plan/index.php index f0c91af8..80396cb3 100644 --- a/erp24/views/category-plan/index.php +++ b/erp24/views/category-plan/index.php @@ -172,6 +172,8 @@ input[readonly] {

store_id]?>

+ 'btn btn-success m-2', 'disabled' => true, diff --git a/erp24/web/js/category-plan/index.js b/erp24/web/js/category-plan/index.js index e552ad6a..ce77ad49 100644 --- a/erp24/web/js/category-plan/index.js +++ b/erp24/web/js/category-plan/index.js @@ -136,9 +136,9 @@ function updateChangesLog(store_id) { } }); - $('#changes-hint').remove(); - $('#changes').after('
После внесения всех изменений нажмите на кнопку\n' + - '
"Пересчитать автопланограмму"
'); + $('#changes-hint').show(); + $('#changes').show(); + $('#changes-count').show(); changesBox.html(``).hide(); changesCount.html(`Были внесены изменения (число изменений) - ${count} `); @@ -157,13 +157,20 @@ $(document).ready(() => { language: data_table_language }); const store_id = $('#selected-store').val(); - const changes = JSON.parse(localStorage.getItem('planChanges') || '{}'); + const changesRaw = localStorage.getItem('planChanges'); + const changes = changesRaw ? JSON.parse(changesRaw) : {}; - if (store_id && changes[store_id]) { - updateChangesLog(store_id); - $('#rebuild').prop('disabled', false); - $('#delete').prop('disabled', false); + const hasChanges = changes[store_id] + && Object.keys(changes[store_id]).length > 0; + + if (hasChanges) { + updateChangesLog(store_id); + $('#rebuild, #delete, #filter-btn').prop('disabled', false); + $('#changes-hint,#changes,#changes-count').show(); + } else { + $('#rebuild, #delete').prop('disabled', true); + $('#changes-hint,#changes,#changes-count').hide(); } $('#delete').on('click', function (event) { @@ -262,6 +269,8 @@ function startTaskPolling() { $('#delete').prop('disabled', true); $('#filter-btn').prop('disabled', true); $('#changes-hint').hide(); + $('#changes').hide(); + $('#changes-count').hide(); $('#categoryPlan').addClass('block_table'); } if (data.status === 'done') { @@ -269,9 +278,10 @@ function startTaskPolling() { taskPollInterval = null; localStorage.removeItem('planChanges'); $('#categoryPlan').removeClass('block_table'); - $('#rebuild').prop('disabled', false).text('Пересчитать автопланограмму'); - $('#delete').prop('disabled', false); - $('#changes-hint').remove(); + $('#rebuild').prop('disabled', true).text('Пересчитать автопланограмму'); + $('#delete').prop('disabled', true); + $('#changes-hint').hide(); + $('#changes-count').hide(); $('#changes').hide(); $('#filter-btn').prop('disabled', false); alert('Персчет автопланнограммы успешно завершен'); -- 2.39.5