天津投入产出系统后端
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
9.6 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
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 QMFrameWork.WebUI.DataSource;
using QMFrameWork.Common.Serialization;
using QMAPP.MESReport.Entity.LineQTY;
using System.Collections;
using System.Reflection;
using QMFrameWork.ServiceInterface;
using System.Data.SqlClient;
using System.Data;
using QMAPP.Common.Web.Util;
using QMFrameWork.WebUI.QMEChart;
using QMFrameWork.WebUI.QMEChart.Data;
using QMAPP.MESReport.Web.Models;
using QMAPP.MESReport.BLL.LineQTY;
using System.Text;
namespace QMAPP.MESReport.Web.Controllers
{
/// <summary>
/// 设备利用率分析
/// 于子清
/// 2017-10-26
/// </summary>
public class EqueUseCountController : QController
{
public ActionResult Index()
{
return View();
}
/// <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();
EqueUseCountDModel condition = new EqueUseCountDModel();
condition.EQPT_CODE = EQPT_CODE;
condition.TYPE_COUNT = TYPE_COUNT;
condition.START_DATE = START_DATE;
condition.END_DATE = END_DATE;
List<EqueUseCountDModel> nli = new List<EqueUseCountDModel>();
try
{
#region wcf服务统一接口
var dataResult = wcfAgent.InvokeServiceFunction<DataResult<List<EqueUseCountDModel>>>("EqueUseCountBLL_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<EqueUseCountDModel> nli, string TYPE_COUNT)
{
StringBuilder html = new StringBuilder();
if (nli == null)
{
return "没有数据";
}
//拼接表头 第一行
html.Append("<tr><td class='L1cos'>产品种类</td>");
string timetype = "号";
if (TYPE_COUNT == "WEEK")
{
timetype = "周";
}
else if (TYPE_COUNT == "MONTH")
{
timetype = "月";
}
foreach (EqueUseCountDModel 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);
}
html.Append("</td>");
}
html.Append("</tr>");
//拼接主体数据
html.Append("<tr>");
html.Append("<td>开机时间(h)");
html.Append("</td>");
foreach (EqueUseCountDModel item in nli)
{
html.Append("<td>");
html.Append(item.BOOTTIMES);
html.Append("</td>");
}
html.Append("</tr>");
html.Append("<tr>");
html.Append("<td>加工时间(h)");
html.Append("</td>");
foreach (EqueUseCountDModel item in nli)
{
html.Append("<td>");
html.Append(item.WORKTIMES);
html.Append("</td>");
}
html.Append("</tr>");
html.Append("<tr>");
html.Append("<td>利用率");
html.Append("</td>");
foreach (EqueUseCountDModel item in nli)
{
html.Append("<td>");
html.Append((Convert.ToDouble(item.WORKTIMES) / Convert.ToDouble(item.BOOTTIMES) * 100).ToString("0")+"%");
html.Append("</td>");
}
html.Append("</tr>");
html.Append("<tr>");
html.Append("<td>目标值");
html.Append("</td>");
foreach (EqueUseCountDModel item in nli)
{
html.Append("<td>");
html.Append(item.val+"%");
html.Append("</td>");
}
html.Append("</tr>");
return html.ToString();
}
/// <summary>
/// 堆积柱状图
/// </summary>
/// <returns>处理结果</returns>
[HandleException]
public ActionResult GetEchartDataBar2()
{
EqueUseCountVModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
EqueUseCountDModel condition = null;
List<EqueUseCountDModel> nli = new List<EqueUseCountDModel>();
try
{
//获取查询对象
seachModel = GetModel<EqueUseCountVModel>();
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel<EqueUseCountDModel, EqueUseCountVModel>(seachModel);
#region wcf服务统一接口
var dataResult = wcfAgent.InvokeServiceFunction<DataResult<List<EqueUseCountDModel>>>("EqueUseCountBLL_GetAllList", condition);
nli = dataResult.Result;
#endregion
}
catch (Exception ex)
{
throw ex;
}
string kaiji = "", jiagong = "", wlv = "", mlv = "",dou="",tday="",timetype="号";
bool first = true;
if (condition.TYPE_COUNT=="WEEK")
{
timetype = "周";
}
else if (condition.TYPE_COUNT=="MONTH")
{
timetype = "月";
}
if (nli==null)
{
return Content("没有数据");
}
foreach (EqueUseCountDModel item in nli)
{
kaiji += dou + "'" + item.BOOTTIMES + "'";
jiagong += dou + "'" + item.WORKTIMES + "'";
wlv += dou + "'" + (Convert.ToDouble(item.WORKTIMES) / Convert.ToDouble(item.BOOTTIMES) * 100).ToString("0") + "'";
mlv += dou + "'" + item.val + "'";
tday += dou + "'" + item.TDAY + timetype + "'";
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',
data: [" + tday + @"]
}
],
yAxis: [
{
type: 'value',
name: '小时',
axisLabel: {
formatter: '{value} h'
}
},
{
type: 'value',
name: '百分比',
axisLabel: {
formatter: '{value} %'
}
}
],
series: [
{
name: '开机时间',
type: 'bar',
data: [" + kaiji + @"]
},
{
name: '加工时间',
type: 'bar',
data: [" + jiagong + @"]
},
{
name: '利用率',
type: 'line',
yAxisIndex: 1,
data: [" + wlv + @"]
,itemStyle: { normal: { label: { show: true}} }
},
{
name: '目标值',
type: 'line',
yAxisIndex: 1,
data: [" + mlv + @"]
, itemStyle: { normal: { label: { show: true}} }
}
]
}";
#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
}
}