From 4f3b0a6727ecfa555892ebea64bd76e5a07cd6fb Mon Sep 17 00:00:00 2001
From: xiazhengtongxue <133085197+xiazhengtongxue@users.noreply.github.com>
Date: 星期二, 17 三月 2026 10:01:38 +0800
Subject: [PATCH] feat: 新增WMS异常上报自动恢复异常按钮
---
项目代码/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs | 99 +++++++++++++++++++++++++++++++++++--------------
1 files changed, 70 insertions(+), 29 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs"
index 6887160..deda58a 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs"
@@ -91,7 +91,7 @@
public List<int> TaskRelocationTypes => typeof(TaskTypeEnum).GetEnumIndexList().Where(x => x >= 900 && x < 1000).ToList();
- public TaskService(ITaskRepository BaseDal, IMapper mapper, ICacheService cacheService, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IApiInfoRepository apiInfoRepository,ILocationInfoRepository locationInfoRepository,IUnitOfWorkManage unitOfWorkManage, ILocationInfoService locationInfoService,ILocationStatusChangeRecordService locationStatusChangeRecordService,IErrorInfoRepository errorInfoRepository) : base(BaseDal)
+ public TaskService(ITaskRepository BaseDal, IMapper mapper, ICacheService cacheService, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IApiInfoRepository apiInfoRepository, ILocationInfoRepository locationInfoRepository, IUnitOfWorkManage unitOfWorkManage, ILocationInfoService locationInfoService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IErrorInfoRepository errorInfoRepository) : base(BaseDal)
{
_mapper = mapper;
_cacheService = cacheService;
@@ -104,7 +104,7 @@
_locationInfoRepository = locationInfoRepository;
_unitOfWorkManage = unitOfWorkManage;
_locationInfoService = locationInfoService;
- _locationStatusChangeRecordService=locationStatusChangeRecordService;
+ _locationStatusChangeRecordService = locationStatusChangeRecordService;
_errorInfoRepository = errorInfoRepository;
}
static object lock_taskReceive = new object();
@@ -123,18 +123,18 @@
{
WriteLog.Write_Log("鍏ュ簱浠诲姟涓嬪彂", "WMS鍏ュ簱浠诲姟鎺ユ敹鍙傛暟", "鎺ユ敹鍙傛暟", $"鍙傛暟锛歿taskDTO.ToJson()}");
List<Dt_Task> tasks = new List<Dt_Task>();
- List<Dt_Task> taskOlds = BaseDal.QueryData(x=> taskDTO.Tasks.Select(x => x.TaskDescribe.ContainerCode).Contains(x.PalletCode));
- List<Dt_LocationInfo> locationInfos = _locationInfoRepository.GetCanOut(taskDTO.Tasks.Select(x=>x.TaskDescribe.ContainerCode).ToList());
+ List<Dt_Task> taskOlds = BaseDal.QueryData(x => taskDTO.Tasks.Select(x => x.TaskDescribe.ContainerCode).Contains(x.PalletCode));
+ List<Dt_LocationInfo> locationInfos = _locationInfoRepository.GetCanOut(taskDTO.Tasks.Select(x => x.TaskDescribe.ContainerCode).ToList());
List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData();
////涓嬪彂浠诲姟缁�
//string taskGroup= taskDTO.TaskGroupCode.IsNullOrEmpty() ? Guid.NewGuid().ToString().Replace("-","") : taskDTO.TaskGroupCode;
- foreach (var item in taskDTO.Tasks.OrderBy(x=>x.TaskDescribe.ToStationCode))
+ foreach (var item in taskDTO.Tasks.OrderBy(x => x.TaskDescribe.ToStationCode))
{
if (item.TaskDescribe.ToStationCode.IsNullOrEmpty()) throw new Exception($"浠诲姟{item.TaskCode}鍑哄簱鐩爣鎿嶄綔鍙颁笉鑳戒负绌�");
//鑾峰彇鎿嶄綔鍙�
Dt_StationManger? stationManger = stationMangers.FirstOrDefault(x => x.PickStationCode == item.TaskDescribe.ToStationCode);
if (stationManger == null) throw new Exception($"浠诲姟{item.TaskCode}鍑哄簱鐩爣鎿嶄綔鍙皗item.TaskDescribe.ToStationCode}涓嶅瓨鍦�");
- Dt_Task? taskOld = taskOlds.FirstOrDefault(x=>x.PalletCode==item.TaskDescribe.ContainerCode);
+ Dt_Task? taskOld = taskOlds.FirstOrDefault(x => x.PalletCode == item.TaskDescribe.ContainerCode);
if (taskOld != null)
{
errorMsg += $"鏂欑{taskOld.PalletCode}" + (taskOld.TaskType == TaskTypeEnum.Inbound.ObjToInt() ? "鍏ュ簱浠诲姟宸插瓨鍦�;" : "鍑哄簱浠诲姟宸插瓨鍦�;");
@@ -147,7 +147,7 @@
errorMsg += $"鏂欑{item.TaskDescribe.ContainerCode}涓嶅瓨鍦�;";
content.FailData.Add(new BinCodeObj() { Bincode = item.TaskDescribe.ContainerCode });
continue;
- };
+ }
Dt_LocationInfo? noOutLocation = locationInfos.FirstOrDefault(x => (x.LocationStatus != LocationStatusEnum.InStock.ObjToInt() || x.EnableStatus != EnableStatusEnum.Normal.ObjToInt()) && x.PalletCode == item.TaskDescribe.ContainerCode);
if (noOutLocation != null)
{
@@ -171,7 +171,7 @@
locationInfos.ForEach(x =>
{
- x.LocationStatus=LocationStatusEnum.Lock.ObjToInt();
+ x.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
});
//娣诲姞浠诲姟鏇存柊璐т綅鏁版嵁
_unitOfWorkManage.BeginTran();
@@ -179,11 +179,11 @@
_locationInfoRepository.UpdateData(locationInfos);
_unitOfWorkManage.CommitTran();
_taskExecuteDetailService.AddTaskExecuteDetail(tasks.Select(x => x.TaskNum).ToList(), "鎺ユ敹WMS浠诲姟");
- if (tasks.Count>0)
+ if (tasks.Count > 0)
{
_locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfos, LocationStatusEnum.InStock, LocationStatusEnum.Lock, LocationChangeType.OutboundAssignLocation, tasks);
}
- content.OK(errorMsg.IsNullOrEmpty()? "鎴愬姛": errorMsg);
+ content.OK(errorMsg.IsNullOrEmpty() ? "鎴愬姛" : errorMsg);
}
}
catch (Exception ex)
@@ -192,7 +192,7 @@
}
return content;
}
-
+
/// <summary>
/// 瀹瑰櫒鍏ュ簱鍒涘缓浠诲姟
/// </summary>
@@ -206,7 +206,7 @@
Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x => x.PalletCode == containerFlowDTO.ContainerCode);
if (locationInfo != null) throw new Exception($"搴撲綅鏂欑鍙穥containerFlowDTO.ContainerCode}宸插瓨鍦�");
Dt_Task taskOld = BaseDal.QueryFirst(x => x.PalletCode == containerFlowDTO.ContainerCode);
- if (taskOld !=null && taskOld.PalletCode == containerFlowDTO.ContainerCode && taskOld.TaskType == TaskTypeEnum.Inbound.ObjToInt() && taskOld.TaskState == TaskStatusEnum.CL_Executing.ObjToInt() && taskOld.DeviceCode == deviceCode)
+ if (taskOld != null && taskOld.PalletCode == containerFlowDTO.ContainerCode && taskOld.TaskType == TaskTypeEnum.Inbound.ObjToInt() && taskOld.TaskState == TaskStatusEnum.CL_Executing.ObjToInt() && taskOld.DeviceCode == deviceCode)
{
Thread.Sleep(500);
return content.OK();
@@ -243,7 +243,7 @@
task.Roadway = noInLocation.RoadwayNo;
task.DeviceCode = stationManger.StationDeviceCode;
task.TaskState = TaskStatusEnum.CL_Executing.ObjToInt();
-
+
//娣诲姞浠诲姟
int taskId = BaseDal.AddData(task);
if (type > 0)
@@ -466,14 +466,14 @@
/// 鐢宠鍏ュ簱
/// </summary>
/// <returns></returns>
- public WebResponseContent RequestInTask(string stationCode,string barCode)
+ public WebResponseContent RequestInTask(string stationCode, string barCode)
{
WebResponseContent content = new WebResponseContent();
try
{
lock (lock_requestInTask)
{
- Dt_Task task = BaseDal.QueryFirst(x => x.PalletCode == barCode && x.TaskType==TaskTypeEnum.Inbound.ObjToInt() && x.NextAddress == stationCode && x.TaskState == TaskStatusEnum.CL_Executing.ObjToInt());
+ Dt_Task task = BaseDal.QueryFirst(x => x.PalletCode == barCode && x.TaskType == TaskTypeEnum.Inbound.ObjToInt() && x.NextAddress == stationCode && x.TaskState == TaskStatusEnum.CL_Executing.ObjToInt());
if (task == null) throw new Exception($"{barCode}鏂欑鏈壘鍒颁换鍔�!");
Dt_LocationInfo? locationInfo = _locationInfoService.AssignLocation();
if (locationInfo == null) throw new Exception($"鍙敤璐т綅涓嶈冻!");
@@ -639,7 +639,7 @@
return content;
}
-
+
/// <summary>
/// 鎺ュ彈WMS鎵嬪姩瀹屾垚浠诲姟
/// </summary>
@@ -669,7 +669,7 @@
/// <returns></returns>
public WebResponseContent AgvTaskFlow(string code)
{
- WebResponseContent content=new WebResponseContent();
+ WebResponseContent content = new WebResponseContent();
try
{
WriteLog.Write_Log("AGV浠诲姟鏀捐", "AGV浠诲姟鏀捐鎺ュ彛", "鏂欑鍙�", $"鏂欑锛歿code}");
@@ -697,7 +697,7 @@
/// WMS鏂欑鍒拌揪鎷i�変綅涓婃姤
/// </summary>
/// <returns></returns>
- public WebResponseContent WMSPickUp(string stationCode,string pickCode)
+ public WebResponseContent WMSPickUp(string stationCode, string pickCode)
{
WebResponseContent content = new WebResponseContent();
try
@@ -737,7 +737,7 @@
Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)//鍑哄簱浠诲姟瀹屾垚閫昏緫
{
- Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x=>x.PalletCode==task.PalletCode);
+ Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
if (locationInfo.LocationStatus != LocationStatusEnum.Lock.ObjToInt())
{
return content.Error($"{locationInfo.LocationCode}璐т綅鐘舵�佷笉姝g‘");
@@ -772,9 +772,9 @@
string response = HttpHelper.Post(url, request);
WriteLog.Write_Log("WMS鍑哄簱浠诲姟瀹屾垚鍥炰紶", "浠诲姟瀹屾垚鎺ュ彛", "浠诲姟淇℃伅", $"璇锋眰锛歿request}锛屽洖浼狅細{response}");
WMSResponseContent wMSResponse = JsonConvert.DeserializeObject<WMSResponseContent>(response) ?? throw new Exception($"{taskNum},鏈帴鏀跺埌WMS鍑哄簱涓婃姤杩斿洖鍊�");
- if (wMSResponse.Code != "0") content.Message=$"鍑哄簱浠诲姟{task.TaskNum}WMS鍑哄簱涓婃姤閿欒,淇℃伅:{wMSResponse.Msg}";
+ if (wMSResponse.Code != "0") content.Message = $"鍑哄簱浠诲姟{task.TaskNum}WMS鍑哄簱涓婃姤閿欒,淇℃伅:{wMSResponse.Msg}";
}
- else if(task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//鍏ュ簱浠诲姟瀹屾垚閫昏緫
+ else if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//鍏ュ簱浠诲姟瀹屾垚閫昏緫
{
string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSInOutBoundBack.ToString())?.ApiAddress;
if (string.IsNullOrEmpty(url))
@@ -834,14 +834,14 @@
WriteLog.Write_Log("浠诲姟鍙栨秷鎺ユ敹", "浜哄伐鎵嬪姩鍙栨秷鎸囧畾浠诲姟", "浠诲姟鍙�", $"浠诲姟锛歿taskNum}");
// 1. 鑾峰彇浠诲姟淇℃伅
Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
- if (task == null)return content.Error($"浠诲姟{taskNum}涓嶅瓨鍦�");
+ if (task == null) return content.Error($"浠诲姟{taskNum}涓嶅瓨鍦�");
TaskTypeGroup group = task.TaskType.GetTaskTypeGroup();
if (group == TaskTypeGroup.InboundGroup)// 鍏ュ簱浠诲姟鍙栨秷
{
// 鑾峰彇鐩爣璐т綅
Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
- if (locationInfo == null)return content.Error($"鐩爣璐т綅{task.TargetAddress}涓嶅瓨鍦�");
+ if (locationInfo == null) return content.Error($"鐩爣璐т綅{task.TargetAddress}涓嶅瓨鍦�");
// 楠岃瘉璐т綅鐘舵��
if (locationInfo.LocationStatus != LocationStatusEnum.Lock.ObjToInt())
return content.Error($"{task.TargetAddress}璐т綅鐘舵�佸紓甯革紝鏃犳硶鍙栨秷");
@@ -1067,12 +1067,12 @@
{
AgvTaskCancelDTO agvTaskCancel = new AgvTaskCancelDTO()
{
- RequestId= DateTime.Now.ToString("yyMMddHHmmssfff"),
- MissionCode=item.GroupId,
- ContainerCode=item.PalletCode,
- Position="",
- CancelMode= "CTU_REDIRECT_START",
- Reason=""
+ RequestId = DateTime.Now.ToString("yyMMddHHmmssfff"),
+ MissionCode = item.GroupId,
+ ContainerCode = item.PalletCode,
+ Position = "",
+ CancelMode = "CTU_REDIRECT_START",
+ Reason = ""
};
AgvCancelTask(agvTaskCancel);
}
@@ -1243,5 +1243,46 @@
return content;
}
+ public WebResponseContent WmsRecovery()
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ // 鍒犻櫎绗竴涓紓甯�
+ // 鎸夊垱寤烘椂闂村崌搴忚幏鍙栫涓�鏉¤褰�
+ var orderBy = new Dictionary<string, OrderByType>
+ {
+ { "CreateDate", OrderByType.Asc }
+ };
+ Dt_ErrorInfo errorInfo = _errorInfoRepository.QueryFirst(x => true, orderBy);
+ if (errorInfo == null)
+ {
+ return content.Error("褰撳墠娌℃湁寮傚父浠诲姟");
+ }
+ // 鑾峰彇绗竴涓紓甯革紙鎸夊垱寤烘椂闂存帓搴忥級
+ _unitOfWorkManage.BeginTran();
+ _errorInfoRepository.DeleteData(errorInfo);
+ _unitOfWorkManage.CommitTran();
+ // 涓婃姤鎭㈠
+ string? apiErrorBack = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSErrorBack.ToString())?.ApiAddress;
+ if (string.IsNullOrEmpty(apiErrorBack)) throw new Exception($"鏈壘鍒癢MS鏁呴殰涓婃姤,璇锋鏌ユ帴鍙i厤缃�");
+ TaskError taskError = new TaskError()
+ {
+ MsgID = errorInfo.Id,
+ StationCode = errorInfo.StationCode,
+ MsgCode = 0,
+ Msg = "鎭㈠"
+ };
+ string reqErrorBack = JsonConvert.SerializeObject(taskError, settings);
+ HttpHelper.Post(apiErrorBack, reqErrorBack);
+ return content.OK();
+ }
+ catch (Exception ex)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return content.Error(ex.Message);
+ throw new Exception(ex.Message);
+ }
+ }
}
}
--
Gitblit v1.9.3