From 65a231315d1dcc35d2996106d36e9cca9aba6ce6 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期五, 06 三月 2026 09:06:44 +0800
Subject: [PATCH] 更新码垛分配工位优化,老厂退库称重上报设定差异范围

---
 项目代码/WCS/WCSServices/WIDESEAWCS_TaskInfoService/PackaxisTaskService.cs |  187 ++++++++++++++++++++++++----------------------
 1 files changed, 99 insertions(+), 88 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 a680a09..d343c54 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;
@@ -39,6 +40,7 @@
             _stationMangerRepository = stationMangerRepository;
             _unitOfWorkManage = unitOfWorkManage;
         }
+        private static object lock_reqPackTask = new object();
         /// <summary>
         /// 鍒嗛厤鐮佸灈浠诲姟
         /// </summary>
@@ -47,103 +49,106 @@
         /// <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();
-                    _unitOfWorkManage.BeginTran();
-                    //鏇存柊鐮佸灈鎵ц宸ヤ綅
-                    _stationPackInfoRepository.UpdateData(stationPackInfo);
-                    //鏇存柊寰呯爜鍨涗俊鎭〃
-                    _packinfoRepository.UpdateData(packinfo);
-                    //娣诲姞鐮佸灈浠诲姟
-                    BaseDal.AddData(packaxisTask);
-                    _unitOfWorkManage.CommitTran();
-                    return content.OK(barCode, 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.QueryData(x => x.PackType == packinfo.PackType);
-                    if (packaxes.Count==0)
-                    {
-                        return content.Error("鏈壘鍒扮爜鍨涘潗鏍囬厤缃�");
+                        return content.Error($"鏈壘鍒版潯鐮亄barCode}");
                     }
-                    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)
+                    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)
                     {
-                        return content.Error("鏈壘鍒板彲鍒嗛厤鍨涗綅");
+                        Dt_PackaxisTask 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();
+                        _unitOfWorkManage.BeginTran();
+                        //鏇存柊鐮佸灈鎵ц宸ヤ綅
+                        _stationPackInfoRepository.UpdateData(stationPackInfo);
+                        //鏇存柊寰呯爜鍨涗俊鎭〃
+                        _packinfoRepository.UpdateData(packinfo);
+                        //娣诲姞鐮佸灈浠诲姟
+                        BaseDal.AddData(packaxisTask);
+                        _unitOfWorkManage.CommitTran();
+                        return content.OK(barCode, packaxisTask);
                     }
-                    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()
+                    else//鍒嗛厤鏂板伐浣�
                     {
-                        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);
+                        //鑾峰彇褰撳墠绌虹洏鍑嗗鐨勭爜鍨涘伐浣�
+                        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 && stations.Contains(x.StationCode));
+                        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;
+                        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);
+                    }
                 }
+                catch (Exception ex)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    content.Error(ex.Message);
+                }
+                return content;
             }
-            catch (Exception ex)
-            {
-                _unitOfWorkManage.RollbackTran();
-                content.Error(ex.Message);
-            }
-            return content;
         }
         /// <summary>
         /// 鐮佸灈缁撴墭骞朵笂浼犵爜鍨涘伐浣嶇爜鍨涙槑缁嗘暟鎹�
@@ -247,4 +252,10 @@
             }
         }
     }
+    public class MDCount
+    {
+        public string MDNo { get; set; }
+
+        public int Count { get; set; }
+    }
 }

--
Gitblit v1.9.3