From 37184b1d1ac000a6ee40e397e2336b213e705902 Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周四, 17 4月 2025 13:08:45 +0800
Subject: [PATCH] 包中只有一块板时,认定为 不齐包 【Editby shaocx,2025-04-01】

---
 CC/iWareCC_ASRS/Common/Helper/MyExtendHelper.cs |  172 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 168 insertions(+), 4 deletions(-)

diff --git a/CC/iWareCC_ASRS/Common/Helper/MyExtendHelper.cs b/CC/iWareCC_ASRS/Common/Helper/MyExtendHelper.cs
index a1b91dc..1461da0 100644
--- a/CC/iWareCC_ASRS/Common/Helper/MyExtendHelper.cs
+++ b/CC/iWareCC_ASRS/Common/Helper/MyExtendHelper.cs
@@ -1,4 +1,6 @@
 锘縰sing Admin.NET.Application;
+using iWareCC.SrmService;
+using iWareCC.StationService;
 using iWareCommon.Common.Globle;
 using iWareCommon.Utils;
 using iWareModel;
@@ -9,11 +11,12 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Reflection.Emit;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
 using XiGang.Core.Model;
-
+using LogType = iWareCommon.Utils.LogType;
 
 namespace iWareCC.Common.Helper
 {
@@ -22,6 +25,147 @@
     /// </summary>
     public class MyExtendHelper
     {
+        /// <summary>
+        /// 楠岃瘉鏌愪釜鍖� 鏄惁鍙湁涓�涓猆PI
+        /// </summary>
+        /// <param name="wmsDB"></param>
+        /// <param name="upi"></param>
+        /// <returns>true:鍙湁涓�涓� </returns>
+        public static bool IsOnlyOneInPackage(WmsDBModel wmsDB, string upi)
+        {
+            var upiObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == upi).FirstOrDefault();
+            if (upiObj != null)
+            {
+                var num = wmsDB.mes_batchOrderUPI_new.Where(x => x.PackageCode == upiObj.PackageCode).Count();
+                if (num == 1)
+                {
+                    return true;
+                }
+            }
+            return false;
+        }
+
+      
+        /// <summary>
+        /// 鍏叡鐨勬帶鍒惰姹傚璞″瓧鍏�
+        /// </summary>
+        public static IDictionary<string, ControlRequest> controlRequestDicts = new Dictionary<string, ControlRequest>();
+
+        /// <summary>
+        /// 鍏叡鐨勬帶鍒惰姹傚璞″瓧鍏歌祴鍊�
+        /// </summary>
+        /// <param name="placeNo"></param>
+        /// <param name="result"></param>
+        /// <param name="msg"></param>
+        public static void SetValueControlRequestDicts(string placeNo, bool result, string msg)
+        {
+            if (controlRequestDicts.ContainsKey(placeNo))
+            {
+                controlRequestDicts[placeNo].IsSuccess = result;
+                controlRequestDicts[placeNo].LastTime = DateTime.Now;
+                controlRequestDicts[placeNo].PlaceNo = placeNo;
+                if (result)
+                {
+                    controlRequestDicts[placeNo].Count = 0;
+                    controlRequestDicts[placeNo].ErrMsg = "";
+                }
+                else
+                {
+                    controlRequestDicts[placeNo].Count++;
+                    controlRequestDicts[placeNo].ErrMsg = msg;
+                }
+            }
+            else
+            {
+                if (result)
+                {
+                    controlRequestDicts.Add(placeNo, new ControlRequest()
+                    {
+                        PlaceNo = placeNo,
+                        Count = 0,
+                        LastTime = DateTime.Now,
+                        ErrMsg = msg,
+                        IsSuccess = result
+                    });
+                }
+                else
+                {
+                    controlRequestDicts.Add(placeNo, new ControlRequest()
+                    {
+                        PlaceNo = placeNo,
+                        Count = 1,
+                        LastTime = DateTime.Now,
+                        ErrMsg = msg,
+                        IsSuccess = result
+                    });
+                }
+            }
+        }
+
+        /// <summary>
+        /// 楠岃瘉鏄惁鍏佽缁橮LC鍙戞姤璀�
+        /// </summary>
+        /// <param name="placeNo"></param>
+        /// <returns></returns>
+        public static bool ValidateIsAllowRequest(string placeNo, LogType logType)
+        {
+            if (controlRequestDicts.ContainsKey(placeNo))
+            {
+                if (controlRequestDicts[placeNo].IsSuccess == false)
+                {
+                    //var diff = DateTime.Now - controlRequestDicts[placeNo].LastTime;
+                    //if (diff.Seconds <= 10)
+                    //{//濡傛灉杩炵画璇锋眰鍦�10绉掑唴锛屽垯璁や负 涓嶉渶瑕佸啀娆¤姹�
+                    //    WZ.Useful.Commons.LogTextHelper.WriteLine("CommonControl", "ValidateIsAllowRequest", "濡傛灉杩炵画璇锋眰鍦�10绉掑唴锛屽垯璁や负 涓嶉渶瑕佸啀娆¤姹傦紝闂撮殧" + diff.Seconds + "绉�,placeNo:" + placeNo);
+                    //    return false;
+                    //}
+                    if (controlRequestDicts[placeNo].Count <= 5)
+                    {//濡傛灉杩炵画璇锋眰鍦�5娆″唴锛屽垯璁や负 涓嶉渶瑕佸啀娆¤姹�
+                        var msg = "濡傛灉杩炵画璇锋眰鍦�5娆″唴锛屽垯璁や负 涓嶉渶瑕佸啀娆¤姹傦紝闂撮殧" + controlRequestDicts[placeNo].Count + "涓�,placeNo:" + placeNo;
+                        Log4NetHelper.WriteInfoLog(logType, msg);
+                        return false;
+                    }
+                }
+            }
+            return true;
+        }
+
+        /// <summary>
+        /// 鐢熸垚鏈�鏂扮殑浠诲姟鍙�
+        /// </summary>
+        /// <param name="wmsDB"></param>
+        /// <param name="rbTaskTypeEnum"></param>
+        /// <param name="plcTaskNo"></param>
+        /// <returns></returns>
+        public static string GetNewTaskNo(WmsDBModel wmsDB, RbTaskTypeEnum rbTaskTypeEnum, string plcTaskNo)
+        {
+            //鍒ゆ柇濡傛灉浠诲姟鍙疯窡涓婁竴涓换鍔″彿閲嶅锛屽氨鑷姩鍑忓幓1
+            var lastTask = wmsDB.wms_rbline_task.Where(x => x.RbTaskType == (int)rbTaskTypeEnum).OrderByDescending(x => x.Id).FirstOrDefault();
+            if (lastTask != null && lastTask.TaskNo == plcTaskNo)
+            {
+                plcTaskNo = (Convert.ToInt32(plcTaskNo) - 1).ToString();
+            }
+            else
+            {
+
+            }
+            return plcTaskNo;
+        }
+
+        /// <summary>
+        /// 鍐欏叆 鎶ヨ淇℃伅
+        /// </summary>
+        /// <param name="warningAddress"></param>
+        /// <returns></returns>
+        public static async Task<iWareCC.StationService.SdaResEntity> WriteBoolPlcDataForWarning(string warningAddress)
+        {
+            using (StationServiceClient client = new StationServiceClient())
+            {
+
+                var res = await client.WriteBoolPlcDataAsync((int)EDevice.Station, "3000|" + warningAddress, true);
+                return res;
+            }
+        }
 
         /// <summary>
         /// 澶勭悊 琛� mes_order_gather
@@ -36,7 +180,8 @@
         {
             errMsg = "";
             //澶勭悊琛�  mes_order_gather
-            if (package == null) {
+            if (package == null)
+            {
                 return true;
             }
             var isAddOrder = false;
@@ -59,18 +204,35 @@
                     Info5 = package.Info5,
                     OrderId = package.OrderId,
                     PlanNo = package.PlanNo,
+
+                    CreateTime = DateTime.Now,
+                    UpdateTime = DateTime.Now,
+                    CreateUserName = SysGloble.WCSSystem,
+                    UpdateUserName = SysGloble.WCSSystem
                 };
                 isAddOrder = true;
             }
             order.PackageNum = packageList.Count();
             order.UnLinePackageNum = packageList.Where(x => x.UpiStatus == (int)UpiStatusEnum.宸蹭笅绾�).Count();
+            if (order.UnLinePackageNum > order.PackageNum)
+            {
+                order.UnLinePackageNum = order.PackageNum;
+            }
+
+            order.NgPackageNum = packageList.Where(x => x.UpiStatus == (int)UpiStatusEnum.宸蹭笅绾� && x.UpiFlag == (int)UpiFlagEnum.NG).Count();
+            if (order.NgPackageNum > order.PackageNum)
+            {
+                order.NgPackageNum = order.PackageNum;
+            }
+
             order.NoUnLinePackageNum = order.PackageNum - order.UnLinePackageNum;
 
             order.AllPackageArea = packageList.Sum(x => Convert.ToDecimal(x.Info13));
-            order.ScanPackageArea = packageList.Where(x => x.UpiStatus == (int)UpiStatusEnum.宸蹭笅绾�).Sum(x => Convert.ToDecimal(x.Info13));
+            order.ScanPackageArea = packageList.Where(x => x.UpiStatus == (int)UpiStatusEnum.宸蹭笅绾� && x.UpiFlag == (int)UpiFlagEnum.姝e父).Sum(x => Convert.ToDecimal(x.Info13));
             order.NoScanPackageArea = order.AllPackageArea - order.ScanPackageArea;
-            order.IsKitting = qitaoValue == "榻愬" ? true : false;
 
+
+            /*
             var order_unLine = false;
             //鏌ヨ涓嬩竴涓寘鏄笉鏄睘浜庤璁㈠崟
             var newLineQueue = wmsDB.mes_package_linequeue.OrderBy(x => x.Id).FirstOrDefault();
@@ -99,6 +261,8 @@
                 order.IsUnline = false;
             }
 
+            //*/
+
             if (isAddOrder)
             {
                 wmsDB.mes_order_gather.Add(order);

--
Gitblit v1.9.3