You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
BookingHeChuan/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs

1209 lines
59 KiB
C#

2 years ago
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;
2 years ago
using System;
using Microsoft.Extensions.Logging;
2 years ago
using System.Reflection;
using System.ComponentModel;
using Myshipping.Application.Service.BookingOrder.Dto;
2 years ago
using Myshipping.Application.ConfigOption;
using System.IO;
using Yitter.IdGenerator;
using Myshipping.Core.Entity;
2 years ago
using Furion.RemoteRequest.Extensions;
using System.Net.Http;
2 years ago
using Myshipping.Core.Service;
2 years ago
using Myshipping.Application.EDI;
using System.Text;
using System.Web;
using Newtonsoft.Json.Linq;
using Myshipping.Core.Helper;
using Myshipping.Application.Enum;
2 years ago
namespace Myshipping.Application
2 years ago
{
/// <summary>
2 years ago
/// 订舱服务
2 years ago
/// </summary>
[ApiDescriptionSettings("Application", Name = "BookingOrder", Order = 1)]
2 years ago
public class BookingOrderService : IBookingOrderService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<BookingOrder> _rep;
2 years ago
private readonly SqlSugarRepository<BookingCtn> _repCtn;
private readonly SqlSugarRepository<BookingCtnDetail> _ctndetailrep;
2 years ago
private readonly SqlSugarRepository<BookingLog> _bookinglog;
private readonly SqlSugarRepository<BookingLogDetail> _bookinglogdetail;
2 years ago
private readonly SqlSugarRepository<BookingRemark> _bookingremark;
2 years ago
private readonly SqlSugarRepository<BookingFile> _bookingfile;
private readonly SqlSugarRepository<DjyWebsiteAccountConfig> _repWebAcc;
2 years ago
private readonly SqlSugarRepository<SysDictData> _dicdata;
private readonly SqlSugarRepository<BookingPrintTemplate> _repPrint;
2 years ago
private readonly ILogger<BookingOrderService> _logger;
2 years ago
private readonly ISysCacheService _cache;
2 years ago
private readonly SqlSugarRepository<BookingStatusLog> _statuslog;
private readonly SqlSugarRepository<BookingStatusLogDetail> _statuslogdetail;
private readonly SqlSugarRepository<BookingPrintTemplate> _repPrintTemplate;
private readonly SqlSugarRepository<BookingLetteryard> _repLetterYard;
private readonly SqlSugarRepository<SysUser> _repUser;
2 years ago
private readonly SqlSugarRepository<BookingOrderUrl> _repOrderUrl;
private readonly SqlSugarRepository<BookingOrderContact> _repOrderContact;
2 years ago
2 years ago
public BookingOrderService(SqlSugarRepository<BookingOrder> rep, SqlSugarRepository<BookingCtn> repCtn, SqlSugarRepository<BookingCtnDetail> ctndetailrep,
2 years ago
SqlSugarRepository<BookingLog> bookinglog, SqlSugarRepository<BookingLogDetail> bookinglogdetail, SqlSugarRepository<BookingRemark> bookingremark,
SqlSugarRepository<BookingFile> bookingfile, SqlSugarRepository<DjyWebsiteAccountConfig> webconfig, SqlSugarRepository<BookingPrintTemplate> repPrint,
SqlSugarRepository<SysDictData> dicdata, SqlSugarRepository<BookingStatusLog> statuslog, SqlSugarRepository<BookingStatusLogDetail> statuslogdetail,
ILogger<BookingOrderService> logger, ISysCacheService cache,
2 years ago
SqlSugarRepository<BookingPrintTemplate> repPrintTemplate, SqlSugarRepository<BookingLetteryard> repLetterYard, SqlSugarRepository<SysUser> repUser,
SqlSugarRepository<BookingOrderUrl> repOrderUrl, SqlSugarRepository<BookingOrderContact> repOrderContact)
2 years ago
{
2 years ago
this._logger = logger;
this._rep = rep;
this._repCtn = repCtn;
this._ctndetailrep = ctndetailrep;
2 years ago
this._bookinglog = bookinglog;
this._bookinglogdetail = bookinglogdetail;
2 years ago
this._bookingremark = bookingremark;
2 years ago
this._bookingfile = bookingfile;
this._repWebAcc = webconfig;
this._repPrint = repPrint;
2 years ago
this._dicdata = dicdata;
2 years ago
this._cache = cache;
2 years ago
this._statuslog = statuslog;
this._statuslogdetail = statuslogdetail;
this._repPrintTemplate = repPrintTemplate;
this._repLetterYard = repLetterYard;
this._repUser = repUser;
2 years ago
this._repOrderUrl = repOrderUrl;
this._repOrderContact = repOrderContact;
2 years ago
}
#region 主表和箱信息
2 years ago
/// <summary>
/// 分页查询订舱主表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/BookingOrder/page")]
public async Task<dynamic> Page([FromQuery] BookingOrderInput input)
{
2 years ago
List<long> userlist = await DataFilterExtensions.GetDataScopeIdList();
2 years ago
var entities = await _rep.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.BSSTATUS), u => u.BSSTATUS == input.BSSTATUS)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.MBLNO), u => input.MBLNO.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Contains(u.MBLNO))
.WhereIF(!string.IsNullOrWhiteSpace(input.HBLNO), u => input.HBLNO.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Contains(u.HBLNO))
.WhereIF(!string.IsNullOrWhiteSpace(input.BOOKINGNO), u => u.BOOKINGNO.IndexOf(input.BOOKINGNO) > -1)
.WhereIF(!string.IsNullOrWhiteSpace(input.CONTRACTNO), u => u.CONTRACTNO.IndexOf(input.CONTRACTNO) > -1)
.WhereIF(!string.IsNullOrWhiteSpace(input.SERVICECONTRACTNO), u => u.SERVICECONTRACTNO.IndexOf(input.SERVICECONTRACTNO) > -1)
.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))
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.YARDID), u => u.YARDID == input.YARDID)
.WhereIF(!string.IsNullOrWhiteSpace(input.YARD), u => u.YARD == input.YARD)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.VESSELID), u => u.VESSELID.IndexOf(input.VESSELID) > -1)
.WhereIF(!string.IsNullOrWhiteSpace(input.VESSEL), u => u.VESSEL.ToLower().IndexOf(u.VESSEL.ToLower()) > -1)
.WhereIF(!string.IsNullOrWhiteSpace(input.VOYNO), u => u.VOYNO.IndexOf(input.VOYNO) > -1)
.WhereIF(!string.IsNullOrWhiteSpace(input.VOYNOINNER), u => u.VOYNOINNER.IndexOf(input.VOYNOINNER) > -1)
.WhereIF(!string.IsNullOrWhiteSpace(input.PLACERECEIPT), u => u.PLACERECEIPT.Contains(input.PLACERECEIPT))
.WhereIF(!string.IsNullOrWhiteSpace(input.PLACERECEIPTID), u => u.PLACERECEIPTID == input.PLACERECEIPTID)
.WhereIF(!string.IsNullOrWhiteSpace(input.PORTLOAD), u => u.PORTLOAD.IndexOf(input.PORTLOAD) > -1)
.WhereIF(!string.IsNullOrWhiteSpace(input.PORTDISCHARGE), u => u.PORTDISCHARGE.IndexOf(input.PORTDISCHARGE) > -1)
.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)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.NOBILL), u => u.NOBILL == input.NOBILL)
.WhereIF(!string.IsNullOrWhiteSpace(input.COPYNOBILLL), u => u.COPYNOBILLL == input.COPYNOBILLL)
.WhereIF(!string.IsNullOrWhiteSpace(input.ISSUETYPE), u => u.ISSUETYPE == input.ISSUETYPE)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.ISSUEPLACE), u => u.ISSUEPLACE.Contains(input.ISSUEPLACE))
.WhereIF(!string.IsNullOrWhiteSpace(input.ISSUEPLACEID), u => u.ISSUEPLACEID == input.ISSUEPLACEID)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.BLFRT), u => u.BLFRT == input.BLFRT)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.PREPARDATID), u => u.PREPARDATID == input.PREPARDATID)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.PREPARDAT), u => u.PREPARDAT == input.PREPARDAT)
2 years ago
.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.IndexOf(input.HSCODE) > -1)
.WhereIF(!string.IsNullOrWhiteSpace(input.DESCRIPTION), u => u.DESCRIPTION.Contains(input.DESCRIPTION))
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.KINDPKGS), u => u.KINDPKGS == input.KINDPKGS)
.WhereIF(!string.IsNullOrWhiteSpace(input.CNTRTOTAL), u => u.CNTRTOTAL == input.CNTRTOTAL)
.WhereIF(!string.IsNullOrWhiteSpace(input.CARRIERID), u => u.CARRIERID == input.CARRIERID)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.CARRIER), u => u.CARRIER.Contains(input.CARRIER))
2 years ago
.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)
2 years ago
.WhereIF(input.ISCONTAINERSOC != null, u => u.ISCONTAINERSOC == input.ISCONTAINERSOC)
2 years ago
.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))
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.COMPID), u => u.COMPID == input.COMPID)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.COMPNAME), u => u.COMPNAME.IndexOf(input.COMPNAME) > -1)
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERNAME), u => u.SHIPPERNAME.Contains(input.SHIPPERNAME))
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERCITY), u => u.SHIPPERCITY.Contains(input.SHIPPERCITY))
2 years ago
.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)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERATTN), u => u.SHIPPERATTN.Contains(input.SHIPPERATTN))
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPPERTEL), u => u.SHIPPERTEL == input.SHIPPERTEL)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEENAME), u => u.CONSIGNEENAME.Contains(input.CONSIGNEENAME))
.WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEECITY), u => u.CONSIGNEECITY.Contains(input.CONSIGNEECITY))
2 years ago
.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)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEEATTN), u => u.CONSIGNEEATTN.Contains(input.CONSIGNEEATTN))
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.CONSIGNEETEL), u => u.CONSIGNEETEL == input.CONSIGNEETEL)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTYNAME), u => u.NOTIFYPARTYNAME.Contains(input.NOTIFYPARTYNAME))
.WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTYCITY), u => u.NOTIFYPARTYCITY.Contains(input.NOTIFYPARTYCITY))
2 years ago
.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)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.NOTIFYPARTYATTN), u => u.NOTIFYPARTYATTN.Contains(input.NOTIFYPARTYATTN))
2 years ago
.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)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.SALE), u => u.SALE.Contains(input.SALE))
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTSERVICEID), u => u.CUSTSERVICEID == input.CUSTSERVICEID)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTSERVICE), u => u.CUSTSERVICE.Contains(input.CUSTSERVICE))
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTOMERNAME), u => u.CUSTOMERNAME.Contains(input.CUSTOMERNAME))
2 years ago
.WhereIF(input.CUSTOMERID != null, u => u.CUSTOMERID == input.CUSTOMERID)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.FORWARDER), u => u.FORWARDER.Contains(input.FORWARDER))
2 years ago
.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.TRUCKER), u => u.TRUCKER == input.TRUCKER)
.WhereIF(!string.IsNullOrWhiteSpace(input.AGENTID), u => u.AGENTID == input.AGENTID)
.WhereIF(!string.IsNullOrWhiteSpace(input.FORWARDERID), u => u.FORWARDERID == input.FORWARDERID)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPAGENCY), u => u.SHIPAGENCY.Contains(input.SHIPAGENCY))
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.SHIPAGENCYID), u => u.SHIPAGENCYID == input.SHIPAGENCYID)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTOMSER), u => u.CUSTOMSER.Contains(input.CUSTOMSER))
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTOMSERID), u => u.CUSTOMSERID == input.CUSTOMSERID)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.TRUCKER), u => u.TRUCKER.Contains(input.TRUCKER))
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.TRUCKERID), u => u.TRUCKERID == input.TRUCKERID)
2 years ago
.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))
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.SCACCODE), u => u.SCACCODE == input.SCACCODE)
.WhereIF(!string.IsNullOrWhiteSpace(input.ITNCODE), u => u.ITNCODE == input.ITNCODE)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.CUSTNO), u => u.CUSTNO.Contains(input.CUSTNO))
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.TRANSPORTID), u => u.TRANSPORTID == input.TRANSPORTID)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.TRANSPORT), u => u.TRANSPORT.Contains(input.TRANSPORT))
2 years ago
.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)
2 years ago
.WhereIF(!string.IsNullOrWhiteSpace(input.LANENAME), u => u.LANENAME.Contains(input.LANENAME))
.WhereIF(!string.IsNullOrWhiteSpace(input.FREIGHTPAYER), u => u.FREIGHTPAYER.Contains(input.FREIGHTPAYER))
2 years ago
.Where(u => userlist.Contains((long)u.CreatedUserId))
2 years ago
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
/// <summary>
2 years ago
/// 增加订舱
2 years ago
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
2 years ago
[SqlSugarUnitOfWork]
2 years ago
[HttpPost("/BookingOrder/add")]
public async Task Add(AddBookingOrderInput input)
{
2 years ago
JsonUtil.PropToUpper(input, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail");
JsonUtil.TrimFields(input);
2 years ago
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);
}
2 years ago
2 years ago
var entity = input.Adapt<BookingOrder>();
2 years ago
2 years ago
await _rep.InsertAsync(entity);
2 years ago
if (input.ctnInputs != null)
{
foreach (var item in input.ctnInputs)
2 years ago
{
var ctnentity = item.Adapt<BookingCtn>();
ctnentity.BILLID = entity.Id;
await _repCtn.InsertAsync(ctnentity);
foreach (var it in item.ctnDetailInputs)
{
var ctndetail = it.Adapt<BookingCtnDetail>();
ctndetail.CTNID = ctnentity.Id;
await _ctndetailrep.InsertAsync(ctndetail);
}
2 years ago
}
}
2 years ago
2 years ago
////添加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
});
2 years ago
if (!string.IsNullOrWhiteSpace(input.YARDID) && !string.IsNullOrWhiteSpace(input.YARD) && !string.IsNullOrWhiteSpace(input.MBLNO))
2 years ago
{
2 years ago
await SendTrace(entity.Id.ToString(), entity.YARDID, entity.YARD, entity.MBLNO);
}
2 years ago
2 years ago
}
/// <summary>
2 years ago
/// 删除订舱
2 years ago
/// </summary>
2 years ago
/// <param name="Id"></param>
2 years ago
/// <returns></returns>
2 years ago
[SqlSugarUnitOfWork]
2 years ago
[HttpPost("/BookingOrder/delete")]
2 years ago
public async Task Delete(long Id)
2 years ago
{
2 years ago
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 });
_logger.LogInformation(Id + "删除成功!");
2 years ago
}
/// <summary>
2 years ago
/// 更新订舱
2 years ago
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
2 years ago
[SqlSugarUnitOfWork]
2 years ago
[HttpPost("/BookingOrder/update")]
2 years ago
public async Task Update(UpdateBookingOrderInput input)
{
2 years ago
JsonUtil.PropToUpper(input, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail");
JsonUtil.TrimFields(input);
2 years ago
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);
}
2 years ago
var main = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
2 years ago
var entity = input.Adapt<BookingOrder>();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
2 years ago
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));
2 years ago
if (input.ctnInputs != null)
{
foreach (var item in input.ctnInputs)
2 years ago
{
var ctnentity = item.Adapt<BookingCtn>();
ctnentity.BILLID = entity.Id;
await _repCtn.InsertAsync(ctnentity);
foreach (var it in item.ctnDetailInputs)
{
var ctndetail = it.Adapt<BookingCtnDetail>();
ctndetail.CTNID = ctnentity.Id;
await _ctndetailrep.InsertAsync(ctndetail);
}
2 years ago
}
}
2 years ago
2 years ago
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)
{
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,
2 years ago
Field = descriptor.Description,
2 years ago
OldValue = _oldvalue,
NewValue = _value,
});
2 years ago
if (descriptor.Name == "YARDID" || descriptor.Name == "YARD" || descriptor.Name == "MBLNO")
{
2 years ago
if (!string.IsNullOrWhiteSpace(input.YARDID) && !string.IsNullOrWhiteSpace(input.YARD) && !string.IsNullOrWhiteSpace(input.MBLNO))
{
2 years ago
await SendTrace(entity.Id.ToString(), entity.YARDID, entity.YARD, entity.MBLNO);
2 years ago
}
}
2 years ago
}
}
2 years ago
}
/// <summary>
2 years ago
/// 获取订舱明细
2 years ago
/// </summary>
2 years ago
/// <param name="Id"></param>
2 years ago
/// <returns></returns>
2 years ago
[HttpGet("/BookingOrder/get")]
2 years ago
public async Task<BookingOrderOutput> Get(long Id)
2 years ago
{
2 years ago
BookingOrderOutput ordOut = new BookingOrderOutput();
2 years ago
var main = await _rep.FirstOrDefaultAsync(u => u.Id == Id);
2 years ago
if (main != null)
{
2 years ago
ordOut = main.Adapt<BookingOrderOutput>();
2 years ago
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>>();
}
2 years ago
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,
};
}
2 years ago
}
2 years ago
return ordOut;
2 years ago
}
#endregion
2 years ago
#region 日志、备注、附件、货运动态等
2 years ago
/// <summary>
/// 获取日志明细
/// </summary>
2 years ago
/// <param name="Id"></param>
2 years ago
/// <returns></returns>
2 years ago
[HttpGet("/BookingOrder/getLog")]
2 years ago
public async Task<BookingLogDto> GetLog(long Id)
{
BookingLogDto list = new BookingLogDto();
2 years ago
var main = await _bookinglog.FirstOrDefaultAsync(u => u.BookingId == Id);
2 years ago
if (main != null)
{
list = main.Adapt<BookingLogDto>();
var details = await _bookinglogdetail.AsQueryable().Where(x => x.PId == main.Id).ToListAsync();
2 years ago
2 years ago
list.details = details;
}
return list;
}
2 years ago
/// <summary>
/// 获取备注
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
2 years ago
[HttpGet("/BookingOrder/getRemark")]
2 years ago
public async Task<BookingRemark> GetRemark(long Id)
{
var list = await _bookingremark.FirstOrDefaultAsync(u => u.PId == Id);
return list;
}
/// <summary>
/// 增加备注
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
[SqlSugarUnitOfWork]
[HttpPost("/BookingOrder/addRemark")]
public async Task AddRemark(BookingRemarkDto dto)
{
var entity = dto.Adapt<BookingRemark>();
await _bookingremark.InsertAsync(entity);
}
2 years ago
/// <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.Oh(BookingErrorCode.BOOK200);
2 years ago
}
var opt = App.GetOptions<BookingAttachOptions>();
2 years ago
var originalFilename = file.FileName; // 文件原始名称
var fileSuffix = Path.GetExtension(file.FileName).ToLower(); // 文件后缀
if (!opt.fileType.Contains(fileSuffix))
{
2 years ago
throw Oops.Oh(BookingErrorCode.BOOK114);
2 years ago
}
var dirAbs = string.Empty;
if (string.IsNullOrEmpty(opt.basePath))
2 years ago
{
dirAbs = Path.Combine(App.WebHostEnvironment.WebRootPath, opt.relativePath);
}
else
{
dirAbs = Path.Combine(opt.basePath, opt.relativePath);
2 years ago
}
if (!Directory.Exists(dirAbs))
Directory.CreateDirectory(dirAbs);
2 years ago
// 先存库获取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();
2 years ago
var newFile = new BookingFile
{
Id = id,
FileName = originalFilename,
FilePath = fileRelaPath,
2 years ago
TypeCode = dto.TypeCode,
2 years ago
TypeName = dto.TypeName,
TenantId = Convert.ToInt16(UserManager.TENANT_ID),
2 years ago
TenantName = UserManager.TENANT_NAME,
2 years ago
};
await _bookingfile.InsertAsync(newFile);
using (var stream = File.Create(fileAbsPath))
2 years ago
{
await file.CopyToAsync(stream);
}
}
/// <summary>
/// 获取附件
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
2 years ago
[HttpGet("/BookingOrder/getFile")]
2 years ago
public async Task<BookingFile> GetFile(long Id)
{
var list = await _bookingfile.FirstOrDefaultAsync(u => u.BookingId == Id);
return list;
}
2 years ago
/// <summary>
/// 获取货运动态
/// </summary>
public async Task<List<BookingStatusLogDto>> GetBookingStatusLog(long Id)
{
var statuslog = await _statuslog.AsQueryable().Where(x => x.BookingId == Id).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;
}
#endregion
#region 运踪
2 years ago
/// <summary>
/// 调用运踪接口
/// </summary>
2 years ago
public async Task SendTrace(string BusinessId, string YARDID, string YARD, string MBLNO)
2 years ago
{
2 years ago
_logger.LogInformation("提单号:" + MBLNO + " 调用运踪接口");
var key = _repWebAcc.FirstOrDefault(x => x.TenantId == Convert.ToInt64(UserManager.TENANT_ID) && x.TypeCode == "seae_billtraceurl");
2 years ago
var url = _cache.GetAllDictData().Result;
BillTraceDto billdto = new BillTraceDto();
List<BillTraceList> billTraceList = new List<BillTraceList>();
billTraceList.Add(new BillTraceList
{
2 years ago
BusinessId = BusinessId,
2 years ago
MBLNO = MBLNO,
YARD = YARD,
YardCode = YARDID,
CARRIER = null,
CARRIERID = null,
isBook = false
});
billdto.Children = billTraceList;
billdto.Key = key.Account;
billdto.PWD = key.Password;
2 years ago
billdto.url = url.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "response_seae_billtraceurl").Value;
billdto.Gid = UserManager.DjyUserId;
2 years ago
var json = billdto.ToJsonString();
2 years ago
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>();
2 years ago
_logger.LogInformation("提单号:" + MBLNO + " 调用运踪接口返回" + html.ToJsonString());
2 years ago
}
/// <summary>
/// 插入货运动态
/// </summary>
[AllowAnonymous]
[SqlSugarUnitOfWork]
public async Task AddBookingStatusLog(List<BookingStatusLogDto> all)
{
foreach (var item in all)
{
//清空原有数据
var old = await _statuslog.AsQueryable().Where(x => x.BookingId == item.BookingId && x.Gategory == "ship").ToListAsync();
await _statuslog.DeleteAsync(x => x.BookingId == item.BookingId && x.Gategory == "ship");
foreach (var ot in old)
{
await _statuslogdetail.DeleteAsync(x => x.PId == ot.Id);
}
//新增数据
var bookingStatusLog = new BookingStatusLog();
bookingStatusLog.BookingId = item.BookingId;
bookingStatusLog.Gategory = "ship";
bookingStatusLog.CreatedTime = DateTime.Now;
bookingStatusLog.Status = item.Status;
2 years ago
bookingStatusLog.OpTime = item.OpTime;
bookingStatusLog.MBLNO = item.MBLNO;
var id = await _statuslog.InsertReturnSnowflakeIdAsync(bookingStatusLog);
if (item.detail != null && item.detail.Count > 0)
{
foreach (var dt in item.detail)
{
var BookingStatusLogDetail = new BookingStatusLogDetail();
BookingStatusLogDetail.PId = id;
BookingStatusLogDetail.Status = dt.Status;
BookingStatusLogDetail.CNTRNO = dt.CNTRNO;
BookingStatusLogDetail.OPTime = dt.OPTime;
await _statuslogdetail.InsertAsync(BookingStatusLogDetail);
}
}
}
}
#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);
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,
};
}
2 years ago
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 Save(UpdateBookingLetteryardInput input)
{
if (input.Id == 0)
{
var entity = input.Adapt<BookingLetteryard>();
await _repLetterYard.InsertAsync(entity);
}
else
{
var entity = _repLetterYard.FirstOrDefault(x => x.BookingId == input.Id);
entity = input.Adapt(entity);
await _repLetterYard.UpdateAsync(entity);
}
2 years ago
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);
}
//todovgm、vgm&si链接
//...
}
/// <summary>
/// 获取放舱pdf
/// </summary>
/// <param name="bookingId"></param>
/// <returns></returns>
[HttpGet("/BookingOrder/letteryardpdf")]
public async Task<IActionResult> LetterYardPdf(long bookingId)
{
return await LetterYardFile(bookingId, 1);
}
/// <summary>
/// 获取放舱excel
/// </summary>
/// <param name="bookingId"></param>
/// <returns></returns>
[HttpGet("/BookingOrder/letteryardxlsx")]
public async Task<IActionResult> LetterYardXlsx(long bookingId)
{
return await LetterYardFile(bookingId, 2);
}
/// <summary>
/// 生成放舱文件
/// </summary>
/// <param name="bookingId"></param>
/// <param name="type">类型1pdf、2xlsx</param>
/// <returns></returns>
[NonAction]
private async Task<IActionResult> LetterYardFile(long bookingId, 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)
{
2 years ago
throw Oops.Oh(BookingErrorCode.BOOK001);
}
var letterYard = await _repLetterYard.FirstOrDefaultAsync(x => x.BookingId == bookingId);
if (letterYard == null)
{
2 years ago
throw Oops.Oh(BookingErrorCode.BOOK116);
}
var printTemplate = _repPrintTemplate.FirstOrDefault(x => x.TenantId == letterYard.TenantId && x.TypeCode == "fangcang");
if (printTemplate == null)
{
2 years ago
throw Oops.Oh(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);
if (!File.Exists(fileAbsPath))
{
2 years ago
throw Oops.Oh(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}");
var fileName = HttpUtility.UrlEncode($"{bookingId}_{type}_{DateTime.Now.Ticks}.{(type == 1 ? "pdf" : "xlsx")}", Encoding.GetEncoding("UTF-8"));
var result = new FileContentResult(bs, "application/octet-stream") { FileDownloadName = fileName };
return result;
}
else
{
throw Oops.Bah($"生成报表文件失败:{jobjRtn.GetStringValue("Message")}");
}
}
#endregion
#region 样单
#endregion
2 years ago
#region 小票链接
/// <summary>
/// 获取提箱小票链接
/// </summary>
/// <param name="bookingId"></param>
/// <returns></returns>
[HttpGet("/BookingOrder/txxplink")]
2 years ago
public async Task<string> TxxpLink(long bookingId)
2 years ago
{
var order = _rep.FirstOrDefault(x => x.Id == bookingId);
if (order == null)
2 years ago
{
throw Oops.Oh(BookingErrorCode.BOOK001);
}
var ordUrl = _repOrderUrl.FirstOrDefault(x => x.BookingId == bookingId);
if (ordUrl == null)
2 years ago
{
ordUrl = new BookingOrderUrl();
ordUrl.BookingId = bookingId;
await _repOrderUrl.InsertAsync(ordUrl);
}
2 years ago
if (!string.IsNullOrEmpty(ordUrl.UrlTxxp))
{
return ordUrl.UrlTxxp;
}
2 years ago
//校验船公司
if (string.IsNullOrEmpty(order.CARRIERID))
{
2 years ago
throw Oops.Oh(BookingErrorCode.BOOK118);
2 years ago
}
//判断船公司是否支持
var allowCarrier = _cache.GetAllDictData().Result.Where(x => x.TypeCode == "txxp_carrier_list").Select(x => x.Code).ToList();
2 years ago
if (!allowCarrier.Contains(order.CARRIERID))
2 years ago
{
2 years ago
throw Oops.Oh(BookingErrorCode.BOOK117);
2 years ago
}
//亿通账号
var ytAcc = _repWebAcc.FirstOrDefault(x => x.CreatedUserId == UserManager.UserId && x.TypeCode == "YitongWeb");
2 years ago
if (ytAcc == null)
2 years ago
{
2 years ago
throw Oops.Oh(BookingErrorCode.BOOK119);
2 years ago
}
2 years ago
//场站转换
var yardset = _cache.GetAllMappingYard().Result.FirstOrDefault(y => y.Code == order.YARDID && y.Module == "BookingTxxp");
if (yardset == null)
{
throw Oops.Oh(BookingErrorCode.BOOK120, order.YARDID);
}
2 years ago
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.Oh(BookingErrorCode.BOOK121);
}
//箱型映射
var ctnMapping = await _cache.GetAllMappingCtn();
ctnMapping = ctnMapping.Where(x => x.Module == "BookingTxxp").ToList();
if (ctnMapping.Count == 0)
{
throw Oops.Oh(BookingErrorCode.BOOK122);
}
var expCode = ctns.Select(x => x.CTNCODE).Distinct().Except(ctnMapping.Select(y => y.Code)).ToList();
if (expCode.Count > 0)
{
throw Oops.Oh(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,
2 years ago
billOrderId = order.Id.ToString(),
2 years ago
sendOrderCode = order.MBLNO,
userId = UserManager.DjyUserId,
2 years ago
customerId = order.CUSTOMERID.ToString(),
2 years ago
// userName = currUser.CODENAME,
//userPassword = currUser.PASSWORD,
operatorName = UserManager.Name,
2 years ago
depotCode = yardset.MapCode,
depotName = yardset.MapName,
2 years ago
AgentName = UserManager.TENANT_NAME,
linkName = UserManager.Name,
linkMobile = user.Tel,
CustomerName = $"{UserManager.TENANT_NAME}+{UserManager.Name}", //公司名称+用户姓名
memo = string.Empty,
boxInfo = ctns.Select(c =>
{
return new
{
2 years ago
boxType = ctnMapping.First(x => x.Code == c.CTNCODE).MapCode,
2 years ago
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.Oh(BookingErrorCode.BOOK124, jobjResp.GetStringValue("message"));
}
//保存url
var txxpUrl = jobjResp.GetStringValue("data");
ordUrl.UrlTxxp = txxpUrl;
await _repOrderUrl.UpdateAsync(ordUrl);
return txxpUrl;
2 years ago
}
#endregion
2 years ago
#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.Oh(BookingErrorCode.BOOK001);
}
var ordUrl = _repOrderUrl.FirstOrDefault(x => x.BookingId == bookingId);
if (ordUrl == null)
{
ordUrl = new BookingOrderUrl();
ordUrl.BookingId = bookingId;
await _repOrderUrl.InsertAsync(ordUrl);
}
2 years ago
if (!string.IsNullOrEmpty(ordUrl.UrlVgm))
{
return new string[] { ordUrl.UrlVgm, ordUrl.UrlVgmSi };
}
//校验船公司
if (string.IsNullOrEmpty(order.CARRIERID))
{
throw Oops.Oh(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.Oh(BookingErrorCode.BOOK117);
}
2 years ago
//船公司网站账号
var carrWebAccMap = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "carrier_web_account_mapping" && x.Code == order.CARRIERID);
var webacc = _repWebAcc.FirstOrDefault(x => x.TypeCode == carrWebAccMap.Value && x.CreatedUserId == UserManager.UserId);
if (webacc == null)
{
throw Oops.Oh(BookingErrorCode.BOOK125);
}
//场站转换
var yardset = _cache.GetAllMappingYard().Result.FirstOrDefault(y => y.Code == order.YARDID && y.Module == "BookingVgm");
if (yardset == null)
{
throw Oops.Oh(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.Oh(BookingErrorCode.BOOK121);
}
//箱型映射
var ctnMapping = await _cache.GetAllMappingCtn();
ctnMapping = ctnMapping.Where(x => x.Module == "BookingVgm").ToList();
if (ctnMapping.Count == 0)
{
throw Oops.Oh(BookingErrorCode.BOOK122);
}
var expCode = ctns.Select(x => x.CTNCODE).Distinct().Except(ctnMapping.Select(y => y.Code)).ToList();
if (expCode.Count > 0)
{
throw Oops.Oh(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 == "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 = "",
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 = "",
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链接接口传递数据{strPostObj}");
var strResp = await dicUrlTxxp.Value.SetBody(postObj).PostAsStringAsync();
_logger.LogInformation($"调用VGM链接接口返回{strResp}");
var jobjResp = JObject.Parse(strResp);
int respCode = jobjResp.GetIntValue("code");
if (respCode != 200)
{
throw Oops.Oh(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);
return new string[] { ordUrl.UrlVgm, ordUrl.UrlVgmSi };
}
2 years ago
#endregion
#region 订舱、截单EDI
#endregion
#region 其他
/// <summary>
/// 获取用户报表的json
/// </summary>
/// <param name="id"></param>
[HttpGet("/BookingOrder/reportJson")]
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/reportFile")]
public async Task<IActionResult> GenReportJson(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)
{
2 years ago
throw Oops.Oh(BookingErrorCode.BOOK001);
}
//打印模板
var printTemplate = _repPrint.FirstOrDefault(x => x.TenantId == order.TenantId && x.TypeCode == type);
if (printTemplate == null)
{
2 years ago
throw Oops.Oh(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))
{
2 years ago
throw Oops.Oh(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")}");
}
}
#endregion
2 years ago
}
}