103 lines
3.3 KiB
PHP
103 lines
3.3 KiB
PHP
<?php
|
||
/*
|
||
* description:
|
||
* author:wh
|
||
* email:
|
||
* createTime:{2024/11/27} {10:11}
|
||
*/
|
||
|
||
namespace app\api\controller;
|
||
|
||
|
||
use app\common\model\TabConf;
|
||
use think\Db;
|
||
use wanghua\general_utility_tools_php\http\Curl;
|
||
use wanghua\general_utility_tools_php\Mmodel;
|
||
use wanghua\general_utility_tools_php\tool\Tools;
|
||
|
||
class Drugsimagesmedicaltasknotify extends BaseHttpApi
|
||
{
|
||
|
||
/**
|
||
* desc:药品,CT,病例上传AI分析任务回调地址
|
||
*
|
||
* 回调地址会在请求ai接口时传递:
|
||
*(参考):
|
||
* 线上域名:https://ybx_prediagnosis.excn.top
|
||
* /api/Drugsimagesmedicaltasknotify/notify
|
||
*
|
||
* method: post
|
||
*
|
||
* 数据结构建议:
|
||
* {
|
||
* "code":200,//500(失败、异常、错误),可以是其它有意义的值
|
||
* "msg":'提示信息',//eg:处理成功、请求失败,处理中等
|
||
* "data":[],//该值可以是任意数据,eg:数组、字符串等
|
||
* }
|
||
*
|
||
* author:wh
|
||
*/
|
||
function notify(){
|
||
return Mmodel::catchJson(function (){
|
||
Tools::log_to_write_txt(['药品,CT,病例上传AI分析任务回调,入参'=>input()]);
|
||
|
||
|
||
$this->notify_test();
|
||
});
|
||
}
|
||
|
||
private function notify_test(){
|
||
$jsondecode = input();
|
||
|
||
$task_id = $jsondecode['task_id'];
|
||
$result = $jsondecode['result'];
|
||
|
||
|
||
if(empty($task_id)){
|
||
return Tools::set_fail('参数错误.0',['error_msg'=>'错误信息:task_id错误']);
|
||
}
|
||
//$log_file_name = 'drugs_images_medical';
|
||
//$header = [
|
||
// //'Accept: application/json',
|
||
// "Content-Type: application/json"
|
||
//];
|
||
//$url = "https://image_fastapi.excn.vip/imgs-task/{$task_id}";
|
||
//Tools::log_to_write_txt(['异步查询图片处理结果,请求地址'=>$url,'task_id'=>$task_id],$log_file_name);
|
||
//$process_images_res = Curl::curl_request($url,'GET',[],$header);
|
||
//Tools::log_to_write_txt(['异步查询图片处理结果,返回结果'=>$process_images_res],$log_file_name);
|
||
|
||
//if(isset($process_images_res['status']) && $process_images_res['status'] == 'error'){
|
||
// return Tools::set_fail($process_images_res['message']);
|
||
//}
|
||
if(isset($result['detail']) && $result['detail'] == '未知的任务 ID'){
|
||
return Tools::set_fail($result['detail']);
|
||
}
|
||
if(isset($result['status']) && $result['status'] == 'pending'){
|
||
return Tools::set_fail('处理中请等待');
|
||
}
|
||
//if(!isset($result['result']) || $result['result'] == ''){
|
||
// return Tools::set_fail('未查询到结果');
|
||
//}
|
||
|
||
//保存处理结果
|
||
Db::table(TabConf::$fa_drugs_images_medical_task)
|
||
->data([
|
||
'result'=>json_encode($jsondecode),
|
||
])
|
||
->where('task_id',$task_id)
|
||
->update();
|
||
|
||
//遍历二维数组,将每张图片的分析同步到
|
||
foreach ($result as $item){
|
||
Db::table(TabConf::$fa_drugs_images_medical_result)
|
||
->where('imageid',$item['id'])
|
||
->data([
|
||
'ai_result'=>$item['result'],
|
||
'type'=>$item['type'],
|
||
])
|
||
->update();
|
||
}
|
||
|
||
return Tools::set_ok('ok',$result);
|
||
}
|
||
} |