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.
449 lines
18 KiB
449 lines
18 KiB
using System;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using QMFrameWork.Data;
|
|
using QMAPP.Entity.Sys;
|
|
using QMAPP.Entity.Sys.Entity;
|
|
using QMAPP.DAL.Sys;
|
|
|
|
namespace QMAPP.DAL.Sys
|
|
{
|
|
/// </summary>
|
|
/// 用户委托授权
|
|
/// 作 者:李炳海
|
|
/// 编写日期:2015年01月07日
|
|
/// </summary>
|
|
public class UserEntrustDAL:BaseDAL
|
|
{
|
|
#region 获取信息
|
|
/// <summary>
|
|
/// 获取信息
|
|
/// </summary>
|
|
/// <param name="">条件</param>
|
|
/// <returns>*信息</returns>
|
|
public UserEntrust Get(UserEntrust info)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters=new List<DataParameter>();
|
|
StringBuilder sqlBuilder = new System.Text.StringBuilder();
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
sql = @"SELECT T1.*,T2.LOGINUSERID AS ENTRUSTUSER,T2.USERNAME AS ENTRUSTUSERNAME,T3.LOGINUSERID AS AGENTUSER,T3.USERNAME AS AGENTUSERNAME
|
|
FROM T_QM_USERENTRUST T1,T_QM_USER T2,T_QM_USER T3
|
|
WHERE T1.ENTRUSTUSERID = T2.USERID AND T1.AGENTUSERID = T3.USERID AND T1.PID = @ENTRUSTPID ";
|
|
sql = this.ChangeSqlByDB(sql, session);
|
|
info = session.Get<UserEntrust>(sql,new DataParameter("ENTRUSTPID",info.PID));
|
|
|
|
if (string.IsNullOrEmpty(info.ENTRUSTUSERID) == false)
|
|
{
|
|
//获取系统权限信息
|
|
sql = @"SELECT T1.*
|
|
FROM T_QM_ENTRUSTAUTHORITY T1
|
|
WHERE T1.ENTRUSTPID = @ENTRUSTPID";
|
|
sql = this.ChangeSqlByDB(sql, session);
|
|
parameters.Add(new DataParameter("ENTRUSTPID", info.PID));
|
|
info.Authoritys = session.GetList<T_QM_ENTRUSTAUTHORITY>(sql, parameters.ToArray()).ToList();
|
|
|
|
//获取委托用户权限
|
|
parameters = new List<DataParameter>();
|
|
sqlBuilder.Append("SELECT AUTHORITYID FROM T_QM_USERAUTHORITY WHERE USERID=@USERID ");
|
|
sqlBuilder.Append(" union ");
|
|
sqlBuilder.Append(" SELECT AUTHORITYID FROM T_QM_ROLEAUTHORITY ");
|
|
sqlBuilder.Append(" where exists (select * from T_QM_USERROLE where T_QM_ROLEAUTHORITY.ROLEID ");
|
|
sqlBuilder.Append(" =T_QM_USERROLE.ROLEID and T_QM_USERROLE.USERID =@USERID)");
|
|
sqlBuilder.Append(" union ");
|
|
sqlBuilder.Append("SELECT AUTHORITYID FROM T_QM_ORGAIZATIONAUTHORITY ");
|
|
sqlBuilder.Append(" where exists (select * from T_QM_USERORGAIZATION where T_QM_ORGAIZATIONAUTHORITY.ORGAID ");
|
|
sqlBuilder.Append(" =T_QM_USERORGAIZATION.ORGAID and T_QM_USERORGAIZATION.USERID =@USERID)");
|
|
parameters.Add(new DataParameter { ParameterName = "USERID", DataType = DbType.String, Value = info.ENTRUSTUSERID });
|
|
sql = sqlBuilder.ToString();
|
|
sql = this.ChangeSqlByDB(sql, session);
|
|
info.EUAuthoritys = session.GetList<UserAuthority>(sql, parameters.ToArray()).ToList();
|
|
|
|
}
|
|
|
|
}
|
|
return info;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 获取业务权限信息
|
|
|
|
/// <summary>
|
|
/// 获取业务权限信息
|
|
/// </summary>
|
|
/// <param name="info">获取条件</param>
|
|
/// <returns>业务权限信息</returns>
|
|
public UserEntrustBusiPower GetBusiInfo(UserEntrustBusiPower info)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
//获取信息
|
|
sql = @"SELECT T1.*,T2.USERNAME AS ENTRUSTUSER,T3.USERNAME AS AGENTUSER
|
|
FROM T_QM_USERENTRUST T1,T_QM_USER T2,T_QM_USER T3
|
|
WHERE T1.ENTRUSTUSERID = T2.USERID AND T1.AGENTUSERID = T3.USERID AND T1.PID = @ENTRUSTPID ";
|
|
sql = this.ChangeSqlByDB(sql, session);
|
|
info = session.Get<UserEntrustBusiPower>(sql, new DataParameter("ENTRUSTPID", info.PID));
|
|
|
|
//获取仓库权限
|
|
sql = "SELECT T1.PID AS ID,T2.CORPID,T2.CORPCODE,T2.CORPNAME FROM T_QM_PARAPOWER T1 "
|
|
+ "INNER JOIN T_BD_CORP T2 ON T1.PARAVALUE=T2.CORPID "
|
|
+ "WHERE T1.RELATIONID = @RELATIONID AND T1.PARATYPE = '1'";
|
|
parameters.Clear();
|
|
parameters.Add(new DataParameter("RELATIONID", info.PID));
|
|
sql = this.ChangeSqlByDB(sql, session);
|
|
info.CorpPowers = session.GetList<UserCorpPower>(sql, parameters.ToArray()).ToList();
|
|
|
|
//获取路线权限
|
|
sql = "SELECT T1.PID AS ID,T2.LINEID,T2.LINENO,T2.LINENAME,T2.CORPID,T3.CORPNAME FROM T_QM_PARAPOWER T1 "
|
|
+ "INNER JOIN T_BD_LINE T2 ON T1.PARAVALUE=T2.LINEID "
|
|
+ "INNER JOIN T_BD_CORP T3 ON T2.CORPID=T3.CORPID "
|
|
+ "WHERE T1.RELATIONID = @RELATIONID AND T1.PARATYPE = '2'";
|
|
parameters.Clear();
|
|
parameters.Add(new DataParameter("RELATIONID", info.PID));
|
|
sql = this.ChangeSqlByDB(sql, session);
|
|
info.LinePowers = session.GetList<UserLinePower>(sql, parameters.ToArray()).ToList();
|
|
|
|
//获取零件类别权限
|
|
sql = "SELECT T1.PID AS ID,T2.MATSORTID,T2.MATSORTNO,T2.SORTNAME AS MATSORTNAME FROM T_QM_PARAPOWER T1 "
|
|
+ "INNER JOIN T_BD_MATERIALSORT T2 ON T1.PARAVALUE=T2.MATSORTID "
|
|
+ "WHERE T1.RELATIONID = @RELATIONID AND T1.PARATYPE = '3'";
|
|
parameters.Clear();
|
|
parameters.Add(new DataParameter("RELATIONID", info.PID));
|
|
sql = this.ChangeSqlByDB(sql, session);
|
|
info.MatSortPowers = session.GetList<UserMatSortPower>(sql, parameters.ToArray()).ToList();
|
|
|
|
//获取要货地权限
|
|
sql = "SELECT T1.PID AS ID,T2.PLACEDISID,T2.PLACEDISNO,T2.DESCRIBE_SITE AS DESCRIBE_SITE FROM T_QM_PARAPOWER T1 "
|
|
+ "INNER JOIN T_BD_PLACEDISCHARGE T2 ON T1.PARAVALUE=T2.PLACEDISID "
|
|
+ "WHERE T1.RELATIONID = @RELATIONID AND T1.PARATYPE = '4'";
|
|
parameters.Clear();
|
|
parameters.Add(new DataParameter("RELATIONID", info.PID));
|
|
sql = this.ChangeSqlByDB(sql, session);
|
|
info.ReqPlacePowers = session.GetList<UserReqPlacePower>(sql, parameters.ToArray()).ToList();
|
|
|
|
//获发要货地权限
|
|
sql = "SELECT T1.PID AS ID,T2.SENDPLACEID,T2.SENDPLACENO,T2.SENDPLACENAME AS SENDPLACENAME FROM T_QM_PARAPOWER T1 "
|
|
+ "INNER JOIN T_BD_HMATSENDPLACE T2 ON T1.PARAVALUE=T2.SENDPLACEID "
|
|
+ "WHERE T1.RELATIONID = @RELATIONID AND T1.PARATYPE = '5'";
|
|
parameters.Clear();
|
|
parameters.Add(new DataParameter("RELATIONID", info.PID));
|
|
sql = this.ChangeSqlByDB(sql, session);
|
|
info.SendPlacePowers = session.GetList<UserSendPlacePower>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
|
|
return info;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 获取列表
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataPage GetList(UserEntrust condition, DataPage page)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition,parameters);
|
|
//分页关键字段及排序
|
|
page.KeyName = "PID";
|
|
if (string.IsNullOrEmpty(page.SortExpression))
|
|
{
|
|
page.SortExpression = "UPDATEDATE DESC";
|
|
}
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
sql = this.ChangeSqlByDB(sql, session);
|
|
page = session.GetDataPage<UserEntrust>(sql, parameters.ToArray(), page);
|
|
}
|
|
return page;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取查询语句
|
|
/// <summary>
|
|
/// 获取查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetQuerySql(UserEntrust condition,List<DataParameter> parameters)
|
|
{
|
|
string sql = "";
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sql = @"SELECT T1.PID,(SELECT USERNAME FROM T_QM_USER WHERE USERID = T1.ENTRUSTUSERID) AS ENTRUSTUSERID
|
|
,(SELECT USERNAME FROM T_QM_USER WHERE USERID = T1.AGENTUSERID) AS AGENTUSERID,T1.STARTTIME,T1.ENDTIME,T1.ENTRUSTREASON
|
|
,T1.VALIDFLG,(SELECT USERNAME FROM T_QM_USER WHERE USERID = T1.CREATEUSER) AS CREATEUSER
|
|
,T1.CREATEDATE,(SELECT USERNAME FROM T_QM_USER WHERE USERID = T1.UPDATEUSER) AS UPDATEUSER,T1.UPDATEDATE
|
|
FROM T_QM_USERENTRUST T1
|
|
WHERE FLGDEL<>1";
|
|
|
|
//查询条件
|
|
if (string.IsNullOrEmpty(condition.ENTRUSTUSERID) == false)
|
|
{
|
|
whereBuilder.Append(" AND T1.ENTRUSTUSERID = @ENTRUSTUSERID");
|
|
parameters.Add(new DataParameter { ParameterName = "ENTRUSTUSERID", DataType = DbType.String, Value = condition.ENTRUSTUSERID });
|
|
}
|
|
if (string.IsNullOrEmpty(condition.AGENTUSERID) == false)
|
|
{
|
|
whereBuilder.Append(" AND T1.AGENTUSERID LIKE @AGENTUSERID");
|
|
parameters.Add(new DataParameter { ParameterName = "AGENTUSERID", DataType = DbType.String, Value = condition.AGENTUSERID });
|
|
}
|
|
if (condition.STARTTIME != new DateTime())
|
|
{
|
|
whereBuilder.Append(" AND T1.STARTTIME >= @STARTTIME");
|
|
parameters.Add(new DataParameter { ParameterName = "STARTTIME", DataType = DbType.DateTime, Value = condition.STARTTIME });
|
|
}
|
|
if (condition.ENDTIME != new DateTime())
|
|
{
|
|
whereBuilder.Append(" AND T1.STARTTIME <= @ENDTIME");
|
|
parameters.Add(new DataParameter { ParameterName = "ENDTIME", DataType = DbType.DateTime, Value = condition.ENDTIME });
|
|
}
|
|
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sql+=" AND " + whereBuilder.ToString().Substring(4);
|
|
}
|
|
|
|
return sql;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取导出的数据
|
|
/// <summary>
|
|
/// 获取导出的数据
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <returns>数据</returns>
|
|
public DataTable GetExportData(UserEntrust info)
|
|
{
|
|
DataTable dt = null;
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sql = this.GetQuerySql(info,parameters);
|
|
sql += " ORDER BY UPDATEDATE DESC ";
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
sql = this.ChangeSqlByDB(sql, session);
|
|
dt = session.GetTable(sql, parameters.ToArray());
|
|
dt.TableName = "T_QM_USERENTRUST";
|
|
}
|
|
return dt;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 插入信息
|
|
/// <summary>
|
|
/// 插入信息(单表)
|
|
/// </summary>
|
|
/// <param name="">信息</param>
|
|
/// <returns>插入行数</returns>
|
|
public int Insert(UserEntrust info)
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
this.BaseSession = session;
|
|
|
|
session.OpenTs();
|
|
|
|
//插入基本信息
|
|
count = this.InsertWithMark<UserEntrust>(info);
|
|
|
|
//插入系统权限信息
|
|
if (info.Authoritys!=null)
|
|
session.Insert<T_QM_ENTRUSTAUTHORITY>(info.Authoritys);
|
|
|
|
////插入业务权限信息
|
|
//if (info.BusinessPowers != null)
|
|
//{
|
|
// session.Insert<ParaAuthorityPort>(info.BusinessPowers);
|
|
//}
|
|
|
|
session.CommitTs();
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 更新信息
|
|
/// <summary>
|
|
/// 更新信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>更新行数</returns>
|
|
public int Update(UserEntrust info)
|
|
{
|
|
int count = 0;
|
|
string sql = null;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
session.OpenTs();
|
|
|
|
this.BaseSession = session;
|
|
|
|
//更新基本信息
|
|
count = this.UpdateWithMark<UserEntrust>(info);
|
|
|
|
//删除原系统权限信息
|
|
sql = "DELETE FROM T_QM_ENTRUSTAUTHORITY WHERE ENTRUSTPID = @ENTRUSTPID";
|
|
sql = this.ChangeSqlByDB(sql, session);
|
|
session.ExecuteSql(sql, new DataParameter("ENTRUSTPID",info.PID));
|
|
|
|
//插入系统权限信息
|
|
session.Insert<T_QM_ENTRUSTAUTHORITY>(info.Authoritys);
|
|
|
|
////删除原业务权限信息
|
|
//sql = "DELETE FROM T_QM_PARAPOWER WHERE RELATIONID = @ENTRUSTPID";
|
|
//sql = this.ChangeSqlByDB(sql, session);
|
|
//session.ExecuteSql(sql, new DataParameter("ENTRUSTPID", info.PID));
|
|
|
|
////插入业务权限信息
|
|
//session.Insert<ParaAuthorityPort>(info.BusinessPowers);
|
|
|
|
session.CommitTs();
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 删除
|
|
/// <summary>
|
|
/// 删除信息
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns>删除个数</returns>
|
|
public int Delete(UserEntrust info)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
int count = 0;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
session.OpenTs();
|
|
|
|
this.BaseSession = session;
|
|
//删除基本信息
|
|
count=this.DeleteWithMark<UserEntrust>(info);
|
|
|
|
//删除系统权限信息
|
|
sql = "DELETE FROM T_QM_ENTRUSTAUTHORITY WHERE ENTRUSTPID = @ENTRUSTPID";
|
|
sql = this.ChangeSqlByDB(sql, session);
|
|
session.ExecuteSql(sql, new DataParameter("ENTRUSTPID", info.PID));
|
|
|
|
////删除原业务权限信息
|
|
//sql = "DELETE FROM T_QM_PARAPOWER WHERE RELATIONID = @ENTRUSTPID";
|
|
//sql = this.ChangeSqlByDB(sql, session);
|
|
//session.ExecuteSql(sql, new DataParameter("ENTRUSTPID", info.PID));
|
|
|
|
session.CommitTs();
|
|
}
|
|
return count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 保存业务数据权限
|
|
|
|
/// <summary>
|
|
/// 保存业务数据权限
|
|
/// </summary>
|
|
/// <param name="info">业务数据权限</param>
|
|
public void SaveBusinessPower(UserEntrustBusiPower info)
|
|
{
|
|
string sql = null;
|
|
try
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
session.OpenTs();
|
|
|
|
////保存基本信息
|
|
//session.Update<UserEntrustBusiPower>(info);
|
|
|
|
//保存业务权限信息
|
|
sql = "DELETE FROM T_QM_PARAPOWER WHERE RELATIONID = :RELATIONID";
|
|
session.ExecuteSql(sql, new DataParameter("RELATIONID", info.PID));
|
|
session.Insert<ParaAuthorityPort>(info.BusinessPowers);
|
|
|
|
session.CommitTs();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
|