|
|
|
|
using ATS.NonCustodial.Application.Base;
|
|
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.AppDictionaries;
|
|
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.AppDictionaries.Output;
|
|
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.Auth.Output;
|
|
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.Menu.Output;
|
|
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.Role.Output;
|
|
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.User;
|
|
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.User.Input;
|
|
|
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.User.Output;
|
|
|
|
|
using ATS.NonCustodial.Domain.Entities.Admins;
|
|
|
|
|
using ATS.NonCustodial.Domain.Shared.AggRootEntities.Dtos;
|
|
|
|
|
using ATS.NonCustodial.Domain.Shared.OrmRepositories.Basic.EfCore;
|
|
|
|
|
using ATS.NonCustodial.DynamicApi;
|
|
|
|
|
using ATS.NonCustodial.DynamicApi.Attributes;
|
|
|
|
|
using ATS.NonCustodial.Shared.Common.Attributes;
|
|
|
|
|
using ATS.NonCustodial.Shared.Common.Constants;
|
|
|
|
|
using ATS.NonCustodial.Shared.Common.Dtos;
|
|
|
|
|
using ATS.NonCustodial.Shared.Common.Dtos.Query;
|
|
|
|
|
using ATS.NonCustodial.Shared.Common.Enums;
|
|
|
|
|
using ATS.NonCustodial.Shared.Common.UnifiedResults;
|
|
|
|
|
using ATS.NonCustodial.Shared.Configurations.Options;
|
|
|
|
|
using ATS.NonCustodial.Shared.Extensions;
|
|
|
|
|
using ATS.NonCustodial.Shared.Helpers;
|
|
|
|
|
using ATS.NonCustodial.Shared.Helpers.Core.Hash;
|
|
|
|
|
using ATS.NonCustodial.Shared.Helpers.Core.Security;
|
|
|
|
|
using AutoMapper.QueryableExtensions;
|
|
|
|
|
using Castle.Components.DictionaryAdapter;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Yitter.IdGenerator;
|
|
|
|
|
|
|
|
|
|
namespace ATS.NonCustodial.Application.Impl.Admins
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 用户服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// Author:mxg
|
|
|
|
|
/// CreatedTimed:2022-05-15 10:08 PM
|
|
|
|
|
[DynamicApi(Area = "admin")]
|
|
|
|
|
public class UserService : AdminAppServiceBase, IUserService, IDynamicApi
|
|
|
|
|
{
|
|
|
|
|
#region Identity
|
|
|
|
|
|
|
|
|
|
private readonly IEfRepository<AppUser?, long> _userRepository;
|
|
|
|
|
private readonly IEfRepository<AppUserRole?, long> _userRoleRepository;
|
|
|
|
|
private readonly IEfRepository<AppApi?, long> _apiRepository;
|
|
|
|
|
private readonly IEfRepository<AppRole?, long> _roleRepository;
|
|
|
|
|
private readonly IEfRepository<AppPermissionApi?, long> _permissionApiRepository;
|
|
|
|
|
private readonly IEfRepository<AppRolePermission?, long> _rolePermissionRepository;
|
|
|
|
|
private readonly IEfRepository<App_Menu?, long> _MenuRepository;
|
|
|
|
|
private readonly IAppDictionaryService _appDictionaryService;
|
|
|
|
|
|
|
|
|
|
public UserService(
|
|
|
|
|
IEfRepository<AppUser?, long> userRepository,
|
|
|
|
|
IEfRepository<AppUserRole?, long> userRoleRepository,
|
|
|
|
|
IEfRepository<AppApi?, long> apiRepository,
|
|
|
|
|
IEfRepository<AppRole?, long> roleRepository,
|
|
|
|
|
IEfRepository<AppPermissionApi?, long> permissionApiRepository,
|
|
|
|
|
IEfRepository<AppRolePermission?, long> rolePermissionRepository,
|
|
|
|
|
IEfRepository<App_Menu?, long> MenuRepository,
|
|
|
|
|
IAppDictionaryService appDictionaryService
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
_userRepository = userRepository;
|
|
|
|
|
_userRoleRepository = userRoleRepository;
|
|
|
|
|
_apiRepository = apiRepository;
|
|
|
|
|
_roleRepository = roleRepository;
|
|
|
|
|
_permissionApiRepository = permissionApiRepository;
|
|
|
|
|
_rolePermissionRepository = rolePermissionRepository;
|
|
|
|
|
_appDictionaryService = appDictionaryService;
|
|
|
|
|
_MenuRepository = MenuRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Identity
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询用户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IResultOutput> GetAsync(long id)
|
|
|
|
|
{
|
|
|
|
|
var userWithRoles = await (from u in _userRepository.AsQueryable(false, true).Where(w => w.Id == id)
|
|
|
|
|
join ur in _userRoleRepository.AsQueryable(false, true) on u.Id equals ur.UserId
|
|
|
|
|
select new { u, ur }).ToListAsync();
|
|
|
|
|
|
|
|
|
|
var roles = await _roleRepository
|
|
|
|
|
.AsQueryable(false, true)
|
|
|
|
|
.Select(a => new { a.Id, a.Name }).ToListAsync();
|
|
|
|
|
|
|
|
|
|
var rtn = new
|
|
|
|
|
{
|
|
|
|
|
Form = Mapper.Map<UserGetOutput>(userWithRoles.FirstOrDefault().u),
|
|
|
|
|
Select = new { roles }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
rtn.Form.RoleIds = userWithRoles.Select(w => w.ur.RoleId).ToArray();
|
|
|
|
|
|
|
|
|
|
return ResultOutput.Ok(rtn);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询角色选中的用户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IResultOutput> GetuserroleAsync(long id)
|
|
|
|
|
{
|
|
|
|
|
var userrole = await _userRoleRepository.AsQueryable(false, true).Where(q => q.RoleId == id).Select(q => q.UserId).ToListAsync();
|
|
|
|
|
return ResultOutput.Ok(userrole);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询当前用户角色权限菜单
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IResultOutput> GetcurrentsAsync()
|
|
|
|
|
{
|
|
|
|
|
var rtnlist = new List<dynamic>();
|
|
|
|
|
//查找当前用户角色权限菜单
|
|
|
|
|
//var usermenulist = await (from u in _userRepository.AsQueryable(false, true).Where(w => w.Id == User.Id)
|
|
|
|
|
// join ur in _userRoleRepository.AsQueryable(false, true) on u.Id equals ur.UserId
|
|
|
|
|
// join urp in _rolePermissionRepository.AsQueryable(false,true) on ur.RoleId equals urp.RoleId
|
|
|
|
|
// join urpm in _MenuRepository.AsQueryable(false, true) on urp.PermissionId equals urpm.Id
|
|
|
|
|
// select new {urpm}).ToListAsync();
|
|
|
|
|
var usermenulis = await _MenuRepository.AsQueryable(false, true).ToListAsync();
|
|
|
|
|
var menulist = Mapper.Map<List<MenuListOutput>>(usermenulis);
|
|
|
|
|
foreach (var item in menulist.Distinct().Where(q => q.pid == 0 || q.pid == null).OrderBy(q => q.sort).ToList())
|
|
|
|
|
{
|
|
|
|
|
rtnlist.Add(new
|
|
|
|
|
{
|
|
|
|
|
Id = item.Id,
|
|
|
|
|
name = item.menuName,
|
|
|
|
|
route = item.menuUrl,
|
|
|
|
|
icon = item.icon,
|
|
|
|
|
iconName = item.iconName,
|
|
|
|
|
Sublevel = menulist.Where(q => q.pid == item.Id).ToList().OrderBy(q => q.sort).Select(q => new { q.Id, name = q.menuName, route = q.menuUrl }).ToList()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return ResultOutput.Ok(rtnlist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询当前用户角色权限菜单
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IResultOutput> GetcurrentAsync()
|
|
|
|
|
{
|
|
|
|
|
var rtnlist = new List<dynamic>();
|
|
|
|
|
//查找当前用户角色权限菜单
|
|
|
|
|
var usermenulist = await (from ur in _userRoleRepository.AsQueryable(false, true).Where(q => q.UserId == User.Id)
|
|
|
|
|
join urp in _rolePermissionRepository.AsQueryable(false, true) on ur.RoleId equals urp.RoleId
|
|
|
|
|
join urpm in _MenuRepository.AsQueryable(false, true) on urp.PermissionId equals urpm.Id
|
|
|
|
|
select new App_Menu
|
|
|
|
|
{
|
|
|
|
|
Id = urpm.Id,
|
|
|
|
|
menuName = urpm.menuName,
|
|
|
|
|
icon = urpm.icon,
|
|
|
|
|
iconName = urpm.iconName,
|
|
|
|
|
pid = urpm.pid,
|
|
|
|
|
sort = urpm.sort,
|
|
|
|
|
route = urpm.route,
|
|
|
|
|
menuUrl = urpm.menuUrl
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
var menulist = Mapper.Map<List<MenuListOutput>>(usermenulist);
|
|
|
|
|
if (User.Name.Contains("aks"))
|
|
|
|
|
{
|
|
|
|
|
var list = await _MenuRepository.AsQueryable(false, true).ToListAsync();
|
|
|
|
|
menulist = Mapper.Map<List<MenuListOutput>>(list);
|
|
|
|
|
}
|
|
|
|
|
menulist = menulist.Where((x, i) => menulist.FindIndex(s => s.Id == x.Id) == i).ToList();
|
|
|
|
|
foreach (var item in menulist.Distinct().Where((q, x) => q.pid == 0 || q.pid == null).OrderBy(q => q.sort).ToList())
|
|
|
|
|
{
|
|
|
|
|
rtnlist.Add(new
|
|
|
|
|
{
|
|
|
|
|
Id = item.Id,
|
|
|
|
|
name = item.menuName,
|
|
|
|
|
route = item.menuUrl,
|
|
|
|
|
icon = item.icon,
|
|
|
|
|
routes = item.route,
|
|
|
|
|
iconName = item.iconName,
|
|
|
|
|
Sublevel = menulist.Distinct().Where(q => q.pid == item.Id).ToList().OrderBy(q => q.sort).Select(q => new { q.Id, name = q.menuName, route = q.menuUrl, routes = q.route }).ToList()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return ResultOutput.Ok(rtnlist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询分页
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IResultOutput> GetPageAsync(UserGetPageDto input)
|
|
|
|
|
{
|
|
|
|
|
var express = GetExpression(input, _userRepository.AsQueryable(false, true).Where(q => !q.UserName.Contains("aks")));
|
|
|
|
|
var pageData = await base.GetPageAsync<AppUser, UserGetPageDto, UserListOutput>(input, express);
|
|
|
|
|
|
|
|
|
|
var userIds = pageData.Data.Select(w => w.Id).ToList();
|
|
|
|
|
//查询角色
|
|
|
|
|
var userRoles = await (from uR in _userRoleRepository.AsQueryable(false, true).Where(w => userIds.Contains(w.UserId))
|
|
|
|
|
join r in _roleRepository.AsQueryable(false, true) on uR.RoleId equals r.Id
|
|
|
|
|
select new
|
|
|
|
|
{
|
|
|
|
|
r.Name,
|
|
|
|
|
uR.UserId
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
//查询职位
|
|
|
|
|
var positionList = await _appDictionaryService.GetListNoApiAsync("job_position");
|
|
|
|
|
|
|
|
|
|
foreach (var userList in pageData.Data)
|
|
|
|
|
{
|
|
|
|
|
userList.RoleNames = userRoles
|
|
|
|
|
.Where(w => w.UserId == userList.Id)
|
|
|
|
|
.Select(w => w.Name)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
userList.PositionName = positionList
|
|
|
|
|
.FirstOrDefault()
|
|
|
|
|
?.Dictionaries!
|
|
|
|
|
.FirstOrDefault(w => w.Id == userList.PositionId)
|
|
|
|
|
?.Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultOutput.Ok(pageData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询登录用户信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<ResultOutput<AuthLoginOutput>> GetLoginUserAsync(long? id)
|
|
|
|
|
{
|
|
|
|
|
var output = new ResultOutput<AuthLoginOutput>();
|
|
|
|
|
var entityDto = Mapper.Map<AppUser, AuthLoginOutput>(await _userRepository.FindAsync(id!.Value));
|
|
|
|
|
return output.Ok(entityDto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询下拉数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IResultOutput> GetSelectAsync()
|
|
|
|
|
{
|
|
|
|
|
var roles = await _roleRepository
|
|
|
|
|
.AsQueryable(false, true)
|
|
|
|
|
.Select(a => new { a.Id, a.Name })
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
return ResultOutput.Ok(new { Select = new { roles } });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据用户Id获取用户列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<List<AuthLoginOutput>> GetAllByConditionAsync(BatchIdsInput input)
|
|
|
|
|
{
|
|
|
|
|
var data = await _userRepository.AsQueryable(false, true)
|
|
|
|
|
.Where(w => input.Ids.Contains(w.Id))
|
|
|
|
|
.ProjectTo<AuthLoginOutput>(Mapper.ConfigurationProvider)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
//查询职位
|
|
|
|
|
var positionList = await _appDictionaryService.GetListNoApiAsync("job_position");
|
|
|
|
|
foreach (var userList in data)
|
|
|
|
|
{
|
|
|
|
|
userList.PositionName = positionList
|
|
|
|
|
.FirstOrDefault()
|
|
|
|
|
?.Dictionaries!
|
|
|
|
|
.FirstOrDefault(w => w.Id == userList.PositionId)
|
|
|
|
|
?.Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据条件获取用户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<List<AuthLoginOutput>> GetAllByConditionAsync(CmShopTListSearchDto<SearchUserEnum, string> input)
|
|
|
|
|
{
|
|
|
|
|
if (!input.Content.Any()) return new List<AuthLoginOutput>();
|
|
|
|
|
|
|
|
|
|
var data = await _userRepository.AsQueryable(false, true)
|
|
|
|
|
.WhereIf(input.SearchType == SearchUserEnum.IdCard, w => input.Content.Contains(w.IdCard))
|
|
|
|
|
.WhereIf(input.SearchType == SearchUserEnum.Phone, w => input.Content.Contains(w.Phone))
|
|
|
|
|
.ProjectTo<AuthLoginOutput>(Mapper.ConfigurationProvider)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询用户基本信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IResultOutput> GetBasicAsync()
|
|
|
|
|
{
|
|
|
|
|
if (!(User?.Id > 0)) return ResultOutput.NotOk("未登录!");
|
|
|
|
|
|
|
|
|
|
var userUpdateBasic = await base.GetAsync<AppUser, UserUpdateBasicInput, long>(_userRepository, User.Id);
|
|
|
|
|
|
|
|
|
|
//查询角色
|
|
|
|
|
var userRoles = await (from uR in _userRoleRepository.AsQueryable(false, true).Where(w => w.UserId == userUpdateBasic.Id)
|
|
|
|
|
join r in _roleRepository.AsQueryable(false, true) on uR.RoleId equals r.Id
|
|
|
|
|
select new
|
|
|
|
|
{
|
|
|
|
|
r.Name,
|
|
|
|
|
uR.UserId
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
//查询职位
|
|
|
|
|
var positionList = await _appDictionaryService.GetListNoApiAsync("job_position");
|
|
|
|
|
|
|
|
|
|
userUpdateBasic.RoleNames = userRoles
|
|
|
|
|
.Select(w => w.Name)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
userUpdateBasic.PositionName = positionList
|
|
|
|
|
.FirstOrDefault()
|
|
|
|
|
?.Dictionaries!
|
|
|
|
|
.FirstOrDefault(w => w.Id == userUpdateBasic.PositionId)
|
|
|
|
|
?.Name;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResultOutput.Ok(userUpdateBasic);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询用户权限信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IList<UserPermissionsOutput>> GetPermissionsAsync()
|
|
|
|
|
{
|
|
|
|
|
var key = string.Format(CacheKey.userPermissions, User.Id);
|
|
|
|
|
|
|
|
|
|
var result = await Cache.GetOrSetAsync(key, async () =>
|
|
|
|
|
{
|
|
|
|
|
var result = await (from api in _apiRepository.AsQueryable(false, true)
|
|
|
|
|
join pApi in _permissionApiRepository.AsQueryable(false, true) on api.Id equals pApi.ApiId
|
|
|
|
|
join rp in _rolePermissionRepository.AsQueryable(false, true) on pApi.PermissionId equals rp.PermissionId
|
|
|
|
|
join ur in _userRoleRepository.AsQueryable(false, true) on new { a = rp.RoleId, b = User.Id } equals new { a = ur.RoleId, b = ur.UserId }
|
|
|
|
|
select new UserPermissionsOutput()
|
|
|
|
|
{
|
|
|
|
|
HttpMethods = api.HttpMethods,
|
|
|
|
|
Path = api.Path
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
return result;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 新增用户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IResultOutput> AddAsync(UserAddInput input)
|
|
|
|
|
{
|
|
|
|
|
//if (await _userRepository.AnyAsync(x => x.ReceiveName == input.ReceiveName)) return ResultOutput.NotOk("账号已经存在");
|
|
|
|
|
if (await _userRepository.AnyAsync(w => w.UserName == input.UserName)) return ResultOutput.NotOk("姓名已经存在");
|
|
|
|
|
|
|
|
|
|
var entity = Mapper.Map<AppUser>(input);
|
|
|
|
|
entity.Id = YitIdHelper.NextId();
|
|
|
|
|
entity.PasswordSalt = InfraHelper.Security.GenerateRandomCode(5);
|
|
|
|
|
entity.Password = InfraHelper.Hash.GetHashedString(HashTypeEnum.Md5, input.Password);
|
|
|
|
|
entity.ChatPersonType = ChatPersonTypeEnum.Supervisor;
|
|
|
|
|
|
|
|
|
|
//添加默认头像
|
|
|
|
|
entity.Avatar = "/avatar/default.png";
|
|
|
|
|
//添加用户
|
|
|
|
|
var user = await _userRepository.InsertAsync(entity);
|
|
|
|
|
|
|
|
|
|
if (!(user!.Id > 0)) return ResultOutput.NotOk();
|
|
|
|
|
|
|
|
|
|
//添加角色
|
|
|
|
|
if (input.RoleIds == null || !input.RoleIds.Any()) return ResultOutput.Ok();
|
|
|
|
|
|
|
|
|
|
var roles = input.RoleIds.Select(a => new AppUserRole
|
|
|
|
|
{
|
|
|
|
|
UserId = user!.Id,
|
|
|
|
|
RoleId = a
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await _userRoleRepository.InsertAsync(roles);
|
|
|
|
|
|
|
|
|
|
return ResultOutput.Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 新增用户角色
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IResultOutput> AdduserroleAsync(List<UserRoleAddInput> inputlist)
|
|
|
|
|
{
|
|
|
|
|
//当前用户角色
|
|
|
|
|
var userRole = await IsAdmin(null);
|
|
|
|
|
if (inputlist == null) return ResultOutput.Ok();
|
|
|
|
|
else
|
|
|
|
|
await _userRoleRepository.DeleteAsync(q => q.RoleId == inputlist[0].RoleId);//删除所有用户角色
|
|
|
|
|
|
|
|
|
|
foreach (var item in inputlist)
|
|
|
|
|
{
|
|
|
|
|
item.Id = YitIdHelper.NextId();
|
|
|
|
|
}
|
|
|
|
|
await _userRoleRepository.InsertAsync(Mapper.Map<List<UserRoleAddInput>, List<AppUserRole>>(inputlist));
|
|
|
|
|
return ResultOutput.Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 批量添加用户(案件管理添加)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="userAddInputs"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<List<GetUserInfoByKeywordDto>> BatchAddAsync(List<SupervisedPersonAddInput> userAddInputs)
|
|
|
|
|
{
|
|
|
|
|
List<AppUser> addAppUsers = new List<AppUser>();
|
|
|
|
|
List<AppUserRole> appUserRoles = new List<AppUserRole>();
|
|
|
|
|
|
|
|
|
|
foreach (var input in userAddInputs)
|
|
|
|
|
{
|
|
|
|
|
if (input.Password.IsNull()) input.Password = "Mr@123456";
|
|
|
|
|
var entity = Mapper.Map<AppUser>(input);
|
|
|
|
|
entity.Id = input.Id/*YitIdHelper.NextId()*/;
|
|
|
|
|
entity.PasswordSalt = InfraHelper.Security.GenerateRandomCode(5);
|
|
|
|
|
entity.Password = InfraHelper.Hash.GetHashedString(HashTypeEnum.Md5, input.Password);
|
|
|
|
|
entity.ChatPersonType = ChatPersonTypeEnum.SupervisedPerson;
|
|
|
|
|
|
|
|
|
|
//添加默认头像
|
|
|
|
|
entity.Avatar = "/avatar/default.png";
|
|
|
|
|
|
|
|
|
|
addAppUsers.Add(entity);
|
|
|
|
|
|
|
|
|
|
//添加角色
|
|
|
|
|
appUserRoles.AddRange(input.RoleIds.Select(a => new AppUserRole
|
|
|
|
|
{
|
|
|
|
|
UserId = entity.Id,
|
|
|
|
|
RoleId = a
|
|
|
|
|
}).ToList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Uow.BeginTransaction();
|
|
|
|
|
|
|
|
|
|
await _userRepository.InsertAsync(addAppUsers);
|
|
|
|
|
|
|
|
|
|
await _userRoleRepository.InsertAsync(appUserRoles);
|
|
|
|
|
|
|
|
|
|
//await Uow.CommitAsync();
|
|
|
|
|
|
|
|
|
|
//返回结果
|
|
|
|
|
var rtn = Mapper.Map<List<GetUserInfoByKeywordDto>>(addAppUsers);
|
|
|
|
|
|
|
|
|
|
return rtn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="userUpdateInputs"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<int> BatchUpdateAsync(List<SupervisedPersonUpdateInput> userUpdateInputs)
|
|
|
|
|
{
|
|
|
|
|
var userIds = userUpdateInputs.Select(w => w.Id).ToList();
|
|
|
|
|
|
|
|
|
|
var allUsers = await _userRepository.Where(w => userIds.Contains(w.Id)).ToListAsync();
|
|
|
|
|
|
|
|
|
|
allUsers.ForEach(item =>
|
|
|
|
|
{
|
|
|
|
|
var tempUser = userUpdateInputs.FirstOrDefault(w => w.IdCard == item.IdCard);
|
|
|
|
|
|
|
|
|
|
if (tempUser != null)
|
|
|
|
|
{
|
|
|
|
|
item.Phone = tempUser.Phone;
|
|
|
|
|
item.UserName = tempUser.UserName;
|
|
|
|
|
item.Name = tempUser.Name;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//批量更新
|
|
|
|
|
return await _userRepository.UpdateAsync(allUsers, UpdatingProps<AppUser>(
|
|
|
|
|
x => x.Phone,
|
|
|
|
|
x => x.Name,
|
|
|
|
|
x => x.UserName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 修改用户(包括角色)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IResultOutput> UpdateAsync(UserUpdateInput input)
|
|
|
|
|
{
|
|
|
|
|
if (!(await IsAdmin(User.Id)).IsAdmin) return ResultOutput.NotOk("无操作权限");
|
|
|
|
|
|
|
|
|
|
if (!(input?.Id > 0)) return ResultOutput.NotOk();
|
|
|
|
|
var user = await _userRepository.FindAsync(input.Id);
|
|
|
|
|
|
|
|
|
|
if (!(user?.Id > 0)) return ResultOutput.NotOk("用户不存在!");
|
|
|
|
|
//监管人和管理员手机号不能重复
|
|
|
|
|
if (await _userRepository.AnyAsync(w => w.Id != input.Id && w.UserName == input.UserName && w.ChatPersonType != ChatPersonTypeEnum.SupervisedPerson)) return ResultOutput.NotOk("姓名不能重复");
|
|
|
|
|
|
|
|
|
|
Mapper.Map(input, user);
|
|
|
|
|
|
|
|
|
|
await _userRepository.UpdateAsync(user, UpdatingProps<AppUser>(
|
|
|
|
|
w => w.UserName!,
|
|
|
|
|
w => w.PositionId!,
|
|
|
|
|
w => w.Phone,
|
|
|
|
|
w => w.UnitId!,
|
|
|
|
|
w => w.Unitname!,
|
|
|
|
|
w => w.DeptcodeId!,
|
|
|
|
|
w => w.Deptcodename!,
|
|
|
|
|
w => w.DataStatus)!);
|
|
|
|
|
if (input.RoleIds != null && input.RoleIds.Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
var roleList = await _roleRepository.AsQueryable(false, true)
|
|
|
|
|
.Where(w=> w.Code == "admin" || w.Code == "supervisor")
|
|
|
|
|
.Select(s=>s.Id).ToListAsync();
|
|
|
|
|
|
|
|
|
|
await _userRoleRepository.DeleteAsync(a => a.UserId == user.Id && roleList.Contains(a.RoleId));
|
|
|
|
|
|
|
|
|
|
if (input.RoleIds == null || !input.RoleIds.Any()) return ResultOutput.Ok();
|
|
|
|
|
{
|
|
|
|
|
var roles = input.RoleIds.Select(a => new AppUserRole(YitIdHelper.NextId())
|
|
|
|
|
{
|
|
|
|
|
UserId = user.Id,
|
|
|
|
|
RoleId = a
|
|
|
|
|
});
|
|
|
|
|
await _userRoleRepository.InsertAsync(roles);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultOutput.Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新用户基本信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IResultOutput> UpdateBasicAsync(UserUpdateBasicInput input)
|
|
|
|
|
{
|
|
|
|
|
var entity = await _userRepository.FindAsync(input.Id);
|
|
|
|
|
|
|
|
|
|
entity = Mapper.Map(input, entity);
|
|
|
|
|
|
|
|
|
|
var result = await _userRepository.UpdateAsync(entity);
|
|
|
|
|
|
|
|
|
|
//清除用户缓存
|
|
|
|
|
await Cache.DelAsync(string.Format(CacheKey.userInfo, input.Id));
|
|
|
|
|
|
|
|
|
|
return ResultOutput.Result(result!.Id > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 修改用户密码
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IResultOutput> ChangePasswordAsync(UserChangePasswordInput input)
|
|
|
|
|
{
|
|
|
|
|
if (input.ConfirmPassword != input.NewPassword) return ResultOutput.NotOk("新密码和确认密码不一致!");
|
|
|
|
|
|
|
|
|
|
//查询用户密码
|
|
|
|
|
var user = await _userRepository.FindAsync(w => w.Id == User.Id);
|
|
|
|
|
|
|
|
|
|
if (user == null) return ResultOutput.NotOk("用户不存在,参数信息不完整");
|
|
|
|
|
|
|
|
|
|
//旧的密码
|
|
|
|
|
var md5OldPwdString = InfraHelper.Hash.GetHashedString(HashTypeEnum.Md5, input.OldPassword);
|
|
|
|
|
if (!md5OldPwdString.EqualsIgnoreCase(user.Password)) return ResultOutput.NotOk("旧密码输入错误!");
|
|
|
|
|
var pattern = "^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$";
|
|
|
|
|
var result = System.Text.RegularExpressions.Regex.IsMatch(input.NewPassword, pattern);
|
|
|
|
|
if (!result)
|
|
|
|
|
{
|
|
|
|
|
return ResultOutput.NotOk("密码由8位以上数字,大小写字母,特殊字符组成");
|
|
|
|
|
}
|
|
|
|
|
//新密码
|
|
|
|
|
//user.PasswordSalt = InfraHelper.Security.GenerateRandomCode(5);
|
|
|
|
|
user.Password = InfraHelper.Hash.GetHashedString(HashTypeEnum.Md5, input.NewPassword);
|
|
|
|
|
|
|
|
|
|
//更新密码
|
|
|
|
|
await _userRepository.UpdateAsync(user, UpdatingProps<AppUser>(x => x.Password)!);
|
|
|
|
|
|
|
|
|
|
return ResultOutput.Result(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 批量重置密码
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IResultOutput> BatchResetPassword(BatchResetPasswordInput input)
|
|
|
|
|
{
|
|
|
|
|
if (!(await IsAdmin(User.Id)).IsAdmin) return ResultOutput.NotOk("无操作权限");
|
|
|
|
|
|
|
|
|
|
//查询用户密码
|
|
|
|
|
var userList = await _userRepository.AsQueryable(false, false)
|
|
|
|
|
.Where(w => input.Ids.Contains(w.Id))
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (!userList.Any()) return ResultOutput.NotOk("用户不存在,参数信息不完整");
|
|
|
|
|
|
|
|
|
|
userList.ForEach(item =>
|
|
|
|
|
{
|
|
|
|
|
item!.Password = InfraHelper.Hash.GetHashedString(HashTypeEnum.Md5, AdminConstant.resetPassword);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await _userRepository.UpdateAsync(userList);
|
|
|
|
|
|
|
|
|
|
return ResultOutput.Result(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 彻底删除用户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IResultOutput> DeleteAsync(long id)
|
|
|
|
|
{
|
|
|
|
|
if (!(await IsAdmin(User.Id)).IsAdmin) return ResultOutput.NotOk("无操作权限");
|
|
|
|
|
//管理员不能对自己删除
|
|
|
|
|
var adminUserIds = (await GetAllAdminUserIds()).Select(w => w.Id).ToList();
|
|
|
|
|
if (adminUserIds.IsNotNullOrEmpty() && adminUserIds.Exists(w => w == id)) return ResultOutput.NotOk("管理员不能修改自己的状态");
|
|
|
|
|
|
|
|
|
|
var result = false;
|
|
|
|
|
if (id > 0) result = (await _userRepository.DeleteAsync(id)) > 0;
|
|
|
|
|
return ResultOutput.Result(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除用户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IResultOutput> SoftDeleteAsync(long id)
|
|
|
|
|
{
|
|
|
|
|
if (!(await IsAdmin(User.Id)).IsAdmin) return ResultOutput.NotOk("无操作权限");
|
|
|
|
|
//管理员不能对自己删除
|
|
|
|
|
var adminUserIds = (await GetAllAdminUserIds()).Select(w => w.Id).ToList();
|
|
|
|
|
if (adminUserIds.IsNotNullOrEmpty() && adminUserIds.Exists(w => w == id)) return ResultOutput.NotOk("管理员不能修改自己的状态");
|
|
|
|
|
var result = await _userRepository.SoftDeleteAsync(w => w.Id == id);
|
|
|
|
|
await _userRoleRepository.DeleteAsync(a => a.UserId == id);
|
|
|
|
|
|
|
|
|
|
return ResultOutput.Result(result > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 批量删除用户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IResultOutput> BatchSoftDeleteAsync(long[] ids)
|
|
|
|
|
{
|
|
|
|
|
if (!(await IsAdmin(User.Id)).IsAdmin) return ResultOutput.NotOk("无操作权限");
|
|
|
|
|
|
|
|
|
|
//管理员不能对自己删除
|
|
|
|
|
var adminUserIds = (await GetAllAdminUserIds()).Select(w => w.Id).ToList();
|
|
|
|
|
if (adminUserIds.IsNotNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in ids)
|
|
|
|
|
{
|
|
|
|
|
if (adminUserIds.Exists(w => w == item) && item == User.Id)
|
|
|
|
|
{
|
|
|
|
|
return ResultOutput.NotOk("管理员不能修改自己的状态");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var result = await _userRepository.DeleteAsync(w => ids.Contains(w.Id));
|
|
|
|
|
await _userRoleRepository.DeleteAsync(a => ids.Contains(a.UserId));
|
|
|
|
|
|
|
|
|
|
return ResultOutput.Result(result > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上传头像
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="file"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Login]
|
|
|
|
|
public async Task<IResultOutput> AvatarUpload([FromForm] IFormFile file)
|
|
|
|
|
{
|
|
|
|
|
var uploadConfig = LazyGetRequiredService<UploadConfigConfiguration>();
|
|
|
|
|
var rtn = await base.CustomizedUpload(file, User.Id, uploadConfig.Avatar, async res =>
|
|
|
|
|
{
|
|
|
|
|
//更新头像
|
|
|
|
|
await _userRepository.UpdateAsync(new AppUser
|
|
|
|
|
{
|
|
|
|
|
Id = User.Id,
|
|
|
|
|
Avatar = res.Data.FileRequestPath
|
|
|
|
|
}, UpdatingProps<AppUser>(x => x.Avatar!)!);
|
|
|
|
|
});
|
|
|
|
|
return rtn;
|
|
|
|
|
/* return await base.CustomizedUpload(file, User.Id, uploadConfig.Avatar, async res =>
|
|
|
|
|
{
|
|
|
|
|
//更新头像
|
|
|
|
|
await _userRepository.UpdateAsync(new AppUser
|
|
|
|
|
{
|
|
|
|
|
Id = User.Id,
|
|
|
|
|
Avatar = res.Data.FileRequestPath
|
|
|
|
|
}, UpdatingProps<AppUser>(x => x.Avatar!)!);
|
|
|
|
|
});*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 批量修改状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IResultOutput> BatchChangeStatus(BatchChangeStatusInput input)
|
|
|
|
|
{
|
|
|
|
|
if (!(await IsAdmin(User.Id)).IsAdmin) return ResultOutput.NotOk("无操作权限");
|
|
|
|
|
|
|
|
|
|
//管理员不能对自己启用、禁用
|
|
|
|
|
var adminUserIds = (await GetAllAdminUserIds()).Select(w => w.Id).ToList();
|
|
|
|
|
if (adminUserIds.IsNotNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in input.Ids)
|
|
|
|
|
{
|
|
|
|
|
if (adminUserIds.Exists(w => w == item) && item == User.Id)
|
|
|
|
|
{
|
|
|
|
|
return ResultOutput.NotOk("管理员不能修改自己的状态");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (input.DataStatus == DataStatusEnum.Disable && input.Ids.Exists(w => w == User.Id)) return ResultOutput.NotOk($"不能禁用当前登录的用户{User.Name}");
|
|
|
|
|
|
|
|
|
|
return await base.BatchChangeStatus(input, _userRepository);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 判断当前登录用户是否是管理员
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IsAdminDto> IsAdmin(long? userId)
|
|
|
|
|
{
|
|
|
|
|
var userRoles = await (from uR in _userRoleRepository.AsQueryable(false, true)
|
|
|
|
|
join r in _roleRepository.AsQueryable(false, true) on uR.RoleId equals r.Id
|
|
|
|
|
select new { uR, r })
|
|
|
|
|
.Where(w => w.uR.UserId == (userId.HasValue ? userId : User.Id))
|
|
|
|
|
.Select(w => w.r)
|
|
|
|
|
.ProjectTo<RoleGetOutput>(Mapper.ConfigurationProvider)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
return new IsAdminDto()
|
|
|
|
|
{
|
|
|
|
|
IsAdmin = userRoles.Any(w => w.Code == AdminConstant.adminRole),
|
|
|
|
|
Roles = userRoles
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 通过关键字(用户名、身份证号、手机号)查询用户信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="keyword"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<IResultOutput> GetUserInfoByKeyword(string keyword)
|
|
|
|
|
{
|
|
|
|
|
List<GetUserInfoByKeywordDto> rtn = new EditableList<GetUserInfoByKeywordDto>();
|
|
|
|
|
|
|
|
|
|
var userIds = await (from r in _roleRepository.AsQueryable(false, true)
|
|
|
|
|
join ur in _userRoleRepository.AsQueryable(false, true) on r.Id equals ur.RoleId
|
|
|
|
|
select new
|
|
|
|
|
{
|
|
|
|
|
ur.UserId
|
|
|
|
|
})
|
|
|
|
|
.Distinct()
|
|
|
|
|
.Select(w => w.UserId)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (!userIds.Any()) ResultOutput.Ok(rtn);
|
|
|
|
|
|
|
|
|
|
rtn = await _userRepository.AsQueryable(false, true)
|
|
|
|
|
.Where(w => w.ChatPersonType == ChatPersonTypeEnum.SupervisedPerson)
|
|
|
|
|
.Where(w => userIds.Contains(w.Id) && (w.Name.Contains(keyword) || w.UserName.Contains(keyword) || w.NickName.Contains(keyword) || w.IdCard.Contains(keyword) || w.Phone.Contains(keyword)))
|
|
|
|
|
.ProjectTo<GetUserInfoByKeywordDto>(Mapper.ConfigurationProvider)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
return ResultOutput.Ok(rtn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 校验当前用户是否被禁用
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<bool> CheckUserStatus()
|
|
|
|
|
{
|
|
|
|
|
var user = await _userRepository.FindAsync(w => w.Id == User.Id).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
if (user == null) return false;
|
|
|
|
|
|
|
|
|
|
return user.DataStatus == DataStatusEnum.Normal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据用户Id查询用户头像
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<List<UserAvatarListOutput>> UserAvatarList(BatchIdsInput input)
|
|
|
|
|
{
|
|
|
|
|
return await _userRepository.AsQueryable(false, true)
|
|
|
|
|
.Where(w => input.Ids.Contains(w.Id))
|
|
|
|
|
.Select(w => new UserAvatarListOutput()
|
|
|
|
|
{
|
|
|
|
|
UserId = w.Id,
|
|
|
|
|
Avatar = w.Avatar
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 判断用户是否存在
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="keyWord">身份证、手机号</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<bool> UserIsExist(string keyWord) => await _userRepository.AnyAsync(w => w.IdCard == keyWord || w.Phone == keyWord);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据当前登录用户查询下拉列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="isCourt">移交给检察院 0 移交法院 1</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<ResultOutput<List<KeyValueDto>>> GetUserSelectList(int isCourt = 0)
|
|
|
|
|
{
|
|
|
|
|
var userRoles = await this.IsAdmin(null);
|
|
|
|
|
|
|
|
|
|
var dataDict = await _appDictionaryService.GetListNoApiAsync("job_position");
|
|
|
|
|
|
|
|
|
|
// 安全地处理可能的空值
|
|
|
|
|
var codeList = dataDict?.FirstOrDefault()?.Dictionaries?
|
|
|
|
|
.Where(w => w.Code == (isCourt == 0 ? "inquisitor" : "judge"))
|
|
|
|
|
.ToList() ?? new List<DictionaryGetOutput>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var rtn = await _userRepository.AsQueryable(false, true)
|
|
|
|
|
.Where(w => w.ChatPersonType != ChatPersonTypeEnum.SupervisedPerson && w.DataStatus != DataStatusEnum.Disable && !w.UserName.Contains("_aks"))
|
|
|
|
|
.WhereIf(codeList.Count>0,w=> w.PositionId == codeList.FirstOrDefault().Id)
|
|
|
|
|
// .WhereIf(!userRoles.IsAdmin, w => w.Id == User.Id) 2025 -10-20 段肖确认修改
|
|
|
|
|
.Select(w => new KeyValueDto()
|
|
|
|
|
{
|
|
|
|
|
Id = w.Id,
|
|
|
|
|
Text = w.UserName ?? w.Name,
|
|
|
|
|
Value = w.Id.ToString(),
|
|
|
|
|
Phone = w.Phone.ToString()
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
return (ResultOutput<List<KeyValueDto>>)ResultOutput.Ok(rtn);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 新建案件时 根据当前登录用户查询下拉列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<ResultOutput<List<KeyValueDto>>> GetNewUserSelectList()
|
|
|
|
|
{
|
|
|
|
|
var userRoles = await this.IsAdmin(null);
|
|
|
|
|
// var limits = User.UnitId;
|
|
|
|
|
var rtn = await _userRepository.AsQueryable(false, true)
|
|
|
|
|
.Where(w => w.ChatPersonType != ChatPersonTypeEnum.SupervisedPerson && w.DataStatus != DataStatusEnum.Disable && !w.UserName.Contains("_aks") && w.UnitId == User.UnitId)
|
|
|
|
|
.Select(w => new KeyValueDto()
|
|
|
|
|
{
|
|
|
|
|
Id = w.Id,
|
|
|
|
|
Text = w.UserName ?? w.Name,
|
|
|
|
|
Value = w.Id.ToString(),
|
|
|
|
|
Phone = w.Phone.ToString()
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
return (ResultOutput<List<KeyValueDto>>)ResultOutput.Ok(rtn);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取所有的管理员
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<List<AuthLoginOutput>> GetAllAdminUserIds()
|
|
|
|
|
{
|
|
|
|
|
var user = await (from uR in _userRoleRepository.AsQueryable(false, true)
|
|
|
|
|
join r in _roleRepository.AsQueryable(false, true) on uR.RoleId equals r.Id
|
|
|
|
|
join u in _userRepository.AsQueryable(false, true) on uR.UserId equals u.Id
|
|
|
|
|
select new
|
|
|
|
|
{
|
|
|
|
|
uR,
|
|
|
|
|
r,
|
|
|
|
|
u
|
|
|
|
|
})
|
|
|
|
|
.Where(w => w.r.Code == AdminConstant.adminRole)
|
|
|
|
|
.Select(w => new AuthLoginOutput()
|
|
|
|
|
{
|
|
|
|
|
Id = w.u.Id,
|
|
|
|
|
NickName = w.u.NickName,
|
|
|
|
|
Avatar = w.u.Avatar,
|
|
|
|
|
ChatPersonType = w.u.ChatPersonType,
|
|
|
|
|
IdCard = w.u.IdCard,
|
|
|
|
|
Phone = w.u.Phone,
|
|
|
|
|
CId = w.u.CId,
|
|
|
|
|
UserName = w.u.UserName
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
user = user.Distinct((x, y) => x.Id == y.Id).ToList();
|
|
|
|
|
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Private
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询条件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pageInput"></param>
|
|
|
|
|
/// <param name="query"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private IQueryable<AppUser> GetExpression(UserGetPageDto pageInput, IQueryable<AppUser?> query)
|
|
|
|
|
{
|
|
|
|
|
query = query
|
|
|
|
|
.Where(w => w.ChatPersonType != ChatPersonTypeEnum.SupervisedPerson)
|
|
|
|
|
.WhereIf(pageInput.KeyWord.NotNull(), a => a.Name.Contains(pageInput.KeyWord) || a.NickName.Contains(pageInput.KeyWord))
|
|
|
|
|
.WhereIf(pageInput.StatusSearch?.Content != null, w => w.DataStatus == pageInput.StatusSearch!.Content)
|
|
|
|
|
.WhereIf(pageInput.Name.NotNull(), w => w.Name.Contains(pageInput.Name) || w.UserName.Contains(pageInput.Name))
|
|
|
|
|
.WhereIf(pageInput.Phone.NotNull(), w => w.Phone.Contains(pageInput.Phone))
|
|
|
|
|
.WhereIf(pageInput.IdCard.NotNull(), w => w.IdCard.Contains(pageInput.IdCard));
|
|
|
|
|
|
|
|
|
|
var express = base.GetExpression<AppUser, UserGetPageDto, long>(pageInput, query);
|
|
|
|
|
|
|
|
|
|
return express;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Private
|
|
|
|
|
}
|
|
|
|
|
}
|