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.
138 lines
5.5 KiB
138 lines
5.5 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;
|
||
|
using QMAPP.MESReport.Entity.Tables;
|
||
|
|
||
|
namespace QMAPP.MESReport.DAL.LineQTY
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 合格率分析 数据访问层
|
||
|
/// 于子清
|
||
|
/// 2017-10-13
|
||
|
/// </summary>
|
||
|
public class StandardRateCountDAL : BaseDAL
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 获取合格率图表数据
|
||
|
/// </summary>
|
||
|
/// <param name="condition"></param>
|
||
|
/// <returns></returns>
|
||
|
public List<StandardRateDModel> GetAllList(StandardRateDModel condition)
|
||
|
{
|
||
|
List<StandardRateDModel> list = new List<StandardRateDModel>();
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
try
|
||
|
{
|
||
|
sql = this.GetQuerySql(condition, ref parameters);
|
||
|
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
list = session.GetList<StandardRateDModel>(sql, parameters.ToArray()).ToList();
|
||
|
}
|
||
|
return list;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public List<StandardRateDModel> GetAllListNot(StandardRateDModel condition)
|
||
|
{
|
||
|
List<StandardRateDModel> list = new List<StandardRateDModel>();
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
try
|
||
|
{
|
||
|
sql = "select t1.NOK_QTY,t2.QTY, t2.QTY- t1.NOK_QTY as OK_QTY,t1.WORKCELL_CODE from ";
|
||
|
sql += "(select sum(MENDNUMBER) as NOK_QTY,WORKCELL_CODE FROM T_AW_MENDRECORDER where MENDTEST = '否' ";
|
||
|
if (string.IsNullOrEmpty(condition.START_DATE) == false && string.IsNullOrEmpty(condition.END_DATE) == false)
|
||
|
{
|
||
|
sql += "and BATCH_NO>='" + condition.START_DATE.Replace("-", "") + "' and BATCH_NO<='" + condition.END_DATE.Replace("-", "") + "' ";
|
||
|
}
|
||
|
if (string.IsNullOrEmpty(condition.WORKCELL_CODE) == false)
|
||
|
{
|
||
|
sql += "and WORKCELL_CODE='" + condition.WORKCELL_CODE + "' ";
|
||
|
}
|
||
|
sql += "group by WORKCELL_CODE) t1, ";
|
||
|
sql += "(select sum(qty) as QTY,WORKCELL_CODE FROM T_SA_WORKCELLQTYCOUNT where EQUIPMENT_CODE <> '' ";
|
||
|
if (string.IsNullOrEmpty(condition.START_DATE) == false && string.IsNullOrEmpty(condition.END_DATE) == false)
|
||
|
{
|
||
|
var startDate = condition.START_DATE + " 00:00:00";
|
||
|
var endDate = condition.END_DATE + " 23:59:59";
|
||
|
sql += "and STATIS_DATE>='" + startDate + "' and STATIS_DATE<='" + endDate + "' ";
|
||
|
}
|
||
|
sql += "group by WORKCELL_CODE) t2 ";
|
||
|
sql += "where t1.WORKCELL_CODE=t2.WORKCELL_CODE ";
|
||
|
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
list = session.GetList<StandardRateDModel>(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(StandardRateDModel condition, ref List<DataParameter> parameters)
|
||
|
{
|
||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||
|
StringBuilder whereBuilder = new StringBuilder();
|
||
|
try
|
||
|
{
|
||
|
//构成查询语句
|
||
|
sqlBuilder.AppendLine("select sum(OK_QTY) OK_QTY,sum(NOK_QTY) NOK_QTY,tmd.WORKCELL_NAME from T_SA_WORKCELLQTYCOUNT tsa inner join T_MD_WORKCELL tmd on tmd.WORKCELL_CODE=tsa.WORKCELL_CODE ");
|
||
|
|
||
|
if (string.IsNullOrEmpty(condition.START_DATE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND 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.WORKCELL_CODE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND tsa.WORKCELL_CODE = @WORKCELL_CODE ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "WORKCELL_CODE", DataType = DbType.String, Value = condition.WORKCELL_CODE });
|
||
|
}
|
||
|
|
||
|
if (whereBuilder.Length > 0)
|
||
|
{
|
||
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
||
|
}
|
||
|
sqlBuilder.Append(" group by tsa.WORKCELL_CODE,tmd.WORKCELL_NAME ");
|
||
|
return sqlBuilder.ToString();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|