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

577 lines
30 KiB

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using QMAPP.BLL;
using QMAPP.Entity;
using QMAPP.FJC.BLL.Common;
using QMAPP.FJC.BLL.FIS;
using QMAPP.FJC.DAL.Basic;
using QMAPP.FJC.DAL.CompleteStatistics;
using QMAPP.FJC.DAL.FIS;
using QMAPP.FJC.DAL.MesB9;
using QMAPP.FJC.DAL.ProductionPlan;
using QMAPP.FJC.Entity.Basic;
using QMAPP.FJC.Entity.Common.Constants;
using QMAPP.FJC.Entity.CompleteStatistics;
using QMAPP.FJC.Entity.FileCopy.FIS;
using QMAPP.FJC.Entity.FIS;
using QMAPP.FJC.Entity.MesB9;
using QMAPP.FJC.Entity.ProductionPlan;
using QMAPP.MD.BLL;
using QMAPP.MD.Entity;
using QMFrameWork.Data;
using QMFrameWork.Log;
using Resource = QMAPP.FJC.Entity.Resource;
namespace QMAPP.FJC.BLL.MesB9
{
public class MesB4BLL : BaseBLL
{
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部数据</returns>
public List<MesB4Entity> GetAllList()
{
try
{
return new MesB4DAL().GetList();
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo { ErrorInfo = ex, Tag = ex.StackTrace, Info = "获取Mes_B4表错误!" });
throw;
}
}
/// <summary>
/// 更新信息
/// </summary>
/// <param name="model"></param>
/// <returns>更新行数</returns>
public DataResult<int> Update(MesB4Entity model)
{
DataResult<int> result = new DataResult<int>
{
IsSuccess = true,
Msg = Resource.MsgSuccess
};
try
{
result.Result = new MesB4DAL().Update(model);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo { ErrorInfo = ex, Tag = ex.StackTrace, Info = "更新Mes_B4表异常!" });
result.IsSuccess = false;
result.Msg = Resource.SystemException;
}
return result;
}
//查询零件号名称
private string getMaterialName(string materialCode)
{
//查询零件号和名称
var materialList = new MaterialBLL().GetAllList(new Material
{
MATERIAL_CODE = materialCode
});
return materialList.Count <= 0 ? "" : materialList[0].MATERIAL_NAME;
}
//查询零件号名称
private string getWorkcenterCode(string materialCode)
{
var initList =
new MaterialCodeInitDAL().GetList(new MaterialCodeInit
{
MATERIAL_CODE = materialCode
});
return initList.Count <= 0 ? "" : initList[0].WORKCENTER_CODE;
}
//执行task程序
//暂时不生成订单--周晓东20180226
public void SelectMesInsertPPtable()
{
//获取Mes_B4表数据
var MesB4BLLList = new MesB4DAL().GetList();
//获取Mes_B4表数据
var MesB4M110BLLList = new MesB4M110DAL().GetList();
if (MesB4BLLList != null && MesB4BLLList.Count>0)
{
foreach (var item in MesB4BLLList)
{
using (
IDataSession session = AppDataFactory.CreateMainSession(),
sessionSelect = AppDataFactory.CreateSession("maindbSelect"))
{
try
{
var orderPlanBll = new OrderPlanBLL();
var fisOrderDAL = new FISOrderDAL { BaseSession = session };
var fisOrderSendDetialDAL = new FISOrederSendDetialDAL { BaseSession = session };
var orderPlanDAL = new OrderPlanDAL { BaseSession = session };
var workOrderDAL = new WorkOrderDAL { BaseSession = session };
var ds = item.m100dtm + "00";
FISOrder fisOrder = new FISOrder
{
VWSEQ = item.seq,
KIN = item.kin,
VIN = item.vin,
//ORDER_NO = item.m100dtm,
M100_ONLINEDATE =
DateTime.Parse(ds.Substring(0, 4) + "-" + ds.Substring(4, 2) + "-" +
ds.Substring(6, 2) +
" " +
ds.Substring(8, 2) + ":" + ds.Substring(10, 2) + ":00"),
LINENO = item.assemblyline,
CREATETIME = DateTime.Now,
SCANSTATE = "0"
};
OrderPlan orderPlan = new OrderPlan
{
//PLAN_NO = fisOrder.ORDER_NO,
PLAN_SEQ = fisOrder.VWSEQ,
PLAN_STATE = "0",
QTY = 1,
COMPLETE_QTY = 0,
PLAN_DATE = fisOrder.M100_ONLINEDATE,
PLANSOURCE = "0",
PRODUCEREQUIRE = "1"
};
// 开始事务
session.OpenTs();
sessionSelect.OpenTs();
//插入T_PP_FISORDER表(因为Mes_B4表里有4个ProdNo,所以要插入4条记录)
//插入T_PP_ORDERPLAN表,T_PP_WORKORDER表.(因为Mes_B4表里有4个ProdNo,所以要插入4条记录)
//11111111111
fisOrder.PID = Guid.NewGuid().ToString();
fisOrder.PRODNO = item.ProdNo1;
fisOrder.ORDER_NO = "DPFIS" + item.m100dtm + "LF" + item.seq.Substring(item.seq.Length - 4);
//查询是否存在数据
var fisOrderNew = fisOrderDAL.FISOrderIsNull(fisOrder);
if (fisOrderNew != null)
{
//更新之前m110存进来的数据
fisOrderNew[0].M100_ONLINEDATE = fisOrder.M100_ONLINEDATE;
session.Update(fisOrderNew);
///////////////////////////////////////////////////
/// 屏蔽订单信息,将来有需要再放开。--周晓东20180226
///////////////////////////////////////////////////
////更新T_PP_ORDERPLAN
//var orderPlanNew = orderPlanDAL.Get(new OrderPlan { PLAN_NO = fisOrderNew.ORDER_NO });
//orderPlanNew.PLAN_DATE = fisOrderNew.M100_ONLINEDATE;
//session.Update(orderPlanNew);
////更新T_PP_WORKORDER
//var workOrderNew = workOrderDAL.GetOne(orderPlanNew.PID);
//workOrderNew.PLAN_DATE = orderPlanNew.PLAN_DATE;
//session.Update(workOrderNew);
}
else
{
fisOrder.M110_ONLINEDATE = fisOrder.M100_ONLINEDATE;
session.Insert(fisOrder);
//插入FISOrederSendDetial --周晓东20180228
FISOrederSendDetial fisOrderSendDetial = new FISOrederSendDetial
{
PID = Guid.NewGuid().ToString(),
FIS_PID = fisOrder.PID,
STATE = "0",
MATERIAL_CODE = fisOrder.PRODNO,
MATERIAL_NAME = getMaterialName(fisOrder.PRODNO),
WORKCENTER_CODE = getWorkcenterCode(fisOrder.PRODNO)
};
session.Insert(fisOrderSendDetial);
///////////////////////////////////////////////////
/// 屏蔽订单信息,将来有需要再放开。--周晓东20180226
///////////////////////////////////////////////////
//orderPlan.PID = Guid.NewGuid().ToString();
//orderPlan.MATERIAL_CODE = fisOrder.PRODNO;
//orderPlan.PLAN_NO = fisOrder.ORDER_NO;
//orderPlanBll.InsertOrderPlanAndWorkOrder(orderPlan, session);
}
//2222222222
fisOrder.PID = Guid.NewGuid().ToString();
fisOrder.PRODNO = item.ProdNo2;
fisOrder.ORDER_NO = "DPFIS" + item.m100dtm + "LR" + item.seq.Substring(item.seq.Length - 4);
//查询是否存在数据
fisOrderNew = fisOrderDAL.FISOrderIsNull(fisOrder);
if (fisOrderNew != null)
{
//更新之前m110存进来的数据
fisOrderNew[0].M100_ONLINEDATE = fisOrder.M100_ONLINEDATE;
session.Update(fisOrderNew);
///////////////////////////////////////////////////
/// 屏蔽订单信息,将来有需要再放开。--周晓东20180226
///////////////////////////////////////////////////
////更新T_PP_ORDERPLAN
//var orderPlanNew = orderPlanDAL.Get(new OrderPlan { PLAN_NO = fisOrderNew.ORDER_NO });
//orderPlanNew.PLAN_DATE = fisOrderNew.M100_ONLINEDATE;
//session.Update(orderPlanNew);
////更新T_PP_WORKORDER
//var workOrderNew = workOrderDAL.GetOne(orderPlanNew.PID);
//workOrderNew.PLAN_DATE = orderPlanNew.PLAN_DATE;
//session.Update(workOrderNew);
}
else
{
fisOrder.M110_ONLINEDATE = fisOrder.M100_ONLINEDATE;
session.Insert(fisOrder);
//插入FISOrederSendDetial --周晓东20180228
FISOrederSendDetial fisOrderSendDetial = new FISOrederSendDetial
{
PID = Guid.NewGuid().ToString(),
FIS_PID = fisOrder.PID,
STATE = "0",
MATERIAL_CODE = fisOrder.PRODNO,
MATERIAL_NAME = getMaterialName(fisOrder.PRODNO),
WORKCENTER_CODE = getWorkcenterCode(fisOrder.PRODNO)
};
session.Insert(fisOrderSendDetial);
///////////////////////////////////////////////////
/// 屏蔽订单信息,将来有需要再放开。--周晓东20180226
///////////////////////////////////////////////////
//orderPlan.PID = Guid.NewGuid().ToString();
//orderPlan.MATERIAL_CODE = fisOrder.PRODNO;
//orderPlan.PLAN_NO = fisOrder.ORDER_NO;
//orderPlanBll.InsertOrderPlanAndWorkOrder(orderPlan, session);
}
//33333333333
fisOrder.PID = Guid.NewGuid().ToString();
fisOrder.PRODNO = item.ProdNo3;
fisOrder.ORDER_NO = "DPFIS" + item.m100dtm + "RF" + item.seq.Substring(item.seq.Length - 4);
//查询是否存在数据
fisOrderNew = fisOrderDAL.FISOrderIsNull(fisOrder);
if (fisOrderNew != null)
{
//更新之前m110存进来的数据
fisOrderNew[0].M100_ONLINEDATE = fisOrder.M100_ONLINEDATE;
session.Update(fisOrderNew);
///////////////////////////////////////////////////
/// 屏蔽订单信息,将来有需要再放开。--周晓东20180226
///////////////////////////////////////////////////
////更新T_PP_ORDERPLAN
//var orderPlanNew = orderPlanDAL.Get(new OrderPlan { PLAN_NO = fisOrderNew.ORDER_NO });
//orderPlanNew.PLAN_DATE = fisOrderNew.M100_ONLINEDATE;
//session.Update(orderPlanNew);
////更新T_PP_WORKORDER
//var workOrderNew = workOrderDAL.GetOne(orderPlanNew.PID);
//workOrderNew.PLAN_DATE = orderPlanNew.PLAN_DATE;
//session.Update(workOrderNew);
}
else
{
fisOrder.M110_ONLINEDATE = fisOrder.M100_ONLINEDATE;
session.Insert(fisOrder);
//插入FISOrederSendDetial --周晓东20180228
FISOrederSendDetial fisOrderSendDetial = new FISOrederSendDetial
{
PID = Guid.NewGuid().ToString(),
FIS_PID = fisOrder.PID,
STATE = "0",
MATERIAL_CODE = fisOrder.PRODNO,
MATERIAL_NAME = getMaterialName(fisOrder.PRODNO),
WORKCENTER_CODE = getWorkcenterCode(fisOrder.PRODNO)
};
session.Insert(fisOrderSendDetial);
///////////////////////////////////////////////////
/// 屏蔽订单信息,将来有需要再放开。--周晓东20180226
///////////////////////////////////////////////////
//orderPlan.PID = Guid.NewGuid().ToString();
//orderPlan.MATERIAL_CODE = fisOrder.PRODNO;
//orderPlan.PLAN_NO = fisOrder.ORDER_NO;
//orderPlanBll.InsertOrderPlanAndWorkOrder(orderPlan, session);
}
//4444444444444
fisOrder.PID = Guid.NewGuid().ToString();
fisOrder.PRODNO = item.ProdNo4;
fisOrder.ORDER_NO = "DPFIS" + item.m100dtm + "RR" + item.seq.Substring(item.seq.Length - 4);
//查询是否存在数据
fisOrderNew = fisOrderDAL.FISOrderIsNull(fisOrder);
if (fisOrderNew != null)
{
//更新之前m110存进来的数据
fisOrderNew[0].M100_ONLINEDATE = fisOrder.M100_ONLINEDATE;
session.Update(fisOrderNew);
///////////////////////////////////////////////////
/// 屏蔽订单信息,将来有需要再放开。--周晓东20180226
///////////////////////////////////////////////////
////更新T_PP_ORDERPLAN
//var orderPlanNew = orderPlanDAL.Get(new OrderPlan { PLAN_NO = fisOrderNew.ORDER_NO });
//orderPlanNew.PLAN_DATE = fisOrderNew.M100_ONLINEDATE;
//session.Update(orderPlanNew);
////更新T_PP_WORKORDER
//var workOrderNew = workOrderDAL.GetOne(orderPlanNew.PID);
//workOrderNew.PLAN_DATE = orderPlanNew.PLAN_DATE;
//session.Update(workOrderNew);
}
else
{
fisOrder.M110_ONLINEDATE = fisOrder.M100_ONLINEDATE;
session.Insert(fisOrder);
//插入FISOrederSendDetial --周晓东20180228
FISOrederSendDetial fisOrderSendDetial = new FISOrederSendDetial
{
PID = Guid.NewGuid().ToString(),
FIS_PID = fisOrder.PID,
STATE = "0",
MATERIAL_CODE = fisOrder.PRODNO,
MATERIAL_NAME = getMaterialName(fisOrder.PRODNO),
WORKCENTER_CODE = getWorkcenterCode(fisOrder.PRODNO)
};
session.Insert(fisOrderSendDetial);
///////////////////////////////////////////////////
/// 屏蔽订单信息,将来有需要再放开。--周晓东20180226
///////////////////////////////////////////////////
//orderPlan.PID = Guid.NewGuid().ToString();
//orderPlan.MATERIAL_CODE = fisOrder.PRODNO;
//orderPlan.PLAN_NO = fisOrder.ORDER_NO;
//orderPlanBll.InsertOrderPlanAndWorkOrder(orderPlan, session);
}
//更新Mes_B9表
item.ReadFlag = 1;
sessionSelect.Update(item);
// 事务提交
session.CommitTs();
sessionSelect.CommitTs();
}
catch (Exception e)
{
session.RollbackTs();
sessionSelect.RollbackTs();
throw e;
}
}
}
}
if (MesB4M110BLLList != null && MesB4M110BLLList.Count > 0)
{
foreach (var item in MesB4M110BLLList)
{
using (
IDataSession session = AppDataFactory.CreateMainSession(),
sessionSelect = AppDataFactory.CreateSession("maindbSelect"))
{
try
{
OrderPlanBLL orderPlanBll = new OrderPlanBLL();
var fisOrderDAL = new FISOrderDAL { BaseSession = session };
var ds = item.m110dtm + "00";
FISOrder fisOrder = new FISOrder
{
VWSEQ = item.seq,
KIN = item.kin,
VIN = item.vin,
//ORDER_NO = item.m100dtm,
M110_ONLINEDATE =
DateTime.Parse(ds.Substring(0, 4) + "-" + ds.Substring(4, 2) + "-" +
ds.Substring(6, 2) +
" " +
ds.Substring(8, 2) + ":" + ds.Substring(10, 2) + ":00"),
LINENO = item.assemblyline,
CREATETIME = DateTime.Now,
SCANSTATE = "0"
};
OrderPlan orderPlan = new OrderPlan
{
//PLAN_NO = fisOrder.ORDER_NO,
PLAN_SEQ = fisOrder.VWSEQ,
PLAN_STATE = "0",
QTY = 1,
COMPLETE_QTY = 0,
PLAN_DATE = fisOrder.M100_ONLINEDATE,
PLANSOURCE = "0",
PRODUCEREQUIRE = "1"
};
// 开始事务
session.OpenTs();
sessionSelect.OpenTs();
//插入T_PP_FISORDER表(因为Mes_B4表里有4个ProdNo,所以要插入4条记录)
//插入T_PP_ORDERPLAN表,T_PP_WORKORDER表.(因为Mes_B4表里有4个ProdNo,所以要插入4条记录)
//11111111111
fisOrder.PID = Guid.NewGuid().ToString();
fisOrder.PRODNO = item.ProdNo1;
fisOrder.ORDER_NO = "DPFIS" + item.m110dtm + "LF" + item.seq.Substring(item.seq.Length - 4);
//查询是否存在数据
var fisOrderNew = fisOrderDAL.FISOrderIsNull(fisOrder);
if (fisOrderNew != null)
{
//更新之前m110存进来的数据
fisOrderNew[0].M110_ONLINEDATE = fisOrder.M110_ONLINEDATE;
session.Update(fisOrderNew);
}
else
{
fisOrder.M100_ONLINEDATE = fisOrder.M110_ONLINEDATE;
session.Insert(fisOrder);
//插入FISOrederSendDetial --周晓东20180228
FISOrederSendDetial fisOrderSendDetial = new FISOrederSendDetial
{
PID = Guid.NewGuid().ToString(),
FIS_PID = fisOrder.PID,
STATE = "0",
MATERIAL_CODE = fisOrder.PRODNO,
MATERIAL_NAME = getMaterialName(fisOrder.PRODNO),
WORKCENTER_CODE = getWorkcenterCode(fisOrder.PRODNO)
};
session.Insert(fisOrderSendDetial);
//orderPlan.PID = Guid.NewGuid().ToString();
//orderPlan.MATERIAL_CODE = fisOrder.PRODNO;
//orderPlan.PLAN_NO = fisOrder.ORDER_NO;
//orderPlanBll.InsertOrderPlanAndWorkOrder(orderPlan, session);
}
//2222222222
fisOrder.PID = Guid.NewGuid().ToString();
fisOrder.PRODNO = item.ProdNo2;
fisOrder.ORDER_NO = "DPFIS" + item.m110dtm + "LR" + item.seq.Substring(item.seq.Length - 4);
//查询是否存在数据
fisOrderNew = fisOrderDAL.FISOrderIsNull(fisOrder);
if (fisOrderNew != null)
{
//更新之前m110存进来的数据
fisOrderNew[0].M110_ONLINEDATE = fisOrder.M110_ONLINEDATE;
session.Update(fisOrderNew);
}
else
{
fisOrder.M100_ONLINEDATE = fisOrder.M110_ONLINEDATE;
session.Insert(fisOrder);
//插入FISOrederSendDetial --周晓东20180228
FISOrederSendDetial fisOrderSendDetial = new FISOrederSendDetial
{
PID = Guid.NewGuid().ToString(),
FIS_PID = fisOrder.PID,
STATE = "0",
MATERIAL_CODE = fisOrder.PRODNO,
MATERIAL_NAME = getMaterialName(fisOrder.PRODNO),
WORKCENTER_CODE = getWorkcenterCode(fisOrder.PRODNO)
};
session.Insert(fisOrderSendDetial);
//orderPlan.PID = Guid.NewGuid().ToString();
//orderPlan.MATERIAL_CODE = fisOrder.PRODNO;
//orderPlan.PLAN_NO = fisOrder.ORDER_NO;
//orderPlanBll.InsertOrderPlanAndWorkOrder(orderPlan, session);
}
//33333333333
fisOrder.PID = Guid.NewGuid().ToString();
fisOrder.PRODNO = item.ProdNo3;
fisOrder.ORDER_NO = "DPFIS" + item.m110dtm + "RF" + item.seq.Substring(item.seq.Length - 4);
//查询是否存在数据
fisOrderNew = fisOrderDAL.FISOrderIsNull(fisOrder);
if (fisOrderNew != null)
{
//更新之前m110存进来的数据
fisOrderNew[0].M110_ONLINEDATE = fisOrder.M110_ONLINEDATE;
session.Update(fisOrderNew);
}
else
{
fisOrder.M100_ONLINEDATE = fisOrder.M110_ONLINEDATE;
session.Insert(fisOrder);
//插入FISOrederSendDetial --周晓东20180228
FISOrederSendDetial fisOrderSendDetial = new FISOrederSendDetial
{
PID = Guid.NewGuid().ToString(),
FIS_PID = fisOrder.PID,
STATE = "0",
MATERIAL_CODE = fisOrder.PRODNO,
MATERIAL_NAME = getMaterialName(fisOrder.PRODNO),
WORKCENTER_CODE = getWorkcenterCode(fisOrder.PRODNO)
};
session.Insert(fisOrderSendDetial);
//orderPlan.PID = Guid.NewGuid().ToString();
//orderPlan.MATERIAL_CODE = fisOrder.PRODNO;
//orderPlan.PLAN_NO = fisOrder.ORDER_NO;
//orderPlanBll.InsertOrderPlanAndWorkOrder(orderPlan, session);
}
//4444444444444
fisOrder.PID = Guid.NewGuid().ToString();
fisOrder.PRODNO = item.ProdNo4;
fisOrder.ORDER_NO = "DPFIS" + item.m110dtm + "RR" + item.seq.Substring(item.seq.Length - 4);
//查询是否存在数据
fisOrderNew = fisOrderDAL.FISOrderIsNull(fisOrder);
if (fisOrderNew != null)
{
//更新之前m110存进来的数据
fisOrderNew[0].M110_ONLINEDATE = fisOrder.M110_ONLINEDATE;
session.Update(fisOrderNew);
}
else
{
fisOrder.M100_ONLINEDATE = fisOrder.M110_ONLINEDATE;
session.Insert(fisOrder);
//插入FISOrederSendDetial --周晓东20180228
FISOrederSendDetial fisOrderSendDetial = new FISOrederSendDetial
{
PID = Guid.NewGuid().ToString(),
FIS_PID = fisOrder.PID,
STATE = "0",
MATERIAL_CODE = fisOrder.PRODNO,
MATERIAL_NAME = getMaterialName(fisOrder.PRODNO),
WORKCENTER_CODE = getWorkcenterCode(fisOrder.PRODNO)
};
session.Insert(fisOrderSendDetial);
//orderPlan.PID = Guid.NewGuid().ToString();
//orderPlan.MATERIAL_CODE = fisOrder.PRODNO;
//orderPlan.PLAN_NO = fisOrder.ORDER_NO;
//orderPlanBll.InsertOrderPlanAndWorkOrder(orderPlan, session);
}
//更新Mes_B9表
item.ReadFlag = 1;
sessionSelect.Update(item);
// 事务提交
session.CommitTs();
sessionSelect.CommitTs();
}
catch (Exception e)
{
session.RollbackTs();
sessionSelect.RollbackTs();
throw e;
}
}
}
}
}
}
}