163 lines
8.1 KiB
C#
163 lines
8.1 KiB
C#
using BaseOUDAL;
|
|
using YLErp.Model;
|
|
|
|
namespace YLErp.Modules.SuperviseReportModule.ChangJiangReport.Service
|
|
{
|
|
public class SuperviseReportClientCashService : YLBaseService
|
|
{
|
|
public SuperviseReportClientCashService(OptUserInfo userInfo) : base(userInfo)
|
|
{
|
|
}
|
|
|
|
public SuperviseReportClientCashService(YLBaseService baseService) : base(baseService)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 从数据库中查询客户资金信息
|
|
/// <para>长江数据采集用</para>
|
|
/// </summary>
|
|
public SearchListResult<SuperviseClientCashDbModel> SearchSuperviseReportList(SuperviseReportReq req)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(req.sidx)) { req.sidx = "ClientName"; }
|
|
|
|
var query = from db in DbContext.SuperviseReportClientCash
|
|
where db.Date == req.ValueDate
|
|
select db;
|
|
if (req.DataType != null && !req.DataType.Contains("全量客户"))
|
|
{
|
|
List<string> clientNames = new List<string>();
|
|
foreach (var dataType in req.DataType)
|
|
{
|
|
switch (dataType)
|
|
{
|
|
case "有持仓":
|
|
var names = (from et in DbContext.eod_trade
|
|
join t in DbContext.trade
|
|
on et.TradeId equals t.id
|
|
where et.ValueDate == req.ValueDate
|
|
select t.ClientName).ToArray();
|
|
clientNames.AddRange(names);
|
|
break;
|
|
case "有资金":
|
|
clientNames.AddRange(from cb in DbContext.ClientBalanceDaily.Where(n => n.BalanceDate == req.ValueDate)
|
|
join cr in DbContext.credit.Where(n => n.ProcessStatus == "已审批" && (n.CreditStartDate == null || n.CreditStartDate <= req.ValueDate) && n.CreditDeadLine >= req.ValueDate)
|
|
on cb.ClientId equals cr.ClientId into t_cr
|
|
from cr in t_cr.DefaultIfEmpty()
|
|
where !((cb.ToDayRemainFund == null || (cb.ToDayRemainFund < 0.0001 && cb.ToDayRemainFund > -0.0001)) &&
|
|
//(cb.TodayRemianFundProduct == null || (cb.TodayRemianFundProduct < 0.0001 && cb.TodayRemianFundProduct > -0.0001)) &&
|
|
(cb.MarginBalance == null || (cb.MarginBalance < 0.0001 && cb.MarginBalance > -0.0001)) &&
|
|
(cb.PayableMargin == null || (cb.PayableMargin < 0.0001 && cb.PayableMargin > -0.0001)) &&
|
|
//(cb.FrozenMarginMoney == null || cb.FrozenMarginMoney < 0.0001) &&
|
|
(cb.PositionPremiumNetCash == null || (cb.PositionPremiumNetCash < 0.0001 && cb.PositionPremiumNetCash > -0.0001)))
|
|
select cb.ClientName);
|
|
break;
|
|
}
|
|
}
|
|
if (clientNames.Count > 0)
|
|
{ query = query.Where(O => clientNames.Contains(O.ClientName)); }
|
|
}
|
|
|
|
return query.ToSearchList(req);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存客户资金报送信息到数据库
|
|
/// <para>长江数据采集用</para>
|
|
/// </summary>
|
|
/// <param name="valueDate">数据日期</param>
|
|
public void SaveReportData(DateTime valueDate, IEnumerable<int> clienIds = null)
|
|
{
|
|
using (var db = DbContextFactory.GetYLDbContext())
|
|
{
|
|
var models = db.SuperviseReportClientCash.Where(a => a.Date == valueDate);
|
|
if (!models.Any())
|
|
{
|
|
var req = new SuperviseReportReq();
|
|
req.ValueDate = valueDate;
|
|
req.page = 1;
|
|
req.rows = 100000;
|
|
var list = new CFMMC.Service.SuperviseReportClientCashService(OptUser).SearchSuperviseReportList(req, clienIds);
|
|
List<SuperviseClientCashDbModel> objs = new List<SuperviseClientCashDbModel>();
|
|
foreach (var item in list.rows)
|
|
{
|
|
objs.Add(new SuperviseClientCashDbModel()
|
|
{
|
|
CompanyName = item.CompanyName,
|
|
CompanyLicenseCode = item.CompanyLicenseCode,
|
|
Date = item.Date,
|
|
ClientName = item.ClientName,
|
|
ClientType = item.ClientType,
|
|
ClientLicenseCode = item.ClientLicenseCode,
|
|
ToClientCredit = item.ToClientCredit,
|
|
ClientTradePriceCredit = item.ClientTradePriceCredit,
|
|
PositionTradePriceOut = item.PositionTradePriceOut,
|
|
ToCompanyCredit = item.ClientName.Contains("保险") ? 0 : item.ToClientCredit,
|
|
PositionTradePriceIn = item.PositionTradePriceIn,
|
|
OpenBalance = item.OpenBalance,
|
|
TodayCashInCashOut = item.TodayCashInCashOut,
|
|
TodaySettleEarnings = item.TodaySettleEarnings,
|
|
TodayOpenTradePrice = item.TodayOpenTradePrice,
|
|
MarginPayTime = item.MarginPayTime,
|
|
MarginType = item.MarginType,
|
|
ClientMarginHold = item.ClientMarginHold,
|
|
CompanyMarginHold = item.CompanyMarginHold,
|
|
AddFunds = item.AddFunds,
|
|
PositionValue = item.PositionValue,
|
|
Remark = item.Remark,
|
|
|
|
ClientPositionCredit = item.ClientPositionCredit,
|
|
CompanyPositionCredit = item.CompanyPositionCredit,
|
|
CompanyTradePriceCredit = item.CompanyTradePriceCredit,
|
|
EndBalance = item.EndBalance,
|
|
AvailableCash = item.AvailableCash,
|
|
DesirableFund = item.DesirableFund,
|
|
MarketValueEquity = item.MarketValueEquity,
|
|
});
|
|
}
|
|
//db.BulkDelete<SuperviseClientCashDbModel>($"{nameof(SuperviseClientCashDbModel.Date)}=@Date", new { Date = req.ValueDate });
|
|
|
|
if (objs.Any())
|
|
{
|
|
db.SuperviseReportClientCash.AddRange(objs);
|
|
db.SaveChanges();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void BatchSuperviseClientCash(List<int> Ids, DateTime ValueDate, bool IsAll, string Type)
|
|
{
|
|
var predicate = PredicateBuilder.True<SuperviseClientCashDbModel>().And(a => a.Date == ValueDate);
|
|
if (!IsAll)//非全选
|
|
{
|
|
predicate = predicate.And(a => Ids.Contains(a.id));
|
|
}
|
|
using (var db = DbContextFactory.GetYLDbContext())
|
|
{
|
|
var clietnCashs = db.SuperviseReportClientCash.Where(predicate);
|
|
if (clietnCashs.Any())
|
|
{
|
|
if (Type == "update")//更新确认状态
|
|
{
|
|
foreach (var item in clietnCashs)
|
|
{
|
|
item.Status = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
db.SuperviseReportClientCash.RemoveRange(clietnCashs);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new ServiceException("没有数据进行批量操作");
|
|
}
|
|
db.SaveChanges();
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|