|
|
@ -44,15 +44,20 @@ namespace Myshipping.Application
|
|
|
|
private readonly ISysCacheService _cache;
|
|
|
|
private readonly ISysCacheService _cache;
|
|
|
|
private readonly SqlSugarRepository<BookingOrder> _rep;
|
|
|
|
private readonly SqlSugarRepository<BookingOrder> _rep;
|
|
|
|
private readonly SqlSugarRepository<BookingCtn> _repCtn;
|
|
|
|
private readonly SqlSugarRepository<BookingCtn> _repCtn;
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<BookingCtnDetail> _ctndetailrep;
|
|
|
|
private readonly SqlSugarRepository<SysUser> _repUser;
|
|
|
|
private readonly SqlSugarRepository<SysUser> _repUser;
|
|
|
|
private readonly SqlSugarRepository<SysTenant> _repTenant;
|
|
|
|
private readonly SqlSugarRepository<SysTenant> _repTenant;
|
|
|
|
private readonly SqlSugarRepository<DjyCustomer> _djycustomer;
|
|
|
|
private readonly SqlSugarRepository<DjyCustomer> _djycustomer;
|
|
|
|
private readonly SqlSugarRepository<DjyCustomerContact> _djycustomercontact;
|
|
|
|
private readonly SqlSugarRepository<DjyCustomerContact> _djycustomercontact;
|
|
|
|
private readonly SqlSugarRepository<DjyVesselInfo> _vesselinfo;
|
|
|
|
private readonly SqlSugarRepository<DjyVesselInfo> _vesselinfo;
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<BookingEDIExt> _bookingEDIExt;
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<BookingLog> _bookinglog;
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<BookingLogDetail> _bookinglogdetail;
|
|
|
|
|
|
|
|
|
|
|
|
public DataSyncService(ILogger<BookingOrderService> logger, ISysCacheService cache, SqlSugarRepository<BookingOrder> rep, SqlSugarRepository<BookingCtn> repCtn,
|
|
|
|
public DataSyncService(ILogger<BookingOrderService> logger, ISysCacheService cache, SqlSugarRepository<BookingOrder> rep, SqlSugarRepository<BookingCtn> repCtn,
|
|
|
|
SqlSugarRepository<SysUser> repUser, SqlSugarRepository<SysTenant> repTenant, SqlSugarRepository<DjyCustomer> djycustomer,
|
|
|
|
SqlSugarRepository<SysUser> repUser, SqlSugarRepository<SysTenant> repTenant, SqlSugarRepository<DjyCustomer> djycustomer,
|
|
|
|
SqlSugarRepository<DjyCustomerContact> djycustomercontact, SqlSugarRepository<DjyVesselInfo> vesselinfo)
|
|
|
|
SqlSugarRepository<DjyCustomerContact> djycustomercontact, SqlSugarRepository<DjyVesselInfo> vesselinfo, SqlSugarRepository<BookingCtnDetail> ctndetailrep
|
|
|
|
|
|
|
|
, SqlSugarRepository<BookingEDIExt> bookingEDIExt, SqlSugarRepository<BookingLog> bookinglog, SqlSugarRepository<BookingLogDetail> bookinglogdetail)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this._logger = logger;
|
|
|
|
this._logger = logger;
|
|
|
|
this._rep = rep;
|
|
|
|
this._rep = rep;
|
|
|
@ -63,6 +68,10 @@ namespace Myshipping.Application
|
|
|
|
this._djycustomer = djycustomer;
|
|
|
|
this._djycustomer = djycustomer;
|
|
|
|
this._djycustomercontact = djycustomercontact;
|
|
|
|
this._djycustomercontact = djycustomercontact;
|
|
|
|
this._vesselinfo = vesselinfo;
|
|
|
|
this._vesselinfo = vesselinfo;
|
|
|
|
|
|
|
|
this._ctndetailrep = ctndetailrep;
|
|
|
|
|
|
|
|
this._bookingEDIExt = bookingEDIExt;
|
|
|
|
|
|
|
|
this._bookinglog = bookinglog;
|
|
|
|
|
|
|
|
this._bookinglogdetail = bookinglogdetail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -72,11 +81,12 @@ namespace Myshipping.Application
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="model"></param>
|
|
|
|
/// <param name="model"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("/DataSync/SyncCustomer"),ApiUser(ApiCode= "SyncCustomer")]
|
|
|
|
[HttpPost("/DataSync/SyncCustomer"), ApiUser(ApiCode = "SyncCustomer")]
|
|
|
|
public async Task<long> SyncCustomer(DjyCustomerSyncDto model)
|
|
|
|
public async Task<long> SyncCustomer(DjyCustomerSyncDto model)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.BSNO)) {
|
|
|
|
if (string.IsNullOrWhiteSpace(model.BSNO))
|
|
|
|
|
|
|
|
{
|
|
|
|
throw Oops.Bah("BSNO未录入");
|
|
|
|
throw Oops.Bah("BSNO未录入");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var m = await _djycustomer.Where(x => x.BSNO == model.BSNO).FirstAsync();
|
|
|
|
var m = await _djycustomer.Where(x => x.BSNO == model.BSNO).FirstAsync();
|
|
|
@ -89,10 +99,11 @@ namespace Myshipping.Application
|
|
|
|
var contact = item.Adapt<DjyCustomerContact>();
|
|
|
|
var contact = item.Adapt<DjyCustomerContact>();
|
|
|
|
contact.CustomerId = entity.Id;
|
|
|
|
contact.CustomerId = entity.Id;
|
|
|
|
await _djycustomercontact.InsertAsync(contact);
|
|
|
|
await _djycustomercontact.InsertAsync(contact);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else
|
|
|
|
entity.Id=m.Id;
|
|
|
|
{
|
|
|
|
|
|
|
|
entity.Id = m.Id;
|
|
|
|
await _djycustomer.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
|
await _djycustomer.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
|
await _djycustomercontact.DeleteAsync(x => x.CustomerId == entity.Id);
|
|
|
|
await _djycustomercontact.DeleteAsync(x => x.CustomerId == entity.Id);
|
|
|
|
foreach (var item in model.ContactList)
|
|
|
|
foreach (var item in model.ContactList)
|
|
|
@ -119,7 +130,7 @@ namespace Myshipping.Application
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw Oops.Bah("BSNO未录入");
|
|
|
|
throw Oops.Bah("BSNO未录入");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var m = await _vesselinfo.Where(x => x.BSNO==model.BSNO).FirstAsync();
|
|
|
|
var m = await _vesselinfo.Where(x => x.BSNO == model.BSNO).FirstAsync();
|
|
|
|
var entity = model.Adapt<DjyVesselInfo>();
|
|
|
|
var entity = model.Adapt<DjyVesselInfo>();
|
|
|
|
entity.Vessel = model.Vessel.ToUpper().Trim();
|
|
|
|
entity.Vessel = model.Vessel.ToUpper().Trim();
|
|
|
|
if (m == null)
|
|
|
|
if (m == null)
|
|
|
@ -139,27 +150,476 @@ namespace Myshipping.Application
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="model"></param>
|
|
|
|
/// <param name="model"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
[SqlSugarUnitOfWork]
|
|
|
|
[HttpPost("/DataSync/SyncBooking"), ApiUser(ApiCode = "SyncBooking")]
|
|
|
|
[HttpPost("/DataSync/SyncBooking"), ApiUser(ApiCode = "SyncBooking")]
|
|
|
|
public async Task<long> SyncBooking(SyncBookingOrderDto model)
|
|
|
|
public async Task<long> SyncBooking(SyncBookingOrderDto model)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(model.BSNO)) {
|
|
|
|
if (string.IsNullOrWhiteSpace(model.BSNO))
|
|
|
|
|
|
|
|
{
|
|
|
|
throw Oops.Bah("主单BSNO未录入");
|
|
|
|
throw Oops.Bah("主单BSNO未录入");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(model.CreatedUserName)) {
|
|
|
|
if (string.IsNullOrWhiteSpace(model.CreatedUserName))
|
|
|
|
|
|
|
|
{
|
|
|
|
throw Oops.Bah("未录入创建人");
|
|
|
|
throw Oops.Bah("未录入创建人");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var user= _repUser.AsQueryable().Where(x => x.CreatedUserName == model.CreatedUserName).FirstAsync();
|
|
|
|
var user = _repUser.AsQueryable().Where(x => x.CreatedUserName.Trim() == model.CreatedUserName.Trim()).FirstAsync();
|
|
|
|
|
|
|
|
if (user == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Bah("未匹配到创建人");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var order = await _rep.AsQueryable().Where(x => x.BSNO == model.BSNO).FirstAsync();
|
|
|
|
|
|
|
|
if (order == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 新增
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.MBLNO))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Bah("请填写提单号!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JsonUtil.PropToUpper(model, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
|
|
|
|
|
|
|
|
JsonUtil.TrimFields(model);
|
|
|
|
|
|
|
|
if (model.ctnInputs != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var groupList = model.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
|
|
|
|
|
|
|
|
model.CNTRTOTAL = string.Join(" / ", groupList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var et = await _rep.Where(x => x.MBLNO == model.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == model.HBLNO && x.ParentId == 0).FirstAsync();
|
|
|
|
|
|
|
|
if (et != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
throw Oops.Bah("当前提单号已存在,请勿重复录入!");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var entity = model.Adapt<BookingOrder>();
|
|
|
|
|
|
|
|
entity.CreatedUserId = user.Result.Id;
|
|
|
|
|
|
|
|
entity.CreatedUserName = user.Result.Name;
|
|
|
|
|
|
|
|
entity.CreatedTime = DateTime.Now;
|
|
|
|
|
|
|
|
await _rep.InsertAsync(entity);
|
|
|
|
|
|
|
|
if (model.ctnInputs != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var item in model.ctnInputs)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var ctnentity = item.Adapt<BookingCtn>();
|
|
|
|
|
|
|
|
ctnentity.BILLID = entity.Id;
|
|
|
|
|
|
|
|
await _repCtn.InsertAsync(ctnentity);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//这里保存有可能没有添加多品名,所有箱下没有货物信息
|
|
|
|
|
|
|
|
if (item.ctnDetailInputs != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var it in item.ctnDetailInputs)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var ctndetail = it.Adapt<BookingCtnDetail>();
|
|
|
|
|
|
|
|
ctndetail.CTNID = ctnentity.Id;
|
|
|
|
|
|
|
|
await _ctndetailrep.InsertAsync(ctndetail);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (model.BookingEDIExt != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//写入EDI扩展
|
|
|
|
|
|
|
|
var ediExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ediExtEntity.BookingId = entity.Id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ediExtEntity.CreatedUserId = user.Result.Id;
|
|
|
|
|
|
|
|
ediExtEntity.CreatedUserName = user.Result.Name;
|
|
|
|
|
|
|
|
ediExtEntity.CreatedTime = DateTime.Now;
|
|
|
|
|
|
|
|
await _bookingEDIExt.InsertAsync(ediExtEntity);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
////添加booking日志
|
|
|
|
|
|
|
|
await _bookinglog.InsertAsync(new BookingLog
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Type = "Add",
|
|
|
|
|
|
|
|
BookingId = entity.Id,
|
|
|
|
|
|
|
|
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
|
|
|
|
|
|
|
|
CreatedTime = DateTime.Now,
|
|
|
|
|
|
|
|
CreatedUserId = user.Result.Id,
|
|
|
|
|
|
|
|
CreatedUserName = "系统"
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//分单
|
|
|
|
|
|
|
|
if (model.childrens != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var item in model.childrens)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(item.MBLNO))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Bah("请填写提单号!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(item.HBLNO))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Bah("请填写分提单号!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonUtil.PropToUpper(item, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
|
|
|
|
|
|
|
|
JsonUtil.TrimFields(item);
|
|
|
|
|
|
|
|
if (model.ctnInputs != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var groupList = item.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
|
|
|
|
|
|
|
|
item.CNTRTOTAL = string.Join(" / ", groupList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var fdet = await _rep.Where(x => x.MBLNO == model.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == model.HBLNO && x.ParentId == entity.Id).FirstAsync();
|
|
|
|
|
|
|
|
if (fdet != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
throw Oops.Bah($"当前分单中提单号({item.MBLNO}_{item.HBLNO})已存在,请勿重复录入!");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var fdentity = item.Adapt<BookingOrder>();
|
|
|
|
|
|
|
|
fdentity.CreatedUserId = user.Result.Id;
|
|
|
|
|
|
|
|
fdentity.CreatedUserName = user.Result.Name;
|
|
|
|
|
|
|
|
fdentity.CreatedTime = DateTime.Now;
|
|
|
|
|
|
|
|
fdentity.ParentId = entity.Id;
|
|
|
|
|
|
|
|
await _rep.InsertAsync(fdentity);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (item.ctnInputs != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var it in item.ctnInputs)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var ctnentity = item.Adapt<BookingCtn>();
|
|
|
|
|
|
|
|
ctnentity.BILLID = fdentity.Id;
|
|
|
|
|
|
|
|
await _repCtn.InsertAsync(ctnentity);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//这里保存有可能没有添加多品名,所有箱下没有货物信息
|
|
|
|
|
|
|
|
if (it.ctnDetailInputs != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var dit in it.ctnDetailInputs)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var ctndetail = dit.Adapt<BookingCtnDetail>();
|
|
|
|
|
|
|
|
ctndetail.CTNID = ctnentity.Id;
|
|
|
|
|
|
|
|
await _ctndetailrep.InsertAsync(ctndetail);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (item.BookingEDIExt != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//写入EDI扩展
|
|
|
|
|
|
|
|
var ediExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ediExtEntity.BookingId = fdentity.Id;
|
|
|
|
|
|
|
|
ediExtEntity.CreatedUserId = user.Result.Id;
|
|
|
|
|
|
|
|
ediExtEntity.CreatedUserName = user.Result.Name;
|
|
|
|
|
|
|
|
ediExtEntity.CreatedTime = DateTime.Now;
|
|
|
|
|
|
|
|
await _bookingEDIExt.InsertAsync(ediExtEntity);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
////添加booking日志
|
|
|
|
|
|
|
|
await _bookinglog.InsertAsync(new BookingLog
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Type = "Add",
|
|
|
|
|
|
|
|
BookingId = fdentity.Id,
|
|
|
|
|
|
|
|
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
|
|
|
|
|
|
|
|
CreatedTime = DateTime.Now,
|
|
|
|
|
|
|
|
CreatedUserId = user.Result.Id,
|
|
|
|
|
|
|
|
CreatedUserName = "系统"
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return entity.Id;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 编辑
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.MBLNO))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Bah("请填写提单号!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JsonUtil.PropToUpper(model, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
|
|
|
|
|
|
|
|
JsonUtil.TrimFields(model);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (model.ctnInputs != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var groupList = model.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
|
|
|
|
|
|
|
|
model.CNTRTOTAL = string.Join(" / ", groupList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var main = await _rep.AsQueryable().Filter(null, true).Where(x => x.BSNO == model.BSNO).FirstAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var et = await _rep.Where(x => x.MBLNO == model.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == model.HBLNO && x.BSNO != model.BSNO).FirstAsync();
|
|
|
|
|
|
|
|
if (et != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Bah("当前提单号已存在,请勿重复录入!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var entity = model.Adapt<BookingOrder>();
|
|
|
|
|
|
|
|
entity.Id = main.Id;
|
|
|
|
|
|
|
|
entity.UpdatedUserName = user.Result.Name;
|
|
|
|
|
|
|
|
entity.UpdatedUserId = user.Result.Id;
|
|
|
|
|
|
|
|
entity.UpdatedTime = DateTime.Now;
|
|
|
|
|
|
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(it => new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
it.ParentId,
|
|
|
|
|
|
|
|
it.TenantId,
|
|
|
|
|
|
|
|
it.CreatedTime,
|
|
|
|
|
|
|
|
it.CreatedUserId,
|
|
|
|
|
|
|
|
it.CreatedUserName
|
|
|
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == main.Id).Select(x => x.Id).ToListAsync();
|
|
|
|
|
|
|
|
await _repCtn.DeleteAsync(x => x.BILLID == main.Id);
|
|
|
|
|
|
|
|
await _ctndetailrep.DeleteAsync(x => ctnlist.Contains((long)x.CTNID));
|
|
|
|
|
|
|
|
if (model.ctnInputs != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var item in model.ctnInputs)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var ctnentity = item.Adapt<BookingCtn>();
|
|
|
|
|
|
|
|
ctnentity.BILLID = main.Id;
|
|
|
|
|
|
|
|
await _repCtn.InsertAsync(ctnentity);
|
|
|
|
|
|
|
|
if (item.ctnDetailInputs != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var it in item.ctnDetailInputs)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var ctndetail = it.Adapt<BookingCtnDetail>();
|
|
|
|
|
|
|
|
ctndetail.CTNID = ctnentity.Id;
|
|
|
|
|
|
|
|
await _ctndetailrep.InsertAsync(ctndetail);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (model.BookingEDIExt != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//检索EDI扩展
|
|
|
|
|
|
|
|
var ediExtEntity = _bookingEDIExt.FirstOrDefault(u => u.BookingId == main.Id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ediExtEntity == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//写入EDI扩展
|
|
|
|
|
|
|
|
ediExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
|
|
|
|
|
ediExtEntity.BookingId = main.Id;
|
|
|
|
|
|
|
|
ediExtEntity.CreatedUserId = user.Result.Id;
|
|
|
|
|
|
|
|
ediExtEntity.CreatedUserName = user.Result.Name;
|
|
|
|
|
|
|
|
ediExtEntity.CreatedTime = DateTime.Now;
|
|
|
|
|
|
|
|
await _bookingEDIExt.InsertAsync(ediExtEntity);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//更新EDI扩展
|
|
|
|
|
|
|
|
var currEdiExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
currEdiExtEntity.Id = ediExtEntity.Id;
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
await _bookingEDIExt.AsUpdateable(currEdiExtEntity).IgnoreColumns(it => new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
it.BookingId,
|
|
|
|
|
|
|
|
it.TenantId,
|
|
|
|
|
|
|
|
it.CreatedTime,
|
|
|
|
|
|
|
|
it.CreatedUserId,
|
|
|
|
|
|
|
|
it.CreatedUserName
|
|
|
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool flag = true;
|
|
|
|
|
|
|
|
long bid = 0;
|
|
|
|
|
|
|
|
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(entity))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string name = descriptor.Name;
|
|
|
|
|
|
|
|
if (name == "TenantId" || name == "CreatedTime" || name == "UpdatedTime" || name == "CreatedUserId" || name == "CreatedUserName")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
object value = descriptor.GetValue(entity);
|
|
|
|
|
|
|
|
var oldvalue = main.GetType().GetProperty(name).GetValue(main, null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (name == "KGS" || name == "CBM")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (Convert.ToDecimal(value) == Convert.ToDecimal(oldvalue))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
string _oldvalue = oldvalue != null ? oldvalue.ToString() : "";
|
|
|
|
|
|
|
|
string _value = value != null ? value.ToString() : "";
|
|
|
|
|
|
|
|
if (_oldvalue != _value && !string.IsNullOrWhiteSpace(descriptor.Description))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (flag)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
////添加booking日志
|
|
|
|
|
|
|
|
bid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Type = "Edit",
|
|
|
|
|
|
|
|
BookingId = entity.Id,
|
|
|
|
|
|
|
|
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
|
|
|
|
|
|
|
|
CreatedTime = DateTime.Now,
|
|
|
|
|
|
|
|
CreatedUserId = user.Result.Id,
|
|
|
|
|
|
|
|
CreatedUserName = user.Result.Name
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
flag = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
PId = bid,
|
|
|
|
|
|
|
|
Field = descriptor.Description,
|
|
|
|
|
|
|
|
OldValue = _oldvalue,
|
|
|
|
|
|
|
|
NewValue = _value,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//分单
|
|
|
|
|
|
|
|
if (model.childrens != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var item in model.childrens)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(item.MBLNO))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Bah("请填写提单号!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonUtil.PropToUpper(item, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
|
|
|
|
|
|
|
|
JsonUtil.TrimFields(item);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (item.ctnInputs != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var groupList = item.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
|
|
|
|
|
|
|
|
item.CNTRTOTAL = string.Join(" / ", groupList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fdmain = await _rep.AsQueryable().Filter(null, true).Where(x => x.BSNO == item.BSNO).FirstAsync();
|
|
|
|
|
|
|
|
var fdet = await _rep.Where(x => x.MBLNO == item.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == item.HBLNO && x.BSNO != fdmain.BSNO).FirstAsync();
|
|
|
|
|
|
|
|
if (fdet != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Bah($"当前提单号{fdet.MBLNO}_{fdet.HBLNO}已存在,请勿重复录入!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var fdentity = model.Adapt<BookingOrder>();
|
|
|
|
|
|
|
|
fdentity.Id = fdmain.Id;
|
|
|
|
|
|
|
|
fdentity.UpdatedUserName = user.Result.Name;
|
|
|
|
|
|
|
|
fdentity.UpdatedUserId = user.Result.Id;
|
|
|
|
|
|
|
|
fdentity.UpdatedTime = DateTime.Now;
|
|
|
|
|
|
|
|
await _rep.AsUpdateable(fdentity).IgnoreColumns(it => new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
it.ParentId,
|
|
|
|
|
|
|
|
it.TenantId,
|
|
|
|
|
|
|
|
it.CreatedTime,
|
|
|
|
|
|
|
|
it.CreatedUserId,
|
|
|
|
|
|
|
|
it.CreatedUserName
|
|
|
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
var fdctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == fdmain.Id).Select(x => x.Id).ToListAsync();
|
|
|
|
|
|
|
|
await _repCtn.DeleteAsync(x => x.BILLID == fdmain.Id);
|
|
|
|
|
|
|
|
await _ctndetailrep.DeleteAsync(x => fdctnlist.Contains((long)x.CTNID));
|
|
|
|
|
|
|
|
if (item.ctnInputs != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var it in model.ctnInputs)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var ctnentity = item.Adapt<BookingCtn>();
|
|
|
|
|
|
|
|
ctnentity.BILLID = fdmain.Id;
|
|
|
|
|
|
|
|
await _repCtn.InsertAsync(ctnentity);
|
|
|
|
|
|
|
|
if (it.ctnDetailInputs != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var it_ in it.ctnDetailInputs)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var ctndetail = it_.Adapt<BookingCtnDetail>();
|
|
|
|
|
|
|
|
ctndetail.CTNID = ctnentity.Id;
|
|
|
|
|
|
|
|
await _ctndetailrep.InsertAsync(ctndetail);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (item.BookingEDIExt != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//检索EDI扩展
|
|
|
|
|
|
|
|
var ediExtEntity = _bookingEDIExt.FirstOrDefault(u => u.BookingId == fdmain.Id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ediExtEntity == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//写入EDI扩展
|
|
|
|
|
|
|
|
ediExtEntity = item.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
|
|
|
|
|
ediExtEntity.BookingId = fdmain.Id;
|
|
|
|
|
|
|
|
ediExtEntity.CreatedUserId = user.Result.Id;
|
|
|
|
|
|
|
|
ediExtEntity.CreatedUserName = user.Result.Name;
|
|
|
|
|
|
|
|
ediExtEntity.CreatedTime = DateTime.Now;
|
|
|
|
|
|
|
|
await _bookingEDIExt.InsertAsync(ediExtEntity);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//更新EDI扩展
|
|
|
|
|
|
|
|
var currEdiExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
currEdiExtEntity.Id = ediExtEntity.Id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await _bookingEDIExt.AsUpdateable(currEdiExtEntity).IgnoreColumns(it => new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
it.BookingId,
|
|
|
|
|
|
|
|
it.TenantId,
|
|
|
|
|
|
|
|
it.CreatedTime,
|
|
|
|
|
|
|
|
it.CreatedUserId,
|
|
|
|
|
|
|
|
it.CreatedUserName
|
|
|
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool fdflag = true;
|
|
|
|
|
|
|
|
long fdbid = 0;
|
|
|
|
|
|
|
|
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(fdentity))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string name = descriptor.Name;
|
|
|
|
|
|
|
|
if (name == "TenantId" || name == "CreatedTime" || name == "UpdatedTime" || name == "CreatedUserId" || name == "CreatedUserName")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
object value = descriptor.GetValue(fdentity);
|
|
|
|
|
|
|
|
var oldvalue = fdmain.GetType().GetProperty(name).GetValue(main, null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (name == "KGS" || name == "CBM")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (Convert.ToDecimal(value) == Convert.ToDecimal(oldvalue))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
string _oldvalue = oldvalue != null ? oldvalue.ToString() : "";
|
|
|
|
|
|
|
|
string _value = value != null ? value.ToString() : "";
|
|
|
|
|
|
|
|
if (_oldvalue != _value && !string.IsNullOrWhiteSpace(descriptor.Description))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (fdflag)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
////添加booking日志
|
|
|
|
|
|
|
|
fdbid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Type = "Edit",
|
|
|
|
|
|
|
|
BookingId = fdentity.Id,
|
|
|
|
|
|
|
|
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
|
|
|
|
|
|
|
|
CreatedTime = DateTime.Now,
|
|
|
|
|
|
|
|
CreatedUserId = user.Result.Id,
|
|
|
|
|
|
|
|
CreatedUserName = user.Result.Name,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
fdflag = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
PId = fdbid,
|
|
|
|
|
|
|
|
Field = descriptor.Description,
|
|
|
|
|
|
|
|
OldValue = _oldvalue,
|
|
|
|
|
|
|
|
NewValue = _value,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return main.Id;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|