天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

344 lines
10 KiB

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
{
/// <summary>
/// 设备用电分析
/// 于子清
/// 2017-11-3
/// </summary>
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<EquConsumeCountDModel>(out seachModel);
//seachModel.url = "/EqptConsume/GetList";
//return View("List", seachModel);
return View(seachModel);
}
/// <summary>
/// 异步刷新TABLE
/// </summary>
/// <param name="pageIndex"></param>
/// <returns></returns>
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<EquConsumeCountDModel> nli = new List<EquConsumeCountDModel>();
try
{
#region wcf服务统一接口
var dataResult = wcfAgent.InvokeServiceFunction<DataResult<List<EquConsumeCountDModel>>>("EquConsumeCountBLL_GetAllList", condition);
nli = dataResult.Result;
#endregion
}
catch (Exception ex)
{
throw ex;
}
string sss = GetHTMLStr(nli, TYPE_COUNT);
return Json(sss);
}
/// <summary>
/// 拼接字符串
/// </summary>
/// <returns></returns>
public string GetHTMLStr(List<EquConsumeCountDModel> nli, string TYPE_COUNT)
{
StringBuilder html = new StringBuilder();
if (nli == null)
{
return "没有数据";
}
//拼接表头 第一行
html.Append("<tr><td class='L1cos'>产品种类</td>");
string timetype = "号";
if (TYPE_COUNT == "YEAR")
{
timetype = "年";
}
else if (TYPE_COUNT == "MONTH")
{
timetype = "月";
}
List<string> arr = new List<string>();
foreach (EquConsumeCountDModel item in nli)
{
if (html.ToString().Contains(item.TDAY + timetype))
{
continue;
}
html.Append("<td>");
if (item.TDAY.Equals("累计"))
{
html.Append(item.TDAY);
}
else
{
html.Append(item.TDAY + timetype);
arr.Add(item.TDAY + timetype);
}
html.Append("</td>");
}
html.Append("</tr>");
//新排序
Dictionary<string, List<EquConsumeCountDModel>> DLEq = new Dictionary<string, List<EquConsumeCountDModel>>();
foreach (EquConsumeCountDModel item in nli)
{
if (DLEq.Keys.Contains(item.MACHINENAME))
{
DLEq[item.MACHINENAME].Add(item);
continue;
}
else
{
List<EquConsumeCountDModel> li = new List<EquConsumeCountDModel>();
li.Add(item);
DLEq.Add(item.MACHINENAME, li);
}
}
//拼接主体数据
foreach (string item in DLEq.Keys)
{
html.Append("<tr>");
html.Append("<td>"+item);
html.Append("</td>");
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("<td>0</td>");
}
else
{
html.Append("<td>" + CONSUME + "</td>");
}
}
html.Append("</tr>");
}
return html.ToString();
}
/// <summary>
/// 堆积柱状图
/// </summary>
/// <returns>处理结果</returns>
[HandleException]
public ActionResult GetEchartDataBar2()
{
EquConsumeCountVModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
EquConsumeCountDModel condition = null;
List<EquConsumeCountDModel> nli = new List<EquConsumeCountDModel>();
try
{
//获取查询对象
seachModel = GetModel<EquConsumeCountVModel>();
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel<EquConsumeCountDModel, EquConsumeCountVModel>(seachModel);
#region wcf服务统一接口
var dataResult = wcfAgent.InvokeServiceFunction<DataResult<List<EquConsumeCountDModel>>>("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<string, List<EquConsumeCountDModel>> DLEq =
new Dictionary<string, List<EquConsumeCountDModel>>();
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<EquConsumeCountDModel> li = new List<EquConsumeCountDModel>();
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
}
}