using CallCenter.Utility;
using CallCenterApi.Common;
using CallCenterApi.DB;
using CallCenterApi.Interface.Controllers.Base;
using CallCenterApi.Interface.Models.Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Transactions;
using System.Web;
using System.Web.Mvc;

namespace CallCenterApi.Interface.Controllers.workorder
{

    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_Operation operBLL = new BLL.T_Bus_Operation();
        private BLL.T_Sys_SystemConfig configBll = new BLL.T_Sys_SystemConfig();

        #region 获取工单

        /// <summary>
        /// 获取工单列表
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult GetList(int isdc = 0)
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            DataTable dt = new DataTable();
            string sql = " and F_IsDelete=0 ";
            string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
            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"));
            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);

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

            #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 like '%" + strname + "%' ";
            }
            if (strtel.Trim() != "" && strtel != "undefined")
            {
                sql += " and (F_CusPhone like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%') ";
            }
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {
                sql += " and F_CreateUser = '" + strusercode + "' ";
            }

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            if (keyid != 0)
            {
                sql += " and ','+F_Key+',' like '%," + 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 + "'";
            }
            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 datediff(day,F_CreateTime,'" + strstarttime + "')<=0 ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and datediff(day,F_CreateTime,'" + strendtime + "')>=0   ";
            }
            #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.GetDictionaryName(F_InfoSource) as SourceName"
                + ",dbo.GetDeptNames(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName,dbo.GetDeptNames(F_DealDeptId) as DealDeptName";

            if (isdc > 0)
            {
                var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder 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",
                "F_WorkOrderId",
                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("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)
                {
                    if (dr["F_MainDeptId"].ToString() == userModel.F_DeptId.ToString()) { iszbdw = "1"; }

                    if (state < 6 || state == 8)
                    {
                        var lt = dr["F_LimitTime"].ToString();//限制时间
                        dr["LimitTime"] = lt;

                        var ltime = DateTime.Parse(lt);
                        TimeSpan ts = ltime.Subtract(DateTime.Now);
                        int tss = Int32.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 (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);
                }

                dr["Buttons"] = ButtonGroup.GetButtons(dr["F_WorkState"].ToString(), userModel.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString(), iszbdw);
            }
            #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();
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);
            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"));
            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"));

            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 "-1"://待处理工单(其他来源)
                    sql = " and F_IsDelete=1 and F_IsEnabled=0 ";
                    break;
                case "0"://待处理工单
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_CreateUser='" + userModel.F_UserCode + "'";
                    }

                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    else
                    {
                        sql += " and F_WorkState in (0,6) ";
                    }
                    break;
                case "1"://已提交的工单
                    //sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_SubmitSuper where F_State=1 and F_IsDelete=0  ";
                    sql += " and F_WorkState >0 ";
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_CreateUser='" + userModel.F_UserCode + "'";
                    }
                    break;
                case "2"://已回访的工单
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_VisitResult where F_State=1 and F_IsDelete=0  ";
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_CreateUser='" + userModel.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "3"://已回退的工单
                    sql += "  and F_WorkState=0 and F_IsReturn=1 ";
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_CreateUser='" + userModel.F_UserCode;
                    }

                    break;
            }

            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 + "%') ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%') ";
            }
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {
                sql += " and F_CreateUser = '" + strusercode + "' ";
            }

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            if (keyid != 0)
            {
                sql += " and ','+F_Key+',' like '%," + 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 + "'";
            }

            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and datediff(day,F_CreateTime,'" + strstarttime + "')<=0 ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and datediff(day,F_CreateTime,'" + strendtime + "')>=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"
                + ",dbo.GetDeptNames(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName,dbo.GetDeptNames(F_DealDeptId) as DealDeptName";

            if (isdc > 0)
            {
                var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder 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",
                "F_WorkOrderId",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);

            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)
                {
                    if (dr["F_MainDeptId"].ToString() == userModel.F_DeptId.ToString()) { iszbdw = "1"; }

                    if (state < 6 || state == 8)
                    {
                        var lt = dr["F_LimitTime"].ToString();//限制时间
                        dr["LimitTime"] = lt;

                        var ltime = DateTime.Parse(lt);
                        TimeSpan ts = ltime.Subtract(DateTime.Now);
                        int tss = Int32.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 (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);
                }
                if (Int32.Parse(strtab) == 0)
                {
                    dr["Buttons"] = ButtonGroup.GetButtons(dr["F_WorkState"].ToString(), userModel.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString(), iszbdw);
                }
                else if (Int32.Parse(strtab) == -1)
                {
                    List<ButtonGroup.button> btns = new List<ButtonGroup.button>();
                    btns.Add(ButtonGroup.query());
                    btns.Add(ButtonGroup.edit());
                    dr["Buttons"] = btns;
                }
                else
                {
                    List<ButtonGroup.button> btns = new List<ButtonGroup.button>();
                    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();
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);
            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"));
            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"));
            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 issatisfie = RequestString.GetInt("issatisfie", -1);//0不满意 1满意

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

            switch (strtab)
            {
                case "0"://待处理工单

                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                        if (strstate.Trim() == "7" && issatisfie != -1)
                        {
                            sql += "  and F_WorkOrderID in (select F_WorkOrderID from T_Bus_VisitResult where F_State=1 and F_IsDelete=0 ";
                            sql += "  and F_IsSatisfie='" + issatisfie + "')";
                        }

                        if (userModel.F_RoleCode != "GLY" && userModel.F_RoleCode != "ZXLDGLY")
                        {
                            sql += " and (F_AssignUser='" + userModel.F_UserCode + "' or isnull(F_AssignUser,'')='')";
                        }
                    }
                    else
                    {
                        sql += " and F_WorkState in (1,2,3,5,7,8) ";
                        if (userModel.F_RoleCode != "GLY" && userModel.F_RoleCode != "ZXLDGLY")
                        {
                            sql += " and (F_AssignUser='" + userModel.F_UserCode + "' or isnull(F_AssignUser,'')='')";
                        }
                    }
                    break;
                case "1"://已交办的工单
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in (select F_WorkOrderID from T_Bus_AssignedInfo where F_State=1 and F_IsDelete=0 ";
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_CreateUser='" + userModel.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "2"://已审核退回的工单
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in (select F_WorkOrderID from T_Bus_Feedback where F_State=1 and F_IsDelete=0 and F_IsAudit>0 ";
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_AuditUser='" + userModel.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "3"://已审核延时的工单
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in (select F_WorkOrderID from T_Bus_DelayTime where F_State=1 and F_IsDelete=0 and F_IsAudit>0 ";
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_AuditUser='" + userModel.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "4"://已重办的工单
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in (select F_WorkOrderID from T_Bus_AssignedInfo where F_State=1 and F_IsDelete=0 and F_IsReload>0 ";
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_ReloadUser='" + userModel.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "5"://已结案的工单
                    sql += "  and F_WorkState =9 and F_IsDelete=0 and F_IsClosed=1 ";
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_CloseUser='" + userModel.F_UserCode + "'";
                    }
                    break;
                case "6"://已督办的工单 
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        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 =1 ";
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_CreateUser='" + userModel.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "7"://已监察的工单 
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        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 ";
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_CreateUser='" + userModel.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
            }

            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 + "%') ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%') ";
            }
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {
                sql += " and F_CreateUser = '" + strusercode + "' ";
            }

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            if (keyid != 0)
            {
                sql += " and ','+F_Key+',' like '%," + 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 datediff(day,F_CreateTime,'" + strstarttime + "')<=0 ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and datediff(day,F_CreateTime,'" + strendtime + "')>=0   ";
            }
            if (deptid != 0)
            {
                sql += " and F_MainDeptId = '" + 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.GetDictionaryName(F_InfoSource) as SourceName"
                + ",dbo.GetDeptNames(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName,dbo.GetDeptNames(F_DealDeptId) as DealDeptName";

            if (isdc > 0)
            {
                var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder 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",
                "F_WorkOrderId",
                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("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)
                {
                    if (dr["F_MainDeptId"].ToString() == userModel.F_DeptId.ToString()) { iszbdw = "1"; }

                    if (state < 6 || state == 8)
                    {
                        var lt = dr["F_LimitTime"].ToString();//限制时间
                        dr["LimitTime"] = lt;

                        var ltime = DateTime.Parse(lt);
                        TimeSpan ts = ltime.Subtract(DateTime.Now);
                        int tss = Int32.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 (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);
                }

                if (Int32.Parse(strtab) < 1)
                {
                    dr["Buttons"] = ButtonGroup.GetButtons(dr["F_WorkState"].ToString(), userModel.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString(), iszbdw);
                }
                else
                {
                    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 GetDWDealList(int isdc = 0)
        {

            DataTable dt = new DataTable();
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            string sql = " and F_IsDelete=0";
            string strtab = HttpUtility.UrlDecode(RequestString.GetQueryString("tab"));
            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 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")
                    {
                        sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    else
                    {
                        sql += " and F_WorkState in (2,4,8)";
                    }
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and ISNULL(F_DealTime, '')='' and F_MainDeptId =" + userModel.F_DeptId + "";
                        if (isyq != -1)
                        {
                            sql += " and dbo.GetOverState(F_WorkOrderId)=" + isyq;
                        }
                    }
                    break;
                case "1"://已查收的工单
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_AssignedInfo where F_State=1 and F_IsDelete=0 and F_IsSure=1 ";
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_SureUser='" + userModel.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "2"://已申请退回的工单
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_Feedback where F_State=1 and F_IsDelete=0 and F_Type = 3 ";
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_CreateUser='" + userModel.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "3"://已申请延时的工单
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_DelayTime where F_State=1 and F_IsDelete=0 ";
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_CreateUser='" + userModel.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "4"://已办理的工单 
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    sql += "  and F_WorkOrderID in(select F_WorkOrderID from T_Bus_Feedback where F_State=1 and F_IsDelete=0 and F_Type in (1,2) ";
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_CreateUser='" + userModel.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "5"://被督办的工单 
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        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 =1 ";

                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_DeptId='" + userModel.F_DeptId + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
                case "6"://被监察的工单 
                    if (strstate.Trim() != "" && strstate != "undefined")
                    {
                        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 ";
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_DeptId='" + userModel.F_DeptId + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
            }

            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 + "%') ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%') ";
            }
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {
                sql += " and F_CreateUser = '" + strusercode + "' ";
            }

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            if (keyid != 0)
            {
                sql += " and ','+F_Key+',' like '%," + 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 datediff(day,F_CreateTime,'" + strstarttime + "')<=0 ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and datediff(day,F_CreateTime,'" + strendtime + "')>=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"
                + ",dbo.GetDeptNames(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName,dbo.GetDeptNames(F_DealDeptId) as DealDeptName";

            if (isdc > 0)
            {
                var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder 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",
                "F_WorkOrderId",
                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("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)
                {
                    if (dr["F_MainDeptId"].ToString() == userModel.F_DeptId.ToString()) { iszbdw = "1"; }

                    if (state < 6 || state == 8)
                    {
                        var lt = dr["F_LimitTime"].ToString();//限制时间
                        dr["LimitTime"] = lt;

                        var ltime = DateTime.Parse(lt);
                        TimeSpan ts = ltime.Subtract(DateTime.Now);
                        int tss = Int32.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 (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);
                }

                if (Int32.Parse(strtab) < 1)
                {
                    dr["Buttons"] = ButtonGroup.GetButtons(dr["F_WorkState"].ToString(), userModel.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString(), iszbdw);
                }
                else
                {
                    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 GetXBDWDealList(int isdc = 0)
        {

            DataTable dt = new DataTable();
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            string sql = " and F_IsDelete=0";
            string strtab = HttpUtility.UrlDecode(RequestString.GetQueryString("tab"));
            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 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")
                    {
                        sql += " and F_WorkState = '" + strstate.Trim() + "' ";
                    }
                    else
                    {
                        sql += " and F_WorkState in (2,4,8)";
                    }

                    sql += " and F_WorkOrderId in (select F_WorkOrderId from T_Bus_AssignedItemInfo where F_State=1 and F_IsDelete=0 and "
                    + " ISNULL(F_FeedbackTime, '')='' ";
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_DeptId =" + userModel.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 where F_State=1 and F_IsDelete=0 and F_Type in (1,2) ";
                    if (userModel.F_RoleCode != "GLY")
                    {
                        sql += " and F_CreateUser='" + userModel.F_UserCode + "')";
                    }
                    else
                    {
                        sql += ")";
                    }
                    break;
            }

            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 + "%') ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%') ";
            }
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {
                sql += " and F_CreateUser = '" + strusercode + "' ";
            }

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            if (keyid != 0)
            {
                sql += " and ','+F_Key+',' like '%," + 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 datediff(day,F_CreateTime,'" + strstarttime + "')<=0 ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and datediff(day,F_CreateTime,'" + strendtime + "')>=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"
                + ",dbo.GetDeptNames(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName,dbo.GetDeptNames(F_DealDeptId) as DealDeptName";

            if (isdc > 0)
            {
                var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder 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",
                "F_WorkOrderId",
                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("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)
                {
                    if (dr["F_MainDeptId"].ToString() == userModel.F_DeptId.ToString()) { iszbdw = "1"; }

                    if (state < 6 || state == 8)
                    {
                        var lt = dr["F_LimitTime"].ToString();//限制时间
                        dr["LimitTime"] = lt;

                        var ltime = DateTime.Parse(lt);
                        TimeSpan ts = ltime.Subtract(DateTime.Now);
                        int tss = Int32.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 (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);
                }

                if (Int32.Parse(strtab) < 1)
                {
                    dr["Buttons"] = ButtonGroup.GetButtons(dr["F_WorkState"].ToString(), userModel.F_RoleCode.ToUpper(), dr["F_IsResult"].ToString(), iszbdw);
                }
                else
                {
                    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 GetDWNoDealList(int isdc = 0)
        {
            DataTable dt = new DataTable();

            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            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 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 (userModel.F_RoleCode == "ZXHWY")
            {
                sql += " and F_CreateUser = '" + userModel.F_UserCode + "' ";
            }
            else if (strusercode.Trim() != "" && strusercode != "undefined")
            {
                sql += " and F_CreateUser = '" + strusercode + "' ";
            }


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

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

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

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

            sql += "))";

            if (strstate.Trim() != "" && strstate != "undefined")
            {
                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 (strtel.Trim() != "" && strtel != "undefined")
            {
                sql += " and (F_CusPhone like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%') ";
            }

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            if (keyid != 0)
            {
                sql += " and ','+F_Key+',' like '%," + 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 datediff(day,F_CreateTime,'" + strstarttime + "')<=0 ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and datediff(day,F_CreateTime,'" + strendtime + "')>=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"
                + ",dbo.GetDeptNames(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName,dbo.GetDeptNames(F_DealDeptId) as DealDeptName";

            if (isdc > 0)
            {
                var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder 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",
                "F_WorkOrderId",
                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("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)
                {
                    if (dr["F_MainDeptId"].ToString() == userModel.F_DeptId.ToString()) { iszbdw = "1"; }

                    if (state < 6 || state == 8)
                    {
                        var lt = dr["F_LimitTime"].ToString();//限制时间
                        dr["LimitTime"] = lt;

                        var ltime = DateTime.Parse(lt);
                        TimeSpan ts = ltime.Subtract(DateTime.Now);
                        int tss = Int32.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 (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 GetTimeOutList(int isdc = 0)
        {
            DataTable dt = new DataTable();

            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            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 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 (userModel.F_RoleCode == "ZXHWY")
            {
                sql += " and F_CreateUser = '" + userModel.F_UserCode + "' ";
            }
            else if (strusercode.Trim() != "" && strusercode != "undefined")
            {
                sql += " and F_CreateUser = '" + strusercode + "' ";
            }


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

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

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

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

            sql += "))";

            if (strstate.Trim() != "" && strstate != "undefined")
            {
                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 (strtel.Trim() != "" && strtel != "undefined")
            {
                sql += " and (F_CusPhone like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%') ";
            }

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            if (keyid != 0)
            {
                sql += " and ','+F_Key+',' like '%," + 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 datediff(day,F_CreateTime,'" + strstarttime + "')<=0 ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and datediff(day,F_CreateTime,'" + strendtime + "')>=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"
                + ",dbo.GetDeptNames(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName,dbo.GetDeptNames(F_DealDeptId) as DealDeptName";

            if (isdc > 0)
            {
                var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder 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",
                "F_WorkOrderId",
                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("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)
            {
                int state = Int32.Parse(dr["F_WorkState"].ToString());
                if (state > 1)
                {
                    if (state < 6 || state == 8)
                    {
                        var lt = dr["F_LimitTime"].ToString();//限制时间
                        dr["LimitTime"] = lt;

                        var ltime = DateTime.Parse(lt);
                        TimeSpan ts = ltime.Subtract(DateTime.Now);
                        int tss = Int32.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 (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 GetMediaList(int isdc = 0)
        {
            DataTable dt = new DataTable();

            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            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"));

            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_IsRelease,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 (strtel.Trim() != "" && strtel != "undefined")
            {
                sql += " and (F_CusPhone like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%') ";
            }
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {
                sql += " and F_CreateUser = '" + strusercode + "' ";
            }

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            if (keyid != 0)
            {
                sql += " and ','+F_Key+',' like '%," + 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 + "'";
            }
            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and datediff(day,F_CreateTime,'" + strstarttime + "')<=0 ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and datediff(day,F_CreateTime,'" + strendtime + "')>=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"
                 + ",dbo.GetDeptNames(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName,dbo.GetDeptNames(F_DealDeptId) as DealDeptName";

            if (isdc > 0)
            {
                var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder 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",
                "F_WorkOrderId",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);

            #region 声音文件

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

            int IsReturnMedia = 0;
            if (userModel.F_RoleCode == "ZXLD" || userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
            {
                IsReturnMedia = 1;
            }
            foreach (DataRow dr in dt.Rows)
            {
                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(int isdc = 0)
        //{
        //    DataTable dt = new DataTable();

        //    int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

        //    Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

        //    string sql = " and F_IsDelete=0 and isnull(F_IsNotice,0) =1";
        //    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"));

        //    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 + "%') ";
        //    }
        //    if (strkey.Trim() != "" && strkey != "undefined")
        //    {
        //        sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%') ";
        //    }
        //    if (strusercode.Trim() != "" && strusercode != "undefined")
        //    {
        //        sql += " and F_CreateUser = '" + strusercode + "' ";
        //    }

        //    if (source != 0)
        //    {
        //        sql += " and F_InfoSource = '" + source + "' ";
        //    }
        //    if (keyid != 0)
        //    {
        //        sql += " and ','+F_Key+',' like '%," + 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 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 datediff(day,F_CreateTime,'" + strstarttime + "')<=0 ";
        //    }
        //    if (strendtime.Trim() != "" && strendtime != "undefined")
        //    {
        //        sql += " and datediff(day,F_CreateTime,'" + strendtime + "')>=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";

        //    if (isdc > 0)
        //    {
        //        var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder 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",
        //        "F_WorkOrderId",
        //        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("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 (userModel.F_RoleCode == "ZXLD" || userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
        //    {
        //        IsReturnNotice = 1;
        //    }
        //    foreach (DataRow dr in dt.Rows)
        //    {
        //        //获取最新交办信息
        //        //string iszbdw = "0";
        //        string sqljb = "SELECT TOP 1 * FROM T_Bus_AssignedInfo 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() == userModel.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() + "')");
        //            }
        //            //int did = Int32.Parse(dtjb.Rows[0]["F_MainDeptId"].ToString());
        //            //var deptinfo = new BLL.T_Sys_Department().GetModel(did);
        //            //if (deptinfo != null)
        //            //{
        //            //    //if (did == userModel.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;
        //            //}
        //        }
        //        //获取最新通报信息
        //        string sqltb = "SELECT TOP 1 * FROM T_Bus_NoticeCriticism 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>
        /// <returns></returns>
        [Authority]
        public ActionResult GetNoticeList(int isdc = 0)
        {
            DataTable dt = new DataTable();

            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            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"));

            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 + "%') ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%') ";
            }
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {
                sql += " and F_CreateUser = '" + strusercode + "' ";
            }

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            if (keyid != 0)
            {
                sql += " and ','+F_Key+',' like '%," + 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 + "' ";
            }
            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and datediff(day,F_CreateTime,'" + strstarttime + "')<=0 ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and datediff(day,F_CreateTime,'" + strendtime + "')>=0   ";
            }

            if (userModel.F_RoleCode == "WLDW")
            {
                string sqlwhere = "select F_WorkOrderID from T_Bus_NoticeCriticism where ','+F_DeptIds+',' like  '%," + userModel.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 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"
                 + ",dbo.GetDeptNames(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName,dbo.GetDeptNames(F_DealDeptId) as DealDeptName"
                 + ",dbo.GetDeptNames(F_NoticeDeptIds) as NoticeDeptName";

            if (isdc > 0)
            {
                var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder 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",
                "F_WorkOrderId",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);

            #region 声音文件

            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 (userModel.F_RoleCode == "ZXLD" || userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
            {
                IsReturnNotice = 1;
            }
            foreach (DataRow dr in dt.Rows)
            {
                //获取最新通报信息
                string sqltb = "SELECT TOP 1 * FROM T_Bus_NoticeCriticism 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)
                {
                    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>
        /// <returns></returns>
        [Authority]
        public ActionResult GetSuperList(int isdc = 0)
        {
            DataTable dt = new DataTable();

            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            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"));

            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 + "%') ";
            }
            if (strkey.Trim() != "" && strkey != "undefined")
            {
                sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%') ";
            }
            if (strusercode.Trim() != "" && strusercode != "undefined")
            {
                sql += " and F_CreateUser = '" + strusercode + "' ";
            }

            if (source != 0)
            {
                sql += " and F_InfoSource = '" + source + "' ";
            }
            if (keyid != 0)
            {
                sql += " and ','+F_Key+',' like '%," + 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 + "'";
            }
            if (strstarttime.Trim() != "" && strstarttime != "undefined")
            {
                sql += " and datediff(day,F_CreateTime,'" + strstarttime + "')<=0 ";
            }
            if (strendtime.Trim() != "" && strendtime != "undefined")
            {
                sql += " and datediff(day,F_CreateTime,'" + strendtime + "')>=0   ";
            }

            sql += " and F_WorkOrderID in(select F_WorkOrderID from T_Bus_SubmitSuper where F_State=1 and F_IsDelete=0 and F_Type in (1,2))";


            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"
                 + ",dbo.GetDeptNames(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName,dbo.GetDeptNames(F_DealDeptId) as DealDeptName"
                 + ",dbo.GetDeptNames(F_NoticeDeptIds) as NoticeDeptName";

            if (isdc > 0)
            {
                var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Bus_WorkOrder 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",
                "F_WorkOrderId",
                cols,
                sql,
                "ORDER BY F_CreateTime DESC",
                pagesize,
                pageindex,
                true,
                out recordCount);

            #region 声音文件

            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();

            foreach (DataRow dr in dt.Rows)
            {
                //获取最新通报信息
                string sqltb = "SELECT TOP 1 * FROM T_Bus_NoticeCriticism 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)
                {
                    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;
            }

            #endregion

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

            return Content(obj.ToJson());
        }

        /// <summary>
        /// 获取工单信息
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult GetWorkOrder()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            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.GetDictionaryName(F_InfoSource) as SourceName"
                 + ",dbo.GetDeptNames(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName,dbo.GetDeptNames(F_DealDeptId) as DealDeptName"
                 + ",dbo.GetDeptNames(F_NoticeDeptIds) as NoticeDeptName,dbo.GetAreaName(F_SourceArea) as AreaName "
                + " from T_Bus_WorkOrder where F_WorkOrderId ='" + strworkorderid + "'";
                var dt = DbHelperSQL.Query(sql).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    if (dt.Rows[0]["F_IsProtect"] != null && userModel.F_RoleCode == "WLDW")
                    {
                        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 where F_Type=2 and F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "'";
                    string dbsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_DeptId) as DeptName "
                                    + "from T_Bus_RemindRecord where F_Type=1 and F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "'";
                    string pssql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_SubmitSuper where F_State=1 and F_IsDelete=0 and F_Type=1 and F_WorkOrderId ='" + strworkorderid + "'";
                    string zssql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_SubmitSuper where F_State=1 and F_IsDelete=0 and F_Type=2 and F_WorkOrderId ='" + strworkorderid + "'";
                    string jbsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_MainDeptId) as DeptName,dbo.GetDeptNames(F_OtherDeptIds) as OtherDeptName "
                                    + "from T_Bus_AssignedInfo where F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "'";
                    string thsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_CreateDeptId) as DeptName "
                                    + "from T_Bus_Feedback where F_State=1 and F_Type=3 and F_IsDelete=0 and  F_WorkOrderId ='" + strworkorderid + "'";
                    string yssql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_DelayTime where F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "'";
                    string blsql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDeptName(F_CreateDeptId) as DeptName "
                                    + "from T_Bus_Feedback where F_State=1 and F_Type!=3 and F_IsDelete=0 and  F_WorkOrderId ='" + strworkorderid + "'";
                    string hfsql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_VisitResult where F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "'";
                    string gcsql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
                                    + "from T_Bus_Operation 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 where F_State=1 and F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "'";


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

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

                    #region 延时信息
                    var ysdt = DbHelperSQL.Query(yssql).Tables[0];
                    #endregion

                    #region 办理情况
                    var bldt = DbHelperSQL.Query(blsql).Tables[0];
                    if (configfj != null)
                    {
                        bldt = BindFileData(bldt, 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 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 lcdt = new DataTable();
                    lcdt.Columns.Add("step", typeof(int));
                    lcdt.Columns.Add("name", typeof(string));
                    lcdt.Columns.Add("dept", typeof(string));
                    lcdt.Columns.Add("time", typeof(string));

                    DataRow dr1 = lcdt.NewRow();
                    dr1["step"] = 1;
                    if (dt.Rows[0]["F_CreateUser"] != null)
                    {
                        var lruser = new BLL.T_Sys_UserAccount().GetModel(dt.Rows[0]["F_CreateUser"].ToString());
                        if (lruser != null)
                        {
                            dr1["name"] = lruser.F_UserName;
                            dr1["dept"] = lruser.depname;
                        }
                        else
                        {
                            dr1["name"] = dt.Rows[0]["F_CreateUser"].ToString();
                            dr1["dept"] = "";
                        }
                    }
                    dr1["time"] = dt.Rows[0]["F_CreateTime"];
                    lcdt.Rows.Add(dr1);

                    int state = Int32.Parse(dt.Rows[0]["F_WorkState"].ToString());
                    if (state >= 1)
                    {
                        if (jbdt.Rows.Count > 0)
                        {
                            var newjb = jbdt.Rows[jbdt.Rows.Count - 1];
                            DataRow dr2 = lcdt.NewRow();
                            dr2["step"] = 2;
                            var jbuser = new BLL.T_Sys_UserAccount().GetModel(newjb["F_CreateUser"].ToString());
                            if (jbuser != null)
                            {
                                dr2["name"] = jbuser.F_UserName;
                                dr2["dept"] = jbuser.depname;
                            }
                            else
                            {
                                dr2["name"] = newjb["F_CreateUser"].ToString();
                                dr2["dept"] = "";
                            }
                            dr2["time"] = newjb["F_CreateTime"];
                            lcdt.Rows.Add(dr2);
                        }
                    }
                    if (state >= 6)
                    {
                        if (bldt.Rows.Count > 0)
                        {
                            var newbl = bldt.Rows[bldt.Rows.Count - 1];
                            DataRow dr3 = lcdt.NewRow();
                            dr3["step"] = 3;
                            var jbuser = new BLL.T_Sys_UserAccount().GetModel(newbl["F_CreateUser"].ToString());
                            if (jbuser != null)
                            {
                                dr3["name"] = jbuser.F_UserName;
                                dr3["dept"] = jbuser.depname;
                            }
                            else
                            {
                                dr3["name"] = newbl["F_CreateUser"].ToString();
                                dr3["dept"] = "";
                            }
                            dr3["time"] = newbl["F_CreateTime"];
                            lcdt.Rows.Add(dr3);
                        }
                    }
                    if (state >= 7)
                    {
                        if (hfdt.Rows.Count > 0)
                        {
                            var newhf = hfdt.Rows[hfdt.Rows.Count - 1];
                            DataRow dr4 = lcdt.NewRow();
                            dr4["step"] = 4;
                            var jbuser = new BLL.T_Sys_UserAccount().GetModel(newhf["F_CreateUser"].ToString());
                            if (jbuser != null)
                            {
                                dr4["name"] = jbuser.F_UserName;
                                dr4["dept"] = jbuser.depname;
                            }
                            else
                            {
                                dr4["name"] = newhf["F_CreateUser"].ToString();
                                dr4["dept"] = "";
                            }
                            dr4["time"] = newhf["F_CreateTime"];
                            lcdt.Rows.Add(dr4);
                        }
                    }
                    if (state == 9)
                    {
                        DataRow dr5 = lcdt.NewRow();
                        dr5["step"] = 5;
                        var enduser = new BLL.T_Sys_UserAccount().GetModel(dt.Rows[0]["F_CloseUser"].ToString());
                        if (enduser != null)
                        {
                            dr5["name"] = enduser.F_UserName;
                            dr5["dept"] = enduser.depname;
                        }
                        else
                        {
                            dr5["name"] = dt.Rows[0]["F_CloseUser"].ToString();
                            dr5["dept"] = "";
                        }
                        dr5["time"] = dt.Rows[0]["F_CloseTime"];
                        lcdt.Rows.Add(dr5);
                    }

                    #endregion

                    #region 操作按钮
                    var btns = new List<ButtonGroup.button>();
                    if (jbdt.Rows.Count > 0)
                    {
                        var jbzx = jbdt.Rows[jbdt.Rows.Count - 1];
                        string iszbdw = "0";
                        string fmd = jbzx["F_MainDeptId"].ToString();
                        string fod = jbzx["F_OtherDeptIds"] == null ? "" : jbzx["F_OtherDeptIds"].ToString();
                        if (fmd == userModel.F_DeptId.ToString()) { iszbdw = "1"; }
                        else if (fod != "" && fod.Split(',').Contains(userModel.F_DeptId.ToString()))
                        {
                            iszbdw = "2";
                        }
                        if (!(userModel.F_RoleCode == "WLDW" && iszbdw == "0"))
                        {
                            btns = ButtonGroup.GetButtons(dt.Rows[0]["F_WorkState"].ToString(), userModel.F_RoleCode.ToUpper(), dt.Rows[0]["F_IsResult"].ToString(), iszbdw);
                        }
                    }
                    else
                    {
                        btns = ButtonGroup.GetButtons(dt.Rows[0]["F_WorkState"].ToString(), userModel.F_RoleCode.ToUpper(), dt.Rows[0]["F_IsResult"].ToString(), "0");
                    }
                    #endregion

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

                    var obj = new
                    {
                        data = dt,
                        jcdata = jcdt,
                        psdata = psdt,
                        zsdata = zsdt,
                        dbdata = dbdt,
                        jbdata = jbdt,
                        thdata = thdt,
                        ysdata = ysdt,
                        bldata = bldt,
                        hfdata = hfdt,
                        cbdata = cbdt,
                        gcdata = gcdt,
                        lcdata = lcdt,
                        issend = issend,
                        isedit = isedit,
                        isnotice = isnotice,
                        btndata = btns
                    };
                    return Success("获取成功", obj);
                }
                else
                {
                    return Error("获取失败");
                }
            }
            else
            {
                return Error("参数传输失败");
            }
        }

        /// <summary>
        /// 获取草稿信息
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult GetDraftInfo()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);
            string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
            int type = RequestString.GetInt("type", 0);//1交办信息2反馈信息3回访信息
            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 from T_Bus_AssignedInfo"; break;
                    case 2: sql = "select top 1 * from T_Bus_Feedback"; break;
                    case 3: sql = "select top 1 * from T_Bus_VisitResult"; break;
                }
                sql += " where F_WorkOrderId='" + strworkorderid + "' and F_State=0 and F_IsDelete=0 and F_CreateUser=" + userModel.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()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            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 * from T_Bus_Feedback where F_Type=3 and"; break;
                    case 2: sql = "select top 1 * from T_Bus_DelayTime where"; break;
                }
                sql += " F_WorkOrderId='" + strworkorderid + "' and F_State=1 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()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            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("操作失败");
            }
        }
        #endregion

        #region 新增工单
        /// <summary>
        /// 上传附件
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult UploadFile()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            #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 = userModel.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 = userModel.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()
        {

            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXHWY" || userModel.F_RoleCode == "ZXBZ" || userModel.F_RoleCode == "GLY")
            {

                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");


                using (TransactionScope trans = new TransactionScope())
                {
                    #region 保存工单信息
                    Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = new Model.T_Bus_WorkOrder();
                    modelT_Bus_WorkOrder.F_WorkOrderId = workorderBLL.GetNewWorkOrderID(userModel.F_UserCode);

                    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;

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

                    modelT_Bus_WorkOrder.F_CreateUser = userModel.F_UserCode;//登记人工号
                    modelT_Bus_WorkOrder.F_CreateTime = DateTime.Now;//登记时间
                    modelT_Bus_WorkOrder.F_WorkState = 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 = 9;//已结案
                        modelT_Bus_WorkOrder.F_DealDeptId = userModel.F_DeptId;
                        modelT_Bus_WorkOrder.F_DealUser = userModel.F_UserCode;
                        modelT_Bus_WorkOrder.F_DealTime = DateTime.Now;
                        modelT_Bus_WorkOrder.F_IsClosed = 1;
                        modelT_Bus_WorkOrder.F_CloseUser = userModel.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 = 1;//提交领导
                    }

                    if (!string.IsNullOrEmpty(callid))
                    {
                        modelT_Bus_WorkOrder.F_CallId = callid;
                        var rd = new BLL.T_Call_CallRecords().GetModelByCallId(callid);
                        if (rd != null)
                        {
                            rd.IsExitWorkOrder = true;
                            new BLL.T_Call_CallRecords().Update(rd);

                            modelT_Bus_WorkOrder.F_CallRecordId = rd.CallRecordsId;
                        }
                    }

                    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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                    if (modelT_Bus_WorkOrder.F_WorkState == 0)
                    {
                        oper.F_Message = userinfo + " 登记了工单,工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId;
                    }
                    if (modelT_Bus_WorkOrder.F_WorkState == 1)
                    {
                        oper.F_Message = userinfo + " 登记并提交了工单,工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId;
                    }
                    if (modelT_Bus_WorkOrder.F_WorkState == 9)
                    {
                        oper.F_Message = userinfo + " 登记并结案了工单,工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId;
                    }

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

                    operBLL.Add(oper);

                    //推送消息表
                    if (modelT_Bus_WorkOrder.F_WorkState != 0)
                    {
                        var role = new BLL.T_Sys_RoleInfo().GetModelList(" (F_RoleCode='ZXLD' or F_RoleCode='ZXLDGLY')  ").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, userModel.F_UserCode);
                        }
                    }
                    #endregion

                    trans.Complete();
                }
                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())
            {
                #region 保存工单信息
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = new Model.T_Bus_WorkOrder();
                modelT_Bus_WorkOrder.F_WorkOrderId = workorderBLL.GetNewWorkOrderID(source.ToString().PadLeft(4, '0'));

                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_CreateUser = userModel.F_UserCode;//登记人工号
                modelT_Bus_WorkOrder.F_CreateTime = DateTime.Now;//登记时间
                modelT_Bus_WorkOrder.F_WorkState = 0;//工单状态0登记中
                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 == 0)
                {
                    oper.F_Message = userinfo + " 登记了工单,工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId;
                }

                //oper.F_CreateUser = userModel.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()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXHWY" || userModel.F_RoleCode == "ZXBZ" || userModel.F_RoleCode == "GLY")
            {

                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())
                {
                    #region 保存工单信息
                    Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = new Model.T_Bus_WorkOrder();
                    modelT_Bus_WorkOrder.F_WorkOrderId = workorderBLL.GetNewWorkOrderID(userModel.F_UserCode);

                    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 = userModel.F_UserCode;//登记人工号
                    modelT_Bus_WorkOrder.F_CreateTime = DateTime.Now;//登记时间
                    modelT_Bus_WorkOrder.F_WorkState = 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 = 9;//已结案
                        modelT_Bus_WorkOrder.F_DealDeptId = userModel.F_DeptId;
                        modelT_Bus_WorkOrder.F_DealUser = userModel.F_UserCode;
                        modelT_Bus_WorkOrder.F_DealTime = DateTime.Now;
                        modelT_Bus_WorkOrder.F_IsClosed = 1;
                        modelT_Bus_WorkOrder.F_CloseUser = userModel.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 = 1;//提交领导
                    }

                    if (lyid != 0)
                    {
                        var rd = new BLL.T_Call_LeaveRecord().GetModel(lyid);
                        if (rd != null)
                        {
                            rd.F_Status = 1;
                            rd.F_DealTime = DateTime.Now;
                            rd.F_UserCode = userModel.F_UserCode;
                            rd.F_UserName = userModel.F_UserName;
                            rd.F_UserId = userModel.F_UserId;
                            new BLL.T_Call_LeaveRecord().Update(rd);

                            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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                    if (modelT_Bus_WorkOrder.F_WorkState == 0)
                    {
                        oper.F_Message = userinfo + " 登记了工单,工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId;
                    }
                    if (modelT_Bus_WorkOrder.F_WorkState == 1)
                    {
                        oper.F_Message = userinfo + " 登记并提交了工单,工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId;
                    }
                    if (modelT_Bus_WorkOrder.F_WorkState == 9)
                    {
                        oper.F_Message = userinfo + " 登记并结案了工单,工单编号：" + modelT_Bus_WorkOrder.F_WorkOrderId;
                    }

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

                    operBLL.Add(oper);

                    //推送消息表
                    if (modelT_Bus_WorkOrder.F_WorkState != 0)
                    {
                        var role = new BLL.T_Sys_RoleInfo().GetModelList(" (F_RoleCode='ZXLD' or F_RoleCode='ZXLDGLY')  ").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, userModel.F_UserCode);
                        }
                    }
                    #endregion

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

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

        /// <summary>
        /// 添加工单信息
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult AddWorkOrderByAPP()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            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);
            if (!string.IsNullOrEmpty(workorderid))
            {
                using (TransactionScope trans = new TransactionScope())
                {
                    #region 保存用户工单信息
                    var model = new BLL.T_Sys_Users().GetModel(userModel.F_UserCode);
                    if (model == null)
                    {
                        model = new Model.T_Sys_Users();
                        model.F_OpenId = userModel.F_UserCode;
                        model.F_Type = 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()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXHWY" || userModel.F_RoleCode == "ZXBZ" || userModel.F_RoleCode == "ZXLD" || userModel.F_RoleCode == "ZXLDGLY" || userModel.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_WorkState == 1 || modelT_Bus_WorkOrder.F_WorkState == 0))
                {
                    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);


                    using (TransactionScope trans = new TransactionScope())
                    {
                        #region 保存工单信息

                        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;//处理结果

                        //如果选择即刻答复：是，即为直办，工单结束
                        if (isresult == 1)
                        {
                            modelT_Bus_WorkOrder.F_WorkState = 9;//已结案
                            modelT_Bus_WorkOrder.F_DealDeptId = userModel.F_DeptId;
                            modelT_Bus_WorkOrder.F_DealUser = userModel.F_UserCode;
                            modelT_Bus_WorkOrder.F_DealTime = DateTime.Now;
                            modelT_Bus_WorkOrder.F_IsClosed = 1;
                            modelT_Bus_WorkOrder.F_CloseUser = userModel.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 = 1;//提交领导
                        }

                        workorderBLL.Update(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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                        if (modelT_Bus_WorkOrder.F_WorkState == 0)
                        {
                            oper.F_Message = userinfo + " 修改了工单";
                        }
                        if (modelT_Bus_WorkOrder.F_WorkState == 1)
                        {
                            oper.F_Message = userinfo + " 修改并提交了工单";
                        }
                        if (modelT_Bus_WorkOrder.F_WorkState == 9)
                        {
                            oper.F_Message = userinfo + " 修改并结案了工单";
                        }

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

                        operBLL.Add(oper);

                        //推送消息表
                        if (modelT_Bus_WorkOrder.F_WorkState == 1)
                        {
                            var role = new BLL.T_Sys_RoleInfo().GetModelList(" (F_RoleCode='ZXLD' or F_RoleCode='ZXLDGLY')  ").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, userModel.F_UserCode);
                            }
                        }

                        #endregion

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

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

        /// <summary>
        /// 修改工单信息
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult EditWorkOrderBySource()
        {

            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXHWY" || userModel.F_RoleCode == "ZXBZ" || userModel.F_RoleCode == "GLY")
            {

                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");

                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)
                {
                    using (TransactionScope trans = new TransactionScope())
                    {
                        #region 保存工单信息

                        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;//处理结果

                        //如果选择即刻答复：是，即为直办，工单结束
                        if (isresult == 1)
                        {
                            modelT_Bus_WorkOrder.F_WorkState = 9;//已结案
                            modelT_Bus_WorkOrder.F_DealDeptId = userModel.F_DeptId;
                            modelT_Bus_WorkOrder.F_DealUser = userModel.F_UserCode;
                            modelT_Bus_WorkOrder.F_DealTime = DateTime.Now;
                            modelT_Bus_WorkOrder.F_IsClosed = 1;
                            modelT_Bus_WorkOrder.F_CloseUser = userModel.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 = 1;//提交领导
                        }
                        modelT_Bus_WorkOrder.F_CreateUser = userModel.F_UserCode;
                        modelT_Bus_WorkOrder.F_IsEnabled = 1;
                        modelT_Bus_WorkOrder.F_EnableTime = DateTime.Now;
                        modelT_Bus_WorkOrder.F_IsDelete = 0;
                        workorderBLL.Update(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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                        if (modelT_Bus_WorkOrder.F_WorkState == 0)
                        {
                            oper.F_Message = userinfo + " 处理了工单";
                        }
                        if (modelT_Bus_WorkOrder.F_WorkState == 1)
                        {
                            oper.F_Message = userinfo + " 处理并提交了工单";
                        }
                        if (modelT_Bus_WorkOrder.F_WorkState == 9)
                        {
                            oper.F_Message = userinfo + " 处理并结案了工单";
                        }

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

                        operBLL.Add(oper);

                        //推送消息表
                        if (modelT_Bus_WorkOrder.F_WorkState == 1)
                        {
                            var role = new BLL.T_Sys_RoleInfo().GetModelList(" (F_RoleCode='ZXLD' or F_RoleCode='ZXLDGLY')  ").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, userModel.F_UserCode);
                            }
                        }
                        #endregion

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

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

        /// <summary>
        /// 提交工单
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [Authority]
        public ActionResult SubmitWorkOrder(string[] ids)
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXHWY" || userModel.F_RoleCode == "ZXBZ" || userModel.F_RoleCode == "GLY")
            {
                if (ids != null && ids.Length > 0)
                {
                    foreach (string str in ids)
                    {
                        using (TransactionScope trans = new TransactionScope())
                        {
                            Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(str);
                            if (modelT_Bus_WorkOrder != null)
                            {
                                if (modelT_Bus_WorkOrder.F_WorkState == 0)
                                {
                                    #region 保存工单信息
                                    modelT_Bus_WorkOrder.F_SubmitTime = DateTime.Now;
                                    modelT_Bus_WorkOrder.F_WorkState = 1;//待交办
                                    workorderBLL.Update(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;

                                    string userinfo = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                                    oper.F_Message = userinfo + " 提交了工单";
                                    oper.F_CreateUser = userModel.F_UserCode;
                                    oper.F_CreateTime = DateTime.Now;
                                    oper.F_IsDelete = 0;

                                    operBLL.Add(oper);

                                    //推送消息表
                                    if (modelT_Bus_WorkOrder.F_WorkState == 1)
                                    {
                                        var role = new BLL.T_Sys_RoleInfo().GetModelList(" (F_RoleCode='ZXLD' or F_RoleCode='ZXLDGLY')  ").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, userModel.F_UserCode);
                                        }
                                    }
                                    #endregion
                                }

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

        /// <summary>
        /// 回退工单
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult ReturnWorkOrder()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);

            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))
                {
                    using (TransactionScope trans = new TransactionScope())
                    {
                        #region 保存工单信息
                        modelT_Bus_WorkOrder.F_WorkState = 0;
                        modelT_Bus_WorkOrder.F_IsResult = 0;
                        modelT_Bus_WorkOrder.F_IsReturn = 1;
                        modelT_Bus_WorkOrder.F_LimitTime = null;
                        modelT_Bus_WorkOrder.F_IsOverdue = 0;
                        modelT_Bus_WorkOrder.F_MainDeptId = null;
                        modelT_Bus_WorkOrder.F_OtherDeptIds = "";
                        modelT_Bus_WorkOrder.F_DealDeptId = null;
                        modelT_Bus_WorkOrder.F_DealUser = "";
                        modelT_Bus_WorkOrder.F_DealTime = null;
                        modelT_Bus_WorkOrder.F_AssignUser = userModel.F_UserCode;
                        modelT_Bus_WorkOrder.F_AssignTime = DateTime.Now;
                        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 = 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 = userModel.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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                        oper.F_Message = userinfo + " 回退了工单";
                        oper.F_CreateUser = userModel.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()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            string workorderid = RequestString.GetFormString("workorderid");
            int type = RequestString.GetInt("type", 0);//1领导批示 2市长指示
            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())
                {

                    #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 = userModel.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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                    oper.F_Message = userinfo + " 批示了工单";
                    oper.F_CreateUser = userModel.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 AssignWorkOrder()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXLD" || userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int state = RequestString.GetInt("state", 0);
                int assignid = RequestString.GetInt("assignid", 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 (!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)
                    {
                        int aid = 0;
                        using (TransactionScope trans = 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 = userModel.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;
                                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_State = state;//0草稿  1正式
                                    modelT_Bus_AssignedInfo.F_CreateUser = userModel.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_LimitTime = limittime;
                                modelT_Bus_WorkOrder.F_MainDeptId = maindeptid;
                                modelT_Bus_WorkOrder.F_OtherDeptIds = otherdeptids;
                                modelT_Bus_WorkOrder.F_AssignUser = userModel.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 = userModel.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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.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 = userModel.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, userModel.F_UserCode);
                                }
                                #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 ActionResult TakeBackWorkOrder()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXLD" || userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
            {
                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)
                    {
                        using (TransactionScope trans = new TransactionScope())
                        {
                            #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;

                            assignBLL.Add(AssignedInfo);

                            #endregion

                            #region 保存工单信息
                            modelT_Bus_WorkOrder.F_WorkState = 1;//待交办
                            modelT_Bus_WorkOrder.F_MainDeptId = null;
                            modelT_Bus_WorkOrder.F_OtherDeptIds = "";
                            workorderBLL.Update(modelT_Bus_WorkOrder);
                            #endregion

                            #region 删除交办信息
                            modelT_Bus_AssignedInfo.F_IsDelete = 1;//删除
                            modelT_Bus_AssignedInfo.F_DeleteUser = userModel.F_UserCode;
                            modelT_Bus_AssignedInfo.F_DeleteTime = 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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                            oper.F_Message = userinfo + " 收回了工单";
                            oper.F_CreateUser = userModel.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()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "WLDW" || userModel.F_RoleCode == "GLY")
            {
                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 == userModel.F_DeptId)
                {
                    if (modelT_Bus_AssignedInfo.F_IsSure == 0)
                    {
                        using (TransactionScope trans = new TransactionScope())
                        {
                            #region 保存工单信息
                            modelT_Bus_WorkOrder.F_WorkState = 4;//办理中
                            workorderBLL.Update(modelT_Bus_WorkOrder);
                            #endregion

                            #region 保存查收信息
                            modelT_Bus_AssignedInfo.F_IsSure = 1;//查收
                            modelT_Bus_AssignedInfo.F_SureUser = userModel.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 = userModel.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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                            oper.F_Message = userinfo + " 查收了工单";
                            oper.F_CreateUser = userModel.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 RebackWorkOrder()
        {

            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "WLDW" || userModel.F_RoleCode == "GLY")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                string backreason = RequestString.GetFormString("backreason");

                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 == userModel.F_DeptId)
                {
                    if (modelT_Bus_AssignedInfo.F_IsSure == 0)
                    {
                        using (TransactionScope trans = new TransactionScope())
                        {
                            #region 保存工单信息
                            modelT_Bus_WorkOrder.F_WorkState = 3;//退回审核中
                            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 = userModel.F_UserCode;//退回人
                            model_T_Bus_Feedback.F_CreateTime = DateTime.Now;//退回时间
                            model_T_Bus_Feedback.F_CreateDeptId = userModel.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_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 = userModel.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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                            oper.F_Message = userinfo + " 申请退回了工单";
                            oper.F_CreateUser = userModel.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, userModel.F_UserCode);
                            #endregion

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

        /// <summary>
        /// 审核退回工单
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult AuditRebackWorkOrder()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXLD" || userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int state = RequestString.GetInt("state", 0);
                string reason = RequestString.GetFormString("reason");

                int rebackid = RequestString.GetInt("rebackid", 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);

                if (modelT_Bus_WorkOrder != null && modelT_Bus_Feedback != null && modelT_Bus_AssignedInfo != null)
                {
                    if (modelT_Bus_Feedback.F_Type == 3 && modelT_Bus_Feedback.F_IsAudit == 0)
                    {
                        using (TransactionScope trans = new TransactionScope())
                        {
                            #region 保存查收信息
                            modelT_Bus_Feedback.F_IsAudit = state;//审核
                            modelT_Bus_Feedback.F_AuditUser = userModel.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_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;//待交办
                                workorderBLL.Update(modelT_Bus_WorkOrder);
                                #endregion
                            }
                            else
                            {
                                #region 保存工单信息

                                modelT_Bus_WorkOrder.F_WorkState = 2;//待查收
                                workorderBLL.Update(modelT_Bus_WorkOrder);
                                #endregion

                                #region 保存交办信息
                                //modelT_Bus_AssignedInfo.F_FeedbackTime = null;//反馈时间
                                modelT_Bus_AssignedInfo.F_IsSure = 0;
                                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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                            oper.F_Message = userinfo + " " + strmsg + "了工单退回申请";
                            oper.F_CreateUser = userModel.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, userModel.F_UserCode);
                            #endregion

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

        /// <summary>
        /// 申请延时
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult DelayWorkOrder()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "WLDW" || userModel.F_RoleCode == "GLY")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                //int state = RequestString.GetInt("state", 0);
                DateTime newlimittime = DateTime.Parse(RequestString.GetFormString("newlimittime") + " 23:59:59");
                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);

                if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo != null && modelT_Bus_AssignedInfo.F_MainDeptId == userModel.F_DeptId)
                {
                    if (modelT_Bus_AssignedInfo.F_IsSure == 1)
                    {
                        using (TransactionScope trans = new TransactionScope())
                        {
                            #region 保存工单信息
                            modelT_Bus_WorkOrder.F_WorkState = 5;//延时审核中
                            workorderBLL.Update(modelT_Bus_WorkOrder);
                            #endregion

                            #region 插入申请延时信息
                            Model.T_Bus_DelayTime delay = new Model.T_Bus_DelayTime();
                            delay.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
                            //delay.F_State = state;
                            delay.F_OldTime = modelT_Bus_AssignedInfo.F_LimitTime;
                            delay.F_NewTime = newlimittime;
                            delay.F_Reason = reason;
                            delay.F_State = 1;
                            delay.F_IsAudit = 0;
                            delay.F_IsDelete = 0;
                            delay.F_AssignedId = modelT_Bus_AssignedInfo.F_Id;
                            delay.F_CreateUser = userModel.F_UserCode;
                            delay.F_CreateTime = DateTime.Now;

                            new BLL.T_Bus_DelayTime().Add(delay);
                            #endregion

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

                            string userinfo = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                            oper.F_Message = userinfo + " 申请了延时处理";
                            oper.F_CreateUser = userModel.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, userModel.F_UserCode);
                            #endregion

                            trans.Complete();
                        }
                        return Success("操作成功");
                    }
                    else
                    {
                        return Error("操作失敗，已查收");
                    }

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

        /// <summary>
        /// 审核延时工单
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult AuditDelayWorkOrder()
        {

            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXLD" || userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
            {
                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);
                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())
                        {
                            #region 保存工单信息
                            modelT_Bus_WorkOrder.F_WorkState = 4;//办理中
                            if (state == 1)
                            {
                                modelT_Bus_WorkOrder.F_LimitTime = newlimittime;
                            }
                            workorderBLL.Update(modelT_Bus_WorkOrder);
                            #endregion

                            #region 保存审核信息
                            modelT_Bus_DelayTime.F_IsAudit = state;//审核
                            modelT_Bus_DelayTime.F_AuditUser = userModel.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 = "同意";
                            if (modelT_Bus_DelayTime.F_IsAudit == 1)
                            {
                                #region 修改交办记录

                                modelT_Bus_AssignedInfo.F_LimitTime = modelT_Bus_DelayTime.F_AgreeTime;
                                assignBLL.Update(modelT_Bus_AssignedInfo);

                                #endregion
                            }
                            else
                            {
                                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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                            oper.F_Message = userinfo + " " + type + "了工单延时申请";
                            oper.F_CreateUser = userModel.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, userModel.F_UserCode);
                            #endregion

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

        /// <summary>
        /// 办理工单
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult FeedBackWorkOrder()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "WLDW" || userModel.F_RoleCode == "GLY")
            {
                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);
                Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                Model.T_Bus_Feedback model_T_Bus_Feedback = new Model.T_Bus_Feedback();
                int type = 0;
                if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo != null)
                {
                    type = AssignDeptType(modelT_Bus_AssignedInfo, userModel.F_DeptId);
                    if (type > 0)
                    {
                        if (modelT_Bus_WorkOrder.F_WorkState == 4)
                        {
                            using (TransactionScope trans = new TransactionScope())
                            {
                                if (feedbackid == 0)
                                {
                                    #region 插入反馈记录

                                    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_DealUser = dealman;
                                    model_T_Bus_Feedback.F_Result = result;//反馈内容
                                    model_T_Bus_Feedback.F_File = files;
                                    model_T_Bus_Feedback.F_IsAudit = 0;
                                    model_T_Bus_Feedback.F_IsDelete = 0;
                                    model_T_Bus_Feedback.F_CreateUser = userModel.F_UserCode;//办理人
                                    model_T_Bus_Feedback.F_CreateTime = DateTime.Now;//办理时间
                                    model_T_Bus_Feedback.F_CreateDeptId = userModel.F_DeptId;//办理部门
                                    model_T_Bus_Feedback.F_IsFeedEnd = 1;
                                    model_T_Bus_Feedback.F_State = state;
                                    model_T_Bus_Feedback.F_Type = type;

                                    new BLL.T_Bus_Feedback().Add(model_T_Bus_Feedback);
                                    #endregion
                                }
                                else
                                {
                                    #region 修改反馈记录
                                    model_T_Bus_Feedback = new BLL.T_Bus_Feedback().GetModel(feedbackid);
                                    if (model_T_Bus_Feedback != null)
                                    {
                                        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_DealUser = dealman;
                                        model_T_Bus_Feedback.F_Result = result;//反馈内容
                                        model_T_Bus_Feedback.F_File = files;

                                        model_T_Bus_Feedback.F_CreateUser = userModel.F_UserCode;//办理人
                                        model_T_Bus_Feedback.F_CreateTime = DateTime.Now;//办理时间
                                        model_T_Bus_Feedback.F_CreateDeptId = userModel.F_DeptId;//办理部门
                                        model_T_Bus_Feedback.F_IsFeedEnd = 1;
                                        model_T_Bus_Feedback.F_State = state;
                                        if (modelT_Bus_AssignedInfo.F_MainDeptId == userModel.F_DeptId)
                                        {
                                            model_T_Bus_Feedback.F_Type = 1;
                                        }
                                        else if (!string.IsNullOrEmpty(modelT_Bus_AssignedInfo.F_OtherDeptIds) && modelT_Bus_AssignedInfo.F_OtherDeptIds.Split(',').Contains(userModel.F_DeptId.ToString()))
                                        {
                                            model_T_Bus_Feedback.F_Type = 2;
                                        }

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

                                if (model_T_Bus_Feedback != null && model_T_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;//待回访
                                        modelT_Bus_WorkOrder.F_DealDeptId = userModel.F_DeptId;
                                        modelT_Bus_WorkOrder.F_DealUser = userModel.F_UserCode;
                                        modelT_Bus_WorkOrder.F_DealTime = DateTime.Now;
                                        modelT_Bus_WorkOrder.F_IsOverdue = iscs;
                                        modelT_Bus_WorkOrder.F_Result = result;
                                        workorderBLL.Update(modelT_Bus_WorkOrder);
                                        #endregion

                                        #region 保存交办信息
                                        modelT_Bus_AssignedInfo.F_FeedbackTime = DateTime.Now;
                                        modelT_Bus_AssignedInfo.F_IsOverdue = iscs;

                                        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='" + userModel.F_DeptId + "'");

                                        foreach (var cg in cglist)
                                        {
                                            cg.F_IsDelete = 1;
                                            cg.F_DeleteUser = userModel.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 = userModel.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='" + userModel.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='" + userModel.F_DeptId + "'");

                                        foreach (var cg in cglist)
                                        {
                                            cg.F_IsDelete = 1;
                                            cg.F_DeleteUser = userModel.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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                                    oper.F_Message = userinfo + " " + typemsg + "了工单";
                                    oper.F_CreateUser = userModel.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, userModel.F_UserCode);
                                    #endregion
                                }

                                trans.Complete();
                            }

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

        /// <summary>
        /// 回访工单
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult VisitWorkOrder()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXHWY" || userModel.F_RoleCode == "ZXBZ" || userModel.F_RoleCode == "GLY")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                string visituser = RequestString.GetFormString("visituser");//回访人
                int type = RequestString.GetInt("type", 0);//回访方式
                int issatisfie = RequestString.GetInt("issatisfie", 0);//0不满意 1满意
                                                                       //DateTime newlimittime = DateTime.Parse(RequestString.GetFormString("newlimittime"));//不满意，重办的办理时限
                int state = RequestString.GetInt("state", 0);//0保存 1保存并下一步
                int visitid = RequestString.GetInt("visitid", 0);
                string result = RequestString.GetFormString("result");//回访情况
                //int nexttype = RequestString.GetInt("nexttype", 0);//1重办 2结案
                //string overseeopinion = RequestString.GetFormString("overseeopinion");//督办意见
                //string finalopinion = RequestString.GetFormString("finalopinion");//结案意见

                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);
                Model.T_Bus_VisitResult modelT_Bus_VisitResult = new Model.T_Bus_VisitResult();

                if (modelT_Bus_WorkOrder != null)
                {
                    if (modelT_Bus_WorkOrder.F_WorkState == 6)
                    {
                        using (TransactionScope trans = new TransactionScope())
                        {
                            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_LimitTime = newlimittime;
                                modelT_Bus_VisitResult.F_IsDelete = 0;
                                modelT_Bus_VisitResult.F_CreateUser = userModel.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, userModel.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 = userModel.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, userModel.F_UserCode, guid);
                                }
                                #endregion
                            }

                            if (modelT_Bus_VisitResult != null && modelT_Bus_VisitResult.F_State == 1)
                            {
                                #region 保存交办信息
                                modelT_Bus_AssignedInfo.F_IsSatisfie = issatisfie;
                                assignBLL.Update(modelT_Bus_AssignedInfo);
                                #endregion

                                #region 保存工单信息
                                modelT_Bus_WorkOrder.F_WorkState = 7;//已回访
                                workorderBLL.Update(modelT_Bus_WorkOrder);
                                #endregion

                                #region 删除草稿信息
                                var cglist = new BLL.T_Bus_VisitResult().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 = userModel.F_UserCode;
                                    cg.F_DeleteTime = DateTime.Now;

                                    new BLL.T_Bus_VisitResult().Update(cg);
                                    //保存回访记录
                                    new BLL.T_Bus_VisitResultRecords().AddInfo(modelT_Bus_VisitResult, userModel.F_UserCode, guid);
                                }
                                #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_VisitResult.F_AssignedId;
                                oper.F_State = modelT_Bus_WorkOrder.F_WorkState;

                                string userinfo = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                                oper.F_Message = userinfo + " 回访了工单,结果：" + (issatisfie == 1 ? "满意" : "不满意");
                                oper.F_CreateUser = userModel.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, userModel.F_UserCode);
                                #endregion

                                #region 自动语音回访
                                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);
                                    }
                                }
                                #endregion
                            }

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

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

        /// <summary>
        /// 督办或监察工单
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult RemindWorkOrder()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            string workorderid = RequestString.GetFormString("workorderid");
            int type = RequestString.GetInt("type", 0);//1督办 2监察
            string overseeopinion = RequestString.GetFormString("overseeopinion");//督办意见
            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);
            if (modelT_Bus_WorkOrder != null && modelT_Bus_AssignedInfo != null)
            {
                using (TransactionScope trans = new TransactionScope())
                {
                    #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 = modelT_Bus_AssignedInfo.F_Id;
                    modelT_Bus_RemindRecord.F_Type = type;
                    modelT_Bus_RemindRecord.F_DeptId = modelT_Bus_AssignedInfo.F_MainDeptId;
                    modelT_Bus_RemindRecord.F_Content = overseeopinion;
                    modelT_Bus_RemindRecord.F_File = files;
                    modelT_Bus_RemindRecord.F_State = 1;
                    modelT_Bus_RemindRecord.F_IsDelete = 0;
                    modelT_Bus_RemindRecord.F_CreateUser = userModel.F_UserCode;
                    modelT_Bus_RemindRecord.F_CreateTime = DateTime.Now;

                    new BLL.T_Bus_RemindRecord().Add(modelT_Bus_RemindRecord);
                    #endregion

                    #region 插入操作记录
                    string typename = "督办";
                    if (type == 2) { typename = "监察"; }
                    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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                    oper.F_Message = userinfo + " " + typename + "了工单";
                    oper.F_CreateUser = userModel.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 ReloadWorkOrder()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXLD" || userModel.F_RoleCode == "ZXLDGLY" || userModel.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_WorkOrder.F_WorkState == 7)
                    {
                        using (TransactionScope trans = new TransactionScope())
                        {
                            #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;
                            if (modelT_Bus_AssignedInfo != null)//转办后重办
                            {
                                #region 插入交办记录
                                int n = Int32.Parse(DbHelperSQL.GetSingle("select count(1) from T_Bus_AssignedInfo 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());

                                modelT_Bus_WorkOrder.F_IsReload = n + 1;
                                modelT_Bus_WorkOrder.F_LimitTime = newlimittime;
                                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 = userModel.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 = userModel.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_Result = "";
                            modelT_Bus_WorkOrder.F_DealDeptId = null;
                            modelT_Bus_WorkOrder.F_DealUser = "";
                            modelT_Bus_WorkOrder.F_DealTime = null;
                            workorderBLL.Update(modelT_Bus_WorkOrder);
                            #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 = "";
                            var deptinfo = new BLL.T_Sys_Department().GetModel(modelT_Bus_AssignedInfo.F_MainDeptId.Value);
                            if (deptinfo != null) { deptname = deptinfo.F_DeptName; }
                            string userinfo = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                            oper.F_Message = userinfo + " 重办并督办了工单,交办单位：" + deptname;
                            oper.F_CreateUser = userModel.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, userModel.F_UserCode);
                            }
                            #endregion

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

        /// <summary>
        /// 结案工单
        /// </summary>
        /// <returns></returns>
        [Authority]
        public ActionResult FinishWorkOrder()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXLD" || userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
            {
                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");//通告原因

                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_WorkOrder.F_WorkState == 7)
                    {
                        using (TransactionScope trans = new TransactionScope())
                        {
                            #region 修改工单记录
                            modelT_Bus_WorkOrder.F_WorkState = 9;
                            modelT_Bus_WorkOrder.F_IsSatisfie = issatisfie;
                            modelT_Bus_WorkOrder.F_IsClosed = 1;
                            modelT_Bus_WorkOrder.F_CloseUser = userModel.F_UserCode;
                            modelT_Bus_WorkOrder.F_CloseTime = DateTime.Now;
                            modelT_Bus_WorkOrder.F_FinalOpinion = finalopinion;
                            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 = userModel.F_UserCode;
                                new BLL.T_Bus_NoticeCriticism().Add(modelT_Bus_NoticeCriticism);

                                modelT_Bus_AssignedInfo.F_IsNotice = 1;
                                modelT_Bus_AssignedInfo.F_NoticeUser = userModel.F_UserCode;
                                modelT_Bus_AssignedInfo.F_NoticeTime = DateTime.Now;
                                assignBLL.Update(modelT_Bus_AssignedInfo);

                                modelT_Bus_WorkOrder.F_IsNotice = 1;
                                modelT_Bus_WorkOrder.F_NoticeDeptIds = deptids;
                            }

                            workorderBLL.Update(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;

                            string userinfo = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.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);
                            }
                            oper.F_CreateUser = userModel.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()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXLD" || userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                string result = RequestString.GetFormString("result");//处理结果
                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");//通告原因

                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())
                    {
                        #region 修改工单记录
                        modelT_Bus_WorkOrder.F_Result = result;
                        modelT_Bus_WorkOrder.F_WorkState = 9;
                        modelT_Bus_WorkOrder.F_IsSatisfie = issatisfie;
                        modelT_Bus_WorkOrder.F_IsClosed = 1;
                        modelT_Bus_WorkOrder.F_CloseUser = userModel.F_UserCode;
                        modelT_Bus_WorkOrder.F_CloseTime = DateTime.Now;
                        modelT_Bus_WorkOrder.F_FinalOpinion = finalopinion;

                        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 = userModel.F_UserCode;
                            new BLL.T_Bus_NoticeCriticism().Add(modelT_Bus_NoticeCriticism);

                            if (modelT_Bus_AssignedInfo != null)
                            {
                                modelT_Bus_AssignedInfo.F_IsNotice = 1;
                                modelT_Bus_AssignedInfo.F_NoticeUser = userModel.F_UserCode;
                                modelT_Bus_AssignedInfo.F_NoticeTime = DateTime.Now;
                                assignBLL.Update(modelT_Bus_AssignedInfo);
                            }

                            modelT_Bus_WorkOrder.F_IsNotice = 1;
                            modelT_Bus_WorkOrder.F_NoticeDeptIds = deptids;
                        }

                        workorderBLL.Update(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;

                        string userinfo = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.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);
                        }
                        oper.F_CreateUser = userModel.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>
        public ActionResult DelWorkOrder(string[] ids)
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXHWY" || userModel.F_RoleCode == "ZXBZ" || userModel.F_RoleCode == "GLY")
            {

                //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 == 0)
                    {
                        using (TransactionScope trans = new TransactionScope())
                        {
                            #region 修改工单记录
                            modelT_Bus_WorkOrder.F_IsDelete = 1;
                            modelT_Bus_WorkOrder.F_DeleteUser = userModel.F_UserCode;
                            modelT_Bus_WorkOrder.F_DeleteTime = DateTime.Now;
                            workorderBLL.Update(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;

                            string userinfo = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                            oper.F_Message = userinfo + " 删除了工单";
                            oper.F_CreateUser = userModel.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()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXLD" || userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
            {
                string workorderid = RequestString.GetFormString("workorderid");
                int isrelease = RequestString.GetInt("isrelease", -1);
                if (isrelease != -1)
                {
                    Model.T_Bus_WorkOrder modelT_Bus_WorkOrder = workorderBLL.GetModel(workorderid);
                    if (modelT_Bus_WorkOrder != null)
                    {
                        using (TransactionScope trans = new TransactionScope())
                        {
                            #region 修改工单记录
                            modelT_Bus_WorkOrder.F_IsRelease = isrelease;
                            workorderBLL.Update(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;

                            string userinfo = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                            oper.F_Message = userinfo + " " + (isrelease == 1 ? "发布了" : "撤回了发布") + "工单";
                            oper.F_CreateUser = userModel.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 NoticeWorkOrder()
        //{
        //    int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

        //    Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

        //    if (userModel.F_RoleCode == "ZXLD" || userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
        //    {
        //        int assignid = RequestString.GetInt("id", 0);
        //        int isnotice = RequestString.GetInt("isnotice", -1);
        //        Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetModel(assignid);
        //        if (modelT_Bus_AssignedInfo != null)
        //        {
        //            if (isnotice == 0 && modelT_Bus_AssignedInfo.F_IsNotice == 1)
        //            {
        //                using (TransactionScope trans = new TransactionScope())
        //                {
        //                    #region 修改交办记录
        //                    modelT_Bus_AssignedInfo.F_IsNotice = 0;
        //                    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;

        //                    var deptinfo = new BLL.T_Sys_Department().GetModel(modelT_Bus_AssignedInfo.F_MainDeptId.Value);
        //                    string userinfo = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
        //                    oper.F_Message = userinfo + " 撤销了通告交办单位：" + (deptinfo != null ? deptinfo.F_DeptName : "");
        //                    oper.F_CreateUser = userModel.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_AssignedInfo.F_IsNotice == 0)
        //            {
        //                using (TransactionScope trans = new TransactionScope())
        //                {
        //                    #region 修改交办记录
        //                    modelT_Bus_AssignedInfo.F_IsNotice = 1;
        //                    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;

        //                    var deptinfo = new BLL.T_Sys_Department().GetModel(modelT_Bus_AssignedInfo.F_MainDeptId.Value);
        //                    string userinfo = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
        //                    oper.F_Message = userinfo + " 通告了交办单位：" + (deptinfo != null ? deptinfo.F_DeptName : "");
        //                    oper.F_CreateUser = userModel.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 NoticeWorkOrder()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXLD" || userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
            {
                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);
                Model.T_Bus_AssignedInfo modelT_Bus_AssignedInfo = assignBLL.GetNewModelByWorkOrderID(workorderid);
                if (modelT_Bus_WorkOrder != null)
                {
                    if (isnotice == 0 && modelT_Bus_WorkOrder.F_IsNotice == 1)
                    {
                        using (TransactionScope trans = new TransactionScope())
                        {
                            #region 修改工单记录
                            modelT_Bus_WorkOrder.F_IsNotice = 0;
                            modelT_Bus_WorkOrder.F_NoticeDeptIds = "";

                            workorderBLL.Update(modelT_Bus_WorkOrder);
                            #endregion

                            if (modelT_Bus_AssignedInfo != null)
                            {
                                #region 修改交办记录
                                modelT_Bus_AssignedInfo.F_IsNotice = 0;
                                modelT_Bus_AssignedInfo.F_NoticeUser = userModel.F_UserCode;
                                modelT_Bus_AssignedInfo.F_NoticeTime = DateTime.Now;
                                assignBLL.Update(modelT_Bus_AssignedInfo);
                                #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 = userModel.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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                            oper.F_Message = userinfo + " 撤销了通告交办单位：" + DbHelperSQL.GetSingle(sql).ToString();
                            oper.F_CreateUser = userModel.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())
                        {
                            #region 修改工单记录
                            modelT_Bus_WorkOrder.F_IsNotice = 1;
                            modelT_Bus_WorkOrder.F_NoticeDeptIds = deptids;
                            workorderBLL.Update(modelT_Bus_WorkOrder);
                            #endregion

                            if (modelT_Bus_AssignedInfo != null)
                            {
                                #region 修改交办记录
                                modelT_Bus_AssignedInfo.F_IsNotice = 1;
                                modelT_Bus_AssignedInfo.F_NoticeUser = userModel.F_UserCode;
                                modelT_Bus_AssignedInfo.F_NoticeTime = DateTime.Now;
                                assignBLL.Update(modelT_Bus_AssignedInfo);
                                #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 = userModel.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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                            oper.F_Message = userinfo + " 通告了交办单位：" + DbHelperSQL.GetSingle(sql).ToString();
                            oper.F_CreateUser = userModel.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()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);

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

                    #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 = userModel.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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                    oper.F_Message = userinfo + " 接到市民催单，内容：" + content;
                    oper.F_CreateUser = userModel.F_UserCode;
                    oper.F_CreateTime = DateTime.Now;
                    oper.F_IsDelete = 0;

                    operBLL.Add(oper);
                    #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;
            var liuyan = new BLL.T_Call_LeaveRecord().GetModelList(" F_Id='" + lid + "' ").FirstOrDefault();
            if (liuyan != null)
            {
                if (!string.IsNullOrEmpty(liuyan.F_RecFileUrl))
                {
                    path = prefix + liuyan.F_RecFileUrl;
                }
            }
            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;
            var luyin = new BLL.T_Call_CallRecords().GetModelList(" CallRecordsId='" + cid + "' ").FirstOrDefault();
            if (luyin != null)
            {
                if (!string.IsNullOrEmpty(luyin.FilePath))
                {
                    var ym = prefix;
                    ym = ym.Substring(0, ym.Length - 1);
                    path = ym + luyin.FilePath.Substring(luyin.FilePath.IndexOf(':') + 1).Replace('\\', '/');
                }
            }
            return path;
        }

        /// <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 where F_FileId in (" + ids + ")").Tables[0];

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

            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)
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
            {
                //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;
                    case 6: table = "T_Bus_VisitResult"; break;
                }

                string sql = "select * from " + table + " 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()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
            {
                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())
                    {
                        #region 保存工单信息

                        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;

                        workorderBLL.Update(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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                        oper.F_Message = userinfo + " 修改了工单基本信息";
                        oper.F_CreateUser = userModel.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()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
            {
                //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())
                    {
                        #region 保存批示信息

                        //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;//附件

                        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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                        oper.F_Message = userinfo + " 修改了工单批示信息";
                        oper.F_CreateUser = userModel.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()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
            {
                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())
                    {
                        #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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                        oper.F_Message = userinfo + " 修改了工单交办信息";
                        oper.F_CreateUser = userModel.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()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
            {
                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())
                    {
                        #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 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);
                            order.F_Result = result;//反馈内容

                            workorderBLL.Update(order);
                        }
                        #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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                        oper.F_Message = userinfo + " 修改了工单办理信息";
                        oper.F_CreateUser = userModel.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()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
            {
                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())
                    {
                        #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, userModel.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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                        oper.F_Message = userinfo + " 修改了工单回访信息";
                        oper.F_CreateUser = userModel.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()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
            {
                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())
                    {
                        #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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                        oper.F_Message = userinfo + " 修改了工单退回审核信息";
                        oper.F_CreateUser = userModel.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()
        {
            int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);

            Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);

            if (userModel.F_RoleCode == "ZXLDGLY" || userModel.F_RoleCode == "GLY")
            {
                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())
                    {
                        #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 = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
                        oper.F_Message = userinfo + " 修改了工单延时审核信息";
                        oper.F_CreateUser = userModel.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

    }
}