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.

223 lines
7.9 KiB
C#

using DSWeb.Areas.MvcShipping.DAL.MsOpSeaeQDPortDataDAL;
using DSWeb.Areas.SysMng.DAL.USERINFO;
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_YGT
{
public static WebModel ExecuteWeb(string mblno,string userid)
{
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对应表
var _user = USERINFODAL.GetUser(userid);
JObject reqObj = new JObject();
reqObj.Add("yardid", "YGT");
reqObj.Add("mblno", new JValue(mblno));
reqObj.Add("isweb", "1");
reqObj.Add("ygttype", "dj");
reqObj.Add("webusername", _user.QdPortUserName);
reqObj.Add("webuserpass", _user.QdPortPassword);
///'webusername':'18611691907',
///'webuserpass':'Qwe123qwe',
string rtn = "";
//②-①请求场站数据
try
{
rtn = WebRequestHelper.DoPost(reqUrl, reqObj.ToString(Formatting.None), reqTimeout * 1000);
WebModel wm = JsonConvert.DeserializeObject<WebModel>(rtn);
return wm;
}
catch (Exception ex)
{
return null;
}
}
catch (Exception ex)
{
return null;
}
}
public static string Execute(string mblno, string carrier, string yardname,string userid)
{
try
{
//接口地址
//string reqUrl = "http://47.105.157.231:5000/query";
string reqUrl = "http://47.104.90.170:5000/query";
int reqTimeout = 25;
//①获取订阅列表
MYSHIPPINGTESTEntities me = new MYSHIPPINGTESTEntities();
//筛选订阅列表,去除不需要查询的数据
//②循环订阅列表并请求物流信息网数据
//※获取场站名称与接口id对应表
List<op_seae_billtrack_yardid> yardlist = me.op_seae_billtrack_yardid.ToList();
JObject reqObj = new JObject();
reqObj.Add("yardid", "YGT");
reqObj.Add("mblno", new JValue(mblno));
reqObj.Add("isweb", "2");
//reqObj.Add("ygttype", "dj");
MsOpSeaeQDPortDataDAL dal = new MsOpSeaeQDPortDataDAL(userid);
var infolist = dal.GetQdportAccount();
reqObj.Add("webusername", infolist[0]);
reqObj.Add("webuserpass", infolist[1]);
string mailAddr = "";
string rtn = "";
YGTModel ygtM;
RepYGTModel mYGT;
//②-①请求物流信息网数据
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.TrackTimesQDPort = times;
bt.updateTimeQDPort = 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.updateTimeQDPort = DateTime.Now;
me.op_seae_billtrack.Add(bt);
}
me.SaveChanges();
return "";
}
}
catch (Exception ex)
{
return "";
}
//②-②反序列化
try
{
mYGT = JsonConvert.DeserializeObject<RepYGTModel>(rtn);
ygtM = mYGT.message;
if (ygtM == null)
{
return "";
}
}
catch (Exception e)
{
return "";
}
//②-④入库更新
try
{
//②-④-① 更新主表舱单信息
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.TrackTimesQDPort) + 1);
bt.TrackTimesQDPort = times;
bt.VESSEL = ygtM.YWCM;
bt.VOYNO = ygtM.CKHC;
bt.KaiChuanShiJian = Helper.ToDateTime(ygtM.SJLGSJ);
bt.updateTimeQDPort = DateTime.Now;
bt.MaTouFangXing = ygtM.FXBZ;
}
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.VESSEL = ygtM.YWCM;
bt.VOYNO = ygtM.CKHC;
bt.KaiChuanShiJian = Helper.ToDateTime(ygtM.SJLGSJ);
bt.MaTouFangXing = ygtM.FXBZ;
bt.TrackTimesQDPort = 1;
bt.TrackTimesFX = 0;
bt.TrackTimesCZ = 0;
bt.TrackTimesWLXX = 0;
bt.updateTimeQDPort = DateTime.Now;
me.op_seae_billtrack.Add(bt);
}
int rst = me.SaveChanges();
if (rst>0)
{
return bt.GID;
}
else
{
return "";
}
}
catch (Exception e)
{
return "";
}
}
catch (Exception ex)
{
return "";
}
}
}
}