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

386 lines
14 KiB

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using QMAPP.DAL;
using QMAPP.FJC.Entity.EM;
using QMAPP.FJC.Entity.Equipment;
using QMFrameWork.Data;
using QMFrameWork.Log;
namespace QMAPP.FJC.DAL.EM
{
public class UsageLogDAL : BaseDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public UsageLogEntity Get(UsageLogEntity model)
{
//页面为空
return null;
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(UsageLogEntity condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "PID";
page.SortExpression = "PID";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<UsageLogEntity>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "数据层-获取列表"
});
throw;
}
}
public DataPage GetCountList(UsageLogEntity condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetCountSql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "RTIME";
page.SortExpression = "RTIME";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<UsageLogEntity>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "数据层-获取列表"
});
throw;
}
}
public UsageLogEntity GetCounts(UsageLogEntity condition)
{
List<DataParameter> parameters = new List<DataParameter>();
try
{
var sql = this.GetQuerySql1(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.Get<UsageLogEntity>(sql, parameters.ToArray());
}
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部集合</returns>
public List<UsageLogEntity> GetList(UsageLogEntity condition)
{
List<UsageLogEntity> list = new List<UsageLogEntity>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<UsageLogEntity>(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 GetQuerySql(UsageLogEntity condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
var pidStr = condition.PID;
var ftimeStr = condition.FLAG_TIME;
try
{
//构成查询语句
sqlBuilder.AppendLine(" select MOULD_PID as PID ");
sqlBuilder.AppendLine(" ,MOULD_PID ");
sqlBuilder.AppendLine(" ,MACHINE_PID ");
sqlBuilder.AppendLine(" ,count(MOULD_PID)as USAGECOUNT ");
sqlBuilder.AppendLine(" from T_EQP_USAGELOG ");
//sqlBuilder.AppendLine(" LEFT JOIN T_EM_METER m ON m.PID=t.METER_PID ");
//sqlBuilder.AppendLine(" LEFT JOIN T_BD_MACHINEINFO b ON b.MACHINECODDE=m.EQPT_CODE ");
//whereBuilder.Append(" and t.READ_RESULT='1' and m.STATE='1'");
//查询条件
//if (string.IsNullOrEmpty(condition.MOULD_PID) == false)
//{
// whereBuilder.Append(@" AND MOULD_PID LIKE '%'+" + "@MOULD_PID" + "+'%'");
// //whereBuilderSet.Append(" AND C.MACHINECODDE LIKE '%'+" + "@EQPT_CODE" + "+'%'");
// parameters.Add(new DataParameter { ParameterName = "MOULD_PID", DataType = DbType.String, Value = condition.MOULD_PID });
//}
//if (string.IsNullOrEmpty(condition.MACHINE_PID) == false)
//{
// whereBuilder.Append(@" AND MACHINE_PID LIKE '%'+" + "@MACHINE_PID" + "+'%'");
// //whereBuilderSet.Append(" AND C.MACHINECODDE LIKE '%'+" + "@EQPT_CODE" + "+'%'");
// parameters.Add(new DataParameter { ParameterName = "MACHINE_PID", DataType = DbType.String, Value = condition.MACHINE_PID });
//}
if (string.IsNullOrEmpty(condition.START_OPERATION_DATE) == false)
{
whereBuilder.Append(" AND OPERATION_DATE >= @START_OPERATION_DATE");
parameters.Add(new DataParameter { ParameterName = "START_OPERATION_DATE", DataType = DbType.String, Value = condition.START_OPERATION_DATE });
}
if (string.IsNullOrEmpty(condition.END_OPERATION_DATE) == false)
{
whereBuilder.Append(" AND OPERATION_DATE <= @END_OPERATION_DATE");
parameters.Add(new DataParameter { ParameterName = "END_OPERATION_DATE", DataType = DbType.String, Value = condition.END_OPERATION_DATE });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
sqlBuilder.AppendLine(" group by MOULD_PID, MACHINE_PID ");
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
private string GetQuerySql1(UsageLogEntity condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
var pidStr = condition.PID;
var ftimeStr = condition.FLAG_TIME;
try
{
//构成查询语句
sqlBuilder.AppendLine(" select count(1)as USAGECOUNT ");
sqlBuilder.AppendLine(" from T_EQP_USAGELOG ");
//sqlBuilder.AppendLine(" LEFT JOIN T_EM_METER m ON m.PID=t.METER_PID ");
//sqlBuilder.AppendLine(" LEFT JOIN T_BD_MACHINEINFO b ON b.MACHINECODDE=m.EQPT_CODE ");
//whereBuilder.Append(" and t.READ_RESULT='1' and m.STATE='1'");
//查询条件
if (string.IsNullOrEmpty(condition.START_OPERATION_DATE) == false)
{
whereBuilder.Append(" AND OPERATION_DATE >= @START_OPERATION_DATE");
parameters.Add(new DataParameter { ParameterName = "START_OPERATION_DATE", DataType = DbType.String, Value = condition.START_OPERATION_DATE });
}
if (string.IsNullOrEmpty(condition.END_OPERATION_DATE) == false)
{
whereBuilder.Append(" AND OPERATION_DATE <= @END_OPERATION_DATE");
parameters.Add(new DataParameter { ParameterName = "END_OPERATION_DATE", DataType = DbType.String, Value = condition.END_OPERATION_DATE });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
//sqlBuilder.AppendLine(" group by MOULD_PID, MACHINE_PID ");
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
private string GetCountSql(UsageLogEntity condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
int dateCount = 4;
if (!string.IsNullOrEmpty(condition.FLAG_TIME))
{
int tempCount = Convert.ToInt32(condition.FLAG_TIME);
if (tempCount==1)
{
dateCount = 7;
}
else if (tempCount == 2)
{
dateCount = 10;
}
}
//构成查询语句
sqlBuilder.AppendLine(" select RTIME,count(MOULD_PID) as USAGECOUNT from ");
sqlBuilder.AppendLine(" (select ");
sqlBuilder.AppendLine(" convert(varchar(" + dateCount + "),OPERATION_DATE,120) RTIME , ");
sqlBuilder.AppendLine(" MOULD_PID ");
sqlBuilder.AppendLine(" from T_EQP_USAGELOG ");
sqlBuilder.Append(" WHERE MOULD_PID = '" + condition.PID + "' ");
if (string.IsNullOrEmpty(condition.START_OPERATION_DATE) == false)
{
sqlBuilder.Append(" AND OPERATION_DATE >= '" + condition.START_OPERATION_DATE + "'");
}
if (string.IsNullOrEmpty(condition.END_OPERATION_DATE) == false)
{
sqlBuilder.Append(" AND OPERATION_DATE <= '" + condition.END_OPERATION_DATE + "'");
}
sqlBuilder.Append(" ) t ");
//whereBuilder.Append(" and t.READ_RESULT='1' and m.STATE='1'");
//whereBuilder.Append(" AND m.EQPT_CODE = '" + condition.PID + "' ");
//查询条件
//if (string.IsNullOrEmpty(condition.STARTCREATEDATE) == false)
//{
// whereBuilder.Append(" AND t.READ_TIME >= '" + condition.STARTCREATEDATE + "'");
//}
//if (string.IsNullOrEmpty(condition.ENDCREATEDATE) == false)
//{
// whereBuilder.Append(" AND t.READ_TIME <= '" + condition.ENDCREATEDATE + "'");
//}
//if (whereBuilder.Length > 0)
//{
// sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
//}
sqlBuilder.AppendLine(" group by RTIME ");
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
//task程序
public List<MonitorCodeEntity> GetMonitorCode(IDataSession Bsession)
{
List<DataParameter> parameters = new List<DataParameter>();
string sql = "SELECT * FROM T_TM_MonitorCode WHERE ReadFlag=0 and CurrentMode = '3'";
if (Bsession != null)
{
//插入基本信息
return Bsession.GetList<MonitorCodeEntity>(sql, parameters.ToArray()).ToList();
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetList<MonitorCodeEntity>(sql, parameters.ToArray()).ToList();
}
}
public List<MonitorDataEntity> GetMonitorData(IDataSession Bsession)
{
List<DataParameter> parameters = new List<DataParameter>();
string sql = "SELECT * FROM T_TM_MonitorData WHERE ReadFlag=0 ";
if (Bsession != null)
{
//插入基本信息
return Bsession.GetList<MonitorDataEntity>(sql, parameters.ToArray()).ToList();
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetList<MonitorDataEntity>(sql, parameters.ToArray()).ToList();
}
}
public int Insert(UsageLogEntity model)
{
try
{
if (BaseSession != null)
{
//插入基本信息
return BaseSession.Insert<UsageLogEntity>(model);
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.Insert(model);
}
}
catch (Exception ex)
{
throw ex;
}
}
public int UpdateMonitorCode(MonitorCodeEntity model, IDataSession Bsession)
{
return Bsession.Update(model);
}
public int UpdateMonitorData(MonitorDataEntity model, IDataSession Bsession)
{
return Bsession.Update(model);
}
}
}