Commit 390604ad by banice

解决断电时间恢复

parent 7bc74168
......@@ -14,6 +14,7 @@ use Illuminate\Support\Facades\DB;
use Lib\Session;
use Lib\station\gateway\Gateway;
use Lib\station\gateway\port\Port;
use Src\BroadcastToAgent;
class GatewayController extends Controller
{
......@@ -44,6 +45,16 @@ class GatewayController extends Controller
$redis->exec();
$broadcastToAgent = new BroadcastToAgent();
$broadcastToAgent->broadcast([
'notice_exception_code' => 15,
'gateway_id' => Session::get('gateway_id'),
'station_id' => Session::get('station_id'),
'station_name' => Session::get('station_name'),
'gateway_mac' => Session::get('gateway_mac'),
]);
}
......
......@@ -10,13 +10,16 @@ namespace Application\controller\business\power;
use Application\controller\Controller;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Log;
use Lib\Session;
class ShutdownController extends Controller
{
protected $parameterMap = [
'04' => []
'0F' => []
];
public function __construct(string $clientId, string $message, string $command)
......@@ -27,6 +30,25 @@ class ShutdownController extends Controller
public function shutdown()
{
Log::debug('offline');
$gatewayId = Session::get('gateway_id');
if (filled($gatewayId)) {
$client = new Client([
'http_errors' => false,
]);
$response = $client->request('POST', route('deviceStateOffline'), [
'form_params' => ['ids' => [$gatewayId]],
]);
if ($response->getStatusCode() === 200) {
Log::info('gateway offline by 0F', compact('gatewayId'));
} else {
Log::error('gateway offline by 0F request fail');
}
}
}
......
......@@ -60,7 +60,9 @@ class SettingController extends Controller
$powerSaturateInvertalTime = $idConfigsValue['7'];
$extraTime = $idConfigsValue['8'];
$powerLowerLimit = getenv('LOW_POWER_LIMIT');
// $powerLowerLimit = getenv('LOW_POWER_LIMIT');
$powerLowerLimit = 30;
$detectTime = 5;
$afterFormat = $this->adaptor([
[$invertalTime, 4],
......
......@@ -33,7 +33,7 @@ class Api
$this->add('08', 'business\port\OnlineController@online');
$this->add('09', 'business\port\OfflineController@offline');
// $this->add('0F', 'business\power\ShutdownController@shutdown');
$this->add('0F', 'business\power\ShutdownController@shutdown');
$this->add('0A', 'setting\SettingController@get');
$this->add('31', 'card\PayRuleController@get');
......
......@@ -21,8 +21,6 @@ class Api
public function boot()
{
Log::debug('boot');
$this->add('01', 'accept\CertifyController@certify');
$this->add('00', 'HeartController@break');
$this->add('02', 'accept\AccessController@request');
......@@ -42,7 +40,7 @@ class Api
$this->add('08', 'business\port\OnlineController@online');
$this->add('09', 'business\port\OfflineController@offline');
// $this->add('0F', 'business\power\ShutdownController@shutdown');
$this->add('0F', 'business\power\ShutdownController@shutdown');
$this->add('0A', 'setting\SettingController@get');
$this->add('31', 'card\PayRuleController@get');
......
......@@ -206,7 +206,6 @@ class ChargerState extends State
'created_at' => $this->nowDate,
]);
Log::debug('充满自停状态');
$chargerFullMessage = new ChargerFullMessage();
$chargerFullMessage->setEndTime($this->nowDate);
......@@ -237,10 +236,6 @@ class ChargerState extends State
* 推送用户信息
* 发布延时任务十分钟后检测端口
*
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \AMQPConnectionException
* @throws \AMQPExchangeException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function toShedState()
......
......@@ -9,6 +9,10 @@
namespace Lib\station\gateway;
use Application\model\OrderExceptionModel;
use Illuminate\Support\Facades\DB;
use Lib\cdz\order\Order;
use Lib\cdz\order\save\OrderSaveRedis;
use Lib\Session;
use Lib\station\gateway\port\Port;
use Illuminate\Support\Facades\Log;
......@@ -38,6 +42,9 @@ class Gateway
Log::debug($portsMacId);
$portsId = array_values($portsMacId);
$redis = app('Redis');
$offlineTime = time();
$date = date('Y-m-d H:i:s');
if ($redis instanceof \Redis) {
......@@ -45,12 +52,36 @@ class Gateway
$port = new Port();
$orderExceptionModel = [];
foreach ($portsId as $portId) {
$port->setPortId($portId);
$port->setState(10);
$port->updatePortState();
$usingOrderId = $port->getPortUsingOrderId();
Log::debug($usingOrderId . 'using');
if (filled($usingOrderId)) {
$order = new Order($usingOrderId);
$order->setOfflineTime($offlineTime);
$orderRedis = new OrderSaveRedis($order);
$orderRedis->save(['offlineTime']);
array_push($orderExceptionModel, [
'order_id' => $usingOrderId,
'state' => 10,
'desc' => '网关离线,订单离线',
'created_at' => $date,
]);
}
}
DB::table('wx_charger_orders_exception')->insert($orderExceptionModel);
}
......
......@@ -46,7 +46,7 @@ $router->post('gateway/offline', 'GatewayController@offline');
$router->get('gateway', 'SessionController@getSession');
$router->post('gateway/offline', 'device\StateController@offline');
$router->post('gateway/offline', ['uses' => 'device\StateController@offline', 'as' => 'deviceStateOffline']);
......
......@@ -10,6 +10,7 @@ namespace Src;
use Lib\Gateway;
use Lib\Session;
class BroadcastToAgent
{
......@@ -18,9 +19,8 @@ class BroadcastToAgent
public function __construct()
{
if (isset($_SESSION['agent_id'])) {
$this->agentId = $_SESSION['agent_id'];
if (filled(Session::get('agent_id'))) {
$this->agentId = Session::get('agent_id');
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment