1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace app\command;
- use app\common\server\ShOneanalysis;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Argument;
- 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接收信息')
- ->addArgument('action', Argument::OPTIONAL, "start|stop|restart|reload|status|connections", 'start');
- // 设置参数
- }
- protected function execute(Input $input, Output $output)
- {
- $action = $input->getArgument('action');
- global $argv;
- array_shift($argv);
- $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();
- }
- }
|