schangxiang@126.com
2024-08-29 f3ac4e7983dd475d800acc31cbbb8bbaf2e6c638
DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/BLL/WorkPieceInfoManager.cs
@@ -1,4 +1,5 @@
using iWare_SCADA_BusinessLogical.Utils;
using HslCommunication.BasicFramework;
using iWare_SCADA_BusinessLogical.Utils;
using iWare_SCADA_Model;
using iWare_SCADA_Model.MiddleModel;
using iWare_SCADA_Model.TableModel;
@@ -7,6 +8,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.Validation;
using System.Diagnostics;
//using System.Data.Entity.Infrastructure;
using System.Linq;
@@ -237,6 +239,7 @@
                            //每次扫描上线都插入追溯表
                            WorkPieceProcess new_process = new WorkPieceProcess();
                            new_process = EntityPropHelper.Mapper<WorkPieceProcess, WorkPieceInfo>(info);
                            QualityStateHelper.ResetQualityNoOkForNewProcess(ref new_process);
                            new_process.StartTime = DateTimeHelper.GetDateTime();
                            //不再默认赋值为合格 【Editby shaocx,2024-08-16】
@@ -371,12 +374,38 @@
                catch (Exception e)
                {
                    loginfo.Remarks = (loginfo.Remarks ?? "") + $"读取二维码{loginfo.WorkPieceID ?? "空"}更新数据异常{e.Message}";
                    Log4NetHelper.WriteErrorLog(type, $" {loginfo.WorkingProcedure}上线监控读码标记 读取工件码数据[{loginfo.WorkPieceID ?? "空"}]时异常:", e);
                }
                finally
                {
                    loginfo.Id = Yitter.IdGenerator.YitIdHelper.NextId();
                    db.WorkPieceLog.Add(loginfo);
                    db.SaveChanges();
                    //保存数据库的异常捕捉 [Editby shaocx,2024-08-29]
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (DbEntityValidationException exception)
                    {
                        var errorMessages =
                            exception.EntityValidationErrors
                                .SelectMany(validationResult => validationResult.ValidationErrors)
                                .Select(m => m.ErrorMessage);
                        var fullErrorMessage = string.Join(", ", errorMessages);
                        var exceptionMessage = string.Concat(exception.Message, " 验证异常消息是:", fullErrorMessage);
                        Log4NetHelper.WriteErrorLog(type, $" {loginfo.WorkingProcedure}上线监控读码标记 读取工件码数据[{loginfo.WorkPieceID ?? "空"}],保存数据库时异常:" + exceptionMessage, exception);
                        throw new DbEntityValidationException(exceptionMessage, exception.EntityValidationErrors);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
@@ -734,10 +763,17 @@
                        var pro = db.WorkPieceProcess.Where(o => o.WorkPieceID == logMiddle.WorkPieceID && o.WorkingProcedureCurrent == pieceInfo.WorkingProcedureCurrent && o.OperationType == OperationType.生产.ToString()).OrderByDescending(o => o.StartTime).FirstOrDefault();
                        if (pro == null || pro.WorkPieceID.Length < 1 || logMiddle.MonitoringPoint.Equals("OP1002") || logMiddle.MonitoringPoint.Equals("OP1003") || logMiddle.MonitoringPoint.Contains("OP2002"))
                        {// OP10 没有上线扫码枪,约定用测量完成信号当上线标记,所以上线需要修改的字段放这里
                            //上线是每次都插入
                         //上线是每次都插入
                            WorkPieceProcess process_05 = WorkPieceProcessHelper.CreateWorkPieceProcessForOP05(logMiddle, db, pieceInfo);
                            if (process_05 != null)
                            {//创建OP05工序,当没有05工序时,才创建 【Editby shaocx,2024-08-29】
                                db.WorkPieceProcess.Add(process_05);
                            }
                            WorkPieceProcess process = new WorkPieceProcess();
                            process = EntityPropHelper.Mapper<WorkPieceProcess, WorkPieceInfo>(pieceInfo);
                            QualityStateHelper.ResetQualityNoOkForNewProcess(ref process);
                            process.StartTime = DateTimeHelper.GetDateTime();
                            //不再默认赋值为合格 【Editby shaocx,2024-08-16】
@@ -1098,6 +1134,7 @@
                        //每次SPC 都插入追溯表
                        WorkPieceProcess process = new WorkPieceProcess();
                        process = EntityPropHelper.Mapper<WorkPieceProcess, WorkPieceInfo>(cur_db_info);
                        QualityStateHelper.ResetQualityNoOkForNewProcess(ref process);
                        process.StartTime = DateTimeHelper.GetDateTime();
                        process.OperationType = OperationType.SPC.ToString();
                        process.QualityState = (int)QualityState.Suspected;
@@ -1250,6 +1287,7 @@
                            info.QualityStateUpdateMode = QualityStateUpdateMode.Auto.ToString();
                            //*/
                            var qualityData = db.QualityDataInfo.Where(o => o.WorkPieceID == logMiddle.WorkPieceID).FirstOrDefault();
                            if (qualityData == null || qualityData.WorkPieceID.Length < 1 || qualityData.WorkingProcedure.Length < 1)
                            {//插入QualityDataInfo表
@@ -1330,11 +1368,14 @@
                        {
                            WorkPieceProcess process = new WorkPieceProcess();
                            process = EntityPropHelper.Mapper<WorkPieceProcess, WorkPieceInfo>(info);
                            QualityStateHelper.ResetQualityNoOkForNewProcess(ref process);
                            process.Id = Yitter.IdGenerator.YitIdHelper.NextId();
                            process.StartTime = DateTimeHelper.GetDateTime();
                            process.EndTime = DateTimeHelper.GetDateTime();
                            if (logMiddle.WorkingProcedure.Equals("OP80"))
                            {//OP80的质量数据是后来获取文件搞的
                             //质检数据,再考虑 另外两种状态  【Editby shaocx,2024-08-27】
                                QualityStateHelper.SetQualityStateForOP80(logMiddle, ref info, ref process);
                            }
                            else
                            {
@@ -1360,6 +1401,11 @@
                        }
                        else
                        {
                            if (logMiddle.WorkingProcedure.Equals("OP80"))
                            {//OP80的质量数据是后来获取文件搞的
                             //质检数据,再考虑 另外两种状态  【Editby shaocx,2024-08-27】
                                QualityStateHelper.SetQualityStateForOP80(logMiddle, ref info, ref pro);
                            }
                            if (op80id > 0)
                            {
                                pro.QualityDataInfoID = op80id;