From 5c272c606bdf2da3577dbaa5f48d0ee163f1e7d2 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期四, 26 三月 2026 10:35:24 +0800
Subject: [PATCH] 纸张淋膜半成品入库逻辑优化

---
 项目代码/WCS/WCSServices/WIDESEAWCS_TaskInfoService/PackaxisTaskService.cs |  239 +++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 150 insertions(+), 89 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_TaskInfoService/PackaxisTaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_TaskInfoService/PackaxisTaskService.cs"
index 17065cd..ce74bab 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_TaskInfoService/PackaxisTaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_TaskInfoService/PackaxisTaskService.cs"
@@ -1,4 +1,5 @@
 锘縰sing Newtonsoft.Json;
+using SqlSugar;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -14,6 +15,7 @@
 using WIDESEAWCS_Core.BaseServices;
 using WIDESEAWCS_Core.Enums;
 using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_DTO.TaskInfo;
 using WIDESEAWCS_IBasicInfoRepository;
 using WIDESEAWCS_IPackInfoRepository;
 using WIDESEAWCS_ITaskInfoRepository;
@@ -39,106 +41,121 @@
             _stationMangerRepository = stationMangerRepository;
             _unitOfWorkManage = unitOfWorkManage;
         }
+        private static object lock_reqPackTask = new object();
+        /// <summary>
+        /// 鍒嗛厤鐮佸灈浠诲姟
+        /// </summary>
+        /// <param name="barCode"></param>
+        /// <param name="deviceCode"></param>
+        /// <returns></returns>
         public WebResponseContent ReqPackTask(string barCode,string deviceCode)
         {
-            WebResponseContent content= new WebResponseContent();
-            try
+            lock (lock_reqPackTask)
             {
-                Dt_Packinfo packinfo = _packinfoRepository.QueryFirst(x=>x.BarCode==barCode && x.PackStatus==StationOccupiedEnum.None.ObjToInt());
-                if (packinfo==null)
+                WebResponseContent content = new WebResponseContent();
+                try
                 {
-                    return content.Error($"鏈壘鍒版潯鐮亄barCode}");
-                }
-                List<Dt_StationPackInfo> stationPackInfos = _stationPackInfoRepository.QueryData();
-                Dt_StationPackInfo? stationPackInfo=stationPackInfos.FirstOrDefault(x=>x.PackType==packinfo.PackType && x.OrderNo==packinfo.OrderNo && x.AssignNum<x.PackNum);
-                //濡傛灉璁㈠崟鐩稿悓銆佸灈鍨嬩竴鑷村苟涓斿垎閰嶆暟閲忓皯浜庣爜鍨涚粨鎵樻暟閲忓垯鍒嗛厤鍒颁竴璧�
-                if (stationPackInfo!=null)
-                {
-                    Dt_PackaxisTask packaxisTask = new Dt_PackaxisTask()
+                    Dt_Packinfo packinfo = _packinfoRepository.QueryFirst(x => x.BarCode == barCode && x.PackStatus == StationOccupiedEnum.None.ObjToInt());
+                    if (packinfo == null)
                     {
-                        DeviceCode=deviceCode,
-                        SourceAddress= "2421",
-                        BarCode=barCode,
-                        CurrentAddress= "2421",
-                        TargetAddress=stationPackInfo.StationCode,
-                        NextAddress=stationPackInfo.LineCode,
-                        TaskState =TaskStatusEnum.Line_Executing.ObjToInt(),
-                        PackLength=packinfo.Length,
-                        PackWidth=packinfo.Width,
-                        PackHeight=packinfo.Height,
-                        PackType=packinfo.PackType,
-                        Dispatchertime=DateTime.Now,
-                    };
-                    stationPackInfo.AssignNum += 1;
-                    stationPackInfo.ExecutingNum += 1;
-                    packinfo.PackStatus = StationOccupiedEnum.Sure.ObjToInt();
+                        return content.Error($"鏈壘鍒版潯鐮亄barCode}");
+                    }
+                    List<Dt_StationPackInfo> stationPackInfos = _stationPackInfoRepository.Db.Queryable<Dt_StationPackInfo>().ToList();
+                    Dt_StationPackInfo? stationPackInfo = stationPackInfos.FirstOrDefault(x => x.PackType == packinfo.PackType && x.OrderNo == packinfo.OrderNo && x.AssignNum < x.PackNum);
+                    Dt_PackaxisTask packaxisTask = new Dt_PackaxisTask();
+                    //濡傛灉璁㈠崟鐩稿悓銆佸灈鍨嬩竴鑷村苟涓斿垎閰嶆暟閲忓皯浜庣爜鍨涚粨鎵樻暟閲忓垯鍒嗛厤鍒颁竴璧�
                     _unitOfWorkManage.BeginTran();
-                    //鏇存柊鐮佸灈鎵ц宸ヤ綅
-                    _stationPackInfoRepository.UpdateData(stationPackInfo);
-                    //鏇存柊寰呯爜鍨涗俊鎭〃
-                    _packinfoRepository.UpdateData(packinfo);
-                    //娣诲姞鐮佸灈浠诲姟
-                    BaseDal.AddData(packaxisTask);
+                    if (stationPackInfo != null)
+                    {
+                        packaxisTask = new Dt_PackaxisTask()
+                        {
+                            DeviceCode = deviceCode,
+                            SourceAddress = "2421",
+                            BarCode = barCode,
+                            CurrentAddress = "2421",
+                            TargetAddress = stationPackInfo.StationCode,
+                            NextAddress = stationPackInfo.LineCode,
+                            TaskState = TaskStatusEnum.Line_Executing.ObjToInt(),
+                            PackLength = packinfo.Length,
+                            PackWidth = packinfo.Width,
+                            PackHeight = packinfo.Height,
+                            PackType = packinfo.PackType,
+                            Dispatchertime = DateTime.Now,
+                        };
+                        stationPackInfo.AssignNum += 1;
+                        stationPackInfo.ExecutingNum += 1;
+                        packinfo.PackStatus = StationOccupiedEnum.Sure.ObjToInt();
+                        
+                        //鏇存柊鐮佸灈鎵ц宸ヤ綅
+                        _stationPackInfoRepository.UpdateData(stationPackInfo);
+                        //鏇存柊寰呯爜鍨涗俊鎭〃
+                        _packinfoRepository.UpdateData(packinfo);
+                        //娣诲姞鐮佸灈浠诲姟
+                        BaseDal.AddData(packaxisTask);
+                        
+                    }
+                    else//鍒嗛厤鏂板伐浣�
+                    {
+                        //鑾峰彇褰撳墠绌虹洏鍑嗗鐨勭爜鍨涘伐浣�
+                        List<string> stations = _stationMangerRepository.QueryData(x => x.StationDeviceCode == "CLC_CP" && x.IsOccupied == StationOccupiedEnum.None.ObjToInt()).Select(x => x.StationCode).ToList();
+                        //鑾峰彇鐮佸灈閰嶇疆琛ㄦ煡璇㈠彲鍒嗛厤骞跺凡閰嶇疆鐨勭爜鍨涘伐浣�
+                        List<Dt_Packaxis> packaxes = _packaxisRepository.Db.Queryable<Dt_Packaxis>().Where(x => x.PackType == packinfo.PackType && stations.Contains(x.StationCode)).ToList();
+                        if (packaxes.Count == 0)
+                        {
+                            return content.Error("鏈壘鍒板彲鍒嗛厤鐮佸灈閰嶇疆");
+                        }
+                        List<string> packStations = packaxes.Select(x => x.StationCode).ToList();
+                        Dt_StationPackInfo? packInfoAssign = stationPackInfos.Where(x => x.PackType == 0 && x.AssignNum == 0 && packStations.Contains(x.StationCode)).OrderBy(x => x.OrderIndex).FirstOrDefault();
+                        if (packInfoAssign == null)
+                        {
+                            return content.Error("鏈壘鍒板彲鍒嗛厤鍨涗綅");
+                        }
+                        packInfoAssign.PackType = packinfo.PackType;
+                        packInfoAssign.OrderNo = packinfo.OrderNo;
+                        packInfoAssign.MakeCode = packinfo.MakeCode;
+                        packInfoAssign.MaterielCode = packInfoAssign.MaterielCode;
+                        packInfoAssign.PackNum = packaxes.FirstOrDefault(x => x.StationCode == packInfoAssign.StationCode).PackNum;
+                        packaxisTask = new Dt_PackaxisTask()
+                        {
+                            DeviceCode = deviceCode,
+                            SourceAddress = "2421",
+                            BarCode = barCode,
+                            CurrentAddress = "2421",
+                            TargetAddress = packInfoAssign.StationCode,
+                            NextAddress = packInfoAssign.LineCode,
+                            TaskState = TaskStatusEnum.Line_Executing.ObjToInt(),
+                            PackLength = packinfo.Length,
+                            PackWidth = packinfo.Width,
+                            PackHeight = packinfo.Height,
+                            PackType = packinfo.PackType,
+                            Dispatchertime = DateTime.Now,
+                        };
+                        packInfoAssign.AssignNum += 1;
+                        packInfoAssign.ExecutingNum += 1;
+                        packinfo.PackStatus = StationOccupiedEnum.Sure.ObjToInt();
+                        //鏇存柊鐮佸灈鎵ц宸ヤ綅
+                        _stationPackInfoRepository.UpdateData(packInfoAssign);
+                        //鏇存柊寰呯爜鍨涗俊鎭〃
+                        _packinfoRepository.UpdateData(packinfo);
+                        //娣诲姞鐮佸灈浠诲姟
+                        BaseDal.AddData(packaxisTask);
+                    }
                     _unitOfWorkManage.CommitTran();
                     return content.OK(barCode, packaxisTask);
                 }
-                else//鍒嗛厤鏂板伐浣�
+                catch (Exception ex)
                 {
-                    //鑾峰彇褰撳墠绌虹洏鍑嗗鐨勭爜鍨涘伐浣�
-                    List<string> stations = _stationMangerRepository.QueryData(x => x.StationDeviceCode == "CLC_CP" && x.IsOccupied == StationOccupiedEnum.None.ObjToInt()).Select(x => x.StationCode).ToList();
-                    //鑾峰彇鐮佸灈閰嶇疆琛ㄦ煡璇㈡湁閰嶇疆鐨勭爜鍨涘伐浣�
-                    List<Dt_Packaxis> packaxes = _packaxisRepository.QueryData(x => x.PackType == packinfo.PackType);
-                    if (packaxes.Count==0)
-                    {
-                        return content.Error("鏈壘鍒扮爜鍨涘潗鏍囬厤缃�");
-                    }
-                    List<string> packStations = packaxes.Select(x => x.StationCode).ToList();
-                    Dt_StationPackInfo? packInfoAssign = stationPackInfos.Where(x => x.PackType == 0 && x.AssignNum == 0 && stations.Contains(x.StationCode) && packStations.Contains(x.StationCode)).OrderByDescending(x => x.StationCode).FirstOrDefault();
-                    if (packInfoAssign == null)
-                    {
-                        return content.Error("鏈壘鍒板彲鍒嗛厤鍨涗綅");
-                    }
-                    packInfoAssign.PackType = packinfo.PackType;
-                    packInfoAssign.OrderNo = packinfo.OrderNo;
-                    packInfoAssign.MakeCode = packinfo.MakeCode;
-                    packInfoAssign.MaterielCode = packInfoAssign.MaterielCode;
-                    packInfoAssign.PackNum = packaxes.FirstOrDefault(x=>x.StationCode== packInfoAssign.StationCode).PackNum;
-                    Dt_PackaxisTask packaxisTask = new Dt_PackaxisTask()
-                    {
-                        DeviceCode = deviceCode,
-                        SourceAddress = "2421",
-                        BarCode = barCode,
-                        CurrentAddress = "2421",
-                        TargetAddress = packInfoAssign.StationCode,
-                        NextAddress = packInfoAssign.LineCode,
-                        TaskState = TaskStatusEnum.Line_Executing.ObjToInt(),
-                        PackLength = packinfo.Length,
-                        PackWidth = packinfo.Width,
-                        PackHeight = packinfo.Height,
-                        PackType = packinfo.PackType,
-                        Dispatchertime = DateTime.Now,
-                    };
-                    packInfoAssign.AssignNum += 1;
-                    packInfoAssign.ExecutingNum += 1;
-                    packinfo.PackStatus = StationOccupiedEnum.Sure.ObjToInt();
-                    _unitOfWorkManage.BeginTran();
-                    //鏇存柊鐮佸灈鎵ц宸ヤ綅
-                    _stationPackInfoRepository.UpdateData(packInfoAssign);
-                    //鏇存柊寰呯爜鍨涗俊鎭〃
-                    _packinfoRepository.UpdateData(packinfo);
-                    //娣诲姞鐮佸灈浠诲姟
-                    BaseDal.AddData(packaxisTask);
-                    _unitOfWorkManage.CommitTran();
-                    return content.OK(barCode, packaxisTask);
+                    _unitOfWorkManage.RollbackTran();
+                    content.Error(ex.Message);
                 }
+                return content;
             }
-            catch (Exception ex)
-            {
-                _unitOfWorkManage.RollbackTran();
-                content.Error(ex.Message);
-            }
-            return content;
         }
+        /// <summary>
+        /// 鐮佸灈缁撴墭骞朵笂浼犵爜鍨涘伐浣嶇爜鍨涙槑缁嗘暟鎹�
+        /// </summary>
+        /// <param name="stationCode"></param>
+        /// <returns></returns>
         public WebResponseContent BoxingInBound(string stationCode)
         {
             WebResponseContent content = new WebResponseContent();
@@ -186,11 +203,17 @@
             }
             return content;
         }
+        /// <summary>
+        /// 鐮佸灈浠诲姟瀹屾垚
+        /// </summary>
+        /// <param name="taskNum"></param>
+        /// <param name="packaxisTask"></param>
+        /// <returns></returns>
         public WebResponseContent TaskCompleted(int taskNum=0,Dt_PackaxisTask? packaxisTask=null)
         {
             try
             {
-                _unitOfWorkManage.BeginTran();
+                
                 Dt_PackaxisTask? packaxisTaskFinish = null;
                 if (packaxisTask!=null)
                 {
@@ -211,15 +234,16 @@
                         StationPackId = stationPackInfo.id,
                         BoxCode = packaxisTaskFinish.BarCode
                     };
+                    _unitOfWorkManage.BeginTran();
                     _stationPackInfoRepository.UpdateData(stationPackInfo);
                     _stationPackDetailRepository.AddData(stationPackDetail);
                     BaseDal.DeleteAndMoveIntoHty(packaxisTaskFinish, App.User?.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
+                    _unitOfWorkManage.CommitTran();
                 }
                 else
                 {
                     return WebResponseContent.Instance.Error("鏈壘鍒颁换鍔�");
                 }
-                _unitOfWorkManage.CommitTran();
                 return WebResponseContent.Instance.OK();
             }
             catch (Exception ex)
@@ -228,5 +252,42 @@
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
+        /// <summary>
+        /// 鍒犻櫎鐮佸灈浠诲姟淇℃伅
+        /// </summary>
+        /// <param name="packTaskNum"></param>
+        /// <returns></returns>
+        /// <exception cref="NotImplementedException"></exception>
+        public WebResponseContent PickaixsTaskDele(int PackTaskNum)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                    Dt_PackaxisTask packaxisTask = BaseDal.QueryFirst(x => x.PackTaskNum == PackTaskNum);
+                    if(packaxisTask == null)
+                    {
+                        return WebResponseContent.Instance.Error("鏈壘鍒颁换鍔�");
+                    }
+                    else 
+                    {
+                        Dt_Packinfo packinfo = _packinfoRepository.QueryFirst(x => x.BarCode == packaxisTask.BarCode);
+                        packinfo.PackStatus = 0;
+                        _packinfoRepository.UpdateData(packinfo);
+                        BaseDal.DeleteAndMoveIntoHty(packaxisTask, App.User?.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐鍒犻櫎);
+                      content.Status = true;
+                    }
+            }
+            catch (Exception e)
+            {
+                return WebResponseContent.Instance.Error(e.Message);
+            }
+            return content;
+        }
+    }
+    public class MDCount
+    {
+        public string MDNo { get; set; }
+
+        public int Count { get; set; }
     }
 }

--
Gitblit v1.9.3