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];
 }
 /**
  * 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]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @param array $ips 过滤IP列表
  *
  * @return ActiveDataProvider
  */
 public function search($params, $ips = [])
 {
     $query = DeviceInfo::find();
     $query->joinWith(['series', 'model']);
     // $query->andFilterWhere(["ip"=>$ips]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['device_info.id' => $this->id, 'status' => $this->status, 'lastPoll' => $this->lastPoll, 'categoryId' => $this->categoryId, 'supportPing' => $this->supportPing, 'webMgrPort' => $this->webMgrPort, 'configPollTime' => $this->configPollTime, 'statePollTime' => $this->statePollTime, 'positionX' => $this->positionX, 'positionY' => $this->positionY, 'symbolType' => $this->symbolType, 'phyCreateTime' => $this->phyCreateTime, 'update_time' => $this->update_time]);
     $query->andFilterWhere(['like', 'label', $this->label])->andFilterWhere(['like', 'ip', $this->ip])->andFilterWhere(['like', 'mask', $this->mask])->andFilterWhere(['like', 'sysName', $this->sysName])->andFilterWhere(['like', 'location', $this->location])->andFilterWhere(['like', 'sysOid', $this->sysOid])->andFilterWhere(['like', 'runtime', $this->runtime])->andFilterWhere(['like', 'typeName', $this->typeName])->andFilterWhere(['like', 'symbolDesc', $this->symbolDesc])->andFilterWhere(['like', 'mac', $this->mac])->andFilterWhere(['like', 'phyName', $this->phyName])->andFilterWhere(['like', 'device_model.name', $this->model])->andFilterWhere(['like', 'device_series.name', $this->series])->andFilterWhere(['like', 'interfaces', $this->interfaces])->andFilterWhere(['like', 'category', $this->category]);
     return $dataProvider;
 }
 /**
  * 获取区域内设备
  */
 public static function getAreaDeviceData($area, $type = 2)
 {
     $template = self::find()->where(["type" => $type, "areaId" => $area])->select("device_id,attributes")->asArray()->all();
     $data = ArrayHelper::map($template, 'device_id', "attributes");
     $deviceIds = array_keys($data);
     //var_dump($deviceIds);
     if ($type == 3) {
         //无线设备
         $rows = WirelessDeviceInfo::find()->with(["category"])->where(["id" => $deviceIds])->select("id,label,categoryId")->asArray()->all();
     } else {
         $rows = DeviceInfo::find()->with(["category"])->where(["id" => $deviceIds])->select("id,label,categoryId")->asArray()->all();
     }
     $result = [];
     foreach ($rows as $row) {
         //$pos = self::getPosition($data[$row["id"]]);
         $result[] = ["id" => $row["id"], "label" => $row["label"], "group" => isset($row["category"]) ? $row["category"]["node_group"] : ''];
     }
     return $result;
 }
 /**
  * 获取本地所有设备IP集合
  */
 private function getLocalDeviceIps()
 {
     $query = DeviceInfo::find()->select('ip')->asArray()->all();
     return $query;
 }
 /**
  * 设备提示信息
  * @param $deviceId
  * @return string
  */
 protected function getTip($deviceId)
 {
     $this->layout = false;
     $device = DeviceInfo::find()->with(["type", "model"])->where(["id" => $deviceId])->one();
     if (!$device) {
         return "设备未找到";
     }
     $deviceConfig = ArrayHelper::map(InfoConfig::getTipConfig(1), "key", "value");
     $perfConfig = ArrayHelper::map(InfoConfig::getTipConfig(2), "key", "value");
     $perfData = DeviceTaskSummary::find()->where(["taskId" => array_values($perfConfig), "devId" => $deviceId])->select(["taskId", "currentValue"])->groupBy("taskId")->asArray()->all();
     $perfData = ArrayHelper::map($perfData, "taskId", "currentValue");
     return $this->render("tip", ["model" => $device, "deviceConfig" => $deviceConfig, "perfConfig" => $perfConfig, "perfData" => $perfData]);
 }
 public static function getDeviceCountStat()
 {
     // $ips = DeviceIpfilter::getIdsByType(DeviceIpfilter::TYPE_BUILD);
     $rows = DeviceInfo::find()->select(["status", "count" => "count(id)"])->groupBy("status")->asArray()->all();
     $rows = ArrayHelper::map($rows, "status", "count");
     $markData = [];
     $categories = [];
     $data = [];
     foreach (self::$status_config as $key => $config) {
         $value = isset($rows[$key]) ? (int) $rows[$key] : 0;
         $markData[] = ["name" => $config[0], "value" => $value];
         $categories[] = $config[0];
         $data[] = $value;
     }
     $series = [["name" => "数量", "data" => $data, "dataLabels" => ["enabled" => true, "align" => "top"]]];
     return ["markData" => $markData, "data" => $data, "categories" => $categories];
 }