1
wangxinhui
2025-06-12 e7be74e711076896e7e841b54691daa95067c567
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/MesTaskService.cs
@@ -37,6 +37,8 @@
    {
        static object lock_out = new object();
        static object solderMask_out = new object();
        /// <summary>
        /// æµ‹è¯•架出仓
        /// </summary>
@@ -111,6 +113,165 @@
                    _unitOfWorkManage.CommitTran();
                    //将任务推送到WCS
                    PushTasksToWCS(new List<Dt_Task>() { taskOut }, "AGV_CSJ");
                    responseContent.OK();
                }
                catch (Exception ex)
                {
                    _unitOfWorkManage.RollbackTran();
                    responseContent.Error(ex.Message);
                }
                return responseContent;
            }
        }
        public MesResponseContent SolderMaskOutNotice(SolderMaskOutNotice model)
        {
            lock (solderMask_out)
            {
                MesResponseContent responseContent = new MesResponseContent();
                try
                {
                    Dt_Task exsit = Repository.QueryFirst(x => x.TargetAddress == model.TargetAddressCode);
                    if (exsit != null)
                    {
                        return responseContent.Error($"目标地址重复");
                    }
                    Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA154.ToString());
                    //获取库存记录
                    List<Dt_StockInfo> stockInfos = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x =>
                      x.WarehouseId == warehouse.WarehouseId &&
                      x.StockStatus == (int)StockStatusEmun.入库完成).Includes(x => x.Details).ToList();
                    Dt_StockInfo? stockInfo = stockInfos.FirstOrDefault(x => x.Details.Any(x => x.BatchNo == model.LotNo));
                    if (stockInfo == null)
                    {
                        return responseContent.Error($"防焊库:无{model.LotNo}可用库存");
                    }
                    Dt_Task exsit2 = Repository.QueryFirst(x => x.PalletCode == stockInfo.PalletCode);
                    if (exsit2 != null)
                    {
                        return responseContent.Error($"防焊任务{stockInfo.PalletCode}已存在");
                    }
                    Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode &&
                      x.WarehouseId == stockInfo.WarehouseId &&
                      x.LocationStatus == (int)LocationStatusEnum.InStock &&
                      (x.EnableStatus == (int)EnableStatusEnum.Normal || x.EnableStatus == (int)EnableStatusEnum.OnlyOut));
                    if (locationInfo == null)
                    {
                        return responseContent.Error($"防焊货位:{stockInfo.LocationCode}出库条件不满足");
                    }
                    //生成防焊出库任务 é”å®šåº“å­˜ æ›´æ”¹è´§ä½çŠ¶æ€
                    Dt_Task taskOut = new()
                    {
                        CurrentAddress = stockInfo.LocationCode,
                        Grade = 0,
                        PalletCode = stockInfo.PalletCode,
                        NextAddress = "",
                        Roadway = locationInfo.RoadwayNo,
                        SourceAddress = stockInfo.LocationCode,
                        TargetAddress = model.TargetAddressCode,
                        TaskStatus = (int)TaskStatusEnum.New,
                        TaskType = stockInfo.PalletType<2 ? (int)TaskTypeEnum.MaskOutNoticeSmall : (int)TaskTypeEnum.MaskOutNoticeLarge,
                        TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                        PalletType = stockInfo.PalletType,
                        WarehouseId = stockInfo.WarehouseId,
                    };
                    stockInfo.StockStatus = (int)StockStatusEmun.出库锁定;
                    LocationStatusEnum locationStatus = (LocationStatusEnum)locationInfo.LocationStatus;
                    locationInfo.LocationStatus = (int)LocationStatusEnum.Lock;
                    //判断是否有出库单信息
                    _unitOfWorkManage.BeginTran();
                    //更新库存状态
                    _stockRepository.StockInfoRepository.UpdateData(stockInfo);
                    //更新货位状态
                    _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, stockInfo.PalletType, LocationStatusEnum.Lock, stockInfo.WarehouseId);
                    //新建任务
                    BaseDal.AddData(taskOut);
                    //加入货位变动记录
                    _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, locationStatus, LocationStatusEnum.Lock, LocationChangeType.OutboundAssignLocation, stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", taskOut.TaskNum);
                    _unitOfWorkManage.CommitTran();
                    //将任务推送到WCS
                    PushTasksToWCS(new List<Dt_Task>() { taskOut }, "AGV_ZH");
                    responseContent.OK();
                }
                catch (Exception ex)
                {
                    _unitOfWorkManage.RollbackTran();
                    responseContent.Error(ex.Message);
                }
                return responseContent;
            }
        }
        public MesResponseContent SolderMaskOut(SolderMaskOut model)
        {
            lock (solderMask_out)
            {
                MesResponseContent responseContent = new MesResponseContent();
                try
                {
                    Dt_Task exsit = Repository.QueryFirst(x => x.TargetAddress == model.TargetAddressCode);
                    if (exsit != null)
                    {
                        return responseContent.Error($"目标地址重复");
                    }
                    Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA154.ToString());
                    //获取库存记录
                    List<Dt_StockInfo> stockInfos = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x =>
                      x.WarehouseId == warehouse.WarehouseId &&
                      x.StockStatus == (int)StockStatusEmun.入库完成).Includes(x => x.Details).ToList();
                    Dt_StockInfo? stockInfo = stockInfos.FirstOrDefault(x => x.Details.Any(x => x.BatchNo == model.LotNo));
                    if (stockInfo == null)
                    {
                        return responseContent.Error($"防焊库:无{model.LotNo}可用库存");
                    }
                    Dt_Task exsit2 = Repository.QueryFirst(x => x.PalletCode == stockInfo.PalletCode);
                    if (exsit2 != null)
                    {
                        return responseContent.Error($"防焊任务{stockInfo.PalletCode}已存在");
                    }
                    Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode &&
                      x.WarehouseId == stockInfo.WarehouseId &&
                      x.LocationStatus == (int)LocationStatusEnum.InStock &&
                      (x.EnableStatus == (int)EnableStatusEnum.Normal || x.EnableStatus == (int)EnableStatusEnum.OnlyOut));
                    if (locationInfo == null)
                    {
                        return responseContent.Error($"防焊货位:{stockInfo.LocationCode}出库条件不满足");
                    }
                    //生成防焊出库任务 é”å®šåº“å­˜ æ›´æ”¹è´§ä½çŠ¶æ€
                    Dt_Task taskOut = new()
                    {
                        CurrentAddress = stockInfo.LocationCode,
                        Grade = 0,
                        PalletCode = stockInfo.PalletCode,
                        NextAddress = "",
                        Roadway = locationInfo.RoadwayNo,
                        SourceAddress = stockInfo.LocationCode,
                        TargetAddress = model.TargetAddressCode,
                        TaskStatus = (int)TaskStatusEnum.New,
                        TaskType = stockInfo.PalletType < 2 ? (int)TaskTypeEnum.MaskOutSmall : (int)TaskTypeEnum.m,
                        TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                        PalletType = stockInfo.PalletType,
                        WarehouseId = stockInfo.WarehouseId,
                    };
                    stockInfo.StockStatus = (int)StockStatusEmun.出库锁定;
                    LocationStatusEnum locationStatus = (LocationStatusEnum)locationInfo.LocationStatus;
                    locationInfo.LocationStatus = (int)LocationStatusEnum.Lock;
                    //判断是否有出库单信息
                    _unitOfWorkManage.BeginTran();
                    //更新库存状态
                    _stockRepository.StockInfoRepository.UpdateData(stockInfo);
                    //更新货位状态
                    _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, stockInfo.PalletType, LocationStatusEnum.Lock, stockInfo.WarehouseId);
                    //新建任务
                    BaseDal.AddData(taskOut);
                    //加入货位变动记录
                    _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, locationStatus, LocationStatusEnum.Lock, LocationChangeType.OutboundAssignLocation, stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", taskOut.TaskNum);
                    _unitOfWorkManage.CommitTran();
                    //将任务推送到WCS
                    PushTasksToWCS(new List<Dt_Task>() { taskOut }, "AGV_ZH");
                    responseContent.OK();
                }
                catch (Exception ex)
@@ -451,10 +612,16 @@
                }
                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == palletTypeInfo.WarehouseId);
                //判断是否托盘库存是否已存在
                Dt_StockInfo stockInfoOld = _stockRepository.StockInfo_HtyRepository.QueryData(x => x.PalletCode == model.CarrierCode).First();
                if (stockInfoOld!=null)
                {
                    return MesResponseContent.Instance.Error($"托盘号{model.CarrierCode}已存在");
                }
                Dt_StockInfo_Hty stockInfo_Hty = _stockRepository.StockInfo_HtyRepository.QueryData(x => x.PalletCode == model.CarrierCode).OrderByDescending(x => x.SourceId).First();
                Dt_StockInfoDetail_Hty stockInfoDetail_Hty = _stockRepository.StockInfoDetail_HtyRepository.QueryFirst(x => x.StockId == stockInfo_Hty.SourceId);
                Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail()
                {