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.
148 lines
5.7 KiB
148 lines
5.7 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-18
|
||
|
/// </summary>
|
||
|
public class QTYInfoCountDAL : BaseDAL
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 生产统计
|
||
|
/// </summary>
|
||
|
/// <param name="condition"></param>
|
||
|
/// <returns></returns>
|
||
|
public List<QTYInfoCountDModel> GetAllList(QTYInfoCountDModel condition)
|
||
|
{
|
||
|
List<QTYInfoCountDModel> list = new List<QTYInfoCountDModel>();
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
try
|
||
|
{
|
||
|
sql = this.GetQuerySql(condition, ref parameters);
|
||
|
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
list = session.GetList<QTYInfoCountDModel>(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(QTYInfoCountDModel condition, ref List<DataParameter> parameters)
|
||
|
{
|
||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||
|
StringBuilder groupBuilder = new StringBuilder();
|
||
|
StringBuilder whereBuilder = new StringBuilder();
|
||
|
try
|
||
|
{
|
||
|
sqlBuilder.AppendLine("SELECT M.MATERIAL_SHORT as MATERIAL_NAME");
|
||
|
sqlBuilder.AppendLine(" ,C.[MATRIAL_CODE] AS [MATERIAL_CODE] ");
|
||
|
sqlBuilder.AppendLine(" ,SUM(C.[QTY]) AS [QTY] ");
|
||
|
|
||
|
|
||
|
|
||
|
groupBuilder.AppendLine(" GROUP BY M.MATERIAL_SHORT ");
|
||
|
groupBuilder.AppendLine(" ,C.[MATRIAL_CODE] ");
|
||
|
|
||
|
//构成查询语句
|
||
|
|
||
|
|
||
|
if (condition.TYPE_COUNT=="WEEK")
|
||
|
{
|
||
|
sqlBuilder.AppendLine(" ,DATENAME(WEEK,DATEADD(DAY,-1,C.[STATIS_DATE])) AS TDAY ");
|
||
|
groupBuilder.AppendLine(" ,DATENAME(WEEK,DATEADD(DAY,-1,C.[STATIS_DATE])) ");
|
||
|
}
|
||
|
else if (condition.TYPE_COUNT=="MONTH")
|
||
|
{
|
||
|
sqlBuilder.AppendLine(" ,MONTH(C.[STATIS_DATE]) AS TDAY ");
|
||
|
groupBuilder.AppendLine(" ,MONTH(C.[STATIS_DATE]) ");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
sqlBuilder.AppendLine(" ,DAY(C.[STATIS_DATE]) AS TDAY ");
|
||
|
groupBuilder.AppendLine(" ,DAY(C.[STATIS_DATE]) ");
|
||
|
}
|
||
|
|
||
|
sqlBuilder.AppendLine(" FROM [T_SA_WORKCELLQTYCOUNT] AS C ");
|
||
|
sqlBuilder.AppendLine(" JOIN [T_MD_MATERIAL] AS M ");
|
||
|
sqlBuilder.AppendLine(" ON C.[MATRIAL_CODE] = M.[MATERIAL_CODE] ");
|
||
|
sqlBuilder.AppendLine(" JOIN [T_MD_MATERIAL_CLASS] AS MC ");
|
||
|
sqlBuilder.AppendLine(" ON M.[MATERIAL_TYPE_CODE] = MC.[MATERIAL_TYPE_CODE] ");
|
||
|
|
||
|
whereBuilder.Append(" AND MC.[MATERIAL_ATTRIBUTE] = '2'");
|
||
|
if (string.IsNullOrEmpty(condition.START_DATE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND C.[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 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 M.MATERIAL_CODE = @MATERIAL_CODE ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
|
||
|
}
|
||
|
|
||
|
if (string.IsNullOrEmpty(condition.HBTYPE) == false)
|
||
|
{
|
||
|
whereBuilder.AppendFormat(" AND charindex(M.HBTYPE,'{0}')>0 ", condition.HBTYPE);
|
||
|
}
|
||
|
|
||
|
if (string.IsNullOrEmpty(condition.COLOR) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND M.COLOR = @COLOR ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "COLOR", DataType = DbType.String, Value = condition.COLOR });
|
||
|
}
|
||
|
|
||
|
if (string.IsNullOrEmpty(condition.PROJECTCODE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND M.PROJECTCODE = @PROJECTCODE ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "PROJECTCODE", DataType = DbType.String, Value = condition.PROJECTCODE });
|
||
|
}
|
||
|
|
||
|
if (whereBuilder.Length > 0)
|
||
|
{
|
||
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
||
|
}
|
||
|
sqlBuilder.Append(groupBuilder.ToString());
|
||
|
sqlBuilder.AppendLine(" ORDER BY TDAY ");
|
||
|
|
||
|
return sqlBuilder.ToString();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
}
|
||
|
}
|