|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using DSWeb.Common.DB;
|
|
|
using DSWeb.Common.Helper;
|
|
|
using DSWeb.Common.Model;
|
|
|
using log4net;
|
|
|
using Newtonsoft.Json;
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
namespace DSWeb.EventBus
|
|
|
{
|
|
|
public class ProcessorVgmLinkRefresh : EventProcessor
|
|
|
{
|
|
|
private static ILog logger = LogManager.GetLogger("ProcessorVgmLinkRefresh");
|
|
|
|
|
|
private BookingDB bookingDB = new BookingDB();
|
|
|
private CommonDataContext commonData = new CommonDataContext();
|
|
|
|
|
|
public override bool CanProcess(EventMessageType type)
|
|
|
{
|
|
|
if (type == EventMessageType.VgmLinkRefresh)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
public override void Process(JObject paraObj)
|
|
|
{
|
|
|
string ordno = paraObj.GetValue("ORDNO").ToString();
|
|
|
var order = bookingDB.Orders.AsNoTracking().FirstOrDefault(o => o.ORDNO == ordno);
|
|
|
var model = bookingDB.VgmLink.FirstOrDefault(v => v.ORDNO == ordno);
|
|
|
if (order == null)
|
|
|
{
|
|
|
logger.Error($"处理更新vgm链接消息时出错:未找到订舱 {ordno}");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
var paraVgmLinkService = commonData.ParamSets.AsNoTracking().FirstOrDefault(p => p.PARAMNAME == "bookingVgmLinkServiceUrl");
|
|
|
if (string.IsNullOrEmpty(paraVgmLinkService.PARAMVALUE))
|
|
|
{
|
|
|
logger.Error($"处理更新vgm链接消息时出错:未正确配置vgm发送服务地址 {ordno} {order.MBLNO}");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
var currUser = commonData.Users.AsNoTracking().First(u => u.GID == order.USERID);
|
|
|
var currUserBase = commonData.UserBases.AsNoTracking().First(ub => ub.USERID == currUser.GID);
|
|
|
|
|
|
if (model == null)
|
|
|
{
|
|
|
model = new OP_SEAE_ORDER_VGM_LINK();
|
|
|
|
|
|
model.GID = Guid.NewGuid().ToString();
|
|
|
model.CREATE_TIME = DateTime.Now;
|
|
|
model.CREATE_USER = currUser.GID;
|
|
|
model.ORDNO = order.ORDNO;
|
|
|
bookingDB.VgmLink.Add(model);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
model.MODIFY_TIME = DateTime.Now;
|
|
|
model.MODIFY_USER = currUser.GID;
|
|
|
}
|
|
|
|
|
|
//调用接口生成vgm链接
|
|
|
var receiveUrl = string.Empty;
|
|
|
var webUser = string.Empty;
|
|
|
var webPass = string.Empty;
|
|
|
|
|
|
if (order.CARRIERID == "CMA")
|
|
|
{
|
|
|
var paraMyshippingUrlService = commonData.ParamSets.AsNoTracking().FirstOrDefault(p => p.PARAMNAME == "bookingWebUrlCMA");
|
|
|
|
|
|
var accType = AccountConfigType.CmaWeb.ToString();
|
|
|
var accCfg = commonData.AccountConfigs.AsNoTracking().FirstOrDefault(a => a.Type == accType && a.UserId == currUser.GID);
|
|
|
if (accCfg == null)
|
|
|
{
|
|
|
logger.Error($"处理更新vgm链接消息失败:未配置CMA网站账号、密码 {ordno} {order.MBLNO}");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
receiveUrl = paraMyshippingUrlService.PARAMVALUE;
|
|
|
webUser = accCfg.Account;
|
|
|
webPass = accCfg.Password;
|
|
|
}
|
|
|
else if (order.CARRIERID == "ONE")
|
|
|
{
|
|
|
var paraMyshippingUrlService = commonData.ParamSets.AsNoTracking().FirstOrDefault(p => p.PARAMNAME == "bookingWebUrlONE");
|
|
|
|
|
|
var accType = AccountConfigType.OneWeb.ToString();
|
|
|
var accCfg = commonData.AccountConfigs.AsNoTracking().FirstOrDefault(a => a.Type == accType && a.UserId == currUser.GID);
|
|
|
if (accCfg == null)
|
|
|
{
|
|
|
logger.Error($"处理更新vgm链接消息失败:未配置ONE网站账号、密码 {ordno} {order.MBLNO}");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
receiveUrl = paraMyshippingUrlService.PARAMVALUE;
|
|
|
webUser = accCfg.Account;
|
|
|
webPass = accCfg.Password;
|
|
|
}
|
|
|
|
|
|
if (string.IsNullOrEmpty(order.CARRIERID)
|
|
|
|| string.IsNullOrEmpty(order.YARDID))
|
|
|
{
|
|
|
logger.Error($"处理更新vgm链接消息失败:未填写船公司和场站 {ordno} {order.MBLNO}");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
CodeYardDataSet yardset = commonData.YardDataSet.AsNoTracking().FirstOrDefault(y => y.YARD == order.YARD);
|
|
|
if (yardset == null)
|
|
|
{
|
|
|
logger.Error($"处理更新vgm链接消息失败:场站代号未找到 {ordno} {order.MBLNO} {order.YARD}");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (!receiveUrl.EndsWith("/"))
|
|
|
{
|
|
|
receiveUrl += "/";
|
|
|
}
|
|
|
|
|
|
//调用接口
|
|
|
var sendObj = new
|
|
|
{
|
|
|
SystemCode = "djy",
|
|
|
billOrderId = order.ORDNO,
|
|
|
sendOrderCode = order.MBLNO,
|
|
|
customerName = $"{currUser.COMNAME}+{currUser.SHOWNAME}", //公司名称+用户姓名
|
|
|
customerId = order.CUSTOMERID,
|
|
|
agentName = string.IsNullOrEmpty(order.FORWARDER) ? currUser.COMNAME : order.FORWARDER,
|
|
|
carrierCode = order.CARRIERID,
|
|
|
userName = webUser,
|
|
|
userPassword = webPass,
|
|
|
depotCode = yardset.YARDCODE,
|
|
|
depotName = order.YARD,
|
|
|
linkName = currUser.SHOWNAME,
|
|
|
linkMobile = currUserBase.OFFICEPHONE,
|
|
|
linkEmail = currUserBase.EMAIL1,
|
|
|
userId = currUser.GID,
|
|
|
returnUrl = $"{receiveUrl}Booking/RecVgmFeedback",
|
|
|
shipName = order.VESSEL,
|
|
|
voyNo = order.VOYNO,
|
|
|
etdstr = order.ETD.HasValue ? order.ETD.Value.ToString("yyyy-MM-dd") : string.Empty,
|
|
|
potrSend = order.PORTLOAD,
|
|
|
potrGoal = order.PORTDISCHARGE,
|
|
|
boxinfoStr = order.CNTRTOTAL,
|
|
|
vgmEndTimeStr = order.VGM_TIME.HasValue ? order.VGM_TIME.Value.ToString("yyyy-MM-dd") : string.Empty,
|
|
|
returnOkUrl = $"{receiveUrl}Booking/RecVgmOk",
|
|
|
SiReturnUrl = $"{receiveUrl}Booking/RecVgmSi",
|
|
|
DataInfoJson = new
|
|
|
{
|
|
|
order.SHIPPER,
|
|
|
order.CONSIGNEE,
|
|
|
order.NOTIFYPARTY,
|
|
|
order.MARKS,
|
|
|
order.DESCRIPTION,
|
|
|
order.BLFRT,
|
|
|
order.SERVICE,
|
|
|
order.ISSUETYPE,
|
|
|
order.TRANSPORT,
|
|
|
order.TRANSPORTID,
|
|
|
order.DESTINATION,
|
|
|
order.DESTINATIONID,
|
|
|
order.KINDPKGS,
|
|
|
order.THIRDPAYADDR,
|
|
|
order.PORTLOAD,
|
|
|
order.PORTLOADID,
|
|
|
order.PORTDISCHARGE,
|
|
|
order.PORTDISCHARGEID
|
|
|
}
|
|
|
};
|
|
|
|
|
|
try
|
|
|
{
|
|
|
var strJson = JsonConvert.SerializeObject(sendObj);
|
|
|
logger.Debug($"处理更新vgm链接消息发送生成vgm链接:{strJson}");
|
|
|
var rtn = WebRequestHelper.DoPost(paraVgmLinkService.PARAMVALUE, strJson, timeout: 5000);
|
|
|
logger.Debug($"调用生成vgm返回:{rtn}");
|
|
|
var jobjRtn = JsonConvert.DeserializeAnonymousType(rtn, new { code = 0, status = false, message = string.Empty, data = string.Empty, memoData = new { vgmAndSiUrl = "", siUrl = "", vgmUrl = "" } });
|
|
|
if (!jobjRtn.status)
|
|
|
{
|
|
|
logger.Error($"处理更新vgm链接消息失败:链接生成错误 {ordno} {order.MBLNO} {jobjRtn.message}");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
model.VGM_URL = jobjRtn.memoData.vgmUrl;
|
|
|
model.SI_VGM_URL = jobjRtn.memoData.vgmAndSiUrl;
|
|
|
|
|
|
//反馈vgm给捷丰
|
|
|
if (!string.IsNullOrEmpty(order.BSNO))
|
|
|
{
|
|
|
VgmFeedbackHelper.FeedbackVgmJiefeng(bookingDB, order.ORDNO, order.BSNO, "", jobjRtn.data);
|
|
|
}
|
|
|
|
|
|
bookingDB.SaveChanges();
|
|
|
|
|
|
logger.Error($"处理更新vgm链接消息成功:{ordno} {order.MBLNO}");
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
logger.Error($"处理更新vgm链接消息失败:调用生成vgm链接出错 {ex.Message}");
|
|
|
logger.Error(ex.StackTrace);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|