Files
zszq-trs/YLErpWeb/Controllers/SyntheticUnderlyingController.cs
2024-05-09 14:06:26 +08:00

162 lines
5.1 KiB
C#

using System.Security.Policy;
using System.Text;
using System.Text.Encodings.Web;
using System.Web;
using YieldChain.Helpers;
using YLErp.Modules.UnderlyingModule;
namespace YLErp.Web.Controllers
{
public class SyntheticUnderlyingController : BaseController
{
public JsonResult GetAllValidSyntheticUnderlyings()
{
var list = new UnderlyingDalService(CurUser).GetAllValidSyntheticUnderlyings();
return JsonSuccess("", list);
}
public JsonResult GetSyntheticUnderlyingByName(string name)
{
if (name.IsNullOrWhiteSpace())
{
return JsonError("请传入别名");
}
var su = new UnderlyingDalService(CurUser).GetSyntheticUnderlyingByName(name);
if (su == null)
{
return JsonError("没有相关组合标的");
}
var codes = su.GetUnderlyingCodes().ToArray();
var codeDict = underlying_managerBLL.GetQuery()
.Where(u => codes.Contains(u.UnderlyingCode)).ToDictionary(K => K.UnderlyingCode, V => V);
var arr = new underlying_manager[codes.Length];
for (var i = 0; i < codes.Length; i++)
{
arr[i] = codeDict[codes[i]];
}
su.UnderlyingList = arr;
if (!su.ContractSize.HasValue)
{
su.ContractSize = 1;
}
return JsonSuccess("", su);
}
/// <summary>
///
/// </summary>
public JsonResult SaveSyntheticUnderlying(SyntheticUnderlyingDto req)
{
if (req == null)
{
return JsonError("保存的对象不能为空");
}
req.OptId = CurUser.UserId;
req.OptName = CurUser.UserName;
req.OptDate = DateTime.Now;
new UnderlyingDalService(CurUser).SaveSyntheticUnderlying(req, out var dbModel);
return JsonSuccess("保存成功", dbModel);
}
/// <summary>
///
/// </summary>
public ActionResult SyntheticUnderlyingEdit(string syntheticUnderlyingName)
{
SyntheticUnderlyingDto su = null;
if (!string.IsNullOrWhiteSpace(syntheticUnderlyingName))
{
su = GetSyntheticUnderlying(syntheticUnderlyingName, out var canEdit);
if (su == null)
{
return Content("没有找到组合标的数据");
}
if (!canEdit)
{
return ShowError("系统存在使用此组合标的的交易,不能修改");
}
}
return View(su ?? new SyntheticUnderlyingDto());
}
private SyntheticUnderlyingDto GetSyntheticUnderlying(string syntheticUnderlyingName, out bool canEdit)
{
canEdit = false;
var su = new UnderlyingDalService(CurUser).GetSyntheticUnderlyingByName(syntheticUnderlyingName);
if (su != null)
{
su.UnderlyingList = su.GetUnderlyingCodes()
.Select(n => DataCacheProvider.GetUnderlyingDataSource().GetData(n)).ToArray();
if (!su.ContractSize.HasValue)
{
su.ContractSize = 1;
}
canEdit = !yldb.trade.Any(trade => trade.UnderlyingCode == syntheticUnderlyingName && trade.ValidState != ConsGlobal.InValid);
}
return su;
}
/// <summary>
///
/// </summary>
public ActionResult SyntheticUnderlyingView(string syntheticUnderlyingName)
{
if (string.IsNullOrWhiteSpace(syntheticUnderlyingName))
{
return Content("缺少参数:合成标的代码");
}
var su = GetSyntheticUnderlying(syntheticUnderlyingName, out var canEdit);
if (su == null)
{
return Content("没有找到组合标的数据");
}
if (canEdit)
{
ViewData["canEdit"] = "true";
}
ViewBag.syntheticUnderlyingName = System.Web.HttpUtility.UrlEncode(syntheticUnderlyingName,Encoding.UTF8);
return View(su);
}
/// <summary>
///
/// </summary>
public JsonResult SyntheticUnderlyingViewSave(underlying_managerSimpleReq req)
{
//需解码
if (!string.IsNullOrEmpty(req.UnderlyingCode))
{
req.UnderlyingCode = HttpUtility.HtmlDecode(req.UnderlyingCode);
}
new UnderlyingDalService(CurUser).UpdateData(req.UnderlyingCode, req.MarginRate, req.VolatilityRate, req.UpDownLimit);
return JsonSuccess("修改成功!");
}
/// <summary>
///
/// </summary>
public JsonResult SyntheticUnderlyingViewRemove(string syntheticUnderlyingName)
{
new UnderlyingDalService(CurUser).RemoveSyntheticUnderlyingByName(syntheticUnderlyingName);
return JsonSuccess("删除成功!");
}
}
}