From ceb8c334e8ca10d569b4c7f72b74126ce1877e48 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期二, 07 一月 2025 21:51:51 +0800
Subject: [PATCH] 添加辅料仓功能,优化测试架仓代码

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/MesTaskService.cs |  233 +++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 197 insertions(+), 36 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/MesTaskService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/MesTaskService.cs"
index 713e75d..3d8e7d2 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/MesTaskService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/MesTaskService.cs"
@@ -1,16 +1,24 @@
-锘縰sing System;
+锘�
+using Newtonsoft.Json.Serialization;
+using Newtonsoft.Json;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEA_Common.APIEnum;
 using WIDESEA_Common.CommonEnum;
 using WIDESEA_Common.LocationEnum;
 using WIDESEA_Common.OtherEnum;
 using WIDESEA_Common.StockEnum;
 using WIDESEA_Common.TaskEnum;
+using WIDESEA_Common.WareHouseEnum;
 using WIDESEA_Core;
 using WIDESEA_Core.BaseServices;
+using WIDESEA_Core.Enums;
+using WIDESEA_Core.Helper;
 using WIDESEA_DTO;
+using WIDESEA_DTO.ERP;
 using WIDESEA_DTO.MES;
 using WIDESEA_ITaskInfoRepository;
 using WIDESEA_ITaskInfoService;
@@ -18,8 +26,10 @@
 
 namespace WIDESEA_TaskInfoService
 {
-    public partial class TaskService 
+    public partial class TaskService
     {
+        static object lock_out = new object();
+
         /// <summary>
         /// 娴嬭瘯鏋跺嚭浠�
         /// </summary>
@@ -27,55 +37,125 @@
         /// <returns></returns>
         public MesResponseContent TestToolOut(TestToolOutModel model)
         {
+            lock (lock_out)
+            {
+                MesResponseContent responseContent = new MesResponseContent();
+                try
+                {
+                    Dt_Task exsit = Repository.QueryFirst(x => x.TargetAddress == model.TargetAddressCode);
+                    if(exsit != null)
+                    {
+                        return responseContent.Error($"鐩爣鍦板潃閲嶅");
+                    }
+
+                    Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA64.ToString());
+                    //鑾峰彇搴撳瓨璁板綍
+                    List<Dt_StockInfo> stockInfos = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x =>
+                      x.WarehouseId == warehouse.WarehouseId &&
+                      x.StockStatus == (int)StockStatusEmun.鍏ュ簱瀹屾垚).Includes(x => x.Details).ToList();
+                    Dt_StockInfo? stockInfo = stockInfos.FirstOrDefault(x => x.Details.Any(x => x.BatchNo == model.ToolCode));
+                    if (stockInfo == null)
+                    {
+                        return responseContent.Error($"娴嬭瘯鏋�:{model.ToolCode}鏃犲彲鐢ㄥ簱瀛�");
+                    }
+                    Dt_Task exsit2 = Repository.QueryFirst(x => x.PalletCode == stockInfo.PalletCode);
+                    if (exsit2 != null)
+                    {
+                        return responseContent.Error($"娴嬭瘯鏋舵壒娆″彿閲嶅");
+                    }
+
+                    Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode &&
+                      x.WarehouseId == stockInfo.WarehouseId &&
+                      x.LocationStatus == (int)LocationStatusEnum.InStock &&
+                      (x.EnableStatus == (int)EnableStatusEnum.Normal || x.EnableStatus == (int)EnableStatusEnum.OnlyOut));
+                    if (locationInfo == null)
+                    {
+                        return responseContent.Error($"娴嬭瘯鏋惰揣浣�:{stockInfo.LocationCode}鍑哄簱鏉′欢涓嶆弧瓒�");
+                    }
+                    //鐢熸垚娴嬭瘯鏋跺嚭搴撲换鍔� 閿佸畾搴撳瓨 鏇存敼璐т綅鐘舵��
+                    Dt_Task taskOut = new()
+                    {
+                        CurrentAddress = stockInfo.LocationCode,
+                        Grade = 0,
+                        PalletCode = stockInfo.PalletCode,
+                        NextAddress = "",
+                        Roadway = locationInfo.RoadwayNo,
+                        SourceAddress = stockInfo.LocationCode,
+                        TargetAddress = model.TargetAddressCode,
+                        TaskStatus = (int)TaskStatusEnum.New,
+                        TaskType = (int)TaskTypeEnum.Outbound,
+                        TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
+                        PalletType = stockInfo.PalletType,
+                        WarehouseId = stockInfo.WarehouseId,
+                    };
+                    stockInfo.StockStatus = (int)StockStatusEmun.鍑哄簱閿佸畾;
+                    LocationStatusEnum locationStatus = (LocationStatusEnum)locationInfo.LocationStatus;
+                    locationInfo.LocationStatus = (int)LocationStatusEnum.Lock;
+                    //鍒ゆ柇鏄惁鏈夊嚭搴撳崟淇℃伅
+                    _unitOfWorkManage.BeginTran();
+                    //鏇存柊搴撳瓨鐘舵��
+                    _stockRepository.StockInfoRepository.UpdateData(stockInfo);
+                    //鏇存柊璐т綅鐘舵��
+                    _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, (PalletTypeEnum)stockInfo.PalletType, LocationStatusEnum.Lock, stockInfo.WarehouseId);
+                    //鏂板缓浠诲姟
+                    BaseDal.AddData(taskOut);
+                    //鍔犲叆璐т綅鍙樺姩璁板綍
+                    _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, locationStatus, LocationStatusEnum.Lock, LocationChangeType.OutboundAssignLocation, stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", taskOut.TaskNum);
+                    _unitOfWorkManage.CommitTran();
+                    //灏嗕换鍔℃帹閫佸埌WCS
+                    PushTasksToWCS(new List<Dt_Task>() { taskOut }, "AGV_CSJ");
+                    responseContent.OK();
+                }
+                catch (Exception ex)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    responseContent.Error(ex.Message);
+                }
+                return responseContent;
+            }
+        }
+        /// <summary>
+        /// 娴嬭瘯鏋堕��搴�
+        /// </summary>
+        /// <returns></returns>
+        public MesResponseContent TestToolBack(TestToolBackModel backModel)
+        {
             MesResponseContent responseContent = new MesResponseContent();
             try
             {
-                //鑾峰彇搴撳瓨璁板綍 warehouseID鏆傚畾鍏堢敤鍥哄畾鍊� TEST
-                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.WarehouseId == 1 && 
-                  x.PalletCode == model.ToolCode && 
-                  x.StockStatus==(int)StockStatusEmun.鍏ュ簱瀹屾垚)
-                .Includes(x => x.Details).First();
-                if (stockInfo==null)
+                //鑾峰彇娴嬭瘯鏋跺師搴撳瓨淇℃伅
+                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA64.ToString());
+                //鑾峰彇搴撳瓨璁板綍
+                List<Dt_StockInfo> stockInfos = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x =>
+                  x.WarehouseId == warehouse.WarehouseId &&
+                  x.StockStatus == (int)StockStatusEmun.鍑哄簱瀹屾垚).Includes(x => x.Details).ToList();
+                Dt_StockInfo? stockInfo = stockInfos.FirstOrDefault(x => x.Details.Any(x => x.BatchNo == backModel.TestToolCode));
+                if (stockInfo == null)
                 {
-                    return responseContent.Error($"娴嬭瘯鏋舵墭鐩�:{model.ToolCode}鏃犲簱瀛樿褰�");
+                    return responseContent.Error($"{backModel.TestToolCode}搴撳瓨淇℃伅涓嶅瓨鍦�");
                 }
-                Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode &&
-                  x.WarehouseId == stockInfo.WarehouseId &&
-                  x.LocationStatus == (int)LocationStatusEnum.InStock &&
-                  (x.EnableStatus == (int)EnableStatusEnum.Normal || x.EnableStatus == (int)EnableStatusEnum.OnlyOut));
-                if (locationInfo==null)
+                //鐢熸垚閫�搴撲换鍔�
+                Dt_Task taskIn = new()
                 {
-                    return responseContent.Error($"璐т綅:{stockInfo.LocationCode}鍑哄簱鏉′欢涓嶆弧瓒�");
-                }
-                //鐢熸垚娴嬭瘯鏋跺嚭搴撲换鍔� 閿佸畾搴撳瓨 鏇存敼璐т綅鐘舵��
-                Dt_Task taskOut = new()
-                {
-                    CurrentAddress = stockInfo.LocationCode,
+                    CurrentAddress = backModel.SourceAddressCode,
                     Grade = 0,
                     PalletCode = stockInfo.PalletCode,
                     NextAddress = "",
-                    Roadway = locationInfo.RoadwayNo,
-                    SourceAddress = stockInfo.LocationCode,
+                    Roadway = "",
+                    SourceAddress = backModel.SourceAddressCode,
                     TargetAddress = "",
-                    TaskStatus = (int)TaskOutStatusEnum.OutNew,
-                    TaskType = (int)TaskOutboundTypeEnum.OutTestStand,
+                    TaskStatus = (int)TaskStatusEnum.New,
+                    TaskType = (int)TaskTypeEnum.ProductionReturn,
                     TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                     PalletType = stockInfo.PalletType,
                     WarehouseId = stockInfo.WarehouseId,
                 };
-                stockInfo.StockStatus = (int)StockStatusEmun.鍑哄簱閿佸畾;
-                LocationStatusEnum locationStatus = (LocationStatusEnum)locationInfo.LocationStatus;
-                locationInfo.LocationStatus = (int)LocationStatusEnum.Lock;
-                _unitOfWorkManage.BeginTran();
-                //鏇存柊搴撳瓨鐘舵��
+                //鏇存敼搴撳瓨鐘舵��
+                stockInfo.StockStatus = StockStatusEmun.閫�搴�.ObjToInt();
+                BaseDal.AddData(taskIn);
                 _stockRepository.StockInfoRepository.UpdateData(stockInfo);
-                //鏇存柊璐т綅鐘舵��
-                _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, (PalletTypeEnum)stockInfo.PalletType, LocationStatusEnum.Lock, stockInfo.WarehouseId);
-                //鏂板缓浠诲姟
-                BaseDal.AddData(taskOut);
-                //鍔犲叆璐т綅鍙樺姩璁板綍
-                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, locationStatus, LocationChangeType.OutboundAssignLocation, stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", taskOut.TaskNum);
-                _unitOfWorkManage.CommitTran();
+                //灏嗕换鍔℃帹閫佸埌WCS
+                PushTasksToWCS(new List<Dt_Task>() { taskIn }, "AGV_CSJ"); ;
                 responseContent.OK();
             }
             catch (Exception ex)
@@ -85,5 +165,86 @@
             }
             return responseContent;
         }
+        /// <summary>
+        /// 娴嬭瘯鏋舵姤搴�
+        /// </summary>
+        /// <returns></returns>
+        public MesResponseContent TestScrap(TestToolScrap toolScraps)
+        {
+            MesResponseContent responseContent = new MesResponseContent();
+            try
+            {
+                //鑾峰彇娴嬭瘯鏋舵壒娆″彿搴撳瓨
+                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA64.ToString());
+                //鑾峰彇搴撳瓨璁板綍
+                List<Dt_StockInfo> stockInfos = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x =>
+                  x.WarehouseId == warehouse.WarehouseId &&
+                  x.StockStatus == (int)StockStatusEmun.鍑哄簱瀹屾垚).Includes(x => x.Details).ToList();
+                List<Dt_StockInfo> stockInfoUpdates = new List<Dt_StockInfo>();
+                List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>();
+                foreach (var item in toolScraps.ToolCodes)
+                {
+                    Dt_StockInfo? stockInfo = stockInfos.FirstOrDefault(x => x.Details.Any(x => x.BatchNo == item));
+                    if (stockInfo == null)
+                    {
+                        return responseContent.Error($"{item}搴撳瓨淇℃伅涓嶅瓨鍦�");
+                    }
+                    stockInfoUpdates.Add(stockInfo);
+                    stockInfoDetails.Add(stockInfo.Details.FirstOrDefault());
+                }
+                //娓呴櫎搴撳瓨淇℃伅
+                _unitOfWorkManage.BeginTran();
+                _stockRepository.StockInfoRepository.DeleteAndMoveIntoHty(stockInfoUpdates, OperateTypeEnum.鑷姩鍒犻櫎);
+                _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(stockInfoDetails,OperateTypeEnum.鑷姩鍒犻櫎);
+                _unitOfWorkManage.CommitTran();
+                responseContent.OK($"鎶ュ簾鎴愬姛");
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                responseContent.Error(ex.Message);
+            }
+            return responseContent;
+        }
+        /// <summary>
+        /// 鍚屾娴嬭瘯鏋跺鍛�
+        /// </summary>
+        /// <param name="toolSynInfo"></param>
+        /// <returns></returns>
+        public WebResponseContent TestSynStock(TestToolSynInfo toolSynInfo)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                Dt_ApiInfo apiInfo = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMS_MES_TestToolSync.ToString());
+                MESRoot<TestToolSynInfo> root = new MESRoot<TestToolSynInfo>()
+                {
+                    From = "WMS",
+                    DateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+                    Content = toolSynInfo
+                };
+                JsonSerializerSettings settings = new JsonSerializerSettings
+                {
+                    ContractResolver = new CamelCasePropertyNamesContractResolver()
+                };
+                string request = JsonConvert.SerializeObject(root, settings);
+                string response = HttpMesHelper.Post(apiInfo.ApiAddress, request);
+                MesResponseContent mesResponseContent = response.DeserializeObject<MesResponseContent>();
+                //璋冪敤鎺ュ彛
+                if (mesResponseContent.BSucc == true)
+                {
+                    content.OK(mesResponseContent.StrMsg);
+                }
+                else
+                {
+                    content.Error(mesResponseContent.StrMsg);
+                }
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
     }
 }

--
Gitblit v1.9.3