| | |
| | | using System.Linq; |
| | | using System.Net.Http.Headers; |
| | | using System.Security.Policy; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_DTO.Agv; |
| | | using WIDESEA_External.Model; |
| | | using WIDESEAWCS_BasicInfoService; |
| | | using WIDESEAWCS_Common; |
| | | using WIDESEAWCS_Common.APIEnum; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | |
| | | private readonly IApiInfoRepository _apiInfoRepository; |
| | | private readonly ILocationInfoRepository _locationInfoRepository; |
| | | private readonly ILocationInfoService _locationInfoService; |
| | | private readonly ILocationStatusChangeRecordService _locationStatusChangeRecordService; |
| | | |
| | | private Dictionary<string, OrderByType> _taskOrderBy = new() |
| | | { |
| | |
| | | |
| | | public List<int> TaskRelocationTypes => typeof(TaskTypeEnum).GetEnumIndexList().Where(x => x >= 900 && x < 1000).ToList(); |
| | | |
| | | public TaskService(ITaskRepository BaseDal, IMapper mapper, ICacheService cacheService, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IApiInfoRepository apiInfoRepository,ILocationInfoRepository locationInfoRepository,IUnitOfWorkManage unitOfWorkManage, ILocationInfoService locationInfoService) : base(BaseDal) |
| | | public TaskService(ITaskRepository BaseDal, IMapper mapper, ICacheService cacheService, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IApiInfoRepository apiInfoRepository,ILocationInfoRepository locationInfoRepository,IUnitOfWorkManage unitOfWorkManage, ILocationInfoService locationInfoService,ILocationStatusChangeRecordService locationStatusChangeRecordService) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _cacheService = cacheService; |
| | |
| | | _locationInfoRepository = locationInfoRepository; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _locationInfoService = locationInfoService; |
| | | _locationStatusChangeRecordService=locationStatusChangeRecordService; |
| | | } |
| | | static object lock_taskReceive = new object(); |
| | | /// <summary> |
| | |
| | | BaseDal.AddData(tasks); |
| | | _locationInfoRepository.UpdateData(locationInfos); |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(tasks.Select(x => x.TaskNum).ToList(), "æ¥æ¶WMSä»»å¡"); |
| | | |
| | | _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfos, LocationStatusEnum.InStock, LocationStatusEnum.Lock, LocationChangeType.OutboundAssignLocation, tasks.Select(x => x.TaskNum).ToList()); |
| | | content = tasks.Count > 0 ? content.OK("æå!"+(errorMsg.IsNullOrEmpty()? "": errorMsg)) : content.Error("失败"); |
| | | } |
| | | } |
| | |
| | | } |
| | | return content; |
| | | } |
| | | static object lock_containerFlow = new object(); |
| | | |
| | | /// <summary> |
| | | /// 容å¨å
¥åºåå»ºä»»å¡ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent ContainerFlow(ContainerFlowDTO containerFlowDTO, string deviceCode) |
| | | public WebResponseContent ContainerFlow(ContainerFlowDTO containerFlowDTO, string deviceCode, string stationCode) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | lock (lock_containerFlow) |
| | | List<Dt_LocationInfo> locationInfos = _locationInfoRepository.QueryData(); |
| | | Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x => x.PalletCode == containerFlowDTO.ContainerCode); |
| | | if (locationInfo != null) throw new Exception($"åºä½æç®±å·{containerFlowDTO.ContainerCode}å·²åå¨"); |
| | | if (BaseDal.QueryFirst(x => x.PalletCode == containerFlowDTO.ContainerCode && x.TaskType == TaskTypeEnum.Inbound.ObjToInt() && x.TaskState == TaskStatusEnum.CL_Executing.ObjToInt() && x.DeviceCode== deviceCode) != null) |
| | | { |
| | | List<Dt_LocationInfo> locationInfos = _locationInfoRepository.QueryData(); |
| | | Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x=>x.PalletCode== containerFlowDTO.ContainerCode); |
| | | if (locationInfo != null) throw new Exception($"åºä½æç®±å·{containerFlowDTO.ContainerCode}å·²åå¨"); |
| | | if (BaseDal.QueryFirst(x=>x.PalletCode==containerFlowDTO.ContainerCode)!=null) throw new Exception($"æç®±å·{containerFlowDTO.ContainerCode}ä»»å¡å·²åå¨"); |
| | | Dt_LocationInfo? noInLocation = locationInfos.FirstOrDefault(x => x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()); |
| | | if (noInLocation == null) throw new Exception($"å¯ç¨è´§ä½ä¸è¶³!"); |
| | | Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && x.StationDeviceCode == deviceCode); |
| | | //åå»ºä»»å¡ |
| | | Dt_Task task = new Dt_Task(); |
| | | task.PalletCode = containerFlowDTO.ContainerCode; |
| | | task.SourceAddress = containerFlowDTO.SlotCode; |
| | | task.CurrentAddress = containerFlowDTO.SlotCode; |
| | | task.NextAddress = stationManger.StationCode; |
| | | task.TargetAddress = ""; |
| | | task.WMSId = ""; |
| | | task.TaskType = TaskTypeEnum.Inbound.ObjToInt(); |
| | | task.Roadway = noInLocation.RoadwayNo; |
| | | task.DeviceCode = stationManger.StationDeviceCode; |
| | | task.TaskState = TaskStatusEnum.CL_Executing.ObjToInt(); |
| | | //æ·»å ä»»å¡ |
| | | BaseDal.AddData(task); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { task.TaskNum }, "å建å
¥åºä»»å¡"); |
| | | content.OK("æå"); |
| | | return content.OK(); |
| | | } |
| | | else if(BaseDal.QueryFirst(x => x.PalletCode == containerFlowDTO.ContainerCode) != null) |
| | | { |
| | | throw new Exception($"æç®±å·{containerFlowDTO.ContainerCode}ä»»å¡å·²åå¨"); |
| | | } |
| | | Dt_LocationInfo? noInLocation = locationInfos.FirstOrDefault(x => x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()); |
| | | if (noInLocation == null) throw new Exception($"å¯ç¨è´§ä½ä¸è¶³!"); |
| | | Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && x.StationDeviceCode == deviceCode); |
| | | //åå»ºä»»å¡ |
| | | Dt_Task task = new Dt_Task(); |
| | | task.PalletCode = containerFlowDTO.ContainerCode; |
| | | task.SourceAddress = containerFlowDTO.SlotCode; |
| | | task.CurrentAddress = containerFlowDTO.SlotCode; |
| | | task.NextAddress = stationManger.StationCode; |
| | | task.TargetAddress = ""; |
| | | task.WMSId = ""; |
| | | task.TaskType = TaskTypeEnum.Inbound.ObjToInt(); |
| | | task.Roadway = noInLocation.RoadwayNo; |
| | | task.DeviceCode = stationManger.StationDeviceCode; |
| | | task.TaskState = TaskStatusEnum.CL_Executing.ObjToInt(); |
| | | //æ·»å ä»»å¡ |
| | | BaseDal.AddData(task); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { task.TaskNum }, "å建å
¥åºä»»å¡"); |
| | | content.OK("æå"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error($"é误信æ¯:{ex.Message}"); |
| | | } |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// æç§å¢åå§å |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent InitLight() |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | EPLightContent lightContent = INITIALIZATION(); |
| | | if (lightContent.Result != "0") throw new Exception($"{lightContent.Msg}"); |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// ç»æä½ä¸ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent EndLight() |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | EPLightContent lightContent = ENDWORK(); |
| | | if (lightContent.Result != "0") throw new Exception($"{lightContent.Msg}"); |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// æç§å¢äº®ç¯ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent SendLight(TaskSendLight taskSendLight) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | EPLightContent pLightContent = new EPLightContent(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | |
| | | { |
| | | lock (lock_requestInTask) |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.PalletCode == barCode && x.NextAddress == stationCode && x.TaskState == TaskStatusEnum.CL_Executing.ObjToInt()); |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.PalletCode == barCode && x.TaskType==TaskTypeEnum.Inbound.ObjToInt() && x.NextAddress == stationCode && x.TaskState == TaskStatusEnum.CL_Executing.ObjToInt()); |
| | | if (task == null) throw new Exception($"{barCode}æç®±æªæ¾å°ä»»å¡!"); |
| | | Dt_LocationInfo? locationInfo = _locationInfoService.AssignLocation(); |
| | | if (locationInfo == null) throw new Exception($"å¯ç¨è´§ä½ä¸è¶³!"); |
| | |
| | | _locationInfoRepository.UpdateData(locationInfo); |
| | | _unitOfWorkManage.CommitTran(); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { task.TaskNum }, $"åé
è´§ä½{locationInfo.LocationCode}"); |
| | | |
| | | _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, LocationStatusEnum.Free, LocationStatusEnum.Lock, LocationChangeType.InboundAssignLocation, task.TaskNum); |
| | | content.OK("æå"); |
| | | } |
| | | } |
| | |
| | | _locationInfoRepository.UpdateData(locationInfo); |
| | | BaseDal.DeleteAndMoveIntoHty(task, App.User?.UserId == 0 ? OperateTypeEnum.èªå¨å®æ : OperateTypeEnum.äººå·¥å®æ); |
| | | _unitOfWorkManage.CommitTran(); |
| | | _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, LocationStatusEnum.Lock, LocationStatusEnum.Free, LocationChangeType.OutboundCompleted, task.TaskNum); |
| | | } |
| | | else if(task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//å
¥åºä»»å¡å®æé»è¾ |
| | | { |
| | |
| | | _locationInfoRepository.UpdateData(locationInfo); |
| | | BaseDal.DeleteAndMoveIntoHty(task, App.User?.UserId == 0 ? OperateTypeEnum.èªå¨å®æ : OperateTypeEnum.äººå·¥å®æ); |
| | | _unitOfWorkManage.CommitTran(); |
| | | _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, LocationStatusEnum.Lock, LocationStatusEnum.InStock, LocationChangeType.InboundCompleted, task.TaskNum); |
| | | } |
| | | content.OK("ä»»å¡å®æ"); |
| | | } |