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

216 lines
6.6 KiB

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
{
/// <summary>
/// 数据任务计划数据层对象
/// 创建者:韩磊
/// 创建日期:2014.12.18
/// </summary>
public class DataTaskPlanDAL:BaseDAL
{
#region 获取数据任务计划
/// <summary>
/// 获取数据任务计划
/// </summary>
/// <param name="task">条件</param>
/// <returns>任务信息</returns>
public DataTaskPlan Get(DataTaskPlan task)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
task = session.Get<DataTaskPlan>(task);
}
return task;
}
catch (Exception ex)
{
throw;
}
}
#endregion
#region 获取数据任务计划列表
/// <summary>
/// 获取数据任务计划列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(DataTaskPlan condition, DataPage page)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
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<DataTaskPlan>(sqlBuilder.ToString(), parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw;
}
}
#endregion
#region 插入执行日志
/// <summary>
/// 插入执行日志
/// </summary>
/// <param name="log">执行日志</param>
public void InsertExecuteLog(DataTaskLog log)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.Insert<DataTaskLog>(log);
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取执行日志列表
/// <summary>
/// 获取执行日志列表
/// </summary>
/// <param name="page">数据页</param>
/// <param name="log">日志</param>
/// <returns>数据页</returns>
public DataPage GetLogList(DataTaskLog log, DataPage page)
{
string sql = "";
List<DataParameter> parameters = new List<DataParameter>();
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<DataTaskLog>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw;
}
}
#endregion
#region 获取导出的数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportLogData(DataTaskLog log)
{
DataTable dt = null;
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
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 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(DataTaskLog log, List<DataParameter> 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
}
}