天津投入产出系统后端
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.
 
 
 
 
 
 

1611 lines
62 KiB

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using QMAPP.DAL;
using QMAPP.FJC.Entity.WarnManage;
using QMFrameWork.Data;
using QMFrameWork.Log;
namespace QMAPP.FJC.DAL.EquipMentAlarmManage
{
/// <summary>
/// 模块编号:M6-3
/// 作 用:自动报警维护
/// 作 者:张敬贺
/// 编写日期:2015年06月19日
///</summary>
public class WarnManageDAL : BaseDAL
{
#region 报警信息维护
#region 报警信息获取信息
/// <summary>
/// 报警信息获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public WarnInfo WarnInfoGet(WarnInfo model)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<WarnInfo>(model);
}
return model;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警信息获取信息"
});
throw;
}
}
#endregion
#region 报警信息获取列表
/// <summary>
/// 报警信息获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetWarnInfoList(WarnInfo condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetWarnInfoQuerySql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "PID";
page.SortExpression = "UPDATEDATE DESC";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<WarnInfo>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警信息获取列表"
});
throw;
}
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部集合</returns>
public List<WarnInfo> GetWarnInfoList(WarnInfo condition)
{
List<WarnInfo> list = new List<WarnInfo>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetWarnInfoQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<WarnInfo>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警信息获取列表"
});
throw;
}
}
#endregion
#region 报警信息获取查询语句
/// <summary>
/// 报警信息获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetWarnInfoQuerySql(WarnInfo condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append(@"SELECT PID
,WARNTYPE
,WARNCODE
,WARNDESCRIBE
,ISDEAL
,ISDONE
,CREATETYPE
,MEMO
,WI.CREATEDATE
,WI.CREATEUSER
,WI.UPDATEUSER
,WI.UPDATEDATE
,C.USERNAME AS CREATEUSERNAME
,U.USERNAME AS UPDATEUSERNAME
FROM T_AW_WARNINFO WI
LEFT JOIN T_QM_USER C ON C.USERID = WI.CREATEUSER
LEFT JOIN T_QM_USER U ON U.USERID = WI.UPDATEUSER ");
//查询条件
//报警类别
if (string.IsNullOrEmpty(condition.WARNTYPE) == false)
{
whereBuilder.Append(" AND WARNTYPE = @WARNTYPE ");
parameters.Add(new DataParameter { ParameterName = "WARNTYPE", DataType = DbType.String, Value = condition.WARNTYPE });
}
//报警代码
if (string.IsNullOrEmpty(condition.WARNCODE) == false)
{
whereBuilder.Append(" AND WARNCODE = @WARNCODE ");
parameters.Add(new DataParameter { ParameterName = "WARNCODE", DataType = DbType.String, Value = condition.WARNCODE });
}
//生成方式
if (string.IsNullOrEmpty(condition.CREATETYPE) == false)
{
whereBuilder.Append(" AND CREATETYPE = @CREATETYPE ");
parameters.Add(new DataParameter { ParameterName = "CREATETYPE", DataType = DbType.String, Value = condition.CREATETYPE });
}
//是否关闭
if (string.IsNullOrEmpty(condition.ISDONE) == false)
{
whereBuilder.Append(" AND ISDONE = @ISDONE ");
parameters.Add(new DataParameter { ParameterName = "ISDONE", DataType = DbType.String, Value = condition.ISDONE });
}
//是否处理
if (string.IsNullOrEmpty(condition.ISDEAL) == false)
{
whereBuilder.Append(" AND ISDEAL = @ISDEAL ");
parameters.Add(new DataParameter { ParameterName = "ISDEAL", DataType = DbType.String, Value = condition.ISDEAL });
}
if (condition.STARTCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND WI.CREATEDATE >= @STARTCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "STARTCREATEDATE", Value = condition.STARTCREATEDATE.ToString("yyyy-MM-dd HH:mm:ss") });
}
if (condition.ENDCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND WI.CREATEDATE < @ENDCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "ENDCREATEDATE", Value = condition.ENDCREATEDATE.ToString("yyyy-MM-dd HH:mm:ss") });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 报警信息插入信息
/// <summary>
/// 报警信息插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int WarnInfoInsert(WarnInfo model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<WarnInfo>(model);
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警信息插入信息"
});
throw;
}
}
#endregion
#region 报警信息更新信息
/// <summary>
/// 报警信息更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int WarnInfoUpdate(WarnInfo model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update<WarnInfo>(model);
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警信息更新信息"
});
throw;
}
}
#endregion
#region 报警信息删除
/// <summary>
/// 报警信息删除信息
/// </summary>
/// <param name="model">生产记录(ID)</param>
/// <returns>删除个数</returns>
public int WarnInfoDelete(WarnInfo model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
sqlBuilder.Append("DELETE FROM T_AW_WARNINFO WHERE PID=@PID ");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
session.Delete<WarnInfo>(model);
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警信息删除信息"
});
throw;
}
}
#endregion
#endregion
#region 报警类别维护
#region 报警类别获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public WarnType WarnTypeGet(WarnType model)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<WarnType>(model);
}
return model;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警类别获取信息"
});
throw;
}
}
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public WarnType WarnTypeGetWith(WarnType model)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetWarnTypeQuerySql(model, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<WarnType>(sql, parameters.ToArray());
}
return model;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警类别获取信息"
});
throw;
}
}
#endregion
#region 报警类别获取列表
/// <summary>
/// 报警类别获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetWarnTypeList(WarnType condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetWarnTypeQuerySql(condition, ref parameters);
#region 排序
//分页关键字段及排序
page.KeyName = "PID";
page.SortExpression = "UPDATEDATE DESC";
#endregion
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<WarnType>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警类别获取列表"
});
throw;
}
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部集合</returns>
public List<WarnType> GetWarnTypeList(WarnType condition)
{
List<WarnType> list = new List<WarnType>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetWarnTypeQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<WarnType>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-获取列表"
});
throw;
}
}
#endregion
#region 报警类别获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetWarnTypeQuerySql(WarnType condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(@" SELECT PID
,WARNTYPE
,WARNCODE
,WARNDESCRIBE
,WT.CREATEUSER
,WT.CREATEDATE
,WT.UPDATEUSER
,WT.UPDATEDATE
,C.USERNAME AS CREATEUSERNAME
,U.USERNAME AS UPDATEUSERNAME
FROM T_AW_WARNTYPE WT
LEFT JOIN T_QM_USER C ON C.USERID = WT.CREATEUSER
LEFT JOIN T_QM_USER U ON U.USERID = WT.UPDATEUSER ");
//查询条件
//报警编码
if (string.IsNullOrEmpty(condition.WARNCODE) == false)
{
whereBuilder.Append(" AND WARNCODE = @WARNCODE ");
parameters.Add(new DataParameter { ParameterName = "WARNCODE", DataType = DbType.String, Value = condition.WARNCODE });
}
//报警类型
if (string.IsNullOrEmpty(condition.WARNTYPE) == false)
{
whereBuilder.Append(" AND WARNTYPE = @WARNTYPE ");
parameters.Add(new DataParameter { ParameterName = "WARNTYPE", DataType = DbType.String, Value = condition.WARNTYPE });
}
if (condition.STARTCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND WT.CREATEDATE >= @STARTCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "STARTCREATEDATE", Value = condition.STARTCREATEDATE.Date.ToString("yyyy-MM-dd HH:mm:ss") });
}
if (condition.ENDCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND WT.CREATEDATE < @ENDCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "ENDCREATEDATE", Value = condition.ENDCREATEDATE.Date.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss") });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 报警类别插入信息
/// <summary>
/// 报警类别插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int WarnTypeInsert(WarnType model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<WarnType>(model);
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警类别插入信息"
});
throw;
}
}
#endregion
#region 报警类别更新信息
/// <summary>
/// 报警类别更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int WarnTypeUpdate(WarnType model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update<WarnType>(model);
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警类别更新信息"
});
throw;
}
}
#endregion
#region 报警类别删除
/// <summary>
/// 报警类别删除信息
/// </summary>
/// <param name="model">生产记录(ID)</param>
/// <returns>删除个数</returns>
public int WarnTypeDelete(WarnType model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
sqlBuilder.Append("DELETE FROM T_AW_WARNTYPE WHERE PID=@PID ");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警类别删除信息"
});
throw;
}
}
#endregion
#region 报警代码重复校验
/// <summary>
/// 报警代码重复校验
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsWarnType(WarnType model)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
sqlBuilder.Append("SELECT COUNT(PID) FROM T_AW_WARNTYPE");
if (string.IsNullOrEmpty(model.PID) == false)
{
whereBuilder.Append(" AND PID !=@PID ");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
}
if (string.IsNullOrEmpty(model.WARNCODE) == false)
{
whereBuilder.Append(" AND WARNCODE=@WARNCODE");
parameters.Add(new DataParameter { ParameterName = "WARNCODE", DataType = DbType.String, Value = model.WARNCODE });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(), parameters.ToArray()));
}
if (count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#endregion
#region 报警通知人员维护
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public WarnInformer WarnInformerGet(WarnInformer model)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<WarnInformer>(model);
}
return model;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警通知人员获取信息"
});
throw;
}
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetWarnInformerList(WarnInformer condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetWarnInformerQuerySql(condition, ref parameters);
#region 排序
//分页关键字段及排序
page.KeyName = "PID";
page.SortExpression = "UPDATEDATE DESC";
#endregion
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<WarnInformer>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警通知人员获取列表"
});
throw;
}
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部集合</returns>
public List<WarnInformer> GetWarnInformerList(WarnInformer condition)
{
List<WarnInformer> list = new List<WarnInformer>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetWarnInformerQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<WarnInformer>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警通知人员获取列表"
});
throw;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetWarnInformerQuerySql(WarnInformer condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(@" SELECT PID
,INFORMNAME
,INFORMCODE
,MAIL
,MOBILEPHONENUMBER
,INFOTYPE
,MEMO
,WIR.WARNCODE
,WIR.CREATEUSER
,WIR.CREATEDATE
,WIR.UPDATEUSER
,WIR.UPDATEDATE
,C.USERNAME AS CREATEUSERNAME
,U.USERNAME AS UPDATEUSERNAME
FROM T_AW_WARNINFORMER WIR
LEFT JOIN T_QM_USER C ON C.USERID = WIR.CREATEUSER
LEFT JOIN T_QM_USER U ON U.USERID = WIR.UPDATEUSER ");
//查询条件
//报警通知人姓名
if (string.IsNullOrEmpty(condition.INFORMNAME) == false)
{
whereBuilder.Append(" AND INFORMNAME = @INFORMNAME ");
parameters.Add(new DataParameter { ParameterName = "INFORMNAME", DataType = DbType.String, Value = condition.INFORMNAME });
}
//报警通知人员编码
if (string.IsNullOrEmpty(condition.INFORMCODE) == false)
{
whereBuilder.Append(" AND INFORMCODE = @INFORMCODE ");
parameters.Add(new DataParameter { ParameterName = "INFORMCODE", DataType = DbType.String, Value = condition.INFORMCODE });
}
//报警编码
if (string.IsNullOrEmpty(condition.WARNCODE) == false)
{
whereBuilder.Append(" AND WARNCODE = @WARNCODE ");
parameters.Add(new DataParameter { ParameterName = "WARNCODE", DataType = DbType.String, Value = condition.WARNCODE });
}
//通知方式
if (string.IsNullOrEmpty(condition.INFOTYPE) == false)
{
whereBuilder.Append(" AND INFOTYPE = @INFOTYPE ");
parameters.Add(new DataParameter { ParameterName = "INFOTYPE", DataType = DbType.String, Value = condition.INFOTYPE });
}
//邮件
if (string.IsNullOrEmpty(condition.MAIL) == false)
{
whereBuilder.Append(" AND MAIL = @MAIL ");
parameters.Add(new DataParameter { ParameterName = "MAIL", DataType = DbType.String, Value = condition.MAIL });
}
//手机号码
if (string.IsNullOrEmpty(condition.MOBILEPHONENUMBER) == false)
{
whereBuilder.Append(" AND MOBILEPHONENUMBER = @MOBILEPHONENUMBER ");
parameters.Add(new DataParameter { ParameterName = "MOBILEPHONENUMBER", DataType = DbType.String, Value = condition.MOBILEPHONENUMBER });
}
if (condition.STARTCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND PP.CREATEDATE >= @STARTCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "STARTCREATEDATE", Value = condition.STARTCREATEDATE.Date.ToString("yyyy-MM-dd HH:mm:ss") });
}
if (condition.ENDCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND PP.CREATEDATE < @ENDCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "ENDCREATEDATE", Value = condition.ENDCREATEDATE.Date.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss") });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 报警通知人员插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int WarnInformerInsert(WarnInformer model)
{
int count = 0;
try
{
if (BaseSession != null)
{
count = BaseSession.Insert<WarnInformer>(model);
}
else
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<WarnInformer>(model);
}
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警通知人员插入信息"
});
throw;
}
}
#endregion
#region 报警通知人重复校验
/// <summary>
/// 报警通知人重复校验
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsWarnInformer(WarnInformer model)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
sqlBuilder.Append("SELECT COUNT(PID) FROM T_AW_WARNINFORMER");
if (string.IsNullOrEmpty(model.PID) == false)
{
whereBuilder.Append(" AND PID !=@PID ");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
}
if (string.IsNullOrEmpty(model.MAIL) == false)
{
whereBuilder.Append(" AND MAIL=@MAIL");
parameters.Add(new DataParameter { ParameterName = "MAIL", DataType = DbType.String, Value = model.MAIL });
}
if (string.IsNullOrEmpty(model.MOBILEPHONENUMBER) == false)
{
whereBuilder.Append(" AND MOBILEPHONENUMBER=@MOBILEPHONENUMBER");
parameters.Add(new DataParameter { ParameterName = "MOBILEPHONENUMBER", DataType = DbType.String, Value = model.MOBILEPHONENUMBER });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(), parameters.ToArray()));
}
if (count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 报警通知人员更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int WarnInformerUpdate(WarnInformer model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update<WarnInformer>(model);
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警通知人员更新信息"
});
throw;
}
}
#endregion
#region 报警通知人员删除
/// <summary>
/// 删除信息
/// </summary>
/// <param name="model">生产记录(ID)</param>
/// <returns>删除个数</returns>
public int WarnInformerDelete(WarnInformer model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
sqlBuilder.Append("DELETE FROM T_AW_WARNINFORMER WHERE PID=@PID ");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警通知人员删除信息"
});
throw;
}
}
#endregion
#region 报警通知人关联报警类别
/// <summary>
/// 报警通知人关联报警类别
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int WarnTypeWithInformerInsert(WarnTypeWithInformer model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<WarnTypeWithInformer>(model);
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警通知人关联报警类别"
});
throw;
}
}
#endregion
#endregion
#region 报警与通知人列表
#region 报警与通知人获取列表
/// <summary>
/// 报警与通知人获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部集合</returns>
public List<WarnTypeWithInformer> GetWarnTypeWithInformerList(WarnTypeWithInformer condition)
{
List<WarnTypeWithInformer> list = new List<WarnTypeWithInformer>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetWarnTypeWithInformerQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<WarnTypeWithInformer>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警与通知人获取列表"
});
throw;
}
}
#endregion
#region 报警与通知人获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetWarnTypeWithInformerQuerySql(WarnTypeWithInformer condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(@" SELECT PID
,INID
,WTID
,INFOTYPE
,WTWI.CREATEUSER
,WTWI.CREATEDATE
,WTWI.UPDATEUSER
,WTWI.UPDATEDATE
,C.USERNAME AS CREATEUSERNAME
,U.USERNAME AS UPDATEUSERNAME
FROM T_AW_WARNTYPEWITHINFORMER WTWI
LEFT JOIN T_QM_USER C ON C.USERID = WTWI.CREATEUSER
LEFT JOIN T_QM_USER U ON U.USERID = WTWI.UPDATEUSER ");
//查询条件
//报警通知人主键
if (string.IsNullOrEmpty(condition.WTID) == false)
{
whereBuilder.Append(" AND WTID = @WTID ");
parameters.Add(new DataParameter { ParameterName = "WTID", DataType = DbType.String, Value = condition.WTID });
}
if (condition.STARTCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND WTWI.CREATEDATE >= @STARTCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "STARTCREATEDATE", Value = condition.STARTCREATEDATE.Date.ToString("yyyy-MM-dd HH:mm:ss") });
}
if (condition.ENDCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND WTWI.CREATEDATE < @ENDCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "ENDCREATEDATE", Value = condition.ENDCREATEDATE.Date.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss") });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 报警代码重复校验
/// <summary>
/// 报警代码重复校验
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsWarnTypeWithInformer(WarnType model)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
sqlBuilder.Append("SELECT COUNT(PID) FROM T_AW_WARNTYPE");
if (string.IsNullOrEmpty(model.PID) == false)
{
whereBuilder.Append(" AND PID !=@PID ");
parameters.Add(new DataParameter { ParameterName = "PID", DataType = DbType.String, Value = model.PID });
}
if (string.IsNullOrEmpty(model.WARNCODE) == false)
{
whereBuilder.Append(" AND WARNCODE=@WARNCODE");
parameters.Add(new DataParameter { ParameterName = "WARNCODE", DataType = DbType.String, Value = model.WARNCODE });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(), parameters.ToArray()));
}
if (count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 报警与通知人删除
/// <summary>
/// 报警与通知人删除信息
/// </summary>
/// <param name="model">生产记录(ID)</param>
/// <returns>删除个数</returns>
public int WarnTypeWithInformerDelete(WarnTypeWithInformer conditon)
{
StringBuilder whereBuilder = new StringBuilder();
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
sqlBuilder.Append("DELETE FROM T_AW_WARNTYPEWITHINFORMER");
if (!string.IsNullOrEmpty(conditon.INID))
{
whereBuilder.Append(" AND INID = @INID ");
parameters.Add(new DataParameter { ParameterName = "INID", DataType = DbType.String, Value = conditon.INID });
}
if (!string.IsNullOrEmpty(conditon.WTID))
{
whereBuilder.Append(" AND WTID = @WTID ");
parameters.Add(new DataParameter { ParameterName = "WTID", DataType = DbType.String, Value = conditon.WTID });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
count = session.ExecuteSql(sqlBuilder.ToString(), parameters.ToArray());
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-删除报警与通知人关联表信息"
});
throw;
}
}
#endregion
#endregion
#region 报警发送
#region 报警发送获取列表
/// <summary>
/// 报警发送获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetWarnInformerListForSend(WarnInformer condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetWarnInformerForSendQuerySql(condition, ref parameters);
#region 排序
//分页关键字段及排序
page.KeyName = "PID";
page.SortExpression = "UPDATEDATE DESC";
#endregion
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<WarnInformer>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警发送获取列表"
});
throw;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetWarnInformerForSendQuerySql(WarnInformer condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(@" SELECT PID
,INFORMNAME
,INFORMCODE
,MAIL
,MOBILEPHONENUMBER
,INFOTYPE
,MEMO
,WIR.CREATEUSER
,WIR.CREATEDATE
,WIR.UPDATEUSER
,WIR.UPDATEDATE
,C.USERNAME AS CREATEUSERNAME
,U.USERNAME AS UPDATEUSERNAME
FROM T_AW_WARNINFORMER WIR
LEFT JOIN T_QM_USER C ON C.USERID = WIR.CREATEUSER
LEFT JOIN T_QM_USER U ON U.USERID = WIR.UPDATEUSER ");
//查询条件
//报警通知人姓名
if (string.IsNullOrEmpty(condition.PID) == false)
{
whereBuilder.Append(" AND PID IN ('" + condition.PID + "')");
}
if (string.IsNullOrEmpty(condition.INFORMNAME) == false)
{
whereBuilder.Append(" AND INFORMNAME = @INFORMNAME ");
parameters.Add(new DataParameter { ParameterName = "INFORMNAME", DataType = DbType.String, Value = condition.INFORMNAME });
}
//报警通知人员编码
if (string.IsNullOrEmpty(condition.INFORMCODE) == false)
{
whereBuilder.Append(" AND INFORMCODE = @INFORMCODE ");
parameters.Add(new DataParameter { ParameterName = "INFORMCODE", DataType = DbType.String, Value = condition.INFORMCODE });
}
//报警编码
if (string.IsNullOrEmpty(condition.WARNCODE) == false)
{
whereBuilder.Append(" AND WARNCODE = @WARNCODE ");
parameters.Add(new DataParameter { ParameterName = "WARNCODE", DataType = DbType.String, Value = condition.WARNCODE });
}
//通知方式
if (string.IsNullOrEmpty(condition.INFOTYPE) == false)
{
whereBuilder.Append(" AND INFOTYPE = @INFOTYPE ");
parameters.Add(new DataParameter { ParameterName = "INFOTYPE", DataType = DbType.String, Value = condition.INFOTYPE });
}
//邮件
if (string.IsNullOrEmpty(condition.MAIL) == false)
{
whereBuilder.Append(" AND MAIL = @MAIL ");
parameters.Add(new DataParameter { ParameterName = "MAIL", DataType = DbType.String, Value = condition.MAIL });
}
//手机号码
if (string.IsNullOrEmpty(condition.MOBILEPHONENUMBER) == false)
{
whereBuilder.Append(" AND MOBILEPHONENUMBER = @MOBILEPHONENUMBER ");
parameters.Add(new DataParameter { ParameterName = "MOBILEPHONENUMBER", DataType = DbType.String, Value = condition.MOBILEPHONENUMBER });
}
if (condition.STARTCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND PP.CREATEDATE >= @STARTCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "STARTCREATEDATE", Value = condition.STARTCREATEDATE.Date.ToString("yyyy-MM-dd HH:mm:ss") });
}
if (condition.ENDCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND PP.CREATEDATE < @ENDCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "ENDCREATEDATE", Value = condition.ENDCREATEDATE.Date.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss") });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入报警详细信息
/// <summary>
/// 插入报警详细信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int WarnDetailInsert(WarnDetail model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<WarnDetail>(model);
}
return count;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-插入报警详细信息"
});
throw;
}
}
#endregion
#endregion
#region 报警详情列表加载
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetWarnDetailList(WarnDetail condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetWarnDetailQuerySql(condition, ref parameters);
#region 排序
//分页关键字段及排序
page.KeyName = "PID";
page.SortExpression = "UPDATEDATE DESC";
#endregion
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<WarnDetail>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警详情获取列表"
});
throw;
}
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部集合</returns>
public List<WarnDetail> GetWarnTypeList(WarnDetail condition)
{
List<WarnDetail> list = new List<WarnDetail>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetWarnDetailQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<WarnDetail>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "报警信息维护数据层-报警详情获取列表"
});
throw;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetWarnDetailQuerySql(WarnDetail condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(@" SELECT PID
,WPID
,INID
,INFORMNAME
,INFORMCODE
,INFOTYPE
,MAIL
,MOBILEPHONENUMBER
,WD.CREATEUSER
,WD.CREATEDATE
,WD.UPDATEUSER
,WD.UPDATEDATE
,C.USERNAME AS CREATEUSERNAME
,U.USERNAME AS UPDATEUSERNAME
FROM T_AW_WARNDETAIL WD
LEFT JOIN T_QM_USER C ON C.USERID = WD.CREATEUSER
LEFT JOIN T_QM_USER U ON U.USERID = WD.UPDATEUSER ");
//查询条件
//报警信息主键
if (string.IsNullOrEmpty(condition.WPID) == false)
{
whereBuilder.Append(" AND WPID = @WPID ");
parameters.Add(new DataParameter { ParameterName = "WPID", DataType = DbType.String, Value = condition.WPID });
}
//报警通知人主键
if (string.IsNullOrEmpty(condition.INID) == false)
{
whereBuilder.Append(" AND INID = @INID ");
parameters.Add(new DataParameter { ParameterName = "INID", DataType = DbType.String, Value = condition.INID });
}
//通知人姓名
if (string.IsNullOrEmpty(condition.INFORMNAME) == false)
{
whereBuilder.Append(" AND INFORMNAME = @INFORMNAME ");
parameters.Add(new DataParameter { ParameterName = "INFORMNAME", DataType = DbType.String, Value = condition.INFORMNAME });
}
//通知人代码
if (string.IsNullOrEmpty(condition.INFORMCODE) == false)
{
whereBuilder.Append(" AND INFORMCODE = @INFORMCODE ");
parameters.Add(new DataParameter { ParameterName = "INFORMCODE", DataType = DbType.String, Value = condition.INFORMCODE });
}
//通知方式
if (string.IsNullOrEmpty(condition.INFOTYPE) == false)
{
whereBuilder.Append(" AND INFOTYPE = @INFOTYPE ");
parameters.Add(new DataParameter { ParameterName = "INFOTYPE", DataType = DbType.String, Value = condition.INFOTYPE });
}
//邮箱
if (string.IsNullOrEmpty(condition.MAIL) == false)
{
whereBuilder.Append(" AND MAIL LIKE '%" + condition.MAIL + "%'");
}
//电话号
if (string.IsNullOrEmpty(condition.MOBILEPHONENUMBER) == false)
{
whereBuilder.Append(" AND MOBILEPHONENUMBER LIKE '%" + condition.MOBILEPHONENUMBER + "%'");
}
if (condition.STARTCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND WD.CREATEDATE >= @STARTCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "STARTCREATEDATE", Value = condition.STARTCREATEDATE.Date.ToString("yyyy-MM-dd HH:mm:ss") });
}
if (condition.ENDCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND WD.CREATEDATE < @ENDCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "ENDCREATEDATE", Value = condition.ENDCREATEDATE.Date.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss") });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#endregion
}
}