feat:基于furion搭建

This commit is contained in:
橙子
2023-04-12 22:30:42 +08:00
parent ccd39474c7
commit 5efdffcda8
631 changed files with 468 additions and 27264 deletions

View File

@@ -1,383 +0,0 @@
using Cike.EventBus.DistributedEvent;
using Hei.Captcha;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Cike.AutoWebApi.Setting;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Auth.JwtBearer.Authentication;
using Yi.Framework.Auth.JwtBearer.Authorization;
using Yi.Framework.Core.CurrentUsers;
using Yi.Framework.Core.Enums;
using Yi.Framework.Core.Exceptions;
using Yi.Framework.Ddd.Repositories;
using Yi.Framework.Ddd.Services;
using Yi.RBAC.Application.Contracts.Identity;
using Yi.RBAC.Application.Contracts.Identity.Dtos.Account;
using Yi.RBAC.Domain.Identity;
using Yi.RBAC.Domain.Identity.Dtos;
using Yi.RBAC.Domain.Identity.Entities;
using Yi.RBAC.Domain.Identity.Repositories;
using Yi.RBAC.Domain.Shared.Identity.ConstClasses;
using Yi.RBAC.Domain.Shared.Identity.Dtos;
using Yi.RBAC.Domain.Shared.Identity.Etos;
using System.Net.WebSockets;
using Yi.Framework.Uow;
using Yi.Framework.Caching;
using Yi.Framework.Sms.Aliyun;
using Microsoft.Extensions.Options;
using System.Text.RegularExpressions;
namespace Yi.RBAC.Application.Identity
{
[AppService]
public class AccountService : ApplicationService, IAutoApiService
{
[Autowired]
private JwtTokenManager _jwtTokenManager { get; set; }
[Autowired]
private IUserRepository _userRepository { get; set; }
[Autowired]
private ICurrentUser _currentUser { get; set; }
[Autowired]
private AccountManager _accountManager { get; set; }
[Autowired]
private IRepository<MenuEntity> _menuRepository { get; set; }
[Autowired]
private SecurityCodeHelper _securityCode { get; set; }
[Autowired]
private IDistributedEventBus _distributedEventBus { get; set; }
[Autowired]
private IUserService _userService { get; set; }
[Autowired]
private UserManager _userManager { get; set; }
[Autowired]
private IUnitOfWorkManager _unitOfWorkManager { get; set; }
[Autowired]
private IRepository<RoleEntity> _roleRepository { get; set; }
[Autowired]
private CacheManager _cacheManager { get; set; }
[Autowired]
private SmsAliyunManager _smsAliyunManager { get; set; }
[Autowired]
private IOptions<SmsAliyunOptions> _smsAliyunManagerOptions { get; set; }
/// <summary>
/// 效验图片登录验证码,无需和账号绑定
/// </summary>
private void ValidationImageCaptcha(LoginInputVo input)
{
//登录不想要验证码 ,不效验
return;
var value = _cacheManager.Get<string>($"Yi:Captcha:{input.Code}");
if (value is not null && value.Equals(input.Uuid))
{
return;
}
throw new UserFriendlyException("验证码错误");
}
/// <summary>
/// 效验电话验证码,需要与电话号码绑定
/// </summary>
private void ValidationPhoneCaptcha(RegisterDto input)
{
var value = _cacheManager.Get<string>($"Yi:Phone:{input.Phone}");
if (value is not null && value.Equals($"{input.Code}"))
{
//成功,需要清空
_cacheManager.Del($"Yi:Phone:{input.Phone}");
return;
}
throw new UserFriendlyException("验证码错误");
}
/// <summary>
/// 登录
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<object> PostLoginAsync(LoginInputVo input)
{
if (string.IsNullOrEmpty(input.Password) || string.IsNullOrEmpty(input.UserName))
{
throw new UserFriendlyException("请输入合理数据!");
}
//效验验证码
ValidationImageCaptcha(input);
UserEntity user = new();
//登录成功
await _accountManager.LoginValidationAsync(input.UserName, input.Password, x => user = x);
//获取用户信息
var userInfo = await _userRepository.GetUserAllInfoAsync(user.Id);
if (userInfo.RoleCodes.Count == 0)
{
throw new UserFriendlyException(UserConst.);
}
//这里抛出一个登录的事件
//不阻碍执行,无需等待
#pragma warning disable CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法
_distributedEventBus.PublishAsync(new LoginEventArgs
{
UserId = userInfo.User.Id,
UserName = user.UserName
});
#pragma warning restore CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法
//创建token
var token = _jwtTokenManager.CreateToken(_accountManager.UserInfoToClaim(userInfo));
return new { Token = token };
}
/// <summary>
/// 生成验证码
/// </summary>
/// <returns></returns>
[AllowAnonymous]
public CaptchaImageDto GetCaptchaImage()
{
var uuid = Guid.NewGuid();
var code = _securityCode.GetRandomEnDigitalText(4);
//将uuid与codeRedis缓存中心化保存起来登录根据uuid比对即可
//10分钟过期
_cacheManager.Set($"Yi:Captcha:{code}", uuid, new TimeSpan(0, 10, 0));
var imgbyte = _securityCode.GetEnDigitalCodeByte(code);
return new CaptchaImageDto { Img = imgbyte, Code = code, Uuid = uuid };
}
/// <summary>
/// 验证电话号码
/// </summary>
/// <param name="str_handset"></param>
private async Task ValidationPhone(string str_handset)
{
var res= Regex.IsMatch(str_handset, "^(0\\d{2,3}-?\\d{7,8}(-\\d{3,5}){0,1})|(((13[0-9])|(15([0-3]|[5-9]))|(18[0-9])|(17[0-9])|(14[0-9]))\\d{8})$");
if (res == false)
{
throw new UserFriendlyException("手机号码格式错误!请检查");
}
if (await _userRepository.IsAnyAsync(x => x.Phone.ToString() == str_handset))
{
throw new UserFriendlyException("该手机号已被注册!");
}
}
/// <summary>
/// 注册 手机验证码
/// </summary>
/// <returns></returns>
[AllowAnonymous]
public async Task<object> PostCaptchaPhone(PhoneCaptchaImageDto input)
{
await ValidationPhone(input.Phone);
var value = _cacheManager.Get<string>($"Yi:Phone:{input.Phone}");
//防止暴刷
if (value is not null)
{
throw new UserFriendlyException($"{input.Phone}已发送过验证码10分钟后可重试");
}
//生成一个4位数的验证码
//发送短信同时生成uuid
//key 电话号码 value:验证码+uuid
var code = _securityCode.GetRandomEnDigitalText(4);
var uuid = Guid.NewGuid();
//未开启短信验证默认8888
if (_smsAliyunManagerOptions.Value.EnableFeature)
{
await _smsAliyunManager.Send(input.Phone, code);
}
else
{
code = "8888";
}
_cacheManager.Set($"Yi:Phone:{input.Phone}", $"{code}", new TimeSpan(0, 10, 0));
return new { Uuid = uuid };
}
/// <summary>
/// 注册,需要验证码通过
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[AllowAnonymous]
public async Task<object> PostRegisterAsync(RegisterDto input)
{
if (input.UserName == UserConst.Admin)
{
throw new UserFriendlyException("用户名无效注册!");
}
if (input.UserName.Length < 2)
{
throw new UserFriendlyException("账号名需大于等于2位");
}
if (input.Password.Length < 6)
{
throw new UserFriendlyException("密码需大于等于6位");
}
//效验验证码,根据电话号码获取 value比对验证码已经uuid
ValidationPhoneCaptcha(input);
//输入的用户名与电话号码都不能在数据库中存在
UserEntity user = new();
var isExist = await _userRepository.IsAnyAsync(x =>
x.UserName == input.UserName
|| x.Phone == input.Phone);
if (isExist)
{
throw new UserFriendlyException("用户已存在,注册失败");
}
using (var uow = _unitOfWorkManager.CreateContext())
{
var newUser = new UserEntity(input.UserName, input.Password, input.Phone);
var entity = await _userRepository.InsertReturnEntityAsync(newUser);
//赋上一个初始角色
var roleRepository = _roleRepository;
var role = await roleRepository.GetFirstAsync(x => x.RoleCode == UserConst.GuestRoleCode);
if (role is not null)
{
await _userManager.GiveUserSetRoleAsync(new List<long> { entity.Id }, new List<long> { role.Id });
}
uow.Commit();
}
return true;
}
/// <summary>
/// 查询已登录的账户信息
/// </summary>
/// <returns></returns>
/// <exception cref="AuthException"></exception>
[Route("/api/account")]
[Authorize]
public async Task<UserRoleMenuDto> Get()
{
//通过鉴权jwt获取到用户的id
var userId = _currentUser.Id;
//此处从缓存中获取即可
//var data = _cacheManager.Get<UserRoleMenuDto>($"Yi:UserInfo:{userId}");
var data = await _userRepository.GetUserAllInfoAsync(userId);
//系统用户数据被重置,老前端访问重新授权
if (data is null)
{
throw new AuthException();
}
data.Menus.Clear();
return data;
}
/// <summary>
/// 获取当前登录用户的前端路由
/// </summary>
/// <returns></returns>
[Authorize]
public async Task<List<Vue3RouterDto>> GetVue3Router()
{
var userId = _currentUser.Id;
var data = await _userRepository.GetUserAllInfoAsync(userId);
var menus = data.Menus.ToList();
//为超级管理员直接给全部路由
if (UserConst.Admin.Equals(data.User.UserName))
{
menus = await _menuRepository.GetListAsync();
}
//将后端菜单转换成前端路由,组件级别需要过滤
List<Vue3RouterDto> routers = menus.Vue3RouterBuild();
return routers;
}
/// <summary>
/// 退出登录
/// </summary>
/// <returns></returns>
public Task<bool> PostLogout()
{
return Task.FromResult(true);
}
/// <summary>
/// 更新密码
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<bool> UpdatePasswordAsync(UpdatePasswordDto input)
{
if (input.OldPassword.Equals(input.NewPassword))
{
throw new UserFriendlyException("无效更新!输入的数据,新密码不能与老密码相同");
}
await _accountManager.UpdatePasswordAsync(_currentUser.Id, input.NewPassword, input.OldPassword);
return true;
}
/// <summary>
/// 重置密码
/// </summary>
/// <param name="userId"></param>
/// <param name="input"></param>
/// <returns></returns>
[HttpPut]
public async Task<bool> RestPasswordAsync(long userId, RestPasswordDto input)
{
if (!string.IsNullOrEmpty(input.Password))
{
throw new UserFriendlyException("重置密码不能为空!");
}
await _accountManager.RestPasswordAsync(userId, input.Password);
return true;
}
/// <summary>
/// 更新头像
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<bool> UpdateIconAsync(UpdateIconDto input)
{
var entity = await _userRepository.GetByIdAsync(_currentUser.Id);
entity.Icon = input.Icon;
await _userRepository.UpdateAsync(entity);
return true;
}
}
}

View File

@@ -1,51 +0,0 @@
using Yi.RBAC.Application.Contracts.Identity;
using Cike.AutoWebApi.Setting;
using Yi.RBAC.Application.Contracts.Identity.Dtos;
using Yi.RBAC.Domain.Identity.Entities;
using Yi.Framework.Ddd.Services;
using Yi.Framework.Ddd.Dtos;
using SqlSugar;
using Microsoft.AspNetCore.Mvc;
namespace Yi.RBAC.Application.Identity
{
/// <summary>
/// Dept服务实现
/// </summary>
[AppService]
public class DeptService : CrudAppService<DeptEntity, DeptGetOutputDto, DeptGetListOutputDto, long, DeptGetListInputVo, DeptCreateInputVo, DeptUpdateInputVo>,
IDeptService, IAutoApiService
{
/// <summary>
/// 通过角色id查询该角色全部部门
/// </summary>
/// <returns></returns>
//[Route("{roleId}")]
public async Task<List<DeptGetListOutputDto>> GetListRoleIdAsync([FromRoute]long roleId)
{
var entities= await _DbQueryable.Where(d => SqlFunc.Subqueryable<RoleDeptEntity>().Where(rd => rd.RoleId == roleId && d.Id==rd.DeptId).Any()).ToListAsync();
return await MapToGetListOutputDtosAsync(entities);
}
/// <summary>
/// 多查
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public override async Task<PagedResultDto<DeptGetListOutputDto>> GetListAsync(DeptGetListInputVo input)
{
RefAsync<int> total = 0;
var entities = await _DbQueryable
.WhereIF(!string.IsNullOrEmpty(input.DeptName), u => u.DeptName.Contains(input.DeptName!))
.WhereIF(input.State is not null, u => u.State == input.State)
.OrderBy(u => u.OrderNum, OrderByType.Asc)
.ToPageListAsync(input.PageNum, input.PageSize, total);
return new PagedResultDto<DeptGetListOutputDto>
{
Items = await MapToGetListOutputDtosAsync(entities),
Total = total
};
}
}
}

View File

@@ -1,44 +0,0 @@
using Yi.RBAC.Application.Contracts.Identity;
using Cike.AutoWebApi.Setting;
using Yi.RBAC.Application.Contracts.Identity.Dtos;
using Yi.RBAC.Domain.Identity.Entities;
using Yi.Framework.Ddd.Services;
using SqlSugar;
using Yi.Framework.Ddd.Dtos;
namespace Yi.RBAC.Application.Identity
{
/// <summary>
/// Menu服务实现
/// </summary>
[AppService]
public class MenuService : CrudAppService<MenuEntity, MenuGetOutputDto, MenuGetListOutputDto, long, MenuGetListInputVo, MenuCreateInputVo, MenuUpdateInputVo>,
IMenuService, IAutoApiService
{
public override async Task<PagedResultDto<MenuGetListOutputDto>> GetListAsync(MenuGetListInputVo input)
{
var entity = await MapToEntityAsync(input);
RefAsync<int> total = 0;
var entities = await _DbQueryable.WhereIF(!string.IsNullOrEmpty(input.MenuName), x => x.MenuName.Contains(input.MenuName!))
.WhereIF(input.State is not null, x => x.State == input.State)
.OrderByDescending(x=>x.OrderNum)
.ToPageListAsync(input.PageNum, input.PageSize, total);
return new PagedResultDto<MenuGetListOutputDto>(total, await MapToGetListOutputDtosAsync(entities));
}
/// <summary>
/// 查询当前角色的菜单
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public async Task<List<MenuGetListOutputDto>> GetListRoleIdAsync(long roleId)
{
var entities = await _DbQueryable.Where(m => SqlFunc.Subqueryable<RoleMenuEntity>().Where(rm => rm.RoleId == roleId && rm.MenuId == m.Id).Any()).ToListAsync();
return await MapToGetListOutputDtosAsync(entities);
}
}
}

View File

@@ -1,31 +0,0 @@
using Yi.RBAC.Application.Contracts.Identity;
using Cike.AutoWebApi.Setting;
using Yi.RBAC.Application.Contracts.Identity.Dtos;
using Yi.RBAC.Domain.Identity.Entities;
using Yi.Framework.Ddd.Services;
using Yi.Framework.Ddd.Dtos;
using SqlSugar;
using Yi.RBAC.Application.Contracts.Setting.Dtos;
namespace Yi.RBAC.Application.Identity
{
/// <summary>
/// Post服务实现
/// </summary>
[AppService]
public class PostService : CrudAppService<PostEntity, PostGetOutputDto, PostGetListOutputDto, long, PostGetListInputVo, PostCreateInputVo, PostUpdateInputVo>,
IPostService, IAutoApiService
{
public override async Task<PagedResultDto<PostGetListOutputDto>> GetListAsync(PostGetListInputVo input)
{
var entity = await MapToEntityAsync(input);
RefAsync<int> total = 0;
var entities = await _DbQueryable.WhereIF(!string.IsNullOrEmpty(input.PostName), x => x.PostName.Contains(input.PostName!))
.WhereIF(input.State is not null, x => x.State == input.State)
.ToPageListAsync(input.PageNum, input.PageSize, total);
return new PagedResultDto<PostGetListOutputDto>(total, await MapToGetListOutputDtosAsync(entities));
}
}
}

View File

@@ -1,106 +0,0 @@
using Yi.RBAC.Application.Contracts.Identity;
using Cike.AutoWebApi.Setting;
using Yi.RBAC.Application.Contracts.Identity.Dtos;
using Yi.RBAC.Domain.Identity.Entities;
using Yi.Framework.Ddd.Services;
using Yi.RBAC.Domain.Identity;
using Microsoft.AspNetCore.Identity;
using Yi.Framework.Uow;
using Yi.Framework.Ddd.Dtos;
using SqlSugar;
using Microsoft.AspNetCore.Mvc;
namespace Yi.RBAC.Application.Identity
{
/// <summary>
/// Role服务实现
/// </summary>
[AppService]
public class RoleService : CrudAppService<RoleEntity, RoleGetOutputDto, RoleGetListOutputDto, long, RoleGetListInputVo, RoleCreateInputVo, RoleUpdateInputVo>,
IRoleService, IAutoApiService
{
[Autowired]
private RoleManager _roleManager { get; set; }
[Autowired]
private IUnitOfWorkManager _unitOfWorkManager { get; set; }
public override async Task<PagedResultDto<RoleGetListOutputDto>> GetListAsync(RoleGetListInputVo input)
{
var entity = await MapToEntityAsync(input);
RefAsync<int> total = 0;
var entities = await _DbQueryable.WhereIF(!string.IsNullOrEmpty(input.RoleCode), x => x.RoleCode.Contains(input.RoleCode!))
.WhereIF(!string.IsNullOrEmpty(input.RoleName), x => x.RoleName.Contains(input.RoleName!))
.WhereIF(input.State is not null, x => x.State == input.State)
.ToPageListAsync(input.PageNum, input.PageSize, total);
return new PagedResultDto<RoleGetListOutputDto>(total, await MapToGetListOutputDtosAsync(entities));
}
/// <summary>
/// 添加角色
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public override async Task<RoleGetOutputDto> CreateAsync(RoleCreateInputVo input)
{
RoleGetOutputDto outputDto;
using (var uow = _unitOfWorkManager.CreateContext())
{
var entity = await MapToEntityAsync(input);
await _repository.InsertAsync(entity);
outputDto = await MapToGetOutputDtoAsync(entity);
await _roleManager.GiveRoleSetMenuAsync(new List<long> { entity.Id }, input.MenuIds);
uow.Commit();
}
return outputDto;
}
/// <summary>
/// 修改角色
/// </summary>
/// <param name="id"></param>
/// <param name="input"></param>
/// <returns></returns>
public override async Task<RoleGetOutputDto> UpdateAsync(long id, RoleUpdateInputVo input)
{
var dto = new RoleGetOutputDto();
using (var uow = _unitOfWorkManager.CreateContext())
{
var entity = await _repository.GetByIdAsync(id);
await MapToEntityAsync(input, entity);
await _repository.UpdateAsync(entity);
await _roleManager.GiveRoleSetMenuAsync(new List<long> { id }, input.MenuIds);
dto = await MapToGetOutputDtoAsync(entity);
uow.Commit();
}
return dto;
}
/// <summary>
/// 更新状态
/// </summary>
/// <param name="id"></param>
/// <param name="state"></param>
/// <returns></returns>
[Route("/api/role/{id}/{state}")]
public async Task<RoleGetOutputDto> UpdateStateAsync([FromRoute] long id, [FromRoute] bool state)
{
var entity = await _repository.GetByIdAsync(id);
if (entity is null)
{
throw new ApplicationException("角色未存在");
}
entity.State = state;
await _repository.UpdateAsync(entity);
return await MapToGetOutputDtoAsync(entity);
}
}
}

View File

@@ -1,192 +0,0 @@
using Yi.RBAC.Application.Contracts.Identity;
using Cike.AutoWebApi.Setting;
using Yi.RBAC.Application.Contracts.Identity.Dtos;
using Yi.RBAC.Domain.Identity.Entities;
using Yi.Framework.Ddd.Services;
using Yi.RBAC.Domain.Shared.Identity.ConstClasses;
using Yi.RBAC.Domain.Identity;
using Yi.Framework.Uow;
using Yi.Framework.Ddd.Dtos;
using Yi.RBAC.Domain.Identity.Repositories;
using SqlSugar;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Yi.Framework.Auth.JwtBearer.Authorization;
using Yi.RBAC.Application.Contracts.Identity.Dtos.User;
using Yi.Framework.Core.CurrentUsers;
using Yi.Framework.OperLogManager;
namespace Yi.RBAC.Application.Identity
{
/// <summary>
/// User服务实现
/// </summary>
[AppService]
public class UserService : CrudAppService<UserEntity, UserGetOutputDto, UserGetListOutputDto, long, UserGetListInputVo, UserCreateInputVo, UserUpdateInputVo>,
IUserService, IAutoApiService
{
[Autowired]
private UserManager _userManager { get; set; }
[Autowired]
private IUnitOfWorkManager _unitOfWorkManager { get; set; }
[Autowired]
private IUserRepository _userRepository { get; set; }
[Autowired]
private ICurrentUser _currentUser { get; set; }
/// <summary>
/// 查询用户
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public override async Task<PagedResultDto<UserGetListOutputDto>> GetListAsync(UserGetListInputVo input)
{
var entity = await MapToEntityAsync(input);
RefAsync<int> total = 0;
List<long>? ids = input.Ids?.Split(",").Select(x=>long.Parse(x)).ToList();
var outPut = await _DbQueryable.WhereIF(!string.IsNullOrEmpty(input.UserName), x => x.UserName.Contains(input.UserName!))
.WhereIF(input.Phone is not null, x => x.Phone.ToString()!.Contains(input.Phone.ToString()!))
.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name!.Contains(input.Name!))
.WhereIF(input.State is not null, x => x.State == input.State)
.WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime)
//这个为过滤当前部门,加入数据权限后,将由数据权限控制
.WhereIF(input.DeptId is not null, x => x.DeptId == input.DeptId)
.WhereIF(ids is not null,x=> ids.Contains(x.Id))
.LeftJoin<DeptEntity>((user, dept) => user.DeptId == dept.Id)
.Select((user, dept) => new UserGetListOutputDto(), true)
.ToPageListAsync(input.PageNum, input.PageSize, total);
var result = new PagedResultDto<UserGetListOutputDto>();
result.Items = outPut;
result.Total = total;
return result;
}
/// <summary>
/// 添加用户
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
[OperLog("添加用户", OperEnum.Insert)]
public async override Task<UserGetOutputDto> CreateAsync(UserCreateInputVo input)
{
if (string.IsNullOrEmpty(input.Password))
{
throw new UserFriendlyException(UserConst._密码为空);
}
if (await _repository.IsAnyAsync(u => input.UserName.Equals(u.UserName)))
{
throw new UserFriendlyException(UserConst._用户存在);
}
var entities = await MapToEntityAsync(input);
entities.BuildPassword();
using (var uow = _unitOfWorkManager.CreateContext())
{
var returnEntity = await _repository.InsertReturnEntityAsync(entities);
await _userManager.GiveUserSetRoleAsync(new List<long> { returnEntity.Id }, input.RoleIds);
await _userManager.GiveUserSetPostAsync(new List<long> { returnEntity.Id }, input.PostIds);
uow.Commit();
var result = await MapToGetOutputDtoAsync(returnEntity);
return result;
}
}
/// <summary>
/// 单查
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public override async Task<UserGetOutputDto> GetAsync(long id)
{
//使用导航树形查询
var entity = await _DbQueryable.Includes(u => u.Roles).Includes(u => u.Posts).Includes(u => u.Dept).InSingleAsync(id);
return await MapToGetOutputDtoAsync(entity);
}
/// <summary>
/// 更新用户
/// </summary>
/// <param name="id"></param>
/// <param name="input"></param>
/// <returns></returns>
[OperLog("更新用户", OperEnum.Update)]
public async override Task<UserGetOutputDto> UpdateAsync(long id, UserUpdateInputVo input)
{
if (await _repository.IsAnyAsync(u => input.UserName!.Equals(u.UserName) && !id.Equals(u.Id)))
{
throw new UserFriendlyException("用户已经在,更新失败");
}
var entity = await _repository.GetByIdAsync(id);
//更新密码,特殊处理
if (input.Password is not null)
{
entity.Password = input.Password;
entity.BuildPassword();
}
await MapToEntityAsync(input, entity);
using (var uow = _unitOfWorkManager.CreateContext())
{
var res1 = await _repository.UpdateAsync(entity);
await _userManager.GiveUserSetRoleAsync(new List<long> { id }, input.RoleIds);
await _userManager.GiveUserSetPostAsync(new List<long> { id }, input.PostIds);
uow.Commit();
}
return await MapToGetOutputDtoAsync(entity);
}
/// <summary>
/// 更新个人中心
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[OperLog("更新个人信息", OperEnum.Update)]
public async Task<UserGetOutputDto> UpdateProfileAsync(ProfileUpdateInputVo input)
{
var entity = await _repository.GetByIdAsync(_currentUser.Id);
_mapper.Map(input, entity);
await _repository.UpdateAsync(entity);
var dto = _mapper.Map<UserGetOutputDto>(entity);
return dto;
}
/// <summary>
/// 更新状态
/// </summary>
/// <param name="id"></param>
/// <param name="state"></param>
/// <returns></returns>
[Route("/api/user/{id}/{state}")]
[OperLog("更新用户状态", OperEnum.Update)]
public async Task<UserGetOutputDto> UpdateStateAsync([FromRoute] long id, [FromRoute] bool state)
{
var entity = await _repository.GetByIdAsync(id);
if (entity is null)
{
throw new ApplicationException("用户未存在");
}
entity.State = state;
await _repository.UpdateAsync(entity);
return await MapToGetOutputDtoAsync(entity);
}
[OperLog("删除用户", OperEnum.Delete)]
public override Task<bool> DeleteAsync(string id)
{
return base.DeleteAsync(id);
}
}
}

View File

@@ -1,39 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Cike.AutoWebApi.Setting;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Ddd.Dtos;
using Yi.Framework.Ddd.Services;
using Yi.RBAC.Application.Contracts.Logs.Dtos.LoginLog;
using Yi.RBAC.Application.Contracts.Setting.Dtos;
using Yi.RBAC.Domain.Logs.Entities;
namespace Yi.RBAC.Application.Logs
{
[AppService]
public class LoginLogService : CrudAppService<LoginLogEntity, LoginLogGetListOutputDto, long, LoginLogGetListInputVo>, IAutoApiService
{
public override async Task<PagedResultDto<LoginLogGetListOutputDto>> GetListAsync(LoginLogGetListInputVo input)
{
var entity = await MapToEntityAsync(input);
RefAsync<int> total = 0;
var entities = await _DbQueryable.WhereIF(!string.IsNullOrEmpty(input.LoginIp), x => x.LoginIp.Contains(input.LoginIp!))
.WhereIF(!string.IsNullOrEmpty(input.LoginUser), x => x.LoginUser!.Contains(input.LoginUser!))
.WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime)
.ToPageListAsync(input.PageNum, input.PageSize, total);
return new PagedResultDto<LoginLogGetListOutputDto>(total, await MapToGetListOutputDtosAsync(entities));
}
[NonAction]
public override Task<LoginLogGetListOutputDto> UpdateAsync(long id, LoginLogGetListOutputDto input)
{
return base.UpdateAsync(id, input);
}
}
}

View File

@@ -1,40 +0,0 @@
using Yi.RBAC.Application.Contracts.Setting;
using Cike.AutoWebApi.Setting;
using Yi.RBAC.Application.Contracts.Setting.Dtos;
using Yi.RBAC.Domain.Setting.Entities;
using Yi.Framework.Ddd.Services;
using Yi.Framework.Ddd.Dtos;
using SqlSugar;
using Yi.RBAC.Application.Contracts.Identity.Dtos;
using Yi.RBAC.Domain.Identity.Entities;
using Microsoft.AspNetCore.Mvc;
namespace Yi.RBAC.Application.Setting
{
/// <summary>
/// Config服务实现
/// </summary>
[AppService]
public class ConfigService : CrudAppService<ConfigEntity, ConfigGetOutputDto, ConfigGetListOutputDto, long, ConfigGetListInputVo, ConfigCreateInputVo, ConfigUpdateInputVo>,
IConfigService, IAutoApiService
{
/// <summary>
/// 多查
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public override async Task<PagedResultDto<ConfigGetListOutputDto>> GetListAsync(ConfigGetListInputVo input)
{
var entity = await MapToEntityAsync(input);
RefAsync<int> total = 0;
var entities = await _DbQueryable.WhereIF(!string.IsNullOrEmpty(input.ConfigKey), x => x.ConfigKey.Contains(input.ConfigKey!))
.WhereIF(!string.IsNullOrEmpty(input.ConfigName), x => x.ConfigName!.Contains(input.ConfigName!))
.WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime)
.ToPageListAsync(input.PageNum, input.PageSize, total);
return new PagedResultDto<ConfigGetListOutputDto>(total, await MapToGetListOutputDtosAsync(entities));
}
}
}

View File

@@ -1,34 +0,0 @@
using Cike.AutoWebApi.Setting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Ddd.Services;
namespace Yi.RBAC.Application
{
class Test01
{
public string Name { get; set; }
public bool State { get; set; }
}
class Test02
{
public string Name { get; set; }
}
public class TestService : ApplicationService, IAutoApiService
{
public void Test()
{
var t001 = new Test02 { Name = "121233" };
var t002 = new Test01 { Name = "123", State = true };
var entity= _mapper.Map(t001, t002);
}
}
}

View File

@@ -1,25 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<DocumentationFile>./$(AssemblyName)SwaggerDoc.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\GlobalUsings.cs" Link="Properties\GlobalUsings.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\framework\Yi.Framework.Auth.JwtBearer\Yi.Framework.Auth.JwtBearer.csproj" />
<ProjectReference Include="..\..\..\framework\Yi.Framework.Uow\Yi.Framework.Uow.csproj" />
<ProjectReference Include="..\Yi.RBAC.Application.Contracts\Yi.RBAC.Application.Contracts.csproj" />
<ProjectReference Include="..\Yi.RBAC.Domain\Yi.RBAC.Domain.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="Yi.RBAC.ApplicationSwaggerDoc.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@@ -1,216 +0,0 @@
<?xml version="1.0"?>
<doc>
<assembly>
<name>Yi.RBAC.Application</name>
</assembly>
<members>
<member name="M:Yi.RBAC.Application.Identity.AccountService.ValidationImageCaptcha(Yi.RBAC.Application.Contracts.Identity.Dtos.Account.LoginInputVo)">
<summary>
效验图片登录验证码,无需和账号绑定
</summary>
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.ValidationPhoneCaptcha(Yi.RBAC.Application.Contracts.Identity.Dtos.Account.RegisterDto)">
<summary>
效验电话验证码,需要与电话号码绑定
</summary>
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.PostLoginAsync(Yi.RBAC.Application.Contracts.Identity.Dtos.Account.LoginInputVo)">
<summary>
登录
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.GetCaptchaImage">
<summary>
生成验证码
</summary>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.ValidationPhone(System.String)">
<summary>
验证电话号码
</summary>
<param name="str_handset"></param>
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.PostCaptchaPhone(Yi.RBAC.Application.Contracts.Identity.Dtos.Account.PhoneCaptchaImageDto)">
<summary>
注册 手机验证码
</summary>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.PostRegisterAsync(Yi.RBAC.Application.Contracts.Identity.Dtos.Account.RegisterDto)">
<summary>
注册,需要验证码通过
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.Get">
<summary>
查询已登录的账户信息
</summary>
<returns></returns>
<exception cref="T:Yi.Framework.Core.Exceptions.AuthException"></exception>
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.GetVue3Router">
<summary>
获取当前登录用户的前端路由
</summary>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.PostLogout">
<summary>
退出登录
</summary>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.UpdatePasswordAsync(Yi.RBAC.Application.Contracts.Identity.Dtos.Account.UpdatePasswordDto)">
<summary>
更新密码
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.RestPasswordAsync(System.Int64,Yi.RBAC.Application.Contracts.Identity.Dtos.Account.RestPasswordDto)">
<summary>
重置密码
</summary>
<param name="userId"></param>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.AccountService.UpdateIconAsync(Yi.RBAC.Application.Contracts.Identity.Dtos.Account.UpdateIconDto)">
<summary>
更新头像
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="T:Yi.RBAC.Application.Identity.DeptService">
<summary>
Dept服务实现
</summary>
</member>
<member name="M:Yi.RBAC.Application.Identity.DeptService.GetListRoleIdAsync(System.Int64)">
<summary>
通过角色id查询该角色全部部门
</summary>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.DeptService.GetListAsync(Yi.RBAC.Application.Contracts.Identity.Dtos.DeptGetListInputVo)">
<summary>
多查
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="T:Yi.RBAC.Application.Identity.MenuService">
<summary>
Menu服务实现
</summary>
</member>
<member name="M:Yi.RBAC.Application.Identity.MenuService.GetListRoleIdAsync(System.Int64)">
<summary>
查询当前角色的菜单
</summary>
<param name="roleId"></param>
<returns></returns>
</member>
<member name="T:Yi.RBAC.Application.Identity.PostService">
<summary>
Post服务实现
</summary>
</member>
<member name="T:Yi.RBAC.Application.Identity.RoleService">
<summary>
Role服务实现
</summary>
</member>
<member name="M:Yi.RBAC.Application.Identity.RoleService.CreateAsync(Yi.RBAC.Application.Contracts.Identity.Dtos.RoleCreateInputVo)">
<summary>
添加角色
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.RoleService.UpdateAsync(System.Int64,Yi.RBAC.Application.Contracts.Identity.Dtos.RoleUpdateInputVo)">
<summary>
修改角色
</summary>
<param name="id"></param>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.RoleService.UpdateStateAsync(System.Int64,System.Boolean)">
<summary>
更新状态
</summary>
<param name="id"></param>
<param name="state"></param>
<returns></returns>
</member>
<member name="T:Yi.RBAC.Application.Identity.UserService">
<summary>
User服务实现
</summary>
</member>
<member name="M:Yi.RBAC.Application.Identity.UserService.GetListAsync(Yi.RBAC.Application.Contracts.Identity.Dtos.UserGetListInputVo)">
<summary>
查询用户
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.UserService.CreateAsync(Yi.RBAC.Application.Contracts.Identity.Dtos.UserCreateInputVo)">
<summary>
添加用户
</summary>
<param name="input"></param>
<returns></returns>
<exception cref="T:Yi.Framework.Core.Exceptions.UserFriendlyException"></exception>
</member>
<member name="M:Yi.RBAC.Application.Identity.UserService.GetAsync(System.Int64)">
<summary>
单查
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.UserService.UpdateAsync(System.Int64,Yi.RBAC.Application.Contracts.Identity.Dtos.UserUpdateInputVo)">
<summary>
更新用户
</summary>
<param name="id"></param>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.UserService.UpdateProfileAsync(Yi.RBAC.Application.Contracts.Identity.Dtos.User.ProfileUpdateInputVo)">
<summary>
更新个人中心
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Yi.RBAC.Application.Identity.UserService.UpdateStateAsync(System.Int64,System.Boolean)">
<summary>
更新状态
</summary>
<param name="id"></param>
<param name="state"></param>
<returns></returns>
</member>
<member name="T:Yi.RBAC.Application.Setting.ConfigService">
<summary>
Config服务实现
</summary>
</member>
<member name="M:Yi.RBAC.Application.Setting.ConfigService.GetListAsync(Yi.RBAC.Application.Contracts.Setting.Dtos.ConfigGetListInputVo)">
<summary>
多查
</summary>
<param name="input"></param>
<returns></returns>
</member>
</members>
</doc>

View File

@@ -1,33 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using StartupModules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.RBAC.Application.Contracts;
using Yi.Framework.Auth.JwtBearer;
using Yi.Framework.Core.Attributes;
using Yi.Framework.Data;
using Yi.Framework.Ddd;
using Yi.RBAC.Domain;
namespace Yi.RBAC.Application
{
[DependsOn(
typeof(YiRBACApplicationContractsModule),
typeof(YiRBACDomainModule),
typeof(YiFrameworkAuthJwtBearerModule)
)]
public class YiRBACApplicationModule : IStartupModule
{
public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context)
{
}
public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context)
{
}
}
}