using AngleSharp.Dom; using DS.Module.Core; using DS.Module.Core.Data; using DS.Module.Core.Extensions; using DS.Module.DjyRulesEngine; using DS.Module.DjyServiceStatus; 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; using DS.WMS.Core.Sys.Entity; 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; using Logger = NLog.Logger; namespace DS.WMS.Core.Op.Method; public partial class SeaExportService : ISeaExportService { private readonly IServiceProvider _serviceProvider; private readonly ISqlSugarClient db; private readonly IUser user; private readonly ISaasDbService saasService; private readonly ICommonService commonService; private static readonly Logger _logger = LogManager.GetCurrentClassLogger(); private readonly ISeaExportCommonService seaComService; private readonly IWebHostEnvironment _environment; private readonly IDjyServiceStatusService _djyServiceStatusService; private readonly IRuleEngineService _ruleEngineService; const string CONST_MAPPING_MODULE = "BOOK_OR_CLOSING"; const string CONST_MAPPING_MODULE_ROUTE = "BOOK_OR_CLOSING_RT"; const string CONST_MAPPING_MODULE_VOLTA = "BOOK_CLOSING_VOLTA"; const string CONST_MAPPING_MODULE_INTTRA = "INTTRA_EDI"; private const string PrintRecentListTypeKey = "booking_print_recent_list"; const string CONST_TSL_EDI_URL = "tsl_edi_declare_url"; const string CONST_TSL_TYPE_CODE = "TslWeb"; const string CONST_ONE_SOFILE_CATE_CODE = "one_so_file_template"; const string PRINT_DATASOURCE_KEY = "booking_order"; /// /// /// /// public SeaExportService(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; db = _serviceProvider.GetRequiredService(); user = _serviceProvider.GetRequiredService(); saasService = _serviceProvider.GetRequiredService(); commonService = _serviceProvider.GetRequiredService(); seaComService = _serviceProvider.GetRequiredService(); _environment = _serviceProvider.GetRequiredService(); //_printService = _serviceProvider.GetRequiredService(); _djyServiceStatusService = _serviceProvider.GetRequiredService(); _ruleEngineService = _serviceProvider.GetRequiredService(); #region 设置对象映射 TypeAdapterConfig .NewConfig() .Map(dto => dto.WEITUO, poco => poco.CustomerName) .Map(dto => dto.OpEName, poco => poco.OpEName) .Map(dto => dto.OpTel, poco => poco.OpTel) .Map(dto => dto.OpEmail, poco => poco.OpEmail) .Map(dto => dto.EDIATTN, poco => poco.EDIAttn) .Map(dto => dto.EDIATTNTEL, poco => poco.EDIAttnTel) .Map(dto => dto.EDIATTNEMAIL, poco => poco.EDIAttnMail) .Map(dto => dto.AMSCONSIGNEE, poco => poco.AMSConsignee) .Map(dto => dto.AMSNOTIFYPARTY, poco => poco.AMSNotifyParty) .Map(dto => dto.MasterBOLIndicator, poco => poco.MasterBolIndicator) .Map(dto => dto.KINGTAREWEIGHT, poco => poco.KingTareweight) .Map(dto => dto.ConsigneeEdiCode, poco => poco.ConsigneeEdiCode) .Map(dto => dto.ShipperEdiCode, poco => poco.ShipperEdiCode) .Map(dto => dto.SalesRepCode, poco => poco.SalerCode) .Map(dto => dto.ACIHBL, poco => poco.ACIHBL) .Map(dto => dto.S0CC0C, poco => poco.S0CC0C) .Map(dto => dto.cKHI, poco => poco.CKHI) .Map(dto => dto.cNCM, poco => poco.CNCM) .Map(dto => dto.wNCM, poco => poco.WNCM) .Map(dto => dto.CNPTNo, poco => poco.CNPTNo) .Map(dto => dto.ORDERREMARK, poco => poco.OrderRemark) //.Map(dto => dto.ERNCODE, poco => poco.) //.Map(dto => dto.TACCODE, poco => poco.) //.Map(dto => dto.VAECODE, poco => poco.) //.Map(dto => dto.FECCODE, poco => poco.) ; TypeAdapterConfig .NewConfig() .Map(dto => dto.ORDERNO, poco => poco.OrderNo) .Map(dto => dto.YARD, poco => poco.Yard) .Map(dto => dto.MBLNO, poco => poco.MBLNO) .Map(dto => dto.BLFRT, poco => poco.MBLFrt) .Map(dto => dto.VESSEL, poco => poco.Vessel) .Map(dto => dto.VOYNO, poco => poco.Voyno) .Map(dto => dto.NVOYNO, poco => poco.InnerVoyno) .Map(dto => dto.ETD, poco => poco.ETD) .Map(dto => dto.ETA, poco => poco.ETA) .Map(dto => dto.CLOSINGDATE, poco => poco.ClosingDate) .Map(dto => dto.EDIREMARK, poco => poco.EdiRemark) //.Map(dto => dto.SIREMARK, poco => poco.) //.Map(dto => dto.BYCOUNTRY, poco => poco.) .Map(dto => dto.CARRIER, poco => poco.Carrier) .Map(dto => dto.CARRIERID, poco => poco.Carrier) .Map(dto => dto.SHIPPER, poco => poco.Shipper) .Map(dto => dto.CONSIGNEE, poco => poco.Consignee) .Map(dto => dto.NOTIFYPARTY, poco => poco.NotifyParty) .Map(dto => dto.NOTIFYPARTY2, poco => poco.SecondNotifyParty) .Map(dto => dto.HSCODE, poco => poco.HSCode) .Map(dto => dto.GOODSNAME, poco => poco.GoodsName) .Map(dto => dto.MARKS, poco => poco.Marks) .Map(dto => dto.PLACERECEIPTID, poco => poco.ReceiptPlace) .Map(dto => dto.PLACERECEIPT, poco => poco.ReceiptPlace) .Map(dto => dto.PORTLOADID, poco => poco.LoadPort) .Map(dto => dto.PORTLOAD, poco => poco.LoadPort) .Map(dto => dto.PORTDISCHARGEID, poco => poco.DischargePort) .Map(dto => dto.PORTDISCHARGE, poco => poco.DischargePort) .Map(dto => dto.TRANSPORTID, poco => poco.TransportCode) .Map(dto => dto.TRANSPORT, poco => poco.Transport) .Map(dto => dto.PLACEDELIVERYID, poco => poco.DeliveryPlace) .Map(dto => dto.PLACEDELIVERY, poco => poco.DeliveryPlace) .Map(dto => dto.DESTINATIONID, poco => poco.Destination) .Map(dto => dto.DESTINATION, poco => poco.Destination) .Map(dto => dto.PKGS, poco => poco.PKGS) .Map(dto => dto.KINDPKGS, poco => poco.KindPkgs) .Map(dto => dto.CBM, poco => poco.CBM) .Map(dto => dto.CARGOID, poco => poco.CargoId) .Map(dto => dto.DCLASS, poco => poco.DangerClass) .Map(dto => dto.DUNNO, poco => poco.DangerNo) .Map(dto => dto.DPAGE, poco => poco.DangerPage) .Map(dto => dto.DLABEL, poco => poco.DangerLabel) .Map(dto => dto.TEMPSET, poco => poco.TemperatureSet) .Map(dto => dto.TEMPMIN, poco => poco.TemperatureMin) .Map(dto => dto.TEMPMAX, poco => poco.TemperatureMax) .Map(dto => dto.REEFERF, poco => poco.ReeferQuantity) .Map(dto => dto.HUMIDITY, poco => poco.Humidity) .Map(dto => dto.PREPARDAT, poco => poco.PrepareAt) .Map(dto => dto.PREPARDATID, poco => poco.PrepareAt) .Map(dto => dto.PAYABLEAT, poco => poco.PayableAt) .Map(dto => dto.PAYABLEATID, poco => poco.PayableAt) .Map(dto => dto.NOBILL, poco => poco.NoBill) .Map(dto => dto.ISSUEPLACE, poco => poco.IssuePlace) .Map(dto => dto.ISSUEDATE, poco => poco.IssueDate) .Map(dto => dto.ISSUEPLACEID, poco => poco.IssuePlace) .Map(dto => dto.SERVICE, poco => poco.Service) .Map(dto => dto.CONTRACTNO, poco => poco.ContractNo) .Map(dto => dto.SERVICECONTRACTNO, poco => poco.ServiceContractNo) //.Map(dto => dto.CONSIGNEEPOSTCODE, poco => poco.) //.Map(dto => dto.CONSIGNEECOUNTRY, poco => poco.) //.Map(dto => dto.CONSIGNEETAXNO, poco => poco.) //.Map(dto => dto.NOTIFYPARTYPOSTCODE, poco => poco.) //.Map(dto => dto.NOTIFYPARTYCOUNTRY, poco => poco.) //.Map(dto => dto.NOTIFYPARTYTAXNO, poco => poco.) //.Map(dto => dto.CONSIGNEEDOORADDR, poco => poco.) //.Map(dto => dto.SHIPPERDOORADDR, poco => poco.) //.Map(dto => dto.SCACCODE, poco => poco.) //.Map(dto => dto.ITNCODE, poco => poco.) //.Map(dto => dto.FREIGHTPAYER, poco => poco.) //.Map(dto => dto.AMSCODE, poco => poco.) .Map(dto => dto.ISCONTAINERSOC, poco => poco.IsContainerSoc) //.Map(dto => dto.GOODSCODE, poco => poco.GoodsName) //.Map(dto => dto.SERVICEEDICODE, poco => poco.) ; TypeAdapterConfig .NewConfig() .Map(dto => dto.CNTRNO, poco => poco.CntrNo) .Map(dto => dto.TEU, poco => poco.TEU) .Map(dto => dto.CTNNUM, poco => poco.CtnNum) .Map(dto => dto.CTNSTATUS, poco => poco.CtnStatus) .Map(dto => dto.SEALNO, poco => poco.SealNo) .Map(dto => dto.PKGS, poco => poco.PKGS) .Map(dto => dto.KINDPKGS, poco => poco.KindPkgs) .Map(dto => dto.KGS, poco => poco.KGS) .Map(dto => dto.CBM, poco => poco.CBM) .Map(dto => dto.TAREWEIGHT, poco => poco.TareWeight) .Map(dto => dto.WEIGHKGS, poco => poco.WeightKGS) .Map(dto => dto.WEIGHTYPE, poco => poco.WeightType) .Map(dto => dto.WEIGHSIGN, poco => poco.WeightSign) ; TypeAdapterConfig .NewConfig() .Map(dto => dto.HSCODE, poco => poco.HSCode) .Map(dto => dto.MARKS, poco => poco.Marks) .Map(dto => dto.DESCRIPTION, poco => poco.Description) .Map(dto => dto.PKGS, poco => poco.PKGS) .Map(dto => dto.KINDPKGS, poco => poco.KindPkgs) .Map(dto => dto.KGS, poco => poco.KGS) .Map(dto => dto.CBM, poco => poco.CBM); //.IgnoreNonMapped(true);//只映射Map指定的属性,其他属性都排除; //映射规则引擎 TypeAdapterConfig .NewConfig() .Map(dto => dto.MasterBlNo, poco => poco.MBLNO) .Map(dto => dto.HouseBlNo, poco => poco.HBLNO) .Map(dto => dto.BookingNo, poco => poco.BookingNo) .Map(dto => dto.ServContrNo, poco => poco.ServiceContractNo) .Map(dto => dto.Shipper, poco => poco.Shipper) .Map(dto => dto.ShipperId, poco => poco.ShipperId) .Map(dto => dto.Consignee, poco => poco.Consignee) .Map(dto => dto.ConsigneeId, poco => poco.ConsigneeId) .Map(dto => dto.NotifyParty, poco => poco.NotifyParty) .Map(dto => dto.NotifyPartyId, poco => poco.NotifyPartyId) .Map(dto => dto.NotifyPrt2, poco => poco.SecondNotifyParty) .Map(dto => dto.Yard, poco => poco.Yard) .Map(dto => dto.YardId, poco => poco.YardId) .Map(dto => dto.Vessel, poco => poco.Vessel) .Map(dto => dto.VesselId, poco => poco.VesselId) .Map(dto => dto.Voyno, poco => poco.Voyno) .Map(dto => dto.VoynoIn, poco => poco.InnerVoyno) .Map(dto => dto.ETD, poco => poco.ETD) .Map(dto => dto.ATD, poco => poco.ATD) .Map(dto => dto.ETA, poco => poco.ETA) .Map(dto => dto.ClosingDate, poco => poco.ClosingDate) .Map(dto => dto.CloseDocDate, poco => poco.CloseDocDate) .Map(dto => dto.CloseVGMDate, poco => poco.CloseVgmDate) .Map(dto => dto.PortLoad, poco => poco.LoadPort) .Map(dto => dto.PortLoadId, poco => poco.LoadPortId) .Map(dto => dto.PlaceReceipt, poco => poco.ReceiptPlace) .Map(dto => dto.PlaceReceiptId, poco => poco.ReceiptPlaceId) .Map(dto => dto.PortDischarge, poco => poco.DischargePort) .Map(dto => dto.PortDischargeId, poco => poco.DischargePortId) .Map(dto => dto.PlaceDelivery, poco => poco.DeliveryPlace) .Map(dto => dto.PlaceDeliveryId, poco => poco.DeliveryPlaceId) .Map(dto => dto.Destination, poco => poco.Destination) .Map(dto => dto.DestinationId, poco => poco.DestinationId) .Map(dto => dto.NoBill, poco => poco.NoBill) .Map(dto => dto.CopyNoBill, poco => poco.CopyNoBill) .Map(dto => dto.IssueType, poco => poco.IssueType) .Map(dto => dto.IssueDate, poco => poco.IssueDate) .Map(dto => dto.IssuePlace, poco => poco.IssuePlace) .Map(dto => dto.Blfrt, poco => poco.MBLFrt) .Map(dto => dto.PrepardAt, poco => poco.PrepareAt) .Map(dto => dto.PayableAt, poco => poco.PayableAt) .Map(dto => dto.Service, poco => poco.Service) .Map(dto => dto.Marks, poco => poco.Marks) .Map(dto => dto.HsCode, poco => poco.HSCode) .Map(dto => dto.GoodsDescription, poco => poco.Description) .Map(dto => dto.PKGs, poco => poco.PKGS) .Map(dto => dto.KindPKGs, poco => poco.KindPkgs) .Map(dto => dto.KGs, poco => poco.KGS) .Map(dto => dto.CBM, poco => poco.CBM) .Map(dto => dto.TotalNO, poco => poco.TotalNo) .Map(dto => dto.CntrTotal, poco => poco.CntrTotal) .Map(dto => dto.Carrier, poco => poco.Carrier) //.Map(dto => dto.CarrierId, poco => poco.Carrier) .Map(dto => dto.CargoId, poco => poco.CargoId) .Map(dto => dto.DClass, poco => poco.DangerClass) .Map(dto => dto.DUnno, poco => poco.DangerNo) .Map(dto => dto.DPage, poco => poco.DangerPage) .Map(dto => dto.DLabel, poco => poco.DangerLabel) //.Map(dto => dto.DLinkMan, poco => poco.dan) .Map(dto => dto.TempId, poco => poco.TemperatureUnit) .Map(dto => dto.TempSet, poco => poco.TemperatureSet) .Map(dto => dto.Reeferf, poco => poco.ReeferQuantity) .Map(dto => dto.Humidity, poco => poco.Humidity) .Map(dto => dto.TempMin, poco => poco.TemperatureMin) .Map(dto => dto.TempMax, poco => poco.TemperatureMax) .Map(dto => dto.IsContaSOC, poco => poco.IsContainerSoc) .Map(dto => dto.YardRemark, poco => poco.YardRemark) //.Map(dto => dto.CompId, poco => poco.OrgId.ToString()) //.Map(dto => dto.CompName, poco => poco.OrgId.ToString()) //.Map(dto => dto.CustserviceName, poco => poco.CustserviceName) .Map(dto => dto.Forwarder, poco => poco.Forwarder) .Map(dto => dto.ShipAgency, poco => poco.ShipAgency) .Map(dto => dto.CustomsER, poco => poco.Customser) .Map(dto => dto.TruckER, poco => poco.Trucker) .Map(dto => dto.AgentId, poco => poco.AgentId) .Map(dto => dto.CustomerId, poco => poco.CustomerId) .Map(dto => dto.ForwarderId, poco => poco.ForwarderId) .Map(dto => dto.ShipAgencyId, poco => poco.ShipAgencyId) .Map(dto => dto.CustomsERId, poco => poco.CustomserId) .Map(dto => dto.TruckERId, poco => poco.TruckerId) //.Map(dto => dto.AgentName, poco => poco.Agent) .Map(dto => dto.WeiTo, poco => poco.CustomerName) //.Map(dto => dto.SCACCode, poco => poco.sca) //.Map(dto => dto.ITNCode, poco => poco.it) .Map(dto => dto.PrePardAtId, poco => poco.PrepareAtId) //.Map(dto => dto.PayableAtId, poco => poco.pa) .Map(dto => dto.CustNo, poco => poco.CustomNo) .Map(dto => dto.TransportId, poco => poco.TransportCode) .Map(dto => dto.Transport, poco => poco.Transport) .Map(dto => dto.IsMutipleGoods, poco => poco.IsMoreGood); TypeAdapterConfig .NewConfig() .Map(dto => dto.ContaType, poco => poco.CtnCode) .Map(dto => dto.ContaTypeName, poco => poco.CtnAll) .Map(dto => dto.ContaNo, poco => poco.CntrNo) .Map(dto => dto.TEU, poco => poco.TEU) .Map(dto => dto.SealNo, poco => poco.SealNo) .Map(dto => dto.PKGs, poco => poco.PKGS) .Map(dto => dto.KindPKGs, poco => poco.KindPkgs) .Map(dto => dto.KGs, poco => poco.KGS) .Map(dto => dto.CBM, poco => poco.CBM) .Map(dto => dto.TareWeight, poco => poco.TareWeight) .Map(dto => dto.WeighKGs, poco => poco.WeightKGS) .Map(dto => dto.WeighType, poco => poco.WeightType) .Map(dto => dto.ContaStatus, poco => poco.CtnStatus) ; #endregion 设置对象映射 } /// /// 列表 /// /// /// public async Task>> GetListByPage(PageRequest request) { var tenantDb = saasService.GetBizDbScopeById(user.TenantId); //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var data = await tenantDb.Queryable() .Where(whereList) .Select() .Mapper(it => { it.SourceDetailName = tenantDb.Queryable().Where(x => x.Id == it.SourceDetailId).Select(n => n.DetailName).First(); var feeStatus = tenantDb.Queryable().First(x => x.BusinessId == it.Id); it.ARFeeStatus = feeStatus.IsNull() ? 0 : (int)feeStatus.ARFeeStatus; it.APFeeStatus = feeStatus.IsNull() ? 0 : (int)feeStatus.APFeeStatus; it.ARInvoiceStatus = feeStatus.IsNull() ? 0 : feeStatus.ARInvoiceStatus; it.APInvoiceStatus = feeStatus.IsNull() ? 0 : feeStatus.APInvoiceStatus; it.ARCheckStatus = feeStatus.IsNull() ? 0 : feeStatus.ARCheckStatus; it.IsFeeLocking = feeStatus.IsNull() ? false : feeStatus.IsFeeLocking; it.IsBusinessLocking = feeStatus.IsNull() ? false : feeStatus.IsBusinessLocking; it.BillFeeStatus = feeStatus.IsNull() ? 0 : feeStatus.BillAuditStatus; it.BillFeeStatusTime = feeStatus.IsNull() ? null : feeStatus.BillFeeStatusTime; } ).ToQueryPageAsync(request.PageCondition); return data; } /// /// 编辑 /// /// /// public async Task EditSeaExport(SeaExportReq req) { var dbScope = (SqlSugarScope)db; var tenantDb = saasService.GetBizDbScopeById(user.TenantId); if (req.Id == 0) { if (req.BLType != "拼箱分票" && tenantDb.Queryable().Where(x => x.MBLNO == req.MBLNO.Trim()).Any()) { return await Task.FromResult(DataResult.Failed("海运出口信息主提单号已存在!", MultiLanguageConst.SeaExportMBLNOExist)); } if (tenantDb.Queryable().Where(x => x.HBLNO == req.HBLNO.Trim()).Any()) { return await Task.FromResult(DataResult.Failed("海运出口信息分提单号已存在!", MultiLanguageConst.SeaExportHBLNOExist)); } //TODO 会计期间不允许小于已结转期间 if (req.CloseDocDate.IsNotNull() && req.CloseDocDate < req.ETD) { return await Task.FromResult(DataResult.Failed("截单日期不允许小于开船日期!", MultiLanguageConst.SeaExportCloseDocDateLimit)); } if (req.ClosingDate.IsNotNull() && req.ClosingDate < req.ETD) { return await Task.FromResult(DataResult.Failed("截港日期不允许小于开船日期!", MultiLanguageConst.SeaExportCloseDateLimit)); } var sequence = commonService.GetSequenceNext(); if (!sequence.Succeeded) { return await Task.FromResult(DataResult.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist)); } var data = req.Adapt(); data.CustomerNo = sequence.Data; #region 处理箱型箱量 if (req.CtnInfo.Count > 0) { //处理箱型箱量 data = UpdateSeaExportCtnInfo(data, req.CtnInfo); } #endregion #region 更新结算方式及结算日期 //更新结算方式及结算日期 var stlInfo = seaComService.GetCustomerStlInfo(new CustomerStlReq() { CustomerId = req.CustomerId, ETD = req.ETD, SaleId = req.SaleId }); if (!stlInfo.Succeeded) { 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(); //处理订单联系人信息 DealBusinessOrderContact(entity, tenantDb); if (req.CtnInfo.Count > 0) { foreach (var item in req.CtnInfo) { var ctn = item.Adapt(); ctn.BSNO = entity.Id.ToString(); await tenantDb.Insertable(ctn).ExecuteCommandAsync(); } } if (req.EdiInfo.IsNotNull()) { var edi = req.EdiInfo.Adapt(); 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)); } catch (Exception ex) { await dbScope.Ado.RollbackTranAsync(); return await Task.FromResult(DataResult.Failed("添加失败!" + ",请联系管理员!" + ex.ToString())); } } else { var info = await tenantDb.Queryable().Where(x => x.Id == req.Id).FirstAsync(); var feeStatus = await tenantDb.Queryable().Where(x => x.BusinessId == req.Id).FirstAsync(); if (feeStatus.IsNotNull() && (bool)feeStatus.IsBusinessLocking) { return await Task.FromResult(DataResult.Failed("海运出口信息业务已锁定!", MultiLanguageConst.SeaExportBusinessLock)); } info = req.Adapt(info); //TODO 会计期间不允许小于已结转期间 if (info.CloseDocDate.IsNotNull() && info.CloseDocDate < info.ETD) { return await Task.FromResult(DataResult.Failed("截单日期不允许小于开船日期!", MultiLanguageConst.SeaExportCloseDocDateLimit)); } if (info.ClosingDate.IsNotNull() && info.ClosingDate < info.ETD) { return await Task.FromResult(DataResult.Failed("截港日期不允许小于开船日期!", MultiLanguageConst.SeaExportCloseDateLimit)); } #region 处理箱型箱量 if (req.CtnInfo.Count > 0) { //处理箱型箱量 info = UpdateSeaExportCtnInfo(info, req.CtnInfo); } #endregion #region 更新结算方式及结算日期 //更新结算方式及结算日期 var stlInfo = seaComService.GetCustomerStlInfo(new CustomerStlReq() { CustomerId = req.CustomerId, ETD = req.ETD, SaleId = req.SaleId }); if (!stlInfo.Succeeded) { return await Task.FromResult(DataResult.Failed(stlInfo.Message)); } info.StlName = stlInfo.Data.StlName; info.StlDate = stlInfo.Data.StlDate; #endregion 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().Where(x => x.BSNO == req.Id.ToString()).ToListAsync(); foreach (var item in req.CtnInfo) { if (item.Id == 0) { var ctn = item.Adapt(); 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.EdiInfo.IsNotNull()) { var edi = await tenantDb.Queryable().Where(x => x.BusinessId == req.Id).FirstAsync(); if (edi.IsNull()) { var ediInfo = req.EdiInfo.Adapt(); ediInfo.BusinessId = req.Id; await tenantDb.Insertable(ediInfo).ExecuteCommandAsync(); } else { 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)); } catch (Exception ex) { await dbScope.Ado.RollbackTranAsync(); return await Task.FromResult(DataResult.Failed("更新失败!" + ",请联系管理员!" + ex.ToString())); } } } /// /// 处理订单联系人信息 /// /// /// private void DealBusinessOrderContact(SeaExport seaExport,SqlSugarScopeProvider sqlSugarScope) { var contactLists = sqlSugarScope.Queryable().Where(x => x.BusinessId == seaExport.Id).ToList(); var addList = new List(); if (seaExport.CustomerId!=0) { var defaultContact = sqlSugarScope.Queryable().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().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().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(); } /// /// 详情 /// /// /// public DataResult GetSeaExportInfo(string id) { var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var data = tenantDb.Queryable() .Where(a => a.Id == long.Parse(id)) .Select() .Mapper(it => { it.EdiInfo = tenantDb.Queryable().Where(x => x.BusinessId == it.Id).Select().First(); } ) .First(); return DataResult.Success(data, MultiLanguageConst.DataQuerySuccess); } /// /// 批量更新 /// /// /// public DataResult SeaExportBatchEdit(SeaExportBatchEditReq req) { var tenantDb = saasService.GetBizDbScopeById(user.TenantId); if (req.Ids.Count == 0) { return DataResult.Failed("海运出口批量编辑未勾选!", MultiLanguageConst.SeaExportBatchEditNoSelect); } if (tenantDb.Queryable().Where(x => !req.Ids.Contains(x.Id)).Any().IsNull()) { return DataResult.Failed("不存在的海运出口信息!", MultiLanguageConst.SeaExportExist); } if (tenantDb.Queryable().Where(x => req.Ids.Contains(x.BusinessId) && x.IsBusinessLocking == true).Any()) { return DataResult.Failed("海运出口信息业务已锁定!", MultiLanguageConst.SeaExportBusinessLock); } if (req.AccountDate.IsNotNull()) { if (tenantDb.Queryable().Where(x => req.Ids.Contains(x.BusinessId) && x.IsFeeLocking == true).Any()) { return DataResult.Failed("海运出口信息费用已锁定!", MultiLanguageConst.SeaExportFeeLock); } } var orderList = tenantDb.Queryable().Where(x => req.Ids.Contains(x.Id)).ToList(); var dic = req.GetPropertiesArray(); foreach (var item in orderList) { var info = req.Adapt(item); tenantDb.Updateable(info).UpdateColumns(dic).EnableDiffLogEvent().ExecuteCommand(); } return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess); } /// /// 业务单据单票复制 /// /// 业务Id /// public DataResult SeaExportCopy(string id) { var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var info = tenantDb.Queryable().Where(x => x.Id == long.Parse(id)).First(); if (info.IsNullOrEmpty()) { return DataResult.Failed("海运出口信息不存在!", MultiLanguageConst.SeaExportNotExist); } //获取表单复制模板 var template = tenantDb.Queryable().Where(x => x.PermissionId == 1772509201441099776).First(); var sequence = commonService.GetSequenceNext(); if (!sequence.Succeeded) { return DataResult.Failed(sequence.Message, MultiLanguageConst.SequenceSetNotExist); } var data = new SeaExport(); if (template.IsNullOrEmpty()) { data = info.Adapt(data); data.Id = 0; data.ParentId = 0; //data.IsBusinessLocking = false; //data.IsFeeLocking = false; data.CustomerNo = sequence.Data; var entity = tenantDb.Insertable(data).ExecuteReturnEntity(); #region 初始化费用状态表 var feeStatus = BusinessFeeStatus.Init(entity.Id); tenantDb.Insertable(feeStatus).ExecuteCommand(); #endregion return DataResult.Successed("复制成功!", entity.Id, MultiLanguageConst.DataCopySuccess); } else { data = info.Adapt(data); data.Id = 0; data.ParentId = 0; //data.IsBusinessLocking = false; //data.IsFeeLocking = false; data.CustomerNo = sequence.Data; var list0 = template.CopyFields.Split(","); var list1 = new List(); foreach (var item in list0) { list1.Add(item.ToUpperCamelCase()); } list1.Add("IsBusinessLocking"); list1.Add("IsFeeLocking"); list1.Add("CustomerNo"); var insertColumns = list1.ToArray(); //insertColumns.AddRange(["Id", "ParentId", "IsBusinessLocking", "IsFeeLocking", "CustomerNo"]); var entity = tenantDb.Insertable(data).InsertColumns(insertColumns).ExecuteReturnEntity(); #region 初始化费用状态表 var feeStatus = BusinessFeeStatus.Init(entity.Id); tenantDb.Insertable(feeStatus).ExecuteCommand(); #endregion return DataResult.Successed("复制成功!", entity.Id, MultiLanguageConst.DataCopySuccess); } } #region 删除 /// /// 业务单据删除 /// /// 业务Id /// public DataResult SeaExportDel(string id) { var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var info = tenantDb.Queryable().Where(x => x.Id == long.Parse(id)).First(); if (info.IsNullOrEmpty()) { return DataResult.Failed("海运出口信息不存在!", MultiLanguageConst.SeaExportNotExist); } if (tenantDb.Queryable().Where(x => x.ParentId == long.Parse(id)).Any()) { return DataResult.Failed("海运出口存在分票信息,不能删除!", MultiLanguageConst.SeaExportPartExist); } if (tenantDb.Queryable().Where(x => x.BusinessId == long.Parse(id)).Any()) { return DataResult.Failed("海运出口存在费用信息,不能删除!", MultiLanguageConst.SeaExportFeeExist); } if (tenantDb.Queryable().Where(x => x.BusinessId == long.Parse(id) && x.IsBusinessLocking == true).Any()) { return DataResult.Failed("海运出口信息业务已锁定!", MultiLanguageConst.SeaExportBusinessLock); } if (tenantDb.Queryable().Where(x => x.BusinessId == long.Parse(id) && x.IsFeeLocking == true).Any()) { return DataResult.Failed("海运出口信息费用已锁定!", MultiLanguageConst.SeaExportFeeLock); } info.Deleted = true; info.DeleteTime = DateTime.Now; info.DeleteBy = long.Parse(user.UserId); tenantDb.Updateable(info).ExecuteCommand(); //tenantDb.Deleteable(info).IsLogic().ExecuteCommand("Deleted"); return DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess); } /// /// 业务单据删除 /// /// 业务Ids /// public DataResult SeaExportBatchDel(IdModel req) { var tenantDb = saasService.GetBizDbScopeById(user.TenantId); if (req.Ids.Length == 0) { return DataResult.Failed("海运出口批量操作未勾选!", MultiLanguageConst.SeaExportBatchOpNoSelect); } if (tenantDb.Queryable().Where(x => req.Ids.Contains(x.Id)).Any().IsNull()) { return DataResult.Failed("不存在的海运出口信息!", MultiLanguageConst.SeaExportExist); } if (tenantDb.Queryable().Where(x => req.Ids.Contains(x.BusinessId) && x.IsBusinessLocking == true).Any()) { return DataResult.Failed("海运出口信息业务已锁定!", MultiLanguageConst.SeaExportBusinessLock); } if (tenantDb.Queryable().Where(x => req.Ids.Contains(x.BusinessId) && x.IsFeeLocking == true).Any()) { return DataResult.Failed("海运出口信息费用已锁定!", MultiLanguageConst.SeaExportFeeLock); } if (tenantDb.Queryable().Where(x => req.Ids.Contains(x.ParentId)).Any()) { return DataResult.Failed("海运出口存在分票信息,不能删除!", MultiLanguageConst.SeaExportPartExist); } if (tenantDb.Queryable().Where(x => req.Ids.Contains(x.BusinessId)).Any()) { return DataResult.Failed("海运出口存在费用信息,不能删除!", MultiLanguageConst.SeaExportFeeExist); } var list = tenantDb.Queryable().Where(x => req.Ids.Contains(x.Id)).ToList(); //tenantDb.Deleteable(list).IsLogic().ExecuteCommand("Deleted"); //tenantDb.Deleteable(list).IsLogic().ExecuteCommand("Deleted"); foreach (var item in list) { item.Deleted = true; item.DeleteTime = DateTime.Now; item.DeleteBy = long.Parse(user.UserId); tenantDb.Updateable(item).ExecuteCommand(); } return DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess); } #endregion #region 保存集装箱明细信息需自动更新业务主表 箱量相关字段(CNTR1--CNTR10)每种箱型的数量,列头显示箱型 、TEU(合计TEU)、CNTRTOTAL(集装箱 例如:20GP*1 40GP*2) /// /// 保存集装箱明细信息需自动更新业务主表 /// /// /// /// private SeaExport UpdateSeaExportCtnInfo(SeaExport entity, List ctnList) { var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var dictList = db.Queryable().InnerJoin((a, b) => a.TypeId == b.Id) .Where((a, b) => b.Code == "seaexport_ctn_map").OrderBy((a, b) => a.OrderNo) .Select((a, b) => a.Value).ToList(); #region 重置相关字段属性 entity.Cntr1 = 0; entity.Cntr2 = 0; entity.Cntr3 = 0; entity.Cntr4 = 0; entity.Cntr5 = 0; entity.Cntr6 = 0; entity.Cntr7 = 0; entity.Cntr8 = 0; entity.Cntr9 = 0; entity.Cntr10 = 0; entity.OtherCntr = 0; entity.TEU = 0; entity.CntrTotal = ""; #endregion #region 处理箱型箱量 for (int i = 0; i < dictList.Count; i++) { var ctnCode = dictList[i]; //var ctn = ctnList.Where(x => (x.CtnCode == ctnCode || x.Ctn == ctnCode)).First(); //var ctn = ctnList.Where(x => x.Ctn == ctnCode).First(); if (ctnList.Where(x => x.CtnCode == ctnCode).Any()) { var ctns = ctnList.Where(x => x.CtnCode == ctnCode).ToList(); foreach (var ctn in ctns) { switch (ctnCode.ToUpper()) { case "40HQ": entity.Cntr1 += ctn.CtnNum; entity.TEU += ctn.TEU; entity.CntrTotal += ctnCode + "*" + ctn.TEU + ""; break; case "20GP": entity.Cntr2 += ctn.CtnNum; entity.TEU += ctn.TEU; entity.CntrTotal += ctnCode + "*" + ctn.TEU + ""; break; case "40GP": entity.Cntr3 += ctn.CtnNum; entity.TEU += ctn.TEU; entity.CntrTotal += ctnCode + "*" + ctn.TEU + ""; break; case "40HC": entity.Cntr4 += ctn.CtnNum; entity.TEU += ctn.TEU; entity.CntrTotal += ctnCode + "*" + ctn.TEU + ""; break; case "20OT": entity.Cntr5 += ctn.CtnNum; entity.TEU += ctn.TEU; entity.CntrTotal += ctnCode + "*" + ctn.TEU + ""; break; case "40OT": entity.Cntr6 += ctn.CtnNum; entity.TEU += ctn.TEU; entity.CntrTotal += ctnCode + "*" + ctn.TEU + ""; break; case "20FR": entity.Cntr7 += ctn.CtnNum; entity.TEU += ctn.TEU; entity.CntrTotal += ctnCode + "*" + ctn.TEU + ""; break; case "40FR": entity.Cntr8 += ctn.CtnNum; entity.TEU += ctn.TEU; entity.CntrTotal += ctnCode + "*" + ctn.TEU + ""; break; case "20RF": entity.Cntr9 += ctn.CtnNum; entity.TEU += ctn.TEU; entity.CntrTotal += ctnCode + "*" + ctn.TEU + ""; break; case "40RF": entity.Cntr10 += ctn.CtnNum; entity.TEU += ctn.TEU; entity.CntrTotal += ctnCode + "*" + ctn.TEU + ""; break; default: break; } } } } //处理其他箱型 var otherCtns = ctnList.Where(x => !dictList.Contains(x.CtnCode)).ToList(); if (otherCtns.Count > 0) { foreach (var item in otherCtns) { entity.OtherCntr += item.CtnNum; entity.TEU += item.TEU; entity.CntrTotal += item.CtnCode + "*" + item.TEU + ""; } } #endregion return entity; } #endregion }