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.
DS7/DSWeb/Areas/CommMng/DAL/PublicPortHelper.cs

706 lines
23 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Globalization;
using System.Data;
using DSWeb.MvcShipping.DAL.MsCodeCtnEdi;
using DSWeb.MvcShipping.Models.MsOpSeae;
using DSWeb.MvcShipping.Models.MsChFee;
using DSWeb.MvcShipping.DAL.MsChFeeDAL;
using HcUtility.Comm;
using DSWeb.Areas.MvcShipping.Comm;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.DAL.MsSysThirdPartyAccount;
using DSWeb.Common.DB;
namespace DSWeb.Areas.CommMng.DAL
{
public class PortSendHelper {
public string URL { get; set; }
public string logname { get; set; }
public string userid { get; set; }
public string infoclient_carrier { get; set; }//该业务相关的船公司的info_client.shortname
public object sendobj { get; set; }
public void MakeMessage()
{
}
public DBResult DoSend(int timeout= 5000) {
var result = new DBResult();
try
{
var strSendObj = JsonConvert.Serialize(sendobj);
BasicDataRefDAL.SaveLog("URL:"+ URL+";"+strSendObj, "", logname, "发送");
var rtn = WebRequestHelper.DoPost(URL, strSendObj, timeout: 50000);
BasicDataRefDAL.SaveLog(rtn, "", logname, "返回");
result.OK("", rtn);
}
catch(Exception ex)
{
result.SetErrorInfo(ex.Message);
return result;
}
//"{\"status\":1,\"message\":\"ok\",\"data\":{\"message\":\"无效的参考号/没有运动可用140201003313\",\"infos\":[]}}"
/*"infos": [
{
"bkgno": "ESLCHNQGA2044855",
"blno": "EPIRCHNQGA230635",
"eta": "",
"origin": "QINGDAO, CHINA",
"delivery": "PENANG, MALAYSIA",
"container": [
{
"contno": "FCIU3466878",
"latestact": "EMPTY GATED IN AT DEPOT",
"actloc": "PENANG, MALAYSIA",
"conttype": "DV20",
"actdate": "19-Jan-2023"
}
]
},
{
"bkgno": "ESLCHNQGA2045659",
"blno": "EPIRCHNQGA230922",
"eta": "",
"origin": "QINGDAO, CHINA",
"delivery": "SOHAR, OMAN",
"container": [
{
"contno": "CLHU8968063",
"latestact": "EMPTY GATED IN AT DEPOT",
"actloc": "SOHAR, OMAN",
"conttype": "HC40",
"actdate": "15-Feb-2023"
},
{
"contno": "ESDU4074261",
"latestact": "EMPTY GATED IN AT DEPOT",
"actloc": "SOHAR, OMAN",
"conttype": "HC40",
"actdate": "15-Feb-2023"
}
]
}
]*/
result = DoDeal(result.Data.ToString());
return result;
}
public virtual DBResult DoDeal(string rtn) {
var result = new DBResult();
return result;
}
}
#region 港联顺相关类和方法
public class GLSFEEHead
{
public string key { get; set; }
public string mbl { get; set; }
public string vessel { get; set; }
public string voyage { get; set; }
public string placeStart { get; set; }
public string placeEnd { get; set; }
public string etd { get; set; }
public string cartonInfo { get; set; }
public string goodsName { get; set; }
public string number { get; set; } = "0";
public string grossWeight { get; set; } = "0";
public string volume { get; set; } = "0";
public string remark { get; set; }
public List<GLSFEE> billInfoList { get; set; } = new List<GLSFEE>();
public GLSFEEHead() { }
public GLSFEEHead(MsOpSeae head, string userid, string username, string companyid)
{
var CUSTOMERNAME = "";
var CUSTOMERNAMEInfo = MsCodeCtnEdiDAL.GetCustList($" EDINAME='GLSFEE'");
if (CUSTOMERNAMEInfo != null && CUSTOMERNAMEInfo.Count > 0)
{
CUSTOMERNAME = CUSTOMERNAMEInfo[0].CTN;
}
var chfeeCondition = $" CUSTOMERNAME='{CUSTOMERNAME}' and BSNO='{head.BSNO}' and not exists(select 1 from OP_LOGICINFO where BSNO=ch_fee.GID and PROPNAME='港联顺费用推送') ";
var List = MsChFeeDAL.GetDataList(chfeeCondition + " and feetype=1 ", 1, "op_seae", userid, username, companyid);
var List = MsChFeeDAL.GetDataList(chfeeCondition + " and feetype=2 ", 2, "op_seae", userid, username, companyid);
var feenamedic = MsCodeCtnEdiDAL.GetFeeNameDicByName("GLSFEE");
mbl = head.MBLNO;
vessel = head.VESSEL;
voyage = head.VOYNO;
placeStart = head.PORTLOAD;
placeEnd = head.DESTINATION;
etd = head.ETD;
cartonInfo = head.CNTRTOTAL;
goodsName = head.GOODSNAME;
number = head.PKGS;
grossWeight = head.KGS;
volume = head.CBM;
billInfoList = new List<GLSFEE>();
if (List != null && List.Count > 0)
{
foreach (var item in List)
{
var newfee = new GLSFEE(item, feenamedic);
billInfoList.Add(newfee);
}
}
if (List != null && List.Count > 0)
{
foreach (var item in List)
{
var newfee = new GLSFEE(item, feenamedic);
billInfoList.Add(newfee);
}
}
}
public List<GLSFEEINFO> getFeeInfo()
{
var result = new List<GLSFEEINFO>();
if (billInfoList != null && billInfoList.Count > 0)
{
foreach (var item in billInfoList)
{
var newrec = new GLSFEEINFO(this);
//newrec.CUSTOMERNAME = CUSTOMERNAME;
newrec.GID = item.GID;
newrec.FEENAME = item.feeItem;
newrec.FEETYPEREF = item.feeType;
newrec.AMOUNT = item.totalPrice;
newrec.CURRENT = item.currency;
result.Add(newrec);
}
}
return result;
}
}
public class GLSFEE
{
public string feeType { get; set; }
public string feeItem { get; set; }
public string FEENAME { get; set; }
public string GID { get; set; }
public string currency { get; set; }
public decimal? quantity { get; set; }
public string unit { get; set; }
public decimal? unitPrice { get; set; }
public decimal? totalPrice { get; set; }
public string remark { get; set; }
public GLSFEE() { }
public GLSFEE(MsChFee chfee, Dictionary<string, string> feenamedic)
{
if (chfee.FeeType == 1) feeType = "R";
if (chfee.FeeType == 2) feeType = "P";
FEENAME = chfee.FeeName;
GID = chfee.GId;
if (feenamedic.ContainsKey(chfee.FeeName))
{
feeItem = feenamedic[chfee.FeeName];
}
else
{
//feeItem = "";
//改为不强制要求设置费用名称 未设置的使用原名称
feeItem = chfee.FeeName;
}
currency = chfee.Currency;
quantity = chfee.Quantity;
unit = chfee.Unit;
unitPrice = chfee.TaxUnitPrice;
totalPrice = chfee.Amount;
}
}
public class GLSFEEINFO
{
public string GID { get; set; }
public string MBLNO { get; set; }
public string VESSEL { get; set; }
public string VOYNO { get; set; }
public string DESTINATION { get; set; }
public string ETD { get; set; }
public string FEENAME { get; set; }
public string FEETYPEREF { get; set; }
public decimal? AMOUNT { get; set; }
public string CURRENT { get; set; }
public GLSFEEINFO() { }
public GLSFEEINFO(GLSFEEHead feehead)
{
MBLNO = feehead.mbl;
VESSEL = feehead.vessel;
VOYNO = feehead.voyage;
ETD = feehead.etd;
DESTINATION = feehead.placeEnd;
}
}
#endregion
#region ESL相关类
public class ESLPortParam_Send
{
public string u { get; set; }//用户名
public string p { get; set; }//密码
public object data { get; set; }
}
public class ESLPortParam
{
public string u { get; set; }//用户名
public string p { get; set; }//密码
public string userid { get; set; }
public string carrier { get; set; }
public DBResult SetUserPassword(string _userid, string _carrier) {
userid = _userid;
carrier = _carrier;
var result = new DBResult();
var thirdaccount= MsSysThirdPartyAccountDAL.GetDataByCustomername(userid, carrier);
if (!thirdaccount.HaveAccount())
{
result.SetErrorInfo($"您没有在第三方账号密码管理中设置【{carrier}】的账号和密码");
}
else {
u = thirdaccount.ACCOUNT;
p = thirdaccount.ACCOUNTPSW;
result.OK();
}
return result;
}
public virtual ESLPortParam_Send getSendParam() {
var result = new ESLPortParam_Send();
result.u = u;
result.p = p;
return result;
}
}
public class ESLPortResult
{
public int? status { get; set; }
public string message { get; set; }
virtual public object data { get; set; }
}
public class ESLPortParam_ETA : ESLPortParam
{
public List<string> data { get; set; }
public ESLPortParam_Send getSendParam() {
var result = new ESLPortParam_Send();
result.u = u;
result.p = p;
result.data = JsonConvert.Serialize(data);
return result;
}
}
public class ESLPortParam_GetMblnoBySO : ESLPortParam
{
public string so_no { get; set; }
}
public class ESLPortParam_GetEP : ESLPortParam
{
public string esl_code { get; set; }
}
public class ESLPortParam_Draft : ESLPortParam
{
public string ep_code { get; set; }
public string esl_code { get; set; }
public string op_email { get; set; }
}
public class ESLPortResult_ETA : ESLPortResult
{
public class etainfo
{
public string bkgno { get; set; }
public string blno { get; set; }
public string eta { get; set; }
public string origin { get; set; }
public string delivery { get; set; }
public List<etacontainer> container { get; set; }
}
public class etacontainer
{
public string contno { get; set; }
public string latestact { get; set; }
public string actloc { get; set; }
public string conttype { get; set; }
public string actdate { get; set; }
}
public class etadata
{
public string message { get; set; }
public List<etainfo> infos { get; set; }
}
public etadata data { get; set; }
}
public class ESLPortResult_GetMblnoBySO : ESLPortResult
{
public class draftdata
{
public string esl_no { get; set; }
public string ref_no { get; set; }
public string bk_no { get; set; }
public string pol { get; set; }
public string pod { get; set; }
public string pol_etd { get; set; }
public string bl_status { get; set; }
public string container_no { get; set; }
public string new_activity { get; set; }
public string teus { get; set; }
}
public draftdata data { get; set; }
}
public class ESLPortResult_GetEP: ESLPortResult
{
public class draftdata
{
public string status { get; set; }
public string bk_no { get; set; }
public string bk_status { get; set; }
public string ep_code { get; set; }
}
public draftdata data { get; set; }
}
public class ESLPortResult_Draft: ESLPortResult
{
public class draftdata
{
public string abs_path { get; set; }
public string api_path { get; set; }
}
public draftdata data { get; set; }
}
public class ESLPort_ETA : PortSendHelper {
private List<MsOpSeae> headList { get; set; }
public ESLPortParam_ETA sendparam { get; set; }
public ESLPort_ETA(string userid,string CARRIER) {
URL = "http://118.190.106.151:10011/bill_track_search/";
logname = "ESL货运追踪接口";
infoclient_carrier= CARRIER;
sendparam = new ESLPortParam_ETA();
this.userid = userid;
}
public DBResult MakeMessage(List<MsOpSeae> _headList) {
var result = new DBResult();
headList = _headList;
try {
result= sendparam.SetUserPassword(userid, infoclient_carrier);
if (!result.Success) return result;
//向data赋值
var MBLNOList = headList.Select(s=>s.MBLNO).Distinct().ToList();
sendparam.data = MBLNOList;
sendobj = sendparam;
result.OK();
}
catch(Exception e)
{
result.SetErrorInfo(e.Message);
}
return result;
}
override public DBResult DoDeal(string rtn)
{
var result = new DBResult();
var _r = JsonConvert.Deserialize<ESLPortResult_ETA>(rtn);
try
{
if (_r.status == 1 && _r.data.infos.Count > 0)
{
//更新这些业务的ETA
foreach (var item in _r.data.infos) {
var eta = item.eta;
if (string.IsNullOrWhiteSpace(eta)) {
continue;
}
var bsnos = headList.Where(x => x.MBLNO.ToUpper() == item.bkgno.ToUpper()).Select(s => s.BSNO).ToList();
var bsnostr ="'"+ string.Join("','", bsnos)+"'";
var sqlstr = $" update op_seae set ETA='{eta}' where bsno in({bsnostr})";
BasicDataRefDAL.ExecSql(sqlstr);
}
result.OK("获取成功!");
}
}
catch (Exception e)
{
result.SetErrorInfo(e.Message);
}
return result;
}
}
public class ESLPort_GetMblnoBySO : PortSendHelper
{
private MsOpSeae head { get; set; }
public ESLPortParam_GetMblnoBySO sendparam { get; set; }
public ESLPort_GetMblnoBySO(string userid, string CARRIER)
{
URL = "http://118.190.106.151:10011/so_search/";
logname = "ESL货运追踪接口";
infoclient_carrier = CARRIER;
sendparam = new ESLPortParam_GetMblnoBySO();
this.userid = userid;
}
public DBResult MakeMessage(MsOpSeae _head)
{
var result = new DBResult();
head = _head;
try
{
result = sendparam.SetUserPassword(userid, infoclient_carrier);
if (!result.Success) return result;
sendparam.so_no = head.MBLNO;
sendobj = sendparam;
result.OK();
}
catch (Exception e)
{
result.SetErrorInfo(e.Message);
}
return result;
}
override public DBResult DoDeal(string rtn)
{
var result = new DBResult();
result.OK();
var _r = JsonConvert.Deserialize<ESLPortResult_GetMblnoBySO>(rtn);
try
{
if (_r.status == 1 && !string.IsNullOrWhiteSpace(_r.data.esl_no))
{
//更新so号
//如ref_no=当前mblno 将当前的mblno移动至申请放箱号APPLYNO并将esl_no写入mblno
if (head.MBLNO == _r.data.ref_no)
{
var bsnostr = $"'{head.BSNO}'";
var sqlstr = $" update op_seae set MBLNO='{_r.data.esl_no}',APPLYNO='{_r.data.ref_no}' where bsno =({bsnostr})";
BasicDataRefDAL.ExecSql(sqlstr);
result.OK($"舱位号获取成功:[{_r.data.esl_no}]");
}
else
{
result.OK($"未能取得ESL号可能业务属于其他账号");
}
}
else {
result.OK($"未能取得ESL号可能业务属于其他账号");
}
}
catch (Exception e)
{
result.SetErrorInfo(e.Message);
}
return result;
}
}
public class ESLPort_GetEP : PortSendHelper
{
private MsOpSeae head { get; set; }
public ESLPortParam_GetEP sendparam { get; set; }
public ESLPort_GetEP(string userid, string CARRIER)
{
URL = "http://118.190.106.151:10011/ep_search/";
logname = "ESL货运追踪接口";
infoclient_carrier = CARRIER;
sendparam = new ESLPortParam_GetEP();
this.userid = userid;
}
public DBResult MakeMessage(MsOpSeae _head)
{
var result = new DBResult();
head = _head;
try
{
result = sendparam.SetUserPassword(userid, infoclient_carrier);
if (!result.Success) return result;
sendparam.esl_code = head.MBLNO;
sendobj = sendparam;
result.OK();
}
catch (Exception e)
{
result.SetErrorInfo(e.Message);
}
return result;
}
override public DBResult DoDeal(string rtn)
{
var result = new DBResult();
var _r = JsonConvert.Deserialize<ESLPortResult_GetEP>(rtn);
try
{
if (_r.status == 1 && !string.IsNullOrWhiteSpace(_r.data.ep_code))
{
//更新so号
//如ref_no=当前mblno 将当前的mblno移动至申请放箱号APPLYNO并将esl_no写入mblno
if (head.MBLNO == _r.data.bk_no)
{
var dic = new Dictionary<string, string>
{
{ "EPCODE", _r.data.ep_code }
};
BasicDataRefDAL.SaveLogicInfo(head.BSNO, "ESL", dic);
result.OK(_r.data.ep_code, _r.data.ep_code);
}
}
else {
result.SetErrorInfo("还没有产生EP号");
}
}
catch (Exception e)
{
result.SetErrorInfo(e.Message);
}
return result;
}
}
public class ESLPort_Draft : PortSendHelper
{
private MsOpSeae head { get; set; }
public ESLPortParam_Draft sendparam { get; set; }
public ESLPort_Draft(string userid, string CARRIER)
{
URL = "http://118.190.106.151:10011/draft_download/";
logname = "ESL货运追踪接口";
infoclient_carrier = CARRIER;
sendparam = new ESLPortParam_Draft();
this.userid = userid;
}
public DBResult MakeMessage(MsOpSeae _head)
{
var result = new DBResult();
head = _head;
try
{
result = sendparam.SetUserPassword(userid, infoclient_carrier);
if (!result.Success) return result;
var esllogic = BasicDataRefDAL.GetLogicInfo(head.BSNO, "ESL");
var epcode = "";
if (esllogic.ContainsKey("EPCODE")) {
epcode = esllogic["EPCODE"];
}
sendparam.ep_code = epcode;
sendparam.esl_code = _head.MBLNO;
var cdc = new CommonDataContext();
var userinfo = cdc.VW_user.First(x => x.USERID == userid);
sendparam.op_email= userinfo.EMAIL1;
if (string.IsNullOrWhiteSpace(userinfo.EMAIL1)) {
result.SetErrorInfo("必须要设置自己的邮箱地址由于接受");
return result;
}
sendobj = sendparam;
result.OK("");
}
catch (Exception e)
{
result.SetErrorInfo(e.Message);
}
return result;
}
override public DBResult DoDeal(string rtn)
{
var result = new DBResult();
var _r = JsonConvert.Deserialize<ESLPortResult_Draft>(rtn);
try
{
if (_r.status == 1)
{
//更新so号
//如ref_no=当前mblno 将当前的mblno移动至申请放箱号APPLYNO并将esl_no写入mblno
if (!string.IsNullOrWhiteSpace(_r.data.api_path))
{
var cdc = new CommonDataContext();
var oldrecList = cdc.Receipt_Doc.Where(x => x.BSNO == head.BSNO && x.Driect_URL == _r.data.api_path).ToList();
if (oldrecList == null || oldrecList.Count == 0) {
var newreceipt = new Receipt_Doc_md(head.BSNO);
newreceipt.Driect_URL = _r.data.api_path;
newreceipt.URL = "DRAFT.pdf";
newreceipt.RECEIPTTYPE = "DRAFT";
cdc.Receipt_Doc.Add(newreceipt);
cdc.SaveChanges();
}
}
}
result.OK("发送成功");
}
catch (Exception e)
{
result.SetErrorInfo(e.Message);
}
return result;
}
}
#endregion
}