Esempio n. 1
0
        /// <summary>
        /// ocr同步到水果通
        /// </summary>
        /// <param name="modelXml"></param>
        /// <returns></returns>
        public void OCRToFruit(HttpContext context)
        {
            SysLogEntity log = new SysLogEntity();

            try
            {
                bool isadd = false;
                //接受
                string id = context.Request.Params["id"];
                Interfaces.OCRWebServ.OcrInvokeServiceImpl serv = new OcrInvokeServiceImpl();
                //判断id是否已经同步
                //serv.Timeout = 20000;//20秒的超时时间
                string xmlData = serv.queryInfo("<?xml version=\"1.0\" encoding=\"utf-8\"?><ROOT><ocrmainid>" + id + "</ocrmainid><token>ocr</token></ROOT>");

                #region xml
                //                string xmlData = @"<freshport>
                //  <flag>true</flag>
                //  <msg/>
                //  <data>
                //    <yw_hddz>
                //      <ocrid>432ce7f1-3012-4e8b-ab81-d6f588afe2bb</ocrid>
                //      <gwgysbm>NEW ZEALAND APPLE LTD</gwgysbm>
                //      <zjsmc>NEW ZEALAND APPLE LTD</zjsmc>
                //      <khbm>Fuhuida Fareast (Xiamen) Corporation.</khbm>
                //      <jydwbm>Fuhuida Fareast (Xiamen) Corporation.</jydwbm>
                //      <hz_spmc>鲜苹果</hz_spmc>
                //      <ysfs>海运</ysfs>
                //      <cyr>中国远洋</cyr>
                //      <cyrbm>中国远洋</cyrbm>
                //      <invoiceno>fp-20160506-1</invoiceno>
                //      <ztdh>td-20160506-1</ztdh>
                //      <ycddm>New zealand1</ycddm>
                //      <ejycd>New zealand</ejycd>
                //      <sfyyf>FREIGHT PREPAID</sfyyf>
                //      <cm>MOL DESTINY</cm>
                //      <hcorhbh>009</hcorhbh>
                //      <zcrq>2015.05.13</zcrq>
                //      <qyg>NAPIER</qyg>
                //      <mdg>SHANGHAI</mdg>
                //      <fh>F3304!7</fh>
                //      <zjz>20916.00</zjz>
                //      <zmz>23240.00</zmz>
                //      <hz_jzxh>TGHU9995270</hz_jzxh>
                //      <hz_xx>40RQ</hz_xx>
                //      <hz_zhlx>40RQ</hz_zhlx>
                //      <jgfs>C&amp;amp;F</jgfs>
                //      <wbbb>USD</wbbb>
                //      <zje>45259.90</zje>
                //      <invoice_date>2015.05.15</invoice_date>
                //      <mygb>New zealand</mygb>
                //      <tzrmc>SHANGHAI YUHUA FRUIT CO. , LTD</tzrmc>
                //      <jldw>CARTONS</jldw>
                //      <details>
                //        <yw_hddz_spxx>
                //          <spmc_yw>Apples</spmc_yw>
                //          <jldw>CARTONS</jldw>
                //          <jlsl>224</jlsl>
                //          <fpje>8724.80</fpje>
                //          <hgbm></hgbm>
                //          <djjg>38.95</djjg>
                //          <spgg_yw>90</spgg_yw>
                //          <sppz_yw>Rose</sppz_yw>
                //          <spdj_yw>HG</spdj_yw>
                //          <sppp_yw></sppp_yw>
                //          <spms></spms>
                //          <zjz>3920.00</zjz>
                //          <zmz>4256.00</zmz>
                //        </yw_hddz_spxx>
                //        <yw_hddz_spxx>
                //          <spmc_yw>Apples</spmc_yw>
                //          <jldw>CARTONS</jldw>
                //          <jlsl>98</jlsl>
                //          <fpje>3817.10</fpje>
                //          <hgbm></hgbm>
                //          <djjg>38.95</djjg>
                //          <spgg_yw>60</spgg_yw>
                //          <sppz_yw>Rose</sppz_yw>
                //          <spdj_yw>HG</spdj_yw>
                //          <sppp_yw></sppp_yw>
                //          <spms></spms>
                //          <zjz></zjz>
                //          <zmz></zmz>
                //        </yw_hddz_spxx>
                //        <yw_hddz_spxx>
                //          <spmc_yw>Apples</spmc_yw>
                //          <jldw>CARTONS</jldw>
                //          <jlsl>392</jlsl>
                //          <fpje>15268.40</fpje>
                //          <hgbm></hgbm>
                //          <djjg>38.95</djjg>
                //          <spgg_yw>80</spgg_yw>
                //          <sppz_yw>Rose</sppz_yw>
                //          <spdj_yw>HG</spdj_yw>
                //          <sppp_yw></sppp_yw>
                //          <spms></spms>
                //          <zjz></zjz>
                //          <zmz></zmz>
                //        </yw_hddz_spxx>
                //        <yw_hddz_spxx>
                //          <spmc_yw>Apples</spmc_yw>
                //          <jldw>CARTONS</jldw>
                //          <jlsl>448</jlsl>
                //          <fpje>17449.60</fpje>
                //          <hgbm></hgbm>
                //          <djjg>38.95</djjg>
                //          <spgg_yw>70</spgg_yw>
                //          <sppz_yw>Rose</sppz_yw>
                //          <spdj_yw>HG</spdj_yw>
                //          <sppp_yw></sppp_yw>
                //          <spms></spms>
                //          <zjz></zjz>
                //          <zmz></zmz>
                //        </yw_hddz_spxx>
                //      </details>
                //    </yw_hddz>
                //  </data>
                //</freshport>";
                #endregion

                List <yw_hddz_spxxEntity>      list     = new List <yw_hddz_spxxEntity>();
                Interfaces.Service.HddzService dbServ   = new Interfaces.Service.HddzService();
                Interfaces.Service.BaseService baseServ = new Interfaces.Service.BaseService();
                yw_hddzEntity editmodel = dbServ.GetHddzModel(id);//主表对象
                yw_hddzEntity model     = new yw_hddzEntity();
                if (editmodel == null)
                {
                    editmodel = new yw_hddzEntity();
                    isadd     = true;
                }
                else
                {
                    isadd = false;
                }

                //解析xml文件
                #region xml测试文件
                //string xmlData = @"<freshport>
                //  <flag>true</flag>
                //  <msg/>
                //  <data><yw_hddz>  <ocrid>432ce7f1-3012-4e8b-ab81-d6f588afe2bb</ocrid>  <gwgysbm>yangliutao</gwgysbm>  <zjsmc>NEW ZEALAND APPLE LTD</zjsmc>  <khbm>yangtao</khbm>  <jydwbm>same</jydwbm>  <ysfs>海运</ysfs>  <cyr>003</cyr>  <invoiceno>fp-20160506-1</invoiceno>  <ztdh>td-20160506-1</ztdh>  <ycddm>4</ycddm>  <ejycd>New zealand</ejycd>  <sfyyf>FREIGHT PREPAID</sfyyf>  <cm>MOL DESTINY</cm>  <hcorhbh>009</hcorhbh>  <czrq/>  <qyg>NAPIER</qyg>  <mdg/>  <fh>F3304!7</fh>  <zjz>20916.00</zjz>  <zmz>23240.00</zmz>  <hz_jzxh>TGHU9995270</hz_jzxh>  <hz_xx>40RQ</hz_xx>  <hz_zhlx>40RQ</hz_zhlx>  <jgfs>C&amp;amp;F</jgfs>  <wbbb>USD</wbbb>  <zje>45259.90</zje>  <invoice_date>13-05-2015</invoice_date>  <details>    <yw_hddz_spxx>      <spmc_yw>Apples</spmc_yw>      <jlsl>224</jlsl>      <fpje>8724.80</fpje>      <or_hscode/>    </yw_hddz_spxx>    <yw_hddz_spxx>      <spmc_yw>Apples</spmc_yw>      <jlsl>98</jlsl>      <fpje>3817.10</fpje>      <or_hscode/>    </yw_hddz_spxx>    <yw_hddz_spxx>      <spmc_yw>Apples</spmc_yw>      <jlsl>392</jlsl>      <fpje>15268.40</fpje>      <or_hscode/>    </yw_hddz_spxx>    <yw_hddz_spxx>      <spmc_yw>Apples</spmc_yw>      <jlsl>448</jlsl>      <fpje>17449.60</fpje>      <or_hscode/>    </yw_hddz_spxx>  </details></yw_hddz></data>
                //</freshport>";
                #endregion

                Interfaces.MasterDataResponse mdr = new Interfaces.MasterDataResponse(xmlData);
                log.otherID = id;
                #region 返回数据异常处理
                if (!mdr.flag)//执行失败
                {
                    log.msg    = mdr.GetMsgStr <yw_hddzEntity>();
                    res.msg    = log.msg;
                    res.result = false;
                    //strrep = "{\"result\":false,\"message\":\"" + log.msg + "\"}";
                }
                else
                {
                    //把xml转化成对象
                    OcrXmlToHddz(mdr.data, out model, out list);


                    #region 基础表名称对应代码
                    List <yw_hddz_ocrvalmapEntity> errordatelist = new List <yw_hddz_ocrvalmapEntity>();

                    #region 国外供应商
                    if (!string.IsNullOrEmpty(model.gwgysbm))
                    {
                        yw_wldwEntity gwgys = Interfaces.Service.BaseService.GetWldwModel(model.gwgysbm);
                        if (gwgys != null)
                        {
                            model.gwgysbm = gwgys.yw_khbm;
                            model.gwgysjc = gwgys.khjc;
                            model.gwgysmc = gwgys.khmc_yw;
                        }
                        else
                        {
                            yw_hddz_ocrvalmapEntity errData = new yw_hddz_ocrvalmapEntity();
                            errData.field     = "gwgys";
                            errData.fieldname = "国外供应商";
                            errData.ocrvalue  = model.gwgysbm;
                            errData.tablename = "yw_wldw";
                            errordatelist.Add(errData);
                        }
                    }
                    #endregion

                    #region 客户
                    if (!string.IsNullOrEmpty(model.khbm))
                    {
                        yw_wldwEntity kh = Interfaces.Service.BaseService.GetWldwModel(model.khbm);
                        if (kh != null)
                        {
                            model.khbm  = kh.yw_khbm;
                            model.khjc  = kh.khjc;
                            model.khmc  = kh.khmc;
                            model.khpym = kh.pym;
                        }
                        else
                        {
                            yw_hddz_ocrvalmapEntity errData = new yw_hddz_ocrvalmapEntity();
                            errData.field     = "kh";
                            errData.fieldname = "委托客户";
                            errData.ocrvalue  = model.khbm;
                            errData.tablename = "yw_wldw";
                            errordatelist.Add(errData);
                        }
                    }
                    #endregion

                    #region 经营单位
                    if (!string.IsNullOrEmpty(model.jydwbm))
                    {
                        yw_wldwEntity jydw = Interfaces.Service.BaseService.GetWldwModel(model.jydwbm);
                        if (jydw != null)
                        {
                            model.jydwbm  = jydw.yw_khbm;
                            model.jydwjc  = jydw.khjc;
                            model.jydwmc  = jydw.khmc;
                            model.jydwpym = jydw.pym;
                        }
                        else
                        {
                            yw_hddz_ocrvalmapEntity errData = new yw_hddz_ocrvalmapEntity();
                            errData.field     = "jydw";
                            errData.fieldname = "经营单位";
                            errData.ocrvalue  = model.jydwbm;
                            errData.tablename = "yw_wldw";
                            errordatelist.Add(errData);
                        }
                    }
                    #endregion

                    #region 承运人
                    if (!string.IsNullOrEmpty(model.cyr))
                    {
                        yw_wldwEntity cyr = Interfaces.Service.BaseService.GetWldwModel(model.cyr);
                        if (cyr != null)
                        {
                            model.cyrbm  = cyr.yw_khbm;
                            model.cyrjc  = cyr.khjc;
                            model.cyr    = cyr.khmc;
                            model.cyrpym = cyr.pym;
                        }
                        else
                        {
                            yw_hddz_ocrvalmapEntity errData = new yw_hddz_ocrvalmapEntity();
                            errData.field     = "cyr";
                            errData.fieldname = "承运人";
                            errData.ocrvalue  = model.cyrbm;
                            errData.tablename = "yw_wldw";
                            errordatelist.Add(errData);
                        }
                    }
                    #endregion

                    #region 中间商
                    if (!string.IsNullOrEmpty(model.zjsmc))
                    {
                        yw_wldwEntity zjs = Interfaces.Service.BaseService.GetWldwModel(model.zjsmc);
                        if (zjs != null)
                        {
                            model.zjsbm  = zjs.yw_khbm;
                            model.zjsjc  = zjs.khjc;
                            model.zjsmc  = zjs.khmc_yw;
                            model.zjspym = zjs.pym;
                        }
                        else
                        {
                            yw_hddz_ocrvalmapEntity errData = new yw_hddz_ocrvalmapEntity();
                            errData.field     = "zjs";
                            errData.fieldname = "中间商";
                            errData.ocrvalue  = model.zjsmc;
                            errData.tablename = "yw_wldw";
                            errordatelist.Add(errData);
                        }
                    }
                    #endregion

                    #region 通知人
                    if (!string.IsNullOrEmpty(model.tzrmc))
                    {
                        yw_wldwEntity tzr = Interfaces.Service.BaseService.GetWldwModel(model.tzrmc);
                        if (tzr != null)
                        {
                            model.tzrbm  = tzr.yw_khbm;
                            model.tzrjc  = tzr.khjc;
                            model.tzrmc  = tzr.khmc;
                            model.tzrpym = tzr.pym;
                        }
                        else
                        {
                            yw_hddz_ocrvalmapEntity errData = new yw_hddz_ocrvalmapEntity();
                            errData.field     = "tzr";
                            errData.fieldname = "通知人";
                            errData.ocrvalue  = model.tzrmc;
                            errData.tablename = "yw_wldw";
                            errordatelist.Add(errData);
                        }
                    }
                    #endregion

                    #region 原产地
                    if (!string.IsNullOrEmpty(model.ycddm))
                    {
                        t_countryEntity ycd = Interfaces.Service.BaseService.GetCountryModel(model.ycddm);
                        if (ycd != null)
                        {
                            model.ycd   = ycd.ctr_ename;
                            model.ycddm = ycd.ctr_hgcode;
                            model.dqdm  = ycd.dqdm;
                        }
                        else
                        {
                            yw_hddz_ocrvalmapEntity errData = new yw_hddz_ocrvalmapEntity();
                            errData.field     = "ycd";
                            errData.fieldname = "原产地";
                            errData.ocrvalue  = model.ycddm;
                            errData.tablename = "t_country";
                            errordatelist.Add(errData);
                        }
                    }
                    #endregion

                    #endregion
                    //完善对象字段
                    #region 根据代码完善数据
                    model.sfyyf = model.sfyyf == "FREIGHT PREPAID" ? "N" : "Y";
                    model.jgfs  = model.jgfs.Replace("&amp;", "&");
                    #endregion


                    #region 数据保存
                    if (errordatelist.Count == 0)//没有错误才能保存
                    {
                        if (isadd)
                        {
                            model.zbr = QsWebSoft.AppService.GetUserID();
                            if (model.ysfs.Trim() == "海运")
                            {
                                model.ywbh = new Interfaces.Service.HddzService().GetNewYwbh(DateTime.Now.ToString("yy") + model.dqdm);
                            }
                            else
                            {
                                model.ywbh = new Interfaces.Service.HddzService().GetNewYwbh(DateTime.Now.ToString("yy") + "OC");
                            }

                            model.zbrq  = DateTime.Now;
                            model.state = "新制";
                            //分录商品表 赋值ywbh
                        }
                        else
                        {
                            model.ywbh           = editmodel.ywbh;
                            model.zbrq           = editmodel.zbrq;
                            model.zbr            = editmodel.zbr;
                            model.state          = editmodel.state;
                            model.SupplierSellID = editmodel.SupplierSellID;
                            model.shdwbm         = editmodel.shdwbm;
                        }
                        list.ForEach(p => p.ywbh = model.ywbh);
                        log.ywbh = model.ywbh;
                        //保存数据
                        if (isadd)
                        {
                            dbServ.SaveHddz(model, list);
                        }
                        else
                        {
                            dbServ.ModifyHddz(model, list);
                        }
                        res.result = true;
                        log.msg    = "编号为" + model.ywbh + "的数据保存成功";
                    }
                    else//把错误和数据抛到前端
                    {
                        res.id        = id;
                        res.data      = model;
                        res.data1     = list;
                        res.errordata = errordatelist;
                        res.errortype = 1;
                        res.msg       = log.msg = "有未匹配的值。";
                        res.result    = false;
                    }

                    #endregion
                }

                #endregion
            }
            catch (Exception ex)
            {
                log.msg       = ex.Message.Replace(Environment.NewLine, "");
                res.msg       = log.msg;
                res.result    = false;
                res.errortype = 2;
            }
            strrep = JsonConvert.SerializeObject(res);
            context.Response.Write(strrep);
        }
Esempio n. 2
0
        /// <summary>
        /// 错误处理后提交
        /// </summary>
        /// <param name="context"></param>
        public void JsonToFruit(HttpContext context)
        {
            SysLogEntity log = new SysLogEntity();

            try
            {
                #region 接受数据、声明变量

                bool isadd = false;
                Interfaces.Service.HddzService dbServ = new Interfaces.Service.HddzService();
                string        strData = context.Request.Params["data"];
                yw_hddzEntity model   = JsonConvert.DeserializeObject <yw_hddzEntity>(strData);

                string strErrorData = context.Request.Params["errdata"];
                List <yw_hddz_ocrvalmapEntity> maplist = JsonConvert.DeserializeObject <List <yw_hddz_ocrvalmapEntity> >(strErrorData);

                string strspxx = context.Request.Params["data1"];
                List <yw_hddz_spxxEntity> spxxlist = JsonConvert.DeserializeObject <List <yw_hddz_spxxEntity> >(strspxx);
                #endregion

                #region 判断是否已经有对应数据
                yw_hddzEntity editmodel = dbServ.GetHddzModel(model.OcrID);//主表对象

                if (editmodel == null)
                {
                    editmodel = new yw_hddzEntity();
                    isadd     = true;
                }
                else
                {
                    isadd = false;
                }
                #endregion

                #region 关系映射
                //保存值对应关系
                maplist.ForEach(p => p.ID = Guid.NewGuid().ToString());

                List <yw_hddz_ocrvalmapEntity> addmaplist = new List <yw_hddz_ocrvalmapEntity>();
                foreach (var mapinfo in maplist)
                {
                    if (string.IsNullOrEmpty(mapinfo.value))//如果没有选择对应值 则需要快速创建
                    {
                        #region 往来单位
                        if (mapinfo.tablename == "yw_wldw")
                        {
                            Interfaces.Service.BaseService.AddWldw(mapinfo.ocrvalue);
                            switch (mapinfo.field)
                            {
                            case "gwgys":
                                #region 国外供应商
                                if (!string.IsNullOrEmpty(model.gwgysbm))
                                {
                                    yw_wldwEntity gwgys = Interfaces.Service.BaseService.GetWldwModel(model.gwgysbm);
                                    if (gwgys != null)
                                    {
                                        model.gwgysbm = gwgys.khbm;
                                        model.gwgysjc = gwgys.khjc;
                                        model.gwgysmc = gwgys.khmc_yw;
                                    }
                                }
                                #endregion
                                break;

                            case "kh":
                                #region 客户
                                if (!string.IsNullOrEmpty(model.khbm))
                                {
                                    yw_wldwEntity kh = Interfaces.Service.BaseService.GetWldwModel(model.khbm);
                                    if (kh != null)
                                    {
                                        model.khbm  = kh.khbm;
                                        model.khjc  = kh.khjc;
                                        model.khmc  = kh.khmc;
                                        model.khpym = kh.pym;
                                    }
                                }
                                #endregion
                                break;

                            case "jydw":
                                #region 经营单位
                                if (!string.IsNullOrEmpty(model.jydwbm))
                                {
                                    yw_wldwEntity jydw = Interfaces.Service.BaseService.GetWldwModel(model.jydwbm);
                                    if (jydw != null)
                                    {
                                        model.jydwbm  = jydw.khbm;
                                        model.jydwjc  = jydw.khjc;
                                        model.jydwmc  = jydw.khmc;
                                        model.jydwpym = jydw.pym;
                                    }
                                }
                                #endregion
                                break;

                            case "cyr":
                                #region 承运人
                                if (!string.IsNullOrEmpty(model.cyrbm))
                                {
                                    yw_wldwEntity cyr = Interfaces.Service.BaseService.GetWldwModel(model.cyrbm);
                                    if (cyr != null)
                                    {
                                        model.cyrbm  = cyr.khbm;
                                        model.cyrjc  = cyr.khjc;
                                        model.cyr    = cyr.khmc;
                                        model.cyrpym = cyr.pym;
                                    }
                                }
                                #endregion
                                break;

                            case "zjs":
                                #region 中间商
                                if (!string.IsNullOrEmpty(model.zjsmc))
                                {
                                    yw_wldwEntity zjs = Interfaces.Service.BaseService.GetWldwModel(model.zjsmc);
                                    if (zjs != null)
                                    {
                                        model.zjsbm  = zjs.khbm;
                                        model.zjsjc  = zjs.khjc;
                                        model.zjsmc  = zjs.khmc;
                                        model.zjspym = zjs.pym;
                                    }
                                }
                                #endregion
                                break;

                            case "tzr":
                                #region 通知人
                                if (!string.IsNullOrEmpty(model.tzrmc))
                                {
                                    yw_wldwEntity tzr = Interfaces.Service.BaseService.GetWldwModel(model.tzrmc);
                                    if (tzr != null)
                                    {
                                        model.tzrbm  = tzr.khbm;
                                        model.tzrjc  = tzr.khjc;
                                        model.tzrmc  = tzr.khmc;
                                        model.tzrpym = tzr.pym;
                                    }
                                }
                                #endregion
                                break;
                            }
                        }
                        #endregion
                        else if (mapinfo.tablename == "t_country")
                        {
                            throw new Exception("原产地没有选择对应值!");
                            //model.ycd = model.ycd;
                        }
                    }
                    else
                    {
                        mapinfo.ID = Guid.NewGuid().ToString();
                        addmaplist.Add(mapinfo);
                    }
                }

                Interfaces.Service.BaseService.AddMapList(addmaplist);
                #endregion

                #region 保存数据
                if (isadd)
                {
                    model.zbr = QsWebSoft.AppService.GetUserID();
                    if (model.ysfs.Trim() == "海运")
                    {
                        model.ywbh = new Interfaces.Service.HddzService().GetNewYwbh(DateTime.Now.ToString("yy") + model.dqdm);
                    }
                    else
                    {
                        model.ywbh = new Interfaces.Service.HddzService().GetNewYwbh(DateTime.Now.ToString("yy") + "OC");
                    }

                    model.zbrq  = DateTime.Now;
                    model.state = "新制";
                    //分录商品表 赋值ywbh
                }
                else
                {
                    model.ywbh           = editmodel.ywbh;
                    model.zbrq           = editmodel.zbrq;
                    model.zbr            = editmodel.zbr;
                    model.state          = editmodel.state;
                    model.SupplierSellID = editmodel.SupplierSellID;
                    model.shdwbm         = editmodel.shdwbm;
                }
                spxxlist.ForEach(p => p.ywbh = model.ywbh);
                //保存数据
                if (isadd)
                {
                    dbServ.SaveHddz(model, spxxlist);
                }
                else
                {
                    dbServ.ModifyHddz(model, spxxlist);
                }


                res.result = true;
                log.msg    = "编号为" + model.ywbh + "的数据保存成功";

                #endregion
            }
            catch (Exception ex)
            {
                log.msg       = ex.Message.Replace(Environment.NewLine, "");
                res.msg       = log.msg;
                res.result    = false;
                res.errortype = 2;
            }
            strrep = JsonConvert.SerializeObject(res);
            context.Response.Write(strrep);
        }
        /// <summary>
        /// 异常拦截
        /// </summary>
        /// <param name="actionExecutedContext"></param>
        public override async void OnException(HttpActionExecutedContext actionExecutedContext)
        {
            StringBuilder sqlLogText = new StringBuilder();

            try
            {
                var controller         = actionExecutedContext.ActionContext.ControllerContext.Controller;
                var unitOfWorkProperty = controller.GetType().BaseType.GetField("_UnitOfWorks", System.Reflection.BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
                var unitOfWorkDict     = (Dictionary <string, IUnitOfWork>)unitOfWorkProperty.GetValue(controller);

                var            serviceContextProperty = controller.GetType().BaseType.GetProperty("ServiceContext", System.Reflection.BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
                ServiceContext serviceContext         = serviceContextProperty.GetValue(controller) as ServiceContext;

                string fuWuCsStr = await actionExecutedContext.ActionContext.Request.Content.ReadAsStringAsync();

                // 获取服务信息
                string pathAndQuery = actionExecutedContext.ActionContext.Request.RequestUri.PathAndQuery;
                string moKuaiMc     = pathAndQuery.Split('/')[1];
                string yeWuMc       = pathAndQuery.Split('/')[2];
                string caoZuoMc     = pathAndQuery.Split('/')[3];


                //ESLog eSLog = new ESLog();


                List <string> unitOfWorkKeys = new List <string>(unitOfWorkDict.Keys);
                for (int i = 0; i < unitOfWorkDict.Values.Count; i++)
                {
                    IUnitOfWork unitOfWork = unitOfWorkDict[unitOfWorkKeys[i]];
                    try
                    {
                        #region 记录SQL日志

                        // 记录日志=====================================================================
                        if (!string.IsNullOrWhiteSpace(unitOfWork.SqlLog.ToString()))
                        {
                            sqlLogText.AppendLine(unitOfWork.SqlLog.ToString());

                            SysLogEntity sqlLogEntity = new SysLogEntity();
                            sqlLogEntity.RiZhiID      = Guid.NewGuid().ToString();
                            sqlLogEntity.ChuangJianSj = DateTime.Now.ToInvariantString("yyyy/MM/dd HH:mm:ss");
                            sqlLogEntity.RiZhiBt      = "[" + moKuaiMc + "/" + yeWuMc + "/" + caoZuoMc + "]服务运行期间的SQL记录。";
                            sqlLogEntity.RiZhiNr      = unitOfWork.SqlLog.ToString();

                            sqlLogEntity.FuWuMc    = moKuaiMc + "/" + yeWuMc + "/" + caoZuoMc;
                            sqlLogEntity.QingQiuLy = serviceContext.DANGQIANCKMC;
                            // 日志类型:1.菜单打开,2.客户端异常,3.服务调用,4服务端异常,5.SQL日志,6.性能日志
                            sqlLogEntity.RiZhiLx = 5;

                            sqlLogEntity.YINGYONGID   = serviceContext.YINGYONGID;
                            sqlLogEntity.XITONGID     = serviceContext.XITONGID;
                            sqlLogEntity.YINGYONGMC   = serviceContext.YINGYONGMC;
                            sqlLogEntity.YINGYONGJC   = serviceContext.YINGYONGJC;
                            sqlLogEntity.VERSION      = serviceContext.VERSION;
                            sqlLogEntity.IP           = serviceContext.IP;
                            sqlLogEntity.MAC          = serviceContext.MAC;
                            sqlLogEntity.COMPUTERNAME = serviceContext.COMPUTERNAME;
                            sqlLogEntity.USERNAME     = serviceContext.USERNAME;
                            sqlLogEntity.USERID       = serviceContext.USERID;
                            sqlLogEntity.KESHIID      = serviceContext.KESHIID;
                            sqlLogEntity.KESHIMC      = serviceContext.KESHIMC;
                            sqlLogEntity.BINGQUID     = serviceContext.BINGQUID;
                            sqlLogEntity.BINGQUMC     = serviceContext.BINGQUMC;
                            sqlLogEntity.JIUZHENKSID  = serviceContext.JIUZHENKSID;
                            sqlLogEntity.JIUZHENKSMC  = serviceContext.JiuZhenKSMC;
                            sqlLogEntity.YUANQUID     = serviceContext.YUANQUID;
                            sqlLogEntity.GONGZUOZID   = serviceContext.GONGZUOZID;
                            //eSLog.PutLog(sqlLogEntity);
                            LogHelper.Intance.PutSysInfoLog(sqlLogEntity);
                        }
                        // 记录日志=====================================================================

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        unitOfWork.Rollback();
                        unitOfWork.Dispose();
                        unitOfWork = null;
                    }
                }
                unitOfWorkKeys.Clear();

                #region 记录日志

                // 记录日志=====================================================================

                SysLogEntity logEntity = new SysLogEntity();
                logEntity.RiZhiID      = Guid.NewGuid().ToString();
                logEntity.ChuangJianSj = DateTime.Now.ToInvariantString("yyyy/MM/dd HH:mm:ss");
                logEntity.RiZhiBt      = serviceContext.USERNAME + "[" + serviceContext.USERID + "]调用[" + moKuaiMc + "/" + yeWuMc + "/" + caoZuoMc + "]服务发生错误。";
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.AppendLine(serviceContext.USERNAME + "[" + serviceContext.USERID + "]调用[" + moKuaiMc + "/" + yeWuMc + "/" + caoZuoMc + "]服务发生错误。");
                stringBuilder.AppendLine();
                stringBuilder.AppendLine("参数列表:");
                // 服务参数
                var fuWuCsList = QueryUrl.GetData(fuWuCsStr);
                foreach (var item in fuWuCsList)
                {
                    stringBuilder.AppendLine(item.Key + "=" + Uri.UnescapeDataString(item.Value).DecompressString());
                }
                stringBuilder.AppendLine();
                stringBuilder.AppendLine("异常信息:");

                if (actionExecutedContext.Exception is BaseException)
                {
                    var exct = (BaseException)actionExecutedContext.Exception;
                    stringBuilder.Append(exct.ErrorMessage);
                }

                stringBuilder.AppendLine(actionExecutedContext.Exception.ToString());
                stringBuilder.AppendLine("异常信息Json:");
                try
                {
                    stringBuilder.AppendLine(JsonUtil.SerializeObject(actionExecutedContext.Exception));
                }
                catch (Exception ex)
                {
                    stringBuilder.Append("转换json日志时发生错误:" + ex.ToString());
                }

                stringBuilder.AppendLine("SQL日志:");
                stringBuilder.AppendLine(sqlLogText.ToString());

                logEntity.RiZhiNr   = stringBuilder.ToString();
                logEntity.FuWuMc    = moKuaiMc + "/" + yeWuMc + "/" + caoZuoMc;
                logEntity.QingQiuLy = serviceContext.DANGQIANCKMC;
                // 日志类型:1.菜单打开,2.客户端异常,3.服务调用,4服务端异常,5.SQL日志,6.性能日志
                logEntity.RiZhiLx      = 4;
                logEntity.YINGYONGID   = serviceContext.YINGYONGID;
                logEntity.XITONGID     = serviceContext.XITONGID;
                logEntity.YINGYONGMC   = serviceContext.YINGYONGMC;
                logEntity.YINGYONGJC   = serviceContext.YINGYONGJC;
                logEntity.VERSION      = serviceContext.VERSION;
                logEntity.IP           = serviceContext.IP;
                logEntity.MAC          = serviceContext.MAC;
                logEntity.COMPUTERNAME = serviceContext.COMPUTERNAME;
                logEntity.USERNAME     = serviceContext.USERNAME;
                logEntity.USERID       = serviceContext.USERID;
                logEntity.KESHIID      = serviceContext.KESHIID;
                logEntity.KESHIMC      = serviceContext.KESHIMC;
                logEntity.BINGQUID     = serviceContext.BINGQUID;
                logEntity.BINGQUMC     = serviceContext.BINGQUMC;
                logEntity.JIUZHENKSID  = serviceContext.JIUZHENKSID;
                logEntity.JIUZHENKSMC  = serviceContext.JiuZhenKSMC;
                logEntity.YUANQUID     = serviceContext.YUANQUID;
                logEntity.GONGZUOZID   = serviceContext.GONGZUOZID;
                //eSLog.PutLog(logEntity);
                LogHelper.Intance.PutSysErrorLog(logEntity);
                // 记录日志=====================================================================

                #endregion

                var requestContextCacheProperty = controller.GetType().BaseType.GetField("_RequestContextCache", System.Reflection.BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
                if (requestContextCacheProperty != null)
                {
                    var requestContextCacheObj = requestContextCacheProperty.GetValue(controller);
                    if (requestContextCacheObj != null)
                    {
                        var requestContextCache = (ContextCache)requestContextCacheObj;
                        requestContextCache.Clear();
                        requestContextCache.Dispose();
                        requestContextCache = null;
                    }
                }

                // 如果截获异常为我们自定义,可以处理的异常则通过我们自己的规则处理
                ServiceResult serviceResult = new ServiceResult("-1", "服务器发生未知错误!", "服务器发生未知错误!");
                if (actionExecutedContext.Exception is ApplicationException)
                {
                    serviceResult = new ServiceResult("-1", actionExecutedContext.Exception.Message, actionExecutedContext.Exception.ToString() + "\n" + sqlLogText);
                }
                if (actionExecutedContext.Exception is UnauthorizedException)
                {
                    serviceResult = new ServiceResult("-5", actionExecutedContext.Exception.Message, actionExecutedContext.Exception.ToString() + "\n" + sqlLogText);
                }
                else if (actionExecutedContext.Exception is ServiceException)
                {
                    var exception = (ServiceException)actionExecutedContext.Exception;
                    serviceResult = new ServiceResult(exception.ErrorCode.ToString(), exception.ErrorMessage, JsonUtil.SerializeObject(actionExecutedContext.Exception) + "\n" + sqlLogText);
                }
                else if (actionExecutedContext.Exception is BaseException)
                {
                    var exception = (BaseException)actionExecutedContext.Exception;
                    serviceResult = new ServiceResult(exception.ErrorCode.ToString(), exception.ErrorMessage, JsonUtil.SerializeObject(actionExecutedContext.Exception) + "\n" + sqlLogText);
                }

                else
                {
                    serviceResult = new ServiceResult("-1", actionExecutedContext.Exception.Message, JsonUtil.SerializeObject(actionExecutedContext.Exception) + "\n" + sqlLogText);
                }

                // 记录服务调用耗时日志
                var ServiceStartTimeProperty = controller.GetType().BaseType.GetField("_ServiceStartTime", System.Reflection.BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
                if (ServiceStartTimeProperty != null)
                {
                    var ServiceStartTimeObj = ServiceStartTimeProperty.GetValue(controller);
                    if (ServiceStartTimeObj != null)
                    {
                        var      serviceStartTime = (long)ServiceStartTimeObj;
                        long     nowTicks         = DateTime.Now.Ticks;
                        DateTime dateTime         = new DateTime(nowTicks - serviceStartTime);
                        float    haoShi           = (float)Math.Round((decimal)((nowTicks - serviceStartTime) / 10000000d), 4);

                        SysLogEntity logTimeEntity = new SysLogEntity
                        {
                            RiZhiID      = Guid.NewGuid().ToString(),
                            ChuangJianSj = DateTime.Now.ToInvariantString("yyyy/MM/dd HH:mm:ss"),
                            RiZhiBt      = serviceContext.USERNAME + "[" + serviceContext.USERID + "]调用[" + moKuaiMc + "/" + yeWuMc + "/" + caoZuoMc + "]服务,总耗时:" + haoShi + "秒。",
                            RiZhiNr      = "[服务调用耗时:" + haoShi + "秒] " + stringBuilder.ToString() + sqlLogText.ToString(),
                            FuWuHs       = haoShi, // 添加耗时
                            FuWuMc       = moKuaiMc + "/" + yeWuMc + "/" + caoZuoMc,
                            QingQiuLy    = serviceContext.DANGQIANCKMC,
                            // 日志类型:1.菜单打开,2.客户端异常,3.服务调用,4服务端异常,5.SQL日志,6.性能日志
                            RiZhiLx      = 6,
                            YINGYONGID   = serviceContext.YINGYONGID,
                            XITONGID     = serviceContext.XITONGID,
                            YINGYONGMC   = serviceContext.YINGYONGMC,
                            YINGYONGJC   = serviceContext.YINGYONGJC,
                            VERSION      = serviceContext.VERSION,
                            IP           = serviceContext.IP,
                            MAC          = serviceContext.MAC,
                            COMPUTERNAME = serviceContext.COMPUTERNAME,
                            USERNAME     = serviceContext.USERNAME,
                            USERID       = serviceContext.USERID,
                            KESHIID      = serviceContext.KESHIID,
                            KESHIMC      = serviceContext.KESHIMC,
                            BINGQUID     = serviceContext.BINGQUID,
                            BINGQUMC     = serviceContext.BINGQUMC,
                            JIUZHENKSID  = serviceContext.JIUZHENKSID,
                            JIUZHENKSMC  = serviceContext.JiuZhenKSMC,
                            YUANQUID     = serviceContext.YUANQUID,
                            GONGZUOZID   = serviceContext.GONGZUOZID
                        };
                        //eSLog.PutLog(logTimeEntity);
                        LogHelper.Intance.PutSysInfoLog(logTimeEntity);
                    }
                }

                actionExecutedContext.Response =
                    actionExecutedContext.Request.CreateResponse(HttpStatusCode.OK,
                                                                 serviceResult);
            }
            catch (Exception ex)
            {
                try
                {
                    // 返回错误信息,并向客户端传递错误
                    var            controller             = actionExecutedContext.ActionContext.ControllerContext.Controller;
                    var            serviceContextProperty = controller.GetType().BaseType.GetProperty("ServiceContext", System.Reflection.BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
                    ServiceContext serviceContext         = serviceContextProperty.GetValue(controller) as ServiceContext;

                    var serviceResult = new ServiceResult("-1", actionExecutedContext.Exception.Message + "ApiExceptionFilterAttribute处理OnException报错:" + ex.Message, JsonUtil.SerializeObject(actionExecutedContext.Exception) + "\n" + JsonUtil.SerializeObject(ex) + "\n" + sqlLogText);

                    actionExecutedContext.Response =
                        actionExecutedContext.Request.CreateResponse(HttpStatusCode.OK,
                                                                     serviceResult);
                    // 本地日志
                    LogHelper.Intance.Error("系统日志", "ApiExceptionFilterAttribute处理OnException报错", "ApiActionFilterAttribute处理OnActionExecuted报错:" + ex.ToString() + "\r\n" + JsonUtil.SerializeObject(serviceContext));
                }
                catch (Exception iex)
                {
                    // 增加捕获异常的异常的处理
                    LogHelper.Intance.Error("ApiExceptionFilterAttribute", "ApiExceptionFilterAttribute处理OnException报错,在异常处理中再次报错", "直接异常:" + ex.ToString() + ";捕获处理异常:" + iex.ToString());
                }
            }
        }
        /// <summary>
        /// 服务执行后
        /// </summary>
        /// <param name="actionExecutedContext"></param>
        public override async void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            try
            {
                var controller         = actionExecutedContext.ActionContext.ControllerContext.Controller;
                var unitOfWorkProperty = controller.GetType().BaseType.GetField("_UnitOfWorks", System.Reflection.BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
                var unitOfWorkDict     = (Dictionary <string, IUnitOfWork>)unitOfWorkProperty.GetValue(controller);

                var            serviceContextProperty = controller.GetType().BaseType.GetProperty("ServiceContext", System.Reflection.BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
                ServiceContext serviceContext         = serviceContextProperty.GetValue(controller) as ServiceContext;

                string fuWuCsStr = await actionExecutedContext.ActionContext.Request.Content.ReadAsStringAsync();

                // 获取服务完整地址信息
                string serviceUri = actionExecutedContext.ActionContext.Request.RequestUri.ToString();

                // 获取服务信息
                string pathAndQuery = actionExecutedContext.ActionContext.Request.RequestUri.PathAndQuery;
                string server       = actionExecutedContext.ActionContext.Request.RequestUri.Host;
                string port         = actionExecutedContext.ActionContext.Request.RequestUri.Port.ToString();
                string moKuaiMc     = pathAndQuery.Split('/')[1];
                string yeWuMc       = pathAndQuery.Split('/')[2];
                string caoZuoMc     = pathAndQuery.Split('/')[3];

                StringBuilder sqlLogText = new StringBuilder();

                //ESLog eSLog = new ESLog();
                StringBuilder stringBuilder = new StringBuilder();

                #region 记录调用日志

                // 记录日志=====================================================================
                try
                {
                    SysLogEntity logEntity = new SysLogEntity();
                    logEntity.RiZhiID      = Guid.NewGuid().ToString();
                    logEntity.ChuangJianSj = DateTime.Now.ToInvariantString("yyyy/MM/dd HH:mm:ss");
                    logEntity.RiZhiBt      = serviceContext.USERNAME + "[" + serviceContext.USERID + "]成功调用了[" + moKuaiMc + "/" + yeWuMc + "/" + caoZuoMc + "]服务。";

                    stringBuilder.AppendLine(serviceContext.USERNAME + "[" + serviceContext.USERID + "]成功调用了[" + server + ":" + port + "端口上的" + serviceUri + "]服务。");

                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("参数列表:");
                    // 服务参数
                    var fuWuCsList = QueryUrl.GetData(fuWuCsStr);
                    foreach (var item in fuWuCsList)
                    {
                        stringBuilder.AppendLine(item.Key + "=" + Uri.UnescapeDataString(item.Value).DecompressString());
                    }

                    try
                    {
                        var res = await actionExecutedContext.Response.Content.ReadAsStringAsync();

                        ServiceResult serviceResult = JsonUtil.DeserializeToObject <ServiceResult>(res);
                        serviceResult.ReturnCode       = serviceResult.ReturnCode.DecompressString();
                        serviceResult.ReturnMessage    = serviceResult.ReturnMessage.DecompressString();
                        serviceResult.ExceptionContent = serviceResult.ExceptionContent.DecompressString();
                        serviceResult.Content          = serviceResult.Content.DecompressString();

                        stringBuilder.AppendLine("返回内容:");
                        stringBuilder.AppendLine(JsonUtil.SerializeObject(serviceResult));
                    }
                    catch (Exception ex)
                    {
                        stringBuilder.AppendLine("返回内容:无,信息:" + ex.ToString());
                    }



                    logEntity.RiZhiNr   = stringBuilder.ToString();
                    logEntity.FuWuMc    = moKuaiMc + "/" + yeWuMc + "/" + caoZuoMc;
                    logEntity.QingQiuLy = serviceContext.DANGQIANCKMC;
                    // 日志类型:1.菜单打开,2.客户端异常,3.服务调用,4服务端异常,5.SQL日志,6.性能日志
                    logEntity.RiZhiLx      = 3;
                    logEntity.YINGYONGID   = serviceContext.YINGYONGID;
                    logEntity.XITONGID     = serviceContext.XITONGID;
                    logEntity.YINGYONGMC   = serviceContext.YINGYONGMC;
                    logEntity.YINGYONGJC   = serviceContext.YINGYONGJC;
                    logEntity.VERSION      = serviceContext.VERSION;
                    logEntity.IP           = serviceContext.IP;
                    logEntity.MAC          = serviceContext.MAC;
                    logEntity.COMPUTERNAME = serviceContext.COMPUTERNAME;
                    logEntity.USERNAME     = serviceContext.USERNAME;
                    logEntity.USERID       = serviceContext.USERID;
                    logEntity.KESHIID      = serviceContext.KESHIID;
                    logEntity.KESHIMC      = serviceContext.KESHIMC;
                    logEntity.BINGQUID     = serviceContext.BINGQUID;
                    logEntity.BINGQUMC     = serviceContext.BINGQUMC;
                    logEntity.JIUZHENKSID  = serviceContext.JIUZHENKSID;
                    logEntity.JIUZHENKSMC  = serviceContext.JiuZhenKSMC;
                    logEntity.YUANQUID     = serviceContext.YUANQUID;
                    logEntity.GONGZUOZID   = serviceContext.GONGZUOZID;
                    //eSLog.PutLog(logEntity);
                    LogHelper.Intance.PutSysInfoLog(logEntity);
                    // 记录日志=====================================================================
                }
                catch (Exception e)
                {
                    LocalLog.WriteLog(this.GetType(), e);
                }

                #endregion

                List <string> unitOfWorkKeys = new List <string>(unitOfWorkDict.Keys);
                for (int i = 0; i < unitOfWorkDict.Values.Count; i++)
                {
                    IUnitOfWork unitOfWork = unitOfWorkDict[unitOfWorkKeys[i]];

                    #region 记录SQL日志

                    try
                    {
                        // 记录日志=====================================================================
                        if (!string.IsNullOrWhiteSpace(unitOfWork.SqlLog.ToString()))
                        {
                            sqlLogText.AppendLine(unitOfWork.SqlLog.ToString());

                            SysLogEntity sqlLogEntity = new SysLogEntity();
                            sqlLogEntity.RiZhiID      = Guid.NewGuid().ToString();
                            sqlLogEntity.ChuangJianSj = DateTime.Now.ToInvariantString("yyyy/MM/dd HH:mm:ss");
                            sqlLogEntity.RiZhiBt      = "[" + moKuaiMc + "/" + yeWuMc + "/" + caoZuoMc + "]服务运行期间的SQL记录。";
                            sqlLogEntity.RiZhiNr      = unitOfWork.SqlLog.ToString();

                            sqlLogEntity.FuWuMc    = moKuaiMc + "/" + yeWuMc + "/" + caoZuoMc;
                            sqlLogEntity.QingQiuLy = serviceContext.DANGQIANCKMC;
                            // 日志类型:1.菜单打开,2.客户端异常,3.服务调用,4服务端异常,5.SQL日志,6.性能日志
                            sqlLogEntity.RiZhiLx = 5;

                            sqlLogEntity.YINGYONGID   = serviceContext.YINGYONGID;
                            sqlLogEntity.XITONGID     = serviceContext.XITONGID;
                            sqlLogEntity.YINGYONGMC   = serviceContext.YINGYONGMC;
                            sqlLogEntity.YINGYONGJC   = serviceContext.YINGYONGJC;
                            sqlLogEntity.VERSION      = serviceContext.VERSION;
                            sqlLogEntity.IP           = serviceContext.IP;
                            sqlLogEntity.MAC          = serviceContext.MAC;
                            sqlLogEntity.COMPUTERNAME = serviceContext.COMPUTERNAME;
                            sqlLogEntity.USERNAME     = serviceContext.USERNAME;
                            sqlLogEntity.USERID       = serviceContext.USERID;
                            sqlLogEntity.KESHIID      = serviceContext.KESHIID;
                            sqlLogEntity.KESHIMC      = serviceContext.KESHIMC;
                            sqlLogEntity.BINGQUID     = serviceContext.BINGQUID;
                            sqlLogEntity.BINGQUMC     = serviceContext.BINGQUMC;
                            sqlLogEntity.JIUZHENKSID  = serviceContext.JIUZHENKSID;
                            sqlLogEntity.JIUZHENKSMC  = serviceContext.JiuZhenKSMC;
                            sqlLogEntity.YUANQUID     = serviceContext.YUANQUID;
                            sqlLogEntity.GONGZUOZID   = serviceContext.GONGZUOZID;
                            //eSLog.PutLog(sqlLogEntity);
                            LogHelper.Intance.PutSysInfoLog(sqlLogEntity);
                        }
                    }
                    catch (Exception e)
                    {
                        LocalLog.WriteLog(this.GetType(), e);
                    }
                    // 记录日志=====================================================================

                    #endregion

                    //try
                    //{
                    //    unitOfWork.MessagePlugin?.Handler();
                    //}
                    //catch (Exception e)
                    //{
                    //    Enterprise.Log.LogHelper.Intance.Error("业务插件",e.Message, JsonUtil.SerializeObject(e));
                    //}

                    try
                    {
                        // 是否发送
                        if (unitOfWork != null && unitOfWork.CurrentMessager.IsPublish)
                        {
                            unitOfWork.CurrentMessager.Context = serviceContext;

                            unitOfWork.CurrentMessager.MoKuaiMc = moKuaiMc;
                            unitOfWork.CurrentMessager.YeWuMc   = yeWuMc;
                            unitOfWork.CurrentMessager.CaoZuoMc = caoZuoMc;

                            // 发送消息
                            using (var client = MessageQueueClientFactory.CreateDbClient())
                            {
                                client.Publish(moKuaiMc, yeWuMc, caoZuoMc, unitOfWork.CurrentMessager);
                            }

                            //是否需要推送消息处理日志
                            bool tuiSong = unitOfWork.CurrentMessager.EntityNameList.ToList().Exists(d => Messager.DaiJianCeSTList.Contains(d));

                            // 将发送的消息异步记录到ES
                            // 需要先将消息内容序列化,否则异步序列化会因部分对象已释放而报错
                            string riZhiNr = JsonConvert.SerializeObject(unitOfWork.CurrentMessager);
                            string id      = unitOfWork.CurrentMessager.ID;
                            await Task.Factory.StartNew(() =>
                            {
                                LogHelper.Intance.Info("消息发送", "消息发送成功", riZhiNr, id);

                                if (tuiSong)
                                {
                                    dynamic obj = new System.Dynamic.ExpandoObject(); //动态类型字段 可读可写
                                    obj.ID      = id;
                                    obj.Status  = 0;                                  //0表示未处理
                                    obj.ChuLiSJ = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                    LogHelper.Intance.Info("消息处理", "消息处理完毕", JsonConvert.SerializeObject(obj), id);
                                }
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        // 发送消息队列失败
                        throw ex;
                    }
                    finally
                    {
                        if (unitOfWork != null)
                        {
                            unitOfWork.Dispose();
                            unitOfWork = null;
                        }
                        unitOfWork = null;
                    }
                }
                unitOfWorkDict.Clear();

                var requestContextCacheProperty = controller.GetType().BaseType.GetField("_RequestContextCache", System.Reflection.BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
                if (requestContextCacheProperty != null)
                {
                    var requestContextCacheObj = requestContextCacheProperty.GetValue(controller);
                    if (requestContextCacheObj != null)
                    {
                        var requestContextCache = (ContextCache)requestContextCacheObj;
                        requestContextCache.Clear();
                        requestContextCache.Dispose();
                        requestContextCache = null;
                    }
                }

                // 记录服务调用耗时日志
                var ServiceStartTimeProperty = controller.GetType().BaseType.GetField("_ServiceStartTime", System.Reflection.BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
                if (ServiceStartTimeProperty != null)
                {
                    var ServiceStartTimeObj = ServiceStartTimeProperty.GetValue(controller);
                    if (ServiceStartTimeObj != null)
                    {
                        var      serviceStartTime = (long)ServiceStartTimeObj;
                        long     nowTicks         = DateTime.Now.Ticks;
                        DateTime dateTime         = new DateTime(nowTicks - serviceStartTime);
                        float    haoShi           = (float)Math.Round((decimal)((nowTicks - serviceStartTime) / 10000000d), 4);

                        SysLogEntity logTimeEntity = new SysLogEntity
                        {
                            RiZhiID      = Guid.NewGuid().ToString(),
                            ChuangJianSj = DateTime.Now.ToInvariantString("yyyy/MM/dd HH:mm:ss"),
                            RiZhiBt      = serviceContext.USERNAME + "[" + serviceContext.USERID + "]调用[" + moKuaiMc + "/" + yeWuMc + "/" + caoZuoMc + "]服务,总耗时:" + haoShi + "秒。",
                            RiZhiNr      = "[服务调用耗时:" + haoShi + "秒] " + stringBuilder.ToString() + sqlLogText.ToString(),
                            FuWuHs       = haoShi, // 添加耗时
                            FuWuMc       = moKuaiMc + "/" + yeWuMc + "/" + caoZuoMc,
                            QingQiuLy    = serviceContext.DANGQIANCKMC,
                            // 日志类型:1.菜单打开,2.客户端异常,3.服务调用,4服务端异常,5.SQL日志,6.性能日志
                            RiZhiLx      = 6,
                            YINGYONGID   = serviceContext.YINGYONGID,
                            XITONGID     = serviceContext.XITONGID,
                            YINGYONGMC   = serviceContext.YINGYONGMC,
                            YINGYONGJC   = serviceContext.YINGYONGJC,
                            VERSION      = serviceContext.VERSION,
                            IP           = serviceContext.IP,
                            MAC          = serviceContext.MAC,
                            COMPUTERNAME = serviceContext.COMPUTERNAME,
                            USERNAME     = serviceContext.USERNAME,
                            USERID       = serviceContext.USERID,
                            KESHIID      = serviceContext.KESHIID,
                            KESHIMC      = serviceContext.KESHIMC,
                            BINGQUID     = serviceContext.BINGQUID,
                            BINGQUMC     = serviceContext.BINGQUMC,
                            JIUZHENKSID  = serviceContext.JIUZHENKSID,
                            JIUZHENKSMC  = serviceContext.JiuZhenKSMC,
                            YUANQUID     = serviceContext.YUANQUID,
                            GONGZUOZID   = serviceContext.GONGZUOZID
                        };
                        //eSLog.PutLog(logTimeEntity);
                        LogHelper.Intance.PutSysInfoLog(logTimeEntity);
                    }
                }
            }
            catch (Exception ex)
            {
                var            controller             = actionExecutedContext.ActionContext.ControllerContext.Controller;
                var            serviceContextProperty = controller.GetType().BaseType.GetProperty("ServiceContext", System.Reflection.BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
                ServiceContext serviceContext         = serviceContextProperty.GetValue(controller) as ServiceContext;
                // 本地日志
                LogHelper.Intance.Error("系统日志", "ApiActionFilterAttribute处理OnActionExecuted报错", "ApiActionFilterAttribute处理OnActionExecuted报错:" + ex.ToString() + "\r\n" + JsonUtil.SerializeObject(serviceContext));
            }
            base.OnActionExecuted(actionExecutedContext);
        }
Esempio n. 5
0
        /// <summary>
        /// 错误处理后提交
        /// </summary>
        /// <param name="context"></param>
        public void JsonToFruit(HttpContext context)
        {
            SysLogEntity log = new SysLogEntity();

            try
            {
                #region 接受数据、声明变量

                bool isadd = false;
                Interfaces.Service.HddzService dbServ = new Interfaces.Service.HddzService();
                string        strData = context.Request.Params["data"];
                yw_hddzEntity model   = JsonConvert.DeserializeObject <yw_hddzEntity>(strData);

                string strErrorData = context.Request.Params["errdata"];
                List <yw_hddz_ocrvalmapEntity> maplist = JsonConvert.DeserializeObject <List <yw_hddz_ocrvalmapEntity> >(strErrorData);

                string strspxx = context.Request.Params["data1"];
                List <yw_hddz_spxxEntity> spxxlist = JsonConvert.DeserializeObject <List <yw_hddz_spxxEntity> >(strspxx);
                #endregion

                #region 判断是否已经有对应数据
                yw_hddzEntity editmodel = dbServ.GetHddzModel(model.OcrID);//主表对象

                if (editmodel == null)
                {
                    editmodel = new yw_hddzEntity();
                    isadd     = true;
                }
                else
                {
                    if (editmodel.zbr != userid)
                    {
                        throw new Exception("该数据已被其他账号同步!");
                    }
                    isadd = false;
                }
                #endregion

                #region 关系映射
                //保存值对应关系
                maplist.ForEach(p => p.ID = Guid.NewGuid().ToString());

                List <yw_hddz_ocrvalmapEntity> addmaplist = new List <yw_hddz_ocrvalmapEntity>();
                foreach (var mapinfo in maplist)
                {
                    string val = null;
                    if (string.IsNullOrEmpty(mapinfo.value))//如果没有选择对应值 则需要快速创建
                    {
                        val = mapinfo.ocrvalue;
                        #region 往来单位
                        if (mapinfo.tablename == "yw_wldw")
                        {
                            Interfaces.Service.BaseService.AddWldw(mapinfo.ocrvalue);
                        }
                        #endregion
                        else if (mapinfo.tablename == "t_country")
                        {
                            throw new Exception("原产地没有选择对应值!");
                            //model.ycd = model.ycd;
                        }
                    }
                    else
                    {
                        val        = mapinfo.value;
                        mapinfo.ID = Guid.NewGuid().ToString();
                        addmaplist.Add(mapinfo);
                    }

                    #region 往来单位匹配
                    if (mapinfo.tablename == "yw_wldw")
                    {
                        yw_wldwEntity wldw = Interfaces.Service.BaseService.GetWldwModel(val);
                        switch (mapinfo.field)
                        {
                        case "gwgys":
                            #region 国外供应商
                            model.gwgysbm = wldw.yw_khbm;
                            model.gwgysjc = wldw.khjc;
                            model.gwgysmc = wldw.khmc_yw;
                            #endregion
                            break;

                        case "kh":
                            #region 客户
                            model.khbm  = wldw.khbm;
                            model.khjc  = wldw.khjc;
                            model.khmc  = wldw.khmc;
                            model.khpym = wldw.pym;

                            #endregion
                            break;

                        case "jydw":
                            #region 经营单位
                            model.jydwbm     = wldw.yw_khbm;
                            model.jydwjc     = wldw.khjc;
                            model.jydwmc     = wldw.khmc;
                            model.jydwpym    = wldw.pym;
                            model.jydwdm     = wldw.qyhgbm;
                            model.jydwsjjgdm = wldw.sjjgdm;
                            #endregion
                            break;

                        case "cyr":
                            #region 承运人
                            model.cyrbm  = wldw.yw_khbm;
                            model.cyrjc  = wldw.khjc;
                            model.cyr    = wldw.khmc;
                            model.cyrpym = wldw.pym;
                            #endregion
                            break;

                        case "zjs":
                            #region 中间商
                            model.zjsbm  = wldw.yw_khbm;
                            model.zjsjc  = wldw.khjc;
                            model.zjsmc  = wldw.khmc;
                            model.zjspym = wldw.pym;
                            #endregion
                            break;

                        case "tzr":
                            #region 通知人
                            model.tzrbm  = wldw.yw_khbm;
                            model.tzrjc  = wldw.khjc;
                            model.tzrmc  = wldw.khmc;
                            model.tzrpym = wldw.pym;
                            #endregion
                            break;
                        }
                    }
                    #endregion
                    #region 原产地
                    else if (mapinfo.field == "ycd")
                    {
                        t_countryEntity ycd = Interfaces.Service.BaseService.GetCountryModel(val);
                        if (ycd != null)
                        {
                            model.ycd        = ycd.ctr_ename;
                            model.ycddm      = ycd.ctr_hgcode;
                            model.dqdm       = ycd.dqdm;
                            model.qiyunguodm = ycd.ctr_hgcode;
                            model.ctr_area2  = ycd.ctr_area2;
                            model.yzbh       = ycd.yzbh;
                        }
                        else
                        {
                            throw new Exception("没有查询到相应的原产地");
                        }
                    }
                    #endregion
                }

                Interfaces.Service.BaseService.AddMapList(addmaplist);
                #endregion

                #region 保存数据
                if (!isadd)
                {
                    model.ywbh           = editmodel.ywbh;
                    model.zbrq           = editmodel.zbrq;
                    model.zbr            = editmodel.zbr;
                    model.state          = editmodel.state;
                    model.SupplierSellID = editmodel.SupplierSellID;
                    model.shdwbm         = editmodel.shdwbm;
                }
                spxxlist.ForEach(p => p.ywbh = model.ywbh);
                //保存数据
                if (isadd)
                {
                    dbServ.SaveHddz(model, spxxlist);
                }
                else
                {
                    dbServ.ModifyHddz(model, spxxlist);
                }

                res.result = true;
                log.msg    = "编号为" + model.ywbh + "的数据保存成功";

                #endregion
            }
            catch (Exception ex)
            {
                log.msg       = ex.Message.Replace(Environment.NewLine, "");
                res.msg       = log.msg;
                res.result    = false;
                res.errortype = 2;
            }
            strrep = JsonConvert.SerializeObject(res);
            context.Response.Write(strrep);
        }