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); 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; } } @@ -735,7 +763,13 @@ 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); 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>