Commit dbaa101f by banice

ac警报信息上报redis缓存

parent 3da31602
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/26
* Time: 上午9:28
*/
namespace App\Http\Controllers;
use App\Http\model\AdvertisementModel;
use Illuminate\Http\Request;
class AdvertisementController extends Controller
{
/**
* 广告信息获取,广告图url
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function get(Request $request)
{
$advertisementArray = AdvertisementModel::all(['url', 'mark'])->toArray();
for ($i = 0; $i < count($advertisementArray); $i++) {
$advertisementArray[$i]['url'] = env('RESOURCE_HOST') . '/' . $advertisementArray[$i]['url'];
}
return response()->json([
'return_code' => 200,
'result_code' => 'SUCCESS',
'data' => $advertisementArray
]);
}
}
\ No newline at end of file
<?php
namespace App\Http\Controllers;
class ExampleController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//
}
//
}
......@@ -2,27 +2,36 @@
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/25
* Time: 下午2:23
* Date: 2018/9/26
* Time: 下午2:51
*/
namespace App\Http\Controllers;
namespace App\Http\Controllers\ac;
use App\Http\Controllers\Controller;
use App\Providers\RedisServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
class SettingController extends Controller
class AlarmController extends Controller
{
public function setting(Request $request)
public function post(Request $request)
{
app()->register(RedisServiceProvider::class);
$boxCode = $request->get('box_code');
$payload = $request->get('payload');
Log::debug($request->all());
$site = $payload['site'];
$user = $payload['user'];
$password = $payload['password'];
$redis = app('Redis');
if ($redis instanceof \Redis) {
}
}
}
\ No newline at end of file
......@@ -25,7 +25,6 @@ class StateController extends Controller
*/
public function post(Request $request)
{
Log::debug($request->all());
$message = json_decode($request->get('Message'), true);
......
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/26
* Time: 下午3:16
*/
namespace App\Http\Controllers\door;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use src\box\Box;
use Validator;
class InitController extends Controller
{
public function init(Request $request, Box $box)
{
$validator = Validator::make($request->all(), [
'box_code' => 'required|exists:boxes,code',
'box_num' => 'required|integer'
]);
if ($validator->fails() === true) {
return response()->json([
'return_code' => 400,
'result_code' => 'FAIL',
'error_message' => $validator->errors()->first()
]);
}
$boxCode = $request->get('box_code');
$boxNum = $request->get('box_num');
$box->setCode($boxCode);
$box->searchByCode($boxCode, ['id']);
$boxId = $box->getValue('id');
$box->setId($boxId);
$validator = Validator::make(['box_id' => $boxId], [
'box_id' => 'unique:box_rooms,box_id'
]);
if ($validator->fails() === true) {
return response()->json([
'return_code' => 400,
'result_code' => 'FAIL',
'error_message' => $validator->errors()->first()
]);
}
$box->initDoor();
return response()->json([
'return_code' => 200,
'result_code' => 'SUCCESS',
]);
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/26
* Time: 上午10:02
*/
namespace App\Http\model;
use Illuminate\Database\Eloquent\Model;
class AdvertisementModel extends Model
{
protected $table = 'adverts';
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/26
* Time: 下午3:19
*/
namespace App\Http\model;
use Illuminate\Database\Eloquent\Model;
use src\box\door\Door;
class DoorModel extends Model
{
protected $table = 'box_rooms';
public function add(Door $door)
{
$this->box_id = $door->getBoxId();
$this->name = $door->getName();
$this->box_type = $door->getBoxType();
return $this->save();
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/27
* Time: 上午10:09
*/
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class RedisServiceProvider extends ServiceProvider
{
protected $defer = true;
public function register()
{
$this->app->singleton('Redis', function ($app) {
$redis = new \Redis();
$config = config('database.redis.default');
$redis->connect($config['host']);
$redis->select($config['database']);
return $redis;
});
}
public function boot()
{
}
public function provides()
{
return ['Redis'];
}
}
\ No newline at end of file
......@@ -28,6 +28,8 @@ $app->withFacades();
$app->withEloquent();
$app->configure('logging');
$app->configure('database');
/*
|--------------------------------------------------------------------------
......@@ -82,6 +84,8 @@ $app->routeMiddleware([
*/
$app->register(App\Providers\AppServiceProvider::class);
//$app->register(\App\Providers\RedisServiceProvider::class);
// $app->register(App\Providers\AuthServiceProvider::class);
// $app->register(App\Providers\EventServiceProvider::class);
......
{
"name": "laravel/lumen",
"description": "The Laravel Lumen Framework.",
"keywords": ["framework", "laravel", "lumen"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=7.1.3",
"laravel/lumen-framework": "5.6.*",
"vlucas/phpdotenv": "~2.2",
"guzzlehttp/guzzle": "~6.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"phpunit/phpunit": "~7.0",
"mockery/mockery": "~1.0"
},
"autoload": {
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/",
"database/"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"optimize-autoloader": true
"name": "laravel/lumen",
"description": "The Laravel Lumen Framework.",
"keywords": [
"framework",
"laravel",
"lumen"
],
"license": "MIT",
"type": "project",
"require": {
"php": ">=7.1.3",
"laravel/lumen-framework": "5.6.*",
"vlucas/phpdotenv": "~2.2",
"guzzlehttp/guzzle": "~6.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"phpunit/phpunit": "~7.0",
"mockery/mockery": "~1.0"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Lib\\": "lib/",
"src\\": "src/"
}
},
"autoload-dev": {
"classmap": [
"tests/",
"database/"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"optimize-autoloader": true
}
}
<?php
return [
/*
|--------------------------------------------------------------------------
| PDO Fetch Style
|--------------------------------------------------------------------------
|
| By default, database results will be returned as instances of the PHP
| stdClass object; however, you may desire to retrieve records in an
| array format for simplicity. Here you can tweak the fetch style.
|
*/
'fetch' => PDO::FETCH_CLASS,
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => env('DB_CONNECTION', 'mysql'),
/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/
'connections' => [
'testing' => [
'driver' => 'sqlite',
'database' => ':memory:',
],
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', base_path('database/database.sqlite')),
'prefix' => env('DB_PREFIX', ''),
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 3306),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => env('DB_CHARSET', 'utf8mb4'),
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
'prefix' => env('DB_PREFIX', ''),
'timezone' => env('DB_TIMEZONE', '+08:00'),
'strict' => env('DB_STRICT_MODE', false),
],
'old_cdz' => [
'driver' => 'mysql',
'host' => env('PRE_DB_HOST'),
'port' => env('PRE_DB_PORT', 3306),
'database' => env('PRE_DB_DATABASE'),
'username' => env('PRE_DB_USERNAME'),
'password' => env('PRE_DB_PASSWORD'),
'charset' => env('DB_CHARSET', 'utf8mb4'),
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
'prefix' => env('DB_PREFIX', ''),
'timezone' => env('DB_TIMEZONE', '+08:00'),
'strict' => env('DB_STRICT_MODE', false),
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 5432),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => env('DB_CHARSET', 'utf8'),
'prefix' => env('DB_PREFIX', ''),
'schema' => env('DB_SCHEMA', 'public'),
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => env('DB_CHARSET', 'utf8'),
'prefix' => env('DB_PREFIX', ''),
],
],
/*
|--------------------------------------------------------------------------
| Migration Repository Table
|--------------------------------------------------------------------------
|
| This table keeps track of all the migrations that have already run for
| your application. Using this information, we can determine which of
| the migrations on disk haven't actually been run in the database.
|
*/
'migrations' => 'migrations',
/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer set of commands than a typical key-value systems
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/
'redis' => [
'cluster' => env('REDIS_CLUSTER', false),
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DATABASE', 4),
'password' => env('REDIS_PASSWORD', null),
],
],
];
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/27
* Time: 上午10:08
*/
namespace Lib;
class RedisSingle
{
}
\ No newline at end of file
# 换电柜mqtt(http订阅端)
\ No newline at end of file
# 换电柜mqtt(http订阅端)
## redis 字典
* ac报警信息
`key:'hdg:ac:alarm:hash`
数据结构:hash
|filed|说明|
|:----:|:----:|
|humidity_1|湿度传感器|
|humidity_2|湿度传感器|
|humidity_3|湿度传感器|
|temperature_1|温度传感器|
|temperature_2|温度传感器|
|temperature_3|温度传感器|
|sensor_state_1|传感器状态|
|sensor_state_2|传感器状态|
|sensor_state_3|传感器状态|
|retain_1|预留状态|
|retain_2|预留状态|
|retain_3|预留状态|
|white_smoke|白烟|
|black_smoke|黑烟|
|retain|预留|
......@@ -13,7 +13,6 @@
$router->get('/', function () use ($router) {
return $router->app->version();
});
......@@ -24,8 +23,15 @@ $router->group(['middleware' => ['mqtt']], function () use ($router) {
$router->get('ac/state', 'ac\StateController@get');
$router->post('ac/state', 'ac\StateController@post');
$router->post('door/lock/version', 'door\LockController@version');
$router->post('door/state', 'door\StateController@state');
$router->post('door/state', 'door\StateController@post');
});
$router->post('ac/alarm/info', 'ac\AlarmController@post');
$router->post('box/init', 'door\InitController@init');
$router->get('advertisement', 'AdvertisementController@get');
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/26
* Time: 下午2:03
*/
namespace src\box;
use App\Http\model\DoorModel;
use src\box\door\Door;
class Box
{
use SearchModel;
private $id = 0;
private $code = '';
private $type = 1;
public function __construct(int $id = 0)
{
$this->id = $id;
}
/**
* @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 getCode(): string
{
return $this->code;
}
/**
* @param string $code
*/
public function setCode(string $code): void
{
$this->code = $code;
}
/**
* @param int $doorCount
*/
public function initDoor(int $doorCount = 16): void
{
$i = 1;
while ($doorCount--) {
$door = new Door();
$door->setName($i++);
$door->setBoxId($this->id);
$door->setBoxType($this->type);
$doorModel = new DoorModel();
$doorModel->add($door);
unset($door);
unset($doorModel);
}
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/26
* Time: 下午2:06
*/
namespace src\box;
use App\Http\model\BoxModel;
trait SearchModel
{
/**
* @var BoxModel
*/
protected $boxModel;
/**
* @param string $code
* @param array $parameters
* @return bool
*/
public function searchByCode(string $code, array $parameters = []): bool
{
$this->boxModel = BoxModel::where('code', $code)->first($parameters);
return $this->boxModel === null ? false : true;
}
/**
* @return BoxModel
*/
public function getBoxModel(): BoxModel
{
return $this->boxModel;
}
/**
* @param BoxModel $boxModel
*/
public function setBoxModel(BoxModel $boxModel): void
{
$this->boxModel = $boxModel;
}
/**
* @param string $parameter
* @return mixed
*/
public function getValue(string $parameter)
{
return $this->boxModel->$parameter;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/9/26
* Time: 下午3:20
*/
namespace src\box\door;
class Door
{
private $id = 0;
private $name = 1;
private $boxId = 0;
private $boxType = 1;
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param int $id
*/
public function setId(int $id): void
{
$this->id = $id;
}
/**
* @return int
*/
public function getName(): int
{
return $this->name;
}
/**
* @param int $name
*/
public function setName(int $name): void
{
$this->name = $name;
}
/**
* @return int
*/
public function getBoxId(): int
{
return $this->boxId;
}
/**
* @param int $boxId
*/
public function setBoxId(int $boxId): void
{
$this->boxId = $boxId;
}
/**
* @return int
*/
public function getBoxType(): int
{
return $this->boxType;
}
/**
* @param int $boxType
*/
public function setBoxType(int $boxType): void
{
$this->boxType = $boxType;
}
}
\ No newline at end of file
......@@ -10,8 +10,8 @@ return array(
'App\\Events\\Event' => $baseDir . '/app/Events/Event.php',
'App\\Events\\ExampleEvent' => $baseDir . '/app/Events/ExampleEvent.php',
'App\\Exceptions\\Handler' => $baseDir . '/app/Exceptions/Handler.php',
'App\\Http\\Controllers\\AdvertisementController' => $baseDir . '/app/Http/Controllers/AdvertisementController.php',
'App\\Http\\Controllers\\Controller' => $baseDir . '/app/Http/Controllers/Controller.php',
'App\\Http\\Controllers\\ExampleController' => $baseDir . '/app/Http/Controllers/ExampleController.php',
'App\\Http\\Controllers\\SettingController' => $baseDir . '/app/Http/Controllers/SettingController.php',
'App\\Http\\Controllers\\ac\\StateController' => $baseDir . '/app/Http/Controllers/ac/StateController.php',
'App\\Http\\Controllers\\ac\\VersionController' => $baseDir . '/app/Http/Controllers/ac/VersionController.php',
......@@ -20,6 +20,7 @@ return array(
'App\\Http\\Middleware\\Authenticate' => $baseDir . '/app/Http/Middleware/Authenticate.php',
'App\\Http\\Middleware\\ExampleMiddleware' => $baseDir . '/app/Http/Middleware/ExampleMiddleware.php',
'App\\Http\\Middleware\\MqttMiddleware' => $baseDir . '/app/Http/Middleware/MqttMiddleware.php',
'App\\Http\\model\\AdvertisementModel' => $baseDir . '/app/Http/model/AdvertisementModel.php',
'App\\Http\\model\\BoxModel' => $baseDir . '/app/Http/model/BoxModel.php',
'App\\Jobs\\ExampleJob' => $baseDir . '/app/Jobs/ExampleJob.php',
'App\\Jobs\\Job' => $baseDir . '/app/Jobs/Job.php',
......
......@@ -6,6 +6,7 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'src\\' => array($baseDir . '/src'),
'phpDocumentor\\Reflection\\' => array($vendorDir . '/phpdocumentor/reflection-common/src', $vendorDir . '/phpdocumentor/reflection-docblock/src', $vendorDir . '/phpdocumentor/type-resolver/src'),
'Webmozart\\Assert\\' => array($vendorDir . '/webmozart/assert/src'),
'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
......@@ -23,6 +24,7 @@ return array(
'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-message/src'),
'Psr\\Container\\' => array($vendorDir . '/psr/container/src'),
'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'),
'Lib\\' => array($baseDir . '/lib'),
'Laravel\\Lumen\\' => array($vendorDir . '/laravel/lumen-framework/src'),
'Illuminate\\View\\' => array($vendorDir . '/illuminate/view'),
'Illuminate\\Validation\\' => array($vendorDir . '/illuminate/validation'),
......
......@@ -19,6 +19,10 @@ class ComposerStaticInit0ade57c1033f366706485424e320dd7a
);
public static $prefixLengthsPsr4 = array (
's' =>
array (
'src\\' => 4,
),
'p' =>
array (
'phpDocumentor\\Reflection\\' => 25,
......@@ -53,6 +57,7 @@ class ComposerStaticInit0ade57c1033f366706485424e320dd7a
),
'L' =>
array (
'Lib\\' => 4,
'Laravel\\Lumen\\' => 14,
),
'I' =>
......@@ -110,6 +115,10 @@ class ComposerStaticInit0ade57c1033f366706485424e320dd7a
);
public static $prefixDirsPsr4 = array (
'src\\' =>
array (
0 => __DIR__ . '/../..' . '/src',
),
'phpDocumentor\\Reflection\\' =>
array (
0 => __DIR__ . '/..' . '/phpdocumentor/reflection-common/src',
......@@ -180,6 +189,10 @@ class ComposerStaticInit0ade57c1033f366706485424e320dd7a
array (
0 => __DIR__ . '/..' . '/monolog/monolog/src/Monolog',
),
'Lib\\' =>
array (
0 => __DIR__ . '/../..' . '/lib',
),
'Laravel\\Lumen\\' =>
array (
0 => __DIR__ . '/..' . '/laravel/lumen-framework/src',
......@@ -348,8 +361,8 @@ class ComposerStaticInit0ade57c1033f366706485424e320dd7a
'App\\Events\\Event' => __DIR__ . '/../..' . '/app/Events/Event.php',
'App\\Events\\ExampleEvent' => __DIR__ . '/../..' . '/app/Events/ExampleEvent.php',
'App\\Exceptions\\Handler' => __DIR__ . '/../..' . '/app/Exceptions/Handler.php',
'App\\Http\\Controllers\\AdvertisementController' => __DIR__ . '/../..' . '/app/Http/Controllers/AdvertisementController.php',
'App\\Http\\Controllers\\Controller' => __DIR__ . '/../..' . '/app/Http/Controllers/Controller.php',
'App\\Http\\Controllers\\ExampleController' => __DIR__ . '/../..' . '/app/Http/Controllers/ExampleController.php',
'App\\Http\\Controllers\\SettingController' => __DIR__ . '/../..' . '/app/Http/Controllers/SettingController.php',
'App\\Http\\Controllers\\ac\\StateController' => __DIR__ . '/../..' . '/app/Http/Controllers/ac/StateController.php',
'App\\Http\\Controllers\\ac\\VersionController' => __DIR__ . '/../..' . '/app/Http/Controllers/ac/VersionController.php',
......@@ -358,6 +371,7 @@ class ComposerStaticInit0ade57c1033f366706485424e320dd7a
'App\\Http\\Middleware\\Authenticate' => __DIR__ . '/../..' . '/app/Http/Middleware/Authenticate.php',
'App\\Http\\Middleware\\ExampleMiddleware' => __DIR__ . '/../..' . '/app/Http/Middleware/ExampleMiddleware.php',
'App\\Http\\Middleware\\MqttMiddleware' => __DIR__ . '/../..' . '/app/Http/Middleware/MqttMiddleware.php',
'App\\Http\\model\\AdvertisementModel' => __DIR__ . '/../..' . '/app/Http/model/AdvertisementModel.php',
'App\\Http\\model\\BoxModel' => __DIR__ . '/../..' . '/app/Http/model/BoxModel.php',
'App\\Jobs\\ExampleJob' => __DIR__ . '/../..' . '/app/Jobs/ExampleJob.php',
'App\\Jobs\\Job' => __DIR__ . '/../..' . '/app/Jobs/Job.php',
......
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