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

301 lines
13 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.MD.Entity;
using QMAPP.MD.DAL;
using QMAPP.FJC.DAL.ProductionPlan;
using QMAPP.FJC.Entity.ProductionPlan;
using QMAPP.FJC.Entity;
using System.Text.RegularExpressions;
namespace QMAPP.FJC.TRACING.DataAnalyzers
{
/// <summary>
/// FIS标签数据解析类
/// </summary>
public class DPFISSNAnalyzer : DAInterface.IDataAnalyzer
{
static string regexp_full = "^D\\d{2}\\w+[RF][LR]\\d{2}(10|11|12|0[1-9])(30|31|2\\d|1\\d|0[1-9])\\w\\d{5}$";
static string regexp_prefix = "^D\\d{2}\\w+(?=[RF][LR]\\d{6})";
static string regexp_position = "[RF][LR](?=\\d{6})";
static string regexp_date = "(?<=[RF][LR])\\d{2}(10|11|12|0[1-9])(30|31|2\\d|1\\d|0[1-9])";
static string regexp_seq = "\\d{5}$";
public void Analyze(DAInterface.DAObject data)
{
//string sn = data.DAValue.ToString();
string orderno = data.DAValue.ToString();
data.WorkOrderID = orderno;
//var plan = GetPlan(data, planno);
var order=data.OrderPlan = GetOrder(data, orderno);
//data.WorkLocState.CurrentState.ORDERPLAN_PID = plan.PID;
DAL.Produce.ProductDAL dal = new DAL.Produce.ProductDAL();
var product = dal.GetNewestProductByOrderNO(orderno);
if (product == null)
{
throw new Exception("无法查到与此FIS码绑定的产品数据!");
}
data.ObjectPID = product.PID;
data.ObjectCacheList.Add(product);
data.AnalyzedValue = product.PRODUCTCODE;
data.MaterialCode = product.MATERIAL_CODE;
MD.DAL.MaterialDAL materialdal = new MaterialDAL();
var material=materialdal.GetMaterial(data.MaterialCode);
data.MaterialName = material == null ? "" : material.MATERIAL_SHORT;
var bindingdal = new DAL.QT.MaterialBindingDAL();
var binding = bindingdal.GetBindingTarget(data.DAI.WORKLOC_CODE + "_MOULD", product.MATERIAL_TYPE);
if (binding == null)
{
throw new Exception("此产品无法在当前工位进行加工!");
}
data.MouldCode = binding.TARGET_CODE;
data.MouldReLocate = true;
if (data.MouldCode.Contains('?'))
{
if (data.AttachData!=null&&data.AttachData.ContainsKey(string.Format("{0}_MouldNO", data.MouldCode.TrimEnd('?'))))
{
var mouldno = data.AttachData[string.Format("{0}_MouldNO", data.MouldCode.TrimEnd('?'))];
if (mouldno == "0")
{
throw new Exception("胎模未在原位无法确定对应胎模!");
}
else
{
data.MouldCode = data.MouldCode.Replace("?", mouldno);
}
}
else
{
if (data.AttachData == null || data.AttachData.Count == 0)
{
data.MouldCode = data.MouldCode.Replace("?", "1");
}
else
{
throw new Exception("此产品无法在当前工位进行加工!");
}
}
}
}
private static Entity.FIS.OrderPlan GetPlan(DAInterface.DAObject data, string planno)
{
var plandal = new DAL.FIS.OrderPlanDAL();
var plan = plandal.GetInfo(new Entity.FIS.OrderPlan { PLAN_NO = planno });
if (plan == null)
{
string regexp_full = "^D\\d{2}\\w+[RF][LR]\\d{2}(10|11|12|0[1-9])(30|31|2\\d|1\\d|0[1-9])\\w\\d{5}$";
string regexp_prefix = "^D\\d{2}\\w+(?=[RF][LR]\\d{6})";
string regexp_position = "[RF][LR](?=\\d{6})";
string regexp_date = "(?<=[RF][LR])\\d{2}(10|11|12|0[1-9])(30|31|2\\d|1\\d|0[1-9])";
string regexp_seq = "\\d{5}$";
if (!Regex.IsMatch(planno, regexp_full))
{
throw new Exception("FIS码格式不正确!");
}
string codeprefix = Regex.Match(planno, regexp_prefix).Value;
string positioncode = Regex.Match(planno, regexp_position).Value;
string date = Regex.Match(planno, regexp_date).Value;
string seq = Regex.Match(planno, regexp_seq).Value;
string materialcode = new DAL.FIS.FISPhraseDAL().GetMESModulCode(codeprefix, positioncode);
if (string.IsNullOrWhiteSpace(materialcode))
{
throw new Exception("FIS码未能识别,FIS短语字典配置不准确或未更新!");
}
DateTime plandate
= new DateTime(2000 + int.Parse(date.Substring(0, 2))
, int.Parse(date.Substring(2, 2))
, int.Parse(date.Substring(4, 2)));
plandal.BaseSession = data.DataSession;
plan = new Entity.FIS.OrderPlan
{
CREATEDATE = DateTime.Now,
COMPLETE_QTY = 0,
CREATEUSER = "",
MATERIAL_CODE = materialcode,//////////////////
PID = Guid.NewGuid().ToString(),
PLAN_DATE = plandate,////////////
PLAN_NO = planno,
PLAN_SEQ = seq,//////////////////
PLAN_STATE = "1",
PLANSOURCE = "0",
QTY = 1,
UPDATEUSER = "",
UPDATEDATE = DateTime.Now,
};
Pbom pbomcode = new PbomDAL().Get(new Pbom { MATERIAL_CODE = plan.MATERIAL_CODE });
if (pbomcode != null)
{
plan.PBOM_CODE = pbomcode.PBOM_CODE;
}
QMAPP.MD.Entity.ProcessRoute routecode = new QMAPP.MD.DAL.ProcessRouteDAL().RouteWithMaterial(plan.MATERIAL_CODE);
if (routecode != null)
{
plan.ROUTE_CODE = routecode.ROUTE_CODE;
}
string workcentercode = new WorkCellDAL().GetWorkcenterWithMaterial(plan.MATERIAL_CODE);
if (workcentercode != null)
{
plan.WORKCENTER_CODE = workcentercode;
}
//赋值新session后插入 zxd20171101
plandal.Insert(plan);
var wodDal = new WorkOrderDAL();
List<QMAPP.MD.Entity.ProcessRouteWorkCellSeq> list = new WorkCellDAL().GetFirstWorkCell(plan.PBOM_CODE);
wodDal.BaseSession = data.DataSession;
//DataRow workOrder = workOrderDt.NewRow();
var workOrder = new WorkOrder();
workOrder.PID = Guid.NewGuid().ToString();
workOrder.ORDERPLANID = plan.PID;
workOrder.ORDERPLAN_NO = plan.PLAN_NO;
workOrder.ORDER_TYPE = EnumGeter.WORKORDERTYPE.FIS.GetHashCode().ToString();
workOrder.SEQ = plan.PLAN_SEQ;
workOrder.MATERIAL_CODE = plan.MATERIAL_CODE;
workOrder.PBOM_CODE = plan.PBOM_CODE;
workOrder.QTY = 1;
workOrder.COMPLETE_QTY = 0;
workOrder.PLAN_DATE = plan.PLAN_DATE;
workOrder.SHIFT_CODE = plan.SHIFT_CODE;
workOrder.WORKCENTER_CODE = plan.WORKCENTER_CODE;
//WorkCell workcellcode = new WorkCellDAL().Get(new WorkCell { WORKCENTER_CODE = info.WORKCENTER_CODE });
workOrder.WORKCELL_CODE = (list.Count > 0) ? list[0].WORKCELL_CODE : "";
workOrder.WORKLOC_CODE = "";
workOrder.REMARK = "";
workOrder.EQPT_NAME = "";
workOrder.EQPT_CODE = "";
workOrder.STATE = EnumGeter.WORKPLANSTATE.READY.GetHashCode();
workOrder.PRI = 1;
//workOrder.UPDATEDATE = DateTime.Now;
workOrder.PRINTED = "1";
wodDal.Insert(workOrder);
}
return plan;
}
private static Entity.ProductionPlan.WorkOrder GetOrder(DAInterface.DAObject data, string orderno)
{
var plandal = new DAL.FIS.OrderPlanDAL();
var workorderdal = new DAL.ProductionPlan.WorkOrderDAL();
//Entity.FIS.OrderPlan plan = null;
Entity.ProductionPlan.WorkOrder order = null;
order = workorderdal.GetOneByOrderNO(orderno);
if (order == null)
{
if (!Regex.IsMatch(orderno, regexp_full))
{
//throw new Exception("FIS码格式不正确!");
throw new Exception("未查询到此条码对应的计划工单,此工单可能已完成或删除!");
}
string codeprefix = Regex.Match(orderno, regexp_prefix).Value;
string positioncode = Regex.Match(orderno, regexp_position).Value;
string date = Regex.Match(orderno, regexp_date).Value;
string seq = Regex.Match(orderno, regexp_seq).Value;
string materialcode = new DAL.FIS.FISPhraseDAL().GetMESModulCode(codeprefix, positioncode);
if (string.IsNullOrWhiteSpace(materialcode))
{
throw new Exception("FIS短语字典配置不准确或未更新!");
}
DateTime plandate
= new DateTime(2000 + int.Parse(date.Substring(0, 2))
, int.Parse(date.Substring(2, 2))
, int.Parse(date.Substring(4, 2)));
plandal.BaseSession = data.DataSession;
var plan = new Entity.FIS.OrderPlan
{
CREATEDATE = DateTime.Now,
COMPLETE_QTY = 0,
CREATEUSER = "",
MATERIAL_CODE = materialcode,//////////////////
PID = Guid.NewGuid().ToString(),
PLAN_DATE = plandate,////////////
PLAN_NO = orderno,
PLAN_SEQ = seq,//////////////////
PLAN_STATE = "1",
PLANSOURCE = "0",
QTY = 1,
UPDATEUSER = "",
UPDATEDATE = DateTime.Now,
};
Pbom pbomcode = new PbomDAL().Get(new Pbom { MATERIAL_CODE = plan.MATERIAL_CODE });
if (pbomcode != null)
{
plan.PBOM_CODE = pbomcode.PBOM_CODE;
}
QMAPP.MD.Entity.ProcessRoute routecode = new QMAPP.MD.DAL.ProcessRouteDAL().RouteWithMaterial(plan.MATERIAL_CODE);
if (routecode != null)
{
plan.ROUTE_CODE = routecode.ROUTE_CODE;
}
string workcentercode = new WorkCellDAL().GetWorkcenterWithMaterial(plan.MATERIAL_CODE);
if (workcentercode != null)
{
plan.WORKCENTER_CODE = workcentercode;
}
//赋值新session后插入 zxd20171101
plandal.Insert(plan);
var wodDal = new WorkOrderDAL();
List<QMAPP.MD.Entity.ProcessRouteWorkCellSeq> list = new WorkCellDAL().GetFirstWorkCell(plan.PBOM_CODE);
wodDal.BaseSession = data.DataSession;
//DataRow workOrder = workOrderDt.NewRow();
order = new WorkOrder();
order.PID = Guid.NewGuid().ToString();
order.ORDERPLANID = plan.PID;
order.ORDERPLAN_NO = plan.PLAN_NO;
order.ORDER_TYPE = EnumGeter.WORKORDERTYPE.FIS.GetHashCode().ToString();
order.SEQ = plan.PLAN_SEQ;
order.MATERIAL_CODE = plan.MATERIAL_CODE;
order.PBOM_CODE = plan.PBOM_CODE;
order.QTY = 1;
order.COMPLETE_QTY = 0;
order.PLAN_DATE = plan.PLAN_DATE;
order.SHIFT_CODE = plan.SHIFT_CODE;
order.WORKCENTER_CODE = plan.WORKCENTER_CODE;
//WorkCell workcellcode = new WorkCellDAL().Get(new WorkCell { WORKCENTER_CODE = info.WORKCENTER_CODE });
order.WORKCELL_CODE = (list.Count > 0) ? list[0].WORKCELL_CODE : "";
order.WORKLOC_CODE = "";
order.REMARK = "";
order.EQPT_NAME = "";
order.EQPT_CODE = "";
order.STATE = EnumGeter.WORKPLANSTATE.READY.GetHashCode();
order.PRI = 1;
//order.UPDATEDATE = DateTime.Now;
order.PRINTED = "1";
wodDal.Insert(order);
}
return order;
}
}
}