List<ProTalkBackEntity> GetProData() { List<ProTalkBackEntity> list =talkbll.GetProTalkBack(Convert.ToDateTime(txtStartDate.Text), Convert.ToDateTime(txtEndDate.Text)); List<ProTalkBackEntity> proList=new List<ProTalkBackEntity>(); var query = list.GroupBy(t => t.ProductName).Select(p => new { ProductName = p.Key, hascomment = p.Sum(x => x.hascomment), Ding = p.Sum(x => x.Ding), Zan = p.Sum(x => x.Zan) }).OrderByDescending(t => t.hascomment).ThenByDescending(t => t.Zan).ThenByDescending(t => t.Ding).Take(10);// 赞,顶,点评最大的前10条数据 foreach (var item in query) { proList.Add(new ProTalkBackEntity() { ProductName = item.ProductName, hascomment = item.hascomment, Ding = item.Ding, Zan = item.Zan }); } return proList; }
Dictionary<string, List<LocationTalkEntiy>> GetLocationData() { List<LocationTalkEntiy> list = talkbll.GetLocationTalkBack(Convert.ToDateTime(txtStartDate.Text), Convert.ToDateTime(txtEndDate.Text)); List<LocationTalkEntiy> proList = new List<LocationTalkEntiy>(); Dictionary<string, List<LocationTalkEntiy>> Dic = new Dictionary<string, List<LocationTalkEntiy>>(); var query = list.GroupBy(t => t.LOCATIONNAME).Select(p => new { LOCATIONNAME = p.Key, hascomment = p.Sum(x => x.hascomment) }).OrderByDescending(t => t.hascomment).Take(10);// 目的地点评最大的前10条数据 foreach (var item in query) { proList.Add(new LocationTalkEntiy() { hascomment = item.hascomment, LOCATIONNAME=item.LOCATIONNAME }); } if (proList != null && proList.Count > 0) { for (int i = 0; i < 2; i++) {//控制表格输出格式 if (i == 0) Dic.Add("", proList); else Dic.Add(this.txtStartDate.Text + "~" + this.txtEndDate.Text, proList); } } return Dic;
多个字段分组
//一天当中手机号打入多次,只算一次呼入数,所以这边用linq去除重复 var query = listlog.GroupBy(t => new { t.CallPhone, CallTime = t.CallTime.ToString("yyyy-MM-dd") });