You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
577 lines
18 KiB
577 lines
18 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System.Text;
|
|
|
|
namespace RoadFlow.Platform
|
|
{
|
|
public class Users
|
|
{
|
|
/// <summary>
|
|
/// 前缀
|
|
/// </summary>
|
|
public const string PREFIX = "u_";
|
|
private RoadFlow.Data.Interface.IUsers dataUsers;
|
|
public Users()
|
|
{
|
|
this.dataUsers = Data.Factory.Factory.GetUsers();
|
|
}
|
|
/// <summary>
|
|
/// 新增
|
|
/// </summary>
|
|
public int Add(RoadFlow.Data.Model.Users model)
|
|
{
|
|
return dataUsers.Add(model);
|
|
}
|
|
/// <summary>
|
|
/// 更新
|
|
/// </summary>
|
|
public int Update(RoadFlow.Data.Model.Users model)
|
|
{
|
|
return dataUsers.Update(model);
|
|
}
|
|
/// <summary>
|
|
/// 查询所有记录
|
|
/// </summary>
|
|
public List<RoadFlow.Data.Model.Users> GetAll()
|
|
{
|
|
return dataUsers.GetAll();
|
|
}
|
|
/// <summary>
|
|
/// 查询单条记录
|
|
/// </summary>
|
|
public FangYar.Model.TBL.TBL_SYS_USERS_Model Get(string id)
|
|
{
|
|
FangYar.BLL.TBL.SysUsersBLL userbll = new FangYar.BLL.TBL.SysUsersBLL();
|
|
return userbll.GetModelByUID(id.Replace("u_",""));
|
|
}
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
public int Delete(string id)
|
|
{
|
|
return dataUsers.Delete(id);
|
|
}
|
|
/// <summary>
|
|
/// 查询记录条数
|
|
/// </summary>
|
|
public long GetCount()
|
|
{
|
|
return dataUsers.GetCount();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据帐号查询一条记录
|
|
/// </summary>
|
|
public RoadFlow.Data.Model.Users GetByAccount2(string Account2)
|
|
{
|
|
return Account2.IsNullOrEmpty() ? null : dataUsers.GetByAccount2(Account2);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 得到系统初始密码
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetInitPassword()
|
|
{
|
|
return RoadFlow.Utility.Config.SystemInitPassword;
|
|
}
|
|
/// <summary>
|
|
/// 得到加密后的密码字符串
|
|
/// </summary>
|
|
/// <param name="password"></param>
|
|
/// <returns></returns>
|
|
public string EncryptionPassword(string password)
|
|
{
|
|
if (password.IsNullOrEmpty())
|
|
{
|
|
return "";
|
|
}
|
|
RoadFlow.Utility.HashEncrypt hash = new RoadFlow.Utility.HashEncrypt();
|
|
return hash.MD5System(hash.MD5System(password)); //hash.SHA512Encrypt(hash.SHA512Encrypt(password.Trim()));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 得到一个用户加密后的密码
|
|
/// </summary>
|
|
/// <param name="userID"></param>
|
|
/// <param name="password"></param>
|
|
/// <returns></returns>
|
|
public string GetUserEncryptionPassword(string userID, string password)
|
|
{
|
|
return password.IsNullOrEmpty() || userID.IsNullOrEmpty() ? "" : EncryptionPassword(userID.Trim().ToLower() + password.Trim());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化一个用户密码
|
|
/// </summary>
|
|
/// <param name="userID"></param>
|
|
/// <returns></returns>
|
|
public bool InitPassword(Guid userID)
|
|
{
|
|
return dataUsers.UpdatePassword(GetUserEncryptionPassword(userID.ToString(), GetInitPassword()), userID);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询一个岗位下所有人员
|
|
/// </summary>
|
|
/// <param name="organizeID"></param>
|
|
/// <returns></returns>
|
|
public List<RoadFlow.Data.Model.Users> GetAllByOrganizeID(string organizeID)
|
|
{
|
|
return dataUsers.GetAllByOrganizeID(organizeID);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 得到一个用户的所有岗位
|
|
/// </summary>
|
|
/// <param name="userID"></param>
|
|
/// <returns>Dictionary<Guid, bool> Guid 岗位ID bool 是否主要岗位</returns>
|
|
public Dictionary<string, bool> GetAllStation(string userID)
|
|
{
|
|
UsersRelation ur = new UsersRelation();
|
|
var urs = ur.GetAllByUserID(userID);
|
|
Dictionary<string, bool> dict = new Dictionary<string, bool>();
|
|
foreach (var u in urs)
|
|
{
|
|
if (!dict.ContainsKey(u.OrganizeID))
|
|
{
|
|
dict.Add(u.OrganizeID, u.IsMain == 1);
|
|
}
|
|
}
|
|
return dict;
|
|
}
|
|
/// <summary>
|
|
/// 得到一个用户的主要岗位
|
|
/// </summary>
|
|
/// <param name="userID"></param>
|
|
/// <returns></returns>
|
|
public string GetMainStation(string userID)
|
|
{
|
|
var ur = new UsersRelation().GetMainByUserID(userID);
|
|
return ur == null ? "" : ur.OrganizeID;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询一组岗位下所有人员
|
|
/// </summary>
|
|
/// <param name="organizeID"></param>
|
|
/// <returns></returns>
|
|
public List<RoadFlow.Data.Model.Users> GetAllByOrganizeIDArray(string[] organizeIDArray)
|
|
{
|
|
return dataUsers.GetAllByOrganizeIDArray(organizeIDArray);
|
|
}
|
|
|
|
///// <summary>
|
|
///// 得到一个用户所在部门
|
|
///// </summary>
|
|
///// <param name="userID"></param>
|
|
///// <returns></returns>
|
|
//public RoadFlow.Data.Model.Organize GetDeptByUserID(string userID)
|
|
//{
|
|
// string stationID =GetMainStation(userID);
|
|
// if(stationID=="")
|
|
// {
|
|
// return null;
|
|
// }
|
|
// var parents = new RoadFlow.Platform.Organize().GetAllParent(stationID);
|
|
// parents.Reverse();
|
|
// foreach (var parent in parents)
|
|
// {
|
|
// if (parent.Type == 2 || parent.Type==1)
|
|
// {
|
|
// return parent;
|
|
// }
|
|
// }
|
|
// return null;
|
|
//}
|
|
/// <summary>
|
|
/// 得到一个用户所在部门
|
|
/// </summary>
|
|
/// <param name="userID"></param>
|
|
/// <returns></returns>
|
|
public FangYar.Model.TBL.TBL_SYS_EMP_Model GetDeptByUserID(string userID)
|
|
{
|
|
FangYar.BLL.TBL.SysEmpBLL empBll = new FangYar.BLL.TBL.SysEmpBLL();
|
|
return empBll.GetModelByUserID("", userID);
|
|
//string stationID =GetMainStation(userID);
|
|
//if(stationID=="")
|
|
//{
|
|
// return null;
|
|
//}
|
|
//var parents = new RoadFlow.Platform.Organize().GetAllParent(stationID);
|
|
//parents.Reverse();
|
|
//foreach (var parent in parents)
|
|
//{
|
|
// if (parent.Type == 2 || parent.Type==1)
|
|
// {
|
|
// return parent;
|
|
// }
|
|
//}
|
|
//return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 当前用户机构ID
|
|
/// </summary>
|
|
public static string CurrentOrgID
|
|
{
|
|
get
|
|
{
|
|
var org = new Users().GetDeptByUserID(CurrentUserID);
|
|
return org == null ? "" : org.ORG_ID;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 当前用户机构名称
|
|
/// </summary>
|
|
public static string CurrentOrgName
|
|
{
|
|
get
|
|
{
|
|
var org = new Users().GetDeptByUserID(CurrentUserID);
|
|
return org == null ? "" : (org.ORG_NAME == null ? "" : org.ORG_NAME);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 当前用户部门ID
|
|
/// </summary>
|
|
public static string CurrentDeptID
|
|
{
|
|
get
|
|
{
|
|
var dept = new Users().GetDeptByUserID(CurrentUserID);
|
|
return dept == null ? "" : dept.DEPT_ID;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 当前用户部门名称
|
|
/// </summary>
|
|
public static string CurrentDeptName
|
|
{
|
|
get
|
|
{
|
|
var dept = new Users().GetDeptByUserID(CurrentUserID);
|
|
return dept == null ? "" : dept.DEPT_NAME;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 当前用户手机号
|
|
/// </summary>
|
|
public static string CurrentMobile
|
|
{
|
|
get
|
|
{
|
|
var emp = new Users().GetDeptByUserID(CurrentUserID);
|
|
return emp == null ? "" : (emp.EMP_MOBILE == null ? "" : emp.EMP_MOBILE);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检查帐号是否重复
|
|
/// </summary>
|
|
/// <param name="Account2">帐号</param>
|
|
/// <param name="userID">人员ID(此人员除外)</param>
|
|
/// <returns></returns>
|
|
public bool HasAccount2(string Account2, string userID = "")
|
|
{
|
|
return Account2.IsNullOrEmpty() ? false : dataUsers.HasAccount2(Account2.Trim(), userID);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改用户密码
|
|
/// </summary>
|
|
/// <param name="password">明文的密码</param>
|
|
/// <param name="userID"></param>
|
|
/// <returns></returns>
|
|
public bool UpdatePassword(string password, Guid userID)
|
|
{
|
|
return password.IsNullOrEmpty() ? false : dataUsers.UpdatePassword(GetUserEncryptionPassword(userID.ToString(), password.Trim()), userID);
|
|
}
|
|
/// <summary>
|
|
/// 得到当前登录用户ID
|
|
/// </summary>
|
|
public static string CurrentUserID
|
|
{
|
|
get
|
|
{
|
|
try
|
|
{
|
|
object session = null;
|
|
if (System.Web.HttpContext.Current.Session != null)
|
|
{
|
|
session = System.Web.HttpContext.Current.Session[RoadFlow.Utility.Keys.SessionKeys.UserID.ToString()];
|
|
if (session == null)
|
|
{
|
|
string kn_root_cookie = System.Web.HttpContext.Current.Request.Cookies["kn_root_cookie"].Value;
|
|
JObject obj = (JObject)JsonConvert.DeserializeObject(kn_root_cookie);
|
|
string usersUid = (string)obj["usersUid"];
|
|
return usersUid == null ? "" : usersUid;
|
|
}
|
|
}
|
|
return session == null ? "" : session.ToString();
|
|
}
|
|
catch { return ""; }
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 得到当前登录用户
|
|
/// </summary>
|
|
public static FangYar.Model.TBL.TBL_SYS_USERS_Model CurrentUser
|
|
{
|
|
get
|
|
{
|
|
try
|
|
{
|
|
object obj = System.Web.HttpContext.Current.Session[RoadFlow.Utility.Keys.SessionKeys.User.ToString()];
|
|
if (obj == null)
|
|
{
|
|
string userID = CurrentUserID;
|
|
if (userID == null || userID == "")
|
|
{
|
|
return null;
|
|
}
|
|
else
|
|
{
|
|
|
|
FangYar.BLL.TBL.SysUsersBLL userbll = new FangYar.BLL.TBL.SysUsersBLL();
|
|
var user = userbll.GetModelByUID(userID);
|
|
if (user != null)
|
|
{
|
|
System.Web.HttpContext.Current.Session[RoadFlow.Utility.Keys.SessionKeys.User.ToString()] = user;
|
|
}
|
|
return user;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return obj as FangYar.Model.TBL.TBL_SYS_USERS_Model;
|
|
}
|
|
}
|
|
catch (Exception ex) { return null; }
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 当前用户名称
|
|
/// </summary>
|
|
[Obsolete("由于该方法拼写错误,请使用CurrentUserName属性")]
|
|
public static string CurrentUsreName
|
|
{
|
|
get
|
|
{
|
|
return CurrentUser == null ? "" : CurrentUser.USERS_NAME;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 当前用户名称
|
|
/// </summary>
|
|
public static string CurrentUserName
|
|
{
|
|
get
|
|
{
|
|
return CurrentUser == null ? "" : CurrentUser.USERS_NAME;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 当前用户的所有角色
|
|
/// </summary>
|
|
public static List<Guid> CurrentUserRoles
|
|
{
|
|
get
|
|
{
|
|
string userID = CurrentUserID;
|
|
if (userID == null || userID == "")
|
|
{
|
|
return new List<Guid>();
|
|
}
|
|
List<Guid> list = new List<Guid>();
|
|
var userRoles = new UsersRole().GetByUserIDFromCache(userID);
|
|
foreach (var userRole in userRoles)
|
|
{
|
|
list.Add(userRole.RoleID);
|
|
}
|
|
return list;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 得到一个不重复的帐号
|
|
/// </summary>
|
|
/// <param name="Account2"></param>
|
|
/// <returns></returns>
|
|
public string GetAccount2(string Account2)
|
|
{
|
|
if (Account2.IsNullOrEmpty())
|
|
{
|
|
return "";
|
|
}
|
|
string newAccount2 = Account2.Trim();
|
|
int i = 0;
|
|
while (HasAccount2(newAccount2))
|
|
{
|
|
newAccount2 += (++i).ToString();
|
|
}
|
|
return newAccount2;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新排序
|
|
/// </summary>
|
|
public int UpdateSort(Guid userID, int sort)
|
|
{
|
|
return dataUsers.UpdateSort(userID, sort);
|
|
}
|
|
/// <summary>
|
|
/// 根据ID得到名称
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public string GetName(string id)
|
|
{
|
|
var user = Get(id);
|
|
return user == null ? "" : user.USERS_NAME;
|
|
}
|
|
/// <summary>
|
|
/// 去除ID前缀
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public static string RemovePrefix(string id)
|
|
{
|
|
return id.IsNullOrEmpty() ? "" : id.Replace(PREFIX, "");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 去除ID前缀
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public string RemovePrefix1(string id)
|
|
{
|
|
return id.IsNullOrEmpty() ? "" : id.Replace(PREFIX, "");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 得到一个人员的主管
|
|
/// </summary>
|
|
/// <param name="userID"></param>
|
|
/// <returns></returns>
|
|
public string GetLeader(string userID)
|
|
{
|
|
var mainStation = GetMainStation(userID);
|
|
if (mainStation == null)
|
|
{
|
|
return "";
|
|
}
|
|
RoadFlow.Platform.Organize borg = new Organize();
|
|
var station = borg.Get(mainStation);
|
|
if (station == null)
|
|
{
|
|
return "";
|
|
}
|
|
if (!station.Leader.IsNullOrEmpty())
|
|
{
|
|
return station.Leader;
|
|
}
|
|
var parents = borg.GetAllParent(station.Number2);
|
|
foreach (var parent in parents)
|
|
{
|
|
if (!parent.Leader.IsNullOrEmpty())
|
|
{
|
|
return parent.Leader;
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 得到一个人员的分管领导
|
|
/// </summary>
|
|
/// <param name="userID"></param>
|
|
/// <returns></returns>
|
|
public string GetChargeLeader(string userID)
|
|
{
|
|
var mainStation = GetMainStation(userID);
|
|
if (mainStation == null)
|
|
{
|
|
return "";
|
|
}
|
|
RoadFlow.Platform.Organize borg = new Organize();
|
|
var station = borg.Get(mainStation);
|
|
if (station == null)
|
|
{
|
|
return "";
|
|
}
|
|
if (!station.ChargeLeader.IsNullOrEmpty())
|
|
{
|
|
return station.ChargeLeader;
|
|
}
|
|
var parents = borg.GetAllParent(station.Number2);
|
|
foreach (var parent in parents)
|
|
{
|
|
if (!parent.ChargeLeader.IsNullOrEmpty())
|
|
{
|
|
return parent.ChargeLeader;
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断一个人员是否是部门主管
|
|
/// </summary>
|
|
/// <param name="userID"></param>
|
|
/// <returns></returns>
|
|
public bool IsLeader(string userID)
|
|
{
|
|
string leader = GetLeader(userID);
|
|
return leader.Contains(userID.ToString(), StringComparison.CurrentCultureIgnoreCase);
|
|
}
|
|
/// <summary>
|
|
/// 判断一个人员是否是部门分管领导
|
|
/// </summary>
|
|
/// <param name="userID"></param>
|
|
/// <returns></returns>
|
|
public bool IsChargeLeader(string userID)
|
|
{
|
|
string leader = GetChargeLeader(userID);
|
|
return leader.Contains(userID.ToString(), StringComparison.CurrentCultureIgnoreCase);
|
|
}
|
|
/// <summary>
|
|
/// 判断一个人员是否在一个组织机构字符串里
|
|
/// </summary>
|
|
/// <param name="userID"></param>
|
|
/// <param name="memberString"></param>
|
|
/// <returns></returns>
|
|
public bool IsContains(string userID, string memberString)
|
|
{
|
|
if (memberString.IsNullOrEmpty())
|
|
{
|
|
return false;
|
|
}
|
|
var user = new Organize().GetAllUsers(memberString).Find(p => p.USERS_UID == userID);
|
|
return user != null;
|
|
}
|
|
}
|
|
|
|
public class UsersEqualityComparer : IEqualityComparer<FangYar.Model.TBL.TBL_SYS_USERS_Model>
|
|
{
|
|
public bool Equals(FangYar.Model.TBL.TBL_SYS_USERS_Model user1, FangYar.Model.TBL.TBL_SYS_USERS_Model user2)
|
|
{
|
|
return user1 == null || user2 == null || user1.USERS_UID == user2.USERS_UID;
|
|
}
|
|
public int GetHashCode(FangYar.Model.TBL.TBL_SYS_USERS_Model user)
|
|
{
|
|
return user.ToString().GetHashCode();
|
|
}
|
|
}
|
|
}
|
|
|