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.
750 lines
34 KiB
750 lines
34 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using QMFrameWork.Data;
|
|
using QMAPP.FJC.DAL.QT;
|
|
using QMAPP.FJC.Entity.QT;
|
|
using QMAPP.FJC.TRACING.DAInterface;
|
|
using QMAPP.FJC.DAL.Produce;
|
|
using QMAPP.FJC.DAL.Basic;
|
|
using QMAPP.FJC.Entity.Operation;
|
|
using QMAPP.FJC.DAL.Operation;
|
|
using QMAPP.FJC.Entity.Basic;
|
|
using QMAPP.MD.Entity;
|
|
using QMAPP.MD.DAL;
|
|
using QMAPP.MD.Entity.View;
|
|
using QMAPP.FJC.Entity.ProductionPlan;
|
|
using QMAPP.FJC.Entity;
|
|
using QMAPP.FJC.Entity.Injection;
|
|
using QMAPP.FJC.DAL.Injection;
|
|
|
|
namespace QMAPP.FJC.TRACING.StateActions
|
|
{
|
|
/// <summary>
|
|
/// 提交数据关联派工单
|
|
/// </summary>
|
|
public class SubmitWithOrder : IStateAction
|
|
{
|
|
/// <summary>
|
|
/// 执行
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
public void Execute(DAObject data)
|
|
{
|
|
//如果当前工序未确定生产产品物料号
|
|
if (string.IsNullOrWhiteSpace(data.WorkLocState.CurrentState.MATERIAL_CODE))
|
|
{
|
|
//搜索确认产品物料号
|
|
SearchMaterial(data);
|
|
}
|
|
|
|
|
|
|
|
WorkCellRunStateDAL wcrsdal = new WorkCellRunStateDAL();
|
|
var state = wcrsdal.GetNextState(data.WorkLocState.WORKCELL_CODE, data.WorkLocState.CurrentState.STATE_SEQ);
|
|
bool workcellend = state == null; //如果当前为工序最终状态
|
|
|
|
var product = SaveProduct(data, workcellend);
|
|
SaveProcessRecord(product, data, workcellend);
|
|
UpdateWorkOrder(product, data, workcellend);
|
|
|
|
|
|
|
|
//List<DAICache> unsavedDai = new List<DAICache>();
|
|
foreach (var dai in data.WorkLocState.DataCache)
|
|
{
|
|
if (!dai.SAVED.Contains(data.MouldCode)&&!string.IsNullOrWhiteSpace(dai.DA_VALUE)) //过滤已保存过的和采集值为空值的
|
|
{
|
|
switch (dai.DATA_TYPE)
|
|
{
|
|
case "SN": //零件序列号
|
|
case "BN": //零件批次号
|
|
{
|
|
SaveProductStructure(product, dai, data);
|
|
break;
|
|
}
|
|
case "MN": //模具编号
|
|
{
|
|
SaveProcessParam(product, dai, data);
|
|
break;
|
|
}
|
|
case "PARM": //加工参数
|
|
{
|
|
//SaveProcessParam(product,dai,data);
|
|
break;
|
|
}
|
|
}
|
|
dai.SAVED = dai.SAVED + data.MouldCode;
|
|
data.AddToPersistentList(dai, dai.PID);
|
|
}
|
|
if (workcellend && !string.IsNullOrWhiteSpace(dai.MATERIAL_CODE) && !dai.MATERIAL_CODE.Equals(product.MATERIAL_CODE)) //如果采集的物料号于产品物料号一直则不保存产品组成
|
|
{
|
|
StringBuilder sql = new StringBuilder();
|
|
sql.AppendLine("MERGE INTO [T_AW_PRODUCTCOUNT] C ");
|
|
sql.AppendLine("USING (SELECT @materialcode AS [MATERIAL_CODE]) V ");
|
|
sql.AppendLine("ON (C.MATERIAL_CODE=V.MATERIAL_CODE AND C.[PROTYPE]=1) ");
|
|
sql.AppendLine("WHEN MATCHED THEN ");
|
|
sql.AppendLine(" UPDATE SET C.[COUNTVALUE]=C.[COUNTVALUE]+1 ");
|
|
sql.AppendLine("WHEN NOT MATCHED THEN ");
|
|
sql.AppendLine(" INSERT ([PID],[MATERIAL_CODE],[COUNTVALUE],[PROTYPE],[UPDATETIME]) ");
|
|
sql.AppendLine(" VALUES (NEWID(),V.[MATERIAL_CODE],1,1,GETDATE());");
|
|
data.SQLCommands.Add(new SQLCommand(sql.ToString(), new DataParameter("materialcode", dai.MATERIAL_CODE)));
|
|
}
|
|
}
|
|
//DAICacheDAL dcdal = new DAICacheDAL();
|
|
//dcdal.Update(unsavedDai, data.DataSession);
|
|
}
|
|
/// <summary>
|
|
/// 更新派工单
|
|
/// </summary>
|
|
/// <param name="product"></param>
|
|
/// <param name="data"></param>
|
|
/// <param name="workcellend"></param>
|
|
private void UpdateWorkOrder(Product product, DAObject data, bool workcellend)
|
|
{
|
|
var workorder=LocateWorkOrder(product,data);
|
|
data.WorkOrderID = workorder.PID;
|
|
data.WorkLocState.CurrentState.BOM_CODE = workorder.PBOM_CODE;
|
|
if (string.IsNullOrWhiteSpace(workorder.REMARK))
|
|
{
|
|
workorder.REMARK = product.PRODUCTCODE;
|
|
}
|
|
//关联计划ID
|
|
product.PLAN_ID = workorder.ORDERPLANID;
|
|
product.PLAN_NO = workorder.ORDERPLAN_NO;
|
|
|
|
//--------------------BC316帽檐超声波焊接工位----------------------------------------------------
|
|
if (data.WorkLocState.WORKCELL_CODE == "BRIM_WELDING_BC316" && data.WorkLocState.CurrentState.STATE_CODE== "WORKING")
|
|
{
|
|
workorder.IsDelete = true;
|
|
}
|
|
//-----------------------------------------------------------------------------------------------
|
|
|
|
|
|
if (!workcellend)
|
|
{
|
|
workorder.WORKLOC_CODE = data.WorkLocState.WORKLOC_CODE;
|
|
workorder.MOULD_CODE = data.MouldCode;
|
|
workorder.STATE = 2;
|
|
}
|
|
else
|
|
{
|
|
workorder.WORKCELL_CODE=product.WORKCELL_CODE;
|
|
workorder.MOULD_CODE = data.MouldCode;
|
|
workorder.WORKLOC_CODE = "";
|
|
workorder.STATE = 1;
|
|
workorder.UPDATEDATE = DateTime.Now;
|
|
if ((string.Equals(workorder.ORDER_TYPE,"3")
|
|
&&string.Equals(workorder.MATERIAL_CODE, product.MATERIAL_CODE))
|
|
|| (!string.Equals(workorder.ORDER_TYPE, "3")&&string.Equals(product.ENDOFLINE,"1")))//产品物料号于派工单物料号一致 派工单完成
|
|
{
|
|
workorder.IsDelete = true;
|
|
ProductWithPlan pwp = new ProductWithPlan
|
|
{
|
|
PID = Guid.NewGuid().ToString(),
|
|
PLAN_TYPE = workorder.ORDER_TYPE,
|
|
PLANID = workorder.ORDERPLANID,
|
|
PRODUCT_PID = product.PID,
|
|
IsNewInfo = true
|
|
};
|
|
data.AddToPersistentList(pwp, pwp.PID);
|
|
DAL.FIS.OrderPlanDAL orderplandal = new DAL.FIS.OrderPlanDAL();
|
|
var orderplan = orderplandal.Get(new Entity.FIS.OrderPlan { PID = workorder.ORDERPLANID });
|
|
orderplan.COMPLETE_QTY += 1;
|
|
if (orderplan.QTY <= orderplan.COMPLETE_QTY)
|
|
{
|
|
orderplan.PLAN_STATE = EnumGeter.PLANSTATE.COMPLATED.GetHashCode().ToString();
|
|
}
|
|
data.AddToPersistentList(orderplan, orderplan.PID);
|
|
//var cmd = new DAInterface.SQLCommand(
|
|
// "UPDATE [T_PP_ORDERPLAN] SET [COMPLETE_QTY]=[COMPLETE_QTY]+1 WHERE [PID]=@planid",
|
|
// new DataParameter("planid", workorder.ORDERPLANID));
|
|
//data.SQLCommands.Add(cmd);
|
|
}
|
|
}
|
|
data.AddToPersistentList(workorder, workorder.PID);
|
|
}
|
|
/// <summary>
|
|
/// 定位派工单
|
|
/// </summary>
|
|
private WorkOrder LocateWorkOrder(Product product, DAObject data)
|
|
{
|
|
DAL.ProductionPlan.WorkOrderDAL workorderdal = new DAL.ProductionPlan.WorkOrderDAL();
|
|
var order = workorderdal.GetWorkingOrderInLoc(data.WorkLocState.WORKLOC_CODE, data.MouldCode);
|
|
if (order != null)
|
|
{
|
|
var lastorder = data.GetPersistentEntity<WorkOrder>(order.PID);
|
|
if (lastorder != null && (lastorder.IsDelete || lastorder.WORKCELL_CODE != data.WorkLocState.WORKCELL_CODE || (order.STATE!=lastorder.STATE && lastorder.STATE==1)))
|
|
{
|
|
order = null;
|
|
}
|
|
}
|
|
if (order == null && data.OrderPlan != null)
|
|
{
|
|
order = data.OrderPlan;
|
|
//order = workorderdal.GetWorkingOrderWithProduct(data.WorkLocState.WORKCELL_CODE, product.PRODUCTCODE, "");
|
|
}
|
|
if (order == null)
|
|
{
|
|
order = workorderdal.GetFirstMatchOrder(data.WorkLocState.WORKCELL_CODE, product.MATERIAL_CODE, "");
|
|
}
|
|
if (order == null)
|
|
{
|
|
throw new Exception("查找派工单失败!");
|
|
}
|
|
return order;
|
|
}
|
|
/// <summary>
|
|
/// 搜索确定加工后的产品物料号及加工消耗的物料号
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <returns>返回加工消耗物料</returns>
|
|
private string[] SearchMaterial(DAObject data)
|
|
{
|
|
var materials = (from da in data.WorkLocState.DataCache
|
|
where !string.IsNullOrWhiteSpace(da.MATERIAL_CODE)
|
|
select da.MATERIAL_CODE).ToArray();
|
|
|
|
BomLocation bomlocation = null;
|
|
if (data.OrderPlan != null)
|
|
{
|
|
if (string.Equals(data.MaterialCode, data.OrderPlan.MATERIAL_CODE))
|
|
{
|
|
bomlocation = new BomLocation
|
|
{
|
|
BOMCode = data.OrderPlan.PBOM_CODE,
|
|
ItemNo = 0,
|
|
SubCount = 1
|
|
};
|
|
}
|
|
else
|
|
{
|
|
bomlocation = GetBomLocation(data.OrderPlan.PBOM_CODE, materials.Distinct().ToArray());
|
|
if (bomlocation == null)
|
|
{
|
|
throw new Exception("采集数据有误,无法确定生产BOM,请检查采集点配置和BOM配置!");
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bomlocation = GetBomLocation(materials.Distinct().ToArray());
|
|
if (bomlocation == null) //未定位到
|
|
{
|
|
materials = (from da in data.WorkLocState.DataCache
|
|
where !string.IsNullOrWhiteSpace(da.MATERIAL_CODE)
|
|
&& !string.Equals(da.DA_MODE, "2") //过滤掉可省略的采集点
|
|
select da.MATERIAL_CODE).ToArray();
|
|
bomlocation = GetBomLocation(materials.Distinct().ToArray());
|
|
if (bomlocation == null) //仍未定位到BOM信息 抛出异常
|
|
{
|
|
if (materials.Length == 1) //单一物料加工
|
|
{
|
|
data.WorkLocState.CurrentState.MATERIAL_CODE = materials[0];
|
|
var dai = data.WorkLocState.DataCache.FirstOrDefault(p => p.MATERIAL_CODE == materials[0]);
|
|
data.WorkLocState.CurrentState.PROCESS_CODE = dai.DA_VALUE;
|
|
data.WorkLocState.CurrentState.PRODUCT_PID = dai.OBJ_PID;
|
|
return materials.Distinct().ToArray();
|
|
}
|
|
else
|
|
{
|
|
throw new Exception("采集数据有误,无法确定生产BOM,请检查采集点配置和BOM配置!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
PbomDAL pbidal = new PbomDAL();
|
|
if (materials.Length == 1) //单一物料加工
|
|
{
|
|
var oneitem = pbidal.GetBomDetail(new MD.Entity.PbomItem { PBOM_CODE = bomlocation.BOMCode, MATERIAL_CODE = materials[0], GMP = data.WorkLocState.WORKCELL_CODE });
|
|
if (oneitem == null)//并且当前工序不是此物料的发料工序
|
|
{
|
|
data.WorkLocState.CurrentState.MATERIAL_CODE = materials[0];
|
|
var dai = data.WorkLocState.DataCache.FirstOrDefault(p => p.MATERIAL_CODE == materials[0]);
|
|
data.WorkLocState.CurrentState.PROCESS_CODE = dai.DA_VALUE;
|
|
data.WorkLocState.CurrentState.PRODUCT_PID = dai.OBJ_PID;
|
|
return materials.Distinct().ToArray();
|
|
}
|
|
}
|
|
|
|
string upperlevelmaterial = "";
|
|
if (bomlocation.ItemNo > 0) //如果Bom定位为明细项
|
|
{
|
|
var bomitem = pbidal.GetByLocate(bomlocation);
|
|
if (bomitem != null)
|
|
{
|
|
upperlevelmaterial = bomitem.MATERIAL_CODE;
|
|
}
|
|
}
|
|
else //如果Bom定位为Bom头
|
|
{
|
|
var bom = pbidal.GetByCode(bomlocation.BOMCode);
|
|
if (bom != null)
|
|
{
|
|
upperlevelmaterial = bom.MATERIAL_CODE;
|
|
}
|
|
}
|
|
data.WorkLocState.CurrentState.MATERIAL_CODE = upperlevelmaterial; //取得产品物料号
|
|
|
|
return materials.Distinct().ToArray();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存产品组成信息
|
|
/// </summary>
|
|
/// <param name="product">产品</param>
|
|
/// <param name="dai"></param>
|
|
/// <param name="data"></param>
|
|
private void SaveProductStructure(Product product, DAICache dai, DAObject data)
|
|
{
|
|
if (!dai.MATERIAL_CODE.Equals(product.MATERIAL_CODE)) //如果采集的物料号于产品物料号一直则不保存产品组成
|
|
{
|
|
QMAPP.FJC.DAL.Produce.ProductDAL proddal = new QMAPP.FJC.DAL.Produce.ProductDAL();
|
|
Product part = null;
|
|
part= data.GetPersistentEntity<Product>(dai.OBJ_PID);
|
|
if (part == null)
|
|
{
|
|
part = data.GetObjectFromCache<Product>(p => p.PID == dai.OBJ_PID);
|
|
if (part == null)
|
|
{
|
|
part = proddal.GetByPID(dai.OBJ_PID);
|
|
|
|
}
|
|
}
|
|
data.ObjectCacheList.Add(part);
|
|
part.USINGCOUNT = part.USINGCOUNT + 1;
|
|
part.USINGSTATE = part.CAPACITY > part.USINGCOUNT ? "1" : "2";
|
|
//part.UPDATEDATE = DateTime.Now;
|
|
part.UPDATEUSER=data.UserID;
|
|
part.WORKLOC_CODE = data.WorkLocState.WORKLOC_CODE;
|
|
|
|
//proddal.Update(part, data.DataSession);
|
|
data.AddToPersistentList(part, dai.OBJ_PID);
|
|
|
|
ProductStructure structure = new ProductStructure()
|
|
{
|
|
PART_PID = part.PID,
|
|
PID = Guid.NewGuid().ToString(),
|
|
PROCESS_CODE = product.PRODUCTCODE,
|
|
PRODUCT_PID = product.PID,
|
|
IsNewInfo=true
|
|
};
|
|
//ProductStructureDAL psdal = new ProductStructureDAL();
|
|
//psdal.Insert(structure, data.DataSession);
|
|
data.AddToPersistentList(structure, structure.PID);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 保存加工参数
|
|
/// </summary>
|
|
/// <param name="product"></param>
|
|
/// <param name="dai"></param>
|
|
private void SaveProcessParam(Product product, DAICache dai,DAObject data)
|
|
{
|
|
ProcessParameters param = new ProcessParameters()
|
|
{
|
|
DA_CODE = dai.DA_CODE,
|
|
DA_MODEL = "1",
|
|
DA_TIME = dai.UPDATEDATE,
|
|
EQUIPMENT_CODE = "",
|
|
MEMBER_CODE = "",
|
|
PARM_ITEM = "",
|
|
PARM_VAL = dai.DA_VALUE,
|
|
PRODUCT_PID = product.PID,
|
|
SHIFT_CODE = "",
|
|
PID = Guid.NewGuid().ToString(),
|
|
TEAM_CODE = "",
|
|
WORKCELL_CODE = dai.WORKCELL_CODE,
|
|
WORKLOC_CODE = dai.WORKLOC_CODE,
|
|
IsNewInfo=true,
|
|
};
|
|
//ProcessParametersDAL ppdal = new ProcessParametersDAL();
|
|
//ppdal.Insert(param, data.DataSession);
|
|
data.AddToPersistentList(param, param.PID);
|
|
}
|
|
/// <summary>
|
|
/// 保存加工记录
|
|
/// </summary>
|
|
private void SaveProcessRecord(Product product, DAObject data, bool workcellend)
|
|
{
|
|
//QMAPP.FJC.DAL.Operation.ProductDAL pdal = new DAL.Operation.ProductDAL();
|
|
//pdal.BaseSession = data.DataSession;
|
|
//product = pdal.Get(product);
|
|
|
|
ProcessRecordDAL prdal = new ProcessRecordDAL();
|
|
ProcessRecord record = null;
|
|
record = data.GetPersistentEntity<ProcessRecord>(product.PID);//加工记录的ID使用PRODUCT的ID代替
|
|
if (record == null)
|
|
{
|
|
record = prdal.Get(product.PID, data.WorkLocState.WORKCELL_CODE);
|
|
}
|
|
if (record != null)
|
|
{
|
|
//if (string.IsNullOrEmpty(record.PROCESS_STATE))
|
|
//{
|
|
//record.PROCESS_STATE = workcellend ? "1" : "0";
|
|
//}
|
|
record.WORKLOC_CODE = data.WorkLocState.WORKLOC_CODE;
|
|
|
|
record.MANUAL_PASS = data.DAI == null ? "1" : "0";
|
|
|
|
if (record.MANUAL_PASS == "1")
|
|
{
|
|
record.PROCESS_STATE = "2";
|
|
}
|
|
else
|
|
{
|
|
record.PROCESS_STATE = workcellend ? "1" : "0";
|
|
}
|
|
|
|
if (workcellend)
|
|
{
|
|
record.WORK_END_TIME = DateTime.Now;
|
|
}
|
|
//prdal.Update(record, data.DataSession);
|
|
}
|
|
else
|
|
{
|
|
record = new ProcessRecord()
|
|
{
|
|
IN_WORKCELL_TIME = DateTime.Now,
|
|
PID = Guid.NewGuid().ToString(),
|
|
PROCESS_STATE = workcellend ? "1" : "0",
|
|
PRODUCT_PID = product.PID,
|
|
WORK_START_TIME = DateTime.Now,
|
|
WORKCELL_CODE = data.WorkLocState.WORKCELL_CODE,
|
|
WORKLOC_CODE = data.WorkLocState.WORKLOC_CODE,
|
|
MANUAL_PASS = data.DAI == null ? "1" : "0",
|
|
MODULE_CODE = data.MouldCode,
|
|
IsNewInfo = true
|
|
};
|
|
if (workcellend)
|
|
{
|
|
record.WORK_END_TIME = DateTime.Now;
|
|
}
|
|
//prdal.Insert(record, data.DataSession);
|
|
}
|
|
data.AddToPersistentList(record, product.PID);//加工记录的ID使用PRODUCT的ID代替
|
|
data.WorkLocState.CurrentState.RECORD_PID = record.PID;
|
|
if (workcellend)
|
|
{
|
|
#region 插入加工记录
|
|
//闫永刚 20170923
|
|
|
|
MainOperation mo = new MainOperation();
|
|
mo.PID = record.PID;
|
|
mo.PDID = product.PID;
|
|
mo.PROCESSTYPE = data.WorkLocState.CURRENTPROCESS;
|
|
mo.PRODUCTTYPE = "";
|
|
mo.PRODUCTCODE = product.PRODUCTCODE;
|
|
mo.MACHINECODDE = data.MachineCode;
|
|
mo.MOLDNUMBER = data.MouldCode;
|
|
mo.MACHINENAME = data.MachineName;
|
|
mo.STATUS = EnumGeter.STATUS.QUALIFIED.GetHashCode().ToString();
|
|
mo.OPERATESTATE = data.DAI == null ? EnumGeter.OPERATESTATE.RELEASED.GetHashCode().ToString(): EnumGeter.OPERATESTATE.COMPLETED.GetHashCode().ToString();
|
|
//mo.OPERATEDDATE = System.DateTime.Now;
|
|
mo.CURRENTPROCESS = "";
|
|
//mo.PRODUCELINE = "B9";
|
|
mo.MODELSTATION = "1";
|
|
mo.OPERATEDDATE = DateTime.Now;
|
|
mo.CREATEDATE = record.IN_WORKCELL_TIME;//DateTime.Now;
|
|
mo.CURRENTPROCESS = data.WorkLocState.CURRENTPROCESS;
|
|
mo.MATERIAL_CODE = product.MATERIAL_CODE;
|
|
mo.MATERIAL_NAME = product.MATERIAL_NAME;
|
|
mo.MATERIAL_TYPE_CODE = product.MATERIAL_TYPE;
|
|
mo.WORKCENTER_CODE = product.WORKCENTER_CODE;
|
|
mo.WORKCELL_CODE = data.WorkLocState.WORKCELL_CODE;
|
|
mo.IsNewInfo = true;
|
|
mo.CREATEUSER = product.CREATEUSER;
|
|
|
|
//MainOperationDAL moDal = new MainOperationDAL();
|
|
//moDal.Insert(mo);
|
|
data.AddToPersistentList(mo, mo.PID);
|
|
#endregion
|
|
|
|
#region 更新产品状态
|
|
|
|
#region 产品下道工序设置
|
|
|
|
//直接获取下道工序信息
|
|
QMAPP.MD.Entity.WorkCell nextCell = new WorkCellDAL().GetNextWorkCell(new QMAPP.MD.Entity.WorkCell() { WORKCELL_CODE = data.WorkLocState.WORKCELL_CODE });
|
|
|
|
if (nextCell != null && string.IsNullOrEmpty(nextCell.PID) == false)
|
|
{
|
|
product.WORKCELL_CODE = nextCell.WORKCELL_CODE;
|
|
product.WORKCENTER_CODE = nextCell.WORKCENTER_CODE;
|
|
product.TEAM_CODE = "";
|
|
product.WORKLOC_CODE = "";
|
|
product.CURRENTPROCESS = nextCell.CURRENTPROCESS;
|
|
}
|
|
else
|
|
{
|
|
//获取其他工艺路线的
|
|
|
|
#region 通过零件号获取BOM
|
|
|
|
//判断当前零件号是否是总成零件号
|
|
//如果不是继续判断下一个工序
|
|
List<Pbom> pbomList = new PbomDAL().GetList(new Pbom() { MATERIAL_CODE = product.MATERIAL_CODE });
|
|
if (pbomList.Count == 0)
|
|
{
|
|
ProcessRouteWithWorkCellSeqDAL seqdal = new ProcessRouteWithWorkCellSeqDAL();
|
|
ProcessRouteWithWorkCellSeq seq = seqdal.GetNextWorkCellBetweenRoute(new Product() { WORKCELL_CODE = product.WORKCELL_CODE, MATERIAL_CODE = product.MATERIAL_CODE }); ;
|
|
product.WORKCELL_CODE = seq != null ? seq.WORKCELL_CODE : "";
|
|
|
|
QMAPP.MD.Entity.WorkCell workcell = new WorkCellDAL().GetByCondition(new QMAPP.MD.Entity.WorkCell() { WORKCELL_CODE = product.WORKCELL_CODE });
|
|
product.CURRENTPROCESS = workcell.CURRENTPROCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
}
|
|
|
|
//pdal.Update(product);
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 获取/创建产品信息
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <param name="workcellend">工序结束</param>
|
|
/// <returns></returns>
|
|
private Product SaveProduct(DAObject data,bool workcellend)
|
|
{
|
|
MD.DAL.ProcessRouteDAL routedal = new MD.DAL.ProcessRouteDAL();
|
|
var route = routedal.LocateRoute(data.WorkLocState.WORKCELL_CODE);
|
|
if (route == null)
|
|
{
|
|
throw new Exception("无法定位工艺路线!请检查工序和工艺路线设置。");
|
|
}
|
|
|
|
DAL.Basic.ProcessRouteWithWorkCellSeqDAL routeseqdal = new ProcessRouteWithWorkCellSeqDAL();
|
|
var endofroute = routeseqdal.EndOfRoute(route.RouteCode, data.WorkLocState.WORKCELL_CODE);
|
|
|
|
var materialdal = new DAL.MD.MaterialDAL();
|
|
var material = materialdal.Get(data.WorkLocState.CurrentState.MATERIAL_CODE);
|
|
|
|
QMAPP.FJC.DAL.Produce.ProductDAL dal = new QMAPP.FJC.DAL.Produce.ProductDAL();
|
|
if (!string.IsNullOrEmpty(data.WorkLocState.CurrentState.PROCESS_CODE)) //如果已存在产品条码则获取产品信息
|
|
{
|
|
Product product=null;
|
|
if (!string.IsNullOrWhiteSpace(data.WorkLocState.CurrentState.PRODUCT_PID))//如果记录了产品ID 则通过产品ID获取产品
|
|
{
|
|
product = data.GetPersistentEntity<Product>(data.WorkLocState.CurrentState.PRODUCT_PID);
|
|
if (product == null)
|
|
{
|
|
product = data.GetObjectFromCache<Product>(p => p.PID == data.WorkLocState.CurrentState.PRODUCT_PID);
|
|
if (product == null)
|
|
{
|
|
product = dal.GetByPID(data.WorkLocState.CurrentState.PRODUCT_PID);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
product = data.GetObjectFromCache<Product>(p => p.PRODUCTCODE == data.WorkLocState.CurrentState.PROCESS_CODE && p.MATERIAL_CODE == data.WorkLocState.CurrentState.MATERIAL_CODE);
|
|
if (product == null)
|
|
{
|
|
product = dal.GetByCode(data.WorkLocState.CurrentState.PROCESS_CODE, data.WorkLocState.CurrentState.MATERIAL_CODE);
|
|
}
|
|
}
|
|
data.ObjectCacheList.Add(product);
|
|
product.WORKCELL_CODE = data.WorkLocState.WORKCELL_CODE;
|
|
product.WORKCENTER_CODE = data.WorkLocState.WORKCENTER_CODE;
|
|
product.WORKLOC_CODE = data.WorkLocState.WORKLOC_CODE;
|
|
product.MATERIAL_TYPE = material == null ? "" : material.MATERIAL_TYPE_CODE;
|
|
//product.UPDATEDATE = DateTime.Now;
|
|
product.UPDATEUSER = data.UserID;
|
|
if (workcellend)
|
|
{
|
|
product.STATUS = workcellend ? "0" : "";
|
|
product.USINGSTATE = workcellend ? "0" : "";
|
|
product.OUTFLAG = workcellend ? "0" : "";
|
|
}
|
|
if (endofroute)
|
|
{
|
|
product.ENDOFLINE = "1";
|
|
}
|
|
data.AddToPersistentList(product, product.PID);
|
|
//dal.Update(product, data.DataSession);
|
|
data.WorkLocState.CurrentState.PRODUCT_PID = product.PID;
|
|
return product;
|
|
}
|
|
else //不存在则创建产品信息
|
|
{
|
|
|
|
string sn = (from da in data.WorkLocState.DataCache
|
|
where string.Equals(da.ISPROCESSCODE, "1")
|
|
select da.DA_VALUE).FirstOrDefault();
|
|
if (string.IsNullOrEmpty(sn))
|
|
{
|
|
//TODO:根据物料号的不同 分别生成产品序列号
|
|
//sn = "";
|
|
ICodeGenerator cgtor = new CodeGenerators.ProductCodeGenerator();
|
|
sn = cgtor.Generate(data.WorkLocState.CurrentState.MATERIAL_CODE, DateTime.Now, null);
|
|
}
|
|
Product product = new Product()
|
|
{
|
|
CAPACITY = 1,
|
|
MATERIAL_CODE = data.WorkLocState.CurrentState.MATERIAL_CODE,
|
|
CREATEDATE = DateTime.Now,
|
|
CREATEUSER = data.UserID,
|
|
PID = Guid.NewGuid().ToString(),
|
|
PRODUCTCODE = sn,
|
|
STATUS = workcellend ? "0" : "",
|
|
TEAM_CODE = "",
|
|
USINGCOUNT = 0,
|
|
WORKCELL_CODE = data.WorkLocState.WORKCELL_CODE,
|
|
WORKCENTER_CODE = data.WorkLocState.WORKCENTER_CODE,
|
|
WORKLOC_CODE = data.WorkLocState.WORKLOC_CODE,
|
|
PRODUCESHIFTTCODE = data.Shift.PRODUCESHIFTTCODE,
|
|
USINGSTATE = workcellend ? "0" : "",
|
|
PRODUCTSOURCE = "0",
|
|
OUTFLAG = workcellend ? "0" : "",
|
|
MACHINECODDE = data.MachineCode,
|
|
MACHINENAME = data.MachineName,
|
|
MATERIAL_TYPE = material == null ? "" : material.MATERIAL_TYPE_CODE,
|
|
IsNewInfo = true
|
|
};
|
|
if (endofroute)
|
|
{
|
|
product.ENDOFLINE = "1";
|
|
}
|
|
data.AddToPersistentList(product, product.PID);
|
|
//dal.Insert(product, data.DataSession);
|
|
|
|
//判断是否为浇注工序
|
|
if (data.WorkLocState.WORKCELL_CODE == "FOAMING_VW371")
|
|
{
|
|
List<InjectionRecorder> updateInjectList = new List<InjectionRecorder>();
|
|
List<ProductInjection> addInjectItemList = new List<ProductInjection>();
|
|
addInjectItemList = this.GetProductInjectionList(product,ref updateInjectList);
|
|
ProductInjectionDAL proInDal = new ProductInjectionDAL();
|
|
if (addInjectItemList.Count > 0)
|
|
{
|
|
foreach (ProductInjection item in addInjectItemList)
|
|
{
|
|
proInDal.Insert(item);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
data.WorkLocState.CurrentState.PROCESS_CODE = sn;
|
|
data.WorkLocState.CurrentState.PRODUCT_PID = product.PID;
|
|
return product;
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 根据物料组获取上层物料号
|
|
/// </summary>
|
|
/// <param name="materials"></param>
|
|
/// <returns></returns>
|
|
private BomLocation GetBomLocation(params string[] materials)
|
|
{
|
|
PbomDAL pbidal = new PbomDAL();
|
|
var bomlocations = pbidal.LocateBom(materials);
|
|
//确定物料组成数量一致
|
|
var bomlocation = bomlocations.FirstOrDefault(p => p.SubCount == materials.Length);
|
|
return bomlocation;
|
|
}
|
|
/// <summary>
|
|
/// 在已知BOM的情况下根据物料组获取上层物料号
|
|
/// </summary>
|
|
/// <param name="bomcode"></param>
|
|
/// <param name="materials"></param>
|
|
/// <returns></returns>
|
|
private BomLocation GetBomLocation(string bomcode, params string[] materials)
|
|
{
|
|
PbomDAL pbidal = new PbomDAL();
|
|
var bomlocations = pbidal.LocateBom(materials);
|
|
//确定BOM编号一致
|
|
var bomlocation = bomlocations.FirstOrDefault(p => p.BOMCode == bomcode);
|
|
return bomlocation;
|
|
}
|
|
|
|
|
|
#region 投料
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="products"></param>
|
|
/// <param name="machine"></param>
|
|
/// <param name="updateInjectList"></param>
|
|
/// <returns></returns>
|
|
public List<ProductInjection> GetProductInjectionList(Product product, ref List<InjectionRecorder> updateInjectList)
|
|
{
|
|
InjectionRecorderDAL injectDal = new InjectionRecorderDAL();
|
|
updateInjectList = new List<InjectionRecorder>();
|
|
List<ProductInjection> addInjectItemList = new List<ProductInjection>();
|
|
|
|
//List<InjectionRecorder> ruleList = injectDal.GetCastLastRecorderWithBom(new InjectionRecorder() { MATERIALCODE = product.MATERIAL_CODE });
|
|
//去BOMItem
|
|
List<MD.Entity.PbomItem> ruleList = new PbomDAL().BomDetailList(new MD.Entity.PbomItem() { PBOM_CODE = product.MATERIAL_CODE });
|
|
//遍历规则信息
|
|
foreach (MD.Entity.PbomItem pm in ruleList)
|
|
{
|
|
#region 获取相应的投料信息
|
|
InjectionRecorder inRecorder = null;
|
|
List<InjectionRecorder> list = injectDal.GetCastLastRecorderWithMAterial(new InjectionRecorder()
|
|
{
|
|
MATERIALCODE = pm.MATERIAL_CODE
|
|
});
|
|
#endregion
|
|
if (list.Count > 0)
|
|
{
|
|
#region 修改投料记录
|
|
inRecorder = updateInjectList.Find(m => m.PID.Equals(list[0].PID));
|
|
if (inRecorder != null)
|
|
{
|
|
inRecorder.USEDWEIGHTSUM += pm.UNIT_SUM;
|
|
}
|
|
else
|
|
{
|
|
inRecorder = list[0];
|
|
inRecorder.USEDWEIGHTSUM += pm.UNIT_SUM;
|
|
//updateInjectList.Add(inRecorder);
|
|
InjectionRecorderDAL recoderDal = new InjectionRecorderDAL();
|
|
recoderDal.Update(inRecorder);
|
|
}
|
|
//recoderDal.Update(item);
|
|
#endregion
|
|
}
|
|
if (inRecorder != null)
|
|
{
|
|
#region 零件投料关联记录
|
|
ProductInjection proInject = new ProductInjection();
|
|
proInject.PID = Guid.NewGuid().ToString();
|
|
proInject.IPID = inRecorder.PID;
|
|
proInject.MPPID = product.PID;
|
|
proInject.MATERIALNAME = inRecorder.MATERIALNAME;
|
|
proInject.MATERIALCODE = inRecorder.MATERIALCODE;
|
|
proInject.MATERIALTYPE = inRecorder.MATERIALTYPE;
|
|
proInject.MATERIALBATCH = inRecorder.MATERIALBATCH;
|
|
proInject.MATERIALCODE = inRecorder.MATERIALCODE;
|
|
proInject.INJECTIONINDEX = inRecorder.INJECTIONINDEX;
|
|
proInject.INJECTIONTERMINAL = inRecorder.INJECTIONTERMINAL;
|
|
proInject.USEDWEIGHT = pm.UNIT_SUM;
|
|
proInject.CREATEDATE = System.DateTime.Now;
|
|
proInject.CREATEUSER = inRecorder.CREATEUSER;
|
|
proInject.UPDATEUSER = inRecorder.UPDATEUSER;
|
|
addInjectItemList.Add(proInject);
|
|
#endregion
|
|
}
|
|
}
|
|
return addInjectItemList;
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
|