From 4afcbaacf09a4acc75ea2cd98c9dc35cffc578fc Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Fri, 8 Sep 2023 17:49:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=80=E5=85=B7=E5=A4=84?= =?UTF-8?q?=E6=96=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...oPharmacistCaVerifyDelayDirectConsumer.php | 80 +++++----- app/Services/CaService.php | 148 ++++++------------ app/Services/OrderPrescriptionService.php | 127 ++++++++++----- app/Services/UserDoctorService.php | 2 +- 4 files changed, 171 insertions(+), 186 deletions(-) diff --git a/app/Amqp/Consumer/AutoPharmacistCaVerifyDelayDirectConsumer.php b/app/Amqp/Consumer/AutoPharmacistCaVerifyDelayDirectConsumer.php index f16af85..16628a3 100644 --- a/app/Amqp/Consumer/AutoPharmacistCaVerifyDelayDirectConsumer.php +++ b/app/Amqp/Consumer/AutoPharmacistCaVerifyDelayDirectConsumer.php @@ -134,7 +134,7 @@ class AutoPharmacistCaVerifyDelayDirectConsumer extends ConsumerMessage // 检测执行次数 $res = $this->checkHandleNumber($data['prescription_file_id']); - }catch (\Exception $e){ + }catch (\Throwable $e){ // 检测次数失败 Log::getInstance("queue-AutoPharmacistCaVerify")->info("错误:" . $e->getMessage()); return Result::ACK; @@ -158,14 +158,13 @@ class AutoPharmacistCaVerifyDelayDirectConsumer extends ConsumerMessage Db::commit(); return Result::ACK; - }catch (\Exception $e){ + }catch (\Throwable $e){ Db::rollBack(); Log::getInstance("queue-AutoPharmacistCaVerify")->info("错误:" . $e->getMessage()); return Result::ACK; } } - // 下载医生签章文件 Db::beginTransaction(); try { @@ -199,30 +198,51 @@ class AutoPharmacistCaVerifyDelayDirectConsumer extends ConsumerMessage return Result::REQUEUE; } - Log::getInstance("queue-AutoPharmacistCaVerify")->info("下载医生的签章pdf并上传至oss"); - // 下载医生的签章pdf并上传至oss - $prescription_pdf_oss_path = $this->downCaPdfToOss($order_prescription, $user_doctor['user_id'],2,$order_prescription_file['doctor_ca_file_id']); - if (!$prescription_pdf_oss_path) { + Log::getInstance("queue-AutoPharmacistCaVerify")->info("下载医生的签章pdf并上传至oss"); + $CaService = new CaService($order_prescription,2,$user_doctor['user_id']); + $prescription_pdf_oss_path = $CaService->downCaPdfToOss($order_prescription_file['doctor_ca_file_id']); + if ($prescription_pdf_oss_path == "") { Db::rollBack(); Log::getInstance("queue-AutoPharmacistCaVerify")->error("错误:" . $prescription_pdf_oss_path); return Result::REQUEUE; } - // 药师/医院签章 - Log::getInstance("queue-AutoPharmacistCaVerify")->info("药师/医院签章"); + // 药师签章 + Log::getInstance("queue-AutoPharmacistCaVerify")->info("药师签章"); $OrderPrescriptionService = new OrderPrescriptionService(); - $prescription_open_result = $OrderPrescriptionService->openPrescription($data['order_prescription_id'],$user_pharmacist['user_id']); + $prescription_open_result = $OrderPrescriptionService->openPrescription($data['order_prescription_id'],3,$user_pharmacist['user_id']); if (empty($prescription_open_result['file_id'])){ Db::rollBack(); - Log::getInstance("queue-AutoPharmacistCaVerify")->error("错误:处方开具失败"); + Log::getInstance("queue-AutoPharmacistCaVerify")->error("错误:药师签章失败"); return Result::REQUEUE; } - // 下载医院的签章pdf并上传至oss + // 下载药师签章pdf并上传至oss + Log::getInstance("queue-AutoPharmacistCaVerify")->info("下载药师的签章pdf并上传至oss"); + $CaService = new CaService($order_prescription,3,$user_pharmacist['user_id']); + $prescription_pdf_oss_path = $CaService->downCaPdfToOss($prescription_open_result['file_id']); + if ($prescription_pdf_oss_path == "") { + Db::rollBack(); + Log::getInstance("queue-AutoPharmacistCaVerify")->error("错误:" . $prescription_pdf_oss_path); + return Result::REQUEUE; + } + + // 医院签章 + Log::getInstance("queue-AutoPharmacistCaVerify")->info("医院签章"); + $OrderPrescriptionService = new OrderPrescriptionService(); + $prescription_open_result = $OrderPrescriptionService->openPrescription($data['order_prescription_id'],1); + if (empty($prescription_open_result['file_id'])){ + Db::rollBack(); + Log::getInstance("queue-AutoPharmacistCaVerify")->error("错误:医院签章失败"); + return Result::REQUEUE; + } + + // 下载医院签章pdf并上传至oss Log::getInstance("queue-AutoPharmacistCaVerify")->info("下载医院的签章pdf并上传至oss"); - $prescription_pdf_oss_path = $this->downCaPdfToOss($order_prescription, $user_pharmacist['user_id'],3,$prescription_open_result['file_id']); - if (!$prescription_pdf_oss_path) { + $CaService = new CaService($order_prescription,1); + $prescription_pdf_oss_path = $CaService->downCaPdfToOss($prescription_open_result['file_id']); + if ($prescription_pdf_oss_path == "") { Db::rollBack(); Log::getInstance("queue-AutoPharmacistCaVerify")->error("错误:" . $prescription_pdf_oss_path); return Result::REQUEUE; @@ -244,7 +264,7 @@ class AutoPharmacistCaVerifyDelayDirectConsumer extends ConsumerMessage Db::commit(); Log::getInstance("queue-AutoPharmacistCaVerify")->info("成功"); - } catch (\Exception $e) { + } catch (\Throwable $e) { Db::rollBack(); Log::getInstance("queue-AutoPharmacistCaVerify")->error("异常错误:" . $e->getMessage()); @@ -279,7 +299,7 @@ class AutoPharmacistCaVerifyDelayDirectConsumer extends ConsumerMessage Log::getInstance("queue-AutoPharmacistCaVerify")->error("添加处方过期队列失败!"); return Result::ACK; } - }catch(\Exception $e){ + }catch(\Throwable $e){ Log::getInstance("queue-AutoPharmacistCaVerify")->error("发送消息异常错误:" . $e->getMessage()); return Result::ACK; } @@ -405,34 +425,6 @@ class AutoPharmacistCaVerifyDelayDirectConsumer extends ConsumerMessage return true; } - /** - * 下载签章pdf并上传至oss - * @param array|object $order_prescription - * @param string $user_id 用户id - * @param string|int $user_type 用户类型 1:患者 2:医生 3:药师 - * @param string $file_id - * @return string|bool oss地址|false(存在异常时) - */ - protected function downCaPdfToOss(array|object $order_prescription, string $user_id, string|int $user_type, string $file_id): string|bool - { - try { - $user = array(); - $user['user_id'] = $user_id; - $user['user_type'] = $user_type; - $CaService = new CaService($order_prescription, $user); - - // 下载签章pdf并上传至oss - if ($user_type == 2){ - return $CaService->downCaPdfToOss($file_id,1); - }else{ - return $CaService->downCaPdfToOss($file_id,2); - } - - } catch (\Exception $e) { - return false; - } - } - /** * 修改处方文件表 * @param string $prescription_file_id 主键id diff --git a/app/Services/CaService.php b/app/Services/CaService.php index 6d55e1a..371493d 100644 --- a/app/Services/CaService.php +++ b/app/Services/CaService.php @@ -38,81 +38,77 @@ class CaService extends BaseService // 是否已添加签章配置(第一次需申请) protected string $is_sign_config; - // 用户签名图片地址 + // 签名图片地址 public string $sign_image_path; - // 医院签名图片地址 - protected string $hospital_sign_image_path; - - // 用户唯一标识 - protected string $user_entity_id; - - // 医院唯一标识 - protected string $hospital_entity_id; + // 唯一标识 + protected string $entity_id; // 证书序列号 protected string $cert_serial_number; - // 身份证号 + // 身份证号/信用代码 protected string $card_num; - // 信用代码 - protected string $org_num; - // 处方pdf本地地址 protected string $prescription_pdf_local_path; // 处方pdf oss地址 protected string $prescription_pdf_oss_path; - /** * 初始化类,此处会获取基础数据 * @param array|object $order_prescription 处方表数据 - * @param array|object $user 用户表数据 + * @param string|int $user_id 用户id + * @param int $type 类型 1:医院 2:医生 3:药师 */ - public function __construct(array|object $order_prescription,array|object $user){ + public function __construct(array|object $order_prescription,int $type,string|int $user_id = ""){ // 获取用户、医院签名图片地址、用户标识信息 - $params = array(); - $params['user_id'] = $user['user_id']; - if ($user['user_type'] == 2) { + if ($type == 1){ + // 医院 + $this->sign_image_path = "basic/file/hospital_signature.png"; + $this->entity_id = "5345345461"; + $this->card_num = "91510106MABTJY4K9R"; + }elseif($type == 2){ + // 用户 + $params = array(); + $params['user_id'] = $user_id; $user_doctor_info = UserDoctorInfo::getOne($params); if (empty($user_doctor_info)) { throw new BusinessException("用户数据错误"); } - $user_sign_image_path = $user_doctor_info['sign_image']; + $this->sign_image_path = substr($user_doctor_info['sign_image'], 1, strlen($user_doctor_info['sign_image']) - 1); $app_env = config('app_env','dev'); if ($app_env == 'prod'){ - $this->user_entity_id = $user_doctor_info['user_id']; + $this->entity_id = $user_doctor_info['user_id']; }else{ - $this->user_entity_id = "491925054435950592"; + $this->entity_id = "491925054435950592"; } $this->card_num = $user_doctor_info['card_num']; - } else { + } elseif ($type == 3){ + $params = array(); + $params['user_id'] = $user_id; $user_pharmacist_info = UserPharmacistInfo::getOne($params); if (empty($user_pharmacist_info)) { throw new BusinessException("用户数据错误"); } - $user_sign_image_path = $user_pharmacist_info['sign_image']; - $this->user_entity_id = $user['user_id']; - $this->card_num = $user_pharmacist_info['card_num']; + // 去除用户签名图片第一个/ oss不识别 + $this->sign_image_path = substr($user_pharmacist_info['sign_image'], 1, strlen($user_pharmacist_info['sign_image']) - 1); - $this->hospital_sign_image_path = "basic/file/hospital_signature.png"; - $this->hospital_entity_id = "5345345461"; - $this->org_num = "91510106MABTJY4K9R"; + $this->entity_id = $user_id; + $this->card_num = $user_pharmacist_info['card_num']; + } else{ + throw new BusinessException("用户类型错误"); } - if (empty($user_sign_image_path) || empty($this->user_entity_id)) { + if (empty($this->sign_image_path) || empty($this->entity_id)) { throw new BusinessException("无签名图片/用户唯一标识"); } - // 去除用户签名图片第一个/ oss不识别 - $this->sign_image_path = substr($user_sign_image_path, 1, strlen($user_sign_image_path) - 1); - $order_prescription_id = $order_prescription['order_prescription_id']; // 创建协程客户端 @@ -225,9 +221,8 @@ class CaService extends BaseService /** * 获取云证书签名+验证云证书签名 * @param array|object $order_prescription - * @param int $type 类型 1:用户 2:医院 */ - public function getVerifyCertSign(array|object $order_prescription,int $type) + public function getVerifyCertSign(array|object $order_prescription) { $CaOnline = new CaOnline(); @@ -254,13 +249,7 @@ class CaService extends BaseService $data['product'][] = $product; } - if ($type == 1){ - // 用户 - $cert_sign_result = $CaOnline->getCertSign($this->user_entity_id, $this->user_entity_id, $data); - }else{ - // 医院 - $cert_sign_result = $CaOnline->getCertSign($this->hospital_entity_id, $this->hospital_entity_id, $data); - } + $cert_sign_result = $CaOnline->getCertSign($this->entity_id, $this->entity_id, $data); // 验证云证书签名 验证无需处理,只要不返回错误即可 $CaOnline->verifyPkcs7($cert_sign_result['signP7'], $data); @@ -411,38 +400,23 @@ class CaService extends BaseService /** * 下载Oss中处方pdf - * 存在:当次发版内医生开具后,药师再去开具 - * 不存在:医生开具后,进行发版过,此时需重新下载 * @return void */ public function downOssPdfToLocal(): void { - $res = file_exists($this->prescription_pdf_local_path); - if (!$res){ - // 去除第一个/ oss不识别 -// $prescription_pdf_path = substr($doctor_pdf_oss_path, 1, strlen($doctor_pdf_oss_path) - 1); - - $oss = new Oss(); - $oss->getObjectToLocal($this->prescription_pdf_oss_path, $this->prescription_pdf_local_path); - } + $oss = new Oss(); + $oss->getObjectToLocal($this->prescription_pdf_oss_path, $this->prescription_pdf_local_path); } /** * 下载CA中pdf至本地文件 * @param string $file_id - * @param int $type 类型 1:用户 2:医院 * @return void */ - public function downCaPdfToLocal(string $file_id,int $type): void + public function downCaPdfToLocal(string $file_id): void { $CaOnline = new CaOnline(); - if ($type == 1){ - // 用户 - $prescription_pdf_result = $CaOnline->getSignedFile($this->user_entity_id, $file_id); - }else{ - // 医院 - $prescription_pdf_result = $CaOnline->getSignedFile($this->hospital_entity_id, $file_id); - } + $prescription_pdf_result = $CaOnline->getSignedFile($this->entity_id, $file_id); $file = fopen($this->prescription_pdf_local_path, "w"); fwrite($file, $prescription_pdf_result); @@ -452,20 +426,13 @@ class CaService extends BaseService /** * 下载CA中的pdf并上传至oss * @param string $file_id - * @param int $type 类型 1:用户 2:医院 * @return string oss地址 */ - public function downCaPdfToOss(string $file_id,int $type): string + public function downCaPdfToOss(string $file_id): string { $CaOnline = new CaOnline(); - if ($type == 1){ - // 用户 - $prescription_pdf_result = $CaOnline->getSignedFile($this->user_entity_id, $file_id); - }else{ - // 医院 - $prescription_pdf_result = $CaOnline->getSignedFile($this->hospital_entity_id, $file_id); - } + $prescription_pdf_result = $CaOnline->getSignedFile($this->entity_id, $file_id); // 上传oss $oss = new Oss(); @@ -479,27 +446,15 @@ class CaService extends BaseService */ public function addSignPdf(string $type): string { - // 下载签名图片 + $oss = new Oss(); + if ($type == 1){ - $local_path = "./extend/Ca/hospital_signature.png"; - $res = file_exists($local_path); - if ($res){ - // 读取本地文件 - $sign_image = fopen($local_path,'r'); - } + $style = "image/resize,w_300,h_300"; + }else{ + $style = "image/resize,m_lfit,w_100,h_350"; } - if (!isset($sign_image)){ - $oss = new Oss(); - - if ($type == 1){ - $style = "image/resize,w_300,h_300"; - $sign_image = $oss->getCusTomObjectToRAM($this->hospital_sign_image_path, $style); - }else{ - $style = "image/resize,m_lfit,w_100,h_350"; - $sign_image = $oss->getCusTomObjectToRAM($this->sign_image_path, $style); - } - } + $sign_image = $oss->getCusTomObjectToRAM($this->sign_image_path, $style); $sign_image = base64_encode($sign_image); if (!$sign_image) { @@ -512,24 +467,18 @@ class CaService extends BaseService $lly = "210"; // 左边底部Y坐标 控制上下(越小越下) $urx = "520"; // 右边上部x坐标 $ury = "360"; // 右边上部y坐标 - - $entity_id = $this->hospital_entity_id; } elseif ($type == 2){ // 医生端 $llx = "120"; // 左边底部X坐标 $lly = "190"; // 左边底部Y坐标 $urx = "190"; // 右边上部x坐标 $ury = "140"; // 右边上部y坐标 - - $entity_id = $this->user_entity_id; }else{ // 药师端 $llx = "350"; // 左边底部X坐标 $lly = "190"; // 左边底部Y坐标 $urx = "440"; // 右边上部x坐标 $ury = "140"; // 右边上部y坐标 - - $entity_id = $this->user_entity_id; } $sign_param = [ @@ -559,11 +508,7 @@ class CaService extends BaseService $data['sign_param'] = json_encode($sign_param); $data['seal_img'] = $sign_image; - if ($type == 1){ - $CaOnline->addUserSignConfig($entity_id,$this->org_num,$data); - }else{ - $CaOnline->addUserSignConfig($entity_id,$this->card_num,$data); - } + $CaOnline->addUserSignConfig($this->entity_id,$this->card_num,$data); $params = array(); $params['cert_id'] = $user_ca_cert['cert_id']; @@ -580,17 +525,16 @@ class CaService extends BaseService throw new BusinessException("处方pdf打开失败"); } + // 处方pdf进行签章 $data = array(); $data['sign_param'] = json_encode($sign_param); $data['pdf_file'] = $pdf_file; - $sign_pdf_result = $CaOnline->addSignPdf($entity_id, $data); + $sign_pdf_result = $CaOnline->addSignPdf($this->entity_id, $data); if (empty($sign_pdf_result[0]['fileId'])) { throw new BusinessException("处方签章失败"); } return $sign_pdf_result[0]['fileId']; } - - } \ No newline at end of file diff --git a/app/Services/OrderPrescriptionService.php b/app/Services/OrderPrescriptionService.php index aae18bc..6d1d23d 100644 --- a/app/Services/OrderPrescriptionService.php +++ b/app/Services/OrderPrescriptionService.php @@ -132,21 +132,90 @@ class OrderPrescriptionService extends BaseService * @param string $user_id 用户id * @return array */ - public function openPrescription(string $order_prescription_id, string $user_id): array +// public function openPrescription1(string $order_prescription_id, string $user_id): array +// { +// try { +// // 获取用户数据 +// $params = array(); +// $params['user_id'] = $user_id; +// $user = User::getOne($params); +// if (empty($user)) { +// throw new BusinessException("用户数据错误"); +// } +// +// if ($user['user_type'] != 2 && $user['user_type'] != 3) { +// throw new BusinessException("用户类型错误"); +// } +// +// // 获取处方数据 +// $params = array(); +// $params['order_prescription_id'] = $order_prescription_id; +// $order_prescription = OrderPrescription::getOne($params); +// if (empty($order_prescription)) { +// throw new BusinessException("处方数据错误"); +// } +// +// if (empty($order_prescription['doctor_created_time'])) { +// throw new BusinessException("医生开方日期错误"); +// } +// +// $CaService = new CaService($order_prescription,$user); +// +// // 获取云证书签名+验证云证书签名 +// $CaService->getVerifyCertSign($order_prescription,1); +// +// // 医生 +// if ($user['user_type'] == 2) { +// // 生成处方图片+处方图片生成pdf +// $prescription_img_oss_path = $CaService->createPrescriptionImgPdf($order_prescription); +// } +// +// // 药师-医院签章 +// if ($user['user_type'] == 3) { +// // 获取医院云证书签名+验证云证书签名 +// $CaService->getVerifyCertSign($order_prescription,2); +// +// // 下载医生开具的处方pdf至本地 +// $CaService->downOssPdfToLocal(); +// } +// +// // 进行处方pdf签章 +// $file_id = $CaService->addSignPdf($user['user_type']); +// +// // 药师-医院签章 +// if ($user['user_type'] == 3) { +// // 药师端时,需要进行系统签章 +// // 把药师签章的pdf存储至本地文件 +// // 下载药师签章pdf图片 +// dump($file_id); +// $CaService->downCaPdfToLocal($file_id,1); +// +// // 进行处方pdf签章 +// $file_id = $CaService->addSignPdf($user['user_type']); +// } +// +// $result = array(); +// $result['prescription_img_oss_path'] = $prescription_img_oss_path ?? ""; +// $result['file_id'] = $file_id; +// return $result; +// +// } catch (\Throwable $e) { +// throw new BusinessException($e->getMessage()); +// } +// } + + /** + * 开具处方 + * 医生-正常开具 + * 药师-先开具药师处方,再开具医院签章 + * @param string $order_prescription_id 处方id + * @param string $user_id 用户id + * @param int $type 类型 1:医院 2:医生 3:药师 + * @return array + */ + public function openPrescription(string $order_prescription_id,int $type,string $user_id = ""): array { try { - // 获取用户数据 - $params = array(); - $params['user_id'] = $user_id; - $user = User::getOne($params); - if (empty($user)) { - throw new BusinessException("用户数据错误"); - } - - if ($user['user_type'] != 2 && $user['user_type'] != 3) { - throw new BusinessException("用户类型错误"); - } - // 获取处方数据 $params = array(); $params['order_prescription_id'] = $order_prescription_id; @@ -159,40 +228,20 @@ class OrderPrescriptionService extends BaseService throw new BusinessException("医生开方日期错误"); } - $CaService = new CaService($order_prescription,$user); + $CaService = new CaService($order_prescription,$type,$user_id); // 获取云证书签名+验证云证书签名 - $CaService->getVerifyCertSign($order_prescription,1); - - // 医生 - if ($user['user_type'] == 2) { + $CaService->getVerifyCertSign($order_prescription); + if ($type == 2) { // 生成处方图片+处方图片生成pdf $prescription_img_oss_path = $CaService->createPrescriptionImgPdf($order_prescription); - } - - // 药师-医院签章 - if ($user['user_type'] == 3) { - // 获取医院云证书签名+验证云证书签名 - $CaService->getVerifyCertSign($order_prescription,2); - - // 下载医生开具的处方pdf至本地,文件存在时不进行下载 + }else{ + // 下载已经开具的处方pdf至本地 $CaService->downOssPdfToLocal(); } // 进行处方pdf签章 - $file_id = $CaService->addSignPdf($user['user_type']); - - // 药师-医院签章 - if ($user['user_type'] == 3) { - // 药师端时,需要进行系统签章 - // 把药师签章的pdf存储至本地文件 - // 下载药师签章pdf图片 - $CaService->downCaPdfToLocal($file_id,1); - - // 进行处方pdf签章 - $file_id = $CaService->addSignPdf($user['user_type']); - } - + $file_id = $CaService->addSignPdf($type); $result = array(); $result['prescription_img_oss_path'] = $prescription_img_oss_path ?? ""; $result['file_id'] = $file_id; diff --git a/app/Services/UserDoctorService.php b/app/Services/UserDoctorService.php index fecc36f..b7778f1 100644 --- a/app/Services/UserDoctorService.php +++ b/app/Services/UserDoctorService.php @@ -1471,7 +1471,7 @@ class UserDoctorService extends BaseService // 开具处方 $OrderPrescriptionService = new OrderPrescriptionService(); - $prescription_open_result = $OrderPrescriptionService->openPrescription($order_prescription->order_prescription_id,$user_info['user_id']); + $prescription_open_result = $OrderPrescriptionService->openPrescription($order_prescription->order_prescription_id,2,$user_info['user_id']); if (empty($prescription_open_result['prescription_img_oss_path']) || empty($prescription_open_result['file_id'])){ Db::rollBack(); return fail(HttpEnumCode::SERVER_ERROR, "处方开具失败");