parent
886f66293b
commit
8563a3f635
@ -31,7 +31,8 @@ class KukaPostingMaterialMapSynchronizer
|
||||
* unmatched: int,
|
||||
* ambiguous: int,
|
||||
* direct: int,
|
||||
* archive: int
|
||||
* archive: int,
|
||||
* brand_sku: int
|
||||
* }
|
||||
*/
|
||||
public function sync(int $companyId = 1, ?string $period = null, bool $dryRun = false): array
|
||||
@ -53,9 +54,9 @@ class KukaPostingMaterialMapSynchronizer
|
||||
throw new RuntimeException('当前账期没有可用于匹配的货号。');
|
||||
}
|
||||
|
||||
$quoteMaterials = $this->activeQuoteMaterials($connection, $companyId);
|
||||
[$direct, $archive] = $this->sourceCandidates($items);
|
||||
$rows = $this->resolveRows($companyId, $items, $quoteMaterials, $direct, $archive);
|
||||
$quotations = $this->activeQuotations($connection, $companyId);
|
||||
[$direct, $archive, $brandSku] = $this->sourceCandidates($items);
|
||||
$rows = $this->resolveRows($companyId, $items, $quotations, $direct, $archive, $brandSku);
|
||||
$stats = $this->stats($rows);
|
||||
|
||||
if (! $dryRun) {
|
||||
@ -112,53 +113,67 @@ class KukaPostingMaterialMapSynchronizer
|
||||
return $items;
|
||||
}
|
||||
|
||||
/** @return array<string,true> */
|
||||
private function activeQuoteMaterials(ConnectionInterface $connection, int $companyId): array
|
||||
/** @return array<string,string> */
|
||||
private function activeQuotations(ConnectionInterface $connection, int $companyId): array
|
||||
{
|
||||
return $connection->table('kuka_posting_quotation_rows')
|
||||
->where('company_id', $companyId)
|
||||
->where('record_status', '生效')
|
||||
->pluck('material_number')
|
||||
->map(static fn (mixed $value): string => trim((string) $value))
|
||||
->filter()
|
||||
->unique()
|
||||
->mapWithKeys(static fn (string $value): array => [$value => true])
|
||||
->get(['material_number', 'material_desc'])
|
||||
->mapWithKeys(static function (object $row): array {
|
||||
$materialNumber = trim((string) $row->material_number);
|
||||
|
||||
return $materialNumber === ''
|
||||
? []
|
||||
: [$materialNumber => trim((string) $row->material_desc)];
|
||||
})
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $items
|
||||
* @return array{0:array<string,array<string,true>>,1:array<string,array<string,true>>}
|
||||
* @return array{
|
||||
* 0:array<string,array<string,true>>,
|
||||
* 1:array<string,array<string,true>>,
|
||||
* 2:array<string,array<string,true>>
|
||||
* }
|
||||
*/
|
||||
private function sourceCandidates(array $items): array
|
||||
{
|
||||
$direct = [];
|
||||
$archive = [];
|
||||
$brandSku = [];
|
||||
$query = $this->queries->forSourceWithTimeout(self::SOURCE_KEY, 15);
|
||||
|
||||
foreach (array_chunk($items, self::SOURCE_ITEM_CHUNK) as $chunk) {
|
||||
$directRows = $query->select($this->directSql(count($chunk)), $chunk);
|
||||
$this->collectCandidates(
|
||||
$direct,
|
||||
$query->select($this->directSql(count($chunk)), $chunk),
|
||||
$directRows,
|
||||
);
|
||||
$this->collectCandidates($brandSku, $directRows, 'brand_sku');
|
||||
$this->collectCandidates(
|
||||
$archive,
|
||||
$query->select($this->archiveSql(count($chunk)), $chunk),
|
||||
);
|
||||
}
|
||||
|
||||
return [$direct, $archive];
|
||||
return [$direct, $archive, $brandSku];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,array<string,true>> $target
|
||||
* @param list<array<string,mixed>> $rows
|
||||
*/
|
||||
private function collectCandidates(array &$target, array $rows): void
|
||||
private function collectCandidates(
|
||||
array &$target,
|
||||
array $rows,
|
||||
string $materialField = 'material_number',
|
||||
): void
|
||||
{
|
||||
foreach ($rows as $row) {
|
||||
$itemNumber = trim((string) ($row['item_number'] ?? ''));
|
||||
$materialNumber = trim((string) ($row['material_number'] ?? ''));
|
||||
$materialNumber = trim((string) ($row[$materialField] ?? ''));
|
||||
if ($itemNumber === '' || $materialNumber === '') {
|
||||
continue;
|
||||
}
|
||||
@ -172,11 +187,13 @@ class KukaPostingMaterialMapSynchronizer
|
||||
$placeholders = implode(', ', array_fill(0, $count, '?'));
|
||||
|
||||
return 'SELECT "normalizedSku" AS item_number, '
|
||||
. 'TRIM(updates->>\'materialNo\') AS material_number '
|
||||
. 'TRIM(updates->>\'materialNo\') AS material_number, '
|
||||
. 'TRIM(updates->>\'brandSkuCode\') AS brand_sku '
|
||||
. 'FROM public."BarcodePrintImportRecord" '
|
||||
. 'WHERE "normalizedSku" IN (' . $placeholders . ') '
|
||||
. 'AND COALESCE(updates->>\'materialNo\', \'\') <> \'\' '
|
||||
. 'GROUP BY "normalizedSku", updates->>\'materialNo\' '
|
||||
. 'AND (COALESCE(updates->>\'materialNo\', \'\') <> \'\' '
|
||||
. 'OR COALESCE(updates->>\'brandSkuCode\', \'\') <> \'\') '
|
||||
. 'GROUP BY "normalizedSku", updates->>\'materialNo\', updates->>\'brandSkuCode\' '
|
||||
. 'LIMIT 5000';
|
||||
}
|
||||
|
||||
@ -197,16 +214,19 @@ class KukaPostingMaterialMapSynchronizer
|
||||
* @param array<string,true> $quoteMaterials
|
||||
* @param array<string,array<string,true>> $direct
|
||||
* @param array<string,array<string,true>> $archive
|
||||
* @param array<string,array<string,true>> $brandSku
|
||||
* @return list<array<string,mixed>>
|
||||
*/
|
||||
private function resolveRows(
|
||||
int $companyId,
|
||||
array $items,
|
||||
array $quoteMaterials,
|
||||
array $quotations,
|
||||
array $direct,
|
||||
array $archive,
|
||||
array $brandSku,
|
||||
): array {
|
||||
$quoteKeys = array_keys($quoteMaterials);
|
||||
$quoteKeys = array_keys($quotations);
|
||||
$brandMaterials = $this->quoteBrandMaterials($quotations);
|
||||
$rows = [];
|
||||
$now = now();
|
||||
|
||||
@ -219,7 +239,18 @@ class KukaPostingMaterialMapSynchronizer
|
||||
array_keys($archive[$itemNumber] ?? []),
|
||||
$quoteKeys,
|
||||
)));
|
||||
$matches = array_values(array_unique(array_merge($directMatches, $archiveMatches)));
|
||||
$brandMatches = [];
|
||||
foreach (array_keys($brandSku[$itemNumber] ?? []) as $brand) {
|
||||
foreach (array_keys($brandMaterials[$brand] ?? []) as $materialNumber) {
|
||||
$brandMatches[] = $materialNumber;
|
||||
}
|
||||
}
|
||||
$brandMatches = array_values(array_unique($brandMatches));
|
||||
$matches = array_values(array_unique(array_merge(
|
||||
$directMatches,
|
||||
$archiveMatches,
|
||||
$brandMatches,
|
||||
)));
|
||||
|
||||
$materialNumber = null;
|
||||
$matchSource = null;
|
||||
@ -229,6 +260,9 @@ class KukaPostingMaterialMapSynchronizer
|
||||
} elseif ($directMatches === [] && count($archiveMatches) === 1) {
|
||||
$materialNumber = $archiveMatches[0];
|
||||
$matchSource = 'archive_barcode';
|
||||
} elseif ($directMatches === [] && $archiveMatches === [] && count($brandMatches) === 1) {
|
||||
$materialNumber = $brandMatches[0];
|
||||
$matchSource = 'brand_sku';
|
||||
}
|
||||
|
||||
$status = match (true) {
|
||||
@ -255,11 +289,29 @@ class KukaPostingMaterialMapSynchronizer
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,string> $quotations
|
||||
* @return array<string,array<string,true>>
|
||||
*/
|
||||
private function quoteBrandMaterials(array $quotations): array
|
||||
{
|
||||
$materials = [];
|
||||
|
||||
foreach ($quotations as $materialNumber => $description) {
|
||||
$brand = trim(explode('~', $description, 2)[0]);
|
||||
if ($brand !== '') {
|
||||
$materials[$brand][$materialNumber] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $materials;
|
||||
}
|
||||
|
||||
/** @param list<array<string,mixed>> $rows */
|
||||
private function stats(array $rows): array
|
||||
{
|
||||
$counts = ['matched' => 0, 'unmatched' => 0, 'ambiguous' => 0];
|
||||
$sources = ['barcode_material_no' => 0, 'archive_barcode' => 0];
|
||||
$sources = ['barcode_material_no' => 0, 'archive_barcode' => 0, 'brand_sku' => 0];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$counts[$row['match_status']]++;
|
||||
@ -275,6 +327,7 @@ class KukaPostingMaterialMapSynchronizer
|
||||
'ambiguous' => $counts['ambiguous'],
|
||||
'direct' => $sources['barcode_material_no'],
|
||||
'archive' => $sources['archive_barcode'],
|
||||
'brand_sku' => $sources['brand_sku'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ class SyncKukaPostingMaterialMap extends Command
|
||||
$this->line(json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
} else {
|
||||
$this->info(sprintf(
|
||||
'物料映射%s完成:货号 %d,唯一匹配 %d,未匹配 %d,冲突 %d;直接物料编号 %d,档案条码 %d。',
|
||||
'物料映射%s完成:货号 %d,唯一匹配 %d,未匹配 %d,冲突 %d;直接物料编号 %d,档案条码 %d,品牌SKU %d。',
|
||||
$result['dry_run'] ? '校验' : '同步',
|
||||
$result['items'],
|
||||
$result['matched'],
|
||||
@ -46,6 +46,7 @@ class SyncKukaPostingMaterialMap extends Command
|
||||
$result['ambiguous'],
|
||||
$result['direct'],
|
||||
$result['archive'],
|
||||
$result['brand_sku'],
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
| 状态 | 说明 |
|
||||
| --- | --- |
|
||||
| 本次接入 | 顾家过账基础数据读取聚水潭“销售主题分析(新版)→ 商品利润 → 明细(订单商品)”10 月导出,仅保留天猫、京东、拼多多和抖音的 12 家 HX 旗舰店,写入 `kuka_posting_base_rows`;导入摘要写入 `kuka_posting_base_imports`。只保存前 40 个聚水潭原始字段,后续成本映射、报价和过账分类不混入基础数据。XLSX 通过 `business-mirror:import-kuka-posting-base` 流式读取,校验 12 家店铺均有数据后,在单一事务内整月替换;文件缺失、字段错误或中断时保留上一版。当前 2026 年 10 月导出为 13,949 行。 |
|
||||
| 本次接入 | `furniture3d_prod` PostgreSQL 只读库用于顾家发货明细的货号映射:以 `public.SupplyChainProductArchive.sku` 对应聚水潭“货号”,候选 `barcode` 再用顾家报价单生效 `MaterialNumber` 做唯一性校验;`public.BarcodePrintImportRecord.updates.materialNo` 提供优先的直接物料编号。只把命中的紧凑结果写入 `kuka_posting_material_map_rows`,不复制整库、不在页面直连上游;未匹配或存在多个报价候选时保留空值,不猜测。每日 05:50 执行 `business-mirror:sync-kuka-posting-material-map`。 |
|
||||
| 本次接入 | `furniture3d_prod` PostgreSQL 只读库用于顾家发货明细的货号映射:优先使用 `public.BarcodePrintImportRecord.updates.materialNo`,其次用 `public.SupplyChainProductArchive.sku` 对应聚水潭“货号”并校验候选 `barcode`,最后按 `updates.brandSkuCode` 对应报价单物料描述前缀回退;命中后必须存在报价单生效 `MaterialNumber`。同一物料编号允许多个货号共用,只要求单个货号内部候选唯一。只把紧凑结果写入 `kuka_posting_material_map_rows`,不复制整库、不在页面直连上游;无命中或仍有多个报价候选时保留空值,不猜测。每日 05:50 执行 `business-mirror:sync-kuka-posting-material-map`。 |
|
||||
| 本次接入 | 钉钉考勤 `attendance/list` 按财务中心在职成员同步到 `ding_attendance_records`,保留打卡记录 ID、用户、工作日期、上下班类型、打卡结果、审批标识、审批实例和打卡时间;每 15 分钟回看 35 天,按 7 天窗口和 50 人上限分页。钉钉排班通过 `getScheduleByRange` 同步到 `ding_attendance_schedule_records`,保留逐日排班 ID、用户、考勤组、班次、是否休息、变更状态和完整源数据;本机脚本为 `scripts/sync-ding-attendance-schedules.py`,导入命令为 `business-mirror:import-ding-attendance-schedules`,默认覆盖最近 95 天,查询不完整时拒绝覆盖旧镜像。日志漏写扣分只统计钉钉排班明确为工作日的日期,并继续排除没有日志但有“请假 / 休息 / 调休”等审批标记的日期;排班或考勤镜像未完成时扣分暂不计算,周五、周末或法定班次调整均以公司真实排班为准。依赖权限 `qyapi_attendance_isv_query_result`、`qyapi_get_attendance_data`。 |
|
||||
| 已完成 | `operations_replica/rpt.Bulk_Price_Limit` 已进入类型化表 `product_price_mirror_rows`,商品价格页面已读取镜像并支持完整分页。 |
|
||||
| 已完成 | `operations_replica/rpt.jst_sku` 已进入 `ops_jst_sku`,普通商品资料页面固定读取 `sku_type = normal` 的共享镜像,并支持稳定分页和业务筛选。 |
|
||||
|
||||
@ -38,6 +38,7 @@ class KukaPostingMaterialMapSynchronizerTest extends TestCase
|
||||
$table->bigIncrements('id');
|
||||
$table->unsignedBigInteger('company_id');
|
||||
$table->string('material_number', 191);
|
||||
$table->string('material_desc', 500)->nullable();
|
||||
$table->string('record_status', 64)->nullable();
|
||||
});
|
||||
$schema->create('kuka_posting_material_map_rows', function (Blueprint $table): void {
|
||||
@ -56,17 +57,20 @@ class KukaPostingMaterialMapSynchronizerTest extends TestCase
|
||||
public function test_only_a_unique_active_quotation_match_is_selected(): void
|
||||
{
|
||||
$connection = DB::connection('business_mirror');
|
||||
foreach (['A', 'B', 'C', 'D', 'E'] as $itemNumber) {
|
||||
foreach (['A', 'B', 'C', 'D', 'E', 'F', 'G'] as $itemNumber) {
|
||||
$connection->table('kuka_posting_base_rows')->insert([
|
||||
'company_id' => 1,
|
||||
'period' => '2026-10',
|
||||
'source_values' => json_encode(['货号' => 'ITEM-'.$itemNumber], JSON_THROW_ON_ERROR),
|
||||
]);
|
||||
}
|
||||
foreach (['Q-A', 'Q-B', 'Q-C1', 'Q-C2', 'Q-E'] as $materialNumber) {
|
||||
foreach (['Q-A', 'Q-B', 'Q-C1', 'Q-C2', 'Q-E', 'Q-G'] as $materialNumber) {
|
||||
$connection->table('kuka_posting_quotation_rows')->insert([
|
||||
'company_id' => 1,
|
||||
'material_number' => $materialNumber,
|
||||
'material_desc' => $materialNumber === 'Q-G'
|
||||
? 'BRAND-G~测试产品'
|
||||
: $materialNumber.'~测试产品',
|
||||
'record_status' => '生效',
|
||||
]);
|
||||
}
|
||||
@ -77,10 +81,12 @@ class KukaPostingMaterialMapSynchronizerTest extends TestCase
|
||||
->andReturnUsing(static function (string $sql): array {
|
||||
if (str_contains($sql, 'BarcodePrintImportRecord')) {
|
||||
return [
|
||||
['item_number' => 'ITEM-A', 'material_number' => 'Q-A'],
|
||||
['item_number' => 'ITEM-B', 'material_number' => 'Q-B'],
|
||||
['item_number' => 'ITEM-C', 'material_number' => 'Q-C-OLD'],
|
||||
['item_number' => 'ITEM-E', 'material_number' => 'Q-E-OLD'],
|
||||
['item_number' => 'ITEM-A', 'material_number' => 'Q-A', 'brand_sku' => ''],
|
||||
['item_number' => 'ITEM-B', 'material_number' => 'Q-B', 'brand_sku' => ''],
|
||||
['item_number' => 'ITEM-C', 'material_number' => 'Q-C-OLD', 'brand_sku' => ''],
|
||||
['item_number' => 'ITEM-E', 'material_number' => 'Q-E-OLD', 'brand_sku' => ''],
|
||||
['item_number' => 'ITEM-F', 'material_number' => 'Q-A', 'brand_sku' => ''],
|
||||
['item_number' => 'ITEM-G', 'material_number' => '', 'brand_sku' => 'BRAND-G'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -103,12 +109,13 @@ class KukaPostingMaterialMapSynchronizerTest extends TestCase
|
||||
|
||||
$this->assertSame([
|
||||
'dry_run' => false,
|
||||
'items' => 5,
|
||||
'matched' => 3,
|
||||
'items' => 7,
|
||||
'matched' => 5,
|
||||
'unmatched' => 1,
|
||||
'ambiguous' => 1,
|
||||
'direct' => 2,
|
||||
'direct' => 3,
|
||||
'archive' => 1,
|
||||
'brand_sku' => 1,
|
||||
], $result);
|
||||
|
||||
$rows = $connection->table('kuka_posting_material_map_rows')
|
||||
@ -119,8 +126,11 @@ class KukaPostingMaterialMapSynchronizerTest extends TestCase
|
||||
$this->assertSame('Q-A', $rows['ITEM-A']->material_number);
|
||||
$this->assertSame('barcode_material_no', $rows['ITEM-A']->match_source);
|
||||
$this->assertSame('Q-B', $rows['ITEM-B']->material_number);
|
||||
$this->assertSame('Q-A', $rows['ITEM-F']->material_number);
|
||||
$this->assertSame('Q-E', $rows['ITEM-E']->material_number);
|
||||
$this->assertSame('archive_barcode', $rows['ITEM-E']->match_source);
|
||||
$this->assertSame('Q-G', $rows['ITEM-G']->material_number);
|
||||
$this->assertSame('brand_sku', $rows['ITEM-G']->match_source);
|
||||
$this->assertSame('ambiguous', $rows['ITEM-C']->match_status);
|
||||
$this->assertNull($rows['ITEM-C']->material_number);
|
||||
$this->assertSame('unmatched', $rows['ITEM-D']->match_status);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user