TestService.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. namespace app\api\servies\test;
  3. use app\api\dao\report\ReportDao;
  4. use app\api\servies\ZskkDefaultService;
  5. use app\api\validate\test\TestValidate;
  6. use app\api\dao\test\TestDao;
  7. use app\api\servies\common\CommonService;
  8. use app\common\library\uploadToCloud;
  9. use PHPMailer\PHPMailer\PHPMailer;
  10. use think\facade\Log;
  11. /**
  12. * 后台控制器基类
  13. * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
  14. */
  15. class TestService extends ZskkDefaultService {
  16. protected $logName = "TestService";
  17. private $testDao = null;
  18. private $reportDao = null;
  19. private $commonService = null;
  20. // protected function zskkInit(TestDao $testDao) {
  21. // $this->testDao;
  22. // }
  23. public function __construct(TestDao $testDao, CommonService $commonService,ReportDao $reportDao) {
  24. parent::__construct();
  25. $this->testDao = $testDao;
  26. $this->reportDao = $reportDao;
  27. $this->commonService = $commonService;
  28. }
  29. private function injectDao($testDao, $commonService) {
  30. }
  31. // public function test($study,$email) {
  32. // set_time_limit(0);
  33. // ini_set('memory_limit','1280M');
  34. // $study = str_replace('&node_type=1','',$study);
  35. // $this->reportDao->insertDcmCompress(['status'=>1,'study_id'=>$study]);
  36. // $path = $this->runRack($study,1);
  37. // $type = 1;
  38. // if(strrpos($path,'zip') !== false && file_exists($path))
  39. // {
  40. // $type = $this->uploadZip($path,$study);
  41. // }
  42. // if(!empty($email))
  43. // {
  44. // $this->reportDao->insertDcmCompress(['status'=>9,'study_id'=>$study,'msg'=>$path]);
  45. // if(strrpos($path,'zip') !== false)
  46. // {
  47. // $name = $this->reportDao->getPatientName($study);
  48. // $this->reportDao->insertDcmCompress(['status'=>10,'study_id'=>$study]);
  49. // // 存在zip压缩文件
  50. // $this->sendEmail($email,$path,$name,$type);
  51. // $this->reportDao->insertDcmCompress(['status'=>11,'study_id'=>$study]);
  52. // Log::record('邮件发送完毕');
  53. // $this->reportDao->updateEmailStatus($email,$study);
  54. // }
  55. // }
  56. // }
  57. //
  58. // public function runRack($study,$come='')
  59. // {
  60. // ini_set('max_execution_time', 6000);
  61. // $time = date('Y-m-d H:i:s',time());
  62. // //过期时间 大于当前 则 还没过期
  63. // $where = "effective_date > '$time'";
  64. // $dcm = $this->reportDao->getDcmPath($where,$study);
  65. // if(!empty($dcm))
  66. // {
  67. // log::record('存在历史dcm地址'.$dcm);
  68. // return $dcm;
  69. // }
  70. // $this->setCache($study.'_zip',$study,600);
  71. // log::record('不存在历史地址则继续'.$study);
  72. // //外网地址 需要network 走带宽
  73. //// $url = "https://query.pacsonline.cn/query/url?network=1&study_id=$study&version=V1.2.0.0";
  74. // //内网地址
  75. // $url = 'https://query.pacsonline.cn/query/url?&study_id='.$study.'&version=V1.2.0.0';
  76. // $data = $this->curl_get($url);
  77. // $data = json_decode($data);
  78. // if(empty($data))
  79. // {
  80. // log::record('没有找到dcm信息');
  81. // return '';
  82. // }
  83. // $this->reportDao->insertDcmCompress(['status'=>2,'study_id'=>$study]);
  84. // $date = time();
  85. // $create = ROOT_PATH . 'public' . DS . 'download'.DS.$date;
  86. // log::record('压缩中');
  87. // $path = $this->zip($data,$create,$date,$study);
  88. // log::record('压缩成功');
  89. // return $path;
  90. // }
  91. //
  92. // public function uploadZip($path_url,$study)
  93. // {
  94. // $this->reportDao->insertDcmCompress(['status'=>7,'study_id'=>$study]);
  95. // $upload = new uploadToCloud();
  96. // $s = $upload->upload($path_url,$path_url, 'zskktemp');
  97. // var_dump($s);
  98. // if(($s['@metadata']['statusCode'] ?? '') == '200')
  99. // {
  100. // $this->reportDao->insertDcmCompress(['status'=>8,'study_id'=>$study]);
  101. // gc_collect_cycles();
  102. // $this->reportDao->updateDcmPath(['study_id'=>$study],['dcm_type'=>2]);
  103. // unlink($path_url);
  104. // return 2;
  105. // }
  106. // return '1';
  107. //
  108. // }
  109. //
  110. // public function zip($data,$create,$date,$study)
  111. // {
  112. // ini_set('max_execution_time', 6000);
  113. // $fileList = [];
  114. // $exam = $this->reportDao->getExamByStudy($study);
  115. // $this->reportDao->insertDcmCompress(['status'=>3,'study_id'=>$study]);
  116. // if($exam['institution_id'] == '06300009')
  117. // {
  118. // $patient_num = $exam['patient_num'];
  119. // $name = $exam['name'];
  120. // //工人医院需要解密
  121. // if (!file_exists($create)) {
  122. // mkdir($create, 0777,true);
  123. // @chmod($create, 0777);
  124. // }
  125. // $ts = system("python3.8 /data/code/ris_server/utils/down/main.py '$patient_num' '$study' '$name' $date");
  126. // if($ts)
  127. // {
  128. // $files = scandir($create);
  129. // foreach ($files as $v)
  130. // {
  131. // if($v == '.' || $v == '..')
  132. // {
  133. // continue;
  134. // }
  135. // $fileList[] = $create.DS.$v;
  136. // }
  137. // }
  138. // }else{
  139. // foreach ($data as $k=>$v)
  140. // {
  141. // $path = $this->downLoad($v,$create.DS.$k,$create);
  142. // $fileList[] = $path;
  143. // }
  144. // $zipPath = ROOT_PATH . 'public' . DS .'zip';
  145. // $filename = $zipPath.DS."$date.zip";
  146. // if (!file_exists($zipPath)) {
  147. // mkdir($zipPath, 0777,true);
  148. // @chmod($zipPath, 0777);
  149. // }
  150. // $this->reportDao->insertDcmCompress(['status'=>4,'study_id'=>$study]);
  151. // $zip = new \ZipArchive();
  152. // $zip->open($filename,\ZipArchive::CREATE); //打开压缩包
  153. // foreach($fileList as $file){
  154. // $zip->addFile($file,basename($file)); //向压缩包中添加文件
  155. // }
  156. // $zip->close(); //关闭压缩包
  157. // }
  158. // $this->reportDao->insertDcmCompress(['status'=>5,'study_id'=>$study]);
  159. // $path_url = 'zip/'.$date.".zip";
  160. // $insert = [
  161. // 'dcm_path'=>$path_url,
  162. // 'study_id'=>$study,
  163. // 'effective_date'=>date('Y-m-d H:i:s',time()+864000), //10天有效期
  164. // ];
  165. // $this->reportDao->insertDcmPath($insert);
  166. // $this->delCache($study.'_zip');
  167. // $this->reportDao->insertDcmCompress(['status'=>6,'study_id'=>$study]);
  168. // return $path_url;
  169. // }
  170. //
  171. // public function sendEmail($email,$dcmPath,$name,$type=1)
  172. // {
  173. // $dcmPath = $this->makeFileUrl($dcmPath,$type,'attachment','+3 days','zskktemp');
  174. // $mail = new PHPMailer(true); // Passing `true` enables exceptions
  175. // try {
  176. // //服务器配置
  177. // $mail->CharSet ="UTF-8"; //设定邮件编码
  178. // $mail->SMTPDebug = 0; // 调试模式输出
  179. // $mail->isSMTP(); // 使用SMTP
  180. // $mail->Host = 'smtp.exmail.qq.com'; // SMTP服务器
  181. // $mail->SMTPAuth = true; // 允许 SMTP 认证
  182. // $mail->Username = 'company@pacsonline.cn'; // SMTP 用户名 即邮箱的用户名
  183. // $mail->Password = 'Zskk1234'; // SMTP 密码 部分邮箱是授权码(例如163邮箱)
  184. // $mail->SMTPSecure = 'ssl'; // 允许 TLS 或者ssl协议
  185. // $mail->Port = 465; // 服务器端口 25 或者465 具体要看邮箱服务器支持
  186. //
  187. // $mail->setFrom('company@pacsonline.cn', '冠医云'); //发件人
  188. // $mail->addAddress($email, ''); // 收件人
  189. // //$mail->addAddress('ellen@example.com'); // 可添加多个收件人
  190. // $mail->addReplyTo('company@pacsonline.cn', '冠医云'); //回复的时候回复给哪个邮箱 建议和发件人一致
  191. // //$mail->addCC('cc@example.com'); //抄送
  192. // //$mail->addBCC('bcc@example.com'); //密送
  193. // $zipPath = ROOT_PATH . 'public';
  194. //// $maxsize = 45 * 1024 * 1024;
  195. // $mail->Subject = $name.'影像';
  196. //// if(filesize($zipPath.'/'.$dcmPath) < $maxsize)
  197. //// {
  198. //// //发送附件
  199. ////// $mail->addAttachment($zipPath.'a.zip'); // 添加附件
  200. //// $mail->addAttachment($zipPath.'/'.$dcmPath, $name.'.zip'); // 发送附件并且重命名
  201. //// $mail->Body = "链接将于".date('Y-m-d',time()+10*24*3600)."失效,请即时下载";
  202. //// $mail->AltBody = "链接将于".date('Y-m-d',time()+10*24*3600)."失效,请即时下载";
  203. //// }else{
  204. // //发送链接地址
  205. //
  206. // //Content
  207. // $mail->isHTML(true); // 是否以HTML文档格式发送 发送后客户端可直接显示对应HTML内容
  208. // if($type == 2)
  209. // {
  210. // $dcmPath = ltrim($dcmPath,'/');
  211. // $mail->Body = "<a href='https://zskktemp.eos-beijing-7.cmecloud.cn/$dcmPath'>下载".$name."影像</a>"."<br>链接将于".date('Y-m-d',time()+3*24*3600)."失效,请及时下载";
  212. // }else
  213. // {
  214. // $mail->Body = "<a href='https://risserver3.pacsonline.cn/$dcmPath'>下载".$name."影像</a>"."<br>链接将于".date('Y-m-d',time()+3*24*3600)."失效,请及时下载";
  215. // }
  216. //// $mail->AltBody = '如果邮件客户端不支持HTML则显示此内容';
  217. //// }
  218. //
  219. // $mail->send();
  220. // return '邮件发送成功';
  221. // } catch (Exception $e) {
  222. // return '邮件发送失败: '.$mail->ErrorInfo;
  223. // }
  224. // }
  225. }