using CallCenter.Utility;
using CallCenterApi.DB;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace CallCenter.QuartzService
{
   public   class PushWorkorder : QuartzJob
    {


        public PushWorkorder()
        {
            CronExpression = "0 0 0 * * ? *";
            DoWork += GetLY;
        }

        public void GetLY(object sender, EventArgs e)
        {
           
             while (true)
             {
               if (DateTime.Now.Hour >= 0 && DateTime.Now.Hour <7)
                {
                    Thread.Sleep(6000);
                    string t = TSWORKORDER();
                   
                    if (t != "推送成功"&& t != "推送失败")
                    {
                        LogFactory.GetLogger("22222").Warn(t);
                        break;
                    }
                        
                }
               else
                   break;
             }
           
        }
        public class submit_case_info
        {
            public List<jsonList> jsonList { set; get; }
        }
        public class jsonList
        {
            /// <summary>
            /// "工单编号",
            /// </summary>
            public string CASE_SERIAL { set; get; }
            /// <summary>
            /// "行政区划代码",
            /// </summary>
            public string AREA_CODE { set; get; }
            /// <summary>
            /// "工单唯一标识",
            /// </summary>
            public string CASE_ID { set; get; }//
            /// <summary>
            /// 诉求人姓名
            /// </summary>
            public string APPLICANT_NAME { set; get; }
            /// <summary>
            /// 诉求人性别
            /// </summary>
            public string APPLICANT_SEX { set; get; }
            /// <summary>
            /// 诉求人年龄
            /// </summary>
            public string APPLICANT_AGE { set; get; }
            /// <summary>
            /// 诉求人联系电话
            /// </summary>
            public string APPLICANT_NUMBER { set; get; }
            /// <summary>
            /// 诉求时间
            /// </summary>
            public string APPLICANT_TIME { set; get; }
            /// <summary>
            /// 话务员姓名
            /// </summary>
            public string HWY_NAME { set; get; }
            /// <summary>
            /// 话务员工号
            /// </summary>
            public string HWY_LOGINID { set; get; }
            /// <summary>
            /// 登记时间
            /// </summary>
            public string CASE_TIME { set; get; }
            /// <summary>
            /// 服务工单标题
            /// </summary>
            public string CASE_TITLE { set; get; }
            /// <summary>
            /// 服务工单内容
            /// </summary>
            public string CASE_CONTENT { set; get; }
            /// <summary>
            /// 诉求渠道
            /// </summary>
            public string CASE_SOURCE { set; get; }
            /// <summary>
            /// 诉求类型
            /// </summary>
            public string CASE_TYPE { set; get; }
            /// <summary>
            /// 诉求归口
            /// </summary>
            public string CASE_ACCORD { set; get; }
            /// <summary>
            /// 诉求人信息是否公开
            /// </summary>
            public string CASE_ISPUBLIC { set; get; }
            /// <summary>
            /// 是否回访
            /// </summary>
            public string CASE_ISVISIT { set; get; }
            /// <summary>
            /// 紧急程度
            /// </summary>
            public string CASE_ISURGENT { set; get; }
            /// <summary>
            /// 经纬度
            /// </summary>
            public string CASE_LNGLAT { set; get; }
            /// <summary>
            /// 诉求情感
            /// </summary>
            public string CASE_EMOTION { set; get; }
            /// <summary>
            /// 诉求详细地址
            /// </summary>
            public string CASE_ADDRESS { set; get; }//""
        }
        private int id = 0;
        public string TSWORKORDER()
        {
            try
            {
                if (DateTime.Now.Hour >= 0 && DateTime.Now.Hour <7)
                {

                    string token = GetToken();
                    if (string.IsNullOrEmpty(token))
                        return "token 错误";

                    int count = 0;
                    DataTable Push = new DataTable();
                    string PushWorkorder = "SELECT top 1  *  FROM T_Bus_PushWorkorder";
                    Push = DbHelperSQL.Query(PushWorkorder).Tables[0];
                    if (Push != null)
                    {
                        id = int.Parse(Push.Rows[0]["id"].ToString());
                        count = int.Parse(Push.Rows[0]["count"].ToString());
                    }
                    var modellist = new CallCenterApi.BLL.T_Bus_WorkOrder().GetModelList(5, "F_CreateTime>='2021-02-18 07:37:00'and F_Id>" + id + " and F_IsDelete=0 and F_CreateTime <'2021-12-13 10:06:53.000' AND F_Email ='' " +
                        "and F_CreateUser !='人民网' ", " F_CreateTime ASC");
                    if (modellist != null && modellist.Count > 0)
                    {
                        submit_case_info paras = new submit_case_info();
                        paras.jsonList = new List<jsonList>();
                        foreach (var model in modellist)
                        {
                           
                            jsonList jsonList = new jsonList();
                            string newwokrkorder = "";
                            if (model.F_WorkOrderId.Contains("XX"))
                                newwokrkorder = "YJ" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                            else if (model.F_WorkOrderId.Contains("YS"))
                                newwokrkorder = "DH" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                            else if (model.F_WorkOrderId.Contains("LX"))
                                newwokrkorder = "AP" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                            else if (model.F_WorkOrderId.Contains("RM"))
                                newwokrkorder = "WZ" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                            else if (model.F_WorkOrderId.Contains("ZG"))
                                newwokrkorder = "WZ" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                            else if (model.F_WorkOrderId.Contains("ZW"))
                                newwokrkorder = "WZ" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                            else
                                newwokrkorder = model.F_WorkOrderId;
                            jsonList.CASE_SERIAL = newwokrkorder;
                            jsonList.AREA_CODE = "410500";
                            jsonList.CASE_ID = model.F_Id.ToString();
                            if (string.IsNullOrEmpty(model.F_CusName))
                                jsonList.APPLICANT_NAME = "匿名";
                            else
                                jsonList.APPLICANT_NAME = model.F_CusName;
                            if (model.F_CusSex == "0")
                                jsonList.APPLICANT_SEX = "1";
                            else if (model.F_CusSex == "1")
                                jsonList.APPLICANT_SEX = "2";
                            else
                                jsonList.APPLICANT_SEX = "3";
                            jsonList.APPLICANT_AGE = "8";//没有
                            jsonList.APPLICANT_NUMBER = model.F_CusPhone;
                            jsonList.APPLICANT_TIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");//没有
                            if (DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')") != null)
                                jsonList.HWY_NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')").ToString();
                            else
                                jsonList.HWY_NAME = model.F_CreateUser;
                            jsonList.HWY_LOGINID = model.F_CreateUser;
                            jsonList.CASE_TIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                            if(!string .IsNullOrEmpty (model.F_ComTitle))
                            jsonList.CASE_TITLE = model.F_ComTitle;
                            else 
                            jsonList.CASE_TITLE = "无";
                            jsonList.CASE_CONTENT = model.F_ComContent;
                            if (model.F_InfoSource == 1)
                                jsonList.CASE_SOURCE = "DH";
                            else if (model.F_InfoSource == 2527)
                                jsonList.CASE_SOURCE = "AP";
                            else if (model.F_InfoSource == 5)
                                jsonList.CASE_SOURCE = "WX";
                            else if (model.F_InfoSource == 3)
                                jsonList.CASE_SOURCE = "WB";
                            else
                                jsonList.CASE_SOURCE = "QT";//缺失
                            if (model.F_InfoType == 9)
                                jsonList.CASE_TYPE = "10";
                            else if (model.F_InfoType == 12)
                                jsonList.CASE_TYPE = "15";
                            else if (model.F_InfoType == 11)
                                jsonList.CASE_TYPE = "20";
                            else if (model.F_InfoType == 89)
                                jsonList.CASE_TYPE = "25";
                            else if (model.F_InfoType == 10)
                                jsonList.CASE_TYPE = "30";
                            else if (model.F_InfoType == 13)
                                jsonList.CASE_TYPE = "35";
                            else
                                jsonList.CASE_TYPE = "40";
                            if (DbHelperSQL.GetSingle(" select dbo.GetDicRemark('" + model.F_Key + "')") != null)
                                jsonList.CASE_ACCORD = DbHelperSQL.GetSingle(" select dbo.GetDicRemark('" + model.F_Key + "')").ToString();
                            else
                                jsonList.CASE_ACCORD = "17";
                            jsonList.CASE_ISPUBLIC = model.F_IsOpen.ToString();
                            if (model.F_IsResult == 0)
                                jsonList.CASE_ISPUBLIC = "1";
                            else
                                jsonList.CASE_ISPUBLIC = "0";
                            if (model.F_Level == 2)
                            {
                                jsonList.CASE_ISURGENT = "20";
                            }
                            else
                            {
                                jsonList.CASE_ISURGENT = "30";
                            }
                            if (model.F_VisitType == 1)
                                jsonList.CASE_ISVISIT = "0";
                            else
                                jsonList.CASE_ISVISIT = "1";

                            jsonList.CASE_LNGLAT = model.F_Latitude + "," + model.F_Longitude;
                            jsonList.CASE_EMOTION = "70";
                            jsonList.CASE_ADDRESS = model.F_SourceAddress;

                            try
                            {
                                if (!string.IsNullOrEmpty(model.F_File))
                                {
                                    fjcl(token, newwokrkorder, model.F_File, model.F_SourceArea.ToString(), model.F_Id, "10");
                                }
                                if (model.F_CallRecordId > 0)
                                {
                                    dianhua(token, model.F_WorkOrderId);
                                }
                            }
                            catch
                            {

                            }
                           

                            paras.jsonList.Add(jsonList);
                        }

                        if (paras.jsonList != null && paras.jsonList.Count > 0)
                        {
                            string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();

                          
                            var responseString = HttpMethods.HttpPost("http://59.227.104.19:8000/share/submit_case_info", jsonParam
                              );
                            try
                            {
                                Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                                if (jo.code == "1")
                                {
                                    id = modellist[modellist.Count - 1].F_Id;
                                    count += modellist.Count;
                                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", modellist.FirstOrDefault().F_Id, "", DateTime.Now, jo.code, jo.message, "批量推送工单", "", "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                                    object objres = DbHelperSQL.GetSingle(strSql);
                                    string ts = "update T_Bus_PushWorkorder set id='" + id + "' ,count='" + count + "'";
                                    var rh = DbHelperSQL.GetSingle(ts);
                                    try
                                    {
                                        yiji(token, modellist);
                                        erji(token, modellist);
                                        pingjia(token, modellist);
                                        bajie(token, modellist);
                                        liucheng(token, modellist);
                                        huifangjilu(token, modellist);

                                    }
                                    catch
                                    {
                                        return "推送失败";
                                    }

                                    return "推送成功";
                                }
                                else
                                {
                                    id = modellist[modellist.Count - 1].F_Id;
                                    count += modellist.Count;
                                    string error = "";
                                    if (jo.body.errorObjs != null && jo.body.errorObjs.Length > 0)
                                    {
                                        foreach (var it in jo.body.errorObjs)
                                        {
                                            if (!string.IsNullOrEmpty(it.resturl))
                                            {
                                                error += " 推送接口名称:" + it.resturl;
                                            }
                                            if (!string.IsNullOrEmpty(it.caseserial))
                                            {
                                                error += " 推送工单号:" + it.caseserial;
                                            }
                                            if (!string.IsNullOrEmpty(it.resturl))
                                            {
                                                error += " 推送标识:" + it.errorid;
                                            }
                                            if (!string.IsNullOrEmpty(it.resturl))
                                            {
                                                error += " 推送失败原因:" + it.errormsg;
                                            }
                                        }
                                    }
                                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", jsonParam, DateTime.Now, jo.code, jo.message, "批量推送工单失败", error, "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                                    object objres = DbHelperSQL.GetSingle(strSql);
                                    string ts = "update T_Bus_PushWorkorder set id='" + id + "' ,count='" + count + "'";
                                    var rh = DbHelperSQL.GetSingle(ts);
                                    try
                                    {
                                        yiji(token, modellist);
                                        erji(token, modellist);
                                        pingjia(token, modellist);
                                        bajie(token, modellist);
                                        liucheng(token, modellist);
                                        huifangjilu(token, modellist);

                                    }
                                    catch
                                    {
                                        return "推送失败";
                                    }
                                    return "推送失败";
                                }
                            }
                            catch 
                            {
                                id = modellist[modellist.Count - 1].F_Id;
                             //   count += modellist.Count;
                                string ts = "update T_Bus_PushWorkorder set id='" + id + "'";
                                var rh = DbHelperSQL.GetSingle(ts);
                                return "推送失败";
                            }
                           
                        }
                        else
                        {
                            return "推送失败空";
                        }


                    }
                    else
                    {
                        return "推送完结";
                    }
                }
                else
                {
                    return "等待时间";
                }
            }
            catch (Exception e)
            {
                return e.ToString();
            }
        }
        public void bajie(string token, List<CallCenterApi.Model.T_Bus_WorkOrder> modellist)
        {
            submit_case_finish_info paras = new submit_case_finish_info();
            paras.jsonList = new List<finish_info>();

            foreach (var model in modellist)
            {
                if (model.F_WorkState == 9 && model.F_DealTime!=null )
                {
                    finish_info jsonList = new finish_info();
                    string newwokrkorder = model.F_WorkOrderId;
                    if (model.F_WorkOrderId.Contains("XX"))
                        newwokrkorder = "YJ" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                    else if (model.F_WorkOrderId.Contains("YS"))
                        newwokrkorder = "DH" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                    else if (model.F_WorkOrderId.Contains("LX"))
                        newwokrkorder = "AP" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                    else if (model.F_WorkOrderId.Contains("RM"))
                        newwokrkorder = "WZ" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                    else if (model.F_WorkOrderId.Contains("ZG"))
                        newwokrkorder = "WZ" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                    else if (model.F_WorkOrderId.Contains("ZW"))
                        newwokrkorder = "WZ" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                    else
                        newwokrkorder = model.F_WorkOrderId;
                    jsonList.CASE_SERIAL = newwokrkorder;

                    jsonList.AREA_CODE = "410500";
                    if (model.F_IsResult == null||model.F_IsResult == 1  )
                    {
                        jsonList.FINISH_TYPE = "10";
                        jsonList.DEPT_NAME = "热线中心";
                        if (model.F_CloseTime!=null )
                        jsonList.END_TIME = model.F_CloseTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        else if (model.F_DealTime  != null)
                            jsonList.END_TIME = model.F_DealTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        else
                            jsonList.END_TIME = model.F_CreateTime .Value.ToString("yyyy-MM-dd HH:mm:ss");
                        jsonList.DEPT_CODE = "4105000261";
                    }
                    else
                    {
                        jsonList.FINISH_TYPE = "20";
                        if (model.F_MainDeptId!=null && model.F_MainDeptId > 0&& model.F_DealTime !=null )
                        {
                            jsonList.END_TIME = model.F_DealTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                            if (DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + model.F_MainDeptId + "')") != null)
                                jsonList.DEPT_NAME = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + model.F_MainDeptId + "')").ToString();
                            if (DbHelperSQL.GetSingle(" select F_DeptNameSpell  from T_Sys_Department where F_DeptId= '" + model.F_MainDeptId + "'") != null)
                                jsonList.DEPT_CODE = DbHelperSQL.GetSingle(" select F_DeptNameSpell  from T_Sys_Department where F_DeptId= '" + model.F_MainDeptId + "'").ToString();
                        }
                        else
                        {
                            if (model.F_CloseTime != null)
                                jsonList.END_TIME = model.F_CloseTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                            else if (model.F_DealTime != null)
                                jsonList.END_TIME = model.F_DealTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                            else
                                jsonList.END_TIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                            jsonList.DEPT_NAME = "热线中心";
                            jsonList.DEPT_CODE = "4105000261";
                        }

                    }
                    if (model.F_CloseTime != null)
                        jsonList.FINISH_TIME = model.F_CloseTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                    else if (model.F_DealTime != null)
                        jsonList.FINISH_TIME = model.F_DealTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                    else
                        jsonList.FINISH_TIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");

                   
                    if (DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_DealUser + "')") != null)
                        jsonList.FINISH_NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_DealUser + "')").ToString();
                    else
                        jsonList.FINISH_NAME = model.F_DealUser;
                    if (string.IsNullOrEmpty(jsonList.FINISH_NAME))
                        jsonList.FINISH_NAME = "热线中心";
                    jsonList.FINISH_CONTENT = model.F_Result;
                    jsonList.END_LENGTH = int.Parse(DbHelperSQL.GetSingle(" SELECT DATEDIFF(SECOND,'" + model.F_CreateTime + "', '" + model.F_DealTime + "')").ToString());
                }
            }
            if (paras.jsonList != null && paras.jsonList.Count > 0)
            {
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                var responseString = HttpMethods.HttpPost("http://59.227.104.19:8000/share/submit_case_finish_info", jsonParam);
                Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                if (jo.code == "1")
                {

                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", jsonParam, DateTime.Now, jo.code, jo.message, "批量推送服务工单办结", "", "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                    object objres = DbHelperSQL.GetSingle(strSql);
                }
                else
                {
                    string error = "";
                    if (jo.body.errorObjs != null && jo.body.errorObjs.Length > 0)
                    {
                        foreach (var it in jo.body.errorObjs)
                        {
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送接口名称:" + it.resturl;
                            }
                            if (!string.IsNullOrEmpty(it.caseserial))
                            {
                                error += " 推送工单号:" + it.caseserial;
                            }
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送标识:" + it.errorid;
                            }
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送失败原因:" + it.errormsg;
                            }
                        }
                    }
                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", jsonParam, DateTime.Now, jo.code, jo.message, "批量推送服务工单办结", error, "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                    object objres = DbHelperSQL.GetSingle(strSql);
                }
            }
        }
        public void yiji(string token, List<CallCenterApi.Model.T_Bus_WorkOrder> modellist)
        {
            submit_task_handle_info paras = new submit_task_handle_info();
            paras.jsonList = new List<handle_info>();

            foreach (var models in modellist)
            {
                if (models.F_MainDeptId != null && models.F_MainDeptId > 0)
                {
                    var model = new CallCenterApi.BLL.T_Bus_Feedback().GetNewModelByWorkOrderID(models.F_WorkOrderId);
                    var info = new CallCenterApi.BLL.T_Bus_AssignedInfo().GetNewModelByWorkOrderID(models.F_WorkOrderId);
                    if (model != null && info != null)
                    {
                        handle_info jsonList = new handle_info();
                        string newwokrkorder = models.F_WorkOrderId;
                        if (model.F_WorkOrderId.Contains("XX"))
                            newwokrkorder = "YJ" + models.F_WorkOrderId.Substring(2, models.F_WorkOrderId.Length - 2);
                        else if (model.F_WorkOrderId.Contains("YS"))
                            newwokrkorder = "DH" + models.F_WorkOrderId.Substring(2, models.F_WorkOrderId.Length - 2);
                        else if (model.F_WorkOrderId.Contains("LX"))
                            newwokrkorder = "AP" + models.F_WorkOrderId.Substring(2, models.F_WorkOrderId.Length - 2);
                        else if (model.F_WorkOrderId.Contains("RM"))
                            newwokrkorder = "WZ" + models.F_WorkOrderId.Substring(2, models.F_WorkOrderId.Length - 2);
                        else if (model.F_WorkOrderId.Contains("ZG"))
                            newwokrkorder = "WZ" + models.F_WorkOrderId.Substring(2, models.F_WorkOrderId.Length - 2);
                        else if (model.F_WorkOrderId.Contains("ZW"))
                            newwokrkorder = "WZ" + models.F_WorkOrderId.Substring(2, models.F_WorkOrderId.Length - 2);
                        else
                            newwokrkorder = models.F_WorkOrderId;
                        jsonList.CASE_SERIAL = newwokrkorder;
                        jsonList.AREA_CODE = "410500";
                        jsonList.TASK_ID = model.F_Id.ToString();
                        jsonList.TASK_PARENTID = "TOP";
                        if (DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + model.F_CreateDeptId + "')") != null)
                            jsonList.TASK_OUNAME = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + model.F_CreateDeptId + "')").ToString();
                        else
                            jsonList.TASK_OUNAME = "";
                        if (DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')") != null)
                            jsonList.TASK_USERNAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')").ToString();
                        else
                            jsonList.TASK_USERNAME = model.F_CreateUser;
                        if (string.IsNullOrEmpty(model.F_Result))
                            jsonList.TASK_CONTENT = "无";
                        else
                            jsonList.TASK_CONTENT = model.F_Result;
                        jsonList.TASK_ASSIGNTIME = info.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        jsonList.TASK_SIGNTIME = info.F_SureTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        jsonList.TASK_FINISHTIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        jsonList.TASK_FINISHTIME_BF = info.F_LimitTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        if (info.F_State == 2)
                        {
                            jsonList.TASK_ISBACK = "1";
                        }
                        else
                        {
                            jsonList.TASK_ISBACK = "0";
                        }
                        if (info.F_IsNext > 0)
                        {
                            jsonList.TASK_ISALLOT = "1";
                        }
                        else
                        {
                            jsonList.TASK_ISALLOT = "0";
                        }
                        if (!string.IsNullOrEmpty(model.F_File))
                        {
                            fjcl(token, newwokrkorder, model.F_File, models.F_SourceArea.ToString(), model.F_Id, "20");
                        }
                        jsonList.TASK_HANDLE_LENGTH = int.Parse(DbHelperSQL.GetSingle(" SELECT DATEDIFF(SECOND,'" + jsonList.TASK_ASSIGNTIME + "', '" + jsonList.TASK_FINISHTIME + "')").ToString());
                        paras.jsonList.Add(jsonList);
                    }
                }
            }

            if (paras.jsonList != null && paras.jsonList.Count > 0)
            {
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                var responseString = HttpMethods.HttpPost("http://59.227.104.19:8000/share/submit_task_handle_info", jsonParam);
                Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                if (jo.code == "1")
                {

                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", jsonParam, DateTime.Now, jo.code, jo.message, "批量推送一级部门处办记录", "", "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                    object objres = DbHelperSQL.GetSingle(strSql);
                }
                else
                {
                    string error = "";
                    if (jo.body.errorObjs != null && jo.body.errorObjs.Length > 0)
                    {
                        foreach (var it in jo.body.errorObjs)
                        {
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送接口名称:" + it.resturl;
                            }
                            if (!string.IsNullOrEmpty(it.caseserial))
                            {
                                error += " 推送工单号:" + it.caseserial;
                            }
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送标识:" + it.errorid;
                            }
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送失败原因:" + it.errormsg;
                            }
                        }
                    }
                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", jsonParam, DateTime.Now, jo.code, jo.message, "批量推送一级部门处办记录", error, "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                    object objres = DbHelperSQL.GetSingle(strSql);
                }
            }
        }
        public void erji(string token, List<CallCenterApi.Model.T_Bus_WorkOrder> modellist)
        {
            submit_task_handle_info paras = new submit_task_handle_info();
            paras.jsonList = new List<handle_info>();

            foreach (var models in modellist)
            {
                if (!string.IsNullOrEmpty(models.F_MainDeptID3))
                {
                    var info1 = new CallCenterApi.BLL.T_Bus_AssignedInfo().GetNewModelByWorkOrderID(models.F_WorkOrderId);
                    var model = new CallCenterApi.BLL.T_Bus_Feedback_Next().GetNewModelByWorkOrderID(models.F_WorkOrderId);
                    var info = new CallCenterApi.BLL.T_Bus_AssignedInfo_Next().GetNewModelByWorkOrderID(models.F_WorkOrderId);
                    if (model != null && info != null && info1 != null)
                    {
                        handle_info jsonList = new handle_info();
                        string newwokrkorder = models.F_WorkOrderId;
                        if (model.F_WorkOrderId.Contains("XX"))
                            newwokrkorder = "YJ" + models.F_WorkOrderId.Substring(2, models.F_WorkOrderId.Length - 2);
                        else if (model.F_WorkOrderId.Contains("YS"))
                            newwokrkorder = "DH" + models.F_WorkOrderId.Substring(2, models.F_WorkOrderId.Length - 2);
                        else if (model.F_WorkOrderId.Contains("LX"))
                            newwokrkorder = "AP" + models.F_WorkOrderId.Substring(2, models.F_WorkOrderId.Length - 2);
                        else if (model.F_WorkOrderId.Contains("RM"))
                            newwokrkorder = "WZ" + models.F_WorkOrderId.Substring(2, models.F_WorkOrderId.Length - 2);
                        else if (model.F_WorkOrderId.Contains("ZG"))
                            newwokrkorder = "WZ" + models.F_WorkOrderId.Substring(2, models.F_WorkOrderId.Length - 2);
                        else if (model.F_WorkOrderId.Contains("ZW"))
                            newwokrkorder = "WZ" + models.F_WorkOrderId.Substring(2, models.F_WorkOrderId.Length - 2);
                        else
                            newwokrkorder = models.F_WorkOrderId;
                        jsonList.CASE_SERIAL = newwokrkorder;
                        jsonList.AREA_CODE = "410500";
                        jsonList.TASK_ID = model.F_Id.ToString();
                        jsonList.TASK_PARENTID = info1.F_Id.ToString();
                        if (DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + model.F_CreateDeptId + "')") != null)
                            jsonList.TASK_OUNAME = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + model.F_CreateDeptId + "')").ToString();
                        if (DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')") != null)
                            jsonList.TASK_USERNAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')").ToString();
                        else
                            jsonList.TASK_USERNAME = model.F_CreateUser;
                        jsonList.TASK_CONTENT = model.F_Result;
                        jsonList.TASK_ASSIGNTIME = info.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        jsonList.TASK_SIGNTIME = info.F_SureTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        jsonList.TASK_FINISHTIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        jsonList.TASK_FINISHTIME_BF = info.F_LimitTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        if (info.F_State == 2)
                        {
                            jsonList.TASK_ISBACK = "1";
                        }
                        else
                        {
                            jsonList.TASK_ISBACK = "0";
                        }
                        jsonList.TASK_ISALLOT = "1";
                        jsonList.TASK_HANDLE_LENGTH = int.Parse(DbHelperSQL.GetSingle(" SELECT DATEDIFF(SECOND,'" + jsonList.TASK_ASSIGNTIME + "', '" + jsonList.TASK_FINISHTIME + "')").ToString());
                        paras.jsonList.Add(jsonList);


                    }
                }
               

            }
            if (paras.jsonList != null && paras.jsonList.Count > 0)
            {
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                var responseString = HttpMethods.HttpPost("http://59.227.104.19:8000/share/submit_task_handle_info", jsonParam);
                Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                if (jo.code == "1")
                {

                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", jsonParam, DateTime.Now, jo.code, jo.message, "批量推送二级部门处办记录", "", "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                    object objres = DbHelperSQL.GetSingle(strSql);

                }
                else
                {
                    string error = "";
                    if (jo.body.errorObjs != null && jo.body.errorObjs.Length > 0)
                    {
                        foreach (var it in jo.body.errorObjs)
                        {
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送接口名称:" + it.resturl;
                            }
                            if (!string.IsNullOrEmpty(it.caseserial))
                            {
                                error += " 推送工单号:" + it.caseserial;
                            }
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送标识:" + it.errorid;
                            }
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送失败原因:" + it.errormsg;
                            }
                        }
                    }
                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", jsonParam, DateTime.Now, jo.code, jo.message, "批量推送二级部门处办记录", error, "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                    object objres = DbHelperSQL.GetSingle(strSql);

                }

            }

        }
        public void dianhua(string token, string WorkOrderId)
        {
            var workorder = workorderBLL.GetModel(WorkOrderId);

            var model = new CallCenterApi.BLL.T_Call_CallRecords().GetModelByCallId(workorder.F_CallId);

            if (model != null)
            {
                submit_case_record paras = new submit_case_record();
                paras.jsonList = new List<record>();
                record jsonList = new record();
                string newwokrkorder = WorkOrderId;
                if (WorkOrderId.Contains("XX"))
                    newwokrkorder = "YJ" + WorkOrderId.Substring(2, WorkOrderId.Length - 2);
                else if (WorkOrderId.Contains("YS"))
                    newwokrkorder = "DH" + WorkOrderId.Substring(2, WorkOrderId.Length - 2);
                else if (WorkOrderId.Contains("LX"))
                    newwokrkorder = "AP" + WorkOrderId.Substring(2, WorkOrderId.Length - 2);
                else if (WorkOrderId.Contains("RM"))
                    newwokrkorder = "WZ" + WorkOrderId.Substring(2, WorkOrderId.Length - 2);
                else if (WorkOrderId.Contains("ZG"))
                    newwokrkorder = "WZ" + WorkOrderId.Substring(2, WorkOrderId.Length - 2);
                else if (WorkOrderId.Contains("ZW"))
                    newwokrkorder = "WZ" + WorkOrderId.Substring(2, WorkOrderId.Length - 2);
                else
                    newwokrkorder = WorkOrderId;
                jsonList.CASE_SERIAL = newwokrkorder;
                jsonList.AREA_CODE = "410500";
                jsonList.RECORD_ID = model.CallRecordsId.ToString();
                jsonList.RECORD_PHONE = model.CallNumber;
                if (model.TalkEndTime != null)
                    jsonList.RECORD_STATUS = "30";
                else
                    jsonList.RECORD_STATUS = "10";
                if (model.CallType == 0)
                    jsonList.RECORD_TYPE = "10";
                else
                    jsonList.RECORD_TYPE = "30";
                 if (model.TalkStartTime!=null )
                jsonList.RECORD_STARTTIME = model.TalkStartTime
                    .Value.ToString("yyyy-MM-dd HH:mm:ss");
                if (model.TalkEndTime != null)
                    jsonList.RECORD_ENDTIME = model.TalkEndTime
                    .Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.RECORD_ENDTIME = "";
                jsonList.RECORD_LENGTH = model.TalkLongTime;
                jsonList.RECORD_LOGINID = model.UserCode;
               // var config = new CallCenterApi.BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
                if ( model.FilePath != null)
                {
                    var ym = "http://125.45.12.160:8890/";
                    if (ym.Substring(ym.Length - 1) == "/")
                    {
                        ym = ym.Substring(0, ym.Length - 1);
                    }

                    string lujing = model.FilePath.Substring(model.FilePath.IndexOf(':') + 1).Replace('\\', '/');
                    string wlpath = ym + lujing;

                    jsonList.RECORD_URL = wlpath;
                }
                paras.jsonList.Add(jsonList);
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();

                var responseString = HttpMethods.HttpPost("http://59.227.104.19:8000/share/submit_case_record", jsonParam);

                Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                if (jo.code == "1")
                {

                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", jsonParam, DateTime.Now, jo.code, jo.message, "批量推送电话服务记录", "", "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                    object objres = DbHelperSQL.GetSingle(strSql);
                }
                else
                {
                    string error = "";
                    if (jo.body.errorObjs != null && jo.body.errorObjs.Length > 0)
                    {
                        foreach (var it in jo.body.errorObjs)
                        {
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送接口名称:" + it.resturl;
                            }
                            if (!string.IsNullOrEmpty(it.caseserial))
                            {
                                error += " 推送工单号:" + it.caseserial;
                            }
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送标识:" + it.errorid;
                            }
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送失败原因:" + it.errormsg;
                            }
                        }
                    }
                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", jsonParam, DateTime.Now, jo.code, jo.message, "批量推送电话服务记录", error, "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                    object objres = DbHelperSQL.GetSingle(strSql);

                }
            }

        }
        public void pingjia(string token, List<CallCenterApi.Model.T_Bus_WorkOrder> modellist)
        {
            submit_case_visit_info paras = new submit_case_visit_info();
            paras.jsonList = new List<visit_info>();

            foreach (var models in modellist)
            {
                var model = new CallCenterApi.BLL.T_Bus_VisitResult().GetNewModelByWorkOrderID(models.F_WorkOrderId);
                if (model != null)
                {
                    visit_info jsonList = new visit_info();
                    string newwokrkorder = models.F_WorkOrderId;
                    if (model.F_WorkOrderId.Contains("XX"))
                        newwokrkorder = "YJ" + models.F_WorkOrderId.Substring(2, models.F_WorkOrderId.Length - 2);
                    else if (model.F_WorkOrderId.Contains("YS"))
                        newwokrkorder = "DH" + models.F_WorkOrderId.Substring(2, models.F_WorkOrderId.Length - 2);
                    else if (model.F_WorkOrderId.Contains("LX"))
                        newwokrkorder = "AP" + models.F_WorkOrderId.Substring(2, models.F_WorkOrderId.Length - 2);
                    else if (model.F_WorkOrderId.Contains("RM"))
                        newwokrkorder = "WZ" + models.F_WorkOrderId.Substring(2, models.F_WorkOrderId.Length - 2);
                    else if (model.F_WorkOrderId.Contains("ZG"))
                        newwokrkorder = "WZ" + models.F_WorkOrderId.Substring(2, models.F_WorkOrderId.Length - 2);
                    else if (model.F_WorkOrderId.Contains("ZW"))
                        newwokrkorder = "WZ" + models.F_WorkOrderId.Substring(2, models.F_WorkOrderId.Length - 2);
                    else
                        newwokrkorder = models.F_WorkOrderId;
                    jsonList.CASE_SERIAL = newwokrkorder;
                    jsonList.AREA_CODE = "410500";
                    jsonList.VISIT_TYPE = "DH";
                    jsonList.VISIT_TIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                    if (DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')") != null)
                        jsonList.VISIT_NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')").ToString();
                    else
                        jsonList.VISIT_NAME = model.F_CreateUser;
                    if (string.IsNullOrEmpty(model.F_Result))
                        jsonList.VISIT_CONTENT = "无";
                    else
                        jsonList.VISIT_CONTENT = model.F_Result;
                    if (model.F_IsSatisfie == 0)
                        jsonList.VISIT_SATISFY = "2";
                    else
                        jsonList.VISIT_SATISFY = "4";

                    jsonList.VISIT_NUMBER = int.Parse(DbHelperSQL.GetSingle(" select count(1) from T_Bus_VisitResult  where F_WorkOrderId ='" + model.F_WorkOrderId + "'").ToString());
                    paras.jsonList.Add(jsonList);




                }
            }
            if (paras.jsonList != null && paras.jsonList.Count > 0)
            {
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                var responseString = HttpMethods.HttpPost("http://59.227.104.19:8000/share/submit_case_visit_info", jsonParam);
                Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                if (jo.code == "1")
                {
                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", jsonParam, DateTime.Now, jo.code, jo.message, "批量推送工单最终评价", "", "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                    object objres = DbHelperSQL.GetSingle(strSql);
                }
                else
                {
                    string error = "";
                    if (jo.body.errorObjs != null && jo.body.errorObjs.Length > 0)
                    {
                        foreach (var it in jo.body.errorObjs)
                        {
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送接口名称:" + it.resturl;
                            }
                            if (!string.IsNullOrEmpty(it.caseserial))
                            {
                                error += " 推送工单号:" + it.caseserial;
                            }
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送标识:" + it.errorid;
                            }
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送失败原因:" + it.errormsg;
                            }
                        }
                    }
                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", jsonParam, DateTime.Now, jo.code, jo.message, "批量推送工单最终评价", error, "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                    object objres = DbHelperSQL.GetSingle(strSql);

                }



            }


        }
        public void liucheng(string token, List<CallCenterApi.Model.T_Bus_WorkOrder> modellist)
        {

            submit_case_process_info paras = new submit_case_process_info();
            paras.jsonList = new List<process_info>();
            foreach (var models in modellist)
            {
                var process = new CallCenterApi.BLL.T_Bus_Operation().GetModelList("F_WorkOrderId='" + models.F_WorkOrderId + "'");
                if (process != null)
                {
                    foreach (var model in process)
                    {
                        if (model.F_Message.Contains("查收了") || model.F_Message.Contains("交办了")
                            || model.F_Message.Contains("回访了"))
                        {
                            process_info jsonList = new process_info();
                            string newwokrkorder = model.F_WorkOrderId;
                            if (models.F_WorkOrderId.Contains("XX"))
                                newwokrkorder = "YJ" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                            else if (model.F_WorkOrderId.Contains("YS"))
                                newwokrkorder = "DH" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                            else if (model.F_WorkOrderId.Contains("LX"))
                                newwokrkorder = "AP" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                            else if (model.F_WorkOrderId.Contains("RM"))
                                newwokrkorder = "WZ" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                            else if (model.F_WorkOrderId.Contains("ZG"))
                                newwokrkorder = "WZ" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                            else if (model.F_WorkOrderId.Contains("ZW"))
                                newwokrkorder = "WZ" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                            else
                                newwokrkorder = model.F_WorkOrderId;
                            jsonList.CASE_SERIAL = newwokrkorder;

                            jsonList.AREA_CODE = "410500";
                            jsonList.PROCESS_ID = model.F_Id.ToString();
                            jsonList.DEPT_NAME = model.F_Message.Split('(')[0];
                            if (model.F_Message.Contains("查收了"))
                                jsonList.TACHE_NAME = "查收工单";
                            else if (model.F_Message.Contains("交办了"))
                                jsonList.TACHE_NAME = "交办工单";
                            else if (model.F_Message.Contains("回访了"))
                                jsonList.TACHE_NAME = "审核工单";
                            jsonList.PROCESS_TIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                            if (DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')") != null)
                                jsonList.PROCESS_NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')").ToString();
                            else
                                jsonList.PROCESS_NAME = model.F_CreateUser;
                            jsonList.PROCESS_NOTE = model.F_Message;
                            paras.jsonList.Add(jsonList);
                        }
                    }
                }
            }

            if (paras.jsonList != null && paras.jsonList.Count > 0)
            {
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                var responseString = HttpMethods.HttpPost("http://59.227.104.19:8000/share/submit_case_process_info", jsonParam);
                Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                if (jo.code == "1")
                {

                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", jsonParam, DateTime.Now, jo.code, jo.message, "批量推送工单处理流程", "", "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                    object objres = DbHelperSQL.GetSingle(strSql);
                }
                else
                {
                    string error = "";
                    if (jo.body.errorObjs != null && jo.body.errorObjs.Length > 0)
                    {
                        foreach (var it in jo.body.errorObjs)
                        {
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送接口名称:" + it.resturl;
                            }
                            if (!string.IsNullOrEmpty(it.caseserial))
                            {
                                error += " 推送工单号:" + it.caseserial;
                            }
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送标识:" + it.errorid;
                            }
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送失败原因:" + it.errormsg;
                            }
                        }
                    }
                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", jsonParam, DateTime.Now, jo.code, jo.message, "批量推送工单处理流程", error, "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                    object objres = DbHelperSQL.GetSingle(strSql);
                }
            }

        }
        public void huifangjilu(string token, List<CallCenterApi.Model.T_Bus_WorkOrder> modellist)
        {
            submit_case_visit_detail_info paras = new submit_case_visit_detail_info();
            paras.jsonList = new List<detail_info>();
          //  LogFactory.GetLogger("HttpPost").Warn(modellist.ToJson()+"ttssds");
            foreach (var models in modellist)
            {
                var modelslist = new CallCenterApi.BLL.T_Bus_VisitResult().GetModelList("F_WorkOrderId='" + models.F_WorkOrderId + "'");
                if (modelslist != null && modelslist.Count > 0)
                {
                    foreach (var model in modelslist)
                    {
                        detail_info jsonList = new detail_info();
                        string newwokrkorder = model.F_WorkOrderId;
                        if (model.F_WorkOrderId.Contains("XX"))
                            newwokrkorder = "YJ" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                        else if (model.F_WorkOrderId.Contains("YS"))
                            newwokrkorder = "DH" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                        else if (model.F_WorkOrderId.Contains("LX"))
                            newwokrkorder = "AP" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                        else if (model.F_WorkOrderId.Contains("RM"))
                            newwokrkorder = "WZ" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                        else if (model.F_WorkOrderId.Contains("ZG"))
                            newwokrkorder = "WZ" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                        else if (model.F_WorkOrderId.Contains("ZW"))
                            newwokrkorder = "WZ" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                        else
                            newwokrkorder = model.F_WorkOrderId;
                        jsonList.CASE_SERIAL = newwokrkorder;

                        jsonList.AREA_CODE = "410500";
                        jsonList.VISIT_ID = model.F_Id.ToString();

                        jsonList.VISIT_TYPE = "DH";
                        jsonList.VISIT_TIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        if (DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')") != null)
                            jsonList.VISIT_NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')").ToString();
                        else
                            jsonList.VISIT_NAME = model.F_CreateUser;
                        if (string.IsNullOrEmpty(model.F_Result))
                            jsonList.VISIT_CONTENT = "无";
                        else
                            jsonList.VISIT_CONTENT = model.F_Result;
                        if (model.F_IsSatisfie == 0)
                            jsonList.VISIT_SATISFY = "2";
                        else
                            jsonList.VISIT_SATISFY = "4";
                        paras.jsonList.Add(jsonList);
                    }
                }
            }
            if (paras.jsonList != null && paras.jsonList.Count > 0)
            {
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                var responseString = HttpMethods.HttpPost("http://59.227.104.19:8000/share/submit_case_visit_detail_info", jsonParam);
                Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                if (jo.code == "1")
                {

                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", jsonParam, DateTime.Now, jo.code, jo.message, "批量推送工单回访记录", "", "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                    object objres = DbHelperSQL.GetSingle(strSql);
                }
                else
                {
                    string error = "";
                    if (jo.body.errorObjs != null && jo.body.errorObjs.Length > 0)
                    {
                        foreach (var it in jo.body.errorObjs)
                        {
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送接口名称:" + it.resturl;
                            }
                            if (!string.IsNullOrEmpty(it.caseserial))
                            {
                                error += " 推送工单号:" + it.caseserial;
                            }
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送标识:" + it.errorid;
                            }
                            if (!string.IsNullOrEmpty(it.resturl))
                            {
                                error += " 推送失败原因:" + it.errormsg;
                            }
                        }
                    }
                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", jsonParam, DateTime.Now, jo.code, jo.message, "批量推送工单回访记录", error, "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                    object objres = DbHelperSQL.GetSingle(strSql);
                }

            }



        }
        public void fjcl(string token, string WorkOrderId, string file, string area, int id, string type)
        {
            string ParamValue = "http://docking.zwfw.anyang.gov.cn:9998";
          //  var configfj = configBll.GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
           // if (configfj != null)
           // {
               // ParamValue = configfj.F_ParamValue;
           // }
            submit_case_material_info paras = new submit_case_material_info();
            paras.jsonList = new List<material_info>();
            var Accessories = new CallCenterApi.BLL.T_Sys_Accessories().GetModelList("F_FileId in (" + file + ")");
            if (Accessories != null && Accessories.Count > 0)
            {
                foreach (var it in Accessories)
                {
                    material_info jsonList = new material_info();
                    string newwokrkorder = "";
                    if (WorkOrderId.Contains("XX"))
                        newwokrkorder = "YJ" + WorkOrderId.Substring(2, WorkOrderId.Length - 2);
                    else if (WorkOrderId.Contains("YS"))
                        newwokrkorder = "DH" + WorkOrderId.Substring(2, WorkOrderId.Length - 2);
                    else if (WorkOrderId.Contains("LX"))
                        newwokrkorder = "AP" + WorkOrderId.Substring(2, WorkOrderId.Length - 2);
                    else if (WorkOrderId.Contains("RM"))
                        newwokrkorder = "WZ" + WorkOrderId.Substring(2, WorkOrderId.Length - 2);
                    else if (WorkOrderId.Contains("ZG"))
                        newwokrkorder = "WZ" + WorkOrderId.Substring(2, WorkOrderId.Length - 2);
                    else if (WorkOrderId.Contains("ZW"))
                        newwokrkorder = "WZ" + WorkOrderId.Substring(2, WorkOrderId.Length - 2);
                    else
                        newwokrkorder = WorkOrderId;
                    jsonList.CASE_SERIAL = newwokrkorder;
                    jsonList.AREA_CODE = "410500";
                    jsonList.MATERIAL_ID = it.F_FileId.ToString();
                    jsonList.MATERIAL_NAME = it.F_FileName;
                    jsonList.MATERIAL_FILE_TYPE = it.F_FileType;
                    jsonList.MATERIAL_TYPE = type;
                    jsonList.MATERIAL_CONTACTID = id.ToString();
                    jsonList.MATERAIL_URL = ParamValue + it.F_FileUrl;
                    paras.jsonList.Add(jsonList);
                }
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                var responseString = HttpMethods.HttpPost("http://59.227.104.19:8000/share/submit_case_material_info", jsonParam);
                Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                if (jo.code == "1")
                {

                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", jsonParam, DateTime.Now, jo.code, jo.message, "批量推送服务工单材料", "", "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                    object objres = DbHelperSQL.GetSingle(strSql);
                }
                else
                {
                    string error = "";
                    if (jo.body.errorObjs != null && jo.body.errorObjs.Length > 0)
                    {
                        foreach (var iv in jo.body.errorObjs)
                        {
                            if (!string.IsNullOrEmpty(iv.resturl))
                            {
                                error += " 推送接口名称:" + iv.resturl;
                            }
                            if (!string.IsNullOrEmpty(iv.caseserial))
                            {
                                error += " 推送工单号:" + iv.caseserial;
                            }
                            if (!string.IsNullOrEmpty(iv.resturl))
                            {
                                error += " 推送标识:" + iv.errorid;
                            }
                            if (!string.IsNullOrEmpty(iv.resturl))
                            {
                                error += " 推送失败原因:" + iv.errormsg;
                            }
                        }
                    }
                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", jsonParam, DateTime.Now, jo.code, jo.message, "批量推送服务工单材料", error, "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                    object objres = DbHelperSQL.GetSingle(strSql);

                }
            }


        }
        public class submit_case_record
        {
            public List<record> jsonList { set; get; }
        }
        private CallCenterApi.BLL.T_Bus_WorkOrder workorderBLL = new CallCenterApi.BLL.T_Bus_WorkOrder();
        public class record
        {
            /// <summary>
            /// "工单编号",
            /// </summary>
            public string CASE_SERIAL { set; get; }
            /// <summary>
            /// "行政区划代码",
            /// </summary>
            public string AREA_CODE { set; get; }
            ///<summary>
            /// 录音唯一标识
            /// </summary>
            public string RECORD_ID { set; get; }

            /// <summary>
            /// 电话号码
            /// </summary>
            public string RECORD_PHONE { set; get; }

            /// <summary>
            /// 通话状态
            /// </summary>
            public string RECORD_STATUS { set; get; }
            /// <summary>
            /// 通话类型
            /// </summary>
            public string RECORD_TYPE { set; get; }
            /// <summary>
            /// 通话开始时间
            /// </summary>
            public string RECORD_STARTTIME { set; get; }
            /// <summary>
            /// 通话结束时间
            /// </summary>
            public string RECORD_ENDTIME { set; get; }
            /// <summary>
            /// 通话时长
            /// </summary>
            public int? RECORD_LENGTH { set; get; }
            /// <summary>
            /// 座席人员工号
            /// </summary>
            public string RECORD_LOGINID { set; get; }
            /// <summary>
            /// 录音路径
            /// </summary>
            public string RECORD_URL { set; get; }
        }
        public class submit_case_material_info
        {
            public List<material_info> jsonList { set; get; }
        }
        public class material_info
        {
            /// <summary>
            /// "工单编号",
            /// </summary>
            public string CASE_SERIAL { set; get; }
            /// <summary>
            /// "行政区划代码",
            /// </summary>
            public string AREA_CODE { set; get; }
            ///<summary>
            /// 附件唯一标识
            /// </summary>
            public string MATERIAL_ID { set; get; }

            /// <summary>
            /// 材料名称
            /// </summary>
            public string MATERIAL_NAME { set; get; }

            /// <summary>
            /// 材料文件类型
            /// </summary>
            public string MATERIAL_FILE_TYPE { set; get; }
            /// <summary>
            /// 材料类别
            /// </summary>
            public string MATERIAL_TYPE { set; get; }
            /// <summary>
            /// 材料关联标识
            /// </summary>
            public string MATERIAL_CONTACTID { set; get; }
            /// <summary>
            /// 材料路径
            /// </summary>
            public string MATERAIL_URL { set; get; }
        }
      //  private CallCenterApi.BLL.T_Sys_SystemConfig configBll = new CallCenterApi.BLL.T_Sys_SystemConfig();
        public class submit_case_visit_detail_info
        {
            public List<detail_info> jsonList { set; get; }
        }
        public class detail_info
        {
            /// <summary>
            /// "工单编号",
            /// </summary>
            public string CASE_SERIAL { set; get; }
            /// <summary>
            /// "行政区划代码",
            /// </summary>
            public string AREA_CODE { set; get; }
            ///<summary>
            /// 回访唯一标识
            /// </summary>
            public string VISIT_ID { set; get; }

            /// <summary>
            /// 回访评价方式
            /// </summary>
            public string VISIT_TYPE { set; get; }

            /// <summary>
            /// 回访时间
            /// </summary>
            public string VISIT_TIME { set; get; }
            /// <summary>
            /// 回访人
            /// </summary>
            public string VISIT_NAME { set; get; }
            /// <summary>
            /// 回访评价情况
            /// </summary>
            public string VISIT_CONTENT { set; get; }
            /// <summary>
            /// 回访结果满意度
            /// </summary>
            public string VISIT_SATISFY { set; get; }
        }
        public class submit_case_process_info
        {
            public List<process_info> jsonList { set; get; }
        }
        public class process_info
        {
            /// <summary>
            /// "工单编号",
            /// </summary>
            public string CASE_SERIAL { set; get; }
            /// <summary>
            /// "行政区划代码",
            /// </summary>
            public string AREA_CODE { set; get; }
            ///<summary>
            /// 流程唯一标识
            /// </summary>
            public string PROCESS_ID { set; get; }

            /// <summary>
            /// 环节名称
            /// </summary>
            public string TACHE_NAME { set; get; }

            /// <summary>
            /// 处理部门
            /// </summary>
            public string DEPT_NAME { set; get; }
            /// <summary>
            /// 处理时间
            /// </summary>
            public string PROCESS_TIME { set; get; }
            /// <summary>
            /// 处理人员
            /// </summary>
            public string PROCESS_NAME { set; get; }
            /// <summary>
            /// 处办意见
            /// </summary>
            public string PROCESS_NOTE { set; get; }
        }

        public class submit_case_finish_info
        {
            public List<finish_info> jsonList { set; get; }
        }
        public class finish_info
        {
            /// <summary>
            /// "工单编号",
            /// </summary>
            public string CASE_SERIAL { set; get; }
            /// <summary>
            /// "行政区划代码",
            /// </summary>
            public string AREA_CODE { set; get; }
            ///<summary>
            /// 办结方式
            /// </summary>
            public string FINISH_TYPE { set; get; }

            /// <summary>
            /// 答复单位
            /// </summary>
            public string DEPT_NAME { set; get; }

            /// <summary>
            /// 答复单位组织架构编码
            /// </summary>
            public string DEPT_CODE { set; get; }
            /// <summary>
            /// 答复时间
            /// </summary>
            public string FINISH_TIME { set; get; }
            /// <summary>
            /// 答复人员
            /// </summary>
            public string FINISH_NAME { set; get; }
            /// <summary>
            /// 答复结果
            /// </summary>
            public string FINISH_CONTENT { set; get; }
            /// <summary>
            /// 答复结果
            /// </summary>
            public string END_TIME { set; get; }
            /// <summary>
            /// 处办时长
            /// </summary>
            public int END_LENGTH { set; get; }
        }
        public class submit_case_visit_info
        {
            public List<visit_info> jsonList { set; get; }
        }
        public class visit_info
        {
            /// <summary>
            /// "工单编号",
            /// </summary>
            public string CASE_SERIAL { set; get; }
            /// <summary>
            /// "行政区划代码",
            /// </summary>
            public string AREA_CODE { set; get; }
            ///<summary>
            /// 回访评价方式
            /// </summary>
            public string VISIT_TYPE { set; get; }

            /// <summary>
            /// 回访时间
            /// </summary>
            public string VISIT_TIME { set; get; }

            /// <summary>
            /// 回访人
            /// </summary>
            public string VISIT_NAME { set; get; }
            /// <summary>
            /// 回访评价情况
            /// </summary>
            public string VISIT_CONTENT { set; get; }
            /// <summary>
            /// 回访结果满意度
            /// </summary>
            public string VISIT_SATISFY { set; get; }

            /// <summary>
            /// 回访次数
            /// </summary>
            public int VISIT_NUMBER { set; get; }
        }
        public class submit_task_handle_info
        {
            public List<handle_info> jsonList { set; get; }
        }
        public class handle_info
        {
            /// <summary>
            /// "工单编号",
            /// </summary>
            public string CASE_SERIAL { set; get; }
            /// <summary>
            /// "行政区划代码",
            /// </summary>
            public string AREA_CODE { set; get; }
            /// <summary>
            /// "工单唯一标识",
            /// </summary>                                   
            public string CASE_ID { set; get; }//
            /// <summary>
            /// 任务单唯一标识
            /// </summary>
            public string TASK_ID { set; get; }
            /// <summary>
            /// 父任务单标识
            /// </summary>
            public string TASK_PARENTID { set; get; }
            /// <summary>
            /// 办理部门
            /// </summary>                                         
            public string TASK_OUNAME { set; get; }

            /// <summary>
            /// 办理人员
            /// </summary>            
            public string TASK_USERNAME { set; get; }
            /// <summary>
            /// 反馈意见
            /// </summary>
            public string TASK_CONTENT { set; get; }
            /// <summary>
            /// 交办时间
            /// </summary>
            public string TASK_ASSIGNTIME { set; get; }

            /// <summary>
            /// 签收时间
            /// </summary>
            public string TASK_SIGNTIME { set; get; }
            /// <summary>
            /// 反馈时间
            /// </summary>
            public string TASK_FINISHTIME { set; get; }
            /// <summary>
            /// 应反馈时间
            /// </summary>
            public string TASK_FINISHTIME_BF { set; get; }
            /// <summary>
            /// 是否退回
            /// </summary>
            public string TASK_ISBACK { set; get; }
            /// <summary>
            /// 是否分派
            /// </summary>
            public string TASK_ISALLOT { set; get; }
            /// <summary>
            /// 处办时长
            /// </summary>
            public int TASK_HANDLE_LENGTH { set; get; }

        }
        private string GetToken()
        {

            //Dictionary<string, object> values = new Dictionary<string, object>();
            //values.Add("client_id", "d620caf2-d00f-41a9-ae99-c6dfd435875e");
            //values.Add("client_secret", "4f75914e-d517-4325-ac64-c321377b12f0");
            //values.Add("grant_type", "client_credentials");
            //var jsonParam = JsonConvert.SerializeObject(values);

            string jsonParam = "client_id=d620caf2-d00f-41a9-ae99-c6dfd435875e&client_secret=4f75914e-d517-4325-ac64-c321377b12f0&grant_type=client_credentials";
            var responseString = HttpMethods.HttpPost("http://59.227.104.17/epoint-sso-web/rest/oauth2/token", jsonParam);
            Token jo = JsonConvert.DeserializeObject<Token>(responseString);
            if (jo.status.code == "1")
            {
                if (!string.IsNullOrEmpty(jo.custom.access_token))
                    return jo.custom.access_token;
                else
                    return "";
            }
            else
                return "";

        }
        public class Token
        {
            public List<Controls> controls { set; get; }
            public Custom custom { set; get; }
            public Status status { set; get; }
        }
        public class Controls
        {

        }
        public class Custom
        {
            public string access_token { set; get; }
            public string refresh_token { set; get; }
            public string jsessionid { set; get; }
            public string expires_in { set; get; }
        }
        public class Status
        {
            public string code { set; get; }
        }
        public class Push
        {
            public string code { set; get; }
            public string message { set; get; }

            public body body { set; get; }
        }
        public class body
        {
            public errorObjs[] errorObjs { set; get; }
            public string successCount { set; get; }
            public string totalCount { set; get; }
        }
        public class goback
        {
            public string code { set; get; }
            public string message { set; get; }
        }

        public class errorObjs
        {
            public string resturl { set; get; }
            public string errorid { set; get; }
            public string errormsg { set; get; }
            public string caseserial { set; get; }
        }
    }
}
