301 lines
14 KiB
C#
301 lines
14 KiB
C#
using AUTS.Domain.Entities;
|
|
using AUTS.Domain.ViewModels;
|
|
using AUTS.Services.DBUtility.Custom;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AUTS.Services.Manager
|
|
{
|
|
public partial class PPlans
|
|
{
|
|
/// <summary>
|
|
/// 内部单记录详情
|
|
/// </summary>
|
|
/// <param name="id">内部单ID</param>
|
|
/// <param name="cacheUserProject">机型缓存</param>
|
|
/// <param name="cacheUserOrderInternal">内部单缓存</param>
|
|
/// <param name="cacheUserOrder">订单缓存</param>
|
|
/// <param name="cacheUserCustomer">客户缓存</param>
|
|
/// <returns></returns>
|
|
public static VM_TBL_PPlanInternalDetails GetPPlanInternalDetails(int id, List<TBL_Project> cacheUserProject, List<TBL_OrderInternal> cacheUserOrderInternal, List<TBL_Orders> cacheUserOrder, List<TBL_Customer> cacheUserCustomer)
|
|
{
|
|
var vmodel = new VM_TBL_PPlanInternalDetails();
|
|
|
|
|
|
var orderInternalModel = cacheUserOrderInternal.Single(x => x.ID == id);//内部单
|
|
var orderModel = cacheUserOrder.Single(x => x.ID == orderInternalModel.OrderID);//订单
|
|
var project = cacheUserProject.Single(x => x.ID == orderModel.ProductID);//机型
|
|
var customer = cacheUserCustomer.Single(x => x.ID == orderModel.CompanyID);//客户
|
|
|
|
vmodel.ID = orderInternalModel.ID;
|
|
vmodel.OrderNo = orderModel.OrderNo;
|
|
vmodel.InternalNo = orderInternalModel.InternalNo;
|
|
vmodel.ProjectName = project.ProjectName;
|
|
vmodel.CustomerAbbr = customer.CustomerAbbr;
|
|
vmodel.DeliveryTime = orderModel.DeliveryTime;
|
|
|
|
|
|
var pPlanList = new DALHelperCustom<VM_TBL_PPlan>("TBL_ProductionPlan").GetList("OrderInternalID=" + id);
|
|
|
|
vmodel.PPlanList = pPlanList;
|
|
|
|
return vmodel;
|
|
}
|
|
|
|
public static ReturnResult<object> GetPPlanInternalDetails_New(int id, List<TBL_Project> cacheUserProject, List<TBL_OrderInternal> cacheUserOrderInternal, List<TBL_Orders> cacheUserOrder, List<TBL_Customer> cacheUserCustomer, List<TBL_StationList> cacheUserStationList)
|
|
{
|
|
ReturnResult<object> result = new ReturnResult<object>();
|
|
var vmodel = new VM_TBL_PPlanInternalDetails();
|
|
|
|
|
|
var orderInternalModel = cacheUserOrderInternal.Single(x => x.ID == id);//内部单
|
|
var orderModel = cacheUserOrder.Single(x => x.ID == orderInternalModel.OrderID);//订单
|
|
var project = cacheUserProject.Single(x => x.ID == orderModel.ProductID);//机型
|
|
var customer = cacheUserCustomer.Single(x => x.ID == orderModel.CompanyID);//客户
|
|
|
|
vmodel.ID = orderInternalModel.ID;
|
|
vmodel.OrderNo = orderModel.OrderNo;
|
|
vmodel.InternalNo = orderInternalModel.InternalNo;
|
|
vmodel.ProjectName = project.ProjectName;
|
|
vmodel.CustomerAbbr = customer.CustomerAbbr;
|
|
vmodel.DeliveryTime = orderModel.DeliveryTime;
|
|
|
|
|
|
var pPlanList = new DALHelperCustom<VM_TBL_PPlan>("TBL_ProductionPlan").GetList("OrderInternalID=" + id);//取出当前内部单全部计划
|
|
|
|
if (pPlanList == null)
|
|
{
|
|
result.Status = 200;
|
|
return result;
|
|
}
|
|
var timeGroupList = pPlanList.GroupBy(g => g.ProductionTime);//按时间分组
|
|
var stationGroupList = pPlanList.GroupBy(g => g.StationID);//按工艺站分组
|
|
|
|
//var stationIDs = stationGroupList.Select(s => s.Key).ToArray();
|
|
|
|
|
|
var excludedFactionSet = new HashSet<int>(stationGroupList.Select(s => s.Key));//取出ID放入比较器
|
|
|
|
var stationList = cacheUserStationList.Where(x => excludedFactionSet.Contains(x.ID)).OrderBy(o => o.ArtworkOrder);//按工艺站排序
|
|
|
|
DataTable tblDatas = new DataTable("Datas");
|
|
//DataColumn dc = null;
|
|
|
|
tblDatas.Columns.Add("站", Type.GetType("System.String"));//新列
|
|
tblDatas.Columns.Add("数据", Type.GetType("System.String"));//新列
|
|
|
|
foreach (var itemStation in stationList)
|
|
{
|
|
var stationName = cacheUserStationList.Single(x => x.ID == itemStation.ID).StationName;//取站名
|
|
//var stationName = cacheUserStationList.Single(x => x.StationID == itemStation.Key).StationName;//取站名
|
|
|
|
DataRow newRow = tblDatas.NewRow();//新行
|
|
newRow["站"] = stationName;
|
|
newRow["数据"] = "目标";
|
|
tblDatas.Rows.Add(newRow);
|
|
|
|
DataRow newRow2 = tblDatas.NewRow();
|
|
newRow2["站"] = stationName;
|
|
newRow2["数据"] = "累计";
|
|
tblDatas.Rows.Add(newRow2);
|
|
}
|
|
|
|
var rowKey = 0;
|
|
var timeStr = "";
|
|
var onPPlan = new VM_TBL_PPlan();
|
|
|
|
foreach (var item in timeGroupList)
|
|
{
|
|
timeStr = item.Key.ToString("yyyy/MM/dd");
|
|
tblDatas.Columns.Add(timeStr, Type.GetType("System.String"));//新列
|
|
rowKey = 0;
|
|
foreach (var itemStation in stationGroupList)
|
|
{
|
|
onPPlan = pPlanList.SingleOrDefault(x => x.ProductionTime == item.Key && x.StationID == itemStation.Key);
|
|
|
|
tblDatas.Rows[rowKey][timeStr] = onPPlan == null ? "" : onPPlan.ObjectiveYield.ToString();//目标
|
|
|
|
rowKey += 1;
|
|
|
|
tblDatas.Rows[rowKey][timeStr] = onPPlan == null ? "" : onPPlan.ObjectiveYieldTotal.ToString();//计划
|
|
rowKey += 1;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
|
|
|
|
foreach (DataRow Row in tblDatas.Rows)//循环行
|
|
{
|
|
Dictionary<string, object> row = new Dictionary<string, object>();
|
|
for (int i = 0; i < Row.ItemArray.Length; i++)
|
|
{
|
|
row.Add(tblDatas.Columns[i].ColumnName, Row[i].ToString());
|
|
}
|
|
rows.Add(row);
|
|
|
|
}
|
|
|
|
vmodel.rows = rows;
|
|
|
|
result.Data = vmodel;
|
|
result.Status = 200;
|
|
return result;
|
|
}
|
|
|
|
public static ReturnResult<object> GetPPlanInternalTable(int id, List<TBL_Project> cacheUserProject, List<TBL_OrderInternal> cacheUserOrderInternal, List<TBL_Orders> cacheUserOrder, List<TBL_Customer> cacheUserCustomer, List<TBL_StationList> cacheUserStationList)
|
|
{
|
|
ReturnResult<object> result = new ReturnResult<object>();
|
|
var vmodel = new VM_TBL_PPlanInternalDetails();
|
|
|
|
try
|
|
{
|
|
|
|
|
|
var orderInternalModel = cacheUserOrderInternal.Single(x => x.ID == id);//内部单
|
|
var orderModel = cacheUserOrder.FirstOrDefault(x => x.ID == orderInternalModel.OrderID);//订单
|
|
var project = cacheUserProject.FirstOrDefault(x => x.ID == orderInternalModel.ProductID);//机型
|
|
var customer = cacheUserCustomer.FirstOrDefault(x => x.ID == orderInternalModel.CompanyID);//客户
|
|
|
|
vmodel.ID = orderInternalModel.ID;
|
|
//vmodel.OrderNo = orderModel.OrderNo;
|
|
vmodel.InternalNo = orderInternalModel.InternalNo;
|
|
vmodel.ProjectName = project.ProjectName;
|
|
vmodel.ProjectID = project.ID;
|
|
//vmodel.CustomerAbbr = customer.CustomerAbbr;
|
|
//vmodel.DeliveryTimeStr = orderModel.DeliveryTime.ToString("yyyy/MM/dd");
|
|
vmodel.OrderCount = orderInternalModel.ObjectiveYield;
|
|
|
|
|
|
var stationList = cacheUserStationList.Where(x => x.ProjectID == orderInternalModel.ProductID).OrderBy(o => o.ArtworkOrder);//按工艺站排序
|
|
foreach (var item in stationList)
|
|
{
|
|
vmodel.StationText += "<strong>" + item.StationName + "</strong>" + "-" + item.StationDesc + " ";
|
|
}
|
|
|
|
var pPlanList = new DALHelperCustom<VM_TBL_PPlan>("TBL_ProductionPlan").GetList("OrderInternalID=" + id);//取出当前内部单全部计划
|
|
|
|
if (pPlanList == null)
|
|
{
|
|
result.Status = 200;
|
|
result.Data = vmodel;
|
|
return result;
|
|
}
|
|
var timeGroupList = pPlanList.OrderBy(o => o.ProductionTime).GroupBy(g => g.ProductionTime);//按时间分组
|
|
var stationGroupList = pPlanList.GroupBy(g => g.StationID);//按工艺站分组
|
|
|
|
var excludedFactionSet = new HashSet<int>(stationGroupList.Select(s => s.Key));//取出ID放入比较器
|
|
|
|
//var stationList = cacheUserStationList.Where(x => excludedFactionSet.Contains(x.StationID)).OrderBy(o => o.ArtworkOrder);//按工艺站排序
|
|
|
|
|
|
DataTable tblDatas = new DataTable("Datas");
|
|
//DataColumn dc = null;
|
|
tblDatas.Columns.Add("Type", Type.GetType("System.String"));//新列
|
|
tblDatas.Columns.Add("Date", Type.GetType("System.String"));//新列
|
|
//tblDatas.Columns.Add("DateTime", Type.GetType("System.String"));//新列
|
|
//tblDatas.Columns.Add("DataType", Type.GetType("System.String"));//新列
|
|
|
|
var totalList = new Dictionary<string, int>();
|
|
foreach (var itemStation in stationList)
|
|
{
|
|
var stationName = cacheUserStationList.Single(x => x.ID == itemStation.ID).StationName;//取站名
|
|
|
|
tblDatas.Columns.Add(stationName, Type.GetType("System.String"));//新列
|
|
totalList.Add(stationName, 0);
|
|
}
|
|
|
|
var timeStr = "";
|
|
var onPPlan = new VM_TBL_PPlan();
|
|
var thisStation = new TBL_StationList();
|
|
foreach (var item in timeGroupList)
|
|
{
|
|
|
|
timeStr = item.Key.ToString("yyyy/MM/dd");
|
|
//timeStr = item.Key.ToString("yyyy/MM/dd");
|
|
|
|
DataRow newRow = tblDatas.NewRow();//新行
|
|
newRow["Date"] = timeStr;
|
|
//newRow["DateTime"] = timeStr + "</br>" + Tool.StringHelp.GetWeek(timeStr.ToDateTime() ?? DateTime.Now);
|
|
newRow["Type"] = "ToDay";
|
|
//newRow["DataType"] = "今日";
|
|
|
|
DataRow newRow2 = tblDatas.NewRow();//新行
|
|
//newRow2["Date"] = timeStr;
|
|
newRow2["Date"] = Tool.StringHelp.GetWeek(timeStr.ToDateTime() ?? DateTime.Now);
|
|
//newRow2["DateTime"] = timeStr + "</br>" + Tool.StringHelp.GetWeek(timeStr.ToDateTime() ?? DateTime.Now);
|
|
newRow2["Type"] = "Total";
|
|
//newRow2["DataType"] = "累计";
|
|
|
|
foreach (var itemStation in stationGroupList)
|
|
{
|
|
thisStation = stationList.Single(x => x.ID == itemStation.Key);
|
|
onPPlan = pPlanList.SingleOrDefault(x => x.ProductionTime == item.Key && x.StationID == itemStation.Key);//计划表对象
|
|
|
|
if (onPPlan != null && onPPlan.ObjectiveYield > 0)
|
|
{
|
|
newRow[thisStation.StationName] = onPPlan == null ? 0 : onPPlan.ObjectiveYield;//目标;
|
|
//newRow2[thisStation.StationName] = (tblDatas.AsEnumerable().Select(d => Convert.ToDouble(d.Field<string>(thisStation.StationName))).Sum()) / 2 + (onPPlan == null ? 0 : onPPlan.ObjectiveYield);
|
|
//newRow2[thisStation.StationName] = onPPlan.ObjectiveYieldTotal;
|
|
totalList[thisStation.StationName] += onPPlan.ObjectiveYield;
|
|
newRow2[thisStation.StationName] = totalList[thisStation.StationName];
|
|
}
|
|
//else
|
|
//{
|
|
// newRow[thisStation.StationName] = 0;//目标;
|
|
// newRow2[thisStation.StationName] = 0;
|
|
//}
|
|
}
|
|
tblDatas.Rows.Add(newRow);
|
|
tblDatas.Rows.Add(newRow2);
|
|
|
|
//rowKey = 0;
|
|
//foreach (var itemStation in stationGroupList)
|
|
//{
|
|
// onPPlan = pPlanList.SingleOrDefault(x => x.ProductionTime == item.Key && x.StationID == itemStation.Key);
|
|
|
|
// tblDatas.Rows[rowKey][timeStr] = onPPlan == null ? "" : onPPlan.ObjectiveYield.ToString();//目标
|
|
|
|
// rowKey += 1;
|
|
|
|
// tblDatas.Rows[rowKey][timeStr] = onPPlan == null ? "" : onPPlan.ObjectiveYieldTotal.ToString();//计划
|
|
// rowKey += 1;
|
|
//}
|
|
}
|
|
|
|
|
|
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
|
|
|
|
foreach (DataRow Row in tblDatas.Rows)//循环行
|
|
{
|
|
Dictionary<string, object> row = new Dictionary<string, object>();
|
|
for (int i = 0; i < Row.ItemArray.Length; i++)
|
|
{
|
|
row.Add(tblDatas.Columns[i].ColumnName, Row[i].ToString());
|
|
}
|
|
rows.Add(row);
|
|
|
|
}
|
|
|
|
vmodel.rows = rows;
|
|
|
|
result.Data = vmodel;
|
|
result.Status = 200;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.Message = "网络系统繁忙,请稍候再试!";
|
|
LogHelp.WriteExceptionLog(ex);
|
|
}
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
}
|