1
HuBingJie
2025-12-25 5ea48455463691678b806badbee198699a878b5a
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -555,16 +555,16 @@
        /// </summary>
        /// <param name="taskNum">任务号</param>
        /// <returns></returns>
        public WebResponseContent Cancelinventory(int taskNum)
        public ApiResponse<object> Cancelinventory(string palletTaskDTO)
        {
            WebResponseContent webResponse = new WebResponseContent();
            try
            {
                // æŸ¥æ‰¾ä»»åŠ¡
                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.TaskStatus == TaskOutStatusEnum.OutFinish.ObjToInt());
                Dt_Task task = BaseDal.QueryFirst(x => x.PalletCode == palletTaskDTO && (x.TaskStatus == TaskOutStatusEnum.OutNew.ObjToInt()|| x.TaskStatus == TaskRelocationStatusEnum.RelocationNew.ObjToInt()|| x.TaskStatus == TaskInStatusEnum.Line_InExecuting.ObjToInt()));
                if (task == null)
                {
                    return webResponse.Error($"未找到任务号为【{taskNum}】的任务信息");
                    return MESresponse($"未找到货位信息,条码:{palletTaskDTO}", false, 0);
                }
                bool res;
@@ -583,7 +583,7 @@
                        res = false;
                        break;
                }
                if (!res) return WebResponseContent.Instance.Error("任务状态异常");
                if (!res) return MESresponse($"任务状态异常", false, 0);
                Dt_StockInfo stockInfo = _stockRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
@@ -598,10 +598,18 @@
                  .SetColumns(x => x.StockStatus == StockStatusEmun.入库完成.ObjToInt())
                  .Where(x => x.PalletCode == task.PalletCode)
                  .ExecuteCommand();
                    if (stockmsseg<=0)
                    {
                        return MESresponse($"无库存信息", false, 0);
                    }
                    locationmsseg = _locationInfoRepository.Db.Updateable<Dt_LocationInfo>()
          .SetColumns(x => x.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
          .Where(x => x.LocationCode == stockInfo.LocationCode)
          .ExecuteCommand();
                    if (locationmsseg <= 0)
                    {
                        return MESresponse($"未找到货位信息,条码:{palletTaskDTO}", false, 0);
                    }
                    taskmsseg = BaseDal.DeleteData(task);
                }
                else
@@ -610,50 +618,83 @@
                    .SetColumns(x => x.LocationStatus == LocationStatusEnum.Free.ObjToInt())
                    .Where(x => x.LocationCode == stockInfo.LocationCode)
                    .ExecuteCommand();
                    if (locationmsseg <= 0)
                    {
                        return MESresponse($"未找到货位信息,条码:{palletTaskDTO}", false, 0);
                    }
                    stockmsseg = _stockRepository.DeleteData(stockInfo).ObjToInt();
                    taskmsseg = BaseDal.DeleteData(task);
                }
                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.人工完成 : OperateTypeEnum.自动完成);
                BaseDal.DeleteAndMoveIntoHty(task,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任务完成反馈接口");
                }
                var respon = HttpHelper.Get(WCSReceiveTaskAPI, JsonConvert.SerializeObject(task.TaskNum));
                if (respon != null)
                {
                    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)
                    {
                        _unitOfWorkManage.CommitTran();
                        return webResponse.OK("任务取消成功");
                    _unitOfWorkManage.RollbackTran();
                    return MESresponse($"手动取消失败未找到wcs的配置接口", false, 0);
                }
                string apiUrl = $"{WCSReceiveTaskAPI}?taskNum={task.TaskNum}";
                var respon = HttpHelper.Get(apiUrl);
                if (respon == null)
                {
                    _unitOfWorkManage.RollbackTran();
                    return MESresponse($"wcs调取接口失败返回参数为null", false, 0);
                }
                var response = JsonConvert.DeserializeObject<ApiResponse<object>>(respon);
                if (!response.status)
                {
                    _unitOfWorkManage.RollbackTran();
                    return MESresponse($"WCS调取接口失败,反馈参数原因:{response.Message}", false, 0);
                }
                if (stockmsseg <= 0 && locationmsseg <= 0 && taskmsseg)
                    {
                    _unitOfWorkManage.RollbackTran();
                    return MESresponse($"任务取消失败", false, 0);
                    }
                }
                ////获取接口进行调取
                //var MESConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_MES_IPAddress, SysConfigConst.MEScancelTask);      //获取到MES全部类型的接口
                //string MEScancelTask = MESConfigsAPIInfo.ApiAddress + MESConfigsAPIInfo.ApiName;
                //if (MEScancelTask == null)
                //{
                //    _unitOfWorkManage.RollbackTran();
                //    return webResponse.Error($"任务手动取消失败,未配置MES任务手动取消反馈接口");
                //}
                //var MES = new
                //{
                //    businessId = task.MESbusinessId,
                //    taskId = task.MEStaskId,
                //    palletCode = task.PalletCode
                //};
                //var MESrespon = HttpHelper.Post(MEScancelTask, JsonConvert.SerializeObject(MES));
                //if (MESrespon == 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}");
                //}
                _unitOfWorkManage.CommitTran();
                return MESresponse($"任务取消成功", true, 1);
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return webResponse.Error($"取消任务失败,原因:{ex.Message}");
                return  MESresponse($"取消任务失败,原因:{ex.Message}", false, 0);
            }
            _unitOfWorkManage.RollbackTran();
            return webResponse.Error("任务取消失败");
        }
        /// <summary>
@@ -832,5 +873,142 @@
            }
        }
        /// <summary>
        /// æ‰‹åŠ¨å®ŒæˆæŽ¥å£
        /// </summary>
        /// <param name="taskNum"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public WebResponseContent ManualTaskCompleted(string palletTaskDTO)
        {
            WebResponseContent webResponse = new WebResponseContent();
            try
            {
                // æŸ¥æ‰¾ä»»åŠ¡
                Dt_Task task = BaseDal.QueryFirst(x => x.PalletCode == palletTaskDTO);
                if (task == null)
                {
                    return webResponse.Error($"未找到托盘编码为【{palletTaskDTO}】的任务信息");
                }
                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任务手动完成反馈接口");
                }
                string apiUrl = $"{WCSReceiveTaskAPI}?taskNum={task.TaskNum}";
                var respon = HttpHelper.Get(apiUrl);
                if (respon == null)
                {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"WCS调取接口失败,反馈参数为空");
                }
                var response = JsonConvert.DeserializeObject<ApiResponse<object>>(respon);
                if (!response.status)
                {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"WCS调取接口失败,反馈参数原因:{response.Message}");
                }
                if (!(resstock && task_htymsseg && taskmsseg && task.TaskType == TaskRelocationTypeEnum.Relocation.ObjToInt() ? (location1 && location2) : location1))
                    {
                    _unitOfWorkManage.RollbackTran();
                    return webResponse.Error($"任务手动完成失败");
                }
                //获取接口进行调取
                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}");
                }
                _unitOfWorkManage.CommitTran();
                return webResponse.OK("任务手动完成成功");
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return webResponse.Error($"任务手动完成失败,原因:{ex.Message}");
            }
        }
    }
}