schangxiang@126.com
2024-11-30 e52dd73ef7b44ec23a49ef2483ee813aa3b7dc96
LA24030_LuLiPackageLine_Wms/Admin.NET.Application/Service/WmsCommonnQuery/WmsCommonnQueryService.cs
@@ -7,6 +7,7 @@
using DocumentFormat.OpenXml.Office.CustomUI;
using Microsoft.CodeAnalysis.Operations;
using Admin.NET.Application.Service.WmsTask.WmsRbLineTask.Dto;
using Admin.NET.Application.Service.WmsCommonnQuery.Dto;
namespace Admin.NET.Application;
/// <summary>
@@ -22,12 +23,14 @@
    private readonly SqlSugarRepository<SysConfig> _sysConfigRep;
    private readonly SqlSugarRepository<Mes_BatchOrderUPI_New> _mesBatchOrderUpiRep;
    private readonly SqlSugarRepository<Mes_Order_Gather> _mesOrderGatherRep;
    private readonly SqlSugarRepository<Mes_Package_UnLine_Record> _mesPackage_UnLine_RecordRep;
    public WmsCommonnQueryService(SqlSugarRepository<WmsRbLineTask> rep, SqlSugarRepository<WmsStockQuan> wmsStockQuanRep
        , SqlSugarRepository<Mes_Package_Gather> mesPackageGatherRep
        , SqlSugarRepository<SysConfig> sysConfigRep
        , SqlSugarRepository<Mes_BatchOrderUPI_New> mesBatchOrderUpiRep
        , SqlSugarRepository<Mes_Order_Gather> mesOrderGatherRep
        , SqlSugarRepository<Mes_Package_UnLine_Record> mesPackage_UnLine_RecordRep
        )
    {
        _sysConfigRep = sysConfigRep;
@@ -36,6 +39,7 @@
        _wmsStockQuanRep = wmsStockQuanRep;
        _mesBatchOrderUpiRep = mesBatchOrderUpiRep;
        _mesOrderGatherRep = mesOrderGatherRep;
        _mesPackage_UnLine_RecordRep = mesPackage_UnLine_RecordRep;
    }
    /// <summary>
@@ -73,7 +77,7 @@
        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 == "无")
        {
            throw Oops.Oh($"没有配置 包装下线登陆时间 值");
            return null;
        }
        var unLineTime = Convert.ToDateTime(sysConfig_wms_unline_time.Value);
@@ -85,5 +89,102 @@
        return list; // 结果
    }
    /// <summary>
    /// 查询 当前生产订单记录 (大屏使用)
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [ApiDescriptionSettings(Name = "QueryCurrentOrder")]
    [Description("WmsCommonnQuery/QueryCurrentOrder")]
    public async Task<Mes_Order_Gather> 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; // 结果
    }
    /// <summary>
    /// 大屏 - 登录人 登录时间 LS070700117B0005GS
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet]
    [ApiDescriptionSettings(Name = "ScreenLogin")]
    [Description("WmsCommonnQuery/ScreenLogin")]
    [AllowAnonymous]
    public async Task<ScreenLoginUserOutput> 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,
            };
        }
        //获取上班时间。
        DateTime unLineTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
        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 == "无")
        {
        }
        else
        {
            unLineTime = Convert.ToDateTime(sysConfig_wms_unline_time.Value);
        }
        var recordList = await _mesPackage_UnLine_RecordRep.AsQueryable()
            .Where(x => x.CreateTime >= unLineTime)
            .ToListAsync(); // 确保获取结果为 List
                            //汇总数据
        TimeSpan ts = DateTime.Now - unLineTime;
        // 返回结果
        return new ScreenLoginUserOutput
        {
            LoginUser = list.FirstOrDefault(x => x.Code == "wms_unline_oper")?.Value,
            TimeLogin = list.FirstOrDefault(x => x.Code == "wms_unline_time")?.Value,
            AllOrderNum = recordList.GroupBy(x => x.Info5).Count(),
            AllPackageArea = recordList.Sum(x => Convert.ToDecimal((x.Info13))),
            PackageNum = recordList.GroupBy(x => x.PackageCode).Count(),
            WorkTime = ts.TotalHours
        };
    }
}