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 { /// /// 设备利用率分析 /// 于子清 /// 2017-10-26 /// public class EqueUseCountDAL : BaseDAL { public List GetAllList(EqueUseCountDModel condition) { List list = new List(); string sql = null; List parameters = new List(); try { sql = this.GetQuerySql(condition, ref parameters); using (IDataSession session = AppDataFactory.CreateMainSession()) { list = session.GetList(sql, parameters.ToArray()).ToList(); } return list; } catch (Exception ex) { throw ex; } } #region 获取查询语句 /// /// 获取查询语句 /// /// 查询条件 /// 参数 /// 查询语句 private string GetQuerySql(EqueUseCountDModel condition, ref List 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 GetSList() { List list = new List(); string sql = null; List parameters = new List(); try { sql = "select MACHINENAME,MACHINECODDE from T_BD_MACHINEINFO where STATUS = 0 "; using (IDataSession session = AppDataFactory.CreateMainSession()) { list = session.GetList(sql, parameters.ToArray()).ToList(); } return list; } catch (Exception ex) { throw ex; } } public List GetMachine(string workcentercode) { var parms = new List(); 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 list = new List(); using (IDataSession session = AppDataFactory.CreateMainSession()) { list = session.GetList(sql.ToString(), parms.ToArray()).ToList(); } return list; } } }