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

namespace CallCenterApi.Interface.Controllers
{
    public class ConvergeController : BaseController
    {
        public ActionResult PushWorkroder()
        {
            string message = "123456789";
            int id = 0; int count = 0;
            try
            {
                string PushWorkorder = "SELECT top 1  *  FROM T_Bus_PushWorkorder";
                var BusPushPhone = DbHelperSQL.Query(PushWorkorder).Tables[0];
                if (BusPushPhone != null)
                {
                    id = int.Parse(BusPushPhone.Rows[0]["id"].ToString());
                    count = int.Parse(BusPushPhone.Rows[0]["count"].ToString());
                }
                var Feedback = new BLL.T_Bus_WorkOrder
                    ().GetList(20000, "F_CreateTime>'2024-05-22 10:20:10' " +
                    $" and F_CreateTime < '2024-06-18 16:55:39' and F_Id>={id} and F_IsDelete =0 " +
                    $" and isnull(F_CallId,'')!=''   ", "  F_Id asc").Tables[0];
                if (Feedback != null && Feedback.Rows.Count>0)
                {
                    int i = 0;
                    foreach (DataRow dr in Feedback.Rows)
                    {
                        if (dr["F_InfoSource"].ToString() != "2580" && dr["F_InfoSource"].ToString() != "4606")
                        {
                            Thread.Sleep(1000);
                            id = int.Parse(dr["F_Id"].ToString());
                            pushcase_record(dr["F_WorkOrderId"].ToString(),dr["F_CallId"].ToString());
                            i++; count++;
                            string ts = "update T_Bus_PushWorkorder set id='" + id
                                   + "' ,count='" + count + "'";
                            var rh = DbHelperSQL.GetSingle(ts);
                        }
                        
                    }
                    message = "成功";
                }
            }
            catch (Exception e)
            {
                string ts = "update T_Bus_PushWorkorder set id='" + id + "' ,count='" + count + "'";
                var rh = DbHelperSQL.GetSingle(ts);
                return Error(e.ToJson());
            }
            return Success(message);
        }
        /// <summary>
        /// 电话服务记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void  pushcase_record(string WorkOrderId, string F_CallId)
        {
          
            var model = new BLL.T_Call_CallRecords().GetModelByCallId(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("QT"))
                    newwokrkorder = "WZ" + WorkOrderId.Substring(2, WorkOrderId.Length - 2);
                jsonList.CASE_SERIAL = newwokrkorder;
                jsonList.AREA_CODE = AREA_CODE;
                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");
                else
                    jsonList.RECORD_STARTTIME = DateTime.Now.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 = "";

                if (jsonList.RECORD_ENDTIME == "" && !string.IsNullOrEmpty(jsonList.RECORD_STARTTIME))
                {
                    jsonList.RECORD_ENDTIME = DateTime.Parse(jsonList.RECORD_STARTTIME)
                   .AddMinutes(1).ToString("yyyy-MM-dd HH:mm:ss");
                }



                if (jsonList.RECORD_STARTTIME != null && jsonList.RECORD_ENDTIME != "")
                    jsonList.RECORD_LENGTH = int.Parse(DbHelperSQL.GetSingle
                        (" SELECT DATEDIFF(SECOND,'" + jsonList.RECORD_STARTTIME +
                        "', '" + jsonList.RECORD_ENDTIME + "')").ToString());
                else
                    jsonList.RECORD_LENGTH = 0;


                if (!string.IsNullOrEmpty(model.UserCode))
                    jsonList.RECORD_LOGINID = model.UserCode;
                else
                    jsonList.RECORD_LOGINID = "无";
                var config = new BLL.T_Sys_SystemConfig().
                    GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();

                if (config != null && !string.IsNullOrEmpty(config.F_ParamValue) && model.FilePath != null)
                {
                    var ym = config.F_ParamValue;
                    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 token = GetToken();
                if (string.IsNullOrEmpty(token))
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/dhfwjl"
                        , "token 错误", "电话服务记录", 7);

                }
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                try
                {


                    var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/dhfwjl", jsonParam);

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

                        Model.submit_case_record model_case_record = Classcase_record(jsonList);
                        int n = new BLL.submit_case_record().Add(model_case_record);

                    }
                    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;
                                }
                            }
                        }
                        AddError(paras.ToJson(), "http://59.227.93.14:9000/share/dhfwjl"
                          , error, "电话服务记录", 7);


                    }
                }
                catch (Exception ex)
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/dhfwjl"
                         , ex.Message, "电话服务记录", 7);

                }

            }


        }
        public string pushcase_info(string workorderid)
        {
            Model.T_Bus_WorkOrder model = new BLL.T_Bus_WorkOrder().GetModel(workorderid);
            if (model != null && model.F_InfoSource != 2580 && model.F_InfoSource !=
                4606)
            {
                submit_case_info paras = new submit_case_info();
                Model.submit_case_info caseinfo = new Model.submit_case_info();
                paras.jsonList = new List<jsonList>();
                jsonList jsonList = new jsonList();
                string newwokrkorder = "";
                if (model.F_WorkOrderId.Contains("QT"))
                    newwokrkorder = "WZ" + workorderid.Substring(2, workorderid.Length - 2);
                else
                    newwokrkorder = workorderid;
                jsonList.CASE_SERIAL = newwokrkorder;
                jsonList.AREA_CODE = AREA_CODE;
                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
                {
                    if (jsonList.APPLICANT_NAME.Contains("先生"))
                        jsonList.APPLICANT_SEX = "1";
                    else if (jsonList.APPLICANT_NAME.Contains("女士"))
                        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");//没有
                var NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')");
                if (NAME != null)
                    jsonList.HWY_NAME = NAME.ToString();
                else
                    jsonList.HWY_NAME = model.F_CreateUser;
                if (string.IsNullOrEmpty(jsonList.HWY_NAME))
                    jsonList.HWY_NAME = "系统";

                if (string.IsNullOrEmpty(model.F_CreateUser))
                    jsonList.HWY_LOGINID = "8000";
                else
                    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 = "无";
                if (!string.IsNullOrEmpty(model.F_ComContent))
                {
                    jsonList.CASE_CONTENT = model.F_ComContent;
                }
                else
                    jsonList.CASE_CONTENT = "无";
                jsonList.CASE_SOURCE = model.F_WorkOrderId.Substring(0, 2);
                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 == 10)//求助
                    jsonList.CASE_TYPE = "30";
                else if (model.F_InfoType == 13)//表扬
                    jsonList.CASE_TYPE = "35";
                else
                    jsonList.CASE_TYPE = "40";//其他
                var CASE_ACCORD = DbHelperSQL.GetSingle(" select dbo.GetDicRemark('" + model.F_Key + "')");
                if (CASE_ACCORD != null)
                    jsonList.CASE_ACCORD = CASE_ACCORD.ToString();
                if (string.IsNullOrEmpty(jsonList.CASE_ACCORD))
                    jsonList.CASE_ACCORD = "1403";
                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 || model.F_Level == 3)
                {
                    jsonList.CASE_ISURGENT = "20";
                }
                else
                {
                    jsonList.CASE_ISURGENT = "30";
                }
                if (model.F_IsResult == 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;
                paras.jsonList.Add(jsonList);
                string token = GetToken();
                if (string.IsNullOrEmpty(token))
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/fwgdsl"
                        , "token 错误", "服务工单受理", 0);
                    return "token 错误";
                }
                try
                {
                    string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                    var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/fwgdsl", jsonParam);
                    Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                    if (jo.code == "1")
                    {
                        Model.submit_case_info model_Case_Info = Classsubmit_case_info(jsonList);
                        int n = new BLL.submit_case_info().Add(model_Case_Info);
                        if (n > 0)
                        {
                            return "添加成功";
                        }
                        else
                        {
                            return "添加失败";
                        }

                    }
                    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;
                                }
                            }
                        }
                        AddError(paras.ToJson(), "http://59.227.93.14:9000/share/fwgdsl"
                            , error, "服务工单受理", 0);
                        return "推送失败，" + error + "";

                    }
                }
                catch (Exception ex)
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/fwgdsl"
                             , ex.Message, "服务工单受理", 0);
                    return "推送失败，" + ex.Message + "";
                }

            }
            else
            {
                LogFactory.GetLogger("case_info").Error(workorderid);
                return "推送失败，工单不存在";
            }

        }
        public string pushhandle_info_1(string workorderid)
        {
           
            var workorder = workorderBLL.GetModel(workorderid);
            var model = new BLL.T_Bus_Feedback().GetNewModelByWorkOrderID(workorderid);
            var info = new BLL.T_Bus_AssignedInfo().GetNewModelByWorkOrderID(workorderid);
            if (workorder != null && workorder.F_InfoSource != 2580 && workorder.F_InfoSource !=
                4606 && model != null && info != null)
            {
                submit_task_handle_info paras = new submit_task_handle_info();
                paras.jsonList = new List<handle_info>();
                handle_info jsonList = new handle_info();
                string newwokrkorder = workorderid;
                if (model.F_WorkOrderId.Contains("QT"))
                    newwokrkorder = "WZ" + workorderid.Substring(2, workorderid.Length - 2);
                else
                    newwokrkorder = workorderid;
                jsonList.CASE_SERIAL = newwokrkorder;
                jsonList.AREA_CODE = AREA_CODE;
                jsonList.TASK_ID = model.F_Id.ToString();
                jsonList.TASK_PARENTID = "TOP";
                if (model.F_CreateDeptId != null)
                {
                    var TASK_OUNAME = deptBLL.GetDeptNames(model.F_CreateDeptId.ToString());
                    if (TASK_OUNAME != null)
                        jsonList.TASK_OUNAME = TASK_OUNAME.ToString();
                    else
                        jsonList.TASK_OUNAME = "办理单位";
                }
                else
                {
                    jsonList.TASK_OUNAME = "办理单位";
                }
                if (!string.IsNullOrEmpty(model.F_CreateUser))
                {
                    var TASK_USERNAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')");
                    if (TASK_USERNAME != null)
                        jsonList.TASK_USERNAME = TASK_USERNAME.ToString();
                    else
                        jsonList.TASK_USERNAME = model.F_CreateUser;
                }
                else
                    jsonList.TASK_USERNAME = "8000";

                if (string.IsNullOrEmpty(model.F_Result))
                    jsonList.TASK_CONTENT = "无";
                else
                    jsonList.TASK_CONTENT = model.F_Result;
                if (info.F_CreateTime != null)
                    jsonList.TASK_ASSIGNTIME = info.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.TASK_ASSIGNTIME = DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
                if (info.F_SureTime != null)
                    jsonList.TASK_SIGNTIME = info.F_SureTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.TASK_SIGNTIME = DateTime.Now.AddHours(-30).ToString("yyyy-MM-dd HH:mm:ss");
                if (model.F_CreateTime != null)
                    jsonList.TASK_FINISHTIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.TASK_FINISHTIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");


                if (info.F_LimitTime != null)
                    jsonList.TASK_FINISHTIME_BF = info.F_LimitTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.TASK_FINISHTIME_BF = DateTime.Now.AddDays(1).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 (jsonList.TASK_ASSIGNTIME != null && jsonList.TASK_FINISHTIME != null)
                    jsonList.TASK_HANDLE_LENGTH = int.Parse(DbHelperSQL.GetSingle(" SELECT DATEDIFF(SECOND,'" + jsonList.TASK_ASSIGNTIME + "', '" + jsonList.TASK_FINISHTIME + "')").ToString());
                paras.jsonList.Add(jsonList);
                string token = GetToken();
                if (string.IsNullOrEmpty(token))
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/bmcbjl"
                        , "token 错误", "一级部门处办记录", 1);
                    return "token 错误";
                }
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                try
                {
                    var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/bmcbjl", jsonParam);
                    Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                    if (jo.code == "1")
                    {

                        Model.submit_task_handle_info model_handle_info = Classhandle_info(jsonList);
                        int n = new BLL.submit_task_handle_info().Add(model_handle_info);
                        if (n > 0)
                        {
                            return "添加成功";
                        }
                        else
                        {
                            return "添加失败";
                        }
                    }
                    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;
                                }
                            }
                        }
                        AddError(paras.ToJson(), "http://59.227.93.14:9000/share/bmcbjl"
                        , error, "一级部门处办记录", 1);
                        return "推送失败";
                    }
                }
                catch (Exception ex)
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/bmcbjl"
                         , ex.Message, "一级部门处办记录", 1);
                    return "推送失败，" + ex.Message + "";
                }
            }
            else
                return "工单不存在";

        }
        public string pushhandle_info_2(string workorderid)
        {
            Thread.Sleep(3000);
            var workorder = workorderBLL.GetModel(workorderid);
            var info1 = new BLL.T_Bus_AssignedInfo().GetNewModelByWorkOrderID(workorderid);
            var model = new BLL.T_Bus_Feedback_Next().GetNewModelByWorkOrderID(workorderid);
            var info = new BLL.T_Bus_AssignedInfo_Next().GetNewModelByWorkOrderID(workorderid);
            if (workorder != null && workorder.F_InfoSource != 2580 && workorder.F_InfoSource !=
                4606 && model != null && info != null)
            {
                submit_task_handle_info paras = new submit_task_handle_info();
                paras.jsonList = new List<handle_info>();
                handle_info jsonList = new handle_info();
                string newwokrkorder = workorderid;
                if (model.F_WorkOrderId.Contains("QT"))
                    newwokrkorder = "WZ" + workorderid.Substring(2, workorderid.Length - 2);
                else
                    newwokrkorder = workorderid;
                jsonList.CASE_SERIAL = newwokrkorder;
                jsonList.AREA_CODE = AREA_CODE;
                jsonList.TASK_ID = model.F_Id.ToString();
                jsonList.TASK_PARENTID = info1.F_Id.ToString();

                if (model.F_CreateDeptId != null)
                {
                    var TASK_OUNAME = deptBLL.GetDeptNames(model.F_CreateDeptId.ToString());
                    if (TASK_OUNAME != null)
                        jsonList.TASK_OUNAME = TASK_OUNAME.ToString();
                    else
                        jsonList.TASK_OUNAME = "办理单位";
                }
                else
                {
                    jsonList.TASK_OUNAME = "办理单位";
                }
                if (!string.IsNullOrEmpty(model.F_CreateUser))
                {
                    var TASK_USERNAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')");
                    if (TASK_USERNAME != null)
                        jsonList.TASK_USERNAME = TASK_USERNAME.ToString();
                    else
                        jsonList.TASK_USERNAME = model.F_CreateUser;
                }
                else
                    jsonList.TASK_USERNAME = "8000";

                if (!string.IsNullOrEmpty(model.F_Result))
                    jsonList.TASK_CONTENT = model.F_Result;
                else
                    jsonList.TASK_CONTENT = "无";

                if (info.F_CreateTime != null)
                    jsonList.TASK_ASSIGNTIME = info.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.TASK_ASSIGNTIME = DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
                if (info.F_SureTime != null)
                    jsonList.TASK_SIGNTIME = info.F_SureTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.TASK_SIGNTIME = DateTime.Now.AddHours(-30).ToString("yyyy-MM-dd HH:mm:ss");
                if (model.F_CreateTime != null)
                    jsonList.TASK_FINISHTIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.TASK_FINISHTIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                if (info.F_LimitTime != null)
                    jsonList.TASK_FINISHTIME_BF = info.F_LimitTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.TASK_FINISHTIME_BF = DateTime.Now.AddDays(1).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";
                if (jsonList.TASK_ASSIGNTIME != null && jsonList.TASK_FINISHTIME != null)
                    jsonList.TASK_HANDLE_LENGTH = int.Parse(DbHelperSQL.GetSingle(" SELECT DATEDIFF(SECOND,'" + jsonList.TASK_ASSIGNTIME + "', '" + jsonList.TASK_FINISHTIME + "')").ToString());
                paras.jsonList.Add(jsonList);
                string token = GetToken();
                if (string.IsNullOrEmpty(token))
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/bmcbjl"
                        , "token 错误", "二级部门处办记录", 1);
                    return "token 错误";
                }
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                try
                {

                    var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/bmcbjl", jsonParam);
                    Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                    if (jo.code == "1")
                    {

                        Model.submit_task_handle_info model_handle_info = Classhandle_info(jsonList);
                        int n = new BLL.submit_task_handle_info().Add(model_handle_info);
                        if (n > 0)
                        {
                            return "添加成功";
                        }
                        else
                        {
                            return "添加失败";
                        }
                    }
                    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;
                                }
                            }
                        }
                        AddError(paras.ToJson(), "http://59.227.93.14:9000/share/bmcbjl"
                        , error, "二级部门处办记录", 1);
                        return "推送失败";
                    }
                }
                catch (Exception ex)
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/bmcbjl"
                         , ex.Message, "二级部门处办记录", 1);
                    return "推送失败，" + ex.Message + "";
                }


            }
            return "工单不存在";
        }
        public string pushprocess_info(Model.T_Bus_WorkOrder model)
        {
            var modellist = new BLL.T_Bus_Operation().GetModelList($"F_WorkOrderId='{model.F_WorkOrderId }'");
            if (model != null && modellist != null && modellist.Count > 0)
            {
                submit_case_process_info paras = new submit_case_process_info();
                paras.jsonList = new List<process_info>();
                foreach (var it in modellist)
                {
                    if (it.F_Message.Contains("查收了") || it.F_Message.Contains("交办")
                     || it.F_Message.Contains("回访了"))
                    {
                        process_info jsonList = new process_info();
                        string newwokrkorder = model.F_WorkOrderId;
                        if (model.F_WorkOrderId.Contains("QT"))
                            newwokrkorder = "WZ" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                        jsonList.CASE_SERIAL = newwokrkorder;
                        jsonList.AREA_CODE = AREA_CODE;
                        jsonList.PROCESS_ID = it.F_Id.ToString();
                        jsonList.DEPT_NAME = it.F_CreateUser;
                        if (it.F_Message.Contains("回访了"))
                            jsonList.TACHE_NAME = "审核工单";
                        else if (it.F_Message.Contains("查收了"))
                            jsonList.TACHE_NAME = "查收工单";
                        else
                            jsonList.TACHE_NAME = "交办工单";
                        jsonList.PROCESS_TIME = it.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        if (!string.IsNullOrEmpty(it.F_CreateUser))
                        {
                            var user = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + it.F_CreateUser + "')");
                            if (user != null)
                                jsonList.PROCESS_NAME = user.ToString();
                            else
                                jsonList.PROCESS_NAME = it.F_CreateUser;
                        }
                        else
                            jsonList.PROCESS_NAME = "8000";

                        jsonList.PROCESS_NOTE = it.F_Message;
                        paras.jsonList.Add(jsonList);
                    }

                }
                if (paras != null && paras.jsonList != null && paras.jsonList.Count > 0)
                {
                    string token = GetToken();
                    if (string.IsNullOrEmpty(token))
                    {
                        AddError(paras.ToJson(), "http://59.227.93.14:9000/share/gdcllc"
                            , "token 错误", "工单处理流程", 4);
                        return "token 错误";
                    }
                    string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                    try
                    {

                        var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/gdcllc", jsonParam);
                        Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                        if (jo.code == "1")
                        {
                            foreach (var it in paras.jsonList)
                            {
                                Model.submit_case_process_info model_process_info = Classprocess_info(it);
                                int n = new BLL.submit_case_process_info().Add(model_process_info);
                                if (n > 0)
                                {
                                    return "添加成功";
                                }
                                else
                                {
                                    return "添加失败";
                                }
                            }


                        }
                        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;
                                    }
                                }
                            }
                            AddError(paras.ToJson(), "http://59.227.93.14:9000/share/gdcllc"
                           , error, "工单处理流程", 4);
                            return "推送失败";
                        }
                    }
                    catch (Exception ex)
                    {
                        AddError(paras.ToJson(), "http://59.227.93.14:9000/share/gdcllc"
                     , ex.Message, "工单处理流程", 4);
                        return ex.ToJson();
                    }
                }

            }

            return "";
        }
        public string pushcase_visit_info(string workorderid)
        {

            Thread.Sleep(3000);
            var model = new BLL.T_Bus_VisitResult().GetNewModelByWorkOrderID(workorderid);
            var workorder = workorderBLL.GetModel(workorderid);
            if (workorder != null && model != null && workorder.F_InfoSource != 2580 && workorder.F_InfoSource !=
                4606 && model != null)
            {
                submit_case_visit_info paras = new submit_case_visit_info();
                paras.jsonList = new List<visit_info>();
                visit_info jsonList = new visit_info();
                string newwokrkorder = workorderid;
                if (model.F_WorkOrderId.Contains("QT"))
                    newwokrkorder = "WZ" + workorderid.Substring(2, workorderid.Length - 2);
                else
                    newwokrkorder = workorderid;
                jsonList.CASE_SERIAL = newwokrkorder;
                jsonList.AREA_CODE = AREA_CODE;
                jsonList.VISIT_TYPE = "DH";
                if (model.F_CreateTime != null)
                    jsonList.VISIT_TIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.VISIT_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                if (!string.IsNullOrEmpty(model.F_CreateUser))
                {
                    var NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')");
                    if (NAME != null)
                        jsonList.VISIT_NAME = NAME.ToString();
                    else
                        jsonList.VISIT_NAME = model.F_CreateUser;
                }
                else
                    jsonList.VISIT_NAME = "8000";

                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";
                var NUMBER = DbHelperSQL.GetSingle(" select count(1) from T_Bus_VisitResult  where F_WorkOrderId ='" + model.F_WorkOrderId + "'");
                if (NUMBER != null)
                    jsonList.VISIT_NUMBER = int.Parse(NUMBER.ToString());
                else
                    jsonList.VISIT_NUMBER = 1;
                paras.jsonList.Add(jsonList);
                string token = GetToken();
                if (string.IsNullOrEmpty(token))
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/gdzzpj"
                        , "token 错误", "工单最终评价", 2);
                    return "token 错误";
                }
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                try
                {
                    var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/gdzzpj", jsonParam);
                    Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                    if (jo.code == "1")
                    {

                        Model.submit_case_visit_info model_visit_info = Classvisit_info(jsonList);
                        int n = new BLL.submit_case_visit_info().Add(model_visit_info);
                        if (n > 0)
                        {
                            return "添加成功";
                        }
                        else
                        {
                            return "添加失败";
                        }
                    }
                    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;
                                }
                            }
                        }
                        AddError(paras.ToJson(), "http://59.227.93.14:9000/share/gdzzpj"
                            , error, "工单最终评价", 2);
                        return "推送失败";
                    }
                }
                catch (Exception ex)
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/gdzzpj"
                           , ex.Message, "工单最终评价", 2);
                    return "推送失败，" + ex.Message + "";
                }

            }
            else
                return "工单不存在";

        }
        public string pushcase_finish_info(string workorderid)
        {

            Thread.Sleep(3000);
            var model = workorderBLL.GetModel(workorderid);
            if (model != null && model.F_InfoSource != 2580 && model.F_InfoSource !=
                4606)
            {

                submit_case_finish_info paras = new submit_case_finish_info();
                paras.jsonList = new List<finish_info>();
                finish_info jsonList = new finish_info();
                string newwokrkorder = workorderid;
                if (model.F_WorkOrderId.Contains("QT"))
                    newwokrkorder = "WZ" + workorderid.Substring(2, workorderid.Length - 2);
                else
                    newwokrkorder = workorderid;
                jsonList.CASE_SERIAL = newwokrkorder;

                jsonList.AREA_CODE = AREA_CODE;
                if (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
                        jsonList.END_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    jsonList.DEPT_CODE = "4106000299";
                }
                else
                {
                    jsonList.FINISH_TYPE = "20";
                    if (model.F_MainDeptId > 0)
                    {
                        if (model.F_DealTime != null)
                            jsonList.END_TIME = model.F_DealTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        else if (model.F_CloseTime != null)
                            jsonList.END_TIME = model.F_CloseTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        else
                            jsonList.END_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        var NAME = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + model.F_MainDeptId + "')");
                        if (NAME != null)
                            jsonList.DEPT_NAME = NAME.ToString();
                        else
                            jsonList.DEPT_NAME = "热线中心";

                        var DEPT_CODE = DbHelperSQL.GetSingle(" select F_DeptNameSpell  from T_Sys_Department where F_DeptId= '" + model.F_MainDeptId + "'");
                        if (DEPT_CODE != null)
                            jsonList.DEPT_CODE = DEPT_CODE.ToString();
                        else
                            jsonList.DEPT_CODE = "4106000299";


                    }
                    else
                    {
                        if (model.F_CloseTime != null)
                            jsonList.END_TIME = model.F_CloseTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        else
                            jsonList.END_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        jsonList.DEPT_NAME = "热线中心";
                        jsonList.DEPT_CODE = "4106000299";
                    }

                }
                if (string.IsNullOrEmpty(jsonList.DEPT_CODE))
                    jsonList.DEPT_CODE = "4106000299";

                if (model.F_CloseTime != null)
                    jsonList.FINISH_TIME = model.F_CloseTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.FINISH_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                if (!string.IsNullOrEmpty(model.F_DealUser))
                {
                    var FINISH_NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_DealUser + "')");
                    if (FINISH_NAME != null)
                        jsonList.FINISH_NAME = FINISH_NAME.ToString();
                    else
                        jsonList.FINISH_NAME = model.F_DealUser;
                }
                else
                {
                    jsonList.FINISH_NAME = "8000";
                }

                if (string.IsNullOrEmpty(jsonList.FINISH_NAME))
                    jsonList.FINISH_NAME = "热线中心";
                if (!string.IsNullOrEmpty(model.F_Result))
                    jsonList.FINISH_CONTENT = model.F_Result;
                else
                    jsonList.FINISH_CONTENT = "强制结案";

                if (jsonList.END_TIME != null && model.F_CreateTime != null)
                {
                    var LENGTH = DbHelperSQL.GetSingle(" SELECT DATEDIFF(SECOND,'" + model.F_CreateTime + "', '" + jsonList.END_TIME + "')");
                    if (LENGTH != null)
                        jsonList.END_LENGTH = int.Parse(LENGTH.ToString());
                    else
                        jsonList.END_LENGTH = 100000;
                }
                else
                    jsonList.END_LENGTH = 100000;

                paras.jsonList.Add(jsonList);
                string token = GetToken();
                if (string.IsNullOrEmpty(token))
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/fwgdbj"
                        , "token 错误", "服务工单办结", 3);
                    return "token 错误";
                }
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                try
                {

                    var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/fwgdbj", jsonParam);
                    Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                    if (jo.code == "1")
                    {
                        Model.submit_case_finish_info model_finish_info = Classfinish_info(jsonList);
                        int n = new BLL.submit_case_finish_info().Add(model_finish_info);
                        if (n > 0)
                        {
                            return "添加成功";
                        }
                        else
                        {
                            return "添加失败";
                        }
                    }
                    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;
                                }
                            }
                        }
                        AddError(paras.ToJson(), "http://59.227.93.14:9000/share/fwgdbj"
                         , error, "服务工单办结", 3);
                        return "推送失败";
                    }
                }
                catch (Exception ex)
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/fwgdbj"
                         , ex.Message, "服务工单办结", 3);
                    return "推送失败，" + ex.Message + "";
                }
            }
            else
                return "工单不存在";

        }
        public string pushcase_visit_detail_info(string workorderid)
        {

            Thread.Sleep(3000);
            var model = new BLL.T_Bus_VisitResult().GetNewModelByWorkOrderID(workorderid);
            var workorder = workorderBLL.GetModel(workorderid);
            if (model != null && workorder != null && workorder.F_InfoSource != 2580 && workorder.F_InfoSource !=
                4606)
            {
                submit_case_visit_detail_info paras = new submit_case_visit_detail_info();
                paras.jsonList = new List<detail_info>();
                detail_info jsonList = new detail_info();
                string newwokrkorder = workorderid;
                if (model.F_WorkOrderId.Contains("QT"))
                    newwokrkorder = "WZ" + workorderid.Substring(2, workorderid.Length - 2);
                else
                    newwokrkorder = workorderid;
                jsonList.CASE_SERIAL = newwokrkorder;

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

                jsonList.VISIT_TYPE = "DH";
                if (model.F_CreateTime != null)
                    jsonList.VISIT_TIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.VISIT_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                if (!string.IsNullOrEmpty(model.F_CreateUser))
                {
                    var NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')");
                    if (NAME != null)
                        jsonList.VISIT_NAME = NAME.ToString();
                    else
                        jsonList.VISIT_NAME = model.F_CreateUser;
                }
                else
                {
                    jsonList.VISIT_NAME = "8000";
                }

                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);
                string token = GetToken();
                if (string.IsNullOrEmpty(token))
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/gdhfjl"
                        , "token 错误", "工单回访记录", 5);
                    return "token 错误";
                }
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                try
                {
                    var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/gdhfjl", jsonParam);
                    Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                    if (jo.code == "1")
                    {

                        Model.submit_case_visit_detail_info model_detail_info = Classvisit_detail_info(jsonList);
                        int n = new BLL.submit_case_visit_detail_info().Add(model_detail_info);
                        if (n > 0)
                        {
                            return "添加成功";
                        }
                        else
                        {
                            return "添加失败";
                        }
                    }
                    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;
                                }
                            }
                        }
                        AddError(paras.ToJson(), "http://59.227.93.14:9000/share/gdhfjl"
                          , error, "工单回访记录", 5);
                        return "推送失败";
                    }
                }
                catch (Exception ex)
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/gdhfjl"
                          , ex.Message, "工单回访记录", 5);
                    return "推送失败，" + ex.Message + "";
                }
            }
            else
                return "工单不不存在";

        }
        string AREA_CODE = Configs.GetValue("AREACODE");
        private BLL.T_Bus_WorkOrder workorderBLL = new BLL.T_Bus_WorkOrder();
        #region 服务工单受理
        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; }//""
            public string USER_TYPE { get; set; }
        }
        /// <summary>
        /// </summary>
        /// 服务工单受理
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult case_info(string workorderid)
        {
            Model.T_Bus_WorkOrder model = new BLL.T_Bus_WorkOrder().GetModel(workorderid);
            if (model != null && model.F_InfoSource != 2580 && model.F_InfoSource !=
                4606 )
            {
                submit_case_info paras = new submit_case_info();
                Model.submit_case_info caseinfo = new Model.submit_case_info();
                paras.jsonList = new List<jsonList>();
                jsonList jsonList = new jsonList();
                string newwokrkorder = "";
                if (model.F_WorkOrderId.Contains("QT"))
                    newwokrkorder = "WZ" + workorderid.Substring(2, workorderid.Length - 2);
                else
                    newwokrkorder = workorderid;
                jsonList.CASE_SERIAL = newwokrkorder;
                jsonList.AREA_CODE = AREA_CODE;
                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
                {
                    if (jsonList.APPLICANT_NAME.Contains("先生"))
                        jsonList.APPLICANT_SEX = "1";
                    else if (jsonList.APPLICANT_NAME.Contains("女士"))
                        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");//没有
                var NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')");
                if (NAME != null)
                    jsonList.HWY_NAME = NAME.ToString();
                else
                    jsonList.HWY_NAME = model.F_CreateUser;
                if (string.IsNullOrEmpty(jsonList.HWY_NAME))
                    jsonList.HWY_NAME = "系统";

                if (string.IsNullOrEmpty(model.F_CreateUser))
                    jsonList.HWY_LOGINID = "8000";
                else
                    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 = "无";
                if (!string.IsNullOrEmpty(model.F_ComContent))
                {
                    jsonList.CASE_CONTENT = model.F_ComContent;
                }
                else
                    jsonList.CASE_CONTENT = "无";
                jsonList.CASE_SOURCE = model.F_WorkOrderId.Substring(0, 2);
                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 == 10)//求助
                    jsonList.CASE_TYPE = "30";
                else if (model.F_InfoType == 13)//表扬
                    jsonList.CASE_TYPE = "35";
                else
                    jsonList.CASE_TYPE = "40";//其他
                var CASE_ACCORD = DbHelperSQL.GetSingle(" select dbo.GetDicRemark('" + model.F_Key + "')");
                if (CASE_ACCORD != null)
                    jsonList.CASE_ACCORD = CASE_ACCORD.ToString();
                if (string.IsNullOrEmpty(jsonList.CASE_ACCORD))
                    jsonList.CASE_ACCORD = "1403";
                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|| model.F_Level == 3)
                {
                    jsonList.CASE_ISURGENT = "20";
                }
                else
                {
                    jsonList.CASE_ISURGENT = "30";
                }
                if (model.F_IsBusiness != null && model.F_IsBusiness == 1)
                {
                    jsonList.USER_TYPE = "20";
                }
                else
                {
                    jsonList.USER_TYPE = "10";
                }
                if (model.F_IsResult == 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;
                paras.jsonList.Add(jsonList);
                string token = GetToken();
                if (string.IsNullOrEmpty(token))
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/fwgdsl"
                        , "token 错误", "服务工单受理", 0);
                    return Error("token 错误");
                }
                try
                {
                    string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                    var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/fwgdsl", jsonParam);
                    Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                    if (jo.code == "1")
                    {
                        Model.submit_case_info model_Case_Info = Classsubmit_case_info(jsonList);
                        int n = new BLL.submit_case_info().Add(model_Case_Info);
                        if (n > 0)
                        {
                            return Success("添加成功");
                        }
                        else
                        {
                            return Error("添加失败");
                        }

                    }
                    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;
                                }
                            }
                        }
                        AddError(paras.ToJson(), "http://59.227.93.14:9000/share/fwgdsl"
                            , error, "服务工单受理", 0);
                        return Error("推送失败，" + error + "");

                    }
                }
                catch (Exception ex)
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/fwgdsl"
                             , ex.Message, "服务工单受理", 0);
                    return Error("推送失败，" + ex.Message + "");
                }

            }
            else
            {
                LogFactory.GetLogger("case_info").Error(workorderid);
                return Error("推送失败，工单不存在");
            }

        }
        /// <summary>
        /// 服务工单受理转换
        /// </summary>
        /// <param name="jsonList"></param>
        /// <returns></returns>
        private Model.submit_case_info Classsubmit_case_info(jsonList jsonList)
        {
            Model.submit_case_info model = new Model.submit_case_info();
            model.CASE_SERIAL = jsonList.CASE_SERIAL;//工单编号
            model.AREA_CODE = jsonList.AREA_CODE;//行政区划代码
            model.CASE_ID = jsonList.CASE_ID;//工单唯一标识
            model.APPLICANT_NAME = jsonList.APPLICANT_NAME;//诉求人姓名
            model.APPLICANT_SEX = jsonList.APPLICANT_SEX;//诉求人性别
            model.APPLICANT_AGE = jsonList.APPLICANT_AGE;//诉求人年龄
            model.APPLICANT_NUMBER = jsonList.APPLICANT_NUMBER;//诉求人联系电话
            model.APPLICANT_TIME = jsonList.APPLICANT_TIME;//诉求时间
            model.HWY_NAME = jsonList.HWY_NAME;//话务员姓名
            model.HWY_LOGINID = jsonList.HWY_LOGINID;//话务员工号
            model.CASE_TIME = jsonList.CASE_TIME;//登记时间
            model.CASE_TITLE = jsonList.CASE_TITLE;//服务工单标题
            model.CASE_CONTENT = jsonList.CASE_CONTENT;//服务工单内容
            model.CASE_SOURCE = jsonList.CASE_SOURCE;//诉求渠道
            model.CASE_TYPE = jsonList.CASE_TYPE;//诉求类型
            model.CASE_ACCORD = jsonList.CASE_ACCORD;//诉求归口
            model.CASE_ISPUBLIC = jsonList.CASE_ISPUBLIC;//诉求人信息是否公开
            model.CASE_ISVISIT = jsonList.CASE_ISVISIT;//是否回访
            model.CASE_ISURGENT = jsonList.CASE_ISURGENT;//紧急程度
            model.CASE_LNGLAT = jsonList.CASE_LNGLAT;//经纬度
            model.CASE_EMOTION = jsonList.CASE_EMOTION;//诉求情感
            model.CASE_ADDRESS = jsonList.CASE_ADDRESS;//诉求详细地址
            model.Create_Time = DateTime.Now;
            model.USER_TYPE = jsonList.USER_TYPE;//是否企业诉求
            return model;
        }
        #endregion
        #region 部门处办记录
        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 BLL.T_Sys_UserAccount userBLL = new BLL.T_Sys_UserAccount();
        private BLL.T_Sys_Department deptBLL = new BLL.T_Sys_Department();
        /// <summary>
        /// 一级部门处办记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult handle_info_1(string workorderid)
        {
            Thread.Sleep(3000);
            var workorder = workorderBLL.GetModel(workorderid);
            var model = new BLL.T_Bus_Feedback().GetNewModelByWorkOrderID(workorderid);
            var info = new BLL.T_Bus_AssignedInfo().GetNewModelByWorkOrderID(workorderid);
            if (workorder != null  && workorder.F_InfoSource != 2580 && workorder.F_InfoSource !=
                4606 && model != null && info != null)
            {
                submit_task_handle_info paras = new submit_task_handle_info();
                paras.jsonList = new List<handle_info>();
                handle_info jsonList = new handle_info();
                string newwokrkorder = workorderid;
                if (model.F_WorkOrderId.Contains("QT"))
                    newwokrkorder = "WZ" + workorderid.Substring(2, workorderid.Length - 2);
                else
                    newwokrkorder = workorderid;
                jsonList.CASE_SERIAL = newwokrkorder;
                jsonList.AREA_CODE = AREA_CODE;
                jsonList.TASK_ID = model.F_Id.ToString();
                jsonList.TASK_PARENTID = "TOP";
                if (model.F_CreateDeptId!=null)
                {
                    var TASK_OUNAME = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + model.F_CreateDeptId + "')");
                    if (TASK_OUNAME != null)
                        jsonList.TASK_OUNAME = TASK_OUNAME.ToString();
                    else
                        jsonList.TASK_OUNAME = "办理单位";
                }
                else
                {
                    jsonList.TASK_OUNAME = "办理单位";
                }
                if (!string.IsNullOrEmpty(model.F_CreateUser))
                {
                    var TASK_USERNAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')");
                    if (TASK_USERNAME != null)
                        jsonList.TASK_USERNAME = TASK_USERNAME.ToString();
                    else
                        jsonList.TASK_USERNAME = model.F_CreateUser;
                }
                else
                    jsonList.TASK_USERNAME = "8000";

                if (string.IsNullOrEmpty(model.F_Result))
                    jsonList.TASK_CONTENT = "无";
                else
                    jsonList.TASK_CONTENT = model.F_Result;
                if (info.F_CreateTime != null)
                    jsonList.TASK_ASSIGNTIME = info.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.TASK_ASSIGNTIME = DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
                if (info.F_SureTime != null)
                    jsonList.TASK_SIGNTIME = info.F_SureTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.TASK_SIGNTIME = DateTime.Now.AddHours(-30).ToString("yyyy-MM-dd HH:mm:ss");
                if (model.F_CreateTime != null)
                    jsonList.TASK_FINISHTIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.TASK_FINISHTIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");


                if (info.F_LimitTime != null)
                    jsonList.TASK_FINISHTIME_BF = info.F_LimitTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.TASK_FINISHTIME_BF = DateTime.Now.AddDays(1).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 (jsonList.TASK_ASSIGNTIME != null && jsonList.TASK_FINISHTIME != null)
                    jsonList.TASK_HANDLE_LENGTH = int.Parse(DbHelperSQL.GetSingle(" SELECT DATEDIFF(SECOND,'" + jsonList.TASK_ASSIGNTIME + "', '" + jsonList.TASK_FINISHTIME + "')").ToString());
                paras.jsonList.Add(jsonList);
                string token = GetToken();
                if (string.IsNullOrEmpty(token))
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/bmcbjl"
                        , "token 错误", "一级部门处办记录", 1);
                    return Error("token 错误");
                }
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                try
                {
                    var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/bmcbjl", jsonParam);
                    Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                    if (jo.code == "1")
                    {

                        Model.submit_task_handle_info model_handle_info = Classhandle_info(jsonList);
                        int n = new BLL.submit_task_handle_info().Add(model_handle_info);
                        if (n > 0)
                        {
                            return Success("添加成功");
                        }
                        else
                        {
                            return Error("添加失败");
                        }
                    }
                    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;
                                }
                            }
                        }
                        AddError(paras.ToJson(), "http://59.227.93.14:9000/share/bmcbjl"
                        , error, "一级部门处办记录", 1);
                        return Error("推送失败");
                    }
                }
                catch (Exception ex)
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/bmcbjl"
                         , ex.Message, "一级部门处办记录", 1);
                    return Error("推送失败，" + ex.Message + "");
                }
            }
            else
                return Error("工单不存在");

        }
        /// <summary>
        /// 部门处办记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult handle_info_2(string workorderid)
        {
            Thread.Sleep(3000);
            var workorder = workorderBLL.GetModel(workorderid);
            var info1 = new BLL.T_Bus_AssignedInfo().GetNewModelByWorkOrderID(workorderid);
            var model = new BLL.T_Bus_Feedback_Next().GetNewModelByWorkOrderID(workorderid);
            var info = new BLL.T_Bus_AssignedInfo_Next().GetNewModelByWorkOrderID(workorderid);
            if (workorder != null && workorder.F_InfoSource != 2580 && workorder.F_InfoSource !=
                4606 && model != null && info != null)
            {
                submit_task_handle_info paras = new submit_task_handle_info();
                paras.jsonList = new List<handle_info>();
                handle_info jsonList = new handle_info();
                string newwokrkorder = workorderid;
                if (model.F_WorkOrderId.Contains("QT"))
                    newwokrkorder = "WZ" + workorderid.Substring(2, workorderid.Length - 2);
                else
                    newwokrkorder = workorderid;
                jsonList.CASE_SERIAL = newwokrkorder;
                jsonList.AREA_CODE = AREA_CODE;
                jsonList.TASK_ID = model.F_Id.ToString();
                jsonList.TASK_PARENTID = info1.F_Id.ToString();

                if (model.F_CreateDeptId != null)
                {
                    var TASK_OUNAME = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + model.F_CreateDeptId + "')");
                    if (TASK_OUNAME != null)
                        jsonList.TASK_OUNAME = TASK_OUNAME.ToString();
                    else
                        jsonList.TASK_OUNAME = "办理单位";
                }
                else
                {
                    jsonList.TASK_OUNAME = "办理单位";
                }
                if (!string.IsNullOrEmpty(model.F_CreateUser))
                {
                    var TASK_USERNAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')");
                    if (TASK_USERNAME != null)
                        jsonList.TASK_USERNAME = TASK_USERNAME.ToString();
                    else
                        jsonList.TASK_USERNAME = model.F_CreateUser;
                }
                else
                    jsonList.TASK_USERNAME = "8000";

                if (!string.IsNullOrEmpty(model.F_Result))
                    jsonList.TASK_CONTENT = model.F_Result;
                else
                    jsonList.TASK_CONTENT = "无";

                if (info.F_CreateTime != null)
                    jsonList.TASK_ASSIGNTIME = info.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.TASK_ASSIGNTIME = DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
                if (info.F_SureTime != null)
                    jsonList.TASK_SIGNTIME = info.F_SureTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.TASK_SIGNTIME = DateTime.Now.AddHours(-30).ToString("yyyy-MM-dd HH:mm:ss");
                if (model.F_CreateTime != null)
                    jsonList.TASK_FINISHTIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.TASK_FINISHTIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                if (info.F_LimitTime != null)
                    jsonList.TASK_FINISHTIME_BF = info.F_LimitTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.TASK_FINISHTIME_BF = DateTime.Now.AddDays(1).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";
                if (jsonList.TASK_ASSIGNTIME != null && jsonList.TASK_FINISHTIME != null)
                    jsonList.TASK_HANDLE_LENGTH = int.Parse(DbHelperSQL.GetSingle(" SELECT DATEDIFF(SECOND,'" + jsonList.TASK_ASSIGNTIME + "', '" + jsonList.TASK_FINISHTIME + "')").ToString());
                paras.jsonList.Add(jsonList);
                string token = GetToken();
                if (string.IsNullOrEmpty(token))
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/bmcbjl"
                        , "token 错误", "二级部门处办记录", 1);
                    return Error("token 错误");
                }
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                try
                {

                    var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/bmcbjl", jsonParam);
                    Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                    if (jo.code == "1")
                    {

                        Model.submit_task_handle_info model_handle_info = Classhandle_info(jsonList);
                        int n = new BLL.submit_task_handle_info().Add(model_handle_info);
                        if (n > 0)
                        {
                            return Success("添加成功");
                        }
                        else
                        {
                            return Error("添加失败");
                        }
                    }
                    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;
                                }
                            }
                        }
                        AddError(paras.ToJson(), "http://59.227.93.14:9000/share/bmcbjl"
                        , error, "二级部门处办记录", 1);
                        return Error("推送失败");
                    }
                }
                catch (Exception ex)
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/bmcbjl"
                         , ex.Message, "二级部门处办记录", 1);
                    return Error("推送失败，" + ex.Message + "");
                }


            }
            return Error("工单不存在");
        }

        /// <summary>
        /// 部门处办记录转换
        /// </summary>
        /// <param name="jsonList"></param>
        /// <returns></returns>
        private Model.submit_task_handle_info Classhandle_info(handle_info jsonList)
        {
            Model.submit_task_handle_info model = new Model.submit_task_handle_info();
            model.CASE_SERIAL = jsonList.CASE_SERIAL;//工单编号
            model.AREA_CODE = jsonList.AREA_CODE;//行政区划代码
            model.CASE_ID = jsonList.CASE_ID;//工单唯一标识
            model.TASK_ID = jsonList.TASK_ID;//任务单唯一标识
            model.TASK_PARENTID = jsonList.TASK_PARENTID;//父任务单标识
            model.TASK_OUNAME = jsonList.TASK_OUNAME;//办理部门
            model.TASK_USERNAME = jsonList.TASK_USERNAME;//办理人员
            model.TASK_CONTENT = jsonList.TASK_CONTENT;//反馈意见
            model.TASK_ASSIGNTIME = jsonList.TASK_ASSIGNTIME;//交办时间
            model.TASK_SIGNTIME = jsonList.TASK_SIGNTIME;//签收时间
            model.TASK_FINISHTIME = jsonList.TASK_FINISHTIME;//反馈时间
            model.TASK_FINISHTIME_BF = jsonList.TASK_FINISHTIME_BF;//应反馈时间
            model.TASK_ISBACK = jsonList.TASK_ISBACK;//是否退回
            model.TASK_ISALLOT = jsonList.TASK_ISALLOT;//是否分派
            model.TASK_HANDLE_LENGTH = jsonList.TASK_HANDLE_LENGTH;//处办时长
            model.CreateTime = DateTime.Now;
            return model;
        }
        #endregion
        # region 工单最终评价
        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 int ISRESOLVED { get; set; }
        }
        /// <summary>
        /// 工单最终评价
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult case_visit_info(string workorderid)
        {
            Thread.Sleep(3000);
            var model = new BLL.T_Bus_VisitResult().GetNewModelByWorkOrderID(workorderid);
            var workorder = workorderBLL.GetModel(workorderid);
            if (workorder != null && model != null && workorder.F_InfoSource != 2580 && workorder.F_InfoSource !=
                4606 && model != null )
            {
                submit_case_visit_info paras = new submit_case_visit_info();
                paras.jsonList = new List<visit_info>();
                visit_info jsonList = new visit_info();
                string newwokrkorder = workorderid;
                if (model.F_WorkOrderId.Contains("QT"))
                    newwokrkorder = "WZ" + workorderid.Substring(2, workorderid.Length - 2);
                else
                    newwokrkorder = workorderid;
                jsonList.CASE_SERIAL = newwokrkorder;
                jsonList.AREA_CODE = AREA_CODE;
                jsonList.VISIT_TYPE = "DH";
                if (model.F_CreateTime != null)
                    jsonList.VISIT_TIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.VISIT_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                if (!string.IsNullOrEmpty(model.F_CreateUser))
                {
                    var NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')");
                    if (NAME != null)
                        jsonList.VISIT_NAME = NAME.ToString();
                    else
                        jsonList.VISIT_NAME = model.F_CreateUser;
                }
                else
                    jsonList.VISIT_NAME = "8000";

                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";
                var NUMBER = DbHelperSQL.GetSingle(" select count(1) from T_Bus_VisitResult  where F_WorkOrderId ='" + model.F_WorkOrderId + "'");
                if (NUMBER != null)
                    jsonList.VISIT_NUMBER = int.Parse(NUMBER.ToString());
                else
                    jsonList.VISIT_NUMBER = 1;
                if (model.F_IsResolved != null)
                    jsonList.ISRESOLVED = model.F_IsResolved.Value;
                else
                    jsonList.ISRESOLVED = 1;
                paras.jsonList.Add(jsonList);
                string token = GetToken();
                if (string.IsNullOrEmpty(token))
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/gdzzpj"
                        , "token 错误", "工单最终评价", 2);
                    return Error("token 错误");
                }
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                try
                {
                    var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/gdzzpj", jsonParam);
                    Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                    if (jo.code == "1")
                    {

                        Model.submit_case_visit_info model_visit_info = Classvisit_info(jsonList);
                        int n = new BLL.submit_case_visit_info().Add(model_visit_info);
                        if (n > 0)
                        {
                            return Success("添加成功");
                        }
                        else
                        {
                            return Error("添加失败");
                        }
                    }
                    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;
                                }
                            }
                        }
                        AddError(paras.ToJson(), "http://59.227.93.14:9000/share/gdzzpj"
                            , error, "工单最终评价", 2);
                        return Error("推送失败");
                    }
                }
                catch (Exception ex)
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/gdzzpj"
                           , ex.Message, "工单最终评价", 2);
                    return Error("推送失败，" + ex.Message + "");
                }

            }
            else
                return Error("工单不存在");

        }
    

        /// <summary>
        /// 工单最终评价转换
        /// </summary>
        /// <param name="jsonList"></param>
        /// <returns></returns>
        private Model.submit_case_visit_info Classvisit_info(visit_info jsonList)
        {
            Model.submit_case_visit_info model = new Model.submit_case_visit_info();
            model.CASE_SERIAL = jsonList.CASE_SERIAL;//工单编号
            model.AREA_CODE = jsonList.AREA_CODE;//行政区划代码
            model.VISIT_TYPE = jsonList.VISIT_TYPE;//回访评价方式
            model.VISIT_TIME = jsonList.VISIT_TIME;//回访时间
            model.VISIT_NAME = jsonList.VISIT_NAME;//回访人
            model.VISIT_CONTENT = jsonList.VISIT_CONTENT;//回访评价情况
            model.VISIT_SATISFY = jsonList.VISIT_SATISFY;//回访结果满意度
            model.VISIT_NUMBER = jsonList.VISIT_NUMBER.ToString();//回访次数
            model.CreateTime = DateTime.Now;
            model.ISRESOLVED = jsonList.ISRESOLVED;//
            return model;
        }
        #endregion
        #region 服务工单办结
        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; }

            /// <summary>
            /// 办结状态
            /// </summary>
           // public string  FINISH_STATUS { set; get; }
        }
        /// <summary>
        /// 服务工单办结
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult case_finish_info(string workorderid)
        {
            Thread.Sleep(3000);
            var model = workorderBLL.GetModel(workorderid);
            if (model != null  && model.F_InfoSource != 2580 && model.F_InfoSource !=
                4606 )
            {

                submit_case_finish_info paras = new submit_case_finish_info();
                paras.jsonList = new List<finish_info>();
                finish_info jsonList = new finish_info();
                string newwokrkorder = workorderid;
                if (model.F_WorkOrderId.Contains("QT"))
                    newwokrkorder = "WZ" + workorderid.Substring(2, workorderid.Length - 2);
                else
                    newwokrkorder = workorderid;
                jsonList.CASE_SERIAL = newwokrkorder;

                jsonList.AREA_CODE = AREA_CODE;
                if (model.F_IsResult == 1)
                {
                    jsonList.FINISH_TYPE = "10";
                    jsonList.DEPT_NAME = "热线中心";
                    if (model.F_CloseTime != null)
                        jsonList.FINISH_TIME = model.F_CloseTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                    else
                        jsonList.FINISH_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    jsonList.DEPT_CODE = "4106000299";
                }
                else
                {
                    jsonList.FINISH_TYPE = "20";
                    if (model.F_MainDeptId > 0)
                    {
                        if (model.F_DealTime != null)
                            jsonList.FINISH_TIME = model.F_DealTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        else if (model.F_CloseTime != null)
                            jsonList.FINISH_TIME = model.F_CloseTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        else
                            jsonList.FINISH_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        var NAME = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + model.F_MainDeptId + "')");
                        if (NAME != null)
                            jsonList.DEPT_NAME = NAME.ToString();
                        else
                            jsonList.DEPT_NAME = "热线中心";

                        var DEPT_CODE = DbHelperSQL.GetSingle(" select F_DeptNameSpell  from T_Sys_Department where F_DeptId= '" + model.F_MainDeptId + "'");
                        if (DEPT_CODE != null)
                            jsonList.DEPT_CODE = DEPT_CODE.ToString();
                        else
                            jsonList.DEPT_CODE = "4106000299";


                    }
                    else
                    {
                        if (model.F_CloseTime != null)
                            jsonList.FINISH_TIME = model.F_CloseTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        else
                            jsonList.FINISH_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        jsonList.DEPT_NAME = "热线中心";
                        jsonList.DEPT_CODE = "4106000299";
                    }

                }
                if (string.IsNullOrEmpty(jsonList.DEPT_CODE))
                    jsonList.DEPT_CODE = "4106000299";

                if (model.F_CloseTime != null)
                    jsonList.END_TIME = model.F_CloseTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.END_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                if (!string.IsNullOrEmpty(model.F_DealUser))
                {
                    var FINISH_NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_DealUser + "')");
                    if (FINISH_NAME != null)
                        jsonList.FINISH_NAME = FINISH_NAME.ToString();
                    else
                        jsonList.FINISH_NAME = model.F_DealUser;
                }
                else
                {
                    jsonList.FINISH_NAME = "8000";
                }

                if (string.IsNullOrEmpty(jsonList.FINISH_NAME))
                    jsonList.FINISH_NAME = "热线中心";
                if (!string.IsNullOrEmpty(model.F_Result))
                    jsonList.FINISH_CONTENT = model.F_Result;
                else
                    jsonList.FINISH_CONTENT = "强制结案";

                if (jsonList.END_TIME != null && model.F_CreateTime != null)
                {
                    var LENGTH = DbHelperSQL.GetSingle(" SELECT DATEDIFF(SECOND,'" + model.F_CreateTime + "', '" + jsonList.END_TIME + "')");
                    if (LENGTH != null)
                        jsonList.END_LENGTH = int.Parse(LENGTH.ToString());
                    else
                        jsonList.END_LENGTH = 100000;
                }
                else
                    jsonList.END_LENGTH = 100000;
                //jsonList.FINISH_STATUS = "10";
                paras.jsonList.Add(jsonList);
                string token = GetToken();
                if (string.IsNullOrEmpty(token))
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/fwgdbj"
                        , "token 错误", "服务工单办结", 3);
                    return Error("token 错误");
                }
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                try
                {
                  
                    var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/fwgdbj", jsonParam);
                    Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                    if (jo.code == "1")
                    {
                        Model.submit_case_finish_info model_finish_info = Classfinish_info(jsonList);
                        int n = new BLL.submit_case_finish_info().Add(model_finish_info);
                        if (n > 0)
                        {
                            return Success("添加成功");
                        }
                        else
                        {
                            return Error("添加失败");
                        }
                    }
                    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;
                                }
                            }
                        }
                        AddError(paras.ToJson(), "http://59.227.93.14:9000/share/fwgdbj"
                         , error, "服务工单办结", 3);
                        return Error("推送失败");
                    }
                }
                catch (Exception ex)
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/fwgdbj"
                         , ex.Message, "服务工单办结", 3);
                    return Error("推送失败，" + ex.Message + "");
                }
            }
            else
                return Error("工单不存在");

        }
        /// <summary>
        /// 服务工单办结转换
        /// </summary>
        /// <param name="jsonList"></param>
        /// <returns></returns>
        private Model.submit_case_finish_info Classfinish_info(finish_info jsonList)
        {
            Model.submit_case_finish_info model = new Model.submit_case_finish_info();
            model.CASE_SERIAL = jsonList.CASE_SERIAL;//工单编号
            model.AREA_CODE = jsonList.AREA_CODE;//行政区划代码
            model.FINISH_TYPE = jsonList.FINISH_TYPE;//行政区划代码
            model.DEPT_NAME = jsonList.DEPT_NAME;//行政区划代码
            model.DEPT_CODE = jsonList.DEPT_CODE;//答复单位组织架构编码
            model.FINISH_TIME = jsonList.FINISH_TIME;//答复时间
            model.FINISH_NAME = jsonList.FINISH_NAME;//答复人员
            model.FINISH_CONTENT = jsonList.FINISH_CONTENT;//答复结果
            model.END_TIME = jsonList.END_TIME;//答复
            model.END_LENGTH = jsonList.END_LENGTH;//处办时长
            model.CreateTime = DateTime.Now;
           // model.FINISH_STATUS = jsonList.FINISH_STATUS;
            return model;
        }


    










        #endregion
        #region 工单处理流程
        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; }
        }
       
        /// <summary>
        /// 工单处理流程
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult case_process_info(int id, string title)
        {
            Thread.Sleep(3000);
            var model = new BLL.T_Bus_Operation().GetModel(id);
            var workordr = workorderBLL.GetModel(model.F_WorkOrderId);
            if (model != null && workordr != null && workordr.F_InfoSource != 2580 && workordr.F_InfoSource !=
                4606)
            {
                submit_case_process_info paras = new submit_case_process_info();
                paras.jsonList = new List<process_info>();
                process_info jsonList = new process_info();
                string newwokrkorder = model.F_WorkOrderId;
                if (model.F_WorkOrderId.Contains("QT"))
                    newwokrkorder = "WZ" + model.F_WorkOrderId.Substring(2, model.F_WorkOrderId.Length - 2);
                jsonList.CASE_SERIAL = newwokrkorder;

                jsonList.AREA_CODE = AREA_CODE;
                jsonList.PROCESS_ID = model.F_Id.ToString();
                if (!string.IsNullOrEmpty(model.F_Message))
                {
                    if (model.F_Message.Contains('('))
                        jsonList.DEPT_NAME = model.F_Message.Split('(')[0];
                    else
                        jsonList.DEPT_NAME = "热线中心";
                    jsonList.PROCESS_NOTE = model.F_Message;
                }
                else
                {
                    jsonList.DEPT_NAME = title;
                    jsonList.PROCESS_NOTE = model.F_Message;
                }

                jsonList.TACHE_NAME = title;
                if (model.F_CreateTime != null)
                    jsonList.PROCESS_TIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.PROCESS_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                if (!string.IsNullOrEmpty(model.F_CreateUser))
                {
                    var NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')");
                    if (NAME != null)
                        jsonList.PROCESS_NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')").ToString();
                    else
                        jsonList.PROCESS_NAME = model.F_CreateUser;
                }
                else
                {
                    jsonList.PROCESS_NAME = "8000";

                }
                paras.jsonList.Add(jsonList);
                string token = GetToken();
                if (string.IsNullOrEmpty(token))
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/gdcllc"
                        , "token 错误", "工单处理流程", 4);
                    return Error("token 错误");
                }
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                try
                {

                    var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/gdcllc", jsonParam);
                    Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                    if (jo.code == "1")
                    {

                        Model.submit_case_process_info model_process_info = Classprocess_info(jsonList);
                        int n = new BLL.submit_case_process_info().Add(model_process_info);
                        if (n > 0)
                        {
                            return Success("添加成功");
                        }
                        else
                        {
                            return Error("添加失败");
                        }
                    }
                    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;
                                }
                            }
                        }
                        AddError(paras.ToJson(), "http://59.227.93.14:9000/share/gdcllc"
                       , error, "工单处理流程", 4);
                        return Error("推送失败");
                    }
                }
                catch (Exception ex)
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/gdcllc"
                  , ex.Message, "工单处理流程", 4);
                    return Error("推送失败，" + ex.Message + "");
                }


            }
            else
                return Error("推送失败");

        }
        /// <summary>
        /// 工单处理流程转换
        /// </summary>
        /// <param name="jsonList"></param>
        /// <returns></returns>
        private Model.submit_case_process_info Classprocess_info(process_info jsonList)
        {
            Model.submit_case_process_info model = new Model.submit_case_process_info();
            model.CASE_SERIAL = jsonList.CASE_SERIAL;//工单编号
            model.AREA_CODE = jsonList.AREA_CODE;//行政区划代码
            model.PROCESS_ID = jsonList.PROCESS_ID;//流程唯一标识
            model.TACHE_NAME = jsonList.TACHE_NAME;//环节名称
            model.DEPT_NAME = jsonList.DEPT_NAME;//处理部门
            model.PROCESS_TIME = jsonList.PROCESS_TIME;//处理时间
            model.PROCESS_NAME = jsonList.PROCESS_NAME;//处理人员
            model.PROCESS_NOTE = jsonList.PROCESS_NOTE;//处办意见
            model.CreateTime = DateTime.Now;
            return model;
        }
        #endregion
        #region 工单回访记录
        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; }
        }



        /// <summary>
        /// 工单回访记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult case_visit_detail_info(string workorderid)
        {
            Thread.Sleep(3000);
            var model = new BLL.T_Bus_VisitResult().GetNewModelByWorkOrderID(workorderid);
            var workorder = workorderBLL.GetModel(workorderid);
            if (model != null && workorder != null && workorder.F_InfoSource != 2580 && workorder.F_InfoSource !=
                4606)
            {
                submit_case_visit_detail_info paras = new submit_case_visit_detail_info();
                paras.jsonList = new List<detail_info>();
                detail_info jsonList = new detail_info();
                string newwokrkorder = workorderid;
                if (model.F_WorkOrderId.Contains("QT"))
                    newwokrkorder = "WZ" + workorderid.Substring(2, workorderid.Length - 2);
                else
                    newwokrkorder = workorderid;
                jsonList.CASE_SERIAL = newwokrkorder;

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

                jsonList.VISIT_TYPE = "DH";
                if (model.F_CreateTime != null)
                    jsonList.VISIT_TIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.VISIT_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                if (!string.IsNullOrEmpty(model.F_CreateUser))
                {
                    var NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')");
                    if (NAME != null)
                        jsonList.VISIT_NAME = NAME.ToString();
                    else
                        jsonList.VISIT_NAME = model.F_CreateUser;
                }
                else
                {
                    jsonList.VISIT_NAME = "8000";
                }

                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);
                string token = GetToken();
                if (string.IsNullOrEmpty(token))
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/gdhfjl"
                        , "token 错误", "工单回访记录", 5);
                    return Error("token 错误");
                }
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                try
                {
                    var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/gdhfjl", jsonParam);
                    Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                    if (jo.code == "1")
                    {

                        Model.submit_case_visit_detail_info model_detail_info = Classvisit_detail_info(jsonList);
                        int n = new BLL.submit_case_visit_detail_info().Add(model_detail_info);
                        if (n > 0)
                        {
                            return Success("添加成功");
                        }
                        else
                        {
                            return Error("添加失败");
                        }
                    }
                    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;
                                }
                            }
                        }
                        AddError(paras.ToJson(), "http://59.227.93.14:9000/share/gdhfjl"
                          , error, "工单回访记录", 5);
                        return Error("推送失败");
                    }
                }
                catch (Exception ex)
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/gdhfjl"
                          , ex.Message, "工单回访记录", 5);
                    return Error("推送失败，" + ex.Message + "");
                }
            }
            else
                return Error("工单不不存在");

        }


   
        /// <summary>
        /// 工单回访记录转换
        /// </summary>
        /// <param name="jsonList"></param>
        /// <returns></returns>
        private Model.submit_case_visit_detail_info Classvisit_detail_info(detail_info jsonList)
        {
            Model.submit_case_visit_detail_info model = new Model.submit_case_visit_detail_info();
            model.CASE_SERIAL = jsonList.CASE_SERIAL;//工单编号
            model.AREA_CODE = jsonList.AREA_CODE;//行政区划代码
            model.VISIT_ID = jsonList.VISIT_ID;//回访唯一标识
            model.VISIT_TYPE = jsonList.VISIT_TYPE;//回访评价方式
            model.VISIT_TIME = jsonList.VISIT_TIME;//回访时间
            model.VISIT_NAME = jsonList.VISIT_NAME;//回访人
            model.VISIT_CONTENT = jsonList.VISIT_CONTENT;//回访评价情况
            model.VISIT_SATISFY = jsonList.VISIT_SATISFY;//回访结果满意度
            model.CreateTime = DateTime.Now;
            return model;
        }
        #endregion
        #region 服务工单材料
        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 BLL.T_Sys_SystemConfig configBll = new BLL.T_Sys_SystemConfig();


        /// <summary>
        /// 服务工单材料
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult case_material_info(string WorkOrderId, string file, string area, int id, string type)
        {
            Thread.Sleep(3000);
            string ParamValue = "";
            var configfj = configBll.GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
            if (configfj != null)
            {
                ParamValue = configfj.F_ParamValue;
            }
            else
            {
                return Error("附件路径不存在");
            }
            var workordr = new BLL.T_Bus_WorkOrder().GetModel(WorkOrderId);
            submit_case_material_info paras = new submit_case_material_info();
            paras.jsonList = new List<material_info>();
            material_info jsonList = new material_info();
            var Accessories = new BLL.T_Sys_Accessories().GetModelList("F_FileId in (" + file + ")");
            if (workordr != null  && workordr.F_InfoSource != 2580 && workordr.F_InfoSource !=
                4606 &&
                Accessories != null && Accessories.Count > 0)
            {
                foreach (var it in Accessories)
                {
                    string newwokrkorder = "";
                    if (WorkOrderId.Contains("QT"))
                        newwokrkorder = "WZ" + WorkOrderId.Substring(2, WorkOrderId.Length - 2);
                    else
                        newwokrkorder = WorkOrderId;
                    jsonList.CASE_SERIAL = newwokrkorder;
                    jsonList.AREA_CODE = AREA_CODE;
                    jsonList.MATERIAL_ID = it.F_FileId.ToString();
                    if (!string.IsNullOrEmpty(it.F_FileName))
                        jsonList.MATERIAL_NAME = it.F_FileName;
                    else
                        jsonList.MATERIAL_NAME = "附件名称";
                    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 token = GetToken();
                if (string.IsNullOrEmpty(token))
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/fwgdcl"
                        , "token 错误", "服务工单材料", 6);
                    return Error("token 错误");
                }
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                try
                {
                    var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/fwgdcl", jsonParam);
                    Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                    if (jo.code == "1")
                    {
                        foreach (var it in paras.jsonList)
                        {
                            Model.submit_case_material_info model_material_info =
                                Classmaterial_info(it);
                            int n = new BLL.submit_case_material_info().Add(model_material_info);
                        }
                        return Success("添加成功");

                    }
                    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;
                                }
                            }
                        }
                        AddError(paras.ToJson(), "http://59.227.93.14:9000/share/fwgdcl"
                        , error, "服务工单材料", 6);
                        return Error("推送失败");
                    }
                }
                catch (Exception ex)
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/fwgdcl"
                        , ex.Message, "服务工单材料", 6);
                    return Error("推送失败，" + ex.Message + "");
                }
            }
            else
            {
                return Error("附件不存在");
            }


        }
        /// <summary>
        /// 服务工单材料转换
        /// </summary>
        /// <param name="jsonList"></param>
        /// <returns></returns>
        private Model.submit_case_material_info Classmaterial_info(material_info jsonList)
        {
            Model.submit_case_material_info model = new Model.submit_case_material_info();
            model.CASE_SERIAL = jsonList.CASE_SERIAL;//工单编号
            model.AREA_CODE = jsonList.AREA_CODE;//行政区划代码
            model.MATERIAL_ID = jsonList.MATERIAL_ID;//附件唯一标识
            model.MATERIAL_NAME = jsonList.MATERIAL_NAME;//材料名称
            model.MATERIAL_FILE_TYPE = jsonList.MATERIAL_FILE_TYPE;//材料文件类型
            model.MATERIAL_TYPE = jsonList.MATERIAL_TYPE;//材料类别
            model.MATERIAL_CONTACTID = jsonList.MATERIAL_CONTACTID;//材料关联标识
            model.MATERAIL_URL = jsonList.MATERAIL_URL;//材料路径
            model.CreateTime = DateTime.Now;
            return model;
        }
        #endregion
        #region 电话服务记录
        public class submit_case_record
        {
            public List<record> jsonList { set; get; }
        }
        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; }
        }
        /// <summary>
        /// 电话服务记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult case_record(string WorkOrderId)
        {
            Thread.Sleep(3000);
            var workorder = workorderBLL.GetModel(WorkOrderId);
            var model = new BLL.T_Call_CallRecords().GetModelByCallId(workorder.F_CallId);
            if (model != null && workorder != null && workorder.F_InfoSource != 2580 && workorder.F_InfoSource !=
                4606)
            {
                submit_case_record paras = new submit_case_record();
                paras.jsonList = new List<record>();
                record jsonList = new record();
                string newwokrkorder = WorkOrderId;
                if (WorkOrderId.Contains("QT"))
                    newwokrkorder = "WZ" + WorkOrderId.Substring(2, WorkOrderId.Length - 2);
                jsonList.CASE_SERIAL = newwokrkorder;
                jsonList.AREA_CODE = AREA_CODE;
                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");
                else
                    jsonList.RECORD_STARTTIME = DateTime.Now.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 = "";

                if (jsonList.RECORD_ENDTIME == "" && !string.IsNullOrEmpty(jsonList.RECORD_STARTTIME))
                {
                    jsonList.RECORD_ENDTIME = DateTime.Parse(jsonList.RECORD_STARTTIME)
                   .AddMinutes(1).ToString("yyyy-MM-dd HH:mm:ss");
                }



                if (jsonList.RECORD_STARTTIME != null && jsonList.RECORD_ENDTIME != "")
                    jsonList.RECORD_LENGTH = int.Parse(DbHelperSQL.GetSingle
                        (" SELECT DATEDIFF(SECOND,'" + jsonList.RECORD_STARTTIME +
                        "', '" + jsonList.RECORD_ENDTIME + "')").ToString());
                else
                    jsonList.RECORD_LENGTH = 0;


                if (!string.IsNullOrEmpty(model.UserCode))
                    jsonList.RECORD_LOGINID = model.UserCode;
                else
                    jsonList.RECORD_LOGINID = "无";
                var config = new BLL.T_Sys_SystemConfig().
                    GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();

                if (config != null && !string.IsNullOrEmpty(config.F_ParamValue) && model.FilePath != null)
                {
                    var ym = config.F_ParamValue;
                    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 token = GetToken();
                if (string.IsNullOrEmpty(token))
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/dhfwjl"
                        , "token 错误", "电话服务记录", 7);
                    return Error("token 错误");
                }
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                try
                {


                    var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/dhfwjl", jsonParam);

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

                        Model.submit_case_record model_case_record = Classcase_record(jsonList);
                        int n = new BLL.submit_case_record().Add(model_case_record);
                        if (n > 0)
                        {
                            return Success("添加成功");
                        }
                        else
                        {
                            return Error("添加失败");
                        }
                    }
                    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;
                                }
                            }
                        }
                        AddError(paras.ToJson(), "http://59.227.93.14:9000/share/dhfwjl"
                          , error, "电话服务记录", 7);
                        return Error("推送失败，" + error + "");

                    }
                }
                catch (Exception ex)
                {
                    AddError(paras.ToJson(), "http://59.227.93.14:9000/share/dhfwjl"
                         , ex.Message, "电话服务记录", 7);
                    return Error("推送失败，" + ex.Message + "");
                }
            }
            else
                return Error("通话记录不存在");

        }
        /// <summary>
        /// 电话服务记录转换
        /// </summary>
        /// <param name="jsonList"></param>
        /// <returns></returns>
        private Model.submit_case_record Classcase_record(record jsonList)
        {
            Model.submit_case_record model = new Model.submit_case_record();
            model.CASE_SERIAL = jsonList.CASE_SERIAL;//工单编号
            model.AREA_CODE = jsonList.AREA_CODE;//行政区划代码
            model.RECORD_ID = jsonList.RECORD_ID;//录音唯一标识
            model.RECORD_PHONE = jsonList.RECORD_PHONE;//电话号码
            model.RECORD_STATUS = jsonList.RECORD_STATUS;//通话状态
            model.RECORD_TYPE = jsonList.RECORD_TYPE;//通话类型
            model.RECORD_STARTTIME = jsonList.RECORD_STARTTIME;//通话开始时间
            model.RECORD_ENDTIME = jsonList.RECORD_ENDTIME;//通话结束时间
            model.RECORD_LENGTH = jsonList.RECORD_LENGTH.ToString();//通话时长
            model.RECORD_LOGINID = jsonList.RECORD_LOGINID;//座席人员工号
            model.RECORD_URL = jsonList.RECORD_URL;//录音路径
            model.CreateTime = DateTime.Now;
            return model;
        }
        #endregion

        /// <summary>
        /// 添加错误日志
        /// </summary>
        /// <param name="content"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public int AddError(string content, string url, string ErrorMsg, string Title, int order = 0)
        {
            Model.submit_RePush model = new Model.submit_RePush();
            model.Code = 0;
            model.CreateTime = DateTime.Now;
            model.ErrorMsg = ErrorMsg;
            model.F_Content = content;
            model.F_Url = url;
            model.Title = Title;
            model.Sequence = order;
            model.number = 0;
            return new BLL.submit_RePush().Add(model);
        }


        #region 重推
        /// <summary>
        /// 重推服务工单受理
        /// </summary>
        /// <returns></returns>
        public ActionResult RePush()
        {
            string token = GetToken();
            if (!string.IsNullOrEmpty(token))
            {
                var modellist = new BLL.submit_RePush().GetModelList("Code=0 and Sequence=0");
                if (modellist != null && modellist.Count > 0)
                {

                    foreach (var model in modellist)
                    {
                        if (model.number > 5)
                        {
                            continue;
                        }
                        Thread.Sleep(3000);
                        model.F_Content = model.F_Content.Replace("\n", "").Replace(@"'", "").Replace(@"\", "").Replace("\t", "").Replace("%", "%25");
                        string jsonParam = "access_token=" + token + "&paras=" + model.F_Content;
                        try
                        {
                            var responseString = HttpMethods.HttpPost(model.F_Url, jsonParam);
                            Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                            if (jo.code == "1")
                            {
                                submit_case_info case_info = JsonConvert.DeserializeObject<submit_case_info>(model.F_Content);
                                foreach (var it in case_info.jsonList)
                                {
                                    Model.submit_case_info model_Case_Info = Classsubmit_case_info(it);
                                    int n = new BLL.submit_case_info().Add(model_Case_Info);
                                }
                                model.Code = 1;
                                bool m = new BLL.submit_RePush().Update(model);
                            }
                            else
                            {
                                model.number = model.number + 1;
                                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;
                                        }
                                    }
                                }
                                model.ErrorMsg = error;
                                bool n = new BLL.submit_RePush().Update(model);
                            }
                        }
                        catch (Exception ex)
                        {
                            model.number = model.number + 1;
                            model.ErrorMsg = ex.Message;
                            bool n = new BLL.submit_RePush().Update(model);
                        }
                        if (model.number > 5)
                        {
                            HttpMethods.HttpGet(NativeURL + "/Converge/DingTalkSendMessageText?mobile=17839539537&content=" + model.ErrorMsg);
                        }
                    }
                }
                return Success("推送完毕");
            }
            else
            {
                return Error("token 错误");
            }

        }
        string NativeURL = Configs.GetValue("NativeURL");
        /// <summary>
        /// 重推其他
        /// </summary>
        /// <returns></returns>
        public ActionResult ReOtherPush()
        {
            string token = GetToken();
            if (!string.IsNullOrEmpty(token))
            {
                var modellist = new BLL.submit_RePush().GetModelList("Code=0 and Sequence!=0");
                if (modellist != null && modellist.Count > 0)
                {
                    foreach (var model in modellist)
                    {
                        if (model.number > 5)
                        {
                            continue;
                        }
                        Thread.Sleep(3000);
                        model.F_Content = model.F_Content.Replace("\n", "").Replace(@"'", "").Replace(@"\", "").Replace("\t", "").Replace("%", "%25");
                        string jsonParam = "access_token=" + token + "&paras=" + model.F_Content;
                        try
                        {
                            var responseString = HttpMethods.HttpPost(model.F_Url, jsonParam);
                            Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                            if (jo.code == "1")
                            {
                                switch (model.Sequence)
                                {
                                    case 1:
                                        submit_task_handle_info handle_info = JsonConvert.
                                            DeserializeObject<submit_task_handle_info>(model.F_Content);
                                        foreach (var it in handle_info.jsonList)
                                        {
                                            Model.submit_task_handle_info model_handle_info = Classhandle_info(it);
                                            int n = new BLL.submit_task_handle_info().Add(model_handle_info);
                                        }
                                        break;
                                    case 2:
                                        submit_case_visit_info visit_info = JsonConvert.
                                            DeserializeObject<submit_case_visit_info>(model.F_Content);
                                        foreach (var it in visit_info.jsonList)
                                        {
                                            Model.submit_case_visit_info model_visit_info = Classvisit_info(it);
                                            int n = new BLL.submit_case_visit_info().Add(model_visit_info);
                                        }
                                        break;
                                    case 3:
                                        submit_case_finish_info case_finish_info = JsonConvert.
                                            DeserializeObject<submit_case_finish_info>(model.F_Content);
                                        foreach (var it in case_finish_info.jsonList)
                                        {
                                            Model.submit_case_finish_info model_finish_info = Classfinish_info(it);
                                            int n = new BLL.submit_case_finish_info().Add(model_finish_info);
                                        }
                                        break;
                                    case 4:
                                        submit_case_process_info case_process_info = JsonConvert.
                                            DeserializeObject<submit_case_process_info>(model.F_Content);
                                        foreach (var it in case_process_info.jsonList)
                                        {
                                            Model.submit_case_process_info model_process_info = Classprocess_info(it);
                                            int n = new BLL.submit_case_process_info().Add(model_process_info);
                                        }
                                        break;
                                    case 5:
                                        submit_case_visit_detail_info case_visit_detail_info = JsonConvert.
                                            DeserializeObject<submit_case_visit_detail_info>(model.F_Content);
                                        foreach (var it in case_visit_detail_info.jsonList)
                                        {
                                            Model.submit_case_visit_detail_info model_visit_detail_info = Classvisit_detail_info(it);
                                            int n = new BLL.submit_case_visit_detail_info().Add(model_visit_detail_info);
                                        }
                                        break;
                                    case 6:
                                        submit_case_material_info case_material_info = JsonConvert.
                                            DeserializeObject<submit_case_material_info>(model.F_Content);
                                        foreach (var it in case_material_info.jsonList)
                                        {
                                            Model.submit_case_material_info model_material_info = Classmaterial_info(it);
                                            int n = new BLL.submit_case_material_info().Add(model_material_info);
                                        }
                                        break;
                                    case 7:
                                        submit_case_record case_record = JsonConvert.
                                            DeserializeObject<submit_case_record>(model.F_Content);
                                        foreach (var it in case_record.jsonList)
                                        {
                                            Model.submit_case_record model_record = Classcase_record(it);
                                            int n = new BLL.submit_case_record().Add(model_record);
                                        }
                                        break;
                                }
                                model.Code = 1;
                                bool m = new BLL.submit_RePush().Update(model);
                            }
                            else
                            {
                                model.number = model.number + 1;
                                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;
                                        }
                                    }
                                }
                                model.ErrorMsg = error;
                                bool n = new BLL.submit_RePush().Update(model);
                            }
                        }
                        catch (Exception ex)
                        {
                            model.number = model.number + 1;
                            model.ErrorMsg = ex.Message;
                            bool n = new BLL.submit_RePush().Update(model);
                        }
                        if (model.number > 5 && !model.ErrorMsg.Contains("服务工单受理表无数据"))
                        {
                            HttpMethods.HttpGet(NativeURL+ "/Converge/DingTalkSendMessageText?mobile=17839539537&content=" + model.ErrorMsg);
                        }
                    }
                }
                return Success("推送完毕");
            }
            else
            {
                return Error("token 错误");
            }

        }
        #endregion

        #region 获取token 
        private string GetToken()
        {

            try
            {
                string jsonParam = "client_id=b3e2ed3b-672a-43a0-80db-21f790c0368d&client_secret=362b50d7-2aa5-4874-9363-6c0ba483dfe9&grant_type=client_credentials";
                var responseString = HttpMethods.HttpPost("http://59.227.93.14:8183/rzpt_edc/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 "";
            }
            catch(Exception e)
            {
                LogFactory.GetLogger("token").Error(e.ToJson());
                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 errorObjs
        {
            public string resturl { set; get; }
            public string errorid { set; get; }
            public string errormsg { set; get; }
            public string caseserial { set; get; }
        }

        /// <summary>
        /// 钉钉发送消息
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public ActionResult DingTalkSendMessageText(string mobile, string content)
        {
            content = "【鹤壁监控报警】" + content;
            var userid = DingTalkHelper.GetUserIdByMobile(mobile);
            var userid1 = DingTalkHelper.GetUserIdByMobile("18238806522");
            var userid2 = DingTalkHelper.GetUserIdByMobile("13241334761");
            DingTalkHelper.SendMessageText(userid1, "", content);
            DingTalkHelper.SendMessageText(userid2, "", content);
            return Success(DingTalkHelper.SendMessageText(userid, "", content));
        }
        #endregion
    }
}