From 1e1047443c6fa2dd2c30d2147166fc9076917936 Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周一, 23 12月 2024 18:43:50 +0800
Subject: [PATCH] 222

---
 CC/iWareCC_ASRS/ThreadService/04_BZ21(搬运整垛机器人)/1、DataProcess_BZ21.cs |  159 ++++++++++++++++++++++++++++++-----------------------
 1 files changed, 90 insertions(+), 69 deletions(-)

diff --git "a/CC/iWareCC_ASRS/ThreadService/04_BZ21\357\274\210\346\220\254\350\277\220\346\225\264\345\236\233\346\234\272\345\231\250\344\272\272\357\274\211/1\343\200\201DataProcess_BZ21.cs" "b/CC/iWareCC_ASRS/ThreadService/04_BZ21\357\274\210\346\220\254\350\277\220\346\225\264\345\236\233\346\234\272\345\231\250\344\272\272\357\274\211/1\343\200\201DataProcess_BZ21.cs"
index 676369f..913f264 100644
--- "a/CC/iWareCC_ASRS/ThreadService/04_BZ21\357\274\210\346\220\254\350\277\220\346\225\264\345\236\233\346\234\272\345\231\250\344\272\272\357\274\211/1\343\200\201DataProcess_BZ21.cs"
+++ "b/CC/iWareCC_ASRS/ThreadService/04_BZ21\357\274\210\346\220\254\350\277\220\346\225\264\345\236\233\346\234\272\345\231\250\344\272\272\357\274\211/1\343\200\201DataProcess_BZ21.cs"
@@ -10,6 +10,7 @@
 using iWareSql.WmsDBModel;
 using Newtonsoft.Json.Linq;
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Diagnostics.Contracts;
@@ -22,14 +23,14 @@
 {
     public class DataProcess_BZ21
     {
-        public static void Hander()
+        public static async void Hander()
         {
             var alertMsg = "";
             LogType logType = LogType.DataProcess_BZ21;
             while (true)
             {
                 Thread.Sleep(2000);//浼戠湢2绉掞紝灏嗕紤鐪犲啓鍒板墠闈紝鏄负浜嗕笅闈㈢殑continue鏂规硶鎵ц鍚庝笉鏄剧ず閿欒淇℃伅鐨勬彁绀猴紒锛侊紒銆怑ditBy shaocx,2022-05-24銆�
-                SystemWarningMsg._lbl_alert_DataProcess_BZ21 = string.Empty;
+                
                 try
                 {
                     if (SystemValue.isStartedModel)
@@ -88,7 +89,7 @@
 
                                 //澧炲姞鏍¢獙锛屽鏋滀笂涓�涓换鍔pi璺熸湰娆pi涓�鑷达紝灏辨姤閿� 銆怑ditby shaocx,2024-12-03銆�
                                 var lastTask = wmsDB.wms_rbline_task.Where(x => x.RbTaskType == (int)RbTaskTypeEnum.鍚堝寘浠诲姟).OrderByDescending(x => x.Id).FirstOrDefault();
-                                if (lastTask != null && lastTask.UPI == result)
+                                if (lastTask != null && lastTask.Upi == result)
                                 {
                                     SystemWarningMsg._lbl_alert_DataProcess_BZ21 = $"{rgvLocation.ToString()}-PLC閲嶅彂姝や换鍔★紝upi锛歿result}锛岀郴缁熶笉鑳介噸澶嶅鐞�,姝ゆ寰幆缁撴潫";
                                     continue;
@@ -97,67 +98,103 @@
                                 var upiObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == result).FirstOrDefault();
                                 if (upiObj == null)
                                 {
+                                    //鍐欏叆鎶ヨ淇℃伅
+                                    await MyExtendHelper.WriteBoolPlcDataForWarning(PlcWarningAddressGloble.Num_BZ21_1);
+
                                     SystemWarningMsg._lbl_alert_DataProcess_BZ21 = $"{rgvLocation.ToString()},鏍规嵁UPI:{result}娌℃湁鎵惧埌瀵硅薄 ";
                                     continue;
                                 }
 
+                                var package = wmsDB.mes_package_gather.Where(x => x.PackageCode == upiObj.PackageCode).FirstOrDefault();
+                                if (package == null)
+                                {
+                                    SystemWarningMsg._lbl_alert_DataProcess_BZ21 = $"{rgvLocation.ToString()},鏍规嵁鍖呭彿:{upiObj.PackageCode}娌℃湁鎵惧埌瀵硅薄 ";
+                                    continue;
+                                }
+
+                                //楠岃瘉鏄惁鍏佽鍒囩焊
                                 var validteReslt = ValidateIsAllowCut();
                                 if (validteReslt == false)
                                 {
+                                    //鍐欏叆鎶ヨ淇℃伅
+                                    await MyExtendHelper.WriteBoolPlcDataForWarning(PlcWarningAddressGloble.Num_BZ21_2);
+
                                     continue;
                                 }
 
                                 //string upi = "LS070700101B0001GS";
                                 //璋冪敤鍑虹焊鏈烘帴鍙�
-                                var papercut = ClassHelper.RotationMapping<mes_push_papercut, mes_batchOrderUPI_new>(upiObj);
+                                var papercut = ClassHelper.RotationMapping<mes_push_papercut, mes_package_gather>(package);
                                 papercut.Id = Yitter.IdGenerator.YitIdHelper.NextId();
                                 papercut.ApiMessage = "";
                                 papercut.PushNum = 0;
                                 papercut.PushStatus = (int)PushStatusEnum.NotPush;
+                                papercut.CreateUserName = papercut.UpdateUserName = SysGloble.WCSSystem;
                                 papercut.CreateTime = papercut.UpdateTime = DateTime.Now;
                                 wmsDB.mes_push_papercut.Add(papercut);
+
+
+                                AreaCodeEnum setAreaCode = AreaCodeEnum.鍚堝寘瑁佸垏鍖�;
+                                UpiStatusEnum setUpiStatus = UpiStatusEnum.宸插悎鍖�;
+
+                                var ngFlag = false;
+                                var queryFlag = (int)UpiFlagEnum.NG;
+                                var upilist = wmsDB.mes_batchOrderUPI_new.Where(x => x.PackageCode == upiObj.PackageCode).ToList();
+                                var ngCount = upilist.Count(x => x.UpiFlag == queryFlag);
+                                if (ngCount > 0)
+                                {
+                                    ngFlag = true;
+                                    setUpiStatus = UpiStatusEnum.宸蹭笅绾�;
+                                    setAreaCode = AreaCodeEnum.涓嬬嚎鍖哄煙;
+                                }
+                                else
+                                {//涓嶆槸NG
+                                 //鏂板mes鎺ㄩ�佽〃
+                                    var putpakegecodeid = Yitter.IdGenerator.YitIdHelper.NextId();
+                                    var putpakegecode = new mes_push_packagecode()
+                                    {
+                                        Id = putpakegecodeid,
+                                        PackageCode = upiObj.PackageCode,
+                                        PushStatus = 0,
+                                        PushNum = 0,
+                                        ApiMessage = "",
+                                        CreateTime = DateTime.Now,
+                                        CreateUserName = SysGloble.WCSSystem,
+                                        UpdateTime = DateTime.Now,
+                                        UpdateUserName = SysGloble.WCSSystem
+
+                                    };
+                                    wmsDB.mes_push_packagecode.Add(putpakegecode);
+
+                                    //鏂板琛�
+                                    var mesinequeue = ClassHelper.RotationMapping<mes_package_linequeue, mes_package_gather>(package);
+                                    mesinequeue.Id = Yitter.IdGenerator.YitIdHelper.NextId();
+                                    mesinequeue.CreateTime = mesinequeue.UpdateTime = DateTime.Now;
+                                    wmsDB.mes_package_linequeue.Add(mesinequeue);
+                                }
 
                                 //鏇存柊琛�
                                 var mesgather = wmsDB.mes_package_gather.Where(x => x.PackageCode == upiObj.PackageCode).FirstOrDefault();
                                 if (mesgather != null)
                                 {
-                                    mesgather.AreaCode = (int)AreaCodeEnum.鍚堝寘瑁佸垏鍖�;
-                                    mesgather.UpiStatus = (int)UpiStatusEnum.宸插悎鍖�;
+                                    mesgather.AreaCode = (int)setAreaCode;
+                                    mesgather.UpiStatus = (int)setUpiStatus;
                                 }
-                                //var upilist = wmsDB.mes_batchOrderUPI_new.Where(x => x.PackageCode == upiObj.PackageCode).ToList();
-                                //var upilength = upilist.Max(x => x.Length);
-                                //var upiwidth = upilist.Max(x => x.Width);
-                                //cartonhigh = (short)upiObj.Info3;
-                                //cartonwidth = (short)upiObj.Info2;
-                                upiObj.UpiStatus = (int)UpiStatusEnum.宸插悎鍖�;
-                                upiObj.AreaCode = (int)AreaCodeEnum.鍚堝寘瑁佸垏鍖�;
+
+                                upiObj.UpiStatus = (int)setUpiStatus;
+                                upiObj.AreaCode = (int)setAreaCode;
                                 //璁板綍浠诲姟
                                 var _id = Yitter.IdGenerator.YitIdHelper.NextId();
-                                var putpakegecodeid = Yitter.IdGenerator.YitIdHelper.NextId();
-                                var plcTaskNo = BusinessHelper.CreatePlcTaskIdForSrmTask();
-                                //鏂板琛�
-                                var mesinequeue = ClassHelper.RotationMapping<mes_package_linequeue, mes_batchOrderUPI_new>(upiObj);
-                                mesinequeue.Id = Yitter.IdGenerator.YitIdHelper.NextId();
-                                //鏂板mes鎺ㄩ�佽〃
-                                var putpakegecode = new mes_push_packagecode()
-                                {
-                                    Id = putpakegecodeid,
-                                    PackageCode = upiObj.PackageCode,
-                                    PushStatus = 0,
-                                    PushNum = 0,
-                                    ApiMessage = "",
-                                    CreateTime = DateTime.Now,
-                                    CreateUserName = "CC",
-                                    UpdateTime = DateTime.Now,
-                                    UpdateUserName = "CC",
 
-                                };
+                                var plcTaskNo = BusinessHelper.CreatePlcTaskId();
+                                plcTaskNo = MyExtendHelper.GetNewTaskNo(wmsDB, RbTaskTypeEnum.鍚堝寘浠诲姟, plcTaskNo);
+
                                 //鏂板浠诲姟琛�
                                 var task = new wms_rbline_task()
                                 {
                                     Id = _id,
                                     TaskNo = plcTaskNo,
-                                    UPI = upiObj.UPI,
+                                    Upi = upiObj.UPI,
                                     Length = upiObj.Length,
                                     Width = upiObj.Width,
                                     Thk = upiObj.Thk,
@@ -166,19 +203,17 @@
                                     OrderId = upiObj.OrderId,
                                     PackageCode = upiObj.PackageCode,
                                     RbTaskType = (int)RbTaskTypeEnum.鍚堝寘浠诲姟,
-                                    RbTaskTypeEnumName = RbTaskTypeEnum.鍚堝寘浠诲姟.ToString(),
                                     TaskStatus = (int)TaskStatusEnum.鏂板缓,
-                                    TaskStatusName = TaskStatusEnum.鏂板缓.ToString(),
                                     TaskMsg = "澶规澘",
                                     CreateTime = DateTime.Now,
-                                    CreateUserName = "CC",
+                                    CreateUserName = SysGloble.WCSSystem,
                                     UpdateTime = DateTime.Now,
-                                    UpdateUserName = "CC",
+                                    UpdateUserName = SysGloble.WCSSystem,
                                     PlaceCode = place
                                 };
                                 //鏂板鎵撳嵃琛�
                                 var printid = Yitter.IdGenerator.YitIdHelper.NextId();
-                                var print = ClassHelper.RotationMapping<wms_record_print, mes_batchOrderUPI_new>(upiObj);
+                                var print = ClassHelper.RotationMapping<wms_record_print, mes_package_gather>(package);
                                 print.Id = printid;
                                 print.PrintType = (int)PrintTypeEnum.鍖呰鏉$爜;
                                 print.PrintSource = (int)PrintSourceEnum.鍖呰鏉$爜鎵撳嵃;
@@ -188,24 +223,24 @@
                                 print.IsAllowPrint = true;
                                 print.CreateTime = print.UpdateTime = DateTime.Now;
                                 wmsDB.wms_record_print.Add(print);
-                                var printtwo = ClassHelper.RotationMapping<wms_record_print, mes_batchOrderUPI_new>(upiObj);
-                                printtwo.PrintType = (int)PrintTypeEnum.鍖呰鏉$爜;
-                                printtwo.PrintSource = (int)PrintSourceEnum.鍖呰鏉$爜鎵撳嵃;
-                                printtwo.PrintSheetNum = 1;
-                                printtwo.PrintNum = 0;
-                                printtwo.PrintStatus = (int)PrintStatuEnum.鏈墦鍗�;
-                                printtwo.IsAllowPrint = true;
-                                printtwo.CreateTime = print.UpdateTime = DateTime.Now;
-                                printtwo.Id = Yitter.IdGenerator.YitIdHelper.NextId();
-                                wmsDB.wms_record_print.Add(printtwo);
+                                //var printtwo = ClassHelper.RotationMapping<wms_record_print, mes_batchOrderUPI_new>(upiObj);
+                                //printtwo.PrintType = (int)PrintTypeEnum.鍖呰鏉$爜;
+                                //printtwo.PrintSource = (int)PrintSourceEnum.鍖呰鏉$爜鎵撳嵃;
+                                //printtwo.PrintSheetNum = 1;
+                                //printtwo.PrintNum = 0;
+                                //printtwo.PrintStatus = (int)PrintStatuEnum.鏈墦鍗�;
+                                //printtwo.IsAllowPrint = true;
+                                //printtwo.CreateTime = print.UpdateTime = DateTime.Now;
+                                //printtwo.Id = Yitter.IdGenerator.YitIdHelper.NextId();
+                                //wmsDB.wms_record_print.Add(printtwo);
 
-                                wmsDB.mes_package_linequeue.Add(mesinequeue);
+
                                 wmsDB.wms_rbline_task.Add(task);
-                                wmsDB.mes_push_packagecode.Add(putpakegecode);
+
 
                                 //澶勭悊琛�  mes_order_gather
                                 var errmsg = "";
-                                var package = wmsDB.mes_package_gather.Where(x => x.PackageCode == upiObj.PackageCode).FirstOrDefault();
+
                                 var resultAlert = MyExtendHelper.HandlerOrderGather(wmsDB, package, "", "", out errmsg);
                                 if (resultAlert == false)
                                 {
@@ -213,31 +248,17 @@
                                     continue;
                                 }
 
-                                /*
-                                using (StationServiceClient client = new StationServiceClient())
-                                {
-
-                                    var plcres = client.WriteSurroundTaskInfo((int)EDevice.Station, rgvLocation, short.Parse(task.TaskNo),
-                                          (short)upilength, (short)upiwidth, cartonhigh, cartonwidth, 0, 0);
-                                    if (!plcres.result)
-                                    {
-                                        SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()}-涓嬪彂鍏ュ簱浠诲姟 澶辫触,WriteInStoreTaskInfoAsync 杩斿洖:{plcres.resMsg}";
-                                        continue;
-                                    }
-                                    else
-                                    {
-                                        Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-涓嬪彂鍏ュ簱浠诲姟 鎴愬姛,WriteInStoreTaskInfoAsync锛屽弬鏁�: 绔欑偣{rgvLocation}");
-                                    }
-                                }
-                                //*/
-
 
                                 WmsRecordUpiProcessHandler.SaveWmsRecordUpiProcess(wmsDB, upiObj, "BZ21", "鍚堝寘");
-                                WmsRecordUpiProcessHandler.SaveWmsRecordPackageProcess(wmsDB, upiObj, "BZ21", "鍚堝寘");
+                                WmsRecordUpiProcessHandler.SaveWmsRecordPackageProcess(wmsDB, package, "BZ21", "鍚堝寘");
 
                                 wmsDB.SaveChanges();
                             }
                         }
+                        else
+                        {
+                            SystemWarningMsg._lbl_Alert_DataProcess_BZ21 = $"{rgvLocation.ToString()}-娌℃湁瑕佸鐞嗙殑鏁版嵁";
+                        }
                     }
                 }
                 catch (Exception ex)

--
Gitblit v1.9.3