From 989c4d1eabca707583ff80b2a0f9dd92b2e89f0d Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Fri, 21 Apr 2023 14:41:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=87=AA=E5=8A=A8=E5=AE=A1?= =?UTF-8?q?=E6=A0=B8=E5=A4=84=E6=96=B9=E4=B8=BA=E5=BB=B6=E8=BF=9F=E9=98=9F?= =?UTF-8?q?=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...PharmacistCaVerifyDelayDirectConsumer.php} | 28 +++++++++++++------ ...PharmacistCaVerifyDelayDirectProducer.php} | 18 ++++++++---- app/Services/UserDoctorService.php | 25 +++++++++-------- 3 files changed, 44 insertions(+), 27 deletions(-) rename app/Amqp/Consumer/{AutoPharmacistCaVerifyConsumer.php => AutoPharmacistCaVerifyDelayDirectConsumer.php} (96%) rename app/Amqp/Producer/{AutoPharmacistCaVerifyProducer.php => AutoPharmacistCaVerifyDelayDirectProducer.php} (52%) diff --git a/app/Amqp/Consumer/AutoPharmacistCaVerifyConsumer.php b/app/Amqp/Consumer/AutoPharmacistCaVerifyDelayDirectConsumer.php similarity index 96% rename from app/Amqp/Consumer/AutoPharmacistCaVerifyConsumer.php rename to app/Amqp/Consumer/AutoPharmacistCaVerifyDelayDirectConsumer.php index 750b73e..506b712 100644 --- a/app/Amqp/Consumer/AutoPharmacistCaVerifyConsumer.php +++ b/app/Amqp/Consumer/AutoPharmacistCaVerifyDelayDirectConsumer.php @@ -5,8 +5,6 @@ declare(strict_types=1); namespace App\Amqp\Consumer; use App\Amqp\Producer\PrescriptionExpiredDelayDirectProducer; -use App\Constants\HttpEnumCode; -use App\Exception\BusinessException; use App\Model\OrderInquiry; use App\Model\OrderPrescription; use App\Model\OrderPrescriptionFile; @@ -19,6 +17,9 @@ use App\Services\ImService; use App\Services\MessagePush; use App\Services\OrderPrescriptionService; use App\Utils\Log; +use Hyperf\Amqp\Message\ConsumerDelayedMessageTrait; +use Hyperf\Amqp\Message\ProducerDelayedMessageTrait; +use Hyperf\Amqp\Message\Type; use Hyperf\Amqp\Producer; use Hyperf\Amqp\Result; use Hyperf\Amqp\Annotation\Consumer; @@ -29,13 +30,20 @@ use PhpAmqpLib\Message\AMQPMessage; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; -/** - * 药师自动签章审核 - * 医生签章后,加入此队列,下载医生签章pdf,并进行药师/医院签章审核 - */ -#[Consumer(exchange: 'amqp.direct', routingKey: 'AutoPharmacistCaVerify', queue: 'auto.pharmacist.ca.verify.queue', nums: 1)] -class AutoPharmacistCaVerifyConsumer extends ConsumerMessage +#[Consumer(nums: 1)] +class AutoPharmacistCaVerifyDelayDirectConsumer extends ConsumerMessage { + use ProducerDelayedMessageTrait; + use ConsumerDelayedMessageTrait; + + protected string $exchange = 'amqp.delay.direct'; + + protected ?string $queue = 'auto.pharmacist.ca.verify.delay.queue'; + + protected string $type = Type::DIRECT; //Type::FANOUT; + + protected string|array $routingKey = 'AutoPharmacistCaVerify'; + public function consumeMessage($data, AMQPMessage $message): string { Log::getInstance("queue-AutoPharmacistCaVerify")->error("开始:" . json_encode($data, JSON_UNESCAPED_UNICODE)); @@ -234,6 +242,7 @@ class AutoPharmacistCaVerifyConsumer extends ConsumerMessage return Result::ACK; } + /** * 检测执行参数 * @param array $data @@ -399,8 +408,9 @@ class AutoPharmacistCaVerifyConsumer extends ConsumerMessage OrderPrescriptionFile::edit($params,$data); }catch(\Exception $e){ - // 失败不做处理 + // 失败不做处理 Log::getInstance("queue-AutoPharmacistCaVerify")->error("错误:修改处方文件表失败" . $e->getMessage()); } } + } diff --git a/app/Amqp/Producer/AutoPharmacistCaVerifyProducer.php b/app/Amqp/Producer/AutoPharmacistCaVerifyDelayDirectProducer.php similarity index 52% rename from app/Amqp/Producer/AutoPharmacistCaVerifyProducer.php rename to app/Amqp/Producer/AutoPharmacistCaVerifyDelayDirectProducer.php index 029d07c..0d2c35d 100644 --- a/app/Amqp/Producer/AutoPharmacistCaVerifyProducer.php +++ b/app/Amqp/Producer/AutoPharmacistCaVerifyDelayDirectProducer.php @@ -5,15 +5,21 @@ declare(strict_types=1); namespace App\Amqp\Producer; use Hyperf\Amqp\Annotation\Producer; +use Hyperf\Amqp\Message\ProducerDelayedMessageTrait; use Hyperf\Amqp\Message\ProducerMessage; +use Hyperf\Amqp\Message\Type; -/** - * 药师自动签章审核 - * 医生签章后,加入此队列,下载医生签章pdf,并进行药师/医院签章审核 - */ -#[Producer(exchange: 'amqp.direct', routingKey: 'AutoPharmacistCaVerify')] -class AutoPharmacistCaVerifyProducer extends ProducerMessage +#[Producer] +class AutoPharmacistCaVerifyDelayDirectProducer extends ProducerMessage { + use ProducerDelayedMessageTrait; + + protected string $exchange = 'amqp.delay.direct'; + + protected string $type = Type::DIRECT; + + protected string|array $routingKey = 'AutoPharmacistCaVerify'; + /** * @param $data * [ diff --git a/app/Services/UserDoctorService.php b/app/Services/UserDoctorService.php index 6061eae..8f3a540 100644 --- a/app/Services/UserDoctorService.php +++ b/app/Services/UserDoctorService.php @@ -5,6 +5,7 @@ namespace App\Services; use App\Amqp\Producer\AssignPharmacistProducer; use App\Amqp\Producer\AutoCompleteInquiryDelayDirectProducer; use App\Amqp\Producer\AutoFinishInquiryDelayDirectProducer; +use App\Amqp\Producer\AutoPharmacistCaVerifyDelayDirectProducer; use App\Amqp\Producer\AutoPharmacistCaVerifyProducer; use App\Constants\DoctorTitleCode; use App\Constants\HttpEnumCode; @@ -1413,14 +1414,6 @@ class UserDoctorService extends BaseService return fail(HttpEnumCode::SERVER_ERROR, "处方开具失败"); } - - Db::commit(); - } catch (\Exception $e) { - Db::rollBack(); - return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage()); - } - - try { // 检测药师自动审核配置开启状态 if ($system_config['is_auto_phar_verify_prescription'] == 1){ // 添加药师自动签章审核队列 @@ -1428,8 +1421,10 @@ class UserDoctorService extends BaseService $data['prescription_file_id'] = $prescription_open_result['file_id']; $data['order_prescription_id'] = $order_prescription->order_prescription_id; - $message = new AutoPharmacistCaVerifyProducer($data); - $producer = ApplicationContext::getContainer()->get(Producer::class); + $message = new AutoPharmacistCaVerifyDelayDirectProducer($data); + + $message->setDelayMs(1000 * 60 * 1); + $producer = $this->container->get(Producer::class); $result = $producer->produce($message); if (!$result) { // 处方开具成功,添加自动签章审核队列失败 @@ -1438,12 +1433,18 @@ class UserDoctorService extends BaseService } } + Db::commit(); + } catch (\Exception $e) { + Db::rollBack(); + return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage()); + } + + try { // 发送消息-药师审核中 $ImService = new ImService(); $ImService->pharmacistVerify($order_inquiry,(string)$order_prescription->order_prescription_id,$product_name,$user_doctor['user_id'],$order_inquiry['user_id']); - }catch (\Exception $e){ - + return success([],HttpEnumCode::HTTP_SUCCESS,"消息发送失败"); } return success();