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]; }
/** * 获取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]; }