Exemplo n.º 1
0
        public static long GenSnowflakeId(uint dataCenterId = 5, uint workId = 20)
        {
            var sf = new Common.IdGenerator.SnowflakeId(dataCenterId, workId);
            var id = sf.NextId();

            return(id);
        }
Exemplo n.º 2
0
        private void AuditValue(object s, AuditValueEventArgs e)
        {
            if (e.AuditValueType == AuditValueType.Insert &&
                e.Property.Name == "Id" &&
                e.Property.GetCustomAttribute <SnowflakeAttribute>(false) != null
                )
            {
                var dataCenterId = _systemConfig.CurrentValue?.DataCenterId ?? 5;
                var workId       = _systemConfig.CurrentValue?.WorkId ?? 20;
                var sf           = new Common.IdGenerator.SnowflakeId(dataCenterId, workId);
                //var sf = Common.IdGenerator.Snowflake.Instance();
                //var dataCenterId = _systemConfig.CurrentValue?.DataCenterId ?? 5;
                //var workId = _systemConfig.CurrentValue?.WorkId ?? 20;
                //sf.Init(dataCenterId, workId);
                var id = sf.NextId();
                e.Value = id.ToString();
            }

            if (_authUser == null || _authUser.Id == "")
            {
                return;
            }

            if (e.AuditValueType == FreeSql.Aop.AuditValueType.Insert)
            {
                switch (e.Property.Name)
                {
                case "CreatedBy":
                    e.Value = _authUser.Id;
                    break;

                case "CreatedByName":
                    e.Value = _authUser.UserName;
                    break;
                    //case "CreatedTime":
                    //    e.Value = DateTime.Now.Subtract(timeOffset);
                    //    break;
                }
            }
            else if (e.AuditValueType == FreeSql.Aop.AuditValueType.Update)
            {
                switch (e.Property.Name)
                {
                case "UpdatedBy":
                    e.Value = _authUser.Id;
                    break;

                case "UpdatedByName":
                    e.Value = _authUser.UserName;
                    break;
                    //case "UpdatedTime":
                    //    e.Value = DateTime.Now.Subtract(timeOffset);
                    //    break;
                }
            }
        }