using System.Linq.Expressions;
using YLErp.Abstract;
using YLErp.Models;
using YLErp.Modules.ClientModule;
namespace YLErp.Modules.EodModule.QueryModule
{
///
/// 日终结算信息查询上下文
///
public class EodSettleInfoQueryContext : YLServiceContext, IDataSource
{
Dictionary _dic;
public EodSettleInfoQueryContext(OptUserInfo userInfo) : base(userInfo)
{
}
#region----IDataSource----
public int Count => _dic != null ? _dic.Count : 0;
public IQueryable AsQueryable(Expression> predicate = null)
{
InitClientDic();
var qry = _dic.Values.AsQueryable();
return predicate == null ? qry : qry.Where(predicate);
}
public ClientMainInfo GetData(int keyId)
{
TryGetClientInfo(keyId, out var clientInfo);
return clientInfo;
}
public void ResetDataSource()
{
_dic?.Clear();
}
#endregion
///
/// 获取客户信息
///
public bool TryGetClientInfo(int clientId, out ClientMainInfo clientInfo)
{
InitClientDic();
return _dic.TryGetValue(clientId, out clientInfo);
}
///
///
///
public List GetClientIds()
{
InitClientDic();
return _dic.Keys.ToList();
}
public List GetClientIdsOfInside()
{
var clientIds = GetClientIds();
using (var clientdb = DbContextFactory.GetClientDbContext(null))
{
if (clientIds.Any())
{
return clientdb.client.Where(a => clientIds.Contains(a.id) && a.IsInsided ==1).Select(a => a.id).ToList();
}
else
{
return new List();
}
}
}
private void InitClientDic()
{
if (_dic == null)
{
_dic = ClientDataQueryService.GetClientsFromDB(x => x.ProcessStatus != "未提交").ToDictionary(n => n.id);
}
}
}
}