| | |
| | | using WIDESEA_Core.Const; |
| | | using WIDESEA_DTO.MOM; |
| | | using WIDESEA_DTO.WMS; |
| | | using WIDESEA_Model.Models.Basic; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | |
| | | |
| | | #region 火警出库 |
| | | |
| | | public WebResponseContent EmergencyTask(object obj) |
| | | public WebResponseContent EmergencyTask(Object obj) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | var emergencyTask = new DTSEmergencyTask(); |
| | | try |
| | | { |
| | | emergencyTask = JsonConvert.DeserializeObject<DTSEmergencyTask>(obj.ToString()); |
| | | |
| | | if (emergencyTask == null) throw new Exception("火警参数为空"); |
| | | |
| | | string[] strings = emergencyTask.LocationCode.Split("-"); |
| | | |
| | | string[] Roadways = strings[0].Select(x => x.ToString()).ToArray(); |
| | | string Roadway = string.Empty; |
| | | switch (Roadways[0]) |
| | | { |
| | | case "J": |
| | | Roadway = "JZSC" + Roadways[1]; |
| | | break; |
| | | case "G": |
| | | Roadway = "GWSC" + Roadways[1]; |
| | | break; |
| | | case "C": |
| | | Roadway = "CWSC" + Roadways[1]; |
| | | break; |
| | | default: throw new Exception("未识别库位编码"); |
| | | } |
| | | |
| | | string Roadway = strings[0]; |
| | | //switch (Roadways[0]) |
| | | //{ |
| | | // case "J": |
| | | // Roadway = "JZSC" + Roadways[1]; |
| | | // break; |
| | | // case "G": |
| | | // Roadway = "GWSC" + Roadways[1]; |
| | | // break; |
| | | // case "C": |
| | | // Roadway = "CWSC" + Roadways[1]; |
| | | // break; |
| | | // default: throw new Exception("未识别库位编码"); |
| | | //} |
| | | int Row = Convert.ToInt16(strings[1]); |
| | | int Column= Convert.ToInt16(strings[2]); |
| | | int Layer= Convert.ToInt16(strings[3]); |
| | | if (!strings[0].Contains("SC")) throw new Exception("未知库区"); |
| | | for (int i = 0; i < 2; i++) |
| | | { |
| | | DtLocationInfo locationInfo = _locationRepository.QueryFirst(x => x.Row == Convert.ToInt16(strings[1]) && x.Column == Convert.ToInt16(strings[2]) && x.Layer == (i == 0 ? Convert.ToInt16(strings[3]) * 2 - 1 : Convert.ToInt16(strings[3]) * 2) && x.RoadwayNo == Roadway); |
| | | DtLocationInfo locationInfo = _locationRepository.QueryFirst(x => x.Row == Row && x.Column == Column && x.Layer == (i == 0 ? Layer - 1 : Layer) && x.RoadwayNo == Roadway); |
| | | if (locationInfo == null) |
| | | { |
| | | throw new Exception("未知库位"); |
| | |
| | | } |
| | | return content; |
| | | } |
| | | /// <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(), |
| | | (int)TaskOutboundTypeEnum.InToOut=> TaskOutboundTypeEnum.InToOut.GetIntegralRuleTypeEnumDesc(), |
| | | }; |
| | | } |
| | | |
| | | #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); |
| | | } |
| | | } |
| | | // 定义获取任务状态描述方法 |
| | | 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> |
| | | /// <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); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 获取货位状态 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent GetStockQuantity() |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var location = _locationRepository.Db.Queryable<DtLocationInfo>().ToList(); |
| | | |
| | | return content.OK(data: location); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | public WebResponseContent Getproductionvolume() |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var now = DateTime.Now; |
| | | var startOfDay = new DateTime(now.Year, now.Month, now.Day); |
| | | var endOfDay1 = startOfDay.AddDays(-7); |
| | | var taskHty = _task_HtyRepository.Db.Queryable<Dt_Task_Hty>().Where(it => it.CreateDate > endOfDay1).ToList(); |
| | | return content.OK(data: taskHty); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | |
| | | } |
| | | |
| | | public WebResponseContent Getoutput() |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var now = DateTime.Now; |
| | | var firstDayOfYear = new DateTime(now.Year, 1, 1); |
| | | var taskHty = _task_HtyRepository.Db.Queryable<Dt_Task_Hty>().Where(it => it.CreateDate > firstDayOfYear && it.TaskType == 100).ToList(); |
| | | return content.OK(data: taskHty); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | |
| | | } |
| | | #endregion |
| | | public WebResponseContent GetTimeout() |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var now = DateTime.Now; |
| | | // 使用Subtract方法 |
| | | var threeHoursAgo = now.Subtract(TimeSpan.FromHours(3)); |
| | | |
| | | List<DtStockInfo> dtStocks = _stockInfoRepository.Db.Queryable<DtStockInfo>() |
| | | .Where(x => x.OutboundTime < threeHoursAgo).ToList(); |
| | | return content.OK1(total1:dtStocks.Count, data: dtStocks); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | |
| | | } |
| | | public WebResponseContent Getproductionstatistics() |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var now = DateTime.Now; |
| | | var thirtyDaysAgo = now.AddDays(-30); |
| | | var roadwayMappings = new Dictionary<string, string> { |
| | | { "JZ", "静置库" }, |
| | | { "CH", "陈化库" }, |
| | | { "FR", "分容库" }, |
| | | { "GW", "高温库" }, |
| | | { "CW", "常温库" } |
| | | }; |
| | | |
| | | var roadwayKeys = roadwayMappings.Keys.ToArray(); |
| | | |
| | | var taskHty = _task_HtyRepository.Db.Queryable<Dt_Task_Hty>() |
| | | .Where(it => |
| | | it.CreateDate >= thirtyDaysAgo && |
| | | it.CreateDate <= now && |
| | | it.TaskType == 100 && |
| | | roadwayKeys.Any(rk => it.Roadway.Contains(rk))) |
| | | .ToList() |
| | | .Select(t => new { |
| | | OriginalRoadway = t.Roadway, |
| | | MatchedKey = roadwayKeys.FirstOrDefault(rk => t.Roadway.Contains(rk)), |
| | | CreateDate = t.CreateDate |
| | | }) |
| | | .Where(t => t.MatchedKey != null) |
| | | .GroupBy(t => new { |
| | | RoadwayKey = t.MatchedKey, |
| | | Date = t.CreateDate.Date, |
| | | Hour = t.CreateDate.Hour |
| | | }) |
| | | .OrderByDescending(group => group.Key.Date) |
| | | .ThenByDescending(group => group.Key.Hour) |
| | | .Select(group => new { |
| | | Hour = $"{group.Key.Date:yyyy/M/d} {group.Key.Hour}:00", |
| | | Count = group.Count(), |
| | | Roadway = roadwayMappings[group.Key.RoadwayKey] // 映射为中文名称 |
| | | }) |
| | | .ToList(); |
| | | return content.OK1(total1: taskHty.Count, data: taskHty); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | } |