1.用户的
This commit is contained in:
parent
e122e5d621
commit
3514814756
199
services/Syc.Basic.Web.WMS.Application/Service/UserService.cs
Normal file
199
services/Syc.Basic.Web.WMS.Application/Service/UserService.cs
Normal file
@ -0,0 +1,199 @@
|
||||
using DotNetCore.CAP;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Syc.Authorize.JwtBearer;
|
||||
|
||||
//using Syc.Basic.Web.Contracts;
|
||||
using Syc.Basic.Web.WMS.Dtos;
|
||||
using Syc.Basic.Web.WMS.Dtos.Auth;
|
||||
using Syc.Basic.Web.WMS.Dtos.Role;
|
||||
using Syc.Basic.Web.WMS.Dtos.User;
|
||||
using Syc.Basic.Web.WMS.Entitys;
|
||||
using Syc.Basic.Web.WMS.IServices;
|
||||
using Syc.Basic.Web.WMS.Repository;
|
||||
using Syc.Basic.Web.Services;
|
||||
using Syc.Core.Tools;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
|
||||
namespace Syc.Basic.Web.WMS.Service
|
||||
{
|
||||
[ApiExplorerSettings(GroupName = "用户服务"), Authorize]
|
||||
public class UserAppService : ApiService, IUserService
|
||||
{
|
||||
private readonly IUserDomainService userDomainService;
|
||||
private readonly IRepository<User> repository;
|
||||
private readonly IUserRepository userRepository;
|
||||
private readonly IRepository<Role> roleRepository;
|
||||
private readonly IRepository<Organization> orgRepository;
|
||||
private readonly IDictionaryService dictionaryService;
|
||||
private readonly IRepository<Position> positionRepository;
|
||||
private readonly IRepository<UserPosition> userPositionRepository;
|
||||
|
||||
public UserAppService(IUserDomainService userDomainService
|
||||
, IRepository<User> repository
|
||||
, IUserRepository userRepository
|
||||
,IRepository<Role> roleRepository
|
||||
,IRepository<Organization> orgRepository
|
||||
,IDictionaryService dictionaryService,
|
||||
IRepository<Position> positionRepository
|
||||
,IRepository<UserPosition> userPositionRepository)
|
||||
{
|
||||
this.userDomainService = userDomainService;
|
||||
this.repository = repository;
|
||||
this.userRepository = userRepository;
|
||||
this.roleRepository = roleRepository;
|
||||
this.orgRepository = orgRepository;
|
||||
this.dictionaryService = dictionaryService;
|
||||
this.positionRepository = positionRepository;
|
||||
this.userPositionRepository = userPositionRepository;
|
||||
}
|
||||
|
||||
public async Task Add(UserInsertInput input)
|
||||
{
|
||||
var user = ObjectMapper.Map(input,new User());
|
||||
var accountExist = await repository.AnyAsync(e => e.Account == user.Account);
|
||||
if (accountExist)
|
||||
throw Oops.Oh("账号已存在,请重复使用");
|
||||
|
||||
var roles = await roleRepository.GetListAsync(e => input.roleIds.Contains(e.Code));
|
||||
var organizations = await orgRepository.GetAsync(e => input.departmentId == e.Id);
|
||||
var positions = await positionRepository.GetListAsync(e => input.positionIds.Contains(e.Code));
|
||||
var password = await dictionaryService.GetAsync<string>(ConstPool.Dict_Code_UserDefaultPassword,ConstPool.DictItem_Key_UserDefaultPassword);
|
||||
user.Createtime = DateTime.Now;
|
||||
user.Creator_Id = Identity.Id;
|
||||
user.Password = Tools.SecurityUtil.MD5Encrypt(password, Encoding.ASCII);
|
||||
user.Roles = roles;
|
||||
user.Organizations = new List<Organization>() { organizations };
|
||||
user.Positions = positions;
|
||||
await repository.InsertAsync(user);
|
||||
}
|
||||
|
||||
public async Task DelUser(UserRemoveDto userInsertDto)
|
||||
{
|
||||
var users = await repository.GetListAsync(e=> userInsertDto.Ids.Contains(e.Id));
|
||||
if (users.Any(e => e.Account == ConstPool.AdminAccount))
|
||||
throw Oops.Oh($"{ConstPool.AdminAccount} 账号禁止删除");
|
||||
if (users.Count > 0)
|
||||
await repository.DeleteManyAsync(users);
|
||||
}
|
||||
|
||||
public async Task Edit(UserInsertInput input)
|
||||
{
|
||||
var accountExist = await repository.AnyAsync(e => e.Account == input.username && e.Id != input.id);
|
||||
if (accountExist)
|
||||
throw Oops.Oh("账号已存在,请重复使用");
|
||||
var userDO = await userRepository.GetUserByAccountAsync(input.username);
|
||||
if(userDO.IsNullOrEmpty())
|
||||
throw Oops.Oh("用户不存在");
|
||||
|
||||
var roles = await roleRepository.GetListAsync(e => input.roleIds.Contains(e.Code));
|
||||
var organizations = await orgRepository.GetAsync(e => input.departmentId == e.Id);
|
||||
var positions = await positionRepository.GetListAsync(e => input.positionIds.Contains(e.Code));
|
||||
|
||||
var user = userDO.User();
|
||||
user.LastUpdateTime = DateTime.UtcNow;
|
||||
user.RealName = input.realname;
|
||||
user.NickName = input.nickname;
|
||||
user.Telephone = input.mobile;
|
||||
user.Email = input.email;
|
||||
user.IsEnable = input.status;
|
||||
user.Roles.Clear();
|
||||
user.Roles.AddRange(roles);
|
||||
user.Organizations.Clear();
|
||||
user.Organizations.AddRange(organizations);
|
||||
user.Positions.Clear();
|
||||
user.Positions.AddRange(positions);
|
||||
await repository.UpdateAsync(user);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 个人信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task Profile()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更改用户状态
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task UpdateStatus(UpdateUserStatInput input)
|
||||
{
|
||||
var user = await repository.GetAsync(e => e.Id == input.id);
|
||||
if (user.IsNullOrEmpty())
|
||||
throw Oops.Oh("用户不存在或已被删除");
|
||||
user.IsEnable = input.status;
|
||||
await repository.UpdateAsync(user);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<GetUserInfoDto> CurrentUserInfo()
|
||||
{
|
||||
var userDO = await userDomainService.GetUserByAccountAsync(Identity.Account);
|
||||
var result = ObjectMapper.Map(Identity, new GetUserInfoDto());
|
||||
result.departmentName = userDO.Department;
|
||||
result.roleName = userDO.Roles().Select(e => e.Name).ToList();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户搜索
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<PageOutput<UserInfoListItemDto>> SearchUserAsync(SearchUserInput input)
|
||||
{
|
||||
var result = await userRepository.SearchUserAsync(input.departmentId, input.email, input.mobile, input.nickname, input.username, input.roleIds, input.Page, input.PageSize);
|
||||
var items = ObjectMapper.Map(result.items, new List<UserInfoListItemDto>());
|
||||
return new PageOutput<UserInfoListItemDto>()
|
||||
{
|
||||
PageIndex = input.Page,
|
||||
Data = items,
|
||||
PageSize = input.PageSize,
|
||||
Total = result.total,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据 id 获取用户信息
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<List<UserInfoListItemDto>> GetByIdAsync(List<int> ids)
|
||||
{
|
||||
var users = await userRepository.GetUsers(ids.ToArray(),false);
|
||||
return ObjectMapper.Map(users, new List<UserInfoListItemDto>());
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取用户职位
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
[HttpGet]
|
||||
public async Task<List<string>> GetUserPosition()
|
||||
{
|
||||
var users = await userPositionRepository.GetQueryableAsync();
|
||||
users = users.Where(e => e.UsersId == Identity.Id);
|
||||
List<string> positions = new List<string>();
|
||||
foreach (var user in users) {
|
||||
positions.Add(user.PositionsCode);
|
||||
}
|
||||
return positions;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user