From 5ea48455463691678b806badbee198699a878b5a Mon Sep 17 00:00:00 2001
From: HuBingJie <3146306518@qq.com>
Date: 星期四, 25 十二月 2025 18:38:58 +0800
Subject: [PATCH] 1
---
项目代码/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs | 329 +++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 295 insertions(+), 34 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
index cd6f546..17eab30 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
@@ -21,6 +21,7 @@
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using SqlSugar;
+using System.Diagnostics;
using System.DirectoryServices.Protocols;
using System.Net;
using System.Reflection.Emit;
@@ -266,7 +267,7 @@
BaseDal.DeleteData(task);
BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
- WebResponseContent content=MES_TransferCompletionFeedback(task);
+ WebResponseContent content = MES_TransferCompletionFeedback(task);
//content.Status = true;
if (!content.Status)
@@ -274,7 +275,7 @@
_unitOfWorkManage.RollbackTran();
return content;
}
-
+
_unitOfWorkManage.CommitTran();
return webResponse.OK();
}
@@ -319,6 +320,7 @@
_locationInfoRepository.UpdateData(dt_LocationInfo);
//淇敼搴撳瓨鐘舵��
_stockRepository.UpdateData(stockInfo);
+ task.TaskStatus = (int)TaskInStatusEnum.InFinish;
//鍒犻櫎浠诲姟娣诲姞鍘嗗彶
BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.浜哄伐瀹屾垚 : OperateTypeEnum.鑷姩瀹屾垚);
@@ -553,26 +555,145 @@
/// </summary>
/// <param name="taskNum">浠诲姟鍙�</param>
/// <returns></returns>
- public WebResponseContent Cancelinventory(int taskNum)
+ public ApiResponse<object> Cancelinventory(string palletTaskDTO)
{
WebResponseContent webResponse = new WebResponseContent();
try
{
// 鏌ユ壘浠诲姟
- Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.TaskStatus == TaskOutStatusEnum.OutFinish.ObjToInt());
+ Dt_Task task = BaseDal.QueryFirst(x => x.PalletCode == palletTaskDTO && (x.TaskStatus == TaskOutStatusEnum.OutNew.ObjToInt()|| x.TaskStatus == TaskRelocationStatusEnum.RelocationNew.ObjToInt()|| x.TaskStatus == TaskInStatusEnum.Line_InExecuting.ObjToInt()));
if (task == null)
{
- return webResponse.Error($"鏈壘鍒颁换鍔″彿涓恒�恵taskNum}銆戠殑浠诲姟淇℃伅");
+ return MESresponse($"鏈壘鍒拌揣浣嶄俊鎭�,鏉$爜锛歿palletTaskDTO}", false, 0);
}
- // TODO: 杩欓噷鍚庣画闇�瑕佹坊鍔犲叿浣撶殑鍙栨秷浠诲姟涓氬姟閫昏緫
- // 渚嬪锛氭洿鏂颁换鍔$姸鎬併�侀噴鏀捐揣浣嶃�侀�氱煡WCS绛�
-
- return webResponse.OK("浠诲姟鍙栨秷鎴愬姛");
+ bool res;
+ switch (task.TaskType)
+ {
+ case (int)TaskInboundTypeEnum.Inbound:
+ res = task.TaskStatus == TaskInStatusEnum.Line_InExecuting.ObjToInt();
+ break;
+ case (int)TaskOutboundTypeEnum.Outbound:
+ res = task.TaskStatus == TaskOutStatusEnum.OutNew.ObjToInt();
+ break;
+ case (int)TaskRelocationTypeEnum.Relocation:
+ res = task.TaskStatus == TaskRelocationStatusEnum.RelocationNew.ObjToInt();
+ break;
+ default:
+ res = false;
+ break;
+ }
+ if (!res) return MESresponse($"浠诲姟鐘舵�佸紓甯�", false, 0);
+
+ Dt_StockInfo stockInfo = _stockRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
+
+ _unitOfWorkManage.BeginTran();
+
+ int stockmsseg;
+ int locationmsseg;
+ bool taskmsseg;
+ if (task.TaskType == TaskOutboundTypeEnum.Outbound.ObjToInt() || task.TaskType == TaskRelocationTypeEnum.Relocation.ObjToInt())
+ {
+ stockmsseg = _stockRepository.Db.Updateable<Dt_StockInfo>()
+ .SetColumns(x => x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt())
+ .Where(x => x.PalletCode == task.PalletCode)
+ .ExecuteCommand();
+ if (stockmsseg<=0)
+ {
+ return MESresponse($"鏃犲簱瀛樹俊鎭�", false, 0);
+ }
+ locationmsseg = _locationInfoRepository.Db.Updateable<Dt_LocationInfo>()
+ .SetColumns(x => x.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
+ .Where(x => x.LocationCode == stockInfo.LocationCode)
+ .ExecuteCommand();
+ if (locationmsseg <= 0)
+ {
+ return MESresponse($"鏈壘鍒拌揣浣嶄俊鎭�,鏉$爜锛歿palletTaskDTO}", false, 0);
+ }
+ taskmsseg = BaseDal.DeleteData(task);
+ }
+ else
+ {
+ locationmsseg = _locationInfoRepository.Db.Updateable<Dt_LocationInfo>()
+ .SetColumns(x => x.LocationStatus == LocationStatusEnum.Free.ObjToInt())
+ .Where(x => x.LocationCode == stockInfo.LocationCode)
+ .ExecuteCommand();
+ if (locationmsseg <= 0)
+ {
+ return MESresponse($"鏈壘鍒拌揣浣嶄俊鎭�,鏉$爜锛歿palletTaskDTO}", false, 0);
+ }
+ stockmsseg = _stockRepository.DeleteData(stockInfo).ObjToInt();
+ taskmsseg = BaseDal.DeleteData(task);
+ }
+ BaseDal.DeleteAndMoveIntoHty(task,OperateTypeEnum.浜哄伐鍒犻櫎);
+ //鑾峰彇鎺ュ彛杩涜璋冨彇
+ var ConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_WCS_IPAddress, SysConfigConst.WCSCancelinventory); //鑾峰彇鍒皐cs鍏ㄩ儴绫诲瀷鐨勬帴鍙�
+ string WCSReceiveTaskAPI = ConfigsAPIInfo.ApiAddress + ConfigsAPIInfo.ApiName;
+ if (WCSReceiveTaskAPI == null)
+ {
+ _unitOfWorkManage.RollbackTran();
+
+ return MESresponse($"鎵嬪姩鍙栨秷澶辫触鏈壘鍒皐cs鐨勯厤缃帴鍙�", false, 0);
+ }
+ string apiUrl = $"{WCSReceiveTaskAPI}?taskNum={task.TaskNum}";
+ var respon = HttpHelper.Get(apiUrl);
+
+ if (respon == null)
+ {
+ _unitOfWorkManage.RollbackTran();
+
+ return MESresponse($"wcs璋冨彇鎺ュ彛澶辫触杩斿洖鍙傛暟涓簄ull", false, 0);
+ }
+ var response = JsonConvert.DeserializeObject<ApiResponse<object>>(respon);
+ if (!response.status)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return MESresponse($"WCS璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁板師鍥狅細{response.Message}", false, 0);
+ }
+ if (stockmsseg <= 0 && locationmsseg <= 0 && taskmsseg)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return MESresponse($"浠诲姟鍙栨秷澶辫触", false, 0);
+ }
+
+
+
+
+
+
+ ////鑾峰彇鎺ュ彛杩涜璋冨彇
+ //var MESConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_MES_IPAddress, SysConfigConst.MEScancelTask); //鑾峰彇鍒癕ES鍏ㄩ儴绫诲瀷鐨勬帴鍙�
+ //string MEScancelTask = MESConfigsAPIInfo.ApiAddress + MESConfigsAPIInfo.ApiName;
+ //if (MEScancelTask == null)
+ //{
+ // _unitOfWorkManage.RollbackTran();
+ // return webResponse.Error($"浠诲姟鎵嬪姩鍙栨秷澶辫触锛屾湭閰嶇疆MES浠诲姟鎵嬪姩鍙栨秷鍙嶉鎺ュ彛");
+ //}
+ //var MES = new
+ //{
+ // businessId = task.MESbusinessId,
+ // taskId = task.MEStaskId,
+ // palletCode = task.PalletCode
+ //};
+ //var MESrespon = HttpHelper.Post(MEScancelTask, JsonConvert.SerializeObject(MES));
+ //if (MESrespon == null)
+ //{
+ // _unitOfWorkManage.RollbackTran();
+ // return webResponse.Error($"MES璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁颁负绌�");
+ //}
+ //var MESresponse = JsonConvert.DeserializeObject<ApiResponse<object>>(MESrespon);
+ //if (!MESresponse.Success)
+ //{
+ // _unitOfWorkManage.RollbackTran();
+ // return webResponse.Error($"MES璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁板師鍥狅細{response.Message}");
+ //}
+ _unitOfWorkManage.CommitTran();
+ return MESresponse($"浠诲姟鍙栨秷鎴愬姛", true, 1);
}
catch (Exception ex)
{
- return webResponse.Error($"鍙栨秷浠诲姟澶辫触锛屽師鍥狅細{ex.Message}");
+ _unitOfWorkManage.RollbackTran();
+ return MESresponse($"鍙栨秷浠诲姟澶辫触锛屽師鍥狅細{ex.Message}", false, 0);
}
}
@@ -682,47 +803,50 @@
try
{
- int result = GetLastPart(locationCode).ObjToInt(); // 杩斿洖 "C03"
+ Dt_StockInfo dt_StockInfo = _stockRepository.QueryFirst(x => x.LocationCode.StartsWith("SC01") && x.StockStatus == 6);
+ int result = GetLastPart(dt_StockInfo.LocationCode).ObjToInt(); // 杩斿洖 "C03"
+
List<Dt_Task> dt_s = new List<Dt_Task>();
//鐢熸垚绉诲姩浠诲姟
Dt_Task dt_Task = new()
{
- PalletCode = "1111",
- TaskNum = 111,
+ PalletCode = dt_StockInfo.PalletCode,
+ TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
Roadway = "SC01",
TaskType = TaskOutboundTypeEnum.Outbound.ObjToInt(),
TaskStatus = TaskOutStatusEnum.OutNew.ObjToInt(),
- SourceAddress = locationCode,
- TargetAddress = "1002",
- CurrentAddress = locationCode,
- NextAddress = "1002",
+ SourceAddress = dt_StockInfo.LocationCode,
+ TargetAddress = "1006",
+ CurrentAddress = dt_StockInfo.LocationCode,
+ NextAddress = "1006",
Grade = 1,
Creater = "MES",
Depth = result,
CreateDate = DateTime.Now,
- MEStaskId = "111",
- MESbusinessId = "123456",
- MESsubPalletCode = "",
- OutboundPlatform = "1001"
+ MEStaskId = "EXTASK20251020002",
+ MESbusinessId = "EXBUS20251020002",
+ MESsubPalletCode = dt_StockInfo.MESsubPalletCode,
+ OutboundPlatform = "1005"
};
- //鍒涘缓缁勭洏淇℃伅
- var dt_Stock = new Dt_StockInfo
- {
- PalletCode = dt_Task.PalletCode,
- PalletType = 1,
- LocationCode = locationCode,
- StockStatus = 6,
- Creater = "WMS",
- CreateDate = DateTime.Now,
- MESsubPalletCode = dt_Task.MESsubPalletCode,
- };
+ ////鍒涘缓缁勭洏淇℃伅
+ //var dt_Stock = new Dt_StockInfo
+ //{
+ // PalletCode = dt_Task.PalletCode,
+ // PalletType = 1,
+ // LocationCode = locationCode,
+ // StockStatus = 6,
+ // Creater = "WMS",
+ // CreateDate = DateTime.Now,
+ // MESsubPalletCode = dt_Task.MESsubPalletCode,
+ //};
- Dt_LocationInfo dt_LocationInfo = _locationInfoRepository.QueryFirst(x => x.LocationCode == locationCode);
+ Dt_LocationInfo dt_LocationInfo = _locationInfoRepository.QueryFirst(x => x.LocationCode == dt_StockInfo.LocationCode);
dt_LocationInfo.LocationStatus = (int)LocationStatusEnum.InStockLock;
+ dt_StockInfo.StockStatus = 7;
bool l = _locationInfoRepository.UpdateData(dt_LocationInfo);
- int s = _stockRepository.AddData(dt_Stock);
+ bool s = _stockRepository.UpdateData(dt_StockInfo);
int t = BaseDal.AddData(dt_Task);
bool ss = s.ObjToBool();
bool tt = t.ObjToBool();
@@ -749,5 +873,142 @@
}
}
+
+ /// <summary>
+ /// 鎵嬪姩瀹屾垚鎺ュ彛
+ /// </summary>
+ /// <param name="taskNum"></param>
+ /// <returns></returns>
+ /// <exception cref="NotImplementedException"></exception>
+ public WebResponseContent ManualTaskCompleted(string palletTaskDTO)
+ {
+ WebResponseContent webResponse = new WebResponseContent();
+ try
+ {
+ // 鏌ユ壘浠诲姟
+ Dt_Task task = BaseDal.QueryFirst(x => x.PalletCode == palletTaskDTO);
+ if (task == null)
+ {
+ return webResponse.Error($"鏈壘鍒版墭鐩樼紪鐮佷负銆恵palletTaskDTO}銆戠殑浠诲姟淇℃伅");
+ }
+
+
+ Dt_StockInfo stockInfo = _stockRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
+
+ _unitOfWorkManage.BeginTran();
+
+ Dt_StockInfo stockmsseg;
+ Dt_LocationInfo locationmsseg1 = null;
+ Dt_LocationInfo locationmsseg2 = null;
+ bool taskmsseg;
+ bool task_htymsseg;
+
+ bool location1;
+ bool location2 = false;
+
+ bool resstock;
+ if (task.TaskType == TaskInboundTypeEnum.Inbound.ObjToInt() || task.TaskType == TaskRelocationTypeEnum.Relocation.ObjToInt())
+ {
+ stockmsseg = _stockRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+ if (stockmsseg == null) { return webResponse.Error("鏈壘鍒板簱瀛樹俊鎭�"); };
+ stockmsseg.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+ resstock = _stockRepository.UpdateData(stockmsseg);
+ if (task.TaskType == TaskRelocationTypeEnum.Relocation.ObjToInt())
+ {
+ locationmsseg1 = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+ locationmsseg2 = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.CurrentAddress);
+ if (locationmsseg1 == null || locationmsseg2 == null) { webResponse.Error("鏈壘鍒拌揣浣嶄俊鎭�"); }
+ locationmsseg1.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+ locationmsseg2.LocationStatus = LocationStatusEnum.Free.ObjToInt();
+ location1 = _locationInfoRepository.UpdateData(locationmsseg1);
+ location2 = _locationInfoRepository.UpdateData(locationmsseg2);
+ }
+ else
+ {
+ locationmsseg1 = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+ if (locationmsseg1 == null) { webResponse.Error("鏈壘鍒拌揣浣嶄俊鎭�"); }
+ locationmsseg1.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+ location1 = _locationInfoRepository.UpdateData(locationmsseg1);
+
+ }
+ }
+ else
+ {
+ stockmsseg = _stockRepository.QueryFirst(x => x.LocationCode == task.CurrentAddress);
+ if (stockmsseg == null) { return webResponse.Error("鏈壘鍒板簱瀛樹俊鎭�"); }
+ resstock = _stockRepository.DeleteData(stockmsseg);
+ locationmsseg1 = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.CurrentAddress);
+ if (locationmsseg1 == null) { webResponse.Error("鏈壘鍒拌揣浣嶄俊鎭�"); }
+ locationmsseg1.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+ location1 = _locationInfoRepository.UpdateData(locationmsseg1);
+ }
+
+ taskmsseg = BaseDal.DeleteData(task);
+
+ task_htymsseg = BaseDal.DeleteAndMoveIntoHty(task, OperateTypeEnum.浜哄伐瀹屾垚);
+ //鑾峰彇鎺ュ彛杩涜璋冨彇
+ var ConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_WCS_IPAddress, SysConfigConst.WCSManualTaskCompleted); //鑾峰彇鍒皐cs鍏ㄩ儴绫诲瀷鐨勬帴鍙�
+ string WCSReceiveTaskAPI = ConfigsAPIInfo.ApiAddress + ConfigsAPIInfo.ApiName;
+ if (WCSReceiveTaskAPI == null)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return webResponse.Error($"浠诲姟鎵嬪姩瀹屾垚澶辫触锛屾湭閰嶇疆WCS浠诲姟鎵嬪姩瀹屾垚鍙嶉鎺ュ彛");
+ }
+
+ string apiUrl = $"{WCSReceiveTaskAPI}?taskNum={task.TaskNum}";
+
+ var respon = HttpHelper.Get(apiUrl);
+ if (respon == null)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return webResponse.Error($"WCS璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁颁负绌�");
+ }
+ var response = JsonConvert.DeserializeObject<ApiResponse<object>>(respon);
+ if (!response.status)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return webResponse.Error($"WCS璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁板師鍥狅細{response.Message}");
+ }
+ if (!(resstock && task_htymsseg && taskmsseg && task.TaskType == TaskRelocationTypeEnum.Relocation.ObjToInt() ? (location1 && location2) : location1))
+ {
+ _unitOfWorkManage.RollbackTran();
+ return webResponse.Error($"浠诲姟鎵嬪姩瀹屾垚澶辫触");
+ }
+
+ //鑾峰彇鎺ュ彛杩涜璋冨彇
+ var MESConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_MES_IPAddress, SysConfigConst.MESmockComplete); //鑾峰彇鍒皐cs鍏ㄩ儴绫诲瀷鐨勬帴鍙�
+ string MESmockComplete = MESConfigsAPIInfo.ApiAddress + MESConfigsAPIInfo.ApiName;
+ if (MESConfigsAPIInfo == null)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return webResponse.Error($"浠诲姟鎵嬪姩瀹屾垚澶辫触锛屾湭閰嶇疆MES浠诲姟鎵嬪姩瀹屾垚鍙嶉鎺ュ彛");
+ }
+ var MES = new
+ {
+ businessId = task.MESbusinessId,
+ taskId = task.MEStaskId,
+ palletCode = task.PalletCode
+ };
+ var MESrespon = HttpHelper.Post(MESmockComplete, JsonConvert.SerializeObject(MES));
+ if (respon == null)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return webResponse.Error($"MES璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁颁负绌�");
+ }
+ var MESresponse = JsonConvert.DeserializeObject<ApiResponse<object>>(MESrespon);
+ if (!MESresponse.Success)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return webResponse.Error($"MES璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁板師鍥狅細{response.Message}");
+ }
+ _unitOfWorkManage.CommitTran();
+ return webResponse.OK("浠诲姟鎵嬪姩瀹屾垚鎴愬姛");
+ }
+ catch (Exception ex)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return webResponse.Error($"浠诲姟鎵嬪姩瀹屾垚澶辫触锛屽師鍥狅細{ex.Message}");
+ }
+ }
}
}
--
Gitblit v1.9.3