示例#1
0
 /**
  * 
  * @return \yii\data\ActiveDataProvider
  */
 public static function findErrorLogByAppId()
 {
     $p_get = \Yii::$app->request->get();
     if (!$p_get['id']) {
         $p_get['id'] = 1;
     }
     $model = new ErrorLog();
     $dataProvider = new ActiveDataProvider(['query' => $model->find()->where("ApplicationId=:appid", [":appid" => $p_get['id']]), 'pagination' => ['pagesize' => 20]]);
     return $dataProvider;
 }
示例#2
0
 public function search($params)
 {
     $query = ErrorLog::find();
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     if (isset($params['id'])) {
         $query->andWhere(['ApplicationId' => $params['id']]);
     }
     if (isset($params['ErrorLogSearch']['start_date']) && !empty($params['ErrorLogSearch']['start_date'])) {
         $query->andWhere(" AddDate>=:start_date", [':start_date' => $params['ErrorLogSearch']['start_date']]);
     }
     if (isset($params['ErrorLogSearch']['end_date']) && !empty($params['ErrorLogSearch']['end_date'])) {
         $query->andWhere(" AddDate<=:end_date", [':end_date' => $params['ErrorLogSearch']['end_date']]);
     }
     if (isset($params['ErrorLogSearch']['Parameter']) && !empty($params['ErrorLogSearch']['Parameter'])) {
         $query->andWhere(['like', 'Parameter', $params['ErrorLogSearch']['Parameter']]);
     }
     if (isset($params['ErrorLogSearch']['Method']) && !empty($params['ErrorLogSearch']['Method'])) {
         $query->andWhere(['like', 'Method', $params['ErrorLogSearch']['Method']]);
     }
     $query->orderBy('AddDate desc ');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     return $dataProvider;
 }
示例#3
0
 public function search($params)
 {
     $query = ErrorLog::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['AddDate' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     if ($this->ApplicationId != "all") {
         $query->andFilterWhere(['ApplicationId' => $this->ApplicationId]);
     }
     $query->andFilterWhere(['>=', 'AddDate', $this->start_date]);
     $query->andFilterWhere(['<=', 'AddDate', $this->end_date]);
     $query->andFilterWhere(['like', 'Parameter', $this->Parameter])->andFilterWhere(['like', 'Method', $this->Method]);
     return $dataProvider;
 }
 public static function findAllLineEcharts()
 {
     #获得所有错误类型
     $allErrorsType = \common\models\ApplicateName::find()->asArray()->select('appname')->where('logtype=0')->all();
     foreach ($allErrorsType as $oneDate) {
         $fitAllErrorsType[] = $oneDate['appname'];
     }
     $whereString = implode(',', $fitAllErrorsType);
     #获得最近五天的数据
     $fitDate = date('Y-m-d 00:00:00');
     $after5Date = date('Y-m-d 00:00:00', strtotime('-5 day', strtotime($fitDate)));
     $fiveDateLists = \common\models\ErrorLogDay::find()->where(["ApplicationId" => $fitAllErrorsType])->andWhere('Date>:sd AND Date<=:ed', [':sd' => $after5Date, ':ed' => $fitDate])->asArray()->orderBy("Date desc")->All();
     //如果为空,就取最后一个时间,以最后一个时间点为准
     //标记是否为最新的数据
     $isToday = true;
     if (empty($fiveDateLists)) {
         $lastDay = \common\models\ErrorLogDay::find()->orderBy("Id desc")->one();
         if (empty($lastDay)) {
             return [];
         }
         $fitDate = date('Y-m-d 00:00:00', strtotime($lastDay->Date));
         $after5Date = date('Y-m-d 00:00:00', strtotime('-5 day', strtotime($fitDate)));
         $fiveDateLists = \common\models\ErrorLogDay::find()->where(["ApplicationId" => $fitAllErrorsType])->andWhere('Date>:sd AND Date<=:ed', [':sd' => $after5Date, ':ed' => $fitDate])->asArray()->orderBy("Date desc")->All();
         if (empty($fiveDateLists)) {
             return [];
         }
         $isToday = false;
     }
     #//开始处理这五天的数据
     $fitdates = [];
     foreach ($fiveDateLists as $key => $oneDate) {
         //处理成2016-5-6形式的日期
         $toIntDay = date("Y-m-d", strtotime($oneDate['Date']));
         $fitdates[$oneDate['ApplicationId']][$toIntDay] = floatval($oneDate['Number']);
     }
     #对处理了的数据再处理一遍,不存在的数据加上0
     $outCharts = [];
     $outCharts['categories'] = [];
     $outCharts['series'] = [];
     foreach ($fitdates as $key => $oneDate) {
         $start_date = date('Y-m-d', strtotime($fitDate));
         for ($i = 1; $i <= 5; $i++) {
             if (!in_array($start_date, $outCharts['categories'])) {
                 $outCharts['categories'][] = $start_date;
             }
             if (!isset($oneDate[$start_date])) {
                 $fitdates[$key][$start_date] = 0;
             }
             $start_date = date('Y-m-d', strtotime("-1 day", strtotime($start_date)));
         }
         ksort($fitdates[$key]);
     }
     //处理一个上面显示的数据
     foreach ($fitdates as $key => $oneDate) {
         $outCharts['series'][] = ['name' => $key, 'type' => 'line', 'smooth' => true, 'data' => array_values($oneDate)];
         $outCharts['toptip'][] = $key;
     }
     $outCharts['categories'] = array_reverse($outCharts['categories']);
     //标记是否为今天的数据,如果是今天的数据,那么对今天的数据进行实时统计处理
     if ($isToday) {
         $fitDate = date('Y-m-d 00:00:00');
         $after1Date = date('Y-m-d 00:00:00', strtotime('+1 day', strtotime($fitDate)));
         //因为上面已经做了判断,所以今天的数据肯定会存在
         //获得今天最新的数据
         $errorstatusLists = \common\models\ErrorLog::find()->select("count(*) nums,ApplicationId")->where('AddDate>:sd AND AddDate<=:ed', [':sd' => $fitDate, ':ed' => $after1Date])->groupBy('ApplicationId')->indexBy('ApplicationId')->asArray()->all();
         //对上面的数组进行处理
         foreach ($outCharts['series'] as $key => $oneVaue) {
             //把最近一个元素推出
             array_pop($outCharts['series'][$key]['data']);
             //推入一个新元素
             //如果没有这个数组就推入一个0的数据
             if (!isset($errorstatusLists[$oneVaue['name']]['nums'])) {
                 array_push($outCharts['series'][$key]['data'], 0);
             } else {
                 array_push($outCharts['series'][$key]['data'], floatval($errorstatusLists[$oneVaue['name']]['nums']));
             }
         }
     }
     return $outCharts;
 }
示例#5
0
 public static function getYearList()
 {
     //获取错误日志最先的时间
     $errorlog = ErrorLog::find()->where("AddDate>0")->orderBy("AddDate asc")->limit(1)->one();
     $add_date = $errorlog->AddDate;
     $str_year = date("Y", strtotime($add_date));
     $cur_year = date("Y");
     $cur_month = date("n");
     $diff = $cur_year - $str_year + 1;
     $year = $cur_year;
     $item = array();
     $key = 0;
     for ($i = 0; $i < $diff; $i++) {
         if ($i == 0) {
             if ($cur_month > 6) {
                 $item[$key] = $year . "下半年";
                 $key -= 1;
             }
         } else {
             $item[$key] = $year . "下半年";
             $key -= 1;
         }
         $item[$key] = $year . "上半年";
         $key -= 1;
         $year = $year - 1;
     }
     return $item;
 }