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

405 lines
13 KiB

using System;
using System.Collections.Generic;
using System.Data;
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;
using QMFrameWork.Common.ExcelOperation;
using QMFrameWork.Log;
using ExcelOperationHelper = QMAPP.MESReport.Web.Common.ExcelOperationHelper;
namespace QMAPP.MESReport.Web.Controllers
{
/// <summary>
/// 维修平均时间
/// 周晓东
/// 2017-10-20
/// </summary>
public class AnDongRepairTimeAvgController : QController
{
public ActionResult List()
{
AnDongCallVModel seachModel = new AnDongCallVModel();
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");
return View(seachModel);
}
#region //报表
/// <summary>
/// 异步刷新TABLE
/// </summary>
/// <param name="pageIndex"></param>
/// <returns></returns>
public ActionResult GetTable(string START_DATE, string END_DATE)
{
ServiceAgent wcfAgent = this.GetServiceAgent();
AnDongCallDModel condition = new AnDongCallDModel();
condition.START_DATE = START_DATE;
condition.END_DATE = END_DATE;
List<AnDongCallDModel> nli = new List<AnDongCallDModel>();
try
{
#region wcf服务统一接口
var dataResult = wcfAgent.InvokeServiceFunction<DataResult<List<AnDongCallDModel>>>("AnDongCallBLL_GetRepairTimeAvg", condition);
nli = dataResult.Result;
#endregion
}
catch (Exception ex)
{
throw ex;
}
string sss = GetHTMLStr(nli);
return Json(sss);
}
/// <summary>
/// 拼接字符串
/// </summary>
/// <returns></returns>
public string GetHTMLStr(List<AnDongCallDModel> nli)
{
StringBuilder html = new StringBuilder();
if (nli == null || nli.Count == 0)
{
return "没有数据";
}
//拼接表头
html.Append("<tr><td ></td>");
foreach (AnDongCallDModel item in nli)
{
html.Append("<td>");
html.Append(item.MACHINENAME);
html.Append("</td>");
}
html.Append("</tr>");
//拼接第一行
html.Append("<tr><td >时间</td>");
foreach (AnDongCallDModel item in nli)
{
html.Append("<td>");
html.Append(item.REPAIR_TIME);
html.Append("</td>");
}
html.Append("</tr>");
//拼接第二行
html.Append("<tr><td >次数</td>");
foreach (AnDongCallDModel item in nli)
{
html.Append("<td>");
html.Append(item.NUM);
html.Append("</td>");
}
html.Append("</tr>");
return html.ToString();
}
#endregion
#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
#region 图表
/// <summary>
/// 多图叠加
/// </summary>
/// <returns>处理结果</returns>
[HandleException]
public ActionResult GetEchartDataGroup1()
{
AnDongCallVModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
AnDongCallDModel condition = null;
List<AnDongCallDModel> nli = new List<AnDongCallDModel>();
try
{
//获取查询对象
seachModel = GetModel<AnDongCallVModel>();
if (string.IsNullOrEmpty(seachModel.START_DATE) || string.IsNullOrEmpty(seachModel.END_DATE))
{
//return Content(null);
}
else
{
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel<AnDongCallDModel, AnDongCallVModel>(seachModel);
#region wcf服务统一接口
var dataResult =
wcfAgent.InvokeServiceFunction<DataResult<List<AnDongCallDModel>>>(
"AnDongCallBLL_GetRepairTimeAvg", condition);
nli = dataResult.Result;
#endregion
}
}
catch (Exception ex)
{
throw ex;
}
#region 源数据定义
string fenmu = "", fenzi = "", bfb = "", xLabe = "", dou = "";
bool first = true;
foreach (AnDongCallDModel item in nli)
{
fenmu += dou + "'" + item.NUM + "'";
fenzi += dou + "'" + item.REPAIR_TIME + "'";
bfb += dou + "'" + (Convert.ToDouble(item.REPAIR_TIME) / Convert.ToDouble(item.NUM)).ToString("0") + "'";
xLabe += dou + "'" + item.MACHINENAME + "'";
if (first)
{
first = false;
dou = ",";
}
}
string strOption = @"{
noDataLoadingOption: {
text: '无数据',
effect: 'bubble',
effectOption: {
effect: {
n: 0
}
}
},
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:0,
rotate:10
},
data: [" + xLabe + @"]
}
],
yAxis: [
{
type: 'value',
name: '维修时间(分钟)',
axisLabel: {
formatter: '{value}'
}
},
{
type: 'value',
name: '平均时间(分钟)',
axisLabel: {
formatter: '{value}'
}
}
],
series: [
{
name: '修理时间',
type: 'bar',
data: [" + fenzi + @"]
},
{
name: '修理次数',
type: 'bar',
data: [" + fenmu + @"]
},
{
name: '平均时间',
type: 'line',
yAxisIndex: 1,
data: [" + bfb + @"]
, itemStyle: { normal: { label: { show: true}} }
}
]
}";
#endregion
return Content(strOption);
}
/// <summary>
/// 统计图页面配置
/// </summary>
/// <returns></returns>
public static string QMEChartPageConfig()
{
StringBuilder configBuilder = new StringBuilder();
configBuilder.AppendLine("");
configBuilder.AppendLine("<!--图表控件-->");
configBuilder.AppendLine("<script src=\"../../Scripts/echarts-2.2.2/build/dist/echarts.js\" type=\"text/javascript\" language=\"javascript\"></script>");
configBuilder.AppendLine("<script type=\"text/javascript\">");
configBuilder.AppendLine("<!-- 路径配置-->");
configBuilder.AppendLine(" require.config({");
configBuilder.AppendLine(" paths: {");
configBuilder.AppendLine(" echarts: '../../Scripts/echarts-2.2.2/build/dist',");
configBuilder.AppendLine(" themes: '../../Scripts/echarts-2.2.2/src'");
configBuilder.AppendLine(" }");
configBuilder.AppendLine(" });");
configBuilder.AppendLine(" if (!window.console || !console.firebug) {");
configBuilder.AppendLine(" var names = ['log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml', 'group', 'groupEnd', 'time', 'timeEnd', 'count', 'trace', 'profile', 'profileEnd'];");
configBuilder.AppendLine(" window.console = {};");
configBuilder.AppendLine(" for (var i = 0; i < names.length; ++i)");
configBuilder.AppendLine(" window.console[names[i]] = function () { }");
configBuilder.AppendLine(" } ");
configBuilder.AppendLine("</script>");
return configBuilder.ToString();
}
#endregion
#region 导出excel
/// <summary>
/// 导出excel
/// </summary>
/// <returns>结果</returns>
[HandleException]
public ActionResult ExportExcel()
{
AnDongCallVModel seachModel = null;
AnDongCallDModel condition = null;
DataTable exportDt = new DataTable();
string selectKey = Request["selectKey"];
ServiceAgent wcfAgent = this.GetServiceAgent();
try
{
//获取查询对象
seachModel = GetModel<AnDongCallVModel>();
condition = CopyToModel<AnDongCallDModel, AnDongCallVModel>(seachModel);
//选择Excel
condition.selectExcel = 1;
//获取数据
var dataResult = wcfAgent.InvokeServiceFunction<DataResult<DataTable>>("AnDongCallBLL_GetExportData", condition);
//通过返回dataResult判断
if (dataResult.Ex != null)
{
throw dataResult.Ex;
}
else if (dataResult.IsSuccess)
{
exportDt = dataResult.Result;
}
else
{
SetMessage(dataResult.Msg);
return View(true);
}
//根据所选信息进行导出
if (!String.IsNullOrEmpty(selectKey))
{
DataView dv = new DataView(exportDt);
string strWhere = "";
string[] list = selectKey.Split(":".ToCharArray());
foreach (string ID in list)
{
strWhere += " PID='" + ID + "' or";
}
if (strWhere != "")
{
strWhere = strWhere.Remove((strWhere.Length - 2), 2);
}
dv.RowFilter = strWhere;
exportDt = dv.ToTable();
}
//导出
IEExcelHelper ieExcelHelper = new IEExcelHelper();
var sheetInfo = ieExcelHelper.GetMainInfo("AnDongRepairTimeAvgExp");
var fileName = System.Guid.NewGuid().ToString() + ".xlsx";
ieExcelHelper.ExportExcel(sheetInfo, exportDt, Common.ExcelOperationHelper.GetTempPath() + fileName, true);
return Content(fileName);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo { ErrorInfo = ex, Info = "导出excel", Tag = "平均故障恢复时间" });
SetMessage("导出excel失败");
return View(true);
}
}
/// <summary>
/// 导出文件
/// </summary>
/// <returns></returns>
public ActionResult ExportFile()
{
String filePath = Common.ExcelOperationHelper.GetTempPath();
String fileName = Request["FileName"];
ExcelOperationHelper.FileDownload(Response, filePath + fileName, "平均故障恢复时间.xlsx");
return Content("");
}
#endregion
}
}