| using System; | 
| using System.Collections.Generic; | 
| using System.ComponentModel; | 
| using System.Linq; | 
| using System.Reflection; | 
| using System.Text; | 
| using WIDESEAWCS_Common.TaskEnum; | 
| using WIDESEAWCS_Core; | 
| using WIDESEAWCS_Core.Enums; | 
| using WIDESEAWCS_Core.Helper; | 
| using WIDESEAWCS_Model.Models; | 
|   | 
| namespace WIDESEAWCS_TaskInfoService | 
| { | 
|     public partial class TaskService | 
|     { | 
|         /// <summary> | 
|         /// 更新任务信息及添加任务明细记录 | 
|         /// </summary> | 
|         /// <param name="task">任务原对象实例(未修改的数据对象)</param> | 
|         /// <param name="taskStatus">修改后的任务状态</param> | 
|         /// <param name="deviceCode">修改后的设备编号</param> | 
|         /// <param name="sourceAddress">修改后的起始地址</param> | 
|         /// <param name="targetAddress">修改后的目标地址</param> | 
|         /// <param name="currentAddress">修改后的当前地址</param> | 
|         /// <param name="nextAddress">修改后的下一地址</param> | 
|         public void UpdateTask(Dt_Task task, TaskStatusEnum taskStatus, string deviceCode = "", string sourceAddress = "", string targetAddress = "", string currentAddress = "", string nextAddress = "", string roadwayNo = "", int heightType = 0) | 
|         { | 
|             StringBuilder stringBuilder = new StringBuilder(App.User?.UserId == 0 ? $"系统自动流程" : "人工手动流程"); | 
|             if (task.DeviceCode != deviceCode && !string.IsNullOrEmpty(deviceCode)) | 
|             { | 
|                 stringBuilder.Append($",设备编号由{task.DeviceCode}变更为{deviceCode}"); | 
|                 task.DeviceCode = deviceCode; | 
|             } | 
|             if (task.SourceAddress != sourceAddress && !string.IsNullOrEmpty(sourceAddress)) | 
|             { | 
|                 stringBuilder.Append($",起始地址由{task.SourceAddress}变更为{sourceAddress}"); | 
|                 task.SourceAddress = sourceAddress; | 
|             } | 
|             if (task.TargetAddress != targetAddress && !string.IsNullOrEmpty(targetAddress)) | 
|             { | 
|                 stringBuilder.Append($",目标地址由{task.TargetAddress}变更为{targetAddress}"); | 
|                 task.TargetAddress = targetAddress; | 
|             } | 
|             if (task.CurrentAddress != currentAddress && !string.IsNullOrEmpty(currentAddress)) | 
|             { | 
|                 stringBuilder.Append($",当前位置由{task.CurrentAddress}变更为{currentAddress}"); | 
|                 task.CurrentAddress = currentAddress; | 
|             } | 
|             if (task.NextAddress != nextAddress && !string.IsNullOrEmpty(nextAddress)) | 
|             { | 
|                 stringBuilder.Append($",下一位置由{task.NextAddress}变更为{nextAddress}"); | 
|                 task.NextAddress = nextAddress; | 
|             } | 
|             if (task.Roadway != roadwayNo && !string.IsNullOrEmpty(roadwayNo)) | 
|             { | 
|                 stringBuilder.Append($",巷道号由{task.Roadway}变更为{roadwayNo}"); | 
|                 task.Roadway = roadwayNo; | 
|             } | 
|             if (heightType!=0) | 
|             { | 
|                 task.HeightType= heightType; | 
|             } | 
|             if (task.TaskState != taskStatus.ObjToInt()) | 
|             { | 
|                 string newStatus = $"{taskStatus}"; | 
|                 try | 
|                 { | 
|                     List<int> enums = Enum.GetValues(typeof(TaskStatusEnum)).Cast<int>().ToList(); | 
|                     FieldInfo? fieldInfo = typeof(TaskStatusEnum).GetField((taskStatus).ToString()); | 
|                     if (fieldInfo != null) | 
|                     { | 
|                         DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>(); | 
|                         if (description != null) | 
|                         { | 
|                             newStatus = $"{description.Description}({taskStatus})"; | 
|                         } | 
|                     } | 
|                 } | 
|                 catch { } | 
|                 string oldStatus = $"{task.TaskState}"; | 
|                 try | 
|                 { | 
|                     FieldInfo? fieldInfo2 = typeof(RouterInOutType).GetField(((TaskStatusEnum)task.TaskState).ToString()); | 
|                     if (fieldInfo2 != null) | 
|                     { | 
|                         DescriptionAttribute? description2 = fieldInfo2.GetCustomAttribute<DescriptionAttribute>(); | 
|                         if (description2 != null) | 
|                         { | 
|                             oldStatus = $"{description2.Description}({task.TaskState})"; | 
|                         } | 
|                     } | 
|                 } | 
|                 catch { } | 
|                 stringBuilder.Append($",任务状态由{oldStatus}变更为{newStatus}"); | 
|   | 
|                 task.TaskState = taskStatus.ObjToInt(); | 
|             } | 
|   | 
|             BaseDal.UpdateData(task); | 
|   | 
|             string address = AppSettings.Get("WMSApiAddress"); | 
|             if (!string.IsNullOrEmpty(address)) | 
|             { | 
|                 HttpHelper.Post($"{address}/api/Task/UpdateTaskInfo", task.Serialize()); | 
|             } | 
|             _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, stringBuilder.ToString()); | 
|         } | 
|     } | 
| } |