using CallCenter.Utility;
using CallCenterApi.DB;
using CallCenterApi.Interface.Controllers.Base;
using NPOI.SS.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace CallCenterApi.Interface.Controllers
{
    public class AutoCallController : BaseController
    {
        BLL.T_AutoCall_Task taskbll = new BLL.T_AutoCall_Task();

        BLL.T_AutoCall_Question quesbll = new BLL.T_AutoCall_Question();

        // GET: AutoCall
        public ActionResult GetTaskList(string key, int pagesize = 10, int pageindex = 1)
        {
            StringBuilder sb = new StringBuilder();

            if (!string.IsNullOrWhiteSpace(key))
            {
                sb.Append(" and  taskName like '%" + key + "%'   ");
            }

            var recordCount = 0;
            var dt = BLL.PagerBLL.GetListPager(
                    "T_AutoCall_Task",
                    "taskId",
                    "*",
                    " and isDelete=0 " + sb.ToString(),
                    "ORDER BY taskId desc",
                    pagesize,
                    pageindex,
                    true,
                    out recordCount);

            var obj = new
            {
                rows = dt,
                total = recordCount
            };
            return Content(obj.ToJson());
        }

        public ActionResult GetQuestionListByTaskId(int taskId, int pagesize = 10, int pageindex = 1)
        {
            var recordCount = 0;
            string sql = "and taskId='" + taskId + "'";
            var dt = BLL.PagerBLL.GetListPager(
                    "T_AutoCall_Question",
                    "F_Id",
                    "*",
                    sql,
                    "ORDER BY createTime ",
                    pagesize,
                    pageindex,
                    true,
                    out recordCount);

            var obj = new
            {
                rows = dt,
                total = recordCount
            };
            return Content(obj.ToJson());
        }

        public ActionResult CreateOrUpdateTask( int id = 0, string name = "")
        {
            var model = new Model.T_AutoCall_Task();
            if (string.IsNullOrWhiteSpace(name))
                return Error("请填写名称" + ",操作人：" + CurrentUser.UserData.F_UserCode);
            if (id <= 0)
            {
                model.taskName = name;
                model.createBy = CurrentUser.UserData.F_UserCode;
                int taskid = taskbll.Add(model);
                if (taskid > 0)
                {               


                    return Success("添加成功" + ",操作人：" + CurrentUser.UserData.F_UserCode);
                }
                return Error("添加失败" + ",操作人：" + CurrentUser.UserData.F_UserCode);
            }
            model = taskbll.GetModel(id);
            model.taskName = name;     
            if (taskbll.Update(model))
                return Success("修改成功" + ",操作人：" + CurrentUser.UserData.F_UserCode);
            return Error("修改失败" + ",操作人：" + CurrentUser.UserData.F_UserCode);
        }


        public ActionResult CreateOrUpdateQuestion(int questionId=0,int taskid = 0, string quesContent="")
        {
            var model = new Model.T_AutoCall_Question();
            if (string.IsNullOrWhiteSpace(quesContent))
                return Error("请填写问题" + ",操作人：" + CurrentUser.UserData.F_UserCode);
            if (questionId <= 0)
            {
                Model.T_AutoCall_Question quesmodel = new Model.T_AutoCall_Question();
                quesmodel.qesContent = quesContent;
                quesmodel.taskId = taskid;
                quesmodel.createBy = CurrentUser.UserData.F_UserCode;
               string path = TtsHelper.GetAudioPath(quesContent);
                quesmodel.path = path.Replace('\\','/');
                if (quesbll.Add(quesmodel) > 0)
                {
                    return Success("添加成功" + ",操作人：" + CurrentUser.UserData.F_UserCode);
                }
                return Error("添加失败" + ",操作人：" + CurrentUser.UserData.F_UserCode);
            }
            model = quesbll.GetModel(questionId);
            model.qesContent = quesContent;
            if (quesbll.Update(model))
                return Success("修改成功" + ",操作人：" + CurrentUser.UserData.F_UserCode);
            return Error("修改失败" + ",操作人：" + CurrentUser.UserData.F_UserCode);
        }


        
        // 导入号码读取填入数据库
        public ActionResult TelInput(int taskid)
        {
            DataTable dtres = new DataTable();
            string errres = "";
            int i = 0;
            int count = 0;//导入成功的条数
            string Excelsource = "";
            int rcount = 0;
            int ccount = 0;
            System.Text.StringBuilder strBuilder = null;
           
            Excelsource = uploadexcel();         

            try
            {
                //************************将文件中的数据导入数据库*************************//
                DataSet dt = ReadEcxel(Excelsource, 0);
                try
                {
                    if (dt != null && dt.Tables[0].Rows.Count != 0)
                    {
                        rcount = dt.Tables[0].Rows.Count;
                        ccount = dt.Tables[0].Columns.Count;
                        strBuilder = new System.Text.StringBuilder();//用于如果导入失败，删除已经导入过的

                        DataTable dtInputData = dt.Tables[0];//要导入的电话号码
                        List<string> sqlList = new List<string>();
                        List<string> lstsql = new List<string>();
                        int ilns = dt.Tables[0].Columns.Count;
                        DataSet dsnew = new DataSet();                    
                        using (SqlConnection coon = new SqlConnection(DbHelperSQL.connectionString))
                        {
                            try
                            {
                                coon.Open();
                                int colscount = dtInputData.Columns.Count;//列数
                                int rowscount = dtInputData.Rows.Count;//行数
                                BLL.T_AutoCall_PhoneRelate bll = new BLL.T_AutoCall_PhoneRelate();
                                Model.T_AutoCall_PhoneRelate modelPhoneImport = new Model.T_AutoCall_PhoneRelate();

                                modelPhoneImport.createBy = CurrentUser.UserData.F_UserCode;
                                modelPhoneImport.taskId = taskid;                          

                           
                         
                                 
                                if (rowscount > 0)
                                {
                                    foreach (DataRow dr in dtInputData.Rows)
                                    {
                                        sqlList.Clear();
                                        lstsql.Clear();
                                        if (dr[2].ToString() != "")
                                        {
                                            //string dddddd = dr[1].ToString();
                                            #region 导入表内容
                                            //目标分类、营业部、电话号码、宽带账号、地址、入网时间、入网渠道、营服、套餐、是否融合、状态
                                            modelPhoneImport.orderNature = dr[0].ToString();//目标分类


                                            modelPhoneImport.salesOffice = dr[1].ToString();//营业部
                                            modelPhoneImport.phone = dr[2].ToString();//电话号码
                                            modelPhoneImport.broadbandAccount = dr[3].ToString();//宽带账号
                                            modelPhoneImport.address = dr[4].ToString();//地址

                                            if (!string.IsNullOrEmpty(dr[5].ToString())) {
                                                modelPhoneImport.accessTime = Convert.ToDateTime(dr[5].ToString());//入网时间
                                            }          
                                            
                                            modelPhoneImport.channel = dr[6].ToString();//入网渠道
                                            modelPhoneImport.service = dr[7].ToString();//营服

                                            modelPhoneImport.package = dr[8].ToString();//taocan
                                            modelPhoneImport.fusion =  dr[9].ToString() ;//是否融合
                                            modelPhoneImport.phoneState = dr[10].ToString();//状态
                                       

                                            string fix=  getfix(dr[2].ToString());
                                            modelPhoneImport.fix = fix;
                                            #endregion

                                            #region 查重
                                            string strwhere = " taskId='" + taskid + "' and phone='" + modelPhoneImport.phone+"'";
                                            DataSet ds = bll.GetList(strwhere);
                                            if (ds != null && ds.Tables.Count > 0)
                                            {
                                                if (ds.Tables[0].Rows.Count > 0)
                                                {
                                                    continue;
                                                }
                                            }
                                            #endregion

                                            int rmw = bll.Add(modelPhoneImport);
                                            if (rmw > 0)
                                            {
                                                count += 1;//导入成功，+1
                                            }
                                        }

                                    }
                                    dtres = dtInputData;

                                }
                                else
                                {
                                    errres += "该文档的内容为空";
                                }
                            }
                            catch (Exception ex)
                            {

                                LogFactory.GetLogger("TelInput").Error("导入失败", ex);
                                if (coon.State == ConnectionState.Open)
                                {
                                    coon.Close();
                                }
                                i++;
                                errres += i.ToString() + ".导入出现异常，共导入" + count + "条数据，请从第" + (count + 2).ToString() + "行开始导入;\n";
                                if (strBuilder.Length > 0)
                                {
                                    errres += "重复的号码为：" + strBuilder.ToString() + "\n";
                                }
                            }
                            finally
                            {
                                if (coon.State == ConnectionState.Open)
                                {
                                    coon.Close();
                                }
                            }


                        }//****************using*********

                     

                    }
                    else
                    {
                        i++;
                        errres += i.ToString() + ".Excel中无数据;\n";
                    }

                }
                catch
                {
                    i++;
                    errres += i.ToString() + ".导入出现异常，导入失败;\n";
                }
                finally
                {
                    dt.Clear();
                    dt.Dispose();
                }

            }
            catch
            {
                errres += i.ToString() + ".Excel格式不正确，系统错误，导入失败;\n";
            }

            
            if (errres != "")
            {
                return Error("导入失败！错误信息：" + errres);
            }
            else
            {
                string info = "本文件有" + rcount.ToString() + "行" + ccount.ToString() + "列数据";
                return Success("导入成功！" + info);
            }
        }
     
        private string uploadexcel()
        {
            string Excelsource = "";
            try
            {
                 
                HttpPostedFile _upfile = RequestString.GetFile("upFile");
                if (_upfile != null)
                {
                    string imgPath = "";

                    string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss");
                    newFileName = newFileName + "_" + _upfile.FileName;
                    if (!Directory.Exists(Server.MapPath(this.Request.ApplicationPath + "\\TelExcelData")))
                    {
                        Directory.CreateDirectory(Server.MapPath(this.Request.ApplicationPath + "\\TelExcelData"));
                    }

                    imgPath = this.Request.ApplicationPath + "/TelExcelData/" + newFileName.ToString();
                    string PhysicalPath = Server.MapPath(imgPath);
                    _upfile.SaveAs(PhysicalPath);

                    Excelsource = Server.MapPath(this.Request.ApplicationPath + "\\TelExcelData\\") + newFileName.ToString();

                    
                    Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
                    model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
                    model_T_Sys_Accessories.F_FileName = _upfile.FileName;//附件名称
                    model_T_Sys_Accessories.F_FileType = _upfile.FileName.Substring(_upfile.FileName.LastIndexOf('.') + 1); //附件类型
                    model_T_Sys_Accessories.F_FileUrl = Excelsource;//附件地址
                   
                    model_T_Sys_Accessories.F_UserCode = CurrentUser.UserData.F_UserCode;//上传人  
                    int fid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
                   
                }
            }
            catch (Exception ex) { }
            return Excelsource;
        }

     
        private DataSet ReadEcxel(string FileName, int Rows)
        {
            return ToDataTable(FileName);
        }
        /// <summary>
        /// 读取Excel文件到DataSet中
        /// </summary>
        /// <param name="filePath">文件路径</param>
        /// <returns></returns>
        private DataSet ToDataTable(string filePath)
        {
            DataSet ds = new DataSet();
            DataTable dt = null;

            try
            {
                FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);

                NPOI.SS.UserModel.IWorkbook book = null;
                if (filePath.IndexOf(".xlsx") > 0) // 2007版本
                    book = new NPOI.XSSF.UserModel.XSSFWorkbook(fs);
                else if (filePath.IndexOf(".xls") > 0) // 2003版本
                    book = new NPOI.HSSF.UserModel.HSSFWorkbook(fs);
             

                 NPOI.SS.UserModel.ISheet sheet = book.GetSheetAt(0);


                NPOI.SS.UserModel.IRow row = sheet.GetRow(0);


                int firstCellNum = row.FirstCellNum;
                int lastCellNum = row.LastCellNum;
             

                dt = new DataTable(sheet.SheetName);
           
                for (int i = firstCellNum; i < lastCellNum; i++)
                {
                    if (row.GetCell(i) != null)
                    {
                        dt.Columns.Add(row.GetCell(i).ToString() + i.ToString(), typeof(string));
                    }
                    else
                    {
                        dt.Columns.Add(i.ToString(), typeof(string));
                    }
                }

                for (int i = 1; i <= sheet.LastRowNum; i++)
                {
                    if (sheet.GetRow(i).GetCell(1) != null && sheet.GetRow(i).GetCell(1).ToString() != "")
                    {
                        DataRow newRow = dt.Rows.Add();
                        for (int j = firstCellNum; j < lastCellNum; j++)
                        {
                            if (sheet.GetRow(i).GetCell(j) != null)
                            {
                                ICell cell = sheet.GetRow(i).GetCell(j);

                                newRow[j] = cell.ToString();
                              
                           
                            }
                            else
                            {
                                newRow[j] = "";
                            }
                        }
                    }
                }

                ds.Tables.Add(dt);
            }
            catch (Exception ex)
            {
                
            }
            return ds;
        }

        public string getfix(string phone)
        {
            string fix = "";
            string zipcode = Configs.GetValue("zipcode");
            if (phone.Trim().Length == 11 && phone[0] == '1')
            {//号码为11位，首位是1，为手机号
                BLL.T_Sys_MobileData mobile_Bll = new BLL.T_Sys_MobileData();
                Model.T_Sys_MobileData mobileModel = mobile_Bll.GetModelList("F_MobileNum='" + phone.Substring(0, 7) + "'").FirstOrDefault();
                if (mobileModel != null)
                {
                    if (!mobileModel.F_ZipCode.Equals(zipcode))
                    {
                        fix = "0";
                    }
                    
                }
            }
            return fix;
        }


        //删除号码
        public ActionResult DeleteTels(string[] ids)
        {
            BLL.T_AutoCall_PhoneRelate bll = new BLL.T_AutoCall_PhoneRelate();
            if (ids != null && ids.Length > 0)
            {
                string idd = " ";
                foreach (string str in ids)
                {
                    idd += str + ",";
                }
                if (bll.DeleteList(idd.TrimEnd(',')))
                {
                    return Success("删除成功");
                }
                else
                    return Error("删除失败");
            }
            else
            {
                return Error("请选择要删除的记录");
            }
            return Error("删除号码失败,操作人：" + CurrentUser.UserData.F_UserCode);
        }

        //通过任务id读取电话号码

        public ActionResult GetPhoneListByTaskId(string taskid, int pagesize = 10, int pageindex = 1)
        {
            StringBuilder sb = new StringBuilder();

            if (!string.IsNullOrWhiteSpace(taskid))
            {
                sb.Append(" and  taskId = '" + taskid + "'   ");
            }

            var recordCount = 0;
            var dt = BLL.PagerBLL.GetListPager(
                    "T_AutoCall_PhoneRelate",
                    "F_Id",
                    "*",
                    sb.ToString(),
                    "ORDER BY F_Id ",
                    pagesize,
                    pageindex,
                    true,
                    out recordCount);

            var obj = new
            {
                rows = dt,
                total = recordCount
            };
            return Content(obj.ToJson());
        }


        //统计及导出

        //通话记录导出
        //public ActionResult GetListExpt(int questionId,string sdate,string edate,string salesOffice, int isexport=0, int pageindex = 1, int pagesize = 10, string result = null)
        //{
        //    string sql = "";
        //    DataTable dt = new DataTable();       
        //    if (questionId != 0)
        //    {
        //        sql += " and  b.questionId='"+questionId+"'";

        //    }
        //    //else
        //    //{
        //    //    sql += " and  b.questionId= -1";
        //    //}

        //    if (result != null && result.Trim() != "")
        //    {
        //        if(result =="1" || result == "2" || result == "3" )
        //        sql += " and b.result='" + result + "'";
        //    }

        //    //if (result != null && result.Trim() == "")
        //    //{                 
        //    //   sql += " and b.result='" + result + "'";
        //    //}

        //    if (salesOffice != null && salesOffice.Trim() != "")
        //    {
        //        sql += " and a.salesOffice='" + salesOffice + "'";
        //    }


        //    if (!string.IsNullOrWhiteSpace(sdate))
        //        sql += " and DATEDIFF(day,b.createTime,'" + sdate.Trim() + "')<=0";
        //    if (!string.IsNullOrWhiteSpace(edate))
        //        sql += " and DATEDIFF(day,b.createTime,'" + edate.Trim() + "')>=0";
        //    if (isexport == 1)
        //    {
        //        string sql1 = " 1=1 " + sql;
        //        dt = new BLL.T_AutoCall_Result().exportList(sql1).Tables[0];
        //        NPOIHelper npoi = new NPOIHelper();
        //        if (npoi.ExportToExcel("问题结果数据", dt, col()) == "")
        //        {
        //            return Success("导出成功");
        //        }
        //        else
        //        {
        //            return Error("导出失败");
        //        }
        //    }
        //    else
        //    {
        //        string tablenew = " (select  a.salesOffice, a.phone,a.ordernature,d.qescontent,a.taskid,case b.result when 1 then '十分满意'  when 2 then '满意'  when 3 then '不满意' else '' end result, b.createTime from T_AutoCall_Result b  left join T_AutoCall_PhoneRelate a  on a.F_id = b.F_id left join  T_AutoCall_Question d on d.F_Id = b.questionId) as t";
        //        // dt = new BLL.T_AutoCall_Result().GetListByPage(sql,"", (pageindex - 1) * pagesize, pagesize).Tables[0];
        //        var recordCount = 0;
        //        dt = BLL.PagerBLL.GetListPager(
        //           tablenew,
        //           "taskId",
        //           "*",
        //           sql,
        //           "order by t.createTime desc",
        //           pagesize,
        //           pageindex,
        //           true,
        //           out recordCount);

        //        var obj = new
        //        {
        //            rows = dt,
        //            total = recordCount
        //        };




        //        return Content(dt.ToJson());
        //    }

        //}

      //  (select  (Convert(varchar(100),a.F_Id)+'_'+Convert(varchar(100),d.F_Id)) Id,  a.salesOffice, a.phone,a.ordernature,a.F_Id,d.qescontent,a.taskid,d.F_Id questionId,  case b.result when 1 then '十分满意'  when 2 then '满意'  when 3 then '不满意' else '' end result from T_AutoCall_PhoneRelate a left join T_AutoCall_Question d on d.taskid = a.taskid left join T_AutoCall_Result b on a.F_id = b.F_id and d.F_Id = b.questionId where   a.callstate = 1 ) as t")

        private string[] col()
        {
            string[] ccc = {
                   "营业部","电话号码","用户分类","问题","结果","日期","taskid","qid"
            };
           
            return ccc;
        }


        //获取所有的任务
        public ActionResult GetExportTaskList()
        {
            var alllist = taskbll.GetModelList("1=1 order by taskId desc");
            return Success("获取任务列表下拉成功", alllist);
        }

        //获取问题
        public ActionResult GetQuestionList(int taskId)
        {
            var alllist = quesbll.GetModelList(" taskId='"+taskId+ "' order by F_Id desc");
            return Success("获取任务列表下拉成功", alllist);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="questionId">问题id</param>
        /// <param name="sdate"></param>
        /// <param name="edate"></param>
        /// <param name="salesOffice">营业部</param>
        /// <param name="mubiao">目标分类</param>
        /// <param name="isexport">是导出</param>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <param name="result">结果</param>
        /// <param name="taskid">任务id</param>
        /// <returns></returns>

        public ActionResult GetListExpt(int questionId, string sdate, string edate, string salesOffice, string mubiao, int isexport = 0, int pageindex = 1, int pagesize = 10, string result = null, int taskid = 0)
        {
            string sql = "";
            DataTable dt = new DataTable();
            if (questionId != 0)
            {
                sql += " and  questionId='" + questionId + "'";

            }
          

            if (result != null && result.Trim() != "")
            {
                if (result == "无评价")
                {
                    sql += " and result=''";
                }
                else
                {
                    if (result != "null")
                        sql += " and result='" + result + "'";
                }
                 
                   
            }

            if (taskid != 0)
            {
                sql += " and  taskid='" + taskid + "'";

            }

            if (salesOffice != null && salesOffice.Trim() != "")
            {
                sql += " and salesOffice='" + salesOffice + "'";
            }

            if (mubiao != null && mubiao.Trim() != "")
            {
                sql += " and orderNature='" + mubiao + "'";
            }          



            if (!string.IsNullOrWhiteSpace(sdate))
                sql += " and DATEDIFF(day,createTime,'" + sdate.Trim() + "')<=0";
            if (!string.IsNullOrWhiteSpace(edate))
                sql += " and DATEDIFF(day,createTime,'" + edate.Trim() + "')>=0";
            if (isexport == 1)
            {
                string sql1 = " 1=1 " + sql;
                dt = new BLL.T_AutoCall_Result().exportList(sql1).Tables[0];
                NPOIHelper npoi = new NPOIHelper();
                if (npoi.ExportToExcel("问题结果数据", dt, col()) == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }
            else
            {
                string tablenew = "( select  (Convert(varchar(100),a.F_Id)+'_'+Convert(varchar(100),d.F_Id)) rr,  a.salesOffice, a.phone,a.ordernature,a.F_Id,d.qescontent,a.taskid,d.F_Id questionId,  case b.result when 1 then '十分满意'  when 2 then '满意'  when 3 then '不满意' else '' end result from T_AutoCall_PhoneRelate a  left join T_AutoCall_Question d on d.taskid = a.taskid left join T_AutoCall_Result b on a.F_id = b.F_id and d.F_Id = b.questionId  where   a.callstate = 1)as t";
                    //string tablenew = " (select   a.salesOffice, ROW_NUMBER() OVER(ORDER BY  b.createTime desc) rr, a.phone,a.ordernature,b.F_Id,d.qescontent,b.taskid,b.questionId,case b.result when 1 then '十分满意'  when 2 then '满意'  when 3 then '不满意' else '' end result, b.createTime from T_AutoCall_Result b left join T_AutoCall_PhoneRelate a  on a.F_id = b.F_id left join  T_AutoCall_Question d on d.F_Id = b.questionId ) as t";
            // dt = new BLL.T_AutoCall_Result().GetListByPage(sql,"", (pageindex - 1) * pagesize, pagesize).Tables[0];
                var recordCount = 0;
                dt = BLL.PagerBLL.GetListPager(
                   tablenew,
                   "rr",
                   "*",
                   sql,
                   "order by taskid desc",
                   pagesize,
                   pageindex,
                   true,
                   out recordCount);

                var obj = new
                {
                    rows = dt,
                    total = recordCount
                };




                return Content(obj.ToJson());
            }

        }



        public ActionResult exportlist(int questionId, string sdate, string edate, string salesOffice, string mubiao, int isexport = 0, int pageindex = 1, int pagesize = 10, string result = null, int taskid = 0)
        {

            string sql = "";
            DataTable dt = new DataTable();
            if (questionId != 0)
            {
                sql += " and  F_Id='" + questionId + "'";

            }


            if (result != null && result.Trim() != "")
            {
                if (result == "无评价")
                {
                    sql += " and result=''";
                }
                else
                {
                    if (result == "十分满意")
                    {
                        sql += " and result=1";
                    }
                    else if (result == "满意")
                    {
                        sql += " and result=2";
                    }
                    else if (result == "不满意")
                    {
                        sql += " and result=3";
                    }
                }


            }

            if (taskid != 0)
            {
                sql += " and  taskid='" + taskid + "'";

            }

            if (salesOffice != null && salesOffice.Trim() != "")
            {
                sql += " and salesOffice='" + salesOffice + "'";
            }

            if (mubiao != null && mubiao.Trim() != "")
            {
                sql += " and orderNature='" + mubiao + "'";
            }



            if (!string.IsNullOrWhiteSpace(sdate))
                sql += " and DATEDIFF(day,createTime,'" + sdate.Trim() + "')<=0";
            if (!string.IsNullOrWhiteSpace(edate))
                sql += " and DATEDIFF(day,createTime,'" + edate.Trim() + "')>=0";
            if (isexport == 1)
            {
                string sql1 = " 1=1 " + sql;
                dt = new BLL.T_AutoCall_Result().exportList(sql1).Tables[0];
                NPOIHelper npoi = new NPOIHelper();
                if (npoi.ExportToExcel("问题结果数据", dt, col()) == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }
            else
            {
                return Error("导出失败");
            }
        }
    }
}