Example #1
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        public void DeleteCut(string id)
        {
            var item = _dbContext.bucket_cut.Find(id);

            if (item != null)
            {
                _dbContext.Remove(item);
            }
            _dbContext.SaveChanges();
            _cacheManager.Remove(MODEL_KEY);
        }
Example #2
0
        /// <summary>
        /// 开启任务
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public (bool Status, string Message) Start(Guid id)
        {
            var item = _dbContext.quarzt_schedule.Find(id);

            if (item == null)
            {
                return(Fail("任务不存在"));
            }

            var res = _jobCenter.AddScheduleJobAsync(_mapper.Map <QuarztScheduleMapping>(item)).Result;

            if (res.Status)
            {
                item.run_status = (int)JobStatus.执行任务中;
                _dbContext.SaveChanges();
            }
            return(res);
        }
Example #3
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="bucket"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public (bool Status, string Message) UpdateBucket(BucketMapping bucket, string userId)
        {
            var item = _dbContext.bucket.Find(bucket.id);

            if (item == null)
            {
                return(Fail("数据不存在"));
            }
            string oldLog = JsonConvert.SerializeObject(item);

            item.description = bucket.description;
            item.is_compress = bucket.is_compress;
            string newLog = JsonConvert.SerializeObject(item);

            _dbContext.SaveChanges();
            _activityLogService.UpdatedEntity <Entities.bucket>(item.id, oldLog, newLog, userId);
            _cacheManager.Remove(MODEL_KEY);
            return(Success("修改成功"));
        }
Example #4
0
 /// <summary>
 /// 新增
 /// </summary>
 /// <param name="bucketImage"></param>
 public void AddImage(Entities.bucket_image bucketImage)
 {
     lock (lockObj)
     {
         if (!_dbContext.bucket_image.Any(o => o.sha1 == bucketImage.sha1))
         {
             _dbContext.bucket_image.Add(bucketImage);
             _dbContext.SaveChanges();
         }
     }
 }
Example #5
0
        /// <summary>
        /// 强制用户下线所有平台
        /// </summary>
        /// <param name="userId"></param>
        public void CompelOut(string userId)
        {
            var jwtList = _dbContext.sys_user_jwt.Where(o => o.user_id == userId).ToList();

            _dbContext.sys_user_jwt.RemoveRange(jwtList);
            _dbContext.SaveChanges();
            jwtList.ForEach(item =>
            {
                RemoveCahce(item.id);
            });
        }
Example #6
0
        /// <summary>
        /// 保存基数设置的值
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public (bool Status, string Message) SaveSetting(string name, string value)
        {
            var item = _dbContext.sys_setting.FirstOrDefault(o => o.name == name);

            if (item == null)
            {
                _dbContext.sys_setting.Add(new Entities.sys_setting()
                {
                    id    = CombGuid.NewGuidAsString(),
                    name  = name,
                    value = value
                });
            }
            else
            {
                item.value = value;
            }
            _dbContext.SaveChanges();
            _cacheManager.Remove(MODEL_KEY);
            return(Success("保存成功"));
        }
Example #7
0
 /// <summary>
 /// 配置用户角色
 /// </summary>
 /// <param name="userRoles"></param>
 public void SetUserRoles(string userId, List <string> roleIds, string modifier)
 {
     try
     {
         using (var trans = _dbContext.Database.BeginTransaction())
         {
             _dbContext.Database.ExecuteSqlRaw($"DELETE FROM sys_user_role WHERE id!='' AND user_id='{userId}'");
             if (roleIds != null && roleIds.Any())
             {
                 roleIds.ForEach(roleId =>
                 {
                     _dbContext.sys_user_role.Add(new sys_user_role()
                     {
                         id      = CombGuid.NewGuidAsString(),
                         role_id = roleId,
                         user_id = userId
                     });
                 });
             }
             _dbContext.SaveChanges();
             trans.Commit();
             _cacheManager.Remove(USER_ROLES_ALL);
         }
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, ex.Message);
     }
 }
Example #8
0
        /// <summary>
        /// 用户登陆验证
        /// </summary>
        /// <param name="account"></param>
        /// <param name="password"></param>
        /// <param name="platform">0:web,1:app</param>
        /// <returns></returns>
        public (bool Status, string Message, Entities.sys_user User, Entities.sys_user_jwt Jwt) ValidateUser(string account, string password, int platform = 0)
        {
            var user = _dbContext.sys_user.Where(o => o.account == account && !o.is_deleted).FirstOrDefault();

            if (user == null)
            {
                return(false, "账号或密码错误", null, null);
            }
            bool success = false;
            var  log     = new Entities.sys_user_login()
            {
                id          = CombGuid.NewGuidAsString(),
                user_id     = user.id,
                ip_addr     = _webHelper.GetIPAddress(),
                logged_time = DateTime.Now,
            };

            Entities.sys_user_jwt jwt = null;
            string msg = "账号或密码错误";

            if (!String.IsNullOrEmpty(user.password) && password.Equals(user.password, StringComparison.InvariantCultureIgnoreCase))
            {
                success          = true;
                msg              = "登陆成功";
                user.last_ipaddr = log.ip_addr;
                jwt              = new Entities.sys_user_jwt()
                {
                    id         = CombGuid.NewGuidAsString(),
                    expiration = DateTime.Now.AddDays(30),
                    platform   = platform,
                    user_id    = user.id
                };
                _dbContext.sys_user_jwt.Add(jwt);
            }
            _dbContext.sys_user_login.Add(log);
            _dbContext.SaveChanges();
            return(success, msg, user, jwt);
        }
Example #9
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="sysCategories"></param>
 public void Init(List <Entities.sys_category> sysCategories)
 {
     using (var tarns = _dbContext.Database.BeginTransaction())
     {
         var oldList = _dbContext.sys_category.ToList();
         oldList.ForEach(del =>
         {
             var item = sysCategories.FirstOrDefault(o => o.uid == del.uid);
             if (item == null)
             {
                 _dbContext.Database.ExecuteSqlRaw($"DELETE FROM sys_permission WHERE id != '' AND category_id='{del.id}'");
                 _dbContext.sys_category.Remove(del);
             }
         });
         sysCategories.ForEach(entity =>
         {
             var item = oldList.FirstOrDefault(o => o.uid == entity.uid);
             if (item == null)
             {
                 _dbContext.sys_category.Add(entity);
             }
             else
             {
                 item.route_template = entity.route_template ?? "";
                 item.name           = entity.name;
                 item.code           = entity.code;
                 item.father_code    = entity.father_code;
                 item.target         = entity.target ?? "0";
                 item.sort           = entity.sort;
                 item.is_menu        = entity.is_menu;
                 item.controller     = entity.controller ?? "";
                 item.action         = entity.action ?? "";
                 item.route_name     = entity.route_name ?? "";
                 item.icon_class     = entity.icon_class ?? "";
             }
         });
         _dbContext.SaveChanges();
         tarns.Commit();
         _cacheManager.Remove(MODEL_ALL);
     }
 }
Example #10
0
 /// <summary>
 /// 私有方法
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="logService"></param>
 /// <param name="method"></param>
 /// <param name="entity"></param>
 public void InsertActivityLog <T>(string method, object primaryKey, string oldValue, string newValue, string userId = null)
 {
     try
     {
         var log = new Entities.sys_activitylog()
         {
             id            = CombGuid.NewGuidAsString(),
             primary_key   = primaryKey.ToString(),
             creation_time = DateTime.Now,
             method        = method,
             oldvalue      = oldValue,
             newvalue      = newValue,
             entity_name   = typeof(T).Name,
             creator       = userId
         };
         _dbContext.sys_activitylog.Add(log);
         _dbContext.SaveChanges();
     }
     catch
     {
     }
 }
Example #11
0
        /// <summary>
        /// 初始化
        /// </summary>
        public void Initialize()
        {
            using (var connection = _dbContext.Database.GetDbConnection())
            {
                connection.Open();
                var com = connection.CreateCommand();
                com.CommandText = $"select table_name from information_schema.tables where table_schema='{connection.Database}';";
                var           dr     = com.ExecuteReader();
                List <string> tables = new List <string>();

                while (dr.Read())
                {
                    tables.Add(dr["table_name"].ToString());
                }
                dr.Close();
                connection.Close();

                var ac_comments = _dbContext.sys_activitylog_comment.ToList();
                ac_comments.ForEach(del =>
                {
                    if (!tables.Any(o => o == del.entity_name))
                    {
                        _dbContext.sys_activitylog_comment.Remove(del);
                    }
                });
                tables.ForEach(name =>
                {
                    if (!ac_comments.Any(o => o.entity_name == name))
                    {
                        _dbContext.sys_activitylog_comment.Add(new sys_activitylog_comment()
                        {
                            entity_name = name
                        });
                    }
                });
                _dbContext.SaveChanges();
            }
        }