从山证v2.3.0拷贝
This commit is contained in:
@@ -0,0 +1,651 @@
|
||||
using BaseOUDAL;
|
||||
using System.Data.SqlTypes;
|
||||
using YLErp.BLL.EodSettlement;
|
||||
using YLErp.Model.Enum;
|
||||
using YLErp.Modules;
|
||||
|
||||
namespace YLErp.BLL
|
||||
{
|
||||
public class company_collateralBLL
|
||||
{
|
||||
private readonly YLContext db = new YLContext();
|
||||
|
||||
public static List<string> OptStatus = new List<string> { ClientCashInCashOut.未确认, ClientCashInCashOut.已确认, ClientCashInCashOut.拒绝 };
|
||||
|
||||
/// <summary>
|
||||
/// 查询clientcashincashout_product
|
||||
/// </summary>
|
||||
public SearchListResult<company_collateralLinq> SearchList(company_collateralReq req, out company_collateralGridSum gsum)
|
||||
{
|
||||
var eodSettlePriceMode = valuedateBLL.SystemDate.EodSettlePriceMode;
|
||||
|
||||
var query = from source in db.company_collateral
|
||||
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 company_collateralLinq
|
||||
{
|
||||
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 * (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.company_collateral
|
||||
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 company_collateralLinq
|
||||
{
|
||||
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 (!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<company_collateralLinq> retListResult = query.ToSearchList(req);
|
||||
|
||||
gsum = new company_collateralGridSum();
|
||||
if (query.Any())
|
||||
{
|
||||
gsum.RateSum = query.Sum(q => q.Rate);
|
||||
gsum.ProductTotalPriceSum = query.Sum(x => x.ProductTotalPrice);
|
||||
}
|
||||
retListResult.Sum = gsum;
|
||||
|
||||
|
||||
return retListResult;
|
||||
}
|
||||
public List<company_collateralLinq> SearchListOnly(company_collateralReq req)
|
||||
{
|
||||
var eodSettlePriceMode = valuedateBLL.SystemDate.EodSettlePriceMode;
|
||||
|
||||
var query = from source in db.company_collateral
|
||||
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 company_collateralLinq
|
||||
{
|
||||
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 * (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.company_collateral
|
||||
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 company_collateralLinq
|
||||
{
|
||||
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)))) ?? 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 == company_collateralStatusEnum.抵押.ToString() && d.OptStatus == ClientCashInCashOut.已确认
|
||||
|| d.Status == company_collateralStatusEnum.赎回.ToString() && d.OptStatus != ClientCashInCashOut.已确认)
|
||||
|| d.Status == company_collateralStatusEnum.赎回.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<company_collateralLinq> retListResult = query.OrderByDescending(x => x.HappenDate).ThenByDescending(x => x.id).ToList();
|
||||
|
||||
return retListResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 盯市报告的质押记录的特殊显示方式
|
||||
/// </summary>
|
||||
/// <param name="req"></param>
|
||||
/// <returns></returns>
|
||||
public SearchListResult<company_collateralLinq> SearchListForMarketReport(company_collateralReq 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.company_collateral
|
||||
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 company_collateralLinq
|
||||
{
|
||||
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<company_collateralLinq> 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<company_collateralLinq> SearchListOnlyForMarketReport(company_collateralReq 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.company_collateral
|
||||
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 company_collateralLinq
|
||||
{
|
||||
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<company_collateralLinq> 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;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 客户抵押品确认操作
|
||||
/// </summary>
|
||||
/// <param name="entryids"></param>
|
||||
public void ExcuteCompanyCollateral(IEnumerable<int> entryids, OptUserInfo OptUser)
|
||||
{
|
||||
var entrys = db.company_collateral.Where(e => entryids.Contains(e.id) && !ClientCashInCashOut.已确认.Equals(e.OptStatus)).OrderBy(t => t.OptDate).ToList();
|
||||
var clientIds = entrys.Select(t => t.ClientId).Distinct().ToList();
|
||||
|
||||
//当前抵押且执行的抵押品记录(包含抵押执行状态的记录和赎回待执行或者赎回拒绝的记录)
|
||||
var entrysExecutedProduct = db.company_collateral.Where(t => (ClientCashInCashOut.已确认.Equals(t.OptStatus) && company_collateralStatusEnum.抵押.ToString().Equals(t.Status))
|
||||
|| (t.OptStatus != ClientCashInCashOut.已确认 && company_collateralStatusEnum.赎回.ToString().Equals(t.Status))).ToList();
|
||||
//获取客户信息
|
||||
var clientList = DbContextFactory.GetClientDbContext(OptUser).client.Where(t => clientIds.Contains(t.id)).ToList();
|
||||
|
||||
foreach (var e in entrys)
|
||||
{
|
||||
//当前执行的出入金标的即期价格
|
||||
e.SpotPrice = DataCacheProvider.GetUnderlyingDataSource().GetData(e.UnderlyingId ?? 0)?.Price;
|
||||
|
||||
//查看客户是否被冻结需要解冻
|
||||
if (company_collateralStatusEnum.抵押.ToString().Equals(e.Status))
|
||||
{
|
||||
var client = clientList.FirstOrDefault(t => t.id == e.ClientId);
|
||||
//判断是否为冻结状态
|
||||
if (client.PendingMarginCallPayment == 1)
|
||||
{
|
||||
//查看当前客户可用资金是否符合出金条件
|
||||
var clientbalance = ClientBalanceUtility.GetClientBanlances(new List<int> { e.ClientId }, DateTime.MinValue, DateTime.Now.Date).FirstOrDefault();
|
||||
|
||||
//如果入金量大于追保金额则更改冻结状态为正常状态
|
||||
if (!clientbalance.IsMargin(e.SpotPrice * e.ProductAmount * e.Rate ?? 0.0))
|
||||
{
|
||||
client.PendingMarginCallPayment = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
e.ExcuteDate = DateTime.Now;
|
||||
e.ExcuteId = OptUser.UserId;
|
||||
e.ExcuteName = OptUser.UserName;
|
||||
e.OptStatus = ClientCashInCashOut.已确认;
|
||||
e.OptId = OptUser.UserId;
|
||||
e.OptName = OptUser.UserName;
|
||||
e.OptDate = DateTime.Now;
|
||||
db.SaveChanges();
|
||||
|
||||
if (company_collateralStatusEnum.抵押.ToString().Equals(e.Status))
|
||||
{
|
||||
entrysExecutedProduct.Add(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
entrysExecutedProduct.Remove(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user