public static function getPolymerData($id1, $id2)
 {
     $polymers = [];
     $links = [];
     $group1 = $group2 = [];
     $models = DeviceInfo::find()->where(["id" => [$id1, $id2]])->all();
     foreach ($models as $model) {
         $polymers[$model->id] = ['id' => 'p' . $model->id, 'label' => $model->label, "children" => []];
     }
     $filterIds = DeviceIpfilter::find()->where(["type_id" => DeviceIpfilter::TYPE_POLYMER])->select("ip")->column();
     $rows = (new Query())->from("device_link a")->leftJoin("device_info b", "a.leftDevice = b.id or a.rightDevice=b.id")->where(['and', ['b.ip' => $filterIds], "a.leftDevice in({$id1},{$id2}) or a.rightDevice in({$id1},{$id2})"])->select(['label' => "b.ip", "b.id", "b.status", 'linkStatus' => "a.status", 'b.area', "a.leftDevice", "a.rightDevice"])->groupBy('b.id')->all();
     foreach ($rows as $row) {
         if (in_array($row["id"], [$id1, $id2])) {
             continue;
         }
         if (in_array(strtoupper($row["area"]), ["A", "C"])) {
             $group = "group1:id" . $row["id"];
             $group1[] = ["label" => $row["label"], "id" => 'id' . $row["id"], "group" => $group, "status" => $row["status"], "device_id" => $row["id"]];
         } else {
             $group = "group2:id" . $row["id"];
             $group2[] = ["label" => $row["label"], "id" => 'id' . $row["id"], "group" => $group, "status" => $row["status"], "device_id" => $row["id"]];
         }
         $polymer_id = $row["leftDevice"] == $row["id"] ? $row["rightDevice"] : $row["leftDevice"];
         $polymers[$polymer_id]["children"][] = $group;
         $links[] = ["from" => 'id' . $row["id"], "to" => $polymers[$polymer_id]["id"], "status" => $row["linkStatus"]];
     }
     return ["groups" => ["group1" => $group1, "group2" => $group2], "polymers" => array_values($polymers), "links" => $links];
 }
 /**
  * 大屏滚动性能指标信息
  * @return string
  */
 public static function getLastPreDatas()
 {
     $ips = DeviceIpfilter::getIdsByType(ViewTemplate::TYPE_BUILD);
     $rows = (new Query())->from("device_task_summary a")->innerJoin("device_info b", "a.devId = b.id")->where(["b.ip" => $ips])->select(["id" => "a.devId", "label" => "b.label", "ip" => "b.ip", "key" => "a.taskName", "value" => "a.currentValue"])->groupBy("a.devId,a.taskId")->orderBy("a.devId asc,a.instId desc")->all();
     $data = [];
     foreach ($rows as $row) {
         $deviceId = $row["id"];
         if (!isset($data[$deviceId])) {
             $data[$deviceId] = [];
             $data[$deviceId][] = $row["label"] . '(' . $row["ip"] . ')';
         }
         $data[$deviceId][] = [$row["key"], $row["value"]];
     }
     $html = [];
     foreach ($data as $id => $item) {
         $table = [];
         $table[] = '<table>';
         $table[] = '<tr><th colspan="2">' . $item[0] . '</th></tr>';
         foreach ($item as $i => $d) {
             if ($i == 0) {
                 continue;
             }
             $table[] = '<tr><th>' . $d[0] . '</th><td>' . $d[1] . '</td></tr>';
         }
         $table[] = '</table>';
         $html[] = implode("\n", $table);
     }
     //return implode('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',$html);
     return '<li>' . implode('</li><li>', $html) . '</li>';
 }
 /**
  * Lists all DeviceInfo models.
  * @return mixed
  */
 public function actionIndex()
 {
     $ips = DeviceInfo::find()->where(["categoryId" => "1001"])->select("ip")->column();
     $ips = array_merge($ips, DeviceIpfilter::getIdsByType(DeviceIpfilter::TYPE_POLYMER));
     $searchModel = new DeviceInfoSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $ips);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
 public static function getDeviceList()
 {
     $result = [];
     $filterIps = DeviceIpfilter::getIdsByType(DeviceIpfilter::TYPE_WLAN);
     $rows = self::find()->with("category")->where(["ip" => $filterIps])->orderBy("ip asc")->asArray()->all();
     foreach ($rows as $row) {
         $type = $row["category"]["node_group"];
         if (!isset($result[$type])) {
             $result[$type] = [];
         }
         $result[$type][] = ["id" => $row["id"], "label" => $row["ip"]];
     }
     return $result;
 }
 /**
  * 获取Echarts 和弦图数据
  */
 public static function getEData($id1, $id2)
 {
     $links = [];
     $nodes = WirelessDeviceInfo::find()->where(["id" => [$id1, $id2]])->select(["id", "name" => "label"])->asArray()->all();
     /*
             array_walk($nodes,function(&$val,$key,$id1){
                 $nodeStyle= [];
                if($val["id"]== $id1){
                    $nodeStyle['normal'] = [
                        'color' => 'green'
                    ];
                }else{
                    $nodeStyle['normal'] = [
                        //'color' => '#45d3c9'
                        'color' => 'green'
                    ];
                }
                 $val["itemStyle"] = $nodeStyle;
             },$id1);
     */
     $filterIds = DeviceIpfilter::find()->where(["type_id" => DeviceIpfilter::TYPE_WIRELESS])->select("ip")->column();
     $lefts = (new Query())->from('wireless_device_link a')->leftJoin("wireless_device_info b", "a.leftDevice = b.id")->where(['and', ["a.rightDevice" => [$id1, $id2], "b.ip" => $filterIds], ["not", ["a.leftDevice" => [$id1, $id2]]]])->select(["leftDevice", "rightDevice", "name" => "b.ip", "id" => "b.id"])->all();
     $rows = (new Query())->from('wireless_device_link a')->leftJoin("wireless_device_info b", "a.rightDevice = b.id")->where(["and", ["a.leftDevice" => [$id1, $id2], "b.ip" => $filterIds], ["not", ["a.rightDevice" => [$id1, $id2]]]])->select(["leftDevice", "rightDevice", "name" => "b.ip", "id" => "b.id"])->all();
     $rows = array_merge($lefts, $rows);
     $tmp = ArrayHelper::map($nodes, "id", "name");
     foreach ($rows as $row) {
         $nodes[] = ["id" => $row["id"], "name" => $row["name"]];
         if (isset($tmp[$row["leftDevice"]])) {
             $source = $tmp[$row["leftDevice"]];
             $target = $row["name"];
         } else {
             $source = $tmp[$row["rightDevice"]];
             $target = $row["name"];
         }
         if ($row['leftDevice'] == $id1 || $row["rightDevice"] == $id1) {
             $color = 'green';
         } else {
             $color = '#45d3c9';
         }
         $links[] = ['source' => $source, 'target' => $target, 'weight' => 1, 'itemStyle' => ['normal' => ['color' => $color, 'width' => 2]]];
         $links[] = ['source' => $target, 'target' => $source, 'weight' => 0.9, 'itemStyle' => ['normal' => ['color' => $color, 'width' => 2]]];
     }
     return ["nodes" => $nodes, "links" => $links];
 }