hospital-applets-api/app/Amqp/Consumer/AutoPharmacistCaVerifyConsumer.php

59 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
namespace App\Amqp\Consumer;
use App\Utils\Log;
use Hyperf\Amqp\Result;
use Hyperf\Amqp\Annotation\Consumer;
use Hyperf\Amqp\Message\ConsumerMessage;
use Hyperf\DbConnection\Db;
use PhpAmqpLib\Message\AMQPMessage;
/**
* 药师自动签章审核
* 医生签章后加入此队列下载医生签章pdf并进行药师/医院签章审核
*/
#[Consumer(exchange: 'amqp.direct', routingKey: 'AutoPharmacistCaVerify', queue: 'auto.pharmacist.ca.verify.queue', nums: 1)]
class AutoPharmacistCaVerifyConsumer extends ConsumerMessage
{
public function consumeMessage($data, AMQPMessage $message): string
{
Log::getInstance()->error("开始执行 药师自动签章审核 队列:" . json_encode($data, JSON_UNESCAPED_UNICODE));
Db::beginTransaction();
try {
// 检测入参参数
$res = $this->checkParams($data);
Db::commit();
Log::getInstance()->error("药师自动签章审核 队列执行成功");
} catch (\Exception $e) {
Db::rollBack();
Log::getInstance()->error("药师自动签章审核 队列执行失败原因:" . $e->getMessage());
return Result::REQUEUE; // 重回队列
}
return Result::ACK;
}
/**
* 检测执行参数
* @param array $data
* @return bool
*/
protected function checkParams(array $data): bool
{
if (!isset($data['prescription_file_id'])){
return false;
}
if (!isset($data['order_prescription_id'])){
return false;
}
return true;
}
}