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.
153 lines
6.4 KiB
153 lines
6.4 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using QMFrameWork.Data;
|
|
using QMAPP.MESReport.Entity.LineQTY;
|
|
using QMAPP.DAL;
|
|
using System.Data;
|
|
using QMAPP.MESReport.Entity.Tables;
|
|
|
|
namespace QMAPP.MESReport.DAL.LineQTY
|
|
{
|
|
/// <summary>
|
|
/// 设备利用率分析
|
|
/// 于子清
|
|
/// 2017-10-26
|
|
/// </summary>
|
|
public class EqueUseCountDAL : BaseDAL
|
|
{
|
|
public List<EqueUseCountDModel> GetAllList(EqueUseCountDModel condition)
|
|
{
|
|
List<EqueUseCountDModel> list = new List<EqueUseCountDModel>();
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<EqueUseCountDModel>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
|
|
#region 获取查询语句
|
|
/// <summary>
|
|
/// 获取查询语句
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <param name="parameters">参数</param>
|
|
/// <returns>查询语句</returns>
|
|
private string GetQuerySql(EqueUseCountDModel condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder sqlBuilder2 = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
string group = "";
|
|
//构成查询语句
|
|
|
|
if (condition.TYPE_COUNT=="WEEK")
|
|
{
|
|
//周统计
|
|
sqlBuilder.AppendLine("select year(tsa.STATIS_DATE) tyear,DateName(week,DATEADD(DAY,-1,STATIS_DATE)) tday,sum(tsa.WORKTIMES) WORKTIMES,sum(tsa.BOOTTIMES) BOOTTIMES,tsay.val from T_SA_EQPTUSECOUNT tsa inner join T_SA_YZQCOUNT tsay on tsay.pid =6 inner join T_BD_MACHINEINFO tbd on tsa.EQPT_CODE =tbd.MACHINECODDE ");
|
|
group = " group by year(tsa.STATIS_DATE),DateName(week,DATEADD(DAY,-1,STATIS_DATE)),tsay.val ";
|
|
}
|
|
else if (condition.TYPE_COUNT == "MONTH")
|
|
{
|
|
//月统计
|
|
sqlBuilder.AppendLine("select year(tsa.STATIS_DATE) tyear,month(tsa.STATIS_DATE) tday,sum(tsa.WORKTIMES) WORKTIMES,sum(tsa.BOOTTIMES) BOOTTIMES,tsay.val from T_SA_EQPTUSECOUNT tsa inner join T_SA_YZQCOUNT tsay on tsay.pid =6 inner join T_BD_MACHINEINFO tbd on tsa.EQPT_CODE =tbd.MACHINECODDE ");
|
|
group = " group by year(tsa.STATIS_DATE),month(tsa.STATIS_DATE),tsay.val ";
|
|
}else
|
|
{
|
|
//日统计
|
|
sqlBuilder.AppendLine("select year(tsa.STATIS_DATE) tyear,month(tsa.STATIS_DATE) tmonth,day(tsa.STATIS_DATE) tday,sum(tsa.WORKTIMES) WORKTIMES,sum(tsa.BOOTTIMES) BOOTTIMES,tsay.val from T_SA_EQPTUSECOUNT tsa inner join T_SA_YZQCOUNT tsay on tsay.pid =6 inner join T_BD_MACHINEINFO tbd on tsa.EQPT_CODE =tbd.MACHINECODDE ");
|
|
group = " group by year(tsa.STATIS_DATE),month(tsa.STATIS_DATE),day(tsa.STATIS_DATE),tsay.val ";
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.START_DATE) == false)
|
|
{
|
|
whereBuilder.Append(" AND tsa.STATIS_DATE >= @START_DATE ");
|
|
parameters.Add(new DataParameter { ParameterName = "START_DATE", DataType = DbType.DateTime, Value = condition.START_DATE });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.END_DATE) == false)
|
|
{
|
|
whereBuilder.Append(" AND tsa.STATIS_DATE <= @END_DATE ");
|
|
parameters.Add(new DataParameter { ParameterName = "END_DATE", DataType = DbType.DateTime, Value = condition.END_DATE });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.EQPT_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND tsa.EQPT_CODE <= @EQPT_CODE ");
|
|
parameters.Add(new DataParameter { ParameterName = "EQPT_CODE", DataType = DbType.String, Value = condition.EQPT_CODE });
|
|
}
|
|
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
sqlBuilder.Append(group);
|
|
|
|
return sqlBuilder.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public List<T_BD_MACHINEINFO> GetSList()
|
|
{
|
|
List<T_BD_MACHINEINFO> list = new List<T_BD_MACHINEINFO>();
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = "select MACHINENAME,MACHINECODDE from T_BD_MACHINEINFO where STATUS = 0 ";
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<T_BD_MACHINEINFO>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public List<T_BD_MACHINEINFO> GetMachine(string workcentercode)
|
|
{
|
|
var parms = new List<DataParameter>();
|
|
StringBuilder sql = new StringBuilder();
|
|
sql.AppendLine("SELECT M.* FROM T_BD_MACHINEINFO M,T_MD_WORKLOC L,T_MD_WORKCELL C ");
|
|
sql.AppendLine("WHERE M.WORKLOC_CODE=L.WORKLOC_CODE ");
|
|
sql.AppendLine("AND L.WORKCELL_CODE=C.WORKCELL_CODE ");
|
|
if (!string.IsNullOrWhiteSpace(workcentercode))
|
|
{
|
|
sql.AppendLine(" AND C.WORKCENTER_CODE =@workcentercode");
|
|
parms.Add(new DataParameter("workcentercode", workcentercode));
|
|
}
|
|
List<T_BD_MACHINEINFO> list = new List<T_BD_MACHINEINFO>();
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<T_BD_MACHINEINFO>(sql.ToString(), parms.ToArray()).ToList<T_BD_MACHINEINFO>();
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
}
|
|
}
|
|
|