public function getMacroVariables()
 {
     $micros = [];
     $model = new DeviceAlarm();
     foreach (self::$template_fields as $micro => $field) {
         $micros[$micro] = $model->getAttributeLabel($field);
     }
     return $micros;
 }
 public function actionAlarmFindBak()
 {
     $configs = SmsConfig::find()->all();
     foreach ($configs as $config) {
         $LastId = Yii::$app->cache->get("config_last_id_" . $config->id);
         if (!$LastId) {
             $LastId = 0;
         }
         $phones = implode(',', array_filter($this->getPhoneNum($config->receivers)));
         if (empty($phones)) {
             continue;
         }
         $condition = $config->alarmCondition;
         $alarms = DeviceAlarm::find()->where(['and', 'serial_num > ' . $LastId, 'faultTime>=' . strtotime($config->update_time)])->andWhere($condition)->select(array_merge(SmsTemplate::$template_fields, ["serial_num" => "serial_num"]))->asArray()->all();
         $template = $this->getTemplate($config->smsTemplate_id);
         foreach ($alarms as $alarm) {
             $model = new SmsList();
             $model->receivers = $phones;
             $model->content = strtr($template, $alarm);
             if (!$model->save()) {
                 Yii::error(print_r($model->getErrors(), true), 'sms/find');
             }
             if ($alarm["serial_num"] > $LastId) {
                 $LastId = $alarm["serial_num"];
             }
         }
         Yii::$app->cache->set("config_last_id_" . $config->id, $LastId);
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = DeviceAlarm::find();
     $query->andWhere(['not', ["deviceId" => 0]]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ["pageSize" => 10]]);
     $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(['id' => $this->id, 'deviceId' => $this->deviceId, 'alarmLevel' => $this->alarmLevel, 'alarmCategory' => $this->alarmCategory, 'faultTime' => $this->faultTime, 'recTime' => $this->recTime, 'recStatus' => $this->recStatus, 'ackTime' => $this->ackTime, 'ackStatus' => $this->ackStatus, 'somState' => $this->somState, 'defineType' => $this->defineType, 'customAlarmLevel' => $this->customAlarmLevel, 'update_time' => $this->update_time, 'specificId' => $this->specificId, 'originalType' => $this->originalType]);
     $query->andFilterWhere(['like', 'OID', $this->OID])->andFilterWhere(['like', 'originalTypeDesc', $this->originalTypeDesc])->andFilterWhere(['like', 'deviceIp', $this->deviceIp])->andFilterWhere(['like', 'deviceName', $this->deviceName])->andFilterWhere(['like', 'alarmLevelDesc', $this->alarmLevelDesc])->andFilterWhere(['like', 'alarmCategoryDesc', $this->alarmCategoryDesc])->andFilterWhere(['like', 'faultTimeDesc', $this->faultTimeDesc])->andFilterWhere(['like', 'recTimeDesc', $this->recTimeDesc])->andFilterWhere(['like', 'recStatusDesc', $this->recStatusDesc])->andFilterWhere(['like', 'recUserName', $this->recUserName])->andFilterWhere(['like', 'ackTimeDesc', $this->ackTimeDesc])->andFilterWhere(['like', 'ackStatusDesc', $this->ackStatusDesc])->andFilterWhere(['like', 'ackUserName', $this->ackUserName])->andFilterWhere(['like', 'alarmDesc', $this->alarmDesc])->andFilterWhere(['like', 'remark', $this->remark])->andFilterWhere(['like', 'eventName', $this->eventName])->andFilterWhere(['like', 'reason', $this->reason]);
     return $dataProvider;
 }
 /**
  * 设备详情页面
  */
 public function actionDetail($id)
 {
     $this->layout = '//main';
     $model = $this->findModel($id);
     //$lists = DeviceTask::getPrefList($id);
     $perfQuery = DeviceTaskSummary::find()->where(["and", ["devId" => $id], ["not", ["taskId" => [1, 5]]]])->orderBy("instId desc")->groupBy('taskId');
     $lists = new ActiveDataProvider(['query' => $perfQuery, 'pagination' => ["pageSize" => 10]]);
     $query = DeviceAlarm::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ["pageSize" => 10]]);
     $query->where(["deviceId" => $id])->orderBy("faultTime desc")->limit(5);
     $interQuery = DeviceTaskSummary::find()->where(['devId' => $id, "taskId" => [1, 5]])->orderBy("instId desc")->groupBy('taskId,objIndex');
     $interfaceProvider = new ActiveDataProvider(['query' => $interQuery, 'pagination' => ["pageSize" => 10]]);
     return $this->render("detail", ['id' => $id, "model" => $model, "perflists" => $lists, "alarmProvider" => $dataProvider, "interfaceProvider" => $interfaceProvider]);
 }
 /**
  * 图表数据
  */
 public function actionAjaxChartData()
 {
     $deviceData = DeviceInfo::getDeviceCountStat();
     $alarmTypes = DeviceAlarm::getTypeChartData();
     $alarmLevels = DeviceAlarm::getLevelChartData();
     return json_encode(["device" => $deviceData, "alarmType" => $alarmTypes, "alarmLevel" => $alarmLevels]);
 }
 /**
  * Finds the DeviceAlarm model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return DeviceAlarm the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id, $type = null)
 {
     if ($type == 2 && ($model = WirelessDeviceAlarm::findOne($id)) !== null) {
         return $model;
     } elseif (($model = DeviceAlarm::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }