diff --git a/web/Djy.Common/Common.xml b/web/Djy.Common/Common.xml index f403217..fcf219e 100644 --- a/web/Djy.Common/Common.xml +++ b/web/Djy.Common/Common.xml @@ -865,6 +865,11 @@ 发送公司 + + + 0:新增发送或原始重发 1:修改发送 5:删除发送 + + 发送人名 @@ -5489,6 +5494,14 @@ + + + 读取redis中的对象数据 不存在返回null + + + + + 安全加密解密类 @@ -5825,6 +5838,31 @@ 字段类型 + + + 第几页,从1开始 + + + + + 总页数 + + + + + 查询的记录数量 + + + + + 每页大小 + + + + + 返回数据 + + 获取web父目录所在位置 @@ -5865,11 +5903,6 @@ 操作状态码,200为正常 - - - - - @@ -5886,6 +5919,37 @@ 回传的结果 + + + WEBAPI通用返回泛型基类 + + + + + + 第几页,从1开始 + + + + + 每页多少 + + + + + 查询的记录数量 + + + + + 总页数 + + + + + 回传的结果 + + table的返回数据 diff --git a/web/djy.IService/Afr/IAfrService.cs b/web/djy.IService/Afr/IAfrService.cs index 29756b8..f8cda5f 100644 --- a/web/djy.IService/Afr/IAfrService.cs +++ b/web/djy.IService/Afr/IAfrService.cs @@ -21,9 +21,9 @@ namespace djy.IService.Afr Task> Load(AFRMasterInputDto input); Task Get(string gid); - Task SaveInfo(AFRMaster input); + Task SaveInfo(AFRMaster input); Task Delete(string ids); - Task Send(string ids, int sendType); + Task Send(string ids, string hids, int sendType); Task SaveReceipt(AFRReceiptDto input); Task> GetHistory(string id); } diff --git a/web/djy.Model/AFR/AFRCntrno.cs b/web/djy.Model/AFR/AFRCntrno.cs index f6a8edd..872588f 100644 --- a/web/djy.Model/AFR/AFRCntrno.cs +++ b/web/djy.Model/AFR/AFRCntrno.cs @@ -17,9 +17,9 @@ namespace djy.Model.Afr public string PID { get; set; } /// - /// 货代提单号唯一编号 同货代提单号,原始修改删除重发报文,该值要一致 + /// 货代提单号 修改报文,该值不可以变更 /// - public string BusinessId { get; set; } + public string HouseBillNo { get; set; } /// /// 货主箱标志 diff --git a/web/djy.Model/AFR/AFRHouse.cs b/web/djy.Model/AFR/AFRHouse.cs index 404dad3..7d1cbac 100644 --- a/web/djy.Model/AFR/AFRHouse.cs +++ b/web/djy.Model/AFR/AFRHouse.cs @@ -23,26 +23,39 @@ namespace djy.Model.Afr /// public bool IsDel { get; set; } + ///// + ///// 货代提单号唯一编号 同货代提单号,原始修改删除重发报文,该值要一致 + ///// + //public string BusinessId { get; set; } + /// - /// 货代提单号唯一编号 同货代提单号,原始修改删除重发报文,该值要一致 + /// 船东提单号 /// - public string BusinessId { get; set; } - - + public string MBLNO { get; set; } /// /// 货代提单号 修改报文,该值不可以变更 /// public string HouseBillNo { get; set; } /// - /// 状态:海关接收 + /// 状态:是否已发送 + /// + public bool StateIsSend { get; set; } + + /// + /// 状态:海关是否接收 + /// + public bool StateIsAccept { get; set; } + + /// + /// 状态:是否已匹配 /// - public byte? StateIsAccept { get; set; } + public bool StateIsMatched { get; set; } /// - /// 状态:已匹配 + /// 最新状态内容 /// - public byte? StateIsMatched { get; set; } + public string StateContent { get; set; } /// /// 通知人地址 diff --git a/web/djy.Model/AFR/AFRMaster.cs b/web/djy.Model/AFR/AFRMaster.cs index 9d105eb..14f900c 100644 --- a/web/djy.Model/AFR/AFRMaster.cs +++ b/web/djy.Model/AFR/AFRMaster.cs @@ -36,6 +36,11 @@ namespace djy.Model.Afr /// public bool IsDel { get; set; } + /// + /// 状态:是否已发送 + /// + public bool StateIsSend { get; set; } + /// /// 运输条款代码 /// diff --git a/web/djy.Model/AFRDto/AFRMasterDto.cs b/web/djy.Model/AFRDto/AFRMasterDto.cs deleted file mode 100644 index 0f409e8..0000000 --- a/web/djy.Model/AFRDto/AFRMasterDto.cs +++ /dev/null @@ -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 - { - /// - /// 分单列表 - /// - List Houses { get; set; } - } -} diff --git a/web/djy.Model/AFRDto/AFRRequestDto.cs b/web/djy.Model/AFRDto/AFRRequestDto.cs new file mode 100644 index 0000000..17e3d3f --- /dev/null +++ b/web/djy.Model/AFRDto/AFRRequestDto.cs @@ -0,0 +1,330 @@ +using System; +using System.Collections.Generic; + +namespace djy.Model.AFRDto +{ + /// + /// 请求电子口岸接口时,用于 原始发送、修改发送、重新发送 的Dto类 + /// + public class AFRRequestDto + { + public MasterBillInfo masterBillInfo { get; set; } + public List houseBillInfoList { get; set; } + } + public class MasterBillInfo + { + /// + /// 船东提单号 + /// + public string masterBillNo { get; set; } + /// + /// 船东单运编号(选填) + /// + public string shippingNo { get; set; } + + /// + /// 运输条款代码 + /// + public string clause { get; set; } + + /// + /// 整箱/拼箱 FCL:整箱 LCL:拼箱 + /// + public string consignmentType { get; set; } + + /// + /// 卸货港全称 + /// + public string dischargeHarbour { get; set; } + + /// + /// 卸货港五字码 + /// + public string dischargeHarbourCode { get; set; } + + /// + /// 预计到达日期 + /// + public DateTime? estimatedArrivalTime { get; set; } + + /// + /// 申报运输类型 + /// + public string filingType { get; set; } + + /// + /// 交货地全称(条件)申报运输类型Tranship时,必填 + /// + public string lastForeignHarbour { get; set; } + + /// + /// 交货地五字码(条件)申报运输类型Tranship时,必填 + /// + public string lastForeignHarbourCode { get; set; } + + /// + /// 预计开船日期 + /// + public DateTime? loadDate { get; set; } + + /// + /// 装货港全称 + /// + public string loadHarbour { get; set; } + + /// + /// 装货港五字码 + /// + public string loadHarbourCode { get; set; } + + /// + /// 船司MapName + /// + public string shipCompany { get; set; } + + /// + /// + /// + public string vessel { get; set; } + + /// + /// + /// + public string voyage { get; set; } + + /// + /// 发送方DEA CARGOEDI账号,联系运营人员配置 + /// + public string requesterDea { get; set; } + } + public class HouseBillInfo + { + /// + /// 货代提单号唯一编号 同货代提单号,原始修改删除重发报文,该值要一致 + /// + public string businessId { get; set; } + + /// + /// 货代单运编号(选填) + /// + public string shippingNo { get; set; } + + /// + /// 货代提单号 修改报文,该值不可以变更 + /// + public string houseBillNo { get; set; } + + /// + /// 通知人地址 + /// + public string notifyAddress { get; set; } + + /// + /// 通知人城市 + /// + public string notifyCity { get; set; } + + /// + /// 通知人联系人 + /// + public string notifyContact { get; set; } + + /// + /// 通知人国家 + /// + public string notifyCountry { get; set; } + + /// + /// 通知人国家代码 + /// + public string notifyCountryCode { get; set; } + + /// + /// 通知人名称 + /// + public string notifyName { get; set; } + + /// + /// 通知人联系人电话 + /// + public string notifyTel { get; set; } + + /// + /// 收货人地址 + /// + public string receiveAddress { get; set; } + + /// + /// 收货人城市 + /// + public string receiveCity { get; set; } + + /// + /// 收货人联系人 + /// + public string receiveContact { get; set; } + + /// + /// 收货人国家 + /// + public string receiveCountry { get; set; } + + /// + /// 收货人国家代码 + /// + public string receiveCountryCode { get; set; } + + /// + /// 收货人名称 + /// + public string receiveName { get; set; } + + /// + /// 收货人联系人电话 + /// + public string receiveTel { get; set; } + + /// + /// 发货人地址 + /// + public string sendAddress { get; set; } + + /// + /// 发货人城市 + /// + public string sendCity { get; set; } + + /// + /// 发货人联系人 + /// + public string sendContact { get; set; } + + /// + /// 发货人国家 + /// + public string sendCountry { get; set; } + + /// + /// 发货人国家代码 + /// + public string sendCountryCode { get; set; } + + /// + /// 发货人名称 + /// + public string sendName { get; set; } + + /// + /// 发货人联系人电话 + /// + public string sendTel { get; set; } + + //public List ctnInfo { get; set; } + public CtnInfo ctnInfo { get; set; } + } + public class CtnInfo + { + public List insertList { get; set; } + } + public class InsertList + { + /// + /// 货主箱标志 + /// + public string containerMark { get; set; } + + /// + /// 箱号 + /// + public string containerNo { get; set; } + + /// + /// 箱型 + /// + public string containerType { get; set; } + + /// + /// 危品联系人(选填) + /// + public string dangerContact { get; set; } + + /// + /// 危品联系人电话(选填) + /// + public string dangerContactTel { get; set; } + + /// + /// 危品等级(条件必填) + /// + public string dangerGrade { get; set; } + + /// + /// 危品备注(选填) + /// + public string dangerMemo { get; set; } + + /// + /// 件数 + /// + public string digit { get; set; } + + /// + /// 品名 + /// + public string enProductName { get; set; } + + /// + /// 毛重 + /// + public string grossWeight { get; set; } + + /// + /// HSCode + /// + public string hscode { get; set; } + + /// + /// 燃点,摄氏度(选填) + /// + public string ignite { get; set; } + + /// + /// 原产国(选填) + /// + public string originCountry { get; set; } + + /// + /// 原产国国家代码(选填) + /// + public string originCountryCode { get; set; } + + /// + /// 包装 + /// + public string packing { get; set; } + /// + /// 包装代码 + /// + public string packingCode { get; set; } + + /// + /// 封号 + /// + public string sealNo { get; set; } + + /// + /// 唛头 + /// + public string shippingMark { get; set; } + + /// + /// UN CODE(条件必填) + /// + public string unCode { get; set; } + + /// + /// 体积 + /// + public string volume { get; set; } + } +} diff --git a/web/djy.Service/Afr/AfrService.cs b/web/djy.Service/Afr/AfrService.cs index 69171f6..da2300e 100644 --- a/web/djy.Service/Afr/AfrService.cs +++ b/web/djy.Service/Afr/AfrService.cs @@ -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 logger; + private IUser User { get; } - public AfrService(IUser user) + public AfrService(IUser user, ILogger logger) { User = user; + this.logger = logger; } #region 下拉接口 public List GetCountry(string strlink, int page, int limit) @@ -61,7 +75,7 @@ namespace djy.Service.AFR { try { - var List = DbBus.Get(DbList.Common).Select().InnerJoin((cc, map) => cc.Code == map.Code && map.Module == "AMS").ToList((cc, map) => new CommonMappiCode + var List = DbBus.Get(DbList.Common).Select().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().InnerJoin((cc, map) => cc.Code == map.Code && map.Module == "AMS").ToList((cc, map) => new CommonMappiCode + var List = DbBus.Get(DbList.Common).Select().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().InnerJoin((cc, map) => cc.Code == map.Code && map.Module == "AMS").ToList((cc, map) => new CommonMappiCode + var List = DbBus.Get(DbList.Common).Select().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> Load(AFRMasterInputDto input) { ISelect select = null; + + bool isSend = false; + // 查询草稿箱列表,草稿箱列表采用一主单内含有多个分单的显示模式 if (input.Type == 1) { select = DbAMS.Select(); + isSend = false; } - // 查询已发送列表,已发送列表采用按分单的显示方式 + // 查询已发送列表,已发送列表采用按分单的显示方式,所以采用内连接的方式 else if (input.Type == 2) { select = DbAMS.Select() .InnerJoin((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 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(); @@ -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(); + house.CntrList = new List(); } 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 Send(string ids, int sendType) + public async Task Send(string ids, string hids, int sendType) { - return sendType switch + + #region 查询电子口岸的请求参数 + var paramSets = await DbBus.Get(DbList.djydb).Select().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 masterAll = null; + List houseAll = null; + List cntrAll = null; + + if (sendType is 1) + { + if (string.IsNullOrEmpty(ids)) + { + throw new ArgumentNullException(nameof(ids)); + } + + var idArr = ids.Split(','); + + masterAll = await DbAMS.Select().Where(m => m.IsDel == false && idArr.Contains(m.GID)).ToListAsync(); + if (masterAll.Count != idArr.Length) + { + throw new Exception("所选记录有些已被删除,请刷新页面后重试"); + } + + houseAll = await DbAMS.Select().Where(h => h.IsDel == false && idArr.Contains(h.PID)).ToListAsync(); + + var houseGids = houseAll.Select(h => h.GID); + cntrAll = await DbAMS.Select().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().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().Where(c => hidArr.Contains(c.PID)).ToListAsync(); + + var housePids = houseAll.Select(h => h.PID); + masterAll = await DbAMS.Select().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().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 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() + }; + + if (houseList != null) + { + foreach (AFRHouse houseItem in houseList) + { + var houseBillInfo = new HouseBillInfo() + { + ctnInfo = new Model.AFRDto.CtnInfo() { insertList = new List() }, + 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 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() + { + { "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() + { + { "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 BuildRequestParam(int sendType, string afrAccount, string afrKey, Dictionary 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(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(); diff --git a/web/djy_AfrApi/.config/dotnet-tools.json b/web/djy_AfrApi/.config/dotnet-tools.json new file mode 100644 index 0000000..e3cadb9 --- /dev/null +++ b/web/djy_AfrApi/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "dotnet-ef": { + "version": "8.0.0", + "commands": [ + "dotnet-ef" + ] + } + } +} \ No newline at end of file diff --git a/web/djy_AfrApi/Controllers/AfrController.cs b/web/djy_AfrApi/Controllers/AfrController.cs index 43faad1..2c57639 100644 --- a/web/djy_AfrApi/Controllers/AfrController.cs +++ b/web/djy_AfrApi/Controllers/AfrController.cs @@ -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 /// /// [HttpGet("PageData")] - public async Task> PageData(AFRMasterInputDto input) + public async Task> PageData([FromQuery] AFRMasterInputDto input) { UserAuthorityDto aut = GetUserAuthorityToFormDto("modIsfList"); @@ -73,10 +74,10 @@ namespace djy_AfrApi.Controllers /// /// [HttpPost("AddOrUpdate")] - public async Task AddOrUpdateAsync([FromBody] AFRMasterDto input) + public async Task> 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 /// /// 发送接口 /// - /// 主键集合 + /// 主单主键的集合,使用,连接(当sendType==1时必填) + /// 分单主键集合,使用,连接(当sendType==2、3、4时必填) /// 1:发送 2:原始重发 3:修改发送 4:删除发送 - /// [HttpGet("Send")] - public async Task Send(string ids, int sendType) + public async Task 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); } diff --git a/web/djy_AfrApi/Properties/PublishProfiles/FolderProfile-Windows.pubxml b/web/djy_AfrApi/Properties/PublishProfiles/FolderProfile-Windows.pubxml new file mode 100644 index 0000000..07cad65 --- /dev/null +++ b/web/djy_AfrApi/Properties/PublishProfiles/FolderProfile-Windows.pubxml @@ -0,0 +1,22 @@ + + + + + true + false + true + Release + Any CPU + FileSystem + bin\Release\net5.0\publish-windows\ + FileSystem + <_TargetId>Folder + + net5.0 + win-x64 + e798a4ec-13e8-4681-8db7-cb9f3c32a3ee + false + + \ No newline at end of file diff --git a/web/djy_AfrApi/Properties/PublishProfiles/FolderProfile-Windows.pubxml.user b/web/djy_AfrApi/Properties/PublishProfiles/FolderProfile-Windows.pubxml.user new file mode 100644 index 0000000..312dda1 --- /dev/null +++ b/web/djy_AfrApi/Properties/PublishProfiles/FolderProfile-Windows.pubxml.user @@ -0,0 +1,12 @@ + + + + + <_PublishTargetUrl>D:\DJY\Code\djyweb_ams\web\djy_AfrApi\bin\Release\net5.0\publish-windows\ + 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; + + + \ No newline at end of file diff --git a/web/djy_AfrApi/appsettings.Development.json b/web/djy_AfrApi/appsettings.Development.json index 69b9a9c..41d33cf 100644 --- a/web/djy_AfrApi/appsettings.Development.json +++ b/web/djy_AfrApi/appsettings.Development.json @@ -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", diff --git a/web/djy_AfrApi/appsettings.Production.json b/web/djy_AfrApi/appsettings.Production.json index b6fd8be..5f9e01f 100644 --- a/web/djy_AfrApi/appsettings.Production.json +++ b/web/djy_AfrApi/appsettings.Production.json @@ -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", diff --git a/web/djy_AfrApi/appsettings.Staging.json b/web/djy_AfrApi/appsettings.Staging.json index a6a722b..b629a9a 100644 --- a/web/djy_AfrApi/appsettings.Staging.json +++ b/web/djy_AfrApi/appsettings.Staging.json @@ -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", diff --git a/web/djy_AfrApi/djy_AfrApi.csproj.user b/web/djy_AfrApi/djy_AfrApi.csproj.user index ad27d65..a281873 100644 --- a/web/djy_AfrApi/djy_AfrApi.csproj.user +++ b/web/djy_AfrApi/djy_AfrApi.csproj.user @@ -4,6 +4,7 @@ ApiControllerEmptyScaffolder root/Common/Api djy_AfrApi + D:\DJY\Code\djyweb_ams\web\djy_AfrApi\Properties\PublishProfiles\FolderProfile-Windows.pubxml ProjectDebugger