船舶更新
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use app\command\UpdateShipInfoCommand;
|
||||
use app\model\LogisticsShip;
|
||||
use app\model\LogisticsShipHis;
|
||||
use app\model\Vehicle;
|
||||
@@ -18,6 +19,9 @@ use app\service\OssService;
|
||||
// use plugin\admin\app\model\Location;
|
||||
use app\service\ShipService;
|
||||
use app\service\TranslatorService;
|
||||
use support\Log;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
use util\Util;
|
||||
use support\Request;
|
||||
use support\Cache;
|
||||
@@ -253,6 +257,64 @@ class VehicleController
|
||||
return Util::success($result);
|
||||
}
|
||||
|
||||
public function shipList(Request $request){
|
||||
$navigate = LogisticsShip::where(['status' => 0])->get();
|
||||
$pending = LogisticsShip::where(['status' => 1])->get();
|
||||
$result = ['navigate' => $navigate,'pending' => $pending];
|
||||
|
||||
return Util::success($result);
|
||||
}
|
||||
|
||||
public function add(Request $request){
|
||||
try {
|
||||
Log::info('开始执行船舶信息更新任务');
|
||||
|
||||
// 通过ShipService获取船舶最新信息
|
||||
$shipInfo = ShipService::getShipInfo($request->get('mmsi'));
|
||||
$apiData = $shipInfo['data']['data'] ?? null;
|
||||
|
||||
$ship = new LogisticsShip();
|
||||
$updateData = $this->mapApiDataToShip($apiData);
|
||||
$updateData['mmsi'] = $request->get('mmsi');
|
||||
$ship->fill($updateData);
|
||||
$res = $ship->save();
|
||||
|
||||
if($res){
|
||||
return Util::success($res,'成功');
|
||||
} else{
|
||||
return Util::fail($res,'成功');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('船舶信息更新任务执行异常', [
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将API数据映射到船舶表字段
|
||||
* @param array $apiData
|
||||
* @return array
|
||||
*/
|
||||
private function mapApiDataToShip(array $apiData): array
|
||||
{
|
||||
return [
|
||||
'IMO' => $apiData['imo'] ?? '',
|
||||
'call_sign' => $apiData['call_sign'] ?? '',
|
||||
'ship_name' => $apiData['ship_name'] ?? '',
|
||||
'ship_cnname' => $apiData['ship_cnname'] ?? '',
|
||||
'dest' => $apiData['dest'] ?? '',
|
||||
'length' => $apiData['length'] ?? '',
|
||||
'width' => $apiData['width'] ?? '',
|
||||
'lat' => $apiData['lat'] ?? '',
|
||||
'lng' => $apiData['lng'] ?? '',
|
||||
'eta_utc' => $apiData['eta_utc'] ?? null,
|
||||
'last_time_utc' => $apiData['last_time_utc'] ?? null,
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific vehicle with its location
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user