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.
110 lines
4.0 KiB
110 lines
4.0 KiB
4 years ago
|
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;
|
||
|
|
||
|
namespace QMAPP.MESReport.DAL.LineQTY
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 设备用电分析
|
||
|
/// 于子清
|
||
|
/// 2017-10-24
|
||
|
/// </summary>
|
||
|
public class WasteRateCountDAL : BaseDAL
|
||
|
{
|
||
|
public List<WasteRateCountDModel> GetAllList(WasteRateCountDModel condition)
|
||
|
{
|
||
|
List<WasteRateCountDModel> list = new List<WasteRateCountDModel>();
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
try
|
||
|
{
|
||
|
sql = this.GetQuerySql(condition, ref parameters);
|
||
|
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
list = session.GetList<WasteRateCountDModel>(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(WasteRateCountDModel condition, ref List<DataParameter> parameters)
|
||
|
{
|
||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||
|
StringBuilder sqlBuilder2 = new StringBuilder();
|
||
|
StringBuilder whereBuilder = new StringBuilder();
|
||
|
try
|
||
|
{
|
||
|
string group = " group by day(STATIS_DATE) ";
|
||
|
//构成查询语句
|
||
|
|
||
|
if (condition.TYPE_COUNT == "MONTH")
|
||
|
{
|
||
|
//月统计
|
||
|
sqlBuilder.AppendLine("select sum(QTY) QTY,sum(NOK_QTY) NOK_QTY,month(STATIS_DATE) tday from T_SA_LINEQTYCOUNT ");
|
||
|
group = " group by month(STATIS_DATE)";
|
||
|
}
|
||
|
else if (condition.TYPE_COUNT == "WEEK")
|
||
|
{
|
||
|
sqlBuilder.AppendLine("select sum(QTY) QTY,sum(NOK_QTY) NOK_QTY,DateName(week,DATEADD(DAY,-1,STATIS_DATE)) tday from T_SA_LINEQTYCOUNT ");
|
||
|
group = " group by DateName(week,DATEADD(DAY,-1,STATIS_DATE))";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//日统计
|
||
|
sqlBuilder.AppendLine("select sum(QTY) QTY,sum(NOK_QTY) NOK_QTY,day(STATIS_DATE) tday from T_SA_LINEQTYCOUNT ");
|
||
|
}
|
||
|
|
||
|
|
||
|
if (string.IsNullOrEmpty(condition.START_DATE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND tppo.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 tppo.STATIS_DATE <= @END_DATE ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "END_DATE", DataType = DbType.DateTime, Value = condition.END_DATE });
|
||
|
}
|
||
|
|
||
|
if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND tppo.MATERIAL_CODE = @MATERIAL_CODE ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
|
||
|
}
|
||
|
|
||
|
if (whereBuilder.Length > 0)
|
||
|
{
|
||
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
||
|
}
|
||
|
sqlBuilder.Append(group);
|
||
|
|
||
|
return sqlBuilder.ToString();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
}
|
||
|
}
|