/**
  * Lists all DcmdTaskTemplate models.
  * @return mixed
  */
 public function actionIndex()
 {
     $params = array();
     if (array_key_exists('DcmdTaskTemplateSearch', Yii::$app->request->queryParams)) {
         $params['DcmdTaskTemplateSearch'] = Yii::$app->request->queryParams['DcmdTaskTemplateSearch'];
         if ($params['DcmdTaskTemplateSearch']['app_id'] == "") {
             $params['DcmdTaskTemplateSearch']['svr_id'] = "";
         }
     }
     ///$searchModel = new DcmdTaskTemplateSearch();
     ///$dataProvider = $searchModel->search($params);
     $task_cmd = array();
     $query = DcmdTaskCmd::find()->asArray()->all();
     if ($query) {
         foreach ($query as $item) {
             $task_cmd[$item['task_cmd_id']] = $item['task_cmd'];
         }
     }
     $app = array();
     $ap_con = "";
     if (Yii::$app->user->getIdentity()->admin != 1) {
         $app_con = "svr_gid in (0";
         $query = DcmdUserGroup::find()->andWhere(['uid' => Yii::$app->user->getId()])->asArray()->all();
         if ($query) {
             foreach ($query as $item) {
                 $app_con .= "," . $item['gid'];
             }
         }
         $app_con .= ")";
         $query = DcmdApp::find()->where($app_con)->asArray()->all();
         $ap_con = "app_id in (0";
         foreach ($query as $item) {
             $ap_con .= "," . $item['app_id'];
         }
         $ap_con .= ")";
     }
     $query = DcmdApp::find()->andWhere($ap_con)->asArray()->all();
     if ($query) {
         foreach ($query as $item) {
             $app[$item['app_id']] = $item['app_name'];
         }
     }
     $service = array();
     if (array_key_exists('DcmdTaskTemplateSearch', $params) && array_key_exists('app_id', $params['DcmdTaskTemplateSearch'])) {
         $query = DcmdService::find()->andWhere(['app_id' => $params['DcmdTaskTemplateSearch']['app_id']])->asArray()->all();
         if ($query) {
             foreach ($query as $item) {
                 $service[$item['svr_id']] = $item['svr_name'];
             }
         }
         if (!array_key_exists($params['DcmdTaskTemplateSearch']['svr_id'], $service)) {
             $params['DcmdTaskTemplateSearch']['svr_id'] = "";
         }
     }
     $searchModel = new DcmdTaskTemplateSearch();
     $dataProvider = $searchModel->search($params);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'task_cmd' => $task_cmd, 'app' => $app, 'service' => $service]);
 }
 /**
  * Displays a single DcmdService model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     ///$query = DcmdServicePool::find()->andWhere(['svr_id'=>$id]);
     $searchModel = new DcmdServicePoolSearch();
     $con = array();
     $con['DcmdServicePoolSearch'] = array('svr_id' => $id);
     if (array_key_exists('DcmdServicePoolSearch', Yii::$app->request->queryParams)) {
         $con = array_merge($con, Yii::$app->request->queryParams);
     }
     $con['DcmdServicePoolSearch']['svr_id'] = $id;
     $dataProvider = $searchModel->search($con);
     ///处理图片
     $service = DcmdService::findOne($id);
     $base_path = dirname(__DIR__) . "/web/app_image/";
     $query = DcmdServiceArchDiagram::find()->andWhere(['svr_id' => $id, 'app_id' => $service->app_id])->asArray()->all();
     foreach ($query as $item) {
         $img_path = $base_path . "svr_" . $item['arch_name'] . '_' . $item['svr_id'] . '.jpg';
         if (file_exists($img_path)) {
             continue;
         }
         $fp = fopen($img_path, 'wb') or die("Open file {$img_path} fail!");
         fwrite($fp, stripslashes($item['diagram']));
         fclose($fp);
     }
     $imageSearch = new DcmdServiceArchDiagramSearch();
     $imageProvider = $imageSearch->search(array('DcmdServiceArchDiagramSearch' => array('app_id' => $service->app_id, 'svr_id' => $id)));
     ///获取任务模版列表
     $tmpt_searchModel = new DcmdTaskTemplateSearch();
     $params["DcmdTaskTemplateSearch"]["svr_id"] = $id;
     $taskTemptDataProvider = $tmpt_searchModel->search($params, 1000);
     return $this->render('view', ['model' => $this->findModel($id), 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'imageProvider' => $imageProvider, 'taskTemptDataProvider' => $taskTemptDataProvider]);
 }