| | |
| | | using AngleSharp.Dom; |
| | | using Mapster; |
| | | using Mapster; |
| | | using Masuit.Tools; |
| | | using SixLabors.Fonts.Tables.AdvancedTypographic; |
| | | using System.Diagnostics; |
| | | using System.Text.RegularExpressions; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Core.Const; |
| | | using WIDESEA_DTO.MOM; |
| | | using WIDESEA_DTO.WMS; |
| | | using WIDESEA_IServices; |
| | | using WIDESEA_IStoragIntegrationServices; |
| | | using WIDESEA_StoragIntegrationServices; |
| | | using WIDESEAWCS_BasicInfoRepository; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | |
| | | namespace WIDESEA_StorageTaskServices; |
| | | |
| | |
| | | var agingOutputDto = MapToAgingOutputDto(stock); |
| | | content = await _agingInOrOutInputService.GetOCVOutputAsync(agingOutputDto); |
| | | |
| | | var result = JsonConvert.DeserializeObject<BasicResult>(content.Data.ToString()); |
| | | task.Remark = result.Success ? null : "NG"; |
| | | |
| | | if (!result.Success && result.MessageCode == "E10001") |
| | | if (content.Status) |
| | | { |
| | | await HandleOutBoundError(stock, task); |
| | | var result = JsonConvert.DeserializeObject<BasicResult>(content.Data.ToString()); |
| | | task.Remark = result.Success ? null : "NG"; |
| | | |
| | | if (!result.Success && result.MessageCode == "E10001") |
| | | { |
| | | await HandleOutBoundError(stock, task); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | task.Remark = "NG"; |
| | | } |
| | | } |
| | | } |
| | |
| | | // 更新库存状态和任务状态 |
| | | (var loc, var tas) = UpdateStockAndTaskStatus(stock, task); |
| | | var taskHty = task.Adapt<Dt_Task_Hty>(); |
| | | taskHty.FinishTime = DateTime.Now; |
| | | |
| | | DtStockInfo_Hty stockInfo_Hty = stock.Adapt<DtStockInfo_Hty>(); |
| | | stockInfo_Hty.ModifyDate = DateTime.Now; |
| | | |
| | |
| | | await DeleteStockInfoAsync(stock.Id); |
| | | await DeleteStockInfoDetailsAsync(stock.StockInfoDetails); |
| | | await AddStockInfoHtyAsync(stockInfo_Hty); |
| | | await UpdateLocationAsync(loc); //质检任务需要持续锁定库位 |
| | | } |
| | | await UpdateLocationAsync(loc); |
| | | await DeleteTaskAsync(task.TaskId); |
| | | await AddTaskHtyAsync(taskHty); |
| | | }); |
| | |
| | | { |
| | | var location = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress && x.RoadwayNo == task.Roadway); |
| | | //var details = _stockInfoDetailRepository.QueryData(x => x.StockId == stock.Id); |
| | | |
| | | int lastStatus = location.LocationStatus; |
| | | location.LocationStatus = (int)LocationEnum.Free; |
| | | task.TaskState = (int)TaskOutStatusEnum.OutFinish; |
| | | //task.CurrentAddress = task.NextAddress; |
| | | //task.NextAddress = task.TargetAddress; |
| | | |
| | | _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(location, lastStatus, (int)StatusChangeTypeEnum.AutomaticDelivery, task.TaskNum); |
| | | |
| | | LogFactory.GetLog("任务完成").Info(true, "更新库存状态与任务状态"); |
| | | return (location, task); |
| | |
| | | |
| | | private async Task AddStockInfoHtyAsync(DtStockInfo_Hty dtStock) |
| | | { |
| | | var isStockAdd = await SqlSugarHelper.Db.InsertNav(dtStock).IncludesAllFirstLayer().ExecuteCommandAsync(); |
| | | var isStockAdd = await SqlSugarHelper.DbWMS.InsertNav(dtStock).IncludesAllFirstLayer().ExecuteCommandAsync(); |
| | | if (!isStockAdd) |
| | | { |
| | | throw new Exception("库存历史信息添加失败"); |
| | |
| | | var boxing = await _boxingInfoRepository.QueryFirstNavAsync(x => x.PalletCode == task.PalletCode); |
| | | var locationInf = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.TargetAddress && x.RoadwayNo == task.Roadway); |
| | | |
| | | int lastStatus = locationInf.LocationStatus; |
| | | // 更新目标位置状态为库存中 |
| | | locationInf.LocationStatus = (int)LocationEnum.InStock; |
| | | |
| | |
| | | await _locationRepository.UpdateDataAsync(locationInf); |
| | | await _task_HtyRepository.AddDataAsync(taskHty); |
| | | await BaseDal.DeleteDataAsync(task); |
| | | |
| | | //记录货位变动信息 |
| | | _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(locationInf, lastStatus, (int)StatusChangeTypeEnum.AutomaticStorage, task.TaskNum); |
| | | |
| | | return content.OK("入库任务完成成功"); |
| | | } |
| | | // 根据是否有组盘信息创建库存实例模型 |
| | |
| | | bool isResult = await ExecuteTransaction(stock, taskHty, locationInf, task.TaskId, boxing); |
| | | if (isResult) |
| | | { |
| | | _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(locationInf, lastStatus, (int)StatusChangeTypeEnum.AutomaticStorage, task.TaskNum); |
| | | content.OK("入库任务完成成功"); |
| | | } |
| | | else |
| | |
| | | // 创建并获取整盘电芯状态 |
| | | TrayCellsStatusDto trayCells = CreateTrayCellsStatusDto(area, input.PalletCode); |
| | | content = await GetTrayCellStatusAsync(trayCells); |
| | | if (!content.Status) return content; |
| | | if (!content.Status) |
| | | { |
| | | ConsoleHelper.WriteErrorLine($"获取电芯状态失败:{content.Message}"); |
| | | return content; |
| | | } |
| | | |
| | | var result = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(content.Data.ToString()); |
| | | |
| | | if (!result.Success) |
| | | { |
| | | ConsoleHelper.WriteErrorLine($"获取电芯状态失败:{result.MOMMessage}"); |
| | | if (result.SerialNos.Count <= 0) |
| | | { |
| | | // 空托盘入库逻辑 |
| | |
| | | return content.Error(result.MOMMessage); |
| | | } |
| | | |
| | | // 处理异常电芯情况 |
| | | var serialNosError = result.SerialNos.Where(x => x.SerialNoStatus != 1).ToList(); |
| | | if (serialNosError.Count > 0) |
| | | |
| | | if (result.SerialNos.Count <= 0) |
| | | { |
| | | return await HandleErrorCells(input, area, serialNosError); |
| | | return await RequestTrayInTaskAsync(input); |
| | | } |
| | | else |
| | | { |
| | | |
| | | var boxing = CreateBoxingInfo(result, input.PalletCode); |
| | | if (boxing == null) return content.Error("组盘失败"); |
| | | |
| | | return await ProcessBasedOnProcessCode(boxing, area, input, result); |
| | | // 处理异常电芯情况 |
| | | var serialNosError = result.SerialNos.Where(x => x.SerialNoStatus != 1 && x.SerialNoStatus != 4).ToList(); |
| | | if (serialNosError.Count > 0) |
| | | { |
| | | return await HandleErrorCells(input, area, serialNosError); |
| | | } |
| | | |
| | | var boxing = CreateBoxingInfo(result, input.PalletCode); |
| | | if (boxing == null) return content.Error("组盘失败"); |
| | | |
| | | return await ProcessBasedOnProcessCode(boxing, area, input, result); |
| | | } |
| | | } |
| | | catch (Exception err) |
| | | { |
| | |
| | | /// </summary> |
| | | private async Task<DtStockInfo> QueryStockInfoForRealTrayCWAsync(List<string> areaCodes, string productionLine) |
| | | { |
| | | var area = await _areaInfoRepository.QueryFirstAsync(x => x.AreaCode == "CWSC1"); |
| | | var areaId = (await _areaInfoRepository.QueryDataAsync(x => areaCodes.Contains(x.AreaCode))).Select(x => x.AreaID).ToList(); |
| | | if (areaId.Count == 0) |
| | | { |
| | | ConsoleHelper.WriteErrorLine($"查询常温实盘库存信息时,未找到区域代码为{JsonConvert.SerializeObject(areaCodes)}的数据"); |
| | | return null; |
| | | } |
| | | |
| | | var result = await _stockInfoRepository.Db.Queryable<DtStockInfo>() |
| | | .Includes(x => x.LocationInfo) // 预加载LocationInfo |
| | | .Includes(x => x.StockInfoDetails) // 预加载StockInfoDetails |
| | | .Where(x => areaCodes.Contains(x.AreaCode) && x.OutboundTime < DateTime.Now && x.IsFull == true) // 过滤条件 |
| | | .WhereIF(!productionLine.IsNullOrEmpty(), x => x.ProductionLine == productionLine) |
| | | .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // 过滤条件 |
| | | .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && areaId.Contains(x.LocationInfo.AreaId) && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // 过滤条件 |
| | | .OrderBy(x => x.OutboundTime) // 排序 |
| | | .FirstAsync(); // 获取第一个元素 |
| | | |
| | |
| | | { |
| | | return content.Error("未查询到对应的库存信息"); |
| | | } |
| | | if (stockInfo.LocationInfo.LocationStatus != (int)LocationEnum.InStock) |
| | | { |
| | | return content.Error("该货位状态不等于【有货】请查看是否已经有任务!"); |
| | | } |
| | | |
| | | var task = await BaseDal.QueryFirstAsync(x => x.PalletCode == palletCode); |
| | | if (task != null) |
| | |
| | | } |
| | | else |
| | | { |
| | | if (stockInfo.LocationInfo.RoadwayNo == "JZSC1") |
| | | if (stockInfo.LocationInfo.RoadwayNo.Contains("JZSC")) |
| | | { |
| | | task = CreateTask(stockInfo, "002-021-001", taskType); |
| | | var targetAddress = "002-021-001"; |
| | | if (stockInfo.LocationInfo.RoadwayNo == "JZSC4") |
| | | targetAddress = "001-021-001"; |
| | | task = CreateTask(stockInfo, targetAddress, taskType); |
| | | } |
| | | } |
| | | //var taskId = await BaseDal.AddDataAsync(task); |
| | |
| | | content.OK(data: taskDTO); |
| | | } |
| | | else |
| | | content.Error(result.MOMMessage); |
| | | { |
| | | var location = await GetLocationDistributeAsync(station.Roadway); |
| | | var task = new Dt_Task |
| | | { |
| | | CurrentAddress = station.stationLocation, |
| | | Grade = 1, |
| | | Roadway = station.Roadway, |
| | | TargetAddress = location.LocationCode, |
| | | Dispatchertime = DateTime.Now, |
| | | MaterialNo = "", |
| | | NextAddress = location.LocationCode, |
| | | OrderNo = null, |
| | | PalletCode = palletCode, |
| | | SourceAddress = position, |
| | | TaskState = (int)TaskInStatusEnum.Line_InFinish, |
| | | TaskType = (int)TaskInboundTypeEnum.InTray, |
| | | TaskNum = await BaseDal.GetTaskNo(), |
| | | Creater = "Systeam" |
| | | }; |
| | | // 创建WMS任务 |
| | | WMSTaskDTO taskDTO = CreateWMSTaskDTO(task); |
| | | |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | | { |
| | | // 添加任务到数据库 |
| | | await BaseDal.AddDataAsync(task); |
| | | // 更新库存位置状态为不可用 |
| | | location.LocationStatus = (int)LocationEnum.Lock; |
| | | await _locationRepository.UpdateDataAsync(location); |
| | | }); |
| | | |
| | | content.OK(data: taskDTO); |
| | | } |
| | | } |
| | | else |
| | | { |
| | |
| | | Grade = 1, |
| | | PalletCode = taskOld.PalletCode, |
| | | RoadWay = taskOld.Roadway, |
| | | SourceAddress = taskOld.CurrentAddress, |
| | | SourceAddress = taskOld.SourceAddress, |
| | | TargetAddress = taskOld.TargetAddress, |
| | | TaskState = taskOld.TaskState.Value, |
| | | Id = 0, |
| | |
| | | #endregion 静置异常口入库 |
| | | |
| | | #endregion 外部接口方法 |
| | | |
| | | |
| | | |
| | | #region 内部调用方法 |
| | | |
| | |
| | | taskHty.TaskId = 0; |
| | | taskHty.OperateType = isHand ? (int)OperateTypeEnum.人工删除 : (int)OperateTypeEnum.自动完成; |
| | | taskHty.SourceId = task.TaskId; |
| | | if (isHand) |
| | | { |
| | | taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System"; |
| | | } |
| | | taskHty.TaskState = TaskOutStatusEnum.OutFinish.ObjToInt(); |
| | | return taskHty; |
| | | } |
| | |
| | | /// <returns></returns> |
| | | public async Task<string> GetRoadWayAsync(List<string> process) |
| | | { |
| | | var minGroup = _locationRepository.QueryData(x => process.Contains(x.RoadwayNo) && x.LocationStatus == (int)LocationEnum.Free) |
| | | var deviceCode = await SqlSugarHelper.DbWCS.Queryable<Dt_DeviceInfo>() |
| | | .Where(x => x.DeviceStatus == 1.ToString() && process.Contains(x.DeviceCode)) |
| | | .Select(x => x.DeviceCode).ToListAsync(); |
| | | |
| | | var minGroup = _locationRepository.QueryData(x => deviceCode.Contains(x.RoadwayNo) && x.LocationStatus == (int)LocationEnum.Free) |
| | | .GroupBy(x => x.RoadwayNo) |
| | | .OrderByDescending(g => g.Count()) // 根据每个组的元素数量排序 |
| | | .ToList(); // 取出数量最多的组 |