633 lines
22 KiB
C#
633 lines
22 KiB
C#
using YieldChain.Commons;
|
|
using YLErp.BLL;
|
|
using YLErp.Models;
|
|
using YLErp.Modules.AppModule;
|
|
|
|
namespace YLErp.Modules.SystemModule
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public static class ClientEditConfigService
|
|
{
|
|
static DateTime _optDate;
|
|
static ClientEditConfig _config;
|
|
static readonly ValueWrap<DateTime> _updateTime;
|
|
|
|
static ClientEditConfigService()
|
|
{
|
|
_updateTime = new ValueWrap<DateTime>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 重置配置
|
|
/// </summary>
|
|
public static void ResetConfig()
|
|
{
|
|
lock (_updateTime)
|
|
{
|
|
_config = null;
|
|
_updateTime.Value = _optDate = DateTime.MinValue;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取配置json
|
|
/// </summary>
|
|
public static string GetConfigJson()
|
|
{
|
|
using (var db = DbContextFactory.GetYLDbContext())
|
|
{
|
|
var query = db.AppConfig.Where(n => n.PGroup == "System" && n.PName == "ClientEditConfig");
|
|
var configJson = query.Select(n => n.PValue).FirstOrDefault();
|
|
return configJson.TrimToNull() ?? Properties.Resources.clientEditConfig;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public static ClientEditConfig GetConfig(bool forceUpdateSelects = false, bool isView = false)
|
|
{
|
|
string configJson = null;
|
|
|
|
if (_config == null || _updateTime.Value.AddSeconds(60) < DateTime.Now)
|
|
{
|
|
lock (_updateTime)
|
|
{
|
|
if (_config == null || _updateTime.Value.AddSeconds(60) < DateTime.Now)
|
|
{
|
|
using (var db = DbContextFactory.GetYLDbContext())
|
|
{
|
|
var query = db.AppConfig.Where(n => n.PGroup == "System" && n.PName == "ClientEditConfig");
|
|
|
|
if (_config == null || query.Select(n => (DateTime?)n.OptDate).FirstOrDefault() != _optDate)
|
|
{
|
|
var data = query.Select(n => new { n.PValue, n.OptDate }).FirstOrDefault();
|
|
|
|
if (data != null)
|
|
{
|
|
_optDate = data.OptDate;
|
|
configJson = data.PValue;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(configJson))
|
|
{
|
|
_config = null;
|
|
configJson = Properties.Resources.clientEditConfig;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (configJson != null)
|
|
{
|
|
var index = configJson.IndexOf('=');
|
|
if (index > 0)
|
|
{
|
|
configJson = configJson.Substring(index + 1);
|
|
}
|
|
|
|
_updateTime.Value = DateTime.MinValue;
|
|
|
|
_config = JsonHelper.Deserialize<ClientEditConfig>(configJson) ?? new ClientEditConfig();
|
|
//开户管理和客户列表列去重;
|
|
_config.openList = _config.openList.DistinctBy(O => O.name);
|
|
_config.clientList = _config.clientList.DistinctBy(O => O.name);
|
|
}
|
|
else if (_config == null)
|
|
{
|
|
throw new SystemException("系统错误");
|
|
}
|
|
else if (!forceUpdateSelects)
|
|
{
|
|
return _config.Clone();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//防止服务器时间更改所以需要双重验证(比如服务器时间由15点改为12点)
|
|
if (forceUpdateSelects || _updateTime.Value > DateTime.Now || _updateTime.Value.AddMinutes(1) < DateTime.Now)
|
|
{
|
|
lock (_updateTime)
|
|
{
|
|
if (forceUpdateSelects || _updateTime.Value > DateTime.Now || _updateTime.Value.AddMinutes(1) < DateTime.Now)
|
|
{
|
|
var allFields = _config.sections.SelectMany(n => n.fields ?? Enumerable.Empty<FormEditField>()).ToArray();
|
|
foreach (var f in allFields)
|
|
{
|
|
if (f.name != null && f.name.StartsWith("meta.", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
f.name = "meta_" + f.name.Substring(5);
|
|
}
|
|
}
|
|
var fieldNames = allFields.Select(m => m.name ?? string.Empty).ToHashSet();
|
|
|
|
//客户等级
|
|
_config.selects[nameof(Client.LevelId)] = ClientDataModelV1.GetAllclientlevel();
|
|
|
|
//客户等级
|
|
_config.selects[nameof(Client.SettlementCurrency)] = ClientDataModelV1.GetAllCurrency();
|
|
|
|
//客服经理
|
|
if (fieldNames.Contains(nameof(Client.CustomerManagerId)))
|
|
{
|
|
_config.selects[nameof(Client.CustomerManagerId)] = ClientDataModelV1.GetAllCustomerManager();
|
|
}
|
|
|
|
//销售
|
|
if (fieldNames.Contains(nameof(Client.Seller)))
|
|
{
|
|
_config.selects[nameof(Client.Seller)] = SalesDataModelV1.GetSalesmen();
|
|
}
|
|
|
|
//所属机构
|
|
if (fieldNames.Contains(nameof(Client.ParentId)))
|
|
{
|
|
_config.selects[nameof(Client.ParentId)] = ClientDataModelV1.GetAllOpenaccountClient(null);
|
|
}
|
|
|
|
//归属营业部
|
|
if (fieldNames.Contains(nameof(Client.SalesDepartmentId)))
|
|
{
|
|
_config.selects[nameof(Client.SalesDepartmentId)] = SalesDataModelV1.GetAllSaleDepartment();
|
|
}
|
|
|
|
//交易种类
|
|
if (!_config.selects.ContainsKey(nameof(Client.DerivativesInvestmentVarieties)))
|
|
{
|
|
_config.selects[nameof(Client.DerivativesInvestmentVarieties)] = ClientDataModelV1.GetAllDerivativesInvestmentVarieties();
|
|
}
|
|
|
|
//不良诚信记录
|
|
if (!_config.selects.ContainsKey(nameof(Client.BadFaithRecord)))
|
|
{
|
|
_config.selects[nameof(Client.BadFaithRecord)] = ClientDataModelV1.GetAllBadFaithRecord();
|
|
}
|
|
|
|
//可接受风险服务
|
|
_config.selects[nameof(Client.RiskServiceDegree)] = ClientDataModelV1.GetRiskServiceDegree();
|
|
|
|
//适当性评估人
|
|
_config.selects[nameof(Client.AppropriatenessAssessor)] = ClientDataModelV1.GetAppropriatenessAssessor(!isView);
|
|
|
|
//适当性评级-默认值,如果配置了其他项,这里的设置会被覆盖掉
|
|
_config.selects[nameof(Client.AppropriatenessDegree)] = ClientDataModelV1.GetAppropriatenessList();
|
|
|
|
var dicInfos =
|
|
_config.sections
|
|
.Where(n => n.fields != null)
|
|
.SelectMany(n =>
|
|
n.fields.Where(m => m.dictionaryKey != null && m.dictionaryKey != "")
|
|
.Select(m => new KeyValuePair<string, string>(m.name, m.dictionaryKey ?? string.Empty)))
|
|
.Concat(new[] {
|
|
new KeyValuePair<string, string>("文件类型", "文件类型"),
|
|
new KeyValuePair<string, string>("权益类签署版本", "权益类签署版本"),
|
|
new KeyValuePair<string, string>("资金用途", "资金用途"),
|
|
}).ToArray();
|
|
|
|
var yldic = DictionaryBLL.GetDictionary(dicInfos.Select(O => O.Value).ToArray());
|
|
|
|
foreach (var item in dicInfos)
|
|
{
|
|
if (item.Key == nameof(Client.AppropriatenessDegree)) { continue; }
|
|
_config.selects[item.Key] = yldic.GetList(item.Value, false);
|
|
//行业字段比较特殊,KeyValue需要保持一致;
|
|
if (item.Key == nameof(Client.BusinessType) || item.Key == nameof(Client.ProtocolSignVersion))
|
|
{
|
|
_config.selects[item.Key].ToList().ForEach(O =>
|
|
{
|
|
O.Value = O.Text;
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
_updateTime.Value = DateTime.Now;
|
|
}
|
|
}
|
|
}
|
|
|
|
return _config.Clone();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取当前配置的所有表单字段
|
|
/// </summary>
|
|
public static IEnumerable<FormEditField> GetAllFormEditField()
|
|
{
|
|
var config = GetConfig(false);
|
|
return config.sections.SelectMany(n => n.fields ?? Enumerable.Empty<FormEditField>());
|
|
}
|
|
|
|
public static IEnumerable<FormEditField> GetAllFormEditFieldByTableId(string tableid)
|
|
{
|
|
var config = GetConfig(false);
|
|
return config.sections.Where(l => l.tabId == tableid).SelectMany(n => n.fields ?? Enumerable.Empty<FormEditField>());
|
|
}
|
|
|
|
public static string GetSelectValue(string name, string text)
|
|
{
|
|
var config = GetConfig(true);
|
|
var selectItem = _config.selects.Where(a => a.Key == name).FirstOrDefault();
|
|
var item = selectItem.Value.Where(a => a.Text == text).FirstOrDefault();
|
|
return item != null ? item.Value : string.Empty;
|
|
}
|
|
|
|
public static FormEditField GetFormEditFieldByName(string name)
|
|
{
|
|
var FormEditFields = GetAllFormEditField();
|
|
if (FormEditFields != null)
|
|
{
|
|
return FormEditFields.Where(a => a.name == name).FirstOrDefault();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static FormEditField GetFormEditFieldByLabel(string label)
|
|
{
|
|
var config = GetConfig(true);
|
|
var FormEditFields = GetAllFormEditField();
|
|
if (FormEditFields != null)
|
|
{
|
|
return FormEditFields.Where(a => a.label == label).FirstOrDefault();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static FormEditField GetFormEditFieldByLabel(IEnumerable<FormEditField> FormEditFields,string label)
|
|
{
|
|
if (FormEditFields != null)
|
|
{
|
|
return FormEditFields.Where(a => a.label == label).FirstOrDefault();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转换成横向流布局的字段列表
|
|
/// </summary>
|
|
public static IEnumerable<FormEditField> GetFlatList(IEnumerable<FormEditField> fields, out int cols)
|
|
{
|
|
cols = 0;
|
|
|
|
if (fields is null)
|
|
{
|
|
return Enumerable.Empty<FormEditField>();
|
|
}
|
|
|
|
var colIndex = 0;
|
|
var list = new List<FormEditField>();
|
|
var listList = new List<List<FormEditField>> { list };
|
|
|
|
foreach (var f in fields)
|
|
{
|
|
if (f.type == "new-col")
|
|
{
|
|
if (list.Count > 0)
|
|
{
|
|
colIndex++;
|
|
if (colIndex >= listList.Count)
|
|
{
|
|
listList.Add(list = new List<FormEditField>());
|
|
}
|
|
}
|
|
}
|
|
else if (f.type == "new-row")
|
|
{
|
|
colIndex = 0;
|
|
JustifyListList(listList);
|
|
list = listList[0];
|
|
}
|
|
else if (f.visible)
|
|
{
|
|
if (f.layout == "row")
|
|
{
|
|
JustifyListList(listList);
|
|
listList.ForEach(x => x.Add(f));
|
|
}
|
|
else
|
|
{
|
|
list.Add(f);
|
|
}
|
|
}
|
|
}
|
|
|
|
var len = JustifyListList(listList);
|
|
|
|
var results = new List<FormEditField>(fields.Count());
|
|
|
|
for (var i = 0; i < len; i++)
|
|
{
|
|
results.AddRange(listList.Select(n => n[i]));
|
|
}
|
|
|
|
cols = listList.Count;
|
|
|
|
return results;
|
|
}
|
|
|
|
private static int JustifyListList(List<List<FormEditField>> listList)
|
|
{
|
|
if (listList.Count > 0)
|
|
{
|
|
var maxCount = listList.Max(n => n.Count);
|
|
foreach (var list in listList)
|
|
{
|
|
if (list.Count < maxCount)
|
|
{
|
|
list.AddRange(new FormEditField[maxCount - list.Count]);
|
|
}
|
|
}
|
|
return maxCount;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取默认配置内容
|
|
/// </summary>
|
|
public static string GetDefaultConfigJson()
|
|
{
|
|
return Properties.Resources.clientEditConfig;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取当前配置内容
|
|
/// </summary>
|
|
public static string GetCurrentConfigJson()
|
|
{
|
|
using (var db = DbContextFactory.GetYLDbContext())
|
|
{
|
|
return db.AppConfig.Where(n => n.PGroup == "System" && n.PName == "ClientEditConfig")
|
|
.Select(n => n.PValue).FirstOrDefault().TrimToNull() ?? Properties.Resources.clientEditConfig;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存配置
|
|
/// </summary>
|
|
public static void SaveEditConfig(string config)
|
|
{
|
|
var arr = config.Split('=');
|
|
if (arr.Length == 2)
|
|
{
|
|
var obj = JsonHelper.Deserialize<ClientEditConfig>(arr[1]);
|
|
if (obj?.clientList?.Any() ?? false)
|
|
{
|
|
var nameList = obj.clientList.GroupBy(O => O.name).Where(O => O.ToArray().Length > 1).Select(O => O.Key);
|
|
if (nameList.Any())
|
|
{
|
|
throw new ServiceException("客户列表中出现列name信息重复,name为" + string.Join(",", nameList));
|
|
}
|
|
}
|
|
if (obj?.openList?.Any() ?? false)
|
|
{
|
|
var nameList = obj.openList.GroupBy(O => O.name).Where(O => O.ToArray().Length > 1).Select(O => O.Key);
|
|
if (nameList.Any())
|
|
{
|
|
throw new ServiceException("开户列表中出现列name信息重复,name为" + string.Join(",", nameList));
|
|
}
|
|
}
|
|
}
|
|
|
|
new AppConfigService(OptUserInfo.SystemUser).SaveConfig("System", "ClientEditConfig", config, "string", "");
|
|
|
|
ResetConfig();
|
|
}
|
|
|
|
public static List<ClientField> GetOpenList()
|
|
{
|
|
var config = GetConfig();
|
|
return config.openList.ToList();
|
|
}
|
|
|
|
public static List<ClientField> GetClientList()
|
|
{
|
|
var config = GetConfig();
|
|
return config.clientList.ToList();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 客户编辑配置
|
|
/// </summary>
|
|
public class ClientEditConfig
|
|
{
|
|
private IEnumerable<FormEditSection> _sections;
|
|
private Dictionary<string, IEnumerable<SelectItem>> _selectItems;
|
|
private Dictionary<string, string> _defaults;
|
|
private Dictionary<string, IEnumerable<object>> _listDatas;
|
|
private IEnumerable<ClientField> _openList;
|
|
private IEnumerable<ClientField> _clientList;
|
|
|
|
/// <summary>
|
|
/// 页面编辑数据组
|
|
/// </summary>
|
|
public IEnumerable<FormEditSection> sections
|
|
{
|
|
get => _sections ?? (_sections = Enumerable.Empty<FormEditSection>());
|
|
set => _sections = value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 页面编辑下拉选择数据
|
|
/// </summary>
|
|
public Dictionary<string, IEnumerable<SelectItem>> selects
|
|
{
|
|
get => _selectItems ?? (_selectItems = new Dictionary<string, IEnumerable<SelectItem>>());
|
|
set => _selectItems = value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 页面编辑数据默认值
|
|
/// </summary>
|
|
public Dictionary<string, string> defaults
|
|
{
|
|
get => _defaults ?? (_defaults = new Dictionary<string, string>());
|
|
set => _defaults = value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 页面编辑列表数据
|
|
/// </summary>
|
|
public Dictionary<string, IEnumerable<object>> lists
|
|
{
|
|
get => _listDatas ?? (_listDatas = new Dictionary<string, IEnumerable<object>>());
|
|
set => _listDatas = value;
|
|
}
|
|
/// <summary>
|
|
/// 开户编辑列表数据
|
|
/// </summary>
|
|
public IEnumerable<ClientField> openList
|
|
{
|
|
get => _openList ?? (_openList = Enumerable.Empty<ClientField>());
|
|
set => _openList = value;
|
|
}
|
|
/// <summary>
|
|
/// 客户编辑列表数据
|
|
/// </summary>
|
|
public IEnumerable<ClientField> clientList
|
|
{
|
|
get => _clientList ?? (_clientList = Enumerable.Empty<ClientField>());
|
|
set => _clientList = value;
|
|
}
|
|
|
|
public ClientEditConfig Clone()
|
|
{
|
|
var clone = (ClientEditConfig)MemberwiseClone();
|
|
|
|
clone.lists = null;
|
|
|
|
if (clone.sections != null)
|
|
{
|
|
clone.sections = clone.sections.Select(n => n.Clone()).ToArray();
|
|
}
|
|
|
|
if (clone.defaults != null)
|
|
{
|
|
clone.defaults = new Dictionary<string, string>(clone.defaults);
|
|
}
|
|
|
|
return clone;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 编辑组
|
|
/// </summary>
|
|
public class FormEditSection
|
|
{
|
|
/// <summary>
|
|
/// 是否可见
|
|
/// </summary>
|
|
public bool visible { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// tab ID
|
|
/// </summary>
|
|
public string tabId { get; set; }
|
|
|
|
/// <summary>
|
|
/// tab标题
|
|
/// </summary>
|
|
public string title { get; set; }
|
|
|
|
/// <summary>
|
|
/// 表单样式类
|
|
/// </summary>
|
|
public string className { get; set; }
|
|
|
|
/// <summary>
|
|
/// 视图路径(这个值存在时fields失效)
|
|
/// </summary>
|
|
public string viewPath { get; set; }
|
|
|
|
/// <summary>
|
|
/// 表单输入字段
|
|
/// </summary>
|
|
public IEnumerable<FormEditField> fields { get; set; }
|
|
|
|
public FormEditSection Clone()
|
|
{
|
|
var clone = (FormEditSection)MemberwiseClone();
|
|
|
|
if (clone.fields != null)
|
|
{
|
|
clone.fields = clone.fields.Select(n => n.Clone()).ToArray();
|
|
}
|
|
else
|
|
{
|
|
clone.fields = Enumerable.Empty<FormEditField>();
|
|
}
|
|
|
|
return clone;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 表单字段
|
|
/// </summary>
|
|
public class FormEditField
|
|
{
|
|
/// <summary>
|
|
/// 是否可见
|
|
/// </summary>
|
|
public bool visible { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// 字段名
|
|
/// </summary>
|
|
public string name { get; set; }
|
|
|
|
/// <summary>
|
|
/// 字段说明
|
|
/// </summary>
|
|
public string label { get; set; }
|
|
|
|
/// <summary>
|
|
/// 字段类型(特殊:none,new-col,new-row)
|
|
/// </summary>
|
|
public string type { get; set; }
|
|
|
|
/// <summary>
|
|
/// 字段样式类
|
|
/// </summary>
|
|
public string className { get; set; }
|
|
|
|
/// <summary>
|
|
/// 是否必需
|
|
/// </summary>
|
|
public bool required { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// 是否只读
|
|
/// </summary>
|
|
public bool @readonly { get; set; }
|
|
|
|
/// <summary>
|
|
/// 当type等于select时是否增加空选项
|
|
/// </summary>
|
|
public bool appendBlank { get; set; }
|
|
|
|
/// <summary>
|
|
/// placeholder
|
|
/// </summary>
|
|
public string placeholder { get; set; }
|
|
|
|
/// <summary>
|
|
/// 布局
|
|
/// </summary>
|
|
public string layout { get; set; }
|
|
|
|
/// <summary>
|
|
/// 数据字典绑定关系
|
|
/// </summary>
|
|
public string dictionaryKey { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{name}-{label}-{type}";
|
|
}
|
|
|
|
public FormEditField Clone()
|
|
{
|
|
return (FormEditField)MemberwiseClone();
|
|
}
|
|
}
|
|
|
|
public class ClientField
|
|
{
|
|
public string name { get; set; }
|
|
public string label { get; set; }
|
|
public bool hidden { get; set; }
|
|
public bool sortable { get; set; }
|
|
/// <summary>
|
|
/// left, center, right.
|
|
/// </summary>
|
|
public string align { get; set; }
|
|
public string width { get; set; }
|
|
}
|
|
|
|
}
|