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.
170 lines
7.9 KiB
170 lines
7.9 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;
|
|
|
|
namespace QMAPP.MESReport.DAL.LineQTY
|
|
{
|
|
/// <summary>
|
|
/// 节拍统计
|
|
/// 于子清
|
|
/// 2017-11-1
|
|
/// </summary>
|
|
public class ProduceCycleTimeDAL : BaseDAL
|
|
{
|
|
public List<ProduceCycleTimeDModel> GetAllListShift(ProduceCycleTimeDModel condition)
|
|
{
|
|
List<ProduceCycleTimeDModel> list = new List<ProduceCycleTimeDModel>();
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = "select tsc.val,t2.QTY,t2.NOK_QTY,tsc.WORKCELL_CODE from ";
|
|
sql +="(select WORKCELL_CODE,cast(round(sum(CYCLETIME)/sum(CYCLECOUNT),0) as int) as val from T_SA_CELLCYCLETIME where (WORKCELL_CODE is not null and WORKCELL_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) tsc left JOIN ";
|
|
sql += "(select tsw.QTY,tsw.WORKCELL_CODE,(case WHEN tam.NOK_QTY is null then 0 else tam.NOK_QTY end) as NOK_QTY from ";
|
|
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 + "' ";
|
|
}
|
|
if (string.IsNullOrEmpty(condition.SHIFT_CODE) == false)
|
|
{
|
|
sql += "and SHIFT_CODE='" + condition.SHIFT_CODE + "' ";
|
|
}
|
|
sql += "group by WORKCELL_CODE) tsw left JOIN ";
|
|
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.SHIFT_CODE) == false)
|
|
{
|
|
sql += "and SHIFT_CODE='" + condition.SHIFT_CODE + "' ";
|
|
}
|
|
sql += "group by WORKCELL_CODE) tam on tsw.WORKCELL_CODE=tam.WORKCELL_CODE ) t2 on t2.WORKCELL_CODE=tsc.WORKCELL_CODE ";
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<ProduceCycleTimeDModel>(sql, parameters.ToArray()).ToList();
|
|
}
|
|
return list;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public List<ProduceCycleTimeDModel> GetAllList(ProduceCycleTimeDModel condition)
|
|
{
|
|
List<ProduceCycleTimeDModel> list = new List<ProduceCycleTimeDModel>();
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
list = session.GetList<ProduceCycleTimeDModel>(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(ProduceCycleTimeDModel condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder sqlBuilder2 = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
string group = "";
|
|
//构成查询语句
|
|
|
|
//sqlBuilder.AppendLine("select tmd.WORKCELL_NAME,tsa.WORKCELL_CODE,");
|
|
//sqlBuilder.AppendLine("cast(round(avg(tsa.CYCLETIME),2) as numeric(5,2)) CYCLETIME,yzq.val from T_SA_CELLCYCLETIME tsa ");
|
|
//sqlBuilder.AppendLine("inner join T_MD_WORKCELL tmd on tsa.WORKCELL_CODE=tmd.WORKCELL_CODE ");
|
|
//sqlBuilder.AppendLine("left join T_SA_YZQCOUNT yzq on yzq.WORKCELL_CODE = tsa.WORKCELL_CODE ");
|
|
|
|
sqlBuilder.AppendLine("select m.MACHINECODDE,cast(round(timeSum/countSum,0) as int) val");
|
|
sqlBuilder.AppendLine(" from (select machinecodde,sum(CYCLECOUNT) as countSum,sum(CYCLETIME) as timeSum");
|
|
sqlBuilder.AppendLine(" from T_SA_CELLCYCLETIME");
|
|
|
|
if (string.IsNullOrEmpty(condition.START_DATE) == false)
|
|
{
|
|
sqlBuilder.AppendLine(" where STATIS_DATE>= '" + condition.START_DATE +" 00:00:00"+ "'");
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.END_DATE) == false)
|
|
{
|
|
sqlBuilder.AppendLine("and STATIS_DATE<='" + condition.END_DATE + " 23:59:59" + "'");
|
|
}
|
|
sqlBuilder.AppendLine(" group by machinecodde)temp1,t_bd_machineinfo m");
|
|
|
|
whereBuilder.Append(" AND temp1.machinecodde=m.machinecodde");
|
|
|
|
//group = " group by tsa.WORKCELL_CODE,tmd.WORKCELL_NAME,yzq.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.MATERIAL_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND tsa.MATERIAL_CODE = @MATERIAL_CODE ");
|
|
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(condition.MACHINECODDE) == false)
|
|
{
|
|
whereBuilder.Append(" AND temp1.MACHINECODDE = @MACHINECODDE ");
|
|
parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
|
|
}
|
|
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
|
}
|
|
sqlBuilder.Append(group);
|
|
|
|
return sqlBuilder.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|