From c3877b2ebec19f473f45e8c2245926f65d2a3948 Mon Sep 17 00:00:00 2001 From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com> Date: 星期三, 10 九月 2025 09:26:23 +0800 Subject: [PATCH] 代码提交 --- 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs | 852 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 829 insertions(+), 23 deletions(-) diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs" index e75b7ac..a1698a9 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs" @@ -1,7 +1,13 @@ -锘縰sing AngleSharp.Io; +锘縰sing AngleSharp.Dom; +using AngleSharp.Io; using Mapster; using Masuit.Tools; +using Microsoft.AspNetCore.Mvc; +using Microsoft.IdentityModel.Tokens; +using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; using SqlSugar; +using System.ComponentModel.Design; +using System.Linq.Expressions; using System.Net.NetworkInformation; using System.Reflection; using System.Text; @@ -19,6 +25,7 @@ using WIDESEA_StorageSocketServices; using WIDESEA_StorageTaskRepository; using WIDESEAWCS_BasicInfoRepository; +using WIDESEAWCS_BasicInfoService; using WIDESEAWCS_Model.Models; namespace WIDESEA_StorageTaskServices; @@ -28,28 +35,500 @@ private readonly LogFactory LogFactory = new LogFactory(); private readonly IUnitOfWorkManage _unitOfWorkManage; private readonly IStockInfoRepository _stockInfoRepository; + private readonly IDt_StationManagerRepository _stationManagerRepository; + private readonly IDt_StationManagerService _stationManagerService; private readonly IDt_Task_HtyRepository _task_HtyRepository; private readonly IMapper _mapper; private readonly ILocationInfoRepository _locationRepository; - + private readonly IDt_HandAutomaticRepository _handAutomaticRepository; + private readonly IDt_HostErrorMessageRepository _errorMessageRepository; + public Dt_TaskService(IDt_TaskRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IStockInfoRepository stockInfoRepository, IDt_Task_HtyRepository task_HtyRepository, IMapper mapper, ILocationInfoRepository locationRepository, - IStockInfoDetailRepository stockInfoDetailRepository) : base(BaseDal) + IStockInfoDetailRepository stockInfoDetailRepository, + IDt_StationManagerRepository stationManagerRepository, + IDt_HandAutomaticRepository handAutomaticRepository, + IDt_StationManagerService stationManagerService, + IDt_HostErrorMessageRepository errorMessageRepository) : base(BaseDal) { _unitOfWorkManage = unitOfWorkManage; _stockInfoRepository = stockInfoRepository; _task_HtyRepository = task_HtyRepository; _mapper = mapper; _locationRepository = locationRepository; + _stationManagerRepository = stationManagerRepository; + _handAutomaticRepository = handAutomaticRepository; + _stationManagerService = stationManagerService; + _errorMessageRepository = errorMessageRepository; } - + #region 澶栭儴鎺ュ彛鏂规硶 + public WebResponseContent InboundTask(TaskDTO taskDTO) + { + WebResponseContent content = new WebResponseContent(); + try + { + //var HandAutomatic = _handAutomaticRepository.QueryFirst(x => true && x.HandAutomatic == "Automatic"); + //if (HandAutomatic != null) + //{ + // return content.Error("褰撳墠涓嶆槸鎵嬪姩妯″紡"); + //} + var station = _stationManagerRepository.QueryFirst(x => x.HostName == taskDTO.SourceAddress && x.stationType == 1); + if (station == null) + { + return content.Error("鏈壘鍒板叆搴撶珯鍙颁俊鎭�"); + } + Dt_Task task = BaseDal.QueryFirst(x => x.PalletCode == taskDTO.PalletCode); + if (task != null) + { + return content.Error("璇ユ墭鐩樺凡瀛樺湪浠诲姟"); + } + var location = GetLocation(); + Dt_Task taskNew = new Dt_Task() + { + TaskNum = BaseDal.GetTaskNo().Result, + PalletCode = taskDTO.PalletCode, + Dispatchertime = DateTime.Now, + Grade = 1, + SeqNo = Convert.ToInt32(0), + CommandID = Convert.ToInt32(0), + SourceAddress = station.stationName, + TargetAddress = location.LocationCode, + CurrentAddress = station.stationName, + NextAddress = location.LocationCode, + TaskType = (int)TaskInboundTypeEnum.Inbound, + TaskState = (int)TaskInStatusEnum.InNew, + Roadway = "PDA", + }; + task_call task_Call = new task_call() + { + d_task_type = "32" , + d_floor = "1", + d_involed1 = taskNew.SourceAddress, + d_involed2 = InsertHyphenEveryTwoChars(taskNew.TargetAddress), + d_involed5 = taskNew.TaskNum.ToString(), + }; + location.LocationStatus = (int)LocationEnum.Lock; + _locationRepository.UpdateData(location); + BaseDal.AddData(taskNew); + var x = SqlSugarHelper.DbAGV.Insertable(task_Call).ExecuteCommand(); + LogFactory.GetLog("鎻掑叆鏁版嵁鍒癆GV").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(x)}", ""); + LogFactory.GetLog("PDA").InfoFormat(true, $"InboundTask璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(taskDTO)}{Environment.NewLine}", ""); + return content.OK("鍏ュ簱浠诲姟涓嬪彂鎴愬姛锛�"); + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + + public WebResponseContent SamplingInboundTask(TaskDTO taskDTO) + { + WebResponseContent content = new WebResponseContent(); + try + { + //var HandAutomatic = _handAutomaticRepository.QueryFirst(x => true && x.HandAutomatic == "Automatic"); + //if (HandAutomatic != null) + //{ + // return content.Error("褰撳墠涓嶆槸鎵嬪姩妯″紡"); + //} + var station = _stationManagerRepository.QueryFirst(x => x.HostName == taskDTO.SourceAddress && x.stationType == 1); + if (station == null) + { + return content.Error("鏈壘鍒板叆搴撶珯鍙颁俊鎭�"); + } + Dt_Task task = BaseDal.QueryFirst(x => x.PalletCode == taskDTO.PalletCode); + if (task != null) + { + return content.Error("璇ユ墭鐩樺凡瀛樺湪浠诲姟"); + } + var stock = _stockInfoRepository.QueryFirst(x => x.PalletCode == taskDTO.PalletCode); + if (stock == null) + { + return content.Error("璇ユ墭鐩樺簱瀛樹笉瀛樺湪"); + } + var location = _locationRepository.QueryFirst(x => x.LocationCode == stock.LocationCode); + + Dt_Task taskNew = new Dt_Task() + { + TaskNum = BaseDal.GetTaskNo().Result, + PalletCode = taskDTO.PalletCode, + Dispatchertime = DateTime.Now, + Grade = 1, + SeqNo = Convert.ToInt32(0), + CommandID = Convert.ToInt32(0), + SourceAddress = station.stationName, + TargetAddress = stock.LocationCode, + CurrentAddress = station.stationName, + NextAddress = stock.LocationCode, + TaskType = (int)TaskInboundTypeEnum.InQuality, + TaskState = (int)TaskInStatusEnum.InNew, + Roadway = "PDA", + }; + task_call task_Call = new task_call() + { + d_task_type = "32", + d_floor = "1", + d_involed1 = taskNew.SourceAddress, + d_involed2 = InsertHyphenEveryTwoChars(taskNew.TargetAddress), + d_involed5 = taskNew.TaskNum.ToString(), + }; + location.LocationStatus = (int)LocationEnum.Lock; + _locationRepository.UpdateData(location); + BaseDal.AddData(taskNew); + var x = SqlSugarHelper.DbAGV.Insertable(task_Call).ExecuteCommand(); + LogFactory.GetLog("鎻掑叆鏁版嵁鍒癆GV").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(x)}", ""); + LogFactory.GetLog("PDA").InfoFormat(true, $"SamplingInboundTask璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(taskDTO)}{Environment.NewLine}", ""); + return content.OK("鎶芥鍏ュ簱浠诲姟涓嬪彂鎴愬姛锛�"); + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + public WebResponseContent OutboundTask(TaskDTO taskDTO) + { + WebResponseContent content = new WebResponseContent(); + try + { + StationStatus stationOut = _stationManagerService.GetStationStatus("B001"); + if (stationOut == null) + { + return content.Error("鑾峰彇鍑哄簱绔欏彴淇℃伅澶辫触锛岃閲嶆柊鍑哄簱"); + } + Dt_StationManager station; + if (stationOut.WorkstationO == "0") + { + var hasTaskOne = BaseDal.QueryFirst(x => x.TargetAddress == "B001::1"); + if (hasTaskOne == null) + { + station = _stationManagerRepository.QueryFirst(x => x.stationName == "B001::1" && x.stationType == 2); + } + else + { + if (stationOut.WorkstationT == "0") + { + var hasTaskTwo = BaseDal.QueryFirst(x => x.TargetAddress == "B001::2"); + if (hasTaskTwo == null) + { + station = _stationManagerRepository.QueryFirst(x => x.stationName == "B001::2" && x.stationType == 2); + } + else + { + return content.Error("鏈壘鍒板彲鐢ㄧ珯鍙帮紝璇锋煡鐪嬬珯鍙版槸鍚﹀瓨鍦ㄤ换鍔�"); + } + } + else + { + return content.Error("鍑哄簱绔欏彴鐘舵�佷笉鏄┖闂诧紝璇风‘璁ゅ啀涓嬪彂鍑哄簱浠诲姟"); + } + } + + } + else if (stationOut.WorkstationT == "0") + { + var hasTaskOne = BaseDal.QueryFirst(x => x.TargetAddress == "B001::2"); + if (hasTaskOne == null) + { + station = _stationManagerRepository.QueryFirst(x => x.stationName == "B001::2" && x.stationType == 2); + } + else + { + return content.Error("鏈壘鍒板彲鐢ㄧ珯鍙帮紝璇锋煡鐪嬬珯鍙版槸鍚﹀瓨鍦ㄤ换鍔�"); + } + } + else + { + return content.Error("鍑哄簱绔欏彴鐘舵�佷笉鏄┖闂诧紝璇风‘璁ゅ啀涓嬪彂鍑哄簱浠诲姟"); + } + //if (station == null) + //{ + // return content.Error("鏈壘鍒板嚭搴撶珯鍙颁俊鎭�"); + //} + + Dt_Task task = BaseDal.QueryFirst(x => x.PalletCode == taskDTO.PalletCode); + if (task != null) + { + return content.Error("璇ユ墭鐩樺凡瀛樺湪浠诲姟"); + } + Dt_Task taskNew = new Dt_Task() + { + TaskNum = BaseDal.GetTaskNo().Result, + PalletCode = taskDTO.PalletCode, + Dispatchertime = DateTime.Now, + Grade = 1, + SeqNo = Convert.ToInt32(0), + CommandID = Convert.ToInt32(0), + SourceAddress = taskDTO.SourceAddress, + TargetAddress = station.stationName, + CurrentAddress = taskDTO.SourceAddress, + NextAddress = station.stationName, + TaskType = (int)TaskOutboundTypeEnum.Outbound, + TaskState = (int)TaskOutStatusEnum.OutNew, + Roadway = "PDA", + }; + task_call task_Call = new task_call() + { + d_task_type = "64", + d_floor = "1", + d_involed1 = InsertHyphenEveryTwoChars(taskNew.SourceAddress), + d_involed2 = taskNew.TargetAddress, + d_involed5 = taskNew.TaskNum.ToString(), + }; + BaseDal.AddData(taskNew); + var x = SqlSugarHelper.DbAGV.Insertable(task_Call).ExecuteCommand(); + LogFactory.GetLog("鎻掑叆鏁版嵁鍒癆GV").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(x)}", ""); + LogFactory.GetLog("PDA").InfoFormat(true, $"OutboundTask璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(taskDTO)}{Environment.NewLine}", ""); + return content.OK("鍑哄簱浠诲姟涓嬪彂鎴愬姛锛�"); + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + public WebResponseContent SamplingOutboundTask(TaskDTO taskDTO) + { + WebResponseContent content = new WebResponseContent(); + try + { + + StationStatus stationOut = _stationManagerService.GetStationStatus("B001"); + if (stationOut == null) + { + return content.Error("鑾峰彇鍑哄簱绔欏彴淇℃伅澶辫触锛岃閲嶆柊鍑哄簱"); + } + Dt_StationManager station; + if (stationOut.WorkstationO == "0") + { + var hasTaskOne = BaseDal.QueryFirst(x => x.TargetAddress == "B001::1"); + if (hasTaskOne == null) + { + station = _stationManagerRepository.QueryFirst(x => x.stationName == "B001::1" && x.stationType == 2); + } + else + { + if (stationOut.WorkstationT == "0") + { + var hasTaskTwo = BaseDal.QueryFirst(x => x.TargetAddress == "B001::2"); + if (hasTaskTwo == null) + { + station = _stationManagerRepository.QueryFirst(x => x.stationName == "B001::2" && x.stationType == 2); + } + else + { + return content.Error("鏈壘鍒板彲鐢ㄧ珯鍙帮紝璇锋煡鐪嬬珯鍙版槸鍚﹀瓨鍦ㄤ换鍔�"); + } + } + else + { + return content.Error("鍑哄簱绔欏彴鐘舵�佷笉鏄┖闂诧紝璇风‘璁ゅ啀涓嬪彂鍑哄簱浠诲姟"); + } + } + + } + else if (stationOut.WorkstationT == "0") + { + var hasTaskOne = BaseDal.QueryFirst(x => x.TargetAddress == "B001::2"); + if (hasTaskOne == null) + { + station = _stationManagerRepository.QueryFirst(x => x.stationName == "B001::2" && x.stationType == 2); + } + else + { + return content.Error("鏈壘鍒板彲鐢ㄧ珯鍙帮紝璇锋煡鐪嬬珯鍙版槸鍚﹀瓨鍦ㄤ换鍔�"); + } + } + else + { + return content.Error("鍑哄簱绔欏彴鐘舵�佷笉鏄┖闂诧紝璇风‘璁ゅ啀涓嬪彂鍑哄簱浠诲姟"); + } + + var stock = _stockInfoRepository.QueryFirst(x => x.LocationCode == taskDTO.SourceAddress); + if (stock == null) + { + return content.Error("璇ュ簱浣嶅簱瀛樹笉瀛樺湪"); + } + Dt_Task task = BaseDal.QueryFirst(x => x.PalletCode == stock.PalletCode); + if (task != null) + { + return content.Error("璇ユ墭鐩樺凡瀛樺湪浠诲姟"); + } + + var location = _locationRepository.QueryFirst(x => x.LocationCode == stock.LocationCode); + if (location.LocationStatus != (int)LocationEnum.InStock) + { + return content.Error("璇ュ簱浣嶄笉鏄湁璐х姸鎬侊紝璇风‘璁ょ姸鎬佸啀涓嬪彂浠诲姟锛�"); + } + station.stationHasTask = "鎶芥鍑哄簱"; + _stationManagerRepository.UpdateData(station); + + Dt_Task taskNew = new Dt_Task() + { + TaskNum = BaseDal.GetTaskNo().Result, + PalletCode = stock.PalletCode, + Dispatchertime = DateTime.Now, + Grade = 1, + SeqNo = Convert.ToInt32(0), + CommandID = Convert.ToInt32(0), + TargetAddress = station.stationName, + SourceAddress = stock.LocationCode, + NextAddress = station.stationName, + CurrentAddress = stock.LocationCode, + TaskType = (int)TaskOutboundTypeEnum.OutQuality, + TaskState = (int)TaskOutStatusEnum.OutNew, + Roadway = "PDA", + }; + task_call task_Call = new task_call() + { + d_task_type = "128", + d_floor = "1", + d_involed1 = InsertHyphenEveryTwoChars(taskNew.SourceAddress), + d_involed2 = taskNew.TargetAddress, + d_involed5 = taskNew.TaskNum.ToString(), + }; + BaseDal.AddData(taskNew); + var x = SqlSugarHelper.DbAGV.Insertable(task_Call).ExecuteCommand(); + LogFactory.GetLog("鎻掑叆鏁版嵁鍒癆GV").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(x)}", ""); + LogFactory.GetLog("PDA").InfoFormat(true, $"SamplingOutboundTask璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(taskDTO)}{Environment.NewLine}", ""); + return content.OK("鎶芥鍑哄簱浠诲姟涓嬪彂鎴愬姛锛�"); + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + + public string InsertHyphenEveryTwoChars(string input) + { + if (string.IsNullOrEmpty(input)) + { + return input; + } + + StringBuilder result = new StringBuilder(); + + for (int i = 0; i < input.Length; i += 2) + { + // 娣诲姞涓や釜瀛楃 + result.Append(input.Substring(i, 2)); + + // 濡傛灉涓嶆槸鏈�鍚庝袱涓瓧绗︼紝娣诲姞涓�涓繛瀛楃 + if (i + 2 < input.Length) + { + result.Append('-'); + } + } + + return result.ToString(); + } + + public DtLocationInfo GetLocation() + { + List<DtLocationInfo> locations = _locationRepository.QueryData(x => x.LocationStatus == (int)LocationEnum.Free); + var location = locations.OrderBy(x => x.Row).ThenBy(x => x.Column).ThenBy(x => x.Layer).FirstOrDefault(); + if(location != null) + { + var task = BaseDal.QueryFirst(x => x.SourceAddress == location.LocationName || x.TargetAddress == location.LocationName); + if(task != null) + { + GetLocation(); + } + } + return location; + } + + public WebResponseContent TaskComplete(int? TaskNum) + { + WebResponseContent content = new WebResponseContent(); + try + { + var task = BaseDal.QueryFirst(x => x.TaskNum == TaskNum); + if (task != null) + { + switch (task.TaskType) + { + case (int)TaskInboundTypeEnum.Inbound: + LogFactory.GetLog("浠诲姟瀹屾垚").InfoFormat(true, "鍏ュ簱浠诲姟", ""); + return CompleteInboundTask(task); + + case (int)TaskOutboundTypeEnum.Outbound: + + LogFactory.GetLog("浠诲姟瀹屾垚").InfoFormat(true, "鍑哄簱浠诲姟", ""); + return CompleteOutboundTask(task); + + case (int)TaskRelocationTypeEnum.Relocation: + return CompleteRelocationboundTask(task); + + case (int)TaskOutboundTypeEnum.OutQuality: + return CompleteSamplingOutboundTask(task); + + case (int)TaskInboundTypeEnum.InQuality: + return CompleteSamplingInboundTask(task); + + default: + return content.Error("浠诲姟绫诲瀷涓嶅瓨鍦�"); + } + } + else + { + return content.Error("鏈壘鍒颁换鍔�"); + } + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + public WebResponseContent TaskStatus(Dt_Task task) + { + WebResponseContent content = new WebResponseContent(); + try + { + if (task != null) + { + switch (task.TaskType) + { + case (int)TaskInboundTypeEnum.Inbound: + case (int)TaskInboundTypeEnum.InQuality: + task.TaskState = (int)TaskInStatusEnum.AGV_InExecuting; + BaseDal.Update(task); + break; + case (int)TaskOutboundTypeEnum.Outbound: + case (int)TaskOutboundTypeEnum.OutQuality: + case (int)TaskStationTypeEnum.StationToStation: + task.TaskState = (int)TaskOutStatusEnum.AGV_OutExecuting; + BaseDal.Update(task); + break; + case (int)TaskRelocationTypeEnum.Relocation: + task.TaskState = (int)TaskRelocationStatusEnum.AGV_RelocationExecuting; + BaseDal.Update(task); + break; + case (int)TaskFireAlarmTypeEnum.FireAlarmOut: + task.TaskState = (int)TaskFireAlarmStatusEnum.AGV_FireAlarmExecuting; + BaseDal.Update(task); + break; + + default: + return content.Error("浠诲姟绫诲瀷涓嶅瓨鍦�"); + } + return content.OK(); + } + else + { + return content.Error("鏈壘鍒颁换鍔�"); + } + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } public WebResponseContent CompleteInboundTask(Dt_Task task) { @@ -57,8 +536,9 @@ try { _unitOfWorkManage.BeginTran(); + task.TaskState = 215; var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); - locationInf.LocationStatus = (int)LocationEnum.InStock; + locationInf.LocationStatus = 2; var stock = new DtStockInfo() { PalletCode = task.PalletCode, @@ -67,15 +547,43 @@ Creater = "system", LocationId = locationInf.Id, }; - _stockInfoRepository.AddData(stock); + SqlSugarHelper.DbWMS.Insertable(stock).ExecuteCommand(); _locationRepository.UpdateData(locationInf); TaskMoveHty(task); _unitOfWorkManage.CommitTran(); + + LogFactory.GetLog("鍏ュ簱浠诲姟瀹屾垚").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(task)}", ""); return content.OK(); } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); + + LogFactory.GetLog("鍏ュ簱浠诲姟瀹屾垚").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(ex.Message)}", ""); + return content.Error(ex.Message); + } + } + + public WebResponseContent CompleteSamplingInboundTask(Dt_Task task) + { + WebResponseContent content = new WebResponseContent(); + try + { + _unitOfWorkManage.BeginTran(); + task.TaskState = 215; + var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); + locationInf.LocationStatus = (int)LocationEnum.InStock; + _locationRepository.UpdateData(locationInf); + TaskMoveHty(task); + _unitOfWorkManage.CommitTran(); + + LogFactory.GetLog("鎶芥鍏ュ簱浠诲姟瀹屾垚").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(task)}", ""); + return content.OK(); + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + LogFactory.GetLog("鎶芥鍏ュ簱浠诲姟瀹屾垚").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(ex.Message)}", ""); return content.Error(ex.Message); } } @@ -86,26 +594,87 @@ try { _unitOfWorkManage.BeginTran(); - var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); - locationInf.LocationStatus = (int)LocationEnum.Free; - var stock = _stockInfoRepository.QueryFirst(x=>x.PalletCode == task.PalletCode); + task.TaskState = 135; - DtStockInfo_Hty stockInfo_Hty = stock.Adapt<DtStockInfo_Hty>(); - stockInfo_Hty.ModifyDate = DateTime.Now; - - AddStockInfoHty(stockInfo_Hty); - - _stockInfoRepository.DeleteData(stock); - _locationRepository.UpdateData(locationInf); + AddStcokHty(task.PalletCode, task.SourceAddress); TaskMoveHty(task); _unitOfWorkManage.CommitTran(); + LogFactory.GetLog("鍑哄簱浠诲姟瀹屾垚").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(task)}", ""); return content.OK(); } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); + LogFactory.GetLog("鍑哄簱浠诲姟瀹屾垚").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(ex.Message)}", ""); + return content.Error(ex.Message); + } + } + + public WebResponseContent CompleteFireAlarmboundTask(Dt_Task task) + { + WebResponseContent content = new WebResponseContent(); + try + { + _unitOfWorkManage.BeginTran(); + task.TaskState = (int)TaskFireAlarmStatusEnum.AGV_FireAlarmFinish; + + AddStcokHty(task.PalletCode,task.SourceAddress); + + TaskMoveHty(task); + _unitOfWorkManage.CommitTran(); + LogFactory.GetLog("鐏鍑哄簱浠诲姟瀹屾垚").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(task)}", ""); + return content.OK(); + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + LogFactory.GetLog("鐏鍑哄簱浠诲姟瀹屾垚").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(ex.Message)}", ""); + return content.Error(ex.Message); + } + } + + public void AddStcokHty(string PalletCode,string Location) + { + //var stock = _stockInfoRepository.QueryFirst(x => x.PalletCode == PalletCode); + var stock = SqlSugarHelper.DbWMS.Queryable<DtStockInfo>().Where(x => x.PalletCode == PalletCode).First(); + if (stock != null) + { + DtStockInfo_Hty stockInfo_Hty = stock.Adapt<DtStockInfo_Hty>(); + stockInfo_Hty.ModifyDate = DateTime.Now; + + AddStockInfoHty(stockInfo_Hty); + + //_stockInfoRepository.DeleteData(stock); + SqlSugarHelper.DbWMS.Deleteable(stock).ExecuteCommand(); + } + var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == Location); + if (locationInf != null) + { + locationInf.LocationStatus = 0; + _locationRepository.UpdateData(locationInf); + } + } + + public WebResponseContent CompleteSamplingOutboundTask(Dt_Task task) + { + WebResponseContent content = new WebResponseContent(); + try + { + _unitOfWorkManage.BeginTran(); + + task.TaskState = 135; + TaskMoveHty(task); + + _unitOfWorkManage.CommitTran(); + LogFactory.GetLog("鎶芥鍑哄簱浠诲姟瀹屾垚").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(task)}", ""); + return content.OK(); + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + LogFactory.GetLog("鎶芥鍑哄簱浠诲姟瀹屾垚").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(ex.Message)}", ""); return content.Error(ex.Message); } } @@ -116,10 +685,11 @@ try { _unitOfWorkManage.BeginTran(); + task.TaskState = 315; var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); var location = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress); - locationInf.LocationStatus = (int)LocationEnum.InStock; - location.LocationStatus = (int)LocationEnum.Free; + locationInf.LocationStatus = 2; + location.LocationStatus = 0; var stock = _stockInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode); @@ -132,12 +702,113 @@ _locationRepository.UpdateData(location); TaskMoveHty(task); _unitOfWorkManage.CommitTran(); + LogFactory.GetLog("绉诲簱浠诲姟瀹屾垚").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(task)}", ""); return content.OK(); } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); + LogFactory.GetLog("绉诲簱浠诲姟瀹屾垚").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(ex.Message)}", ""); return content.Error(ex.Message); + } + } + + public void UpdateTask(string SourceAddress,string TargetAddress, string PalletCode) + { + var task = BaseDal.QueryFirst(x => x.PalletCode == PalletCode); + if (task != null) + { + task.SourceAddress = SourceAddress; + task.TargetAddress = TargetAddress; + BaseDal.UpdateData(task); + InsertAGVTask(task); + } + } + private int InsertAGVTask(Dt_Task task) + { + var AgvTask = SqlSugarHelper.DbAGV.Queryable<task_call>().Where(x => x.d_involed5 == task.TaskNum.ToString()).First(); + if (AgvTask != null) + { + string SourceAddress = string.Empty; + string TargetAddress = string.Empty; + if (task.TaskType == (int)TaskInboundTypeEnum.Inbound) + { + SourceAddress = task.SourceAddress; + TargetAddress = InsertHyphenEveryTwoChars(task.TargetAddress); + } + else if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound) + { + SourceAddress = InsertHyphenEveryTwoChars(task.SourceAddress); + TargetAddress = task.TargetAddress; + } + else if (task.TaskType == (int)TaskRelocationTypeEnum.Relocation) + { + TargetAddress = InsertHyphenEveryTwoChars(task.TargetAddress); + SourceAddress = InsertHyphenEveryTwoChars(task.SourceAddress); + } + else if (task.TaskType == (int)TaskStationTypeEnum.StationToStation) + { + TargetAddress = task.TargetAddress; + SourceAddress = task.SourceAddress; + } + else if (task.TaskType == (int)TaskFireAlarmTypeEnum.FireAlarmOut) + { + TargetAddress = task.TargetAddress; + SourceAddress = task.SourceAddress; + } + + AgvTask.d_involed1 = SourceAddress; + AgvTask.d_involed2 = TargetAddress; + var x = SqlSugarHelper.DbAGV.Updateable(AgvTask).ExecuteCommand(); + LogFactory.GetLog("鎻掑叆鏁版嵁鍒癆GV").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(x)}", ""); + return x; + } + else + { + string SourceAddress = string.Empty; + string TargetAddress = string.Empty; + string AGVType = string.Empty; + if (task.TaskType == (int)TaskInboundTypeEnum.Inbound) + { + SourceAddress = task.SourceAddress; + AGVType = "2"; + TargetAddress = InsertHyphenEveryTwoChars(task.TargetAddress); + } + else if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound) + { + SourceAddress = InsertHyphenEveryTwoChars(task.SourceAddress); + TargetAddress = task.TargetAddress; + AGVType = "4"; + } + else if (task.TaskType == (int)TaskRelocationTypeEnum.Relocation) + { + TargetAddress = InsertHyphenEveryTwoChars(task.TargetAddress); + SourceAddress = InsertHyphenEveryTwoChars(task.SourceAddress); + AGVType = "16"; + } + else if (task.TaskType == (int)TaskStationTypeEnum.StationToStation) + { + TargetAddress = task.TargetAddress; + SourceAddress = task.SourceAddress; + AGVType = "8"; + } + else if (task.TaskType == (int)TaskFireAlarmTypeEnum.FireAlarmOut) + { + TargetAddress = task.TargetAddress; + SourceAddress = task.SourceAddress; + AGVType = "1"; + } + task_call task_Call = new task_call() + { + d_task_type = AGVType, + d_floor = "1", + d_involed1 = SourceAddress, + d_involed2 = TargetAddress, + d_involed5 = task.TaskNum.ToString(), + }; + var x = SqlSugarHelper.DbAGV.Insertable(task_Call).ExecuteCommand(); + LogFactory.GetLog("鎻掑叆鏁版嵁鍒癆GV").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(x)}", ""); + return x; } } public WebResponseContent TaskMoveHty(Dt_Task task) @@ -147,12 +818,15 @@ { _unitOfWorkManage.BeginTran(); var taskHtyNG = CreateHistoricalTask(task); + + var taskNum = task.TaskNum.ToString(); var isTaskHtyAdd = _task_HtyRepository.AddData(taskHtyNG) > 0; var isTaskDelete = Delete(task.TaskId); - var AgvTask = SqlSugarHelper.DbAGV.Queryable<task_call>().Where(x => x.d_involed5 == task.TaskNum).First(); - if(AgvTask != null) + var AgvTask = SqlSugarHelper.DbAGV.Queryable<task_call>().Where(x => x.d_involed5 == taskNum).First(); + if (AgvTask != null) { - SqlSugarHelper.DbAGV.Deleteable(AgvTask).ExecuteCommand(); + var x=SqlSugarHelper.DbAGV.Deleteable(AgvTask).ExecuteCommand(); + LogFactory.GetLog("鎻掑叆鏁版嵁鍒癆GV").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(x)}", ""); } _unitOfWorkManage.CommitTran(); return content.OK(); @@ -160,8 +834,103 @@ catch (Exception ex) { _unitOfWorkManage.RollbackTran(); + LogFactory.GetLog("鍒犻櫎浠诲姟").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(ex.Message)}", ""); return content.Error(ex.Message); } + } + + public WebResponseContent GetTaskInfo() + { + WebResponseContent content = new WebResponseContent(); + try + { + Expression<Func<Dt_Task, bool>> expression = x => true; + if (!App.User.IsSuperAdmin) + { + expression = x => x.Creater == App.User.UserName; + } + + var task = BaseDal.QueryData(x => true).ToList(); + var newTask = task.OrderByDescending(x => x.CreateDate).Select(x => new + { + x.TaskNum, + x.PalletCode, + x.SourceAddress, + x.TargetAddress, + TaskType = new List<string> { GetTaskTypeDesc(x.TaskType) }[0], // 姣忎釜浠诲姟鐙珛鐢熸垚 TaskType + TaskState = new List<string> { GetTaskStateDesc(x.TaskState) }[0] // 姣忎釜浠诲姟鐙珛鐢熸垚 TaskState + }).ToList(); + + content = WebResponseContent.Instance.OK(data: newTask); + } + catch (Exception ex) + { + content = WebResponseContent.Instance.Error(ex.Message); + } + return content; + } + + public WebResponseContent GetHostError() + { + WebResponseContent content = new WebResponseContent(); + try + { + Expression<Func<Dt_Task, bool>> expression = x => true; + if (!App.User.IsSuperAdmin) + { + expression = x => x.Creater == App.User.UserName; + } + + var now = DateTime.Now; + var startOfDay = new DateTime(now.Year, now.Month, now.Day); + var newTask = _errorMessageRepository.QueryData(x =>x.CreateDate> startOfDay).OrderByDescending(x => x.CreateDate).Select(x => new + { + x.id, + x.ErrorCode, + x.ErrorMessage, + x.Grade, + x.CreateDate + }).ToList(); + + content = WebResponseContent.Instance.OK(data: newTask); + } + catch (Exception ex) + { + content = WebResponseContent.Instance.Error(ex.Message); + } + return content; + } + + + public string GetTaskTypeDesc(int taskType) + { + return taskType switch + { + (int)TaskInboundTypeEnum.Inbound => TaskInboundTypeEnum.Inbound.GetIntegralRuleTypeEnumDesc(), + (int)TaskRelocationTypeEnum.Relocation => TaskRelocationTypeEnum.Relocation.GetIntegralRuleTypeEnumDesc(), + (int)TaskStationTypeEnum.StationToStation => TaskStationTypeEnum.StationToStation.GetIntegralRuleTypeEnumDesc(), + (int)TaskFireAlarmTypeEnum.FireAlarmOut => TaskFireAlarmTypeEnum.FireAlarmOut.GetIntegralRuleTypeEnumDesc(), + (int)TaskOutboundTypeEnum.Outbound => TaskOutboundTypeEnum.Outbound.GetIntegralRuleTypeEnumDesc(), + (int)TaskOutboundTypeEnum.OutQuality => TaskOutboundTypeEnum.OutQuality.GetIntegralRuleTypeEnumDesc(), + }; + } + public string GetTaskStateDesc(int? taskState) + { + return taskState switch + { + (int)TaskInStatusEnum.InNew => TaskInStatusEnum.InNew.GetIntegralRuleTypeEnumDesc(), + (int)TaskInStatusEnum.AGV_InExecuting => TaskInStatusEnum.AGV_InExecuting.GetIntegralRuleTypeEnumDesc(), + (int)TaskInStatusEnum.AGV_InFinish => TaskInStatusEnum.AGV_InFinish.GetIntegralRuleTypeEnumDesc(), + (int)TaskRelocationStatusEnum.RelocationNew => TaskRelocationStatusEnum.RelocationNew.GetIntegralRuleTypeEnumDesc(), + (int)TaskRelocationStatusEnum.AGV_RelocationExecuting => TaskRelocationStatusEnum.AGV_RelocationExecuting.GetIntegralRuleTypeEnumDesc(), + (int)TaskRelocationStatusEnum.AGV_RelocationFinish => TaskRelocationStatusEnum.AGV_RelocationFinish.GetIntegralRuleTypeEnumDesc(), + (int)TaskOutStatusEnum.OutNew => TaskOutStatusEnum.OutNew.GetIntegralRuleTypeEnumDesc(), + (int)TaskOutStatusEnum.AGV_OutExecuting => TaskOutStatusEnum.AGV_OutExecuting.GetIntegralRuleTypeEnumDesc(), + (int)TaskOutStatusEnum.AGV_OutFinish => TaskOutStatusEnum.AGV_OutFinish.GetIntegralRuleTypeEnumDesc(), + (int)TaskFireAlarmStatusEnum.FireAlarmNew => TaskFireAlarmStatusEnum.FireAlarmNew.GetIntegralRuleTypeEnumDesc(), + (int)TaskFireAlarmStatusEnum.AGV_FireAlarmExecuting => TaskFireAlarmStatusEnum.AGV_FireAlarmExecuting.GetIntegralRuleTypeEnumDesc(), + (int)TaskFireAlarmStatusEnum.FireAlarmFinish => TaskFireAlarmStatusEnum.FireAlarmFinish.GetIntegralRuleTypeEnumDesc(), + }; } #endregion 澶栭儴鎺ュ彛鏂规硶 @@ -196,9 +965,9 @@ /// <returns>鏄惁鍒犻櫎鎴愬姛</returns> public bool Delete(int id) { - return BaseDal.Delete(id); + return BaseDal.Delete(id); } - private void AddStockInfoHty(DtStockInfo_Hty dtStock) + private void AddStockInfoHty(DtStockInfo_Hty dtStock) { var isStockAdd = SqlSugarHelper.DbWMS.InsertNav(dtStock).IncludesAllFirstLayer().ExecuteCommand(); if (!isStockAdd) @@ -207,5 +976,42 @@ } } + public override WebResponseContent DeleteData(object[] key) + { + WebResponseContent content = new WebResponseContent(); + // 鍒涘缓鍘嗗彶浠诲姟瀹炰緥妯″瀷 + try + { + foreach (var item in key) + { + //var task = BaseDal.QueryFirst(x => x.TaskId == Convert.ToInt32(item)); + //var taskHty = task.Adapt<Dt_Task_Hty>(); + //taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System"; + //_taskHtyRepository.AddData(taskHty); + + //return base.DeleteData(key); + Dt_Task task = BaseDal.QueryFirst(x => x.TaskId == Convert.ToInt32(item)); + if (task == null) + { + return content.Error("鏈壘鍒颁换鍔′俊鎭�!"); + } + var taskHtyNG = CreateHistoricalTask(task, true); + + // 鎵ц鏁版嵁搴撲簨鍔� + + // 娣诲姞鍘嗗彶浠诲姟 + var isTaskHtyAdd = _task_HtyRepository.AddData(taskHtyNG) > 0; + + // 鍒犻櫎浠诲姟鏁版嵁 + var isTaskDelete = BaseDal.Delete(task.TaskId); + } + return content.OK("鍒犻櫎鎴愬姛!"); + } + catch (Exception ex) + { + return content.Error("鍒犻櫎浠诲姟寮傚父锛�" + ex.Message); + } + } + #endregion private 鍐呴儴鏂规硶 } \ No newline at end of file -- Gitblit v1.9.3