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

namespace CallCenterApi.BLL
{
    public class T_Bus_WorkOrderReport
    {
        #region 工单周报
        /// <summary>
        ///  区域
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List<Model.WeaklyReport> DataTableToAreaList(DataTable dt)
        {
            List<Model.WeaklyReport> list = new List<Model.WeaklyReport>();
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow r in dt.Rows)
                {
                    list.Add(new Model.WeaklyReport
                    {
                        WorkOrderId = r["F_WorkOrderId"] == DBNull.Value ? "" : r["F_WorkOrderId"].ToString(),
                        WorkOrderState = r["F_WorkState"] == DBNull.Value ? -1 : Convert.ToInt32(r["F_WorkState"]),
                        FieldId = r["F_SourceArea"] == DBNull.Value ? -1 : Convert.ToInt32(r["F_SourceArea"]),
                        FieldName = r["F_AreaName"] == DBNull.Value ? "" : r["F_AreaName"].ToString()
                    });
                }
            }
            return list;
        }

        /// <summary>
        /// 部门
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List<Model.WeaklyReport> DataTableToDeptList(DataTable dt)
        {
            List<Model.WeaklyReport> list = new List<Model.WeaklyReport>();
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow r in dt.Rows)
                {
                    list.Add(new Model.WeaklyReport
                    {
                        WorkOrderId = r["F_WorkOrderId"] == DBNull.Value ? "" : r["F_WorkOrderId"].ToString(),
                        WorkOrderState = r["F_WorkState"] == DBNull.Value ? -1 : Convert.ToInt32(r["F_WorkState"]),
                        FieldId = r["F_MainDeptId"] == DBNull.Value ? -1 : Convert.ToInt32(r["F_MainDeptId"]),
                        FieldName = r["F_DeptName"] == DBNull.Value ? "" : r["F_DeptName"].ToString()
                    });
                }
            }
            return list;
        }

        /// <summary>
        /// 工单类型
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List<Model.WeaklyReport> DataTableToTypeList(DataTable dt)
        {
            List<Model.WeaklyReport> list = new List<Model.WeaklyReport>();
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow r in dt.Rows)
                {
                    list.Add(new Model.WeaklyReport
                    {
                        WorkOrderId = r["F_WorkOrderId"] == DBNull.Value ? "" : r["F_WorkOrderId"].ToString(),
                        WorkOrderState = r["F_WorkState"] == DBNull.Value ? -1 : Convert.ToInt32(r["F_WorkState"]),
                        FieldId = r["F_InfoType"] == DBNull.Value ? -1 : Convert.ToInt32(r["F_InfoType"]),
                        FieldName = r["F_Value"] == DBNull.Value ? "" : r["F_Value"].ToString()
                    });
                }
            }
            return list;
        }

        /// <summary>
        /// 工单来源
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public List<Model.WeaklyReport> DataTableToSourceList(DataTable dt)
        {
            List<Model.WeaklyReport> list = new List<Model.WeaklyReport>();
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow r in dt.Rows)
                {
                    list.Add(new Model.WeaklyReport
                    {
                        WorkOrderId = r["F_WorkOrderId"] == DBNull.Value ? "" : r["F_WorkOrderId"].ToString(),
                        WorkOrderState = r["F_WorkState"] == DBNull.Value ? -1 : Convert.ToInt32(r["F_WorkState"]),
                        FieldId = r["F_InfoSource"] == DBNull.Value ? -1 : Convert.ToInt32(r["F_InfoSource"]),
                        FieldName = r["F_Value"] == DBNull.Value ? "" : r["F_Value"].ToString()
                    });
                }
            }
            return list;
        }
        #endregion

        #region 延期统计
        public List<Model.DelayReport> DataTableToDelayList(DataTable dt)
        {
            List<Model.DelayReport> list = new List<Model.DelayReport>();
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow r in dt.Rows)
                {
                    list.Add(new Model.DelayReport
                    {
                        WorkOrderId = r["F_WorkOrderId"] == DBNull.Value ? "" : r["F_WorkOrderId"].ToString(),
                        DeptId = r["F_MainDeptId"] == DBNull.Value ? 0 : Convert.ToInt32(r["F_MainDeptId"]),
                        DelayId = r["F_ID"] == DBNull.Value ? 0 : Convert.ToInt32(r["F_ID"]),
                    });
                }
            }
            return list;
        }
        #endregion

        #region 延期统计
        public List<Model.NoticeReport> DataTableToNoticeList(DataTable dt)
        {
            List<Model.NoticeReport> list = new List<Model.NoticeReport>();
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow r in dt.Rows)
                {
                    list.Add(new Model.NoticeReport
                    {
                        WorkOrderId = r["F_WorkOrderId"] == DBNull.Value ? "" : r["F_WorkOrderId"].ToString(),
                        DeptId = r["F_MainDeptId"] == DBNull.Value ? 0 : Convert.ToInt32(r["F_MainDeptId"]),
                        IsNotice = r["F_IsNotice"] == DBNull.Value ? false : Convert.ToBoolean(r["F_IsNotice"]),
                    });
                }
            }
            return list;
        }
        #endregion

        #region 处理效率统计
        public List<Model.EfficiencyReport> DataTableToEfficiencyList(DataTable dt)
        {
            List<Model.EfficiencyReport> list = new List<Model.EfficiencyReport>();
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow r in dt.Rows)
                {
                    list.Add(new Model.EfficiencyReport
                    {
                        WorkOrderId = r["F_WorkOrderId"] == DBNull.Value ? "" : r["F_WorkOrderId"].ToString(),
                        DeptId = r["F_CreateDeptId"] == DBNull.Value ? -1 : Convert.ToInt32(r["F_CreateDeptId"]),
                        IsOverdue = r["F_IsOverdue"] == DBNull.Value ? false : Convert.ToBoolean(r["F_IsOverdue"]),
                        IsSatisfie = r["F_IsSatisfie"] == DBNull.Value ? false : Convert.ToBoolean(r["F_IsSatisfie"])
                    });
                }
            }
            return list;
        }
        #endregion

        #region 诉求受理对比
        public List<Model.AppealReport> DataTableAppealList(DataTable dt)
        {
            List<Model.AppealReport> list = new List<Model.AppealReport>();
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow r in dt.Rows)
                {
                    list.Add(new Model.AppealReport
                    {
                        WorkOrderId = r["F_WorkOrderId"] == DBNull.Value ? "" : r["F_WorkOrderId"].ToString(),
                        UserCode = r["F_CreateUser"] == DBNull.Value ? "" : r["F_CreateUser"].ToString()
                    });
                }
            }
            return list;
        }
        #endregion




    }
}
