private ISearchResponse <es_t_bp_item> GetStatisDetailData(SysSearchModel model) { model.modelType = SysSearchModelModelType.UnQualified; var userItems = userItemrep.GetDictByCondition <string, string>(r => r.UserId == GetCurrentUserId() && r.UserItemType == UserItemType.UnQualifiedReport, r => new { r.Id, r.ItemTableName }); var userInstIds = userCustomrep.GetDictByCondition <string, string>(r => r.UserId == GetCurrentUserId() && r.UserCustomType == UserCustomType.UnQualifiedCount, r => new { r.Id, r.CustomId }); var filterQuery = GetFilterQuery(checkUnitService, itemNameService, model, userInstIds, userItems); int pos = model.posStart.HasValue ? model.posStart.Value : 0; int count = model.count.HasValue ? model.count.Value : 30; ISearchResponse <es_t_bp_item> response = tbpitemESRep.Search(s => s.Source(t => t.Includes(tt => tt.Fields( f => f.SYSPRIMARYKEY, f => f.CUSTOMID, f => f.PROJECTNAME, f => f.STRUCTPART, f => f.ITEMNAME, f => f.ITEMCHNAME, f => f.ACSTIME, f => f.ENTRUSTDATE, f => f.CHECKDATE, f => f.PRINTDATE, f => f.SAMPLENUM, f => f.REPORTNUM, f => f.HAVREPORT, f => f.ISCREPORT, f => f.REPORTJXLB //f => f.SUBITEMCODE ))).Sort(cs => cs.Descending(sd => sd.PRINTDATE)).From(pos).Size(count). Query(filterQuery)); return(response); }
private ISearchResponse <es_t_bp_item> GetSearchResult(SysSearchModel model) { var filterQuery = GetFilterQuery(checkUnitService, itemNameService, model, new Dictionary <string, string>(), new Dictionary <string, string>()); int pos = model.posStart.HasValue ? model.posStart.Value : 0; int count = model.count.HasValue ? model.count.Value : 30; return(tbpitemESRep.Search(s => s.Source(sf => sf.Includes(sfi => sfi.Fields( f => f.SYSPRIMARYKEY, f => f.APPROVEDATE, f => f.SAMPLENAME, f => f.PROJECTNAME, f => f.STRUCTPART, f => f.CONCLUSIONCODE, f => f.ITEMNAME, f => f.ITEMCHNAME, f => f.REPORTNUM, f => f.CUSTOMID, f => f.ENTRUSTDATE, f => f.CHECKDATE, f => f.SAMPLENUM, f => f.SAMPLEDISPOSEPHASEORIGIN, f => f.PRINTDATE, f => f.ADDTIME, f => f.SAMPLEDISPOSEPHASE, f => f.ACSTIME, f => f.CODEBAR, f => f.QRCODEBAR ))).From(pos).Size(count).Query(filterQuery))); }
private ISearchResponse <es_t_bp_item> GetStatisData(SysSearchModel model) { if (model.GroupType != "Custom") //不以机构分组则只查不合格,以机构分组则查询所有报告,再聚合一次不合格数量 { model.modelType = SysSearchModelModelType.UnQualified; } var userItems = userItemrep.GetDictByCondition <string, string>(r => r.UserId == GetCurrentUserId() && r.UserItemType == UserItemType.UnQualifiedReport, r => new { r.Id, r.ItemTableName }); var userInstIds = userCustomrep.GetDictByCondition <string, string>(r => r.UserId == GetCurrentUserId() && r.UserCustomType == UserCustomType.UnQualifiedCount, r => new { r.Id, r.CustomId }); var filterQuery = GetFilterQuery(checkUnitService, itemNameService, model, userInstIds, userItems); ISearchResponse <es_t_bp_item> response = null; if (!string.IsNullOrEmpty(model.GroupType)) { switch (model.GroupType) { case "Item": aggeKey = "ItemNum"; //response = tbpitemESRep.Search(s => s.Size(0).Query(filterQuery) //.Aggregations(af => af.Terms(aggeKey, item => item //.Field(iif => iif.ITEMNAME).Size(1000)))); response = tbpitemESRep.Search(s => s.Size(0).Query(filterQuery) .Aggregations(af => af.Terms(aggeKey, item => item .Script("doc['REPORTJXLB'].value+'|'+doc['ITEMNAME'].value").Size(1000)))); break; case "Custom": aggeKey = "Custom"; response = tbpitemESRep.Search(s => s.Size(0).Query(filterQuery) .Aggregations(af => af.Terms(aggeKey, item => item .Field(iif => iif.CUSTOMID).Size(1000) .Aggregations(aaaf => aaaf.Terms("Conclution", aaa => aaa.Field(aac => aac.CONCLUSIONCODE).Aggregations(tt => tt.Terms("ProductFactory", ttt => ttt.Field(tttt => tttt.PRODUCEFACTORY)))) )))); break; case "Project": aggeKey = "Project"; response = tbpitemESRep.Search(s => s.Size(0).Query(filterQuery) .Aggregations(af => af.Terms(aggeKey, item => item .Field(iif => iif.PROJECTNAME[0].Suffix("PROJECTNAMERAW")).Size(1000)))); break; default: aggeKey = "ItemNum"; response = tbpitemESRep.Search(s => s.Size(0).Query(filterQuery) .Aggregations(af => af.Terms(aggeKey, item => item .Field(iif => iif.ITEMNAME).Size(1000)))); break; } } return(response); }
public ActionResult StatisGrid(SysSearchModel model) { int pos = model.posStart.HasValue ? model.posStart.Value : 0; model.GroupType = "Item"; var response = GetStatisData(model); DhtmlxGrid grid = new DhtmlxGrid(); if (response.IsValid) { int index = pos; var bucks = response.Aggs.Terms(aggeKey).Buckets; var allItems = itemNameService.GetAllItemName(); int totalCount = bucks.Count; grid.AddPaging(totalCount, pos); string CustomId = InstUserCustomId(); string itemValue = string.Empty; foreach (var item in bucks) { string itemKey = item.Key; switch (aggeKey) { case "ItemNum": var itemKeys = item.Key.Split('|'); var jxlb = itemKeys[0]; var itemCode = itemKeys[1]; itemValue = itemNameService.GetItemCNNameFromAll(allItems, jxlb, itemCode); break; case "Custom": itemValue = checkUnitService.GetCheckUnitById(item.Key); break; case "Project": itemValue = item.Key; //item.Key= HttpUtility.UrlEncode(item.Key); break; } DhtmlxGridRow row = new DhtmlxGridRow(item.Key); row.AddCell((index + 1).ToString()); row.AddCell(itemValue); row.AddCell((item.DocCount.HasValue ? item.DocCount.Value : 0).ToString()); row.AddLinkJsCell("材料动态分析表查看", "showUnquailfyAnalysis(\"{0}\",\"{1}\")".Fmt(itemKey, itemValue)); grid.AddGridRow(row); index++; } } string str = grid.BuildRowXml().ToString(System.Xml.Linq.SaveOptions.DisableFormatting); return(Content(str, "text/xml")); }
private ISearchResponse <es_t_bp_item> GetGridSearchResponse(SysSearchModel model) { var filter = GetFilterQuery(checkUnitService, itemNameService, model, new Dictionary <string, string>(), new Dictionary <string, string>()); if (model.Group == "1") { return(tbpESRep.Search(t => t.Size(0).Query(filter).Aggregations(tt => tt.Terms(aggKey, tst => tst.Field(tstt => tstt.PROJECTNAME).Size(1000))))); } else { return(tbpESRep.Search(t => t.Size(0).Query(filter).Aggregations(tt => tt.Terms(aggKey, tst => tst.Script("doc['REPORTJXLB'].value+'|'+doc['ITEMNAME'].value")))));//tst => tst.Field(tstt => tstt.ITEMNAME).Size(1000)))); } }
public ActionResult Search(SysSearchModel model) { ISearchResponse <es_t_bp_item> response = GetSearchResult(model); int pos = model.posStart.HasValue ? model.posStart.Value : 0; int totalCount = (int)response.Total; DhtmlxGrid grid = new DhtmlxGrid(); grid.AddPaging(totalCount, pos); int index = pos; var allItems = itemNameService.GetAllItemName(); var allInsts = checkUnitService.GetAllCheckUnit(); var reportConclusions = sysDictService.GetDictsByKey("ReportConclusionCode"); foreach (var item in response.Documents) { DhtmlxGridRow row = new DhtmlxGridRow(item.SYSPRIMARYKEY); row.AddCell(index + 1); if (item.CONCLUSIONCODE == "Y") { row.AddCell(item.PROJECTNAME); } else { row.AddCell(new DhtmlxGridCell("{0}".Fmt(item.PROJECTNAME), false).AddCellAttribute("style", "color:red")); //row.AddCell(item.PROJECTNAME); } row.AddCell(SysDictUtility.GetKeyFromDic(reportConclusions, item.CONCLUSIONCODE, "/")); row.AddCell(checkUnitService.GetCheckUnitByIdFromAll(allInsts, item.CUSTOMID)); if (item.ITEMCHNAME.IsNullOrEmpty()) { row.AddCell(itemNameService.GetItemCNNameFromAll(allItems, item.REPORTJXLB, item.ITEMNAME)); } else { row.AddCell(item.ITEMCHNAME); } row.AddLinkJsCell(item.REPORTNUM, "detailsReport(\"{0}\")".Fmt(item.SYSPRIMARYKEY)); row.AddCell(item.SAMPLENUM); row.AddCell(item.ENTRUSTDATE.HasValue ? item.ENTRUSTDATE.Value.ToString("yyyy-MM-dd") : "/"); row.AddCell(item.CHECKDATE.HasValue ? item.CHECKDATE.Value.ToString("yyyy-MM-dd") : "/"); row.AddCell(reportService.GetReportDataStatus(item.SAMPLEDISPOSEPHASEORIGIN)); index++; grid.AddGridRow(row); } string str = grid.BuildRowXml().ToString(System.Xml.Linq.SaveOptions.DisableFormatting); return(Content(str, "text/xml")); }
public ActionResult SiderBar(SysSearchModel model) { model.modelType = SysSearchModelModelType.CheckStatis; DhtmlxSidebar siderbar = new DhtmlxSidebar(); var response = GetGridSearchResponse(model); if (response.IsValid) { var buckets = response.Aggs.Terms(aggKey).Buckets; var allItem = itemNameService.GetAllItemName(); foreach (var bucket in buckets) { if (model.Group == "1") { var key = bucket.Key; var bubble = bucket.DocCount.ToString(); siderbar.AddSidebarItem(new DhtmlxSidebarItem(key, key, bubble)); } else { var key = bucket.Key; var ItemName = string.Empty; if (key.Contains('|')) { var keys = key.Split('|'); var typeName = keys[0]; var itemCode = keys[1]; ItemName = itemNameService.GetItemCNNameFromAll(allItem, typeName, itemCode); } if (ItemName.IsNullOrEmpty()) { continue; } var bubble = bucket.DocCount.ToString(); siderbar.AddSidebarItem(new DhtmlxSidebarItem(key, ItemName, bubble)); } } } string str = siderbar.BuildDhtmlXml().ToString(System.Xml.Linq.SaveOptions.DisableFormatting); return(Content(str, "text/xml")); }
/// <summary> /// 画过去一年的厂家不合格报告折线图 /// </summary> /// <returns></returns> public ActionResult DrawBrokenLineImage(SysSearchModel model) { HomeEchartData <EchartNameValue> data = new HomeEchartData <EchartNameValue>(); data.records = new List <EchartNameValue>(); var userItems = userItemrep.GetDictByCondition <string, string>(r => r.UserId == GetCurrentUserId() && r.UserItemType == UserItemType.UnQualifiedReport, r => new { r.Id, r.ItemTableName }); var userInstIds = userCustomrep.GetDictByCondition <string, string>(r => r.UserId == GetCurrentUserId() && r.UserCustomType == UserCustomType.UnQualifiedCount, r => new { r.Id, r.CustomId }); model.IsMonthAgg = true; var filterQuery = GetFilterQuery(checkUnitService, itemNameService, model, userInstIds, userItems); return(Content(string.Empty)); }
public ActionResult Search(SysSearchModel model) { model.modelType = SysSearchModelModelType.CheckStatis; var response = GetSearchResponse(model); int pos = model.posStart.HasValue ? model.posStart.Value : 0; int index = pos + 1; DhtmlxGrid grid = new DhtmlxGrid(); var allInsts = checkUnitService.GetAllCheckUnit(); var allItems = itemNameService.GetAllItemName(); if (response.IsValid) { int totalCount = (int)response.Total; grid.AddPaging(totalCount, pos); var pkrReports = reportService.GetPkrReportNums(response.Documents); foreach (var item in response.Documents) { DhtmlxGridRow row = new DhtmlxGridRow(item.SYSPRIMARYKEY); row.AddCell(index++); row.AddCell(item.ENTRUSTUNIT); row.AddCell(item.CONSTRACTUNIT); row.AddCell(checkUnitService.GetCheckUnitByIdFromAll(allInsts, item.CUSTOMID)); row.AddCell(item.PROJECTNAME); row.AddCell(item.STRUCTPART); row.AddCell(itemNameService.GetItemCNNameFromAll(allItems, item.REPORTJXLB, item.ITEMNAME)); row.AddCell(item.CHECKTYPE); row.AddCell(GetUIDtString(item.ENTRUSTDATE, "yyyy-MM-dd")); row.AddCell(GetUIDtString(item.CHECKDATE, "yyyy-MM-dd")); row.AddCell(GetUIDtString(item.PRINTDATE, "yyyy-MM-dd")); BuildReportNumRow(reportService, pkrReports, item, row); row.AddCell(item.CHECKCONCLUSION); row.AddCell(new DhtmlxGridCell("查看", false).AddCellAttribute("title", "查看")); grid.AddGridRow(row); } } string str = grid.BuildRowXml().ToString(System.Xml.Linq.SaveOptions.DisableFormatting); return(Content(str, "text/xml")); }
public ActionResult SearchGrid(SysSearchModel model) { int pos = model.posStart.HasValue ? model.posStart.Value : 0; DhtmlxGrid grid = new DhtmlxGrid(); var response = GetStatisDetailData(model); if (response.IsValid) { int totalCount = (int)response.Total; grid.AddPaging(totalCount, pos); int index = pos; var allInst = checkUnitService.GetAllCheckUnit(); var allItems = itemNameService.GetAllItemName(); var pkrReports = reportService.GetPkrReportNums(response.Documents); foreach (var item in response.Documents) { DhtmlxGridRow row = new DhtmlxGridRow(item.SYSPRIMARYKEY); row.AddCell((index + 1).ToString()); row.AddCell(checkUnitService.GetCheckUnitByIdFromAll(allInst, item.CUSTOMID)); row.AddCell(item.PROJECTNAME); if (item.ITEMCHNAME.IsNullOrEmpty()) { row.AddCell(itemNameService.GetItemCNNameFromAll(allItems, item.REPORTJXLB, item.ITEMNAME)); } else { row.AddCell(item.ITEMCHNAME); } row.AddCell(GetUIDtString(item.PRINTDATE)); BuildReportNumRow(reportService, pkrReports, item, row); row.AddCell(new DhtmlxGridCell("查看", false).AddCellAttribute("title", "查看")); index++; grid.AddGridRow(row); } } string str = grid.BuildRowXml().ToString(System.Xml.Linq.SaveOptions.DisableFormatting); return(Content(str, "text/xml")); }
/// <summary> /// 数据导出 /// </summary> /// <param name="searchModel">查询参数</param> /// <param name="fileFormat">文件格式,2003/2007</param> /// <returns>用于下载的Excel文件内容</returns> public ActionResult Export(SysSearchModel searchModel, int?fileFormat) { searchModel.GroupType = "Custom"; var response = GetStatisData(searchModel); bool xlsx = (fileFormat ?? 2007) == 2007; ExcelExporter ee = new ExcelExporter("材料动态分析表", xlsx); ee.SetColumnTitles("序号, 地区, 报告总数, 不合格数量, 不合格数量占比, 生产厂家总数, 不合格生产商家数量, 不合格生产厂家占比 "); if (response.IsValid) { var bucks = response.Aggs.Terms("Custom").Buckets; //countByArea 地区报告总数 unQualifyCount 地区报告不合格总数 countUnitByArea 地区厂家总数 unQualifyUnitCountByArea 地区厂家不合格总数 Dictionary <string, int> countByArea, unQualifyCount, countUnitByArea, unQualifyUnitCountByArea; GetSearchResult(bucks, out countByArea, out unQualifyCount, out countUnitByArea, out unQualifyUnitCountByArea); var index = 1; foreach (var item in countByArea) { var unQualifyCountRow = 0; var unitCountByArea = 0; var unqualifyUnitCount = 0; var isUnqualify = unQualifyCount.TryGetValue(item.Key, out unQualifyCountRow); //isUnqualify 标识是否有不合格报告 var isUnitCount = countUnitByArea.TryGetValue(item.Key, out unitCountByArea); var isUnqualifyUnitCount = unQualifyUnitCountByArea.TryGetValue(item.Key, out unqualifyUnitCount); ExcelRow row = ee.AddRow(); row.AddCell(index++); row.AddCell(item.Key); row.AddCell(item.Value); row.AddCell(isUnqualify ? unQualifyCountRow : 0); row.AddCell(item.Value == 0 ? "0" : Math.Round(((unQualifyCountRow * 1.00 / item.Value) * 100), 2).ToString() + "%"); row.AddCell(unitCountByArea.ToString()); row.AddCell(unqualifyUnitCount.ToString()); row.AddCell(unitCountByArea == 0 ? "0" : Math.Round(((unqualifyUnitCount * 1.00 / unitCountByArea) * 100), 2).ToString() + "%"); } } // 改动4:返回字节流 return(File(ee.GetAsBytes(), ee.MIME, ee.FileName)); }
public ActionResult Export(SysSearchModel model, int?fileFormat) { ISearchResponse <es_t_bp_item> response = GetSearchResult(model); var allItems = itemNameService.GetAllItemName(); var allInsts = checkUnitService.GetAllCheckUnit(); var reportConclusions = sysDictService.GetDictsByKey("ReportConclusionCode"); bool xlsx = (fileFormat ?? 2007) == 2007; ExcelExporter ee = new ExcelExporter("监督抽检", xlsx); ee.SetColumnTitles("序号, 工程名称, 合格, 机构名称, 检测项目, 报告编号, 样品编号, 委托日期, 检测日期, 数据状态"); int pos = model.posStart.HasValue ? model.posStart.Value : 0; int index = pos; foreach (var item in response.Documents) { ExcelRow row = ee.AddRow(); row.AddCell(index + 1); row.AddCell(item.PROJECTNAME); row.AddCell(SysDictUtility.GetKeyFromDic(reportConclusions, item.CONCLUSIONCODE, "/")); row.AddCell(checkUnitService.GetCheckUnitByIdFromAll(allInsts, item.CUSTOMID)); if (item.ITEMCHNAME.IsNullOrEmpty()) { row.AddCell(itemNameService.GetItemCNNameFromAll(allItems, item.REPORTJXLB, item.ITEMNAME)); } else { row.AddCell(item.ITEMCHNAME); } row.AddCell(item.REPORTNUM); row.AddCell(item.SAMPLENUM); row.AddCell(item.ENTRUSTDATE.HasValue ? item.ENTRUSTDATE.Value.ToString("yyyy-MM-dd") : "/"); row.AddCell(item.CHECKDATE.HasValue ? item.CHECKDATE.Value.ToString("yyyy-MM-dd") : "/"); row.AddCell(reportService.GetReportDataStatus(item.SAMPLEDISPOSEPHASEORIGIN)); index++; } return(File(ee.GetAsBytes(), ee.MIME, ee.FileName)); }
private ISearchResponse <es_t_bp_item> GetSearchResponse(SysSearchModel model) { var filter = GetFilterQuery(checkUnitService, itemNameService, model, new Dictionary <string, string>(), new Dictionary <string, string>()); int pos = model.posStart.HasValue ? model.posStart.Value : 0; int count = model.count.HasValue ? model.count.Value : 30; return(tbpESRep.Search(t => t.Query(filter).From(pos).Size(count) .Source(tt => tt.Includes(tst => tst.Fields( ttt => ttt.SYSPRIMARYKEY, ttt => ttt.ENTRUSTUNIT, ttt => ttt.CONSTRACTUNIT, ttt => ttt.CUSTOMID, ttt => ttt.PROJECTNAME, ttt => ttt.STRUCTPART, ttt => ttt.REPORTJXLB, ttt => ttt.ITEMNAME, ttt => ttt.CHECKTYPE, ttt => ttt.ENTRUSTDATE, ttt => ttt.CHECKDATE, ttt => ttt.PRINTDATE, ttt => ttt.REPORTNUM, ttt => ttt.CHECKCONCLUSION ))))); }
public ActionResult Statis(SysSearchModel model) { int pos = model.posStart.HasValue ? model.posStart.Value : 0; model.GroupType = "Item"; var statisData = GetStatisData(model); StatisChart chart = new StatisChart(); if (statisData.IsValid) { var bucks = statisData.Aggs.Terms(aggeKey).Buckets; var allItems = itemNameService.GetAllItemName(); string itemValue = string.Empty; string CustomId = InstUserCustomId(); int index = 1; bool ProjectCount30 = false; foreach (var item in bucks) { switch (aggeKey) { case "ItemNum": if (index++ > 30) { ProjectCount30 = true; break; } var itemKeys = item.Key.Split('|'); var jxlb = itemKeys[0]; var itemCode = itemKeys[1]; itemValue = itemNameService.GetItemCNNameFromAll(allItems, jxlb, itemCode); break; case "Custom": if (index++ > 30) { ProjectCount30 = true; break; } itemValue = checkUnitService.GetCheckUnitById(item.Key); break; case "Project": //按工程分组只显示30个 if (index++ > 30) { ProjectCount30 = true; break; } itemValue = item.Key; break; } if (ProjectCount30) { break; } chart.StatisChartItems.Add(new StatisChartItem() { StatisKey = item.Key, StatisName = itemValue, DocCount = item.DocCount.HasValue ? item.DocCount.Value : 0 }); } } return(Content(chart.ToJson())); }
/// <summary> /// 根据机构分组统计之后,塞到对应的地区中 /// </summary> /// <param name="model"></param> /// <returns></returns> public ActionResult Search(SysSearchModel model) { model.GroupType = "Custom"; var response = GetStatisData(model); DhtmlxGrid grid = new DhtmlxGrid(); /* * 1.查出所有报告数量以及分组统计不合格报告数量 * 2.countByArea 存储该地区报告总数 * 3.需要一个存储该地区所有不合格报告数量 * 4.存储改地区所有有不合格报告数量的厂家 厂家总数 * */ if (response.IsValid) { var bucks = response.Aggs.Terms("Custom").Buckets; Dictionary <string, int> countByArea, unQualifyCount, countUnitByArea, unQualifyUnitCountByArea; GetSearchResult(bucks, out countByArea, out unQualifyCount, out countUnitByArea, out unQualifyUnitCountByArea); var allAreas = AreaService.GetAllArea(); /* * 1.从所有的地区中选择名字相对应的地区,判断是否为市级节点,是直接加入,不是的话需要判断本节点所属的市级节点是否存在,如果存在直接加上,不存在则增加一条数值为0的记录 */ var index = 1; var rootAreas = new List <AreaResultModel>(); var childAreas = new List <AreaResultModel>(); foreach (var item in countByArea) { if (item.Key.IsNullOrEmpty()) { continue; } var unQualifyCountRow = 0; var unitCountByArea = 0; var unqualifyUnitCount = 0; var isUnqualify = unQualifyCount.TryGetValue(item.Key, out unQualifyCountRow); //isUnqualify 标识是否有不合格报告 var isUnitCount = countUnitByArea.TryGetValue(item.Key, out unitCountByArea); var isUnqualifyUnitCount = unQualifyUnitCountByArea.TryGetValue(item.Key, out unqualifyUnitCount); List <t_bp_area> areas = new List <t_bp_area>(); var areass = allAreas.Where(t => t.AREANAME == item.Key); if (areass != null) { areas = areass.ToList(); } if (areas != null && areas.Count > 0) { var area = areas.First(); logger.Debug("areasfirst"); AreaResultModel areaResult = new AreaResultModel() { AreaCode = area.AREACODE, ParentCode = area.PAREACODE, Name = area.AREANAME, TotalCount = (int)item.Value, UnqualifuCount = unQualifyCountRow, FactoryCount = unitCountByArea, UnqualifyFactoryCount = unqualifyUnitCount }; if (area.PAREACODE == "45")//市 { GetRootAreaResult(rootAreas, area, areaResult, areaResult); } else //市辖区,县等 { childAreas.Add(areaResult); var parentCode = area.PAREACODE; if (parentCode != null) { List <t_bp_area> parentAreas = new List <t_bp_area>(); var parentAreass = allAreas.Where(t => t.AREACODE == parentCode); if (parentAreass != null) { parentAreas = parentAreass.ToList(); } if (parentAreas != null && parentAreas.Count > 0) { var parentArea = parentAreas.First(); //获得所属市地区信息 AreaResultModel parentareaResult = new AreaResultModel() { AreaCode = parentArea.AREACODE, Name = parentArea.AREANAME, TotalCount = 0, UnqualifuCount = 0, FactoryCount = 0, UnqualifyFactoryCount = 0 }; GetRootAreaResult(rootAreas, parentArea, areaResult, parentareaResult); } } } } } foreach (var item in rootAreas) { DhtmlxGridRow row = new DhtmlxGridRow(item.AreaCode); row.AddCell(index++); row.AddCell(item.Name); row.AddCell(item.TotalCount); row.AddCell(item.UnqualifuCount); row.AddCell(item.TotalCount == 0 ? "0" : Math.Round(((item.UnqualifuCount * 1.00 / item.TotalCount) * 100), 2).ToString() + "%"); row.AddCell(item.FactoryCount); row.AddCell(item.UnqualifyFactoryCount); row.AddCell(item.FactoryCount == 0 ? "0" : Math.Round(((item.UnqualifyFactoryCount * 1.00 / item.FactoryCount) * 100), 2).ToString() + "%"); row.AddCell(string.Empty); //同比 row.AddCell(string.Empty); //环比 if (item.TotalCount > 0) { row.AddLinkJsCell("详情查看", "showItemKeyGrid(\"{0}\")".Fmt(item.Name)); } List <AreaResultModel> thisChildAreas = new List <AreaResultModel>(); var thisChildAreass = childAreas.Where(t => t.ParentCode == item.AreaCode); if (thisChildAreass != null) { thisChildAreas = thisChildAreass.ToList(); } if (thisChildAreas != null && thisChildAreas.Count > 0) { var childIndex = 1; foreach (var childItem in thisChildAreas) { DhtmlxGridRow childRow = new DhtmlxGridRow(childItem.AreaCode); childRow.AddCell(childIndex++); childRow.AddCell(childItem.Name); childRow.AddCell(childItem.TotalCount); childRow.AddCell(childItem.UnqualifuCount); childRow.AddCell(childItem.TotalCount == 0 ? "0" : Math.Round(((childItem.UnqualifuCount * 1.00 / childItem.TotalCount) * 100), 2).ToString() + "%"); childRow.AddCell(childItem.FactoryCount); childRow.AddCell(childItem.UnqualifyFactoryCount); childRow.AddCell(childItem.FactoryCount == 0 ? "0" : Math.Round(((childItem.UnqualifyFactoryCount * 1.00 / childItem.FactoryCount) * 100), 2).ToString() + "%"); childRow.AddCell(string.Empty); //同比 childRow.AddCell(string.Empty); //环比 if (childItem.UnqualifuCount > 0) //有不合格报告才显示详情查看 { //TODO 由于改了实现方式,将市辖区,县的信息塞到了市中,在不合格详情查看时需要增加如果是市,则需要查本市所有的不合格数据 childRow.AddLinkJsCell("详情查看", "showItemKeyGrid(\"{0}\")".Fmt(childItem.Name)); } row.AddRow(childRow); } } grid.AddGridRow(row); } //foreach (var item in countByArea) //{ // var unQualifyCountRow = 0; // var unitCountByArea = 0; // var unqualifyUnitCount = 0; // var isUnqualify = unQualifyCount.TryGetValue(item.Key, out unQualifyCountRow); //isUnqualify 标识是否有不合格报告 // var isUnitCount = countUnitByArea.TryGetValue(item.Key, out unitCountByArea); // var isUnqualifyUnitCount = unQualifyUnitCountByArea.TryGetValue(item.Key, out unqualifyUnitCount); // DhtmlxGridRow row = new DhtmlxGridRow(item.Key); // row.AddCell(index++); // row.AddCell(item.Key); // row.AddCell(item.Value); // row.AddCell(isUnqualify ? unQualifyCountRow : 0); // row.AddCell(item.Value == 0 ? "0" : Math.Round(((unQualifyCountRow * 1.00 / item.Value) * 100), 2).ToString() + "%"); // row.AddCell(unitCountByArea.ToString()); // row.AddCell(unqualifyUnitCount.ToString()); // row.AddCell(unitCountByArea == 0 ? "0" : Math.Round(((unqualifyUnitCount * 1.00 / unitCountByArea) * 100), 2).ToString() + "%"); // row.AddCell(string.Empty);//同比 // row.AddCell(string.Empty);//环比 // if (isUnqualify)//有不合格报告才显示详情查看 // { // row.AddLinkJsCell("详情查看", "showItemKeyGrid(\"{0}\")".Fmt(item.Key)); // } // grid.AddGridRow(row); //} } string str = grid.BuildRowXml().ToString(System.Xml.Linq.SaveOptions.DisableFormatting); return(Content(str, "text/xml")); }
public ActionResult UnquailfyAnalysis(SysSearchModel model) { return(View(model)); }
// GET: Welcome public ActionResult Index() { var measnumEndDate = new PagingOptions <t_bp_custom>(0, 7, t => t.measnumEndDate); var measnumDate = customRep.GetByConditonPage <MeasnumDateModel>(t => t.measnumEndDate != null, t => new { t.ID, t.NAME, t.measnumEndDate }, measnumEndDate);//检测资质有效期日期 var detectnumEndDate = new PagingOptions <t_bp_custom>(0, 7, t => t.detectnumEndDate); var detectnumDate = customRep.GetByConditonPage <DetectnumDateModel>(t => t.detectnumEndDate != null, t => new { t.ID, t.NAME, t.detectnumEndDate }, detectnumEndDate);//计量认证有效期日期 var checkenddate = new PagingOptions <t_bp_Equipment>(0, 7, t => t.checkenddate); var checkdate = equipmentRep.GetByConditonPage <CheckdateModel>(t => t.checkenddate != null, t => new { t.id, t.EquName, t.checkenddate, t.customid }, checkenddate);//设备有效期 var allUnitByArea = checkUnitService.GetAllCustomInArea(); WelcomeViewMoel viewmodel = new WelcomeViewMoel() { EchartUnqualifyReportsCount = new List <EchartNameValue>(), EchartTotalReportsCount = new List <EchartNameValue>(), EcharModifyReportsCount = new List <EchartNameValue>(), MeasnumDate = new List <DueRemindModel>(), DetectnumDate = new List <DueRemindModel>(), Checkdate = new List <DueRemindModel>() }; int i = 1; foreach (var item in measnumDate) { DueRemindModel dueRemind = new DueRemindModel(); var dateTime = Convert.ToDateTime(DateTime.Now); var time = dateTime - Convert.ToDateTime(item.measnumEndDate); if (time.Days >= 0) { dueRemind.Type = item.Name + "单位检测资质证书已经过期" + time.Days + "天"; } else { dueRemind.Type = item.Name + "单位检测资质证书有效期剩余" + time.Days * (-1) + "天"; } dueRemind.Date = item.measnumEndDate.HasValue ? item.measnumEndDate.Value.ToString("yyyy-MM-dd") : string.Empty; dueRemind.Num = i; i++; dueRemind.Id = item.Id; viewmodel.MeasnumDate.Add(dueRemind); } i = 1; foreach (var item in detectnumDate) { DueRemindModel dueRemind = new DueRemindModel(); var dateTime = Convert.ToDateTime(DateTime.Now); var time = dateTime - Convert.ToDateTime(item.detectnumEndDate); if (time.Days >= 0) { dueRemind.Type = item.Name + "单位计量认证证书已经过期" + time.Days + "天"; } else { dueRemind.Type = item.Name + "单位计量认证证书有效期剩余" + time.Days * (-1) + "天"; } dueRemind.Num = i; i++; dueRemind.Date = item.detectnumEndDate.HasValue ? item.detectnumEndDate.Value.ToString("yyyy-MM-dd") : string.Empty; dueRemind.Id = item.Id; viewmodel.DetectnumDate.Add(dueRemind); } i = 1; foreach (var item in checkdate) { DueRemindModel dueRemind = new DueRemindModel(); var dateTime = Convert.ToDateTime(DateTime.Now); var time = dateTime - Convert.ToDateTime(item.checkenddate); var checkName = checkUnitService.GetCheckUnitById(item.customid); if (time.Days >= 0) { dueRemind.Type = checkName + "单位仪器设备检定已经过期" + time.Days + "天"; } else { dueRemind.Type = checkName + "单位仪器设备检定有效期剩余" + time.Days * (-1) + "天"; } dueRemind.Num = i; i++; dueRemind.Id = item.id; dueRemind.Date = item.checkenddate.HasValue ? item.checkenddate.Value.ToString("yyyy-MM-dd") : string.Empty; viewmodel.Checkdate.Add(dueRemind); } DateTime DtNow = DateTime.Now; string dtFormatStr = "yyyy-MM-dd'T'HH:mm:ss"; string endDtStr = DtNow.AddDays(1).ToString(dtFormatStr); //string endDt = endDtStr DateTime DtStart = DtNow.AddDays(-7); string startDtStr = DtStart.ToString(dtFormatStr); #region 获得首页上部统计信息 var instFilter = GetCurrentInstFilter(); Func <Nest.QueryContainerDescriptor <es_t_bp_item>, QueryContainer> qcd = q => { var qc = q.DateRange(qdr => qdr.Field(qdrf => qdrf.PRINTDATE).GreaterThanOrEquals(DateMath.FromString(startDtStr))) && q.DateRange(qddr => qddr.Field(qddrf => qddrf.PRINTDATE).LessThanOrEquals(DateMath.FromString(endDtStr))); if (instFilter.NeedFilter && instFilter.FilterInstIds.Count() > 0) { qc = qc && +q.Terms(qtm => qtm.Field(qtmf => qtmf.CUSTOMID).Terms(instFilter.FilterInstIds)); } return(qc); }; var response = tbpitemESRep.Search(s => s.Size(0).Query(qcd).Aggregations(af => af.Terms(UnQualiKey, adn => adn.Field(aaa => aaa.CONCLUSIONCODE)) .Terms(ModifyKey, adm => adm.Field(aadm => aadm.HAVELOG)) .Terms(ReportKey, ada => ada.Field(adaa => adaa.HAVREPORT)))); if (response.IsValid) { viewmodel.TotalReports = (int)response.Total; var unQualiBuckets = response.Aggs.Terms(UnQualiKey).Buckets; foreach (var buctet in unQualiBuckets) { if (buctet.Key == "N") { viewmodel.UnqualifyReports = (int)buctet.DocCount; } } var modifyBuckets = response.Aggs.Terms(ModifyKey).Buckets; foreach (var buctet in modifyBuckets) { if (buctet.Key == "1") { viewmodel.ModifyReports = (int)buctet.DocCount; } } var reportBuckets = response.Aggs.Terms(ReportKey).Buckets; foreach (var buctet in reportBuckets) { if (buctet.Key == "1") { viewmodel.PKRReports = (int)buctet.DocCount; } } } if (viewmodel.TotalReports == 0) { viewmodel.UnqualifyPercentage = "0"; viewmodel.ModifyPercentage = "0"; viewmodel.PKRPercentage = "0"; } else { viewmodel.UnqualifyPercentage = (viewmodel.UnqualifyReports * 100 / viewmodel.TotalReports).ToString(); viewmodel.ModifyPercentage = (viewmodel.ModifyReports * 100 / viewmodel.TotalReports).ToString(); viewmodel.PKRPercentage = (viewmodel.PKRReports * 100 / viewmodel.TotalReports).ToString(); } #endregion #region 获得首页中间部分地图信息数据 var countByArea = new Dictionary <string, int>(); var unQualifyCount = new Dictionary <string, int>(); var ModifyCount = new Dictionary <string, int>(); var EchartTotalReportsCount = new Dictionary <string, int>(); var EchartUnqualifyReportsCount = new Dictionary <string, int>(); var EcharModifyReportsCount = new Dictionary <string, int>(); var allArea = areaService.GetAllArea(); var userItems = userItemrep.GetDictByCondition <string, string>(r => r.UserId == GetCurrentUserId() && r.UserItemType == UserItemType.UnQualifiedReport, r => new { r.Id, r.ItemTableName }); var userInstIds = userCustomrep.GetDictByCondition <string, string>(r => r.UserId == GetCurrentUserId() && r.UserCustomType == UserCustomType.UnQualifiedCount, r => new { r.Id, r.CustomId }); SysSearchModel model = new SysSearchModel() { StartDt = DateTime.Today.AddDays(-7), EndDt = DateTime.Today.AddDays(1) }; var filterQuery = GetFilterQuery(checkUnitService, itemNameService, model, userInstIds, userItems); var mapResponse = tbpitemESRep.Search(s => s.Size(0).Query(filterQuery) .Aggregations(af => af.Terms(aggeKey, item => item.Field(iif => iif.CUSTOMID).Size(1000) .Aggregations(aaaf => aaaf.Terms("Conclution", aaa => aaa.Field(aac => aac.CONCLUSIONCODE)).Terms("Havelog", aab => aab.Field(aad => aad.HAVELOG)) )))); if (mapResponse.IsValid) { var bucks = mapResponse.Aggs.Terms(aggeKey).Buckets; foreach (var item in bucks) { var unqualiBucks = item.Terms("Conclution").Buckets; var modifyBucks = item.Terms("Havelog").Buckets; var customId = item.Key; var unitArea = string.Empty; var areaBool = allUnitByArea.TryGetValue(item.Key, out unitArea); if (areaBool) { GetDictResult(countByArea, item, unitArea); } else { unitArea = "其他"; GetDictResult(countByArea, item, unitArea); } foreach (var unqualifyItem in unqualiBucks) { if (unqualifyItem.Key == "N" || unqualifyItem.Key == "n") { GetDictResult(unQualifyCount, unqualifyItem, unitArea); } } foreach (var modifyItem in modifyBucks) { if (modifyItem.Key == "1") { GetDictResult(ModifyCount, modifyItem, unitArea); } } } foreach (var item in countByArea) { GetEchartValue(EchartTotalReportsCount, allArea, item); } foreach (var item in unQualifyCount) { GetEchartValue(EchartUnqualifyReportsCount, allArea, item); } foreach (var item in ModifyCount) { GetEchartValue(EcharModifyReportsCount, allArea, item); } foreach (var item in EchartTotalReportsCount) { EchartNameValue echart = new EchartNameValue() { name = item.Key, value = item.Value }; viewmodel.EchartTotalReportsCount.Add(echart); } foreach (var item in EchartUnqualifyReportsCount) { EchartNameValue echart = new EchartNameValue() { name = item.Key, value = item.Value }; viewmodel.EchartUnqualifyReportsCount.Add(echart); } foreach (var item in EcharModifyReportsCount) { EchartNameValue echart = new EchartNameValue() { name = item.Key, value = item.Value }; viewmodel.EcharModifyReportsCount.Add(echart); } viewmodel.EchartTotalReportsCount = viewmodel.EchartTotalReportsCount.OrderBy(s => s.name).ToList(); viewmodel.EchartUnqualifyReportsCount = viewmodel.EchartUnqualifyReportsCount.OrderBy(s => s.name).ToList(); viewmodel.EcharModifyReportsCount = viewmodel.EcharModifyReportsCount.OrderBy(s => s.name).ToList(); } #endregion #region 获得首页下部到期提醒数据 #endregion return(View(viewmodel)); }