yanjinhui
2 天以前 e8323315b683a76509b9c1ecc717bb5b6a9ee08a
´úÂë¹ÜÀí/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,7 +522,16 @@
                var rgv = new List<Dt_RGVLocationInfo>();
                var kls = new List<Dt_KLSLocationInfo>();
                var hk = new List<Dt_HKLocationInfo>();
                var pk = new List<Dt_StationInfo>();
                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();
@@ -523,6 +540,7 @@
                        item.WarehouseId = wMSUpdateLocationArea.UpdateAreaCode.ObjToInt();
                    }
                    rgv.AddRange(rgvList);
                    _rGVLocationInfoService.Repository.UpdateData(rgv);
                }
                if (wMSUpdateLocationArea.WarehouseId == 2)
                {
@@ -533,6 +551,7 @@
                        item.WarehouseId = wMSUpdateLocationArea.UpdateAreaCode.ObjToInt();
                    }
                    kls.AddRange(KLSLocationInfoList);
                    _kLSLocationInfoService.Repository.UpdateData(kls);
                }
                if (wMSUpdateLocationArea.WarehouseId == 3)
                {
@@ -542,21 +561,18 @@
                        item.WarehouseId = wMSUpdateLocationArea.UpdateAreaCode.ObjToInt();
                    }
                    hk.AddRange(hkList);
                    _hKLocationInfoService.Repository.UpdateData(hk);
                }
                if (wMSUpdateLocationArea.WarehouseId == 4)
                {
                    var pkList = _stationInfo.Repository.QueryData(x => wMSUpdateLocationArea.LocationCodes.Contains(x.StationCode)).ToList();
                    foreach (var item in pk)
                    foreach (var item in pkList)
                    {
                        item.StationRegion = wMSUpdateLocationArea.UpdateAreaCode.ObjToInt();
                    }
                    pk.AddRange(pkList);
                    _stationInfo.Repository.UpdateData(pk);
                }
                Db.Ado.BeginTran();
                _rGVLocationInfoService.UpdateData(rgv);
                _kLSLocationInfoService.UpdateData(kls);
                _hKLocationInfoService.UpdateData(hk);
                Db.Ado.CommitTran();
                content.OK();
            }
            catch (Exception ex)
@@ -1139,7 +1155,8 @@
                            LoctionCode = item.LocationCode,
                            LocationStatus = item.LocationStatus,
                            EnableStatus = item.EnableStatus,
                            PalletCode = item.PalletCode
                            PalletCode = item.PalletCode,
                            AreaCode=item.WarehouseId
                        });
                    }
@@ -1159,7 +1176,8 @@
                            LoctionCode = item.LocationCode,
                            LocationStatus = item.LocationStatus,
                            EnableStatus = item.EnableStatus,
                            PalletCode = item.PalletCode
                            PalletCode = item.PalletCode,
                            AreaCode = item.WarehouseId
                        });
                    }
                    content.OK(data: list);
@@ -1193,7 +1211,8 @@
                            LoctionCode = item.LocationCode,
                            LocationStatus = item.LocationStatus,
                            EnableStatus = item.EnableStatus,
                            PalletCode = item.PalletCode
                            PalletCode = item.PalletCode,
                            AreaCode = item.WarehouseId
                        });
                    }
                    content.OK(data: list);
@@ -1231,7 +1250,9 @@
                            LoctionCode = item.StationCode,
                            LocationStatus = item.StationStatus,
                            EnableStatus = item.IsOccupied,
                            PalletCode = item.PalletCode
                            PalletCode = item.PalletCode,
                            AreaCode = item.StationRegion
                        });
                    }
                    content.OK(data: list);
@@ -1510,7 +1531,10 @@
            {
                // æŸ¥æ‰¾æ‰€æœ‰ä»»åŠ¡ä¸­åŒ…å«è¿™ä¸ªid的
                var take = BaseDal.QueryData(x => keys.Contains(x.TaskId));
                foreach (var item in take)
                {
                    item.Modifier = App.User.UserName;
                }
                // æ‰§è¡Œç§»å…¥åŽ†å²æ“ä½œï¼Œå¹¶æ£€æŸ¥ç»“æžœ
                bool moveResult = BaseDal.DeleteAndMoveIntoHty(take, OperateTypeEnum.人工删除);
@@ -1596,5 +1620,253 @@
        }
        /// <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}");
            }
        }
    }
}