|
|
|
@ -7,6 +7,7 @@ using DS.Module.SqlSugar;
|
|
|
|
|
using DS.Module.UserModule;
|
|
|
|
|
using DS.WMS.Core.Code.Entity;
|
|
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
|
|
using DS.WMS.Core.Info.Entity;
|
|
|
|
|
using DS.WMS.Core.Op.Dtos;
|
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
|
using DS.WMS.Core.Op.Interface;
|
|
|
|
@ -15,6 +16,7 @@ using DS.WMS.Core.Sys.Interface;
|
|
|
|
|
using LanguageExt;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using NLog;
|
|
|
|
|
using SqlSugar;
|
|
|
|
@ -235,32 +237,33 @@ public partial class SeaExportService : ISeaExportService
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult EditSeaExport(SeaExportReq req)
|
|
|
|
|
public async Task<DataResult> EditSeaExport(SeaExportReq req)
|
|
|
|
|
{
|
|
|
|
|
var dbScope = (SqlSugarScope)db;
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
if (req.Id == 0)
|
|
|
|
|
{
|
|
|
|
|
if (req.BLType != "拼箱分票" && tenantDb.Queryable<SeaExport>().Where(x => x.MBLNO == req.MBLNO.Trim()).Any())
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("海运出口信息主提单号已存在!", MultiLanguageConst.SeaExportMBLNOExist);
|
|
|
|
|
return await Task.FromResult(DataResult.Failed("海运出口信息主提单号已存在!", MultiLanguageConst.SeaExportMBLNOExist));
|
|
|
|
|
}
|
|
|
|
|
if (tenantDb.Queryable<SeaExport>().Where(x => x.HBLNO == req.HBLNO.Trim()).Any())
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("海运出口信息分提单号已存在!", MultiLanguageConst.SeaExportHBLNOExist);
|
|
|
|
|
return await Task.FromResult(DataResult.Failed("海运出口信息分提单号已存在!", MultiLanguageConst.SeaExportHBLNOExist));
|
|
|
|
|
}
|
|
|
|
|
//TODO 会计期间不允许小于已结转期间
|
|
|
|
|
if (req.CloseDocDate.IsNotNull() && req.CloseDocDate < req.ETD)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("截单日期不允许小于开船日期!", MultiLanguageConst.SeaExportCloseDocDateLimit);
|
|
|
|
|
return await Task.FromResult(DataResult.Failed("截单日期不允许小于开船日期!", MultiLanguageConst.SeaExportCloseDocDateLimit));
|
|
|
|
|
}
|
|
|
|
|
if (req.ClosingDate.IsNotNull() && req.ClosingDate < req.ETD)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("截港日期不允许小于开船日期!", MultiLanguageConst.SeaExportCloseDateLimit);
|
|
|
|
|
return await Task.FromResult(DataResult.Failed("截港日期不允许小于开船日期!", MultiLanguageConst.SeaExportCloseDateLimit));
|
|
|
|
|
}
|
|
|
|
|
var sequence = commonService.GetSequenceNext<SeaExport>();
|
|
|
|
|
if (!sequence.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist);
|
|
|
|
|
return await Task.FromResult(DataResult.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist));
|
|
|
|
|
}
|
|
|
|
|
var data = req.Adapt<SeaExport>();
|
|
|
|
|
data.CustomerNo = sequence.Data;
|
|
|
|
@ -278,14 +281,20 @@ public partial class SeaExportService : ISeaExportService
|
|
|
|
|
|
|
|
|
|
if (!stlInfo.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed(stlInfo.Message);
|
|
|
|
|
return await Task.FromResult(DataResult.Failed(stlInfo.Message));
|
|
|
|
|
}
|
|
|
|
|
data.StlName = stlInfo.Data.StlName;
|
|
|
|
|
data.StlDate = stlInfo.Data.StlDate;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//开启事务
|
|
|
|
|
await dbScope.Ado.BeginTranAsync();
|
|
|
|
|
var entity = await tenantDb.Insertable(data).ExecuteReturnEntityAsync();
|
|
|
|
|
|
|
|
|
|
var entity = tenantDb.Insertable(data).ExecuteReturnEntity();
|
|
|
|
|
//处理订单联系人信息
|
|
|
|
|
DealBusinessOrderContact(entity, tenantDb);
|
|
|
|
|
|
|
|
|
|
if (req.CtnInfo.Count > 0)
|
|
|
|
|
{
|
|
|
|
@ -293,40 +302,48 @@ public partial class SeaExportService : ISeaExportService
|
|
|
|
|
{
|
|
|
|
|
var ctn = item.Adapt<OpCtn>();
|
|
|
|
|
ctn.BSNO = entity.Id.ToString();
|
|
|
|
|
tenantDb.Insertable(ctn).ExecuteCommand();
|
|
|
|
|
await tenantDb.Insertable(ctn).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (req.EdiInfo.IsNotNull())
|
|
|
|
|
{
|
|
|
|
|
var edi = req.EdiInfo.Adapt<SeaExportEdi>();
|
|
|
|
|
edi.BusinessId = entity.Id;
|
|
|
|
|
tenantDb.Insertable(edi).ExecuteCommand();
|
|
|
|
|
await tenantDb.Insertable(edi).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#region 初始化费用状态表
|
|
|
|
|
var feeStatus = BusinessFeeStatus.Init(entity.Id);
|
|
|
|
|
tenantDb.Insertable(feeStatus).ExecuteCommand();
|
|
|
|
|
await tenantDb.Insertable(feeStatus).ExecuteCommandAsync();
|
|
|
|
|
#endregion
|
|
|
|
|
return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess);
|
|
|
|
|
//return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess);
|
|
|
|
|
await dbScope.Ado.CommitTranAsync();
|
|
|
|
|
return await Task.FromResult(DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
await dbScope.Ado.RollbackTranAsync();
|
|
|
|
|
return await Task.FromResult(DataResult.Failed("添加失败!" + ",请联系管理员!" + ex.ToString()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var info = tenantDb.Queryable<SeaExport>().Where(x => x.Id == req.Id).First();
|
|
|
|
|
var feeStatus = tenantDb.Queryable<BusinessFeeStatus>().Where(x => x.BusinessId == req.Id).First();
|
|
|
|
|
var info = await tenantDb.Queryable<SeaExport>().Where(x => x.Id == req.Id).FirstAsync();
|
|
|
|
|
var feeStatus = await tenantDb.Queryable<BusinessFeeStatus>().Where(x => x.BusinessId == req.Id).FirstAsync();
|
|
|
|
|
|
|
|
|
|
if (feeStatus.IsNotNull() && (bool)feeStatus.IsBusinessLocking)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("海运出口信息业务已锁定!", MultiLanguageConst.SeaExportBusinessLock);
|
|
|
|
|
return await Task.FromResult(DataResult.Failed("海运出口信息业务已锁定!", MultiLanguageConst.SeaExportBusinessLock));
|
|
|
|
|
}
|
|
|
|
|
info = req.Adapt(info);
|
|
|
|
|
//TODO 会计期间不允许小于已结转期间
|
|
|
|
|
if (info.CloseDocDate.IsNotNull() && info.CloseDocDate < info.ETD)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("截单日期不允许小于开船日期!", MultiLanguageConst.SeaExportCloseDocDateLimit);
|
|
|
|
|
return await Task.FromResult(DataResult.Failed("截单日期不允许小于开船日期!", MultiLanguageConst.SeaExportCloseDocDateLimit));
|
|
|
|
|
}
|
|
|
|
|
if (info.ClosingDate.IsNotNull() && info.ClosingDate < info.ETD)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("截港日期不允许小于开船日期!", MultiLanguageConst.SeaExportCloseDateLimit);
|
|
|
|
|
return await Task.FromResult(DataResult.Failed("截港日期不允许小于开船日期!", MultiLanguageConst.SeaExportCloseDateLimit));
|
|
|
|
|
}
|
|
|
|
|
#region 处理箱型箱量
|
|
|
|
|
if (req.CtnInfo.Count > 0)
|
|
|
|
@ -341,47 +358,52 @@ public partial class SeaExportService : ISeaExportService
|
|
|
|
|
|
|
|
|
|
if (!stlInfo.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed(stlInfo.Message);
|
|
|
|
|
return await Task.FromResult(DataResult.Failed(stlInfo.Message));
|
|
|
|
|
}
|
|
|
|
|
info.StlName = stlInfo.Data.StlName;
|
|
|
|
|
info.StlDate = stlInfo.Data.StlDate;
|
|
|
|
|
#endregion
|
|
|
|
|
tenantDb.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).EnableDiffLogEvent().ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//开启事务
|
|
|
|
|
await dbScope.Ado.BeginTranAsync();
|
|
|
|
|
await tenantDb.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).EnableDiffLogEvent().ExecuteCommandAsync();
|
|
|
|
|
//处理订单联系人信息
|
|
|
|
|
DealBusinessOrderContact(info, tenantDb);
|
|
|
|
|
|
|
|
|
|
if (req.CtnInfo.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var ctnList = tenantDb.Queryable<OpCtn>().Where(x => x.BSNO == req.Id.ToString()).ToList();
|
|
|
|
|
var ctnList = await tenantDb.Queryable<OpCtn>().Where(x => x.BSNO == req.Id.ToString()).ToListAsync();
|
|
|
|
|
foreach (var item in req.CtnInfo)
|
|
|
|
|
{
|
|
|
|
|
if (item.Id == 0)
|
|
|
|
|
{
|
|
|
|
|
var ctn = item.Adapt<OpCtn>();
|
|
|
|
|
ctn.BSNO = info.Id.ToString();
|
|
|
|
|
tenantDb.Insertable(ctn).ExecuteCommand();
|
|
|
|
|
await tenantDb.Insertable(ctn).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var ctn = ctnList.First(x => x.Id == item.Id);
|
|
|
|
|
ctn = item.Adapt(ctn);
|
|
|
|
|
tenantDb.Updateable(ctn).ExecuteCommand();
|
|
|
|
|
await tenantDb.Updateable(ctn).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (req.EdiInfo.IsNotNull())
|
|
|
|
|
{
|
|
|
|
|
var edi = tenantDb.Queryable<SeaExportEdi>().Where(x => x.BusinessId == req.Id).First();
|
|
|
|
|
var edi = await tenantDb.Queryable<SeaExportEdi>().Where(x => x.BusinessId == req.Id).FirstAsync();
|
|
|
|
|
if (edi.IsNull())
|
|
|
|
|
{
|
|
|
|
|
var ediInfo = req.EdiInfo.Adapt<SeaExportEdi>();
|
|
|
|
|
ediInfo.BusinessId = req.Id;
|
|
|
|
|
tenantDb.Insertable(ediInfo).ExecuteCommand();
|
|
|
|
|
await tenantDb.Insertable(ediInfo).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var ediInfo = req.EdiInfo.Adapt(edi);
|
|
|
|
|
tenantDb.Updateable(ediInfo).ExecuteCommand();
|
|
|
|
|
await tenantDb.Updateable(ediInfo).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -390,12 +412,93 @@ public partial class SeaExportService : ISeaExportService
|
|
|
|
|
if (feeStatus.IsNull())
|
|
|
|
|
{
|
|
|
|
|
feeStatus = BusinessFeeStatus.Init(req.Id);
|
|
|
|
|
tenantDb.Insertable(feeStatus).ExecuteCommand();
|
|
|
|
|
await tenantDb.Insertable(feeStatus).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
//return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
await dbScope.Ado.CommitTranAsync();
|
|
|
|
|
return await Task.FromResult(DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
await dbScope.Ado.RollbackTranAsync();
|
|
|
|
|
return await Task.FromResult(DataResult.Failed("更新失败!" + ",请联系管理员!" + ex.ToString()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 处理订单联系人信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="seaExport"></param>
|
|
|
|
|
/// <param name="sqlSugarScope"></param>
|
|
|
|
|
private void DealBusinessOrderContact(SeaExport seaExport,SqlSugarScopeProvider sqlSugarScope)
|
|
|
|
|
{
|
|
|
|
|
var contactLists = sqlSugarScope.Queryable<BusinessOrderContact>().Where(x => x.BusinessId == seaExport.Id).ToList();
|
|
|
|
|
|
|
|
|
|
var addList = new List<BusinessOrderContact>();
|
|
|
|
|
if (seaExport.CustomerId!=0)
|
|
|
|
|
{
|
|
|
|
|
var defaultContact = sqlSugarScope.Queryable<InfoClientContact>().Where(x => x.ClientId == seaExport.CustomerId && x.IsOperator == true).First();
|
|
|
|
|
if (defaultContact.IsNotNull())
|
|
|
|
|
{
|
|
|
|
|
if (!contactLists.Where(x=>x.BusinessType == BusinessType.OceanShippingExport &&x.CustomerType == "controller"&& x.Name == defaultContact.ShortName).Any())
|
|
|
|
|
{
|
|
|
|
|
addList.Add(new BusinessOrderContact()
|
|
|
|
|
{
|
|
|
|
|
BusinessId = seaExport.Id,
|
|
|
|
|
CustomerType = "controller",
|
|
|
|
|
CustomerTypeName="委托单位",
|
|
|
|
|
Name = defaultContact.ShortName,
|
|
|
|
|
Tel = defaultContact.Tel,
|
|
|
|
|
Email = defaultContact.Email,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (seaExport.TruckerId != 0)
|
|
|
|
|
{
|
|
|
|
|
var defaultContact = sqlSugarScope.Queryable<InfoClientContact>().Where(x => x.ClientId == seaExport.TruckerId && x.IsOperator == true).First();
|
|
|
|
|
if (defaultContact.IsNotNull())
|
|
|
|
|
{
|
|
|
|
|
if (!contactLists.Where(x => x.BusinessType == BusinessType.OceanShippingExport && x.CustomerType == "truck" && x.Name == defaultContact.ShortName).Any())
|
|
|
|
|
{
|
|
|
|
|
addList.Add(new BusinessOrderContact()
|
|
|
|
|
{
|
|
|
|
|
BusinessId = seaExport.Id,
|
|
|
|
|
CustomerType = "truck",
|
|
|
|
|
CustomerTypeName = "车队",
|
|
|
|
|
Name = defaultContact.ShortName,
|
|
|
|
|
Tel = defaultContact.Tel,
|
|
|
|
|
Email = defaultContact.Email,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (seaExport.YardId != 0)
|
|
|
|
|
{
|
|
|
|
|
var defaultContact = sqlSugarScope.Queryable<InfoClientContact>().Where(x => x.ClientId == seaExport.YardId && x.IsOperator == true).First();
|
|
|
|
|
if (defaultContact.IsNotNull())
|
|
|
|
|
{
|
|
|
|
|
if (!contactLists.Where(x => x.BusinessType == BusinessType.OceanShippingExport && x.CustomerType == "yard" && x.Name == defaultContact.ShortName).Any())
|
|
|
|
|
{
|
|
|
|
|
addList.Add(new BusinessOrderContact()
|
|
|
|
|
{
|
|
|
|
|
BusinessId = seaExport.Id,
|
|
|
|
|
CustomerType = "yard",
|
|
|
|
|
CustomerTypeName = "场站",
|
|
|
|
|
Name = defaultContact.ShortName,
|
|
|
|
|
Tel = defaultContact.Tel,
|
|
|
|
|
Email = defaultContact.Email,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (addList.Count > 0)
|
|
|
|
|
sqlSugarScope.Insertable(addList).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 详情
|
|
|
|
|