/// <summary> /// 根据管道获取数据[异步] /// </summary> /// <param name="search"></param> /// <returns></returns> public async Task <BaseResultModel <T> > GetListAggregateAsync(ManagePostAttPageSearch search) { Dictionary <string, string> searchDic = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(search.SearchDic.ToString()); Dictionary <string, string> sortDic = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(search.SortDic.ToString()); PipeLineBsonHelper pipeLineBsonHelper = new PipeLineBsonHelper(); List <string> pipeLinelist = new List <string>(); #region 过滤(条件查询) pipeLineBsonHelper.AddMatchList(searchDic, pipeLinelist); #endregion #region 分组(用 $last排序,后续改为属性映射独立方法 ) if (string.IsNullOrEmpty(search.GroupField)) { throw new ArgumentNullException($"分组参数{nameof(search.GroupField)}不能为空!"); } string group = "{'" + search.GroupField + "':'$" + search.GroupField + "'}"; string pipelineGroup = @"{$group: { _id:" + group + @", 'id':{ '$first':'$_id'}, 'ConstructPermitNum':{ '$first' :'$ConstructPermitNum'}, 'ProjectName':{ '$last' :'$ProjectName'}, 'ProjectGuid':{ '$last' :'$ProjectGuid'}, 'Company':{ '$last':'$Company'}, 'OrganizationCode':{ '$last':'$OrganizationCode'}, 'CorpType':{ '$last':'$CorpType'}, 'SegmentAddressArea':{ '$last':'$SegmentAddressArea'}, 'AttendanceTime':{ '$last':'$AttendanceTime'}, 'AttendanceId':{ '$last':'$AttendanceId'}, 'PersonGUID':{ '$last':'$PersonGUID'}, 'PersonName':{ '$last':'$PersonName'}, 'IdCard':{ '$last':'$IdCard'}, 'PostType':{ '$last':'$PostType'}, 'ImageBuffer':{ '$last':'$ImageBuffer'}, 'SupervisionDepartment':{ '$last':'$SupervisionDepartment'}, 'SupervisionDepartmentGUID':{ '$last':'$SupervisionDepartmentGUID'}, 'CreateTime':{ '$last':'$CreateTime'} } }"; pipeLinelist.Add(pipelineGroup); #endregion #region 总数(根据条件查询总数) string pipelineCount = "{$count:'total'}"; pipeLinelist.Add(pipelineCount); IList <IPipelineStageDefinition> stageList = new List <IPipelineStageDefinition>(); foreach (string item in pipeLinelist) { PipelineStageDefinition <BsonDocument, BsonDocument> stageGroup = new JsonPipelineStageDefinition <BsonDocument, BsonDocument>(item); stageList.Add(stageGroup); } BaseResultModel <T> baseResultModel = new BaseResultModel <T>(); BsonDocument bsonDocument = await mongodbBsonService.GetAggregateAsync(stageList); if (null != bsonDocument) { baseResultModel = BsonSerializer.Deserialize <BaseResultModel <T> >(bsonDocument); } else { baseResultModel.total = 0; baseResultModel.rows = new List <T>(); baseResultModel.success = false; return(baseResultModel); } #endregion //移除总数 pipeLinelist.Clear(); stageList.RemoveAt(stageList.Count - 1); #region 排序 pipeLineBsonHelper.AddSortList(sortDic, pipeLinelist); #endregion #region 分页 string pipelineSkip = "{$skip:" + ((search.PageIndex - 1) * search.PageSize) + "}"; string pipelineLimit = "{$limit:" + search.PageSize + "}"; pipeLinelist.Add(pipelineSkip); pipeLinelist.Add(pipelineLimit); #endregion #region 射 string pipelineProject = "{$project:{'_id':0,'id':0}}"; pipeLinelist.Add(pipelineProject); #endregion foreach (string item in pipeLinelist) { PipelineStageDefinition <BsonDocument, BsonDocument> stageGroup = new JsonPipelineStageDefinition <BsonDocument, BsonDocument>(item); stageList.Add(stageGroup); } //baseResultModel.rows = await mongodbBsonService.GetListAggregateAsync(stageList); List <T> list = new List <T>(); foreach (var item in await mongodbBsonService.GetListAggregateAsync(stageList)) { var d = BsonSerializer.Deserialize <BsonDocument>(item); list.Add(BsonSerializer.Deserialize <T>(item)); } baseResultModel.rows = list; baseResultModel.success = true; return(baseResultModel); }
/// <summary> /// 根据施工许可证号码、身份证号码、日期分组统计考勤人数 /// </summary> /// <param name="search"></param> /// <returns></returns> public async Task <IEnumerable <ManagePostAttStatistics> > GetListStatisticsAsync(ManagePostAttPageSearch search) { if (null == search) { throw new ArgumentNullException($"查询条件{nameof(search.SearchDic)}不能为空!"); } Dictionary <string, string> searchDic = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(search.SearchDic.ToString()); PipeLineBsonHelper pipeLineBsonHelper = new PipeLineBsonHelper(); List <string> pipeLinelist = new List <string>(); #region 过滤(条件查询) pipeLineBsonHelper.AddMatchList(searchDic, pipeLinelist); #endregion #region 分组(用 $last排序,后续改为属性映射独立方法 ) string group = "{'ConstructPermitNum':'$ConstructPermitNum'"; group += ",'IdCard':'$IdCard'"; group += ",'day':{'$substr':[{'$add':['$AttendanceTime', 28800000]},0,10]}"; group += "}"; string pipelineGroup1 = @"{$group: { _id:" + group + @", 'ConstructPermitNum':{ '$first' :'$ConstructPermitNum'}, 'ProjectName':{ '$last' :'$ProjectName'}, 'ProjectGuid':{ '$last' :'$ProjectGuid'}, 'AttendanceTime':{ '$last':'$AttendanceTime'} } }"; pipeLinelist.Add(pipelineGroup1); string pipelineGroup2 = @"{$group: { _id:" + group + @", 'ConstructPermitNum':{ '$first' :'$ConstructPermitNum'}, 'ProjectName':{ '$last' :'$ProjectName'}, 'ProjectGuid':{ '$last' :'$ProjectGuid'}, 'AttendanceTime':{ '$last':'$AttendanceTime'}, 'AttPersonCount':{'$sum':1} } }"; pipeLinelist.Add(pipelineGroup2); #endregion #region 排序 if (null != search.SortDic) { Dictionary <string, string> sortDic = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(search.SortDic.ToString()); pipeLineBsonHelper.AddSortList(sortDic, pipeLinelist); } #endregion #region 射 string pipelineProject = "{$project:{'_id':0}}"; pipeLinelist.Add(pipelineProject); #endregion IList <IPipelineStageDefinition> stageList = new List <IPipelineStageDefinition>(); foreach (string item in pipeLinelist) { PipelineStageDefinition <BsonDocument, BsonDocument> stageGroup = new JsonPipelineStageDefinition <BsonDocument, BsonDocument>(item); stageList.Add(stageGroup); } //baseResultModel.rows = await mongodbBsonService.GetListAggregateAsync(stageList); List <ManagePostAttStatistics> list = new List <ManagePostAttStatistics>(); foreach (var item in await mongodbBsonService.GetListAggregateAsync(stageList)) { var d = BsonSerializer.Deserialize <BsonDocument>(item); list.Add(BsonSerializer.Deserialize <ManagePostAttStatistics>(item)); } return(list); }