using JNPF.Apps.Entitys.Dto;
using JNPF.Common.Core.Manager;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Interfaces.Permission;
using Mapster;
using Microsoft.AspNetCore.Mvc;
namespace JNPF.Apps;
///
/// App用户信息
/// 版 本:V3.2
/// 版 权:拓通智联科技有限公司(http://www.tuotong-tech.com)
/// 日 期:2021-06-01.
///
[ApiDescriptionSettings(Tag = "App", Name = "User", Order = 800)]
[Route("api/App/[controller]")]
public class AppUserService : IDynamicApiController, ITransient
{
///
/// 用户信息.
///
private readonly IUsersService _usersService;
///
/// 部门管理.
///
private readonly IDepartmentService _departmentService;
///
/// 岗位管理.
///
private readonly IPositionService _positionService;
///
/// 用户管理.
///
private readonly IUserManager _userManager;
///
/// 构造.
///
///
///
///
///
public AppUserService(IUsersService usersService, IDepartmentService departmentService, IPositionService positionService, IUserManager userManager)
{
_usersService = usersService;
_departmentService = departmentService;
_positionService = positionService;
_userManager = userManager;
}
#region Get
///
/// 用户信息.
///
///
[HttpGet("")]
public async Task GetInfo()
{
UserEntity? userEntity = _usersService.GetInfoByUserId(_userManager.UserId);
AppUserOutput? appUserInfo = userEntity.Adapt();
appUserInfo.positionIds = userEntity.PositionId == null ? null : await _usersService.GetPosition(userEntity.PositionId);
appUserInfo.departmentName = _departmentService.GetOrganizeNameTree(userEntity.OrganizeId);
appUserInfo.organizeId = _departmentService.GetCompanyId(userEntity.OrganizeId);
appUserInfo.organizeName = appUserInfo.departmentName;
// 获取当前组织角色和全局角色
List? roleList = await _userManager.GetUserOrgRoleIds(userEntity.RoleId, userEntity.OrganizeId);
appUserInfo.roleName = await _userManager.GetRoleNameByIds(string.Join(",", roleList));
appUserInfo.manager = await _usersService.GetUserName(userEntity.ManagerId);
return appUserInfo;
}
///
/// 用户信息.
///
///
[HttpGet("{id}")]
public dynamic GetInfo(string id)
{
UserEntity? userEntity = _usersService.GetInfoByUserId(id);
AppUserInfoOutput? appUserInfo = userEntity.Adapt();
appUserInfo.organizeName = _departmentService.GetDepName(userEntity.OrganizeId);
appUserInfo.positionName = _positionService.GetName(userEntity.PositionId);
return appUserInfo;
}
#endregion
}