#region << 版 本 注 释 >> /*---------------------------------------------------------------- * 命名空间:WIDESEAWCS_TaskInfoService * 创建者:胡童庆 * 创建时间:2024/8/2 16:13:36 * 版本:V1.0.0 * 描述: * * ---------------------------------------------------------------- * 修改人: * 修改时间: * 版本:V1.0.1 * 修改说明: * *----------------------------------------------------------------*/ #endregion << 版 本 注 释 >> using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical; using System.Text.Json; using WIDESEAWCS_Common.TaskEnum; using WIDESEAWCS_Core; using WIDESEAWCS_Core.BaseServices; using WIDESEAWCS_DTO.TaskInfo; 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; namespace WIDESEAWCS_TaskInfoService { public class TaskCZService : ServiceBase, ITaskCZService { private readonly ITaskRepository _taskRepository; private readonly ITaskService _taskService; private readonly ITaskCZDetailsRepository _detailsRepository; private readonly IDt_StationinfoRepository _stationinfoRepository; public TaskCZService(ITaskCZRepository BaseDal, IDt_StationinfoRepository stationinfoRepository, ITaskService taskService, ITaskRepository taskRepository, ITaskCZDetailsRepository detailsRepository) : base(BaseDal) { _taskRepository = taskRepository; _detailsRepository = detailsRepository; _taskService = taskService; _stationinfoRepository = stationinfoRepository; } public Task AddTaskCZAsync(CZTaskDto dto) { var response = new WebResponseContent(); try { var task = BaseDal.QueryFirst(x => (x.TaskTaskID == dto.DTaskId) || (x.TaskEndAddress == dto.InputValue) || (x.TaskType == dto.TaskType)); if (task != null) { response.Error("任务已存在,请勿重复添加!"); } var taskModel = new DtCZTask() { TaskTaskID = dto.DTaskId, TaskType = dto.TaskType, TaskEndAddress = dto.InputValue, TaskStatus = TaskInStatusEnum.InNew.ToString(), CreateDate = DateTime.Now, TaskStartDate = DateTime.Now, TaskEndDate = DateTime.Now.AddDays(1), TaskName = dto.TaskType.ToString(), TaskNumber = dto.Number, TaskExecutor = "CZ", TaskOrderNo = dto.OrderNo, TaskOwner = "KH", TaskProductCode = dto.ProductCode, Creater = "KH" }; var isTrue = BaseDal.AddData(taskModel) > 0; if (isTrue) response.OK("任务添加成功!"); else response.Error("任务添加失败!"); } catch (System.Exception ex) { response.Error(ex.Message); } return Task.FromResult(response); } /// /// 完成任务 /// /// /// public Task FinishTask(CZTaskFinshDto dto) { WebResponseContent response = new WebResponseContent(); try { var czTask = BaseDal.QueryFirst(x => x.TaskTaskID == dto.TaskId); if (czTask == null) { response.Error("任务不存在!"); return Task.FromResult(response); } //if (dto.Tags.Contains("正极")) //{ // 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 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("参数错误!FinishNum 必须为 1-4"); //var detail = dto.FinishNum == 1 // ? new CZTaskBarCodeDto() // : JsonSerializer.Deserialize(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("参数错误!请检查【FinishNum】!") //}; //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("任务完成失败!"); } } catch (Exception ex) { response.Error(ex.Message); } return Task.FromResult(response); } /// /// 空托回流 /// /// /// public Task EmptyTask(SaveModel saveModel) { WebResponseContent webResponseContent = new WebResponseContent(); try { //通过站点表判断缓存架是那个区域去那条输送线回流口。。。。。。。。。。。 string Saddress = saveModel.MainData["sourceAddress"].ToString(); string Taddress = saveModel.MainData["targetAddress"].ToString(); Dt_Task task = _taskRepository.QueryFirst(x => x.SourceAddress == Saddress); if (task != null) { webResponseContent.Error("此缓存架已存在任务!"); return Task.FromResult(webResponseContent); } Dt_Stationinfo Stationinfo = _stationinfoRepository.QueryFirst(x => x.StationCode == Saddress); Dt_Task dt_Task = new Dt_Task(); dt_Task.TaskNum = _taskService.GetTaskNum(); dt_Task.CreateDate = DateTime.Now; dt_Task.Creater = "system"; dt_Task.CurrentAddress = Saddress; dt_Task.SourceAddress = Saddress; dt_Task.TaskState = (int)TaskInStatusEnum.InNew; dt_Task.TaskType = (int)TaskOutboundTypeEnum.Outbound; dt_Task.Grade = 1; dt_Task.PalletCode = ""; if (Stationinfo.Area == "正极") { dt_Task.TargetAddress = "正极回流输送线入口"; } else { dt_Task.TargetAddress = "负极回流输送线入口"; } dt_Task.NextAddress = dt_Task.TargetAddress; dt_Task.Barcode = ""; dt_Task.Roadway = "AGV"; dt_Task.WMSId = 0; dt_Task.Remark = "空托回流"; Dt_Task dt_Tasks = new Dt_Task(); dt_Tasks.TaskNum = _taskService.GetTaskNum(); dt_Tasks.CreateDate = DateTime.Now; dt_Tasks.Creater = "system"; if (Stationinfo.Area == "正极") { dt_Task.CurrentAddress = "正极回流输送线出口"; } else { dt_Task.CurrentAddress = "负极回流输送线出口"; } dt_Tasks.SourceAddress = dt_Task.CurrentAddress; dt_Tasks.TaskState = (int)TaskInStatusEnum.InPending; dt_Tasks.TaskType = (int)TaskOutboundTypeEnum.Outbound; 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 = "空托回流"; var isTrue = _taskRepository.AddData(dt_Task); var isTrue1 = _taskRepository.AddData(dt_Tasks); webResponseContent.OK("任务下发成功!"); } catch (Exception ex) { webResponseContent.Error(ex.Message); } return Task.FromResult(webResponseContent); } /// /// 烘烤出料 /// /// /// public Task OutBoundTask(string sourceAddress) { WebResponseContent webResponseContent = new WebResponseContent(); try { Dt_Task task = _taskRepository.QueryFirst(x => x.SourceAddress == sourceAddress); if (task != null) { webResponseContent.Error("起点已存在任务!"); return Task.FromResult(webResponseContent); } Dt_Stationinfo stationinfo = _stationinfoRepository.QueryFirst(x => x.Location_state == LocationStatusEnum.Free.ObjToInt()); if (stationinfo == null) { webResponseContent.Error("未找到空缓存架放置!"); return Task.FromResult(webResponseContent); } Dt_Task tasks = _taskRepository.QueryFirst(x => x.SourceAddress == stationinfo.StationCode || x.TargetAddress == stationinfo.StationCode); if (tasks != null) { webResponseContent.Error("未找到可用缓存架"); return Task.FromResult(webResponseContent); } Dt_Task dt_Task = new Dt_Task() { TaskNum = _taskService.GetTaskNum(), CreateDate = DateTime.Now, Creater = "system", CurrentAddress = sourceAddress, SourceAddress = sourceAddress, TaskState = (int)TaskInStatusEnum.InNew, TaskType = (int)TaskOutboundTypeEnum.Outbound, Grade = 1, PalletCode = "", TargetAddress = stationinfo.StationCode, NextAddress = stationinfo.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); } /// /// 烘烤回炉 /// /// /// public Task OutBoundTasks(SaveModel saveModel) { WebResponseContent webResponseContent = new WebResponseContent(); try { //通过站点表判断缓存架是那个区域去那条输送线回流口。。。。。。。。。。。 string Saddress = saveModel.MainData["sourceAddress"].ToString(); string Taddress = saveModel.MainData["targetAddress"].ToString(); Dt_Stationinfo Stationinfo = _stationinfoRepository.QueryFirst(x => x.StationCode == Saddress); Dt_Task dt_Task = new Dt_Task(); dt_Task.TaskNum = _taskService.GetTaskNum(); dt_Task.CreateDate = DateTime.Now; dt_Task.Creater = "system"; dt_Task.CurrentAddress = Saddress; dt_Task.SourceAddress = Saddress; dt_Task.TaskState = (int)TaskInStatusEnum.InNew; dt_Task.TaskType = (int)TaskOutboundTypeEnum.Outbound; dt_Task.Grade = 1; dt_Task.PalletCode = ""; if (Stationinfo.Area == "正极") { dt_Task.TargetAddress = "正极回流输送线入口"; } else { dt_Task.TargetAddress = "负极回流输送线入口"; } dt_Task.NextAddress = dt_Task.TargetAddress; dt_Task.Barcode = ""; dt_Task.Roadway = "AGV"; dt_Task.WMSId = 0; dt_Task.Remark = "烘烤回炉"; Dt_Task dt_Tasks = new Dt_Task(); dt_Tasks.TaskNum = _taskService.GetTaskNum(); dt_Tasks.CreateDate = DateTime.Now; dt_Tasks.Creater = "system"; if (Stationinfo.Area == "正极") { dt_Task.CurrentAddress = "正极回流输送线出口"; } else { dt_Task.CurrentAddress = "负极回流输送线出口"; } dt_Tasks.SourceAddress = dt_Task.CurrentAddress; dt_Tasks.TaskState = (int)TaskInStatusEnum.InPending; dt_Tasks.TaskType = (int)TaskOutboundTypeEnum.Outbound; 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 = "烘烤回炉"; var isTrue = _taskRepository.AddData(dt_Task); var isTrue1 = _taskRepository.AddData(dt_Tasks); webResponseContent.OK("任务下发成功!"); } catch (Exception ex) { webResponseContent.Error(ex.Message); } return Task.FromResult(webResponseContent); } } }