using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Text;
using QMFrameWork.Data;
using QMAPP.Entity.Sys;
namespace QMAPP.DAL.Sys
{
///
/// 数据任务计划数据层对象
/// 创建者:韩磊
/// 创建日期:2014.12.18
///
public class DataTaskPlanDAL:BaseDAL
{
#region 获取数据任务计划
///
/// 获取数据任务计划
///
/// 条件
/// 任务信息
public DataTaskPlan Get(DataTaskPlan task)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
task = session.Get(task);
}
return task;
}
catch (Exception ex)
{
throw;
}
}
#endregion
#region 获取数据任务计划列表
///
/// 获取数据任务计划列表
///
/// 条件
/// 数据页
/// 数据页
public DataPage GetList(DataTaskPlan condition, DataPage page)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
List parameters = new List();
try
{
//构成查询语句
sqlBuilder.Append(" SELECT PLANID, ");
sqlBuilder.Append(" PLANNAME,TASKID,PERIOD ,PLANSTARTDATE , PLANENDDATE , ISUSE , REMARK");
sqlBuilder.Append(" ,PERIODTYPE,EXECUTEDAY,ONCETIME,INTERVAL ,IINTERVALTYPE , DAYSTARTTIME,DAYENDTIME");
sqlBuilder.Append(" FROM T_QM_DATATASKPLAN ");
//分页关键字段及排序
page.KeyName = "PLANID";
if (string.IsNullOrEmpty(page.SortExpression))
{
page.SortExpression = "PLANID DESC";
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage(sqlBuilder.ToString(), parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw;
}
}
#endregion
#region 插入执行日志
///
/// 插入执行日志
///
/// 执行日志
public void InsertExecuteLog(DataTaskLog log)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.Insert(log);
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取执行日志列表
///
/// 获取执行日志列表
///
/// 数据页
/// 日志
/// 数据页
public DataPage GetLogList(DataTaskLog log, DataPage page)
{
string sql = "";
List parameters = new List();
try
{
//构成查询语句
sql = this.GetQuerySql(log, parameters);
//分页关键字段及排序
page.KeyName = "PID";
if(string.IsNullOrEmpty(page.SortExpression)==true)
page.SortExpression = "LASTEXECUTETIME DESC";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = this.ChangeSqlByDB(sql, session);
page = session.GetDataPage(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw;
}
}
#endregion
#region 获取导出的数据
///
/// 获取导出的数据
///
/// 查询条件
/// 数据
public DataTable GetExportLogData(DataTaskLog log)
{
DataTable dt = null;
string sql = null;
List parameters = new List();
try
{
//构成查询语句
sql = this.GetQuerySql(log, parameters);
//sql += " ORDER BY LASTEXECUTETIME DESC";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = this.ChangeSqlByDB(sql, session);
dt = session.GetTable(sql, parameters.ToArray());
dt.TableName = "T_QM_DATATASKLOG";
}
return dt;
}
catch (Exception ex)
{
throw;
}
}
#endregion
#region 获取查询语句
///
/// 获取查询语句
///
/// 查询条件
/// 参数
/// 查询语句
private string GetQuerySql(DataTaskLog log, List parameters)
{
string sql = "";
try
{
//构成查询语句
sql = "SELECT * FROM T_QM_DATATASKLOG WHERE PLANID = @PLANID";
parameters.Add(new DataParameter("PLANID", log.PLANID));
if (string.IsNullOrEmpty(log.StartTime) == false)
{
sql += " AND LASTEXECUTETIME >= @STARTTIME";
parameters.Add(new DataParameter("STARTTIME", DateTime.Parse(log.StartTime)));
}
if (string.IsNullOrEmpty(log.EndTime) == false)
{
sql += " AND LASTEXECUTETIME >= @ENDTIME";
parameters.Add(new DataParameter("ENDTIME", DateTime.Parse(log.EndTime).AddDays(1).AddSeconds(-1)));
}
return sql;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}