update:组织用户目录树全部读取

This commit is contained in:
2021-06-28 15:20:25 +08:00
parent 4eace63902
commit 6178ac5059
5 changed files with 73 additions and 20 deletions

View File

@@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Xml.Serialization; using System.Xml.Serialization;
@@ -29,6 +30,7 @@ namespace Ewide.Core
/// 名称 /// 名称
/// </summary> /// </summary>
[Comment("名称")] [Comment("名称")]
[MaxLength(20)]
public string Name { get; set; } public string Name { get; set; }
/// <summary> /// <summary>

View File

@@ -0,0 +1,6 @@
namespace Ewide.Core.Service
{
public class OrgUserInput
{
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ewide.Core.Service.User.Dto
{
public class OrgUserTreeNode : ITreeNode
{
public string Id { get; set; }
public string ParentId { get; set; }
public string Name { get; set; }
public int Type { get; set; }
public List<OrgUserTreeNode> Children { get; set; }
public string GetId() => Id;
public string GetPid() => ParentId;
public void SetChildren(IList children)
{
Children = (List<OrgUserTreeNode>)children;
}
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc; using Ewide.Core.Service.User.Dto;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -29,5 +30,7 @@ namespace Ewide.Core.Service
Task<dynamic> SendCode(Usermailphone input); Task<dynamic> SendCode(Usermailphone input);
Task<dynamic> CheckBindcode(Usermailphone input); Task<dynamic> CheckBindcode(Usermailphone input);
Task<dynamic> GetOrgUserTree(OrgUserInput input);
} }
} }

View File

@@ -1,4 +1,5 @@
using Ewide.Core.Service.Role; using Ewide.Core.Service.Role;
using Ewide.Core.Service.User.Dto;
using Ewide.Core.Util; using Ewide.Core.Util;
using Furion.DatabaseAccessor; using Furion.DatabaseAccessor;
using Furion.DatabaseAccessor.Extensions; using Furion.DatabaseAccessor.Extensions;
@@ -25,6 +26,8 @@ namespace Ewide.Core.Service
public class SysUserService : ISysUserService, IDynamicApiController, ITransient public class SysUserService : ISysUserService, IDynamicApiController, ITransient
{ {
private readonly IRepository<SysUser> _sysUserRep; // 用户表仓储 private readonly IRepository<SysUser> _sysUserRep; // 用户表仓储
private readonly IRepository<SysOrg> _sysOrgRep;
private readonly IRepository<SysEmp> _sysEmpRep;
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
private readonly ISysCacheService _sysCacheService; private readonly ISysCacheService _sysCacheService;
private readonly ISysEmpService _sysEmpService; private readonly ISysEmpService _sysEmpService;
@@ -34,6 +37,8 @@ namespace Ewide.Core.Service
private readonly ISysUserAreaService _sysUserAreaService; private readonly ISysUserAreaService _sysUserAreaService;
public SysUserService(IRepository<SysUser> sysUserRep, public SysUserService(IRepository<SysUser> sysUserRep,
IRepository<SysOrg> sysOrgRep,
IRepository<SysEmp> sysEmpRep,
IUserManager userManager, IUserManager userManager,
IMemoryCache memoryCache, IMemoryCache memoryCache,
ISysCacheService sysCacheService, ISysCacheService sysCacheService,
@@ -43,6 +48,8 @@ namespace Ewide.Core.Service
ISysUserAreaService sysUserAreaService) ISysUserAreaService sysUserAreaService)
{ {
_sysUserRep = sysUserRep; _sysUserRep = sysUserRep;
_sysOrgRep = sysOrgRep;
_sysEmpRep = sysEmpRep;
_userManager = userManager; _userManager = userManager;
_iMemoryCache = memoryCache; _iMemoryCache = memoryCache;
_sysCacheService = sysCacheService; _sysCacheService = sysCacheService;
@@ -65,11 +72,10 @@ namespace Ewide.Core.Service
var pid = input.SysEmpParam.OrgId; var pid = input.SysEmpParam.OrgId;
var sysEmpRep = Db.GetRepository<SysEmp>(); var sysEmpRep = Db.GetRepository<SysEmp>();
var sysOrgRep = Db.GetRepository<SysOrg>();
var dataScopes = await GetUserDataScopeIdList(_userManager.UserId); var dataScopes = await GetUserDataScopeIdList(_userManager.UserId);
var users = await _sysUserRep.DetachedEntities var users = await _sysUserRep.DetachedEntities
.Join(sysEmpRep.DetachedEntities, u => u.Id, e => e.Id, (u, e) => new { u, e }) .Join(sysEmpRep.DetachedEntities, u => u.Id, e => e.Id, (u, e) => new { u, e })
.Join(sysOrgRep.DetachedEntities, n => n.e.OrgId, o => o.Id, (n, o) => new { n, o }) .Join(_sysOrgRep.DetachedEntities, n => n.e.OrgId, o => o.Id, (n, o) => new { n, o })
.Where(!string.IsNullOrEmpty(searchValue), x => (x.n.u.Account.Contains(input.SearchValue) || .Where(!string.IsNullOrEmpty(searchValue), x => (x.n.u.Account.Contains(input.SearchValue) ||
x.n.u.Name.Contains(input.SearchValue) || x.n.u.Name.Contains(input.SearchValue) ||
x.n.u.Phone.Contains(input.SearchValue))) x.n.u.Phone.Contains(input.SearchValue)))
@@ -467,7 +473,7 @@ namespace Ewide.Core.Service
var Regex_Email = @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"; var Regex_Email = @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$";
CodeHelper ch = new CodeHelper(_iMemoryCache); CodeHelper ch = new CodeHelper(_iMemoryCache);
//Type为1时给原手机号发送验证码 //Type为1时给原手机号发送验证码
if(input.Type == 1) if (input.Type == 1)
{ {
try try
{ {
@@ -480,9 +486,9 @@ namespace Ewide.Core.Service
} }
//Type为2时给原邮箱发送验证码 //Type为2时给原邮箱发送验证码
else if(input.Type == 2) else if (input.Type == 2)
{ {
if(new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$").IsMatch(_userManager.User.Email)) if (new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$").IsMatch(_userManager.User.Email))
{ {
try try
{ {
@@ -499,7 +505,7 @@ namespace Ewide.Core.Service
else else
{ {
//通过正则判断绑定类型 //通过正则判断绑定类型
if(new Regex(Regex_phone).IsMatch(input.Target)) if (new Regex(Regex_phone).IsMatch(input.Target))
{ {
try try
{ {
@@ -507,12 +513,12 @@ namespace Ewide.Core.Service
ch.SendSmscode(input.Target, Smscode_Key); ch.SendSmscode(input.Target, Smscode_Key);
return true; return true;
} }
catch(Exception e) catch (Exception e)
{ {
throw Oops.Oh(ErrorCode.D1018); throw Oops.Oh(ErrorCode.D1018);
} }
} }
if(new Regex(Regex_Email).IsMatch(input.Target)) if (new Regex(Regex_Email).IsMatch(input.Target))
{ {
try try
{ {
@@ -541,7 +547,7 @@ namespace Ewide.Core.Service
var Regex_Email = @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"; var Regex_Email = @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$";
var user = await _sysUserRep.FirstOrDefaultAsync(u => u.Id == _userManager.UserId); var user = await _sysUserRep.FirstOrDefaultAsync(u => u.Id == _userManager.UserId);
CodeHelper ch = new CodeHelper(_iMemoryCache); CodeHelper ch = new CodeHelper(_iMemoryCache);
if(input.Type == 1) if (input.Type == 1)
{ {
if (ch.Checkcode(_userManager.User.Phone, input.Orgcode, Orgcode_Key)) if (ch.Checkcode(_userManager.User.Phone, input.Orgcode, Orgcode_Key))
{ {
@@ -549,9 +555,9 @@ namespace Ewide.Core.Service
}; };
throw Oops.Oh("验证错误"); throw Oops.Oh("验证错误");
} }
else if(input.Type == 2) else if (input.Type == 2)
{ {
if(ch.Checkcode(_userManager.User.Email, input.Orgcode, Orgcode_Key)) if (ch.Checkcode(_userManager.User.Email, input.Orgcode, Orgcode_Key))
{ {
return true; return true;
} }
@@ -560,11 +566,11 @@ namespace Ewide.Core.Service
else else
{ {
//为第一次绑定 //为第一次绑定
if(string.IsNullOrEmpty(_userManager.User.Phone) && string.IsNullOrEmpty(_userManager.User.Email)) if (string.IsNullOrEmpty(_userManager.User.Phone) && string.IsNullOrEmpty(_userManager.User.Email))
{ {
if(new Regex(Regex_phone).IsMatch(input.Target)) if (new Regex(Regex_phone).IsMatch(input.Target))
{ {
if (ch.Checkcode(input.Target,input.Code, Smscode_Key)) if (ch.Checkcode(input.Target, input.Code, Smscode_Key))
{ {
try try
{ {
@@ -581,7 +587,7 @@ namespace Ewide.Core.Service
} }
throw Oops.Oh("验证码失效"); throw Oops.Oh("验证码失效");
} }
if(new Regex(Regex_Email).IsMatch(input.Target)) if (new Regex(Regex_Email).IsMatch(input.Target))
{ {
if (ch.Checkcode(input.Target, input.Code, Mailcode_Key)) if (ch.Checkcode(input.Target, input.Code, Mailcode_Key))
{ {
@@ -652,5 +658,17 @@ namespace Ewide.Core.Service
} }
} }
} }
[HttpPost("/sysUser/GetOrgUserTree")]
public async Task<dynamic> GetOrgUserTree(OrgUserInput input)
{
var list = await (from u in _sysUserRep.DetachedEntities
join e in _sysEmpRep.DetachedEntities on u.Id equals e.Id
select new OrgUserTreeNode { Id = u.Id, ParentId = e.OrgId,Type=1,Name=u.Name }).Union(
from o in _sysOrgRep.DetachedEntities
select new OrgUserTreeNode { Id = o.Id, ParentId = o.Pid ,Type=0,Name=o.Name}).ToListAsync();
return new TreeBuildUtil<OrgUserTreeNode>().DoTreeBuild(list);
}
} }
} }