From f45293a0c3c9838567d6ff01eae53157a9ed5284 Mon Sep 17 00:00:00 2001
From: 刘磊 <1161824510@qq.com>
Date: 星期四, 05 三月 2026 10:59:38 +0800
Subject: [PATCH] 1
---
项目代码/WMS/WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs | 211 +++++++++++++++++++++++++++++++++-------------------
1 files changed, 135 insertions(+), 76 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs"
index b806b38..28e3152 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs"
@@ -10,6 +10,7 @@
using WIDESEA_DTO.WMS;
using WIDESEA_IServices;
using WIDESEA_IStoragIntegrationServices;
+using WIDESEA_StorageTaskRepository;
using WIDESEA_StoragIntegrationServices;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_BasicInfoService;
@@ -81,9 +82,12 @@
WebResponseContent content = new WebResponseContent();
try
{
+ var stationInfo = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway);
+
+ //if( stationInfo == null ) throw new Exception ("鏈厤缃换鍔$珯鍙�")锛�
// 鑾峰彇搴撲綅淇℃伅
- var locationInf = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.TargetAddress && x.RoadwayNo == task.Roadway);
+ var locationInf = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.TargetAddress && x.RoadwayNo == stationInfo.RoadwayNo);
int lastStatus = locationInf.LocationStatus;
// 鏇存柊鐩爣浣嶇疆鐘舵�佷负搴撳瓨涓�
@@ -93,18 +97,22 @@
var taskHty = CreateHistoricalTask(task);
//鑾峰彇缁勭洏淇℃伅
- var carBody = await _carBodyRepository.QueryFirstAsync(x => x.PalletCode == task.PalletCode);
+ var carBody = await _carBodyRepository.QueryFirstAsync(x => x.PalletCode == task.PalletCode && x.RFID == task.PVI);
// 鏍规嵁鍒涘缓搴撳瓨瀹炰緥妯″瀷
//var boxDetail = boxinginfo.BoxingInfoDetails.Adapt<List<Dt_PalletStockInfoDetail>>();
Dt_PalletStockInfo palletStockInfo = new Dt_PalletStockInfo
{
CreateDate = DateTime.Now,
-
Creater = task.Creater,
LocationCode = task.TargetAddress,
- StockStatus = 2,
- PalletCode = task.PalletCode,
+ StockStatus = 0,
+ //PalletCode = task.PalletCode,
+ RoadwayNo = stationInfo.RoadwayNo,
+ LockOrder = 0,
+ TaskStatus = 0,
+ carBodyID = carBody.Id,
+ CarBodyInfo = carBody
};
// 鎵ц鏁版嵁搴撲簨鍔�
@@ -137,7 +145,7 @@
try
{
//鏌ユ壘搴撳瓨
- var stock = await _palletStockInfoRepository.QueryFirstNavAsync(x => x.PalletCode == task.PalletCode);
+ var stock = await _palletStockInfoRepository.QueryFirstNavAsync(x => x.CarBodyInfo.PalletCode == task.PalletCode);
// 鏇存柊搴撲綅鐘舵�佷笌浠诲姟鐘舵��
(var loc, var tas) = UpdateStockAndTaskStatus(stock, task);
@@ -156,8 +164,8 @@
{
var isLocationUpdate = await _locationRepository.UpdateDataAsync(loc); //鏇存柊搴撲綅
var isPalletHty = await _palletStockInfo_HtyRepository.AddDataAsync(stockInfo_Hty); //娣诲姞鍘嗗彶搴撳瓨璁板綍
- //var isTaskUpdated = await BaseDal.DeleteDataByIdAsync(task.TaskId); //鍒犻櫎浠诲姟
- await BaseDal.UpdateDataAsync(task); //鍙栨秷鍒犻櫎浠诲姟锛屾敼涓哄畬鎴愮姸鎬侊紱骞禬MS鐣岄潰鐢变汉宸ョ‘璁ゅ畬鎴�
+ var isTaskUpdated = await BaseDal.DeleteDataByIdAsync(task.TaskId); //鍒犻櫎浠诲姟
+ //await BaseDal.UpdateDataAsync(task); //鍙栨秷鍒犻櫎浠诲姟锛屾敼涓哄畬鎴愮姸鎬侊紱骞禬MS鐣岄潰鐢变汉宸ョ‘璁ゅ畬鎴�
var isTaskAdd = await _task_HtyRepository.AddDataAsync(taskHty) > 0; //鍔犲叆鍘嗗彶浠诲姟
var isDelete = await _palletStockInfoRepository.DeleteDataAsync(stock); //鍒犻櫎搴撳瓨
//await DeleteStockInfoDetailsAsync(stock.StockInfoDetails); //鍒犻櫎搴撳瓨鏄庣粏
@@ -181,7 +189,9 @@
private (DtLocationInfo, Dt_Task) UpdateStockAndTaskStatus(Dt_PalletStockInfo stock, Dt_Task task)
{
- var location = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress && x.RoadwayNo == task.Roadway);
+ var stationInfo = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway);
+
+ var location = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress && x.RoadwayNo == stationInfo.RoadwayNo);
int lastStatus = location.LocationStatus;
location.LocationStatus = (int)LocationEnum.Free;
task.TaskState = (int)TaskOutStatusEnum.OutFinish;
@@ -254,7 +264,7 @@
if (task == null)
return content.Error($"鏆傛湭鎵惧埌銆恵input.PalletCode}銆戠殑浠诲姟");
- return content; //= await UpdateExistingTask(input, task);
+ return await UpdateExistingTask(input, task); // content;
}
catch (Exception err)
{
@@ -287,6 +297,7 @@
await _unitOfWorkManage.UseTranAsync(async () =>
{
var asb = await BaseDal.DeleteDataByIdAsync(task.TaskId);
+
var asbHty = await _task_HtyRepository.AddDataAsync(taskHty) > 0;
if (asb && asbHty)
content.OK();
@@ -298,6 +309,7 @@
else
{
task.TaskState = taskState;
+ task.Dispatchertime = DateTime.Now;
var asb = await BaseDal.UpdateDataAsync(task);
if (asb)
content.OK();
@@ -331,16 +343,16 @@
foreach (var item in barcode)
{
// 鏌ヨ搴撳瓨淇℃伅
- var stockInfo = _palletStockInfoRepository.QueryFirst(x => x.PalletCode == item);
+ var stockInfo = _palletStockInfoRepository.QueryFirst(x => x.Id == item.ObjToInt());
if (stockInfo == null)
{
return content.Error("鏈煡璇㈠埌瀵瑰簲鐨勫簱瀛樹俊鎭�");
}
- if (stockInfo.StockStatus != 2) return content.Error($"鎸囧畾澶辫触锛氭墭鐩榹item}褰撳墠鐘舵�佷笉鍏佽鎸囧畾鍑哄簱");
+ if (stockInfo.StockStatus != 0) return content.Error($"鎸囧畾澶辫触锛氭墭鐩榹item}褰撳墠鐘舵�佷笉鍏佽鎸囧畾鍑哄簱");
- stockInfo.StockStatus = 3;
+ stockInfo.StockStatus = 1;
//鏌ヨ搴撲綅鏄惁閿佸畾锛�
var location = _locationRepository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
@@ -355,20 +367,50 @@
return content.Error($"銆恵item}銆戝凡瀛樺湪浠诲姟");
}
- var stationInfo = _stationManagerRepository.QueryFirst(x => x.stationChildCode == station);
+ var carBody = _carBodyRepository.QueryFirst(x => x.Id == stockInfo.carBodyID);
+ List<Dt_StationManager> stationLists = null;
+ if (carBody.CarType == 1)
+ {
+ stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == stockInfo.RoadwayNo && x.stationType == 2 && x.stationStatus == "1" && x.stationArea == "3");
+ }
+ else if (carBody.CarType == 2)
+ {
+ stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == stockInfo.RoadwayNo && x.stationType == 2 && x.stationStatus == "1" && x.stationArea == "4");
+ }
+ else if (carBody.CarType == 3)
+ {
+ stationLists = _stationManagerRepository.QueryData(x => x.RoadwayNo == stockInfo.RoadwayNo && x.stationType == 7 && x.stationStatus == "1" && x.stationArea == "3");
+ }
- //if (stationInfo.Roadway != stockInfo.AreaCode) throw new Exception($"褰撳墠鎵樼洏{item}涓庝笅鏂欎綅涓嶅悓鍖哄煙锛岃閲嶆柊閫夋嫨锛�");
+ if (stationLists == null || stationLists.Count == 0) throw new Exception("鍑哄簱绔欏彴鏈厤缃垨鏈惎鐢�");
+
+ Dt_StationManager Outstation = null;
+
+ //if (stationLists.Count > 1)
+ //{
+ // var Outtask = BaseDal.QueryData(x => x.Roadway == stationLists.FirstOrDefault().Roadway && x.TaskType == (int)TaskTypeEnum.Outbound).OrderByDescending(x => x.CreateDate).FirstOrDefault();
+ // if (Outtask != null) Outstation = stationLists.Where(x => x.stationChildCode != task.NextAddress && x.stationChildCode != Outtask.CurrentAddress).FirstOrDefault();
+ // else Outstation = stationLists.FirstOrDefault();
+ //}
+ //else
+ //{
+ Outstation = stationLists.FirstOrDefault();
+ //}
+ //var stationInfo = stationInfos.FirstOrDefault();
+
+
// 鍒涘缓骞舵坊鍔犱换鍔″埌鏁版嵁搴�
task = new Dt_Task
{
Grade = 1,
- Roadway = stationInfo.Roadway,
- TargetAddress = stationInfo.stationLocation,
+ Roadway = Outstation.Roadway,
+ TargetAddress = "RB043",
Dispatchertime = DateTime.Now,
- NextAddress = stationInfo.stationLocation,
+ NextAddress = Outstation.stationChildCode,
OrderNo = null,
- PalletCode = stockInfo.PalletCode,
+ PalletCode = carBody.PalletCode,
+ PVI = carBody.PVI,
SourceAddress = stockInfo.LocationCode,
CurrentAddress = stockInfo.LocationCode,
TaskState = (int)TaskOutStatusEnum.OutNew,
@@ -379,40 +421,33 @@
TaskId = 0,
};
+ // 鍒涘缓浠诲姟浼犺緭鐢ㄧ殑DTO瀵硅薄
+ var taskDTO = CreateTaskDTO(task);
- //addtask schedulingTask = new addtask
- //{
- // task_id = task.AGVtaskId,
- // task_type = task.TaskType == (int)TaskTypeEnum.Inbound ? "push" : "pop",
- // work_begin = task.SourceAddress,
- // work_end = task.TargetAddress
- //};
+ // 鑾峰彇WMS IP鍦板潃鐢ㄤ簬鍙戦�佷换鍔¤姹�
+ var wmsIpAddress = GetWCSIpReceiveTask();
+ if (wmsIpAddress == null)
+ {
+ throw new InvalidOperationException("WMS IP 鏈厤缃�");
+ }
- //string address = AGV_Interface + "add_task";
- //string result = HttpsClient.PostAsync(address, schedulingTask.ToDictionary()).Result;
+ var tasks = new List<WMSTaskDTO>() { taskDTO };
+ // 鍙戦�佷换鍔¤姹傚埌WMS
+ var result = HttpHelper.PostAsync(wmsIpAddress, tasks.ToJsonString()).Result;
+ content = JsonConvert.DeserializeObject<WebResponseContent>(result);
+ if (content.Status)
+ {
+ _unitOfWorkManage.BeginTran();
+ // 娣诲姞浠诲姟鍒版暟鎹簱
+ BaseDal.AddData(task);
+ // 鏇存柊搴撲綅浣嶇疆鐘舵�佷负涓嶅彲鐢�
+ _locationRepository.UpdateData(location);
+ _palletStockInfoRepository.UpdateData(stockInfo);
- //content = JsonConvert.DeserializeObject<WebResponseContent>(result);
-
- //if (content.ack != 0)
- //{
- // Console.WriteLine($"璇锋眰RCS寮傚父锛歿content.msg}");
- // LogFactory.GetLog("涓嬪彂AGV浠诲姟").Info(true, $"\r\r--------------------------------------");
- // LogFactory.GetLog("涓嬪彂AGV浠诲姟").Info(true, $"璇锋眰鍙傛暟锛歿schedulingTask.ToJsonString()}");
- // LogFactory.GetLog("涓嬪彂AGV浠诲姟").Info(true, $"鍝嶅簲鍙傛暟锛歿content.ToJsonString()}");
- // throw new Exception(content.msg);
- //}
-
- _unitOfWorkManage.BeginTran();
- // 娣诲姞浠诲姟鍒版暟鎹簱
- BaseDal.AddData(task);
- // 鏇存柊搴撲綅浣嶇疆鐘舵�佷负涓嶅彲鐢�
- _locationRepository.UpdateData(location);
- _palletStockInfoRepository.UpdateData(stockInfo);
-
- _unitOfWorkManage.CommitTran();
+ _unitOfWorkManage.CommitTran();
+ }
}
-
content.OK();
}
catch (Exception ex)
@@ -425,20 +460,42 @@
}
return content;
}
+ #endregion 鎸囧畾浠诲姟鍑哄簱
- private string GetAGVIpReceiveTask()
+
+ /// <summary>
+ /// 鍒涘缓浠诲姟DTO
+ /// </summary>
+ private WMSTaskDTO CreateTaskDTO(Dt_Task task)
+ {
+ return new WMSTaskDTO
+ {
+ TaskNum = task.TaskNum.Value,
+ Grade = task.Grade.Value,
+ PalletCode = task.PalletCode,
+ RoadWay = task.Roadway,
+ SourceAddress = task.SourceAddress,
+ TargetAddress = task.TargetAddress,
+ TaskState = task.TaskState.Value,
+ Id = 0,
+ TaskType = task.TaskType,
+ pvi = task.PVI,
+ NextAddress = task.NextAddress
+
+ };
+ }
+
+ private string GetWCSIpReceiveTask()
{
var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
- var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.AGVIPAddress)?.ConfigValue;
- var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.addTask)?.ConfigValue;
+ var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.WCSIPAddress)?.ConfigValue;
+ var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.ReceiveTask)?.ConfigValue;
if (wmsBase == null || ipAddress == null)
{
return null;
}
return wmsBase + ipAddress;
}
-
- #endregion 鎸囧畾浠诲姟鍑哄簱
#endregion 澶栭儴鎺ュ彛鏂规硶
@@ -666,17 +723,17 @@
var isUpdateStock = true;
var isDeleteBoxing = true;
// 娣诲姞搴撳瓨
- isUpdateStock = await _palletStockInfoRepository.AddDataNavAsync(stock);
+ isUpdateStock = await _palletStockInfoRepository.AddDataAsync(stock) > 0;
//鍒犻櫎缁勭洏鏁版嵁
- if (boxingInfo != null)
- {
- var box = _carBodyRepository.DeleteData(boxingInfo);
- //boxingInfo.CurrentStatue = 5;
- //isDeleteBoxing = await _boxingInfoRepository.Db.DeleteNav<DtBoxingInfo>(x => x.Id == boxingInfo.Id)
- // .Include(x => x.BoxingInfoDetails)
- // .ExecuteCommandAsync();
- }
+ //if (boxingInfo != null)
+ //{
+ // //var box = _carBodyRepository.DeleteData(boxingInfo);
+ // //boxingInfo.CurrentStatue = 5;
+ // //isDeleteBoxing = await _boxingInfoRepository.Db.DeleteNav<DtBoxingInfo>(x => x.Id == boxingInfo.Id)
+ // // .Include(x => x.BoxingInfoDetails)
+ // // .ExecuteCommandAsync();
+ //}
//
// 娣诲姞鍘嗗彶浠诲姟
@@ -732,25 +789,27 @@
// 鍒涘缓WebResponseContent瀵硅薄
var content = new WebResponseContent();
- // 鑾峰彇搴撲綅
- //var location = RequestLocation(input);
- //if (location == null)
- //{
- // return content.Error("鏃犳硶鑾峰彇璐т綅淇℃伅");
- //}
+ var carInfo = _carBodyRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
+ var stationInfo = _stationManagerRepository.QueryFirst(x => x.stationChildCode == input.Position);
+ // 鑾峰彇搴撲綅;
+ var location = RequestLocation(stationInfo.RoadwayNo, carInfo.CarType);
+ if (location == null)
+ {
+ return content.Error("鏃犳硶鑾峰彇璐т綅淇℃伅");
+ }
- //string toAddress = location.LocationCode;
- //int taskState = (int)TaskInStatusEnum.Line_InFinish;
- //int beforeStatus = location.LocationStatus;
- //// 鏇存柊璐т綅淇℃伅
- //location.LocationStatus = (int)LocationEnum.Lock;
+ string toAddress = location.LocationCode;
+ int taskState = (int)TaskInStatusEnum.Line_InFinish;
+ int beforeStatus = location.LocationStatus;
+ // 鏇存柊璐т綅淇℃伅
+ location.LocationStatus = (int)LocationEnum.Lock;
- // 鏇存柊浠诲姟淇℃伅
- //MapTaskProperties(task, input, toAddress, taskState);
+ //鏇存柊浠诲姟淇℃伅
+ MapTaskProperties(task, input, toAddress, taskState);
_unitOfWorkManage.BeginTran();
// 寮�濮嬩簨鍔�
- var isResult = false; //await UpdateTaskAsync(task, location, beforeStatus);
+ var isResult = await UpdateTaskAsync(task, location, beforeStatus);
if (!isResult)
{
_unitOfWorkManage.RollbackTran();
--
Gitblit v1.9.3