/// <summary>
        /// 主键 来源字段1
        /// </summary>
        public string PrimaryFromFieldOne { get; set; }

        /// <summary>
        /// 主键 来源字段2
        /// </summary>
        public string PrimaryFromFieldTwo { get; set; }

        /// <summary>
        /// 主键 来源字段2
        /// </summary>
        public string PrimaryFromFieldThree { get; set; }


        /// <summary>
        /// 主键 显示格式
        /// </summary>
        public string PrimaryFormat { get; set; }

                #region  设置guid主键信息  cbg  20190208
                IEnumerable<SqlColumn> sqlColumGuid = sqlConfig.ColumnsLst.Where<SqlColumn>(temp =>
                {
                    return temp.GuidMethod != GuidMethod.None && temp.TableId == sqlTable.Id;
                });
                foreach (SqlColumn sqlColumn in sqlColumGuid)
                {
                    // 雪花ID,用于主键添加前缀等
                    dicPK["_gidSnowflakeGuid"] = _guid.GidSnowflakeGuid();

                    bool fromPrimary = !string.IsNullOrEmpty(sqlColumn.PrimaryFormat) && !string.IsNullOrEmpty(sqlColumn.PrimaryFromFieldOne) && !string.IsNullOrEmpty(sqlColumn.PrimaryFromFieldTwo);
                    if (fromPrimary && !string.IsNullOrEmpty(sqlColumn.PrimaryFromFieldThree))
                    {
                        StringBuilder sbC = new StringBuilder();
                        sbC.Append(sqlColumn.PrimaryFormat);
                        sbC.Replace("{primary_from_field_one}", dicPK[sqlColumn.PrimaryFromFieldOne].ToString());
                        sbC.Replace("{primary_from_field_two}", dicPK[sqlColumn.PrimaryFromFieldTwo].ToString());
                        sbC.Replace("{primary_from_field_three}", dicPK[sqlColumn.PrimaryFromFieldThree].ToString());
                        sbC.Append(sqlColumn.PrimaryFormat);
                        if (sbC.Length > sqlColumn.MaxLength)
                        {
                            dicPK[sqlColumn.Field] = sbC.ToString().Substring(5, (sbC.Length - Convert.ToInt32(sqlColumn.MaxLength))).Replace("--", "");
                        }
                        else
                        {
                            dicPK[sqlColumn.Field] = sbC.ToString();
                        }
                        SetInsertValue(dicPK, sqlConfig, sbInsertColumn, sbInsertColumnValue, sqlColumn);
                    }
                    else if (fromPrimary)
                    {
                        StringBuilder sbC = new StringBuilder();
                        sbC.Append(sqlColumn.PrimaryFormat);
                        sbC.Replace("{primary_from_field_one}", dicPK[sqlColumn.PrimaryFromFieldOne].ToString());
                        sbC.Replace("{primary_from_field_two}", dicPK[sqlColumn.PrimaryFromFieldTwo].ToString());
                        if (sbC.Length > sqlColumn.MaxLength)
                        {
                            dicPK[sqlColumn.Field] = sbC.ToString().Substring(5, (sbC.Length - Convert.ToInt32(sqlColumn.MaxLength))).Replace("--", "");
                        }
                        else
                        {
                            dicPK[sqlColumn.Field] = sbC.ToString();
                        }
                        dicPK[sqlColumn.Field] = sbC.ToString();
                        SetInsertValue(dicPK, sqlConfig, sbInsertColumn, sbInsertColumnValue, sqlColumn);
                    }
                    else if (dicPK.ContainsKey(sqlColumn.Field))
                    {
                        SetInsertValue(dicPK, sqlConfig, sbInsertColumn, sbInsertColumnValue, sqlColumn);
                    }
                    else
                    {
                        dicPK[sqlColumn.Field] = _guid.GidSnowflakeGuid();
                        SetInsertValue(dicPK, sqlConfig, sbInsertColumn, sbInsertColumnValue, sqlColumn);
                    }
                }
                #endregion
文档更新时间: 2022-09-18 14:56   作者:admin