605 lines
32 KiB
C#
605 lines
32 KiB
C#
using BaseOUDAL;
|
|
using System.Data.SqlTypes;
|
|
using YLErp.BLL.EodSettlement;
|
|
using YLErp.Model.Enum;
|
|
|
|
namespace YLErp.BLL
|
|
{
|
|
public class clientcashincashout_productBLL
|
|
{
|
|
private readonly YLContext db = new YLContext();
|
|
|
|
public static List<string> OptStatus = new List<string> { ClientCashInCashOut.未确认, ClientCashInCashOut.已确认, ClientCashInCashOut.拒绝 };
|
|
|
|
/// <summary>
|
|
/// 查询clientcashincashout_product
|
|
/// </summary>
|
|
public SearchListResult<clientcashincashout_productLinq> SearchList(clientcashincashout_productReq req, out clientcashincashout_productGridSum gsum)
|
|
{
|
|
var eodSettlePriceMode = valuedateBLL.SystemDate.EodSettlePriceMode;
|
|
|
|
var query = from source in db.clientcashincashout_product
|
|
join underlying in db.underlying_manager on source.UnderlyingId equals underlying.id into underlying_manager
|
|
from underlying in underlying_manager.DefaultIfEmpty()
|
|
join v in db.variety on source.VarietyId equals v.id into variety
|
|
from v in variety.DefaultIfEmpty()
|
|
select new clientcashincashout_productLinq
|
|
{
|
|
BackDate = source.BackDate,
|
|
ClientId = source.ClientId,
|
|
ClientName = source.ClientName,
|
|
ClientNumber = source.ClientNumber,
|
|
Comments = source.Comments,
|
|
CreateDate = source.CreateDate,
|
|
CreatorId = source.CreatorId,
|
|
CreatorName = source.CreatorName,
|
|
ExcuteDate = source.ExcuteDate,
|
|
ExcuteId = source.ExcuteId,
|
|
ExcuteName = source.ExcuteName,
|
|
HappenDate = source.HappenDate,
|
|
id = source.id,
|
|
Number = source.Number,
|
|
OptDate = source.OptDate,
|
|
OptId = source.OptId,
|
|
ProductAmount = source.ProductAmount,
|
|
Rate = source.Rate,
|
|
OptName = source.OptName,
|
|
OptStatus = source.OptStatus,
|
|
SerialNumber = source.SerialNumber,
|
|
ProductTotalPrice = source.ProductAmount * source.Rate * (underlying == null ? 0 : underlying.Price),
|
|
SpotPrice = underlying == null ? 0 : underlying.Price,
|
|
Status = source.Status,
|
|
VarietyId = source.VarietyId,
|
|
VarietyShortName = v.ShortName,
|
|
UnderlyingId = source.UnderlyingId,
|
|
UnderlyingCode = underlying.UnderlyingCode
|
|
};
|
|
|
|
if (req.ValueDate != null && req.ValueDate != DateTime.MinValue)
|
|
{
|
|
var valueDate = req.ValueDate.Value.Date;
|
|
query = from source in db.clientcashincashout_product
|
|
join underlying in db.underlying_manager on source.UnderlyingId equals underlying.id into underlying_manager
|
|
from underlying in underlying_manager.DefaultIfEmpty()
|
|
join commodityFuturePrice in db.eod_commodity_future_price.Where(n => n.ValueDate == valueDate) on underlying.UnderlyingCode equals commodityFuturePrice.UnderlyingCode
|
|
into commodityFuturePrices
|
|
from commodityFuturePrice in commodityFuturePrices.DefaultIfEmpty()
|
|
join stockPrice in db.eod_stock_price.Where(n => n.ValueDate == valueDate) on underlying.UnderlyingCode equals stockPrice.UnderlyingCode
|
|
into stockPrices
|
|
from stockPrice in stockPrices.DefaultIfEmpty()
|
|
join v in db.variety on source.VarietyId equals v.id into variety
|
|
from v in variety.DefaultIfEmpty()
|
|
select new clientcashincashout_productLinq
|
|
{
|
|
BackDate = source.BackDate,
|
|
ClientId = source.ClientId,
|
|
ClientName = source.ClientName,
|
|
ClientNumber = source.ClientNumber,
|
|
Comments = source.Comments,
|
|
CreateDate = source.CreateDate,
|
|
CreatorId = source.CreatorId,
|
|
CreatorName = source.CreatorName,
|
|
ExcuteDate = source.ExcuteDate,
|
|
ExcuteId = source.ExcuteId,
|
|
ExcuteName = source.ExcuteName,
|
|
HappenDate = source.HappenDate,
|
|
id = source.id,
|
|
Number = source.Number,
|
|
OptDate = source.OptDate,
|
|
OptId = source.OptId,
|
|
ProductAmount = source.ProductAmount,
|
|
Rate = source.Rate,
|
|
OptName = source.OptName,
|
|
OptStatus = source.OptStatus,
|
|
SerialNumber = source.SerialNumber,
|
|
ProductTotalPrice = source.ProductAmount * source.Rate * (commodityFuturePrice != null ? (eodSettlePriceMode == "结算价" ? commodityFuturePrice.SettlePrice : commodityFuturePrice.ClosePrice) : (stockPrice != null ? stockPrice.ClosePrice : (underlying == null ? 0 : underlying.Price))),
|
|
SpotPrice = commodityFuturePrice != null ? (eodSettlePriceMode == "结算价" ? commodityFuturePrice.SettlePrice : commodityFuturePrice.ClosePrice) : (stockPrice != null ? stockPrice.ClosePrice : (underlying == null ? 0 : underlying.Price)),
|
|
Status = source.Status,
|
|
VarietyId = source.VarietyId,
|
|
VarietyShortName = v.ShortName,
|
|
UnderlyingId = source.UnderlyingId,
|
|
UnderlyingCode = underlying.UnderlyingCode
|
|
};
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(req.Status))
|
|
{
|
|
query = query.Where(d => d.Status != null && req.Status.Contains(d.Status));
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(req.Number))
|
|
{
|
|
query = query.Where(d => d.Number.Contains(req.Number));
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(req.ClientIdString))
|
|
{
|
|
query = query.Where(d => d.ClientId != null && req.ClientIds.Contains(d.ClientId.ToString()));
|
|
}
|
|
else if (req.ClientId != null)
|
|
{
|
|
query = query.Where(d => d.ClientId == req.ClientId);
|
|
}
|
|
if (!string.IsNullOrEmpty(req.VarietyIdString))
|
|
{
|
|
query = query.Where(d => d.VarietyId != null && req.VarietyIds.Contains(d.VarietyId.ToString()));
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(req.ClientNumber))
|
|
{
|
|
query = query.Where(d => d.ClientNumber.Contains(req.ClientNumber));
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(req.ClientName))
|
|
{
|
|
query = query.Where(d => d.ClientName.Contains(req.ClientName));
|
|
}
|
|
|
|
if (req.ProductAmount != null)
|
|
{
|
|
query = query.Where(d => d.ProductAmount == req.ProductAmount);
|
|
}
|
|
|
|
if (req.Rate != null)
|
|
{
|
|
query = query.Where(d => d.Rate == req.Rate);
|
|
}
|
|
|
|
if (req.UnderlyingId != null)
|
|
{
|
|
query = query.Where(d => d.UnderlyingId == req.UnderlyingId);
|
|
}
|
|
|
|
if (req.HappenDateStart != DateTime.MinValue)
|
|
{
|
|
query = query.Where(d => d.HappenDate >= req.HappenDateStart);
|
|
}
|
|
|
|
if (req.HappenDateEnd != DateTime.MinValue)
|
|
{
|
|
DateTime HappenDateTemp = req.HappenDateEnd.AddDays(1);
|
|
query = query.Where(d => d.HappenDate < HappenDateTemp);
|
|
}
|
|
if (req.BackDateStart != DateTime.MinValue)
|
|
{
|
|
query = query.Where(d => d.BackDate >= req.BackDateStart);
|
|
}
|
|
|
|
if (req.BackDateEnd != DateTime.MinValue)
|
|
{
|
|
DateTime BackDateTemp = req.BackDateEnd.AddDays(1);
|
|
query = query.Where(d => d.BackDate < BackDateTemp);
|
|
}
|
|
if (!string.IsNullOrEmpty(req.OptStatus))
|
|
{
|
|
query = query.Where(d => d.OptStatus != null && req.OptStatus.Contains(d.OptStatus));
|
|
}
|
|
|
|
if (req.OptId != null)
|
|
{
|
|
query = query.Where(d => d.OptId == req.OptId);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(req.OptName))
|
|
{
|
|
query = query.Where(d => d.OptName.Contains(req.OptName));
|
|
}
|
|
|
|
if (req.OptDateStart != DateTime.MinValue)
|
|
{
|
|
query = query.Where(d => d.OptDate >= req.OptDateStart);
|
|
}
|
|
|
|
if (req.OptDateEnd != DateTime.MinValue)
|
|
{
|
|
DateTime OptDateTemp = req.OptDateEnd.AddDays(1);
|
|
query = query.Where(d => d.OptDate < OptDateTemp);
|
|
}
|
|
|
|
if (req.ValueDate != null && req.ValueDate != DateTime.MinValue)
|
|
{
|
|
var valueDate = req.ValueDate.Value.AddDays(1);
|
|
query = query.Where(d => d.HappenDate < valueDate &&
|
|
((d.Status == Clientcashincashout_productStatusEnum.抵押.ToString() && d.OptStatus == ClientCashInCashOut.已确认
|
|
|| d.Status == Clientcashincashout_productStatusEnum.赎回.ToString() && d.OptStatus != ClientCashInCashOut.已确认)
|
|
|| d.Status == Clientcashincashout_productStatusEnum.赎回.ToString() && d.OptStatus == ClientCashInCashOut.已确认 && d.BackDate >= valueDate)
|
|
);
|
|
}
|
|
if (string.IsNullOrEmpty(req.sidx))
|
|
{
|
|
req.sidx = "HappenDate,id";
|
|
req.sord = "desc";
|
|
}
|
|
SearchListResult<clientcashincashout_productLinq> retListResult = query.ToSearchList(req);
|
|
|
|
gsum = new clientcashincashout_productGridSum();
|
|
if (query.Any())
|
|
{
|
|
gsum.RateSum = query.Sum(q => q.Rate);
|
|
gsum.ProductTotalPriceSum = query.Sum(x => x.ProductTotalPrice);
|
|
}
|
|
retListResult.Sum = gsum;
|
|
|
|
|
|
return retListResult;
|
|
}
|
|
public List<clientcashincashout_productLinq> SearchListOnly(clientcashincashout_productReq req)
|
|
{
|
|
var eodSettlePriceMode = valuedateBLL.SystemDate.EodSettlePriceMode;
|
|
|
|
var query = from source in db.clientcashincashout_product
|
|
join underlying in db.underlying_manager on source.UnderlyingId equals underlying.id into underlying_manager
|
|
from underlying in underlying_manager.DefaultIfEmpty()
|
|
join v in db.variety on source.VarietyId equals v.id into variety
|
|
from v in variety.DefaultIfEmpty()
|
|
select new clientcashincashout_productLinq
|
|
{
|
|
BackDate = source.BackDate,
|
|
ClientId = source.ClientId,
|
|
ClientName = source.ClientName,
|
|
ClientNumber = source.ClientNumber,
|
|
Comments = source.Comments,
|
|
CreateDate = source.CreateDate,
|
|
CreatorId = source.CreatorId,
|
|
CreatorName = source.CreatorName,
|
|
ExcuteDate = source.ExcuteDate,
|
|
ExcuteId = source.ExcuteId,
|
|
ExcuteName = source.ExcuteName,
|
|
HappenDate = source.HappenDate,
|
|
id = source.id,
|
|
Number = source.Number,
|
|
OptDate = source.OptDate,
|
|
OptId = source.OptId,
|
|
ProductAmount = source.ProductAmount,
|
|
Rate = source.Rate,
|
|
OptName = source.OptName,
|
|
OptStatus = source.OptStatus,
|
|
SerialNumber = source.SerialNumber,
|
|
ProductTotalPrice = (source.ProductAmount * source.Rate * (underlying == null ? 0 : underlying.Price)) ?? 0,
|
|
SpotPrice = underlying == null ? 0 : underlying.Price,
|
|
Status = source.Status,
|
|
VarietyId = source.VarietyId,
|
|
VarietyShortName = v.ShortName,
|
|
UnderlyingId = source.UnderlyingId,
|
|
UnderlyingCode = underlying.UnderlyingCode
|
|
};
|
|
if (req != null)
|
|
{
|
|
if (req.ValueDate != null && req.ValueDate != DateTime.MinValue && req.ValueDate != SqlDateTime.MinValue.Value)
|
|
{
|
|
var valueDate = req.ValueDate.Value.Date;
|
|
query = from source in db.clientcashincashout_product
|
|
join underlying in db.underlying_manager on source.UnderlyingId equals underlying.id into underlying_manager
|
|
from underlying in underlying_manager.DefaultIfEmpty()
|
|
join commodityFuturePrice in db.eod_commodity_future_price.Where(n => n.ValueDate == valueDate) on underlying.UnderlyingCode equals commodityFuturePrice.UnderlyingCode
|
|
into commodityFuturePrices
|
|
from commodityFuturePrice in commodityFuturePrices.DefaultIfEmpty()
|
|
join stockPrice in db.eod_stock_price.Where(n => n.ValueDate == valueDate) on underlying.UnderlyingCode equals stockPrice.UnderlyingCode
|
|
into stockPrices
|
|
from stockPrice in stockPrices.DefaultIfEmpty()
|
|
join v in db.variety on source.VarietyId equals v.id into variety
|
|
from v in variety.DefaultIfEmpty()
|
|
select new clientcashincashout_productLinq
|
|
{
|
|
BackDate = source.BackDate,
|
|
ClientId = source.ClientId,
|
|
ClientName = source.ClientName,
|
|
ClientNumber = source.ClientNumber,
|
|
Comments = source.Comments,
|
|
CreateDate = source.CreateDate,
|
|
CreatorId = source.CreatorId,
|
|
CreatorName = source.CreatorName,
|
|
ExcuteDate = source.ExcuteDate,
|
|
ExcuteId = source.ExcuteId,
|
|
ExcuteName = source.ExcuteName,
|
|
HappenDate = source.HappenDate,
|
|
id = source.id,
|
|
Number = source.Number,
|
|
OptDate = source.OptDate,
|
|
OptId = source.OptId,
|
|
ProductAmount = source.ProductAmount,
|
|
Rate = source.Rate,
|
|
OptName = source.OptName,
|
|
OptStatus = source.OptStatus,
|
|
SerialNumber = source.SerialNumber,
|
|
ProductTotalPrice = (source.ProductAmount * source.Rate * (commodityFuturePrice != null ? (eodSettlePriceMode == "结算价" ? commodityFuturePrice.SettlePrice : commodityFuturePrice.ClosePrice) : (stockPrice != null ? stockPrice.ClosePrice : (underlying == null ? 0 : underlying.Price)))) ?? 0,
|
|
SpotPrice = commodityFuturePrice != null ? (eodSettlePriceMode == "结算价" ? commodityFuturePrice.SettlePrice : commodityFuturePrice.ClosePrice) : (stockPrice != null ? stockPrice.ClosePrice : (underlying == null ? 0 : underlying.Price)),
|
|
Status = source.Status,
|
|
VarietyId = source.VarietyId,
|
|
VarietyShortName = v.ShortName,
|
|
UnderlyingId = source.UnderlyingId,
|
|
UnderlyingCode = underlying.UnderlyingCode
|
|
};
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(req.Status))
|
|
{
|
|
query = query.Where(d => d.Status != null && req.Status.Contains(d.Status));
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(req.Number))
|
|
{
|
|
query = query.Where(d => d.Number.Contains(req.Number));
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(req.ClientIdString))
|
|
{
|
|
query = query.Where(d => d.ClientId != null && req.ClientIds.Contains(d.ClientId.ToString()));
|
|
}
|
|
else if (req.ClientId != null)
|
|
{
|
|
query = query.Where(d => d.ClientId == req.ClientId);
|
|
}
|
|
if (!string.IsNullOrEmpty(req.VarietyIdString))
|
|
{
|
|
query = query.Where(d => d.VarietyId != null && req.VarietyIds.Contains(d.VarietyId.ToString()));
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(req.ClientNumber))
|
|
{
|
|
query = query.Where(d => d.ClientNumber.Contains(req.ClientNumber));
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(req.ClientName))
|
|
{
|
|
query = query.Where(d => d.ClientName.Contains(req.ClientName));
|
|
}
|
|
|
|
if (req.ProductAmount != null)
|
|
{
|
|
query = query.Where(d => d.ProductAmount == req.ProductAmount);
|
|
}
|
|
|
|
if (req.Rate != null)
|
|
{
|
|
query = query.Where(d => d.Rate == req.Rate);
|
|
}
|
|
|
|
if (req.UnderlyingId != null)
|
|
{
|
|
query = query.Where(d => d.UnderlyingId == req.UnderlyingId);
|
|
}
|
|
|
|
if (req.HappenDateStart != DateTime.MinValue && req.HappenDateStart != SqlDateTime.MinValue.Value)
|
|
{
|
|
query = query.Where(d => d.HappenDate >= req.HappenDateStart);
|
|
}
|
|
|
|
if (req.HappenDateEnd != DateTime.MinValue && req.HappenDateEnd != SqlDateTime.MinValue.Value)
|
|
{
|
|
DateTime HappenDateTemp = req.HappenDateEnd.AddDays(1);
|
|
query = query.Where(d => d.HappenDate < HappenDateTemp);
|
|
}
|
|
if (req.BackDateStart != DateTime.MinValue && req.BackDateStart != SqlDateTime.MinValue.Value)
|
|
{
|
|
query = query.Where(d => d.BackDate >= req.BackDateStart);
|
|
}
|
|
|
|
if (req.BackDateEnd != DateTime.MinValue && req.BackDateEnd != SqlDateTime.MinValue.Value)
|
|
{
|
|
DateTime BackDateTemp = req.BackDateEnd.AddDays(1);
|
|
query = query.Where(d => d.BackDate < BackDateTemp);
|
|
}
|
|
if (!string.IsNullOrEmpty(req.OptStatus))
|
|
{
|
|
query = query.Where(d => d.OptStatus != null && req.OptStatus.Contains(d.OptStatus));
|
|
}
|
|
|
|
if (req.OptId != null)
|
|
{
|
|
query = query.Where(d => d.OptId == req.OptId);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(req.OptName))
|
|
{
|
|
query = query.Where(d => d.OptName.Contains(req.OptName));
|
|
}
|
|
|
|
if (req.OptDateStart != DateTime.MinValue && req.OptDateStart != SqlDateTime.MinValue.Value)
|
|
{
|
|
query = query.Where(d => d.OptDate >= req.OptDateStart);
|
|
}
|
|
|
|
if (req.OptDateEnd != DateTime.MinValue && req.OptDateEnd != SqlDateTime.MinValue.Value)
|
|
{
|
|
DateTime OptDateTemp = req.OptDateEnd.AddDays(1);
|
|
query = query.Where(d => d.OptDate < OptDateTemp);
|
|
}
|
|
|
|
if (req.ValueDate != null && req.ValueDate != DateTime.MinValue && req.ValueDate != SqlDateTime.MinValue.Value)
|
|
{
|
|
var valueDate = req.ValueDate.Value.AddDays(1);
|
|
query = query.Where(d => d.HappenDate < valueDate &&
|
|
((d.Status == Clientcashincashout_productStatusEnum.抵押.ToString() && d.OptStatus == ClientCashInCashOut.已确认
|
|
|| d.Status == Clientcashincashout_productStatusEnum.赎回.ToString() && d.OptStatus != ClientCashInCashOut.已确认)
|
|
|| d.Status == Clientcashincashout_productStatusEnum.赎回.ToString() && d.OptStatus == ClientCashInCashOut.已确认 && d.BackDate >= valueDate)
|
|
);
|
|
}
|
|
|
|
|
|
if (req.ClientNameList != null)
|
|
{ query = query.Where(O => req.ClientNameList.Contains(O.ClientName)); }
|
|
if (req.ClientNumberList != null)
|
|
{ query = query.Where(O => req.ClientNumberList.Contains(O.ClientNumber)); }
|
|
if (req.StatusList != null)
|
|
{ query = query.Where(O => req.StatusList.Contains(O.Status)); }
|
|
if (req.RateStart != null)
|
|
{
|
|
if (req.RateStart == req.RateEnd)
|
|
{ query = query.Where(O => req.RateStart == O.Rate); }
|
|
else { query = query.Where(O => req.RateStart <= O.Rate); }
|
|
}
|
|
if (req.RateEnd != null && req.RateStart != req.RateEnd)
|
|
{ query = query.Where(O => req.RateEnd >= O.Rate); }
|
|
if (req.OptStatusList != null)
|
|
{ query = query.Where(O => req.OptStatusList.Contains(O.OptStatus)); }
|
|
if (req.VarietyShortNameList != null)
|
|
{ query = query.Where(O => req.VarietyShortNameList.Contains(O.VarietyShortName)); }
|
|
}
|
|
List<clientcashincashout_productLinq> retListResult = query.OrderByDescending(x => x.HappenDate).ThenByDescending(x => x.id).ToList();
|
|
|
|
return retListResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 盯市报告的质押记录的特殊显示方式
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
public SearchListResult<clientcashincashout_productLinq> SearchListForMarketReport(clientcashincashout_productReq req)
|
|
{
|
|
var eodSettlePriceMode = valuedateBLL.SystemDate.EodSettlePriceMode;
|
|
var valueDateAddOneDay = (req.ValueDate ?? valuedateBLL.ValueDate).AddDays(1);
|
|
|
|
var valueDate = (req.ValueDate ?? new DateTime(1949, 10, 1)).Date;
|
|
var query = from source in db.clientcashincashout_product
|
|
join underlying in db.underlying_manager on source.UnderlyingId equals underlying.id into underlying_manager
|
|
from underlying in underlying_manager.DefaultIfEmpty()
|
|
join commodityFuturePrice in db.eod_commodity_future_price.Where(n => n.ValueDate == valueDate) on underlying.UnderlyingCode equals commodityFuturePrice.UnderlyingCode
|
|
into commodityFuturePrices
|
|
from commodityFuturePrice in commodityFuturePrices.DefaultIfEmpty()
|
|
join stockPrice in db.eod_stock_price.Where(n => n.ValueDate == valueDate) on underlying.UnderlyingCode equals stockPrice.UnderlyingCode
|
|
into stockPrices
|
|
from stockPrice in stockPrices.DefaultIfEmpty()
|
|
join v in db.variety on source.VarietyId equals v.id into variety
|
|
from v in variety.DefaultIfEmpty()
|
|
select new clientcashincashout_productLinq
|
|
{
|
|
BackDate = source.BackDate,
|
|
ClientId = source.ClientId,
|
|
ClientName = source.ClientName,
|
|
ClientNumber = source.ClientNumber,
|
|
Comments = source.Comments,
|
|
ExcuteDate = source.ExcuteDate,
|
|
ExcuteId = source.ExcuteId,
|
|
ExcuteName = source.ExcuteName,
|
|
HappenDate = source.HappenDate,
|
|
id = source.id,
|
|
Number = source.Number,
|
|
OptDate = source.OptDate,
|
|
OptId = source.OptId,
|
|
ProductAmount = source.ProductAmount,
|
|
Rate = source.Rate,
|
|
OptName = source.OptName,
|
|
OptStatus = source.OptStatus,
|
|
SerialNumber = source.SerialNumber,
|
|
ProductTotalPrice = source.ProductAmount * source.Rate * (commodityFuturePrice != null ? (eodSettlePriceMode == "结算价" ? commodityFuturePrice.SettlePrice : commodityFuturePrice.ClosePrice) : (stockPrice != null ? stockPrice.ClosePrice : (underlying == null ? 0 : underlying.Price))),
|
|
SpotPrice = (commodityFuturePrice != null ? (eodSettlePriceMode == "结算价" ? commodityFuturePrice.SettlePrice : commodityFuturePrice.ClosePrice) : (stockPrice != null ? stockPrice.ClosePrice : (underlying == null ? 0 : underlying.Price))),
|
|
Status = source.Status,
|
|
VarietyId = source.VarietyId,
|
|
VarietyShortName = v.ShortName,
|
|
UnderlyingId = source.UnderlyingId,
|
|
UnderlyingCode = underlying.UnderlyingCode
|
|
};
|
|
|
|
if (req.ClientId != null && req.ParentFlag)
|
|
{
|
|
//query = query.Where(d => d.ClientId == req.ClientId);
|
|
var lists = ClientBalanceUtility.GetSubclientId(req.ClientId.Value);
|
|
query = query.Where(d => lists.Contains(d.ClientId.Value));
|
|
}
|
|
else if (req.ClientId != null && !req.ParentFlag)
|
|
{
|
|
query = query.Where(d => d.ClientId == req.ClientId);
|
|
}
|
|
|
|
if (req.ValueDate != null && req.ValueDate != DateTime.MinValue)
|
|
{
|
|
query = query.Where(d => d.HappenDate < valueDateAddOneDay &&
|
|
(d.Status == Clientcashincashout_productStatusEnum.抵押.ToString() && d.OptStatus == ClientCashInCashOut.已确认
|
|
|| d.Status == Clientcashincashout_productStatusEnum.赎回.ToString()));
|
|
}
|
|
if (string.IsNullOrEmpty(req.sidx))
|
|
{
|
|
req.sidx = "HappenDate,id";
|
|
req.sord = "desc";
|
|
}
|
|
SearchListResult<clientcashincashout_productLinq> retListResult = query.ToSearchList(req);
|
|
|
|
foreach (var x in retListResult.rows)
|
|
{
|
|
x.Status = x.Status == "赎回" && x.OptStatus == "已确认" && x.BackDate < valueDateAddOneDay ? "赎回" : "抵押";
|
|
x.BackDate = x.BackDate < valueDateAddOneDay ? x.BackDate : null;
|
|
}
|
|
|
|
return retListResult;
|
|
}
|
|
|
|
public List<clientcashincashout_productLinq> SearchListOnlyForMarketReport(clientcashincashout_productReq req)
|
|
{
|
|
var eodSettlePriceMode = valuedateBLL.SystemDate.EodSettlePriceMode;
|
|
var valueDateAddOneDay = (req.ValueDate ?? valuedateBLL.ValueDate).AddDays(1);
|
|
|
|
var valueDate = (req.ValueDate ?? new DateTime(1949, 10, 1)).Date;
|
|
var query = from source in db.clientcashincashout_product
|
|
join underlying in db.underlying_manager on source.UnderlyingId equals underlying.id into underlying_manager
|
|
from underlying in underlying_manager.DefaultIfEmpty()
|
|
join commodityFuturePrice in db.eod_commodity_future_price.Where(n => n.ValueDate == valueDate) on underlying.UnderlyingCode equals commodityFuturePrice.UnderlyingCode
|
|
into commodityFuturePrices
|
|
from commodityFuturePrice in commodityFuturePrices.DefaultIfEmpty()
|
|
join stockPrice in db.eod_stock_price.Where(n => n.ValueDate == valueDate) on underlying.UnderlyingCode equals stockPrice.UnderlyingCode
|
|
into stockPrices
|
|
from stockPrice in stockPrices.DefaultIfEmpty()
|
|
join v in db.variety on source.VarietyId equals v.id into variety
|
|
from v in variety.DefaultIfEmpty()
|
|
select new clientcashincashout_productLinq
|
|
{
|
|
BackDate = source.BackDate,
|
|
ClientId = source.ClientId,
|
|
ClientName = source.ClientName,
|
|
ClientNumber = source.ClientNumber,
|
|
Comments = source.Comments,
|
|
ExcuteDate = source.ExcuteDate,
|
|
ExcuteId = source.ExcuteId,
|
|
ExcuteName = source.ExcuteName,
|
|
HappenDate = source.HappenDate,
|
|
id = source.id,
|
|
Number = source.Number,
|
|
OptDate = source.OptDate,
|
|
OptId = source.OptId,
|
|
ProductAmount = source.ProductAmount,
|
|
Rate = source.Rate,
|
|
OptName = source.OptName,
|
|
OptStatus = source.OptStatus,
|
|
SerialNumber = source.SerialNumber,
|
|
ProductTotalPrice = source.ProductAmount * source.Rate * (commodityFuturePrice != null ? (eodSettlePriceMode == "结算价" ? commodityFuturePrice.SettlePrice : commodityFuturePrice.ClosePrice) : (stockPrice != null ? stockPrice.ClosePrice : (underlying == null ? 0 : underlying.Price))),
|
|
SpotPrice = (commodityFuturePrice != null ? (eodSettlePriceMode == "结算价" ? commodityFuturePrice.SettlePrice : commodityFuturePrice.ClosePrice) : (stockPrice != null ? stockPrice.ClosePrice : (underlying == null ? 0 : underlying.Price))),
|
|
Status = source.Status,
|
|
VarietyId = source.VarietyId,
|
|
VarietyShortName = v.ShortName,
|
|
UnderlyingId = source.UnderlyingId,
|
|
UnderlyingCode = underlying.UnderlyingCode
|
|
};
|
|
|
|
if (req.ClientId != null && req.ParentFlag)
|
|
{
|
|
//query = query.Where(d => d.ClientId == req.ClientId);
|
|
var lists = ClientBalanceUtility.GetSubclientId(req.ClientId.Value);
|
|
query = query.Where(d => lists.Contains(d.ClientId.Value));
|
|
}
|
|
else if (req.ClientId != null && !req.ParentFlag)
|
|
{
|
|
query = query.Where(d => d.ClientId == req.ClientId);
|
|
}
|
|
|
|
if (req.ValueDate != null && req.ValueDate != DateTime.MinValue)
|
|
{
|
|
query = query.Where(d => d.HappenDate < valueDateAddOneDay &&
|
|
(d.Status == Clientcashincashout_productStatusEnum.抵押.ToString() && d.OptStatus == ClientCashInCashOut.已确认
|
|
|| d.Status == Clientcashincashout_productStatusEnum.赎回.ToString()));
|
|
}
|
|
|
|
List<clientcashincashout_productLinq> retListResult = query.OrderByDescending(x => x.HappenDate).ThenByDescending(x => x.id).ToList();
|
|
|
|
retListResult.ForEach(x =>
|
|
{
|
|
x.Status = x.Status == "赎回" && x.OptStatus == "已确认" && x.BackDate < valueDateAddOneDay ? "赎回" : "抵押";
|
|
x.BackDate = x.BackDate < valueDateAddOneDay ? x.BackDate : null;
|
|
});
|
|
|
|
return retListResult;
|
|
}
|
|
|
|
}
|
|
}
|