1
xby-y
2026-01-12 c1eac732fc3ef407d51b76d288f311d2fa43e618
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -546,7 +546,7 @@
            ApiResponse<object> apiResponse = new ApiResponse<object>();
            apiResponse.Message = Message;
            apiResponse.Success = Success;
            apiResponse.Code = 1;
            apiResponse.Code = Code;
            return apiResponse;
        }
@@ -880,7 +880,7 @@
        /// <param name="taskNum"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public WebResponseContent ManualTaskCompleted(string palletTaskDTO)
        public ApiResponse<object> ManualTaskCompleted(string palletTaskDTO)
        {
            WebResponseContent webResponse = new WebResponseContent();
            try
@@ -889,7 +889,7 @@
                Dt_Task task = BaseDal.QueryFirst(x => x.PalletCode == palletTaskDTO);
                if (task == null)
                {
                    return webResponse.Error($"未找到托盘编码为【{palletTaskDTO}】的任务信息");
                    return MESresponse($"未找到托盘编码为【{palletTaskDTO}】的任务信息", false, 0);
                }
@@ -910,14 +910,15 @@
                if (task.TaskType == TaskInboundTypeEnum.Inbound.ObjToInt() || task.TaskType == TaskRelocationTypeEnum.Relocation.ObjToInt())
                {
                    stockmsseg = _stockRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
                    if (stockmsseg == null) { return webResponse.Error("未找到库存信息"); };
                    if (stockmsseg == null) { return MESresponse($"未找到库存信息", false, 0); }
                    ;
                    stockmsseg.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                     resstock = _stockRepository.UpdateData(stockmsseg);
                    if (task.TaskType == TaskRelocationTypeEnum.Relocation.ObjToInt())
                    {
                        locationmsseg1 = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
                        locationmsseg2 = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.CurrentAddress);
                        if (locationmsseg1 == null || locationmsseg2 == null) { webResponse.Error("未找到货位信息"); }
                        if (locationmsseg1 == null || locationmsseg2 == null) { return MESresponse($"未找到货位信息", false, 0); }
                        locationmsseg1.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
                        locationmsseg2.LocationStatus = LocationStatusEnum.Free.ObjToInt();
                        location1 = _locationInfoRepository.UpdateData(locationmsseg1);
@@ -926,7 +927,7 @@
                    else
                    {
                        locationmsseg1 = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
                        if (locationmsseg1 == null) { webResponse.Error("未找到货位信息"); }
                        if (locationmsseg1 == null) { return MESresponse($"未找到货位信息", false, 0); }
                        locationmsseg1.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
                        location1 = _locationInfoRepository.UpdateData(locationmsseg1);
                        
@@ -935,10 +936,10 @@
                else
                {
                    stockmsseg = _stockRepository.QueryFirst(x => x.LocationCode == task.CurrentAddress);
                    if (stockmsseg == null) { return webResponse.Error("未找到库存信息"); }
                    if (stockmsseg == null) { return MESresponse($"未找到库存信息", false, 0); }
                    resstock = _stockRepository.DeleteData(stockmsseg);
                    locationmsseg1 = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.CurrentAddress);
                    if (locationmsseg1 == null) { webResponse.Error("未找到货位信息"); }
                    if (locationmsseg1 == null) { return MESresponse($"未找到货位信息", false, 0); }
                    locationmsseg1.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
                    location1 = _locationInfoRepository.UpdateData(locationmsseg1);
                }
@@ -952,7 +953,7 @@
                if (WCSReceiveTaskAPI == null)
                {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"任务手动完成失败,未配置WCS任务手动完成反馈接口");
                    return MESresponse($"任务手动完成失败,未配置WCS任务手动完成反馈接口", false, 0);
                }
                string apiUrl = $"{WCSReceiveTaskAPI}?taskNum={task.TaskNum}";
@@ -961,53 +962,144 @@
                if (respon == null)
                {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"WCS调取接口失败,反馈参数为空");
                    return MESresponse($"WCS调取接口失败,反馈参数为空", false, 0);
                }
                var response = JsonConvert.DeserializeObject<ApiResponse<object>>(respon);
                if (!response.status)
                {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"WCS调取接口失败,反馈参数原因:{response.Message}");
                    return MESresponse($"WCS调取接口失败,反馈参数原因:{response.Message}", false, 0);
                }
                if (!(resstock && task_htymsseg && taskmsseg && task.TaskType == TaskRelocationTypeEnum.Relocation.ObjToInt() ? (location1 && location2) : location1))
                    {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"任务手动完成失败");
                    return MESresponse($"任务手动完成失败", false, 0);
                }
                //获取接口进行调取
                var MESConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_MES_IPAddress, SysConfigConst.MESmockComplete);      //获取到wcs全部类型的接口
                string MESmockComplete = MESConfigsAPIInfo.ApiAddress + MESConfigsAPIInfo.ApiName;
                if (MESConfigsAPIInfo == null)
                ////获取接口进行调取
                //var MESConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_MES_IPAddress, SysConfigConst.MESmockComplete);      //获取到wcs全部类型的接口
                //string MESmockComplete = MESConfigsAPIInfo.ApiAddress + MESConfigsAPIInfo.ApiName;
                //if (MESConfigsAPIInfo == null)
                //{
                //    _unitOfWorkManage.RollbackTran();
                //    return webResponse.Error($"任务手动完成失败,未配置MES任务手动完成反馈接口");
                //}
                //var MES = new
                //{
                //    businessId = task.MESbusinessId,
                //    taskId = task.MEStaskId,
                //    palletCode = task.PalletCode
                //};
                //var MESrespon = HttpHelper.Post(MESmockComplete, JsonConvert.SerializeObject(MES));
                //if (respon == null)
                //{
                //    _unitOfWorkManage.RollbackTran();
                //    return webResponse.Error($"MES调取接口失败,反馈参数为空");
                //}
                //var MESresponse = JsonConvert.DeserializeObject<ApiResponse<object>>(MESrespon);
                //if (!MESresponse.Success)
                //{
                //    _unitOfWorkManage.RollbackTran();
                //    return webResponse.Error($"MES调取接口失败,反馈参数原因:{response.Message}");
                //}
                WebResponseContent content;
                switch (task.TaskType)
                {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"任务手动完成失败,未配置MES任务手动完成反馈接口");
                    case (int)TaskRelocationTypeEnum.Relocation:
                        content = MES_TransferCompletionFeedback(task);
                        break;
                    case (int)TaskInboundTypeEnum.Inbound:
                        content = TaskCompletionFeedback(task);
                        break;
                    case (int)TaskOutboundTypeEnum.Outbound:
                        content = TaskCompletionFeedback(task);
                        break;
                    default: return MESresponse($"任务类型错误,任务号:{task.TaskNum}", false, 0);
                }
                var MES = new
                {
                    businessId = task.MESbusinessId,
                    taskId = task.MEStaskId,
                    palletCode = task.PalletCode
                };
                var MESrespon = HttpHelper.Post(MESmockComplete, JsonConvert.SerializeObject(MES));
                if (respon == null)
                if (!content.Status)
                {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"MES调取接口失败,反馈参数为空");
                }
                var MESresponse = JsonConvert.DeserializeObject<ApiResponse<object>>(MESrespon);
                if (!MESresponse.Success)
                {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"MES调取接口失败,反馈参数原因:{response.Message}");
                    return MESresponse($"手动向MES接口报完成失败{task.TaskNum}", false, 0);
                }
                _unitOfWorkManage.CommitTran();
                return webResponse.OK("任务手动完成成功");
                return MESresponse($"任务手动完成成功{task.TaskNum}", true, 1);
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return webResponse.Error($"任务手动完成失败,原因:{ex.Message}");
                return MESresponse($"任务手动完成失败,原因:{ex.Message}", false, 0);
            }
        }
        /// <summary>
        /// èŽ·å–å®žæ—¶ä»»åŠ¡åˆ—è¡¨
        /// </summary>
        /// <returns></returns>
        public WebResponseContent GetRealTimeTasks()
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                // æŸ¥è¯¢æœ€æ–°çš„10条任务记录
                var tasks = Repository.Db.Queryable<Dt_Task>()
                    .OrderByDescending(x => x.CreateDate)
                    .Take(10)
                    .ToList();
                // è½¬æ¢ä»»åŠ¡æ•°æ®ä¸ºå‰ç«¯éœ€è¦çš„æ ¼å¼
                var result = tasks.Select(task => {
                    // è½¬æ¢ä»»åŠ¡ç±»åž‹
                    string taskTypeText = "未知";
                    switch ((TaskInboundTypeEnum)task.TaskType)
                    {
                        case TaskInboundTypeEnum.Inbound:
                            taskTypeText = "入库";
                            break;
                        case (TaskInboundTypeEnum)TaskOutboundTypeEnum.Outbound:
                            taskTypeText = "出库";
                            break;
                        case (TaskInboundTypeEnum)TaskRelocationTypeEnum.Relocation:
                            taskTypeText = "移库";
                            break;
                    }
                    // è½¬æ¢ä»»åŠ¡çŠ¶æ€
                        string taskStatusText = "未知";
                        if ((TaskOutStatusEnum)task.TaskStatus == TaskOutStatusEnum.OutNew) {
                            taskStatusText = "待处理";
                        } else if (
                            (TaskInStatusEnum)task.TaskStatus == TaskInStatusEnum.Line_InExecuting ||
                            (TaskInStatusEnum)task.TaskStatus == TaskInStatusEnum.SC_InExecuting ||
                            (TaskOutStatusEnum)task.TaskStatus == TaskOutStatusEnum.SC_OutExecuting ||
                            (TaskOutStatusEnum)task.TaskStatus == TaskOutStatusEnum.Line_OutExecuting
                        ) {
                            taskStatusText = "运行中";
                        } else if (
                            (TaskInStatusEnum)task.TaskStatus == TaskInStatusEnum.InFinish ||
                            (TaskOutStatusEnum)task.TaskStatus == TaskOutStatusEnum.OutFinish
                        ) {
                            taskStatusText = "已完成";
                        }
                        return new {
                            id = task.TaskId,
                            taskNum = task.TaskNum,
                            taskType = taskTypeText,
                            sourceAddress = task.SourceAddress,
                            targetAddress = task.TargetAddress,
                            taskStatus = taskStatusText
                        };
                }).ToList();
                return content.OK(data: result);
            }
            catch (Exception ex)
            {
                return content.Error(ex.Message);
            }
        }
    }