public void GetOcrDataList(HttpContext context) { try { OcrInvokeServiceImpl serv = new OcrInvokeServiceImpl(); string fph = context.Request.Params["invoiceno"]; string tdh = context.Request.Params["billno"]; if (fph == null) { fph = ""; } if (tdh == null) { tdh = ""; } string strJson = serv.queryMainInfoList("ocr", fph, tdh); //string strJson = "{\"info\":\"[{'billno':'COSU6900370400','blairstatusname':'未上传,N','blstatusname':'待调整,Y','ciqstatusname':'未上传,N','countrycnname':'新西兰','examinationstatusname':'未上传,N','invoiceno':'fp20160407-4','invstatusname':'字段检验不通过,Y','ocrmainid':'0f222c22-fffc-4dab-a4e1-701e5a28cee8','orstatusname':'调整结束,Y','phystatusname':'待调整,Y','plstatusname':'字段检验不通过,Y','productcnname':'鲜苹果','prstatusname':'未上传,N','regions':'','shippingcompany':'中国远洋','transportname':'海运'},{'billno':'td20160411-1','blairstatusname':'未上传,N','blstatusname':'待调整,Y','ciqstatusname':'未上传,N','countrycnname':'新西兰','examinationstatusname':'未上传,N','invoiceno':'fp20160411-1','invstatusname':'字段检验不通过,Y','ocrmainid':'0f239773-29b1-4d36-b3f4-9a71ed8d2269','orstatusname':'字段检验不通过,Y','phystatusname':'字段检测通过,Y','plstatusname':'待调整,Y','productcnname':'鲜苹果','prstatusname':'未上传,N','regions':'','shippingcompany':'中国远洋','transportname':'海运'},{'billno':'3213213','blairstatusname':'未上传,N','blstatusname':'字段检验不通过,Y','ciqstatusname':'未上传,N','countrycnname':'新西兰','examinationstatusname':'未上传,N','invoiceno':'23123','invstatusname':'调整结束,Y','ocrmainid':'1a1bfb80-5806-40e7-a0de-147078cd6c2d','orstatusname':'待调整,Y','phystatusname':'待调整,Y','plstatusname':'待调整,Y','productcnname':'鲜苹果','prstatusname':'未上传,N','regions':'','shippingcompany':'中国远洋','transportname':'海运'},{'billno':'td-20160421-1','blairstatusname':'未上传,N','blstatusname':'调整结束,Y','ciqstatusname':'未上传,N','countrycnname':'新西兰','examinationstatusname':'未上传,N','invoiceno':'fp-20160421-1','invstatusname':'调整结束,Y','ocrmainid':'c7a2c909-a912-4500-a9b0-991192c81dc0','orstatusname':'待调整,Y','phystatusname':'待调整,Y','plstatusname':'调整结束,Y','productcnname':'鲜苹果','prstatusname':'未上传,N','regions':'','shippingcompany':'中国远洋','transportname':'海运'},{'billno':'COSU6900370400','blairstatusname':'未上传,N','blstatusname':'调整结束,Y','ciqstatusname':'未上传,N','countrycnname':'新西兰','examinationstatusname':'未上传,N','invoiceno':'5736','invstatusname':'字段检验不通过,Y','ocrmainid':'e1a7ab4b-3fcd-4c09-9c8b-115c1a144c26','orstatusname':'调整结束,Y','phystatusname':'字段检验不通过,Y','plstatusname':'字段检验不通过,Y','productcnname':'鲜苹果','prstatusname':'未上传,N','regions':'','shippingcompany':'中国远洋','transportname':'海运'}]\",\"status\":\"Y\"}"; ServerResEntity model = JsonConvert.DeserializeObject <ServerResEntity>(strJson); if (model != null && model.status == "Y") { List <OCRHddzEntity> list = JsonConvert.DeserializeObject <List <OCRHddzEntity> >(model.info); if (list.Count == 0) { throw new Exception("没有查询到数据"); } //给数据加上同步状态 Interfaces.OcrIF.ChangeStatus(list); strrep = "{\"rows\":" + JsonConvert.SerializeObject(list) + ",\"total\":" + list.Count + "}"; } else { strrep = "{\"rows\":[],\"total\":0,\"result\":false,\"message\":\"" + model.info + "\"}"; //strrep = "{\"result\":false,\"message\":\"" + model.info + "\"}"; } } catch (Exception ex) { strrep = "{\"rows\":[],\"total\":0,\"result\":false,\"message\":\"" + ex.Message + "\"}"; } context.Response.Write(strrep); }
/// <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;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;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("&", "&"); #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); }