From 0d59b3fd8050b0f0766be47ed5527d96bd4bf2f7 Mon Sep 17 00:00:00 2001
From: yangle <admin@YINMOU>
Date: 星期一, 07 四月 2025 09:38:43 +0800
Subject: [PATCH] 斯莫尔插件优化

---
 WFormSynchronizeData_SMR/EquipmentCollectionForm/EquipmentCollectionForm.cs |   71 ++++++++++++++++++++++++++++++-----
 1 files changed, 61 insertions(+), 10 deletions(-)

diff --git a/WFormSynchronizeData_SMR/EquipmentCollectionForm/EquipmentCollectionForm.cs b/WFormSynchronizeData_SMR/EquipmentCollectionForm/EquipmentCollectionForm.cs
index b94db9c..d659723 100644
--- a/WFormSynchronizeData_SMR/EquipmentCollectionForm/EquipmentCollectionForm.cs
+++ b/WFormSynchronizeData_SMR/EquipmentCollectionForm/EquipmentCollectionForm.cs
@@ -326,7 +326,7 @@
                         {
                             if (jsonResult.data[i].propId == 173)
                             {
-                                HInSpectQty = jsonResult.data[i].sum;
+                                //HInSpectQty = jsonResult.data[i].sum;
                             }
                             else if (jsonResult.data[i].propId == 469)
                             {
@@ -341,8 +341,10 @@
                                 HUnRightQty = jsonResult.data[i].sum;
                             }
                         }
+                        //閫氳繃鍙屾柟璁ㄨ 鏈�缁堥噰绾� 妫�楠屾暟閲�=鍚堟牸+涓嶅悎鏍�+鍙枒
+                        HInSpectQty = HRightQty + HUnKnowQty + HUnRightQty;
 
-                      
+
                         string HNumber = "";
                         int HSourceID = 0;
                         string HSourceNumber = "";
@@ -794,7 +796,7 @@
                 if (dr == DialogResult.Yes)
                 {
                     this.txtHBathNo.ReadOnly = true;
-                    this.txtBegin.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+                    this.txtBegin.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:00");
                     //this.txtBegin.Text = "2024-11-21 13:40:27";
                     this.btnBegin.Enabled = false;
                     this.timer.Enabled = true;
@@ -819,7 +821,7 @@
                     // 娣诲姞鏇村閿�煎锛屾牴鎹偍鐨勯渶瑕�
                 });
             JsonResult jsonResult = await getUrl(urls, formData);
-            string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+            string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:00");
 
             if (cmbEquipFile.SelectedIndex == 1)
             {
@@ -919,8 +921,8 @@
             }
             //this.timer.Enabled = false;
 
-            //TimeDate = "2024-08-19 19:38:14.540";
-            //time = "2024-08-19 19:39:14.540";
+            //TimeDate = "2025-02-10 13:10:50";
+            //time = "2025-02-10 13:11:50";
 
             JsonEquipmentData jsonResult = await FindDeviceList(Url, token);
             if (jsonResult.code != "0")
@@ -947,7 +949,7 @@
                 JsonEquipmentData jsonEquipment = await FindAllDevicePropsDetailByTimeRange(Url, token, nos, TimeDate, time);
 
                 var JsonData = "{\"data\":[";
-
+                CustomWriteLog("01" , DateTime.Now.ToString("yyyy-MM-dd"));
                 for (int i = 0; i < jsonEquipment.data.Count; i++)
                 {
                     if (jsonEquipment.data[i].deviceNo.Contains("CMR-ZZ-SE-"))
@@ -956,7 +958,9 @@
                         {
                             for (int k = 0; k < jsonEquipment.data[i].props[j].datas.Count; k++)
                             {
+                                CustomWriteLog("1-" + k + ":" + jsonEquipment.data[i].props[j].datas[k].value, DateTime.Now.ToString("yyyy-MM-dd"));
                                 valueData value = JsonConvert.DeserializeObject<valueData>(jsonEquipment.data[i].props[j].datas[k].value);
+                                CustomWriteLog("2", DateTime.Now.ToString("yyyy-MM-dd"));
                                 if (value.type == "鑹搧")
                                 {
                                     JsonData += "{\"HDate\":\"" + jsonEquipment.data[i].props[j].datas[k].createTime + "\",\"HTechParamName\":\"铻烘瘝鏄惁鍑稿嚭\",\"HResult\":\"OK\",\"HCount\":1,\"HSourceCode\":\"" + jsonEquipment.data[i].deviceNo + "\"},";
@@ -1004,6 +1008,7 @@
                     }
                 }
 
+                CustomWriteLog("02", DateTime.Now.ToString("yyyy-MM-dd"));
                 var  EquipmentStaus = await FindDeviceStatusByNos(Url, token, nos);
 
                 for (int i = 0; i < EquipmentStaus.data.Count; i++)
@@ -1013,7 +1018,11 @@
                         || EquipmentStaus.data[i].no.Contains("CMR-ZD-SD")|| EquipmentStaus.data[i].no.Contains("CMR-ZS-SE-"))
                     {
                         string HBegDate = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
-                        string HEndDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+                        string HEndDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:00");
+
+                        if (DateTime.Parse(HEndDate).AddMinutes(1).ToString("yyyy-MM-dd") != DateTime.Parse(HEndDate).ToString("yyyy-MM-dd")) {
+                            HEndDate= DateTime.Parse(HEndDate).AddMinutes(1).ToString("yyyy-MM-dd HH:mm:00");
+                        }
 
                         JsonResult HEqDate = await FindDeviceStatusTimeByNo(Url, token, EquipmentStaus.data[i].no, HBegDate, HEndDate);
 
@@ -1086,7 +1095,7 @@
                     }
                 }
 
-
+                CustomWriteLog("03", DateTime.Now.ToString("yyyy-MM-dd"));
                 JsonData = JsonData.Substring(0, JsonData.Length - 1);
                 JsonData += "]}";
                 DataSave(JsonData);
@@ -1259,6 +1268,48 @@
             //鍏夋爣閫変腑鍒跺崟浜�
             this.txtHMaker.Focus();
         }
+
+        private static readonly object lockObj = new object();
+        //鍐欐棩蹇�
+        public static void CustomWriteLog(object obj, string FileName, string filePath = "Vlog", bool isAppend = true)
+        {
+            try
+            {
+                lock (lockObj)
+                {
+                    filePath = $@"{filePath}\{FileName}.txt";
+
+                    filePath = AppDomain.CurrentDomain.BaseDirectory + filePath;
+
+                    if (!System.IO.Directory.Exists(Path.GetDirectoryName(filePath)))
+                    {
+                        System.IO.Directory.CreateDirectory(Path.GetDirectoryName(filePath));
+                    }
+
+                    bool fileExists = System.IO.File.Exists(filePath);
+                    //涓嶅瓨鍦� 鍒欏垱寤鸿鏂囦欢
+                    if (!fileExists)
+                    {
+                        System.IO.File.Create(filePath).Close();
+                    }
+
+                    using (StreamWriter writer = new StreamWriter(filePath, isAppend))
+                    {
+                        //瀛樺湪鐨勬椂鍊欐墠鍐欎竴琛�
+                        if (fileExists && isAppend)
+                        {
+                            writer.WriteLine();
+                        }
+
+                        var content = obj is string ? obj : JsonConvert.SerializeObject(obj);
+                        writer.WriteLine($"{DateTime.Now} {content}");
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+            }
+        }
     }
 
 
@@ -1361,5 +1412,5 @@
         public string Id { get; set; }
         public string Name { get; set; }
     }
-   
+
 }

--
Gitblit v1.9.1