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

161 lines
6.6 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 TJDPFISCodeAnalyzer : DAInterface.IDataAnalyzer
{
static string regexp_full = "^770(C|M){2}([0-9])+[FL][RL][FR][RR][0-9]+$";
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 = GetOrder(data, orderno);
data.OrderPlan = plan;
//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("无法查到与此条码相关的产品数据!");
}
//data.ObjectPID = product.PID;
data.AnalyzedValue = plan.ORDERPLAN_NO;
//data.MaterialCode = plan.MATERIAL_CODE;
//var bindingdal = new DAL.QT.MaterialBindingDAL();
//var binding = bindingdal.GetBindingTarget("MOULD", product.MATERIAL_TYPE);
//if (binding == null)
//{
// throw new Exception("此产品无法在当前工位进行加工!");
//}
//data.MouldCode = binding.TARGET_CODE;
}
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码未能识别,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;
}
}
}