Commit 914e138d by BANice

订单同步完成未测试,网关离线记录正在充电的订单的离线时间

parent fa8cd04d
......@@ -15,7 +15,11 @@ use Application\Model\OrderModel;
use Application\Model\PortModel;
use Application\Model\StationModel;
use GatewayWorker\Lib\Gateway;
use Lib\cdz_order\Order;
use Lib\cdz_order\state\Offline;
use Lib\cdz_order\state\Online;
use Lib\Log;
use Lib\order_exception\OrderState;
use Lib\port\Port;
use Lib\redis\RedisKey;
......@@ -123,6 +127,12 @@ class AccessController extends Controller
}
private function syncOrder(array $portId)
{
}
/**
* command 03
* 端口同步
......@@ -146,7 +156,13 @@ class AccessController extends Controller
$this->plc += $countDec * 16;
$macsState = substr($this->message, $this->plc);
$macsState = substr($this->message, $this->plc, $countDec * 2);
$this->plc += $countDec * 2;
$offlineReason = substr($this->message, $this->plc);
$offlineReason = hexdec($offlineReason);
$stateArray = $this->parseState($macsState);
......@@ -192,6 +208,7 @@ class AccessController extends Controller
if (isset($portMacId[$mac])) {
$portIdState[$portMacId[$mac]] = $stateArray[$i];
}
$i++;
......@@ -199,87 +216,76 @@ class AccessController extends Controller
$redis->exec();
Log::debug('口子状态', $portIdState
);
$port->setPortState($portIdState); //改变口子状态
if (isset($_SESSION['port_mac_id'])) {
$portMacId = $_SESSION['port_mac_id'];
}
$responseOrder = [];
$time = time();
foreach ($portIdState as $id => $state) {
$port->setId($id);
$orderId = $port->getPortUsingOrderId($redis, $id);
var_dump($orderId);
Log::debug('order_id->'.$orderId);
if (isset($orderId) === false || $orderId === false || $orderId == 0) {
continue;
} else {
$orderModel = new OrderModel();
$order = new Order();
$order->setId($orderId);
var_dump($orderId);
$orderInfo = $orderModel->getColumns(['charger_time', 'created_at', 'logic_num'], 'id = ' . $orderId);
if ($order->getOrderCache($redis) !== false) {
$createdTime = $orderInfo['created_at'];
$orderState = new Offline($order, $redis, $offlineReason);
$chargerTime = $orderInfo['charger_time'];
$orderState->toCharger();
$remainChargerTime = $orderState->getRemainChargerTime();
if (($chargerTime + strtotime($createdTime) < $time)) {
continue;
} else {
Log::debug('remainChargerTime'.$remainChargerTime);
$chargerTime = ceil($chargerTime - ($time - strtotime($createdTime)));
$chargerTime = (int)$chargerTime;
if ($chargerTime > 0) {
if ($remainChargerTime > 0) {
array_push($responseOrder, [
sprintf('%02x', $orderInfo['logic_num']),
sprintf('%012x', $orderId),
sprintf('%04x', $chargerTime),
sprintf('%02x', $order->getPortLogicId()),
sprintf('%012x', $order->getId()),
sprintf('%04x', $remainChargerTime),
]);
}
}
}
}
unset($order);
}
$orderCount = sprintf('%02x',count($responseOrder));
Log::debug('using order',$responseOrder);
$orderCount = sprintf('%02x', count($responseOrder));
$responseOrderMessage = '';
foreach ($responseOrder as $order) {
$responseOrderMessage.=implode('',$order);
$responseOrderMessage .= implode('', $order);
}
Log::debug($orderCount);
Log::debug('order_using',$responseOrder);
Log::debug('response_order_message ->'.$responseOrderMessage);
return $this->response->send('03', $startLogicNum . $count . $totalCount.$orderCount.$responseOrderMessage);
$this->response->send('03', $startLogicNum . $count . $totalCount . $orderCount . $responseOrderMessage);
}
......@@ -302,8 +308,6 @@ class AccessController extends Controller
}
Log::debug('mac => logic', $macLogic);
return $macLogic;
}
......@@ -324,6 +328,22 @@ class AccessController extends Controller
}, $state);
}
/**
* 解析离线原因
* @param string $reason
* @return array
*/
private function parseOfflineReason(string $reason)
{
$reasonCode = str_split($reason, 2);
return array_map(function ($hex) {
return (int)hexdec($hex);
}, $reasonCode);
}
}
......
......@@ -20,6 +20,8 @@ use Lib\api\message\ChargerReloadMessage;
use Lib\api\message\ChargerStartMessage;
use Lib\api\message\PortShedMessage;
use Lib\api\message\Push;
use Lib\cdz_order\Order;
use Lib\cdz_order\state\WaitingCharger;
use Lib\Gateway;
use Lib\Log;
use Lib\order_exception\OrderState;
......@@ -210,23 +212,25 @@ class PortController extends Controller
$update = ['shed_time' => $nowTime];
$orderLastState = OrderState::getState($orderId);
if($orderLastState == StateCode::PORT_SHED) {
if (isset($lastShedTime)) {
$gapTime = strtotime($nowTime) - strtotime($lastShedTime);
if (($gapTime / 60) > 12) {
//口子距离上一次插口脱落时间超过了十分中,下发结束充电命令
//发送结束充电,结束状态为远程超时结束
Log::debug('todo 插口脱落超时10分钟');
}
}
}
// $orderLastState = OrderState::getState($orderId);
//
// if ($orderLastState == StateCode::PORT_SHED) {
//
// if (isset($lastShedTime)) {
// $gapTime = strtotime($nowTime) - strtotime($lastShedTime);
//
// if (($gapTime / 60) > 12) {
//
// //fixme debug
//
// //口子距离上一次插口脱落时间超过了十分中,下发结束充电命令
// //发送结束充电,结束状态为远程超时结束
//
// Log::debug('todo 插口脱落超时10分钟');
//
// }
// }
// }
$orderModel->update($update, 'id = ' . $orderId);
......@@ -292,13 +296,11 @@ class PortController extends Controller
}
$redis = \Events::getRedis();
switch ($state) {
case StateCode::PORT_CHARGER:
$orderState = new OrderState($orderId);
$orderState->setState(12);
$orderModel = new OrderModel();
$result = $orderModel->getColumns(['port_name', 'station_name', 'created_at', 'charger_time', 'order_amount'], 'id = ' . $orderId);
......@@ -330,6 +332,18 @@ class PortController extends Controller
} else if ($lastState == -1) {
$order = new Order();
$order->setId($orderId);
if($order->getOrderCache($redis) !== false)
{
$waiting = new WaitingCharger($order,$redis);
$waiting->toCharger();
}
$chargerStartMessage = new ChargerStartMessage();
$chargerStartMessage->setStartTime($result['created_at']);
......@@ -420,7 +434,6 @@ class PortController extends Controller
case StateCode::FINISH_REMOTE:
break;
case StateCode::PORT_OFFLINE:
......@@ -433,6 +446,11 @@ class PortController extends Controller
break;
case StateCode::FINISH_EXCEED:
break;
default:
break;
......
......@@ -10,7 +10,6 @@ namespace Application\Controller;
use Application\Controller;
use Application\Model\ExceptionModel;
use Application\Model\OrderCapacityModel;
use Application\Model\OrderExceptionModel;
use Application\Model\OrderModel;
......@@ -21,19 +20,16 @@ use Lib\api\message\ChargerFailMessage;
use Lib\api\message\ChargerFinishMessage;
use Lib\api\message\ChargerRefundMessage;
use Lib\api\message\ChargerStartMessage;
use Lib\api\message\MessageData;
use Lib\api\message\PortShedMessage;
use Lib\api\message\Push;
use Lib\cdz_order\Order;
use Lib\cdz_order\state\WaitingCharger;
use Lib\Gateway;
use Lib\Log;
use Lib\order_exception\OrderState;
use Lib\order_exception\OrderTrace;
use Lib\port\Port;
use Lib\rabbitmq\MyRabbitMq;
use Lib\send\command\StopChargerCommand;
use Lib\send\Send;
use Lib\state\StateCode;
use Workerman\Events\Event;
class PowerController extends Controller
{
......@@ -131,7 +127,14 @@ class PowerController extends Controller
$stationName = $_SESSION['station_name'];
$orderState = new OrderState($orderId);
$order = new Order();
$order->setId($id);
$redis = \Events::getRedis();
if ($state === StateCode::PORT_CHARGER) {
......@@ -147,7 +150,16 @@ class PowerController extends Controller
$pushMessage->setAddress($stationName . '-' . $portName . '号');
$orderState->setState($state);
if( $order->getOrderCache($redis) !== false)
{
var_dump($order->getOrderCache($redis));
$waiting = new WaitingCharger($order,$redis);
$waiting->toCharger();
}
......@@ -163,8 +175,6 @@ class PowerController extends Controller
$pushMessage->setOrderId($orderId);
$orderState->setState($state);
}
......@@ -247,7 +257,6 @@ class PowerController extends Controller
$time = date('Y-m-d H:i:s');
$port = new Port();
$port->setLogic((int)$logic);
......
......@@ -149,13 +149,12 @@ class Events
{
// 网关离线将往下所有的口子全部设置为离线
$redis = Events::getRedis();
if (isset($_SESSION['gateway_id']) === true) {
Log::info('gateway_id(' . $_SESSION['gateway_id'] . ')' . 'disconnect');
$redis = Events::getRedis();
$redis->zAdd(\Lib\redis\RedisKey::GATEWAY_STATE, 0, $_SESSION['gateway_id']);
......@@ -193,9 +192,8 @@ class Events
$portMacIdArray = $_SESSION['port_mac_id'];
if (isset($portMacIdArray)) {
$port = new \Lib\port\Port();
Log::debug('close 设置离线口子', $portMacIdArray);
$port = new \Lib\port\Port();
$port->offline(array_values($portMacIdArray));
......@@ -203,12 +201,10 @@ class Events
try {
$exceptionModel = new \Application\Model\ExceptionModel();
$gatewayId = $_SESSION['gateway_id'];
$insert = ['message' => '网关离线', 'gateway_id' => $gatewayId, 'type' => 1, 'created_at' => date('Y-m-d H:i:s')];
if (isset($_SESSION['station_id'])) {
......@@ -221,7 +217,27 @@ class Events
}
$portIds = array_values($portMacIdArray);
$time = time();
$port = new \Lib\port\Port();
$usingOrderIds = $port->getPortsUsingId($redis, $portIds);
$redis->multi(2);
foreach ($usingOrderIds as $portId => $usingOrderId) {
if ($usingOrderId !== false) {
$keyName = \Lib\cdz_order\state\State::ORDER_HASH_PREFIX . $usingOrderId;
$redis->hSet($keyName, 'offlineTime', $time);
}
}
$redis->exec();
}
......
......@@ -82,9 +82,6 @@ class Response
$this->length = sprintf('%04x',(8+strlen($data)/2 ));
Log::debug('send-length'.$this->length);
Gateway::sendToClient($this->controller->getClientId(),$this->organize());
}
......
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/16
* Time: 上午9:24
*/
namespace Lib\cdz_order;
use Lib\cdz_order\state\State;
use Lib\Log;
class Order
{
/**
* @var int
*/
private $id;
/**
* @var string
*/
private $createdTime = '';
/**
* @var int
*/
private $userId;
/**
* @var int
*/
private $payAmount;
/**
* @var int
*/
private $purchaseTime;
/**
* @var int
*/
private $portId;
/**
* @var int
*/
private $gatewayId;
/**
* @var string
*/
private $gatewayMac;
/**
* @var int
*/
private $portLogicId;
/**
* @var State
*/
private $currentState;
/**
* @var int
*/
private $stateCode;
/**
* @var array
*/
private $orderCache;
/**
* @var string
*/
private $portName;
/**
* @var string
*/
private $stationName;
/**
* @param \Redis $redis
* @return array|bool
*/
public function getOrderCache(\Redis $redis)
{
if(isset($this->orderCache) === false){
$keyName = State::ORDER_HASH_PREFIX . $this->id;
if ($redis->exists($keyName) === false) {
Log::debug('exists false');
return false;
}
$this->orderCache = $redis->hGetAll($keyName);
foreach ($this->orderCache as $key => $value) {
$this->$key = $value;
}
}
return $this->orderCache;
}
/**
* @param \Redis $redis
* @param $orderCache
*/
public function setOrderCache(\Redis $redis, $orderCache): void
{
$this->orderCache = $orderCache;
$redis->hMset(State::ORDER_HASH_PREFIX . $this->id, $orderCache);
}
/**
* @return State
*/
public function getCurrentState(): State
{
return $this->currentState;
}
/**
* @param State $currentState
*/
public function setCurrentState(State $currentState): void
{
$this->currentState = $currentState;
}
/**
* @return int
*/
public function getStateCode(): int
{
return $this->stateCode;
}
/**
* @param int $stateCode
*/
public function setStateCode(int $stateCode): void
{
$this->stateCode = $stateCode;
}
/**
* @return string
*/
public function getCreatedTime(): string
{
return $this->createdTime;
}
/**
* @param string $createdTime
*/
public function setCreatedTime(string $createdTime): void
{
$this->createdTime = $createdTime;
}
/**
* @return int
*/
public function getUserId(): int
{
return $this->userId;
}
/**
* @param int $userId
*/
public function setUserId(int $userId): void
{
$this->userId = $userId;
}
/**
* @return int
*/
public function getPayAmount(): int
{
return $this->payAmount;
}
/**
* @param int $payAmount
*/
public function setPayAmount(int $payAmount): void
{
$this->payAmount = $payAmount;
}
/**
* @return int
*/
public function getPurchaseTime(): int
{
return $this->purchaseTime;
}
/**
* @param int $purchaseTime
*/
public function setPurchaseTime(int $purchaseTime): void
{
$this->purchaseTime = $purchaseTime;
}
/**
* @return int
*/
public function getPortId(): int
{
return $this->portId;
}
/**
* @param int $portId
*/
public function setPortId(int $portId): void
{
$this->portId = $portId;
}
/**
* @return int
*/
public function getGatewayId(): int
{
return $this->gatewayId;
}
/**
* @param int $gatewayId
*/
public function setGatewayId(int $gatewayId): void
{
$this->gatewayId = $gatewayId;
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param int $id
*/
public function setId(int $id): void
{
$this->id = $id;
}
/**
* @return string
*/
public function getGatewayMac(): string
{
return $this->gatewayMac;
}
/**
* @param string $gatewayMac
*/
public function setGatewayMac(string $gatewayMac): void
{
$this->gatewayMac = $gatewayMac;
}
/**
* @return int
*/
public function getPortLogicId(): int
{
return $this->portLogicId;
}
/**
* @param int $portLogicId
*/
public function setPortLogicId(int $portLogicId): void
{
$this->portLogicId = $portLogicId;
}
/**
* @return string
*/
public function getPortName(): string
{
return $this->portName;
}
/**
* @param string $portName
*/
public function setPortName(string $portName): void
{
$this->portName = $portName;
}
/**
* @return string
*/
public function getStationName(): string
{
return $this->stationName;
}
/**
* @param string $stationName
*/
public function setStationName(string $stationName): void
{
$this->stationName = $stationName;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/16
* Time: 上午9:34
*/
namespace Lib\cdz_order\order;
use Lib\cdz_order\Order;
use Lib\cdz_order\state\State;
class SaveOrder
{
protected $state;
protected $redis;
public function __construct(State $state)
{
$this->state = $state;
$this->redis = $state->getRedis();
}
public function saveCreatedTime()
{
$this->redis->hSet($this->state->getKeyName(), State::FIELD[0], $this->state->getOrder()->getCreatedTime());
}
public function saveStartTime()
{
$this->redis->hSet($this->state->getKeyName(), State::FIELD[2], $this->state->getStartTime());
}
public function saveShedTime()
{
$this->redis->hSet($this->state->getKeyName(), State::FIELD[4], $this->state->getShedTime());
}
public function savePortOfflineTime()
{
$this->redis->hSet($this->state->getKeyName(), State::FIELD[5], $this->state->getOfflineTime());
}
public function savePortOnlineTime()
{
$this->redis->hSet($this->state->getKeyName(), State::FIELD[6], $this->state->getOnlineTime());
}
public function saveStateCode()
{
$this->redis->hSet($this->state->getKeyName(), State::FIELD[7], $this->state->getOrder()->getStateCode());
}
public function pipe()
{
$this->state->getRedis()->multi(2);
}
public function exec()
{
$this->state->getRedis()->exec();
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/16
* Time: 上午9:36
*/
namespace Lib\cdz_order\state;
use Lib\cdz_order\Order;
class Charger extends State
{
public function __construct(Order $order, \Redis $redis) { parent::__construct($order, $redis); }
public function toCharger()
{
// TODO: Implement toCharger() method.
}
public function toPortShed()
{
// TODO: Implement toPortShed() method.
}
public function toPowerExceed()
{
// TODO: Implement toPowerExceed() method.
}
public function toFull()
{
// TODO: Implement toFull() method.
}
public function toFinish()
{
// TODO: Implement toFinish() method.
}
public function toOffline()
{
// TODO: Implement toOffline() method.
}
public function toOnline()
{
// TODO: Implement toOnline() method.
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/16
* Time: 上午10:49
*/
namespace Lib\cdz_order\state;
use Lib\cdz_order\Order;
class Created extends State
{
public function __construct(Order $order, \Redis $redis) { parent::__construct($order, $redis); }
public function toCharger()
{
// TODO: Implement toCharger() method.
}
public function toPortShed()
{
// TODO: Implement toPortShed() method.
}
public function toPowerExceed()
{
// TODO: Implement toPowerExceed() method.
}
public function toFull()
{
// TODO: Implement toFull() method.
}
public function toFinish()
{
// TODO: Implement toFinish() method.
}
public function toOffline()
{
// TODO: Implement toOffline() method.
}
public function toOnline()
{
// TODO: Implement toOnline() method.
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/16
* Time: 上午9:39
*/
namespace Lib\cdz_order\state;
class Finish
{
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/16
* Time: 上午10:32
*/
namespace Lib\cdz_order\state;
use Lib\cdz_order\Order;
class Offline extends State
{
public function __construct(Order $order, \Redis $redis, int $offlineReason)
{
parent::__construct($order, $redis);
$this->offlineReason = $offlineReason;
}
/**
*
*/
public function toCharger()
{
$purchaseTime = $this->order->getPurchaseTime();
$startTime = $this->getStartTime();
$offlineTime = $this->getOfflineTime();
$this->onlineTime = time();
if ($this->offlineReason == 1) {
$remainTime = $purchaseTime * 60 - ($offlineTime - $startTime);
$this->remainChargerTime = (int)ceil($remainTime / 60);
} else {
$remainTime = $purchaseTime * 60 - ($this->onlineTime - $startTime);
$this->remainChargerTime = (int) ceil($remainTime/60);
}
$this->saveOrder->savePortOnlineTime();
$this->order->setCurrentState(new Charger($this->order,$this->redis));
}
public function toPortShed()
{
// TODO: Implement toPortShed() method.
}
public function toPowerExceed()
{
// TODO: Implement toPowerExceed() method.
}
public function toFull()
{
// TODO: Implement toFull() method.
}
public function toFinish()
{
// TODO: Implement toFinish() method.
}
public function toOffline()
{
// TODO: Implement toOffline() method.
}
public function toOnline()
{
// TODO: Implement toOnline() method.
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/16
* Time: 上午10:32
*/
namespace Lib\cdz_order\state;
class Online extends State
{
public function toCharger()
{
// TODO: Implement toCharger() method.
}
public function toPortShed()
{
// TODO: Implement toPortShed() method.
}
public function toPowerExceed()
{
// TODO: Implement toPowerExceed() method.
}
public function toFull()
{
// TODO: Implement toFull() method.
}
public function toFinish()
{
// TODO: Implement toFinish() method.
}
public function toOffline()
{
// TODO: Implement toOffline() method.
}
public function toOnline()
{
// TODO: Implement toOnline() method.
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/16
* Time: 上午9:36
*/
namespace Lib\cdz_order\state;
class PortShed
{
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/16
* Time: 上午9:30
*/
namespace Lib\cdz_order\state;
use Lib\api\message\Push;
use Lib\cdz_order\Order;
use Lib\cdz_order\order\SaveOrder;
abstract class State
{
/**
* 订单状态包含的参数
*/
const FIELD = [
'createdTime',
'purchaseTime',
'startTime',
'finishTime',
'shedTime',
'offlineTime',
'onlineTime',
'stateCode',
];
/**
* 订单状态hash前缀
*/
const ORDER_HASH_PREFIX = 'cdz:order:state:';
/**
* @var Order
*/
protected $order;
/**
* @var SaveOrder
*/
protected $saveOrder;
/**
* @var string
*/
protected $keyName= '';
/**
* @var \Redis
*/
protected $redis;
/**
* @var string
*/
protected $shedTime;
/**
* @var string
*/
protected $startTime;
/**
* @var string
*/
protected $endTime;
/**
* @var string
*/
protected $offlineTime;
/**
* @var string
*/
protected $onlineTime;
/**
* @var int
*/
protected $offlineReason;
/**
* @var int
*/
protected $remainChargerTime;
/**
* State constructor.
* @param Order $order
*/
public function __construct(Order $order,\Redis $redis) {
$this->order = $order;
$this->keyName = self::ORDER_HASH_PREFIX.$order->getId();
$this->redis = $redis;
$this->saveOrder = new SaveOrder($this);
$orderCache = $order->getOrderCache($redis);
if(is_array($orderCache))
{
foreach ($orderCache as $key => $value)
{
if(isset($value) === true)
{
if(property_exists($this,$key) === true)
{
$this->$key =$value;
}
}
}
}
}
abstract public function toCharger();
abstract public function toPortShed();
abstract public function toPowerExceed();
abstract public function toFull();
abstract public function toFinish();
abstract public function toOffline();
abstract public function toOnline();
/**
* @return Order
*/
public function getOrder(): Order
{
return $this->order;
}
/**
* @param Order $order
*/
public function setOrder(Order $order): void
{
$this->order = $order;
}
/**
* @return SaveOrder
*/
public function getSaveOrder(): SaveOrder
{
return $this->saveOrder;
}
/**
* @param SaveOrder $saveOrder
*/
public function setSaveOrder(SaveOrder $saveOrder): void
{
$this->saveOrder = $saveOrder;
}
/**
* @return string
*/
public function getKeyName(): string
{
return $this->keyName;
}
/**
* @param string $keyName
*/
public function setKeyName(string $keyName): void
{
$this->keyName = $keyName;
}
/**
* @return \Redis
*/
public function getRedis(): \Redis
{
return $this->redis;
}
/**
* @param \Redis $redis
*/
public function setRedis(\Redis $redis): void
{
$this->redis = $redis;
}
/**
* @return string
*/
public function getShedTime(): string
{
return $this->shedTime;
}
/**
* @param string $shedTime
*/
public function setShedTime(string $shedTime): void
{
$this->shedTime = $shedTime;
}
/**
* @return string
*/
public function getOfflineTime(): string
{
return $this->offlineTime;
}
/**
* @param string $offlineTime
*/
public function setOfflineTime(string $offlineTime): void
{
$this->offlineTime = $offlineTime;
}
/**
* @return string
*/
public function getOnlineTime(): string
{
return $this->onlineTime;
}
/**
* @param string $onlineTime
*/
public function setOnlineTime(string $onlineTime): void
{
$this->onlineTime = $onlineTime;
}
/**
* @return int
*/
public function getOfflineReason(): int
{
return $this->offlineReason;
}
/**
* @param int $offlineReason
*/
public function setOfflineReason(int $offlineReason): void
{
$this->offlineReason = $offlineReason;
}
/**
* @return int
*/
public function getRemainChargerTime(): int
{
return $this->remainChargerTime;
}
/**
* @param int $remainChargerTime
*/
public function setRemainChargerTime(int $remainChargerTime): void
{
$this->remainChargerTime = $remainChargerTime;
}
/**
* @return string
*/
public function getStartTime(): string
{
return $this->startTime;
}
/**
* @param string $startTime
*/
public function setStartTime(string $startTime): void
{
$this->startTime = $startTime;
}
/**
* @return string
*/
public function getEndTime(): string
{
return $this->endTime;
}
/**
* @param string $endTime
*/
public function setEndTime(string $endTime): void
{
$this->endTime = $endTime;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/16
* Time: 上午9:36
*/
namespace Lib\cdz_order\state;
use Lib\cdz_order\Order;
class WaitingCharger extends State
{
public function __construct(Order $order, \Redis $redis) { parent::__construct($order, $redis); }
/**
* 订单从等待充电转为开始充电状态
*/
public function toCharger():void
{
$this->setStartTime(time());
$this->order->setStateCode(12);
$this->order->setCurrentState(new Charger($this->order,$this->redis));
$this->saveOrder->pipe();
$this->saveOrder->saveStartTime();
$this->saveOrder->saveStateCode();
$this->saveOrder->exec();
$this->order->setCurrentState(new Charger($this->order,$this->redis));
}
/**
* @throws \Exception
*/
public function toPortShed()
{
throw new \Exception(' waiting state can not change to port shed');
// TODO: Implement toPortShed() method.
}
/**
* @throws \Exception
*/
public function toPowerExceed()
{
throw new \Exception('waiting state can not change to power exceed');
// TODO: Implement toPowerExceed() method.
}
/**
* @throws \Exception
*/
public function toFull()
{
throw new \Exception('waiting state can not change to full state');
// TODO: Implement toFull() method.
}
public function toFinish()
{
// TODO: Implement toFinish() method.
}
/**
* 充电中口子发生离线,订单状态变为离线
*/
public function toOffline()
{
$this->offlineTime = time();
$this->saveOrder->savePortOfflineTime();
$this->order->setCurrentState(new Offline($this->order,$this->redis));
}
/**
* @throws \Exception
*/
public function toOnline()
{
throw new \Exception('waiting state can not change to online');
// TODO: Implement toOnline() method.
}
}
\ No newline at end of file
......@@ -202,8 +202,6 @@ class Port
*/
public function offline(array $portId)
{
Log::debug('offline');
$tmp = [RedisKey::PORT_STATE_ZSET];
foreach ($portId as $item) {
......@@ -350,7 +348,23 @@ class Port
$result = $redis->hGet(RedisKey::PORT_USING_ORDER_ID,$portId);
return isset($result) ? $result : 0;
var_dump('using order');
var_dump($result);
return is_string($result) ? $result : 0;
}
public function getPortsUsingId(\Redis $redis, array $portsId):array
{
$result = $redis->hMGet(RedisKey::PORT_USING_ORDER_ID,$portsId);
var_dump($result);
return $result;
}
/**
......
# 通讯协议v2(应用协议)
# 通讯协议v2(应用协议)
......@@ -2,11 +2,11 @@
## 同步口子
1.下位机->服务器<font color='red'> 同步口子增加了订单的同步</font>
1.下位机->服务器<font color='red'> 同步口子增加了订单的同步和口子离线原因</font>
|preamble|headerFlag|headerCtrl|length|nonce|startNum|count|totalCount|portMac|portState|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---|:---|:---:|:---:|:---:|:---:|
|协议头|是否加密|03|包长|随机字符|口子起始逻辑号(1byte)|包中口子数(1byte)|网关下口子总数(1byte)|口子mac地址(8bytes*n)|口子状态(n bytes)|crc|
|preamble|headerFlag|headerCtrl|length|nonce|startNum|count|totalCount|portMac|portState|offline_reason|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---|:---|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|03|包长|随机字符|口子起始逻辑号(1byte)|包中口子数(1byte)|网关下口子总数(1byte)|口子mac地址(8bytes*n)|口子状态(n bytes)|口子离线原因(1:断电,0:断网) 1byte|crc|
2.服务器->下位机
......@@ -39,11 +39,12 @@
## 结束充电
<font color ='red'>添加结束类型字段,finish_type默认为0,服务器远程结束时下位机原样返回给服务器,下位机自主结束返回00</font>
1.服务器->下位机
|preamble|headerFlag|headerCtrl|length|nonce|port|outTradeNo|finish_type|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|05|包长|随机字符|端口逻辑号|订单号(6bytes)|结束类型(1byte)|crc|
|preamble|headerFlag|headerCtrl|length|nonce|port|outTradeNo|finish_type|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|05|包长|随机字符|端口逻辑号|订单号(6bytes)|结束类型(1byte)|crc|
2.下位机->服务器修改状态字段位置
......@@ -54,24 +55,24 @@
3.服务器->下位机
|preamble|headerFlag|headerCtrl|length|nonce|port|outTradeNo|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|15|包长|随机字符|口子逻辑号|订单号(6bytes)|crc|
|preamble|headerFlag|headerCtrl|length|nonce|port|outTradeNo|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|15|包长|随机字符|口子逻辑号|订单号(6bytes)|crc|
## 上报电表电量
1.服务器->下位机
|preamble|headerFlag|headerCtrl|length|nonce|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|06|包长|随机字符|crc|
|preamble|headerFlag|headerCtrl|length|nonce|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|06|包长|随机字符|crc|
2.下位机->服务器
|preamble|headerFlag|headerCtrl|length|nonce|powerCapacity|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|06|包长|随机字符|电表用电量(4bytes)|crc|
|preamble|headerFlag|headerCtrl|length|nonce|powerCapacity|mic|
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|协议头|是否加密|06|包长|随机字符|电表用电量(4bytes)|crc|
## 上报充电功率
......
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/7/16
* Time: 下午5:35
*/
$redis = new \Redis();
$redis->pconnect('redis.test.senthink.com',6379, 1);
$redis->select(4);
var_dump($redis->hGet('','123'));
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