/// <summary>
        /// 暂停/删除 指定的计划
        /// </summary>
        /// <param name="jobKey"></param>
        /// <param name="isDelete">停止并删除任务</param>
        /// <returns></returns>
        public async Task <BaseResponseModel> StopOrDelScheduleJobAsync(JobKey jobKey, bool isDelete = false)
        {
            var result = new ResponseModel <string>();

            try
            {
                await Scheduler.PauseJob(jobKey);

                if (isDelete)
                {
                    await Scheduler.DeleteJob(jobKey);

                    result.Succeed("删除任务计划成功");
                }
                else
                {
                    result.Succeed("暂停任务计划成功");
                }
            }
            catch (Exception ex)
            {
                result.Fail(ResponseCode.UnknownEx, "停止计划任务失败!--" + ex.Message, "");
            }

            return(result);
        }
        /// <summary>
        /// 恢复运行暂停的任务
        /// </summary>
        /// <param name="jobKey">任务</param>
        public async Task <BaseResponseModel> ResumeJobAsync(JobKey jobKey)
        {
            var result = new ResponseModel <string>();

            try
            {
                //检查任务是否存在
                if (await Scheduler.CheckExists(jobKey))
                {
                    //任务已经存在则暂停任务
                    await Scheduler.ResumeJob(jobKey);

                    result.Succeed("恢复任务计划成功");
                }
                else
                {
                    result.Succeed("任务不存在");
                }
            }
            catch (Exception ex)
            {
                result.Fail(ResponseCode.UnknownEx, "恢复任务计划失败!--" + ex.Message, "");
                LogHelper.Logger.Error($"恢复任务失败!{ex}");
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// 修改角色
        /// </summary>
        /// <param name="incrementRoleParam"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <BaseResponseModel> ModifyRoleAsync(IncrementRoleParam incrementRoleParam, UserCacheBo currentUser)
        {
            var result = new ResponseModel <string>();
            var db     = SysRoleDao.CurrentDbContext;

            if (await db.SysRoles.AnyAsync(c => c.TenantId == currentUser.TenantId && !c.Deleted && c.RoleName == incrementRoleParam.RoleName && c.RoleId != incrementRoleParam.RoleId))
            {
                return(result.Fail("角色名已存在"));
            }

            var checkResult = await RoleIdCheckAsync(incrementRoleParam.RoleId, currentUser);

            if (!checkResult.IsNullOrEmpty())
            {
                return(result.Fail(checkResult));
            }

            var role = await db.SysRoles.FirstOrDefaultAsync(c => !c.Deleted && c.RoleId == incrementRoleParam.RoleId && c.TenantId == currentUser.TenantId);

            role.RoleName    = incrementRoleParam.RoleName;
            role.RoleDesc    = incrementRoleParam.RoleDesc ?? "";
            role.UpdatedBy   = currentUser.UserId;
            role.UpdatedTime = DateTime.Now;
            var count = await db.SaveChangesAsync();

            return(count > 0 ? result.Succeed("修改成功") : result.Fail("修改失败", "修改失败"));
        }
Beispiel #4
0
        public virtual async Task <BaseResponseModel> RemoveManagerUserAsync(long uid, UserCacheBo currentUser)
        {
            var result = new ResponseModel <bool>();
            var db     = SysUserDao.CurrentDbContext;

            var deleteUser = await db.SysUsers.FirstOrDefaultAsync(c => c.UserId == uid && c.TenantId == currentUser.UserId && c.State == 1);

            if (deleteUser == null)
            {
                return(result.Fail("账号不存在"));
            }
            // 管理员创建者都是0  注册的
            if (deleteUser.CreatedBy <= 0)
            {
                return(result.Fail("管理员只读"));
            }

            var count = 0;

            count += await db.SysUsers.Where(c => c.UserId == uid && c.TenantId == currentUser.TenantId).DeleteFromQueryAsync();

            count += await db.SysUserRoleRelations.Where(c => c.UserId == uid && c.TenantId == currentUser.TenantId).DeleteFromQueryAsync();

            count += await db.SaveChangesAsync();

            return(count > 0 ? result.Succeed(true) : result.Fail("删除失败"));
        }
Beispiel #5
0
        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="incrementMenu"></param>
        /// <returns></returns>
        public async Task <BaseResponseModel> UpdateMenuAsync(UserCacheBo currentUser, IncrementMenuParam incrementMenu)
        {
            var responseModel = new ResponseModel <bool>();
            var count         = await SysMenuDao.UpdateMenuAsync(currentUser, incrementMenu);

            return(count ? responseModel.Succeed(true) : responseModel.Fail(ResponseCode.Fail, "修改失败"));
        }
Beispiel #6
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="modifyPwdParam"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <ResponseModel <string> > ModifyPwdAsync(ModifyPwdParam modifyPwdParam, UserCacheBo currentUser)
        {
            var result = new ResponseModel <string>();

            if (modifyPwdParam.NewPassWord == modifyPwdParam.OldPassWord)
            {
                return(result.Fail(ResponseCode.Fail, "不允许原密码和新密码相同的修改"));
            }

            if (modifyPwdParam.OldPassWord.Md5Encrypt() == currentUser.PassWord)
            {
                var updateResult = await SysUserDao.ModifyPwdAsync(modifyPwdParam, currentUser.UserId);

                if (updateResult)
                {
                    // 修改成功 登出 重新登录
                    await LogoutAsync(currentUser);

                    return(result.Succeed("修改成功,请重新登录"));
                }

                return(result.Fail(ResponseCode.Fail, "修改失败,请稍后再试"));
            }

            return(result.Fail(ResponseCode.Fail, "原密码不正确"));
        }
Beispiel #7
0
        /// <summary>
        /// 发送验证码 - 找回密码
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public async Task <ResponseModel <string> > SendEmailAsync(string email)
        {
            var response = new ResponseModel <string>();

            if (!email.IsEmail())
            {
                return(response.Fail("邮箱格式错误"));
            }

            var key           = $"{CacheKeys.RETRIEVEPWDCAPTCHA}{email}";
            var expireMinutes = 5;

            if (await FrequentlyGetCaptchaAsync(key, expireMinutes, 2))
            {
                return(response.Fail("获取验证码过于频繁,请稍后再获取"));
            }

            if (!await ExistUserAsync(email))
            {
                return(response.Fail("该邮箱尚未注册或无效"));
            }

            var captchaNumber = CaptchaHelper.CreateRandomNumber(6);
            var htmlEmail     = SystemBll.GetMailContent("找回密码", captchaNumber, expireMinutes);
            var result        = await SystemBll.SendSystemMailAsync("LionFrame-找回密码", htmlEmail, email);

            if (result.Contains("发送成功"))
            {
                await RedisClient.SetAsync(key, captchaNumber, new TimeSpan(0, expireMinutes, 0));
            }

            return(response.Succeed("发送成功"));
        }
Beispiel #8
0
        public virtual async Task <ResponseModel <bool> > RegisterUserAsync(RegisterUserParam registerUserParam)
        {
            var result             = new ResponseModel <bool>();
            var verificationResult = await VerificationCaptchaAsync(CacheKeys.REGISTERCAPTCHA, registerUserParam.Email, registerUserParam.Captcha, false);

            if (verificationResult != "验证通过")
            {
                result.Fail(ResponseCode.Fail, verificationResult, false);
                return(result);
            }

            if (await ExistUserAsync(registerUserParam.Email))
            {
                result.Fail(ResponseCode.Fail, "该邮箱已存在,请切换或找回密码", false);
                return(result);
            }

            var count = await SaveRegisterUserAsync(registerUserParam);

            if (count > 0)
            {
                return(result.Succeed(true));
            }

            return(result.Fail(ResponseCode.Fail, "保存失败,请稍后再试", false));
        }
Beispiel #9
0
        /// <summary>
        /// 新增角色
        /// </summary>
        /// <param name="incrementRoleParam"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <BaseResponseModel> AddRoleAsync(IncrementRoleParam incrementRoleParam, UserCacheBo currentUser)
        {
            var result = new ResponseModel <string>();
            var db     = SysRoleDao.CurrentDbContext;

            SysRoleDao.CloseTracking();
            if (await db.SysRoles.CountAsync(c => c.TenantId == currentUser.TenantId && !c.Deleted) > 500)
            {
                return(result.Fail("一个租户下角色上限为500个"));
            }

            if (await db.SysRoles.AnyAsync(c => c.TenantId == currentUser.TenantId && !c.Deleted && c.RoleName == incrementRoleParam.RoleName))
            {
                return(result.Fail("角色名已存在"));
            }

            var role = new SysRole()
            {
                TenantId    = currentUser.TenantId,
                CreatedBy   = currentUser.UserId,
                CreatedTime = DateTime.Now,
                Deleted     = false,
                RoleDesc    = incrementRoleParam.RoleDesc ?? "",
                RoleName    = incrementRoleParam.RoleName,
            };
            await db.SysRoles.AddAsync(role);

            var count = await db.SaveChangesAsync();

            return(count > 0 ? result.Succeed("添加成功") : result.Fail("添加失败"));
        }
Beispiel #10
0
        public virtual async Task <ResponseModel <bool> > ModifyManagerUserAsync(long uid, List <long> roleIds, string nickName, UserCacheBo currentUser)
        {
            var result = new ResponseModel <bool>();
            var user   = await CurrentDbContext.SysUsers.FirstOrDefaultAsync(c => c.UserId == uid && c.State == 1 && c.TenantId == currentUser.TenantId);

            if (user == null)
            {
                return(result.Fail("修改的用户信息不存在"));
            }
            if (user.CreatedBy == 0)
            {
                return(result.Fail("管理员只读"));
            }

            //获取当前用户所拥有的角色
            var existRoleIds = await CurrentDbContext.SysUserRoleRelations.Where(c => c.UserId == uid && !c.Deleted && c.State == 1 && c.TenantId == currentUser.TenantId && c.CreatedBy > 0)
                               .Select(c => c.RoleId).ToListAsync();

            user.NickName = nickName;

            var dRoleIds = existRoleIds.Except(roleIds).ToList(); //删除此前分配的角色 不在这次保存角色中的
            var iRoleIds = roleIds.Except(existRoleIds).ToList(); //插入这次新增的不在之前角色中的

            //相同部分不做改变
            if (dRoleIds.Any())
            {
                // 删除
                await CurrentDbContext.SysUserRoleRelations.Where(c => c.UserId == uid && dRoleIds.Contains(c.RoleId) && c.TenantId == currentUser.TenantId).DeleteFromQueryAsync();
            }

            if (iRoleIds.Count > 0)
            {
                //插入
                var userRoleRelations = new List <SysUserRoleRelation>();
                iRoleIds.ForEach(roleId =>
                {
                    userRoleRelations.Add(new SysUserRoleRelation()
                    {
                        TenantId    = currentUser.TenantId,
                        CreatedBy   = currentUser.UserId,
                        CreatedTime = DateTime.Now,
                        RoleId      = roleId,
                        State       = 1,
                        UserId      = uid,
                    });
                });
                await CurrentDbContext.SysUserRoleRelations.AddRangeAsync(userRoleRelations);
            }

            var count = await SaveChangesAsync();

            return(count > 0 ? result.Succeed(true) : result.Fail("保存修改信息失败"));
        }
Beispiel #11
0
        /// <summary>
        /// 取消分配菜单
        /// </summary>
        /// <param name="menuIds"></param>
        /// <param name="uid"></param>
        /// <returns></returns>
        public async Task <BaseResponseModel> CancelAssignMenuAsync(List <string> menuIds, long uid)
        {
            var count = await SysRoleMenuRelationDao.CurrentDbContext.SysRoleMenuRelations.Where(c => menuIds.Contains(c.MenuId) && c.RoleId != 1).UpdateFromQueryAsync(c => new SysRoleMenuRelation()
            {
                Deleted     = true,
                UpdatedBy   = uid,
                UpdatedTime = DateTime.Now,
            });

            var result = new ResponseModel <bool>();

            return(count > 0 ? result.Succeed(true) : result.Fail("分配菜单失败"));
        }
        /// <summary>
        /// 添加一个工作调度
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <BaseResponseModel> AddScheduleJobAsync(ScheduleEntityParam entity)
        {
            var result = new ResponseModel <string>();

            try
            {
                if (!await CheckScheduleEntityParam(entity, result))
                {
                    return(result);
                }

                var jobDataMap = new Dictionary <string, string>()
                {
                    { QuartzConstant.NOTIFYEMAIL, entity.NotifyEmail },
                    { QuartzConstant.MAILMESSAGE, ((int)entity.MailMessage).ToString() },
                    { QuartzConstant.JOBTYPE, ((int)entity.JobType).ToString() },
                    { QuartzConstant.REQUESTPARAMETERS, entity.RequestParameters } //http Body 参数,Assembly 调用方法参数。
                };
                IJobDetail job;
                switch (entity.JobType)
                {
                case JobTypeEnum.Http:
                    job = AddHttpJob(entity, jobDataMap);
                    break;

                case JobTypeEnum.Assembly:
                    job = AddAssemblyJob(entity, jobDataMap);
                    break;

                case JobTypeEnum.None:
                default:
                    return(result.Fail("未选择任务类型"));

                    break;
                }

                //校验是否正确的执行周期表达式
                var trigger = entity.TriggerType == TriggerTypeEnum.Cron ? CreateCronTrigger(entity) : CreateSimpleTrigger(entity);

                await Scheduler.ScheduleJob(job, trigger);

                result.Succeed("添加任务成功");
            }
            catch (Exception ex)
            {
                LogHelper.Logger.Fatal(ex, "添加任务失败");
                result.Fail(ResponseCode.UnknownEx, ex.Message, "");
            }

            return(result);
        }
Beispiel #13
0
        public virtual async Task <BaseResponseModel> ModifyRoleMenuAsync(ModifyRoleMenuParam roleMenuParam, UserCacheBo currentUser)
        {
            var result = new ResponseModel <string>();

            var checkResult = await RoleIdCheckAsync(roleMenuParam.RoleId, currentUser);

            if (!checkResult.IsNullOrEmpty())
            {
                return(result.Fail(checkResult));
            }

            var currentUserMenus = await MenuBll.GetCurrentMenuAsync(currentUser);

            var currentMenuIds = currentUserMenus.Select(c => c.MenuId).ToList();
            //检查提交的按钮是否存在当前用户管理菜单数据中,只操作存在部分 即交集
            var crossMenuIds = roleMenuParam.MenuIds.Intersect(currentMenuIds).ToList();

            // 这里不是做的全量操作,而且新增部分做插入 数据库中的不在提交数据中的部分做删除  提交的和数据库相交叉的部分不做变动
            var dbMenuIds = await SysMenuDao.LoadEntities <SysRoleMenuRelation>(c => c.RoleId == roleMenuParam.RoleId && c.TenantId == currentUser.TenantId).Select(c => c.MenuId).ToListAsync();

            var dIds = dbMenuIds.Except(crossMenuIds).ToList(); //需要删除的权限
            var iIds = crossMenuIds.Except(dbMenuIds).ToList(); //需要插入的新权限

            var db = SysRoleDao.CurrentDbContext;

            if (dIds.Count > 0)
            {
                await db.SysRoleMenuRelations.Where(c => dIds.Contains(c.MenuId) && c.RoleId == roleMenuParam.RoleId).DeleteAsync();
            }

            if (iIds.Count > 0)
            {
                var roleMenuRelations = iIds.Select(iId => new SysRoleMenuRelation()
                {
                    TenantId    = currentUser.TenantId,
                    CreatedBy   = currentUser.UserId,
                    CreatedTime = DateTime.Now,
                    MenuId      = iId,
                    State       = 1,
                    Deleted     = false,
                    RoleId      = roleMenuParam.RoleId,
                    UpdatedBy   = 0,
                    UpdatedTime = DateTime.Now,
                }).ToList();
                await db.SysRoleMenuRelations.AddRangeAsync(roleMenuRelations);
            }

            await db.SaveChangesAsync();

            return(result.Succeed("修改成功"));
        }
Beispiel #14
0
        /// <summary>
        /// 用户管理界面创建用户
        /// </summary>
        /// <param name="param"></param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <BaseResponseModel> CreateManagerUserAsync(CreateUserParam param, UserCacheBo currentUser)
        {
            var result = new ResponseModel <bool>();

            // 考虑是否验证上传的角色是当前租户下的
            var checkResult = await CheckRoleIds(param.RoleIds, currentUser);

            if (!checkResult.IsNullOrEmpty())
            {
                return(result.Fail(checkResult));
            }

            if (await ExistUserAsync(param.Email))
            {
                result.Fail(ResponseCode.Fail, "该邮箱已存在", false);
                return(result);
            }

            var sysUser = new SysUser()
            {
                NickName             = param.NickName,
                PassWord             = param.Pwd.Md5Encrypt(),
                Email                = param.Email,
                Sex                  = 1,
                State                = 1,
                CreatedTime          = DateTime.Now,
                UpdatedTime          = DateTime.Now,
                TenantId             = currentUser.TenantId,
                UpdatedBy            = 0,
                CreatedBy            = currentUser.UserId,
                SysUserRoleRelations = new List <SysUserRoleRelation>()
            };

            param.RoleIds.ForEach(roleId =>
            {
                sysUser.SysUserRoleRelations.Add(new SysUserRoleRelation()
                {
                    TenantId    = currentUser.TenantId,
                    RoleId      = roleId,
                    State       = 1,
                    CreatedTime = DateTime.Now,
                    CreatedBy   = currentUser.UserId,
                    Deleted     = false,
                });
            });
            SysUserDao.Add(sysUser);
            var count = await SysUserDao.SaveChangesAsync();

            return(count > 0 ? result.Succeed(true) : result.Fail("保存失败", false));
        }
Beispiel #15
0
        public virtual async Task <BaseResponseModel> DeleteMenuAsync(string menuId)
        {
            var result          = new ResponseModel <string>();
            var db              = SysMenuDao.CurrentDbContext;
            var isExistChildren = await db.SysMenus.AnyAsync(c => c.ParentMenuId == menuId);

            if (isExistChildren)
            {
                return(result.Fail("请先删除子菜单后再删除父菜单"));
            }

            await db.SysMenus.Where(c => c.MenuId == menuId).DeleteFromQueryAsync();

            await db.SysRoleMenuRelations.Where(c => c.MenuId == menuId).DeleteFromQueryAsync();

            return(result.Succeed("删除成功"));
        }
Beispiel #16
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="loginParam"></param>
        /// <returns></returns>
        public async Task <ResponseModel <UserCacheBo> > LoginAsync(LoginParam loginParam)
        {
            CloseTracking();
            var response = new ResponseModel <UserCacheBo>();
            var user     = await FirstAsync <SysUser>(c => c.Email == loginParam.Email && c.State == 1);

            if (user == null)
            {
                return(response.Fail(ResponseCode.LoginFail, "账号不存在", null));
            }

            if (user.PassWord != loginParam.Password.Md5Encrypt())
            {
                return(response.Fail(ResponseCode.LoginFail, "账号或密码错误", null));
            }

            var dbData = from sysUser in CurrentDbContext.SysUsers
                         where sysUser.UserId == user.UserId && sysUser.State == 1
                         select new UserCacheBo
            {
                UserId       = sysUser.UserId,
                TenantId     = sysUser.TenantId,
                NickName     = sysUser.NickName,
                PassWord     = sysUser.PassWord,
                Email        = sysUser.Email,
                Sex          = sysUser.Sex,
                CreatedBy    = sysUser.CreatedBy,
                RoleCacheBos = from userRoleRelation in CurrentDbContext.SysUserRoleRelations
                               join sysRole in CurrentDbContext.SysRoles on userRoleRelation.RoleId equals sysRole.RoleId
                               where userRoleRelation.UserId == sysUser.UserId && !userRoleRelation.Deleted && !sysRole.Deleted &&
                               userRoleRelation.State == 1
                               select new RoleCacheBo()
                {
                    RoleId   = sysRole.RoleId,
                    TenantId = sysRole.TenantId,
                    RoleDesc = sysRole.RoleDesc,
                    RoleName = sysRole.RoleName,
                }
            };

            // 使用include 无法使用条件判断
            //var dbData1 = CurrentDbContext.SysUsers.Where(c => c.UserId == user.UserId && c.Status == 1).Include(c => c.SysUserRoleRelations).ThenInclude(c => c.SysRole).FirstOrDefault();
            //var userCacheBo = dbData1.MapTo<UserCacheBo>();
            response.Succeed(await dbData.FirstOrDefaultAsync());
            return(response);
        }
Beispiel #17
0
        /// <summary>
        /// 找回密码 -- 修改当前用户密码
        /// </summary>
        /// <param name="retrievePwdParam"></param>
        /// <returns></returns>
        public async Task <ResponseModel <bool> > RetrievePwdAsync(RetrievePwdParam retrievePwdParam)
        {
            var result             = new ResponseModel <bool>();
            var verificationResult = await VerificationCaptchaAsync(CacheKeys.RETRIEVEPWDCAPTCHA, retrievePwdParam.Email, retrievePwdParam.Captcha, false);

            if (verificationResult != "验证通过")
            {
                return(result.Fail(verificationResult, false));
            }

            var uid = await SysUserDao.RetrievePwdAsync(retrievePwdParam);

            await LogoutAsync(new UserCacheBo()
            {
                UserId = uid
            });

            return(result.Succeed(true));
        }
Beispiel #18
0
        public virtual async Task <BaseResponseModel> ModifyUserRoleAsync(ModifyUserRoleParam param, UserCacheBo currentUser)
        {
            var result      = new ResponseModel <string>();
            var checkResult = await RoleIdCheckAsync(param.RoleId, currentUser);

            if (!checkResult.IsNullOrEmpty())
            {
                return(result.Fail(checkResult));
            }

            var db        = SysRoleDao.CurrentDbContext;
            var dbUserIds = await db.SysUsers.Where(c => c.TenantId == currentUser.TenantId && c.CreatedBy > 0 && c.UserId != currentUser.UserId).Select(c => c.UserId).ToListAsync();

            var crossUserIds = param.UserIds.Intersect(dbUserIds).ToList(); //检查修改的用户是否是自己管理的用户ID,谨防其它手段上传的数据
            //直接全量修改 原有角色用户关系删除 直接新增现加的
            await db.SysUserRoleRelations.Where(c => c.RoleId == param.RoleId && c.TenantId == currentUser.TenantId).DeleteFromQueryAsync();

            if (crossUserIds.Count > 0)
            {
                var userRoles = new List <SysUserRoleRelation>();
                crossUserIds.ForEach(uid =>
                {
                    userRoles.Add(new SysUserRoleRelation()
                    {
                        TenantId    = currentUser.TenantId,
                        UserId      = uid,
                        RoleId      = param.RoleId,
                        State       = 1,
                        CreatedBy   = currentUser.UserId,
                        CreatedTime = DateTime.Now,
                        Deleted     = false,
                        UpdatedBy   = 0,
                        UpdatedTime = DateTime.Now,
                    });
                });
                await db.SysUserRoleRelations.AddRangeAsync(userRoles);
            }

            await db.SaveChangesAsync();

            return(result.Succeed("修改成功"));
        }
Beispiel #19
0
        public virtual async Task <BaseResponseModel> RemoveRoleAsync(long roleId, UserCacheBo currentUser)
        {
            var result = new ResponseModel <string>();
            var db     = SysRoleDao.CurrentDbContext;

            var checkResult = await RoleIdCheckAsync(roleId, currentUser);

            if (!checkResult.IsNullOrEmpty())
            {
                return(result.Fail(checkResult));
            }

            var count = await db.SysRoles.Where(c => c.RoleId == roleId && !c.Deleted).DeleteFromQueryAsync();

            count += await db.SysUserRoleRelations.Where(c => c.RoleId == roleId).DeleteFromQueryAsync();

            count += await db.SysRoleMenuRelations.Where(c => c.RoleId == roleId).DeleteFromQueryAsync();

            count += await db.SaveChangesAsync();

            return(count > 0 ? result.Succeed("角色删除成功") : result.Fail("角色删除失败"));
        }
Beispiel #20
0
        /// <summary>
        /// 修改任务
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <BaseResponseModel> ModifyTask(ScheduleEntityParam entity)
        {
            var responseResult = new ResponseModel <string>();
            var result         = await SysQuartzDao.CurrentDbContext.SysQuartzs.Where(c => c.JobGroup == entity.JobGroup && c.JobName == entity.JobName).UpdateFromQueryAsync(c => new SysQuartz()
            {
                BeginTime         = entity.BeginTime,
                EndTime           = entity.EndTime,
                Cron              = entity.Cron ?? "",
                RunTimes          = entity.RunTimes ?? 1,
                IntervalSecond    = entity.IntervalSecond ?? 1,
                RequestPath       = entity.RequestPath,
                RequestMethod     = entity.RequestMethod,
                RequestParameters = entity.RequestParameters ?? "{}",
                Headers           = entity.Headers ?? "{}",
                Priority          = entity.Priority,
                Description       = entity.Description,
                NotifyEmail       = entity.NotifyEmail ?? "",
                MailMessage       = entity.MailMessage,
                TriggerState      = TriggerState.Normal,
            });

            return(result > 0 ? responseResult.Succeed() : responseResult.Fail("最终修改失败"));
        }
Beispiel #21
0
        /// <summary>
        /// 用户登录 业务层
        /// </summary>
        /// <param name="loginParam"></param>
        /// <returns></returns>
        public async Task <ResponseModel <UserDto> > LoginAsync(LoginParam loginParam)
        {
            var result             = new ResponseModel <UserDto>();
            var verificationResult = await SystemBll.VerificationLoginAsync(loginParam);

            if (verificationResult != "验证通过")
            {
                result.Fail(ResponseCode.LoginFail, verificationResult, null);
                return(result);
            }

            var responseResult = await SysUserDao.LoginAsync(loginParam);

            if (responseResult.Success)
            {
                var userCache = responseResult.Data;
                CreateTokenCache(userCache);
                var userDto = userCache.MapTo <UserDto>();
                result.Succeed(userDto);
            }

            return(result);
        }
Beispiel #22
0
        public virtual async Task <BaseResponseModel> AddMenuAsync(UserCacheBo currentUser, IncrementMenuParam incrementMenu)
        {
            var responseModel = new ResponseModel <bool>();
            var sysMenu       = incrementMenu.MapTo <SysMenu>();

            sysMenu.CreatedTime = DateTime.Now;
            sysMenu.CreatedBy   = currentUser.UserId;
            sysMenu.UpdatedBy   = currentUser.UserId;


            var relations = new List <SysRoleMenuRelation>();
            // 循环取出租户主体信息角色 增加新权限关系 默认为删除状态 点击分配给使用
            var db = SysMenuDao.CurrentDbContext;
            var roleIdsQueryable = db.SysUserRoleRelations.Where(c => !c.Deleted && c.State == 1 && c.TenantId > 1 && c.CreatedBy == 0).Select(c => new RoleCacheBo {
                RoleId = c.RoleId, TenantId = c.TenantId
            });

            for (int i = 1; i < 100000; i++)
            {
                var roleIds = SysMenuDao.LoadPageEntities(roleIdsQueryable, i, 100, true, roleId => roleId.RoleId);
                if (roleIds.PageData.Count > 0)
                {
                    roleIds.PageData.ForEach(roleInfo =>
                    {
                        relations.Add(new SysRoleMenuRelation()
                        {
                            TenantId    = roleInfo.TenantId,
                            MenuId      = sysMenu.MenuId,
                            RoleId      = roleInfo.RoleId,
                            Deleted     = true, //默认不分配给超级管理员看  需单独分配
                            CreatedTime = DateTime.Now,
                            CreatedBy   = 0,    //系统创建的都设置为0
                            State       = 1,
                        });
                    });
                }
                else
                {
                    break;
                }
            }

            relations.Add(new SysRoleMenuRelation()
            {
                TenantId    = 1,     //系统租户ID
                MenuId      = sysMenu.MenuId,
                RoleId      = 1,     //系统角色ID
                Deleted     = false, //系统管理员使用
                CreatedTime = DateTime.Now,
                CreatedBy   = 0,     //系统创建的都设置为0
                State       = 1,
            });

            await db.SysRoleMenuRelations.AddRangeAsync(relations);

            await SysMenuDao.AddAsync(sysMenu);

            var count = await SysMenuDao.SaveChangesAsync();

            return(count > 0 ? responseModel.Succeed(true) : responseModel.Fail(ResponseCode.Fail, "保存失败"));
        }