Files
zszq-trs/YLErpDAL/Modules/SuperviseReportModule/ExtendReport/DongWu/CustomerFundsReport.cs
T
2024-05-09 14:06:26 +08:00

158 lines
6.0 KiB
C#

using YLErp.BLL;
using YLErp.Helpers;
using YLErp.Model;
using YLErp.Modules.ClientModule;
namespace YLErp.Modules.SuperviseReportModule.ExtendReport.GeLin
{
/// <summary>
/// 资金记录页面新增余额列
/// </summary>
public class CustomerFundsReport : ExtendReportBaseService
{
public CustomerFundsReport(OptUserInfo userInfo, SuperviseReportReq req) : base(userInfo, req)
{ }
public override string TemplateName => "客户资金记录报表.xlsx";
public override string TargetFileName => $"客户资金记录报表{RequestInfo.ValueDate:yyyy-MM-dd}~{RequestInfo.EndDate:yyyy-MM-dd}.xlsx";
public override Dictionary<string, object> SearchReportInfo()
{
var endDate = RequestInfo.EndDate;
var maxDate = DbContext.ClientBalanceDaily.Where(O => O.BalanceDate <= endDate).Max(O => O.BalanceDate);
if (maxDate == null || maxDate < RequestInfo.ValueDate)
{
throw new ServiceException("该客户未收盘!!");
}
var cashDict =
DbContext.ClientBalanceDaily
.Where(O => O.BalanceDate == maxDate)
.Select(O => new { O.ClientName, O.ToDayRemainFund })
.ToDictionary(K => K.ClientName, V => V.ToDayRemainFund);
var clientIdArr = JsonHelper.Parse<List<int>>(RequestInfo.ExtendParamer ?? "[]");
var req = new EntryExitReq
{
HappenDateStart = RequestInfo.ValueDate,
HappenDateEnd = RequestInfo.EndDate,
ClientIds = string.Join(",", clientIdArr)
};
var sList = new EntryExitBLL().SearchListExtend(req, out _, true);
var list = sList.rows.ToList();
list.Sort((X, Y) =>
{
var val = string.Compare(X.ClientName, Y.ClientName);
if (val != 0)
{
return -val;
}
val = DateTime.Compare(X.HappenDate.GetValueOrDefault(), Y.HappenDate.GetValueOrDefault());
if (val != 0)
{
return -val;
}
val = string.Compare(X.Number, Y.Number);
if (val != 0)
{
return -val;
}
return 0;
});
foreach (var item in cashDict)
{
cashDict[item.Key] += list.Where(O => O.HappenDate > maxDate).Sum(O => O.Money);
}
var dict = new List<DongWu_ClientPositionNotional>();
foreach (var item in list)
{
if (cashDict[item.ClientName] == null)
{
continue;
}
if (item.Direction == "出金")
{
item.Money = 0 - item.Money;
}
var obj = new DongWu_ClientPositionNotional
{
Action = item.Action,
CashFlag = item.CashFlag,
OptDate = item.OptDate,
HappenDate = item.HappenDate,
Number = item.Number,
ClientName = item.ClientName,
Direction = item.Direction,
Money = item.Money,
Balance = cashDict[item.ClientName].GetValueOrDefault(),
CurrencyCode = item.CurrencyCode,
TradeNumber = item.TradeNumber,
UnderlyingCode = item.UnderlyingCode,
State = item.State,
OptName = item.OptName,
Comments = item.Comments
};
dict.Add(obj);
cashDict[item.ClientName] -= item.Money;
}
return new Dictionary<string, object>()
{
{"最终导出报告",dict }
};
}
public List<int> GetClientIdsByCustomerManager()
{
var clients = DbContextFactory.GetClientDbContext(UserInfo).client.AsQueryable().ToList();
var clientCustomerManager = new ClientDataService(UserInfo).GetClientsByCustomerManager(clients, true);
if (clientCustomerManager.Any())
{
return clientCustomerManager.Select(a => a.id).ToList();
}
return new List<int>();
}
public class DongWu_ClientPositionNotional : ClientCashInCashOutExtend
{
public new string DirectionType
{
get
{
if (CashFlag == 21)
{
return "调入";
}
if (CashFlag == 121)
{
return "调出";
}
if (Direction == "应收")
{
var action = "";
if (Action == "系统操作-平仓费" || Action == "系统操作-行权费")
{
action = "平仓/行权";
}
else if (Action == "系统操作-期权费")
{
action = "权利金";
}
else if (Action == "系统操作-票息")
{
action = "票息";
}
else if (Action == "系统操作-互换")
{
action = "互换";
}
if (!action.IsNullOrWhiteSpace())
{
return $"{action}{(Money > 0 ? "收入" : "支出")}";
}
}
return Direction;
}
}
public double Balance { get; set; }
}
}
}