一厂MES,含注塑,喷涂,冲孔
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.
 
 
 
 
 

367 lines
14 KiB

using MESClassLibrary;
using MESClassLibrary.BLL.Log;
using MESClassLibrary.BLL.Show;
using MESClassLibrary.EFModel;
using MESClassLibrary.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MESWebSite.Manage
{
public partial class AnalysisApi : System.Web.UI.Page
{
public static string GoodsListHtml;
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["LoginUserInfo"] == null)
{
Response.Write("<script language=javascript>alert('您的登录信息已过期,请重新登录!');top.location.href='../Login.aspx';</script>");
}
}
[WebMethod]
public static string GetBarDate(string side, string ProductName)
{
try
{
AnalysisBLL bll = new AnalysisBLL();
List<tb_InspectResult> list = bll.SearchInfo(ProductName);
List<AnalysisBarModel> listModel = new List<AnalysisBarModel>();
BuildBar(side, "S前保", ProductName, list, ref listModel);
BuildBar(side, "S后保", ProductName, list, ref listModel);
BuildBar(side, "AMG前保", ProductName, list, ref listModel);
BuildBar(side, "AMG后保", ProductName, list, ref listModel);
return JSONTools.ScriptSerialize(listModel);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return "";
}
}
[WebMethod]
public static string GetLineTable(string side, string ProductName)
{
try
{
try
{
AnalysisBLL bll = new AnalysisBLL();
List<string> r_list = new List<string>();
List<tb_InspectResult> list = bll.SearchInfo(ProductName);
list = list.Where(p => p.InspectTimes.Equals("1") && p.side.Equals(side)).ToList();
BuildLineTable("S前保", list, ref r_list);
BuildLineTable("S后保", list, ref r_list);
BuildLineTable("AMG前保", list, ref r_list);
BuildLineTable("AMG后保", list, ref r_list);
BuildLineTable("S左门槛", list, ref r_list);
BuildLineTable("S右门槛", list, ref r_list);
BuildLineTable("AMG左门槛", list, ref r_list);
BuildLineTable("AMG右门槛", list, ref r_list);
return JSONTools.ScriptSerialize(r_list);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return "";
}
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return "";
}
}
[WebMethod]
public static string GetLineData(string side, string ProductName)
{
try
{
List<string> categories = new List<string>();
List<string> data = new List<string>();
AnalysisBLL bll = new AnalysisBLL();
List<tb_InspectResult> list = bll.SearchInfo(ProductName);
list = list.Where(p => p.InspectTimes.Equals("1") && p.side.Equals(side)).ToList();
DateTime date = DateTime.Now;
//DateTime date = Convert.ToDateTime("2019-06-20 7:00:00");
string nowTime = date.ToString("yyyy-MM-dd");
DateTime startTime = Convert.ToDateTime(nowTime + " 08:00:00");//班次开始时间
DateTime endTime = Convert.ToDateTime(nowTime + " 19:59:59");//班次结束时间
if (DateTime.Compare(date, startTime) < 0)
{
//昨天夜班
for (int i = 1; i <= 12; i++)
{
categories.Add(endTime.AddDays(-1).AddHours(i).Hour.ToString() + "点");
var t = list.Where(p => p.createTime >= endTime.AddDays(-1).AddHours(i - 1) && p.createTime <= endTime.AddDays(-1).AddHours(i)).ToList();
if (t != null && t.Count > 0)
{
double r = (double)t.Where(p => p.inspectResult.Equals("[合格]")).Count() / (double)t.Count;
data.Add(Math.Round(r * 100, 2).ToString());
}
else
{
data.Add("0.00%");
}
}
}
if (DateTime.Compare(date, endTime) > 0)
{
//今天夜班
for (int i = 1; i <= 12; i++)
{
categories.Add(endTime.AddHours(i).Hour.ToString() + "点");
var t = list.Where(p => p.createTime > endTime.AddHours(i - 1) && p.createTime <= endTime.AddHours(i)).ToList();
if (t != null && t.Count > 0)
{
double r = (double)t.Where(p => p.inspectResult.Equals("[合格]")).Count() / (double)t.Count;
data.Add(Math.Round(r * 100, 2).ToString());
}
else
{
data.Add("0.00%");
}
}
}
if (DateTime.Compare(date, startTime) >= 0 && DateTime.Compare(date, endTime) <= 0)
{
//今天白班
for (int i = 1; i <= 12; i++)
{
categories.Add(startTime.AddHours(i).Hour.ToString() + "点");
var t = list.Where(p => p.createTime >= startTime.AddHours(i - 1) && p.createTime <= startTime.AddHours(i)).ToList();
if (t != null && t.Count > 0)
{
double r = (double)t.Where(p => p.inspectResult.Equals("[合格]")).Count() / (double)t.Count;
data.Add(Math.Round(r * 100, 2).ToString());
}
else
{
data.Add("0.00");
}
}
}
AnalysisBarModel analysisBarModel = new AnalysisBarModel();
analysisBarModel.text = "";
analysisBarModel.subtext = "一次合格率(%)";
analysisBarModel.categories = categories;
analysisBarModel.data = data;
return JSONTools.ScriptSerialize(analysisBarModel);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return "";
}
}
[WebMethod]
public static string GetPieData(string reason, string ProductName)
{
try
{
AnalysisBLL bll = new AnalysisBLL();
List<tb_InspectResult> list = bll.SearchInfo(ProductName);
List<tb_InspectResult> info = new List<tb_InspectResult>();
if ("其他".Equals(reason))
{
info = list.Where(p =>
p.reason != null
&& !p.reason.Contains("颗粒;")
//&& !p.reason.Contains("浮泡;")
&& !p.reason.Contains("流挂;")
&& !p.reason.Contains("遮盖不良;")
//&& !p.reason.Contains("异色;")
//&& !p.reason.Contains("水迹;")
).ToList();
}
else
{
info = list.Where(p => p.reason != null && p.reason.Contains(reason + ";")).ToList();
}
List<AnalysisPieModel> listModel = new List<AnalysisPieModel>();
BuildPieData("A侧", ProductName, "上支架", reason, info, ref listModel);
BuildPieData("A侧", ProductName, "中支架", reason, info, ref listModel);
BuildPieData("A侧", ProductName, "下支架", reason, info, ref listModel);
BuildPieData("B侧", ProductName, "上支架", reason, info, ref listModel);
BuildPieData("B侧", ProductName, "中支架", reason, info, ref listModel);
BuildPieData("B侧", ProductName, "下支架", reason, info, ref listModel);
return JSONTools.ScriptSerialize(listModel);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return "";
}
}
private static void BuildBar(string side, string partName, string ProductName, List<tb_InspectResult> list, ref List<AnalysisBarModel> listModel)
{
try
{
var A_list = list.Where(p => side.Equals(p.side) && p.productInfo.Contains(partName)).OrderByDescending(p => p.createTime).ToList();
List<string> barcodeList = new List<string>();
List<tb_InspectResult> newlist = new List<tb_InspectResult>();
foreach (var item in A_list)
{
if (barcodeList.Contains(item.barcode))
{
continue;
}
barcodeList.Add(item.barcode);
newlist.Add(item);
}
Dictionary<string, int> colorList = new Dictionary<string, int>();
foreach (var item in newlist)
{
string pinfo = item.productInfo;
pinfo = pinfo.Substring(0, pinfo.IndexOf(","));
if (!colorList.ContainsKey(pinfo))
{
colorList.Add(pinfo, 0);
}
if ("[合格]".Equals(item.inspectResult))
{
colorList[pinfo] = colorList[pinfo] + 1;
}
}
List<string> categories = new List<string>();
List<string> data = new List<string>();
foreach (KeyValuePair<string, int> kvp in colorList)
{
categories.Add(kvp.Key);
double r = (double)kvp.Value / (double)newlist.Count;
data.Add(Math.Round(r * 100, 2).ToString());
}
AnalysisBarModel analysisBarModel = new AnalysisBarModel();
analysisBarModel.text = side + " " + ProductName + " " + partName;
analysisBarModel.subtext = "颜色合格率分析";
analysisBarModel.categories = categories;
analysisBarModel.data = data;
listModel.Add(analysisBarModel);
}
catch (Exception)
{
}
}
private static void BuildLineTable(string partName, List<tb_InspectResult> list, ref List<string> listModel)
{
double cnum = 0;
double num = 0;
double r = 0;
var info = list.Where(p => p.productInfo.Contains(partName));
if (info.Count() > 0)
{
cnum = info.Count();
num = info.Where(p => p.inspectResult.Equals("[合格]")).Count();
r = num / cnum;
listModel.Add(Math.Round(r * 100, 2).ToString() + "%");
}
else
{
listModel.Add("0.00%");
}
}
private static void BuildPieData(string side, string ProductName, string position, string reason, List<tb_InspectResult> list, ref List<AnalysisPieModel> listModel)
{
List<tb_InspectResult> info = list.Where(p => p.side.Equals(side) && p.position.Contains(position)).ToList();
List<string> damnPositionList = new List<string>();
foreach (var item in info)
{
if (String.IsNullOrWhiteSpace(item.damnPosition))
{
continue;
}
string[] sArray = item.damnPosition.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
if (sArray.Length > 0)
{
foreach (var damn in sArray)
{
if (!damnPositionList.Contains(damn))
{
damnPositionList.Add(damn);
}
}
}
}
List<PieDataModel> data = new List<PieDataModel>();
foreach (var item in damnPositionList)
{
PieDataModel pieDataModel = new PieDataModel();
pieDataModel.value = info.Where(p => p.damnPosition.Contains(item)).Count();
pieDataModel.name = item + "区";
data.Add(pieDataModel);
}
AnalysisPieModel analysisPieModel = new AnalysisPieModel();
analysisPieModel.text = side + " " + ProductName + " " + position + " " + reason;
analysisPieModel.data = data;
listModel.Add(analysisPieModel);
}
}
}