| | |
| | | using SixLabors.Fonts.Tables.AdvancedTypographic; |
| | | using SqlSugar; |
| | | using System.Text.RegularExpressions; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Cache; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.Const; |
| | |
| | | |
| | | #endregion 出库任务完成 |
| | | |
| | | #region 火警任务完成 |
| | | public async Task<WebResponseContent> CompleteOutFireAlarmTaskAsync(Dt_Task task, DtStockInfo stock) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | (var loc, var tas) = UpdateStockAndTaskStatus(stock, task); |
| | | var taskHty = task.Adapt<Dt_Task_Hty>(); |
| | | taskHty.FinishTime = DateTime.Now; |
| | | taskHty.OperateType = App.User.UserName != null ? (int)OperateTypeEnum.人工完成 : (int)OperateTypeEnum.自动完成; |
| | | taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System"; |
| | | |
| | | DtStockInfo_Hty stockInfo_Hty = stock.Adapt<DtStockInfo_Hty>(); |
| | | stockInfo_Hty.ModifyDate = DateTime.Now; |
| | | |
| | | // 事务处理 |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | | { |
| | | if (task.TaskType != (int)TaskOutboundTypeEnum.OutQuality) |
| | | { |
| | | await DeleteStockInfoAsync(stock.Id); |
| | | await DeleteStockInfoDetailsAsync(stock.StockInfoDetails); |
| | | await AddStockInfoHtyAsync(stockInfo_Hty); |
| | | await UpdateLocationAsync(loc); //质检任务需要持续锁定库位 |
| | | } |
| | | await DeleteTaskAsync(task.TaskId); |
| | | await AddTaskHtyAsync(taskHty); |
| | | }); |
| | | return content.OK("任务完成成功", task.Remark); |
| | | } |
| | | #endregion |
| | | |
| | | #region 移库任务完成 |
| | | |
| | | /// <summary> |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (task.TaskType == (int)TaskInboundTypeEnum.InNG || task.TaskType == (int)TaskInboundTypeEnum.InQuality) |
| | | if (task.TaskType == (int)TaskInboundTypeEnum.InNG) |
| | | { |
| | | task.TaskState = (int)TaskInStatusEnum.SC_InFinish; |
| | | // 创建历史任务实例模型 |
| | |
| | | Console.WriteLine(err.Message.ToString()); |
| | | LogFactory.GetLog("任务完成").Error(true, err); |
| | | content.Error(err.Message); |
| | | task.ErrorMessage = err.Message; |
| | | task.TaskState = (int)TaskInStatusEnum.SC_InExecuting; |
| | | await BaseDal.Update(task); |
| | | } |
| | | return content; |
| | | } |
| | |
| | | case (int)TaskOutboundTypeEnum.OutNG: |
| | | LogFactory.GetLog("任务完成").InfoFormat(true, "出库任务", ""); |
| | | return await CompleteStackTaskAsync(task, stock); |
| | | |
| | | case (int)TaskOutboundTypeEnum.OutFireAlarm: |
| | | |
| | | LogFactory.GetLog("任务完成").InfoFormat(true, "火警任务", ""); |
| | | return await CompleteOutFireAlarmTaskAsync(task, stock); |
| | | |
| | | case (int)TaskRelocationTypeEnum.Relocation: |
| | | return await CompleteTransferTaskAsync(task, stock); |
| | |
| | | .ToList().Select(x => x.DeviceCode).ToList(); |
| | | |
| | | var result = await _stockInfoRepository.Db.Queryable<DtStockInfo>() |
| | | .Where(x => x.ProductionLine == station.productLine) |
| | | .WhereIF(!station.Roadway.Contains("JZSC"), x => x.ProductionLine == station.productLine) |
| | | .Where(x => x.AreaCode == areaCode && x.IsFull == false) |
| | | .Includes(x=>x.StockInfoDetails) |
| | | .Includes(x => x.StockInfoDetails) |
| | | .Where(x => x.StockInfoDetails.Any(y => y.MaterielCode == "空托盘")) |
| | | .Includes(x=>x.LocationInfo) |
| | | .Includes(x => x.LocationInfo) |
| | | .WhereIF(!deviceCode.IsNullOrEmpty(), x => deviceCode.Contains(x.LocationInfo.RoadwayNo)) |
| | | .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.AreaId == area.AreaID && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) // 过滤条件 |
| | | .OrderBy(x => x.CreateDate) // 排序 |
| | |
| | | { |
| | | return new Dt_Task |
| | | { |
| | | Grade = tag == 104 ? (stockInfo.LocationInfo.RoadwayNo.Contains("CWSC") ? 1 : 2) : (stockInfo.LocationInfo.RoadwayNo.Contains("CWSC") ? 2 : 1), |
| | | Grade = tag == 104 ? (stockInfo.LocationInfo.RoadwayNo.Contains("CWSC")|| stockInfo.LocationInfo.RoadwayNo.Contains("JZSC") ? 1 : 2) : (stockInfo.LocationInfo.RoadwayNo.Contains("CWSC") || stockInfo.LocationInfo.RoadwayNo.Contains("JZSC") ? 2 : 1), |
| | | Roadway = stockInfo.LocationInfo.RoadwayNo, |
| | | TargetAddress = position, |
| | | Dispatchertime = DateTime.Now, |
| | |
| | | |
| | | #endregion |
| | | |
| | | #region 查询静置空闲库位 |
| | | public WebResponseContent QueryLocationFreeJZ(string RoadwayNo) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var result = _locationRepository.QueryData(x => x.EnalbeStatus != (int)EnableEnum.Disable && x.LocationStatus == (int)LocationEnum.Free && x.RoadwayNo.Contains("JZSC")); |
| | | LogFactory.GetLog($"静置{RoadwayNo}查询空闲库位").Info(true, $"{JsonConvert.SerializeObject(result)}"); |
| | | if (result.Count > 5) |
| | | { |
| | | return content.OK(); |
| | | } |
| | | return content.Error("库位已满"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 大屏接口 |
| | | |
| | | /// <summary> |
| | | /// 获取任务信息 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent GetTaskInfo() |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var task = BaseDal.QueryData(x => true).ToList(); |
| | | var newTask = task.Select(x => new |
| | | { |
| | | x.PalletCode, |
| | | x.Roadway, |
| | | x.SourceAddress, |
| | | x.TargetAddress, |
| | | x.ProductionLine, |
| | | TaskType = new List<string> { GetTaskTypeDesc(x.TaskType) }[0], // 每个任务独立生成 TaskType |
| | | TaskState = new List<string> { GetTaskStateDesc(x.TaskState) }[0] // 每个任务独立生成 TaskState |
| | | }).ToList(); |
| | | |
| | | return content.OK(data: newTask); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 获取库存信息 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent GetStockInfo() |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var now = DateTime.Now; |
| | | var startOfDay = new DateTime(now.Year, now.Month, now.Day); |
| | | var endOfDay = startOfDay.AddDays(1); |
| | | var filteredItems = _stockInfoRepository.Db.Queryable<DtStockInfo>() |
| | | .Where(x => x.OutboundTime >= startOfDay && x.OutboundTime < endOfDay && x.IsFull) |
| | | .Includes(x => x.StockInfoDetails) |
| | | .ToList(); |
| | | |
| | | var result = filteredItems |
| | | .GroupBy(x => x.AreaCode) |
| | | .Select(g => new GroupedStockInfo |
| | | { |
| | | AreaCode = g.Key, |
| | | TotalQuantity = g.Sum(item => item.StockInfoDetails?.Count ?? 0), |
| | | Items = g.ToList() |
| | | }) |
| | | .ToList(); |
| | | return content.OK(data: result); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | #endregion |
| | | |
| | | #endregion 外部接口方法 |
| | | |
| | | #region 内部调用方法 |
| | |
| | | |
| | | #region private 内部方法 |
| | | |
| | | |
| | | /// <summary> |
| | | /// 获取任务类型描述方法 |
| | | /// </summary> |
| | | /// <param name="taskType"></param> |
| | | /// <returns></returns> |
| | | private string GetTaskTypeDesc(int taskType) |
| | | { |
| | | return taskType switch |
| | | { |
| | | (int)TaskInboundTypeEnum.Inbound => TaskInboundTypeEnum.Inbound.GetIntegralRuleTypeEnumDesc(), |
| | | (int)TaskInboundTypeEnum.InTray => TaskInboundTypeEnum.InTray.GetIntegralRuleTypeEnumDesc(), |
| | | (int)TaskInboundTypeEnum.InNG => TaskInboundTypeEnum.InNG.GetIntegralRuleTypeEnumDesc(), |
| | | (int)TaskInboundTypeEnum.InQuality => TaskInboundTypeEnum.InQuality.GetIntegralRuleTypeEnumDesc(), |
| | | (int)TaskOutboundTypeEnum.OutTray => TaskOutboundTypeEnum.OutTray.GetIntegralRuleTypeEnumDesc(), |
| | | (int)TaskOutboundTypeEnum.Outbound => TaskOutboundTypeEnum.Outbound.GetIntegralRuleTypeEnumDesc(), |
| | | (int)TaskOutboundTypeEnum.OutNG => TaskOutboundTypeEnum.OutNG.GetIntegralRuleTypeEnumDesc(), |
| | | }; |
| | | } |
| | | |
| | | // 定义获取任务状态描述方法 |
| | | private string GetTaskStateDesc(int? taskState) |
| | | { |
| | | return taskState switch |
| | | { |
| | | (int)TaskInStatusEnum.InNew => TaskInStatusEnum.InNew.GetIntegralRuleTypeEnumDesc(), |
| | | (int)TaskInStatusEnum.Line_InExecuting => TaskInStatusEnum.Line_InExecuting.GetIntegralRuleTypeEnumDesc(), |
| | | (int)TaskInStatusEnum.Line_InFinish => TaskInStatusEnum.Line_InFinish.GetIntegralRuleTypeEnumDesc(), |
| | | (int)TaskInStatusEnum.SC_InExecuting => TaskInStatusEnum.SC_InExecuting.GetIntegralRuleTypeEnumDesc(), |
| | | (int)TaskInStatusEnum.SC_InFinish => TaskInStatusEnum.SC_InFinish.GetIntegralRuleTypeEnumDesc(), |
| | | (int)TaskOutStatusEnum.OutNew => TaskOutStatusEnum.OutNew.GetIntegralRuleTypeEnumDesc(), |
| | | (int)TaskOutStatusEnum.SC_OutExecuting => TaskOutStatusEnum.SC_OutExecuting.GetIntegralRuleTypeEnumDesc(), |
| | | (int)TaskOutStatusEnum.SC_OutFinish => TaskOutStatusEnum.SC_OutFinish.GetIntegralRuleTypeEnumDesc(), |
| | | (int)TaskOutStatusEnum.Line_OutExecuting => TaskOutStatusEnum.Line_OutExecuting.GetIntegralRuleTypeEnumDesc(), |
| | | (int)TaskOutStatusEnum.Line_OutFinish => TaskOutStatusEnum.Line_OutFinish.GetIntegralRuleTypeEnumDesc(), |
| | | }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 创建历史任务记录 |
| | | /// </summary> |
| | |
| | | } |
| | | |
| | | #region 更新库存信息(暂时不需要) |
| | | //if (stock.IsFull) |
| | | //{ |
| | | // // 查询符合条件的库存信息 |
| | | // var stocks = _stockInfoRepository.QueryData(x => x.AreaCode == stock.AreaCode && x.ProductionLine == stock.ProductionLine && x.SpecialParameterDuration != stock.SpecialParameterDuration); |
| | | if (stock.IsFull) |
| | | { |
| | | // 查询符合条件的库存信息 |
| | | var stocks = _stockInfoRepository.QueryData(x => x.AreaCode == stock.AreaCode && x.ProductionLine == stock.ProductionLine && x.SpecialParameterDuration != stock.SpecialParameterDuration); |
| | | |
| | | // // 查询任务信息 |
| | | // var tasks = BaseDal.QueryData(x => x.PalletCode != stock.PalletCode && x.ProductionLine == stock.ProductionLine).Select(x => x.PalletCode).ToList(); |
| | | // 查询任务信息 |
| | | var tasks = BaseDal.QueryData(x => x.PalletCode != stock.PalletCode && x.ProductionLine == stock.ProductionLine).Select(x => x.PalletCode).ToList(); |
| | | |
| | | // if (stocks != null && stocks.Count > 0) |
| | | // { |
| | | // // 过滤出需要更新的库存信息 |
| | | // var stocksToUpdate = stocks.Where(item => !tasks.Contains(item.PalletCode)).ToList(); |
| | | // foreach (var item in stocksToUpdate) |
| | | // { |
| | | // // 更新库存信息的特定参数 |
| | | // item.SpecialParameterDuration = stock.SpecialParameterDuration; |
| | | // item.ParameterInfos = stock.ParameterInfos; |
| | | // item.OutboundTime = Convert.ToDateTime(item.LinedProcessFeedbackTime == null ? item.CreateDate : item.LinedProcessFeedbackTime).AddHours(Convert.ToDouble(stock.SpecialParameterDuration)); |
| | | // } |
| | | // if (stocksToUpdate.Count > 0) |
| | | // { |
| | | // // 异步更新库存信息 |
| | | // var isUpdates = await _stockInfoRepository.UpdateDataAsync(stocksToUpdate); |
| | | // } |
| | | // } |
| | | //} |
| | | if (stocks != null && stocks.Count > 0) |
| | | { |
| | | // 过滤出需要更新的库存信息 |
| | | var stocksToUpdate = stocks.Where(item => !tasks.Contains(item.PalletCode)).ToList(); |
| | | foreach (var item in stocksToUpdate) |
| | | { |
| | | // 更新库存信息的特定参数 |
| | | item.SpecialParameterDuration = stock.SpecialParameterDuration; |
| | | item.ParameterInfos = stock.ParameterInfos; |
| | | item.OutboundTime = Convert.ToDateTime(item.LinedProcessFeedbackTime == null ? item.CreateDate : item.LinedProcessFeedbackTime).AddHours(Convert.ToDouble(stock.SpecialParameterDuration)); |
| | | } |
| | | if (stocksToUpdate.Count > 0) |
| | | { |
| | | // 异步更新库存信息 |
| | | var isUpdates = await _stockInfoRepository.UpdateDataAsync(stocksToUpdate); |
| | | } |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | // 添加历史任务 |