|
|
|
@ -3256,6 +3256,7 @@ namespace Myshipping.Application
|
|
|
|
|
return new string[] { ordUrl.UrlVgm, ordUrl.UrlVgmSi };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 直发VGM(单票)
|
|
|
|
|
/// </summary>
|
|
|
|
@ -3267,151 +3268,216 @@ namespace Myshipping.Application
|
|
|
|
|
var order = _rep.FirstOrDefault(x => x.Id == bookingId);
|
|
|
|
|
var ctns = _repCtn.Where(x => x.BILLID == bookingId).ToList();
|
|
|
|
|
|
|
|
|
|
var dicUrlVgm = _cache.GetAllDictData().Result.First(x => x.TypeCode == "url_set" && x.Code == "vgm_service_single");
|
|
|
|
|
|
|
|
|
|
//船公司
|
|
|
|
|
if (string.IsNullOrEmpty(order.CARRIERID))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK118);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//判断船公司是否支持
|
|
|
|
|
var allowCarrier = _cache.GetAllDictData().Result.Where(x => x.TypeCode == "vgm_carrier_list").Select(x => x.Code).ToList();
|
|
|
|
|
if (!allowCarrier.Contains(order.CARRIERID))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK117);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//船公司网站账号
|
|
|
|
|
var carrWebAccMap = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "carrier_web_account_mapping" && x.Code == order.CARRIERID);
|
|
|
|
|
var webacc = _webAccountConfig.GetAccountConfig(carrWebAccMap.Value, UserManager.UserId).Result;
|
|
|
|
|
if (webacc == null)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK125);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//提单号不能为空
|
|
|
|
|
if (string.IsNullOrEmpty(order.MBLNO))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK127);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////箱型映射
|
|
|
|
|
//var ctnMapping = await _cache.GetAllMappingCtn();
|
|
|
|
|
//ctnMapping = ctnMapping.Where(x => x.Module == "BookingVgm").ToList();
|
|
|
|
|
//if (ctnMapping.Count == 0)
|
|
|
|
|
//{
|
|
|
|
|
// throw Oops.Bah(BookingErrorCode.BOOK122);
|
|
|
|
|
//}
|
|
|
|
|
var config = _cache.GetAllTenantParam().Result.FirstOrDefault(x => x.TenantId == UserManager.TENANT_ID && x.ParaCode == "VGM_SEND_CHANNEL");
|
|
|
|
|
if (config != null && config.ItemCode == "USE_MYSHIPPING") //使用大简云发送vgm
|
|
|
|
|
{
|
|
|
|
|
//ETD不能为空
|
|
|
|
|
if (!order.ETD.HasValue)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("ETD不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//var expCode = ctns.Select(x => x.CTNCODE).Distinct().Except(ctnMapping.Select(y => y.Code)).ToList();
|
|
|
|
|
//if (expCode.Count > 0)
|
|
|
|
|
//{
|
|
|
|
|
// throw Oops.Bah(BookingErrorCode.BOOK123, string.Join(',', expCode));
|
|
|
|
|
//}
|
|
|
|
|
//重量不能为空
|
|
|
|
|
if (!order.KGS.HasValue)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("重量不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 箱信息校验,2022-7-1修改:【累加】的必须有重量、皮重和称重重量;【总重】的只需要称重重量不为空
|
|
|
|
|
if (ctns.Where(c => c.WEIGHTYPE == "累加" &&
|
|
|
|
|
(
|
|
|
|
|
string.IsNullOrEmpty(c.CNTRNO)
|
|
|
|
|
|| !c.WEIGHKGS.HasValue
|
|
|
|
|
|| c.WEIGHKGS == 0
|
|
|
|
|
|| !c.TAREWEIGHT.HasValue
|
|
|
|
|
|| c.TAREWEIGHT == 0
|
|
|
|
|
|| !c.KGS.HasValue
|
|
|
|
|
|| c.KGS == 0)
|
|
|
|
|
).Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("称重方式为累加时,箱号、重量、箱皮重以及称重重量都不能为空");
|
|
|
|
|
}
|
|
|
|
|
var urlConfig = _cache.GetAllSysConfig().Result.FirstOrDefault(x => x.GroupCode == "DJY_CONST" && x.Code == "DjyVgmApiMyshpping");
|
|
|
|
|
|
|
|
|
|
if (ctns.Where(c => c.WEIGHTYPE == "总重" &&
|
|
|
|
|
(
|
|
|
|
|
string.IsNullOrEmpty(c.CNTRNO)
|
|
|
|
|
|| !c.WEIGHKGS.HasValue
|
|
|
|
|
|| c.WEIGHKGS == 0)
|
|
|
|
|
).Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("称重方式为总重时,箱号和称重重量都不能为空");
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
var objMdata = new
|
|
|
|
|
{
|
|
|
|
|
MBLNO = order.MBLNO,
|
|
|
|
|
CARRIER = order.CARRIERID,
|
|
|
|
|
ChuanMing = order.VESSEL,
|
|
|
|
|
HangCi = order.VOYNOINNER,
|
|
|
|
|
ETD = order.ETD.Value.ToString("yyyy-MM-dd HH:mm:ss"),
|
|
|
|
|
ZongZhongLiang = order.KGS.ToString(),
|
|
|
|
|
BeiZhu = "",
|
|
|
|
|
ORDERNO = order.CUSTNO,
|
|
|
|
|
VGMCLOSETIME = order.CLOSEVGMDATE.HasValue ? order.CLOSEVGMDATE.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var listCtn = new List<dynamic>();
|
|
|
|
|
foreach (var ctn in ctns)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(ctn.CTNALL)
|
|
|
|
|
|| string.IsNullOrEmpty(ctn.CNTRNO)
|
|
|
|
|
|| string.IsNullOrEmpty(ctn.SEALNO)
|
|
|
|
|
|| !ctn.WEIGHKGS.HasValue
|
|
|
|
|
|| string.IsNullOrEmpty(ctn.WEIGHDATE))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("所有箱子的箱型、箱号、封号、称重重量和称重时间都不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////场站转换
|
|
|
|
|
//var yardset = _cache.GetAllMappingYard().Result.FirstOrDefault(y => y.Code == order.YARDID && y.Module == "BookingVgm");
|
|
|
|
|
//if (yardset == null)
|
|
|
|
|
//{
|
|
|
|
|
// throw Oops.Bah(BookingErrorCode.BOOK120, order.YARDID);
|
|
|
|
|
//}
|
|
|
|
|
if (string.IsNullOrEmpty(order.YARD) || string.IsNullOrEmpty(order.YARDID))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("场站未正确选择");
|
|
|
|
|
listCtn.Add(new
|
|
|
|
|
{
|
|
|
|
|
ChengZhongZhongLiang = ctn.WEIGHKGS.Value.ToString(),
|
|
|
|
|
ChengZhongShiJian = ctn.WEIGHDATE,
|
|
|
|
|
CTNALL = ctn.CTNALL,
|
|
|
|
|
CNTRNO = ctn.CNTRNO,
|
|
|
|
|
SEALNO = ctn.SEALNO
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
urlConfig.Value.SetBody(new Dictionary<string, string> {
|
|
|
|
|
{ "ac", "vgm" },
|
|
|
|
|
{ "uid", ""},
|
|
|
|
|
{ "skey", ""},
|
|
|
|
|
{ "optype", "9"},
|
|
|
|
|
{ "mdata", JsonConvert.SerializeObject(objMdata)},
|
|
|
|
|
{ "ctndata", JsonConvert.SerializeObject(listCtn)}
|
|
|
|
|
}, "application/x-www-form-urlencoded");
|
|
|
|
|
}
|
|
|
|
|
else //直接调用vgm接口直发
|
|
|
|
|
{
|
|
|
|
|
var dicUrlVgm = _cache.GetAllDictData().Result.First(x => x.TypeCode == "url_set" && x.Code == "vgm_service_single");
|
|
|
|
|
|
|
|
|
|
var user = await _repUser.FirstOrDefaultAsync(x => x.Id == UserManager.UserId);
|
|
|
|
|
|
|
|
|
|
int idx = 1;
|
|
|
|
|
//调用接口
|
|
|
|
|
var dicUrl = _cache.GetAllDictData().Result.First(x => x.TypeCode == "url_set" && x.Code == "vgm_service_single");
|
|
|
|
|
var sendObj = new
|
|
|
|
|
{
|
|
|
|
|
SystemCode = "djy_hechuan",
|
|
|
|
|
billOrderId = order.Id.ToString(),
|
|
|
|
|
sendOrderCode = order.MBLNO,
|
|
|
|
|
customerName = $"{UserManager.TENANT_NAME}+{UserManager.Name}", //公司名称+用户姓名
|
|
|
|
|
customerId = order.CUSTOMERID.ToString(),
|
|
|
|
|
agentName = string.IsNullOrEmpty(order.FORWARDER) ? UserManager.TENANT_NAME : order.FORWARDER,
|
|
|
|
|
carrierCode = order.CARRIERID,
|
|
|
|
|
userName = webacc.Account,
|
|
|
|
|
userPassword = webacc.Password,
|
|
|
|
|
depotCode = order.YARDID,
|
|
|
|
|
depotName = order.YARD,
|
|
|
|
|
linkName = UserManager.Name,
|
|
|
|
|
linkMobile = user.Phone,
|
|
|
|
|
linkEmail = user.Email,
|
|
|
|
|
userId = user.DjyUserId,
|
|
|
|
|
returnUrl = "",
|
|
|
|
|
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.CLOSEVGMDATE.HasValue ? order.CLOSEVGMDATE.Value.ToString("yyyy-MM-dd") : string.Empty,
|
|
|
|
|
BoxInfo = ctns.Select(c => new
|
|
|
|
|
{
|
|
|
|
|
index = idx++,
|
|
|
|
|
boxType = c.CTNALL,
|
|
|
|
|
boxcount = c.CTNNUM.HasValue ? c.CTNNUM.Value : 0,
|
|
|
|
|
code = c.CNTRNO,
|
|
|
|
|
sealCode = c.SEALNO,
|
|
|
|
|
weigth = c.KGS,
|
|
|
|
|
weigthTare = c.TAREWEIGHT,
|
|
|
|
|
weigthTotal = c.WEIGHKGS,
|
|
|
|
|
weigthType = c.WEIGHTYPE == "累加" ? "SM2" : "SM1"
|
|
|
|
|
}).ToList(),
|
|
|
|
|
returnOkUrl = ""
|
|
|
|
|
};
|
|
|
|
|
//判断船公司是否支持
|
|
|
|
|
var allowCarrier = _cache.GetAllDictData().Result.Where(x => x.TypeCode == "vgm_carrier_list").Select(x => x.Code).ToList();
|
|
|
|
|
if (!allowCarrier.Contains(order.CARRIERID))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK117);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string strPostObj = sendObj.ToJsonString();
|
|
|
|
|
_logger.LogInformation($"调用VGM直发接口 {dicUrl.Value} 传递数据:{strPostObj}");
|
|
|
|
|
var strResp = await dicUrl.Value.SetBody(sendObj).PostAsStringAsync();
|
|
|
|
|
_logger.LogInformation($"调用VGM直发接口返回:{strResp}");
|
|
|
|
|
//船公司网站账号
|
|
|
|
|
var carrWebAccMap = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "carrier_web_account_mapping" && x.Code == order.CARRIERID);
|
|
|
|
|
var webacc = _webAccountConfig.GetAccountConfig(carrWebAccMap.Value, UserManager.UserId).Result;
|
|
|
|
|
if (webacc == null)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK125);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var jobjResp = JObject.Parse(strResp);
|
|
|
|
|
int respCode = jobjResp.GetIntValue("code");
|
|
|
|
|
if (respCode != 200)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK128, jobjResp.GetStringValue("message"));
|
|
|
|
|
////箱型映射
|
|
|
|
|
//var ctnMapping = await _cache.GetAllMappingCtn();
|
|
|
|
|
//ctnMapping = ctnMapping.Where(x => x.Module == "BookingVgm").ToList();
|
|
|
|
|
//if (ctnMapping.Count == 0)
|
|
|
|
|
//{
|
|
|
|
|
// throw Oops.Bah(BookingErrorCode.BOOK122);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//var expCode = ctns.Select(x => x.CTNCODE).Distinct().Except(ctnMapping.Select(y => y.Code)).ToList();
|
|
|
|
|
//if (expCode.Count > 0)
|
|
|
|
|
//{
|
|
|
|
|
// throw Oops.Bah(BookingErrorCode.BOOK123, string.Join(',', expCode));
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
#region 箱信息校验,2022-7-1修改:【累加】的必须有重量、皮重和称重重量;【总重】的只需要称重重量不为空
|
|
|
|
|
if (ctns.Where(c => c.WEIGHTYPE == "累加" &&
|
|
|
|
|
(
|
|
|
|
|
string.IsNullOrEmpty(c.CNTRNO)
|
|
|
|
|
|| !c.WEIGHKGS.HasValue
|
|
|
|
|
|| c.WEIGHKGS == 0
|
|
|
|
|
|| !c.TAREWEIGHT.HasValue
|
|
|
|
|
|| c.TAREWEIGHT == 0
|
|
|
|
|
|| !c.KGS.HasValue
|
|
|
|
|
|| c.KGS == 0)
|
|
|
|
|
).Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("称重方式为累加时,箱号、重量、箱皮重以及称重重量都不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ctns.Where(c => c.WEIGHTYPE == "总重" &&
|
|
|
|
|
(
|
|
|
|
|
string.IsNullOrEmpty(c.CNTRNO)
|
|
|
|
|
|| !c.WEIGHKGS.HasValue
|
|
|
|
|
|| c.WEIGHKGS == 0)
|
|
|
|
|
).Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("称重方式为总重时,箱号和称重重量都不能为空");
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////场站转换
|
|
|
|
|
//var yardset = _cache.GetAllMappingYard().Result.FirstOrDefault(y => y.Code == order.YARDID && y.Module == "BookingVgm");
|
|
|
|
|
//if (yardset == null)
|
|
|
|
|
//{
|
|
|
|
|
// throw Oops.Bah(BookingErrorCode.BOOK120, order.YARDID);
|
|
|
|
|
//}
|
|
|
|
|
if (string.IsNullOrEmpty(order.YARD) || string.IsNullOrEmpty(order.YARDID))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("场站未正确选择");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var user = await _repUser.FirstOrDefaultAsync(x => x.Id == UserManager.UserId);
|
|
|
|
|
|
|
|
|
|
int idx = 1;
|
|
|
|
|
//调用接口
|
|
|
|
|
var dicUrl = _cache.GetAllDictData().Result.First(x => x.TypeCode == "url_set" && x.Code == "vgm_service_single");
|
|
|
|
|
var sendObj = new
|
|
|
|
|
{
|
|
|
|
|
SystemCode = "djy_hechuan",
|
|
|
|
|
billOrderId = order.Id.ToString(),
|
|
|
|
|
sendOrderCode = order.MBLNO,
|
|
|
|
|
customerName = $"{UserManager.TENANT_NAME}+{UserManager.Name}", //公司名称+用户姓名
|
|
|
|
|
customerId = order.CUSTOMERID.ToString(),
|
|
|
|
|
agentName = string.IsNullOrEmpty(order.FORWARDER) ? UserManager.TENANT_NAME : order.FORWARDER,
|
|
|
|
|
carrierCode = order.CARRIERID,
|
|
|
|
|
userName = webacc.Account,
|
|
|
|
|
userPassword = webacc.Password,
|
|
|
|
|
depotCode = order.YARDID,
|
|
|
|
|
depotName = order.YARD,
|
|
|
|
|
linkName = UserManager.Name,
|
|
|
|
|
linkMobile = user.Phone,
|
|
|
|
|
linkEmail = user.Email,
|
|
|
|
|
userId = user.DjyUserId,
|
|
|
|
|
returnUrl = "",
|
|
|
|
|
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.CLOSEVGMDATE.HasValue ? order.CLOSEVGMDATE.Value.ToString("yyyy-MM-dd") : string.Empty,
|
|
|
|
|
BoxInfo = ctns.Select(c => new
|
|
|
|
|
{
|
|
|
|
|
index = idx++,
|
|
|
|
|
boxType = c.CTNALL,
|
|
|
|
|
boxcount = c.CTNNUM.HasValue ? c.CTNNUM.Value : 0,
|
|
|
|
|
code = c.CNTRNO,
|
|
|
|
|
sealCode = c.SEALNO,
|
|
|
|
|
weigth = c.KGS,
|
|
|
|
|
weigthTare = c.TAREWEIGHT,
|
|
|
|
|
weigthTotal = c.WEIGHKGS,
|
|
|
|
|
weigthType = c.WEIGHTYPE == "累加" ? "SM2" : "SM1"
|
|
|
|
|
}).ToList(),
|
|
|
|
|
returnOkUrl = ""
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
string strPostObj = sendObj.ToJsonString();
|
|
|
|
|
_logger.LogInformation($"调用VGM直发接口 {dicUrl.Value} 传递数据:{strPostObj}");
|
|
|
|
|
var strResp = await dicUrl.Value.SetBody(sendObj).PostAsStringAsync();
|
|
|
|
|
_logger.LogInformation($"调用VGM直发接口返回:{strResp}");
|
|
|
|
|
|
|
|
|
|
var jobjResp = JObject.Parse(strResp);
|
|
|
|
|
int respCode = jobjResp.GetIntValue("code");
|
|
|
|
|
if (respCode != 200)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK128, jobjResp.GetStringValue("message"));
|
|
|
|
|
}
|
|
|
|
|
//货运动态
|
|
|
|
|
var bsl = new BookingStatusLog();
|
|
|
|
|
bsl.BookingId = bookingId;
|
|
|
|
|
bsl.Status = $"直发VGM";
|
|
|
|
|
bsl.OpTime = DateTime.Now;
|
|
|
|
|
bsl.Category = "ship";
|
|
|
|
|
bsl.MBLNO = order.MBLNO;
|
|
|
|
|
await _repStatuslog.InsertAsync(bsl);
|
|
|
|
|
}
|
|
|
|
|
//货运动态
|
|
|
|
|
var bsl = new BookingStatusLog();
|
|
|
|
|
bsl.BookingId = bookingId;
|
|
|
|
|
bsl.Status = $"直发VGM";
|
|
|
|
|
bsl.OpTime = DateTime.Now;
|
|
|
|
|
bsl.Category = "ship";
|
|
|
|
|
bsl.MBLNO = order.MBLNO;
|
|
|
|
|
await _repStatuslog.InsertAsync(bsl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|