|
|
|
@ -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,55 +281,69 @@ 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)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in req.CtnInfo)
|
|
|
|
|
if (req.CtnInfo.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var ctn = item.Adapt<OpCtn>();
|
|
|
|
|
ctn.BSNO = entity.Id.ToString();
|
|
|
|
|
tenantDb.Insertable(ctn).ExecuteCommand();
|
|
|
|
|
foreach (var item in req.CtnInfo)
|
|
|
|
|
{
|
|
|
|
|
var ctn = item.Adapt<OpCtn>();
|
|
|
|
|
ctn.BSNO = entity.Id.ToString();
|
|
|
|
|
await tenantDb.Insertable(ctn).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (req.EdiInfo.IsNotNull())
|
|
|
|
|
{
|
|
|
|
|
var edi = req.EdiInfo.Adapt<SeaExportEdi>();
|
|
|
|
|
edi.BusinessId = entity.Id;
|
|
|
|
|
await tenantDb.Insertable(edi).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#region 初始化费用状态表
|
|
|
|
|
var feeStatus = BusinessFeeStatus.Init(entity.Id);
|
|
|
|
|
await tenantDb.Insertable(feeStatus).ExecuteCommandAsync();
|
|
|
|
|
#endregion
|
|
|
|
|
//return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess);
|
|
|
|
|
await dbScope.Ado.CommitTranAsync();
|
|
|
|
|
return await Task.FromResult(DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess));
|
|
|
|
|
}
|
|
|
|
|
if (req.EdiInfo.IsNotNull())
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
var edi = req.EdiInfo.Adapt<SeaExportEdi>();
|
|
|
|
|
edi.BusinessId = entity.Id;
|
|
|
|
|
tenantDb.Insertable(edi).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
await dbScope.Ado.RollbackTranAsync();
|
|
|
|
|
return await Task.FromResult(DataResult.Failed("添加失败!" + ",请联系管理员!" + ex.ToString()));
|
|
|
|
|
}
|
|
|
|
|
#region 初始化费用状态表
|
|
|
|
|
var feeStatus = BusinessFeeStatus.Init(entity.Id);
|
|
|
|
|
tenantDb.Insertable(feeStatus).ExecuteCommand();
|
|
|
|
|
#endregion
|
|
|
|
|
return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess);
|
|
|
|
|
}
|
|
|
|
|
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,62 +358,148 @@ 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 = 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();
|
|
|
|
|
await tenantDb.Insertable(ctn).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var ctn = ctnList.First(x => x.Id == item.Id);
|
|
|
|
|
ctn = item.Adapt(ctn);
|
|
|
|
|
await tenantDb.Updateable(ctn).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (req.CtnInfo.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var ctnList = tenantDb.Queryable<OpCtn>().Where(x => x.BSNO == req.Id.ToString()).ToList();
|
|
|
|
|
foreach (var item in req.CtnInfo)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (req.EdiInfo.IsNotNull())
|
|
|
|
|
{
|
|
|
|
|
if (item.Id == 0)
|
|
|
|
|
var edi = await tenantDb.Queryable<SeaExportEdi>().Where(x => x.BusinessId == req.Id).FirstAsync();
|
|
|
|
|
if (edi.IsNull())
|
|
|
|
|
{
|
|
|
|
|
var ctn = item.Adapt<OpCtn>();
|
|
|
|
|
ctn.BSNO = info.Id.ToString();
|
|
|
|
|
tenantDb.Insertable(ctn).ExecuteCommand();
|
|
|
|
|
var ediInfo = req.EdiInfo.Adapt<SeaExportEdi>();
|
|
|
|
|
ediInfo.BusinessId = req.Id;
|
|
|
|
|
await tenantDb.Insertable(ediInfo).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var ctn = ctnList.First(x => x.Id == item.Id);
|
|
|
|
|
ctn = item.Adapt(ctn);
|
|
|
|
|
tenantDb.Updateable(ctn).ExecuteCommand();
|
|
|
|
|
var ediInfo = req.EdiInfo.Adapt(edi);
|
|
|
|
|
await tenantDb.Updateable(ediInfo).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#region 处理未初始化费用状态表
|
|
|
|
|
if (feeStatus.IsNull())
|
|
|
|
|
{
|
|
|
|
|
feeStatus = BusinessFeeStatus.Init(req.Id);
|
|
|
|
|
await tenantDb.Insertable(feeStatus).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
//return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
await dbScope.Ado.CommitTranAsync();
|
|
|
|
|
return await Task.FromResult(DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess));
|
|
|
|
|
}
|
|
|
|
|
if (req.EdiInfo.IsNotNull())
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
var edi = tenantDb.Queryable<SeaExportEdi>().Where(x => x.BusinessId == req.Id).First();
|
|
|
|
|
if (edi.IsNull())
|
|
|
|
|
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())
|
|
|
|
|
{
|
|
|
|
|
var ediInfo = req.EdiInfo.Adapt<SeaExportEdi>();
|
|
|
|
|
ediInfo.BusinessId = req.Id;
|
|
|
|
|
tenantDb.Insertable(ediInfo).ExecuteCommand();
|
|
|
|
|
addList.Add(new BusinessOrderContact()
|
|
|
|
|
{
|
|
|
|
|
BusinessId = seaExport.Id,
|
|
|
|
|
CustomerType = "controller",
|
|
|
|
|
CustomerTypeName="委托单位",
|
|
|
|
|
Name = defaultContact.ShortName,
|
|
|
|
|
Tel = defaultContact.Tel,
|
|
|
|
|
Email = defaultContact.Email,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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())
|
|
|
|
|
{
|
|
|
|
|
var ediInfo = req.EdiInfo.Adapt(edi);
|
|
|
|
|
tenantDb.Updateable(ediInfo).ExecuteCommand();
|
|
|
|
|
addList.Add(new BusinessOrderContact()
|
|
|
|
|
{
|
|
|
|
|
BusinessId = seaExport.Id,
|
|
|
|
|
CustomerType = "truck",
|
|
|
|
|
CustomerTypeName = "车队",
|
|
|
|
|
Name = defaultContact.ShortName,
|
|
|
|
|
Tel = defaultContact.Tel,
|
|
|
|
|
Email = defaultContact.Email,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#region 处理未初始化费用状态表
|
|
|
|
|
if (feeStatus.IsNull())
|
|
|
|
|
}
|
|
|
|
|
if (seaExport.YardId != 0)
|
|
|
|
|
{
|
|
|
|
|
var defaultContact = sqlSugarScope.Queryable<InfoClientContact>().Where(x => x.ClientId == seaExport.YardId && x.IsOperator == true).First();
|
|
|
|
|
if (defaultContact.IsNotNull())
|
|
|
|
|
{
|
|
|
|
|
feeStatus = BusinessFeeStatus.Init(req.Id);
|
|
|
|
|
tenantDb.Insertable(feeStatus).ExecuteCommand();
|
|
|
|
|
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,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (addList.Count > 0)
|
|
|
|
|
sqlSugarScope.Insertable(addList).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 详情
|
|
|
|
|
/// </summary>
|
|
|
|
|