using YLErp.Cache; using YLErp.Modules.ExchangeTradeModule; using YLErp.Modules.SystemModule; namespace YLErp.Web.Controllers { /// /// 场内交易 /// public class ExchangeTradeController : BaseController { private IYLCache _yLCache; public ExchangeTradeController(IYLCache yLCache) { _yLCache = yLCache; } /// /// 场内交易列表 /// [MyAuthorize("交易管理-标的交易")] public ActionResult TradeList(bool IsFirstTime = true) { if (IsFirstTime) { return Redirect("positionList"); } return View(); } /// /// 场内交易持仓记录 /// /// [MyAuthorize("交易管理-标的交易")] public ActionResult PositionList() { return View(); } public ActionResult TradeListSingle(ExchangeTradeReq model) { model.IsOption = !string.IsNullOrEmpty(model.OptionCode); return View(model); } /// /// 场内期权交易列表 /// /// 1:期权交易 /// 1:标的交易 [MyAuthorize("交易管理-标的交易")] public ActionResult OptionTradeList(int sourceType = 1) { ViewBag.sourceType = sourceType; return View(); } public ActionResult AjaxGetTradeList(ExchangeTradeReq model) { model.PageIndex = model.page; model.PageSize = model.rows; model.AssetBookIds = AssetUnitModel.IntersectAssetUnits(model.AssetIdGroupList, model.AssetBookIds).ToList(); model.UserAssets = GetUserAssetunitIds(); var pagedList = new ExchangeTradeQueryService(CurUser).GetPagedList(model); return JsonForJqGrid(pagedList); } public ActionResult AjaxGetPositionList(ExchangeTradeReq model) { model.PageIndex = model.page; model.PageSize = model.rows; model.AssetBookIds = AssetUnitModel.IntersectAssetUnits(model.AssetIdGroupList, model.AssetBookIds).ToList(); model.UserAssets = GetUserAssetunitIds(); var pagedList = new ExchangeTradeQueryService(CurUser).GetPagedPositionList(model); return JsonForJqGrid(pagedList); } public ActionResult TradeView(string enid) { var intid = DecryptInt(enid); var detail = new ExchangeTradeQueryService(CurUser).GetDetail(intid); return View(detail); } /// /// 交易编辑 /// public ActionResult TradeEdit(string enid, bool isOption = false) { ExchangeTrade td = null; var isAdd = string.IsNullOrEmpty(enid) || enid == "0"; if (isAdd) { if (!CurUser.交易管理_交易新增) { return ShowError("没有新增权限"); } td = new ExchangeTrade { TradeType = "信用债", InstrumentType = ConsGlobal.InstrumentType.CreditBonds, TradeDate = valuedateBLL.ValueDate, TraderId = UserId, TraderName = UserName, TradeSide = "多头开仓", CommissionType = DBModels.Enums.CommissionType.系统计算 }; } else if (!CurUser.交易管理_交易编辑) { return ShowError("没有编辑权限"); } else { var intid = DecryptInt(enid); td = yldb.ExchangeTrade.Find(intid); if (td == null) { return ShowError("数据不存在"); } } return View("TradeEdit", td); } /// /// 场内期权编辑 /// public ActionResult OptionTradeEdit(string enid) { return TradeEdit(enid, true); } public JsonResult AjaxSaveTradeEdit(ExchangeTrade model) { model.TradeAmount *= 100;//张数 model.TradeSinglePrice /= 100;// 价格除100 var td = new ExchangeTradeSaveService(CurUser).Save(model, Model.Enum.TradeSourceEnum.系统交易); return JsonSuccessData(td); } public JsonResult InValidTrade(string enid) { var intid = DecryptInt(enid); new ExchangeTradeSaveService(CurUser).InValidTrade(intid); return JsonSuccess(); } [MyAuthorize("交易管理-交易导入")] public ActionResult tradeUpload() { return View(); } /// /// 导入场内交易 /// public ActionResult UploadTrade() { if (Request.Form.Files.Count == 0) { return JsonError("上传文件不存在"); } var file = Request.Form.Files[0]; if (!Path.GetExtension(file.FileName).Equals(".xlsx", StringComparison.OrdinalIgnoreCase)) { return JsonError("请上传Excel(.xlsx)格式文件"); } using var stream = file.OpenReadStream(); new ExchangeTradeImportService(CurUser).ImportExcel(stream, out var TotalNum, out var SuccessNum); return Json(new { success = true, totalNum = TotalNum, successNum = SuccessNum, }); } /// /// 重置对冲交易持仓 /// public JsonResult AjaxResetTradePosition() { new ExchangeTradePositionService(CurUser).ResetExchangeTradePosition(); return JsonSuccess(); } public ActionResult BatchTradeAdjustView(string Ids) { ViewBag.TradeIds = Ids; return View(); } public JsonResult BatchTradeAdjust(List tradeIds, int AssetBookId, bool IsValid) { var exchangeTrades = yldb.ExchangeTrade.Where(a => tradeIds.Contains(a.id)); var assetBook = DataCacheProvider.GetAssetUnitDataSource(); var db = new YLContext(); if (exchangeTrades.Any()) { exchangeTrades.ToList().ForEach(a => { var logList = new List>(); if (a.AssetBookId != AssetBookId) { var log = new List{ "AssetBookName", "簿记账户", assetBook.GetData(a.AssetBookId)?.Name, assetBook.GetData(AssetBookId)?.Name, }; logList.Add(log); } if (a.IsValid != IsValid) { var log = new List{ "IsValid", "是否有效", a.IsValid ?"有效":"无效", IsValid ?"有效":"无效", }; logList.Add(log); } if (a.OptDate != DateTime.Now) { var log = new List{ "OptDate", "操作时间", a.OptDate?.ToString("yyyy-MM-dd HH:mm:ss"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), }; logList.Add(log); } if (a.OptName != CurUser.UserName) { var log = new List{ "OptName", "操作人", a.OptName, CurUser.UserName, }; logList.Add(log); } a.AssetBookId = IsValid ? AssetBookId : (AssetBookId == 0 ? a.AssetBookId : AssetBookId); a.IsValid = IsValid; a.OptDate = DateTime.Now; a.OptId = CurUser.UserId; a.OptName = CurUser.UserName; new ExchangeTradeSaveService(CurUser).Save(a, Model.Enum.TradeSourceEnum.系统交易); }); db.SaveChanges(); } return JsonSuccess(); } /// /// 偏移设置 /// /// [MyAuthorize("交易管理-偏移设置")] public ActionResult SpreadSetting() { var result = new XBondSpread() { bid = 0, ofr = 0 }; try { result = new XBondSpreadService().GetXBondSpread(_yLCache) ?? new XBondSpread() { bid = 0, ofr = 0 }; } catch(Exception) { } return View(result); } public JsonResult AjaxSaveSpreadSetting(XBondSpread data) { try { new XBondSpreadService().SetXBondSpread(data, _yLCache); return JsonSuccess(); } catch(Exception ex) { return JsonError(ex.Message); } } } }