wang jun 1 year ago
parent
commit
b60212e7a6

+ 80 - 0
application/command/analysisShoneMsg.php

@@ -0,0 +1,80 @@
+<?php
+
+namespace app\command;
+
+use app\common\server\ShOneanalysis;
+use think\console\Command;
+use think\console\Input;
+use think\console\Output;
+use think\facade\Log;
+use Workerman\Lib\Timer;
+use Workerman\Worker;
+
+/**
+ * 30秒执行一次
+ *
+ * @author wj
+ * @date 2023-08-14
+ */
+class analysisShoneMsg extends Command
+{
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('analysisShoneMsg')->setDescription('解析手环one接收信息');
+        // 设置参数
+
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        // 指令输出
+        // Log::write([123123, 76868], 'shouhuan');
+        // $output->writeln('test');
+        $task = new Worker();
+        $task->count = 4;
+        $server_sa = new ShOneanalysis();
+        $server_sa->initanalysisShoneReceiveMsg();
+        $task->onWorkerStart = function ($task) use ($server_sa) {
+            //$time = microtime(true);
+            $pageinfo = $server_sa->getreceivequeuelist();
+            $totalpage = $pageinfo['totalpage'];
+            $size = $pageinfo['size'];
+            for ($i = 0; $i < $totalpage; $i++) {
+                Timer::add(1, function () use ($size, $server_sa) {
+                    $page = 1;
+                    $list = $server_sa->getreceivequeuelist($page, $size);
+                    if ($list) {
+                        $list = (array) $list;
+                        foreach ($list as $key => $value) {
+                            try {
+                                $linedata = $server_sa->getline($value['msg']);
+                                //长度相等可解析
+                                $content = $linedata['content_str'];
+                                $device_id_code = $linedata['device_id_code'];
+                                $fid = $server_sa->getfacilityid($device_id_code);
+                                $content = $server_sa->getcommandcontent($content);
+                                $server_sa->saveshinfo($fid, $device_id_code, $content, $value['msg']);
+                                $command = $content[0];
+                                $data = $server_sa->createbacksendmsg($fid, $device_id_code, $content, $command);
+                                Log::write($data, 'shouhuan');
+                                $server_sa->receivemsgsuccess($value);
+                            } catch (\Exception $e) {
+                                $msg = $e->getMessage();
+                                echo $msg . "\n";
+                                Log::write($msg, 'shouhuan');
+                                Log::write($e->getTraceAsString(), 'shouhuan');
+                            }
+                        }
+                    }
+                });
+            }
+
+            // $endtime = microtime(true);
+            // $difftime = bcsub($endtime, $time);
+            // var_dump('difftime:' . $difftime);
+        };
+        // 运行worker
+        Worker::runAll();
+    }
+}

+ 17 - 2
application/common/server/ShOneanalysis.php

@@ -174,12 +174,18 @@ class ShOneanalysis
                 ],
                 'kind' => 'back',
             ],
-            'HEART'=>[
+            'HEART' => [
                 'content' => [
                     'command' => 'heart',
                 ],
                 'kind' => 'back',
-            ]
+            ],
+            'BLOOD' => [
+                'content' => [
+                    'command' => 'blood',
+                ],
+                'kind' => 'back',
+            ],
         ];
         if (!isset($data[$command])) {
             return false;
@@ -306,6 +312,15 @@ class ShOneanalysis
                 'kind' => 'tsend',
                 'need_back' => 1,
             ],
+            'BLOOD' => [
+                'content' => [
+                    'command' => 'blood',
+                    'blood_height_pressure' => '',
+                    'blood_low_pressure' => '',
+                ],
+                'kind' => 'tsend',
+                'need_back' => 1,
+            ],
         ];
         if (!isset($data[$command])) {
             return false;