This commit is contained in:
chenbo 2024-02-21 14:25:33 +08:00
parent 3643b2b7d7
commit 2c48c37228
2 changed files with 23 additions and 2 deletions

View File

@ -15,6 +15,7 @@
namespace app\adminapi\logic\animal_info;
use app\common\logic\RemoteRequestLogic;
use app\common\model\animal_info\AnimalInfo;
use app\common\logic\BaseLogic;
use think\facade\Db;
@ -134,10 +135,19 @@ class AnimalInfoLogic extends BaseLogic
*/
public static function detail($params): array
{
$data = AnimalInfo::with(['fenceHouseAttr'])->findOrEmpty($params['id'])->toArray();
if (isset($params['sn'])) {
return AnimalInfo::with(['fenceHouseAttr'])->where('sn', $params['sn'])->findOrEmpty()->toArray();
$data = AnimalInfo::with(['fenceHouseAttr'])->where('sn', $params['sn'])->findOrEmpty()->toArray();
}
return AnimalInfo::with(['fenceHouseAttr'])->findOrEmpty($params['id'])->toArray();
// 查动物体温
$res = RemoteRequestLogic::requestAnimalTemperature($data['sn']);
if (!empty($res['values'])) {
$temperature = $res['values'][1];
} else {
$temperature = 0;
}
$data['temperature'] = $temperature;
return $data;
}
}

View File

@ -264,4 +264,15 @@ class RemoteRequestLogic extends BaseLogic
$monitor = json_decode($response->getContent(), true);
return $monitor['data']['values'];
}
public static function requestAnimalTemperature($rfid='')
{
$response = HttpClient::create()->request('GET', env('PROJECT.MQTT_PROJECT_URL'). 'api/xumu/warning/past_seven_days', [
'query' => [
'rfid' => $rfid
]
]);
$monitor = json_decode($response->getContent(), true);
return $monitor['data'];
}
}