From 46908c0f79e7aab8a3fa41bfdcd8390bbc3659f2 Mon Sep 17 00:00:00 2001
From: xiazhengtongxue <133085197+xiazhengtongxue@users.noreply.github.com>
Date: 星期日, 04 一月 2026 11:48:15 +0800
Subject: [PATCH] 完善前端二期播种墙初始化和任务完成按钮,后端定期删除日志
---
项目代码/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs | 621 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 574 insertions(+), 47 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 bc33716..fe591f7 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"
@@ -15,17 +15,26 @@
*----------------------------------------------------------------*/
#endregion << 鐗� 鏈� 娉� 閲� >>
using AutoMapper;
+using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using NPOI.SS.Formula.Functions;
+using NPOI.SS.UserModel;
+using NPOI.XSSF.UserModel;
+using RYB_PTL_API;
using SqlSugar;
using System.Diagnostics.CodeAnalysis;
using System.DirectoryServices.Protocols;
+using System.Linq;
using System.Net.Http.Headers;
using System.Security.Policy;
+using System.Text;
+using System.Threading.Tasks;
using WIDESEA_DTO.Agv;
using WIDESEA_External.Model;
+using WIDESEAWCS_BasicInfoService;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.APIEnum;
+using WIDESEAWCS_Common.Helper;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseRepository;
@@ -37,6 +46,7 @@
using WIDESEAWCS_DTO.Agv;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_IBasicInfoRepository;
+using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
@@ -59,6 +69,9 @@
private readonly IRouterRepository _routerRepository;
private readonly IApiInfoRepository _apiInfoRepository;
private readonly ILocationInfoRepository _locationInfoRepository;
+ private readonly ILocationInfoService _locationInfoService;
+ private readonly ILocationStatusChangeRecordService _locationStatusChangeRecordService;
+ private readonly IErrorInfoRepository _errorInfoRepository;
private Dictionary<string, OrderByType> _taskOrderBy = new()
{
@@ -76,7 +89,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) : 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;
@@ -88,6 +101,9 @@
_apiInfoRepository = apiInfoRepository;
_locationInfoRepository = locationInfoRepository;
_unitOfWorkManage = unitOfWorkManage;
+ _locationInfoService = locationInfoService;
+ _locationStatusChangeRecordService=locationStatusChangeRecordService;
+ _errorInfoRepository = errorInfoRepository;
}
static object lock_taskReceive = new object();
/// <summary>
@@ -95,40 +111,59 @@
/// </summary>
/// <param name="taskDTOs">WMS浠诲姟瀵硅薄闆嗗悎</param>
/// <returns>杩斿洖澶勭悊缁撴灉</returns>
- public WebResponseContent ReceiveWMSTask([NotNull] WMSTaskDTO taskDTO)
+ public WMSReceiveTaskContent ReceiveWMSTask([NotNull] WMSTaskDTO taskDTO)
{
- WebResponseContent content = new WebResponseContent();
+ WMSReceiveTaskContent content = new WMSReceiveTaskContent();
+ string errorMsg = "";
try
{
lock (lock_taskReceive)
{
List<Dt_Task> tasks = new List<Dt_Task>();
- List<Dt_LocationInfo> locationInfos = _locationInfoRepository.GetCanOut(taskDTO.Tasks.Select(x=>x.ContainerCode).ToList());
- TasksItem? tasksItem = taskDTO.Tasks.FirstOrDefault(x => !locationInfos.Select(t => t.PalletCode).Contains(x.ContainerCode));
- if (tasksItem != null) throw new Exception($"浠诲姟{tasksItem.TaskCode}鏂欑鍙穥tasksItem.ContainerCode}涓嶅瓨鍦�");
- Dt_LocationInfo? noOutLocation = locationInfos.FirstOrDefault(x=>x.LocationStatus != LocationStatusEnum.InStock.ObjToInt() || x.EnableStatus != EnableStatusEnum.Normal.ObjToInt());
- if (noOutLocation != null) throw new Exception($"鏂欑{noOutLocation.PalletCode}璐т綅{noOutLocation.LocationCode}鐘舵�佷笉鍙嚭搴�");
+ 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)
+ ////涓嬪彂浠诲姟缁�
+ //string taskGroup= taskDTO.TaskGroupCode.IsNullOrEmpty() ? Guid.NewGuid().ToString().Replace("-","") : taskDTO.TaskGroupCode;
+ foreach (var item in taskDTO.Tasks.OrderBy(x=>x.TaskDescribe.ToStationCode))
{
- if (item.ToStationCode.IsNullOrEmpty()) throw new Exception($"浠诲姟{item.TaskCode}鍑哄簱鐩爣鎿嶄綔鍙颁笉鑳戒负绌�");
+ if (item.TaskDescribe.ToStationCode.IsNullOrEmpty()) throw new Exception($"浠诲姟{item.TaskCode}鍑哄簱鐩爣鎿嶄綔鍙颁笉鑳戒负绌�");
//鑾峰彇鎿嶄綔鍙�
- Dt_StationManger? stationManger = stationMangers.FirstOrDefault(x => x.PickStationCode == item.ToStationCode);
- if (stationManger == null) throw new Exception($"浠诲姟{item.TaskCode}鍑哄簱鐩爣鎿嶄綔鍙皗item.ToStationCode}涓嶅瓨鍦�");
+ 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);
+ if (taskOld != null)
+ {
+ errorMsg += $"鏂欑{taskOld.PalletCode}" + (taskOld.TaskType == TaskTypeEnum.Inbound.ObjToInt() ? "鍏ュ簱浠诲姟宸插瓨鍦�;" : "鍑哄簱浠诲姟宸插瓨鍦�;");
+ content.FailData.Add(new BinCodeObj() { Bincode = item.TaskDescribe.ContainerCode });
+ continue;
+ }
+ Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x => x.PalletCode == item.TaskDescribe.ContainerCode);
+ if (locationInfo == null)
+ {
+ 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)
+ {
+ errorMsg += $"鏂欑{noOutLocation.PalletCode}璐т綅{noOutLocation.LocationCode}鐘舵�佷笉鍙嚭搴�";
+ content.FailData.Add(new BinCodeObj() { Bincode = noOutLocation.PalletCode });
+ continue;
+ }
Dt_Task task = _mapper.Map<Dt_Task>(item);
- Dt_LocationInfo locationInfo = locationInfos.FirstOrDefault(x=>x.PalletCode==item.ContainerCode);
task.SourceAddress = locationInfo.LocationCode;
task.CurrentAddress = locationInfo.LocationCode;
task.NextAddress = stationManger.PickStationCode;
task.TargetAddress = stationManger.PickStationCode;
- task.GroupId = taskGroup;
+ //task.GroupId = taskGroup;
task.TaskType = TaskTypeEnum.Outbound.ObjToInt();
task.Roadway = locationInfo.RoadwayNo;
- task.DeviceCode = "AGV";
+ task.DeviceCode = stationManger.CraneCode;
task.TaskState = TaskStatusEnum.AGV_Execute.ObjToInt();
tasks.Add(task);
+ content.SucessData.Add(new BinCodeObj() { Bincode = item.TaskDescribe.ContainerCode });
}
locationInfos.ForEach(x =>
@@ -140,10 +175,12 @@
BaseDal.AddData(tasks);
_locationInfoRepository.UpdateData(locationInfos);
_unitOfWorkManage.CommitTran();
-
_taskExecuteDetailService.AddTaskExecuteDetail(tasks.Select(x => x.TaskNum).ToList(), "鎺ユ敹WMS浠诲姟");
-
- content = tasks.Count > 0 ? content.OK("鎴愬姛") : content.Error("澶辫触");
+ if (tasks.Count>0)
+ {
+ _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfos, LocationStatusEnum.InStock, LocationStatusEnum.Lock, LocationChangeType.OutboundAssignLocation, tasks);
+ }
+ content.OK(errorMsg.IsNullOrEmpty()? "鎴愬姛": errorMsg);
}
}
catch (Exception ex)
@@ -152,30 +189,324 @@
}
return content;
}
-
+
+ /// <summary>
+ /// 瀹瑰櫒鍏ュ簱鍒涘缓浠诲姟
+ /// </summary>
+ /// <returns></returns>
+ public WebResponseContent ContainerFlow(ContainerFlowDTO containerFlowDTO, string deviceCode, string stationCode, int type = 0)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ List<Dt_LocationInfo> locationInfos = _locationInfoRepository.QueryData();
+ 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)
+ {
+ return content.OK();
+ }
+ if (taskOld != null && taskOld.PalletCode == containerFlowDTO.ContainerCode && taskOld.TaskType == TaskTypeEnum.Inbound.ObjToInt() && taskOld.TaskState == TaskStatusEnum.CL_Executing.ObjToInt() && taskOld.DeviceCode != deviceCode)
+ {
+ Dt_StationManger stationOld = _stationMangerRepository.QueryFirst(x => x.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && x.StationDeviceCode == deviceCode);
+ string oldSlotCode = taskOld.SourceAddress;
+ taskOld.SourceAddress = containerFlowDTO.SlotCode;
+ taskOld.CurrentAddress = containerFlowDTO.SlotCode;
+ taskOld.NextAddress = stationOld.StationCode;
+ taskOld.DeviceCode = stationOld.StationDeviceCode;
+ //鏇存柊浠诲姟
+ BaseDal.UpdateData(taskOld);
+ _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { taskOld.TaskNum }, $"{oldSlotCode}鎹㈣嚦{containerFlowDTO.SlotCode}鍏ュ簱");
+ return content.OK();
+ }
+ else if(taskOld != null)
+ {
+ throw new Exception($"鏂欑鍙穥containerFlowDTO.ContainerCode}" + (taskOld.TaskType == TaskTypeEnum.Inbound.ObjToInt() ? "鍏ュ簱AGV鎵ц涓�": "鍑哄簱AGV鎵ц涓�"));
+ }
+ Dt_LocationInfo? noInLocation = locationInfos.FirstOrDefault(x => x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt());
+ if (noInLocation == null) throw new Exception($"鍙敤璐т綅涓嶈冻!");
+ Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && x.StationDeviceCode == deviceCode);
+ //鍒涘缓浠诲姟
+ Dt_Task task = new Dt_Task();
+ task.PalletCode = containerFlowDTO.ContainerCode;
+ task.SourceAddress = containerFlowDTO.SlotCode;
+ task.CurrentAddress = containerFlowDTO.SlotCode;
+ task.NextAddress = stationManger.StationCode;
+ task.TargetAddress = "";
+ task.WMSId = "";
+ task.TaskType = TaskTypeEnum.Inbound.ObjToInt();
+ task.Roadway = noInLocation.RoadwayNo;
+ task.DeviceCode = stationManger.StationDeviceCode;
+ task.TaskState = TaskStatusEnum.CL_Executing.ObjToInt();
+
+ //娣诲姞浠诲姟
+ BaseDal.AddData(task);
+ if (type > 0)
+ {
+ _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { task.TaskNum }, "鎵嬪姩鎸夐挳鍏ュ簱");
+ }
+ else
+ {
+ _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { task.TaskNum }, "鍒涘缓鍏ュ簱浠诲姟");
+ }
+ content.OK("鎴愬姛");
+ }
+ catch (Exception ex)
+ {
+ content.Error($"閿欒淇℃伅:{ex.Message}");
+ }
+ return content;
+ }
+ /// <summary>
+ /// 鎾澧欏垵濮嬪寲
+ /// </summary>
+ /// <returns></returns>
+ public WebResponseContent InitLight()
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ EPLightContent lightContent = INITIALIZATION();
+ if (lightContent.Result != "0") throw new Exception($"{lightContent.Msg}");
+ content.OK();
+ }
+ catch (Exception ex)
+ {
+ content.Error(ex.Message);
+ }
+ return content;
+ }
+ /// <summary>
+ /// 缁撴潫浣滀笟
+ /// </summary>
+ /// <returns></returns>
+ public WebResponseContent EndLight()
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ EPLightContent lightContent = ENDWORK();
+ if (lightContent.Result != "0") throw new Exception($"{lightContent.Msg}");
+ content.OK();
+ }
+ catch (Exception ex)
+ {
+ content.Error(ex.Message);
+ }
+ return content;
+ }
+ /// <summary>
+ /// 涓�鏈熸挱绉嶅涓嬪彂
+ /// </summary>
+ /// <returns></returns>
+ public EPLightContent Phase1PickOrderInfoRequest(List<EPLightSendDTO> lightSendDTOs)
+ {
+ EPLightContent content = new EPLightContent();
+
+ try
+ {
+ string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.Phase1PickOrderInfoRequest.ToString())?.ApiAddress;
+ if (string.IsNullOrEmpty(url))
+ {
+ return content.Error("鏈壘鍒版挱绉嶅涓嬪彂鎺ュ彛锛岃妫�鏌ユ帴鍙i厤缃�");
+ }
+
+ bool allSuccess = true;
+ StringBuilder errorMessages = new StringBuilder();
+
+ foreach (EPLightSendDTO lightSendDTO in lightSendDTOs)
+ {
+ try
+ {
+ bool operationResult;
+
+ // 澶勭悊鐏厜绫诲瀷杞崲
+ if (!int.TryParse(lightSendDTO.LIGHTTYPE, out int lightType))
+ {
+ allSuccess = false;
+ errorMessages.AppendLine($"浣嶇疆 {lightSendDTO.LOCATION} 閿欒: 鏃犳晥鐨勭伅鍏夌被鍨� '{lightSendDTO.LIGHTTYPE}'");
+ continue;
+ }
+
+ // 澶勭悊鍏抽棴鐏厜璇锋眰
+ if (lightType == 2)
+ {
+ operationResult = RYB_PTL.RYB_PTL_CloseDigit5(url, lightSendDTO.LOCATION);
+ // TODO: 鍏抽棴鐏厜鍥炶皟澶勭悊
+ //List<EPLightBackDTO> lightBackDTOs = new List<EPLightBackDTO>();
+ //List<TaskBackLight> taskBackLights = lightSendDTOs.Select(x => new TaskBackLight()
+ //{
+ // TagNo = "B1",
+ // TagCode = x.LOCATION,
+ //}).ToList();
+ //content = WMSLightBack(taskBackLights);
+ }
+ // 澶勭悊鏄剧ず鐏厜璇锋眰
+ else
+ {
+ // 澶勭悊鐏厜棰滆壊杞崲
+ if (!int.TryParse(lightSendDTO.LIGHTCOLOR, out int lightColor))
+ {
+ allSuccess = false;
+ errorMessages.AppendLine($"浣嶇疆 {lightSendDTO.LOCATION} 閿欒: 鏃犳晥鐨勭伅鍏夐鑹� '{lightSendDTO.LIGHTCOLOR}'");
+ continue;
+ }
+
+ operationResult = RYB_PTL.RYB_PTL_DspDigit5(
+ url,
+
+ lightSendDTO.LOCATION,
+ lightSendDTO.QUANTITY,
+ lightType,
+ lightColor);
+ }
+ if (!operationResult)
+ {
+ allSuccess = false;
+ errorMessages.AppendLine($"浣嶇疆 {lightSendDTO.LOCATION} 鎿嶄綔澶辫触");
+ }
+ }
+
+ catch (Exception ex)
+ {
+ allSuccess = false;
+ errorMessages.AppendLine($"浣嶇疆 {lightSendDTO.LOCATION} 澶勭悊寮傚父: {ex.Message}");
+ }
+ }
+
+ return allSuccess
+ ? content.OK("鎵�鏈夋挱绉嶅涓嬪彂鎿嶄綔鎴愬姛")
+ : content.Error(errorMessages.ToString());
+ }
+ catch (Exception ex)
+ {
+ content.Error(ex.Message);
+ }
+ return content;
+ }
+ /// <summary>
+ /// 鎾澧欎寒鐏�
+ /// </summary>
+ /// <returns></returns>
+ public WebResponseContent SendLight(TaskSendLight taskSendLight)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ if (taskSendLight.TagNo == "B1")
+ {
+ List<EPLightSendDTO> lightSendDTOs = new List<EPLightSendDTO>()
+ {
+ new EPLightSendDTO
+ {
+ DOCNO = taskSendLight.DocNo,
+ TASKNO= taskSendLight.TaskNo,
+ LOCATION=taskSendLight.TagCode,
+ QUANTITY=taskSendLight.TagQunity,
+ LIGHTCOLOR=taskSendLight.Color switch
+ {
+ "Blue" => "4",
+ "Green" => "2",
+ "Red" => "1",
+ _ => throw new Exception($"鏈壘鍒伴鑹插畾涔�")
+ },
+ ORDERTYPE="1",
+ LIGHTTYPE=taskSendLight.Mode.ToString(),
+ }
+ };
+ EPLightContent pLightContent = Phase1PickOrderInfoRequest(lightSendDTOs);
+ if (pLightContent.Result != "0") throw new Exception($"{pLightContent.Msg}");
+ content.OK();
+ }
+ else if (taskSendLight.TagNo == "B2")
+ {
+ List<EPLightSendDTO> lightSendDTOs = new List<EPLightSendDTO>()
+ {
+ new EPLightSendDTO
+ {
+ DOCNO = taskSendLight.DocNo,
+ TASKNO= taskSendLight.TaskNo,
+ LOCATION=taskSendLight.TagCode,
+ QUANTITY=taskSendLight.TagQunity,
+ LIGHTCOLOR=taskSendLight.Color switch
+ {
+ "Blue" => "1",
+ "Green" => "2",
+ "Red" => "4",
+ _ => throw new Exception($"鏈壘鍒伴鑹插畾涔�")
+ },
+ ORDERTYPE="1",
+ LIGHTTYPE=taskSendLight.Mode.ToString(),
+ }
+ };
+ EPLightContent pLightContent = PickOrderInfoRequest(lightSendDTOs);
+ if (pLightContent.Result != "0") throw new Exception($"{pLightContent.Msg}");
+ content.OK();
+ }
+ else
+ {
+ content.OK();
+ }
+
+ }
+ catch (Exception ex)
+ {
+ content.Error(ex.Message);
+ }
+ return content;
+ }
+ static object lock_requestInTask = new object();
+ /// <summary>
+ /// 鐢宠鍏ュ簱
+ /// </summary>
+ /// <returns></returns>
+ 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());
+ if (task == null) throw new Exception($"{barCode}鏂欑鏈壘鍒颁换鍔�!");
+ Dt_LocationInfo? locationInfo = _locationInfoService.AssignLocation();
+ if (locationInfo == null) throw new Exception($"鍙敤璐т綅涓嶈冻!");
+ task.NextAddress = locationInfo.LocationCode;
+ task.TargetAddress = locationInfo.LocationCode;
+ task.CurrentAddress = stationCode;
+ task.DeviceCode = "AGV";
+ task.TaskState = TaskStatusEnum.AGV_Execute.ObjToInt();
+ locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
+ //鏇存柊浠诲姟鍜岃揣浣嶆暟鎹�
+ _unitOfWorkManage.BeginTran();
+ BaseDal.UpdateData(task);
+ _locationInfoRepository.UpdateData(locationInfo);
+ _unitOfWorkManage.CommitTran();
+ _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { task.TaskNum }, $"鍒嗛厤璐т綅{locationInfo.LocationCode}");
+ _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, LocationStatusEnum.Free, LocationStatusEnum.Lock, LocationChangeType.InboundAssignLocation, task.TaskNum);
+ content.OK("鎴愬姛");
+ }
+ }
+ catch (Exception ex)
+ {
+ _unitOfWorkManage.RollbackTran();
+ content.Error($"閿欒淇℃伅:{ex.Message}");
+ }
+ return content;
+ }
+
public static string Post(string serviceAddress, string requestJson = "", string contentType = "application/json", Dictionary<string, string>? headers = null)
{
string result = string.Empty;
DateTime beginDate = DateTime.Now;
try
{
- using (HttpContent httpContent = new StringContent(requestJson))
+ using (HttpContent httpContent = new StringContent(string.Empty))
{
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
-
using HttpClient httpClient = new HttpClient();
httpClient.Timeout = new TimeSpan(0, 0, 30);
- string LoginToken = AppSettings.Get("MESLoginToken");
- headers = new Dictionary<string, string>
- {
- //姝e紡
- { "LoginToken", LoginToken }
- };
- if (headers != null)
- {
- foreach (var header in headers)
- httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
- }
HttpResponseMessage responseMessage = httpClient.PostAsync(serviceAddress, httpContent).Result;
result = responseMessage.Content.ReadAsStringAsync().Result;
}
@@ -208,7 +539,7 @@
task.ModifyDate = DateTime.Now;
BaseDal.UpdateData(task);
- _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, task.ExceptionMessage);
+ _taskExecuteDetailService.AddTaskExecuteDetail(task, task.ExceptionMessage);
content = WebResponseContent.Instance.OK();
}
@@ -250,7 +581,7 @@
BaseDal.UpdateData(task);
- _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"浜哄伐鎭㈠鎸傝捣浠诲姟,鎭㈠鎸傝捣鏃朵换鍔$姸鎬併�恵task.TaskState}銆�");
+ _taskExecuteDetailService.AddTaskExecuteDetail(task, $"浜哄伐鎭㈠鎸傝捣浠诲姟,鎭㈠鎸傝捣鏃朵换鍔$姸鎬併�恵task.TaskState}銆�");
content = WebResponseContent.Instance.OK();
}
@@ -291,7 +622,7 @@
BaseDal.UpdateData(task);
- _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"浜哄伐灏嗕换鍔$姸鎬佷粠銆恵oldState}銆戝洖婊氬埌銆恵task.TaskState}銆�");
+ _taskExecuteDetailService.AddTaskExecuteDetail(task, $"浜哄伐灏嗕换鍔$姸鎬佷粠銆恵oldState}銆戝洖婊氬埌銆恵task.TaskState}銆�");
content = WebResponseContent.Instance.OK();
}
@@ -339,7 +670,7 @@
AgvTaskFlowDTO agvTaskFlowDTO = new AgvTaskFlowDTO()
{
RequestId = Guid.NewGuid().ToString().Replace("-", ""),
- ContainerCode = code
+ MissionCode = code
};
string request = JsonConvert.SerializeObject(agvTaskFlowDTO, settings);
string response = HttpHelper.Post(url, request);
@@ -392,7 +723,7 @@
try
{
Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
- if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)//鍑哄簱浠诲姟閫昏緫
+ if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)//鍑哄簱浠诲姟瀹屾垚閫昏緫
{
Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x=>x.PalletCode==task.PalletCode);
if (locationInfo.LocationStatus != LocationStatusEnum.Lock.ObjToInt())
@@ -402,32 +733,70 @@
task.TaskState = TaskStatusEnum.Finish.ObjToInt();
locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
locationInfo.PalletCode = "";
+ //鏂欑鍑哄簱瀹屾垚涓婃姤缁橶MS
+ string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSInOutBoundBack.ToString())?.ApiAddress;
+ if (string.IsNullOrEmpty(url))
+ {
+ _taskExecuteDetailService.AddTaskExecuteDetail(task, $"鏈壘鍒癢MS鍑哄簱涓婃姤鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
+ UpdateTaskExceptionMessage(taskNum, $"鏈壘鍒癢MS鍑哄簱涓婃姤鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
+ return content.Error($"{taskNum},鏈壘鍒癢MS鍑哄簱涓婃姤鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
+ }
+ ContainerInFinishDTO containerInFinishDTO = new ContainerInFinishDTO()
+ {
+ TaskCode = task.TaskNum.ToString(),
+ ContainerCode = task.PalletCode,
+ StationCode = task.TargetAddress,
+ LocationCode = task.SourceAddress,
+ CompleteType = 1
+ };
+ string request = JsonConvert.SerializeObject(containerInFinishDTO, settings);
+
_unitOfWorkManage.BeginTran();
_locationInfoRepository.UpdateData(locationInfo);
BaseDal.DeleteAndMoveIntoHty(task, App.User?.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
_unitOfWorkManage.CommitTran();
+ _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, LocationStatusEnum.Lock, LocationStatusEnum.Free, LocationChangeType.OutboundCompleted, task.TaskNum);
+ //璋冪敤鎺ュ彛
+ string response = HttpHelper.Post(url, request);
+ WMSResponseContent wMSResponse = JsonConvert.DeserializeObject<WMSResponseContent>(response) ?? throw new Exception($"{taskNum},鏈帴鏀跺埌WMS鍑哄簱涓婃姤杩斿洖鍊�");
+ 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.WMSInBoundBack.ToString())?.ApiAddress;
+ string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSInOutBoundBack.ToString())?.ApiAddress;
if (string.IsNullOrEmpty(url))
{
- _taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"鏈壘鍒癢MS鍏ュ簱涓婃姤鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
+ _taskExecuteDetailService.AddTaskExecuteDetail(task, $"鏈壘鍒癢MS鍏ュ簱涓婃姤鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
UpdateTaskExceptionMessage(taskNum, $"鏈壘鍒癢MS鍏ュ簱涓婃姤鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
return content.Error($"{taskNum},鏈壘鍒癢MS鍏ュ簱涓婃姤鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
}
ContainerInFinishDTO containerInFinishDTO = new ContainerInFinishDTO()
{
- TaskCode= task.TaskNum.ToString(),
+ TaskCode = task.TaskNum.ToString(),
ContainerCode = task.PalletCode,
- FromStationCode = task.SourceAddress,
- ToLocationCode = task.TargetAddress
+ StationCode = task.SourceAddress,
+ LocationCode = task.TargetAddress,
+ CompleteType = 2
};
string request = JsonConvert.SerializeObject(containerInFinishDTO, settings);
+
+ Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+ if (locationInfo.LocationStatus != LocationStatusEnum.Lock.ObjToInt())
+ {
+ return content.Error($"{locationInfo.LocationCode}璐т綅鐘舵�佷笉姝g‘");
+ }
+ task.TaskState = TaskStatusEnum.Finish.ObjToInt();
+ locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+ locationInfo.PalletCode = task.PalletCode;
+ _unitOfWorkManage.BeginTran();
+ _locationInfoRepository.UpdateData(locationInfo);
+ BaseDal.DeleteAndMoveIntoHty(task, App.User?.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
+ _unitOfWorkManage.CommitTran();
+ _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, LocationStatusEnum.Lock, LocationStatusEnum.InStock, LocationChangeType.InboundCompleted, task.TaskNum);
//璋冪敤鎺ュ彛
string response = HttpHelper.Post(url, request);
- WMSResponseContent wMSResponse = JsonConvert.DeserializeObject<WMSResponseContent>(response) ??throw new Exception($"{taskNum},鏈帴鏀跺埌WMS鍏ュ簱涓婃姤杩斿洖鍊�");
- if (wMSResponse.Code!="0") throw new Exception($"鍏ュ簱浠诲姟{task.TaskNum}WMS鍏ュ簱涓婃姤閿欒,淇℃伅:{wMSResponse.Msg}");
+ WMSResponseContent wMSResponse = JsonConvert.DeserializeObject<WMSResponseContent>(response) ?? throw new Exception($"{taskNum},鏈帴鏀跺埌WMS鍏ュ簱涓婃姤杩斿洖鍊�");
+ if (wMSResponse.Code != "0") content.Message = $"鍏ュ簱浠诲姟{task.TaskNum}WMS鍏ュ簱涓婃姤閿欒,淇℃伅:{wMSResponse.Msg}";
}
content.OK("浠诲姟瀹屾垚");
}
@@ -438,5 +807,163 @@
}
return content;
}
+ /// <summary>
+ /// 浜屾湡鎾澧欏洖浼�
+ /// </summary>
+ /// <returns></returns>
+ public EPLightContent WMSLightBack(List<TaskBackLight> taskBackLights)
+ {
+ EPLightContent content = new EPLightContent();
+ try
+ {
+ string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSLightBack.ToString())?.ApiAddress;
+ if (string.IsNullOrEmpty(url))
+ {
+ return content.Error($"鏈壘鍒版挱绉嶅涓婃姤,璇锋鏌ユ帴鍙i厤缃�");
+ }
+ string request = JsonConvert.SerializeObject(taskBackLights, settings);
+ string response = HttpHelper.Post(url, request);
+ WMSResponseContent wMSResponse = JsonConvert.DeserializeObject<WMSResponseContent>(response) ?? throw new Exception($"鏈帴鏀跺埌鎾澧欎笂鎶ヨ繑鍥炲��");
+ if (wMSResponse.Code != "0") throw new Exception($"鎾澧欎笂鎶ラ敊璇�,淇℃伅:{wMSResponse.Msg}");
+ content.OK();
+ }
+ catch (Exception ex)
+ {
+ content.Error(ex.Message);
+ }
+ return content;
+ }
+ /// <summary>
+ /// 浜屾湡鎾澧欎笅鍙�
+ /// </summary>
+ /// <returns></returns>
+ public EPLightContent PickOrderInfoRequest(List<EPLightSendDTO> lightSendDTOs)
+ {
+ EPLightContent content = new EPLightContent();
+ try
+ {
+ string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.PickOrderInfoRequest.ToString())?.ApiAddress;
+ if (string.IsNullOrEmpty(url))
+ {
+ return content.Error($"鏈壘鍒版挱绉嶅涓嬪彂鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
+ }
+ string request = JsonConvert.SerializeObject(lightSendDTOs, settings).ToUpper();
+ // 璋冪敤鎺ュ彛
+ string response = HttpHelper.Post(url, request);
+ EPLightContent lightContent = JsonConvert.DeserializeObject<EPLightContent>(response) ?? throw new Exception($"鏈帴鏀跺埌鎾澧欎笅鍙戜笂鎶ヨ繑鍥炲��");
+ if (lightContent.Result != "0") throw new Exception($"鎾澧欎笅鍙戦敊璇�,淇℃伅:{lightContent.Msg}");
+ content.OK("鎴愬姛");
+ }
+ catch (Exception ex)
+ {
+ content.Error(ex.Message);
+ }
+ return content;
+ }
+ /// <summary>
+ /// 浜屾湡鎾澧欏垵濮嬪寲
+ /// </summary>
+ /// <param name="taskNum"></param>
+ /// <returns></returns>
+ public EPLightContent INITIALIZATION()
+ {
+ EPLightContent content = new EPLightContent();
+ try
+ {
+ string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.INITIALIZATION.ToString())?.ApiAddress;
+ if (string.IsNullOrEmpty(url))
+ {
+ return content.Error($"鏈壘鍒版挱绉嶅鍒濆鍖栨帴鍙�,璇锋鏌ユ帴鍙i厤缃�");
+ }
+ //璋冪敤鎺ュ彛
+ string response = Post(url);
+ EPLightContent lightContent = JsonConvert.DeserializeObject<EPLightContent>(response) ?? throw new Exception($"鏈帴鏀跺埌鎾澧欏垵濮嬪寲涓婃姤杩斿洖鍊�");
+ if (lightContent.Result != "0") throw new Exception($"鎾澧欏垵濮嬪寲閿欒,淇℃伅:{lightContent.Msg}");
+ content.OK("鎴愬姛");
+ }
+ catch (Exception ex)
+ {
+ content.Error(ex.Message);
+ }
+ return content;
+ }
+ /// <summary>
+ /// 浜屾湡鎾澧欑粨鏉熶綔涓�
+ /// </summary>
+ /// <param name="taskNum"></param>
+ /// <returns></returns>
+ public EPLightContent ENDWORK()
+ {
+ EPLightContent content = new EPLightContent();
+ try
+ {
+ string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.ENDWORK.ToString())?.ApiAddress;
+ if (string.IsNullOrEmpty(url))
+ {
+ return content.Error($"鏈壘鍒版挱绉嶅缁撴潫浣滀笟鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
+ }
+ //璋冪敤鎺ュ彛
+ string response = Post(url);
+ EPLightContent lightContent = JsonConvert.DeserializeObject<EPLightContent>(response) ?? throw new Exception($"鏈帴鏀跺埌鎾澧欑粨鏉熶綔涓氫笂鎶ヨ繑鍥炲��");
+ if (lightContent.Result != "0") throw new Exception($"鎾澧欑粨鏉熶綔涓氶敊璇�,淇℃伅:{lightContent.Msg}");
+ content.OK("鎴愬姛");
+ }
+ catch (Exception ex)
+ {
+ content.Error(ex.Message);
+ }
+ return content;
+ }
+ public override WebResponseContent Export(PageDataOptions options)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ string savePath = AppDomain.CurrentDomain.BaseDirectory + "ExcelExport";
+
+ // 纭繚鐩綍瀛樺湪
+ if (!Directory.Exists(savePath))
+ Directory.CreateDirectory(savePath);
+
+ // 鑾峰彇鏁版嵁
+ ISugarQueryable<Dt_Task> query = BaseDal.Db.Queryable<Dt_Task>();
+ var dataList = query.ToList();
+ var properties = typeof(Dt_Task).GetProperties();
+
+ string filePath = TExportHelper.GetExport(savePath, properties, dataList);
+ return WebResponseContent.Instance.OK(data: filePath);
+ }
+ catch (Exception ex)
+ {
+ content = WebResponseContent.Instance.Error(ex.Message);
+ }
+ return content;
+ }
+ /// <summary>
+ /// 閲嶇疆鎵�鏈夊紓甯镐换鍔�
+ /// </summary>
+ public WebResponseContent ResetAllExceptionTask(int taskNum)
+ {
+ // 鑾峰彇寮傚父浠诲姟990淇敼涓篈GV寰呮墽琛�300
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
+ if (task == null) return WebResponseContent.Instance.Error($"鏈壘鍒拌浠诲姟淇℃伅,浠诲姟鍙�:銆恵taskNum}銆�");
+ if (task.TaskState != (int)TaskStatusEnum.Exception)
+ {
+ return content = WebResponseContent.Instance.Error($"璇ヤ换鍔$姸鎬佷笉鍙噸缃�,浠诲姟鍙�:銆恵taskNum}銆�,浠诲姟鐘舵��:銆恵task.TaskState}銆�");
+ }
+ task.TaskState = (int)TaskStatusEnum.AGV_Execute;
+ BaseDal.UpdateData(task);
+ //_taskExecuteDetailService.AddTaskExecuteDetail(task, $"浜哄伐閲嶇疆寮傚父浠诲姟,閲嶇疆鍚庝换鍔$姸鎬併�恵task.TaskState}銆�");
+ content = WebResponseContent.Instance.OK();
+ }
+ catch (Exception ex)
+ {
+ content.Error(ex.Message);
+ }
+ return content;
+ }
}
}
--
Gitblit v1.9.3