dengjunjie
6 天以前 1daf7ed93fbdca2521edbd7fc1670ff3cd303806
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs
@@ -16,6 +16,7 @@
#endregion << ç‰ˆ æœ¬ æ³¨ é‡Š >>
using AutoMapper;
using Newtonsoft.Json;
using SixLabors.ImageSharp.ColorSpaces;
using SqlSugar;
using System.Collections.Generic;
@@ -55,6 +56,8 @@
        private readonly IRepository<Dt_TaskExecuteDetail> _taskExecuteDetailRepository;
        private readonly IApiInfoService _apiInfoService;
        private readonly IStationMangerService _stationMangerService;
        private readonly IStationInfoService _stationInfo;
        private readonly ITaskErrorMessageService _taskErrorMessageService;
        private readonly IMapper _mapper;
        private Dictionary<string, OrderByType> _taskOrderBy = new()
@@ -74,7 +77,7 @@
        /// </summary>
        public IRepository<Dt_Task> Repository => BaseDal;
        public TaskService(IRepository<Dt_Task> BaseDal, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, IRepository<Dt_TaskExecuteDetail> taskExecuteDetailRepository, IMapper mapper, IKLSLocationInfoService kLSLocationInfoService, IRGVLocationInfoService rGVLocationInfoService, IHKLocationInfoService hKLocationInfoService, IApiInfoService apiInfoService, ITrackloginfoService trackloginfoService, IStationMangerService stationMangerService) : base(BaseDal)
        public TaskService(IRepository<Dt_Task> BaseDal, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, IRepository<Dt_TaskExecuteDetail> taskExecuteDetailRepository, IMapper mapper, IKLSLocationInfoService kLSLocationInfoService, IRGVLocationInfoService rGVLocationInfoService, IHKLocationInfoService hKLocationInfoService, IApiInfoService apiInfoService, ITrackloginfoService trackloginfoService, IStationMangerService stationMangerService, IStationInfoService stationInfo, ITaskErrorMessageService taskErrorMessageService) : base(BaseDal)
        {
            _routerService = routerService;
            _taskExecuteDetailService = taskExecuteDetailService;
@@ -86,6 +89,8 @@
            _apiInfoService = apiInfoService;
            _trackloginfoService = trackloginfoService;
            _stationMangerService = stationMangerService;
            _stationInfo = stationInfo;
            _taskErrorMessageService = taskErrorMessageService;
        }
        public WebResponseContent ReceiveWMSTask([NotNull] List<WMSTasksDTO> taskDTOs)
        {
@@ -94,11 +99,11 @@
            {
                List<object> objects = new List<object>();
                foreach (var item in taskDTOs)
                {
                {
                    foreach (var task in item.tasks)
                    {
                        #region åˆ¤æ–­
                       var  contentStatus = TaskHelpMethods.isOkTaskInfo(task, true, true);
                        var contentStatus = TaskHelpMethods.isOkTaskInfo(task, true, true);
                        if (!contentStatus.Status)
                        {
                            objects.Add(new
@@ -107,7 +112,6 @@
                                Message = $"任务号【{task.taskCode}】{content.Message}"
                            });
                            continue;
                            //throw new Exception(content.Message);
                        }
                        if (BaseDal.QueryFirst(x => x.WMSTaskNum == task.taskCode && x.TaskType == item.taskType) != null)
                        {
@@ -119,7 +123,7 @@
                            continue;
                            //throw new Exception($"任务号【{task.taskCode}】已存在任务");
                        }
                        if (BaseDal.QueryFirst(x => x.PalletCode == task.containerCode && x.TaskType == item.taskType) != null)
                        if (BaseDal.QueryFirst(x => x.PalletCode == task.containerCode /*&& x.TaskType == item.taskType*/) != null)
                        {
                            objects.Add(new
                            {
@@ -129,7 +133,7 @@
                            continue;
                            //throw new Exception($"托盘号【{task.containerCode}】已存在任务");
                        }
                        if (BaseDal.QueryFirst(x => x.SourceAddress == task.fromLocationCode && x.TaskType == item.taskType) != null)
                        if (BaseDal.QueryFirst(x => x.SourceAddress == task.fromLocationCode && x.TaskType == item.taskType && x.TaskState < TaskStatusEnum.TakeFinish.ObjToInt()) != null)
                        {
                            objects.Add(new
                            {
@@ -142,6 +146,7 @@
                        #endregion
                        switch (item.taskType)
                        {
                            #region å‡¯ä¹å£«AGV面料库
                            case (int)TaskTypeEnum.MLInbound:
                                content = CreateKLSNewInTask(task, item.taskType);
                                objects.Add(content.Data);
@@ -150,6 +155,8 @@
                                content = CreateKLSNewOutTask(task, item.taskType);
                                objects.Add(content.Data);
                                break;
                            #endregion
                            #region æ—·è§†å››å‘车成品库
                            case (int)TaskTypeEnum.CPInbound:
                                content = CreateRGVNewInTask(task, item.taskType);
                                objects.Add(content.Data);
@@ -158,22 +165,40 @@
                                content = CreateRGVNewOutTask(task, item.taskType);
                                objects.Add(content.Data);
                                break;
                            case (int)TaskTypeEnum.CJInbound:
                            case (int)TaskTypeEnum.CPMoveInventory:
                                content = CreateRGVNewMoveTask(task, item.taskType);
                                objects.Add(content.Data);
                                break;
                            #endregion
                            #region æµ·åº·AGV
                            case (int)TaskTypeEnum.STURR:
                            case (int)TaskTypeEnum.Q1TSJ4:
                                content = CreateHKNewInTask(task, item.taskType);
                                objects.Add(content.Data);
                                break;
                            case (int)TaskTypeEnum.CJOutbound:
                            case (int)TaskTypeEnum.STU0003:
                            case (int)TaskTypeEnum.CHUKU1:
                                content = CreateHKNewOutTask(task, item.taskType);
                                objects.Add(content.Data);
                                break;
                            case (int)TaskTypeEnum.Carry:
                            case (int)TaskTypeEnum.Q3RK:
                            case (int)TaskTypeEnum.Q3CK:
                                content = CarryTask(task, item.taskType);
                                objects.Add(content.Data);
                                break;
                            case (int)TaskTypeEnum.CJCarry:
                            case (int)TaskTypeEnum.F01:
                                content = HKF01Transport(task, item.taskType);
                                break;
                            case (int)TaskTypeEnum.F04:
                            case (int)TaskTypeEnum.RK3F:
                            case (int)TaskTypeEnum.F02:
                            case (int)TaskTypeEnum.F03:
                            case (int)TaskTypeEnum.CK3F:
                                content = CJCarryTaske(task, item.taskType);
                                objects.Add(content.Data);
                                break;
                            #endregion
                            default:
                                objects.Add(new
                                {
@@ -212,7 +237,7 @@
            var deviceName = "";
            try
            {
                Dt_Task dt_Task = BaseDal.QueryFirst(x => x.WMSTaskNum == wMSCancelTask.TaskCode&&x.TaskType!=TaskTypeEnum.CPMoveInventory.ObjToInt());
                Dt_Task dt_Task = BaseDal.QueryFirst(x => x.WMSTaskNum == wMSCancelTask.TaskCode && x.TaskType != TaskTypeEnum.CPMoveInventory.ObjToInt());
                if (dt_Task == null) throw new Exception("未查询到任务号相关任务");
                // åˆ¤æ–­å½“前任务是否为凯乐士任务
@@ -221,13 +246,13 @@
                //四向车
                bool isAGV = dt_Task.TaskType == (int)TaskTypeEnum.CPInbound || dt_Task.TaskType == (int)TaskTypeEnum.CPOutbound;
                //海康
                bool isHK = dt_Task.TaskType == (int)TaskTypeEnum.Carry || dt_Task.TaskType == (int)TaskTypeEnum.CJInbound || dt_Task.TaskType == (int)TaskTypeEnum.CJInbound || dt_Task.TaskType == (int)TaskTypeEnum.CJOutbound;
                bool isHK = dt_Task.TaskType == (int)TaskTypeEnum.F01 || dt_Task.TaskType == (int)TaskTypeEnum.RK3F || dt_Task.TaskType == (int)TaskTypeEnum.CK3F || dt_Task.TaskType == (int)TaskTypeEnum.Q1TSJ4 || dt_Task.TaskType == (int)TaskTypeEnum.STU0003 || dt_Task.TaskType == (int)TaskTypeEnum.F02 || dt_Task.TaskType == (int)TaskTypeEnum.CHUKU1 || dt_Task.TaskType == (int)TaskTypeEnum.Q3RK || dt_Task.TaskType == (int)TaskTypeEnum.Q3CK || dt_Task.TaskType == (int)TaskTypeEnum.STURR;
                //这里将状态改变了198取消任务
                dt_Task.TaskType = TaskStatusEnum.WMSCancel.ObjToInt();
                #region å‡¯ä¹å£«
                if (isGALAXISTask)
                {
                    deviceName= "凯乐士AGV";
                    deviceName = "凯乐士AGV";
                    KLS = new CancelGALAXISTask
                    {
                        taskId = dt_Task.WMSTaskNum,
@@ -256,8 +281,14 @@
                if (isAGV)
                {
                    deviceName = "四向车";
                    if (dt_Task.RGVTaskId==0)
                    if (dt_Task.RGVTaskId == 0)
                    {
                        if (dt_Task.TaskType == TaskTypeEnum.CPOutbound.ObjToInt() && dt_Task.TaskState == TaskStatusEnum.RGV_WaitSend.ObjToInt())
                        {
                            //修改库位状态
                            var rgvlocaiion = _rGVLocationInfoService.Repository.QueryFirst(x => x.LocationCode == dt_Task.SourceAddress);
                            rgvlocaiion.LocationStatus = LocationStatusEnum.InStock.ObjToInt(); //将库位状态改为有货
                        }
                        BaseDal.DeleteAndMoveIntoHty(dt_Task, OperateTypeEnum.自动删除);
                        content.OK($"取消{dt_Task.WMSTaskNum}任务成功", dt_Task);
                    }
@@ -294,11 +325,16 @@
                    cancelHIKROBOTTask = new CancelHIKROBOTTask
                    {
                        robotTaskCode = dt_Task.WMSTaskNum,
                        cancelType = "CANCEL"//原软取消,DROP人工介入(原硬取消)
                        cancelType = "DROP"//原软取消,DROP人工介入(原硬取消)
                    };
                    var headers = new Dictionary<string, string>
                    {
                        { "X-lr-request-id", DateTimeOffset.Now.ToUnixTimeSeconds().ToString() + wMSCancelTask.TaskCode }
                    };
                    Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(CancelHIKROBOTTask));
                    if (apiInfo == null) throw new Exception("未找到四向车AGV任务下发接口配置信息!请检查接口配置");
                    string response = HttpHelper.Post(apiInfo.ApiAddress, cancelHIKROBOTTask.Serialize());
                    string response = HttpHelper.Post(apiInfo.ApiAddress, cancelHIKROBOTTask.Serialize(), headers: headers);
                    HIKROBOTReturn hIKROBOTReturn = response.DeserializeObject<HIKROBOTReturn>();
                    content.OK(data: hIKROBOTReturn);
                    if (hIKROBOTReturn.code == "SUCCESS" && hIKROBOTReturn.message == "成功")
@@ -352,7 +388,7 @@
                bool isAGV = dt_Task.TaskType == (int)TaskTypeEnum.CPInbound || dt_Task.TaskType == (int)TaskTypeEnum.CPOutbound;
                //海康
                bool isHK = dt_Task.TaskType == (int)TaskTypeEnum.Carry || dt_Task.TaskType == (int)TaskTypeEnum.CJInbound || dt_Task.TaskType == (int)TaskTypeEnum.CJInbound || dt_Task.TaskType == (int)TaskTypeEnum.CJOutbound;
                bool isHK = dt_Task.TaskType == (int)TaskTypeEnum.F01 || dt_Task.TaskType == (int)TaskTypeEnum.RK3F || dt_Task.TaskType == (int)TaskTypeEnum.CK3F || dt_Task.TaskType == (int)TaskTypeEnum.Q1TSJ4 || dt_Task.TaskType == (int)TaskTypeEnum.STU0003 || dt_Task.TaskType == (int)TaskTypeEnum.F02 || dt_Task.TaskType == (int)TaskTypeEnum.CHUKU1 || dt_Task.TaskType == (int)TaskTypeEnum.Q3RK || dt_Task.TaskType == (int)TaskTypeEnum.Q3CK;
                //修改原本任务优先级
                dt_Task.Grade = updateTaskPriority.taskPriority;
                #region å‡¯ä¹å£«
@@ -1092,7 +1128,9 @@
                        {
                            LoctionCode = item.LocationCode,
                            LocationStatus = item.LocationStatus,
                            EnableStatus = item.EnableStatus
                            EnableStatus = item.EnableStatus,
                            PalletCode = item.PalletCode
                        });
                    }
                    content.OK(data: list);
@@ -1110,35 +1148,62 @@
                        {
                            LoctionCode = item.LocationCode,
                            LocationStatus = item.LocationStatus,
                            EnableStatus = item.EnableStatus
                            EnableStatus = item.EnableStatus,
                            PalletCode = item.PalletCode
                        });
                    }
                    content.OK(data: list);
                }
                else if (getLocationInfo.WarehouseId == 3)
                {
                    //这里是提升机的
                    var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "TSJ") as OtherDevice;
                    if (device == null) throw new Exception("未找到提升机设备信息");
                    if (!device.IsConnected) throw new Exception("PLC1提升机设备连接失败");
                    var value = device.GetValue<HoistEnum, short>(HoistEnum.Outboundmaterialbox, "TSJC3F");
                    list.Add(new
                    {
                        LoctionCode = value,
                        LocationStatus = value != 0 ? 100 : 0,
                        EnableStatus = 0,
                    });
                    content.OK(data: list);
                }
                else if (getLocationInfo.WarehouseId == 4)
                {
                    List<Dt_HKLocationInfo> rGVLocationInfos = new List<Dt_HKLocationInfo>();
                    if (!string.IsNullOrEmpty(getLocationInfo.AreaCode))
                        rGVLocationInfos = _hKLocationInfoService.Repository.QueryData(x => x.WarehouseId == getLocationInfo.AreaCode.ObjToInt());
                    else
                        rGVLocationInfos = _hKLocationInfoService.Repository.QueryData();
                    foreach (var item in rGVLocationInfos)
                    {
                        list.Add(new
                        {
                            LoctionCode = item.LocationCode,
                            LocationStatus = item.LocationStatus,
                            EnableStatus = item.EnableStatus,
                            PalletCode = item.PalletCode
                        });
                    }
                    content.OK(data: list);
                }
                else if (getLocationInfo.WarehouseId == 5)
                {
                    //读取光电信号
                    var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "F1") as OtherDevice;
                    if (device == null) throw new Exception("未找到1楼质检门设备信息") ;
                    if (device == null) throw new Exception("未找到1楼质检门设备信息");
                    if (!device.IsConnected) throw new Exception("PLC1楼质检门设备连接失败");
                    var sta = _stationMangerService.Repository.QueryData(x => x.Remark == "成品库");
                    var sta = _stationMangerService.Repository.QueryData(x => x.StationName.Contains("成品仓"));
                    foreach (var item in sta)
                    {
                        bool value = device.GetValue<QualityInspectionCommandEnum,bool>(QualityInspectionCommandEnum.R_StockAvailableSymbol, item.StationCode);
                             list.Add(new
                             {
                                 LoctionCode = item.StationCode,
                                 LocationStatus = value?100:0,
                                 EnableStatus = 0,
                             });
                        bool value = device.GetValue<QualityInspectionCommandEnum, bool>(QualityInspectionCommandEnum.R_StockAvailableSymbol, item.StationCode);
                        list.Add(new
                        {
                            LoctionCode = item.StationCode,
                            LocationStatus = value ? 100 : 0,
                            EnableStatus = 0,
                        });
                    }
                    content.OK(data: list);
                }
@@ -1171,7 +1236,28 @@
        {
            throw new NotImplementedException();
        }
        public WebResponseContent InboundElevatorExit(string LocationCode, string containerCode)
        {
            WebResponseContent content = new WebResponseContent();
            inboundElevatorExitDTO inboundElevator=new inboundElevatorExitDTO();
            try
            {
                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(inboundElevatorExitDTO)) ?? throw new Exception("未找到4F提升机出口托盘号上报WMS接口配置信息!请检查接口配置");
                inboundElevator.containerCode= containerCode;
                inboundElevator.toLocationCode = LocationCode;
                string response = HttpHelper.Post(apiInfo.ApiAddress, inboundElevator.Serialize());
                content.OK(data: response);
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
            finally
            {
                _trackloginfoService.AddTrackLog(inboundElevator, content, "4F提升机出口托盘号上报WMS", "", "");
            }
        }
        /// <summary>
        /// æ–™ç®±éªŒè¯
        /// </summary>
@@ -1180,7 +1266,30 @@
        /// <returns></returns>
        public WebResponseContent MaterialBoxInspection(string taskCode, string containerCode)
        {
            throw new NotImplementedException();
            WebResponseContent content = new WebResponseContent();
            inboundTransportCheckDTO checkDTO = new inboundTransportCheckDTO();
            try
            {
                checkDTO.containerCode = containerCode;
                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(inboundTransportCheckDTO)) ?? throw new Exception("未找到裁片入库3F到4F运输箱号校验接口配置信息!请检查接口配置");
                string response = HttpHelper.Post(apiInfo.ApiAddress, checkDTO.Serialize());
                content.OK(data: response);
                WMSReturn wMSReturn = response.DeserializeObject<WMSReturn>();
                if (wMSReturn == null) throw new Exception("WMS返回结果转换失败!");
                if (!wMSReturn.success) throw new Exception(wMSReturn.message);
                string dataJson = wMSReturn.result.ToString();
                Exists? exists = JsonConvert.DeserializeObject<Exists>(dataJson);
                if (exists == null) throw new Exception($"WMS返回结果的result转换失败");
                return WebResponseContent.Instance.OK(exists.errorAreaCode);
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
            finally
            {
                _trackloginfoService.AddTrackLog(checkDTO, content, "裁片入库3F到4F运输箱号校验", "", "");
            }
        }
        /// <summary>
@@ -1332,6 +1441,6 @@
        }
    }
}