You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
7.9 KiB
C#

using log4net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
namespace DSWeb.Interface.YZ
{
public class JobBillTrackRequest_WLXX
{
public static WebModel ExecuteWeb(string mblno)
{
try
{
//接口地址
//string reqUrl = "http://47.105.157.231:5000/query";
string reqUrl = "http://47.104.90.170:5000/query";
int reqTimeout = 20;
//①获取订阅列表
MYSHIPPINGTESTEntities me = new MYSHIPPINGTESTEntities();
//②循环订阅列表并请求场站数据
//※获取场站名称与接口id对应表
JObject reqObj = new JObject();
reqObj.Add("yardid", "WLXX");
reqObj.Add("mblno", new JValue(mblno));
reqObj.Add("isweb", "1");
reqObj.Add("wltype", "WLXXSX");
string rtn = "";
//②-①请求场站数据
try
{
rtn = WebRequestHelper.DoPost(reqUrl, reqObj.ToString(Formatting.None), reqTimeout * 1000);
WebModel wm = JsonConvert.DeserializeObject<WebModel>(rtn);
if (rtn.Contains("无可用账号"))
{
wm.message="查询人数过多,请稍后再试!";
}
if (rtn.Contains("单号信息不存在") || rtn.Contains("验证码"))
{
wm.message = "单号信息不存在!";
}
return wm;
}
catch (Exception ex)
{
return null;
}
}
catch (Exception ex)
{
return null;
}
}
public static string Execute(string mblno, string carrier, string yardname)
{
try
{
//接口地址
//string reqUrl = "http://47.105.157.231:5000/query";
string reqUrl = "http://47.104.90.170:5000/query";
int reqTimeout = 20;
//①获取订阅列表
MYSHIPPINGTESTEntities me = new MYSHIPPINGTESTEntities();
//筛选订阅列表,去除不需要查询的数据
//②循环订阅列表并请求物流信息网数据
//※获取场站名称与接口id对应表
List<op_seae_billtrack_yardid> yardlist = me.op_seae_billtrack_yardid.ToList();
JObject reqObj = new JObject();
reqObj.Add("yardid", "WLXX");
reqObj.Add("mblno", new JValue(mblno));
reqObj.Add("isweb", "2");
reqObj.Add("wltype", "WLXXSX");
string mailAddr = "";
string rtn = "";
List<WLXXModel> mList;
RepWLXXModel mWLXX;
//②-①请求物流信息网数据
try
{
rtn = WebRequestHelper.DoPost(reqUrl, reqObj.ToString(Formatting.None), reqTimeout * 1000);
if (rtn.Contains("单号信息不存在") || rtn.Contains("验证码")|| rtn.Contains("无可用账号"))
{
op_seae_billtrack bt;
var bto = me.op_seae_billtrack.Where(o => o.MBLNO == mblno).ToList();
if (bto.Count > 0)
{
bt = bto.First();
int times = (Helper.ToInt32(bt.TrackTimesWLXX) + 1);
bt.TrackTimesCZ = times;
bt.updateTimeWLXX = DateTime.Now;
}
else
{
bt = new op_seae_billtrack();
bt.GID = Guid.NewGuid().ToString();
bt.CreateTime = DateTime.Now;
bt.CARRIERID = carrier;
bt.MBLNO =mblno;
bt.YARD = yardname;
bt.YunDiShiJian = null;
bt.CangDanShiJian = null;
bt.updateTime = DateTime.Now;
bt.BaoGuanFangXing = null;
bt.ZhuangZaiFangXing = null;
bt.TrackTimesWLXX = 0;
bt.TrackTimesQDPort = 0;
bt.TrackTimesCZ = 0;
bt.TrackTimesFX = 0;
bt.updateTimeWLXX = DateTime.Now;
me.op_seae_billtrack.Add(bt);
}
me.SaveChanges();
return "";
}
}
catch (Exception ex)
{
return "";
}
//②-②反序列化
try
{
mWLXX = JsonConvert.DeserializeObject<RepWLXXModel>(rtn);
mList = mWLXX.message;
if (mList.Count == 0)
{
return "";
}
}
catch (Exception e)
{
return "";
}
//②-④入库更新
try
{
WLXXModel m = mList[0];
//②-④-① 更新主表舱单信息
op_seae_billtrack bt;
var bto = me.op_seae_billtrack.Where(o => o.MBLNO == mblno).ToList();
if (bto.Count > 0)
{
bt = bto.First();
bt.YunDiShiJian = Helper.ToDateTime(m.YunDiShiJian);
bt.CangDanShiJian = Helper.ToDateTime(m.YuPeiShiJian);
bt.BaoGuanFangXing = Helper.ToDateTime(m.FangXingShiJian);
bt.ZhuangZaiFangXing = Helper.ToDateTime(m.ZhuangZaiShiJian);
int times = (Helper.ToInt32(bt.TrackTimesWLXX) + 1);
bt.TrackTimesWLXX = times;
bt.updateTimeWLXX = DateTime.Now;
bt.updateTime = DateTime.Now;
}
else
{
bt = new op_seae_billtrack();
bt.GID = Guid.NewGuid().ToString();
bt.CreateTime = DateTime.Now;
bt.CARRIERID = carrier;
bt.MBLNO = mblno;
bt.YARD = yardname;
bt.YunDiShiJian = Helper.ToDateTime(m.YunDiShiJian);
bt.CangDanShiJian = Helper.ToDateTime(m.YuPeiShiJian);
bt.BaoGuanFangXing = Helper.ToDateTime(m.FangXingShiJian);
bt.ZhuangZaiFangXing = Helper.ToDateTime(m.ZhuangZaiShiJian);
bt.updateTime = DateTime.Now;
bt.TrackTimesWLXX = 1;
bt.TrackTimesFX = 0;
bt.TrackTimesCZ = 0;
bt.TrackTimesQDPort = 0;
bt.updateTimeWLXX = DateTime.Now;
me.op_seae_billtrack.Add(bt);
}
int rst = me.SaveChanges();
return bt.GID;
}
catch (Exception e)
{
return "";
}
}
catch (Exception ex)
{
return "";
}
}
}
}