Просмотр исходного кода

添加定时任务的自动执行

程旭源 1 год назад
Родитель
Сommit
35f3754ed3

+ 25 - 0
application/admin/command/AutoTask.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace app\admin\command;
+
+use think\console\Command;
+use think\console\Input;
+use think\console\Output;
+
+class AutoTask extends Command
+{
+    public function configure()
+    {
+        $this
+            ->setName('AutoTask')
+            ->setDescription('自动下发定时指令');
+    }
+
+    public function execute(Input $input, Output $output)
+    {
+        //TODO STEP1 获取当前的时间
+        //TODO 根据时间获取需要下发的指令
+        //TODO 下发指令
+        echo "自动执行启动了";
+    }
+}

+ 15 - 15
application/admin/command/Min.php

@@ -15,20 +15,20 @@ class Min extends Command
      * 路径和文件名配置
      */
     protected $options = [
-        'cssBaseUrl'  => 'public/assets/css/',
+        'cssBaseUrl' => 'public/assets/css/',
         'cssBaseName' => '{module}',
-        'jsBaseUrl'   => 'public/assets/js/',
-        'jsBaseName'  => 'require-{module}',
+        'jsBaseUrl' => 'public/assets/js/',
+        'jsBaseName' => 'require-{module}',
     ];
 
     protected function configure()
     {
         $this
-                ->setName('min')
-                ->addOption('module', 'm', Option::VALUE_REQUIRED, 'module name(frontend or backend),use \'all\' when build all modules', null)
-                ->addOption('resource', 'r', Option::VALUE_REQUIRED, 'resource name(js or css),use \'all\' when build all resources', null)
-                ->addOption('optimize', 'o', Option::VALUE_OPTIONAL, 'optimize type(uglify|closure|none)', 'none')
-                ->setDescription('Compress js and css file');
+            ->setName('min')
+            ->addOption('module', 'm', Option::VALUE_REQUIRED, 'module name(frontend or backend),use \'all\' when build all modules', null)
+            ->addOption('resource', 'r', Option::VALUE_REQUIRED, 'resource name(js or css),use \'all\' when build all resources', null)
+            ->addOption('optimize', 'o', Option::VALUE_OPTIONAL, 'optimize type(uglify|closure|none)', 'none')
+            ->setDescription('Compress js and css file');
     }
 
     protected function execute(Input $input, Output $output)
@@ -79,15 +79,15 @@ class Min extends Command
         foreach ($moduleArr as $mod) {
             foreach ($resourceArr as $res) {
                 $data = [
-                    'publicPath'  => $publicPath,
-                    'jsBaseName'  => str_replace('{module}', $mod, $this->options['jsBaseName']),
-                    'jsBaseUrl'   => $this->options['jsBaseUrl'],
+                    'publicPath' => $publicPath,
+                    'jsBaseName' => str_replace('{module}', $mod, $this->options['jsBaseName']),
+                    'jsBaseUrl' => $this->options['jsBaseUrl'],
                     'cssBaseName' => str_replace('{module}', $mod, $this->options['cssBaseName']),
-                    'cssBaseUrl'  => $this->options['cssBaseUrl'],
-                    'jsBasePath'  => str_replace(DS, '/', ROOT_PATH . $this->options['jsBaseUrl']),
+                    'cssBaseUrl' => $this->options['cssBaseUrl'],
+                    'jsBasePath' => str_replace(DS, '/', ROOT_PATH . $this->options['jsBaseUrl']),
                     'cssBasePath' => str_replace(DS, '/', ROOT_PATH . $this->options['cssBaseUrl']),
-                    'optimize'    => $optimize,
-                    'ds'          => DS,
+                    'optimize' => $optimize,
+                    'ds' => DS,
                 ];
 
                 //源文件

+ 0 - 4
application/admin/command/MqttMessage.php

@@ -4,13 +4,9 @@ namespace app\admin\command;
 
 use app\admin\services\MqttMessageClient;
 use app\jobs\DeviceReportEvent;
-use \PhpMqtt\Client\MqttClient;
-use \PhpMqtt\Client\ConnectionSettings;
 use think\console\Command;
 use think\console\Input;
-use think\console\input\Option;
 use think\console\Output;
-use think\Env;
 use think\Queue;
 
 class MqttMessage extends Command

+ 1 - 1
application/admin/services/MqttMessageClient.php

@@ -29,7 +29,7 @@ class MqttMessageClient
         $password = Env::get("mqtt.password");
 
 
-        $mqtt = new \PhpMqtt\Client\MqttClient($hostname, $port, $clientId, MqttClient::MQTT_3_1_1);
+        $mqtt =new MqttClient($hostname, $port, $clientId, MqttClient::MQTT_3_1_1);
         $connectionSettings = (new ConnectionSettings());
         if ($username !== null) {
             $connectionSettings = $connectionSettings->setUsername($username);

+ 2 - 1
application/command.php

@@ -17,5 +17,6 @@ return [
     'app\admin\command\Min',
     'app\admin\command\Addon',
     'app\admin\command\Api',
-    'app\admin\command\MqttMessage'
+    'app\admin\command\MqttMessage',
+    'app\admin\command\AutoTask'
 ];

+ 0 - 2
application/jobs/DeviceReportEvent.php

@@ -33,8 +33,6 @@ class DeviceReportEvent
 //            "DATA"  =>  [] // 事件参数
 //        ];
 
-        var_dump($data);
-
         if (!isset($data['TYPE'])) return false;
 
         switch ($data['TYPE']) {