|
|
|
@ -1,4 +1,7 @@
|
|
|
|
|
using Common.DJYModel;
|
|
|
|
|
using Common;
|
|
|
|
|
using Common.DJYModel;
|
|
|
|
|
using Common.Extensions;
|
|
|
|
|
using Common.Tools;
|
|
|
|
|
using Common.Utilities;
|
|
|
|
|
using djy.IService.Afr;
|
|
|
|
|
using djy.Model;
|
|
|
|
@ -8,10 +11,18 @@ using djy.Model.Ams;
|
|
|
|
|
using djy.Model.AmsDto;
|
|
|
|
|
using djy.Service.DjyService;
|
|
|
|
|
using FreeSql;
|
|
|
|
|
using Google.Protobuf.WellKnownTypes;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using NETCore.Encrypt.Internal;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data.Common;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Security.Policy;
|
|
|
|
|
using System.Security.Principal;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
@ -19,11 +30,14 @@ namespace djy.Service.AFR
|
|
|
|
|
{
|
|
|
|
|
public class AfrService : DjyService.DbContext, IAfrService
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<AfrService> logger;
|
|
|
|
|
|
|
|
|
|
private IUser User { get; }
|
|
|
|
|
|
|
|
|
|
public AfrService(IUser user)
|
|
|
|
|
public AfrService(IUser user, ILogger<AfrService> logger)
|
|
|
|
|
{
|
|
|
|
|
User = user;
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
}
|
|
|
|
|
#region 下拉接口
|
|
|
|
|
public List<CommonCNEN> GetCountry(string strlink, int page, int limit)
|
|
|
|
@ -61,7 +75,7 @@ namespace djy.Service.AFR
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var List = DbBus.Get(DbList.Common).Select<CodeCarrier, MappingCarrier>().InnerJoin((cc, map) => cc.Code == map.Code && map.Module == "AMS").ToList((cc, map) => new CommonMappiCode
|
|
|
|
|
var List = DbBus.Get(DbList.Common).Select<CodeCarrier, MappingCarrier>().InnerJoin((cc, map) => cc.Code == map.Code && map.Module == "AFR").ToList((cc, map) => new CommonMappiCode
|
|
|
|
|
{
|
|
|
|
|
Code = cc.Code,
|
|
|
|
|
Value = cc.EnName,
|
|
|
|
@ -79,7 +93,7 @@ namespace djy.Service.AFR
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var List = DbBus.Get(DbList.Common).Select<CodeCtn, MappingCtn>().InnerJoin((cc, map) => cc.Code == map.Code && map.Module == "AMS").ToList((cc, map) => new CommonMappiCode
|
|
|
|
|
var List = DbBus.Get(DbList.Common).Select<CodeCtn, MappingCtn>().InnerJoin((cc, map) => cc.Code == map.Code && map.Module == "AFR").ToList((cc, map) => new CommonMappiCode
|
|
|
|
|
{
|
|
|
|
|
Code = cc.Code,
|
|
|
|
|
Value = cc.Name,
|
|
|
|
@ -97,7 +111,7 @@ namespace djy.Service.AFR
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var List = DbBus.Get(DbList.Common).Select<CodePackage, MappingPackage>().InnerJoin((cc, map) => cc.Code == map.Code && map.Module == "AMS").ToList((cc, map) => new CommonMappiCode
|
|
|
|
|
var List = DbBus.Get(DbList.Common).Select<CodePackage, MappingPackage>().InnerJoin((cc, map) => cc.Code == map.Code && map.Module == "AFR").ToList((cc, map) => new CommonMappiCode
|
|
|
|
|
{
|
|
|
|
|
Code = cc.Code,
|
|
|
|
|
Value = cc.Name,
|
|
|
|
@ -193,19 +207,24 @@ namespace djy.Service.AFR
|
|
|
|
|
public async Task<PageModel<AFRMaster>> Load(AFRMasterInputDto input)
|
|
|
|
|
{
|
|
|
|
|
ISelect<AFRMaster> select = null;
|
|
|
|
|
|
|
|
|
|
bool isSend = false;
|
|
|
|
|
|
|
|
|
|
// 查询草稿箱列表,草稿箱列表采用一主单内含有多个分单的显示模式
|
|
|
|
|
if (input.Type == 1)
|
|
|
|
|
{
|
|
|
|
|
select = DbAMS.Select<AFRMaster>();
|
|
|
|
|
isSend = false;
|
|
|
|
|
}
|
|
|
|
|
// 查询已发送列表,已发送列表采用按分单的显示方式
|
|
|
|
|
// 查询已发送列表,已发送列表采用按分单的显示方式,所以采用内连接的方式
|
|
|
|
|
else if (input.Type == 2)
|
|
|
|
|
{
|
|
|
|
|
select = DbAMS.Select<AFRMaster>()
|
|
|
|
|
.InnerJoin<AFRHouse>((m, h) => m.GID == h.PID);
|
|
|
|
|
isSend = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
select.Where((m) => m.IsDel == false)
|
|
|
|
|
select.Where((m) => m.IsDel == false && m.StateIsSend == isSend)
|
|
|
|
|
//下面两个是Controller中传来的条件
|
|
|
|
|
.WhereIf(!string.IsNullOrEmpty(input.CompanyId), m => m.CompID == input.CompanyId)
|
|
|
|
|
.WhereIf(!string.IsNullOrEmpty(input.UserId), m => m.UserID == input.UserId)
|
|
|
|
@ -264,7 +283,7 @@ namespace djy.Service.AFR
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task SaveInfo(AFRMaster input)
|
|
|
|
|
public async Task<AFRMaster> SaveInfo(AFRMaster input)
|
|
|
|
|
{
|
|
|
|
|
int type;
|
|
|
|
|
AFRMaster oldMaster = null;
|
|
|
|
@ -296,6 +315,7 @@ namespace djy.Service.AFR
|
|
|
|
|
house.GID = Guid.NewGuid().ToString();
|
|
|
|
|
house.PID = input.GID;
|
|
|
|
|
house.CreateTime = nowTime;
|
|
|
|
|
house.MBLNO = input.MBLNO;
|
|
|
|
|
|
|
|
|
|
// 将null换为空对象,避免后续处理null值麻烦
|
|
|
|
|
house.CntrList ??= new List<AFRCntrno>();
|
|
|
|
@ -304,6 +324,7 @@ namespace djy.Service.AFR
|
|
|
|
|
cntr.GID = Guid.NewGuid().ToString();
|
|
|
|
|
cntr.PID = house.GID;
|
|
|
|
|
cntr.CreateTime = nowTime;
|
|
|
|
|
cntr.HouseBillNo = house.HouseBillNo;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -332,36 +353,38 @@ namespace djy.Service.AFR
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
input.HouseList.ForEach(h =>
|
|
|
|
|
input.HouseList.ForEach(house =>
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(h.GID))
|
|
|
|
|
if (string.IsNullOrEmpty(house.GID))
|
|
|
|
|
{
|
|
|
|
|
h.GID = Guid.NewGuid().ToString();
|
|
|
|
|
h.PID = input.GID;
|
|
|
|
|
h.CreateTime = nowTime;
|
|
|
|
|
house.GID = Guid.NewGuid().ToString();
|
|
|
|
|
house.PID = input.GID;
|
|
|
|
|
house.CreateTime = nowTime;
|
|
|
|
|
house.MBLNO = input.MBLNO;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
h.LastUpdate = nowTime;
|
|
|
|
|
house.LastUpdate = nowTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (h.CntrList == null)
|
|
|
|
|
if (house.CntrList == null)
|
|
|
|
|
{
|
|
|
|
|
h.CntrList = new List<AFRCntrno>();
|
|
|
|
|
house.CntrList = new List<AFRCntrno>();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
h.CntrList.ForEach(c =>
|
|
|
|
|
house.CntrList.ForEach(cntr =>
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(c.GID))
|
|
|
|
|
if (string.IsNullOrEmpty(cntr.GID))
|
|
|
|
|
{
|
|
|
|
|
c.GID = Guid.NewGuid().ToString();
|
|
|
|
|
c.PID = h.GID;
|
|
|
|
|
c.CreateTime = nowTime;
|
|
|
|
|
cntr.GID = Guid.NewGuid().ToString();
|
|
|
|
|
cntr.PID = house.GID;
|
|
|
|
|
cntr.CreateTime = nowTime;
|
|
|
|
|
cntr.HouseBillNo = house.HouseBillNo;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
c.LastUpdate = nowTime;
|
|
|
|
|
cntr.LastUpdate = nowTime;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -470,6 +493,8 @@ namespace djy.Service.AFR
|
|
|
|
|
|
|
|
|
|
tran.Commit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await Get(input.GID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private AFRMasterHistory BuildAFRMasterHistory(string pid, string state, int type, string remark)
|
|
|
|
@ -483,7 +508,7 @@ namespace djy.Service.AFR
|
|
|
|
|
State = state,
|
|
|
|
|
Type = Convert.ToByte(type)
|
|
|
|
|
};
|
|
|
|
|
history.Remark = $"{history.Operator}于{history.CreateTime}{remark}";
|
|
|
|
|
history.Remark = $"{history.Operator}于{(DateTime)history.CreateTime:yyyy-MM-dd HH:mm:ss}{remark}";
|
|
|
|
|
return history;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -518,14 +543,386 @@ namespace djy.Service.AFR
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<string> Send(string ids, int sendType)
|
|
|
|
|
public async Task<string> Send(string ids, string hids, int sendType)
|
|
|
|
|
{
|
|
|
|
|
return sendType switch
|
|
|
|
|
|
|
|
|
|
#region 查询电子口岸的请求参数
|
|
|
|
|
var paramSets = await DbBus.Get(DbList.djydb).Select<ParamSet>().Where(x => x.PARAMNAME == "AFRURL" || x.PARAMNAME == "AFRAccount" || x.PARAMNAME == "AFRKey").ToListAsync(p => new
|
|
|
|
|
{
|
|
|
|
|
_ => "发送成功",
|
|
|
|
|
};
|
|
|
|
|
p.PARAMNAME,
|
|
|
|
|
p.PARAMVALUE
|
|
|
|
|
});
|
|
|
|
|
var afrUrl = paramSets.FirstOrDefault(p => p.PARAMNAME == "AFRURL").PARAMVALUE ?? throw new Exception("需要配置电子口岸AFR服务的接口地址:AFRURL");
|
|
|
|
|
var afrAccount = paramSets.FirstOrDefault(p => p.PARAMNAME == "AFRAccount")?.PARAMVALUE ?? throw new Exception("需要配置用于请求电子口岸AFR服务的账户名:AFRAccount");
|
|
|
|
|
var afrKey = paramSets.FirstOrDefault(p => p.PARAMNAME == "AFRKey")?.PARAMVALUE ?? throw new Exception("需要配置用于请求电子口岸AFR服务的密钥:AFRKey");
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 根据不同的发送类型,使用不同的方式从库里查询要发送的数据
|
|
|
|
|
List<AFRMaster> masterAll = null;
|
|
|
|
|
List<AFRHouse> houseAll = null;
|
|
|
|
|
List<AFRCntrno> cntrAll = null;
|
|
|
|
|
|
|
|
|
|
if (sendType is 1)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(ids))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(ids));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var idArr = ids.Split(',');
|
|
|
|
|
|
|
|
|
|
masterAll = await DbAMS.Select<AFRMaster>().Where(m => m.IsDel == false && idArr.Contains(m.GID)).ToListAsync();
|
|
|
|
|
if (masterAll.Count != idArr.Length)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("所选记录有些已被删除,请刷新页面后重试");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
houseAll = await DbAMS.Select<AFRHouse>().Where(h => h.IsDel == false && idArr.Contains(h.PID)).ToListAsync();
|
|
|
|
|
|
|
|
|
|
var houseGids = houseAll.Select(h => h.GID);
|
|
|
|
|
cntrAll = await DbAMS.Select<AFRCntrno>().Where(c => houseGids.Contains(c.PID)).ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
else if (sendType is 2 or 3)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(hids))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(hids));
|
|
|
|
|
}
|
|
|
|
|
var hidArr = hids.Split(',');
|
|
|
|
|
|
|
|
|
|
houseAll = await DbAMS.Select<AFRHouse>().Where(h => h.IsDel == false && hidArr.Contains(h.GID)).ToListAsync();
|
|
|
|
|
if (houseAll.Count != hidArr.Length)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("所选记录有些已被删除,请刷新页面后重试");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var houseGids = houseAll.Select(h => h.GID);
|
|
|
|
|
cntrAll = await DbAMS.Select<AFRCntrno>().Where(c => hidArr.Contains(c.PID)).ToListAsync();
|
|
|
|
|
|
|
|
|
|
var housePids = houseAll.Select(h => h.PID);
|
|
|
|
|
masterAll = await DbAMS.Select<AFRMaster>().Where(m => m.IsDel == false && housePids.Contains(m.GID)).ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
else if (sendType is 4)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(hids))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(hids));
|
|
|
|
|
}
|
|
|
|
|
var hidArr = hids.Split(',');
|
|
|
|
|
|
|
|
|
|
houseAll = await DbAMS.Select<AFRHouse>().Where(h => h.IsDel == false && hidArr.Contains(h.GID)).ToListAsync();
|
|
|
|
|
if (houseAll.Count != hidArr.Length)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("所选记录有些已被删除,请刷新页面后重试");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
StringBuilder messageBuilder = new();
|
|
|
|
|
|
|
|
|
|
#region 构建请求参数
|
|
|
|
|
// 原始发送
|
|
|
|
|
if (sendType is 1 or 2 or 3)
|
|
|
|
|
{
|
|
|
|
|
foreach (AFRMaster masterItem in masterAll)
|
|
|
|
|
{
|
|
|
|
|
List<AFRHouse> houseList = null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
#region 发送前的参数验证
|
|
|
|
|
houseList = houseAll.Where(h => h.PID == masterItem.GID).ToList() ?? throw new Exception("分单为空");
|
|
|
|
|
|
|
|
|
|
if (masterItem.FilingType == "Tranship" && (string.IsNullOrWhiteSpace(masterItem.LastForeignHarbourCode) || string.IsNullOrWhiteSpace(masterItem.LastForeignHarbour)))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("当【申报运输类型】为【Tranship】时,【交货地全称】与【交货地五字码】为必填项");
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
AFRRequestDto requestDto = new AFRRequestDto()
|
|
|
|
|
{
|
|
|
|
|
// 添加主单的数据
|
|
|
|
|
masterBillInfo = new MasterBillInfo()
|
|
|
|
|
{
|
|
|
|
|
masterBillNo = masterItem.MBLNO,
|
|
|
|
|
shippingNo = masterItem.ShippingNo,
|
|
|
|
|
clause = masterItem.Clause, //test
|
|
|
|
|
consignmentType = masterItem.ConsignmentType,
|
|
|
|
|
dischargeHarbour = masterItem.DischargeHarbour,
|
|
|
|
|
dischargeHarbourCode = masterItem.DischargeHarbourCode,
|
|
|
|
|
estimatedArrivalTime = masterItem.EstimatedArrivalTime,
|
|
|
|
|
filingType = masterItem.FilingType,
|
|
|
|
|
lastForeignHarbour = masterItem.LastForeignHarbour,
|
|
|
|
|
lastForeignHarbourCode = masterItem.LastForeignHarbourCode,
|
|
|
|
|
loadDate = masterItem.LoadDate,
|
|
|
|
|
loadHarbour = masterItem.LoadHarbour,
|
|
|
|
|
loadHarbourCode = masterItem.LoadHarbourCode,
|
|
|
|
|
requesterDea = sysOptionConfig.Webconfig.requesterDea, //test
|
|
|
|
|
shipCompany = masterItem.ShipCompanyMapCode,
|
|
|
|
|
vessel = masterItem.Vessel,
|
|
|
|
|
voyage = masterItem.Voyno
|
|
|
|
|
},
|
|
|
|
|
houseBillInfoList = new List<HouseBillInfo>()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (houseList != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (AFRHouse houseItem in houseList)
|
|
|
|
|
{
|
|
|
|
|
var houseBillInfo = new HouseBillInfo()
|
|
|
|
|
{
|
|
|
|
|
ctnInfo = new Model.AFRDto.CtnInfo() { insertList = new List<InsertList>() },
|
|
|
|
|
businessId = houseItem.HouseBillNo,
|
|
|
|
|
houseBillNo = houseItem.HouseBillNo,
|
|
|
|
|
notifyAddress = houseItem.NotifyAddress,
|
|
|
|
|
notifyCity = houseItem.NotifyCity,
|
|
|
|
|
notifyContact = houseItem.NotifyContact,
|
|
|
|
|
notifyCountry = houseItem.NotifyCountry,
|
|
|
|
|
notifyCountryCode = houseItem.NotifyCountryCode,
|
|
|
|
|
notifyName = houseItem.NotifyName,
|
|
|
|
|
notifyTel = houseItem.NotifyTel,
|
|
|
|
|
receiveAddress = houseItem.ReceiveAddress,
|
|
|
|
|
receiveCity = houseItem.ReceiveCity,
|
|
|
|
|
receiveContact = houseItem.ReceiveContact,
|
|
|
|
|
receiveCountry = houseItem.ReceiveCountry,
|
|
|
|
|
receiveCountryCode = houseItem.ReceiveCountryCode,
|
|
|
|
|
receiveName = houseItem.ReceiveName,
|
|
|
|
|
receiveTel = houseItem.ReceiveTel,
|
|
|
|
|
sendAddress = houseItem.SendAddress,
|
|
|
|
|
sendCity = houseItem.SendCity,
|
|
|
|
|
sendContact = houseItem.SendContact,
|
|
|
|
|
sendCountry = houseItem.SendCountry,
|
|
|
|
|
sendCountryCode = houseItem.SendCountryCode,
|
|
|
|
|
sendName = houseItem.SendName,
|
|
|
|
|
sendTel = houseItem.SendTel,
|
|
|
|
|
shippingNo = houseItem.ShippingNo
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 添加箱信息的数据
|
|
|
|
|
List<AFRCntrno> cntrList = cntrAll.Where(c => c.PID == houseItem.GID).ToList();
|
|
|
|
|
if (cntrList != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (AFRCntrno cntrItem in cntrList)
|
|
|
|
|
{
|
|
|
|
|
houseBillInfo.ctnInfo.insertList.Add(new InsertList()
|
|
|
|
|
{
|
|
|
|
|
containerMark = cntrItem.ContainerMark,
|
|
|
|
|
containerNo = cntrItem.ContainerNo,
|
|
|
|
|
containerType = cntrItem.ContainerTypeMapCode,
|
|
|
|
|
dangerContact = cntrItem.DangerContact,
|
|
|
|
|
dangerContactTel = cntrItem.DangerContactTel,
|
|
|
|
|
dangerGrade = cntrItem.DangerGrade,
|
|
|
|
|
dangerMemo = cntrItem.DangerMemo,
|
|
|
|
|
digit = cntrItem.Digit?.ToString(),
|
|
|
|
|
enProductName = cntrItem.EnProductName,
|
|
|
|
|
grossWeight = cntrItem.GrossWeight?.ToString(),
|
|
|
|
|
hscode = cntrItem.Hscode,
|
|
|
|
|
ignite = cntrItem.Ignite,
|
|
|
|
|
originCountry = cntrItem.OriginCountry,
|
|
|
|
|
originCountryCode = cntrItem.OriginCountryCode,
|
|
|
|
|
packing = cntrItem.PackingMapName,
|
|
|
|
|
packingCode = cntrItem.PackingMapCode,
|
|
|
|
|
sealNo = cntrItem.SealNo,
|
|
|
|
|
shippingMark = cntrItem.ShippingMark,
|
|
|
|
|
unCode = cntrItem.UnCode,
|
|
|
|
|
volume = cntrItem.Volume?.ToString(),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
requestDto.houseBillInfoList.Add(houseBillInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 开始请求电子口岸的接口
|
|
|
|
|
var masterBillInfoStr = JsonConvert.SerializeObject(requestDto);
|
|
|
|
|
var businessParam = new Dictionary<string, string>()
|
|
|
|
|
{
|
|
|
|
|
{ "masterBillInfo", masterBillInfoStr }
|
|
|
|
|
};
|
|
|
|
|
var param = BuildRequestParam(sendType, afrAccount, afrKey, businessParam);
|
|
|
|
|
|
|
|
|
|
var request = JsonConvert.SerializeObject(param);
|
|
|
|
|
var logGuid = Guid.NewGuid().ToString();
|
|
|
|
|
logger.LogInformation($"请求宁波电子口岸API,{logGuid},入参:{request}");
|
|
|
|
|
|
|
|
|
|
string response = await HttpHelp.Post(param, afrUrl, PsotType.Json);
|
|
|
|
|
|
|
|
|
|
logger.LogInformation($"请求宁波电子口岸API,{logGuid},响应:{response}");
|
|
|
|
|
|
|
|
|
|
JObject rlt = JObject.Parse(response);
|
|
|
|
|
var code = rlt.GetValue("code")?.ToString();
|
|
|
|
|
var msg = rlt.GetValue("msg")?.ToString();
|
|
|
|
|
if (code == "T")
|
|
|
|
|
{
|
|
|
|
|
var data = rlt["data"] as JObject;
|
|
|
|
|
|
|
|
|
|
var code2 = data.GetValue("code")?.ToString();
|
|
|
|
|
var msg2 = data.GetValue("msg")?.ToString();
|
|
|
|
|
var data2 = data.GetValue("data")?.ToString();
|
|
|
|
|
|
|
|
|
|
if (code2 == "1")
|
|
|
|
|
{
|
|
|
|
|
string tip = $"发送成功!船东提单号:【{masterItem.MBLNO}】货代提单号:【{string.Join("、", houseList.Select(h => h.HouseBillNo))}】{Environment.NewLine}";
|
|
|
|
|
messageBuilder.Append(tip);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"电子口岸接口返回失败结果(code:{code2},msg:{msg})");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"电子口岸接口调用失败(msg:{msg})");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
string tip;
|
|
|
|
|
if (houseList == null)
|
|
|
|
|
{
|
|
|
|
|
tip = $"发送失败!船东提单号:【{masterItem.MBLNO}】,原因:{ex.Message}{Environment.NewLine}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tip = $"发送失败!船东提单号:【{masterItem.MBLNO}】货代提单号:【{string.Join("、", houseList.Select(h => h.HouseBillNo))}】,原因:{ex.Message}{Environment.NewLine}";
|
|
|
|
|
}
|
|
|
|
|
messageBuilder.Append(tip);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 删除发送
|
|
|
|
|
else if (sendType == 4)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string hbnos = string.Join(',', houseAll.Select(h => h.HouseBillNo));
|
|
|
|
|
var businessParam = new Dictionary<string, string>()
|
|
|
|
|
{
|
|
|
|
|
{ "ids", hbnos },
|
|
|
|
|
{ "fromdea", sysOptionConfig.Webconfig.requesterDea }
|
|
|
|
|
};
|
|
|
|
|
var param = BuildRequestParam(sendType, afrAccount, afrKey, businessParam);
|
|
|
|
|
|
|
|
|
|
var request = JsonConvert.SerializeObject(param);
|
|
|
|
|
var logGuid = Guid.NewGuid().ToString();
|
|
|
|
|
logger.LogInformation($"请求宁波电子口岸API,{logGuid},入参:{request}");
|
|
|
|
|
|
|
|
|
|
string response = await HttpHelp.Post(param, afrUrl, PsotType.Json);
|
|
|
|
|
|
|
|
|
|
logger.LogInformation($"请求宁波电子口岸API,{logGuid},响应:{response}");
|
|
|
|
|
|
|
|
|
|
//JObject rlt = JObject.Parse(response);
|
|
|
|
|
//var code = rlt.GetValue("code")?.ToString();
|
|
|
|
|
//var msg = rlt.GetValue("msg")?.ToString();
|
|
|
|
|
//if (code == "T")
|
|
|
|
|
//{
|
|
|
|
|
// var data = rlt["data"] as JObject;
|
|
|
|
|
|
|
|
|
|
// var code2 = data.GetValue("code")?.ToString();
|
|
|
|
|
// var msg2 = data.GetValue("msg")?.ToString();
|
|
|
|
|
// var data2 = data.GetValue("data")?.ToString();
|
|
|
|
|
|
|
|
|
|
// if (code2 == "1")
|
|
|
|
|
// {
|
|
|
|
|
// string tip = $"发送成功!船东提单号:【{masterItem.MBLNO}】货代提单号:【{string.Join("、", houseList.Select(h => h.HouseBillNo))}】{Environment.NewLine}";
|
|
|
|
|
// messageBuilder.Append(tip);
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// throw new Exception($"电子口岸接口返回失败结果(code:{code2},msg:{msg})");
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
//else
|
|
|
|
|
//{
|
|
|
|
|
// throw new Exception($"电子口岸接口调用失败(msg:{msg})");
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//string tip;
|
|
|
|
|
//if (houseList == null)
|
|
|
|
|
//{
|
|
|
|
|
// tip = $"发送失败!船东提单号:【{masterItem.MBLNO}】,原因:{ex.Message}{Environment.NewLine}";
|
|
|
|
|
//}
|
|
|
|
|
//else
|
|
|
|
|
//{
|
|
|
|
|
// tip = $"发送失败!船东提单号:【{masterItem.MBLNO}】货代提单号:【{string.Join("、", houseList.Select(h => h.HouseBillNo))}】,原因:{ex.Message}{Environment.NewLine}";
|
|
|
|
|
//}
|
|
|
|
|
//messageBuilder.Append(tip);
|
|
|
|
|
//continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return messageBuilder.ToString();
|
|
|
|
|
|
|
|
|
|
//var method = sendType switch
|
|
|
|
|
//{
|
|
|
|
|
// 1 => "eportyun.manifest.afr.sendBill",
|
|
|
|
|
// 2 => "eportyun.manifest.afr.resendBill",
|
|
|
|
|
// 3 => "eportyun.manifest.afr.modifyBill",
|
|
|
|
|
// 4 => "eportyun.manifest.afr.deleteBill",
|
|
|
|
|
// _ => throw new Exception()
|
|
|
|
|
//};
|
|
|
|
|
|
|
|
|
|
//// 原始重发 || 修改发送
|
|
|
|
|
//else if (sendType == 2 || sendType == 3)
|
|
|
|
|
//{
|
|
|
|
|
// foreach (string id in idArr)
|
|
|
|
|
// {
|
|
|
|
|
// var param = new
|
|
|
|
|
// {
|
|
|
|
|
// method = sendType switch
|
|
|
|
|
// {
|
|
|
|
|
// 2 => "eportyun.manifest.afr.sendBill",
|
|
|
|
|
// 3 => "eportyun.manifest.afr.modifyBill",
|
|
|
|
|
// _ => throw new Exception()
|
|
|
|
|
// },
|
|
|
|
|
// masterBillInfo = "",
|
|
|
|
|
// };
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
private SortedDictionary<string, string> BuildRequestParam(int sendType, string afrAccount, string afrKey, Dictionary<string, string> businessParam)
|
|
|
|
|
{
|
|
|
|
|
string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
string method = sendType switch
|
|
|
|
|
{
|
|
|
|
|
1 => "eportyun.manifest.afr.sendBill",
|
|
|
|
|
2 => "eportyun.manifest.afr.resendBill",
|
|
|
|
|
3 => "eportyun.manifest.afr.modifyBill",
|
|
|
|
|
4 => "eportyun.manifest.afr.deleteBill",
|
|
|
|
|
_ => throw new Exception()
|
|
|
|
|
};
|
|
|
|
|
var param = new SortedDictionary<string, string>(StringComparer.Ordinal)
|
|
|
|
|
{
|
|
|
|
|
{ "method", method },
|
|
|
|
|
{ "user_id", afrAccount },
|
|
|
|
|
{ "timestamp", timestamp },
|
|
|
|
|
{ "format", "json" },
|
|
|
|
|
{ "version", "2.0" }
|
|
|
|
|
};
|
|
|
|
|
foreach (var item in businessParam)
|
|
|
|
|
{
|
|
|
|
|
param.Add(item.Key, item.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringBuilder builder = new();
|
|
|
|
|
foreach (var item in param)
|
|
|
|
|
{
|
|
|
|
|
builder.Append(item.Key);
|
|
|
|
|
builder.Append('=');
|
|
|
|
|
builder.Append(item.Value);
|
|
|
|
|
builder.Append('&');
|
|
|
|
|
}
|
|
|
|
|
builder.Append("key=").Append(afrKey);
|
|
|
|
|
param.Add("sign", builder.ToString().ToMd5().ToUpper());
|
|
|
|
|
return param;
|
|
|
|
|
}
|
|
|
|
|
public Task SaveReceipt(AFRReceiptDto input)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|