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

namespace CallCenterApi.Interface.Controllers.visit
{
    public class VisitRecordsController : BaseController
    {
        //获取回访记录
        public ActionResult GetList(string telid)
        {
                string sql = "";
                DataTable dt = new DataTable();
                if (telid.Trim() != "")
                {
                    sql += " and F_HFID=" + telid.Trim() + " ";
                }
                string strpageindex = RequestString.GetQueryString("page");
                int pageindex = 1;
                string strpagesize = RequestString.GetQueryString("pagesize");
                int pagesize = 10;
                if (strpageindex.Trim() != "")
                {
                    pageindex = Convert.ToInt32(strpageindex);
                }

                if (strpagesize.Trim() != "")
                {
                    pagesize = Convert.ToInt32(strpagesize);
                }
                int recordCount = 0;
                
                dt = BLL.PagerBLL.GetListPager(
                   "T_Vis_TelRecords",
                   "F_TRID",
                   "*",
                   " " + sql,
                   "ORDER BY F_TRID desc",
                   pagesize,
                   pageindex,
                   true,
                   out recordCount);

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

                return Content(obj.ToJson());
        }

        //获取回访通话记录
        public ActionResult GetTelList(string telid, string phone, string usercode)
        {
                string sql = "";
                DataTable dt = new DataTable();
                if (telid != null && telid.Trim() != "")
                {
                    sql += " and OperateType=7 and CallType=1 and OperateObject='" + telid.Trim() + "' ";
                }
                if (phone != null && phone.Trim() != "")
                {
                    sql += " and CallNumber like'%" + phone + "%'";
                }
                if (usercode != null && usercode.Trim() != "")
                {
                    sql += " and UserCode='" + usercode + "'";
                }
                string strpageindex = RequestString.GetQueryString("page");
                int pageindex = 1;
                string strpagesize = RequestString.GetQueryString("pagesize");
                int pagesize = 10;
                if (strpageindex.Trim() != "")
                {
                    pageindex = Convert.ToInt32(strpageindex);
                }

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

                dt = BLL.PagerBLL.GetListPager(
                   "T_Call_CallRecords",
                    "CallRecordsId",
                    "*",
                    sql,
                    "ORDER BY CallRecordsId desc",
                   pagesize,
                   pageindex,
                   true,
                   out recordCount);

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

                return Content(obj.ToJson());
        }
    }
}