| | |
| | | |
| | | #region 火警出库 |
| | | |
| | | public WebResponseContent EmergencyTask(object obj) |
| | | public WebResponseContent EmergencyTask(Object obj) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | var emergencyTask = new DTSEmergencyTask(); |
| | | try |
| | | { |
| | | Console.WriteLine($"火警参数:{obj.ToString()}"); |
| | | 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("未知库位"); |
| | |
| | | TaskType = task.TaskType, |
| | | }; |
| | | |
| | | List<WMSTaskDTO> taskDTOs = new List<WMSTaskDTO>(); |
| | | taskDTOs.Add(taskDTO); |
| | | |
| | | var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); |
| | | var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.WCSIPAddress)?.ConfigValue; |
| | | var ReceiveByWMSTask = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.ReceiveByWMSTask)?.ConfigValue; |
| | | var ReceiveByWMSTask = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.ReceiveWMSTask)?.ConfigValue; |
| | | if (ReceiveByWMSTask == null || ipAddress == null) |
| | | { |
| | | throw new Exception("WMS IP 未配置"); |
| | | } |
| | | var wmsIpAddrss = ipAddress + ReceiveByWMSTask; |
| | | |
| | | var respon = HttpHelper.Post(wmsIpAddrss, JsonConvert.SerializeObject(taskDTO)); |
| | | var respon = HttpHelper.Post(wmsIpAddrss, JsonConvert.SerializeObject(taskDTOs)); |
| | | if (respon != null) |
| | | { |
| | | WebResponseContent respone = JsonConvert.DeserializeObject<WebResponseContent>(respon.ToString()); |
| | |
| | | } |
| | | 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 result = _stockInfoRepository.Db.Queryable<DtStockInfo>().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 taskTypes = new[] { 100, 104, 200, 204 }; |
| | | |
| | | var taskHty = _task_HtyRepository.Db.Queryable<Dt_Task_Hty>() |
| | | .Where(it => |
| | | it.CreateDate >= thirtyDaysAgo && |
| | | it.CreateDate <= now && |
| | | taskTypes.Contains(it.TaskType) && |
| | | roadwayKeys.Any(rk => it.Roadway.Contains(rk))) |
| | | .ToList() |
| | | .Select(t => new { |
| | | OriginalRoadway = t.Roadway, |
| | | RoadwayKey = roadwayKeys.FirstOrDefault(rk => t.Roadway.Contains(rk)), |
| | | TaskType = t.TaskType, |
| | | CreateDate = t.CreateDate |
| | | }) |
| | | .Where(t => t.RoadwayKey != null) |
| | | .GroupBy(t => new { |
| | | RoadwayKey = t.RoadwayKey, |
| | | Date = t.CreateDate.Date, |
| | | Hour = t.CreateDate.Hour |
| | | }) |
| | | .OrderByDescending(group => group.Key.Date) |
| | | .ThenByDescending(group => group.Key.Hour) |
| | | .Select(group => new TaskHourData |
| | | { |
| | | Hour = $"{group.Key.Date:yyyy/M/d} {(group.Key.Hour == 23 ? "23:00-24:00" : $"{group.Key.Hour}:00-{group.Key.Hour + 1}:00")}", |
| | | Roadway = roadwayMappings[group.Key.RoadwayKey], |
| | | TaskType100Count = group.Count(t => t.TaskType == 100), |
| | | TaskType104Count = group.Count(t => t.TaskType == 104), |
| | | TaskType200Count = group.Count(t => t.TaskType == 200), |
| | | TaskType204Count = group.Count(t => t.TaskType == 204) |
| | | }) |
| | | .ToList(); |
| | | |
| | | // 按日期和库位分组,找出每天的最后一个小时 |
| | | var dailyLastHours = taskHty |
| | | .GroupBy(item => new { |
| | | Date = DateTime.Parse(item.Hour.Split(' ')[0]), |
| | | item.Roadway |
| | | }) |
| | | .Select(group => new { |
| | | Date = group.Key.Date, |
| | | Roadway = group.Key.Roadway, |
| | | LastHour = group.Max(item => int.Parse(item.Hour.Split(' ')[1].Split(':')[0])) |
| | | }) |
| | | .ToList(); |
| | | |
| | | // 生成汇总数据(调整Hour格式为"日期+日汇总") |
| | | var summaryItems = dailyLastHours |
| | | .Select(dailyLastHour => { |
| | | // 找到该日期该库位的所有小时数据 |
| | | var dailyItems = taskHty |
| | | .Where(item => |
| | | DateTime.Parse(item.Hour.Split(' ')[0]) == dailyLastHour.Date && |
| | | item.Roadway == dailyLastHour.Roadway) |
| | | .ToList(); |
| | | |
| | | return new TaskHourData |
| | | { |
| | | Hour = $"{dailyLastHour.Date:yyyy/M/d}日汇总", // 修改Hour格式 |
| | | Roadway = dailyLastHour.Roadway, |
| | | TaskType100Count = dailyItems.Sum(item => item.TaskType100Count), |
| | | TaskType104Count = dailyItems.Sum(item => item.TaskType104Count), |
| | | TaskType200Count = dailyItems.Sum(item => item.TaskType200Count), |
| | | TaskType204Count = dailyItems.Sum(item => item.TaskType204Count), |
| | | IsSummary = true |
| | | }; |
| | | }) |
| | | .ToList(); |
| | | |
| | | // 将汇总数据添加到结果中 |
| | | taskHty = taskHty.Concat(summaryItems).ToList(); |
| | | |
| | | // 调整排序逻辑:先按日期降序,再按是否汇总(汇总在前),最后按小时降序 |
| | | taskHty = taskHty |
| | | .OrderByDescending(item => { |
| | | var datePart = item.Hour.Contains("日汇总") |
| | | ? item.Hour.Split("日汇总")[0] |
| | | : item.Hour.Split(' ')[0]; |
| | | return DateTime.Parse(datePart); |
| | | }) |
| | | .ThenByDescending(item => item.IsSummary) // 汇总数据排在前面 |
| | | .ThenByDescending(item => { |
| | | if (!item.IsSummary && item.Hour.Contains(' ')) |
| | | { |
| | | return int.Parse(item.Hour.Split(' ')[1].Split(':')[0]); |
| | | } |
| | | return 0; |
| | | }) |
| | | .ToList(); |
| | | return content.OK1(total1: taskHty.Count, data: taskHty); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | } |
| | | |
| | | internal class TaskHourData |
| | | { |
| | | public string Hour { get; set; } |
| | | public string Roadway { get; set; } |
| | | public int TaskType100Count { get; set; } |
| | | public int TaskType104Count { get; set; } |
| | | public int TaskType200Count { get; set; } |
| | | public int TaskType204Count { get; set; } |
| | | public bool IsSummary { get; set; } = false; |
| | | } |