using CallCenter.Utility;
using CallCenterApi.Common;
using CallCenterApi.DB;
using CallCenterApi.Interface.Controllers.Base;
using CallCenterApi.Interface.Models.Enum;
using CallCenterApi.Model;
using CallCenterAPI.WechatSDK;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;

namespace CallCenterApi.Interface.Controllers.workorder
{
    public class WorkOrderController : BaseController
    {
        BLL.T_Wo_WorkOrder_Logs blllogs = new BLL.T_Wo_WorkOrder_Logs();
        BLL.T_Wo_WorkOrder bll = new BLL.T_Wo_WorkOrder();
        BLL.T_Wo_WorkOrderItem_New itembll = new BLL.T_Wo_WorkOrderItem_New();
        BLL.T_Sys_UserAccount sysUserAccountBll = new BLL.T_Sys_UserAccount();
        BLL.T_Sys_Department sysDeptBll = new BLL.T_Sys_Department();
        BLL.T_Sys_DictionaryValue dicvalueBll = new BLL.T_Sys_DictionaryValue();

        BLL.T_Wo_QuestionManage quesBLL = new BLL.T_Wo_QuestionManage();


        #region 操作
        //分配
        //接单
        //处理
        //退回
        //异常退回
        //延期
        #endregion

        #region 质量管理部 id=12
        //根据工单id获取工单类型 根据类型区别提交处理

        //分配
        //"展示：工单编号、工单来源、工单类型、客户姓名、电话、问题描述
        //投诉类、咨询类、需求类字段：
        //点选：质量事件等级（未遂、一般、较大、重大）
        //手输：索赔金额（单位元，对应责任单位）
        //点选：责任单位（需列出，可选多个）
        //点选：审批意见（同意、不同意，若选择不同意，增加输入框输入补充内容）
        //点选：补偿方式（实物、钱款【单位元】，若选择钱款，增加输入框输入补充内容）
        //处理内容：输入框
        //点选：处理结果（已处理，未处理）若点选未处理，则弹出点选：未处理原因（资金、技术、人员、其他（若选其他，则手输））
        //下拉：对应责任单位（生产、研发、农化、物流、质量管理科，销售内勤）
        //手输：确认实收数量（吨）
        //手输：改进要求
        //手输：对应审批工作流单号
        //抽检类字段：
        //点选：未备案、已备案
        //公共字段：
        //点选：是否建议回访（是，否）此项若选是，则流转到客服-待回访工单，若选否，则流转至客服待完结工单
        //手输：索赔金额（单位：元）
        //按钮：申请关闭工单
        //接收部门：
        //接收人：
        //超时时限：
        //短信提醒：1、您有一条新的工单，工单编号为：xxx，请尽快处理！（默认为接收人电话）2、抄送给业务员：您好！X月X日发起的XXX号投诉工单，质量管理部已处理，详情可通过微信端口/PC查看！）（业务员联系方式从客户编码所对应业务员联系方式获取，如果没有则不发送短信）
        //确定（按钮）"

        //处理
        //"展示：工单编号、工单来源、工单类型、客户姓名、电话、问题描述
        //投诉类、咨询类、需求类字段：
        //点选：质量事件等级（未遂、一般、较大、重大）
        //手输：索赔金额（单位元，对应责任单位）
        //点选：责任单位（需列出，可选多个）
        //点选：审批意见（同意、不同意，若选择不同意，增加输入框输入补充内容）
        //点选：补偿方式（实物、钱款【单位元】，若选择钱款，增加输入框输入补充内容）
        //处理内容：输入框
        //点选：处理结果（已处理，未处理）若点选未处理，则弹出点选：未处理原因（资金、技术、人员、其他（若选其他，则手输））
        //下拉：对应责任单位（生产、研发、农化、物流、质量管理科，销售内勤）
        //手输：确认实收数量（吨）
        //手输：改进要求
        //手输：对应审批工作流单号
        //抽检类字段：
        //点选：未备案、已备案
        //公共字段：
        //点选：是否建议回访（是，否）此项若选是，则流转到客服-待回访工单，若选否，则流转至客服待完结工单
        //手输：索赔金额（单位：元）
        //按钮：申请关闭工单
        //短信提醒：抄送给业务员：您好！X月X日发起的XXX号投诉工单，质量管理部已处理，详情可通过微信端口/PC查看！）（业务员联系方式从客户编码所对应业务员联系方式获取，如果没有则不发送短信）
        //确定（按钮）"

        #endregion

        #region 市场管理科 id=37
        //分配
        //"展示：工单编号、工单来源、工单类型、客户姓名、电话、问题描述
        //点选：生产基地（新乡、新疆、九江、东北、贴牌、无法确定）
        //投诉类、咨询类、需求类填写以下字段：
        //自动获取：超出质保期限（算法：工单创建日期-生产日期，生产日期根据生产批次号获取，单位：月）
        //点选：初审意见（退货、换货、补偿、自行处理）
        //处理内容：输入框
        //点选：处理结果（已处理，未处理）若点选未处理，则弹出点选：未处理原因（资金、技术、人员、其他（若选其他，则手输））
        //抽检类填写以下字段：
        //点选：抽检结果（视同合格、合格、不合格、复检后合格、未送检）
        //手输：自检结果
        //手输：对应审批工作流单号
        //手输：确认返账金额（元）
        //公共字段：
        //接收部门：
        //接收人：
        //超时时限：
        //短信提醒：1、您有一条新的工单，工单编号为：xxx，请尽快处理！（默认为接收人电话）2、抄送给业务员：您好！X月X日发起的XXX号投诉工单，质量管理部已处理，详情可通过微信端口/PC查看！）（业务员联系方式从客户编码所对应业务员联系方式获取，如果没有则不发送短信）
        //确定（按钮）"

        //处理
        //"展示：工单编号、工单来源、工单类型、客户姓名、电话、问题描述
        //点选：生产基地（新乡、新疆、九江、东北、贴牌、无法确定）
        //自动获取：超出质保期限（算法：工单创建日期-生产日期，生产日期根据生产批次号获取，单位：月）
        //点选：初审意见（退货、换货、补偿、自行处理）
        //短信提醒：抄送给业务员：您好！X月X日发起的XXX号投诉工单，质量管理部已处理，详情可通过微信端口/PC查看！）（业务员联系方式从客户编码所对应业务员联系方式获取，如果没有则不发送短信）
        //处理内容：输入框
        //点选：处理结果（已处理，未处理）若点选未处理，则弹出点选：未处理原因（资金、技术、人员、其他（若选其他，则手输））
        //处理状态：完结、未完结（点选）
        //确定（按钮）"

        #endregion
        #region 生产批次号
        /// <summary>
        /// 根据生产批次号获取超出质保期限
        /// 质保期限以月为单位
        /// </summary>
        /// <param name="BatchNumber">生产批次号</param>
        /// <param name="createtime">工单创建时间</param>
        public int GetProTime(string BatchNumber,DateTime createtime)
        {
            //生产批次号截取前六位日期
            var prono = BatchNumber.Substring(0, 6);
            //转为生产日期格式
            var pronos = DateTime.ParseExact(prono, "yyMMdd", null).ToString("yyyy-MM-dd");
            var protime = Convert.ToDateTime(pronos);
            TimeSpan ts = createtime - protime;
            var days = ts.TotalDays;
            var month = (int)Math.Ceiling((days / 30));//以30天为一月计算几个月并且有余数取整
            return month;
        }
        #endregion
        #region 读取问题类别
        public ActionResult GetQuestionNameType(int type = 0, string QuestionName = "")
        {
            DataTable dt = new DataTable();
            var sql = "and F_IsDelete=0";
            if (QuestionName != "")
            {
                var Question = quesBLL.GetModel(QuestionName);
                sql += "  and F_ParentId=" + Question.F_Id;
            }
            else
            {
                sql += "  and F_ParentId=" + 0;
            }
            if (type == (int)EnumWOType.Complaint)//投诉
                sql += " and F_Type='" + EnumWOType.Complaint.ToString() + "'";
            if (type == (int)EnumWOType.ConsultingNeeds)//咨询及需求
                sql += " and F_Type='" + EnumWOType.ConsultingNeeds.ToString() + "'";
            if (type == (int)EnumWOType.SpotCheck)//抽检
                sql += " and F_Type='" + EnumWOType.SpotCheck.ToString() + "'";
            int recordCount = 0;

         
            if (QuestionName == "" && type == (int)EnumWOType.Complaint)
            {

                dt = BLL.PagerBLL.GetListPager(
                       "T_Wo_QuestionManage",
                       "F_ID",
                       "*",
                       sql,
                       "ORDER BY T_Wo_QuestionManage.F_ID desc",
                       10000,
                       1,
                       true,
                       out recordCount);
            }
            else
            {
                dt = BLL.PagerBLL.GetListPager(
                      "T_Wo_QuestionManage",
                      "F_ID",
                      "*",
                      sql,
                      "ORDER BY T_Wo_QuestionManage.F_ID ",
                      10000,
                      1,
                      true,
                      out recordCount);
            }

            List<Model.TreeModel> modelList = BindTree(dt, "0");
            if (modelList != null)
            {
                if (modelList.Count > 0)
                    return Success("加载成功", modelList);
            }
            return Error("加载失败");
        }
        public ActionResult GetQuestionName()
        {
            DataTable dt = new DataTable();
            var sql = "and F_IsDelete=0";
            sql += "and  F_Label=3";
            int recordCount = 0;
            dt = BLL.PagerBLL.GetListPager(
                       "T_Wo_QuestionManage",
                       "F_ID",
                       "*",
                       sql,
                      "ORDER BY T_Wo_QuestionManage.F_ID desc",
                       10000,
                       1,
                       true,
                       out recordCount);

            List<Model.T_Wo_QuestionManage> modelList = new BLL.T_Wo_QuestionManage().DataTableToList(dt);
            if (modelList != null)
            {
                if (modelList.Count > 0)
                    return Success("加载成功", modelList);
            }
            return Error("加载失败");
        }
        public ActionResult GetQuestionType(int type = 0,int pid=0)
        {
            DataTable dt = new DataTable();
            var sql = "and F_IsDelete=0";
                sql += "  and F_ParentId=" + pid;
            if (type == (int)EnumWOType.Complaint)//投诉
                sql += " and F_Type='" + EnumWOType.Complaint.ToString() + "'";
            if (type == (int)EnumWOType.ConsultingNeeds)//咨询及需求
                sql += " and F_Type='" + EnumWOType.ConsultingNeeds.ToString() + "'";
            if (type == (int)EnumWOType.SpotCheck)//抽检
                sql += " and F_Type='" + EnumWOType.SpotCheck.ToString() + "'";
            int recordCount = 0;
            if (pid == 0 && type == (int)EnumWOType.Complaint)
            {
                if (!string.IsNullOrWhiteSpace(sql))
                {

                    dt = BLL.PagerBLL.GetListPager(
                        "T_Wo_QuestionManage",
                        "F_ID",
                        "*",
                        sql,
                        "ORDER BY T_Wo_QuestionManage.F_ID desc",
                        10000,
                        1,
                        true,
                        out recordCount);
                }
            }
            else
            {
                dt = BLL.PagerBLL.GetListPager(
                      "T_Wo_QuestionManage",
                      "F_ID",
                      "*",
                      sql,
                      "ORDER BY T_Wo_QuestionManage.F_ID ",
                      10000,
                      1,
                      true,
                      out recordCount);
            }

            List<Model.TreeModel> modelList = BindTree(dt, "0");
            if (modelList != null)
            {
                if (modelList.Count > 0)
                    return Success("加载成功", modelList);
            }
            return Error("加载失败");
        }
        /// <summary>
        /// tree  树形部门
        /// </summary>
        /// <param name="tab"></param>
        /// <param name="parentid"></param>
        /// <returns></returns>
        private List<Model.TreeModel> BindTree(DataTable tab, string parentid)
        {
            DataTable tab2 = new DataTable();

            if (tab != null && tab.Rows.Count > 0)
            {
                List<Model.T_Wo_QuestionManage> categorylist = quesBLL.DataTableToList(tab);
                List<Model.TreeModel> modelList = new List<Model.TreeModel>(categorylist.Count);
                for (int i = 0; i < categorylist.Count; i++)
                {
                    Model.TreeModel model = new Model.TreeModel();
                    string currentID = categorylist[i].F_Id.ToString();//当前功能ID
                    model.id = currentID;
                    model.code = "";
                    model.IconCls = "";//图标
                    model.text = categorylist[i].F_QuestionName;
                    model.headerid = categorylist[i].F_ParentId ?? 0;   
                    tab2 = new BLL.T_Wo_QuestionManage().GetList("F_ParentId=" + currentID + " and F_IsDelete=0 ").Tables[0];
                    if (tab2 != null && tab2.Rows.Count > 0)
                    {
                        model.children = BindTree(tab2, currentID);
                    }
                    modelList.Add(model);
                }
                return modelList;

            }
            else
            {
                return null;
            }

        }
        #endregion
        //#region 工单状态
        //public ActionResult GetWorkState()
        //{
        //    var res = new BLL.T_Sys_DictionaryValue().GetModelList("F_DictionaryFlag='GDZT'");
        //    return Success("获取工单状态成功！", res);
        //}
        //#endregion

        //#region 工单
        ///// <summary>
        ///// 获取工单列表
        ///// </summary>
        ///// <returns></returns>
        //public ActionResult GetListAll()
        //{
        //    string sql = " and isdel=0 ";
        //    DataTable dt = new DataTable();

        //    string strorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("orderid"));
        //    string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
        //    string strtype = HttpUtility.UrlDecode(RequestString.GetQueryString("type"));
        //    string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
        //    //来电号码
        //    string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
        //    string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
        //    //坐席工号
        //    string strcode = HttpUtility.UrlDecode(RequestString.GetQueryString("code"));
        //    //起止时间
        //    string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
        //    string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));

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

        //    if (strorderid.Trim() != "" && strorderid != "undefined")
        //    {
        //        sql += " and WorkOrderID like '%" + strorderid.Trim() + "%' ";
        //    }
        //    if (strstate.Trim() != "" && strstate != "undefined")
        //    {
        //        sql += " and State = '" + strstate.Trim() + "' ";
        //    }
        //    if (strtype.Trim() != "" && strtype != "undefined")
        //    {
        //        sql += " and Type = '" + strtype.Trim() + "' ";
        //    }
        //    if (strkey.Trim() != "" && strkey != "undefined")
        //    {
        //        sql += " and Detail like '%" + strkey.Trim() + "%' ";
        //    }
        //    if (strcode.Trim() != "" && strcode != "undefined")
        //    {
        //        sql += " and CreateUser = '" + strcode.Trim() + "' ";
        //    }
        //    if (strname.Trim() != "" && strname != "undefined")
        //    {
        //        sql += " and Customer like '%" + strname.Trim() + "%' ";
        //    }
        //    if (strtel.Trim() != "" && strtel != "undefined")
        //    {
        //        sql += " and CustomerTel like '%" + strtel + "%'  ";
        //    }
        //    if (strstarttime.Trim() != "" && strstarttime != "undefined")
        //    {
        //        sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
        //    }
        //    if (strendtime.Trim() != "" && strendtime != "undefined")
        //    {
        //        sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0   ";
        //    }

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

        //    if (strpagesize.Trim() != "")
        //    {
        //        pagesize = Convert.ToInt32(strpagesize);
        //    }
        //    int recordCount = 0;
        //    dt = BLL.PagerBLL.GetListPager(
        //        "T_Wo_WorkOrder",
        //        "T_Wo_WorkOrder.ID",
        //        "*,dbo.GetDictionaryName(source) as SourceName,dbo.GetDictionaryName(Type) as TypeName,dbo.GetDictionaryName(TypeClass) as TypeClassName,dbo.GetUserName(CreateUser) as CreateUserName, dbo.GetDeptName(ResponDept) as ResponDeptName,dbo.GetUserName(ResponUser) as ResponUserName,convert(decimal(18,2),DATEDIFF(minute, CreateTime, ISNULL(LastDealTime, GETDATE()))/60.00) as totalhour",
        //        sql,
        //        "ORDER BY T_Wo_WorkOrder.ID desc",
        //        pagesize,
        //        pageindex,
        //        true,
        //        out recordCount);
        //    dt.Columns.Add("CLDeptName", typeof(String));
        //    dt.Columns.Add("CLUserName", typeof(String));
        //    foreach (DataRow dr in dt.Rows)
        //    {
        //        string sqlitem = "select top 1 dbo.GetUserName(F_NextUser) as ToUserName, dbo.GetDeptName(F_NextDept) as ToDeptName from T_Wo_WorkOrderItem_New where F_WoID ='" + dr["ID"].ToString() + "' and F_ItemType=" + (int)EnumItemType.deal + " and F_IsUsed = 0 order by F_CreateTime desc";
        //        var item = DbHelperSQL.Query(sqlitem).Tables[0];
        //        if (item.Rows.Count > 0)
        //        {
        //            dr["CLUserName"] = item.Rows[0]["ToUserName"].ToString();
        //            dr["CLDeptName"] = item.Rows[0]["ToDeptName"].ToString();
        //        }
        //    }

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

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

        ///// <summary>
        ///// 获取工单列表
        ///// </summary>
        ///// <returns></returns>
        //public ActionResult GetList()
        //{
        //    string sql = " and isdel=0 ";
        //    DataTable dt = new DataTable();
        //    int userId = CurrentUser.UserData.F_UserId;
        //    var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='TimeLimitDays' ").FirstOrDefault();
        //    int days = config != null ? Convert.ToInt32(config.F_ParamValue) : 60;  //默认60天
        //    if (userId != 0)
        //    {
        //        Model.T_Sys_UserAccount ua = sysUserAccountBll.GetModel(userId);
        //        if (ua != null)
        //        {
        //            //客户姓名,电话,房间号,工单号，接待描述
        //            string keyword = HttpUtility.UrlDecode(RequestString.GetQueryString("keyword"));
        //            //工单状态(ltype:)
        //            string strltype = HttpUtility.UrlDecode(RequestString.GetQueryString("ltype"));
        //            //工单状态
        //            int states = RequestString.GetInt("states", -1);
        //            //工单来源
        //            int strsource = RequestString.GetInt("source", 0);
        //            //工单类型
        //            int strtype = RequestString.GetInt("type", 0);
        //            //业务类型
        //            int strtypeclass = RequestString.GetInt("typeclass", 0);
        //            //工单起止时间
        //            string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
        //            string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));

        //            //微信列表（0未审核微信列表，1已审核微信列表）
        //            int isaudit = RequestString.GetInt("isaudit", -1);
        //            //坐席工号
        //            string uid = HttpUtility.UrlDecode(RequestString.GetQueryString("userid") == "" ? "0" : HttpUtility.UrlDecode(RequestString.GetQueryString("userid")));
        //            string strpageindex = RequestString.GetQueryString("page");
        //            int pageindex = 1;
        //            string strpagesize = RequestString.GetQueryString("pagesize");
        //            int pagesize = 10;

        //            //客户姓名,电话,工单号，接待描述
        //            if (!string.IsNullOrEmpty(keyword))
        //            {
        //                sql += " and (CustomerTel like '%" + keyword + "%' or Customer like '%" + keyword + "%' or Address like '%" + keyword + "%' or WorkOrderID like '%" + keyword + "%' or Detail like '%" + keyword + "%' ) ";
        //            }
        //            string uwhere = " ";
        //            //客服部根据工单状态判断是否加旗标，工程部根据备注
        //            switch (strltype)
        //            {
        //                case "0"://待指派的
        //                         //sql += " and State ='0' and CreateUser= '" + ua.F_UserCode + "' ";
        //                         //3区域客服可以看到区域待指派工单
        //                    if (ua.F_RoleId != 17)
        //                    {
        //                        uwhere += " and CreateUser='" + ua.F_UserCode + "' ";
        //                    }
        //                    sql += " and State =" + (int)EnumWorkOrderState.neworder + " " + uwhere;
        //                    break;
        //                case "1"://待接单的
        //                    sql += " and State ="+ (int)EnumWorkOrderState.assign + " and T_Wo_WorkOrder.ID in ( " + GetDJDWorkOrderID(ua.F_UserCode) + ") ";
        //                    break;
        //                case "2"://待完成的(待处理)
        //                    sql += " and State in(" + (int)EnumWorkOrderState.dealing + "," + (int)EnumWorkOrderState.receive + "," + (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + ") and T_Wo_WorkOrder.ID in ( " + GetDWCWorkOrderID(ua.F_UserCode) + ") ";
        //                    break;
        //                case "3"://已完成的
        //                    sql += " and State ="+ (int)EnumWorkOrderState.finish + " and LastDealUser = '" + ua.F_UserCode + "' ";
        //                    break;
        //                case "4"://我参与的
        //                    sql += " and (CreateUser= '" + ua.F_UserCode + "' or T_Wo_WorkOrder.ID in ( " + GetCYWorkOrderID(ua.F_UserCode) + ")) ";
        //                    break;
        //                case "5"://超期工单 - 设置两个月的处理时效，两个月内未解决的工单都直接汇总到这里
        //                    sql += $" and DATEADD(DAY,{days},CreateTime) < GETDATE() AND State < " + (int)EnumWorkOrderState.finish + " ";
        //                    break;
        //            }
        //            if (isaudit >= 0)
        //            {
        //                sql += " and IsAudit = " + isaudit + " "; 
        //            }
        //            if (states >= 0)
        //                sql += " and State = " + states + " ";
        //            if (strsource > 0)
        //            {
        //                sql += " and Source = '" + strsource + "' ";
        //            }
        //            if (strtype > 0)
        //            {
        //                sql += " and Type = " + strtype + " ";
        //            }
        //            if (strtypeclass > 0)
        //            {
        //                sql += " and TypeClass = " + strtypeclass + " ";
        //            }
        //            if (strstarttime.Trim() != "" && strstarttime != "undefined")
        //            {
        //                sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
        //            }
        //            if (strendtime.Trim() != "" && strendtime != "undefined")
        //            {
        //                sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0   ";
        //            }
        //            if (strpageindex.Trim() != "")
        //            {
        //                pageindex = Convert.ToInt32(strpageindex);
        //            }

        //            if (strpagesize.Trim() != "")
        //            {
        //                pagesize = Convert.ToInt32(strpagesize);
        //            }
        //            int recordCount = 0;
        //            dt = BLL.PagerBLL.GetListPager(
        //                "T_Wo_WorkOrder",
        //                "T_Wo_WorkOrder.ID",
        //                "*,dbo.GetDictionaryName(Source) as GDLYName,dbo.GetDictionaryName(Type) as GDLXName,dbo.GetDictionaryName(TypeClass) as TypeClassName,dbo.GetUserName(CreateUser) as CreateUserNameRel,dbo.GetUserName(LastDealUser) as LastDealUserNameRel,dbo.GetUserName(AuditUser) as AuditUserNameRel, dbo.GetDeptName(ResponDept) as ResponDeptName,dbo.GetUserName(ResponUser) as ResponUserName,convert(decimal(18,2),DATEDIFF(minute, CreateTime, ISNULL(LastDealTime, GETDATE()))/60.00) as totalhour,GETDATE() as nowTime",
        //                sql,
        //                "ORDER BY T_Wo_WorkOrder.ID desc",
        //                pagesize,
        //                pageindex,
        //                true,
        //                out recordCount);
        //            dt.Columns.Add("CBCount", typeof(int));
        //            dt.Columns.Add("TimeoutTime", typeof(string));
        //            foreach (DataRow dr in dt.Rows)
        //            {
        //                var list = itembll.GetList(" F_WoID ='" + dr["ID"].ToString() + "' and F_ItemType=" + (int)EnumItemType.urge + " ").Tables[0];
        //                dr["CBCount"] = list.Rows.Count;
        //                dr["TimeoutTime"] = DateTimeConvert.DateDiff(Convert.ToDateTime(dr["CreateTime"]).AddDays(days), Convert.ToDateTime(dr["nowTime"]));
        //            }

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

        //            return Content(obj.ToJson());
        //        }
        //    }
        //    return Error("获取失败");
        //}

        ///// <summary>
        ///// 获取可催办工单列表
        ///// </summary>
        ///// <returns></returns>
        //public ActionResult GetNotDoneWorkList()
        //{
        //    ActionResult res = NoToken("未知错误，请重新登录");
        //    if (Request.IsAuthenticated)
        //    {
        //        string sql = " and isdel=0 and State != " + (int)EnumWorkOrderState.finish;
        //           // + " and T_Wo_WorkOrder.ID not in (select F_WoID from T_Wo_WorkOrderItem_New where F_ItemType=" + (int)EnumItemType.urge + " and isnull(F_IsUsed,'0')='0')";
        //        //string sql = " and isdel=0 and State = 1 ";
        //        DataTable dt = new DataTable();

        //        int userId = CurrentUser.UserData.F_UserId;

        //        if (userId != 0)
        //        {
        //            Model.T_Sys_UserAccount ua = sysUserAccountBll.GetModel(userId);
        //            if (ua != null)
        //            {
        //                //客户姓名,电话,房间号,工单号
        //                string keyword = HttpUtility.UrlDecode(RequestString.GetQueryString("keyword"));
        //                //工单状态
        //                string strltype = HttpUtility.UrlDecode(RequestString.GetQueryString("ltype"));
        //                //工单状态
        //                int states = RequestString.GetInt("states", -1);
        //                //工单来源
        //                int strsource = RequestString.GetInt("source", 0);
        //                //工单类型
        //                int strtype = RequestString.GetInt("type", 0);
        //                int strtypeclass = RequestString.GetInt("typeclass", 0);
        //                //工单起止时间
        //                string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
        //                string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
        //                //坐席工号
        //                string uid = HttpUtility.UrlDecode(RequestString.GetQueryString("userid") == "" ? "0" : HttpUtility.UrlDecode(RequestString.GetQueryString("userid")));
        //                string strpageindex = RequestString.GetQueryString("page");
        //                int pageindex = 1;
        //                string strpagesize = RequestString.GetQueryString("pagesize");
        //                int pagesize = 10;

        //                //客户姓名,电话,工单号
        //                if (!string.IsNullOrEmpty(keyword))
        //                {
        //                    sql += " and (CustomerTel like '%" + keyword + "%' or Customer like '%" + keyword + "%' or WorkOrderID like '%" + keyword + "%' ) ";
        //                }
        //                if (states >= 0)
        //                    sql += " and State = " + states + " ";
        //                //坐席工号
        //                if (uid.Trim() != "" && uid != "0")
        //                {
        //                    sql += " and CreateUser = '" + uid + "' ";
        //                }
        //                if (strsource > 0)
        //                    sql += " and Source = " + strsource + " ";
        //                if (strtype > 0)
        //                {
        //                    sql += " and Type = " + strtype + " ";
        //                }
        //                if (strtypeclass > 0)
        //                {
        //                    sql += " and TypeClass = " + strtype + " ";
        //                }
        //                if (strstarttime.Trim() != "" && strstarttime != "undefined")
        //                {
        //                    sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
        //                }
        //                if (strendtime.Trim() != "" && strendtime != "undefined")
        //                {
        //                    sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0   ";
        //                }
        //                if (strpageindex.Trim() != "")
        //                {
        //                    pageindex = Convert.ToInt32(strpageindex);
        //                }

        //                if (strpagesize.Trim() != "")
        //                {
        //                    pagesize = Convert.ToInt32(strpagesize);
        //                }
        //                int recordCount = 0;
        //                dt = BLL.PagerBLL.GetListPager(
        //                    "T_Wo_WorkOrder",
        //                    "T_Wo_WorkOrder.ID",
        //                    "*,dbo.GetDictionaryName(Source) as GDLYName,dbo.GetDictionaryName(Type) as GDLXName,dbo.GetDictionaryName(TypeClass) as TypeClassName,dbo.GetUserName(CreateUser) as CreateUserNameRel,dbo.GetUserName(LastDealUser) as LastDealUserNameRel,dbo.GetUserName(AuditUser) as AuditUserNameRel",
        //                    sql,
        //                    "ORDER BY T_Wo_WorkOrder.ID desc",
        //                    pagesize,
        //                    pageindex,
        //                    true,
        //                    out recordCount);
        //                dt.Columns.Add("CBCount", typeof(int));
        //                foreach (DataRow dr in dt.Rows)
        //                {
        //                    var list = itembll.GetList(" F_WoID ='" + dr["ID"].ToString() + "' and F_ItemType=" + (int)EnumItemType.urge).Tables[0];
        //                    dr["CBCount"] = list.Rows.Count;
        //                }

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

        //                res = Content(obj.ToJson());
        //            }
        //        }
        //    }
        //    return res;
        //}

        ///// <summary>
        ///// 获取待接单的工单编号
        ///// </summary>
        ///// <returns></returns>
        //public string GetDJDWorkOrderID(string user)
        //{
        //    string str = string.Empty;
        //    str = "select F_WoID from T_Wo_WorkOrderItem_New where F_ItemType=" + (int)EnumItemType.deal 
        //        + " and F_WoState="+ (int)EnumWorkOrderState.assign
        //        + " and isnull(F_IsUsed,'0')='0' and F_NextUser='" + user + "' ";

        //    return str;
        //}

        ///// <summary>
        ///// 获取待完成的工单编号
        ///// </summary>
        ///// <returns></returns>
        //public string GetDWCWorkOrderID(string user)
        //{
        //    string str = string.Empty;

        //    str = "select F_WoID from T_Wo_WorkOrderItem_New where F_ItemType=" + (int)EnumItemType.deal
        //        + " and ("
        //            +"(F_WoState in(" + (int)EnumWorkOrderState.dealing + ","+ (int)EnumWorkOrderState.receive + ") and F_CreateUser='" + user + "') "//办理中和接单状态的操作人
        //            +" or (F_WoState in("+ (int)EnumWorkOrderState.reback + "," + (int)EnumWorkOrderState.abreback + ") and F_NextUser='" + user + "')"//退回下一步操作人
        //        +")"
        //        + " and isnull(F_IsUsed,'0')='0' ";

        //    return str;
        //}

        ///// <summary>
        ///// 获取我参与的工单编号
        ///// </summary>
        ///// <param name="user"></param>
        ///// <returns></returns>
        //public string GetCYWorkOrderID(string user)
        //{
        //    string str = string.Empty;

        //    str = "select F_WoID from T_Wo_WorkOrderItem_New where F_CreateUser='" + user + "' ";

        //    return str;
        //}

        ///// <summary>
        ///// 获取工单信息
        ///// </summary>
        ///// <returns></returns>
        //public ActionResult GetWorkOrder(long orderid)
        //{
        //    int userId = CurrentUser.UserData.F_UserId;
        //    if (userId != 0)
        //    {
        //        Model.T_Sys_UserAccount ua = sysUserAccountBll.GetModel(userId);
        //        if (ua != null)
        //        {
        //            if (orderid > 0)
        //            {
        //                string sql = "select *,dbo.GetDictionaryName(Type) as GDLXName,dbo.GetDictionaryName(TypeClass) as YWLXName,dbo.GetDictionaryName(source) as GDLYName,dbo.GetUserName(CreateUser) as CreateUserName,dbo.GetUserName(LastDealUser) as LastDealUserNameRel,dbo.GetUserName(AuditUser) as AuditUserNameRel,dbo.GetUserName(ResponUser) as ResponUserName,dbo.GetDeptName(ResponDept) as ResponDeptName from T_Wo_WorkOrder where ID =" + orderid + " ";
        //                var data = DbHelperSQL.Query(sql).Tables[0];
        //                var obj = new
        //                {
        //                    data
        //                };
        //                return Success("获取成功", obj);
        //            }
        //            else
        //                return Error("参数获取失败");
        //        }
        //    }
        //    return Error("无操作权限！");

        //    #region
        //    //string orderid = RequestString.GetQueryString("orderid");
        //    //if (!string.IsNullOrEmpty(orderid))
        //    //{
        //    //    string sql = "select *,dbo.GetDictionaryName(Type) as GDLXName,dbo.GetDictionaryName(TypeClass) as YWLXName,dbo.GetDictionaryName(source) as GDLYName,dbo.GetUserName(CreateUser) as CreateUserName,dbo.GetUserName(LastDealUser) as LastDealUserNameRel,dbo.GetUserName(AuditUser) as AuditUserNameRel,dbo.GetUserName(ResponUser) as ResponUserName,dbo.GetDeptName(ResponDept) as ResponDeptName from T_Wo_WorkOrder where WorkOrderID ='" + orderid + "'";
        //    //    //Type = 3 评论
        //    //    string sqlitem = "select *,dbo.GetUserName(CreateUser) as CreateUserName from T_Wo_WorkOrderItem where Type=" + (int)EnumItemType.comment + " and IsDel=0 and WorkOrderID ='" + orderid + "'";

        //    //    var data = DbHelperSQL.Query(sql).Tables[0];
        //    //    var item = DbHelperSQL.Query(sqlitem).Tables[0];
        //    //    var obj = new
        //    //    {
        //    //        data = data,
        //    //        item = item,
        //    //        processcount = itembll.GetList(" Type=" + (int)EnumItemType.deal + " and IsDel=0 and  WorkOrderID='" + orderid + "' ").Tables[0].Rows.Count,
        //    //        remindcount = itembll.GetList(" Type=" + (int)EnumItemType.urge + " and IsDel=0 and  WorkOrderID='" + orderid + "' ").Tables[0].Rows.Count,
        //    //        extencount = item.Rows.Count,
        //    //        //commentcount = itembll.GetList(" Type=4 and IsDel=0 and  WorkOrderID='" + orderid + "' ").Tables[0].Rows.Count
        //    //    };
        //    //    return Success("获取成功", obj);
        //    //}
        //    //else
        //    //{
        //    //    return Error("参数传输失败");
        //    //}
        //    #endregion
        //}

        //#region 在用工单操作
        ///// <summary>
        ///// 修改工单记录详情
        ///// </summary>
        ///// <returns></returns>
        //public ActionResult EditWorkOrderDetail(long orderid)
        //{
        //    int userId = CurrentUser.UserData.F_UserId;
        //    if (userId != 0)
        //    {
        //        Model.T_Sys_UserAccount ua = sysUserAccountBll.GetModel(userId);
        //        if (ua != null)
        //        {
        //            //工单类型
        //            int gdlx = RequestString.GetFormInt("gdlx", 0);
        //            //业务类型
        //            int ywlx = RequestString.GetFormInt("ywlx", 0);
        //            //客户姓名
        //            string callCustomer = RequestString.GetFormString("callCustomer");
        //            //公司名称
        //            string company = RequestString.GetFormString("company");
        //            //联系电话
        //            string tel = RequestString.GetFormString("tel");
        //            //受理人 - 审核人工号
        //            string auditusercode = RequestString.GetFormString("auditusercode");
        //            //接待描述 - 反馈内容
        //            string fkcont = RequestString.GetFormString("fkcont");
        //            //是否有效工单项(0有效，1无效)
        //            int iseffective = RequestString.GetFormInt("iseffective", 0);
        //            //备注
        //            string note = RequestString.GetFormString("note");
        //            //是否结束
        //            int isover = RequestString.GetFormInt("isover", 0);
        //            Model.T_Wo_WorkOrder model = bll.GetModel(orderid);
        //            if (model != null)
        //            {
        //                string detail = model.Detail;
        //                model.Type = gdlx;              //工单类型                    
        //                model.TypeClass = ywlx;         //业务办理-数据字典读取
        //                model.Customer = callCustomer;  //客户姓名
        //                model.County = company;//公司名称
        //                model.CustomerTel = tel;        //联系电话  
        //                if (!string.IsNullOrEmpty(auditusercode))
        //                    model.AuditUser = auditusercode;  //受理人 - 审核人工号
        //                                                      //反馈内容
        //                var detailutf8 = System.Web.HttpUtility.UrlDecode(fkcont, System.Text.Encoding.UTF8);
        //                model.Detail = detailutf8;
        //                model.F_IsOver = isover;
        //                model.IsEffective = iseffective;    //是否有效工单项(0有效，1无效)
        //                if (iseffective == 1)
        //                    model.Province = System.Web.HttpUtility.UrlDecode(note, System.Text.Encoding.UTF8); //备注

        //                if (bll.Update(model))
        //                {
        //                    //添加工单修改操作日志
        //                    WriteWorkOrderLog(model.WorkOrderID, detail, detailutf8, ua.F_UserCode, 0, "", 1, "修改工单");
        //                    #region 读取当前登录人的部门
        //                    string deptname = "";
        //                    var deptmodel = sysDeptBll.GetModel(ua.F_DeptId);
        //                    if(deptmodel!=null)
        //                    {
        //                        deptname = deptmodel.F_DeptName + "-";
        //                    }
        //                    #endregion
        //                    AddLog(orderid, model.State.Value, deptname + ua.F_UserName + "(" + ua.F_UserCode + ")" + "修改工单", (int)EnumItemType.update, (int)EnumItemOpt.update, "", 0, "", 0, "", "", ua);
        //                    return Success("修改成功！");
        //                }
        //                else
        //                    return Error("修改失败！");
        //            }
        //            return Error("工单不存在！");
        //        }
        //    }
        //    return Error("无操作权限！");
        //}
        ///// <summary>
        ///// 删除工单
        ///// </summary>
        ///// <param name="ids"></param>
        ///// <returns></returns>
        //public ActionResult DelWorkOrder(string[] ids)
        //{
        //    int userId = CurrentUser.UserData.F_UserId;
        //    if (userId != 0)
        //    {
        //        Model.T_Sys_UserAccount ua = sysUserAccountBll.GetModel(userId);
        //        if (ua != null)
        //        {
        //            if (ids != null && ids.Length > 0)
        //            {
        //                bool res = true;
        //                string idd = " ";
        //                foreach (string str in ids)
        //                {
        //                    idd += str + ",";
        //                }
        //                var list = bll.GetModelList(" ID in (" + idd.TrimEnd(',') + ") ");
        //                foreach (var item in list)
        //                {
        //                    item.DelTime = DateTime.Now;
        //                    item.DelUser = ua.F_UserCode;
        //                    item.IsDel = 1;
        //                    if (bll.Update(item))
        //                    {
        //                        string deptname = "";
        //                        var deptmodel = sysDeptBll.GetModel(ua.F_DeptId);
        //                        if (deptmodel != null)
        //                        {
        //                            deptname = deptmodel.F_DeptName + "-";
        //                        }
        //                        AddLog(item.ID, item.State.Value, deptname + ua.F_UserName + "(" + ua.F_UserCode + ")" + "修改工单", (int)EnumItemType.delete, (int)EnumItemOpt.delete, "", 0, "", 0, "", "", ua);
        //                        res &= true;
        //                    }
        //                    else
        //                    {
        //                        res &= false;
        //                        continue;
        //                    }
        //                }
        //                if (res)
        //                    return Success("删除成功");
        //                else
        //                    return Error("删除失败！");
        //            }
        //            else
        //            {
        //                return Error("获取参数失败！");
        //            }
        //        }
        //    }
        //    return Error("无操作权限！");
        //}
        ///// <summary>
        ///// 处理工单信息
        ///// </summary>
        ///// <returns></returns>
        //[Authority]
        //public ActionResult DealWorkOrder(long orderid, string cont,int isover=0)
        //{
        //    int userId = CurrentUser.UserData.F_UserId;
        //    if (userId != 0)
        //    {
        //        Model.T_Sys_UserAccount ua = sysUserAccountBll.GetModel(userId);
        //        if (ua != null)
        //        {
        //            Model.T_Wo_WorkOrder model = bll.GetModel(orderid);
        //            if (model != null)
        //            {
        //                var res = DealWO(ua, model, cont, isover);
        //                if (res)
        //                    return Success("处理成功");
        //                else
        //                    return Error("处理失败！");
        //            }
        //            else
        //                return Error("工单不存在！");
        //        }
        //    }
        //    return Error("无操作权限！");
        //}

        ///// <summary>
        ///// 指派/转派工单
        ///// </summary>
        ///// <returns></returns>
        //[Authority]
        //public ActionResult AssignWorkOrder(long orderid, string cont, int clbm=0,int clid=0)
        //{
        //    int userId = CurrentUser.UserData.F_UserId;
        //    string usercode = CurrentUser.UserData.F_UserCode;
        //    if (userId != 0)
        //    {
        //        Model.T_Sys_UserAccount ua = sysUserAccountBll.GetModel(userId);
        //        if (ua != null)
        //        {
        //            if (clbm != 0 && clid == 0)
        //                return Error("请选择接收人");
        //            Model.T_Wo_WorkOrder model = bll.GetModel(orderid);
        //            if (model != null)
        //            {
        //                var res=AssignWO(ua, model, cont, clbm, clid);
        //                if (res)
        //                    return Success("转派成功");
        //                else
        //                    return Error("转派失败！");
        //            }
        //            else
        //                return Error("工单不存在！");
        //        }
        //    }
        //    return Error("无操作权限！");
        //}

        ///// <summary>
        ///// 接单 - 确认工单
        ///// </summary>
        ///// <returns></returns>
        //[Authority]
        //public ActionResult SureWorkOrder(long orderid)
        //{
        //    int userId = CurrentUser.UserData.F_UserId;
        //    if (userId != 0)
        //    {
        //        Model.T_Sys_UserAccount ua = sysUserAccountBll.GetModel(userId);
        //        if (ua != null)
        //        {
        //            Model.T_Wo_WorkOrder model = bll.GetModel(orderid);
        //            if (model != null)
        //            {
        //                var res = SureWO(ua, model);
        //                if (res)
        //                    return Success("接单成功");
        //                else
        //                    return Error("接单失败");
        //            }
        //            else
        //                return Error("工单不存在");
        //        }
        //    }
        //    return Error("无操作权限");
        //}

        ///// <summary>
        ///// 退回工单
        ///// </summary>
        ///// <param name="input"></param>
        ///// <returns></returns>
        //[Authority]
        //public ActionResult BackWorkOrder(long orderid, string cont,int type=0)
        //{//办理人员和监管可以退回工单
        //    int userId = CurrentUser.UserData.F_UserId;
        //    if (userId != 0)
        //    {
        //        Model.T_Sys_UserAccount ua = sysUserAccountBll.GetModel(userId);
        //        if (ua != null)
        //        {
        //            Model.T_Wo_WorkOrder model = bll.GetModel(orderid);
        //            //验证信息
        //            if (model != null)
        //            {
        //                var res = BackWO(ua, model, cont, type);
        //                if(res)
        //                    return Success("处理成功");
        //                else
        //                    return Error("处理失败！");
        //            }
        //            return Error("工单不存在");
        //        }
        //    }
        //    return Error("无操作权限");
        //}

        ///// <summary>
        ///// 催办工单
        ///// </summary>
        ///// <returns></returns>
        //public ActionResult AddWorkOrderRemind(long orderid, string cont)
        //{
        //    int userId = CurrentUser.UserData.F_UserId;
        //    if (userId != 0)
        //    {
        //        Model.T_Sys_UserAccount ua = sysUserAccountBll.GetModel(userId);
        //        if (ua != null)
        //        {
        //            Model.T_Wo_WorkOrder model = bll.GetModel(orderid);
        //            if (model != null)
        //            {
        //                var res = RemindWO(ua, model, cont);
        //                if (res)
        //                    return Success("催办成功！");
        //                else
        //                    return Error("操作失败！");
        //            }
        //            return Error("工单不存在！");
        //        }
        //    }
        //    return Error("无操作权限！");
        //}

        //#endregion
        //#region 暂时不用
        /////// <summary>
        /////// 审核
        /////// </summary>
        ////[Authority]
        ////public ActionResult AuditWorkOrder(long orderid, string note, int iseffective = 0)
        ////{
        ////    int userId = CurrentUser.UserData.F_UserId;
        ////    if (userId != 0)
        ////    {
        ////        Model.T_Sys_UserAccount ua = sysUserAccountBll.GetModel(userId);
        ////        if (ua != null)
        ////        {
        ////            Model.T_Wo_WorkOrder model = bll.GetModel(orderid);
        ////            if (model != null)
        ////            {
        ////                if (iseffective == 1 && string.IsNullOrEmpty(note))
        ////                    return Error("请输入无效原因，如不填写，工单无法创建");

        ////                model.IsAudit = 1;
        ////                model.AuditTime = DateTime.Now;
        ////                model.IsEffective = iseffective;    //是否有效工单项(0有效，1无效)
        ////                if (iseffective == 1)
        ////                    model.Province = System.Web.HttpUtility.UrlDecode(note, System.Text.Encoding.UTF8); //备注
        ////                if (bll.Update(model))
        ////                {
        ////                    AddLog(model.ID, model.State.Value, "", (int)EnumItemType.deal, (int)EnumItemOpt.audit, "", 0, ua);
        ////                    return Success("操作成功");
        ////                }
        ////                return Error("操作失败");
        ////            }
        ////            else
        ////                return Error("工单不存在");
        ////        }
        ////    }
        ////    return Error("无操作权限！");
        ////}
        /////// <summary>
        /////// 导出工单列表
        /////// </summary>
        /////// <returns></returns>
        ////public ActionResult ExportListAll()
        ////{
        ////    ActionResult res = NoToken("未知错误，请重新登录");
        ////    if (Request.IsAuthenticated)
        ////    {
        ////        string sql = " and isdel=0 ";
        ////        DataTable dt = new DataTable();

        ////        string strorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("orderid"));
        ////        string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
        ////        string strtype = HttpUtility.UrlDecode(RequestString.GetQueryString("type"));
        ////        string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
        ////        string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
        ////        string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
        ////        string strcode = HttpUtility.UrlDecode(RequestString.GetQueryString("code"));
        ////        string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
        ////        string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));

        ////        if (strorderid.Trim() != "" && strorderid != "undefined")
        ////        {
        ////            sql += " and WorkOrderID like '%" + strorderid.Trim() + "%' ";
        ////        }
        ////        if (strstate.Trim() != "" && strstate != "undefined")
        ////        {
        ////            sql += " and State = '" + strstate.Trim() + "' ";
        ////        }
        ////        if (strtype.Trim() != "" && strtype != "undefined")
        ////        {
        ////            sql += " and Type = '" + strtype.Trim() + "' ";
        ////        }
        ////        if (strkey.Trim() != "" && strkey != "undefined")
        ////        {
        ////            sql += " and Detail like '%" + strkey.Trim() + "%' ";
        ////        }
        ////        if (strcode.Trim() != "" && strcode != "undefined")
        ////        {
        ////            sql += " and CreateUser = '" + strcode.Trim() + "' ";
        ////        }
        ////        if (strname.Trim() != "" && strname != "undefined")
        ////        {
        ////            sql += " and Customer like '%" + strname.Trim() + "%' ";
        ////        }
        ////        if (strtel.Trim() != "" && strtel != "undefined")
        ////        {
        ////            sql += " and CustomerTel like '%" + strtel + "%'  ";
        ////        }
        ////        if (strstarttime.Trim() != "" && strstarttime != "undefined")
        ////        {
        ////            sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
        ////        }
        ////        if (strendtime.Trim() != "" && strendtime != "undefined")
        ////        {
        ////            sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0   ";
        ////        }

        ////        sql = " select WorkOrderID as '工单编号',( case isnull(Type,0) when 1 then '售前咨询' when 2 then '报修服务' when 3 then '投诉建议' else '' end) as '工单类型',"
        ////            + " dbo.GetDictionaryName(TypeClass) as '问题类型',Detail as '工单内容',Customer as '客户名称',CustomerTel as '客户电话',"
        ////            + " (case isnull(State,0) when 0 then '未指派' when 1 then '处理中' when 2 then '已完结' else '' end ) as '工单状态', dbo.GetDeptName(ResponDept) as '投诉部门',"
        ////            + " dbo.GetUserName(ResponUser) as '投诉人',CreateUser as '坐席工号',dbo.GetUserName(CreateUser) as '坐席姓名',"
        ////            + " convert(decimal(18,2),DATEDIFF(minute, CreateTime, ISNULL(LastDealTime, GETDATE()))/60.00) as '处理工时',CreateTime as '创建时间',AppointTime as '指派时间',"
        ////            + " dbo.GetUserName(LastDealUser) as '完结人',LastDealTime as '完结时间' from T_Wo_WorkOrder where 1=1 " + sql;
        ////        dt = DbHelperSQL.Query(sql).Tables[0];

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

        ////    }
        ////    return res;
        ////}

        /////// <summary>
        /////// 导出工单列表
        /////// </summary>
        /////// <returns></returns>
        ////public ActionResult ExportList()
        ////{
        ////    ActionResult res = NoToken("未知错误，请重新登录");
        ////    if (Request.IsAuthenticated)
        ////    {
        ////        //20180523导出表格
        ////        #region 获取数据
        ////        string sql = " and isdel=0 ";
        ////        DataTable dt = new DataTable();
        ////        int userId = CurrentUser.UserData.F_UserId;
        ////        int deptid = CurrentUser.UserData.F_DeptId;         //部门id
        ////        string deptCode = CurrentUser.UserData.F_DeptCode;  //部门code
        ////        int userRegionId = CurrentUser.UserData.RegionId;  //项目id
        ////        var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='TimeLimitDays' ").FirstOrDefault();
        ////        int days = config != null ? Convert.ToInt32(config.F_ParamValue) : 60;  //默认60天
        ////        if (userId != 0)
        ////        {
        ////            Model.T_Sys_UserAccount ua = sysUserAccountBll.GetModel(userId);
        ////            if (ua != null)
        ////            {
        ////                //客户姓名,电话,房间号,工单号
        ////                string keyword = HttpUtility.UrlDecode(RequestString.GetQueryString("keyword"));
        ////                //工单状态(ltype:)
        ////                string strltype = HttpUtility.UrlDecode(RequestString.GetQueryString("ltype"));
        ////                //工单状态
        ////                int states = RequestString.GetInt("states", -1);
        ////                //工单来源
        ////                int strtype = RequestString.GetInt("type", 0);
        ////                //工单类型
        ////                int strtypeclass = RequestString.GetInt("typeclass", 0);
        ////                //工单起止时间
        ////                string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
        ////                string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));

        ////                //微信列表（0未审核微信列表，1已审核微信列表）
        ////                int isaudit = RequestString.GetInt("isaudit", -1);
        ////                #region 权限限制        
        ////                //部门信息
        ////                var modelDep = new BLL.T_Sys_Department().GetModel(deptid);
        ////                int depType = 0, depRegion = 0;
        ////                if (modelDep != null)
        ////                {
        ////                    depType = modelDep.F_Type ?? 0;  //部门操作权限：1接待部，2办理人员，3区域客服，4监管
        ////                    depRegion = modelDep.F_Header ?? 0; //部门权限范围：9全部，1区域，2项目，3期
        ////                }
        ////                if (ua.F_RoleId != 17)
        ////                {
        ////                    if (depType == 2)
        ////                    {
        ////                        if (depRegion == 1)
        ////                        {
        ////                            // 查看该区域工单
        ////                            //sql += $" and IsUserSend = (SELECT TOP 1 F_ParentId FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = {userRegionId}) ";
        ////                            sql += $" and IsUserSend = {userRegionId} ";
        ////                        }
        ////                        else if (depRegion == 2)
        ////                        {
        ////                            // 查看该项目工单
        ////                            sql += $" and IsAdminSend = {userRegionId} ";
        ////                        }
        ////                    }
        ////                    else if (depType == 3)
        ////                    {
        ////                        if (depRegion == 1)
        ////                        {
        ////                            // 查看该区域工单
        ////                            //sql += $" and IsUserSend = (SELECT TOP 1 F_ParentId FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = {userRegionId}) ";
        ////                            sql += $" and IsUserSend = {userRegionId} ";
        ////                        }
        ////                    }
        ////                    else if (depType == 4)
        ////                    {
        ////                        if (depRegion == 2)
        ////                        {
        ////                            // 查看该项目工单
        ////                            sql += $" and IsAdminSend = {userRegionId} ";
        ////                        }
        ////                        else if (depRegion == 9)
        ////                        {
        ////                            // 查看该部门工单（包括一级，二级）
        ////                            string deptCodeNew = String.Empty;
        ////                            int deptCodeIndex = 0;                                  //变量声明
        ////                            string deptCodeN = deptCode.TrimEnd('|');      //去掉最后一个|
        ////                            deptCodeIndex = deptCodeN.LastIndexOf("|");             //获得|的索引
        ////                            deptCodeNew = deptCodeN.Substring(0, deptCodeIndex + 1);    //获得目标字符串（//去掉最后一个|后面的字符串）
        ////                            //============== 部门权限条件 - 部门 ================
        ////                            string arrUser = " select F_UserCode from T_Sys_UserAccount where F_DeptCode LIKE '" + deptCodeNew + "%' ";
        ////                            sql += $" and WorkOrderID in (SELECT DISTINCT WorkOrderID FROM dbo.T_Wo_WorkOrderItem WHERE ToUser IN ({arrUser})) ";
        ////                        }
        ////                    }
        ////                }
        ////                #endregion

        ////                //客户姓名,电话,房间号,工单号
        ////                if (!string.IsNullOrEmpty(keyword))
        ////                {
        ////                    sql += " and (CustomerTel like '%" + keyword + "%' or Customer like '%" + keyword + "%' or Address like '%" + keyword + "%' or WorkOrderID like '%" + keyword + "%' ) ";
        ////                }
        ////                string uwhere = " ";
        ////                //客服部根据工单状态判断是否加旗标，工程部根据备注
        ////                switch (strltype)
        ////                {
        ////                    case "0"://待指派的
        ////                        //sql += " and State ='0' and CreateUser= '" + ua.F_UserCode + "' ";
        ////                        if (ua.F_RoleId != 17 && depType != 1 && depType != 3)
        ////                        {
        ////                            uwhere += " and CreateUser='" + ua.F_UserCode + "' ";
        ////                        }
        ////                        sql += " and State =0 " + uwhere;
        ////                        break;
        ////                    case "1"://待接单的
        ////                        sql += " and State =1 and WorkOrderID in ( " + GetDJDWorkOrderID(ua.F_UserCode) + ") ";
        ////                        break;
        ////                    case "2"://待完成的(待处理)
        ////                        sql += " and State =1 and WorkOrderID in ( " + GetDWCWorkOrderID(ua.F_UserCode) + ") ";
        ////                        break;
        ////                    case "3"://已完成的
        ////                        sql += " and State =2 and LastDealUser = '" + ua.F_UserCode + "' ";
        ////                        break;
        ////                    case "4"://我参与的
        ////                        sql += " and (CreateUser= '" + ua.F_UserCode + "' or WorkOrderID in ( " + GetCYWorkOrderID(ua.F_UserCode) + ")) ";
        ////                        break;
        ////                    case "5"://超期工单 - 设置两个月的处理时效，两个月内未解决的工单都直接汇总到这里
        ////                        sql += $" and DATEADD(DAY,{days},CreateTime) < GETDATE() AND State < 2 ";
        ////                        break;
        ////                        //case "471"://待处理
        ////                        //    sql += " and State =1 and CreateUser = '" + ua.F_UserCode + "' ";
        ////                        //    break;
        ////                        //case "472"://已处理
        ////                        //    sql += " and State =1 and LastDealUser = '" + ua.F_UserCode + "' ";
        ////                        //    break;
        ////                }
        ////                if (isaudit >= 0)
        ////                {
        ////                    sql += " and isaudit = " + isaudit + " and type = (select f_dictionaryvalueid from dbo.t_sys_dictionaryvalue (nolock) where f_dictionaryflag = 'gdly' and f_name = '微信') ";
        ////                }
        ////                else
        ////                {
        ////                    sql += " and isaudit = 1 ";
        ////                }
        ////                if (states >= 0)
        ////                    sql += " and State = " + states + " ";

        ////                if (strtype > 0)
        ////                {
        ////                    sql += " and Type = " + strtype + " ";
        ////                }
        ////                if (strtypeclass > 0)
        ////                {
        ////                    sql += " and TypeClass = " + strtypeclass + " ";
        ////                }
        ////                if (strstarttime.Trim() != "" && strstarttime != "undefined")
        ////                {
        ////                    sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
        ////                }
        ////                if (strendtime.Trim() != "" && strendtime != "undefined")
        ////                {
        ////                    sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0   ";
        ////                }
        ////                string str = "SELECT [WorkOrderID] as '工单编号',(case [State] when 0 then '待处理' else '已处理' end) as '工单状态',(SELECT F_RegionName FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = dbo.T_Wo_WorkOrder.IsUserSend) AS '区域名称',(SELECT F_RegionName FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = dbo.T_Wo_WorkOrder.IsAdminSend) AS '项目名称',(SELECT F_RegionName FROM dbo.T_Cus_RegionCategory WHERE F_RegionId = dbo.T_Wo_WorkOrder.IsTimeOut) AS '楼号名称',Address as '房间号',dbo.GetDictionaryName(Type) as '工单来源',dbo.GetDictionaryName(TypeClass) as '工单类型',(SELECT TOP 1 F_DeptName FROM dbo.T_Sys_Department WHERE F_DeptId = Source) AS '投诉类型',Customer as '姓名',CustomerTel as '联系电话',Detail as '接待描述',dbo.GetUserName(AuditUser) as '受理人',CreateUser as '坐席工号',CreateTime as '创建时间' FROM T_Wo_WorkOrder where 1=1 " + sql + "ORDER BY T_Wo_WorkOrder.ID desc";
        ////                dt = DbHelperSQL.Query(str).Tables[0];
        ////                foreach (DataRow dr in dt.Rows)
        ////                {
        ////                    dr["接待描述"] = Utils.DropHTML(dr["接待描述"].ToString());
        ////                }
        ////            }
        ////        }
        ////        #endregion

        ////        NPOIHelper npoi = new NPOIHelper();
        ////        if (npoi.ExportToExcel("工单列表", dt) == "")
        ////        {
        ////            return Success("导出成功");
        ////        }
        ////        else
        ////        {
        ////            return Error("导出失败");
        ////        }
        ////    }
        ////    return res;
        ////}
        //#region
        /////// <summary>
        /////// 获取可催办工单列表
        /////// </summary>
        /////// <returns></returns>
        ////public ActionResult GetCBList()
        ////{
        ////    ActionResult res = NoToken("未知错误，请重新登录");
        ////    if (Request.IsAuthenticated)
        ////    {
        ////        string sql = " and isdel=0 and State !='2'";
        ////        DataTable dt = new DataTable();

        ////        int userId = CurrentUser.UserData.F_UserId;
        ////        if (userId != 0)
        ////        {
        ////            Model.T_Sys_UserAccount ua = sysUserAccountBll.GetModel(userId);
        ////            if (ua != null)
        ////            {
        ////                string strorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("orderid"));
        ////                string strtype = HttpUtility.UrlDecode(RequestString.GetQueryString("type"));
        ////                string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
        ////                string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
        ////                string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
        ////                string strcode = HttpUtility.UrlDecode(RequestString.GetQueryString("code"));
        ////                string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
        ////                string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));

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

        ////                if (strorderid.Trim() != "" && strorderid != "undefined")
        ////                {
        ////                    sql += " and WorkOrderID like '%" + strorderid.Trim() + "%' ";
        ////                }
        ////                if (strtype.Trim() != "" && strtype != "undefined")
        ////                {
        ////                    sql += " and Type = '" + strkey.Trim() + "' ";
        ////                }
        ////                if (strkey.Trim() != "" && strkey != "undefined")
        ////                {
        ////                    sql += " and Detail like '%" + strkey.Trim() + "%' ";
        ////                }
        ////                if (strname.Trim() != "" && strname != "undefined")
        ////                {
        ////                    sql += " and Customer like '%" + strname.Trim() + "%' ";
        ////                }
        ////                if (strtel.Trim() != "" && strtel != "undefined")
        ////                {
        ////                    sql += " and CustomerTel like '%" + strtel + "%'  ";
        ////                }
        ////                if (strcode.Trim() != "" && strcode != "undefined")
        ////                {
        ////                    sql += " and CreateUser = '" + strcode.Trim() + "' ";
        ////                }
        ////                if (strstarttime.Trim() != "" && strstarttime != "undefined")
        ////                {
        ////                    sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
        ////                }
        ////                if (strendtime.Trim() != "" && strendtime != "undefined")
        ////                {
        ////                    sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0   ";
        ////                }

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

        ////                if (strpagesize.Trim() != "")
        ////                {
        ////                    pagesize = Convert.ToInt32(strpagesize);
        ////                }
        ////                int recordCount = 0;
        ////                dt = BLL.PagerBLL.GetListPager(
        ////                    "T_Wo_WorkOrder",
        ////                    "T_Wo_WorkOrder.ID",
        ////                    "*,dbo.GetDictionaryName(TypeClass) as TypeClassName,dbo.GetDictionaryName(Source) as SourceName,dbo.GetDictionaryName(Type) as TypeName,dbo.GetUserName(CreateUser) as CreateUserName, dbo.GetDeptName(ResponDept) as ResponDeptName,dbo.GetUserName(ResponUser) as ResponUserName,convert(decimal(18,2),DATEDIFF(minute, CreateTime, ISNULL(LastDealTime, GETDATE()))/60.00) as totalhour",
        ////                    sql,
        ////                    "ORDER BY T_Wo_WorkOrder.ID desc",
        ////                    pagesize,
        ////                    pageindex,
        ////                    true,
        ////                    out recordCount);
        ////                dt.Columns.Add("CBCount", typeof(int));
        ////                dt.Columns.Add("CLDeptName", typeof(String));
        ////                dt.Columns.Add("CLUserName", typeof(String));
        ////                foreach (DataRow dr in dt.Rows)
        ////                {
        ////                    var list = itembll.GetList(" WorkOrderID='" + dr["WorkOrderID"].ToString() + "' and IsDel=0 and Type=" + (int)EnumItemType.urge + " and ','+ToUser+',' like ',%" + ua.F_UserCode + "%,' ").Tables[0];
        ////                    dr["CBCount"] = list.Rows.Count;

        ////                    string sqlitem = "select top 1 dbo.GetUserName(ToUser) as ToUserName, dbo.GetDeptName(ToDept) as ToDeptName from T_Wo_WorkOrderItem where WorkOrderID ='" + dr["WorkOrderID"].ToString() + "' and IsDel=0 and Type=" + (int)EnumItemType.deal + " order by ID desc";
        ////                    var item = DbHelperSQL.Query(sqlitem).Tables[0];
        ////                    if (item.Rows.Count > 0)
        ////                    {
        ////                        dr["CLUserName"] = item.Rows[0]["ToUserName"].ToString();
        ////                        dr["CLDeptName"] = item.Rows[0]["ToDeptName"].ToString();
        ////                    }
        ////                }

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

        ////                res = Content(obj.ToJson());
        ////            }
        ////        }

        ////    }
        ////    return res;
        ////}
        //#endregion
        /////// <summary>
        /////// 补充工单
        /////// </summary>
        /////// <returns></returns>
        ////public ActionResult AddWorkOrderExten()
        ////{
        ////    ActionResult res = NoToken("未知错误，请重新登录");
        ////    if (Request.IsAuthenticated)
        ////    {

        ////        int userId = CurrentUser.UserData.F_UserId;
        ////        if (userId != 0)
        ////        {
        ////            Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
        ////            if (ua != null)
        ////            {
        ////                res = Error("补充失败！");
        ////                string orderid = RequestString.GetFormString("orderid");
        ////                string cont = RequestString.GetFormString("cont");
        ////                string file = RequestString.GetFormString("file");
        ////                string callid = RequestString.GetFormString("callid");
        ////                Model.T_Wo_WorkOrder model = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + orderid + "'").FirstOrDefault();
        ////                if (model != null)
        ////                {
        ////                    Model.T_Wo_WorkOrderItem item = new Model.T_Wo_WorkOrderItem();
        ////                    item.WorkOrderID = orderid;
        ////                    item.Type = (int)EnumItemType.comment;//3;
        ////                    item.Detail = cont;
        ////                    item.Files = file;
        ////                    item.CallID = callid;
        ////                    item.State = (int)EnumItemState.assign;//0;
        ////                    item.IsDel = 0;
        ////                    item.IsLast = 0;
        ////                    item.IsStart = 0;
        ////                    item.IsTimeOut = 0;
        ////                    item.CreateUser = ua.F_UserCode;
        ////                    item.CreateTime = DateTime.Now;

        ////                    if (new BLL.T_Wo_WorkOrderItem().Add(item) > 0)
        ////                    {
        ////                        res = Success("补充成功！");
        ////                    }
        ////                }
        ////            }
        ////        }

        ////    }
        ////    return res;
        ////}

        /////// <summary>
        /////// 评论工单
        /////// </summary>
        /////// <returns></returns>
        ////public ActionResult AddWorkOrderComment()
        ////{
        ////    ActionResult res = NoToken("未知错误，请重新登录");
        ////    if (Request.IsAuthenticated)
        ////    {

        ////        int userId = CurrentUser.UserData.F_UserId;
        ////        if (userId != 0)
        ////        {
        ////            Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
        ////            if (ua != null)
        ////            {
        ////                res = Error("评论失败！");
        ////                string orderid = RequestString.GetFormString("orderid");
        ////                string cont = RequestString.GetFormString("cont");
        ////                string file = RequestString.GetFormString("file");

        ////                Model.T_Wo_WorkOrder model = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + orderid + "'").FirstOrDefault();
        ////                if (model != null)
        ////                {
        ////                    Model.T_Wo_WorkOrderItem item = new Model.T_Wo_WorkOrderItem();
        ////                    item.WorkOrderID = orderid;
        ////                    item.Type = (int)EnumItemType.comment;//3;  //评论
        ////                    item.Detail = cont;
        ////                    item.Files = file;
        ////                    item.State = (int)EnumItemState.assign;//0;
        ////                    item.IsDel = 0;
        ////                    item.IsStart = 0;
        ////                    item.IsTimeOut = 0;
        ////                    item.IsLast = 0;
        ////                    item.CreateUser = ua.F_UserCode;
        ////                    item.CreateTime = DateTime.Now;

        ////                    if (new BLL.T_Wo_WorkOrderItem().Add(item) > 0)
        ////                    {
        ////                        res = Success("评论成功！");
        ////                    }
        ////                }
        ////            }
        ////        }

        ////    }
        ////    return res;
        ////}

        /////// <summary>
        /////// 重新开启工单
        /////// </summary>
        /////// <returns></returns>
        ////public ActionResult StartWorkOrder()
        ////{
        ////    ActionResult res = NoToken("未知错误，请重新登录");
        ////    if (Request.IsAuthenticated)
        ////    {

        ////        int userId = CurrentUser.UserData.F_UserId;
        ////        if (userId != 0)
        ////        {
        ////            Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
        ////            if (ua != null)
        ////            {
        ////                res = Error("开启失败！");
        ////                string orderid = RequestString.GetFormString("orderid");
        ////                string cont = RequestString.GetFormString("cont");
        ////                string file = RequestString.GetFormString("file");
        ////                string callid = RequestString.GetFormString("callid");
        ////                Model.T_Wo_WorkOrder model = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + orderid + "'").FirstOrDefault();
        ////                if (model != null && model.State == (int)EnumWorkOrderState.finish)
        ////                {
        ////                    model.State = (int)EnumWorkOrderState.assign;//1;
        ////                    model.LastDealUser = "";
        ////                    model.LastDealTime = null;
        ////                    if (new BLL.T_Wo_WorkOrder().Update(model))
        ////                    {
        ////                        var last = new BLL.T_Wo_WorkOrderItem().GetModelList("  WorkOrderID='" + orderid + "' and IsDel=0 ").OrderByDescending(p => p.ID).FirstOrDefault();

        ////                        if (last != null)
        ////                        {
        ////                            Model.T_Wo_WorkOrderItem itemnew = new Model.T_Wo_WorkOrderItem();
        ////                            itemnew.WorkOrderID = model.WorkOrderID;
        ////                            itemnew.Type = (int)EnumItemType.deal;//1;
        ////                            itemnew.ToDept = last.ToDept;
        ////                            itemnew.ToUser = last.ToUser;
        ////                            itemnew.Files = file;
        ////                            itemnew.CallID = callid;
        ////                            itemnew.IsStart = 1;
        ////                            itemnew.IsTimeOut = 0;
        ////                            itemnew.State = (int)EnumItemState.assign;//0;
        ////                            itemnew.IsDel = 0;
        ////                            itemnew.IsLast = 0;
        ////                            itemnew.CreateUser = ua.F_UserCode;
        ////                            itemnew.CreateTime = DateTime.Now;

        ////                            long itemid = new BLL.T_Wo_WorkOrderItem().Add(itemnew);
        ////                            if (itemid > 0)
        ////                            {
        ////                                foreach (string ur in itemnew.ToUser.Split(','))
        ////                                {
        ////                                    #region
        ////                                    sendsysmsg(model, ua, ur, Int32.Parse(itemid.ToString()), "重新开启");
        ////                                    //Model.T_Msg_List msg = new Model.T_Msg_List();
        ////                                    //msg.Type = (int)Model.MSGType.workorder;
        ////                                    //msg.ToUser = ur;
        ////                                    //msg.ToID = Int32.Parse(itemid.ToString());
        ////                                    //msg.Detail = ua.F_UserName + "重新开启工单，单号：" + model.WorkOrderID;
        ////                                    //msg.State = 0;
        ////                                    //msg.IsDel = 0;
        ////                                    //msg.CreateUser = ua.F_UserCode;
        ////                                    //msg.CreateDate = DateTime.Now;

        ////                                    //new BLL.T_Msg_List().Add(msg);
        ////                                    #endregion
        ////                                }
        ////                            }
        ////                        }

        ////                        res = Success("开启成功！");
        ////                    }
        ////                }
        ////            }
        ////        }

        ////    }
        ////    return res;
        ////}
        //#region
        ////public ActionResult BackWorkOrder()
        ////{
        ////    int userId = Utils.StrToInt(CurrentUser.UserData.F_UserId.ToString(), 0);
        ////    string usercode = CurrentUser.UserData.F_UserCode;
        ////    string orderid = RequestString.GetFormString("orderid");
        ////    //项目Id
        ////    var model = new Model.T_Wo_WorkOrder();
        ////    model = bll.GetModel(orderid);
        ////    //验证信息
        ////    if (model == null)
        ////    {
        ////        return Error("工单不存在");
        ////    }

        ////    model.State = 0;
        ////    if (bll.Update(model))
        ////    {
        ////        var modelItem = new BLL.T_Wo_WorkOrderItem().GetModelList(" IsDel=0 and Type=1 and (state='0' and ','+ToUser+',' like '%," + usercode + ",%') and WorkOrderID = '" + orderid + "' ").FirstOrDefault();
        ////        if (modelItem != null)
        ////        {
        ////            modelItem.State = 6;
        ////            new BLL.T_Wo_WorkOrderItem().Update(modelItem);
        ////        }
        ////        return Success("操作成功");
        ////    }
        ////    return Error("操作失败");
        ////}
        //#endregion
        //#endregion

        //#endregion

        //#region 工单明细
        ///// <summary>
        ///// 获取工单明细列表
        ///// </summary>
        ///// <returns></returns>
        //public ActionResult GetItemList()
        //{
        //    ActionResult res = NoToken("未知错误，请重新登录");
        //    if (Request.IsAuthenticated)
        //    {
        //        string sql = " ";
        //        DataTable dt = new DataTable();

        //        string strid = HttpUtility.UrlDecode(RequestString.GetQueryString("orderid"));
        //        string strtype = HttpUtility.UrlDecode(RequestString.GetQueryString("type"));
        //        string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
        //        string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));

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

        //        if (strid.Trim() != "" && strid != "undefined")
        //        {
        //            sql += " and F_WoID = '" + strid.Trim() + "' ";
        //        }
        //        if (strtype.Trim() != "" && strtype != "undefined")
        //        {
        //            sql += " and F_ItemType = '" + strtype.Trim() + "' ";
        //        }
        //        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);
        //        }
        //        int recordCount = 0;
        //        dt = BLL.PagerBLL.GetListPager(
        //            "T_Wo_WorkOrderItem_New",
        //            "F_ID",
        //            "*,dbo.GetUserName(F_NextUser) as F_NextUserName, dbo.GetDeptName(F_NextDept) as F_NextDeptName,dbo.GetUserName(F_CreateUser) as F_CreateUserName",
        //            sql,
        //            "ORDER BY F_ID desc",
        //            pagesize,
        //            pageindex,
        //            true,
        //            out recordCount);

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

        //        res = Content(obj.ToJson());

        //    }
        //    return res;
        //}

        /////// <summary>
        /////// 获取工单明细信息
        /////// </summary>
        /////// <returns></returns>
        ////public ActionResult GetWorkOrderItem()
        ////{
        ////    ActionResult res = NoToken("未知错误，请重新登录");
        ////    if (Request.IsAuthenticated)
        ////    {

        ////        int id = Utils.StrToInt(RequestString.GetQueryString("id"), 0);
        ////        if (id != 0)
        ////        {
        ////            Model.T_Wo_WorkOrderItem userModel = new BLL.T_Wo_WorkOrderItem().GetModel(id);
        ////            if (userModel != null)
        ////            {
        ////                res = Success("获取成功", userModel);
        ////            }
        ////            else
        ////            {
        ////                res = Error("获取失败");
        ////            }
        ////        }
        ////        else
        ////        {
        ////            res = Error("参数传输失败");
        ////        }

        ////    }
        ////    return res;
        ////}

        /////// <summary>
        /////// 添加工单明细信息
        /////// </summary>
        /////// <returns></returns>
        ////public ActionResult AddWorkOrderItem()
        ////{
        ////    ActionResult res = NoToken("未知错误，请重新登录");
        ////    if (Request.IsAuthenticated)
        ////    {

        ////        int userId = CurrentUser.UserData.F_UserId;
        ////        if (userId != 0)
        ////        {
        ////            Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
        ////            if (ua != null)
        ////            {
        ////                string orderid = RequestString.GetFormString("orderid");
        ////                int clbm = RequestString.GetInt("clbm", 0);
        ////                int clid = RequestString.GetInt("clid", 0);

        ////                Model.T_Wo_WorkOrder model = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + orderid + "'").FirstOrDefault();
        ////                if (model != null)
        ////                {
        ////                    Model.T_Wo_WorkOrderItem item = new Model.T_Wo_WorkOrderItem();
        ////                    item.WorkOrderID = model.WorkOrderID;
        ////                    item.Type = (int)EnumItemType.deal;//1;
        ////                    item.ToDept = clbm;

        ////                    Model.T_Wo_WorkOrderTimeOut to = new BLL.T_Wo_WorkOrderTimeOut().GetModel(model.Type.Value);
        ////                    if (to != null)
        ////                    {
        ////                        item.LimitTime = to.ItemTime;
        ////                    }
        ////                    if (clid != 0)
        ////                    {
        ////                        Model.T_Sys_UserAccount clus = new BLL.T_Sys_UserAccount().GetModel(clid);
        ////                        if (clus != null)
        ////                        {
        ////                            item.ToUser = clus.F_UserCode;
        ////                        }
        ////                    }
        ////                    else
        ////                    {
        ////                        string users = string.Empty;
        ////                        var list = new BLL.T_Sys_UserAccount().GetModelList(" F_DeptId='" + clbm + "'");
        ////                        foreach (var l in list)
        ////                        {
        ////                            if (string.IsNullOrEmpty(users))
        ////                            {
        ////                                users = l.F_UserCode;
        ////                            }
        ////                            else
        ////                            {
        ////                                users = users + "," + l.F_UserCode;
        ////                            }
        ////                        }
        ////                        item.ToUser = users;
        ////                    }

        ////                    item.IsLast = 0;
        ////                    item.IsStart = 0;
        ////                    item.IsTimeOut = 0;
        ////                    item.State = (int)EnumItemState.assign;// 0;
        ////                    item.CreateUser = ua.F_UserCode;
        ////                    item.CreateTime = DateTime.Now;

        ////                    model.State = (int)EnumWorkOrderState.assign;//1;//已指派
        ////                    new BLL.T_Wo_WorkOrder().Update(model);

        ////                    if (new BLL.T_Wo_WorkOrderItem().Add(item) > 0)
        ////                    {
        ////                        res = Success("新增成功！");
        ////                    }
        ////                    else
        ////                    {
        ////                        res = Error("新增失败！");
        ////                    }
        ////                }
        ////            }
        ////        }

        ////    }
        ////    return res;
        ////}

        /////// <summary>
        /////// 删除工单明细
        /////// </summary>
        /////// <param name="ids"></param>
        /////// <returns></returns>
        ////public ActionResult DelWorkOrderItem(string[] ids)
        ////{
        ////    ActionResult res = NoToken("未知错误，请重新登录");
        ////    if (Request.IsAuthenticated)
        ////    {

        ////        int userId = CurrentUser.UserData.F_UserId;
        ////        if (userId != 0)
        ////        {
        ////            Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
        ////            if (ua != null)
        ////            {
        ////                if (ids != null && ids.Length > 0)
        ////                {
        ////                    string idd = " ";
        ////                    foreach (string str in ids)
        ////                    {
        ////                        idd += str + ",";
        ////                    }

        ////                    string sql = "Update T_Wo_WorkOrderItem set IsDel=1,DelUser='" + ua.F_UserCode + "',DelTime=getdate() where ID in(" + idd.TrimEnd(',') + ")";
        ////                    if (!string.IsNullOrEmpty(idd.Trim()))
        ////                    {
        ////                        if (DbHelperSQL.ExecuteSql(sql) > 0)
        ////                        {
        ////                            res = Success("删除成功");
        ////                        }
        ////                        else
        ////                        {
        ////                            res = Error("删除失败");
        ////                        }
        ////                    }
        ////                    else
        ////                    {
        ////                        res = Error("请选择明细");
        ////                    }
        ////                }
        ////                else
        ////                {
        ////                    res = Error("获取参数失败");
        ////                }
        ////            }
        ////        }

        ////    }
        ////    return res;
        ////}
        //#endregion

        //#region 工单超时
        ///// <summary>
        ///// 获取工单超时列表
        ///// </summary>
        ///// <returns></returns>
        //public ActionResult GetTimeOutList()
        //{
        //    ActionResult res = NoToken("未知错误，请重新登录");
        //    if (Request.IsAuthenticated)
        //    {
        //        DataTable dt = new DataTable();

        //        dt = new BLL.T_Wo_WorkOrderTimeOut().GetList(" state=0 ").Tables[0];

        //        res = Success("成功", dt);

        //    }
        //    return res;
        //}

        ///// <summary>
        ///// 获取工单超时信息
        ///// </summary>
        ///// <returns></returns>
        //public ActionResult GetWorkOrderTimeOut()
        //{
        //    ActionResult res = NoToken("未知错误，请重新登录");
        //    if (Request.IsAuthenticated)
        //    {

        //        int id = Utils.StrToInt(RequestString.GetQueryString("id"), 0);
        //        if (id != 0)
        //        {
        //            Model.T_Wo_WorkOrderTimeOut userModel = new BLL.T_Wo_WorkOrderTimeOut().GetModel(id);
        //            if (userModel != null)
        //            {
        //                res = Success("获取成功", userModel);
        //            }
        //            else
        //            {
        //                res = Error("获取失败");
        //            }
        //        }
        //        else
        //        {
        //            res = Error("参数传输失败");
        //        }

        //    }
        //    return res;
        //}

        ///// <summary>
        ///// 添加/修改客户超时
        ///// </summary>
        ///// <returns></returns>
        //public ActionResult AddWorkOrderTimeOut()
        //{
        //    ActionResult res = NoToken("未知错误，请重新登录");
        //    if (Request.IsAuthenticated)
        //    {

        //        int userId = CurrentUser.UserData.F_UserId;
        //        if (userId != 0)
        //        {
        //            Model.T_Sys_UserAccount ua = sysUserAccountBll.GetModel(userId);
        //            if (ua != null)
        //            {
        //                int id = RequestString.GetInt("id", 0);
        //                int type = RequestString.GetInt("type", 0);
        //                string mtime = RequestString.GetFormString("mtime");
        //                string itime = RequestString.GetFormString("itime");

        //                Model.T_Wo_WorkOrderTimeOut timeout = new Model.T_Wo_WorkOrderTimeOut();

        //                if (id != 0)
        //                {
        //                    timeout = new BLL.T_Wo_WorkOrderTimeOut().GetModel(id);
        //                    if (timeout != null)
        //                    {
        //                        timeout.MainTime = decimal.Parse(mtime);
        //                        timeout.ItemTime = decimal.Parse(itime);

        //                        if (new BLL.T_Wo_WorkOrderTimeOut().Update(timeout))
        //                        {
        //                            res = Success("修改成功！");
        //                        }
        //                        else
        //                        {
        //                            res = Error("修改失败！");
        //                        }
        //                    }
        //                }
        //                else
        //                {

        //                    timeout.Type = type;
        //                    timeout.MainTime = decimal.Parse(mtime);
        //                    timeout.ItemTime = decimal.Parse(itime);

        //                    timeout.State = 0;
        //                    timeout.CreateUser = ua.F_UserCode;
        //                    timeout.CreateTime = DateTime.Now;

        //                    if (new BLL.T_Wo_WorkOrderTimeOut().Add(timeout) > 0)
        //                    {
        //                        res = Success("新增成功！");
        //                    }
        //                    else
        //                    {
        //                        res = Error("新增失败！");
        //                    }
        //                }
        //            }
        //        }

        //    }
        //    return res;
        //}

        ///// <summary>
        ///// 删除工单超时
        ///// </summary>
        ///// <param name="ids"></param>
        ///// <returns></returns>
        //public ActionResult DelWorkOrderTimeOut(string[] ids)
        //{
        //    ActionResult res = NoToken("未知错误，请重新登录");
        //    if (Request.IsAuthenticated)
        //    {

        //        if (ids != null && ids.Length > 0)
        //        {
        //            string idd = " ";
        //            foreach (string str in ids)
        //            {
        //                idd += str + ",";
        //            }

        //            string sql = "Delete T_Wo_WorkOrderTimeOut where ID in(" + idd.TrimEnd(',') + ")";
        //            if (!string.IsNullOrEmpty(idd.Trim()))
        //            {
        //                if (DbHelperSQL.ExecuteSql(sql) > 0)
        //                {
        //                    res = Success("删除成功");
        //                }
        //                else
        //                {
        //                    res = Error("删除失败");
        //                }
        //            }
        //            else
        //            {
        //                res = Error("请选择记录");
        //            }
        //        }
        //        else
        //        {
        //            res = Error("获取参数失败");
        //        }

        //    }
        //    return res;
        //}
        //#endregion
        //#region 工单操作公用方法
        ///// <summary>
        ///// 转派工单
        ///// </summary>
        //public bool AssignWO(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, string cont, int clbm = 0, int clid = 0)
        //{
        //    string touser = "";string tousername = "";
        //    #region 获取接收人
        //    if (clid != 0)
        //    {
        //        Model.T_Sys_UserAccount clus = sysUserAccountBll.GetModel(clid);
        //        if (clus != null)
        //        {
        //            touser = clus.F_UserCode;
        //            tousername = clus.F_UserName + "(" + touser + ")";
        //        }
        //    }
        //    else
        //    {
        //        string users = string.Empty;
        //        var list = sysUserAccountBll.GetModelList(" F_DeptId='" + clbm + "'");
        //        foreach (var l in list)
        //        {
        //            if (string.IsNullOrEmpty(users))
        //            {
        //                users = l.F_UserCode;
        //                tousername = l.F_UserName + "(" + l.F_UserCode + ")";
        //            }
        //            else
        //            {
        //                users = users + "," + l.F_UserCode;
        //                tousername = tousername + "," + l.F_UserName + "(" + l.F_UserCode + ")";
        //            }
        //        }
        //        touser = users;
        //    }
        //    #endregion
        //    #region 工单处理
        //    var opt = "指派";
        //    int optbut = (int)EnumItemOpt.assign;
        //    int wostate = (int)EnumWorkOrderState.assign;//已指派待接单
        //    #region 读取当前登录人部门
        //    string deptname = "";
        //    var deptmodel = sysDeptBll.GetModel(nowUser.F_DeptId);
        //    if (deptmodel != null)
        //    {
        //        deptname = deptmodel.F_DeptName + "-";
        //    }
        //    #endregion
        //    var optcont = "";
        //    if (!string.IsNullOrEmpty(cont))
        //        optcont = "，说明：" + cont;
        //    var content = deptname + nowUser.F_UserName + "(" + nowUser.F_UserCode + ")" + opt + "工单给 " + tousername+ optcont;
        //    var itemid = AddLog(model.ID, wostate, content, (int)EnumItemType.deal, optbut, touser, clbm, "", 0, "", "", nowUser);
        //    if (itemid > 0)
        //    {
        //        #region 处理工单
        //        //工单完结要更新工单的状态
        //        model.AuditUser = touser;
        //        model.State = wostate;
        //        //处理内容
        //        if (!string.IsNullOrEmpty(cont))
        //            model.Clcontent += cont + "；";
        //        bll.Update(model);
        //        #endregion
        //        #region 推送消息
        //        #region 推送消息给添加的坐席 -转派和处理
        //        if (nowUser.F_UserCode != model.CreateUser)
        //        {
        //            sendsysmsg(model, nowUser, model.CreateUser, (int)model.ID, opt);//推送系统消息
        //            var createmodel = sysUserAccountBll.GetModel(model.CreateUser);  //被指派人
        //            if (createmodel != null)
        //            {
        //                if (!string.IsNullOrEmpty(createmodel.F_WxOpenId))
        //                {
        //                    sendwxmsg(model, createmodel.F_WxOpenId, nowUser, opt);
        //                }
        //            }
        //        }
        //        #endregion
        //        #region 向下一级操作人员推送消息
        //        if (!string.IsNullOrWhiteSpace(touser))
        //        {
        //            sendsysmsg(model, nowUser, touser, (int)model.ID, opt);//推送系统消息
        //            var modelUser2 = sysUserAccountBll.GetModel(touser);  //被指派人
        //            if (modelUser2 != null)
        //            {
        //                if (!string.IsNullOrEmpty(modelUser2.F_WxOpenId))
        //                {
        //                    sendwxmsg(model, modelUser2.F_WxOpenId, nowUser, "指派");
        //                }
        //            }
        //        }
        //        #endregion
        //        #endregion
        //        return true;
        //    }
        //    else
        //        return false;
        //    #endregion
        //}
        ///// <summary>
        ///// 接单
        ///// </summary>
        //public bool SureWO(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model)
        //{
        //    #region 工单处理
        //    var opt = "处理接单";
        //    int optbut = (int)EnumItemOpt.receive;
        //    int wostate = (int)EnumWorkOrderState.receive;

        //    #region 读取当前登录人部门
        //    string deptname = "";
        //    var deptmodel = sysDeptBll.GetModel(nowUser.F_DeptId);
        //    if (deptmodel != null)
        //    {
        //        deptname = deptmodel.F_DeptName + "-";
        //    }
        //    #endregion
        //    var content = deptname + nowUser.F_UserName + "(" + nowUser.F_UserCode + ")" + opt;
        //    var itemid = AddLog((int)model.ID, wostate, content, (int)EnumItemType.deal, optbut, "", 0, "", 0, "", "", nowUser);
        //    if (itemid > 0)
        //    {
        //        #region 处理工单
        //        model.State = wostate;//已接单待处理
        //        bll.Update(model);
        //        #endregion
        //        #region 推送消息
        //        //读取上一级指派人员以及添加坐席并推送系统消息和微信消息
        //        #region 给添加坐席推送系统消息和微信消息
        //        sendsysmsg(model, nowUser, model.CreateUser, (int)itemid, "处理接单");
        //        var createUser = sysUserAccountBll.GetModel(model.CreateUser);
        //        if (createUser != null && !string.IsNullOrEmpty(createUser.F_WxOpenId))
        //            sendwxmsg(model, createUser.F_WxOpenId, nowUser, "接单");
        //        #endregion
        //        #region 读取上一级指派人员推送系统消息和微信消息
        //        var itemlast = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and  F_WoID='" + model.ID + "' and F_NextUser='" + nowUser.F_UserCode + "' order by F_CreateTime desc").FirstOrDefault();
        //        if (itemlast.F_CreateUser != model.CreateUser)
        //        {
        //            sendsysmsg(model, nowUser, itemlast.F_CreateUser, (int)itemid, "处理接单");
        //            var lastUser = sysUserAccountBll.GetModel(itemlast.F_CreateUser);
        //            if (lastUser != null && !string.IsNullOrEmpty(lastUser.F_WxOpenId))
        //                sendwxmsg(model, lastUser.F_WxOpenId, nowUser, "接单");
        //        }
        //        #endregion
        //        #endregion
        //        return true;
        //    }
        //    else
        //        return false;
        //    #endregion
        //}
        ///// <summary>
        ///// 处理工单
        ///// </summary>
        //public bool DealWO(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, string cont, int isover = 0)
        //{
        //    #region 工单处理
        //    var opt = "处理";
        //    int optbut = (int)EnumItemOpt.deal;
        //    int wostate = (int)EnumWorkOrderState.dealing;
        //    if (isover == 1)
        //    {
        //        opt = "处理完结";
        //        optbut = (int)EnumItemOpt.end;
        //        wostate = (int)EnumWorkOrderState.finish;
        //        model.LastDealUser = nowUser.F_UserCode;
        //        model.LastDealTime = DateTime.Now;
        //    }
        //    #region 读取当前登录人部门
        //    string deptname = "";
        //    var deptmodel = sysDeptBll.GetModel(nowUser.F_DeptId);
        //    if (deptmodel != null)
        //    {
        //        deptname = deptmodel.F_DeptName + "-";
        //    }
        //    #endregion
        //    var optcont = "";
        //    if (!string.IsNullOrEmpty(cont))
        //        optcont = "，处理内容：" + cont;
        //    var content = deptname + nowUser.F_UserName + "(" + nowUser.F_UserCode + ")" + opt + "工单"+ optcont;
        //    var itemid = AddLog(model.ID, wostate, content, (int)EnumItemType.deal, optbut, "", 0, "", 0, "", "", nowUser);
        //    if (itemid > 0)
        //    {
        //        #region 处理工单
        //        model.State = wostate;
        //        //处理内容
        //        if (!string.IsNullOrEmpty(cont))
        //            model.Clcontent += cont + "；";
        //        bll.Update(model);
        //        #endregion
        //        #region 推送消息
        //        #region 推送消息给添加的坐席 -处理情况
        //        if (nowUser.F_UserCode != model.CreateUser)
        //        {
        //            sendsysmsg(model, nowUser, model.CreateUser, (int)model.ID, opt);//推送系统消息
        //            var createmodel = sysUserAccountBll.GetModel(model.CreateUser);  //被指派人
        //            if (createmodel != null)
        //            {
        //                if (!string.IsNullOrEmpty(createmodel.F_WxOpenId))
        //                {
        //                    sendwxmsg(model, createmodel.F_WxOpenId, nowUser, opt);
        //                }
        //            }
        //        }
        //        #endregion
        //        #region 向上一级操作人员推送消息
        //        var itemlast = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and  F_WoID='" + model.ID + "' and F_NextUser='" + nowUser.F_UserCode + "' order by F_CreateTime desc").FirstOrDefault();
        //        if (itemlast.F_CreateUser != model.CreateUser)
        //        {
        //            sendsysmsg(model, nowUser, itemlast.F_CreateUser, (int)itemid, opt);
        //            var lastUser = sysUserAccountBll.GetModel(itemlast.F_CreateUser);
        //            if (lastUser != null && !string.IsNullOrEmpty(lastUser.F_WxOpenId))
        //                sendwxmsg(model, lastUser.F_WxOpenId, nowUser, opt);
        //        }
        //        #endregion
        //        #endregion
        //        return true;
        //    }
        //    else
        //        return false;
        //    #endregion
        //}
        ///// <summary>
        ///// 退回工单
        ///// </summary>
        //public bool BackWO(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, string cont,int type)
        //{
        //    #region 工单处理
        //    var opt = "退回";
        //    int optbut = (int)EnumItemOpt.reback;
        //    int wostate = (int)EnumWorkOrderState.reback;
        //    if (type == 1)
        //    {
        //        opt = "异常退回";
        //        optbut = (int)EnumItemOpt.abreback;
        //        wostate=(int)EnumWorkOrderState.abreback;
        //    }
        //    #region 读取当前登录人部门
        //    string deptname = "";
        //    var deptmodel = sysDeptBll.GetModel(nowUser.F_DeptId);
        //    if (deptmodel != null)
        //    {
        //        deptname = deptmodel.F_DeptName + "-";
        //    }
        //    #endregion
        //    var content = deptname + nowUser.F_UserName + "(" + nowUser.F_UserCode + ")" + opt + "工单，退回说明：" + cont;
        //    //获取上一级处理人员
        //    var touser = "";
        //    var itemlast = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and  F_WoID='" + model.ID + "' and F_NextUser='" + nowUser.F_UserCode + "' order by F_CreateTime desc").FirstOrDefault();
        //    if (itemlast != null)
        //        touser = itemlast.F_CreateUser;
        //    var itemid = AddLog((int)model.ID, wostate, content, (int)EnumItemType.deal, optbut, touser, 0, "", 0, "", "", nowUser);
        //    if (itemid > 0)
        //    {
        //        #region 处理工单
        //        model.State = wostate;
        //        bll.Update(model);
        //        #endregion
        //        #region 推送消息
        //        #region 向上一级操作人员推送消息
        //        if (!string.IsNullOrWhiteSpace(touser)&& touser != nowUser.F_UserCode)
        //        {//排除上一级指派人是自己
        //            sendsysmsg(model, nowUser, touser, (int)itemid, opt);
        //            var lastUser = sysUserAccountBll.GetModel(touser);
        //            if (lastUser != null && !string.IsNullOrEmpty(lastUser.F_WxOpenId))
        //                sendwxmsg(model, lastUser.F_WxOpenId, nowUser, opt);
        //        }
        //        #endregion
        //        #endregion
        //        return true;
        //    }
        //    else
        //        return false;
        //    #endregion
        //}
        ///// <summary>
        ///// 催办工单
        ///// </summary>
        //public bool RemindWO(Model.T_Sys_UserAccount nowUser, Model.T_Wo_WorkOrder model, string cont)
        //{
        //    var itemlast = itembll.GetModelList(" F_ItemType=" + (int)EnumItemType.deal + " and  F_WoID='" + model.ID + "' and F_IsUsed=0 order by F_CreateTime desc").FirstOrDefault();
        //    #region 接收人
        //    int todept = 0; string touser = "";
        //    if (itemlast != null)
        //    {
        //        touser = itemlast.F_NextUser;
        //        if (!string.IsNullOrWhiteSpace(touser))
        //            touser = itemlast.F_CreateUser;
        //        #region 读取当前登录人部门
        //        string deptname = "";
        //        var deptmodel = sysDeptBll.GetModel(nowUser.F_DeptId);
        //        if (deptmodel != null)
        //        {
        //            deptname = deptmodel.F_DeptName + "-";
        //        }
        //        #endregion
        //        var content = deptname + nowUser.F_UserName + "(" + nowUser.F_UserCode + ")催办工单，催办说明：" + cont;
        //        long itemid = AddLog(model.ID, model.State.Value, content, (int)EnumItemType.urge, (int)EnumItemOpt.urge, touser, todept, "", 0, "", "", nowUser);
        //        if (itemid > 0)
        //        {
        //            sendsysmsg(model, nowUser, touser, Int32.Parse(itemid.ToString()), "催办");
        //            var tousers = sysUserAccountBll.GetModel(touser);
        //            if (tousers != null && !string.IsNullOrWhiteSpace(tousers.F_WxOpenId))
        //            {
        //                sendwxmsg(model, tousers.F_WxOpenId, nowUser, "催办");
        //            }
        //            return true;
        //        }
        //    }
        //    return false;
        //    #endregion
        //}
        //#endregion
        //#region 微信工单        

        ///// <summary>
        ///// 添加/修改工单信息 - 微信
        ///// </summary>
        ////public string AddWXWorkOrder(string workOrder, int gdly, int gdlx, int customerid, string callCustomer, 
        ////    string tel, string fkdep,string kfdepid,string auditusercode, string fkcont,string files, 
        ////    int gdzt,string note,string userCode,int iseffective)
        ////{
        ////    string workorderid = string.Empty;
        ////    Model.T_Wo_WorkOrder model = new Model.T_Wo_WorkOrder();
        ////    model.WorkOrderID = workOrder;  //工单编号                        
        ////    model.Type = gdly;              //工单来源                    
        ////    model.TypeClass = gdlx;         //投诉类型 -工单类型
        ////    model.Customer = callCustomer;  //客户姓名
        ////    model.CustomerTel = tel;        //联系电话  
        ////    model.CustomerID = customerid;  //用户档案Id

        ////    model.Source = fkdep;  //处理部门 反馈单位  
        ////    //model.CreateUserID = kfdepid;  //客服类类型           
        ////    model.AuditUser = auditusercode;  //受理人 - 审核人工号
        ////    model.CreateUser = userCode;      //创建人
        ////    //工单状态  471 默认未处理
        ////    model.State = (int)EnumWorkOrderState.neworder;//0;
        ////    //接待描述 - 反馈内容
        ////    var detailutf8 = System.Web.HttpUtility.UrlDecode(fkcont, System.Text.Encoding.UTF8);
        ////    model.Detail = detailutf8;
        ////    model.IsEffective = iseffective;    //是否有效工单项(-1未知，0有效，1无效)          
        ////    model.F_IsOver = 0;
        ////    model.CreateTime = DateTime.Now;
        ////    model.IsDel = 0;
        ////    model.IsReturn = 0;
        ////    model.IsReturnBak = 0;
        ////    model.Answer = "";

        ////    workorderid = bll.Add(model).ToString();
        ////    return workorderid;
        ////}

        //////处理工单 - 微信
        ////public bool DealWXWorkOrder(string orderid, int isend, int clbm, int clid, string cont,int isover, string openid)
        ////{
        ////    if (openid != "")
        ////    {
        ////        Model.T_Sys_UserAccount ua = sysUserAccountBll.GetModelList(" F_WxOpenId='" + openid + "'").FirstOrDefault();

        ////        Model.T_Wo_WorkOrder model = new BLL.T_Wo_WorkOrder().GetModelList(" WorkOrderID='" + orderid + "'").FirstOrDefault();
        ////        if (ua != null)
        ////        {
        ////            if (model != null)
        ////            {
        ////                string touser = "";
        ////                #region 获取接收人
        ////                if (clid != 0)
        ////                {
        ////                    Model.T_Sys_UserAccount clus = sysUserAccountBll.GetModel(clid);
        ////                    if (clus != null)
        ////                    {
        ////                        touser = clus.F_UserCode;
        ////                    }
        ////                }
        ////                else
        ////                {
        ////                    string users = string.Empty;
        ////                    var list = sysUserAccountBll.GetModelList(" F_DeptId='" + clbm + "'");
        ////                    foreach (var l in list)
        ////                    {
        ////                        if (string.IsNullOrEmpty(users))
        ////                        {
        ////                            users = l.F_UserCode;
        ////                        }
        ////                        else
        ////                        {
        ////                            users = users + "," + l.F_UserCode;
        ////                        }
        ////                    }
        ////                    touser = users;
        ////                }
        ////                #endregion
        ////                #region 工单记录
        ////                //Model.T_Wo_WorkOrderItem item = new Model.T_Wo_WorkOrderItem();
        ////                //item.WorkOrderID = orderid;
        ////                //item.Type = (int)EnumItemType.deal;//1;      //处理
        ////                //item.ToDept = clbm; //部门
        ////                //if (!string.IsNullOrEmpty(cont))
        ////                //    item.Detail = cont;
        ////                //item.IsDel = 0;
        ////                ////转派
        ////                //if (isend == 0)
        ////                //{
        ////                //    item.State = (int)EnumItemState.assign;//0;
        ////                //    item.IsLast = 0;
        ////                //}
        ////                //else
        ////                //{
        ////                //    item.State = (int)EnumItemState.finish;//2;
        ////                //    item.IsLast = 1;
        ////                //}
        ////                //item.IsStart = 0;
        ////                //item.IsTimeOut = 0;
        ////                //item.IsUsed = 0;
        ////                //item.CreateUser = ua.F_UserCode;
        ////                //item.CreateTime = DateTime.Now;
        ////                //long itemid = new BLL.T_Wo_WorkOrderItem().Add(item);
        ////                #endregion
        ////                long itemid = AddOrderItem(orderid, (int)EnumItemType.deal, clbm, touser, isend, cont, isover, 0, ua);
        ////                if (itemid > 0)
        ////                {
        ////                    #region

        ////                    //工单完结要更新工单的状态
        ////                    if (isend == 0)
        ////                    {
        ////                        model.ResponDept = clid;
        ////                        //无接收人时，状态修改成 0待指派
        ////                        if (clid == 0)
        ////                        {
        ////                            model.State = (int)EnumWorkOrderState.neworder;// 0;    //待指派
        ////                        }
        ////                        else
        ////                        {
        ////                            model.AuditUser = touser;
        ////                            model.State = (int)EnumWorkOrderState.assign;//1;    //待处理
        ////                        }
        ////                        //model.State = 1;    //已处理
        ////                    }
        ////                    else
        ////                    {
        ////                        if (isover == 1)
        ////                        {
        ////                            model.State = (int)EnumWorkOrderState.finish;//2;    //已处理item.ToUser
        ////                            model.LastDealUser = ua.F_UserCode;
        ////                            model.LastDealTime = DateTime.Now;
        ////                        }
        ////                    }
        ////                    //处理内容
        ////                    if (!string.IsNullOrEmpty(cont))
        ////                        model.Clcontent += cont + "；";

        ////                    new BLL.T_Wo_WorkOrder().Update(model);
        ////                    #endregion
        ////                    #region 消息表
        ////                    sendsysmsg(model, ua, ua.F_UserCode, Int32.Parse(itemid.ToString()), "处理");
        ////                    //string strmsg = string.Empty;
        ////                    //strmsg = ua.F_UserName + "完结了工单，单号：" + model.WorkOrderID;
        ////                    //Model.T_Msg_List msg = new Model.T_Msg_List();
        ////                    //msg.Type = (int)Model.MSGType.workorder;//处理
        ////                    //msg.ToUser = ua.F_UserCode;
        ////                    //msg.ToID = Int32.Parse(itemid.ToString());
        ////                    //msg.Detail = strmsg;
        ////                    //msg.State = 0;
        ////                    //msg.IsDel = 0;
        ////                    //msg.CreateUser = ua.F_UserCode;
        ////                    //msg.CreateDate = DateTime.Now;

        ////                    //new BLL.T_Msg_List().Add(msg);
        ////                    #endregion
        ////                    #region 派单后发送微信推送
        ////                    if (clid != 0)
        ////                    {
        ////                        if (model.State == (int)EnumWorkOrderState.assign)
        ////                        {//已派单状态
        ////                            var modelUser2 = sysUserAccountBll.GetModel(clid);  //被指派人
        ////                            if (modelUser2 != null)
        ////                            {
        ////                                if (!string.IsNullOrEmpty(modelUser2.F_WxOpenId))
        ////                                {
        ////                                    sendwxmsg(model, modelUser2.F_WxOpenId, ua, "派单");
        ////                                    //var dicv = dicvalueBll.GetModel(model.TypeClass.Value);
        ////                                    //string content = string.Empty;
        ////                                    //var wotype = "";
        ////                                    //if (dicv != null)
        ////                                    //{
        ////                                    //    wotype = dicv.F_Name;
        ////                                    //    content = "客户" + model.Customer + "提出的工单已派单，请及时处理";
        ////                                    //}
        ////                                    //WxHelper.SendWechatMsg1(model.WorkOrderID, "你有新的工单需要处理", wotype, model.State.ToString(), content, orderid.ToString(), modelUser2.F_WxOpenId);
        ////                                    //WxHelper.SendWechatMsg1(model.WorkOrderID, "你有新的工单需要处理", wotype, content, orderid.ToString(), modelUser2.F_WxOpenId);


        ////                                }
        ////                            }
        ////                        }
        ////                    }
        ////                    #endregion
        ////                    return true;
        ////                }
        ////            }
        ////        }
        ////    }
        ////    return false;
        ////}

        //#endregion

        //#region 日志信息
        ///// <summary>
        ///// 添加工单记录
        ///// </summary>
        //public long AddLog(long woid,int wostate,string content,int itemtype,int opttype,string nextuser,int nextdept, 
        //    string limittime,int issms,string smsuser,string smscont,Model.T_Sys_UserAccount nowUser)
        //{
        //    Model.T_Wo_WorkOrderItem_New itemModel = new Model.T_Wo_WorkOrderItem_New();
        //    #region 
        //    //处理当前工单的记录之前的记录过期
        //    var itemlast = itembll.GetModelList(" isnull(F_IsUsed,'0')='0' and F_ItemType=" + itemtype + " and  F_WoID=" + woid + " ");
        //    if (itemlast.Count > 0)
        //    {
        //        foreach (var it in itemlast)
        //        {
        //            it.F_IsUsed = 1;
        //            itembll.Update(it);
        //        }
        //    }
        //    #endregion
        //    itemModel.F_WoID = woid;
        //    itemModel.F_WoState = wostate;
        //    itemModel.F_ItemType = itemtype;
        //    itemModel.F_OptType = opttype;
        //    itemModel.F_OptContent = content;
        //    itemModel.F_NextUser = nextuser;
        //    itemModel.F_NextDept = nextdept;
        //    itemModel.F_IsUsed = 0;
        //    itemModel.F_LimitTime = limittime;
        //    itemModel.F_IsSMS = issms;
        //    itemModel.F_SMSToUser = smsuser;
        //    if (!string.IsNullOrWhiteSpace(smsuser))
        //    {
        //        var smsusermodel = sysUserAccountBll.GetModel(smsuser);
        //        if (smsusermodel != null)
        //            itemModel.F_SMSToPhone = smsusermodel.F_Mobile;
        //    }
        //    itemModel.F_SMSContent = smscont;
        //    itemModel.F_CreateUser = nowUser.F_UserCode;
        //    itemModel.F_CreateTime = DateTime.Now;
        //    var res= itembll.Add(itemModel);
        //    return res;
        //}
        ///// <summary>
        ///// 工单修改操作日志
        ///// </summary>
        ///// <param name="WorkOrderID">工单编号</param>
        ///// <param name="BeforeContent">之前内容</param>
        ///// <param name="UpdateContent">修改内容</param>
        ///// <param name="UserCode">修改人code</param>
        ///// <param name="DelUserCode">删除人code</param>
        ///// <param name="TypeId">类型（0添加，1修改）</param>
        ///// <param name="AreaId">区域id</param>
        ///// <param name="ProId">区域id</param>
        ///// <param name="StageId">项目Id</param>
        ///// <param name="remark">期（一期，二期 ...）</param>
        //public void WriteWorkOrderLog(string WorkOrderID, string BeforeContent, string UpdateContent, string UserCode,int IsDelete, string DelUserCode,int TypeId,string Remark)
        //{
        //    var model = new Model.T_Wo_WorkOrder_Logs();
        //    model.WorkOrderID = WorkOrderID;        //工单编号
        //    model.BeforeContent = BeforeContent;    //之前内容
        //    model.UpdateContent = UpdateContent;    //修改内容
        //    model.UserCode = UserCode;              //修改人code
        //    model.AddTime = DateTime.Now;           //添加时间
        //    model.IsDelete = IsDelete;              //是否删除（0正常1删除）
        //    model.DelUserCode = DelUserCode;        //删除人code
        //    model.TypeId = TypeId;                  //类型（0添加，1修改）
        //    model.Remark = Remark;                  //备注
        //    blllogs.Add(model);
        //}
        //#endregion

        //#region 消息提醒
        ////推送系统提醒
        //public void sendsysmsg(Model.T_Wo_WorkOrder womodel, Model.T_Sys_UserAccount nowUser, string touser,int toid,string opt)
        //{
        //    #region 消息提醒
        //    string strmsg = string.Empty;
        //    strmsg = nowUser.F_UserName + "(" + nowUser.F_UserCode + ")" + "操作" + opt + "工单";
        //    Model.T_Msg_List msg = new Model.T_Msg_List();
        //    msg.Type = (int)Model.MSGType.workorder;//处理
        //    msg.ToUser = touser;
        //    msg.ToID = toid;
        //    msg.Detail = strmsg;
        //    msg.State = 0;
        //    msg.IsDel = 0;
        //    msg.CreateUser = nowUser.F_UserCode;
        //    msg.CreateDate = DateTime.Now;

        //    new BLL.T_Msg_List().Add(msg);
        //    #endregion
        //}
        ////推送微信消息
        //public void sendwxmsg(Model.T_Wo_WorkOrder womodel,string openid, Model.T_Sys_UserAccount nowUser, string opt)
        //{
        //    #region 推送微信
        //    try
        //    {
        //        if (!string.IsNullOrEmpty(openid))
        //        {
        //            var dicv = dicvalueBll.GetModel(womodel.TypeClass.Value);
        //            string content = string.Empty;
        //            var wotype = "";
        //            if (dicv != null)
        //            {
        //                wotype = dicv.F_Name;
        //            }
        //            content = "编号" + womodel.WorkOrderID + "的工单已" + opt + "，操作人：" + nowUser.F_UserName + "(" + nowUser.F_UserCode + ")";
        //            var msg=WxHelper.SendWechatMsg1(womodel.WorkOrderID, "你有工单已" + opt, wotype, womodel.State.ToString(), content, womodel.ID.ToString(), openid,"");
        //            Error("推送微信::::::"+msg.ToString());
        //        }
        //    }
        //    catch { }
        //    #endregion
        //}
        //#endregion
    }
}