快递模块调整

optimize
zhangxiaofeng 12 months ago
parent 7f5893c8db
commit 99c28f001f

@ -18,6 +18,11 @@ namespace Myshipping.Application.Service.ExpressDelivery.Dto
/// 客户订单号,重复使用订单号时返回第一次下单成功时的运单信息 /// 客户订单号,重复使用订单号时返回第一次下单成功时的运单信息
/// </summary> /// </summary>
public string orderId { get; set; } public string orderId { get; set; }
/// <summary>
/// 顺丰月结卡号 月结支付时传值,现结不需传值;
/// </summary>
public string monthlyCard { get; set; }
} }
public class CargoDetailsItem public class CargoDetailsItem
{ {

@ -95,6 +95,28 @@ namespace Myshipping.Application
} }
return list; return list;
} }
/// <summary>
/// 获取详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
[HttpPost("Get")]
public async Task<dynamic> Get(long Id)
{
ExpressDeliveryDto ordOut = new ExpressDeliveryDto();
var main = await _orderRep.FirstOrDefaultAsync(u => u.Id == Id);
if (main != null)
{
ordOut = main.Adapt<ExpressDeliveryDto>();
var business = await _businessRep.AsQueryable().Where(x => x.PId == Id).ToListAsync();
ordOut.Business = business;
}
return ordOut;
}
/// <summary> /// <summary>
/// 保存并返回数据 /// 保存并返回数据
/// </summary> /// </summary>
@ -110,8 +132,8 @@ namespace Myshipping.Application
if (input.Id == 0) if (input.Id == 0)
{ {
entity.CurrentStateCode = "DJY01"; entity.CurrentStateCode = "DJY02";
entity.CurrentStateDesc = "新建"; entity.CurrentStateDesc = "已保存";
_logger.LogInformation($"快递订单新增操作开始,{logGuid}"); _logger.LogInformation($"快递订单新增操作开始,{logGuid}");
@ -143,6 +165,11 @@ namespace Myshipping.Application
} }
else else
{ {
var oldOrder = _orderRep.FirstOrDefault(x => x.Id == input.Id);
if (oldOrder.CurrentStateCode != "DJY02")
{
throw Oops.Bah("修改失败,原因:下单过的快递单无法修改信息");
}
_logger.LogInformation($"快递订单修改操作开始,{logGuid}"); _logger.LogInformation($"快递订单修改操作开始,{logGuid}");
await _orderRep.AsUpdateable(entity).IgnoreColumns(it => new await _orderRep.AsUpdateable(entity).IgnoreColumns(it => new
{ {
@ -229,7 +256,7 @@ namespace Myshipping.Application
{ {
OrderId = Id, OrderId = Id,
MailNo = order.KDNO, MailNo = order.KDNO,
StatusCode = "DJY04", StatusCode = "DJY05",
StatusDesc = "快递单已删除" StatusDesc = "快递单已删除"
}; };
await _statusRep.InsertAsync(status); await _statusRep.InsertAsync(status);
@ -257,25 +284,6 @@ namespace Myshipping.Application
} }
} }
/// <summary>
/// 获取详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
[HttpPost("Get")]
public async Task<dynamic> Get(long Id)
{
ExpressDeliveryDto ordOut = new ExpressDeliveryDto();
var main = await _orderRep.FirstOrDefaultAsync(u => u.Id == Id);
if (main != null)
{
ordOut = main.Adapt<ExpressDeliveryDto>();
var business = await _businessRep.AsQueryable().Where(x => x.PId == Id).ToListAsync();
ordOut.Business = business;
}
return ordOut;
}
/// <summary> /// <summary>
/// 发送快递 /// 发送快递
/// </summary> /// </summary>
@ -285,50 +293,61 @@ namespace Myshipping.Application
public async Task<dynamic> SendBooking(long Id) public async Task<dynamic> SendBooking(long Id)
{ {
var rt = String.Empty; var rt = String.Empty;
SFSendBooking sFSend = new SFSendBooking();
var order = _orderRep.FirstOrDefault(x => x.Id == Id); var order = _orderRep.FirstOrDefault(x => x.Id == Id);
if (order == null) if (order == null)
{ {
throw Oops.Bah("请选择正确数据!"); throw Oops.Bah("请选择正确数据!");
} }
if (order.CurrentStateCode == "DJY01")
sFSend.orderId = Id.ToString();
sFSend.language = "zh_CN";
List<CargoDetailsItem> cargo = new List<CargoDetailsItem>();
cargo.Add(new CargoDetailsItem
{ {
count = (int)order.KDNum, throw Oops.Bah("下单失败,原因:尚未保存");
name = order.GOODSNAME }
if (order.CurrentStateCode != "DJY02")
});
List<ContactInfoListItem> contactList = new List<ContactInfoListItem>();
contactList.Add(new ContactInfoListItem
{ {
throw Oops.Bah("下单失败,原因:重复下单");
address = $"{order.FJProvince}{order.FJCity}{order.FJAddress}", }
contact = order.FJPeople, SFSendBooking sFSend = new SFSendBooking()
contactType = 1,
country = "CN",
//postCode = order.FJPostCode,
tel = order.FJTel,
});
contactList.Add(new ContactInfoListItem
{ {
orderId = Id.ToString(),
language = "zh_CN",
cargoDetails = new List<CargoDetailsItem>()
{
new CargoDetailsItem()
{
count = (int)order.KDNum,
name = order.GOODSNAME
}
}
};
if (order.SettleAccountsTypeCode == "2")
{
if (string.IsNullOrWhiteSpace(order.MonthlyCard))
{
throw Oops.Bah("当结费类型为月结时,月结卡号不能为空");
}
sFSend.monthlyCard = order.MonthlyCard;
}
address = $"{order.SJProvince}{order.SJCity}{order.SJAddress}", List<ContactInfoListItem> contactList = new()
contact = order.SJPeople, {
contactType = 2, new ContactInfoListItem
country = "CN", {
//postCode = order.SJPostCode, address = $"{order.FJProvince}{order.FJCity}{order.FJAddress}",
tel = order.SJTel, contact = order.FJPeople,
}); contactType = 1,
country = "CN",
tel = order.FJTel,
},
new ContactInfoListItem
{
address = $"{order.SJProvince}{order.SJCity}{order.SJAddress}",
contact = order.SJPeople,
contactType = 2,
country = "CN",
tel = order.SJTel,
}
};
sFSend.contactInfoList = contactList; sFSend.contactInfoList = contactList;
sFSend.cargoDetails = cargo;
(string url, Dictionary<string, object> dict) apiParam = await CreateSFApiParams("EXP_RECE_CREATE_ORDER", sFSend); (string url, Dictionary<string, object> dict) apiParam = await CreateSFApiParams("EXP_RECE_CREATE_ORDER", sFSend);
@ -356,7 +375,7 @@ namespace Myshipping.Application
{ {
OrderId = Id, OrderId = Id,
MailNo = waybillNo, MailNo = waybillNo,
StatusCode = "DJY02", StatusCode = "DJY03",
StatusDesc = statusDesc StatusDesc = statusDesc
}; };
await _statusRep.InsertAsync(status); await _statusRep.InsertAsync(status);
@ -434,7 +453,6 @@ namespace Myshipping.Application
return rt; return rt;
} }
/// <summary> /// <summary>
/// 取消快递下单 /// 取消快递下单
/// </summary> /// </summary>
@ -443,6 +461,16 @@ namespace Myshipping.Application
[HttpPost("CancelBooking")] [HttpPost("CancelBooking")]
public async Task<string> CancelBooking(long Id) public async Task<string> CancelBooking(long Id)
{ {
var order = _orderRep.FirstOrDefault(x => x.Id == Id) ?? throw Oops.Bah("请选择正确数据!");
if (order.CurrentStateCode is "DJY01" or "DJY02")
{
throw Oops.Bah("消单失败,原因:尚未下单,无需消单");
}
if (order.CurrentStateCode is "DJY04")
{
throw Oops.Bah("消单失败,原因:已消单,无需再次消单");
}
var param = new var param = new
{ {
dealType = 2, dealType = 2,
@ -469,7 +497,7 @@ namespace Myshipping.Application
{ {
OrderId = Id, OrderId = Id,
MailNo = order.KDNO, MailNo = order.KDNO,
StatusCode = "DJY03", StatusCode = "DJY04",
StatusDesc = STATUS_CANCEL StatusDesc = STATUS_CANCEL
}; };
await _statusRep.InsertAsync(status); await _statusRep.InsertAsync(status);
@ -548,6 +576,66 @@ namespace Myshipping.Application
return rt; return rt;
} }
/// <summary>
/// 根据提单号列表,向与之快递关联的订舱动态中,添加快递动态
/// </summary>
/// <param name="mblnoList">需要添加快递动态的提单号列表</param>
/// <param name="status">快递动态描述</param>
/// <param name="logGuid">日志标志</param>
[NonAction]
private async Task InsertNewBookingStatusWithMblnoList(List<string> mblnoList, string status, string logGuid = "")
{
if (mblnoList == null || mblnoList.Count == 0)
{
_logger.LogInformation($"快递订单关联订舱增加动态,{logGuid}mblNoList为空return");
return;
}
_logger.LogInformation($"快递订单关联订舱增加动态,{logGuid}mblNoList:{string.Join(',', mblnoList)}");
List<string> filteredList = mblnoList.Where(m => !string.IsNullOrWhiteSpace(m)).ToList(); // 如果提单号为空,则不进行处理
if (filteredList == null || filteredList.Count == 0)
{
return;
}
var bookingIdMapMblnoList = await _bookingOrderRep.AsQueryable(o => o.ParentId == 0 && filteredList.Contains(o.MBLNO))
.Select(o => new { o.Id, o.MBLNO })
.ToListAsync();
var bookingStatusLogList = new List<BookingStatusLog>();
foreach (string mblNo in filteredList)
{
var bookingOrderIdListTemp = bookingIdMapMblnoList.Where(o => o.MBLNO == mblNo);
if (bookingOrderIdListTemp == null)
{
_logger.LogInformation($"根据提单号{mblNo}查询订舱记录主键结果为空,{logGuid}");
continue;
}
else if (bookingOrderIdListTemp.Count() > 1)
{
_logger.LogInformation($"根据提单号{mblNo}查询订舱记录主键时查出多条记录ids{string.Join(',', bookingOrderIdListTemp.Select(b => b.Id).ToArray())}{logGuid}");
continue;
}
long? bookingOrderId = bookingOrderIdListTemp.First().Id;
_logger.LogInformation($"根据提单号{mblNo}查询订舱记录主键为{bookingOrderId}{logGuid}");
bookingStatusLogList.Add(new BookingStatusLog()
{
BookingId = bookingOrderId,
Status = status,
Category = "kuaidi",
OpTime = DateTime.Now,
MBLNO = mblNo
});
}
if (bookingStatusLogList.Count > 0)
{
await _bookingStatuslogRep.InsertAsync(bookingStatusLogList);
}
}
#region 顺丰专有方法
/// <summary> /// <summary>
/// 获取顺丰API接口调用参数 /// 获取顺丰API接口调用参数
/// </summary> /// </summary>
@ -619,65 +707,7 @@ namespace Myshipping.Application
return (url + "/std/service", dict); return (url + "/std/service", dict);
} }
/// <summary>
/// 根据提单号列表,向与之快递关联的订舱动态中,添加快递动态
/// </summary>
/// <param name="mblnoList">需要添加快递动态的提单号列表</param>
/// <param name="status">快递动态描述</param>
/// <param name="logGuid">日志标志</param>
[NonAction]
private async Task InsertNewBookingStatusWithMblnoList(List<string> mblnoList, string status, string logGuid = "")
{
if (mblnoList == null || mblnoList.Count == 0)
{
_logger.LogInformation($"快递订单关联订舱增加动态,{logGuid}mblNoList为空return");
return;
}
_logger.LogInformation($"快递订单关联订舱增加动态,{logGuid}mblNoList:{string.Join(',', mblnoList)}");
List<string> filteredList = mblnoList.Where(m => !string.IsNullOrWhiteSpace(m)).ToList(); // 如果提单号为空,则不进行处理
if (filteredList == null || filteredList.Count == 0)
{
return;
}
var bookingIdMapMblnoList = await _bookingOrderRep.AsQueryable(o => o.ParentId == 0 && filteredList.Contains(o.MBLNO))
.Select(o => new { o.Id, o.MBLNO })
.ToListAsync();
var bookingStatusLogList = new List<BookingStatusLog>();
foreach (string mblNo in filteredList)
{
var bookingOrderIdListTemp = bookingIdMapMblnoList.Where(o => o.MBLNO == mblNo);
if (bookingOrderIdListTemp == null)
{
_logger.LogInformation($"根据提单号{mblNo}查询订舱记录主键结果为空,{logGuid}");
continue;
}
else if (bookingOrderIdListTemp.Count() > 1)
{
_logger.LogInformation($"根据提单号{mblNo}查询订舱记录主键时查出多条记录ids{string.Join(',', bookingOrderIdListTemp.Select(b => b.Id).ToArray())}{logGuid}");
continue;
}
long? bookingOrderId = bookingOrderIdListTemp.First().Id;
_logger.LogInformation($"根据提单号{mblNo}查询订舱记录主键为{bookingOrderId}{logGuid}");
bookingStatusLogList.Add(new BookingStatusLog()
{
BookingId = bookingOrderId,
Status = status,
Category = "kuaidi",
OpTime = DateTime.Now,
MBLNO = mblNo
});
}
if (bookingStatusLogList.Count > 0)
{
await _bookingStatuslogRep.InsertAsync(bookingStatusLogList);
}
}
/// <summary> /// <summary>
/// 接收顺丰推送的快递动态 /// 接收顺丰推送的快递动态
/// </summary> /// </summary>
@ -810,7 +840,7 @@ namespace Myshipping.Application
return new { return_code = "0000", return_msg = "成功" }; return new { return_code = "0000", return_msg = "成功" };
} }
#endregion
#region 地址簿相关 #region 地址簿相关
/// <summary> /// <summary>

Loading…
Cancel
Save