增加了手机操作端
This commit is contained in:
31
server-api/app/queue/redis/MaterialBatchPackageConsumer.php
Normal file
31
server-api/app/queue/redis/MaterialBatchPackageConsumer.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace app\queue\redis;
|
||||
|
||||
use app\support\MaterialBatchPackageService;
|
||||
use support\Log;
|
||||
use Webman\RedisQueue\Consumer;
|
||||
|
||||
class MaterialBatchPackageConsumer implements Consumer
|
||||
{
|
||||
public string $queue = MaterialBatchPackageService::QUEUE_NAME;
|
||||
public string $connection = 'default';
|
||||
|
||||
public function consume($data): void
|
||||
{
|
||||
$batchId = (int)($data['batch_id'] ?? 0);
|
||||
if ($batchId <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
(new MaterialBatchPackageService())->generateForBatchId($batchId);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('material batch package generation failed', [
|
||||
'batch_id' => $batchId,
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
54
server-api/app/queue/redis/MaterialTagQrCodeConsumer.php
Normal file
54
server-api/app/queue/redis/MaterialTagQrCodeConsumer.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace app\queue\redis;
|
||||
|
||||
use app\support\MaterialTagQrCodeService;
|
||||
use app\support\MaterialBatchPackageService;
|
||||
use support\Log;
|
||||
use Webman\RedisQueue\Consumer;
|
||||
|
||||
class MaterialTagQrCodeConsumer implements Consumer
|
||||
{
|
||||
public string $queue = MaterialTagQrCodeService::QUEUE_NAME;
|
||||
public string $connection = 'default';
|
||||
|
||||
public function consume($data): void
|
||||
{
|
||||
$tagIds = array_values(array_filter(array_map('intval', (array)($data['tag_ids'] ?? []))));
|
||||
if (!$tagIds) {
|
||||
return;
|
||||
}
|
||||
|
||||
$service = new MaterialTagQrCodeService();
|
||||
$errors = [];
|
||||
foreach ($tagIds as $tagId) {
|
||||
try {
|
||||
$service->generateForTagId($tagId);
|
||||
} catch (\Throwable $e) {
|
||||
$errors[] = sprintf('#%d %s', $tagId, $e->getMessage());
|
||||
Log::error('material tag QR image generation failed', [
|
||||
'tag_id' => $tagId,
|
||||
'batch_id' => (int)($data['batch_id'] ?? 0),
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($errors) {
|
||||
throw new \RuntimeException('物料二维码图片生成失败:' . implode('; ', array_slice($errors, 0, 3)));
|
||||
}
|
||||
|
||||
$batchId = (int)($data['batch_id'] ?? 0);
|
||||
if ($batchId > 0) {
|
||||
try {
|
||||
(new MaterialBatchPackageService())->enqueueIfReady($batchId);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('material batch package job enqueue failed after QR generation', [
|
||||
'batch_id' => $batchId,
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user