From b62a2f5ad99995ec01da71b9f93be7284023171b Mon Sep 17 00:00:00 2001
From: chr <chr@chr.com>
Date: 星期二, 20 八月 2024 11:29:13 +0800
Subject: [PATCH] 优化插件;

---
 PdmSwPlugin.PDM/PdmControl.xaml.cs |  118 ++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 65 insertions(+), 53 deletions(-)

diff --git a/PdmSwPlugin.PDM/PdmControl.xaml.cs b/PdmSwPlugin.PDM/PdmControl.xaml.cs
index 909cb44..d4b28ac 100644
--- a/PdmSwPlugin.PDM/PdmControl.xaml.cs
+++ b/PdmSwPlugin.PDM/PdmControl.xaml.cs
@@ -34,6 +34,7 @@
 using static PdmSwPlugin.PDM.Event.PdmEvent;
 using System.Windows.Interop;
 using PdmSwPlugin.Commmon.Control;
+using PdmSwPlugin.Common.Entity.System;
 
 namespace PdmSwPlugin.PDM
 {
@@ -856,6 +857,12 @@
             List<PdmBom> treeBoms = model.bomTreeReader.TreeList.ToList();
             if (treeBoms == null || treeBoms.Count <= 0) return;
             treeBoms[0].selected = cb.IsChecked.Value;
+            model.RefreshSelectedBomCount();
+        }
+
+        private void SingleCheckBox_Event(object sender, RoutedEventArgs e)
+        {
+            model.RefreshSelectedBomCount();
         }
 
         /// <summary>
@@ -898,6 +905,11 @@
             return result;
         }
 
+        /// <summary>
+        /// 澶勭悊璐ㄩ噺锛屼繚鐣�6浣嶅皬鏁�
+        /// </summary>
+        /// <param name="number"></param>
+        /// <returns></returns>
         public static string HandleMass(double number)
         {
             return Math.Round(number, 6).ToString("0.000000");
@@ -925,6 +937,7 @@
             allProperties["鏂囦欢鍚庣紑"] = Path.GetExtension(filepath);
             // 鏂囦欢璺緞
             allProperties["鏂囦欢璺緞"] = filepath;
+            allProperties["鍘嗗彶鍥剧焊"] = drawInfo.HistoryData.ToString();
             string drawFilePath = filepath.Replace(Path.GetExtension(filepath), ".slddrw");
             bool drawExists = File.Exists(drawFilePath);
             // 宸ョ▼鍥句竴鑷存�ф鏌�
@@ -988,6 +1001,10 @@
             return drawInfo;
         }
 
+        /// <summary>
+        /// 鑾峰彇鍏ㄩ儴灞炴��
+        /// </summary>
+        /// <param name="param"></param>
         public void GetAll(object param)
         {
             object[] datas = param as object[];
@@ -1055,14 +1072,16 @@
             Dictionary<string, DrawInfo> checkResult = result.HandleResult();
             foreach (string key in properties.Keys)
             {
-                if (!checkResult[key].checkRuleOk)
-                {
-                    allSuccess = false;
-                }
                 properties[key].checkRuleResult = checkResult[key].checkRuleResult;
                 properties[key].errMessages = checkResult[key].errMessages;
                 var msgs = checkResult[key].errMessages;
-                if (msgs != null && msgs.Count > 0)
+                if (!properties[key].HistoryData && !checkResult[key].checkRuleOk)
+                {
+                    // 涓嶆槸鍘嗗彶鏁版嵁骞朵笖鏈夋湭閫氳繃鐨勶紝鏍囪涓篺alse
+                    allSuccess = false;
+                }
+                
+                if (!properties[key].HistoryData && msgs != null && msgs.Count > 0)
                 {
                     foreach (string msg in msgs)
                     {
@@ -1148,6 +1167,8 @@
             {
                 try
                 {
+                    // 瀵规墍鏈夌殑BOM鍋氳鍒欐鏌�
+                    bool allSuccess = DoCheckRule(out _);
                     // 鍏堣幏鍙栨墍鏈夌殑BOM
                     HashSet<string> cache = new HashSet<string>();
                     // 鐒跺悗绛涢�夐�変腑鐨凚OM
@@ -1156,20 +1177,13 @@
                     {   // 濡傛灉娌℃湁閫変腑鐨凚OM锛岄偅灏辨槸鎵�鏈塀OM
                         boms = model.bomTreeReader.CacheList.ToList();
                     }
-                    // 绛涢�夋湁鍥剧焊鐨勶紝鏈彁浜ょ殑锛岄浂浠朵綋鍔犲伐浠惰繘琛屼笂浼�
+                    // 绛涢�夋湁鍥剧焊鐨勶紝鍦ㄧ墿鏂欐槑缁嗕腑锛屾湭鎻愪氦鐨勶紝鍦ㄧ墿鏂欐槑缁嗚〃涓殑闆朵欢浣撳姞宸ヤ欢杩涜涓婁紶
                     boms = boms.Where(b =>
                     {
                         if (!cache.Contains(b.partModel))
                         {
                             cache.Add(b.partModel);
-                            // 鏂囨。瀛樺湪鐨�
-                            return b.lost != true
-                            // && b.drawingType == (int)swDocumentTypes_e.swDocPART
-                            // 鏄姞宸ヤ欢鐨�
-                            && b.produceWay == "鍔犲伐浠�"
-                            // 鏈鎻愪氦鐨�
-                            && (b.drawStatus != "submitted" && b.drawStatus != "resubmitted")
-                            && (b.drawStatus != "completed" || b.auditedMd5Changed);
+                            return b.NeedAudit;
                         }
                         return false;
                     }).ToList();
@@ -1179,12 +1193,11 @@
                         this.Warning("鍙湁鏈彁浜よ繃鎴栧彂鐢熷彉鏇寸殑鍔犲伐浠跺浘绾稿彲浠ヨ繘琛屽鏍�");
                         return;
                     }
-                    // 瀵规墍鏈夌殑BOM鍋氳鍒欐鏌�
-                    bool allSuccess = DoCheckRule(out _);
+
                     if (!allSuccess)
                     {
                         // 濡傛灉鏈夋湭閫氳繃鐨勫浘绾革紝闇�瑕佹彁绀�
-                        var err = boms.Where(b => !b.checkRuleOk).ToList();
+                        var err = boms.Where(b => !b.IsHistoryData && !b.checkRuleOk).ToList();
                         if (err != null && err.Count > 0)
                         {
                             List<string> msgs = new List<string>();
@@ -1192,6 +1205,7 @@
                             {
                                 if (ee.drawInfo.errMessages == null)
                                 {
+                                    msgs.Add($"鐗╂枡銆恵ee.partNo}銆戞湭閫氳繃瑙勫垯妫�鏌ワ紒");
                                     continue;
                                 }
                                 foreach (string msg in ee.drawInfo.errMessages)
@@ -1207,18 +1221,28 @@
                             });
                             return;
                         }
-
-                        // 涓嶇浉鍏崇殑瑙勫垯妫�鏌ヤ笉閫氳繃灏辨棤鎵�璋撲簡
-                        /*int res = SwApp.SendMsgToUser2("鏈夋湭閫氳繃瑙勫垯妫�鏌ョ殑鍥剧焊锛屾槸鍚︾户缁紵", (int)swMessageBoxIcon_e.swMbWarning,
-                            (int)swMessageBoxBtn_e.swMbOkCancel);
-
-                        if (res == (int)swMessageBoxResult_e.swMbHitCancel)
-                        {
-                            return;
-                        }*/
                     }
 
                     // 閮介�氳繃浜嗭紝鍐嶈繘琛屽鎵�
+
+                    // 鍏堢敵璇峰崟鍙�
+                    DrawAuditOrder daOrder = new DrawAuditOrder
+                    {
+                        requestUserId = PdmUser.LoginUser.id,
+                        requestUser = PdmUser.LoginUser.realname
+                    };
+                    try
+                    {
+                        Result<DrawAuditOrder> res = Client.PostSyncAction<DrawAuditOrder>(daOrder, "drawAudit/order/create");
+                        daOrder = res.HandleResult();
+                    }
+                    catch (Exception ex)
+                    {
+                        Logger.Error($"璇锋眰瀹℃壒鍗曞彿澶辫触", ex);
+                        this.Error($"璇锋眰瀹℃壒鍗曞彿澶辫触! {ex.Message}");
+                        return;
+                    }
+
                     ConcurrentQueue<string> errs = new ConcurrentQueue<string>();
                     CountdownEvent counter = new CountdownEvent(boms.Count);
                     foreach (PdmBom bom in boms)
@@ -1243,6 +1267,7 @@
                                 MultipartFormDataContent httpContent = new MultipartFormDataContent();
                                 httpContent.Add(new StringContent(bom.partNo), "materialCode");
                                 httpContent.Add(new StringContent(bom.partNo), "materialModel");
+                                httpContent.Add(new StringContent(daOrder.id), "orderId");
                                 fileInfo = new FileInfo(d3FilePath);
                                 FileInfo file2Info = new FileInfo(d2FilePath);
                                 httpContent.Add(new ByteArrayContent(FileUtil.toByteArray(d3FilePath)), "d3File", fileInfo.Name);
@@ -1387,11 +1412,11 @@
                 if (bom.checkRuleResult == 3)
                 {
                     string title = string.Empty;
-                    if (bom.historyData)
+                    if (bom.IsHistoryData)
                     {
                         title = "鍘嗗彶鍥剧焊鏃犻渶妫�鏌�";
                     }
-                    else if (bom.inBom)
+                    else if (bom.ExcludeFromBOM)
                     {
                         title = "涓嶅湪鐗╂枡鏄庣粏琛ㄤ腑鐨勭墿鏂欐棤闇�妫�鏌�";
                     }
@@ -1432,6 +1457,16 @@
                     if (bom.produceWay == "妯$粍" || bom.produceWay == "鏍囧噯浠�")
                     {
                         this.Info($"{bom.produceWay}鏃犻渶瀹℃牳");
+                        return;
+                    }
+                    if (bom.IsHistoryData && !bom.localDocChanged)
+                    {
+                        this.Info("鍘嗗彶鍥剧焊鏃犻渶瀹℃牳");
+                        return;
+                    }
+                    if (bom.IsHistoryData && bom.localDocChanged)
+                    {
+                        this.Info("鍘嗗彶鍥剧焊涓�鑷存�у彉鏇达紝闇�瀹℃牳");
                         return;
                     }
                     this.Warning("璇ュ浘绾告湭瀹℃牳");
@@ -1593,31 +1628,8 @@
                         RefreshBomList(SwApp.IActiveDoc2);
                         DoCheckRule(out _);
                         // 绛涢�夋墍鏈夊湪鐗╂枡鏄庣粏琛ㄤ腑锛屼笉璺宠繃妫�鏌ュ苟涓旀鏌ユ湭閫氳繃鐨勶紝绫诲瀷鏄姞宸ヤ欢鐨勬湭閫氳繃瀹℃牳鐨勶紝鍔犲伐浠跺鏍搁�氳繃鐨勪絾鍥剧焊鍙樻洿鐨�
-                        List<string> errs = model.bomTreeReader.CacheList.Where(b =>
-                            !b.inBom
-                            && (
-                                (!b.skipCheck && !b.checkRuleOk)
-                                || (b.produceWay == "鍔犲伐浠�" && b.drawStatus != "completed")
-                                || (b.produceWay == "鍔犲伐浠�" && b.drawStatus == "completed" && b.auditedMd5Changed)
-                            )
-                        ).Select(b =>
-                        {
-                            string msg = $"銆恵b.partModel}銆�";
-                            if (!b.skipCheck && !b.checkRuleOk)
-                            {
-                                msg += "鏈�氳繃瑙勫垯妫�鏌�;";
-                            }
-                            if (b.produceWay == "鍔犲伐浠�" && b.drawStatus != "completed")
-                            {
-                                msg += "鏈�氳繃瀹℃牳;";
-                            }
-                            if (b.produceWay == "鍔犲伐浠�" && b.drawStatus == "completed" && b.auditedMd5Changed)
-                            {
-                                msg += "鍥剧焊鍙樻洿鍚庢湭閲嶆柊瀹℃牳";
-                            }
-                            return msg;
-                        }
-                        ).ToList();
+                        List<string> errs = model.bomTreeReader.CacheList.Select(b => b.NeedStopCheckIn())
+                        .Where(s => s != null).ToList();
 
                         if (errs != null && errs.Count > 0)
                         {

--
Gitblit v1.9.1