From 6cc35000a6e138cfad96e7b02f8aeddcdb4ba6bf Mon Sep 17 00:00:00 2001 From: wankeda <Administrator@DESKTOP-HAU3ST3> Date: 星期二, 24 六月 2025 09:57:25 +0800 Subject: [PATCH] 代码提交 --- 代码管理/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskCZService.cs | 443 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 415 insertions(+), 28 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskCZService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskCZService.cs" index edd5122..a9f031a 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskCZService.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskCZService.cs" @@ -17,6 +17,8 @@ #endregion << 鐗� 鏈� 娉� 閲� >> +using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical; +using System.Text.Json; using WIDESEAWCS_Common.TaskEnum; using WIDESEAWCS_Core; using WIDESEAWCS_Core.BaseServices; @@ -24,13 +26,37 @@ using WIDESEAWCS_ITaskInfoRepository; using WIDESEAWCS_ITaskInfoService; using WIDESEAWCS_Model.Models; - +using WIDESEAWCS_ISystemServices; +using WIDESEAWCS_ISystemRepository; +using WIDESEA_Common; +using WIDESEA_Core.Enums; +using SqlSugar.Extensions; +using System.Threading.Tasks; +using System.Reflection.Emit; +using WIDESEAWCS_Core.Enums; +using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Numeric; +using WIDESEAWCS_Core.Tool; +using System.Net; namespace WIDESEAWCS_TaskInfoService { public class TaskCZService : ServiceBase<DtCZTask, ITaskCZRepository>, ITaskCZService { - public TaskCZService(ITaskCZRepository BaseDal) : base(BaseDal) + private readonly ITaskRepository _taskRepository; + private readonly ITaskService _taskService; + private readonly ITaskCZDetailsRepository _detailsRepository; + private readonly IDt_StationinfoRepository _stationinfoRepository; + private readonly ITaskHtyRepository _taskHtyRepository; + private readonly ITaskHtyService _taskHtyService; + + public TaskCZService(ITaskCZRepository BaseDal, ITaskHtyService taskHtyService, ITaskHtyRepository taskHtyRepository, IDt_StationinfoRepository stationinfoRepository, ITaskService taskService, ITaskRepository taskRepository, ITaskCZDetailsRepository detailsRepository) : base(BaseDal) { + _taskRepository = taskRepository; + _detailsRepository = detailsRepository; + _taskService = taskService; + _stationinfoRepository = stationinfoRepository; + _taskHtyRepository = taskHtyRepository; + _taskHtyService = taskHtyService; } public Task<WebResponseContent> AddTaskCZAsync(CZTaskDto dto) @@ -83,38 +109,118 @@ WebResponseContent response = new WebResponseContent(); try { - var czTask = BaseDal.QueryFirst(x => x.TaskTaskID == dto.TaskId); - if (czTask == null) + //ConsoleHelper.WriteErrorLine($"{nameof(dto.TaskId)}"); + WriteLog.Info("浠诲姟瀹屾垚").Write($"浠诲姟鍙穥dto.TaskId}", "浠诲姟瀹屾垚"); + if (dto.Floor == 1) { - response.Error("浠诲姟涓嶅瓨鍦紒"); - return Task.FromResult(response); - } - if (dto.Tags.Contains("姝f瀬")) - { - czTask.TaskZJFinishNumber += 1; - } - else - { - czTask.TaskFJFinishNumber += 1; - } - if (czTask.TaskZJFinishNumber == czTask.TaskNumber || czTask.TaskFJFinishNumber == czTask.TaskNumber) - { - czTask.TaskStatus = TaskInStatusEnum.InFinish.ToString(); - czTask.TaskEndDate = DateTime.Now; - } - else - { + var czTask = BaseDal.QueryFirst(x => x.TaskTaskID == dto.TaskId); + if (czTask == null) + { + response.Error("浠诲姟涓嶅瓨鍦紒"); + return Task.FromResult(response); + } + //if (dto.Tags.Contains("姝f瀬")) + //{ + // czTask.TaskZJFinishNumber += 1; + //} + //else + //{ + // czTask.TaskFJFinishNumber += 1; + //} + //if (czTask.TaskZJFinishNumber == czTask.TaskNumber || czTask.TaskFJFinishNumber == czTask.TaskNumber) + //{ + // czTask.TaskStatus = TaskInStatusEnum.InFinish.ToString(); + // czTask.TaskEndDate = DateTime.Now; + //} + //else + //{ czTask.TaskStatus = TaskInStatusEnum.Line_InExecuting.ToString(); - } - var isTrue = BaseDal.UpdateData(czTask); - if (isTrue) - { - response.OK("浠诲姟瀹屾垚鎴愬姛锛�"); + //} + + var details = new DtCZTaskDetails() + { + MaterialBarCode = dto.MaterialBarcode, + MaterialType = dto.ProductCode, + TaskDescription = "鍒涙櫤鎻愪氦浠诲姟瀹屾垚", + TaskEndAddress = czTask.TaskEndAddress, + TaskName = czTask.TaskName, + TaskType = czTask.TaskType, + TaskStatus = czTask.TaskStatus, + TaskTaskID = czTask.TaskTaskID, + }; + _detailsRepository.AddData(details); + + //if (dto.FinishNum is < 1 or > 4) + // throw new ArgumentException("鍙傛暟閿欒锛丗inishNum 蹇呴』涓� 1-4"); + + //var detail = dto.FinishNum == 1 + // ? new CZTaskBarCodeDto() + // : JsonSerializer.Deserialize<CZTaskBarCodeDto>(czTask.DtCZTaskDetails) ?? new CZTaskBarCodeDto(); + + //var property = dto.FinishNum switch + //{ + // 1 => nameof(CZTaskBarCodeDto.BarCode1), + // 2 => nameof(CZTaskBarCodeDto.BarCode2), + // 3 => nameof(CZTaskBarCodeDto.BarCode3), + // 4 => nameof(CZTaskBarCodeDto.BarCode4), + // _ => throw new ArgumentOutOfRangeException("鍙傛暟閿欒锛佽妫�鏌ャ�怓inishNum銆戯紒") + //}; + + //typeof(CZTaskBarCodeDto).GetProperty(property)?.SetValue(detail, dto.MaterialBarcode); + + //czTask.DtCZTaskDetails = JsonSerializer.Serialize(detail); + + var isTrue = BaseDal.UpdateData(czTask); + if (isTrue) + { + response.OK("浠诲姟瀹屾垚鎴愬姛锛�"); + } + else + { + response.Error("浠诲姟瀹屾垚澶辫触锛�"); + } } else { - response.Error("浠诲姟瀹屾垚澶辫触锛�"); + Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == dto.TaskId.ObjToInt()); + if (task == null) + { + response.Error("浠诲姟涓嶅瓨鍦紒"); + return Task.FromResult(response); + } + WriteLog.Info("1").Write($"浠诲姟鍙穥task.TaskNum}", "1"); + task.TaskState = TaskInStatusEnum.AGV_InFinish.ObjToInt(); + if (task.SourceAddress.Contains("SL-0")) + { + var address = task.SourceAddress.Split("||"); + WriteLog.Info("1").Write($"{address}", "1"); + Dt_Stationinfo Stationinfo = _stationinfoRepository.QueryFirst(x => x.StationCode == address[0]); + WriteLog.Info("1").Write($"{Stationinfo.StationCode}", "1"); + Dt_Stationinfo Stationinfo1 = _stationinfoRepository.QueryFirst(x => x.StationCode == address[1]); + WriteLog.Info("1").Write($"{Stationinfo.StationCode}", "1"); + Stationinfo.Location_state = LocationStatusEnum.Free.ObjToInt(); + _stationinfoRepository.UpdateData(Stationinfo); + Stationinfo1.Location_state = LocationStatusEnum.Free.ObjToInt(); + _stationinfoRepository.UpdateData(Stationinfo1); + } + if (task.TargetAddress.Contains("SL-0")) + { + var address = task.TargetAddress.Split("||"); + Dt_Stationinfo Stationinfo = _stationinfoRepository.QueryFirst(x => x.StationCode == address[0]); + WriteLog.Info("2").Write($"{Stationinfo.StationCode}", "2"); + Dt_Stationinfo Stationinfo1 = _stationinfoRepository.QueryFirst(x => x.StationCode == address[1]); + WriteLog.Info("2").Write($"{Stationinfo.StationCode}", "2"); + Stationinfo.Location_state = LocationStatusEnum.InStock.ObjToInt(); + _stationinfoRepository.UpdateData(Stationinfo); + Stationinfo1.Location_state = LocationStatusEnum.InStock.ObjToInt(); + _stationinfoRepository.UpdateData(Stationinfo1); + } + _taskHtyService.AddTask_Hty(task, OperateTypeEnum.鑷姩瀹屾垚); + _taskService.DeleteData(task); + response.OK("浠诲姟瀹屾垚鎴愬姛锛�"); + WriteLog.Info("浠诲姟瀹屾垚鎴愬姛").Write($"浠诲姟鍙穥task.TaskId}", "浠诲姟瀹屾垚鎴愬姛"); } + } catch (Exception ex) { @@ -122,5 +228,286 @@ } return Task.FromResult(response); } + + /// <summary> + /// 绌烘墭鍥炴祦 AGV浠诲姟瀹屾垚涔嬪悗闇�鏇存柊缂撳瓨鏋剁姸鎬� + /// </summary> + /// <param name="saveModel"></param> + /// <returns></returns> + public Task<WebResponseContent> EmptyTask(SaveModel saveModel) + { + WebResponseContent webResponseContent = new WebResponseContent(); + try + { + //閫氳繃绔欑偣琛ㄥ垽鏂紦瀛樻灦鏄偅涓尯鍩熷幓閭f潯杈撻�佺嚎鍥炴祦鍙c�傘�傘�傘�傘�傘�傘�傘�傘�傘�傘�� + string Saddress = saveModel.MainData["sourceAddress"].ToString(); + string Saddress1 = saveModel.MainData["sourceAddress1"].ToString(); + string Taddress = saveModel.MainData["targetAddress"].ToString(); + if (Saddress == Saddress1) + { + webResponseContent.Error("鍚屼竴缂撳瓨鏋朵笉鑳芥壂鎻忎袱娆★紒"); + return Task.FromResult(webResponseContent); + } + Dt_Task task = _taskRepository.QueryFirst(x => x.SourceAddress == Saddress || x.SourceAddress == Saddress1 || x.TargetAddress == Saddress || x.TargetAddress == Saddress1); + if (task != null) + { + webResponseContent.Error("姝ょ紦瀛樻灦宸插瓨鍦ㄤ换鍔★紒"); + return Task.FromResult(webResponseContent); + } + Dt_Stationinfo Stationinfo = _stationinfoRepository.QueryFirst(x => x.StationCode == Saddress && x.Enable); + Dt_Stationinfo Stationinfo1 = _stationinfoRepository.QueryFirst(x => x.StationCode == Saddress1 && x.Enable); + if (Stationinfo == null || Stationinfo1 == null) + { + webResponseContent.Error("鏈壘鍒版璧风偣缂撳瓨鏋�,鎴栨缂撳瓨鏋跺凡琚鐢紒"); + return Task.FromResult(webResponseContent); + } + Stationinfo.Location_state = LocationStatusEnum.Lock.ObjToInt(); + _stationinfoRepository.UpdateData(Stationinfo); + Stationinfo1.Location_state = LocationStatusEnum.Lock.ObjToInt(); + _stationinfoRepository.UpdateData(Stationinfo1); + Dt_Task dt_Task = new Dt_Task(); + { + dt_Task.TaskNum = _taskService.GetTaskNum(); + dt_Task.CreateDate = DateTime.Now; + dt_Task.Creater = "system"; + dt_Task.CurrentAddress = Stationinfo.StationCode + "||" + Stationinfo1.StationCode; + dt_Task.SourceAddress = Stationinfo.StationCode + "||" + Stationinfo1.StationCode; + dt_Task.TaskState = (int)TaskInStatusEnum.InNew; + //dt_Task.TaskType = (int)TaskOutboundTypeEnum.Outbound; + dt_Task.Grade = 1; + dt_Task.PalletCode = ""; + if (Stationinfo.Area == "A鍖�") + { + dt_Task.TargetAddress = "ZJXL-KPHLS001"; + dt_Task.NextAddress = "ZJXL-KPHLX001"; + dt_Task.TaskType = 64; + } + else + { + dt_Task.TargetAddress = "FJXL-KPHLS001"; + dt_Task.NextAddress = "FJXL-KPHLX001"; + dt_Task.TaskType = 256; + } + dt_Task.NextAddress = dt_Task.TargetAddress; + dt_Task.Barcode = ""; + dt_Task.Roadway = "AGV"; + dt_Task.WMSId = 0; + dt_Task.Remark = "绌烘墭鍥炴祦"; + dt_Task.Floor = 3; + } + var isTrue = _taskRepository.AddData(dt_Task); + + Dt_Task dt_Tasks = new Dt_Task(); + { + dt_Tasks.TaskNum = _taskService.GetTaskNum(); + dt_Tasks.CreateDate = DateTime.Now; + dt_Tasks.Creater = "system"; + if (Stationinfo.Area == "A鍖�") + { + dt_Tasks.CurrentAddress = "ZJXL-KPHLX001"; + } + else + { + dt_Tasks.CurrentAddress = "FJXL-KPHLX001"; + } + dt_Tasks.SourceAddress = dt_Tasks.CurrentAddress; + dt_Tasks.TaskState = (int)TaskInStatusEnum.InPending; + dt_Tasks.TaskType = 16; + dt_Tasks.Grade = 1; + dt_Tasks.PalletCode = ""; + dt_Tasks.TargetAddress = Taddress; + dt_Tasks.NextAddress = Taddress; + dt_Tasks.Barcode = ""; + dt_Tasks.Roadway = "AGV"; + dt_Tasks.WMSId = 0; + dt_Tasks.Remark = "绌烘墭鍥炴祦"; + dt_Task.Floor = 3; + } + + var isTrue1 = _taskRepository.AddData(dt_Tasks); + webResponseContent.OK("浠诲姟涓嬪彂鎴愬姛锛�"); + } + catch (Exception ex) + { + webResponseContent.Error(ex.Message); + } + return Task.FromResult(webResponseContent); + } + /// <summary> + /// 鐑樼儰鍑烘枡 AGV浠诲姟瀹屾垚涔嬪悗闇�鏇存柊缂撳瓨鏋剁姸鎬� + /// </summary> + /// <param name="sourceAddress"></param> + /// <returns></returns> + public Task<WebResponseContent> OutBoundTask(SaveModel saveModel) + { + WebResponseContent webResponseContent = new WebResponseContent(); + try + { + string Saddress = saveModel.MainData["sourceAddress"].ToString(); + Dt_Task task = _taskRepository.QueryFirst(x => x.SourceAddress == Saddress); + if (task != null) + { + webResponseContent.Error("璧风偣宸插瓨鍦ㄤ换鍔★紒"); + return Task.FromResult(webResponseContent); + } + //var station = _stationinfoRepository.QueryFirst(x => x.StationCode == Saddress); + //// 鏌ユ壘涓や釜鍙敤鐨勭┖缂撳瓨鏋� + //var freeStations = _stationinfoRepository + // .QueryData(x => x.Location_state == LocationStatusEnum.Free.ObjToInt() && x.Enable && x.Remark == station.Remark && x.Area == station.Area)// && x.Stationtype == station.Stationtype + // .Take(2) // 鍙彇鍓嶄袱涓� + // .ToList(); + + //int floor = 0; + //if (station.Area.Contains("A鍖�")) + //{ + // floor = 32; + //} + //else + //{ + // floor = 128; + //} + //if (freeStations.Count < 2) + //{ + // webResponseContent.Error("鏈壘鍒拌冻澶熺殑绌虹紦瀛樻灦锛�"); + // return Task.FromResult(webResponseContent); + //} + //// 妫�鏌ヨ繖涓や釜缂撳瓨鏋舵槸鍚﹁浠诲姟鍗犵敤 + //var stationCodes = freeStations.Select(s => s.StationCode).ToList(); + //freeStations[0].Location_state = LocationStatusEnum.Lock.ObjToInt(); + //_stationinfoRepository.UpdateData(freeStations[0]); + //freeStations[1].Location_state = LocationStatusEnum.Lock.ObjToInt(); + //_stationinfoRepository.UpdateData(freeStations[1]); + ////stationCodes. + //var tasks = _taskRepository.QueryData(x => stationCodes.Contains(x.SourceAddress) || stationCodes.Contains(x.TargetAddress)).ToList(); + //if (tasks.Any()) + //{ + // webResponseContent.Error("閮ㄥ垎缂撳瓨鏋跺凡琚崰鐢紝鏃犳硶浣跨敤锛�"); + // return Task.FromResult(webResponseContent); + //} + + Dt_Task dt_Task = new Dt_Task() + { + TaskNum = _taskService.GetTaskNum(), + CreateDate = DateTime.Now, + Creater = "system", + CurrentAddress = Saddress, + SourceAddress = Saddress, + TaskState = (int)TaskInStatusEnum.AGV_Queue, + TaskType = 0,//floor + Grade = 1, + PalletCode = "", + Floor = 3, + TargetAddress = "",//string.Join("||", freeStations.Select(s => s.StationCode)) + NextAddress = "",//string.Join("||", freeStations.Select(s => s.StationCode)) + Barcode = "", + Roadway = "AGV", + WMSId = 0, + Remark = "绌烘墭鍥炴祦" + }; + var isTrue = _taskRepository.AddData(dt_Task); + webResponseContent.OK("浠诲姟涓嬪彂鎴愬姛锛�"); + } + catch (Exception ex) + { + webResponseContent.Error(ex.Message); + } + return Task.FromResult(webResponseContent); + } + /// <summary> + /// 鐑樼儰鍥炵倝 AGV浠诲姟瀹屾垚涔嬪悗闇�鏇存柊缂撳瓨鏋剁姸鎬� + /// </summary> + /// <param name="saveModel"></param> + /// <returns></returns> + public Task<WebResponseContent> OutBoundTasks(SaveModel saveModel) + { + WebResponseContent webResponseContent = new WebResponseContent(); + try + { + //閫氳繃绔欑偣琛ㄥ垽鏂紦瀛樻灦鏄偅涓尯鍩熷幓閭f潯杈撻�佺嚎鍥炴祦鍙c�傘�傘�傘�傘�傘�傘�傘�傘�傘�傘�� + string Saddress = saveModel.MainData["sourceAddress"].ToString(); + string Saddress1 = saveModel.MainData["sourceAddress1"].ToString(); + string Taddress = saveModel.MainData["targetAddress"].ToString(); + if (Saddress == Saddress1) + { + webResponseContent.Error("鍚屼竴缂撳瓨鏋朵笉鑳芥壂鎻忎袱娆★紒"); + return Task.FromResult(webResponseContent); + } + Dt_Stationinfo Stationinfo = _stationinfoRepository.QueryFirst(x => x.StationCode == Saddress && x.Enable); + Dt_Stationinfo Stationinfo1 = _stationinfoRepository.QueryFirst(x => x.StationCode == Saddress1 && x.Enable); + if (Stationinfo == null || Stationinfo1 == null) + { + webResponseContent.Error("鏈壘鍒版璧风偣缂撳瓨鏋�,鎴栨缂撳瓨鏋跺凡琚鐢紒"); + return Task.FromResult(webResponseContent); + } + Stationinfo.Location_state = LocationStatusEnum.Lock.ObjToInt(); + _stationinfoRepository.UpdateData(Stationinfo); + Stationinfo1.Location_state = LocationStatusEnum.Lock.ObjToInt(); + _stationinfoRepository.UpdateData(Stationinfo1); + Dt_Task dt_Task = new Dt_Task(); + { + dt_Task.TaskNum = _taskService.GetTaskNum(); + dt_Task.CreateDate = DateTime.Now; + dt_Task.Creater = "system"; + dt_Task.CurrentAddress = Stationinfo.StationCode + "||" + Stationinfo1.StationCode; + dt_Task.SourceAddress = Stationinfo.StationCode + "||" + Stationinfo1.StationCode; + dt_Task.TaskState = (int)TaskInStatusEnum.InNew; + //dt_Task.TaskType = (int)TaskOutboundTypeEnum.Outbound; + dt_Task.Grade = 1; + dt_Task.PalletCode = ""; + if (Stationinfo.Area == "A鍖�") + { + dt_Task.TargetAddress = "ZJXL-KPHLS001"; + dt_Task.NextAddress = "ZJXL-KPHLX001"; + dt_Task.TaskType = 64; + } + else + { + dt_Task.TargetAddress = "FJXL-KPHLS001"; + dt_Task.NextAddress = "FJXL-KPHLX001"; + dt_Task.TaskType = 256; + } + dt_Task.Barcode = ""; + dt_Task.Roadway = "AGV"; + dt_Task.WMSId = 0; + dt_Task.Remark = "鐑樼儰鍥炵倝"; + dt_Task.Floor = 3; + } + var isTrue = _taskRepository.AddData(dt_Task); + + Dt_Task dt_Tasks = new Dt_Task(); + { + dt_Tasks.TaskNum = _taskService.GetTaskNum(); + dt_Tasks.CreateDate = DateTime.Now; + dt_Tasks.Creater = "system"; + if (Stationinfo.Area == "A鍖�") + { + dt_Tasks.CurrentAddress = "ZJXL-KPHLX001"; + } + else + { + dt_Tasks.CurrentAddress = "FJXL-KPHLX001"; + } + dt_Tasks.SourceAddress = dt_Tasks.CurrentAddress; + dt_Tasks.TaskState = (int)TaskInStatusEnum.InPending; + dt_Tasks.TaskType = 8; + dt_Tasks.Grade = 1; + dt_Tasks.PalletCode = ""; + dt_Tasks.TargetAddress = Taddress; + dt_Tasks.NextAddress = Taddress; + dt_Tasks.Barcode = ""; + dt_Tasks.Roadway = "AGV"; + dt_Tasks.WMSId = 0; + dt_Tasks.Remark = "鐑樼儰鍥炵倝"; + dt_Task.Floor = 3; + } + var isTrue1 = _taskRepository.AddData(dt_Tasks); + webResponseContent.OK("浠诲姟涓嬪彂鎴愬姛锛�"); + } + catch (Exception ex) + { + webResponseContent.Error(ex.Message); + } + return Task.FromResult(webResponseContent); + } } } \ No newline at end of file -- Gitblit v1.9.3