AFR对接

master
zhangxiaofeng 11 months ago
parent aecdc87e70
commit cdd2dabcb0

@ -865,6 +865,11 @@
发送公司
</summary>
</member>
<member name="P:Common.DJYModel.CustFee.SENDTYPE">
<summary>
0新增发送或原始重发 1修改发送 5删除发送
</summary>
</member>
<member name="P:Common.DJYModel.CustFee.SENDUSER">
<summary>
发送人名
@ -5489,6 +5494,14 @@
<param name="Key"></param>
<returns></returns>
</member>
<member name="M:Common.Tools.YsRedisHelp.RedisGetString(System.String)">
<summary>
读取redis中的对象数据 不存在返回null
</summary>
<typeparam name="T"></typeparam>
<param name="Key"></param>
<returns></returns>
</member>
<member name="T:Common.Tools.SafeTools">
<summary>
安全加密解密类
@ -5825,6 +5838,31 @@
字段类型
</summary>
</member>
<member name="P:Common.Utilities.PageModel`1.PageNumber">
<summary>
第几页从1开始
</summary>
</member>
<member name="P:Common.Utilities.PageModel`1.PageCount">
<summary>
总页数
</summary>
</member>
<member name="P:Common.Utilities.PageModel`1.Count">
<summary>
查询的记录数量
</summary>
</member>
<member name="P:Common.Utilities.PageModel`1.PageSize">
<summary>
每页大小
</summary>
</member>
<member name="P:Common.Utilities.PageModel`1.Result">
<summary>
返回数据
</summary>
</member>
<member name="M:Common.Utilities.ProjectPath.GetProjectDirectoryInfo">
<summary>
获取web父目录所在位置
@ -5865,11 +5903,6 @@
操作状态码200为正常
</summary>
</member>
<member name="P:Common.Utilities.Response.Total">
<summary>
</summary>
</member>
<member name="M:Common.Utilities.Response.#ctor">
<summary>
@ -5886,6 +5919,37 @@
回传的结果
</summary>
</member>
<member name="T:Common.Utilities.ResponsePage`1">
<summary>
WEBAPI通用返回泛型基类
</summary>
<typeparam name="T"></typeparam>
</member>
<member name="P:Common.Utilities.ResponsePage`1.PageNumber">
<summary>
第几页从1开始
</summary>
</member>
<member name="P:Common.Utilities.ResponsePage`1.PageSize">
<summary>
每页多少
</summary>
</member>
<member name="P:Common.Utilities.ResponsePage`1.Count">
<summary>
查询的记录数量
</summary>
</member>
<member name="P:Common.Utilities.ResponsePage`1.PageCount">
<summary>
总页数
</summary>
</member>
<member name="P:Common.Utilities.ResponsePage`1.Result">
<summary>
回传的结果
</summary>
</member>
<member name="T:Common.Utilities.TableData">
<summary>
table的返回数据

@ -21,9 +21,9 @@ namespace djy.IService.Afr
Task<PageModel<AFRMaster>> Load(AFRMasterInputDto input);
Task<AFRMaster> Get(string gid);
Task SaveInfo(AFRMaster input);
Task<AFRMaster> SaveInfo(AFRMaster input);
Task Delete(string ids);
Task<string> Send(string ids, int sendType);
Task<string> Send(string ids, string hids, int sendType);
Task SaveReceipt(AFRReceiptDto input);
Task<List<AFRMasterHistory>> GetHistory(string id);
}

@ -17,9 +17,9 @@ namespace djy.Model.Afr
public string PID { get; set; }
/// <summary>
/// 货代提单号唯一编号 同货代提单号,原始修改删除重发报文,该值要一致
/// 货代提单号 修改报文,该值不可以变更
/// </summary>
public string BusinessId { get; set; }
public string HouseBillNo { get; set; }
/// <summary>
/// 货主箱标志

@ -23,26 +23,39 @@ namespace djy.Model.Afr
/// </summary>
public bool IsDel { get; set; }
///// <summary>
///// 货代提单号唯一编号 同货代提单号,原始修改删除重发报文,该值要一致
///// </summary>
//public string BusinessId { get; set; }
/// <summary>
/// 货代提单号唯一编号 同货代提单号,原始修改删除重发报文,该值要一致
/// 船东提单号
/// </summary>
public string BusinessId { get; set; }
public string MBLNO { get; set; }
/// <summary>
/// 货代提单号 修改报文,该值不可以变更
/// </summary>
public string HouseBillNo { get; set; }
/// <summary>
/// 状态:海关接收
/// 状态:是否已发送
/// </summary>
public bool StateIsSend { get; set; }
/// <summary>
/// 状态:海关是否接收
/// </summary>
public bool StateIsAccept { get; set; }
/// <summary>
/// 状态:是否已匹配
/// </summary>
public byte? StateIsAccept { get; set; }
public bool StateIsMatched { get; set; }
/// <summary>
/// 状态:已匹配
/// 最新状态内容
/// </summary>
public byte? StateIsMatched { get; set; }
public string StateContent { get; set; }
/// <summary>
/// 通知人地址

@ -36,6 +36,11 @@ namespace djy.Model.Afr
/// </summary>
public bool IsDel { get; set; }
/// <summary>
/// 状态:是否已发送
/// </summary>
public bool StateIsSend { get; set; }
/// <summary>
/// 运输条款代码
/// </summary>

@ -1,20 +0,0 @@
using djy.Model.Afr;
using djy.Model.AFR;
using djy.Model.Ams;
using FreeSql.Internal.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace djy.Model.AFRDto
{
public class AFRMasterDto : AFRMaster
{
/// <summary>
/// 分单列表
/// </summary>
List<AMS_House> Houses { get; set; }
}
}

@ -0,0 +1,330 @@
using System;
using System.Collections.Generic;
namespace djy.Model.AFRDto
{
/// <summary>
/// 请求电子口岸接口时,用于 原始发送、修改发送、重新发送 的Dto类
/// </summary>
public class AFRRequestDto
{
public MasterBillInfo masterBillInfo { get; set; }
public List<HouseBillInfo> houseBillInfoList { get; set; }
}
public class MasterBillInfo
{
/// <summary>
/// 船东提单号
/// </summary>
public string masterBillNo { get; set; }
/// <summary>
/// 船东单运编号(选填)
/// </summary>
public string shippingNo { get; set; }
/// <summary>
/// 运输条款代码
/// </summary>
public string clause { get; set; }
/// <summary>
/// 整箱/拼箱 FCL整箱 LCL拼箱
/// </summary>
public string consignmentType { get; set; }
/// <summary>
/// 卸货港全称
/// </summary>
public string dischargeHarbour { get; set; }
/// <summary>
/// 卸货港五字码
/// </summary>
public string dischargeHarbourCode { get; set; }
/// <summary>
/// 预计到达日期
/// </summary>
public DateTime? estimatedArrivalTime { get; set; }
/// <summary>
/// 申报运输类型
/// </summary>
public string filingType { get; set; }
/// <summary>
/// 交货地全称条件申报运输类型Tranship时必填
/// </summary>
public string lastForeignHarbour { get; set; }
/// <summary>
/// 交货地五字码条件申报运输类型Tranship时必填
/// </summary>
public string lastForeignHarbourCode { get; set; }
/// <summary>
/// 预计开船日期
/// </summary>
public DateTime? loadDate { get; set; }
/// <summary>
/// 装货港全称
/// </summary>
public string loadHarbour { get; set; }
/// <summary>
/// 装货港五字码
/// </summary>
public string loadHarbourCode { get; set; }
/// <summary>
/// 船司MapName
/// </summary>
public string shipCompany { get; set; }
/// <summary>
///
/// </summary>
public string vessel { get; set; }
/// <summary>
///
/// </summary>
public string voyage { get; set; }
/// <summary>
/// 发送方DEA CARGOEDI账号联系运营人员配置
/// </summary>
public string requesterDea { get; set; }
}
public class HouseBillInfo
{
/// <summary>
/// 货代提单号唯一编号 同货代提单号,原始修改删除重发报文,该值要一致
/// </summary>
public string businessId { get; set; }
/// <summary>
/// 货代单运编号(选填)
/// </summary>
public string shippingNo { get; set; }
/// <summary>
/// 货代提单号 修改报文,该值不可以变更
/// </summary>
public string houseBillNo { get; set; }
/// <summary>
/// 通知人地址
/// </summary>
public string notifyAddress { get; set; }
/// <summary>
/// 通知人城市
/// </summary>
public string notifyCity { get; set; }
/// <summary>
/// 通知人联系人
/// </summary>
public string notifyContact { get; set; }
/// <summary>
/// 通知人国家
/// </summary>
public string notifyCountry { get; set; }
/// <summary>
/// 通知人国家代码
/// </summary>
public string notifyCountryCode { get; set; }
/// <summary>
/// 通知人名称
/// </summary>
public string notifyName { get; set; }
/// <summary>
/// 通知人联系人电话
/// </summary>
public string notifyTel { get; set; }
/// <summary>
/// 收货人地址
/// </summary>
public string receiveAddress { get; set; }
/// <summary>
/// 收货人城市
/// </summary>
public string receiveCity { get; set; }
/// <summary>
/// 收货人联系人
/// </summary>
public string receiveContact { get; set; }
/// <summary>
/// 收货人国家
/// </summary>
public string receiveCountry { get; set; }
/// <summary>
/// 收货人国家代码
/// </summary>
public string receiveCountryCode { get; set; }
/// <summary>
/// 收货人名称
/// </summary>
public string receiveName { get; set; }
/// <summary>
/// 收货人联系人电话
/// </summary>
public string receiveTel { get; set; }
/// <summary>
/// 发货人地址
/// </summary>
public string sendAddress { get; set; }
/// <summary>
/// 发货人城市
/// </summary>
public string sendCity { get; set; }
/// <summary>
/// 发货人联系人
/// </summary>
public string sendContact { get; set; }
/// <summary>
/// 发货人国家
/// </summary>
public string sendCountry { get; set; }
/// <summary>
/// 发货人国家代码
/// </summary>
public string sendCountryCode { get; set; }
/// <summary>
/// 发货人名称
/// </summary>
public string sendName { get; set; }
/// <summary>
/// 发货人联系人电话
/// </summary>
public string sendTel { get; set; }
//public List<CtnInfo> ctnInfo { get; set; }
public CtnInfo ctnInfo { get; set; }
}
public class CtnInfo
{
public List<InsertList> insertList { get; set; }
}
public class InsertList
{
/// <summary>
/// 货主箱标志
/// </summary>
public string containerMark { get; set; }
/// <summary>
/// 箱号
/// </summary>
public string containerNo { get; set; }
/// <summary>
/// 箱型
/// </summary>
public string containerType { get; set; }
/// <summary>
/// 危品联系人(选填)
/// </summary>
public string dangerContact { get; set; }
/// <summary>
/// 危品联系人电话(选填)
/// </summary>
public string dangerContactTel { get; set; }
/// <summary>
/// 危品等级(条件必填)
/// </summary>
public string dangerGrade { get; set; }
/// <summary>
/// 危品备注(选填)
/// </summary>
public string dangerMemo { get; set; }
/// <summary>
/// 件数
/// </summary>
public string digit { get; set; }
/// <summary>
/// 品名
/// </summary>
public string enProductName { get; set; }
/// <summary>
/// 毛重
/// </summary>
public string grossWeight { get; set; }
/// <summary>
/// HSCode
/// </summary>
public string hscode { get; set; }
/// <summary>
/// 燃点,摄氏度(选填)
/// </summary>
public string ignite { get; set; }
/// <summary>
/// 原产国(选填)
/// </summary>
public string originCountry { get; set; }
/// <summary>
/// 原产国国家代码(选填)
/// </summary>
public string originCountryCode { get; set; }
/// <summary>
/// 包装
/// </summary>
public string packing { get; set; }
/// <summary>
/// 包装代码
/// </summary>
public string packingCode { get; set; }
/// <summary>
/// 封号
/// </summary>
public string sealNo { get; set; }
/// <summary>
/// 唛头
/// </summary>
public string shippingMark { get; set; }
/// <summary>
/// UN CODE条件必填
/// </summary>
public string unCode { get; set; }
/// <summary>
/// 体积
/// </summary>
public string volume { get; set; }
}
}

@ -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)
{
#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)
{
return sendType switch
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();

@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "8.0.0",
"commands": [
"dotnet-ef"
]
}
}
}

@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
namespace djy_AfrApi.Controllers
@ -43,7 +44,7 @@ namespace djy_AfrApi.Controllers
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("PageData")]
public async Task<ResponsePage<AFRMaster>> PageData(AFRMasterInputDto input)
public async Task<ResponsePage<AFRMaster>> PageData([FromQuery] AFRMasterInputDto input)
{
UserAuthorityDto aut = GetUserAuthorityToFormDto("modIsfList");
@ -73,10 +74,10 @@ namespace djy_AfrApi.Controllers
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("AddOrUpdate")]
public async Task<Response> AddOrUpdateAsync([FromBody] AFRMasterDto input)
public async Task<Response<AFRMaster>> AddOrUpdateAsync([FromBody] AFRMaster input)
{
await _afrService.SaveInfo(input);
return SuccessResp();
var result = await _afrService.SaveInfo(input);
return SuccessResp(result);
}
#endregion
@ -98,13 +99,13 @@ namespace djy_AfrApi.Controllers
/// <summary>
/// 发送接口
/// </summary>
/// <param name="ids">主键集合</param>
/// <param name="ids">主单主键的集合,使用,连接当sendType==1时必填</param>
/// <param name="hids">分单主键集合,使用,连接当sendType==2、3、4时必填</param>
/// <param name="sendType">1:发送 2原始重发 3修改发送 4删除发送</param>
/// <returns></returns>
[HttpGet("Send")]
public async Task<Response> Send(string ids, int sendType)
public async Task<Response> Send(string ids, string hids, [Required] int sendType)
{
string message = await _afrService.Send(ids, sendType);
string message = await _afrService.Send(ids, hids, sendType);
return SuccessResp(message);
}

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<DeleteExistingFiles>true</DeleteExistingFiles>
<ExcludeApp_Data>false</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>bin\Release\net5.0\publish-windows\</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<ProjectGuid>e798a4ec-13e8-4681-8db7-cb9f3c32a3ee</ProjectGuid>
<SelfContained>false</SelfContained>
</PropertyGroup>
</Project>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
此文件由 Web 项目的发布/打包过程使用。可以通过编辑此 MSBuild 文件
自定义此过程的行为。为了解与此相关的更多内容,请访问 https://go.microsoft.com/fwlink/?LinkID=208121。
-->
<Project>
<PropertyGroup>
<_PublishTargetUrl>D:\DJY\Code\djyweb_ams\web\djy_AfrApi\bin\Release\net5.0\publish-windows\</_PublishTargetUrl>
<History>True|2024-01-03T08:04:13.6208067Z;True|2024-01-03T15:07:08.9376581+08:00;True|2024-01-02T10:57:59.7067270+08:00;True|2024-01-02T10:28:44.8223638+08:00;True|2023-12-29T17:26:12.9612280+08:00;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>

@ -23,13 +23,14 @@
"ConnName": "sqldb",
"cache_time": 10,
"WebHostUrl": "http://127.0.0.1:30818",
"Redis": "192.168.0.80:6379,password=,defaultDatabase=12",
"Redis": "127.0.0.1:6379,password=,defaultDatabase=12",
"RedisDb": 12,
"Rbmq_Host": "",
"Rbmq_UserName": "admin",
"Rbmq_Password": "admin",
"Rbmq_Sqlhost": "Data Source =60.209.125.238; Initial Catalog=djy_logs; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true",
"DapperDbString": "Data Source =60.209.125.238,32009; Initial Catalog=DevAMS; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true;",
"requesterDea": "HWCDDS",
"DataConnList": [
{
"SysKey": "AMS",
@ -45,7 +46,7 @@
"Index": 100,
"DataType": 1,
"Status": 0,
"ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=DevCommonDB; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true;"
"ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=TestCommonDB; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true;"
},
{
"SysKey": "djydb",

@ -30,6 +30,7 @@
"Rbmq_Password": "djy_ams",
"Rbmq_Sqlhost": "Data Source =172.31.85.154; Initial Catalog=djy_logs; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true",
"DapperDbString": "Data Source =172.31.85.161; Initial Catalog=AMS; Persist Security Info=True; User ID =sa; Password=QDdjy#2020*;pooling=true;",
"requesterDea": "HWCDDS",
"DataConnList": [
{
"SysKey": "AMS",

@ -23,13 +23,14 @@
"ConnName": "sqldb",
"cache_time": 10,
"WebHostUrl": "http://127.0.0.1:30818",
"Redis": "192.168.0.80:6379,password=,defaultDatabase=待配置待配置待配置待配置待配置待配置待配置待配置待配置待配置待配置待配置待配置待配置待配置",
"RedisDb": "待配置待配置待配置待配置待配置待配置待配置待配置待配置待配置待配置待配置待配置待配置待配置待配置待配置待配置",
"Redis": "192.168.1.83:6379,password=,defaultDatabase=12",
"RedisDb": "12",
"Rbmq_Host": "",
"Rbmq_UserName": "admin",
"Rbmq_Password": "admin",
"Rbmq_Sqlhost": "Data Source =60.209.125.238; Initial Catalog=djy_logs; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true",
"DapperDbString": "Data Source =60.209.125.238,32009; Initial Catalog=DevAMS; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true;",
"requesterDea": "HWCDDS",
"DataConnList": [
{
"SysKey": "AMS",

@ -4,6 +4,7 @@
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/Api</Controller_SelectedScaffolderCategoryPath>
<ActiveDebugProfile>djy_AfrApi</ActiveDebugProfile>
<NameOfLastUsedPublishProfile>D:\DJY\Code\djyweb_ams\web\djy_AfrApi\Properties\PublishProfiles\FolderProfile-Windows.pubxml</NameOfLastUsedPublishProfile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>

Loading…
Cancel
Save