fix(快递机器人): 按指定群关系绑定并区分常州德邦逆向
This commit is contained in:
parent
d3d26284cb
commit
b85c82b830
@ -7,6 +7,23 @@ use RuntimeException;
|
||||
/** 按财务分组名称匹配工作平台的快递名称或群名;组合分组任一名称命中即可。 */
|
||||
final class WorkPlatformCourierRobots
|
||||
{
|
||||
/** 负责人明确指定的对应关系,目标必须命中工作平台完整业务名称。 */
|
||||
private const DESIGNATED_NAMES = [
|
||||
'北京韵达-乐鑫达' => '北京大件韵达',
|
||||
'樵舍中通' => '樵舍中通',
|
||||
'樵舍中通-上楼' => '樵舍中通',
|
||||
'樵舍中通上楼' => '樵舍中通',
|
||||
'江西中通快运' => '樵舍中通',
|
||||
'江西新建中通' => '樵舍中通',
|
||||
'山东中通快运' => '樵舍中通',
|
||||
'南昌樵舍仓仓储费' => '樵舍中通',
|
||||
'中通快运专线' => '常州中通快运',
|
||||
'宿迁中通快运' => '沭阳中通快运',
|
||||
'山东顺丰干配' => '顺德德邦',
|
||||
'河北中通-江三' => '顺德德邦',
|
||||
'苏北顺丰干配大件' => '顺德德邦',
|
||||
];
|
||||
|
||||
public function match(array $groups, array $rows): array
|
||||
{
|
||||
$platformRows = [];
|
||||
@ -20,13 +37,16 @@ final class WorkPlatformCourierRobots
|
||||
$robots = $unmatched = $ambiguous = [];
|
||||
foreach ($groups as $group) {
|
||||
$name = (string) $group->name;
|
||||
// 负责人指定北京乐鑫达使用北京大件韵达的现有群机器人。
|
||||
$matchName = $name === '北京韵达-乐鑫达' ? '北京大件韵达' : $name;
|
||||
$designatedName = self::DESIGNATED_NAMES[$name] ?? null;
|
||||
$candidates = [];
|
||||
$bestScore = 0;
|
||||
$names = preg_split('/[|++、,,;;]+/u', $matchName, -1, PREG_SPLIT_NO_EMPTY) ?: [];
|
||||
$names = preg_split('/[|++、,,;;]+/u', $name, -1, PREG_SPLIT_NO_EMPTY) ?: [];
|
||||
foreach ($platformRows as $row) {
|
||||
$keys = array_filter(array_map('trim', explode('|', (string) ($row['businessKey'] ?? ''))));
|
||||
if ($designatedName !== null) {
|
||||
if (in_array($designatedName, $keys, true)) $candidates[(string) $row['Id']] = $row;
|
||||
continue;
|
||||
}
|
||||
$platformGroup = (string) ($row['groupname'] ?? '');
|
||||
$score = 0;
|
||||
foreach ($names as $part) {
|
||||
|
||||
@ -12,6 +12,10 @@
|
||||
|
||||
北京韵达-乐鑫达按负责人指定使用“北京大件韵达+北京大件韵达临时”的机器人,匹配业务名称“北京大件韵达”。
|
||||
|
||||
樵舍中通、樵舍中通-上楼(也兼容樵舍中通上楼)、江西中通快运、江西新建中通、山东中通快运、南昌樵舍仓仓储费,统一使用包含完整业务名称“樵舍中通”的南昌对接群配置。中通快运专线使用“常州中通快运+武进韵达快运”的机器人;宿迁中通快运使用“沭阳中通快运”的机器人。指定目标不存在或存在多条时保持未匹配/有歧义,不回退到其他同名群。
|
||||
|
||||
山东顺丰干配、河北中通-江三、苏北顺丰干配大件按负责人指定使用“顺德德邦+廊坊德邦+廊坊德邦其他”的机器人,匹配业务名称“顺德德邦”。
|
||||
|
||||
```sh
|
||||
php artisan courier-bills:import-platform-robots /private/path/robots.json --company=1
|
||||
php artisan courier-bills:import-platform-robots /private/path/robots.json --company=1 --apply
|
||||
|
||||
@ -60,6 +60,28 @@ final class WorkPlatformCourierRobotsTest extends FeatureTestCase
|
||||
$this->assertSame('北京大件韵达+北京大件韵达临时', $result['robots']['北京韵达-乐鑫达']['group_name']);
|
||||
}
|
||||
|
||||
public function test_designated_nanchang_changzhou_and_shuyang_groups_use_the_requested_robot(): void
|
||||
{
|
||||
$rows = [$this->robot(588, '樵舍中通|江西中通快运', '南昌对接群'),
|
||||
$this->robot(601, '常州中通快运|武进韵达快运', '常州中通快运+武进韵达快运'),
|
||||
$this->robot(624, '沭阳中通快运', '沭阳中通快运群'),
|
||||
$this->robot(603, '顺德德邦|廊坊德邦|廊坊德邦其他', '顺德德邦+廊坊德邦+廊坊德邦其他'),
|
||||
$this->robot(999, '山东中通快运|宿迁中通快运|中通快运专线', '同名但未指定的群')];
|
||||
$names = ['樵舍中通', '樵舍中通-上楼', '樵舍中通上楼', '江西中通快运', '江西新建中通',
|
||||
'山东中通快运', '南昌樵舍仓仓储费', '中通快运专线', '宿迁中通快运',
|
||||
'山东顺丰干配', '河北中通-江三', '苏北顺丰干配大件'];
|
||||
$groups = array_map(fn ($name) => (object) ['name' => $name], $names);
|
||||
$result = (new WorkPlatformCourierRobots())->match($groups, $rows);
|
||||
foreach (array_slice($names, 0, 7) as $name) $this->assertSame('588', $result['robots'][$name]['source_id']);
|
||||
$this->assertSame('601', $result['robots']['中通快运专线']['source_id']);
|
||||
$this->assertSame('624', $result['robots']['宿迁中通快运']['source_id']);
|
||||
foreach (array_slice($names, 9) as $name) $this->assertSame('603', $result['robots'][$name]['source_id']);
|
||||
$this->assertSame([], $result['unmatched']);
|
||||
$this->assertSame([], $result['ambiguous']);
|
||||
$missing = (new WorkPlatformCourierRobots())->match($groups, [end($rows)]);
|
||||
$this->assertSame([], $missing['robots']);
|
||||
}
|
||||
|
||||
public function test_import_is_previewed_backed_up_encrypted_and_used_for_upload_notifications(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user