HuBingJie
昨天 ba998c70b77180668f295e65e07f3a62bf85e5ee
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -561,7 +561,7 @@
            try
            {
                // æŸ¥æ‰¾ä»»åŠ¡
                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.TaskStatus == TaskOutStatusEnum.OutFinish.ObjToInt());
                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum &&(x.TaskStatus == TaskOutStatusEnum.OutNew.ObjToInt()|| x.TaskStatus == TaskRelocationStatusEnum.RelocationNew.ObjToInt()|| x.TaskStatus == TaskInStatusEnum.Line_InExecuting.ObjToInt()));
                if (task == null)
                {
                    return webResponse.Error($"未找到任务号为【{taskNum}】的任务信息");
@@ -615,45 +615,69 @@
                }
                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.人工完成 : OperateTypeEnum.自动完成);
                //获取接口进行调取
                var ConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_MES_IPAddress, SysConfigConst.WCSCancelinventory);      //获取到wcs全部类型的接口
                var ConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_WCS_IPAddress, SysConfigConst.WCSCancelinventory);      //获取到wcs全部类型的接口
                string WCSReceiveTaskAPI = ConfigsAPIInfo.ApiAddress + ConfigsAPIInfo.ApiName;
                if (WCSReceiveTaskAPI == null)
                {
                    return webResponse.Error($"任务反馈MES失败,未配置MES任务完成反馈接口");
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"任务手动取消失败,未配置WCS任务手动取消反馈接口");
                }
                var respon = HttpHelper.Get(WCSReceiveTaskAPI, JsonConvert.SerializeObject(task.TaskNum));
                if (respon != null)
                if (respon == null)
                {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"调取接口失败,反馈参数为空");
                }
                    var response = JsonConvert.DeserializeObject<ApiResponse<object>>(respon);
                    //    if (response.Success)
                    //    {
                    //        return webResponse.OK();
                    //    }
                    //    else
                    //    {
                    //        return webResponse.Error($"调取接口失败,反馈参数原因:{response.Message}");
                    //    }
                    //}
                    //else
                    //{
                    //    return webResponse.Error($"调取接口失败,反馈参数为空");
                    //}
                    if (stockmsseg > 0 && locationmsseg > 0 && taskmsseg)
                if (!response.Success)
                    {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"调取接口失败,反馈参数原因:{response.Message}");
                }
                if (stockmsseg <= 0 && locationmsseg <= 0 && taskmsseg)
                    {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error("任务取消失败");
                    }
                //获取接口进行调取
                var MESConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_MES_IPAddress, SysConfigConst.MEScancelTask);      //获取到MES全部类型的接口
                string MEScancelTask = ConfigsAPIInfo.ApiAddress + ConfigsAPIInfo.ApiName;
                if (MEScancelTask == null)
                {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"任务手动完成失败,未配置WCS任务手动完成反馈接口");
                }
                var MES = new
                {
                    businessId = task.MESbusinessId,
                    taskId = task.MEStaskId,
                    palletCode = task.PalletCode
                };
                var MESrespon = HttpHelper.Post(MEScancelTask, JsonConvert.SerializeObject(MES));
                if (respon == null)
                {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"调取接口失败,反馈参数为空");
                }
                var MESresponse = JsonConvert.DeserializeObject<ApiResponse<object>>(respon);
                if (!response.Success)
                {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"调取接口失败,反馈参数原因:{response.Message}");
                }
                        _unitOfWorkManage.CommitTran();
                        return webResponse.OK("任务取消成功");
                    }
                }
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return webResponse.Error($"取消任务失败,原因:{ex.Message}");
            }
            _unitOfWorkManage.RollbackTran();
            return webResponse.Error("任务取消失败");
        }
        /// <summary>
@@ -832,5 +856,139 @@
            }
        }
        /// <summary>
        /// æ‰‹åŠ¨å®ŒæˆæŽ¥å£
        /// </summary>
        /// <param name="taskNum"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public WebResponseContent ManualTaskCompleted(int taskNum)
        {
            WebResponseContent webResponse = new WebResponseContent();
            try
            {
                // æŸ¥æ‰¾ä»»åŠ¡
                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
                if (task == null)
                {
                    return webResponse.Error($"未找到任务号为【{taskNum}】的任务信息");
                }
                Dt_StockInfo stockInfo = _stockRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
                _unitOfWorkManage.BeginTran();
                Dt_StockInfo stockmsseg;
                Dt_LocationInfo locationmsseg1 = null;
                Dt_LocationInfo locationmsseg2 = null;
                bool taskmsseg;
                bool task_htymsseg;
                bool location1;
                bool location2 = false;
                bool resstock;
                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("未找到库存信息"); };
                    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("未找到货位信息"); }
                        locationmsseg1.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
                        locationmsseg2.LocationStatus = LocationStatusEnum.Free.ObjToInt();
                        location1 = _locationInfoRepository.UpdateData(locationmsseg1);
                        location2 = _locationInfoRepository.UpdateData(locationmsseg2);
                    }
                    else
                    {
                        locationmsseg1 = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
                        if (locationmsseg1 == null) { webResponse.Error("未找到货位信息"); }
                        locationmsseg1.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
                        location1 = _locationInfoRepository.UpdateData(locationmsseg1);
                    }
                }
                else
                {
                    stockmsseg = _stockRepository.QueryFirst(x => x.LocationCode == task.CurrentAddress);
                    if (stockmsseg == null) { return webResponse.Error("未找到库存信息"); }
                    resstock = _stockRepository.DeleteData(stockmsseg);
                    locationmsseg1 = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.CurrentAddress);
                    if (locationmsseg1 == null) { webResponse.Error("未找到货位信息"); }
                    locationmsseg1.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
                    location1 = _locationInfoRepository.UpdateData(locationmsseg1);
                }
                taskmsseg = BaseDal.DeleteData(task);
                task_htymsseg = BaseDal.DeleteAndMoveIntoHty(task,OperateTypeEnum.人工完成);
                //获取接口进行调取
                var ConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_WCS_IPAddress, SysConfigConst.WCSManualTaskCompleted);      //获取到wcs全部类型的接口
                string WCSReceiveTaskAPI = ConfigsAPIInfo.ApiAddress + ConfigsAPIInfo.ApiName;
                if (WCSReceiveTaskAPI == null)
                {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"任务手动完成失败,未配置WCS任务手动完成反馈接口");
                }
                var respon = HttpHelper.Get(WCSReceiveTaskAPI, JsonConvert.SerializeObject(task.TaskNum));
                if (respon == null)
                {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"调取接口失败,反馈参数为空");
                }
                var response = JsonConvert.DeserializeObject<ApiResponse<object>>(respon);
                if (!response.Success)
                {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"调取接口失败,反馈参数原因:{response.Message}");
                }
                if (!(resstock && task_htymsseg && taskmsseg && task.TaskType ==TaskOutboundTypeEnum.Outbound.ObjToInt() ? location1 : (location1 && location2)))
                    {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"任务手动完成失败");
                }
                //获取接口进行调取
                var MESConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_MES_IPAddress, SysConfigConst.MESmockComplete);      //获取到wcs全部类型的接口
                string MESmockComplete = ConfigsAPIInfo.ApiAddress + ConfigsAPIInfo.ApiName;
                if (MESConfigsAPIInfo == null)
                {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"任务手动完成失败,未配置WCS任务手动完成反馈接口");
                }
                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($"调取接口失败,反馈参数为空");
                }
                var MESresponse = JsonConvert.DeserializeObject<ApiResponse<object>>(respon);
                if (!response.Success)
                {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"调取接口失败,反馈参数原因:{response.Message}");
                }
                _unitOfWorkManage.CommitTran();
                return webResponse.OK("任务手动完成成功");
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return webResponse.Error($"任务手动完成失败,原因:{ex.Message}");
            }
        }
    }
}