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

namespace CallCenterApi.Interface.Controllers.workorder
{
    public class ShangQiuWorkOrderController : BaseController
    {
        BLL.T_Bus_WorkOrder_GovernmentServiceWO_Map womapbll = new BLL.T_Bus_WorkOrder_GovernmentServiceWO_Map();
        BLL.T_Bus_WorkOrder_GriddingWO_Map womagpbll = new BLL.T_Bus_WorkOrder_GriddingWO_Map();
        private BLL.T_Sys_SystemConfig configBll = new BLL.T_Sys_SystemConfig();
        private AjaxResult ajresult = new AjaxResult();
        private FileUp fileup = new FileUp();

        /// <summary>
        /// 添加工单接口（投诉/咨询）
        /// 商丘市政务服务网和12345系统对接接口
        /// </summary>
        /// <returns></returns>
        //[HttpPost]
        public ActionResult AddWorkOrder()
        {
            
            Model.T_Bus_WorkOrder_GovernmentServiceWO_Map womapmodel = new Model.T_Bus_WorkOrder_GovernmentServiceWO_Map();
            string message = string.Empty;
            string port_password = RequestString.GetFormString("port_password");   //加密信息(安全验证用)
            string uuid = RequestString.GetFormString("uuid");          //客户唯一标识（安全验证用）
            int source = RequestString.GetInt("source", 7);             //信息来源
            string cusname = RequestString.GetFormString("cusname");    //投诉人姓名
            string cussex = RequestString.GetFormString("cussex");      //投诉人性别
            string cusphone = RequestString.GetFormString("cusphone");  //投诉人电话
            string cusaddress = RequestString.GetFormString("cusaddress");    //投诉人详细地址
            string email = RequestString.GetFormString("email");        //邮箱
            string zipcode = RequestString.GetFormString("zipcode");    //邮编
            string conname = RequestString.GetFormString("conname");    //联系人姓名
            string conphone = RequestString.GetFormString("conphone");  //客户电话
            string title = RequestString.GetFormString("title");        //标题
            string content = RequestString.GetFormString("content");    //内容
            int sourcearea = RequestString.GetInt("sourcearea", 0);      //事发地域id
            string sourceaddress = RequestString.GetFormString("sourceaddress");    //事发详细地址
            string keys = RequestString.GetFormString("keys");          //关键词id(多个用英文逗号, 隔开)
            string splituser = RequestString.GetFormString("splituser");    //分管领导id(多个用英文逗号, 隔开)
            int type = RequestString.GetInt("type", 0);              //类型
            int bigtype = RequestString.GetInt("bigtype", 0);        //大类别
            int smalltype = RequestString.GetInt("smalltype", 0);    //小类别
            int isprotect = RequestString.GetInt("isprotect", 0);    //0普通1保密
            int level = RequestString.GetInt("level", 0);            //1普通2紧急3特急

            if (string.IsNullOrEmpty(uuid))
            {
                ajresult.state = (int)CodeStatus.ID不存在;
                ajresult.message = "客户唯一标识不能为空";
                return Process();
            }
            else if (uuid.Length > 50)
            {
                ajresult.state = (int)CodeStatus.字符串超出长度;
                ajresult.message = "客户唯一标识超出长度";
                return Process();
            }
            if (string.IsNullOrEmpty(cusphone))
            {
                ajresult.state = (int)CodeStatus.必填字段为空;
                ajresult.message = "投诉人电话不能为空";
                return Process();
            }
            if (!Common.CodeValidate.ICodeValidate(uuid + cusphone, port_password))
            {
                ajresult.state = (int)CodeStatus.安全验证未通过;
                ajresult.message = "安全验证未通过";
                return Process();
            }
            if (string.IsNullOrEmpty(cusname))
            {
                ajresult.state = (int)CodeStatus.必填字段为空;
                ajresult.message = "投诉人姓名不能为空";
                return Process();
            }
            if (string.IsNullOrEmpty(title))
            {
                ajresult.state = (int)CodeStatus.必填字段为空;
                ajresult.message = "标题不能为空";
                return Process();
            }
            WorkOrderController wo = new WorkOrderController();
            if (!womapbll.ExistsByGSWorkOrderId(uuid))  //uuid不存在时,防止重复添加
            {
                string WorkOrderId = wo.AddWorkOrderBySource(source, cusname, cussex, cusphone, cusaddress, email, zipcode, conname, conphone, title, content, sourcearea, sourceaddress, keys, splituser, type, bigtype, smalltype, isprotect, level);
                if (string.IsNullOrEmpty(WorkOrderId))
                {
                    ajresult.state = (int)CodeStatus.异常结果类型;
                    ajresult.message = "操作失败";
                    return Process();
                }

                womapmodel.F_WorkOrderId = WorkOrderId;
                womapmodel.F_GSWorkOrderId = uuid;
                womapmodel.F_AddTime = DateTime.Now;
                int n = womapbll.Add(womapmodel);
                if (n <= 0)
                {
                    ajresult.state = (int)CodeStatus.异常结果类型;
                    ajresult.message = "操作失败";
                    return Process();
                }

                ajresult.state = (int)CodeStatus.SUCCESS;
                ajresult.message = "操作成功";
                ajresult.data = WorkOrderId;  //订单号
                return Process();
            }
            else {
                ajresult.state = (int)CodeStatus.数据库错误;
                ajresult.message = "操作失败,信息已存在";
                return Process();
            }
        }

        public ActionResult GetScor()
        {
            string port_password = RequestString.GetFormString("port_password");   //加密信息(安全验证用)
            string uuid = RequestString.GetFormString("uuid");          //客户唯一标识（安全验证用）
            string workorderid = RequestString.GetFormString("workorderid");
            string usercode = RequestString.GetFormString("usercode");

            var pp=Common.CodeValidate.ICodeValidateGriddingT(uuid + workorderid, port_password);
            return Success("获取", pp);
        }

        #region 20200401 zhengbingbing 新增网格化对接办理接口
        public ActionResult Test()
        {
            int id = 0;
            string workorderid = RequestString.GetFormString("workorderid");
            string title = RequestString.GetFormString("title");
            string des = RequestString.GetFormString("des");
            string place = RequestString.GetFormString("place");
            string contact = RequestString.GetFormString("contact");
            string parties = RequestString.GetFormString("parties");
            string files = RequestString.GetFormString("fileids");
            string usercode = RequestString.GetFormString("usercode");
            int type= RequestString.GetInt("type", 0);
            //var upstr = new ImageUpload().ImgToBase64(videos);
            //var re = UpdateImg(files);
            //var re = UploadMp(videos);
            //int re = SendToGrdding(id, workorderid, title, des, place, contact, parties, files, usercode,type);
            #region 附件处理
            var imgnames = string.IsNullOrWhiteSpace(files) ? "" : Upload(files, 1);
            var videonames = "";// string.IsNullOrWhiteSpace(files) ? "" : Upload(files, 2);
            var filenames = "";//string.IsNullOrWhiteSpace(files) ? "" : Upload(files, 0);
            #endregion
            var re = "img:" + imgnames + ";video:" + videonames + ";file:" + filenames;
            return Success("测试", re);
        }
        /// <summary>
        /// 发送网格化对接工单
        /// </summary>
        /// <param name="title">事件（工单）标题</param>
        /// <param name="des">事件（工单）描述</param>
        /// <param name="place">事发场所</param>
        /// <param name="contact">联系电话</param>
        /// <param name="parties">当事人</param>
        /// <param name="files">文件名称</param>
        /// <param name="videos">视频名称</param>
        /// <param name="imageurl">图片名称</param>
        /// <returns></returns>
        public int SendToGrdding(int id, string workorderid, string title, string des, string place, string contact, string parties, string fileids, string usercode,int type,string latitude,string longitude)
        {
           
            var ress = 0;
            try
            {
                var eventsort = "";
                #region 类型对应
                switch (type)
                {
                    #region
                    //eventsort   type
                    //963    投诉 11
                    //964    咨询 9
                    //965    求助 10 
                    //966    表扬 13
                    //967    建议 12
                    //968    其他 14
                    #endregion
                    case 9:
                        eventsort = "964";
                        break;
                    case 10:
                        eventsort = "965";
                        break;
                    case 11:
                        eventsort = "963";
                        break;
                    case 12:
                        eventsort = "967";
                        break;
                    case 13:
                        eventsort = "966";
                        break;
                    case 14:
                        eventsort = "968";
                        break;

                }
                #endregion
                using (TransactionScope trans = new TransactionScope())
                {
                    #region 附件处理
                    //var imgnames = string.IsNullOrWhiteSpace(fileids) ? "" : Upload(fileids, 1);
                    //var videonames = string.IsNullOrWhiteSpace(fileids) ? "" : Upload(fileids, 2);
                    //var filenames = string.IsNullOrWhiteSpace(fileids) ? "" : Upload(fileids, 0);
                    var imgnames = string.IsNullOrWhiteSpace(fileids) ? "" : UploadUrl(fileids, 1);//照片
                    var videonames = string.IsNullOrWhiteSpace(fileids) ? "" : UploadUrl(fileids, 3);//音频
                    var filenames = string.IsNullOrWhiteSpace(fileids) ? "" : UploadUrl(fileids, 2);//视频    
                    #endregion
                    #region 参数发送
                    var param = new
                    {
                        taskid = workorderid,
                        eventplace = place,//事发场所,
                        title = title,//事件（工单）标题,
                        imageurl = imgnames,//图片名称,
                        description = des,//事件（工单）描述,
                        contact = contact,//联系电话,
                        parties = parties,//当事人,
                        shejinum = id,//5,
                        filename = filenames,//文件名称,多个文件以|分隔
                        video = videonames,//视频名称,
                        adduser = usercode,
                        eventsort = eventsort,
                        latitude = latitude,//纬度
                        longitude = longitude 
//经度
                    };
                    #endregion
                    WebReference.Service1 webs = new WebReference.Service1();
                    var res = webs.ReportDispute12345(param.ToJson());
                    int n = 0;
                    if (res == "200")
                    {
                        Model.T_Bus_WorkOrder_GriddingWO_Map womagpmodel = new Model.T_Bus_WorkOrder_GriddingWO_Map();
                        womagpmodel.F_WorkOrderId = workorderid;
                        womagpmodel.F_GWorkOrderId = workorderid;
                        womagpmodel.F_Direction = "send";
                        womagpmodel.F_AddTime = DateTime.Now;
                        n = womagpbll.Add(womagpmodel);
                    }
                    AddGriddingLogs("", "", "send", "SendToGrdding|||" + param.ToJson().ToString() + "|||result:" + res, usercode, workorderid, "", "", "", "", "", "", "", "", "", "", 0, 0, 0, 0, n);
                    if (n > 0)
                        ress = 1;
                    else
                        ress = 2;

                    trans.Complete();
                }
            }
            catch (Exception ex)
            {
                ress = 4;
                ajresult.state = (int)CodeStatus.异常结果类型;
                ajresult.message = ex.Message;
                Process();
            }

            return ress;
        }
        /// <summary>
        /// 审核退回
        /// 工单结果反馈给网格化
        /// </summary>
        /// <param name="id"></param>
        /// <param name="workorderid"></param>
        /// <param name="state"></param>
        /// <param name="reason"></param>
        /// <param name="usercode"></param>
        /// <returns></returns>
        public int AuditRebackToGrdding(string workorderid, string state, string reason,string usercode)
        {
            var ress = 0;
            try
            {
                var states = "0";
                #region
                if (state == "1")
                    states = "1";
                #endregion
                using (TransactionScope trans = new TransactionScope())
                {
                    var param = new
                    {
                        taskid = workorderid,
                        examine = states,//0不通过 1通过
                    };
                    WebReference.Service1 webs = new WebReference.Service1();
                    var res = webs.DisputeBackExamine(param.ToJson());
                    int n = 0;
                    if (res == "200")
                    {
                        Model.T_Bus_WorkOrder_GriddingWO_Map womagpmodel = new Model.T_Bus_WorkOrder_GriddingWO_Map();
                        womagpmodel.F_WorkOrderId = workorderid;
                        womagpmodel.F_GWorkOrderId = workorderid;
                        womagpmodel.F_Direction = "send";
                        womagpmodel.F_AddTime = DateTime.Now;
                        n = womagpbll.Add(womagpmodel);
                    }
                    AddGriddingLogs("", "", "send", "AuditRebackToGrdding|||" + param.ToJson().ToString() + "|||result:" + res, usercode, workorderid, "", "", "", "", "", "", "", "", "", "", 0, 0, 0, 0, n);
                    if (n > 0)
                        ress = 1;
                    else
                        ress = 2;

                    trans.Complete();
                }
            }
            catch (Exception ex)
            {
                ress = 4;
                ajresult.state = (int)CodeStatus.异常结果类型;
                ajresult.message = ex.Message;
                Process();
            }

            return ress;
        }

        /// <summary>
        /// 保存图片至网格化
        /// </summary>
        /// <param name="fileids"></param>
        /// <returns></returns>
        public string Upload(string fileids,int type)
        {
            var configfj = configBll.GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
            var filelists = new BLL.T_Sys_Accessories().GetModelList(" F_FileId in (" + fileids + ") ");
            var filenames = "";
            WebReference.Service1 webs = new WebReference.Service1();
            foreach (var filemodel in filelists)
            {
                var timetag = DateTimeConvert.ToTimetag(DateTime.Now);
               var fileurl = configfj.F_ParamValue + filemodel.F_FileUrl;
               var filename= "("+timetag+")"+filemodel.F_FileName;
                var upstr = new ImageUpload().ImgToBase64(fileurl);
                var dd= new ImageUpload().CompressString(upstr);
                
                var upres = "";
                if (!string.IsNullOrWhiteSpace(upstr))
                {
                    if (type == 1)
                    {
                        if (new ImageUpload().IsImg(filemodel.F_FileType))
                        { //上传图片
                            upres = webs.UploadImageResume(filename, dd, 1, "event");
                            if (upres == "1")
                            {
                                filenames = filenames + filename + "|";
                            }
                        }
                    }
                    else if (type==2)
                    {
                        if (new ImageUpload().IsMp3(filemodel.F_FileType)|| new ImageUpload().IsMp4(filemodel.F_FileType))
                        { //上传音频、视频  
                            upres = webs.UploadFileResume(filename, upstr, -1);
                            //webs.IsExistsFile(fileurl); //判断音频、视频是否存在
                            if (upres == "-1")
                                filenames = filenames + filename + "|";
                        }
                    }
                    else
                    {
                        if (!new ImageUpload().IsImg(filemodel.F_FileType) && !new ImageUpload().IsMp3(filemodel.F_FileType)&& !new ImageUpload().IsMp4(filemodel.F_FileType))
                            upres = webs.UploadFileResume(filename, upstr, -1);
                        if(upres=="-1")
                            filenames = filenames + filename + "|";
                    }
                    
                }
            }

            return filenames.Trim('|');
        }
        public string UploadUrl(string fileids, int type)
        {
            var fileurls = "";
            using (TransactionScope trans = new TransactionScope())
            {
                var configfj = configBll.GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
                var filelists = new BLL.T_Sys_Accessories().GetModelList(" F_FileId in (" + fileids + ") ");
                
                foreach (var filemodel in filelists)
                {
                    var fileurl = configfj.F_ParamValue + filemodel.F_FileUrl;
                    if (type == 1)
                    {
                        if (new ImageUpload().IsImg(filemodel.F_FileType))
                            fileurls = fileurls + fileurl + "|";
                    }
                    else if (type == 2)
                    {
                        if (new ImageUpload().IsMp3(filemodel.F_FileType))
                            fileurls = fileurls + fileurl + "|";
                    }
                    else if (type == 3)
                    {
                        if (new ImageUpload().IsMp4(filemodel.F_FileType))
                            fileurls = fileurls + fileurl + "|";
                    }
                    else
                    {
                        fileurls = fileurls + fileurl + "|";
                    }
                }
                trans.Complete();
            }
            return fileurls.Trim('|');
        }

        /// <summary>
        /// 查收接口
        /// 新城办事处网格化对接
        /// </summary>
        /// <returns></returns>
        public ActionResult ReceiveWorkOrder()
        {
            Model.T_Bus_WorkOrder_GriddingWO_Map womagpmodel = new Model.T_Bus_WorkOrder_GriddingWO_Map();
            string port_password = RequestString.GetFormString("port_password");   //加密信息(安全验证用)
            string uuid = RequestString.GetFormString("uuid");          //客户唯一标识（安全验证用）
            string workorderid = RequestString.GetFormString("workorderid");
            string content = RequestString.GetFormString("content");//查收详情
            string usercode = RequestString.GetFormString("usercode");
            using (TransactionScope trans = new TransactionScope())
            {
                #region 参数验证
                if (string.IsNullOrEmpty(uuid))
                {
                    ajresult.state = (int)CodeStatus.ID不存在;
                    ajresult.message = "客户唯一标识不能为空";
                    return Process();
                }
                else if (uuid.Length > 50)
                {
                    ajresult.state = (int)CodeStatus.字符串超出长度;
                    ajresult.message = "客户唯一标识超出长度";
                    return Process();
                }
                if (string.IsNullOrEmpty(workorderid))
                {
                    ajresult.state = (int)CodeStatus.必填字段为空;
                    ajresult.message = "工单编号不能为空";
                    return Process();
                }
                if (string.IsNullOrEmpty(usercode))
                {
                    ajresult.state = (int)CodeStatus.必填字段为空;
                    ajresult.message = "工号不能为空";
                    return Process();
                }
                if (!Common.CodeValidate.ICodeValidateGridding(uuid + workorderid, port_password))
                {
                    ajresult.state = (int)CodeStatus.安全验证未通过;
                    ajresult.message = "安全验证未通过";
                    return Process();
                }
                #endregion
                WorkOrderController wo = new WorkOrderController();
                int mapid = 0; var backid = "";
                if (!womagpbll.ExistsByGSWorkOrderId(uuid))  //uuid不存在时,防止重复添加
                {
                    backid = wo.ReceiveWorkOrderByDock(usercode, workorderid, content);
                    if (string.IsNullOrEmpty(backid))
                    {
                        ajresult.state = (int)CodeStatus.执行失败;
                        ajresult.message = "操作失败";
                        return Process();
                    }

                    womagpmodel.F_WorkOrderId = workorderid;
                    womagpmodel.F_GWorkOrderId = uuid;
                    womagpmodel.uuid = uuid;
                    womagpmodel.port_password = port_password;
                    womagpmodel.F_Direction = "receive";
                    womagpmodel.F_AddTime = DateTime.Now;
                    mapid = womagpbll.Add(womagpmodel);

                    var rets = backid.Split('|');
                    if (rets[0] == "false")
                    {
                        ajresult.state = (int)CodeStatus.执行失败;
                        ajresult.message = "操作失败，" + rets[2];
                    }
                    else
                    {
                        ajresult.state = (int)CodeStatus.SUCCESS;
                        ajresult.message = "操作成功";
                        ajresult.data = rets[1];  //反馈ID
                    }
                }
                else
                {
                    ajresult.state = (int)CodeStatus.数据库错误;
                    ajresult.message = "操作失败,信息已存在";
                }
                AddGriddingLogs(uuid, port_password, "receive", "ReceiveWorkOrder：" + ajresult.message + "||" + content + "||" + backid, usercode, workorderid, "", "", "", "", "", "", "", "", "", "", 0, 0, 0, 0, mapid);
                trans.Complete();
            }
            return Process();
        }
        /// <summary>
        /// 退回接口
        /// 新城办事处网格化对接
        /// </summary>
        /// <returns></returns>
        public ActionResult RebackWorkOrder()
        {
            Model.T_Bus_WorkOrder_GriddingWO_Map womagpmodel = new Model.T_Bus_WorkOrder_GriddingWO_Map();
            string port_password = RequestString.GetFormString("port_password");   //加密信息(安全验证用)
            string uuid = RequestString.GetFormString("uuid");          //客户唯一标识（安全验证用）
            string workorderid = RequestString.GetFormString("workorderid");
            string content = RequestString.GetFormString("content");//退回详情
            string backreason = RequestString.GetFormString("backreason");
            string usercode = RequestString.GetFormString("usercode");
            using (TransactionScope trans = new TransactionScope())
            {
                #region 参数验证
                if (string.IsNullOrEmpty(uuid))
                {
                    ajresult.state = (int)CodeStatus.ID不存在;
                    ajresult.message = "客户唯一标识不能为空";
                    return Process();
                }
                else if (uuid.Length > 50)
                {
                    ajresult.state = (int)CodeStatus.字符串超出长度;
                    ajresult.message = "客户唯一标识超出长度";
                    return Process();
                }
                if (string.IsNullOrEmpty(workorderid))
                {
                    ajresult.state = (int)CodeStatus.必填字段为空;
                    ajresult.message = "工单编号不能为空";
                    return Process();
                }
                if (string.IsNullOrEmpty(usercode))
                {
                    ajresult.state = (int)CodeStatus.必填字段为空;
                    ajresult.message = "工号不能为空";
                    return Process();
                }
                if (!Common.CodeValidate.ICodeValidateGridding(uuid + workorderid, port_password))
                {
                    ajresult.state = (int)CodeStatus.安全验证未通过;
                    ajresult.message = "安全验证未通过";
                    return Process();
                }
                #endregion
                WorkOrderController wo = new WorkOrderController();
                int mapid = 0; var backid = "";
                if (!womagpbll.ExistsByGSWorkOrderId(uuid))  //uuid不存在时,防止重复添加
                {
                    backid = wo.RebackWorkOrderByDock(usercode, workorderid,backreason, content);
                    if (string.IsNullOrEmpty(backid))
                    {
                        ajresult.state = (int)CodeStatus.执行失败;
                        ajresult.message = "操作失败";
                        return Process();
                    }
                    womagpmodel.F_WorkOrderId = workorderid;
                    womagpmodel.F_GWorkOrderId = uuid;
                    womagpmodel.uuid = uuid;
                    womagpmodel.port_password = port_password;
                    womagpmodel.F_Direction = "receive";
                    womagpmodel.F_AddTime = DateTime.Now;
                    mapid = womagpbll.Add(womagpmodel);

                    var rets = backid.Split('|');
                    if(rets[0]=="false")
                    {
                        ajresult.state = (int)CodeStatus.执行失败;
                        ajresult.message = "操作失败，"+ rets[2];
                    }
                    else
                    {
                        ajresult.state = (int)CodeStatus.SUCCESS;
                        ajresult.message = "操作成功";
                        ajresult.data = rets[1];  //反馈ID
                    }
                }
                else
                {
                    ajresult.state = (int)CodeStatus.数据库错误;
                    ajresult.message = "操作失败,信息已存在";
                }
                AddGriddingLogs(uuid, port_password, "receive", "RebackWorkOrder：" + ajresult.message + "||" + content + "||" + backid, usercode, workorderid, "", "", "", "", "", "", "", "", "", "", 0, 0, 0, 0, mapid);
                trans.Complete();
            }
            return Process();
        }

        /// <summary>
        /// 处理工单接口
        /// 新城办事处网格化对接
        /// </summary>
        /// <returns></returns>
        //[HttpPost]
        public ActionResult DealWorkOrder()
        {
            Model.T_Bus_WorkOrder_GriddingWO_Map womagpmodel = new Model.T_Bus_WorkOrder_GriddingWO_Map();
            #region 获取参数
            string message = string.Empty;
            string port_password = RequestString.GetFormString("port_password");   //加密信息(安全验证用)
            string uuid = RequestString.GetFormString("uuid");          //客户唯一标识（安全验证用）
            string workorderid = RequestString.GetFormString("workorderid");
            string dealman = RequestString.GetFormString("dealman");
            string files = RequestString.GetFormString("files");
            int state = RequestString.GetInt("state", 0);
            int feedbackid = RequestString.GetInt("feedbackid", 0);
            int isproresult = RequestString.GetInt("isproresult", 0);//是否有处理结果:0默认，1是，2否
            string prosituation = RequestString.GetFormString("prosituation");
            string dealcontact = RequestString.GetFormString("dealcontact");
            string connecttime = RequestString.GetFormString("connecttime");
            string connectmode = RequestString.GetFormString("connectmode");
            int isstaisfied = RequestString.GetInt("isstaisfied", 0);
            string duties = RequestString.GetFormString("duties");
            string situation = RequestString.GetFormString("situation");
            string usercode = RequestString.GetFormString("usercode");
            #endregion
            using (TransactionScope trans = new TransactionScope())
            {
                #region 参数验证
                if (string.IsNullOrEmpty(uuid))
                {
                    ajresult.state = (int)CodeStatus.ID不存在;
                    ajresult.message = "客户唯一标识不能为空";
                    return Process();
                }
                else if (uuid.Length > 50)
                {
                    ajresult.state = (int)CodeStatus.字符串超出长度;
                    ajresult.message = "客户唯一标识超出长度";
                    return Process();
                }
                if (string.IsNullOrEmpty(workorderid))
                {
                    ajresult.state = (int)CodeStatus.必填字段为空;
                    ajresult.message = "工单编号不能为空";
                    return Process();
                }
                if (string.IsNullOrEmpty(usercode))
                {
                    ajresult.state = (int)CodeStatus.必填字段为空;
                    ajresult.message = "工号不能为空";
                    return Process();
                }
                if (!Common.CodeValidate.ICodeValidateGridding(uuid + workorderid, port_password))
                {
                    ajresult.state = (int)CodeStatus.安全验证未通过;
                    ajresult.message = "安全验证未通过";
                    return Process();
                }
                #endregion

                var backid = ""; int mapid = 0;int bid = 0;
                WorkOrderController wo = new WorkOrderController();
                if (!womagpbll.ExistsByGSWorkOrderId(uuid))  //uuid不存在时,防止重复添加
                {
                    backid = wo.FeedBackWorkOrderBYDock(usercode, workorderid, dealman, "", files, prosituation, dealcontact, connecttime, connectmode, "", duties, situation, state, feedbackid, isproresult, isstaisfied);
                    if (string.IsNullOrEmpty(backid))
                    {
                        ajresult.state = (int)CodeStatus.执行失败;
                        ajresult.message = "操作失败";
                        return Process();
                    }

                    womagpmodel.F_WorkOrderId = workorderid;
                    womagpmodel.F_GWorkOrderId = uuid;
                    womagpmodel.uuid = uuid;
                    womagpmodel.port_password = port_password;
                    womagpmodel.F_Direction = "receive";
                    womagpmodel.F_AddTime = DateTime.Now;
                    mapid = womagpbll.Add(womagpmodel);

                    var rets = backid.Split('|');
                    if (rets[0] == "false")
                    {
                        ajresult.state = (int)CodeStatus.执行失败;
                        ajresult.message = "操作失败，" + rets[2];
                    }
                    else
                    {
                        ajresult.state = (int)CodeStatus.SUCCESS;
                        ajresult.message = "操作成功";
                        ajresult.data = rets[1];  //反馈ID
                        bid = int.Parse(rets[1]);
                    }
                }
                else
                {
                    ajresult.state = (int)CodeStatus.数据库错误;
                    ajresult.message = "操作失败,信息已存在";
                }

                AddGriddingLogs(uuid, port_password, "receive", "DealWorkOrder||" + ajresult.message, usercode, workorderid, dealman, "", files, prosituation, dealcontact, connecttime, connectmode, "", duties, situation, state, bid, isproresult, isstaisfied, mapid);

                trans.Complete();
            }
            return Process();
        }
        /// <summary>
        /// 处理工单过程接口
        /// 新城办事处网格化对接
        /// </summary>
        /// <returns></returns>
        public ActionResult DealProcess()
        {
            Model.T_Bus_WorkOrder_GriddingWO_Map womagpmodel = new Model.T_Bus_WorkOrder_GriddingWO_Map();
            string port_password = RequestString.GetFormString("port_password");   //加密信息(安全验证用)
            string uuid = RequestString.GetFormString("uuid");          //客户唯一标识（安全验证用）
            string workorderid = RequestString.GetFormString("workorderid");
            string content = RequestString.GetFormString("content");
            string usercode = RequestString.GetFormString("usercode");
            using (TransactionScope trans = new TransactionScope())
            {
                #region 参数验证
                if (string.IsNullOrEmpty(uuid))
                {
                    ajresult.state = (int)CodeStatus.ID不存在;
                    ajresult.message = "客户唯一标识不能为空";
                    return Process();
                }
                else if (uuid.Length > 50)
                {
                    ajresult.state = (int)CodeStatus.字符串超出长度;
                    ajresult.message = "客户唯一标识超出长度";
                    return Process();
                }
                if (string.IsNullOrEmpty(workorderid))
                {
                    ajresult.state = (int)CodeStatus.必填字段为空;
                    ajresult.message = "工单编号不能为空";
                    return Process();
                }
                if (string.IsNullOrEmpty(usercode))
                {
                    ajresult.state = (int)CodeStatus.必填字段为空;
                    ajresult.message = "工号不能为空";
                    return Process();
                }
                if (!Common.CodeValidate.ICodeValidateGridding(uuid + workorderid, port_password))
                {
                    ajresult.state = (int)CodeStatus.安全验证未通过;
                    ajresult.message = "安全验证未通过";
                    return Process();
                }
                #endregion
                WorkOrderController wo = new WorkOrderController();
                int mapid = 0;var backid = "";
                if (!womagpbll.ExistsByGSWorkOrderId(uuid))  //uuid不存在时,防止重复添加
                {
                    backid = wo.DealProcessWorkOrderByDock(usercode, workorderid, content);
                    if (string.IsNullOrEmpty(backid))
                    {
                        ajresult.state = (int)CodeStatus.执行失败;
                        ajresult.message = "操作失败";
                        return Process();
                    }

                    womagpmodel.F_WorkOrderId = workorderid;
                    womagpmodel.F_GWorkOrderId = uuid;
                    womagpmodel.uuid = uuid;
                    womagpmodel.port_password = port_password;
                    womagpmodel.F_Direction = "receive";
                    womagpmodel.F_AddTime = DateTime.Now;
                    mapid = womagpbll.Add(womagpmodel);

                    var rets = backid.Split('|');
                    if (rets[0] == "false")
                    {
                        ajresult.state = (int)CodeStatus.执行失败;
                        ajresult.message = "操作失败，" + rets[2];
                    }
                    else
                    {
                        ajresult.state = (int)CodeStatus.SUCCESS;
                        ajresult.message = "操作成功";
                        ajresult.data = rets[1];  //反馈ID
                    }
                }
                else
                {
                    ajresult.state = (int)CodeStatus.数据库错误;
                    ajresult.message = "操作失败,信息已存在";
                }
                AddGriddingLogs(uuid, port_password, "receive", "DealProcess||" + ajresult.message + "||" + content+"||"+ backid, usercode, workorderid, "", "", "", "", "", "", "", "", "", "", 0, 0, 0, 0, mapid);
                trans.Complete();
            }
            return Process();
        }
        /// <summary>
        /// 上传图片接口
        /// 新城办事处网格化对接
        /// </summary>
        /// <returns></returns>
        public ActionResult UploadIMGForGridding()
        {
            Model.T_Bus_WorkOrder_GriddingWO_Map womagpmodel = new Model.T_Bus_WorkOrder_GriddingWO_Map();
            string port_password = RequestString.GetFormString("port_password");   //加密信息(安全验证用)
            string uuid = RequestString.GetFormString("uuid");          //客户唯一标识（安全验证用）
            string workorderid = RequestString.GetFormString("workorderid");
            string usercode = RequestString.GetFormString("usercode");

            string dataurl = RequestString.GetFormString("dataurl");
            string filename = RequestString.GetFormString("filename");
            using (TransactionScope trans = new TransactionScope())
            {
                #region 参数验证
                if (string.IsNullOrEmpty(uuid))
                {
                    ajresult.state = (int)CodeStatus.ID不存在;
                    ajresult.message = "客户唯一标识不能为空";
                    return Process();
                }
                else if (uuid.Length > 50)
                {
                    ajresult.state = (int)CodeStatus.字符串超出长度;
                    ajresult.message = "客户唯一标识超出长度";
                    return Process();
                }
                if (string.IsNullOrEmpty(workorderid))
                {
                    ajresult.state = (int)CodeStatus.必填字段为空;
                    ajresult.message = "工单编号不能为空";
                    return Process();
                }
                if (string.IsNullOrEmpty(usercode))
                {
                    ajresult.state = (int)CodeStatus.必填字段为空;
                    ajresult.message = "工号不能为空";
                    return Process();
                }
                if (string.IsNullOrEmpty(dataurl))
                {
                    ajresult.state = (int)CodeStatus.必填字段为空;
                    ajresult.message = "文件地址不能为空";
                    return Process();
                }
                if (!Common.CodeValidate.ICodeValidateGridding(uuid + workorderid, port_password))
                {
                    ajresult.state = (int)CodeStatus.安全验证未通过;
                    ajresult.message = "安全验证未通过";
                    return Process();
                }
                #endregion
                string path = "/Upload/Gridding/" + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd") + "/";
                int mapid = 0; var resid = 0;
                if (!womagpbll.ExistsByGSWorkOrderId(uuid))  //uuid不存在时,防止重复添加
                {
                    //ar upstr = new ImageUpload().ImgToBase64(dataurl);
                    #region 图片上传
                    ImageUpload iu = new ImageUpload();
                    iu.SavePath = path;
                    iu.DataUrl = dataurl;
                    if (!string.IsNullOrEmpty(filename))
                    {
                        iu.SaveType = 1;
                        iu.InFileName = filename;
                    }
                    iu.Upload64();
                    #endregion
                    
                    int n = iu.Error;
                    if (n == 0)
                    {
                        path = path + iu.OutFileName;

                        #region 附件保存
                        Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
                        model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
                        model_T_Sys_Accessories.F_FileName = iu.OutFileName;//附件名称
                        model_T_Sys_Accessories.F_FileType = ".jpg";//附件类型
                        model_T_Sys_Accessories.F_FileUrl = path;//附件地址
                        model_T_Sys_Accessories.F_Size = iu.FileSize;
                        model_T_Sys_Accessories.F_UserCode = usercode;//上传人  
                        resid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
                        model_T_Sys_Accessories.F_FileId = resid;
                        #endregion
                        if (resid <= 0)
                        {
                            ajresult.state = (int)CodeStatus.执行失败;
                            ajresult.message = "操作失败";
                            return Process();
                        }
                        womagpmodel.F_WorkOrderId = workorderid;
                        womagpmodel.F_GWorkOrderId = uuid;
                        womagpmodel.uuid = uuid;
                        womagpmodel.port_password = port_password;
                        womagpmodel.F_Direction = "receivefile";
                        womagpmodel.F_AddTime = DateTime.Now;
                        mapid = womagpbll.Add(womagpmodel);
                        

                        ajresult.state = (int)CodeStatus.SUCCESS;
                        ajresult.message = "操作成功";
                        ajresult.data = resid;  //反馈ID
                    }
                    else
                    {
                        string msg = string.Empty;
                        switch (n)
                        {
                            case 1: msg = "请选择要上传的文件"; break;
                            case 2: msg = "上传的文件类型不支持"; break;
                            case 3: msg = "上传的文件过大"; break;
                            case 4: msg = "未知错误"; break;
                        }
                        ajresult.state = (int)CodeStatus.异常结果类型;
                        ajresult.message = msg;
                    }
                }
                else
                {
                    ajresult.state = (int)CodeStatus.数据库错误;
                    ajresult.message = "操作失败,信息已存在";
                }
                AddGriddingLogs(uuid, port_password, "receivefile", "UploadIMGForGridding||" + ajresult.message + "||" + path+"||"+ resid.ToString(), usercode, workorderid, "", "", "", "", "", "", "", "", "", "", 0, 0, 0, 0, mapid);
                trans.Complete();
            }
            return Process();
        }
        #region
        ///// <summary>
        ///// 上传附件接口
        ///// 新城办事处网格化对接
        ///// </summary>
        ///// <returns></returns>
        //public ActionResult UploadFileForGridding()
        //{
        //    Model.T_Bus_WorkOrder_GriddingWO_Map womagpmodel = new Model.T_Bus_WorkOrder_GriddingWO_Map();
        //    string port_password = RequestString.GetFormString("port_password");   //加密信息(安全验证用)
        //    string uuid = RequestString.GetFormString("uuid");          //客户唯一标识（安全验证用）
        //    string workorderid = RequestString.GetFormString("workorderid");
        //    string usercode = RequestString.GetFormString("usercode");

        //    string dataurl = RequestString.GetFormString("dataurl");
        //    string filename = RequestString.GetFormString("filename");
        //    #region 参数验证
        //    //if (string.IsNullOrEmpty(uuid))
        //    //{
        //    //    ajresult.state = (int)CodeStatus.ID不存在;
        //    //    ajresult.message = "客户唯一标识不能为空";
        //    //    return Process();
        //    //}
        //    //else if (uuid.Length > 50)
        //    //{
        //    //    ajresult.state = (int)CodeStatus.字符串超出长度;
        //    //    ajresult.message = "客户唯一标识超出长度";
        //    //    return Process();
        //    //}
        //    //if (string.IsNullOrEmpty(workorderid))
        //    //{
        //    //    ajresult.state = (int)CodeStatus.必填字段为空;
        //    //    ajresult.message = "工单编号不能为空";
        //    //    return Process();
        //    //}
        //    //if (string.IsNullOrEmpty(usercode))
        //    //{
        //    //    ajresult.state = (int)CodeStatus.必填字段为空;
        //    //    ajresult.message = "工号不能为空";
        //    //    return Process();
        //    //}
        //    //if (string.IsNullOrEmpty(dataurl))
        //    //{
        //    //    ajresult.state = (int)CodeStatus.必填字段为空;
        //    //    ajresult.message = "文件地址不能为空";
        //    //    return Process();
        //    //}
        //    //if (!Common.CodeValidate.ICodeValidateGridding(uuid + workorderid, port_password))
        //    //{
        //    //    ajresult.state = (int)CodeStatus.安全验证未通过;
        //    //    ajresult.message = "安全验证未通过";
        //    //    return Process();
        //    //}
        //    #endregion
        //    //if (!womagpbll.ExistsByGSWorkOrderId(uuid))  //uuid不存在时,防止重复添加
        //    {
        //        string path = "/Upload/Gridding/" + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd") + "/";

        //        string aLastName = filename.Substring(filename.LastIndexOf(".") + 1, (filename.Length - filename.LastIndexOf(".") - 1)); //扩展名

        //        path = path + filename;
        //        var upstr = new ImageUpload().ImgToBase64(dataurl);
        //        var res = new ImageUpload().Base64ToMP(upstr, path);
        //        var resid = 0;
        //        if (res)
        //        {
        //            #region 附件保存
        //            Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
        //            model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
        //            model_T_Sys_Accessories.F_FileName = filename;//附件名称
        //            model_T_Sys_Accessories.F_FileType = aLastName;//附件类型
        //            model_T_Sys_Accessories.F_FileUrl = path;//附件地址
        //            model_T_Sys_Accessories.F_Size = 0;//iu.FileSize;
        //            model_T_Sys_Accessories.F_UserCode = usercode;//上传人  
        //            resid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
        //            model_T_Sys_Accessories.F_FileId = resid;
        //            #endregion
        //            if (resid <= 0)
        //            {
        //                ajresult.state = (int)CodeStatus.异常结果类型;
        //                ajresult.message = "操作失败";
        //                return Process();
        //            }
        //            womagpmodel.F_WorkOrderId = workorderid;
        //            womagpmodel.F_GWorkOrderId = uuid;
        //            womagpmodel.uuid = uuid;
        //            womagpmodel.port_password = port_password;
        //            womagpmodel.F_Direction = "receivefile";
        //            womagpmodel.F_AddTime = DateTime.Now;
        //            int jj = womagpbll.Add(womagpmodel);
        //            AddGriddingLogs(uuid, port_password, "receivefile", ajresult.message + "||" + path, usercode, workorderid, "", "", "", "", "", "", "", "", "", "", 0, 0, 0, 0, jj);

        //            ajresult.state = (int)CodeStatus.SUCCESS;
        //            ajresult.message = "操作成功";
        //            ajresult.data = resid;  //反馈ID
        //            return Process();
        //        }
        //        else
        //        {
        //            ajresult.state = (int)CodeStatus.异常结果类型;
        //            ajresult.message = "操作失败";
        //            return Process();
        //        }
        //    }
        //    //else
        //    //{
        //    //    ajresult.state = (int)CodeStatus.数据库错误;
        //    //    ajresult.message = "操作失败,信息已存在";
        //    //    return Process();
        //    //}
        //}
        #endregion

        /// <summary>
        /// 上传附件接口
        /// 新城办事处网格化对接
        /// </summary>
        /// <returns></returns>
        public ActionResult UploadUrlForGridding()
        {
            Model.T_Bus_WorkOrder_GriddingWO_Map womagpmodel = new Model.T_Bus_WorkOrder_GriddingWO_Map();
            string port_password = RequestString.GetFormString("port_password");   //加密信息(安全验证用)
            string uuid = RequestString.GetFormString("uuid");          //客户唯一标识（安全验证用）
            string workorderid = RequestString.GetFormString("workorderid");
            string usercode = RequestString.GetFormString("usercode");

            string dataurl = RequestString.GetFormString("dataurl");
            var resid = ""; var mapid = 0;
            using (TransactionScope trans = new TransactionScope())
            {
                #region 参数验证
                if (string.IsNullOrEmpty(uuid))
                {
                    ajresult.state = (int)CodeStatus.ID不存在;
                    ajresult.message = "客户唯一标识不能为空";
                    return Process();
                }
                else if (uuid.Length > 50)
                {
                    ajresult.state = (int)CodeStatus.字符串超出长度;
                    ajresult.message = "客户唯一标识超出长度";
                    return Process();
                }
                if (string.IsNullOrEmpty(workorderid))
                {
                    ajresult.state = (int)CodeStatus.必填字段为空;
                    ajresult.message = "工单编号不能为空";
                    return Process();
                }
                if (string.IsNullOrEmpty(usercode))
                {
                    ajresult.state = (int)CodeStatus.必填字段为空;
                    ajresult.message = "工号不能为空";
                    return Process();
                }
                if (string.IsNullOrEmpty(dataurl))
                {
                    ajresult.state = (int)CodeStatus.必填字段为空;
                    ajresult.message = "文件地址不能为空";
                    return Process();
                }
                if (!Common.CodeValidate.ICodeValidateGridding(uuid + workorderid, port_password))
                {
                    ajresult.state = (int)CodeStatus.安全验证未通过;
                    ajresult.message = "安全验证未通过";
                    return Process();
                }
                #endregion
                if (!womagpbll.ExistsByGSWorkOrderId(uuid))  //uuid不存在时,防止重复添加
                {
                    string path = "/Upload/Gridding/" + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd") + "/";
                    var url = dataurl.Split('|');

                    if (url.Count() > 0)
                    {
                        foreach (var item in url)
                        {
                            var filename = fileup.GetFileName(item);
                            var fileext = fileup.GetExt(item);
                            ImageUpload iu = new ImageUpload();
                            iu.SavePath = path;
                            string fileExtension = Configs.GetValue("fileExtension");
                            if (!fileExtension.Contains((System.IO.Path.GetExtension(fileext).ToLower())))
                            {
                                return Error("附件格式不正确");
                            }
                            var re = iu.downloadurl(item, filename);

                            if (re == "")
                            {
                                #region 附件保存
                                Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
                                model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
                                model_T_Sys_Accessories.F_FileName = filename;//附件名称
                                model_T_Sys_Accessories.F_FileType = fileext;//附件类型
                                model_T_Sys_Accessories.F_FileUrl = path+ filename;//附件地址
                                model_T_Sys_Accessories.F_Size = 0;//iu.FileSize;
                                model_T_Sys_Accessories.F_UserCode = usercode;//上传人  
                                var assid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
                                model_T_Sys_Accessories.F_FileId = assid;
                                #endregion
                                if (assid > 0)
                                {
                                    resid = resid + assid.ToString() + ",";
                                }
                                else
                                    continue;
                            }
                        }
                        resid = resid.Trim(',');
                        #region 接收信息保存
                        womagpmodel.F_WorkOrderId = workorderid;
                        womagpmodel.F_GWorkOrderId = uuid;
                        womagpmodel.uuid = uuid;
                        womagpmodel.port_password = port_password;
                        womagpmodel.F_Direction = "receivefile";
                        womagpmodel.F_AddTime = DateTime.Now;
                        mapid = womagpbll.Add(womagpmodel);

                        #endregion

                        ajresult.state = (int)CodeStatus.SUCCESS;
                        ajresult.message = "操作成功";
                        ajresult.data = resid;  //反馈ID

                    }
                    else
                    {
                        ajresult.state = (int)CodeStatus.无可上传文件;
                        ajresult.message = "无可上传文件";
                    }
                }
                else
                {
                    ajresult.state = (int)CodeStatus.数据库错误;
                    ajresult.message = "操作失败,信息已存在";
                }

                //接收信息日志保存
                AddGriddingLogs(uuid, port_password, "receivefile", "UploadUrlForGridding||" + ajresult.message + "||" + dataurl + "||" + resid, usercode, workorderid, "", "", "", "", "", "", "", "", "", "", 0, 0, 0, 0, mapid);
                trans.Complete();
            }
            return Process();
        }
        #endregion

        /// <summary>
        /// 成功的消息格式化
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        protected virtual ActionResult Process()
        {
            string methodName = new System.Diagnostics.StackTrace(true).GetFrame(1).GetMethod().Name;   //事件源
            LogInterface.WriteLog(this.GetType().ToString() + " -- " + methodName + "\r\n" + ajresult.state + "|" + ajresult.data + ajresult.message); //日志
            var jsonMsg = new AjaxResult { state = ajresult.state, message = ajresult.message, data = ajresult.data }.ToJson();
            return Content(jsonMsg);
        }


        /// <summary>
        /// 处理信息推送（咨询、投诉）
        /// </summary>
        /// <param name="WorkOrderId">唯一标识</param>
        /// <param name="operateUserName">处理人</param>
        /// <param name="operateOrgName">处理人单位</param>
        /// <param name="opinion">处理意见</param>
        /// <param name="operateFlag">处理状态（1: 未处理 2: 处理中 3: 已归档）</param>
        /// <param name="type">处理类型（0:咨询 1:投诉）</param>
        /// <returns>返回（true 成功 false 失败）</returns>
        public bool SaveReplyInfo(string WorkOrderId, string operateUserName, string operateOrgName, string opinion, string operateFlag, string type)
        {
            string methodName = new System.Diagnostics.StackTrace(true).GetFrame(1).GetMethod().Name;   //事件源
            //9咨询 11投诉
            if (type == "9") {
                type = "0"; //0:咨询 1:投诉
            }
            else {
                type = "1";
            }
            if (womapbll.ExistsByWorkOrderId(WorkOrderId))    //WorkOrderId存在时,防止重复添加
            {
                var womap = womapbll.GetModelList(" F_WorkOrderId = " + WorkOrderId + "").FirstOrDefault();
                try
                {
                    string ReqURL = Configs.GetValue("ReplyInfoUrl");
                    string param = "id=" + womap.F_GSWorkOrderId
                        + "&operateUserName=" + operateUserName
                        + "&operateOrgName=" + operateOrgName
                        + "&opinion=" + opinion
                        + "&operateFlag=" + operateFlag
                        + "&type=" + type;
                    string resultReq = HttpMethods.HttpPost(ReqURL, param);
                    JObject result = JObject.Parse(resultReq);
                    if (result["flag"].ToString() == "true")
                    {
                        LogInterface.WriteLog(this.GetType().ToString() + " -- " + methodName + "\r\n" + "Success:订单" + WorkOrderId + "信息推送成功"); //日志
                        return true;
                    }
                    else
                    {
                        LogInterface.WriteLog(this.GetType().ToString() + " -- " + methodName + "\r\n" + "ERROR:订单" + WorkOrderId + "信息推送失败"); //日志
                        return false;
                    }
                }
                catch (Exception ex)
                {
                    LogInterface.WriteLog(this.GetType().ToString() + " -- " + methodName + "\r\n" + "ERROR:订单" + WorkOrderId + "报错" + ex.Message); //日志
                    return false;
                }
            }
            else {
                LogInterface.WriteLog(this.GetType().ToString() + " -- " + methodName + "\r\n" + "ERROR:订单" + WorkOrderId + "信息推送失败"); //日志
                return false;
            }


        }

        /// <summary>
        /// 状态枚举
        /// </summary>
        enum CodeStatus
        {
            SUCCESS = 200,
            安全验证未通过 = 400,
            无法预测的程序错误 = 501,
            参数格式错误 = 100,
            必填字段为空 = 101,
            字符串超出长度 = 102,
            数据库错误 = 103,
            执行超时 = 104,
            参数逻辑错误 = 105,
            ID不存在 = 106,
            无可上传文件=107,
            执行失败 = 108,
            用户已禁用 = 120,
            
            异常结果类型 = 500

        }

        /// <summary>
        /// 添加日志
        /// </summary>
        public void AddGriddingLogs(string uuid,string port_password,string direction,string msg, string usercode, string workorderid, string dealman, string result, string files, string prosituation, string dealcontact, string connecttime, string connectmode, string replycontent, string duties, string situation, int state = 0, int feedbackid = 0, int isproresult = 0, int isstaisfied = 0,int mapid = 0)
        {
            Model.T_Bus_WorkOrder_GriddingWO_logs logs= new Model.T_Bus_WorkOrder_GriddingWO_logs();
            logs.F_WorkOrderId = workorderid;
            logs.F_uuid = uuid;
            logs.F_port_password = port_password;
            logs.F_MapID = mapid;
            logs.F_Direction = direction;
            logs.F_AddTime = DateTime.Now;
            logs.F_Message = msg;

            logs.F_Result = result;

            logs.F_Usercode = usercode;
            logs.F_dealman = dealman;
            logs.F_Files = files;
            logs.F_ProSituation = prosituation;

            logs.F_DealContact = dealcontact;
            logs.F_ConnectTime = connecttime;
            logs.F_ConnectMode = connectmode;
            logs.F_Duties = duties;
            logs.F_Situation = situation;

            logs.F_State = state;
            logs.F_FeedbackID = feedbackid;
            logs.F_IsProResult = isproresult;
            logs.F_IsSatisfied = isstaisfied;


            new BLL.T_Bus_WorkOrder_GriddingWO_logs().Add(logs);
        }
    }
}