|
|
@@ -81,20 +81,36 @@ class ClearController extends Controller
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 回填 xhOrderCgClear:clearStyle 1(hd2Gys) + 2(gys2Hd)
|
|
|
+ * 漏补 xhOrderCgClear:clearStyle 1(hd2Gys) + 2(gys2Hd) + 3(gys2KmGys) 统一扫描
|
|
|
+ *
|
|
|
+ * 仅处理:无关系行 / 关系行不足 / amount 为空 / gys2KmGys 旧格式;已完整则跳过。
|
|
|
*
|
|
|
* 用法:
|
|
|
- * php yii clear/backfill-order-cg-clear-hd-gys --dryRun=1 --limit=100
|
|
|
- * php yii clear/backfill-order-cg-clear-hd-gys --reset=1 --batchSize=50 --sleepMs=200
|
|
|
+ * php yii clear/backfill-order-cg-clear --dryRun=1 --limit=1000
|
|
|
+ * php yii clear/backfill-order-cg-clear --reset=1 --batchSize=50 --sleepMs=200
|
|
|
+ * php yii clear/backfill-order-cg-clear --clearId=123
|
|
|
+ */
|
|
|
+ public function actionBackfillOrderCgClear()
|
|
|
+ {
|
|
|
+ return $this->runBackfillOrderCgClear(
|
|
|
+ OrderCgClearClass::getRelationClearStyles(),
|
|
|
+ 'all',
|
|
|
+ 'hd2Gys(1)+gys2Hd(2)+gys2KmGys(3)',
|
|
|
+ true
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @deprecated 请改用 backfill-order-cg-clear(已合并 1+2+3)
|
|
|
*/
|
|
|
public function actionBackfillOrderCgClearHdGys()
|
|
|
{
|
|
|
- $clearStyles = [
|
|
|
- intval(dict::getDict('clearStyle', 'hd2Gys')),
|
|
|
- intval(dict::getDict('clearStyle', 'gys2Hd')),
|
|
|
- ];
|
|
|
+ $this->stderr("已合并至: php yii clear/backfill-order-cg-clear\n");
|
|
|
return $this->runBackfillOrderCgClear(
|
|
|
- $clearStyles,
|
|
|
+ [
|
|
|
+ intval(dict::getDict('clearStyle', 'hd2Gys')),
|
|
|
+ intval(dict::getDict('clearStyle', 'gys2Hd')),
|
|
|
+ ],
|
|
|
'hd_gys',
|
|
|
'hd2Gys(1)+gys2Hd(2)',
|
|
|
false
|
|
|
@@ -102,37 +118,19 @@ class ClearController extends Controller
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 回填 xhOrderCgClear:clearStyle 3(gys2KmGys) 供货商向昆明供货商结账
|
|
|
- *
|
|
|
- * 用法:
|
|
|
- * php yii clear/rebuild-order-cg-clear-index
|
|
|
- * php yii clear/backfill-order-cg-clear-km-gys --dryRun=1 --limit=100
|
|
|
- * php yii clear/backfill-order-cg-clear-km-gys --reset=1 --batchSize=50 --sleepMs=200
|
|
|
+ * @deprecated 请改用 backfill-order-cg-clear(已合并 1+2+3)
|
|
|
*/
|
|
|
public function actionBackfillOrderCgClearKmGys()
|
|
|
{
|
|
|
- $clearStyles = [
|
|
|
- intval(dict::getDict('clearStyle', 'gys2KmGys')),
|
|
|
- ];
|
|
|
+ $this->stderr("已合并至: php yii clear/backfill-order-cg-clear\n");
|
|
|
return $this->runBackfillOrderCgClear(
|
|
|
- $clearStyles,
|
|
|
+ [intval(dict::getDict('clearStyle', 'gys2KmGys'))],
|
|
|
'km_gys',
|
|
|
'gys2KmGys(3)',
|
|
|
true
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @deprecated 请改用 backfill-order-cg-clear-hd-gys 与 backfill-order-cg-clear-km-gys
|
|
|
- */
|
|
|
- public function actionBackfillOrderCgClear()
|
|
|
- {
|
|
|
- $this->stderr("请使用独立脚本:\n");
|
|
|
- $this->stderr(" php yii clear/backfill-order-cg-clear-hd-gys --reset=1\n");
|
|
|
- $this->stderr(" php yii clear/backfill-order-cg-clear-km-gys --reset=1\n");
|
|
|
- return ExitCode::UNSPECIFIED_ERROR;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 迁移 gys2KmGys 关系行:orderId/cgId 旧格式 -> cgId 存 xhGhsCgOrder、orderId=0
|
|
|
*
|
|
|
@@ -213,10 +211,12 @@ class ClearController extends Controller
|
|
|
$total = 0;
|
|
|
$inserted = 0;
|
|
|
$skipped = 0;
|
|
|
+ $needBackfill = 0;
|
|
|
$batchNo = 0;
|
|
|
+ $styleStats = [];
|
|
|
|
|
|
$this->stdout(sprintf(
|
|
|
- "开始回填 xhOrderCgClear [%s] | id DESC 分批 | dryRun=%d batchSize=%d sleepMs=%d limit=%d | 续跑 id<%s | 进度=%s\n",
|
|
|
+ "开始漏补 xhOrderCgClear [%s] | id DESC 分批 | dryRun=%d batchSize=%d sleepMs=%d limit=%d | 续跑 id<%s | 进度=%s\n",
|
|
|
$label,
|
|
|
(int)$this->dryRun,
|
|
|
$this->batchSize,
|
|
|
@@ -254,13 +254,20 @@ class ClearController extends Controller
|
|
|
foreach ($list as $clear) {
|
|
|
$total++;
|
|
|
$currentClearId = intval($clear['id'] ?? 0);
|
|
|
+ $clearStyle = intval($clear['clearStyle'] ?? 0);
|
|
|
$batchMinId = $currentClearId;
|
|
|
$cursorId = $currentClearId;
|
|
|
|
|
|
+ if (!isset($styleStats[$clearStyle])) {
|
|
|
+ $styleStats[$clearStyle] = ['scan' => 0, 'need' => 0, 'skip' => 0];
|
|
|
+ }
|
|
|
+ $styleStats[$clearStyle]['scan']++;
|
|
|
+
|
|
|
$saleIds = trim($clear['saleIds'] ?? '');
|
|
|
$purchaseIds = trim($clear['purchaseIds'] ?? '');
|
|
|
if ($saleIds === '' && $purchaseIds === '') {
|
|
|
$skipped++;
|
|
|
+ $styleStats[$clearStyle]['skip']++;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
@@ -272,12 +279,24 @@ class ClearController extends Controller
|
|
|
$legacyGys2KmGysClearIds
|
|
|
)) {
|
|
|
$skipped++;
|
|
|
+ $styleStats[$clearStyle]['skip']++;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
+ $needBackfill++;
|
|
|
+ $styleStats[$clearStyle]['need']++;
|
|
|
+
|
|
|
if ($this->dryRun) {
|
|
|
- if ($this->logEvery > 0 && $total % $this->logEvery === 0) {
|
|
|
- $this->stdout("dryRun 已扫描 {$total} 条,当前 clearId={$currentClearId}\n");
|
|
|
+ $expected = OrderCgClearClass::expectedRelationCountFromClear($clear);
|
|
|
+ $this->stdout(sprintf(
|
|
|
+ "需漏补 clearId=%d clearStyle=%d 已有关系=%d 应有≈%d\n",
|
|
|
+ $currentClearId,
|
|
|
+ $clearStyle,
|
|
|
+ $relationCount,
|
|
|
+ $expected
|
|
|
+ ));
|
|
|
+ if ($this->logEvery > 0 && $needBackfill % $this->logEvery === 0) {
|
|
|
+ $this->stdout("dryRun 需漏补累计 {$needBackfill} 条\n");
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
@@ -287,9 +306,12 @@ class ClearController extends Controller
|
|
|
$inserted += $count;
|
|
|
} else {
|
|
|
$skipped++;
|
|
|
+ $styleStats[$clearStyle]['skip']++;
|
|
|
+ $styleStats[$clearStyle]['need']--;
|
|
|
+ $needBackfill--;
|
|
|
}
|
|
|
if ($this->logEvery > 0 && $total % $this->logEvery === 0) {
|
|
|
- $this->stdout("进度:扫描 {$total},写入关系 {$inserted} 行,跳过 {$skipped},当前 clearId={$currentClearId}\n");
|
|
|
+ $this->stdout("进度:扫描 {$total},需漏补 {$needBackfill},写入关系 {$inserted} 行,跳过 {$skipped},当前 clearId={$currentClearId}\n");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -298,10 +320,11 @@ class ClearController extends Controller
|
|
|
}
|
|
|
|
|
|
$this->stdout(sprintf(
|
|
|
- "第 %d 批完成:本批 %d 条,累计扫描 %d,写入关系 %d 行,跳过 %d,checkpoint id=%d\n",
|
|
|
+ "第 %d 批完成:本批 %d 条,累计扫描 %d,需漏补 %d,写入关系 %d 行,跳过 %d,checkpoint id=%d\n",
|
|
|
$batchNo,
|
|
|
count($list),
|
|
|
$total,
|
|
|
+ $needBackfill,
|
|
|
$inserted,
|
|
|
$skipped,
|
|
|
(int)$batchMinId
|
|
|
@@ -316,7 +339,26 @@ class ClearController extends Controller
|
|
|
if (!$this->dryRun && $this->clearId <= 0 && $cursorId !== null) {
|
|
|
$this->stdout("进度已保存,下次从 id < {$cursorId} 继续\n");
|
|
|
}
|
|
|
- $this->stdout("全部完成 [{$label}]:扫描 {$total} 条 xhClear,写入 {$inserted} 行关系,跳过 {$skipped} 条\n");
|
|
|
+ $this->stdout(sprintf(
|
|
|
+ "全部完成 [%s]:扫描 %d 条 xhClear,需漏补 %d 条,写入 %d 行关系,跳过 %d 条\n",
|
|
|
+ $label,
|
|
|
+ $total,
|
|
|
+ $needBackfill,
|
|
|
+ $inserted,
|
|
|
+ $skipped
|
|
|
+ ));
|
|
|
+ if (!empty($styleStats)) {
|
|
|
+ ksort($styleStats);
|
|
|
+ foreach ($styleStats as $style => $stat) {
|
|
|
+ $this->stdout(sprintf(
|
|
|
+ " clearStyle=%d:扫描 %d,需漏补 %d,跳过 %d\n",
|
|
|
+ $style,
|
|
|
+ (int)$stat['scan'],
|
|
|
+ (int)$stat['need'],
|
|
|
+ (int)$stat['skip']
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ }
|
|
|
return ExitCode::OK;
|
|
|
}
|
|
|
|