using CallCenterApi.DB;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CallCenterApi.DAL
{
    public class T_CTI_TaskDaily
    {
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [Date],TaskId,AllCount,CalledCount,connectedCount,ConnectedAgentCount,UpdateTime ");
            strSql.Append(" FROM T_CTI_TaskDaily ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取以日期分组总列表
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetList()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT Date,Sum(AllCount)as AllCount,Sum(CalledCount)as CalledCount,sum(connectedcount)as connectedcount, sum(connectedagentcount)as connectedagentcount FROM T_CTI_TaskDaily group by Date");
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.T_CTI_TaskDaily DataRowToModel(DataRow row, DataColumnCollection columns)
        {
            Model.T_CTI_TaskDaily model = new Model.T_CTI_TaskDaily();
            if (row != null)
            {
                model.Date = Convert.ToDateTime(row["Date"]);
                if (columns["TaskId"] != null)
                {
                    model.TaskId = Convert.ToInt32(row["TaskId"]);
                }
                model.AllCount = Convert.ToInt32(row["AllCount"]);
                model.CalledCount = Convert.ToInt32(row["CalledCount"]);
                model.ConnectedCount = Convert.ToInt32(row["ConnectedCount"]);
                model.ConnectedAgentCount = Convert.ToInt32(row["ConnectedAgentCount"]);
                model.UpdateTime = Convert.ToDateTime(row["UpdateTime"]);
            }
            return model;
        }

    }
}
