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

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

        /// <summary>
        /// 退回市工单
        /// </summary>
        /// <returns></returns>
        public ActionResult RefuseCityWorkOrder()
        {
            string workorderid = RequestString.GetFormString("workorderid");
            string reson = RequestString.GetFormString("reson");
            Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = new BLL.T_Bus_WorkOrder().GetModel(workorderid);
            Model.T_Bus_CityTurn modelT_Bus_CityTurn = new BLL.T_Bus_CityTurn().GetModelList(" F_WorkOrderId='" + workorderid + "' and F_IsDelete=0 ").FirstOrDefault();
            if (modelT_Bus_WorkOrder != null && modelT_Bus_CityTurn != null)
            {
                using (TransactionScope trans = new TransactionScope())
                {
                    #region 保存工单信息
                    modelT_Bus_WorkOrder.F_WorkState = 1;
                    modelT_Bus_WorkOrder.F_IsClosed = 0;
                    modelT_Bus_WorkOrder.F_Result = "";
                    modelT_Bus_WorkOrder.F_DealUser = "";
                    modelT_Bus_WorkOrder.F_DealTime = null;
                    modelT_Bus_WorkOrder.F_CloseUser = "";
                    modelT_Bus_WorkOrder.F_CloseTime = null;
                    new BLL.T_Bus_WorkOrder().Update(modelT_Bus_WorkOrder);
                    #endregion

                    #region 保存转单信息
                    modelT_Bus_CityTurn.F_IsSure = 2;
                    modelT_Bus_CityTurn.F_SureTime = DateTime.Now;
                    modelT_Bus_CityTurn.F_Reson = reson;
                    new BLL.T_Bus_CityTurn().Update(modelT_Bus_CityTurn); 
                    #endregion

                    #region 插入操作记录
                    Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                    oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                    oper.F_Message = modelT_Bus_CityTurn.F_CityName + " 退回了工单";
                    oper.F_CreateTime = DateTime.Now;
                    oper.F_IsDelete = 0;

                    new BLL.T_Bus_Operation().Add(oper);
                    #endregion

                    trans.Complete();
                }

                return Success("操作成功");
            }
            else
            {
                return Error("操作失败");
            }
        }

        /// <summary>
        /// 获取工单列表
        /// </summary>
        /// <returns></returns>
        public ActionResult GetAreaOrderList()
        {
            DataTable dt = new DataTable();
            string sql = " and F_IsDelete=0 ";
            string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
            string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
            string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
            string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
            string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));
            int dealtype = RequestString.GetInt("dealtype", -1);

            #region 新增筛选项
            string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));
            string strddusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("ddusercode"));//调度员
            int source = RequestString.GetInt("source", 0);
            int keyid = RequestString.GetInt("keyid", 0);
            int type = RequestString.GetInt("type", 0);
            int bigtype = RequestString.GetInt("bigtype", 0);
            int smalltype = RequestString.GetInt("smalltype", 0);
            int sourcearea = RequestString.GetInt("sourcearea", 0);
            int deptid = RequestString.GetInt("deptid", 0);
            int issend = RequestString.GetInt("issend", -1);
            int deptlevel = RequestString.GetInt("deptlevel", 0);
            #endregion

            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;

            #region sql 语句相关处理
            if (strstate.Trim() != "" && strstate != "undefined")
            {
                if (strstate.Trim() == EnumWorkState.neworder.ToString())
                    sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                else
                    sql += " and F_WorkState = '" + strstate.Trim() + "' "; 
                //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
            }
            if (strworkid.Trim() != "" && strworkid != "undefined")
            {
                sql += " and F_WorkOrderId like '%" + strworkid + "%' ";
            }
            if (strname.Trim() != "" && strname != "undefined")
            {
                sql += " and F_CusName like '%" + strname + "%' ";
            }
            if (strtel.Trim() != "" && strtel != "undefined")
            {
                sql += " and (F_CusPhone like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%') ";
            }
            if (dealtype != -1)
            {
                sql += " and isnull(F_IsResult,0) = '" + dealtype + "' ";
            }
           
            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and datediff(day,F_CreateTime,'" + strstarttime + "')<=0 ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and datediff(day,F_CreateTime,'" + strendtime + "')>=0   ";
            }
            #region 新增筛选项
            #region 坐席&调度员
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {//坐席
                var usercode = strusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in usercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_CreateUser in (" + newusercode + ") ";
                    //sql += " and F_CreateUser ='" + strusercode + "' ";
                }
            }
            if (strddusercode.Trim() != "" && strddusercode != "undefined")
            {//调度员
                var ddusercode = strddusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in ddusercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_AssignUser in(" + newusercode + ") ";
                    //sql += " and F_AssignUser = '" + strddusercode + "' ";
                }
            }
            #endregion
            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            if (keyid != 0)
            {
                sql += " and ','+F_Key+',' like '%," + keyid + ",%' ";
            }
            if (type != 0)
            {
                sql += " and F_InfoType = '" + type + "' ";
            }
            if (bigtype != 0)
            {
                sql += " and F_InfoConBigType = '" + bigtype + "' ";
            }
            if (smalltype != 0)
            {
                sql += " and F_InfoConSmallType = '" + smalltype + "' ";
            }

            if (sourcearea != 0)
            {
                sql += " and F_SourceArea = '" + sourcearea + "' ";
            }

            if (deptid != 0)
            {
                if (deptlevel == 0)
                {
                    string sqlwhere = "select F_WorkOrderID from T_Bus_AssignedInfo where F_MainDeptId = '" + deptid + "' and F_IsSure in (0,1) and F_State=1 and F_IsDelete=0 ";
                    sql += " and F_WorkOrderID in(" + sqlwhere + ")";
                }
                else
                {
                    string sqlwhere = "select F_WorkOrderID from T_Bus_AssignedInfo_Next where F_MainDeptId = '" + deptid + "' and F_IsSure in (0,1) and F_State=1 and F_IsDelete=0 ";
                    sql += " and F_WorkOrderID in(" + sqlwhere + ")";
                }
            }
            if (issend != -1)
            {
                sql += " and isnull(F_IsRelease,0) = '" + issend + "' ";
            }

            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and datediff(day,F_CreateTime,'" + strstarttime + "')<=0 ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and datediff(day,F_CreateTime,'" + strendtime + "')>=0   ";
            }
            #endregion
            #endregion

            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }

            if (strpagesize.Trim() != "")
            {
                pagesize = Convert.ToInt32(strpagesize);
            }

            string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName";

            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_WorkOrder",
                "F_WorkOrderId",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);

            #region 声音文件和交办超时
            dt.Columns.Add("DeptName", typeof(string));//交办单位
            dt.Columns.Add("AssignTime", typeof(string));//交办时间
            dt.Columns.Add("OtherDeptName", typeof(string));//协办单位
            foreach (DataRow dr in dt.Rows)
            {
                int state = Int32.Parse(dr["F_WorkState"].ToString());
                if (state > 1)
                {
                    //获取最新交办信息
                    string sqljb = "SELECT TOP 1 * FROM T_Bus_AssignedInfo WHERE F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' and F_State=1 and F_IsDelete=0 and F_IsSure<>3   ORDER BY F_Id DESC";
                    var dtjb = DbHelperSQL.Query(sqljb).Tables[0];
                    if (dtjb.Rows.Count > 0)
                    {
                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_MainDeptId"].ToString() + "')");
                        if (dtjb.Rows[0]["F_OtherDeptIds"] != null && dtjb.Rows[0]["F_OtherDeptIds"].ToString() != "")
                        {
                            dr["OtherDeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_OtherDeptIds"].ToString() + "')");
                        }
                        dr["AssignTime"] = dtjb.Rows[0]["F_CreateTime"].ToString();
                    }
                }
            }
            #endregion

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };
            return Content(obj.ToJson());

        }

        /// <summary>
        /// 获取工单信息
        /// </summary>
        /// <returns></returns>
        public ActionResult GetAreaWorkOrder()
        {
            string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));

            if (!string.IsNullOrEmpty(strworkorderid))
            {
                string sql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName1,"
                    + "dbo.GetAreaName(F_SourceArea) as AreaName,dbo.GetDictionaryName(F_InfoSource) as SourceName "
                    + " from T_Bus_WorkOrder where F_WorkOrderId ='" + strworkorderid + "'";
                var dt = DbHelperSQL.Query(sql).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    var configly = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayLeaveVoice' ").FirstOrDefault();
                    var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
                    var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();

                    string jcsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_DeptId) as DeptName "
                                    + "from T_Bus_RemindRecord where F_Type=2 and F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "'";
                    string dbsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_DeptId) as DeptName "
                         + "from T_Bus_RemindRecord where F_Type=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "'";
                    // + "from T_Bus_RemindRecord where F_Type=1 and F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "'";
                    string pssql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_SubmitSuper where F_State=1 and F_IsDelete=0 and F_Type=1 and F_WorkOrderId ='" + strworkorderid + "'";
                    string zssql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_SubmitSuper where F_State=1 and F_IsDelete=0 and F_Type=2 and F_WorkOrderId ='" + strworkorderid + "'";
                    string htsql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_SubmitSuper where F_State=1 and F_IsDelete=0 and F_Type=3 and F_WorkOrderId ='" + strworkorderid + "'";
                    string jbsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName "
                                    + "from T_Bus_AssignedInfo where F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "'";
                    string thsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_CreateDeptId) as DeptName "
                                    + "from T_Bus_Feedback where F_State=1 and F_Type=3 and F_IsDelete=0 and  F_WorkOrderId ='" + strworkorderid + "'";
                    string yssql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_DelayTime where  F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "'";
                    string blsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_CreateDeptId) as DeptName "
                                    + "from T_Bus_Feedback where F_State=1 and F_Type!=3 and F_IsDelete=0 and  F_WorkOrderId ='" + strworkorderid + "'";
                    string hfsql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_VisitResult where F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "'";
                    string gcsql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_Operation where F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "'";
                    string cbsql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_Additional where F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "'";


                    #region 声音文件
                    dt.Columns.Add("FilePath", typeof(string));

                    if (dt.Rows[0]["F_LeaveRecordId"] != null)
                    {
                        dt.Rows[0]["FilePath"] = GetLeavePath(dt.Rows[0]["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                    }
                    else if (dt.Rows[0]["F_CallRecordId"] != null)
                    {
                        dt.Rows[0]["FilePath"] = GetCallPath(dt.Rows[0]["F_CallRecordId"].ToString(), config.F_ParamValue);
                    }
                    #endregion

                    #region 附件
                    if (configfj != null)
                    {
                        dt = BindFileData(dt, configfj.F_ParamValue);
                    }
                    #endregion

                    #region 监察信息
                    var jcdt = DbHelperSQL.Query(jcsql).Tables[0];
                    if (configfj != null)
                    {
                        jcdt = BindFileData(jcdt, configfj.F_ParamValue);
                    }
                    #endregion

                    #region 批示信息
                    var psdt = DbHelperSQL.Query(pssql).Tables[0];
                    if (configfj != null)
                    {
                        psdt = BindFileData(psdt, configfj.F_ParamValue);
                    }
                    #endregion

                    #region 指示信息
                    var zsdt = DbHelperSQL.Query(zssql).Tables[0];
                    if (configfj != null)
                    {
                        zsdt = BindFileData(zsdt, configfj.F_ParamValue);
                    }
                    #endregion

                    #region 回退信息
                    var htdt = DbHelperSQL.Query(htsql).Tables[0];
                    #endregion

                    #region 督办信息
                    var dbdt = DbHelperSQL.Query(dbsql).Tables[0];
                    if (configfj != null)
                    {
                        dbdt = BindFileData(dbdt, configfj.F_ParamValue);
                    }
                    #endregion

                    #region 交办信息
                    var jbdt = DbHelperSQL.Query(jbsql).Tables[0];
                    if (configfj != null)
                    {
                        jbdt = BindFileData(jbdt, configfj.F_ParamValue);
                    }
                    #endregion

                    #region 退回信息
                    var thdt = DbHelperSQL.Query(thsql).Tables[0];
                    #endregion

                    #region 延时信息
                    var ysdt = DbHelperSQL.Query(yssql).Tables[0];
                    #endregion

                    #region 办理情况
                    var bldt = DbHelperSQL.Query(blsql).Tables[0];
                    if (configfj != null)
                    {
                        bldt = BindFileData(bldt, configfj.F_ParamValue);
                    }
                    #endregion

                    #region 回访信息
                    var hfdt = DbHelperSQL.Query(hfsql).Tables[0];
                    hfdt.Columns.Add("FilePath", typeof(string));
                    foreach (DataRow bldr in hfdt.Rows)
                    {
                        if (bldr["F_CallRecordId"] != null && config != null)
                        {
                            bldr["FilePath"] = GetCallPath(bldr["F_CallRecordId"].ToString(), config.F_ParamValue);
                        }
                    }
                    #endregion

                    #region 市民催单
                    var cbdt = DbHelperSQL.Query(cbsql).Tables[0];
                    cbdt.Columns.Add("FilePath", typeof(string));
                    foreach (DataRow bldr in cbdt.Rows)
                    {
                        if (bldr["F_CallRecordId"] != null && config != null)
                        {
                            bldr["FilePath"] = GetCallPath(bldr["F_CallRecordId"].ToString(), config.F_ParamValue);
                        }
                    }
                    #endregion

                    #region 办理过程
                    var gcdt = DbHelperSQL.Query(gcsql).Tables[0];
                    gcdt.Columns.Add("File", typeof(object));
                    gcdt.Columns.Add("FilePath", typeof(string));
                    if (configfj != null || configly != null || config != null)
                    {
                        foreach (DataRow bldr in gcdt.Rows)
                        {
                            if (bldr["F_File"] != null && bldr["F_File"].ToString() != "" && configfj != null)
                            {
                                bldr["File"] = GetFileData(bldr["F_File"].ToString(), configfj.F_ParamValue);
                            }

                            if (bldr["F_LeaveRecordId"] != null && configly != null)
                            {
                                bldr["FilePath"] = GetLeavePath(bldr["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                            }
                            else if (bldr["F_CallRecordId"] != null && config != null)
                            {
                                bldr["FilePath"] = GetCallPath(bldr["F_CallRecordId"].ToString(), config.F_ParamValue);
                            }
                        }
                    }
                    #endregion

                    var obj = new
                    {
                        data = dt,
                        jcdata = jcdt,
                        psdata = psdt,
                        zsdata = zsdt,
                        htdata = htdt,
                        dbdata = dbdt,
                        jbdata = jbdt,
                        thdata = thdt,
                        ysdata = ysdt,
                        bldata = bldt,
                        hfdata = hfdt,
                        cbdata = cbdt,
                        gcdata = gcdt
                    };
                    return Success("获取成功", obj);
                }
                else
                {
                    return Error("获取失败");
                }
            }
            else
            {
                return Error("参数传输失败");
            }
        }

        /// <summary>
        /// 获取留言路径
        /// </summary>
        /// <param name="lid">留言id</param>
        /// <param name="prefix">前缀</param>
        /// <returns></returns>
        public string GetLeavePath(string lid, string prefix)
        {
            string path = string.Empty;
            var liuyan = new BLL.T_Call_LeaveRecord().GetModelList(" F_Id='" + lid + "' ").FirstOrDefault();
            if (liuyan != null)
            {
                if (!string.IsNullOrEmpty(liuyan.F_RecFileUrl))
                {
                    path = prefix + liuyan.F_RecFileUrl;
                }
            }
            return path;
        }

        /// <summary>
        /// 获取通话录音路径
        /// </summary>
        /// <param name="cid">通话id</param>
        /// <param name="prefix">前缀</param>
        /// <returns></returns>
        public string GetCallPath(string cid, string prefix)
        {
            string path = string.Empty;
            var luyin = new BLL.T_Call_CallRecords().GetModelList(" CallRecordsId='" + cid + "' ").FirstOrDefault();
            if (luyin != null)
            {
                if (!string.IsNullOrEmpty(luyin.FilePath))
                {
                    var ym = prefix;
                    ym = ym.Substring(0, ym.Length - 1);
                    string lujing = luyin.FilePath.Substring(luyin.FilePath.IndexOf(':') + 1).Replace('\\', '/');
                    path = ym + lujing;

                    //if (!CommonHelper.FileIsExist(path))
                    //{
                    //    path = lujing;
                    //}
                }
            }
            return path;
        }

        /// <summary>
        /// 获取附件数据
        /// </summary>
        /// <param name="ids">附件id，多个用英文逗号,隔开</param>
        /// <param name="prefix">前缀</param>
        /// <returns></returns>
        public DataTable GetFileData(string ids, string prefix)
        {
            DataTable dt = DbHelperSQL.Query("select * from T_Sys_Accessories where F_FileId in (" + ids + ")").Tables[0];

            foreach (DataRow dr in dt.Rows)
            {
                dr["F_FileUrl"] = prefix + dr["F_FileUrl"].ToString();
            }

            return dt;
        }

        /// <summary>
        /// 绑定附件信息
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="prefix"></param>
        /// <returns></returns>
        public DataTable BindFileData(DataTable dt, string prefix)
        {
            dt.Columns.Add("File", typeof(object));
            foreach (DataRow dr in dt.Rows)
            {
                if (dr["F_File"] != null && dr["F_File"].ToString() != "")
                {
                    dr["File"] = GetFileData(dr["F_File"].ToString(), prefix);
                }
            }
            return dt;
        }

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

            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");

            return Success("成功", obj.Tables[0]);

        }

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

            Dictionary<string, string> paras = new Dictionary<string, string>();
            paras.Add("@date", date.Value.ToString("yyyy-MM"));
            var obj = DbHelperSQL.RunProcedure("P_AreaAcceptReport", paras, "AreaAcceptReport");

            return Success("成功", obj.Tables[0]);
        }

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

            Dictionary<string, string> paras = new Dictionary<string, string>();
            paras.Add("@date", date.Value.ToString("yyyy-MM"));
            var obj = DbHelperSQL.RunProcedure("P_AreaDealReport", paras, "AreaDealReport");

            return Success("成功", obj.Tables[0]);

        }

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


            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");

            return Success("成功", obj.Tables[0]);

        }

        /// <summary>
        /// 办理率统计
        /// </summary>
        /// <param name="month"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public ActionResult GetAreaEndRate(string month)
        {
            string start = "", end = "";
            if (!string.IsNullOrEmpty(month))
            {
                var date = DateTime.Parse(month + "-01");
                start = date.ToString("yyyy-MM-dd"); ;
                end = date.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
            }

            Dictionary<string, string> paras = new Dictionary<string, string>();
            paras.Add("@sdate", start);
            paras.Add("@edate", end);
            var obj = DbHelperSQL.RunProcedure("P_AreaEndRateReport", paras, "AreaEndRateReport");

            return Success("成功", obj.Tables[0]);
        }

        /// <summary>
        /// 获取简报月
        /// </summary>
        /// <param name="sdate"></param>
        /// <param name="edate"></param>
        /// <param name="monthdate"></param>
        /// <param name="isdc"></param>
        /// <returns></returns>
        public ActionResult GetSimpleReport(string month)
        {
            string start = "", end = "";
            if (!string.IsNullOrEmpty(month))
            {
                var date = DateTime.Parse(month + "-01");
                start = date.ToString("yyyy-MM-dd"); ;
                end = date.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
            }

            Dictionary<string, string> paras = new Dictionary<string, string>();
            paras.Add("@sdate", start);
            paras.Add("@edate", end);
            var obj = DbHelperSQL.RunProcedure("P_SimpleReport", paras, "SimpleReport");
            return Success("成功", obj);
        }

    }
}