wangxinhui
2025-07-24 875e462062d827b109a86f6a1bccbfc853156f30
优化
已修改8个文件
174 ■■■■ 文件已修改
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/阻焊仓/GroundStationJob_ZH.cs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/阻焊仓/StackerCraneJob_ZH.cs 107 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderService.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WMS/WIDESEA_WMSServer/WIDESEA_StockRepository/ProStockInfoRepository.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WMS/WIDESEA_WMSServer/WIDESEA_StockService/ProStockInfoService.cs 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/MesProductService.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/×躸²Ö/GroundStationJob_ZH.cs
@@ -71,8 +71,8 @@
                            ////判断AGV任务完成,后写给地面站取货完成
                            //device.SetValue(GroundStationDBName.W_TakeRequest, false, item.StationCode);
                            //device.SetValue(GroundStationDBName.W_TakeFinish, false, item.StationCode);
                            Dt_Task task = _taskRepository.QueryFirst(x => x.DeviceCode == item.StackerCraneCode && x.TaskState == TaskStatusEnum.New.ObjToInt() && x.NextAddress==item.StationCode);
                            Dt_Task? taskOther = _taskRepository.QueryFirst(x => x.Roadway == item.StackerCraneCode && (x.TaskState == TaskStatusEnum.SC_Executing.ObjToInt() || x.TaskState == TaskStatusEnum.SC_Execute.ObjToInt() || x.TaskState == TaskStatusEnum.AGV_Executing.ObjToInt() || x.TaskState == TaskStatusEnum.AGV_WaitToExecute.ObjToInt() || x.TaskState == TaskStatusEnum.Exception.ObjToInt()));
                            Dt_Task task = _taskRepository.QueryFirst(x => x.DeviceCode == item.StackerCraneCode && x.TaskType < TaskTypeEnum.Inbound.ObjToInt() && x.TaskState == TaskStatusEnum.New.ObjToInt() && x.NextAddress==item.StationCode);
                            Dt_Task? taskOther = _taskRepository.QueryFirst(x => x.Roadway == item.StackerCraneCode && x.TaskType < TaskTypeEnum.Inbound.ObjToInt() && (x.TaskState == TaskStatusEnum.SC_Executing.ObjToInt() || x.TaskState == TaskStatusEnum.SC_Execute.ObjToInt() || x.TaskState == TaskStatusEnum.AGV_Executing.ObjToInt() || x.TaskState == TaskStatusEnum.AGV_WaitToExecute.ObjToInt() || x.TaskState == TaskStatusEnum.Exception.ObjToInt()));
                            if (task != null && isCanPut && !isCanTake && !putRequest && !putFinish && !takeRequest && !takeFinish && taskOther == null)
                            {
                                _taskService.UpdateTask(task, TaskStatusEnum.SC_Execute, nextAddress: item.StackerCraneStationCode);
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/×躸²Ö/StackerCraneJob_ZH.cs
@@ -21,6 +21,12 @@
using WIDESEAWCS_Tasks.StackerCraneJob;
using WIDESEAWCS_Tasks;
using WIDESEAWCS_Core;
using Newtonsoft.Json;
using WIDESEAWCS_Common.APIEnum;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_Core.Caches;
using AutoMapper;
namespace WIDESEAWCS_Tasks
{
@@ -32,14 +38,32 @@
        private readonly ITaskRepository _taskRepository;
        private readonly IRouterService _routerService;
        private readonly IStationMangerRepository _stationMangerRepository;
        private readonly ICacheService _cacheService;
        private readonly IMapper _mapper;
        private List<Dt_ApiInfo> apiInfos;
        public StackerCraneJob_ZH(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository)
        public StackerCraneJob_ZH(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository,ICacheService cacheService, IMapper mapper)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _taskRepository = taskRepository;
            _routerService = routerService;
            _stationMangerRepository = stationMangerRepository;
            _cacheService = cacheService;
            _mapper = mapper;
            string? apiInfoStr = _cacheService.Get("apiInfos");
            if (!string.IsNullOrEmpty(apiInfoStr))
            {
                List<Dt_ApiInfo>? infos = JsonConvert.DeserializeObject<List<Dt_ApiInfo>>(apiInfoStr);
                if (infos == null || infos.Count == 0)
                {
                    apiInfos = new List<Dt_ApiInfo>();
                }
                else
                {
                    apiInfos = infos;
                }
            }
        }
        public Task Execute(IJobExecutionContext context)
@@ -183,22 +207,89 @@
            if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
            {
                if (OutTaskStationIsOccupied(task) != null || true)
                if (OutTaskStationIsOccupied(task) == null)
                {
                    return task;
                }
                else
                {
                    bool flag = false;
                    List<string> otherOutStaionCodes = _routerService.QueryNextRoutes(commonStackerCrane.DeviceCode, task.NextAddress, task.TaskType).Select(x => x.ChildPosi).ToList();
                    List<Dt_Task> tasks = _taskService.QueryStackerCraneOutTasks(commonStackerCrane.DeviceCode, otherOutStaionCodes);
                    foreach (var item in tasks)
                    {
                        if (OutTaskStationIsOccupied(task) != null)
                        {
                            return task;
                            flag = true;
                            break;
                        }
                    }
                    task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
                    if (!flag)
                    {
                        task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
                    }
                }
            }
            if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
            {
                string? url = apiInfos.FirstOrDefault(x => x.ApiCode == APIEnum.WMSIsReloaction.ToString())?.ApiAddress;
                if (string.IsNullOrEmpty(url))
                {
                    _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"未找到WMS移库判断接口");
                    WriteError(commonStackerCrane.DeviceCode, $"未找到WMS移库判断接口");
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到WMS移库判断接口");
                    return null;
                }
                string response = HttpHelper.Post($"{url}?taskNum={task.TaskNum}&locationCode={task.CurrentAddress}", "");//todo è°ƒç”¨WMS任务完成方法
                if (string.IsNullOrEmpty(response))
                {
                    _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"移库接口调用错误");
                    WriteError(commonStackerCrane.DeviceCode, $"移库接口调用错误");
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库接口调用错误");
                    return null;
                }
                WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(response);
                if (responseContent == null || !responseContent.Status)
                {
                    _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"移库接口调用错误");
                    WriteError(commonStackerCrane.DeviceCode, $"移库接口调用错误");
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库接口调用错误");
                    return null;
                }
                WMSTaskDTO? taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(responseContent.Data.Serialize());
                if (taskDTO == null)
                {
                    _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"移库接口调用错误");
                    WriteError(commonStackerCrane.DeviceCode, $"移库接口调用错误");
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库接口调用错误");
                    return null;
                }
                if (task.TaskNum == taskDTO.TaskNum)
                {
                    return task;
                }
                else
                {
                    Dt_Task reloTask = _mapper.Map<Dt_Task>(taskDTO);
                    //判断移库货位任务是否已存在,如存在先执行
                    Dt_Task existTask = _taskService.QueryStackerExistTask(reloTask.PalletCode, reloTask.SourceAddress);
                    if (existTask != null && existTask.TaskState == (int)TaskStatusEnum.SC_Execute)
                    {
                        return existTask;
                    }
                    else if (existTask != null && existTask.TaskState != (int)TaskStatusEnum.SC_Execute)
                    {
                        return null;
                    }
                    else
                    {
                        reloTask.TaskState = TaskStatusEnum.SC_Execute.ObjToInt();
                        reloTask.CurrentAddress = taskDTO.SourceAddress;
                        reloTask.NextAddress = taskDTO.TargetAddress;
                        reloTask.DeviceCode = task.DeviceCode;
                        reloTask.TaskType = TaskTypeEnum.Relocation.ObjToInt();
                        int taskId = _taskRepository.AddData(reloTask);
                        reloTask.TaskId = taskId;
                    }
                    return reloTask;
                }
            }
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderService.cs
@@ -95,7 +95,7 @@
                }
                else if (outOrderDTO.OType==2)
                {
                    warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA101.ToString());
                    warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA71.ToString());
                }
                List<Dt_ProOutOrderDetail> proOutOrderDetails = new List<Dt_ProOutOrderDetail>();
                Dictionary<string,string> keyValuePairs =new Dictionary<string, string>();
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_StockRepository/ProStockInfoRepository.cs
@@ -56,7 +56,7 @@
                .Any(v =>
                    v.ProductCode == proOutOrderDetail.PCode
                    && v.ProductVersion.StartsWith(proOutOrderDetail.PVer.Substring(0,1)) 
                    && (isCanLot ? isCanLot : v.BagNo == proOutOrderDetail.PLot)
                    && (isCanLot ? isCanLot : v.ProductCode == proOutOrderDetail.PLot)
                    && (isCanDate ? isCanDate : v.DateCode == proOutOrderDetail.DateCode)
                ))
                .ToList();
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_StockService/ProStockInfoService.cs
@@ -128,7 +128,7 @@
            bool isCanLot = string.IsNullOrEmpty(outOrderDetail.PLot);
            bool isCanDate = string.IsNullOrEmpty(outOrderDetail.DateCode);
            float stockTotalQuantity = stockInfos.Select(x => x.proStockInfoDetails.Where(x => x.ProductCode == outOrderDetail.PCode && x.ProductVersion.StartsWith(outOrderDetail.PVer.Substring(0, 1))
                            && (isCanLot ? isCanLot : x.BagNo == outOrderDetail.PLot)
                            && (isCanLot ? isCanLot : x.ProductCode == outOrderDetail.PLot)
                            && (isCanDate ? isCanDate : x.DateCode == outOrderDetail.DateCode))
                        .Sum(v => v.StockPcsQty - v.OutboundQuantity)).Sum(x => x);
            //stockInfos = stockInfos.OrderBy(x => x.Id).ToList();
@@ -141,13 +141,13 @@
                    Dt_ProStockInfo stockInfo = stockInfos[index];
                    float useableStockQuantity = stockInfo.proStockInfoDetails
                        .Where(x => x.ProductCode == outOrderDetail.PCode && x.ProductVersion.StartsWith(outOrderDetail.PVer.Substring(0,1))
                            && (isCanLot ? isCanLot : x.BagNo == outOrderDetail.PLot)
                            && (isCanLot ? isCanLot : x.ProductCode == outOrderDetail.PLot)
                            && (isCanDate ? isCanDate : x.DateCode == outOrderDetail.DateCode))
                        .Sum(x => x.StockPcsQty - x.OutboundQuantity);
                    if (useableStockQuantity < needQuantity && useableStockQuantity >0)
                    {
                        stockInfo.proStockInfoDetails.Where(x => x.ProductCode == outOrderDetail.PCode && x.ProductVersion.StartsWith(outOrderDetail.PVer.Substring(0, 1))
                            && (isCanLot ? isCanLot : x.BagNo == outOrderDetail.PLot)
                            && (isCanLot ? isCanLot : x.ProductCode == outOrderDetail.PLot)
                            && (isCanDate ? isCanDate : x.DateCode == outOrderDetail.DateCode)).ToList().ForEach(x => x.OutboundQuantity = x.StockPcsQty);
                        needQuantity -= useableStockQuantity;
                    }
@@ -158,7 +158,7 @@
                            //满足条件进行分配
                            if ((x.StockPcsQty > x.OutboundQuantity)
                                && x.ProductCode == outOrderDetail.PCode && x.ProductVersion.StartsWith(outOrderDetail.PVer.Substring(0, 1)) 
                                && (isCanLot ? isCanLot : x.BagNo == outOrderDetail.PLot)
                                && (isCanLot ? isCanLot : x.ProductCode == outOrderDetail.PLot)
                                && (isCanDate ? isCanDate : x.DateCode == outOrderDetail.DateCode))
                            {
                                if (x.StockPcsQty - x.OutboundQuantity >= needQuantity)
@@ -375,11 +375,14 @@
        {
            try
            {
                List<Dt_ProStockInfo> proStockInfo = BaseDal.QueryData(x => x.WarehouseId == warehouseId);
                List<int> proStockId = proStockInfo.Select(x => x.Id).ToList();
                List<Dt_ProStockInfoDetail> proStockInfoDetails = BaseDal.Db.Queryable<Dt_ProStockInfoDetail>().Where(x => proStockId.Contains(x.OutDetailId)).ToList();
                List<string> proCode = proStockInfoDetails.Select(x => x.ProductCode).ToList();
                return WebResponseContent.Instance.OK(data: proCode);
                //获取所有库存型号
                List<Dt_ProStockInfoDetail> proStockInfoDetails = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo, Dt_ProStockInfoDetail>((master, detail) => master.Id == detail.ProStockId)
                .Where((master, detail) => master.WarehouseId == warehouseId)
                .Select((master, detail) => detail)
                .ToList();
                //过滤重复
                List<string> proCode = proStockInfoDetails.Select(x => x.ProductCode).Distinct().ToList();
                return WebResponseContent.Instance.OK("成功",data: proCode);
            }
            catch (Exception ex)
            {
@@ -391,11 +394,14 @@
        {
            try
            {
                List<Dt_ProStockInfo> proStockInfo = BaseDal.QueryData(x => x.WarehouseId == warehouseId);
                List<int> proStockId = proStockInfo.Select(x => x.Id).ToList();
                List<Dt_ProStockInfoDetail> proStockInfoDetails = BaseDal.Db.Queryable<Dt_ProStockInfoDetail>().Where(x => scrapProCode.Contains(x.ProductCode) && proStockId.Contains(x.OutDetailId)).ToList();
                List<string> productVersion = proStockInfoDetails.Select(x => x.ProductVersion).ToList();
                return WebResponseContent.Instance.OK(data: productVersion);
                //获取指定产品库存版本
                List<Dt_ProStockInfoDetail> proStockInfoDetails = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo, Dt_ProStockInfoDetail>((master, detail) => master.Id == detail.ProStockId)
                .Where((master, detail) => master.WarehouseId == warehouseId && detail.ProductCode== scrapProCode)
                .Select((master, detail) => detail)
                .ToList();
                //过滤重复
                List<string> productVersion = proStockInfoDetails.Select(x => x.ProductVersion).Distinct().ToList();
                return WebResponseContent.Instance.OK("成功",data: productVersion);
            }
            catch (Exception ex)
            {
@@ -407,11 +413,14 @@
        {
            try
            {
                List<Dt_ProStockInfo> proStockInfo = BaseDal.QueryData(x => x.WarehouseId == warehouseId);
                List<int> proStockId = proStockInfo.Select(x => x.Id).ToList();
                List<Dt_ProStockInfoDetail> proStockInfoDetails = BaseDal.Db.Queryable<Dt_ProStockInfoDetail>().Where(x => scrapProCode.Contains(x.ProductCode) && proStockId.Contains(x.OutDetailId)).ToList();
                List<string> lotNumber = proStockInfoDetails.Select(x => x.LotNumber).ToList();
                return WebResponseContent.Instance.OK(data: lotNumber);
                //获取指定产品库存批次
                List<Dt_ProStockInfoDetail> proStockInfoDetails = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo, Dt_ProStockInfoDetail>((master, detail) => master.Id == detail.ProStockId)
                .Where((master, detail) => master.WarehouseId == warehouseId && detail.ProductCode == scrapProCode)
                .Select((master, detail) => detail)
                .ToList();
                //过滤重复
                List<string> lotNumber = proStockInfoDetails.Select(x => x.LotNumber).Distinct().ToList();
                return WebResponseContent.Instance.OK("成功", data: lotNumber);
            }
            catch (Exception ex)
            {
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/MesProductService.cs
@@ -663,6 +663,7 @@
                        throw new Exception("同步MES库存板出库失败,错误:" + responseContent.Message);
                    }
                    _unitOfWorkManage.CommitTran();
                    PushTasksToWCS(tasks);
                }
                return content.OK($"提供返库单接收成功,ReceiveDown:{model.ReceiveDown}");
            }
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -824,6 +824,7 @@
                switch (task.TaskType)
                {
                    case (int)TaskTypeEnum.OutProduct:
                    case (int)TaskTypeEnum.OutSendProduct:
                        content = OutProductCompleted(task);
                        break;
                    case (int)TaskTypeEnum.OutMesRworkProduct:
@@ -935,9 +936,12 @@
                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.自动完成 : OperateTypeEnum.人工完成);
                _unitOfWorkManage.CommitTran();
                //MES成品出库同步
                MesShipmentOrderSync shipmentOrderSync = MesOutSync(outProStockInfo, proOutOrderDetail, proStockInfoDetails);
                ShipmentOrderSync(shipmentOrderSync);
                ShipmentOrderMESSync(shipmentOrderSync);
                if (task.TaskType!= TaskTypeEnum.OutSendProduct.ObjToInt())
                {
                    MesShipmentOrderSync shipmentOrderSync = MesOutSync(outProStockInfo, proOutOrderDetail, proStockInfoDetails);
                    ShipmentOrderSync(shipmentOrderSync);
                    ShipmentOrderMESSync(shipmentOrderSync);
                }
                content.OK();
            }
            catch (Exception ex)
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs
@@ -1024,6 +1024,7 @@
                                StockQuantity -=(decimal)assignAmount;
                                OrderDetail.OverOutQuantity += assignAmount;
                                OrderDetail.LockQuantity += assignAmount;
                                v.StockQuantity = (float)Math.Round(StockQuantity,3);
                                upstockDetails.Add(v);
                            }
                            else