| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection.Metadata; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common; |
| | |
| | | /// <returns></returns> |
| | | public WebResponseContent ShelfOutboundCarry(Dt_Task outTask) |
| | | { |
| | | Dt_CachePoint cachePoint = GetCachePointByStartPoint(outTask.TargetAddress); |
| | | //夿æ¯å¦ä¸ºçµè¯åºï¼è¾
æåºäººå·¥å¤ç(ç«åºç®æ å°åè½¬æ¢æAGVç«ç¹å°å) |
| | | if (!outTask.Roadway.Contains("CP")) return WebResponseContent.Instance.OK(); |
| | | Dt_RoadwayInfo dt_RoadwayInfo = _basicService.RoadwayInfoService.Repository.QueryFirst(x => x.OutSCStationCode == outTask.TargetAddress); |
| | | if (dt_RoadwayInfo == null) return WebResponseContent.Instance.OK(); |
| | | Dt_CachePoint startcachePoint = new Dt_CachePoint(); |
| | | Dt_CachePoint cachePoint = GetCachePointByStartPoint(dt_RoadwayInfo.OutStationCode, ref startcachePoint); |
| | | |
| | | Dt_Task task = new() |
| | | { |
| | | CurrentAddress = outTask.TargetAddress, |
| | | CurrentAddress = startcachePoint.PointCode, |
| | | Grade = 0, |
| | | NextAddress = cachePoint.PointCode, |
| | | OrderNo = outTask.OrderNo, |
| | | PalletCode = outTask.PalletCode + "-AGV", |
| | | Roadway = "", |
| | | SourceAddress = outTask.TargetAddress, |
| | | SourceAddress = startcachePoint.PointCode, |
| | | TargetAddress = cachePoint.PointCode, |
| | | SourceKey = outTask.TaskId, |
| | | //TaskNum = outTask.TaskNum, |
| | | TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)), |
| | | TaskStatus = AGVTaskStatusEnum.AGV_New.ObjToInt(), |
| | | TaskStatus = AGVTaskStatusEnum.Create.ObjToInt(), |
| | | TaskType = TaskTypeEnum.AGVCarry.ObjToInt(), |
| | | CreateDate = DateTime.Now, |
| | | Creater = App.User.UserId > 0 ? App.User.UserName : "System", |
| | | }; |
| | | cachePoint.PointStatus = LocationStatusEnum.Lock.ObjToInt(); |
| | | startcachePoint.PointStatus = LocationStatusEnum.Lock.ObjToInt(); |
| | | |
| | | _basicService.CachePointService.Repository.UpdateData(cachePoint); |
| | | _basicService.CachePointService.Repository.UpdateData(startcachePoint); |
| | | Repository.AddData(task); |
| | | SendAGVTask(task, cachePoint); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è´§ä½ç»å® |
| | | /// </summary> |
| | | /// <param name="qty"></param> |
| | | /// <param name="Point"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent Bind(string qty, string point) |
| | | { |
| | | try |
| | | { |
| | | if (Repository.QueryFirst(x => x.SourceAddress == point && |
| | | x.TaskStatus < AGVTaskStatusEnum.DoneFetch.ObjToInt() || |
| | | x.TargetAddress == point) != null) |
| | | throw new Exception($"ç«ç¹ã{point}ãåå¨ä»»å¡ï¼"); |
| | | Dt_CachePoint? cachePoint = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == point); |
| | | if (cachePoint == null) throw new Exception("æªæ¾å°ç¼åç¹!"); |
| | | if (cachePoint.AreaId != 4) throw new Exception("å½åç¼åç¹åºåæ ç»å®æé!"); |
| | | cachePoint.PointStatus = LocationStatusEnum.InStock.ObjToInt(); |
| | | cachePoint.Remark = qty; |
| | | cachePoint.Modifier = App.User.UserName; |
| | | _basicService.CachePointService.Repository.UpdateData(cachePoint); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// éæ¾ç¼åç¹ |
| | | /// </summary> |
| | | /// <param name="point"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent AcrossFloorCallMat(string point) |
| | | { |
| | | try |
| | | { |
| | | if (Repository.QueryFirst(x => x.SourceAddress == point && |
| | | x.TaskStatus < AGVTaskStatusEnum.DoneFetch.ObjToInt() || |
| | | x.TargetAddress == point) != null) |
| | | throw new Exception($"ç«ç¹ã{point}ãåå¨ä»»å¡ï¼"); |
| | | Dt_CachePoint? cachePoint = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == point); |
| | | if (cachePoint == null) throw new Exception("æªæ¾å°ç¼åç¹!"); |
| | | if (cachePoint.AreaId != 2 && cachePoint.AreaId != 5 && cachePoint.AreaId != 8) |
| | | throw new Exception("å½åç¼åç¹åºåæ éæ¾æé!"); |
| | | cachePoint.PointStatus = LocationStatusEnum.Free.ObjToInt(); |
| | | _basicService.CachePointService.Repository.UpdateData(cachePoint); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | /// <param name="endPoint"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent CallMateriel(SaveModel saveModel) |
| | | public WebResponseContent CallMateriel(string endPoint) |
| | | { |
| | | try |
| | | { |
| | | string endPoint = saveModel.MainData["endPoint"].ToString(); |
| | | if (Repository.QueryFirst(x => x.SourceAddress == endPoint && |
| | | x.TaskStatus < AGVTaskStatusEnum.DoneFetch.ObjToInt() || |
| | | x.TargetAddress == endPoint) != null) |
| | | throw new Exception($"ç«ç¹ã{endPoint}ãåå¨ä»»å¡ï¼"); |
| | | |
| | | Dt_CachePoint cachePoint = GetCachePointByEndPoint(endPoint); |
| | | |
| | |
| | | TargetAddress = endPoint, |
| | | SourceKey = 0, |
| | | TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)), |
| | | TaskStatus = AGVTaskStatusEnum.AGV_New.ObjToInt(), |
| | | TaskStatus = AGVTaskStatusEnum.Create.ObjToInt(), |
| | | TaskType = TaskTypeEnum.AGVCarry.ObjToInt(), |
| | | }; |
| | | cachePoint.PointStatus = LocationStatusEnum.Lock.ObjToInt(); |
| | | |
| | | Db.Ado.BeginTran(); |
| | | var response = SendAGVTask(task, cachePoint); |
| | | if (!response.Status) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error($"{response.Message}"); |
| | | } |
| | | _basicService.CachePointService.Repository.UpdateData(cachePoint); |
| | | Repository.AddData(task); |
| | | Db.Ado.CommitTran(); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | /// <param name="startPoint"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent MaterielCarry(SaveModel saveModel) |
| | | public WebResponseContent MaterielCarry(string startPoint) |
| | | { |
| | | try |
| | | { |
| | | string startPoint = saveModel.MainData["startPoint"].ToString(); |
| | | |
| | | Dt_CachePoint cachePoint = GetCachePointByStartPoint(startPoint); |
| | | if (Repository.QueryFirst(x => x.SourceAddress == startPoint && |
| | | x.TaskStatus < AGVTaskStatusEnum.DoneFetch.ObjToInt() || |
| | | x.TargetAddress == startPoint) != null) |
| | | throw new Exception($"ç«ç¹ã{startPoint}ãåå¨ä»»å¡ï¼"); |
| | | Dt_CachePoint startcachePoint = new Dt_CachePoint(); |
| | | Dt_CachePoint cachePoint = GetCachePointByStartPoint(startPoint, ref startcachePoint); |
| | | |
| | | Dt_Task task = new() |
| | | { |
| | |
| | | TargetAddress = cachePoint.PointCode, |
| | | SourceKey = 0, |
| | | TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)), |
| | | TaskStatus = AGVTaskStatusEnum.AGV_New.ObjToInt(), |
| | | TaskStatus = AGVTaskStatusEnum.Create.ObjToInt(), |
| | | TaskType = TaskTypeEnum.AGVCarry.ObjToInt(), |
| | | }; |
| | | cachePoint.PointStatus = LocationStatusEnum.Lock.ObjToInt(); |
| | | |
| | | Db.Ado.BeginTran(); |
| | | var response = SendAGVTask(task, cachePoint); |
| | | if (!response.Status) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error($"{response.Message}"); |
| | | } |
| | | _basicService.CachePointService.Repository.UpdateData(cachePoint); |
| | | Repository.AddData(task); |
| | | Db.Ado.CommitTran(); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æ¬è¿ |
| | | /// </summary> |
| | | /// <param name="startPoint"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | private Dt_CachePoint GetCachePointByStartPoint(string startPoint, ref Dt_CachePoint startcachePoint) |
| | | { |
| | | #region MyRegion |
| | | Dt_CachePoint? StartcachePoint = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == startPoint); |
| | | if (StartcachePoint == null) throw new Exception("æªæ¾å°ç¼åç¹!"); |
| | | startcachePoint = StartcachePoint; |
| | | Dt_AreaRouter areaRouter = _basicService.AreaRouterService.Repository.QueryFirst(x => x.StartArea == StartcachePoint.AreaId.ToString()); |
| | | if (areaRouter == null) throw new Exception("æªæ¾å°è·¯ç±ä¿¡æ¯!"); |
| | | |
| | | Dt_CachePoint? cachePoint = _basicService.CachePointService.AssignCachePoint(areaRouter.NextArea.ObjToInt()); |
| | | if (cachePoint == null) |
| | | { |
| | | throw new Exception("æªæ¾å°ç©ºé²ç¼åç¹!"); |
| | | } |
| | | #endregion |
| | | |
| | | return cachePoint; |
| | | } |
| | | /// <summary> |
| | | /// 嫿 |
| | | /// </summary> |
| | | /// <param name="endPoint"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | private Dt_CachePoint GetCachePointByEndPoint(string endPoint) |
| | | { |
| | | #region MyRegion |
| | | Dt_CachePoint? StartcachePoint = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == endPoint); |
| | | if (StartcachePoint == null) throw new Exception("æªæ¾å°ç¼åç¹!"); |
| | | |
| | | Dt_AreaRouter areaRouter = _basicService.AreaRouterService.Repository.QueryFirst(x => x.NextArea == StartcachePoint.AreaId.ToString()); |
| | | if (areaRouter == null) throw new Exception("æªæ¾å°è·¯ç±ä¿¡æ¯!"); |
| | | |
| | | Dt_CachePoint? cachePoint = _basicService.CachePointService.GetIbStockCachePoint(areaRouter.StartArea.ObjToInt()); |
| | | if (cachePoint == null) |
| | | { |
| | | throw new Exception("æªæ¾å°æè´§ç¼åç¹!"); |
| | | } |
| | | #endregion |
| | | return cachePoint; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä¸åAGVä»»å¡ |
| | | /// </summary> |
| | | /// <param name="task"></param> |
| | | public WebResponseContent SendAGVTask(Dt_Task task, Dt_CachePoint? cachePoint = null) |
| | | { |
| | | try |
| | | { |
| | | AGVSendTaskModel aGVSendTask = new AGVSendTaskModel |
| | | { |
| | | task_id = task.TaskNum.ToString(), |
| | | src_pos = task.CurrentAddress, |
| | | site_value_type = 1, |
| | | dst_pos = task.NextAddress |
| | | }; |
| | | if (cachePoint != null && cachePoint.AreaId == 4) aGVSendTask.src_level = cachePoint.Remark.ObjToInt() - 1; |
| | | var response = HttpHelper.Post<WebResponseContent>(AGVurl + "sendTask/", aGVSendTask, "嫿任å¡ä¸å"); |
| | | if (response.Code != 200) throw new Exception(response.Message); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | private Dt_CachePoint GetCachePointByStartPoint(string startPoint) |
| | | { |
| | | Dt_AreaRouter areaRouter = _basicService.AreaRouterService.Repository.QueryFirst(x => x.StartArea == startPoint); |
| | | if (areaRouter == null) |
| | | { |
| | | throw new Exception("æªæ¾å°è·¯ç±ä¿¡æ¯"); |
| | | } |
| | | Dt_AreaInfo areaInfo = _basicService.AreaInfoService.Repository.QueryFirst(x => x.AreaCode == areaRouter.NextArea); |
| | | if (areaInfo == null) |
| | | { |
| | | throw new Exception("æªæ¾å°ä¸ä¸åºåä¿¡æ¯"); |
| | | } |
| | | |
| | | Dt_CachePoint? cachePoint = _basicService.CachePointService.AssignCachePoint(areaInfo.Id); |
| | | if (cachePoint == null) |
| | | { |
| | | throw new Exception("æªæ¾å°ç©ºé²ç¼åç¹"); |
| | | } |
| | | |
| | | return cachePoint; |
| | | } |
| | | |
| | | private Dt_CachePoint GetCachePointByEndPoint(string endPoint) |
| | | { |
| | | Dt_AreaRouter areaRouter = _basicService.AreaRouterService.Repository.QueryFirst(x => x.NextArea == endPoint); |
| | | if (areaRouter == null) |
| | | { |
| | | throw new Exception("æªæ¾å°è·¯ç±ä¿¡æ¯"); |
| | | } |
| | | Dt_AreaInfo areaInfo = _basicService.AreaInfoService.Repository.QueryFirst(x => x.AreaCode == areaRouter.StartArea); |
| | | if (areaInfo == null) |
| | | { |
| | | throw new Exception("æªæ¾å°èµ·ç¹ç¼ååºåä¿¡æ¯"); |
| | | } |
| | | |
| | | Dt_CachePoint? cachePoint = _basicService.CachePointService.GetIbStockCachePoint(areaInfo.Id); |
| | | if (cachePoint == null) |
| | | { |
| | | throw new Exception("æªæ¾å°æè´§ç¼åç¹"); |
| | | } |
| | | return cachePoint; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä»»å¡ç¶æä¸æ¥ |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | public object AGVTaskFeedBack(AGVTaskFeedBackModel model) |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskId == Convert.ToInt32(model.Task_id)); |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == Convert.ToInt32(model.Task_id)); |
| | | if (task == null) |
| | | { |
| | | return new { code = 404, message = "æªæ¾å°è¯¥ä»»å¡" }; |
| | | return new { code = 404, message = "æªæ¾å°è¯¥ä»»å¡!" }; |
| | | } |
| | | |
| | | Dt_CachePoint startCachePoint = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == task.SourceAddress); |
| | | if (startCachePoint != null) |
| | | if (task.TaskStatus == ((AGVTaskStatusEnum)Enum.Parse(typeof(AGVTaskStatusEnum), model.Task_status)).ObjToInt()) |
| | | return new { code = 200, message = "æå" }; |
| | | switch ((AGVTaskStatusEnum)Enum.Parse(typeof(AGVTaskStatusEnum), model.Task_status)) |
| | | { |
| | | startCachePoint.PointStatus = LocationStatusEnum.Free.ObjToInt(); |
| | | _basicService.CachePointService.Repository.UpdateData(startCachePoint); |
| | | case AGVTaskStatusEnum.Create: |
| | | break; |
| | | case AGVTaskStatusEnum.Queuing: |
| | | task.TaskStatus = AGVTaskStatusEnum.Queuing.ObjToInt(); |
| | | break; |
| | | case AGVTaskStatusEnum.Running: |
| | | task.TaskStatus = AGVTaskStatusEnum.Running.ObjToInt(); |
| | | break; |
| | | case AGVTaskStatusEnum.DoneFetch: |
| | | { |
| | | task.TaskStatus = AGVTaskStatusEnum.DoneFetch.ObjToInt(); |
| | | Dt_CachePoint startCachePoint = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == task.SourceAddress); |
| | | if (startCachePoint != null) |
| | | { |
| | | startCachePoint.PointStatus = LocationStatusEnum.Free.ObjToInt(); |
| | | if (startCachePoint.AreaId == 4)//夿æ¯å¦ä¸ºæ¨¡ç»ç©ºæ æ¿åºå |
| | | { |
| | | var qty = (startCachePoint.Remark.ObjToInt() - 1); |
| | | if (qty > 0) startCachePoint.PointStatus = LocationStatusEnum.InStock.ObjToInt(); |
| | | startCachePoint.Remark = qty.ToString(); |
| | | } |
| | | else if (startCachePoint.AreaId == 1) |
| | | { |
| | | startCachePoint.PointStatus = LocationStatusEnum.PalletLock.ObjToInt(); |
| | | } |
| | | _basicService.CachePointService.Repository.UpdateData(startCachePoint); |
| | | } |
| | | } |
| | | break; |
| | | case AGVTaskStatusEnum.DonePut: |
| | | { |
| | | task.TaskStatus = AGVTaskStatusEnum.DonePut.ObjToInt(); |
| | | Dt_CachePoint endCachePoint = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == task.TargetAddress); |
| | | if (endCachePoint != null) |
| | | { |
| | | endCachePoint.PointStatus = LocationStatusEnum.InStock.ObjToInt(); |
| | | _basicService.CachePointService.Repository.UpdateData(endCachePoint); |
| | | } |
| | | } |
| | | break; |
| | | case AGVTaskStatusEnum.Finish: |
| | | { |
| | | task.TaskStatus = AGVTaskStatusEnum.Finish.ObjToInt(); |
| | | BaseDal.DeleteAndMoveIntoHty(task, /*App.User.UserId == 0 ?*/ OperateType.èªå¨å®æ /*: OperateType.äººå·¥å®æ*/); |
| | | return new { code = 200, message = "æå" }; |
| | | } |
| | | case AGVTaskStatusEnum.Cancel: |
| | | case AGVTaskStatusEnum.Terminate: |
| | | case AGVTaskStatusEnum.Error: |
| | | { |
| | | if (task.TaskStatus < AGVTaskStatusEnum.DoneFetch.ObjToInt()) |
| | | { |
| | | Dt_CachePoint startCachePoint = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == task.SourceAddress); |
| | | startCachePoint.PointStatus = LocationStatusEnum.InStock.ObjToInt(); |
| | | _basicService.CachePointService.Repository.UpdateData(startCachePoint); |
| | | } |
| | | task.TaskStatus = AGVTaskStatusEnum.Cancel.ObjToInt(); |
| | | BaseDal.DeleteAndMoveIntoHty(task, OperateType.èªå¨å é¤); |
| | | return new { code = 200, message = "æå" }; |
| | | } |
| | | //case AGVTaskStatusEnum.Terminate: |
| | | // task.TaskStatus = AGVTaskStatusEnum.Terminate.ObjToInt(); |
| | | // break; |
| | | //case AGVTaskStatusEnum.Error: |
| | | // task.TaskStatus = AGVTaskStatusEnum.Error.ObjToInt(); |
| | | // break; |
| | | default: |
| | | return new { code = 404, message = "æªå®ä¹ä»»å¡ç±»å!" }; |
| | | } |
| | | |
| | | Dt_CachePoint endCachePoint = _basicService.CachePointService.Repository.QueryFirst(x => x.PointCode == task.TargetAddress); |
| | | if (endCachePoint != null) |
| | | { |
| | | endCachePoint.PointStatus = LocationStatusEnum.InStock.ObjToInt(); |
| | | _basicService.CachePointService.Repository.UpdateData(endCachePoint); |
| | | } |
| | | BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.èªå¨å®æ : OperateType.äººå·¥å®æ); |
| | | //BaseDal.DeleteData(task); |
| | | |
| | | BaseDal.UpdateData(task); |
| | | return new { code = 200, message = "æå" }; |
| | | } |
| | | } |