141 lines
4.6 KiB
C#
141 lines
4.6 KiB
C#
using YLErp.BLL;
|
|
using YLErp.Model.Enum;
|
|
|
|
namespace YLErp.Modules.TradeModule.DealModule
|
|
{
|
|
/// <summary>
|
|
/// 交易拒绝服务
|
|
/// </summary>
|
|
public class TradeRejectService : TradeServiceBase
|
|
{
|
|
public TradeRejectService(YLBaseService baseService) : base(baseService)
|
|
{
|
|
}
|
|
|
|
public TradeRejectService(OptUserInfo userInfo) : base(userInfo)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// from tradecontroller.TradeReject
|
|
/// </summary>
|
|
public void OtcOptionTradeReject(trade req, int tradeId)
|
|
{
|
|
if (req is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(req));
|
|
}
|
|
|
|
var trade = DbContext.trade.Find(tradeId);
|
|
if (trade == null)
|
|
{
|
|
throw new ServiceException("系统中没有此交易");
|
|
}
|
|
trade.MetaDic = DbContext.TradeMeta.Where(a => a.TradeId == req.id).ToDictionary(a => a.MetaKey, a => a.MetaValue);
|
|
if (trade.TradeStatus != ConsTrade.审批中 && trade.TradeStatus != ConsTrade.行权待复核 && trade.TradeStatus != ConsTrade.平仓待复核 && trade.TradeStatus != ConsTrade.互换待复核)
|
|
{
|
|
throw new ServiceException("该交易状态已变更,不能被拒绝,请先刷新页面");
|
|
}
|
|
|
|
|
|
tradeBLL.SetFieldsByTradeType(trade);
|
|
|
|
|
|
//if (req.TradeOpenVolatility.HasValue && req.TradeOpenVolatility.Value < 0)
|
|
//{
|
|
// throw new ServiceException("成交波动率不能小于0");
|
|
//}
|
|
|
|
//if (req.TradeCloseVolatility.HasValue && req.TradeCloseVolatility.Value < 0)
|
|
//{
|
|
// throw new ServiceException("目标波动率不能小于0");
|
|
//}
|
|
|
|
if (!req.PremiumPayDate.HasValue)
|
|
{
|
|
req.PremiumPayDate = req.TradeDate;
|
|
}
|
|
//else if (req.PremiumPayDate < req.TradeDate && req.PremiumPayDate > req.ExerciseDate)
|
|
//{
|
|
// throw new ServiceException("权利金应付日必须介于交易日与到期日之间!");
|
|
//}
|
|
|
|
//if (req.NumOfSmoothingDays.HasValue)
|
|
//{
|
|
// if (req.NumOfSmoothingDays.Value < 0)
|
|
// {
|
|
// throw new ServiceException("平滑过渡天数不能小于0");
|
|
// }
|
|
//}
|
|
|
|
//if (req.TradeType == "价差期权")
|
|
//{
|
|
// var errMsg = SpreadOptionValidator.Validate(req);
|
|
// if (!string.IsNullOrEmpty(errMsg))
|
|
// {
|
|
// throw new ServiceException(errMsg);
|
|
// }
|
|
//}
|
|
if (trade != null)
|
|
{
|
|
trade.ProcessOrderId = Convert.ToInt32(PStatusEnum.reject);
|
|
trade.TradeStatus = ConsTrade.已拒绝;
|
|
trade.ProcessOptDate = DateTime.Now;
|
|
trade.ProcessStatus = "已拒绝";
|
|
trade.CheckStatus = 0;
|
|
}
|
|
|
|
var diffList = TradeCheckUtil.GetDiffs(trade, req);
|
|
|
|
if (diffList?.Count > 0)
|
|
{
|
|
TradeCheckUtil.SaveTradeCheck(trade, req, UserId, UserName);
|
|
}
|
|
|
|
AddTradeOperationHistoryAndSetParentTradeInfo(false, trade, "交易复核拒绝成功");
|
|
|
|
DbContext.SaveChanges();
|
|
}
|
|
|
|
/// <summary>
|
|
/// from forwardtradecontroller.TradeReject
|
|
/// </summary>
|
|
public void ForwardTradeReject(trade req, int tradeId)
|
|
{
|
|
if (req is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(req));
|
|
}
|
|
|
|
var trade = DbContext.trade.Find(tradeId);
|
|
|
|
if (trade == null)
|
|
{
|
|
throw new ServiceException("系统中没有此交易");
|
|
}
|
|
|
|
tradeBLL.SetFieldsByTradeType(trade);
|
|
|
|
if (trade != null)
|
|
{
|
|
trade.ProcessOrderId = Convert.ToInt32(PStatusEnum.reject);
|
|
trade.TradeStatus = ConsTrade.已拒绝;
|
|
trade.ProcessOptDate = DateTime.Now;
|
|
trade.ProcessStatus = "已拒绝";
|
|
trade.CheckStatus = 0;
|
|
}
|
|
|
|
var diffList = TradeCheckUtil.GetDiffs(trade, req);
|
|
|
|
if (diffList?.Count > 0)
|
|
{
|
|
TradeCheckUtil.SaveTradeCheck(trade, req, UserId, UserName);
|
|
}
|
|
|
|
AddTradeOperationHistoryAndSetParentTradeInfo(false, trade, "交易复核拒绝成功");
|
|
|
|
DbContext.SaveChanges();
|
|
}
|
|
}
|
|
}
|