private void Init() { var result = AppSession.Dal.GetCommonModelByCondition <StepTrace>($"where id = {taskId}"); if (!result.Success) { Grid1.IsEnabled = false; MessageBox.Show($"未找到任务号为:{taskId}的任务:{result.Msg}"); } else { Grid1.IsEnabled = true; TaskModel = result.Data[0]; Grid1.DataContext = TaskModel; } ////更改当前工序需要,根据产品编码,取对应的ID //var step = AppSession.Dal.GetCommonModelByCondition<Step>($"WHERE productCode ='{TaskModel.ProductCode}'"); //if (!step.Success) //{ // Grid1.IsEnabled = false; // MessageBox.Show($"未找到任务号为:{taskId}的任务:{result.Msg}"); //} //else //{ // var dictDetails = step.Data; // Cbx_StepId.ItemsSource = dictDetails; // Cbx_StepId.DisplayMemberPath = "Name"; // Cbx_StepId.SelectedValuePath = "Id"; //} //var station = AppSession.Dal.GetCommonModelByCondition<Station>($"where 1=1"); //var StepStation = AppSession.Dal.GetCommonModelByCondition<StepStation>($"where 1=1"); }
public TableData Query(StepTrace entity) { var result = new TableData(); var data = _app.Find(EntityToExpression <StepTrace> .GetExpressions(entity)); GetData(data, result); result.count = data.Count(); return(result); }
public BllResult StepTraceExceptionOver(StepTrace stepTrace, string userCode, List <Station> stations, List <Step> steps) { if (stepTrace.Status >= StepTraceStatus.任务完成.GetIndexInt()) { return(BllResultFactory.Error("任务已经完成,不能修改数据")); } var oldStatus = stepTrace.Status; stepTrace.Status = StepTraceStatus.异常结束.GetIndexInt(); stepTrace.UpdateTime = DateTime.Now; stepTrace.UpdateBy = userCode; var step = steps.Find(t => t.Id == stepTrace.NextStepId); using (IDbConnection connection = AppSession.Dal.GetConnection()) { IDbTransaction transaction = null; try { connection.Open(); transaction = connection.BeginTransaction(); //也就是这里已经到了成品下线工序 if (step != null && step.StepType == "FinishedType") { if (stepTrace.WCSLayer != null && stepTrace.WCSLine != null && stepTrace.WCSLayer != "0" && stepTrace.WCSLine != "0") { //这里拿取对应的站台数据,更新库位数据 var res = updateLocation(stepTrace, stations); if (!res.Success) { return(BllResultFactory.Error($"异常结束任务时,更新库位数据{stepTrace.Id}失败:{res.Msg}")); } } } var result = AppSession.Dal.UpdateCommonModel <StepTrace>(stepTrace, connection, transaction); if (!result.Success) { transaction.Rollback(); AppSession.LogService.LogContent(LogTitle.任务状态维护, $"任务号{stepTrace.Id},当前工序:从[{oldStatus}]更新至[{StepTraceStatus.异常结束.GetIndexString()}]成功", userCode, LogLevel.Success); return(BllResultFactory.Error($"异常结束任务{stepTrace.Id}失败:{result.Msg}")); } else { transaction.Commit(); AppSession.LogService.LogContent(LogTitle.任务状态维护, $"任务号{stepTrace.Id},当前工序:从[{oldStatus}]更新至[{StepTraceStatus.异常结束.GetIndexString()}]失败,原因:{result.Msg}", userCode, LogLevel.Success); return(BllResultFactory.Sucess($"异常结束任务{stepTrace.Id}成功")); } } catch (Exception ex) { transaction?.Rollback(); return(BllResultFactory.Error($"异常结束任务{stepTrace.Id}出现异常:{ex.Message}")); } } }
/// <summary> /// 人工确认,新增任务数据 /// </summary> public BllResult HumanTasks(StepTrace stepTrace) { //向工序跟踪日志表插入一条记录 StepTraceLog stepTraceLog = new StepTraceLog(); stepTraceLog.StepTraceId = stepTrace.Id; stepTraceLog.WONumber = stepTrace.WONumber; stepTraceLog.ProductId = stepTrace.ProductId; stepTraceLog.ProductCode = stepTrace.ProductCode; stepTraceLog.SerialNumber = stepTrace.SerialNumber; stepTraceLog.LineId = stepTrace.LineId; stepTraceLog.LastStationId = stepTrace.StationId; stepTraceLog.StationId = stepTrace.NextStationId; //stepTraceLog.SrmCode = truss.Code; stepTraceLog.PassOrFail = ""; stepTraceLog.IsNG = stepTrace.IsNG; stepTraceLog.NGcode = stepTrace.NGcode; stepTraceLog.StationInTime = DateTime.Now; //stepTraceLog.StationOutTime = stepTrace.StationOutTime; stepTraceLog.LineInTime = stepTrace.LineInTime; //stepTraceLog.LineOutTime = DateTime.Now; stepTraceLog.CreateBy = stepTrace.CreateBy; stepTraceLog.CreateTime = DateTime.Now; using (IDbConnection connection = AppSession.Dal.GetConnection()) { IDbTransaction tran = null; try { connection.Open(); tran = connection.BeginTransaction(); var res1 = AppSession.Dal.InsertCommonModel <StepTrace>(stepTrace, connection, tran); if (!res1.Success) { tran?.Rollback(); return(BllResultFactory.Error($"插入工序跟踪表发生错误:{res1.Msg}")); } var res2 = AppSession.Dal.InsertCommonModel <StepTraceLog>(stepTraceLog, connection, tran); if (!res2.Success) { tran?.Rollback(); return(BllResultFactory.Error($"插入工序跟踪日志表发生错误:{res1.Msg}")); } tran.Commit(); stepTrace.Id = res1.Data; stepTraceLog.Id = res2.Data; return(BllResultFactory.Sucess()); } catch (Exception ex) { tran?.Rollback(); return(BllResultFactory.Error($"发生异常:{ex.Message}")); } } }
public TableData TurnStepApp(StepTrace stepTrace, string tostep) { TableData tab = new TableData { code = 200 }; string sErrorMsg = ""; int nofree = 0; try { if (stepTrace != null) { var sidlist = _unitWork.Find <StepStation>(u => u.StepType == tostep).Select(a => a.StationId); List <Equipment> equipments = _unitWork.Find <Equipment>(u => sidlist.Contains(u.StationId)).ToList(); foreach (var equipment in equipments) { if (_unitWork.IsExist <EquipmentStatus>(u => u.EquipmentId.Equals(equipment.Id) && u.Status == "0")) { //调用桁车接口进行转移工序作业,如果接口调用成功,更新下一工位为指定的去向工位; int?toStepId = _unitWork.Find <Step>(u => u.StepType == tostep).Select(a => a.Id).FirstOrDefault(); stepTrace.NextStepId = toStepId; _app.Update(stepTrace); tab.code = 200; tab.msg = "工单号:" + stepTrace.WONumber + "操作成功!"; break; //待桁车工序转移作业完成后调用中控桁车运行节点接口告知中控系统完成信号,中控系统更新StepTrace的当前工位,和下一工序工位,及当前工序,及呼叫焊接设备开始工作 } else { nofree = nofree + 1; if (nofree == equipments.Count) { sErrorMsg += "此工序没有空闲工位可用,无法转到此工序!<br>"; tab.msg = sErrorMsg; } } } } else { sErrorMsg += "数据错误,传入空数据!<br>"; tab.msg = sErrorMsg; } } catch (Exception ex) { tab.code = 300; tab.msg += ex.Message; } return(tab); }
public string Upd(StepTrace Table_entity) { try { _app.Upd(Table_entity); } catch (Exception ex) { Result.Status = false; Result.Message = ex.Message; } return(JsonHelper.Instance.Serialize(Result)); }
/// <summary> /// 空出处理 /// </summary> /// <param name="task"></param> /// <returns></returns> public BllResult EmptyOutHandle(StepTrace task) { //List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>> // { // new KeyValuePair<string, string>("taskId", task.Id.ToString()) // }; //return AppSession.CommonService.FormPost(list, WMSUrls.HandleEmptyOut, client, urls); try { task.Status = (int)StepTraceStatus.异常结束; //task.IsEmptyOut = 1; return(AppSession.Dal.UpdateCommonModel <StepTrace>(task)); } catch (Exception ex) { return(BllResultFactory.Error(null, "更新失败:" + ex.ToString())); } }
public TableData SetNGApp(StepTrace stepTrace, string otype, string ntype, string ncode) { TableData tab = new TableData { code = 200 }; string sErrorMsg = ""; try { if (stepTrace != null) { if (otype == "discard") { stepTrace.IsInvalid = true; stepTrace.IsNG = true; stepTrace.NGcode = ncode; _app.Update(stepTrace); //此处写报废逻辑走向,呼叫桁车转移工序,人工补焊工位标记为报废后应该是直接流向下料口退出线体,不能流向下一工位(机加工序) } else { stepTrace.IsNG = true; stepTrace.NGcode = ncode; _app.Update(stepTrace); //此处写不良去向逻辑,呼叫桁车转移工序 } tab.code = 200; tab.msg = "工单号:" + stepTrace.WONumber + "操作成功!"; } else { sErrorMsg += "数据错误,传入空数据!<br>"; tab.msg = sErrorMsg; } } catch (Exception ex) { tab.code = 300; tab.msg += ex.Message; } return(tab); }
public string GetTemplate() { var result = new TableData(); List <StepTrace> listStepTrace = new List <StepTrace>(); StepTrace entity = _app.FindSingle(u => u.Id > 0); if (entity != null) { listStepTrace.Add(entity); } else { listStepTrace.Add(new StepTrace()); } result.data = listStepTrace; result.count = listStepTrace.Count; return(JsonHelper.Instance.Serialize(result)); }
public Response ImportIn(IFormFile excelfile) { Response result = new Infrastructure.Response(); List <StepTrace> exp = imp.ConvertToModel <StepTrace>(excelfile); string sErrorMsg = ""; for (int i = 0; i < exp.Count; i++) { try { StepTrace e = exp[i]; e.Id = null; _app.Add(e); } catch (Exception ex) { sErrorMsg += "第" + (i + 2) + "行:" + ex.Message + "<br>"; result.Message = sErrorMsg; break; } } if (sErrorMsg.Equals(string.Empty)) { if (exp.Count == 0) { sErrorMsg += "没有发现有效数据, 请确定模板是否正确, 或是否有填充数据!"; result.Message = sErrorMsg; } else { result.Message = "导入完成"; } } else { result.Status = false; result.Message = result.Message; } return(result); }
/// <summary> /// 处理设备下料请求 /// </summary> /// <param name="robot"></param> /// <param name="allEquipments"></param> /// <param name="stepTraceList"></param> /// <param name="plc"></param> /// <returns></returns> public override BllResult ExcuteRequest(Equipment robot, List <Equipment> allEquipments, List <StepTrace> stepTraceList, IPLC plc) { try { var workStation = robot.StationList.Find(t => t.Id == robot.StationId); if (workStation == null) { Logger.Log($"处理设备[{robot.Name}]的站台[{robot.StationId}]下料请求时候,不存在ID为[{robot.StationId}]的站台,请检查站台基础数据", LogLevel.Error); return(BllResultFactory.Error()); } var productTypeProp = robot.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == RobotPcStation.TYPE_Feedback.ToString()); var result1 = int.TryParse(productTypeProp.Value, out int productType); if (productType < 1) { Logger.Log($"处理设备[{robot.Name}]的站台[{robot.StationId}]下料请求失败,工件类型[{productType}]小于1", LogLevel.Error); return(BllResultFactory.Error()); } var Step_Trace_Id = robot.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == PcRobotStation.Step_Trace_Id.ToString()); var convertResult = int.TryParse(Step_Trace_Id.Value, out int stepTraceId); if (!convertResult) { Logger.Log($"处理设备[{robot.Name}]的站台[{robot.StationId}]下料请求失败,工序任务的id[{Step_Trace_Id.Value}]转化为整数失败!", LogLevel.Error); return(BllResultFactory.Error()); } if (stepTraceId > 0) { var stepTrace = stepTraceList.FirstOrDefault(t => t.Id == stepTraceId); if (stepTrace != null) { if (stepTrace.StationId != robot.StationId) { Logger.Log($"处理设备[{robot.Name}]的站台[{robot.StationId}]下料请求失败,工序任务的id[{stepTrace.Id}]对应的站台是[{stepTrace.StationId}],请检查任务数据!", LogLevel.Error); return(BllResultFactory.Error()); } if (stepTrace.WcsProductType != productType) { return(BllResultFactory.Error($"处理设备[{robot.Name}]的站台[{robot.StationId}]下料请求失败,根据任务号[{stepTrace.Id}]查找到的任务工件类型为[{stepTrace.WcsProductType}],设备给出的工件类型是[{productType}],请检查任务数据")); } //向工序跟踪写入下料请求,等待桁车处理 if (stepTrace.Status == StepTraceStatus.设备开始生产.GetIndexInt()) { stepTrace.Status = StepTraceStatus.设备请求下料.GetIndexInt(); stepTrace.UpdateTime = DateTime.Now; stepTrace.UpdateBy = App.User.UserCode; AppSession.Dal.UpdateCommonModel <StepTrace>(stepTrace); Logger.Log($"处理设备[{robot.Name}]的站台[{robot.StationId}]下料请求成功,工序任务id[{Step_Trace_Id.Value}]的状态已修改为[{StepTraceStatus.设备请求下料}]", LogLevel.Success); return(BllResultFactory.Sucess()); } //给桁架下发任务后,清除站台的物料信息 if (stepTrace.Status > StepTraceStatus.设备请求下料.GetIndexInt()) { BllResult plcResult = SendStepTraceToPlc("0", "0", "0", false, robot, plc); if (plcResult.Success) { Logger.Log($"清除设备【{robot.Name}】任务信息成功", LogLevel.Success); } else { Logger.Log($"清除设备【{robot.Name}】任务信息失败,写入PLC失败:原因:{plcResult.Msg}", LogLevel.Error); } return(plcResult); } } else { Logger.Log($"处理设备[{robot.Name}]的站台[{robot.StationId}]下料请求失败,找不到未完成的工序任务id[{Step_Trace_Id.Value}]", LogLevel.Error); return(BllResultFactory.Error()); } } else { // 如果存在 已经处理过的任务,但是还在请求下线,就不处理 if (stepTraceList.Exists(t => t.StationId == robot.StationId && t.Status >= StepTraceStatus.设备请求下料.GetIndexInt())) { return(BllResultFactory.Sucess()); } var createTypeFlagPro = robot.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == RobotPcStation.ManualSign.ToString()); var result = int.TryParse(createTypeFlagPro.Value, out int createTypeFlag); if (createTypeFlag == (int)CreateTypeFlag.手动任务) { var stepTraceCount = AppSession.Dal.GetCommonModelCount <StepTrace>($"where stationId={robot.StationId} and status < {StepTraceStatus.响应桁车取货完成.GetIndexInt()}"); if (!stepTraceCount.Success) { Logger.Log($"[{robot.Name}]的站台[{robot.StationId}]下料请求时候,生成人工确认任务失败,查询任务数据异常,原因:{stepTraceCount.Msg}", LogLevel.Error); return(BllResultFactory.Error()); } if (stepTraceCount.Data > 0) { Logger.Log($"处理设备[{robot.Name}]的站台[{robot.StationId}][{workStation.Name}]下料请求时候,生成人工确认任务失败,当前站台存在[{stepTraceCount.Data}]任务,请先把站台存在的任务完成掉", LogLevel.Error); return(BllResultFactory.Error()); } StepTrace stepTrace = new StepTrace(); //获取产品信息 var productHeaderResult = AppSession.Dal.GetCommonModelByCondition <ProductHeader>($"where wcsProductType = '{productType}'"); if (!productHeaderResult.Success) { Logger.Log($"处理设备[{robot.Name}]的站台[{robot.StationId}]下料请求时候,根据设备工件类型[{productType}]没有检测到对应的产品信息,原因:{productHeaderResult.Msg},请检查产品基础数据", LogLevel.Error); return(BllResultFactory.Error()); } //获取工位工序表--工位类型 var stepStationResult = AppSession.Dal.GetCommonModelByCondition <StepStation>($"where stationId = '{robot.StationId}'"); if (!stepStationResult.Success) { Logger.Log($"处理设备[{robot.Name}]的站台[{robot.StationId}]下料请求时候,根据站台[{robot.StationId}]没有检测到工序工位,原因:{stepStationResult.Msg},请检查基础数据", LogLevel.Error); return(BllResultFactory.Error()); } //获取工序表 var stepResult = AppSession.Dal.GetCommonModelByCondition <Step>($"where productId={productHeaderResult.Data[0].Id} and stepType='{stepStationResult.Data[0].StepType}'"); if (!stepResult.Success) { Logger.Log($"处理设备[{robot.Name}]的站台[{robot.StationId}]下料请求时候,根据产品[{productHeaderResult.Data[0].Id}]和工位类型[{stepStationResult.Data[0].StepType}]没有查询到工序,原因:{stepResult.Msg},请检查基础数据", LogLevel.Error); return(BllResultFactory.Error()); } var step = stepResult.Data[0]; stepTrace.StepId = step.Id.Value; //工件型号 stepTrace.WcsProductType = productType; stepTrace.StationId = robot.StationId; stepTrace.ProductCode = step.ProductCode; stepTrace.Status = StepTraceStatus.设备请求下料.GetIndexInt(); stepTrace.LineId = robot.LineId; stepTrace.WONumber = ""; stepTrace.SerialNumber = ""; stepTrace.StationInTime = DateTime.Now; stepTrace.LineInTime = DateTime.Now; stepTrace.CreateType = CreateTypeFlag.手动任务.GetIndexInt(); //人工确认任务起始点 stepTrace.ManualStartPoint = robot.Name; stepTrace.CreateTime = DateTime.Now; stepTrace.CreateBy = "PLC"; var resultHumanTasks = AppSession.StepTraceService.HumanTasks(stepTrace); if (!resultHumanTasks.Success) { Logger.Log($"处理设备[{robot.Name}]的站台[{robot.StationId}]下料请求时候,人工确认任务失败,原因:{resultHumanTasks.Msg}", LogLevel.Error); return(BllResultFactory.Error()); } Logger.Log($"处理设备[{robot.Name}]的站台[{robot.StationId}]下料请求时候,人工确认任务成功", LogLevel.Success); return(BllResultFactory.Sucess()); } else { Logger.Log($"处理设备[{robot.Name}]的站台[{robot.StationId}]下料请求失败,工序跟踪ID[{stepTraceId}]小于1,也没有人工确认工件类型。", LogLevel.Error); return(BllResultFactory.Error()); } } } catch (Exception ex) { Logger.Log($"处理设备[{robot.Name}]的站台[{robot.StationId}]下料请求时候,发生异常:{ex.Message}", LogLevel.Exception, ex); return(BllResultFactory.Error()); } return(BllResultFactory.Sucess()); }
public string TurnStep(StepTrace steptrace, string tostep) { return(JsonHelper.Instance.Serialize(_app.TurnStepApp(steptrace, tostep))); }
/// <summary> /// 处理定长切割请求 /// </summary> /// <param name="cutter"></param> /// <param name="allEquipments"></param> /// <param name="stepTraceList"></param> /// <param name="plc"></param> /// <returns></returns> public override BllResult ExcuteCut(Equipment cutter, List <Equipment> allEquipments, List <StepTrace> stepTraceList, IPLC plc) { try { var RequestCutTaskId = cutter.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MachineProps.RequestCutTaskId.ToString()); var convertResult = int.TryParse(RequestCutTaskId.Value, out int stationCacheId); if (!convertResult) { Logger.Log($"处理工位[{cutter.StationCode}]的设备[{cutter.Name}] 自动请求切割失败,管材缓存标识[{RequestCutTaskId.Value}]转化为整数失败!", LogLevel.Error); return(BllResultFactory.Error()); } if (stationCacheId < 1) { Logger.Log($"处理工位[{cutter.StationCode}]的设备[{cutter.Name}] 自动请求切割失败,管材缓存标识[{RequestCutTaskId.Value}]不能小于1!", LogLevel.Error); return(BllResultFactory.Error()); } //找出 套料计划 var cutPlanResult = AppSession.Dal.GetCommonModelByConditionWithZero <CutPlan>($" where stationCacheId = {stationCacheId}"); if (!cutPlanResult.Success) { Logger.Log($"查询套料计划出错,原因:{cutPlanResult.Msg}", LogLevel.Error); return(BllResultFactory.Error()); } if (cutPlanResult.Data.Count == 0) { #region 找不到套料方案 ,返回给PLC没有套料方案 //没有套料计划,就告诉定长切割机 切完了 var sendResult = SendCutToPlc(cutter, plc, CutFlag.WCS回复没有套料方案, "0", "0", "0", "0", "0"); if (sendResult.Success) { Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]自动请求切割成功,告诉设备 没有套料方案。", LogLevel.Success); } else { Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]自动请求切割成功失败,写入PLC失败,原因:{sendResult.Msg}", LogLevel.Error); } return(sendResult); #endregion } var cutPlans = cutPlanResult.Data.Where(t => t.Status == CutPlanStatus.初始.GetIndexInt()).ToList(); if (cutPlans.Count == 0) { #region 如果整根管子的套料计划都切割完毕,返回给PLC切割结束 //var stationCacheResult = AppSession.Dal.GetCommonModelByCondition<StationCache>($" where id = '{stationCacheId}' "); //if (!stationCacheResult.Success) //{ // Logger.Log($"处理工位[{cutter.StationCode}]的设备[{cutter.Name}] 自动请求切割失败,查询缓存区失败,原因:[{stationCacheResult.Msg}]", LogLevel.Error); // return BllResultFactory.Error(); //} //var sql = $"update station_cache set status = {StationCacheStatus.使用完毕.GetIndexInt()},updateBy='{App.User.UserCode}',updateTime='{DateTime.Now}' where id = {stationCacheId}"; //using (IDbConnection connection = AppSession.Dal.GetConnection()) //{ // IDbTransaction tran = null; // try // { // connection.Open(); // tran = connection.BeginTransaction(); // connection.Execute(sql, transaction: tran); // //没有套料计划,就告诉定长切割机 切完了 var sendResult = SendCutToPlc(cutter, plc, CutFlag.WCS回复结束切割, "0", "0", "0", "0", "0"); if (sendResult.Success) { //tran.Commit(); Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]自动请求切割成功,告诉设备 结束切割。", LogLevel.Success); } else { //tran?.Rollback(); Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]自动请求切割成功失败,写入PLC失败,原因:{sendResult.Msg}", LogLevel.Error); } return(sendResult); //} //catch (Exception ex) //{ // tran?.Rollback(); // Logger.Log($"处理工位[{cutter.StationCode}]的设备[{cutter.Name}] 自动请求切割的时候,删除管子缓存标识[{stationCacheId}]的数据候发生异常,原因:{ex.Message}", LogLevel.Exception, ex); //} //} //return BllResultFactory.Error(); #endregion } var cutPlan = cutPlans[0]; #region 如果未切割的套料计划,就发送切割机 //根据产品找出前两个工序,第一个是组焊工序,第二个就是下个工序 var stepResult = AppSession.Dal.GetCommonModelByCondition <Step>(""); if (!stepResult.Success) { Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]自动请求切割时候,没有工序数据,原因:{stepResult.Msg}", LogLevel.Error); return(BllResultFactory.Error()); } var step = stepResult.Data.FirstOrDefault(t => t.Code == "Cutting"); if (step == null) { Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]自动请求切割时候,没有检测到[Cutting]工序!", LogLevel.Error); return(BllResultFactory.Error()); } var nextStep = stepResult.Data.FirstOrDefault(t => t.Sequence > step.Sequence); if (nextStep == null) { Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]自动请求切割时候,没有检测到[Cutting]工序的下一道工序!", LogLevel.Error); return(BllResultFactory.Error()); } var productHeaderResult = AppSession.Dal.GetCommonModelByCondition <ProductHeader>($"where wcsProductType = {cutPlan.WcsProductType}"); if (!productHeaderResult.Success) { Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]自动请求切割时候,没有检测到电器编号[{cutPlan.WcsProductType}]对应的产品,原因:{productHeaderResult.Msg}", LogLevel.Error); return(BllResultFactory.Error()); } //向工序表插入一条记录 StepTrace stepTrace = new StepTrace(); stepTrace.WONumber = cutPlan.WONumber; stepTrace.SerialNumber = cutPlan.Id.ToString(); stepTrace.ProductId = productHeaderResult.Data[0].Id.Value; stepTrace.ProductCode = productHeaderResult.Data[0].Code; stepTrace.WcsProductType = cutPlan.WcsProductType; stepTrace.LineId = cutter.LineId; stepTrace.StepId = step.Id.Value; stepTrace.NextStepId = nextStep.Id.Value; stepTrace.StationId = cutter.StationId; stepTrace.PipeMaterial = cutPlan.WcsProductType; stepTrace.PipeLength = cutPlan.Length; stepTrace.PipeDiameter = cutPlan.Diameter; stepTrace.PipeThickness = cutPlan.Thickness; stepTrace.NextStationId = 0; stepTrace.IsNG = false; stepTrace.NGcode = ""; stepTrace.IsInvalid = false; stepTrace.WeldingNo = cutPlan.AssemblyStation.ToString(); stepTrace.Status = StepTraceStatus.设备开始生产.GetIndexInt(); stepTrace.StationInTime = DateTime.Now; stepTrace.LineInTime = DateTime.Now; stepTrace.CreateTime = DateTime.Now; stepTrace.CreateBy = App.User.UserCode; //修改套料状态为已经发送给CES cutPlan.Status = CutPlanStatus.发送定长.GetIndexInt(); using (IDbConnection connection = AppSession.Dal.GetConnection()) { IDbTransaction tran = null; try { connection.Open(); tran = connection.BeginTransaction(); stepTrace.Id = connection.Insert <StepTrace>(stepTrace, transaction: tran); connection.Update <CutPlan>(cutPlan, transaction: tran); //如果是最后一个套料结果,那就可以把管子状态改为使用完毕 if (cutPlans.Count == 1) { var sql = $"update station_cache set status = {StationCacheStatus.使用完毕.GetIndexInt()},updateBy='{App.User.UserCode}',updateTime='{DateTime.Now}' where id = {stationCacheId}"; connection.Execute(sql: sql, transaction: tran); } var sendResult = SendCutToPlc(cutter, plc, CutFlag.WCS回复允许切割, stepTrace.Id.ToString(), stepTrace.PipeMaterial.ToString(), stepTrace.PipeLength.ToString(), stepTrace.PipeDiameter.ToString(), stepTrace.PipeThickness.ToString()); if (sendResult.Success) { tran?.Commit(); Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]自动请求切割成功,返回给设备管子切割[{stepTrace.PipeLength}]长度。", LogLevel.Success); } else { tran?.Rollback(); Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]自动请求切割成功失败,写入PLC失败,原因:{sendResult.Msg}", LogLevel.Error); } return(sendResult); } catch (Exception ex) { tran?.Rollback(); Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]自动请求切割的时候,发生异常,任务:{stepTrace.Id},原因:{ex.Message}", LogLevel.Exception, ex); return(BllResultFactory.Error()); } } #endregion } catch (Exception ex) { Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]允许翻转信号时候,发生异常:{ex.Message}", LogLevel.Exception, ex); } return(BllResultFactory.Error()); }
public Response QCCheckApp(QCCheckModel qccheck) { Response <QCCheckModel> Response = new Response <QCCheckModel>(); string sErrorMsg = ""; //if (!CheckLogin()) //{ // Response.Code = 500; // Response.Status = false; // Response.Message = "请先登录!"; // return Response; //} try { if (qccheck.IsGood == 0)//如果不合格 { OrderHeader orderHeader = _unitWork.FindSingle <OrderHeader>(u => u.Code.Equals(qccheck.OrderCode)); if (orderHeader == null) { sErrorMsg += "工单号为:" + qccheck.OrderCode + "不存在,请确认<br>"; Response.Message = sErrorMsg; } else { if (_unitWork.IsExist <Repair>(u => u.SerialNumber == qccheck.SerialNumber && u.MaterialCode == qccheck.MaterialCode)) { sErrorMsg += "SN:" + qccheck.SerialNumber + "已经判定过,请勿重复判定<br>"; Response.Message = sErrorMsg; } else { Repair repair = new Repair(); repair.WONumber = qccheck.OrderCode; repair.ItemCode = qccheck.ProductCode; repair.SerialNumber = qccheck.SerialNumber; repair.MaterialCode = qccheck.MaterialCode; repair.NGcode = qccheck.NGCode; repair.NGMarkUser = qccheck.NGMarkUser; repair.CreateTime = DateTime.Now; repair.CreateBy = "padApi"; _unitWork.Add(repair); } if (_unitWork.IsExist <StepTrace>(u => u.SerialNumber == qccheck.SerialNumber)) { StepTrace stepTrace = _unitWork.Find <StepTrace>(u => u.SerialNumber == qccheck.SerialNumber).FirstOrDefault(); stepTrace.IsNG = true; stepTrace.NGcode = qccheck.NGCode; stepTrace.UpdateBy = qccheck.NGMarkUser; stepTrace.UpdateTime = DateTime.Now; _unitWork.UpdateByTracking(stepTrace); } } } } catch (Exception ex) { Response.Code = 500; Response.Status = false; Response.Message = (Response.Message == "操作成功" ? "" : Response.Message) + "\r\n" + "Code:" + qccheck.OrderCode + "判定失败!" + ex.Message; } return(Response); }
/// <summary> /// 更新库位表数据源 /// </summary> /// <param name="stepTrace"></param> /// <param name="stations"></param> /// <returns></returns> public BllResult updateLocation(StepTrace stepTrace, List <Station> stations) { try { //var temp = stations.Where(t => t.Code.Contains("StationForFinished")).ToList(); //if (temp.Count == 0 || temp == null) //{ // return BllResultFactory.Error("没有查询到相对应的成品下线站台数据"); //} var station = stations.Find(t => t.Id == stepTrace.NextStationId); if (station != null) { var locationResult = AppSession.Dal.GetCommonModelByCondition <Location>($"where srmCode = '{station.Code}'"); if (locationResult.Success == false) { return(BllResultFactory.Error($"根据{station.Code}查询库位数据失败")); } if (locationResult.Data.Count != 1) { return(BllResultFactory.Error($"根据{station.Code}查询库位数据不是1条,请核对库位基础数据")); } var location = locationResult.Data[0]; if (location.Line < 1 || location.Layer < 1) { location.Row = 1; location.Line = 1; location.Layer = 1; return(AppSession.Dal.UpdateCommonModel <Location>(location)); } if (location.Line == 1 && location.Layer == 1) { return(BllResultFactory.Sucess()); } if (location.Line == 1) { location.Line = 4; location.Layer = (short)(location.Layer - 1); return(AppSession.Dal.UpdateCommonModel <Location>(location)); } if (location.Line > 1) { location.Line = (short)(location.Line - 1); return(AppSession.Dal.UpdateCommonModel <Location>(location)); } return(BllResultFactory.Error("更新下线站台的列层失败,存在程序未处理的情况。")); //string sql_1 = $"update wcslocation set WCSLayer = @WCSLayer,WCSLine=@WCSLine where id = @id "; //string sql_2 = $"update wcslocation set WCSLine=@WCSLine where id = @id "; ////当前列数减一,发生异常情况实际未送过去的, //int? newLine = location.Line - 1; //if (newLine == 0) //{ // var result = AppSession.Dal.ExcuteCommonSqlForInsertOrUpdate(sql_1, new { WCSLine = 1, WCSLayer = 1, id = location.Id }); // if (!result.Success) // { // return BllResultFactory.Error($"更新库位表失败{location.Id}"); // } //} //else //{ // var result = AppSession.Dal.ExcuteCommonSqlForInsertOrUpdate(sql_2, new { WCSLine = newLine, id = location.Id }); // if (!result.Success) // { // return BllResultFactory.Error($"更新库位表失败{location.Id}"); // } //} } return(BllResultFactory.Error($"更新下线站台的列层失败,因为没有找到ID[{stepTrace.NextStationId}]对应的站台")); } catch (Exception) { return(BllResultFactory.Error()); } }
public string SetNG(StepTrace steptrace, string optype, string ngtype, string ngcode) { return(JsonHelper.Instance.Serialize(_app.SetNGApp(steptrace, optype, ngtype, ngcode))); }
public TableData ExportData(StepTrace entity) { return(_app.ExportData(entity)); }
public override BllResult ExcuteArrive(Equipment station, List <Equipment> allEquipments, IPLC plc) { var isSuccess = station.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == StationProps.ArriveResult.ToString()).Value; if (isSuccess == StationArriveResult.成功.GetIndexString()) { var sql = string.Empty; StepTrace stepTrace = null; //获取条码 var barcode = station.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == StationProps.ArriveBarcode.ToString()).Value; var arriveRealAddress = station.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == StationProps.ArriveRealAddress.ToString()).Value; var productTypeProp = station.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == StationProps.ProductId.ToString()); var result1 = int.TryParse(productTypeProp.Value, out int productType); if (productType < 1) { Logger.Log($"处理设备[{station.Name}]的站台[{station.StationId}]下料请求失败,工件类型[{productTypeProp.Value}]不是大于1的整数", LogLevel.Error); return(BllResultFactory.Error()); } var workStation = station.StationList.Find(t => t.Id == station.StationId); if (workStation == null) { Logger.Log($"处理设备[{station.Name}]的站台[{station.StationId}]下料请求时候,不存在ID为[{station.StationId}]的站台,请检查站台基础数据", LogLevel.Error); return(BllResultFactory.Error()); } var backEquipment = allEquipments.Find(t => t.SelfAddress == station.BackAddress); if (backEquipment == null) { return(BllResultFactory.Error($"站台{station.Code}{station.Name}的上一个地址 {station.BackAddress} 没有对应的设备,请检查设备基础数据")); } var stepTraceCount = AppSession.Dal.GetCommonModelByConditionWithZero <StepTrace>($"where stationId={station.StationId} and status in ({StepTraceStatus.设备请求下料.GetIndexInt()},{StepTraceStatus.等待任务执行.GetIndexInt()})"); if (!stepTraceCount.Success) { Logger.Log($"[{station.Name}]的站台[{station.StationId}]下料请求时候,查询数据异常{stepTraceCount.Msg}", LogLevel.Error); return(BllResultFactory.Error()); } if (stepTraceCount.Data.Count > 0) { string ids = $"存在任务号为:{string.Join(",", stepTraceCount.Data.Select(t => t.Id).ToArray())}的任务没有完成"; return(BllResultFactory.Error($"处理设备[{station.Name}]的站台[{station.StationId}][{workStation.Name}]下料请求时候," + $"当前站台存在[{stepTraceCount.Data.Count}]条任务:{ids},请先把站台【{station.Name}】存在的任务完成掉")); } if (!string.IsNullOrWhiteSpace(barcode) && barcode != "0") { var stepTracesResult = AppSession.Dal.GetCommonModelByCondition <StepTrace>($"where id = '{barcode}'"); if (!stepTracesResult.Success || stepTracesResult.Data.Count == 0) { return(BllResultFactory.Error($"站台{station.Code}{station.Name}根据id[{barcode}]查询不到任务")); } if (stepTracesResult.Data.Count() > 1) { return(BllResultFactory.Error($"站台{station.Code}{station.Name}根据id[{barcode}]查找到了多条任务,请检查数据")); } else { //TODO 如果查询到任务与最初产品类型不一致,报错 if (stepTracesResult.Data[0].WcsProductType != productType) { return(BllResultFactory.Error($"站台[{station.Code}],[{station.Name}],[{station.StationId}]根据ID[{stepTrace.Id}]查找到的任务工件类型为[{stepTrace.WcsProductType}],站台给出的工件类型是[{productType}],请检查任务数据")); } stepTrace = stepTracesResult.Data.First(); } } else { //return BllResultFactory.Error($"处理设备[{station.Name}]的站台[{station.StationId}]下料请求失败,请求的ID为[{barcode}],条码不能为空或0"); var createTypeFlagPro = station.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == StationProps.ManualSign.ToString()); if (createTypeFlagPro == null) { Logger.Log($"处理设备[{station.Name}]的站台[{station.StationId}][{workStation.Name}]下料请求时候,{createTypeFlagPro}为空,请核查基础数据配置", LogLevel.Error); return(BllResultFactory.Error()); } var result = int.TryParse(createTypeFlagPro.Value, out int createTypeFlag); if (createTypeFlag == CreateTypeFlag.手动任务.GetIndexInt()) { stepTrace = new StepTrace(); //获取产品信息 var productHeaderResult = AppSession.Dal.GetCommonModelByCondition <ProductHeader>($"where wcsProductType = '{productType}'"); if (!productHeaderResult.Success) { Logger.Log($"处理设备[{station.Name}]的站台[{station.StationId}]下料请求时候,根据设备工件类型[{productType}]没有检测到对应的产品信息,原因:{productHeaderResult.Msg},请检查[产品]基础数据", LogLevel.Error); return(BllResultFactory.Error()); } ////获取工位工序表--工位类型 //var stepStationResult = AppSession.Dal.GetCommonModelByCondition<StepStation>($"where stationId = '{backEquipment.StationId}'"); //if (!stepStationResult.Success) //{ // Logger.Log($"处理设备[{station.Name}]的站台[{station.StationId}]下料请求时候,根据站台[{backEquipment.StationId}]没有检测到工序工位,原因:{stepStationResult.Msg},请检查[工序工位]基础数据", LogLevel.Error); // return BllResultFactory.Error(); //} //获取工序表 var stepResult = AppSession.Dal.GetCommonModelBySql <Step>($"select top 1 step.* from step inner join step_station on step.id = step_station.stepId and step.productId = {productHeaderResult.Data[0].Id} and step_station.stationId = {station.StationId} "); if (!stepResult.Success) { Logger.Log($"处理设备[{station.Name}]的站台[{station.StationId}]下料请求时候,根据产品标识[{productHeaderResult.Data[0].Id}]和工位标识[{station.StationId}]没有查询到工序,原因:{stepResult.Msg},请检查[工序]基础数据", LogLevel.Error); return(BllResultFactory.Error()); } var step = stepResult.Data[0]; stepTrace.StepId = step.Id.Value; //工件型号 stepTrace.WcsProductType = productType; stepTrace.StationId = backEquipment.StationId; stepTrace.ProductCode = step.ProductCode; stepTrace.Status = StepTraceStatus.设备开始生产.GetIndexInt(); stepTrace.LineId = station.LineId; stepTrace.WONumber = ""; stepTrace.SerialNumber = ""; stepTrace.StationInTime = DateTime.Now; stepTrace.LineInTime = DateTime.Now; stepTrace.CreateType = CreateTypeFlag.手动任务.GetIndexInt(); //人工确认任务起始点 stepTrace.ManualStartPoint = station.Name; stepTrace.CreateTime = DateTime.Now; stepTrace.CreateBy = "PLC"; var resultHumanTasks = AppSession.StepTraceService.HumanTasks(stepTrace); if (!resultHumanTasks.Success) { return(BllResultFactory.Error($"处理设备[{station.Name}]的站台[{station.StationId}]下料请求时候,人工确认任务失败,原因:{resultHumanTasks.Msg}")); } } else { return(BllResultFactory.Error($"站台{station.Code}{station.Name}有请求,但是没有任务号,也没有人工确认工件类型。")); } } if (stepTrace.StationId != backEquipment.StationId) { var stepTraceStation = station.StationList.Find(t => t.Id == stepTrace.StationId); if (stepTraceStation == null) { Logger.Log($"站台{station.Code}{station.Name}根据id[{barcode}]查询到达任务的当前站台[{stepTrace.StationId}]不存在,请检查任务数据", LogLevel.Error); return(BllResultFactory.Error()); } Logger.Log($"站台{station.Code}{station.Name}根据id[{barcode}]查询到达任务,任务对应的站台是[{stepTraceStation.Name}],请检查任务数据", LogLevel.Error); return(BllResultFactory.Error()); } if (stepTrace.WcsProductType != productType) { return(BllResultFactory.Error($"站台[{station.Code}],[{station.Name}],[{station.StationId}]根据ID[{stepTrace.Id}]查找到的任务工件类型为[{stepTrace.WcsProductType}],站台给出的工件类型是[{productType}],请检查任务数据")); } if (stepTrace.Status != StepTraceStatus.设备开始生产.GetIndexInt()) { //SendAckToPlc(station, plc, StationMessageFlag.WCSPLCACK, StationLoadStatus.回复到达, arriveRealAddress, "0"); Logger.Log($"站台{station.Code}{station.Name}根据id[{barcode}]的任务状态不是[{StepTraceStatus.设备开始生产}],不能处理!", LogLevel.Success); return(BllResultFactory.Error()); } ////记录原始状态以便回滚 //int tempStatus = stepTrace.Status; //var machining = true.ToString(); //var finished = false.ToString(); var machining = station.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == StationProps.Machining_WCS.ToString()).Value; var finished = station.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == StationProps.AGV_WCS.ToString()).Value; if (machining == true.ToString()) { //转到机加工生产 stepTrace.StationId = station.StationId; stepTrace.Status = StepTraceStatus.设备请求下料.GetIndexInt(); } else if (finished == true.ToString()) { //TODO: 根据已匹配到的任务产品编码,查询与实际成品下线站台的摆放类型 if (stepTrace.ProductCode == null) { Logger.Log($"站台{station.Code}{station.Name}根据任务{barcode}产品编码{stepTrace.ProductCode}为空,请检查数据", LogLevel.Error); return(BllResultFactory.Error()); } var productCodeResult = AppSession.Dal.GetCommonModelByCondition <ProductHeader>($"where Code={stepTrace.ProductCode}"); if (!productCodeResult.Success || productCodeResult.Data.Count == 0) { Logger.Log($"站台{station.Code}{station.Name}根据任务{barcode}产品编码{stepTrace.ProductCode},查询产品表失败,请检查数据", LogLevel.Error); return(BllResultFactory.Error()); } //直接下线 var steps = AppSession.Dal.GetCommonModelBySql <Step>($"select top 1 * from step where productCode = '{stepTrace.ProductCode}' and stepType='FinishedType' order by sequence"); if (!steps.Success || steps.Data.Count == 0) { Logger.Log($"站台{station.Code}{station.Name}根据产品编码{stepTrace.ProductCode}未找到成品下线工序,请检查数据", LogLevel.Error); return(BllResultFactory.Error()); } if (steps.Data.Count() > 1) { Logger.Log($"站台{station.Code}{station.Name}根据产品编码{stepTrace.ProductCode}找到多条成品下线工序,请检查数据", LogLevel.Error); return(BllResultFactory.Error()); } stepTrace.NextStepId = steps.Data.First().Id.Value; stepTrace.StationId = station.StationId; stepTrace.Status = StepTraceStatus.设备请求下料.GetIndexInt(); } else { Logger.Log($"响应站台{station.Code}{station.Name}位置到达失败,任务{stepTrace.Id},任务既没有去机加工信号,也没有下线信号!", LogLevel.Error); return(BllResultFactory.Error()); } using (IDbConnection connection = AppSession.Dal.GetConnection()) { IDbTransaction tran = null; try { connection.Open(); tran = connection.BeginTransaction(); connection.Update <StepTrace>(stepTrace, transaction: tran); //回复位置到达 var temp = SendAckToPlc(station, plc, StationMessageFlag.WCSPLCACK, StationLoadStatus.回复到达, arriveRealAddress, "0"); if (temp.Success) { tran.Commit(); if (stepTrace.CreateType == CreateTypeFlag.手动任务.GetIndexInt()) { return(BllResultFactory.Sucess($"响应站台{station.Code}{station.Name}位置到达,人工确认任务成功,任务{stepTrace.Id}")); } else { return(BllResultFactory.Sucess($"响应站台{station.Code}{station.Name}位置到达成功,任务{stepTrace.Id}")); } } else { tran?.Rollback(); //如果响应PLC失败,就要删除人工确认的任务 if (stepTrace.CreateType == CreateTypeFlag.手动任务.GetIndexInt()) { tran = connection.BeginTransaction(); connection.DeleteList <StepTrace>($"where id in @ids", new { ids = stepTrace.Id.Value }, tran); connection.DeleteList <StepTraceLog>("where stepTraceId in @ids", new { ids = stepTrace.Id.Value }, tran); tran.Commit(); } return(BllResultFactory.Error($"响应站台{station.Code}{station.Name}位置到达失败,任务{stepTrace.Id},回滚任务状态")); } } catch (Exception ex) { tran?.Rollback(); Logger.Log($"站台{station.Code}{station.Name}处理到达响应,出现异常:{ex.Message}", LogLevel.Exception, ex); return(BllResultFactory.Error()); } } } else { Logger.Log($"站台{station.Code}{station.Name}位置电控报告到达失败", LogLevel.Error); return(BllResultFactory.Error()); } }
public override BllResult ExcuteRequest(Equipment station, List <Equipment> allEquipments, IPLC plc) { StepTrace stepTrace = null; var workStation = station.StationList.Find(t => t.Id == station.StationId); if (workStation == null) { Logger.Log($"处理设备[{station.Name}]的站台[{station.StationId}]下料请求时候,不存在ID为[{station.StationId}]的站台,请检查站台基础数据", LogLevel.Error); return(BllResultFactory.Error()); } var productTypeProp = station.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == StationProps.ProductId.ToString()); var result1 = int.TryParse(productTypeProp.Value, out int productType); if (productType < 1) { Logger.Log($"处理设备[{station.Name}]的站台[{station.StationId}]下料请求失败,工件类型[{productTypeProp.Value}]不是大于1的整数", LogLevel.Error); return(BllResultFactory.Error()); } //获取自动任务 var stepTracesResult = AppSession.Dal.GetCommonModelByConditionWithZero <StepTrace>($"WHERE status = {StepTraceStatus.响应放货完成.GetIndexInt()} and stationId = {station.StationId} ORDER BY stationInTime DESC"); if (!stepTracesResult.Success) { Logger.Log($"处理设备[{station.Name}]的站台[{station.StationId}]下料请求失败,查询数据库爆错:{stepTracesResult.Msg}", LogLevel.Error); return(BllResultFactory.Error()); } if (stepTracesResult.Data.Count > 0) { if (stepTracesResult.Data.Count > 1) { string redundanceID = ""; for (var i = 0; i < stepTracesResult.Data.Count; i++) { redundanceID += stepTracesResult.Data[i].Id; redundanceID += ";"; //if (i > 0) //{ // AppSession.Dal.ExcuteCommonSqlForInsertOrUpdate($"UPDATE step_trace SET status = 3 WHERE id = {stepTraces.Data[i].Id}"); //} } return(BllResultFactory.Error($"站台[{station.Code}],[{station.Name}],[{station.StationId}]查找到了多条任务[{redundanceID}],请检查任务数据")); } stepTrace = stepTracesResult.Data[0]; if (stepTrace.WcsProductType != productType) { return(BllResultFactory.Error($"站台[{station.Code}],[{station.Name}],[{station.StationId}]查找到的任务工件类型为[{stepTrace.WcsProductType}],站台给出的工件类型是[{productType}],请检查任务数据")); } } else { var excutingStepTraces = AppSession.Dal.GetCommonModelByCondition <StepTrace>($"where status = {StepTraceStatus.下发放货任务.GetIndexInt()} and nextStationId = {station.StationId}"); if (excutingStepTraces.Success) { //如果有 请求站台有下发放货任务任务的数据,不需要处理 return(BllResultFactory.Sucess()); } var createTypeFlagPro = station.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == StationProps.ManualSign.ToString()); if (createTypeFlagPro == null) { Logger.Log($"处理设备[{station.Name}]的站台[{station.StationId}][{workStation.Name}]下料请求时候,{createTypeFlagPro}为空,请核查基础数据配置", LogLevel.Error); return(BllResultFactory.Error()); } var result = int.TryParse(createTypeFlagPro.Value, out int createTypeFlag); if (createTypeFlag == (int)CreateTypeFlag.手动任务) { //var stepTraceCount = AppSession.Dal.GetCommonModelByCondition<StepTrace>($"where stationId={station.StationId} and status = {StepTraceStatus.响应放货完成.GetIndexInt()}"); //if (!stepTraceCount.Success) //{ // Logger.Log($"[{station.Name}]的站台[{station.StationId}]下料请求时候,生成人工确认任务失败;查询数据异常{stepTraceCount.Msg}", LogLevel.Error); // return BllResultFactory.Error(); //} //if (stepTraceCount.Data.Count > 0) //{ // string ids = $"存在任务号为:{string.Join(",", stepTraceCount.Data.Select(t => t.Id).ToArray())}的任务没有完成"; // Logger.Log($"处理设备[{station.Name}]的站台[{station.StationId}][{workStation.Name}]下料请求时候,生成人工确认任务失败," + // $"当前站台存在[{stepTraceCount.Data.Count}]条任务:{ids},请先把站台【{station.Name}】存在的任务完成掉", LogLevel.Error); // return BllResultFactory.Error(); //} stepTrace = new StepTrace(); //获取产品信息 var productHeaderResult = AppSession.Dal.GetCommonModelByCondition <ProductHeader>($"where wcsProductType = '{productType}'"); if (!productHeaderResult.Success) { Logger.Log($"处理设备[{station.Name}]的站台[{station.StationId}]下料请求时候,根据设备工件类型[{productType}]没有检测到对应的产品信息,原因:{productHeaderResult.Msg},请检查产品基础数据", LogLevel.Error); return(BllResultFactory.Error()); } ////获取工位工序表--工位类型 //var stepStationResult = AppSession.Dal.GetCommonModelByCondition<StepStation>($"where stationId = '{station.StationId}'"); //if (!stepStationResult.Success) //{ // Logger.Log($"处理设备[{station.Name}]的站台[{station.StationId}]下料请求时候,根据站台[{station.StationId}]没有检测到工序工位,原因:{stepStationResult.Msg},请检查 [工序工位] 基础数据", LogLevel.Error); // return BllResultFactory.Error(); //} //获取工序表 var stepResult = AppSession.Dal.GetCommonModelBySql <Step>($"select top 1 step.* from step inner join step_station on step.id = step_station.stepId and step.productId = {productHeaderResult.Data[0].Id} and step_station.stationId = {station.StationId} "); if (!stepResult.Success) { Logger.Log($"处理设备[{station.Name}]的站台[{station.StationId}]下料请求时候,根据产品标识[{productHeaderResult.Data[0].Id}]和工位标识[{station.StationId}]没有查询到工序,原因:{stepResult.Msg},请检查 [工序] 基础数据", LogLevel.Error); return(BllResultFactory.Error()); } var step = stepResult.Data[0]; stepTrace.StepId = step.Id.Value; //工件型号 stepTrace.WcsProductType = productType; stepTrace.StationId = station.StationId; stepTrace.ProductCode = step.ProductCode; stepTrace.Status = StepTraceStatus.响应放货完成.GetIndexInt(); stepTrace.LineId = station.LineId; stepTrace.WONumber = ""; stepTrace.SerialNumber = ""; stepTrace.StationInTime = DateTime.Now; stepTrace.LineInTime = DateTime.Now; stepTrace.CreateType = CreateTypeFlag.手动任务.GetIndexInt(); //人工确认任务起始点 stepTrace.ManualStartPoint = station.Name; stepTrace.CreateTime = DateTime.Now; stepTrace.CreateBy = "PLC"; var resultHumanTasks = AppSession.StepTraceService.HumanTasks(stepTrace); if (!resultHumanTasks.Success) { return(BllResultFactory.Error($"处理设备[{station.Name}]的站台[{station.StationId}]下料请求时候,人工确认任务失败,原因:{resultHumanTasks.Msg}")); } } else { return(BllResultFactory.Error($"站台{station.Code}{station.Name}有请求,但是没有任务号,也没有人工确认工件类型。")); } } var requestNumber = station.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == StationProps.RequestNumber.ToString()).Value; //*********************************************************************************************************************** // 根据托盘上一个入库性质的任务进行查找其长宽高重信息 这个其实不重要---so,what do you want? var requestWeight = station.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == StationProps.RequestWeight.ToString()).Value; var requestLength = station.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == StationProps.RequestLength.ToString()).Value; var requestWidth = station.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == StationProps.RequestWidth.ToString()).Value; var requestHeight = station.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == StationProps.RequestHeight.ToString()).Value; string goAddress = station.GoAddress; if (string.IsNullOrWhiteSpace(goAddress) || goAddress == "0") { return(BllResultFactory.Error($"没有配置站台{station.Code}的去向地址,系统也找不到任务{stepTrace.Id}对应的去向地址")); } //记录旧数据 var updateTime = stepTrace.UpdateTime; var updateBy = stepTrace.UpdateBy; int tempStatus = stepTrace.Status; //更新数据 stepTrace.Status = StepTraceStatus.设备开始生产.GetIndexInt(); stepTrace.UpdateTime = DateTime.Now; stepTrace.UpdateBy = App.User.UserCode; var updateResult = AppSession.Dal.UpdateCommonModel <StepTrace>(stepTrace); if (updateResult.Success) { //回复地址请求 var temp = SendAddressReplyToPlc(station, plc, StationMessageFlag.地址回复, StationLoadStatus.默认, requestNumber, stepTrace.Id.ToString(), requestWeight, requestLength, requestWidth, requestHeight, goAddress, "0"); if (temp.Success) { if (stepTrace.CreateType == CreateTypeFlag.手动任务.GetIndexInt()) { return(BllResultFactory.Sucess($"响应站台{station.Code}{station.Name}地址请求,人工确认任务成功,任务{stepTrace.Id}")); } else { return(BllResultFactory.Sucess($"响应站台{station.Code}{station.Name}地址请求成功,任务{stepTrace.Id}")); } } else { stepTrace.Status = tempStatus; stepTrace.UpdateTime = updateTime; stepTrace.UpdateBy = updateBy; AppSession.Dal.UpdateCommonModel <StepTrace>(stepTrace); return(BllResultFactory.Error($"响应站台{station.Code}{station.Name}地址请求失败,任务{stepTrace.Id},写入PLC失败:{temp.Msg},回滚任务状态")); } } else { return(BllResultFactory.Error($"站台{station.Code}{station.Name},响应请求时更新任务{stepTrace.Id}状态失败,写入数据库失败:{updateResult.Msg}。")); } }
/// <summary> /// 重新下发桁车任务 /// 重新下发任务限制: /// 取货:货叉在中心、联机、无货 /// 放货:货叉在中心、联机、有货 /// </summary> /// <param name="srm"></param> /// <param name="plc"></param> /// <param name="row"></param> /// <param name="column"></param> /// <param name="layer"></param> /// <param name="forkStation">对应桁车的出入口,wcs的桁车出入站台;库内取放为0</param> /// <param name="taskForResend"></param> /// <param name="forkTaskFlag"></param> /// <returns></returns> protected BllResult ReSendTask(Equipment truss, IPLC plc, StepTrace stepTrace, TrussTaskFlag taskFlag, string stationId) { var station = truss.StationList.FirstOrDefault(t => t.Id.ToString() == stationId); if (station == null) { Logger.Log($"未查询到ID为{stationId}的站台", LogLevel.Error); return(BllResultFactory.Error()); } int trussStationId = 0; string wcsLine = "0"; string wcsLayer = "0"; using (IDbConnection connection = AppSession.Dal.GetConnection()) { IDbTransaction tran = null; try { if (taskFlag == TrussTaskFlag.机械手取货) { trussStationId = int.Parse(station.TrussTakeStationId.ToString()); } else if (taskFlag == TrussTaskFlag.机械手放货) { trussStationId = int.Parse(station.TrussPutStationId.ToString()); wcsLine = string.IsNullOrEmpty(stepTrace.WCSLine) ? "0" : stepTrace.WCSLine; wcsLayer = string.IsNullOrEmpty(stepTrace.WCSLayer) ? "0" : stepTrace.WCSLayer; } if (trussStationId == 0) { Logger.Log($"站台[{station.Id}][{station.Name}]没有对应的桁架点位数据,请补齐数据", LogLevel.Error); return(BllResultFactory.Error()); } stepTrace.SendAgain = 2; stepTrace.SrmCode = truss.Code; connection.Open(); tran = connection.BeginTransaction(); connection.Update <StepTrace>(stepTrace, tran); connection.Update <Equipment>(truss, tran); BllResult sendResult = SendTaskToTruss(truss, plc, taskFlag, stepTrace.WcsProductType.ToString(), trussStationId.ToString(), wcsLine, wcsLayer, stepTrace.Id.ToString()); if (sendResult.Success) { tran?.Commit(); Logger.Log($"重新下发桁车{truss.Name}任务,任务id:{stepTrace.Id},操作类型:{taskFlag},目的站台:{stationId} {station.Name},桁车点位{trussStationId},成功", LogLevel.Info); return(BllResultFactory.Sucess()); } else { tran?.Rollback(); stepTrace.SendAgain = 1; Logger.Log($"重新下发桁车{truss.Name}任务,任务id:{stepTrace.Id},操作类型:{taskFlag},目的站台:{stationId} {station.Name},桁车点位{trussStationId},失败:{sendResult.Msg};", LogLevel.Error); return(BllResultFactory.Error()); } } catch (Exception ex) { tran?.Rollback(); stepTrace.SendAgain = 1; Logger.Log($"重新下发桁车{truss.Name}任务,任务id:{stepTrace.Id},操作类型:{taskFlag},目的站台:{stationId} {station.Name},桁车点位{trussStationId},失败:{ex.Message},回滚任务{stepTrace.Id}状态。", LogLevel.Exception, ex); return(BllResultFactory.Error()); } } }
/// <summary> /// 处理切割请求 /// </summary> /// <param name="cutter"></param> /// <param name="allEquipments"></param> /// <param name="stepTraceList"></param> /// <param name="plc"></param> /// <returns></returns> public override BllResult ExcuteCut(Equipment cutter, List <Equipment> allEquipments, List <StepTrace> stepTraceList, IPLC plc) { try { //找出 套料计划 var cutPlanResult = AppSession.Dal.GetCommonModelBySqlWithZero <CutPlan>($" select top 1 * from cutPlan where status = 0"); if (!cutPlanResult.Success) { Logger.Log($"查询套料计划出错,原因:{cutPlanResult.Msg}", LogLevel.Error); return(BllResultFactory.Error()); } if (cutPlanResult.Data.Count == 0) { //没有套料计划,就告诉定长切割机 切完了 var WCSAllowCut = cutter.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MachineProps.WCSAllowCut.ToString()); WCSAllowCut.Value = CutFlag.回复结束切割.ToString(); var plcResult = SendCutToPlc(cutter, CutFlag.回复结束切割, plc); if (plcResult.Success) { Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]自动请求切割成功,告诉设备 结束切割。", LogLevel.Success); return(BllResultFactory.Sucess()); } else { Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]自动请求切割成功失败,写入PLC失败,原因:{plcResult.Msg}", LogLevel.Error); return(BllResultFactory.Error()); } } else { var cutPlan = cutPlanResult.Data[0]; //根据产品找出前两个工序,第一个是组焊工序,第二个就是下个工序 var stepResult = AppSession.Dal.GetCommonModelBySql <Step>($"select top 1 * from step where order by sequence"); if (!stepResult.Success) { Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]自动请求切割时候,没有检测到工序信息,原因:{stepResult.Msg}", LogLevel.Error); return(BllResultFactory.Error()); } //向工序表插入一条记录 StepTrace stepTrace = new StepTrace(); stepTrace.WONumber = cutPlan.WONumber; stepTrace.SerialNumber = cutPlan.Id.ToString(); stepTrace.ProductId = cutPlan.Id.Value; stepTrace.ProductCode = cutPlan.ProductCode; stepTrace.LineId = cutter.LineId; stepTrace.StepId = stepResult.Data[0].Id.Value; stepTrace.StationId = cutter.StationId; //stepTrace.NextStepId = stepResult.Data[1].Id.Value; stepTrace.IsNG = false; stepTrace.NGcode = ""; stepTrace.IsInvalid = false; stepTrace.Status = StepTraceStatus.设备开始生产.GetIndexInt(); stepTrace.StationInTime = DateTime.Now; stepTrace.LineInTime = DateTime.Now; stepTrace.CreateTime = DateTime.Now; stepTrace.CreateBy = App.User.UserCode; var insertResult = AppSession.Dal.InsertCommonModel <StepTrace>(stepTrace); if (!insertResult.Success) { Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]自动请求切割失败,向数据库插入工序监控失败,原因:{insertResult.Msg}", LogLevel.Error); return(BllResultFactory.Error()); } var RequestTaskId = cutter.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MachineProps.RequestTaskId.ToString()); var plcResult = SendCutToPlc(cutter, CutFlag.回复允许切割, plc); if (plcResult.Success) { Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]自动请求切割成功,返回给设备切割数据。", LogLevel.Success); return(BllResultFactory.Sucess()); } else { AppSession.Dal.DeleteCommonModelByIds <StepTrace>(new List <int>() { stepTrace.Id.Value }); Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]自动请求切割成功失败,写入PLC失败,原因:{plcResult.Msg}", LogLevel.Error); return(BllResultFactory.Error()); } } } catch (Exception ex) { Logger.Log($"处理工位[{cutter.StationId}]设备[{cutter.Name}]允许翻转信号时候,发生异常:{ex.Message}", LogLevel.Exception, ex); return(BllResultFactory.Error()); } return(BllResultFactory.Sucess()); }
public string Load(PageReq pageRequest, StepTrace entity) { return(JsonHelper.Instance.Serialize(_app.Load(pageRequest, entity))); }
public TableData Load(PageReq pageRequest, StepTrace entity) { return(_app.Load(pageRequest, entity)); }
public void Ins(StepTrace entity) { _app.Add(entity); }
private BllResult ExcuteRequest(Equipment bevelCcache, Equipment bevel, StepTrace stepTrace, IPLC plc) { //就生成AGV任务并且插入数据库 小车任务的状态和类型需要重新定义? CarTask taskCar = new CarTask(); taskCar.StepTraceId = stepTrace.Id; taskCar.CarNo = 1; taskCar.Type = CarTaskType.取货和放货.GetIndexInt(); taskCar.FromLocation = bevelCcache.Station.TrussTakeStationId.ToString(); taskCar.ToLocation = bevel.Station.TrussPutStationId.ToString(); taskCar.ReSend = 0; taskCar.Status = TaskCarStatus.Init.GetIndexInt(); //taskCar.IsFlip = CarTaskType.取货和放货.GetIndexInt(); taskCar.CreateTime = DateTime.Now; taskCar.EndTime = DateTime.Now; taskCar.StartTime = DateTime.Now; taskCar.UpdateTime = DateTime.Now; //修改工序跟踪 stepTrace.NextStationId = bevel.StationId; stepTrace.Status = StepTraceStatus.等待任务执行.GetIndexInt(); stepTrace.UpdateTime = DateTime.Now; stepTrace.UpdateBy = App.User.UserCode; stepTrace.CreateTime = DateTime.Now; stepTrace.LineInTime = DateTime.Now; // stepTrace.LineOutTime = DateTime.Now; // stepTrace.StationInTime = DateTime.Now; stepTrace.StationOutTime = DateTime.Now; var requestNumber = bevelCcache.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == PipeLineProps.RequestNumber.ToString()); using (IDbConnection connection = AppSession.Dal.GetConnection()) { IDbTransaction tran = null; try { connection.Open(); tran = connection.BeginTransaction(); connection.Insert <CarTask>(taskCar, transaction: tran); connection.Update <StepTrace>(stepTrace, transaction: tran); var sendResult = SendAddressReplyToPlc(bevelCcache, plc, StationMessageFlag.地址回复, StationLoadStatus.默认, requestNumber.Value, stepTrace.Id.ToString(), "", stepTrace.WcsProductType.ToString(), stepTrace.PipeLength.ToString(), stepTrace.PipeDiameter.ToString(), stepTrace.PipeThickness.ToString(), bevelCcache.GoAddress); if (sendResult.Success) { tran.Commit(); Logger.Log($"处理工位[{bevelCcache.StationCode}]的设备[{bevelCcache.Name}] 地址请求 成功,任务:{stepTrace.Id}", LogLevel.Success); return(BllResultFactory.Sucess()); } else { tran?.Rollback(); Logger.Log($"处理工位[{bevelCcache.StationCode}]的设备[{bevelCcache.Name}] 地址请求的时候,写入PLC失败,任务:{stepTrace.Id},原因:{sendResult.Msg}", LogLevel.Error); return(BllResultFactory.Error()); } } catch (Exception ex) { tran?.Rollback(); Logger.Log($"处理工位[{bevelCcache.StationCode}]的设备[{bevelCcache.Name}] 地址请求的时候,发生异常,任务:{stepTrace.Id},原因:{ex.Message}", LogLevel.Exception, ex); return(BllResultFactory.Error()); } } }
public void Upd(StepTrace entity) { _app.Update(entity); }
public Response EquipmentWorkNodeApp(EquipmentWorkNodeModel equipmentWorkNode) { using (var tran = _context.Database.BeginTransaction()) { Response <ReviseModel> Response = new Response <ReviseModel>(); string sErrorMsg = ""; //if (!CheckLogin()) //{ // Response.Code = 500; // Response.Status = false; // Response.Message = "请先登录!"; // return Response; //} try { Equipment equipment = _unitWork.FindSingle <Equipment>(u => u.Code.Equals(equipmentWorkNode.EquipmentCode)); if (equipment == null) { sErrorMsg += "设备号为:" + equipmentWorkNode.EquipmentCode + "系统中不存在,请确认<br>"; Response.Message = sErrorMsg; } else { EquipmentStatus equipmentStatus = _unitWork.FindSingle <EquipmentStatus>(u => u.EquipmentId.Equals(equipment.Id)); if (equipmentWorkNode.EquipmentCode == EquipmentStart.桁车1 || equipmentWorkNode.EquipmentCode == EquipmentStart.桁车2 || equipmentWorkNode.EquipmentCode == EquipmentStart.桁车3) { StepTrace stCar = _unitWork.Find <StepTrace>(u => u.SerialNumber == equipmentWorkNode.SerialNumber).FirstOrDefault(); if (equipmentWorkNode.Status == "1") { stCar.StationId = equipment.StationId; stCar.StationOutTime = DateTime.Now; equipmentStatus.Status = equipmentWorkNode.Status; } else { stCar.StationId = 0; stCar.StationInTime = DateTime.Now; equipmentStatus.Status = "0"; } _unitWork.UpdateByTracking(stCar); equipmentStatus.UpdateBy = "ECSApi"; equipmentStatus.UpdateTime = DateTime.Now; _unitWork.Update(equipmentStatus); } else { //工位工序对应关系 StepStation stepStation = _unitWork.Find <StepStation>(u => u.StationId == equipment.StationId).FirstOrDefault(); Step step = _unitWork.Find <Step>(u => u.ProductCode == equipmentWorkNode.ProductCode && u.StepType == stepStation.StepType).FirstOrDefault(); //更新设备状态 if (equipmentWorkNode.Status == "0") { equipmentStatus.Status = equipmentWorkNode.Status; equipmentStatus.UpdateBy = "ECSApi"; equipmentStatus.UpdateTime = DateTime.Now; _unitWork.Update(equipmentStatus); } else if (equipmentWorkNode.Status == "1")//开始工作 { if (equipmentWorkNode.EquipmentCode == EquipmentStart.组对1 || equipmentWorkNode.EquipmentCode == EquipmentStart.组对2 || equipmentWorkNode.EquipmentCode == EquipmentStart.组对3 || equipmentWorkNode.EquipmentCode == EquipmentStart.组对4 || equipmentWorkNode.EquipmentCode == EquipmentStart.组对5 || equipmentWorkNode.EquipmentCode == EquipmentStart.组对6) {//开始生产,写入在制品 StepTrace steptrace = _unitWork.FindSingle <StepTrace>(u => u.WONumber.Equals(equipmentWorkNode.OrderCode)); if (steptrace == null) { steptrace = new StepTrace(); steptrace.WONumber = equipmentWorkNode.OrderCode; steptrace.ProductCode = equipmentWorkNode.ProductCode; steptrace.SerialNumber = equipmentWorkNode.SerialNumber; steptrace.LineId = equipment.LineId; steptrace.StepId = step.Id; steptrace.StationId = equipment.StationId; steptrace.NextStepId = _unitWork.FindSingle <Step>(u => u.Sequence == step.Sequence + 1).Id; steptrace.IsNG = false; steptrace.IsInvalid = false; steptrace.LineInTime = DateTime.Now; steptrace.StationInTime = DateTime.Now; steptrace.CreateBy = "ECSApi"; steptrace.CreateTime = DateTime.Now; _unitWork.Add(steptrace); } } else { StepTrace st = _unitWork.Find <StepTrace>(u => u.SerialNumber == equipmentWorkNode.SerialNumber).FirstOrDefault(); st.StepId = step.Id; st.StationId = equipment.StationId; if (step.Sequence == 4) { st.NextStepId = 0; } else { st.NextStepId = _unitWork.FindSingle <Step>(u => u.Sequence == step.Sequence + 1).Id; } st.StationInTime = DateTime.Now; _unitWork.UpdateByTracking(st); } equipmentStatus.Status = equipmentWorkNode.Status; equipmentStatus.UpdateBy = "ECSApi"; equipmentStatus.UpdateTime = DateTime.Now; _unitWork.Update(equipmentStatus); } else if (equipmentWorkNode.Status == "2")//完成 { equipmentStatus.Status = "0"; equipmentStatus.UpdateBy = "ECSApi"; equipmentStatus.UpdateTime = DateTime.Now; _unitWork.Update(equipmentStatus); //执行其它逻辑块(如更新steptrace在制品信息,呼叫桁车已转至下一个工序,给三一MES工序报工等) if (_unitWork.IsExist <StepTrace>(u => u.SerialNumber == equipmentWorkNode.SerialNumber)) { //在制品追踪表 StepTrace stepTrace = _unitWork.Find <StepTrace>(u => u.SerialNumber == equipmentWorkNode.SerialNumber).FirstOrDefault(); stepTrace.StationOutTime = DateTime.Now; //取下道工序 int?StationIdSequence = _unitWork.FindSingle <Step>(u => u.Id.Equals(stepTrace.StepId)).Sequence; //如果下道工序为最后一道机加工序则为空否则取下道工序 if (step.Sequence == 4) { stepTrace.LineOutTime = DateTime.Now; stepTrace.NextStepId = 0; _unitWork.UpdateByTracking(stepTrace); OrderHeader oh; if (equipmentWorkNode.OrderCode != null) { oh = _unitWork.Find <OrderHeader>(u => u.Code == equipmentWorkNode.OrderCode).FirstOrDefault(); } else { var headerid = _unitWork.FindSingle <OrderDetiail>(u => u.SerialNumber == equipmentWorkNode.SerialNumber).OrderHeaderId; oh = _unitWork.Find <OrderHeader>(u => u.Id == headerid).FirstOrDefault(); } //更新明细状态为完成 OrderDetiail orderdt = _unitWork.Find <OrderDetiail>(u => u.OrderCode.Equals(equipmentWorkNode.OrderCode) && u.SerialNumber == equipmentWorkNode.SerialNumber).FirstOrDefault(); orderdt.ExecuteStatus = "done"; orderdt.EndTime = DateTime.Now; orderdt.UpdateBy = "ECSApi"; orderdt.UpdateTime = DateTime.Now; _unitWork.Update(orderdt); if (oh.CompleteQty == null) { oh.CompleteQty = 0; } oh.CompleteQty = oh.CompleteQty + 1; List <OrderDetiail> orderDetiails = _unitWork.Find <OrderDetiail>(u => u.OrderCode.Equals(equipmentWorkNode.OrderCode) && u.ExecuteStatus != "done").ToList(); if (orderDetiails.Count == 0) { //更新工单状态为已完成 oh.Status = OrderStatus.完成; oh.ActualEndTime = DateTime.Now; oh.UpdateBy = "ECSApi"; oh.UpdateTime = DateTime.Now; _unitWork.Update(oh); } if (oh.Status == OrderStatus.完成) { //在制品写入历史表 StepTraceHistory stepTraceHistory = _unitWork.FindSingle <StepTraceHistory>(u => u.WONumber.Equals(stepTrace.WONumber)); if (stepTraceHistory == null) { stepTraceHistory = new StepTraceHistory(); stepTrace.CopyTo(stepTraceHistory); stepTraceHistory.Id = null; _unitWork.Add(stepTraceHistory); //删除已完成的在制品数据 _unitWork.DeleteByTracking(stepTrace); } OrderHeaderHistory orderHeaderHistory = _unitWork.FindSingle <OrderHeaderHistory>(u => u.Code.Equals(oh.Code)); if (orderHeaderHistory == null) { orderHeaderHistory = new OrderHeaderHistory(); //工单主表写入工单历史表 oh.CopyTo(orderHeaderHistory); orderHeaderHistory.Id = null; _unitWork.Add(orderHeaderHistory); //写入工单明细历史表 List <OrderDetiail> detiails = _unitWork.Find <OrderDetiail>(u => u.OrderHeaderId.Equals(oh.Id)).ToList(); foreach (OrderDetiail oddt in detiails) { OrderDetiailHistory orderDetiailHistory = new OrderDetiailHistory(); oddt.CopyTo(orderDetiailHistory); orderDetiailHistory.Id = null; orderDetiailHistory.OrderHeaderId = orderHeaderHistory.Id; _unitWork.Add(orderDetiailHistory); } } } } else { //stepTrace.NextStepId = _unitWork.FindSingle<Step>(u => u.Sequence == StationIdSequence + 1).Id; stepTrace.UpdateBy = "ECSApi"; stepTrace.UpdateTime = DateTime.Now; _unitWork.Update(stepTrace); } //写入过站记录表 StepTraceLog stepTraceLog = _unitWork.FindSingle <StepTraceLog>(u => u.WONumber.Equals(stepTrace.WONumber) && u.SerialNumber == stepTrace.SerialNumber && u.StationId == stepTrace.StationId); if (stepTraceLog == null) { stepTraceLog = new StepTraceLog(); stepTraceLog.WONumber = stepTrace.WONumber; stepTraceLog.ProductCode = stepTrace.ProductCode; stepTraceLog.SerialNumber = stepTrace.SerialNumber; stepTraceLog.LineId = stepTrace.LineId; stepTraceLog.StationId = stepTrace.StationId; stepTraceLog.PassOrFail = "pass"; stepTraceLog.IsNG = stepTrace.IsNG; stepTraceLog.NGcode = stepTrace.NGcode; stepTraceLog.LineInTime = stepTrace.LineInTime; stepTraceLog.StationInTime = stepTrace.StationInTime; stepTraceLog.StationOutTime = DateTime.Now; stepTraceLog.CreateBy = "ECSApi"; stepTraceLog.CreateTime = DateTime.Now; //如果工序为最后一道机加则更新出线时间 if (step.Sequence == 4) { stepTraceLog.LineOutTime = DateTime.Now; } _unitWork.Add(stepTraceLog); } } else { sErrorMsg += "在制品:" + equipmentWorkNode.SerialNumber + "不存在或已完工,请至在制品历史页面确认!<br>"; Response.Message = sErrorMsg; } } else { sErrorMsg += "状态为:" + equipmentWorkNode.Status + "不识别的设备状态<br>"; Response.Message = sErrorMsg; } } } tran.Commit(); } catch (Exception ex) { tran.Rollback(); Response.Code = 500; Response.Status = false; Response.Message = (Response.Message == "操作成功" ? "" : Response.Message) + "\r\n" + "EquipmentCode:" + equipmentWorkNode.EquipmentCode + "反馈失败!" + ex.Message; } return(Response); } }
public string Export(StepTrace entity) { return(JsonHelper.Instance.Serialize(_app.ExportData(entity))); }