using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using QMAPP.MESReport.Web.Models.LineQTY; using QMAPP.Common.Web.Controllers; using QMFrameWork.WebUI.Attribute; using QMFrameWork.Data; using QMAPP.Entity; using QMAPP.ServicesAgent; using QMAPP.MESReport.Entity.LineQTY; using System.Text; namespace QMAPP.MESReport.Web.Controllers { /// /// 设备用电分析 /// 于子清 /// 2017-11-3 /// public class EquConsumeCountController : QController { public ActionResult Index(bool? callback) { EquConsumeCountVModel seachModel = new EquConsumeCountVModel(); seachModel.START_DATE = DateTime.Now.Date.AddDays(-30).ToString("yyyy-MM-dd HH:mm:ss"); seachModel.END_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //if (callback == true) // TryGetSelectBuffer(out seachModel); //seachModel.url = "/EqptConsume/GetList"; //return View("List", seachModel); return View(seachModel); } /// /// 异步刷新TABLE /// /// /// public ActionResult GetTable(string EQPT_CODE, string TYPE_COUNT, string START_DATE, string END_DATE) { ServiceAgent wcfAgent = this.GetServiceAgent(); EquConsumeCountDModel condition = new EquConsumeCountDModel(); condition.EQPT_CODE = EQPT_CODE; condition.TYPE_COUNT = TYPE_COUNT; condition.START_DATE = START_DATE; condition.END_DATE = END_DATE; List nli = new List(); try { #region wcf服务统一接口 var dataResult = wcfAgent.InvokeServiceFunction>>("EquConsumeCountBLL_GetAllList", condition); nli = dataResult.Result; #endregion } catch (Exception ex) { throw ex; } string sss = GetHTMLStr(nli, TYPE_COUNT); return Json(sss); } /// /// 拼接字符串 /// /// public string GetHTMLStr(List nli, string TYPE_COUNT) { StringBuilder html = new StringBuilder(); if (nli == null) { return "没有数据"; } //拼接表头 第一行 html.Append("产品种类"); string timetype = "号"; if (TYPE_COUNT == "YEAR") { timetype = "年"; } else if (TYPE_COUNT == "MONTH") { timetype = "月"; } List arr = new List(); foreach (EquConsumeCountDModel item in nli) { if (html.ToString().Contains(item.TDAY + timetype)) { continue; } html.Append(""); if (item.TDAY.Equals("累计")) { html.Append(item.TDAY); } else { html.Append(item.TDAY + timetype); arr.Add(item.TDAY + timetype); } html.Append(""); } html.Append(""); //新排序 Dictionary> DLEq = new Dictionary>(); foreach (EquConsumeCountDModel item in nli) { if (DLEq.Keys.Contains(item.MACHINENAME)) { DLEq[item.MACHINENAME].Add(item); continue; } else { List li = new List(); li.Add(item); DLEq.Add(item.MACHINENAME, li); } } //拼接主体数据 foreach (string item in DLEq.Keys) { html.Append(""); html.Append(""+item); html.Append(""); foreach (string itit in arr) { bool sss = true; string CONSUME = ""; foreach (EquConsumeCountDModel its in DLEq[item]) { if (its.TDAY+timetype==itit) { sss = false; CONSUME=its.CONSUME; break; } } if (sss) { html.Append("0"); } else { html.Append("" + CONSUME + ""); } } html.Append(""); } return html.ToString(); } /// /// 堆积柱状图 /// /// 处理结果 [HandleException] public ActionResult GetEchartDataBar2() { EquConsumeCountVModel seachModel = null; DataPage page = null; ServiceAgent wcfAgent = this.GetServiceAgent(); EquConsumeCountDModel condition = null; List nli = new List(); try { //获取查询对象 seachModel = GetModel(); //获取前台分页设置信息 page = this.GetDataPage(seachModel); condition = CopyToModel(seachModel); #region wcf服务统一接口 var dataResult = wcfAgent.InvokeServiceFunction>>("EquConsumeCountBLL_GetAllList", condition); nli = dataResult.Result; #endregion } catch (Exception ex) { throw ex; } string XZ = "", yongdian = "", dou = "", tday = "", timetype = "号:"; bool first = true; if (condition.TYPE_COUNT == "YEAR") { timetype = "年:"; } else if (condition.TYPE_COUNT == "MONTH") { timetype = "月:"; } //if (nli == null) //{ // return Content("没有数据"); //} if (nli == null || nli.Count == 0) { yongdian += "''"; //wancheng += "''"; tday += "''"; XZ += "''"; } else { //新排序 Dictionary> DLEq = new Dictionary>(); foreach (EquConsumeCountDModel item in nli) { if (DLEq.Keys.Contains(item.EQPT_CODE)) { DLEq[item.EQPT_CODE][0].CONSUME = (Convert.ToDouble(DLEq[item.EQPT_CODE][0].CONSUME) + Convert.ToDouble(item.CONSUME)) .ToString(); continue; } else { List li = new List(); li.Add(item); DLEq.Add(item.EQPT_CODE, li); } } foreach (string item in DLEq.Keys) { XZ += dou + "'" + item + "'"; yongdian += dou + "'" + DLEq[item][0].CONSUME + "'"; tday += dou + "'" + DLEq[item][0].TDAY + timetype +item+ "'"; if (first) { first = false; dou = ","; } } } #region 源数据定义 string strOption = @"{ tooltip: { trigger: 'axis' }, toolbox: { show: false, feature: { mark: { show: true }, dataView: { show: true, readOnly: false }, magicType: { show: true, type: ['line', 'bar'] }, restore: { show: true }, saveAsImage: { show: true } } }, calculable: true, legend: { data: ['设备能耗'] }, xAxis: [ { type: 'category', axisLabel : { //坐标轴刻度标签的相关设置。 interval:'auto', rotate:20 }, data: [" + XZ + @"] } ], yAxis: [ { type: 'value', name: 'KWh', axisLabel: { formatter: '{value}' } } ], series: [ { name: '设备能耗', type: 'bar', data: [" +yongdian+@"] } ] }"; #endregion return Content(strOption); } #region 导出图片 [HttpPost] [HandleException] public ActionResult ExportBanCi() { string imgSend = Request.Form["hiChartImg"]; imgSend = imgSend.Replace(" ", "+"); string[] contents = imgSend.Split(','); imgSend = contents[1]; byte[] content = Convert.FromBase64String(imgSend); System.Web.Mvc.FileContentResult result = null; result = new System.Web.Mvc.FileContentResult(content, "application/png"); result.FileDownloadName = System.Web.HttpUtility.UrlEncode("生产统计.png", System.Text.Encoding.UTF8); return result; } #endregion } }