using Admin.NET.Core.Service; using Admin.NET.Application.Entity; using Microsoft.AspNetCore.Http; using System.Data; using System.Web; using System.Text; using DocumentFormat.OpenXml.Office.CustomUI; using Microsoft.CodeAnalysis.Operations; using Admin.NET.Application.Service.WmsTask.WmsRbLineTask.Dto; namespace Admin.NET.Application; /// /// 通用查询服务 /// [ApiDescriptionSettings(ApplicationConst.WmsCommonnQueryGroupName, Order = 100)] [AllowAnonymous] public class WmsCommonnQueryService : IDynamicApiController, ITransient { private readonly SqlSugarRepository _rep; private readonly SqlSugarRepository _wmsStockQuanRep; private readonly SqlSugarRepository _mesPackageGatherRep; private readonly SqlSugarRepository _sysConfigRep; private readonly SqlSugarRepository _mesBatchOrderUpiRep; private readonly SqlSugarRepository _mesOrderGatherRep; public WmsCommonnQueryService(SqlSugarRepository rep, SqlSugarRepository wmsStockQuanRep , SqlSugarRepository mesPackageGatherRep , SqlSugarRepository sysConfigRep , SqlSugarRepository mesBatchOrderUpiRep , SqlSugarRepository mesOrderGatherRep ) { _sysConfigRep = sysConfigRep; _mesPackageGatherRep = mesPackageGatherRep; _rep = rep; _wmsStockQuanRep = wmsStockQuanRep; _mesBatchOrderUpiRep = mesBatchOrderUpiRep; _mesOrderGatherRep = mesOrderGatherRep; } /// /// 查询不齐套单据 /// /// /// [HttpGet] [ApiDescriptionSettings(Name = "QueryNoKittingList")] [Description("WmsCommonnQuery/QueryNoKittingList")] public async Task> QueryNoKittingList([FromQuery] KittingListInput input) { var list = await _mesOrderGatherRep.AsQueryable() .WhereIF(!string.IsNullOrWhiteSpace(input.Info5), u => u.Info5.Contains(input.Info5.Trim())) .WhereIF(!string.IsNullOrWhiteSpace(input.Info5), u => u.Info5.Contains(input.Info5.Trim())) .Where(x => ((DateTime)x.CreateTime).ToString("yyyyMMdd") == DateTime.Now.ToString("yyyyMMdd")) .Where(x => x.IsKitting == false) .OrderBy(g => g.Id) .ToListAsync(); // 确保获取结果为 List return list; // 结果 } /// /// 查询 历史生产订单记录 (大屏使用) /// /// [HttpGet] [ApiDescriptionSettings(Name = "QueryHistoryOrderList")] [Description("WmsCommonnQuery/QueryHistoryOrderList")] public async Task> QueryHistoryOrderList() { //获取上班时间。 var sysConfig_wms_unline_time = await _sysConfigRep.GetFirstAsync(x => x.Code == CommonConst.wms_unline_time); if (sysConfig_wms_unline_time == null || sysConfig_wms_unline_time.Value == "无") { return null; } var unLineTime = Convert.ToDateTime(sysConfig_wms_unline_time.Value); var list = await _mesOrderGatherRep.AsQueryable() .Where(x => x.UnlineTime >= unLineTime) .Where(x => x.IsUnline == true) .OrderByDescending(g => g.Id) .ToListAsync(); // 确保获取结果为 List return list; // 结果 } /// /// 查询 当前生产订单记录 (大屏使用) /// /// [HttpGet] [ApiDescriptionSettings(Name = "QueryCurrentOrder")] [Description("WmsCommonnQuery/QueryCurrentOrder")] public async Task QueryCurrentOrder() { //获取上班时间。 var sysConfig_wms_wms_unline_oper = await _sysConfigRep.GetFirstAsync(x => x.Code == CommonConst.wms_unline_oper); if (sysConfig_wms_wms_unline_oper == null || sysConfig_wms_wms_unline_oper.Value == "无") { return null; } var arr = sysConfig_wms_wms_unline_oper.Value.Split('|'); var packagecode = arr[0]; var packObj = await _mesPackageGatherRep.AsQueryable().FirstAsync(x => x.PackageCode == packagecode); if (packObj == null) { throw Oops.Oh($"没有找到包{packagecode}的汇总数据"); } var list = await _mesOrderGatherRep.AsQueryable() .Where(x => x.Info5 == packObj.Info5) .FirstAsync(); // 确保获取结果为 List return list; // 结果 } /// /// 大屏 - 登录人 登录时间 LS070700117B0005GS /// /// /// [HttpGet] [ApiDescriptionSettings(Name = "ScreenLogin")] [Description("WmsCommonnQuery/ScreenLogin")] [AllowAnonymous] public async Task ScreenLogin([FromQuery] Mes_Package_LineQueueInput input) { // 基本查询 var list = await _sysConfigRep.AsQueryable() .Where(x => x.Code == "wms_bz30_qitao" || x.Code == "wms_unline_oper" || x.Code == "wms_unline_time") .ToListAsync(); // 检查list是否为空 if (list == null || !list.Any()) { // 返回默认值或者抛出异常 return new ScreenLoginUserOutput { LoginUser = null, TimeLogin = null, List = null }; } // 获取 wms_bz30_qitao 对应的值 var param = list.FirstOrDefault(x => x.Code == "wms_bz30_qitao")?.Value; // 获取包裹代码 var PackageCode = string.IsNullOrEmpty(param) ? "" : param.Split("|")[0]; // 获取包裹信息 var packageGather = await _mesPackageGatherRep.GetFirstAsync(w => w.PackageCode == PackageCode); // 返回结果 return new ScreenLoginUserOutput { LoginUser = list.FirstOrDefault(x => x.Code == "wms_unline_oper")?.Value, TimeLogin = list.FirstOrDefault(x => x.Code == "wms_unline_time")?.Value, List = packageGather // 确保这里是一个有效的 Mes_Package_Gather 实例 }; } public class ScreenLoginUserOutput { public string LoginUser { get; set; } // 分组的键 public string TimeLogin { get; set; } // 登录时间(示例用) public Mes_Package_Gather List { get; set; } // 包裹信息 } }