diff --git a/YLErpDAL/Modules/AppModule/AppUpgrader.cs b/YLErpDAL/Modules/AppModule/AppUpgrader.cs index 4a35b61f..edf14f79 100644 --- a/YLErpDAL/Modules/AppModule/AppUpgrader.cs +++ b/YLErpDAL/Modules/AppModule/AppUpgrader.cs @@ -309,6 +309,9 @@ namespace YLErp.Modules.AppModule //----------------------------------------------- // 删除不再使用的 //----------------------------------------------- + configService.AddDataIfNotExists("ProjectConfig", YLErp.Modules.SwapModule.SwapMarginTemplateConfigService.ConfigName, + YLErp.Modules.SwapModule.SwapMarginTemplateConfigService.DefaultConfigJson, "text", "互换保证金模板(JSON)"); + RemoveUnUsed(configService); } diff --git a/YLErpDAL/Modules/SwapModule/SwapMarginTemplateConfigService.cs b/YLErpDAL/Modules/SwapModule/SwapMarginTemplateConfigService.cs new file mode 100644 index 00000000..b873dbd1 --- /dev/null +++ b/YLErpDAL/Modules/SwapModule/SwapMarginTemplateConfigService.cs @@ -0,0 +1,80 @@ +using YLErp.Modules.AppModule; +using YLErp.Models; + +namespace YLErp.Modules.SwapModule +{ + public static class SwapMarginTemplateConfigService + { + public const string ConfigName = "Trade.SwapMarginTemplateConfig"; + + public const string DefaultConfigJson = @"{ + ""options"": [ + { ""text"": ""授信保证金"", ""value"": ""授信保证金"" }, + { ""text"": ""现金保证金"", ""value"": ""现金保证金"" } + ], + ""defaultValue"": ""现金保证金"" +}"; + + public static SwapMarginTemplateConfig GetConfig() + { + var json = AppManager.GetAppConfigValue("ProjectConfig", ConfigName); + return TryParse(json, out var config, out _) ? config : GetDefaultConfig(); + } + + public static bool TryValidate(string json, out string error) + { + return TryParse(json, out _, out error); + } + + private static SwapMarginTemplateConfig GetDefaultConfig() + { + return JsonHelper.Deserialize(DefaultConfigJson); + } + + private static bool TryParse(string json, out SwapMarginTemplateConfig config, out string error) + { + config = null; + error = null; + + try + { + config = JsonHelper.Deserialize(json); + } + catch (Exception) + { + error = "保证金模板配置不是有效的 JSON"; + return false; + } + + var items = config?.options? + .Where(item => item != null && !string.IsNullOrWhiteSpace(item.Value)) + .ToArray(); + if (items == null || items.Length == 0) + { + error = "保证金模板配置至少需要一个有效选项"; + return false; + } + if (items.Select(item => item.Value).Distinct(StringComparer.OrdinalIgnoreCase).Count() != items.Length) + { + error = "保证金模板配置的选项值不能重复"; + return false; + } + var defaultValue = config.defaultValue; + if (!items.Any(item => item.Value == defaultValue)) + { + error = "保证金模板默认值必须在选项中"; + return false; + } + + config.options = items; + return true; + } + } + + public class SwapMarginTemplateConfig + { + public IEnumerable options { get; set; } + + public string defaultValue { get; set; } + } +} diff --git a/YLErpWeb/Areas/Admin/Controllers/OtcConfigController.cs b/YLErpWeb/Areas/Admin/Controllers/OtcConfigController.cs index b186e765..cc4f6321 100644 --- a/YLErpWeb/Areas/Admin/Controllers/OtcConfigController.cs +++ b/YLErpWeb/Areas/Admin/Controllers/OtcConfigController.cs @@ -3,6 +3,7 @@ using Org.BouncyCastle.Asn1.Ocsp; using YLErp.Commons; using YLErp.Modules.AppModule; using YLErp.Modules.EodModule.SettlementModule; +using YLErp.Modules.SwapModule; using YLErp.Web.App_Start.AppConfig; using YLErp.Web.Areas.Admin.Models; @@ -53,6 +54,11 @@ namespace YLErp.Web.Areas.Admin.Controllers { value = Uri.UnescapeDataString(value); } + if (name == SwapMarginTemplateConfigService.ConfigName + && !SwapMarginTemplateConfigService.TryValidate(value, out var configError)) + { + return JsonError(configError); + } using (var db = DbContextFactory.GetYLDbContext()) { var data = db.AppConfig.FirstOrDefault(n => n.PGroup == "ProjectConfig" && n.PName == name); @@ -282,4 +288,4 @@ namespace YLErp.Web.Areas.Admin.Controllers #endregion } -} \ No newline at end of file +} diff --git a/YLErpWeb/Controllers/SwapTrade2Controller.cs b/YLErpWeb/Controllers/SwapTrade2Controller.cs index 717ad13f..76a82824 100644 --- a/YLErpWeb/Controllers/SwapTrade2Controller.cs +++ b/YLErpWeb/Controllers/SwapTrade2Controller.cs @@ -52,6 +52,7 @@ namespace YLErp.Web.Controllers trade r = null; if (intid == 0) { + var defaultMarginTemplateName = SwapMarginTemplateConfigService.GetConfig().defaultValue; TradeExtendJson tradeExtendJson = new TradeExtendJson() { FlowBookMode = (int)FlowBookModeEnum.否, @@ -71,7 +72,7 @@ namespace YLErp.Web.Controllers TradeDate = QdpCalendarHelper.GetNonHolidayDefore(valuedateBLL.ValueDate.AddDays(-1), tradeDateCountry), TraderId = CurUser.UserId, TraderName = CurUser.UserName, - MarginTemplateName = "系统默认", + MarginTemplateName = defaultMarginTemplateName, OpponentRole = "乙方", OriginalStockEqvNotional = 0, StructureType = "普通收益互换", @@ -1111,4 +1112,4 @@ namespace YLErp.Web.Controllers } -} \ No newline at end of file +} diff --git a/YLErpWeb/Views/SwapTrade2/TradeEdit.cshtml b/YLErpWeb/Views/SwapTrade2/TradeEdit.cshtml index b8c7d03f..50d78b66 100644 --- a/YLErpWeb/Views/SwapTrade2/TradeEdit.cshtml +++ b/YLErpWeb/Views/SwapTrade2/TradeEdit.cshtml @@ -1,5 +1,6 @@ @using YLErp.Web.Models.JsModels; @using YLErp.Commons; +@using YLErp.Modules.SwapModule; @model trade @{ ViewBag.Title = "交易信息 | 编辑"; @@ -13,6 +14,7 @@ var jsClient = canChangeClient && Model.ClientId > 0 ? jsClients.FirstOrDefault(n => n.id == Model.ClientId) : null; var jsAssetUnits = JsDataModel.GetAssetUnits(CurUser); var tradeMarginTemplates = new tradeController().GetMarginTemplates(); + var swapMarginTemplateItems = SwapMarginTemplateConfigService.GetConfig().options; var tradeMarginTemplateItems = new tradeController().GetMarginTemplateItems(); var jsAssetUnit = Model.AssetId > 0 ? jsAssetUnits.FirstOrDefault(n => n.id == Model.AssetId) : null; var assetunits = JsDataModel.GetAssetUnits(CurUser); @@ -66,6 +68,7 @@ jsTrader, jsTraders, tradeMarginTemplates = tradeMarginTemplates, + swapMarginTemplateItems = swapMarginTemplateItems, tradeMarginTemplateItems = tradeMarginTemplateItems, needRemark = !isAdd && valuedateBLL.SystemDate.EditTradeNeedRemark, parentTradeId = ViewBag.ParentTradeId, @@ -266,6 +269,14 @@ +
+ + +
diff --git a/YLErpWeb/Views/SwapTrade2/TradeView.cshtml b/YLErpWeb/Views/SwapTrade2/TradeView.cshtml index 310b7897..5b2e1e92 100644 --- a/YLErpWeb/Views/SwapTrade2/TradeView.cshtml +++ b/YLErpWeb/Views/SwapTrade2/TradeView.cshtml @@ -236,6 +236,10 @@ 派息金额支付日 @(trade.trade_extend.ExtendObj.DividendPayDate == 0 ? "到期结算日" : "派息日+" + (trade.trade_extend.ExtendObj.DividendPayDate - 1)) + + 保证金模板 + @trade.MarginTemplateName +