wangxinhui
2 天以前 6d3ea08855337c0cfcc60df2903d3431611c7097
ÏîÄ¿´úÂë/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs
@@ -24,8 +24,10 @@
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;
@@ -63,6 +65,7 @@
        private readonly IApiInfoRepository _apiInfoRepository;
        private readonly ILocationInfoRepository _locationInfoRepository;
        private readonly ILocationInfoService _locationInfoService;
        private readonly ILocationStatusChangeRecordService _locationStatusChangeRecordService;
        private Dictionary<string, OrderByType> _taskOrderBy = new()
            {
@@ -80,7 +83,7 @@
        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;
@@ -93,6 +96,7 @@
            _locationInfoRepository = locationInfoRepository;
            _unitOfWorkManage = unitOfWorkManage;
            _locationInfoService = locationInfoService;
            _locationStatusChangeRecordService=locationStatusChangeRecordService;
        }
        static object lock_taskReceive = new object();
        /// <summary>
@@ -156,9 +160,8 @@
                    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("失败");
                }
            }
@@ -168,22 +171,27 @@
            }
            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)!=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)
                {
                    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);
@@ -204,10 +212,64 @@
                    _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;
        }
@@ -239,7 +301,7 @@
                    _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("成功");
                }
            }
@@ -513,6 +575,7 @@
                    _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)//入库任务完成逻辑
                {
@@ -548,6 +611,7 @@
                    _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("任务完成");
            }