´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs
@@ -198,6 +198,10 @@
                                content = CJCarryTaske(task, item.taskType);
                                objects.Add(content.Data);
                                break;
                            case (int)TaskTypeEnum.STUPTBY:
                                content = HKSTUPTP(task, item.taskType);
                                objects.Add(content.Data);
                                break;
                            #endregion
                            default:
                                objects.Add(new
@@ -388,7 +392,7 @@
                bool isAGV = dt_Task.TaskType == (int)TaskTypeEnum.CPInbound || dt_Task.TaskType == (int)TaskTypeEnum.CPOutbound;
                //海康
                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;
                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.STUPTBY;
                //修改原本任务优先级
                dt_Task.Grade = updateTaskPriority.taskPriority;
                #region å‡¯ä¹å£«
@@ -452,11 +456,15 @@
                        initPriority = updateTaskPriority.taskPriority//优先级
                    };
                    Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(HIKROBOTTaskGrade));
                    if (apiInfo == null) throw new Exception("未找到四向车AGV任务下发接口配置信息!请检查接口配置");
                    string response = HttpHelper.Post(apiInfo.ApiAddress, Hkrequest.Serialize());
                    if (apiInfo == null) throw new Exception("未找到海康AGV任务下发接口配置信息!请检查接口配置");
                    var headers = new Dictionary<string, string>
                    {
                        { "X-lr-request-id", DateTimeOffset.Now.ToUnixTimeSeconds().ToString() + dt_Task.WMSTaskNum }
                    };
                    string response = HttpHelper.Post(apiInfo.ApiAddress, Hkrequest.Serialize(), headers: headers);
                    HIKROBOTReturn hIKROBOTReturn = response.DeserializeObject<HIKROBOTReturn>();
                    content.OK(data: hIKROBOTReturn);
                    if (hIKROBOTReturn.code == "SUCCESS0" && hIKROBOTReturn.message == "成功")
                    if (hIKROBOTReturn.code == "SUCCESS" && hIKROBOTReturn.message == "成功")
                    {
                        BaseDal.UpdateData(dt_Task);
                        content.OK("修改{dt_Task.WMSTaskNum}任务优先级成功", dt_Task);
@@ -514,6 +522,16 @@
                var rgv = new List<Dt_RGVLocationInfo>();
                var kls = new List<Dt_KLSLocationInfo>();
                var hk = new List<Dt_HKLocationInfo>();
                List<Dt_StationInfo> pk = new List<Dt_StationInfo>();
                if (wMSUpdateLocationArea==null)
                {
                    return content.Error("请求参数不能为空");
                }
                var validWarehouseIds = new[] { 1, 2, 3, 4 };
                if (!validWarehouseIds.Contains(wMSUpdateLocationArea.WarehouseId))
                {
                    return content.Error($"无效的仓库ID:{wMSUpdateLocationArea.WarehouseId},有效值为:1-成品库,2-面料库,3-货库,4-裁剪库");
                }
                if (wMSUpdateLocationArea.WarehouseId == 1)
                {
                    var rgvList = _rGVLocationInfoService.Repository.QueryData(x => wMSUpdateLocationArea.LocationCodes.Contains(x.LocationCode)).ToList();
@@ -522,6 +540,7 @@
                        item.WarehouseId = wMSUpdateLocationArea.UpdateAreaCode.ObjToInt();
                    }
                    rgv.AddRange(rgvList);
                    _rGVLocationInfoService.Repository.UpdateData(rgv);
                }
                if (wMSUpdateLocationArea.WarehouseId == 2)
                {
@@ -532,6 +551,7 @@
                        item.WarehouseId = wMSUpdateLocationArea.UpdateAreaCode.ObjToInt();
                    }
                    kls.AddRange(KLSLocationInfoList);
                    _kLSLocationInfoService.Repository.UpdateData(kls);
                }
                if (wMSUpdateLocationArea.WarehouseId == 3)
                {
@@ -541,12 +561,18 @@
                        item.WarehouseId = wMSUpdateLocationArea.UpdateAreaCode.ObjToInt();
                    }
                    hk.AddRange(hkList);
                    _hKLocationInfoService.Repository.UpdateData(hk);
                }
                Db.Ado.BeginTran();
                _rGVLocationInfoService.UpdateData(rgv);
                _kLSLocationInfoService.UpdateData(kls);
                _hKLocationInfoService.UpdateData(hk);
                Db.Ado.CommitTran();
                if (wMSUpdateLocationArea.WarehouseId == 4)
                {
                    var pkList = _stationInfo.Repository.QueryData(x => wMSUpdateLocationArea.LocationCodes.Contains(x.StationCode)).ToList();
                    foreach (var item in pkList)
                    {
                        item.StationRegion = wMSUpdateLocationArea.UpdateAreaCode.ObjToInt();
                    }
                    pk.AddRange(pkList);
                    _stationInfo.Repository.UpdateData(pk);
                }
                content.OK();
            }
            catch (Exception ex)
@@ -1207,6 +1233,25 @@
                    }
                    content.OK(data: list);
                }
                else if (getLocationInfo.WarehouseId == 6)
                {
                    List<Dt_StationInfo> StationInfo = new List<Dt_StationInfo>();
                    if (!string.IsNullOrEmpty(getLocationInfo.AreaCode))
                        StationInfo = _stationInfo.Repository.QueryData(x => x.StationRegion == getLocationInfo.AreaCode.ObjToInt());
                    else
                        StationInfo = _stationInfo.Repository.QueryData();
                    foreach (var item in StationInfo)
                    {
                        list.Add(new
                        {
                            LoctionCode = item.StationCode,
                            LocationStatus = item.StationStatus,
                            EnableStatus = item.IsOccupied,
                            PalletCode = item.PalletCode
                        });
                    }
                    content.OK(data: list);
                }
            }
            catch (Exception ex)
            {
@@ -1239,11 +1284,11 @@
        public WebResponseContent InboundElevatorExit(string LocationCode, string containerCode)
        {
            WebResponseContent content = new WebResponseContent();
            inboundElevatorExitDTO inboundElevator=new inboundElevatorExitDTO();
            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.containerCode = containerCode;
                inboundElevator.toLocationCode = LocationCode;
                string response = HttpHelper.Post(apiInfo.ApiAddress, inboundElevator.Serialize());
                content.OK(data: response);
@@ -1280,6 +1325,9 @@
                string dataJson = wMSReturn.result.ToString();
                Exists? exists = JsonConvert.DeserializeObject<Exists>(dataJson);
                if (exists == null) throw new Exception($"WMS返回结果的result转换失败");
                //如果成功就不返回
                if (exists.taskExists) return WebResponseContent.Instance.OK();
                //如果失败了就返回exists.errorAreaCode
                return WebResponseContent.Instance.OK(exists.errorAreaCode);
            }
            catch (Exception ex)
@@ -1301,6 +1349,41 @@
            throw new NotImplementedException();
        }
        /// <summary>
        /// å¹³åº“货位上下架容器
        /// </summary>
        /// <param name="wMSUpOrDown"></param>
        /// <returns></returns>
        public WebResponseContent UpOrDownContainer(WMSUpOrDownContainerDTO wMSUpOrDown)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_StationInfo stationInfo = _stationInfo.Repository.QueryFirst(x => x.StationCode == wMSUpOrDown.locationCode) ?? throw new Exception($"未找到货位【{wMSUpOrDown.locationCode}】信息");
                if (wMSUpOrDown.direction == 1)
                {
                    stationInfo.StationStatus = LocationStatusEnum.InStock.ObjToInt();
                    stationInfo.PalletCode = wMSUpOrDown.containerCode;
                }
                else
                {
                    stationInfo.StationStatus = LocationStatusEnum.Free.ObjToInt();
                    stationInfo.PalletCode = "";
                }
                _stationInfo.UpdateData(stationInfo);
                content.OK();
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            finally
            {
                _trackloginfoService.AddTrackLog(wMSUpOrDown, content, "平库货位上下架容器", "", "");
            }
            return content;
        }
        /// <summary>
        /// å®¹å™¨æµåŠ¨è¯·æ±‚
        /// </summary>
        /// <param name="wMSContainerFlow"></param>
@@ -1308,7 +1391,7 @@
        /// <exception cref="NotImplementedException"></exception>
        public WebResponseContent ContainerRequest(WMSContainerFlow wMSContainerFlow)
        {
            WebResponseContent content =new WebResponseContent();
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_StationManger stationManger = _stationMangerService.Repository.QueryFirst(x => x.StationCode == wMSContainerFlow.slotCode) ?? throw new Exception($"未找到站台【{wMSContainerFlow.slotCode}】信息");
@@ -1323,7 +1406,7 @@
                    };
                    string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOToccupyStation.Serialize());
                    FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
                    content.OK(data:fOURBOTReturn);
                    content.OK(data: fOURBOTReturn);
                    if (fOURBOTReturn.returnCode != 0) throw new Exception(fOURBOTReturn.returnUserMsg);
                    _stationMangerService.UpdateData(stationManger);
                }
@@ -1432,7 +1515,7 @@
            }
            finally
            {
                _trackloginfoService.AddTrackLog(fOURBOTStorageStatusNotify,content, "批量更新储位状态", "", "");
                _trackloginfoService.AddTrackLog(fOURBOTStorageStatusNotify, content, "批量更新储位状态", "", "");
            }
        }
@@ -1469,7 +1552,7 @@
        /// <param name="taskDTO">任务DTO</param>
        /// <returns>返回起点库位和终点库位信息</returns>
        /// <exception cref="Exception">校验失败时抛出异常</exception>
        private  WebResponseContent ValidateLocationForTask(int taskType, TaskDTO taskDTO)
        private WebResponseContent ValidateLocationForTask(int taskType, TaskDTO taskDTO)
        {
            WebResponseContent content = new WebResponseContent();
            try
@@ -1481,7 +1564,7 @@
                    var toStation = _stationInfo.Repository.QueryFirst(x => x.StationName == taskDTO.toLocationCode)
                          ?? throw new Exception($"未找到终点库位【{taskDTO.toLocationCode}】!");
                    if (toStation.StationName != LocationStatusEnum.Free.ToString())
                    if (toStation.StationStatus != (int)LocationStatusEnum.Free)
                        throw new Exception($"终点库位【{taskDTO.toLocationCode}】库位状态不可入库!");
                }
                // å‡ºåº“类任务(需要校验起点库位)
@@ -1490,7 +1573,7 @@
                    var fromStation = _stationInfo.Repository.QueryFirst(x => x.StationName == taskDTO.fromLocationCode)
                        ?? throw new Exception($"未找到起点库位【{taskDTO.fromLocationCode}】!");
                    if (fromStation.StationName != LocationStatusEnum.InStock.ToString())
                    if (fromStation.StationStatus != (int)LocationStatusEnum.InStock)
                        throw new Exception($"起点库位【{taskDTO.fromLocationCode}】当前库位状态不可出库!");
                    if (fromStation.PalletCode != taskDTO.containerCode)
@@ -1503,31 +1586,279 @@
                    var toStation = _stationInfo.Repository.QueryFirst(x => x.StationName == taskDTO.toLocationCode)
                        ?? throw new Exception($"未找到终点库位【{taskDTO.toLocationCode}】!");
                    if (toStation.StationName != LocationStatusEnum.Free.ToString())
                    if (toStation.StationStatus != (int)LocationStatusEnum.Free)
                        throw new Exception($"终点库位【{taskDTO.toLocationCode}】库位状态不可入库!");
                    // æ ¡éªŒèµ·ç‚¹åº“位
                    var fromStation = _stationInfo.Repository.QueryFirst(x => x.StationName == taskDTO.fromLocationCode)
                        ?? throw new Exception($"未找到起点库位【{taskDTO.fromLocationCode}】!");
                    if (fromStation.StationName != LocationStatusEnum.InStock.ToString())
                    if (fromStation.StationStatus != (int)LocationStatusEnum.InStock)
                        throw new Exception($"起点库位【{taskDTO.fromLocationCode}】当前库位状态不可出库!");
                    if (fromStation.PalletCode != taskDTO.containerCode)
                        throw new Exception($"起点库位【{taskDTO.fromLocationCode}】绑定料箱号【{fromStation.PalletCode}】与任务料箱号【{taskDTO.containerCode}】不匹配!");
                }
                #endregion
               return content.OK();
                return content.OK();
            }
            catch (Exception ex)
            {
               return content.Error(ex.Message);
                return content.Error(ex.Message);
            }
        }
        /// <summary>
        /// æ›´æ–°åº“位启用禁用状态
        /// </summary>
        /// <param name="upLocationStatusDTO"></param>
        /// <returns></returns>
        public WebResponseContent UpLocationStatus(UpLocationStatusDTO upLocationStatusDTO)
        {
            WebResponseContent content = new WebResponseContent();
            List<object> resultList = new List<object>();
            try
            {
                // å‚数验证
                if (upLocationStatusDTO == null)
                {
                    return content.Error("请求参数不能为空");
                }
                if (upLocationStatusDTO.LocationNubList == null || upLocationStatusDTO.LocationNubList.Length == 0)
                {
                    return content.Error("货位编号列表不能为空");
                }
                // æ ¹æ® EnableStatus çš„值判断是启用还是禁用
                // 0=启用,3=禁用
                bool isEnable = (upLocationStatusDTO.EnableStatus == 0);
                int targetStatus = isEnable ? (int)EnableStatusEnum.Normal : (int)EnableStatusEnum.Disable;
                var updatedList = new List<object>();  // ç”¨äºŽæ‰¹é‡æ›´æ–°
                var notFoundLocations = new List<string>();
                // æˆå“åº“ (WarehouseId = 1)
                if (upLocationStatusDTO.WarehouseId == 1)
                {
                    var locationsToUpdate = new List<Dt_RGVLocationInfo>();
                    foreach (var locationCode in upLocationStatusDTO.LocationNubList)
                    {
                        var agv = _rGVLocationInfoService.Repository.QueryFirst(x => x.LocationCode == locationCode);
                        if (agv != null)
                        {
                            agv.EnableStatus = targetStatus;
                            locationsToUpdate.Add(agv);
                            resultList.Add(new
                            {
                                LoctionCode = agv.LocationCode,
                                EnableStatus = agv.EnableStatus,
                            });
                        }
                        else
                        {
                            notFoundLocations.Add(locationCode);
                        }
                    }
                    if (locationsToUpdate.Any())
                    {
                        _rGVLocationInfoService.UpdateData(locationsToUpdate);
                        string message = $"成功更新 {locationsToUpdate.Count} ä¸ªè´§ä½çš„状态";
                        if (notFoundLocations.Any())
                        {
                            message += $",未找到货位:{string.Join(",", notFoundLocations)}";
                        }
                        content.OK(data: resultList, message: message);
                    }
                    else
                    {
                        return content.Error($"未找到任何可更新的货位。未找到的货位:{string.Join(",", notFoundLocations)}");
                    }
                }
                // é¢æ–™åº“ (WarehouseId = 2)
                else if (upLocationStatusDTO.WarehouseId == 2)
                {
                    var locationsToUpdate = new List<Dt_KLSLocationInfo>();
                    foreach (var locationCode in upLocationStatusDTO.LocationNubList)
                    {
                        var kls = _kLSLocationInfoService.Repository.QueryFirst(x => x.LocationCode == locationCode);
                        if (kls != null)
                        {
                            kls.EnableStatus = targetStatus;
                            locationsToUpdate.Add(kls);
                            resultList.Add(new
                            {
                                LoctionCode = kls.LocationCode,
                                EnableStatus = kls.EnableStatus,
                            });
                        }
                        else
                        {
                            notFoundLocations.Add(locationCode);
                        }
                    }
                    if (locationsToUpdate.Any())
                    {
                        _kLSLocationInfoService.UpdateData(locationsToUpdate);
                        string message = $"成功更新 {locationsToUpdate.Count} ä¸ªè´§ä½çš„状态";
                        if (notFoundLocations.Any())
                        {
                            message += $",未找到货位:{string.Join(",", notFoundLocations)}";
                        }
                        content.OK(data: resultList, message: message);
                    }
                    else
                    {
                        return content.Error($"未找到任何可更新的货位。未找到的货位:{string.Join(",", notFoundLocations)}");
                    }
                }
                // è£å‰ªåº“ (WarehouseId = 3)
                else if (upLocationStatusDTO.WarehouseId == 3)
                {
                    var locationsToUpdate = new List<Dt_HKLocationInfo>();
                    foreach (var locationCode in upLocationStatusDTO.LocationNubList)
                    {
                        var hk = _hKLocationInfoService.Repository.QueryFirst(x => x.LocationCode == locationCode);
                        if (hk != null)
                        {
                            hk.EnableStatus = targetStatus;
                            locationsToUpdate.Add(hk);
                            resultList.Add(new
                            {
                                LoctionCode = hk.LocationCode,
                                EnableStatus = hk.EnableStatus,
                            });
                        }
                        else
                        {
                            notFoundLocations.Add(locationCode);
                        }
                    }
                    if (locationsToUpdate.Any())
                    {
                        _hKLocationInfoService.UpdateData(locationsToUpdate);
                        string message = $"成功更新 {locationsToUpdate.Count} ä¸ªè´§ä½çš„状态";
                        if (notFoundLocations.Any())
                        {
                            message += $",未找到货位:{string.Join(",", notFoundLocations)}";
                        }
                        content.OK(data: resultList, message: message);
                    }
                    else
                    {
                        return content.Error($"未找到任何可更新的货位。未找到的货位:{string.Join(",", notFoundLocations)}");
                    }
                }
                // 3-4平库
                else if (upLocationStatusDTO.WarehouseId == 4)
                {
                    var locationsToUpdate = new List<Dt_StationInfo>();
                    foreach (var locationCode in upLocationStatusDTO.LocationNubList)
                    {
                        var station = _stationInfo.Repository.QueryFirst(x => x.StationCode == locationCode);
                        if (station != null)
                        {
                            station.IsOccupied = upLocationStatusDTO.EnableStatus==0?0:1;
                            locationsToUpdate.Add(station);
                            resultList.Add(new
                            {
                                LoctionCode = station.StationCode,
                                EnableStatus = station.IsOccupied,
                            });
                        }
                        else
                        {
                            notFoundLocations.Add(locationCode);
                        }
                    }
                    if (locationsToUpdate.Any())
                    {
                        _stationInfo.UpdateData(locationsToUpdate);
                        string message = $"成功更新 {locationsToUpdate.Count} ä¸ªè´§ä½çš„状态";
                        if (notFoundLocations.Any())
                        {
                            message += $",未找到货位:{string.Join(",", notFoundLocations)}";
                        }
                        content.OK(data: resultList, message: message);
                    }
                    else
                    {
                        return content.Error($"未找到任何可更新的货位。未找到的货位:{string.Join(",", notFoundLocations)}");
                    }
                }
                else if (upLocationStatusDTO.WarehouseId == 5)
                {
                    var locationsToUpdate = new List<Dt_StationManger>();
                    foreach (var locationCode in upLocationStatusDTO.LocationNubList)
                    {
                        var station = _stationMangerService.Repository.QueryFirst(x => x.StationCode == locationCode);
                        if (station != null)
                        {
                            station.IsOccupied = upLocationStatusDTO.EnableStatus == 0 ? 0 : 1;
                            locationsToUpdate.Add(station);
                            resultList.Add(new
                            {
                                LoctionCode = station.StationCode,
                                EnableStatus = station.IsOccupied,
                            });
                        }
                        else
                        {
                            notFoundLocations.Add(locationCode);
                        }
                    }
                    if (locationsToUpdate.Any())
                    {
                        _stationMangerService.UpdateData(locationsToUpdate);
                        string message = $"成功更新 {locationsToUpdate.Count} ä¸ªè´§ä½çš„状态";
                        if (notFoundLocations.Any())
                        {
                            message += $",未找到站台:{string.Join(",", notFoundLocations)}";
                        }
                        content.OK(data: resultList, message: message);
                    }
                    else
                    {
                        return content.Error($"未找到任何可更新的站台。未找到的站台:{string.Join(",", notFoundLocations)}");
                    }
                }
                else
                {
                    return content.Error($"不支持的仓库类型:{upLocationStatusDTO.WarehouseId}");
                }
                return content;
            }
            catch (Exception ex)
            {
                return content.Error($"更新站台状态失败:{ex.Message}");
            }
        }
    }
}