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]; }
/** * 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; }
/** * 有限网络(plane) */ public function actionWlanPlane() { $lists = DeviceInfo::getDeviceList(ViewTemplate::TYPE_WLAN_PLANE); $selected = ViewTemplate::getTempateSet(ViewTemplate::TYPE_WLAN_PLANE); $categorys = ArrayHelper::map(DeviceCategory::find()->all(), "node_group", "name"); return $this->render('editorWlanPlane', ["deviceList" => $lists, "selected" => Json::encode($selected), "type" => ViewTemplate::TYPE_WLAN_PLANE, "categorys" => $categorys]); }
/** * Finds the DeviceInfo model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return DeviceInfo the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id, $type = 2) { if (($model = DeviceInfo::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
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]; }
/** * 图表数据 */ public function actionAjaxChartData() { $deviceData = DeviceInfo::getDeviceCountStat(); $alarmTypes = DeviceAlarm::getTypeChartData(); $alarmLevels = DeviceAlarm::getLevelChartData(); return json_encode(["device" => $deviceData, "alarmType" => $alarmTypes, "alarmLevel" => $alarmLevels]); }