New file |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using HH.WCS.Mobox3.FJJT.util; |
| | | using HH.WCS.Mobox3.FJJT.wms; |
| | | using Newtonsoft.Json; |
| | | using static HH.WCS.Mobox3.FJJT.api.ApiModel; |
| | | using static HH.WCS.Mobox3.FJJT.util.ExcetionHelper; |
| | | |
| | | namespace HH.WCS.Mobox3.FJJT.dispatch |
| | | { |
| | | internal class WCSDispatch |
| | | { |
| | | private static readonly HttpHelper apiHelper = new HttpHelper(); |
| | | private static readonly string baseUrl = "http://10.30.10.8:8100/dev-api"; |
| | | |
| | | internal static string GenerateReqId() |
| | | { |
| | | var id = SYSHelper.GetSerialNumber("请求ID", "RE"); |
| | | var date = DateTime.Now.ToString("yyMMdd"); |
| | | return $"{date}{id.ToString().PadLeft(4, '0')}"; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 任务下发 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | public static bool sendTask(SendTaskModel model) |
| | | { |
| | | var result = false; |
| | | model.reqId = GenerateReqId(); |
| | | model.reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | var request = JsonConvert.SerializeObject(model); |
| | | try |
| | | { |
| | | var response = apiHelper.Post(baseUrl + "/api/hecWms/produceProcessTracing/trayMaterialUnBind", request); |
| | | LogHelper.Info($"[WCS-sendTask] request={request} response={response}", "WMS"); |
| | | if (response != null && response != "") |
| | | { |
| | | |
| | | var dataResult = JsonConvert.DeserializeObject<ResponseResult>(response); |
| | | if (dataResult.code == 200) |
| | | { |
| | | result = true; |
| | | } |
| | | else |
| | | { |
| | | WMSHelper.addAlarmRecord("流程异常", "高", $"下发WCS任务失败,WCS反馈原因:{dataResult.msg}"); |
| | | throw new BusinessException($"下发WCS任务失败,WCS反馈原因:{dataResult.msg}"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | WMSHelper.addAlarmRecord("流程异常", "高", $"下发WCS任务失败,WCS没有返回数据"); |
| | | throw new BusinessException($"下发WCS任务失败,WCS没有返回数据"); |
| | | } |
| | | } |
| | | catch (BusinessException be) |
| | | { |
| | | throw be; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | WMSHelper.addAlarmRecord("系统异常", "高", $"下发WCS任务错误,错误原因:{ex.Message}"); |
| | | throw new BusinessException($"下发WCS任务错误,错误原因:{ex.Message}"); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 任务取消(任务执行中不允许取消) |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | public static bool cancelTask(CancelTaskModel model) |
| | | { |
| | | var result = false; |
| | | model.reqId = GenerateReqId(); |
| | | model.reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | var request = JsonConvert.SerializeObject(model); |
| | | try |
| | | { |
| | | var response = apiHelper.Post(baseUrl + "/api/hecWms/produceProcessTracing/trayMaterialUnBind", request); |
| | | LogHelper.Info($"[WCS-cancelTask] request={request} response={response}", "WMS"); |
| | | if (response != null && response != "") |
| | | { |
| | | |
| | | var dataResult = JsonConvert.DeserializeObject<ResponseResult>(response); |
| | | if (dataResult.code == 200) |
| | | { |
| | | result = true; |
| | | } |
| | | else |
| | | { |
| | | WMSHelper.addAlarmRecord("流程异常", "高", $"取消WCS任务失败,WCS反馈原因:{dataResult.msg}"); |
| | | throw new BusinessException($"取消WCS任务失败,WCS反馈原因:{dataResult.msg}"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | WMSHelper.addAlarmRecord("流程异常", "高", $"取消WCS任务失败,WCS没有返回数据"); |
| | | throw new BusinessException($"取消WCS任务失败,WCS没有返回数据"); |
| | | } |
| | | } |
| | | catch (BusinessException be) |
| | | { |
| | | throw be; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | WMSHelper.addAlarmRecord("系统异常", "高", $"取消WCS任务错误,错误原因:{ex.Message}"); |
| | | throw new BusinessException($"取消WCS任务错误,错误原因:{ex.Message}"); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取设备状态 |
| | | /// </summary> |
| | | /// <param name="deviceNoList"></param> |
| | | /// <returns></returns> |
| | | public static List<DeviceStatusData> getDeviceStatus(List<string> deviceNoList) |
| | | { |
| | | List<DeviceStatusData> deviceStatusDatas = new List<DeviceStatusData>(); |
| | | |
| | | DeviceStatusModel model = new DeviceStatusModel() |
| | | { |
| | | reqId = GenerateReqId(), |
| | | reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
| | | deviceNoList = deviceNoList |
| | | }; |
| | | |
| | | var request = JsonConvert.SerializeObject(model); |
| | | try |
| | | { |
| | | var response = apiHelper.Post(baseUrl + "/api/hecWms/produceProcessTracing/trayMaterialUnBind", request); |
| | | LogHelper.Info($"[WCS-getDeviceStatus] request={request} response={response}", "WMS"); |
| | | if (response != null && response != "") |
| | | { |
| | | |
| | | var dataResult = JsonConvert.DeserializeObject<ResponseResult>(response); |
| | | if (dataResult.code == 200) |
| | | { |
| | | deviceStatusDatas = JsonConvert.DeserializeObject<List<DeviceStatusData>>(response); |
| | | } |
| | | else |
| | | { |
| | | WMSHelper.addAlarmRecord("流程异常", "高", $"获取设备状态失败,WCS反馈原因:{dataResult.msg}"); |
| | | throw new BusinessException($"获取设备状态失败,WCS反馈原因:{dataResult.msg}"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | WMSHelper.addAlarmRecord("流程异常", "高", $"获取设备状态失败,WCS没有返回数据"); |
| | | throw new BusinessException($"获取设备状态失败,WCS没有返回数据"); |
| | | } |
| | | } |
| | | catch (BusinessException be) |
| | | { |
| | | throw be; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | WMSHelper.addAlarmRecord("系统异常", "高", $"获取设备状态错误,错误原因:{ex.Message}"); |
| | | throw new BusinessException($"获取设备状态错误,错误原因:{ex.Message}"); |
| | | } |
| | | return deviceStatusDatas; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 修改任务优先级 |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | public static bool changePriority(ChangePriorityModel model) |
| | | { |
| | | var result = false; |
| | | model.reqId = GenerateReqId(); |
| | | model.reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | var request = JsonConvert.SerializeObject(model); |
| | | try |
| | | { |
| | | var response = apiHelper.Post(baseUrl + "/api/hecWms/produceProcessTracing/trayMaterialUnBind", request); |
| | | LogHelper.Info($"[WCS-changePriority] request={request} response={response}", "WMS"); |
| | | if (response != null && response != "") |
| | | { |
| | | |
| | | var dataResult = JsonConvert.DeserializeObject<ResponseResult>(response); |
| | | if (dataResult.code == 200) |
| | | { |
| | | result = true; |
| | | } |
| | | else |
| | | { |
| | | WMSHelper.addAlarmRecord("流程异常", "高", $"修改任务优先级失败,WCS反馈原因:{dataResult.msg}"); |
| | | throw new BusinessException($"修改任务优先级失败,WCS反馈原因:{dataResult.msg}"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | WMSHelper.addAlarmRecord("流程异常", "高", $"修改任务优先级失败,WCS没有返回数据"); |
| | | throw new BusinessException($"修改任务优先级失败,WCS没有返回数据"); |
| | | } |
| | | } |
| | | catch (BusinessException be) |
| | | { |
| | | throw be; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | WMSHelper.addAlarmRecord("系统异常", "高", $"修改任务优先级错误,错误原因:{ex.Message}"); |
| | | throw new BusinessException($"修改任务优先级错误,错误原因:{ex.Message}"); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// AGV安全交互 |
| | | /// </summary> |
| | | /// <param name="req_no"></param> |
| | | /// <param name="locCode"></param> |
| | | /// <param name="type"></param> |
| | | /// <returns></returns> |
| | | public static bool safetyInteraction(string req_no, string locCode, string type) |
| | | { |
| | | var result = false; |
| | | LocStateModel model = new LocStateModel() |
| | | { |
| | | req_no = req_no, |
| | | loc_code = locCode, |
| | | type = type |
| | | }; |
| | | |
| | | var request = JsonConvert.SerializeObject(model); |
| | | try |
| | | { |
| | | var response = apiHelper.Post(baseUrl + "/api/hecWms/produceProcessTracing/trayMaterialUnBind", request); |
| | | LogHelper.Info($"[WCS-changePriority] request={request} response={response}", "WMS"); |
| | | if (response != null && response != "") |
| | | { |
| | | |
| | | var dataResult = JsonConvert.DeserializeObject<ResponseResult>(response); |
| | | if (dataResult.code == 200) |
| | | { |
| | | result = true; |
| | | } |
| | | else |
| | | { |
| | | WMSHelper.addAlarmRecord("流程异常", "高", $"AGV安全交互请求失败,WCS反馈原因:{dataResult.msg}"); |
| | | throw new BusinessException($"AGV安全交互请求失败,WCS反馈原因:{dataResult.msg}"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | WMSHelper.addAlarmRecord("流程异常", "高", $"AGV安全交互请求失败,WCS没有返回数据"); |
| | | throw new BusinessException($"AGV安全交互请求失败,WCS没有返回数据"); |
| | | } |
| | | } |
| | | catch (BusinessException be) |
| | | { |
| | | throw be; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | WMSHelper.addAlarmRecord("系统异常", "高", $"AGV安全交互请求错误,错误原因:{ex.Message}"); |
| | | throw new BusinessException($"AGV安全交互请求错误,错误原因:{ex.Message}"); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public class LocStateModel |
| | | { |
| | | public string req_no { get; set; } // 请求id |
| | | public string loc_code { get; set; } // 货位 |
| | | public string type { get; set; } // 货位 1 请求取货 2 请求放货 3 取货完成离开信号 4 放货完成离开信号 |
| | | } |
| | | |
| | | public class ChangePriorityModel |
| | | { |
| | | public string reqId { get; set; } // 请求id |
| | | public string reqTime { get; set; } // 请求时间 |
| | | public string taskNo { get; set; } // 任务号 |
| | | public int priority { get; set; } // 优先级 |
| | | } |
| | | |
| | | public class DeviceStatusData |
| | | { |
| | | public string deviceNo { get; set; } // 设备号 |
| | | public int workStatus { get; set; } // 工作状态 1可用,2不可用 |
| | | public int photoStatus { get; set; } // 光电状态 1是空载 ,2是有载 |
| | | public int manualStatus { get; set; } //手动状态 0.禁用 1.启用 |
| | | } |
| | | |
| | | public class DeviceStatusModel |
| | | { |
| | | public string reqId { get; set; } // 请求id |
| | | public string reqTime { get; set; } // 请求时间 |
| | | public List<string> deviceNoList { get; set; } // 设备号 |
| | | } |
| | | |
| | | public class CancelTaskModel |
| | | { |
| | | public string reqId { get; set; } // 请求id |
| | | public string reqTime { get; set; } // 请求时间 |
| | | public string taskNo { get; set; } // 任务号 |
| | | } |
| | | |
| | | public class SendTaskModel |
| | | { |
| | | public string reqId { get; set; } // 请求id |
| | | public string reqTime { get; set; } // 请求时间 |
| | | public string taskNo { get; set; } // 任务号 |
| | | public int groupNo { get; set; } // 任务组 |
| | | public string taskType { get; set; } // 任务类型 1.物料入库 2.物料出库 |
| | | public string from { get; set; } // 起点 |
| | | public string to { get; set; } // 终点 |
| | | public string cntrNo { get; set; } // 容器编码 |
| | | public string cntrType { get; set; } // 容器类型 |
| | | public List<object> extData { get; set; } // 容器类型 |
| | | |
| | | } |
| | | } |
| | | } |