|
|
using Myshipping.Core;
|
|
|
using Furion.DependencyInjection;
|
|
|
using Furion.DynamicApiController;
|
|
|
using Mapster;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using SqlSugar;
|
|
|
using System.Linq;
|
|
|
using System.Threading.Tasks;
|
|
|
using Myshipping.Application.Entity;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
using Furion;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using Furion.DataEncryption;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Security.Claims;
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
using Furion.FriendlyException;
|
|
|
using Furion.Logging;
|
|
|
using System;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
using System.Reflection;
|
|
|
using System.ComponentModel;
|
|
|
using Myshipping.Application.Service.BookingOrder.Dto;
|
|
|
using Myshipping.Application.ConfigOption;
|
|
|
using System.IO;
|
|
|
using Yitter.IdGenerator;
|
|
|
using Myshipping.Core.Entity;
|
|
|
using Furion.RemoteRequest.Extensions;
|
|
|
using System.Net.Http;
|
|
|
using Myshipping.Core.Service;
|
|
|
using Myshipping.Application.EDI;
|
|
|
using System.Text;
|
|
|
using System.Web;
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
using Myshipping.Core.Helper;
|
|
|
using Myshipping.Application.Enum;
|
|
|
using Org.BouncyCastle.Asn1.X500;
|
|
|
using System.Drawing.Drawing2D;
|
|
|
using StackExchange.Profiling.Internal;
|
|
|
using Myshipping.Application;
|
|
|
using Myshipping.Application.EDI.PIL;
|
|
|
using Newtonsoft.Json;
|
|
|
using Myshipping.Application.EDI.TSL;
|
|
|
using Myshipping.Application.EDI.WY;
|
|
|
using Myshipping.Application.EDI.YML;
|
|
|
using Myshipping.Application.EDI.YT;
|
|
|
using System.Runtime.InteropServices;
|
|
|
using System.Threading;
|
|
|
using Furion.JsonSerialization;
|
|
|
using System.Xml.Linq;
|
|
|
using Myshipping.Application.Helper;
|
|
|
using System.Net;
|
|
|
using Furion.DistributedIDGenerator;
|
|
|
using System.Linq.Expressions;
|
|
|
using Myshipping.Core.Extension;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using MathNet.Numerics.Distributions;
|
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
using Myshipping.Application.EDI.ESL;
|
|
|
using NPOI.HSSF.UserModel;
|
|
|
using NPOI.SS.UserModel;
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
using NPOI.HPSF;
|
|
|
using MimeKit;
|
|
|
using NPOI.SS.Formula;
|
|
|
using NPOI.Util;
|
|
|
using System.Collections.Specialized;
|
|
|
using System.Net.Http.Headers;
|
|
|
using MySqlX.XDevAPI.Common;
|
|
|
using Ubiety.Dns.Core;
|
|
|
using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData;
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
|
namespace Myshipping.Application
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 订舱服务
|
|
|
/// </summary>
|
|
|
[ApiDescriptionSettings("Application", Name = "BookingOrder", Order = 1)]
|
|
|
public class BookingOrderService : IBookingOrderService, IDynamicApiController, ITransient
|
|
|
{
|
|
|
private readonly SqlSugarRepository<BookingOrder> _rep;
|
|
|
private readonly SqlSugarRepository<BookingCtn> _repCtn;
|
|
|
private readonly SqlSugarRepository<BookingCtnDetail> _ctndetailrep;
|
|
|
private readonly SqlSugarRepository<BookingLog> _bookinglog;
|
|
|
private readonly SqlSugarRepository<BookingLogDetail> _bookinglogdetail;
|
|
|
private readonly SqlSugarRepository<BookingRemark> _bookingremark;
|
|
|
private readonly SqlSugarRepository<BookingFile> _bookingfile;
|
|
|
private readonly ISysDataUserMenu _right;
|
|
|
private readonly SqlSugarRepository<BookingPrintTemplate> _repPrint;
|
|
|
private readonly ILogger<BookingOrderService> _logger;
|
|
|
private readonly ISysCacheService _cache;
|
|
|
private readonly IDjyWebsiteAccountConfigService _webAccountConfig;
|
|
|
private readonly SqlSugarRepository<BookingStatusLog> _repStatuslog;
|
|
|
private readonly SqlSugarRepository<BookingStatusLogDetail> _statuslogdetail;
|
|
|
private readonly SqlSugarRepository<BookingPrintTemplate> _repPrintTemplate;
|
|
|
private readonly SqlSugarRepository<BookingLetteryard> _repLetterYard;
|
|
|
private readonly SqlSugarRepository<SysUser> _repUser;
|
|
|
private readonly SqlSugarRepository<BookingOrderUrl> _repOrderUrl;
|
|
|
private readonly SqlSugarRepository<BookingOrderContact> _repOrderContact;
|
|
|
private readonly SqlSugarRepository<BookingSampleBill> _repSampleBill;
|
|
|
private readonly SqlSugarRepository<DjyUserMailAccount> _repUserMail;
|
|
|
private readonly SqlSugarRepository<SysTenant> _repTenant;
|
|
|
private readonly SqlSugarRepository<BookingStatus> _repBookingStatus;
|
|
|
private readonly SqlSugarRepository<BookingEDIExt> _bookingEDIExt;
|
|
|
private readonly SqlSugarRepository<DjyUserConfig> _repUserConfig;
|
|
|
private readonly SqlSugarRepository<BookingExcelTemplate> _excelrep;
|
|
|
private readonly SqlSugarRepository<BookingServiceItem> _serviceItem;
|
|
|
private readonly SqlSugarRepository<BookingGoodsStatus> _goodsStatus;
|
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
const string CONST_MAPPING_MODULE = "BOOK_OR_CLOSING";
|
|
|
const string CONST_MAPPING_MODULE_ROUTE = "BOOK_OR_CLOSING_RT";
|
|
|
private const string PrintRecentListTypeKey = "booking_print_recent_list";
|
|
|
|
|
|
public BookingOrderService(SqlSugarRepository<BookingOrder> rep, SqlSugarRepository<BookingCtn> repCtn, SqlSugarRepository<BookingCtnDetail> ctndetailrep,
|
|
|
SqlSugarRepository<BookingLog> bookinglog, SqlSugarRepository<BookingLogDetail> bookinglogdetail, SqlSugarRepository<BookingRemark> bookingremark,
|
|
|
SqlSugarRepository<BookingFile> bookingfile, SqlSugarRepository<DjyUserConfig> repUserConfig, SqlSugarRepository<BookingPrintTemplate> repPrint,
|
|
|
SqlSugarRepository<SysDictData> dicdata, SqlSugarRepository<BookingStatusLog> statuslog, SqlSugarRepository<BookingStatusLogDetail> statuslogdetail,
|
|
|
ILogger<BookingOrderService> logger, ISysCacheService cache, IDjyWebsiteAccountConfigService webAccountConfig, ISysDataUserMenu right,
|
|
|
SqlSugarRepository<BookingPrintTemplate> repPrintTemplate, SqlSugarRepository<BookingLetteryard> repLetterYard, SqlSugarRepository<SysUser> repUser,
|
|
|
SqlSugarRepository<BookingOrderUrl> repOrderUrl, SqlSugarRepository<BookingOrderContact> repOrderContact, SqlSugarRepository<BookingSampleBill> repSampleBill,
|
|
|
SqlSugarRepository<BookingExcelTemplate> excelrep, SqlSugarRepository<DjyUserMailAccount> repUserMail, SqlSugarRepository<BookingGoodsStatus> goodsStatus,
|
|
|
SqlSugarRepository<SysTenant> repTenant, SqlSugarRepository<BookingStatus> repBookingStatus, SqlSugarRepository<BookingEDIExt> bookingEDIExt, SqlSugarRepository<BookingServiceItem> serviceItem,
|
|
|
IHttpContextAccessor httpContextAccessor)
|
|
|
{
|
|
|
this._logger = logger;
|
|
|
this._rep = rep;
|
|
|
this._repCtn = repCtn;
|
|
|
this._ctndetailrep = ctndetailrep;
|
|
|
this._bookinglog = bookinglog;
|
|
|
this._bookinglogdetail = bookinglogdetail;
|
|
|
this._bookingremark = bookingremark;
|
|
|
this._bookingfile = bookingfile;
|
|
|
this._repPrint = repPrint;
|
|
|
this._right = right;
|
|
|
this._cache = cache;
|
|
|
this._webAccountConfig = webAccountConfig;
|
|
|
this._repStatuslog = statuslog;
|
|
|
this._statuslogdetail = statuslogdetail;
|
|
|
this._repPrintTemplate = repPrintTemplate;
|
|
|
this._repLetterYard = repLetterYard;
|
|
|
this._repUser = repUser;
|
|
|
this._repOrderUrl = repOrderUrl;
|
|
|
this._repOrderContact = repOrderContact;
|
|
|
this._repSampleBill = repSampleBill;
|
|
|
this._repUserMail = repUserMail;
|
|
|
this._repTenant = repTenant;
|
|
|
this._repBookingStatus = repBookingStatus;
|
|
|
this._bookingEDIExt = bookingEDIExt;
|
|
|
this._repUserConfig = repUserConfig;
|
|
|
this._excelrep = excelrep;
|
|
|
this._serviceItem = serviceItem;
|
|
|
this._goodsStatus = goodsStatus;
|
|
|
_httpContextAccessor = httpContextAccessor;
|
|
|
}
|
|
|
|
|
|
#region 主表和箱信息
|
|
|
/// <summary>
|
|
|
/// 分页查询订舱主表
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/Page")]
|
|
|
public async Task<dynamic> Page([FromQuery] BookingOrderInput input)
|
|
|
{
|
|
|
List<long> userlist = await _right.GetDataScopeList(351064299098181);
|
|
|
List<long?> pidlist = new List<long?>();
|
|
|
if (!string.IsNullOrWhiteSpace(input.SEALNO) || !string.IsNullOrWhiteSpace(input.CNTRNO))
|
|
|
{
|
|
|
pidlist = await _repCtn.AsQueryable().WhereIF(!string.IsNullOrWhiteSpace(input.SEALNO), x => x.SEALNO.StartsWith(input.SEALNO)).WhereIF(!string.IsNullOrWhiteSpace(input.CNTRNO), x => x.CNTRNO.StartsWith(input.CNTRNO)).Select(x => x.BILLID).ToListAsync();
|
|
|
}
|
|
|
var ftoday = DateTime.Now.AddDays(-15);
|
|
|
var etoday = DateTime.Now.AddDays(15);
|
|
|
//List<long> userlist = await DataFilterExtensions.GetDataScopeIdList();
|
|
|
var entities = await _rep.AsQueryable()
|
|
|
.WhereIF(input.firstFlag, x=>x.ETD<= etoday&&x.ETD>=ftoday||x.ETD==null)
|
|
|
.WhereIF(string.IsNullOrWhiteSpace(input.HBLNO), x => x.ParentId == 0 || x.ParentId == null)
|
|
|
.WhereIF(pidlist != null && pidlist.Count > 0, x => pidlist.Contains(x.Id))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.BSNO), u => u.BSNO.Contains(input.BSNO))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.BSSTATUS), u => u.BSSTATUS == input.BSSTATUS)
|
|
|
.WhereIF(input.BBSDATE != null, u => u.BSDATE >= input.BBSDATE)
|
|
|
.WhereIF(input.EBSDATE != null, u => u.BSDATE <= input.EBSDATE)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.MBLNO) && !input.MBLNO.Contains(','), u => u.MBLNO.Contains(input.MBLNO.Trim()))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.HBLNO) && !input.HBLNO.Contains(','), u => u.HBLNO.Contains(input.HBLNO.Trim()))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.MBLNO) && input.MBLNO.Contains(','), u => input.MBLNO.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Contains(u.MBLNO.Trim()))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.HBLNO) && input.HBLNO.Contains(','), u => input.HBLNO.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Contains(u.HBLNO.Trim()))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.BOOKINGNO), u => u.BOOKINGNO.Contains(input.BOOKINGNO))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CONTRACTNO), u => u.CONTRACTNO.Contains(input.CONTRACTNO))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SERVICECONTRACTNO), u => u.SERVICECONTRACTNO.Contains(input.SERVICECONTRACTNO))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPER), u => u.SHIPPER.Contains(input.SHIPPER))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEE), u => u.CONSIGNEE.Contains(input.CONSIGNEE))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTY), u => u.NOTIFYPARTY.Contains(input.NOTIFYPARTY))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTY2), u => u.NOTIFYPARTY2.Contains(input.NOTIFYPARTY2))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.YARDID), u => u.YARDID == input.YARDID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.VESSELID), u => u.VESSELID.Contains(input.VESSELID))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.VESSEL), u => u.VESSEL.ToLower().Contains(u.VESSEL.ToLower()))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.VOYNO), u => u.VOYNO.Contains(input.VOYNO))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.VOYNOINNER), u => u.VOYNOINNER.Contains(input.VOYNOINNER))
|
|
|
.WhereIF(input.BETD != null, u => u.ETD >= input.BETD)
|
|
|
.WhereIF(input.EETD != null, u => u.ETD <= input.EETD)
|
|
|
.WhereIF(input.BATD != null, u => u.ATD >= input.BATD)
|
|
|
.WhereIF(input.EATD != null, u => u.ATD <= input.EATD)
|
|
|
.WhereIF(input.BCLOSINGDATE != null, u => u.CLOSINGDATE >= input.BCLOSINGDATE)
|
|
|
.WhereIF(input.ECLOSINGDATE != null, u => u.CLOSINGDATE <= input.ECLOSINGDATE)
|
|
|
.WhereIF(input.BCLOSEDOCDATE != null, u => u.CLOSEDOCDATE >= input.BCLOSEDOCDATE)
|
|
|
.WhereIF(input.ECLOSEDOCDATE != null, u => u.CLOSEDOCDATE <= input.ECLOSEDOCDATE)
|
|
|
.WhereIF(input.BCLOSEVGMDATE != null, u => u.CLOSEVGMDATE >= input.BCLOSEVGMDATE)
|
|
|
.WhereIF(input.ECLOSEVGMDATE != null, u => u.CLOSEVGMDATE <= input.ECLOSEVGMDATE)
|
|
|
.WhereIF(input.BETA != null, u => u.ETA >= input.BETA)
|
|
|
.WhereIF(input.EETA != null, u => u.ETA <= input.EETA)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.PLACERECEIPT), u => u.PLACERECEIPT.Contains(input.PLACERECEIPT))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.PORTLOAD), u => u.PORTLOAD.Contains(input.PORTLOAD))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.PORTLOADID), u => u.PORTLOADID == input.PORTLOADID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.PORTDISCHARGEID), u => u.PORTDISCHARGEID == input.PORTDISCHARGEID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.PORTDISCHARGE), u => u.PORTDISCHARGE.Contains(input.PORTDISCHARGE))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.PLACEDELIVERY), u => u.PLACEDELIVERY.Contains(input.PLACEDELIVERY))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.PLACEDELIVERYID), u => u.PLACEDELIVERYID == input.PLACEDELIVERYID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.DESTINATION), u => u.DESTINATION.Contains(input.DESTINATION))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.DESTINATIONID), u => u.DESTINATIONID == input.DESTINATIONID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.NOBILL), u => u.NOBILL == input.NOBILL)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.COPYNOBILLL), u => u.COPYNOBILL == input.COPYNOBILLL)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ISSUETYPE), u => u.ISSUETYPE == input.ISSUETYPE)
|
|
|
.WhereIF(input.BISSUEDATE != null, u => u.ISSUEDATE >= input.BISSUEDATE)
|
|
|
.WhereIF(input.EISSUEDATE != null, u => u.ISSUEDATE <= input.EISSUEDATE)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ISSUEPLACE), u => u.ISSUEPLACE.Contains(input.ISSUEPLACE))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ISSUEPLACEID), u => u.ISSUEPLACEID == input.ISSUEPLACEID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.BLFRT), u => u.BLFRT == input.BLFRT)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.PREPARDATID), u => u.PREPARDATID == input.PREPARDATID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.PREPARDAT), u => u.PREPARDAT == input.PREPARDAT)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.PAYABLEAT), u => u.PAYABLEAT.Contains(input.PAYABLEAT))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.PAYABLEATID), u => u.PAYABLEATID == input.PAYABLEATID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SERVICE), u => u.SERVICE.Contains(input.SERVICE))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.MARKS), u => u.MARKS.Contains(input.MARKS))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.HSCODE), u => u.HSCODE.Contains(input.HSCODE))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.DESCRIPTION), u => u.DESCRIPTION.Contains(input.DESCRIPTION))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.KINDPKGS), u => u.KINDPKGS == input.KINDPKGS)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CNTRTOTAL), u => u.CNTRTOTAL.StartsWith(input.CNTRTOTAL))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CARRIERID), u => u.CARRIERID == input.CARRIERID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CARRIER), u => u.CARRIER.Contains(input.CARRIER))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CARGOID), u => u.CARGOID == input.CARGOID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.DCLASS), u => u.DCLASS == input.DCLASS)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.DUNNO), u => u.DUNNO == input.DUNNO)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.DPAGE), u => u.DPAGE == input.DPAGE)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.DLABEL), u => u.DLABEL == input.DLABEL)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.LINKMAN), u => u.LINKMAN == input.LINKMAN)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.TEMPID), u => u.TEMPID == input.TEMPID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.TEMPSET), u => u.TEMPSET == input.TEMPSET)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.REEFERF), u => u.REEFERF == input.REEFERF)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.HUMIDITY), u => u.HUMIDITY == input.HUMIDITY)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.TEMPMIN), u => u.TEMPMIN == input.TEMPMIN)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.TEMPMAX), u => u.TEMPMAX == input.TEMPMAX)
|
|
|
.WhereIF(input.ISCONTAINERSOC != null, u => u.ISCONTAINERSOC == input.ISCONTAINERSOC)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SOREMARK), u => u.SOREMARK.Contains(input.SOREMARK))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SIREMARK), u => u.SIREMARK.Contains(input.SIREMARK))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.YARDREMARK), u => u.YARDREMARK.Contains(input.YARDREMARK))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.COMPID), u => u.COMPID == input.COMPID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.COMPNAME), u => u.COMPNAME.Contains(input.COMPNAME))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERNAME), u => u.SHIPPERNAME.Contains(input.SHIPPERNAME))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERCITY), u => u.SHIPPERCITY.Contains(input.SHIPPERCITY))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERPROVINCE), u => u.SHIPPERPROVINCE == input.SHIPPERPROVINCE)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERPOSTCODE), u => u.SHIPPERPOSTCODE == input.SHIPPERPOSTCODE)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERCOUNTRY), u => u.SHIPPERCOUNTRY == input.SHIPPERCOUNTRY)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERATTN), u => u.SHIPPERATTN.Contains(input.SHIPPERATTN))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERTEL), u => u.SHIPPERTEL == input.SHIPPERTEL)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEENAME), u => u.CONSIGNEENAME.Contains(input.CONSIGNEENAME))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEECITY), u => u.CONSIGNEECITY.Contains(input.CONSIGNEECITY))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEEPROVINCE), u => u.CONSIGNEEPROVINCE == input.CONSIGNEEPROVINCE)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEEPOSTCODE), u => u.CONSIGNEEPOSTCODE == input.CONSIGNEEPOSTCODE)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEERCOUNTRY), u => u.CONSIGNEERCOUNTRY == input.CONSIGNEERCOUNTRY)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEEATTN), u => u.CONSIGNEEATTN.Contains(input.CONSIGNEEATTN))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEETEL), u => u.CONSIGNEETEL == input.CONSIGNEETEL)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTYNAME), u => u.NOTIFYPARTYNAME.Contains(input.NOTIFYPARTYNAME))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTYCITY), u => u.NOTIFYPARTYCITY.Contains(input.NOTIFYPARTYCITY))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTYPROVINCE), u => u.NOTIFYPARTYPROVINCE == input.NOTIFYPARTYPROVINCE)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTYPOSTCODE), u => u.NOTIFYPARTYPOSTCODE == input.NOTIFYPARTYPOSTCODE)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTYCOUNTRY), u => u.NOTIFYPARTYCOUNTRY == input.NOTIFYPARTYCOUNTRY)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTYATTN), u => u.NOTIFYPARTYATTN.Contains(input.NOTIFYPARTYATTN))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTYTEL), u => u.NOTIFYPARTYTEL == input.NOTIFYPARTYTEL)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.PONO), u => u.PONO == input.PONO)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.OPID), u => u.OPID == input.OPID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.DOCID), u => u.DOCID == input.DOCID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.OP), u => u.OP == input.OP)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.DOC), u => u.DOC == input.DOC)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SALEID), u => u.SALEID == input.SALEID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SALE), u => u.SALE.Contains(input.SALE))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTSERVICEID), u => u.CUSTSERVICEID == input.CUSTSERVICEID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTSERVICE), u => u.CUSTSERVICE.Contains(input.CUSTSERVICE))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTOMERNAME), u => u.CUSTOMERNAME.Contains(input.CUSTOMERNAME))
|
|
|
.WhereIF(input.CUSTOMERID != null && input.CUSTOMERID != 0, u => u.CUSTOMERID == input.CUSTOMERID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.FORWARDER), u => u.FORWARDER.Contains(input.FORWARDER))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTSERVICE), u => u.CUSTSERVICE == input.CUSTSERVICE)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTOMERNAME), u => u.CUSTOMERNAME == input.CUSTOMERNAME)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.FORWARDER), u => u.FORWARDER == input.FORWARDER)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPAGENCY), u => u.SHIPAGENCY == input.SHIPAGENCY)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTOMSER), u => u.CUSTOMSER == input.CUSTOMSER)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.AGENTID), u => u.AGENTID == input.AGENTID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.FORWARDERID), u => u.FORWARDERID == input.FORWARDERID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPAGENCY), u => u.SHIPAGENCY.Contains(input.SHIPAGENCY))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPAGENCYID), u => u.SHIPAGENCYID == input.SHIPAGENCYID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTOMSER), u => u.CUSTOMSER.Contains(input.CUSTOMSER))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTOMSERID), u => u.CUSTOMSERID == input.CUSTOMSERID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.TRUCKER), u => u.TRUCKER.Contains(input.TRUCKER))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.TRUCKERID), u => u.TRUCKERID == input.TRUCKERID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.AGENTNAME), u => u.AGENTNAME.Contains(input.AGENTNAME))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.AGENTID), u => u.AGENTID == input.AGENTID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.WEITUO), u => u.WEITUO.Contains(input.WEITUO))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SCACCODE), u => u.SCACCODE == input.SCACCODE)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ITNCODE), u => u.ITNCODE == input.ITNCODE)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTNO), u => u.CUSTNO.Contains(input.CUSTNO))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.TRANSPORTID), u => u.TRANSPORTID == input.TRANSPORTID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.TRANSPORT), u => u.TRANSPORT.Contains(input.TRANSPORT))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.YARDCONTRACTTEL), u => u.YARDCONTRACTTEL == input.YARDCONTRACTTEL)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.YARDCONTRACTEMAIL), u => u.YARDCONTRACTEMAIL == input.YARDCONTRACTEMAIL)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.LANECODE), u => u.LANECODE == input.LANECODE)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.LANENAME), u => u.LANENAME.Contains(input.LANENAME))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ROUTEID), u => u.ROUTEID == input.ROUTEID)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ROUTE), u => u.ROUTE.Contains(input.ROUTE))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CreatedUserName), u => u.CreatedUserName.Contains(input.CreatedUserName))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.FREIGHTPAYER), u => u.FREIGHTPAYER.Contains(input.FREIGHTPAYER))
|
|
|
.WhereIF(userlist != null && userlist.Count() > 0, u => userlist.Contains((long)u.CreatedUserId) || UserManager.UserId.ToString() == u.ROUTEID|| UserManager.Name.ToString() == u.ROUTE || UserManager.UserId.ToString() == u.SALEID|| UserManager.Name.ToString() == u.SALE || UserManager.UserId.ToString() == u.OPID || UserManager.Name.ToString() == u.OP || UserManager.UserId.ToString() == u.DOCID|| UserManager.Name.ToString() == u.DOC || UserManager.UserId.ToString() == u.CUSTSERVICEID || UserManager.Name.ToString() == u.CUSTSERVICE)
|
|
|
.OrderBy(PageInputOrder.OrderBuilder(input.SortField, input.descSort))
|
|
|
.ToPagedListAsync(input.PageNo, input.PageSize);
|
|
|
|
|
|
|
|
|
var list = entities.Adapt<SqlSugarPagedList<PageBookingOrder>>();
|
|
|
|
|
|
var status = await _repBookingStatus.AsQueryable().ToListAsync();
|
|
|
var remark = await _bookingremark.AsQueryable().ToListAsync();
|
|
|
|
|
|
|
|
|
foreach (var item in list.Items)
|
|
|
{
|
|
|
var sta = status.Where(x => x.BookingId == item.Id).ToList();
|
|
|
if (sta != null) {
|
|
|
|
|
|
item.bookstatus = sta;
|
|
|
}
|
|
|
var st = remark.Where(x => x.PId == item.Id).ToList();
|
|
|
if (st != null) {
|
|
|
item.bookremark = st;
|
|
|
}
|
|
|
if (!string.IsNullOrWhiteSpace(item.ETD))
|
|
|
{
|
|
|
item.ETD = Convert.ToDateTime(item.ETD).ToString("yyyy-MM-dd");
|
|
|
}
|
|
|
if (!string.IsNullOrWhiteSpace(item.ETA))
|
|
|
{
|
|
|
item.ETA = Convert.ToDateTime(item.ETA).ToString("yyyy-MM-dd");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return list;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 立即返回保存信息
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/BookingOrder/Save")]
|
|
|
public async Task<BookingOrderOutput> Save(BookingOrderDto input)
|
|
|
{
|
|
|
|
|
|
if (input == null)
|
|
|
{
|
|
|
throw Oops.Bah("请传入正常数据!");
|
|
|
}
|
|
|
var ms = JsonUtil.TrimFields(input);
|
|
|
if (!string.IsNullOrEmpty(ms)) {
|
|
|
throw Oops.Bah(ms);
|
|
|
}
|
|
|
|
|
|
JsonUtil.PropToUpper(input, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
|
|
|
if (input.ctnInputs != null)
|
|
|
{
|
|
|
var groupList = input.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
|
|
|
input.CNTRTOTAL = string.Join(" / ", groupList);
|
|
|
}
|
|
|
if (!string.IsNullOrWhiteSpace(input.MBLNO))
|
|
|
{
|
|
|
var et = await _rep.Where(x => x.MBLNO == input.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == input.HBLNO && x.ParentId == input.ParentId && x.Id != input.Id).FirstAsync();
|
|
|
if (et != null)
|
|
|
{
|
|
|
|
|
|
throw Oops.Bah("当前提单号已存在,请勿重复录入!");
|
|
|
|
|
|
}
|
|
|
}
|
|
|
var entity = input.Adapt<BookingOrder>();
|
|
|
if (input.Id == 0)
|
|
|
{
|
|
|
entity.BOOKINGNO = Yitter.IdGenerator.YitIdHelper.NextId().ToString();
|
|
|
|
|
|
await _rep.InsertAsync(entity);
|
|
|
if (input.ctnInputs != null)
|
|
|
{
|
|
|
foreach (var item in input.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 (input.BookingEDIExt != null)
|
|
|
{
|
|
|
//写入EDI扩展
|
|
|
var ediExt = input.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
|
|
|
ediExt.BookingId = entity.Id;
|
|
|
|
|
|
await _bookingEDIExt.InsertAsync(ediExt);
|
|
|
}
|
|
|
|
|
|
////添加booking日志
|
|
|
await _bookinglog.InsertAsync(new BookingLog
|
|
|
{
|
|
|
Type = "Add",
|
|
|
BookingId = entity.Id,
|
|
|
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
|
|
|
CreatedTime = DateTime.Now,
|
|
|
CreatedUserId = UserManager.UserId,
|
|
|
CreatedUserName = UserManager.Name
|
|
|
});
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var mlist = await _rep.AsQueryable().Filter(null, true).Where(x => x.Id == input.Id).FirstAsync();
|
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(it => new
|
|
|
{
|
|
|
it.ParentId,
|
|
|
it.TenantId,
|
|
|
it.CreatedTime,
|
|
|
it.CreatedUserId,
|
|
|
it.CreatedUserName,
|
|
|
it.TenantName,
|
|
|
it.IsDeleted,
|
|
|
it.BOOKINGNO
|
|
|
}).ExecuteCommandAsync();
|
|
|
var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == input.Id).Select(x => x.Id).ToListAsync();
|
|
|
await _repCtn.DeleteAsync(x => x.BILLID == input.Id);
|
|
|
await _ctndetailrep.DeleteAsync(x => ctnlist.Contains((long)x.CTNID));
|
|
|
if (input.ctnInputs != null)
|
|
|
{
|
|
|
foreach (var item in input.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 (input.BookingEDIExt != null)
|
|
|
{
|
|
|
//检索EDI扩展
|
|
|
var ediExt = _bookingEDIExt.FirstOrDefault(u => u.BookingId == input.Id);
|
|
|
|
|
|
if (ediExt == null)
|
|
|
{
|
|
|
//写入EDI扩展
|
|
|
ediExt = input.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
ediExt.BookingId = entity.Id;
|
|
|
|
|
|
await _bookingEDIExt.InsertAsync(ediExt);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//更新EDI扩展
|
|
|
var currEdiExtEntity = input.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
|
|
|
currEdiExtEntity.Id = ediExt.Id;
|
|
|
currEdiExtEntity.BookingId = ediExt.BookingId;
|
|
|
|
|
|
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 = mlist.GetType().GetProperty(name).GetValue(mlist, 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 = UserManager.UserId,
|
|
|
CreatedUserName = UserManager.Name
|
|
|
});
|
|
|
flag = false;
|
|
|
}
|
|
|
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
|
|
|
{
|
|
|
PId = bid,
|
|
|
Field = descriptor.Description,
|
|
|
OldValue = _oldvalue,
|
|
|
NewValue = _value,
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
var Id = entity.Id;
|
|
|
BookingOrderOutput ordOut = new BookingOrderOutput();
|
|
|
var main = await _rep.FirstOrDefaultAsync(u => u.Id == Id);
|
|
|
if (main != null)
|
|
|
{
|
|
|
ordOut = main.Adapt<BookingOrderOutput>();
|
|
|
var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == Id).ToListAsync();
|
|
|
var ctninput = ctnlist.Adapt<List<BookingCtnDto>>();
|
|
|
foreach (var item in ctninput)
|
|
|
{
|
|
|
var ctndetaillist = await _ctndetailrep.AsQueryable().Where(x => x.CTNID == item.Id).ToListAsync();
|
|
|
item.ctnDetailInputs = ctndetaillist.Adapt<List<BookingCtnDetailDto>>();
|
|
|
}
|
|
|
ordOut.ctnInputs = ctninput;
|
|
|
|
|
|
var ordUrl = _repOrderUrl.FirstOrDefault(x => x.BookingId == Id);
|
|
|
if (ordUrl != null)
|
|
|
{
|
|
|
ordOut.Link = new BookingOrderUrlOutput()
|
|
|
{
|
|
|
LinkUrlTxxp = ordUrl.UrlTxxp,
|
|
|
LinkUrlVgm = ordUrl.UrlVgm,
|
|
|
LinkUrlVmgSi = ordUrl.UrlVgmSi,
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
List<BookingOrderDto> HbList = new List<BookingOrderDto>();
|
|
|
var _hblist = await _rep.AsQueryable().Where(x => x.ParentId == Id).ToListAsync();
|
|
|
if (_hblist != null)
|
|
|
{
|
|
|
HbList = _hblist.Adapt<List<BookingOrderDto>>();
|
|
|
foreach (var item in HbList)
|
|
|
{
|
|
|
var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == item.Id).ToListAsync();
|
|
|
var ctninput = ctnlist.Adapt<List<BookingCtnDto>>();
|
|
|
foreach (var it in ctninput)
|
|
|
{
|
|
|
var ctndetaillist = await _ctndetailrep.AsQueryable().Where(x => x.CTNID == it.Id).ToListAsync();
|
|
|
it.ctnDetailInputs = ctndetaillist.Adapt<List<BookingCtnDetailDto>>();
|
|
|
}
|
|
|
item.ctnInputs = ctninput;
|
|
|
//检索EDI扩展
|
|
|
var ediExt = _bookingEDIExt.FirstOrDefault(u => u.BookingId == item.Id);
|
|
|
|
|
|
if (ediExt != null)
|
|
|
{
|
|
|
item.BookingEDIExt = ediExt.Adapt<BookingEDIExtDto>();
|
|
|
}
|
|
|
}
|
|
|
ordOut.HbList = HbList;
|
|
|
}
|
|
|
|
|
|
//检索EDI扩展
|
|
|
var ediExtEntity = _bookingEDIExt.FirstOrDefault(u => u.BookingId == Id);
|
|
|
|
|
|
if (ediExtEntity != null)
|
|
|
{
|
|
|
ordOut.BookingEDIExt = ediExtEntity.Adapt<BookingEDIExtDto>();
|
|
|
}
|
|
|
|
|
|
return ordOut;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost("/BookingOrder/AddOrUpdate")]
|
|
|
public async Task<long> AddOrUpdate(BookingOrderDto Dto)
|
|
|
{
|
|
|
if (Dto == null)
|
|
|
{
|
|
|
throw Oops.Bah("请传入正常数据!");
|
|
|
}
|
|
|
|
|
|
if (Dto.Id == 0)
|
|
|
{
|
|
|
return await Add(Dto);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
await Update(Dto);
|
|
|
return Dto.Id;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 增加订舱
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[SqlSugarUnitOfWork]
|
|
|
[HttpPost("/BookingOrder/Add")]
|
|
|
public async Task<long> Add(BookingOrderDto input)
|
|
|
{
|
|
|
JsonUtil.PropToUpper(input, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
|
|
|
var ms = JsonUtil.TrimFields(input);
|
|
|
if (!string.IsNullOrEmpty(ms))
|
|
|
{
|
|
|
throw Oops.Bah(ms);
|
|
|
}
|
|
|
if (input.ctnInputs != null)
|
|
|
{
|
|
|
var groupList = input.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
|
|
|
input.CNTRTOTAL = string.Join(" / ", groupList);
|
|
|
}
|
|
|
if (!string.IsNullOrWhiteSpace(input.MBLNO))
|
|
|
{
|
|
|
var et = await _rep.Where(x => x.MBLNO == input.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == input.HBLNO && x.ParentId == input.ParentId).FirstAsync();
|
|
|
if (et != null)
|
|
|
{
|
|
|
|
|
|
throw Oops.Bah("当前提单号已存在,请勿重复录入!");
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
var entity = input.Adapt<BookingOrder>();
|
|
|
entity.BOOKINGNO = Yitter.IdGenerator.YitIdHelper.NextId().ToString();
|
|
|
//entity.TOTALNO = NumberToUpper.ToUpper(entity.PKGS == null ? 0 : entity.PKGS);
|
|
|
await _rep.InsertAsync(entity);
|
|
|
if (input.ctnInputs != null)
|
|
|
{
|
|
|
foreach (var item in input.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 (input.BookingEDIExt != null)
|
|
|
{
|
|
|
//写入EDI扩展
|
|
|
var ediExtEntity = input.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
|
|
|
ediExtEntity.BookingId = entity.Id;
|
|
|
|
|
|
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 = UserManager.UserId,
|
|
|
CreatedUserName = UserManager.Name
|
|
|
});
|
|
|
|
|
|
//////分单不调用
|
|
|
//if (!string.IsNullOrWhiteSpace(input.YARDID) && !string.IsNullOrWhiteSpace(input.YARD) && !string.IsNullOrWhiteSpace(input.MBLNO))
|
|
|
//{
|
|
|
// await SendTrace(entity.Id.ToString(), entity.YARDID, entity.YARD, entity.MBLNO);
|
|
|
//}
|
|
|
return entity.Id;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除订舱
|
|
|
/// </summary>
|
|
|
/// <param name="Ids"></param>
|
|
|
/// <returns></returns>
|
|
|
[SqlSugarUnitOfWork]
|
|
|
[HttpPost("/BookingOrder/Delete")]
|
|
|
public async Task Delete(string Ids)
|
|
|
{
|
|
|
var arr = Ids.Split(",");
|
|
|
if (arr.Count() > 0)
|
|
|
{
|
|
|
foreach (var ar in arr)
|
|
|
{
|
|
|
long Id = Convert.ToInt64(ar);
|
|
|
var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == Id).Select(x => x.Id).ToListAsync();
|
|
|
await _repCtn.UpdateAsync(x => x.BILLID == Id, x => new BookingCtn { IsDeleted = true });
|
|
|
await _ctndetailrep.UpdateAsync(x => ctnlist.Contains((long)x.CTNID), x => new BookingCtnDetail { IsDeleted = true });
|
|
|
await _rep.UpdateAsync(x => x.Id == Id, x => new BookingOrder { IsDeleted = true });
|
|
|
_logger.LogInformation(Id + "删除成功!");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else {
|
|
|
|
|
|
throw Oops.Bah("请上传正确参数");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新订舱
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[SqlSugarUnitOfWork]
|
|
|
[HttpPost("/BookingOrder/Update")]
|
|
|
public async Task Update(BookingOrderDto input)
|
|
|
{
|
|
|
|
|
|
JsonUtil.PropToUpper(input, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
|
|
|
JsonUtil.TrimFields(input);
|
|
|
if (input.ctnInputs != null)
|
|
|
{
|
|
|
var groupList = input.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
|
|
|
input.CNTRTOTAL = string.Join(" / ", groupList);
|
|
|
}
|
|
|
var main = await _rep.AsQueryable().Filter(null, true).Where(x => x.Id == input.Id).FirstAsync();
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(input.MBLNO))
|
|
|
{
|
|
|
var et = await _rep.Where(x => x.MBLNO == input.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == input.HBLNO && x.ParentId == input.ParentId && x.Id != input.Id).FirstAsync();
|
|
|
if (et != null)
|
|
|
{
|
|
|
|
|
|
throw Oops.Bah("当前提单号已存在,请勿重复录入!");
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
var entity = input.Adapt<BookingOrder>();
|
|
|
//entity.TOTALNO = NumberToUpper.ToUpper(entity.PKGS == null ? 0 : entity.PKGS);
|
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(it => new
|
|
|
{
|
|
|
it.ParentId,
|
|
|
it.TenantId,
|
|
|
it.CreatedTime,
|
|
|
it.CreatedUserId,
|
|
|
it.CreatedUserName,
|
|
|
it.TenantName,
|
|
|
it.IsDeleted,
|
|
|
it.BOOKINGNO
|
|
|
}).ExecuteCommandAsync();
|
|
|
var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == input.Id).Select(x => x.Id).ToListAsync();
|
|
|
await _repCtn.DeleteAsync(x => x.BILLID == input.Id);
|
|
|
await _ctndetailrep.DeleteAsync(x => ctnlist.Contains((long)x.CTNID));
|
|
|
if (input.ctnInputs != null)
|
|
|
{
|
|
|
foreach (var item in input.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 (input.BookingEDIExt != null)
|
|
|
{
|
|
|
//检索EDI扩展
|
|
|
var ediExtEntity = _bookingEDIExt.FirstOrDefault(u => u.BookingId == input.Id);
|
|
|
|
|
|
if (ediExtEntity == null)
|
|
|
{
|
|
|
//写入EDI扩展
|
|
|
ediExtEntity = input.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
ediExtEntity.BookingId = entity.Id;
|
|
|
|
|
|
await _bookingEDIExt.InsertAsync(ediExtEntity);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//更新EDI扩展
|
|
|
var currEdiExtEntity = input.BookingEDIExt.Adapt<BookingEDIExt>();
|
|
|
|
|
|
currEdiExtEntity.Id = ediExtEntity.Id;
|
|
|
currEdiExtEntity.BookingId = ediExtEntity.BookingId;
|
|
|
|
|
|
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 = UserManager.UserId,
|
|
|
CreatedUserName = UserManager.Name
|
|
|
});
|
|
|
flag = false;
|
|
|
}
|
|
|
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
|
|
|
{
|
|
|
PId = bid,
|
|
|
Field = descriptor.Description,
|
|
|
OldValue = _oldvalue,
|
|
|
NewValue = _value,
|
|
|
});
|
|
|
//if (descriptor.Name == "YARDID" || descriptor.Name == "YARD" || descriptor.Name == "MBLNO")
|
|
|
//{
|
|
|
// if (!string.IsNullOrWhiteSpace(input.YARDID) && !string.IsNullOrWhiteSpace(input.YARD) && !string.IsNullOrWhiteSpace(input.MBLNO))
|
|
|
// {
|
|
|
// await SendTrace(entity.Id.ToString(), entity.YARDID, entity.YARD, entity.MBLNO);
|
|
|
// }
|
|
|
//}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取订舱明细
|
|
|
/// </summary>
|
|
|
/// <param name="Id"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/Get")]
|
|
|
public async Task<BookingOrderOutput> Get(long Id)
|
|
|
{
|
|
|
BookingOrderOutput ordOut = new BookingOrderOutput();
|
|
|
var main = await _rep.FirstOrDefaultAsync(u => u.Id == Id);
|
|
|
if (main != null)
|
|
|
{
|
|
|
ordOut = main.Adapt<BookingOrderOutput>();
|
|
|
var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == Id).ToListAsync();
|
|
|
var ctninput = ctnlist.Adapt<List<BookingCtnDto>>();
|
|
|
foreach (var item in ctninput)
|
|
|
{
|
|
|
var ctndetaillist = await _ctndetailrep.AsQueryable().Where(x => x.CTNID == item.Id).ToListAsync();
|
|
|
item.ctnDetailInputs = ctndetaillist.Adapt<List<BookingCtnDetailDto>>();
|
|
|
}
|
|
|
ordOut.ctnInputs = ctninput;
|
|
|
|
|
|
var ordUrl = _repOrderUrl.FirstOrDefault(x => x.BookingId == Id);
|
|
|
if (ordUrl != null)
|
|
|
{
|
|
|
ordOut.Link = new BookingOrderUrlOutput()
|
|
|
{
|
|
|
LinkUrlTxxp = ordUrl.UrlTxxp,
|
|
|
LinkUrlVgm = ordUrl.UrlVgm,
|
|
|
LinkUrlVmgSi = ordUrl.UrlVgmSi,
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
List<BookingOrderDto> HbList = new List<BookingOrderDto>();
|
|
|
var _hblist = await _rep.AsQueryable().Where(x => x.ParentId == Id).ToListAsync();
|
|
|
if (_hblist != null)
|
|
|
{
|
|
|
HbList = _hblist.Adapt<List<BookingOrderDto>>();
|
|
|
foreach (var item in HbList)
|
|
|
{
|
|
|
var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == item.Id).ToListAsync();
|
|
|
var ctninput = ctnlist.Adapt<List<BookingCtnDto>>();
|
|
|
foreach (var it in ctninput)
|
|
|
{
|
|
|
var ctndetaillist = await _ctndetailrep.AsQueryable().Where(x => x.CTNID == it.Id).ToListAsync();
|
|
|
it.ctnDetailInputs = ctndetaillist.Adapt<List<BookingCtnDetailDto>>();
|
|
|
}
|
|
|
item.ctnInputs = ctninput;
|
|
|
//检索EDI扩展
|
|
|
var ediExt = _bookingEDIExt.FirstOrDefault(u => u.BookingId == item.Id);
|
|
|
|
|
|
if (ediExt != null)
|
|
|
{
|
|
|
item.BookingEDIExt = ediExt.Adapt<BookingEDIExtDto>();
|
|
|
}
|
|
|
}
|
|
|
ordOut.HbList = HbList;
|
|
|
}
|
|
|
|
|
|
//检索EDI扩展
|
|
|
var ediExtEntity = _bookingEDIExt.FirstOrDefault(u => u.BookingId == Id);
|
|
|
|
|
|
if (ediExtEntity != null)
|
|
|
{
|
|
|
ordOut.BookingEDIExt = ediExtEntity.Adapt<BookingEDIExtDto>();
|
|
|
}
|
|
|
|
|
|
return ordOut;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 批量编辑
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/BookingOrder/BachUpdate")]
|
|
|
public async Task BachUpdate(BatchUpdate dto)
|
|
|
{
|
|
|
if (dto == null || dto.Id.Count == 0)
|
|
|
{
|
|
|
throw Oops.Bah("未提交数据");
|
|
|
}
|
|
|
await _rep.UpdateAsync(x => dto.Id.Contains(x.Id), x => new BookingOrder
|
|
|
{
|
|
|
VESSEL = dto.VESSEL,
|
|
|
VOYNOINNER = dto.VOYNOINNER,
|
|
|
ETD = dto.ETD,
|
|
|
VOYNO = dto.VOYNO,
|
|
|
PORTDISCHARGEID = dto.PORTDISCHARGEID,
|
|
|
PORTDISCHARGE = dto.PORTDISCHARGE,
|
|
|
DESTINATIONID = dto.DESTINATIONID,
|
|
|
DESTINATION = dto.DESTINATION,
|
|
|
CLOSINGDATE = dto.CLOSINGDATE,
|
|
|
CLOSEDOCDATE = dto.CLOSEDOCDATE
|
|
|
});
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 日志、备注、附件、货运动态、服务项目、货物状态 等
|
|
|
/// <summary>
|
|
|
/// 获取日志明细
|
|
|
/// </summary>
|
|
|
/// <param name="Id"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/GetLog")]
|
|
|
public async Task<List<BookingLogDto>> GetLog(long Id)
|
|
|
{
|
|
|
List<BookingLogDto> list = new List<BookingLogDto>();
|
|
|
var main = await _bookinglog.AsQueryable().Where(u => u.BookingId == Id).ToListAsync();
|
|
|
list = main.Adapt<List<BookingLogDto>>();
|
|
|
if (list != null)
|
|
|
{
|
|
|
foreach (var item in list)
|
|
|
{
|
|
|
var details = await _bookinglogdetail.AsQueryable().Where(x => x.PId == item.Id).ToListAsync();
|
|
|
item.details = details;
|
|
|
}
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取备注
|
|
|
/// </summary>
|
|
|
/// <param name="Id"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/GetRemark")]
|
|
|
public async Task<List<BookingRemark>> GetRemark(long Id)
|
|
|
{
|
|
|
var list = await _bookingremark.AsQueryable().Where(u => u.PId == Id).ToListAsync();
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 增加备注
|
|
|
/// </summary>
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
|
[SqlSugarUnitOfWork]
|
|
|
[HttpPost("/BookingOrder/AddRemark")]
|
|
|
public async Task AddRemark(BookingRemarkDto dto)
|
|
|
{
|
|
|
if (dto.Id == 0)
|
|
|
{
|
|
|
var entity = dto.Adapt<BookingRemark>();
|
|
|
entity.UpdatedUserId = UserManager.UserId;
|
|
|
entity.UpdatedUserName = UserManager.Name;
|
|
|
await _bookingremark.InsertAsync(entity);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var entity = _bookingremark.FirstOrDefault(x => x.Id == dto.Id);
|
|
|
entity.Remark = dto.Remark;
|
|
|
await _bookingremark.AsUpdateable(entity).IgnoreColumns(it => new
|
|
|
{
|
|
|
|
|
|
it.TenantId,
|
|
|
it.CreatedTime,
|
|
|
it.CreatedUserId,
|
|
|
it.CreatedUserName
|
|
|
}).ExecuteCommandAsync();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除备注
|
|
|
/// </summary>
|
|
|
/// <param name="Id"></param>
|
|
|
/// <returns></returns>
|
|
|
[SqlSugarUnitOfWork]
|
|
|
[HttpPost("/BookingOrder/DeleteRemark")]
|
|
|
public async Task DeleteRemark(long Id)
|
|
|
{
|
|
|
|
|
|
await _bookingremark.DeleteAsync(x => x.Id == Id);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 增加订舱附件
|
|
|
/// </summary>
|
|
|
/// <param name="file"></param>
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/BookingOrder/AddFile")]
|
|
|
public async Task AddFile(IFormFile file, [FromForm] BookingFileDto dto)
|
|
|
{
|
|
|
//未上传文件
|
|
|
if (file == null || file.Length == 0)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK200);
|
|
|
}
|
|
|
|
|
|
var opt = App.GetOptions<BookingAttachOptions>();
|
|
|
var originalFilename = file.FileName; // 文件原始名称
|
|
|
var fileSuffix = Path.GetExtension(file.FileName).ToLower(); // 文件后缀
|
|
|
if (!opt.fileType.Contains(fileSuffix))
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK114);
|
|
|
}
|
|
|
|
|
|
var dirAbs = string.Empty;
|
|
|
if (string.IsNullOrEmpty(opt.basePath))
|
|
|
{
|
|
|
dirAbs = Path.Combine(App.WebHostEnvironment.WebRootPath, opt.relativePath);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dirAbs = Path.Combine(opt.basePath, opt.relativePath);
|
|
|
}
|
|
|
|
|
|
if (!Directory.Exists(dirAbs))
|
|
|
Directory.CreateDirectory(dirAbs);
|
|
|
|
|
|
|
|
|
// 先存库获取Id
|
|
|
var id = YitIdHelper.NextId();
|
|
|
var fileSaveName = $"{id}{fileSuffix}".ToLower();
|
|
|
var fileRelaPath = Path.Combine(opt.relativePath, fileSaveName).ToLower();
|
|
|
var fileAbsPath = Path.Combine(dirAbs, fileSaveName).ToLower();
|
|
|
var newFile = new BookingFile
|
|
|
{
|
|
|
Id = id,
|
|
|
FileName = originalFilename,
|
|
|
FilePath = fileRelaPath,
|
|
|
TypeCode = dto.TypeCode,
|
|
|
TypeName = dto.TypeName,
|
|
|
BookingId = dto.BookingId,
|
|
|
|
|
|
};
|
|
|
await _bookingfile.InsertAsync(newFile);
|
|
|
using (var stream = File.Create(fileAbsPath))
|
|
|
{
|
|
|
await file.CopyToAsync(stream);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取附件
|
|
|
/// </summary>
|
|
|
/// <param name="Id"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/GetFile")]
|
|
|
public async Task<List<BookingFile>> GetFile(long Id)
|
|
|
{
|
|
|
var list = await _bookingfile.AsQueryable().Filter(null, true).Where(u => u.BookingId == Id).ToListAsync();
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取货运动态
|
|
|
/// </summary>
|
|
|
[HttpGet("/BookingOrder/GetStatusLog")]
|
|
|
public async Task<List<BookingStatusLogDto>> GetBookingStatusLog(long Id)
|
|
|
{
|
|
|
|
|
|
var statuslog = await _repStatuslog.AsQueryable().Filter(null, true).Where(x => x.BookingId == Id).OrderByDescending(x => x.OpTime).ToListAsync();
|
|
|
var dto = statuslog.Adapt<List<BookingStatusLogDto>>();
|
|
|
foreach (var item in dto)
|
|
|
{
|
|
|
var detail = await _statuslogdetail.AsQueryable().Where(x => x.PId == item.Id).ToListAsync();
|
|
|
item.detail = detail.Adapt<List<BookingStatusLogDetailDto>>();
|
|
|
}
|
|
|
|
|
|
return dto;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取订舱动态
|
|
|
/// </summary>
|
|
|
[HttpGet("/BookingOrder/GetStatus")]
|
|
|
public async Task<List<BookingStatus>> GetBookingStatus(long Id)
|
|
|
{
|
|
|
|
|
|
var dto = await _repBookingStatus.AsQueryable().Where(x => x.BookingId == Id).ToListAsync();
|
|
|
return dto;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 保存服务项目
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/BookingOrder/SaveServiceItem")]
|
|
|
[SqlSugarUnitOfWork]
|
|
|
public async Task SaveServiceItem(BookingServiceItemList input)
|
|
|
{
|
|
|
if (input.BookingId == null || input.BookingId == 0)
|
|
|
{
|
|
|
|
|
|
throw Oops.Bah("未传入业务id");
|
|
|
}
|
|
|
await _serviceItem.DeleteAsync(x => x.BookingId == input.BookingId);
|
|
|
foreach (var item in input.item)
|
|
|
{
|
|
|
await _serviceItem.InsertAsync(
|
|
|
new BookingServiceItem
|
|
|
{
|
|
|
BookingId = input.BookingId,
|
|
|
Code = item.Code,
|
|
|
Value = item.Value
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获取服务项目
|
|
|
/// </summary>
|
|
|
/// <param name="bookingId"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/GetServiceItemList")]
|
|
|
public async Task<dynamic> GetServiceItemList(long bookingId)
|
|
|
{
|
|
|
|
|
|
return await _serviceItem.AsQueryable().Where(x => x.BookingId == bookingId).ToListAsync();
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 增加货物状态
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[SqlSugarUnitOfWork]
|
|
|
[HttpPost("/BookingOrder/SaveGoodsStatus")]
|
|
|
public async Task SaveGoodsStatus(GoodsStatusDtoList input)
|
|
|
{
|
|
|
if (input.BookingId == null || input.BookingId == 0)
|
|
|
{
|
|
|
|
|
|
throw Oops.Bah("未传入业务id");
|
|
|
}
|
|
|
await _goodsStatus.DeleteAsync(x => x.bookingId == input.BookingId);
|
|
|
foreach (var item in input.item)
|
|
|
{
|
|
|
var entity = item.Adapt<BookingGoodsStatus>();
|
|
|
await _goodsStatus.InsertAsync(entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获取货物状态
|
|
|
/// </summary>
|
|
|
/// <param name="bookingId"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/GetGoodsStatusList")]
|
|
|
public async Task<dynamic> GetGoodsStatusList(long bookingId)
|
|
|
{
|
|
|
|
|
|
return await _goodsStatus.AsQueryable().Where(x => x.bookingId == bookingId).ToListAsync();
|
|
|
}
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 运踪
|
|
|
/// <summary>
|
|
|
/// 调用运踪接口
|
|
|
/// </summary>
|
|
|
[HttpPost("/BookingOrder/SendTrace")]
|
|
|
[SqlSugarUnitOfWork]
|
|
|
public async Task SendTrace(List<BillTraceList> dto)
|
|
|
{
|
|
|
if (dto == null)
|
|
|
{
|
|
|
throw Oops.Bah("未传入正确参数!");
|
|
|
}
|
|
|
var key = _webAccountConfig.GetAccountConfig("seae_billtraceurl", UserManager.UserId).Result;
|
|
|
if (key == null)
|
|
|
{
|
|
|
throw Oops.Bah("调用运踪接口相关账号未维护!");
|
|
|
}
|
|
|
var url = _cache.GetAllDictData().Result;
|
|
|
BillTraceDto billdto = new BillTraceDto();
|
|
|
List<BillTraceList> billTraceList = new List<BillTraceList>();
|
|
|
var dicdatalist = _cache.GetAllDictData().Result;
|
|
|
foreach (var item in dto)
|
|
|
{
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.CARRIERID))
|
|
|
{
|
|
|
var et = _repBookingStatus.AsQueryable().Where(x => x.StaCode == "sta_mudigang" && x.BookingId == Convert.ToInt64(item.BusinessId)).FirstAsync().Result;
|
|
|
if (et != null)
|
|
|
{
|
|
|
throw Oops.Bah("提单号" + item.MBLNO + "已订阅!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.YardCode))
|
|
|
{
|
|
|
var et = _repBookingStatus.AsQueryable().Where(x => x.StaCode == "sta_qiyungang" && x.BookingId == Convert.ToInt64(item.BusinessId)).FirstAsync().Result;
|
|
|
if (et != null)
|
|
|
{
|
|
|
throw Oops.Bah("提单号" + item.MBLNO + "已订阅!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
_logger.LogInformation("调用运踪接口提单号:" + item.MBLNO + " 调用运踪接口");
|
|
|
if (item.isBook && (string.IsNullOrWhiteSpace(item.CARRIERID) || string.IsNullOrWhiteSpace(item.CARRIER) || string.IsNullOrWhiteSpace(item.MBLNO)))
|
|
|
{
|
|
|
throw Oops.Bah("订阅目的港船公司或提单号不能为空!");
|
|
|
}
|
|
|
billTraceList.Add(new BillTraceList
|
|
|
{
|
|
|
BusinessId = item.BusinessId,
|
|
|
MBLNO = item.MBLNO,
|
|
|
YARD = item.YARD == "" ? null : item.YARD,
|
|
|
YardCode = item.YardCode == "" ? null : item.YardCode,
|
|
|
CARRIER = item.CARRIER == "" ? null : item.CARRIER,
|
|
|
CARRIERID = item.CARRIERID == "" ? null : item.CARRIERID,
|
|
|
isBook = item.isBook
|
|
|
});
|
|
|
//var bookingStatusLog = new BookingStatusLog();
|
|
|
//bookingStatusLog.BookingId = Convert.ToInt64(item.BusinessId);
|
|
|
//bookingStatusLog.Category = "dingyue";
|
|
|
//bookingStatusLog.CreatedTime = DateTime.Now;
|
|
|
var status = string.Empty;
|
|
|
if (string.IsNullOrWhiteSpace(item.YardCode) && !string.IsNullOrWhiteSpace(item.CARRIERID))
|
|
|
{
|
|
|
status = "订阅目的港";
|
|
|
}
|
|
|
if (!string.IsNullOrWhiteSpace(item.YardCode) && string.IsNullOrWhiteSpace(item.CARRIERID))
|
|
|
{
|
|
|
status = "订阅起运港";
|
|
|
}
|
|
|
if (!string.IsNullOrWhiteSpace(item.YardCode) && !string.IsNullOrWhiteSpace(item.CARRIERID))
|
|
|
{
|
|
|
status = "订阅起运港,目的港";
|
|
|
}
|
|
|
//bookingStatusLog.OpTime = DateTime.Now;
|
|
|
//bookingStatusLog.MBLNO = item.MBLNO;
|
|
|
//await _repStatuslog.InsertAsync(bookingStatusLog);
|
|
|
|
|
|
////添加booking日志
|
|
|
var bid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog
|
|
|
{
|
|
|
Type = "Trace",
|
|
|
BookingId = Convert.ToInt64(item.BusinessId),
|
|
|
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
|
|
|
CreatedTime = DateTime.Now,
|
|
|
CreatedUserId = UserManager.UserId,
|
|
|
CreatedUserName = UserManager.Name
|
|
|
});
|
|
|
|
|
|
|
|
|
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
|
|
|
{
|
|
|
PId = bid,
|
|
|
Field = "",
|
|
|
OldValue = "",
|
|
|
NewValue = status,
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.CARRIERID))
|
|
|
{
|
|
|
BookingStatus bookingStatus = new BookingStatus();
|
|
|
bookingStatus.BookingId = Convert.ToInt64(item.BusinessId);
|
|
|
bookingStatus.StaCode = "sta_mudigang";
|
|
|
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_mudigang").Select(x => x.Value).FirstOrDefault();
|
|
|
bookingStatus.StaTime = DateTime.Now;
|
|
|
bookingStatus.StaCate = "book_sta_cate_billtrace";
|
|
|
await _repBookingStatus.InsertAsync(bookingStatus);
|
|
|
}
|
|
|
if (!string.IsNullOrWhiteSpace(item.YardCode))
|
|
|
{
|
|
|
BookingStatus bookingStatus = new BookingStatus();
|
|
|
bookingStatus.BookingId = Convert.ToInt64(item.BusinessId);
|
|
|
bookingStatus.StaCode = "sta_qiyungang";
|
|
|
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_qiyungang").Select(x => x.Value).FirstOrDefault();
|
|
|
bookingStatus.StaTime = DateTime.Now;
|
|
|
bookingStatus.StaCate = "book_sta_cate_billtrace";
|
|
|
await _repBookingStatus.InsertAsync(bookingStatus);
|
|
|
}
|
|
|
}
|
|
|
billdto.Children = billTraceList;
|
|
|
billdto.Key = key.Account;
|
|
|
billdto.PWD = key.Password;
|
|
|
billdto.url = url.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "response_seae_billtraceurl").Value;
|
|
|
billdto.Gid = UserManager.DjyUserId;
|
|
|
var json = billdto.ToJsonString();
|
|
|
_logger.LogInformation("调用运踪接口发送josn:" + json);
|
|
|
var html = await url.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "request_seae_billtraceurl").Value.SetHttpMethod(HttpMethod.Post).SetQueries(new { msg = json }).SetRetryPolicy(3, 5000).SendAsAsync<RespCommon>();
|
|
|
_logger.LogInformation("调用运踪接口返回" + html.ToJsonString());
|
|
|
if (html.Success != true)
|
|
|
{
|
|
|
_logger.LogError("调用运踪接口返回:" + html.ToJsonString());
|
|
|
throw Oops.Bah(html.Message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 插入货运动态
|
|
|
/// </summary>
|
|
|
[AllowAnonymous]
|
|
|
[SqlSugarUnitOfWork]
|
|
|
[HttpPost("/BookingOrder/AddBookingStatusLog")]
|
|
|
public async Task AddBookingStatusLog(List<BookingStatusLogDto> all)
|
|
|
{
|
|
|
//清空原有数据
|
|
|
var old = await _repStatuslog.AsQueryable().Where(x => x.BookingId == all[0].BookingId && x.Category == "yunzong").ToListAsync();
|
|
|
await _repStatuslog.DeleteAsync(x => x.BookingId == all[0].BookingId && x.Category == "yunzong");
|
|
|
foreach (var ot in old)
|
|
|
{
|
|
|
await _statuslogdetail.DeleteAsync(x => x.PId == ot.Id);
|
|
|
}
|
|
|
var dicdatalist = _cache.GetAllDictData().Result;
|
|
|
foreach (var item in all)
|
|
|
{
|
|
|
#region 日志
|
|
|
//新增数据
|
|
|
var bookingStatusLog = new BookingStatusLog();
|
|
|
bookingStatusLog.BookingId = item.BookingId;
|
|
|
bookingStatusLog.Category = "yunzong";
|
|
|
bookingStatusLog.CreatedTime = DateTime.Now;
|
|
|
bookingStatusLog.Status = item.Status;
|
|
|
bookingStatusLog.OpTime = item.OpTime;
|
|
|
bookingStatusLog.MBLNO = item.MBLNO;
|
|
|
await _repStatuslog.InsertAsync(bookingStatusLog);
|
|
|
var list = await _repBookingStatus.AsQueryable().InnerJoin<SysDictData>((d, t) => d.StaCode == t.Code && d.StaCate == "book_sta_cate_billtrace" && d.BookingId == item.BookingId).Select((d, t) => new
|
|
|
{
|
|
|
BookingId = d.BookingId,
|
|
|
StaCode = d.StaCode,
|
|
|
StaName = d.StaName,
|
|
|
StaTime = d.StaTime,
|
|
|
Code = t.Code,
|
|
|
Value = t.Value
|
|
|
}).ToListAsync();
|
|
|
|
|
|
if (item.detail != null && item.detail.Count > 0)
|
|
|
{
|
|
|
foreach (var dt in item.detail)
|
|
|
{
|
|
|
var BookingStatusLogDetail = new BookingStatusLogDetail();
|
|
|
BookingStatusLogDetail.PId = bookingStatusLog.Id;
|
|
|
BookingStatusLogDetail.Status = dt.Status;
|
|
|
BookingStatusLogDetail.CNTRNO = dt.CNTRNO;
|
|
|
BookingStatusLogDetail.OPTime = dt.OPTime;
|
|
|
await _statuslogdetail.InsertAsync(BookingStatusLogDetail);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 订舱状态
|
|
|
if (item.Status == "舱单")
|
|
|
{
|
|
|
if (list.Where(x => x.Code == "sta_cangdan").FirstOrDefault() == null)
|
|
|
{
|
|
|
BookingStatus bookingStatus = new BookingStatus();
|
|
|
bookingStatus.BookingId = item.BookingId;
|
|
|
bookingStatus.StaCode = "sta_cangdan";
|
|
|
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_cangdan").Select(x => x.Value).FirstOrDefault();
|
|
|
bookingStatus.StaTime = item.OpTime;
|
|
|
bookingStatus.StaCate = "book_sta_cate_billtrace";
|
|
|
await _repBookingStatus.InsertAsync(bookingStatus);
|
|
|
}
|
|
|
}
|
|
|
if (item.Status == "报关")
|
|
|
{
|
|
|
if (list.Where(x => x.Code == "sta_haifang").FirstOrDefault() == null)
|
|
|
{
|
|
|
BookingStatus bookingStatus = new BookingStatus();
|
|
|
bookingStatus.BookingId = item.BookingId;
|
|
|
bookingStatus.StaCode = "sta_haifang";
|
|
|
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_haifang").Select(x => x.Value).FirstOrDefault();
|
|
|
bookingStatus.StaTime = item.OpTime;
|
|
|
bookingStatus.StaCate = "book_sta_cate_billtrace";
|
|
|
await _repBookingStatus.InsertAsync(bookingStatus);
|
|
|
}
|
|
|
}
|
|
|
if (item.Status == "装载")
|
|
|
{
|
|
|
if (list.Where(x => x.Code == "sta_zhuangzai").FirstOrDefault() == null)
|
|
|
{
|
|
|
BookingStatus bookingStatus = new BookingStatus();
|
|
|
bookingStatus.BookingId = item.BookingId;
|
|
|
bookingStatus.StaCode = "sta_zhuangzai";
|
|
|
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_zhuangzai").Select(x => x.Value).FirstOrDefault();
|
|
|
bookingStatus.StaTime = item.OpTime;
|
|
|
bookingStatus.StaCate = "book_sta_cate_billtrace";
|
|
|
await _repBookingStatus.InsertAsync(bookingStatus);
|
|
|
}
|
|
|
}
|
|
|
if (item.Status == "码放")
|
|
|
{
|
|
|
if (list.Where(x => x.Code == "sta_mafang").FirstOrDefault() == null)
|
|
|
{
|
|
|
BookingStatus bookingStatus = new BookingStatus();
|
|
|
bookingStatus.BookingId = item.BookingId;
|
|
|
bookingStatus.StaCode = "sta_mafang";
|
|
|
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_mafang").Select(x => x.Value).FirstOrDefault();
|
|
|
bookingStatus.StaTime = item.OpTime;
|
|
|
bookingStatus.StaCate = "book_sta_cate_billtrace";
|
|
|
await _repBookingStatus.InsertAsync(bookingStatus);
|
|
|
}
|
|
|
}
|
|
|
if (item.Status == "装船")
|
|
|
{
|
|
|
if (list.Where(x => x.Code == "sta_zhuangchuan").FirstOrDefault() == null)
|
|
|
{
|
|
|
BookingStatus bookingStatus = new BookingStatus();
|
|
|
bookingStatus.BookingId = item.BookingId;
|
|
|
bookingStatus.StaCode = "sta_zhuangchuan";
|
|
|
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_zhuangchuan").Select(x => x.Value).FirstOrDefault();
|
|
|
bookingStatus.StaTime = item.detail.Max(x => x.OPTime);
|
|
|
bookingStatus.StaCate = "book_sta_cate_billtrace";
|
|
|
await _repBookingStatus.InsertAsync(bookingStatus);
|
|
|
}
|
|
|
}
|
|
|
if (item.Status == "ATD")
|
|
|
{
|
|
|
if (list.Where(x => x.Code == "sta_atd").FirstOrDefault() == null)
|
|
|
{
|
|
|
BookingStatus bookingStatus = new BookingStatus();
|
|
|
bookingStatus.BookingId = item.BookingId;
|
|
|
bookingStatus.StaCode = "sta_atd";
|
|
|
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_atd").Select(x => x.Value).FirstOrDefault();
|
|
|
bookingStatus.StaTime = item.OpTime;
|
|
|
bookingStatus.StaCate = "book_sta_cate_billtrace";
|
|
|
await _repBookingStatus.InsertAsync(bookingStatus);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region ATD
|
|
|
if (item.Status == "ATD")
|
|
|
{
|
|
|
var o = _rep.AsQueryable().Filter(null, true).Where(x => x.Id == item.BookingId).FirstAsync().Result;
|
|
|
var oldatd = o.ATD;
|
|
|
if (oldatd != item.OpTime)
|
|
|
{
|
|
|
o.ATD = item.OpTime;
|
|
|
await _rep.UpdateAsync(o);
|
|
|
////添加booking日志
|
|
|
var bid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog
|
|
|
{
|
|
|
Type = "Edit",
|
|
|
BookingId = item.BookingId,
|
|
|
TenantId = o.TenantId,
|
|
|
CreatedTime = DateTime.Now,
|
|
|
CreatedUserId = o.CreatedUserId,
|
|
|
CreatedUserName = "系统管理员"
|
|
|
});
|
|
|
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
|
|
|
{
|
|
|
PId = bid,
|
|
|
Field = "实际开船",
|
|
|
OldValue = oldatd == null ? "" : oldatd.ToString(),
|
|
|
NewValue = item.OpTime == null ? "" : item.OpTime.ToString(),
|
|
|
});
|
|
|
}
|
|
|
if (!string.IsNullOrWhiteSpace(o.VESSEL) && !string.IsNullOrWhiteSpace(o.VOYNO))
|
|
|
{
|
|
|
var order = await _rep.AsQueryable().Where(x => x.VOYNO == o.VOYNO && x.VESSEL == o.VESSEL && x.TenantId == o.TenantId).ToListAsync();
|
|
|
foreach (var it in order)
|
|
|
{
|
|
|
var _oldatd = it.ATD;
|
|
|
if (_oldatd != item.OpTime)
|
|
|
{
|
|
|
it.ATD = item.OpTime;
|
|
|
await _rep.UpdateAsync(it);
|
|
|
////添加booking日志
|
|
|
var _bid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog
|
|
|
{
|
|
|
Type = "Edit",
|
|
|
BookingId = it.Id,
|
|
|
TenantId = it.TenantId,
|
|
|
CreatedTime = DateTime.Now,
|
|
|
CreatedUserId = o.CreatedUserId,
|
|
|
CreatedUserName = "系统管理员"
|
|
|
});
|
|
|
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
|
|
|
{
|
|
|
PId = _bid,
|
|
|
Field = "实际开船",
|
|
|
OldValue = _oldatd == null ? "" : _oldatd.ToString(),
|
|
|
NewValue = item.OpTime == null ? "" : item.OpTime.ToString(),
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 放舱(入货通知)
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取放舱信息
|
|
|
/// </summary>
|
|
|
/// <param name="bookingId"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/LetterYard")]
|
|
|
public async Task<UpdateBookingLetteryardOutput> LetterYard(long bookingId)
|
|
|
{
|
|
|
var order = _rep.FirstOrDefault(x => x.Id == bookingId);
|
|
|
if (order == null)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK001);
|
|
|
}
|
|
|
|
|
|
var letterYard = await _repLetterYard.FirstOrDefaultAsync(x => x.BookingId == bookingId);
|
|
|
if (letterYard == null)
|
|
|
{
|
|
|
var user = _repUser.FirstOrDefault(x => x.Id == UserManager.UserId);
|
|
|
letterYard = new BookingLetteryard()
|
|
|
{
|
|
|
BookingId = bookingId,
|
|
|
Description = order.DESCRIPTION,
|
|
|
FromName = user.Name,
|
|
|
FromTel = user.Tel,
|
|
|
FromMail = user.Email,
|
|
|
YARDID = order.YARDID,
|
|
|
YARD = order.YARD,
|
|
|
YARDCONTRACT = order.YARDCONTRACT,
|
|
|
YARDCONTRACTTEL = order.YARDCONTRACTTEL,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
var output = letterYard.Adapt<UpdateBookingLetteryardOutput>();
|
|
|
|
|
|
//链接信息
|
|
|
var urlModel = _repOrderUrl.FirstOrDefault(x => x.BookingId == bookingId);
|
|
|
if (urlModel != null)
|
|
|
{
|
|
|
output.OrderUrl = urlModel.Adapt<BookingOrderUrlLetterYardOutput>();
|
|
|
}
|
|
|
|
|
|
return output;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 保存(新增或修改)放舱
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/BookingLetteryard/Save")]
|
|
|
public async Task<long> LetteryardSave(UpdateBookingLetteryardInput input)
|
|
|
{
|
|
|
long rtnId = 0;
|
|
|
if (input.Id == 0)
|
|
|
{
|
|
|
var entity = input.Adapt<BookingLetteryard>();
|
|
|
await _repLetterYard.InsertAsync(entity);
|
|
|
rtnId = entity.Id;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var entity = _repLetterYard.AsQueryable().Filter(null, true).First(x => x.Id == input.Id);
|
|
|
input.Adapt(entity);
|
|
|
await _repLetterYard.UpdateAsync(entity);
|
|
|
rtnId = entity.Id;
|
|
|
}
|
|
|
|
|
|
var order = _rep.FirstOrDefault(x => x.Id == input.BookingId);
|
|
|
|
|
|
//生成提箱小票
|
|
|
var allowCarrier = _cache.GetAllDictData().Result.Where(x => x.TypeCode == "txxp_carrier_list").Select(x => x.Code).ToList();
|
|
|
if (allowCarrier.Contains(order.CARRIERID))
|
|
|
{
|
|
|
var txxpLink = await TxxpLink(input.BookingId);
|
|
|
}
|
|
|
|
|
|
//vgm链接
|
|
|
allowCarrier = _cache.GetAllDictData().Result.Where(x => x.TypeCode == "vgm_carrier_list").Select(x => x.Code).ToList();
|
|
|
if (allowCarrier.Contains(order.CARRIERID))
|
|
|
{
|
|
|
await VgmLink(input.BookingId);
|
|
|
}
|
|
|
|
|
|
return rtnId;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除放舱
|
|
|
/// </summary>
|
|
|
/// <param name="Id"></param>
|
|
|
/// <returns></returns>
|
|
|
[SqlSugarUnitOfWork]
|
|
|
[HttpPost("/BookingLetteryard/LetterYardDelete")]
|
|
|
public async Task LetterYardDelete(long Id)
|
|
|
{
|
|
|
await _repLetterYard.DeleteAsync(x => x.BookingId == Id);
|
|
|
_logger.LogInformation(Id + "放舱删除成功!");
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 放舱发送
|
|
|
/// </summary>
|
|
|
/// <param name="bookingId"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/BookingLetteryard/SendLetterYard")]
|
|
|
public async Task SendLetterYard(long bookingId)
|
|
|
{
|
|
|
var order = _rep.FirstOrDefault(x => x.Id == bookingId);
|
|
|
var user = await _repUser.FirstOrDefaultAsync(u => u.Id == order.CreatedUserId);
|
|
|
var tenant = await _repTenant.FirstOrDefaultAsync(t => t.Id == order.TenantId);
|
|
|
|
|
|
var letterYard = await _repLetterYard.FirstOrDefaultAsync(x => x.BookingId == bookingId);
|
|
|
if (letterYard == null)
|
|
|
{
|
|
|
throw Oops.Bah("放舱信息未找到,请先保存数据");
|
|
|
}
|
|
|
|
|
|
var mailAcc = await _repUserMail.FirstOrDefaultAsync(x => x.CreatedUserId == user.Id && x.SmtpPort > 0 && x.SmtpServer != null && x.SmtpServer != "");
|
|
|
if (mailAcc == null)
|
|
|
{
|
|
|
throw Oops.Bah("用户邮箱未设置或smtp未正确配置");
|
|
|
}
|
|
|
|
|
|
var orderUrl = await _repOrderUrl.FirstOrDefaultAsync(u => u.BookingId == bookingId);
|
|
|
if (orderUrl == null)
|
|
|
{
|
|
|
throw Oops.Bah("未生成链接信息,请重新保存数据");
|
|
|
}
|
|
|
|
|
|
if (string.IsNullOrEmpty(letterYard.AttnMail))
|
|
|
{
|
|
|
throw Oops.Bah("ATTN MAIL未正确填写");
|
|
|
}
|
|
|
|
|
|
#region 保存放舱文件,并挂载到订舱附件
|
|
|
var fileBytes = await GetReportFile(bookingId, "fangcang");
|
|
|
var opt = App.GetOptions<BookingAttachOptions>();
|
|
|
var fileSaveName = $"放舱_{order.MBLNO}_{DateTime.Now.Ticks}.pdf"; // 文件原始名称
|
|
|
var dirAbs = string.Empty;
|
|
|
if (string.IsNullOrEmpty(opt.basePath))
|
|
|
{
|
|
|
dirAbs = Path.Combine(App.WebHostEnvironment.WebRootPath, opt.relativePath);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dirAbs = Path.Combine(opt.basePath, opt.relativePath);
|
|
|
}
|
|
|
|
|
|
if (!Directory.Exists(dirAbs))
|
|
|
Directory.CreateDirectory(dirAbs);
|
|
|
|
|
|
var fileRelaPath = Path.Combine(opt.relativePath, fileSaveName).ToLower();
|
|
|
var fileAbsPath = Path.Combine(dirAbs, fileSaveName).ToLower();
|
|
|
|
|
|
File.WriteAllBytes(fileAbsPath, fileBytes);
|
|
|
|
|
|
var newFile = new BookingFile
|
|
|
{
|
|
|
FileName = fileSaveName,
|
|
|
FilePath = fileRelaPath,
|
|
|
TypeCode = "ruhuotongzhi",
|
|
|
TypeName = ".pdf",
|
|
|
|
|
|
};
|
|
|
await _bookingfile.InsertAsync(newFile);
|
|
|
#endregion
|
|
|
|
|
|
//货运动态
|
|
|
var bsl = new BookingStatusLog();
|
|
|
bsl.BookingId = bookingId;
|
|
|
bsl.Status = $"放舱给客户";
|
|
|
bsl.OpTime = DateTime.Now;
|
|
|
bsl.Category = "ship";
|
|
|
bsl.MBLNO = order.MBLNO;
|
|
|
await _repStatuslog.InsertAsync(bsl);
|
|
|
|
|
|
//订舱状态
|
|
|
await SaveBookingStatus(bookingId, "sta_letter_yard", "放舱");
|
|
|
|
|
|
#region 发送邮件
|
|
|
|
|
|
var mailSubject = $"放舱信息:{order.MBLNO}/{order.CARRIERID}/{order.VESSEL}/{order.VOYNO}/PO:{order.PONO}/{order.TenantName}";
|
|
|
|
|
|
var extContent = string.Empty;
|
|
|
if (order.CARGOID == "R") //冻柜
|
|
|
{
|
|
|
extContent = $"温度:{order.TEMPSET}{order.TEMPID} <br/>通风:{order.REEFERF} <br/>湿度:{order.HUMIDITY}<br/>";
|
|
|
}
|
|
|
else if (order.CARGOID == "D") //危险品
|
|
|
{
|
|
|
extContent = $"危险品等级:{order.DCLASS} <br/>危险品编号:{order.DUNNO}<br/>";
|
|
|
}
|
|
|
|
|
|
var mailContent = $@"TO:{order.CUSTOMERNAME} 贵司委托我司代理订舱出口的货物信息如下,详情请见附件,谢谢!<br/>
|
|
|
提单号:{order.MBLNO}<br/>
|
|
|
船名航次:{order.VESSEL}/{order.VOYNO}<br/>
|
|
|
目的港:{order.PORTDISCHARGE}<br/>
|
|
|
预计船期:{(order.ETD.HasValue ? order.ETD.Value.Date.ToString("yyyy-MM-dd") : "")}<br/>
|
|
|
场站:{order.YARD}<br/>
|
|
|
船代:{order.SHIPAGENCY}<br/>
|
|
|
预计截港时间:{order.CLOSINGDATE}<br/>
|
|
|
预计截单时间:{order.CLOSEDOCDATE}<br/>
|
|
|
截VGM时间:{order.CLOSEVGMDATE}<br/>
|
|
|
{extContent}
|
|
|
备注:{order.YARDREMARK}<br/>
|
|
|
提箱小票链接:<a href='{orderUrl.UrlTxxp}'>{orderUrl.UrlTxxp}</a><br/>
|
|
|
提交VGM链接:<a href='{orderUrl.UrlVgm}'>{orderUrl.UrlVgm}</a><br/>
|
|
|
<br/>
|
|
|
<span style='color:red;'>温馨提示:</span><br/>
|
|
|
<span style='color:red;'>如果分票报关,请回箱前通知场站及我司。</span><br/>
|
|
|
<span style='color:red;'>开船及截港时间以码头具体计划为准。</span><br/>
|
|
|
<span style='color:red;'>若贵司自输VGM,请不要通过VGM链接提交数据,否则我司收取相关VGM申报费用。</span><br/>
|
|
|
<br/>
|
|
|
订舱代理联系人:{UserManager.Name}<br/>
|
|
|
电话:{user.Tel} 手机:{user.Phone}<br/>
|
|
|
邮箱:{user.Email}
|
|
|
<br/>";
|
|
|
|
|
|
var sendResult = await MailSendHelper.SendMail(mailAcc, mailSubject, mailContent, letterYard.AttnMail);
|
|
|
if (!sendResult.Key)
|
|
|
{
|
|
|
_logger.LogError($"放舱邮件发送失败:从{mailAcc.MailAccount}到{letterYard.AttnMail},主题 {mailSubject}");
|
|
|
throw Oops.Bah($"邮件发送失败:{sendResult.Value}");
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取放舱pdf(准备作废,后期使用打印相关接口)
|
|
|
/// </summary>
|
|
|
/// <param name="bookingId"></param>
|
|
|
/// <param name="type">类型,1:pdf、2:xlsx、3:docx</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/LetterYardPdf")]
|
|
|
public async Task<IActionResult> LetterYardPdf(long bookingId, int type = 1)
|
|
|
{
|
|
|
var letterYard = await _repLetterYard.FirstOrDefaultAsync(x => x.BookingId == bookingId);
|
|
|
if (letterYard == null)
|
|
|
{
|
|
|
throw Oops.Bah("放舱信息未找到,请先保存数据");
|
|
|
}
|
|
|
|
|
|
var fileType = "";
|
|
|
if (type == 1)
|
|
|
{
|
|
|
fileType = ".pdf";
|
|
|
}
|
|
|
else if (type == 2)
|
|
|
{
|
|
|
fileType = ".xlsx";
|
|
|
}
|
|
|
else if (type == 3)
|
|
|
{
|
|
|
fileType = ".docx";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
throw Oops.Bah("类型参数不正确");
|
|
|
}
|
|
|
|
|
|
var bs = await GetReportFile(bookingId, "fangcang", type);
|
|
|
var fileName = HttpUtility.UrlEncode($"{bookingId}_{DateTime.Now.Ticks}{fileType}", Encoding.GetEncoding("UTF-8"));
|
|
|
var result = new FileContentResult(bs, "application/octet-stream") { FileDownloadName = fileName };
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取放舱excel(准备作废,后期使用打印相关接口)
|
|
|
/// </summary>
|
|
|
/// <param name="bookingId"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/LetterYardXlsx")]
|
|
|
public async Task<IActionResult> LetterYardXlsx(long bookingId)
|
|
|
{
|
|
|
var letterYard = await _repLetterYard.FirstOrDefaultAsync(x => x.BookingId == bookingId);
|
|
|
if (letterYard == null)
|
|
|
{
|
|
|
throw Oops.Bah("放舱信息未找到,请先保存数据");
|
|
|
}
|
|
|
var bs = await GetReportFile(bookingId, "fangcang", 2);
|
|
|
var fileName = HttpUtility.UrlEncode($"{bookingId}_{DateTime.Now.Ticks}.xlsx", Encoding.GetEncoding("UTF-8"));
|
|
|
var result = new FileContentResult(bs, "application/octet-stream") { FileDownloadName = fileName };
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 生成报表文件(准备作废)
|
|
|
/// </summary>
|
|
|
/// <param name="bookingId"></param>
|
|
|
/// <param name="type">类型,1:pdf、2:xlsx、3:docx</param>
|
|
|
/// <param name="typeCode">报表类型代码,例如fangcang、samplebill等</param>
|
|
|
/// <returns></returns>
|
|
|
[NonAction]
|
|
|
private async Task<byte[]> GetReportFile(long bookingId, string typeCode, int type = 1)
|
|
|
{
|
|
|
//打印报表服务地址
|
|
|
var reportUrl = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "url_report_generate").Value;
|
|
|
if (!reportUrl.EndsWith("/"))
|
|
|
{
|
|
|
reportUrl += "/";
|
|
|
}
|
|
|
|
|
|
//订舱数据
|
|
|
var order = _rep.FirstOrDefault(x => x.Id == bookingId);
|
|
|
if (order == null)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK001);
|
|
|
}
|
|
|
|
|
|
_logger.LogInformation($"查找模板:bookingId-{bookingId} TenantId-{order.TenantId}");
|
|
|
var printTemplate = await _repPrintTemplate.AsQueryable().Filter(null, true).FirstAsync(x => x.TenantId == order.TenantId && x.TypeCode == typeCode);
|
|
|
if (printTemplate == null)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK115);
|
|
|
}
|
|
|
|
|
|
var opt = App.GetOptions<PrintTemplateOptions>();
|
|
|
var dirAbs = opt.basePath;
|
|
|
if (string.IsNullOrEmpty(dirAbs))
|
|
|
{
|
|
|
dirAbs = App.WebHostEnvironment.WebRootPath;
|
|
|
}
|
|
|
|
|
|
var fileAbsPath = Path.Combine(dirAbs, printTemplate.FilePath);
|
|
|
_logger.LogInformation($"查找模板文件:{fileAbsPath}");
|
|
|
if (!File.Exists(fileAbsPath))
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK115);
|
|
|
}
|
|
|
|
|
|
_logger.LogInformation($"准备调用报表生成:id:{bookingId},文件:{printTemplate.FileName}");
|
|
|
var genUrl = $"{reportUrl}Report/BookingReport?bookingId={bookingId}&type={type}";
|
|
|
var rtn = await genUrl
|
|
|
.SetContentType("multipart/form-data")
|
|
|
.SetBodyBytes(("file", File.ReadAllBytes(fileAbsPath), HttpUtility.UrlEncode(printTemplate.FileName, Encoding.GetEncoding("UTF-8"))))
|
|
|
.PostAsStringAsync();
|
|
|
var jobjRtn = JObject.Parse(rtn);
|
|
|
_logger.LogInformation($"调用报表生成返回:{rtn}");
|
|
|
if (jobjRtn.GetBooleanValue("Success"))
|
|
|
{
|
|
|
//调用读取文件
|
|
|
var fn = jobjRtn.GetStringValue("Data");
|
|
|
_logger.LogInformation($"准备调用读取报表文件:id:{bookingId},文件名:{fn}");
|
|
|
var readFileUrl = $"{reportUrl}Report/GetFile?fileName={fn}";
|
|
|
var bs = await readFileUrl.GetAsByteArrayAsync();
|
|
|
|
|
|
_logger.LogInformation($"调用读取报表文件返回:{bs.Length}");
|
|
|
|
|
|
return bs;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
throw Oops.Bah($"生成报表文件失败:{jobjRtn.GetStringValue("Message")}");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 生成打印报表文件
|
|
|
/// </summary>
|
|
|
/// <param name="bookingId">订舱ID</param>
|
|
|
/// <param name="printTemplate">打印模板</param>
|
|
|
/// <param name="type">类型,1:pdf、2:xlsx、3:docx</param>
|
|
|
/// <returns></returns>
|
|
|
[NonAction]
|
|
|
private async Task<byte[]> GenPrintFile(long bookingId, BookingPrintTemplate printTemplate, int type = 1)
|
|
|
{
|
|
|
//打印报表服务地址
|
|
|
var reportUrl = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "url_report_generate").Value;
|
|
|
if (!reportUrl.EndsWith("/"))
|
|
|
{
|
|
|
reportUrl += "/";
|
|
|
}
|
|
|
|
|
|
//订舱数据
|
|
|
var order = _rep.FirstOrDefault(x => x.Id == bookingId);
|
|
|
if (order == null)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK001);
|
|
|
}
|
|
|
|
|
|
var opt = App.GetOptions<PrintTemplateOptions>();
|
|
|
var dirAbs = opt.basePath;
|
|
|
if (string.IsNullOrEmpty(dirAbs))
|
|
|
{
|
|
|
dirAbs = App.WebHostEnvironment.WebRootPath;
|
|
|
}
|
|
|
|
|
|
var fileAbsPath = Path.Combine(dirAbs, printTemplate.FilePath);
|
|
|
_logger.LogInformation($"查找模板文件:{fileAbsPath}");
|
|
|
if (!File.Exists(fileAbsPath))
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK115);
|
|
|
}
|
|
|
|
|
|
_logger.LogInformation($"准备调用报表生成:id:{bookingId},文件:{printTemplate.FileName}");
|
|
|
var genUrl = $"{reportUrl}Report/BookingReport?bookingId={bookingId}&type={type}";
|
|
|
var rtn = await genUrl
|
|
|
.SetContentType("multipart/form-data")
|
|
|
.SetBodyBytes(("file", File.ReadAllBytes(fileAbsPath), HttpUtility.UrlEncode(printTemplate.FileName, Encoding.GetEncoding("UTF-8"))))
|
|
|
.PostAsStringAsync();
|
|
|
var jobjRtn = JObject.Parse(rtn);
|
|
|
_logger.LogInformation($"调用报表生成返回:{rtn}");
|
|
|
if (jobjRtn.GetBooleanValue("Success"))
|
|
|
{
|
|
|
//调用读取文件
|
|
|
var fn = jobjRtn.GetStringValue("Data");
|
|
|
_logger.LogInformation($"准备调用读取报表文件:id:{bookingId},文件名:{fn}");
|
|
|
var readFileUrl = $"{reportUrl}Report/GetFile?fileName={fn}";
|
|
|
var bs = await readFileUrl.GetAsByteArrayAsync();
|
|
|
|
|
|
_logger.LogInformation($"调用读取报表文件返回:{bs.Length}");
|
|
|
|
|
|
return bs;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
throw Oops.Bah($"生成报表文件失败:{jobjRtn.GetStringValue("Message")}");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 打印
|
|
|
/// <summary>
|
|
|
/// 打印(准备作废,使用PrintOrder代替)
|
|
|
/// </summary>
|
|
|
/// <param name="bookingId">订舱Id</param>
|
|
|
/// <param name="typeCode">打印类型代码,对应字典booking_template_type</param>
|
|
|
/// <param name="type">类型,1:pdf、2:xlsx、3:docx</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/Print")]
|
|
|
public async Task<string> Print(long bookingId, string typeCode, int type = 1)
|
|
|
{
|
|
|
var bs = await GetReportFile(bookingId, typeCode, type);
|
|
|
var fileType = "";
|
|
|
if (type == 1)
|
|
|
{
|
|
|
fileType = ".pdf";
|
|
|
}
|
|
|
else if (type == 2)
|
|
|
{
|
|
|
fileType = ".xlsx";
|
|
|
}
|
|
|
else if (type == 3)
|
|
|
{
|
|
|
fileType = ".docx";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
throw Oops.Bah("类型参数不正确");
|
|
|
}
|
|
|
|
|
|
var typeObj = (await _cache.GetAllDictData()).First(x => x.TypeCode == "booking_template_type" && x.Code == typeCode);
|
|
|
|
|
|
var mblno = await _rep.AsQueryable().Where(x => x.Id == bookingId).Select(x => x.MBLNO).FirstAsync();
|
|
|
string fileName = string.Empty;
|
|
|
if (string.IsNullOrWhiteSpace(mblno))
|
|
|
{
|
|
|
fileName = $"{bookingId}_{typeObj.Value.ValidFileName()}_{DateTime.Now.Ticks}{fileType}";////名称
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
fileName = $"{mblno}_{typeObj.Value.ValidFileName()}_{DateTime.Now.Ticks}{fileType}";////名称
|
|
|
}
|
|
|
//var result = new FileContentResult(bs, "application/octet-stream") { FileDownloadName = fileName };
|
|
|
var opt = App.GetOptions<TempFileOptions>().Path;
|
|
|
var serverpath = Path.Combine(App.WebHostEnvironment.WebRootPath, opt);//服务器路径
|
|
|
if (!Directory.Exists(serverpath))
|
|
|
{
|
|
|
Directory.CreateDirectory(serverpath);
|
|
|
}
|
|
|
await File.WriteAllBytesAsync(Path.Combine(serverpath, fileName), bs);
|
|
|
|
|
|
//记录打印次数和时间,用于前端动态展示常用的打印类型
|
|
|
var usrCfg = _repUserConfig.AsQueryable().First(x => x.CreatedUserId == UserManager.UserId && x.Type == PrintRecentListTypeKey);
|
|
|
if (usrCfg == null)
|
|
|
{
|
|
|
usrCfg = new DjyUserConfig();
|
|
|
usrCfg.Type = PrintRecentListTypeKey;
|
|
|
usrCfg.ConfigJson = (new string[] { typeCode }).ToJson();
|
|
|
await _repUserConfig.InsertAsync(usrCfg);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var arr = JArray.Parse(usrCfg.ConfigJson).Select(x => x.ToString()).Where(x => x != typeCode).ToList();
|
|
|
arr.Insert(0, typeCode);
|
|
|
usrCfg.ConfigJson = arr.ToArray().ToJson();
|
|
|
await _repUserConfig.UpdateAsync(usrCfg);
|
|
|
}
|
|
|
|
|
|
|
|
|
return fileName;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 下载打印文件
|
|
|
/// </summary>
|
|
|
/// <param name="fileName">文件名</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/DownloadPrint"), AllowAnonymous]
|
|
|
public IActionResult DownloadPrint(string fileName)
|
|
|
{
|
|
|
var opt = App.GetOptions<TempFileOptions>().Path;
|
|
|
var fileFullPath = Path.Combine(App.WebHostEnvironment.WebRootPath, opt);//服务器路径
|
|
|
var result = new FileStreamResult(new FileStream(Path.Combine(fileFullPath, fileName), FileMode.Open), "application/octet-stream") { FileDownloadName = fileName };
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 订舱打印(返回文件名)
|
|
|
/// </summary>
|
|
|
/// <param name="bookingId">订舱Id</param>
|
|
|
/// <param name="templateId">打印模板ID</param>
|
|
|
/// <param name="cateCode">分类代码(使用字典【booking_template_category】中的代码)</param>
|
|
|
/// <param name="type">类型,1:pdf、2:xlsx、3:docx</param>
|
|
|
/// <param name="printType">打印类型,10:FastReport、20:Excel模板</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/PrintOrder")]
|
|
|
public async Task<string> PrintOrder(long bookingId, long templateId, string cateCode, int type = 1, BookingPrintTemplateType printType = BookingPrintTemplateType.FastReport)
|
|
|
{
|
|
|
var printTemplate = await _repPrintTemplate.AsQueryable().Filter(null, true).FirstAsync(x => x.Id == templateId);
|
|
|
if (printTemplate == null)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK115);
|
|
|
}
|
|
|
|
|
|
var order = await _rep.FirstOrDefaultAsync(x => x.Id == bookingId);
|
|
|
var edi = await _bookingEDIExt.FirstOrDefaultAsync(x => x.BookingId == bookingId);
|
|
|
if (order == null)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK001);
|
|
|
}
|
|
|
|
|
|
var fileName = string.Empty;
|
|
|
var dicCate = (await _cache.GetAllDictData()).FirstOrDefault(x => x.Code == cateCode && x.TypeCode == "booking_template_category");
|
|
|
if (dicCate == null)
|
|
|
{
|
|
|
throw Oops.Bah("分类代码参数不正确");
|
|
|
}
|
|
|
#region FastReport打印
|
|
|
if (printType == BookingPrintTemplateType.FastReport)
|
|
|
{
|
|
|
var bs = await GenPrintFile(bookingId, printTemplate, type);
|
|
|
var fileType = "";
|
|
|
if (type == 1)
|
|
|
{
|
|
|
fileType = ".pdf";
|
|
|
}
|
|
|
else if (type == 2)
|
|
|
{
|
|
|
fileType = ".xlsx";
|
|
|
}
|
|
|
else if (type == 3)
|
|
|
{
|
|
|
fileType = ".docx";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
throw Oops.Bah("类型参数不正确");
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fileName = $"{order.MBLNO}_{DateTime.Now.Ticks}";//名称
|
|
|
var opt = App.GetOptions<TempFileOptions>().Path;
|
|
|
var serverpath = Path.Combine(App.WebHostEnvironment.WebRootPath, opt);//服务器路径
|
|
|
if (!Directory.Exists(serverpath))
|
|
|
{
|
|
|
Directory.CreateDirectory(serverpath);
|
|
|
}
|
|
|
|
|
|
var fullPath = Path.Combine(serverpath, fileName);
|
|
|
await File.WriteAllBytesAsync(fullPath, bs);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region Excel模板打印
|
|
|
else if (printType == BookingPrintTemplateType.ExcelTemplate)
|
|
|
{
|
|
|
var opt = App.GetOptions<PrintTemplateOptions>();
|
|
|
var dirAbs = opt.basePath;
|
|
|
if (string.IsNullOrEmpty(dirAbs))
|
|
|
{
|
|
|
dirAbs = App.WebHostEnvironment.WebRootPath;
|
|
|
}
|
|
|
var fileAbsPath = Path.Combine(dirAbs, printTemplate.FilePath);
|
|
|
_logger.LogInformation($"准备调用EXCEL生成:id:{bookingId},文件:{printTemplate.FileName}");
|
|
|
var result = new FileStream(fileAbsPath, FileMode.Open);
|
|
|
var excelwork = new HSSFWorkbook(result);
|
|
|
var sheet = excelwork.GetSheetAt(0);
|
|
|
var entity = await _excelrep.AsQueryable().Where(x => x.PId == templateId).OrderBy(x => x.Row).ToListAsync();
|
|
|
if (entity == null)
|
|
|
{
|
|
|
|
|
|
throw Oops.Bah("当前模板未设置");
|
|
|
|
|
|
}
|
|
|
for (int _row = 1; _row <= entity.Max(x => x.Row); _row++)
|
|
|
{
|
|
|
|
|
|
if (entity.Where(x => x.Row == _row).Count() > 0)
|
|
|
{
|
|
|
////获取行
|
|
|
var row = sheet.GetRow(_row - 1);
|
|
|
if (row != null)
|
|
|
{
|
|
|
for (int _cellNum = 1; _cellNum <= entity.Max(x => x.Column); _cellNum++)
|
|
|
{
|
|
|
if (entity.Where(x => x.Row == _row && x.Column == _cellNum).Count() > 0)
|
|
|
{
|
|
|
var name = entity.Where(x => x.Row == _row && x.Column == _cellNum).Select(x => x.Field).FirstOrDefault();
|
|
|
|
|
|
if (name.Split('.')[0].ToLower() == "order")
|
|
|
{
|
|
|
|
|
|
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(order))
|
|
|
{
|
|
|
var _name = descriptor.Name.ToLower();
|
|
|
if (name.Split('.')[0].ToLower() == "order" && name.Split('.')[1].ToLower() == _name)
|
|
|
{
|
|
|
var value = descriptor.GetValue(order) != null ? descriptor.GetValue(order).ToString() : "";
|
|
|
ICell cell = row.GetCell(_cellNum - 1);
|
|
|
if (descriptor.PropertyType.FullName.Contains("DateTime"))
|
|
|
{
|
|
|
value = value != "" ? Convert.ToDateTime(value).ToString("yyyy-MM-dd") : "";
|
|
|
}
|
|
|
if (cell != null)
|
|
|
{
|
|
|
row.Cells[_cellNum - 1].SetCellValue(value);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
row.CreateCell(_cellNum - 1).SetCellValue(value);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
if (name.Split('.')[0].ToLower() == "edi")
|
|
|
{
|
|
|
|
|
|
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(edi))
|
|
|
{
|
|
|
var _name = descriptor.Name.ToLower();
|
|
|
if (name.Split('.')[0].ToLower() == "edi" && name.Split('.')[1].ToLower() == _name)
|
|
|
{
|
|
|
var value = descriptor.GetValue(edi) != null ? descriptor.GetValue(edi).ToString() : "";
|
|
|
ICell cell = row.GetCell(_cellNum - 1);
|
|
|
if (descriptor.PropertyType.FullName.Contains("DateTime"))
|
|
|
{
|
|
|
value = value != "" ? Convert.ToDateTime(value).ToString("yyyy-MM-dd") : "";
|
|
|
}
|
|
|
if (cell != null)
|
|
|
{
|
|
|
row.Cells[_cellNum - 1].SetCellValue(value);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
row.CreateCell(_cellNum - 1).SetCellValue(value);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
if (name.Split('.')[0].ToLower() == "userinfo")
|
|
|
{
|
|
|
ICell cell = row.GetCell(_cellNum - 1);
|
|
|
var value = string.Empty;
|
|
|
if (name.Split('.')[1].ToLower() == "username")
|
|
|
{
|
|
|
value = UserManager.Name;
|
|
|
}
|
|
|
if (name.Split('.')[1].ToLower() == "usertel")
|
|
|
{
|
|
|
value = UserManager.TEl;
|
|
|
}
|
|
|
if (name.Split('.')[1].ToLower() == "usermobile")
|
|
|
{
|
|
|
value = UserManager.Phone;
|
|
|
}
|
|
|
if (name.Split('.')[1].ToLower() == "useremail")
|
|
|
{
|
|
|
value = UserManager.Email;
|
|
|
}
|
|
|
if (name.Split('.')[1].ToLower() == "usertenant")
|
|
|
{
|
|
|
value = UserManager.TENANT_NAME;
|
|
|
}
|
|
|
if (cell != null)
|
|
|
{
|
|
|
row.Cells[_cellNum - 1].SetCellValue(value);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
row.CreateCell(_cellNum - 1).SetCellValue(value);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
////创建行
|
|
|
var srow = NpoiExcelExportHelper._.CreateRow(sheet, _row - 1);
|
|
|
|
|
|
for (int _cellNum = 1; _cellNum <= entity.Max(x => x.Column); _cellNum++)
|
|
|
{
|
|
|
if (entity.Where(x => x.Row == _row && x.Column == _cellNum).Count() > 0)
|
|
|
{
|
|
|
var name = entity.Where(x => x.Row == _row && x.Column == _cellNum).Select(x => x.Field).FirstOrDefault();
|
|
|
|
|
|
if (name.Split('.')[0].ToLower() == "order")
|
|
|
{
|
|
|
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(order))
|
|
|
{
|
|
|
var _name = descriptor.Name.ToLower();
|
|
|
if (name.Split('.')[1].ToLower() == _name && name.Split('.')[0].ToLower() == "order")
|
|
|
{
|
|
|
var value = descriptor.GetValue(order) != null ? descriptor.GetValue(order).ToString() : "";
|
|
|
if (descriptor.PropertyType.FullName.Contains("DateTime"))
|
|
|
{
|
|
|
value = value != "" ? Convert.ToDateTime(value).ToString("yyyy-MM-dd") : "";
|
|
|
}
|
|
|
srow.CreateCell(_cellNum - 1).SetCellValue(value);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (name.Split('.')[0].ToLower() == "edi")
|
|
|
{
|
|
|
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(edi))
|
|
|
{
|
|
|
var _name = descriptor.Name.ToLower();
|
|
|
if (name.Split('.')[1].ToLower() == _name && name.Split('.')[0].ToLower() == "edi")
|
|
|
{
|
|
|
var value = descriptor.GetValue(edi) != null ? descriptor.GetValue(edi).ToString() : "";
|
|
|
if (descriptor.PropertyType.FullName.Contains("DateTime"))
|
|
|
{
|
|
|
value = value != "" ? Convert.ToDateTime(value).ToString("yyyy-MM-dd") : "";
|
|
|
}
|
|
|
srow.CreateCell(_cellNum - 1).SetCellValue(value);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (name.Split('.')[0].ToLower() == "userinfo")
|
|
|
{
|
|
|
|
|
|
var value = string.Empty;
|
|
|
if (name.Split('.')[1].ToLower() == "username")
|
|
|
{
|
|
|
value = UserManager.Name;
|
|
|
}
|
|
|
if (name.Split('.')[1].ToLower() == "usertel")
|
|
|
{
|
|
|
value = UserManager.TEl;
|
|
|
}
|
|
|
if (name.Split('.')[1].ToLower() == "usermobile")
|
|
|
{
|
|
|
value = UserManager.Phone;
|
|
|
}
|
|
|
if (name.Split('.')[1].ToLower() == "useremail")
|
|
|
{
|
|
|
value = UserManager.Email;
|
|
|
}
|
|
|
if (name.Split('.')[1].ToLower() == "usertenant")
|
|
|
{
|
|
|
value = UserManager.TENANT_NAME;
|
|
|
}
|
|
|
|
|
|
srow.CreateCell(_cellNum - 1).SetCellValue(value);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
var fileFullPath = Path.Combine(App.WebHostEnvironment.WebRootPath, App.GetOptions<TempFileOptions>().Path);//服务器路径
|
|
|
if (!Directory.Exists(fileFullPath))
|
|
|
{
|
|
|
Directory.CreateDirectory(fileFullPath);
|
|
|
}
|
|
|
fileName = $"{order.MBLNO}_{DateTime.Now.Ticks}" + ".xls";//名称
|
|
|
_logger.LogInformation("导出excel:" + Path.Combine(fileFullPath, fileName));
|
|
|
var filestream = new FileStream(Path.Combine(fileFullPath, fileName), FileMode.OpenOrCreate, FileAccess.ReadWrite);
|
|
|
excelwork.Write(filestream);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
//记录打印次数和时间,用于前端动态展示常用的打印类型
|
|
|
var printRecentListKey = $"{PrintRecentListTypeKey}_{cateCode}_{printType}";
|
|
|
var usrCfg = _repUserConfig.AsQueryable().First(x => x.CreatedUserId == UserManager.UserId && x.Type == printRecentListKey);
|
|
|
if (usrCfg == null)
|
|
|
{
|
|
|
usrCfg = new DjyUserConfig();
|
|
|
usrCfg.Type = printRecentListKey;
|
|
|
usrCfg.ConfigJson = (new long[] { templateId }).ToJson();
|
|
|
await _repUserConfig.InsertAsync(usrCfg);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var arr = JArray.Parse(usrCfg.ConfigJson).Select(x => Convert.ToInt64(x)).Where(x => x != templateId).ToList();
|
|
|
arr.Insert(0, templateId);
|
|
|
usrCfg.ConfigJson = arr.ToArray().ToJson();
|
|
|
await _repUserConfig.UpdateAsync(usrCfg);
|
|
|
}
|
|
|
|
|
|
return HttpUtility.UrlEncode(fileName, Encoding.GetEncoding("UTF-8"));
|
|
|
}
|
|
|
|
|
|
//[HttpGet("/BookingOrder/TestExcel"), AllowAnonymous]
|
|
|
//public async Task TestExcel()
|
|
|
//{
|
|
|
// var excelwork = new HSSFWorkbook(new FileStream(@"E:\whm\proj_git\BookingHeChuan\Myshipping.Web.Entry\bin\Debug\net6.0\wwwroot\Upload\PrintTemplate\373472276209733.xls", FileMode.Open));
|
|
|
// var sheet = excelwork.GetSheetAt(0);
|
|
|
|
|
|
// sheet.GetRow(0).GetCell(0).SetCellValue(Guid.NewGuid().ToString());
|
|
|
// sheet.GetRow(0).GetCell(1).SetCellValue(DateTime.Now.Ticks);
|
|
|
|
|
|
// var filestream = new FileStream(Path.Combine(@"E:\whm\proj_git\BookingHeChuan\Myshipping.Web.Entry\bin\Debug\net6.0\wwwroot\Upload\PrintTemplate", "result.xls"), FileMode.Create);
|
|
|
// excelwork.Write(filestream);
|
|
|
// filestream.Close();
|
|
|
//}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 预览模板生成的pdf文件
|
|
|
/// </summary>
|
|
|
/// <param name="fn">文件名称</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/ViewPrintPdf/{fn}"), AllowAnonymous]
|
|
|
public void ViewPrintPdf(string fn)
|
|
|
{
|
|
|
var opt = App.GetOptions<TempFileOptions>().Path;
|
|
|
var fileFullPath = Path.Combine(App.WebHostEnvironment.WebRootPath, opt);
|
|
|
var fileFullName = Path.Combine(fileFullPath, fn);
|
|
|
if (File.Exists(fileFullName))
|
|
|
{
|
|
|
var readMem = new ReadOnlyMemory<byte>(File.ReadAllBytes(fileFullName));
|
|
|
_httpContextAccessor.HttpContext.Response.BodyWriter.WriteAsync(readMem);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_httpContextAccessor.HttpContext.Response.StatusCode = 404;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取订舱打印模板列表(带有当前用户打印历史排序)(准备作废,使用PrintTemplateWithHistoryList代替)
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/PrintTemplateList")]
|
|
|
public async Task<dynamic> PrintTemplateList()
|
|
|
{
|
|
|
//当前公司所有已配置的模板
|
|
|
var allList = await _repPrintTemplate.AsQueryable()
|
|
|
.Filter(null, true).InnerJoin<BookingPrinttemplateRight>((d, t) => d.Id == t.PrintTemplateId && t.SysUserId == UserManager.UserId)
|
|
|
.Where(d => d.TenantId == UserManager.TENANT_ID)
|
|
|
.Select(d => new
|
|
|
{
|
|
|
|
|
|
d.TypeCode,
|
|
|
d.TypeName,
|
|
|
d.IsMain,
|
|
|
d.IsSub
|
|
|
|
|
|
})
|
|
|
.ToListAsync();
|
|
|
|
|
|
var listReult = new List<dynamic>();
|
|
|
//当前用户打印历史数据
|
|
|
var usrCfg = await _repUserConfig.AsQueryable().FirstAsync(x => x.CreatedUserId == UserManager.UserId && x.Type == PrintRecentListTypeKey);
|
|
|
if (usrCfg != null)
|
|
|
{
|
|
|
var arr = JArray.Parse(usrCfg.ConfigJson).Select(x => x.ToString()).ToList();
|
|
|
|
|
|
//按顺序加入到结果
|
|
|
arr.ForEach(x =>
|
|
|
{
|
|
|
var find = allList.FirstOrDefault(y => y.TypeCode == x);
|
|
|
if (find != null)
|
|
|
{
|
|
|
listReult.Add(find);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
var listOut = allList.Where(x => !arr.Contains(x.TypeCode)).ToList();
|
|
|
listReult.AddRange(listOut);
|
|
|
|
|
|
return listReult;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return allList;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取订舱打印模板列表(带有当前用户打印历史排序)
|
|
|
/// </summary>
|
|
|
/// <param name="cateCode">分类代码(使用字典【booking_template_category】中的代码)</param>
|
|
|
/// <param name="printType">打印分类,10:FastReport、20:Excel模板</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/PrintTemplateWithHistoryList")]
|
|
|
public async Task<dynamic> PrintTemplateWithHistoryList(string cateCode, BookingPrintTemplateType printType)
|
|
|
{
|
|
|
var typeCode = printType.ToString();
|
|
|
//当前公司所有已配置的模板
|
|
|
var allList = await _repPrintTemplate.AsQueryable()
|
|
|
.Filter(null, true).InnerJoin<BookingPrinttemplateRight>((d, t) => d.Id == t.PrintTemplateId && t.SysUserId == UserManager.UserId)
|
|
|
.Where(d => d.TenantId == UserManager.TENANT_ID && d.CateCode.Contains(cateCode) && d.Type == typeCode)
|
|
|
.Select(d => new
|
|
|
{
|
|
|
d.Id,
|
|
|
d.CateCode,
|
|
|
d.CateName,
|
|
|
d.DisplayName
|
|
|
|
|
|
})
|
|
|
.ToListAsync();
|
|
|
|
|
|
var listReult = new List<dynamic>();
|
|
|
//当前用户打印历史数据
|
|
|
var printRecentListKey = $"{PrintRecentListTypeKey}_{cateCode}_{printType}";
|
|
|
var usrCfg = await _repUserConfig.AsQueryable().FirstAsync(x => x.CreatedUserId == UserManager.UserId && x.Type == printRecentListKey);
|
|
|
if (usrCfg != null)
|
|
|
{
|
|
|
var arr = JArray.Parse(usrCfg.ConfigJson).Select(x => Convert.ToInt64(x)).ToList();
|
|
|
|
|
|
//按顺序加入到结果
|
|
|
arr.ForEach(x =>
|
|
|
{
|
|
|
var find = allList.FirstOrDefault(y => y.Id == x);
|
|
|
if (find != null)
|
|
|
{
|
|
|
listReult.Add(find);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
var listOut = allList.Where(x => !arr.Contains(x.Id)).ToList();
|
|
|
listReult.AddRange(listOut);
|
|
|
|
|
|
return listReult;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return allList;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 下载文件
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpGet("/BookingOrder/Download")]
|
|
|
public async Task<IActionResult> Download(long id)
|
|
|
{
|
|
|
var printFile = await _bookingfile.FirstOrDefaultAsync(u => u.Id == id);
|
|
|
if (printFile == null)
|
|
|
{
|
|
|
throw Oops.Oh(BookingErrorCode.BOOK200);
|
|
|
}
|
|
|
var opt = App.GetOptions<BookingAttachOptions>();
|
|
|
var dirAbs = opt.basePath;
|
|
|
if (string.IsNullOrEmpty(dirAbs))
|
|
|
{
|
|
|
dirAbs = App.WebHostEnvironment.WebRootPath;
|
|
|
}
|
|
|
|
|
|
var fileFullPath = Path.Combine(dirAbs, printFile.FilePath);
|
|
|
if (!File.Exists(fileFullPath))
|
|
|
{
|
|
|
throw Oops.Oh(BookingErrorCode.BOOK115);
|
|
|
}
|
|
|
|
|
|
var fileName = HttpUtility.UrlEncode(printFile.FileName, Encoding.GetEncoding("UTF-8"));
|
|
|
var result = new FileStreamResult(new FileStream(fileFullPath, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName };
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 下货纸
|
|
|
/// <summary>
|
|
|
/// 发送下货纸
|
|
|
/// </summary>
|
|
|
/// <param name="bookingId"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/BookingOrder/SendXHZ")]
|
|
|
public async Task SendXHZ(long bookingId)
|
|
|
{
|
|
|
var rtn = await XiahuozhiHelpler.Send(bookingId, "9");
|
|
|
if (!rtn.Key)
|
|
|
{
|
|
|
throw Oops.Bah($"发送失败:{rtn.Value}");
|
|
|
}
|
|
|
|
|
|
//订舱状态
|
|
|
await SaveBookingStatus(bookingId, "sta_xhz", "下货纸");
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 样单(提单确认)
|
|
|
|
|
|
/// <summary>
|
|
|
/// 样单
|
|
|
/// </summary>
|
|
|
/// <param name="bookingId"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/SampleBill")]
|
|
|
public async Task<BookingSampleBillOutput> SampleBill(long bookingId)
|
|
|
{
|
|
|
var order = _rep.FirstOrDefault(x => x.Id == bookingId);
|
|
|
var samp = await _repSampleBill.FirstOrDefaultAsync(x => x.BookingId == bookingId);
|
|
|
if (samp == null)
|
|
|
{
|
|
|
var user = _repUser.FirstOrDefault(x => x.Id == UserManager.UserId);
|
|
|
samp = new BookingSampleBill()
|
|
|
{
|
|
|
BookingId = bookingId,
|
|
|
Description = order.DESCRIPTION,
|
|
|
FromName = user.Name,
|
|
|
FromTel = user.Tel,
|
|
|
FromMail = user.Email,
|
|
|
|
|
|
};
|
|
|
}
|
|
|
|
|
|
var output = samp.Adapt<BookingSampleBillOutput>();
|
|
|
|
|
|
return output;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 保存(新增或修改)样单
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/BookingSampleBill/Save")]
|
|
|
public async Task<long> SampleBillSave(UpdateBookingSampleBillInput input)
|
|
|
{
|
|
|
BookingSampleBill entity = null;
|
|
|
if (input.Id == 0)
|
|
|
{
|
|
|
entity = input.Adapt<BookingSampleBill>();
|
|
|
await _repSampleBill.InsertAsync(entity);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
entity = _repSampleBill.FirstOrDefault(x => x.BookingId == input.Id);
|
|
|
entity = input.Adapt(entity);
|
|
|
await _repSampleBill.UpdateAsync(entity);
|
|
|
}
|
|
|
|
|
|
return entity.Id;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取样单pdf(准备作废,后期使用打印相关api)
|
|
|
/// </summary>
|
|
|
/// <param name="bookingId"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/SampleBillPdf")]
|
|
|
public async Task<IActionResult> SampleBillPdf(long bookingId)
|
|
|
{
|
|
|
var samp = await _repSampleBill.FirstOrDefaultAsync(x => x.BookingId == bookingId);
|
|
|
if (samp == null)
|
|
|
{
|
|
|
throw Oops.Bah("请先保存提单确认数据后再继续");
|
|
|
}
|
|
|
|
|
|
var bs = await GetReportFile(bookingId, "tidanqueren");
|
|
|
var fileName = HttpUtility.UrlEncode($"{bookingId}_{DateTime.Now.Ticks}.xlsx", Encoding.GetEncoding("UTF-8"));
|
|
|
var result = new FileContentResult(bs, "application/octet-stream") { FileDownloadName = fileName };
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 小票链接
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取提箱小票链接
|
|
|
/// </summary>
|
|
|
/// <param name="bookingId"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/TxxpLink")]
|
|
|
public async Task<string> TxxpLink(long bookingId)
|
|
|
{
|
|
|
var order = _rep.FirstOrDefault(x => x.Id == bookingId);
|
|
|
if (order == null)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK001);
|
|
|
}
|
|
|
|
|
|
var ordUrl = _repOrderUrl.FirstOrDefault(x => x.BookingId == bookingId);
|
|
|
if (ordUrl == null)
|
|
|
{
|
|
|
ordUrl = new BookingOrderUrl();
|
|
|
ordUrl.BookingId = bookingId;
|
|
|
await _repOrderUrl.InsertAsync(ordUrl);
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(ordUrl.UrlTxxp))
|
|
|
{
|
|
|
return ordUrl.UrlTxxp;
|
|
|
}
|
|
|
|
|
|
//校验船公司
|
|
|
if (string.IsNullOrEmpty(order.CARRIERID))
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK118);
|
|
|
}
|
|
|
|
|
|
//判断船公司是否支持
|
|
|
var allowCarrier = _cache.GetAllDictData().Result.Where(x => x.TypeCode == "txxp_carrier_list").Select(x => x.Code).ToList();
|
|
|
if (!allowCarrier.Contains(order.CARRIERID))
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK117);
|
|
|
}
|
|
|
|
|
|
//亿通账号
|
|
|
var ytAcc = _webAccountConfig.GetAccountConfig("YitongWeb", UserManager.UserId).Result;
|
|
|
if (ytAcc == null)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK119);
|
|
|
}
|
|
|
|
|
|
//场站转换
|
|
|
var yardset = _cache.GetAllMappingYard().Result.FirstOrDefault(y => y.Code == order.YARDID && y.Module == "BookingTxxp");
|
|
|
if (yardset == null)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK120, $"{order.YARDID}(提箱小票)");
|
|
|
}
|
|
|
|
|
|
var ctns = await _repCtn.Where(x => x.BILLID == bookingId).ToListAsync();
|
|
|
//校验箱子数据录入
|
|
|
if (ctns.Where(c => string.IsNullOrEmpty(c.CTNALL) || !c.CTNNUM.HasValue).Count() > 0)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK121);
|
|
|
}
|
|
|
|
|
|
//箱型映射
|
|
|
var ctnMapping = await _cache.GetAllMappingCtn();
|
|
|
ctnMapping = ctnMapping.Where(x => x.Module == "BookingTxxp").ToList();
|
|
|
//if (ctnMapping.Count == 0)
|
|
|
//{
|
|
|
// throw Oops.Bah(BookingErrorCode.BOOK122);
|
|
|
//}
|
|
|
|
|
|
var expCode = ctns.Select(x => x.CTNCODE).Distinct().Except(ctnMapping.Select(y => y.Code)).ToList();
|
|
|
if (expCode.Count > 0)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK123, $"{string.Join(',', expCode)}(提箱小票)");
|
|
|
}
|
|
|
|
|
|
var user = await _repUser.FirstOrDefaultAsync(x => x.Id == UserManager.UserId);
|
|
|
|
|
|
//调用小票服务
|
|
|
var dicUrlTxxp = _cache.GetAllDictData().Result.First(x => x.TypeCode == "url_set" && x.Code == "txxp_service");
|
|
|
var postObj = new
|
|
|
{
|
|
|
SystemCode = "djy_hechuan",
|
|
|
CarrierCode = order.CARRIERID,
|
|
|
billOrderId = order.Id.ToString(),
|
|
|
sendOrderCode = order.MBLNO,
|
|
|
userId = UserManager.DjyUserId,
|
|
|
customerId = order.CUSTOMERID.ToString(),
|
|
|
// userName = currUser.CODENAME,
|
|
|
//userPassword = currUser.PASSWORD,
|
|
|
operatorName = UserManager.Name,
|
|
|
depotCode = yardset.MapCode,
|
|
|
depotName = yardset.MapName,
|
|
|
AgentName = UserManager.TENANT_NAME,
|
|
|
linkName = UserManager.Name,
|
|
|
linkMobile = user.Tel,
|
|
|
CustomerName = $"{UserManager.TENANT_NAME}+{UserManager.Name}", //公司名称+用户姓名
|
|
|
memo = string.Empty,
|
|
|
boxInfo = ctns.Select(c =>
|
|
|
{
|
|
|
var mapCtn = ctnMapping.First(x => x.Code == c.CTNCODE);
|
|
|
return new
|
|
|
{
|
|
|
boxType = mapCtn == null ? c.CTNALL : mapCtn.MapCode,
|
|
|
boxCount = c.CTNNUM.Value
|
|
|
};
|
|
|
}),
|
|
|
sysLoginName = ytAcc.Account,
|
|
|
sysPsssword = ytAcc.Password
|
|
|
};
|
|
|
|
|
|
|
|
|
string strPostObj = postObj.ToJsonString();
|
|
|
_logger.LogInformation($"调用提箱小票接口传递数据:{strPostObj}");
|
|
|
var strResp = await dicUrlTxxp.Value.SetBody(postObj).PostAsStringAsync();
|
|
|
_logger.LogInformation($"调用提箱小票接口返回:{strResp}");
|
|
|
|
|
|
var jobjResp = JObject.Parse(strResp);
|
|
|
int respCode = jobjResp.GetIntValue("code");
|
|
|
if (respCode != 200)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK124, jobjResp.GetStringValue("message"));
|
|
|
}
|
|
|
|
|
|
//保存url
|
|
|
var txxpUrl = jobjResp.GetStringValue("data");
|
|
|
ordUrl.UrlTxxp = txxpUrl;
|
|
|
await _repOrderUrl.UpdateAsync(ordUrl);
|
|
|
|
|
|
//货运动态
|
|
|
var bsl = new BookingStatusLog();
|
|
|
bsl.BookingId = bookingId;
|
|
|
bsl.Status = $"生成提箱小票链接";
|
|
|
bsl.OpTime = DateTime.Now;
|
|
|
bsl.Category = "ship";
|
|
|
bsl.MBLNO = order.MBLNO;
|
|
|
await _repStatuslog.InsertAsync(bsl);
|
|
|
|
|
|
return txxpUrl;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region VGM及VMG链接
|
|
|
/// <summary>
|
|
|
/// 获取VGM、VGM SI链接
|
|
|
/// </summary>
|
|
|
/// <param name="bookingId"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/VgmLink")]
|
|
|
public async Task<string[]> VgmLink(long bookingId)
|
|
|
{
|
|
|
var order = _rep.FirstOrDefault(x => x.Id == bookingId);
|
|
|
if (order == null)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK001);
|
|
|
}
|
|
|
|
|
|
var ordUrl = _repOrderUrl.FirstOrDefault(x => x.BookingId == bookingId);
|
|
|
if (ordUrl == null)
|
|
|
{
|
|
|
ordUrl = new BookingOrderUrl();
|
|
|
ordUrl.BookingId = bookingId;
|
|
|
await _repOrderUrl.InsertAsync(ordUrl);
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(ordUrl.UrlVgm))
|
|
|
{
|
|
|
return new string[] { ordUrl.UrlVgm, ordUrl.UrlVgmSi };
|
|
|
}
|
|
|
|
|
|
//校验船公司
|
|
|
if (string.IsNullOrEmpty(order.CARRIERID))
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK118);
|
|
|
}
|
|
|
|
|
|
var ctns = await _repCtn.Where(x => x.BILLID == bookingId).ToListAsync();
|
|
|
//判断船公司是否支持
|
|
|
var allowCarrier = _cache.GetAllDictData().Result.Where(x => x.TypeCode == "vgm_carrier_list").Select(x => x.Code).ToList();
|
|
|
if (!allowCarrier.Contains(order.CARRIERID))
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK117);
|
|
|
}
|
|
|
|
|
|
//船公司网站账号
|
|
|
var carrWebAccMap = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "carrier_web_account_mapping" && x.Code == order.CARRIERID);
|
|
|
var webacc = _webAccountConfig.GetAccountConfig(carrWebAccMap.Value, UserManager.UserId).Result;
|
|
|
if (webacc == null)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK125);
|
|
|
}
|
|
|
|
|
|
//场站转换
|
|
|
var yardset = _cache.GetAllMappingYard().Result.FirstOrDefault(y => y.Code == order.YARDID && y.Module == "BookingVgm");
|
|
|
if (yardset == null)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK120, $"{order.YARDID}(VGM)");
|
|
|
}
|
|
|
|
|
|
//校验箱子数据录入
|
|
|
if (ctns.Where(c => string.IsNullOrEmpty(c.CTNALL) || !c.CTNNUM.HasValue).Count() > 0)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK121);
|
|
|
}
|
|
|
|
|
|
//箱型映射
|
|
|
var ctnMapping = await _cache.GetAllMappingCtn();
|
|
|
ctnMapping = ctnMapping.Where(x => x.Module == "BookingVgm").ToList();
|
|
|
//if (ctnMapping.Count == 0)
|
|
|
//{
|
|
|
// throw Oops.Bah(BookingErrorCode.BOOK122);
|
|
|
//}
|
|
|
|
|
|
var expCode = ctns.Select(x => x.CTNCODE).Distinct().Except(ctnMapping.Select(y => y.Code)).ToList();
|
|
|
if (expCode.Count > 0)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK123, $"{string.Join(',', expCode)}(VGM)");
|
|
|
}
|
|
|
|
|
|
//接收反馈地址
|
|
|
var dicUrlVgmResp = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "url_reponse" && x.Code == "vgm_si_post_reponse");
|
|
|
var dicUrlSiResp = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "url_reponse" && x.Code == "si_post_response");
|
|
|
|
|
|
var user = await _repUser.FirstOrDefaultAsync(x => x.Id == UserManager.UserId);
|
|
|
|
|
|
//调用vgm链接服务
|
|
|
var dicUrl = _cache.GetAllDictData().Result.First(x => x.TypeCode == "url_set" && x.Code == "vgm_link_service");
|
|
|
var postObj = new
|
|
|
{
|
|
|
SystemCode = "djy_hechuan",
|
|
|
billOrderId = order.Id.ToString(),
|
|
|
sendOrderCode = order.MBLNO,
|
|
|
customerName = $"{UserManager.TENANT_NAME}+{UserManager.Name}", //公司名称+用户姓名
|
|
|
customerId = order.CUSTOMERID.ToString(),
|
|
|
agentName = string.IsNullOrEmpty(order.FORWARDER) ? UserManager.TENANT_NAME : order.FORWARDER,
|
|
|
carrierCode = order.CARRIERID,
|
|
|
userName = webacc.Account,
|
|
|
userPassword = webacc.Password,
|
|
|
depotCode = yardset.MapCode,
|
|
|
depotName = order.YARD,
|
|
|
linkName = UserManager.Name,
|
|
|
linkMobile = user.Tel,
|
|
|
linkEmail = user.Email,
|
|
|
userId = UserManager.DjyUserId,
|
|
|
returnUrl = dicUrlVgmResp?.Value,
|
|
|
shipName = order.VESSEL,
|
|
|
voyNo = order.VOYNO,
|
|
|
etdstr = order.ETD.HasValue ? order.ETD.Value.ToString("yyyy-MM-dd") : string.Empty,
|
|
|
potrSend = order.PORTLOAD,
|
|
|
potrGoal = order.PORTDISCHARGE,
|
|
|
boxinfoStr = order.CNTRTOTAL,
|
|
|
vgmEndTimeStr = order.CLOSEVGMDATE.HasValue ? order.CLOSEVGMDATE.Value.ToString("yyyy-MM-dd") : string.Empty,
|
|
|
returnOkUrl = "",
|
|
|
SiReturnUrl = dicUrlSiResp?.Value,
|
|
|
DataInfoJson = new
|
|
|
{
|
|
|
order.SHIPPER,
|
|
|
order.CONSIGNEE,
|
|
|
order.NOTIFYPARTY,
|
|
|
order.MARKS,
|
|
|
order.DESCRIPTION,
|
|
|
order.BLFRT,
|
|
|
order.SERVICE,
|
|
|
order.ISSUETYPE,
|
|
|
order.TRANSPORT,
|
|
|
order.TRANSPORTID,
|
|
|
order.DESTINATION,
|
|
|
order.DESTINATIONID,
|
|
|
order.KINDPKGS,
|
|
|
order.THIRDPAYADDR,
|
|
|
order.PORTLOAD,
|
|
|
order.PORTLOADID,
|
|
|
order.PORTDISCHARGE,
|
|
|
order.PORTDISCHARGEID
|
|
|
}
|
|
|
};
|
|
|
|
|
|
string strPostObj = postObj.ToJsonString();
|
|
|
_logger.LogInformation($"调用VGM链接接口 {dicUrl.Value} 传递数据:{strPostObj}");
|
|
|
var strResp = await dicUrl.Value.SetBody(postObj).PostAsStringAsync();
|
|
|
_logger.LogInformation($"调用VGM链接接口返回:{strResp}");
|
|
|
|
|
|
var jobjResp = JObject.Parse(strResp);
|
|
|
int respCode = jobjResp.GetIntValue("code");
|
|
|
if (respCode != 200)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK126, jobjResp.GetStringValue("message"));
|
|
|
}
|
|
|
|
|
|
|
|
|
//保存url
|
|
|
var memoData = jobjResp.GetJObjectValue("memoData");
|
|
|
ordUrl.UrlVgm = memoData.GetStringValue("vgmUrl");
|
|
|
ordUrl.UrlVgmSi = memoData.GetStringValue("vgmAndSiUrl");
|
|
|
await _repOrderUrl.UpdateAsync(ordUrl);
|
|
|
|
|
|
|
|
|
//货运动态
|
|
|
var bsl = new BookingStatusLog();
|
|
|
bsl.BookingId = bookingId;
|
|
|
bsl.Status = $"生成VGM链接";
|
|
|
bsl.OpTime = DateTime.Now;
|
|
|
bsl.Category = "ship";
|
|
|
bsl.MBLNO = order.MBLNO;
|
|
|
await _repStatuslog.InsertAsync(bsl);
|
|
|
|
|
|
return new string[] { ordUrl.UrlVgm, ordUrl.UrlVgmSi };
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 直发VGM(单票)
|
|
|
/// </summary>
|
|
|
/// <param name="bookingId"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/BookingOrder/VgmSend")]
|
|
|
public async Task VgmSend(long bookingId)
|
|
|
{
|
|
|
var order = _rep.FirstOrDefault(x => x.Id == bookingId);
|
|
|
var ctns = _repCtn.Where(x => x.BILLID == bookingId).ToList();
|
|
|
|
|
|
var dicUrlVgm = _cache.GetAllDictData().Result.First(x => x.TypeCode == "url_set" && x.Code == "vgm_service_single");
|
|
|
|
|
|
//船公司
|
|
|
if (string.IsNullOrEmpty(order.CARRIERID))
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK118);
|
|
|
}
|
|
|
|
|
|
//判断船公司是否支持
|
|
|
var allowCarrier = _cache.GetAllDictData().Result.Where(x => x.TypeCode == "vgm_carrier_list").Select(x => x.Code).ToList();
|
|
|
if (!allowCarrier.Contains(order.CARRIERID))
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK117);
|
|
|
}
|
|
|
|
|
|
//船公司网站账号
|
|
|
var carrWebAccMap = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "carrier_web_account_mapping" && x.Code == order.CARRIERID);
|
|
|
var webacc = _webAccountConfig.GetAccountConfig(carrWebAccMap.Value, UserManager.UserId).Result;
|
|
|
if (webacc == null)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK125);
|
|
|
}
|
|
|
|
|
|
//提单号不能为空
|
|
|
if (string.IsNullOrEmpty(order.MBLNO))
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK127);
|
|
|
}
|
|
|
|
|
|
////箱型映射
|
|
|
//var ctnMapping = await _cache.GetAllMappingCtn();
|
|
|
//ctnMapping = ctnMapping.Where(x => x.Module == "BookingVgm").ToList();
|
|
|
//if (ctnMapping.Count == 0)
|
|
|
//{
|
|
|
// throw Oops.Bah(BookingErrorCode.BOOK122);
|
|
|
//}
|
|
|
|
|
|
//var expCode = ctns.Select(x => x.CTNCODE).Distinct().Except(ctnMapping.Select(y => y.Code)).ToList();
|
|
|
//if (expCode.Count > 0)
|
|
|
//{
|
|
|
// throw Oops.Bah(BookingErrorCode.BOOK123, string.Join(',', expCode));
|
|
|
//}
|
|
|
|
|
|
#region 箱信息校验,2022-7-1修改:【累加】的必须有重量、皮重和称重重量;【总重】的只需要称重重量不为空
|
|
|
if (ctns.Where(c => c.WEIGHTYPE == "累加" &&
|
|
|
(
|
|
|
string.IsNullOrEmpty(c.CNTRNO)
|
|
|
|| !c.WEIGHKGS.HasValue
|
|
|
|| c.WEIGHKGS == 0
|
|
|
|| !c.TAREWEIGHT.HasValue
|
|
|
|| c.TAREWEIGHT == 0
|
|
|
|| !c.KGS.HasValue
|
|
|
|| c.KGS == 0)
|
|
|
).Count() > 0)
|
|
|
{
|
|
|
throw Oops.Bah("称重方式为累加时,箱号、重量、箱皮重以及称重重量都不能为空");
|
|
|
}
|
|
|
|
|
|
if (ctns.Where(c => c.WEIGHTYPE == "总重" &&
|
|
|
(
|
|
|
string.IsNullOrEmpty(c.CNTRNO)
|
|
|
|| !c.WEIGHKGS.HasValue
|
|
|
|| c.WEIGHKGS == 0)
|
|
|
).Count() > 0)
|
|
|
{
|
|
|
throw Oops.Bah("称重方式为总重时,箱号和称重重量都不能为空");
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
////场站转换
|
|
|
//var yardset = _cache.GetAllMappingYard().Result.FirstOrDefault(y => y.Code == order.YARDID && y.Module == "BookingVgm");
|
|
|
//if (yardset == null)
|
|
|
//{
|
|
|
// throw Oops.Bah(BookingErrorCode.BOOK120, order.YARDID);
|
|
|
//}
|
|
|
if (string.IsNullOrEmpty(order.YARD) || string.IsNullOrEmpty(order.YARDID))
|
|
|
{
|
|
|
throw Oops.Bah("场站未正确选择");
|
|
|
}
|
|
|
|
|
|
var user = await _repUser.FirstOrDefaultAsync(x => x.Id == UserManager.UserId);
|
|
|
|
|
|
int idx = 1;
|
|
|
//调用接口
|
|
|
var dicUrl = _cache.GetAllDictData().Result.First(x => x.TypeCode == "url_set" && x.Code == "vgm_service_single");
|
|
|
var sendObj = new
|
|
|
{
|
|
|
SystemCode = "djy_hechuan",
|
|
|
billOrderId = order.Id.ToString(),
|
|
|
sendOrderCode = order.MBLNO,
|
|
|
customerName = $"{UserManager.TENANT_NAME}+{UserManager.Name}", //公司名称+用户姓名
|
|
|
customerId = order.CUSTOMERID.ToString(),
|
|
|
agentName = string.IsNullOrEmpty(order.FORWARDER) ? UserManager.TENANT_NAME : order.FORWARDER,
|
|
|
carrierCode = order.CARRIERID,
|
|
|
userName = webacc.Account,
|
|
|
userPassword = webacc.Password,
|
|
|
depotCode = order.YARDID,
|
|
|
depotName = order.YARD,
|
|
|
linkName = UserManager.Name,
|
|
|
linkMobile = user.Phone,
|
|
|
linkEmail = user.Email,
|
|
|
userId = user.DjyUserId,
|
|
|
returnUrl = "",
|
|
|
shipName = order.VESSEL,
|
|
|
voyNo = order.VOYNO,
|
|
|
etdstr = order.ETD.HasValue ? order.ETD.Value.ToString("yyyy-MM-dd") : string.Empty,
|
|
|
potrSend = order.PORTLOAD,
|
|
|
potrGoal = order.PORTDISCHARGE,
|
|
|
boxinfoStr = order.CNTRTOTAL,
|
|
|
vgmEndTimeStr = order.CLOSEVGMDATE.HasValue ? order.CLOSEVGMDATE.Value.ToString("yyyy-MM-dd") : string.Empty,
|
|
|
BoxInfo = ctns.Select(c => new
|
|
|
{
|
|
|
index = idx++,
|
|
|
boxType = c.CTNALL,
|
|
|
boxcount = c.CTNNUM.HasValue ? c.CTNNUM.Value : 0,
|
|
|
code = c.CNTRNO,
|
|
|
sealCode = c.SEALNO,
|
|
|
weigth = c.KGS,
|
|
|
weigthTare = c.TAREWEIGHT,
|
|
|
weigthTotal = c.WEIGHKGS,
|
|
|
weigthType = c.WEIGHTYPE == "累加" ? "SM2" : "SM1"
|
|
|
}).ToList(),
|
|
|
returnOkUrl = ""
|
|
|
};
|
|
|
|
|
|
string strPostObj = sendObj.ToJsonString();
|
|
|
_logger.LogInformation($"调用VGM直发接口 {dicUrl.Value} 传递数据:{strPostObj}");
|
|
|
var strResp = await dicUrl.Value.SetBody(sendObj).PostAsStringAsync();
|
|
|
_logger.LogInformation($"调用VGM直发接口返回:{strResp}");
|
|
|
|
|
|
var jobjResp = JObject.Parse(strResp);
|
|
|
int respCode = jobjResp.GetIntValue("code");
|
|
|
if (respCode != 200)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK128, jobjResp.GetStringValue("message"));
|
|
|
}
|
|
|
//货运动态
|
|
|
var bsl = new BookingStatusLog();
|
|
|
bsl.BookingId = bookingId;
|
|
|
bsl.Status = $"直发VGM";
|
|
|
bsl.OpTime = DateTime.Now;
|
|
|
bsl.Category = "ship";
|
|
|
bsl.MBLNO = order.MBLNO;
|
|
|
await _repStatuslog.InsertAsync(bsl);
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 批量编辑vgm
|
|
|
/// </summary>
|
|
|
/// <param name="ids">业务id 逗号拼接</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/GetVmgDataList")]
|
|
|
public async Task<List<BatchVGM>> GetVmgDataList(string ids)
|
|
|
{
|
|
|
var arr = ids.Split(',');
|
|
|
if (arr.Length == 0)
|
|
|
{
|
|
|
throw Oops.Bah("请传入正确数据");
|
|
|
}
|
|
|
var main = await _rep.AsQueryable().Where(x => x.ParentId == 0).ToListAsync();
|
|
|
List<BatchVGM> batchVGMs = new List<BatchVGM>();
|
|
|
foreach (var item in arr)
|
|
|
{
|
|
|
BatchVGM batchVGM = new BatchVGM();
|
|
|
batchVGM.Id = Convert.ToInt64(item);
|
|
|
batchVGM.MBLNO = main.Where(x => x.Id == batchVGM.Id).Select(x => x.MBLNO).FirstOrDefault();
|
|
|
batchVGM.ctnlist = await _repCtn.Where(x => x.BILLID == batchVGM.Id).Select(x => new BatchVGMList
|
|
|
{
|
|
|
Id = x.Id,
|
|
|
CTNCODE = x.CTNCODE,
|
|
|
CTNALL = x.CTNALL,
|
|
|
CNTRNO = x.CNTRNO,
|
|
|
KGS = x.KGS,
|
|
|
TAREWEIGHT = x.TAREWEIGHT,
|
|
|
WEIGHTYPE = x.WEIGHTYPE,
|
|
|
WEIGHKGS = x.WEIGHKGS
|
|
|
}).ToListAsync();
|
|
|
|
|
|
batchVGMs.Add(batchVGM);
|
|
|
}
|
|
|
return batchVGMs;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 批量保存vgm
|
|
|
/// </summary>
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/BookingOrder/SaveBatchVgm")]
|
|
|
public async Task SaveBatchVgm(List<BatchVGMList> dto)
|
|
|
{
|
|
|
|
|
|
if (dto == null)
|
|
|
{
|
|
|
throw Oops.Bah("未提交数据");
|
|
|
}
|
|
|
|
|
|
foreach (var item in dto)
|
|
|
{
|
|
|
await _repCtn.UpdateAsync(x => x.Id == item.Id, x => new BookingCtn
|
|
|
{
|
|
|
CTNCODE = item.CTNCODE,
|
|
|
CTNALL = item.CTNALL,
|
|
|
CNTRNO = item.CNTRNO,
|
|
|
KGS = item.KGS,
|
|
|
TAREWEIGHT = item.TAREWEIGHT,
|
|
|
WEIGHTYPE = item.WEIGHTYPE,
|
|
|
WEIGHKGS = item.WEIGHKGS
|
|
|
});
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 订舱、截单EDI
|
|
|
/// <summary>
|
|
|
/// 发送订舱、截单EDI
|
|
|
/// </summary>
|
|
|
/// <param name="model">订舱、截单EDI请求</param>
|
|
|
/// <returns>返回回执</returns>
|
|
|
[HttpPost("/BookingOrder/SendBookingOrClosingEDI")]
|
|
|
public async Task<string> SendBookingOrClosingEDI(BookingOrClosingEDIOrderDto model)
|
|
|
{
|
|
|
return await InnerBookingOrClosingEDI(model);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
[NonAction]
|
|
|
public async Task<string> InnerBookingOrClosingEDI(BookingOrClosingEDIOrderDto model)
|
|
|
{
|
|
|
string batchNo = IDGen.NextID().ToString();
|
|
|
|
|
|
_logger.LogInformation("批次={no}获取请求订舱、截单EDI {msg}", batchNo, JSON.Serialize(model));
|
|
|
/*
|
|
|
发送订舱和截单EDI的流程
|
|
|
1、通过订单号获取订单信息。
|
|
|
2、检查订单的必填信息。
|
|
|
3、根据船公司ID获取对应的路由枚举。
|
|
|
4、获取EDI转换参数。(集装箱型号、包装方式)
|
|
|
5、读取EDI的配置信息,获取船公司相关的EDI配置。
|
|
|
6、检查详细信息。
|
|
|
7、生成订舱或者截单EDI报文,并返回文件保存绝对路径。
|
|
|
*/
|
|
|
if (model.Id == 0)
|
|
|
throw Oops.Bah("订单Id不能为空");
|
|
|
|
|
|
var order = _rep.FirstOrDefault(a => a.Id == model.Id);
|
|
|
|
|
|
if (order == null)
|
|
|
throw Oops.Bah($"获取订单信息失败");
|
|
|
|
|
|
if (order.ParentId.HasValue && order.ParentId.Value > 0)
|
|
|
throw Oops.Bah($"获取当前订单为分单不能生成EDI信息");
|
|
|
|
|
|
_logger.LogInformation("批次={no}提取订单信息完成", batchNo);
|
|
|
|
|
|
var ediExtModel = _bookingEDIExt.FirstOrDefault(a => a.BookingId == model.Id);
|
|
|
|
|
|
if (ediExtModel == null)
|
|
|
throw Oops.Bah($"获取EDI信息失败");
|
|
|
|
|
|
_logger.LogInformation("批次={no}提取订单EDI信息完成", batchNo);
|
|
|
|
|
|
CheckBookingOrClosingEDI(order);
|
|
|
|
|
|
EDIRouteEnum ediRouteEnum = GetEDIRoute(order.CARRIERID);
|
|
|
|
|
|
//部分船公司EDI需要填写操作英文名称,这里预先预警,其他船公司如果也需要可以再此追加
|
|
|
if (ediRouteEnum == EDIRouteEnum.TSL)
|
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(ediExtModel.OpEName))
|
|
|
throw Oops.Bah("未填写(EDI并补充信息)操作英文名称");
|
|
|
}
|
|
|
|
|
|
_logger.LogInformation("批次={no} 获取EDI路由完成 路由={route}", batchNo, ediRouteEnum.ToString());
|
|
|
|
|
|
if (ediRouteEnum == EDIRouteEnum.NULL)
|
|
|
throw Oops.Bah($"当前船公司没有对应的请求路由配置");
|
|
|
|
|
|
//集装箱型
|
|
|
var ediCtnList = _cache.GetAllMappingCtn().GetAwaiter().GetResult()
|
|
|
.Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)
|
|
|
&& !string.IsNullOrWhiteSpace(t.CarrierCode) && t.CarrierCode.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase)).ToList();
|
|
|
|
|
|
//包装
|
|
|
var ediPkgsList = _cache.GetAllMappingPackage().GetAwaiter().GetResult()
|
|
|
.Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)
|
|
|
&& !string.IsNullOrWhiteSpace(t.CarrierCode) && t.CarrierCode.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase)).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
//包装基础数据
|
|
|
var basePkgsList = _cache.GetAllCodePackage().GetAwaiter().GetResult();
|
|
|
|
|
|
//EDI SO\SI代码
|
|
|
var ediSOSICfg = _cache.GetAllMappingCarrier().GetAwaiter().GetResult()
|
|
|
.FirstOrDefault(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)
|
|
|
&& t.Code.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (ediSOSICfg == null || string.IsNullOrWhiteSpace(ediSOSICfg.MapCode))
|
|
|
throw Oops.Bah($"CARRIERID={order.CARRIERID} 发送SO(SI)的船公司EDI代码未找到");
|
|
|
|
|
|
var ediModel = new EDIBaseModel();
|
|
|
|
|
|
//2023-03-06 修改读取EDI配置方法,所有提取配置必须是已启用的EnableFlag=true,并且要根据SendType匹配发送类型,SendType=""表示使用订舱和截单,SO-订舱 SI-截单
|
|
|
var ftpSet = _cache.GetAllEdiSetting().GetAwaiter().GetResult()
|
|
|
.FirstOrDefault(a => a.EDICODE.Equals(ediRouteEnum.ToString(), StringComparison.OrdinalIgnoreCase)
|
|
|
&& a.TenantId == order.TenantId && !string.IsNullOrWhiteSpace(a.CARRIERID)
|
|
|
&& a.CARRIERID.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase)
|
|
|
&& a.EnableFlag
|
|
|
&& (string.IsNullOrWhiteSpace(a.SendType) ||
|
|
|
(!string.IsNullOrWhiteSpace(a.SendType) && ((model.sendType == "B" && a.SendType == "SO") || (model.sendType == "E" && a.SendType == "SI")))));
|
|
|
|
|
|
if (ftpSet == null)
|
|
|
throw Oops.Bah($"获取EDICODE={ediRouteEnum.ToString()}的EDI参数设置失败");
|
|
|
|
|
|
_logger.LogInformation("批次={no} 获取EDI配置完成 路由={set}", batchNo, JSON.Serialize(ftpSet));
|
|
|
|
|
|
ediModel.SENDCODE = ftpSet.SENDCODE;
|
|
|
ediModel.SENDNAME = ftpSet.SENDNAME;
|
|
|
ediModel.RECEIVECODE = ftpSet.RECEIVECODE;
|
|
|
ediModel.SENDCOMPANYCODE = ftpSet.SENDCOMPANYCODE;
|
|
|
ediModel.SENDSUBCOMPANYCODE = ftpSet.SENDSUBCOMPANYCODE;
|
|
|
ediModel.ALIASSENDCODE = ftpSet.ALIASSENDCODE;
|
|
|
ediModel.SENDSHIPPERCODE = ftpSet.SENDSHIPPERCODE;
|
|
|
|
|
|
ediModel.filetype = model.sendType; //订舱
|
|
|
ediModel.filerole = model.fileRole;
|
|
|
|
|
|
//读取文件配置
|
|
|
var fileCfg = App.GetOptions<BookingAttachOptions>();
|
|
|
|
|
|
string filePath = String.Empty;
|
|
|
string relativePath = string.Empty;
|
|
|
|
|
|
if (!model.send)
|
|
|
{
|
|
|
var opt = App.GetOptions<TempFileOptions>().Path;
|
|
|
|
|
|
filePath = $"{Path.Combine(App.WebHostEnvironment.WebRootPath, opt)}\\{order.BOOKINGNO}";//服务器路径
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
relativePath = $"{fileCfg.relativePath}\\edifiles\\{order.BOOKINGNO}";
|
|
|
|
|
|
filePath = $"{(!string.IsNullOrWhiteSpace(fileCfg.basePath) ? fileCfg.basePath : App.WebHostEnvironment.WebRootPath)}\\{relativePath}";
|
|
|
}
|
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
{
|
|
|
relativePath = relativePath.Replace("\\", "/");
|
|
|
filePath = filePath.Replace("\\", "/");
|
|
|
}
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} 生成文件保存路径完成 路由={filePath} 服务器系统={system}", batchNo, filePath, RuntimeInformation.OSDescription);
|
|
|
//预先创建目录
|
|
|
if (!Directory.Exists(filePath))
|
|
|
{
|
|
|
Directory.CreateDirectory(filePath);
|
|
|
}
|
|
|
|
|
|
ediModel.filerpath = filePath;
|
|
|
|
|
|
/*
|
|
|
* 2023-03-08 这里根据最新的要求,不通过前台读取了,直接从配置读取
|
|
|
ediModel.UseForWarderCode = model.useForwarderCode;
|
|
|
ediModel.ForWarderCode = model.forwarderCode;
|
|
|
ediModel.ForWarderName = model.forwarderName;
|
|
|
*/
|
|
|
ediModel.ForWarderCode = ftpSet.SENDCODE;
|
|
|
ediModel.ForWarderName = ftpSet.SENDNAME;
|
|
|
|
|
|
ediModel.BSLIST = new List<MsOpSeaeEDIBaseModel>();
|
|
|
|
|
|
var primaryModel = order.Adapt<MsOpSeaeEDIBaseModel>();
|
|
|
|
|
|
//起始港映射
|
|
|
var ediLoadPortList = _cache.GetAllMappingPortLoad().GetAwaiter().GetResult()
|
|
|
.Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)
|
|
|
&& !string.IsNullOrWhiteSpace(t.CarrierCode) && t.CarrierCode.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase)).ToList();
|
|
|
|
|
|
//收货地
|
|
|
if (!string.IsNullOrWhiteSpace(primaryModel.PLACERECEIPTID))
|
|
|
{
|
|
|
var currPortInfo = ediLoadPortList.FirstOrDefault(a =>
|
|
|
a.Code.Equals(primaryModel.PLACERECEIPTID, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (currPortInfo == null)
|
|
|
throw Oops.Bah($"收货地{primaryModel.PLACERECEIPTID}的EDI代码未找到");
|
|
|
|
|
|
primaryModel.PLACERECEIPTID = currPortInfo.MapCode?.Trim();
|
|
|
}
|
|
|
|
|
|
//装货港
|
|
|
if (!string.IsNullOrWhiteSpace(primaryModel.PORTLOADID))
|
|
|
{
|
|
|
var currPortInfo = ediLoadPortList.FirstOrDefault(a =>
|
|
|
a.Code.Equals(primaryModel.PORTLOADID, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (currPortInfo == null)
|
|
|
throw Oops.Bah($"装货港{primaryModel.PORTLOADID}的EDI代码未找到");
|
|
|
|
|
|
primaryModel.PORTLOADID = currPortInfo.MapCode?.Trim();
|
|
|
}
|
|
|
|
|
|
//签单地点
|
|
|
if (!string.IsNullOrWhiteSpace(primaryModel.ISSUEPLACEID))
|
|
|
{
|
|
|
var currPortInfo = ediLoadPortList.FirstOrDefault(a =>
|
|
|
a.Code.Equals(primaryModel.ISSUEPLACEID, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (currPortInfo == null)
|
|
|
throw Oops.Bah($"签单地点{primaryModel.ISSUEPLACEID}的EDI代码未找到");
|
|
|
|
|
|
primaryModel.ISSUEPLACEID = currPortInfo.MapCode?.Trim();
|
|
|
}
|
|
|
|
|
|
//预付地点
|
|
|
if (!string.IsNullOrWhiteSpace(primaryModel.PREPARDATID))
|
|
|
{
|
|
|
var currPortInfo = ediLoadPortList.FirstOrDefault(a =>
|
|
|
a.Code.Equals(primaryModel.PREPARDATID, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (currPortInfo == null)
|
|
|
throw Oops.Bah($"预付地点{primaryModel.PREPARDATID}的EDI代码未找到");
|
|
|
|
|
|
primaryModel.PREPARDATID = currPortInfo.MapCode?.Trim();
|
|
|
}
|
|
|
|
|
|
//目的港基础
|
|
|
var portList = _cache.GetAllCodePort().GetAwaiter().GetResult();
|
|
|
|
|
|
//目的港映射
|
|
|
var ediPortList = _cache.GetAllMappingPort().GetAwaiter().GetResult()
|
|
|
.Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)
|
|
|
&&
|
|
|
(string.IsNullOrWhiteSpace(t.CarrierCode) ||(!string.IsNullOrWhiteSpace(t.CarrierCode)
|
|
|
&& t.CarrierCode.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase)))
|
|
|
).ToList();
|
|
|
|
|
|
//卸货港
|
|
|
if(!string.IsNullOrWhiteSpace(primaryModel.PORTDISCHARGEID))
|
|
|
{
|
|
|
var checkName = portList.Count(a =>
|
|
|
!string.IsNullOrWhiteSpace(a.EdiCode)
|
|
|
&& a.EdiCode.Equals(primaryModel.PORTDISCHARGEID, StringComparison.OrdinalIgnoreCase)) > 1;
|
|
|
|
|
|
var basePortInfo = portList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(a.EdiCode)
|
|
|
&& a.EdiCode.Equals(primaryModel.PORTDISCHARGEID, StringComparison.OrdinalIgnoreCase)
|
|
|
&& (!checkName || a.EnName.Equals(primaryModel.PORTDISCHARGE, StringComparison.OrdinalIgnoreCase)));
|
|
|
|
|
|
if (basePortInfo == null)
|
|
|
throw Oops.Bah($"卸货港{primaryModel.PORTDISCHARGEID}基础港口代码未找到");
|
|
|
|
|
|
var currPortInfo = ediPortList.FirstOrDefault(a =>
|
|
|
a.Code.Equals(basePortInfo.Code?.Trim(), StringComparison.OrdinalIgnoreCase)
|
|
|
&& !string.IsNullOrWhiteSpace(a.CarrierCode)
|
|
|
&& a.CarrierCode.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (currPortInfo == null)
|
|
|
{
|
|
|
currPortInfo = ediPortList.FirstOrDefault(a =>
|
|
|
a.Code.Equals(basePortInfo.Code?.Trim(), StringComparison.OrdinalIgnoreCase));
|
|
|
}
|
|
|
|
|
|
if (currPortInfo == null)
|
|
|
throw Oops.Bah($"卸货港{primaryModel.PORTDISCHARGEID}的EDI代码未找到");
|
|
|
|
|
|
primaryModel.PORTDISCHARGEID = currPortInfo.MapCode?.Trim();
|
|
|
}
|
|
|
|
|
|
//中转港
|
|
|
if (!string.IsNullOrWhiteSpace(primaryModel.TRANSPORTID))
|
|
|
{
|
|
|
var checkName = portList.Count(a =>
|
|
|
!string.IsNullOrWhiteSpace(a.EdiCode)
|
|
|
&& a.EdiCode.Equals(primaryModel.TRANSPORTID, StringComparison.OrdinalIgnoreCase)) > 1;
|
|
|
|
|
|
var basePortInfo = portList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(a.EdiCode)
|
|
|
&& a.EdiCode.Equals(primaryModel.TRANSPORTID, StringComparison.OrdinalIgnoreCase)
|
|
|
&& (!checkName || a.EnName.Equals(primaryModel.TRANSPORT, StringComparison.OrdinalIgnoreCase)));
|
|
|
|
|
|
if (basePortInfo == null)
|
|
|
throw Oops.Bah($"中转港{primaryModel.TRANSPORTID}基础港口代码未找到");
|
|
|
|
|
|
var currPortInfo = ediPortList.FirstOrDefault(a =>
|
|
|
a.Code.Equals(basePortInfo.Code?.Trim(), StringComparison.OrdinalIgnoreCase)
|
|
|
&& !string.IsNullOrWhiteSpace(a.CarrierCode)
|
|
|
&& a.CarrierCode.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (currPortInfo == null)
|
|
|
{
|
|
|
currPortInfo = ediPortList.FirstOrDefault(a =>
|
|
|
a.Code.Equals(basePortInfo.Code?.Trim(), StringComparison.OrdinalIgnoreCase));
|
|
|
}
|
|
|
|
|
|
if (currPortInfo == null)
|
|
|
throw Oops.Bah($"中转港{primaryModel.TRANSPORTID}的EDI代码未找到");
|
|
|
|
|
|
primaryModel.TRANSPORTID = currPortInfo.MapCode?.Trim();
|
|
|
}
|
|
|
|
|
|
//目的地
|
|
|
if (!string.IsNullOrWhiteSpace(primaryModel.DESTINATIONID))
|
|
|
{
|
|
|
var checkName = portList.Count(a =>
|
|
|
!string.IsNullOrWhiteSpace(a.EdiCode)
|
|
|
&& a.EdiCode.Equals(primaryModel.DESTINATIONID, StringComparison.OrdinalIgnoreCase)) > 1;
|
|
|
|
|
|
var basePortInfo = portList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(a.EdiCode)
|
|
|
&& a.EdiCode.Equals(primaryModel.DESTINATIONID, StringComparison.OrdinalIgnoreCase)
|
|
|
&& (!checkName || a.EnName.Equals(primaryModel.DESTINATION, StringComparison.OrdinalIgnoreCase)));
|
|
|
|
|
|
if (basePortInfo == null)
|
|
|
throw Oops.Bah($"目的地{primaryModel.DESTINATIONID}基础港口代码未找到");
|
|
|
|
|
|
var currPortInfo = ediPortList.FirstOrDefault(a =>
|
|
|
a.Code.Equals(basePortInfo.Code?.Trim(), StringComparison.OrdinalIgnoreCase)
|
|
|
&& !string.IsNullOrWhiteSpace(a.CarrierCode)
|
|
|
&& a.CarrierCode.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (currPortInfo == null)
|
|
|
{
|
|
|
currPortInfo = ediPortList.FirstOrDefault(a =>
|
|
|
a.Code.Equals(basePortInfo.Code?.Trim(), StringComparison.OrdinalIgnoreCase));
|
|
|
}
|
|
|
|
|
|
if (currPortInfo == null)
|
|
|
throw Oops.Bah($"目的地{primaryModel.DESTINATIONID}的EDI代码未找到");
|
|
|
|
|
|
primaryModel.DESTINATIONID = currPortInfo.MapCode?.Trim();
|
|
|
}
|
|
|
|
|
|
//交货地
|
|
|
if (!string.IsNullOrWhiteSpace(primaryModel.PLACEDELIVERYID))
|
|
|
{
|
|
|
var checkName = portList.Count(a =>
|
|
|
!string.IsNullOrWhiteSpace(a.EdiCode)
|
|
|
&& a.EdiCode.Equals(primaryModel.PLACEDELIVERYID, StringComparison.OrdinalIgnoreCase)) > 1;
|
|
|
|
|
|
var basePortInfo = portList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(a.EdiCode)
|
|
|
&& a.EdiCode.Equals(primaryModel.PLACEDELIVERYID, StringComparison.OrdinalIgnoreCase)
|
|
|
&& (!checkName || a.EnName.Equals(primaryModel.PLACEDELIVERY, StringComparison.OrdinalIgnoreCase)));
|
|
|
|
|
|
if (basePortInfo == null)
|
|
|
throw Oops.Bah($"交货地{primaryModel.PLACEDELIVERYID}基础港口代码未找到");
|
|
|
|
|
|
var currPortInfo = ediPortList.FirstOrDefault(a =>
|
|
|
a.Code.Equals(basePortInfo.Code?.Trim(), StringComparison.OrdinalIgnoreCase)
|
|
|
&& !string.IsNullOrWhiteSpace(a.CarrierCode)
|
|
|
&& a.CarrierCode.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (currPortInfo == null)
|
|
|
{
|
|
|
currPortInfo = ediPortList.FirstOrDefault(a =>
|
|
|
a.Code.Equals(basePortInfo.Code?.Trim(), StringComparison.OrdinalIgnoreCase));
|
|
|
}
|
|
|
|
|
|
if (currPortInfo == null)
|
|
|
throw Oops.Bah($"交货地{primaryModel.PLACEDELIVERYID}的EDI代码未找到");
|
|
|
|
|
|
primaryModel.PLACEDELIVERYID = currPortInfo.MapCode?.Trim();
|
|
|
}
|
|
|
|
|
|
//到付地点
|
|
|
if (!string.IsNullOrWhiteSpace(primaryModel.PAYABLEATID))
|
|
|
{
|
|
|
var checkName = portList.Count(a =>
|
|
|
!string.IsNullOrWhiteSpace(a.EdiCode)
|
|
|
&& a.EdiCode.Equals(primaryModel.PAYABLEATID, StringComparison.OrdinalIgnoreCase)) > 1;
|
|
|
|
|
|
var basePortInfo = portList.FirstOrDefault(a => !string.IsNullOrWhiteSpace(a.EdiCode)
|
|
|
&& a.EdiCode.Equals(primaryModel.PAYABLEATID, StringComparison.OrdinalIgnoreCase)
|
|
|
&& (!checkName || a.EnName.Equals(primaryModel.PAYABLEAT, StringComparison.OrdinalIgnoreCase)));
|
|
|
|
|
|
if (basePortInfo == null)
|
|
|
throw Oops.Bah($"到付地点{primaryModel.PAYABLEATID}基础港口代码未找到");
|
|
|
|
|
|
var currPortInfo = ediPortList.FirstOrDefault(a =>
|
|
|
a.Code.Equals(basePortInfo.Code?.Trim(), StringComparison.OrdinalIgnoreCase)
|
|
|
&& !string.IsNullOrWhiteSpace(a.CarrierCode)
|
|
|
&& a.CarrierCode.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (currPortInfo == null)
|
|
|
{
|
|
|
currPortInfo = ediPortList.FirstOrDefault(a =>
|
|
|
a.Code.Equals(basePortInfo.Code?.Trim(), StringComparison.OrdinalIgnoreCase));
|
|
|
}
|
|
|
|
|
|
if (currPortInfo == null)
|
|
|
throw Oops.Bah($"到付地点{primaryModel.PAYABLEATID}的EDI代码未找到");
|
|
|
|
|
|
primaryModel.PAYABLEATID = currPortInfo.MapCode?.Trim();
|
|
|
}
|
|
|
|
|
|
//起运港是CNTAO并且船公司是太平需要判断场站EDI
|
|
|
if (ediRouteEnum == EDIRouteEnum.WY)
|
|
|
{
|
|
|
//场站
|
|
|
var ediYardList = _cache.GetAllMappingYard().GetAwaiter().GetResult()
|
|
|
.Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)).ToList();
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(order.YARDID))
|
|
|
{
|
|
|
var currYardInfo = ediYardList.FirstOrDefault(t => t.Code.Equals(order.YARDID, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (currYardInfo == null)
|
|
|
throw Oops.Bah($"场站{order.YARDID}的EDI代码未找到");
|
|
|
|
|
|
primaryModel.YARDEDICODE = currYardInfo.MapCode?.Trim();
|
|
|
primaryModel.YARD = currYardInfo.MapName?.Trim();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//ESL、PIL、WY、YML、YT 需要付费方式映射EDI代码
|
|
|
if (ediRouteEnum == EDIRouteEnum.ESL || ediRouteEnum == EDIRouteEnum.PIL || ediRouteEnum == EDIRouteEnum.WY
|
|
|
|| ediRouteEnum == EDIRouteEnum.YML || ediRouteEnum == EDIRouteEnum.YT)
|
|
|
{
|
|
|
//付费方式基础数据
|
|
|
var baseFrtList = _cache.GetAllCodeFrt().GetAwaiter().GetResult();
|
|
|
|
|
|
var baseFrtInfo = baseFrtList.FirstOrDefault(t =>
|
|
|
t.EnName.Equals(order.BLFRT, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (baseFrtInfo == null)
|
|
|
throw Oops.Bah($"付费方式{order.BLFRT}的基础代码未找到");
|
|
|
|
|
|
//付费方式映射
|
|
|
var ediFrtList = _cache.GetAllMappingFrt().GetAwaiter().GetResult()
|
|
|
.Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)
|
|
|
&& !string.IsNullOrWhiteSpace(t.CarrierCode) && t.CarrierCode.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase)
|
|
|
).ToList();
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(order.BLFRT))
|
|
|
{
|
|
|
var currFrtInfo = ediFrtList.FirstOrDefault(t => t.Code.Equals(baseFrtInfo.Code, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (currFrtInfo == null)
|
|
|
throw Oops.Bah($"付费方式{order.BLFRT}的EDI代码未找到");
|
|
|
|
|
|
primaryModel.BLFRTEDICODE = currFrtInfo.MapCode?.Trim();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//运输条款EDI
|
|
|
var baseServiceList = _cache.GetAllCodeService().GetAwaiter().GetResult();
|
|
|
|
|
|
var baseServiceInfo = baseServiceList.FirstOrDefault(t =>
|
|
|
t.Name.Equals(order.SERVICE, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (baseServiceInfo == null)
|
|
|
throw Oops.Bah($"运输条款{order.SERVICE}的基础代码未找到");
|
|
|
|
|
|
//付费方式映射
|
|
|
var ediServiceList = _cache.GetAllMappingService().GetAwaiter().GetResult()
|
|
|
.Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)
|
|
|
&& !string.IsNullOrWhiteSpace(t.CarrierCode) && t.CarrierCode.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase)
|
|
|
).ToList();
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(order.SERVICE))
|
|
|
{
|
|
|
var currServiceInfo = ediServiceList.FirstOrDefault(t => t.Code.Equals(baseServiceInfo.Code, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (currServiceInfo == null)
|
|
|
throw Oops.Bah($"运输条款{order.SERVICE}的EDI代码未找到");
|
|
|
|
|
|
primaryModel.SERVICEEDICODE = currServiceInfo.MapCode?.Trim();
|
|
|
}
|
|
|
|
|
|
primaryModel.CARRIEREDICODE = ediSOSICfg.MapCode;
|
|
|
primaryModel.ORDERNO = order.BOOKINGNO;
|
|
|
|
|
|
var curBasePkgs = basePkgsList.FirstOrDefault(p => p.Name.Equals(order.KINDPKGS, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (curBasePkgs == null)
|
|
|
throw Oops.Bah($"包装{order.KINDPKGS}的基础数据代码未找到");
|
|
|
|
|
|
var ediPkgs = ediPkgsList.FirstOrDefault(x => x.Code.Equals(curBasePkgs.Code, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (ediPkgs == null || string.IsNullOrWhiteSpace(ediPkgs.MapCode))
|
|
|
throw Oops.Bah($"包装{order.KINDPKGS}的EDI代码未找到");
|
|
|
|
|
|
primaryModel.KINDPKGS_EDI_CODE = ediPkgs.MapCode?.Trim();
|
|
|
|
|
|
//这里是订舱时,默认取SOREMARK赋值到EDIREMARK
|
|
|
if (model.sendType == "B")
|
|
|
{
|
|
|
primaryModel.EDIREMARK = order.SOREMARK;
|
|
|
}
|
|
|
|
|
|
primaryModel.S0CC0C = ediExtModel.S0CC0C;
|
|
|
primaryModel.ACIHBL = ediExtModel.ACIHBL;
|
|
|
|
|
|
primaryModel.MasterBOLIndicator = ediExtModel.MasterBolIndicator;
|
|
|
primaryModel.ConsigneeEdiCode = ediExtModel.ConsigneeEdiCode;
|
|
|
primaryModel.ShipperEdiCode = ediExtModel.ShipperEdiCode;
|
|
|
primaryModel.SalesRepCode = ediExtModel.SalerCode;
|
|
|
|
|
|
//优先取订舱的EDI附属信息,为空取FTP配置
|
|
|
primaryModel.EDIATTN = ediExtModel.EDIAttn;
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(primaryModel.EDIATTN))
|
|
|
{
|
|
|
primaryModel.EDIATTN = ftpSet.SENDATTN;
|
|
|
}
|
|
|
primaryModel.EDIATTNTEL = ediExtModel.EDIAttnTel;
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(primaryModel.EDIATTNTEL))
|
|
|
{
|
|
|
primaryModel.EDIATTNTEL = ftpSet.SENDTEL;
|
|
|
}
|
|
|
|
|
|
primaryModel.EDIATTNEMAIL = ediExtModel.EDIAttnMail;
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(primaryModel.EDIATTNEMAIL))
|
|
|
{
|
|
|
primaryModel.EDIATTNEMAIL = ftpSet.SENDEMAIL;
|
|
|
}
|
|
|
|
|
|
primaryModel.AMSCONSIGNEE = ediExtModel.AMSConsignee;
|
|
|
primaryModel.AMSNOTIFYPARTY = ediExtModel.AMSNotifyParty;
|
|
|
|
|
|
primaryModel.OpEName = ediExtModel.OpEName;
|
|
|
primaryModel.OpTel = ediExtModel.OpTel;
|
|
|
primaryModel.OpEmail = ediExtModel.OpEmail;
|
|
|
|
|
|
primaryModel.GOODSNAME = ediExtModel.GoodsName;
|
|
|
|
|
|
primaryModel.cKHI = ediExtModel.CKHI;
|
|
|
primaryModel.cNCM = ediExtModel.CNCM;
|
|
|
primaryModel.wNCM = ediExtModel.WNCM;
|
|
|
primaryModel.ORDERREMARK = ediExtModel.OrderRemark;
|
|
|
|
|
|
primaryModel.KINGTAREWEIGHT = ediExtModel.KingTareweight.HasValue ? ediExtModel.KingTareweight.Value : 0;
|
|
|
|
|
|
//箱信息
|
|
|
var contaList = _repCtn.AsQueryable().Where(t => t.BILLID == order.Id).ToList();
|
|
|
|
|
|
_logger.LogInformation("批次={no} 提取箱完成 数量={total}", batchNo, contaList.Count);
|
|
|
|
|
|
primaryModel.CTNLIST = new List<MsOpSeaeCtnEDIBaseModel>();
|
|
|
|
|
|
|
|
|
//集装箱
|
|
|
foreach (var conta in contaList)
|
|
|
{
|
|
|
var contaModel = conta.Adapt<MsOpSeaeCtnEDIBaseModel>();
|
|
|
|
|
|
//EDI箱型
|
|
|
var currConta = ediCtnList.FirstOrDefault(x => x.Code.Equals(conta.CTNCODE, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (currConta == null)
|
|
|
throw Oops.Oh($"箱型{conta.CTNCODE}的EDI代码未找到");
|
|
|
|
|
|
contaModel.CTNALLCODE = currConta.MapCode;
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(conta.KINDPKGS))
|
|
|
throw Oops.Oh($"集装箱包装不能为空");
|
|
|
|
|
|
var curContaBasePkgs = basePkgsList.FirstOrDefault(p => p.Name.Equals(conta.KINDPKGS, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (curContaBasePkgs == null)
|
|
|
throw Oops.Bah($"包装{conta.KINDPKGS}的基础数据代码未找到");
|
|
|
|
|
|
//EDI包装
|
|
|
var ediContaPkgs = ediPkgsList.FirstOrDefault(x => x.Code.Equals(curContaBasePkgs.Code, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (currConta == null)
|
|
|
throw Oops.Oh($"集装箱包装{conta.KINDPKGS}的EDI代码未找到");
|
|
|
|
|
|
contaModel.KINDPKGS_EDI_CODE = ediContaPkgs.MapCode?.Trim();
|
|
|
|
|
|
primaryModel.CTNLIST.Add(contaModel);
|
|
|
}
|
|
|
|
|
|
//多品名
|
|
|
var cargoList = _ctndetailrep.AsQueryable().Where(t => contaList.Select(a => a.Id).ToArray().Contains(t.CTNID.Value)).ToList();
|
|
|
|
|
|
_logger.LogInformation("批次={no} 提取多品名完成 数量={total}", batchNo, cargoList.Count);
|
|
|
|
|
|
primaryModel.CTNGOODSLIST = new List<MsOpSeaeCtnDetailEDIBaseModel>();
|
|
|
|
|
|
foreach (var cargo in cargoList)
|
|
|
{
|
|
|
MsOpSeaeCtnDetailEDIBaseModel cargoModel = cargo.Adapt<MsOpSeaeCtnDetailEDIBaseModel>();
|
|
|
|
|
|
cargoModel.CNTRNO = contaList.FirstOrDefault(a => a.Id == cargo.CTNID.Value).CNTRNO;
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(cargo.KINDPKGS))
|
|
|
throw Oops.Oh($"多品名包装不能为空");
|
|
|
|
|
|
var curCargoBasePkgs = basePkgsList.FirstOrDefault(p => p.Name.Equals(cargo.KINDPKGS, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (curCargoBasePkgs == null)
|
|
|
throw Oops.Bah($"包装{cargo.KINDPKGS}的基础数据代码未找到");
|
|
|
|
|
|
var ediDetailPkgs = ediPkgsList.FirstOrDefault(x => x.Code.Equals(curCargoBasePkgs.Code, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (ediDetailPkgs == null)
|
|
|
throw Oops.Oh($"货明细的包装{cargo.KINDPKGS}的EDI代码未找到");
|
|
|
|
|
|
cargoModel.KINDPKGS_EDI_CODE = ediDetailPkgs.MapCode?.Trim();
|
|
|
|
|
|
primaryModel.CTNGOODSLIST.Add(cargoModel);
|
|
|
}
|
|
|
|
|
|
ediModel.BSLIST.Add(primaryModel);
|
|
|
|
|
|
var result = await InnerSendBookingOrClosingEDI(model, ediModel, ediRouteEnum);
|
|
|
|
|
|
_logger.LogInformation("批次={no} 生成EDI文件完成 结果={result}", batchNo, JSON.Serialize(result));
|
|
|
|
|
|
if (!result.succ)
|
|
|
{
|
|
|
throw Oops.Bah(result.msg);
|
|
|
}
|
|
|
|
|
|
if (model.send)
|
|
|
{
|
|
|
string currFilePath = string.Empty;
|
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
{
|
|
|
currFilePath = System.Text.RegularExpressions.Regex.Match(result.extra.ToString(), relativePath.Replace("/", "\\/") + ".*").Value;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
currFilePath = System.Text.RegularExpressions.Regex.Match(result.extra.ToString(), relativePath.Replace("\\", "\\\\") + ".*").Value;
|
|
|
}
|
|
|
|
|
|
//这里先写入附件表
|
|
|
await SaveEDIFile(model.Id, currFilePath, new System.IO.FileInfo(currFilePath).Name);
|
|
|
|
|
|
_logger.LogInformation("批次={no} 直接发送FTP 文件访问地址={filepath}", batchNo, result.extra.ToString());
|
|
|
|
|
|
DateTime bDate = DateTime.Now;
|
|
|
|
|
|
//上传FTP
|
|
|
CommonWebApiResult sendStatus = null;
|
|
|
|
|
|
//是否发送邮件,EDI这里主要分2种通道发送 默认是FTP,如果配置里指定了接收接收邮箱,就需要推送邮件
|
|
|
bool isSendEmail = false;
|
|
|
|
|
|
//是订舱并且FTP配置了订舱接收邮箱则触发邮箱发送
|
|
|
if (ftpSet.SendType.Equals("SO", StringComparison.OrdinalIgnoreCase)
|
|
|
&& model.sendType.Equals("B", StringComparison.OrdinalIgnoreCase)
|
|
|
&& !string.IsNullOrWhiteSpace(ftpSet.RECEIVEEMAIL))
|
|
|
{
|
|
|
isSendEmail = true;
|
|
|
}
|
|
|
else if (ftpSet.SendType.Equals("SI", StringComparison.OrdinalIgnoreCase)
|
|
|
&& model.sendType.Equals("E", StringComparison.OrdinalIgnoreCase)
|
|
|
&& !string.IsNullOrWhiteSpace(ftpSet.RECEIVEEMAIL))
|
|
|
{
|
|
|
isSendEmail = true;
|
|
|
}
|
|
|
else if (string.IsNullOrWhiteSpace(ftpSet.SendType)
|
|
|
&& !string.IsNullOrWhiteSpace(ftpSet.RECEIVEEMAIL))
|
|
|
{
|
|
|
isSendEmail = true;
|
|
|
}
|
|
|
|
|
|
if (isSendEmail)
|
|
|
{
|
|
|
//推送订舱邮件
|
|
|
sendStatus = await InnerSendBookingOrClosingEDIToEmail(order, result.extra.ToString(),
|
|
|
model.sendType, result.extra2.ToString(), ftpSet);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sendStatus = await InnerSendBookingOrClosingEDIToFTP(result.extra.ToString(), ftpSet);
|
|
|
}
|
|
|
|
|
|
DateTime eDate = DateTime.Now;
|
|
|
TimeSpan ts = eDate.Subtract(bDate);
|
|
|
var timeDiff = ts.TotalMilliseconds;
|
|
|
|
|
|
_logger.LogInformation("批次={no} 发送完成,耗时:{timeDiff}ms. 结果{msg}", batchNo, timeDiff, sendStatus.succ ? "成功" : "失败");
|
|
|
|
|
|
var logId = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog
|
|
|
{
|
|
|
Type = "Trace",
|
|
|
BookingId = model.Id,
|
|
|
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
|
|
|
CreatedTime = DateTime.Now,
|
|
|
CreatedUserId = UserManager.UserId,
|
|
|
CreatedUserName = UserManager.Name
|
|
|
});
|
|
|
|
|
|
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
|
|
|
{
|
|
|
PId = logId,
|
|
|
Field = String.Empty,
|
|
|
OldValue = String.Empty,
|
|
|
NewValue = $"发送 {order.CARRIERID} EDI 类型={model.sendType} 通过{(isSendEmail ? "邮件" : "FTP")} {(sendStatus.succ ? "成功" : "失败")}",
|
|
|
});
|
|
|
|
|
|
if (!sendStatus.succ)
|
|
|
{
|
|
|
throw Oops.Bah($"发送失败,原因:{sendStatus.msg}");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
return result.extra.ToString();
|
|
|
}
|
|
|
|
|
|
[NonAction]
|
|
|
private async Task SaveEDIFile(long boookId, string FilePath, string fileName, string fileTypeCode = "edi", string fileTypeName = "EDI文件")
|
|
|
{
|
|
|
/*
|
|
|
直接将附件信息写入附件表
|
|
|
*/
|
|
|
//EDI文件
|
|
|
var bookFile = new BookingFile
|
|
|
{
|
|
|
Id = YitIdHelper.NextId(),
|
|
|
FileName = fileName,
|
|
|
FilePath = FilePath,
|
|
|
TypeCode = fileTypeCode,
|
|
|
TypeName = fileTypeName,
|
|
|
BookingId = boookId,
|
|
|
};
|
|
|
|
|
|
await _bookingfile.InsertAsync(bookFile);
|
|
|
}
|
|
|
|
|
|
#region 下载订舱、截单EDI
|
|
|
/// <summary>
|
|
|
/// 下载订舱、截单EDI
|
|
|
/// </summary>
|
|
|
/// <param name="id">订单主键</param>
|
|
|
/// <param name="orderNo">订单号</param>
|
|
|
/// <param name="useForwarderCode">是否使用货代代码</param>
|
|
|
/// <param name="forwarderCode">货代代码</param>
|
|
|
/// <param name="forwarderName">货代称呼</param>
|
|
|
/// <param name="fileRole">文件功能 (9原始,1 更新,5 退舱 )</param>
|
|
|
/// <param name="sendType">发送类型 B-订舱 E-截单</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/DownloadBookingOrClosingEDI")]
|
|
|
public IActionResult DownloadBookingOrClosingEDI([FromQuery] long id, [FromQuery] string orderNo, [FromQuery] bool useForwarderCode,
|
|
|
[FromQuery] string forwarderCode, [FromQuery] string forwarderName, [FromQuery] string fileRole, [FromQuery] string sendType)
|
|
|
{
|
|
|
var model = new BookingOrClosingEDIOrderDto
|
|
|
{
|
|
|
Id = id,
|
|
|
orderNo = orderNo,
|
|
|
useForwarderCode = useForwarderCode,
|
|
|
forwarderCode = forwarderCode,
|
|
|
forwarderName = forwarderName,
|
|
|
fileRole = fileRole,
|
|
|
send = false,
|
|
|
sendType = sendType
|
|
|
};
|
|
|
var filePath = InnerBookingOrClosingEDI(model).GetAwaiter().GetResult();
|
|
|
|
|
|
var fileInfo = new FileInfo(filePath);
|
|
|
|
|
|
var result = new FileStreamResult(new FileStream(filePath, FileMode.Open), "application/octet-stream") { FileDownloadName = fileInfo.Name };
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 上传FTP
|
|
|
/// <summary>
|
|
|
/// 上传FTP
|
|
|
/// </summary>
|
|
|
/// <param name="filePath">EDI文件路径</param>
|
|
|
/// <param name="ediCfg">FTP配置</param>
|
|
|
/// <returns>返回回执</returns>
|
|
|
private async Task<CommonWebApiResult> InnerSendBookingOrClosingEDIToFTP(string filePath, DjyEdiSetting ediCfg)
|
|
|
{
|
|
|
CommonWebApiResult result = new CommonWebApiResult { succ = true };
|
|
|
|
|
|
CancellationTokenSource cts = new CancellationTokenSource();
|
|
|
|
|
|
string host = string.Empty;
|
|
|
string port = string.Empty;
|
|
|
|
|
|
if (ediCfg.SERVERIP.IndexOf(":") >= 0)
|
|
|
{
|
|
|
host = ediCfg.SERVERIP.Split(new char[] { ':' }).FirstOrDefault().Trim();
|
|
|
port = ediCfg.SERVERIP.Split(new char[] { ':' }).Last()?.Trim();
|
|
|
}
|
|
|
|
|
|
NameValueCollection par = new NameValueCollection();
|
|
|
par.Add("host", host);
|
|
|
par.Add("port", port);
|
|
|
par.Add("username", ediCfg.USERNAME);
|
|
|
par.Add("pwd", ediCfg.PASSWORD);
|
|
|
par.Add("path", ediCfg.FOLDERNAME);
|
|
|
|
|
|
var ftpSpiderUrl = _cache.GetAllDictData().GetAwaiter().GetResult()
|
|
|
.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "booking_edi_ftp_server")?.Value;
|
|
|
|
|
|
if (ftpSpiderUrl == null)
|
|
|
throw Oops.Bah("字典未配置 url_set->booking_edi_ftp_server 请联系管理员");
|
|
|
|
|
|
//var fileInfo = new FileInfo(filePath);
|
|
|
|
|
|
_logger.LogInformation($"准备请求发送ftp:{ftpSpiderUrl} ,参数:{JSON.Serialize(par)},文件:{filePath}");
|
|
|
|
|
|
|
|
|
System.IO.FileStream file = new System.IO.FileStream(filePath, FileMode.Open, FileAccess.Read);
|
|
|
int SplitSize = 5242880;//5M分片长度
|
|
|
int index = 1; //序号 第几片
|
|
|
long StartPosition = 5242880 * (index - 1);
|
|
|
long lastLens = file.Length - StartPosition;//真不知道怎么起命了,就这样吧
|
|
|
if (lastLens < 5242880)
|
|
|
{
|
|
|
SplitSize = (int)lastLens;
|
|
|
}
|
|
|
byte[] heByte = new byte[SplitSize];
|
|
|
file.Seek(StartPosition, SeekOrigin.Begin);
|
|
|
//第一个参数是 起始位置
|
|
|
file.Read(heByte, 0, SplitSize);
|
|
|
//第三个参数是 读取长度(剩余长度)
|
|
|
file.Close();
|
|
|
|
|
|
string strJoin = System.IO.File.ReadAllText(filePath);
|
|
|
|
|
|
DateTime bDate = DateTime.Now;
|
|
|
|
|
|
_logger.LogInformation("FTP 开始上传");
|
|
|
|
|
|
var res = FTPHelper.TransmitFtpFile(ftpSpiderUrl, par, new
|
|
|
{
|
|
|
file = "file",
|
|
|
fileName = Path.GetFileName(filePath),
|
|
|
fileBytes = heByte
|
|
|
});
|
|
|
|
|
|
DateTime eDate = DateTime.Now;
|
|
|
TimeSpan ts = eDate.Subtract(bDate);
|
|
|
var timeDiff = ts.TotalMilliseconds;
|
|
|
|
|
|
_logger.LogInformation($"FTP 上传完成 上传文件大小:{heByte.Length} 用时:{timeDiff}ms.,{strJoin}");
|
|
|
|
|
|
_logger.LogInformation($"发送ftp返回:{res}");
|
|
|
|
|
|
var jobjRetn = JObject.Parse(res);
|
|
|
|
|
|
if (jobjRetn.GetStringValue("status") != "1")
|
|
|
{
|
|
|
result.succ = false;
|
|
|
result.msg = jobjRetn.GetStringValue("message");
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 上传邮件
|
|
|
/// <summary>
|
|
|
/// 上传邮件
|
|
|
/// </summary>
|
|
|
/// <param name="bookingOrder">订舱详情</param>
|
|
|
/// <param name="filePath">文件路径</param>
|
|
|
/// <param name="sendType">请求类型</param>
|
|
|
/// <param name="ediCfg">EDI配置</param>
|
|
|
/// <returns>返回回执</returns>
|
|
|
private async Task<CommonWebApiResult> InnerSendBookingOrClosingEDIToEmail(BookingOrder bookingOrder, string filePath,
|
|
|
string sendType, string emailTopic, DjyEdiSetting ediCfg)
|
|
|
{
|
|
|
CommonWebApiResult result = new CommonWebApiResult { succ = true };
|
|
|
|
|
|
var emailUrl = _cache.GetAllDictData().GetAwaiter().GetResult()
|
|
|
.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "email_api_url")?.Value;
|
|
|
|
|
|
if (emailUrl == null)
|
|
|
throw Oops.Bah("字典未配置 url_set->email_api_url 请联系管理员");
|
|
|
|
|
|
List<EmailApiDto> emailList = new List<EmailApiDto>();
|
|
|
|
|
|
EmailApiDto emailApiDto = new EmailApiDto
|
|
|
{
|
|
|
SendTo = ediCfg.RECEIVEEMAIL,
|
|
|
Title = emailTopic,
|
|
|
Attaches = new List<AttachesInfo>(),
|
|
|
Body = emailTopic,
|
|
|
};
|
|
|
|
|
|
System.IO.FileStream file = new System.IO.FileStream(filePath, FileMode.Open, FileAccess.Read);
|
|
|
int SplitSize = 5242880;//5M分片长度
|
|
|
int index = 1; //序号 第几片
|
|
|
long StartPosition = 5242880 * (index - 1);
|
|
|
long lastLens = file.Length - StartPosition;//真不知道怎么起命了,就这样吧
|
|
|
if (lastLens < 5242880)
|
|
|
{
|
|
|
SplitSize = (int)lastLens;
|
|
|
}
|
|
|
byte[] heByte = new byte[SplitSize];
|
|
|
file.Seek(StartPosition, SeekOrigin.Begin);
|
|
|
//第一个参数是 起始位置
|
|
|
file.Read(heByte, 0, SplitSize);
|
|
|
//第三个参数是 读取长度(剩余长度)
|
|
|
file.Close();
|
|
|
|
|
|
string base64Str = Convert.ToBase64String(heByte);
|
|
|
|
|
|
emailApiDto.Attaches.Add(new AttachesInfo
|
|
|
{
|
|
|
AttachName = Path.GetFileName(filePath),
|
|
|
AttachContent = base64Str
|
|
|
});
|
|
|
|
|
|
emailList.Add(emailApiDto);
|
|
|
|
|
|
string strJoin = System.IO.File.ReadAllText(filePath);
|
|
|
|
|
|
DateTime bDate = DateTime.Now;
|
|
|
|
|
|
HttpResponseMessage res = null;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
res = await emailUrl.SetBody(emailList, "application/json").PostAsync();
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
_logger.LogInformation($"发送邮件异常:{ex.Message}");
|
|
|
}
|
|
|
|
|
|
DateTime eDate = DateTime.Now;
|
|
|
TimeSpan ts = eDate.Subtract(bDate);
|
|
|
var timeDiff = ts.TotalMilliseconds;
|
|
|
|
|
|
_logger.LogInformation($"邮件上传完成 上传文件大小:{heByte.Length} 用时:{timeDiff}ms.,{strJoin}");
|
|
|
|
|
|
_logger.LogInformation($"发送邮件返回:{JSON.Serialize(res)}");
|
|
|
|
|
|
if (res != null && res.StatusCode == System.Net.HttpStatusCode.OK)
|
|
|
{
|
|
|
var userResult = await res.Content.ReadAsStringAsync();
|
|
|
|
|
|
var respObj = JsonConvert.DeserializeAnonymousType(userResult, new
|
|
|
{
|
|
|
Success = false,
|
|
|
Message = string.Empty,
|
|
|
Code = -9999,
|
|
|
});
|
|
|
|
|
|
result.succ = respObj.Success;
|
|
|
result.msg = respObj.Message;
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region
|
|
|
/// <summary>
|
|
|
/// 转发EDI内部方法
|
|
|
/// </summary>
|
|
|
/// <param name="requestUrl">请求接口地址</param>
|
|
|
/// <param name="nameValueCollection">键值对参数</param>
|
|
|
/// <param name="fileInfo">文件信息</param>
|
|
|
/// <param name="contentType">默认 application/json</param>
|
|
|
/// <returns>返回结果</returns>
|
|
|
private static string TransmitFtpFile(string requestUrl, NameValueCollection nameValueCollection, dynamic fileInfo,
|
|
|
string contentType = "application/json")
|
|
|
{
|
|
|
var result = string.Empty;
|
|
|
|
|
|
using (var httpClient = new HttpClient())
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
using (var reduceAttach = new MultipartFormDataContent())
|
|
|
{
|
|
|
string[] allKeys = nameValueCollection.AllKeys;
|
|
|
foreach (string key in allKeys)
|
|
|
{
|
|
|
var dataContent = new ByteArrayContent(Encoding.UTF8.GetBytes(nameValueCollection[key]));
|
|
|
|
|
|
dataContent.Headers.ContentDisposition = new ContentDispositionHeaderValue($"form-data")
|
|
|
{
|
|
|
Name = key
|
|
|
};
|
|
|
|
|
|
reduceAttach.Add(dataContent);
|
|
|
}
|
|
|
|
|
|
#region 文件参数
|
|
|
if (fileInfo != null)
|
|
|
{
|
|
|
var Content = new ByteArrayContent(fileInfo.fileBytes);
|
|
|
|
|
|
//Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
|
|
|
//{
|
|
|
// Name = fileInfo.file.ToString(),
|
|
|
// FileName = fileInfo.fileName.ToString(),
|
|
|
|
|
|
//};
|
|
|
|
|
|
Content.Headers.Add("Content-Type", contentType);
|
|
|
|
|
|
reduceAttach.Add(Content, fileInfo.file.ToString(), HttpUtility.UrlEncode(fileInfo.fileName.ToString()));
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
//请求
|
|
|
var response = httpClient.PostAsync(requestUrl, reduceAttach).Result;
|
|
|
result = response.Content.ReadAsStringAsync().Result;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
result = JSON.Serialize(new
|
|
|
{
|
|
|
message = $"{nameof(TransmitFtpFile)} 转发EDI内部方法异常,原因:{ex.Message}",
|
|
|
status = 0
|
|
|
});
|
|
|
}
|
|
|
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 触发订舱
|
|
|
/// <summary>
|
|
|
/// 触发订舱
|
|
|
/// </summary>
|
|
|
/// <param name="model"></param>
|
|
|
/// <param name="ediModel"></param>
|
|
|
/// <param name="ediRouteEnum"></param>
|
|
|
/// <returns></returns>
|
|
|
[NonAction]
|
|
|
private async Task<CommonWebApiResult> InnerSendBookingOrClosingEDI(BookingOrClosingEDIOrderDto model, EDIBaseModel ediModel, EDIRouteEnum ediRouteEnum)
|
|
|
{
|
|
|
CommonWebApiResult result = new CommonWebApiResult();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
if (ediRouteEnum == EDIRouteEnum.PIL)
|
|
|
{
|
|
|
#region PIL
|
|
|
string strCheck = PILEdiHelper.IsCreatePILEDI(ediModel);
|
|
|
|
|
|
_logger.LogInformation($"调用SO(SI),校验:{strCheck},数据对象:{JsonConvert.SerializeObject(ediModel)}");
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(strCheck))
|
|
|
{
|
|
|
if (Regex.IsMatch(strCheck, "\\<br\\s{1,}/\\>"))
|
|
|
{
|
|
|
strCheck = Regex.Replace(strCheck, "\\<br\\s{1,}/\\>", "\n");
|
|
|
}
|
|
|
|
|
|
throw Oops.Bah($"发送{EDIRouteEnum.PIL.ToString()}校验失败,{strCheck}");
|
|
|
}
|
|
|
|
|
|
|
|
|
var currRlt = PILEdiHelper.CreateEdiPIL(ediModel);
|
|
|
#endregion
|
|
|
result.succ = currRlt.succ;
|
|
|
result.extra = currRlt.succ ? currRlt.extra.ToString() : "";
|
|
|
result.extra2 = currRlt.succ ? currRlt.extra2.ToString() : "";
|
|
|
}
|
|
|
else if (ediRouteEnum == EDIRouteEnum.TSL)
|
|
|
{
|
|
|
#region TSL
|
|
|
string strCheck = TSLEdiHelper.IsCreateTSL(ediModel);
|
|
|
|
|
|
_logger.LogInformation($"调用SO(SI),校验:{strCheck},数据对象:{JsonConvert.SerializeObject(ediModel)}");
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(strCheck))
|
|
|
{
|
|
|
if (Regex.IsMatch(strCheck, "\\<br\\s{1,}/\\>"))
|
|
|
{
|
|
|
strCheck = Regex.Replace(strCheck, "\\<br\\s{1,}/\\>", "\n");
|
|
|
}
|
|
|
|
|
|
throw Oops.Bah($"发送{EDIRouteEnum.TSL.ToString()}校验失败,{strCheck}");
|
|
|
}
|
|
|
|
|
|
CommonWebApiResult currRlt = new CommonWebApiResult();
|
|
|
|
|
|
if (model.sendType == "B")
|
|
|
{
|
|
|
currRlt = TSLEdiHelper.CreateEdiTSL(ediModel);
|
|
|
}
|
|
|
else if (model.sendType == "E")
|
|
|
{
|
|
|
currRlt = TSLEdiHelper.CreateEdiTSLSI(ediModel);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
result.succ = currRlt.succ;
|
|
|
result.extra = currRlt.succ ? currRlt.extra.ToString() : "";
|
|
|
}
|
|
|
else if (ediRouteEnum == EDIRouteEnum.WY)
|
|
|
{
|
|
|
#region WY
|
|
|
string strCheck = WYEdiHelper.IsCreateWYEDI(ediModel);
|
|
|
|
|
|
_logger.LogInformation($"调用SO(SI),校验:{strCheck},数据对象:{JsonConvert.SerializeObject(ediModel)}");
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(strCheck))
|
|
|
{
|
|
|
if (Regex.IsMatch(strCheck, "\\<br\\s{1,}/\\>"))
|
|
|
{
|
|
|
strCheck = Regex.Replace(strCheck, "\\<br\\s{1,}/\\>", "\n");
|
|
|
}
|
|
|
throw Oops.Bah($"发送{EDIRouteEnum.WY.ToString()}校验失败,{strCheck}");
|
|
|
}
|
|
|
|
|
|
var currRlt = WYEdiHelper.CreateEdiWY(ediModel);
|
|
|
#endregion
|
|
|
|
|
|
result.succ = currRlt.succ;
|
|
|
result.extra = currRlt.succ ? currRlt.extra.ToString() : "";
|
|
|
}
|
|
|
else if (ediRouteEnum == EDIRouteEnum.YML)
|
|
|
{
|
|
|
#region YML
|
|
|
string strCheck = YMLEdiHelper.IsCreateYMLEDI(ediModel);
|
|
|
|
|
|
_logger.LogInformation($"调用SO(SI),校验:{strCheck},数据对象:{JsonConvert.SerializeObject(ediModel)}");
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(strCheck))
|
|
|
{
|
|
|
if (Regex.IsMatch(strCheck, "\\<br\\s{1,}/\\>"))
|
|
|
{
|
|
|
strCheck = Regex.Replace(strCheck, "\\<br\\s{1,}/\\>", "\n");
|
|
|
}
|
|
|
|
|
|
throw Oops.Bah($"发送{EDIRouteEnum.YML.ToString()}校验失败,{strCheck}");
|
|
|
}
|
|
|
|
|
|
CommonWebApiResult currRlt = new CommonWebApiResult();
|
|
|
|
|
|
if (model.sendType == "B")
|
|
|
{
|
|
|
currRlt = YMLEdiHelper.CreateEdiYML(ediModel);
|
|
|
}
|
|
|
else if (model.sendType == "E")
|
|
|
{
|
|
|
currRlt = YMLEdiHelper.CreateEdiYMLSI(ediModel);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
result.succ = currRlt.succ;
|
|
|
result.extra = currRlt.succ ? currRlt.extra.ToString() : "";
|
|
|
}
|
|
|
else if (ediRouteEnum == EDIRouteEnum.YT)
|
|
|
{
|
|
|
#region YT
|
|
|
string strCheck = YTEdiHelper.IsCreateYTEDI(ediModel);
|
|
|
|
|
|
_logger.LogInformation($"调用SO(SI),校验:{strCheck},数据对象:{JsonConvert.SerializeObject(ediModel)}");
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(strCheck))
|
|
|
{
|
|
|
if (Regex.IsMatch(strCheck, "\\<br\\s{1,}/\\>"))
|
|
|
{
|
|
|
strCheck = Regex.Replace(strCheck, "\\<br\\s{1,}/\\>", "\n");
|
|
|
}
|
|
|
|
|
|
throw Oops.Bah($"发送{EDIRouteEnum.YT.ToString()}校验失败,{strCheck}");
|
|
|
}
|
|
|
|
|
|
|
|
|
CommonWebApiResult currRlt = YTEdiHelper.CreateEdiYT(ediModel);
|
|
|
#endregion
|
|
|
|
|
|
result.succ = currRlt.succ;
|
|
|
result.extra = currRlt.succ ? currRlt.extra.ToString() : "";
|
|
|
}
|
|
|
else if (ediRouteEnum == EDIRouteEnum.ESL)
|
|
|
{
|
|
|
#region ESL
|
|
|
string strCheck = ESLEdiHelper.IsCreateESLEDI(ediModel);
|
|
|
|
|
|
_logger.LogInformation($"调用SO(SI),校验:{strCheck},数据对象:{JsonConvert.SerializeObject(ediModel)}");
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(strCheck))
|
|
|
{
|
|
|
if (Regex.IsMatch(strCheck, "\\<br\\s{1,}/\\>"))
|
|
|
{
|
|
|
strCheck = Regex.Replace(strCheck, "\\<br\\s{1,}/\\>", "\n");
|
|
|
}
|
|
|
|
|
|
throw Oops.Bah($"发送{EDIRouteEnum.ESL.ToString()}校验失败,{strCheck}");
|
|
|
}
|
|
|
|
|
|
|
|
|
CommonWebApiResult currRlt = ESLEdiHelper.CreateEdiESL(ediModel);
|
|
|
#endregion
|
|
|
|
|
|
result.succ = currRlt.succ;
|
|
|
result.extra = currRlt.succ ? currRlt.extra.ToString() : "";
|
|
|
}
|
|
|
else if (ediRouteEnum == EDIRouteEnum.MELL)
|
|
|
{
|
|
|
#region MELL
|
|
|
string strCheck = MellEdiHelper.IsCreatePILMELL(ediModel);
|
|
|
|
|
|
_logger.LogInformation($"调用SO(SI),校验:{strCheck},数据对象:{JsonConvert.SerializeObject(ediModel)}");
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(strCheck))
|
|
|
{
|
|
|
if (Regex.IsMatch(strCheck, "\\<br\\s{1,}/\\>"))
|
|
|
{
|
|
|
strCheck = Regex.Replace(strCheck, "\\<br\\s{1,}/\\>", "\n");
|
|
|
}
|
|
|
|
|
|
throw Oops.Bah($"发送{EDIRouteEnum.MELL.ToString()}校验失败,{strCheck}");
|
|
|
}
|
|
|
|
|
|
|
|
|
var currRlt = MellEdiHelper.CreateEdiPILMELL(ediModel);
|
|
|
#endregion
|
|
|
result.succ = currRlt.succ;
|
|
|
result.extra = currRlt.succ ? currRlt.extra.ToString() : "";
|
|
|
result.extra2 = currRlt.succ ? currRlt.extra2.ToString() : "";
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
result.succ = false;
|
|
|
result.msg = ex.Message;
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 检查订舱、截单EDI订单信息
|
|
|
/// <summary>
|
|
|
/// 检查订舱、截单EDI订单信息
|
|
|
/// </summary>
|
|
|
/// <param name="order"></param>
|
|
|
[NonAction]
|
|
|
private void CheckBookingOrClosingEDI(BookingOrder order)
|
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(order.CARRIERID))
|
|
|
throw Oops.Bah("船公司必须填写");
|
|
|
|
|
|
//if (string.IsNullOrWhiteSpace(order.OPID))
|
|
|
// throw Oops.Bah("未填写操作人");
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(order.KINDPKGS))
|
|
|
throw Oops.Bah("包装种类未填写");
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 根据船公司ID获取EDI的路由枚举
|
|
|
/// <summary>
|
|
|
/// 根据船公司ID获取EDI的路由枚举
|
|
|
/// </summary>
|
|
|
/// <param name="carrierId">船公司ID</param>
|
|
|
/// <returns>返回适用的路由枚举</returns>
|
|
|
[NonAction]
|
|
|
private EDIRouteEnum GetEDIRoute(string carrierId)
|
|
|
{
|
|
|
EDIRouteEnum routeEnum = EDIRouteEnum.NULL;
|
|
|
|
|
|
var ediRouteCfg = _cache.GetAllMappingCarrier().GetAwaiter().GetResult()
|
|
|
.FirstOrDefault(t => t.Module.Equals(CONST_MAPPING_MODULE_ROUTE, StringComparison.OrdinalIgnoreCase)
|
|
|
&& t.Code.Equals(carrierId, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
if (ediRouteCfg != null && !string.IsNullOrWhiteSpace(ediRouteCfg.MapCode))
|
|
|
routeEnum = (EDIRouteEnum)System.Enum.Parse(typeof(EDIRouteEnum), ediRouteCfg.MapCode);
|
|
|
|
|
|
//switch (carrierId.ToUpper())
|
|
|
//{
|
|
|
// case "PIL":
|
|
|
// routeEnum = EDIRouteEnum.PIL;
|
|
|
// break;
|
|
|
// case "ONE":
|
|
|
// routeEnum = EDIRouteEnum.YT;
|
|
|
// break;
|
|
|
// case "TSL":
|
|
|
// routeEnum = EDIRouteEnum.TSL;
|
|
|
// break;
|
|
|
// case "YML":
|
|
|
// routeEnum = EDIRouteEnum.YML;
|
|
|
// break;
|
|
|
// case "WY":
|
|
|
// routeEnum = EDIRouteEnum.WY;
|
|
|
// break;
|
|
|
//}
|
|
|
|
|
|
return routeEnum;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region ocr
|
|
|
|
|
|
/// <summary>
|
|
|
/// 上传ocr文件
|
|
|
/// </summary>
|
|
|
/// <param name="file"></param>
|
|
|
/// <param name="bookingId">订舱id</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/BookingOrder/OcrUpFile")]
|
|
|
public async Task<string> OcrUpFile(IFormFile file, long bookingId)
|
|
|
{
|
|
|
//未上传文件
|
|
|
if (file == null || file.Length == 0)
|
|
|
{
|
|
|
throw Oops.Bah("未上传文件");
|
|
|
}
|
|
|
|
|
|
//保存到订舱
|
|
|
await AddFile(file, new BookingFileDto()
|
|
|
{
|
|
|
BookingId = bookingId,
|
|
|
TypeCode = "other",
|
|
|
TypeName = "其他"
|
|
|
});
|
|
|
|
|
|
var originalFilename = file.FileName; // 文件原始名称
|
|
|
var fileSuffix = Path.GetExtension(file.FileName).ToLower(); // 文件后缀
|
|
|
|
|
|
var serverUrl = (await _cache.GetAllDictData()).FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "ocr_api_url").Value;
|
|
|
if (!serverUrl.EndsWith("/"))
|
|
|
{
|
|
|
serverUrl += "/";
|
|
|
}
|
|
|
|
|
|
var ms = new MemoryStream();
|
|
|
await file.CopyToAsync(ms);
|
|
|
_logger.LogInformation($"调用ocr处理文件{originalFilename}");
|
|
|
|
|
|
//Furion框架上传文件名称带有双引号,导致上传失败
|
|
|
//var strRtn = await $"{serverUrl}pdf/upload"
|
|
|
// .SetContentType("multipart/form-data")
|
|
|
// .SetContentEncoding(Encoding.UTF8)
|
|
|
// .SetBodyBytes(("file", ms.GetBuffer(), "test.pdf"))
|
|
|
// .PostAsStringAsync();
|
|
|
//var jobj = strRtn.ToJObject();
|
|
|
//if (jobj.GetIntValue("code") == 0)
|
|
|
//{
|
|
|
// var fn = jobj.GetStringValue("data");
|
|
|
// return fn;
|
|
|
//}
|
|
|
//else
|
|
|
//{
|
|
|
// throw Oops.Bah(jobj.GetStringValue("message"));
|
|
|
//}
|
|
|
|
|
|
//使用HttpClient方式上传文件
|
|
|
ms.Position = 0;
|
|
|
var formData = new MultipartFormDataContent();
|
|
|
formData.Add(new StreamContent(ms, (int)ms.Length), "file", originalFilename);
|
|
|
var _httpclient = new HttpClient();
|
|
|
var response = await _httpclient.PostAsync($"{serverUrl}pdf/upload", formData);
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
{
|
|
|
var strRtn = response.Content.ReadAsStringAsync().Result;
|
|
|
var jobj = strRtn.ToJObject();
|
|
|
if (jobj.GetIntValue("code") == 0)
|
|
|
{
|
|
|
var fn = jobj.GetStringValue("data");
|
|
|
return fn;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
throw Oops.Bah(jobj.GetStringValue("message"));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
throw Oops.Bah("文件上传失败");
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取图片
|
|
|
/// </summary>
|
|
|
/// <param name="fileName">文件名称</param>
|
|
|
/// <param name="scale">缩放比例,默认为1.5</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/BookingOrder/OcrGetImg")]
|
|
|
public async Task<IActionResult> OcrGetImg(string fileName, float scale = 1.5f)
|
|
|
{
|
|
|
var serverUrl = (await _cache.GetAllDictData()).FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "ocr_api_url").Value;
|
|
|
if (!serverUrl.EndsWith("/"))
|
|
|
{
|
|
|
serverUrl += "/";
|
|
|
}
|
|
|
|
|
|
var bs = await $"{serverUrl}pdf/getCanvasImage?fileName={fileName}&scale={scale}"
|
|
|
.GetAsByteArrayAsync();
|
|
|
var result = new FileContentResult(bs, "application/octet-stream") { FileDownloadName = "ocr.jpg" };
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取文字
|
|
|
/// </summary>
|
|
|
/// <param name="fileName">文件名称</param>
|
|
|
/// <param name="scale">缩放比例</param>
|
|
|
/// <param name="x">x坐标</param>
|
|
|
/// <param name="y">y坐标</param>
|
|
|
/// <param name="w">宽度</param>
|
|
|
/// <param name="h">高度</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/BookingOrder/OcrGetText")]
|
|
|
public async Task<string> OcrGetText(string fileName, float scale, int x, int y, int w, int h)
|
|
|
{
|
|
|
var serverUrl = (await _cache.GetAllDictData()).FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "ocr_api_url").Value;
|
|
|
if (!serverUrl.EndsWith("/"))
|
|
|
{
|
|
|
serverUrl += "/";
|
|
|
}
|
|
|
|
|
|
var str = await $"{serverUrl}pdf/getRegionText?fileName={fileName}&scale={scale}&x={x}&y={y}&w={w}&h={h}"
|
|
|
.PostAsStringAsync();
|
|
|
return str;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 其他
|
|
|
/// <summary>
|
|
|
/// 获取用户报表的json
|
|
|
/// </summary>
|
|
|
/// <param name="id"></param>
|
|
|
[HttpGet("/BookingOrder/GenReportJson")]
|
|
|
public async Task<IActionResult> GenReportJson(long id)
|
|
|
{
|
|
|
var jsonUrl = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "url_report_generate").Value;
|
|
|
if (!jsonUrl.EndsWith("/"))
|
|
|
{
|
|
|
jsonUrl += "/";
|
|
|
}
|
|
|
|
|
|
jsonUrl += "Report/BookingReportJson?bookingId=" + id;
|
|
|
|
|
|
var rtn = await jsonUrl.SetHttpMethod(HttpMethod.Get).GetAsStringAsync();
|
|
|
var fileName = HttpUtility.UrlEncode($"{id}.json", Encoding.GetEncoding("UTF-8"));
|
|
|
var result = new FileContentResult(Encoding.UTF8.GetBytes(rtn), "application/octet-stream") { FileDownloadName = fileName };
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 生成报表文件
|
|
|
/// </summary>
|
|
|
/// <param name="id"></param>
|
|
|
/// <param name="type">类型,对应字典中的【订舱打印模板类型】</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/GenReportFile")]
|
|
|
public async Task<IActionResult> GenReportFile(long id, string type)
|
|
|
{
|
|
|
//打印报表服务地址
|
|
|
var reportUrl = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "url_report_generate").Value;
|
|
|
if (!reportUrl.EndsWith("/"))
|
|
|
{
|
|
|
reportUrl += "/";
|
|
|
}
|
|
|
|
|
|
//订舱数据
|
|
|
var order = _rep.FirstOrDefault(x => x.Id == id);
|
|
|
if (order == null)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK001);
|
|
|
}
|
|
|
|
|
|
//打印模板
|
|
|
var printTemplate = _repPrint.FirstOrDefault(x => x.TenantId == order.TenantId && x.TypeCode == type);
|
|
|
if (printTemplate == null)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK112);
|
|
|
}
|
|
|
|
|
|
//读取配置路劲
|
|
|
var opt = App.GetOptions<PrintTemplateOptions>();
|
|
|
var dirAbs = opt.basePath;
|
|
|
if (string.IsNullOrEmpty(dirAbs))
|
|
|
{
|
|
|
dirAbs = App.WebHostEnvironment.WebRootPath;
|
|
|
}
|
|
|
|
|
|
//读取模板并调用接口
|
|
|
var fileAbsPath = Path.Combine(dirAbs, printTemplate.FilePath).ToLower();
|
|
|
if (!File.Exists(fileAbsPath))
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK112);
|
|
|
}
|
|
|
|
|
|
_logger.LogInformation($"准备调用报表生成:id:{id},文件:{printTemplate.FileName}");
|
|
|
var genUrl = reportUrl + "Report/BookingReport?bookingId=" + id;
|
|
|
var rtn = await genUrl
|
|
|
.SetContentType("multipart/form-data")
|
|
|
.SetBodyBytes(("file", File.ReadAllBytes(fileAbsPath), HttpUtility.UrlEncode(printTemplate.FileName, Encoding.GetEncoding("UTF-8"))))
|
|
|
.PostAsStringAsync();
|
|
|
var jobjRtn = JObject.Parse(rtn);
|
|
|
_logger.LogInformation($"调用报表生成返回:{rtn}");
|
|
|
if (jobjRtn.GetBooleanValue("Success"))
|
|
|
{
|
|
|
|
|
|
//调用读取文件
|
|
|
var fn = jobjRtn.GetStringValue("Data");
|
|
|
_logger.LogInformation($"准备调用读取文件:id:{id},文件名:{fn}");
|
|
|
var readFileUrl = reportUrl + "Report/GetFile?fileName=" + fn;
|
|
|
var bs = await readFileUrl.GetAsByteArrayAsync();
|
|
|
|
|
|
_logger.LogInformation($"调用读取文件返回:{bs.Length}");
|
|
|
|
|
|
var fileName = HttpUtility.UrlEncode($"{id}_{type}_{DateTime.Now.Ticks}.pdf", Encoding.GetEncoding("UTF-8"));
|
|
|
var result = new FileContentResult(bs, "application/octet-stream") { FileDownloadName = fileName };
|
|
|
return result;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
throw Oops.Bah($"生成报表文件失败:{jobjRtn.GetStringValue("Message")}");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取场站数据
|
|
|
/// </summary>
|
|
|
/// <param name="bookingId"></param>
|
|
|
/// <param name="isWeb"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/GetYardData")]
|
|
|
public async Task<string> GetYardData(long bookingId, bool isWeb = false)
|
|
|
{
|
|
|
//订舱数据
|
|
|
var order = _rep.FirstOrDefault(x => x.Id == bookingId);
|
|
|
if (order == null)
|
|
|
{
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK001);
|
|
|
}
|
|
|
|
|
|
var rtn = await YardDataHelper.GetYardData(order.TenantId.Value, order.TenantName, order.MBLNO, order.YARDID, isWeb);
|
|
|
if (!rtn.Key)
|
|
|
{
|
|
|
throw Oops.Bah(rtn.Value);
|
|
|
}
|
|
|
|
|
|
return rtn.Value;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 记录或更新订舱状态
|
|
|
/// </summary>
|
|
|
/// <param name="bookingId"></param>
|
|
|
/// <param name="code"></param>
|
|
|
/// <param name="name"></param>
|
|
|
/// <returns></returns>
|
|
|
[NonAction]
|
|
|
public async Task SaveBookingStatus(long bookingId, string code, string name)
|
|
|
{
|
|
|
var bookSta = _repBookingStatus.FirstOrDefault(x => x.BookingId == bookingId && x.StaCode == code);
|
|
|
if (bookSta == null)
|
|
|
{
|
|
|
//记录状态
|
|
|
bookSta = new BookingStatus();
|
|
|
bookSta.BookingId = bookingId;
|
|
|
bookSta.StaCode = code;
|
|
|
bookSta.StaName = name;
|
|
|
bookSta.StaTime = DateTime.Now;
|
|
|
await _repBookingStatus.InsertAsync(bookSta);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
bookSta.StaTime = DateTime.Now;
|
|
|
await _repBookingStatus.UpdateAsync(bookSta);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 下拉获取字段名称
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/GetFieldName")]
|
|
|
public async Task<dynamic> GetFieldName()
|
|
|
{
|
|
|
BookingOrder order = new BookingOrder();
|
|
|
BookingCtn ctn = new BookingCtn();
|
|
|
BookingEDIExt edi = new BookingEDIExt();
|
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
|
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(order))
|
|
|
{
|
|
|
string name = descriptor.Name;
|
|
|
if (name == "TenantId" || name == "CreatedTime" || name == "UpdatedTime" || name == "CreatedUserId" || name == "CreatedUserName")
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
if (!string.IsNullOrWhiteSpace(descriptor.Description))
|
|
|
{
|
|
|
dic.Add("order." + descriptor.Name, descriptor.Description);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Dictionary<string, string> dic1 = new Dictionary<string, string>();
|
|
|
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(ctn))
|
|
|
{
|
|
|
string name = descriptor.Name;
|
|
|
if (name == "TenantId" || name == "CreatedTime" || name == "UpdatedTime" || name == "CreatedUserId" || name == "CreatedUserName")
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
if (!string.IsNullOrWhiteSpace(descriptor.Description))
|
|
|
{
|
|
|
dic1.Add("ctn." + descriptor.Name, descriptor.Description);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Dictionary<string, string> dic2 = new Dictionary<string, string>();
|
|
|
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(edi))
|
|
|
{
|
|
|
string name = descriptor.Name;
|
|
|
if (name == "TenantId" || name == "CreatedTime" || name == "UpdatedTime" || name == "CreatedUserId" || name == "CreatedUserName")
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
if (!string.IsNullOrWhiteSpace(descriptor.Description))
|
|
|
{
|
|
|
dic2.Add("edi." + descriptor.Name, descriptor.Description);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Dictionary<string, string> dic3 = new Dictionary<string, string>();
|
|
|
dic3.Add("userinfo.username", "当前登录人");
|
|
|
dic3.Add("userinfo.usertel", "当前登录人电话");
|
|
|
dic3.Add("userinfo.usermobile", "当前登录人手机");
|
|
|
dic3.Add("userinfo.useremail", "当前登录人邮箱");
|
|
|
dic3.Add("userinfo.usertenant", "当前登录人所在公司");
|
|
|
|
|
|
var dynamic = new
|
|
|
{
|
|
|
order = dic,
|
|
|
ctn = dic1,
|
|
|
edi = dic2,
|
|
|
userinfo = dic3
|
|
|
};
|
|
|
return dynamic;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取订舱数据接口 备注 、 文件 、日志、服务项目、状态日志
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/BookingOrder/GetAllData")]
|
|
|
public async Task<dynamic> GetAllData(long bookingId)
|
|
|
{
|
|
|
BookingAllData allData = new BookingAllData();
|
|
|
if (bookingId == 0)
|
|
|
{
|
|
|
return allData;
|
|
|
}
|
|
|
//服务项目
|
|
|
var itemlist = await _serviceItem.AsQueryable().Where(x => x.BookingId == bookingId).ToListAsync();
|
|
|
allData.item = itemlist;
|
|
|
var remarklist = await _bookingremark.AsQueryable().Where(u => u.PId == bookingId).ToListAsync();
|
|
|
allData.remark = remarklist;
|
|
|
var filelist = await _bookingfile.AsQueryable().Filter(null, true).Where(u => u.BookingId == bookingId).ToListAsync();
|
|
|
allData.file = filelist;
|
|
|
|
|
|
var statuslog = await _repStatuslog.AsQueryable().Filter(null, true).Where(x => x.BookingId == bookingId).OrderByDescending(x => x.OpTime).ToListAsync();
|
|
|
var dto = statuslog.Adapt<List<BookingStatusLogDto>>();
|
|
|
var statuslogdetail = await _statuslogdetail.AsQueryable().ToListAsync();
|
|
|
foreach (var item in dto)
|
|
|
{
|
|
|
var detail = statuslogdetail.Where(x => x.PId == item.Id).ToList();
|
|
|
item.detail = detail.Adapt<List<BookingStatusLogDetailDto>>();
|
|
|
}
|
|
|
allData.statuslog = dto;
|
|
|
|
|
|
List<BookingLogDto> list = new List<BookingLogDto>();
|
|
|
var main = await _bookinglog.AsQueryable().Where(u => u.BookingId == bookingId).ToListAsync();
|
|
|
list = main.Adapt<List<BookingLogDto>>();
|
|
|
if (list != null)
|
|
|
{
|
|
|
var bookinglogdetail = await _bookinglogdetail.AsQueryable().ToListAsync() ;
|
|
|
foreach (var item in list)
|
|
|
{
|
|
|
var details = bookinglogdetail.Where(x => x.PId == item.Id).ToList();
|
|
|
item.details = details;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
allData.log = list;
|
|
|
|
|
|
List<BookingGoodsStatus> Goodslist= new List<BookingGoodsStatus>();
|
|
|
Goodslist = await _goodsStatus.AsQueryable().Where(u => u.bookingId == bookingId).ToListAsync();
|
|
|
|
|
|
allData.GoodsStatus = Goodslist;
|
|
|
return allData;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
}
|
|
|
}
|