init commit
This commit is contained in:
71
20220330_Vote/Ewide.RoadFlow/Data/Organize/IOrganize.cs
Normal file
71
20220330_Vote/Ewide.RoadFlow/Data/Organize/IOrganize.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using Ewide.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RoadFlow.Data
|
||||
{
|
||||
public interface IOrganize
|
||||
{
|
||||
/// <summary>
|
||||
/// 人员前缀
|
||||
/// </summary>
|
||||
const string PREFIX_USER = "u_";
|
||||
/// <summary>
|
||||
/// 工作组前缀
|
||||
/// </summary>
|
||||
const string PREFIX_WORKGROUP = "w_";
|
||||
/// <summary>
|
||||
/// 人员兼职前缀
|
||||
/// </summary>
|
||||
const string PREFIX_RELATION = "r_";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID字符串得到所有人员ID
|
||||
/// </summary>
|
||||
/// <param name="idString">u_人员,id,w_工作且,r_兼职</param>
|
||||
/// <returns>逗号分开的ID</returns>
|
||||
public string GetAllUsersId(string idString);
|
||||
/// <summary>
|
||||
/// 得到一个机构下所有人员
|
||||
/// </summary>
|
||||
/// <param name="id">机构ID</param>
|
||||
/// <param name="hasPartTime">是否包含兼任人员</param>
|
||||
/// <returns></returns>
|
||||
public List<SysUser> GetAllUsers(string id, bool hasPartTime = true);
|
||||
|
||||
/// <summary>
|
||||
/// 得到所有下级组织机构
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="isMe">是否包含自己</param>
|
||||
/// <returns></returns>
|
||||
public List<SysOrg> GetAllChilds(string id, bool isMe = false);
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID查询一个组织机构
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public SysOrg Get(string id);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 得到一个人员的主要组织显示
|
||||
/// </summary>
|
||||
/// <param name="id">人员ID</param>
|
||||
/// <param name="isShowRoot">是否显示根</param>
|
||||
/// <returns></returns>
|
||||
public string GetOrganizeMainShowHtml(string id, bool isShowRoot = true);
|
||||
/// <summary>
|
||||
/// 得到一个人员的主要组织显示
|
||||
/// </summary>
|
||||
/// <param name="id">人员ID</param>
|
||||
/// <param name="isShowRoot">是否显示根</param>
|
||||
/// <returns></returns>
|
||||
public Dictionary<string, string> GetOrganizeMainShowHtml(IEnumerable<string> ids, bool isShowRoot = true);
|
||||
}
|
||||
}
|
||||
269
20220330_Vote/Ewide.RoadFlow/Data/Organize/Organize.cs
Normal file
269
20220330_Vote/Ewide.RoadFlow/Data/Organize/Organize.cs
Normal file
@@ -0,0 +1,269 @@
|
||||
using Ewide.Core;
|
||||
using Furion;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DependencyInjection;
|
||||
using RoadFlow.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RoadFlow.Data
|
||||
{
|
||||
public class Organize:IOrganize, ITransient
|
||||
{
|
||||
private readonly IRepository<SysUser> _sysUserRep = App.GetService<IRepository<SysUser>>(); // 用户表仓储
|
||||
private readonly IRepository<SysOrg> _sysOrgRep = App.GetService<IRepository<SysOrg>>();
|
||||
private readonly IRepository<SysEmp> _sysEmpRep = App.GetService<IRepository<SysEmp>>();
|
||||
private readonly IRepository<SysEmpExtOrgPos> _sysEmpExtOrgPosRep = App.GetService<IRepository<SysEmpExtOrgPos>>();
|
||||
private readonly IUserManager _userManager = App.GetService<IUserManager>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID字符串得到所有人员ID
|
||||
/// </summary>
|
||||
/// <param name="idString">u_人员,id,w_工作且,r_兼职</param>
|
||||
/// <returns>逗号分开的ID</returns>
|
||||
public string GetAllUsersId(string idString)
|
||||
{
|
||||
var users = GetAllUsers(idString);
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
foreach (var user in users)
|
||||
{
|
||||
stringBuilder.Append(user.Id);
|
||||
stringBuilder.Append(",");
|
||||
}
|
||||
return stringBuilder.ToString().TrimEnd(',');
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到一个机构下所有人员
|
||||
/// </summary>
|
||||
/// <param name="id">机构ID</param>
|
||||
/// <param name="hasPartTime">是否包含兼任人员</param>
|
||||
/// <returns></returns>
|
||||
public List<SysUser> GetAllUsers(string id, bool hasPartTime = true)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(id)&&id.StartsWith(IOrganize.PREFIX_USER))
|
||||
return _sysUserRep.DetachedEntities.Where(x => x.Id == id.RemoveUserPrefix()).ToList();
|
||||
|
||||
var allChilds = GetAllChilds(id, true);
|
||||
List<string> orgids = new List<string>();
|
||||
foreach (var child in allChilds)
|
||||
{
|
||||
orgids.Add(child.Id);
|
||||
}
|
||||
List<string> userIds = new List<string>();
|
||||
var empList =_sysEmpRep.DetachedEntities.Where(x => orgids.Contains(x.OrgId)).ToList();
|
||||
foreach (var emp in empList)
|
||||
userIds.Add(emp.Id);
|
||||
if (hasPartTime)
|
||||
{
|
||||
var empExtList = _sysEmpExtOrgPosRep.DetachedEntities.Where(x => orgids.Contains(x.SysOrgId)).ToList();
|
||||
foreach (var emp in empExtList)
|
||||
userIds.Add(emp.SysEmpId);
|
||||
}
|
||||
|
||||
return _sysUserRep.DetachedEntities.Where(x => userIds.Contains(x.Id)).ToList();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 得到所有下级组织机构
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="isMe">是否包含自己</param>
|
||||
/// <returns></returns>
|
||||
public List<SysOrg> GetAllChilds(string id, bool isMe = false)
|
||||
{
|
||||
List<SysOrg> organizes = new List<SysOrg>();
|
||||
var org = Get(id);
|
||||
if (null == org)
|
||||
{
|
||||
return organizes;
|
||||
}
|
||||
if (isMe)
|
||||
{
|
||||
organizes.Add(org);
|
||||
}
|
||||
var all = _sysOrgRep.DetachedEntities.ToList();//GetAll();
|
||||
AddChilds(org, organizes, all);
|
||||
return organizes;
|
||||
}
|
||||
private void AddChilds(SysOrg organize, List<SysOrg> organizes, List<SysOrg> all)
|
||||
{
|
||||
if (null == organize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var childs = all.FindAll(p => p.Pid == organize.Id).OrderBy(p => p.Sort).ToList();
|
||||
foreach (var child in childs)
|
||||
{
|
||||
organizes.Add(child);
|
||||
AddChilds(child, organizes, all);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据ID查询一个组织机构
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public SysOrg Get(string id)
|
||||
{
|
||||
return _sysOrgRep.DetachedEntities.FirstOrDefault(x=>x.Id ==id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据JSON字符串得到组织机构选择属性
|
||||
/// </summary>
|
||||
/// <param name="json">例:{"dept":"1","station":"0"}</param>
|
||||
/// <returns>dept="1" station="0"</returns>
|
||||
public string GetOrganizeAttrString(string json)
|
||||
{
|
||||
Newtonsoft.Json.Linq.JObject jObject = null;
|
||||
try
|
||||
{
|
||||
jObject = Newtonsoft.Json.Linq.JObject.Parse(json);
|
||||
}
|
||||
catch { }
|
||||
if (null == jObject)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
string unit = jObject.Value<string>("unit");
|
||||
string dept = jObject.Value<string>("dept");
|
||||
string station = jObject.Value<string>("station");
|
||||
string user = jObject.Value<string>("user");
|
||||
string more = jObject.Value<string>("more");
|
||||
string group = jObject.Value<string>("group");
|
||||
string role = jObject.Value<string>("role");
|
||||
string rootid = jObject.Value<string>("rootid");
|
||||
stringBuilder.Append(" unit=\"" + (unit.IsNullOrWhiteSpace() ? "0" : unit) + "\"");
|
||||
stringBuilder.Append(" dept=\"" + (dept.IsNullOrWhiteSpace() ? "0" : dept) + "\"");
|
||||
stringBuilder.Append(" station=\"" + (station.IsNullOrWhiteSpace() ? "0" : station) + "\"");
|
||||
stringBuilder.Append(" user=\"" + (user.IsNullOrWhiteSpace() ? "0" : user) + "\"");
|
||||
stringBuilder.Append(" more=\"" + (more.IsNullOrWhiteSpace() ? "0" : more) + "\"");
|
||||
stringBuilder.Append(" group=\"" + (group.IsNullOrWhiteSpace() ? "0" : group) + "\"");
|
||||
stringBuilder.Append(" role=\"" + (role.IsNullOrWhiteSpace() ? "0" : role) + "\"");
|
||||
stringBuilder.Append(" rootid=\"" + (rootid.IsNullOrWhiteSpace() ? "" : rootid) + "\"");
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID字符串得到名称
|
||||
/// </summary>
|
||||
/// <param name="idString">逗号分开的人员ID,机构ID,工作组ID等</param>
|
||||
/// <param name="splitChar">多个名称之前的分隔字符</param>
|
||||
/// <returns></returns>
|
||||
public string GetNames(string idString, string splitChar = "、")
|
||||
{
|
||||
if (idString.IsNullOrWhiteSpace())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
foreach (string id in idString.Split(','))
|
||||
{
|
||||
if (id.IsGuid(out Guid orgId))
|
||||
{
|
||||
stringBuilder.Append(_sysOrgRep.DetachedEntities.FirstOrDefault(x => x.Id == id)?.Name);
|
||||
stringBuilder.Append(splitChar);
|
||||
}
|
||||
else if (id.StartsWith(IOrganize.PREFIX_USER))
|
||||
{
|
||||
stringBuilder.Append(_sysUserRep.DetachedEntities.FirstOrDefault(x=>x.Id==id.RemoveUserPrefix())?.Name);
|
||||
stringBuilder.Append(splitChar);
|
||||
}
|
||||
else if (id.StartsWith(IOrganize.PREFIX_RELATION))
|
||||
{
|
||||
|
||||
stringBuilder.Append(_sysUserRep.DetachedEntities.FirstOrDefault(x => x.Id == id.RemoveUserRelationPrefix())?.Name);
|
||||
stringBuilder.Append(splitChar);
|
||||
|
||||
}
|
||||
else if (id.StartsWith(IOrganize.PREFIX_WORKGROUP))
|
||||
{
|
||||
/* 无workgroup
|
||||
stringBuilder.Append(workGroup.GetName(id.RemoveWorkGroupPrefix().ToGuid()));
|
||||
stringBuilder.Append(splitChar);
|
||||
*/
|
||||
}
|
||||
}
|
||||
return stringBuilder.ToString().TrimEnd(splitChar.ToCharArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到一个人员的主要组织显示
|
||||
/// </summary>
|
||||
/// <param name="id">人员ID</param>
|
||||
/// <param name="isShowRoot">是否显示根</param>
|
||||
/// <returns></returns>
|
||||
public string GetOrganizeMainShowHtml(string id, bool isShowRoot = true)
|
||||
{
|
||||
var emp =_sysEmpRep.DetachedEntities.FirstOrDefault(x => x.Id == id);
|
||||
if (emp == null)
|
||||
return "";
|
||||
var org = _sysOrgRep.DetachedEntities.FirstOrDefault(x=>x.Id==emp.OrgId);
|
||||
string[] pararr = org.Pids.TrimStart('[').TrimEnd(',',']').Split("],[");
|
||||
var parents = _sysOrgRep.DetachedEntities.Where(x => pararr.Contains(x.Id));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var tmp = org;
|
||||
while (tmp.Pid != "00000000 - 0000 - 0000 - 0000 - 000000000000")
|
||||
{
|
||||
sb.Insert(0, "\\" + tmp.Name);
|
||||
tmp = parents.FirstOrDefault(x => x.Id == tmp.Pid);
|
||||
}
|
||||
if(isShowRoot)
|
||||
sb.Insert(0, tmp.Name);
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到一个人员的主要组织显示
|
||||
/// </summary>
|
||||
/// <param name="id">人员ID</param>
|
||||
/// <param name="isShowRoot">是否显示根</param>
|
||||
/// <returns></returns>
|
||||
public Dictionary<string,string> GetOrganizeMainShowHtml(IEnumerable<string> ids, bool isShowRoot = true)
|
||||
{
|
||||
var emps =_sysEmpRep.DetachedEntities.ToList();
|
||||
var orgs = _sysOrgRep.DetachedEntities.ToList();
|
||||
Dictionary<string, string> rtn = new Dictionary<string, string>();
|
||||
foreach (string id in ids)
|
||||
{
|
||||
var emp =emps.FirstOrDefault(x => x.Id == id);
|
||||
if (emp == null)
|
||||
rtn.Add(id, "");
|
||||
else
|
||||
{
|
||||
string orgId = emp.OrgId;
|
||||
var org =orgs.FirstOrDefault(x => x.Id == orgId);
|
||||
if (org == null)
|
||||
{
|
||||
rtn.Add(id, "");
|
||||
continue;
|
||||
}
|
||||
string[] pararr = org.Pids.TrimStart('[').TrimEnd(',', ']').Split("],[");
|
||||
var parents = orgs.Where(x => pararr.Contains(x.Id));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var tmp = org;
|
||||
while (tmp.Pid != "00000000 - 0000 - 0000 - 0000 - 000000000000")
|
||||
{
|
||||
sb.Insert(0, "\\" + tmp.Name);
|
||||
tmp = parents.FirstOrDefault(x => x.Id == tmp.Pid);
|
||||
}
|
||||
if(isShowRoot)
|
||||
sb.Insert(0, tmp.Name);
|
||||
rtn.Add(id, sb.ToString());
|
||||
}
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user