schangxiang@126.com
2024-08-29 f3ac4e7983dd475d800acc31cbbb8bbaf2e6c638
修复 OP05工位 获取打标二维码,会漏获取数据
已添加1个文件
已修改7个文件
301 ■■■■■ 文件已修改
DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/BLL/WorkPieceInfoManager.cs 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/DataCaptureHandlerV2/DataCaptureHandler_01.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/Utils/WorkPieceProcessHelper.cs 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/iWare_SCADA_BusinessLogical.csproj 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_FormTest/Form1.Designer.cs 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_FormTest/Form1.cs 130 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_Test/UnitTest1.cs 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_Test/iWare_SCADA_Test.csproj 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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;
@@ -372,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);
                    //保存数据库的异常捕捉 [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;
                    }
                }
@@ -737,6 +765,12 @@
                        {// 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);
DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/DataCaptureHandlerV2/DataCaptureHandler_01.cs
@@ -191,8 +191,8 @@
                        threadStatusMonitor.Remarks = $"abcdefg:{RandomHelper.GenerateRandomCode(4)}";
                        if (!_dataCaptureConfig.DataCaptureFrequency.HasValue || _dataCaptureConfig.DataCaptureFrequency < 10)
                        {
                            threadStatusMonitor.ThreadFrequency = 5000;
                            Thread.Sleep(5000);
                            threadStatusMonitor.ThreadFrequency = 1000;
                            Thread.Sleep(1000);
                        }
                        else
                        {
DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/Utils/WorkPieceProcessHelper.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,68 @@

using iWare_SCADA_BusinessLogical.BLL;
using iWare_SCADA_Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace iWare_SCADA_BusinessLogical.Utils
{
    /// <summary>
    /// å·¥åºå¸®åŠ©ç±»
    /// </summary>
    public class WorkPieceProcessHelper
    {
        /// <summary>
        /// åˆ›å»ºOP05工序数据
        /// </summary>
        /// <param name="db"></param>
        /// <param name="pieceInfo"></param>
        /// <returns></returns>
        public static WorkPieceProcess CreateWorkPieceProcessForOP05(WorkPieceLogMiddle logMiddle, DbModel db, WorkPieceInfo pieceInfo)
        {
            if (!logMiddle.MonitoringPoint.Equals("OP1002"))
            {
                return null;
            }
            var _procedureCurrent_05 = "OP05";
            var pro_05 = db.WorkPieceProcess.Where(o => o.WorkPieceID == pieceInfo.WorkPieceID && o.WorkingProcedureCurrent == _procedureCurrent_05
            && o.OperationType == OperationType.生产.ToString()).OrderByDescending(o => o.StartTime).FirstOrDefault();
            if (pro_05 == null)
            {
                WorkPieceProcess process = new WorkPieceProcess();
                process.WorkPieceID = pieceInfo.WorkPieceID;
                var _time = DateTimeHelper.GetDateTime().AddMinutes(-3);
                var _user = "OP0501";
                process.StartTime = _time;
                process.EndTime = _time;
                process.EquipmentID = "EOP05";
                process.WorkingProcedureCurrent = _procedureCurrent_05;
                process.QualityState = (int)QualityState.OK;
                process.Id = Yitter.IdGenerator.YitIdHelper.NextId();
                process.CreatedUserName = _user;
                process.CreatedTime = _time;
                process.UpdatedUserName = _user;
                process.UpdatedTime = _time;
                process.OperationType = OperationType.生产.ToString();
                process.Remarks = "";
                return process;
            }
            return null;
        }
    }
}
DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_BusinessLogical/iWare_SCADA_BusinessLogical.csproj
@@ -156,6 +156,7 @@
      <DesignTime>True</DesignTime>
      <DependentUpon>Resources.resx</DependentUpon>
    </Compile>
    <Compile Include="Utils\WorkPieceProcessHelper.cs" />
    <Compile Include="Utils\QualityStateHelper.cs" />
    <Compile Include="Utils\MonitorHelper.cs" />
    <Compile Include="Utils\SystemBussinessHelper.cs" />
DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_FormTest/Form1.Designer.cs
@@ -38,6 +38,7 @@
            this.label16 = new System.Windows.Forms.Label();
            this.dateTimePicker_Start = new System.Windows.Forms.DateTimePicker();
            this.btn_TongJi = new System.Windows.Forms.Button();
            this.button5 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // button1
@@ -137,11 +138,24 @@
            this.btn_TongJi.UseVisualStyleBackColor = false;
            this.btn_TongJi.Click += new System.EventHandler(this.btn_TongJi_Click);
            // 
            // button5
            //
            this.button5.BackColor = System.Drawing.Color.Aqua;
            this.button5.Location = new System.Drawing.Point(444, 605);
            this.button5.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
            this.button5.Name = "button5";
            this.button5.Size = new System.Drawing.Size(155, 48);
            this.button5.TabIndex = 20;
            this.button5.Text = "分析缺工序问题";
            this.button5.UseVisualStyleBackColor = false;
            this.button5.Click += new System.EventHandler(this.button5_Click);
            //
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(1307, 688);
            this.Controls.Add(this.button5);
            this.Controls.Add(this.tb_TongJi);
            this.Controls.Add(this.checkBox_NowDay);
            this.Controls.Add(this.dateTimePicker_End);
@@ -171,6 +185,7 @@
        private System.Windows.Forms.Label label16;
        private System.Windows.Forms.DateTimePicker dateTimePicker_Start;
        private System.Windows.Forms.Button btn_TongJi;
        private System.Windows.Forms.Button button5;
    }
}
DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_FormTest/Form1.cs
@@ -183,5 +183,135 @@
            this.tb_TongJi.Text = str;
        }
        private void button5_Click(object sender, EventArgs e)
        {
            //分析缺工序
            this.tb_TongJi.Text = "";
            //某段时间的统计
            var str_start = this.dateTimePicker_Start.Value.ToString("yyyy-MM-dd" + " " + "00:00:00");
            var str_end = this.dateTimePicker_End.Value.ToString("yyyy-MM-dd" + " " + "23:59:59");
            var start = Convert.ToDateTime(str_start);
            var end = Convert.ToDateTime(str_end);
            int allPlacesCount = 0;
            List<WorkPieceProcess> workPieceProcessList = new List<WorkPieceProcess>();
            List<string> js_strList = new List<string>();
            List<string> strList = new List<string>() {
                "OP05","OP10","OP20","OP30","OP35","OP40","OP50","OP60","OP70","OP80"
            };
            var q_strList = string.Join(",", strList);
            var str = "";
            str += "时间范围: " + str_start + "至" + str_end + " \r\n";
            using (DbModel edm = new DbModel())
            {
                var pieces = edm.WorkPieceInfo.AsNoTracking().Where(x =>
                 (x.CreatedTime >= start && x.CreatedTime <= end)).ToList();
                var queryIds = pieces.Select(x => x.WorkPieceID).ToList();
                var allPlaces = edm.WorkPieceProcess.AsNoTracking().Where(x => queryIds.Contains(x.WorkPieceID)).ToList();
                var groups = allPlaces.GroupBy(x => x.WorkPieceID).OrderBy(x => x.Key);
                foreach (var gg in groups)
                {
                    var _key = gg.Key;
                    if (_key.Length != 22)
                    {
                        continue;
                    }
                    if (!(_key.IndexOf("DZ") > -1))
                    {
                        continue;
                    }
                    //重新读取数据库
                    var _list = gg.ToList().OrderByDescending(x => x.CreatedTime);
                    if (_key == "DZ045L2408290100451PAS")
                    {
                        var zz = "";
                    }
                    var fisrt = _list.FirstOrDefault();
                    var first_pr = fisrt.WorkingProcedureCurrent;
                    var bb = first_pr.Substring(2, 2);
                    int ii = Convert.ToInt32(bb);
                    List<string> new_strList = GetListForOP(ii);//全部的
                    var curList = _list.Select(x => x.WorkingProcedureCurrent).ToList();
                    var cur_new_strList = new_strList.Where(x => !curList.Contains(x)).ToList();
                    if (cur_new_strList.Count > 0)
                    {
                        //         //再读下数据库
                        //         _list = edm.WorkPieceProcess.AsNoTracking().Where(x =>
                        //x.WorkPieceID == _key).ToList().OrderByDescending(x => x.CreatedTime);
                        //         curList = _list.Select(x => x.WorkingProcedureCurrent).ToList();
                        //         cur_new_strList = new_strList.Where(x => !curList.Contains(x)).ToList();
                    }
                    //看看前面的工序是否都有
                    foreach (var item in cur_new_strList)
                    {
                        workPieceProcessList.Add(new WorkPieceProcess()
                        {
                            WorkingProcedureCurrent = item,
                            WorkPieceID = _key
                        });
                        js_strList.Add(item);
                        allPlacesCount++;
                    }
                }
            }
            var hzStr = "";
            //var groups22 = js_strList.GroupBy(x => x).OrderBy(x => x.Count());
            var groups22 = js_strList.GroupBy(x => x).OrderBy(x => x.Key);
            foreach (var gg in groups22)
            {
                hzStr += $"工序缺失{gg.Key} å…±{gg.ToList().Count()}个" + "\r\n";
            }
            var total = $"总计缺失:{allPlacesCount}。";
            total += "\r\n";
            total += hzStr;
            total += "\r\n";
            //处理
            workPieceProcessList = workPieceProcessList.OrderBy(x => x.WorkingProcedureCurrent).ToList();
            foreach (var item in workPieceProcessList)
            {
                str += $"缺少{item.WorkingProcedureCurrent}工序,WorkPieceID: {item.WorkPieceID}  \r\n";
            }
            str += "\r\n";
            this.tb_TongJi.Text = total + str;
        }
        private List<string> GetListForOP(int ii)
        {
            List<string> new_strList = new List<string>() { };
            List<string> strList = new List<string>() {
                "OP05","OP10","OP20","OP30","OP35","OP40","OP50","OP60","OP70","OP80"
            };
            foreach (var item in strList)
            {
                var bb = item.Substring(2, 2);
                int dd = Convert.ToInt32(bb);
                if (dd <= ii)
                {
                    new_strList.Add(item);
                }
            }
            return new_strList;
        }
    }
}
DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_Test/UnitTest1.cs
@@ -3,8 +3,10 @@
using iWare_SCADA_BusinessLogical.Utils;
using iWare_SCADA_Model;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data.Entity.Validation;
using System.IO;
using System.Linq;
@@ -13,6 +15,46 @@
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethoEntityValidationErrors()
        {
            var aa = "";
            WorkPieceInfo cur_db_info = new WorkPieceInfo()
            {
                WorkingProcedureCurrent = "OP05"
            };
            try
            {
                using (DbModel db = new DbModel())
                {
                    db.WorkPieceInfo.Add(cur_db_info);
                    db.SaveChanges();
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                //var bb = dbEx.EntityValidationErrors.ToList();
                //var pp = bb.First().ValidationErrors.ToList();
                //var z = JsonConvert.SerializeObject(pp);
                var errorMessages =
                    dbEx.EntityValidationErrors
                        .SelectMany(validationResult => validationResult.ValidationErrors)
                        .Select(m => m.ErrorMessage);
                var fullErrorMessage = string.Join(", ", errorMessages);
                //throw new DbEntityValidationException(exceptionMessage, exception.EntityValidationErrors);
            }
            catch (Exception)
            {
                throw;
            }
        }
        [TestMethod]
DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_Test/iWare_SCADA_Test.csproj
@@ -52,8 +52,13 @@
    <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>..\packages\MSTest.TestFramework.2.2.7\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
    </Reference>
    <Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\DLL\Newtonsoft.Json.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Data" />
    <Reference Include="Yitter.IdGenerator.Net45, Version=1.0.0.4, Culture=neutral, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\packages\Yitter.IdGenerator.Net45.1.0.0\lib\net452\Yitter.IdGenerator.Net45.dll</HintPath>