
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CallCenter.Utility;
using CallCenterApi.DB;
using CallCenterApi.Interface.Controllers.Base;

namespace CallCenterApi.Interface.Controllers.County
{
    public class CountyBusinessController : BaseController
    {
        // GET: CountyBusiness


        /// <summary>
        /// 绩效考核
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public ActionResult GetAreaAssessment(string branchcode,DateTime? start, DateTime? end, int isdc = 0)
        {
            if (start == null)
            {
                start = DateTime.Now;
                start = new DateTime(start.Value.Year, start.Value.Month, 1);
            }
            if (end == null)
            {
                end = DateTime.Now;
            }

            if (branchcode == "sqs12345")
            {
                Dictionary<string, string> paras = new Dictionary<string, string>();
                paras.Add("@sdate", start.Value.ToString("yyyy-MM-dd"));
                paras.Add("@edate", end.Value.ToString("yyyy-MM-dd"));
                var obj = DbHelperSQL.RunProcedure("P_AreaAssessmentReport", paras, "AreaAssessmentReport");
                if (isdc > 0)
                {
                    string[] cols = new string[] { "区县名称", "受理量", "交办量", "已办量", "重办量", "及时量", "超时量", "延时量", "回访量", "市民满意", "市民不满意" };
                    NPOIHelper npoi = new NPOIHelper();
                    if (npoi.ExportToExcel("绩效考核报表", obj.Tables[0], cols) == "")
                    {
                        return Success("导出成功");
                    }
                    else
                    {
                        return Error("导出失败");
                    }
                }
                return Success("成功", obj);
            }
            else
            {
                var obj = new
                {
                    AreaAssessmentReport = ""
                };
                return Success("成功", obj);
            }
        }

        /// <summary>
        /// 县区受理
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public ActionResult GetAreaAccept(string branchcode,DateTime? date, int isdc = 0)
        {
            if (date == null)
            {
                date = DateTime.Now;
            }

            if (branchcode == "sqs12345")
            {
                Dictionary<string, string> paras = new Dictionary<string, string>();
                paras.Add("@date", date.Value.ToString("yyyy-MM"));
                var obj = DbHelperSQL.RunProcedure("P_AreaAcceptReport", paras, "AreaAcceptReport");
                if (isdc > 0)
                {
                    string[] cols = new string[] { "区县名称", "受理量", "同比", "环比" };
                    NPOIHelper npoi = new NPOIHelper();
                    if (npoi.ExportToExcel("县区受理报表", obj.Tables[0], cols) == "")
                    {
                        return Success("导出成功");
                    }
                    else
                    {
                        return Error("导出失败");
                    }
                }
                return Success("成功", obj);
            }
            else
            {
                var obj = new
                {
                    AreaAcceptReport = ""
                };
                return Success("成功", obj);
            }
        }

        /// <summary>
        /// 县区办理
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public ActionResult GetAreaDeal(string branchcode, DateTime? date, int isdc = 0)
        {
            if (date == null)
            {
                date = DateTime.Now;
            }

            if (branchcode == "sqs12345")
            {
                Dictionary<string, string> paras = new Dictionary<string, string>();
                paras.Add("@date", date.Value.ToString("yyyy-MM"));
                var obj = DbHelperSQL.RunProcedure("P_AreaDealReport", paras, "AreaDealReport");
                if (isdc > 0)
                {
                    string[] cols = new string[] { "区县名称", "办理量", "同比", "环比" };
                    NPOIHelper npoi = new NPOIHelper();
                    if (npoi.ExportToExcel("县区办理报表", obj.Tables[0], cols) == "")
                    {
                        return Success("导出成功");
                    }
                    else
                    {
                        return Error("导出失败");
                    }
                }
                return Success("成功", obj);
            }
            else
            {
                var obj = new
                {
                    AreaDealReport = ""
                };
                return Success("成功", obj);
            }
        }

        /// <summary>
        /// 县区各类型统计
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public ActionResult GetAreaCount(string branchcode,DateTime? start, DateTime? end,int type, int isdc = 0)
        {
            if (start == null)
            {
                start = DateTime.Now;
                start = new DateTime(start.Value.Year, start.Value.Month, 1);
            }
            if (end == null)
            {
                end = DateTime.Now;
            }

            if (branchcode == "sqs12345")
            {
                Dictionary<string, string> paras = new Dictionary<string, string>();
                paras.Add("@sdate", start.Value.ToString("yyyy-MM-dd"));
                paras.Add("@edate", end.Value.ToString("yyyy-MM-dd"));
                paras.Add("@type", type.ToString());
                var obj = DbHelperSQL.RunProcedure("P_AreaCountReport", paras, "AreaCountReport");
                if (isdc > 0)
                {
                    string[] cols = new string[] { "名称", "数量" };
                    NPOIHelper npoi = new NPOIHelper();
                    if (npoi.ExportToExcel("统计报表", obj.Tables[0], cols) == "")
                    {
                        return Success("导出成功");
                    }
                    else
                    {
                        return Error("导出失败");
                    }
                }
                return Success("成功", obj);
            }
            else
            {
                var obj = new
                {
                    AreaCountReport = ""
                };
                return Success("成功", obj);
            }
        }

    }
}