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.
202 lines
9.3 KiB
C#
202 lines
9.3 KiB
C#
using DS.Module.Core;
|
|
using DS.Module.Core.Extensions;
|
|
using DS.Module.Core.Helpers;
|
|
using DS.WMS.Core.Map.Entity;
|
|
using DS.WMS.Core.Op.Dtos;
|
|
using DS.WMS.Core.Op.Entity;
|
|
using DS.WMS.Core.Sys.Entity;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace DS.WMS.Core.Op.Method
|
|
{
|
|
/// <summary>
|
|
/// 海运出口运踪相关接口
|
|
/// </summary>
|
|
public partial class SeaExportService
|
|
{
|
|
#region 运踪相关
|
|
/// <summary>
|
|
/// 发起运踪订阅或者更新提单号
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
public async Task<DataResult<string>> SendOrUpdateTrace(List<BillTraceReq> req)
|
|
{
|
|
if (req.Count == 0)
|
|
{
|
|
return await Task.FromResult(DataResult<string>.Failed("未传入正确参数!"));
|
|
}
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var userKey = db.Queryable<SysConfig>().Filter(null, true).Where(x => x.Code == "seae_billtraceurl_userKey" && x.TenantId == 1288018625843826688).First().Value;
|
|
var userPwd = db.Queryable<SysConfig>().Filter(null, true).Where(x => x.Code == "seae_billtraceurl_userPwd" && x.TenantId == 1288018625843826688).First().Value;
|
|
var userId = db.Queryable<SysConfig>().Filter(null, true).Where(x => x.Code == "seae_billtraceurl_userId" && x.TenantId == 1288018625843826688).First().Value;
|
|
var reqUrl = db.Queryable<SysConfig>().Filter(null, true).Where(x => x.Code == "request_seae_billtraceurl" && x.TenantId == 1288018625843826688).First().Value;
|
|
var resUrl = db.Queryable<SysConfig>().Filter(null, true).Where(x => x.Code == "response_seae_billtraceurl" && x.TenantId == 1288018625843826688).First().Value;
|
|
|
|
BillTraceMain billdto = new BillTraceMain();
|
|
List<BillTraceReq> billTraceList = new List<BillTraceReq>();
|
|
foreach (var item in req)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(item.CARRIERID))
|
|
{
|
|
var et = await tenantDb.Queryable<BookingStatus>().Where(x => x.StatusCode == "status_mudigang" && x.BusinessId == Convert.ToInt64(item.BusinessId)).FirstAsync();
|
|
if (et != null)
|
|
{
|
|
return await Task.FromResult(DataResult<string>.Failed("\"提单号\" + item.MBLNO + \"已订阅!"));
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.YardCode))
|
|
{
|
|
var et = await tenantDb.Queryable<BookingStatus>().Where(x => x.StatusCode == "status_qiyungang" && x.BusinessId == Convert.ToInt64(item.BusinessId)).FirstAsync();
|
|
if (et != null)
|
|
{
|
|
return await Task.FromResult(DataResult<string>.Failed("\"提单号\" + item.MBLNO + \"已订阅!"));
|
|
}
|
|
}
|
|
|
|
if (item.isBook && (string.IsNullOrWhiteSpace(item.CARRIERID) || string.IsNullOrWhiteSpace(item.CARRIER) || string.IsNullOrWhiteSpace(item.MBLNO)))
|
|
{
|
|
return await Task.FromResult(DataResult<string>.Failed("订阅目的港船公司或提单号不能为空!"));
|
|
}
|
|
if (!item.isBook && (string.IsNullOrWhiteSpace(item.YARD) || string.IsNullOrWhiteSpace(item.YardCode) || string.IsNullOrWhiteSpace(item.MBLNO)))
|
|
{
|
|
return await Task.FromResult(DataResult<string>.Failed("订阅港前数据提单号或场站不能为空!"));
|
|
}
|
|
var yardMap = tenantDb.Queryable<MappingYard>().Where(x => x.Code == item.YardCode && x.Module == "BillTrace").First();
|
|
if (yardMap.IsNull())
|
|
{
|
|
return await Task.FromResult(DataResult<string>.Failed($"场站代号配置未找到:{item.YardCode}"));
|
|
}
|
|
billTraceList.Add(new BillTraceReq
|
|
{
|
|
BusinessId = item.BusinessId,
|
|
MBLNO = item.MBLNO,
|
|
YARD = item.YARD == "" ? null : item.YARD,
|
|
YardCode = yardMap.MapCode == "" ? null : yardMap.MapCode,
|
|
CARRIER = item.CARRIER == "" ? null : item.CARRIER,
|
|
CARRIERID = item.CARRIERID == "" ? null : item.CARRIERID,
|
|
isBook = item.isBook
|
|
});
|
|
var status = string.Empty;
|
|
var IsBookingYZ = String.Empty;
|
|
if (!string.IsNullOrWhiteSpace(item.YardCode) && !string.IsNullOrWhiteSpace(item.CARRIERID))
|
|
{
|
|
status = "订阅起运港,目的港";
|
|
IsBookingYZ = "3";
|
|
}
|
|
else if (string.IsNullOrWhiteSpace(item.YardCode) && !string.IsNullOrWhiteSpace(item.CARRIERID))
|
|
{
|
|
status = "订阅目的港";
|
|
IsBookingYZ = "2";
|
|
}
|
|
else if (!string.IsNullOrWhiteSpace(item.YardCode) && string.IsNullOrWhiteSpace(item.CARRIERID))
|
|
{
|
|
status = "订阅起运港";
|
|
IsBookingYZ = "1";
|
|
}
|
|
else
|
|
{
|
|
IsBookingYZ = "0";
|
|
}
|
|
//TODO 添加booking日志
|
|
//更新运踪标识
|
|
var info = tenantDb.Queryable<SeaExport>().First(x => x.Id == Convert.ToInt64(item.BusinessId));
|
|
info.IsBookingYZ = IsBookingYZ;
|
|
|
|
await tenantDb.Updateable(info).ExecuteCommandAsync();
|
|
}
|
|
|
|
billdto.Children = billTraceList;
|
|
billdto.Key = userKey;
|
|
billdto.PWD = userPwd;
|
|
billdto.url = resUrl;
|
|
billdto.Gid = userId;
|
|
var json = billdto.ToJsonString();
|
|
|
|
if (!reqUrl.EndsWith("/"))
|
|
{
|
|
reqUrl += "/";
|
|
}
|
|
|
|
reqUrl += "BillTrace/UpdateMblno";
|
|
|
|
var result = RequestHelper.Post(json, reqUrl);
|
|
|
|
var res = JsonConvert.DeserializeObject<BillTraceRes>(result);
|
|
|
|
if (!res.Success)
|
|
{
|
|
return await Task.FromResult(DataResult<string>.Failed($"发起运踪订阅或者更新提单号失败:{res.Message}"));
|
|
}
|
|
else
|
|
{
|
|
return await Task.FromResult(DataResult<string>.Success(res.Data));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 运踪退订
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
public async Task<DataResult<string>> UnsubscribeBillTrace(List<BillTraceUnsubscribeList> req)
|
|
{
|
|
if (req.Count == 0)
|
|
{
|
|
return await Task.FromResult(DataResult<string>.Failed("未传入正确参数!"));
|
|
}
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
var userKey = db.Queryable<SysConfig>().Filter(null, true).Where(x => x.Code == "seae_billtraceurl_userKey" && x.TenantId == 1288018625843826688).First().Value;
|
|
var userPwd = db.Queryable<SysConfig>().Filter(null, true).Where(x => x.Code == "seae_billtraceurl_userPwd" && x.TenantId == 1288018625843826688).First().Value;
|
|
var userId = db.Queryable<SysConfig>().Filter(null, true).Where(x => x.Code == "seae_billtraceurl_userId" && x.TenantId == 1288018625843826688).First().Value;
|
|
var reqUrl = db.Queryable<SysConfig>().Filter(null, true).Where(x => x.Code == "request_seae_billtraceurl" && x.TenantId == 1288018625843826688).First().Value;
|
|
var resUrl = db.Queryable<SysConfig>().Filter(null, true).Where(x => x.Code == "response_seae_billtraceurl" && x.TenantId == 1288018625843826688).First().Value;
|
|
|
|
BillTraceUnsubscribeDto reqDto = new BillTraceUnsubscribeDto()
|
|
{
|
|
Children = new List<BillTraceUnsubscribeList>(),
|
|
Key = userKey,
|
|
PWD = userPwd,
|
|
Gid = userId
|
|
};
|
|
foreach (var item in req)
|
|
{
|
|
if (string.IsNullOrEmpty(item.BusinessId))
|
|
{
|
|
return await Task.FromResult(DataResult<string>.Failed("订舱记录主键不能为空!!"));
|
|
}
|
|
reqDto.Children.Add(new BillTraceUnsubscribeList(item.BusinessId, item.MBLNO));
|
|
|
|
//TODO 添加booking日志
|
|
//更新运踪标识
|
|
var info = tenantDb.Queryable<SeaExport>().First(x => x.Id == Convert.ToInt64(item.BusinessId));
|
|
info.IsBookingYZ = "0";
|
|
|
|
await tenantDb.Updateable(info).ExecuteCommandAsync();
|
|
}
|
|
var json = reqDto.ToJsonString();
|
|
if (!reqUrl.EndsWith("/"))
|
|
{
|
|
reqUrl += "/";
|
|
}
|
|
|
|
reqUrl += "BillTrace/UnsubscribeBillTrace";
|
|
|
|
var result = RequestHelper.Post(json, reqUrl);
|
|
|
|
var res = JsonConvert.DeserializeObject<BillTraceRes>(result);
|
|
|
|
if (!res.Success)
|
|
{
|
|
return await Task.FromResult(DataResult<string>.Failed($"运踪退订失败:{res.Message}"));
|
|
}
|
|
else
|
|
{
|
|
return await Task.FromResult(DataResult<string>.Success(res.Data));
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|