快递模块调整

optimize
zhangxiaofeng 12 months ago
parent 7f5893c8db
commit 99c28f001f

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

@ -95,6 +95,28 @@ namespace Myshipping.Application
}
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>
@ -110,8 +132,8 @@ namespace Myshipping.Application
if (input.Id == 0)
{
entity.CurrentStateCode = "DJY01";
entity.CurrentStateDesc = "新建";
entity.CurrentStateCode = "DJY02";
entity.CurrentStateDesc = "已保存";
_logger.LogInformation($"快递订单新增操作开始,{logGuid}");
@ -143,6 +165,11 @@ namespace Myshipping.Application
}
else
{
var oldOrder = _orderRep.FirstOrDefault(x => x.Id == input.Id);
if (oldOrder.CurrentStateCode != "DJY02")
{
throw Oops.Bah("修改失败,原因:下单过的快递单无法修改信息");
}
_logger.LogInformation($"快递订单修改操作开始,{logGuid}");
await _orderRep.AsUpdateable(entity).IgnoreColumns(it => new
{
@ -229,7 +256,7 @@ namespace Myshipping.Application
{
OrderId = Id,
MailNo = order.KDNO,
StatusCode = "DJY04",
StatusCode = "DJY05",
StatusDesc = "快递单已删除"
};
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>
@ -285,50 +293,61 @@ namespace Myshipping.Application
public async Task<dynamic> SendBooking(long Id)
{
var rt = String.Empty;
SFSendBooking sFSend = new SFSendBooking();
var order = _orderRep.FirstOrDefault(x => x.Id == Id);
if (order == null)
{
throw Oops.Bah("请选择正确数据!");
}
sFSend.orderId = Id.ToString();
sFSend.language = "zh_CN";
List<CargoDetailsItem> cargo = new List<CargoDetailsItem>();
cargo.Add(new CargoDetailsItem
if (order.CurrentStateCode == "DJY01")
{
throw Oops.Bah("下单失败,原因:尚未保存");
}
if (order.CurrentStateCode != "DJY02")
{
throw Oops.Bah("下单失败,原因:重复下单");
}
SFSendBooking sFSend = new SFSendBooking()
{
orderId = Id.ToString(),
language = "zh_CN",
cargoDetails = new List<CargoDetailsItem>()
{
new CargoDetailsItem()
{
count = (int)order.KDNum,
name = order.GOODSNAME
});
List<ContactInfoListItem> contactList = new List<ContactInfoListItem>();
contactList.Add(new ContactInfoListItem
}
}
};
if (order.SettleAccountsTypeCode == "2")
{
if (string.IsNullOrWhiteSpace(order.MonthlyCard))
{
throw Oops.Bah("当结费类型为月结时,月结卡号不能为空");
}
sFSend.monthlyCard = order.MonthlyCard;
}
List<ContactInfoListItem> contactList = new()
{
new ContactInfoListItem
{
address = $"{order.FJProvince}{order.FJCity}{order.FJAddress}",
contact = order.FJPeople,
contactType = 1,
country = "CN",
//postCode = order.FJPostCode,
tel = order.FJTel,
});
contactList.Add(new ContactInfoListItem
},
new ContactInfoListItem
{
address = $"{order.SJProvince}{order.SJCity}{order.SJAddress}",
contact = order.SJPeople,
contactType = 2,
country = "CN",
//postCode = order.SJPostCode,
tel = order.SJTel,
});
}
};
sFSend.contactInfoList = contactList;
sFSend.cargoDetails = cargo;
(string url, Dictionary<string, object> dict) apiParam = await CreateSFApiParams("EXP_RECE_CREATE_ORDER", sFSend);
@ -356,7 +375,7 @@ namespace Myshipping.Application
{
OrderId = Id,
MailNo = waybillNo,
StatusCode = "DJY02",
StatusCode = "DJY03",
StatusDesc = statusDesc
};
await _statusRep.InsertAsync(status);
@ -434,7 +453,6 @@ namespace Myshipping.Application
return rt;
}
/// <summary>
/// 取消快递下单
/// </summary>
@ -443,6 +461,16 @@ namespace Myshipping.Application
[HttpPost("CancelBooking")]
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
{
dealType = 2,
@ -469,7 +497,7 @@ namespace Myshipping.Application
{
OrderId = Id,
MailNo = order.KDNO,
StatusCode = "DJY03",
StatusCode = "DJY04",
StatusDesc = STATUS_CANCEL
};
await _statusRep.InsertAsync(status);
@ -548,6 +576,66 @@ namespace Myshipping.Application
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>
/// 获取顺丰API接口调用参数
/// </summary>
@ -620,64 +708,6 @@ namespace Myshipping.Application
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>
@ -810,7 +840,7 @@ namespace Myshipping.Application
return new { return_code = "0000", return_msg = "成功" };
}
#endregion
#region 地址簿相关
/// <summary>

Loading…
Cancel
Save