260 lines
8.6 KiB
C#
260 lines
8.6 KiB
C#
using YLErp.Modules.ExchangeTradeModule;
|
|
|
|
namespace YLErp.Web.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 场内交易
|
|
/// </summary>
|
|
public class ExchangeTradeController : BaseController
|
|
{
|
|
/// <summary>
|
|
/// 场内交易列表
|
|
/// </summary>
|
|
[MyAuthorize("交易管理-标的交易")]
|
|
public ActionResult TradeList(bool IsFirstTime = true)
|
|
{
|
|
if (IsFirstTime)
|
|
{
|
|
return Redirect("positionList");
|
|
}
|
|
return View();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 场内交易持仓记录
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[MyAuthorize("交易管理-标的交易")]
|
|
public ActionResult PositionList()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public ActionResult TradeListSingle(ExchangeTradeReq model)
|
|
{
|
|
model.IsOption = !string.IsNullOrEmpty(model.OptionCode);
|
|
return View(model);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 场内期权交易列表
|
|
/// </summary>
|
|
/// <param name="sourceType">1:期权交易</param>
|
|
/// <param name="sourceType">1:标的交易</param>
|
|
[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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 交易编辑
|
|
/// </summary>
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 场内期权编辑
|
|
/// </summary>
|
|
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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导入场内交易
|
|
/// </summary>
|
|
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,
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 重置对冲交易持仓
|
|
/// </summary>
|
|
public JsonResult AjaxResetTradePosition()
|
|
{
|
|
new ExchangeTradePositionService(CurUser).ResetExchangeTradePosition();
|
|
return JsonSuccess();
|
|
}
|
|
|
|
public ActionResult BatchTradeAdjustView(string Ids)
|
|
{
|
|
ViewBag.TradeIds = Ids;
|
|
return View();
|
|
}
|
|
|
|
public JsonResult BatchTradeAdjust(List<int> 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<List<string>>();
|
|
if (a.AssetBookId != AssetBookId)
|
|
{
|
|
var log = new List<string>{
|
|
"AssetBookName",
|
|
"簿记账户",
|
|
assetBook.GetData(a.AssetBookId)?.Name,
|
|
assetBook.GetData(AssetBookId)?.Name,
|
|
};
|
|
logList.Add(log);
|
|
}
|
|
if (a.IsValid != IsValid)
|
|
{
|
|
var log = new List<string>{
|
|
"IsValid",
|
|
"是否有效",
|
|
a.IsValid ?"有效":"无效",
|
|
IsValid ?"有效":"无效",
|
|
};
|
|
logList.Add(log);
|
|
}
|
|
if (a.OptDate != DateTime.Now)
|
|
{
|
|
var log = new List<string>{
|
|
"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<string>{
|
|
"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();
|
|
}
|
|
}
|
|
}
|