fix: 更改保证金模板名称配置的取值 由admin-> 数据字典
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
<dictionary name="业务部门编号" catalog="客户"></dictionary>
|
||||
<dictionary name="自定义交易要素" catalog="交易"></dictionary>
|
||||
<dictionary name="自定义结构类型" catalog="交易"></dictionary>
|
||||
<dictionary name="保证金模板名称" catalog="交易"></dictionary>
|
||||
<dictionary name="实际控制主体" catalog="客户"></dictionary>
|
||||
<dictionary name="银行信用评级" catalog="客户"></dictionary>
|
||||
<dictionary name="指数类型" catalog="客户"></dictionary>
|
||||
|
||||
@@ -306,17 +306,13 @@ namespace YLErp.Modules.AppModule
|
||||
//-----------------------------------------------
|
||||
configService.AddDataIfNotExists("ProjectConfig", "Erp.IsAutoSealAfterGeneratedBook", "false", "bool", "确认书生成时是否自动用印(IsAutoSealAndUploadFiles勾选时生效)");
|
||||
configService.AddDataIfNotExists("ProjectConfig", "Erp.ReportFileBeginNumber", "0", "int", "报送文件开始编号");
|
||||
//-----------------------------------------------
|
||||
// 删除不再使用的
|
||||
//-----------------------------------------------
|
||||
configService.AddDataIfNotExists("ProjectConfig", YLErp.Modules.SwapModule.SwapMarginTemplateConfigService.ConfigName,
|
||||
YLErp.Modules.SwapModule.SwapMarginTemplateConfigService.DefaultConfigJson, "text", "互换保证金模板(JSON)");
|
||||
|
||||
RemoveUnUsed(configService);
|
||||
}
|
||||
|
||||
private static void RemoveUnUsed(InnerAppConfigService configService)
|
||||
{
|
||||
configService.RemoveData("ProjectConfig", "Trade.SwapMarginTemplateConfig");
|
||||
|
||||
if (AppManager.Version.Major < 3)
|
||||
{
|
||||
configService.RemoveData("ProjectConfig", "Erp.TradeConfirmBookEmailTPL");
|
||||
@@ -456,6 +452,38 @@ namespace YLErp.Modules.AppModule
|
||||
}
|
||||
|
||||
adminDb.SaveChanges();
|
||||
|
||||
var marginTemplateDictionary = adminDb.Dictionaries.FirstOrDefault(item => item.Name == YLErp.Modules.SwapModule.SwapMarginTemplateConfigService.DictionaryName);
|
||||
if (marginTemplateDictionary == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var existingNames = adminDb.DictionaryItems
|
||||
.Where(item => item.DictId == marginTemplateDictionary.Id)
|
||||
.Select(item => item.Name)
|
||||
.ToHashSet();
|
||||
var nextIndex = adminDb.DictionaryItems
|
||||
.Where(item => item.DictId == marginTemplateDictionary.Id)
|
||||
.Select(item => item.IndexNum)
|
||||
.DefaultIfEmpty(-1)
|
||||
.Max();
|
||||
foreach (var templateName in YLErp.Modules.SwapModule.SwapMarginTemplateConfigService.InitialTemplateNames)
|
||||
{
|
||||
if (existingNames.Contains(templateName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
adminDb.DictionaryItems.Add(new BaseOUDAL.DictionaryItem
|
||||
{
|
||||
DictId = marginTemplateDictionary.Id,
|
||||
Name = templateName,
|
||||
ShortName = templateName,
|
||||
IndexNum = ++nextIndex
|
||||
});
|
||||
}
|
||||
adminDb.SaveChanges();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -1,73 +1,32 @@
|
||||
using YLErp.Modules.AppModule;
|
||||
using BaseOUDAL;
|
||||
using YLErp.Models;
|
||||
|
||||
namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
public static class SwapMarginTemplateConfigService
|
||||
{
|
||||
public const string ConfigName = "Trade.SwapMarginTemplateConfig";
|
||||
public const string DictionaryName = "保证金模板名称";
|
||||
|
||||
public const string DefaultConfigJson = @"{
|
||||
""options"": [
|
||||
{ ""text"": ""授信保证金"", ""value"": ""授信保证金"" },
|
||||
{ ""text"": ""现金保证金"", ""value"": ""现金保证金"" }
|
||||
],
|
||||
""defaultValue"": ""现金保证金""
|
||||
}";
|
||||
public static readonly string[] InitialTemplateNames = { "现金保证金", "授信保证金" };
|
||||
|
||||
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<SwapMarginTemplateConfig>(DefaultConfigJson);
|
||||
}
|
||||
|
||||
private static bool TryParse(string json, out SwapMarginTemplateConfig config, out string error)
|
||||
{
|
||||
config = null;
|
||||
error = null;
|
||||
|
||||
try
|
||||
{
|
||||
config = JsonHelper.Deserialize<SwapMarginTemplateConfig>(json);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
error = "保证金模板配置不是有效的 JSON";
|
||||
return false;
|
||||
}
|
||||
|
||||
var items = config?.options?
|
||||
.Where(item => item != null && !string.IsNullOrWhiteSpace(item.Value))
|
||||
using var db = new ErpBaseContext();
|
||||
var dictionaryId = db.Dictionaries
|
||||
.Where(item => item.Name == DictionaryName)
|
||||
.Select(item => item.Id)
|
||||
.FirstOrDefault();
|
||||
var items = db.DictionaryItems
|
||||
.Where(item => item.DictId == dictionaryId && !string.IsNullOrWhiteSpace(item.Name))
|
||||
.OrderBy(item => item.IndexNum)
|
||||
.Select(item => new SelectItem { Text = item.Name, Value = item.Name })
|
||||
.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;
|
||||
return new SwapMarginTemplateConfig
|
||||
{
|
||||
options = items,
|
||||
defaultValue = items.FirstOrDefault()?.Value
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ 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;
|
||||
|
||||
@@ -54,11 +53,6 @@ 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);
|
||||
|
||||
Reference in New Issue
Block a user