RG3.PF.Abstractions.Enums
namespace RG3.PF.Abstractions.Enums
{
/// <summary>
/// guid 输出方式
/// </summary>
public enum GuidMethod
{
/// <summary>
/// 程序 入库 前8位
/// </summary>
None = 0,
/// <summary>
/// 程序 入库 前8位
/// </summary>
GUID_08 = 1,
/// <summary>
/// 程序 入库 36位 机器码-所属项目4-所属系统4-GUID补全
/// </summary>
GUID_32 = 2,
/// <summary>
///程序 有数据库自动生成
/// </summary>
GUID_DB = 3,
/// <summary>
///每次都自动生成ID
/// </summary>
NEW_ID = 4,
/// <summary>
/// 外部传递
/// </summary>
Out = 5,
/// <summary>
/// 雪花算法
/// </summary>
Snowflake = 6,
}
}
RG3.BO.DB/Repository/DbExecuteRepository$InitDefaultParams.cs
bool savePrimary = !isChild || dicPK[sqlColumn.Field] == null || string.IsNullOrEmpty(dicPK[sqlColumn.Field].ToString());
/// <summary>
/// 新增的默认参数
/// </summary>
/// <param name="pf"></param>
/// <param name="sqlTable"></param>
/// <param name="sqlConfig"></param>
/// <param name="dictionaryUrl"></param>
/// <param name="dicPK"></param>
/// <param name="isChild"></param>
public void SetDefaultParamsAdd(PFGlobalParameter pf, SqlTable sqlTable, SqlConfig sqlConfig, Dictionary<string, object> dictionaryUrl, Dictionary<string, object> dicPK, bool isChild)
{
IEnumerable<SqlColumn> sqlColumnGuid = sqlConfig.ColumnsLst.Where<SqlColumn>(temp =>
{
return temp.TableId == sqlTable.Id && ValidateUtil.ValidateExistsValue(temp.GuidMethod) && (temp.GuidMethod != GuidMethod.GUID_DB || temp.GuidMethod != GuidMethod.NEW_ID) && temp.GuidMethod != GuidMethod.None;
});
foreach (SqlColumn sqlColumn in sqlColumnGuid)
{
if (!dicPK.ContainsKey(sqlColumn.Field)) continue;
//表示外部传递进来的值
//if (dicPK[sqlColumn.Field] != null && dicPK[sqlColumn.Field].ToString().Length > 2) continue;
if (sqlConfig.ResponseFieldTemp.GuidMethod == GuidMethod.Out) continue;
if (dicPK[sqlColumn.Field] != null && dicPK[sqlColumn.Field].ToString() != "-1" && dicPK[sqlColumn.Field].ToString() != "0") continue;
string guid = null;
bool savePrimary = !isChild || dicPK[sqlColumn.Field] == null || string.IsNullOrEmpty(dicPK[sqlColumn.Field].ToString());
if (_configuration.GetValue<bool>($"snowflake:{pf.OwnerId}:global"))
{
guid = _guid.GetDataGuid(pf.OwnerId, pf.SysId, dictionaryUrl);
dicPK[sqlColumn.Field] = guid;
}
else if (savePrimary && sqlColumn.GuidMethod == GuidMethod.Snowflake)
{
string machineIdI = _configuration.GetValue<string>($"snowflake:{pf.OwnerId}:machine") ?? "1";
string datacenterId = _configuration.GetValue<string>($"snowflake:{pf.OwnerId}:{pf.SysId}") ?? "-1";
GidSnowflakeUtil GidSnowflakeUtil = new GidSnowflakeUtil(Convert.ToInt32(machineIdI), Convert.ToInt32(datacenterId));
guid = GidSnowflakeUtil.GetId().ToString();
dicPK[sqlColumn.Field] = guid;
}
else if (savePrimary && dictionaryUrl.ContainsKey("_ownerId") && !string.IsNullOrEmpty(dictionaryUrl["_ownerId"]?.ToString()))
{
guid = _guid.GetDataGuid(pf.OwnerId, pf.SysId, dictionaryUrl);
if (sqlColumn.GuidMethod == GuidMethod.GUID_08)
{
guid = guid.Split('-')[0];
}
string tempOwnerId = dictionaryUrl["_ownerId"].ToString();
if (tempOwnerId.Length > 8)
{
tempOwnerId = tempOwnerId.Substring(0, 8);
}
//标示ID来源项目,开头几位表示来源
string temp = guid.Substring(0, tempOwnerId.Length + 1);
dicPK[sqlColumn.Field] = guid.Replace(temp, $"{tempOwnerId}-").Replace("--", "-").Trim('-');
}
else if (savePrimary)
{
guid = _guid.GetDataGuid(pf.OwnerId, pf.SysId, dictionaryUrl);
if (sqlColumn.GuidMethod == GuidMethod.GUID_08)
{
guid = guid.Split('-')[0];
}
dicPK[sqlColumn.Field] = guid;
}
}
//设置使用系统内部默认的参数值
bool isTempDef = sqlConfig?.ResponseFieldTemp?.Field?.Params?.Count > 0;
IEnumerable<SqlColumn> sqlColumnCommon = sqlConfig.ColumnsLst.Where<SqlColumn>(temp =>
{
return temp.TableId == sqlTable.Id && temp.AddPropertie != null
&& temp.AddPropertie.DefaultValue != null
&& (dictionaryUrl.ContainsKey(temp.AddPropertie.DefaultValue.ToString()) || isTempDef);
});
foreach (SqlColumn sqlColumn in sqlColumnCommon)
{
if (dicPK.ContainsKey(sqlColumn.Field)
&& (Convert.IsDBNull(dicPK[sqlColumn.Field]) || dicPK[sqlColumn.Field] == null || sqlColumn.EditPropertie.IsUser == true || sqlColumn.EditPropertie.IsRequired == true))
{
if (!string.IsNullOrEmpty(sqlColumn.AddPropertie?.DefaultValue?.ToString()) && dictionaryUrl.ContainsKey(sqlColumn.AddPropertie.DefaultValue.ToString()))
{
dicPK[sqlColumn.Field] = dictionaryUrl[sqlColumn.AddPropertie.DefaultValue.ToString()];
}
}
}
//设置默认值来至内置参数
if (sqlConfig.ResponseFieldTemp != null && sqlConfig.ResponseFieldTemp.Field?.Params != null)
{
IEnumerable<SqlColumn> sqlColumnCommonDef = sqlConfig.ColumnsLst.Where<SqlColumn>(temp =>
{
return sqlConfig.ResponseFieldTemp.Field.Params.ContainsKey(temp.Field);
});
foreach (SqlColumn sqlColumn in sqlColumnCommonDef)
{
if (ValidateUtil.IsNullOrEmptyOrDbNull(dicPK[sqlColumn.Field]))
{
dicPK[sqlColumn.Field] = sqlConfig.ResponseFieldTemp.Field.Params[sqlColumn.Field];
}
}
}
}
/// <summar
文档更新时间: 2022-09-18 13:25 作者:admin