Exemplo n.º 1
0
 /**
  * 
  * @return \yii\data\ActiveDataProvider
  */
 public static function findTraceLogByAppId()
 {
     $p_get = \Yii::$app->request->get();
     if (!$p_get['id']) {
         $p_get['id'] = 1;
     }
     $model = new TraceLog();
     $dataProvider = new ActiveDataProvider(['query' => $model->find()->where("ApplicationId=:appid", [":appid" => $p_get['id']]), 'pagination' => ['pagesize' => 20]]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 public function search($params)
 {
     $query = TraceLog::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     if (isset($params['id'])) {
         $query->andWhere(['ApplicationId' => $params['id']]);
     }
     if (isset($params['TraceLogSearch']['start_date']) && !empty($params['TraceLogSearch']['start_date'])) {
         $query->andWhere(" AddDate>=:start_date", [':start_date' => $params['TraceLogSearch']['start_date']]);
     }
     if (isset($params['TraceLogSearch']['end_date']) && !empty($params['TraceLogSearch']['end_date'])) {
         $query->andWhere(" AddDate<=:end_date", [':end_date' => $params['TraceLogSearch']['end_date']]);
     }
     if (isset($params['TraceLogSearch']['Parameter']) && !empty($params['TraceLogSearch']['Parameter'])) {
         $query->andWhere(['like', 'Parameter', $params['TraceLogSearch']['Parameter']]);
     }
     if (isset($params['TraceLogSearch']['Method']) && !empty($params['TraceLogSearch']['Method'])) {
         $query->andWhere(['like', 'Method', $params['TraceLogSearch']['Method']]);
     }
     $query->orderBy('AddDate desc ');
     return $dataProvider;
 }
Exemplo n.º 3
0
 public function search($params)
 {
     $this->load($params);
     $query = TraceLog::find();
     if (isset($params['TraceLogSearch']['start_date']) && !empty($params['TraceLogSearch']['start_date'])) {
         $data = date("Ym", strtotime($params['TraceLogSearch']['start_date']));
         $nowdata = date("Ym");
         if ($data < $nowdata && $data > '201608') {
             TraceLog::$tablename = 'TraceLog_' . $data;
         }
         $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20]]);
     } else {
         $rownums = \Yii::$app->db->createCommand("select TABLE_ROWS nums from information_schema.TABLES where TABLE_SCHEMA='Tuandai_Log' and TABLE_NAME='TraceLog'")->queryOne();
         $dataProvider = new ActiveDataProvider(['query' => $query, 'totalCount' => (int) $rownums['nums'], 'pagination' => ['pageSize' => 20]]);
     }
     //print_r($rownums['nums']);exit;
     //$values = $params['TraceLogSearch'];
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['ApplicationId' => $this->ApplicationId]);
     $query->andFilterWhere(['>', 'AddDate', $this->start_date]);
     $query->andFilterWhere(['<', 'AddDate', $this->end_date]);
     $query->andFilterWhere(['like', 'Parameter', $this->Parameter]);
     $query->andFilterWhere(['like', 'Method', $this->Method]);
     $query->orderBy('AddDate desc ');
     return $dataProvider;
 }
Exemplo n.º 4
0
 /**
  * 错误类型
  * @param bool $isReturnData
  * @return array
  */
 public static function getTraceCategory($isReturnData = true)
 {
     if ($isReturnData) {
         //统计表数据
         $appNameTotal = ApplicateName::find()->select("id,appname,logtotal,lastupdatetime")->where(['logtype' => 1])->asArray()->all();
         if ($appNameTotal) {
             foreach ($appNameTotal as $oneAppValue) {
                 if (empty($oneAppValue['lastupdatetime'])) {
                     $oneAppValue['lateupdatetime'] = date('Y-m-d H:i:s');
                 }
                 #获得最新统计数据
                 $nums = TraceLog::find()->where('ApplicationId=:appid AND AddDate>=:addDate', [':appid' => $oneAppValue['appname'], ':addDate' => $oneAppValue['lastupdatetime']])->count();
                 #更新当前最新统计
                 $updatenums = $oneAppValue['logtotal'] + $nums;
                 $lastupdatetime = date('Y-m-d H:i:s');
                 ApplicateName::updateAll(['logtotal' => $updatenums, 'lastupdatetime' => $lastupdatetime], 'id=:id', [':id' => $oneAppValue['id']]);
             }
             $appname_list = ArrayHelper::map($appNameTotal, 'logtotal', 'appname');
         }
         #获得没有统计在ApplicateName里的错误信息
         #由于有自动任务的处理所以每次更新的时候以前两天的数据再统计一次不存在的数据就可以了,以前两天为了有个时间宽度作保证
         $lastvaluetime = date('Y-m-d H:i:s', strtotime('-1 day'));
         if ($appname_list) {
             $listString = implode("','", $appname_list);
             $listString = "'" . $listString . "'";
             $sql = "insert into ApplicateName(`appname`,`newname`,`logtotal`,`logtype`,`lastupdatetime`) select ApplicationId,ApplicationId,count(*),1,now() from TraceLog where ApplicationId not in({$listString}) AND AddDate>='{$lastvaluetime}' group by ApplicationId";
             \Yii::$app->db->createCommand($sql)->execute();
         }
         //重新获取TraceLog的统计数据
         $error_query = new Query();
         $error_query->select("logtotal as total,appname as ApplicationId")->from("ApplicateName")->where("logtype=1")->groupBy("appname");
         $error_count_lists = $error_query->all();
         $error_count_list = ArrayHelper::map($error_count_lists, 'ApplicationId', 'total');
         //$total['name'] = '跟踪日志列表';
         arsort($error_count_list);
         foreach ($error_count_list as $k => $v) {
             $category[] = trim($k);
             $total['data'][] = floatval($v);
         }
         return ['category' => $category, 'series' => [$total]];
     } else {
         $ApplicationIds = ApplicateName::find()->select('appname as ApplicationId')->where(['logtype' => 1])->asArray()->all();
         foreach ($ApplicationIds as $k => $v) {
             $category[] = trim($v['ApplicationId']);
         }
         if (!$isReturnData) {
             return $category;
         }
     }
 }