From 1933217e67170c24807c7cfa28b337b9344944f2 Mon Sep 17 00:00:00 2001 From: wanghaomei <86whm@163.com> Date: Wed, 15 May 2024 17:25:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=A3=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EDI/ZhongYuanSoApiHelper.cs | 2 +- .../BookingCustomerOrderService.cs | 142 +++++++++++++++++- 2 files changed, 142 insertions(+), 2 deletions(-) diff --git a/Myshipping.Application/EDI/ZhongYuanSoApiHelper.cs b/Myshipping.Application/EDI/ZhongYuanSoApiHelper.cs index 1fca0684..3100a8ee 100644 --- a/Myshipping.Application/EDI/ZhongYuanSoApiHelper.cs +++ b/Myshipping.Application/EDI/ZhongYuanSoApiHelper.cs @@ -158,7 +158,7 @@ namespace Myshipping.Application.EDI sailSchedulePriority = template.Priority.Split(',').ToList(), outboundHaulage = mapServArr[0], inboundHaulage = mapServArr[1], - searchConditionDate = DateTime.Today.AddDays(startDay).ToString("yyyy-MM-dd"), + searchConditionDate = custOrder.ETD.Value.AddDays(startDay).ToString("yyyy-MM-dd"), numberOfWeeks = endWeek, etd = custOrder.ETD.Value.ToString("yyyy-MM-dd"), }; diff --git a/Myshipping.Application/Service/BookingCustomerOrder/BookingCustomerOrderService.cs b/Myshipping.Application/Service/BookingCustomerOrder/BookingCustomerOrderService.cs index ea05d807..ac41963f 100644 --- a/Myshipping.Application/Service/BookingCustomerOrder/BookingCustomerOrderService.cs +++ b/Myshipping.Application/Service/BookingCustomerOrder/BookingCustomerOrderService.cs @@ -3,6 +3,7 @@ using Furion.DependencyInjection; using Furion.DynamicApiController; using Furion.EventBus; using Furion.FriendlyException; +using Furion.LinqBuilder; using Furion.RemoteRequest.Extensions; using Mapster; using MathNet.Numerics.LinearAlgebra.Factorization; @@ -28,8 +29,10 @@ using RabbitMQ.Client; using System; using System.Collections.Generic; using System.Data; +using System.Drawing.Drawing2D; using System.IO; using System.Linq; +using System.Net.Http; using System.Text; using System.Threading.Tasks; using Yitter.IdGenerator; @@ -63,6 +66,8 @@ namespace Myshipping.Application private readonly IBookingOrderService bookingOrderService; private readonly SqlSugarRepository _repCustomer; private readonly SqlSugarRepository _repCustomerParamValue; + private readonly SqlSugarRepository _repCustomerContact; + private readonly SqlSugarRepository _repFeeRecord; public BookingCustomerOrderService(SqlSugarRepository rep, SqlSugarRepository repCtn, ILogger logger, ISysCacheService cache, SqlSugarRepository repFile, @@ -71,7 +76,8 @@ namespace Myshipping.Application SqlSugarRepository repOrderTempl, SqlSugarRepository repEdiExt, SqlSugarRepository goodsStatus, SqlSugarRepository goodsStatusConfig, IEventPublisher publisher, SqlSugarRepository repApiAuth, SqlSugarRepository repMessage, IBookingOrderService bookingOrderService, - SqlSugarRepository repCustomer, SqlSugarRepository repCustomerParamValue) + SqlSugarRepository repCustomer, SqlSugarRepository repCustomerParamValue, SqlSugarRepository repCustomerContact, + SqlSugarRepository repFeeRecord) { this._logger = logger; this._rep = rep; @@ -92,6 +98,8 @@ namespace Myshipping.Application this.bookingOrderService = bookingOrderService; this._repCustomer = repCustomer; this._repCustomerParamValue = repCustomerParamValue; + this._repCustomerContact = repCustomerContact; + this._repFeeRecord = repFeeRecord; } #region 订舱草稿及附件 @@ -1839,6 +1847,9 @@ namespace Myshipping.Application } + + //扣费 + await FeeSo(model.Id); } @@ -1969,6 +1980,15 @@ namespace Myshipping.Application await _publisher.PublishAsync(new ChannelEventSource("Message:NotifyReceiveNew")); } + /// + /// 扣费 + /// + /// + [HttpPost("/BookingCustomerOrder/DoFee")] + public async Task DoFee(long custOrdId) + { + await FeeSo(custOrdId); + } #endregion #region 私有方法 @@ -2007,6 +2027,126 @@ namespace Myshipping.Application staLog.Remark = remark; _repStatuslog.Insert(staLog); } + + /// + /// 订舱审核后自动扣费 + /// + /// + private async Task FeeSo(long id) + { + var model = await _rep.AsQueryable().Filter(null, true).FirstAsync(x => x.Id == id); + var cust = await _repCustomer.AsQueryable().Filter(null, true).FirstAsync(x => x.CustSysId == model.BookingTenantId); + var custParaList = await _repCustomerParamValue.AsQueryable().Filter(null, true).Where(x => x.CustomerId == cust.Id && (x.ParaCode == "DjyFeeApiUserId" || x.ParaCode == "DjyFeeApiUserSecret")).ToListAsync(); + + var bsType = 32; + var sendType = 0; + var typeStr = $"{bsType}_{sendType}"; + var sysCfg = await _cache.GetAllSysConfig(); + var feeUrl = sysCfg.FirstOrDefault(x => x.Code == "djyFeeApiUrl"); + if (feeUrl == null || string.IsNullOrEmpty(feeUrl.Value)) + { + var errMsg = "大简云扣费URL未配置"; + _logger.LogError(errMsg); + SaveAuditLog($"扣费失败", model.Id, model.CreatedUserId.Value, model.TenantId.Value, "系统", remark: errMsg); + return; + } + + //扣费接口用户id和key + var feeUserId = custParaList.FirstOrDefault(x => x.ParaCode == "DjyFeeApiUserId")?.ItemCode; + var feeUserKey = custParaList.FirstOrDefault(x => x.ParaCode == "DjyFeeApiUserSecret")?.ItemCode; + if (string.IsNullOrEmpty(feeUserId) || string.IsNullOrEmpty(feeUserKey)) + { + var errMsg = $"未找到{model.BOOKINGNO}({model.Id})所在客户的授权userid和key,无法调用扣费"; + _logger.LogError(errMsg); + SaveAuditLog($"扣费失败", model.Id, model.CreatedUserId.Value, model.TenantId.Value, "系统", remark: "未找到扣费接口授权信息"); + return; + } + + //判断重复扣费 + var c = _repFeeRecord.AsQueryable().Filter(null, true).Count(x => x.TenantId == model.BookingTenantId && x.MBLNO == model.BOOKINGNO); + if (c > 0) + { + _logger.LogInformation($"已存在扣费记录,id:{model.Id},订舱号:{model.BOOKINGNO},租户:{model.BookingTenantId}"); + return; + } + + //客户联系人 + var contact = await _repCustomerContact.AsQueryable().Filter(null, true).FirstAsync(x => x.CustSysId == model.BookingUserId); + if (contact == null) + { + var errMsg = $"未找到{model.BOOKINGNO}({model.Id})的客户联系人"; + _logger.LogError(errMsg); + SaveAuditLog($"扣费失败", model.Id, model.CreatedUserId.Value, model.TenantId.Value, "系统", remark: "未找到客户联系人"); + return; + } + + //扣费dto + var seconds = DateTime.Now.ToTimeStamp(); + var runId = Guid.NewGuid().ToString(); + var srcBeforMD5 = $"{runId}{feeUserId}expend{bsType}{sendType}{model.Id}{model.BOOKINGNO}{seconds}{feeUserKey}"; + var postObj = new + { + runId, + userId = feeUserId, + module = "expend",//固定 + bsType = $"{bsType}", + sendType = $"{sendType}", + timestamp = seconds,//秒级时间戳 + md5 = srcBeforMD5.ToMd5(),// 加密字符串小写 RunId + UserId + Module + BsType + SendType+Timestamp+ Key + Data = new + { + BSNO = model.Id.ToString(), + MBLNO = model.BOOKINGNO, + CtnrInfo = "", + CtnrCount = 1, + IsCredit = 0,//是否是信用支付 1 信用支付 0不允许信用支付默认值为0, + LURURENID = contact.DjyGid, + SENDUSERID = contact.DjyGid, + VESSEL = model.VESSEL, + VOYNO = model.VOYNO, + ETD = model.ETD, + CARRIER = model.CARRIER + } + }; + + _logger.LogInformation($"调用扣费:{postObj.ToJsonString()}"); + var apiRtn = await feeUrl.Value + .SetHttpMethod(HttpMethod.Post) + .SetBody(postObj) + .SetRetryPolicy(3, 5000) + .OnException((c, m, errMsg) => + { + _logger.LogError($"扣费失败:{errMsg}"); + SaveAuditLog($"扣费失败", model.Id, model.CreatedUserId.Value, model.TenantId.Value, "系统", remark: errMsg); + }) + .SendAsStringAsync(); + _logger.LogInformation($"调用扣费返回:{apiRtn}"); + var jobjApiRtn = JObject.Parse(apiRtn); + var code = jobjApiRtn.GetIntValue("code"); + var jobjApiRtnData = jobjApiRtn.GetValue("data") as JObject; + if (code == 200 || code == 450) + { + var jobjApiRtnDataPayInfo = jobjApiRtnData.GetValue("payInfo") as JObject; + var price = Convert.ToDecimal(jobjApiRtnDataPayInfo.GetValue("price").ToString()); + var total = Convert.ToDecimal(jobjApiRtnDataPayInfo.GetValue("total").ToString()); + + //记录扣费 + var fr = new BookingFeeRecord(); + fr.Id = YitIdHelper.NextId(); + fr.BillId = model.Id; + fr.MBLNO = model.BOOKINGNO; + fr.TenantId = model.BookingTenantId; + fr.Type = typeStr; + fr.Amount = total; + await _repFeeRecord.InsertAsync(fr); + } + else + { + var errMsg = jobjApiRtn.GetValue("message").ToString(); + _logger.LogError($"扣费失败:{errMsg}"); + SaveAuditLog($"扣费失败", model.Id, model.CreatedUserId.Value, model.TenantId.Value, "系统", remark: errMsg); + } + } #endregion #region 外部开放接口