using CallCenter.Utility;
using CallCenterApi.BLL;
using CallCenterApi.Common;
using CallCenterApi.DB;
using CallCenterApi.Interface.Controllers.Base;
using CallCenterApi.Interface.Controllers.Sms;
using CallCenterApi.Interface.Models.Common;
using CallCenterApi.Model;
using LumiSoft.Net.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Transactions;
using System.Web;
using System.Web.Mvc;

namespace CallCenterApi.Interface.Controllers.workorder
{
  //[Authority]
    public class AffairsController : BaseController
    {
      


        public ActionResult PushPhone()
        {
            string message = "";
            int Phone = 0; int Phonecount = 0;
            try
            {
                string PushWorkorder = "SELECT top 1  *  FROM T_Bus_PushWorkorder";
               var  BusPushPhone = DbHelperSQL.Query(PushWorkorder).Tables[0];
                if (BusPushPhone != null)
                {
                    Phone = int.Parse(BusPushPhone.Rows[0]["id"].ToString());
                    Phonecount = int.Parse(BusPushPhone.Rows[0]["count"].ToString());
                }
                var modellist = new BLL.T_Bus_WorkOrder
                    ().GetModelList(100000, "ISNULL(F_CallRecordId,'')!='' and F_CreateTime>'2023-11-11 01:00:07.000' " +
                    $" and F_CreateTime < '2024-03-13 17:01:46.000' and F_Id>={Phone} and F_IsDelete =0", " F_Id asc");
                if (modellist!=null && modellist.Count >0)
                {

                    foreach (var it in modellist)
                    {
                        Thread.Sleep(300);
                        Phone = it.F_Id;
                        Phonecount++;
                        WebClient web = new WebClient();
                        web.Encoding = Encoding.UTF8;
                        string Dataurl = web.DownloadString(FrontUrl + "/Affairs/case_record?workorderid=" + it.F_WorkOrderId );
                        if (!string .IsNullOrEmpty (it .F_File ) )
                        {
                            string Dataur2 = web.DownloadString(FrontUrl 
                                + "/Affairs/" + "case_material_info" + "?WorkOrderId=" + it .F_WorkOrderId 
                                + "&file=" + it .F_File + "&id=" + it .F_Id + "&type=" + 10);
                        }
                        string ts = "update T_Bus_PushWorkorder set id='" + Phone + "' ,count='" + Phonecount + "'";
                        var rh = DbHelperSQL.GetSingle(ts);
                    }
                    message = "成功";
                }
            }
            catch(Exception e)
            {
                string ts = "update T_Bus_PushWorkorder set id='" + Phone + "' ,count='" + Phonecount + "'";
                var rh = DbHelperSQL.GetSingle(ts);
                message = e.ToJson();
            }

            return Success(message);
        }



        public ActionResult Pushhandleinfo()
        {
            string message = "";
            int Phone = 0; int Phonecount = 0;
            try
            {
                string PushWorkorder = "SELECT top 1  *  FROM T_Bus_PushWorkorder1";
                var BusPushPhone = DbHelperSQL.Query(PushWorkorder).Tables[0];
                if (BusPushPhone != null)
                {
                    Phone = int.Parse(BusPushPhone.Rows[0]["id"].ToString());
                    Phonecount = int.Parse(BusPushPhone.Rows[0]["count"].ToString());
                }
                var modellist = new BLL.T_Bus_WorkOrder
                    ().GetModelList(100000, "F_WorkOrderId in( " +
                    " select b.case_serial from [dbo].[submit_case_finish_info] a left join [dbo].[submit_case_info] b on a.case_serial = b.case_serial  " +
                    " where a.finish_type = '20' and b.case_isvisit = '1' " +
                    " and b.applicant_time >= '2024-06-01 00:00:00' and b.applicant_time <= '2024-06-30 23:59:59' " +
                    " and a.case_serial not in " +
                    " (select a.case_serial from[dbo].[submit_case_finish_info] a left join[dbo].[submit_case_info] b on a.case_serial = b.case_serial " +
                    " left join(select distinct case_serial from[dbo].[submit_task_handle_info]) c on a.case_serial = c.case_serial " +
                    " left join(select distinct case_serial from[dbo].[submit_case_process_info]) d on a.case_serial = d.case_serial " +
                    " left join(select distinct case_serial from[dbo].[submit_case_visit_info]) e on a.case_serial = e.case_serial " +
                    " left join(select distinct case_serial from[dbo].[submit_case_visit_detail_info]) f on a.case_serial = f.case_serial " +
                    " where a.finish_type = '20' and b.case_isvisit = '1' " +
                    " and b.applicant_time >= '2024-06-01 00:00:00' and b.applicant_time <= '2024-06-30 23:59:59' " +
                    " and  b.case_serial is not null and c.case_serial is not null and " +
                    " d.case_serial is not null and e.case_serial is not null and f.case_serial is not null))", " F_Id asc");
                if (modellist != null && modellist.Count > 0)
                {

                    foreach (var it in modellist)
                    {
                        Thread.Sleep(3000);
                        Phone = it.F_Id;
                        Phonecount++;
                        WebClient web = new WebClient();
                        web.Encoding = Encoding.UTF8;
                        string Dataurl = web.DownloadString(FrontUrl + "/Affairs/handle_info_1?workorderid=" + it.F_WorkOrderId);
                        var model = new BLL.T_Bus_Feedback().GetNewModelByWorkOrderID(it.F_WorkOrderId);
                        if (model!=null )
                        {
                            if (!string.IsNullOrEmpty(model.F_File))
                            {
                                string Dataur2 = web.DownloadString(FrontUrl
                                    + "/Affairs/" + "case_material_info" + "?WorkOrderId=" + it.F_WorkOrderId
                                    + "&file=" + model.F_File + "&id=" + model.F_Id + "&type=" + 20);
                            }
                        }
                       
                        string ts = "update T_Bus_PushWorkorder1 set id='" + Phone + "' ,count='" + Phonecount + "'";
                        var rh = DbHelperSQL.GetSingle(ts);
                    }
                    message = "成功";
                }
            }
            catch (Exception e)
            {
                string ts = "update T_Bus_PushWorkorder1 set id='" + Phone + "' ,count='" + Phonecount + "'";
                var rh = DbHelperSQL.GetSingle(ts);
                message = e.ToJson();
            }

            return Success(message);
        }


        private BLL.T_Sys_Department deptBLL = new BLL.T_Sys_Department();

        #region 上传省政务平台
        #region 服务工单受理

       
        public class paras
        {
            /// <summary>
            /// 行政区划代码
            /// </summary>
            public string AREA_CODE { set; get; }
            /// <summary>
            /// 在线服务代表数
            /// </summary>
            public string CRNT_SEATNUM { set; get; }
            /// <summary>
            /// 通话服务代表数
            /// </summary>
            public string CRNT_TELNUM { set; get; }
            /// <summary>
            /// 今日诉求总量
            /// </summary>
            public int TDY_NUM { set; get; }
            /// <summary>
            /// 今日电话总量
            /// </summary>
            public string TDY_TELNUM { set; get; }
            /// <summary>
            /// 今日政务服务网诉求量
            /// </summary>
            public string TDY_ZWNUM { set; get; }
            /// <summary>
            /// 今日网站诉求量
            /// </summary>
            public string TDY_WZNUM { set; get; }
            /// <summary>
            /// 今日微信诉求量
            /// </summary>
            public string TDY_WXNUM { set; get; }
            /// <summary>
            /// 今日APP诉求量
            /// </summary>
            public string TDY_APNUM { set; get; }
            /// <summary>
            /// 今日其他诉求量
            /// </summary>
            public string TDY_OTNUM { set; get; }
            /// <summary>
            /// 今日电话接通率
            /// </summary>
            public string TDY_TELRATE { set; get; }
            /// <summary>
            /// 今日来电量
            /// </summary>
            public string TDY_CALLNUM { set; get; }
            /// <summary>
            /// 今日接通量
            /// </summary>
            public string TDY_CONNECTNUM { set; get; }
            ///// <summary>
            ///// 今日15秒接通量
            ///// </summary>
            //public string TDY_15_CONNECTNUM { set; get; }
            ///// <summary>
            ///// 今日回拨接通量
            ///// </summary>
            //public string TDY_RETURN_CONNECTNUM { set; get; }
        }





        string AREA_CODE = Configs.GetValue("AREACODE");
        string FrontUrl = Configs.GetValue("FrontUrl");
        string NativeURL = Configs.GetValue("NativeURL");
        string ForeNativeURL = Configs.GetValue("ForeNativeURL");
        
        /// <summary>
        /// 实时服务信息上报接口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult submit_dept_crnt_status()
        {
            
            string token = GetToken();

            paras paras = new paras();
            paras.AREA_CODE = AREA_CODE;
            string ZX = " select top 1  Checkin from rep_service WITH(NOLOCK)  ";
            paras.CRNT_SEATNUM = DbHelperSQL.GetSingle(ZX).ToString();

            string TH = "select top 1  Conversation from rep_service WITH(NOLOCK)  ";
            paras.CRNT_TELNUM = DbHelperSQL.GetSingle(TH).ToString();

          

            string DHCount = "SELECT  COUNT(1)  FROM T_Bus_WorkOrder WITH(NOLOCK) WHERE F_InfoSource = 1 AND datediff(day , F_CreateTime   , getdate())= 0    ";
            paras.TDY_TELNUM = DbHelperSQL.GetSingle(DHCount).ToString();
            paras.TDY_ZWNUM = "0";

            //暂时不知
            string WZCount = "SELECT  COUNT(1)  FROM T_Bus_WorkOrder WITH(NOLOCK) WHERE F_InfoSource in(4,7,2459) AND datediff(day , F_CreateTime   , getdate())= 0    ";
            paras.TDY_WZNUM = DbHelperSQL.GetSingle(WZCount).ToString();

            string WXCount = "SELECT  COUNT(1)  FROM T_Bus_WorkOrder WITH(NOLOCK) WHERE F_InfoSource =5 AND datediff(day , F_CreateTime   , getdate())= 0    ";
            paras.TDY_WXNUM = DbHelperSQL.GetSingle(WXCount).ToString();

            string APPCount = "SELECT  COUNT(1)  FROM T_Bus_WorkOrder WITH(NOLOCK) WHERE F_InfoSource in (2527,2458 )AND datediff(day , F_CreateTime   , getdate())= 0    ";
            paras.TDY_APNUM = DbHelperSQL.GetSingle(APPCount).ToString();

            string WBCount = "SELECT  COUNT(1)  FROM T_Bus_WorkOrder WITH(NOLOCK) WHERE F_InfoSource =3 AND datediff(day , F_CreateTime   , getdate())= 0    ";
            paras.TDY_OTNUM = DbHelperSQL.GetSingle(WBCount).ToString();
            paras.TDY_NUM = int.Parse(paras.TDY_TELNUM) + int.Parse(paras.TDY_WZNUM) + int.Parse(paras.TDY_WXNUM) +
                int.Parse(paras.TDY_APNUM) + int.Parse(paras.TDY_OTNUM);

           
            string jt = "SELECT COUNT(1) FROM T_Call_CallRecords  WITH(NOLOCK)  " +
                  "WHERE datediff(day , BeginTime    , getdate())= 0 AND CallState =1  ";
            var jtl = DbHelperSQL.GetSingle(jt).ToString();
            paras.TDY_CONNECTNUM = jtl;
            string wjt = "SELECT COUNT(1) FROM T_Call_CallRecords  WITH(NOLOCK)  WHERE " +
                "datediff(day , BeginTime    , getdate())= 0" +
                " AND CallState =0  and isnull(UserCode,'')!='' and    DATEDIFF (SECOND ,BeginTime,EndTime)>=20 ";
            var wjt1 = DbHelperSQL.GetSingle(wjt).ToString();

            string TDY_TELRATE = "0";
            try
            {
                paras.TDY_CALLNUM = string.Format("{0}", int.Parse(wjt1) + int.Parse(jtl));
                float total = float.Parse(wjt1) + float.Parse(jtl);

                if (total > 0)
                {

                    TDY_TELRATE = string.Format("{0:f2}", float.Parse(jtl) / total * 100);
                    paras.TDY_TELRATE = TDY_TELRATE;
                }
               
            }
            catch
            {
                paras.TDY_TELRATE = TDY_TELRATE;
            }

            //string CONNECTNUM = "SELECT COUNT(1) FROM T_Call_CallRecords  WITH(NOLOCK)  " +
            //   "  WHERE datediff(day , BeginTime    , getdate())= 0 AND CallState = 1" +
            //   "  and IvrEndTime is not null and RingStartTime is not null" +
            //   "   and DATEDIFF(SECOND , IvrEndTime, RingStartTime)<= 15  ";
            //var CONNECTNUM15 = DbHelperSQL.GetSingle(CONNECTNUM).ToString();
            //paras.TDY_15_CONNECTNUM = CONNECTNUM15;


            //string RETURN = " SELECT count(1) FROM T_Call_CallRecords WITH(NOLOCK) " +
            //    "  WHERE datediff(day , BeginTime    , getdate())= 0 AND CallState = 1 " +
            //    "     and CallbackCallid is not null and CallType = 1  ";
            //var RETURN_CONNECTNUM = DbHelperSQL.GetSingle(RETURN).ToString();
            //paras.TDY_RETURN_CONNECTNUM = RETURN_CONNECTNUM;



            string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
            var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/ssfwxx", jsonParam);
            Push jo = JsonConvert.DeserializeObject<Push>(responseString);

            if (jo.code == "1")
            {

                string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], 
                [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ",
                   "", jsonParam, DateTime.Now, jo.code, jo.message, "实时服务信息上报接口", "", "推送成功数："
                   + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                object objres = DbHelperSQL.GetSingle(strSql);
                string Sql = string.Format(@"INSERT INTO submit_dept_crnt_status ( [AREA_CODE], [CRNT_SEATNUM], [CRNT_TELNUM], 
                [TDY_NUM], [TDY_TELNUM], [TDY_ZWNUM], [TDY_WZNUM], [TDY_WXNUM] , [TDY_APNUM]
                , [TDY_OTNUM], [TDY_TELRATE], [TDY_CALLNUM], [TDY_CONNECTNUM], [CreateTime]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}') ;select @@IDENTITY ",
                  paras.AREA_CODE, paras.CRNT_SEATNUM, paras.CRNT_TELNUM, paras.TDY_NUM, paras.TDY_TELNUM
                  , paras.TDY_ZWNUM, paras.TDY_WZNUM, paras.TDY_WXNUM, paras.TDY_APNUM, paras.TDY_OTNUM,
                  paras.TDY_TELRATE, paras.TDY_CALLNUM, paras.TDY_CONNECTNUM, DateTime.Now);
                object res = DbHelperSQL.GetSingle(Sql);
            

            //string Sql = string.Format(@"INSERT INTO submit_dept_crnt_status ( [AREA_CODE], [CRNT_SEATNUM], [CRNT_TELNUM], 
            //[TDY_NUM], [TDY_TELNUM], [TDY_ZWNUM], [TDY_WZNUM], [TDY_WXNUM] , [TDY_APNUM]
            //, [TDY_OTNUM], [TDY_TELRATE], [TDY_CALLNUM], [TDY_CONNECTNUM], [CreateTime],[TDY_15_CONNECTNUM],[TDY_RETURN_CONNECTNUM]) 
            //   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}') ;select @@IDENTITY ",
            //  paras.AREA_CODE, paras.CRNT_SEATNUM, paras.CRNT_TELNUM, paras.TDY_NUM, paras.TDY_TELNUM
            //  , paras.TDY_ZWNUM, paras.TDY_WZNUM, paras.TDY_WXNUM, paras.TDY_APNUM, paras.TDY_OTNUM,
            //  paras.TDY_TELRATE, paras.TDY_CALLNUM, paras.TDY_CONNECTNUM, DateTime.Now, paras.TDY_15_CONNECTNUM, paras.TDY_RETURN_CONNECTNUM);
            //object res = DbHelperSQL.GetSingle(Sql);
          }
            else
            {
                string error = "";
                if (jo.body.errorObjs != null && jo.body.errorObjs.Length > 0)
                {
                       foreach (var it in jo.body.errorObjs)
                    {
                        if (!string.IsNullOrEmpty(it.resturl))
                        {
                            error += " 推送接口名称:" + it.resturl;
                        }
                        if (!string.IsNullOrEmpty(it.caseserial))
                        {
                            error += " 推送工单号:" + it.caseserial;
                        }
                        if (!string.IsNullOrEmpty(it.resturl))
                        {
                            error += " 推送标识:" + it.errorid;
                        }
                        if (!string.IsNullOrEmpty(it.resturl))
                        {
                            error += " 推送失败原因:" + it.errormsg;
                        }
                    }
                }
                string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], 
[CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "",
                   paras.ToJson(), DateTime.Now, jo.code, jo.message, "实时服务信息上报接口", error, "推送成功数："
                   + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                object objres = DbHelperSQL.GetSingle(strSql);

            }
            var obj = new
            {
                responseString,
                jsonParam
            };
            return Content (obj.ToJson ());

        }


    

        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; }//""
        }
        /// <summary>
        /// </summary>
        /// 服务工单受理
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult case_info(string workorderid)
        {
            string token = GetToken();
            if (string.IsNullOrEmpty(token))
                return Error("token 错误");
            Model.T_Bus_WorkOrder model = new BLL.T_Bus_WorkOrder().GetModel(workorderid);
            if (model != null)
            {
                submit_case_info paras = new submit_case_info();
                paras.jsonList = new List<jsonList>();
                jsonList jsonList = new jsonList();
                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.CASE_ID = model.F_Id.ToString();
                if (string.IsNullOrEmpty(model.F_CusName))
                    jsonList.APPLICANT_NAME = "匿名";
                else
                    jsonList.APPLICANT_NAME = model.F_CusName;
                if (model.F_CusSex == "0")
                    jsonList.APPLICANT_SEX = "1";
                else if (model.F_CusSex == "1")
                    jsonList.APPLICANT_SEX = "2";
                else
                    jsonList.APPLICANT_SEX = "3";

                jsonList.APPLICANT_AGE = "8";//没有
                jsonList.APPLICANT_NUMBER = model.F_CusPhone;
                jsonList.APPLICANT_TIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");//没有
                if (DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')") != null)
                    jsonList.HWY_NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')").ToString();
                else
                    jsonList.HWY_NAME = model.F_CreateUser;
                jsonList.HWY_LOGINID = model.F_CreateUser;
                jsonList.CASE_TIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                jsonList.CASE_TITLE = model.F_ComTitle;
                jsonList.CASE_CONTENT = model.F_ComContent;
                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";//其他
                if (DbHelperSQL.GetSingle(" select dbo.GetDicRemark('" + model.F_Key + "')") != null)
                    jsonList.CASE_ACCORD = DbHelperSQL.GetSingle(" select dbo.GetDicRemark('" + model.F_Key + "')").ToString();
                else
                    jsonList.CASE_ACCORD = "";
                jsonList.CASE_ISPUBLIC = model.F_IsProtect.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 jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/fwgdsl", jsonParam);
                try
                {
                    Push jo = JsonConvert.DeserializeObject<Push>(responseString);

                    if (jo.code == "1")
                    {

                        string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", workorderid, "", DateTime.Now, jo.code, jo.message, "服务工单受理", "", "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                        object objres = DbHelperSQL.GetSingle(strSql);

                        string Mapping = string.Format(@"INSERT INTO T_Bus_Mapping ( [F_OldWorkOrder], [F_NewWorkOrder], [F_CreateTime], [F_Type]) 
                   values   ('{0}','{1}','{2}','{3}') ;select @@IDENTITY ", workorderid, newwokrkorder, DateTime.Now, 1);
                        object Mappings = DbHelperSQL.GetSingle(Mapping);
                        return Success("推送成功");
                    }
                    else
                    {
                        string error = "";
                        if (jo.body.errorObjs != null && jo.body.errorObjs.Length > 0)
                        {
                            foreach (var it in jo.body.errorObjs)
                            {
                                if (!string.IsNullOrEmpty(it.resturl))
                                {
                                    error += " 推送接口名称:" + it.resturl;
                                }
                                if (!string.IsNullOrEmpty(it.caseserial))
                                {
                                    error += " 推送工单号:" + it.caseserial;
                                }
                                if (!string.IsNullOrEmpty(it.resturl))
                                {
                                    error += " 推送标识:" + it.errorid;
                                }
                                if (!string.IsNullOrEmpty(it.resturl))
                                {
                                    error += " 推送失败原因:" + it.errormsg;
                                }
                            }
                        }
                        string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", paras.ToJson(), DateTime.Now, jo.code, jo.message, "服务工单受理", error, "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                        object objres = DbHelperSQL.GetSingle(strSql);
                        LogFactory.GetLogger("111").Warn("服务工单受理" + error);
                        return Error("推送失败---" + error);

                    }
                }
                catch(Exception e)
                {
                    return Error(e.Message + responseString);
                }
              

            }
            else
            {
                return Error("推送失败工单不存在");
            }

        }
        #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; }

        }
        /// <summary>
        /// 一级部门处办记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult handle_info_1(string workorderid)
        {

            var workorder = new BLL.T_Bus_WorkOrder().GetModel(workorderid);
            var model = new BLL.T_Bus_Feedback().GetNewModelByWorkOrderID(workorderid);
            var info = new BLL.T_Bus_AssignedInfo().GetNewModelByWorkOrderID(workorderid);
            if (workorder != null)
            {
                string token = GetToken();
                if (string.IsNullOrEmpty(token))
                    return Error("token 错误");
                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.CASE_ID = workorder.F_Id.ToString();
                jsonList.AREA_CODE = AREA_CODE;
                jsonList.TASK_ID = model.F_Id.ToString();
                jsonList.TASK_PARENTID = "TOP";
           
                jsonList.TASK_OUNAME = deptBLL.GetDeptNames(model.F_CreateDeptId.ToString());
                
                string username = userBLL.GetUserName(model.F_CreateUser);
                jsonList.TASK_USERNAME = string.IsNullOrEmpty(username)? model.F_CreateUser: username;

                if (string.IsNullOrEmpty(model.F_Result))
                    jsonList.TASK_CONTENT = "无";
                else
                    jsonList.TASK_CONTENT = model.F_Result;
                jsonList.TASK_ASSIGNTIME = info.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                jsonList.TASK_SIGNTIME = info.F_SureTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                jsonList.TASK_FINISHTIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                jsonList.TASK_FINISHTIME_BF = info.F_LimitTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                if (info.F_State == 2)
                {
                    jsonList.TASK_ISBACK = "1";
                }
                else
                {
                    jsonList.TASK_ISBACK = "0";
                }
                if (info.F_IsNext > 0)
                {
                    jsonList.TASK_ISALLOT = "1";
                }
                else
                {
                    jsonList.TASK_ISALLOT = "0";
                }
                jsonList.TASK_HANDLE_LENGTH = int.Parse(DbHelperSQL.GetSingle(" SELECT DATEDIFF(SECOND,'" + jsonList.TASK_ASSIGNTIME + "', '" + jsonList.TASK_FINISHTIME + "')").ToString());
                paras.jsonList.Add(jsonList);
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/bmcbjl", jsonParam);
                Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                if (jo.code == "1")
                {

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

        }


        /// <summary>
        /// 二级部门处办记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult handle_info_2(string workorderid)
        {
            string token = GetToken();
            if (string.IsNullOrEmpty(token))
                return Error("token 错误");
            var workorder = new BLL.T_Bus_WorkOrder().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)
            {
                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();
            
                jsonList.TASK_OUNAME = deptBLL.GetDeptNames(model.F_CreateDeptId.ToString());
               
                string username = userBLL.GetUserName(model.F_CreateUser);
                jsonList.TASK_USERNAME = string.IsNullOrEmpty(username) ? model.F_CreateUser : username;

                jsonList.TASK_CONTENT = model.F_Result;
                jsonList.TASK_ASSIGNTIME = info.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                jsonList.TASK_SIGNTIME = info.F_SureTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                jsonList.TASK_FINISHTIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                jsonList.TASK_FINISHTIME_BF = info.F_LimitTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                if (info.F_State == 2)
                {
                    jsonList.TASK_ISBACK = "1";
                }
                else
                {
                    jsonList.TASK_ISBACK = "0";
                }
                jsonList.TASK_ISALLOT = "1";
                jsonList.TASK_HANDLE_LENGTH = int.Parse(DbHelperSQL.GetSingle(" SELECT DATEDIFF(SECOND,'" + jsonList.TASK_ASSIGNTIME + "', '" + jsonList.TASK_FINISHTIME + "')").ToString());
                paras.jsonList.Add(jsonList);
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/bmcbjl", jsonParam);
                Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                if (jo.code == "1")
                {

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

            }
            return Error("工单不存在");
        }
        #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; }
        }


        /// <summary>
        /// 工单最终评价
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult case_visit_info(string workorderid)
        {

            var model = new BLL.T_Bus_VisitResult().GetNewModelByWorkOrderID(workorderid);
            var workorder = new BLL.T_Bus_WorkOrder().GetModel(workorderid);
            if (workorder != null && model != null)
            {
                string token = GetToken();
                if (string.IsNullOrEmpty(token))
                    return Error("token 错误");
                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";
                jsonList.VISIT_TIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                if (DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')") != null)
                    jsonList.VISIT_NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')").ToString();
                else
                    jsonList.VISIT_NAME = model.F_CreateUser;
                if (string.IsNullOrEmpty(model.F_Result))
                    jsonList.VISIT_CONTENT = "无";
                else
                    jsonList.VISIT_CONTENT = model.F_Result;
                if (model.F_IsSatisfie ==-1)
                    jsonList.VISIT_SATISFY = "1";
                else if (model.F_IsSatisfie == 0)
                    jsonList.VISIT_SATISFY = "2";
                else if (model.F_IsSatisfie == 1)
                    jsonList.VISIT_SATISFY = "4";
                else if (model.F_IsSatisfie == 2)
                    jsonList.VISIT_SATISFY = "3";
                else if (model.F_IsSatisfie == 3)
                    jsonList.VISIT_SATISFY = "4";
               

                jsonList.VISIT_NUMBER = int.Parse(DbHelperSQL.GetSingle(" select count(1) from T_Bus_VisitResult  where F_WorkOrderId ='" + model.F_WorkOrderId + "'").ToString());
                paras.jsonList.Add(jsonList);
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/gdzzpj", jsonParam);
                Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                if (jo.code == "1")
                {

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

            }
            else
                return Error("工单不存在或工单未评价");

        }
        #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>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult case_finish_info(string workorderid)
        {

            var model = new BLL.T_Bus_WorkOrder().GetModel(workorderid);
            if (model != null)
            {
                string token = GetToken();
                if (string.IsNullOrEmpty(token))
                    return Error("token 错误");

                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 = "热线中心";
                    jsonList.END_TIME = model.F_CloseTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                    jsonList.DEPT_CODE = "4106000299";
                }
                else
                {
                    jsonList.FINISH_TYPE = "20";
                    if (model.F_MainDeptId > 0)
                    {
                        jsonList.END_TIME = model.F_DealTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                        //if (DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + model.F_MainDeptId + "')") != null)
                        //    jsonList.DEPT_NAME = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + model.F_MainDeptId + "')").ToString();
                        jsonList.DEPT_NAME = deptBLL.GetDeptNames(model.F_MainDeptId.ToString());
                        //if (DbHelperSQL.GetSingle(" select F_DeptNameSpell  from T_Sys_Department where F_DeptId= '" + model.F_MainDeptId + "'") != null)
                        //    jsonList.DEPT_CODE = DbHelperSQL.GetSingle(" select F_DeptNameSpell  from T_Sys_Department where F_DeptId= '" + model.F_MainDeptId + "'").ToString();
                        jsonList.DEPT_CODE = deptBLL.GetModelList("F_DeptId= '" + model.F_MainDeptId + "'").FirstOrDefault()?.F_DeptNameSpell ?? "";


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

                }


                jsonList.FINISH_TIME = model.F_CloseTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                if (DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_DealUser + "')") != null)
                    jsonList.FINISH_NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_DealUser + "')").ToString();
                else
                    jsonList.FINISH_NAME = model.F_DealUser;
                if (string.IsNullOrEmpty(jsonList.FINISH_NAME))
                    jsonList.FINISH_NAME = "热线中心";
                jsonList.FINISH_CONTENT = model.F_Result;
                jsonList.END_LENGTH = int.Parse(DbHelperSQL.GetSingle(" SELECT DATEDIFF(SECOND,'" + model.F_CreateTime + "', '" + model.F_DealTime + "')").ToString());
                paras.jsonList.Add(jsonList);
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/fwgdbj", jsonParam);
               
                try
                {
                    Push jo = JsonConvert.DeserializeObject<Push>(responseString);

                    if (jo.code == "1")
                    {

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

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

        }
        #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)
        {
            var model = new BLL.T_Bus_Operation().GetModel(id);
            if (model != null)
            {
                var workordr = new BLL.T_Bus_WorkOrder().GetModel(model.F_WorkOrderId);
                if (workordr != null)
                {
                    string token = GetToken();
                    if (string.IsNullOrEmpty(token))
                        return Error("token 错误");

                    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();
                    jsonList.DEPT_NAME = model.F_Message.Split('(')[0];
                    jsonList.TACHE_NAME = title;
                    jsonList.PROCESS_TIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                    if (DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')") != null)
                        jsonList.PROCESS_NAME = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CreateUser + "')").ToString();
                    else
                        jsonList.PROCESS_NAME = model.F_CreateUser;
                    jsonList.PROCESS_NOTE = model.F_Message;
                    paras.jsonList.Add(jsonList);


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

            }
            else
                return Error("推送失败流程不存在");

        }
        #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)
        {
            var model = new BLL.T_Bus_VisitResult().GetNewModelByWorkOrderID(workorderid);

            if (model != null)
            {

                string token = GetToken();
                if (string.IsNullOrEmpty(token))
                    return Error("token 错误");
                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);
                jsonList.CASE_SERIAL = newwokrkorder;
                jsonList.AREA_CODE = AREA_CODE;
                jsonList.VISIT_ID = model.F_Id.ToString();

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

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

            }
            else
                return Error("工单未回访");

        }
        #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, int id, string type)
        {
            string ParamValue = "";
            var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
            if (configfj != null)
            {
                ParamValue = configfj.F_ParamValue;
            }
            else
            {
                return Error("附件路径不存在");             }
            string token = GetToken();
            if (string.IsNullOrEmpty(token))
                return Error("token 错误");
            string newwokrkorder = WorkOrderId;
            if (WorkOrderId.Contains("QT"))
                newwokrkorder = "WZ" + WorkOrderId.Substring(2, WorkOrderId.Length - 2);

            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 (Accessories != null && Accessories.Count > 0)
            {
                foreach (var it in Accessories)
                {
                   
                    jsonList.CASE_SERIAL = newwokrkorder;
                    jsonList.AREA_CODE = AREA_CODE;
                    jsonList.MATERIAL_ID = it.F_FileId.ToString();
                    jsonList.MATERIAL_NAME = it.F_FileName;
                    jsonList.MATERIAL_FILE_TYPE = it.F_FileType;
                    jsonList.MATERIAL_TYPE = type;
                    jsonList.MATERIAL_CONTACTID = id.ToString();
                    jsonList.MATERAIL_URL = ParamValue + it.F_FileUrl;
                    paras.jsonList.Add(jsonList);
                }
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/fwgdcl", jsonParam);
                Push jo = JsonConvert.DeserializeObject<Push>(responseString);
                if (jo.code == "1")
                {

                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", paras.ToJson(), DateTime.Now, jo.code, jo.message, "服务工单材料", "", "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                    object objres = DbHelperSQL.GetSingle(strSql);
                    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;
                            }
                        }
                    }
                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", paras.ToJson(), DateTime.Now, jo.code, jo.message, "服务工单材料", error, "推送成功数：" + jo.body.successCount + " 推送总数：" + jo.body.totalCount);
                    object objres = DbHelperSQL.GetSingle(strSql);
                    return Error("推送失败--" + error);
                }
            }
            else
            {
                return Error("附件不存在");
            }


        }

        #endregion
        #region 获取附件

        public class receive
        {
            public string ATTATH_STEP_ID { set; get; }
        }
        public class receive_material_infos
        {
            public string code { set; get; }
            public string message { set; get; }
            public List<bodys> body { set; get; }
        }
        public class bodys
        {
            public string ATTATH_TYPE { set; get; }
            public string ATTATH_NAME { set; get; }
            public string ATTATH_CONTENT { set; get; }
        }
        /// <summary>
        /// 获取附件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private string receive_info(string ids)
        {
            string token = GetToken();
            if (string.IsNullOrEmpty(token))
                return "";
            receive paras = new receive();
            paras.ATTATH_STEP_ID = ids;
            //  values.Add("paras", paras);
            string fileid = "";

            //序列化参数
            string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
            var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/fjcljk", jsonParam);
            receive_material_infos jo = JsonConvert.DeserializeObject<receive_material_infos>(responseString);
            if (jo.code == "1")
            {
                if (jo.body != null && jo.body.Count > 0)
                {
                    List<Model.T_Sys_Accessories> acs = new List<Model.T_Sys_Accessories>();
                    string path = "/Upload/ZhenWu/" + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd") + "/";
                    foreach (var it in jo.body)
                    {
                      //  byte[] data = Encoding.UTF8.GetBytes(it.ATTATH_CONTENT);
                        FileUp fu = new FileUp();
                        fu.ByteSaveFile(it.ATTATH_CONTENT, path, it.ATTATH_NAME);
                        Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
                        model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
                        model_T_Sys_Accessories.F_FileName = it.ATTATH_NAME;//附件名称
                        model_T_Sys_Accessories.F_FileType = System.IO.Path.GetExtension(it.ATTATH_TYPE);//附件类型
                        model_T_Sys_Accessories.F_FileUrl = path + it.ATTATH_NAME;//附件地址
                                                                                  //model_T_Sys_Accessories.F_Size = file.ContentLength;
                        model_T_Sys_Accessories.F_UserCode = "省12345平台";//上传人  
                        int id = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
                        model_T_Sys_Accessories.F_FileId = id;
                        if (string.IsNullOrEmpty(fileid))
                            fileid = id.ToString();
                        else
                            fileid += "," + id.ToString();
                        acs.Add(model_T_Sys_Accessories);
                    }

                }

            }
            else
            {
                string error = "";
                error += " 获取附件失败:" + jo.message;
                string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", paras.ToJson(), DateTime.Now, jo.code, jo.message, "获取附件失败", error, "");
                object objres = DbHelperSQL.GetSingle(strSql);

            }
            WebClient web = new WebClient();
            web.Encoding = Encoding.UTF8;
            string Dataurl = web.DownloadString(NativeURL  + "Affairs/SetFileData" + "?ids=" + fileid);
            return fileid;

        }

        public ActionResult SetFileData(string ids)
        {
            DataTable dt = DbHelperSQL.Query("select * from T_Sys_Accessories WITH(NOLOCK) where F_FileId in (" + ids + ")").Tables[0];

            foreach (DataRow dr in dt.Rows)
            {
                string url = Upload(FrontUrl  + dr["F_FileUrl"].ToString(), dr["F_FileName"].ToString(), "/" + dr["F_FileUrl"].ToString().Replace(dr["F_FileName"].ToString(), ""));
                if (url == "1")
                    dr["F_FileUrl"] = NativeURL + dr["F_FileUrl"].ToString();
                else
                    dr["F_FileUrl"] = url;
            }
            return Success("添加成功");
        }
        #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)
        {
            var workorder = new BLL.T_Bus_WorkOrder().GetModel(WorkOrderId);

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

            if (model != null)
            {
                string token = GetToken();
                if (string.IsNullOrEmpty(token))
                    return Error("获取token失败");
                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";
                jsonList.RECORD_STARTTIME = model.TalkStartTime
                    .Value.ToString("yyyy-MM-dd HH:mm:ss");
                if (model.TalkEndTime != null)
                    jsonList.RECORD_ENDTIME = model.TalkEndTime
                    .Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    jsonList.RECORD_ENDTIME = "";
                jsonList.RECORD_LENGTH = model.TalkLongTime;
                jsonList.RECORD_LOGINID = model.UserCode;
                var config = new 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);
                //Dictionary<string, object> values = new Dictionary<string, object>();
                //values.Add("access_token", token);
                //values.Add("paras", paras);
                ////序列化参数
                //var jsonParam = JsonConvert.SerializeObject(values);


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

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

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

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

        }
        #endregion
        #endregion
       
        private BLL.T_Bus_WorkOrder workorderBLL = new BLL.T_Bus_WorkOrder();
        private BLL.T_Bus_Operation operBLL = new BLL.T_Bus_Operation();
        private BLL.T_Sys_UserAccount userBLL = new BLL.T_Sys_UserAccount();
        private information.InternalMessagesController msg = new information.InternalMessagesController();
        private BLL.T_Cus_CustomerBase cusBLL = new BLL.T_Cus_CustomerBase();
        private BLL.T_Bus_AssignedInfo assignBLL = new BLL.T_Bus_AssignedInfo();
        private BLL.T_Sys_Affairs affairsBll = new BLL.T_Sys_Affairs();

        public class receive_case_sign
        {
            public string TROWGUID { set; get; }
            public string SIGN_NAME { set; get; }
        }
        public ActionResult case_sign(string workorderid)
        {
            Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
            if (modelT_Bus_WorkOrder != null)
            {
                var affairs = affairsBll.GetModel(modelT_Bus_WorkOrder.F_WorkOrderId);
                receive_case_sign paras = new receive_case_sign();
                paras.TROWGUID = affairs.TROWGUID;
                paras.SIGN_NAME = "审核员";
                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                try
                {
                    string jsonParam = "paras=" + paras.ToJson() + "&message=签收工单&url=http://59.227.93.14:9000/share/fwgdqsjk&WorkOrderId=" + modelT_Bus_WorkOrder.F_WorkOrderId;
                    var responseString = HttpMethods.HttpPost(FrontUrl + "/Affairs/receive_Push", jsonParam);
                    bendiack jo = JsonConvert.DeserializeObject<bendiack>(responseString);
                    if (jo.state != "success")
                    {
                        if (!jo.message.Contains("该任务单已签收"))
                        {
                            keyValuePairs.Add("F_Administrative", "2");
                            LogFactory.GetLogger("签收").Error(jo.message);
                            return Error("签收失败");
                        }
                        else
                        {
                            keyValuePairs.Add("F_Administrative", "0");
                        } 

                    }

                }
                catch (Exception e)
                {
                    keyValuePairs.Add("F_Administrative", "2");
                    LogFactory.GetLogger("签收").Error(e.Message);
                }
                bool n = workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs);
                return Success("");
            }
            else
                return Error("");
        }
        /// <summary>
        /// 提交签收工单
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [Authority]
        public ActionResult SubmitWorkOrder(string[] ids)
        {
            if (User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "ZXBZ" || User.F_RoleCode == "SPZJZ" || User.F_RoleCode == "GLY" || User.F_RoleCode == "ZXLD"||User.F_RoleCode == "SPZJZ" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD" || User.F_RoleCode == "DMTSH")
            {
                if (ids != null && ids.Length > 0)
                {
                    foreach (string str in ids)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(str);
                            if (modelT_Bus_WorkOrder != null)
                            {

                                var affairs = affairsBll.GetModel(modelT_Bus_WorkOrder.F_WorkOrderId);
                                receive_case_sign paras = new receive_case_sign();
                                paras.TROWGUID = affairs.TROWGUID;
                                paras.SIGN_NAME = User.F_UserName;
                                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                                try
                                {


                                    string jsonParam = "paras=" + paras.ToJson() + "&message=签收工单&url=http://59.227.93.14:9000/share/fwgdqsjk&WorkOrderId=" + modelT_Bus_WorkOrder.F_WorkOrderId;
                                    var responseString = HttpMethods.HttpPost(FrontUrl +"/Affairs/receive_Push", jsonParam);
                                    bendiack jo = JsonConvert.DeserializeObject<bendiack>(responseString);
                                    if (jo.state != "success")
                                    {
                                        if (!jo.message.Contains("该任务单已签收"))
                                        {
                                            keyValuePairs.Add("F_Administrative", "2");
                                            LogFactory.GetLogger("签收").Error(jo.message);
                                            return Error("签收失败");
                                        }
                                       
                                    }

                                }
                                catch(Exception e)
                                {
                                    LogFactory.GetLogger("签收").Error(e.Message );
                                     return Error("签收失败");
                                }




                                if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.neworder || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.audit)
                                {
                                 
                                    #region 保存工单信息
                                    keyValuePairs.Add("F_SubmitTime", DateTime.Now);
                                    //  modelT_Bus_WorkOrder.F_SubmitTime = DateTime.Now;
                                    keyValuePairs.Add("F_WorkState", 1);
                                    modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.submit;//待交办

                                    bool n = workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs);
                                    #endregion


                                    #region 插入操作记录
                                    Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                                    oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                    oper.F_State = 1;

                                    string userinfo = User.depname + "(" + User.F_UserCode + ")";
                                    oper.F_Message = userinfo + " 提交并签收了工单";
                                    oper.F_CreateUser = User.F_UserCode;
                                    oper.F_CreateTime = DateTime.Now;
                                    oper.F_IsDelete = 0;

                                    operBLL.Add(oper);

                                   
                                    #endregion
                                }

                            }
                            trans.Complete();
                        }
                    }
                    return Success("操作成功");
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }

        public class signgoback
        {
            public string code { set; get; }
            public string message { set; get; }
            public signbody body { set; get; }
        }
        public class signbody
        {
            public string TFDBACKTIME_BF { set; get; }
        }
        public ActionResult case_sign1(string workorderid)
        {
            Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
            if (modelT_Bus_WorkOrder != null)
            {
                var affairs = affairsBll.GetModel(modelT_Bus_WorkOrder.F_WorkOrderId);
                receive_case_sign paras = new receive_case_sign();
                paras.TROWGUID = affairs.TROWGUID;
                paras.SIGN_NAME = "审核员";
                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                try
                {
                    string jsonParam = "", responseString = "";
                    string token = GetToken();
                    if (string.IsNullOrEmpty(token))
                        return Error("token获取失败");
                    jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                    responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/fwgdqsjk", jsonParam);

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

                        string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", modelT_Bus_WorkOrder.F_WorkOrderId, paras, DateTime.Now, jo.code, jo.message, "签收工单", "", "");
                        object objres = DbHelperSQL.GetSingle(strSql);
                        if (jo.body != null)
                        {
                            affairs.TFDBACKTIME_BF = jo.body.TFDBACKTIME_BF;
                            affairsBll.Update(affairs);
                        }
                        keyValuePairs.Add("F_Administrative", "0");
                        return Success("成功");
                    }
                    else
                    {
                        if (!jo.message.Contains("该任务单已签收"))
                        {
                            keyValuePairs.Add("F_Administrative", "2");
                            LogFactory.GetLogger("签收").Error(jo.message);
                            return Error("签收失败");
                        }
                        else
                        {
                            keyValuePairs.Add("F_Administrative", "0");
                        }
                        string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", modelT_Bus_WorkOrder.F_WorkOrderId, paras, DateTime.Now, jo.code, jo.message, "签收工单", jo.message, "");
                        object objres = DbHelperSQL.GetSingle(strSql);
                        return Error(jo.message);
                    }


                }
                catch (Exception e)
                {
                    keyValuePairs.Add("F_Administrative", "2");
                    LogFactory.GetLogger("签收").Error(e.Message);
                }
                bool n = workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs);
                return Success("");
            }
            else
                return Error("");
        }
        /// <summary>
        /// 提交签收工单
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [Authority]
        public ActionResult SubmitWorkOrder1(string[] ids)
        {
            if (User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "ZXBZ" || User.F_RoleCode == "SPZJZ" || User.F_RoleCode == "GLY" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "SPZJZ" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD" || User.F_RoleCode == "DMTSH")
            {
                if (ids != null && ids.Length > 0)
                {
                    foreach (string str in ids)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(str);
                            if (modelT_Bus_WorkOrder != null)
                            {

                                var affairs = affairsBll.GetModel(modelT_Bus_WorkOrder.F_WorkOrderId);
                                receive_case_sign paras = new receive_case_sign();
                                paras.TROWGUID = affairs.TROWGUID;
                                paras.SIGN_NAME = User.F_UserName;
                                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                                try
                                {





                                    string jsonParam = "", responseString = "";
                                    string token = GetToken();
                                    if (string.IsNullOrEmpty(token))
                                        return Error("token获取失败");
                                    jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                                    responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/fwgdqsjk", jsonParam);

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

                                        string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", modelT_Bus_WorkOrder.F_WorkOrderId, paras, DateTime.Now, jo.code, jo.message, "签收工单", "", "");
                                        object objres = DbHelperSQL.GetSingle(strSql);
                                        if (jo.body != null)
                                        {
                                            affairs.TFDBACKTIME_BF = jo.body.TFDBACKTIME_BF;
                                            affairsBll.Update(affairs);
                                        }
                                        return Success("成功");
                                    }
                                    else
                                    {
                                        if (!jo.message.Contains("该任务单已签收"))
                                        {
                                            keyValuePairs.Add("F_Administrative", "2");
                                            LogFactory.GetLogger("签收").Error(jo.message);
                                            return Error("签收失败");
                                        }
                                        string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", modelT_Bus_WorkOrder.F_WorkOrderId, paras, DateTime.Now, jo.code, jo.message, "签收工单", jo.message, "");
                                        object objres = DbHelperSQL.GetSingle(strSql);
                                        return Error(jo.message);
                                    }
                                }
                                catch (Exception e)
                                {
                                    LogFactory.GetLogger("签收").Error(e.Message);
                                    return Error("签收失败");
                                }




                                if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.neworder || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.audit)
                                {

                                    #region 保存工单信息
                                    keyValuePairs.Add("F_SubmitTime", DateTime.Now);
                                    //  modelT_Bus_WorkOrder.F_SubmitTime = DateTime.Now;
                                    keyValuePairs.Add("F_WorkState", 1);
                                    modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.submit;//待交办

                                    bool n = workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs);
                                    #endregion


                                    #region 插入操作记录
                                    Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                                    oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                    oper.F_State = 1;

                                    string userinfo = User.depname + "(" + User.F_UserCode + ")";
                                    oper.F_Message = userinfo + " 提交并签收了工单";
                                    oper.F_CreateUser = User.F_UserCode;
                                    oper.F_CreateTime = DateTime.Now;
                                    oper.F_IsDelete = 0;

                                    operBLL.Add(oper);


                                    #endregion
                                }

                            }
                            trans.Complete();
                        }
                    }
                    return Success("操作成功");
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }










        public class bendiack
        {
            public string state;
            public string message;
        }

        public ActionResult receive_Push(string paras, string url, string message, string WorkOrderId = "")
        {
            string jsonParam = "", responseString = "";
            string token = GetToken();
            if (string.IsNullOrEmpty(token))
                return Error("token获取失败");
            // string jsonParam = "paras=" + paras;
            jsonParam = "access_token=" + token + "&paras=" + paras;
            try
            {

                responseString = HttpMethods.HttpPost(url, jsonParam);
                if (message == "签收工单")
                {
                    signgoback jo = JsonConvert.DeserializeObject<signgoback>(responseString);
                    if (jo.code == "1")
                    {
                        if (!string.IsNullOrEmpty(WorkOrderId))
                        {
                            var affairs = affairsBll.GetModel(WorkOrderId);
                            if (affairs != null)
                            {
                                if (jo.body != null)
                                {
                                    affairs.TFDBACKTIME_BF = jo.body.TFDBACKTIME_BF;
                                    affairsBll.Update(affairs);
                                }
                            }
                        }


                        string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", WorkOrderId, paras, DateTime.Now, jo.code, jo.message, message, "", "");
                        object objres = DbHelperSQL.GetSingle(strSql);
                        return Success("成功");
                    }
                    else
                    {
                        string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", WorkOrderId, paras, DateTime.Now, jo.code, jo.message, message, jo.message, "");
                        object objres = DbHelperSQL.GetSingle(strSql);
                        return Error(jo.message);
                    }
                }
                else
                {
                    goback jo = JsonConvert.DeserializeObject<goback>(responseString);
                    if (jo.code == "1")
                    {

                        string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", WorkOrderId, paras, DateTime.Now, jo.code, jo.message, message, "", "");
                        object objres = DbHelperSQL.GetSingle(strSql);
                        return Success("成功");
                    }
                    else
                    {
                        string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", WorkOrderId, paras, DateTime.Now, jo.code, jo.message, message, jo.message, "");
                        object objres = DbHelperSQL.GetSingle(strSql);
                        return Error(jo.message);
                    }

                }
                  
            }
            catch (Exception e)
            {
                LogFactory.GetLogger("123").Error(e.Message);
                return Error(responseString);
            }
        }
        public class receive_case_back
        {
            public string TROWGUID { set; get; }
            public string BACK_NAME { set; get; }
            public string BACK_TYPE { set; get; }
            public string BACK_REASON { set; get; }
            public string BACK_ATTATH_ID { set; get; }
        }
        /// <summary>
        /// 退回工单
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult RebackWorkOrder()
        {

            if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "SPZJZ" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                string backreason = RequestString.GetFormString("backreason");
                string BACK_TYPE = RequestString.GetFormString("type");
                string file = RequestString.GetFormString("file");
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);

                if (modelT_Bus_WorkOrder != null)
                {
                    using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                    {
                        #region 保存工单信息
                        //modelT_Bus_WorkOrder.F_WorkState = 3;//退回审核中
                        Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                        keyValuePairs.Add("F_WorkState", "9");
                        keyValuePairs.Add("F_DealDeptId", User.F_DeptId);
                        keyValuePairs.Add("F_DealUser", User.F_UserCode);
                        keyValuePairs.Add("F_DealTime", DateTime.Now);
                        keyValuePairs.Add("F_IsClosed", 1);
                        keyValuePairs.Add("F_CloseUser", User.F_UserCode);
                        keyValuePairs.Add("F_Result", backreason);
                        keyValuePairs.Add("F_CloseTime", DateTime.Now);
                        workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs);
                        #endregion
                        receive_case_back paras = new receive_case_back();
                        var affairs = affairsBll.GetModel(modelT_Bus_WorkOrder.F_WorkOrderId);
                        paras.TROWGUID = affairs.TROWGUID;
                        paras.BACK_NAME = User.F_UserName;
                        paras.BACK_TYPE = BACK_TYPE;
                        paras.BACK_REASON = backreason;
                        paras.BACK_ATTATH_ID = file;

                        try
                        {
                            string jsonParam = "paras=" + paras.ToJson() + "&message=退回工单&url=http://59.227.93.14:9000/share/fwgdthjk&WorkOrderId=" + modelT_Bus_WorkOrder.F_WorkOrderId;
                            var responseString = HttpMethods.HttpPost(FrontUrl +"/Affairs/receive_Push", jsonParam);
                            bendiack jo = JsonConvert.DeserializeObject<bendiack>(responseString);
                            if (jo.state != "success")
                                return Error("退回失败");

                        }
                        catch (Exception e)
                        {
                            return Error(e.ToString());
                        }
                        Model.T_Bus_Operation oper1 = new Model.T_Bus_Operation();
                        oper1.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                        oper1.F_State = modelT_Bus_WorkOrder.F_WorkState;
                        string userinfo = User.F_UserName + "(" + User.F_UserCode + ")";
                        oper1.F_Message = userinfo + " 退回了省平台工单";
                        oper1.F_CreateUser = User.F_UserCode;
                        oper1.F_CreateTime = DateTime.Now;
                        oper1.F_IsDelete = 0;
                        operBLL.Add(oper1);
                        trans.Complete();
                        return Success("操作成功");
                    }


                }
                else
                {
                    return Error("退回失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }

        public class receive_case_finish
        {
            public string TROWGUID { set; get; }
            public string FINISH_NAME { set; get; }
            public string FINISH_RESULT { set; get; }
            public string FINISH_ATTATH_ID { set; get; }
            /// <summary>
            /// 答复群众结果
            /// </summary>
           // public string FINISH_RESULT_QZ { set; get; }
        }
        /// <summary>
        /// 反馈结案工单
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult ForceFinishWorkOrder()
        {

            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "SPZJZ" || User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD" || User.F_RoleCode == "DMTSH" || User.F_RoleCode == "DBZY")
            {

                string workorderid = RequestString.GetFormString("workorderid");
                string result = RequestString.GetFormString("result");//处理结果
                string finalopinion = RequestString.GetFormString("finalopinion");//结案意见
                int issatisfie = RequestString.GetInt("issatisfie", 1);//0不满意 1满意
                int isnotice = RequestString.GetInt("isnotice", 0);//0不通告 1通告
                int issms = RequestString.GetInt("issms", 0);
                string deptids = RequestString.GetFormString("deptids");//通告单位
                string noticereson = RequestString.GetFormString("noticereson");//通告其他原因
                int noticeid = RequestString.GetInt("noticeid", 0);//通告选项id
                string noticeinfo = RequestString.GetFormString("noticeinfo");//通告内容

                int isstandard = RequestString.GetInt("isstandard", 0);//是否规范，0是，1否
                string standardids = RequestString.GetFormString("standardids");//不规范项，记录多项ID
                Model.T_Bus_Feedback modelT_Bus_Feedback = new BLL.T_Bus_Feedback().GetNewModelByWorkOrderID(workorderid);
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);


                if (modelT_Bus_WorkOrder != null)
                {
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG"
                        && User.F_RoleCode != "ZXHWY" &&User .F_RoleCode !="SPZJZ"&& User.F_RoleCode != "ZXLD" && User.F_RoleCode != "YSZY" && User.F_RoleCode != "MTDD" && User.F_RoleCode != "DBZY" && User.F_RoleCode != "DMTSH")
                    {
                        if (modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_CreateUser != User.F_UserCode)
                        {
                            return Error("操作失败");
                        }
                    }
                    using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                    {
                        Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                        #region 修改工单记录
                        if (!string.IsNullOrEmpty(result))
                        {
                            keyValuePairs.Add("F_Result", result);
                            modelT_Bus_WorkOrder.F_Result = result;
                        }
                        else if (string.IsNullOrEmpty(modelT_Bus_WorkOrder.F_Result))
                        {
                            if (!string.IsNullOrEmpty(finalopinion))
                            {
                                keyValuePairs.Add("F_Result", finalopinion);
                                modelT_Bus_WorkOrder.F_Result = finalopinion;
                            }

                        }
                        if (modelT_Bus_WorkOrder.F_DealTime == null)
                            keyValuePairs.Add("F_DealTime", DateTime.Now);
                        var affairs = affairsBll.GetModel(modelT_Bus_WorkOrder.F_WorkOrderId);

                        keyValuePairs.Add("F_WorkState", (int)EnumWorkState.finish);

                        modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.finish;
                        keyValuePairs.Add("F_IsSatisfie", issatisfie);
                        keyValuePairs.Add("F_IsClosed", 1);
                        keyValuePairs.Add("F_CloseUser", User.F_UserCode);
                        keyValuePairs.Add("F_CloseTime", DateTime.Now);
                        if (modelT_Bus_Feedback != null && !string.IsNullOrEmpty(modelT_Bus_Feedback.F_File)
                            && modelT_Bus_Feedback.F_Type != 3)
                            affairs.FILES = modelT_Bus_Feedback.F_File;

                        if (!string.IsNullOrEmpty(modelT_Bus_WorkOrder.F_HandlingFile))
                        {
                            affairs.FILES = modelT_Bus_WorkOrder.F_HandlingFile;
                        }

                        if (!string.IsNullOrEmpty(finalopinion))
                        {
                            keyValuePairs.Add("F_FinalOpinion", finalopinion);
                            modelT_Bus_WorkOrder.F_FinalOpinion = finalopinion;
                        }
                        keyValuePairs.Add("F_IsStandard", isstandard);
                        keyValuePairs.Add("F_StandardIDS", standardids);
                        if (isnotice == 1)
                        {
                            Model.T_Bus_NoticeCriticism modelT_Bus_NoticeCriticism = new Model.T_Bus_NoticeCriticism();
                            modelT_Bus_NoticeCriticism.F_DeptIds = deptids;
                            modelT_Bus_NoticeCriticism.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                            modelT_Bus_NoticeCriticism.F_Content = noticereson;
                            modelT_Bus_NoticeCriticism.F_State = 1;
                            modelT_Bus_NoticeCriticism.F_IsDelete = 0;
                            modelT_Bus_NoticeCriticism.F_CreateTime = DateTime.Now;
                            modelT_Bus_NoticeCriticism.F_CreateUser = User.F_UserCode;
                            modelT_Bus_NoticeCriticism.F_NoticeID = noticeid;
                            modelT_Bus_NoticeCriticism.F_NoticeInfo = noticeinfo;
                            new BLL.T_Bus_NoticeCriticism().Add(modelT_Bus_NoticeCriticism);
                            keyValuePairs.Add("F_IsNotice", 1);
                            keyValuePairs.Add("F_NoticeDeptIds", deptids);
                            if (modelT_Bus_AssignedInfo != null)
                            {
                                modelT_Bus_AssignedInfo.F_IsNotice = 1;
                                modelT_Bus_AssignedInfo.F_NoticeUser = User.F_UserCode;
                                modelT_Bus_AssignedInfo.F_NoticeTime = DateTime.Now;

                            }
                        }
                        if (modelT_Bus_AssignedInfo != null)
                        {
                            modelT_Bus_AssignedInfo.F_IsStandard = isstandard;
                            modelT_Bus_AssignedInfo.F_StandardIDS = standardids;
                            assignBLL.Update(modelT_Bus_AssignedInfo);
                        }

                       
                        #endregion

                        #region 插入操作记录
                        Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                        oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                        oper.F_State = modelT_Bus_WorkOrder.F_WorkState;

                        string userinfo = User.depname + "(" + User.F_UserCode + ")";
                        oper.F_Message = userinfo + " 结案了工单，结果：" + (issatisfie == 1 ? "满意" : "不满意");
                        if (isnotice == 1)
                        {
                            //string deptname = DbHelperSQL.GetSingle("select dbo.GetDeptNames('" + deptids + "')").ToString();
                            string deptname = deptBLL.GetDeptNames(deptids);
                            oper.F_Message = oper.F_Message + "，并通告了交办单位：" + deptname;
                        }
                        if (isstandard == 1)
                        {
                            oper.F_Message = oper.F_Message + "，办理结果出现不规范情况，请及时查看";
                        }

                        oper.F_CreateUser = User.F_UserCode;
                        oper.F_CreateTime = DateTime.Now;
                        oper.F_IsDelete = 0;
                        operBLL.Add(oper);
                        int type = 0;
                        receive_case_finish paras = new receive_case_finish();
                        paras.TROWGUID = affairs.TROWGUID;
                        paras.FINISH_NAME = User.F_UserName;
                        paras.FINISH_RESULT = modelT_Bus_WorkOrder.F_Result.Replace("\n", "").Replace("\t", "").Replace("%", "%25");

                       // paras.FINISH_RESULT_QZ = modelT_Bus_WorkOrder.F_Result.Replace("\n", "").Replace("\t", "").Replace("%", "%25");
                        paras.FINISH_ATTATH_ID = affairs.FILES;
                        try
                        {
                            string jsonParam = "paras=" + paras.ToJson() + "&message=反馈工单&url=http://59.227.93.14:9000/share/fwgdfkjk&WorkOrderId=" + modelT_Bus_WorkOrder.F_WorkOrderId;
                            var responseString = HttpMethods.HttpPost(FrontUrl+ "/Affairs/receive_Push", jsonParam);
                            bendiack jo = JsonConvert.DeserializeObject<bendiack>(responseString);
                            if (jo.state != "success"&& !jo.message .Contains ( "该任务单已反馈或退回"))
                            {
                                return Error(jo.message );
                            }
                            else
                            {

                                var modellist = new BLL.T_Bus_Supervision().GetModelList($"F_WorkOrderId='{modelT_Bus_WorkOrder.F_WorkOrderId }'");
                                if (modellist!=null && modellist.Count >0)
                                {
                                    foreach (var model in modellist)
                                    {
                                        model.F_DealTime = DateTime.Now;
                                        model.F_DealUser = User.F_UserCode;
                                        model.F_Result = "已反馈";
                                        model.F_State = 1;
                                        Model.T_Bus_Operation oper2 = new Model.T_Bus_Operation();
                                        oper2.F_WorkOrderId = model.F_WorkOrderId;
                                        new BLL.T_Bus_Supervision().Update(model);
                                        oper2.F_Message = userinfo + " 监察督办反馈了工单，反馈意见：" + "已反馈";
                                        oper2.F_CreateUser = User.F_UserCode;
                                        oper2.F_CreateTime = DateTime.Now;
                                        oper2.F_IsDelete = 0;
                                        operBLL.Add(oper2);
                                        jcsupervise_finish paras1 = new jcsupervise_finish();
                                        paras1.JC_SERIALNUM = model.F_Code;
                                        paras1.JC_NAME = User.F_UserName;
                                        paras1.JC_OPINION = "已反馈";
                                        try
                                        {
                                            string jsonParam1 = "paras=" + paras1.ToJson() + "&message=监察督办反馈&url=http://59.227.93.14:9000/share/jcdbfkjk&WorkOrderId=" + model.F_WorkOrderId;
                                            var responseString1 = HttpMethods.HttpPost(FrontUrl + "/Affairs/receive_Push", jsonParam1);
                                            bendiack jo1 = JsonConvert.DeserializeObject<bendiack>(responseString1);
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            return Error(e.Message );
                        }

                        workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs);
                        #region 插入操作记录
                        Model.T_Bus_Operation oper1 = new Model.T_Bus_Operation();
                        oper1.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;

                        oper1.F_State = modelT_Bus_WorkOrder.F_WorkState;
                        string message = "";
                        if (!string.IsNullOrEmpty(modelT_Bus_WorkOrder.F_Result))
                        {
                            message = "，反馈内容:" + modelT_Bus_WorkOrder.F_Result;
                        }
                        oper1.F_Message = userinfo + " 反馈了省政务平台工单" + message;
                        oper1.F_CreateUser = User.F_UserCode;
                        oper1.F_CreateTime = DateTime.Now;
                        oper1.F_IsDelete = 0;
                        operBLL.Add(oper1);
                        #endregion
                        #endregion

                        trans.Complete();
                    }

                    return Success("操作成功");
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }
        public ActionResult FinishWorkOrder(string workorderid)
        {
            var model = workorderBLL.GetModel(workorderid);

            if (model != null)
            {

                var affairs = affairsBll.GetModel(workorderid);
                if (affairs != null)
                {
                    Model.T_Bus_Feedback modelT_Bus_Feedback = new BLL.T_Bus_Feedback().GetNewModelByWorkOrderID(workorderid);


                    if (modelT_Bus_Feedback != null && !string.IsNullOrEmpty(modelT_Bus_Feedback.F_File)
                                  && modelT_Bus_Feedback.F_Type != 3)
                        affairs.FILES = modelT_Bus_Feedback.F_File;

                    if (!string.IsNullOrEmpty(model.F_HandlingFile))
                    {
                        affairs.FILES = model.F_HandlingFile;
                    }
                    string username = "匿名";
                    if (!string.IsNullOrEmpty(model.F_CloseUser))
                    {
                        var user = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + model.F_CloseUser + "')");
                        if (user != null)
                            username = user.ToString();
                    }

                    receive_case_finish paras = new receive_case_finish();
                    paras.TROWGUID = affairs.TROWGUID;
                    paras.FINISH_NAME = username;
                    if (!string.IsNullOrEmpty(model.F_Result))
                    {
                        paras.FINISH_RESULT = model.F_Result.Replace("\n", "").Replace("\t", "").Replace("%", "%25");
                       // paras.FINISH_RESULT_QZ = model.F_Result.Replace("\n", "").Replace("\t", "").Replace("%", "%25");
                    }
                       
                    paras.FINISH_ATTATH_ID = affairs.FILES;
                    string token = GetToken();
                    string message = "";
                    if (string.IsNullOrEmpty(token))
                        return Error("token获取失败");
                    string userinfo = username + "(" + model.F_CloseUser + ")";
                    try
                    {


                        string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                        string responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/fwgdfkjk", jsonParam);
                        try
                        {
                            goback jo = JsonConvert.DeserializeObject<goback>(responseString);
                            if (jo.code == "1")
                            {
                                Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                                keyValuePairs1.Add("F_Administrative", "0");
                                workorderBLL.UpdateWorkOrder(model.F_Id, keyValuePairs1);

                                message = " 反馈了省政务平台工单";
                                string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", model.F_WorkOrderId, jsonParam, DateTime.Now, jo.code, jo.message, "反馈工单", "", "");
                                object objres = DbHelperSQL.GetSingle(strSql);

                                var modellist = new BLL.T_Bus_Supervision().GetModelList($"F_WorkOrderId='{model.F_WorkOrderId }'");
                                if (modellist != null && modellist.Count > 0)
                                {
                                    foreach (var model1 in modellist)
                                    {
                                        model1.F_DealTime = DateTime.Now;
                                        model1.F_DealUser = model.F_CloseUser;
                                        model1.F_Result = "已反馈";
                                        model1.F_State = 1;
                                        Model.T_Bus_Operation oper2 = new Model.T_Bus_Operation();
                                        oper2.F_WorkOrderId = model1.F_WorkOrderId;
                                        new BLL.T_Bus_Supervision().Update(model1);
                                        oper2.F_Message = userinfo + " 监察督办反馈了工单，反馈意见：" + "已反馈";
                                        oper2.F_CreateUser = model.F_CloseUser;
                                        oper2.F_CreateTime = DateTime.Now;
                                        oper2.F_IsDelete = 0;
                                        operBLL.Add(oper2);
                                        jcsupervise_finish paras1 = new jcsupervise_finish();
                                        paras1.JC_SERIALNUM = model1.F_Code;
                                        paras1.JC_NAME = username;
                                        paras1.JC_OPINION = "已反馈";
                                        try
                                        {
                                            string jsonParam1 = "paras=" + paras1.ToJson() + "&message=监察督办反馈&url=http://59.227.93.14:9000/share/jcdbfkjk&WorkOrderId=" + model1.F_WorkOrderId;
                                            var responseString1 = HttpMethods.HttpPost(FrontUrl + "/Affairs/receive_Push", jsonParam1);
                                            bendiack jo1 = JsonConvert.DeserializeObject<bendiack>(responseString1);
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (jo.message .Contains ( "该任务单已反馈或退回"))
                                {
                                    Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                                    keyValuePairs1.Add("F_Administrative", "0");
                                    workorderBLL.UpdateWorkOrder(model.F_Id, keyValuePairs1);
                                    var modellist = new BLL.T_Bus_Supervision().GetModelList($"F_WorkOrderId='{model.F_WorkOrderId }'");
                                    if (modellist != null && modellist.Count > 0)
                                    {
                                        foreach (var model1 in modellist)
                                        {
                                            model1.F_DealTime = DateTime.Now;
                                            model1.F_DealUser = model.F_CloseUser;
                                            model1.F_Result = "已反馈";
                                            model1.F_State = 1;
                                            Model.T_Bus_Operation oper2 = new Model.T_Bus_Operation();
                                            oper2.F_WorkOrderId = model1.F_WorkOrderId;
                                            new BLL.T_Bus_Supervision().Update(model1);
                                            oper2.F_Message = userinfo + " 监察督办反馈了工单，反馈意见：" + "已反馈";
                                            oper2.F_CreateUser = model.F_CloseUser;
                                            oper2.F_CreateTime = DateTime.Now;
                                            oper2.F_IsDelete = 0;
                                            operBLL.Add(oper2);
                                            jcsupervise_finish paras1 = new jcsupervise_finish();
                                            paras1.JC_SERIALNUM = model1.F_Code;
                                            paras1.JC_NAME = username;
                                            paras1.JC_OPINION = "已反馈";
                                            try
                                            {
                                                string jsonParam1 = "paras=" + paras1.ToJson() + "&message=监察督办反馈&url=http://59.227.93.14:9000/share/jcdbfkjk&WorkOrderId=" + model1.F_WorkOrderId;
                                                var responseString1 = HttpMethods.HttpPost(FrontUrl + "/Affairs/receive_Push", jsonParam1);
                                                bendiack jo1 = JsonConvert.DeserializeObject<bendiack>(responseString1);
                                            }
                                            catch
                                            {
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                                    keyValuePairs1.Add("F_Administrative", "1");
                                    workorderBLL.UpdateWorkOrder(model.F_Id, keyValuePairs1);
                                }

                                message = " 反馈省政务平台工单失败 " + jo.message;
                                LogFactory.GetLogger("1234567").Error(responseString);
                                string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", model.F_WorkOrderId, jsonParam, DateTime.Now, jo.code, jo.message, "反馈工单", jo.message, "");
                                object objres = DbHelperSQL.GetSingle(strSql);

                            }
                        }
                        catch (Exception e)
                        {
                            Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                            keyValuePairs1.Add("F_Administrative", "1");
                            workorderBLL.UpdateWorkOrder(model.F_Id, keyValuePairs1);
                            message = " 反馈省政务平台工单失败 " + responseString;
                            string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", model.F_WorkOrderId, jsonParam, DateTime.Now, "0", e.Message, "反馈工单", e.Message, "");
                            object objres = DbHelperSQL.GetSingle(strSql);
                            LogFactory.GetLogger("123456").Error(responseString);
                            // return Error(token + paras.ToJson() + responseString);



                        }


                    }
                    catch (Exception e)
                    {
                        Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                        keyValuePairs1.Add("F_Administrative", "1");
                        workorderBLL.UpdateWorkOrder(model.F_Id, keyValuePairs1);
                        message = " 反馈省政务平台工单失败 " + e.Message;
                        string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", model.F_WorkOrderId, paras.ToJson(), DateTime.Now, "0", e.Message, "反馈工单", e.Message, "");
                        object objres = DbHelperSQL.GetSingle(strSql);
                        // return Error(token +paras.ToJson());
                    }
                    Model.T_Bus_Operation oper1 = new Model.T_Bus_Operation();
                    oper1.F_WorkOrderId = model.F_WorkOrderId;

                    oper1.F_State = model.F_WorkState;
                    if (username == "匿名")
                    {
                        oper1.F_Message = model.F_CloseUser + message;
                    }
                    else
                    {
                       
                        oper1.F_Message = userinfo + message;
                    }
                    oper1.F_CreateUser = model.F_CloseUser;
                    oper1.F_CreateTime = DateTime.Now;
                    oper1.F_IsDelete = 0;
                    operBLL.Add(oper1);
                    return Success("反馈成功");
                }
                else
                {
                    return Error("非省平台工单");
                }

            }
            else
            {
                return Error("反馈失败");
            }

        }
        public class receive_case_delay_apply
        {/// <summary>
         /// 任务单唯一标识
         /// </summary>
            public string TROWGUID { set; get; }
            /// <summary>
            /// 申请人姓名
            /// </summary>
            public string APPLY_NAME { set; get; }
            /// <summary>
            /// 申请延期天数
            /// </summary>
            public int APPLY_DELAYNUM { set; get; }
            /// <summary>
            /// 申请延期原因
            /// </summary>
            public string APPLY_REASON { set; get; }
            /// <summary>
            /// 申请延期类型
            /// 代码项名称	
            /// 办结延时	10	
            ///  退回延时	20	
            /// </summary>
            public string APPLY_TYPE { set; get; }
        }
        public class receive_case_delay_apply1
        {/// <summary>
         /// 任务单唯一标识
         /// </summary>
            public string TROWGUID { set; get; }
            /// <summary>
            /// 申请人姓名
            /// </summary>
            public string APPLY_NAME { set; get; }
            /// <summary>
            /// 申请延期天数
            /// </summary>
            public int APPLY_DELAYNUM { set; get; }
            /// <summary>
            /// 申请延期原因
            /// </summary>
            public string APPLY_REASON { set; get; }
            /// <summary>
            ///常规延时	10
            ///特殊延时	20
            ///类别错误更正	30
            /// </summary>
            public string APPLY_TYPE { set; get; }

            ///// <summary>
            ///// 变更后诉求类型
            ///// </summary>
            public string APPLY_RQSTTYPE { set; get; }
            ///// <summary>
            ///// 延期附件
            ///// </summary>
            public string APPLY_ATTATH_ID { set; get; }
        }

        /// <summary>
        /// 申请延时
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult DelayWorkOrder()
        {

            if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "SPZJZ" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int newlimittime = RequestString.GetInt("newlimittime", 0);
                string reason = RequestString.GetFormString("reason");
                //   string files = RequestString.GetFormString("files");

                int type = RequestString.GetInt("type", 0);
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                if (type == 0)
                {
                    if (User .F_RoleCode =="WLDW")
                    {
                        int n = DbHelperSQL.ExecuteSql(" update T_Bus_WorkOrder set F_WorkState=5 where F_Id ='" + modelT_Bus_WorkOrder.F_Id + "'");
                    }
                   
                    var Delay = new BLL.T_Bus_DelayTime().GetModelList("F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' " +
                        "and F_AssignedId=-1 and (F_IsAudit=0 or F_IsAudit=3)");
                    if (Delay != null && Delay.Count > 0)
                        return Error("已申请延时，请等待审核结束");
                }
                else
                {
                    var Delay = new BLL.T_Bus_DelayTime().GetModelList("F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and F_AssignedId=0 and F_IsAudit=0");
                    if (Delay != null && Delay.Count > 0)
                        return Error("已申请延时，请等待审核结束");
                }

                if (modelT_Bus_WorkOrder != null)
                {
                    using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                    {
                        #region 保存工单信息
                        #endregion
                        #region 插入申请延时信息
                        string workordercode = modelT_Bus_WorkOrder.F_WorkOrderId;
                        if (!string.IsNullOrEmpty(modelT_Bus_WorkOrder.F_MainWorkorder1))
                        {
                            workordercode = modelT_Bus_WorkOrder.F_MainWorkorder1;
                        }

                        var affairs = affairsBll.GetModel(workordercode);
                        Model.T_Bus_DelayTime delay = new Model.T_Bus_DelayTime();
                        delay.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                        if (type == 0)
                        {
                            if (User.F_RoleCode == "WLDW")
                                delay.F_IsAudit = 0;
                            else
                                delay.F_IsAudit = 3;
                            delay.F_AssignedId = -1;
                            delay.F_State = modelT_Bus_WorkOrder.F_WorkState;
                            delay.F_OldTime = DateTime.Parse(affairs.TFDBACKTIME_BF);
                        }
                        else
                        {
                            delay.F_IsAudit = 0;
                            delay.F_AssignedId = 0;
                            delay.F_OldTime = DateTime.Parse(affairs.TBACKTIME_BF);
                        }

                        string resdate = delay.F_OldTime.Value.ToString("yyyy-MM-dd");
                        DataTable dt = DbHelperSQL.Query("select top " + newlimittime + " F_OffDate from  T_Sys_WorkOFFDays  with(nolock) where F_OffState = 1   and F_OffDate>'" + resdate + "' order by F_OffDate").Tables[0];
                        var resdatetime = dt.Rows[dt.Rows.Count - 1]["F_OffDate"].ToString();
                        resdatetime = Convert.ToDateTime(resdatetime).ToString("yyyy-MM-dd") + " " + delay.F_OldTime.Value.ToString("HH:mm:ss");

                        delay.F_NewTime = Convert.ToDateTime(resdatetime);

                        delay.F_Reason = reason;
                        //delay.F_State = 1;
                      
                            
                       

                        delay.F_IsDelete = 0;
                        //  delay.F_AssignedId = "";
                        delay.F_CreateUser = User.F_UserCode;
                        delay.F_CreateTime = DateTime.Now;
                        //  delay.F_File = files;
                        new BLL.T_Bus_DelayTime().Add(delay);
                        #endregion
                        #region 插入操作记录
                        Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                        oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                        //  oper.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                        oper.F_State = modelT_Bus_WorkOrder.F_WorkState;
                        string userinfo = User.depname + "(" + User.F_UserCode + ")";
                        oper.F_Message = userinfo + " 申请了延时处理";
                        oper.F_CreateUser = User.F_UserCode;
                        oper.F_CreateTime = DateTime.Now;
                        oper.F_IsDelete = 0;
                        operBLL.Add(oper);

                        receive_case_delay_apply paras = new receive_case_delay_apply();
                        paras.TROWGUID = affairs.TROWGUID;
                        paras.APPLY_NAME = User.F_UserName;
                        paras.APPLY_DELAYNUM = newlimittime;
                        if (type == 0)
                            paras.APPLY_TYPE = "10";
                        else
                            paras.APPLY_TYPE = "20";
                        paras.APPLY_REASON = reason;
                        if (!string.IsNullOrEmpty(modelT_Bus_WorkOrder.F_MainWorkorder1))
                        {
                            var model = new BLL.T_Bus_WorkOrder().GetModel(modelT_Bus_WorkOrder.F_MainWorkorder1);
                            if (model != null)
                            {
                                if (!string.IsNullOrEmpty(model.F_SubWorkorder1))
                                {
                                    var modellist = workorderBLL.GetModelList
                                        ("F_WorkOrderId in(select col from dbo.SplitToNvarchar('" + model.F_SubWorkorder1 + "',',' )) " +
                                        " and F_IsDelete =0  ");

                                    if (modellist != null && modellist.Count > 0)
                                    {
                                        foreach (var it in modellist)
                                        {
                                            Model.T_Bus_DelayTime delaynew = new Model.T_Bus_DelayTime();
                                            delaynew.F_WorkOrderId = it.F_WorkOrderId;
                                            if (type == 0)
                                            {
                                                delaynew.F_AssignedId = -1;
                                                delaynew.F_OldTime = DateTime.Parse(affairs.TFDBACKTIME_BF);
                                            }
                                            else
                                            {
                                                delaynew.F_AssignedId = 0;
                                                delaynew.F_OldTime = DateTime.Parse(affairs.TBACKTIME_BF);
                                            }
                                            string resdates = delaynew.F_OldTime.Value.ToString("yyyy-MM-dd");
                                            DataTable dt1 = DbHelperSQL.Query("select top " + newlimittime + " " +
                                                "F_OffDate from  T_Sys_WorkOFFDays  with(nolock) where F_OffState = 1   " +
                                                "and F_OffDate>'" + resdates + "' order by F_OffDate").Tables[0];
                                            var resdatetime1 = dt1.Rows[dt1.Rows.Count - 1]["F_OffDate"].ToString();
                                            resdatetime1 = Convert.ToDateTime(resdatetime1).ToString("yyyy-MM-dd") + " " +
                                                delaynew.F_OldTime.Value.ToString("HH:mm:ss");

                                            delaynew.F_NewTime = Convert.ToDateTime(resdatetime1);

                                            delaynew.F_Reason = reason;
                                            delaynew.F_State = 1;
                                            delaynew.F_IsAudit = 0;
                                            delaynew.F_IsDelete = 0;

                                            //  delay.F_AssignedId = "";
                                            delaynew.F_CreateUser = User.F_UserCode;
                                            delaynew.F_CreateTime = DateTime.Now;
                                            //  delay.F_File = files;
                                            new BLL.T_Bus_DelayTime().Add(delaynew);
                                        }
                                    }

                                }
                            }

                        }

                        try
                        {

                            if (User.F_RoleCode != "WLDW"||type !=0)
                            {
                                string jsonParam = "paras=" + paras.ToJson() + "&message=申请延时&url=http://59.227.93.14:9000/share/fwgdyqsqjk&WorkOrderId=" + modelT_Bus_WorkOrder.F_WorkOrderId;

                                var responseString = HttpMethods.HttpPost(FrontUrl + "/Affairs/receive_Push", jsonParam);
                                bendiack jo = JsonConvert.DeserializeObject<bendiack>(responseString);
                                if (jo.state != "success")
                                    return Error("申请延时失败");

                            }



                        }
                        catch
                        {

                        }
                        #endregion

                        trans.Complete();
                    }
                    return Success("操作成功");


                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }

        /// <summary>
        /// 申请延时
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult NewDelayWorkOrder()
        {

            if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "SPZJZ" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int newlimittime = RequestString.GetInt("newlimittime", 0);
                string reason = RequestString.GetFormString("reason");
                int infoType = RequestString.GetInt("infoType", 0);

                  string files = RequestString.GetFormString("files");
                int types = RequestString.GetInt("types", 0);
                if (!string .IsNullOrEmpty(files))
                    return Error("请选择附件");
                //0常规延时1特殊延时2类别错误更正
                int type = RequestString.GetInt("type", 0);
                if(types == 2&& infoType<=0)
                {
                    return Error("请选择更正错误类别");
                }
                if (User.F_RoleCode == "WLDW")
                {
                    return Error("省平台工单不允许申请延时");
                }
              

                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
               
               if (User.F_RoleCode == "WLDW")
                {
              int n = DbHelperSQL.ExecuteSql(" update T_Bus_WorkOrder set F_WorkState=5 where F_Id ='" + modelT_Bus_WorkOrder.F_Id + "'");
                }

               var Delay = new BLL.T_Bus_DelayTime().GetModelList("F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' " +
                "and F_AssignedId=-1 and (F_IsAudit=0 or F_IsAudit=3)");
                if (Delay != null && Delay.Count > 0)
                  return Error("已申请延时，请等待审核结束");
                

                if (modelT_Bus_WorkOrder != null)
                {
                    using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                    {
                        #region 保存工单信息
                        #endregion
                        #region 插入申请延时信息
                        string workordercode = modelT_Bus_WorkOrder.F_WorkOrderId;
                        if (!string.IsNullOrEmpty(modelT_Bus_WorkOrder.F_MainWorkorder1))
                        {
                            workordercode = modelT_Bus_WorkOrder.F_MainWorkorder1;
                        }

                        var affairs = affairsBll.GetModel(workordercode);
                        Model.T_Bus_DelayTime delay = new Model.T_Bus_DelayTime();
                        delay.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                        if (User.F_RoleCode == "WLDW")
                            delay.F_IsAudit = 0;
                        else
                            delay.F_IsAudit = 3;
                        delay.F_AssignedId = -1;
                        delay.F_State = modelT_Bus_WorkOrder.F_WorkState;
                        delay.F_OldTime = DateTime.Parse(affairs.TFDBACKTIME_BF);
                        delay.F_File = files;
                        string resdate = delay.F_OldTime.Value.ToString("yyyy-MM-dd");
                        DataTable dt = DbHelperSQL.Query("select top " + newlimittime + " F_OffDate from  T_Sys_WorkOFFDays  with(nolock) where F_OffState = 1   and F_OffDate>'" + resdate + "' order by F_OffDate").Tables[0];
                        var resdatetime = dt.Rows[dt.Rows.Count - 1]["F_OffDate"].ToString();
                        resdatetime = Convert.ToDateTime(resdatetime).ToString("yyyy-MM-dd") + " " + delay.F_OldTime.Value.ToString("HH:mm:ss");
                        delay.F_NewTime = Convert.ToDateTime(resdatetime);
                        delay.F_Reason = reason;
                        delay.F_IsDelete = 0;
                        delay.F_CreateUser = User.F_UserCode;
                        delay.F_CreateTime = DateTime.Now;
                     
                        new BLL.T_Bus_DelayTime().Add(delay);
                        #endregion
                        #region 插入操作记录
                        Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                        oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                        //  oper.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                        oper.F_State = modelT_Bus_WorkOrder.F_WorkState;
                        string userinfo = User.depname + "(" + User.F_UserCode + ")";
                        oper.F_Message = userinfo + " 申请了延时处理";
                        oper.F_CreateUser = User.F_UserCode;
                        oper.F_CreateTime = DateTime.Now;
                        oper.F_IsDelete = 0;
                        operBLL.Add(oper);

                        receive_case_delay_apply1 paras = new receive_case_delay_apply1();
                        paras.TROWGUID = affairs.TROWGUID;
                        paras.APPLY_NAME = User.F_UserName;
                        paras.APPLY_DELAYNUM = newlimittime;
                        paras.APPLY_ATTATH_ID = files;
                        if (types == 1)
                            paras.APPLY_TYPE = "20";
                        else if (types == 2)
                            paras.APPLY_TYPE = "30";
                        else
                            paras.APPLY_TYPE = "10";
                        paras.APPLY_REASON = reason;
                        if (infoType>0)
                        {
                            if (infoType == 9)//咨询
                                paras.APPLY_RQSTTYPE = "10";
                            else if (infoType == 12)//建议
                                paras.APPLY_RQSTTYPE = "15";
                            else if (infoType == 11)//投诉
                                paras.APPLY_RQSTTYPE = "20";
                            else if (infoType == 10)//求助
                                paras.APPLY_RQSTTYPE = "30";
                            else if (infoType == 13)//表扬
                                paras.APPLY_RQSTTYPE = "35";
                            else
                                paras.APPLY_RQSTTYPE = "40";//其他
                        }
                      



                        if (!string.IsNullOrEmpty(modelT_Bus_WorkOrder.F_MainWorkorder1))
                        {
                            var model = new BLL.T_Bus_WorkOrder().GetModel(modelT_Bus_WorkOrder.F_MainWorkorder1);
                            if (model != null)
                            {
                                if (!string.IsNullOrEmpty(model.F_SubWorkorder1))
                                {
                                    var modellist = workorderBLL.GetModelList
                                        ("F_WorkOrderId in(select col from dbo.SplitToNvarchar('" + model.F_SubWorkorder1 + "',',' )) " +
                                        " and F_IsDelete =0  ");

                                    if (modellist != null && modellist.Count > 0)
                                    {
                                        foreach (var it in modellist)
                                        {
                                            Model.T_Bus_DelayTime delaynew = new Model.T_Bus_DelayTime();
                                            delaynew.F_WorkOrderId = it.F_WorkOrderId;
                                            if (type == 0)
                                            {
                                                delaynew.F_AssignedId = -1;
                                                delaynew.F_OldTime = DateTime.Parse(affairs.TFDBACKTIME_BF);
                                            }
                                            else
                                            {
                                                delaynew.F_AssignedId = 0;
                                                delaynew.F_OldTime = DateTime.Parse(affairs.TBACKTIME_BF);
                                            }
                                            string resdates = delaynew.F_OldTime.Value.ToString("yyyy-MM-dd");
                                            DataTable dt1 = DbHelperSQL.Query("select top " + newlimittime + " " +
                                                "F_OffDate from  T_Sys_WorkOFFDays  with(nolock) where F_OffState = 1   " +
                                                "and F_OffDate>'" + resdates + "' order by F_OffDate").Tables[0];
                                            var resdatetime1 = dt1.Rows[dt1.Rows.Count - 1]["F_OffDate"].ToString();
                                            resdatetime1 = Convert.ToDateTime(resdatetime1).ToString("yyyy-MM-dd") + " " +
                                                delaynew.F_OldTime.Value.ToString("HH:mm:ss");

                                            delaynew.F_NewTime = Convert.ToDateTime(resdatetime1);

                                            delaynew.F_Reason = reason;
                                            delaynew.F_State = 1;
                                            delaynew.F_IsAudit = 0;
                                            delaynew.F_IsDelete = 0;

                                            //  delay.F_AssignedId = "";
                                            delaynew.F_CreateUser = User.F_UserCode;
                                            delaynew.F_CreateTime = DateTime.Now;
                                            //  delay.F_File = files;
                                            new BLL.T_Bus_DelayTime().Add(delaynew);
                                        }
                                    }

                                }
                            }

                        }

                        try
                        {

                            if (User.F_RoleCode != "WLDW" || type != 0)
                            {
                                string jsonParam = "paras=" + paras.ToJson() + "&message=申请延时&url=http://59.227.93.14:9000/share/fwgdyqsqjk&WorkOrderId=" + modelT_Bus_WorkOrder.F_WorkOrderId;

                                var responseString = HttpMethods.HttpPost(FrontUrl + "/Affairs/receive_Push", jsonParam);
                                bendiack jo = JsonConvert.DeserializeObject<bendiack>(responseString);
                                if (jo.state != "success")
                                    return Error("申请延时失败");

                            }



                        }
                        catch
                        {

                        }
                        #endregion

                        trans.Complete();
                    }
                    return Success("操作成功");


                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }
        public class case_delay_audit
        {
            /// <summary>
            /// 任务单唯一标识
            /// </summary>
            public string TROWGUID { set; get; }
            /// <summary>
            /// 审核人工号
            /// </summary>
            public string AUDIT_NAME { set; get; }
            /// <summary>
            /// 审核结果
            /// </summary>
            public string AUDIT_RESULT { set; get; }
            /// <summary>
            /// 审核意见
            /// </summary>
            public string AUDIT_OPINION { set; get; }
        }
      


     
        public class jcsupervise_finish
        {
            public string JC_SERIALNUM { set; get; }
            public string JC_NAME { set; get; }
            public string JC_OPINION { set; get; }
        }
        /// <summary>
        /// 监察督办批量反馈接口
        /// </summary>
        /// <returns></returns>
       // [Authority]
        public ActionResult batchreceive_jcsupervise_finish()
        {
            var modellist = new BLL.T_Bus_Supervision().GetModelList ("F_State=0");
            if (modellist != null&& modellist.Count >0)
            {
               foreach (var model in modellist)
                {
                    var modelbusworkorder = new BLL.T_Bus_WorkOrder().GetModel(model.F_WorkOrderId);
                    if (modelbusworkorder!=null && modelbusworkorder.F_WorkState ==9)
                    {
                        #region 
                        model.F_DealTime = DateTime.Now;
                        model.F_DealUser = modelbusworkorder.F_CloseUser;
                        model.F_Result = "已反馈";
                        model.F_State = 1;
                        #endregion
                        #region 插入操作记录
                        Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                        oper.F_WorkOrderId = model.F_WorkOrderId;
                        new BLL.T_Bus_Supervision().Update(model);
                        //  oper.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                        string username = "匿名";
                        if (!string.IsNullOrEmpty(modelbusworkorder.F_CloseUser))
                        {
                            var user = DbHelperSQL.GetSingle(" select dbo.GetUserName('" + modelbusworkorder.F_CloseUser + "')");
                            if (user != null)
                                username = user.ToString();
                        }
                        string userinfo = username + "(" + modelbusworkorder.F_CloseUser + ")";
                        oper.F_Message = userinfo + " 监察督办反馈了工单，反馈意见：" + "已反馈";
                        oper.F_CreateUser = modelbusworkorder.F_CloseUser;
                        oper.F_CreateTime = DateTime.Now;
                        oper.F_IsDelete = 0;
                        operBLL.Add(oper);
                        jcsupervise_finish paras = new jcsupervise_finish();
                        paras.JC_SERIALNUM = model.F_Code;
                        paras.JC_NAME = username;
                        paras.JC_OPINION = "已反馈";

                        try
                        {
                            string jsonParam = "paras=" + paras.ToJson() + "&message=监察督办反馈&url=http://59.227.93.14:9000/share/jcdbfkjk&WorkOrderId=" + model.F_WorkOrderId;
                            var responseString = HttpMethods.HttpPost(FrontUrl + "/Affairs/receive_Push", jsonParam);
                            bendiack jo = JsonConvert.DeserializeObject<bendiack>(responseString);
                            if (jo.state != "success")
                                return Error("监察督办反馈失败"+jo.message );

                        }
                        catch
                        {
                            return Error("监察督办反馈失败");
                        }
                        #endregion
                    }
                }
                return Success("操作成功");
            }
            else
            {
                return Error("操作失败");
            }

        }




        /// <summary>
        /// 监察督办反馈接口
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult receive_jcsupervise_finish()
        {


            int id = RequestString.GetInt("id", 0);
            string opinion = RequestString.GetFormString("opinion");

            var model = new BLL.T_Bus_Supervision().GetModel(id);
            int type = RequestString.GetInt("type", 0);

            if (model != null)
            {
                using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                {
                    #region 保存工单信息
                    #endregion
                    #region 

                    model.F_DealTime = DateTime.Now;
                    model.F_DealUser = User.F_UserCode;
                    model.F_Result = opinion;
                    model.F_State = 1;
                    #endregion
                    #region 插入操作记录
                    Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                    oper.F_WorkOrderId = model.F_WorkOrderId;
                    new BLL.T_Bus_Supervision().Update(model);
                    //  oper.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                    string userinfo = User.depname + "(" + User.F_UserCode + ")";
                    oper.F_Message = userinfo + " 监察督办反馈了工单，反馈意见：" + opinion;
                    oper.F_CreateUser = User.F_UserCode;
                    oper.F_CreateTime = DateTime.Now;
                    oper.F_IsDelete = 0;
                    operBLL.Add(oper);

                    jcsupervise_finish paras = new jcsupervise_finish();
                    paras.JC_SERIALNUM = model.F_Code;
                    paras.JC_NAME = User.F_UserName;
                    paras.JC_OPINION = opinion;

                    try
                    {
                        string jsonParam = "paras=" + paras.ToJson() + "&message=监察督办反馈&url=http://59.227.93.14:9000/share/jcdbfkjk&WorkOrderId=" + model.F_WorkOrderId;
                        var responseString = HttpMethods.HttpPost(FrontUrl +"/Affairs/receive_Push", jsonParam);
                        bendiack jo = JsonConvert.DeserializeObject<bendiack>(responseString);
                        if (jo.state != "success")
                            return Error("监察督办反馈成功");

                    }
                    catch
                    {
                        return Error("监察督办反馈失败");
                    }
                    #endregion

                    trans.Complete();
                    return Success("操作成功");
                }



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

        }
        /// <summary>
        /// 督查督办派发接口
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult dcsupervise_send(string workorderid, string Code, string Situation
            , string content, string Opinion)
        {

            Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
            using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
            {
                Model.T_Bus_Supervision model = new Model.T_Bus_Supervision();
                model.F_Code = Code;
                model.F_UserCode = User.F_UserCode;
                model.F_SERIALNUM = modelT_Bus_WorkOrder.F_WorkOrderId;
                model.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                model.F_Situation = Situation;
                model.F_Content = content;
                model.F_Opinion = Opinion;
                model.F_State = 0;
                model.F_Type = 1;
                model.F_CreateTime = DateTime.Now;
                model.F_LimitTime = DateTime.Now.AddDays(5);



                string des = "";
                if (!string.IsNullOrWhiteSpace(model.F_Opinion))
                {
                    des = ",督察内容：" + model.F_Opinion;
                }
                model.F_Type = 1;
                model.F_IsDelete = 0;
                int n = new BLL.T_Bus_Supervision().Add(model);
                if (n > 0)
                {

                    Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                    oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                    oper.F_State = modelT_Bus_WorkOrder.F_WorkState;

                    oper.F_Message = "省平台督查督办派发了工单" + des;
                    oper.F_CreateUser = User.F_UserCode;
                    oper.F_CreateTime = DateTime.Now;
                    oper.F_IsDelete = 0;
                    operBLL.Add(oper);
                    var obj1 = new
                    {
                        code = "1",
                        message = "推送成功"
                    };
                    trans.Complete();
                    return Content(obj1.ToJson());

                }
                else
                {
                    var obj1 = new
                    {
                        code = "1",
                        message = "推送失败"
                    };
                    trans.Complete();
                    return Content(obj1.ToJson());
                }

            }



        }
        /// <summary>
        /// 督查督办派发接口
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult receive_dcsupervise_send()
        {
            StreamReader reader = new StreamReader(System.Web.HttpContext.Current.Request.InputStream);
            var postString = reader.ReadToEnd();
            JObject paras = null;
            paras = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(postString);
            var txnBodyCom = paras["paras"].ToString();
            var result = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(txnBodyCom);
            if (result["DC_RELATION_SERIALNUM"] == null)
            {
                var obj = new
                {
                    code = "0",
                    message = "DC_RELATION_SERIALNUM不能为空"
                };
                return Content(obj.ToJson());
            }
            if (string.IsNullOrEmpty(result["DC_RELATION_SERIALNUM"].ToString()))
            {
                var obj = new
                {
                    code = "0",
                    message = "DC_RELATION_SERIALNUM不能为空"
                };
                return Content(obj.ToJson());
            }
            var affairs = affairsBll.GetModelList("CASE_SERIAL='" + result["DC_RELATION_SERIALNUM"].ToString() + "'");
            if (affairs != null && affairs.Count > 0)
            {
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(affairs.FirstOrDefault().F_WorkOrderId);
                using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                {
                    Model.T_Bus_Supervision model = new Model.T_Bus_Supervision();
                    model.F_Code = result["DC_SERIALNUM"] == null ? "" : result["DC_SERIALNUM"].ToString();
                    model.F_UserCode = result["DC_NAME"] == null ? "" : result["DC_NAME"].ToString();
                    model.F_SERIALNUM = result["DC_RELATION_SERIALNUM"] == null ? "" : result["DC_RELATION_SERIALNUM"].ToString();
                    model.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                    model.F_Situation = result["DC_TYPE"] == null ? "" : result["DC_TYPE"].ToString();
                    model.F_Content = result["DC_CONTENT"] == null ? "" : result["DC_CONTENT"].ToString();
                    model.F_Opinion = result["DC_OPINION"] == null ? "" : result["DC_OPINION"].ToString();
                    model.F_State = 0;
                    model.F_Type = 1;
                    model.F_CreateTime = DateTime.Now;
                    if (result["DC_FINISHTIME_BF"] != null && !string.IsNullOrEmpty(result["DC_FINISHTIME_BF"].ToString()))
                        model.F_LimitTime = DateTime.Parse(result["DC_FINISHTIME_BF"].ToString());

                    if (result["DC_ATTATH_ID"] != null && !string.IsNullOrEmpty(result["DC_ATTATH_ID"].ToString()))
                    {
                        model.F_File = receive_info(result["DC_ATTATH_ID"].ToString());
                    }


                    string des = "";
                    if (!string.IsNullOrWhiteSpace(model.F_Opinion))
                    {
                        des = ",督察内容：" + model.F_Opinion;
                    }
                    model.F_Type = 1;
                    model.F_IsDelete = 0;
                    int n = new BLL.T_Bus_Supervision().Add(model);
                    if (n > 0)
                    {

                        Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                        oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                        oper.F_State = modelT_Bus_WorkOrder.F_WorkState;

                        oper.F_Message = "省平台督查督办派发了工单" + des;
                        oper.F_CreateUser = result["DC_NAME"] == null ? "" : result["DC_NAME"].ToString();
                        oper.F_CreateTime = DateTime.Now;
                        oper.F_IsDelete = 0;
                        operBLL.Add(oper);
                        var obj1 = new
                        {
                            code = "1",
                            message = "推送成功"
                        };
                        trans.Complete();
                        return Content(obj1.ToJson());

                    }
                    else
                    {
                        var obj1 = new
                        {
                            code = "1",
                            message = "推送失败"
                        };
                        trans.Complete();
                        return Content(obj1.ToJson());
                    }

                }

            }
            else
            {
                var obj = new
                {
                    code = "0",
                    message = "推送失败"
                };
                return Content(obj.ToJson());
            }


        }
        public class dcsupervise_finish
        {
            public string DC_SERIALNUM { set; get; }
            public string DC_OPINION { set; get; }
        }
        /// <summary>
        /// 督察督办反馈接口
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult receive_dcsupervise_finish()
        {

            int id = RequestString.GetInt("id", 0);
            string opinion = RequestString.GetFormString("opinion");
            var model = new BLL.T_Bus_Supervision().GetModel(id);
            int type = RequestString.GetInt("type", 0);

            if (model != null)
            {
                using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                {
                    #region 保存工单信息
                    #endregion
                    #region 插入
                    model.F_DealTime = DateTime.Now;
                    model.F_DealUser = User.F_UserCode;
                    model.F_Result = opinion;
                    model.F_State = 1;
                    #endregion
                    #region 插入操作记录
                    Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                    oper.F_WorkOrderId = model.F_WorkOrderId;
                    new BLL.T_Bus_Supervision().Update(model);
                    //  oper.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                    string userinfo = User.depname + "(" + User.F_UserCode + ")";
                    oper.F_Message = userinfo + " 督察督办反馈了工单，反馈意见：" + opinion;
                    oper.F_CreateUser = User.F_UserCode;
                    oper.F_CreateTime = DateTime.Now;
                    oper.F_IsDelete = 0;
                    operBLL.Add(oper);

                    dcsupervise_finish paras = new dcsupervise_finish();
                    paras.DC_SERIALNUM = model.F_Code;
                    paras.DC_OPINION = opinion;
                    try
                    {

                        string jsonParam = "paras=" + paras.ToJson() + "&message=督察督办反馈&url=http://59.227.93.14:9000/share/dcdbfkjk&WorkOrderId=" + model.F_WorkOrderId;
                        var responseString = HttpMethods.HttpPost(FrontUrl +"/Affairs/receive_Push", jsonParam);
                        bendiack jo = JsonConvert.DeserializeObject<bendiack>(responseString);
                        if (jo.state != "success")
                            return Error("督察督办反馈失败");

                    }
                    catch
                    {
                        return Error("督察督办反馈失败");
                    }
                    #endregion

                    trans.Complete();
                    return Success("操作成功");
                }



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

        }
        /// <summary>
        ///催单短信
        /// </summary>
        /// <returns></returns>

        public ActionResult Reminders(string workorderid)
        {


            List<Model.T_Bus_WorkOrder> workorder = new List<Model.T_Bus_WorkOrder>();

            Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
            Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
            if (modelT_Bus_AssignedInfo != null)
            {
                if (modelT_Bus_AssignedInfo.F_IsNext == 1 || modelT_Bus_AssignedInfo.F_IsNext == 2)
                {
                    Model.T_Bus_AssignedInfo_Next modelT_Bus_AssignedInfo_Next = new BLL.T_Bus_AssignedInfo_Next().GetNewModelByWorkOrderID(workorderid);
                    var user = new BLL.T_Sys_UserAccount().GetModelList(" F_DeptId = " + (modelT_Bus_AssignedInfo_Next.F_MainDeptId ?? 0) + " and F_DeleteFlag=0");
                    if (user != null)
                    {
                        foreach (var iv in user)
                        {

                            //msg.AddInternalMessagesInfo("催单消息", "您的工单" + workorderid + "收到催办，请及时处理！", iv.F_UserCode, "8000", (int)EnumSmsType.additional);
                            if (!string.IsNullOrEmpty(iv.F_Mobile))
                            {
                                string count = "您的工单" + workorderid + "收到催办，请及时处理！";
                                bool n = SMSController.AddSmS(0, count, workorderid, iv.F_Mobile, "2764366");

                            }
                        }
                    }

                }
                else
                {
                    var user = new BLL.T_Sys_UserAccount().GetModelList(" F_DeptId = " + (modelT_Bus_WorkOrder.F_MainDeptId ?? 0) + " and F_DeleteFlag=0");
                    if (user != null)
                    {
                        foreach (var iv in user)
                        {

                           // msg.AddInternalMessagesInfo("催单消息", "您的工单" + workorderid + "收到催办，请及时处理！", iv.F_UserCode, "8000", (int)EnumSmsType.additional);
                            if (!string.IsNullOrEmpty(iv.F_Mobile))
                            {
                                string count = "您的工单" + workorderid + "收到催办，请及时处理！";
                                bool n = SMSController.AddSmS(0, count, workorderid, iv.F_Mobile, "2764366");
                            }
                        }
                    }
                }

            }
            return Success("催单成功");



        }




        public class case_c_info
        {
            public string TROWGUID { set; get; }
        }
        public class receive_case_c_info
        {
            public string code { set; get; }
            public string message { set; get; }
            public List<Process> body { set; get; }
        }
        public class Process
        {/// <summary>
         /// 序号
         /// </summary>
            public string PROCESS_INDEX { set; get; }
            /// <summary>
            /// 处理部门
            /// </summary>
            public string PROCESS_OUNAME { set; get; }
            /// <summary>
            /// 处理人员
            /// </summary>
            public string PROCESS_USERNAME { set; get; }
            /// <summary>
            /// 处理时间
            /// </summary>
            public string PROCESS_HANDLE_TIME { set; get; }
            /// <summary>
            /// 处理意见
            /// </summary>
            public string PROCESS_OPINION { set; get; }
            /// <summary>
            /// 操作
            /// </summary>
            public string PROCESS_OPERATE { set; get; }
            /// <summary>
            /// 步骤
            /// </summary>
            public string PROCESS_STEP { set; get; }
            /// <summary>
            /// 附件步骤id"
            /// </summary>
            public string PROCESS_ATTATH_ID { set; get; }
        }
        /// <summary>
        /// 获取省工单流程
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult GetProcess(string workorderid)
        {
            string token = GetToken();

            string fileid = "";
            var modelbusworkorder = affairsBll.GetModel(workorderid);
            case_c_info paras = new case_c_info();
            paras.TROWGUID = modelbusworkorder.TROWGUID;
            //序列化参数
            //Dictionary<string, object> values = new Dictionary<string, object>();
            //values.Add("access_token", token);
            //values.Add("paras", paras);
            //var jsonParam = JsonConvert.SerializeObject(values);

            string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
            var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/fwgdcllcjk", jsonParam);
            receive_case_c_info jo = JsonConvert.DeserializeObject<receive_case_c_info>(responseString); ;
            if (jo.code == "1")
            {
                return Success("获取成功", jo);

            }
            else
            {

                return Error("获取失败");
            }
        }
        /// <summary>
        /// 附件材料接口
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult receive_material_info()
        {
            StreamReader reader = new StreamReader(System.Web.HttpContext.Current.Request.InputStream);
            var postString = reader.ReadToEnd();
            JObject paras = null;
            paras = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(postString);
            var txnBodyCom = paras["paras"].ToString();
            var result = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(txnBodyCom);

            var body = GetFileData(result["ATTATH_STEP_ID"].ToString());
            if (body != null)
            {
                var obj = new
                {
                    code = "1",
                    message = "获取附件成功！",
                    body = body
                };

                return Content(obj.ToJson());

            }
            else
            {
                var obj = new
                {
                    code = "0",
                    message = "获取附件失败！该附件不存在",
                    body = ""
                };

                return Content(obj.ToJson());

            }

        }
        public class push_case
        {
            /// <summary>
            /// "工单编号",
            /// </summary>
            public string CASE_SERIAL { set; get; }
            /// <summary>
            /// "行政区划代码",
            /// </summary>
            public string AREA_CODE { 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 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_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; }
            /// <summary>
            /// 推送意见
            /// </summary>
            public string SEND_CONTENT { set; get; }
            /// <summary>
            /// 工单登记附件id
            /// </summary>
            public string CASE_ATTATH_ID { set; get; }
            public string USER_TYPE { set; get; }
        }
        /// <summary>
        /// </summary>
        /// 服务工单上报接口
        /// <param name="sender"></param>
        /// <param name="e"></param>
        [Authority]
        public ActionResult PhshWorkOrder(string workorderid, string content, int limittime = 7)
        {

            var model = workorderBLL.GetModel(workorderid);
            if (model != null)
            {

                push_case paras = new push_case();

                string newwokrkorder = workorderid;
                 if (model.F_WorkOrderId.Contains("QT"))
                    newwokrkorder = "WZ" + workorderid.Substring(2, workorderid.Length - 2);
               
                paras.CASE_SERIAL = newwokrkorder;
                paras.AREA_CODE = AREA_CODE;
                if (string.IsNullOrEmpty(model.F_CusName))
                    paras.APPLICANT_NAME = "匿名";
                else
                    paras.APPLICANT_NAME = model.F_CusName;
                if (model.F_CusSex == "0")
                    paras.APPLICANT_SEX = "1";
                else if (model.F_CusSex == "1")
                    paras.APPLICANT_SEX = "2";
                else
                    paras.APPLICANT_SEX = "3";
                paras.APPLICANT_AGE = "8";//没有
                paras.APPLICANT_NUMBER = model.F_CusPhone;
                paras.APPLICANT_TIME = model.F_CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");//没有
                paras.CASE_TITLE = model.F_ComTitle;
                paras.CASE_CONTENT = model.F_ComContent;
                paras.CASE_SOURCE = model.F_WorkOrderId.Substring(0, 2);
                if (model.F_InfoType == 9)//咨询
                    paras.CASE_TYPE = "10";
                else if (model.F_InfoType == 12)//建议
                    paras.CASE_TYPE = "15";
                else if (model.F_InfoType == 11)//投诉
                    paras.CASE_TYPE = "20";
                else if (model.F_InfoType == 10)//求助
                    paras.CASE_TYPE = "30";
                else if (model.F_InfoType == 13)//表扬
                    paras.CASE_TYPE = "35";
                else
                    paras.CASE_TYPE = "40";//其他
                paras.CASE_ACCORD = DbHelperSQL.GetSingle(" select dbo.GetDicRemark('" + model.F_Key + "')").ToString();
                paras.CASE_ISPUBLIC = model.F_IsProtect.ToString();
                if (model.F_IsResult == 0)
                    paras.CASE_ISPUBLIC = "1";
                else
                    paras.CASE_ISPUBLIC = "0";
                if (model.F_Level == 2|| model.F_Level == 3)
                {
                    paras.CASE_ISURGENT = "20";
                }
                else
                {
                    paras.CASE_ISURGENT = "30";
                }
                paras.CASE_LNGLAT = model.F_Latitude + "," + model.F_Longitude;
                paras.CASE_EMOTION = "70";
                paras.CASE_ADDRESS = model.F_SourceAddress;
                paras.SEND_CONTENT = content;
                paras.CASE_ATTATH_ID = model.F_File;
                if (model.F_IsBusiness != null && model.F_IsBusiness == 1)
                {
                    paras.USER_TYPE = "20";
                }
                else
                {
                    paras.USER_TYPE = "10";
                }

                try
                {

                    string jsonParam = "paras=" + paras.ToJson() + "&message=服务工单上报接口&url=http://59.227.93.14:9000/share/fwgdsbjk&WorkOrderId=" + model.F_WorkOrderId;
                    var responseString = HttpMethods.HttpPost(FrontUrl +"/Affairs/receive_Push", jsonParam);
                    bendiack jo = JsonConvert.DeserializeObject<bendiack>(responseString);
                    var workoder = DbHelperSQL.GetSingle(" select top 1 F_NewWorkOrder from T_Bus_Mapping  where F_OldWorkOrder='" + workorderid + "'and F_Type=1  order by F_CreateTime desc ");
                    if (workoder == null)
                    {
                        string Mapping = string.Format(@"INSERT INTO T_Bus_Mapping ( [F_OldWorkOrder], [F_NewWorkOrder], [F_CreateTime], [F_Type]) 
                   values   ('{0}','{1}','{2}','{3}') ;select @@IDENTITY ", workorderid, newwokrkorder, DateTime.Now, 1);
                        object Mappings = DbHelperSQL.GetSingle(Mapping);
                        ;
                    }
                    if (jo.state != "success")
                        return Error("上报失败");

                }
                catch
                {
                    return Error("上报失败");
                }
                string resdatetime = "";
                if (limittime > 0)
                {
                    string resdate = DateTime.Now.Date.ToString("yyyy-MM-dd");
                    DataTable dt = DbHelperSQL.Query("select top " + limittime + " F_OffDate from  T_Sys_WorkOFFDays  with(nolock) where F_OffState = 1   and " +
                        "F_OffDate> (select top 1 F_OffDate from T_Sys_WorkOFFDays  where F_OffDate >= '" + resdate + "'  and   F_OffState = 1  order by F_OffDate asc) order by F_OffDate").Tables[0];
                    resdatetime = dt.Rows[dt.Rows.Count - 1]["F_OffDate"].ToString();
                }
                resdatetime = Convert.ToDateTime(resdatetime).ToString("yyyy-MM-dd") + " " + DateTime.Now.ToString("HH:mm:ss"); 
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = new Model.T_Bus_AssignedInfo();
                modelT_Bus_AssignedInfo.F_WorkOrderId = model.F_WorkOrderId;
                modelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(resdatetime);
                modelT_Bus_AssignedInfo.F_MainDeptId = 633;
                modelT_Bus_AssignedInfo.F_OtherDeptIds = "";//协办单位id
                modelT_Bus_AssignedInfo.F_AssignedOpinion = content;//交办意见
                modelT_Bus_AssignedInfo.F_State = 1;//0草稿  1正式
                modelT_Bus_AssignedInfo.F_CreateUser = "省12345平台";
                modelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                modelT_Bus_AssignedInfo.F_IsDelete = 0;
                modelT_Bus_AssignedInfo.F_IsOverdue = 0;
                modelT_Bus_AssignedInfo.F_IsSure = 1;
                modelT_Bus_AssignedInfo.F_IsReload = 0;
                modelT_Bus_AssignedInfo.F_SureUser = "省12345平台";
                modelT_Bus_AssignedInfo.F_SureTime = DateTime.Now;
                modelT_Bus_AssignedInfo.F_IsNext = 0;
                modelT_Bus_AssignedInfo.F_TimeResp = assignBLL.GetRepTimly(DateTime.Now);//及时查收时间点
                modelT_Bus_AssignedInfo.F_Id = assignBLL.Add(modelT_Bus_AssignedInfo);
                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                keyValuePairs.Add("F_AssignUser", 8000);
                keyValuePairs.Add("F_AssignTime", DateTime.Now);
                keyValuePairs.Add("F_MainDeptId", 633);
                model.F_MainDeptId = 633;
                keyValuePairs.Add("F_WorkState", 4);
                model.F_WorkState = 4;
                workorderBLL.UpdateWorkOrder(model.F_Id, keyValuePairs);
                Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                oper.F_WorkOrderId = model.F_WorkOrderId;
                //  oper.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                string userinfo = User.F_UserName + "(" + User.F_UserCode + ")";
                oper.F_Message = userinfo + " 上报了工单，推送意见：" + content;
                oper.F_CreateUser = User.F_UserCode;
                oper.F_CreateTime = DateTime.Now;
                oper.F_IsDelete = 0;
                operBLL.Add(oper);
                return Success("推送成功");
            }
            else
                return Error("工单不存在");


        }



        /// <summary>
        /// 服务工单推送处理结果接口
        /// </summary>
        /// <returns></returns>
      //  [Authority]
        public ActionResult push_case_finish()
        {

            StreamReader reader = new StreamReader(System.Web.HttpContext.Current.Request.InputStream);
            var postString = reader.ReadToEnd();
            JObject paras = null;
            paras = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(postString);
            var txnBodyCom = paras["paras"].ToString();
            var result = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(txnBodyCom);
            if (result["CASE_SERIAL"] == null)
            {
                var obj = new
                {
                    code = "0",
                    message = "CASE_SERIAL不能为空"
                };
                return Content(obj.ToJson());
            }
            if (string.IsNullOrEmpty(result["CASE_SERIAL"].ToString()))
            {
                var obj = new
                {
                    code = "0",
                    message = "CASE_SERIAL不能为空"
                };
                return Content(obj.ToJson());
            }

           // string workoderid = result["CASE_SERIAL"].ToString();
            var workoder = DbHelperSQL.GetSingle(" select top 1 F_OldWorkOrder from T_Bus_Mapping  where F_NewWorkOrder='" + result["CASE_SERIAL"].ToString() + "'and F_Type=1  order by F_CreateTime desc ");
            string workoderid = result["CASE_SERIAL"].ToString();
            if (workoder != null)
            {
                workoderid = workoder.ToString()
;
            }
            Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workoderid);
            Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workoderid);
            Model.T_Bus_Feedback modelT_Bus_Feedback = new Model.T_Bus_Feedback();
            if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo != null)
            {
                using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                {
                    #region 插入反馈记录
                    Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                    modelT_Bus_Feedback.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;//工单编号
                    modelT_Bus_Feedback.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;//交办id

                    modelT_Bus_Feedback.F_AuditUser = "";
                    modelT_Bus_Feedback.F_DealUser = result["FINISH_NAME"] == null ? "" : result["FINISH_NAME"].ToString();
                    modelT_Bus_Feedback.F_Result = result["FINISH_OUNAME"] == null ? "" : result["FINISH_OUNAME"].ToString() + "于时间（" + DateTime.Now.ToString("yyyy年MM月dd日 HH时mm分ss秒") + "）回复：" + result["FINISH_RESULT"] == null ? "" : result["FINISH_RESULT"].ToString();
                    #region 20200114新增字段 zhengbingbing

                    modelT_Bus_Feedback.F_ProSituation = "";//处理情况/方案/进程
                    modelT_Bus_Feedback.F_IsProtect = modelT_Bus_WorkOrder.F_IsProtect;
                    modelT_Bus_Feedback.F_DealUserContact = "";//承办人联系方式
                    DateTime contime = DateTime.Now;
                    modelT_Bus_Feedback.F_IsProResult = 1;
                    #endregion
                    if (result["FINISH_ATTATH_ID"] != null && !string.IsNullOrEmpty(result["FINISH_ATTATH_ID"].ToString()))
                        keyValuePairs.Add("F_File", receive_info(result["FINISH_ATTATH_ID"].ToString()));


                    modelT_Bus_Feedback.F_IsAudit = 0;
                    modelT_Bus_Feedback.F_IsDelete = 0;
                    modelT_Bus_Feedback.F_CreateUser = result["FINISH_NAME"] == null ? "" : result["FINISH_NAME"].ToString();
                    modelT_Bus_Feedback.F_CreateTime = DateTime.Now;//办理时间
                    modelT_Bus_Feedback.F_CreateDeptId = 633;//办理部门
                    modelT_Bus_Feedback.F_IsFeedEnd = 1;
                    modelT_Bus_Feedback.F_State = 1;
                    new BLL.T_Bus_Feedback().Add(modelT_Bus_Feedback);
                    #endregion
                    if (modelT_Bus_Feedback != null && modelT_Bus_Feedback.F_State == 1)
                    {
                        string typemsg = "办理";
                        #region 保存工单信息
                        keyValuePairs.Add("F_WorkState", 6);
                        //  modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.dealed;//待回访
                        keyValuePairs.Add("F_Result", modelT_Bus_Feedback.F_Result);
                        //  modelT_Bus_WorkOrder.F_Result = modelT_Bus_Feedback.F_Result;
                        keyValuePairs.Add("F_DealDeptId", 633);
                        modelT_Bus_WorkOrder.F_DealDeptId = 633;
                        keyValuePairs.Add("F_DealUser", result["FINISH_NAME"] == null ? "" : result["FINISH_NAME"].ToString());
                        // modelT_Bus_WorkOrder.F_DealUser = result["FINISH_NAME"] == null ? "" : result["FINISH_NAME"].ToString();
                        keyValuePairs.Add("F_DealTime", DateTime.Now);
                        //  modelT_Bus_WorkOrder.F_DealTime = DateTime.Now;

                        keyValuePairs.Add("F_IsOverdue", 0);
                        // modelT_Bus_WorkOrder.F_IsOverdue = 0;

                        workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs);
                        #endregion
                        #region 保存交办信息
                        modelT_Bus_AssignedInfo.F_FeedbackTime = DateTime.Now;
                        modelT_Bus_AssignedInfo.F_IsOverdue = 0;
                        assignBLL.Update(modelT_Bus_AssignedInfo);
                        #endregion

                        typemsg = "主办";
                        #region 插入操作记录
                        Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                        oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                        oper.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                        oper.F_State = modelT_Bus_WorkOrder.F_WorkState;
                        string userinfo = result["FINISH_NAME"] == null ? "" : result["FINISH_NAME"].ToString();
                        oper.F_Message = userinfo + " " + typemsg + "了工单";
                        oper.F_CreateUser = userinfo;
                        oper.F_CreateTime = DateTime.Now;
                        oper.F_IsDelete = 0;
                        operBLL.Add(oper);
                        //推送消息表
                       // msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, modelT_Bus_WorkOrder.F_CreateUser, userinfo, (int)EnumSmsType.workorder);
                        #endregion
                    }

                    trans.Complete();
                }
                var obj = new
                {
                    code = "1",
                    message = "反馈成功！"
                };

                return Content(obj.ToJson());

            }
            else
            {
                var obj = new
                {
                    code = "0",
                    message = "工单不存在！"
                };
                return Content(obj.ToJson());
            }
        }




        /// <summary>
        /// 获取附件数据
        /// </summary>
        /// <param name="ids">附件id，多个用英文逗号,隔开</param>
        /// <param name="prefix">前缀</param>
        /// <returns></returns>
        public List<bodys> GetFileData(string ids)
        {
            DataTable dt = DbHelperSQL.Query("select * from T_Sys_Accessories WITH(NOLOCK) where F_FileId in (" + ids + ")").Tables[0];
            List<bodys> bodys = new List<bodys>();
            foreach (DataRow dr in dt.Rows)
            {
                if (dr["F_UserCode"].ToString() != "知识附件")
                {
                    string url = Upload(NativeURL  + dr["F_FileUrl"].ToString(), dr["F_FileName"].ToString(), "/" + dr["F_FileUrl"].ToString().Replace(dr["F_FileName"].ToString(), ""));
                    if (url != "1")
                        return null;
                }


                bodys body = new bodys();
                body.ATTATH_TYPE = dr["F_FileType"].ToString();
                body.ATTATH_NAME = dr["F_FileName"].ToString();
                FileStream fs = new FileStream(System.Web.HttpContext.Current.Server.MapPath("..") + dr["F_FileUrl"].ToString(), FileMode.Open);
                byte[] filebyte = new byte[fs.Length];
                fs.Read(filebyte, 0, filebyte.Length);
                fs.Close();
                body.ATTATH_CONTENT = Convert.ToBase64String(filebyte);
                bodys.Add(body);
            }

            return bodys;
        }
        public string Upload(string pathUrl, string newFileName, string path)
        {
            //文件下载地址
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(pathUrl);
                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                Stream responseStream = response.GetResponseStream();
                string Currentpath = System.Web.HttpContext.Current.Server.MapPath("..") + path;
                // 如果不存在就创建file文件夹
                if (!Directory.Exists(Currentpath))
                {
                    if (Currentpath != null) Directory.CreateDirectory(Currentpath);
                }
                Stream stream = new FileStream(Currentpath + newFileName, FileMode.Create);
                byte[] bArr = new byte[1024];
                int size = responseStream.Read(bArr, 0, bArr.Length);
                while (size > 0)
                {
                    stream.Write(bArr, 0, size);
                    size = responseStream.Read(bArr, 0, bArr.Length);
                }
                stream.Close();
                responseStream.Close();

                return "1";
            }
            catch (Exception e)
            {
                return e.Message;
            }
        }
        #region 

        public class kinfo
        {
            public string code { set; get; }
            public string message { set; get; }
            public kinfobody body { set; get; }
        }
        public class kinfobody
        {
            public string KINFO_ID { set; get; }
        }
        public class Push
        {
            public string code { set; get; }
            public string message { set; get; }

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

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

        //}

    
        private string GetToken()
        {

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

            string jsonParam = "client_id=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 "";

        }

        private string GetTokenzsk()
        {

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

            string jsonParam = "client_id=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 "";

        }

        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; }
        }
      


        /// <summary>
        /// HMACSHA1算法加密
        /// </summary>
        private static string Hmacsha256Encrypt(string encryptText, string encryptKey)
        {
            var encoding = new System.Text.UTF8Encoding();
            var shaKeyBytes = encoding.GetBytes(encryptKey);
            StringBuilder builder = new StringBuilder();

            using (var shaAlgorithm = new System.Security.Cryptography.HMACSHA256(shaKeyBytes))
            {
                var signatureBytes = System.Text.Encoding.UTF8.GetBytes(encryptText);
                var signatureHashBytes = shaAlgorithm.ComputeHash(signatureBytes);
                return System.Convert.ToBase64String(signatureHashBytes);
            }
        }

        /// <summary>
        /// 用种子获取密钥
        /// </summary>
        /// <param name="Seed">种子</param>
        /// <param name="KeyLen">密钥长度（默认为16）</param>
        /// <returns>密钥Key</returns>
        public static byte[] GetKeyBySeed(string Seed, int KeyLen = 16)
        {
            byte[] bySeed = Encoding.UTF8.GetBytes(Seed);
            byte[] byKeyArray = null;
            using (var st = new SHA1CryptoServiceProvider())
            {
                using (var nd = new SHA1CryptoServiceProvider())
                {
                    var rd = nd.ComputeHash(st.ComputeHash(bySeed));
                    byKeyArray = rd.Take(KeyLen).ToArray();
                }
            }
            return byKeyArray;
        }

        /// <summary>
        /// AES加密
        /// </summary>
        /// <param name="Bytes">明文（byte[]）</param>
        /// <param name="Key">密钥（byte[]）</param>
        /// <param name="Vector">向量</param>
        /// <returns>密文（byte[]）</returns>
        public static byte[] Encrypt(byte[] Bytes, byte[] Key, string Vector)
        {
            RijndaelManaged aes = new RijndaelManaged();
            aes.Mode = CipherMode.CBC;
            aes.Padding = PaddingMode.PKCS7;
            aes.Key = Key;
            aes.IV = Encoding.UTF8.GetBytes(Vector);

            ICryptoTransform cTransform = aes.CreateEncryptor();
            return cTransform.TransformFinalBlock(Bytes, 0, Bytes.Length);
        }

        /// <summary>
        /// AES解密
        /// </summary>
        /// <param name="Bytes">密文（byte[]）</param>
        /// <param name="Key">密钥（byte[]）</param>
        /// <param name="Vector">向量</param>
        /// <returns>明文（byte[]）</returns>
        public static byte[] Decrypt(byte[] Bytes, byte[] Key, string Vector)
        {
            RijndaelManaged aes = new RijndaelManaged();
            aes.Mode = CipherMode.CBC;
            aes.Padding = PaddingMode.PKCS7;
            aes.Key = Key;
            aes.IV = Encoding.UTF8.GetBytes(Vector);

            ICryptoTransform cTransform = aes.CreateDecryptor();
            return cTransform.TransformFinalBlock(Bytes, 0, Bytes.Length);
        }




        private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
        {
            return true; //总是接受  
        }



      
        public class Tokenbody
        {
            public string access_token { set; get; }
            public string refresh_token { set; get; }
            public string token_type { set; get; }
            public int expires_in { set; get; }
        }
        public class Status
        {
            public string code { set; get; }
        }
        /// <summary>
        /// 监察督办督察督办列表
        /// </summary>
        /// <param name="isdc"></param>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetSupervList(int isdc = 0)
        {
            DataTable dt = new DataTable();
            string sql = " and F_IsDelete=0";
            #region 参数
            int type = RequestString.GetInt("type", 0);//0监察督办1督察督办
            sql += " and F_Type ='" + type + "'";
            int state = RequestString.GetInt("state", 0);//0未回复1已回复
            if (state > -1)
                sql += " and F_State ='" + state + "'";
            string starttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("strendtime"));
            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;
            string title = HttpUtility.UrlDecode(RequestString.GetQueryString("title"));
            if (title.Trim() != "" && title != "undefined")
            {
                sql += " and F_Title like '%" + title + "%' ";
            }
            string content = HttpUtility.UrlDecode(RequestString.GetQueryString("content"));
            if (content.Trim() != "" && content != "undefined")
            {
                sql += " and F_Content like '%" + content + "%' ";
            }
            string opinion = HttpUtility.UrlDecode(RequestString.GetQueryString("opinion"));
            if (opinion.Trim() != "" && opinion != "undefined")
            {
                sql += " and F_Opinion like '%" + opinion + "%' ";
            }

            string level = HttpUtility.UrlDecode(RequestString.GetQueryString("level"));
            if (level.Trim() != "" && level != "undefined")
            {
                sql += " and F_Level ='" + level + "' ";
            }
            string situation = HttpUtility.UrlDecode(RequestString.GetQueryString("situation"));
            if (situation.Trim() != "" && situation != "undefined")
            {
                sql += " and F_Situation like '%" + situation + "%' ";
            }
            if (starttime.Trim() != "" && starttime != "undefined")
            {
                sql += " and F_CreateTime >='" + starttime + "'";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and F_CreateTime <='" + strendtime + "'";
            }
            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }

            if (strpagesize.Trim() != "")
            {
                pagesize = Convert.ToInt32(strpagesize);
            }
            #endregion
            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_Supervision a WITH(NOLOCK)",
                "F_Id",
                "*",
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);

            #region 附加展示

            var config = configBll.GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();

            foreach (DataRow dr in dt.Rows)
            {

                #endregion
            }
            #endregion

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };
            return Content(obj.ToJson());
        }
        /// <summary>
        /// 获取监察督办督察督办
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetSuperv(int id)
        {
            var model = new BLL.T_Bus_Supervision().GetModel(id);
            var configfj = configBll.GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
            string sql = "select * from T_Bus_Supervision a WITH(NOLOCK) where F_ID ='" + id + "'";
            var dt = DbHelperSQL.Query(sql).Tables[0];

            var configly = configBll.GetModelList(" F_ParamCode='PlayLeaveVoice' ").FirstOrDefault();
            var config = configBll.GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
            if (dt.Rows.Count > 0)
            {
                #region 声音文件
                dt.Columns.Add("FilePath", typeof(string));
                #endregion

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

                var obj = new
                {
                    data = dt

                };
                return Success("获取成功", obj);
            }
            else
            {
                return Error("获取失败");
            }


        }
        /// <summary>
        /// 绑定附件信息
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="prefix"></param>
        /// <returns></returns>
        public DataTable BindFileData(DataTable dt, string prefix)
        {
            dt.Columns.Add("File", typeof(object));
            foreach (DataRow dr in dt.Rows)
            {
                if (dr["F_File"] != null && dr["F_File"].ToString() != "")
                {
                    dr["File"] = GetFileData(dr["F_File"].ToString(), prefix);
                }
            }
            return dt;
        }
        /// <summary>
        /// 获取附件数据
        /// </summary>
        /// <param name="ids">附件id，多个用英文逗号,隔开</param>
        /// <param name="prefix">前缀</param>
        /// <returns></returns>
        public DataTable GetFileData(string ids, string prefix)
        {
            DataTable dt = DbHelperSQL.Query("select * from T_Sys_Accessories WITH(NOLOCK) where F_FileId in (" + ids + ")").Tables[0];

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


            }

            return dt;
        }
        #region 知识库

        public class transmit_kinfo_add
        {
            public string AREA_CODE { set; get; }
            /// <summary>
            /// 标题
            /// </summary>
            public string KINFO_KNAME { set; get; }
            /// <summary>
            /// 内容
            /// </summary>
            public string KINFO_KCONTENT { set; get; }
            /// <summary>
            /// 知识分类编码
            /// </summary>
            public string KINFO_TYPECODE { set; get; }
            /// <summary>
            /// 发布时间
            /// </summary>
            public string KINFO_CREATDATE { set; get; }
            /// <summary>
            /// 生效时间
            /// </summary>
            public string KINFO_BEGINDATE { set; get; }
            /// <summary>
            /// 失效时间
            /// </summary>
            public string KINFO_DISABLEDATE { set; get; }
            /// <summary>
            /// 知识报送附件id
            /// </summary>
            public string KINFO_ATTATH_ID { set; get; }
        }
        /// <summary>
        /// </summary>
        /// 知识报送接口
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult kinfo_add(int id)
        {
            Model.T_RepositoryInformation model = new BLL.T_RepositoryInformation().GetModel(id);
            if (model != null)
            {
                transmit_kinfo_add paras = new transmit_kinfo_add();

                paras.AREA_CODE = AREA_CODE;
                paras.KINFO_KNAME = model.F_Title;
                if (!string.IsNullOrEmpty(model.F_Description))
                    paras.KINFO_KCONTENT = model.F_Description;
                else
                    paras.KINFO_KCONTENT = "无";
                if (model.F_Key == null)
                    return Error("分类不存在");
                string key = DbHelperSQL.GetSingle(" select dbo.GetDicRemark('" + model.F_Key + "')").ToString();
                if (!string.IsNullOrEmpty(key))
                    paras.KINFO_TYPECODE = DbHelperSQL.GetSingle(" select dbo.GetDicRemark('" + model.F_Key + "')").ToString();
                else
                    paras.KINFO_TYPECODE = "";
                paras.KINFO_CREATDATE = model.F_CreateOn.Value.ToString("yyyy-MM-dd HH:mm:ss");

                paras.KINFO_BEGINDATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");


                string fileid = "";
                if (!string.IsNullOrEmpty(model.F_Content))
                {

                    if (!string.IsNullOrEmpty(model.F_Content))
                    {
                        string[] str = model.F_Content.Split('"');
                        for (int i = 0; i < str.Length; i++)
                        {
                            if (str[i].Contains("/js/kindeditor/upload"))
                            {

                                string path = "/Upload/kinfo/" + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd") + "/";

                                var response = kinfo_upload(ForeNativeURL + str[i], System.IO.Path.GetFileName(str[i]), path);
                                List<Model.T_Sys_Accessories> acs = new List<Model.T_Sys_Accessories>();
                                Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
                                model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
                                model_T_Sys_Accessories.F_FileName = System.IO.Path.GetFileName(str[i]);//附件名称
                                model_T_Sys_Accessories.F_FileType = System.IO.Path.GetExtension(str[i]);//附件类
                                model_T_Sys_Accessories.F_FileUrl = path + System.IO.Path.GetFileName(str[i]);//附件地址
                                model_T_Sys_Accessories.F_UserCode = "知识附件";//上传人  
                                int accid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
                                model_T_Sys_Accessories.F_FileId = accid;
                                if (string.IsNullOrEmpty(fileid))
                                    fileid = id.ToString();
                                else
                                    fileid += "," + id.ToString();
                            }
                        }
                    }
                }

                paras.KINFO_ATTATH_ID = fileid;
                string token = GetTokenzsk();
                if (string.IsNullOrEmpty(token))
                    return Error("token获取失败");
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();

                var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/zssbjk", jsonParam);
                //   return Success(responseString);
                JObject jo = (JObject)JsonConvert.DeserializeObject(responseString);


                if (jo["code"].ToString() == "1")
                {
                    kinfo kinfo = JsonConvert.DeserializeObject<kinfo>(responseString);
                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", id, "", DateTime.Now, jo["code"].ToString(), jo["message"].ToString(), "知识报送接口", "", "推送成功数1");
                    object objres = DbHelperSQL.GetSingle(strSql);

                    string Mapping = string.Format(@"INSERT INTO T_Bus_Mapping ( [F_OldWorkOrder], [F_NewWorkOrder], [F_CreateTime], [F_Type]) 
                    values   ('{0}','{1}','{2}','{3}') ;select @@IDENTITY ", model.F_RepositoryId, kinfo.body.KINFO_ID, DateTime.Now, 0);
                    object Mappings = DbHelperSQL.GetSingle(Mapping);
                    return Error("推送成功");

                }
                else
                {
                    string error = "";

                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", paras.ToJson(), DateTime.Now, jo["code"].ToString(), jo["message"].ToString(), "知识报送接口", error, "推送成功数1");
                    object objres = DbHelperSQL.GetSingle(strSql);
                    LogFactory.GetLogger("111").Warn("知识报送接口" + error);
                    return Error("推送失败---" + error);

                }

            }
            else
            {
                return Error("推送失败知识不存在");
            }

        }


        public class transmit_kinfo_update
        {
            public string AREA_CODE { set; get; }
            /// <summary>
            /// 知识唯一标识
            /// </summary>
            public string KINFO_ID { set; get; }
            /// <summary>
            /// 标题
            /// </summary>
            public string KINFO_KNAME { set; get; }

            /// <summary>
            /// 内容
            /// </summary>
            public string KINFO_KCONTENT { set; get; }
            /// <summary>
            /// 知识分类编码
            /// </summary>
            public string KINFO_TYPECODE { set; get; }
            /// <summary>
            /// 发布时间
            /// </summary>
            public string KINFO_CREATDATE { set; get; }
            /// <summary>
            /// 生效时间
            /// </summary>
            public string KINFO_BEGINDATE { set; get; }
            /// <summary>
            /// 失效时间
            /// </summary>
            public string KINFO_DISABLEDATE { set; get; }
            /// <summary>
            /// 知识报送附件id
            /// </summary>
            public string KINFO_ATTATH_ID { set; get; }
        }
        /// <summary>
        /// </summary>
        /// 知识变更接口
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult kinfo_update(int id)
        {
            Model.T_RepositoryInformation model = new BLL.T_RepositoryInformation().GetModel(id);
            if (model != null)
            {
                transmit_kinfo_update paras = new transmit_kinfo_update();

                paras.AREA_CODE = AREA_CODE;
                paras.KINFO_KNAME = model.F_Title;
                paras.KINFO_KCONTENT = model.F_Description;
                var KINFO_ID = DbHelperSQL.GetSingle(" select top 1 F_NewWorkOrder from T_Bus_Mapping  where F_OldWorkOrder='" + model.F_RepositoryId + "' and F_Type=0 order by F_CreateTime desc ");
                if (KINFO_ID != null)
                {
                    paras.KINFO_ID = KINFO_ID.ToString();
                }
                else
                {
                    return Error("知识未上传");
                }
                if (!string.IsNullOrEmpty(model.F_Description))
                    paras.KINFO_KCONTENT = model.F_Description;
                else
                    paras.KINFO_KCONTENT = "无";
                string key = DbHelperSQL.GetSingle(" select dbo.GetDicRemark('" + model.F_Key + "')").ToString();
                if (!string.IsNullOrEmpty(key))
                    paras.KINFO_TYPECODE = DbHelperSQL.GetSingle(" select dbo.GetDicRemark('" + model.F_Key + "')").ToString();
                else
                    paras.KINFO_TYPECODE = "";
                paras.KINFO_CREATDATE = model.F_CreateOn.Value.ToString("yyyy-MM-dd HH:mm:ss");

                paras.KINFO_BEGINDATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");


                string fileid = "";
                if (!string.IsNullOrEmpty(model.F_Content))
                {

                    if (!string.IsNullOrEmpty(model.F_Content))
                    {
                        string[] str = model.F_Content.Split('"');
                        for (int i = 0; i < str.Length; i++)
                        {
                            if (str[i].Contains("/js/kindeditor/upload"))
                            {
                                string path = "/Upload/kinfo/" + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd") + "/";
                                var response = kinfo_upload(ForeNativeURL + str[i], System.IO.Path.GetFileName(str[i]), path);
                                List<Model.T_Sys_Accessories> acs = new List<Model.T_Sys_Accessories>();
                                Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
                                model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
                                model_T_Sys_Accessories.F_FileName = System.IO.Path.GetFileName(str[i]);//附件名称
                                model_T_Sys_Accessories.F_FileType = System.IO.Path.GetExtension(str[i]);//附件类
                                model_T_Sys_Accessories.F_FileUrl = path + System.IO.Path.GetFileName(str[i]);//附件地址
                                model_T_Sys_Accessories.F_UserCode = "知识附件";//上传人  
                                int accid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
                                model_T_Sys_Accessories.F_FileId = id;
                                if (string.IsNullOrEmpty(fileid))
                                    fileid = id.ToString();
                                else
                                    fileid += "," + id.ToString();
                            }
                        }
                    }
                }
                paras.KINFO_ATTATH_ID = fileid;
                string token = GetTokenzsk();
                if (string.IsNullOrEmpty(token))
                    return Error("token获取失败");
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();

                var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/zsbgjk", jsonParam);
                JObject jo = (JObject)JsonConvert.DeserializeObject(responseString);


                if (jo["code"].ToString() == "1")
                {
                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", id, "", DateTime.Now, jo["code"].ToString(), jo["message"].ToString(), "知识变更接口", "", "推送成功数1");
                    object objres = DbHelperSQL.GetSingle(strSql);
                    return Success("推送成功");
                }
                else
                {
                    string error = "";

                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", paras.ToJson(), DateTime.Now, jo["code"].ToString(), jo["message"].ToString(), "知识变更接口", error, "推送成功数1");
                    object objres = DbHelperSQL.GetSingle(strSql);
                    LogFactory.GetLogger("111").Warn("知识变更接口" + error);
                    return Error("推送失败---" + error);

                }

            }
            else
            {
                return Error("推送失败知识不存在");
            }

        }


        public class transmit_kinfo_delete
        {

            /// <summary>
            /// 知识唯一标识
            /// </summary>
            public string KINFO_ID { set; get; }

            /// <summary>
            /// 知识下架原因
            /// </summary>
            public string KINFO_REASON { set; get; }

        }
        /// <summary>
        /// </summary>
        /// 知识下架接口
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public ActionResult kinfo_delete(int id, string remark)
        {
            Model.T_RepositoryInformation model = new BLL.T_RepositoryInformation().GetModel(id);
            if (model != null)
            {
                transmit_kinfo_delete paras = new transmit_kinfo_delete();

                var KINFO_ID = DbHelperSQL.GetSingle(" select top 1 F_NewWorkOrder from T_Bus_Mapping  where F_OldWorkOrder='" + model.F_RepositoryId + "'and F_Type=0  order by F_CreateTime desc ");
                if (KINFO_ID != null)
                {
                    paras.KINFO_ID = KINFO_ID.ToString();
                }
                else
                {
                    return Error("知识未上传");
                }
                string token = GetTokenzsk();
                if (string.IsNullOrEmpty(token))
                    return Error("token获取失败");
                paras.KINFO_REASON = remark;
                string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
                
                var responseString = HttpMethods.HttpPost("http://59.227.93.14:9000/share/zsxjjk", jsonParam);
                JObject jo = (JObject)JsonConvert.DeserializeObject(responseString);


                if (jo["code"].ToString() == "1")
                {
                    kinfo kinfo = JsonConvert.DeserializeObject<kinfo>(responseString);
                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", id, "", DateTime.Now, jo["code"].ToString(), jo["message"].ToString(), "知识下架接口", "", "推送成功数1");
                    object objres = DbHelperSQL.GetSingle(strSql);
                    return Success("推送成功");
                }
                else
                {
                    string error = "";

                    string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", "", paras.ToJson(), DateTime.Now, jo["code"].ToString(), jo["message"].ToString(), "知识下架接口", error, "推送成功数1");
                    object objres = DbHelperSQL.GetSingle(strSql);
                    LogFactory.GetLogger("111").Warn("知识下架接口" + error);
                    return Error("推送失败---" + error);

                }

            }
            else
            {
                return Error("推送失败知识不存在");
            }

        }


        /// <summary>
        /// 知识提问接口
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult transmit_kinfo_quiz()
        {
            StreamReader reader = new StreamReader(System.Web.HttpContext.Current.Request.InputStream);
            var postString = reader.ReadToEnd();
            JObject paras = null;
            paras = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(postString);
            var txnBodyCom = paras["paras"].ToString();
            var result = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(txnBodyCom);
            if (result["KINFO_ID"] == null)
            {
                var obj1 = new
                {
                    code = "0",
                    message = "KINFO_ID不能为空"
                };
                return Content(obj1.ToJson());
            }
            if (string.IsNullOrEmpty(result["KINFO_KNAME"].ToString()))
            {
                var obj1 = new
                {
                    code = "0",
                    message = "KINFO_KNAME不能为空"
                };
                return Content(obj1.ToJson());
            }
            if (string.IsNullOrEmpty(result["KINFO_KCONTENT"].ToString()))
            {
                var obj1 = new
                {
                    code = "0",
                    message = "KINFO_KCONTENT不能为空"
                };
                return Content(obj1.ToJson());
            }

            using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
            {
                Model.T_Sys_kinfoQuestions model = new Model.T_Sys_kinfoQuestions();
                model.KINFO_ID = result["KINFO_ID"].ToString();
                model.KINFO_KNAME = result["KINFO_KNAME"].ToString();
                model.KINFO_KCONTENT = result["KINFO_KCONTENT"].ToString();
                model.F_CreateTime = DateTime.Now;
                model.F_State = 0;
                model.F_IsDelete = 0;
                int n = new BLL.T_Sys_kinfoQuestions().Add(model);
                if (n > 0)
                {

                    var obj1 = new
                    {
                        code = "1",
                        message = "推送成功"
                    };
                    trans.Complete();
                    return Content(obj1.ToJson());

                }
                else
                {
                    var obj1 = new
                    {
                        code = "0",
                        message = "推送失败"
                    };
                    trans.Complete();
                    return Content(obj1.ToJson());
                }

            }

        }




        public class transmit_kinfo_answer
        {
            /// <summary>
            /// 知识唯一标识
            /// </summary>
            public string KINFO_ID { set; get; }
            /// <summary>
            /// 知识标题
            /// </summary>
            public string KINFO_KNAME { set; get; }
            /// <summary>
            /// 知识内容
            /// </summary>
            public string KINFO_KCONTENT { set; get; }
            /// <summary>
            /// 生效时间
            /// </summary>
            public string KINFO_BEGINDATE { set; get; }
            /// <summary>
            /// 失效时间
            /// </summary>
            public string KINFO_DISABLEDATE { set; get; }
        }
        /// <summary>
        /// </summary>
        /// 知识答复接口
        /// <param name="sender"></param>
        /// <param name="e"></param>
        [Authority]
        public ActionResult kinfo_answer(string KINFO_KNAME,
         string KINFO_KCONTENT, DateTime? KINFO_BEGINDATE, DateTime? KINFO_DISABLEDATE,
         int id = 0)
        {

            Model.T_Sys_kinfoQuestions model = new BLL.T_Sys_kinfoQuestions().GetModel(id);
            if (model != null)
            {
                transmit_kinfo_answer paras = new transmit_kinfo_answer();

                paras.KINFO_ID = model.KINFO_ID;
                paras.KINFO_KNAME = KINFO_KNAME;
                paras.KINFO_KCONTENT = KINFO_KCONTENT;
                if (KINFO_BEGINDATE != null)
                    paras.KINFO_BEGINDATE = KINFO_BEGINDATE.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    return Error("请选择生效时间");
                if (KINFO_DISABLEDATE != null)
                    paras.KINFO_DISABLEDATE = KINFO_DISABLEDATE.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    paras.KINFO_DISABLEDATE = "";

                model.ReKINFO_KNAME = KINFO_KNAME;
                model.ReKINFO_KCONTENT = KINFO_KCONTENT;
                model.KINFO_BEGINDATE = KINFO_BEGINDATE;
                model.KINFO_DISABLEDATE = KINFO_DISABLEDATE;
                model.ReUser = User.F_UserCode;
                model.F_State = 1;
                bool n = new BLL.T_Sys_kinfoQuestions().Update(model);
                if (n)
                {
                    string content = $"{User.F_UserName}({User.F_UserCode })答复知识库{  model.ReKINFO_KNAME }";
                    string Operation = OperationLogController
                        .AddOperationList(content, User.F_UserCode, Common.DTRequest.GetIP(), 3, 4594, model.F_ID );

                    string jsonParam = "paras=" + paras.ToJson() + "&message=知识答复接口&url=http://59.227.93.14:9000/share/zsdfjk";
                    var responseString = HttpMethods.HttpPost(FrontUrl+"/Affairs/Kinforeceive_Push", jsonParam);
                    bendiack jo = JsonConvert.DeserializeObject<bendiack>(responseString);
                    if (jo.state == "success")
                        return Success("知识答复成功");
                    else
                        return Error("知识答复失败");


                }
                else
                {
                    return Error("答复失败");
                }
            }
            else
            {
                return Error("推送失败知识不存在");
            }

        }


        public class transmit_kinfo_refuse
        {
            /// <summary>
            /// 知识唯一标识
            /// </summary>
            public string KINFO_ID { set; get; }
            /// <summary>
            /// 知识拒绝答复原因
            /// </summary>
            public string KINFO_REASON { set; get; }

        }
        /// <summary>
        /// </summary>
        /// 知识拒绝答复接口
        /// <param name="sender"></param>
        /// <param name="e"></param>
        [Authority]
        public ActionResult kinfo_refuse(string KINFO_REASON,

         int id = 0)
        {

            Model.T_Sys_kinfoQuestions model = new BLL.T_Sys_kinfoQuestions().GetModel(id);
            if (model != null)
            {
                transmit_kinfo_refuse paras = new transmit_kinfo_refuse();

                paras.KINFO_ID = model.KINFO_ID;
                paras.KINFO_REASON = KINFO_REASON;
                model.F_State = 2;
                model.KINFO_REASON = KINFO_REASON;
                model.ReUser = User.F_UserCode;


                bool n = new BLL.T_Sys_kinfoQuestions().Update(model);
                if (n)
                {
                    string content = $"{User.F_UserName}({User.F_UserCode })拒绝答复知识库{  model.ReKINFO_KNAME }";
                    string Operation = OperationLogController
                        .AddOperationList(content, User.F_UserCode, Common.DTRequest.GetIP(), 3, 4594, model.F_ID);

                    string jsonParam = "paras=" + paras.ToJson() + "&message=知识拒绝答复接口&url=http://59.227.93.14:9000/share/zsjjdfjk";
                    var responseString = HttpMethods.HttpPost(FrontUrl+"/Affairs/Kinforeceive_Push", jsonParam);
                    bendiack jo = JsonConvert.DeserializeObject<bendiack>(responseString);
                    if (jo.state == "success")
                        return Success("知识答复成功");
                    else
                        return Error("知识答复失败");


                }
                else
                {
                    return Error("答复失败");
                }

            }
            else
            {
                return Error("推送失败知识不存在");
            }

        }

        /// <summary>
        /// 知识审核退回接口
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult transmit_kinfo_back()
        {
            StreamReader reader = new StreamReader(System.Web.HttpContext.Current.Request.InputStream);
            var postString = reader.ReadToEnd();
            JObject paras = null;
            paras = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(postString);
            var txnBodyCom = paras["paras"].ToString();
            var result = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(txnBodyCom);
            if (result["KINFO_ID"] == null)
            {
                var obj1 = new
                {
                    code = "0",
                    message = "KINFO_ID不能为空"
                };
                return Content(obj1.ToJson());
            }
            if (string.IsNullOrEmpty(result["KINFO_KNAME"].ToString()))
            {
                var obj1 = new
                {
                    code = "0",
                    message = "KINFO_KNAME不能为空"
                };
                return Content(obj1.ToJson());
            }
            if (string.IsNullOrEmpty(result["KINFO_KCONTENT"].ToString()))
            {
                var obj1 = new
                {
                    code = "0",
                    message = "KINFO_KCONTENT不能为空"
                };
                return Content(obj1.ToJson());
            }

            using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
            {
                Model.T_Sys_kinfoQuestions model = new Model.T_Sys_kinfoQuestions();
                model.KINFO_ID = result["KINFO_ID"].ToString();
                model.KINFO_KNAME = result["KINFO_KNAME"].ToString();
                model.KINFO_KCONTENT = result["KINFO_KCONTENT"].ToString();
                model.KINFO_KCONTENT = result["KINFO_KCONTENT"].ToString();
                model.ReKINFO_REASON = result["KINFO_REASON"].ToString();
                model.F_CreateTime = DateTime.Now;
                model.F_State = 3;
                model.F_IsDelete = 0;
                int n = new BLL.T_Sys_kinfoQuestions().Add(model);
                if (n > 0)
                {

                    var obj1 = new
                    {
                        code = "1",
                        message = "推送成功"
                    };
                    trans.Complete();
                    return Content(obj1.ToJson());

                }
                else
                {
                    var obj1 = new
                    {
                        code = "0",
                        message = "推送失败"
                    };
                    trans.Complete();
                    return Content(obj1.ToJson());
                }

            }


        }

        /// <summary>
        /// </summary>
        /// 知识重新答复接口
        /// <param name="sender"></param>
        /// <param name="e"></param>
        [Authority]
        public ActionResult kinfo_againanswer(string KINFO_KNAME,
         string KINFO_KCONTENT, DateTime? KINFO_BEGINDATE, DateTime? KINFO_DISABLEDATE,
         int id = 0)
        {

            Model.T_Sys_kinfoQuestions model = new BLL.T_Sys_kinfoQuestions().GetModel(id);
            if (model != null)
            {
                transmit_kinfo_answer paras = new transmit_kinfo_answer();

                paras.KINFO_ID = model.KINFO_ID;
                paras.KINFO_KNAME = KINFO_KNAME;
                paras.KINFO_KCONTENT = KINFO_KCONTENT;
                if (KINFO_BEGINDATE != null)
                    paras.KINFO_BEGINDATE = KINFO_BEGINDATE.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    return Error("请选择生效时间");
                if (KINFO_DISABLEDATE != null)
                    paras.KINFO_DISABLEDATE = KINFO_DISABLEDATE.Value.ToString("yyyy-MM-dd HH:mm:ss");
                else
                    paras.KINFO_DISABLEDATE = "";

                model.ReKINFO_KNAME = KINFO_KNAME;
                model.ReKINFO_KCONTENT = KINFO_KCONTENT;
                model.KINFO_BEGINDATE = KINFO_BEGINDATE;
                model.KINFO_DISABLEDATE = KINFO_DISABLEDATE;
                model.ReUser = User.F_UserCode;
                model.F_State = 4;
                bool n = new BLL.T_Sys_kinfoQuestions().Update(model);
                if (n)
                {
                    string content = $"{User.F_UserName}({User.F_UserCode })重新答复知识库{  model.ReKINFO_KNAME }";
                    string Operation = OperationLogController
                        .AddOperationList(content, User.F_UserCode, Common.DTRequest.GetIP(), 3, 4594, model.F_ID);

                    string jsonParam = "paras=" + paras.ToJson() + "&message=知识重新答复接口&url=http://59.227.93.14:9000/share/zscxdfjk";
                    var responseString = HttpMethods.HttpPost(FrontUrl+"/Affairs/Kinforeceive_Push", jsonParam);
                    bendiack jo = JsonConvert.DeserializeObject<bendiack>(responseString);
                    if (jo.state == "success")
                        return Success("知识答复成功");
                    else
                        return Error("知识答复失败");


                }
                else
                {
                    return Error("答复失败");
                }
            }
            else
            {
                return Error("推送失败知识不存在");
            }

        }
        /// <summary>
        /// 知识库列表
        /// </summary>
        /// <param name="isdc"></param>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetKinfoList(int isdc = 0)
        {
            DataTable dt = new DataTable();
            string sql = " and F_IsDelete=0";
            #region 参数

            string starttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("strendtime"));
            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;
            string title = HttpUtility.UrlDecode(RequestString.GetQueryString("title"));
            if (title.Trim() != "" && title != "undefined")
            {
                sql += " and (KINFO_KNAME like '%" + title + "%'or ReKINFO_KNAME like '%" + title + "%'  )";
            }
            string content = HttpUtility.UrlDecode(RequestString.GetQueryString("content"));
            if (content.Trim() != "" && content != "undefined")
            {
                sql += " and (KINFO_KCONTENT like '%" + title + "%'or ReKINFO_KCONTENT like '%" + title + "%'  )";
            }

            int state = RequestString.GetInt("state", -1);
            if (state > -1)
            {
                sql += " and F_State ='" + state + "'";
            }
            if (starttime.Trim() != "" && starttime != "undefined")
            {
                sql += " and F_CreateTime >='" + starttime + "'";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and F_CreateTime <='" + strendtime + "'";
            }

            #endregion
            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Sys_kinfoQuestions a WITH(NOLOCK)",
                "F_Id",
                "*",
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);


            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };
            return Content(obj.ToJson());
        }
        /// <summary>
        /// 详情
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetKinfo(int id)
        {
            var model = new BLL.T_Sys_kinfoQuestions().GetModel(id);

            if (model != null)
            {
                return Success("获取成功", model);
            }

            else
            {
                return Error("获取失败");
            }


        }

        public ActionResult Kinforeceive_Push(string paras, string url, string message, string WorkOrderId = "")
        {
            string token = GetTokenzsk();
            if (string.IsNullOrEmpty(token))
                return Error("token获取失败");
            string jsonParam = "access_token=" + token + "&paras=" + paras.ToJson();
            // string jsonParam = "paras=" + paras;
            var responseString = HttpMethods.HttpPost(url, jsonParam);
            JObject jo = (JObject)JsonConvert.DeserializeObject(responseString);
            if (jo["code"].ToString() == "1")
            {

                string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", WorkOrderId, paras, DateTime.Now, jo["code"].ToString(), jo["message"].ToString(), message, "", "");
                object objres = DbHelperSQL.GetSingle(strSql);
                return Success("成功");
            }
            else
            {
                string strSql = string.Format(@"INSERT INTO T_Sys_PushMsg ( [WorkOrderId], [Conent], [CreatTime], [Code], [Message], [Title], [ErrorObjs], [Remarks]) 
                   values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ;select @@IDENTITY ", WorkOrderId, paras, DateTime.Now, jo["code"].ToString(), jo["message"].ToString(), message, jo["message"].ToString(), "");
                object objres = DbHelperSQL.GetSingle(strSql);
                return Error(message + jo["message"].ToString());
            }
        }
        public string kinfo_upload(string pathUrl, string newFileName, string path)
        {
            //文件下载地址
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(pathUrl);
                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                Stream responseStream = response.GetResponseStream();
                string Currentpath = System.Web.HttpContext.Current.Server.MapPath("..") + path;
                // 如果不存在就创建file文件夹
                if (!Directory.Exists(Currentpath))
                {
                    if (Currentpath != null) Directory.CreateDirectory(Currentpath);
                }
                Stream stream = new FileStream(Currentpath + newFileName, FileMode.Create);
                byte[] bArr = new byte[1024];
                int size = responseStream.Read(bArr, 0, bArr.Length);
                while (size > 0)
                {
                    stream.Write(bArr, 0, size);
                    size = responseStream.Read(bArr, 0, bArr.Length);
                }
                stream.Close();
                responseStream.Close();

                return "1";
            }
            catch (Exception e)
            {
                LogFactory.GetLogger("11").Warn(e.Message);
                return e.Message;
            }
        }
        #endregion


 

        public class dy_jjdb
        {

            /// <summary>
            /// 行政区划代码
            /// </summary>
            public string xzqhdm { set; get; }

            /// <summary>
            /// 接警单位代码
            /// </summary>
            public string jjdwdm { set; get; }

            /// <summary>
            /// 接警单编号
            /// </summary>
            public string jjdbh { set; get; }

            /// <summary>
            /// 接警员编号
            /// </summary>
            public string jjybh { set; get; }

            /// <summary>
            /// 接警员姓名
            /// </summary>
            public string jjyxm { set; get; }

            /// <summary>
            /// 报警时间
            /// </summary>
            public DateTime? bjsj { set; get; }

            /// <summary>
            /// 报警电话
            /// </summary>
            public string bjdh { set; get; }

            /// <summary>
            /// 报警人名称
            /// </summary>
            public string bjrmc { set; get; }

            /// <summary>
            /// 联系电话
            /// </summary>
            public string lxdh { set; get; }

            /// <summary>
            /// 警情地址
            /// </summary>
            public string jqdz { set; get; }

            /// <summary>
            /// 报警内容
            /// </summary>
            public string bjnr { set; get; }

            /// <summary>
            /// 管辖单位代码
            /// </summary>
            public string gxdwdm { set; get; }

            /// <summary>
            /// 警情类别代码
            /// </summary>
            public string jqlbdm { set; get; }

            /// <summary>
            /// 警情类型代码
            /// </summary>
            public string jqlxdm { set; get; }

            /// <summary>
            /// 警情细类代码
            /// </summary>
            public string jqxldm { set; get; }

            /// <summary>
            /// 警情子类代码
            /// </summary>
            public string jqzldm { set; get; }

            /// <summary>
            /// 入库时间
            /// </summary>
            public DateTime? rksj { set; get; }

            /// <summary>
            /// 数据更新时间
            /// </summary>
            public DateTime? tbsj { set; get; }


        }

        /// <summary>
        /// 110的数据调这个接口添加到本地的数据
        /// </summary>
        /// <param name="jjdb"></param>
        /// <returns></returns>


        /// <summary>
        /// 发送短信gei 默认
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="WorkOrderId"></param>
        /// <returns></returns>
        public bool SendDx(string workorderid)
        {
            //string phone = "15803722599";


            string phone = Configs.GetValue("SendToPhone");

            string mag = "[\"" + workorderid + "\"]";
            string v = SmsNewController.AddSmS(0, "你有新工单:工单号" + workorderid + "，请及时查收处理。",
                phone, "681240888655478784", mag,
          "");
            if (v == string.Empty)
                return true;
            else
                return false;

        }
        [AllowAnonymous]
        public ActionResult AddExternalOrder(dy_jjdb jjdb)
        {
            Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = new Model.T_Bus_WorkOrder();

            string dtsql = " select * from dy_jjdb where jjdbh='" + jjdb.jjdbh + "'";
            DataTable dtquery = DbHelperSQL.Query(dtsql).Tables[0];
            if (dtquery != null && dtquery.Rows.Count > 0)
            {
                var obje = new
                {
                    state = "success",
                    message = "已存在"

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


            using (TransactionScope trans = new TransactionScope())
            {
                string creattime = DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00";
                string endtime = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59";
                modelT_Bus_WorkOrder.F_WorkOrderId = workorderBLL.GetNewWorkOrderID(Convert.ToInt32(4606), 0, creattime, endtime);

                modelT_Bus_WorkOrder.F_WorkState = 1;
                modelT_Bus_WorkOrder.F_InfoSource = 4606;//信息来源
                                                         //   modelT_Bus_WorkOrder.F_InfoType = type;//信息类别
                modelT_Bus_WorkOrder.F_CusName = jjdb.bjrmc;//投诉人姓名
                modelT_Bus_WorkOrder.F_CusPhone = jjdb.lxdh;//来电号码
                modelT_Bus_WorkOrder.F_ComTitle = "110推送工单";//标题
                modelT_Bus_WorkOrder.F_ComContent = jjdb.bjnr;//情况摘要（投诉内容）

             //   modelT_Bus_WorkOrder.F_Inlet = 1;
                modelT_Bus_WorkOrder.F_SourceAddress = jjdb.jqdz;//jingqing地址

              //  modelT_Bus_WorkOrder.F_PhoneType = "110";

                
                 
                try
                {
                    FileLog.Info("AddExternalOrder:" + modelT_Bus_WorkOrder.F_WorkOrderId + "/" + jjdb.jqzldm);


                    var objid = DbHelperSQL.GetSingle("select top 1  F_Id from T_EventType where F_bm='" + jjdb.jqzldm + "' order by F_level desc");

                    FileLog.Info("AddExternalOrder:" + modelT_Bus_WorkOrder.F_WorkOrderId + "/" + objid);
                    if (objid != null)
                    {
                        modelT_Bus_WorkOrder.F_InfoConBigType = Convert.ToInt32(objid.ToString());
                    }
                }
                catch (Exception e)
                {
                    FileLog.Info(jjdb.jqzldm);

                    FileLog.Info("AddExternalOrder" + e.ToJson());

                }

 

                modelT_Bus_WorkOrder.F_IsProtect = 0;
                modelT_Bus_WorkOrder.F_CreateTime = jjdb.bjsj;

                modelT_Bus_WorkOrder.F_CreateUser = jjdb.jjyxm + "-" + jjdb.jjybh;
                modelT_Bus_WorkOrder.F_OrderSign = 2;

                 int a = workorderBLL.Add(modelT_Bus_WorkOrder);
            
               // string sql = "";
                #region 插入操作记录
                BLL.T_Bus_Operation operBLL = new BLL.T_Bus_Operation();
                Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                oper.F_State = modelT_Bus_WorkOrder.F_WorkState;
                oper.F_Message = "110" + " 登记并提交了工单，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId;
                oper.F_CreateUser = "110";
                oper.F_CreateTime = DateTime.Now;
                oper.F_IsDelete = 0;

                operBLL.Add(oper);

                string strSql = string.Format(@"INSERT INTO dy_jjdb ( [xzqhdm]      ,[jjdwdm]      ,[jjdbh]      ,[jjybh]      ,[jjyxm]      ,[bjsj]      ,[bjdh]      ,[bjrmc]      ,[lxdh]      ,[jqdz]      ,[bjnr]      ,[gxdwdm]      ,[jqlbdm]
      ,[jqlxdm]      ,[jqxldm]      ,[jqzldm]      ,[rksj]      ,[tbsj]      ,[workorderId])                    values   ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}') ;select @@IDENTITY ", jjdb.xzqhdm, jjdb.jjdwdm, jjdb.jjdbh, jjdb.jjybh, jjdb.jjyxm, jjdb.bjsj, jjdb.bjdh, jjdb.bjrmc, jjdb.lxdh, jjdb.jqdz, jjdb.bjnr, jjdb.gxdwdm, jjdb.jqlbdm, jjdb.jqlxdm, jjdb.jqxldm, jjdb.jqzldm, jjdb.rksj, jjdb.tbsj, modelT_Bus_WorkOrder.F_WorkOrderId
                   );
                object objres = DbHelperSQL.GetSingle(strSql);



                #endregion
                trans.Complete();
            }
            var obj = new
            {
                state = "success",
                message = "成功",
                strWrkOrdr_ID = modelT_Bus_WorkOrder.F_WorkOrderId,


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



        }


        [Authority]
        ///12345的工单 推送到110那
        public ActionResult PushWorkOrder(string workorderid, string content, int limittime = 7)
        {
            int maindeptid = Convert.ToInt32( Configs.GetValue("maindeptid"));

            string url = Configs.GetValue("PushAyOrderUrl");
            //  string url = "http://localhost:51927/api/BusWorkorder/update";

            Model.T_Bus_WorkOrder oldmodel = new BLL.T_Bus_WorkOrder().GetModel(workorderid);

            string sql = " select count(1) from dy_jjdb where workorderId='" + workorderid + "'";


            int count = Convert.ToInt32(DbHelperSQL.GetSingle(sql));
            if (count > 0)
            {
                return Error("已存在");
            }
            else
            {
                Dictionary<string, object> dic = new Dictionary<string, object>();

                dic.Add("F_WorkOrderId", oldmodel.F_WorkOrderId);

                dic.Add("F_IsProtect", oldmodel.F_IsProtect);
                dic.Add("F_Level", oldmodel.F_Level);
                dic.Add("F_LimitTime", oldmodel.F_LimitTime);
                dic.Add("F_CusName", oldmodel.F_CusName);
                dic.Add("F_CusPhone", oldmodel.F_CusPhone);
                dic.Add("F_ComContent", oldmodel.F_ComContent);
                dic.Add("F_SourceAddress", oldmodel.F_SourceAddress);
                dic.Add("F_CreateUser", oldmodel.F_CreateUser);
                dic.Add("F_CreateTime", oldmodel.F_CreateTime);

                dic.Add("CASE_TITLE", oldmodel.F_ComTitle);

                var result = Post(url, dic);
                goback workorders = JsonConvert.DeserializeObject<goback>(result);
                if (workorders.code == "error")
                {
                    return Error("推送失败" + workorders.message);
                }
                string resdatetime = "";
                if (limittime > 0)
                {
                    string resdate = DateTime.Now.Date.ToString("yyyy-MM-dd");
                    DataTable dt = DbHelperSQL.Query("select top " + limittime + " F_OffDate from  T_Sys_WorkOFFDays  with(nolock) where F_OffState = 1   and F_OffDate>'" + resdate + "' order by F_OffDate").Tables[0];
                    resdatetime = dt.Rows[dt.Rows.Count - 1]["F_OffDate"].ToString();
                }
                resdatetime = Convert.ToDateTime(resdatetime).ToString("yyyy-MM-dd") + " 23:59:59 ";
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = new Model.T_Bus_AssignedInfo();
                modelT_Bus_AssignedInfo.F_WorkOrderId = oldmodel.F_WorkOrderId;
                modelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(resdatetime);
                modelT_Bus_AssignedInfo.F_MainDeptId = maindeptid;
                modelT_Bus_AssignedInfo.F_OtherDeptIds = "";//协办单位id
                modelT_Bus_AssignedInfo.F_AssignedOpinion = "";//交办意见
                modelT_Bus_AssignedInfo.F_State = 1;//0草稿  1正式
                modelT_Bus_AssignedInfo.F_CreateUser = "110平台";
                modelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                modelT_Bus_AssignedInfo.F_IsDelete = 0;
                modelT_Bus_AssignedInfo.F_IsOverdue = 0;
                modelT_Bus_AssignedInfo.F_IsSure = 1;
                modelT_Bus_AssignedInfo.F_IsReload = 0;
                modelT_Bus_AssignedInfo.F_SureUser = "110平台";
                modelT_Bus_AssignedInfo.F_SureTime = DateTime.Now;
                modelT_Bus_AssignedInfo.F_IsNext = 0;
                modelT_Bus_AssignedInfo.F_TimeResp = assignBLL.GetRepTimly(DateTime.Now);//及时查收时间点
                modelT_Bus_AssignedInfo.F_Id = assignBLL.Add(modelT_Bus_AssignedInfo);
                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                keyValuePairs.Add("F_AssignUser", 8000);
  
                keyValuePairs.Add("F_AssignTime", DateTime.Now);
            
                keyValuePairs.Add("F_MainDeptId", maindeptid);
                oldmodel.F_MainDeptId = 1600;
                keyValuePairs.Add("F_WorkState", 4);

                keyValuePairs.Add("F_OrderSign", 1);

                oldmodel.F_WorkState = 4;
                workorderBLL.UpdateWorkOrder(oldmodel.F_Id, keyValuePairs);
                Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                oper.F_WorkOrderId = oldmodel.F_WorkOrderId;
                oper.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                string userinfo = User.F_UserName + "(" + User.F_UserCode + ")";
                oper.F_Message = userinfo + " 推送了工单";
                oper.F_CreateUser = User.F_UserCode;
                oper.F_CreateTime = DateTime.Now;
                oper.F_IsDelete = 0;
                operBLL.Add(oper);
                return Success("推送成功");
            }

        }
        public static string Post(string url, Dictionary<string, object> dic)
        {
            string result = "";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            #region 添加Post 参数
            StringBuilder builder = new StringBuilder();
            int i = 0;
            foreach (var item in dic)
            {
                if (i > 0)
                    builder.Append("&");
                builder.AppendFormat("{0}={1}", item.Key, item.Value);
                i++;
            }
            byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
            req.ContentLength = data.Length;
            using (Stream reqStream = req.GetRequestStream())
            {
                reqStream.Write(data, 0, data.Length);
                reqStream.Close();
            }
            #endregion
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            Stream stream = resp.GetResponseStream();
            //获取响应内容
            using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
            {
                result = reader.ReadToEnd();
            }
            return result;
        }
        public class Bus_WorkOrder
        {

            public string F_WorkOrderId
            { set; get; }
            /// <summary>
            /// 公开/保密（0公开1保密）
            /// </summary>
            public int? F_IsProtect
            { set; get; }
            /// <summary>
            /// 紧急程度(1一般2紧急)
            /// </summary>
            public int? F_Level
            { set; get; }
            /// <summary>
            /// 办理时限
            /// </summary>
            public DateTime? F_LimitTime
            { set; get; }
            /// <summary>
            /// 签收时限
            /// </summary>
            public DateTime? TSIGNTIME_BF
            { set; get; }
            /// <summary>
            /// 退回时限
            /// </summary>
            public DateTime? TBACKTIME_BF
            { set; get; }
            /// <summary>
            /// 退回原因
            /// </summary>
            public string BACK_REASON
            { set; get; }
            /// <summary>
            /// 延期天数
            /// </summary>
            public int? APPLY_DELAYNUM
            { set; get; }
            /// <summary>
            /// 延期原因
            /// </summary>
            public string APPLY_REASON
            { set; get; }
            /// <summary>
            /// 反馈结果
            /// </summary>
            public string FINISH_RESULT
            { set; get; }
            /// <summary>
            /// 催单内容
            /// </summary>
            public string SUPPLY_CONTENT
            { set; get; }
            /// <summary>
            /// 工单附件
            /// </summary>
            public string CASE_ATTATH
            { set; get; }
            /// <summary>
            /// 反馈附件
            /// </summary>
            public string FINISH_ATTATH
            { set; get; }
            /// <summary>
            /// 反映类别
            /// </summary>
            public string CASE_ACCORD
            { set; get; }
            /// <summary>
            /// 工单标题
            /// </summary>
            public string CASE_TITLE
            { set; get; }
            /// <summary>
            /// 审核结果（0不同意1同意）
            /// </summary>
            public int? AUDIT_RESULT
            { set; get; }
            /// <summary>
            /// 审核意见
            /// </summary>
            public string AUDIT_OPINION
            { set; get; }
            /// <summary>
            /// 姓名
            /// </summary>
            public string F_CusName
            { set; get; }
            /// <summary>
            /// 联系电话
            /// </summary>
            public string F_CusPhone
            { set; get; }
            /// <summary>
            /// 内容
            /// </summary>
            public string F_ComContent
            { set; get; }
            /// <summary>
            /// 地址
            /// </summary>
            public string F_SourceAddress
            { set; get; }
            /// <summary>
            /// 创建人工号
            /// </summary>
            public string F_CreateUser
            { set; get; }
            /// <summary>
            /// 创建日期
            /// </summary>
            public DateTime? F_CreateTime
            { set; get; }
            /// <summary>
            /// 数据更新时间
            /// </summary>
            public DateTime tbsj { set; get; }


        }

        /// <summary>
        /// 服务工单推送处理结果接口
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult hbpush_case_finish(string workoderid, string sldwdm)
        {





            try
            {

           

            Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workoderid);
            if (modelT_Bus_WorkOrder == null)
            {
                var obj = new
                {
                    code = "0",
                    message = "工单不存在！"
                };
                return Content(obj.ToJson());
            }

                if (string.IsNullOrEmpty( sldwdm))
                {
                    var obj = new
                    {
                        code = "0",
                        message = "结果不能为空"
                    };
                    return Content(obj.ToJson());
                }


    

            Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workoderid);
            Model.T_Bus_Feedback modelT_Bus_Feedback = new Model.T_Bus_Feedback();
            if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo != null)
            {
                using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                {
                    #region 插入反馈记录
                    Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                    modelT_Bus_Feedback.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;//工单编号
                    modelT_Bus_Feedback.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;//交办id
                    modelT_Bus_Feedback.F_AuditPost = "";
                    modelT_Bus_Feedback.F_AuditContact = "";
                    modelT_Bus_Feedback.F_AuditUser = "";
                    modelT_Bus_Feedback.F_DealUser = "110平台";
                    modelT_Bus_Feedback.F_Result = sldwdm;
                    #region 20200114新增字段 zhengbingbing

                    modelT_Bus_Feedback.F_ProSituation = "";//处理情况/方案/进程
                    modelT_Bus_Feedback.F_IsProtect = modelT_Bus_WorkOrder.F_IsProtect;
                    modelT_Bus_Feedback.F_DealUserContact = "";//承办人联系方式
                    DateTime contime = DateTime.Now;
                    modelT_Bus_Feedback.F_IsProResult = 1;
                    #endregion


                    modelT_Bus_Feedback.F_IsAudit = 0;
                    modelT_Bus_Feedback.F_IsDelete = 0;
                    modelT_Bus_Feedback.F_CreateUser = "110平台";
                    modelT_Bus_Feedback.F_CreateTime = DateTime.Now;//办理时间
                    modelT_Bus_Feedback.F_CreateDeptId = 1600;//办理部门
                    modelT_Bus_Feedback.F_IsFeedEnd = 1;
                    modelT_Bus_Feedback.F_State = 1;
                    new BLL.T_Bus_Feedback().Add(modelT_Bus_Feedback);
                    #endregion
                    if (modelT_Bus_Feedback != null && modelT_Bus_Feedback.F_State == 1)
                    {
                        string typemsg = "办理";
                        #region 保存工单信息
                        keyValuePairs.Add("F_WorkState", 6);
                        keyValuePairs.Add("F_Result", modelT_Bus_Feedback.F_Result);
                        keyValuePairs.Add("F_DealDeptId", 1600);
                        modelT_Bus_WorkOrder.F_DealDeptId = 1600;
                        keyValuePairs.Add("F_DealUser", "110平台");
                        keyValuePairs.Add("F_DealTime", DateTime.Now);
                        keyValuePairs.Add("F_ToBereply", 1);
                        keyValuePairs.Add("F_IsOverdue", 0);
                        keyValuePairs.Add("F_IsProResult", 1);
                        workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs);
                        #endregion
                        #region 保存交办信息
                        modelT_Bus_AssignedInfo.F_FeedbackTime = DateTime.Now;
                        modelT_Bus_AssignedInfo.F_IsOverdue = 0;
                        assignBLL.Update(modelT_Bus_AssignedInfo);
                        #endregion

                        typemsg = "主办";
                        #region 插入操作记录
                        Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                        oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                        oper.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                        oper.F_State = modelT_Bus_WorkOrder.F_WorkState;
                            string userinfo = "110平台";// -" + sldwdm;
                        oper.F_Message = userinfo + " " + typemsg + "了工单";
                        oper.F_CreateUser = userinfo;
                        oper.F_CreateTime = DateTime.Now;
                        oper.F_IsDelete = 0;
                        operBLL.Add(oper);
                        //推送消息表
                        msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, modelT_Bus_WorkOrder.F_CreateUser, userinfo, (int)EnumSmsType.workorder);
                        #endregion
                    }

                    trans.Complete();
                }
                var obj = new
                {
                    code = "1",
                    message = "反馈成功！"
                };

                return Content(obj.ToJson());

            }
            else
            {
                var obj = new
                {
                    code = "0",
                    message = "工单不存在！"
                };
                return Content(obj.ToJson());
            }
            }
            catch (Exception e)
            {
                LogFactory.GetLogger("推送结果的").Error(e.ToString());
                throw;
               
            }
        }




    }
}
