using CallCenter.Utility;

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 Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
using System.Web;
using System.Web.Mvc;

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

        // GET: WorkOrder

        //工单状态：0新工单 1待交办 2待查收 3退回审核中 4办理中 5延时审核中 6已办理 7已回访 8重办中 9已结案
        //操作按钮：1查询 2编辑 3删除 4提交 5交办 6领导批示 7市长指示 8督办 9监察 10收回 11查收 12退回申请 
        //          13办理 14延时申请 15退回审核 16回访 17延时审核 18重办 19结案 20导出 21回退 22强制结案

        private information.InternalMessagesController msg = new information.InternalMessagesController();
        private BLL.T_Sys_UserAccount userBLL = new BLL.T_Sys_UserAccount();
        private BLL.T_Bus_WorkOrder workorderBLL = new BLL.T_Bus_WorkOrder();
        private BLL.T_Bus_AssignedInfo assignBLL = new BLL.T_Bus_AssignedInfo();
        private BLL.T_Bus_AssignedItemInfo assignItemBLL = new BLL.T_Bus_AssignedItemInfo();
        private BLL.T_Bus_Operation operBLL = new BLL.T_Bus_Operation();
        private BLL.T_Sys_SystemConfig configBll = new BLL.T_Sys_SystemConfig();
        private BLL.T_Bus_RemindRecord remindBLL = new BLL.T_Bus_RemindRecord();
        private BLL.T_Bus_Feedback feedbackBLL = new BLL.T_Bus_Feedback();
        private readonly static object _MyLock = new object();
        #region 获取工单
        /// <summary>
        /// 获取工单列表
        /// </summary>
        /// <returns></returns>

        public ActionResult GetList(int isdc = 0)
        {
            DataTable dt = new DataTable();
            string sql = " and F_IsDelete=0 ";
            string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
            string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
            int islike = RequestString.GetInt("islike", 1);
            string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
            string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
            string splituser = HttpUtility.UrlDecode(RequestString.GetQueryString("splituser"));
            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
            string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));
            string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));
            string strddusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("ddusercode"));//调度员
            //调度员
            int isproresult = RequestString.GetInt("isproresult", 0);
            int source = RequestString.GetInt("source", 0);
            int keyid = RequestString.GetInt("keyid", 0);
            int type = RequestString.GetInt("type", 0);
            int bigtype = RequestString.GetInt("bigtype", 0);
            int smalltype = RequestString.GetInt("smalltype", 0);
            int sourcearea = RequestString.GetInt("sourcearea", 0);
            int deptid = RequestString.GetInt("deptid", 0);
            string myd = HttpUtility.UrlDecode(RequestString.GetQueryString("myd"));
            int zdpy = RequestString.GetInt("zdpy", 0);
            int smpy = RequestString.GetInt("smpy", 0);
            int dealtype = RequestString.GetInt("dealtype", -1);
            int issend = RequestString.GetInt("issend", -1);
            int deptlevel = RequestString.GetInt("deptlevel", 0);
            int dbgd = RequestString.GetInt("dbgd", 0);
            int dbdata = RequestString.GetInt("dbdata", 0);
            int workordertype = RequestString.GetInt("workordertype", -1);
            int IsRelease = RequestString.GetInt("IsRelease", 0);

            int dbdata2 = RequestString.GetInt("dbdata2", 0);
            int issatisfie = RequestString.GetInt("issatisfie", -1);
            string assignUser = HttpUtility.UrlDecode(RequestString.GetQueryString("assignUser"));
           
            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;
            string dealstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("dealstarttime"));
            string dealstrendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("dealstrendtime"));
            string Result = HttpUtility.UrlDecode(RequestString.GetQueryString("Result"));
            int isopen = RequestString.GetInt("isopen", -1);//是否公开
            if (isopen > -1)
                sql += " and isnull(F_IsOpen,0) =" + isopen;

            if (IsRelease>0)
            {if (IsRelease==1)
                sql += " and F_IsRelease = '2'";
            else
                    sql += " and F_IsRelease = '3'";
            }
            if (assignUser.Trim() != "" && assignUser != "undefined")
            {
                sql += "and F_AssignUser='" + assignUser.Trim() + "'";
            }
          
            string assuser = HttpUtility.UrlDecode(RequestString.GetQueryString("assuser"));
            if (assuser.Trim() != "" && assuser != "undefined")
            {
                sql += " and F_AssignUser = '" + assuser + "' ";
            }
            if (dealstarttime.Trim() != "" && dealstarttime != "undefined")
            {
                if (dealstrendtime.Trim() != "" && dealstrendtime != "undefined")
                {
                    sql += " and F_DealTime  between   '" + dealstarttime +
                             "' AND  '" + dealstrendtime + "'";
                }
                else
                {
                    sql += " and F_DealTime>='" + dealstarttime + "' ";
                }
            }
            else
            {
                if (dealstrendtime.Trim() != "" && dealstrendtime != "undefined")
                {
                    sql += " and F_DealTime<='" + dealstrendtime + "' ";
                }
                }
            if (issatisfie != -1)
            {
                sql += " and  F_WorkOrderID in(select F_WorkOrderID from T_Bus_VisitResult b  WITH(NOLOCK) where F_State = 1 and F_IsDelete = 0 and F_IsSatisfie = " + issatisfie + "  and F_Id       in (select  MAX(F_Id) from T_Bus_VisitResult WITH(NOLOCK) where F_WorkOrderId in          (select F_WorkOrderId from T_Bus_VisitResult WITH(NOLOCK) where F_WorkOrderId = b.F_WorkOrderId  group by F_WorkOrderId  ) ) )";
            }
            if (workordertype>-1)
            {
                if (workordertype==0)
                {
                    sql += " and F_CallRecordId is not null  ";
                }
                else
                {
                    sql += " and F_CallRecordId is  null  ";
                }
            }
            int isbusiness = RequestString.GetInt("isbusiness", -1);

            #region sql 语句相关处理
            if (strstate.Trim() != "" && strstate != "undefined")
            {
                if (isproresult>0)
                {
                    sql += " and F_WorkState in(6,7) ";
                }
                else 
                sql += " and F_WorkState = '" + strstate.Trim() + "' ";
            }
            if (strworkid.Trim() != "" && strworkid != "undefined")
            {

                sql += " and F_WorkOrderId like '%" + strworkid + "%' ";
            }
            if (strname.Trim() != "" && strname != "undefined")
            {
                sql += " and F_CusName = '" + strname + "' ";
            }

            if (splituser.Trim() != "" && splituser != "undefined")
            {
                sql += " and F_SplitUser = '" + splituser + "' ";
            }

            if (islike > 0)
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
                }
            }
            else
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  = '" + strtel + "' or F_ConPhone like '" + strtel + "') ";
                }
            }
            int dbtype = RequestString.GetInt("dbtype", 0);
            string value1 = "";
             if (dbdata > 0)
            {
                if (deptid == 0)
                {
                    return Error("请选择部门");
                }
                string sdate = ""; string etime = "";
                if (strstarttime.Trim() == "" || strstarttime == "undefined")
                {
                    sdate = DateTime.Now.AddMonths(-1).
                   ToString("yyyy-MM") + "-21 00:00:01";

                    sql += " and F_CreateTime  between   '" + sdate + "' AND  '" + DateTime.Now.ToString("yyyy-MM") + "-20 23:59:59" + "'";
                }
                else
                {
                    sdate = strstarttime;
                    if (strendtime.Trim() == "" || strendtime == "undefined")
                    {
                        etime = DateTime.Now.ToString("yyyy-MM") + "-20 23:59:59";
                    }
                    else
                        etime = DateTime.Parse(strendtime).ToString("yyyy-MM-dd") + " 23:59:59";
                    sql += " and F_CreateTime  between   '" + sdate + "' AND  '" + etime + "'";
                }
                if (dbtype != 6)
                    sql += "and F_WorkState not in (0, 1, 11) and F_MainDeptId='" + deptid + "'";
                else
                    sql += "and F_WorkState not in (0, 1, 11)";

                if (dbtype == 1)
                {
                    sql += "and ((isnull(F_DealTime,F_CloseTime )>(select top 1 F_LimitTime from T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId = a.F_WorkOrderId  and F_State = 1 and F_IsDelete = 0 and F_IsSure<>3   ORDER BY F_Id DESC) AND F_WorkState = 9 AND F_CloseTime IS NOT NULL ) OR(isnull(F_DealTime, getdate()) > (select top 1 F_LimitTime from T_Bus_AssignedInfo WITH(NOLOCK)WHERE F_WorkOrderId = a.F_WorkOrderId  and F_State = 1 and F_IsDelete = 0 and F_IsSure <> 3   ORDER BY F_Id DESC) AND F_WorkState in(2, 4, 6, 8) ) ) ";
                }
                else if (dbtype == 2)
                {
                    sql += "and F_IsProResult =2 and F_WorkState =6 ";
                }
                else if (dbtype == 3)
                {
                    sql += "and  F_WorkOrderId  in(select F_WorkOrderId from T_Bus_Feedback where   (F_Id in (select MAX(F_Id) from T_Bus_Feedback where F_Type = 3 and F_CreateDeptId = a.F_DealDeptId and a.F_WorkState = 9  group by F_WorkOrderId) or F_Id in(select MAX(F_Id) from T_Bus_Feedback where F_Type = 3 and F_CreateDeptId = a.F_DealDeptId and F_WorkState in (2, 4, 5, 6, 8) group by F_WorkOrderId) ) ) and " +
                        "F_WorkOrderId not in(select F_WorkOrderId   from T_Bus_SubmitSuper where F_Type =3  and F_IsDelete = 0 and F_CreateTime >'" + sdate + "' ) ";
                }
              
                else if (dbtype == 6)
                {
                    sql += "and F_WorkOrderId in (select F_WorkOrderId from T_Bus_VisitResult where F_IsSatisfie=0 and F_AssignedId in (select F_Id from T_Bus_AssignedInfo where F_MainDeptId ='" + deptid + "') group by F_WorkOrderId having COUNT(1) = 1 )";
                }
            }
            else if (dbdata2 > 0)
            {
                if (deptid == 0)
                {
                    return Error("请选择部门");
                }
                int deptid2 = 0;
                if (User.F_RoleCode == "WLDW")
                    deptid2 = User.F_DeptId;
                string sdate = ""; string etime = "";
                if (strstarttime.Trim() == "" || strstarttime == "undefined")
                {
                    sdate = DateTime.Now.AddMonths(-1).
                   ToString("yyyy-MM") + "-21 00:00:01";

                    sql += " and F_CreateTime  between   '" + sdate + "' AND  '" + DateTime.Now.ToString("yyyy-MM") + "-20 23:59:59" + "'";
                }
                else
                {
                    sdate = strstarttime;
                    if (strendtime.Trim() == "" || strendtime == "undefined")
                    {
                        etime = DateTime.Now.ToString("yyyy-MM") + "-20 23:59:59";
                    }
                    else
                        etime = DateTime.Parse(strendtime).ToString("yyyy-MM-dd") + " 23:59:59";
                    sql += " and F_CreateTime  between   '" + sdate + "' AND  '" + etime + "'";
                }
                if (dbtype != 6)
                    sql += "and F_WorkState not in (0, 1, 11) and F_MainDeptId='" + deptid2 + "' " +
                        "and F_MainDeptID3='" + deptid + "'";
                else
                    sql += "and F_WorkState not in (0, 1, 11)";

                if (dbtype == 1)
                {
                    sql += "and ((isnull(F_DealTime,F_CloseTime )>(select top 1 F_LimitTime from T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId = a.F_WorkOrderId  and F_State = 1 and F_IsDelete = 0 and F_IsSure<>3   ORDER BY F_Id DESC) AND F_WorkState = 9 AND F_CloseTime IS NOT NULL ) OR(isnull(F_DealTime, getdate()) > (select top 1 F_LimitTime from T_Bus_AssignedInfo WITH(NOLOCK)WHERE F_WorkOrderId = a.F_WorkOrderId  and F_State = 1 and F_IsDelete = 0 and F_IsSure <> 3   ORDER BY F_Id DESC) AND F_WorkState in(2, 4, 6, 8) ) ) ";
                }
                else if (dbtype == 2)
                {
                    sql += "and F_IsProResult =2 and F_WorkState =6 ";
                }
                else if (dbtype == 3)
                {
                    sql += "and  F_WorkOrderId  in(select F_WorkOrderId from T_Bus_Feedback where   (F_Id in (select MAX(F_Id) from T_Bus_Feedback where F_Type = 3 and F_CreateDeptId = a.F_DealDeptId and a.F_WorkState = 9  group by F_WorkOrderId) or F_Id in(select MAX(F_Id) from T_Bus_Feedback where F_Type = 3 and F_CreateDeptId = a.F_DealDeptId and F_WorkState in (2, 4, 5, 6, 8) group by F_WorkOrderId) ) ) and " +
                        "F_WorkOrderId not in(select F_WorkOrderId   from T_Bus_SubmitSuper where F_Type =3  and F_IsDelete = 0 and F_CreateTime >'" + sdate + "' ) ";
                }
                else if (dbtype == 6)
                {
                    sql += "and F_WorkOrderId in (select F_WorkOrderId from T_Bus_VisitResult where F_IsSatisfie=0 and F_AssignedId in (select F_Id from T_Bus_AssignedInfo where F_MainDeptId ='" + deptid2 + "' ) group by F_WorkOrderId having COUNT(1) = 1 ) " +
                        "and F_MainDeptID3='" + deptid + "'";
                }
            }
           
            if (dbgd > 0)
            {
                sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_RemindRecord where F_Type=1 and F_IsDelete=0)";
            }
            string ComTitle = HttpUtility.UrlDecode(RequestString.GetQueryString("ComTitle"));
            string ComContent = HttpUtility.UrlDecode(RequestString.GetQueryString("ComContent"));
           
            if (ComTitle.Trim() != "" && ComTitle != "undefined")
            {
                sql += " and F_ComTitle like '%" + ComTitle + "%' ";
            }
            if (Result.Trim() != "" && Result != "undefined")
            {
                sql += " and F_Result like '%" + Result + "%' ";
            }
            if (ComContent.Trim() != "" && ComContent != "undefined")
            {
                sql += " and (F_ComContent like '%" + ComContent + "%' " +
                    "or F_Content like '%" + ComContent + "%'  )";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%'" +
                    " or F_Result like  '%" + strkey + "%' ) ";

            }



            if (strusercode.Trim() != "" && strusercode != "undefined")
            {//坐席
                var usercode = strusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in usercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (usercode.Length > 1)
                {
                    if (newusercode.Trim() != "" && newusercode != "undefined")
                    {
                        sql += " and F_CreateUser in (" + newusercode + ") ";
                    }
                }
                else
                {
                    if (newusercode.Trim() != "" && newusercode != "undefined")
                    {
                        sql += " and F_CreateUser = " + newusercode + " ";
                    }
                }

            }
            if (strddusercode.Trim() != "" && strddusercode != "undefined")
            {//调度员
                var ddusercode = strddusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in ddusercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');

                if (ddusercode.Length > 1)
                {
                    if (newusercode.Trim() != "" && newusercode != "undefined")
                    {
                        sql += " and F_AssignUser in (" + newusercode + ") ";
                    }
                }
                else
                {
                    if (newusercode.Trim() != "" && newusercode != "undefined")
                    {
                        sql += " and F_AssignUser = " + newusercode + " ";
                    }
                }
            }

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            string sqlwhere = ""; string value = "";
            if (keyid != 0)
            {
                sqlwhere = " INNER JOIN[GetValueId]('" + keyid + "') Value on a.F_Key = Value.F_ValueId";
                value = " INNER JOIN[GetValueId]('" + keyid + "') Value on a.F_Key = Value.F_ValueId";

            }
            else if (User.F_RoleCode == "DFZF")
            {
                sql += " and F_CreateUser ='" + User.F_UserCode + "' ";
            }
            if (type != 0)
            {
                sql += " and F_InfoType = '" + type + "' ";
            }
            if (bigtype != 0)
            {
                sql += " and F_InfoConBigType = '" + bigtype + "' ";
            }
            if (smalltype != 0)
            {
                sql += " and F_InfoConSmallType = '" + smalltype + "' ";
            }
            if (isproresult != 0)
            {
                sql += "and (F_IsSms =0 or  F_IsSms is null )";
                if (User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY"
                    || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
                {
                    if (isproresult == 2)
                    {
                        isproresult = 3;
                        sql += " and F_IsProResult = '" + 3 + "' ";
                    }
                    else
                    {
                        isproresult = 2;
                        sql += " and F_IsProResult = '" + 2 + "' ";
                    }

                }
                else
                    sql += " and F_IsProResult = '" + 2 + "' ";
            }
            if (sourcearea != 0)
            {
                sql += " and F_SourceArea = '" + sourcearea + "' ";
            }

            if (deptid != 0)
            {
                sql += " and  (F_MainDeptId = '" + deptid + "' or F_MainDeptID3='" + deptid + "')";
                #region 20190924 zhengbingbing 主办单位查询以最后办理单位为准
                #endregion
            }



            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                if (strendtime.Trim() != "" && strendtime != "undefined")
                {
                    sql += " and F_CreateTime  between   '" + strstarttime +
                             "' AND  '" + strendtime + "'";
                }
                else
                {
                    sql += " and F_CreateTime>='" + strstarttime + "' ";
                }
            }
            else
            {
                if (strendtime.Trim() != "" && strendtime != "undefined")
                {
                    sql += " and F_CreateTime<='" + strendtime + "' ";
                }
            }

            if (dealtype != -1)
            {
                sql += " and isnull(F_IsResult,0) = '" + dealtype + "' ";
            }
            if (issend != -1)
            {
                sql += " and isnull(F_IsRelease,0) = '" + issend + "' ";
            }



            #endregion

            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }

            if (strpagesize.Trim() != "")
            {
                pagesize = Convert.ToInt32(strpagesize);
            }
            //string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetOverState(F_WorkOrderId) as OverState,"
            //    + "dbo.GetDictionaryName(F_InfoSource) as SourceName,dbo.GetWorkOrderAssign(F_WorkOrderId) as DeptName ,dbo.GetLimitTime(F_WorkOrderId) as LimitTime";
            //string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName";
           
            #region 导出
            if (isdc > 0)
            {
                var top = " "; var orderby = " order by F_CreateTime";
                if (sql == " and F_IsDelete=0 ")
                {
                    top = " top 1000 "; orderby += " desc ";
                }
                //20190715调整导出字段 zhengbingbing
                //日期，工单号，诉求标题，诉求内容，承办单位，办理结果，是否满意，备注
                var dtdc = DbHelperSQL.Query(" select  F_CreateTime 日期, F_CusName 姓名, dbo.GetUserName(F_CreateUser ) 受话员姓名,F_CusPhone 手机号,F_WorkOrderId 工单号,F_ComTitle 诉求标题,F_ComContent 诉求内容,dbo.GetKeyName(F_Key,0) 反映类别一, dbo.GetKeyName(F_Key,1) 反映类别二,dbo.GetKeyName(F_Key,2) 反映类别三,dbo.GetKeyName(F_Key,3) 反映类别四,"
                    + "  dbo.GetDeptNames(F_MainDeptId ) 主办单位, "
                    + " F_Result 办理结果, "
                    + " (select top 1 (case F_IsSatisfie when 1 then'满意' when 0 then '不满意' else '未评价' end) F_Satisfie from T_Bus_VisitResult WITH(NOLOCK) where F_State = 1 and F_IsDelete = 0 and F_WorkOrderId = a.F_WorkOrderId order by F_Id desc) 是否满意 "
                    + " from T_Bus_WorkOrder a WITH(NOLOCK)" + value + value1 + " where 1=1 " + sql + orderby).Tables[0];
                var msg = new NPOIHelper().ExportToExcel("工单列表", dtdc);
                if (msg == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }
            string cols = "";
            cols = "F_Result,F_CusName,F_Unsuccessful,F_WorkOrderId,F_ComTitle,F_WorkState,F_MainDeptId,F_OtherDeptIds,F_DealTime,F_LeaveRecordId,F_CallRecordId,F_IsResult,F_IsProtect,F_IsReturn,F_CreateTime,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName,dbo.GetDeptNames(F_MainDeptId) as DeptName,F_CloseTime,F_AssignTime as AssignTime,F_LimitTime as LimitTime,(SELECT TOP 1 F_IsNext FROM T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId=a .F_WorkOrderId  and F_State = 1 and F_IsDelete = 0 and F_IsSure != 3   ORDER BY F_Id DESC) as PDState,(SELECT  COUNT(1)  FROM T_Sys_WorkOFFDays WITH(NOLOCK) WHERE F_OffState =0    AND F_OffDate >GETDATE() AND F_OffDate<a.F_LimitTime) as SYSJ ,F_IsProResult,F_ComContent,F_DealDeptId,F_Identification,F_IsRelease,F_AssignUser";

            #endregion
            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_WorkOrder a WITH(NOLOCK)" + sqlwhere+ value1,
                "F_Id",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);
            #region 声音文件和交办超时
            dt.Columns.Add("OverState", typeof(string));//超时状态
                                                        //   dt.Columns.Add("LimitTime", typeof(string));//限制时间
            dt.Columns.Add("GapTime", typeof(string));//时间差
                                                      //  dt.Columns.Add("PDState", typeof(string));//派单状态
            dt.Columns.Add("FilePath", typeof(string));//语音文件路径
            dt.Columns.Add("Buttons", typeof(object));//操作按钮
            dt.Columns.Add("Dissatisfied", typeof(object));//不满意
            dt.Columns.Add("Supervise", typeof(object));
            var configly = configBll.GetModelList(" F_ParamCode='PlayLeaveVoice' ").FirstOrDefault();
            var config = configBll.GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
            var configcs = configBll.GetModelList(" F_ParamCode='CSYJ' ").FirstOrDefault();
            
            foreach (DataRow dr in dt.Rows)
            {
                string iszbdw = "0";
                string ispd = "";
                int state = Int32.Parse(dr["F_WorkState"].ToString());
                if (state > 1)
                {
                    if (dr["F_MainDeptId"].ToString() == User.F_DeptId.ToString()) { iszbdw = "1"; }
                 
                  

                    var lt = dr["LimitTime"].ToString();//限制时间
                                                       
                    #region 超时时限
                    if (state < (int)EnumWorkState.dealed || state == (int)EnumWorkState.reload)
                    {
                        if (!string.IsNullOrWhiteSpace(lt))
                        {
                            var ltime = DateTime.Parse(lt);

                            if (ltime > DateTime.Now)
                            {
                             
                                if (dr["SYSJ"] != null && dr["SYSJ"].ToString() != "")
                                {
                                    try
                                    {
                                        ltime = ltime.AddDays(-int.Parse(dr["SYSJ"].ToString()));
                                    }
                                    catch
                                    {
                                    }
                                }
                            }
                            TimeSpan ts = ltime.Subtract(DateTime.Now);
                            double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                            if (tss < 0) { tss = -tss; }
                            string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                            if (ltime > DateTime.Now)
                            {
                                if (configcs != null)
                                {
                                    int cs = Int32.Parse(configcs.F_ParamValue);
                                    if (ts.TotalHours > cs)
                                    {
                                        dr["OverState"] = 1;
                                    }
                                    else
                                    {
                                        dr["OverState"] = 2;
                                    }
                                }
                                dr["GapTime"] = "剩余" + gshsj;
                            }
                            else
                            {
                                dr["OverState"] = 3;
                                dr["GapTime"] = "超时" + gshsj;
                            }
                        }
                        ispd = dr["PDState"] != null ? dr["PDState"].ToString() : "";
                      
                    }
                    if (state == (int)EnumWorkState.finish &&
                    dr["F_MainDeptId"].ToString() == dr["F_DealDeptId"].ToString())
                    {

                        var closetime = dr["F_DealTime"].ToString();//关闭工单时间
                        var dttime = DateTime.Now;

                        if (!string.IsNullOrWhiteSpace(closetime)) { dttime = DateTime.Parse(closetime); }
                        else
                        {
                            var DealTime = dr["F_CloseTime"].ToString();
                            if (!string.IsNullOrWhiteSpace(DealTime)) { dttime = DateTime.Parse(DealTime); }
                        }
                        if (!string.IsNullOrWhiteSpace(lt))
                        {
                            var ltime = DateTime.Parse(lt);
                            TimeSpan ts = ltime.Subtract(dttime);
                            double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                            if (tss < 0) { tss = -tss; }
                            string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                            if (ltime < dttime)
                            {
                                dr["OverState"] = 3;
                                dr["GapTime"] = "超时" + gshsj;
                            }
                        }
                    }
                    #endregion
                    // }
                }
                if (dr["F_LeaveRecordId"] != null && dr["F_LeaveRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetLeavePath(dr["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                }
                else if (dr["F_CallRecordId"] != null && dr["F_CallRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetCallPath(dr["F_CallRecordId"].ToString(), config.F_ParamValue);
                }
                var buttons = ButtonGroup.GetButtons(dr["F_WorkState"].ToString(), User.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString(), iszbdw, ispd, isproresult);
                if (dbdata > 0 && dbtype == 5)
                {
                    string dbsql = " select top 1 strSsf_Cst_Ass_CntDsc,*  from   PublicComment WITH(NOLOCK) where WorkOrderId ='" + dr["F_WorkOrderId"].ToString() + "' and strWrkOrder_Cst_Ssf_Cd like '%不满意%' order by CreateTime desc";
                    var db = DbHelperSQL.Query(dbsql).Tables[0];
                    if (db.Rows.Count > 0)
                    {
                        dr["Dissatisfied"] = db.Rows[0]["strSsf_Cst_Ass_CntDsc"].ToString();
                    }
                }
                #region 判断是否存在待督办
            

                var reminds = new BLL.T_Bus_RemindRecord().GetNewModelByWorkOrderID(dr["F_WorkOrderId"].ToString());
                if (reminds!=null )
                {
                    dr["Supervise"] = 1;
           
                     var butt = buttons.Find(c => c.key == ButtonGroup.turnsee().key);
                    if (reminds.F_State ==0 && butt != null)
                        buttons.Remove(butt);
                }
                else 
              {
                    dr["Supervise"] = 0;
                }
                   
               
                #endregion
             
                //if (state == 9)
                //{
                //    if (User.F_RoleCode.ToUpper() == "ZJZY" || User.F_RoleCode.ToUpper() == "GLY" || User.F_RoleCode.ToUpper() == "DDZG" || User.F_RoleCode.ToUpper() == "ZXLD" || User.F_RoleCode.ToUpper() == "ZXHWY" || User.F_RoleCode.ToUpper() == "MTDD")
                //    {
                //        if (dr["F_CloseTime"] != null && dr["F_CloseTime"].ToString() != "")
                //        {
                //            var closedttime = DateTime.Parse(dr["F_CloseTime"].ToString());
                //            TimeSpan ts = DateTime.Now - closedttime;
                //            if (ts.TotalDays < 20)
                //            {
                //                buttons.Add(ButtonGroup.subreload());
                //            }
                //        }
                //    }
                //}
               // else
              if (state == 6)
                {
                    if (User.F_RoleCode.ToUpper() == "ZXHWY")
                    {
                        if (isproresult == 2 || isproresult == 3)
                            buttons.Add(ButtonGroup.forceend());
                    }
                }
                else if (state == 0&&dr["F_IsReturn"].ToString ()=="1")
                {
                    if (User.F_RoleCode.ToUpper() == "MTDD" 
                       )
                    {
                        buttons.Add(ButtonGroup.edit());
                     
                    }
                    else if ( User.F_RoleCode.ToUpper() == "ZXLD" || User.F_RoleCode == "YSZY")
                    {
                        buttons.Add(ButtonGroup.submit());
                        buttons.Add(ButtonGroup.delete());
                    }
                }
                dr["Buttons"] = buttons;
            }
            #endregion

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };
            return Content(obj.ToJson());

        }



        /// <summary>
        /// 获取工单列表
        /// </summary>
        /// <returns></returns>

        public ActionResult GetModelList(int isdc = 0)
        {
            DataTable dt = new DataTable();
            string sql = " and F_IsDelete=0 ";

            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));

            int source = RequestString.GetInt("source", 0);

            int deptid = RequestString.GetInt("deptid", 0);
            int dbdata = RequestString.GetInt("dbdata", 0);
            int dbdata2 = RequestString.GetInt("dbdata2", 0);
            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;
           
            #region sql 语句相关处理
            int dbtype = RequestString.GetInt("dbtype", 0);
            if (dbdata > 0)
            {
                if (deptid == 0)
                {
                    return Error("请选择部门");
                }
                string sdate = ""; string etime = "";
                if (strstarttime.Trim() == "" || strstarttime == "undefined")
                {
                    sdate = DateTime.Now.AddMonths(-1).
                   ToString("yyyy-MM") + "-21 00:00:01";

                    sql += " and F_CreateTime  between   '" + sdate + "' AND  '" + DateTime.Now.ToString("yyyy-MM") + "-20 23:59:59" + "'";
                }
                else
                {
                    sdate = strstarttime;
                    if (strendtime.Trim() == "" || strendtime == "undefined")
                    {
                        etime = DateTime.Now.ToString("yyyy-MM") + "-20 23:59:59";
                    }
                    else
                        etime = DateTime.Parse(strendtime).ToString("yyyy-MM-dd") + " 23:59:59";
                    sql += " and F_CreateTime  between   '" + sdate + "' AND  '" + etime + "'";
                }
                sql += "and F_WorkState not in (0, 1, 11) and F_MainDeptId='" + deptid + "'";
                if (dbtype == 1)
                {
                    sql += "and ((isnull(F_DealTime,F_CloseTime )>(select top 1 F_LimitTime from T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId = a.F_WorkOrderId  and F_State = 1 and F_IsDelete = 0 and F_IsSure<>3   ORDER BY F_Id DESC) AND F_WorkState = 9 AND F_CloseTime IS NOT NULL ) OR(isnull(F_DealTime, getdate()) > (select top 1 F_LimitTime from T_Bus_AssignedInfo WITH(NOLOCK)WHERE F_WorkOrderId = a.F_WorkOrderId  and F_State = 1 and F_IsDelete = 0 and F_IsSure <> 3   ORDER BY F_Id DESC) AND F_WorkState in(2, 4, 6, 8) ) ) ";
                }
                else if (dbtype == 2)
                {
                    sql += "and F_IsProResult =2 and F_WorkState =6 ";
                }
                else if (dbtype == 3)
                {
                    sql += "and  F_WorkOrderId  in(select F_WorkOrderId from T_Bus_Feedback  WITH(NOLOCK) where   (F_Id in (select MAX(F_Id) from T_Bus_Feedback where F_Type = 3 and F_CreateDeptId = a.F_DealDeptId and a.F_WorkState = 9  group by F_WorkOrderId) or F_Id in(select MAX(F_Id) from T_Bus_Feedback where F_Type = 3 and F_CreateDeptId = a.F_DealDeptId and F_WorkState in (2, 4, 5, 6, 8) group by F_WorkOrderId) ) ) and " +
                        "F_WorkOrderId not in(select F_WorkOrderId   from T_Bus_SubmitSuper where F_Type =3  and F_IsDelete = 0 and F_CreateTime >'" + sdate + "' ) ";
                }
            }
            else if (dbdata2 > 0)
            {
                if (deptid == 0)
                {
                    return Error("请选择部门");
                }
                int deptid2 = 0;
                if (User.F_RoleCode == "WLDW")
                    deptid2 = User.F_DeptId;
                string sdate = ""; string etime = "";
                if (string.IsNullOrEmpty(strstarttime))
                {
                    sdate = DateTime.Now.AddMonths(-1).ToString("yyyy-MM") + "-21 00:00:00";
                }
                else
                {
                    sdate = DateTime.Parse(strstarttime).ToString("yyyy-MM-dd") + " 00:00:00";

                }
                if (string.IsNullOrEmpty(strendtime))
                {
                    etime = DateTime.Now.ToString("yyyy-MM") + "-20 23:59:59";

                }
                else
                {
                    etime = DateTime.Parse(strendtime).ToString("yyyy-MM-dd") + " 23:59:59";

                }
                sql += " and F_CreateTime  between   '" + sdate + "' AND  '" + etime + "'";
                if (dbtype != 6)
                    sql += "and F_WorkState not in (0, 1, 11) and F_MainDeptId='" + deptid2 + "' " +
                        "and F_MainDeptID3='" + deptid + "'";
                else
                    sql += "and F_WorkState not in (0, 1, 11)";

                if (dbtype == 1)
                {
                    sql += "and ((isnull(F_DealTime,F_CloseTime )>(select top 1 F_LimitTime from T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId = a.F_WorkOrderId  and F_State = 1 and F_IsDelete = 0 and F_IsSure<>3   ORDER BY F_Id DESC) AND F_WorkState = 9 AND F_CloseTime IS NOT NULL ) OR(isnull(F_DealTime, getdate()) > (select top 1 F_LimitTime from T_Bus_AssignedInfo WITH(NOLOCK)WHERE F_WorkOrderId = a.F_WorkOrderId  and F_State = 1 and F_IsDelete = 0 and F_IsSure <> 3   ORDER BY F_Id DESC) AND F_WorkState in(2, 4, 6, 8) ) ) ";
                }
                else if (dbtype == 2)
                {
                    sql += "and F_IsProResult =2 and F_WorkState =6 ";
                }
                else if (dbtype == 3)
                {
                    sql += "and  F_WorkOrderId  in(select F_WorkOrderId from T_Bus_Feedback where   (F_Id in (select MAX(F_Id) from T_Bus_Feedback where F_Type = 3 and F_CreateDeptId = a.F_DealDeptId and a.F_WorkState = 9  group by F_WorkOrderId) or F_Id in(select MAX(F_Id) from T_Bus_Feedback where F_Type = 3 and F_CreateDeptId = a.F_DealDeptId and F_WorkState in (2, 4, 5, 6, 8) group by F_WorkOrderId) ) ) and " +
                        "F_WorkOrderId not in(select F_WorkOrderId   from T_Bus_SubmitSuper where F_Type =3  and F_IsDelete = 0 and F_CreateTime >'" + sdate + "' ) ";
                }
                else if (dbtype == 6)
                {
                    sql += "and F_WorkOrderId in (select F_WorkOrderId from T_Bus_VisitResult where F_IsSatisfie=0 and F_AssignedId in (select F_Id from T_Bus_AssignedInfo where F_MainDeptId ='" + deptid2 + "' ) group by F_WorkOrderId having COUNT(1) = 1 ) " +
                        "and F_MainDeptID3='" + deptid + "'";
                }
            }
            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            #endregion

            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }

            if (strpagesize.Trim() != "")
            {
                pagesize = Convert.ToInt32(strpagesize);
            }
            string cols = "";
            cols = "F_DealTime,F_CusName,F_CloseTime,F_Result,F_Unsuccessful,F_WorkOrderId,F_ComTitle,F_WorkState,F_MainDeptId,F_OtherDeptIds,F_DealTime,F_LeaveRecordId,F_CallRecordId,F_IsResult,F_IsProtect,F_IsReturn,F_CreateTime,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName,dbo.GetDeptNames(F_MainDeptId) as DeptName,F_CloseTime,F_AssignTime as AssignTime,F_LimitTime as LimitTime,F_IsProResult,F_ComContent,F_DealDeptId,F_Identification," +
                "(select top 1 strSsf_Cst_Ass_CntDsc from PublicComment where WorkOrderId =a.F_WorkOrderId order by CreateTime desc) as Oncedissatisfied,F_IsRelease";

            #region 导出
            if (isdc > 0)
            {
                var top = " "; var orderby = " order by F_CreateTime";
                if (sql == " and F_IsDelete=0 ")
                {
                    top = " top 1000 "; orderby += " desc ";
                }
                //20190715调整导出字段 zhengbingbing
                //日期，工单号，诉求标题，诉求内容，承办单位，办理结果，是否满意，备注
                var dtdc = DbHelperSQL.Query(" select  ROW_NUMBER() OVER(ORDER BY F_CreateTime desc)  序号,F_CreateTime 日期, F_WorkOrderId 工单号,F_ComTitle 诉求标题,F_ComContent 诉求内容,dbo.GetDictionaryName(F_Key) 反映类别, "
                    + "  dbo.GetDeptNames(F_MainDeptId ) 主办单位, "
                    + " (select top 1 F_Result from T_Bus_Feedback WITH(NOLOCK) where F_State=1 and F_Type!=3 and F_IsDelete=0 and  F_WorkOrderId =a.F_WorkOrderId order by F_Id desc) 办理结果, "
                    + " F_CusName 来电人姓名 ,F_CusPhone  来电人手机号 "
                    + " from T_Bus_WorkOrder a WITH(NOLOCK) where 1=1 " + sql + orderby).Tables[0];

                var msg = new NPOIHelper().ExportToExcel("工单列表", dtdc);
                if (msg == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }
            #endregion
            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_WorkOrder a WITH(NOLOCK)",
                "F_Id",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);
            #region 声音文件和交办超时
            #endregion
            dt.Columns.Add("GapTime", typeof(object));//不满意
            foreach (DataRow dr in dt.Rows)
            {
                if (dbtype == 1)
                {
                    var lt = dr["LimitTime"].ToString();//限制时间
                    int state = Int32.Parse(dr["F_WorkState"].ToString());                                //   
                    if (state < (int)EnumWorkState.dealed || state == (int)EnumWorkState.reload)
                    {
                        if (!string.IsNullOrWhiteSpace(lt))
                        {
                            var ltime = DateTime.Parse(lt);
                            TimeSpan ts = ltime.Subtract(DateTime.Now);
                            double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                            if (tss < 0) { tss = -tss; }
                            string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                            if (ltime > DateTime.Now)
                            {
                                dr["GapTime"] = "剩余" + gshsj;
                            }
                            else
                            {
                                dr["GapTime"] = "超时" + gshsj;
                            }
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrWhiteSpace(lt))
                        {
                            
                             var det = dr["F_DealTime"].ToString();
                            var ct = dr["F_CloseTime"].ToString();
                            if (!string .IsNullOrEmpty (det))
                            {
                                var ltime = DateTime.Parse(lt);
                                var detime= DateTime.Parse(det);
                                TimeSpan ts = ltime.Subtract(detime);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime > detime)
                                {
                                    dr["GapTime"] = "剩余" + gshsj;
                                }
                                else
                                {
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                            else
                            {
                                var ltime = DateTime.Parse(lt);
                                var ctime = DateTime.Parse(ct);
                                TimeSpan ts = ltime.Subtract(ctime);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime > ctime)
                                {
                                    dr["GapTime"] = "剩余" + gshsj;
                                }
                                else
                                {
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }

                        }
                    }
                }
            }

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };
            return Content(obj.ToJson());
        }



        /// <summary>
        /// 获取回收站工单列表
        /// </summary>
        /// <returns></returns>

        public ActionResult GetDeleteList(int isdc = 0)
        {
            DataTable dt = new DataTable();
            string sql = " and F_IsDelete=1 ";
            string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
            string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
            int islike = RequestString.GetInt("islike", 1);
            string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
            string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
            string splituser = HttpUtility.UrlDecode(RequestString.GetQueryString("splituser"));
            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
            string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));
            string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));
            string strddusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("ddusercode"));//调度员
            int isproresult = RequestString.GetInt("isproresult", 0);
            int source = RequestString.GetInt("source", 0);
            int keyid = RequestString.GetInt("keyid", 0);
            int type = RequestString.GetInt("type", 0);
            int bigtype = RequestString.GetInt("bigtype", 0);
            int smalltype = RequestString.GetInt("smalltype", 0);
            int sourcearea = RequestString.GetInt("sourcearea", 0);
            int deptid = RequestString.GetInt("deptid", 0);
            int dealtype = RequestString.GetInt("dealtype", -1);
            int issend = RequestString.GetInt("issend", -1);
            int deptlevel = RequestString.GetInt("deptlevel", 0);
            int dbdata = RequestString.GetInt("dbdata", 0);
            int dbdata2 = RequestString.GetInt("dbdata2", 0);
            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;
            string dealstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("dealstarttime"));
            string dealstrendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("dealstrendtime"));
            int isopen = RequestString.GetInt("isopen", -1);
            if (isopen > -1)
                sql += " and isnull(F_IsOpen,0) =" + isopen;

          

            if (dealstarttime.Trim() != "" && dealstarttime != "undefined")
            {
                if (dealstrendtime.Trim() != "" && dealstrendtime != "undefined")
                {
                    sql += " and F_DealTime  between   '" + dealstarttime +
                             "' AND  '" + dealstrendtime + "'";
                }
                else
                {
                    sql += " and F_DealTime>='" + dealstarttime + "' ";
                }
            }
            else
            {
                if (dealstrendtime.Trim() != "" && dealstrendtime != "undefined")
                {
                    sql += " and F_DealTime<='" + dealstrendtime + "' ";
                }
            }


            #region sql 语句相关处理
            if (strstate.Trim() != "" && strstate != "undefined")
            {

                sql += " and F_WorkState = '" + strstate.Trim() + "' ";
            }
            if (strworkid.Trim() != "" && strworkid != "undefined")
            {

                sql += " and F_WorkOrderId like '%" + strworkid + "%' ";
            }
            if (strname.Trim() != "" && strname != "undefined")
            {
                sql += " and F_CusName = '" + strname + "' ";
            }

            if (splituser.Trim() != "" && splituser != "undefined")
            {
                sql += " and F_SplitUser = '" + splituser + "' ";
            }

            if (islike > 0)
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
                }
            }
            else
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  = '" + strtel + "' or F_ConPhone like '" + strtel + "') ";
                }
            }
            int dbtype = RequestString.GetInt("dbtype", 0);
             if (dbdata > 0)
            {
                if (deptid == 0)
                {
                    return Error("请选择部门");
                }
                string sdate = ""; string etime = "";
                if (strstarttime.Trim() == "" || strstarttime == "undefined")
                {
                    sdate = DateTime.Now.AddMonths(-1).
                   ToString("yyyy-MM") + "-21 00:00:01";

                    sql += " and F_CreateTime  between   '" + sdate + "' AND  '" + DateTime.Now.ToString("yyyy-MM") + "-20 23:59:59" + "'";
                }
                else
                {
                    sdate = strstarttime;
                    if (strendtime.Trim() == "" || strendtime == "undefined")
                    {
                        etime = DateTime.Now.ToString("yyyy-MM") + "-20 23:59:59";
                    }
                    else
                        etime = DateTime.Parse(strendtime).ToString("yyyy-MM-dd") + " 23:59:59";
                    sql += " and F_CreateTime  between   '" + sdate + "' AND  '" + etime + "'";
                }
                if (dbtype != 6)
                    sql += "and F_WorkState not in (0, 1, 11) and F_MainDeptId='" + deptid + "'";
                else
                    sql += "and F_WorkState not in (0, 1, 11)";

                if (dbtype == 1)
                {
                    sql += "and ((isnull(F_DealTime,F_CloseTime )>(select top 1 F_LimitTime from T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId = a.F_WorkOrderId  and F_State = 1 and F_IsDelete = 0 and F_IsSure<>3   ORDER BY F_Id DESC) AND F_WorkState = 9 AND F_CloseTime IS NOT NULL ) OR(isnull(F_DealTime, getdate()) > (select top 1 F_LimitTime from T_Bus_AssignedInfo WITH(NOLOCK)WHERE F_WorkOrderId = a.F_WorkOrderId  and F_State = 1 and F_IsDelete = 0 and F_IsSure <> 3   ORDER BY F_Id DESC) AND F_WorkState in(2, 4, 6, 8) ) ) ";
                }
                else if (dbtype == 2)
                {
                    sql += "and F_IsProResult =2 and F_WorkState =6 ";
                }
                else if (dbtype == 3)
                {
                    sql += "and  F_WorkOrderId  in(select F_WorkOrderId from T_Bus_Feedback where   (F_Id in (select MAX(F_Id) from T_Bus_Feedback where F_Type = 3 and F_CreateDeptId = a.F_DealDeptId and a.F_WorkState = 9  group by F_WorkOrderId) or F_Id in(select MAX(F_Id) from T_Bus_Feedback where F_Type = 3 and F_CreateDeptId = a.F_DealDeptId and F_WorkState in (2, 4, 5, 6, 8) group by F_WorkOrderId) ) ) and " +
                        "F_WorkOrderId not in(select F_WorkOrderId   from T_Bus_SubmitSuper where F_Type =3  and F_IsDelete = 0 and F_CreateTime >'" + sdate + "' ) ";
                }
               
                else if (dbtype == 6)
                {
                    sql += "and F_WorkOrderId in (select F_WorkOrderId from T_Bus_VisitResult where F_IsSatisfie=0 and F_AssignedId in (select F_Id from T_Bus_AssignedInfo where F_MainDeptId ='" + deptid + "') group by F_WorkOrderId having COUNT(1) = 1 )";
                }
            }
            else if (dbdata2 > 0)
            {
                if (deptid == 0)
                {
                    return Error("请选择部门");
                }
                int deptid2 = 0;
                if (User.F_RoleCode == "WLDW")
                    deptid2 = User.F_DeptId;
                string sdate = ""; string etime = "";
                if (strstarttime.Trim() == "" || strstarttime == "undefined")
                {
                    sdate = DateTime.Now.AddMonths(-1).
                   ToString("yyyy-MM") + "-21 00:00:01";

                    sql += " and F_CreateTime  between   '" + sdate + "' AND  '" + DateTime.Now.ToString("yyyy-MM") + "-20 23:59:59" + "'";
                }
                else
                {
                    sdate = strstarttime;
                    if (strendtime.Trim() == "" || strendtime == "undefined")
                    {
                        etime = DateTime.Now.ToString("yyyy-MM") + "-20 23:59:59";
                    }
                    else
                        etime = DateTime.Parse(strendtime).ToString("yyyy-MM-dd") + " 23:59:59";
                    sql += " and F_CreateTime  between   '" + sdate + "' AND  '" + etime + "'";
                }
                if (dbtype != 6)
                    sql += "and F_WorkState not in (0, 1, 11) and F_MainDeptId='" + deptid2 + "' " +
                        "and F_MainDeptID3='" + deptid + "'";
                else
                    sql += "and F_WorkState not in (0, 1, 11)";

                if (dbtype == 1)
                {
                    sql += "and ((isnull(F_DealTime,F_CloseTime )>(select top 1 F_LimitTime from T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId = a.F_WorkOrderId  and F_State = 1 and F_IsDelete = 0 and F_IsSure<>3   ORDER BY F_Id DESC) AND F_WorkState = 9 AND F_CloseTime IS NOT NULL ) OR(isnull(F_DealTime, getdate()) > (select top 1 F_LimitTime from T_Bus_AssignedInfo WITH(NOLOCK)WHERE F_WorkOrderId = a.F_WorkOrderId  and F_State = 1 and F_IsDelete = 0 and F_IsSure <> 3   ORDER BY F_Id DESC) AND F_WorkState in(2, 4, 6,7, 8) ) ) ";
                }
                else if (dbtype == 2)
                {
                    sql += "and F_IsProResult =2 and F_WorkState =6 ";
                }
                else if (dbtype == 3)
                {
                    sql += "and  F_WorkOrderId  in(select F_WorkOrderId from T_Bus_Feedback where   (F_Id in (select MAX(F_Id) from T_Bus_Feedback where F_Type = 3 and F_CreateDeptId = a.F_DealDeptId and a.F_WorkState = 9  group by F_WorkOrderId) or F_Id in(select MAX(F_Id) from T_Bus_Feedback where F_Type = 3 and F_CreateDeptId = a.F_DealDeptId and F_WorkState in (2, 4, 5, 6, 8) group by F_WorkOrderId) ) ) and " +
                        "F_WorkOrderId not in(select F_WorkOrderId   from T_Bus_SubmitSuper where F_Type =3  and F_IsDelete = 0 and F_CreateTime >'" + sdate + "' ) ";
                }
                else if (dbtype == 6)
                {
                    sql += "and F_WorkOrderId in (select F_WorkOrderId from T_Bus_VisitResult where F_IsSatisfie=0 and F_AssignedId in (select F_Id from T_Bus_AssignedInfo where F_MainDeptId ='" + deptid2 + "' ) group by F_WorkOrderId having COUNT(1) = 1 ) " +
                        "and F_MainDeptID3='" + deptid + "'";
                }
            }
            string ComTitle = HttpUtility.UrlDecode(RequestString.GetQueryString("ComTitle"));
            string ComContent = HttpUtility.UrlDecode(RequestString.GetQueryString("ComContent"));
            string Result = HttpUtility.UrlDecode(RequestString.GetQueryString("Result"));
            if (ComTitle.Trim() != "" && ComTitle != "undefined")
            {
                sql += " and F_ComTitle like '%" + ComTitle + "%' ";
            }
            if (Result.Trim() != "" && Result != "undefined")
            {
                sql += " and F_Result like '%" + Result + "%' ";
            }
            if (ComContent.Trim() != "" && ComContent != "undefined")
            {
                sql += " and (F_ComContent like '%" + ComContent + "%' " +
                    "or F_Content like '%" + ComContent + "%'  )";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%'" +
                    " or F_Result like  '%" + strkey + "%' ) ";

            }
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {//坐席
                var usercode = strusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in usercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (usercode.Length > 1)
                {
                    if (newusercode.Trim() != "" && newusercode != "undefined")
                    {
                        sql += " and F_CreateUser in (" + newusercode + ") ";
                        //sql += " and F_CreateUser ='" + strusercode + "' ";
                    }
                }
                else
                {
                    if (newusercode.Trim() != "" && newusercode != "undefined")
                    {
                        sql += " and F_CreateUser = " + newusercode + " ";
                        //sql += " and F_CreateUser ='" + strusercode + "' ";
                    }
                }

            }
            if (strddusercode.Trim() != "" && strddusercode != "undefined")
            {//调度员
                var ddusercode = strddusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in ddusercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');

                if (ddusercode.Length > 1)
                {
                    if (newusercode.Trim() != "" && newusercode != "undefined")
                    {
                        sql += " and F_AssignUser in (" + newusercode + ") ";
                        //sql += " and F_CreateUser ='" + strusercode + "' ";
                    }
                }
                else
                {
                    if (newusercode.Trim() != "" && newusercode != "undefined")
                    {
                        sql += " and F_AssignUser = " + newusercode + " ";
                        //sql += " and F_CreateUser ='" + strusercode + "' ";
                    }
                }
            }

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            string sqlwhere = ""; string value = "";
            if (keyid != 0)
            {
                sqlwhere = " INNER JOIN[GetValueId]('" + keyid + "') Value on a.F_Key = Value.F_ValueId";
                value = " INNER JOIN[GetValueId]('" + keyid + "') Value on a.F_Key = Value.F_ValueId";

            }
            else if (User.F_RoleCode == "DFZF")
            {
                sql += " and F_CreateUser ='" + User.F_UserCode + "' ";
            }

            if (type != 0)
            {
                sql += " and F_InfoType = '" + type + "' ";
            }
            if (bigtype != 0)
            {
                sql += " and F_InfoConBigType = '" + bigtype + "' ";
            }
            if (smalltype != 0)
            {
                sql += " and F_InfoConSmallType = '" + smalltype + "' ";
            }
            if (isproresult != 0)
            {
                if (User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY"
                    || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
                {
                    if (isproresult == 2)
                    {
                        isproresult = 3;
                        sql += " and F_IsProResult = '" + 3 + "' ";
                    }
                    else
                    {
                        isproresult = 2;
                        sql += " and F_IsProResult = '" + 2 + "' ";
                    }

                }
                else
                    sql += " and F_IsProResult = '" + 2 + "' ";
            }
            if (sourcearea != 0)
            {
                sql += " and F_SourceArea = '" + sourcearea + "' ";
            }
           
           if (deptid != 0)
            {
               
                sql += " and  (F_MainDeptId = '" + deptid + "' or F_MainDeptID3='" + deptid + "')";
                #region 20190924 zhengbingbing 主办单位查询以最后办理单位为准
                #endregion
            }
           else
            {
                if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "EJWLDW")
                {
                    deptid = User.F_DeptId;
                    sql += " and  (F_MainDeptId = '" + deptid + "' or F_MainDeptID3='" + deptid + "')";
                }
            }



            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                if (strendtime.Trim() != "" && strendtime != "undefined")
                {
                    sql += " and F_CreateTime  between   '" + strstarttime +
                             "' AND  '" + strendtime + "'";
                }
                else
                {
                    sql += " and F_CreateTime>='" + strstarttime + "' ";
                }
            }
            else
            {
                if (strendtime.Trim() != "" && strendtime != "undefined")
                {
                    sql += " and F_CreateTime<='" + strendtime + "' ";
                }
            }

            if (dealtype != -1)
            {
                sql += " and isnull(F_IsResult,0) = '" + dealtype + "' ";
            }
            if (issend != -1)
            {
                sql += " and isnull(F_IsRelease,0) = '" + issend + "' ";
            }



            #endregion

            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }

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

            string cols = "  a.F_WorkOrderId,F_ComTitle,F_WorkState,F_MainDeptId,F_IsResult,a.F_CreateTime,dbo.GetUserName(a.F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName,dbo.GetDictionaryName(F_Key) KeyName,dbo.GetDeptNames(F_MainDeptId) as DeptName,F_CloseTime,F_LimitTime as LimitTime,F_ComContent,F_CusPhone,F_AssignTime";
            #region 导出
            if (isdc > 0)
            {
                var top = " "; var orderby = " order by F_CreateTime";
                if (sql == " and F_IsDelete=0 ")
                {
                    top = " top 1000 "; orderby += " desc ";
                }
                //20190715调整导出字段 zhengbingbing
                //日期，工单号，诉求标题，诉求内容，承办单位，办理结果，是否满意，备注
                var dtdc = DbHelperSQL.Query(" select  ROW_NUMBER() OVER(ORDER BY F_CreateTime desc)  序号,F_CreateTime 日期, F_WorkOrderId 工单号,F_ComTitle 诉求标题,F_ComContent 诉求内容,dbo.GetDictionaryName(F_Key) 反映类别, "
                    + "  dbo.GetDeptNames(F_MainDeptId ) 主办单位, "
                    + " (select top 1 F_Result from T_Bus_Feedback WITH(NOLOCK) where F_State=1 and F_Type!=3 and F_IsDelete=0 and  F_WorkOrderId =a.F_WorkOrderId order by F_Id desc) 办理结果, "
                    + " F_CusName 来电人姓名 ,F_CusPhone  来电人手机号 "
                    + " from T_Bus_WorkOrder a WITH(NOLOCK) where 1=1 " + sql + orderby).Tables[0];

                var msg = new NPOIHelper().ExportToExcel("工单列表", dtdc);
                if (msg == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }
            #endregion
            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_WorkOrder a WITH(NOLOCK)",
                "F_Id",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);
            #region 声音文件和交办超时
            #endregion

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };
            return Content(obj.ToJson());
        }
        /// <summary>
        /// 获取坐席处理列表
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetZXDealList(int isdc = 0)
        {
            DataTable dt = new DataTable();


            string sql = " and F_IsDelete=0";
            string strtab = HttpUtility.UrlDecode(RequestString.GetQueryString("tab"));
            string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
            string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
            int islike = RequestString.GetInt("islike", 1);
            string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
            string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
            string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));
            string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));
            string strddusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("ddusercode"));//调度员
            string order = "ORDER BY F_CreateTime DESC";

            int source = RequestString.GetInt("source", 0);
            int keyid = RequestString.GetInt("keyid", 0);
            int type = RequestString.GetInt("type", 0);
            int bigtype = RequestString.GetInt("bigtype", 0);
            int smalltype = RequestString.GetInt("smalltype", 0);
            int sourcearea = RequestString.GetInt("sourcearea", 0);
            int tobereply = RequestString.GetInt("tobereply", 0);
            int deptid = RequestString.GetInt("deptid", 0);
            int deptlevel = RequestString.GetInt("deptlevel", 0);
            int issms = RequestString.GetInt("issms", -1);
            int smspy = RequestString.GetInt("smspy", -1);//0未发送短信1
            int db = RequestString.GetInt("db", 0);
            int visit = RequestString.GetInt("visit", -1);//0满意1一评不满意2二评不满意
            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;
            string dealstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("dealstarttime"));
            string dealstrendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("dealstrendtime"));
            if (dealstarttime.Trim() != "" && dealstarttime != "undefined")
            {
                if (dealstrendtime.Trim() != "" && dealstrendtime != "undefined")
                {
                    sql += " and F_DealTime  between   '" + dealstarttime +
                             "' AND  '" + dealstrendtime + "'";
                }
                else
                {
                    sql += " and F_DealTime>='" + dealstarttime + "' ";
                }
            }
            else
            {
                if (dealstrendtime.Trim() != "" && dealstrendtime != "undefined")
                {
                    sql += " and F_DealTime<='" + dealstrendtime + "' ";
                }
            }
            switch (strtab)
            {
                case "-1"://待处理工单(其他来源)
                    sql = " and F_IsDelete=1 and F_IsEnabled=0 ";
                    break;
                case "0"://待处理工单
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "GNZY" && User.F_RoleCode != "ZXLD" && User.F_RoleCode != "YSZY" && User.F_RoleCode != "DDZG" && User.F_RoleCode != "MTDD" && User.F_RoleCode != "DMTCK")
                    {
                        //话务员，已办待回访菜单中可以看到所有工单并能操作
                        if (User.F_RoleCode != "ZJZY" && User.F_RoleCode != "ZXHWY"&&User.F_RoleCode != "DMTSH")
                            sql += " and F_CreateUser='" + User.F_UserCode + "'";
                        //话务员，已办待回访菜单中可以看到所有工单并能操作
                    }
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                        {
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                            sql += "and F_ToBereply=" + tobereply;
                        }
                        else if (strstate.Trim() == ((int)EnumWorkState.audit).ToString())
                        {
                            sql += " and F_WorkState in (" + (int)EnumWorkState.audit + "," + (int)EnumWorkState.auditreback + ") ";
                            sql += "and F_WorkOrderID not in (select F_WorkOrderID from T_Bus_RemindRecord where F_Type=1 and F_IsDelete=0 and  (F_Content != '推诿工单' or F_Content is null  ) and F_State!=2)";
                        }
                        else if (strstate.Trim() == "6" )
                        {
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        }
                        else
                        {
                            if (smspy == -1)
                            sql += "and F_ToBereply=" + tobereply;
                           
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        }
                        if (strstate.Trim() == "6"|| strstate.Trim() == "7")
                        {
                           // order = "order by F_DealTime desc";
                            if (db > -1)
                            {
                                if (db == 0)
                                {
                                    sql += "and F_WorkOrderID not in (select F_WorkOrderID from T_Bus_RemindRecord where F_Type=1 and F_IsDelete=0 and  F_State !=2)";
                                }
                                else
                                {
                                    sql += "and F_WorkOrderID  in (select F_WorkOrderID from T_Bus_RemindRecord where F_Type=1 and F_IsDelete=0 and  (F_Content != '推诿工单' or F_Content is null  ) and F_State not in (0,2) )";

                                }
                            }
                            else
                            {
                                sql += "and F_WorkOrderID not in (select F_WorkOrderID from T_Bus_RemindRecord where F_Type=1 and F_IsDelete=0 and  (F_Content != '推诿工单' or F_Content is null  ) and F_State!=2)";
                            }
                        }
                    }
                    else
                    {
                       // order = "order by F_Level desc";
                        sql += "and F_ToBereply=" + tobereply;
                        // sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + "," + (int)EnumWorkState.dealed + "," + (int)EnumWorkState.rejload + ") ";
                        sql += " and F_WorkState in (0) ";
                    }
                    order = "order by F_Id desc";
                    break;
                case "1"://已提交的工单
                    sql += " and F_WorkState >0 ";
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG" || User.F_RoleCode != "DBZY")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "'";
                    }
                    break;
                case "2"://已回访的工单
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_VisitResult WITH(NOLOCK) where F_State=1 and F_IsDelete=0  ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG" && User.F_RoleCode != "DBZY")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "3"://已回退的工单
                    //sql += "  and F_WorkState=0 and F_IsReturn=1 ";
                    sql += " and F_WorkState in (0,10) and F_IsReturn=1";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "GNZY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "'";
                    }

                    break;
                case "4":
                    sql += " and F_WorkOrderID in(select F_WorkOrderID from T_Bus_SubmitSuper WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_Type=3)";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "'";
                    }
                    break;
                case "5":
                    sql += " and F_WorkState =0 ";
                    sql += " and F_InfoSource = '2580'";
                    break;
            }
         
            if (issms > -1)
            {
                if (issms == 1)
                    sql += " and F_IsSms = '" + issms + "'";
                else
                    sql += " and (F_IsSms = '0' or F_IsSms is null  )";
            }
            string splituser = HttpUtility.UrlDecode(RequestString.GetQueryString("splituser"));
            if (splituser.Trim() != "" && splituser != "undefined")
            {
                sql += " and F_SplitUser = '" + splituser + "' ";
            }

            string assuser = HttpUtility.UrlDecode(RequestString.GetQueryString("assuser"));
            if (assuser.Trim() != "" && assuser != "undefined")
            {
                sql += " and F_AssignUser = '" + assuser + "' ";
            }
            if (User .F_RoleCode =="WLDW")
            {
                if (strtab != "5")
                {
                    sql += " and F_InfoSource in (1,3,6) ";
                }
            }
            if (strworkid.Trim() != "" && strworkid != "undefined")
            {
                sql += " and F_WorkOrderId like '%" + strworkid + "%' ";
            }
            if (strname.Trim() != "" && strname != "undefined")
            {
                sql += " and F_CusName like '%" + strname + "%' ";
            }
            if (islike > 0)
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
                }
            }
            else
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  = '" + strtel + "' or F_ConPhone like '" + strtel + "') ";
                }
            }
            string ComTitle = HttpUtility.UrlDecode(RequestString.GetQueryString("ComTitle"));
            string ComContent = HttpUtility.UrlDecode(RequestString.GetQueryString("ComContent"));
            string Result = HttpUtility.UrlDecode(RequestString.GetQueryString("Result"));
            if (ComTitle.Trim() != "" && ComTitle != "undefined")
            {
                sql += " and F_ComTitle like '%" + ComTitle + "%' ";
            }
            if (Result.Trim() != "" && Result != "undefined")
            {
                sql += " and F_Result like '%" + Result + "%' ";
            }
            if (ComContent.Trim() != "" && ComContent != "undefined")
            {
                sql += " and F_ComContent like '%" + ComContent + "%' ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%'" +
                    " or F_Result like  '%" + strkey + "%' ) ";
            }

            #region  坐席&调度员
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {//坐席
                var usercode = strusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in usercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_CreateUser in (" + newusercode + ") ";
                }
            }
            if (strddusercode.Trim() != "" && strddusercode != "undefined")
            {//调度员
                var ddusercode = strddusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in ddusercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_AssignUser in(" + newusercode + ") ";
                }
            }
            #endregion
            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            string sqlwhere = ""; string value = "";
            if (keyid != 0)
            {
                sqlwhere = " INNER JOIN[GetValueId]('" + keyid + "') Value on a.F_Key = Value.F_ValueId";
                //sql += "and (F_Key IN(  SELECT  F_ValueId from [GetValueId]('"+ keyid + "'))" +
                //  " or F_Key='" + keyid + "' )";
                value = " INNER JOIN[GetValueId]('" + keyid + "') Value on wo.F_Key = Value.F_ValueId";

            }
            if (type != 0)
            {
                sql += " and F_InfoType = '" + type + "' ";
            }
            if (bigtype != 0)
            {
                sql += " and F_InfoConBigType = '" + bigtype + "' ";
            }
            if (smalltype != 0)
            {
                sql += " and F_InfoConSmallType = '" + smalltype + "' ";
            }
            if (sourcearea != 0)
            {
                sql += " and F_SourceArea = '" + sourcearea + "' ";
            }
            if (deptid != 0)
            {
                //sql += " and ',' + F_MainDeptID + ',' like '%," + deptid.ToString() + ",%'";
                //sql += " and isnull(F_MainDeptId,null)='" + deptid + "'";
                sql += " and  (F_MainDeptId = '" + deptid + "' or F_MainDeptID3='" + deptid + "')";
                #region 20190924 zhengbingbing 主办单位查询以最后办理单位为准
              
                #endregion
            }
            else
            {
                if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "EJWLDW")
                {
                    deptid = User.F_DeptId;
                    sql += " and  (F_MainDeptId = '" + deptid + "' or F_MainDeptID3='" + deptid + "')";
                }
            }

            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and F_CreateTime>='" + strstarttime + "' ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and F_CreateTime<='" + strendtime + "' ";
            }

            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }

            if (strpagesize.Trim() != "")
            {
                pagesize = Convert.ToInt32(strpagesize);
            }
            //string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetOverState(F_WorkOrderId) as OverState,"
            //    + "dbo.GetDictionaryName(F_InfoSource) as SourceName,dbo.GetWorkOrderAssign(F_WorkOrderId) as DeptName ,dbo.GetLimitTime(F_WorkOrderId) as LimitTime";
            //string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName";
            string cols = "";
            cols = "F_WorkOrderId,F_InfoSource,F_CusName,F_ComTitle,F_WorkState,F_MainDeptId,F_OtherDeptIds,F_DealTime,F_LeaveRecordId,F_CallRecordId,F_IsResult,F_IsProtect,F_IsReturn,F_CreateTime,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName,(select top 1 F_Result from T_Bus_Feedback WITH(NOLOCK)  where F_Type=3 and F_State=1 and F_IsDelete=0" +
              "and F_WorkOrderId=a.F_WorkOrderId order by F_CreateTime desc ) as Backreason ,F_CloseTime,F_Identification,F_IsRelease";
            if (smspy>-1)
            {
                order = "  order by F_Id  desc";
            }
            if (isdc > 0)
            {
                var top = " "; var orderby = " order by F_CreateTime";
                if (sql == " and F_IsDelete=0 ")
                {
                    top = " top 1000 "; orderby += " desc ";
                }
                //20190715调整导出字段 zhengbingbing
                //日期，工单号，诉求标题，诉求内容，承办单位，办理结果，是否满意，备注
                var dtdc = DbHelperSQL.Query(" select  F_CreateTime 日期, F_WorkOrderId 工单号,F_ComTitle 诉求标题,F_ComContent 诉求内容,dbo.GetDictionaryName(F_Key) 主题词, "
                      + "  dbo.GetDeptNames(F_MainDeptId ) 主办单位, "

                    + " (select top 1 F_Result from T_Bus_Feedback WITH(NOLOCK) where F_State=1 and F_Type!=3 and F_IsDelete=0 and  F_WorkOrderId =wo.F_WorkOrderId order by F_Id desc) 办理结果, "
                    + " (select top 1 (case F_IsSatisfie when 1 then'满意' when 0 then '不满意' else '未评价' end) F_Satisfie from T_Bus_VisitResult WITH(NOLOCK) where F_State = 1 and F_IsDelete = 0 and F_WorkOrderId = wo.F_WorkOrderId order by F_Id desc) 是否满意 "
                    + " from T_Bus_WorkOrder wo WITH(NOLOCK)" + value + " where 1=1 " + sql + orderby).Tables[0];
                var msg = new NPOIHelper().ExportToExcel("工单列表", dtdc);
                if (msg == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }

            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_WorkOrder a WITH(NOLOCK)" + sqlwhere,
                "F_Id",
                cols,
                sql,
               order,
                pagesize,
                pageindex,
                true,
                out recordCount);

            dt.Columns.Add("DeptName", typeof(string));//交办单位
            dt.Columns.Add("AssignTime", typeof(string));//交办时间
            dt.Columns.Add("OtherDeptName", typeof(string));//协办单位
            dt.Columns.Add("OverState", typeof(string));//超时状态
            dt.Columns.Add("LimitTime", typeof(string));//限制时间
            dt.Columns.Add("GapTime", typeof(string));//时间差
            dt.Columns.Add("FilePath", typeof(string));//语音文件路径
            dt.Columns.Add("Buttons", typeof(object));//操作按钮
            var configly = configBll.GetModelList(" F_ParamCode='PlayLeaveVoice' ").FirstOrDefault();
            var config = configBll.GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
            var configcs = configBll.GetModelList(" F_ParamCode='CSYJ' ").FirstOrDefault();
            var reminds = remindBLL.GetModelList("F_State=0 and F_IsDelete=0 and F_Type =1").ToList();
            foreach (DataRow dr in dt.Rows)
            {
                //获取最新交办信息
                string iszbdw = "0";
                int state = Int32.Parse(dr["F_WorkState"].ToString());
                if (state > 1)
                {
                    string sqljb = "SELECT TOP 1 * FROM T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' and F_State=1 and F_IsDelete=0 and F_IsSure<>3   ORDER BY F_Id DESC";
                    var dtjb = DbHelperSQL.Query(sqljb).Tables[0];
                    if (dtjb.Rows.Count > 0)
                    {
                        //if (dtjb.Rows[0]["F_MainDeptId"].ToString().Split(',').Contains(User.F_DeptId.ToString())) { iszbdw = "1"; }
                        if (dtjb.Rows[0]["F_MainDeptId"].ToString() == User.F_DeptId.ToString()) { iszbdw = "1"; }
                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_MainDeptId"].ToString() + "')");
                        if (dtjb.Rows[0]["F_OtherDeptIds"] != null && dtjb.Rows[0]["F_OtherDeptIds"].ToString() != "")
                        {
                            dr["OtherDeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_OtherDeptIds"].ToString() + "')");
                        }
                        dr["AssignTime"] = dtjb.Rows[0]["F_CreateTime"].ToString();
                        #region
                       
                        #endregion
                        #region
                        //if (state < 6 || state == 8)
                        if (state < (int)EnumWorkState.dealed || state == (int)EnumWorkState.reload)
                        {
                            var lt = dtjb.Rows[0]["F_LimitTime"].ToString();//限制时间
                            dr["LimitTime"] = lt;
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                if (ltime > DateTime.Now)
                                {
                                    string SY = "SELECT  COUNT(1)  FROM T_Sys_WorkOFFDays WHERE F_OffState =0    AND F_OffDate > '" + DateTime.Now.ToString("yyyy-MM-dd") + "' AND F_OffDate<'" + lt + "'";
                                    var SYSJ = DbHelperSQL.GetSingle(SY);
                                    if (!string.IsNullOrEmpty(SYSJ.ToString()))
                                    {
                                        try
                                        {
                                            ltime = ltime.AddDays(-int.Parse(SYSJ.ToString()));
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                                TimeSpan ts = ltime.Subtract(DateTime.Now);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime > DateTime.Now)
                                {
                                    if (configcs != null)
                                    {
                                        int cs = Int32.Parse(configcs.F_ParamValue);
                                        if (ts.TotalHours > cs)
                                        {
                                            dr["OverState"] = 1;
                                        }
                                        else
                                        {
                                            dr["OverState"] = 2;
                                        }
                                    }
                                    dr["GapTime"] = "剩余" + gshsj;
                                }
                                else
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                        }
                        if (state == (int)EnumWorkState.finish)
                        {
                            var closetime = dr["F_DealTime"].ToString();//关闭工单时间
                            var dttime = DateTime.Now;
                            if (!string.IsNullOrWhiteSpace(closetime)) { dttime = DateTime.Parse(closetime); }
                            else
                            {
                                var DealTime = dr["F_CloseTime"].ToString();
                                if (!string.IsNullOrWhiteSpace(DealTime)) { dttime = DateTime.Parse(DealTime); }
                            }

                            //else
                            //{
                            //    var DealTime = dr["F_CloseTime"].ToString();//关闭工单时间
                            //    if (!string.IsNullOrWhiteSpace(DealTime))
                            //        dttime = DateTime.Parse(DealTime);
                            //}



                            var lt = dtjb.Rows[0]["F_LimitTime"].ToString();//限制时间
                            dr["LimitTime"] = lt;
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);

                                TimeSpan ts = ltime.Subtract(dttime);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime < dttime)
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                        }




                        #endregion
                    }
                    else
                    {

                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dr["F_MainDeptId"].ToString() + "')");
                    }
                }
                if (dr["F_LeaveRecordId"] != null && dr["F_LeaveRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetLeavePath(dr["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                }
                else if (dr["F_CallRecordId"] != null && dr["F_CallRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetCallPath(dr["F_CallRecordId"].ToString(), config.F_ParamValue);
                }

                List<ButtonGroup.button> btns = new List<ButtonGroup.button>();
                if (Int32.Parse(strtab) == 0 || Int32.Parse(strtab) == 3)
                {
                    btns.Clear();
                    btns = ButtonGroup.GetButtons(dr["F_WorkState"].ToString(), User.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString(), iszbdw
                        );
                    //if (dr["F_InfoSource"].ToString()=="2580"&& dr["F_WorkState"].ToString()=="7")
                    //{
                    //    if (User.F_RoleCode.ToUpper() == "ZJZY" || User.F_RoleCode.ToUpper() == "GNZY" || User.F_RoleCode.ToUpper() == "GLY" || User.F_RoleCode.ToUpper() == "ZXLD" || User.F_RoleCode.ToUpper() == "YSZY" || User.F_RoleCode.ToUpper() == "DDZG" || User.F_RoleCode.ToUpper() == "MTDD"|| User.F_RoleCode.ToUpper() == "ZXHWY")
                    //    {
                    //        var butts = btns.Find(c => c.key == ButtonGroup.visit().key);
                    //        if (butts != null)
                    //        {
                    //            btns.Remove(butts);
                    //            btns.Add(ButtonGroup.visits());
                    //        }
                               
                    //    }
                    //}
                    #region 判断是否存在待督办
                    var recount = reminds.Where(r => r.F_WorkOrderId == dr["F_WorkOrderId"].ToString()).Count();
                    var butt = btns.Find(c => c.key == ButtonGroup.turnsee().key);
                    if (recount > 0 && butt != null)
                        btns.Remove(butt); 
                    if (Int32.Parse(strtab) == 0 && state == 7)
                    {
                        if (User.F_RoleCode.ToUpper() != "ZXHWY")
                        btns.Add(ButtonGroup.turnsee());
                    }
                    if (Int32.Parse(strtab) == 0 && state == 3)
                    {
                        if ( butt != null)
                            btns.Remove(butt);
                    }
                    if (Int32.Parse(strtab) == 0 && state == 6)
                    {
                        btns.Add(ButtonGroup.modify());
                    }
                    #endregion
                    if (dr["F_InfoSource"].ToString() == "4" && dr["F_WorkState"].ToString() == "7")
                    {
                        if (User.F_RoleCode.ToUpper() == "GLY" || User.F_RoleCode.ToUpper() == "MTDD")
                        {
                            var prople = new BLL.T_Bus_People().GetModelList("state !=3 and F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "'");
                            if (prople != null&& prople.Count >0)
                            {
                                btns.Add(ButtonGroup.Explain());
                            }

                        }
                    }
                }
                else if (Int32.Parse(strtab) == 5)
                {
                    btns.Clear();
                    btns.Add(ButtonGroup.query());
                    btns.Add(ButtonGroup.Signfor());
                    btns.Add(ButtonGroup.Sendback());
                    btns.Add(ButtonGroup.delayback());
                    
                }
                else if (Int32.Parse(strtab) == -1)
                {
                    btns.Clear();
                    btns.Add(ButtonGroup.query());
                    btns.Add(ButtonGroup.edit());
                }
                else
                {
                    btns.Clear();
                    btns.Add(ButtonGroup.query());
                }

                dr["Buttons"] = btns;
            }

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };
            return Content(obj.ToJson());
        }

        /// <summary>
        /// 获取领导处理列表
        /// </summary>发
        /// <returns></returns>
        //[Authority]
        public ActionResult GetLDDealList(int isdc = 0)
        {
            DataTable dt = new DataTable();


            string sql = " and F_IsDelete=0";
            string strtab = HttpUtility.UrlDecode(RequestString.GetQueryString("tab"));
            string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
            string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
            int islike = RequestString.GetInt("islike", 1);
            string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
            string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
            string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));
            string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));
            string strddusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("ddusercode"));//调度员
            int source = RequestString.GetInt("source", 0);
            int keyid = RequestString.GetInt("keyid", 0);
            int type = RequestString.GetInt("type", 0);
            int bigtype = RequestString.GetInt("bigtype", 0);
            int smalltype = RequestString.GetInt("smalltype", 0);
            int sourcearea = RequestString.GetInt("sourcearea", 0);
            int deptid = RequestString.GetInt("deptid", 0);
            int isdb = RequestString.GetInt("isdb", -1);
            int issh = RequestString.GetInt("issh", -1);
            int deptlevel = RequestString.GetInt("deptlevel", 0);
            int issatisfie = RequestString.GetInt("issatisfie", -1);//0不满意 1满意
            int dealtype = RequestString.GetInt("dealtype", -1);//1当即办理，0转办办理，2按时办结，3超期办结
            string order = "ORDER BY F_CreateTime DESC";
            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;
            string dealstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("dealstarttime"));
            string dealstrendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("dealstrendtime"));
            int db = RequestString.GetInt("db", 0);
            int isopen = RequestString.GetInt("isopen", -1);
            int identification = RequestString.GetInt("identification", -1);
            if (identification>-1)
            {
                sql += "and F_Identification='" + identification + "'";
            }
            int cshf = RequestString.GetInt("cshf", -1);
            if (cshf>-1)
            {
                if (cshf==0)
                sql += "and F_DealTime >F_LimitTime  and  F_DealTime is not null and F_LimitTime is not null and F_MainDeptId > 0 ";
                else 
                sql += "and F_DealTime <F_LimitTime  and  F_DealTime is not null and F_LimitTime is not null and F_MainDeptId > 0 ";
            }
            if (isopen > -1)
                sql += " and isnull(F_IsOpen,0) =" + isopen;
            string splituser = HttpUtility.UrlDecode(RequestString.GetQueryString("splituser"));
            if (splituser.Trim() != "" && splituser != "undefined")
            {
                sql += " and F_SplitUser = '" + splituser + "' ";
            }
            string assuser = HttpUtility.UrlDecode(RequestString.GetQueryString("assuser"));
            if (assuser.Trim() != "" && assuser != "undefined")
            {
                sql += " and F_AssignUser = '" + assuser + "' ";
            }
            if (dealstarttime.Trim() != "" && dealstarttime != "undefined")
            {
                if (dealstrendtime.Trim() != "" && dealstrendtime != "undefined")
                {
                    sql += " and F_DealTime  between   '" + dealstarttime +
                             "' AND  '" + dealstrendtime + "'";
                }
                else
                {
                    sql += " and F_DealTime>='" + dealstarttime + "' ";
                }
            }
            else
            {
                if (dealstrendtime.Trim() != "" && dealstrendtime != "undefined")
                {
                    sql += " and F_DealTime<='" + dealstrendtime + "' ";
                }
            }
            if (isdb>-1)
            {
                if (isdb==0)
                {
                    sql += "and F_WorkOrderID not in (select F_WorkOrderID from T_Bus_RemindRecord where F_Type=1 and F_IsDelete=0and  (F_Content != '推诿工单' or F_Content is null  ) and F_State!=2)";
                }
                else
                {
                    sql += "and F_WorkOrderID  in (select F_WorkOrderID from T_Bus_RemindRecord where F_Type=1 and F_IsDelete=0and  (F_Content != '推诿工单' or F_Content is null  ) and F_State!=2)";

                }
              
            }
            switch (strtab)
            {
                case "0"://待处理工单
                    order = "order by a.F_Level desc, a.F_CreateTime desc";
                    sql += " and (F_IsRelease !='" + 3 + "' or " +
                        "F_IsRelease is null) ";
                    sql += "and F_WorkOrderID not in (select F_WorkOrderID from T_Bus_RemindRecord WITH(NOLOCK) where F_Type=1 and F_IsDelete=0and  (F_Content != '推诿工单' or F_Content is null  ) and F_State!=2)";
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                        {
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + "," + (int)EnumWorkState.resubmit + ") ";
                        }
                        else if (strstate.Trim() == ((int)EnumWorkState.submit).ToString())
                        {
                            if (User.F_RoleCode == "ZXHWY")
                                sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                            else
                                sql += " and F_WorkState in (" + (int)EnumWorkState.submit + "," + (int)EnumWorkState.resubmit + ") ";
                        }
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";

                        if (strstate.Trim() != ((int)EnumWorkState.submit).ToString())
                        {
                            sql += "  and F_WorkOrderID in (select F_WorkOrderID from T_Bus_AssignedInfo WITH(NOLOCK) where F_State=1 and F_IsDelete=0 ";

                            if (User.F_RoleCode != "GLY" && User.F_RoleCode != "ZXLDGLY" && User.F_RoleCode != "ZXLDGLYGLY" && User.F_RoleCode != "DDZG"
                                && User.F_RoleCode != "ZXLD " && User.F_RoleCode != "YSZY" && User.F_RoleCode != "MTDD"
                                &&User .F_RoleCode != "DMTCK")
                            {
                                sql += " and F_CreateUser='" + User.F_UserCode + "')";
                            }
                            else
                            {
                                sql += ")";
                            }
                        }
                        else
                        {
                            if (User.F_RoleCode != "GLY" && User.F_RoleCode != "ZXLDGLY" && User.F_RoleCode != "ZXLDGLYGLY" && User.F_RoleCode != "DDZG" && User.F_RoleCode != "GNZY")
                            {
                                sql += " and (F_WorkOrderId in (select F_WorkOrderId from T_Bus_AssignedInfo WITH(NOLOCK) where F_State = 1 and F_IsDelete = 0 "
                                    + "and F_CreateUser = '" + User.F_UserCode + "') or (select top 1 F_WorkOrderId from T_Bus_AssignedInfo WITH(NOLOCK) where"
                                    + " F_State = 1 and F_IsDelete = 0 and T_Bus_AssignedInfo.F_WorkOrderId = T_Bus_WorkOrder.F_WorkOrderId) is null)";
                                sql += " and F_WorkState != '9' ";
                            }
                            if (User.F_RoleCode == "ZXHWY")
                            {
                                sql += "  and F_CreateUser='" + User.F_UserCode + "' ";
                            }
                        }
                    }
                    else
                    {
                        int[] sts = new int[] { (int)EnumWorkState.submit, (int)EnumWorkState.resubmit };
                        sql += "and F_WorkState in(1,11) ";
                    }
                    break;
                case "1"://已交办的工单
                    string strjbstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("jbstarttime"));
                    string strjbendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("jbendtime"));
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        // sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in (select F_WorkOrderID from T_Bus_AssignedInfo WITH(NOLOCK) where F_State=1 and F_IsDelete=0 )";
                    sql += " and F_WorkState  in (2,3,4,5,8)";
                    if (strjbstarttime.Trim() != "" && strjbstarttime != "undefined")
                    {
                        sql += " and datediff(day,F_CreateTime,'" + strjbstarttime + "')<=0 ";
                    }
                    if (strjbendtime.Trim() != "" && strjbendtime != "undefined")
                    {
                        sql += " and datediff(day,F_CreateTime,'" + strjbendtime + "')>=0   ";
                    }
                    //if (deptid != 0)
                    //{
                    //    //sql += " and ',' + F_MainDeptID + ',' like '%," + deptid.ToString() + ",%'";
                    //    sql += " and F_MainDeptId = '" + deptid + "'";
                    //}
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "ZXLDGLY" && User.F_RoleCode != "ZXLDGLYGLY" && User.F_RoleCode != "DDZG"
                        && User.F_RoleCode != "ZXLD" && User.F_RoleCode != "YSZY" && User.F_RoleCode != "MTDD" && User.F_RoleCode != "DMTCK")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "'";
                    }
                    break;
                case "2"://已审核退回的工单
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in (select F_WorkOrderID from T_Bus_Feedback WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_IsAudit>0 ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "ZXLDGLY" && User.F_RoleCode != "ZXLDGLYGLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_AuditUser='" + User.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "3"://已审核延时的工单
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in (select F_WorkOrderID from T_Bus_DelayTime WITH(NOLOCK) where F_IsDelete=0 and F_IsAudit>0 ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "ZXLDGLY" && User.F_RoleCode != "ZXLDGLYGLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_AuditUser='" + User.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "4"://已重办的工单
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in (select F_WorkOrderID from T_Bus_AssignedInfo WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_IsReload>0 ";
                    sql += ")";
                    break;
                case "5"://已结案的工单
                    string strwjstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("wjstarttime"));
                    string strwjendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("wjendtime"));
                   
                    if (issatisfie != -1)
                    {
                        sql += " and  F_WorkOrderID in(select F_WorkOrderID from T_Bus_VisitResult b  WITH(NOLOCK) where F_State = 1 and F_IsDelete = 0 and F_IsSatisfie = " + issatisfie + "  and F_Id       in (select  MAX(F_Id) from T_Bus_VisitResult WITH(NOLOCK) where F_WorkOrderId in          (select F_WorkOrderId from T_Bus_VisitResult WITH(NOLOCK) where F_WorkOrderId = b.F_WorkOrderId  group by F_WorkOrderId  ) ) )";
                    }
                    if (dealtype > -1)
                    {
                        if (dealtype == 2)
                        {//按时
                            sql += " and F_IsResult=0 and isnull(F_DealTime,'')<>'' and F_LimitTime>=F_DealTime ";
                        }
                        else if (dealtype == 3)
                        {//超期
                            sql += " and isnull(F_DealTime,'')<>'' and F_LimitTime<F_DealTime ";
                        }
                        else
                            sql += " and isnull(F_IsResult,0) = '" + dealtype + "' ";
                    }
                    sql += "  and F_WorkState =9 and F_IsDelete=0 and F_IsClosed=1 ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "ZXHWY" && User.F_RoleCode != "ZXLD" && User.F_RoleCode != "YSZY"  && User.F_RoleCode != "MTDD" && User.F_RoleCode != "DBZY" && User.F_RoleCode != "GNZY" && User.F_RoleCode != "DMTCK")
                    {
                        sql += " and F_CloseUser='" + User.F_UserCode + "'";
                    }
                    if (strwjstarttime.Trim() != "" && strwjstarttime != "undefined")
                    {
                        sql += " and datediff(day,F_CloseTime,'" + strwjstarttime + "')<=0 ";
                    }
                    if (strwjendtime.Trim() != "" && strwjendtime != "undefined")
                    {
                        sql += " and datediff(day,F_CloseTime,'" + strwjendtime + "')>=0   ";
                    }

                    break;
                case "6"://已督办的工单 
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_RemindRecord WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_Type =1 ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "ZXLDGLY" && User.F_RoleCode != "ZXLDGLYGLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "7"://已监察的工单 
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    //sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_RemindRecord where F_State=1 and F_IsDelete=0 and F_Type =2 ";
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_RemindRecord WITH(NOLOCK) where F_IsDelete=0 and F_Type =2 ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "ZXLDGLY" && User.F_RoleCode != "ZXLDGLYGLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "8"://待督办列表
                    //20190315需求变动，由督办查看督办列表并监管 20190401 zhengbingbing
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_RemindRecord WITH(NOLOCK) where F_State=0 and F_IsDelete=0 and F_Type =1 ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DBZY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "9"://重办驳回列表
                    sql += " and F_WorkState=" + (int)EnumWorkState.rejload;
                    sql += " and F_WorkOrderID in (select F_WorkOrderId from T_Bus_Operation WITH(NOLOCK) where F_Id in (select max(F_Id) from T_Bus_Operation WITH(NOLOCK) where F_State = " + (int)EnumWorkState.resubmit + " and F_WorkOrderId in (select F_WorkOrderId from T_Bus_Operation WITH(NOLOCK) where F_State=" + (int)EnumWorkState.rejload + ") group by F_WorkOrderId)";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "'";
                    }
                    sql += ")";
                    break;
                case "10"://
                    sql += " and (F_IsRelease !='" + 3 + "' or " +
                       "F_IsRelease is null) ";
                    sql += " and F_WorkState in(1,11)";
                    sql += "and F_WorkOrderID not in (select F_WorkOrderID from T_Bus_RemindRecord where F_Type=1 and F_IsDelete=0and  (F_Content != '推诿工单' or F_Content is null  ) and F_State!=2)";
                    //  sql += " and F_WorkOrderID in(select F_WorkOrderID from T_Bus_Feedback b WITH(NOLOCK) where F_State = 1 and F_IsDelete = 0 and F_Type = 3 and F_IsAudit = 1  ) ";
                    // sql += "and F_WorkOrderID in(  select  b.F_WorkOrderID from T_Bus_Feedback b  WITH(NOLOCK)  inner join T_Bus_Feedback a on a.F_Id = b.F_Id and a .F_Id = (select max(t1.F_Id) from T_Bus_Feedback t1 where t1.F_WorkOrderId = b.F_WorkOrderId)  where b.F_State = 1 and b.F_IsDelete = 0 and b.F_Type = 3 and b.F_IsAudit = 1  ) ";
                  
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DMTCK" && User.F_RoleCode != "ZXLD" && User.F_RoleCode != "YSZY" && User.F_RoleCode != "MTDD")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "'";
                    }

                    break;
                case "11"://
                  
                    sql += " and F_WorkState =14";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DMTCK" && User.F_RoleCode != "ZXLD" && User.F_RoleCode != "YSZY" && User.F_RoleCode != "MTDD")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "'";
                    }
                    if (db > -1)
                    {
                        if (db == 0)
                        {
                            sql += "and F_WorkOrderID not in (select F_WorkOrderID from T_Bus_RemindRecord where F_Type=1 and F_IsDelete=0 and  F_State !=2)";
                        }
                        else
                        {
                            sql += "and F_WorkOrderID  in (select F_WorkOrderID from T_Bus_RemindRecord where F_Type=1 and F_IsDelete=0 and  (F_Content != '推诿工单' or F_Content is null  ) and F_State not in (0,2) )";

                        }
                    }
                   
                    break;

            }
            
         
        
            if (strworkid.Trim() != "" && strworkid != "undefined")
            {
                sql += " and F_WorkOrderId like '%" + strworkid + "%' ";
            }
            if (strname.Trim() != "" && strname != "undefined")
            {
                sql += " and F_CusName like '%" + strname + "%' ";
            }
            if (islike > 0)
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
                }
            }
            else
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  = '" + strtel + "' or F_ConPhone like '" + strtel + "') ";
                }
            }
            string ComTitle = HttpUtility.UrlDecode(RequestString.GetQueryString("ComTitle"));
            string ComContent = HttpUtility.UrlDecode(RequestString.GetQueryString("ComContent"));
            string Result = HttpUtility.UrlDecode(RequestString.GetQueryString("Result"));
            if (ComTitle.Trim() != "" && ComTitle != "undefined")
            {
                sql += " and F_ComTitle like '%" + ComTitle + "%' ";
            }
            if (Result.Trim() != "" && Result != "undefined")
            {
                sql += " and F_Result like '%" + Result + "%' ";
            }
            if (ComContent.Trim() != "" && ComContent != "undefined")
            {
                sql += " and F_ComContent like '%" + ComContent + "%' ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%'" +
                     " or F_Result like  '%" + strkey + "%' ) ";
            }
            #region  坐席&调度员
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {//坐席
                var usercode = strusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in usercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_CreateUser in (" + newusercode + ") ";
                }
            }
            if (strddusercode.Trim() != "" && strddusercode != "undefined")
            {//调度员
                var ddusercode = strddusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in ddusercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_AssignUser in(" + newusercode + ") ";
                }
            }
            //if (strusercode.Trim() != "" && strusercode != "undefined")
            //{
            //    sql += " and F_CreateUser = '" + strusercode + "' ";
            //}
            #endregion

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            string sqlwheres = ""; string value = "";
            if (keyid != 0)
            {
                sqlwheres = " INNER JOIN[GetValueId]('" + keyid + "') Value on a.F_Key = Value.F_ValueId";
                //sql += "and (F_Key IN(  SELECT  F_ValueId from [GetValueId]('"+ keyid + "'))" +
                //  " or F_Key='" + keyid + "' )";
                value = " INNER JOIN[GetValueId]('" + keyid + "') Value on wo.F_Key = Value.F_ValueId";

            }
            if (type != 0)
            {
                sql += " and F_InfoType = '" + type + "' ";
            }
            if (bigtype != 0)
            {
                sql += " and F_InfoConBigType = '" + bigtype + "' ";
            }
            if (smalltype != 0)
            {
                sql += " and F_InfoConSmallType = '" + smalltype + "' ";
            }
            if (sourcearea != 0)
            {
                sql += " and F_SourceArea = '" + sourcearea + "' ";
            }

            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and F_CreateTime>='" + strstarttime + "' ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and F_CreateTime<='" + strendtime + "' ";
            }
            if (deptid != 0 && strtab != "1")
            {
                if (deptlevel == 0)
                {
                    string sqlwhere = "select F_WorkOrderID from T_Bus_AssignedInfo WITH(NOLOCK) where F_MainDeptId = '" + deptid + "' and F_IsSure in (0,1) and F_State=1 and F_IsDelete=0 ";
                    //string sqlwhere = "select F_WorkOrderID from T_Bus_AssignedInfo where ',' + F_MainDeptID + ',' like '%," + deptid.ToString() + ",%' and F_IsSure in (0,1) and F_State=1 and F_IsDelete=0 ";
                    sql += " and F_WorkOrderID in(" + sqlwhere + ")";
                }
                else
                {
                    //string sqlwhere = "select F_WorkOrderID from T_Bus_AssignedInfo_Next where ',' + F_MainDeptID + ',' like '%," + deptid.ToString() + ",%' and F_IsSure in (0,1) and F_State=1 and F_IsDelete=0 ";
                    string sqlwhere = "select F_WorkOrderID from T_Bus_AssignedInfo_Next WITH(NOLOCK) where F_MainDeptId = '" + deptid + "' and F_IsSure in (0,1) and F_State=1 and F_IsDelete=0 ";
                    sql += " and F_WorkOrderID in(" + sqlwhere + ")";
                }
            }
            if (deptid != 0)
            {
                sql += " and  (F_MainDeptId = '" + deptid + "' or F_MainDeptID3='" + deptid + "')";
            }
            else
            {
                if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "EJWLDW")
                {
                    deptid = User.F_DeptId;
                    sql += " and  (F_MainDeptId = '" + deptid + "' or F_MainDeptID3='" + deptid + "')";
                }
            }

            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }

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

            //string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetOverState(F_WorkOrderId) as OverState,"
            //    + "dbo.GetDictionaryName(F_InfoSource) as SourceName,dbo.GetWorkOrderAssign(F_WorkOrderId) as DeptName ,dbo.GetLimitTime(F_WorkOrderId) as LimitTime";
            //string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName";
            string cols = "";
            if (strtab == "10")
            {
                cols = "F_WorkOrderId,F_CusName,F_ComTitle,F_WorkState,F_MainDeptId,F_OtherDeptIds,F_DealTime,F_LeaveRecordId,F_CallRecordId,F_IsResult,F_IsProtect,F_IsReturn,F_CreateTime,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName, dbo.GetDictionaryName(F_InfoSource) as SourceName,F_CloseTime,F_ComContent,F_Identification,F_IsRelease";
            }
          
            else
            {
                cols = "F_WorkOrderId,F_CusName,F_ComTitle,F_WorkState,F_MainDeptId,F_OtherDeptIds,F_DealTime,F_LeaveRecordId,F_CallRecordId,F_IsResult,F_IsProtect,F_IsReturn,F_CreateTime,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName, dbo.GetDeptNames(F_MainDeptId)as DeptNames,dbo.GetDictionaryName(F_InfoSource) as SourceName,F_CloseTime,F_ComContent,F_Identification,F_IsRelease";
            }
            if (isdc > 0)
            {
                var top = " "; var orderby = " order by F_CreateTime";
                if (sql == " and F_IsDelete=0 ")
                {
                    top = " top 1000 "; orderby += " desc ";
                }
                //20190715调整导出字段 zhengbingbing
                //日期，工单号，诉求标题，诉求内容，承办单位，办理结果，是否满意，备注
                var dtdc = DbHelperSQL.Query(" select " + top + " F_CreateTime 日期, F_WorkOrderId 工单号,F_ComTitle 诉求标题,F_ComContent 诉求内容,dbo.GetDictionaryName(F_Key) 主题词, "
                     + "  dbo.GetDeptNames(F_MainDeptId ) 主办单位, "
                    + " (select top 1 F_Result from T_Bus_Feedback WITH(NOLOCK) where F_State=1 and F_Type!=3 and F_IsDelete=0 and  F_WorkOrderId =wo.F_WorkOrderId order by F_Id desc) 办理结果, "
                    + " (select top 1 (case F_IsSatisfie when 1 then'满意' when 0 then '不满意' else '未评价' end) F_Satisfie from T_Bus_VisitResult WITH(NOLOCK) where F_State = 1 and F_IsDelete = 0 and F_WorkOrderId = wo.F_WorkOrderId order by F_Id desc) 是否满意 "
                    + " from T_Bus_WorkOrder wo WITH(NOLOCK)" + value + " where 1=1 " + sql + orderby).Tables[0];
                var msg = new NPOIHelper().ExportToExcel("工单列表", dtdc);
                if (msg == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }

            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_WorkOrder a WITH(NOLOCK)" + sqlwheres,
                "F_Id",
                cols,
                sql,
               order,
                pagesize,
                pageindex,
                true,
                out recordCount);

            #region 声音文件
            dt.Columns.Add("DeptName", typeof(string));//交办单位
            dt.Columns.Add("AssignTime", typeof(string));//交办时间
            dt.Columns.Add("OtherDeptName", typeof(string));//协办单位
            dt.Columns.Add("OverState", typeof(string));//超时状态
            dt.Columns.Add("LimitTime", typeof(string));//限制时间
            dt.Columns.Add("GapTime", typeof(string));//时间差
            dt.Columns.Add("FilePath", typeof(string));//语音文件路径
            dt.Columns.Add("Buttons", typeof(object));//操作按钮
            if (strtab == "10")
            {
                dt.Columns.Add("DeptNames", typeof(string));//退回部门
                dt.Columns.Add("Backreason", typeof(object));//退回原因
            }
            var configly = configBll.GetModelList(" F_ParamCode='PlayLeaveVoice' ").FirstOrDefault();
            var config = configBll.GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
            var configcs = configBll.GetModelList(" F_ParamCode='CSYJ' ").FirstOrDefault();
            var reminds = remindBLL.GetModelList("F_State=0 and F_IsDelete=0 and F_Type =1").ToList();
            foreach (DataRow dr in dt.Rows)
            {
                //获取最新交办信息
                string iszbdw = "0";
                int state = Int32.Parse(dr["F_WorkState"].ToString());
                if (state > 1 && state != 11)
                {
                    string sqljb = "SELECT TOP 1 * FROM T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' and F_State=1 and F_IsDelete=0 and F_IsSure<>3   ORDER BY F_Id DESC";
                    var dtjb = DbHelperSQL.Query(sqljb).Tables[0];
                    if (dtjb.Rows.Count > 0)
                    {
                        if (dtjb.Rows[0]["F_MainDeptId"].ToString() == User.F_DeptId.ToString()) { iszbdw = "1"; }
                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_MainDeptId"].ToString() + "')");
                        if (dtjb.Rows[0]["F_OtherDeptIds"] != null && dtjb.Rows[0]["F_OtherDeptIds"].ToString() != "")
                        {
                            dr["OtherDeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_OtherDeptIds"].ToString() + "')");
                        }
                        dr["AssignTime"] = dtjb.Rows[0]["F_CreateTime"].ToString();
                        #region
                        #endregion
                        #region
                        //if (state < 6 || state == 8)
                        if (state < (int)EnumWorkState.dealed || state == (int)EnumWorkState.reload)
                        {
                            var lt = dtjb.Rows[0]["F_LimitTime"].ToString();//限制时间
                            dr["LimitTime"] = lt;
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                if (ltime > DateTime.Now)
                                {
                                    string SY = "SELECT  COUNT(1)  FROM T_Sys_WorkOFFDays WHERE F_OffState =0    AND F_OffDate > '" + DateTime.Now.ToString("yyyy-MM-dd") + "' AND F_OffDate<'" + lt + "'";
                                    var SYSJ = DbHelperSQL.GetSingle(SY);
                                    if (!string.IsNullOrEmpty(SYSJ.ToString()))
                                    {
                                        try
                                        {
                                            ltime = ltime.AddDays(-int.Parse(SYSJ.ToString()));
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                                TimeSpan ts = ltime.Subtract(DateTime.Now);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime > DateTime.Now)
                                {
                                    if (configcs != null)
                                    {
                                        int cs = Int32.Parse(configcs.F_ParamValue);
                                        if (ts.TotalHours > cs)
                                        {
                                            dr["OverState"] = 1;
                                        }
                                        else
                                        {
                                            dr["OverState"] = 2;
                                        }
                                    }
                                    dr["GapTime"] = "剩余" + gshsj;
                                }
                                else
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                        }
                        if (state == (int)EnumWorkState.finish)
                        {
                            var closetime = dr["F_DealTime"].ToString();//关闭工单时间
                            var dttime = DateTime.Now;
                            if (!string.IsNullOrWhiteSpace(closetime)) { dttime = DateTime.Parse(closetime); }
                            else
                            {
                                var dealTime = dr["F_CloseTime"].ToString();//关闭工单时间
                                if (!string.IsNullOrWhiteSpace(dealTime)) { dttime = DateTime.Parse(dealTime); }
                            }


                            var lt = dtjb.Rows[0]["F_LimitTime"].ToString();//限制时间
                            dr["LimitTime"] = lt;
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                TimeSpan ts = ltime.Subtract(dttime);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime < dttime)
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dr["F_MainDeptId"].ToString() + "')");
                    }
                }
                if (strtab == "10")
                {
                    string strtu = " select top 1 dbo.GetDeptNames(F_CreateDeptId) as DeptNames ,F_Result   from T_Bus_Feedback WITH(NOLOCK)  where F_Type = 3 and F_IsAudit = 1 and F_WorkOrderId = '" + dr["F_WorkOrderId"].ToString() + "'  order by  F_CreateTime desc";
                    var tu = DbHelperSQL.Query(strtu).Tables[0];
                    if (tu.Rows.Count > 0)
                    {
                        dr["DeptNames"] = tu.Rows[0]["DeptNames"].ToString();
                        dr["Backreason"] = tu.Rows[0]["F_Result"].ToString();
                    }
                }
                else
                {
                    if (dr["F_LeaveRecordId"] != null && dr["F_LeaveRecordId"].ToString() != "")
                    {
                        dr["FilePath"] = GetLeavePath(dr["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                    }
                    else if (dr["F_CallRecordId"] != null && dr["F_CallRecordId"].ToString() != "")
                    {
                        dr["FilePath"] = GetCallPath(dr["F_CallRecordId"].ToString(), config.F_ParamValue);
                    }
                }
                List<ButtonGroup.button> btns = new List<ButtonGroup.button>();
                if (Int32.Parse(strtab) <= 1 || Int32.Parse(strtab) == 11 || Int32.Parse(strtab) == 10)
                {
                    btns = ButtonGroup.GetButtons(dr["F_WorkState"].ToString(), User.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString(), iszbdw,"",0,"",issh );
                    #region 判断是否存在待督办
                    var recount = reminds.Where(r => r.F_WorkOrderId == dr["F_WorkOrderId"].ToString()).Count();
                    var butt = btns.Find(c => c.key == ButtonGroup.turnsee().key);
                    if (recount > 0 && butt != null)
                        btns.Remove(butt);
                    if (User.F_RoleCode.ToUpper() == "ZJZY" || User.F_RoleCode.ToUpper() == "MTDD" || User.F_RoleCode.ToUpper() == "GLY" || User.F_RoleCode.ToUpper() == "ZXLD" || User.F_RoleCode.ToUpper() == "DDZG")
                    {
                     if (   Int32.Parse(strtab) != 11)
                        btns.Add(ButtonGroup.turnsee());
                    }

                    if (User.F_RoleCode.ToUpper() == "MTDD" && strtab=="0"&&issh ==2)
                    {
                        btns.Add(ButtonGroup.AuditDispatch());
                        btns.Add(ButtonGroup.Failed());
                        var butt1 = btns.Find(c => c.key == ButtonGroup.reject().key);
                        if (butt1 != null)
                            btns.Remove(butt1);
                        var butt2 = btns.Find(c => c.key == ButtonGroup.reload().key);
                        if (butt2 != null)
                            btns.Remove(butt2);
                       
                    }
                    if (strtab == "0" && issh == 2)
                    {
                        dr["DeptName"] = DbHelperSQL.GetSingle("  select [dbo].[GetDeptNames]( (select top 1  F_MainDeptId  from T_Bus_ToExamine where F_WorkOrderId ='" + dr["F_WorkOrderId"].ToString() + "' and F_IsDelete = 0 and F_MainDeptId is not null and F_State = 0 and F_IsDelete = 0 and  F_AssignedId = 0and F_MainDeptId != '' order by F_ID desc))");
                    }
                    #endregion
                }
                else
                {
                    btns.Clear();
                    if (Int32.Parse(strtab) == 8)
                        btns = ButtonGroup.GetButtons("12", User.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString(), iszbdw);
                    else
                        btns.Add(ButtonGroup.query());
                    if (Int32.Parse(strtab) != 4)
                    {
                        if (state == 9)
                        {
                            if (User.F_RoleCode.ToUpper() == "GNZY")
                            {
                                btns.Add(ButtonGroup.modify());
                            }
                            if (User.F_RoleCode.ToUpper() == "ZJZY" || User.F_RoleCode.ToUpper() == "GLY" || User.F_RoleCode.ToUpper() == "DDZG" || User.F_RoleCode.ToUpper() == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode.ToUpper() == "ZXHWY" || User.F_RoleCode.ToUpper() == "MTDD" )
                            {
                                //if (dr["F_CloseTime"] != null && dr["F_CloseTime"].ToString() != "")
                                //{
                                //    var closedttime = DateTime.Parse(dr["F_CloseTime"].ToString());
                                //    TimeSpan ts = DateTime.Now - closedttime;
                                //    if (ts.TotalDays < 20)
                                //    {
                                //        btns.Add(ButtonGroup.subreload());
                                //    }
                                //}
                                //btns.Add(ButtonGroup.Unsuccessful ());
                                if (User.F_RoleCode.ToUpper() != "ZXHWY")
                                    btns.Add(ButtonGroup.modify());

                            }
                        }
                    }



                }
                dr["Buttons"] = btns;
            }
            #endregion

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };
            return Content(obj.ToJson());
        }

        /// <summary>
        /// 获取单位处理列表
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetDWDealList(int isdc = 0)
        {

            DataTable dt = new DataTable();

            string sql = " and F_IsDelete=0";
            string strtab = HttpUtility.UrlDecode(RequestString.GetQueryString("tab"));
            string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
            int islike = RequestString.GetInt("islike", 1);
            string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
            string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
            string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));
            string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));
            string strddusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("ddusercode"));//调度员
            string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
            int source = RequestString.GetInt("source", 0);
            int keyid = RequestString.GetInt("keyid", 0);
            int type = RequestString.GetInt("type", 0);
            int bigtype = RequestString.GetInt("bigtype", 0);
            int smalltype = RequestString.GetInt("smalltype", 0);
            int sourcearea = RequestString.GetInt("sourcearea", 0);
            int deptid = RequestString.GetInt("deptid", 0);
            int ejdeptid = RequestString.GetInt("ejdeptid", 0);
            int deptlevel = RequestString.GetInt("deptlevel", 0);
            int distribute = RequestString.GetInt("distribute", -1);//0未派单1已派单
            int blstate = RequestString.GetInt("blstate", 0);//办理状态0办理中1已办理
            int isys = RequestString.GetInt("isys", -1);
            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;
            string order = "ORDER BY a.F_LimitTime";
            #region 模块
            switch (strtab)
            {
                case "0"://待处理工单
                    order = "order by F_Level desc, F_CreateTime desc ";
                    int isyq = RequestString.GetInt("isyq", -1);
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    else
                    {
                        if (distribute != 0)
                        {
                            int[] sts = new int[] { (int)EnumWorkState.receive, (int)EnumWorkState.dealing };
                            sql += " and F_WorkState in (" + string.Join(",", sts.Select(p => p.ToString())) + ")";
                    }


            }

                    sql += "and F_WorkOrderID  not in (select F_WorkOrderID from T_Bus_RemindRecord WITH(NOLOCK) where F_Type=1 and F_IsDelete=0 and F_State !=2)";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        if (distribute > -1)
                        {
                            if (distribute == 0)
                            {
                                sql += "and F_WorkOrderId in   (  select F_WorkOrderId from T_Bus_AssignedInfo as a  WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and ISNULL(F_FeedbackTime, '')='' and F_MainDeptId =" + User.F_DeptId + " and F_IsSure in (0,1) and (F_IsNext =" + distribute + " or  F_IsNext='' )and not exists(select 1 from T_Bus_AssignedInfo    WITH(NOLOCK) where F_WorkOrderId = a.F_WorkOrderId and F_Id > a.F_Id  )and (F_WorkState  in (2,4) or (F_WorkState=8 and F_Identification=0) ) ";

                                if (isys > -1)
                                {
                                    if (isys == 0)
                                    {
                                        sql += "and F_WorkOrderId not in (select F_WorkOrderID from T_Bus_DelayTime WITH(NOLOCK) where  F_IsDelete=0)";
                                    }
                                    else if (isys == 1)
                                    {
                                        sql += "and F_WorkOrderId  in (select F_WorkOrderID from T_Bus_DelayTime WITH(NOLOCK) where  F_IsDelete=0)";
                                    }
                                }

                            }
                            else
                            {
                                sql += "and F_WorkOrderId in(  select F_WorkOrderId from T_Bus_AssignedInfo as a  WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and ISNULL(F_FeedbackTime, '')=''and F_IsNext != '0' and  F_IsNext !='' and  F_IsNext <3 and F_MainDeptId =" + User.F_DeptId + " and F_IsSure in (0,1) and not exists(select 1 from T_Bus_AssignedInfo WITH(NOLOCK) where F_WorkOrderId = a.F_WorkOrderId and F_Id > a.F_Id  )) ";
                            }
                        }
                        else
                        {
                            sql += " and F_WorkOrderId in (select F_WorkOrderId from T_Bus_AssignedInfo WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and "
                      + " ISNULL(F_FeedbackTime, '')='' and F_MainDeptId =" + User.F_DeptId + " and F_IsSure in (0,1)";
                        }

                        if (isyq != -1)
                        {
                            sql += " and dbo.GetOverState(F_WorkOrderId)=" + isyq;
                        }
                        else
                        {
                            sql += ")";
                        }

                    }
                    break;
                case "1"://已查收的工单
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_AssignedInfo WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_IsSure=1 ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_SureUser='" + User.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "2"://已申请退回的工单
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_Feedback WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_Type = 3 ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG" && User.F_RoleCode != "ZXHWY" && User.F_RoleCode != "ZXLD" && User.F_RoleCode != "DDZG" && User.F_RoleCode != "MTDD")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "3"://已申请延时的工单

                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    else
                    {
                        if (blstate == 0)
                        {
                            sql += " and F_WorkState in (1,2,3,4,5,8,10,11,13) ";
                        }
                        else
                        {
                            sql += " and F_WorkState in (6,7,9) ";
                        }
                    }

                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_DelayTime WITH(NOLOCK) where  F_IsDelete=0 ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG" && User.F_RoleCode != "ZXHWY" && User.F_RoleCode != "ZXLD" && User.F_RoleCode != "DDZG" && User.F_RoleCode != "MTDD")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "4"://已办理的工单 
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_Feedback WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_Type in (1,2) and F_WorkState !='8' ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "5"://被督办的工单 
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_RemindRecord WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_Type =1 ";

                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_DeptId='" + User.F_DeptId + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "6"://被监察的工单 
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    //sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_RemindRecord where F_State=1 and F_IsDelete=0 and F_Type =2 ";
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_RemindRecord WITH(NOLOCK) where F_IsDelete=0 and F_Type =2 ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_DeptId='" + User.F_DeptId + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "7"://延时审核中的工单 
                    sql += " and F_WorkState = '" + (int)EnumWorkState.auditdelay + "' ";
                   
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "ZXLDGLY" && User.F_RoleCode != "ZXLDGLYGLY" && User.F_RoleCode != "DDZG" && User.F_RoleCode != "ZXLD" &&  User.F_RoleCode != "YSZY" && User.F_RoleCode != "MTDD" && User.F_RoleCode != "DMTCK")
                    {
                        sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_AssignedInfo WITH(NOLOCK) where F_State=1 and F_IsDelete=0 ";
                        sql += " and F_CreateUser='" + User.F_UserCode + "')";
                    }
                   
                    break;
                case "8"://退回审核中的工单 
                    sql += " and F_WorkState = '" + (int)EnumWorkState.auditreback + "' ";
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_AssignedInfo WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_IsSure=2 and isnull(F_FeedbackTime,'')=''";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_SureUser='" + User.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "9"://需履职界定表
                    sql += " and F_WorkState in ('" + (int)EnumWorkState.visit + "','" + (int)EnumWorkState.resubmit + "','" + (int)EnumWorkState.reload + "','" + (int)EnumWorkState.rejload + "','" + (int)EnumWorkState.finish + "' )";
                    sql += " and F_WorkOrderID not in(select F_WorkOrderID from T_Bus_PerformDuties WITH(NOLOCK) where F_IsDelete=0 and F_State=1 )";
                    sql += " and F_WorkOrderID in (select F_WorkOrderID from T_Bus_VisitResult WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_IsSatisfie=0 and F_AssignedId in(select F_ID from T_Bus_AssignedInfo WITH(NOLOCK) where F_State=1 and F_IsDelete=0   ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_MainDeptId='" + User.F_DeptId + "' ";
                    }
                    sql += "))";
                    break;
                case "10"://履职界定待审核表

                    sql += " and F_WorkOrderID in (select F_WorkOrderID from T_Bus_PerformDuties WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_IsAudit=0 )";
                    break;
                case "11"://履职界定已审核表

                    sql += " and F_WorkOrderID in (select F_WorkOrderID from T_Bus_PerformDuties WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_IsAudit>0 )";
                    break;
                case "12"://退回重办
                    sql += " and F_WorkState = '" + (int)EnumWorkState.reload + "' ";
                    //if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    //{
                    //    sql += " and F_WorkOrderId in (select F_WorkOrderId from T_Bus_AssignedInfo WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and "
                    //  + "  F_MainDeptId =" + User.F_DeptId + " and F_IsSure in (0,1))";
                    //}
                    sql += "and F_WorkOrderID  not in (select F_WorkOrderID from T_Bus_RemindRecord WITH(NOLOCK) where F_Type=1 and F_IsDelete=0 and F_State !=2)";
                    sql += "and (F_Identification!=0 or F_Identification is null) ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_WorkOrderId in (select F_WorkOrderId from T_Bus_AssignedInfo a  WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and "
                      + "  F_MainDeptId =" + User.F_DeptId + " and F_IsSure in (0,1)" +
                      "and ISNULL(F_FeedbackTime, '')='' and F_IsNext =0 and not exists(select  1 from T_Bus_AssignedInfo WITH(NOLOCK) where F_WorkOrderId = a.F_WorkOrderId and F_Id > a.F_Id ))  and F_MainDeptId = " + User.F_DeptId;


                    }


                    break;
                case "13"://下级单位退回
                          //  int[] st = new int[] { (int)EnumWorkState.receive, (int)EnumWorkState.dealing };
                    sql += " and F_WorkState in (2,4,8)";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += "and F_WorkOrderId in(  select F_WorkOrderId from T_Bus_AssignedInfo as a   WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and ISNULL(F_FeedbackTime, '')=''and F_IsNext =4 and F_MainDeptId in (" + User.F_DeptId + ")  and not exists(select 1 from T_Bus_AssignedInfo  where F_WorkOrderId = a.F_WorkOrderId and F_Id > a.F_Id  ))";
                    }
                    break;
                case "14"://正在办理
                    sql += " and F_WorkState in (2,4,8)";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += "and F_WorkOrderId in(  select F_WorkOrderId from T_Bus_AssignedInfo as a  WITH(NOLOCK)  where F_State=1 and F_IsDelete=0 and ISNULL(F_FeedbackTime, '')=''and F_IsNext != '0' and  F_IsNext !='' and  F_IsNext <3 and F_MainDeptId =" + User.F_DeptId + "  and not exists(select  1 from T_Bus_AssignedInfo WITH(NOLOCK) where F_WorkOrderId = a.F_WorkOrderId and F_Id > a.F_Id  ))";
                    }
                    break;
                case "15"://已办理提交
                    sql += " and F_WorkState in (4,8)";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += "and F_WorkOrderId in(  select F_WorkOrderId from T_Bus_AssignedInfo as a  WITH(NOLOCK)  where F_State=1 and F_IsDelete=0 and ISNULL(F_FeedbackTime, '')=''and F_IsNext = 3  and F_MainDeptId =" + User.F_DeptId + "  and not exists(select 1 from T_Bus_AssignedInfo WITH(NOLOCK) where F_WorkOrderId = a.F_WorkOrderId and F_Id > a.F_Id  )) ";
                    }
                    else
                    {
                        sql += "and F_WorkOrderId in(  select F_WorkOrderId from T_Bus_AssignedInfo as a  WITH(NOLOCK)  where F_State=1 and F_IsDelete=0 and ISNULL(F_FeedbackTime, '')=''and F_IsNext = 3  and not exists(select 1 from T_Bus_AssignedInfo WITH(NOLOCK) where F_WorkOrderId = a.F_WorkOrderId and F_Id > a.F_Id  )) ";
                    }
                    break;
                case "16"://退回被拒绝
                    sql += " and F_WorkState in (4,8)";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += "and F_WorkOrderId in(  select F_WorkOrderId from T_Bus_AssignedInfo as a  WITH(NOLOCK)  where F_State=1 and F_IsDelete=0 and ISNULL(F_FeedbackTime, '')=''  and F_MainDeptId =" + User.F_DeptId + "  and F_IsNext =0 and F_IsSure =4 and not exists(select 1 from T_Bus_AssignedInfo WITH(NOLOCK) where F_WorkOrderId = a.F_WorkOrderId and F_Id > a.F_Id  )) ";
                    }
                    break;
                case "17"://延时被拒绝
                   
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG" && User.F_RoleCode != "ZXHWY" && User.F_RoleCode != "ZXLD" && User.F_RoleCode != "DDZG" && User.F_RoleCode != "MTDD" && User.F_RoleCode != "DMTCK")
                    {
                        sql += " and F_WorkState in (4,8)";
                       
                        sql += "and F_WorkOrderId in(  select F_WorkOrderId from T_Bus_AssignedInfo as a  WITH(NOLOCK)  where F_State=1 and F_IsDelete=0 and ISNULL(F_FeedbackTime, '')='' and F_MainDeptId =" + User.F_DeptId + " and F_IsSure =5  and F_IsNext =0 and not exists(select 1 from T_Bus_AssignedInfo  WITH(NOLOCK) where F_WorkOrderId = a.F_WorkOrderId and F_Id > a.F_Id  ) )";
                    }
                    else  
                    {
                        sql += "and F_WorkOrderId in(  select F_WorkOrderId from T_Bus_AssignedInfo as a  WITH(NOLOCK)  where F_State=1 and F_IsDelete=0 and ISNULL(F_FeedbackTime, '')=''  and F_IsSure =5  and F_IsNext =0 and not exists(select 1 from T_Bus_AssignedInfo  WITH(NOLOCK) where F_WorkOrderId = a.F_WorkOrderId and F_Id > a.F_Id  ) )";
                    }
                    break;
                case "18"://已办理未果
                    sql += " and F_WorkState in(6,7,9)";
                    sql += " and F_IsProResult = '2' ";
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_Feedback WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_Type in (1,2) ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {

                        sql += " and F_MainDeptId='" + User.F_DeptId + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;

            }
            #endregion
            string splituser = HttpUtility.UrlDecode(RequestString.GetQueryString("splituser"));
            if (splituser.Trim() != "" && splituser != "undefined")
            {
                sql += " and F_SplitUser = '" + splituser + "' ";
            }
           
            string assuser = HttpUtility.UrlDecode(RequestString.GetQueryString("assuser"));
            if (assuser.Trim() != "" && assuser != "undefined")
            {
                sql += " and F_AssignUser = '" + assuser + "' ";
            }
            #region 条件
        
            if (strworkid.Trim() != "" && strworkid != "undefined")
            {
                sql += " and F_WorkOrderId like '%" + strworkid + "%' ";
            }
            if (strname.Trim() != "" && strname != "undefined")
            {
                sql += " and F_CusName like '%" + strname + "%' ";
            }
            if (islike > 0)
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
                }
            }
            else
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  = '" + strtel + "' or F_ConPhone like '" + strtel + "') ";
                }
            }
            string ComTitle = HttpUtility.UrlDecode(RequestString.GetQueryString("ComTitle"));
            string ComContent = HttpUtility.UrlDecode(RequestString.GetQueryString("ComContent"));
            string Result = HttpUtility.UrlDecode(RequestString.GetQueryString("Result"));
            if (ComTitle.Trim() != "" && ComTitle != "undefined")
            {
                sql += " and F_ComTitle like '%" + ComTitle + "%' ";
            }
            if (Result.Trim() != "" && Result != "undefined")
            {
                sql += " and F_Result like '%" + Result + "%' ";
            }
            if (ComContent.Trim() != "" && ComContent != "undefined")
            {
                sql += " and F_ComContent like '%" + ComContent + "%' ";
            }

            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%'" +
                     " or F_Result like  '%" + strkey + "%' ) ";
            }
            #region  坐席&调度员
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {//坐席
                var usercode = strusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in usercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_CreateUser in (" + newusercode + ") ";
                }
            }
            if (strddusercode.Trim() != "" && strddusercode != "undefined")
            {//调度员
                var ddusercode = strddusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in ddusercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_AssignUser in(" + newusercode + ") ";
                }
            }
            //if (strusercode.Trim() != "" && strusercode != "undefined")
            //{
            //    sql += " and F_CreateUser = '" + strusercode + "' ";
            //}
            #endregion

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            string sqlwhere = ""; string value = "";
            if (keyid != 0)
            {
                sqlwhere = " INNER JOIN[GetValueId]('" + keyid + "') Value on a.F_Key = Value.F_ValueId";
                //sql += "and (F_Key IN(  SELECT  F_ValueId from [GetValueId]('"+ keyid + "'))" +
                //  " or F_Key='" + keyid + "' )";
                value = " INNER JOIN[GetValueId]('" + keyid + "') Value on wo.F_Key = Value.F_ValueId";

            }
        

          

            if (type != 0)
            {
                sql += " and F_InfoType = '" + type + "' ";
            }
            if (bigtype != 0)
            {
                sql += " and F_InfoConBigType = '" + bigtype + "' ";
            }
            if (smalltype != 0)
            {
                sql += " and F_InfoConSmallType = '" + smalltype + "' ";
            }
            if (sourcearea != 0)
            {
                sql += " and F_SourceArea = '" + sourcearea + "' ";
            }
            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                if (strendtime.Trim() != "" && strendtime != "undefined")
                {
                    sql += " and F_CreateTime between  '" + strstarttime + "' and  '" + strendtime + "'";
                }
                else
                {
                    sql += " and F_CreateTime>='" + strstarttime + "' ";
                }
            }
            if (deptid != 0)
            {
                sql += " and  (F_MainDeptId = '" + deptid + "' or F_MainDeptID3='" + deptid + "')";
            }
            if (ejdeptid>0)
            {
                sql += "and F_MainDeptID3='" + ejdeptid + "'";
            }
            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }

            if (strpagesize.Trim() != "")
            {
                pagesize = Convert.ToInt32(strpagesize);
            }
            #endregion

            //string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetOverState(F_WorkOrderId) as OverState,"
            //    + "dbo.GetDictionaryName(F_InfoSource) as SourceName,dbo.GetWorkOrderAssign(F_WorkOrderId) as DeptName ,dbo.GetLimitTime(F_WorkOrderId) as LimitTime";
            //string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName";
            string cols = "F_WorkOrderId,F_CusName,F_ComTitle,F_WorkState,F_MainDeptId,F_OtherDeptIds,F_DealTime,F_LeaveRecordId,F_CallRecordId,F_IsResult,F_IsProtect,F_IsReturn,F_CreateTime,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName,dbo.GetDeptNames(F_MainDeptID3) AS EJDeptName,F_CloseTime,F_IsRelease,F_Identification,F_IsRelease";
            if (isdc > 0)
            {
                var top = " "; var orderby = " order by F_CreateTime";
                if (sql == " and F_IsDelete=0 ")
                {
                    top = " top 1000 "; orderby += " desc ";
                }
                //20190715调整导出字段 zhengbingbing
                //日期，工单号，诉求标题，诉求内容，承办单位，办理结果，是否满意，备注
                var dtdc = DbHelperSQL.Query(" select  F_CreateTime 日期, F_WorkOrderId 工单号,F_ComTitle 诉求标题,F_ComContent 诉求内容,dbo.GetDictionaryName(F_Key) 主题词, "
                    + "  dbo.GetDeptNames(F_MainDeptId ) 主办单位, "

                    + " F_Result 办理结果 "
                    + " from T_Bus_WorkOrder wo WITH(NOLOCK)" + value + " where 1=1 " + sql + orderby).Tables[0];
                var msg = new NPOIHelper().ExportToExcel("工单列表", dtdc);
                if (msg == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }

            int recordCount = 0;
            //二级单位待办事项、正在办理页面中，工单排列按照剩余时长来排序，超期最久的放在最上边，离办理时限最远的放在最后
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_WorkOrder a WITH(NOLOCK)" + sqlwhere,
                "F_Id",
                cols,
                sql,
                order,
                pagesize,
                pageindex,
                true,
                out recordCount);
            //二级单位待办事项、正在办理页面中，工单排列按照剩余时长来排序，超期最久的放在最上边，离办理时限最远的放在最后
            #region 声音文件
            dt.Columns.Add("DeptName", typeof(string));//交办单位
            dt.Columns.Add("OtherDeptName", typeof(string));//协办单位
            dt.Columns.Add("AssignTime", typeof(string));//交办时间
            dt.Columns.Add("OverState", typeof(string));//超时状态
            dt.Columns.Add("LimitTime", typeof(string));//限制时间
            dt.Columns.Add("GapTime", typeof(string));//时间差
            dt.Columns.Add("FilePath", typeof(string));//语音文件路径
            dt.Columns.Add("PDState", typeof(string));//派单状态
            dt.Columns.Add("Buttons", typeof(object));//操作按钮

            var configly = configBll.GetModelList(" F_ParamCode='PlayLeaveVoice' ").FirstOrDefault();
            var config = configBll.GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
            var configcs = configBll.GetModelList(" F_ParamCode='CSYJ' ").FirstOrDefault();
            var reminds = remindBLL.GetModelList("F_State=0 and F_IsDelete=0 and F_Type =1").ToList();
            foreach (DataRow dr in dt.Rows)
            {
                //获取最新交办信息
                string iszbdw = "0";
                string ispd = "";
                int state = Int32.Parse(dr["F_WorkState"].ToString());
                if (state > 1)
                {


                    string sqljb = "SELECT TOP 1 * FROM T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' and F_State=1 and F_IsDelete=0 and F_IsSure<>3   ORDER BY F_Id DESC";
                    var dtjb = DbHelperSQL.Query(sqljb).Tables[0];
                    if (dtjb.Rows.Count > 0)

                    {
                        if (dtjb.Rows[0]["F_MainDeptId"].ToString() == User.F_DeptId.ToString()) { iszbdw = "1"; }
                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_MainDeptId"].ToString() + "')");
                        if (dtjb.Rows[0]["F_OtherDeptIds"] != null && dtjb.Rows[0]["F_OtherDeptIds"].ToString() != "")
                        {
                            dr["OtherDeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_OtherDeptIds"].ToString() + "')");
                        }
                        dr["AssignTime"] = dtjb.Rows[0]["F_CreateTime"].ToString();
                        #region
                        //int did = Int32.Parse(dtjb.Rows[0]["F_MainDeptId"].ToString());
                        //var deptinfo = new BLL.T_Sys_Department().GetModel(did);
                        //if (deptinfo != null)
                        //{
                        //    if (did == User.F_DeptId) { iszbdw = "1"; }
                        //    dr["DeptName"] = deptinfo.F_DeptName;//交办单位
                        //}

                        //if (dtjb.Rows[0]["F_OtherDeptIds"] != null && dtjb.Rows[0]["F_OtherDeptIds"].ToString() != "")
                        //{
                        //    string[] strids = dtjb.Rows[0]["F_OtherDeptIds"].ToString().Split(',');
                        //    string dns = string.Empty;
                        //    foreach (string strid in strids)
                        //    {
                        //        var dinfo = new BLL.T_Sys_Department().GetModel(Int32.Parse(strid));
                        //        if (dinfo != null)
                        //        {
                        //            if (string.IsNullOrEmpty(dns))
                        //            {
                        //                dns = dinfo.F_DeptName;//交办单位
                        //            }
                        //            else
                        //            {
                        //                dns += "," + dinfo.F_DeptName;//交办单位
                        //            }
                        //        }
                        //    }
                        //    dr["OtherDeptName"] = dns;
                        //}
                        #endregion
                        #region
                        //if (state < 6 || state == 8)
                        if (state < (int)EnumWorkState.dealed || state == (int)EnumWorkState.reload)
                        {
                            var lt = dtjb.Rows[0]["F_LimitTime"].ToString();//限制时间
                            dr["LimitTime"] = lt;
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                if (ltime > DateTime.Now)
                                {
                                    string SY = "SELECT  COUNT(1)  FROM T_Sys_WorkOFFDays WITH(NOLOCK) WHERE F_OffState =0    AND F_OffDate > '" + DateTime.Now.ToString("yyyy-MM-dd") + "' AND F_OffDate<'" + lt + "'";
                                    var SYSJ = DbHelperSQL.GetSingle(SY);
                                    if (!string.IsNullOrEmpty(SYSJ.ToString()))
                                    {
                                        try
                                        {
                                            ltime = ltime.AddDays(-int.Parse(SYSJ.ToString()));
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                                TimeSpan ts = ltime.Subtract(DateTime.Now);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime > DateTime.Now)
                                {
                                    if (configcs != null)
                                    {
                                        int cs = Int32.Parse(configcs.F_ParamValue);
                                        if (ts.TotalHours > cs)
                                        {
                                            dr["OverState"] = 1;
                                        }
                                        else
                                        {
                                            dr["OverState"] = 2;
                                        }
                                    }
                                    dr["GapTime"] = "剩余" + gshsj;
                                }
                                else
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }

                            ispd = dtjb.Rows[0]["F_IsNext"].ToString();
                            dr["PDState"] = ispd;
                        }
                        if (state == (int)EnumWorkState.finish)
                        {
                            var closetime = dr["F_DealTime"].ToString();//关闭工单时间
                            var dttime = DateTime.Now;
                            if (!string.IsNullOrWhiteSpace(closetime)) { dttime = DateTime.Parse(closetime); }
                            else
                            {
                                var DealTime = dr["F_CloseTime"].ToString();
                                if (!string.IsNullOrWhiteSpace(DealTime)) { dttime = DateTime.Parse(DealTime); }
                            }
                            var lt = dtjb.Rows[0]["F_LimitTime"].ToString();//限制时间
                            dr["LimitTime"] = lt;
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                TimeSpan ts = ltime.Subtract(dttime);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime < dttime)
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                        }
                        #endregion
                    }
                    else
                    {

                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dr["F_MainDeptId"].ToString() + "')");
                    }
                }
                if (User.F_RoleCode.ToUpper() == "WLDW" || User.F_RoleCode.ToUpper() == "EJWLDW")
                {
                    if (dr["EJDeptName"] != null && dr["EJDeptName"].ToString() != "")
                        dr["DeptName"] = dr["EJDeptName"].ToString();
                }
                if (dr["F_LeaveRecordId"] != null && dr["F_LeaveRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetLeavePath(dr["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                }
                else if (dr["F_CallRecordId"] != null && dr["F_CallRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetCallPath(dr["F_CallRecordId"].ToString(), config.F_ParamValue);
                }

                //string sqlpd = "SELECT TOP 1 * FROM T_Bus_AssignedInfo_Next WHERE F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' and F_State=1 and F_IsDelete=0 ORDER BY F_Id DESC";
                //var dtpd = DbHelperSQL.Query(sqlpd).Tables[0];

                List<ButtonGroup.button> btns = new List<ButtonGroup.button>();
                if (Int32.Parse(strtab) < 1 || Int32.Parse(strtab) == 16 || Int32.Parse(strtab) == 17)
                {
                    btns = ButtonGroup.GetButtons(dr["F_WorkState"].ToString(), User.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString(), iszbdw, ispd);
                    #region 判断是否存在待督办
                    var recount = reminds.Where(r => r.F_WorkOrderId == dr["F_WorkOrderId"].ToString()).Count();
                    var butt = btns.Find(c => c.key == ButtonGroup.turnsee().key);
                    if (recount > 0 && butt != null)
                        btns.Remove(butt);
                    #endregion
                }
                else
                {
                    if (Int32.Parse(strtab) == 9)
                    {//需履职界定
                        btns.Add(ButtonGroup.query());
                        btns.Add(ButtonGroup.perform());
                    }
                    else if (Int32.Parse(strtab) == 10)
                    {//履职界定待审核
                        btns.Add(ButtonGroup.query());
                        btns.Add(ButtonGroup.performaudit());
                    }
                    else if (Int32.Parse(strtab) == 7)
                    {//履职界定待审核
                        btns = ButtonGroup.GetButtons(dr["F_WorkState"].ToString(), User.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString(), iszbdw, ispd);
                    }
                    else if (Int32.Parse(strtab) == 12)
                    {//退回重办
                        btns = ButtonGroup.GetButtons(dr["F_WorkState"].ToString(), User.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString());
                        var reback = btns.Find(c => c.key == ButtonGroup.reback().key);
                        if (reback != null)
                            btns.Remove(reback);
                    }
                    else if (Int32.Parse(strtab) == 14)
                    {//正在办理
                        btns.Add(ButtonGroup.query());
                        btns.Add(ButtonGroup.withdraw());
                    }
                    else if (Int32.Parse(strtab) == 13)
                    {//下级单位退回
                        btns.Add(ButtonGroup.query());
                        btns.Add(ButtonGroup.split());//转派
                      //  btns.Add(ButtonGroup.reback());//
                        btns.Add(ButtonGroup.turndown());
                    }
                    else if (Int32.Parse(strtab) == 15)
                    {//已办理提交
                        if (ispd == "3")
                        {
                            btns.Add(ButtonGroup.auditdeal());
                        }
                        btns.Add(ButtonGroup.feedback());//
                        btns.Add(ButtonGroup.redo());//
                        btns.Add(ButtonGroup.query());
                    }
                    else
                        btns.Add(ButtonGroup.query());
                }
                dr["Buttons"] = btns;
            }
            #endregion

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };

            return Content(obj.ToJson());
        }
        /// <summary>
        /// 添加工单信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult AddWorkOrderOper()
        {

            string workorderid = RequestString.GetFormString("workorderid");
            string remarks = RequestString.GetFormString("remarks");
            Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
            if (modelT_Bus_WorkOrder != null)
            {
                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_CallRecordId = modelT_Bus_WorkOrder.F_CallRecordId;
                oper.F_File = modelT_Bus_WorkOrder.F_File;

                string userinfo = User.depname + "-" + User.F_UserName + "(" + User.F_UserCode + ")";
                oper.F_Message = userinfo + " 办理了工单：" + remarks;

                oper.F_CreateUser = User.F_UserCode;
                oper.F_CreateTime = DateTime.Now;
                oper.F_IsDelete = 0;

                if (operBLL.Add(oper) > 0)
                    return Success("操作成功");
                else
                    return Error("操作失败");
            }
            else
            {
                return Error("工单不存在");
            }

        }
        /// <summary>
        /// 获取单位处理列表
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetXBDWDealList(int isdc = 0)
        {

            DataTable dt = new DataTable();
            string sql = " and F_IsDelete=0";
            string strtab = HttpUtility.UrlDecode(RequestString.GetQueryString("tab"));
            string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
            int islike = RequestString.GetInt("islike", 1);
            string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
            string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
            string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));
            string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));
            string strddusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("ddusercode"));//调度员
            string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));

            int source = RequestString.GetInt("source", 0);
            int keyid = RequestString.GetInt("keyid", 0);
            int type = RequestString.GetInt("type", 0);
            int bigtype = RequestString.GetInt("bigtype", 0);
            int smalltype = RequestString.GetInt("smalltype", 0);
            int sourcearea = RequestString.GetInt("sourcearea", 0);
            int deptid = RequestString.GetInt("deptid", 0);

            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;

            switch (strtab)
            {
                case "0"://待处理工单
                    int isyq = RequestString.GetInt("isyq", -1);
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    else
                    {
                        int[] sts = new int[] { (int)EnumWorkState.receive, (int)EnumWorkState.dealing, (int)EnumWorkState.reload };
                        sql += " and F_WorkState in (" + string.Join(",", sts.Select(p => p.ToString())) + ")";
                        //sql += " and F_WorkState in (2,4,8)";
                    }

                    sql += " and F_WorkOrderId in (select F_WorkOrderId from T_Bus_AssignedItemInfo WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and "
                    + " ISNULL(F_FeedbackTime, '')='' ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_DeptId =" + User.F_DeptId;
                    }
                    if (isyq != -1)
                    {
                        sql += " and dbo.GetOverState(F_WorkOrderId)=" + isyq;
                    }
                    else
                    {
                        sql += ")";
                    }

                    break;
                case "1"://已办理的工单 
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_Feedback WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_Type in (1,2) ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
            }
            if (deptid != 0)
            {
                sql += " and  (F_MainDeptId = '" + deptid + "' or F_MainDeptID3='" + deptid + "')";
            }
         
           
            if (strworkid.Trim() != "" && strworkid != "undefined")
            {
                sql += " and F_WorkOrderId like '%" + strworkid + "%' ";
            }
            if (strname.Trim() != "" && strname != "undefined")
            {
                sql += " and F_CusName like '%" + strname + "%' ";
            }
            if (islike > 0)
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
                }
            }
            else
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  = '" + strtel + "' or F_ConPhone like '" + strtel + "') ";
                }
            }
            string ComTitle = HttpUtility.UrlDecode(RequestString.GetQueryString("ComTitle"));
            string ComContent = HttpUtility.UrlDecode(RequestString.GetQueryString("ComContent"));
            string Result = HttpUtility.UrlDecode(RequestString.GetQueryString("Result"));
            if (ComTitle.Trim() != "" && ComTitle != "undefined")
            {
                sql += " and F_ComTitle like '%" + ComTitle + "%' ";
            }
            if (Result.Trim() != "" && Result != "undefined")
            {
                sql += " and F_Result like '%" + Result + "%' ";
            }
            if (ComContent.Trim() != "" && ComContent != "undefined")
            {
                sql += " and F_ComContent like '%" + ComContent + "%' ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%'" +
                    " or F_Result like  '%" + strkey + "%' ) ";
            }
            #region  坐席&调度员
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {//坐席
                var usercode = strusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in usercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_CreateUser in (" + newusercode + ") ";
                }
            }
            if (strddusercode.Trim() != "" && strddusercode != "undefined")
            {//调度员
                var ddusercode = strddusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in ddusercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_AssignUser in(" + newusercode + ") ";
                }
            }
            //if (strusercode.Trim() != "" && strusercode != "undefined")
            //{
            //    sql += " and F_CreateUser = '" + strusercode + "' ";
            //}
            #endregion

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            string sqlwhere = "";
            if (keyid != 0)
            {
                sqlwhere = " INNER JOIN[GetValueId]('" + keyid + "') Value on a.F_Key = Value.F_ValueId";
                //sql += "and (F_Key IN(  SELECT  F_ValueId from [GetValueId]('"+ keyid + "'))" +
                //  " or F_Key='" + keyid + "' )";


            }
            if (type != 0)
            {
                sql += " and F_InfoType = '" + type + "' ";
            }
            if (bigtype != 0)
            {
                sql += " and F_InfoConBigType = '" + bigtype + "' ";
            }
            if (smalltype != 0)
            {
                sql += " and F_InfoConSmallType = '" + smalltype + "' ";
            }
            if (sourcearea != 0)
            {
                sql += " and F_SourceArea = '" + sourcearea + "' ";
            }
            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and F_CreateTime>='" + strstarttime + "' ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and F_CreateTime<='" + strendtime + "' ";
            }

            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }

            if (strpagesize.Trim() != "")
            {
                pagesize = Convert.ToInt32(strpagesize);
            }
            //string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetOverState(F_WorkOrderId) as OverState,"
            //    + "dbo.GetDictionaryName(F_InfoSource) as SourceName,dbo.GetWorkOrderAssign(F_WorkOrderId) as DeptName ,dbo.GetLimitTime(F_WorkOrderId) as LimitTime";
            //string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName";
            string cols = "F_WorkOrderId,F_ComTitle,F_WorkState,F_MainDeptId,F_OtherDeptIds,F_DealTime,F_LeaveRecordId,F_CallRecordId,F_IsResult,F_IsProtect,F_IsReturn,F_CreateTime,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName,F_CloseTime,F_Identification";
            if (isdc > 0)
            {
                var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder WITH(NOLOCK) where 1=1 " + sql).Tables[0];
                var msg = new NPOIHelper().ExportToExcel("工单列表", dtdc);
                if (msg == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }

            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_WorkOrder a WITH(NOLOCK)" + sqlwhere,
                "F_Id",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);

            #region 声音文件
            dt.Columns.Add("DeptName", typeof(string));//交办单位
            dt.Columns.Add("OtherDeptName", typeof(string));//协办单位
            dt.Columns.Add("AssignTime", typeof(string));//交办时间
            dt.Columns.Add("OverState", typeof(string));//超时状态
            dt.Columns.Add("LimitTime", typeof(string));//限制时间
            dt.Columns.Add("GapTime", typeof(string));//时间差
            dt.Columns.Add("FilePath", typeof(string));//语音文件路径
            dt.Columns.Add("Buttons", typeof(object));//操作按钮
            var configly = configBll.GetModelList(" F_ParamCode='PlayLeaveVoice' ").FirstOrDefault();
            var config = configBll.GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
            var configcs = configBll.GetModelList(" F_ParamCode='CSYJ' ").FirstOrDefault();
            var reminds = remindBLL.GetModelList("F_State=0 and F_IsDelete=0 and F_Type =1").ToList();
            foreach (DataRow dr in dt.Rows)
            {
                //获取最新交办信息
                string iszbdw = "0";
                string ispd = "";
                int state = Int32.Parse(dr["F_WorkState"].ToString());
                if (state > 1)
                {
                    string sqljb = "SELECT TOP 1 * FROM T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' and F_State=1 and F_IsDelete=0 and F_IsSure<>3   ORDER BY F_Id DESC";
                    var dtjb = DbHelperSQL.Query(sqljb).Tables[0];
                    if (dtjb.Rows.Count > 0)
                    {
                        if (dtjb.Rows[0]["F_MainDeptId"].ToString() == User.F_DeptId.ToString()) { iszbdw = "1"; }

                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_MainDeptId"].ToString() + "')");
                        if (dtjb.Rows[0]["F_OtherDeptIds"] != null && dtjb.Rows[0]["F_OtherDeptIds"].ToString() != "")
                        {
                            dr["OtherDeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_OtherDeptIds"].ToString() + "')");


                        }
                        dr["AssignTime"] = dtjb.Rows[0]["F_CreateTime"].ToString();
                        #region
                        //int did = Int32.Parse(dtjb.Rows[0]["F_MainDeptId"].ToString());
                        //var deptinfo = new BLL.T_Sys_Department().GetModel(did);
                        //if (deptinfo != null)
                        //{
                        //    if (did == User.F_DeptId) { iszbdw = "1"; }
                        //    dr["DeptName"] = deptinfo.F_DeptName;//交办单位
                        //}

                        //if (dtjb.Rows[0]["F_OtherDeptIds"] != null && dtjb.Rows[0]["F_OtherDeptIds"].ToString() != "")
                        //{
                        //    string[] strids = dtjb.Rows[0]["F_OtherDeptIds"].ToString().Split(',');
                        //    string dns = string.Empty;
                        //    foreach (string strid in strids)
                        //    {
                        //        var dinfo = new BLL.T_Sys_Department().GetModel(Int32.Parse(strid));
                        //        if (dinfo != null)
                        //        {
                        //            if (string.IsNullOrEmpty(dns))
                        //            {
                        //                dns = dinfo.F_DeptName;//交办单位
                        //            }
                        //            else
                        //            {
                        //                dns += "," + dinfo.F_DeptName;//交办单位
                        //            }
                        //        }
                        //    }
                        //    dr["OtherDeptName"] = dns;
                        //}
                        #endregion
                        #region
                        //if (state < 6 || state == 8)
                        if (state < (int)EnumWorkState.dealed || state == (int)EnumWorkState.reload)
                        {
                            var lt = dtjb.Rows[0]["F_LimitTime"].ToString();//限制时间
                            dr["LimitTime"] = lt;
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                if (ltime > DateTime.Now)
                                {
                                    string SY = "SELECT  COUNT(1)  FROM T_Sys_WorkOFFDays WHERE F_OffState =0    AND F_OffDate > '" + DateTime.Now.ToString("yyyy-MM-dd") + "' AND F_OffDate<'" + lt + "'";
                                    var SYSJ = DbHelperSQL.GetSingle(SY);
                                    if (!string.IsNullOrEmpty(SYSJ.ToString()))
                                    {
                                        try
                                        {
                                            ltime = ltime.AddDays(-int.Parse(SYSJ.ToString()));
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                                TimeSpan ts = ltime.Subtract(DateTime.Now);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime > DateTime.Now)
                                {
                                    if (configcs != null)
                                    {
                                        int cs = Int32.Parse(configcs.F_ParamValue);
                                        if (ts.TotalHours > cs)
                                        {
                                            dr["OverState"] = 1;
                                        }
                                        else
                                        {
                                            dr["OverState"] = 2;
                                        }
                                    }
                                    dr["GapTime"] = "剩余" + gshsj;
                                }
                                else
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                            ispd = dtjb.Rows[0]["F_IsNext"].ToString();
                        }
                        if (state == (int)EnumWorkState.finish)
                        {
                            var closetime = dr["F_DealTime"].ToString();//关闭工单时间
                            var dttime = DateTime.Now;
                            if (!string.IsNullOrWhiteSpace(closetime)) { dttime = DateTime.Parse(closetime); }
                            else
                            {
                                var DealTime = dr["F_CloseTime"].ToString();
                                if (!string.IsNullOrWhiteSpace(DealTime)) { dttime = DateTime.Parse(DealTime); }
                            }
                            var lt = dtjb.Rows[0]["F_LimitTime"].ToString();//限制时间
                            dr["LimitTime"] = lt;
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                TimeSpan ts = ltime.Subtract(dttime);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime < dttime)
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                        }
                        #endregion
                    }
                    else
                    {

                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dr["F_MainDeptId"].ToString() + "')");
                    }
                }
                if (dr["F_LeaveRecordId"] != null && dr["F_LeaveRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetLeavePath(dr["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                }
                else if (dr["F_CallRecordId"] != null && dr["F_CallRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetCallPath(dr["F_CallRecordId"].ToString(), config.F_ParamValue);
                }

                List<ButtonGroup.button> btns = new List<ButtonGroup.button>();
                if (Int32.Parse(strtab) < 1)
                {
                    btns = ButtonGroup.GetButtons(dr["F_WorkState"].ToString(), User.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString(), iszbdw, ispd);
                    #region 判断是否存在待督办
                    var recount = reminds.Where(r => r.F_WorkOrderId == dr["F_WorkOrderId"].ToString()).Count();
                    var butt = btns.Find(c => c.key == ButtonGroup.turnsee().key);
                    if (recount > 0 && butt != null)
                        btns.Remove(butt);
                    #endregion
                }
                else
                {
                    btns.Add(ButtonGroup.query());
                }
                dr["Buttons"] = btns;
            }
            #endregion

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };

            return Content(obj.ToJson());
        }

        /// <summary>
        /// 获取单位主办协办未处理工单列表
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetDWNoDealList(int isdc = 0)
        {
            DataTable dt = new DataTable();





            string sql = " and F_IsDelete=0";
            string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
            int islike = RequestString.GetInt("islike", 1);
            string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
            string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
            string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));
            string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));
            string strddusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("ddusercode"));//调度员
            string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));

            int source = RequestString.GetInt("source", 0);
            int keyid = RequestString.GetInt("keyid", 0);
            int type = RequestString.GetInt("type", 0);
            int bigtype = RequestString.GetInt("bigtype", 0);
            int smalltype = RequestString.GetInt("smalltype", 0);
            int sourcearea = RequestString.GetInt("sourcearea", 0);
            int deptid = RequestString.GetInt("deptid", 0);

            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;
           
            if (User.F_RoleCode == "ZXHWY")
            {
                sql += " and F_CreateUser = '" + User.F_UserCode + "' ";
            }
            #region  坐席&调度员
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {//坐席
                var usercode = strusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in usercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_CreateUser in (" + newusercode + ") ";
                }
            }
            if (strddusercode.Trim() != "" && strddusercode != "undefined")
            {//调度员
                var ddusercode = strddusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in ddusercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_AssignUser in(" + newusercode + ") ";
                }
            }
            //if (strusercode.Trim() != "" && strusercode != "undefined")
            //{
            //    sql += " and F_CreateUser = '" + strusercode + "' ";
            //}
            #endregion

          
            sql += " and ( F_WorkOrderId in (select F_WorkOrderId  from T_Bus_AssignedInfo WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and isnull(F_FeedbackTime,'')='' and F_IsSure in (0,1) ";

            if (User.F_RoleCode == "WLDW")
            {
                sql += " and  (F_MainDeptId = '" + User.F_DeptId + "'  or F_MainDeptID3='" + User.F_DeptId + "')";
            }
            else if (deptid != 0)
            {
                sql += " and (F_MainDeptId = '" + deptid + "' or F_MainDeptID3='" + deptid + "')";
            }

            sql += ") or F_WorkOrderId in (select F_WorkOrderId from T_Bus_AssignedItemInfo WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and ISNULL(F_FeedbackTime, '')='' ";

            if (User.F_RoleCode == "WLDW")
            {
                sql += " and  (F_DeptId = '" + User.F_DeptId + "' or F_MainDeptID3='" + User.F_DeptId + "')";
            }
            else if (deptid != 0)
            {
                sql += " and  (F_MainDeptId = '" + deptid + "' or F_MainDeptID3='" + deptid + "')";
            }

            sql += "))";

            if (strstate.Trim() != "" && strstate != "undefined")
            {
                if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                    sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                else
                    sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
            }
            else
            {
                sql += " and F_WorkState in (2,4,8)";
            }
            if (strworkid.Trim() != "" && strworkid != "undefined")
            {
                sql += " and F_WorkOrderId like '%" + strworkid + "%' ";
            }
            if (strname.Trim() != "" && strname != "undefined")
            {
                sql += " and F_CusName like '%" + strname + "%' ";
            }
            if (islike > 0)
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
                }
            }
            else
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  = '" + strtel + "' or F_ConPhone like '" + strtel + "') ";
                }
            }
            string ComTitle = HttpUtility.UrlDecode(RequestString.GetQueryString("ComTitle"));
            string ComContent = HttpUtility.UrlDecode(RequestString.GetQueryString("ComContent"));
            string Result = HttpUtility.UrlDecode(RequestString.GetQueryString("Result"));
            if (ComTitle.Trim() != "" && ComTitle != "undefined")
            {
                sql += " and F_ComTitle like '%" + ComTitle + "%' ";
            }
            if (Result.Trim() != "" && Result != "undefined")
            {
                sql += " and F_Result like '%" + Result + "%' ";
            }
            if (ComContent.Trim() != "" && ComContent != "undefined")
            {
                sql += " and F_ComContent like '%" + ComContent + "%' ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%'" +
                      " or F_Result like  '%" + strkey + "%' ) ";
            }

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            string sqlwhere = "";
            if (keyid != 0)
            {
                sqlwhere = " INNER JOIN[GetValueId]('" + keyid + "') Value on a.F_Key = Value.F_ValueId";
                //sql += "and (F_Key IN(  SELECT  F_ValueId from [GetValueId]('"+ keyid + "'))" +
                //  " or F_Key='" + keyid + "' )";
            }
            if (type != 0)
            {
                sql += " and F_InfoType = '" + type + "' ";
            }
            if (bigtype != 0)
            {
                sql += " and F_InfoConBigType = '" + bigtype + "' ";
            }
            if (smalltype != 0)
            {
                sql += " and F_InfoConSmallType = '" + smalltype + "' ";
            }
            if (sourcearea != 0)
            {
                sql += " and F_SourceArea = '" + sourcearea + "' ";
            }

            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and F_CreateTime>='" + strstarttime + "' ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and F_CreateTime<='" + strendtime + "' ";
            }

            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }

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

            //string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName ";
            string cols = "F_WorkOrderId,F_ComTitle,F_WorkState,F_MainDeptId,F_OtherDeptIds,F_DealTime,F_LeaveRecordId,F_CallRecordId,F_IsResult,F_IsProtect,F_IsReturn,F_CreateTime,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName,F_CloseTime,F_Identification";
            if (isdc > 0)
            {
                var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder WITH(NOLOCK) where 1=1 " + sql).Tables[0];
                var msg = new NPOIHelper().ExportToExcel("工单列表", dtdc);
                if (msg == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }

            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_WorkOrder a WITH(NOLOCK)" + sqlwhere,
                "F_Id",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);

            #region 声音文件
            dt.Columns.Add("DeptName", typeof(string));//交办单位
            dt.Columns.Add("OtherDeptName", typeof(string));//协办单位
            dt.Columns.Add("AssignTime", typeof(string));//交办时间
            dt.Columns.Add("OverState", typeof(string));//超时状态
            dt.Columns.Add("LimitTime", typeof(string));//限制时间
            dt.Columns.Add("GapTime", typeof(string));//时间差
            dt.Columns.Add("FilePath", typeof(string));
            dt.Columns.Add("Buttons", typeof(object));
            var configly = configBll.GetModelList(" F_ParamCode='PlayLeaveVoice' ").FirstOrDefault();
            var config = configBll.GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
            var configcs = configBll.GetModelList(" F_ParamCode='CSYJ' ").FirstOrDefault();
            foreach (DataRow dr in dt.Rows)
            {
                //获取最新交办信息
                string iszbdw = "0";
                int state = Int32.Parse(dr["F_WorkState"].ToString());
                if (state > 1)
                {
                    string sqljb = "SELECT TOP 1 * FROM T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' and F_State=1 and F_IsDelete=0 and F_IsSure<>3   ORDER BY F_Id DESC";
                    var dtjb = DbHelperSQL.Query(sqljb).Tables[0];
                    if (dtjb.Rows.Count > 0)
                    {
                        if (dtjb.Rows[0]["F_MainDeptId"].ToString() == User.F_DeptId.ToString()) { iszbdw = "1"; }
                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_MainDeptId"].ToString() + "')");
                        if (dtjb.Rows[0]["F_OtherDeptIds"] != null && dtjb.Rows[0]["F_OtherDeptIds"].ToString() != "")
                        {
                            dr["OtherDeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_OtherDeptIds"].ToString() + "')");
                        }
                        dr["AssignTime"] = dtjb.Rows[0]["F_CreateTime"].ToString();
                        #region
                        //if (state < 6 || state == 8)
                        if (state < (int)EnumWorkState.dealed || state == (int)EnumWorkState.reload)
                        {
                            var lt = dtjb.Rows[0]["F_LimitTime"].ToString();//限制时间
                            dr["LimitTime"] = lt;
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                if (ltime > DateTime.Now)
                                {
                                    string SY = "SELECT  COUNT(1)  FROM T_Sys_WorkOFFDays WHERE F_OffState =0    AND F_OffDate > '" + DateTime.Now.ToString("yyyy-MM-dd") + "' AND F_OffDate<'" + lt + "'";
                                    var SYSJ = DbHelperSQL.GetSingle(SY);
                                    if (!string.IsNullOrEmpty(SYSJ.ToString()))
                                    {
                                        try
                                        {
                                            ltime = ltime.AddDays(-int.Parse(SYSJ.ToString()));
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                                TimeSpan ts = ltime.Subtract(DateTime.Now);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime > DateTime.Now)
                                {
                                    if (configcs != null)
                                    {
                                        int cs = Int32.Parse(configcs.F_ParamValue);
                                        if (ts.TotalHours > cs)
                                        {
                                            dr["OverState"] = 1;
                                        }
                                        else
                                        {
                                            dr["OverState"] = 2;
                                        }
                                    }
                                    dr["GapTime"] = "剩余" + gshsj;
                                }
                                else
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                        }
                        if (state == (int)EnumWorkState.finish)
                        {
                            var closetime = dr["F_DealTime"].ToString();//关闭工单时间
                            var dttime = DateTime.Now;
                            if (!string.IsNullOrWhiteSpace(closetime)) { dttime = DateTime.Parse(closetime); }
                            else
                            {
                                var DealTime = dr["F_CloseTime"].ToString();
                                if (!string.IsNullOrWhiteSpace(DealTime)) { dttime = DateTime.Parse(DealTime); }
                            }
                            var lt = dtjb.Rows[0]["F_LimitTime"].ToString();//限制时间
                            dr["LimitTime"] = lt;
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                TimeSpan ts = ltime.Subtract(dttime);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime < dttime)
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                        }
                        #endregion
                    }
                    else
                    {

                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dr["F_MainDeptId"].ToString() + "')");
                    }
                }
                if (dr["F_LeaveRecordId"] != null && dr["F_LeaveRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetLeavePath(dr["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                }
                else if (dr["F_CallRecordId"] != null && dr["F_CallRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetCallPath(dr["F_CallRecordId"].ToString(), config.F_ParamValue);
                }

                List<ButtonGroup.button> btns = new List<ButtonGroup.button>();
                btns.Add(ButtonGroup.query());
                dr["Buttons"] = btns;
            }
            #endregion

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };

            return Content(obj.ToJson());
        }

        /// <summary>
        /// 获取二级单位处理列表
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetEJDWDealList(int isdc = 0)
        {
            DataTable dt = new DataTable();
            string sql = " and F_IsDelete=0";
            string strtab = HttpUtility.UrlDecode(RequestString.GetQueryString("tab"));
            string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
            int islike = RequestString.GetInt("islike", 1);
            string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
            string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
            string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));
            string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));
            string strddusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("ddusercode"));//调度员
            string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));

            int source = RequestString.GetInt("source", 0);
            int keyid = RequestString.GetInt("keyid", 0);
            int type = RequestString.GetInt("type", 0);
            int bigtype = RequestString.GetInt("bigtype", 0);
            int smalltype = RequestString.GetInt("smalltype", 0);
            int sourcearea = RequestString.GetInt("sourcearea", 0);
            int deptid = RequestString.GetInt("deptid", 0);
            int isys = RequestString.GetInt("isys", -1);
            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;

            #region 模块
            switch (strtab)
            {
                case "0"://待处理工单
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    int[] sts = new int[] { (int)EnumWorkState.dealing, (int)EnumWorkState.auditdelay
                        , (int)EnumWorkState.reload};
                    sql += " and F_WorkState in (" + string.Join(",", sts.Select(p => p.ToString())) + ")";
                    //sql += " and F_WorkState in (4,5) ";
                    if (isys > -1)
                    {
                        if (isys == 0)  //未延时
                        {
                            sql += " and F_WorkOrderId in (select F_WorkOrderId from T_Bus_AssignedInfo_Next WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and "
                       + " ISNULL(F_FeedbackTime, '')='' and F_MainDeptId =" + User.F_DeptId + " and F_IsSure in (0,1) and F_WorkOrderId not in (select F_WorkOrderID from T_Bus_DelayTime WITH(NOLOCK) where  F_IsDelete=0 and F_IsAudit=1)  ) " +
                       "and  F_MainDeptID3='" + User.F_DeptId + "'";
                        }
                        else
                        {
                            sql += " and F_WorkOrderId in (select F_WorkOrderId from T_Bus_AssignedInfo_Next WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and "
                     + " ISNULL(F_FeedbackTime, '')='' and F_MainDeptId =" + User.F_DeptId + " and F_IsSure in (0,1) and F_WorkOrderId  in (select F_WorkOrderID from T_Bus_DelayTime WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_IsAudit=1))"
                     + "and  F_MainDeptID3='" + User.F_DeptId + "'";
                        }
                    }
                    else
                    {
                        sql += " and F_WorkOrderId in (select F_WorkOrderId from T_Bus_AssignedInfo_Next WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and "
                        + " ISNULL(F_FeedbackTime, '')='' and F_MainDeptId =" + User.F_DeptId + " and F_IsSure in (0,1))"
                         + "and  F_MainDeptID3='" + User.F_DeptId + "'";
                    }
                    break;
                case "1"://已办理的工单 
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_Feedback_Next c WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_Type in (1,2) ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "')  and F_MainDeptID3 = '" + User.F_DeptId + "'";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;

                case "3"://已办未果
                    sql += " and F_WorkState in(6,7) ";
                    sql += " and F_IsProResult = '" + 2 + "' ";
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_Feedback_Next WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_Type in (1,2) ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                //三级单位给已签收工单增加一个菜单
                case "4"://已签收
                         // sql += " and F_WorkState in (4,5,8)";
                    sql += " and F_WorkOrderId in (select F_WorkOrderId from T_Bus_AssignedInfo_Next WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_MainDeptId =" + User.F_DeptId + " and F_IsSure in (1))";
                    break;
                case "5"://
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_DelayTime WITH(NOLOCK) where  F_IsDelete=0)" +
                        "and F_MainDeptID3 ='" + User.F_DeptId + "'";
                    break;
                case "6"://已完结
                    sql += " and F_WorkState = '9' ";
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_Feedback_Next WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_Type in (1,2) ";
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "7"://二级待审回复
                   
                    sql += "  and F_WorkOrderID in(  F_WorkOrderId in (select F_WorkOrderId from T_Bus_AssignedInfo where F_IsDelete = 0 and F_CreateTime = a.F_AssignTime and F_IsNext = 3 ) and F_MainDeptID3 = '"+User .F_DeptId +"' and F_WorkState in(4, 8)) ";
                  
                    break;
                  
                    //

            }
            #endregion
           
            #region 条件
            if (strworkid.Trim() != "" && strworkid != "undefined")
            {
                sql += " and F_WorkOrderId like '%" + strworkid + "%' ";
            }
            if (strname.Trim() != "" && strname != "undefined")
            {
                sql += " and F_CusName like '%" + strname + "%' ";
            }
            if (islike > 0)
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
                }
            }
            else
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  = '" + strtel + "' or F_ConPhone like '" + strtel + "') ";
                }
            }
            string ComTitle = HttpUtility.UrlDecode(RequestString.GetQueryString("ComTitle"));
            string ComContent = HttpUtility.UrlDecode(RequestString.GetQueryString("ComContent"));
            string Result = HttpUtility.UrlDecode(RequestString.GetQueryString("Result"));
            if (ComTitle.Trim() != "" && ComTitle != "undefined")
            {
                sql += " and F_ComTitle like '%" + ComTitle + "%' ";
            }
            if (Result.Trim() != "" && Result != "undefined")
            {
                sql += " and F_Result like '%" + Result + "%' ";
            }
            if (ComContent.Trim() != "" && ComContent != "undefined")
            {
                sql += " and F_ComContent like '%" + ComContent + "%' ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%'" +
                      " or F_Result like  '%" + strkey + "%' ) ";
            }
            #region  坐席&调度员
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {//坐席
                var usercode = strusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in usercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_CreateUser in (" + newusercode + ") ";
                }
            }
            if (strddusercode.Trim() != "" && strddusercode != "undefined")
            {//调度员
                var ddusercode = strddusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in ddusercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_AssignUser in(" + newusercode + ") ";
                }
            }
            //if (strusercode.Trim() != "" && strusercode != "undefined")
            //{
            //    sql += " and F_CreateUser = '" + strusercode + "' ";
            //}
            #endregion
            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            string sqlwhere = "";
            if (keyid != 0)
            {
                sqlwhere = " INNER JOIN[GetValueId]('" + keyid + "') Value on a.F_Key = Value.F_ValueId";
                //sql += "and (F_Key IN(  SELECT  F_ValueId from [GetValueId]('"+ keyid + "'))" +
                //  " or F_Key='" + keyid + "' )";
            }
            if (type != 0)
            {
                sql += " and F_InfoType = '" + type + "' ";
            }
            if (bigtype != 0)
            {
                sql += " and F_InfoConBigType = '" + bigtype + "' ";
            }
            if (smalltype != 0)
            {
                sql += " and F_InfoConSmallType = '" + smalltype + "' ";
            }
            if (sourcearea != 0)
            {
                sql += " and F_SourceArea = '" + sourcearea + "' ";
            }
            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and F_CreateTime>='" + strstarttime + "' ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and F_CreateTime<='" + strendtime + "' ";
            }
            if (deptid != 0)
            {
                sql += " and  (F_MainDeptId = '" + deptid + "' or F_MainDeptID3='" + deptid + "')";
            }

            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }

            if (strpagesize.Trim() != "")
            {
                pagesize = Convert.ToInt32(strpagesize);
            }
            #endregion

            //string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetOverState(F_WorkOrderId) as OverState,"
            //    + "dbo.GetDictionaryName(F_InfoSource) as SourceName,dbo.GetWorkOrderAssign(F_WorkOrderId) as DeptName ,dbo.GetLimitTime(F_WorkOrderId) as LimitTime";
            //string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName";
            //,(case when F_WorkOrderId  in (select F_WorkOrderID from T_Bus_DelayTime WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_IsAudit=1) then '1'else '0' end) IsYS
            string cols = "F_WorkOrderId,F_ComTitle,F_WorkState,F_MainDeptId,F_OtherDeptIds,F_DealTime,F_LeaveRecordId,F_CallRecordId,F_IsResult,F_IsProtect,F_IsReturn,F_CreateTime,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName,F_CloseTime,(select TOP 1 F_LimitTime from T_Bus_AssignedInfo_Next WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_WorkOrderId=a.F_WorkOrderId  order by F_CreateTime desc) as  F_LimitTime,F_IsRelease,F_Identification"
                ;
            //(select TOP 1 F_LimitTime from T_Bus_AssignedInfo_Next WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_WorkOrderId=a.F_WorkOrderId) as
            if (isdc > 0)
            {
                var dtdc = DbHelperSQL.Query(" select  F_CreateTime 日期, F_WorkOrderId 工单号,F_ComTitle 诉求标题,F_ComContent 诉求内容,dbo.GetDictionaryName(F_Key) 主题词, "
                    + "  dbo.GetDeptNames(F_MainDeptId ) 主办单位, "
                    + " (select top 1 F_Result from T_Bus_Feedback WITH(NOLOCK) where F_State=1 and F_Type!=3 and F_IsDelete=0 and  F_WorkOrderId =a.F_WorkOrderId order by F_Id desc) 办理结果, "
                    + " (select top 1 (case F_IsSatisfie when 1 then'满意' when 0 then '不满意' else '未评价' end) F_Satisfie from T_Bus_VisitResult WITH(NOLOCK) where F_State = 1 and F_IsDelete = 0 and F_WorkOrderId = a.F_WorkOrderId order by F_Id desc) 是否满意 ,"
                + "(case when F_WorkOrderId  in (select F_WorkOrderID from T_Bus_DelayTime WITH(NOLOCK) where  F_IsDelete=0 and F_IsAudit=1) then '1'else '0' end) 延时状态"
                    + " from T_Bus_WorkOrder a WITH(NOLOCK) where 1=1 " + sql).Tables[0];

                var msg = new NPOIHelper().ExportToExcel("工单列表", dtdc);
                if (msg == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }

            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_WorkOrder a WITH(NOLOCK)" + sqlwhere,
                "F_Id",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);

            #region 声音文件
            dt.Columns.Add("DeptName", typeof(string));//交办单位
            dt.Columns.Add("OtherDeptName", typeof(string));//协办单位
            dt.Columns.Add("AssignTime", typeof(string));//交办时间
            dt.Columns.Add("OverState", typeof(string));//超时状态
            dt.Columns.Add("LimitTime", typeof(string));//限制时间
            dt.Columns.Add("GapTime", typeof(string));//时间差
            dt.Columns.Add("FilePath", typeof(string));//语音文件路径
            dt.Columns.Add("PDState", typeof(string));//派单状态
            dt.Columns.Add("Buttons", typeof(object));//操作按钮
           dt.Columns.Add("IsYS", typeof(string));//是否延时           

            var configly = configBll.GetModelList(" F_ParamCode='PlayLeaveVoice' ").FirstOrDefault();
            var config = configBll.GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
            var configcs = configBll.GetModelList(" F_ParamCode='CSYJ' ").FirstOrDefault();
            var reminds = remindBLL.GetModelList("F_State=0 and F_IsDelete=0 and F_Type =1").ToList();
            foreach (DataRow dr in dt.Rows)
            {
                string yssql= "select * from  T_Bus_DelayTime WITH(NOLOCK) where F_State= 1 and F_IsDelete = 0 and F_IsAudit = 1 and F_WorkOrderID='" + dr["F_WorkOrderId"].ToString()+ "'";
                var dtys = DbHelperSQL.Query(yssql).Tables[0];
                if (dtys.Rows.Count > 0)
                {
                    dr["IsYS"] = 1;
                }
                else {
                    dr["IsYS"] = 0;//未延时
                }


                    //获取最新交办信息
                    string iszbdw = "0";
                string ispd = "";
                int state = Int32.Parse(dr["F_WorkState"].ToString());
                if (state > 1)
                {
                    string sqljb = "SELECT TOP 1 * FROM T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' and F_State=1 and F_IsDelete=0 and F_IsSure<>3   ORDER BY F_Id DESC";
                    var dtjb = DbHelperSQL.Query(sqljb).Tables[0];
                    if (dtjb.Rows.Count > 0)
                    {
                        if (dtjb.Rows[0]["F_MainDeptId"].ToString() == User.F_DeptId.ToString()) { iszbdw = "1"; }
                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_MainDeptId"].ToString() + "')");
                        if (dtjb.Rows[0]["F_OtherDeptIds"] != null && dtjb.Rows[0]["F_OtherDeptIds"].ToString() != "")
                        {
                            dr["OtherDeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_OtherDeptIds"].ToString() + "')");
                        }
                        dr["AssignTime"] = dtjb.Rows[0]["F_CreateTime"].ToString();

                        var lt = dr["F_LimitTime"].ToString();//限制时间
                        dr["LimitTime"] = lt;
                        #region
                        //if (state < 6 || state == 8)
                        if (state < (int)EnumWorkState.dealed || state == (int)EnumWorkState.reload)
                        {
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                if (ltime > DateTime.Now)
                                {
                                    string SY = "SELECT  COUNT(1)  FROM T_Sys_WorkOFFDays WHERE F_OffState =0    AND F_OffDate > '" + DateTime.Now.ToString("yyyy-MM-dd") + "' AND F_OffDate<'" + lt + "'";
                                    var SYSJ = DbHelperSQL.GetSingle(SY);
                                    if (!string.IsNullOrEmpty(SYSJ.ToString()))
                                    {
                                        try
                                        {
                                            ltime = ltime.AddDays(-int.Parse(SYSJ.ToString()));
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                                TimeSpan ts = ltime.Subtract(DateTime.Now);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime > DateTime.Now)
                                {
                                    if (configcs != null)
                                    {
                                        int cs = Int32.Parse(configcs.F_ParamValue);
                                        if (ts.TotalHours > cs)
                                        {
                                            dr["OverState"] = 1;
                                        }
                                        else
                                        {
                                            dr["OverState"] = 2;
                                        }
                                    }
                                    dr["GapTime"] = "剩余" + gshsj;
                                }
                                else
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                        }
                        if (state == (int)EnumWorkState.finish)
                        {
                            var closetime = dr["F_DealTime"].ToString();//关闭工单时间
                            var dttime = DateTime.Now;
                            if (!string.IsNullOrWhiteSpace(closetime)) { dttime = DateTime.Parse(closetime); }
                            else
                            {
                                var DealTime = dr["F_CloseTime"].ToString();
                                if (!string.IsNullOrWhiteSpace(DealTime)) { dttime = DateTime.Parse(DealTime); }
                            }
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                TimeSpan ts = ltime.Subtract(dttime);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime < dttime)
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                        }
                        #endregion
                        ispd = dtjb.Rows[0]["F_IsNext"].ToString();
                        dr["PDState"] = ispd;
                    }
                    else
                    {

                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dr["F_MainDeptId"].ToString() + "')");
                    }
                }
                if (dr["F_LeaveRecordId"] != null && dr["F_LeaveRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetLeavePath(dr["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                }
                else if (dr["F_CallRecordId"] != null && dr["F_CallRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetCallPath(dr["F_CallRecordId"].ToString(), config.F_ParamValue);
                }

                List<ButtonGroup.button> btns = new List<ButtonGroup.button>();
                if (Int32.Parse(strtab) < 1)
                {
                    btns = ButtonGroup.GetButtons(dr["F_WorkState"].ToString(), User.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString(), iszbdw, ispd);
                    #region 判断是否存在待督办
                    var recount = reminds.Where(r => r.F_WorkOrderId == dr["F_WorkOrderId"].ToString()).Count();
                    var butt = btns.Find(c => c.key == ButtonGroup.turnsee().key);
                    if (recount > 0 && butt != null)
                        btns.Remove(butt);
                    #endregion
                }
                else
                {
                    btns.Add(ButtonGroup.query());
                }
                dr["Buttons"] = btns;
            }
            #endregion

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };

            return Content(obj.ToJson());
        }

        /// <summary>
        /// 获取三级单位处理列表
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetSJDWDealList(int isdc = 0)
        {

            DataTable dt = new DataTable();




            string sql = " and F_IsDelete=0";
            string strtab = HttpUtility.UrlDecode(RequestString.GetQueryString("tab"));
            string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
            int islike = RequestString.GetInt("islike", 1);
            string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
            string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
            string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));
            string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));
            string strddusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("ddusercode"));//调度员
            string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));

            int source = RequestString.GetInt("source", 0);
            int keyid = RequestString.GetInt("keyid", 0);
            int type = RequestString.GetInt("type", 0);
            int bigtype = RequestString.GetInt("bigtype", 0);
            int smalltype = RequestString.GetInt("smalltype", 0);
            int sourcearea = RequestString.GetInt("sourcearea", 0);
            int deptid = RequestString.GetInt("deptid", 0);

            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;
            #region 模块
            switch (strtab)
            {
                case "0"://待处理工单
                    int[] sts = new int[] { (int)EnumWorkState.dealing, (int)EnumWorkState.auditdelay };
                    sql += " and F_WorkState in (" + string.Join(",", sts.Select(p => p.ToString())) + ")";

                    //if (User.F_RoleCode == "EJWLDW")
                    // {
                    //  sql += " and F_MainDeptID3 ='" + User.F_DeptId + "' ";
                    // }
                    if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and ((F_WorkOrderId in (select F_WorkOrderId from T_Bus_AssignedInfo_Next WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and "
                            + " ISNULL(F_FeedbackTime, '')='' and F_MainDeptID='" + User.F_DeptId + "' and F_IsSure in (0,1)))";
                        if (User.F_RoleCode == "WLDW")
                        {
                            sql += " or (F_MainDeptID3 ='" + User.F_DeptId + "')"
                                + " or (F_MainDeptID3 in (SELECT F_DeptId FROM T_Sys_Department WITH(NOLOCK) WHERE F_State=0 AND F_PartentId=" + User.F_DeptId + "))";
                        }
                        sql += ")";
                    }
                    else
                    {
                        sql += " and F_MainDeptID3 ='" + User.F_DeptId + "' ";
                    }
                    break;
                case "1"://已办理的工单 
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_Feedback_Next WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_Type in (1,2) ";

                    if (User.F_RoleCode == "EJWLDW")
                    {
                        sql += "  and F_MainDeptID3 ='" + User.F_DeptId + "' ";
                    }
                    else if (User.F_RoleCode == "WLDW")
                    {
                        sql += " and( (F_MainDeptID3 ='" + User.F_DeptId + "')"
                            + " or (F_MainDeptID3 in (SELECT F_DeptId FROM T_Sys_Department WITH(NOLOCK) WHERE F_State=0 AND F_PartentId=" + User.F_DeptId + ")) )";
                    }
                    else if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                    {
                        sql += " and F_CreateUser='" + User.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
            }
            #endregion
          
            #region 条件
            if (strworkid.Trim() != "" && strworkid != "undefined")
            {
                sql += " and F_WorkOrderId like '%" + strworkid + "%' ";
            }
            if (strname.Trim() != "" && strname != "undefined")
            {
                sql += " and F_CusName like '%" + strname + "%' ";
            }
            if (islike > 0)
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
                }
            }
            else
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  = '" + strtel + "' or F_ConPhone like '" + strtel + "') ";
                }
            }
            string ComTitle = HttpUtility.UrlDecode(RequestString.GetQueryString("ComTitle"));
            string ComContent = HttpUtility.UrlDecode(RequestString.GetQueryString("ComContent"));
            string Result = HttpUtility.UrlDecode(RequestString.GetQueryString("Result"));
            if (ComTitle.Trim() != "" && ComTitle != "undefined")
            {
                sql += " and F_ComTitle like '%" + ComTitle + "%' ";
            }
            if (Result.Trim() != "" && Result != "undefined")
            {
                sql += " and F_Result like '%" + Result + "%' ";
            }
            if (ComContent.Trim() != "" && ComContent != "undefined")
            {
                sql += " and F_ComContent like '%" + ComContent + "%' ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%'" +
                      " or F_Result like  '%" + strkey + "%' ) ";
            }
            #region  坐席&调度员
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {//坐席
                var usercode = strusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in usercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_CreateUser in (" + newusercode + ") ";
                }
            }
            if (strddusercode.Trim() != "" && strddusercode != "undefined")
            {//调度员
                var ddusercode = strddusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in ddusercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_AssignUser in(" + newusercode + ") ";
                }
            }
            #endregion
            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            string sqlwhere = "";
            if (keyid != 0)
            {
                sqlwhere = " INNER JOIN[GetValueId]('" + keyid + "') Value on a.F_Key = Value.F_ValueId";
                //sql += "and (F_Key IN(  SELECT  F_ValueId from [GetValueId]('"+ keyid + "'))" +
                //  " or F_Key='" + keyid + "' )";
            }
            if (type != 0)
            {
                sql += " and F_InfoType = '" + type + "' ";
            }
            if (bigtype != 0)
            {
                sql += " and F_InfoConBigType = '" + bigtype + "' ";
            }
            if (smalltype != 0)
            {
                sql += " and F_InfoConSmallType = '" + smalltype + "' ";
            }
            if (sourcearea != 0)
            {
                sql += " and F_SourceArea = '" + sourcearea + "' ";
            }
            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and F_CreateTime>='" + strstarttime + "' ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and F_CreateTime<='" + strendtime + "' ";
            }
            if (deptid != 0)
            {
                sql += " and  (F_MainDeptId = '" + deptid + "' or F_MainDeptID3='" + deptid + "')";
            }
            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }

            if (strpagesize.Trim() != "")
            {
                pagesize = Convert.ToInt32(strpagesize);
            }
            #endregion

            //string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName";
            string cols = "F_WorkOrderId,F_ComTitle,F_WorkState,F_MainDeptId,F_OtherDeptIds,F_DealTime,F_LeaveRecordId,F_CallRecordId,F_IsResult,F_IsProtect,F_IsReturn,F_CreateTime,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName,F_CloseTime,F_Identification";
            if (isdc > 0)
            {
                var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder WITH(NOLOCK) where 1=1 " + sql).Tables[0];
                var msg = new NPOIHelper().ExportToExcel("工单列表", dtdc);
                if (msg == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }

            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_WorkOrder a WITH(NOLOCK)" + sqlwhere,
                "F_Id",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);

            #region 声音文件
            dt.Columns.Add("DeptName", typeof(string));//交办单位
            dt.Columns.Add("OtherDeptName", typeof(string));//协办单位
            dt.Columns.Add("AssignTime", typeof(string));//交办时间
            dt.Columns.Add("OverState", typeof(string));//超时状态
            dt.Columns.Add("LimitTime", typeof(string));//限制时间
            dt.Columns.Add("GapTime", typeof(string));//时间差
            dt.Columns.Add("FilePath", typeof(string));//语音文件路径
            dt.Columns.Add("PDState", typeof(string));//派单状态
            dt.Columns.Add("Buttons", typeof(object));//操作按钮
            var configly = configBll.GetModelList(" F_ParamCode='PlayLeaveVoice' ").FirstOrDefault();
            var config = configBll.GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
            var configcs = configBll.GetModelList(" F_ParamCode='CSYJ' ").FirstOrDefault();
            var reminds = remindBLL.GetModelList("F_State=0 and F_IsDelete=0 and F_Type =1").ToList();
            foreach (DataRow dr in dt.Rows)
            {
                //获取最新交办信息
                string iszbdw = "0";
                string ispd = "";
                int state = Int32.Parse(dr["F_WorkState"].ToString());
                if (state > 1)
                {
                    string sqljb = "SELECT TOP 1 * FROM T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' and F_State=1 and F_IsDelete=0 and F_IsSure<>3   ORDER BY F_Id DESC";
                    var dtjb = DbHelperSQL.Query(sqljb).Tables[0];
                    if (dtjb.Rows.Count > 0)
                    {
                        if (dtjb.Rows[0]["F_MainDeptId"].ToString() == User.F_DeptId.ToString()) { iszbdw = "1"; }
                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_MainDeptId"].ToString() + "')");
                        if (dtjb.Rows[0]["F_OtherDeptIds"] != null && dtjb.Rows[0]["F_OtherDeptIds"].ToString() != "")
                        {
                            dr["OtherDeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_OtherDeptIds"].ToString() + "')");
                        }
                        dr["AssignTime"] = dtjb.Rows[0]["F_CreateTime"].ToString();

                        var lt = dtjb.Rows[0]["F_LimitTime"].ToString();//限制时间
                        dr["LimitTime"] = lt;
                        #region
                        if (state < (int)EnumWorkState.dealed || state == (int)EnumWorkState.reload)
                        {
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                if (ltime > DateTime.Now)
                                {
                                    string SY = "SELECT  COUNT(1)  FROM T_Sys_WorkOFFDays WHERE F_OffState =0    AND F_OffDate > '" + DateTime.Now.ToString("yyyy-MM-dd") + "' AND F_OffDate<'" + lt + "'";
                                    var SYSJ = DbHelperSQL.GetSingle(SY);
                                    if (!string.IsNullOrEmpty(SYSJ.ToString()))
                                    {
                                        try
                                        {
                                            ltime = ltime.AddDays(-int.Parse(SYSJ.ToString()));
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                                TimeSpan ts = ltime.Subtract(DateTime.Now);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime > DateTime.Now)
                                {
                                    if (configcs != null)
                                    {
                                        int cs = Int32.Parse(configcs.F_ParamValue);
                                        if (ts.TotalHours > cs)
                                        {
                                            dr["OverState"] = 1;
                                        }
                                        else
                                        {
                                            dr["OverState"] = 2;
                                        }
                                    }
                                    dr["GapTime"] = "剩余" + gshsj;
                                }
                                else
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                        }
                        if (state == (int)EnumWorkState.finish)
                        {
                            var closetime = dr["F_DealTime"].ToString();//关闭工单时间
                            var dttime = DateTime.Now;
                            if (!string.IsNullOrWhiteSpace(closetime)) { dttime = DateTime.Parse(closetime); }
                            else
                            {
                                var DealTime = dr["F_CloseTime"].ToString();
                                if (!string.IsNullOrWhiteSpace(DealTime)) { dttime = DateTime.Parse(DealTime); }
                            }
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                TimeSpan ts = ltime.Subtract(dttime);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime < dttime)
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                        }
                        #endregion
                        ispd = dtjb.Rows[0]["F_IsNext"].ToString();
                        dr["PDState"] = ispd;
                    }
                    else
                    {

                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dr["F_MainDeptId"].ToString() + "')");
                    }
                }
                if (dr["F_LeaveRecordId"] != null && dr["F_LeaveRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetLeavePath(dr["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                }
                else if (dr["F_CallRecordId"] != null && dr["F_CallRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetCallPath(dr["F_CallRecordId"].ToString(), config.F_ParamValue);
                }

                List<ButtonGroup.button> btns = new List<ButtonGroup.button>();
                if (Int32.Parse(strtab) < 1)
                {
                    btns = ButtonGroup.GetButtons(dr["F_WorkState"].ToString(), User.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString(), iszbdw, ispd);
                    #region 判断是否存在待督办
                    var recount = reminds.Where(r => r.F_WorkOrderId == dr["F_WorkOrderId"].ToString()).Count();
                    var butt = btns.Find(c => c.key == ButtonGroup.turnsee().key);
                    if (recount > 0 && butt != null)
                        btns.Remove(butt);
                    #endregion
                }
                else
                {
                    btns.Add(ButtonGroup.query());
                }
                dr["Buttons"] = btns;
            }
            #endregion

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };

            return Content(obj.ToJson());
        }

        /// <summary>
        /// 获取自己提交工单
        /// </summary>
        /// <param name="isdc"></param>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetSelfList(int isdc = 0)
        {



            DataTable dt = new DataTable();
            string sql = " and F_IsDelete=0 ";
            string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
            string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
            int islike = RequestString.GetInt("islike", 1);
            string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
            string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
            string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));
            int source = RequestString.GetInt("source", 0);
            int keyid = RequestString.GetInt("keyid", 0);
            int type = RequestString.GetInt("type", 0);
            int bigtype = RequestString.GetInt("bigtype", 0);
            int smalltype = RequestString.GetInt("smalltype", 0);
            int sourcearea = RequestString.GetInt("sourcearea", 0);

            int deptid = RequestString.GetInt("deptid", 0);
            int dealtype = RequestString.GetInt("dealtype", -1);
            int issend = RequestString.GetInt("issend", -1);
            int deptlevel = RequestString.GetInt("deptlevel", 0);

            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;

            #region sql 语句相关处理
            if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
                sql += " and F_CreateUser ='" + User.F_UserCode + "' ";
            if (strstate.Trim() != "" && strstate != "undefined")
            {
                if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                    sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                else
                    sql += " and F_WorkState = '" + strstate.Trim() + "' ";
            }
            if (strworkid.Trim() != "" && strworkid != "undefined")
            {
                sql += " and F_WorkOrderId like '%" + strworkid + "%' ";
            }
           
            if (strname.Trim() != "" && strname != "undefined")
            {
                sql += " and F_CusName like '%" + strname + "%' ";
            }
            if (islike > 0)
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
                }
            }
            else
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  = '" + strtel + "' or F_ConPhone like '" + strtel + "') ";
                }
            }
            string ComTitle = HttpUtility.UrlDecode(RequestString.GetQueryString("ComTitle"));
            string ComContent = HttpUtility.UrlDecode(RequestString.GetQueryString("ComContent"));
            string Result = HttpUtility.UrlDecode(RequestString.GetQueryString("Result"));
            if (ComTitle.Trim() != "" && ComTitle != "undefined")
            {
                sql += " and F_ComTitle like '%" + ComTitle + "%' ";
            }
            if (Result.Trim() != "" && Result != "undefined")
            {
                sql += " and F_Result like '%" + Result + "%' ";
            }
            if (ComContent.Trim() != "" && ComContent != "undefined")
            {
                sql += " and F_ComContent like '%" + ComContent + "%' ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%'" +
                      " or F_Result like  '%" + strkey + "%' ) ";
            }
            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            string sqlwhere = "";
            if (keyid != 0)
            {
                sqlwhere = " INNER JOIN[GetValueId]('" + keyid + "') Value on a.F_Key = Value.F_ValueId";
                //sql += "and (F_Key IN(  SELECT  F_ValueId from [GetValueId]('"+ keyid + "'))" +
                //  " or F_Key='" + keyid + "' )";
            }
            if (type != 0)
            {
                sql += " and F_InfoType = '" + type + "' ";
            }
            if (bigtype != 0)
            {
                sql += " and F_InfoConBigType = '" + bigtype + "' ";
            }
            if (smalltype != 0)
            {
                sql += " and F_InfoConSmallType = '" + smalltype + "' ";
            }

            if (sourcearea != 0)
            {
                sql += " and F_SourceArea = '" + sourcearea + "' ";
            }

            if (deptid != 0)
            {
                sql += " and  (F_MainDeptId = '" + deptid + "' or F_MainDeptID3='" + deptid + "')";
            }
            if (dealtype != -1)
            {
                sql += " and isnull(F_IsResult,0) = '" + dealtype + "' ";
            }
            if (issend != -1)
            {
                sql += " and isnull(F_IsRelease,0) = '" + issend + "' ";
            }
            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and F_CreateTime>='" + strstarttime + "' ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and F_CreateTime<='" + strendtime + "' ";
            }
            #endregion

            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }

            if (strpagesize.Trim() != "")
            {
                pagesize = Convert.ToInt32(strpagesize);
            }
            string cols = "F_WorkOrderId,F_ComTitle,F_WorkState,F_MainDeptId,F_OtherDeptIds,F_DealTime,F_LeaveRecordId,F_CallRecordId,F_IsResult,F_IsProtect,F_IsReturn,F_CreateTime,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName,F_CloseTime,F_Identification";
            #region 导出
            if (isdc > 0)
            {
                var top = " "; var orderby = " order by F_CreateTime";
                if (sql == " and F_IsDelete=0 ")
                {
                    top = " top 1000 "; orderby += " desc ";
                }
                //20190715调整导出字段 zhengbingbing
                //日期，工单号，诉求标题，诉求内容，承办单位，办理结果，是否满意，备注
                var dtdc = DbHelperSQL.Query(" select " + top + " F_CreateTime 日期, F_WorkOrderId 工单号,F_ComTitle 诉求标题,F_ComContent 诉求内容,dbo.GetDictionaryName(F_Key) 主题词, "
                 + "  dbo.GetDeptNames(F_MainDeptId ) 主办单位, "

                    + " (select top 1 F_Result from T_Bus_Feedback WITH(NOLOCK) where F_State=1 and F_Type!=3 and F_IsDelete=0 and  F_WorkOrderId =wo.F_WorkOrderId order by F_Id desc) 办理结果, "
                    + " (select top 1 (case F_IsSatisfie when 1 then'满意' when 0 then '不满意' else '未评价' end) F_Satisfie from T_Bus_VisitResult WITH(NOLOCK) where F_State = 1 and F_IsDelete = 0 and F_WorkOrderId = wo.F_WorkOrderId order by F_Id desc) 是否满意 "
                    + " from T_Bus_WorkOrder wo WITH(NOLOCK) where 1=1 " + sql + orderby).Tables[0];
                var msg = new NPOIHelper().ExportToExcel("工单列表", dtdc);
                if (msg == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }
            #endregion
            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_WorkOrder a WITH(NOLOCK)" + sqlwhere,
                "F_Id",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);

            #region 声音文件和交办超时
            dt.Columns.Add("DeptName", typeof(string));//交办单位
            dt.Columns.Add("AssignTime", typeof(string));//交办时间
            dt.Columns.Add("OtherDeptName", typeof(string));//协办单位
            dt.Columns.Add("OverState", typeof(string));//超时状态
            dt.Columns.Add("LimitTime", typeof(string));//限制时间
            dt.Columns.Add("GapTime", typeof(string));//时间差
            dt.Columns.Add("PDState", typeof(string));//派单状态
            dt.Columns.Add("FilePath", typeof(string));//语音文件路径
            dt.Columns.Add("Buttons", typeof(object));//操作按钮
            var configly = configBll.GetModelList(" F_ParamCode='PlayLeaveVoice' ").FirstOrDefault();
            var config = configBll.GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
            var configcs = configBll.GetModelList(" F_ParamCode='CSYJ' ").FirstOrDefault();
            var reminds = remindBLL.GetModelList(" F_State=0 and F_IsDelete=0 and F_Type =1").ToList();
            foreach (DataRow dr in dt.Rows)
            {
                string iszbdw = "0";
                string ispd = "";

                int state = Int32.Parse(dr["F_WorkState"].ToString());
                if (state > 1)
                {
                    dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dr["F_MainDeptId"].ToString() + "')");
                    //获取最新交办信息
                    string sqljb = "SELECT TOP 1 * FROM T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' and F_State=1 and F_IsDelete=0 and F_IsSure<>3   ORDER BY F_Id DESC";
                    var dtjb = DbHelperSQL.Query(sqljb).Tables[0];
                    if (dtjb.Rows.Count > 0)
                    {
                        if (dr["F_MainDeptId"].ToString() == User.F_DeptId.ToString()) { iszbdw = "1"; }

                        if (dr["F_OtherDeptIds"] != null && dr["F_OtherDeptIds"].ToString() != "")
                        {
                            dr["OtherDeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dr["F_OtherDeptIds"].ToString() + "')");
                        }
                        dr["AssignTime"] = dtjb.Rows[0]["F_CreateTime"].ToString();
                        var lt = dtjb.Rows[0]["F_LimitTime"].ToString();//限制时间
                        dr["LimitTime"] = lt;
                        #region 超时时限
                        if (state < (int)EnumWorkState.dealed || state == (int)EnumWorkState.reload)
                        {
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                if (ltime > DateTime.Now)
                                {
                                    string SY = "SELECT  COUNT(1)  FROM T_Sys_WorkOFFDays WHERE F_OffState =0    AND F_OffDate > '" + DateTime.Now.ToString("yyyy-MM-dd") + "' AND F_OffDate<'" + lt + "'";
                                    var SYSJ = DbHelperSQL.GetSingle(SY);
                                    if (!string.IsNullOrEmpty(SYSJ.ToString()))
                                    {
                                        try
                                        {
                                            ltime = ltime.AddDays(-int.Parse(SYSJ.ToString()));
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                                TimeSpan ts = ltime.Subtract(DateTime.Now);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime > DateTime.Now)
                                {
                                    if (configcs != null)
                                    {
                                        int cs = Int32.Parse(configcs.F_ParamValue);
                                        if (ts.TotalHours > cs)
                                        {
                                            dr["OverState"] = 1;
                                        }
                                        else
                                        {
                                            dr["OverState"] = 2;
                                        }
                                    }
                                    dr["GapTime"] = "剩余" + gshsj;
                                }
                                else
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                            ispd = dtjb.Rows[0]["F_IsNext"] != null ? dtjb.Rows[0]["F_IsNext"].ToString() : "";
                            dr["PDState"] = ispd;
                        }
                        if (state == (int)EnumWorkState.finish)
                        {
                            var closetime = dr["F_DealTime"].ToString();//关闭工单时间
                            var dttime = DateTime.Now;
                            if (!string.IsNullOrWhiteSpace(closetime)) { dttime = DateTime.Parse(closetime); }
                            else
                            {
                                var DealTime = dr["F_CloseTime"].ToString();
                                if (!string.IsNullOrWhiteSpace(DealTime)) { dttime = DateTime.Parse(DealTime); }
                            }
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                TimeSpan ts = ltime.Subtract(dttime);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime < dttime)
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                        }
                        #endregion
                    }
                }
                if (dr["F_LeaveRecordId"] != null && dr["F_LeaveRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetLeavePath(dr["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                }
                else if (dr["F_CallRecordId"] != null && dr["F_CallRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetCallPath(dr["F_CallRecordId"].ToString(), config.F_ParamValue);
                }

                var buttons = ButtonGroup.GetButtons(dr["F_WorkState"].ToString(), User.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString(), iszbdw, ispd);
                #region 判断是否存在待督办
                var recount = reminds.Where(r => r.F_WorkOrderId.Equals(dr["F_WorkOrderId"].ToString())).Count();
                var butt = buttons.Find(c => c.key == ButtonGroup.turnsee().key);
                if (recount > 0 && butt != null)
                    buttons.Remove(butt);
                #endregion
                dr["Buttons"] = buttons;
            }
            #endregion

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };
            return Content(obj.ToJson());
        }

        /// <summary>
        /// 获取逾期未回复工单列表
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetTimeOutList(int isdc = 0)
        {
            DataTable dt = new DataTable();
            string sql = "   and F_IsDelete=0";
            string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
            int islike = RequestString.GetInt("islike", 1);
            string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
            string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
            string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));
            string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));
            string strddusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("ddusercode"));//调度员
            string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
            
                 int ejdeptid = RequestString.GetInt("ejdeptid", 0);
            int source = RequestString.GetInt("source", 0);
            int keyid = RequestString.GetInt("keyid", 0);
            int type = RequestString.GetInt("type", 0);
            int bigtype = RequestString.GetInt("bigtype", 0);
            int smalltype = RequestString.GetInt("smalltype", 0);
            int sourcearea = RequestString.GetInt("sourcearea", 0);
            int deptid = RequestString.GetInt("deptid", 0);
            int soon = RequestString.GetInt("soon", 0);
            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;
            #region  坐席&调度员
            string splituser = HttpUtility.UrlDecode(RequestString.GetQueryString("splituser"));
            if (splituser.Trim() != "" && splituser != "undefined")
            {
                sql += " and F_SplitUser = '" + splituser + "' ";
            }

            string assuser = HttpUtility.UrlDecode(RequestString.GetQueryString("assuser"));
            if (assuser.Trim() != "" && assuser != "undefined")
            {
                sql += " and F_AssignUser = '" + assuser + "' ";
            }
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {//坐席
                var usercode = strusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in usercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_CreateUser in (" + newusercode + ") ";
                }
            }

            if (ejdeptid > 0)
            {
                sql += "and F_MainDeptID3='" + ejdeptid + "'";
            }
            if (strddusercode.Trim() != "" && strddusercode != "undefined")
            {//调度员
                var ddusercode = strddusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in ddusercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_AssignUser in(" + newusercode + ") ";
                }
            }
            //if (strusercode.Trim() != "" && strusercode != "undefined")
            //{
            //    sql += " and F_CreateUser = '" + strusercode + "' ";
            //}
            #endregion
           
            string sqlwhere = ""; string sqlwhere1 = "";


            if (User.F_RoleCode == "WLDW")
            {

                if (soon == 1)
                {
                    sqlwhere += " and (F_LimitTime<getdate() or " +
                        " F_LimitTime<(dateadd(dd,-1,GETDATE()))) ";
                    // sqlwhere += " and  F_MainDeptId = '" + User.F_DeptId + "') or F_WorkOrderId in (select F_WorkOrderId from T_Bus_AssignedItemInfo WITH(NOLOCK) "
                    //+ " where F_State=1 and F_IsDelete=0 and  and ISNULL(F_FeedbackTime, '')='' and  F_DeptId = '" + User.F_DeptId + "' ";
                }
                else
                {
                    // sqlwhere += " and  F_MainDeptId = '" + User.F_DeptId + "') or F_WorkOrderId in (select F_WorkOrderId from T_Bus_AssignedItemInfo WITH(NOLOCK) "
                    //+ " where F_State=1 and F_IsDelete=0 and F_LimitTime<getdate() and ISNULL(F_FeedbackTime, '')='' and  F_DeptId = '" + User.F_DeptId + "' ";
                    sqlwhere += " and F_LimitTime<getdate()  ";
                }

                //sqlwhere1 += " and  F_MainDeptId = '" + User.F_DeptId + "'";
                sql += " and  F_MainDeptId = '" + User.F_DeptId + "' " +
                    "and F_WorkState NOT IN (6,7,9)";
                //  sqlwhere += "))";
            }
            else if (User.F_RoleCode == "EJWLDW")
            {
                sqlwhere += " and  F_WorkOrderId in (select F_WorkOrderId  from T_Bus_AssignedInfo WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_LimitTime<getdate() and isnull(F_FeedbackTime,'')='' and F_IsSure in (0,1)  ";
                sqlwhere += "and F_WorkOrderId in (select F_WorkOrderId from T_Bus_AssignedInfo_Next WITH(NOLOCK) where F_State=1 and  isnull(F_FeedbackTime,'')='' and F_IsDelete=0 and "
                           + "   F_MainDeptId =" + User.F_DeptId + " and F_IsSure in (0,1)))";
            }
            else if (deptid != 0)
            {
                sqlwhere += " and F_LimitTime<getdate() and F_WorkState NOT IN(6,7,9)";
                sqlwhere += " and  (F_MainDeptId = '" + deptid + "' or F_MainDeptID3='" + deptid + "')";
                sqlwhere1 += " and  (F_MainDeptId = '" + deptid + "' or F_MainDeptID3='" + deptid + "')";
            }
            else
            {
                sqlwhere += " and F_LimitTime<getdate() and F_WorkState NOT IN (6,7,9) ";

            }
            sql += "and F_MainDeptId is not null and F_MainDeptId !='' ";
            //if (User.F_RoleCode == "ZXLD")
            //{
            //    sqlwhere += " and  F_CreateUser = '" + User.F_UserCode + "' ";
            //    sqlwhere1 += " and  F_CreateUser = '" + User.F_UserCode + "'";
            //}



            if (strstate.Trim() != "" && strstate != "undefined")
            {
                if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                    sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                else
                    sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                if (strstate.Trim() == ((int)EnumWorkState.finish).ToString())
                    sql += " and F_LimitTime<F_DealTime " + sqlwhere1;
                else
                    sql += sqlwhere;
            }
            else
            {
                int[] sts = new int[] { (int)EnumWorkState.receive, (int)EnumWorkState.dealing, (int)EnumWorkState.reload };
                sql += " and F_WorkState in (" + string.Join(",", sts.Select(p => p.ToString())) + ")";
                sql += sqlwhere;
                //sql += " and F_WorkState in (2,4,8)";
            }
            if (strworkid.Trim() != "" && strworkid != "undefined")
            {
                sql += " and F_WorkOrderId like '%" + strworkid + "%' ";
            }
            if (strname.Trim() != "" && strname != "undefined")
            {
                sql += " and F_CusName like '%" + strname + "%' ";
            }
            if (islike > 0)
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
                }
            }
            else
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  = '" + strtel + "' or F_ConPhone like '" + strtel + "') ";
                }
            }
            string ComTitle = HttpUtility.UrlDecode(RequestString.GetQueryString("ComTitle"));
            string ComContent = HttpUtility.UrlDecode(RequestString.GetQueryString("ComContent"));
            string Result = HttpUtility.UrlDecode(RequestString.GetQueryString("Result"));
            if (ComTitle.Trim() != "" && ComTitle != "undefined")
            {
                sql += " and F_ComTitle like '%" + ComTitle + "%' ";
            }
            if (Result.Trim() != "" && Result != "undefined")
            {
                sql += " and F_Result like '%" + Result + "%' ";
            }
            if (ComContent.Trim() != "" && ComContent != "undefined")
            {
                sql += " and F_ComContent like '%" + ComContent + "%' ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%'" +
                      " or F_Result like  '%" + strkey + "%' ) ";
            }

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }

            string sqlwheres = ""; string value = "";
            if (keyid != 0)
            {
                sqlwheres = " INNER JOIN[GetValueId]('" + keyid + "') Value on a.F_Key = Value.F_ValueId";
                //sql += "and (F_Key IN(  SELECT  F_ValueId from [GetValueId]('"+ keyid + "'))" +
                //  " or F_Key='" + keyid + "' )";
                value = " INNER JOIN[GetValueId]('" + keyid + "') Value on wo.F_Key = Value.F_ValueId";

            }
            if (type != 0)
            {
                sql += " and F_InfoType = '" + type + "' ";
            }
            if (bigtype != 0)
            {
                sql += " and F_InfoConBigType = '" + bigtype + "' ";
            }
            if (smalltype != 0)
            {
                sql += " and F_InfoConSmallType = '" + smalltype + "' ";
            }
            if (sourcearea != 0)
            {
                sql += " and F_SourceArea = '" + sourcearea + "' ";
            }
            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and F_CreateTime>='" + strstarttime + "' ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and F_CreateTime<='" + strendtime + "' ";
            }

            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }

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

            //string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName ";
            string cols = "F_WorkOrderId,F_CusName,F_ComTitle,F_WorkState,F_MainDeptId,F_OtherDeptIds,F_DealTime,F_LeaveRecordId,F_CallRecordId,F_IsResult,F_IsProtect,F_IsReturn,F_CreateTime,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName,F_CloseTime,F_Identification";
            if (isdc > 0)
            {
                //  var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder WITH(NOLOCK) where 1=1 " + sql).Tables[0];
                var top = " "; var orderby = " order by F_CreateTime";
                if (sql == " and F_IsDelete=0 ")
                {
                    top = " top 1000 "; orderby += " desc ";
                }
                var dtdc = DbHelperSQL.Query(" select  F_CreateTime 日期, F_WorkOrderId 工单号,F_ComTitle 诉求标题,F_ComContent 诉求内容,dbo.GetDictionaryName(F_Key) 主题词, "
   + "  dbo.GetDeptNames(F_MainDeptId ) 主办单位, "
                   + " (select top 1 F_Result from T_Bus_Feedback WITH(NOLOCK) where F_State=1 and F_Type!=3 and F_IsDelete=0 and  F_WorkOrderId =wo.F_WorkOrderId order by F_Id desc) 办理结果, "
                   + " (select top 1 (case F_IsSatisfie when 1 then'满意' when 0 then '不满意' else '未评价' end) F_Satisfie from T_Bus_VisitResult WITH(NOLOCK) where F_State = 1 and F_IsDelete = 0 and F_WorkOrderId = wo.F_WorkOrderId order by F_Id desc) 是否满意 "
                   + " from T_Bus_WorkOrder wo WITH(NOLOCK)" + value + " where 1=1 " + sql + orderby).Tables[0];

                var msg = new NPOIHelper().ExportToExcel("工单列表", dtdc);
                if (msg == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }

            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_WorkOrder a WITH(NOLOCK)" + sqlwheres,
                "F_Id",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);

            #region 声音文件
            dt.Columns.Add("DeptName", typeof(string));//交办单位
            dt.Columns.Add("OtherDeptName", typeof(string));//协办单位
            dt.Columns.Add("AssignTime", typeof(string));//交办时间
            dt.Columns.Add("OverState", typeof(string));//超时状态
            dt.Columns.Add("LimitTime", typeof(string));//限制时间
            dt.Columns.Add("GapTime", typeof(string));//时间差
            dt.Columns.Add("FilePath", typeof(string));
            dt.Columns.Add("Buttons", typeof(object));
            var configly = configBll.GetModelList(" F_ParamCode='PlayLeaveVoice' ").FirstOrDefault();
            var config = configBll.GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
            var configcs = configBll.GetModelList(" F_ParamCode='CSYJ' ").FirstOrDefault();
            foreach (DataRow dr in dt.Rows)
            {
                //获取最新交办信息
                string iszbdw = "0";
                int state = Int32.Parse(dr["F_WorkState"].ToString());
                string ispd = "";
                if (state > 1)
                {
                    string sqljb = "SELECT TOP 1 * FROM T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' and F_State=1 and F_IsDelete=0 and F_IsSure<>3   ORDER BY F_Id DESC";
                    string sqlej = "";
                    if (User.F_RoleCode == "EJWLDW")
                    {
                        sqlej = " select TOP 1 F_LimitTime from T_Bus_AssignedInfo_Next WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' order by F_CreateTime desc";
                    }

                    var dtjb = DbHelperSQL.Query(sqljb).Tables[0];
                    if (dtjb.Rows.Count > 0)
                    {
                        if (dtjb.Rows[0]["F_MainDeptId"].ToString() == User.F_DeptId.ToString()) { iszbdw = "1"; }
                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_MainDeptId"].ToString() + "')");
                        if (dtjb.Rows[0]["F_OtherDeptIds"] != null && dtjb.Rows[0]["F_OtherDeptIds"].ToString() != "")
                        {
                            dr["OtherDeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_OtherDeptIds"].ToString() + "')");
                        }
                        dr["AssignTime"] = dtjb.Rows[0]["F_CreateTime"].ToString();

                        #region 时限
                        //if (state < 6 || state == 8)
                        if (state < (int)EnumWorkState.dealed || state == (int)EnumWorkState.reload)
                        {
                            var lt = dtjb.Rows[0]["F_LimitTime"].ToString();//限制时间
                            if (User.F_RoleCode == "EJWLDW")
                            {
                                sqlej = " select TOP 1 F_LimitTime from T_Bus_AssignedInfo_Next WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' order by F_CreateTime desc";
                                var dtej = DbHelperSQL.Query(sqljb).Tables[0];
                                lt = dtej.Rows[0]["F_LimitTime"].ToString();
                            }
                            dr["LimitTime"] = lt;
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                if (ltime > DateTime.Now)
                                {
                                    string SY = "SELECT  COUNT(1)  FROM T_Sys_WorkOFFDays WHERE F_OffState =0    AND F_OffDate > '" + DateTime.Now.ToString("yyyy-MM-dd") + "' AND F_OffDate<'" + lt + "'";
                                    var SYSJ = DbHelperSQL.GetSingle(SY);
                                    if (!string.IsNullOrEmpty(SYSJ.ToString()))
                                    {
                                        try
                                        {
                                            ltime = ltime.AddDays(-int.Parse(SYSJ.ToString()));
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                                TimeSpan ts = ltime.Subtract(DateTime.Now);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime > DateTime.Now)
                                {
                                    if (configcs != null)
                                    {
                                        int cs = Int32.Parse(configcs.F_ParamValue);
                                        if (ts.TotalHours > cs)
                                        {
                                            dr["OverState"] = 1;
                                        }
                                        else
                                        {
                                            dr["OverState"] = 2;
                                        }
                                    }
                                    dr["GapTime"] = "剩余" + gshsj;
                                }
                                else
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                        }
                        if (state == (int)EnumWorkState.finish)
                        {
                            var closetime = dr["F_DealTime"].ToString();//关闭工单时间
                            var dttime = DateTime.Now;
                            if (!string.IsNullOrWhiteSpace(closetime)) { dttime = DateTime.Parse(closetime); }
                            else
                            {
                                var DealTime = dr["F_CloseTime"].ToString();
                                if (!string.IsNullOrWhiteSpace(DealTime)) { dttime = DateTime.Parse(DealTime); }
                            }
                            var lt = dtjb.Rows[0]["F_LimitTime"].ToString();//限制时间
                            dr["LimitTime"] = lt;
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                TimeSpan ts = ltime.Subtract(dttime);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime < dttime)
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                        }
                        ispd = dtjb.Rows[0]["F_IsNext"] != null ? dtjb.Rows[0]["F_IsNext"].ToString() : "";
                        #endregion
                    }
                }
                if (dr["F_LeaveRecordId"] != null && dr["F_LeaveRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetLeavePath(dr["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                }
                else if (dr["F_CallRecordId"] != null && dr["F_CallRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetCallPath(dr["F_CallRecordId"].ToString(), config.F_ParamValue);
                }

                List<ButtonGroup.button> btns = new List<ButtonGroup.button>();
                if (User.F_RoleCode == "EJWLDW")
                {
                    btns = ButtonGroup.GetButtons(dr["F_WorkState"].ToString(), User.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString(), iszbdw, ispd);

                }
                if (User.F_RoleCode == "WLDW")
                {
                    if (ispd == "0"|| ispd=="")
                    btns = ButtonGroup.GetButtons(dr["F_WorkState"].ToString(), User.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString(), iszbdw, ispd);

                }
                else
                {
                    btns.Add(ButtonGroup.query());
                }
                dr["Buttons"] = btns;
            }
            #endregion

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };

            return Content(obj.ToJson());
        }

        /// <summary>
        /// 获取公开工单列表
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetMediaList(int isdc = 0)
        {
            DataTable dt = new DataTable();
            string sql = " and F_IsDelete=0";
            string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
            int islike = RequestString.GetInt("islike", 1);
            string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
            string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
            string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));
            string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));
            string strddusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("ddusercode"));//调度员
            int source = RequestString.GetInt("source", 0);
            int keyid = RequestString.GetInt("keyid", 0);
            int type = RequestString.GetInt("type", 0);
            int bigtype = RequestString.GetInt("bigtype", 0);
            int smalltype = RequestString.GetInt("smalltype", 0);
            int sourcearea = RequestString.GetInt("sourcearea", 0);
            int deptid = RequestString.GetInt("deptid", 0);

            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;

            sql += " and isnull(F_IsOpen,0) =1 ";
           
            if (strworkid.Trim() != "" && strworkid != "undefined")
            {
                sql += " and F_WorkOrderId like '%" + strworkid + "%' ";
            }
            if (strname.Trim() != "" && strname != "undefined")
            {
                sql += " and F_CusName like '%" + strname + "%' ";
            }
           
            if (islike > 0)
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
                }
            }
            else
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  = '" + strtel + "' or F_ConPhone like '" + strtel + "') ";
                }
            }

            string ComTitle = HttpUtility.UrlDecode(RequestString.GetQueryString("ComTitle"));
            string ComContent = HttpUtility.UrlDecode(RequestString.GetQueryString("ComContent"));
            string Result = HttpUtility.UrlDecode(RequestString.GetQueryString("Result"));
            if (ComTitle.Trim() != "" && ComTitle != "undefined")
            {
                sql += " and F_ComTitle like '%" + ComTitle + "%' ";
            }
            if (Result.Trim() != "" && Result != "undefined")
            {
                sql += " and F_Result like '%" + Result + "%' ";
            }
            if (ComContent.Trim() != "" && ComContent != "undefined")
            {
                sql += " and F_ComContent like '%" + ComContent + "%' ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%'" +
                   " or F_Result like  '%" + strkey + "%' ) ";
            }
            #region  坐席&调度员
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {//坐席
                var usercode = strusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in usercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_CreateUser in (" + newusercode + ") ";
                }
            }
            if (strddusercode.Trim() != "" && strddusercode != "undefined")
            {//调度员
                var ddusercode = strddusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in ddusercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_AssignUser in(" + newusercode + ") ";
                }
            }
            //if (strusercode.Trim() != "" && strusercode != "undefined")
            //{
            //    sql += " and F_CreateUser = '" + strusercode + "' ";
            //}
            #endregion

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            string sqlwheres = "";
            if (keyid != 0)
            {
                sqlwheres = " INNER JOIN[GetValueId]('" + keyid + "') Value on a.F_Key = Value.F_ValueId";
                //sql += "and (F_Key IN(  SELECT  F_ValueId from [GetValueId]('"+ keyid + "'))" +
                //  " or F_Key='" + keyid + "' )";
            }
            if (type != 0)
            {
                sql += " and F_InfoType = '" + type + "' ";
            }
            if (bigtype != 0)
            {
                sql += " and F_InfoConBigType = '" + bigtype + "' ";
            }
            if (smalltype != 0)
            {
                sql += " and F_InfoConSmallType = '" + smalltype + "' ";
            }
            if (sourcearea != 0)
            {
                sql += " and F_SourceArea = '" + sourcearea + "' ";
            }
            if (deptid != 0)
            {
                string sqlwhere = "select F_WorkOrderID from T_Bus_AssignedInfo WITH(NOLOCK) where F_MainDeptId = '" + deptid + "' and F_IsSure in (0,1) and F_State=1 and F_IsDelete=0 ";
                sql += " and F_WorkOrderID in(" + sqlwhere + ")";
            }
            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and F_CreateTime>='" + strstarttime + "' ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and F_CreateTime<='" + strendtime + "' ";
            }

            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }

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

            //string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,"
            //        + "dbo.GetDictionaryName(F_InfoSource) as SourceName ";
            string cols = "F_WorkOrderId,F_ComTitle,F_WorkState,F_MainDeptId,F_OtherDeptIds,F_DealTime,F_LeaveRecordId,F_CallRecordId,F_IsResult,F_IsProtect,F_IsReturn,F_CreateTime,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName,F_Identification";
            if (isdc > 0)
            {
                var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder WITH(NOLOCK) where 1=1 " + sql).Tables[0];
                var msg = new NPOIHelper().ExportToExcel("工单列表", dtdc);
                if (msg == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }

            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_WorkOrder a WITH(NOLOCK)" + sqlwheres,
                "F_Id",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);

            #region 声音文件
            dt.Columns.Add("DeptName", typeof(string));//交办单位
            dt.Columns.Add("OtherDeptName", typeof(string));//协办单位
            dt.Columns.Add("AssignTime", typeof(string));//交办时间
            dt.Columns.Add("IsReturnMedia", typeof(string));

            dt.Columns.Add("Buttons", typeof(object));

            int IsReturnMedia = 0;
            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "ZXLDGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {
                IsReturnMedia = 1;
            }
            foreach (DataRow dr in dt.Rows)
            {
                int state = Int32.Parse(dr["F_WorkState"].ToString());
                if (state > 1)
                {
                    //获取最新交办信息
                    string sqljb = "SELECT TOP 1 * FROM T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' and F_State=1 and F_IsDelete=0 and F_IsSure<>3   ORDER BY F_Id DESC";
                    var dtjb = DbHelperSQL.Query(sqljb).Tables[0];
                    if (dtjb.Rows.Count > 0)
                    {
                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_MainDeptId"].ToString() + "')");
                        if (dtjb.Rows[0]["F_OtherDeptIds"] != null && dtjb.Rows[0]["F_OtherDeptIds"].ToString() != "")
                        {
                            dr["OtherDeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_OtherDeptIds"].ToString() + "')");
                        }
                        dr["AssignTime"] = dtjb.Rows[0]["F_CreateTime"].ToString();
                        //int did = Int32.Parse(dtjb.Rows[0]["F_MainDeptId"].ToString());
                        //var deptinfo = new BLL.T_Sys_Department().GetModel(did);
                        //if (deptinfo != null)
                        //{
                        //    dr["DeptName"] = deptinfo.F_DeptName;//交办单位
                        //}

                        //if (dtjb.Rows[0]["F_OtherDeptIds"] != null && dtjb.Rows[0]["F_OtherDeptIds"].ToString() != "")
                        //{
                        //    string[] strids = dtjb.Rows[0]["F_OtherDeptIds"].ToString().Split(',');
                        //    string dns = string.Empty;
                        //    foreach (string strid in strids)
                        //    {
                        //        var dinfo = new BLL.T_Sys_Department().GetModel(Int32.Parse(strid));
                        //        if (dinfo != null)
                        //        {
                        //            if (string.IsNullOrEmpty(dns))
                        //            {
                        //                dns = dinfo.F_DeptName;//交办单位
                        //            }
                        //            else
                        //            {
                        //                dns += "," + dinfo.F_DeptName;//交办单位
                        //            }
                        //        }
                        //    }
                        //    dr["OtherDeptName"] = dns;
                        //}
                    }
                }
                List<ButtonGroup.button> btns = new List<ButtonGroup.button>();
                btns.Add(ButtonGroup.query());
                dr["Buttons"] = btns;

                dr["IsReturnMedia"] = IsReturnMedia;
            }

            #endregion

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };

            return Content(obj.ToJson());
        }


        /// <summary>
        /// 获取媒体工单列表
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetMassList(int isdc = 0)
        {
            DataTable dt = new DataTable();
            string sql = " and F_IsDelete=0";
            string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
            int islike = RequestString.GetInt("islike", 1);
            string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
            string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
            string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));
            string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));
            string strddusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("ddusercode"));//调度员
            int source = RequestString.GetInt("source", 0);
            int keyid = RequestString.GetInt("keyid", 0);
            int type = RequestString.GetInt("type", 0);
            int bigtype = RequestString.GetInt("bigtype", 0);
            int smalltype = RequestString.GetInt("smalltype", 0);
            int sourcearea = RequestString.GetInt("sourcearea", 0);
            int deptid = RequestString.GetInt("deptid", 0);

            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;

            sql += " and isnull(F_IsMedia,0) =1 ";
          
            if (strworkid.Trim() != "" && strworkid != "undefined")
            {
                sql += " and F_WorkOrderId like '%" + strworkid + "%' ";
            }
            if (strname.Trim() != "" && strname != "undefined")
            {
                sql += " and F_CusName like '%" + strname + "%' ";
            }
          
            if (islike > 0)
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
                }
            }
            else
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  = '" + strtel + "' or F_ConPhone like '" + strtel + "') ";
                }
            }

            string ComTitle = HttpUtility.UrlDecode(RequestString.GetQueryString("ComTitle"));
            string ComContent = HttpUtility.UrlDecode(RequestString.GetQueryString("ComContent"));
            string Result = HttpUtility.UrlDecode(RequestString.GetQueryString("Result"));
            if (ComTitle.Trim() != "" && ComTitle != "undefined")
            {
                sql += " and F_ComTitle like '%" + ComTitle + "%' ";
            }
            if (Result.Trim() != "" && Result != "undefined")
            {
                sql += " and F_Result like '%" + Result + "%' ";
            }
            if (ComContent.Trim() != "" && ComContent != "undefined")
            {
                sql += " and F_ComContent like '%" + ComContent + "%' ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%'" +
                   " or F_Result like  '%" + strkey + "%' ) ";
            }
            #region  坐席&调度员
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {//坐席
                var usercode = strusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in usercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_CreateUser in (" + newusercode + ") ";
                }
            }
            if (strddusercode.Trim() != "" && strddusercode != "undefined")
            {//调度员
                var ddusercode = strddusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in ddusercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_AssignUser in(" + newusercode + ") ";
                }
            }

            #endregion

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            string sqlwheres = "";
            if (keyid != 0)
            {
                sqlwheres = " INNER JOIN[GetValueId]('" + keyid + "') Value on a.F_Key = Value.F_ValueId";
                //sql += "and (F_Key IN(  SELECT  F_ValueId from [GetValueId]('"+ keyid + "'))" +
                //  " or F_Key='" + keyid + "' )";
            }
            if (type != 0)
            {
                sql += " and F_InfoType = '" + type + "' ";
            }
            if (bigtype != 0)
            {
                sql += " and F_InfoConBigType = '" + bigtype + "' ";
            }
            if (smalltype != 0)
            {
                sql += " and F_InfoConSmallType = '" + smalltype + "' ";
            }
            if (sourcearea != 0)
            {
                sql += " and F_SourceArea = '" + sourcearea + "' ";
            }
            if (deptid != 0)
            {
                string sqlwhere = "select F_WorkOrderID from T_Bus_AssignedInfo WITH(NOLOCK) where F_MainDeptId = '" + deptid + "' and F_IsSure in (0,1) and F_State=1 and F_IsDelete=0 ";
                sql += " and F_WorkOrderID in(" + sqlwhere + ")";
            }
            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and F_CreateTime>='" + strstarttime + "' ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and F_CreateTime<='" + strendtime + "' ";
            }

            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }

            if (strpagesize.Trim() != "")
            {
                pagesize = Convert.ToInt32(strpagesize);
            }
            string cols = "F_WorkOrderId,F_ComTitle,F_WorkState,F_MainDeptId,F_OtherDeptIds,F_DealTime,F_LeaveRecordId,F_CallRecordId,F_IsResult,F_IsProtect,F_IsReturn,F_CreateTime,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName,F_Identification";
            if (isdc > 0)
            {
                var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder WITH(NOLOCK) where 1=1 " + sql).Tables[0];
                var msg = new NPOIHelper().ExportToExcel("工单列表", dtdc);
                if (msg == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }

            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_WorkOrder a WITH(NOLOCK)" + sqlwheres,
                "F_Id",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);

            #region 声音文件
            dt.Columns.Add("DeptName", typeof(string));//交办单位
            dt.Columns.Add("OtherDeptName", typeof(string));//协办单位
            dt.Columns.Add("AssignTime", typeof(string));//交办时间
            dt.Columns.Add("IsReturnMedia", typeof(string));

            dt.Columns.Add("Buttons", typeof(object));

            int IsReturnMedia = 0;
            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "ZXLDGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {
                IsReturnMedia = 1;
            }
            foreach (DataRow dr in dt.Rows)
            {
                int state = Int32.Parse(dr["F_WorkState"].ToString());
                if (state > 1)
                {
                    //获取最新交办信息
                    string sqljb = "SELECT TOP 1 * FROM T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' and F_State=1 and F_IsDelete=0 and F_IsSure<>3   ORDER BY F_Id DESC";
                    var dtjb = DbHelperSQL.Query(sqljb).Tables[0];
                    if (dtjb.Rows.Count > 0)
                    {
                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_MainDeptId"].ToString() + "')");
                        if (dtjb.Rows[0]["F_OtherDeptIds"] != null && dtjb.Rows[0]["F_OtherDeptIds"].ToString() != "")
                        {
                            dr["OtherDeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_OtherDeptIds"].ToString() + "')");
                        }
                        dr["AssignTime"] = dtjb.Rows[0]["F_CreateTime"].ToString();
                    }
                }
                List<ButtonGroup.button> btns = new List<ButtonGroup.button>();
                btns.Add(ButtonGroup.query());
                dr["Buttons"] = btns;

                dr["IsReturnMedia"] = IsReturnMedia;
            }

            #endregion

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };

            return Content(obj.ToJson());
        }

      

        /// <summary>
        /// 获取通报工单列表
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetNoticeList(string[] usercode, string[] ddusercode, int isdc = 0)//
        {
            DataTable dt = new DataTable();
            //int userId = 8000;




            string sql = " and F_IsDelete=0 ";
            string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
            int islike = RequestString.GetInt("islike", 1);
            string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
            string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
            string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));
            //string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));
            //string strddusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("ddusercode"));//调度员
            int source = RequestString.GetInt("source", 0);
            int keyid = RequestString.GetInt("keyid", 0);
            int type = RequestString.GetInt("type", 0);
            int bigtype = RequestString.GetInt("bigtype", 0);
            int smalltype = RequestString.GetInt("smalltype", 0);
            int sourcearea = RequestString.GetInt("sourcearea", 0);
            int deptid = RequestString.GetInt("deptid", 0);

            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;
           
            if (strworkid.Trim() != "" && strworkid != "undefined")
            {
                sql += " and F_WorkOrderId like '%" + strworkid + "%' ";
            }
            if (strname.Trim() != "" && strname != "undefined")
            {
                sql += " and F_CusName like '%" + strname + "%' ";
            }
            if (islike > 0)
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
                }
            }
            else
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  = '" + strtel + "' or F_ConPhone like '" + strtel + "') ";
                }
            }
            string ComTitle = HttpUtility.UrlDecode(RequestString.GetQueryString("ComTitle"));
            string ComContent = HttpUtility.UrlDecode(RequestString.GetQueryString("ComContent"));
            string Result = HttpUtility.UrlDecode(RequestString.GetQueryString("Result"));
            if (ComTitle.Trim() != "" && ComTitle != "undefined")
            {
                sql += " and F_ComTitle like '%" + ComTitle + "%' ";
            }
            if (Result.Trim() != "" && Result != "undefined")
            {
                sql += " and F_Result like '%" + Result + "%' ";
            }
            if (ComContent.Trim() != "" && ComContent != "undefined")
            {
                sql += " and F_ComContent like '%" + ComContent + "%' ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%'" +
                      " or F_Result like  '%" + strkey + "%' ) ";
            }
            #region  坐席&调度员
            /*if (strusercode.Trim() != "" && strusercode != "undefined")
            {//坐席
                var usercode = strusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in usercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_CreateUser in (" + newusercode + ") ";
                }
            }*/
            #region 
            if (usercode != null && usercode.Length > 0)
            {
                var newusercode = "";
                //string codes = "";
                for (int i = 0; i < usercode.Length; i++)
                {
                    if (usercode[i] != "")
                    {
                        newusercode += "'" + usercode[i] + "',";
                    }
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_CreateUser in (" + newusercode + ") ";
                }
            }
            if (ddusercode != null && ddusercode.Length > 0)
            {
                var newusercode = "";
                //string codes = "";
                for (int i = 0; i < ddusercode.Length; i++)
                {
                    if (ddusercode[i] != "")
                    {
                        newusercode += "'" + ddusercode[i] + "',";
                    }
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_AssignUser in (" + newusercode + ") ";
                }
            }
            #endregion
            /*if (strddusercode.Trim() != "" && strddusercode != "undefined")
            {//调度员
                var ddusercode = strddusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in ddusercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_AssignUser in(" + newusercode + ") ";
                }
            }*/
            //if (strusercode.Trim() != "" && strusercode != "undefined")
            //{
            //    sql += " and F_CreateUser = '" + strusercode + "' ";
            //}
            #endregion

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            string sqlwheres = "";
            if (keyid != 0)
            {
                sqlwheres = " INNER JOIN[GetValueId]('" + keyid + "') Value on a.F_Key = Value.F_ValueId";
                //sql += "and (F_Key IN(  SELECT  F_ValueId from [GetValueId]('"+ keyid + "'))" +
                //  " or F_Key='" + keyid + "' )";
            }
            if (type != 0)
            {
                sql += " and F_InfoType = '" + type + "' ";
            }
            if (bigtype != 0)
            {
                sql += " and F_InfoConBigType = '" + bigtype + "' ";
            }
            if (smalltype != 0)
            {
                sql += " and F_InfoConSmallType = '" + smalltype + "' ";
            }
            if (sourcearea != 0)
            {
                sql += " and F_SourceArea = '" + sourcearea + "' ";
            }
            if (deptid != 0)
            {
                string sqlwhere = "select F_WorkOrderID from T_Bus_AssignedInfo WITH(NOLOCK) where F_MainDeptId = '" + deptid + "' and F_IsSure in (0,1) and F_State=1 and F_IsDelete=0 ";
                sql += " and F_WorkOrderID in(" + sqlwhere + ")";
            }
            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and F_CreateTime>='" + strstarttime + "' ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and F_CreateTime<='" + strendtime + "' ";
            }

            if (User.F_RoleCode == "WLDW")
            {
                string sqlwhere = "select F_WorkOrderID from T_Bus_NoticeCriticism WITH(NOLOCK) where ','+F_DeptIds+',' like  '%," + User.F_DeptId + ",%' and F_State=1 and F_IsDelete=0 ";
                sql += " and F_WorkOrderID in(" + sqlwhere + ")";
            }
            else
            {
                sql += " and F_WorkOrderID in(select F_WorkOrderID from T_Bus_NoticeCriticism WITH(NOLOCK) where F_State=1 and F_IsDelete=0) ";
            }

            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }

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

            //string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName";
            string cols = "F_WorkOrderId,F_ComTitle,F_WorkState,F_MainDeptId,F_OtherDeptIds,F_DealTime,F_LeaveRecordId,F_CallRecordId,F_IsResult,F_IsProtect,F_IsReturn,F_CreateTime,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName,F_CloseTime,F_Identification";
            if (isdc > 0)
            {
                var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder WITH(NOLOCK) where 1=1 " + sql).Tables[0];
                var msg = new NPOIHelper().ExportToExcel("工单列表", dtdc);
                if (msg == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }

            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_WorkOrder a WITH(NOLOCK)" + sqlwheres,
                "F_Id",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);

            #region 声音文件
            dt.Columns.Add("DeptName", typeof(string));//交办单位
            dt.Columns.Add("OtherDeptName", typeof(string));//协办单位
            dt.Columns.Add("AssignTime", typeof(string));//交办时间
            dt.Columns.Add("NoticeDeptName", typeof(string));//通报单位
            dt.Columns.Add("NoticeReson", typeof(string));//通报原因
            dt.Columns.Add("IsReturnNotice", typeof(string));
            dt.Columns.Add("FilePath", typeof(string));
            dt.Columns.Add("Buttons", typeof(object));
            var configly = configBll.GetModelList(" F_ParamCode='PlayLeaveVoice' ").FirstOrDefault();
            var config = configBll.GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
            int IsReturnNotice = 0;
            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "ZXLDGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {
                IsReturnNotice = 1;
            }
            foreach (DataRow dr in dt.Rows)
            {
                //获取最新交办信息
                //string iszbdw = "0";
                int state = Int32.Parse(dr["F_WorkState"].ToString());
                if (state > 1)
                {
                    string sqljb = "SELECT TOP 1 * FROM T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' and F_State=1 and F_IsDelete=0 and F_IsSure<>3   ORDER BY F_Id DESC";
                    var dtjb = DbHelperSQL.Query(sqljb).Tables[0];
                    if (dtjb.Rows.Count > 0)
                    {
                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_MainDeptId"].ToString() + "')");
                        if (dtjb.Rows[0]["F_OtherDeptIds"] != null && dtjb.Rows[0]["F_OtherDeptIds"].ToString() != "")
                        {
                            dr["OtherDeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_OtherDeptIds"].ToString() + "')");
                        }
                        dr["AssignTime"] = dtjb.Rows[0]["F_CreateTime"].ToString();
                    }
                    else
                    {

                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dr["F_MainDeptId"].ToString() + "')");
                    }
                }
                //获取最新通报信息
                string sqltb = "SELECT TOP 1 * FROM T_Bus_NoticeCriticism WITH(NOLOCK) WHERE F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' and F_State=1 and F_IsDelete=0  ORDER BY F_Id DESC";
                var dttb = DbHelperSQL.Query(sqltb).Tables[0];
                if (dttb.Rows.Count > 0)
                {
                    if (dttb.Rows[0]["F_DeptIds"] != null && dttb.Rows[0]["F_DeptIds"].ToString() != "")
                    {
                        dr["NoticeDeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dttb.Rows[0]["F_DeptIds"].ToString() + "')");
                    }

                    dr["NoticeReson"] = dttb.Rows[0]["F_Content"] != null ? dttb.Rows[0]["F_Content"].ToString() : "";
                }
                if (dr["F_LeaveRecordId"] != null && dr["F_LeaveRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetLeavePath(dr["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                }
                else if (dr["F_CallRecordId"] != null && dr["F_CallRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetCallPath(dr["F_CallRecordId"].ToString(), config.F_ParamValue);
                }
                List<ButtonGroup.button> btns = new List<ButtonGroup.button>();
                btns.Add(ButtonGroup.query());
                dr["Buttons"] = btns;

                dr["IsReturnNotice"] = IsReturnNotice;
            }

            #endregion

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };

            return Content(obj.ToJson());
        }

        /// <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 参数
            //0督办-待办，1督办-办理中，2督办-超期未完结，3督办-已退回，4督办-已完结
            string strtab = HttpUtility.UrlDecode(RequestString.GetQueryString("tab"));
            string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
            string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
            int islike = RequestString.GetInt("islike", 1);
            string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
            string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
            string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));
            string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));
            string strddusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("ddusercode"));//调度员
            int source = RequestString.GetInt("source", 0);
            int keyid = RequestString.GetInt("keyid", 0);
            int type = RequestString.GetInt("type", 0);
            int bigtype = RequestString.GetInt("bigtype", 0);
            int smalltype = RequestString.GetInt("smalltype", 0);
            int sourcearea = RequestString.GetInt("sourcearea", 0);
            int deptid = RequestString.GetInt("deptid", 0);
          
            int deptlevel = RequestString.GetInt("deptlevel", 0);
            int issatisfie = RequestString.GetInt("issatisfie", -1);//0不满意 1满意
            int ejdeptid = RequestString.GetInt("ejdeptid", 0);
            
            int pageindex = RequestString.GetInt("page", 1);
            int pagesize = RequestString.GetInt("pagesize", 10);
            int business = RequestString.GetInt("business", 0);
            int Supervisor = RequestString.GetInt("Supervisor", 0);
            string strSupervisor = HttpUtility.UrlDecode(RequestString.GetQueryString("strSupervisor"));//
            int isExamine = RequestString.GetInt("isExamine", 0);

            int dbdeptid = RequestString.GetInt("dbdeptid", 0);

            string result = HttpUtility.UrlDecode(RequestString.GetQueryString("result"));//办理结果

            string dealstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("dealstarttime"));
            string dealstrendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("dealstrendtime"));

            string dbstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("dbstarttime"));
            string dbstrendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("dbstrendtime"));

            string comtitle = HttpUtility.UrlDecode(RequestString.GetQueryString("ComTitle"));
            string comContent = HttpUtility.UrlDecode(RequestString.GetQueryString("ComContent"));
            int isRelease = RequestString.GetInt("isRelease", 0);
            if (keyid != 0)
            {
                sql += "and a.F_Key in(select F_ValueId  from  dbo.GetValueId(" + keyid + ")) ";
            }
            if (comtitle.Trim() != "" && comtitle != "undefined")
            {
                sql += " and F_ComTitle like '%" + comtitle + "%' ";
            }
            if (comContent.Trim() != "" && comContent != "undefined")
            {
                sql += " and (F_ComContent like '%" + comContent + "%' " +
                    "or F_Content like '%" + comContent + "%'  )";
            }
            if (isRelease > 0)
            {
                sql += "and F_IsRelease='" + isRelease + "'";
            }
            if (ejdeptid > 0)
            {
                sql += "and F_MainDeptID3='" + ejdeptid + "'";
            }
            int isbusiness = RequestString.GetInt("isbusiness", -1);
            if (isbusiness > -1)
            {
                if (isbusiness == 0)
                {
                    sql += " and (F_IsBusiness =0 or F_IsBusiness is null) ";
                }
                else
                {
                    sql += " and F_IsBusiness='1' ";
                }
            }
            if (result.Trim() != "" && result != "undefined")
            {
                sql += " and F_Result like'%" + result + "%' ";
            }
            string Remind = "";
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {
                Remind += " and F_CreateUser ='" + strusercode + "' ";
            }
            if (dbdeptid>0)
            {
                sql += " and F_WorkOrderId in(select F_WorkOrderId from T_Bus_AssignedInfo  WITH(NOLOCK) where  F_MainDeptId ="+ dbdeptid + " )";
            }

            if (dealstarttime.Trim() != "" && dealstarttime != "undefined")
            {
                if (dealstrendtime.Trim() != "" && dealstrendtime != "undefined")
                {
                    sql += " and F_DealTime  between   '" + dealstarttime +
                             "' AND  '" + dealstrendtime + "'";
                }
                else
                {
                    sql += " and F_DealTime>='" + dealstarttime + "' ";
                }
            }
            else
            {
                if (dealstrendtime.Trim() != "" && dealstrendtime != "undefined")
                {
                    sql += " and F_DealTime<='" + dealstrendtime + "' ";
                }
            }


            int iscb = RequestString.GetInt("iscb", -1);


          
            
            if (strSupervisor.Trim() != "" && strSupervisor != "undefined")
            {
                Remind += " and Supervisor ='" + strSupervisor + "' ";
            }
            //if (User.F_RoleCode == "DBZY")
            //{
            //    if (Supervisor == 1)
            //    {
            //        if (strtab == "0")
            //            Remind += "and Supervisor='" + User.F_UserCode + "'";
            //        else
            //            Remind += "and (Supervisor ='' or  Supervisor is null  " +
            //                "or Supervisor='" + User.F_UserCode + "' )";
            //    }
            //    else if (Supervisor == 2)
            //    {
            //        Remind += "and (Supervisor ='' or  Supervisor is null )";
            //    }
            //}
            //else
            //{
            //    if (Supervisor == 1)
            //    {
            //        if (strtab == "0")
            //            Remind += "and Supervisor !='' and Supervisor is not null";
                    
            //    }
            //    else if (Supervisor == 2)
            //    {
            //        Remind += "and (Supervisor ='' or  Supervisor is null )";
            //    }
            //}
            if (dbstarttime.Trim() != "" && dbstarttime != "undefined")
            {
                if (dbstrendtime.Trim() != "" && dbstrendtime != "undefined")
                {
                    Remind += " and F_CreateTime  between   '" + dbstarttime +
                             "' AND  '" + dbstrendtime + "'";
                }
                else
                {
                    Remind += " and F_CreateTime>='" + dbstarttime + "' ";
                }
            }
            else
            {
                if (dbstrendtime.Trim() != "" && dbstrendtime != "undefined")
                {
                    Remind += " and F_CreateTime<='" + dbstrendtime + "' ";
                }
            }
            if (isExamine == 1)
            {
                Remind += "and F_IsExamine='1'";
            }
            else if (isExamine == 2)
            {
                Remind += "and (F_IsExamine !='1' or F_IsExamine is null) ";
            }

            #endregion
            #region 筛选
            //存在有督办记录的工单
            var sqlsup = "select F_WorkOrderID from T_Bus_RemindRecord where F_Type=1 and F_IsDelete=0" + Remind;
            //  sql += " and F_WorkOrderID in (select F_WorkOrderID from T_Bus_RemindRecord where F_Type=1 and F_IsDelete=0)";
            switch (strtab)
            {
                case "0"://督办-待办
                    sql += "  and F_WorkOrderID in(" + sqlsup + " and F_State =0 )";
                    sql += "and F_WorkState  !='9'";
                    break;
                case "1"://督办-办理中
                    sql += "  and F_WorkOrderID in(" + sqlsup + " and F_State =1 ) and F_WorkState " +
                        "not in (6,9)";
                    string strjbstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("jbstarttime"));
                    string strjbendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("jbendtime"));
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                       
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    if (iscb>-1)
                    {
                        if (iscb==0)
                        {
                            sql += " and F_WorkState != '8' ";
                        }
                        else
                        {
                            sql += " and F_WorkState = '8' ";
                        }
                    }
                    sql += "  and F_WorkOrderID in (select F_WorkOrderID from T_Bus_AssignedInfo WITH(NOLOCK) where F_State=1 and F_IsDelete=0 ";
                    if (strjbstarttime.Trim() != "" && strjbstarttime != "undefined")
                    {
                        sql += " and datediff(day,F_CreateTime,'" + strjbstarttime + "')<=0 ";
                    }
                    if (strjbendtime.Trim() != "" && strjbendtime != "undefined")
                    {
                        sql += " and datediff(day,F_CreateTime,'" + strjbendtime + "')>=0   ";
                    }
                    sql += ")";
                    if (User.F_RoleCode == "WLDW" )
                    {
                        sql += "and F_WorkOrderId in   (  select F_WorkOrderId from T_Bus_AssignedInfo as b  WITH(NOLOCK) where F_State=1 and F_IsDelete=0  and F_MainDeptId =" + User.F_DeptId + " and F_IsSure in (0,1) and (F_IsNext =" + 0 + " or  F_IsNext='' )and not exists(select 1 from T_Bus_AssignedInfo  where F_WorkOrderId = b.F_WorkOrderId and F_Id > b.F_Id  ) and F_WorkState  in (2,4,8)  )";
                    }
                    break;
                case "2"://督办-超期未完结
                    sql += "  and F_WorkOrderID in(" + sqlsup + " and F_State =1 ) and F_WorkState  IN (2,4,8) and F_LimitTime<getdate() ";
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        if (strstate.Trim() == ((int)EnumWorkState.neworder).ToString())
                            sql += " and F_WorkState in (" + (int)EnumWorkState.neworder + "," + (int)EnumWorkState.audit + ") ";
                        else
                            sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        //sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    break;
                case "3"://督办-已退回
                    sql += "  and F_WorkOrderID in(" + sqlsup + " and F_State =2 )  ";
                    break;
                case "4"://督办-已完结的工单
                    sql += "  and F_WorkOrderID in(" + sqlsup + " and F_State !=2 )  " + "  and F_WorkState =9 and F_IsDelete=0 and F_IsClosed=1 ";
                    string strwjstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("wjstarttime"));
                    string strwjendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("wjendtime"));
                    if (strwjstarttime.Trim() != "" && strwjstarttime != "undefined")
                    {
                        sql += " and datediff(day,F_CloseTime,'" + strwjstarttime + "')<=0 ";
                    }
                    if (strwjendtime.Trim() != "" && strwjendtime != "undefined")
                    {
                        sql += " and datediff(day,F_CloseTime,'" + strwjendtime + "')>=0   ";
                    }
                    break;
                default:
                    sql += "  and F_WorkOrderID in(" + sqlsup + " )";
                    break;
                case "6"://督办-待审核回复
                    
                    sql += "  and F_WorkOrderID in(" + sqlsup + " and F_State =1 )  " + "   and F_IsDelete=0  ";
                    if (isExamine == 1)
                        sql += "and F_WorkState =7";
                    else
                        sql += "and F_WorkState =6";
                    break;
                case "7"://督办综合查询

                    sql += "  and F_WorkOrderID in(" + sqlsup + "  )  " + "   and F_IsDelete=0  ";
                   
                    break;


            }
            //int jianhang = RequestString.GetInt("jianhang", 0);
            //int phoneType = RequestString.GetInt("phoneType", 0);
            //if (jianhang > 0)
            //{
            //    if (jianhang == 3)
            //        sql += " and F_InfoSource = '2501' ";
            //    else
            //        sql += " and F_InfoSource != '1' and F_InfoSource != '2501'";
            //}
            //else
            //{
            //    sql += " and F_InfoSource = '1' ";
            //    if (phoneType == 1)
            //        sql += " and F_PhoneType != '12345' ";
            //    else if (phoneType == 2)
            //        sql += " and (F_PhoneType = '12345' or F_PhoneType ='' " +
            //                   "or F_PhoneType is null ) ";
            //}
            string incomingcall = RequestString.GetString("incomingcall");//来电电话
            if (incomingcall.Trim() != "" && incomingcall != "undefined")
            {
                sql += " and F_PhoneType = '" + incomingcall + "' ";
            }
            if (strworkid.Trim() != "" && strworkid != "undefined")
            {
                sql += " and F_WorkOrderId like '%" + strworkid + "%' ";
            }
            if (strname.Trim() != "" && strname != "undefined")
            {
                sql += " and F_CusName like '%" + strname + "%' ";
            }
            if (islike > 0)
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
                }
            }
            else
            {
                if (strtel.Trim() != "" && strtel != "undefined")
                {
                    sql += " and (F_CusPhone  = '" + strtel + "' or F_ConPhone like '" + strtel + "') ";
                }
            }
            if (User.F_RoleCode == "WLDW")
            {
                deptid = User.F_DeptId;

            }

            string ComTitle = HttpUtility.UrlDecode(RequestString.GetQueryString("ComTitle"));
            string ComContent = HttpUtility.UrlDecode(RequestString.GetQueryString("ComContent"));
            string Result = HttpUtility.UrlDecode(RequestString.GetQueryString("Result"));
            if (ComTitle.Trim() != "" && ComTitle != "undefined")
            {
                sql += " and F_ComTitle like '%" + ComTitle + "%' ";
            }
            if (Result.Trim() != "" && Result != "undefined")
            {
                sql += " and F_Result like '%" + Result + "%' ";
            }
            if (ComContent.Trim() != "" && ComContent != "undefined")
            {
                sql += " and F_ComContent like '%" + ComContent + "%' ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%'" +
                       " or F_Result like  '%" + strkey + "%' ) ";
            }
            #region  坐席&调度员
            if (strtab !="0")
            {
                if (strusercode.Trim() != "" && strusercode != "undefined")
                {//坐席
                    var usercode = strusercode.Trim().Split(',');
                    var newusercode = "";
                    foreach (var item in usercode)
                    {
                        if (!string.IsNullOrWhiteSpace(item.Trim()))
                            newusercode += "'" + item + "',";
                    }
                    newusercode = newusercode.Trim(',');
                    if (newusercode.Trim() != "" && newusercode != "undefined")
                    {
                        sql += " and F_CreateUser in (" + newusercode + ") ";
                    }
                }
            }
          
            if (strddusercode.Trim() != "" && strddusercode != "undefined")
            {//调度员
                var ddusercode = strddusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in ddusercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_AssignUser in(" + newusercode + ") ";
                }
            }
            #endregion

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            string sqlwheres = ""; string value = "";
            if (keyid != 0)
            {
                sqlwheres = " INNER JOIN[GetValueId]('" + keyid + "') Value on a.F_Key = Value.F_ValueId";
                value = " INNER JOIN[GetValueId]('" + keyid + "') Value on wo.F_Key = Value.F_ValueId";
                //sql += "and (F_Key IN(  SELECT  F_ValueId from [GetValueId]('"+ keyid + "'))" +
                //  " or F_Key='" + keyid + "' )";
            }
            if (type != 0)
            {
                sql += " and F_InfoType = '" + type + "' ";
            }
            if (bigtype != 0)
            {
                sql += " and F_InfoConBigType = '" + bigtype + "' ";
            }
            if (smalltype != 0)
            {
                sql += " and F_InfoConSmallType = '" + smalltype + "' ";
            }
            if (sourcearea != 0)
            {
                sql += " and F_SourceArea = '" + sourcearea + "' ";
            }

            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and F_CreateTime>='" + strstarttime + "' ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and F_CreateTime<='" + strendtime + "' ";
            }
            if (deptid != 0)
            {
                if (deptlevel == 0)
                {
                    string sqlwhere = "select F_WorkOrderID from T_Bus_AssignedInfo WITH(NOLOCK) where F_MainDeptId = '" + deptid + "' and F_IsSure in (0,1) and F_State=1 and F_IsDelete=0 ";
                    sql += " and F_WorkOrderID in(" + sqlwhere + ")";
                }
                else
                {
                    string sqlwhere = "select F_WorkOrderID from T_Bus_AssignedInfo_Next WITH(NOLOCK) where F_MainDeptId = '" + deptid + "' and F_IsSure in (0,1) and F_State=1 and F_IsDelete=0 ";
                    sql += " and F_WorkOrderID in(" + sqlwhere + ")";
                }
            }
            if (deptid != 0)
            {
                sql += " and  (F_MainDeptId = '" + deptid + "' or F_MainDeptID3='" + deptid + "')";
            }
            #endregion

            #region 导出
            string cols = "F_WorkOrderId,F_ComTitle,F_ComContent,F_WorkState,F_MainDeptId,F_OtherDeptIds,F_DealTime,F_LeaveRecordId,F_CallRecordId,F_IsResult,F_IsProtect,F_IsReturn,F_CreateTime,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName, dbo.GetDictionaryName(F_InfoSource) as SourceName,F_Identification";
            if (isdc > 0)
            {
                var top = " "; var orderby = " order by F_CreateTime";
                if (sql == " and F_IsDelete=0 ")
                {
                    top = " top 1000 "; orderby += " desc ";
                }
                var dtdc = DbHelperSQL.Query(" select " + top + " F_CreateTime 日期, F_WorkOrderId 工单号,F_ComTitle 诉求标题,F_ComContent 诉求内容,dbo.GetDictionaryName(F_Key) 主题词, "
                   + "  dbo.GetDeptNames((select top 1 F_MainDeptId from T_Bus_AssignedInfo where F_WorkOrderId=wo.F_WorkOrderId order by F_Id desc  )) 主办单位, "

                   + " (select top 1 F_Result from T_Bus_Feedback WITH(NOLOCK) where F_State=1 and F_Type!=3 and F_IsDelete=0 and  F_WorkOrderId =wo.F_WorkOrderId order by F_Id desc) 办理结果, "
                   + " (select top 1 (case F_IsSatisfie when 1 then'满意' when 0 then '不满意' else '未评价' end) F_Satisfie from T_Bus_VisitResult WITH(NOLOCK) where F_State = 1 and F_IsDelete = 0 and F_WorkOrderId = wo.F_WorkOrderId order by F_Id desc) 是否满意,(select top 1 F_Result from T_Bus_Feedback WITH(NOLOCK)  where F_Type=3 and F_State=1 and F_IsDelete=0" +
              "and F_WorkOrderId=wo.F_WorkOrderId order by F_CreateTime desc ) as 退回原因 "
                   + " from T_Bus_WorkOrder wo WITH(NOLOCK)" + value + " where 1=1 " + sql + orderby).Tables[0];
                var msg = new NPOIHelper().ExportToExcel("工单列表", dtdc);

                if (msg == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }
            #endregion
            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_WorkOrder a WITH(NOLOCK)" + sqlwheres,
                "F_Id",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);

            #region 附加展示
            dt.Columns.Add("DeptName", typeof(string));//交办单位
            dt.Columns.Add("AssignTime", typeof(string));//交办时间
            dt.Columns.Add("OtherDeptName", typeof(string));//协办单位
            dt.Columns.Add("OverState", typeof(string));//超时状态
            dt.Columns.Add("LimitTime", typeof(string));//限制时间
            dt.Columns.Add("GapTime", typeof(string));//时间差
            dt.Columns.Add("FilePath", typeof(string));//语音文件路径
            dt.Columns.Add("Buttons", typeof(object));//操作按钮
            var configly = configBll.GetModelList(" F_ParamCode='PlayLeaveVoice' ").FirstOrDefault();
            var config = configBll.GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
            var configcs = configBll.GetModelList(" F_ParamCode='CSYJ' ").FirstOrDefault();
           // var reminds = remindBLL.GetModelList(" F_IsDelete=0 and F_Type =1").ToList();
            foreach (DataRow dr in dt.Rows)
            {
                //获取最新交办信息
                string iszbdw = "0";
                int state = Int32.Parse(dr["F_WorkState"].ToString());
                string ispd = "";
                if (state > 1 && User.F_RoleCode != "DBZY" && User.F_RoleCode != "DBGLY")
                {
                    string sqljb = "SELECT TOP 1 * FROM T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' and F_State=1 and F_IsDelete=0 and F_IsSure<>3   ORDER BY F_Id DESC";
                    var dtjb = DbHelperSQL.Query(sqljb).Tables[0];
                    if (dtjb.Rows.Count > 0)
                    {
                        if (dtjb.Rows[0]["F_MainDeptId"].ToString() == User.F_DeptId.ToString()) { iszbdw = "1"; }
                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_MainDeptId"].ToString() + "')");
                        if (dtjb.Rows[0]["F_OtherDeptIds"] != null && dtjb.Rows[0]["F_OtherDeptIds"].ToString() != "")
                        {
                            dr["OtherDeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_OtherDeptIds"].ToString() + "')");
                        }
                        dr["AssignTime"] = dtjb.Rows[0]["F_CreateTime"].ToString();
                        #region
                        if (state < (int)EnumWorkState.dealed || state == (int)EnumWorkState.reload)
                        {
                            var lt = dtjb.Rows[0]["F_LimitTime"].ToString();//限制时间
                            dr["LimitTime"] = lt;
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                if (ltime > DateTime.Now)
                                {
                                    string SY = "SELECT  COUNT(1)  FROM T_Sys_WorkOFFDays WHERE F_OffState =0    AND F_OffDate > '" + DateTime.Now.ToString("yyyy-MM-dd") + "' AND F_OffDate<'" + lt + "'";
                                    var SYSJ = DbHelperSQL.GetSingle(SY);
                                    if (!string.IsNullOrEmpty(SYSJ.ToString()))
                                    {
                                        try
                                        {
                                            ltime = ltime.AddDays(-int.Parse(SYSJ.ToString()));
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                                TimeSpan ts = ltime.Subtract(DateTime.Now);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime > DateTime.Now)
                                {
                                    if (configcs != null)
                                    {
                                        int cs = Int32.Parse(configcs.F_ParamValue);
                                        if (ts.TotalHours > cs)
                                        {
                                            dr["OverState"] = 1;
                                        }
                                        else
                                        {
                                            dr["OverState"] = 2;
                                        }
                                    }
                                    dr["GapTime"] = "剩余" + gshsj;
                                }
                                else
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                        }
                        if (state == (int)EnumWorkState.finish)
                        {
                            var closetime = dr["F_DealTime"].ToString();//关闭工单时间
                            var dttime = DateTime.Now;
                            if (!string.IsNullOrWhiteSpace(closetime)) { dttime = DateTime.Parse(closetime); }
                            else
                            {
                                var DealTime = dr["F_CloseTime"].ToString();
                                if (!string.IsNullOrWhiteSpace(DealTime)) { dttime = DateTime.Parse(DealTime); }
                            }
                            var lt = dtjb.Rows[0]["F_LimitTime"].ToString();//限制时间
                            dr["LimitTime"] = lt;
                            if (!string.IsNullOrWhiteSpace(lt))
                            {
                                var ltime = DateTime.Parse(lt);
                                TimeSpan ts = ltime.Subtract(dttime);
                                double tss = double.Parse(Math.Round(ts.TotalSeconds, 0).ToString());
                                if (tss < 0) { tss = -tss; }
                                string gshsj = DateTimeConvert.parseTimeSeconds(tss, 1);
                                if (ltime < dttime)
                                {
                                    dr["OverState"] = 3;
                                    dr["GapTime"] = "超时" + gshsj;
                                }
                            }
                        }
                        #endregion
                        ispd = dtjb.Rows[0]["F_IsNext"] != null ? dtjb.Rows[0]["F_IsNext"].ToString() : "";
                    }
                    else
                    {

                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dr["F_MainDeptId"].ToString() + "')");
                    }
                }
                if (dr["F_LeaveRecordId"] != null && dr["F_LeaveRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetLeavePath(dr["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                }
                else if (dr["F_CallRecordId"] != null && dr["F_CallRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetCallPath(dr["F_CallRecordId"].ToString(), config.F_ParamValue);
                }
                #region 按钮
                List<ButtonGroup.button> btns = new List<ButtonGroup.button>();
                //0督办-待办，1督办-办理中，2督办-超期未完结，3督办-已退回，4督办-已完结
                btns.Clear();
               

                if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "EJWLDW")
                {
                    btns = ButtonGroup.GetButtons(dr["F_WorkState"].ToString(), User.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString(), iszbdw, ispd);
                    #region 判断是否存在待督办
                  
                    var butt = btns.Find(c => c.key == ButtonGroup.turnsee().key);
                    if ( butt != null)
                        btns.Remove(butt);
                    var delay = btns.Find(c => c.key == ButtonGroup.delay().key);
                    if (delay != null)
                        btns.Remove(delay);
                    #endregion
                }
                else
                {
                    switch (strtab)
                    {
                        case "0"://督办-待办 操作为：回复、派单（督办且审核交办）、退回（不督办）、打印
                            btns.Add(ButtonGroup.oversee()); //督办 输入督办信息确认后跳转编辑页面进行审核交办
                            btns.Add(ButtonGroup.turnnosee());//不督办 工单被退回
                            if (User.F_RoleCode == "DBZY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DBGLY")
                                btns.Add(ButtonGroup.forceend());

                            break;
                        case "1"://督办-办理中 操作为：查看工单、短信催办
                           
                            if (User.F_RoleCode == "DBZY" || User.F_RoleCode == "DBGLY" || User.F_RoleCode == "GLY")
                            {
                                if (state ==3)
                                {
                                    btns.Add(ButtonGroup.auditreback()); 
                                }
                                else
                                {
                                    btns.Add(ButtonGroup.takeback());
                                    btns.Add(ButtonGroup.forceend());
                                }
                            }
                                
                            break;
                        case "2"://督办-超期未完结 操作为：查看工单、短信催办
                                 //if (User.F_RoleCode == "DBZY" || User.F_RoleCode == "GLY")
                                 // btns.Add(ButtonGroup.forceend());
                            break;
                        case "3"://督办-已退回：查看
                            break;
                        case "4"://督办-已完结：查看
                            break;
                        case "6"://督办-办理中 操作为：查看工单、短信催办
                            if (isExamine!=1)
                            {
                                if (User.F_RoleCode == "DBZY" || User.F_RoleCode == "DBGLY" || User.F_RoleCode == "GLY")
                                {
                                    btns.Add(ButtonGroup.Approved());
                                    btns.Add(ButtonGroup.Auditreject());
                                }
                            }
                            else
                            {
                                if (User.F_RoleCode == "DBZY" || User.F_RoleCode == "DBGLY" || User.F_RoleCode == "GLY")
                                {
                                    btns.Add(ButtonGroup.forceend());
                                }
                            }
                           

                            break;
                    }
                    btns.Add(ButtonGroup.query());
                }

                dr["Buttons"] = btns;
                #endregion
            }
            #endregion

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };
            return Content(obj.ToJson());
        }


        public ActionResult GetNoticeListOLD(int isdc = 0)
        {
            DataTable dt = new DataTable();





            string sql = " and F_IsDelete=0 ";
            string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
            string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
            string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
            string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));
            string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));
            string strddusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("ddusercode"));//调度员
            int source = RequestString.GetInt("source", 0);
            int keyid = RequestString.GetInt("keyid", 0);
            int type = RequestString.GetInt("type", 0);
            int bigtype = RequestString.GetInt("bigtype", 0);
            int smalltype = RequestString.GetInt("smalltype", 0);
            int sourcearea = RequestString.GetInt("sourcearea", 0);
            int deptid = RequestString.GetInt("deptid", 0);

            string strpageindex = RequestString.GetQueryString("page");
            int pageindex = 1;
            string strpagesize = RequestString.GetQueryString("pagesize");
            int pagesize = 10;
           
          
            if (strworkid.Trim() != "" && strworkid != "undefined")
            {
                sql += " and F_WorkOrderId like '%" + strworkid + "%' ";
            }
            if (strname.Trim() != "" && strname != "undefined")
            {
                sql += " and F_CusName like '%" + strname + "%' ";
            }
            if (strtel.Trim() != "" && strtel != "undefined")
            {
                sql += " and (F_CusPhone like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
            }
            string ComTitle = HttpUtility.UrlDecode(RequestString.GetQueryString("ComTitle"));
            string ComContent = HttpUtility.UrlDecode(RequestString.GetQueryString("ComContent"));
            string Result = HttpUtility.UrlDecode(RequestString.GetQueryString("Result"));
            if (ComTitle.Trim() != "" && ComTitle != "undefined")
            {
                sql += " and F_ComTitle like '%" + ComTitle + "%' ";
            }
            if (Result.Trim() != "" && Result != "undefined")
            {
                sql += " and F_Result like '%" + Result + "%' ";
            }
            if (ComContent.Trim() != "" && ComContent != "undefined")
            {
                sql += " and F_ComContent like '%" + ComContent + "%' ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%'" +
                      " or F_Result like  '%" + strkey + "%' ) ";
            }
            #region  坐席&调度员
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {//坐席
                var usercode = strusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in usercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_CreateUser in (" + newusercode + ") ";
                }
            }
            if (strddusercode.Trim() != "" && strddusercode != "undefined")
            {//调度员
                var ddusercode = strddusercode.Trim().Split(',');
                var newusercode = "";
                foreach (var item in ddusercode)
                {
                    if (!string.IsNullOrWhiteSpace(item.Trim()))
                        newusercode += "'" + item + "',";
                }
                newusercode = newusercode.Trim(',');
                if (newusercode.Trim() != "" && newusercode != "undefined")
                {
                    sql += " and F_AssignUser in(" + newusercode + ") ";
                }
            }
            //if (strusercode.Trim() != "" && strusercode != "undefined")
            //{
            //    sql += " and F_CreateUser = '" + strusercode + "' ";
            //}
            #endregion

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            string sqlwheres = "";
            if (keyid != 0)
            {
                sqlwheres = " INNER JOIN[GetValueId]('" + keyid + "') Value on a.F_Key = Value.F_ValueId";
                //sql += "and (F_Key IN(  SELECT  F_ValueId from [GetValueId]('"+ keyid + "'))" +
                //  " or F_Key='" + keyid + "' )";
            }
            if (type != 0)
            {
                sql += " and F_InfoType = '" + type + "' ";
            }
            if (bigtype != 0)
            {
                sql += " and F_InfoConBigType = '" + bigtype + "' ";
            }
            if (smalltype != 0)
            {
                sql += " and F_InfoConSmallType = '" + smalltype + "' ";
            }
            if (sourcearea != 0)
            {
                sql += " and F_SourceArea = '" + sourcearea + "' ";
            }
            if (deptid != 0)
            {
                string sqlwhere = "select F_WorkOrderID from T_Bus_AssignedInfo WITH(NOLOCK) where F_MainDeptId = '" + deptid + "' and F_IsSure in (0,1) and F_State=1 and F_IsDelete=0 ";
                sql += " and F_WorkOrderID in(" + sqlwhere + ")";
            }
            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and F_CreateTime>='" + strstarttime + "' ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and F_CreateTime<='" + strendtime + "' ";
            }

            if (User.F_RoleCode == "WLDW")
            {
                string sqlwhere = "select F_WorkOrderID from T_Bus_NoticeCriticism WITH(NOLOCK) where ','+F_DeptIds+',' like  '%," + User.F_DeptId + ",%' and F_State=1 and F_IsDelete=0 ";
                sql += " and F_WorkOrderID in(" + sqlwhere + ")";
            }
            else
            {
                sql += " and F_WorkOrderID in(select F_WorkOrderID from T_Bus_NoticeCriticism WITH(NOLOCK) where F_State=1 and F_IsDelete=0) ";
            }

            if (strpageindex.Trim() != "")
            {
                pageindex = Convert.ToInt32(strpageindex);
            }

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

            //string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName";
            string cols = "F_WorkOrderId,F_ComTitle,F_WorkState,F_MainDeptId,F_OtherDeptIds,F_DealTime,F_LeaveRecordId,F_CallRecordId,F_IsResult,F_IsProtect,F_IsReturn,F_CreateTime,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,dbo.GetDictionaryName(F_InfoSource) as SourceName,F_Identification";
            if (isdc > 0)
            {
                var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder WITH(NOLOCK) where 1=1 " + sql).Tables[0];
                var msg = new NPOIHelper().ExportToExcel("工单列表", dtdc);
                if (msg == "")
                {
                    return Success("导出成功");
                }
                else
                {
                    return Error("导出失败");
                }
            }

            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                "T_Bus_WorkOrder a WITH(NOLOCK)" + sqlwheres,
                "F_Id",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);

            #region 声音文件
            dt.Columns.Add("DeptName", typeof(string));//交办单位
            dt.Columns.Add("OtherDeptName", typeof(string));//协办单位
            dt.Columns.Add("AssignTime", typeof(string));//交办时间
            dt.Columns.Add("NoticeDeptName", typeof(string));//通报单位
            dt.Columns.Add("NoticeReson", typeof(string));//通报原因
            dt.Columns.Add("IsReturnNotice", typeof(string));
            dt.Columns.Add("FilePath", typeof(string));
            dt.Columns.Add("Buttons", typeof(object));
            var configly = configBll.GetModelList(" F_ParamCode='PlayLeaveVoice' ").FirstOrDefault();
            var config = configBll.GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
            int IsReturnNotice = 0;
            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "ZXLDGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {
                IsReturnNotice = 1;
            }
            foreach (DataRow dr in dt.Rows)
            {
                //获取最新交办信息
                //string iszbdw = "0";
                int state = Int32.Parse(dr["F_WorkState"].ToString());
                if (state > 1)
                {
                    string sqljb = "SELECT TOP 1 * FROM T_Bus_AssignedInfo WITH(NOLOCK) WHERE F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' and F_State=1 and F_IsDelete=0 and F_IsSure<>3   ORDER BY F_Id DESC";
                    var dtjb = DbHelperSQL.Query(sqljb).Tables[0];
                    if (dtjb.Rows.Count > 0)
                    {
                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_MainDeptId"].ToString() + "')");
                        if (dtjb.Rows[0]["F_OtherDeptIds"] != null && dtjb.Rows[0]["F_OtherDeptIds"].ToString() != "")
                        {
                            dr["OtherDeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dtjb.Rows[0]["F_OtherDeptIds"].ToString() + "')");
                        }
                        dr["AssignTime"] = dtjb.Rows[0]["F_CreateTime"].ToString();
                    }
                    else
                    {

                        dr["DeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dr["F_MainDeptId"].ToString() + "')");
                    }
                }
                //获取最新通报信息
                string sqltb = "SELECT TOP 1 * FROM T_Bus_NoticeCriticism WITH(NOLOCK) WHERE F_WorkOrderId='" + dr["F_WorkOrderId"].ToString() + "' and F_State=1 and F_IsDelete=0  ORDER BY F_Id DESC";
                var dttb = DbHelperSQL.Query(sqltb).Tables[0];
                if (dttb.Rows.Count > 0)
                {
                    if (dttb.Rows[0]["F_DeptIds"] != null && dttb.Rows[0]["F_DeptIds"].ToString() != "")
                    {
                        dr["NoticeDeptName"] = DbHelperSQL.GetSingle(" select dbo.GetDeptNames('" + dttb.Rows[0]["F_DeptIds"].ToString() + "')");
                    }

                    dr["NoticeReson"] = dttb.Rows[0]["F_Content"] != null ? dttb.Rows[0]["F_Content"].ToString() : "";
                }
                if (dr["F_LeaveRecordId"] != null && dr["F_LeaveRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetLeavePath(dr["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                }
                else if (dr["F_CallRecordId"] != null && dr["F_CallRecordId"].ToString() != "")
                {
                    dr["FilePath"] = GetCallPath(dr["F_CallRecordId"].ToString(), config.F_ParamValue);
                }
                List<ButtonGroup.button> btns = new List<ButtonGroup.button>();
                btns.Add(ButtonGroup.query());
                dr["Buttons"] = btns;

                dr["IsReturnNotice"] = IsReturnNotice;
            }

            #endregion

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = dt,
                total = recordCount
            };

            return Content(obj.ToJson());
        }

        public ActionResult GetWorkorderSimp()
        {




            string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
            if (!string.IsNullOrEmpty(strworkorderid))
            {
                string sql = "select F_WorkOrderId,F_CreateTime,F_ComTitle,F_Result,dbo.GetDictionaryName(F_InfoSource) as SourceName,dbo.GetDeptName(F_MainDeptId) deptname "
                    + " from T_Bus_WorkOrder WITH(NOLOCK) where F_WorkOrderId ='" + strworkorderid + "'";
                var dt = DbHelperSQL.Query(sql).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    return Success("成功", dt);
                }
                return Error("获取失败");
            }
            return Error("参数错误");
        }
        /// <summary>
        /// 获取工单信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetWorkOrder()
        {
            string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
            //int type = RequestString.GetInt("type", 0);//0基本信息1监察意见2领导批示3办理情况4回访信息5督办信息6办理过程
            if (!string.IsNullOrEmpty(strworkorderid))
            {
                string sql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName1,"
                    + "dbo.GetAreaName(F_SourceArea) as AreaName,dbo.GetDictionaryName(F_InfoSource) as SourceName,dbo.GetDictionaryName(F_Key) as KeyName,dbo.GetAreaChildrenCode(F_Township) as Township , dbo.GetAreaChildrenCode(F_Village) as Village,dbo.GetDeptName(F_MainDeptId) deptname ," + "F_DeptIdIsSms = (select F_IsSms  from T_Sys_Department where F_DeptId =a.F_MainDeptId)"
                      + " from T_Bus_WorkOrder a WITH(NOLOCK) where F_WorkOrderId ='" + strworkorderid + "'";
                var dt = DbHelperSQL.Query(sql).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    if (dt.Rows[0]["F_IsProtect"] != null && (User.F_RoleCode == "WLDW" || User.F_RoleCode == "EJWLDW" ))
                    {
                        string isp = dt.Rows[0]["F_IsProtect"].ToString();
                        if (isp == "1")
                        {
                            dt.Rows[0]["F_CusName"] = "";
                            dt.Rows[0]["F_CusPhone"] = "";
                            dt.Rows[0]["F_ConPhone"] = "";
                        }
                    }

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


                    var configfj = configBll.GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();

                    //string jcsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_DeptId) as DeptName "
                    //                + "from T_Bus_RemindRecord WITH(NOLOCK) where F_Type=2 and F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "'";
                    string jcsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_DeptId) as DeptName "
                                    + "from T_Bus_RemindRecord WITH(NOLOCK) where F_Type=2 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                    string dbsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_DeptId) as DeptName "
                                    + "from T_Bus_RemindRecord WITH(NOLOCK) where F_Type=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                    string pssql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_SubmitSuper WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_Type=1 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                    string zssql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_SubmitSuper WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_Type=2 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                    string htsql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_SubmitSuper WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_Type=3 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                    string jbsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName,dbo.GetDictionaryNames(F_StandardIDS) as StandardNames  "
                                    + "from T_Bus_AssignedInfo WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                    string ejjbsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName "
                                    + "from T_Bus_AssignedInfo_Next WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                    string thsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_CreateDeptId) as DeptName "
                                    + "from T_Bus_Feedback WITH(NOLOCK) where F_State=1 and F_Type=3 and F_IsDelete=0 and  F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                    string yssql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_DelayTime WITH(NOLOCK) where  F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                    string blsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_CreateDeptId) as DeptName "
                                    + "from T_Bus_Feedback WITH(NOLOCK) where F_State=1 and F_Type!=3 and F_IsDelete=0 and  F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                    string ejblsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_CreateDeptId) as DeptName "
                                    + "from T_Bus_Feedback_Next WITH(NOLOCK) where F_State=1 and F_Type!=3 and F_IsDelete=0 and  F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                    string hfsql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_VisitResult WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime ";
                    string gcsql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_Operation WITH(NOLOCK) where F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime ";
                    string cbsql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_Additional WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";


                    string pysql = "select * from PublicComment WITH(NOLOCK) where  WorkOrderId ='" + strworkorderid + "' order by CreateTime";




                    #region 声音文件
                    dt.Columns.Add("FilePath", typeof(string));

                    if (dt.Rows[0]["F_LeaveRecordId"] != null)
                    {
                        dt.Rows[0]["FilePath"] = GetLeavePath(dt.Rows[0]["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                    }
                    else if (dt.Rows[0]["F_CallRecordId"] != null)
                    {
                        dt.Rows[0]["FilePath"] = GetCallPath(dt.Rows[0]["F_CallRecordId"].ToString(), config.F_ParamValue);
                    }
                    #endregion

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

                    #region 监察信息
                    var jcdt = DbHelperSQL.Query(jcsql).Tables[0];
                    if (configfj != null)
                    {
                        jcdt = BindFileData(jcdt, configfj.F_ParamValue);
                    }
                    #endregion

                    #region 批示信息
                    var psdt = DbHelperSQL.Query(pssql).Tables[0];
                    if (configfj != null)
                    {
                        psdt = BindFileData(psdt, configfj.F_ParamValue);
                    }
                    #endregion

                    #region 指示信息
                    var zsdt = DbHelperSQL.Query(zssql).Tables[0];
                    if (configfj != null)
                    {
                        zsdt = BindFileData(zsdt, configfj.F_ParamValue);
                    }
                    #endregion

                    #region 回退信息
                    var htdt = DbHelperSQL.Query(htsql).Tables[0];
                    #endregion

                    #region 督办信息
                    var dbdt = DbHelperSQL.Query(dbsql).Tables[0];
                    if (configfj != null)
                    {
                        dbdt = BindFileData(dbdt, configfj.F_ParamValue);
                    }
                    #endregion

                    #region 交办信息
                    var jbdt = DbHelperSQL.Query(jbsql).Tables[0];
                    if (configfj != null)
                    {
                        jbdt = BindFileData(jbdt, configfj.F_ParamValue);
                    }
                    var ejjbdt = DbHelperSQL.Query(ejjbsql).Tables[0];
                    if (configfj != null)
                    {
                        ejjbdt = BindFileData(ejjbdt, configfj.F_ParamValue);
                    }
                    #endregion

                    #region 退回信息
                    var thdt = DbHelperSQL.Query(thsql).Tables[0];
                    #endregion

                    #region 延时信息
                    var ysdt = DbHelperSQL.Query(yssql).Tables[0];
                    if (configfj != null)
                    {
                        ysdt = BindFileData(ysdt, configfj.F_ParamValue);
                    }
                    #endregion

                    #region 办理情况
                    var bldt = DbHelperSQL.Query(blsql).Tables[0];
                    if (configfj != null)
                    {
                        bldt = BindFileDatas(bldt, configfj.F_ParamValue);
                    }
                    var ejbldt = DbHelperSQL.Query(ejblsql).Tables[0];
                    if (configfj != null)
                    {
                        ejbldt = BindFileData(ejbldt, configfj.F_ParamValue);
                    }
                    #endregion

                    #region 回访信息
                    var hfdt = DbHelperSQL.Query(hfsql).Tables[0];
                    hfdt.Columns.Add("FilePath", typeof(string));
                    foreach (DataRow bldr in hfdt.Rows)
                    {
                        if (bldr["F_CallRecordId"] != null && config != null)
                        {
                            bldr["FilePath"] = GetCallPath(bldr["F_CallRecordId"].ToString(), config.F_ParamValue);
                        }
                    }
                    #endregion

                    #region 市民催单
                    var cbdt = DbHelperSQL.Query(cbsql).Tables[0];




                    cbdt.Columns.Add("FilePath", typeof(string));
                    foreach (DataRow bldr in cbdt.Rows)
                    {
                        if (bldr["F_CallRecordId"] != null && config != null)
                        {
                            bldr["FilePath"] = GetCallPath(bldr["F_CallRecordId"].ToString(), config.F_ParamValue);
                        }
                    }
                    #endregion
                    #region 市民评议
                    var pydt = DbHelperSQL.Query(pysql).Tables[0];
                    #endregion
                    #region 办理过程
                    var gcdt = DbHelperSQL.Query(gcsql).Tables[0];
                    gcdt.Columns.Add("File", typeof(object));
                    gcdt.Columns.Add("FilePath", typeof(string));
                    if (configfj != null || configly != null || config != null)
                    {
                        foreach (DataRow bldr in gcdt.Rows)
                        {
                            if (bldr["F_File"] != null && bldr["F_File"].ToString() != "" && configfj != null)
                            {
                                bldr["File"] = GetFileData(bldr["F_File"].ToString(), configfj.F_ParamValue);
                            }

                            if (bldr["F_LeaveRecordId"] != null && configly != null)
                            {
                                bldr["FilePath"] = GetLeavePath(bldr["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                            }
                            else if (bldr["F_CallRecordId"] != null && config != null)
                            {
                                bldr["FilePath"] = GetCallPath(bldr["F_CallRecordId"].ToString(), config.F_ParamValue);
                            }
                        }
                    }
                    #endregion

                    #region 操作按钮
                    var btns = new List<ButtonGroup.button>();

                    if (jbdt.Rows.Count > 0)
                    {

                        var jbzx = jbdt.Rows[jbdt.Rows.Count - 1];

                        string ispd = jbzx["F_IsNext"].ToString();
                        string iszbdw = "0";
                        string fmd = jbzx["F_MainDeptId"].ToString();
                        string fod = jbzx["F_OtherDeptIds"] == null ? "" : jbzx["F_OtherDeptIds"].ToString();
                        if (fmd == User.F_DeptId.ToString())
                        { iszbdw = "1"; }
                        else if (fod != "" && fod.Split(',').Contains(User.F_DeptId.ToString()))
                        {
                            iszbdw = "2";
                        }
                        if (!(User.F_RoleCode == "WLDW" && iszbdw == "0"))
                        {
                            btns = ButtonGroup.GetButtons(dt.Rows[0]["F_WorkState"].ToString(), User.F_RoleCode.ToUpper(), dt.Rows[0]["F_IsResult"].ToString(), iszbdw, ispd);
                        }
                    }
                    else
                    {
                        btns = ButtonGroup.GetButtons(dt.Rows[0]["F_WorkState"].ToString(), User.F_RoleCode.ToUpper(), dt.Rows[0]["F_IsResult"].ToString(), "0");
                    }


                    #region 判断是否存在待督办
                    var recount = remindBLL.GetModelList("F_State=0 and F_IsDelete=0 and F_Type=1 and F_WorkOrderId ='" + strworkorderid + "'").ToList().Count();
                    var butt = btns.Find(c => c.key == ButtonGroup.turnsee().key);
                    if (recount > 0)
                    {
                        if (butt != null)
                            btns.Remove(butt);
                        if (User.F_RoleCode == "DBZY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
                        {
                            btns.Add(ButtonGroup.oversee());
                            btns.Add(ButtonGroup.turnnosee());
                        }
                    }
                    if (btns == null)
                    {
                        btns.Add(ButtonGroup.query());
                    }
                    else
                    {
                        if (btns.Count == 0)
                            btns.Add(ButtonGroup.query());
                    }
                    #endregion
                    #endregion

                    #region 其他权限
                    int issend = 0;
                    //if (dt.Rows[0]["F_IsRelease"] != null && (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "ZXLDGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG"|| User.F_RoleCode == "MTDD"))
                    //{
                    //    if (dt.Rows[0]["F_IsRelease"].ToString() != "1")
                    //    {
                    //        issend = 1;
                    //    }
                    //}
                    int isnotice = 0;
                    if (dt.Rows[0]["F_IsNotice"] != null && (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "ZXLDGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG"))
                    {
                        if (dt.Rows[0]["F_IsNotice"].ToString() != "1")
                        {
                            isnotice = 1;
                        }
                    }
                    int isedit = 0;
                    //if (dt.Rows[0]["F_IsRelease"] != null && (User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "ZXLDGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG"))
                    //{
                    //    isedit = 1;
                    //}
                    #endregion

                    var obj = new
                    {
                        data = dt,
                        jcdata = jcdt,
                        psdata = psdt,
                        zsdata = zsdt,
                        htdata = htdt,
                        dbdata = dbdt,
                        jbdata = jbdt,
                        ejjbdata = ejjbdt,
                        thdata = thdt,
                        ysdata = ysdt,
                        bldata = bldt,
                        ejbldata = ejbldt,
                        hfdata = hfdt,
                        cbdata = cbdt,
                        gcdata = gcdt,
                        issend = issend,
                        isedit = isedit,
                        isnotice = isnotice,
                        btndata = btns,
                        pydt
                    };
                    return Success("获取成功", obj);
                }
                else
                {
                    return Error("获取失败");
                }
            }
            else
            {
                return Error("参数传输失败");
            }
        }
        /// <summary>
        /// 导出word
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult ExportWorkOrder()
        {


            string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
            if (!string.IsNullOrEmpty(strworkorderid))
            {
                string sql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName1,"
                    + "dbo.GetAreaName(F_SourceArea) as AreaName,dbo.GetDictionaryName(F_InfoSource) as SourceName,dbo.GetDictionaryName(F_Key) as KeyName,dbo.GetDeptName(F_MainDeptId) deptname ," + "F_DeptIdIsSms = (select F_IsSms  from T_Sys_Department where F_DeptId =a.F_MainDeptId)"
                      + " from T_Bus_WorkOrder a WITH(NOLOCK) where F_WorkOrderId ='" + strworkorderid + "'";
                var dt = DbHelperSQL.Query(sql).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    if (dt.Rows[0]["F_IsProtect"] != null && (User.F_RoleCode == "WLDW" || User.F_RoleCode == "EJWLDW" || User.F_RoleCode == "DBZY"))
                    {
                        string isp = dt.Rows[0]["F_IsProtect"].ToString();
                        if (isp == "1")
                        {
                            dt.Rows[0]["F_CusName"] = "";
                            dt.Rows[0]["F_CusPhone"] = "";
                            dt.Rows[0]["F_ConPhone"] = "";
                        }
                    }
                    string jbsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName,dbo.GetDictionaryNames(F_StandardIDS) as StandardNames  "
                                    + "from T_Bus_AssignedInfo WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime desc";
                    var jbdt = DbHelperSQL.Query(jbsql).Tables[0];
                    //ExportWord np = new ExportWord();
                    //np.CreateWord(dt ,jbdt,User .F_UserCode  );
                    //string url = dt.Rows[0]["F_WorkOrderId"].ToString();
                    //url = "http://192.168.8.9:1042//Upload/Word/工单" + url + ".doc";
                    //return Success(url);

                    var aw = new AsposeWord();
                    aw.OpenWithTemplate(Server.MapPath("/Upload/Word/热线工单模版.doc"));
                    aw.Builder();
                    aw.CreateAssignWord(dt, jbdt, User.F_UserCode);
                    var bt = aw.ExportAs();
                    Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
                    return File(bt, "application/msword", "工单" + strworkorderid + ".doc");
                }
                else
                {
                    return Error("获取失败");
                }
            }
            else
            {
                return Error("参数传输失败");
            }
        }
        /// <summary>
        /// 获取工单信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetWorkOrderNew()
        {
            string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
            int type = RequestString.GetInt("type", 0);//0基本信息1监察意见2领导批示3办理情况4回访信息5督办信息6办理过程
            if (!string.IsNullOrEmpty(strworkorderid))
            {
                var configly = configBll.GetModelList(" F_ParamCode='PlayLeaveVoice' ").FirstOrDefault();
                var config = configBll.GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
                var configfj = configBll.GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();

                switch (type)
                {
                    case 0:
                        #region 基本信息
                        string sql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName1,dbo.GetAreaName(F_SourceArea) as AreaName,dbo.GetDictionaryName(F_InfoSource) as SourceName,dbo.GetKeyNames(F_Key) as KeyName,dbo.GetDeptName(F_MainDeptId) deptname ,dbo.GetAreaChildrenCode(F_Township) as Township , dbo.GetAreaChildrenCode(F_Village) as Village,F_DeptIdIsSms = (select F_IsSms  from T_Sys_Department WITH(NOLOCK) where F_DeptId =a.F_MainDeptId),(select  top 1 remark   from T_Bus_People  where F_WorkOrderId =a.F_WorkOrderId order by F_ID desc) as remark from T_Bus_WorkOrder a WITH(NOLOCK) where F_WorkOrderId ='" + strworkorderid + "'";
                        var dt = DbHelperSQL.Query(sql).Tables[0];
                        if (dt.Rows.Count > 0)
                        {
                            if (User.F_RoleCode == "WLDW"&& dt.Rows[0]["F_MainDeptId"] .ToString ()!= User.F_DeptId.ToString())
                            {
                                dt.Rows[0]["F_Result"] = "";
                            }

                            if (dt.Rows[0]["F_IsProtect"] != null && (User.F_RoleCode == "WLDW" || User.F_RoleCode == "EJWLDW" || User.F_RoleCode == "DMTCK"))
                            {
                                string isp = dt.Rows[0]["F_IsProtect"].ToString();
                                if (isp == "1")
                                {
                                   // dt.Rows[0]["F_CusName"] = "";
                                    dt.Rows[0]["F_CusPhone"] = "";
                                    dt.Rows[0]["F_ConPhone"] = "";
                                    if (User.F_RoleCode == "DMTCK")
                                    {
                                        dt.Rows[0]["F_CusName"] = "";
                                        dt.Rows[0]["F_ConName"] = "";

                                    }
                                       

                                }
                            }
                           

                            #region 声音文件
                            dt.Columns.Add("FilePath", typeof(string));

                            if (dt.Rows[0]["F_LeaveRecordId"] != null)
                            {
                                dt.Rows[0]["FilePath"] = GetLeavePath(dt.Rows[0]["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                            }
                            else if (dt.Rows[0]["F_CallRecordId"] != null)
                            {
                                dt.Rows[0]["FilePath"] = GetCallPath(dt.Rows[0]["F_CallRecordId"].ToString(), config.F_ParamValue);
                            }
                            #endregion

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

                            #region 操作按钮
                            var btns = new List<ButtonGroup.button>();

                            string jbsql1 = "select top 1 * from T_Bus_AssignedInfo WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                            var jbdt1 = DbHelperSQL.Query(jbsql1).Tables[0];
                            if (jbdt1.Rows.Count > 0)
                            {

                                var jbzx = jbdt1.Rows[0];

                                string ispd = jbzx["F_IsNext"].ToString();
                                string iszbdw = "0";
                                string fmd = jbzx["F_MainDeptId"].ToString();
                                string fod = jbzx["F_OtherDeptIds"] == null ? "" : jbzx["F_OtherDeptIds"].ToString();
                                if (fmd == User.F_DeptId.ToString())
                                { iszbdw = "1"; }
                                else if (fod != "" && fod.Split(',').Contains(User.F_DeptId.ToString()))
                                {
                                    iszbdw = "2";
                                }
                                if (!(User.F_RoleCode == "WLDW" && iszbdw == "0"))
                                {
                                    btns = ButtonGroup.GetButtons(dt.Rows[0]["F_WorkState"].ToString(), User.F_RoleCode.ToUpper(), dt.Rows[0]["F_IsResult"].ToString(), iszbdw, ispd);
                                }
                            }
                            else
                            {
                                btns = ButtonGroup.GetButtons(dt.Rows[0]["F_WorkState"].ToString(), User.F_RoleCode.ToUpper(), dt.Rows[0]["F_IsResult"].ToString(), "0");
                            }


                            #region 判断是否存在待督办
                            var recount = remindBLL.GetModelList("F_State=0 and F_IsDelete=0 and F_Type=1 and F_WorkOrderId ='" + strworkorderid + "'").ToList().Count();
                            var butt = btns.Find(c => c.key == ButtonGroup.turnsee().key);
                            if (recount > 0)
                            {
                                if (butt != null)
                                    btns.Remove(butt);
                                if (User.F_RoleCode == "DBZY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
                                {
                                    btns.Add(ButtonGroup.oversee());
                                    btns.Add(ButtonGroup.turnnosee());
                                }
                            }
                            if (btns == null)
                            {
                                btns.Add(ButtonGroup.query());
                            }
                            else
                            {
                                if (btns.Count == 0)
                                    btns.Add(ButtonGroup.query());
                            }
                            #endregion
                            #endregion

                            #region 其他权限
                            int issend = 0;
                            //if (dt.Rows[0]["F_IsRelease"] != null && (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "ZXLDGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG"|| User.F_RoleCode == "MTDD"))
                            //{
                            //    if (dt.Rows[0]["F_IsRelease"].ToString() != "1")
                            //    {
                            //        issend = 1;
                            //    }
                            //}
                            int isnotice = 0;
                            if (dt.Rows[0]["F_IsNotice"] != null && (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "ZXLDGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG"))
                            {
                                if (dt.Rows[0]["F_IsNotice"].ToString() != "1")
                                {
                                    isnotice = 1;
                                }
                            }
                            int isedit = 0;
                            //if (dt.Rows[0]["F_IsRelease"] != null && (User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "ZXLDGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG"))
                            //{
                            //    isedit = 1;
                            //}
                            #endregion

                            var obj = new
                            {
                                data = dt,
                                issend,
                                isedit,
                                isnotice,
                                btndata = btns
                            };
                            return Success("获取成功", obj);
                        }
                        else
                        {
                            return Error("获取失败");
                        }
                    #endregion
                    case 1:
                        #region 交办信息
                        string jbsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName,dbo.GetDictionaryNames(F_StandardIDS) as StandardNames  from T_Bus_AssignedInfo WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                        string ejjbsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName from T_Bus_AssignedInfo_Next WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                        string thsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_CreateDeptId) as DeptName from T_Bus_Feedback WITH(NOLOCK) where F_State=1 and F_Type=3 and F_IsDelete=0 and  F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                        var jbdt = DbHelperSQL.Query(jbsql).Tables[0];
                        if (configfj != null)
                        {
                            jbdt = BindFileData(jbdt, configfj.F_ParamValue);
                        }
                        var ejjbdt = DbHelperSQL.Query(ejjbsql).Tables[0];
                        if (configfj != null)
                        {
                            ejjbdt = BindFileData(ejjbdt, configfj.F_ParamValue);
                        }
                        var thdt = DbHelperSQL.Query(thsql).Tables[0];
                        if (!string.IsNullOrEmpty(configfj.F_ParamValue))
                        {
                            BindFileData(thdt, configfj.F_ParamValue);
                        }
                        var obj1 = new
                        {
                            jbdata = jbdt,
                            ejjbdata = ejjbdt,
                            thdata = thdt
                        };
                        return Success("获取成功", obj1);
                    #endregion
                    case 2:
                        #region 指示信息
                        string zssql = "select *,dbo.GetUserName(F_CreateUser) as UserName from T_Bus_SubmitSuper WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_Type=2 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                        var zsdt = DbHelperSQL.Query(zssql).Tables[0];
                        if (configfj != null)
                        {
                            zsdt = BindFileData(zsdt, configfj.F_ParamValue);
                        }
                        return Success("获取成功", zsdt);
                    #endregion
                    case 3:
                        #region 回退信息
                        string htsql = "select *,dbo.GetUserName(F_CreateUser) as UserName from T_Bus_SubmitSuper WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_Type=3 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                        var htdt = DbHelperSQL.Query(htsql).Tables[0];
                        return Success("获取成功", htdt);
                    #endregion
                    case 4:
                        #region 办理情况
                        string blsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_CreateDeptId) as DeptName from T_Bus_Feedback WITH(NOLOCK) where F_State=1 and F_Type!=3 and F_IsDelete=0 and  F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                        string ejblsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_CreateDeptId) as DeptName from T_Bus_Feedback_Next WITH(NOLOCK) where F_State=1 and F_Type!=3 and F_IsDelete=0 and  F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";

                       
                        var bldt = DbHelperSQL.Query(blsql).Tables[0];
                        if (bldt != null && bldt.Rows.Count > 0)
                        {
                            if (User.F_RoleCode == "WLDW" && bldt.Rows[0]["F_CreateDeptId"].ToString() != User.F_DeptId.ToString())
                            {

                                bldt.Rows[0]["F_Result"] = "";
                            }
                        }
                           
                        if (configfj != null)
                        {
                            bldt = BindFileDatas(bldt, configfj.F_ParamValue);
                        }
                        var ejbldt = DbHelperSQL.Query(ejblsql).Tables[0];
                        if (configfj != null)
                        {
                            ejbldt = BindFileData(ejbldt, configfj.F_ParamValue);
                        }
                        var obj5 = new
                        {
                            bldata = bldt,
                            ejbldata = ejbldt
                        };
                        return Success("获取成功", obj5);
                    #endregion
                    case 5:
                        #region 延时信息
                        string yssql = "select *,dbo.GetUserName(F_CreateUser) as UserName from T_Bus_DelayTime WITH(NOLOCK) where  F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                        var ysdt = DbHelperSQL.Query(yssql).Tables[0];
                        if (configfj != null)
                        {
                            ysdt = BindFileData(ysdt, configfj.F_ParamValue);
                        }
                        return Success("获取成功", ysdt);
                    #endregion
                    case 6:
                        #region 回访信息
                        string hfsql = "select *,dbo.GetUserName(F_CreateUser) as UserName from T_Bus_VisitResult WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime ";
                        var hfdt = DbHelperSQL.Query(hfsql).Tables[0];
                        hfdt.Columns.Add("FilePath", typeof(string));
                        foreach (DataRow bldr in hfdt.Rows)
                        {
                            if (bldr["F_CallRecordId"] != null && config != null)
                            {
                                bldr["FilePath"] = GetCallPath(bldr["F_CallRecordId"].ToString(), config.F_ParamValue);
                            }
                        }
                        return Success("获取成功", hfdt);
                    #endregion
                    case 7:
                        #region 督办信息
                        string dbsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_DeptId) as DeptName  from T_Bus_RemindRecord WITH(NOLOCK) where F_Type=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                        var dbdt = DbHelperSQL.Query(dbsql).Tables[0];
                        if (configfj != null)
                        {
                            dbdt = BindFileData(dbdt, configfj.F_ParamValue);
                        }
                        return Success("获取成功", dbdt);
                    #endregion
                    case 8:
                        #region 市民催单
                        string cbsql = "select *,dbo.GetUserName(F_CreateUser) as UserName from T_Bus_Additional WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                        var cbdt = DbHelperSQL.Query(cbsql).Tables[0];
                        cbdt.Columns.Add("FilePath", typeof(string));
                        foreach (DataRow bldr in cbdt.Rows)
                        {
                            if (bldr["F_CallRecordId"] != null && config != null)
                            {
                                bldr["FilePath"] = GetCallPath(bldr["F_CallRecordId"].ToString(), config.F_ParamValue);
                            }
                        }
                        return Success("获取成功", cbdt);
                    #endregion
                    case 9:
                        #region 办理过程
                        string gcsql = "select o.*,u.F_UserName from T_Bus_Operation o WITH(NOLOCK) left join T_Sys_UserAccount u WITH(NOLOCK) on o.F_CreateUser=u.F_UserCode  where o.F_IsDelete=0 and o.F_WorkOrderId ='" + strworkorderid + "' order by o.F_CreateTime ";
                        var gcdt = DbHelperSQL.Query(gcsql).Tables[0];
                        gcdt.Columns.Add("File", typeof(object));
                        gcdt.Columns.Add("FilePath", typeof(string));
                        if (configfj != null || configly != null || config != null)
                        {
                            foreach (DataRow bldr in gcdt.Rows)
                            {
                                if (bldr["F_File"] != null && bldr["F_File"].ToString() != "" && configfj != null)
                                {
                                    bldr["File"] = GetFileData(bldr["F_File"].ToString(), configfj.F_ParamValue);
                                }

                                if (bldr["F_LeaveRecordId"] != null && configly != null)
                                {
                                    bldr["FilePath"] = GetLeavePath(bldr["F_LeaveRecordId"].ToString(), config.F_ParamValue);
                                }
                                else if (bldr["F_CallRecordId"] != null && config != null)
                                {
                                    bldr["FilePath"] = GetCallPath(bldr["F_CallRecordId"].ToString(), config.F_ParamValue);
                                }
                            }
                        }
                        return Success("获取成功", gcdt);
                    #endregion
                    case 10:
                        #region 市民评议
                        string pysql = "select * from PublicComment WITH(NOLOCK) where  WorkOrderId ='" + strworkorderid + "' order by CreateTime";
                        var pydt = DbHelperSQL.Query(pysql).Tables[0];
                        return Success("获取成功", pydt);
                    #endregion
                    case 11:
                        #region 监察信息
                        string jcsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_DeptId) as DeptName from T_Bus_RemindRecord WITH(NOLOCK) where F_Type=2 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                        var jcdt = DbHelperSQL.Query(jcsql).Tables[0];
                        if (configfj != null)
                        {
                            jcdt = BindFileData(jcdt, configfj.F_ParamValue);
                        }
                        return Success("获取成功", jcdt);
                    #endregion
                    case 12:
                        #region 批示信息
                        string pssql = "select *,dbo.GetUserName(F_CreateUser) as UserName from T_Bus_SubmitSuper WITH(NOLOCK) where F_State=1 and F_IsDelete=0 and F_Type=1 and F_WorkOrderId ='" + strworkorderid + "' order by F_CreateTime";
                        var psdt = DbHelperSQL.Query(pssql).Tables[0];
                        if (configfj != null)
                        {
                            psdt = BindFileData(psdt, configfj.F_ParamValue);
                        }
                        return Success("获取成功", psdt);
                    #endregion
                    case 13:
                        #region 审核信息
                        string shsql = "select *,[dbo].[GetDeptNames](a.F_MainDeptId) as DeptNames from T_Bus_ToExamine a WITH(NOLOCK) where  F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "' order by F_ID desc";
                        var shdt = DbHelperSQL.Query(shsql).Tables[0];
                        return Success("获取成功", shdt);
                    #endregion
                    
                }
                return Error("获取失败");
            }
            else
            {
                return Error("参数传输失败");
            }
        }

        /// <summary>
        /// 获取草稿信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetDraftInfo()
        {


            string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
            int type = RequestString.GetInt("type", 0);//1交办信息 2反馈信息 3回访信息 4履职界定信息
            if (!string.IsNullOrEmpty(strworkorderid) && type != 0)
            {
                string sql = string.Empty;
                switch (type)
                {
                    case 1:
                        sql = "select top 1 *,dbo.GetDeptName(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName,dbo.GetDictionaryName(F_StandardIDS) as StandardNames from T_Bus_AssignedInfo WITH(NOLOCK)"; break;
                    case 2: sql = "select top 1 * from T_Bus_Feedback WITH(NOLOCK)"; break;
                    case 3: sql = "select top 1 * from T_Bus_VisitResult WITH(NOLOCK)"; break;
                    case 4: sql = "select top 1 * from T_Bus_PerformDuties WITH(NOLOCK)"; break;
                }
                sql += " where F_WorkOrderId='" + strworkorderid + "' and F_State=0 and F_IsDelete=0 and F_CreateUser=" + User.F_UserCode + " order by F_CreateTime desc";
                var dt = DbHelperSQL.Query(sql).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    #region 附件
                    var configfj = configBll.GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();

                    if (!string.IsNullOrEmpty(configfj.F_ParamValue))
                    {
                        BindFileData(dt, configfj.F_ParamValue);
                    }
                    #endregion
                }

                return Success("获取成功", dt);
            }
            else
            {
                return Error("参数传输失败");
            }
        }

        /// <summary>
        /// 获取审核信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetAuditInfo()
        {

            string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
            int type = RequestString.GetInt("type", 0);//1退回信息2延时信息
            if (!string.IsNullOrEmpty(strworkorderid) && type != 0)
            {
                string sql = string.Empty;
                switch (type)
                {

                    case 1: sql = "select top 1 dbo.GetDeptNames(a .F_CreateDeptId) as DepeName , * from T_Bus_Feedback a     WITH(NOLOCK) where F_Type=3 and "; break;
                    case 2: sql = "select top 1 * from T_Bus_DelayTime WITH(NOLOCK) where "; break;
                    case 3: sql = "select top 1 * from T_Bus_PerformDuties WITH(NOLOCK) where "; break;
                }
                if (type != 2)
                {
                    sql += " and F_State=1";
                }
                sql += " F_WorkOrderId='" + strworkorderid + "' and F_IsDelete=0 and F_IsAudit=0 order by F_CreateTime desc";
                var dt = DbHelperSQL.Query(sql).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    #region 附件

                    var configfj = configBll.GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();

                    if (!string.IsNullOrEmpty(configfj.F_ParamValue))
                    {
                        BindFileData(dt, configfj.F_ParamValue);
                    }
                    #endregion
                }

                return Success("获取成功", dt);
            }
            else
            {
                return Error("参数传输失败");
            }
        }

        /// <summary>
        /// 获取所有交办单位
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetAllAssignDept()
        {



            string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
            Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(strworkorderid);
            if (modelT_Bus_WorkOrder != null)
            {
                string ids = string.Empty;
                var Assigns = assignBLL.GetModelList(" F_WorkOrderId='" + strworkorderid + "' and F_IsDelete=0 and F_IsSure in (0,1,2) ");
                foreach (var assign in Assigns)
                {
                    if (string.IsNullOrEmpty(ids))
                    {
                        ids = assign.F_MainDeptId.Value.ToString();
                        if (!string.IsNullOrEmpty(assign.F_OtherDeptIds))
                        {
                            ids += "," + assign.F_OtherDeptIds;
                        }
                    }
                    else
                    {
                        ids += "," + assign.F_MainDeptId.Value.ToString();
                        if (!string.IsNullOrEmpty(assign.F_OtherDeptIds))
                        {
                            ids += "," + assign.F_OtherDeptIds;
                        }
                    }
                }
                if (string.IsNullOrEmpty(ids))
                {
                    ids = "0";
                }
                var dt = new BLL.T_Sys_Department().GetModelList(" F_DeptId in ( " + ids + " ) ");

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

        /// <summary>
        /// 获取二级单位处理信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetSecondDealInfo()
        {


            string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
            if (!string.IsNullOrEmpty(strworkorderid))
            {
                //string sql = "SELECT an.F_Id, an.F_WorkOrderId, an.F_MainDeptId, an.F_OtherDeptIds, an.F_AssignedOpinion, an.F_Remark, an.F_CreateUser, an.F_CreateTime, an.F_IsSure, an.F_State, ";
                //sql += " an.F_SureTime, an.F_IsDelete, an.F_DeleteUser, an.F_DeleteTime, an.F_SureUser, an.F_FeedbackTime, an.F_LimitTime, an.F_IsOverdue, an.F_IsSatisfie, ";
                //sql += " an.F_IsReload, an.F_ReloadUser, an.F_ReloadTime, an.F_File, an.F_IsNotice, an.F_NoticeUser, an.F_NoticeTime,  fn.F_AssignedId, ";
                //sql += " fn.F_Result, fn.F_CreateDeptId, fn.F_IsFeedEnd, fn.F_IsAudit, fn.F_AuditUser, fn.F_AuditTime, fn.F_AuditReason ";
                //sql += " FROM T_Bus_AssignedInfo_Next AS an LEFT OUTER JOIN T_Bus_Feedback_Next AS fn ON an.F_Id = fn.F_AssignedId AND an.F_IsDelete = 0 AND fn.F_IsDelete = 0";
                //sql += " where an.F_WorkOrderId='" + strworkorderid + "' order by F_CreateTime desc";
                //var dt = DbHelperSQL.Query(sql).Tables[0];

                string sql = "select top 1 * from T_Bus_AssignedInfo_Next WITH(NOLOCK) where F_WorkOrderId='" + strworkorderid + "' and F_IsDelete = 0 order by F_CreateTime desc";
                string sql1 = "select * from T_Bus_Feedback_Next WITH(NOLOCK) where  F_WorkOrderId='" + strworkorderid + "' and F_IsDelete = 0 ";

                var bldt = DbHelperSQL.Query(sql1).Tables[0];
                var configfj = configBll.GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
                if (configfj != null)
                {
                    bldt = BindFileData(bldt, configfj.F_ParamValue);
                }

                var obj = new
                {
                    pdinfo = DbHelperSQL.Query(sql).Tables[0],
                    fkinfo = bldt
                };

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

        /// <summary>
        /// 获取二级单位最新处理信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetNewSecondDealInfo()
        {


            string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
            if (!string.IsNullOrEmpty(strworkorderid))
            {
                string sql = "select top 1 * from T_Bus_Feedback_Next WITH(NOLOCK) where  F_WorkOrderId='" + strworkorderid + "' and F_IsDelete = 0 order by F_CreateTime desc";

                var bldt = DbHelperSQL.Query(sql).Tables[0];
                var configfj = configBll.GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
                if (configfj != null)
                {
                    bldt = BindFileData(bldt, configfj.F_ParamValue);
                }

                return Success("获取成功", bldt);
            }
            else
            {
                return Error("参数传输失败");
            }
        }

        /// <summary>
        /// 修改工单内容和处理结果
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult EditResult()
        {


            if (User.F_RoleCode == "ZXBZ" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "GNZY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                string result = RequestString.GetFormString("result");
                string content = RequestString.GetFormString("content");
                string comContent = RequestString.GetFormString("comContent");
                string additionalReply = RequestString.GetFormString("additionalReply");
               
                if (modelT_Bus_WorkOrder != null)
                {
                    Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                  
                    string userinfo = User.depname + "(" + User.F_UserCode + ")";
                    if (!string.IsNullOrEmpty(content))
                    {
                        string message = "";
                        if (!string.IsNullOrEmpty(modelT_Bus_WorkOrder.F_Content))
                            message = modelT_Bus_WorkOrder.F_Content;
                        else
                            message = modelT_Bus_WorkOrder.F_ComTitle;
                        if (content != message)
                        {
                           // modelT_Bus_WorkOrder.F_Content = content;
                            keyValuePairs.Add("F_Content", content);
                            Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                            oper.F_WorkOrderId = workorderid;
                            oper.F_AssignedId = 0;
                            oper.F_State = modelT_Bus_WorkOrder.F_WorkState;
                            oper.F_Message = userinfo + " 修改了工单内容，原内容：" + message;
                            oper.F_CreateUser = User.F_UserCode;
                            oper.F_CreateTime = DateTime.Now;
                            oper.F_IsDelete = 0;
                            operBLL.Add(oper);
                        }

                    }
                    if (!string.IsNullOrEmpty(comContent))
                    {
                        string message = "";
                        message = modelT_Bus_WorkOrder.F_ComContent;
                        if (comContent != message)
                        {
                            // modelT_Bus_WorkOrder.F_Content = content;
                            keyValuePairs.Add("F_ComContent", comContent);
                            Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                            oper.F_WorkOrderId = workorderid;
                            oper.F_AssignedId = 0;
                            oper.F_State = modelT_Bus_WorkOrder.F_WorkState;
                            oper.F_Message = userinfo + " 修改了来电内容，原内容：" + message;
                            oper.F_CreateUser = User.F_UserCode;
                            oper.F_CreateTime = DateTime.Now;
                            oper.F_IsDelete = 0;
                            operBLL.Add(oper);
                        }

                    }
                    if (!string.IsNullOrEmpty(additionalReply))
                    {
                        string message = "";
                        message = modelT_Bus_WorkOrder.F_AdditionalReply;
                        if (additionalReply != message)
                        {
                            // modelT_Bus_WorkOrder.F_Content = content;
                            keyValuePairs.Add("F_AdditionalReply", additionalReply);
                            Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                            oper.F_WorkOrderId = workorderid;
                            oper.F_AssignedId = 0;
                            oper.F_State = modelT_Bus_WorkOrder.F_WorkState;
                            oper.F_Message = userinfo + " 修改了追加回复内容，原内容：" + message;
                            oper.F_CreateUser = User.F_UserCode;
                            oper.F_CreateTime = DateTime.Now;
                            oper.F_IsDelete = 0;
                            operBLL.Add(oper);
                        }

                    }
                    if (!string.IsNullOrEmpty(result))
                    {
                        string message = "";
                        message = modelT_Bus_WorkOrder.F_Result;
                        if (result != message)
                        {
                           // modelT_Bus_WorkOrder.F_Result = result;
                            keyValuePairs.Add("F_Result", result);
                            Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                            oper.F_WorkOrderId = workorderid;
                            oper.F_AssignedId = 0;
                            oper.F_State = modelT_Bus_WorkOrder.F_WorkState;
                            oper.F_Message = userinfo + " 修改了办理结果，原结果：" + message;
                            oper.F_CreateUser = User.F_UserCode;
                            oper.F_CreateTime = DateTime.Now;
                            oper.F_IsDelete = 0;
                            operBLL.Add(oper);
                        }
                    }
                    if (keyValuePairs.Count >0)
                    {
                        bool n = workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs);
                        if (n)
                            return Success("操作成功");
                        else
                            return Error("修改失败");
                    }
                    else
                    {
                        return Success("操作成功");
                    }
                   
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }


        /// <summary>
        /// 修改下级单位处理内容
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult EditDealWorkOrder()
        {


            if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                string result = RequestString.GetFormString("result");
                string flies = RequestString.GetFormString("flies");
                var modelT_Bus_Feedback_Nexts = new BLL.T_Bus_Feedback_Next()
                    .GetModelList("F_WorkOrderId='" + workorderid + "' and F_IsDelete = 0 order by F_CreateTime desc");
                if (modelT_Bus_Feedback_Nexts != null && modelT_Bus_WorkOrder != null && modelT_Bus_Feedback_Nexts.Count > 0)
                {
                    string message = modelT_Bus_Feedback_Nexts[0].F_Result;
                    modelT_Bus_Feedback_Nexts[0].F_Result = result;//反馈内容
                    modelT_Bus_Feedback_Nexts[0].F_File = flies;
                    bool n = new BLL.T_Bus_Feedback_Next().Update(modelT_Bus_Feedback_Nexts[0]);
                    Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                    oper.F_WorkOrderId = workorderid;
                    oper.F_AssignedId = modelT_Bus_Feedback_Nexts[0].F_Id;
                    oper.F_State = modelT_Bus_WorkOrder.F_WorkState;

                    string userinfo = User.depname + "(" + User.F_UserCode + ")";
                    oper.F_Message = userinfo + " 修改了下级单位办理内容，原内容：" + message;
                    oper.F_CreateUser = User.F_UserCode;
                    oper.F_CreateTime = DateTime.Now;
                    oper.F_IsDelete = 0;
                    operBLL.Add(oper);
                    return Success("操作成功");
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }

        /// <summary>
        /// 查看回访信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetVisitInfo()
        {



            string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));

            if (!string.IsNullOrEmpty(strworkorderid))
            {
                string sqlvisit = "select * from T_Bus_VisitResult WITH(NOLOCK) where F_WorkOrderId='" + strworkorderid + "' and F_State=1 and F_IsDelete=0 and F_IsSatisfie=0 order by F_CreateTime";
                string sqlassgin = "select * from T_Bus_AssignedInfo WITH(NOLOCK) where F_WorkOrderId ='" + strworkorderid + "' and F_State=1 and F_IsDelete=0 order by F_CreateTime";

                var dtvisit = DbHelperSQL.Query(sqlvisit).Tables[0];
                var dtassgin = DbHelperSQL.Query(sqlassgin).Tables[0];
                var config = configBll.GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
                dtvisit.Columns.Add("FilePath", typeof(string));
                dtvisit.Columns.Add("IsShowCheck", typeof(string));
                if (dtvisit.Rows.Count > 0)
                {
                    foreach (DataRow bldr in dtvisit.Rows)
                    {
                        #region 是否可勾选
                        var IsShowCheck = 0;
                        var drass = dtassgin.Select(" F_ID='" + bldr["F_AssignedId"].ToString() + "'");
                        if (drass.Length > 0)
                        {
                            var ass = (from DataRow dr in drass select dr.Field<int>("F_MainDeptId")).FirstOrDefault();
                            if (ass > 0)
                            {
                                if (ass == User.F_DeptId)
                                    IsShowCheck = 1;
                            }
                        }
                        bldr["IsShowCheck"] = IsShowCheck;
                        #endregion
                        #region 录音
                        if (bldr["F_CallRecordId"] != null && config != null)
                        {
                            bldr["FilePath"] = GetCallPath(bldr["F_CallRecordId"].ToString(), config.F_ParamValue);
                        }
                        #endregion
                    }

                }

                return Success("获取成功", dtvisit);
            }
            else
            {
                return Error("参数传输失败");
            }
        }


        

        #endregion

        #region 新增工单
        /// <summary>
        /// 上传附件
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult UploadFile()
        {
            #region 单个上传 no use
            //string path = string.Empty;
            //HttpPostedFile _upfile = RequestString.GetFile("upFile");
            //if (_upfile != null)
            //{
            //    //byte[] buffer = new Byte[(int)_upfile.InputStream.Length]; //声明文件长度的二进制类型
            //    //_upfile.InputStream.Read(buffer, 0, buffer.Length); //将文件转成二进制
            //    string name = string.Empty;
            //    FileUp fu = new FileUp();
            //    var model = configBll.GetModelList(" F_ParamCode='FilePath' ").FirstOrDefault();
            //    if (model != null)
            //    {
            //        name = fu.Upload(_upfile, model.F_ParamValue);

            //        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 = name;//附件名称
            //        model_T_Sys_Accessories.F_FileType = System.IO.Path.GetExtension(_upfile.FileName);//附件类型
            //        model_T_Sys_Accessories.F_FileUrl = model.F_ParamValue + name;//附件地址
            //        model_T_Sys_Accessories.F_Size = _upfile.ContentLength;
            //        model_T_Sys_Accessories.F_UserCode = User.F_UserCode;//上传人  
            //        int p_fuId = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);

            //        return Success("成功", model_T_Sys_Accessories);
            //    }
            //    else
            //    {
            //        return Error("上传失败");
            //    }

            //}
            //else
            //{
            //    return Error("请选择要上传的文件");
            //} 
            #endregion

            #region 多个上传
            HttpFileCollection files = RequestString.GetFiles();
            if (files.Count > 0)
            {
                List<Model.T_Sys_Accessories> acs = new List<Model.T_Sys_Accessories>();
                string path = "/Upload/Files/" + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd") + "/";
                for (int i = 0; i < files.Count; i++)
                {
                    HttpPostedFile file = files[i];
                    FileUp fu = new FileUp();

                    string name = fu.Upload(file, path);

                    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 = name;//附件名称
                    model_T_Sys_Accessories.F_FileType = System.IO.Path.GetExtension(file.FileName);//附件类型
                    model_T_Sys_Accessories.F_FileUrl = path + name;//附件地址
                    model_T_Sys_Accessories.F_Size = file.ContentLength;
                    model_T_Sys_Accessories.F_UserCode = User.F_UserCode;//上传人  
                    int id = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
                    model_T_Sys_Accessories.F_FileId = id;
                    acs.Add(model_T_Sys_Accessories);
                }

                return Success("成功", acs);
            }
            else
            {
                return Error("请选择要上传的文件");
            }
            #endregion

        }
        /// <summary>
        /// 添加工单信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult AddWorkOrder()
        {
            if (User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "ZXBZ"
                || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY"
                || User.F_RoleCode == "ZJZY" || User.F_RoleCode == "DBZY" || User.F_RoleCode == "GNZY"
                || User.F_RoleCode == "11" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG"
                || User.F_RoleCode == "DFZF" || User.F_RoleCode == "MTDD") //增加新闻媒体(编号11)的添加工单权限 
            {

                int source = RequestString.GetInt("source", 0);
                string cusname = RequestString.GetFormString("cusname");
                string cussex = RequestString.GetFormString("cussex");
                string cusphone = RequestString.GetFormString("cusphone");
                string cusaddress = RequestString.GetFormString("cusaddress");
                string email = RequestString.GetFormString("email");
                string zipcode = RequestString.GetFormString("zipcode");
                string conname = RequestString.GetFormString("conname");
                string conphone = RequestString.GetFormString("conphone");
                string title = RequestString.GetFormString("title");
                string content = RequestString.GetFormString("content");
                string files = RequestString.GetFormString("files");
                int sourcearea = RequestString.GetInt("sourcearea", 0);
                string sourceaddress = RequestString.GetFormString("sourceaddress");
                int isresult = RequestString.GetInt("isresult", 0);
                string result = RequestString.GetFormString("result");
                string keys = RequestString.GetFormString("keys");
                string splituser = RequestString.GetFormString("splituser");
                int type = RequestString.GetInt("type", 0);
                int bigtype = RequestString.GetInt("bigtype", 0);
                int smalltype = RequestString.GetInt("smalltype", 0);
                int isprotect = RequestString.GetInt("isprotect", 0);
                int level = RequestString.GetInt("level", 0);
                int issubmit = RequestString.GetInt("issubmit", 0);
                string callid = RequestString.GetFormString("callid");

                string CallRecordsId = RequestString.GetFormString("CallRecordsId");
                string longitude = RequestString.GetFormString("longitude");//经度
                string latitude = RequestString.GetFormString("latitude");//纬度
                int business = RequestString.GetInt("business", 0); ;//
                int ispd = RequestString.GetInt("ispd", 0); ;//是否自动派单
                int visittype = RequestString.GetInt("visittype", 0); ;//回访方式
                int LeaveRecordId = RequestString.GetInt("LeaveRecordId", 0);
                int  township = RequestString.GetInt("township", 0);
                int village = RequestString.GetInt("village", 0);
                string file = RequestString.GetFormString("file");
               
                int smsid = RequestString.GetInt("smsid", 0);
               
                int deptid = 0;
                var modeldept = new Model.T_Sys_Department();
                var premodeldept = new Model.T_Sys_Department();
                if (ispd > 0)
                {
                    if (string.IsNullOrEmpty(keys))
                        return Error("自动派单失败,请选择反映类别!");

                    try
                    {
                        var model = new BLL.T_Sys_DictionaryValue().GetModel
                             (int.Parse(keys));
                        if (model != null)
                        {
                            if (model.F_Deptid != null)
                                deptid = (int)model.F_Deptid;
                            else
                                return Error("当前反映类别暂未设置相应派单部门,自动派单失败");
                        }
                        else
                            return Error("自动派单失败,请选择反映类别.");
                    }
                    catch
                    {
                        return Error("自动派单失败,请选择反映类别");
                    }
                    modeldept = new BLL.T_Sys_Department().GetModel(deptid);
                    if (modeldept == null)
                        return Error("自动派单失败,派单单位不存在");

                    if (modeldept.F_IsDept == 2)
                    {
                        if (modeldept.F_PartentId > 0)
                        {
                            premodeldept = department((int)modeldept.F_PartentId);
                            if (premodeldept == null)
                                return Error("该单位没有上级单位，派单失败");
                        }
                        else
                        {
                            return Error("该单位没有上级单位，派单失败");
                        }
                    }
                    else
                    {
                        premodeldept = modeldept;
                    }
                }
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = new Model.T_Bus_WorkOrder();

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

                    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(source, sourcearea, creattime, endtime);
                    modelT_Bus_WorkOrder.F_InfoSource = source;//信息来源
                   
                    modelT_Bus_WorkOrder.F_InfoType = type;//信息类别
                    modelT_Bus_WorkOrder.F_InfoConBigType = bigtype;//内容大类
                    modelT_Bus_WorkOrder.F_InfoConSmallType = smalltype;//内容小类
                    modelT_Bus_WorkOrder.F_SourceArea = sourcearea;//反映地域
                    modelT_Bus_WorkOrder.F_SourceAddress = sourceaddress;//事发地址
                    modelT_Bus_WorkOrder.F_CusName = cusname;//投诉人姓名

                   
                    modelT_Bus_WorkOrder.F_CusSex = cussex;//性别
                    modelT_Bus_WorkOrder.F_CusPhone = cusphone;//来电号码
                    modelT_Bus_WorkOrder.F_CusAddress = cusaddress;//地址
                    modelT_Bus_WorkOrder.F_ZipCode = zipcode;//邮编
                    modelT_Bus_WorkOrder.F_ConName = conname;//联系人姓名
                    modelT_Bus_WorkOrder.F_ConPhone = conphone;//联系人电话
                    modelT_Bus_WorkOrder.F_Email = email;//E-mail
                    modelT_Bus_WorkOrder.F_ComTitle = title;//标题
                    modelT_Bus_WorkOrder.F_ComContent = content;//情况摘要（投诉内容）
                    modelT_Bus_WorkOrder.F_File = files;//附件
                    modelT_Bus_WorkOrder.F_IsProtect = isprotect;//保密方式0否1是
                    modelT_Bus_WorkOrder.F_Key = keys;
                    modelT_Bus_WorkOrder.F_SplitUser = splituser;
                    modelT_Bus_WorkOrder.F_Level = level;
                    modelT_Bus_WorkOrder.F_VisitType = visittype;
                    modelT_Bus_WorkOrder.F_Township = township;
                    modelT_Bus_WorkOrder.F_Village = village;
                 
                    if (LeaveRecordId>0)
                    {
                        var ld = new BLL.T_Call_LeaveRecord().GetModel (LeaveRecordId);
                        if (ld != null)
                        {
                           
                            ld .F_Status  = 1;
                            ld.F_DealTime = DateTime.Now;
                            ld.F_UserId = User.F_UserId;
                            ld.F_UserCode = User.F_UserCode;
                            ld.F_UserName = User.F_UserName;
                            new BLL.T_Call_LeaveRecord().Update(ld);
                            modelT_Bus_WorkOrder.F_LeaveRecordId = LeaveRecordId;
                        }
                    }
                    Task.Run(() =>
                    {
                        if (smsid > 0)
                        {
                            var sms = new BLL.T_SMS_RecvSMS().GetModel(smsid);
                            if (sms!=null )
                            {
                                sms.F_Name = modelT_Bus_WorkOrder.F_WorkOrderId;
                                new BLL.T_SMS_RecvSMS().Update(sms);
                            }
                        }
                    });
              
                    modelT_Bus_WorkOrder.F_Latitude = latitude != "" ? decimal.Parse(latitude) : 0;//纬度
                    modelT_Bus_WorkOrder.F_Longitude = longitude != "" ? decimal.Parse(longitude) : 0;//经度

                    // modelT_Bus_WorkOrder.F_IsOpen = isopen;
                    //是否直办（即时答复）0:，否1： 是         
                    modelT_Bus_WorkOrder.F_IsResult = isresult;
                    modelT_Bus_WorkOrder.F_Result = result;//处理结果

                    modelT_Bus_WorkOrder.F_CreateUser = User.F_UserCode;//登记人工号
                    modelT_Bus_WorkOrder.F_CreateTime = DateTime.Now;//登记时间
                    modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.neworder;// 0;//工单状态0登记中
                    modelT_Bus_WorkOrder.F_IsClosed = 0;//工单是否关闭
                    modelT_Bus_WorkOrder.F_IsOverdue = 0;//是否逾期(0:否，1：是)
                    modelT_Bus_WorkOrder.F_IsDelete = 0;//是否删除(0:否，1：是)
                    modelT_Bus_WorkOrder.F_ToBereply = 0;
                   
                  
                    //如果选择即刻答复：是，即为直办，工单结束
                    if (isresult == 1)
                    {
                        modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.finish;// 9;//已结案
                        modelT_Bus_WorkOrder.F_DealDeptId = User.F_DeptId;
                        modelT_Bus_WorkOrder.F_DealUser = User.F_UserCode;
                        modelT_Bus_WorkOrder.F_DealTime = DateTime.Now;
                        modelT_Bus_WorkOrder.F_IsClosed = 1;
                        modelT_Bus_WorkOrder.F_CloseUser = User.F_UserCode;
                        modelT_Bus_WorkOrder.F_CloseTime = DateTime.Now;

                        if (!string.IsNullOrEmpty(file) )
                        {
                            Model.T_Bus_Feedback modelT_Bus_Feedback = new T_Bus_Feedback();
                            modelT_Bus_Feedback.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;//工单编号
                         
                            modelT_Bus_Feedback.F_DealUser = User.F_UserCode;
                            modelT_Bus_Feedback.F_Result = result;//反馈内容
                            #region 20200114新增字段 zhengbingbing
                         
                            modelT_Bus_Feedback.F_IsProtect = modelT_Bus_WorkOrder.F_IsProtect;//是否保密(0:否1:是)
                          
                            DateTime contime = DateTime.Now;
                            modelT_Bus_Feedback.F_IsProResult = 1;
                            #endregion
                            modelT_Bus_Feedback.F_File = file;
                            modelT_Bus_Feedback.F_IsAudit = 0;
                            modelT_Bus_Feedback.F_IsDelete = 0;
                            modelT_Bus_Feedback.F_CreateUser = User.F_UserCode;//办理人
                            modelT_Bus_Feedback.F_CreateTime = DateTime.Now;//办理时间
                            modelT_Bus_Feedback.F_CreateDeptId = User.F_DeptId;//办理部门
                            modelT_Bus_Feedback.F_IsFeedEnd = 1;
                            modelT_Bus_Feedback.F_State = 1;
                            modelT_Bus_Feedback.F_Type = 1;

                            new BLL.T_Bus_Feedback().Add(modelT_Bus_Feedback);
                        }
                    }
                    else if (issubmit == 1)
                    {
                        modelT_Bus_WorkOrder.F_SubmitTime = DateTime.Now;
                        modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.submit;// 
                    }
                    #region
                    #endregion

                    if (!string.IsNullOrEmpty(CallRecordsId ))
                    {
                        var rd = new BLL.T_Call_CallRecords().GetModelByRecordId (CallRecordsId);
                        if (rd != null)
                        {
                            modelT_Bus_WorkOrder.F_CallId = rd.CallId ;
                            rd.WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                            rd.IsExitWorkOrder = true;
                            new BLL.T_Call_CallRecords().Update(rd);
                            modelT_Bus_WorkOrder.F_CallRecordId = rd.CallRecordsId;
                        }
                    }
                   else  if (!string.IsNullOrEmpty(callid))
                    {
                        modelT_Bus_WorkOrder.F_CallId = callid;
                        var rd = new BLL.T_Call_CallRecords().GetModelByCallId(callid);
                        if (rd != null)
                        {
                            rd.WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                            rd.IsExitWorkOrder = true;
                            new BLL.T_Call_CallRecords().Update(rd);

                            modelT_Bus_WorkOrder.F_CallRecordId = rd.CallRecordsId;
                        }
                    }
                   

                    modelT_Bus_WorkOrder.F_Id = workorderBLL.Add(modelT_Bus_WorkOrder);

                    #endregion

                    trans.Complete();
                }
                if (modelT_Bus_WorkOrder.F_Id <= 0)
                    return Error("添加失败");
                else
                {
                    string userinfo = User.depname + "(" + User.F_UserCode + ")";
                    string message = "";
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.neworder || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.audit)
                    {
                        message = userinfo + " 登记了工单，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId;
                    }
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.submit)
                    {
                        message = userinfo + " 登记并提交了工单，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId;
                    }
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.finish)
                    {
                        message = userinfo + " 登记并结案了工单，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId;
                    }
                    var curuser = User;
                    Task.Run(() =>
                    {
                        #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;
                        oper.F_CallRecordId = modelT_Bus_WorkOrder.F_CallRecordId;
                        oper.F_File = modelT_Bus_WorkOrder.F_File;
                        oper.F_Message = message;
                        oper.F_CreateUser = curuser.F_UserCode;
                        oper.F_CreateTime = DateTime.Now;
                        oper.F_IsDelete = 0;
                        operBLL.Add(oper);
                     
                        if (modelT_Bus_WorkOrder.F_WorkState != (int)EnumWorkState.finish)
                        {
                          
                            string count = "您反映的事项已受理并转交相关部门处理，感谢您拨打市长热线！";
                            string msg = "";
                            //  bool n = SMSController.AddSmS(0, msg, count, modelT_Bus_WorkOrder.F_CusPhone, "197387", "", modelT_Bus_WorkOrder.F_WorkOrderId);
                            string phone = modelT_Bus_WorkOrder.F_CusPhone;
                            if (phone.Length > 11)
                                phone = phone.Substring(1, 11);
                            string n = SmsNewController.AddSmS(0, count, phone, "681240256766803968", "", modelT_Bus_WorkOrder.F_WorkOrderId);

                        }
                        #endregion
                    }).ContinueWith(p => {
                        System.Diagnostics.Debug.WriteLine(DateTime.Now);
                    });
                    Task.Run(() =>
                    {
                        #region 插入推送消息

                        //推送消息表
                        if (modelT_Bus_WorkOrder.F_WorkState != (int)EnumWorkState.neworder && modelT_Bus_WorkOrder.F_WorkState != (int)EnumWorkState.audit)
                        {

                            var role = new BLL.T_Sys_RoleInfo().GetModelList(" (F_RoleCode='ZXLD' or F_RoleCode='ZXLDGLYGLY' or F_RoleCode='MTDD')  ").Select(p => p.F_RoleId);
                            var users = userBLL.GetModelList(" F_RoleId in (" + string.Join(",", role) + ")  ");

                            foreach (var u in users)
                            {
                                msg.AddInternalMessagesInfo("工单消息", message, u.F_UserCode, curuser.F_UserCode, (int)EnumSmsType.workorder);
                            }
                        }
                        #endregion
                    }).ContinueWith(p => {
                        System.Diagnostics.Debug.WriteLine(DateTime.Now);
                    });
                    Task.Run(async () =>
                    {
                        #region 自动派单
                        if (ispd > 0)
                        {
                            //时限
                            string resdatetime = "";
                            string resdate = DateTime.Now.Date.ToString("yyyy-MM-dd");
                            DataTable dt = DbHelperSQL.Query("select top " + 7 + " F_OffDate from  T_Sys_WorkOFFDays  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 = modelT_Bus_WorkOrder.F_WorkOrderId;
                            modelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(resdatetime);
                            modelT_Bus_AssignedInfo.F_MainDeptId = premodeldept.F_DeptId;
                            modelT_Bus_AssignedInfo.F_OtherDeptIds = "";//协办单位id
                            modelT_Bus_AssignedInfo.F_AssignedOpinion = "自动派单";//交办意见
                            modelT_Bus_AssignedInfo.F_State = 1;//0草稿  1正式
                            modelT_Bus_AssignedInfo.F_CreateUser = curuser.F_UserCode;
                            modelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                            modelT_Bus_AssignedInfo.F_IsDelete = 0;
                            modelT_Bus_AssignedInfo.F_IsOverdue = 0;
                            modelT_Bus_AssignedInfo.F_IsSure = 0;
                            modelT_Bus_AssignedInfo.F_IsReload = 0;
                            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_LimitTime", Convert.ToDateTime(resdatetime));
                            // modelT_Bus_WorkOrder.F_LimitTime = Convert.ToDateTime(resdatetime);
                            keyValuePairs.Add("F_MainDeptId", premodeldept.F_DeptId);
                            //modelT_Bus_WorkOrder.F_MainDeptId = premodeldept.F_DeptId;
                            keyValuePairs.Add("F_OtherDeptIds", "");
                            // modelT_Bus_WorkOrder.F_OtherDeptIds = ""
                            keyValuePairs.Add("F_AssignUser", curuser.F_UserCode);
                            // modelT_Bus_WorkOrder.F_AssignUser = curuser.F_UserCode;
                            keyValuePairs.Add("F_AssignTime", DateTime.Now);
                           // modelT_Bus_WorkOrder.F_AssignTime = DateTime.Now;
                            workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);


                            var msgss = userinfo + " 交办了工单，主办单位：" + premodeldept.F_DeptName;
                            addoptlog(modelT_Bus_WorkOrder.F_WorkOrderId, modelT_Bus_WorkOrder.F_WorkState, modelT_Bus_AssignedInfo.F_Id, msgss, curuser.F_UserCode);

                            if (modeldept.F_IsDept == 2)
                            {
                                await SplitOrderNew(modelT_Bus_WorkOrder, modeldept, Convert.ToDateTime(resdatetime), modelT_Bus_AssignedInfo, "自动派单", curuser).ContinueWith(p =>
                                {

                                });
                            }
                            else
                            {

                                Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                                keyValuePairs1.Add("F_WorkState", 2);
                                modelT_Bus_WorkOrder.F_WorkState = 2;
                                new BLL.T_Bus_WorkOrder().UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs1);
                                await Task.Run(() =>
                                {
                                    //addoptlog(modelT_Bus_WorkOrder.F_WorkOrderId, modelT_Bus_WorkOrder.F_WorkState, modelT_Bus_AssignedInfo.F_Id, msgss, curuser.F_UserCode);
                                });
                            }


                            await Task.Run(() => {
                                //推送消息表
                                var users = userBLL.GetModelList(" F_DeptId='" + premodeldept.F_DeptId + "' ");

                                foreach (var u in users)
                                {
                                    msg.AddInternalMessagesInfo("工单消息", msgss + "，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId, u.F_UserCode, curuser.F_UserCode, (int)EnumSmsType.workorder);
                                    if(u .F_RoleCode =="WLDW" && u.F_IsSms != null && u .F_IsSms ==1)
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        string count = "你有新工单：" + modelT_Bus_WorkOrder.F_WorkOrderId + "，请及时查收处理。";
                                       // string mag = modelT_Bus_WorkOrder.F_WorkOrderId;
                                      //  bool n = SMSController.AddSmS(0, mag, count, u.F_Mobile, "153305", "");
                                        string mag = "[\"" + modelT_Bus_WorkOrder.F_WorkOrderId + "\"]";
                                        string v = SmsNewController.AddSmS(0, count, u.F_Mobile, "681240888655478784", mag,
                                       modelT_Bus_WorkOrder.F_WorkOrderId);
                                    }
                                  
                                }
                            });
                        }
                        #endregion
                    }).ContinueWith(p => {
                        System.Diagnostics.Debug.WriteLine(DateTime.Now);
                    });
                   
                   
                }
                return Success("操作成功");

            }
            else
            {
                return Error("权限不足");
            }
        }
      



        /// <summary>
        /// 添加工单信息
        /// </summary>
        /// <returns></returns>
        public string AddWorkOrderBySource(int source, string cusname, string cussex, string cusphone, string cusaddress, string email,
            string zipcode, string conname, string conphone, string title, string content, int sourcearea, string sourceaddress,
            string keys, string splituser, int type, int bigtype, int smalltype, int isprotect, int level, string files = null)
        {
            string workorderid = string.Empty;

            using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
            {
                #region 保存工单信息
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = new Model.T_Bus_WorkOrder();
                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(source, sourcearea
                    , creattime, endtime);

                modelT_Bus_WorkOrder.F_InfoSource = source;//信息来源

                modelT_Bus_WorkOrder.F_InfoType = type;//信息类别
                modelT_Bus_WorkOrder.F_InfoConBigType = bigtype;//内容大类
                modelT_Bus_WorkOrder.F_InfoConSmallType = smalltype;//内容小类
                modelT_Bus_WorkOrder.F_SourceArea = sourcearea;//反映地域
                modelT_Bus_WorkOrder.F_SourceAddress = sourceaddress;//事发地址

                modelT_Bus_WorkOrder.F_CusName = cusname;//投诉人姓名
                modelT_Bus_WorkOrder.F_CusSex = cussex;//性别
                modelT_Bus_WorkOrder.F_CusPhone = cusphone;//来电号码
                modelT_Bus_WorkOrder.F_CusAddress = cusaddress;//地址
                modelT_Bus_WorkOrder.F_ZipCode = zipcode;//邮编
                modelT_Bus_WorkOrder.F_ConName = conname;//联系人姓名
                modelT_Bus_WorkOrder.F_ConPhone = conphone;//联系人电话
                modelT_Bus_WorkOrder.F_Email = email;//E-mail

                modelT_Bus_WorkOrder.F_ComTitle = title;//标题
                modelT_Bus_WorkOrder.F_ComContent = content;//情况摘要（投诉内容）
                modelT_Bus_WorkOrder.F_File = files;//附件
                modelT_Bus_WorkOrder.F_IsProtect = isprotect;//保密方式0否1是

                modelT_Bus_WorkOrder.F_Key = keys;
                modelT_Bus_WorkOrder.F_SplitUser = splituser;
                modelT_Bus_WorkOrder.F_Level = level;

                //modelT_Bus_WorkOrder.F_Latitude = latitude != "" ? decimal.Parse(latitude) : 0;//纬度
                //modelT_Bus_WorkOrder.F_Longitude = longitude != "" ? decimal.Parse(longitude) : 0;//经度

                //modelT_Bus_WorkOrder.F_CreateUser = User.F_UserCode;//登记人工号
                modelT_Bus_WorkOrder.F_CreateTime = DateTime.Now;//登记时间
                modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.neworder;// 0;//工单状态0登记中
                //modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.audit;//审核环节去掉 20190715
                modelT_Bus_WorkOrder.F_IsClosed = 0;//工单是否关闭
                modelT_Bus_WorkOrder.F_IsOverdue = 0;//是否逾期(0:否，1：是)
                modelT_Bus_WorkOrder.F_IsDelete = 1;//是否删除(0:否，1：是)
                modelT_Bus_WorkOrder.F_IsEnabled = 0;//是否处理

                workorderBLL.Add(modelT_Bus_WorkOrder);
                workorderid = modelT_Bus_WorkOrder.F_WorkOrderId;
                #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 = "";
                var sourceinfo = new BLL.T_Sys_DictionaryValue().GetModel(source);
                if (sourceinfo != null) { userinfo = "由 " + sourceinfo.F_Value; }
                if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.neworder || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.audit)//0)
                {
                    oper.F_Message = userinfo + " 登记了工单，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId;
                }

                //oper.F_CreateUser = User.F_UserCode;
                oper.F_CreateTime = DateTime.Now;
                oper.F_IsDelete = 0;

                operBLL.Add(oper);
                #endregion

                trans.Complete();
            }

            return workorderid;
        }

        /// <summary>
        /// 添加工单信息留言
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult AddWorkOrderByLY()
        {
            if (User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "ZXBZ" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {

                int source = RequestString.GetInt("source", 0);

                string cusname = RequestString.GetFormString("cusname");
                string cussex = RequestString.GetFormString("cussex");
                string cusphone = RequestString.GetFormString("cusphone");
                string cusaddress = RequestString.GetFormString("cusaddress");
                string email = RequestString.GetFormString("email");
                string zipcode = RequestString.GetFormString("zipcode");
                string conname = RequestString.GetFormString("conname");
                string conphone = RequestString.GetFormString("conphone");

                string title = RequestString.GetFormString("title");
                string content = RequestString.GetFormString("content");
                string files = RequestString.GetFormString("files");
                int sourcearea = RequestString.GetInt("sourcearea", 0);
                string sourceaddress = RequestString.GetFormString("sourceaddress");

                int isresult = RequestString.GetInt("isresult", 0);
                string result = RequestString.GetFormString("result");

                string keys = RequestString.GetFormString("keys");
                string splituser = RequestString.GetFormString("splituser");

                int type = RequestString.GetInt("type", 0);
                int bigtype = RequestString.GetInt("bigtype", 0);
                int smalltype = RequestString.GetInt("smalltype", 0);

                int isprotect = RequestString.GetInt("isprotect", 0);
                int level = RequestString.GetInt("level", 0);
                int issubmit = RequestString.GetInt("issubmit", 0);

                int lyid = RequestString.GetInt("lyid", 0);


                using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                {
                    #region 保存工单信息
                    Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = new Model.T_Bus_WorkOrder();
                    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(source, sourcearea, creattime, endtime);

                    modelT_Bus_WorkOrder.F_InfoSource = source;//信息来源

                    modelT_Bus_WorkOrder.F_InfoType = type;//信息类别
                    modelT_Bus_WorkOrder.F_InfoConBigType = bigtype;//内容大类
                    modelT_Bus_WorkOrder.F_InfoConSmallType = smalltype;//内容小类
                    modelT_Bus_WorkOrder.F_SourceArea = sourcearea;//反映地域
                    modelT_Bus_WorkOrder.F_SourceAddress = sourceaddress;//事发地址

                    modelT_Bus_WorkOrder.F_CusName = cusname;//投诉人姓名
                    modelT_Bus_WorkOrder.F_CusSex = cussex;//性别
                    modelT_Bus_WorkOrder.F_CusPhone = cusphone;//来电号码
                    modelT_Bus_WorkOrder.F_CusAddress = cusaddress;//地址
                    modelT_Bus_WorkOrder.F_ZipCode = zipcode;//邮编
                    modelT_Bus_WorkOrder.F_ConName = conname;//联系人姓名
                    modelT_Bus_WorkOrder.F_ConPhone = conphone;//联系人电话
                    modelT_Bus_WorkOrder.F_Email = email;//E-mail

                    modelT_Bus_WorkOrder.F_ComTitle = title;//标题
                    modelT_Bus_WorkOrder.F_ComContent = content;//情况摘要（投诉内容）
                    modelT_Bus_WorkOrder.F_File = files;//附件
                    modelT_Bus_WorkOrder.F_IsProtect = isprotect;//保密方式0否1是

                    modelT_Bus_WorkOrder.F_Key = keys;
                    modelT_Bus_WorkOrder.F_Level = level;

                    //是否直办（即时答复）0:，否1： 是         
                    modelT_Bus_WorkOrder.F_IsResult = isresult;
                    modelT_Bus_WorkOrder.F_Result = result;//处理结果

                    modelT_Bus_WorkOrder.F_CreateUser = User.F_UserCode;//登记人工号
                    modelT_Bus_WorkOrder.F_CreateTime = DateTime.Now;//登记时间
                    modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.neworder;// 0;//工单状态0登记中
                    modelT_Bus_WorkOrder.F_IsClosed = 0;//工单是否关闭
                    modelT_Bus_WorkOrder.F_IsOverdue = 0;//是否逾期(0:否，1：是)
                    modelT_Bus_WorkOrder.F_IsDelete = 0;//是否删除(0:否，1：是)

                    //如果选择即刻答复：是，即为直办，工单结束
                    if (isresult == 1)
                    {
                        modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.finish;// 9;//已结案
                        modelT_Bus_WorkOrder.F_DealUser = User.F_UserCode;
                        modelT_Bus_WorkOrder.F_DealTime = DateTime.Now;
                        modelT_Bus_WorkOrder.F_IsClosed = 1;
                        modelT_Bus_WorkOrder.F_CloseUser = User.F_UserCode;
                        modelT_Bus_WorkOrder.F_CloseTime = DateTime.Now;
                    }
                    else if (issubmit == 1)
                    {
                        modelT_Bus_WorkOrder.F_SubmitTime = DateTime.Now;
                        modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.submit;// 1;//提交领导
                    }
                    #region
                    //20190715去掉审核环节
                    //else
                    //{
                    //    modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.audit;//待审核
                    //}

                    //else if (issubmit == 1)
                    //{
                    //    modelT_Bus_WorkOrder.F_SubmitTime = DateTime.Now;
                    //    modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.submit;// 1;//提交领导
                    //}
                    #endregion
                    if (lyid != 0)
                    {
                        var rd = new BLL.T_Call_LeaveRecord().GetModel(lyid);
                        if (rd != null)
                        {
                            modelT_Bus_WorkOrder.F_LeaveRecordId = rd.F_Id;
                        }
                    }

                    workorderBLL.Add(modelT_Bus_WorkOrder);
                    #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;
                    oper.F_CallRecordId = modelT_Bus_WorkOrder.F_CallRecordId;
                    oper.F_File = modelT_Bus_WorkOrder.F_File;

                    string userinfo = User.depname + "(" + User.F_UserCode + ")";
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.neworder || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.audit)//0)
                    {
                        oper.F_Message = userinfo + " 登记了工单，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId;
                    }
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.submit)//1)
                    {
                        oper.F_Message = userinfo + " 登记并提交了工单，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId;
                    }
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.finish)//9)
                    {
                        oper.F_Message = userinfo + " 登记并结案了工单，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId;
                    }

                    oper.F_CreateUser = User.F_UserCode;
                    oper.F_CreateTime = DateTime.Now;
                    oper.F_IsDelete = 0;

                    operBLL.Add(oper);

                    //推送消息表
                    if (modelT_Bus_WorkOrder.F_WorkState != (int)EnumWorkState.neworder && modelT_Bus_WorkOrder.F_WorkState != (int)EnumWorkState.audit)//0)
                    {

                        var role = new BLL.T_Sys_RoleInfo().GetModelList(" (F_RoleCode='ZXLD' or F_RoleCode='ZXLDGLYGLY' or F_RoleCode='MTDD')  ").Select(p => p.F_RoleId);
                        var users = userBLL.GetModelList(" F_RoleId in (" + string.Join(",", role) + ")  ");

                        foreach (var u in users)
                        {
                            msg.AddInternalMessagesInfo("工单消息", oper.F_Message, u.F_UserCode, User.F_UserCode, (int)EnumSmsType.workorder);
                        }
                    }
                    #endregion

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

            }
            else
            {
                return Error("权限不足");
            }
        }

        /// <summary>
        /// 添加工单信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult AddWorkOrderByAPP()
        {




            int source = RequestString.GetInt("source", 6);

            string cusname = RequestString.GetFormString("cusname");
            string cussex = RequestString.GetFormString("cussex");
            string cusphone = RequestString.GetFormString("cusphone");
            string cusaddress = RequestString.GetFormString("cusaddress");
            string email = RequestString.GetFormString("email");
            string zipcode = RequestString.GetFormString("zipcode");
            string conname = RequestString.GetFormString("conname");
            string conphone = RequestString.GetFormString("conphone");

            string title = RequestString.GetFormString("title");
            string content = RequestString.GetFormString("content");
            string files = RequestString.GetFormString("files");
            int sourcearea = RequestString.GetInt("sourcearea", 0);
            string sourceaddress = RequestString.GetFormString("sourceaddress");

            int isresult = RequestString.GetInt("isresult", 0);
            string result = RequestString.GetFormString("result");

            string keys = RequestString.GetFormString("keys");
            string splituser = RequestString.GetFormString("splituser");

            int type = RequestString.GetInt("type", 0);
            int bigtype = RequestString.GetInt("bigtype", 0);
            int smalltype = RequestString.GetInt("smalltype", 0);

            int isprotect = RequestString.GetInt("isprotect", 0);
            int level = RequestString.GetInt("level", 0);


            string workorderid = AddWorkOrderBySource(6, cusname, cussex, cusphone, cusaddress, email, zipcode, conname,
                    conphone, title, content, sourcearea, sourceaddress, keys, splituser, type, bigtype, smalltype, isprotect, level, files);
            if (!string.IsNullOrEmpty(workorderid))
            {
                using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                {
                    #region 保存用户工单信息
                    var model = new BLL.T_Sys_Users().GetModel(User.F_UserCode);
                    if (model == null)
                    {
                        model = new Model.T_Sys_Users();
                        model.F_OpenId = User.F_UserCode;
                        model.F_Type = (int)EnumUserType.app;//3;
                        model.F_CreateTime = DateTime.Now;
                        model.F_Id = new BLL.T_Sys_Users().Add(model);
                    }

                    Model.T_Bus_UserWorkOrder tbu = new Model.T_Bus_UserWorkOrder();
                    tbu.F_UserId = model.F_Id;
                    tbu.F_WorkOrderId = workorderid;
                    new BLL.T_Bus_UserWorkOrder().Add(tbu);
                    #endregion

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


        }
        #endregion

        #region 操作工单

        /// <summary>
        /// 修改工单信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult EditWorkOrder(List<maindeptcontent> contsents)
        {
            if (User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "ZXBZ" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD"
               || User.F_RoleCode == "GNZY")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);

                int source = RequestString.GetInt("source", 0);
                string cusname = RequestString.GetFormString("cusname");
                string cussex = RequestString.GetFormString("cussex");
                string cusphone = RequestString.GetFormString("cusphone");
                string cusaddress = RequestString.GetFormString("cusaddress");
                string email = RequestString.GetFormString("email");
                string zipcode = RequestString.GetFormString("zipcode");
                string conname = RequestString.GetFormString("conname");
                string conphone = RequestString.GetFormString("conphone");
                int state = RequestString.GetInt("state", 0);
                string title = RequestString.GetFormString("title");
                string content = RequestString.GetFormString("content");
                string files = RequestString.GetFormString("files");
                int sourcearea = RequestString.GetInt("sourcearea", 0);
                string sourceaddress = RequestString.GetFormString("sourceaddress");
                int isresult = RequestString.GetInt("isresult", 0);
                string result = RequestString.GetFormString("result");
                string keys = RequestString.GetFormString("keys");
                string splituser = RequestString.GetFormString("splituser");
                int type = RequestString.GetInt("type", 0);
                int bigtype = RequestString.GetInt("bigtype", 0);
                int smalltype = RequestString.GetInt("smalltype", 0);
                int isprotect = RequestString.GetInt("isprotect", 0);
                int level = RequestString.GetInt("level", 0);
                int issubmit = RequestString.GetInt("issubmit", 0);
                int isopen = RequestString.GetInt("isopen", 0);
                int business = RequestString.GetInt("business", 0);
                int township = RequestString.GetInt("township", 0);
                int village = RequestString.GetInt("village", 0);
                string file = RequestString.GetFormString("file");
                string workcontent = RequestString.GetFormString("workcontent");
                string maindeptids = RequestString.GetFormString("maindeptids");
                 int limittimes = RequestString.GetInt("limittimes", 0);
              
                lock (_MyLock)
                {
                        #region 保存工单信息
                        Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                        keyValuePairs.Add("F_InfoSource", source);
                        //modelT_Bus_WorkOrder.F_InfoSource = source;//信息来源
                        keyValuePairs.Add("F_Township", township);
                        //modelT_Bus_WorkOrder.F_Township = township;
                        keyValuePairs.Add("F_Village", village);
                        //modelT_Bus_WorkOrder.F_Village  = village;
                        keyValuePairs.Add("F_InfoType", type);
                        //modelT_Bus_WorkOrder.F_InfoType = type;//信息类别
                        keyValuePairs.Add("F_InfoConBigType", bigtype);
                        //modelT_Bus_WorkOrder.F_InfoConBigType = bigtype;//内容大类
                        keyValuePairs.Add("F_InfoConSmallType", smalltype);
                        //modelT_Bus_WorkOrder.F_InfoConSmallType = smalltype;//内容小类
                        keyValuePairs.Add("F_SourceArea", sourcearea);
                        //modelT_Bus_WorkOrder.F_SourceArea = sourcearea;//反映地域
                        keyValuePairs.Add("F_SourceAddress", sourceaddress);
                        //modelT_Bus_WorkOrder.F_SourceAddress = sourceaddress;//事发地址
                        keyValuePairs.Add("F_CusName", cusname);
                        // modelT_Bus_WorkOrder.F_CusName = cusname;//投诉人姓名
                        keyValuePairs.Add("F_CusSex", cussex);
                        //modelT_Bus_WorkOrder.F_CusSex = cussex;//性别
                        keyValuePairs.Add("F_CusPhone", cusphone);
                        // modelT_Bus_WorkOrder.F_CusPhone = cusphone;//来电号码
                        keyValuePairs.Add("F_CusAddress", cusaddress);
                        //  modelT_Bus_WorkOrder.F_CusAddress = cusaddress;//地址
                        keyValuePairs.Add("F_ZipCode", zipcode);
                        // modelT_Bus_WorkOrder.F_ZipCode = zipcode;//邮编
                        keyValuePairs.Add("F_ConName", conname);
                        //modelT_Bus_WorkOrder.F_ConName = conname;//联系人姓名
                        keyValuePairs.Add("F_ConPhone", conphone);
                        // modelT_Bus_WorkOrder.F_ConPhone = conphone;//联系人电话
                        keyValuePairs.Add("F_Email", email);
                        modelT_Bus_WorkOrder.F_Email = email;//E-mail
                        keyValuePairs.Add("F_ComTitle", title);
                        //  modelT_Bus_WorkOrder.F_ComTitle = title;//标题
                        keyValuePairs.Add("F_ComContent", content);
                        // modelT_Bus_WorkOrder.F_ComContent = content;//情况摘要（投诉内容）
                        keyValuePairs.Add("F_File", files);
                       // modelT_Bus_WorkOrder.F_File = files;//附件
                        keyValuePairs.Add("F_IsProtect", isprotect);
                        // modelT_Bus_WorkOrder.F_IsProtect = isprotect;//保密方式0否1是
                        keyValuePairs.Add("F_Content", workcontent);
                        //  modelT_Bus_WorkOrder.F_Content = workcontent;
                        keyValuePairs.Add("F_Key", keys);
                        // modelT_Bus_WorkOrder.F_Key = keys;
                        keyValuePairs.Add("F_Level", level);
                        // modelT_Bus_WorkOrder.F_Level = level;
                        keyValuePairs.Add("F_ToBereply", 0);
                        keyValuePairs.Add("F_SplitUser", splituser);
                        // modelT_Bus_WorkOrder.F_ToBereply = 0;
                        //是否直办（即时答复）0:，否1： 是  
                       keyValuePairs.Add("F_IsResult", isresult);
                     

                      if (source !=1&&source !=3 &&source !=6&& !string .IsNullOrEmpty (maindeptids))
                       {
                        var deptlist = new BLL.T_Sys_Department().GetModelList("F_DeptId in (" + maindeptids + ")");
                        if (deptlist != null)
                        {
                            if (deptlist.Count == 1)
                            {
                                var deptinfo = deptlist.FirstOrDefault();
                                if (deptinfo.F_IsDept == 2)
                                {
                                    if (deptinfo.F_PartentId > 0)
                                    {
                                    var  premodeldept = department((int)deptinfo.F_PartentId);
                                        if (premodeldept == null)
                                            return Error("该单位没有上级单位,派单失败");
                                    }
                                    else
                                    {
                                        return Error("该单位没有上级单位,派单失败");
                                    }
                                }

                            }
                            else
                            {
                                if (deptlist.Where(x => x.F_IsDept == 2).Count() > 0)
                                    return Error("派单多单位不能派给三级单位");
                            }
                        }
                        else
                        {
                            return Error("单位不存在");
                        }
                      }
                

                        modelT_Bus_WorkOrder.F_IsResult = isresult;
                        keyValuePairs.Add("F_Result", result);
                        modelT_Bus_WorkOrder.F_Result = result;//处理结果
                        if (isopen > 0)
                        {
                            keyValuePairs.Add("F_IsOpen", isopen);
                           // modelT_Bus_WorkOrder.F_IsOpen = isopen;
                        }
                     
                        if (isresult == 1)
                        {
                            keyValuePairs.Add("F_WorkState", 9);
                            modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.finish;// 9;//已结案
                            keyValuePairs.Add("F_DealDeptId", User.F_DeptId);
                            // modelT_Bus_WorkOrder.F_DealDeptId = User.F_DeptId;
                            keyValuePairs.Add("F_DealUser", User.F_UserCode);
                            // modelT_Bus_WorkOrder.F_DealUser = User.F_UserCode;
                            keyValuePairs.Add("F_DealTime", DateTime.Now);
                            //  modelT_Bus_WorkOrder.F_DealTime = DateTime.Now;
                            keyValuePairs.Add("F_IsClosed", 1);
                            // modelT_Bus_WorkOrder.F_IsClosed = 1;
                            keyValuePairs.Add("F_CloseUser", User.F_UserCode);
                            // modelT_Bus_WorkOrder.F_CloseUser = User.F_UserCode;
                            keyValuePairs.Add("F_CloseTime", DateTime.Now);

                        var cureuser = User;
                        Task.Run(() =>
                        {
                            CloseWorkorder(modelT_Bus_WorkOrder, cureuser);
                        }).ContinueWith(p => {
                            System.Diagnostics.Debug.WriteLine(DateTime.Now);
                        });
                      
                        }
                        else if (issubmit == 1)
                        {
                            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;// 1;//提交领导
                        }

                    if (!string.IsNullOrEmpty(file))
                    {
                        Model.T_Bus_Feedback modelT_Bus_Feedback = new T_Bus_Feedback();
                        modelT_Bus_Feedback.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;//工单编号
                        modelT_Bus_Feedback.F_DealUser = User.F_UserCode;
                        modelT_Bus_Feedback.F_Result = result;//反馈内容
                        #region 20200114新增字段 zhengbingbing
                        modelT_Bus_Feedback.F_IsProtect = modelT_Bus_WorkOrder.F_IsProtect;//是否保密(0:否1:是)
                        DateTime contime = DateTime.Now;
                        modelT_Bus_Feedback.F_IsProResult = 1;
                        #endregion
                        modelT_Bus_Feedback.F_File = file;
                        modelT_Bus_Feedback.F_IsAudit = 0;
                        modelT_Bus_Feedback.F_IsDelete = 0;
                        modelT_Bus_Feedback.F_CreateUser = User.F_UserCode;//办理人
                        modelT_Bus_Feedback.F_CreateTime = DateTime.Now;//办理时间
                        modelT_Bus_Feedback.F_CreateDeptId = User.F_DeptId;//办理部门
                        modelT_Bus_Feedback.F_IsFeedEnd = 1;
                        modelT_Bus_Feedback.F_State = 1;
                        modelT_Bus_Feedback.F_Type = 1;
                        new BLL.T_Bus_Feedback().Add(modelT_Bus_Feedback);
                    }
                    #region
                    #endregion
                    if (state > 0)
                        {
                            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
                            {

                                int assignid = RequestString.GetInt("assignid", 0);
                                int maindeptid = RequestString.GetInt("maindeptid", 0);
                                //string maindeptid = RequestString.GetFormString("maindeptid");
                                string otherdeptids = RequestString.GetFormString("otherdeptids");
                                DateTime limittime = DateTime.Now;
                                try
                                {
                                    limittime = DateTime.Now.AddDays(int.Parse(RequestString.GetFormString("limittime")));
                                }
                                catch
                                {
                                    limittime = DateTime.Parse(RequestString.GetFormString("limittime") + " 23:59:59");
                                }

                                string assignedopinion = RequestString.GetFormString("assignedopinion");

                                var modelT_Bus_AssignedInfoLasts = assignBLL.GetList(0, $" F_WorkOrderId='{workorderid}' and F_IsDelete='0' and  F_State='1' ", " F_CreateTime desc").Tables[0];

                                if (!string.IsNullOrEmpty(otherdeptids))
                                {
                                    if (otherdeptids.Split(',').Contains(maindeptid.ToString()))
                                    {
                                        return Error("主办单位不能出现在协办单位");
                                    }
                                }
                                if (limittime < DateTime.Now)
                                {
                                    return Error("办理时限不能小于当前时间");
                                }

                                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = new Model.T_Bus_AssignedInfo();
                                var deptinfo = new BLL.T_Sys_Department().GetModel(maindeptid);
                                if (modelT_Bus_WorkOrder != null && deptinfo != null)
                                {
                                    //if (modelT_Bus_WorkOrder.F_WorkState == 1)
                                    //if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.submit)
                                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.submit)
                                    {
                                        int aid = 0;
                                        using (TransactionScope tran = new TransactionScope())
                                        {
                                            if (assignid == 0)
                                            {
                                                #region 插入交办记录
                                                modelT_Bus_AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                                modelT_Bus_AssignedInfo.F_LimitTime = limittime;//办理时限
                                                modelT_Bus_AssignedInfo.F_MainDeptId = maindeptid;//主办单位id
                                                modelT_Bus_AssignedInfo.F_OtherDeptIds = otherdeptids;//协办单位id
                                                modelT_Bus_AssignedInfo.F_AssignedOpinion = assignedopinion;//交办意见

                                                modelT_Bus_AssignedInfo.F_State = state;//0草稿  1正式
                                                modelT_Bus_AssignedInfo.F_CreateUser = User.F_UserCode;
                                                modelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                                                modelT_Bus_AssignedInfo.F_IsDelete = 0;
                                                modelT_Bus_AssignedInfo.F_IsOverdue = 0;
                                                modelT_Bus_AssignedInfo.F_IsSure = 0;
                                                modelT_Bus_AssignedInfo.F_IsReload = 0;
                                                modelT_Bus_AssignedInfo.F_IsNext = 0;
                                                modelT_Bus_AssignedInfo.F_TimeResp = assignBLL.GetRepTimly(DateTime.Now);//及时查收时间点
                                                aid = assignBLL.Add(modelT_Bus_AssignedInfo);

                                                #endregion
                                            }
                                            else
                                            {
                                                #region 修改交办记录
                                                modelT_Bus_AssignedInfo = assignBLL.GetModel(assignid);
                                                if (modelT_Bus_AssignedInfo != null)
                                                {
                                                    modelT_Bus_AssignedInfo.F_LimitTime = limittime;//办理时限
                                                    modelT_Bus_AssignedInfo.F_MainDeptId = maindeptid;//主办单位id
                                                    modelT_Bus_AssignedInfo.F_OtherDeptIds = otherdeptids;//协办单位id
                                                    modelT_Bus_AssignedInfo.F_AssignedOpinion = assignedopinion;//交办意见
                                                    modelT_Bus_AssignedInfo.F_TimeResp = assignBLL.GetRepTimly(DateTime.Now);//及时查收时间点
                                                    modelT_Bus_AssignedInfo.F_State = state;//0草稿  1正式
                                                    modelT_Bus_AssignedInfo.F_CreateUser = User.F_UserCode;
                                                    modelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                                                    assignBLL.Update(modelT_Bus_AssignedInfo);
                                                    aid = modelT_Bus_AssignedInfo.F_Id;
                                                }

                                                #endregion
                                            }

                                            if (modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_State == 1)
                                            {
                                                #region 保存工单信息
                                                //modelT_Bus_WorkOrder.F_WorkState = 2;//待查收
                                                keyValuePairs.Add("F_WorkState",2);
                                                modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.receive;//待查收
                                                keyValuePairs.Add("F_LimitTime", limittime);
                                                // modelT_Bus_WorkOrder.F_LimitTime = limittime;
                                                keyValuePairs.Add("F_MainDeptId", maindeptid);
                                                modelT_Bus_WorkOrder.F_MainDeptId = maindeptid;
                                                keyValuePairs.Add("F_OtherDeptIds", otherdeptids);
                                                // modelT_Bus_WorkOrder.F_OtherDeptIds = otherdeptids;
                                                keyValuePairs.Add("F_AssignUser", User.F_UserCode);
                                                // modelT_Bus_WorkOrder.F_AssignUser = User.F_UserCode;
                                                keyValuePairs.Add("F_AssignTime", DateTime.Now);
                                              //  modelT_Bus_WorkOrder.F_AssignTime = DateTime.Now;
                                               
                                                #endregion

                                                #region 删除草稿信息
                                                var cglist = assignBLL.GetModelList(" F_IsDelete=0 and F_State=0 and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "'");

                                                foreach (var cg in cglist)
                                                {
                                                    cg.F_IsDelete = 1;
                                                    cg.F_DeleteUser = User.F_UserCode;
                                                    cg.F_DeleteTime = DateTime.Now;

                                                    assignBLL.Update(cg);
                                                }
                                                #endregion

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

                                                string userinfos = User.depname + "(" + User.F_UserCode + ")";

                                                opers.F_Message = userinfos + " 交办了工单，主办单位：" + deptinfo.F_DeptName;
                                                if (!string.IsNullOrEmpty(otherdeptids))
                                                {
                                                    string sql = "select dbo.GetDeptNames('" + otherdeptids + "')";
                                                    opers.F_Message += "，协办单位：" + DbHelperSQL.GetSingle(sql);
                                                }
                                                opers.F_CreateUser = User.F_UserCode;
                                                opers.F_CreateTime = DateTime.Now;
                                                opers.F_IsDelete = 0;

                                                operBLL.Add(opers);

                                                //推送消息表
                                                var users = userBLL.GetModelList(" F_DeptId='" + deptinfo.F_DeptId + "' ");

                                                foreach (var u in users)
                                                {
                                                    msg.AddInternalMessagesInfo("工单消息", opers.F_Message + "，工单编号：" + opers.F_WorkOrderId, u.F_UserCode, User.F_UserCode, (int)EnumSmsType.workorder);
                                                }
                                                #endregion
                                            }

                                            tran.Complete();
                                        }
                                        return Success("操作成功", modelT_Bus_AssignedInfo.F_Id);
                                    }
                                    else
                                    {
                                        return Error("已经交办过了");
                                    }
                                }
                                else
                                {
                                    return Error("操作失败");
                                }

                            }
                            else
                            {
                                return Error("权限不足");
                            }
                        }
                        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 = modelT_Bus_WorkOrder.F_WorkState;
                        oper.F_CallRecordId = modelT_Bus_WorkOrder.F_CallRecordId;
                        oper.F_File = modelT_Bus_WorkOrder.F_File;

                        string userinfo = User.depname + "(" + User.F_UserCode + ")";
                          oper.F_Message = userinfo + " 修改了工单";
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.submit)//1)
                        {
                            oper.F_Message = userinfo + " 修改并提交了工单";
                        }
                        if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.resubmit)//1)
                        {
                            oper.F_Message = userinfo + " 修改了重办工单";
                        }
                        if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.finish)//9)
                        {
                            oper.F_Message = userinfo + " 修改并结案了工单";
                        }

                        oper.F_CreateUser = User.F_UserCode;
                        oper.F_CreateTime = DateTime.Now;
                        oper.F_IsDelete = 0;

                        operBLL.Add(oper);
                        Task.Run(() =>
                        {//推送消息表
                            if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.submit)//1)
                            {

                                var role = new BLL.T_Sys_RoleInfo().GetModelList(" (F_RoleCode='ZXLD' or F_RoleCode='ZXLDGLYGLY'or F_RoleCode='MTDD')  ").Select(p => p.F_RoleId);
                                var users = userBLL.GetModelList(" F_RoleId in (" + string.Join(",", role) + ")  ");

                                foreach (var u in users)
                                {
                                    msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, u.F_UserCode, User.F_UserCode, (int)EnumSmsType.workorder);
                                }
                            }
                        });
                        //调用科大讯飞

                        #endregion
                       
                }
                return Success("操作成功");

            }
            else
            {
                return Success("权限不足");
            }
        }

        /// <summary>
        /// 修改工单信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult EditWorkOrderBySource()
        {
            if (User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "ZXBZ" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int source = RequestString.GetInt("source", 0);
                string cusname = RequestString.GetFormString("cusname");
                string cussex = RequestString.GetFormString("cussex");
                string cusphone = RequestString.GetFormString("cusphone");
                string cusaddress = RequestString.GetFormString("cusaddress");
                string email = RequestString.GetFormString("email");
                string zipcode = RequestString.GetFormString("zipcode");
                string conname = RequestString.GetFormString("conname");
                string conphone = RequestString.GetFormString("conphone");

                string title = RequestString.GetFormString("title");
                string content = RequestString.GetFormString("content");
                string files = RequestString.GetFormString("files");
                int sourcearea = RequestString.GetInt("sourcearea", 0);
                string sourceaddress = RequestString.GetFormString("sourceaddress");
                string workcontent = RequestString.GetFormString("workcontent");

                int isresult = RequestString.GetInt("isresult", 0);
                string result = RequestString.GetFormString("result");

                string keys = RequestString.GetFormString("keys");
                string splituser = RequestString.GetFormString("splituser");

                int type = RequestString.GetInt("type", 0);
                int bigtype = RequestString.GetInt("bigtype", 0);
                int smalltype = RequestString.GetInt("smalltype", 0);

                int isprotect = RequestString.GetInt("isprotect", 0);
                int level = RequestString.GetInt("level", 0);
                int issubmit = RequestString.GetInt("issubmit", 0);

                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                if (modelT_Bus_WorkOrder != null)
                {
                    if (modelT_Bus_WorkOrder.F_IsEnabled == 0)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            #region 保存工单信息

                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            keyValuePairs.Add("F_InfoSource", source);
                            //modelT_Bus_WorkOrder.F_InfoSource = source;//信息来源
                            keyValuePairs.Add("F_InfoType", type);
                            //modelT_Bus_WorkOrder.F_InfoType = type;//信息类别
                            keyValuePairs.Add("F_InfoConBigType", bigtype);
                            //modelT_Bus_WorkOrder.F_InfoConBigType = bigtype;//内容大类
                            keyValuePairs.Add("F_InfoConSmallType", smalltype);
                            //modelT_Bus_WorkOrder.F_InfoConSmallType = smalltype;//内容小类
                            keyValuePairs.Add("F_SourceArea", sourcearea);
                            //modelT_Bus_WorkOrder.F_SourceArea = sourcearea;//反映地域
                            keyValuePairs.Add("F_SourceAddress", sourceaddress);
                            //modelT_Bus_WorkOrder.F_SourceAddress = sourceaddress;//事发地址
                            keyValuePairs.Add("F_CusName", cusname);
                            // modelT_Bus_WorkOrder.F_CusName = cusname;//投诉人姓名
                            keyValuePairs.Add("F_CusSex", cussex);
                            //modelT_Bus_WorkOrder.F_CusSex = cussex;//性别
                            keyValuePairs.Add("F_CusPhone", cusphone);
                            // modelT_Bus_WorkOrder.F_CusPhone = cusphone;//来电号码
                            keyValuePairs.Add("F_CusAddress", cusaddress);
                            //  modelT_Bus_WorkOrder.F_CusAddress = cusaddress;//地址
                            keyValuePairs.Add("F_ZipCode", zipcode);
                            // modelT_Bus_WorkOrder.F_ZipCode = zipcode;//邮编
                            keyValuePairs.Add("F_ConName", conname);
                            //modelT_Bus_WorkOrder.F_ConName = conname;//联系人姓名
                            keyValuePairs.Add("F_ConPhone", conphone);
                            // modelT_Bus_WorkOrder.F_ConPhone = conphone;//联系人电话
                            keyValuePairs.Add("F_Email", email);
                            modelT_Bus_WorkOrder.F_Email = email;//E-mail
                            keyValuePairs.Add("F_ComTitle", title);
                            //  modelT_Bus_WorkOrder.F_ComTitle = title;//标题
                            keyValuePairs.Add("F_ComContent", content);
                            // modelT_Bus_WorkOrder.F_ComContent = content;//情况摘要（投诉内容）
                            keyValuePairs.Add("F_File", files);
                            // modelT_Bus_WorkOrder.F_File = files;//附件
                            keyValuePairs.Add("F_File", isprotect);
                            // modelT_Bus_WorkOrder.F_IsProtect = isprotect;//保密方式0否1是
                            keyValuePairs.Add("F_Content", workcontent);
                            //  modelT_Bus_WorkOrder.F_Content = workcontent;
                            keyValuePairs.Add("F_Key", keys);
                            // modelT_Bus_WorkOrder.F_Key = keys;
                            keyValuePairs.Add("F_Level", level);
                            // modelT_Bus_WorkOrder.F_Level = level;
                            keyValuePairs.Add("F_ToBereply", 0);
                            // modelT_Bus_WorkOrder.F_ToBereply = 0;
                            //是否直办（即时答复）0:，否1： 是  
                            keyValuePairs.Add("F_IsResult", isresult);
                            modelT_Bus_WorkOrder.F_IsResult = isresult;
                            keyValuePairs.Add("F_Result", result);
                            modelT_Bus_WorkOrder.F_Result = result;//处理结果
                            //   modelT_Bus_WorkOrder.F_Business = business;
                            //如果选择即刻答复：是，即为直办，工单结束
                            if (isresult == 1)
                            {
                                keyValuePairs.Add("F_WorkState", 9);
                                modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.finish;// 9;//已结案
                                keyValuePairs.Add("F_DealDeptId", User.F_DeptId);
                                // modelT_Bus_WorkOrder.F_DealDeptId = User.F_DeptId;
                                keyValuePairs.Add("F_DealUser", User.F_UserCode);
                                // modelT_Bus_WorkOrder.F_DealUser = User.F_UserCode;
                                keyValuePairs.Add("F_DealTime", DateTime.Now);
                                //  modelT_Bus_WorkOrder.F_DealTime = DateTime.Now;
                                keyValuePairs.Add("F_IsClosed", 1);
                                // modelT_Bus_WorkOrder.F_IsClosed = 1;
                                keyValuePairs.Add("F_CloseUser", User.F_UserCode);
                                // modelT_Bus_WorkOrder.F_CloseUser = User.F_UserCode;
                                keyValuePairs.Add("F_CloseTime", DateTime.Now);
                                // modelT_Bus_WorkOrder.F_CloseTime = DateTime.Now;
                            }
                            else if (issubmit == 1)
                            {
                                keyValuePairs.Add("F_SubmitTime", DateTime.Now);
                                // modelT_Bus_WorkOrder.F_SubmitTime = DateTime.Now;
                                keyValuePairs.Add("F_WorkState", (int)EnumWorkState.submit);
                                modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.submit;// 1;//提交领导
                            }
                            #region
                         
                            #endregion
                            // modelT_Bus_WorkOrder.F_CreateUser = User.F_UserCode;
                            keyValuePairs.Add("F_IsEnabled",1);
                            // modelT_Bus_WorkOrder.F_IsEnabled = 1;
                            keyValuePairs.Add("F_EnableTime", DateTime.Now);
                            // modelT_Bus_WorkOrder.F_EnableTime = DateTime.Now
                            keyValuePairs.Add("F_IsDelete", 0); ;
                         //   modelT_Bus_WorkOrder.F_IsDelete = 0;
                            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 = modelT_Bus_WorkOrder.F_WorkState;
                            oper.F_CallRecordId = modelT_Bus_WorkOrder.F_CallRecordId;
                            oper.F_File = modelT_Bus_WorkOrder.F_File;

                            string userinfo = User.depname + "(" + User.F_UserCode + ")";
                            if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.neworder || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.audit)//0)
                            {
                                oper.F_Message = userinfo + " 处理了工单";
                            }
                            if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.submit)//1)
                            {
                                oper.F_Message = userinfo + " 处理并提交了工单";
                            }
                            if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.finish)//9)
                            {
                                oper.F_Message = userinfo + " 处理并结案了工单";
                            }

                            oper.F_CreateUser = User.F_UserCode;
                            oper.F_CreateTime = DateTime.Now;
                            oper.F_IsDelete = 0;

                            operBLL.Add(oper);

                            //推送消息表
                            if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.submit)//1)
                            {

                                var role = new BLL.T_Sys_RoleInfo().GetModelList(" (F_RoleCode='ZXLD' or F_RoleCode='ZXLDGLYGLY' or F_RoleCode='MTDD')  ").Select(p => p.F_RoleId);
                                var users = userBLL.GetModelList(" F_RoleId in (" + string.Join(",", role) + ")  ");

                                foreach (var u in users)
                                {
                                    msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, u.F_UserCode, User.F_UserCode, (int)EnumSmsType.workorder);
                                }
                            }
                            //调用科大讯飞
                            if (modelT_Bus_WorkOrder.F_InfoSource == 7 && modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.finish)//9)
                            {
                                ShangQiuWorkOrderController sqwo = new ShangQiuWorkOrderController();
                                bool bl = sqwo.SaveReplyInfo(oper.F_WorkOrderId, User.F_UserCode, User.depname, modelT_Bus_WorkOrder.F_Result, "3", modelT_Bus_WorkOrder.F_InfoType.Value.ToString());
                                if (bl)
                                {
                                    Success("调用成功,工单号：" + oper.F_WorkOrderId);
                                }
                                else
                                {
                                    Error("调用失败,工单号：" + oper.F_WorkOrderId);
                                }
                            }
                            #endregion

                            trans.Complete();
                        }
                        return Success("操作成功");
                    }
                    else
                    {
                        return Error("已经处理过了");
                    }
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Success("权限不足");
            }
        }

        #region 新增审核工单流程
        /// <summary>
        /// 20190315需求变动，新增审核工单，由组长审核
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        //[Authority]
        public ActionResult AuditWorkOrder()
        {


            if (User.F_RoleCode == "ZXBZ" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int state = RequestString.GetInt("state", 0);
                string reason = RequestString.GetFormString("reason");

                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)))
                    {

                        if (modelT_Bus_WorkOrder != null)
                        {
                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.audit)
                            {
                                var opt = "审核并提交"; var re = "";
                                #region 保存工单信息
                                if (state == 1)
                                {
                                    keyValuePairs.Add("F_SubmitTime", DateTime.Now);
                                    // modelT_Bus_WorkOrder.F_SubmitTime = DateTime.Now;
                                    keyValuePairs.Add("F_WorkState", (int)EnumWorkState.submit);
                                    modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.submit;//待交办
                                }
                                else
                                {
                                    keyValuePairs.Add("F_WorkState",0);
                                    modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.neworder;
                                    opt = "审核并退回";
                                    re = "，退回原因：" + reason;
                                }
                                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 = modelT_Bus_WorkOrder.F_WorkState;

                                string userinfo = User.depname + "(" + User.F_UserCode + ")";
                                oper.F_Message = userinfo + " " + opt + "了工单" + re;
                                oper.F_CreateUser = User.F_UserCode;
                                oper.F_CreateTime = DateTime.Now;
                                oper.F_IsDelete = 0;

                                operBLL.Add(oper);

                                //推送消息表
                                //if (modelT_Bus_WorkOrder.F_WorkState == 1)
                                if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.submit)
                                {

                                    var role = new BLL.T_Sys_RoleInfo().GetModelList(" (F_RoleCode='ZXLD' or F_RoleCode='ZXLDGLYGLY' or F_RoleCode='MTDD')  ").Select(p => p.F_RoleId);
                                    var users = userBLL.GetModelList(" F_RoleId in (" + string.Join(",", role) + ")  ");

                                    foreach (var u in users)
                                    {
                                        msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, u.F_UserCode, User.F_UserCode, (int)EnumSmsType.workorder);
                                    }
                                }
                                #endregion
                            }

                        }
                        trans.Complete();
                    }

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

        /// <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 == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "GNZY")
            {
                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)
                            {
                                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                                //if (modelT_Bus_WorkOrder.F_WorkState == 0)
                                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;
                                    //modelT_Bus_WorkOrder.F_WorkState = 1;//待交办
                                    keyValuePairs.Add("F_WorkState", (int)EnumWorkState.submit);
                                    modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.submit;//待交办
                                    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 = 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);

                                    //推送消息表
                                    //if (modelT_Bus_WorkOrder.F_WorkState == 1)
                                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.submit)
                                    {

                                        var role = new BLL.T_Sys_RoleInfo().GetModelList(" (F_RoleCode='ZXLD' or F_RoleCode='ZXLDGLYGLY' or F_RoleCode='MTDD')  ").Select(p => p.F_RoleId);
                                        if(role!=null && role.Count ()>0)
                                            {
                                            var users = userBLL.GetModelList(" F_RoleId in (" + string.Join(",", role) + ")  ");

                                            foreach (var u in users)
                                            {
                                                msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, u.F_UserCode, User.F_UserCode, (int)EnumSmsType.workorder);
                                            }
                                        }
                                      
                                    }
                                    #endregion
                                }

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

        /// <summary>
        /// 回退工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult ReturnWorkOrder()
        {
            string workorderid = RequestString.GetFormString("workorderid");
            string backuser = RequestString.GetFormString("backuser");
            string backreason = RequestString.GetFormString("backreason");
            string files = RequestString.GetFormString("files");
            Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = new BLL.T_Bus_WorkOrder().GetModel(workorderid);
            if (modelT_Bus_WorkOrder != null)
            {
                //if (modelT_Bus_WorkOrder.F_WorkState == 1 || (modelT_Bus_WorkOrder.F_WorkState == 9 && modelT_Bus_WorkOrder.F_IsResult==1))
                if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.submit || (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.finish && modelT_Bus_WorkOrder.F_IsResult == 1))
                {
                    using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                    {
                        #region 保存工单信息
                        Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                        keyValuePairs.Add("F_WorkState", 0);
                        modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.neworder;// 0;
                                                                                       //modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.audit;// 0;
                        keyValuePairs.Add("F_IsResult",0);
                     
                        keyValuePairs.Add("F_IsReturn", 1);
                        // modelT_Bus_WorkOrder.F_IsReturn = 1;
                        keyValuePairs.Add("F_AssignUser", User.F_UserCode);
                        // modelT_Bus_WorkOrder.F_AssignUser = User.F_UserCode;
                        keyValuePairs.Add("F_AssignTime", DateTime.Now);
                        //modelT_Bus_WorkOrder.F_AssignTime = DateTime.Now;
                        keyValuePairs.Add("F_Prevaricate", modelT_Bus_WorkOrder.F_Prevaricate+1);
                        
                        workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);
                        #endregion

                        #region 插入批示记录
                        //批示记录
                        Model.T_Bus_SubmitSuper model_T_Bus_SubmitSuper = new Model.T_Bus_SubmitSuper();
                        model_T_Bus_SubmitSuper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;//工单流水号
                        model_T_Bus_SubmitSuper.F_Type = 3;//1领导批示 2市长指示 3回退
                        model_T_Bus_SubmitSuper.F_BatchReason = backuser;//批示人
                        model_T_Bus_SubmitSuper.F_SuperOpinion = backreason;//批示内容
                        model_T_Bus_SubmitSuper.F_File = files;//附件
                        model_T_Bus_SubmitSuper.F_CreateUser = User.F_UserCode;//呈批人
                        model_T_Bus_SubmitSuper.F_CreateTime = DateTime.Now;//呈批时间
                        model_T_Bus_SubmitSuper.F_IsDelete = 0;
                        model_T_Bus_SubmitSuper.F_State = 1;//审批状态（0:未处理，1:通过）
                        new BLL.T_Bus_SubmitSuper().Add(model_T_Bus_SubmitSuper);
                        #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 + " 回退了工单";
                        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("操作失败");
            }
        }

        /// <summary>
        /// 领导批示/市长指示
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        //[Authority]
        public ActionResult SuperWorkOrder()
        {



            string workorderid = RequestString.GetFormString("workorderid");
            int type = RequestString.GetInt("type", 0);//1领导批示 2市长指示 3转督办
            string superuser = RequestString.GetFormString("superuser");
            string superopinion = RequestString.GetFormString("superopinion");
            string files = RequestString.GetFormString("files");
            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 保存工单信息 no use
                    //modelT_Bus_WorkOrder.F_WorkState = 2;//领导批示
                    //workorderBLL.Update(modelT_Bus_WorkOrder);
                    #endregion

                    #region 插入批示记录
                    //批示记录
                    Model.T_Bus_SubmitSuper model_T_Bus_SubmitSuper = new Model.T_Bus_SubmitSuper();
                    model_T_Bus_SubmitSuper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;//工单流水号
                    model_T_Bus_SubmitSuper.F_Type = type;//1领导批示 2市长指示
                    model_T_Bus_SubmitSuper.F_BatchReason = superuser;//批示人
                    model_T_Bus_SubmitSuper.F_SuperOpinion = superopinion;//批示内容
                    model_T_Bus_SubmitSuper.F_File = files;//附件
                    model_T_Bus_SubmitSuper.F_CreateUser = User.F_UserCode;//呈批人
                    model_T_Bus_SubmitSuper.F_CreateTime = DateTime.Now;//呈批时间
                    model_T_Bus_SubmitSuper.F_IsDelete = 0;
                    model_T_Bus_SubmitSuper.F_State = 1;//审批状态（0:未处理，1:通过）
                    new BLL.T_Bus_SubmitSuper().Add(model_T_Bus_SubmitSuper);
                    #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 + " 批示了工单";
                    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("操作失败");
            }
        }



        /// <summary>
        /// 办理中交办
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult HandleAssign()
        {
            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "DBZY" || User.F_RoleCode == "MTDD")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int state = RequestString.GetInt("state", 0);
                int assignid = RequestString.GetInt("assignid", 0);
                string maindeptid = RequestString.GetFormString("maindeptid");
                string otherdeptids = RequestString.GetFormString("otherdeptids");
                int limittime = RequestString.GetInt("limittime", 0);
                string limittimes = RequestString.GetFormString("limittimes");
                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  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 ";
                string assignedopinion = RequestString.GetFormString("assignedopinion");

                var modelT_Bus_AssignedInfoLasts = assignBLL.GetList(0, $" F_WorkOrderId='{workorderid}' and F_IsDelete='0' and  F_State='1' ", " F_CreateTime desc").Tables[0];
                if (!string.IsNullOrEmpty(otherdeptids))
                {
                    var both = otherdeptids.Split(',').Intersect(maindeptid.Split(','));
                    if (both.Count() > 0)
                    {
                        return Error("主办单位不能出现在协办单位");
                    }
                }

                string userinfo = User.depname + "(" + User.F_UserCode + ")";
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = new Model.T_Bus_AssignedInfo();
                var deptlist = new BLL.T_Sys_Department().GetModelList("F_DeptId in (" + maindeptid + ")");
                if (modelT_Bus_WorkOrder != null && deptlist != null && deptlist.Count > 0)
                {
                    int aid = 0; var rre = "";
                    using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                    {
                        string newids = ""; string errdeptid = ""; string deptname = "";
                        foreach (var deptinfo in deptlist)
                        {
                            deptname += deptinfo.F_DeptName + "，";
                            #region 新增工单
                            Model.T_Bus_WorkOrder modelT_Bus_WorkOrder1 = new Model.T_Bus_WorkOrder();
                            modelT_Bus_WorkOrder1 = modelT_Bus_WorkOrder;
                            string creattime = ((DateTime)modelT_Bus_WorkOrder1.F_CreateTime).ToString("yyyy-MM-dd") + " 00:00:00";
                            string endtime = ((DateTime)modelT_Bus_WorkOrder1.F_CreateTime).ToString("yyyy-MM-dd") + " 23:59:59";
                            modelT_Bus_WorkOrder1.F_WorkOrderId = workorderBLL.GetNewWorkOrderID((int)modelT_Bus_WorkOrder.F_InfoSource, (int)modelT_Bus_WorkOrder.F_SourceArea, creattime, endtime);
                            modelT_Bus_WorkOrder1.F_MainWorkorder1 = workorderid;
                            modelT_Bus_WorkOrder1.F_Id = workorderBLL.Add(modelT_Bus_WorkOrder1);
                            if (modelT_Bus_WorkOrder1.F_Id <= 0)
                            {
                                errdeptid += deptinfo.F_DeptName + ",";
                                continue;
                            }

                            #endregion
                            #region 交办
                            #region 插入交办记录
                            modelT_Bus_AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder1.F_WorkOrderId;
                            if (modelT_Bus_WorkOrder.F_Level == 2)
                            {
                                try
                                {
                                    modelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(limittimes);
                                }
                                catch
                                {
                                    return Error("请选择正确的时间");
                                }
                            }
                            else
                            {
                                modelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(resdatetime);
                            }

                            modelT_Bus_AssignedInfo.F_MainDeptId = deptinfo.F_DeptId;//主办单位id
                            modelT_Bus_AssignedInfo.F_OtherDeptIds = otherdeptids;//协办单位id
                            modelT_Bus_AssignedInfo.F_AssignedOpinion = assignedopinion;//交办意见
                            modelT_Bus_AssignedInfo.F_TimeResp = assignBLL.GetRepTimly(DateTime.Now);//及时查收时间点
                            modelT_Bus_AssignedInfo.F_State = state;//0草稿  1正式
                            modelT_Bus_AssignedInfo.F_CreateUser = User.F_UserCode;
                            modelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                            modelT_Bus_AssignedInfo.F_IsDelete = 0;
                            modelT_Bus_AssignedInfo.F_IsOverdue = 0;
                            modelT_Bus_AssignedInfo.F_IsSure = 0;
                            modelT_Bus_AssignedInfo.F_IsReload = 0;
                            modelT_Bus_AssignedInfo.F_IsNext = 0;
                            aid = assignBLL.Add(modelT_Bus_AssignedInfo);

                            #endregion
                            #endregion
                            if (modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_State == 1)
                            {
                                #region 保存工单信息
                                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                                keyValuePairs.Add("F_WorkState", (int)EnumWorkState.receive);
                                modelT_Bus_WorkOrder1.F_WorkState = (int)EnumWorkState.receive;//待查收
                                                                                               //   modelT_Bus_WorkOrder1.F_LimitTime = DateTime.Now.AddDays(limittime); ;
                                if (modelT_Bus_WorkOrder1.F_Level == 2)
                                {
                                    try
                                    {
                                        keyValuePairs.Add("F_LimitTime", Convert.ToDateTime(limittimes));
                                       // modelT_Bus_WorkOrder1.F_LimitTime = Convert.ToDateTime(limittimes);
                                    }
                                    catch
                                    {
                                        return Error("请选择正确的时间");
                                    }

                                }
                                else
                                {
                                    keyValuePairs.Add("F_LimitTime", Convert.ToDateTime(resdatetime));
                                   // modelT_Bus_WorkOrder1.F_LimitTime = Convert.ToDateTime(resdatetime);
                                }
                                keyValuePairs.Add("F_MainDeptId", deptinfo.F_DeptId);
                                // modelT_Bus_WorkOrder1.F_MainDeptId = deptinfo.F_DeptId;
                                keyValuePairs.Add("F_OtherDeptIds", otherdeptids);
                               // modelT_Bus_WorkOrder1.F_OtherDeptIds = otherdeptids;
                                keyValuePairs.Add("F_AssignUser", User.F_UserCode);
                                //modelT_Bus_WorkOrder1.F_AssignUser = User.F_UserCode;
                                keyValuePairs.Add("F_AssignTime", DateTime.Now);
                                //modelT_Bus_WorkOrder1.F_AssignTime = DateTime.Now;
                                workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder1.F_Id , keyValuePairs);


                                #endregion
                            
                                #region 插入操作记录
                                var msgss = userinfo + " 交办了工单，主办单位：" + deptinfo.F_DeptName;
                                if (!string.IsNullOrEmpty(otherdeptids))
                                {
                                    string sql = "select dbo.GetDeptNames('" + otherdeptids + "')";
                                    msgss += "，协办单位：" + DbHelperSQL.GetSingle(sql);
                                }

                                addoptlog(modelT_Bus_WorkOrder1.F_WorkOrderId, modelT_Bus_WorkOrder1.F_WorkState, modelT_Bus_AssignedInfo.F_Id, msgss, User.F_UserCode);

                                //推送消息表
                                var users = userBLL.GetModelList(" F_DeptId='" + deptinfo.F_DeptId + "' ");

                                foreach (var u in users)
                                {
                                    msg.AddInternalMessagesInfo("工单消息", msgss + "，工单编号：" + modelT_Bus_WorkOrder1.F_WorkOrderId, u.F_UserCode, User.F_UserCode, (int)EnumSmsType.workorder);
                                }
                                #endregion
                            }
                            newids += modelT_Bus_WorkOrder1.F_WorkOrderId + ",";
                        }
                        newids = newids.Trim(',');
                        var msgs = "";
                        Model.T_Bus_WorkOrder tempT_Bus_WorkOrder1 = workorderBLL.GetModel(workorderid);
                        Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                        keyValuePairs1.Add("F_MainWorkorder1", tempT_Bus_WorkOrder1.F_WorkOrderId);
                        // tempT_Bus_WorkOrder1.F_MainWorkorder1 = tempT_Bus_WorkOrder1.F_WorkOrderId;
                        keyValuePairs1.Add("F_SubWorkorder1", newids + "," + tempT_Bus_WorkOrder1.F_WorkOrderId);
                       // tempT_Bus_WorkOrder1.F_SubWorkorder1 = newids+","+ tempT_Bus_WorkOrder1.F_WorkOrderId ;
                        workorderBLL.UpdateWorkOrder (tempT_Bus_WorkOrder1.F_Id , keyValuePairs1);
                        if (errdeptid == "")
                        {

                            msgs = userinfo + " 交办多单位："+ deptname + "生成新工单，新工单编号为：" + newids;
                            addoptlog(workorderid, 4, 0, msgs, User.F_UserCode);
                        }
                        else
                        {
                            errdeptid = errdeptid.Trim(',');
                            msgs = userinfo + " 交办的单位有" + deptname + "，部分操作成功，新工单编号为：" + newids + "，交办失败的部门为：" + errdeptid;
                            addoptlog(workorderid, 4, 0, msgs, User.F_UserCode);
                        }
                        #region 插入操作记录

                        #endregion


                        trans.Complete();

                        #region
                        #endregion
                    }

                    var user = new BLL.T_Sys_UserAccount().GetModelList("F_DeptId in (" + maindeptid + ") ");
                    if (user != null && user.Count > 0)
                    {
                        foreach (var it in user)
                        {
                            if (it.F_RoleCode == "WLDW" && it.F_IsSms != null && it.F_IsSms == 1)
                            {
                                continue;
                            }
                            else
                            {
                                string count = "你有新工单：" + workorderid + "，请及时查收处理。";
                               // string msg = workorderid;
                               // bool n = SMSController.AddSmS(0, msg, count, it.F_Mobile, "153305", "");


                                string mag = "[\"" + workorderid + "\"]";
                                string v = SmsNewController.AddSmS(0, count, it.F_Mobile, "681240888655478784", mag,
                               workorderid);
                            }
                           
                        }
                    }

                    //审核员给二级单位转派

                    return Success("操作成功" + rre, modelT_Bus_AssignedInfo.F_Id);
                }
                else
                {
                    return Error("操作失败");
                }

            }
            else
            {
                return Error("权限不足");
            }
        }



        private Model.T_Sys_Department department(int PartentId)
        {
            var model = new BLL.T_Sys_Department().GetModel(PartentId);
            if (model!=null )
            {
                if (model.F_IsDept == 1)
                {
                    return model;
                }
                else
                {
                    if (model.F_PartentId > 0)
                        model = department((int)model.F_PartentId);
                    else
                        return null;
                }

            }
            else
            {
                return null;
            }
          
            return model;
        }
        public class maindeptcontent
        {
            public int id { set; get; }
            public string content { set; get; }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult AssignWorkOrderNew( List <maindeptcontent> content )
        {
            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "DBZY" || User.F_RoleCode == "MTDD")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int state = RequestString.GetInt("state", 0);
                int assignid = RequestString.GetInt("assignid", 0);
                string maindeptid = RequestString.GetFormString("maindeptid");
                string otherdeptids = RequestString.GetFormString("otherdeptids");
                int limittime = RequestString.GetInt("limittime", 0);
                string limittimes = RequestString.GetFormString("limittimes");
                int ispd = RequestString.GetInt("ispd", 0);
                int isms = RequestString.GetInt("isms", 0);
                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 ";
                string assignedopinion = RequestString.GetFormString("assignedopinion");

                var modelT_Bus_AssignedInfoLasts = assignBLL.GetList(0, $" F_WorkOrderId='{workorderid}' and F_IsDelete='0' and  F_State='1' ", " F_CreateTime desc").Tables[0];
                if (!string.IsNullOrEmpty(otherdeptids))
                {
                    var both = otherdeptids.Split(',').Intersect(maindeptid.Split(','));
                    if (both.Count() > 0)
                    {
                        return Error("主办单位不能出现在协办单位");
                    }
                }

                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                var premodeldept = new Model.T_Sys_Department();
                if (ispd > 0)
                {
                    if (string.IsNullOrEmpty(modelT_Bus_WorkOrder.F_Key ))
                        return Error("自动派单失败,请选择反映类别!");

                    try
                    {
                        var model = new BLL.T_Sys_DictionaryValue().GetModel
                             (int.Parse(modelT_Bus_WorkOrder.F_Key));
                        if (model != null)
                        {
                            if (model.F_Deptid != null)
                                maindeptid = model.F_Deptid.ToString ();
                            else
                                return Error("当前反映类别暂未设置相应派单部门,自动派单失败");
                        }
                        else
                            return Error("自动派单失败,请选择反映类别.");
                    }
                    catch
                    {
                        return Error("自动派单失败,请选择反映类别");
                    }

                   
                }
                else
                {
                    if (string .IsNullOrEmpty (maindeptid))
                        return Error("请选择派单部门");
                }
               
                var deptlist = new BLL.T_Sys_Department().GetModelList("F_DeptId in (" + maindeptid + ")");
                if (deptlist!=null )
                {
                    if (deptlist.Count == 1)
                    {
                        var deptinfo = deptlist.FirstOrDefault();
                        if (deptinfo.F_IsDept == 2)
                        {
                            if (deptinfo.F_PartentId > 0)
                            {
                                premodeldept = department((int)deptinfo.F_PartentId);
                                if (premodeldept == null)
                                    return Error("该单位没有上级单位,派单失败");
                            }
                            else
                            {
                                return Error("该单位没有上级单位,派单失败");
                            }
                        }

                    }
                    else
                    {
                        if (deptlist.Where(x => x.F_IsDept == 2).Count() > 0)
                            return Error("派单多单位不能派给三级单位");
                    }
                }
                else
                {
                    return Error("单位不存在");
                }
               

                string userinfo = User.depname + "(" + User.F_UserCode + ")";
               
                Model.T_Bus_WorkOrder tempT_Bus_WorkOrder = modelT_Bus_WorkOrder.ToJson().ToObject<Model.T_Bus_WorkOrder>();
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = new Model.T_Bus_AssignedInfo();
                if (modelT_Bus_WorkOrder != null && deptlist != null && deptlist.Count > 0)
                {
                    if (modelT_Bus_WorkOrder.F_Level == 2)
                    {
                        try
                        {
                            Convert.ToDateTime(limittimes);
                        }
                        catch
                        {
                            return Error("请选择正确的时间");
                        }
                    }

                    int aid = 0;
                    var curuser = User;
                    if (deptlist.Count == 1)
                    {
                        #region 交办一个单位
                        var maindept = deptlist.FirstOrDefault();
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            if (assignid == 0)
                            {
                                #region 插入交办记录
                                modelT_Bus_AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                if (modelT_Bus_WorkOrder.F_Level == 2)
                                {
                                    modelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(limittimes);
                                }
                                else
                                {
                                    modelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(resdatetime);
                                }
                                if (maindept.F_IsDept == 2)
                                    modelT_Bus_AssignedInfo.F_MainDeptId = premodeldept.F_DeptId;//主办单位id
                                else
                                    modelT_Bus_AssignedInfo.F_MainDeptId = maindept.F_DeptId;
                                modelT_Bus_AssignedInfo.F_OtherDeptIds = otherdeptids;//协办单位id
                                modelT_Bus_AssignedInfo.F_AssignedOpinion = assignedopinion;//交办意见
                                modelT_Bus_AssignedInfo.F_State = state;//0草稿  1正式
                                modelT_Bus_AssignedInfo.F_CreateUser = curuser.F_UserCode;
                                modelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                                modelT_Bus_AssignedInfo.F_IsDelete = 0;
                                modelT_Bus_AssignedInfo.F_IsOverdue = 0;
                                modelT_Bus_AssignedInfo.F_IsSure = 0;
                                modelT_Bus_AssignedInfo.F_IsReload = 0;
                                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);


                                #endregion
                            }
                            else
                            {
                                #region 修改交办记录
                                modelT_Bus_AssignedInfo = assignBLL.GetModel(assignid);
                                if (modelT_Bus_AssignedInfo != null)
                                {
                                    if (modelT_Bus_WorkOrder.F_Level == 2)
                                    {
                                        modelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(limittimes);
                                    }
                                    else
                                    {
                                        modelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(resdatetime);
                                    }
                                    if (maindept.F_IsDept == 2)
                                        modelT_Bus_AssignedInfo.F_MainDeptId = premodeldept.F_DeptId;//主办单位id
                                    else
                                        modelT_Bus_AssignedInfo.F_MainDeptId = maindept.F_DeptId;
                                    modelT_Bus_AssignedInfo.F_OtherDeptIds = otherdeptids;//协办单位id
                                    modelT_Bus_AssignedInfo.F_AssignedOpinion = assignedopinion;//交办意见
                                    modelT_Bus_AssignedInfo.F_TimeResp = assignBLL.GetRepTimly(DateTime.Now);//及时查收时间点
                                    modelT_Bus_AssignedInfo.F_State = state;//0草稿  1正式
                                    modelT_Bus_AssignedInfo.F_CreateUser = curuser.F_UserCode;
                                    modelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                                    assignBLL.Update(modelT_Bus_AssignedInfo);
                                    aid = modelT_Bus_AssignedInfo.F_Id;
                                }

                                #endregion
                            }

                            trans.Complete();
                        }
                        if (modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_State == 1)
                        {
                            Task.Run(() =>
                            {
                                #region 保存工单信息
                                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                                if (content != null && content.Count > 0)
                                {
                                    keyValuePairs.Add("F_Content", content[0].content);
                                }

                                if (modelT_Bus_WorkOrder.F_Level == 2)
                                {
                                    keyValuePairs.Add("F_LimitTime", Convert.ToDateTime(limittimes));
                                    //modelT_Bus_WorkOrder.F_LimitTime = Convert.ToDateTime(limittimes);
                                }
                                else
                                {
                                    keyValuePairs.Add("F_LimitTime", Convert.ToDateTime(resdatetime));
                                    //  modelT_Bus_WorkOrder.F_LimitTime = Convert.ToDateTime(resdatetime);
                                }
                                if (maindept.F_IsDept == 2)
                                {
                                    keyValuePairs.Add("F_MainDeptId", premodeldept.F_DeptId);
                                    modelT_Bus_WorkOrder.F_MainDeptId = premodeldept.F_DeptId;
                                }
                                else
                                {
                                    keyValuePairs.Add("F_MainDeptId", maindept.F_DeptId);
                                    modelT_Bus_WorkOrder.F_MainDeptId = maindept.F_DeptId;
                                }
                                keyValuePairs.Add("F_OtherDeptIds", otherdeptids);
                                // modelT_Bus_WorkOrder.F_OtherDeptIds = otherdeptids;
                                keyValuePairs.Add("F_AssignUser", curuser.F_UserCode);
                                // modelT_Bus_WorkOrder.F_AssignUser = curuser.F_UserCode;
                                keyValuePairs.Add("F_AssignTime", DateTime.Now);
                               // modelT_Bus_WorkOrder.F_AssignTime = DateTime.Now;
                                if (maindept.F_IsDept == 2)
                                {
                                    modelT_Bus_WorkOrder.F_WorkState = 4;
                                    keyValuePairs.Add("F_WorkState", 4);
                                }
                                  
                                else
                                {
                                    modelT_Bus_WorkOrder.F_WorkState = 2;
                                    keyValuePairs.Add("F_WorkState", 2);
                                }
                               // keyValuePairs.Add("F_IsSendBack", 0);
                              //  modelT_Bus_WorkOrder.F_IsSendBack = 0;
                                workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);

                                #endregion
                            }).ContinueWith(q =>
                            {
                                string DeptName = "";
                                if (maindept.F_IsDept == 2)
                                {
                                    DeptName = premodeldept.F_DeptName;
                                }
                                else
                                    DeptName = maindept.F_DeptName;

                                var msgss = userinfo + " 交办了工单，主办单位：" + DeptName;
                                if (!string.IsNullOrEmpty(otherdeptids))
                                {
                                    string sql = "select dbo.GetDeptNames('" + otherdeptids + "')";
                                    msgss += "，协办单位：" + DbHelperSQL.GetSingle(sql);
                                }

                                if (maindept.F_IsDept == 2)
                                {
                                    addoptlog(modelT_Bus_WorkOrder.F_WorkOrderId, modelT_Bus_WorkOrder.F_WorkState, modelT_Bus_AssignedInfo.F_Id, msgss, curuser.F_UserCode,0,1);
                                    SplitOrderNew(modelT_Bus_WorkOrder, maindept, Convert.ToDateTime(resdatetime), modelT_Bus_AssignedInfo, assignedopinion, curuser).ContinueWith(p =>
                                    {
                                        System.Diagnostics.Debug.WriteLine(DateTime.Now);
                                    });
                                }
                                else
                                {
                                    Task.Run(() =>
                                    {
                                        addoptlog(modelT_Bus_WorkOrder.F_WorkOrderId, modelT_Bus_WorkOrder.F_WorkState, modelT_Bus_AssignedInfo.F_Id, msgss, curuser.F_UserCode, 0, 1);
                                    }).ContinueWith(p =>
                                    {
                                        System.Diagnostics.Debug.WriteLine(DateTime.Now);
                                    });
                                }
                                    #region 插入推送消息
                                if (isms>0)
                                {
                                    if (maindept.F_IsDept == 2)
                                    {
                                        var users = userBLL.GetModelList(" F_DeptId='" + premodeldept.F_DeptId + "' ");

                                        foreach (var u in users)
                                        {
                                            if (curuser.F_RoleCode == "DBZY")
                                            {
                                                string count = "你有督办工单：" + modelT_Bus_WorkOrder.F_WorkOrderId + "，请及时查收处理。";
                                                //   string msgcount = modelT_Bus_WorkOrder.F_WorkOrderId;
                                                // bool n = SMSController.AddSmS(0, msgcount, count, u.F_Mobile, "242065", "");

                                                string mag = "[\"" + modelT_Bus_WorkOrder.F_WorkOrderId + "\"]";
                                                string v = SmsNewController.AddSmS(0, count, u.F_Mobile,
                                            "681240181093470208", mag, modelT_Bus_WorkOrder.F_WorkOrderId);


                                                msg.AddInternalMessagesInfo("工单消息", msgss + "，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId, u.F_UserCode, curuser.F_UserCode, (int)EnumSmsType.workorder);
                                            }
                                            else
                                            {
                                                if (u.F_RoleCode == "WLDW" && u.F_IsSms != null && u.F_IsSms == 1)
                                                {
                                                    continue;
                                                }
                                                else
                                                {
                                                    string count = "你有新工单：" + modelT_Bus_WorkOrder.F_WorkOrderId + "，已转至三级单位，请在已派单菜单查看。";
                                                    // string msgcount = modelT_Bus_WorkOrder.F_WorkOrderId;
                                                    //  bool n = SMSController.AddSmS(0, msgcount, count, u.F_Mobile, "153305", "");
                                                    string mag = "[\"" + modelT_Bus_WorkOrder.F_WorkOrderId + "\"]";
                                                    string v = SmsNewController.AddSmS(0, count, u.F_Mobile, "681240888655478784", mag,
                                                   modelT_Bus_WorkOrder.F_WorkOrderId);




                                                    msg.AddInternalMessagesInfo("工单消息", msgss + "，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId, u.F_UserCode, curuser.F_UserCode, (int)EnumSmsType.workorder);

                                                }


                                            }
                                        }
                                    }
                                    else
                                    {
                                        var users = userBLL.GetModelList(" F_DeptId='" + maindept.F_DeptId + "' ");
                                        foreach (var u in users)
                                        {
                                            if (curuser.F_RoleCode == "DBZY")
                                            {
                                                string count = "你有督办工单：" + modelT_Bus_WorkOrder.F_WorkOrderId + "，请及时查收处理。";
                                                //string msgcount = modelT_Bus_WorkOrder.F_WorkOrderId;
                                                // bool n = SMSController.AddSmS(0, msgcount, count, u.F_Mobile, "242065", "");
                                                string mag = "[\"" + modelT_Bus_WorkOrder.F_WorkOrderId + "\"]";
                                                string v = SmsNewController.AddSmS(0, count, u.F_Mobile,
                                            "681240181093470208", mag, modelT_Bus_WorkOrder.F_WorkOrderId);

                                                msg.AddInternalMessagesInfo("工单消息", msgss + "，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId, u.F_UserCode, curuser.F_UserCode, (int)EnumSmsType.workorder);
                                            }
                                            else
                                            {
                                                if (u.F_RoleCode == "WLDW" && u.F_IsSms != null && u.F_IsSms == 1)
                                                {
                                                    continue;
                                                }
                                                else
                                                {
                                                    string count = "你有新工单：" + modelT_Bus_WorkOrder.F_WorkOrderId + "，请及时查收处理。";
                                                    //  string msgcount = modelT_Bus_WorkOrder.F_WorkOrderId;
                                                    // bool n = SMSController.AddSmS(0, msgcount, count, u.F_Mobile, "153305", "");
                                                    string mag = "[\"" + modelT_Bus_WorkOrder.F_WorkOrderId + "\"]";
                                                    string v = SmsNewController.AddSmS(0, count, u.F_Mobile, "681240888655478784", mag,
                                                   modelT_Bus_WorkOrder.F_WorkOrderId);
                                                }

                                                msg.AddInternalMessagesInfo("工单消息", msgss + "，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId, u.F_UserCode, curuser.F_UserCode, (int)EnumSmsType.workorder);
                                            }

                                        }
                                    }
                                }
                                  

                                    #endregion
                              
                            });
                        }
                        return Success("操作成功", modelT_Bus_AssignedInfo.F_Id);
                        #endregion
                    }
                    else
                    {
                        Task.Run(() =>
                        {
                            string newids = ""; string errdeptid = ""; string deptname = "";
                            Model.T_Bus_RemindRecord t_Bus_RemindRecord = new Model.T_Bus_RemindRecord();
                            if (curuser.F_RoleCode == "DBZY")
                            {
                                t_Bus_RemindRecord = new BLL.T_Bus_RemindRecord().GetNewModelByWorkOrderID(tempT_Bus_WorkOrder.F_WorkOrderId);
                            }
                            object obj = new object();
                            List<Task> taskList = new List<Task>();
                            foreach (var deptinfo in deptlist)
                            {
                                deptname += deptinfo.F_DeptName + "，";

                                #region 新增工单
                                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder1 = new Model.T_Bus_WorkOrder();
                                modelT_Bus_WorkOrder1 = tempT_Bus_WorkOrder;
                                string creattime = ((DateTime)modelT_Bus_WorkOrder1.F_CreateTime).ToString("yyyy-MM-dd") + " 00:00:00";
                                string endtime = ((DateTime)modelT_Bus_WorkOrder1.F_CreateTime).ToString("yyyy-MM-dd") + " 23:59:59";
                                modelT_Bus_WorkOrder1.F_WorkOrderId = workorderBLL.GetNewWorkOrderID((int)modelT_Bus_WorkOrder.F_InfoSource, (int)modelT_Bus_WorkOrder.F_SourceArea, creattime, endtime);
                                modelT_Bus_WorkOrder1.F_MainWorkorder1 = modelT_Bus_WorkOrder.F_WorkOrderId;
                                if (content!=null && content.Count >0)
                                {
                                    if (content.Where (x=>x .id == deptinfo.F_DeptId).Count() >0)
                                    {
                                        modelT_Bus_WorkOrder1.F_Content = content.Where(x => x.id == deptinfo.F_DeptId).First ().content ;
                                        modelT_Bus_WorkOrder1.F_ComContent  = content.Where(x => x.id == deptinfo.F_DeptId).First().content;
                                    }
                                }
                                modelT_Bus_WorkOrder1.F_IsRelease = null;
                                modelT_Bus_WorkOrder1.F_Id = workorderBLL.Add(modelT_Bus_WorkOrder1);

                                if (curuser.F_RoleCode == "DBZY")
                                {
                                    Model.T_Bus_RemindRecord t_Bus_RemindRecord_1 = t_Bus_RemindRecord;
                                    t_Bus_RemindRecord_1.F_WorkOrderId = modelT_Bus_WorkOrder1.F_WorkOrderId;
                                    new BLL.T_Bus_RemindRecord().Add(t_Bus_RemindRecord_1);
                                }
                                #endregion

                                if (modelT_Bus_WorkOrder1.F_Id > 0)
                                {
                                    #region 插入交办记录
                                    modelT_Bus_AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder1.F_WorkOrderId;
                                    if (modelT_Bus_WorkOrder.F_Level == 2)
                                    {
                                        modelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(limittimes);
                                    }
                                    else
                                    {
                                        modelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(resdatetime);
                                    }

                                    modelT_Bus_AssignedInfo.F_MainDeptId = deptinfo.F_DeptId;//主办单位id
                                    modelT_Bus_AssignedInfo.F_OtherDeptIds = otherdeptids;//协办单位id
                                    modelT_Bus_AssignedInfo.F_AssignedOpinion = assignedopinion;//交办意见
                                    modelT_Bus_AssignedInfo.F_TimeResp = assignBLL.GetRepTimly(DateTime.Now);//及时查收时间点
                                    modelT_Bus_AssignedInfo.F_State = state;//0草稿  1正式
                                    modelT_Bus_AssignedInfo.F_CreateUser = curuser.F_UserCode;
                                    modelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                                    modelT_Bus_AssignedInfo.F_IsDelete = 0;
                                    modelT_Bus_AssignedInfo.F_IsOverdue = 0;
                                    modelT_Bus_AssignedInfo.F_IsSure = 0;
                                    modelT_Bus_AssignedInfo.F_IsReload = 0;
                                    modelT_Bus_AssignedInfo.F_IsNext = 0;
                                    aid = assignBLL.Add(modelT_Bus_AssignedInfo);

                                    #endregion

                                    if (modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_State == 1)
                                    {
                                        #region 保存工单信息
                                        Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                                        keyValuePairs.Add("F_WorkState", (int)EnumWorkState.receive);
                                        modelT_Bus_WorkOrder1.F_WorkState = (int)EnumWorkState.receive;//待查收
                                        if (modelT_Bus_WorkOrder1.F_Level == 2)
                                        {
                                            keyValuePairs.Add("F_LimitTime", Convert.ToDateTime(limittimes));
                                          //  modelT_Bus_WorkOrder1.F_LimitTime = Convert.ToDateTime(limittimes);
                                        }
                                        else
                                        {
                                            keyValuePairs.Add("F_LimitTime", Convert.ToDateTime(resdatetime));
                                            //modelT_Bus_WorkOrder1.F_LimitTime = Convert.ToDateTime(resdatetime);
                                        }
                                        keyValuePairs.Add("F_MainDeptId", deptinfo.F_DeptId);
                                        modelT_Bus_WorkOrder1.F_MainDeptId = deptinfo.F_DeptId;
                                        keyValuePairs.Add("F_OtherDeptIds", otherdeptids);
                                        // modelT_Bus_WorkOrder1.F_OtherDeptIds = otherdeptids;
                                        keyValuePairs.Add("F_AssignUser", curuser.F_UserCode);
                                        // modelT_Bus_WorkOrder1.F_AssignUser = curuser.F_UserCode;
                                        keyValuePairs.Add("F_AssignTime", DateTime.Now);
                                        // modelT_Bus_WorkOrder1.F_AssignTime = DateTime.Now;
                                       // keyValuePairs.Add("F_IsSendBack", 0);
                                       // modelT_Bus_WorkOrder1.F_IsSendBack = 0;
                                        workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder1.F_Id, keyValuePairs);
                                        #endregion

                                        var msgss = userinfo + " 交办了工单，主办单位：" + deptinfo.F_DeptName;
                                        if (!string.IsNullOrEmpty(otherdeptids))
                                        {
                                            string sql = "select dbo.GetDeptNames('" + otherdeptids + "')";
                                            msgss += "，协办单位：" + DbHelperSQL.GetSingle(sql);
                                        }

                                        #region 插入操作记录
                                        addoptlog(modelT_Bus_WorkOrder1.F_WorkOrderId, modelT_Bus_WorkOrder1.F_WorkState, modelT_Bus_AssignedInfo.F_Id, msgss, curuser.F_UserCode, 0, 1);
                                        #endregion

                                        #region 插入推送消息
                                        //推送消息表
                                        var users = userBLL.GetModelList(" F_DeptId='" + deptinfo.F_DeptId + "' ");

                                        foreach (var u in users)
                                        {
                                            msg.AddInternalMessagesInfo("工单消息", msgss + "，工单编号：" + modelT_Bus_WorkOrder1.F_WorkOrderId, u.F_UserCode, curuser.F_UserCode, (int)EnumSmsType.workorder);
                                        }
                                        #endregion

                                        #region 发短信
                                        if (isms > 0)
                                        {
                                            var user = new BLL.T_Sys_UserAccount().GetModelList("F_DeptId =" + deptinfo.F_DeptId);
                                            if (user != null && user.Count > 0)
                                            {
                                                foreach (var it in user)
                                                {
                                                    if (curuser.F_RoleCode == "DBZY")
                                                    {
                                                        string count = "你有督办工单：" + modelT_Bus_WorkOrder1.F_WorkOrderId + "，请及时查收处理。";
                                                        //  string msg = modelT_Bus_WorkOrder1.F_WorkOrderId;
                                                        //  bool n = SMSController.AddSmS(0, msg, count, it.F_Mobile, "242065", "");
                                                        string mag = "[\"" + modelT_Bus_WorkOrder1.F_WorkOrderId + "\"]";
                                                        string v = SmsNewController.AddSmS(0, count, it.F_Mobile, "681240181093470208", mag,
                                                        modelT_Bus_WorkOrder1.F_WorkOrderId);
                                                    }
                                                    else
                                                    {
                                                        if (it.F_RoleCode == "WLDW" && it.F_IsSms != null && it.F_IsSms == 1)
                                                        {
                                                            continue;
                                                        }
                                                        else
                                                        {
                                                            string count = "你有新工单：" + modelT_Bus_WorkOrder1.F_WorkOrderId + "，请及时查收处理。";
                                                            // string msg = modelT_Bus_WorkOrder1.F_WorkOrderId;
                                                            // bool n = SMSController.AddSmS(0, msg, count, it.F_Mobile, "153305", "");
                                                            string mag = "[\"" + modelT_Bus_WorkOrder1.F_WorkOrderId + "\"]";
                                                            string v = SmsNewController.AddSmS(0, count, it.F_Mobile, "681240888655478784", mag,
                                                            modelT_Bus_WorkOrder1.F_WorkOrderId);
                                                        }

                                                    }

                                                }
                                            }
                                        }
                                           
                                        #endregion

                                    }

                                    newids += modelT_Bus_WorkOrder1.F_WorkOrderId + ",";
                                }
                                else
                                {
                                    errdeptid += deptinfo.F_DeptName + ",";
                                }
                            }

                            newids = newids.Trim(','); 
                            var msgs = "";
                            if (errdeptid == "")
                            {
                                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                                keyValuePairs.Add("F_SubWorkorder1", newids);
                                modelT_Bus_WorkOrder.F_SubWorkorder1 = newids;
                                workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);
                                msgs = userinfo + " 交办多单位：" + deptname + "生成新工单，新工单编号为：" + newids;
                            }
                            else
                            {
                                errdeptid = errdeptid.Trim(',');
                                msgs = userinfo + " 交办的单位有" + deptname + "部分操作成功，新工单编号为：" + newids + "，交办失败的部门为：" + errdeptid;
                            }

                            addoptlog(modelT_Bus_WorkOrder.F_WorkOrderId, modelT_Bus_WorkOrder.F_WorkState, modelT_Bus_AssignedInfo.F_Id, msgs, curuser.F_UserCode, 0, 1);


                        }).ContinueWith(p =>
                        {
                            System.Diagnostics.Debug.WriteLine(DateTime.Now);
                        });
                        Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                      //  keyValuePairs1.Add("F_IsSendBack", 0);
                        // modelT_Bus_WorkOrder.F_IsSendBack = 0;
                        keyValuePairs1.Add("F_WorkState", (int)EnumWorkState.dealing);
                       // modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.dealing;
                        workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs1);
                        return Success("操作成功");
                    }
                }
                else
                {
                    return Error("操作失败");
                }

            }
            else
            {
                return Error("权限不足");
            }
        }


        /// <summary>
        /// 审核工单
        /// </summary>
        /// <returns></returns>
        public ActionResult ToExamineWorkOrder()
        {
            if (User.F_RoleCode == "ZJZY" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "MTDD" || User.F_RoleCode == "DMTSH")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int nexttype = RequestString.GetInt("nexttype", 0);//审核通过1审核不通过2审核通过转办
                string cbreason = RequestString.GetFormString("cbreason");//重办原因
                int issms = RequestString.GetInt("issms", 0);//是否发送短信
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                Model.T_Bus_ToExamine modelT_Bus_ToExamine = new Model.T_Bus_ToExamine();
                if (modelT_Bus_WorkOrder != null)
                {
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.dealed)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            modelT_Bus_ToExamine.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                            modelT_Bus_ToExamine.F_IsDelete = 0;
                            modelT_Bus_ToExamine.F_Type = nexttype;
                            modelT_Bus_ToExamine.F_CreatUser = User.F_UserCode;
                            modelT_Bus_ToExamine.F_Result = cbreason;
                            if (modelT_Bus_AssignedInfo != null)
                            {
                                modelT_Bus_ToExamine.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                            }
                            int id = new BLL.T_Bus_ToExamine().Add(modelT_Bus_ToExamine);
                            if (modelT_Bus_ToExamine != null)
                            {
                                //提交重办满意度改为满意
                                var opt = "审核通过"; var cbreasons = "";
                                //结案
                                if (nexttype == 0)
                                {
                                    keyValuePairs.Add("F_WorkState", 7);

                                    modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.visit;//已回访
                                    workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs);
                                    string deptname = User.depname; string code = User.F_UserCode;
                                    Task.Run(() =>
                                    {
                                        if (issms > 0)
                                        {
                                            SendVisits(modelT_Bus_WorkOrder.F_CusPhone, modelT_Bus_WorkOrder.F_WorkOrderId, deptname, code);
                                        }
                                    });
                                }
                                #region 重办
                                else if (nexttype == 2)
                                {
                                    #region 保存工单信息
                                    //if (modelT_Bus_WorkOrder.F_RemindDay == 2 || modelT_Bus_WorkOrder.F_RemindDay == 3)
                                    //{
                                    //    return Error("回访时，提交重办只能操作一次");
                                    //}
                                    Dictionary<string, object> keyValuePairs2 = new Dictionary<string, object>();
                                    if (modelT_Bus_WorkOrder.F_RemindDay == 1 || modelT_Bus_WorkOrder.F_RemindDay == 3)
                                        keyValuePairs2.Add("F_RemindDay", 3);
                                    else
                                        keyValuePairs2.Add("F_RemindDay", 2);
                                    keyValuePairs2.Add("F_WorkState", (int)EnumWorkState.resubmit);
                                    modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.resubmit;
                                   
                                    //  modelT_Bus_WorkOrder.F_IsExamine = 1;
                                    keyValuePairs2.Add("F_IsSms", 0);
                                    //  modelT_Bus_WorkOrder.F_IsSms = 0;
                                    keyValuePairs2.Add("F_Identification", 0);
                                    // modelT_Bus_WorkOrder.F_Identification = 0;
                                    workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs2);
                                    #endregion
                                    opt = "于" + DateTime.Now
                                                                        .ToString("yyyy年MM月dd日HH时mm分ss秒") + "提交重办";

                                    cbreasons = "，重办原因：" + cbreason;
                                 var    t_Bus_RemindRecord = new BLL.T_Bus_RemindRecord().GetNewModelByWorkOrderID(modelT_Bus_WorkOrder.F_WorkOrderId);
                                    if (t_Bus_RemindRecord!=null )
                                    {
                                        t_Bus_RemindRecord.F_State = 0;
                                        new BLL.T_Bus_RemindRecord().Update(t_Bus_RemindRecord);
                                    }


                                    #endregion
                                }
                                else if (nexttype == 1)
                                {
                                    if (modelT_Bus_WorkOrder.F_MainDeptId != null &&
                              modelT_Bus_WorkOrder.F_MainDeptId > 0)
                                    {

                                        if (User.F_RoleCode == "ZXHWY")
                                        {
                                            Dictionary<string, object> keyValuePairs3 = new Dictionary<string, object>();
                                            keyValuePairs3.Add("F_WorkState", (int)EnumWorkState.backaudit);
                                            modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.backaudit;//重办审核
                                            if (workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs3))
                                            {
                                                #region 插入操作记录

                                                #region 20191021调整为多个主办单位时调整

                                                #endregion
                                                opt = "于" + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒") + "退回重办";
                                                cbreasons = "，重办原因：" + cbreason;
                                                #endregion

                                            }
                                        }
                                        else
                                        {
                                            int n = Int32.Parse(DbHelperSQL.GetSingle("select count(1) from T_Bus_AssignedInfo WITH(NOLOCK) where F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and  F_State=1 and F_IsSure=1 and F_IsDelete=0 and isnull(F_IsReload,0)>0").ToString());
                                            Model.T_Bus_AssignedInfo newmodelT_Bus_AssignedInfo = new Model.T_Bus_AssignedInfo();
                                            newmodelT_Bus_AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                            DataTable dt = DbHelperSQL.Query("select top 6 F_OffDate from  T_Sys_WorkOFFDays  where F_OffState = 1   and F_OffDate>='" + DateTime.Now + "' order by F_OffDate ").Tables[0];
                                            var resdatetime = dt.Rows[5]["F_OffDate"].ToString();
                                            if (!string.IsNullOrEmpty(resdatetime))
                                            {
                                                newmodelT_Bus_AssignedInfo.F_LimitTime = DateTime.Parse(resdatetime.Split(' ')[0] + " 23:59:59");//办理时限
                                            }
                                            newmodelT_Bus_AssignedInfo.F_MainDeptId = modelT_Bus_WorkOrder.F_MainDeptId;//主办单位id
                                            newmodelT_Bus_AssignedInfo.F_OtherDeptIds = "";//协办单位id
                                            newmodelT_Bus_AssignedInfo.F_AssignedOpinion = cbreason;//交办意见
                                            newmodelT_Bus_AssignedInfo.F_State = 1;
                                            newmodelT_Bus_AssignedInfo.F_CreateUser = User.F_UserCode;
                                            newmodelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                                            newmodelT_Bus_AssignedInfo.F_IsDelete = 0;
                                            newmodelT_Bus_AssignedInfo.F_IsOverdue = 0;
                                            newmodelT_Bus_AssignedInfo.F_IsSure = 0;
                                            newmodelT_Bus_AssignedInfo.F_IsReload = n + 1;
                                            newmodelT_Bus_AssignedInfo.F_ReloadUser = User.F_UserCode;
                                            newmodelT_Bus_AssignedInfo.F_ReloadTime = DateTime.Now;
                                            newmodelT_Bus_AssignedInfo.F_IsNext = 0;
                                            newmodelT_Bus_AssignedInfo.F_Id = assignBLL.Add(newmodelT_Bus_AssignedInfo);
                                            if (newmodelT_Bus_AssignedInfo.F_Id > 0)
                                            {
                                                #region 保存工单信息
                                                Dictionary<string, object> keyValuePairs3 = new Dictionary<string, object>();
                                                //  modelT_Bus_WorkOrder.F_MainDeptId = modelT_Bus_WorkOrder.F_MainDeptId;
                                                keyValuePairs3.Add("F_MainDeptId", modelT_Bus_WorkOrder.F_MainDeptId);
                                                keyValuePairs3.Add("F_OtherDeptIds", modelT_Bus_WorkOrder.F_OtherDeptIds);
                                                // modelT_Bus_WorkOrder.F_OtherDeptIds = modelT_Bus_WorkOrder.F_OtherDeptIds;
                                                keyValuePairs3.Add("F_AssignUser", User.F_UserCode);
                                                // modelT_Bus_WorkOrder.F_AssignUser = User.F_UserCode;
                                                keyValuePairs3.Add("F_AssignTime", DateTime.Now);
                                                //  modelT_Bus_WorkOrder.F_AssignTime = DateTime.Now;
                                                if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.finish)
                                                {
                                                    keyValuePairs3.Add("F_RemindDay", 1);
                                                    //   modelT_Bus_WorkOrder.F_RemindDay = 1;
                                                }
                                                keyValuePairs3.Add("F_IsReload", n + 1);
                                                // modelT_Bus_WorkOrder.F_IsReload = n + 1;
                                                if (!string.IsNullOrEmpty(resdatetime))
                                                    keyValuePairs3.Add("F_LimitTime", DateTime.Parse(resdatetime.Split(' ')[0] + " 23:59:59"));
                                                keyValuePairs3.Add("F_IsOverdue", 0);
                                                // modelT_Bus_WorkOrder.F_IsOverdue = 0;
                                                keyValuePairs3.Add("F_IsSms", 0);
                                                //  modelT_Bus_WorkOrder.F_IsSms = 0;
                                                keyValuePairs3.Add("F_WorkState", (int)EnumWorkState.reload);
                                                modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.reload;//重办中

                                                //  modelT_Bus_WorkOrder.F_IsExamine = 1;
                                                keyValuePairs3.Add("F_Identification", 2);
                                                //  modelT_Bus_WorkOrder.F_Identification = 1;
                                                keyValuePairs3.Add("F_Result", "");
                                                // modelT_Bus_WorkOrder.F_Result = "";
                                                keyValuePairs3.Add("F_DealDeptId", null);
                                                // modelT_Bus_WorkOrder.F_DealDeptId = null;
                                                keyValuePairs3.Add("F_DealUser", "");
                                                // modelT_Bus_WorkOrder.F_DealUser = "";
                                                keyValuePairs3.Add("F_DealTime", null);
                                                //   modelT_Bus_WorkOrder.F_DealTime = null;
                                                if (workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs3))
                                                {
                                                    var user = new BLL.T_Sys_UserAccount().GetModelList("F_DeptId in ('" + modelT_Bus_WorkOrder.F_MainDeptId + "') ");
                                                    if (user != null && user.Count > 0)
                                                    {
                                                        foreach (var it in user)
                                                        {
                                                            string count = "你有退回重办工单：" + modelT_Bus_WorkOrder.F_WorkOrderId + "，请及时查收处理";
                                                            // string msg = modelT_Bus_WorkOrder.F_WorkOrderId;
                                                            //  bool v = SMSController.AddSmS(0, msg, count, it.F_Mobile, "196362", "");

                                                            string mag = "[\"" + modelT_Bus_WorkOrder.F_WorkOrderId + "\"]";
                                                            string v = SmsNewController.AddSmS(0, count, it.F_Mobile,
                                                    "681240339285540864", mag, modelT_Bus_WorkOrder.F_WorkOrderId);
                                                        }
                                                    }
                                                    #region 插入操作记录

                                                    #region 20191021调整为多个主办单位时调整

                                                    #endregion
                                                    opt = "于" + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒") + "退回重办";
                                                    cbreasons = "，重办原因：" + cbreason;
                                                    #endregion

                                                }
                                                #endregion

                                            }
                                            else
                                            {
                                                return Error("退回失败");
                                            }



                                        }
                                       
                                    }
                                }
                                #region 插入操作记录
                                Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                                oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                oper.F_AssignedId = modelT_Bus_ToExamine.F_AssignedId;
                                oper.F_State = modelT_Bus_WorkOrder.F_WorkState;
                                string userinfo = User.depname + "(" + User.F_UserCode + ")";

                                oper.F_Message = userinfo + " " + opt + "了工单" + cbreasons;
                                oper.F_CreateUser = User.F_UserCode;
                                oper.F_CreateTime = DateTime.Now;
                                oper.F_IsDelete = 0;

                                operBLL.Add(oper);

                                //推送消息表
                                #endregion




                            }
                            trans.Complete();
                        }
                        return Success("操作成功", modelT_Bus_ToExamine.F_ID);
                    }
                    else
                    {
                        return Error("已经审核过了");
                    }
                }
                else
                {
                    return Error("工单不存在");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }

        /// <summary>
        /// 交办工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult AssignWorkOrder()
        {

            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG"  || User.F_RoleCode == "MTDD")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int state = RequestString.GetInt("state", 0);
                int assignid = RequestString.GetInt("assignid", 0);
                int maindeptid = RequestString.GetInt("maindeptid", 0);
                //string maindeptid = RequestString.GetFormString("maindeptid");
                string otherdeptids = RequestString.GetFormString("otherdeptids");
                DateTime limittime = DateTime.Parse(RequestString.GetFormString("limittime") + " 23:59:59");
                string assignedopinion = RequestString.GetFormString("assignedopinion");

                var modelT_Bus_AssignedInfoLasts = assignBLL.GetList(0, $" F_WorkOrderId='{workorderid}' and F_IsDelete='0' and  F_State='1' ", " F_CreateTime desc").Tables[0];
                if (modelT_Bus_AssignedInfoLasts.Rows.Count > 0)
                {
                    if (modelT_Bus_AssignedInfoLasts.Rows[0]["F_CreateUser"].ToString() != User.F_UserCode)
                    {
                        return Error("操作失败");
                    }
                }

                if (!string.IsNullOrEmpty(otherdeptids))
                {
                    if (otherdeptids.Split(',').Contains(maindeptid.ToString()))
                    {
                        return Error("主办单位不能出现在协办单位");
                    }
                }
                if (limittime < DateTime.Now)
                {
                    return Error("办理时限不能小于当前时间");
                }

                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = new Model.T_Bus_AssignedInfo();
                var deptinfo = new BLL.T_Sys_Department().GetModel(maindeptid);
                if (modelT_Bus_WorkOrder != null && deptinfo != null)
                {
                    //if (modelT_Bus_WorkOrder.F_WorkState == 1)
                    //if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.submit)
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.submit)
                    {
                        int aid = 0;
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            if (assignid == 0)
                            {
                                #region 插入交办记录
                                modelT_Bus_AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                modelT_Bus_AssignedInfo.F_LimitTime = limittime;//办理时限
                                modelT_Bus_AssignedInfo.F_MainDeptId = maindeptid;//主办单位id
                                modelT_Bus_AssignedInfo.F_OtherDeptIds = otherdeptids;//协办单位id
                                modelT_Bus_AssignedInfo.F_AssignedOpinion = assignedopinion;//交办意见

                                modelT_Bus_AssignedInfo.F_State = state;//0草稿  1正式
                                modelT_Bus_AssignedInfo.F_CreateUser = User.F_UserCode;
                                modelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                                modelT_Bus_AssignedInfo.F_IsDelete = 0;
                                modelT_Bus_AssignedInfo.F_IsOverdue = 0;
                                modelT_Bus_AssignedInfo.F_IsSure = 0;
                                modelT_Bus_AssignedInfo.F_IsReload = 0;
                                modelT_Bus_AssignedInfo.F_IsNext = 0;
                                modelT_Bus_AssignedInfo.F_TimeResp = assignBLL.GetRepTimly(DateTime.Now);//及时查收时间点
                                aid = assignBLL.Add(modelT_Bus_AssignedInfo);

                                #endregion
                            }
                            else
                            {
                                #region 修改交办记录
                                modelT_Bus_AssignedInfo = assignBLL.GetModel(assignid);
                                if (modelT_Bus_AssignedInfo != null)
                                {
                                    modelT_Bus_AssignedInfo.F_LimitTime = limittime;//办理时限
                                    modelT_Bus_AssignedInfo.F_MainDeptId = maindeptid;//主办单位id
                                    modelT_Bus_AssignedInfo.F_OtherDeptIds = otherdeptids;//协办单位id
                                    modelT_Bus_AssignedInfo.F_AssignedOpinion = assignedopinion;//交办意见
                                    modelT_Bus_AssignedInfo.F_TimeResp = assignBLL.GetRepTimly(DateTime.Now);//及时查收时间点
                                    modelT_Bus_AssignedInfo.F_State = state;//0草稿  1正式
                                    modelT_Bus_AssignedInfo.F_CreateUser = User.F_UserCode;
                                    modelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                                    assignBLL.Update(modelT_Bus_AssignedInfo);
                                    aid = modelT_Bus_AssignedInfo.F_Id;
                                }

                                #endregion
                            }

                            if (modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_State == 1)
                            {
                                #region 保存工单信息
                                //modelT_Bus_WorkOrder.F_WorkState = 2;//待查收
                                modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.receive;//待查收
                                modelT_Bus_WorkOrder.F_LimitTime = limittime;
                                modelT_Bus_WorkOrder.F_MainDeptId = maindeptid;
                                modelT_Bus_WorkOrder.F_OtherDeptIds = otherdeptids;
                                modelT_Bus_WorkOrder.F_AssignUser = User.F_UserCode;
                                modelT_Bus_WorkOrder.F_AssignTime = DateTime.Now;
                                workorderBLL.Update(modelT_Bus_WorkOrder);
                                #endregion

                                #region 删除草稿信息
                                var cglist = assignBLL.GetModelList(" F_IsDelete=0 and F_State=0 and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "'");

                                foreach (var cg in cglist)
                                {
                                    cg.F_IsDelete = 1;
                                    cg.F_DeleteUser = User.F_UserCode;
                                    cg.F_DeleteTime = DateTime.Now;

                                    assignBLL.Update(cg);
                                }
                                #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 + " 交办了工单，主办单位：" + deptinfo.F_DeptName;
                                if (!string.IsNullOrEmpty(otherdeptids))
                                {
                                    string sql = "select dbo.GetDeptNames('" + otherdeptids + "')";
                                    oper.F_Message += "，协办单位：" + DbHelperSQL.GetSingle(sql);
                                }
                                oper.F_CreateUser = User.F_UserCode;
                                oper.F_CreateTime = DateTime.Now;
                                oper.F_IsDelete = 0;

                                operBLL.Add(oper);

                                //推送消息表
                                var users = userBLL.GetModelList(" F_DeptId='" + deptinfo.F_DeptId + "' ");

                                foreach (var u in users)
                                {
                                    msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, u.F_UserCode, User.F_UserCode, (int)EnumSmsType.workorder);
                                }
                              
                                #endregion
                            }

                            trans.Complete();
                        }
                        return Success("操作成功", modelT_Bus_AssignedInfo.F_Id);
                    }
                    else
                    {
                        return Error("已经交办过了");
                    }
                }
                else
                {
                    return Error("操作失败");
                }

            }
            else
            {
                return Error("权限不足");
            }
        }

        /// <summary>
        /// 派工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public string SplitOrder(Model.T_Bus_WorkOrder modelT_Bus_WorkOrder
            , Model.T_Sys_Department deptinfo, DateTime limittime, Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo, string assignedopinion)
        {

            Model.T_Bus_AssignedInfo_Next modelT_Bus_AssignedInfo_Next = new Model.T_Bus_AssignedInfo_Next();
            if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo != null && deptinfo != null)
            {

                if (modelT_Bus_AssignedInfo.F_IsNext == null || modelT_Bus_AssignedInfo.F_IsNext.Value == 0 || modelT_Bus_AssignedInfo.F_IsNext.Value == 4)
                {
                    // using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                    using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                    {

                        #region 插入派单记录
                        modelT_Bus_AssignedInfo_Next.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                        modelT_Bus_AssignedInfo_Next.F_LimitTime = limittime;//办理时限
                                                                             //  modelT_Bus_AssignedInfo_Next.F_LimitTime = modelT_Bus_AssignedInfo.F_LimitTime ;
                        modelT_Bus_AssignedInfo_Next.F_MainDeptId = deptinfo.F_DeptId;//主办单位id

                        modelT_Bus_AssignedInfo_Next.F_OtherDeptIds = "";
                        modelT_Bus_AssignedInfo_Next.F_AssignedOpinion = assignedopinion;//交办意见
                        modelT_Bus_AssignedInfo_Next.F_State = 1;//0草稿  1正式
                        modelT_Bus_AssignedInfo_Next.F_CreateUser = User.F_UserCode;
                        modelT_Bus_AssignedInfo_Next.F_CreateTime = DateTime.Now;
                        modelT_Bus_AssignedInfo_Next.F_IsDelete = 0;
                        modelT_Bus_AssignedInfo_Next.F_IsOverdue = 0;
                        modelT_Bus_AssignedInfo_Next.F_IsSure = 0;
                        modelT_Bus_AssignedInfo_Next.F_IsReload = 0;
                        modelT_Bus_AssignedInfo_Next.F_Id = new BLL.T_Bus_AssignedInfo_Next().Add(modelT_Bus_AssignedInfo_Next);
                        #endregion


                        if (modelT_Bus_AssignedInfo_Next != null && modelT_Bus_AssignedInfo_Next.F_State == 1)
                        {
                            #region 保存交办信息
                            modelT_Bus_AssignedInfo.F_IsNext = 1;
                            modelT_Bus_AssignedInfo.F_NextUser = User.F_UserCode;
                            modelT_Bus_AssignedInfo.F_NextTime = DateTime.Now;
                            new BLL.T_Bus_AssignedInfo().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_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                            oper.F_State = 4;

                            string userinfo = User.depname + "(" + User.F_UserCode + ")";
                            oper.F_Message = userinfo + " 派单给单位：" + deptinfo.F_DeptName;
                            oper.F_CreateUser = User.F_UserCode;
                            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, User.F_UserCode, (int)EnumSmsType.workorder);
                            #endregion
                        }
                        trans.Complete();
                    }
                    var user = new BLL.T_Sys_UserAccount().GetModelList(" F_DeptId=" + deptinfo.F_DeptId + "  ");
                    if (user != null && user.Count > 0)
                    {
                        foreach (var it in user)
                        {
                            if (it.F_RoleCode == "WLDW" && it.F_IsSms != null && it.F_IsSms == 1)
                            {
                                continue;
                            }
                            string count = "你有新工单：" + modelT_Bus_WorkOrder.F_WorkOrderId + "，请及时查收处理。";
                            //string msg = modelT_Bus_WorkOrder.F_WorkOrderId;
                            //bool n = SMSController.AddSmS(0, msg, count, it.F_Mobile, "153305", "");
                            string mag = "[\"" + modelT_Bus_WorkOrder.F_WorkOrderId + "\"]";
                            string v = SmsNewController.AddSmS(0, count, it.F_Mobile, "681240888655478784", mag,
                            modelT_Bus_WorkOrder.F_WorkOrderId);

                        }

                    }
                    //二级单位给三级单位转派都有短信提醒

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

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

        public async Task SplitOrderNew(Model.T_Bus_WorkOrder modelT_Bus_WorkOrder
            , Model.T_Sys_Department deptinfo, DateTime limittime, Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo, string assignedopinion, Model.T_Sys_UserAccount Users)
        {

            Model.T_Bus_AssignedInfo_Next modelT_Bus_AssignedInfo_Next = new Model.T_Bus_AssignedInfo_Next();
            if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo != null && deptinfo != null)
            {

                if (modelT_Bus_AssignedInfo.F_IsNext == null || modelT_Bus_AssignedInfo.F_IsNext.Value == 0 || modelT_Bus_AssignedInfo.F_IsNext.Value == 4)
                {

                    #region 插入派单记录
                    modelT_Bus_AssignedInfo_Next.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                    modelT_Bus_AssignedInfo_Next.F_LimitTime = limittime;//办理时限
                    modelT_Bus_AssignedInfo_Next.F_MainDeptId = deptinfo.F_DeptId;//主办单位id

                    modelT_Bus_AssignedInfo_Next.F_OtherDeptIds = "";
                    modelT_Bus_AssignedInfo_Next.F_AssignedOpinion = assignedopinion;//交办意见
                    modelT_Bus_AssignedInfo_Next.F_State = 1;//0草稿  1正式
                    modelT_Bus_AssignedInfo_Next.F_CreateUser = Users.F_UserCode;
                    modelT_Bus_AssignedInfo_Next.F_CreateTime = DateTime.Now;
                    modelT_Bus_AssignedInfo_Next.F_IsDelete = 0;
                    modelT_Bus_AssignedInfo_Next.F_IsOverdue = 0;
                    modelT_Bus_AssignedInfo_Next.F_IsSure = 0;
                    modelT_Bus_AssignedInfo_Next.F_IsReload = 0;

                    modelT_Bus_AssignedInfo_Next.F_Id = new BLL.T_Bus_AssignedInfo_Next().Add(modelT_Bus_AssignedInfo_Next);
                    #endregion

                    string userinfo = Users.depname + "(" + Users.F_UserCode + ")";
                    string message = userinfo + " 派单给单位：" + deptinfo.F_DeptName;
                    if (modelT_Bus_AssignedInfo_Next.F_Id > 0)
                    {
                        await Task.Run(() =>
                        {
                            #region 保存工单信息
                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            keyValuePairs.Add("F_MainDeptID3", deptinfo.F_DeptId.ToString());
                            modelT_Bus_WorkOrder.F_MainDeptID3 = deptinfo.F_DeptId.ToString();
                            if (modelT_Bus_WorkOrder.F_WorkState == 11|| modelT_Bus_WorkOrder.F_WorkState ==8)
                            {
                                keyValuePairs.Add("F_WorkState", 8);
                                modelT_Bus_WorkOrder.F_WorkState = 8 ;
                            }
                            else
                            {
                                keyValuePairs.Add("F_WorkState", 4);
                                modelT_Bus_WorkOrder.F_WorkState = 4;
                            }
                            
                            new BLL.T_Bus_WorkOrder().UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);

                            modelT_Bus_AssignedInfo.F_IsNext = 1;
                            modelT_Bus_AssignedInfo.F_NextUser = Users.F_UserCode;
                            modelT_Bus_AssignedInfo.F_NextTime = DateTime.Now;
                            new BLL.T_Bus_AssignedInfo().Update(modelT_Bus_AssignedInfo);
                            #endregion
                        });
                        await Task.Run(() =>
                        {
                            #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 = 4;
                            oper.F_Message = message;
                            oper.F_CreateUser = Users.F_UserCode;
                            oper.F_CreateTime = DateTime.Now;
                            oper.F_IsDelete = 0;
                            operBLL.Add(oper);
                            #region 短信通知
                            var user = new BLL.T_Sys_UserAccount().GetModelList(" F_DeptId=" + deptinfo.F_DeptId + "  ");
                            if (user != null && user.Count > 0)
                            {
                                foreach (var it in user)
                                {
                                    if (it.F_RoleCode == "WLDW" && it.F_IsSms != null && it.F_IsSms == 1)
                                    {
                                        continue;
                                    }
                                    string count = "你有新工单：" + modelT_Bus_WorkOrder.F_WorkOrderId + "，请及时查收处理。";
                                    //string msg = modelT_Bus_WorkOrder.F_WorkOrderId;
                                  //  bool n = SMSController.AddSmS(0, msg, count, it.F_Mobile, "153305", "");
                                  string mag = "[\"" + modelT_Bus_WorkOrder.F_WorkOrderId + "\"]";
                                    string v = SmsNewController.AddSmS(0, count, it.F_Mobile, "681240888655478784", mag,
                                    modelT_Bus_WorkOrder.F_WorkOrderId);


                                }
                            }
                            #endregion
                            #endregion
                        });
                        await Task.Run(() =>
                        {
                            #region 插入推送消息
                            msg.AddInternalMessagesInfo("工单消息", message + "，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId, modelT_Bus_WorkOrder.F_CreateUser, Users.F_UserCode, (int)EnumSmsType.workorder);
                            #endregion
                        });

                    }
                }
            }
        }

        /// <summary>
        /// 派工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult SplitWorkOrder()
        {

            if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int maindeptid = RequestString.GetInt("maindeptid", 0);
                string otherdeptids = RequestString.GetFormString("otherdeptids");
                DateTime limittime = DateTime.Parse(RequestString.GetFormString("limittime") + " 23:59:59");
                string assignedopinion = RequestString.GetFormString("assignedopinion");
                string files = RequestString.GetFormString("files");
                int state = RequestString.GetInt("state", 0);
                int nextid = RequestString.GetInt("nextid", 0);
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                Model.T_Bus_AssignedInfo_Next modelT_Bus_AssignedInfo_Next = new Model.T_Bus_AssignedInfo_Next();
                var deptinfo = new BLL.T_Sys_Department().GetModel(maindeptid);
                if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo != null && deptinfo != null)
                {
                    if (limittime > modelT_Bus_AssignedInfo.F_LimitTime)
                    {
                        return Error("办理时限不能大于当前办理时限");
                    }
                    int type = AssignDeptType(modelT_Bus_AssignedInfo, User.F_DeptId);
                    if ((type == 1 && (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.dealing || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.reload)) || (User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG"))
                    {
                        if (modelT_Bus_AssignedInfo.F_IsNext == null || modelT_Bus_AssignedInfo.F_IsNext.Value == 0 || modelT_Bus_AssignedInfo.F_IsNext.Value == 4)
                        {
                            // using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                            using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                            {
                                if (nextid == 0)
                                {
                                    #region 插入派单记录

                                    modelT_Bus_AssignedInfo_Next.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                    modelT_Bus_AssignedInfo_Next.F_LimitTime = limittime;//办理时限
                                                                                         //  modelT_Bus_AssignedInfo_Next.F_LimitTime = modelT_Bus_AssignedInfo.F_LimitTime ;
                                    modelT_Bus_AssignedInfo_Next.F_MainDeptId = maindeptid;//主办单位id
                                    if (otherdeptids.Trim() != "" && otherdeptids != "undefined")
                                        modelT_Bus_AssignedInfo_Next.F_OtherDeptIds = otherdeptids;//协办单位id
                                    else
                                        modelT_Bus_AssignedInfo_Next.F_OtherDeptIds = "";
                                    modelT_Bus_AssignedInfo_Next.F_AssignedOpinion = assignedopinion;//交办意见

                                    modelT_Bus_AssignedInfo_Next.F_State = state;//0草稿  1正式
                                    modelT_Bus_AssignedInfo_Next.F_CreateUser = User.F_UserCode;
                                    modelT_Bus_AssignedInfo_Next.F_CreateTime = DateTime.Now;
                                    modelT_Bus_AssignedInfo_Next.F_IsDelete = 0;
                                    modelT_Bus_AssignedInfo_Next.F_IsOverdue = 0;
                                    modelT_Bus_AssignedInfo_Next.F_IsSure = 0;
                                    modelT_Bus_AssignedInfo_Next.F_IsReload = 0;
                                    modelT_Bus_AssignedInfo_Next.F_Id = new BLL.T_Bus_AssignedInfo_Next().Add(modelT_Bus_AssignedInfo_Next);
                                    #endregion
                                }
                                else
                                {
                                    #region 修改派单记录
                                    modelT_Bus_AssignedInfo_Next = new BLL.T_Bus_AssignedInfo_Next().GetModel(nextid);
                                    if (modelT_Bus_AssignedInfo_Next != null)
                                    {
                                        modelT_Bus_AssignedInfo_Next.F_LimitTime = limittime;//办理时限
                                                                                             //modelT_Bus_AssignedInfo_Next.F_LimitTime = modelT_Bus_AssignedInfo.F_LimitTime;
                                        modelT_Bus_AssignedInfo_Next.F_MainDeptId = maindeptid;//主办单位id

                                        if (otherdeptids.Trim() != "" && otherdeptids != "undefined")
                                            modelT_Bus_AssignedInfo_Next.F_OtherDeptIds = otherdeptids;//协办单位id
                                        else
                                            modelT_Bus_AssignedInfo_Next.F_OtherDeptIds = "";
                                        modelT_Bus_AssignedInfo_Next.F_AssignedOpinion = assignedopinion;//交办意见

                                        modelT_Bus_AssignedInfo_Next.F_State = state;//0草稿  1正式
                                        modelT_Bus_AssignedInfo_Next.F_CreateUser = User.F_UserCode;
                                        modelT_Bus_AssignedInfo_Next.F_CreateTime = DateTime.Now;
                                        new BLL.T_Bus_AssignedInfo_Next().Update(modelT_Bus_AssignedInfo_Next);
                                    }
                                    #endregion
                                }
                                if (modelT_Bus_AssignedInfo_Next != null && modelT_Bus_AssignedInfo_Next.F_State == 1)
                                {
                                    #region 保存交办信息
                                    modelT_Bus_AssignedInfo.F_IsNext = 1;
                                    modelT_Bus_AssignedInfo.F_NextUser = User.F_UserCode;
                                    modelT_Bus_AssignedInfo.F_NextTime = DateTime.Now;
                                    new BLL.T_Bus_AssignedInfo().Update(modelT_Bus_AssignedInfo);
                                    #endregion
                                    #region 保存工单信息
                                    Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                                    keyValuePairs.Add("F_MainDeptID3", maindeptid.ToString());
                                    //modelT_Bus_WorkOrder.F_MainDeptID3 = maindeptid.ToString();
                                    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_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 + " 派单给单位：" + deptinfo.F_DeptName;
                                    oper.F_CreateUser = User.F_UserCode;
                                    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, User.F_UserCode, (int)EnumSmsType.workorder);
                                    #endregion
                                }
                                trans.Complete();
                            }
                            var user = new BLL.T_Sys_UserAccount().GetModelList(" F_DeptId=" + maindeptid + "  ");
                            if (user != null && user.Count > 0)
                            {
                                foreach (var it in user)
                                {
                                    if (it.F_RoleCode == "WLDW" && it.F_IsSms != null && it.F_IsSms == 1)
                                    {
                                        continue;
                                    }
                                    string count = "你有新工单：" + workorderid + "，请及时查收处理。";
                                    // string msg = workorderid;
                                    //  bool n = SMSController.AddSmS(0, msg, count, it.F_Mobile, "153305", "");
                                    string mag = "[\"" + workorderid + "\"]";
                                    string v = SmsNewController.AddSmS(0, count, it.F_Mobile, "681240888655478784", mag,
                                   workorderid);
                                }

                            }
                            //二级单位给三级单位转派都有短信提醒

                            return Success("操作成功", modelT_Bus_AssignedInfo_Next.F_Id);
                        }
                        else
                        {
                            return Error("已经派过单了");
                        }
                    }
                    else
                    {
                        return Error("操作失败");
                    }
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }

        /// <summary>
        ///催单短信
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult Reminders(string workorderid)
        {
            List<T_Bus_WorkOrder> workorder = new List<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.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, User.F_UserCode, (int)EnumSmsType.additional);
                        if (!string.IsNullOrEmpty(iv.F_Mobile))
                        {
                            string count = "您的工单" + workorderid + "收到催办，请及时处理！";
                           // string msg = workorderid;
                            //bool n = SMSController.AddSmS(0, msg, count, iv.F_Mobile, "165151", "", workorderid);
                            string mag = "[\"" + workorderid + "\"]";
                            string v = SmsNewController.AddSmS(0, count, iv.F_Mobile, "681240804383522816", mag,
                            workorderid);
                        }
                    }
                }

            }
            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, User.F_UserCode, (int)EnumSmsType.additional);
                        if (!string.IsNullOrEmpty(iv.F_Mobile))
                        {
                            string count = "您的工单" + workorderid + "收到催办，请及时处理！";
                            // string msg = workorderid;
                            // bool n = SMSController.AddSmS(0, msg, count, iv.F_Mobile, "165151", "", workorderid);
                            string mag = "[\"" + workorderid + "\"]";
                            string v = SmsNewController.AddSmS(0, count, iv.F_Mobile, "681240804383522816", mag,
                            workorderid);
                        }
                    }
                }
            }
            return Success("发送成功");
        }
      

        /// <summary>
        /// 撤回待审核转办
        /// 话务员操作撤回自己提交的工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult WithdrawDWorkOrder()
        {




            if (User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "GLY")
            {
                string workorderid = RequestString.GetFormString("workorderid");

                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);

                if (modelT_Bus_WorkOrder != null && modelT_Bus_WorkOrder.F_CreateUser == User.F_UserCode && modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.submit)
                {

                    using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                    {
                        #region 保存工单信息
                        Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                        keyValuePairs.Add("F_WorkState",0);
                        modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.neworder;
                        workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);
                        #endregion

                        #region 插入操作记录
                        string userinfo = User.depname + "(" + User.F_UserCode + ")";
                        string msg = userinfo + " 撤回了工单";

                        addoptlog(modelT_Bus_WorkOrder.F_WorkOrderId, modelT_Bus_WorkOrder.F_WorkState, 0, msg, User.F_UserCode);
                        #endregion

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

                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }
        /// <summary>
        /// 收回工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult TakeBackWorkOrder()
        {

            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD" || User.F_RoleCode == "DBZY")
            {
                string workorderid = RequestString.GetFormString("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 && modelT_Bus_AssignedInfo != null)
                {

                    //if (modelT_Bus_AssignedInfo.F_IsSure == 0 || (modelT_Bus_AssignedInfo.F_IsSure == 1 && modelT_Bus_WorkOrder.F_WorkState == 4))
                    if (modelT_Bus_AssignedInfo.F_IsSure == 0 || (modelT_Bus_AssignedInfo.F_IsSure == 1 && modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.dealing))
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            #region 插入交办记录
                            Model.T_Bus_AssignedInfo AssignedInfo = new Model.T_Bus_AssignedInfo();
                            AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                            AssignedInfo.F_LimitTime = modelT_Bus_AssignedInfo.F_LimitTime;//办理时限
                            AssignedInfo.F_MainDeptId = modelT_Bus_AssignedInfo.F_MainDeptId;//主办单位id
                            AssignedInfo.F_OtherDeptIds = modelT_Bus_AssignedInfo.F_OtherDeptIds;//协办单位id
                            AssignedInfo.F_AssignedOpinion = modelT_Bus_AssignedInfo.F_AssignedOpinion;//交办意见

                            AssignedInfo.F_State = 0;//0草稿  1正式
                            AssignedInfo.F_CreateUser = modelT_Bus_AssignedInfo.F_CreateUser;
                            AssignedInfo.F_CreateTime = modelT_Bus_AssignedInfo.F_CreateTime;
                            AssignedInfo.F_IsDelete = 0;
                            AssignedInfo.F_IsOverdue = 0;
                            AssignedInfo.F_IsSure = 0;
                            AssignedInfo.F_IsReload = 0;
                            AssignedInfo.F_IsNext = 0;

                            assignBLL.Add(AssignedInfo);

                            #endregion

                            #region 保存工单信息
                            //modelT_Bus_WorkOrder.F_WorkState = 1;//待交办
                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            keyValuePairs.Add("F_WorkState", (int)EnumWorkState.submit);
                            modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.submit;//待交办
                            keyValuePairs.Add("F_MainDeptId", null);
                            // modelT_Bus_WorkOrder.F_MainDeptId = null;
                            keyValuePairs.Add("F_OtherDeptIds", "");
                         //   modelT_Bus_WorkOrder.F_OtherDeptIds = "";
                            workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);
                            #endregion

                            #region 删除交办信息
                            modelT_Bus_AssignedInfo.F_IsDelete = 1;//删除
                            modelT_Bus_AssignedInfo.F_DeleteUser = User.F_UserCode;
                            modelT_Bus_AssignedInfo.F_DeleteTime = DateTime.Now;
                            assignBLL.Update(modelT_Bus_AssignedInfo);
                            #endregion

                            #region 删除派单信息
                            var pdlist = new BLL.T_Bus_AssignedInfo_Next().GetModelList(" F_IsDelete=0 and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' ");

                            foreach (var cg in pdlist)
                            {
                                cg.F_IsDelete = 1;
                                cg.F_DeleteUser = User.F_UserCode;
                                cg.F_DeleteTime = DateTime.Now;

                                new BLL.T_Bus_AssignedInfo_Next().Update(cg);
                            }
                            #endregion

                            #region 删除二级单位处理信息
                            var cglist = new BLL.T_Bus_Feedback_Next().GetModelList(" F_IsDelete=0 and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' ");

                            foreach (var cg in cglist)
                            {
                                cg.F_IsDelete = 1;
                                cg.F_DeleteUser = User.F_UserCode;
                                cg.F_DeleteTime = DateTime.Now;

                                new BLL.T_Bus_Feedback_Next().Update(cg);
                            }
                            #endregion
                          var   modelT_Bus_RemindRecord = new BLL.T_Bus_RemindRecord().GetModelList(" F_State !=2  and F_IsDelete = 0 and F_Type = 1 and F_WorkOrderId = '" 
                       + modelT_Bus_WorkOrder.F_WorkOrderId + "' order by F_CreateTime desc").FirstOrDefault();
                            if (modelT_Bus_RemindRecord!=null )
                            {
                                modelT_Bus_RemindRecord.F_State = 0;
                                new BLL.T_Bus_RemindRecord().Update(modelT_Bus_RemindRecord);
                            }
                            #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);
                            #endregion

                            trans.Complete();
                        }
                        return Success("操作成功");
                    }
                    else
                    {
                        return Error("单位已查收，不能收回");
                    }
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }

        /// <summary>
        /// 查收工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult ReceiveWorkOrder()
        {

            if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("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 && modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_MainDeptId == User.F_DeptId)
                if (modelT_Bus_WorkOrder != null && (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.receive || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.reload) && modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_MainDeptId == User.F_DeptId)
                {
                    if (modelT_Bus_AssignedInfo.F_IsSure == 0)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            #region 保存工单信息
                            //modelT_Bus_WorkOrder.F_WorkState = 4;//办理中
                          //  int n = DbHelperSQL.ExecuteSql(" update T_Bus_WorkOrder set F_WorkState=4 where F_Id ='" + modelT_Bus_WorkOrder .F_Id + "'");
                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            keyValuePairs.Add("F_WorkState", 4);
                            workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);

                              modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.dealing;//办理中
                            //   workorderBLL.Update(modelT_Bus_WorkOrder);
                            #endregion

                            #region 保存查收信息
                            modelT_Bus_AssignedInfo.F_IsSure = 1;//查收
                            modelT_Bus_AssignedInfo.F_SureUser = User.F_UserCode;
                            modelT_Bus_AssignedInfo.F_SureTime = DateTime.Now;
                            assignBLL.Update(modelT_Bus_AssignedInfo);
                            #endregion

                            #region 保存明细信息
                            if (!string.IsNullOrEmpty(modelT_Bus_AssignedInfo.F_OtherDeptIds))
                            {
                                string[] strids = modelT_Bus_AssignedInfo.F_OtherDeptIds.Split(',');
                                foreach (string strid in strids)
                                {
                                    Model.T_Bus_AssignedItemInfo modelT_Bus_AssignedItemInfo = new Model.T_Bus_AssignedItemInfo();
                                    modelT_Bus_AssignedItemInfo.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                                    modelT_Bus_AssignedItemInfo.F_AssignedOpinion = modelT_Bus_AssignedInfo.F_AssignedOpinion;
                                    modelT_Bus_AssignedItemInfo.F_DeptId = Int32.Parse(strid);
                                    modelT_Bus_AssignedItemInfo.F_LimitTime = modelT_Bus_AssignedInfo.F_LimitTime;
                                    modelT_Bus_AssignedItemInfo.F_Remark = modelT_Bus_AssignedInfo.F_Remark;
                                    modelT_Bus_AssignedItemInfo.F_State = 1;
                                    modelT_Bus_AssignedItemInfo.F_Type = 2;
                                    modelT_Bus_AssignedItemInfo.F_WorkOrderId = modelT_Bus_AssignedInfo.F_WorkOrderId;
                                    modelT_Bus_AssignedItemInfo.F_IsSure = 0;
                                    modelT_Bus_AssignedItemInfo.F_CreateTime = DateTime.Now;
                                    modelT_Bus_AssignedItemInfo.F_CreateUser = User.F_UserCode;
                                    modelT_Bus_AssignedItemInfo.F_IsDelete = 0;

                                    new BLL.T_Bus_AssignedItemInfo().Add(modelT_Bus_AssignedItemInfo);

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

                          int n=  operBLL.Add(oper);

                          
                            #endregion

                            trans.Complete();
                        }
                        return Success("操作成功");
                    }
                    else
                    {
                        return Error("单位已查收，不能再次查收");
                    }
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }


        /// <summary>
        /// 审核退回重办
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult AuditWorkorders()
        {
           
            if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                string cbreason = RequestString.GetFormString("cbreason");
                int state= RequestString.GetInt ("state",0);
                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 && modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_MainDeptId == User.F_DeptId)
                if (modelT_Bus_WorkOrder != null  && modelT_Bus_AssignedInfo != null )
                {
                    if (state>0)
                    {
                        Dictionary<string, object> keyValuePairs3 = new Dictionary<string, object>();
                        keyValuePairs3.Add("F_WorkState", (int)EnumWorkState.reload);
                        modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.reload;//重办中
                        int n = Int32.Parse(DbHelperSQL.GetSingle("select count(1) from T_Bus_AssignedInfo WITH(NOLOCK) where F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and  F_State=1 and F_IsSure=1 and F_IsDelete=0 and isnull(F_IsReload,0)>0").ToString());
                        Model.T_Bus_AssignedInfo newmodelT_Bus_AssignedInfo = new Model.T_Bus_AssignedInfo();
                        newmodelT_Bus_AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                        DataTable dt = DbHelperSQL.Query("select top 6 F_OffDate from  T_Sys_WorkOFFDays  where F_OffState = 1   and F_OffDate>='" + DateTime.Now + "' order by F_OffDate ").Tables[0];
                        var resdatetime = dt.Rows[5]["F_OffDate"].ToString();
                        if (!string.IsNullOrEmpty(resdatetime))
                        {
                            newmodelT_Bus_AssignedInfo.F_LimitTime = DateTime.Parse(resdatetime.Split(' ')[0] + " 23:59:59");//办理时限
                        }
                        newmodelT_Bus_AssignedInfo.F_MainDeptId = modelT_Bus_WorkOrder.F_MainDeptId;//主办单位id
                        newmodelT_Bus_AssignedInfo.F_OtherDeptIds = "";//协办单位id
                        newmodelT_Bus_AssignedInfo.F_AssignedOpinion = "";//交办意见
                        newmodelT_Bus_AssignedInfo.F_State = 1;
                        newmodelT_Bus_AssignedInfo.F_CreateUser = User.F_UserCode;
                        newmodelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                        newmodelT_Bus_AssignedInfo.F_IsDelete = 0;
                        newmodelT_Bus_AssignedInfo.F_IsOverdue = 0;
                        newmodelT_Bus_AssignedInfo.F_IsSure = 0;
                        newmodelT_Bus_AssignedInfo.F_IsReload = n + 1;
                        newmodelT_Bus_AssignedInfo.F_ReloadUser = User.F_UserCode;
                        newmodelT_Bus_AssignedInfo.F_ReloadTime = DateTime.Now;
                        newmodelT_Bus_AssignedInfo.F_IsNext = 0;
                        newmodelT_Bus_AssignedInfo.F_Id = assignBLL.Add(newmodelT_Bus_AssignedInfo);
                        if (newmodelT_Bus_AssignedInfo.F_Id > 0)
                        {
                            #region 保存工单信息

                            //  modelT_Bus_WorkOrder.F_MainDeptId = modelT_Bus_WorkOrder.F_MainDeptId;
                            keyValuePairs3.Add("F_MainDeptId", modelT_Bus_WorkOrder.F_MainDeptId);
                            keyValuePairs3.Add("F_OtherDeptIds", modelT_Bus_WorkOrder.F_OtherDeptIds);
                            // modelT_Bus_WorkOrder.F_OtherDeptIds = modelT_Bus_WorkOrder.F_OtherDeptIds;
                            keyValuePairs3.Add("F_AssignUser", User.F_UserCode);
                            // modelT_Bus_WorkOrder.F_AssignUser = User.F_UserCode;
                            keyValuePairs3.Add("F_AssignTime", DateTime.Now);
                            //  modelT_Bus_WorkOrder.F_AssignTime = DateTime.Now;
                            if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.finish)
                            {
                                keyValuePairs3.Add("F_RemindDay", 1);
                                //   modelT_Bus_WorkOrder.F_RemindDay = 1;
                            }
                            keyValuePairs3.Add("F_IsReload", n + 1);
                            // modelT_Bus_WorkOrder.F_IsReload = n + 1;
                            if (!string.IsNullOrEmpty(resdatetime))
                                keyValuePairs3.Add("F_LimitTime", DateTime.Parse(resdatetime.Split(' ')[0] + " 23:59:59"));
                            keyValuePairs3.Add("F_IsOverdue", 0);
                            // modelT_Bus_WorkOrder.F_IsOverdue = 0;
                            keyValuePairs3.Add("F_IsSms", 0);
                            //  modelT_Bus_WorkOrder.F_IsSms = 0;

                          
                            //  modelT_Bus_WorkOrder.F_IsExamine = 1;
                            keyValuePairs3.Add("F_Identification", 1);
                            //  modelT_Bus_WorkOrder.F_Identification = 1;
                            keyValuePairs3.Add("F_Result", "");
                            // modelT_Bus_WorkOrder.F_Result = "";
                            keyValuePairs3.Add("F_DealDeptId", null);
                            // modelT_Bus_WorkOrder.F_DealDeptId = null;
                            keyValuePairs3.Add("F_DealUser", "");
                            // modelT_Bus_WorkOrder.F_DealUser = "";
                            keyValuePairs3.Add("F_DealTime", null);
                            //   modelT_Bus_WorkOrder.F_DealTime = null;
                            if (workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs3))
                            {
                                #region 插入操作记录

                                #region 20191021调整为多个主办单位时调整

                                #endregion
                              string  opt = "于" + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒") + "审核通过了退回重办";
                              string  cbreasons = "，审核原因：" + cbreason;

                                #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 + opt+ cbreasons;
                                oper.F_CreateUser = User.F_UserCode;
                                oper.F_CreateTime = DateTime.Now;
                                oper.F_IsDelete = 0;

                                int v = operBLL.Add(oper);

                                
                                #endregion
                                #endregion

                            }
                            #endregion
                        }
                        else
                        {
                            return Error("退回失败");
                        }
                    }
                    else
                    {
                        Dictionary<string, object> keyValuePairs3 = new Dictionary<string, object>();
                        keyValuePairs3.Add("F_WorkState", (int)EnumWorkState.dealed );
                        modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.dealed;
                        string opt = "于" + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒") + "审核拒绝了退回重办";
                        string cbreasons = "，审核原因：" + cbreason;

                        #region 插入操作记录
                        if (workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs3))
                        {
                            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 + opt + cbreasons;
                            oper.F_CreateUser = User.F_UserCode;
                            oper.F_CreateTime = DateTime.Now;
                            oper.F_IsDelete = 0;

                            int v = operBLL.Add(oper);
                        }

                        #endregion
                    }

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

        /// <summary>
        /// 退回工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult RebackWorkOrder()
        {
            if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                string backreason = RequestString.GetFormString("backreason");
                string file = RequestString.GetFormString("file");
                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 && modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_MainDeptId == User.F_DeptId)
                {
                    //  if (modelT_Bus_AssignedInfo.F_IsSure == 0)
                    // {
                    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", (int)EnumWorkState.auditreback);
                        modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.auditreback;//退回审核中
                        workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);
                        #endregion

                        #region 插入退回申请信息
                        Model.T_Bus_Feedback model_T_Bus_Feedback = new Model.T_Bus_Feedback();
                        model_T_Bus_Feedback.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;//工单编号
                        model_T_Bus_Feedback.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;//交办id
                        model_T_Bus_Feedback.F_Result = backreason;//退回原因
                        model_T_Bus_Feedback.F_IsAudit = 0;
                        model_T_Bus_Feedback.F_IsDelete = 0;
                        model_T_Bus_Feedback.F_CreateUser = User.F_UserCode;//退回人
                        model_T_Bus_Feedback.F_CreateTime = DateTime.Now;//退回时间
                        model_T_Bus_Feedback.F_CreateDeptId = User.F_DeptId;//退回部门
                        model_T_Bus_Feedback.F_IsFeedEnd = 1;
                        model_T_Bus_Feedback.F_State = 1;
                        model_T_Bus_Feedback.F_Type = 3;
                        model_T_Bus_Feedback.F_File = file;

                        new BLL.T_Bus_Feedback().Add(model_T_Bus_Feedback);
                        #endregion

                        #region 保存交办信息
                        //modelT_Bus_AssignedInfo.F_FeedbackTime = DateTime.Now;//办理 
                        //if (modelT_Bus_AssignedInfo.F_LimitTime < DateTime.Now)
                        //{
                        //    modelT_Bus_AssignedInfo.F_IsOverdue = 1;
                        //}
                        modelT_Bus_AssignedInfo.F_IsSure = 2;//申请退回
                        modelT_Bus_AssignedInfo.F_SureUser = User.F_UserCode;
                        modelT_Bus_AssignedInfo.F_SureTime = DateTime.Now;
                        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_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                        oper.F_State = modelT_Bus_WorkOrder.F_WorkState;

                        string userinfo = User.depname + "(" + User.F_UserCode + ")";
                        string message = "";
                        if (!string.IsNullOrEmpty(backreason))
                        {
                            message = "，退回原因:" + backreason;
                        }
                        oper.F_Message = userinfo + " 申请退回了工单"+ message;
                      
                        oper.F_CreateUser = User.F_UserCode;
                        oper.F_CreateTime = DateTime.Now;
                        oper.F_IsDelete = 0;

                        operBLL.Add(oper);

                        //推送消息表
                        msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, modelT_Bus_AssignedInfo.F_CreateUser, User.F_UserCode, (int)EnumSmsType.workorder);
                        #endregion

                        trans.Complete();
                    }
                    return Success("操作成功");
                    //  }
                    //  else
                    // {
                    //  return Error("单位已查收，不能退回");
                    //  }
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }

        /// <summary>
        /// 审核退回工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult AuditRebackWorkOrder()
        {


            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DBZY" || User.F_RoleCode == "DBGLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int state = RequestString.GetInt("state", 0);
                string reason = RequestString.GetFormString("reason");
                int isjb = RequestString.GetInt("isjb", 0);
                int rebackid = RequestString.GetInt("rebackid", 0);
                int zb = RequestString.GetInt("zb", 0);
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_Feedback modelT_Bus_Feedback = new BLL.T_Bus_Feedback().GetModel(rebackid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                Model.T_Bus_AssignedInfo_Next modelAssignedInfo_Next = new BLL.T_Bus_AssignedInfo_Next().GetNewModelByWorkOrderID(workorderid);
                Model.T_Bus_RemindRecord modelT_Bus_RemindRecord = new BLL.T_Bus_RemindRecord().GetNewModelByWorkOrderID(workorderid);


                if (modelT_Bus_WorkOrder != null && modelT_Bus_Feedback != null && modelT_Bus_AssignedInfo != null)
                {
                    //if (modelT_Bus_AssignedInfo.F_CreateUser != User.F_UserCode)
                    //{
                    //    return Error("操作失败");
                    //}
                    Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                    if (modelT_Bus_Feedback.F_Type == 3 && modelT_Bus_Feedback.F_IsAudit == 0)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            var rre = "";
                            #region 保存查收信息
                            modelT_Bus_Feedback.F_IsAudit = state;//审核
                            modelT_Bus_Feedback.F_AuditUser = User.F_UserCode;
                            modelT_Bus_Feedback.F_AuditTime = DateTime.Now;
                            modelT_Bus_Feedback.F_AuditReason = reason;
                            new BLL.T_Bus_Feedback().Update(modelT_Bus_Feedback);
                            #endregion
                            string strmsg = "同意";
                            if (modelT_Bus_Feedback.F_IsAudit == 1)
                            {

                                #region 插入交办记录
                                Model.T_Bus_AssignedInfo AssignedInfo = new Model.T_Bus_AssignedInfo();
                                AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                AssignedInfo.F_LimitTime = modelT_Bus_AssignedInfo.F_LimitTime;//办理时限
                                AssignedInfo.F_MainDeptId = modelT_Bus_AssignedInfo.F_MainDeptId;//主办单位id
                                AssignedInfo.F_OtherDeptIds = modelT_Bus_AssignedInfo.F_OtherDeptIds;//协办单位id
                                AssignedInfo.F_AssignedOpinion = modelT_Bus_AssignedInfo.F_AssignedOpinion;//交办意见

                                AssignedInfo.F_State = 0;//0草稿  1正式
                                AssignedInfo.F_CreateUser = modelT_Bus_AssignedInfo.F_CreateUser;
                                AssignedInfo.F_CreateTime = modelT_Bus_AssignedInfo.F_CreateTime;
                                AssignedInfo.F_IsDelete = 0;
                                AssignedInfo.F_IsOverdue = 0;
                                AssignedInfo.F_IsSure = 0;
                                AssignedInfo.F_IsNext = 0;
                                AssignedInfo.F_IsReload = modelT_Bus_AssignedInfo.F_IsReload;
                                assignBLL.Add(AssignedInfo);
                                #endregion
                                #region 保存交办信息
                                modelT_Bus_AssignedInfo.F_IsSure = 3;//退回
                                assignBLL.Update(modelT_Bus_AssignedInfo);
                                #endregion
                                #region 保存工单信息
                                //modelT_Bus_WorkOrder.F_WorkState = 1;//待交办
                                keyValuePairs.Add("F_MainDeptId", null);
                                // modelT_Bus_WorkOrder.F_MainDeptId = null;
                                keyValuePairs.Add("F_IsSendBack", 1);
                                // modelT_Bus_WorkOrder.F_IsSendBack = 1;
                                keyValuePairs.Add("F_WorkState", (int)EnumWorkState.submit);
                                keyValuePairs.Add("F_LimitTime", null);
                               modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.submit;//待交办
                                workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);
                                #endregion
                                if (modelAssignedInfo_Next != null)
                                {
                                    modelAssignedInfo_Next.F_State = 2;
                                    new BLL.T_Bus_AssignedInfo_Next().Update(modelAssignedInfo_Next);
                                }

                                if (zb==0)
                                {if (modelT_Bus_RemindRecord!=null )
                                  {
                                        modelT_Bus_RemindRecord.F_State = 0;
                                        new BLL.T_Bus_RemindRecord().Update(modelT_Bus_RemindRecord);
                                    }
                                   
                                }
                            }
                            else
                            {
                                #region 保存工单信息

                                //modelT_Bus_WorkOrder.F_WorkState = 2;//待查收

                                TimeSpan ts = DateTime.Now.Subtract(modelT_Bus_Feedback.F_CreateTime.Value);
                                int tss = int.Parse(Math.Round(ts.TotalHours, 0).ToString());
                                keyValuePairs.Add("F_LimitTime", modelT_Bus_WorkOrder.F_LimitTime
                                     .Value.AddHours(tss));
                                // modelT_Bus_WorkOrder.F_LimitTime = modelT_Bus_WorkOrder.F_LimitTime
                                //      .Value.AddHours(tss);
                                keyValuePairs.Add("F_WorkState", (int)EnumWorkState.dealing);
                                modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.dealing;//待查收
                                workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);
                                var modelT_Bus_AssignedInfo_Next = new BLL.T_Bus_AssignedInfo_Next().GetModelList("F_State=1 and F_IsDelete=0 and F_WorkOrderId='" + workorderid + "'  order by F_CreateTime desc");

                                modelT_Bus_AssignedInfo.F_LimitTime = modelT_Bus_WorkOrder.F_LimitTime;
                                assignBLL.Update(modelT_Bus_AssignedInfo);
                                if (modelT_Bus_AssignedInfo_Next != null && modelT_Bus_AssignedInfo_Next.Count > 0)
                                {
                                    modelT_Bus_AssignedInfo_Next[0].F_LimitTime =
                                         modelT_Bus_AssignedInfo_Next[0].F_LimitTime.Value
                                         .AddHours(tss);
                                    new BLL.T_Bus_AssignedInfo_Next().Update(modelT_Bus_AssignedInfo_Next[0]);
                                }

                                #endregion

                                #region 保存交办信息
                                //modelT_Bus_AssignedInfo.F_FeedbackTime = null;//反馈时间
                                modelT_Bus_AssignedInfo.F_IsSure = 4;
                                modelT_Bus_AssignedInfo.F_SureUser = "";
                                modelT_Bus_AssignedInfo.F_SureTime = null;
                                assignBLL.Update(modelT_Bus_AssignedInfo);

                               
                                #endregion

                                strmsg = "拒绝";
                            }

                            #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 + " " + strmsg + "了工单退回申请";
                            oper.F_CreateUser = User.F_UserCode;
                            oper.F_CreateTime = DateTime.Now;
                            oper.F_IsDelete = 0;

                            operBLL.Add(oper);

                            //推送消息表
                            msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, modelT_Bus_Feedback.F_CreateUser, User.F_UserCode, (int)EnumSmsType.workorder);
                            #endregion
                            if (modelT_Bus_AssignedInfo.F_MainDeptId == 304)
                            {
                                rre = new ShangQiuWorkOrderController().AuditRebackToGrdding(workorderid, state.ToString(), reason, User.F_UserCode).ToString();
                            }
                            if (isjb > 0)
                            {
                                if (modelT_Bus_Feedback.F_IsAudit == 1)
                                {
                                    if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
                                    {
                                        string maindeptid = RequestString.GetFormString("maindeptid");
                                        string otherdeptids = RequestString.GetFormString("otherdeptids");
                                        int limittime = RequestString.GetInt("limittime", 0);
                                        string limittimes = RequestString.GetString("limittimes");
                                        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  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 ";
                                        string assignedopinion = RequestString.GetFormString("assignedopinion");
                                        var modelT_Bus_AssignedInfoLasts = assignBLL.GetList(0, $" F_WorkOrderId='{workorderid}' and F_IsDelete='0' and  F_State='1' ", " F_CreateTime desc").Tables[0];
                                        if (modelT_Bus_AssignedInfoLasts.Rows.Count > 0)
                                        {
                                            if (modelT_Bus_AssignedInfoLasts.Rows[0]["F_CreateUser"].ToString() != User.F_UserCode)
                                            {
                                                return Error("操作失败");
                                            }
                                        }
                                        if (!string.IsNullOrEmpty(otherdeptids))
                                        {
                                            var both = otherdeptids.Split(',').Intersect(maindeptid.Split(','));
                                            if (both.Count() > 0)
                                            {
                                                return Error("主办单位不能出现在协办单位");
                                            }
                                        }
                                        Model.T_Bus_WorkOrder tempT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                                        var deptlist = new BLL.T_Sys_Department().GetModelList("F_DeptId in (" + maindeptid + ")");
                                        if (modelT_Bus_WorkOrder != null && deptlist != null && deptlist.Count > 0)
                                        {
                                            if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.submit)
                                            {
                                                int aid = 0;
                                                if (deptlist.Count == 1)
                                                {
                                                    var deptinfo = deptlist.FirstOrDefault();

                                                    #region 插入交办记录
                                                    modelT_Bus_AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                                    //  modelT_Bus_AssignedInfo.F_LimitTime = DateTime .Now .AddDays  (limittime);//办理时限
                                                    if (modelT_Bus_WorkOrder.F_Level == 2)
                                                    {
                                                        try
                                                        {
                                                            modelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(limittimes);
                                                        }
                                                        catch
                                                        {
                                                            return Error("请选择正确的时间");
                                                        }

                                                    }
                                                    else
                                                    {
                                                        modelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(resdatetime);
                                                    }
                                                    modelT_Bus_AssignedInfo.F_MainDeptId = deptinfo.F_DeptId;//主办单位id
                                                    modelT_Bus_AssignedInfo.F_OtherDeptIds = otherdeptids;//协办单位id
                                                    modelT_Bus_AssignedInfo.F_AssignedOpinion = assignedopinion;//交办意见
                                                    modelT_Bus_AssignedInfo.F_State = state;//0草稿  1正式
                                                    modelT_Bus_AssignedInfo.F_CreateUser = User.F_UserCode;
                                                    modelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                                                    modelT_Bus_AssignedInfo.F_IsDelete = 0;
                                                    modelT_Bus_AssignedInfo.F_IsOverdue = 0;
                                                    modelT_Bus_AssignedInfo.F_IsSure = 0;
                                                    modelT_Bus_AssignedInfo.F_IsReload = 0;
                                                    modelT_Bus_AssignedInfo.F_IsNext = 0;
                                                    modelT_Bus_AssignedInfo.F_TimeResp = assignBLL.GetRepTimly(DateTime.Now);//及时查收时间点
                                                    aid = assignBLL.Add(modelT_Bus_AssignedInfo);

                                                    #endregion

                                                    if (modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_State == 1)
                                                    {

                                                        #region 保存工单信息
                                                        keyValuePairs.Add("F_WorkState", (int)EnumWorkState.receive);
                                                        modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.receive;//待查收
                                                                                                                      //modelT_Bus_WorkOrder.F_LimitTime = DateTime.Now.AddDays(limittime); ;
                                                        if (modelT_Bus_WorkOrder.F_Level == 2)
                                                        {
                                                            try
                                                            {
                                                               // modelT_Bus_WorkOrder.F_LimitTime = Convert.ToDateTime(limittimes);
                                                                keyValuePairs.Add("F_LimitTime", Convert.ToDateTime(limittimes));
                                                            }
                                                            catch
                                                            {
                                                                return Error("请选择正确的时间");
                                                            }

                                                        }
                                                        else
                                                        {
                                                         //   modelT_Bus_WorkOrder.F_LimitTime = Convert.ToDateTime(resdatetime);
                                                            keyValuePairs.Add("F_LimitTime", Convert.ToDateTime(resdatetime));
                                                        }
                                                        keyValuePairs.Add("F_MainDeptId", deptinfo.F_DeptId);
                                                        //   modelT_Bus_WorkOrder.F_MainDeptId = deptinfo.F_DeptId;
                                                        keyValuePairs.Add("F_OtherDeptIds", otherdeptids);
                                                        //  modelT_Bus_WorkOrder.F_OtherDeptIds = otherdeptids;
                                                        keyValuePairs.Add("F_AssignUser", User.F_UserCode);
                                                        //  modelT_Bus_WorkOrder.F_AssignUser = User.F_UserCode;
                                                        keyValuePairs.Add("F_AssignTime", DateTime.Now);
                                                       // modelT_Bus_WorkOrder.F_AssignTime = DateTime.Now;
                                                        workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);
                                                        #endregion

                                                        #region 删除草稿信息
                                                        var cglist = assignBLL.GetModelList(" F_IsDelete=0 and F_State=0 and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "'");

                                                        foreach (var cg in cglist)
                                                        {
                                                            cg.F_IsDelete = 1;
                                                            cg.F_DeleteUser = User.F_UserCode;
                                                            cg.F_DeleteTime = DateTime.Now;

                                                            assignBLL.Update(cg);
                                                        }
                                                        #endregion

                                                        #region 插入操作记录
                                                        var msgss = userinfo + " 交办了工单，主办单位：" + deptinfo.F_DeptName;
                                                        if (!string.IsNullOrEmpty(otherdeptids))
                                                        {
                                                            string sql = "select dbo.GetDeptNames('" + otherdeptids + "')";
                                                            msgss += "，协办单位：" + DbHelperSQL.GetSingle(sql);
                                                        }
                                                        addoptlog(modelT_Bus_WorkOrder.F_WorkOrderId, modelT_Bus_WorkOrder.F_WorkState, modelT_Bus_AssignedInfo.F_Id, msgss, User.F_UserCode);

                                                        //推送消息表
                                                        var users = userBLL.GetModelList(" F_DeptId='" + deptinfo.F_DeptId + "' ");
                                                        foreach (var u in users)
                                                        {
                                                            msg.AddInternalMessagesInfo("工单消息", msgss + "，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId, u.F_UserCode, User.F_UserCode, (int)EnumSmsType.workorder);
                                                        }
                                                        #endregion
                                                    }
                                                }
                                                else
                                                {
                                                    string newids = ""; string errdeptid = ""; string deptname = "";
                                                    foreach (var deptinfo in deptlist)
                                                    {
                                                        deptname += deptinfo.F_DeptName + ",";
                                                        #region 新增工单
                                                        Model.T_Bus_WorkOrder modelT_Bus_WorkOrder1 = new Model.T_Bus_WorkOrder();
                                                        modelT_Bus_WorkOrder1 = tempT_Bus_WorkOrder;
                                                        string creattime = ((DateTime)modelT_Bus_WorkOrder1.F_CreateTime).ToString("yyyy-MM-dd") + " 00:00:00";
                                                        string endtime = ((DateTime)modelT_Bus_WorkOrder1.F_CreateTime).ToString("yyyy-MM-dd") + " 23:59:59";

                                                        modelT_Bus_WorkOrder1.F_WorkOrderId = workorderBLL.GetNewWorkOrderID((int)modelT_Bus_WorkOrder.F_InfoSource, (int)modelT_Bus_WorkOrder.F_SourceArea, creattime, endtime);
                                                        modelT_Bus_WorkOrder1.F_Id = workorderBLL.Add(modelT_Bus_WorkOrder1);
                                                        if (modelT_Bus_WorkOrder1.F_Id <= 0)
                                                        {
                                                            errdeptid += deptinfo.F_DeptName + ",";
                                                            continue;
                                                        }
                                                        #endregion
                                                        #region 交办
                                                        #region 插入交办记录
                                                        modelT_Bus_AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder1.F_WorkOrderId;
                                                        //  modelT_Bus_AssignedInfo.F_LimitTime = DateTime.Now.AddDays(limittime); ;//办理时限
                                                        if (modelT_Bus_WorkOrder.F_Level == 2)
                                                        {
                                                            try
                                                            {
                                                                modelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(limittimes);
                                                            }
                                                            catch
                                                            {
                                                                return Error("请选择正确的时间");
                                                            }

                                                        }
                                                        else
                                                        {
                                                            modelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(resdatetime);
                                                        }

                                                        modelT_Bus_AssignedInfo.F_MainDeptId = deptinfo.F_DeptId;//主办单位id
                                                        modelT_Bus_AssignedInfo.F_OtherDeptIds = otherdeptids;//协办单位id
                                                        modelT_Bus_AssignedInfo.F_AssignedOpinion = assignedopinion;//交办意见
                                                        modelT_Bus_AssignedInfo.F_TimeResp = assignBLL.GetRepTimly(DateTime.Now);//及时查收时间点
                                                        modelT_Bus_AssignedInfo.F_State = 1;//0草稿  1正式
                                                        modelT_Bus_AssignedInfo.F_CreateUser = User.F_UserCode;
                                                        modelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                                                        modelT_Bus_AssignedInfo.F_IsDelete = 0;
                                                        modelT_Bus_AssignedInfo.F_IsOverdue = 0;
                                                        modelT_Bus_AssignedInfo.F_IsSure = 0;
                                                        modelT_Bus_AssignedInfo.F_IsReload = 0;
                                                        modelT_Bus_AssignedInfo.F_IsNext = 0;
                                                        aid = assignBLL.Add(modelT_Bus_AssignedInfo);

                                                        #endregion
                                                        #endregion
                                                        if (modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_State == 1)
                                                        {
                                                            #region 保存工单信息
                                                            Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                                                            keyValuePairs1.Add("F_WorkState", (int)EnumWorkState.receive);
                                                            modelT_Bus_WorkOrder1.F_WorkState = (int)EnumWorkState.receive;//待查收
                                                            if (modelT_Bus_WorkOrder.F_Level == 2)
                                                            {
                                                                try
                                                                {
                                                                    //modelT_Bus_WorkOrder1.F_LimitTime = Convert.ToDateTime(limittimes);
                                                                    keyValuePairs1.Add("F_LimitTime", Convert.ToDateTime(limittimes));
                                                                }
                                                                catch
                                                                {
                                                                    return Error("请选择正确的时间");
                                                                }

                                                            }
                                                            else
                                                            {
                                                                keyValuePairs1.Add("F_LimitTime", Convert.ToDateTime(resdatetime));
                                                              //  modelT_Bus_WorkOrder1.F_LimitTime = Convert.ToDateTime(resdatetime);
                                                            }
                                                            keyValuePairs1.Add("F_MainDeptId", Convert.ToDateTime(deptinfo.F_DeptId));
                                                            //  modelT_Bus_WorkOrder1.F_MainDeptId = deptinfo.F_DeptId;
                                                            keyValuePairs1.Add("F_OtherDeptIds", otherdeptids);
                                                            //   modelT_Bus_WorkOrder1.F_OtherDeptIds = otherdeptids;
                                                            keyValuePairs1.Add("F_AssignUser", User.F_UserCode);
                                                            //  modelT_Bus_WorkOrder1.F_AssignUser = User.F_UserCode;
                                                            keyValuePairs1.Add("F_AssignTime", DateTime.Now);
                                                           // modelT_Bus_WorkOrder1.F_AssignTime = DateTime.Now;
                                                            workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder1.F_Id , keyValuePairs1);
                                                            #endregion
                                                            #region 删除草稿信息
                                                            var cglist = assignBLL.GetModelList(" F_IsDelete=0 and F_State=0 and F_WorkOrderId='" + modelT_Bus_WorkOrder1.F_WorkOrderId + "'");

                                                            foreach (var cg in cglist)
                                                            {
                                                                cg.F_IsDelete = 1;
                                                                cg.F_DeleteUser = User.F_UserCode;
                                                                cg.F_DeleteTime = DateTime.Now;

                                                                assignBLL.Update(cg);
                                                            }
                                                            #endregion
                                                            #region 插入操作记录
                                                            var msgss = userinfo + " 交办了工单，主办单位：" + deptinfo.F_DeptName;
                                                            if (!string.IsNullOrEmpty(otherdeptids))
                                                            {
                                                                string sql = "select dbo.GetDeptNames('" + otherdeptids + "')";
                                                                msgss += "，协办单位：" + DbHelperSQL.GetSingle(sql);
                                                            }

                                                            addoptlog(modelT_Bus_WorkOrder1.F_WorkOrderId, modelT_Bus_WorkOrder1.F_WorkState, modelT_Bus_AssignedInfo.F_Id, msgss, User.F_UserCode);

                                                            //推送消息表
                                                            var users = userBLL.GetModelList(" F_DeptId='" + deptinfo.F_DeptId + "' ");

                                                            foreach (var u in users)
                                                            {
                                                                msg.AddInternalMessagesInfo("工单消息", msgss + "，工单编号：" + modelT_Bus_WorkOrder1.F_WorkOrderId, u.F_UserCode, User.F_UserCode, (int)EnumSmsType.workorder);
                                                            }
                                                            #endregion
                                                        }
                                                        newids += modelT_Bus_WorkOrder1.F_WorkOrderId + ",";
                                                    }
                                                    newids = newids.Trim(',');
                                                    var msgs = "";
                                                    if (errdeptid == "")
                                                    {
                                                        Dictionary<string, object> keyValuePairs2 = new Dictionary<string, object>();
                                                        keyValuePairs2.Add("F_WorkState", (int)EnumWorkState.finish);
                                                        modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.finish;//待查收
                                                        keyValuePairs2.Add("F_CloseTime", DateTime.Now);
                                                        //     modelT_Bus_WorkOrder.F_CloseTime = DateTime.Now;
                                                        keyValuePairs2.Add("F_CloseUser", User.F_UserCode);
                                                        //modelT_Bus_WorkOrder.F_CloseUser = User.F_UserCode;
                                                        workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs2);
                                                        msgs = userinfo + " 交办多单位："+ deptname + "关闭此工单并生成新工单，新工单编号为：" + newids;
                                                    }
                                                    else
                                                    {
                                                        errdeptid = errdeptid.Trim(',');
                                                        msgs = userinfo + " 交办的单位有" + deptname + "，部分操作成功，新工单编号为：" + newids + "，交办失败的部门为：" + errdeptid;
                                                    }
                                                    #region 插入操作记录
                                                    addoptlog(modelT_Bus_WorkOrder.F_WorkOrderId, modelT_Bus_WorkOrder.F_WorkState, modelT_Bus_AssignedInfo.F_Id, msgs, User.F_UserCode);
                                                    #endregion

                                                }
                                                #region
                                                #endregion
                                            }
                                            else
                                            {
                                                return Error("已经交办过了");
                                            }
                                        }
                                        else
                                        {
                                            return Error("操作失败");
                                        }

                                    }
                                    else
                                    {
                                        return Error("权限不足");
                                    }
                                }

                            }
                            trans.Complete();
                        }
                        return Success("操作成功");
                    }
                    else
                    {
                        return Error("此审核已经处理");
                    }
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }

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

            if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int newlimittime =7;
                string resdatetime = "";
                string reason = RequestString.GetFormString("reason");
                string files = RequestString.GetFormString("files");
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);

                var Delay = new BLL.T_Bus_DelayTime().GetModelList("F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and F_IsAudit in (0,1) and F_CreateUser='" + User.F_DeptId + "'and F_AssignedId='"+ modelT_Bus_AssignedInfo.F_Id +"'");

                if (Delay != null && Delay.Count > 0)
                {
                    return Error("当前工单只能申请一次延时");
                }
                    
                if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_MainDeptId == User.F_DeptId)
                {
                    using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                    {
                        #region 保存工单信息
                        int n = DbHelperSQL.ExecuteSql(" update T_Bus_WorkOrder set F_WorkState=5 where F_Id ='" + modelT_Bus_WorkOrder.F_Id + "'");
                        #endregion
                        #region 插入申请延时信息
                        Model.T_Bus_DelayTime delay = new Model.T_Bus_DelayTime();
                        delay.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                        delay.F_OldTime = modelT_Bus_AssignedInfo.F_LimitTime;
                         if (newlimittime > 0)
                        {
                            DataTable dt = DbHelperSQL.Query("select top " + newlimittime + " F_OffDate from  T_Sys_WorkOFFDays  where F_OffState = 1   and F_OffDate>'" + modelT_Bus_AssignedInfo.F_LimitTime + "' 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 ";
                        //   delay.F_NewTime =DateTime .Now .AddDays ( newlimittime);
                        delay.F_NewTime = Convert.ToDateTime(resdatetime);
                        delay.F_Reason = reason;
                        delay.F_State = modelT_Bus_WorkOrder.F_WorkState ;
                        delay.F_IsAudit = 0;
                        delay.F_IsDelete = 0;
                        delay.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                        delay.F_CreateUser = User.F_DeptId .ToString ();
                        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);

                        //推送消息表
                        msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, modelT_Bus_AssignedInfo.F_CreateUser, User.F_UserCode, (int)EnumSmsType.workorder);
                        #endregion

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


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

        /// <summary>
        /// 审核延时工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult AuditDelayWorkOrder()
        {
            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int state = RequestString.GetInt("state", 0);
                string reason = RequestString.GetFormString("reason");
                DateTime newlimittime = DateTime.Parse(RequestString.GetFormString("newlimittime") + " 23:59:59");
                int delayid = RequestString.GetInt("delayid", 0);
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_DelayTime modelT_Bus_DelayTime = new BLL.T_Bus_DelayTime().GetModel(delayid);
                var modelT_Bus_AssignedInfo_Next = new BLL.T_Bus_AssignedInfo_Next().GetModelList("F_State=1 and F_IsDelete=0 and F_WorkOrderId='" + workorderid + "'  order by F_CreateTime desc");
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);

                if (modelT_Bus_WorkOrder != null && modelT_Bus_DelayTime != null && modelT_Bus_AssignedInfo != null)
                {
                    if (modelT_Bus_DelayTime.F_IsAudit == 0)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            #region 保存工单信息
                            int workstate = 4;
                            if (modelT_Bus_DelayTime.F_State!=null )
                             workstate = modelT_Bus_DelayTime.F_State.Value  ;
                          


                            int n = DbHelperSQL.ExecuteSql(" update T_Bus_WorkOrder set F_WorkState="+ workstate + ",F_LimitTime='"+ newlimittime + "'   where F_Id ='" + modelT_Bus_WorkOrder.F_Id + "'");
                            #endregion

                            #region 保存审核信息
                            modelT_Bus_DelayTime.F_IsAudit = state;//审核
                            modelT_Bus_DelayTime.F_AuditUser = User.F_UserCode;
                            modelT_Bus_DelayTime.F_AuditTime = DateTime.Now;
                            modelT_Bus_DelayTime.F_RefuseReason = reason;
                            modelT_Bus_DelayTime.F_AgreeTime = newlimittime;
                            new BLL.T_Bus_DelayTime().Update(modelT_Bus_DelayTime);
                            #endregion
                            string type = "同意"; string des = "";
                            if (modelT_Bus_DelayTime.F_IsAudit == 1)
                            {
                                #region 修改交办记录
                                modelT_Bus_AssignedInfo.F_IsSure = 1;
                                modelT_Bus_AssignedInfo.F_LimitTime = modelT_Bus_DelayTime.F_AgreeTime;
                                assignBLL.Update(modelT_Bus_AssignedInfo);
                                if (modelT_Bus_AssignedInfo_Next != null && modelT_Bus_AssignedInfo_Next.Count > 0)
                                {
                                    TimeSpan ts = modelT_Bus_DelayTime.F_AgreeTime.Value.Subtract(modelT_Bus_DelayTime.F_OldTime.Value);
                                    int tss = int.Parse(Math.Round(ts.TotalHours, 0).ToString());
                                    modelT_Bus_AssignedInfo_Next[0].F_LimitTime =
                                         modelT_Bus_AssignedInfo_Next[0].F_LimitTime.Value
                                         .AddHours(tss);
                                    new BLL.T_Bus_AssignedInfo_Next().Update(modelT_Bus_AssignedInfo_Next[0]);

                                }
                                #endregion
                                #region 处理协办单位
                                #endregion
                                des = "，原定时间" + modelT_Bus_DelayTime.F_OldTime + "，申请延长到" + modelT_Bus_DelayTime.F_AgreeTime;
                            }
                            else
                            {
                                TimeSpan ts = DateTime.Now.Subtract(modelT_Bus_DelayTime.F_CreateTime.Value);
                                int tss = int.Parse(Math.Round(ts.TotalHours, 0).ToString());
                                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                                keyValuePairs.Add("F_LimitTime", modelT_Bus_WorkOrder.F_LimitTime
                                     .Value.AddHours(tss));
                               // modelT_Bus_WorkOrder.F_LimitTime = modelT_Bus_WorkOrder.F_LimitTime
                                   //  .Value.AddHours(tss);
                                workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);
                                modelT_Bus_AssignedInfo.F_LimitTime = modelT_Bus_WorkOrder.F_LimitTime;
                                if (modelT_Bus_AssignedInfo_Next != null && modelT_Bus_AssignedInfo_Next.Count > 0)
                                {
                                    modelT_Bus_AssignedInfo_Next[0].F_LimitTime =
                                         modelT_Bus_AssignedInfo_Next[0].F_LimitTime.Value
                                         .AddHours(tss);
                                    new BLL.T_Bus_AssignedInfo_Next().Update(modelT_Bus_AssignedInfo_Next[0]);
                                }
                                modelT_Bus_AssignedInfo.F_IsSure = 5;
                                assignBLL.Update(modelT_Bus_AssignedInfo);
                                type = "拒绝";
                            }

                            #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 + " " + type + "了工单延时申请" + des;
                            oper.F_CreateUser = User.F_UserCode;
                            oper.F_CreateTime = DateTime.Now;
                            oper.F_IsDelete = 0;

                            operBLL.Add(oper);

                            //推送消息表
                            msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, modelT_Bus_DelayTime.F_CreateUser, User.F_UserCode, (int)EnumSmsType.workorder);
                            #endregion

                            trans.Complete();
                        }
                        return Success("操作成功");
                    }
                    else
                    {
                        return Error("此审核已经处理");
                    }
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }
        /// <summary>
        /// 批量审核延时
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        //[Authority]
        public ActionResult AuditDelayWorkOrderBatch(string ids)
        {




            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {
                int state = RequestString.GetInt("state", 0);
                string reason = RequestString.GetFormString("reason");
                //   DateTime newlimittime = DateTime.Parse(RequestString.GetFormString("newlimittime") + " 23:59:59");
                string errids = ""; string errids1 = "";
                if (!string.IsNullOrEmpty(ids))
                {
                    string[] strids = ids.Split(',');
                    foreach (string str in strids)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(str);
                            Model.T_Bus_DelayTime modelT_Bus_DelayTime = new BLL.T_Bus_DelayTime().GetModelList("   F_WorkOrderId = '" + str + "'  and F_IsDelete = 0 and F_IsAudit = 0 order by  F_CreateTime desc").FirstOrDefault();
                            Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(str);
                            var modelT_Bus_AssignedInfo_Next = new BLL.T_Bus_AssignedInfo_Next().GetModelList("F_State=1 and F_IsDelete=0 and F_WorkOrderId='" + str + "'  order by F_CreateTime desc");
                            if (modelT_Bus_WorkOrder != null && modelT_Bus_DelayTime != null && modelT_Bus_AssignedInfo != null)
                            {
                                if (modelT_Bus_DelayTime.F_IsAudit == 0)
                                {
                                    #region 保存工单信息
                                    int workstate = 4;
                                    if (modelT_Bus_DelayTime.F_State != null)
                                        workstate = modelT_Bus_DelayTime.F_State.Value;

                                    Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                                    keyValuePairs.Add("F_WorkState", workstate);
                                    //  modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.dealing;//办理中
                                    keyValuePairs.Add("F_LimitTime", modelT_Bus_DelayTime.F_NewTime);
                                  //  modelT_Bus_WorkOrder.F_LimitTime = modelT_Bus_DelayTime.F_NewTime;
                                    workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);
                                    #endregion

                                    #region 保存审核信息
                                    modelT_Bus_DelayTime.F_IsAudit = state;//审核
                                    modelT_Bus_DelayTime.F_AuditUser = User.F_UserCode;
                                    modelT_Bus_DelayTime.F_AuditTime = DateTime.Now;

                                    modelT_Bus_DelayTime.F_RefuseReason = reason;
                                    modelT_Bus_DelayTime.F_AgreeTime = modelT_Bus_DelayTime.F_NewTime;
                                    new BLL.T_Bus_DelayTime().Update(modelT_Bus_DelayTime);
                                    #endregion
                                    string type = "同意"; string des = "";
                                    if (modelT_Bus_DelayTime.F_IsAudit == 1)
                                    {
                                        #region 修改交办记录

                                        modelT_Bus_AssignedInfo.F_LimitTime = modelT_Bus_DelayTime.F_AgreeTime;
                                        assignBLL.Update(modelT_Bus_AssignedInfo);
                                        if (modelT_Bus_AssignedInfo_Next != null && modelT_Bus_AssignedInfo_Next.Count > 0)
                                        {
                                            TimeSpan ts = modelT_Bus_DelayTime.F_AgreeTime.Value.Subtract(modelT_Bus_DelayTime.F_OldTime.Value);
                                            int tss = int.Parse(Math.Round(ts.TotalHours, 0).ToString());
                                            modelT_Bus_AssignedInfo_Next[0].F_LimitTime =
                                                 modelT_Bus_AssignedInfo_Next[0].F_LimitTime.Value
                                                 .AddHours(tss);
                                            new BLL.T_Bus_AssignedInfo_Next().Update(modelT_Bus_AssignedInfo_Next[0]);

                                        }
                                        #endregion
                                        #region 处理协办单位
                                        var xblist = assignItemBLL.GetModelList(" F_IsDelete=0 and F_State=1 and  ISNULL(F_FeedbackTime, '')='' and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "'");
                                        foreach (var xb in xblist)
                                        {
                                            //xb.F_LimitTime = DateTime.Now;
                                            xb.F_LimitTime = modelT_Bus_DelayTime.F_AgreeTime;

                                            assignItemBLL.Update(xb);
                                        }
                                        #endregion
                                        des = "，原定时间" + modelT_Bus_DelayTime.F_OldTime + "，申请延长到" + modelT_Bus_DelayTime.F_AgreeTime;
                                    }
                                    else
                                    {
                                        TimeSpan ts = DateTime.Now.Subtract(modelT_Bus_DelayTime.F_CreateTime.Value);
                                        int tss = int.Parse(Math.Round(ts.TotalHours, 0).ToString());
                                        Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                                        keyValuePairs1.Add("F_LimitTime", modelT_Bus_WorkOrder.F_LimitTime);
                                        modelT_Bus_WorkOrder.F_LimitTime = modelT_Bus_WorkOrder.F_LimitTime
                                            .Value.AddHours(tss);
                                        workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs1);
                                        modelT_Bus_AssignedInfo.F_LimitTime = modelT_Bus_WorkOrder.F_LimitTime;
                                        if (modelT_Bus_AssignedInfo_Next != null && modelT_Bus_AssignedInfo_Next.Count > 0)
                                        {
                                            modelT_Bus_AssignedInfo_Next[0].F_LimitTime =
                                                 modelT_Bus_AssignedInfo_Next[0].F_LimitTime.Value
                                                 .AddHours(tss);
                                            new BLL.T_Bus_AssignedInfo_Next().Update(modelT_Bus_AssignedInfo_Next[0]);
                                        }
                                        modelT_Bus_AssignedInfo.F_IsSure = 5;
                                        assignBLL.Update(modelT_Bus_AssignedInfo);


                                        type = "拒绝";
                                    }

                                    #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 + " " + type + "了工单延时申请" + des;
                                    oper.F_CreateUser = User.F_UserCode;
                                    oper.F_CreateTime = DateTime.Now;
                                    oper.F_IsDelete = 0;

                                    operBLL.Add(oper);

                                    //推送消息表
                                    msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, modelT_Bus_DelayTime.F_CreateUser, User.F_UserCode, (int)EnumSmsType.workorder);
                                    #endregion
                                }
                                else
                                    errids1 += str + ",";

                            }
                            trans.Complete();
                        }
                    }
                    if (errids1 == "" && errids == "")
                        return Success("操作成功");
                    else
                    {
                        string msg = "";
                        if (errids1 != "")
                            msg += "，工单编号为" + errids1.Trim(',') + "的工单已被其他人审核";
                        if (errids != "")
                            msg += "，工单编号为" + errids1.Trim(',') + "的工单不是交办人本人";
                        return Error("部分工单操作失败" + msg);
                    }
                }
                else
                {
                    return Error("参数获取失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }


        /// <summary>
        /// 办理工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult FeedBackWorkOrder()
        {
            if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                string dealman = RequestString.GetFormString("dealman");
                string result = RequestString.GetFormString("result");
                string files = RequestString.GetFormString("files");
                int state = RequestString.GetInt("state", 0);
                int feedbackid = RequestString.GetInt("feedbackid", 0);
                int isproresult = RequestString.GetInt("isproresult", 0);//是否向当事人反馈
                string prosituation = RequestString.GetFormString("prosituation");
                string dealcontact = RequestString.GetFormString("dealcontact");
                string connecttime = RequestString.GetFormString("connecttime");
                string connectmode = RequestString.GetFormString("connectmode");
                string replycontent = RequestString.GetFormString("replycontent");
                int isstaisfied = RequestString.GetInt("isstaisfied", 0);
                string duties = RequestString.GetFormString("duties");
                string situation = RequestString.GetFormString("situation");
                string IsProResultState = RequestString.GetFormString("IsProResultState ");
                string Unsuccessful = RequestString.GetFormString("Unsuccessful");
                string AuditUser = RequestString.GetFormString("AuditUser");//审核领导
                string post = RequestString.GetFormString("post");//审核领导职务
                string auditContact = RequestString.GetFormString("auditContact");//审核领导职务

                string feedbackreason = RequestString.GetFormString("feedbackReason");//办理操作里   是否向当事人反馈，选择否的时候，有个输入框，可以填原因，


                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                Model.T_Bus_Feedback modelT_Bus_Feedback = new Model.T_Bus_Feedback();
                int type = 0;
                if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo != null)
                {        
                    type = AssignDeptType(modelT_Bus_AssignedInfo, User.F_DeptId);
                    if (type > 0)
                    {
                        //if (modelT_Bus_WorkOrder.F_WorkState == 4)
                        if (modelT_Bus_WorkOrder.F_WorkState >= (int)EnumWorkState.dealing || modelT_Bus_WorkOrder.F_IsProResult == 0)
                        {
                            using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                            {
                                if (feedbackid == 0)
                                {
                                    #region 插入反馈记录
                                    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 = post;
                                    modelT_Bus_Feedback.F_AuditContact = auditContact;
                                    modelT_Bus_Feedback.F_AuditUser = AuditUser;
                                    modelT_Bus_Feedback.F_DealUser = dealman;
                                    modelT_Bus_Feedback.F_Result = result;//反馈内容
                                    #region 20200114新增字段 zhengbingbing
                                    // modelT_Bus_Feedback.F_IsProResult = isproresult;//是否有处理结果:0默认，1是，2否
                                    modelT_Bus_Feedback.F_ProSituation = prosituation;//处理情况/方案/进程
                                    modelT_Bus_Feedback.F_IsProtect = modelT_Bus_WorkOrder.F_IsProtect;//是否保密(0:否1:是)
                                    modelT_Bus_Feedback.F_DealUserContact = dealcontact;//承办人联系方式
                                    DateTime contime = DateTime.Now;
                                    if (connecttime != "" && DateTime.TryParse(connecttime, out contime))
                                        modelT_Bus_Feedback.F_ConnectTime = DateTime.Parse(connecttime);//沟通时间
                                    modelT_Bus_Feedback.F_ConnectMode = connectmode;//沟通方式
                                    modelT_Bus_Feedback.F_ReplyContent = replycontent;//答复内容
                                    modelT_Bus_Feedback.F_IsSatisfied = isstaisfied;//是否满意:0未评价，1满意，2基本满意，3不满意

                                    modelT_Bus_Feedback.F_FeedbackReason = feedbackreason;
                                    
                                    modelT_Bus_Feedback.F_Duties = duties;//职务
                                    modelT_Bus_Feedback.F_Situation = situation;
                                    modelT_Bus_Feedback.F_IsProResult = isproresult;



                                    #endregion
                                    modelT_Bus_Feedback.F_File = files;
                                    modelT_Bus_Feedback.F_IsAudit = 0;
                                    modelT_Bus_Feedback.F_IsDelete = 0;
                                    modelT_Bus_Feedback.F_CreateUser = User.F_UserCode;//办理人
                                    modelT_Bus_Feedback.F_CreateTime = DateTime.Now;//办理时间
                                    modelT_Bus_Feedback.F_CreateDeptId = User.F_DeptId;//办理部门
                                    modelT_Bus_Feedback.F_IsFeedEnd = 1;
                                    modelT_Bus_Feedback.F_State = state;
                                    modelT_Bus_Feedback.F_Type = type;

                                    new BLL.T_Bus_Feedback().Add(modelT_Bus_Feedback);
                                    #endregion
                                }
                                else
                                {
                                    #region 修改反馈记录
                                    modelT_Bus_Feedback = new BLL.T_Bus_Feedback().GetModel(feedbackid);
                                    if (modelT_Bus_Feedback != null)
                                    {
                                        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_DealUser = dealman;
                                        modelT_Bus_Feedback.F_Result = result;//反馈内容
                                        modelT_Bus_Feedback.F_File = files;
                                        modelT_Bus_Feedback.F_AuditUser = AuditUser;
                                        #region 20200114新增字段 zhengbingbing
                                        //  modelT_Bus_Feedback.F_IsProResult = isproresult;//是否有处理结果:0默认，1是，2否
                                        modelT_Bus_Feedback.F_ProSituation = prosituation;//处理情况/方案/进程
                                        modelT_Bus_Feedback.F_IsProtect = modelT_Bus_WorkOrder.F_IsProtect;//是否保密(0:否1:是)
                                        modelT_Bus_Feedback.F_DealUserContact = dealcontact;//承办人联系方式
                                        DateTime contime = DateTime.Now;
                                        if (connecttime != "" && DateTime.TryParse(connecttime, out contime))
                                            modelT_Bus_Feedback.F_ConnectTime = DateTime.Parse(connecttime);//沟通时间
                                        modelT_Bus_Feedback.F_ConnectMode = connectmode;//沟通方式
                                        modelT_Bus_Feedback.F_ReplyContent = replycontent;//答复内容
                                        modelT_Bus_Feedback.F_IsSatisfied = isstaisfied;//是否满意:0未评价，1满意，2基本满意，3不满意

                                        modelT_Bus_Feedback.F_FeedbackReason = feedbackreason;


                                        modelT_Bus_Feedback.F_Duties = duties;//职务
                                        modelT_Bus_Feedback.F_Situation = situation;
                                        #endregion
                                        modelT_Bus_Feedback.F_CreateUser = User.F_UserCode;//办理人
                                        modelT_Bus_Feedback.F_CreateTime = DateTime.Now;//办理时间
                                        modelT_Bus_Feedback.F_CreateDeptId = User.F_DeptId;//办理部门
                                        modelT_Bus_Feedback.F_IsFeedEnd = 1;
                                        modelT_Bus_Feedback.F_State = state;
                                        modelT_Bus_Feedback.F_IsProResult = isproresult;
                                        if (modelT_Bus_AssignedInfo.F_MainDeptId == User.F_DeptId)
                                        {
                                            modelT_Bus_Feedback.F_Type = 1;
                                        }
                                        else if (!string.IsNullOrEmpty(modelT_Bus_AssignedInfo.F_OtherDeptIds) && modelT_Bus_AssignedInfo.F_OtherDeptIds.Split(',').Contains(User.F_DeptId.ToString()))
                                        {
                                            modelT_Bus_Feedback.F_Type = 2;
                                        }

                                        new BLL.T_Bus_Feedback().Update(modelT_Bus_Feedback);
                                    }
                                    #endregion
                                }

                                if (modelT_Bus_Feedback != null && modelT_Bus_Feedback.F_State == 1)
                                {
                                    string typemsg = "办理";
                                    if (type == 1)
                                    {
                                        int iscs = 0;
                                        if (modelT_Bus_AssignedInfo.F_LimitTime < DateTime.Now)
                                        {
                                            iscs = 1;
                                        }

                                        #region 保存工单信息
                                        //modelT_Bus_WorkOrder.F_WorkState = 6;//待回访

                                        Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                                        keyValuePairs.Add("F_WorkState", (int)EnumWorkState.dealed);
                                        modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.dealed;//待回访
                                        keyValuePairs.Add("F_Result", result);
                                        // modelT_Bus_WorkOrder.F_Result = result;
                                        keyValuePairs.Add("F_DealDeptId", User.F_DeptId);
                                        //  modelT_Bus_WorkOrder.F_DealDeptId = User.F_DeptId;
                                        keyValuePairs.Add("F_DealUser", User.F_UserCode);
                                        // modelT_Bus_WorkOrder.F_DealUser = User.F_UserCode;
                                        keyValuePairs.Add("F_DealTime", DateTime.Now);
                                        // modelT_Bus_WorkOrder.F_DealTime = DateTime.Now;
                                        keyValuePairs.Add("F_ToBereply", 1);
                                        // modelT_Bus_WorkOrder.F_ToBereply = 1;
                                        keyValuePairs.Add("F_IsOverdue", iscs);
                                        //modelT_Bus_WorkOrder.F_IsOverdue = iscs;
                                        keyValuePairs.Add("F_IsProResult", isproresult);
                                       // modelT_Bus_WorkOrder.F_IsProResult = isproresult;
                                        workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);


                                        #endregion

                                        #region 保存交办信息
                                        modelT_Bus_AssignedInfo.F_FeedbackTime = DateTime.Now;
                                        if (modelT_Bus_AssignedInfo.F_LimitTime < DateTime.Now)
                                        {
                                            modelT_Bus_AssignedInfo.F_IsOverdue = 1;
                                        }

                                        assignBLL.Update(modelT_Bus_AssignedInfo);
                                        #endregion

                                        #region 删除草稿信息
                                        var cglist = new BLL.T_Bus_Feedback().GetModelList(" F_IsDelete=0 and F_State=0 and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and F_CreateDeptId='" + User.F_DeptId + "'");

                                        foreach (var cg in cglist)
                                        {
                                            cg.F_IsDelete = 1;
                                            cg.F_DeleteUser = User.F_UserCode;
                                            cg.F_DeleteTime = DateTime.Now;

                                            new BLL.T_Bus_Feedback().Update(cg);
                                        }
                                        #endregion

                                        #region 删除二级单位未办理信息
                                        var ejlist = new BLL.T_Bus_AssignedInfo_Next().GetModelList(" F_IsDelete=0 and isnull(F_FeedbackTime,'')='' and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "'");
                                        foreach (var ej in ejlist)
                                        {
                                            ej.F_IsDelete = 1;
                                            ej.F_DeleteUser = User.F_UserCode;
                                            ej.F_DeleteTime = DateTime.Now;

                                            new BLL.T_Bus_AssignedInfo_Next().Update(ej);
                                        }
                                        #endregion

                                        #region 处理协办单位
                                        var xblist = new BLL.T_Bus_AssignedItemInfo().GetModelList(" F_IsDelete=0 and F_State=1 and  ISNULL(F_FeedbackTime, '')='' and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "'");
                                        foreach (var xb in xblist)
                                        {
                                            xb.F_State = 2;
                                            xb.F_SureUser = User.F_UserCode;
                                            xb.F_SureTime = DateTime.Now;

                                            new BLL.T_Bus_AssignedItemInfo().Update(xb);
                                        }
                                        #endregion

                                        typemsg = "主办";
                                    }
                                    else if (type == 2)
                                    {
                                        #region 保存明细信息
                                        Model.T_Bus_AssignedItemInfo modelT_Bus_AssignedItemInfo = new BLL.T_Bus_AssignedItemInfo().GetModelList(" F_IsDelete=0 and F_State=1 and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and F_DeptId='" + User.F_DeptId + "'").FirstOrDefault();
                                        modelT_Bus_AssignedItemInfo.F_FeedbackTime = DateTime.Now;
                                        if (modelT_Bus_AssignedItemInfo.F_LimitTime < DateTime.Now)
                                        {
                                            modelT_Bus_AssignedItemInfo.F_IsOverdue = 1;
                                        }

                                        new BLL.T_Bus_AssignedItemInfo().Update(modelT_Bus_AssignedItemInfo);
                                        #endregion

                                        #region 删除草稿信息
                                        var cglist = new BLL.T_Bus_Feedback().GetModelList(" F_IsDelete=0 and F_State=0 and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and F_CreateDeptId='" + User.F_DeptId + "'");

                                        foreach (var cg in cglist)
                                        {
                                            cg.F_IsDelete = 1;
                                            cg.F_DeleteUser = User.F_UserCode;
                                            cg.F_DeleteTime = DateTime.Now;

                                            new BLL.T_Bus_Feedback().Update(cg);
                                        }
                                        #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 = User.depname + "(" + User.F_UserCode + ")";
                                    oper.F_Message = userinfo + " " + typemsg + "了工单";
                                    oper.F_CreateUser = User.F_UserCode;
                                    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, User.F_UserCode, (int)EnumSmsType.workorder);

                                    #endregion
                                }

                                trans.Complete();
                            }

                            return Success("操作成功", modelT_Bus_Feedback.F_Id);
                        }
                        else
                        {
                            return Error("已经办理过了");
                        }
                    }
                    else
                    {
                        return Error("权限不足");
                    }
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }
        /// <summary>
        ///追问回复
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult ReplyWorkOrder()
        {
            if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "EJWLDW" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                string files = RequestString.GetFormString("files");
                string replycount = RequestString.GetFormString("replycount");
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                Model.T_Bus_Feedback modelT_Bus_Feedback = feedbackBLL
                    .GetNewModelByWorkOrderID(workorderid);

                int type = 0;
                if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo != null
                    && modelT_Bus_Feedback != null)
                {
                    // type = AssignDeptType(modelT_Bus_AssignedInfo, User.F_DeptId);
                    //if (modelT_Bus_WorkOrder.F_WorkState == 4)
                    if (modelT_Bus_WorkOrder.F_IsProResult == 2)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            if (string.IsNullOrEmpty(modelT_Bus_WorkOrder.F_AdditionalReply))
                                keyValuePairs.Add("F_AdditionalReply", replycount );
                            else
                                keyValuePairs.Add("F_AdditionalReply", modelT_Bus_WorkOrder.F_AdditionalReply + "; "+ replycount);
                            keyValuePairs.Add("F_IsProResult",3);
                            bool n = workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);
                            if (!string.IsNullOrEmpty(files))
                            {
                                if (!string.IsNullOrEmpty(modelT_Bus_Feedback.F_Files))
                                    modelT_Bus_Feedback.F_Files += "," + files;
                                else
                                    modelT_Bus_Feedback.F_Files = files;
                                bool f = feedbackBLL.Update(modelT_Bus_Feedback);
                            }

                            #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);
                            #endregion
                            trans.Complete();
                        }
                        return Success("操作成功");
                    }
                    else
                    {
                        return Error("已经办理过了");
                    }

                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }
        /// <summary>
        /// 转办回访
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult Transfer()
        {

            string workorderid = RequestString.GetFormString("workorderid");


            if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "MTDD")
            {
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo_Next modelT_Bus_AssignedInfo_Next = new BLL.T_Bus_AssignedInfo_Next().GetNewModelByWorkOrderID(workorderid);
                if (modelT_Bus_WorkOrder != null)
                {
                    Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                    // modelT_Bus_WorkOrder.F_ToBereply = 0;
                    keyValuePairs.Add("F_ToBereply", 0);
                    keyValuePairs.Add("F_IsSms", 0);
                    keyValuePairs.Add("F_IsProResult", 2);
                  //  modelT_Bus_WorkOrder.F_IsProResult = 2;
                    #region 插入操作记录
                    Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                    oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                    if (modelT_Bus_WorkOrder.F_MainDeptId>0)
                    {
                        var user = new BLL.T_Sys_UserAccount().GetModelList(" F_DeptId=" + modelT_Bus_WorkOrder.F_MainDeptId + "  ");
                        if (user != null && user.Count > 0)
                        {
                            foreach (var it in user)
                            {
                                string count = "已办未果短信提醒，您的工单" + workorderid + "被审核员评定为已办未果工单，请继续处理。";
                              //  string msg = workorderid;
                              //  bool n = SMSController.AddSmS(0, msg, count, it.F_Mobile, "170343", "");
                                string mag = "[\"" + workorderid + "\"]";
                                string v = SmsNewController.AddSmS(0, count, it.F_Mobile, "681240517979668480", mag,
                               workorderid);
                            }

                        }
                        if (modelT_Bus_AssignedInfo_Next != null)
                        {
                            var modelT_Bus_Feedback_Next
                                  = new BLL.T_Bus_Feedback_Next().GetModelList
                                  ("F_AssignedId='" + modelT_Bus_AssignedInfo_Next.F_Id + "' and F_WorkOrderId='" +
                                 workorderid + "' ORDER BY F_CreateTime DESC ");
                            if (modelT_Bus_Feedback_Next != null && modelT_Bus_Feedback_Next
                                .Count > 0)
                            {
                                if(modelT_Bus_Feedback_Next[0].F_CreateDeptId >0)
                                {
                                    var users = new BLL.T_Sys_UserAccount().GetModelList(" F_DeptId=" + modelT_Bus_Feedback_Next[0].F_CreateDeptId + "  ");
                                    if (users != null && users.Count > 0)
                                    {
                                        foreach (var it in users)
                                        {
                                            string count = "已办未果短信提醒，您的工单" + workorderid + "被审核员评定为已办未果工单，请继续处理。";
                                            // string msg = workorderid;
                                            //  bool n = SMSController.AddSmS(0, msg, count, it.F_Mobile, "170343", "");
                                            string mag = "[\"" + workorderid + "\"]";
                                            string v = SmsNewController.AddSmS(0, count, it.F_Mobile, "681240517979668480", mag,
                                           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);
                        #endregion
                        if (workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs))
                            return Success("转办成功");
                        else
                            return Error("转办失败");
                    }
                    else
                        return Error("该工单没有承办单位");
                }
                else
                {
                    return Error("工单不存在");
                }

            }
            return Error("权限不足");

        }

        #region 网格化对接
        /// <summary>
        /// 对接网格化
        /// 工单查收操作
        /// </summary>
        /// <param name="usercode"></param>
        /// <param name="workorderid"></param>
        /// <returns></returns>
        public string ReceiveWorkOrderByDock(string usercode, string workorderid, string content)
        {
            var returns = "";
            using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
            {
                string optmsg = ""; var assid = 0; var msgend = ""; var state = 0; var userinfo = ""; var msgss = ""; var retbool = "false"; var optid = string.Empty;
                Model.T_Sys_UserAccount User = userBLL.GetModel(usercode);
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                msgend = "，工单编号：" + workorderid + "，办理详情：" + content;
                if (User != null)
                {
                    if (modelT_Bus_WorkOrder == null)
                        msgss = "要办理的工单已不存在";
                    else if (modelT_Bus_AssignedInfo == null)
                    {
                        msgss = "工单无法处理或已被处理";
                    }
                    else
                    {
                        if (modelT_Bus_WorkOrder != null && (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.receive || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.reload) && modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_MainDeptId == User.F_DeptId)
                        {
                            if (modelT_Bus_AssignedInfo.F_IsSure == 0)
                            {

                                #region 保存工单信息
                                //modelT_Bus_WorkOrder.F_WorkState = 4;//办理中
                                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                                keyValuePairs.Add("F_WorkState", (int)EnumWorkState.dealing);
                                modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.dealing;//办理中
                                workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);
                                #endregion

                                #region 保存查收信息
                                modelT_Bus_AssignedInfo.F_IsSure = 1;//查收
                                modelT_Bus_AssignedInfo.F_SureUser = User.F_UserCode;
                                modelT_Bus_AssignedInfo.F_SureTime = DateTime.Now;
                                assignBLL.Update(modelT_Bus_AssignedInfo);
                                #endregion

                                #region 保存明细信息
                                if (!string.IsNullOrEmpty(modelT_Bus_AssignedInfo.F_OtherDeptIds))
                                {
                                    string[] strids = modelT_Bus_AssignedInfo.F_OtherDeptIds.Split(',');
                                    foreach (string strid in strids)
                                    {
                                        Model.T_Bus_AssignedItemInfo modelT_Bus_AssignedItemInfo = new Model.T_Bus_AssignedItemInfo();
                                        modelT_Bus_AssignedItemInfo.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                                        modelT_Bus_AssignedItemInfo.F_AssignedOpinion = modelT_Bus_AssignedInfo.F_AssignedOpinion;
                                        modelT_Bus_AssignedItemInfo.F_DeptId = Int32.Parse(strid);
                                        modelT_Bus_AssignedItemInfo.F_LimitTime = modelT_Bus_AssignedInfo.F_LimitTime;
                                        modelT_Bus_AssignedItemInfo.F_Remark = modelT_Bus_AssignedInfo.F_Remark;
                                        modelT_Bus_AssignedItemInfo.F_State = 1;
                                        modelT_Bus_AssignedItemInfo.F_Type = 2;
                                        modelT_Bus_AssignedItemInfo.F_WorkOrderId = modelT_Bus_AssignedInfo.F_WorkOrderId;
                                        modelT_Bus_AssignedItemInfo.F_IsSure = 0;
                                        modelT_Bus_AssignedItemInfo.F_CreateTime = DateTime.Now;
                                        modelT_Bus_AssignedItemInfo.F_CreateUser = User.F_UserCode;
                                        modelT_Bus_AssignedItemInfo.F_IsDelete = 0;

                                        new BLL.T_Bus_AssignedItemInfo().Add(modelT_Bus_AssignedItemInfo);

                                    }
                                }
                                #endregion
                                retbool = "true";
                                optmsg = " 查收了工单";
                                msgss = optmsg;
                            }
                            else
                                msgss = "工单已被查收";

                            assid = modelT_Bus_AssignedInfo.F_Id;
                            state = modelT_Bus_WorkOrder.F_WorkState.Value;
                        }
                        else
                            msgss = "工单已办理或已被重新指派";
                    }
                    userinfo = User.depname + "(" + User.F_UserCode + ")";
                }
                else
                {
                    userinfo = "无法获取工号信息，工号为" + usercode + msgend;
                    msgss = "无法获取工号信息";
                }
                #region 插入操作记录
                Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                oper.F_WorkOrderId = workorderid;
                oper.F_AssignedId = assid;
                oper.F_State = state;
                oper.F_Message = userinfo + " " + msgss + msgend;
                oper.F_CreateUser = usercode;
                oper.F_CreateTime = DateTime.Now;
                oper.F_IsDelete = 0;
                oper.F_Type = 1;

                optid = operBLL.Add(oper).ToString();
                #endregion
                trans.Complete();
                returns = retbool + "|" + optid + "|" + msgss;
            }

            return returns;
        }
        /// <summary>
        /// 对接网格化 工单退回操作
        /// </summary>
        /// <returns></returns>
        public string RebackWorkOrderByDock(string usercode, string workorderid, string backreason, string content)
        {

            var returns = "";
            using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
            {
                string optmsg = ""; var assid = 0; var msgend = ""; var state = 0;
                var userinfo = ""; var msgss = ""; var optid = string.Empty; var retbool = "false";
                Model.T_Sys_UserAccount User = userBLL.GetModel(usercode);
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                msgend = "，工单编号：" + workorderid + "，办理详情：" + content;
                if (User != null)
                {
                    userinfo = User.depname + "-" + User.F_UserName + "(" + User.F_UserCode + ")";
                    if (modelT_Bus_WorkOrder == null)
                        msgss = "要办理的工单已不存在";
                    else if (modelT_Bus_AssignedInfo == null)
                    {
                        msgss = "工单无法处理或已被处理";
                    }
                    else
                    {
                        if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_MainDeptId == User.F_DeptId)
                        {
                            if (modelT_Bus_AssignedInfo.F_IsSure == 0)
                            {

                                #region 保存工单信息
                                modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.auditreback;//退回审核中
                                workorderBLL.Update(modelT_Bus_WorkOrder);
                                #endregion

                                #region 插入退回申请信息
                                Model.T_Bus_Feedback model_T_Bus_Feedback = new Model.T_Bus_Feedback();
                                model_T_Bus_Feedback.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;//工单编号
                                model_T_Bus_Feedback.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;//交办id
                                model_T_Bus_Feedback.F_Result = backreason;//退回原因
                                model_T_Bus_Feedback.F_IsAudit = 0;
                                model_T_Bus_Feedback.F_IsDelete = 0;
                                model_T_Bus_Feedback.F_CreateUser = User.F_UserCode;//退回人
                                model_T_Bus_Feedback.F_CreateTime = DateTime.Now;//退回时间
                                model_T_Bus_Feedback.F_CreateDeptId = User.F_DeptId;//退回部门
                                model_T_Bus_Feedback.F_IsFeedEnd = 1;
                                model_T_Bus_Feedback.F_State = 1;
                                model_T_Bus_Feedback.F_Type = 3;

                                new BLL.T_Bus_Feedback().Add(model_T_Bus_Feedback);
                                #endregion

                                #region 保存交办信息
                                modelT_Bus_AssignedInfo.F_IsSure = 2;//申请退回
                                modelT_Bus_AssignedInfo.F_SureUser = User.F_UserCode;
                                modelT_Bus_AssignedInfo.F_SureTime = DateTime.Now;
                                assignBLL.Update(modelT_Bus_AssignedInfo);
                                #endregion

                                #region 推送消息
                                retbool = "true";
                                optmsg = " 申请退回了工单";

                                //推送消息表
                                msg.AddInternalMessagesInfo("工单消息", userinfo + optmsg + "，工单编号：" + workorderid, modelT_Bus_AssignedInfo.F_CreateUser, User.F_UserCode, (int)EnumSmsType.workorder);
                                #endregion
                                msgss = optmsg;
                            }
                            else
                                msgss = "工单已被查收，不能退回";
                            assid = modelT_Bus_AssignedInfo.F_Id;
                            state = modelT_Bus_WorkOrder.F_WorkState.Value;
                        }
                        else
                            msgss = "工单已办理或已被重新指派";
                    }
                }
                else
                {
                    userinfo = "无法获取工号信息，工号为" + usercode + msgend;
                    msgss = "无法获取工号信息";
                }
                #region 插入操作记录
                Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                oper.F_WorkOrderId = workorderid;
                oper.F_AssignedId = assid;
                oper.F_State = state;
                oper.F_Message = userinfo + " " + msgss + msgend;
                oper.F_CreateUser = usercode;
                oper.F_CreateTime = DateTime.Now;
                oper.F_IsDelete = 0;
                oper.F_Type = 1;

                optid = operBLL.Add(oper).ToString();
                #endregion
                trans.Complete();

                returns = retbool + "|" + optid + "|" + msgss;
            }

            return returns;
        }
        /// <summary>
        /// 对接网格化办理
        /// </summary>
        /// <param name="usercode">工号</param>
        /// <param name="workorderid">工单编号</param>
        /// <param name="dealman">承办人人</param>
        /// <param name="result">反馈内容</param>
        /// <param name="files">附件</param>
        /// <param name="prosituation">处理情况/方案/进程</param>
        /// <param name="dealcontact">承办人联系方式</param>
        /// <param name="connecttime">沟通时间</param>
        /// <param name="connectmode">沟通方式</param>
        /// <param name="replycontent">答复内容</param>
        /// <param name="duties">职务</param>
        /// <param name="situation">处理情况</param>
        /// <param name="state">0保存，1保存并办理</param>
        /// <param name="feedbackid"></param>
        /// <param name="isproresult">是否有处理结果:0默认，1是，2否</param>
        /// <param name="isstaisfied">是否满意:0未评价，1满意，2基本满意，3不满意</param>
        /// <returns></returns>
        public string FeedBackWorkOrderBYDock(string usercode, string workorderid, string dealman, string result, string files, string prosituation, string dealcontact, string connecttime, string connectmode, string replycontent, string duties, string situation, int state = 0, int feedbackid = 0, int isproresult = 0, int isstaisfied = 0)
        {
            var returns = "";
            using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
            {
                string optmsg = ""; var assid = 0; var msgend = ""; var wostate = 0; var userinfo = ""; string backid = string.Empty; var msgss = ""; var retbool = "false";
                Model.T_Sys_UserAccount User = userBLL.GetModel(usercode);
                if (User != null)
                {
                    userinfo = User.depname + "-" + User.F_UserName + "(" + User.F_UserCode + ")";
                    Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                    Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                    Model.T_Bus_Feedback modelT_Bus_Feedback = new Model.T_Bus_Feedback();
                    msgend = "，工单编号：" + workorderid;
                    int type = 0; var resmsg = ""; string typemsg = "办理";
                    if (modelT_Bus_WorkOrder == null)
                        msgss = "要办理的工单已不存在";
                    else if (modelT_Bus_AssignedInfo == null)
                    {
                        msgss = "工单无法处理";
                    }
                    else
                    {
                        type = AssignDeptType(modelT_Bus_AssignedInfo, User.F_DeptId);
                        if (type > 0)
                        {
                            #region 办理结果合成
                            result = "";
                            #region 获取部门
                            var deptname = "";
                            if (modelT_Bus_WorkOrder.F_MainDeptId != null)
                            {
                                var deptmodel = new BLL.T_Sys_Department().GetModel(modelT_Bus_WorkOrder.F_MainDeptId.Value);
                                if (deptmodel != null)
                                    deptname = deptmodel.F_DeptName;
                            }
                            #endregion
                            #region 获取来源
                            var sourcename = "";
                            if (modelT_Bus_WorkOrder.F_InfoSource != null)
                            {
                                var dicmodel = new BLL.T_Sys_DictionaryValue().GetModel(modelT_Bus_WorkOrder.F_InfoSource.Value);
                                if (dicmodel != null)
                                    sourcename = dicmodel.F_Value;
                            }
                            #endregion
                            var startstr = modelT_Bus_WorkOrder.F_CreateTime + " " + deptname + "部门接到" + sourcename + "来源工单（编号：" + modelT_Bus_WorkOrder.F_WorkOrderId + "）反映" + modelT_Bus_WorkOrder.F_ComTitle + "问题，";
                            var bljg = ""; var endstr = "";
                            if (isproresult == 1)
                            {
                                bljg = "已办理";
                                if (modelT_Bus_WorkOrder.F_IsProtect == 0)
                                {
                                    var isStaisfiedRadioData = "未评价";
                                    if (isstaisfied == 1)
                                    {
                                        isStaisfiedRadioData = "满意";
                                    }
                                    else if (isstaisfied == 2)
                                    {
                                        isStaisfiedRadioData = "基本满意";
                                    }
                                    else if (isstaisfied == 3)
                                    {
                                        isStaisfiedRadioData = "不满意";
                                    }
                                    endstr = "; " + dealman + "用" + connectmode + "方式在" + connecttime + "对反映人进行了回复，反映人对结果表示" + isStaisfiedRadioData;
                                }
                            }
                            else if (isproresult == 2)
                            {
                                bljg = "未办理";
                                endstr = "; 处理方案/进程：" + prosituation;
                            }
                            result = startstr + "经落实，具体情况回复如下：" + situation + " 办理结果：" + bljg + " 承办人：" + dealman + " 职务：" + duties + " 联系电话：" + dealcontact + endstr;
                            #endregion
                            if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.dealing)
                            {
                                #region 处理办理
                                if (feedbackid == 0)
                                {
                                    #region 插入反馈记录
                                    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_DealUser = dealman;
                                    modelT_Bus_Feedback.F_Result = result;//反馈内容
                                    #region 20200114新增字段 zhengbingbing
                                    modelT_Bus_Feedback.F_IsProResult = isproresult;//是否有处理结果:0默认，1是，2否
                                    modelT_Bus_Feedback.F_ProSituation = prosituation;//处理情况/方案/进程
                                    modelT_Bus_Feedback.F_IsProtect = modelT_Bus_WorkOrder.F_IsProtect;//是否保密(0:否1:是)
                                    modelT_Bus_Feedback.F_DealUserContact = dealcontact;//承办人联系方式
                                    DateTime contime = DateTime.Now;
                                    if (connecttime != "" && DateTime.TryParse(connecttime, out contime))
                                        modelT_Bus_Feedback.F_ConnectTime = DateTime.Parse(connecttime);//沟通时间
                                    modelT_Bus_Feedback.F_ConnectMode = connectmode;//沟通方式
                                    modelT_Bus_Feedback.F_ReplyContent = replycontent;//答复内容
                                    modelT_Bus_Feedback.F_IsSatisfied = isstaisfied;//是否满意:0未评价，1满意，2基本满意，3不满意
                                    modelT_Bus_Feedback.F_Duties = duties;//职务
                                    modelT_Bus_Feedback.F_Situation = situation;
                                    #endregion
                                    modelT_Bus_Feedback.F_File = files;
                                    modelT_Bus_Feedback.F_IsAudit = 0;
                                    modelT_Bus_Feedback.F_IsDelete = 0;
                                    modelT_Bus_Feedback.F_CreateUser = User.F_UserCode;//办理人
                                    modelT_Bus_Feedback.F_CreateTime = DateTime.Now;//办理时间
                                    modelT_Bus_Feedback.F_CreateDeptId = User.F_DeptId;//办理部门
                                    modelT_Bus_Feedback.F_IsFeedEnd = 1;
                                    modelT_Bus_Feedback.F_State = state;
                                    modelT_Bus_Feedback.F_Type = type;
                                    modelT_Bus_Feedback.F_Id = new BLL.T_Bus_Feedback().Add(modelT_Bus_Feedback);
                                    #endregion
                                }
                                else
                                {
                                    #region 修改反馈记录
                                    modelT_Bus_Feedback = new BLL.T_Bus_Feedback().GetModel(feedbackid);
                                    if (modelT_Bus_Feedback != null)
                                    {
                                        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_DealUser = dealman;
                                        modelT_Bus_Feedback.F_Result = result;//反馈内容
                                        modelT_Bus_Feedback.F_File = files;
                                        #region 20200114新增字段 zhengbingbing
                                        modelT_Bus_Feedback.F_IsProResult = isproresult;//是否有处理结果:0默认，1是，2否
                                        modelT_Bus_Feedback.F_ProSituation = prosituation;//处理情况/方案/进程
                                        modelT_Bus_Feedback.F_IsProtect = modelT_Bus_WorkOrder.F_IsProtect;//是否保密(0:否1:是)
                                        modelT_Bus_Feedback.F_DealUserContact = dealcontact;//承办人联系方式
                                        DateTime contime = DateTime.Now;
                                        if (connecttime != "" && DateTime.TryParse(connecttime, out contime))
                                            modelT_Bus_Feedback.F_ConnectTime = DateTime.Parse(connecttime);//沟通时间
                                        modelT_Bus_Feedback.F_ConnectMode = connectmode;//沟通方式
                                        modelT_Bus_Feedback.F_ReplyContent = replycontent;//答复内容
                                        modelT_Bus_Feedback.F_IsSatisfied = isstaisfied;//是否满意:0未评价，1满意，2基本满意，3不满意
                                        modelT_Bus_Feedback.F_Duties = duties;//职务
                                        modelT_Bus_Feedback.F_Situation = situation;
                                        #endregion
                                        modelT_Bus_Feedback.F_CreateUser = User.F_UserCode;//办理人
                                        modelT_Bus_Feedback.F_CreateTime = DateTime.Now;//办理时间
                                        modelT_Bus_Feedback.F_CreateDeptId = User.F_DeptId;//办理部门
                                        modelT_Bus_Feedback.F_IsFeedEnd = 1;
                                        modelT_Bus_Feedback.F_State = state;

                                        if (modelT_Bus_AssignedInfo.F_MainDeptId == User.F_DeptId)
                                        {
                                            modelT_Bus_Feedback.F_Type = 1;
                                        }
                                        else if (!string.IsNullOrEmpty(modelT_Bus_AssignedInfo.F_OtherDeptIds) && modelT_Bus_AssignedInfo.F_OtherDeptIds.Split(',').Contains(User.F_DeptId.ToString()))
                                        {
                                            modelT_Bus_Feedback.F_Type = 2;
                                        }

                                        new BLL.T_Bus_Feedback().Update(modelT_Bus_Feedback);
                                    }
                                    #endregion
                                }
                                if (modelT_Bus_Feedback != null && modelT_Bus_Feedback.F_State == 1)
                                {
                                    if (type == 1)
                                    {
                                        int iscs = 0;
                                        if (modelT_Bus_AssignedInfo.F_LimitTime < DateTime.Now)
                                        {
                                            iscs = 1;
                                        }

                                        #region 保存工单信息
                                        //modelT_Bus_WorkOrder.F_WorkState = 6;//待回访
                                        modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.dealed;//待回访
                                        modelT_Bus_WorkOrder.F_Result = result;
                                        modelT_Bus_WorkOrder.F_DealDeptId = User.F_DeptId;
                                        modelT_Bus_WorkOrder.F_DealUser = User.F_UserCode;
                                        modelT_Bus_WorkOrder.F_DealTime = DateTime.Now;
                                        modelT_Bus_WorkOrder.F_IsOverdue = iscs;
                                        workorderBLL.Update(modelT_Bus_WorkOrder);
                                        #endregion

                                        #region 保存交办信息
                                        modelT_Bus_AssignedInfo.F_FeedbackTime = DateTime.Now;
                                        if (modelT_Bus_AssignedInfo.F_LimitTime < DateTime.Now)
                                        {
                                            modelT_Bus_AssignedInfo.F_IsOverdue = 1;
                                        }

                                        assignBLL.Update(modelT_Bus_AssignedInfo);
                                        #endregion

                                        #region 删除草稿信息
                                        var cglist = new BLL.T_Bus_Feedback().GetModelList(" F_IsDelete=0 and F_State=0 and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and F_CreateDeptId='" + User.F_DeptId + "'");

                                        foreach (var cg in cglist)
                                        {
                                            cg.F_IsDelete = 1;
                                            cg.F_DeleteUser = User.F_UserCode;
                                            cg.F_DeleteTime = DateTime.Now;

                                            new BLL.T_Bus_Feedback().Update(cg);
                                        }
                                        #endregion

                                        #region 删除二级单位未办理信息
                                        var ejlist = new BLL.T_Bus_AssignedInfo_Next().GetModelList(" F_IsDelete=0 and isnull(F_FeedbackTime,'')='' and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "'");
                                        foreach (var ej in ejlist)
                                        {
                                            ej.F_IsDelete = 1;
                                            ej.F_DeleteUser = User.F_UserCode;
                                            ej.F_DeleteTime = DateTime.Now;

                                            new BLL.T_Bus_AssignedInfo_Next().Update(ej);
                                        }
                                        #endregion

                                        #region 处理协办单位
                                        var xblist = new BLL.T_Bus_AssignedItemInfo().GetModelList(" F_IsDelete=0 and F_State=1 and  ISNULL(F_FeedbackTime, '')='' and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "'");
                                        foreach (var xb in xblist)
                                        {
                                            xb.F_State = 2;
                                            xb.F_SureUser = User.F_UserCode;
                                            xb.F_SureTime = DateTime.Now;

                                            new BLL.T_Bus_AssignedItemInfo().Update(xb);
                                        }
                                        #endregion

                                        typemsg = "主办";
                                    }
                                    else if (type == 2)
                                    {
                                        #region 保存明细信息
                                        Model.T_Bus_AssignedItemInfo modelT_Bus_AssignedItemInfo = new BLL.T_Bus_AssignedItemInfo().GetModelList(" F_IsDelete=0 and F_State=1 and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and F_DeptId='" + User.F_DeptId + "'").FirstOrDefault();
                                        modelT_Bus_AssignedItemInfo.F_FeedbackTime = DateTime.Now;
                                        if (modelT_Bus_AssignedItemInfo.F_LimitTime < DateTime.Now)
                                        {
                                            modelT_Bus_AssignedItemInfo.F_IsOverdue = 1;
                                        }

                                        new BLL.T_Bus_AssignedItemInfo().Update(modelT_Bus_AssignedItemInfo);
                                        #endregion

                                        #region 删除草稿信息
                                        var cglist = new BLL.T_Bus_Feedback().GetModelList(" F_IsDelete=0 and F_State=0 and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and F_CreateDeptId='" + User.F_DeptId + "'");

                                        foreach (var cg in cglist)
                                        {
                                            cg.F_IsDelete = 1;
                                            cg.F_DeleteUser = User.F_UserCode;
                                            cg.F_DeleteTime = DateTime.Now;

                                            new BLL.T_Bus_Feedback().Update(cg);
                                        }
                                        #endregion

                                        typemsg = "协办";
                                    }

                                    var msgs = userinfo + " " + resmsg + " " + typemsg + "了工单";
                                    //推送消息表
                                    msg.AddInternalMessagesInfo("工单消息", msgs + "，工单编号：" + workorderid, modelT_Bus_WorkOrder.F_CreateUser, User.F_UserCode, (int)EnumSmsType.workorder);
                                }
                                #endregion
                                retbool = "true";
                            }
                            else
                                msgss = "工单已办理";
                            backid = modelT_Bus_Feedback.F_Id.ToString();
                        }
                        else
                            msgss = "工单已办理或已被重新指派";
                        assid = modelT_Bus_AssignedInfo.F_Id;
                        wostate = modelT_Bus_WorkOrder.F_WorkState.Value;
                    }
                    msgend = resmsg + " " + typemsg + "了工单";
                }
                else
                {
                    userinfo = "无法获取工号信息，工号为" + usercode + msgend;
                    msgss = "无法获取工号信息";
                }
                #region 插入操作记录
                Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                oper.F_WorkOrderId = workorderid;
                oper.F_AssignedId = assid;
                oper.F_State = wostate;
                oper.F_Message = userinfo + msgend;
                oper.F_CreateUser = usercode;
                oper.F_CreateTime = DateTime.Now;
                oper.F_IsDelete = 0;
                oper.F_Type = 1;
                oper.F_File = files;
                operBLL.Add(oper);

                #endregion
                trans.Complete();
                returns = retbool + "|" + backid + "|" + msgss;
            }
            return returns;
        }
        /// <summary>
        /// 对接网格化，记录办理过程
        /// </summary>
        /// <param name="usercode"></param>
        /// <param name="workorderid"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public string DealProcessWorkOrderByDock(string usercode, string workorderid, string content)
        {
            var returns = "";
            using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
            {
                var assid = 0; var msgend = ""; var state = 0; var userinfo = ""; var msgss = ""; var optid = string.Empty; var retbool = "false";
                Model.T_Sys_UserAccount User = userBLL.GetModel(usercode);
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                msgend = "，工单编号：" + workorderid + "，办理内容为：" + content;
                if (User != null)
                {
                    if (modelT_Bus_WorkOrder == null)
                        msgss = "要办理的工单已不存在";
                    else if (modelT_Bus_AssignedInfo == null)
                    {
                        msgss = "工单无法处理或已被处理";
                    }
                    else
                    {
                        if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.dealing && modelT_Bus_AssignedInfo.F_IsSure == 1 && modelT_Bus_AssignedInfo.F_MainDeptId == User.F_DeptId)
                        {
                            msgss = "办理工单";
                            retbool = "true";
                            assid = modelT_Bus_AssignedInfo.F_Id;
                            state = modelT_Bus_WorkOrder.F_WorkState.Value;
                        }
                        else
                        {
                            msgss = "工单无法处理";
                        }
                    }
                    userinfo = User.depname + "-" + User.F_UserName + "(" + User.F_UserCode + ")";
                }
                else
                {
                    userinfo = "无法获取工号信息，工号为" + usercode + msgend;
                    msgss = "无法获取工号信息";
                }
                #region 插入操作记录
                Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                oper.F_WorkOrderId = workorderid;
                oper.F_AssignedId = assid;
                oper.F_State = state;
                oper.F_Message = userinfo + msgend;
                oper.F_CreateUser = usercode;
                oper.F_CreateTime = DateTime.Now;
                oper.F_IsDelete = 0;
                oper.F_Type = 1;

                optid = operBLL.Add(oper).ToString();
                #endregion
                trans.Complete();
                returns = retbool + "|" + optid + "|" + msgss;
            }
            return returns;
        }
        #endregion


        /// <summary>
        /// 撤回工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult WithdrawWorkOrder()
        {
            if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("workorderid");

                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                Model.T_Bus_AssignedInfo_Next modelT_Bus_AssignedInfo_Next = new BLL.T_Bus_AssignedInfo_Next().GetNewModelByWorkOrderID(workorderid);

                if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo_Next != null && modelT_Bus_AssignedInfo.F_MainDeptId == User.F_DeptId)
                {

                    using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                    {
                        #region 保存撤单信息
                        modelT_Bus_AssignedInfo_Next.F_IsDelete = 1;
                        modelT_Bus_AssignedInfo_Next.F_DeleteUser = User.F_UserCode;
                        modelT_Bus_AssignedInfo_Next.F_DeleteTime = DateTime.Now;
                        new BLL.T_Bus_AssignedInfo_Next().Update(modelT_Bus_AssignedInfo_Next);
                        #endregion

                        #region 删除处理信息
                        var cglist = new BLL.T_Bus_Feedback_Next().GetModelList(" F_IsDelete=0 and F_AssignedId='" + modelT_Bus_AssignedInfo_Next.F_Id + "'");

                        foreach (var cg in cglist)
                        {
                            cg.F_IsDelete = 1;
                            cg.F_DeleteUser = User.F_UserCode;
                            cg.F_DeleteTime = DateTime.Now;

                            new BLL.T_Bus_Feedback_Next().Update(cg);
                        }
                        #endregion

                        #region 保存交办信息
                        modelT_Bus_AssignedInfo.F_IsNext = 0;
                        new BLL.T_Bus_AssignedInfo().Update(modelT_Bus_AssignedInfo);
                        #endregion
                        #region 保存工单信息
                        Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                        keyValuePairs.Add("F_MainDeptID3", null);
                        //modelT_Bus_WorkOrder.F_MainDeptID3 = null;
                        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_AssignedId = modelT_Bus_AssignedInfo_Next.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);
                        #endregion

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

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

        /// <summary>
        /// 签收工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult SignWorkOrder()
        {
            if (User.F_RoleCode == "EJWLDW" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("workorderid");

                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                Model.T_Bus_AssignedInfo_Next modelT_Bus_AssignedInfo_Next = new BLL.T_Bus_AssignedInfo_Next().GetNewModelByWorkOrderID(workorderid);

                if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo_Next != null && modelT_Bus_AssignedInfo_Next.F_MainDeptId == User.F_DeptId)
                {
                    if (modelT_Bus_AssignedInfo_Next.F_IsSure == 0)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            #region 保存签收信息
                            modelT_Bus_AssignedInfo_Next.F_IsSure = 1;//签收
                            modelT_Bus_AssignedInfo_Next.F_SureUser = User.F_UserCode;
                            modelT_Bus_AssignedInfo_Next.F_SureTime = DateTime.Now;
                            new BLL.T_Bus_AssignedInfo_Next().Update(modelT_Bus_AssignedInfo_Next);
                            #endregion

                            #region 保存交办信息
                            modelT_Bus_AssignedInfo.F_IsNext = 2;
                            new BLL.T_Bus_AssignedInfo().Update(modelT_Bus_AssignedInfo);
                            #endregion
                            if (!string.IsNullOrEmpty(modelT_Bus_AssignedInfo_Next.F_OtherDeptIds))
                            {
                                if (modelT_Bus_AssignedInfo_Next.F_OtherDeptIds != "null")
                                {
                                    string[] strids = modelT_Bus_AssignedInfo_Next.F_OtherDeptIds.TrimEnd(',').Split(',');
                                    foreach (string strid in strids)
                                    {
                                        Model.T_Bus_AssignedItemInfo modelT_Bus_AssignedItemInfo = new Model.T_Bus_AssignedItemInfo();
                                        modelT_Bus_AssignedItemInfo.F_AssignedId = modelT_Bus_AssignedInfo_Next.F_Id;
                                        modelT_Bus_AssignedItemInfo.F_AssignedOpinion = modelT_Bus_AssignedInfo_Next.F_AssignedOpinion;
                                        modelT_Bus_AssignedItemInfo.F_DeptId = Int32.Parse(strid);
                                        modelT_Bus_AssignedItemInfo.F_LimitTime = modelT_Bus_AssignedInfo_Next.F_LimitTime;
                                        modelT_Bus_AssignedItemInfo.F_Remark = modelT_Bus_AssignedInfo_Next.F_Remark;
                                        modelT_Bus_AssignedItemInfo.F_State = 1;
                                        modelT_Bus_AssignedItemInfo.F_Type = 2;
                                        modelT_Bus_AssignedItemInfo.F_WorkOrderId = modelT_Bus_AssignedInfo_Next.F_WorkOrderId;
                                        modelT_Bus_AssignedItemInfo.F_IsSure = 0;
                                        modelT_Bus_AssignedItemInfo.F_CreateTime = DateTime.Now;
                                        modelT_Bus_AssignedItemInfo.F_CreateUser = User.F_UserCode;
                                        modelT_Bus_AssignedItemInfo.F_IsDelete = 0;

                                        new BLL.T_Bus_AssignedItemInfo().Add(modelT_Bus_AssignedItemInfo);

                                    }
                                }
                            }
                            #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_Next.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);
                            #endregion

                            trans.Complete();
                        }
                        return Success("操作成功");
                    }
                    else
                    {
                        return Error("单位已签收，不能再次签收");
                    }
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }

        /// <summary>
        /// 拒收工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult RefuseWorkOrder()
        {




            if (User.F_RoleCode == "EJWLDW" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                string reason = RequestString.GetFormString("reason");

                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                Model.T_Bus_AssignedInfo_Next modelT_Bus_AssignedInfo_Next = new BLL.T_Bus_AssignedInfo_Next().GetNewModelByWorkOrderID(workorderid);

                if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo_Next != null && modelT_Bus_AssignedInfo_Next.F_MainDeptId == User.F_DeptId)
                {
                    if (modelT_Bus_AssignedInfo_Next.F_IsSure == 0
                        || modelT_Bus_AssignedInfo_Next.F_IsSure == 1)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            #region 保存签收信息
                            modelT_Bus_AssignedInfo_Next.F_IsSure = 3;//签收
                            modelT_Bus_AssignedInfo_Next.F_SureUser = User.F_UserCode;
                            modelT_Bus_AssignedInfo_Next.F_SureTime = DateTime.Now;
                            new BLL.T_Bus_AssignedInfo_Next().Update(modelT_Bus_AssignedInfo_Next);
                            #endregion

                            #region 保存交办信息
                            //三级单位退单
                            modelT_Bus_AssignedInfo.F_IsNext = 4;

                            new BLL.T_Bus_AssignedInfo().Update(modelT_Bus_AssignedInfo);
                            #endregion
                            #region 保存工单信息

                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            keyValuePairs.Add("F_MainDeptID3", null);
                            //modelT_Bus_WorkOrder.F_MainDeptID3 = null;
                            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_AssignedId = modelT_Bus_AssignedInfo_Next.F_Id;
                            oper.F_State = modelT_Bus_WorkOrder.F_WorkState;

                            string userinfo = User.depname + "(" + User.F_UserCode + ")";
                            oper.F_Message = userinfo + " 拒收了工单，原因：" + reason;
                            oper.F_CreateUser = User.F_UserCode;
                            oper.F_CreateTime = DateTime.Now;
                            oper.F_IsDelete = 0;

                            operBLL.Add(oper);
                            #endregion
                            var user = new BLL.T_Sys_UserAccount().GetModelList("F_DeptId=" + modelT_Bus_WorkOrder.F_MainDeptId + " ");
                            if (user != null && user.Count > 0)
                            {
                                foreach (var it in user)
                                {
                                    string count = "工单" + workorderid + "已被退回至本单位，请及时转派处理！";
                                  //  string msg = workorderid;
                                   // bool n = SMSController.AddSmS(0, msg, count, it.F_Mobile, "181769", "");

                                    string mag = "[\"" + workorderid + "\"]";
                                    string v = SmsNewController.AddSmS(0, count, it.F_Mobile, "681240428561600512", mag,
                                   workorderid);
                                }
                            }
                            //三级单位退回工单给二级单位时，增加短信提醒


                            //三级单位退回工单给二级单位时，增加短信提醒
                            trans.Complete();
                        }
                        return Success("操作成功");
                    }
                    else
                    {
                        return Error("单位未拒收");
                    }
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }
        /// <summary>
        /// 拒绝工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult RejectWorkOrder()
        {




            if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                string reason = RequestString.GetFormString("reason");

                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                Model.T_Bus_AssignedInfo_Next modelT_Bus_AssignedInfo_Next = new BLL.T_Bus_AssignedInfo_Next().GetNewModelByWorkOrderID(workorderid);
                ;
                if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo_Next != null
                    && modelT_Bus_AssignedInfo.F_MainDeptId == User.F_DeptId)
                {
                    if (modelT_Bus_AssignedInfo_Next.F_IsSure == 3)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            #region 保存签收信息
                            modelT_Bus_AssignedInfo_Next.F_IsSure = 0;
                            //  modelT_Bus_AssignedInfo_Next.F_SureUser = User.F_UserCode;
                            //  modelT_Bus_AssignedInfo_Next.F_SureTime = DateTime.Now;
                            new BLL.T_Bus_AssignedInfo_Next().Update(modelT_Bus_AssignedInfo_Next);
                            #endregion

                            #region 保存交办信息
                            //三级单位退单
                            modelT_Bus_AssignedInfo.F_IsNext = 1;

                            new BLL.T_Bus_AssignedInfo().Update(modelT_Bus_AssignedInfo);
                            #endregion
                            #region 保存工单信息
                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            keyValuePairs.Add("F_MainDeptID3", modelT_Bus_AssignedInfo_Next.F_MainDeptId.ToString());
                            //modelT_Bus_WorkOrder.F_MainDeptID3 = null;
                            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_AssignedId = modelT_Bus_AssignedInfo_Next.F_Id;
                            oper.F_State = modelT_Bus_WorkOrder.F_WorkState;

                            string userinfo = User.depname + "(" + User.F_UserCode + ")";
                            oper.F_Message = userinfo + " 拒绝了工单，原因：" + reason;
                            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("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }
        /// <summary>
        /// 二级单位退回工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult BackWorkOrder()
        {




            if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "GLY" || User.F_RoleCode == "EJWLDW")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                string reason = RequestString.GetFormString("reason");

                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                Model.T_Bus_AssignedInfo_Next modelT_Bus_AssignedInfo_Next = new BLL.T_Bus_AssignedInfo_Next().GetNewModelByWorkOrderID(workorderid);
                ;
                if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo_Next != null
                    && modelT_Bus_AssignedInfo.F_MainDeptId == User.F_DeptId)
                {
                    if (modelT_Bus_AssignedInfo_Next.F_FeedbackTime != null)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            #region 
                            modelT_Bus_AssignedInfo_Next.F_FeedbackTime = null;
                            modelT_Bus_AssignedInfo_Next.F_IsSure = 0;
                            //  modelT_Bus_AssignedInfo_Next.F_SureUser = User.F_UserCode;
                            //  modelT_Bus_AssignedInfo_Next.F_SureTime = DateTime.Now;
                            new BLL.T_Bus_AssignedInfo_Next().Update(modelT_Bus_AssignedInfo_Next);
                            #endregion

                            #region 
                            //三级单位退单
                            modelT_Bus_AssignedInfo.F_IsNext = 1;

                            new BLL.T_Bus_AssignedInfo().Update(modelT_Bus_AssignedInfo);
                            #endregion
                            #region 保存工单信息
                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            keyValuePairs.Add("F_MainDeptID3", modelT_Bus_AssignedInfo_Next.F_MainDeptId.ToString());
                            //modelT_Bus_WorkOrder.F_MainDeptID3 = null;
                            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_AssignedId = modelT_Bus_AssignedInfo_Next.F_Id;
                            oper.F_State = modelT_Bus_WorkOrder.F_WorkState;

                            string userinfo = User.depname + "(" + User.F_UserCode + ")";
                            oper.F_Message = userinfo + " 退回了工单，原因：" + reason;
                            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("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }

        /// <summary>
        /// 处理工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult DealWorkOrder()
        {

            if (User.F_RoleCode == "EJWLDW" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                string dealman = RequestString.GetFormString("dealman");
                string result = RequestString.GetFormString("result");
                string files = RequestString.GetFormString("files");
                int state = RequestString.GetInt("state", 0);
                int dealid = RequestString.GetInt("dealid", 0);
                int isproresult = RequestString.GetInt("isproresult", 0);//是否有处理结果:0默认，1是，2否
                string prosituation = RequestString.GetFormString("prosituation");
                string dealcontact = RequestString.GetFormString("dealcontact");
                string connecttime = RequestString.GetFormString("connecttime");
                string connectmode = RequestString.GetFormString("connectmode");
                string replycontent = RequestString.GetFormString("replycontent");
                int isstaisfied = RequestString.GetInt("isstaisfied", 0);
                string duties = RequestString.GetFormString("duties");//职务
                string situation = RequestString.GetFormString("situation");
                string AuditUser = RequestString.GetFormString("AuditUser");
                string post = RequestString.GetFormString("post");
                string auditContact = RequestString.GetFormString("auditContact");//审核领导职务
                string feedbackreason = RequestString.GetFormString("feedbackReason");//办理操作里 


                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                Model.T_Bus_AssignedInfo_Next modelT_Bus_AssignedInfo_Next = new BLL.T_Bus_AssignedInfo_Next().GetNewModelByWorkOrderID(workorderid);
                Model.T_Bus_Feedback_Next modelT_Bus_Feedback_Next = new Model.T_Bus_Feedback_Next();

                if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo_Next != null && (modelT_Bus_AssignedInfo_Next.F_MainDeptId == User.F_DeptId || modelT_Bus_AssignedInfo_Next
                    .F_OtherDeptIds.Contains(User.F_DeptId.ToString()))
                    && modelT_Bus_AssignedInfo_Next.F_IsSure == 1)
                {
                    //if (modelT_Bus_WorkOrder.F_WorkState == 4 || modelT_Bus_WorkOrder.F_WorkState == 5)
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.dealing || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.auditdelay
                        || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.reload)
                    {
                        if (modelT_Bus_AssignedInfo.F_IsNext == 2)
                        {
                            using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                            {
                                if (dealid == 0)
                                {
                                    #region 插入反馈记录

                                    modelT_Bus_Feedback_Next.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;//工单编号
                                    modelT_Bus_Feedback_Next.F_AssignedId = modelT_Bus_AssignedInfo_Next.F_Id;//交办id
                                    modelT_Bus_Feedback_Next.F_DealUser = dealman;
                                    modelT_Bus_Feedback_Next.F_Result = result;//反馈内容
                                    #region 20200114新增字段 zhengbingbing
                                    modelT_Bus_Feedback_Next.F_IsProResult = isproresult;//是否有处理结果:0默认，1是，2否
                                    modelT_Bus_Feedback_Next.F_ProSituation = prosituation;//处理情况/方案/进程
                                    modelT_Bus_Feedback_Next.F_IsProtect = modelT_Bus_WorkOrder.F_IsProtect;//是否保密(0:否1:是)
                                    modelT_Bus_Feedback_Next.F_DealUserContact = dealcontact;//承办人联系方式
                                    DateTime contime = DateTime.Now;
                                    if (connecttime != "" && DateTime.TryParse(connecttime, out contime))
                                        modelT_Bus_Feedback_Next.F_ConnectTime = DateTime.Parse(connecttime);//沟通时间
                                    modelT_Bus_Feedback_Next.F_ConnectMode = connectmode;//沟通方式
                                    modelT_Bus_Feedback_Next.F_ReplyContent = replycontent;//答复内容
                                    modelT_Bus_Feedback_Next.F_IsSatisfied = isstaisfied;//是否满意:0未评价，1满意，2基本满意，3不满意
                                    modelT_Bus_Feedback_Next.F_Duties = duties;//职务
                                    modelT_Bus_Feedback_Next.F_Situation = situation;
                                    #endregion
                                    modelT_Bus_Feedback_Next.F_File = files;
                                    modelT_Bus_Feedback_Next.F_IsAudit = 0;
                                    modelT_Bus_Feedback_Next.F_AuditUser = AuditUser;
                                    modelT_Bus_Feedback_Next.F_AuditPost = post;

                                    modelT_Bus_Feedback_Next.F_IsDelete = 0;
                                    modelT_Bus_Feedback_Next.F_CreateUser = User.F_UserCode;//办理人
                                    modelT_Bus_Feedback_Next.F_CreateTime = DateTime.Now;//办理时间
                                    modelT_Bus_Feedback_Next.F_CreateDeptId = User.F_DeptId;//办理部门
                                    modelT_Bus_Feedback_Next.F_IsFeedEnd = 1;
                                    modelT_Bus_Feedback_Next.F_State = state;
                                    modelT_Bus_Feedback_Next.F_Type = 1;
                                    modelT_Bus_Feedback_Next.F_AuditContact = auditContact;
                                    modelT_Bus_Feedback_Next.F_FeedbackReason = feedbackreason;
                                    new BLL.T_Bus_Feedback_Next().Add(modelT_Bus_Feedback_Next);
                                    #endregion
                                }
                                else
                                {
                                    #region 修改反馈记录
                                    modelT_Bus_Feedback_Next = new BLL.T_Bus_Feedback_Next().GetModel(dealid);
                                    if (modelT_Bus_Feedback_Next != null)
                                    {
                                        modelT_Bus_Feedback_Next.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;//工单编号
                                        modelT_Bus_Feedback_Next.F_AssignedId = modelT_Bus_AssignedInfo_Next.F_Id;//交办id
                                        modelT_Bus_Feedback_Next.F_DealUser = dealman;
                                        modelT_Bus_Feedback_Next.F_Result = result;//反馈内容
                                        modelT_Bus_Feedback_Next.F_File = files;
                                        #region 20200114新增字段 zhengbingbing
                                        modelT_Bus_Feedback_Next.F_IsProResult = isproresult;//是否有处理结果:0默认，1是，2否
                                        modelT_Bus_Feedback_Next.F_ProSituation = prosituation;//处理情况/方案/进程
                                        modelT_Bus_Feedback_Next.F_IsProtect = modelT_Bus_WorkOrder.F_IsProtect;//是否保密(0:否1:是)
                                        modelT_Bus_Feedback_Next.F_DealUserContact = dealcontact;//承办人联系方式
                                        DateTime contime = DateTime.Now;
                                        if (connecttime != "" && DateTime.TryParse(connecttime, out contime))
                                            modelT_Bus_Feedback_Next.F_ConnectTime = DateTime.Parse(connecttime);//沟通时间
                                        modelT_Bus_Feedback_Next.F_ConnectMode = connectmode;//沟通方式
                                        modelT_Bus_Feedback_Next.F_ReplyContent = replycontent;//答复内容
                                        modelT_Bus_Feedback_Next.F_IsSatisfied = isstaisfied;//是否满意:0未评价，1满意，2基本满意，3不满意
                                        modelT_Bus_Feedback_Next.F_Duties = duties;//职务
                                        modelT_Bus_Feedback_Next.F_Situation = situation;
                                        #endregion
                                        modelT_Bus_Feedback_Next.F_CreateUser = User.F_UserCode;//办理人
                                        modelT_Bus_Feedback_Next.F_AuditUser = AuditUser;
                                        modelT_Bus_Feedback_Next.F_CreateTime = DateTime.Now;//办理时间
                                        modelT_Bus_Feedback_Next.F_CreateDeptId = User.F_DeptId;//办理部门
                                        modelT_Bus_Feedback_Next.F_IsFeedEnd = 1;
                                        modelT_Bus_Feedback_Next.F_State = state;
                                        modelT_Bus_Feedback_Next.F_FeedbackReason = feedbackreason;

                                        new BLL.T_Bus_Feedback_Next().Update(modelT_Bus_Feedback_Next);
                                    }
                                    #endregion
                                }

                                if (modelT_Bus_Feedback_Next != null && modelT_Bus_Feedback_Next.F_State == 1)
                                {
                                    #region 保存交办信息
                                    modelT_Bus_AssignedInfo.F_IsNext = 3;
                                    new BLL.T_Bus_AssignedInfo().Update(modelT_Bus_AssignedInfo);
                                    #endregion

                                    #region 保存派单信息
                                    modelT_Bus_AssignedInfo_Next.F_FeedbackTime = DateTime.Now;
                                    if (modelT_Bus_AssignedInfo_Next.F_LimitTime < DateTime.Now)
                                    {
                                        modelT_Bus_AssignedInfo_Next.F_IsOverdue = 1;
                                    }

                                    new BLL.T_Bus_AssignedInfo_Next().Update(modelT_Bus_AssignedInfo_Next);
                                    #endregion

                                    #region 删除草稿信息
                                    var cglist = new BLL.T_Bus_Feedback_Next().GetModelList(" F_IsDelete=0 and F_State=0 and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and F_CreateDeptId='" + User.F_DeptId + "'");

                                    foreach (var cg in cglist)
                                    {
                                        cg.F_IsDelete = 1;
                                        cg.F_DeleteUser = User.F_UserCode;
                                        cg.F_DeleteTime = DateTime.Now;

                                        new BLL.T_Bus_Feedback_Next().Update(cg);
                                    }
                                    #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_Next.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);
                                  
                                    //推送消息表
                                    msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, modelT_Bus_WorkOrder.F_CreateUser, User.F_UserCode, (int)EnumSmsType.workorder);
                                    #endregion
                                }

                                trans.Complete();
                            }

                            return Success("操作成功", modelT_Bus_AssignedInfo_Next.F_Id);
                        }
                        else
                        {
                            return Error("已经办理过了");
                        }
                    }
                    else
                    {
                        return Error("已经办理过了");
                    }
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }
        private BLL.T_Cus_CustomerBase cusBLL = new BLL.T_Cus_CustomerBase();
        /// <summary>
        /// 保存客户档案
        /// </summary>
        /// <param name="telphone"></param>
        /// <param name="name"></param>
        /// <param name="phone"></param>
        /// <param name="countryid"></param>
        /// <param name="address"></param>
        /// <returns></returns>
        private void saveCus(string name, string phone, string address)
        {
            int res = 0;
            Model.T_Cus_CustomerBase cusmodel = new Model.T_Cus_CustomerBase();
            if (!string.IsNullOrWhiteSpace(phone))
            {
                cusmodel = cusBLL.GetModelBy(phone, name);
                if (cusmodel == null)
                {
                    cusmodel = new Model.T_Cus_CustomerBase();
                    cusmodel.F_Address = address;
                    cusmodel.F_CustomerName = name;
                    cusmodel.F_Mobile = phone;
                    cusmodel.F_DeleteFlag = 0;
                    res = cusBLL.Add(cusmodel);
                }
            }
        }
        /// <summary>
        /// 审核派单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult AuditSplitWorkOrder()
        {
            if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int state = RequestString.GetInt("state", 0);
                string reason = RequestString.GetFormString("reason");
                int backid = RequestString.GetInt("backid", 0);
                string files = RequestString.GetFormString("files");

                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                Model.T_Bus_Feedback_Next modelT_Bus_Feedback_Next = new BLL.T_Bus_Feedback_Next().GetModel(backid);
                if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo != null && modelT_Bus_Feedback_Next != null)
                {
                    if (modelT_Bus_Feedback_Next.F_IsAudit.Value == 0)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            modelT_Bus_Feedback_Next.F_IsAudit = state;
                            modelT_Bus_Feedback_Next.F_AuditUser = User.F_UserCode;
                            modelT_Bus_Feedback_Next.F_AuditTime = DateTime.Now;
                            modelT_Bus_Feedback_Next.F_AuditReason = reason;
                            new BLL.T_Bus_Feedback_Next().Update(modelT_Bus_Feedback_Next);

                            string strmsg = "";
                            string message = User.F_UserName + "于时间（" + DateTime.Now.ToString("yyyy年MM月dd日 HH时mm分ss秒") + "）回复：" + modelT_Bus_Feedback_Next.F_Result; ;
                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            if (state == 1)
                            {
                                strmsg = "同意";

                                #region 插入反馈记录
                                Model.T_Bus_Feedback modelT_Bus_Feedback = new Model.T_Bus_Feedback();
                                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_DealUser = modelT_Bus_Feedback_Next.F_DealUser;
                                modelT_Bus_Feedback.F_Result = message;//反馈内容
                                #region 20200114新增字段 zhengbingbing
                                modelT_Bus_Feedback.F_IsProResult = modelT_Bus_Feedback_Next.F_IsProResult;//是否有处理结果:0默认，1是，2否
                                modelT_Bus_Feedback.F_ProSituation = modelT_Bus_Feedback_Next.F_ProSituation;//处理情况/方案/进程
                                modelT_Bus_Feedback.F_IsProtect = modelT_Bus_Feedback_Next.F_IsProtect;//是否保密(0:否1:是)
                                modelT_Bus_Feedback.F_DealUserContact = modelT_Bus_Feedback_Next.F_DealUserContact;//承办人联系方式
                                modelT_Bus_Feedback.F_ConnectTime = modelT_Bus_Feedback_Next.F_ConnectTime;//沟通时间
                                modelT_Bus_Feedback.F_ConnectMode = modelT_Bus_Feedback_Next.F_ConnectMode;//沟通方式
                                modelT_Bus_Feedback.F_ReplyContent = modelT_Bus_Feedback_Next.F_ReplyContent;//答复内容
                                modelT_Bus_Feedback.F_IsSatisfied = modelT_Bus_Feedback_Next.F_IsSatisfied;//是否满意:0未评价，1满意，2基本满意，3不满意
                                #endregion
                                modelT_Bus_Feedback.F_File = modelT_Bus_Feedback_Next.F_File;
                                modelT_Bus_Feedback.F_IsAudit = 0;
                                modelT_Bus_Feedback.F_IsDelete = 0;
                                modelT_Bus_Feedback.F_CreateUser = User.F_UserCode;//办理人
                                modelT_Bus_Feedback.F_CreateTime = DateTime.Now;//办理时间
                                modelT_Bus_Feedback.F_CreateDeptId = User.F_DeptId;//办理部门
                                modelT_Bus_Feedback.F_IsFeedEnd = 1;
                                modelT_Bus_Feedback.F_State = state;
                                modelT_Bus_Feedback.F_Type = 1;

                                new BLL.T_Bus_Feedback().Add(modelT_Bus_Feedback);
                                #endregion


                                if (modelT_Bus_AssignedInfo.F_LimitTime < DateTime.Now)
                                {
                                    modelT_Bus_AssignedInfo.F_IsOverdue = 1;
                                    keyValuePairs.Add("F_IsOverdue",1);
                                   // modelT_Bus_WorkOrder.F_IsOverdue = 1;
                                }

                                #region 保存工单信息
                                //modelT_Bus_WorkOrder.F_WorkState = 6;//待回访
                                if (modelT_Bus_Feedback.F_IsProResult == 2)
                                {
                                    keyValuePairs.Add("F_IsProResult", 2);
                                    // modelT_Bus_WorkOrder.F_IsProResult = 2;
                                    // modelT_Bus_WorkOrder.F_IsProResultState = IsProResultState;
                                    keyValuePairs.Add("F_Unsuccessful", modelT_Bus_Feedback.F_ProSituation);
                                 //   modelT_Bus_WorkOrder.F_Unsuccessful = modelT_Bus_Feedback.F_ProSituation;
                                }
                                else
                                {
                                    keyValuePairs.Add("F_ToBereply", 1);
                                    keyValuePairs.Add("F_IsProResult", 1);
                                   // modelT_Bus_WorkOrder.F_ToBereply = 1;
                                   // modelT_Bus_WorkOrder.F_IsProResult = 1;
                                }
                                keyValuePairs.Add("F_WorkState", (int)EnumWorkState.dealed);
                                modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.dealed;//待回访
                                keyValuePairs.Add("F_Result", message);
                                //  modelT_Bus_WorkOrder.F_Result = message;

                                keyValuePairs.Add("F_DealDeptId", modelT_Bus_Feedback_Next.F_CreateDeptId);
                                //  modelT_Bus_WorkOrder.F_DealDeptId = modelT_Bus_Feedback_Next.F_CreateDeptId;
                                keyValuePairs.Add("F_DealUser", modelT_Bus_Feedback_Next.F_CreateUser);
                                // modelT_Bus_WorkOrder.F_DealUser = modelT_Bus_Feedback_Next.F_CreateUser;
                                keyValuePairs.Add("F_DealTime", DateTime.Now);
                               // modelT_Bus_WorkOrder.F_DealTime = DateTime.Now;
                                workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);
                                #endregion

                                #region 保存交办信息
                                modelT_Bus_AssignedInfo.F_FeedbackTime = DateTime.Now;

                                assignBLL.Update(modelT_Bus_AssignedInfo);
                                #endregion

                                #region 删除草稿信息
                                var cglist = new BLL.T_Bus_Feedback().GetModelList(" F_IsDelete=0 and F_State=0 and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and F_CreateDeptId='" + User.F_DeptId + "'");

                                foreach (var cg in cglist)
                                {
                                    cg.F_IsDelete = 1;
                                    cg.F_DeleteUser = User.F_UserCode;
                                    cg.F_DeleteTime = DateTime.Now;

                                    new BLL.T_Bus_Feedback().Update(cg);
                                }
                                #endregion

                                #region 处理协办单位
                                var xblist = new BLL.T_Bus_AssignedItemInfo().GetModelList(" F_IsDelete=0 and F_State=1 and  ISNULL(F_FeedbackTime, '')='' and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "'");
                                foreach (var xb in xblist)
                                {
                                    xb.F_State = 2;
                                    xb.F_SureUser = User.F_UserCode;
                                    xb.F_SureTime = DateTime.Now;

                                    new BLL.T_Bus_AssignedItemInfo().Update(xb);
                                }
                                #endregion



                            }
                            else if (state == 2)
                            {
                                strmsg = "拒绝";
                                Model.T_Bus_AssignedInfo_Next modelT_Bus_AssignedInfo_Next1 = new BLL.T_Bus_AssignedInfo_Next().GetModel(modelT_Bus_Feedback_Next.F_AssignedId.Value);
                                modelT_Bus_AssignedInfo_Next1.F_FeedbackTime = null;
                                new BLL.T_Bus_AssignedInfo_Next().Update(modelT_Bus_AssignedInfo_Next1);

                                modelT_Bus_AssignedInfo.F_IsNext = 2;
                                assignBLL.Update(modelT_Bus_AssignedInfo);


                            }

                            #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 + " " + strmsg + "了此处理";
                            if (!string.IsNullOrWhiteSpace(reason))
                                oper.F_Message = oper.F_Message + "，原因：" + reason;
                            oper.F_CreateUser = User.F_UserCode;
                            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, User.F_UserCode, (int)EnumSmsType.workorder);
                            #endregion

                            trans.Complete();
                        }

                        return Success("操作成功");
                    }
                    else
                    {
                        return Error("已经审核过了");
                    }
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }

        /// <summary>
        /// 发送评价短信
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="WorkOrderId"></param>
        /// <returns></returns>
        public void  SendVisits(string phone, string WorkOrderId,string deptname,string code )
        {
            if (!string.IsNullOrEmpty(phone))
            {
                if (phone.Trim().Length > 11)
                    phone = phone.Substring(1, 11);
            }
         
            var model = new BLL.T_Bus_WorkOrder().GetModel(WorkOrderId);
            if (model != null)
            {
                string content = ""; string temp = "680847330371186688";
                if (model.F_InfoSource == 1 || model.F_InfoSource == 3 || model.F_InfoSource == 6)
                    content = "您反映的诉求已有回复，请前往http://12345rx.zwfw.anyang.gov.cn:9999/citizenNode/orderDetails.html?workorderid=" + model.F_WorkOrderId + ",查看办结结果并进行评价，或者拨打12345市长热线来电咨询，谢谢！";
                else
                {
                    temp = "681914832337539072";
                    content = "您反映的诉求已有回复，请前往http://12345rx.zwfw.anyang.gov.cn:9999/citizenNode/orderDetails.html?workorderid=" + model.F_WorkOrderId + ",查看办结结果并进行评价，谢谢！";
                }

                string mag = "[\"http://12345rx.zwfw.anyang.gov.cn:9999/citizenNode/orderDetails.html?workorderid=" + model.F_WorkOrderId + ",\"]";
                string n = SmsNewController.AddSmS(0, content, phone, temp, mag, WorkOrderId);
                if (n == "")
                {
                    Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                    keyValuePairs.Add("F_IsSms", "1");
                    // model.F_IsSms = 1;
                    new BLL.T_Bus_WorkOrder().UpdateWorkOrder(model.F_Id, keyValuePairs);
                    Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                    oper.F_WorkOrderId = model.F_WorkOrderId;
                    oper.F_State = model.F_WorkState;
                    oper.F_CallRecordId = model.F_CallRecordId;
                    oper.F_File = model.F_File;
                    string userinfo = deptname + "(" + code  + ")";
                    oper.F_Message = userinfo + "发送了市民评价短信";

                    oper.F_CreateUser = code;
                    oper.F_CreateTime = DateTime.Now;
                    oper.F_IsDelete = 0;
                    operBLL.Add(oper);
                   
                }
               
               

            }


            
        }

        /// <summary>
        /// 发送评价短信
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="WorkOrderId"></param>
        /// <returns></returns>
        public ActionResult SendVisit(string phone, string WorkOrderId)
        {
            if (!string.IsNullOrEmpty(phone))
            {
                if (phone.Trim().Length > 11)
                    phone = phone.Substring(1, 11);
            }
            else
            {
                return Error("请输入号码");
            }
            var model = new BLL.T_Bus_WorkOrder().GetModel(WorkOrderId);
            if (model != null)
            {
                string content = "";string temp = "680847330371186688";
                if (model.F_InfoSource ==1|| model.F_InfoSource == 3 || model.F_InfoSource == 6)
                    content = "您反映的诉求已有回复，请前往http://12345rx.zwfw.anyang.gov.cn:9999/citizenNode/orderDetails.html?workorderid=" + model .F_WorkOrderId +",查看办结结果并进行评价，或者拨打12345市长热线来电咨询，谢谢！";
                else
                {
                    temp = "681914832337539072";
                   content = "您反映的诉求已有回复，请前往http://12345rx.zwfw.anyang.gov.cn:9999/citizenNode/orderDetails.html?workorderid=" + model.F_WorkOrderId + ",查看办结结果并进行评价，谢谢！";
                }
                  
                string mag = "[\"http://12345rx.zwfw.anyang.gov.cn:9999/citizenNode/orderDetails.html?workorderid=" + model.F_WorkOrderId + ",\"]";
                string n = SmsNewController.AddSmS(0, content, phone, temp, mag, WorkOrderId);
                if (n == "")
                {
                    Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                    keyValuePairs.Add("F_IsSms", "1");
                    // model.F_IsSms = 1;
                    new BLL.T_Bus_WorkOrder().UpdateWorkOrder(model.F_Id, keyValuePairs);
                    Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                    oper.F_WorkOrderId = model.F_WorkOrderId;
                    oper.F_State = model.F_WorkState;
                    oper.F_CallRecordId = model.F_CallRecordId;
                    oper.F_File = model.F_File;
                    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);
                    return Success("发送成功");
                }
                else
                    return Error(n);
             //   if (model.F_InfoSource == 1 || model.F_InfoSource == 2501)
             //   {
             //       //string count = "您反映的诉求已有回复，请前往安阳政务服务官网（https://zwfw.anyang.gov.cn）登录后查看办结结果并对办理情况进行评价，或者拨打12345市长热线来电咨询，谢谢！";
             //       string content = "您提交的" + model.F_ComTitle + "事项的办理结果为：" + model.F_Result + "请于15天内回复：“$" + model.F_Id + "#”+1、满意，2、基本满意，3、不满意+#评议内容，进行评价。（不超过60字）";
             //       string mag = "[\"" + model.F_ComTitle + "\",\"" + model.F_Result + "\",\"" + model.F_Id + "\"]";
             //       string n = SmsNewController.AddSmS(0, content, phone, "660571546305982464", mag, WorkOrderId);
             //       if (n == "")
             //       {
             //           Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
             //           keyValuePairs.Add("F_IsSms", "1");
             //           // model.F_IsSms = 1;
             //           new BLL.T_Bus_WorkOrder().UpdateWorkOrder(model.F_Id, keyValuePairs);
             //           Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
             //           oper.F_WorkOrderId = model.F_WorkOrderId;
             //           oper.F_State = model.F_WorkState;
             //           oper.F_CallRecordId = model.F_CallRecordId;
             //           oper.F_File = model.F_File;
             //           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);
             //           return Success("发送成功");
             //       }
             //       else
             //           return Error(n);
             //   }
             //   else
             //   {
             //      // if (model.F_InfoSource == 2 || model.F_InfoSource == 2458)
             //// {
                      
             //           //string count = "您反映的诉求已有回复，请前往安阳政务服务官网（https://zwfw.anyang.gov.cn）登录后查看办结结果并对办理情况进行评价，或者拨打12345市长热线来电咨询，谢谢！";
             //           string content = "您诉求的诉求已完成，请前往安阳政务服务官网（https://zwfw.anyang.gov.cn），登录后查看办结结果对执行情况进行评价，谢谢";
             //           string n = SmsNewController.AddSmS(0, content, phone, "614918587799461888", "", WorkOrderId);
             //           if (n == "")
             //           {
             //               Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
             //               keyValuePairs.Add("F_IsSms", "1");
             //               // model.F_IsSms = 1;
             //               new BLL.T_Bus_WorkOrder().UpdateWorkOrder(model.F_Id, keyValuePairs);

             //               Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
             //               oper.F_WorkOrderId = model.F_WorkOrderId;
             //               oper.F_State = model.F_WorkState;
             //               oper.F_CallRecordId = model.F_CallRecordId;
             //               oper.F_File = model.F_File;
             //               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);
             //               return Success("发送成功");
             //           }
             //           else
             //               return Error(n);
             //      // }
                   

             //   }
               
            }
               
            
            return Error("发送失败");
        }
     

        /// <summary>
        /// 审核派单
        /// </summary>
        /// <returns></returns>
        public ActionResult AuditDispatch()
        {
            if (User.F_RoleCode == "ZJZY" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "MTDD"||User .F_RoleCode == "DMTSH")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int nexttype = RequestString.GetInt("nexttype", 0);//0审核通过1审核不通过
                string cbreason = RequestString.GetFormString("cbreason");//审核
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
              
                Model.T_Bus_ToExamine modelT_Bus_ToExamine = new BLL .T_Bus_ToExamine().GetNewModelByWorkOrderID(workorderid);
                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = new T_Bus_AssignedInfo();
                if (modelT_Bus_WorkOrder != null)
                {
                    if (modelT_Bus_WorkOrder.F_WorkState ==1|| modelT_Bus_WorkOrder.F_WorkState == 11&& modelT_Bus_ToExamine!=null )
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            modelT_Bus_ToExamine.F_IsDelete = 0;
                            if (nexttype==1)
                            modelT_Bus_ToExamine.F_State = 1;
                            else
                            modelT_Bus_ToExamine.F_State = 0;
                            modelT_Bus_ToExamine.F_Type = nexttype;
                            modelT_Bus_ToExamine.AuditUser  = User.F_UserCode;
                            modelT_Bus_ToExamine.F_Result = cbreason;
                            var n=new BLL.T_Bus_ToExamine().Update (modelT_Bus_ToExamine);
                            if (n)
                            {
                                var opt = "审核通过"; var cbreasons = "";
                                string userinfo = User.depname + "(" + User.F_UserCode + ")";
                                #region 
                                if (nexttype == 1)
                                {
                                    #region 保存工单信息
                                    Dictionary<string, object> keyValuePairs2 = new Dictionary<string, object>();
                                  
                                    keyValuePairs2.Add("F_MainDeptId", null );
                                    workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs2);
                                    #endregion
                                    cbreasons = "，拒绝原因：" + cbreason;
                                    #endregion
                                    Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                                    oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                    oper.F_AssignedId = modelT_Bus_ToExamine.F_AssignedId;
                                    oper.F_State = modelT_Bus_WorkOrder.F_WorkState;
                                    

                                    oper.F_Message = userinfo + " 审核拒绝了工单" + cbreasons;
                                    oper.F_CreateUser = User.F_UserCode;
                                    oper.F_CreateTime = DateTime.Now;
                                    oper.F_IsDelete = 0;

                                    operBLL.Add(oper);
                                }
                               else
                                {
                                    int day = 7;
                                    if (modelT_Bus_ToExamine.F_LimitTime !=null &&modelT_Bus_ToExamine .F_LimitTime >0)
                                    {
                                        day = (int )modelT_Bus_ToExamine.F_LimitTime+1;
                                    }
                                   
                                    DataTable dt = DbHelperSQL.Query("select top "+ day + " F_OffDate from  T_Sys_WorkOFFDays  where F_OffState = 1   and F_OffDate>='" + DateTime.Now + "' order by F_OffDate ").Tables[0];
                                    var resdatetime = dt.Rows[day-1]["F_OffDate"].ToString();
                                    resdatetime = Convert.ToDateTime(resdatetime).ToString("yyyy-MM-dd") + " 23:59:59 ";
                                    var deptlist = new BLL.T_Sys_Department().GetModelList("F_DeptId in (" + modelT_Bus_ToExamine.F_MainDeptId  + ")");
                                    int t = 0;
                                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.resubmit)
                                        t= Int32.Parse(DbHelperSQL.GetSingle("select count(1) from T_Bus_AssignedInfo WITH(NOLOCK) where F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and  F_State=1 and F_IsSure=1 and F_IsDelete=0 and isnull(F_IsReload,0)>0").ToString())+1;

                                  
                                    var curuser = User;
                                    if (deptlist!=null )
                                    {
                                        if (deptlist.Count == 1)
                                        {
                                           
                                            #region 交办一个单位
                                            var maindept = deptlist.FirstOrDefault();
                                            
                                            var premodeldept = department((int)maindept.F_PartentId);
                                            #region 插入交办记录
                                           
                                            modelT_Bus_AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                           
                                                     modelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(resdatetime);

                                                  if (maindept.F_IsDept == 2)
                                                        modelT_Bus_AssignedInfo.F_MainDeptId = premodeldept.F_DeptId;//主办单位id
                                                    else
                                                        modelT_Bus_AssignedInfo.F_MainDeptId = maindept.F_DeptId;

                                                    modelT_Bus_AssignedInfo.F_OtherDeptIds = "";//协办单位id
                                            modelT_Bus_AssignedInfo.F_AssignedOpinion = "请于1小时内与来电人取得联系（匿名除外），并于5个工作日内将办理情况反馈来电人，并将办理结果报市长便民公开电话受理中心，同时做好来电人信息保密工作。（若超期将进行通报；若无故不回复，将转交市委市政府督查局。）";
                                                    modelT_Bus_AssignedInfo.F_State = 1;//0草稿  1正式
                                                    modelT_Bus_AssignedInfo.F_CreateUser = modelT_Bus_ToExamine.F_CreatUser ;
                                                    modelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                                                    modelT_Bus_AssignedInfo.F_IsDelete = 0;
                                                    modelT_Bus_AssignedInfo.F_IsOverdue = 0;
                                                    modelT_Bus_AssignedInfo.F_IsSure = 0;
                                                    modelT_Bus_AssignedInfo.F_IsReload = t ;
                                                    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);
                                                    #endregion
                                            if (modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_State == 1)
                                            {
                                             //   Task.Run(() =>
                                             //   {
                                                    #region 保存工单信息
                                                    Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();


                                                    if (modelT_Bus_WorkOrder.F_Level == 2)
                                                    {
                                                        keyValuePairs1.Add("F_LimitTime", Convert.ToDateTime(resdatetime));
                                                        //modelT_Bus_WorkOrder.F_LimitTime = Convert.ToDateTime(limittimes);
                                                    }
                                                    else
                                                    {
                                                        keyValuePairs1.Add("F_LimitTime", Convert.ToDateTime(resdatetime));
                                                        //  modelT_Bus_WorkOrder.F_LimitTime = Convert.ToDateTime(resdatetime);
                                                    }
                                                    if (maindept.F_IsDept == 2)
                                                    {
                                                        keyValuePairs1.Add("F_MainDeptId", premodeldept.F_DeptId);
                                                        modelT_Bus_WorkOrder.F_MainDeptId = premodeldept.F_DeptId;
                                                    }
                                                    else
                                                    {
                                                        keyValuePairs1.Add("F_MainDeptId", maindept.F_DeptId);
                                                        modelT_Bus_WorkOrder.F_MainDeptId = maindept.F_DeptId;
                                                    }
                                                    if (!string.IsNullOrEmpty(modelT_Bus_ToExamine.F_Content))
                                                    {
                                                        string[] content = modelT_Bus_ToExamine.F_Content.Split('ぶ');
                                                        if (content != null && content.Length > 0)
                                                        {
                                                                string[] deptid = content[0].Split(',');
                                                                if (deptid != null && deptid.Length > 0)
                                                                {
                                                            keyValuePairs1.Add("F_Content", content[0].Remove(0, deptid[0].Length + 1));
                                                                }
                                                        }
                                                    }




                                              
                                                    keyValuePairs1.Add("F_OtherDeptIds", "");
                                                    // modelT_Bus_WorkOrder.F_OtherDeptIds = otherdeptids;
                                                    keyValuePairs1.Add("F_AssignUser", modelT_Bus_ToExamine.F_CreatUser);
                                                    // modelT_Bus_WorkOrder.F_AssignUser = curuser.F_UserCode;
                                                    keyValuePairs1.Add("F_AssignTime", DateTime.Now);
                                                    // modelT_Bus_WorkOrder.F_AssignTime = DateTime.Now;
                                                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.resubmit)
                                                    {
                                                        keyValuePairs1.Add("F_IsReload", t);
                                                        keyValuePairs1.Add("F_IsOverdue", 0);
                                                      
                                                        keyValuePairs1.Add("F_WorkState", (int)EnumWorkState.reload);
                                                        modelT_Bus_WorkOrder.F_WorkState=8;
                                                    }
                                                    else
                                                    {
                                                        if (maindept.F_IsDept == 2)
                                                        {
                                                            modelT_Bus_WorkOrder.F_WorkState = 4;
                                                            keyValuePairs1.Add("F_WorkState", 4);
                                                        }

                                                        else
                                                        {
                                                            modelT_Bus_WorkOrder.F_WorkState = 2;
                                                            keyValuePairs1.Add("F_WorkState", 2);
                                                        }
                                                    }
                                                      
                                                    keyValuePairs1.Add("F_IsSendBack", 0);
                                                    // modelT_Bus_WorkOrder.F_IsSendBack = 0;
                                                    workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs1);

                                                    #endregion
                                             //   }).ContinueWith(q =>
                                               // {
                                                    string DeptName = "";
                                                    if (maindept.F_IsDept == 2)
                                                    {
                                                        DeptName = premodeldept.F_DeptName;
                                                    }
                                                    else
                                                        DeptName = maindept.F_DeptName;

                                                    var msgss = userinfo + " 审核通过了工单，主办单位：" + DeptName;
                                                    if (!string .IsNullOrEmpty (cbreason ))
                                                    {
                                                    msgss += "，审核意见：" + cbreason;
                                                    }

                                                    if (maindept.F_IsDept == 2)
                                                    {
                                                        addoptlog(modelT_Bus_WorkOrder.F_WorkOrderId, modelT_Bus_WorkOrder.F_WorkState, modelT_Bus_AssignedInfo.F_Id, msgss, curuser.F_UserCode, 0, 1);
                                                        SplitOrderNew(modelT_Bus_WorkOrder, maindept, Convert.ToDateTime(resdatetime), modelT_Bus_AssignedInfo, cbreason , curuser).ContinueWith(p =>
                                                        {
                                                            System.Diagnostics.Debug.WriteLine(DateTime.Now);
                                                        });
                                                    }
                                                    else
                                                    {
                                                        Task.Run(() =>
                                                        {
                                                            addoptlog(modelT_Bus_WorkOrder.F_WorkOrderId, modelT_Bus_WorkOrder.F_WorkState, modelT_Bus_AssignedInfo.F_Id, msgss, curuser.F_UserCode, 0, 1);
                                                        }).ContinueWith(p =>
                                                        {
                                                            System.Diagnostics.Debug.WriteLine(DateTime.Now);
                                                        });
                                                    }
                                                    #region 插入推送消息
                                                    if (maindept.F_IsDept == 2)
                                                    {
                                                        var users = userBLL.GetModelList(" F_DeptId='" + premodeldept.F_DeptId + "' ");

                                                        foreach (var u in users)
                                                        {
                                                            if (curuser.F_RoleCode == "DBZY")
                                                            {
                                                                string count = "你有督办工单：" + modelT_Bus_WorkOrder.F_WorkOrderId + "，请及时查收处理。";
                                                                //  string msgcount = modelT_Bus_WorkOrder.F_WorkOrderId;
                                                                //  bool v = SMSController.AddSmS(0, msgcount, count, u.F_Mobile, "242065", "");
                                                                string mag = "[\"" + modelT_Bus_WorkOrder.F_WorkOrderId + "\"]";
                                                                string v = SmsNewController.AddSmS(0, count, u.F_Mobile,
         "681240181093470208", mag, modelT_Bus_WorkOrder.F_WorkOrderId);
                                                                msg.AddInternalMessagesInfo("工单消息", msgss + "，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId, u.F_UserCode, curuser.F_UserCode, (int)EnumSmsType.workorder);
                                                            }
                                                            else
                                                            {
                                                                if (u.F_RoleCode == "WLDW" && u.F_IsSms != null && u.F_IsSms == 1)
                                                                {
                                                                    continue;
                                                                }
                                                                else
                                                                {
                                                                    string count = "你有新工单：" + modelT_Bus_WorkOrder.F_WorkOrderId + "，已转至三级单位，请在已派单菜单查看。";
                                                                    // string msgcount = modelT_Bus_WorkOrder.F_WorkOrderId;
                                                                    //   bool v = SMSController.AddSmS(0, msgcount, count, u.F_Mobile, "153305", "");
                                                                    string mag = "[\"" + modelT_Bus_WorkOrder.F_WorkOrderId + "\"]";
                                                                    string v = SmsNewController.AddSmS(0, count, u.F_Mobile, "681555443768397824", mag,
                                                                   modelT_Bus_WorkOrder.F_WorkOrderId);
                                                                    msg.AddInternalMessagesInfo("工单消息", msgss + "，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId, u.F_UserCode, curuser.F_UserCode, (int)EnumSmsType.workorder);

                                                                }
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        var users = userBLL.GetModelList(" F_DeptId='" + maindept.F_DeptId + "' ");
                                                        foreach (var u in users)
                                                        {
                                                            if (curuser.F_RoleCode == "DBZY")
                                                            {
                                                                string count = "你有督办工单：" + modelT_Bus_WorkOrder.F_WorkOrderId + "，请及时查收处理。";
                                                                //  string msgcount = modelT_Bus_WorkOrder.F_WorkOrderId;
                                                                // bool v = SMSController.AddSmS(0, msgcount, count, u.F_Mobile, "242065", "");
                                                                string mag = "[\"" + modelT_Bus_WorkOrder.F_WorkOrderId + "\"]";
                                                                string v = SmsNewController.AddSmS(0, count, u.F_Mobile,
         "681240181093470208", mag, modelT_Bus_WorkOrder.F_WorkOrderId);
                                                                msg.AddInternalMessagesInfo("工单消息", msgss + "，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId, u.F_UserCode, curuser.F_UserCode, (int)EnumSmsType.workorder);
                                                            }
                                                            else
                                                            {
                                                                if (u.F_RoleCode == "WLDW" && u.F_IsSms != null && u.F_IsSms == 1)
                                                                {
                                                                    continue;
                                                                }
                                                                else
                                                                {
                                                                    string count = "你有新工单：" + modelT_Bus_WorkOrder.F_WorkOrderId + "，请及时查收处理。";
                                                                    // string msgcount = modelT_Bus_WorkOrder.F_WorkOrderId;
                                                                    // bool v = SMSController.AddSmS(0, msgcount, count, u.F_Mobile, "153305", "");
                                                                    string mag = "[\"" + modelT_Bus_WorkOrder.F_WorkOrderId + "\"]";
                                                                    string v = SmsNewController.AddSmS(0, count, u.F_Mobile, "681240888655478784", mag,
                                                                   modelT_Bus_WorkOrder.F_WorkOrderId);

                                                                }

                                                                msg.AddInternalMessagesInfo("工单消息", msgss + "，工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId, u.F_UserCode, curuser.F_UserCode, (int)EnumSmsType.workorder);
                                                            }

                                                        }
                                                    }

                                                    #endregion

                                              //  });
                                            }
                                           
                                            #endregion
                                        }
                                        else
                                        {
                                          //  Task.Run(() =>
                                          //  {
                                                Model.T_Bus_WorkOrder tempT_Bus_WorkOrder = modelT_Bus_WorkOrder.ToJson().ToObject<Model.T_Bus_WorkOrder>();
                                                string newids = ""; string errdeptid = ""; string deptname = "";
                                                Model.T_Bus_RemindRecord t_Bus_RemindRecord = new Model.T_Bus_RemindRecord();
                                                if (curuser.F_RoleCode == "DBZY")
                                                {
                                                    t_Bus_RemindRecord = new BLL.T_Bus_RemindRecord().GetNewModelByWorkOrderID(tempT_Bus_WorkOrder.F_WorkOrderId);
                                                }
                                                object obj = new object();
                                                List<Task> taskList = new List<Task>();
                                                foreach (var deptinfo in deptlist)
                                                {
                                                    deptname += deptinfo.F_DeptName + "，";
                                                   
                                                    #region 新增工单
                                                    Model.T_Bus_WorkOrder modelT_Bus_WorkOrder1 = new Model.T_Bus_WorkOrder();
                                                    modelT_Bus_WorkOrder1 = tempT_Bus_WorkOrder;
                                                    string creattime = ((DateTime)modelT_Bus_WorkOrder1.F_CreateTime).ToString("yyyy-MM-dd") + " 00:00:00";
                                                    string endtime = ((DateTime)modelT_Bus_WorkOrder1.F_CreateTime).ToString("yyyy-MM-dd") + " 23:59:59";
                                                    modelT_Bus_WorkOrder1.F_WorkOrderId = workorderBLL.GetNewWorkOrderID((int)modelT_Bus_WorkOrder.F_InfoSource, (int)modelT_Bus_WorkOrder.F_SourceArea, creattime, endtime);
                                                    modelT_Bus_WorkOrder1.F_MainWorkorder1 = modelT_Bus_WorkOrder.F_WorkOrderId;
                                                    string deptcontent = "";
                                                    if (!string.IsNullOrEmpty(modelT_Bus_ToExamine.F_Content))
                                                    {
                                                      string []  content = modelT_Bus_ToExamine.F_Content.Split('ぶ');
                                                        if (content!=null && content.Length  >0)
                                                        {
                                                            foreach (var it in content)
                                                            {
                                                                string[] deptid = it.Split(',');
                                                                if (deptid != null && deptid.Length > 0)
                                                                {
                                                                    if (deptid[0] == deptinfo.F_DeptId.ToString())
                                                                    {
                                                                        deptcontent= it.Remove(0, deptid[0].Length + 1);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                   if (!string .IsNullOrEmpty (deptcontent))
                                                    {
                                                        modelT_Bus_WorkOrder1.F_Content = deptcontent;
                                                        modelT_Bus_WorkOrder1.F_ComContent = deptcontent;
                                                    }
                                                modelT_Bus_WorkOrder1.F_IsRelease = null;
                                                modelT_Bus_WorkOrder1.F_Id = workorderBLL.Add(modelT_Bus_WorkOrder1);
                                                    if (curuser.F_RoleCode == "DBZY")
                                                    {
                                                        Model.T_Bus_RemindRecord t_Bus_RemindRecord_1 = t_Bus_RemindRecord;
                                                        t_Bus_RemindRecord_1.F_WorkOrderId = modelT_Bus_WorkOrder1.F_WorkOrderId;
                                                        new BLL.T_Bus_RemindRecord().Add(t_Bus_RemindRecord_1);
                                                    }
                                                    #endregion

                                                    if (modelT_Bus_WorkOrder1.F_Id > 0)
                                                    {
                                                        #region 插入交办记录
                                                        modelT_Bus_AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder1.F_WorkOrderId;
                                                        modelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(resdatetime);

                                                        modelT_Bus_AssignedInfo.F_MainDeptId = deptinfo.F_DeptId;//主办单位id
                                                        modelT_Bus_AssignedInfo.F_OtherDeptIds = "";//协办单位id
                                                    modelT_Bus_AssignedInfo.F_AssignedOpinion = "请于1小时内与来电人取得联系（匿名除外），并于5个工作日内将办理情况反馈来电人，并将办理结果报市长便民公开电话受理中心，同时做好来电人信息保密工作。（若超期将进行通报；若无故不回复，将转交市委市政府督查局。）";
                                                    modelT_Bus_AssignedInfo.F_TimeResp = assignBLL.GetRepTimly(DateTime.Now);//及时查收时间点
                                                        modelT_Bus_AssignedInfo.F_State = 1;//0草稿  1正式
                                                        modelT_Bus_AssignedInfo.F_CreateUser = modelT_Bus_ToExamine.F_CreatUser;
                                                        modelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                                                        modelT_Bus_AssignedInfo.F_IsDelete = 0;
                                                        modelT_Bus_AssignedInfo.F_IsOverdue = 0;
                                                        modelT_Bus_AssignedInfo.F_IsSure = 0;
                                                        modelT_Bus_AssignedInfo.F_IsReload = 0;
                                                        modelT_Bus_AssignedInfo.F_IsNext = 0;
                                                       int   aid = assignBLL.Add(modelT_Bus_AssignedInfo);

                                                        #endregion

                                                        if (modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_State == 1)
                                                        {
                                                            #region 保存工单信息
                                                            Dictionary<string, object> keyValuePairs2 = new Dictionary<string, object>();


                                                          
                                                          


                                                            if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.resubmit)
                                                            {
                                                                keyValuePairs2.Add("F_IsReload", t);
                                                                keyValuePairs2.Add("F_IsOverdue", 0);
                                                              
                                                                keyValuePairs2.Add("F_WorkState", (int)EnumWorkState.reload);
                                                            }
                                                            else 
                                                            keyValuePairs2.Add("F_WorkState", (int)EnumWorkState.receive);
                                                            modelT_Bus_WorkOrder1.F_WorkState = (int)EnumWorkState.receive;//待查收
                                                            if (modelT_Bus_WorkOrder1.F_Level == 2)
                                                            {
                                                                keyValuePairs2.Add("F_LimitTime", Convert.ToDateTime(resdatetime));
                                                                //  modelT_Bus_WorkOrder1.F_LimitTime = Convert.ToDateTime(limittimes);
                                                            }
                                                            else
                                                            {
                                                                keyValuePairs2.Add("F_LimitTime", Convert.ToDateTime(resdatetime));
                                                                //modelT_Bus_WorkOrder1.F_LimitTime = Convert.ToDateTime(resdatetime);
                                                            }
                                                            keyValuePairs2.Add("F_MainDeptId", deptinfo.F_DeptId);
                                                            modelT_Bus_WorkOrder1.F_MainDeptId = deptinfo.F_DeptId;
                                                            keyValuePairs2.Add("F_OtherDeptIds", "");
                                                            // modelT_Bus_WorkOrder1.F_OtherDeptIds = otherdeptids;
                                                            keyValuePairs2.Add("F_AssignUser", modelT_Bus_ToExamine.F_CreatUser);
                                                            // modelT_Bus_WorkOrder1.F_AssignUser = curuser.F_UserCode;
                                                            keyValuePairs2.Add("F_AssignTime", DateTime.Now);
                                                            // modelT_Bus_WorkOrder1.F_AssignTime = DateTime.Now;
                                                          //  keyValuePairs2.Add("F_IsSendBack", 0);
                                                            // modelT_Bus_WorkOrder1.F_IsSendBack = 0;
                                                            workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder1.F_Id, keyValuePairs2);
                                                            #endregion

                                                            var msgss = userinfo + " 审核通过了工单，主办单位：" + deptinfo.F_DeptName;
                                                        if (!string.IsNullOrEmpty(cbreason))
                                                        {
                                                            msgss += "，审核意见：" + cbreason;
                                                        }

                                                        #region 插入操作记录
                                                        addoptlog(modelT_Bus_WorkOrder1.F_WorkOrderId, modelT_Bus_WorkOrder1.F_WorkState, modelT_Bus_AssignedInfo.F_Id, msgss, curuser.F_UserCode, 0, 1);
                                                            #endregion

                                                            #region 插入推送消息
                                                            //推送消息表
                                                            var users = userBLL.GetModelList(" F_DeptId='" + deptinfo.F_DeptId + "' ");

                                                            foreach (var u in users)
                                                            {
                                                                msg.AddInternalMessagesInfo("工单消息", msgss + "，工单编号：" + modelT_Bus_WorkOrder1.F_WorkOrderId, u.F_UserCode, curuser.F_UserCode, (int)EnumSmsType.workorder);
                                                            }
                                                            #endregion

                                                            #region 发短信
                                                            var user = new BLL.T_Sys_UserAccount().GetModelList("F_DeptId =" + deptinfo.F_DeptId);
                                                            if (user != null && user.Count > 0)
                                                            {
                                                                foreach (var it in user)
                                                                {
                                                                    if (curuser.F_RoleCode == "DBZY")
                                                                    {
                                                                        string count = "你有督办工单：" + modelT_Bus_WorkOrder1.F_WorkOrderId + "，请及时查收处理。";
                                                                      //  string msg = modelT_Bus_WorkOrder1.F_WorkOrderId;
                                                                        //bool v = SMSController.AddSmS(0, msg, count, it.F_Mobile, "242065", "");

                                                                        string mag = "[\"" + modelT_Bus_WorkOrder1.F_WorkOrderId + "\"]";
                                                                        string v = SmsNewController.AddSmS(0, count, it.F_Mobile,
                 "681240181093470208", mag, modelT_Bus_WorkOrder1.F_WorkOrderId);
                                                                    }
                                                                    else
                                                                    {
                                                                        if (it.F_RoleCode == "WLDW" && it.F_IsSms != null && it.F_IsSms == 1)
                                                                        {
                                                                            continue;
                                                                        }
                                                                        else
                                                                        {
                                                                            string count = "你有新工单：" + modelT_Bus_WorkOrder1.F_WorkOrderId + "，请及时查收处理。";
                                                                            // string msg = modelT_Bus_WorkOrder1.F_WorkOrderId;
                                                                            // bool v = SMSController.AddSmS(0, msg, count, it.F_Mobile, "153305", "");
                                                                            string mag = "[\"" + modelT_Bus_WorkOrder1.F_WorkOrderId + "\"]";
                                                                            string v = SmsNewController.AddSmS(0, count, it.F_Mobile, "681240888655478784", mag,
                                                                           modelT_Bus_WorkOrder1.F_WorkOrderId);
                                                                        }

                                                                    }

                                                                }
                                                            }
                                                            #endregion

                                                        }

                                                        newids += modelT_Bus_WorkOrder1.F_WorkOrderId + ",";
                                                    }
                                                    else
                                                    {
                                                        errdeptid += deptinfo.F_DeptName + ",";
                                                    }
                                                }

                                                newids = newids.Trim(',');
                                                var msgs = "";
                                                if (errdeptid == "")
                                                {
                                                    Dictionary<string, object> keyValuePairs3 = new Dictionary<string, object>();
                                                    keyValuePairs3.Add("F_SubWorkorder1", newids);
                                                    modelT_Bus_WorkOrder.F_SubWorkorder1 = newids;
                                                    workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs3);
                                                    msgs = userinfo + " 交办多单位：" + deptname + "生成新工单，新工单编号为：" + newids;
                                                }
                                                else
                                                {
                                                    errdeptid = errdeptid.Trim(',');
                                                    msgs = userinfo + " 交办的单位有" + deptname + "部分操作成功，新工单编号为：" + newids + "，交办失败的部门为：" + errdeptid;
                                                }

                                                addoptlog(modelT_Bus_WorkOrder.F_WorkOrderId, modelT_Bus_WorkOrder.F_WorkState, modelT_Bus_AssignedInfo.F_Id, msgs, curuser.F_UserCode, 0, 1);


                                          //  }).ContinueWith(p =>
                                           // {
                                           //     System.Diagnostics.Debug.WriteLine(DateTime.Now);
                                         //   });
                                            Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                                            keyValuePairs1.Add("F_IsSendBack", 0);
                                            // modelT_Bus_WorkOrder.F_IsSendBack = 0;

                                            if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.resubmit)
                                            {
                                                keyValuePairs1.Add("F_IsReload", t);
                                                keyValuePairs1.Add("F_IsOverdue", 0);
                                              
                                                keyValuePairs1.Add("F_WorkState", (int)EnumWorkState.reload);
                                                modelT_Bus_WorkOrder.F_WorkState = 8;
                                            }
                                            else
                                                keyValuePairs1.Add("F_WorkState", (int)EnumWorkState.dealing);
                                            // modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.dealing;
                                            workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs1);
                                            
                                        }
                                    }
                                    else
                                    {
                                        return Error("单位不存在");
                                    }
                                  
                                }
                             
                                #region 插入操作记录
                               

                                //推送消息表
                                #endregion




                            }
                            trans.Complete();
                        }
                        return Success("操作成功", modelT_Bus_ToExamine.F_ID);
                    }
                    else
                    {
                        return Error("已经审核过了");
                    }
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }


        /// <summary>
        /// 回访工单
        /// </summary>
        /// <returns></returns>
        public ActionResult VisitWorkOrder()
        {
            if (User.F_RoleCode == "ZJZY" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "MTDD")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                string visituser = RequestString.GetFormString("visituser");//回访人
                int type = RequestString.GetInt("type", 0);//回访方式
                int issatisfie = RequestString.GetInt("issatisfie", 0);//0不满意 1满意
                int state = RequestString.GetInt("state", 1);//0保存 1保存并下一步
                int visitid = RequestString.GetInt("visitid", 0);
                string result = RequestString.GetFormString("result");//回访情况
                int nexttype = RequestString.GetInt("nexttype", 0);//1重办 2退回重办
                string cbreason = RequestString.GetFormString("cbreason");//重办原因
                string callid = RequestString.GetFormString("callid");
                string guid = RequestString.GetFormString("guid");
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                Model.T_Bus_VisitResult modelT_Bus_VisitResult = new Model.T_Bus_VisitResult();
                if (modelT_Bus_WorkOrder != null)
                {
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.dealed|| modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.visit )
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {

                            if (visitid == 0)
                            {
                                #region 新增回访结果记录
                                modelT_Bus_VisitResult.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                modelT_Bus_VisitResult.F_AssignedId = 0;
                                modelT_Bus_VisitResult.F_VisitUser = visituser;
                                modelT_Bus_VisitResult.F_Type = type;
                                modelT_Bus_VisitResult.F_IsSatisfie = issatisfie;
                                modelT_Bus_VisitResult.F_Result = result;
                                modelT_Bus_VisitResult.F_State = state;
                                if (!string.IsNullOrEmpty(callid))
                                {
                                    var rd = new BLL.T_Call_CallRecords().GetModelByCallId(callid);
                                    if (rd != null)
                                    {
                                        modelT_Bus_VisitResult.F_CallRecordId = rd.CallRecordsId;
                                    }
                                }
                                modelT_Bus_VisitResult.F_IsDelete = 0;
                                modelT_Bus_VisitResult.F_CreateUser = User.F_UserCode;
                                modelT_Bus_VisitResult.F_CreateTime = DateTime.Now;
                                if (modelT_Bus_AssignedInfo != null)
                                {
                                    modelT_Bus_VisitResult.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                                }

                                int id = new BLL.T_Bus_VisitResult().Add(modelT_Bus_VisitResult);
                                modelT_Bus_VisitResult.F_Id = id;
                                //保存回访记录
                                new BLL.T_Bus_VisitResultRecords().AddInfo(modelT_Bus_VisitResult, User.F_UserCode, guid);
                                #endregion
                            }
                            else
                            {
                                #region 修改回访结果记录
                                modelT_Bus_VisitResult = new BLL.T_Bus_VisitResult().GetModel(visitid);
                                if (modelT_Bus_VisitResult != null)
                                {
                                    modelT_Bus_VisitResult.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                    modelT_Bus_VisitResult.F_AssignedId = 0;
                                    modelT_Bus_VisitResult.F_VisitUser = visituser;
                                    modelT_Bus_VisitResult.F_Type = type;
                                    modelT_Bus_VisitResult.F_IsSatisfie = issatisfie;
                                    modelT_Bus_VisitResult.F_Result = result;
                                    modelT_Bus_VisitResult.F_State = state;
                                    if (!string.IsNullOrEmpty(callid))
                                    {
                                        var rd = new BLL.T_Call_CallRecords().GetModelByCallId(callid);
                                        if (rd != null)
                                        {
                                            modelT_Bus_VisitResult.F_CallRecordId = rd.CallRecordsId;
                                        }
                                    }
                                    //modelT_Bus_VisitResult.F_LimitTime = newlimittime;
                                    modelT_Bus_VisitResult.F_IsDelete = 0;
                                    modelT_Bus_VisitResult.F_CreateUser = User.F_UserCode;
                                    modelT_Bus_VisitResult.F_CreateTime = DateTime.Now;
                                    if (modelT_Bus_AssignedInfo != null)
                                    {
                                        modelT_Bus_VisitResult.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                                    }
                                    int id = new BLL.T_Bus_VisitResult().Add(modelT_Bus_VisitResult);
                                    modelT_Bus_VisitResult.F_Id = id;
                                    //保存回访记录
                                    new BLL.T_Bus_VisitResultRecords().AddInfo(modelT_Bus_VisitResult, User.F_UserCode, guid);
                                }
                                #endregion
                            }
                            
                           
                          
                           
                            if (modelT_Bus_VisitResult != null && modelT_Bus_VisitResult.F_State == 1)
                            {
                                //提交重办满意度改为满意
                                modelT_Bus_AssignedInfo.F_IsSatisfie = issatisfie;
                                assignBLL.Update(modelT_Bus_AssignedInfo);
                                var opt = "回访"; var cbreasons = "";
                                //结案
                                if (nexttype == 0)
                                {
                                    if (issatisfie == 0)
                                     keyValuePairs.Add("F_ToBereply", 1);
                                    keyValuePairs.Add("F_IsClosed", 1);
                                    // modelT_Bus_WorkOrder.F_IsClosed = 1;
                                    keyValuePairs.Add("F_CloseTime", DateTime.Now);
                                    // modelT_Bus_WorkOrder.F_CloseTime = DateTime.Now;
                                    keyValuePairs.Add("F_CloseUser", User.F_UserCode);
                                    // modelT_Bus_WorkOrder.F_CloseUser = User.F_UserCode;
                                    keyValuePairs.Add("F_WorkState", 9);
                                    keyValuePairs.Add("F_IsProResult", 1);
                                    modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.finish;//已回访
                                    workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);
                                    var cureuser = User;
                                    Task.Run(() =>
                                    {
                                        CloseWorkorder(modelT_Bus_WorkOrder, cureuser);
                                    }).ContinueWith(p => {
                                        System.Diagnostics.Debug.WriteLine(DateTime.Now);
                                    });
                                 
                                }
                                #region 重办
                                else if (nexttype == 1)
                                {
                                    #region 保存工单信息
                                    if (modelT_Bus_WorkOrder.F_RemindDay == 2|| modelT_Bus_WorkOrder.F_RemindDay == 3)
                                    {
                                        return Error("回访时，提交重办只能操作一次");
                                    }
                                    Dictionary<string, object> keyValuePairs2 = new Dictionary<string, object>();
                                    if (modelT_Bus_WorkOrder.F_RemindDay == 1 || modelT_Bus_WorkOrder.F_RemindDay == 3)
                                        keyValuePairs2.Add("F_RemindDay", 3);
                                    else
                                        keyValuePairs2.Add("F_RemindDay", 2);
                                    keyValuePairs2.Add("F_WorkState", (int)EnumWorkState.resubmit);
                                     modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.resubmit;
                                  
                                    //  modelT_Bus_WorkOrder.F_IsExamine = 1;
                                    keyValuePairs2.Add("F_IsSms", 0);
                                    //  modelT_Bus_WorkOrder.F_IsSms = 0;
                                    keyValuePairs2.Add("F_Identification", 0);
                                   // modelT_Bus_WorkOrder.F_Identification = 0;
                                    workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs2);
                                    #endregion
                                    opt = "于" + DateTime.Now
                                                                        .ToString("yyyy年MM月dd日HH时mm分ss秒") + "提交重办";

                                    cbreasons = "，重办原因：" + cbreason;
                                    var t_Bus_RemindRecord = new BLL.T_Bus_RemindRecord().GetNewModelByWorkOrderID(modelT_Bus_WorkOrder.F_WorkOrderId);
                                    if (t_Bus_RemindRecord != null)
                                    {
                                        t_Bus_RemindRecord.F_State = 0;
                                        new BLL.T_Bus_RemindRecord().Update(t_Bus_RemindRecord);
                                    }
                                    #endregion
                                }
                                else if (nexttype == 2)
                                {
                                    if (modelT_Bus_WorkOrder.F_MainDeptId != null &&
                              modelT_Bus_WorkOrder.F_MainDeptId > 0)
                                    {
                                        Dictionary<string, object> keyValuePairs3 = new Dictionary<string, object>();
                                        if (User.F_RoleCode == "ZXHWY")
                                        {
                                            keyValuePairs3.Add("F_WorkState", (int)EnumWorkState.backaudit);
                                            modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.backaudit;//重办审核
                                            if (workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs3))
                                            {
                                                #region 插入操作记录

                                                #region 20191021调整为多个主办单位时调整

                                                #endregion
                                                opt = "于" + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒") + "退回重办";
                                                cbreasons = "，重办原因：" + cbreason;
                                                #endregion

                                            }
                                        }
                                        else
                                        {
                                            keyValuePairs3.Add("F_WorkState", (int)EnumWorkState.reload);
                                            modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.reload;//重办中
                                            int n = Int32.Parse(DbHelperSQL.GetSingle("select count(1) from T_Bus_AssignedInfo WITH(NOLOCK) where F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and  F_State=1 and F_IsSure=1 and F_IsDelete=0 and isnull(F_IsReload,0)>0").ToString());
                                            Model.T_Bus_AssignedInfo newmodelT_Bus_AssignedInfo = new Model.T_Bus_AssignedInfo();
                                            newmodelT_Bus_AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                            DataTable dt = DbHelperSQL.Query("select top 6 F_OffDate from  T_Sys_WorkOFFDays  where F_OffState = 1   and F_OffDate>='" + DateTime.Now + "' order by F_OffDate ").Tables[0];
                                            var resdatetime = dt.Rows[5]["F_OffDate"].ToString();
                                            if (!string.IsNullOrEmpty(resdatetime))
                                            {
                                                newmodelT_Bus_AssignedInfo.F_LimitTime = DateTime.Parse(resdatetime.Split(' ')[0] + " 23:59:59");//办理时限
                                            }
                                            newmodelT_Bus_AssignedInfo.F_MainDeptId = modelT_Bus_WorkOrder.F_MainDeptId;//主办单位id
                                            newmodelT_Bus_AssignedInfo.F_OtherDeptIds = "";//协办单位id
                                            newmodelT_Bus_AssignedInfo.F_AssignedOpinion = cbreason;//交办意见
                                            newmodelT_Bus_AssignedInfo.F_State = 1;
                                            newmodelT_Bus_AssignedInfo.F_CreateUser = User.F_UserCode;
                                            newmodelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                                            newmodelT_Bus_AssignedInfo.F_IsDelete = 0;
                                            newmodelT_Bus_AssignedInfo.F_IsOverdue = 0;
                                            newmodelT_Bus_AssignedInfo.F_IsSure = 0;
                                            newmodelT_Bus_AssignedInfo.F_IsReload = n + 1;
                                            newmodelT_Bus_AssignedInfo.F_ReloadUser = User.F_UserCode;
                                            newmodelT_Bus_AssignedInfo.F_ReloadTime = DateTime.Now;
                                            newmodelT_Bus_AssignedInfo.F_IsNext = 0;
                                            newmodelT_Bus_AssignedInfo.F_Id = assignBLL.Add(newmodelT_Bus_AssignedInfo);
                                            if (newmodelT_Bus_AssignedInfo.F_Id > 0)
                                            {
                                                #region 保存工单信息

                                                //  modelT_Bus_WorkOrder.F_MainDeptId = modelT_Bus_WorkOrder.F_MainDeptId;
                                                keyValuePairs3.Add("F_MainDeptId", modelT_Bus_WorkOrder.F_MainDeptId);
                                                keyValuePairs3.Add("F_OtherDeptIds", modelT_Bus_WorkOrder.F_OtherDeptIds);
                                                // modelT_Bus_WorkOrder.F_OtherDeptIds = modelT_Bus_WorkOrder.F_OtherDeptIds;
                                                keyValuePairs3.Add("F_AssignUser", User.F_UserCode);
                                                // modelT_Bus_WorkOrder.F_AssignUser = User.F_UserCode;
                                                keyValuePairs3.Add("F_AssignTime", DateTime.Now);
                                                //  modelT_Bus_WorkOrder.F_AssignTime = DateTime.Now;
                                                if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.finish)
                                                {
                                                    keyValuePairs3.Add("F_RemindDay", 1);
                                                    //   modelT_Bus_WorkOrder.F_RemindDay = 1;
                                                }
                                                keyValuePairs3.Add("F_IsReload", n + 1);
                                                // modelT_Bus_WorkOrder.F_IsReload = n + 1;
                                                if (!string.IsNullOrEmpty(resdatetime))
                                                    keyValuePairs3.Add("F_LimitTime", DateTime.Parse(resdatetime.Split(' ')[0] + " 23:59:59"));
                                                keyValuePairs3.Add("F_IsOverdue", 0);
                                                // modelT_Bus_WorkOrder.F_IsOverdue = 0;
                                                keyValuePairs3.Add("F_IsSms", 0);
                                                //  modelT_Bus_WorkOrder.F_IsSms = 0;

                                              
                                                keyValuePairs3.Add("F_Identification", 1);
                                                //  modelT_Bus_WorkOrder.F_Identification = 1;
                                                keyValuePairs3.Add("F_Result", "");
                                                // modelT_Bus_WorkOrder.F_Result = "";
                                                keyValuePairs3.Add("F_DealDeptId", null);
                                                // modelT_Bus_WorkOrder.F_DealDeptId = null;
                                                keyValuePairs3.Add("F_DealUser", "");
                                                // modelT_Bus_WorkOrder.F_DealUser = "";
                                                keyValuePairs3.Add("F_DealTime", null);
                                                //   modelT_Bus_WorkOrder.F_DealTime = null;
                                                if (workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs3))
                                                {
                                                    #region 插入操作记录

                                                    #region 20191021调整为多个主办单位时调整

                                                    #endregion
                                                    opt = "于" + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒") + "退回重办";
                                                    cbreasons = "，重办原因：" + cbreason;
                                                    #endregion

                                                }
                                                #endregion
                                            }
                                            else
                                            {
                                                return Error("退回失败");
                                            }
                                        }
                                    
                                    }
                                }
                                #region 插入操作记录
                                Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                                oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                oper.F_AssignedId = modelT_Bus_VisitResult.F_AssignedId;
                                oper.F_State = modelT_Bus_WorkOrder.F_WorkState;
                                string userinfo = User.depname + "(" + User.F_UserCode + ")";

                                oper.F_Message = userinfo + " " + opt + "了工单，结果：" + (issatisfie == 1 ? "满意" : "不满意") + cbreasons;
                                oper.F_CreateUser = User.F_UserCode;
                                oper.F_CreateTime = DateTime.Now;
                                oper.F_IsDelete = 0;

                               int o= operBLL.Add(oper);
                              
                                //推送消息表
                                msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, modelT_Bus_AssignedInfo.F_CreateUser, User.F_UserCode, (int)EnumSmsType.workorder);
                                #endregion
                                if (issatisfie == 1)//如果满意就进行自动语音回访
                                {
                                    var configacb = configBll.GetModelList(" F_ParamCode='AutoCallBack' ").FirstOrDefault();
                                    if (configacb != null && configacb.F_ParamValue == "1")//如果为1就是开启了自动语音回访，其他都是关闭
                                    {
                                        string AutoCallMsg = string.Empty;
                                        new BLL.T_CTI_Task().AddToAutoVoiceNotice(modelT_Bus_WorkOrder.F_CusPhone, modelT_Bus_WorkOrder.F_WorkOrderId, modelT_Bus_AssignedInfo.F_Id, out AutoCallMsg);
                                    }
                                }
                              


                            }
                            trans.Complete();
                            //////多次不满意转督办
                            ////if (issatisfie == 0 && nexttype > 0)
                            ////{
                            ////    Remind(modelT_Bus_WorkOrder, modelT_Bus_AssignedInfo);
                            ////}
                        }
                        return Success("操作成功", modelT_Bus_VisitResult.F_Id);
                    }
                    else
                    {
                        return Error("已经回访过了");
                    }
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }
       public void CloseWorkorder(Model.T_Bus_WorkOrder modelT_Bus_WorkOrder ,Model .T_Sys_UserAccount  curruser)
        {
            if (!string.IsNullOrEmpty(modelT_Bus_WorkOrder.F_MainWorkorder1))
            {
                var model = workorderBLL.GetModel(modelT_Bus_WorkOrder.F_MainWorkorder1);
                if (model != null)
                {
                    string Result = "";
                    if (modelT_Bus_WorkOrder.F_WorkOrderId == modelT_Bus_WorkOrder.F_MainWorkorder1)
                    {
                        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  ");
                            string FinalOpinion = "";
                            if (modellist != null && modellist.Count > 0)
                            {
                                foreach (var it in modellist)
                                {
                                    if (string.IsNullOrEmpty(Result))
                                        Result = modelT_Bus_WorkOrder.F_Result;
                                    else
                                        Result += ";   " + it.F_Result;
                                    if (!string.IsNullOrEmpty(FinalOpinion))
                                    {
                                        if (string.IsNullOrEmpty(FinalOpinion))
                                            FinalOpinion = it.F_FinalOpinion;
                                        else
                                        {
                                            if (!string.IsNullOrEmpty(it.F_FinalOpinion))
                                                FinalOpinion += ";   " + it.F_FinalOpinion;
                                        }

                                    }
                                }
                                Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                                keyValuePairs1.Add("F_Result", Result);
                                model.F_Result = Result;
                                keyValuePairs1.Add("F_FinalOpinion", FinalOpinion);
                                //  model.F_FinalOpinion = FinalOpinion;
                                workorderBLL.UpdateWorkOrder(model.F_Id, keyValuePairs1);
                              
                            }

                        }
                    }
                    else
                    {
                        Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                        if (string.IsNullOrEmpty(model.F_Result))
                            keyValuePairs1.Add("F_Result", modelT_Bus_WorkOrder.F_Result);
                        else
                            keyValuePairs1.Add("F_Result", model.F_Result + ";   " + modelT_Bus_WorkOrder.F_Result);
                        Result = model.F_Result + ";   " + modelT_Bus_WorkOrder.F_Result;
                        keyValuePairs1.Add("F_DealUser", modelT_Bus_WorkOrder.F_DealUser);
                        keyValuePairs1.Add("F_DealTime", modelT_Bus_WorkOrder.F_DealTime);
                        keyValuePairs1.Add("F_DealDeptId", modelT_Bus_WorkOrder.F_DealDeptId);
                        keyValuePairs1.Add("F_MainDeptId", modelT_Bus_WorkOrder.F_MainDeptId);
                        if (!string.IsNullOrEmpty(model.F_SubWorkorder1))
                        {
                            int v = Int32.Parse(DbHelperSQL.GetSingle("  select COUNT(1) from t_bus_workorder  where F_WorkOrderId in(select col from dbo.SplitToNvarchar('" + model.F_SubWorkorder1 + "',',' ))  and F_WorkState != 9 and F_IsDelete =0").ToString());
                            if (v <= 0)
                            {
                                keyValuePairs1.Add("F_IsClosed", 1);
                                keyValuePairs1.Add("F_CloseTime", DateTime.Now);
                                keyValuePairs1.Add("F_CloseUser", curruser.F_UserCode);
                                keyValuePairs1.Add("F_WorkState", 9);
                                keyValuePairs1.Add("F_IsProResult", 1);
                                model.F_WorkState = (int)EnumWorkState.finish;//已回访

                                workorderBLL.UpdateWorkOrder(model.F_Id, keyValuePairs1);
                            
                            }
                            else
                                workorderBLL.UpdateWorkOrder(model.F_Id, keyValuePairs1);


                        }
                        else
                        {
                            keyValuePairs1.Add("F_IsClosed", 1);
                            keyValuePairs1.Add("F_CloseTime", DateTime.Now);
                            keyValuePairs1.Add("F_CloseUser", curruser.F_UserCode);
                            keyValuePairs1.Add("F_WorkState", 9);
                            keyValuePairs1.Add("F_IsProResult", 1);
                            model.F_WorkState = (int)EnumWorkState.finish;//已回访
                            workorderBLL.UpdateWorkOrder(model.F_Id, keyValuePairs1);

                        }

                    }
                    if (model.F_IsRelease == 2)
                    {
                        if (!string.IsNullOrEmpty(model.F_SubWorkorder))
                        {
                            var orderlist = model.F_SubWorkorder.Split(',');
                            if (orderlist.Length > 0)
                            {
                                foreach (var it in orderlist)
                                {
                                    var model1 = workorderBLL.GetModel(it);
                                    if (model1 != null)
                                    {

                                        Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                                        keyValuePairs1.Add("F_IsClosed", 1);
                                        keyValuePairs1.Add("F_CloseTime", DateTime.Now);
                                        keyValuePairs1.Add("F_CloseUser", curruser.F_UserCode);
                                       
                                        keyValuePairs1.Add("F_WorkState", 9);
                                        keyValuePairs1.Add("F_IsProResult", 1);
                                        model1.F_WorkState = (int)EnumWorkState.finish;//已回访
                                        keyValuePairs1.Add("F_Result", Result);
                                      
                                        keyValuePairs1.Add("F_DealUser", modelT_Bus_WorkOrder.F_DealUser);
                                       
                                        keyValuePairs1.Add("F_DealTime", modelT_Bus_WorkOrder.F_DealTime);
                                        
                                        keyValuePairs1.Add("F_DealDeptId", modelT_Bus_WorkOrder.F_DealDeptId);
                                     
                                        keyValuePairs1.Add("F_MainDeptId", modelT_Bus_WorkOrder.F_MainDeptId);
                                      
                                        workorderBLL.UpdateWorkOrder(model1.F_Id, keyValuePairs1);
                                       
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (modelT_Bus_WorkOrder.F_IsRelease == 2)
            {
                if (!string.IsNullOrEmpty(modelT_Bus_WorkOrder.F_SubWorkorder))
                {
                    var orderlist = modelT_Bus_WorkOrder.F_SubWorkorder.Split(',');
                    if (orderlist.Length > 0)
                    {
                        foreach (var it in orderlist)
                        {
                            var model = workorderBLL.GetModel(it);
                            if (model != null)
                            {

                                Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                                keyValuePairs1.Add("F_IsClosed", 1);
                                keyValuePairs1.Add("F_CloseTime", DateTime.Now);
                                keyValuePairs1.Add("F_CloseUser", curruser.F_UserCode);
                                keyValuePairs1.Add("F_WorkState", 9);
                                keyValuePairs1.Add("F_IsProResult", 1);
                                model.F_WorkState = (int)EnumWorkState.finish;//已回访
                                keyValuePairs1.Add("F_Result", modelT_Bus_WorkOrder.F_Result);
                                keyValuePairs1.Add("F_DealUser", modelT_Bus_WorkOrder.F_DealUser);
                                keyValuePairs1.Add("F_DealTime", modelT_Bus_WorkOrder.F_DealTime);
                                keyValuePairs1.Add("F_DealDeptId", modelT_Bus_WorkOrder.F_DealDeptId);
                                keyValuePairs1.Add("F_MainDeptId", modelT_Bus_WorkOrder.F_MainDeptId);
                                workorderBLL.UpdateWorkOrder(model.F_Id, keyValuePairs1);
                              

                                if (!string.IsNullOrEmpty(model.F_MainWorkorder1))
                                {
                                    var model2 = workorderBLL.GetModel(model.F_MainWorkorder1);
                                    if (model2!=null )
                                    {
                                        if (model2.F_WorkOrderId == model2.F_MainWorkorder1)
                                        {
                                            if (!string.IsNullOrEmpty(model2.F_SubWorkorder1))
                                            {
                                                var modellist = workorderBLL.GetModelList("F_WorkOrderId in(select col from dbo.SplitToNvarchar('" + model2.F_SubWorkorder1 + "',',' ))  and F_IsDelete =0  ");
                                                string Result = ""; string FinalOpinion = "";
                                                if (modellist != null && modellist.Count > 0)
                                                {
                                                    foreach (var iv in modellist)
                                                    {
                                                        if (string.IsNullOrEmpty(Result))
                                                            Result = modelT_Bus_WorkOrder.F_Result;
                                                        else
                                                            Result += ";   " + iv.F_Result;
                                                        if (!string.IsNullOrEmpty(FinalOpinion))
                                                        {
                                                            if (string.IsNullOrEmpty(FinalOpinion))
                                                                FinalOpinion = iv.F_FinalOpinion;
                                                            else
                                                            {
                                                                if (!string.IsNullOrEmpty(iv.F_FinalOpinion))
                                                                    FinalOpinion += ";   " + iv.F_FinalOpinion;
                                                            }

                                                        }
                                                    }
                                                    Dictionary<string, object> keyValuePairs2 = new Dictionary<string, object>();
                                                    keyValuePairs2.Add("F_Result", Result);
                                                    model2.F_Result = Result;
                                                    keyValuePairs2.Add("F_FinalOpinion", FinalOpinion);
                                                    workorderBLL.UpdateWorkOrder(model2.F_Id, keyValuePairs2);
                                                   
                                                }

                                            }
                                        }
                                        else
                                        {
                                            Dictionary<string, object> keyValuePairs3 = new Dictionary<string, object>();
                                            if (string.IsNullOrEmpty(model2.F_Result))
                                                keyValuePairs3.Add("F_Result", modelT_Bus_WorkOrder.F_Result);
                                            else
                                                keyValuePairs3.Add("F_Result", model2.F_Result + ";   " + modelT_Bus_WorkOrder.F_Result);
                                            keyValuePairs3.Add("F_DealUser", modelT_Bus_WorkOrder.F_DealUser);
                                            //  model.F_DealUser = modelT_Bus_WorkOrder.F_DealUser;
                                            keyValuePairs3.Add("F_DealTime", modelT_Bus_WorkOrder.F_DealTime);
                                            // model.F_DealTime = modelT_Bus_WorkOrder.F_DealTime;
                                            keyValuePairs3.Add("F_DealDeptId", modelT_Bus_WorkOrder.F_DealDeptId);
                                            // model.F_DealDeptId = modelT_Bus_WorkOrder.F_DealDeptId;
                                            keyValuePairs3.Add("F_MainDeptId", modelT_Bus_WorkOrder.F_MainDeptId);
                                            //   model.F_MainDeptId = modelT_Bus_WorkOrder.F_MainDeptId;
                                            if (!string.IsNullOrEmpty(model2.F_SubWorkorder1))
                                            {
                                                int v = Int32.Parse(DbHelperSQL.GetSingle("  select COUNT(1) from t_bus_workorder  where F_WorkOrderId in(select col from dbo.SplitToNvarchar('" + model2.F_SubWorkorder1 + "',',' ))  and F_WorkState != 9 and F_IsDelete =0").ToString());
                                                if (v <= 0)
                                                {
                                                    keyValuePairs3.Add("F_IsClosed", 1);
                                                    keyValuePairs3.Add("F_CloseTime", DateTime.Now);
                                                    keyValuePairs3.Add("F_WorkState", 9);
                                                    keyValuePairs3.Add("F_IsProResult", 1);
                                                    model2.F_WorkState = (int)EnumWorkState.finish;//已回访
                                                    workorderBLL.UpdateWorkOrder(model2.F_Id, keyValuePairs3);
                                                   
                                                }
                                                else
                                                    workorderBLL.UpdateWorkOrder(model2.F_Id, keyValuePairs3);


                                            }
                                            else
                                            {
                                                keyValuePairs3.Add("F_IsClosed", 1);
                                                keyValuePairs3.Add("F_CloseTime", DateTime.Now);
                                                keyValuePairs3.Add("F_WorkState", 9);
                                                keyValuePairs3.Add("F_IsProResult", 1);
                                                model2.F_WorkState = (int)EnumWorkState.finish;//已回访
                                                workorderBLL.UpdateWorkOrder(model2.F_Id, keyValuePairs3);

                                            }

                                        }
                                    }
                                   
                                }
                            }
                                
                        }
                    }
                }
            }
        }
        /// <summary>
        /// 多次不满意转督办
        /// </summary>
        /// <returns></returns>
        public bool Remind(Model.T_Bus_WorkOrder modelT_Bus_WorkOrder, Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo)
        {
            bool n = true;
            int f = Int32.Parse(DbHelperSQL.GetSingle("select COUNT(1) from T_Bus_VisitResult WITH(NOLOCK)    where F_IsSatisfie = 0 and F_WorkOrderId = '" + modelT_Bus_WorkOrder.F_WorkOrderId + "'").ToString());
            if (f >= 2)
            {
                Model.T_Bus_RemindRecord modelT_Bus_RemindRecord = new Model.T_Bus_RemindRecord();
                var modelRemindlist = new BLL.T_Bus_RemindRecord().GetModelList(" F_State=0 and F_IsDelete=0 and F_Type =1 and F_WorkOrderId= '" + modelT_Bus_WorkOrder.F_WorkOrderId + "'  order by F_CreateTime desc");
                if (modelRemindlist != null && modelRemindlist.Count > 0)
                {
                    modelT_Bus_RemindRecord = modelRemindlist.FirstOrDefault();
                    if (modelT_Bus_RemindRecord != null)
                    {
                        modelT_Bus_RemindRecord.F_Content = "多次回访不满意转督办";
                        modelT_Bus_RemindRecord.F_State = 0;
                        new BLL.T_Bus_RemindRecord().Update(modelT_Bus_RemindRecord);
                    }
                }
                else
                {
                    modelT_Bus_RemindRecord.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                    if (modelT_Bus_AssignedInfo != null)
                        modelT_Bus_RemindRecord.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                    modelT_Bus_RemindRecord.F_Type = 1;
                    if (modelT_Bus_AssignedInfo != null)
                        modelT_Bus_RemindRecord.F_DeptId = modelT_Bus_AssignedInfo.F_MainDeptId;
                    modelT_Bus_RemindRecord.F_Content = "多次回访不满意转督办"; ;
                    modelT_Bus_RemindRecord.F_File = "";
                    modelT_Bus_RemindRecord.F_State = 0;//0待办 1已办 2退回
                    modelT_Bus_RemindRecord.F_IsDelete = 0;
                    modelT_Bus_RemindRecord.F_CreateUser = User.F_UserCode;
                    modelT_Bus_RemindRecord.F_CreateTime = DateTime.Now;

                    new BLL.T_Bus_RemindRecord().Add(modelT_Bus_RemindRecord);
                }
                #endregion

                #region 插入操作记录
                string typename = "督办";
                Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                if (modelT_Bus_AssignedInfo != null)
                    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 + " " + typename + "了工单";
                oper.F_CreateUser = User.F_UserCode;
                oper.F_CreateTime = DateTime.Now;
                oper.F_IsDelete = 0;

                operBLL.Add(oper);
            }



            return n;
        }



        #region 20200311 zhengbingbing 增加履职界定操作
        /// <summary>
        /// 履职
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult PerformWorkOrder()
        {

            if (User.F_RoleCode == "WLDW" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {//承办单位和管理员
                string workorderid = RequestString.GetFormString("workorderid");
                int state = RequestString.GetInt("state", 0);//0保存 1保存并下一步
                int perid = RequestString.GetInt("perid", 0);
                string file = RequestString.GetFormString("file");
                string result = RequestString.GetFormString("result");
                string guid = RequestString.GetFormString("guid");

                string visitids = RequestString.GetFormString("visitids");
                if (string.IsNullOrWhiteSpace(visitids))
                    return Error("请选择你要履职的回访记录");

                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                List<Model.T_Bus_VisitResult> listT_Bus_VisitResult = new BLL.T_Bus_VisitResult().GetModelList("F_Id in (" + visitids + ")");
                Model.T_Bus_PerformDuties modelT_Bus_PerformDuties = new Model.T_Bus_PerformDuties();

                if (modelT_Bus_WorkOrder != null)
                {
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.visit || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.resubmit || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.reload || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.rejload || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.finish)
                    {//已回访，重办待交办，重办中，重办驳回，已结案
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            var assids = ""; //读取对应的交办记录
                            #region 读取对应的交办id
                            foreach (var item in listT_Bus_VisitResult)
                            {
                                if (item.F_AssignedId != null && item.F_AssignedId != 0)
                                    assids = item.F_AssignedId + ",";
                            }
                            assids = assids.Trim(',');
                            #endregion
                            #region 履职
                            if (perid == 0)
                            {
                                #region 新增履职记录
                                modelT_Bus_PerformDuties.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                modelT_Bus_PerformDuties.F_AssignedId = assids;
                                modelT_Bus_PerformDuties.F_VisitId = visitids;
                                modelT_Bus_PerformDuties.F_File = file;
                                modelT_Bus_PerformDuties.F_State = state;
                                modelT_Bus_PerformDuties.F_Result = result;
                                modelT_Bus_PerformDuties.F_IsAudit = 0;
                                modelT_Bus_PerformDuties.F_IsDelete = 0;
                                modelT_Bus_PerformDuties.F_CreateDeptId = User.F_DeptId;
                                modelT_Bus_PerformDuties.F_CreateTime = DateTime.Now;
                                modelT_Bus_PerformDuties.F_CreateUser = User.F_UserCode;

                                int id = new BLL.T_Bus_PerformDuties().Add(modelT_Bus_PerformDuties);
                                modelT_Bus_PerformDuties.F_Id = id;
                                //保存回访记录
                                new BLL.T_Bus_PerformDutiesRecords().AddInfo(modelT_Bus_PerformDuties, User.F_UserCode, guid);
                                #endregion
                            }
                            else
                            {
                                #region 修改履职记录
                                modelT_Bus_PerformDuties = new BLL.T_Bus_PerformDuties().GetModel(perid);
                                if (modelT_Bus_PerformDuties != null)
                                {
                                    modelT_Bus_PerformDuties.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                    modelT_Bus_PerformDuties.F_AssignedId = assids;
                                    modelT_Bus_PerformDuties.F_VisitId = visitids;
                                    modelT_Bus_PerformDuties.F_File = file;
                                    modelT_Bus_PerformDuties.F_State = state;
                                    modelT_Bus_PerformDuties.F_Result = result;
                                    modelT_Bus_PerformDuties.F_IsAudit = 0;
                                    modelT_Bus_PerformDuties.F_IsDelete = 0;
                                    modelT_Bus_PerformDuties.F_CreateDeptId = User.F_DeptId;
                                    modelT_Bus_PerformDuties.F_CreateTime = DateTime.Now;
                                    modelT_Bus_PerformDuties.F_CreateUser = User.F_UserCode;
                                    int id = new BLL.T_Bus_PerformDuties().Add(modelT_Bus_PerformDuties);
                                    modelT_Bus_PerformDuties.F_Id = id;
                                    //保存回访记录
                                    new BLL.T_Bus_PerformDutiesRecords().AddInfo(modelT_Bus_PerformDuties, User.F_UserCode, guid);
                                }
                                #endregion
                            }

                            if (modelT_Bus_PerformDuties != null && modelT_Bus_PerformDuties.F_State == 1)
                            {
                                #region 保存交办信息
                                foreach (var item in assids.Split(','))
                                {
                                    var model = assignBLL.GetModel(int.Parse(item));
                                    if (model != null)
                                    {
                                        model.F_IsPerform = 1;
                                        assignBLL.Update(model);
                                    }
                                }
                                #endregion
                                #region
                                foreach (var item in listT_Bus_VisitResult)
                                {
                                    item.F_IsPerform = 1;
                                    new BLL.T_Bus_VisitResult().Update(item);
                                }
                                #endregion

                                #region 删除草稿信息
                                var cglist = new BLL.T_Bus_PerformDuties().GetModelList(" F_IsDelete=0 and F_State=0 and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and F_CreateUser='" + User.F_UserCode + "' ");

                                foreach (var cg in cglist)
                                {
                                    cg.F_IsDelete = 1;
                                    cg.F_DeleteUser = User.F_UserCode;
                                    cg.F_DeleteTime = DateTime.Now;

                                    new BLL.T_Bus_PerformDuties().Update(cg);
                                    new BLL.T_Bus_PerformDutiesRecords().AddInfo(cg, User.F_UserCode, guid);
                                }
                                #endregion
                                var opt = "履职界定";
                                #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 + " 对工单提交 " + opt + " 操作";
                                oper.F_File = modelT_Bus_PerformDuties.F_File;
                                oper.F_CreateUser = User.F_UserCode;
                                oper.F_CreateTime = DateTime.Now;
                                oper.F_IsDelete = 0;
                                foreach (var item in assids.Split(','))
                                {
                                    oper.F_AssignedId = int.Parse(item);
                                    operBLL.Add(oper);

                                    //推送消息表 履职界定消息目前推送给工号8666 
                                    msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, "8666", User.F_UserCode, (int)EnumSmsType.workorder);
                                }
                                #endregion
                            }
                            #endregion
                            trans.Complete();
                        }
                        return Success("操作成功", modelT_Bus_PerformDuties.F_Id);
                    }
                    else
                    {
                        return Error("此状态下不能进行履职操作");
                    }
                }
                else
                {
                    return Error("操作失败");
                }

            }
            else
            {
                return Error("权限不足");
            }
        }
        /// <summary>
        /// 履职界定审核
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult DefinitionWorkOrder()
        {
            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int state = RequestString.GetInt("state", 0);
                string reason = RequestString.GetFormString("reason");
                int perid = RequestString.GetInt("perid", 0);
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_PerformDuties modelT_Bus_PerformDuties = new BLL.T_Bus_PerformDuties().GetModel(perid);
                if (modelT_Bus_WorkOrder != null && modelT_Bus_PerformDuties != null)
                {
                    if (modelT_Bus_PerformDuties.F_IsAudit.Value == 0)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            #region 保存履职界定信息
                            modelT_Bus_PerformDuties.F_IsAudit = state;
                            modelT_Bus_PerformDuties.F_AuditUser = User.F_UserCode;
                            modelT_Bus_PerformDuties.F_AuditTime = DateTime.Now;
                            modelT_Bus_PerformDuties.F_AuditReason = reason;
                            new BLL.T_Bus_PerformDuties().Update(modelT_Bus_PerformDuties);
                            #endregion
                            string strmsg = ""; var isperform = 1; int IsSatisfie = 0;

                            #region
                            if (state == 1)
                            {
                                strmsg = "同意";
                                isperform = 2;
                                IsSatisfie = 1;
                            }
                            else if (state == 2)
                            {
                                strmsg = "拒绝";

                                isperform = 3;
                            }
                            #endregion

                            #region 交办记录处理
                            foreach (var item in modelT_Bus_PerformDuties.F_AssignedId.Split(','))
                            {
                                var model = assignBLL.GetModel(int.Parse(item));
                                if (model != null)
                                {
                                    model.F_IsPerform = isperform;
                                    if (state == 1)//同意此履职界定则修改回访结果为满意
                                        model.F_IsSatisfie = IsSatisfie;
                                    assignBLL.Update(model);

                                }
                            }
                            #endregion
                            #region 回访记录处理
                            foreach (var item in modelT_Bus_PerformDuties.F_VisitId.Split(','))
                            {
                                var model = new BLL.T_Bus_VisitResult().GetModel(int.Parse(item));
                                if (model != null)
                                {
                                    model.F_IsPerform = isperform;
                                    if (state == 1)//同意此履职界定则修改回访结果为满意
                                        model.F_IsSatisfie = IsSatisfie;
                                    new BLL.T_Bus_VisitResult().Update(model);

                                }
                            }
                            #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 + " " + strmsg + "了此处理";
                            if (!string.IsNullOrWhiteSpace(reason))
                                oper.F_Message = oper.F_Message + "，理由为：" + reason;
                            oper.F_CreateUser = User.F_UserCode;
                            oper.F_CreateTime = DateTime.Now;
                            oper.F_IsDelete = 0;

                            foreach (var item in modelT_Bus_PerformDuties.F_AssignedId.Split(','))
                            {
                                oper.F_AssignedId = int.Parse(item);
                                operBLL.Add(oper);

                                //推送消息表
                                msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, modelT_Bus_PerformDuties.F_CreateUser, User.F_UserCode, (int)EnumSmsType.workorder);
                            }
                            #endregion

                            trans.Complete();
                        }
                        return Success("操作成功");
                    }
                    else
                        return Error("已经审核过了");
                }
                else
                    return Error("操作失败");
            }
            else
                return Error("权限不足");
        }

        #endregion

        /// <summary>
        /// 督办工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult RemindWorkOrder()
        {
            string workorderid = RequestString.GetFormString("workorderid");
            int type = RequestString.GetInt("type", 0);//1督办 2监察
            int state = RequestString.GetInt("state", 0);//0待办 1已办 2退回
            string overseeopinion = RequestString.GetFormString("overseeopinion");//督办意见
            string files = RequestString.GetFormString("files");
            int mode = RequestString.GetInt("mode", 0);//0现场1电话
            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)
            {
                using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                {
                    #region 插入督办记录
                    Model.T_Bus_RemindRecord modelT_Bus_RemindRecord = new Model.T_Bus_RemindRecord();
                    if (type == 1 && state > 0)
                    {
                        modelT_Bus_RemindRecord = new BLL.T_Bus_RemindRecord().GetModelList(" F_State !=2  and F_IsDelete=0 and F_Type =1 and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' order by F_CreateTime desc").FirstOrDefault();
                        if (modelT_Bus_RemindRecord != null)
                        {
                            if (state == 0)
                                modelT_Bus_RemindRecord.F_Remark = overseeopinion;

                            else
                                modelT_Bus_RemindRecord.F_Content = overseeopinion;
                            modelT_Bus_RemindRecord.F_State = state;
                            modelT_Bus_RemindRecord.Supervisor = User.F_UserCode;
                            modelT_Bus_RemindRecord.SupervisorTime = DateTime.Now;
                            new BLL.T_Bus_RemindRecord().Update(modelT_Bus_RemindRecord);
                        }
                    }
                    else
                    {
                        modelT_Bus_RemindRecord.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                        if (modelT_Bus_AssignedInfo != null)
                            modelT_Bus_RemindRecord.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                        modelT_Bus_RemindRecord.F_Type = type;
                        if (modelT_Bus_AssignedInfo != null)
                            modelT_Bus_RemindRecord.F_DeptId = modelT_Bus_AssignedInfo.F_MainDeptId;
                        if (state == 0)
                            modelT_Bus_RemindRecord.F_Remark = overseeopinion;
                      
                        else
                            modelT_Bus_RemindRecord.F_Content = overseeopinion;
                        modelT_Bus_RemindRecord.F_File = files;
                        modelT_Bus_RemindRecord.F_State = state;//0待办 1已办 2退回
                        modelT_Bus_RemindRecord.F_IsDelete = 0;
                        modelT_Bus_RemindRecord.F_CreateUser = User.F_UserCode;
                        modelT_Bus_RemindRecord.F_CreateTime = DateTime.Now;
                        modelT_Bus_RemindRecord.F_Mode = mode;
                        modelT_Bus_RemindRecord.Supervisor = User.F_UserCode;
                        modelT_Bus_RemindRecord.SupervisorTime  = DateTime.Now;
                        new BLL.T_Bus_RemindRecord().Add(modelT_Bus_RemindRecord);
                    }
                    #endregion

                    #region 插入操作记录
                    string typename = "督办";
                    if (type == 2) { typename = "监察"; }
                    if (type == 1 && state == 0) { typename = "提交督办"; }
                    if (type == 1 && state == 1) { typename = "督办"; }
                    if (type == 1 && state == 2) { typename = "退回督办"; }
                    // modelT_Bus_WorkOrder.F_CreateUser = User.F_UserCode;
                    // bool n = workorderBLL.Update(modelT_Bus_WorkOrder);
                    Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                    oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                    if (modelT_Bus_AssignedInfo != null)
                          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 + " " + typename + "了工单";
                    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("操作失败");
            }
        }


        /// <summary>
        /// 督办查收工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult RemindCheck()
        {
            string workorderid = RequestString.GetFormString("workorderid");
            Model.T_Bus_RemindRecord modelT_Bus_RemindRecord = new BLL.T_Bus_RemindRecord().GetNewModelByWorkOrderID(workorderid);
            Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
            if (modelT_Bus_RemindRecord != null)
            {
                using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                {
                    #region 插入督办记录
                    modelT_Bus_RemindRecord.Supervisor = User.F_UserCode;
                    modelT_Bus_RemindRecord.SupervisorTime = DateTime.Now;
                    new BLL.T_Bus_RemindRecord().Update(modelT_Bus_RemindRecord);
                    #endregion

                    #region 插入操作记录


                    Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                    oper.F_WorkOrderId = modelT_Bus_RemindRecord.F_WorkOrderId;
                    if (modelT_Bus_AssignedInfo != null)
                        oper.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                    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("操作失败");
            }
        }
    


        /// <summary>
        /// 督办审核工单
        /// </summary>
        /// <returns></returns>
        public ActionResult RemindApproved()
        {
            if (User.F_RoleCode == "GLY" || User.F_RoleCode == "DBGLY" || User.F_RoleCode == "DBZY")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int state = RequestString.GetInt("state", 0);//0通过1拒绝
                string reason = RequestString.GetFormString("reason");//审核意见
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                Model.T_Bus_RemindRecord modelT_Bus_RemindRecord = new BLL.T_Bus_RemindRecord().GetNewModelByWorkOrderID(workorderid);
                if (modelT_Bus_WorkOrder != null && modelT_Bus_RemindRecord != null)
                {
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.dealed)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            var opt = ""; var cbreasons = "";
                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            if (state == 1)
                            {
                                if (modelT_Bus_WorkOrder.F_MainDeptId != null &&
                          modelT_Bus_WorkOrder.F_MainDeptId > 0)
                                {
                                    int n = Int32.Parse(DbHelperSQL.GetSingle("select count(1) from T_Bus_AssignedInfo WITH(NOLOCK) where F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and  F_State=1 and F_IsSure=1 and F_IsDelete=0 and isnull(F_IsReload,0)>0").ToString());
                                    Model.T_Bus_AssignedInfo newmodelT_Bus_AssignedInfo = new Model.T_Bus_AssignedInfo();
                                    newmodelT_Bus_AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                    DataTable dt = DbHelperSQL.Query("select top 6 F_OffDate from  T_Sys_WorkOFFDays  where F_OffState = 1   and F_OffDate>='" + DateTime.Now + "' order by F_OffDate ").Tables[0];
                                    var resdatetime = dt.Rows[5]["F_OffDate"].ToString();
                                    if (!string.IsNullOrEmpty(resdatetime))
                                    {
                                        newmodelT_Bus_AssignedInfo.F_LimitTime = DateTime.Parse(resdatetime.Split(' ')[0] + " 23:59:59");//办理时限
                                    }
                                    newmodelT_Bus_AssignedInfo.F_MainDeptId = modelT_Bus_WorkOrder.F_MainDeptId;//主办单位id
                                    newmodelT_Bus_AssignedInfo.F_OtherDeptIds = "";//协办单位id
                                    newmodelT_Bus_AssignedInfo.F_AssignedOpinion = reason;//交办意见
                                    newmodelT_Bus_AssignedInfo.F_State = 1;
                                    newmodelT_Bus_AssignedInfo.F_CreateUser = User.F_UserCode;
                                    newmodelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                                    newmodelT_Bus_AssignedInfo.F_IsDelete = 0;
                                    newmodelT_Bus_AssignedInfo.F_IsOverdue = 0;
                                    newmodelT_Bus_AssignedInfo.F_IsSure = 0;
                                    newmodelT_Bus_AssignedInfo.F_IsReload = n + 1;
                                    newmodelT_Bus_AssignedInfo.F_ReloadUser = User.F_UserCode;
                                    newmodelT_Bus_AssignedInfo.F_ReloadTime = DateTime.Now;
                                    newmodelT_Bus_AssignedInfo.F_IsNext = 0;
                                    newmodelT_Bus_AssignedInfo.F_Id = assignBLL.Add(newmodelT_Bus_AssignedInfo);
                                    if (newmodelT_Bus_AssignedInfo.F_Id > 0)
                                    {
                                        #region 保存工单信息
                                        keyValuePairs.Add("F_MainDeptId", modelT_Bus_WorkOrder.F_MainDeptId);
                                        modelT_Bus_WorkOrder.F_MainDeptId = modelT_Bus_WorkOrder.F_MainDeptId;
                                        keyValuePairs.Add("F_OtherDeptIds", modelT_Bus_WorkOrder.F_OtherDeptIds);
                                        //  modelT_Bus_WorkOrder.F_OtherDeptIds = modelT_Bus_WorkOrder.F_OtherDeptIds;
                                        keyValuePairs.Add("F_AssignUser", User.F_UserCode);
                                        //   modelT_Bus_WorkOrder.F_AssignUser = User.F_UserCode;
                                        keyValuePairs.Add("F_AssignTime", DateTime.Now);
                                     //   modelT_Bus_WorkOrder.F_AssignTime = DateTime.Now;
                                        if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.finish)
                                        {
                                            // modelT_Bus_WorkOrder.F_RemindDay = 1;
                                            keyValuePairs.Add("F_RemindDay",1);
                                        }
                                        keyValuePairs.Add("F_IsReload", n + 1);
                                      //  modelT_Bus_WorkOrder.F_IsReload = n + 1;
                                        if (!string.IsNullOrEmpty(resdatetime))
                                        keyValuePairs.Add("F_LimitTime", DateTime.Parse(resdatetime.Split(' ')[0] + " 23:59:59"));
                                        keyValuePairs.Add("F_IsOverdue", 0);
                                        // modelT_Bus_WorkOrder.F_IsOverdue = 0;
                                        keyValuePairs.Add("F_IsSms", 0);
                                        //  modelT_Bus_WorkOrder.F_IsSms = 0;
                                        if (User .F_RoleCode  == "ZXHWY")
                                        {
                                            keyValuePairs.Add("F_WorkState", (int)EnumWorkState.backaudit );
                                            modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.backaudit;//重办审核
                                        }
                                        else
                                        {
                                            keyValuePairs.Add("F_WorkState", (int)EnumWorkState.reload);
                                            modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.reload;//重办中
                                        }
                                           
                                        
                                        //  modelT_Bus_WorkOrder.F_IsExamine = 1;
                                        keyValuePairs.Add("F_Identification", 1);
                                        // modelT_Bus_WorkOrder.F_Identification = 1;
                                        keyValuePairs.Add("F_Result", "");
                                        //  modelT_Bus_WorkOrder.F_Result = "";
                                        keyValuePairs.Add("F_DealDeptId", null);
                                        // modelT_Bus_WorkOrder.F_DealDeptId = null;
                                        keyValuePairs.Add("F_DealUser", "");
                                        // modelT_Bus_WorkOrder.F_DealUser = "";
                                        keyValuePairs.Add("F_DealTime", null);
                                      //  modelT_Bus_WorkOrder.F_DealTime = null;
                                        if (workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs))
                                        {
//                                            var user = new BLL.T_Sys_UserAccount().GetModelList("F_DeptId in ('" + modelT_Bus_WorkOrder.F_MainDeptId + "') ");
//                                            if (user != null && user.Count > 0)
//                                            {
//                                                foreach (var it in user)
//                                                {
//                                                    string count = "你有督办退回重办工单：" + modelT_Bus_WorkOrder.F_WorkOrderId + "，请及时查收处理";
//                                                    //string msg = modelT_Bus_WorkOrder.F_WorkOrderId;
//                                                    // bool v = SMSController.AddSmS(0, msg, count, it.F_Mobile, "255884", "", modelT_Bus_WorkOrder.F_WorkOrderId);

//                                                    string mag = "[\"" + modelT_Bus_WorkOrder.F_WorkOrderId + "\"]";
//                                                    string v = SmsNewController.AddSmS(0, count, it.F_Mobile,
//"681240088986554368", mag, modelT_Bus_WorkOrder.F_WorkOrderId);
//                                                }
//                                            }
                                            #region 插入操作记录

                                            opt = "于" + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒") + "审核拒绝了工单";
                                            cbreasons = "，审核意见：" + reason;
                                            #endregion

                                        }
                                        #endregion
                                    }
                                    else
                                    {
                                        return Error("退回失败");
                                    }
                                }
                            }
                            else
                            {
                                modelT_Bus_RemindRecord.F_IsExamine = 1;
                                new BLL.T_Bus_RemindRecord().Update(modelT_Bus_RemindRecord);
                                opt = "于" + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒") + "审核通过了工单";
                             
                            }
                            #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 + " " + opt + "" + cbreasons;
                            oper.F_CreateUser = User.F_UserCode;
                            oper.F_CreateTime = DateTime.Now;
                            oper.F_IsDelete = 0;

                            operBLL.Add(oper);
                            //推送消息表
                            msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, modelT_Bus_AssignedInfo.F_CreateUser, User.F_UserCode, (int)EnumSmsType.workorder);
                            #endregion
                            trans.Complete();
                        }
                        return Success("操作成功");
                    }
                    else
                    {
                        return Error("督办单不存在");
                    }
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }
        /// <summary>
        /// 重办工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult ReloadWorkOrder()
        {
            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            //if (User.F_RoleCode == "ZJZY" || User.F_RoleCode == "GLY")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                string overseeopinion = RequestString.GetFormString("overseeopinion");//督办意见
                DateTime newlimittime = DateTime.Parse(RequestString.GetFormString("newlimittime") + " 23:59:59");//不满意，重办的办理时限

                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 (modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_CreateUser != User.F_UserCode)
                    {
                        return Error("操作失败");
                    }
                    //if (modelT_Bus_WorkOrder.F_WorkState == 7)
                    //if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.visit)
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.resubmit)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            #region 插入督办记录
                            Model.T_Bus_RemindRecord modelT_Bus_RemindRecord = new Model.T_Bus_RemindRecord();
                            modelT_Bus_RemindRecord.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                            modelT_Bus_RemindRecord.F_AssignedId = 0;
                            modelT_Bus_RemindRecord.F_Type = 1;
                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            if (modelT_Bus_AssignedInfo != null)//转办后重办
                            {
                                #region 插入交办记录
                                int n = Int32.Parse(DbHelperSQL.GetSingle("select count(1) from T_Bus_AssignedInfo WITH(NOLOCK) where F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and  F_State=1 and F_IsSure=1 and F_IsDelete=0 and isnull(F_IsReload,0)>0").ToString());
                               
                                keyValuePairs.Add("F_IsReload", n + 1);
                                // modelT_Bus_WorkOrder.F_IsReload = n + 1;
                                keyValuePairs.Add("F_LimitTime", newlimittime);
                                // modelT_Bus_WorkOrder.F_LimitTime = newlimittime;
                                keyValuePairs.Add("F_IsOverdue", 0);
                             //   modelT_Bus_WorkOrder.F_IsOverdue = 0;

                                Model.T_Bus_AssignedInfo AssignedInfo = new Model.T_Bus_AssignedInfo();
                                AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                AssignedInfo.F_LimitTime = newlimittime;//办理时限
                                AssignedInfo.F_MainDeptId = modelT_Bus_AssignedInfo.F_MainDeptId;//主办单位id
                                AssignedInfo.F_OtherDeptIds = modelT_Bus_AssignedInfo.F_OtherDeptIds;//协办单位id
                                AssignedInfo.F_AssignedOpinion = modelT_Bus_AssignedInfo.F_AssignedOpinion;//交办意见

                                AssignedInfo.F_State = 1;//0草稿  1正式
                                AssignedInfo.F_CreateUser = modelT_Bus_AssignedInfo.F_CreateUser;
                                AssignedInfo.F_CreateTime = modelT_Bus_AssignedInfo.F_CreateTime;
                                AssignedInfo.F_IsDelete = 0;
                                AssignedInfo.F_IsOverdue = 0;
                                AssignedInfo.F_IsSure = 0;
                                AssignedInfo.F_IsReload = n + 1;
                                AssignedInfo.F_ReloadUser = User.F_UserCode;
                                AssignedInfo.F_ReloadTime = DateTime.Now;

                                assignBLL.Add(AssignedInfo);
                                #endregion

                                modelT_Bus_RemindRecord.F_AssignedId = AssignedInfo.F_Id;
                                modelT_Bus_RemindRecord.F_DeptId = AssignedInfo.F_MainDeptId;
                            }
                            else if (modelT_Bus_WorkOrder.F_IsResult == 1)//直办后重办
                            {
                                var cruser = userBLL.GetModel(modelT_Bus_WorkOrder.F_CreateUser);
                                if (cruser != null)
                                {
                                    modelT_Bus_RemindRecord.F_DeptId = cruser.F_DeptId;
                                }
                            }

                            modelT_Bus_RemindRecord.F_Content = overseeopinion;
                            modelT_Bus_RemindRecord.F_State = 1;
                            modelT_Bus_RemindRecord.F_IsDelete = 0;
                            modelT_Bus_RemindRecord.F_CreateUser = User.F_UserCode;
                            modelT_Bus_RemindRecord.F_CreateTime = DateTime.Now;

                            new BLL.T_Bus_RemindRecord().Add(modelT_Bus_RemindRecord);
                            #endregion

                            #region 保存工单信息
                            //modelT_Bus_WorkOrder.F_WorkState = 8;//重办中
                            // modelT_Bus_WorkOrder.F_IsSms = 0;
                            keyValuePairs.Add("F_WorkState", (int)EnumWorkState.reload);
                            modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.reload;//重办中
                           // keyValuePairs.Add("F_IsExamine", 1);
                            //modelT_Bus_WorkOrder.F_IsExamine = 1;
                            keyValuePairs.Add("F_Result", "");
                            //modelT_Bus_WorkOrder.F_Result = "";
                            keyValuePairs.Add("F_DealDeptId", null);
                            //modelT_Bus_WorkOrder.F_DealDeptId = null;
                            keyValuePairs.Add("F_DealUser", "");
                            //modelT_Bus_WorkOrder.F_DealUser = "";
                            keyValuePairs.Add("F_DealTime", null);
                           // modelT_Bus_WorkOrder.F_DealTime = null;
                            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;
                            if (modelT_Bus_AssignedInfo != null)
                            {
                                oper.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                            }
                            oper.F_State = modelT_Bus_WorkOrder.F_WorkState;

                            string deptname = "";
                            #region 20191021调整为多个主办单位时调整
                            var deptinfo = new BLL.T_Sys_Department().GetModel(modelT_Bus_AssignedInfo.F_MainDeptId.Value);
                            if (deptinfo != null) { deptname = deptinfo.F_DeptName; }
                            #endregion
                            string userinfo = User.depname + "(" + User.F_UserCode + ")";
                            oper.F_Message = userinfo + " 重办并督办了工单，交办单位：" + deptname;

                            oper.F_CreateUser = User.F_UserCode;
                            oper.F_CreateTime = DateTime.Now;
                            oper.F_IsDelete = 0;

                            operBLL.Add(oper);

                            //推送消息表
                            var users = userBLL.GetModelList(" F_DeptId='" + modelT_Bus_AssignedInfo.F_MainDeptId + "' ");

                            foreach (var u in users)
                            {
                                msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, u.F_UserCode, User.F_UserCode, (int)EnumSmsType.workorder);
                            }
                            #endregion

                            trans.Complete();
                        }
                        return Success("操作成功");
                    }
                    else
                    {
                        return Error("已经处理过了");
                    }
                }
                else
                {
                    return Error("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }
        /// <summary>
        /// 重办提交工单 提交后为重办待交办
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult SubReloadWorkOrder(string ids, string reason
            , int iszb = 0)
        {
            int maindeptid = RequestString.GetInt("maindeptid", 0);
            string otherdeptids = RequestString.GetFormString("otherdeptids");
            DateTime limittime = DateTime.Parse(RequestString.GetFormString("limittime") + " 23:59:59");
            string assignedopinion = RequestString.GetFormString("assignedopinion");
            if (User.F_RoleCode == "ZJZY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "MTDD")
            {
                if (!string.IsNullOrEmpty(ids))
                {

                    Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(ids);
                    if (modelT_Bus_WorkOrder != null)
                    {
                        if (iszb == 0)
                        {
                            if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.finish || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.rejload
                           || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.dealed
                           || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.visit)
                            {
                                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                                #region 保存工单信息
                                keyValuePairs.Add("F_SubmitTime", DateTime.Now);
                                // modelT_Bus_WorkOrder.F_SubmitTime = DateTime.Now;
                                keyValuePairs.Add("F_WorkState", (int)EnumWorkState.resubmit);
                                modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.resubmit;//待交办
                               // keyValuePairs.Add("F_IsExamine", 1);
                                //modelT_Bus_WorkOrder.F_IsExamine = 1;
                                keyValuePairs.Add("F_IsSms", 0);
                                // modelT_Bus_WorkOrder.F_IsSms = 0;
                                keyValuePairs.Add("F_Identification", 0);
                                //  modelT_Bus_WorkOrder.F_Identification = 0;
                                #region 重办待交办时-主办单位清空 zhengbingbing 20191016
                                keyValuePairs.Add("F_MainDeptId", null);
                                // modelT_Bus_WorkOrder.F_MainDeptId = null;
                                keyValuePairs.Add("F_OtherDeptIds", "");
                                // modelT_Bus_WorkOrder.F_OtherDeptIds = "";
                                keyValuePairs.Add("F_DealDeptId", null);
                               // modelT_Bus_WorkOrder.F_DealDeptId = null;
                                #endregion
                                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 = modelT_Bus_WorkOrder.F_WorkState;

                                string userinfo = User.depname + "(" + User.F_UserCode + ")";


                                oper.F_Message = userinfo + "于" + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒") + "提交重办了工单，重办原因：" + reason;
                                oper.F_CreateUser = User.F_UserCode;
                                oper.F_CreateTime = DateTime.Now;
                                oper.F_IsDelete = 0;

                                operBLL.Add(oper);
                                var t_Bus_RemindRecord = new BLL.T_Bus_RemindRecord().GetNewModelByWorkOrderID(modelT_Bus_WorkOrder.F_WorkOrderId);
                                if (t_Bus_RemindRecord != null)
                                {
                                    t_Bus_RemindRecord.F_State = 0;
                                    new BLL.T_Bus_RemindRecord().Update(t_Bus_RemindRecord);
                                }
                                #endregion
                            }
                            else
                            {
                                return Error("此工单已处理");
                            }

                        }
                        else
                        {
                            if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.rejload)
                            {
                                #region 保存工单信息
                                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                                keyValuePairs.Add("F_SubmitTime", DateTime.Now);
                                //  modelT_Bus_WorkOrder.F_SubmitTime = DateTime.Now;
                                keyValuePairs.Add("F_WorkState", (int)EnumWorkState.submit);
                                modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.submit;//待交办
                                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 = modelT_Bus_WorkOrder.F_WorkState;

                                string userinfo = User.depname + "(" + User.F_UserCode + ")";
                                if (!string.IsNullOrEmpty(assignedopinion))
                                {
                                    oper.F_Message = userinfo + " 提交了驳回重办工单，意见:" + assignedopinion;
                                }
                                else
                                {
                                    oper.F_Message = userinfo + " 提交了驳回重办工单";
                                }

                                oper.F_CreateUser = User.F_UserCode;
                                oper.F_CreateTime = DateTime.Now;
                                oper.F_IsDelete = 0;

                                operBLL.Add(oper);
                                #endregion  插入操作记录
                                //推送消息表
                                //if (modelT_Bus_WorkOrder.F_WorkState == 1)
                                if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.submit)
                                {

                                    var role = new BLL.T_Sys_RoleInfo().GetModelList(" (F_RoleCode='ZXLD' or F_RoleCode='ZXLDGLYGLY' or F_RoleCode='MTDD')  ").Select(p => p.F_RoleId);
                                    if (role!=null &&role.Count ()>0)
                                     {
                                        var users = userBLL.GetModelList(" F_RoleId in (" + string.Join(",", role) + ")  ");
                                        if (users!=null && users.Count ()>0)
                                        {
                                            foreach (var u in users)
                                            {
                                                msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, u.F_UserCode, User.F_UserCode, (int)EnumSmsType.workorder);
                                            }
                                        }
                                        
                                    }
                                   
                                }
                            }
                            else
                            {
                                if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.finish && (modelT_Bus_WorkOrder.F_RemindDay == 1 || modelT_Bus_WorkOrder.F_RemindDay == 3))
                                {
                                    return Error("结案后工单只能提交重办一次");
                                }
                                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                                if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.finish)
                                {
                                    if (modelT_Bus_WorkOrder.F_RemindDay == 2 || modelT_Bus_WorkOrder.F_RemindDay == 3)
                                        keyValuePairs.Add("F_RemindDay", 3);
                                    else
                                        keyValuePairs.Add("F_RemindDay", 1);
                                }
                                if (modelT_Bus_WorkOrder.F_MainDeptId != null &&
                                modelT_Bus_WorkOrder.F_MainDeptId > 0)
                                {
                                    Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID
                                  (modelT_Bus_WorkOrder.F_WorkOrderId);
                                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.finish || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.rejload
    || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.dealed
    || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.visit)
                                    {

                                        if (User.F_RoleCode == "ZXHWY")
                                        {
                                            Dictionary<string, object> keyValuePairs3 = new Dictionary<string, object>();
                                            keyValuePairs3.Add("F_WorkState", (int)EnumWorkState.backaudit);
                                            modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.backaudit;//重办审核
                                            if (workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs3))
                                            {
                                                #region 插入操作记录

                                                #region 20191021调整为多个主办单位时调整

                                                #endregion
                                              
                                                #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 deptname = "";
                                                #region 20191021调整为多个主办单位时调整
                                                //var deptinfo = new BLL.T_Sys_Department().GetModel(modelT_Bus_AssignedInfo.F_MainDeptId.Value);
                                                var deptinfo = new BLL.T_Sys_Department().GetModel((int)modelT_Bus_WorkOrder.F_MainDeptId);
                                                if (deptinfo != null) { deptname = deptinfo.F_DeptName; }
                                                #endregion

                                                string userinfo = User.depname + "(" + User.F_UserCode + ")";
                                                oper.F_Message = userinfo + "于" + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒") + "退回重办了工单，重办原因：" + reason;
                                                if (!string.IsNullOrEmpty(otherdeptids))
                                                {
                                                    string sql = "select dbo.GetDeptNames('" + otherdeptids + "')";
                                                    oper.F_Message += "，协办单位：" + DbHelperSQL.GetSingle(sql);
                                                }

                                                oper.F_CreateUser = User.F_UserCode;
                                                oper.F_CreateTime = DateTime.Now;
                                                oper.F_IsDelete = 0;
                                                operBLL.Add(oper);
                                                //推送消息表
                                                var users = userBLL.GetModelList(" F_DeptId='" + deptinfo.F_DeptId + "' ");

                                                foreach (var u in users)
                                                {
                                                    msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, u.F_UserCode, User.F_UserCode, (int)EnumSmsType.workorder);
                                                }
                                                #endregion

                                            }
                                        }
                                        else
                                        {
                                            int n = Int32.Parse(DbHelperSQL.GetSingle("select count(1) from T_Bus_AssignedInfo WITH(NOLOCK) where F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and  F_State=1 and F_IsSure=1 and F_IsDelete=0 and isnull(F_IsReload,0)>0").ToString());
                                            Model.T_Bus_AssignedInfo newmodelT_Bus_AssignedInfo = new Model.T_Bus_AssignedInfo();
                                            newmodelT_Bus_AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                            DataTable dt = DbHelperSQL.Query("select top 6 F_OffDate from  T_Sys_WorkOFFDays  where F_OffState = 1   and F_OffDate>='" + DateTime.Now + "' order by F_OffDate ").Tables[0];
                                            var resdatetime = dt.Rows[5]["F_OffDate"].ToString();
                                            if (!string.IsNullOrEmpty(resdatetime))
                                            {
                                                newmodelT_Bus_AssignedInfo.F_LimitTime = DateTime.Parse(resdatetime.Split(' ')[0] + " 23:59:59");//办理时限
                                            }
                                            newmodelT_Bus_AssignedInfo.F_MainDeptId = modelT_Bus_WorkOrder.F_MainDeptId;//主办单位id
                                            newmodelT_Bus_AssignedInfo.F_OtherDeptIds = "";//协办单位id
                                            newmodelT_Bus_AssignedInfo.F_AssignedOpinion = reason;//交办意见
                                            newmodelT_Bus_AssignedInfo.F_State = 1;
                                            newmodelT_Bus_AssignedInfo.F_CreateUser = User.F_UserCode;
                                            newmodelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                                            newmodelT_Bus_AssignedInfo.F_IsDelete = 0;
                                            newmodelT_Bus_AssignedInfo.F_IsOverdue = 0;
                                            newmodelT_Bus_AssignedInfo.F_IsSure = 0;
                                            newmodelT_Bus_AssignedInfo.F_IsReload = n + 1;
                                            newmodelT_Bus_AssignedInfo.F_ReloadUser = User.F_UserCode;
                                            newmodelT_Bus_AssignedInfo.F_ReloadTime = DateTime.Now;
                                            newmodelT_Bus_AssignedInfo.F_IsNext = 0;
                                            newmodelT_Bus_AssignedInfo.F_Id = assignBLL.Add(newmodelT_Bus_AssignedInfo);
                                            if (newmodelT_Bus_AssignedInfo.F_Id > 0)
                                            {
                                                #region 保存工单信息
                                                keyValuePairs.Add("F_MainDeptId", modelT_Bus_WorkOrder.F_MainDeptId);
                                                modelT_Bus_WorkOrder.F_MainDeptId = modelT_Bus_WorkOrder.F_MainDeptId;
                                                keyValuePairs.Add("F_OtherDeptIds", modelT_Bus_WorkOrder.F_OtherDeptIds);
                                                // modelT_Bus_WorkOrder.F_OtherDeptIds = modelT_Bus_WorkOrder.F_OtherDeptIds;
                                                keyValuePairs.Add("F_AssignUser", User.F_UserCode);
                                                //  modelT_Bus_WorkOrder.F_AssignUser = User.F_UserCode;
                                                keyValuePairs.Add("F_AssignTime", DateTime.Now);
                                                //  modelT_Bus_WorkOrder.F_AssignTime = DateTime.Now;

                                                keyValuePairs.Add("F_IsReload", n + 1);
                                                // modelT_Bus_WorkOrder.F_IsReload = n + 1;
                                                if (!string.IsNullOrEmpty(resdatetime))
                                                    keyValuePairs.Add("F_LimitTime", DateTime.Parse(resdatetime.Split(' ')[0] + " 23:59:59"));
                                                keyValuePairs.Add("F_IsOverdue", 0);
                                                //  modelT_Bus_WorkOrder.F_IsOverdue = 0;

                                                keyValuePairs.Add("F_IsSms", 0);
                                                //  modelT_Bus_WorkOrder.F_IsSms = 0;
                                                keyValuePairs.Add("F_WorkState", (int)EnumWorkState.reload);
                                                modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.reload;//重办中

                                                //modelT_Bus_WorkOrder.F_IsExamine = 1;
                                                keyValuePairs.Add("F_Identification", 1);
                                                // modelT_Bus_WorkOrder.F_Identification = 1;
                                                keyValuePairs.Add("F_Result", "");
                                                //  modelT_Bus_WorkOrder.F_Result = "";
                                                keyValuePairs.Add("F_DealDeptId", null);
                                                //  modelT_Bus_WorkOrder.F_DealDeptId = null;
                                                keyValuePairs.Add("F_DealUser", "");
                                                // modelT_Bus_WorkOrder.F_DealUser = "";
                                                keyValuePairs.Add("F_DealTime", null);
                                                // modelT_Bus_WorkOrder.F_DealTime = null;
                                                if (workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs))
                                                {
                                                    var user = new BLL.T_Sys_UserAccount().GetModelList("F_DeptId in ('" + modelT_Bus_WorkOrder.F_MainDeptId + "') ");
                                                    if (user != null && user.Count > 0)
                                                    {
                                                        foreach (var it in user)
                                                        {
                                                            string count = "你有退回重办工单：" + modelT_Bus_WorkOrder.F_WorkOrderId + "，请及时查收处理";
                                                            // string msg = modelT_Bus_WorkOrder.F_WorkOrderId;
                                                            //  bool v = SMSController.AddSmS(0, msg, count, it.F_Mobile, "196362", "");
                                                            string mag = "[\"" + modelT_Bus_WorkOrder.F_WorkOrderId + "\"]";
                                                            string v = SmsNewController.AddSmS(0, count, it.F_Mobile,
                                                    "681240339285540864", mag, modelT_Bus_WorkOrder.F_WorkOrderId);
                                                        }
                                                    }
                                                    #region 插入操作记录
                                                    Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                                                    oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                                    oper.F_AssignedId = newmodelT_Bus_AssignedInfo.F_Id;
                                                    oper.F_State = modelT_Bus_WorkOrder.F_WorkState;

                                                    string deptname = "";
                                                    #region 20191021调整为多个主办单位时调整
                                                    //var deptinfo = new BLL.T_Sys_Department().GetModel(modelT_Bus_AssignedInfo.F_MainDeptId.Value);
                                                    var deptinfo = new BLL.T_Sys_Department().GetModel((int)modelT_Bus_WorkOrder.F_MainDeptId);
                                                    if (deptinfo != null) { deptname = deptinfo.F_DeptName; }
                                                    #endregion

                                                    string userinfo = User.depname + "(" + User.F_UserCode + ")";
                                                    oper.F_Message = userinfo + "于" + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒") + "提交重办了工单，重办原因：" + reason;
                                                    if (!string.IsNullOrEmpty(otherdeptids))
                                                    {
                                                        string sql = "select dbo.GetDeptNames('" + otherdeptids + "')";
                                                        oper.F_Message += "，协办单位：" + DbHelperSQL.GetSingle(sql);
                                                    }

                                                    oper.F_CreateUser = User.F_UserCode;
                                                    oper.F_CreateTime = DateTime.Now;
                                                    oper.F_IsDelete = 0;
                                                    operBLL.Add(oper);
                                                    //推送消息表
                                                    var users = userBLL.GetModelList(" F_DeptId='" + deptinfo.F_DeptId + "' ");

                                                    foreach (var u in users)
                                                    {
                                                        msg.AddInternalMessagesInfo("工单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, u.F_UserCode, User.F_UserCode, (int)EnumSmsType.workorder);
                                                    }
                                                    #endregion
                                                    return Success("操作成功");
                                                }
                                                else
                                                {
                                                    return Error("重办失败");
                                                }
                                                #endregion
                                            }
                                            else
                                            {
                                                return Error("退回失败");
                                            }

                                        }


                                       
                                    }
                                    else
                                    {
                                        return Error("已经处理过了");
                                    }
                                }
                                else
                                {
                                    #region 保存工单信息
                                    keyValuePairs.Add("F_MainDeptId", modelT_Bus_WorkOrder.F_MainDeptId);
                                    //  modelT_Bus_WorkOrder.F_MainDeptId = modelT_Bus_WorkOrder.F_MainDeptId;
                                    keyValuePairs.Add("F_OtherDeptIds", modelT_Bus_WorkOrder.F_OtherDeptIds);
                                    //modelT_Bus_WorkOrder.F_OtherDeptIds = modelT_Bus_WorkOrder.F_OtherDeptIds;
                                    keyValuePairs.Add("F_AssignUser", User.F_UserCode);
                                    // modelT_Bus_WorkOrder.F_AssignUser = User.F_UserCode;
                                    keyValuePairs.Add("F_AssignTime", DateTime.Now);
                                    //modelT_Bus_WorkOrder.F_AssignTime = DateTime.Now;
                                    keyValuePairs.Add("F_IsReload", 1);
                                    //  modelT_Bus_WorkOrder.F_IsReload = 1;
                                    keyValuePairs.Add("F_IsOverdue", 0);
                                    // modelT_Bus_WorkOrder.F_IsOverdue = 0;
                                    keyValuePairs.Add("F_WorkState", (int)EnumWorkState.resubmit);
                                  modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.resubmit;//重办中
                                 
                                    // modelT_Bus_WorkOrder.F_IsExamine = 1;
                                    keyValuePairs.Add("F_Identification", 0);
                                    // modelT_Bus_WorkOrder.F_Identification = 0;
                                    keyValuePairs.Add("F_Result", "");
                                    //  modelT_Bus_WorkOrder.F_Result = "";
                                    keyValuePairs.Add("F_DealDeptId", null);
                                    // modelT_Bus_WorkOrder.F_DealDeptId = null;
                                    keyValuePairs.Add("F_DealUser", "");
                                    //  modelT_Bus_WorkOrder.F_DealUser = "";
                                    keyValuePairs.Add("F_DealTime", null);
                                   // modelT_Bus_WorkOrder.F_DealTime = null;
                                    if (workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs))
                                    {
                                        #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 + "于" + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss秒") + "提交重办了工单，重办原因：" + reason;
                                        if (!string.IsNullOrEmpty(otherdeptids))
                                        {
                                            string sql = "select dbo.GetDeptNames('" + otherdeptids + "')";
                                            oper.F_Message += "，协办单位：" + DbHelperSQL.GetSingle(sql);
                                        }
                                        oper.F_CreateUser = User.F_UserCode;
                                        oper.F_CreateTime = DateTime.Now;
                                        oper.F_IsDelete = 0;
                                        operBLL.Add(oper);
                                        //推送消息表
                                        var t_Bus_RemindRecord = new BLL.T_Bus_RemindRecord().GetNewModelByWorkOrderID(modelT_Bus_WorkOrder.F_WorkOrderId);
                                        if (t_Bus_RemindRecord != null)
                                        {
                                            t_Bus_RemindRecord.F_State = 0;
                                            new BLL.T_Bus_RemindRecord().Update(t_Bus_RemindRecord);
                                        }
                                        #endregion
                                    }
                                    else
                                    {
                                        return Error("重办失败");
                                    }
                                    #endregion

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

                    return Success("操作成功");


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

        /// <summary>
        /// 驳回重办，驳回后状态为重办驳回状态
        /// 调度员可驳回
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        //[Authority]
        public ActionResult RejReloadWorkOrder(string id, string reason)
        {


            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {
                if (!string.IsNullOrEmpty(id))
                {
                    using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                    {
                        Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(id.Trim());
                        if (modelT_Bus_WorkOrder != null)
                        {
                            Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetModelList(" F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "'and F_FeedbackTime is not null and F_FeedbackTime !='' order by F_CreateTime desc ").FirstOrDefault();
                            if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.resubmit)
                            {
                                #region 保存工单信息
                                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                              //  keyValuePairs.Add("F_IsExamine", 1);
                                // modelT_Bus_WorkOrder.F_IsExamine = 1;
                                keyValuePairs.Add("F_WorkState", (int)EnumWorkState.rejload);
                                modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.rejload;//重办驳回

                                if (modelT_Bus_AssignedInfo != null)
                                {
                                    Model.T_Bus_Feedback modelT_Bus_Feedback = feedbackBLL.GetModelList(" F_AssignedId=" + modelT_Bus_AssignedInfo.F_Id + " and F_IsFeedEnd=1 and   F_State=1  order by F_CreateTime desc").FirstOrDefault();
                                  
                                    #region 重办驳回时-恢复主办单位 zhengbingbing 20191017
                                    keyValuePairs.Add("F_MainDeptId", modelT_Bus_AssignedInfo.F_MainDeptId);
                                    // modelT_Bus_WorkOrder.F_MainDeptId = modelT_Bus_AssignedInfo.F_MainDeptId;
                                    keyValuePairs.Add("F_Identification", 1);
                                    //modelT_Bus_WorkOrder.F_Identification = 1;
                                    keyValuePairs.Add("F_OtherDeptIds", modelT_Bus_AssignedInfo.F_OtherDeptIds);
                                    // modelT_Bus_WorkOrder.F_OtherDeptIds = modelT_Bus_AssignedInfo.F_OtherDeptIds;
                                    keyValuePairs.Add("F_DealDeptId", modelT_Bus_Feedback.F_CreateDeptId);
                                    //  modelT_Bus_WorkOrder.F_DealDeptId = modelT_Bus_Feedback.F_CreateDeptId;
                                    keyValuePairs.Add("F_DealUser", modelT_Bus_Feedback.F_CreateUser);
                                    //modelT_Bus_WorkOrder.F_DealUser = modelT_Bus_Feedback.F_CreateUser;
                                    keyValuePairs.Add("F_DealTime", modelT_Bus_Feedback.F_CreateTime);
                                   // modelT_Bus_WorkOrder.F_DealTime = modelT_Bus_Feedback.F_CreateTime;
                                    #endregion
                                }
                                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 = modelT_Bus_WorkOrder.F_WorkState;

                                string userinfo = User.depname + "(" + User.F_UserCode + ")";
                                oper.F_Message = userinfo + " 驳回重办工单，驳回原因：" + reason;
                                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("权限不足");
            }
        }

        /// <summary>
        /// 重办工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult NewReloadWorkOrder(List<maindeptcontent> content)
        {

           // var User = new BLL.T_Sys_UserAccount ().GetModel("8000");


            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "MTDD")
            //if (User.F_RoleCode == "ZJZY" || User.F_RoleCode == "GLY")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                string maindeptid = RequestString.GetFormString("maindeptid");
                string otherdeptids = RequestString.GetFormString("otherdeptids");
                //  DateTime limittime = DateTime.Parse(RequestString.GetFormString("limittime") + " 23:59:59");
                int limittime = RequestString.GetInt("limittime", 0);
                string assignedopinion = RequestString.GetFormString("assignedopinion");
                var premodeldept = new Model.T_Sys_Department();
                var curuser = User;
                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  where F_OffState = 1   and F_OffDate>'" + resdate + "' order by F_OffDate").Tables[0];
                    resdatetime = dt.Rows[dt.Rows.Count - 1]["F_OffDate"].ToString();
                }
                else
                {
                    return Error("请选择办理时限");
                }
                resdatetime = Convert.ToDateTime(resdatetime).ToString("yyyy-MM-dd") + " 23:59:59 ";
                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)
                {

                    var deptlist = new BLL.T_Sys_Department().GetModelList("F_DeptId in (" + maindeptid + ")");
                    if (deptlist != null)
                    {
                        if (deptlist.Count == 1)
                        {
                            var deptinfo = deptlist.FirstOrDefault();
                            if (deptinfo.F_IsDept == 2)
                            {
                                if (deptinfo.F_PartentId > 0)
                                {
                                    premodeldept = department((int)deptinfo.F_PartentId);
                                    if (premodeldept == null)
                                        return Error("该单位没有上级单位,派单失败");
                                }
                                else
                                {
                                    return Error("该单位没有上级单位,派单失败");
                                }
                            }

                        }
                        else
                        {
                            if (deptlist.Where(x => x.F_IsDept == 2).Count() > 0)
                                return Error("派单多单位不能派给三级单位");
                        }
                    }
                    else
                    {
                        return Error("单位不存在");
                    }

                    if (!string.IsNullOrEmpty(otherdeptids))
                    {
                        if (otherdeptids.Split(',').Contains(maindeptid.ToString()))
                        {
                            return Error("主办单位不能出现在协办单位");
                        }
                    }
                    //if (limittime < DateTime.Now)
                    //{
                    //    return Error("办理时限不能小于当前时间");
                    //}
                    string userinfo = User.depname + "(" + User.F_UserCode + ")";
                    //if (modelT_Bus_WorkOrder.F_WorkState == 7)
                    //if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.visit)
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.resubmit)
                    {
                        int n = Int32.Parse(DbHelperSQL.GetSingle("select count(1) from T_Bus_AssignedInfo WITH(NOLOCK) where F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "' and  F_State=1 and F_IsSure=1 and F_IsDelete=0 and isnull(F_IsReload,0)>0").ToString());
                        if (deptlist.Count == 1)
                        {
                            using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                            {
                             
                                var maindept = deptlist.FirstOrDefault();
                                Model.T_Bus_AssignedInfo newmodelT_Bus_AssignedInfo = new Model.T_Bus_AssignedInfo();
                                newmodelT_Bus_AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                                newmodelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(resdatetime);//办理时限
                                if (maindept.F_IsDept == 2)
                                    newmodelT_Bus_AssignedInfo.F_MainDeptId = premodeldept.F_DeptId;//主办单位id
                                else
                                    newmodelT_Bus_AssignedInfo.F_MainDeptId = maindept.F_DeptId;


                               // newmodelT_Bus_AssignedInfo.F_MainDeptId = maindeptid;//主办单位id
                                newmodelT_Bus_AssignedInfo.F_OtherDeptIds = otherdeptids;//协办单位id
                                newmodelT_Bus_AssignedInfo.F_AssignedOpinion = assignedopinion;//交办意见

                                newmodelT_Bus_AssignedInfo.F_State = 1;
                                newmodelT_Bus_AssignedInfo.F_CreateUser = User.F_UserCode;
                                newmodelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                                newmodelT_Bus_AssignedInfo.F_IsDelete = 0;
                                newmodelT_Bus_AssignedInfo.F_IsOverdue = 0;
                                newmodelT_Bus_AssignedInfo.F_IsSure = 0;
                                newmodelT_Bus_AssignedInfo.F_IsReload = n + 1;
                                newmodelT_Bus_AssignedInfo.F_ReloadUser = User.F_UserCode;
                                newmodelT_Bus_AssignedInfo.F_ReloadTime = DateTime.Now;
                                newmodelT_Bus_AssignedInfo.F_IsNext = 0;
                                newmodelT_Bus_AssignedInfo.F_Id = assignBLL.Add(newmodelT_Bus_AssignedInfo);

                                #region 保存工单信息
                                Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                                if (maindept.F_IsDept == 2)
                                    keyValuePairs.Add("F_MainDeptId", premodeldept.F_DeptId);
                                else
                                    keyValuePairs.Add("F_MainDeptId", maindept.F_DeptId);
                                if (content != null && content.Count > 0)
                                {
                                    keyValuePairs.Add("F_Content", content[0]);
                                    keyValuePairs.Add("F_ComContent", content[0]);
                                }

                                //modelT_Bus_WorkOrder.F_MainDeptId = maindeptid;
                                keyValuePairs.Add("F_OtherDeptIds", otherdeptids);
                                // modelT_Bus_WorkOrder.F_OtherDeptIds = otherdeptids;
                                keyValuePairs.Add("F_AssignUser", User.F_UserCode);
                                //modelT_Bus_WorkOrder.F_AssignUser = User.F_UserCode;
                                keyValuePairs.Add("F_AssignTime", DateTime.Now);
                                // modelT_Bus_WorkOrder.F_AssignTime = DateTime.Now;
                                keyValuePairs.Add("F_MainDeptID3", "");
                                //modelT_Bus_WorkOrder.F_MainDeptID3 = "";
                                keyValuePairs.Add("F_IsReload", n + 1);

                                //modelT_Bus_WorkOrder.F_IsReload = n + 1;
                                keyValuePairs.Add("F_LimitTime", Convert.ToDateTime(resdatetime));
                                // modelT_Bus_WorkOrder.F_LimitTime = limittime;
                                keyValuePairs.Add("F_IsOverdue", 0);
                                keyValuePairs.Add("F_Identification", 0);
                                
                                //modelT_Bus_WorkOrder.F_IsOverdue = 0;
                                //modelT_Bus_WorkOrder.F_WorkState = 8;//重办中
                                keyValuePairs.Add("F_WorkState", (int)EnumWorkState.reload);
                                modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.reload;//重办中
                               // keyValuePairs.Add("F_IsExamine", 1);
                                // modelT_Bus_WorkOrder.F_IsExamine = 1;                                                //   modelT_Bus_WorkOrder.F_IsSms = 0;
                                keyValuePairs.Add("F_Result", "");
                                //modelT_Bus_WorkOrder.F_Result = "";
                                keyValuePairs.Add("F_DealDeptId", null);
                                // modelT_Bus_WorkOrder.F_DealDeptId = null;
                                keyValuePairs.Add("F_DealUser", "");
                                //  modelT_Bus_WorkOrder.F_DealUser = "";
                                keyValuePairs.Add("F_DealTime", null);
                                //modelT_Bus_WorkOrder.F_DealTime = null;
                                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_AssignedId = newmodelT_Bus_AssignedInfo.F_Id;
                                oper.F_State = modelT_Bus_WorkOrder.F_WorkState;

                                string deptname = "";
                                #region 20191021调整为多个主办单位时调整
                                //var deptinfo = new BLL.T_Sys_Department().GetModel(modelT_Bus_AssignedInfo.F_MainDeptId.Value);
                                if (maindept.F_IsDept == 2)
                                {
                                    deptname = premodeldept.F_DeptName;
                                }
                                else
                                    deptname = maindept.F_DeptName;
                               
                                if (maindept.F_IsDept == 2)
                                {
                                    SplitOrderNew(modelT_Bus_WorkOrder, maindept, Convert.ToDateTime(resdatetime), modelT_Bus_AssignedInfo, assignedopinion, curuser).ContinueWith(p =>
                                    {
                                        System.Diagnostics.Debug.WriteLine(DateTime.Now);
                                    });
                                }


                                #endregion

                              
                                oper.F_Message = userinfo + " 重办了工单，主办单位：" + deptname;
                                if (!string.IsNullOrEmpty(otherdeptids))
                                {
                                    string sql = "select dbo.GetDeptNames('" + otherdeptids + "')";
                                    oper.F_Message += "，协办单位：" + DbHelperSQL.GetSingle(sql);
                                }
                                var user = new BLL.T_Sys_UserAccount().GetModelList("F_DeptId in ('" + maindeptid + "') ");
                                if (user != null && user.Count > 0)
                                {
                                    foreach (var it in user)
                                    {
                                        if (it.F_RoleCode == "WLDW" && it.F_IsSms != null && it.F_IsSms == 1)
                                        {
                                            continue;
                                        }
                                        string count = "你有新工单：" + workorderid + "，请及时查收处理。";
                                        // string msg = workorderid;
                                        // bool v = SMSController.AddSmS(0, msg, count, it.F_Mobile, "153305", "");
                                        string mag = "[\"" + workorderid + "\"]";
                                        string v = SmsNewController.AddSmS(0, count, it.F_Mobile, "681240888655478784", mag,
                                       workorderid);
                                    }
                                }
                                oper.F_CreateUser = User.F_UserCode;
                                oper.F_CreateTime = DateTime.Now;
                                oper.F_IsDelete = 0;
                                operBLL.Add(oper);
                                #endregion

                                trans.Complete();
                            }
                        }
                        else
                        {
                           Task.Run(() =>
                           {
                                string newids = ""; string errdeptid = ""; string deptname = "";
                                Model.T_Bus_WorkOrder tempT_Bus_WorkOrder = modelT_Bus_WorkOrder.ToJson().ToObject<Model.T_Bus_WorkOrder>();
                                Model.T_Bus_RemindRecord t_Bus_RemindRecord = new Model.T_Bus_RemindRecord();
                                if (curuser.F_RoleCode == "DBZY")
                                {
                                    t_Bus_RemindRecord = new BLL.T_Bus_RemindRecord().GetNewModelByWorkOrderID(tempT_Bus_WorkOrder.F_WorkOrderId);
                                }
                                object obj = new object();
                                List<Task> taskList = new List<Task>();
                                foreach (var deptinfo in deptlist)
                                {
                                    deptname += deptinfo.F_DeptName + "，";

                                    #region 新增工单
                                    Model.T_Bus_WorkOrder modelT_Bus_WorkOrder1 = new Model.T_Bus_WorkOrder();
                                    modelT_Bus_WorkOrder1 = tempT_Bus_WorkOrder;
                                    string creattime = ((DateTime)modelT_Bus_WorkOrder1.F_CreateTime).ToString("yyyy-MM-dd") + " 00:00:00";
                                    string endtime = ((DateTime)modelT_Bus_WorkOrder1.F_CreateTime).ToString("yyyy-MM-dd") + " 23:59:59";
                                    modelT_Bus_WorkOrder1.F_WorkOrderId = workorderBLL.GetNewWorkOrderID((int)modelT_Bus_WorkOrder.F_InfoSource, (int)modelT_Bus_WorkOrder.F_SourceArea, creattime, endtime);
                                    modelT_Bus_WorkOrder1.F_MainWorkorder1 = modelT_Bus_WorkOrder.F_WorkOrderId;
                                    if (content != null && content.Count > 0)
                                    {
                                        if (content.Where(x => x.id == deptinfo.F_DeptId).Count() > 0)
                                        {
                                            modelT_Bus_WorkOrder1.F_Content = content.Where(x => x.id == deptinfo.F_DeptId).First().content;
                                            modelT_Bus_WorkOrder1.F_ComContent = content.Where(x => x.id == deptinfo.F_DeptId).First().content;
                                        }
                                    }
                                   modelT_Bus_WorkOrder1.F_IsRelease = null;
                                   modelT_Bus_WorkOrder1.F_Id = workorderBLL.Add(modelT_Bus_WorkOrder1);

                                    if (curuser.F_RoleCode == "DBZY")
                                    {
                                        Model.T_Bus_RemindRecord t_Bus_RemindRecord_1 = t_Bus_RemindRecord;
                                        t_Bus_RemindRecord_1.F_WorkOrderId = modelT_Bus_WorkOrder1.F_WorkOrderId;
                                        new BLL.T_Bus_RemindRecord().Add(t_Bus_RemindRecord_1);
                                    }
                                    #endregion

                                    if (modelT_Bus_WorkOrder1.F_Id > 0)
                                    {
                                        #region 插入交办记录
                                        Model.T_Bus_AssignedInfo newmodelT_Bus_AssignedInfo = new Model.T_Bus_AssignedInfo();
                                        newmodelT_Bus_AssignedInfo.F_WorkOrderId = modelT_Bus_WorkOrder1.F_WorkOrderId;
                                        newmodelT_Bus_AssignedInfo.F_LimitTime = Convert.ToDateTime(resdatetime);//办理时限
                                    newmodelT_Bus_AssignedInfo.F_MainDeptId = deptinfo.F_DeptId;
                                        newmodelT_Bus_AssignedInfo.F_OtherDeptIds = otherdeptids;//协办单位id
                                        newmodelT_Bus_AssignedInfo.F_AssignedOpinion = assignedopinion;//交办意见
                                        newmodelT_Bus_AssignedInfo.F_State = 1;
                                        newmodelT_Bus_AssignedInfo.F_CreateUser = curuser.F_UserCode;
                                        newmodelT_Bus_AssignedInfo.F_CreateTime = DateTime.Now;
                                        newmodelT_Bus_AssignedInfo.F_IsDelete = 0;
                                        newmodelT_Bus_AssignedInfo.F_IsOverdue = 0;
                                        newmodelT_Bus_AssignedInfo.F_IsSure = 0;
                                        newmodelT_Bus_AssignedInfo.F_IsReload = n + 1;
                                        newmodelT_Bus_AssignedInfo.F_ReloadUser = curuser.F_UserCode;
                                        newmodelT_Bus_AssignedInfo.F_ReloadTime = DateTime.Now;
                                        newmodelT_Bus_AssignedInfo.F_IsNext = 0;
                                        newmodelT_Bus_AssignedInfo.F_Id = assignBLL.Add(newmodelT_Bus_AssignedInfo);

                                        #endregion

                                        if (newmodelT_Bus_AssignedInfo != null && newmodelT_Bus_AssignedInfo.F_State == 1)
                                        {
                                            #region 保存工单信息
                                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                                            keyValuePairs.Add("F_WorkState", (int)EnumWorkState.reload);
                                            modelT_Bus_WorkOrder1.F_WorkState = (int)EnumWorkState.reload;
                                            keyValuePairs.Add("F_LimitTime", Convert.ToDateTime(resdatetime));
                                            keyValuePairs.Add("F_MainDeptId", deptinfo.F_DeptId);
                                            modelT_Bus_WorkOrder1.F_MainDeptId = deptinfo.F_DeptId;
                                            keyValuePairs.Add("F_OtherDeptIds", otherdeptids);
                                            keyValuePairs.Add("F_AssignUser", curuser.F_UserCode);
                                            keyValuePairs.Add("F_IsReload", n + 1);
                                            keyValuePairs.Add("F_AssignTime", DateTime.Now);
                                            keyValuePairs.Add("F_IsSendBack", 0);
                                       //     keyValuePairs.Add("F_IsExamine", 1);
                                            keyValuePairs.Add("F_Result", "");
                                            keyValuePairs.Add("F_DealDeptId", null);
                                            keyValuePairs.Add("F_DealUser", "");
                                            keyValuePairs.Add("F_Identification", 0);
                                            keyValuePairs.Add("F_DealTime", null);
                                            workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder1.F_Id, keyValuePairs);
                                            #endregion
                                            var msgss = userinfo + " 重办了工单，主办单位：" + deptinfo.F_DeptName;
                                            if (!string.IsNullOrEmpty(otherdeptids))
                                            {
                                                string sql = "select dbo.GetDeptNames('" + otherdeptids + "')";
                                                msgss += "，协办单位：" + DbHelperSQL.GetSingle(sql);
                                            }
                                            #region 插入操作记录
                                            addoptlog(modelT_Bus_WorkOrder1.F_WorkOrderId, modelT_Bus_WorkOrder1.F_WorkState, newmodelT_Bus_AssignedInfo.F_Id, msgss, curuser.F_UserCode, 0, 1);
                                            #endregion
                                            #region 插入推送消息
                                            //推送消息表
                                            var users = userBLL.GetModelList(" F_DeptId='" + deptinfo.F_DeptId + "' ");

                                            foreach (var u in users)
                                            {
                                                msg.AddInternalMessagesInfo("工单消息", msgss + "，工单编号：" + modelT_Bus_WorkOrder1.F_WorkOrderId, u.F_UserCode, curuser.F_UserCode, (int)EnumSmsType.workorder);
                                            }
                                            #endregion

                                            #region 发短信
                                            var user = new BLL.T_Sys_UserAccount().GetModelList("F_DeptId =" + deptinfo.F_DeptId);
                                            if (user != null && user.Count > 0)
                                            {
                                                foreach (var it in user)
                                                {
                                                    if (curuser.F_RoleCode == "DBZY")
                                                    {
                                                     string count = "你有督办工单：" + modelT_Bus_WorkOrder1.F_WorkOrderId + "，请及时查收处理。";
                                                       // string msg = modelT_Bus_WorkOrder1.F_WorkOrderId;
                                                       //  bool v = SMSController.AddSmS(0, msg, count, it.F_Mobile, "242065", "");
                                                      
                                                       string mag = "[\"" + modelT_Bus_WorkOrder1.F_WorkOrderId + "\"]";
                                                       string v = SmsNewController.AddSmS(0, count, it.F_Mobile, "681240181093470208", mag, modelT_Bus_WorkOrder1.F_WorkOrderId);

                                                   }
                                                    else
                                                    {
                                                        if (it.F_RoleCode == "WLDW" && it.F_IsSms !=null && it.F_IsSms==1)
                                                    {
                                                            continue;
                                                        }
                                                        else
                                                        {
                                                            string count = "你有新工单：" + modelT_Bus_WorkOrder1.F_WorkOrderId + "，请及时查收处理。";
                                                           // string msg = modelT_Bus_WorkOrder1.F_WorkOrderId;
                                                           //  bool f = SMSController.AddSmS(0, msg, count, it.F_Mobile, "153305", "");
                                                           string mag = "[\"" + modelT_Bus_WorkOrder1.F_WorkOrderId + "\"]";
                                                           string v = SmsNewController.AddSmS(0, count, it.F_Mobile, "681240888655478784", mag, modelT_Bus_WorkOrder1.F_WorkOrderId);
                                                       }

                                                    }

                                                }
                                            }
                                            #endregion
                                        }
                                        newids += modelT_Bus_WorkOrder1.F_WorkOrderId + ",";
                                    }
                                    else
                                    {
                                        errdeptid += deptinfo.F_DeptName + ",";
                                    }
                                }

                                newids = newids.Trim(',');
                                var msgs = "";
                                if (errdeptid == "")
                                {
                                    Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                                    keyValuePairs.Add("F_SubWorkorder1", newids);
                                    modelT_Bus_WorkOrder.F_SubWorkorder1 = newids;
                                    workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs);
                                    msgs = userinfo + " 交办多单位：" + deptname + "生成新工单，新工单编号为：" + newids;
                                }
                                else
                                {
                                    errdeptid = errdeptid.Trim(',');
                                    msgs = userinfo + " 交办的单位有" + deptname + "部分操作成功，新工单编号为：" + newids + "，交办失败的部门为：" + errdeptid;
                                }

                                addoptlog(modelT_Bus_WorkOrder.F_WorkOrderId, modelT_Bus_WorkOrder.F_WorkState, 0, msgs, curuser.F_UserCode, 0, 1);


                            }).ContinueWith(p =>
                            {
                               System.Diagnostics.Debug.WriteLine(DateTime.Now);
                            });
                            Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                            keyValuePairs1.Add("F_IsSendBack", 0);
                            keyValuePairs1.Add("F_WorkState", (int)EnumWorkState.reload );
                            // modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.dealing;
                            workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs1);
                            return Success("操作成功");
                        }
                        return Success("操作成功");
                    }
                    else
                    {
                        return Error("已经处理过了");
                    }

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

        /// <summary>
        /// 结案工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult FinishWorkOrder()
        {
            //if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY")
            if (User.F_RoleCode == "ZJZY" || User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                string finalopinion = RequestString.GetFormString("finalopinion");//结案意见
                int issatisfie = RequestString.GetInt("issatisfie", 0);//0不满意 1满意
                int isnotice = RequestString.GetInt("isnotice", 0);//0不通告 1通告
                string deptids = RequestString.GetFormString("deptids");//通告单位
                string noticereson = RequestString.GetFormString("noticereson");//通告原因

                //2020-3-4添加通告选项
                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（1,2,3）

                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 (modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_CreateUser != User.F_UserCode)
                    //{
                    //    return Error("操作失败");
                    //}

                    //if (modelT_Bus_WorkOrder.F_WorkState == 7)
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.visit || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.rejload)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            #region 修改工单记录
                            //modelT_Bus_WorkOrder.F_WorkState = 9;
                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            keyValuePairs.Add("F_WorkState", (int)EnumWorkState.finish);
                            modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.finish;
                            keyValuePairs.Add("F_IsSatisfie", issatisfie);
                            //modelT_Bus_WorkOrder.F_IsSatisfie = issatisfie;
                            keyValuePairs.Add("F_IsClosed", 1);
                            // modelT_Bus_WorkOrder.F_IsClosed = 1;
                            keyValuePairs.Add("F_CloseUser", User.F_UserCode);
                            // modelT_Bus_WorkOrder.F_CloseUser = User.F_UserCode;
                            keyValuePairs.Add("F_CloseTime", DateTime.Now);
                            // modelT_Bus_WorkOrder.F_CloseTime = DateTime.Now;
                            keyValuePairs.Add("F_FinalOpinion", finalopinion);
                            // modelT_Bus_WorkOrder.F_FinalOpinion = finalopinion;
                            keyValuePairs.Add("F_IsStandard", isstandard);
                            //modelT_Bus_WorkOrder.F_IsStandard = isstandard;
                            keyValuePairs.Add("F_StandardIDS", standardids);
                            //  modelT_Bus_WorkOrder.F_StandardIDS = standardids;
                            keyValuePairs.Add("F_ToBereply", 0);
                            keyValuePairs.Add("F_IsProResult", 1);
                            //modelT_Bus_WorkOrder.F_ToBereply = 0;
                            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);

                                modelT_Bus_AssignedInfo.F_IsNotice = 1;
                                modelT_Bus_AssignedInfo.F_NoticeUser = User.F_UserCode;
                                modelT_Bus_AssignedInfo.F_NoticeTime = DateTime.Now;

                                keyValuePairs.Add("F_IsNotice", 1);
                                keyValuePairs.Add("F_NoticeDeptIds", deptids);
                               // modelT_Bus_WorkOrder.F_IsNotice = 1;
                               // modelT_Bus_WorkOrder.F_NoticeDeptIds = deptids;
                            }
                            modelT_Bus_AssignedInfo.F_IsStandard = isstandard;
                            modelT_Bus_AssignedInfo.F_StandardIDS = standardids;
                            assignBLL.Update(modelT_Bus_AssignedInfo);
                            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 = modelT_Bus_WorkOrder.F_WorkState;
                            string userinfo = User.depname + "(" + User.F_UserCode + ")";
                            oper.F_Message = userinfo + " 结案了工单，结果：" + (issatisfie == 1 ? "满意" : "不满意");
                            if (isnotice == 1)
                            {
                                string sql = "select dbo.GetDeptNames('" + deptids + "')";
                                oper.F_Message = oper.F_Message + ",并通告了交办单位：" + DbHelperSQL.GetSingle(sql);
                            }
                            if (isstandard == 1)
                            {
                                var sqlstand = "select dbo.GetDictionaryNames('" + standardids + "')";
                                var sts = DbHelperSQL.GetSingle(sqlstand);
                                oper.F_Message = oper.F_Message + "；办理结果出现不规范" + sts + "情况，请及时查看";
                            }
                            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("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }

        /// <summary>
        /// 结案工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult ForceFinishWorkOrder()
        {

            if (User.F_RoleCode == "ZXLD" || 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 == "DBZY")
            //if (User.F_RoleCode == "ZJZY" || User.F_RoleCode == "GLY")
            {
                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通告
                //是否发送短信0否1是
                int issms = RequestString.GetInt("issms", 0);
                string deptids = RequestString.GetFormString("deptids");//通告单位
                string noticereson = RequestString.GetFormString("noticereson");//通告其他原因

                //2020-3-4添加通告选项
                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（1,2,3）

                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 != "ZXLD" &&   User.F_RoleCode != "YSZY" && User.F_RoleCode != "MTDD" && User.F_RoleCode != "DBZY")
                    {
                        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)))
                    {
                        #region 修改工单记录
                        Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                        if (!string.IsNullOrEmpty(result))
                        {
                            keyValuePairs.Add("F_Result", result);
                           modelT_Bus_WorkOrder.F_Result = result;
                        }
                        else 
                        {
                            if (!string.IsNullOrEmpty(finalopinion)&&
                                string.IsNullOrEmpty(modelT_Bus_WorkOrder.F_Result))
                            {
                                keyValuePairs.Add("F_Result", finalopinion);
                                modelT_Bus_WorkOrder.F_Result = finalopinion;
                            }
                                
                        }
                        if (modelT_Bus_WorkOrder.F_DealTime == null)
                            keyValuePairs.Add("F_DealTime", DateTime .Now );
                        //modelT_Bus_WorkOrder.F_WorkState = 9;
                        keyValuePairs.Add("F_WorkState", 9);
                        modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.finish;
                        keyValuePairs.Add("F_IsSatisfie", issatisfie);
                        // modelT_Bus_WorkOrder.F_IsSatisfie = issatisfie;
                        keyValuePairs.Add("F_IsClosed", 1);
                        //  modelT_Bus_WorkOrder.F_IsClosed = 1;
                        keyValuePairs.Add("F_CloseUser", User.F_UserCode);
                        // modelT_Bus_WorkOrder.F_CloseUser = User.F_UserCode;
                        keyValuePairs.Add("F_CloseTime", DateTime.Now);
                        //  modelT_Bus_WorkOrder.F_CloseTime = DateTime.Now;
                        if (!string.IsNullOrEmpty(finalopinion))
                        {
                            keyValuePairs.Add("F_FinalOpinion", finalopinion);
                            modelT_Bus_WorkOrder.F_FinalOpinion = finalopinion;
                        }
                        keyValuePairs.Add("F_IsStandard", isstandard);
                        keyValuePairs.Add("F_IsProResult", 1);
                        //modelT_Bus_WorkOrder.F_IsStandard = isstandard;
                        keyValuePairs.Add("F_StandardIDS", standardids);
                        //  modelT_Bus_WorkOrder.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);
                            // modelT_Bus_WorkOrder.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);
                        }

                        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 = modelT_Bus_WorkOrder.F_WorkState;

                        string userinfo = User.depname + "(" + User.F_UserCode + ")";
                        oper.F_Message = userinfo + " 强制结案了工单，结果：" + (issatisfie == 1 ? "满意" : "不满意");
                        if (isnotice == 1)
                        {
                            string sql = "select dbo.GetDeptNames('" + deptids + "')";
                            oper.F_Message = oper.F_Message + "，并通告了交办单位：" + DbHelperSQL.GetSingle(sql);
                        }
                        if (isstandard == 1)
                        {
                            oper.F_Message = oper.F_Message + "，办理结果出现不规范情况，请及时查看";
                        }
                        if (issms > 0)
                        {
                            if (modelT_Bus_WorkOrder.F_InfoSource == 1 || modelT_Bus_WorkOrder.F_InfoSource == 2501)
                            {
                                if (modelT_Bus_WorkOrder.F_CusPhone.Length >11)
                                    modelT_Bus_WorkOrder.F_CusPhone= modelT_Bus_WorkOrder.F_CusPhone.Substring(1, 11);

                                string content = ""; string temp = "680847330371186688";
                                if (modelT_Bus_WorkOrder.F_InfoSource == 1 || modelT_Bus_WorkOrder.F_InfoSource == 3 || modelT_Bus_WorkOrder.F_InfoSource == 6)
                                    content = "您反映的诉求已有回复，请前往http://12345rx.zwfw.anyang.gov.cn:9999/citizenNode/orderDetails.html?workorderid=" + modelT_Bus_WorkOrder.F_WorkOrderId + ",查看办结结果并进行评价，或者拨打12345市长热线来电咨询，谢谢！";
                                else
                                {
                                    temp = "681914832337539072";
                                    content = "您反映的诉求已有回复，请前往http://12345rx.zwfw.anyang.gov.cn:9999/citizenNode/orderDetails.html?workorderid=" + modelT_Bus_WorkOrder.F_WorkOrderId + ",查看办结结果并进行评价，谢谢！";
                                }
                                string mag = "[\"http://12345rx.zwfw.anyang.gov.cn:9999/citizenNode/orderDetails.html?workorderid=" + modelT_Bus_WorkOrder.F_WorkOrderId + ",\"]";

                                string n = SmsNewController.AddSmS(0, content, modelT_Bus_WorkOrder.F_CusPhone, temp, mag, modelT_Bus_WorkOrder.F_WorkOrderId);
                                if (n != "")
                                    return Error(n);
                                //string count = "您反映的诉求已有回复，请前往安阳政务服务官网（https://zwfw.anyang.gov.cn）登录后查看办结结果并对办理情况进行评价，或者拨打12345市长热线来电咨询，谢谢！";
                                //string mag = "";
                                //bool n = SMSController.AddSmS(0, mag, count, modelT_Bus_WorkOrder.F_CusPhone, "289715", "", modelT_Bus_WorkOrder.F_WorkOrderId);
                            }
                          
                        }
                        oper.F_CreateUser = User.F_UserCode;
                        oper.F_CreateTime = DateTime.Now;
                        oper.F_IsDelete = 0;
                        operBLL.Add(oper);
                        var cureuser = User;
                        Task.Run(() =>
                        {
                            CloseWorkorder(modelT_Bus_WorkOrder, cureuser);
                        }).ContinueWith(p => {
                            System.Diagnostics.Debug.WriteLine(DateTime.Now);
                        });
                        //if (!string.IsNullOrEmpty(modelT_Bus_WorkOrder.F_MainWorkorder1))
                        //{
                        //    var model = workorderBLL.GetModel(modelT_Bus_WorkOrder.F_MainWorkorder1);

                        //    if (model != null)
                        //    {
                        //        Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                        //        if (modelT_Bus_WorkOrder.F_WorkOrderId == modelT_Bus_WorkOrder.F_MainWorkorder1)
                        //        {
                        //            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");
                        //                string Result = "";string FinalOpinion = "";
                        //                if (modellist!=null && modellist.Count >0)
                        //                {
                        //                    foreach (var it in modellist)
                        //                    {
                        //                        if (string.IsNullOrEmpty(Result))
                        //                            Result = modelT_Bus_WorkOrder.F_Result;
                        //                        else
                        //                            Result += ";   " + it .F_Result;
                        //                        if (!string.IsNullOrEmpty(FinalOpinion))
                        //                        {
                        //                            if (string.IsNullOrEmpty(FinalOpinion))
                        //                                FinalOpinion = it.F_FinalOpinion;
                        //                            else
                        //                            {
                        //                                if (!string .IsNullOrEmpty (it.F_FinalOpinion))
                        //                                FinalOpinion += ";   " + it.F_FinalOpinion;
                        //                            }
                                                       
                        //                        }
                        //                    }
                        //                    keyValuePairs1.Add("F_Result", Result);
                        //                    // model.F_Result = Result;
                        //                    keyValuePairs1.Add("F_FinalOpinion", FinalOpinion);
                        //                   // model.F_FinalOpinion = FinalOpinion;
                        //                    workorderBLL.UpdateWorkOrder (model.F_Id , keyValuePairs1);

                        //                    Task.Run(() =>
                        //                    {
                        //                        case_info(model.F_WorkOrderId, "case_finish_info");
                        //                    }).ContinueWith(p => {
                        //                        System.Diagnostics.Debug.WriteLine(DateTime.Now);
                        //                    });
                        //                }

                        //            }
                        //        }
                        //        else
                        //        {
                        //            if (string.IsNullOrEmpty(model.F_Result))
                        //            {
                        //                keyValuePairs1.Add("F_Result", modelT_Bus_WorkOrder.F_Result);
                        //                //  model.F_Result = modelT_Bus_WorkOrder.F_Result;
                        //            }
                        //            else
                        //            {
                        //                keyValuePairs1.Add("F_Result", model.F_Result + ";   " + modelT_Bus_WorkOrder.F_Result);
                        //                // model.F_Result += ";" + modelT_Bus_WorkOrder.F_Result;
                        //            }
                        //            if (!string.IsNullOrEmpty(finalopinion))
                        //            {
                        //                if (string.IsNullOrEmpty(model.F_FinalOpinion))
                        //                {
                        //                    keyValuePairs1.Add("F_FinalOpinion", finalopinion);
                        //                    //  model.F_FinalOpinion = finalopinion;
                        //                }
                        //                else
                        //                {
                        //                    keyValuePairs1.Add("F_FinalOpinion", model.F_FinalOpinion + modelT_Bus_WorkOrder.F_FinalOpinion);
                        //                    //  model.F_FinalOpinion += ";   " + modelT_Bus_WorkOrder.F_FinalOpinion;
                        //                }
                        //            }
                        //           // model.F_DealTime = modelT_Bus_WorkOrder.F_DealTime;
                        //          //  keyValuePairs1.Add("F_DealTime", modelT_Bus_WorkOrder.F_DealTime);
                        //            if (!string.IsNullOrEmpty(model.F_SubWorkorder1))
                        //            {
                        //                int n = Int32.Parse(DbHelperSQL.GetSingle("  select COUNT(1) from t_bus_workorder  where F_WorkOrderId in(select col from dbo.SplitToNvarchar('" + model.F_SubWorkorder1 + "',',' ))  and F_WorkState != 9 and F_IsDelete =0").ToString());
                        //                if (n <= 0)
                        //                {
                        //                    keyValuePairs1.Add("F_IsClosed", 1);
                        //                    // model.F_IsClosed = 1;
                        //                    keyValuePairs1.Add("F_CloseTime", DateTime.Now);
                        //                    // model.F_CloseTime = DateTime.Now;
                        //                    keyValuePairs1.Add("F_WorkState", (int)EnumWorkState.finish);
                        //                    model.F_WorkState = (int)EnumWorkState.finish;//已回访
                        //                    keyValuePairs1.Add("F_DealTime", modelT_Bus_WorkOrder.F_DealTime);
                        //                    //  model.F_DealTime = modelT_Bus_WorkOrder.F_DealTime;
                        //                    keyValuePairs1.Add("F_DealDeptId", modelT_Bus_WorkOrder.F_DealDeptId);
                        //                    //  model.F_DealDeptId = modelT_Bus_WorkOrder.F_DealDeptId;
                        //                    workorderBLL.UpdateWorkOrder (model.F_Id , keyValuePairs1);
                        //                    Task.Run(() =>
                        //                    {
                        //                        case_info(model.F_WorkOrderId, "case_finish_info");
                        //                    }).ContinueWith(p => {
                        //                        System.Diagnostics.Debug.WriteLine(DateTime.Now);
                        //                    });

                        //                }
                        //                else
                        //                    workorderBLL.UpdateWorkOrder (model.F_Id , keyValuePairs1);


                        //            }
                        //            else
                        //            {
                                        
                        //                keyValuePairs1.Add("F_IsClosed", 1);
                        //                // model.F_IsClosed = 1;
                        //                keyValuePairs1.Add("F_CloseTime", DateTime.Now);
                        //                // model.F_CloseTime = DateTime.Now;
                                      
                        //                keyValuePairs1.Add("F_WorkState", 9);
                        //                model.F_WorkState = (int)EnumWorkState.finish;//已回访
                                     
                        //                keyValuePairs1.Add("F_DealTime", modelT_Bus_WorkOrder.F_DealTime);
                        //                // model.F_DealTime = modelT_Bus_WorkOrder.F_DealTime;
                        //                keyValuePairs1.Add("F_DealDeptId", modelT_Bus_WorkOrder.F_DealDeptId);
                                       
                        //                workorderBLL.UpdateWorkOrder (model.F_Id , keyValuePairs1);

                        //            }

                        //        }



                        //    }
                        //}
                        //if (modelT_Bus_WorkOrder.F_IsRelease == 2)
                        //{
                        //    if (!string.IsNullOrEmpty(modelT_Bus_WorkOrder.F_SubWorkorder))
                        //    {
                        //        var orderlist = modelT_Bus_WorkOrder.F_SubWorkorder.Split(',');
                        //        if (orderlist.Length > 0)
                        //        {
                        //            foreach (var it in orderlist)
                        //            {
                        //                var model = workorderBLL.GetModel(it);
                        //                if (model != null)
                        //                {
                                           
                                          
                                         
                        //                    Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                        //                    keyValuePairs1.Add("F_IsClosed", 1);
                        //                    //model.F_IsClosed = 1;
                        //                    keyValuePairs1.Add("F_CloseTime", DateTime.Now);
                        //                    //model.F_CloseTime = DateTime.Now;
                        //                    keyValuePairs1.Add("F_CloseUser", User.F_UserCode);
                        //                    //  model.F_CloseUser = User.F_UserCode;
                        //                    keyValuePairs1.Add("F_WorkState", 9);
                        //                    model.F_WorkState = (int)EnumWorkState.finish;//已回访
                        //                    keyValuePairs1.Add("F_Result", modelT_Bus_WorkOrder.F_Result);
                        //                    // model.F_Result = modelT_Bus_WorkOrder.F_Result;
                        //                    if (!string.IsNullOrEmpty(finalopinion))
                        //                    {
                        //                        model.F_FinalOpinion = finalopinion;
                        //                        keyValuePairs1.Add("F_FinalOpinion", finalopinion);
                        //                    }
                        //                    keyValuePairs1.Add("F_DealUser", modelT_Bus_WorkOrder.F_DealUser);
                        //                    //  model.F_DealUser = modelT_Bus_WorkOrder.F_DealUser;
                        //                    keyValuePairs1.Add("F_DealTime", modelT_Bus_WorkOrder.F_DealTime);
                        //                    //  model.F_DealTime = modelT_Bus_WorkOrder.F_DealTime;
                        //                    keyValuePairs1.Add("F_DealDeptId", modelT_Bus_WorkOrder.F_DealDeptId);
                        //                    //  model.F_DealDeptId = modelT_Bus_WorkOrder.F_DealDeptId;
                        //                    keyValuePairs1.Add("F_MainDeptId", modelT_Bus_WorkOrder.F_MainDeptId);
                        //                    //   model.F_MainDeptId = modelT_Bus_WorkOrder.F_MainDeptId;
                        //                    Task.Run(() =>
                        //                    {
                        //                        case_info(model.F_WorkOrderId, "case_finish_info");
                        //                    }).ContinueWith(p => {
                        //                        System.Diagnostics.Debug.WriteLine(DateTime.Now);
                        //                    });
                        //                    workorderBLL.UpdateWorkOrder(model.F_Id, keyValuePairs1);
                        //                }
                        //            }
                        //        }

                        //    }
                        //}
                        
                        #endregion

                        trans.Complete();
                    }

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

        /// <summary>
        /// 删除工单
        /// </summary>
        /// <returns></returns>
        public ActionResult DelWorkOrder(string[] ids)
        {




            if (User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "ZXBZ" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD"|| User.F_RoleCode == "ZXLD")
            {

                //StringBuilder sb = new StringBuilder();
                foreach (var item in ids)
                {
                    //sb.Append("'" + item + "',");
                    Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(item);
                    if (modelT_Bus_WorkOrder != null && (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.neworder || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.audit))//0)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            #region 修改工单记录
                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            keyValuePairs.Add("F_IsDelete",1);
                            //modelT_Bus_WorkOrder.F_IsDelete = 1;
                            keyValuePairs.Add("F_DeleteUser", User.F_UserCode);
                            //modelT_Bus_WorkOrder.F_DeleteUser = User.F_UserCode;
                            keyValuePairs.Add("F_DeleteTime", DateTime.Now);
                            //modelT_Bus_WorkOrder.F_DeleteTime = DateTime.Now;
                            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 = 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);
                            #endregion

                            trans.Complete();
                        }
                    }
                }

                return Success("删除成功");
            }
            else
            {
                return Error("权限不足");
            }
        }

        /// <summary>
        /// 删除工单
        /// </summary>
        /// <returns></returns>
        public ActionResult Recovery(string[] ids)
        {

            if (User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "ZXBZ" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {

                //StringBuilder sb = new StringBuilder();
                foreach (var item in ids)
                {
                    //sb.Append("'" + item + "',");
                    Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(item);
                    if (modelT_Bus_WorkOrder != null && (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.neworder || modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.audit))//0)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            #region 修改工单记录
                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            keyValuePairs.Add("F_IsDelete", 0);
                            //modelT_Bus_WorkOrder.F_IsDelete = 1;
                            keyValuePairs.Add("F_DeleteUser", User.F_UserCode);
                            //modelT_Bus_WorkOrder.F_DeleteUser = User.F_UserCode;
                            keyValuePairs.Add("F_DeleteTime", DateTime.Now);
                            //modelT_Bus_WorkOrder.F_DeleteTime = DateTime.Now;
                            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 = 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);
                            #endregion

                            trans.Complete();
                        }
                    }
                }

                return Success("删除成功");
            }
            else
            {
                return Error("权限不足");
            }
        }

        /// <summary>
        /// 转公开工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult ReleaseWorkOrder()
        {
            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int isrelease = RequestString.GetInt("isrelease", -1);
                // int isopen = RequestString.GetInt("isopen", 0);
                if (isrelease > -1)
                {
                    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)))
                        {
                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            #region 修改工单记录
                            if (isrelease > 0)
                            {
                                var configly = configBll.GetModelList(" F_ParamCode='Public' ").FirstOrDefault();
                                int day = 5;
                                if (configly!=null )
                                {
                                    try
                                    {
                                        day = int.Parse(configly.F_ParamValue);
                                    }
                                    catch
                                    {
                                        day = 5;
                                    }
                                }
                                if (modelT_Bus_WorkOrder.F_WorkState !=6&& modelT_Bus_WorkOrder.F_WorkState != 9)
                                {
                                    if (modelT_Bus_WorkOrder.F_DealTime!=null&& modelT_Bus_WorkOrder.F_AssignTime  != null)
                                    {
                                        TimeSpan time = (DateTime)modelT_Bus_WorkOrder.F_DealTime - (DateTime)modelT_Bus_WorkOrder.F_AssignTime;
                                        if (time.TotalDays > day)
                                        {
                                            return Error("公开件的回复时间必须在"+ day + "个工作日内");
                                        }
                                   }
                                }
                                keyValuePairs.Add("F_IsOpen", 1);
                                modelT_Bus_WorkOrder.F_IsOpen = 1;
                            }
                            else
                            {
                                keyValuePairs.Add("F_IsOpen", 0);
                                modelT_Bus_WorkOrder.F_IsOpen = 0;
                            }
                            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 = modelT_Bus_WorkOrder.F_WorkState;
                            string userinfo = User.depname + "(" + User.F_UserCode + ")";
                            if (modelT_Bus_WorkOrder.F_IsOpen == 1)
                                oper.F_Message = userinfo + "公开了工单";
                            else
                                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("操作失败");

            }
            else
            {
                return Error("权限不足");
            }
        }
        /// <summary>
        /// 转公开媒体
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult MediaWorkOrder()
        {
            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "ZXHWY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int isrelease = RequestString.GetInt("isrelease", -1);
                // int isopen = RequestString.GetInt("isopen", 0);
                if (isrelease > -1)
                {
                    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)))
                        {
                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            #region 修改工单记录
                            if (isrelease > 0)
                            {
                                keyValuePairs.Add("F_IsMedia",1);
                                modelT_Bus_WorkOrder.F_IsMedia = 1;
                            }
                            else
                            {
                                keyValuePairs.Add("F_IsMedia", 0);
                                modelT_Bus_WorkOrder.F_IsMedia = 0;
                            }
                            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 = modelT_Bus_WorkOrder.F_WorkState;
                            string userinfo = User.depname + "(" + User.F_UserCode + ")";
                            if (modelT_Bus_WorkOrder.F_IsMedia == 1)
                                oper.F_Message = userinfo + "转媒体了工单";
                            else
                                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("操作失败");

            }
            else
            {
                return Error("权限不足");
            }
        }
        /// <summary>
        /// 撤销关联工单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult DisassociateWorkOrder()
        {
            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {
                string workorderid = RequestString.GetFormString("workorderid");
               // string subworkorderid = RequestString.GetFormString("subworkorderid");
               
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                if (modelT_Bus_WorkOrder == null)
                    return Error("工单不存在");
                if (modelT_Bus_WorkOrder.F_IsRelease != 3)
                    return Error( "只能撤销子工单");

                string userinfo = User.depname + "(" + User.F_UserCode + ")";


                  Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                      
                       
                        keyValuePairs.Add("F_MainWorkorder", "");
                        keyValuePairs.Add("F_IsRelease", null );
                        //  modelT_Bus_WorkOrder1.F_IsRelease = 3;
                        bool n = workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs);
                        if (!n)
                            return Error("撤销子工单失败");
                        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 = userinfo + "撤销子工单";
                        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 RelationWorkOrder()
        {
            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                string subworkorderid = RequestString.GetFormString("subworkorderid");
                string userinfo = User.depname + "(" + User.F_UserCode + ")";
                if (string.IsNullOrEmpty(workorderid))
                    return Error("请选择主工单");
                if (string.IsNullOrEmpty(subworkorderid))
                    return Error("请选择子工单");
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                if (modelT_Bus_WorkOrder == null)
                    return Error("主工单不存在");
                if (modelT_Bus_WorkOrder.F_IsRelease == 3)
                    return Error(modelT_Bus_WorkOrder.F_WorkOrderId + "工单已被设置为子工单不能设置为主工单");
                string[] orderlist = subworkorderid.Split(',');
                if (subworkorderid.Contains(workorderid))
                {
                    return Error("主工单不能出现在子工单中");
                }
              
                if (orderlist.Length > 0)
                {
                    foreach (var it in orderlist)
                    {
                        Model.T_Bus_WorkOrder modelT_Bus_WorkOrder1 = workorderBLL.GetModel(it);
                        Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                        if (modelT_Bus_WorkOrder1 == null)
                            return Error("子工单" + it + "不存在");
                        if (modelT_Bus_WorkOrder1.F_IsRelease == 3)
                            return Error("" + it + "已被设置为子工单,不能重复设置");
                        if (modelT_Bus_WorkOrder1.F_IsRelease == 2)
                            return Error("" + it + "已被设置为主工单，不能设置为子工单");
                       // modelT_Bus_WorkOrder1.F_MainWorkorder = modelT_Bus_WorkOrder.F_WorkOrderId;
                        keyValuePairs.Add("F_MainWorkorder", modelT_Bus_WorkOrder.F_WorkOrderId);
                        keyValuePairs.Add("F_IsRelease", 3);
                      //  modelT_Bus_WorkOrder1.F_IsRelease = 3;
                        bool n = workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder1.F_Id , keyValuePairs);
                        if (!n)
                            return Error("设置子工单" + it + "失败");
                        Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                        oper.F_WorkOrderId = modelT_Bus_WorkOrder1.F_WorkOrderId;
                        oper.F_State = modelT_Bus_WorkOrder1.F_WorkState;
                        oper.F_Message = userinfo + "设置该工单为子工单，主工单为:" + modelT_Bus_WorkOrder.F_WorkOrderId;
                        oper.F_CreateUser = User.F_UserCode;
                        oper.F_CreateTime = DateTime.Now;
                        oper.F_IsDelete = 0;
                        operBLL.Add(oper);
                    }
                }
                else
                {
                    return Error("请选择子工单");
                }
                Dictionary<string, object> keyValuePairs1 = new Dictionary<string, object>();
                if (!string .IsNullOrEmpty (modelT_Bus_WorkOrder.F_SubWorkorder))
                keyValuePairs1.Add("F_SubWorkorder", modelT_Bus_WorkOrder.F_SubWorkorder+","+subworkorderid);
                else
                    keyValuePairs1.Add("F_SubWorkorder", subworkorderid);
                keyValuePairs1.Add("F_IsRelease", 2);
               // modelT_Bus_WorkOrder.F_SubWorkorder = subworkorderid;
               // modelT_Bus_WorkOrder.F_IsRelease = 2;
                Model.T_Bus_Operation ope = new Model.T_Bus_Operation();
                ope.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                ope.F_State = modelT_Bus_WorkOrder.F_WorkState;
                ope.F_Message = userinfo + "设置该工单为主工单，子工单为:" + subworkorderid;
                ope.F_CreateUser = User.F_UserCode;
                ope.F_CreateTime = DateTime.Now;
                ope.F_IsDelete = 0;
                operBLL.Add(ope);
                if (workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs1))
                    return Success("操作成功");
                else
                    return Error("操作失败");
            }
            else
            {
                return Error("权限不足");
            }
        }
    

        /// <summary>
        /// 通告和撤销通告
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult NoticeWorkOrder()
        {




            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int isnotice = RequestString.GetInt("isnotice", -1);
                string deptids = RequestString.GetFormString("deptids");//通告单位
                string noticereson = RequestString.GetFormString("noticereson");//通告原因
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                if (modelT_Bus_WorkOrder != null)
                {
                    if (isnotice == 0 && modelT_Bus_WorkOrder.F_IsNotice == 1)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            #region 修改工单记录
                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            keyValuePairs.Add("F_IsNotice",0);
                            //  modelT_Bus_WorkOrder.F_IsNotice = 0;
                            keyValuePairs.Add("F_NoticeDeptIds", "");
                            modelT_Bus_WorkOrder.F_NoticeDeptIds = "";
                            workorderBLL.UpdateWorkOrder (modelT_Bus_WorkOrder.F_Id , keyValuePairs);
                            #endregion

                            #region 修改通告记录
                            Model.T_Bus_NoticeCriticism modelT_Bus_NoticeCriticism = new BLL.T_Bus_NoticeCriticism().GetModelList(" F_WorkOrderId='" + workorderid + "' and F_IsDelete=0 ").FirstOrDefault();
                            modelT_Bus_NoticeCriticism.F_IsDelete = 1;
                            modelT_Bus_NoticeCriticism.F_DeleteTime = DateTime.Now;
                            modelT_Bus_NoticeCriticism.F_DeleteUser = User.F_UserCode;
                            new BLL.T_Bus_NoticeCriticism().Update(modelT_Bus_NoticeCriticism);
                            #endregion

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

                            string sql = "select dbo.GetDeptNames('" + modelT_Bus_NoticeCriticism.F_DeptIds + "')";
                            string userinfo = User.depname + "(" + User.F_UserCode + ")";
                            oper.F_Message = userinfo + " 撤销了通告交办单位：" + DbHelperSQL.GetSingle(sql).ToString();
                            oper.F_CreateUser = User.F_UserCode;
                            oper.F_CreateTime = DateTime.Now;
                            oper.F_IsDelete = 0;

                            operBLL.Add(oper);
                            #endregion

                            trans.Complete();
                        }

                        return Success("操作成功");
                    }
                    else if (isnotice == 1 && modelT_Bus_WorkOrder.F_IsNotice == 0)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            #region 修改工单记录
                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            keyValuePairs.Add("F_IsNotice", 1);
                            //  modelT_Bus_WorkOrder.F_IsNotice = 1;
                            keyValuePairs.Add("F_NoticeDeptIds", deptids);
                            modelT_Bus_WorkOrder.F_NoticeDeptIds = deptids;
                            workorderBLL.UpdateWorkOrder(modelT_Bus_WorkOrder.F_Id, keyValuePairs);
                            #endregion
                           
                            #region 新增通告记录
                            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;
                            new BLL.T_Bus_NoticeCriticism().Add(modelT_Bus_NoticeCriticism);
                            #endregion

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

                            string sql = "select dbo.GetDeptNames('" + deptids + "')";
                            string userinfo = User.depname + "(" + User.F_UserCode + ")";
                            oper.F_Message = userinfo + " 通告了交办单位：" + DbHelperSQL.GetSingle(sql).ToString();
                            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("操作失败");
                }
            }
            else
            {
                return Error("权限不足");
            }
        }

        /// <summary>
        /// 市民催单
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult AdditionalWorkOrder()
        {
            string workorderid = RequestString.GetFormString("workorderid");
            string title = RequestString.GetFormString("title");
            string content = RequestString.GetFormString("content");
            string files = RequestString.GetFormString("files");
            string callid = RequestString.GetFormString("callid");
            Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = new BLL.T_Bus_WorkOrder().GetModel(workorderid);
            if (modelT_Bus_WorkOrder != null)
            {
                using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                {

                    #region 插入附加记录
                    //批示记录
                    Model.T_Bus_Additional model_T_Bus_Additional = new Model.T_Bus_Additional();
                    model_T_Bus_Additional.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;//工单流水号
                    model_T_Bus_Additional.F_Title = title;
                    model_T_Bus_Additional.F_Content = content;
                    if (!string.IsNullOrEmpty(callid))
                    {
                        model_T_Bus_Additional.F_CallId = callid;
                        var rd = new BLL.T_Call_CallRecords().GetModelByCallId(callid);
                        if (rd != null)
                        {
                            model_T_Bus_Additional.F_CallRecordId = rd.CallRecordsId;
                        }
                    }

                    model_T_Bus_Additional.F_File = files;//附件
                    model_T_Bus_Additional.F_CreateUser = User.F_UserCode;//呈批人
                    model_T_Bus_Additional.F_CreateTime = DateTime.Now;//呈批时间
                    model_T_Bus_Additional.F_IsDelete = 0;
                    model_T_Bus_Additional.F_State = 1;//审批状态（0:未处理，1:通过）
                    new BLL.T_Bus_Additional().Add(model_T_Bus_Additional);
                    #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 + " 接到市民催单，内容：" + content;
                    oper.F_CreateUser = User.F_UserCode;
                    oper.F_CreateTime = DateTime.Now;
                    oper.F_IsDelete = 0;

                    operBLL.Add(oper);
                    #endregion
                    #region 根据状态不同给出提醒
                    var sqlusers = " F_DeleteFlag=0 ";
                    #region 获取被提醒人
                    Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.neworder)
                        sqlusers += " and F_UserCode='" + modelT_Bus_WorkOrder.F_CreateUser + "'";//"新工单"向添加人提醒
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.submit)
                        sqlusers += " and F_RoleId in (select F_RoleId from T_Sys_RoleInfo WITH(NOLOCK) where F_RoleCode='ZXLD')";//"待交办"向所有调度提醒
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.receive)
                    {
                        if (modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_MainDeptId != null)
                            sqlusers += " and F_DeptId='" + modelT_Bus_AssignedInfo.F_MainDeptId + "' ";//"待查收"向被指派单位的所有人提醒
                    }
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.auditreback)
                    {
                        if (modelT_Bus_AssignedInfo != null)
                            sqlusers += " and F_UserCode='" + modelT_Bus_AssignedInfo.F_CreateUser + "' ";//"退回审核中"向指派人提醒
                    }
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.dealing)
                    {
                        if (modelT_Bus_AssignedInfo != null && !string.IsNullOrEmpty(modelT_Bus_AssignedInfo.F_SureUser))
                            sqlusers += " and F_UserCode='" + modelT_Bus_AssignedInfo.F_SureUser + "' ";//"办理中"向查收人提醒
                    }
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.auditdelay)
                    {
                        if (modelT_Bus_AssignedInfo != null)
                            sqlusers += " and F_UserCode='" + modelT_Bus_AssignedInfo.F_CreateUser + "' ";//"延时审核中"
                    }
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.dealed)
                    {
                        sqlusers += " and F_RoleId in (select F_RoleId from T_Sys_RoleInfo WITH(NOLOCK) where F_RoleCode='ZJZY')";//"已办理"向所有质检提醒
                    }
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.visit)
                    {
                        sqlusers += " and F_RoleId in (select F_RoleId from T_Sys_RoleInfo WITH(NOLOCK) where F_RoleCode='ZJZY')";//"已回访"向所有质检提醒
                    }
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.reload)
                    {
                        if (modelT_Bus_AssignedInfo != null)
                            sqlusers += " and F_UserCode='" + modelT_Bus_AssignedInfo.F_CreateUser + "' ";//"重办中"向指派人提醒
                    }
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.audit)
                    {
                        sqlusers += " and F_RoleId in (select F_RoleId from T_Sys_RoleInfo WITH(NOLOCK) where F_RoleCode='ZXBZ')";//"待审核"向坐席班长提醒
                    }
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.resubmit)
                    {
                        if (modelT_Bus_AssignedInfo != null)
                            sqlusers += " and F_UserCode='" + modelT_Bus_AssignedInfo.F_CreateUser + "' ";//"重办待交办"向指派人提醒
                    }
                    if (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.rejload)
                    {
                        sqlusers += " and F_RoleId in (select F_RoleId from T_Sys_RoleInfo WITH(NOLOCK) where F_RoleCode='ZJZY')";//"重办驳回"向所有质检提醒
                    }
                    #endregion
                    var userlists = userBLL.GetModelListNoCache(sqlusers);
                    //推送消息表
                    foreach (var u in userlists)
                    {
                        msg.AddInternalMessagesInfo("催单消息", oper.F_Message + "，工单编号：" + oper.F_WorkOrderId, u.F_UserCode, User.F_UserCode, (int)EnumSmsType.additional);
                    }
                    #endregion
                    trans.Complete();
                }
                return Success("操作成功");
            }
            else
            {
                return Error("操作失败");
            }
        }
        #endregion

        #region 语音附件其他
        /// <summary>
        /// 验证当前单位是否交办单位
        /// </summary>
        /// <param name="modelT_Bus_AssignedInfo"></param>
        /// <param name="deptid"></param>
        /// <returns></returns>
        public int AssignDeptType(Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo, int deptid)
        {
            int type = 0;
            if (modelT_Bus_AssignedInfo.F_MainDeptId == deptid)
            {
                type = 1;//主办
            }
            else if (!string.IsNullOrEmpty(modelT_Bus_AssignedInfo.F_OtherDeptIds) && modelT_Bus_AssignedInfo.F_OtherDeptIds.Split(',').Contains(deptid.ToString()))
            {
                type = 2;//协办
            }
            return type;
        }

        /// <summary>
        /// 获取留言路径
        /// </summary>
        /// <param name="lid">留言id</param>
        /// <param name="prefix">前缀</param>
        /// <returns></returns>
        public string GetLeavePath(string lid, string prefix)
        {
            string path = string.Empty;
            try
            {
                var liuyan = new BLL.T_Call_LeaveRecord().GetModel(int.Parse(lid));
                if (liuyan != null)
                {
                    if (!string.IsNullOrEmpty(liuyan.F_RecFileUrl))
                    {
                        path = prefix + liuyan.F_RecFileUrl;
                    }
                }
            }
            catch
            {

            }

            return path;
        }

        /// <summary>
        /// 获取通话录音路径
        /// </summary>
        /// <param name="cid">通话id</param>
        /// <param name="prefix">前缀</param>
        /// <returns></returns>
        public string GetCallPath(string cid, string prefix)
        {
            string path = string.Empty;
            try
            {
                var luyin = new BLL.T_Call_CallRecords().GetModel(int.Parse(cid));
                if (luyin != null)
                {
                    if (!string.IsNullOrEmpty(luyin.FilePath))
                    {
                        var ym = prefix;
                        ym = ym.Substring(0, ym.Length - 1);
                        string lujing = luyin.FilePath.Substring(luyin.FilePath.IndexOf(':') + 1).Replace('\\', '/');
                        path = ym + lujing;
                    }
                }
            }
            catch
            {

            }

            return path;
        }

        public ActionResult Uploads(string ids)
        {
            var configfj = configBll.GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
            string prefix = configfj.F_ParamValue;
            DataTable dt = DbHelperSQL.Query("select * from T_Sys_Accessories WITH(NOLOCK) where F_FileId in (" + ids + ")").Tables[0];

            foreach (DataRow dr in dt.Rows)
            {
                if (dr["F_UserCode"].ToString() == "jianhang")
                {
                    if (System.IO.File.Exists(Directory.GetCurrentDirectory() + dr["F_FileUrl"].ToString()))
                    {
                        dr["F_FileUrl"] = prefix + dr["F_FileUrl"].ToString();
                    }
                    else
                    {
                        string url = Upload("http://172.16.0.10/" + dr["F_FileUrl"].ToString(), dr["F_FileName"].ToString(), "/" + dr["F_FileUrl"].ToString().Replace(dr["F_FileName"].ToString(), ""));
                        if (url == "1")
                            dr["F_FileUrl"] = prefix + dr["F_FileUrl"].ToString();
                        else
                            dr["F_FileUrl"] = url;
                    }
                }
                else
                {
                    dr["F_FileUrl"] = prefix + dr["F_FileUrl"].ToString();
                }
            }

            return Success("成功");
        }
        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 = "F:/WEB/anyang12345Api" + 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;
            }
        }
        /// <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)
            {
                if (dr["F_UserCode"].ToString() == "jianhang"|| dr["F_UserCode"].ToString() == "shengpingtai")
                {
                    if (System.IO.File.Exists(Directory.GetCurrentDirectory() + dr["F_FileUrl"].ToString()))
                    {
                        dr["F_FileUrl"] = prefix + dr["F_FileUrl"].ToString();
                    }
                    else
                    {
                        string url = Upload("http://172.16.0.10/" + dr["F_FileUrl"].ToString(), dr["F_FileName"].ToString(), "/" + dr["F_FileUrl"].ToString().Replace(dr["F_FileName"].ToString(), ""));
                        if (url == "1")
                            dr["F_FileUrl"] = prefix + dr["F_FileUrl"].ToString();
                        else
                            dr["F_FileUrl"] = url;
                    }
                }
                else
                {
                    dr["F_FileUrl"] = prefix + dr["F_FileUrl"].ToString();
                }


            }

            return dt;
        }

        /// <summary>
        /// 添加人民网回复
        /// </summary>
        /// <returns></returns>
        public ActionResult Reply(string workorderid, string content, string organization)
        {

            var mdoel = new BLL.T_Bus_WorkOrder().GetModelList("F_WorkOrderId='" + workorderid + "' and F_IsDelete=0");
            if (mdoel != null && mdoel.Count > 0)
            {
                var modelPeople = new BLL.T_Bus_People().GetModelList("F_WorkOrderId='" + mdoel.First().F_WorkOrderId + "' ");
                var prople = new Model.T_Bus_People();
                if (modelPeople != null && modelPeople.Count > 0)
                {
                    prople = modelPeople.FirstOrDefault();
                }
                else
                {
                    return Error("此工单非从网站抓取工单");
                }
                if (content.Length < 20)
                {
                    return Error("回复内容应在20字以上");
                }
                string token = Login();
                Dictionary<string, object> LY = new Dictionary<string, object>();
                LY.Add("tid", prople.tid);
                LY.Add("asContent", content);
                LY.Add("organization", organization);
                Dictionary<string, object> ParamMap = new Dictionary<string, object>();
                ParamMap.Add("answer", LY);
                if (prople.state == 1)
                {
                    //序列化参数
                    // 发送请求
                    var request = (HttpWebRequest)WebRequest.Create(rmwurl+"/v1/org/addExplainOne");
                    request.Method = "POST";
                    request.ContentType = "application/json;charset=UTF-8";
                    var byteData = Encoding.UTF8.GetBytes(createParamMap("/v1/org/addExplainOne", ParamMap.ToJson(), token).ToJson());
                    var length = byteData.Length;
                    request.ContentLength = length;
                    var writer = request.GetRequestStream();
                    writer.Write(byteData, 0, length);
                    writer.Close();
                    //接收数据
                    var response = (HttpWebResponse)request.GetResponse();
                    var responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();

                    try
                    {
                        JObject paras = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(responseString);
                        var txnBodyCom = paras["result"].ToString();
                        var result = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(txnBodyCom);
                        if (result["code"].ToString() == "0")
                        {
                            prople.state = 3;
                            bool n = new BLL.T_Bus_People().Update(prople);
                            #region 插入操作记录
                            Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                            oper.F_WorkOrderId = mdoel.First().F_WorkOrderId;
                            // oper.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                            oper.F_State = mdoel.First().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);
                            #endregion
                            return Success("回复成功");
                        }
                        else
                        {
                            return Error(result["msgDesc"].ToString());
                        }

                    }
                    catch
                    {
                        return Error("回复失败");
                    }

                }
                else if (prople.state == 2)
                {

                    //序列化参数
                    // 发送请求
                    var request = (HttpWebRequest)WebRequest.Create(rmwurl+"/v1/org/addExplainTwo");
                    request.Method = "POST";
                    request.ContentType = "application/json;charset=UTF-8";
                    var byteData = Encoding.UTF8.GetBytes(createParamMap("/v1/org/addExplainTwo", ParamMap.ToJson(), token).ToJson());
                    var length = byteData.Length;
                    request.ContentLength = length;
                    var writer = request.GetRequestStream();
                    writer.Write(byteData, 0, length);
                    writer.Close();
                    //接收数据
                    var response = (HttpWebResponse)request.GetResponse();
                    var responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();


                    try
                    {
                        JObject paras = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(responseString);
                        var txnBodyCom = paras["result"].ToString();
                        var result = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(txnBodyCom);
                        if (result["code"].ToString() == "0")
                        {
                            prople.state = 3;
                            bool n = new BLL.T_Bus_People().Update(prople);
                            #region 插入操作记录
                            Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                            oper.F_WorkOrderId = mdoel.First().F_WorkOrderId;
                            // oper.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                            oper.F_State = mdoel.First().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);
                            #endregion
                            return Success("回复成功");
                        }
                        else
                        {
                            return Error(result["msgDesc"].ToString());
                        }

                    }
                    catch
                    {
                        return Error("回复失败");
                    }
                }
                else
                {  //序列化参数
                    // 发送请求
                    var request = (HttpWebRequest)WebRequest.Create(rmwurl+"/v1/org/addAnswerOne");
                    request.Method = "POST";
                    request.ContentType = "application/json;charset=UTF-8";
                    var byteData = Encoding.UTF8.GetBytes(createParamMap("/v1/org/addAnswerOne", ParamMap.ToJson(), token).ToJson());
                    var length = byteData.Length;
                    request.ContentLength = length;
                    var writer = request.GetRequestStream();
                    writer.Write(byteData, 0, length);
                    writer.Close();
                    //接收数据
                    var response = (HttpWebResponse)request.GetResponse();
                    var responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
                    try
                    {
                        JObject paras = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(responseString);
                        var txnBodyCom = paras["result"].ToString();
                        var result = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(txnBodyCom);
                        if (result["code"].ToString() == "0")
                        {
                            prople.state = 3;
                            bool n = new BLL.T_Bus_People().Update(prople);
                            #region 插入操作记录
                            Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                            oper.F_WorkOrderId = mdoel.First().F_WorkOrderId;
                            // oper.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                            oper.F_State = mdoel.First().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);
                            #endregion
                            return Success("回复成功");
                        }
                        else
                        {
                            return Error(result["msgDesc"].ToString());
                        }

                    }
                    catch
                    {
                        return Error("回复失败");
                    }

                }
               

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


        }
        public string Login()
        {
            Dictionary<string, string> login = new Dictionary<string, string>();
            login.Add("loginName", "ayszxx");
            login.Add("password", "5116008");
            //序列化参数

            // 发送请求
            //序列化参数

            // 发送请求
            var request = (HttpWebRequest)WebRequest.Create(rmwurl+"/v1/user/login");
            request.Method = "POST";
            request.ContentType = "application/json;charset=UTF-8";

            var byteData = Encoding.UTF8.GetBytes(createParamMap("/v1/user/login", login.ToJson()).ToJson());
            var length = byteData.Length;
            request.ContentLength = length;
            var writer = request.GetRequestStream();
            writer.Write(byteData, 0, length);
            writer.Close();
            //接收数据
            var response = (HttpWebResponse)request.GetResponse();
            var responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
            JObject paras = null;
            paras = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(responseString);
            var txnBodyCom = paras["resultData"].ToString();
            var result = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(txnBodyCom);
            //  token = jo["token"].ToString();
            // string result = SmsNewHelper.Send(mobiles, Content);

            return result["token"].ToString();
        }
        private string APP_CODE =Configs .GetValue ("APP_CODE");
        private string APP_SECRET = Configs.GetValue("APP_SECRET");
        private string rmwurl = Configs.GetValue("Rmwurl");
        // private string APP_CODE = "d377d97d7e9346e7831351ee5b62a418";
        //  private string APP_SECRET = "ff24bb32f2e14ea595dcd1748feceabd";
        //  private string rmwurl = "http://api-qa-dfbbs.peopletech.cn/pro-dfbbs-api";
        //private string APP_CODE = "314f185e71e74dd8879ab154746f7681";
        //private string APP_SECRET = "900a640b37e84a8c88ffc83d6f3500f6";
        //private string rmwurl = "http://liuyan-api.people.com.cn/api";
        public Dictionary<string, string> createParamMap(string url, string param)
        {
            Dictionary<string, string> parame = new Dictionary<string, string>();
            parame.Add("appCode", APP_CODE);
            parame.Add("param", param);
            parame.Add("signature", Md5(url + param + APP_SECRET));
            return parame;
        }

        public Dictionary<string, string> createParamMap(string url, string param, string token)
        {
            Dictionary<string, string> parame = new Dictionary<string, string>();
            parame.Add("token", token);
            parame.Add("appCode", APP_CODE);
            parame.Add("param", param);
            parame.Add("signature", Md5(url + param + APP_SECRET + token));
            return parame;
        }
        /// <summary>
        /// MD5加密
        /// </summary>
        /// <param name="txt"></param>
        /// <returns></returns>
        public static string Md5(string txt)
        {
            byte[] sor = Encoding.UTF8.GetBytes(txt);
            MD5 md5 = MD5.Create();
            byte[] result = md5.ComputeHash(sor);
            StringBuilder strbul = new StringBuilder(40);
            for (int i = 0; i < result.Length; i++)
            {
                //加密结果"x2"结果为32位,"x3"结果为48位,"x4"结果为64位
                strbul.Append(result[i].ToString("x2"));
            }
            return strbul.ToString().ToLower(); ;
        }

        /// <summary>
        /// 绑定追问回复附件信息
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="prefix"></param>
        /// <returns></returns>
        public DataTable BindFileDatas(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);
                }
            }
            dt.Columns.Add("Files", typeof(object));
            foreach (DataRow dr in dt.Rows)
            {
                if (dr["F_Files"] != null && dr["F_Files"].ToString() != "")
                {
                    dr["Files"] = GetFileData(dr["F_Files"].ToString(), prefix);
                }
            }
            return dt;
        }
        /// <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;
        }
        #endregion

        #region 修改工单 by admin

        /// <summary>
        /// 获取详情
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetInfoByAdmin(int id, int type)
        {




            if (User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                //string sql = "select * from ";
                string table = string.Empty;
                switch (type)
                {
                    case 1: table = "T_Bus_AssignedInfo"; break;//交办信息
                    case 2: table = "T_Bus_DelayTime"; break;//延时信息
                    case 3: table = "T_Bus_Feedback"; break;//办理信息
                    case 4: table = "T_Bus_RemindRecord"; break;//督办
                    case 5: table = "T_Bus_SubmitSuper"; break;//1领导批示 2市长指示 3回退
                    case 6: table = "T_Bus_VisitResult"; break;//回访
                }

                string sql = "select * from " + table + "  WITH(NOLOCK) where F_IsDelete=0 and F_Id=" + id;
                var dt = DbHelperSQL.Query(sql).Tables[0];
                return Success("操作成功", dt);
            }
            else
            {
                return Error("权限不足");
            }
        }

        /// <summary>
        /// 修改工单信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult EditWorkOrderByAdmin()
        {




            if (User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string workorderid = RequestString.GetFormString("workorderid");

                int source = RequestString.GetInt("source", 0);

                string cusname = RequestString.GetFormString("cusname");
                string cussex = RequestString.GetFormString("cussex");
                string cusphone = RequestString.GetFormString("cusphone");
                string cusaddress = RequestString.GetFormString("cusaddress");
                string email = RequestString.GetFormString("email");
                string zipcode = RequestString.GetFormString("zipcode");
                string conname = RequestString.GetFormString("conname");
                string conphone = RequestString.GetFormString("conphone");

                string title = RequestString.GetFormString("title");
                string content = RequestString.GetFormString("content");
                string files = RequestString.GetFormString("files");
                int sourcearea = RequestString.GetInt("sourcearea", 0);
                string sourceaddress = RequestString.GetFormString("sourceaddress");

                string keys = RequestString.GetFormString("keys");
                string splituser = RequestString.GetFormString("splituser");

                int type = RequestString.GetInt("type", 0);
                int bigtype = RequestString.GetInt("bigtype", 0);
                int smalltype = RequestString.GetInt("smalltype", 0);

                int isprotect = RequestString.GetInt("isprotect", 0);
                int level = RequestString.GetInt("level", 0);

                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 保存工单信息

                        Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                        keyValuePairs.Add("F_InfoSource", source);
                        //modelT_Bus_WorkOrder.F_InfoSource = source;//信息来源
                      
                        keyValuePairs.Add("F_InfoType", type);
                        //modelT_Bus_WorkOrder.F_InfoType = type;//信息类别
                        keyValuePairs.Add("F_InfoConBigType", bigtype);
                        //modelT_Bus_WorkOrder.F_InfoConBigType = bigtype;//内容大类
                        keyValuePairs.Add("F_InfoConSmallType", smalltype);
                        //modelT_Bus_WorkOrder.F_InfoConSmallType = smalltype;//内容小类
                        keyValuePairs.Add("F_SourceArea", sourcearea);
                        //modelT_Bus_WorkOrder.F_SourceArea = sourcearea;//反映地域
                        keyValuePairs.Add("F_SourceAddress", sourceaddress);
                        //modelT_Bus_WorkOrder.F_SourceAddress = sourceaddress;//事发地址
                        keyValuePairs.Add("F_CusName", cusname);
                        // modelT_Bus_WorkOrder.F_CusName = cusname;//投诉人姓名
                        keyValuePairs.Add("F_CusSex", cussex);
                        //modelT_Bus_WorkOrder.F_CusSex = cussex;//性别
                        keyValuePairs.Add("F_CusPhone", cusphone);
                        // modelT_Bus_WorkOrder.F_CusPhone = cusphone;//来电号码
                        keyValuePairs.Add("F_CusAddress", cusaddress);
                        //  modelT_Bus_WorkOrder.F_CusAddress = cusaddress;//地址
                        keyValuePairs.Add("F_ZipCode", zipcode);
                        // modelT_Bus_WorkOrder.F_ZipCode = zipcode;//邮编
                        keyValuePairs.Add("F_ConName", conname);
                        //modelT_Bus_WorkOrder.F_ConName = conname;//联系人姓名
                        keyValuePairs.Add("F_ConPhone", conphone);
                        // modelT_Bus_WorkOrder.F_ConPhone = conphone;//联系人电话
                        keyValuePairs.Add("F_Email", email);
                        modelT_Bus_WorkOrder.F_Email = email;//E-mail
                        keyValuePairs.Add("F_ComTitle", title);
                        //  modelT_Bus_WorkOrder.F_ComTitle = title;//标题
                        keyValuePairs.Add("F_ComContent", content);
                        // modelT_Bus_WorkOrder.F_ComContent = content;//情况摘要（投诉内容）
                        keyValuePairs.Add("F_File", files);
                        // modelT_Bus_WorkOrder.F_File = files;//附件
                        keyValuePairs.Add("F_File", isprotect);
                        // modelT_Bus_WorkOrder.F_IsProtect = isprotect;//保密方式0否1是
                       
                        //  modelT_Bus_WorkOrder.F_Content = workcontent;
                        keyValuePairs.Add("F_Key", keys);
                        // modelT_Bus_WorkOrder.F_Key = keys;
                        keyValuePairs.Add("F_Level", level);
                        // modelT_Bus_WorkOrder.F_Level = level;
                        keyValuePairs.Add("F_ToBereply", 0);
                        // modelT_Bus_WorkOrder.F_ToBereply = 0;
                        //是否直办（即时答复）0:，否1： 是  
                      
                        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 = modelT_Bus_WorkOrder.F_WorkState;
                        oper.F_CallRecordId = modelT_Bus_WorkOrder.F_CallRecordId;
                        oper.F_File = modelT_Bus_WorkOrder.F_File;

                        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 Success("权限不足");
            }
        }

        /// <summary>
        /// 修改批示信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult EditSuperInfoByAdmin()
        {




            if (User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                //int type = RequestString.GetInt("type", 0);//1领导批示 2市长指示
                string superuser = RequestString.GetFormString("superuser");
                string superopinion = RequestString.GetFormString("superopinion");
                string files = RequestString.GetFormString("files");
                int id = RequestString.GetInt("id", 0);

                Model.T_Bus_SubmitSuper model_T_Bus_SubmitSuper = new BLL.T_Bus_SubmitSuper().GetModel(id);
                if (model_T_Bus_SubmitSuper != null)
                {
                    using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                    {
                        #region 保存批示信息

                        //model_T_Bus_SubmitSuper.F_Type = type;//1领导批示 2市长指示
                        model_T_Bus_SubmitSuper.F_BatchReason = superuser;//批示人
                        model_T_Bus_SubmitSuper.F_SuperOpinion = superopinion;//批示内容
                        if (!string.IsNullOrEmpty(files))
                            model_T_Bus_SubmitSuper.F_File = files;//附件

                        new BLL.T_Bus_SubmitSuper().Update(model_T_Bus_SubmitSuper);
                        #endregion

                        #region 插入操作记录
                        Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                        oper.F_WorkOrderId = model_T_Bus_SubmitSuper.F_WorkOrderId;
                        oper.F_File = model_T_Bus_SubmitSuper.F_File;

                        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("权限不足");
            }
        }

        /// <summary>
        /// 修改交办信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult EditAssignInfoByAdmin()
        {




            if (User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                int assignid = RequestString.GetInt("id", 0);
                //int maindeptid = RequestString.GetInt("maindeptid", 0);
                //string otherdeptids = RequestString.GetFormString("otherdeptids");
                DateTime limittime = DateTime.Parse(RequestString.GetFormString("limittime"));
                string assignedopinion = RequestString.GetFormString("assignedopinion");

                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetModel(assignid);
                if (modelT_Bus_AssignedInfo != null)
                {
                    using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                    {
                        #region 保存交办信息

                        modelT_Bus_AssignedInfo.F_LimitTime = limittime;//办理时限
                        //modelT_Bus_AssignedInfo.F_MainDeptId = maindeptid;//主办单位id
                        //modelT_Bus_AssignedInfo.F_OtherDeptIds = otherdeptids;//协办单位id
                        modelT_Bus_AssignedInfo.F_AssignedOpinion = assignedopinion;//交办意见

                        assignBLL.Update(modelT_Bus_AssignedInfo);
                        #endregion

                        #region 插入操作记录
                        Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                        oper.F_WorkOrderId = modelT_Bus_AssignedInfo.F_WorkOrderId;
                        oper.F_File = modelT_Bus_AssignedInfo.F_File;

                        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("权限不足");
            }
        }

        /// <summary>
        /// 修改办理信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult EditFeedBackInfoByAdmin()
        {




            if (User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string dealman = RequestString.GetFormString("dealman");
                string result = RequestString.GetFormString("result");
                string files = RequestString.GetFormString("files");
                int feedbackid = RequestString.GetInt("id", 0);

                Model.T_Bus_Feedback model_T_Bus_Feedback = new BLL.T_Bus_Feedback().GetModel(feedbackid);
                if (model_T_Bus_Feedback != null)
                {
                    using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                    {
                        #region 保存办理信息

                        model_T_Bus_Feedback.F_DealUser = dealman;
                        model_T_Bus_Feedback.F_Result = result;//反馈内容
                        model_T_Bus_Feedback.F_File = files;

                        new BLL.T_Bus_Feedback().Update(model_T_Bus_Feedback);
                        #endregion

                        #region 保存工单信息
                        int maxid = Int32.Parse(DbHelperSQL.GetSingle("select max(F_Id) from T_Bus_AssignedInfo WITH(NOLOCK) where F_WorkOrderId='" + model_T_Bus_Feedback.F_WorkOrderId + "' and  F_State=1 and F_IsSure=1 and F_IsDelete=0 ").ToString());
                        var assign = assignBLL.GetModel(model_T_Bus_Feedback.F_AssignedId.Value);
                        if (maxid == assign.F_Id)
                        {
                            var order = workorderBLL.GetModel(model_T_Bus_Feedback.F_WorkOrderId);
                            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
                            keyValuePairs.Add("F_Result", result);

                            workorderBLL.UpdateWorkOrder (order.F_Id , keyValuePairs);
                        }
                        #endregion

                        #region 插入操作记录
                        Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                        oper.F_WorkOrderId = model_T_Bus_Feedback.F_WorkOrderId;
                        oper.F_File = model_T_Bus_Feedback.F_File;

                        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("权限不足");
            }
        }

        /// <summary>
        /// 修改回访信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult EditVisitInfoByAdmin()
        {
            if (User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string visituser = RequestString.GetFormString("visituser");//回访人
                int type = RequestString.GetInt("type", 0);//回访方式
                int issatisfie = RequestString.GetInt("issatisfie", 0);//0不满意 1满意
                int visitid = RequestString.GetInt("id", 0);
                string result = RequestString.GetFormString("result");//回访情况
                string guid = RequestString.GetFormString("guid");

                Model.T_Bus_VisitResult modelT_Bus_VisitResult = new BLL.T_Bus_VisitResult().GetModel(visitid);
                if (modelT_Bus_VisitResult != null)
                {
                    using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                    {
                        #region 保存回访信息

                        modelT_Bus_VisitResult.F_VisitUser = visituser;
                        modelT_Bus_VisitResult.F_Type = type;
                        modelT_Bus_VisitResult.F_IsSatisfie = issatisfie;
                        modelT_Bus_VisitResult.F_Result = result;

                        new BLL.T_Bus_VisitResult().Update(modelT_Bus_VisitResult);
                        //保存回访记录
                        new BLL.T_Bus_VisitResultRecords().AddInfo(modelT_Bus_VisitResult, User.F_UserCode, guid);
                        #endregion

                        #region 插入操作记录
                        Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
                        oper.F_WorkOrderId = modelT_Bus_VisitResult.F_WorkOrderId;
                        oper.F_File = modelT_Bus_VisitResult.F_File;

                        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("权限不足");
            }
        }

        /// <summary>
        /// 修改退回审核信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult EditAuditRebackByAdmin()
        {




            if (User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string reason = RequestString.GetFormString("reason");
                int rebackid = RequestString.GetInt("id", 0);

                Model.T_Bus_Feedback modelT_Bus_Feedback = new BLL.T_Bus_Feedback().GetModel(rebackid);
                if (modelT_Bus_Feedback != null)
                {
                    using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                    {
                        #region 保存反馈信息
                        modelT_Bus_Feedback.F_AuditReason = reason;//交办意见

                        new BLL.T_Bus_Feedback().Update(modelT_Bus_Feedback);
                        #endregion

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

                        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("权限不足");
            }
        }

        /// <summary>
        /// 修改延时审核信息
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult EditAuditDelayByAdmin()
        {




            if (User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG")
            {
                string reason = RequestString.GetFormString("reason");
                //DateTime newlimittime = DateTime.Parse(RequestString.GetFormString("newlimittime"));

                int delayid = RequestString.GetInt("id", 0);

                Model.T_Bus_DelayTime modelT_Bus_DelayTime = new BLL.T_Bus_DelayTime().GetModel(delayid);

                if (modelT_Bus_DelayTime != null)
                {
                   // Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetModel(modelT_Bus_DelayTime.F_AssignedId.Value);

                    using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                    {
                        #region 保存延时审核信息
                        modelT_Bus_DelayTime.F_RefuseReason = reason;
                        //modelT_Bus_DelayTime.F_AgreeTime = newlimittime;
                        new BLL.T_Bus_DelayTime().Update(modelT_Bus_DelayTime);
                        #endregion

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

                        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("权限不足");
            }
        }
        #endregion

        #region 县级对接

        /// <summary>
        /// 获取网点列表
        /// </summary>
        /// <param name="code"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetCityList(string code, string name)
        {
            string signcode = Configs.GetValue("CityOutSignCode");
            string url = Configs.GetValue("CityOutUrl");
            string outsigncode = CommonHelper.getsigncode("CountyBranch", "GetCityList", signcode);
            string strparams = "?code=" + code + "&name=" + name + "&signcode=" + outsigncode;
            string result = HttpMethods.HttpGet(url + "/CountyBranch/GetCityList" + strparams);
            return Content(result);
        }

        /// <summary>
        /// 获取网点详情
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetCityDetail(string code)
        {
            string signcode = Configs.GetValue("CityOutSignCode");
            string url = Configs.GetValue("CityOutUrl");
            string outsigncode = CommonHelper.getsigncode("CountyBranch", "GetCityDetail", signcode);
            string strparams = "?code=" + code + "&signcode=" + outsigncode;
            string result = HttpMethods.HttpGet(url + "/CountyBranch/GetCityDetail" + strparams);
            return Content(result);
        }

        /// <summary>
        /// 转派工单到县级
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult TurnWorkOrder()
        {




            if (User.F_RoleCode == "ZXLD" || User.F_RoleCode == "YSZY" || User.F_RoleCode == "ZXLDGLYGLY" || User.F_RoleCode == "GLY" || User.F_RoleCode == "DDZG" || User.F_RoleCode == "MTDD")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                string citycode = RequestString.GetFormString("citycode");
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                if (modelT_Bus_WorkOrder != null && (modelT_Bus_WorkOrder.F_WorkState == (int)EnumWorkState.submit))
                {
                    string code = Configs.GetValue("CityCode");
                    var branchmodel = GetCityInfo(code);
                    var citymodel = GetCityInfo(citycode);
                    if (branchmodel != null && citymodel != null)
                    {
                        using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                        {
                            string cityworkorderid = string.Empty;

                            #region 转单

                            string turnsigncode = citymodel["F_Sign"].ToString();
                            string turnurl = citymodel["F_Url"].ToString();
                            string turnoutsigncode = CommonHelper.getsigncode("CountyBusiness", "AddWorkOrder", turnsigncode);
                            string turnstrparams = "workorderid=" + modelT_Bus_WorkOrder.F_WorkOrderId + "&signcode=" + turnoutsigncode
                            + "&citycode=" + branchmodel["F_Code"].ToString() + "&cityname=" + branchmodel["F_Name"].ToString() + "&cusname=" + modelT_Bus_WorkOrder.F_CusName + "&cussex=" + modelT_Bus_WorkOrder.F_CusSex
                            + "&cusphone=" + modelT_Bus_WorkOrder.F_CusPhone + "&cusaddress=" + modelT_Bus_WorkOrder.F_CusAddress + "&email=" + modelT_Bus_WorkOrder.F_Email
                            + "&zipcode=" + modelT_Bus_WorkOrder.F_ZipCode + "&conname=" + modelT_Bus_WorkOrder.F_ConName + "&conphone=" + modelT_Bus_WorkOrder.F_ConPhone
                            + "&title=" + modelT_Bus_WorkOrder.F_ComTitle + "&content=" + modelT_Bus_WorkOrder.F_ComContent + "&sourceaddress=" + modelT_Bus_WorkOrder.F_SourceAddress
                            + "&isprotect=" + modelT_Bus_WorkOrder.F_IsProtect + "&level=" + modelT_Bus_WorkOrder.F_Level;

                            string turnresultstr = HttpMethods.HttpPost(turnurl + "/CountyBusiness/AddWorkOrder", turnstrparams);
                            var turnresult = turnresultstr.ToJObject();
                            if (turnresult["state"].ToString() != "success")
                            {
                                return Content(turnresultstr);
                            }
                            else
                            {
                                cityworkorderid = turnresult["data"].ToString();
                            }

                            #endregion

                            #region 保存工单信息
                            modelT_Bus_WorkOrder.F_WorkState = (int)EnumWorkState.finish;
                            modelT_Bus_WorkOrder.F_IsClosed = 1;
                            modelT_Bus_WorkOrder.F_Result = "已转单到" + citymodel["F_Name"].ToString();
                            modelT_Bus_WorkOrder.F_DealUser = User.F_UserCode;
                            modelT_Bus_WorkOrder.F_DealTime = DateTime.Now;
                            modelT_Bus_WorkOrder.F_CloseUser = User.F_UserCode;
                            modelT_Bus_WorkOrder.F_CloseTime = DateTime.Now;
                            modelT_Bus_WorkOrder.F_AssignUser = User.F_UserCode;
                            modelT_Bus_WorkOrder.F_AssignTime = DateTime.Now;
                            workorderBLL.Update(modelT_Bus_WorkOrder);
                            #endregion

                            #region 删除草稿信息
                            var cglist = assignBLL.GetModelList(" F_IsDelete=0 and F_State=0 and F_WorkOrderId='" + modelT_Bus_WorkOrder.F_WorkOrderId + "'");

                            foreach (var cg in cglist)
                            {
                                cg.F_IsDelete = 1;
                                cg.F_DeleteUser = User.F_UserCode;
                                cg.F_DeleteTime = DateTime.Now;

                                assignBLL.Update(cg);
                            }
                            #endregion

                            #region 新增转单记录
                            Model.T_Bus_CityTurn modelT_Bus_CityTurn = new Model.T_Bus_CityTurn();
                            modelT_Bus_CityTurn.F_CityCode = citycode;
                            modelT_Bus_CityTurn.F_CityName = citymodel["F_Name"].ToString();
                            modelT_Bus_CityTurn.F_CityWorkOrderId = cityworkorderid;
                            modelT_Bus_CityTurn.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                            modelT_Bus_CityTurn.F_Type = 2;
                            modelT_Bus_CityTurn.F_State = 1;
                            modelT_Bus_CityTurn.F_IsSure = 0;
                            modelT_Bus_CityTurn.F_IsDelete = 0;
                            modelT_Bus_CityTurn.F_CreateTime = DateTime.Now;

                            new BLL.T_Bus_CityTurn().Add(modelT_Bus_CityTurn);
                            #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 + " 转派工单到 " + citymodel["F_Name"].ToString();
                            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("操作失败");
                }
            }
            else
            {
                return Success("权限不足");
            }
        }

        /// <summary>
        /// 获取当前网点信息
        /// </summary>
        /// <returns></returns>
        public Newtonsoft.Json.Linq.JObject GetCityInfo(string code)
        {
            string signcode = Configs.GetValue("CityOutSignCode");
            string url = Configs.GetValue("CityOutUrl");
            string outsigncode = CommonHelper.getsigncode("CountyBranch", "GetCityDetail", signcode);
            string strparams = "?code=" + code + "&signcode=" + outsigncode;
            var result = HttpMethods.HttpGet(url + "/CountyBranch/GetCityDetail" + strparams).ToJObject();
            if (result["state"].ToString() == "success")
            {
                return result["data"].ToString().ToJObject();
            }
            else
            {
                return null;
            }
        }
        #endregion

        #region 私有方法
        /// <summary>
        /// 添加操作日志
        /// </summary>
        /// <param name="workorderid"></param>
        /// <param name="workstate"></param>
        /// <param name="msgs"></param>
        /// <param name="usercode"></param>
        private void addoptlog(string workorderid, int? workstate, int assid, string msgs, string usercode, int type = 0,int isjb=0)
        {
            Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
            oper.F_WorkOrderId = workorderid;
            oper.F_State = workstate;
            oper.F_AssignedId = assid;
            oper.F_Message = msgs;
            oper.F_CreateUser = usercode;
            oper.F_CreateTime = DateTime.Now;
            oper.F_IsDelete = 0;
            oper.F_Type = type;
           int n=  operBLL.Add(oper);
           

           
        }

        #endregion


        /// <summary>
        /// 二级单位下工单数量
        /// </summary>
        /// <returns></returns>
        //[Authority]
        public ActionResult GetDWCount()
        {
           
            Dictionary<string, string> paras = new Dictionary<string, string>();
            paras.Add("@deptid", User.F_DeptId .ToString ());

            paras.Add("@usercode", User.F_UserCode.ToString());

            if (User.F_RoleCode != "GLY" && User.F_RoleCode != "DDZG")
            {
               
                var obj = DbHelperSQL.RunProcedure("P_DWCount", paras, "DWCount");
                return Success("成功", obj);
            }
           else
            {
                var obj = DbHelperSQL.RunProcedure("P_GLCount", paras, "DWCount");
                return Success("成功", obj);
            }
           
        }

   }
}