//WidgetModel widgetModel, int? interval, string startDate, string endDate
        public override async Task<ResultValue> GetSystemData(Dictionary<string, object> parameterDictionary)
        {
            try
            {
                var widgetModel = parameterDictionary["WidgetModel"] as WidgetModel;
                var startDate = parameterDictionary["StartDate"].ToString();
                var endDate = parameterDictionary["EndDate"].ToString();
                var interval = Convert.ToInt32(parameterDictionary["Interval"].ToString());

                var siteRealtimeDataResult = await SiteRealtimeService.GetRealtimeData(widgetModel.EnHeader, widgetModel.DataType, widgetModel.TableName, startDate, endDate, widgetModel.DataCount.ToString(), interval);
                if(siteRealtimeDataResult != null)
                {
                    SystemData = new ResultValue
                    {
                        Key = string.Empty,
                        Value = JsonConvert.SerializeObject(siteRealtimeDataResult)
                    };
                }
            }
            catch(Exception ex)
            {
                ShowMessage.Show("查询数据出错");
                LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "Failed to GetSystemData", ex);
            }
            finally
            {
                if(LogHelper.LogLevel == LogLevelEnum.Debug || LogHelper.LogLevel == LogLevelEnum.Info)
                {
                    LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "GetSystemData", null);
                }
            }

            return SystemData;
        }
示例#2
0
        public async Task<ResultValue> GetSponsorData(string programName, string startDate, string endDate, string dataFilterCount, string dataOrderBy)
        {
            if(string.IsNullOrEmpty(dataOrderBy))
            {
                dataOrderBy = ",";
            }

            var request = new RestRequest(string.Format(SponsorResource.SponsorDataRequest, programName, startDate, endDate, dataFilterCount, dataOrderBy), Method.POST);

            var data = new ResultValue();
            var response = await this.client.ExecutePostTaskAsync<ResultValue>(request);
            if (((RestResponseBase)(response)).StatusCode == HttpStatusCode.OK) //200
            {
                data = response.Data;
            }
            else if (((RestResponseBase)(response)).StatusCode == HttpStatusCode.NotFound) //404
            {
                ShowMessage.Show("访问404错误");
            }
            else if ((int)response.StatusCode == 422)
            {
                ShowMessage.Show("访问422错误");
            }
            else if (((RestResponseBase)(response)).StatusCode == HttpStatusCode.InternalServerError) //500
            {
                ShowMessage.Show("访问500错误");
            }
            else
            {
                ShowMessage.Show("未知错误");
            }

            return data;
        }
        //WidgetModel widgetModel, int? interval, string startDate, string endDate
        public override async Task<ResultValue> GetSystemData(Dictionary<string, object> parameterDictionary)
        {
            try
            {
                var widgetModel = parameterDictionary["WidgetModel"] as WidgetModel;
                var startDate = parameterDictionary["StartDate"].ToString();
                var endDate = parameterDictionary["EndDate"].ToString();
                if (widgetModel == null)
                {
                    return null;
                }


                // if TA has been configured
                if (widgetModel.Filter !=null)
                {
                    var taInfo = JsonConvert.DeserializeObject<TargetAudienceInfo>(widgetModel.Filter);
                    if (taInfo != null)
                    {
                        var clientId = parameterDictionary["ClientId"].ToString();
                        var programsName = await this.GetProgramsName(clientId, widgetModel.TableName);
                        //var programsName = new string[]{"女神新装","偶滴歌神啊"};
                        //var programsName = new string[]{"女神新装"};
                        //var programsName = new string[] { "偶滴歌神啊" };
                        var taDataSet = await TargetAudienceService.Singleton.GetTaData(programsName, endDate, taInfo);
                        var taData = TargetAudienceService.Singleton.ConvertDataSet(taDataSet, parameterDictionary);
                        if (taDataSet != null)
                        {
                            var data = JsonConvert.SerializeObject(taData);
                            var resultValue = new ResultValue();
                            resultValue.Value = data;
                        }

                        return null;
                    }
                }

                
                var sponsorData = await SponsorService.Singleton.GetSponsorData(widgetModel.TableName, startDate, endDate, widgetModel.DataCount.ToString(), widgetModel.DataOrderBy);
                SystemData = sponsorData;
                
            }
            catch(Exception ex)
            {
                ShowMessage.Show("查询数据出错");
                LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "Failed to GetSystemData", ex);
            }
            finally
            {
                if(LogHelper.LogLevel == LogLevelEnum.Debug || LogHelper.LogLevel == LogLevelEnum.Info)
                {
                    LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "GetSystemData", null);
                }
            }

            return SystemData;
        }
        public static async Task<ResultValue> GetSystemData(Dictionary<string, object> parameterDictionary)
        {
            var systemDataResult = new ResultValue();
            try
            {
                var dateType = parameterDictionary["DateType"].ToString();
                var brandType = parameterDictionary["BrandType"].ToString();
                var category = parameterDictionary["Category"] == null ? string.Empty : parameterDictionary["Category"].ToString();
                var category1 = string.Empty;
                var category2 = string.Empty;
                if(!string.IsNullOrEmpty(category))
                {
                    var categorys = category.Split(new[] { "*" }, StringSplitOptions.RemoveEmptyEntries);
                    category1 = categorys[0];
                    category2 = categorys.Count() == 2 ? categorys[1] : string.Empty;
                }

                var dimensions = parameterDictionary["Dimensions"] == null ? string.Empty : parameterDictionary["Dimensions"].ToString();
                var metrics = parameterDictionary["Metrics"].ToString();
                var benchmarkDataValue = await BenchmarkService.GetBenchmarkDatas(dateType, brandType, category1, category2, dimensions, metrics);

                if(((RestResponseBase)(benchmarkDataValue)).StatusCode == HttpStatusCode.OK) //200
                {
                    systemDataResult = benchmarkDataValue.Data;
                }
                else if(((RestResponseBase)(benchmarkDataValue)).StatusCode == HttpStatusCode.NotFound) //404
                {
                    ShowMessage.Show("访问404错误");
                }
                else if((int)benchmarkDataValue.StatusCode == 422)
                {
                    ShowMessage.Show("访问422错误");
                }
                else if(((RestResponseBase)(benchmarkDataValue)).StatusCode == HttpStatusCode.InternalServerError) //500
                {
                    ShowMessage.Show("访问500错误");
                }
                else
                {
                    ShowMessage.Show("未知错误");
                }
            }
            catch(Exception ex)
            {
                ShowMessage.Show("加载数据出错");
                LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "Failed to GetSystemData", ex);
            }
            finally
            {
                if(LogHelper.LogLevel == LogLevelEnum.Debug || LogHelper.LogLevel == LogLevelEnum.Info)
                {
                    LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "GetSystemData", null);
                }
            }

            return systemDataResult;
        }
        public static void BuildSystemData(int systemType, string dataType, ResultValue resultValue, string enHeader)
        {
            try
            {
                switch(systemType)
                {
                    case (int)SystemTypeEnum.SiteAnalysisReport:
                        SystemData = new ObservableCollection<SiteData>();
                        SystemDataList = JsonConvert.DeserializeObject<List<SiteData>>(resultValue.Value);
                        break;
                    case (int)SystemTypeEnum.SiteDataBank:

                        break;
                    case (int)SystemTypeEnum.SiteRealtime:
                        SystemData = new ObservableCollection<ISystemData>();
                        SystemDataList = SiteRealtimeType.GetSiteRealtimeData(dataType, resultValue.Value, enHeader);
                        break;
                    case (int)SystemTypeEnum.Sponsor:
                    case (int)SystemTypeEnum.Benchmark:
                        SystemData = new ObservableCollection<SponsorData>();
                        SystemDataList = JsonConvert.DeserializeObject<List<SponsorData>>(resultValue.Value);
                        break;
                    case (int)SystemTypeEnum.TrackAnalysisReport:
                        SystemData = new ObservableCollection<TrackAnalysisData>();
                        SystemDataList = JsonConvert.DeserializeObject<List<TrackAnalysisData>>(resultValue.Value);
                        break;
                    case (int)SystemTypeEnum.TrackDataBank:

                        break;
                    case (int)SystemTypeEnum.TrackRealtime:
                        SystemData = new ObservableCollection<TrackRealtimeData>();
                        SystemDataList = JsonConvert.DeserializeObject<List<TrackRealtimeData>>(resultValue.Value);
                        break;
                }
            }
            catch(Exception ex)
            {
                ShowMessage.Show("构建数据类型出错");
                LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "Failed to BuildSystemData", ex);
            }
            finally
            {
                if(LogHelper.LogLevel == LogLevelEnum.Debug || LogHelper.LogLevel == LogLevelEnum.Info)
                {
                    LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "BuildSystemData", null);
                }
            }
        }
        //WidgetModel widgetModel, int? interval, string startDate, string endDate
        public override async Task<ResultValue> GetSystemData(Dictionary<string, object> parameterDictionary)
        {
            try
            {
                var widgetModel = parameterDictionary["WidgetModel"] as WidgetModel;
                var startDate = parameterDictionary["StartDate"].ToString();
                var endDate = parameterDictionary["EndDate"].ToString();

                var trackRealtimeDataResult = await TrackRealtimeService.GetRealtimeData(widgetModel.TableName, startDate, endDate, widgetModel.Dimensions + "," + widgetModel.TimeDimensions, widgetModel.Metrics, widgetModel.DataCount.ToString(), widgetModel.DataOrderBy);
                if(trackRealtimeDataResult == null)
                {
                    SystemData = new ResultValue
                    {
                        Key = string.Empty,
                        Value = string.Empty
                    };
                }
                else
                {
                    var data = trackRealtimeDataResult;
                    SystemData = new ResultValue { Key = "", Value = JsonConvert.SerializeObject(data) };
                }
            }
            catch(Exception ex)
            {
                ShowMessage.Show("查询数据出错");
                LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "Failed to GetSystemData", ex);
            }
            finally
            {
                if(LogHelper.LogLevel == LogLevelEnum.Debug || LogHelper.LogLevel == LogLevelEnum.Info)
                {
                    LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "GetSystemData", null);
                }
            }

            return SystemData;
        }
        public static List<object> ConvertToChartData(WidgetModel widgetModel, ResultValue resultValue, List<MetricTypeModel> metricsCache)
        {
            var datas = new ObservableCollection<string>();
            var series = new ObservableCollection<MyReport>();
            var axisDic = new Dictionary<string, Tuple<string, string>>();
            var values = new List<decimal>();

            var metrics = widgetModel.Metrics.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            foreach(var metric in metrics)
            {
                var metricX = metricsCache.FirstOrDefault(m => m.SystemTypeId == widgetModel.SystemTypeId && m.EnName == metric);
                datas.Add(metricX.CnName);

                axisDic.Add(metric, new Tuple<string, string>(metricX.CnName, "Y"));
            }

            #region

            var label = string.Empty;
            switch(widgetModel.DataType)
            {
                case "1":
                    label = "所有节目";
                    break;
                case "2":
                    label = "指定节目";
                    break;
                case "3":
                    label = "节目类型";
                    break;
                case "4":
                    label = "赞助级别";
                    break;
                case "5":
                    label = "电视台";
                    break;
                case "6":
                    label = "视频网站自制";
                    break;
                case "7":
                    label = "品牌品类";
                    break;
            }

            switch(widgetModel.DateTypeId)
            {
                case 5:
                    label += "-本期";
                    break;
                case 6:
                    label += "-上期";
                    break;
                case 7:
                    label += "-历史";
                    break;
            }

            #endregion

            var report = new MyReport();
            report.Label = label;

            var data = new ObservableCollection<C1Data>();
            Type systemType = typeof(SponsorData);
            var resultX = JsonConvert.DeserializeObject<SponsorData>(resultValue.Value);

            foreach(var metric in metrics)
            {
                PropertyInfo mPropertyInfo = systemType.GetProperty(metric.Substring(0, 1).ToUpperInvariant() + metric.Substring(1, metric.Length - 1).TrimEnd());

                decimal value;
                if(mPropertyInfo.GetValue(resultX, null) == null)
                {
                    value = 0;
                }
                else
                {
                    if(mPropertyInfo.GetValue(resultX, null) is int)
                    {
                        value = Convert.ToInt32(mPropertyInfo.GetValue(resultX, null));
                    }
                    else if(mPropertyInfo.GetValue(resultX, null) is double || mPropertyInfo.GetValue(resultX, null) is decimal)
                    {
                        value = Convert.ToDecimal(mPropertyInfo.GetValue(resultX, null));
                    }
                    else
                    {
                        value = 0;
                    }
                }
                data.Add(new C1Data { Value = value });
                values.Add(value);
            }

            report.Data = data;
            series.Add(report);

            return new List<object> { datas, series, axisDic, values };
        }
        public static async Task<ResultValue> GetDataByCategorys1(string categorys1)
        {
            var categorys2ListResult = new ResultValue();
            try
            {
                var benchmarkTypeDataValue = await BenchmarkService.GetCategorys2Datas(categorys1);

                if(((RestResponseBase)(benchmarkTypeDataValue)).StatusCode == HttpStatusCode.OK) //200
                {
                    categorys2ListResult = benchmarkTypeDataValue.Data;
                }
                else if(((RestResponseBase)(benchmarkTypeDataValue)).StatusCode == HttpStatusCode.NotFound) //404
                {
                    ShowMessage.Show("访问404错误");
                }
                else if((int)benchmarkTypeDataValue.StatusCode == 422)
                {
                    ShowMessage.Show("访问422错误");
                }
                else if(((RestResponseBase)(benchmarkTypeDataValue)).StatusCode == HttpStatusCode.InternalServerError) //500
                {
                    ShowMessage.Show("访问500错误");
                }
                else
                {
                    ShowMessage.Show("未知错误");
                }
            }
            catch(Exception ex)
            {
                ShowMessage.Show("加载数据出错");
                LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "Failed to GetDataByType", ex);
            }
            finally
            {
                if(LogHelper.LogLevel == LogLevelEnum.Debug || LogHelper.LogLevel == LogLevelEnum.Info)
                {
                    LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "GetDataByType", null);
                }
            }

            return categorys2ListResult;
        }