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.

369 lines
15 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_YARD
{
public static WebModel ExecuteWeb(string mblno, 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();
string yardname2 = "";
if (yardname.IndexOf('-') > 0)
{
yardname2 = yardname.Split('-')[1];
}
else
{
yardname2 = yardname;
}
var yard = yardlist.Find(o => o.YARDNAME == yardname2);
if (yard == null)
{
return null;
}
string yardid = yard.YARDID;
JObject reqObj = new JObject();
reqObj.Add("yardid", new JValue(yardid));
reqObj.Add("mblno", new JValue(mblno));
reqObj.Add("isweb", "1");
reqObj.Add("ygttype", "dj");
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)
{
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();
string yardname2 = "";
if (yardname.IndexOf('-')>0)
{
yardname2 = yardname.Split('-')[1];
}
else
{
yardname2 = yardname;
}
var yard = yardlist.Find(o => o.YARDNAME == yardname2);
if (yard == null)
{
return "";
}
string yardid = yard.YARDID;
string mailAddr = "";
JObject reqObj = new JObject();
reqObj.Add("yardid", new JValue(yardid));
reqObj.Add("mblno", new JValue(mblno));
reqObj.Add("isweb", "2");
reqObj.Add("ygttype", "dj");
string rtn = "";
List<CZModel> mList;
RepCZModel CZM;
//②-①请求场站数据
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.updateTimeCZ = 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 = yardname2;
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.updateTimeCZ = DateTime.Now;
me.op_seae_billtrack.Add(bt);
}
me.SaveChanges();
return "";
}
}
catch (Exception ex)
{
return "";
}
//②-②反序列化
try
{
CZM = JsonConvert.DeserializeObject<RepCZModel>(rtn);
mList = CZM.message;
}
catch (Exception e)
{
return "";
}
//合并列表
mList = mList.GroupBy(m => new { m.CNTRNO, m.SEALNO, m.FanChangShiJian, m.TiXiangShiJian, m.VESSEL, m.VOYNO, m.KINDPKGS, m.CheHao, m.CTNALL, m.XiangLiang,m.JiGangShiJian })
.Select(m =>
new CZModel
{
CNTRNO = m.Key.CNTRNO,
SEALNO = m.Key.SEALNO,
FanChangShiJian = m.Key.FanChangShiJian,
TiXiangShiJian = m.Key.TiXiangShiJian,
JiGangShiJian = m.Key.JiGangShiJian,
VESSEL = m.Key.VESSEL,
VOYNO = m.Key.VOYNO,
KINDPKGS = m.Key.KINDPKGS,
CheHao = m.Key.CheHao,
CTNALL = m.Key.CTNALL,
XiangLiang = m.Key.XiangLiang,
CBM = m.Sum(w => Helper.ToDecimal(w.CBM)).ToString(),
KGS = m.Sum(w => Helper.ToDecimal(w.KGS)).ToString(),
PKGS = m.Sum(w => Helper.ToDecimal(w.PKGS)).ToString(),
TAREWEIGHT = m.Sum(w => Helper.ToDecimal(w.TAREWEIGHT)).ToString()
}).ToList();
string fanchangStr = "";//返厂状态
string tixiangStr = "";//提箱状态
string jigangStr = "";//集港状态
//②-③对比并计算场站状态
try
{
//②-③-①获取旧的状态
//②-③-②判断并计算新的状态
if (mList.Count > 0)
{
//②-③-②-①根据集装箱明细返厂时间,获取主表的返厂状态
var templist = mList.FindAll(o => o.FanChangShiJian != "").ToList();
if (templist.Count > 0 && templist.Count != Helper.ToInt32(mList[0].XiangLiang))
{
fanchangStr = "部分返场";
}
else if (templist.Count > 0 && templist.Count == Helper.ToInt32(mList[0].XiangLiang))
{
fanchangStr = "已返场";
}
else
{
fanchangStr = "未返场";
}
//②-③-②-②根据实际箱量与预计箱量,获取主表的提箱状态
int XiangLiang = Helper.ToInt32(mList.First().XiangLiang);
//实际箱量与预计箱量是否相等,不等则为部分提箱
var txlist = mList.FindAll(o => o.TiXiangShiJian != "").ToList();
if (XiangLiang == txlist.Count)
{
tixiangStr = "已提箱";
}
else
{
if (txlist.Count == 0)
{
tixiangStr = "未提箱";
}
else
{
tixiangStr = "部分提箱";
}
}
//②-③-②-③根据集装箱明细返厂时间,获取主表的集港状态
//判断装箱状态列表里,是否存集港时间为空的数据,如果有则返场时间为部分集港
var jglist = mList.FindAll(o => o.JiGangShiJian != "").ToList();
if (jglist.Count > 0 && jglist.Count != Helper.ToInt32(mList[0].XiangLiang))
{
jigangStr = "部分集港";
}
else if (jglist.Count > 0 && jglist.Count == Helper.ToInt32(mList[0].XiangLiang))
{
jigangStr = "已集港";
}
else
{
jigangStr = "未集港";
}
}
else
{
fanchangStr = "未返厂";
tixiangStr = "未提箱";
jigangStr = "未集港";
}
}
catch (Exception e)
{
return "";
}
//②-④入库更新
try
{
string bgid = "";
if (mList.Count > 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.TiXiangShiJian = tixiangStr;
bt.FanChangShiJian = fanchangStr;
bt.JiGangShiJian = jigangStr;
int times = (Helper.ToInt32(bt.TrackTimesCZ) + 1);
bt.updateTime = DateTime.Now;
bt.TrackTimesCZ = times;
bt.updateTimeCZ = DateTime.Now;
bgid = bt.GID;
}
else
{
bt = new op_seae_billtrack();
bt.GID = Guid.NewGuid().ToString();
bt.CreateTime = DateTime.Now;
bt.CARRIERID = carrier;
bt.MBLNO = mblno;
bt.YARD = yardname2;
bt.TiXiangShiJian = tixiangStr;
bt.FanChangShiJian = fanchangStr;
bt.JiGangShiJian = jigangStr;
bt.updateTime = DateTime.Now;
bt.TrackTimesCZ = 1;
bt.TrackTimesFX = 0;
bt.TrackTimesQDPort = 0;
bt.TrackTimesWLXX = 0;
bt.updateTimeCZ = DateTime.Now;
bgid = bt.GID;
me.op_seae_billtrack.Add(bt);
}
//②-④-②删除并新增集装箱明细表
List<op_seae_billtrack_ctn> listctn = me.op_seae_billtrack_ctn.Where(m => m.MBLNO == mblno).ToList();
foreach (var item in listctn)
{
me.op_seae_billtrack_ctn.Remove(item);
}
foreach (var mctn in mList)
{
op_seae_billtrack_ctn ctn = new op_seae_billtrack_ctn();
ctn.GID = Guid.NewGuid().ToString();
ctn.SEALNO = mctn.SEALNO;
ctn.CNTRNO = mctn.CNTRNO;
ctn.CTNALL = mctn.CTNALL;
ctn.KGS = Helper.ToDecimal(mctn.KGS);
ctn.PKGS = Helper.ToDecimal(mctn.PKGS);
ctn.CBM = Helper.ToDecimal(mctn.CBM);
ctn.TiXiangShiJian = Helper.ToDateTime(mctn.TiXiangShiJian);
ctn.FanChangShiJian = Helper.ToDateTime(mctn.FanChangShiJian);
ctn.JiGangShiJian = Helper.ToDateTime(mctn.JiGangShiJian);
ctn.CreateTime = DateTime.Now;
ctn.CheHao = mctn.CheHao;
ctn.MBLNO = mblno;
ctn.PID = bt.GID;
me.op_seae_billtrack_ctn.Add(ctn);
}
int rst = me.SaveChanges();
return bt.GID;
}
else
{
return "";
}
}
catch (Exception e)
{
return "";
}
}
catch (Exception ex)
{
return "";
}
}
}
}