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.

2591 lines
128 KiB
C#

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.ConfigOption;
using System.IO;
using Yitter.IdGenerator;
using Myshipping.Core.Entity;
using Furion.RemoteRequest.Extensions;
using System.Net.Http;
using Myshipping.Core.Service;
2 years ago
using System.Reflection.Emit;
2 years ago
using Myshipping.Application.Service.DataSync.Dto;
using Newtonsoft.Json.Linq;
2 years ago
using Myshipping.Application.Service.BookingOrder.Dto;
using Myshipping.Application.Enum;
using Myshipping.Core.Helper;
using Furion.TaskScheduler;
using System.Linq.Expressions;
namespace Myshipping.Application
{
/// <summary>
/// 数据同步服务
/// </summary>
[ApiDescriptionSettings("Application", Name = "DataSync", Order = 1), AllowAnonymous]
public class DataSyncService : IDynamicApiController, ITransient
{
2 years ago
private readonly ILogger<DataSyncService> _logger;
private readonly ISysCacheService _cache;
private readonly SqlSugarRepository<BookingOrder> _rep;
private readonly SqlSugarRepository<BookingCtn> _repCtn;
2 years ago
private readonly SqlSugarRepository<BookingCtnDetail> _ctndetailrep;
private readonly SqlSugarRepository<SysUser> _repUser;
private readonly SqlSugarRepository<SysTenant> _repTenant;
2 years ago
private readonly SqlSugarRepository<DjyCustomer> _djycustomer;
private readonly SqlSugarRepository<DjyCustomerContact> _djycustomercontact;
2 years ago
private readonly SqlSugarRepository<DjyVesselInfo> _vesselinfo;
private readonly SqlSugarRepository<BookingEDIExt> _bookingEDIExt;
private readonly SqlSugarRepository<BookingLog> _bookinglog;
private readonly SqlSugarRepository<BookingLogDetail> _bookinglogdetail;
2 years ago
private readonly SqlSugarRepository<BookingRemark> _bookingremark;
private readonly SqlSugarRepository<BookingGoodsStatus> _goodsStatus;
private readonly SqlSugarRepository<BookingGoodsStatusConfig> _goodsStatusConfig;
2 years ago
private readonly SqlSugarRepository<DjyTenantLine> _repline;
2 years ago
private readonly SqlSugarRepository<MappingCarrier> _mapcarrier;
private readonly SqlSugarRepository<CodeLane> _codeLaneRep;
private readonly SqlSugarRepository<CodePort> _codePortRep;
private readonly SqlSugarRepository<RelaPortCarrierLane> _relaPortLane;
private readonly ICommonDBService _commonDBService;
2 years ago
private readonly SqlSugarRepository<CodeForwarder> _codeForwarder;
2 years ago
private readonly SqlSugarRepository<BookingFile> _bookingfile;
2 years ago
private readonly SqlSugarRepository<DjyWebsiteAccountConfig> _accountconfig;
private readonly SqlSugarRepository<BookingStatusLog> _repStatuslog;
private readonly SqlSugarRepository<BookingStatusLogDetail> _statuslogdetail;
private readonly SqlSugarRepository<BookingStatus> _repBookingStatus;
2 years ago
private readonly IBookingOrderService _bookingorderservice;
2 years ago
2 years ago
public DataSyncService(ILogger<DataSyncService> logger, ISysCacheService cache, SqlSugarRepository<BookingOrder> rep, SqlSugarRepository<BookingCtn> repCtn,
2 years ago
SqlSugarRepository<SysUser> repUser, SqlSugarRepository<SysTenant> repTenant, SqlSugarRepository<DjyCustomer> djycustomer,
SqlSugarRepository<BookingStatusLog> statuslog, SqlSugarRepository<BookingStatusLogDetail> statuslogdetail, SqlSugarRepository<BookingStatus> repBookingStatus,
SqlSugarRepository<DjyCustomerContact> djycustomercontact, SqlSugarRepository<DjyVesselInfo> vesselinfo, SqlSugarRepository<BookingCtnDetail> ctndetailrep
2 years ago
, SqlSugarRepository<BookingEDIExt> bookingEDIExt, SqlSugarRepository<BookingLog> bookinglog, SqlSugarRepository<BookingLogDetail> bookinglogdetail,
2 years ago
SqlSugarRepository<BookingGoodsStatus> goodsStatus, SqlSugarRepository<BookingGoodsStatusConfig> goodsStatusConfig, SqlSugarRepository<DjyTenantLine> repline,
2 years ago
SqlSugarRepository<BookingRemark> bookingremark, SqlSugarRepository<MappingCarrier> mapcarrier, SqlSugarRepository<CodeForwarder> codeForwarder,
2 years ago
SqlSugarRepository<CodePort> codePortRep, SqlSugarRepository<CodeLane> codeLaneRep, ICommonDBService commonDBService, SqlSugarRepository<RelaPortCarrierLane> relaPortLane,
2 years ago
SqlSugarRepository<DjyWebsiteAccountConfig> accountconfig, SqlSugarRepository<BookingFile> bookingfile, IBookingOrderService bookingorderservice)
{
this._logger = logger;
this._rep = rep;
this._repCtn = repCtn;
this._cache = cache;
this._repUser = repUser;
this._repTenant = repTenant;
2 years ago
this._djycustomer = djycustomer;
this._djycustomercontact = djycustomercontact;
2 years ago
this._vesselinfo = vesselinfo;
2 years ago
this._ctndetailrep = ctndetailrep;
this._bookingEDIExt = bookingEDIExt;
this._bookinglog = bookinglog;
this._bookinglogdetail = bookinglogdetail;
2 years ago
this._bookingremark = bookingremark;
2 years ago
this._goodsStatus = goodsStatus;
this._goodsStatusConfig = goodsStatusConfig;
2 years ago
this._repline = repline;
2 years ago
this._mapcarrier = mapcarrier;
this._codePortRep = codePortRep;
this._codeLaneRep = codeLaneRep;
this._commonDBService = commonDBService;
this._relaPortLane = relaPortLane;
2 years ago
this._codeForwarder = codeForwarder;
2 years ago
this._accountconfig = accountconfig;
this._bookingfile = bookingfile;
2 years ago
this._bookingorderservice = bookingorderservice;
this._repStatuslog = statuslog;
this._statuslogdetail = statuslogdetail;
this._repBookingStatus = repBookingStatus;
}
#region 上传数据
2 years ago
/// <summary>
/// 同步客户
/// </summary>
2 years ago
/// <param name="model">参数</param>
2 years ago
/// <returns></returns>
[HttpPost("/DataSync/SyncCustomer"), ApiUser(ApiCode = "SyncCustomer")]
public async Task<long> SyncCustomer(DjyCustomerSyncDto model)
{
var userlist = await _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync();
2 years ago
if (string.IsNullOrWhiteSpace(model.ShortName))
{
2 years ago
throw Oops.Bah("简称未录入");
2 years ago
}
var m = await _djycustomer.AsQueryable().Filter(null, true).Where(x => x.ShortName == model.ShortName && x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).FirstAsync();
2 years ago
var entity = model.Adapt<DjyCustomer>();
2 years ago
if (!string.IsNullOrEmpty(entity.SALE))
{
entity.SALEID = userlist.Where(x => x.Name == entity.SALE).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(entity.OP))
{
entity.OPID = userlist.Where(x => x.Name == entity.OP).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.OP).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(entity.DOC))
{
entity.DOCID = userlist.Where(x => x.Name == entity.DOC).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(entity.CUSTSERVICE))
{
entity.CUSTSERVICEID = userlist.Where(x => x.Name == entity.CUSTSERVICE).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
}
1 year ago
if (entity.Level == "R3" && !string.IsNullOrEmpty(entity.CUSTSERVICE))
{
2 years ago
throw Oops.Bah("等级为R3客服为空");
}
1 year ago
if ((entity.Level == "R1" || entity.Level == "R2") && string.IsNullOrEmpty(entity.CUSTSERVICE))
2 years ago
{
throw Oops.Bah("等级为R1/R2客服必填");
}
entity.PropString = entity.PropString.Replace("forwarder", "booking_agent");
2 years ago
if (m == null)
{
2 years ago
entity.TenantId = UserManager.TENANT_ID;
2 years ago
await _djycustomer.InsertAsync(entity);
foreach (var item in model.ContactList)
{
var contact = item.Adapt<DjyCustomerContact>();
contact.CustomerId = entity.Id;
2 years ago
contact.TenantId = UserManager.TENANT_ID;
2 years ago
await _djycustomercontact.InsertAsync(contact);
}
2 years ago
if (entity.PropString.Contains("shipagency"))
{
var ship = await _codeForwarder.AsQueryable().Where(x => x.Code == entity.CodeName).FirstAsync();
if (ship == null)
{
await _codeForwarder.InsertAsync(new CodeForwarder
{
GID = Guid.NewGuid().ToString(),
CreateTime = DateTime.Now,
CreateUser = UserManager.DjyUserId,
Code = entity.CodeName,
Name = entity.ShortName
});
}
else
{
ship.Code = entity.CodeName;
ship.Name = entity.ShortName;
ship.ModifyTime = DateTime.Now;
ship.ModifyUser = UserManager.DjyUserId;
await _codeForwarder.UpdateAsync(ship);
}
2 years ago
await _commonDBService.GetAllForwarder(false);
2 years ago
}
2 years ago
}
else
{
entity.Id = m.Id;
2 years ago
2 years ago
2 years ago
await _djycustomer.AsUpdateable(entity).IgnoreColumns(it => new
{
2 years ago
it.TenantId,
2 years ago
it.TIDANINFO
}).ExecuteCommandAsync();
2 years ago
await _djycustomercontact.DeleteAsync(x => x.CustomerId == entity.Id);
2 years ago
if (entity.PropString.Contains("shipagency"))
{
var ship = await _codeForwarder.AsQueryable().Where(x => x.Code == entity.CodeName).FirstAsync();
if (ship == null)
{
await _codeForwarder.InsertAsync(new CodeForwarder
{
GID = Guid.NewGuid().ToString(),
CreateTime = DateTime.Now,
CreateUser = UserManager.DjyUserId,
Code = entity.CodeName,
Name = entity.ShortName
});
}
else
{
ship.Code = entity.CodeName;
ship.Name = entity.ShortName;
ship.ModifyTime = DateTime.Now;
ship.ModifyUser = UserManager.DjyUserId;
await _codeForwarder.UpdateAsync(ship);
}
2 years ago
await _commonDBService.GetAllForwarder(false);
2 years ago
}
2 years ago
foreach (var item in model.ContactList)
{
var contact = item.Adapt<DjyCustomerContact>();
contact.CustomerId = entity.Id;
2 years ago
contact.TenantId = UserManager.TENANT_ID;
2 years ago
await _djycustomercontact.InsertAsync(contact);
}
}
return entity.Id;
}
2 years ago
/// <summary>
/// 批量同步客户无返回值
/// </summary>
/// <param name="model">参数</param>
/// <returns></returns>
[HttpPost("/DataSync/SyncCustomerList"), ApiUser(ApiCode = "SyncCustomerList")]
2 years ago
[SqlSugarUnitOfWork]
2 years ago
public async Task SyncCustomer(List<DjyCustomerSyncDto> model)
{
var userlist = await _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync();
var mlist = await _djycustomer.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync();
2 years ago
var shiplist = await _codeForwarder.AsQueryable().ToListAsync();
2 years ago
foreach (var item in model)
{
if (string.IsNullOrWhiteSpace(item.ShortName))
{
throw Oops.Bah("简称未录入");
}
2 years ago
var m = mlist.Where(x => x.ShortName == item.ShortName).FirstOrDefault();
2 years ago
var entity = item.Adapt<DjyCustomer>();
2 years ago
if (!string.IsNullOrEmpty(entity.SALE))
{
entity.SALEID = userlist.Where(x => x.Name == entity.SALE).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(entity.OP))
{
entity.OPID = userlist.Where(x => x.Name == entity.OP).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.OP).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(entity.DOC))
{
entity.DOCID = userlist.Where(x => x.Name == entity.DOC).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
}
if (!string.IsNullOrEmpty(entity.CUSTSERVICE))
{
entity.CUSTSERVICEID = userlist.Where(x => x.Name == entity.CUSTSERVICE).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (entity.Level == "R3" && !string.IsNullOrEmpty(entity.CUSTSERVICE))
{
throw Oops.Bah("等级为R3客服为空");
}
if ((entity.Level == "R1" || entity.Level == "R2") && string.IsNullOrEmpty(entity.CUSTSERVICE))
{
throw Oops.Bah("等级为R1/R2客服必填");
2 years ago
}
entity.PropString = entity.PropString.Replace("forwarder", "booking_agent");
2 years ago
if (m == null)
{
2 years ago
2 years ago
entity.TenantId = UserManager.TENANT_ID;
2 years ago
await _djycustomer.InsertAsync(entity);
foreach (var it in item.ContactList)
{
var contact = it.Adapt<DjyCustomerContact>();
contact.CustomerId = entity.Id;
2 years ago
contact.TenantId = UserManager.TENANT_ID;
2 years ago
await _djycustomercontact.InsertAsync(contact);
2 years ago
}
if (entity.PropString.Contains("shipagency"))
{
2 years ago
var ship = shiplist.Where(x => x.Code == entity.CodeName).FirstOrDefault();
2 years ago
if (ship == null)
{
await _codeForwarder.InsertAsync(new CodeForwarder
{
GID = Guid.NewGuid().ToString(),
CreateTime = DateTime.Now,
CreateUser = UserManager.DjyUserId,
Code = entity.CodeName,
Name = entity.ShortName
});
}
else
{
ship.Code = entity.CodeName;
ship.Name = entity.ShortName;
ship.ModifyTime = DateTime.Now;
ship.ModifyUser = UserManager.DjyUserId;
await _codeForwarder.UpdateAsync(ship);
}
2 years ago
await _commonDBService.GetAllForwarder(false);
2 years ago
}
}
else
{
entity.Id = m.Id;
2 years ago
await _djycustomer.AsUpdateable(entity).IgnoreColumns(it => new
{
2 years ago
it.TenantId,
2 years ago
it.TIDANINFO
}).ExecuteCommandAsync();
2 years ago
await _djycustomercontact.DeleteAsync(x => x.CustomerId == entity.Id);
foreach (var it in item.ContactList)
{
var contact = it.Adapt<DjyCustomerContact>();
contact.CustomerId = entity.Id;
2 years ago
contact.TenantId = UserManager.TENANT_ID;
2 years ago
await _djycustomercontact.InsertAsync(contact);
2 years ago
}
if (entity.PropString.Contains("shipagency"))
{
2 years ago
var ship = shiplist.Where(x => x.Code == entity.CodeName).FirstOrDefault();
2 years ago
if (ship == null)
{
await _codeForwarder.InsertAsync(new CodeForwarder
{
GID = Guid.NewGuid().ToString(),
CreateTime = DateTime.Now,
CreateUser = UserManager.DjyUserId,
Code = entity.CodeName,
Name = entity.ShortName
});
}
else
{
ship.Code = entity.CodeName;
ship.Name = entity.ShortName;
ship.ModifyTime = DateTime.Now;
ship.ModifyUser = UserManager.DjyUserId;
await _codeForwarder.UpdateAsync(ship);
}
2 years ago
await _commonDBService.GetAllForwarder(false);
2 years ago
2 years ago
}
}
}
}
/// <summary>
/// 批量同步船期无返回值
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost("/DataSync/SyncVesselDateList"), ApiUser(ApiCode = "SyncVesselDateList")]
[SqlSugarUnitOfWork]
2 years ago
public async Task<dynamic> SyncVesselDateList(List<DjyVesselInfoDto> model)
2 years ago
{
2 years ago
var mapcarrier = _mapcarrier.Where(x => x.Module == "HeChuan").ToList();
2 years ago
var userlist = _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToList();
var mlist = _vesselinfo.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false).ToList();
var orderlist = _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false).ToList();
2 years ago
foreach (var item in model)
{
2 years ago
var CreatedUserId = userlist.Where(x => x.Name == item.CreatedUserName).Select(x => x.Id).FirstOrDefault();
2 years ago
if (string.IsNullOrWhiteSpace(item.BSNO))
{
throw Oops.Bah("BSNO未录入");
}
1 year ago
//根据东胜bsno获取当前数据查询不到则为新增
2 years ago
var m = mlist.Where(x => x.BSNO == item.BSNO).FirstOrDefault();
2 years ago
var entity = item.Adapt<DjyVesselInfo>();
2 years ago
entity.Vessel = item.Vessel.ToUpper().Trim();
2 years ago
if (!string.IsNullOrEmpty(item.CARRIER))
2 years ago
{
2 years ago
entity.CARRIERID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == item.CARRIER).Select(x => x.Code).FirstOrDefault();
2 years ago
2 years ago
if (string.IsNullOrEmpty(entity.CARRIERID))
2 years ago
{
entity.CARRIERID = mapcarrier.Where(x => x.MapName == item.CARRIER).Select(x => x.Code).FirstOrDefault();
}
if (string.IsNullOrEmpty(entity.CARRIERID))
{
throw Oops.Bah($"未找到{item.CARRIER}对应code,请联系管理员!");
}
2 years ago
}
2 years ago
2 years ago
if (!string.IsNullOrEmpty(item.CreatedUserName))
{
2 years ago
entity.CreatedUserId = CreatedUserId;
2 years ago
}
2 years ago
if (string.IsNullOrEmpty(item.Voyno))
{
entity.Voyno = entity.VoynoInside;
}
2 years ago
if (m == null)
{
1 year ago
//查询是否存在相同船名航次数据
var e = mlist.Where(x => x.CARRIERID == entity.CARRIERID && x.Vessel == entity.Vessel && x.Voyno == entity.Voyno && x.VoynoInside == entity.VoynoInside).FirstOrDefault();
1 year ago
//2023年7月27日王书岚航次为V.开头的不查询船期
if (!string.IsNullOrEmpty(entity.VoynoInside) && entity.VoynoInside.StartsWith("V."))
{
entity.Sign = true;
}
1 year ago
if (e == null)
{
await _vesselinfo.InsertAsync(entity);
}
else
1 year ago
{
1 year ago
entity.Id = e.Id;
if (e.ETA != null)
{
entity.ETA = e.ETA;
}
await _vesselinfo.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
2 years ago
}
else
{
1 year ago
//2023年7月27日王书岚航次为V.开头的不查询船期
if (!string.IsNullOrEmpty(entity.VoynoInside) && entity.VoynoInside.StartsWith("V."))
{
entity.Sign = true;
}
2 years ago
entity.Id = m.Id;
1 year ago
if (m.ETA != null)
2 years ago
{
1 year ago
entity.ETA = m.ETA;
2 years ago
}
2 years ago
await _vesselinfo.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
////根据船公司船名航次更新船期信息
if (!string.IsNullOrEmpty(item.CARRIER) && !string.IsNullOrEmpty(item.Vessel) && (!string.IsNullOrEmpty(item.Voyno) || !string.IsNullOrWhiteSpace(item.VoynoInside)))
{
var order = orderlist.Where(x => x.CARRIERID == item.CARRIERID && x.VESSEL == item.Vessel)
2 years ago
.WhereIF(!string.IsNullOrEmpty(item.Voyno), x => x.VOYNO == item.Voyno)
1 year ago
.WhereIF(!string.IsNullOrEmpty(item.VoynoInside), x => x.VOYNOINNER == item.VoynoInside).Distinct().ToList();
2 years ago
_logger.LogInformation($"同步船期_查询到{UserManager.TENANT_NAME}需要更新{order.Count()}条订舱数据");
foreach (var it in order)
{
var old = it;
2 years ago
//更新订舱船期
2 years ago
if (it.ETD != item.ETD && item.ETD != null)
2 years ago
{
it.ETD = item.ETD;
1 year ago
await _rep.AsUpdateable(it).IgnoreColumns(it => new
2 years ago
{
1 year ago
it.ParentId,
it.TenantId,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName,
it.TenantName,
it.IsDeleted,
it.BOOKINGNO,
it.LstShipOrderCompareId,
it.LstShipOrderCompareDate,
it.LstShipOrderCompareRlt,
it.LstShipOrderCompareRltName,
it.LstShipOrderCompareMode
}).ExecuteCommandAsync();
await _bookingorderservice.SaveLog(it, old);
await _bookingorderservice.SendBookingOrder(new long[] { it.Id });
2 years ago
}
2 years ago
}
}
}
2 years ago
return "上传成功!";
2 years ago
}
1 year ago
/// <summary>
/// 删除船期
/// </summary>
/// <returns></returns>
[HttpPost("/DataSync/DeletaVesselDate"), ApiUser(ApiCode = "DeletaVesselDate")]
[SqlSugarUnitOfWork]
public async Task DeletaVesselDate(string bsnos)
{
var arr = bsnos.Split(",");
if (arr.Count() > 0)
{
foreach (var item in arr)
{
await _vesselinfo.UpdateAsync(x => x.BSNO == item, x => new DjyVesselInfo { IsDeleted = true });
}
}
1 year ago
}
2 years ago
2 years ago
1 year ago
2 years ago
/// <summary>
/// 同步订舱批量 没有返回值
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
[SqlSugarUnitOfWork]
[HttpPost("/DataSync/SyncBookingList"), ApiUser(ApiCode = "SyncBookingList")]
2 years ago
public async Task SyncBookingList(List<SyncBookingOrderDto> list)
2 years ago
{
2 years ago
List<CodeCtn> ctncode = await _cache.GetAllCodeCtn();
2 years ago
var mapcarrier = await _mapcarrier.Where(x => x.Module == "HeChuan").ToListAsync();
var userlist = await _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync();
var djycustomer = await _djycustomer.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync();
var goodsconfig = await _goodsStatusConfig.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync();
var orderlist = await _rep.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false && x.TenantId == UserManager.TENANT_ID).ToListAsync();
2 years ago
var linelist = await _repline.AsQueryable().Filter(null, true).Where(m => m.TenantId == UserManager.TENANT_ID).ToListAsync();
2 years ago
foreach (var model in list)
{
if (string.IsNullOrWhiteSpace(model.BSNO))
{
throw Oops.Bah("主单BSNO未录入");
}
if (string.IsNullOrWhiteSpace(model.CreatedUserName))
{
throw Oops.Bah("未录入创建人");
}
var user = userlist.Where(x => x.Name == model.CreatedUserName.Trim() && x.IsDeleted == false).FirstOrDefault();
if (user == null)
2 years ago
{
2 years ago
throw Oops.Bah($"未匹配到创建人{model.CreatedUserName.Trim()}请联系管理员添加相关用户");
2 years ago
}
var order = orderlist.Where(x => x.BSNO == model.BSNO).FirstOrDefault();
2 years ago
2 years ago
if (order == null)
{
#region 新增
if (string.IsNullOrWhiteSpace(model.MBLNO))
{
throw Oops.Bah("请填写提单号!");
}
2 years ago
JsonUtil.PropToUpper(model, "ORDNO", "BSSTATUS", "YARDID", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
2 years ago
var ms = JsonUtil.TrimFields(model);
if (!string.IsNullOrEmpty(ms))
{
throw Oops.Bah(ms);
}
if (model.ctnInputs != null)
{
var groupList = model.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
model.CNTRTOTAL = string.Join(" / ", groupList);
}
var et = await _rep.Where(x => x.MBLNO == model.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == model.HBLNO && x.ParentId == 0).FirstAsync();
if (et != null)
{
throw Oops.Bah("当前提单号已存在,请勿重复录入!");
}
var entity = model.Adapt<BookingOrder>();
if (!string.IsNullOrEmpty(entity.ROUTE))
{
entity.ROUTEID = userlist.Where(x => x.Name == entity.ROUTE).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.ROUTE).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (!string.IsNullOrEmpty(entity.SALE))
{
entity.SALEID = userlist.Where(x => x.Name == entity.SALE).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (!string.IsNullOrEmpty(entity.OP))
{
entity.OPID = userlist.Where(x => x.Name == entity.OP).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.OP).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (!string.IsNullOrEmpty(entity.DOC))
{
entity.DOCID = userlist.Where(x => x.Name == entity.DOC).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (!string.IsNullOrEmpty(entity.CUSTSERVICE))
{
entity.CUSTSERVICEID = userlist.Where(x => x.Name == entity.CUSTSERVICE).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
2 years ago
if (!string.IsNullOrEmpty(entity.CUSTOMSER))
{
entity.CUSTOMSERID = djycustomer.Where(x => x.ShortName == entity.CUSTOMSER && x.PropString == "customs_broker").Select(x => x.CodeName).FirstOrDefault();
2 years ago
}
if (!string.IsNullOrEmpty(entity.TRUCKER))
{
entity.TRUCKERID = djycustomer.Where(x => x.ShortName == entity.TRUCKER && x.PropString == "fleet").Select(x => x.CodeName).FirstOrDefault();
2 years ago
}
if (!string.IsNullOrEmpty(entity.CUSTOMERNAME))
{
entity.CUSTOMERID = djycustomer.Where(x => x.ShortName == entity.CUSTOMERNAME && x.PropString == "consignor").Select(x => x.Id).FirstOrDefault();
}
if (!string.IsNullOrEmpty(entity.FORWARDER))
{
entity.FORWARDERID = djycustomer.Where(x => x.ShortName == entity.FORWARDER && x.PropString == "booking_agent").Select(x => x.CodeName).FirstOrDefault();
}
2 years ago
if (!string.IsNullOrEmpty(entity.YARD))
{
entity.YARDID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == entity.YARD).Select(x => x.Code).FirstOrDefault();
2 years ago
}
2 years ago
if (!string.IsNullOrEmpty(entity.CARRIER))
2 years ago
{
2 years ago
entity.CARRIERID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == entity.CARRIER).Select(x => x.Code).FirstOrDefault();
if (string.IsNullOrEmpty(entity.CARRIERID))
{
entity.CARRIERID = mapcarrier.Where(x => x.MapName == entity.CARRIER).Select(x => x.Code).FirstOrDefault();
}
2 years ago
}
2 years ago
if (!string.IsNullOrEmpty(entity.LineName))
2 years ago
{
var line = linelist.Where(m => m.LineName.Contains(entity.LineName)).FirstOrDefault();
2 years ago
if (line == null)
{
await _repline.InsertAsync(new DjyTenantLine
{
2 years ago
LineName = entity.LineName,
2 years ago
LineCode = "",
2 years ago
TenantId = UserManager.TENANT_ID,
CreatedUserId = user.Id,
CreatedUserName = user.Name
});
}
}
2 years ago
entity.BOOKINGNO = Yitter.IdGenerator.YitIdHelper.NextId().ToString();
entity.CreatedUserId = user.Id;
entity.CreatedUserName = user.Name.ToString();
2 years ago
entity.CreatedTime = DateTime.Now;
2 years ago
entity.TenantId = UserManager.TENANT_ID;
entity.TenantName = UserManager.TENANT_NAME;
2 years ago
entity.ParentId = 0;
await _rep.InsertAsync(entity);
if (model.ctnInputs != null)
{
foreach (var item in model.ctnInputs)
{
var ctnentity = item.Adapt<BookingCtn>();
ctnentity.BILLID = entity.Id;
ctnentity.CreatedUserId = user.Id;
ctnentity.CreatedUserName = user.Name;
2 years ago
ctnentity.CTNCODE = ctncode.Where(x => x.Name == ctnentity.CTNALL).Select(x => x.Code).FirstOrDefault();
2 years ago
ctnentity.CreatedUserId = user.Id;
ctnentity.CreatedUserName = user.Name.ToString();
ctnentity.CreatedTime = DateTime.Now;
ctnentity.TenantId = UserManager.TENANT_ID;
2 years ago
await _repCtn.InsertAsync(ctnentity);
//这里保存有可能没有添加多品名,所有箱下没有货物信息
if (item.ctnDetailInputs != null)
{
foreach (var it in item.ctnDetailInputs)
{
var ctndetail = it.Adapt<BookingCtnDetail>();
ctndetail.CTNID = ctnentity.Id;
ctndetail.CreatedUserId = user.Id;
ctndetail.CreatedUserName = user.Name;
2 years ago
ctndetail.CreatedUserId = user.Id;
ctndetail.CreatedUserName = user.Name.ToString();
ctndetail.CreatedTime = DateTime.Now;
ctndetail.TenantId = UserManager.TENANT_ID;
2 years ago
await _ctndetailrep.InsertAsync(ctndetail);
}
}
}
}
if (model.BookingEDIExt != null)
{
//写入EDI扩展
var ediExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
ediExtEntity.BookingId = entity.Id;
ediExtEntity.CreatedUserId = user.Id;
ediExtEntity.CreatedUserName = user.Name;
2 years ago
ediExtEntity.CreatedTime = DateTime.Now;
2 years ago
ediExtEntity.TenantId = UserManager.TENANT_ID;
2 years ago
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 = user.Id,
2 years ago
CreatedUserName = "系统"
});
//分单
if (model.childrens != null)
{
foreach (var item in model.childrens)
{
2 years ago
2 years ago
if (string.IsNullOrWhiteSpace(item.HBLNO))
{
throw Oops.Bah("请填写分提单号!");
}
2 years ago
JsonUtil.PropToUpper(item, "ORDNO", "BSSTATUS", "YARDID", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
2 years ago
var fms = JsonUtil.TrimFields(item);
if (!string.IsNullOrEmpty(fms))
{
throw Oops.Bah(fms);
}
if (item.ctnInputs != null)
{
var groupList = item.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
item.CNTRTOTAL = string.Join(" / ", groupList);
}
var fdet = await _rep.Where(x => x.MBLNO == model.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == model.HBLNO && x.ParentId == entity.Id).FirstAsync();
if (fdet != null)
{
throw Oops.Bah($"当前分单中提单号({item.MBLNO}_{item.HBLNO})已存在,请勿重复录入!");
}
var fdentity = item.Adapt<BookingOrder>();
if (!string.IsNullOrEmpty(fdentity.ROUTE))
{
fdentity.ROUTEID = userlist.Where(x => x.Name == fdentity.ROUTE).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.ROUTE).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (!string.IsNullOrEmpty(fdentity.SALE))
{
fdentity.SALEID = userlist.Where(x => x.Name == fdentity.SALE).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (!string.IsNullOrEmpty(fdentity.OP))
{
fdentity.OPID = userlist.Where(x => x.Name == fdentity.OP).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.OP).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (!string.IsNullOrEmpty(fdentity.DOC))
{
fdentity.DOCID = userlist.Where(x => x.Name == fdentity.DOC).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (!string.IsNullOrEmpty(fdentity.CUSTSERVICE))
{
fdentity.CUSTSERVICEID = userlist.Where(x => x.Name == fdentity.CUSTSERVICE).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (!string.IsNullOrEmpty(fdentity.CUSTOMSER))
{
fdentity.CUSTOMSERID = djycustomer.Where(x => x.ShortName == fdentity.CUSTOMSER && x.PropString == "customs_broker").Select(x => x.CodeName).FirstOrDefault();
}
if (!string.IsNullOrEmpty(fdentity.TRUCKER))
{
fdentity.TRUCKERID = djycustomer.Where(x => x.ShortName == fdentity.TRUCKER && x.PropString == "fleet").Select(x => x.CodeName).FirstOrDefault();
}
if (!string.IsNullOrEmpty(fdentity.CUSTOMERNAME))
{
fdentity.CUSTOMERID = djycustomer.Where(x => x.ShortName == fdentity.CUSTOMERNAME && x.PropString == "consignor").Select(x => x.Id).FirstOrDefault();
2 years ago
}
if (!string.IsNullOrEmpty(fdentity.FORWARDER))
2 years ago
{
fdentity.FORWARDERID = djycustomer.Where(x => x.ShortName == fdentity.FORWARDER && x.PropString == "booking_agent").Select(x => x.CodeName).FirstOrDefault();
2 years ago
}
2 years ago
if (!string.IsNullOrEmpty(fdentity.CARRIERID))
2 years ago
{
2 years ago
fdentity.CARRIER = _cache.GetAllCodeCarrier().Result.Where(x => x.Code == fdentity.CARRIERID).Select(x => x.CnName).FirstOrDefault();
2 years ago
}
2 years ago
if (!string.IsNullOrEmpty(fdentity.YARD))
{
fdentity.YARDID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == fdentity.YARD).Select(x => x.Code).FirstOrDefault();
}
2 years ago
if (!string.IsNullOrEmpty(fdentity.CARRIER))
{
fdentity.CARRIERID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == fdentity.CARRIER).Select(x => x.Code).FirstOrDefault();
if (string.IsNullOrEmpty(fdentity.CARRIERID))
{
fdentity.CARRIERID = mapcarrier.Where(x => x.MapName == fdentity.CARRIER).Select(x => x.Code).FirstOrDefault();
}
2 years ago
}
2 years ago
if (!string.IsNullOrEmpty(item.LineName))
2 years ago
{
2 years ago
var line = _repline.AsQueryable().Filter(null, true).Where(m => m.TenantId == UserManager.TENANT_ID && m.LineName.Contains(item.LineName)).FirstAsync();
2 years ago
if (line == null)
{
await _repline.InsertAsync(new DjyTenantLine
{
2 years ago
LineName = item.LineName,
2 years ago
LineCode = "",
2 years ago
TenantId = UserManager.TENANT_ID,
CreatedUserId = user.Id,
CreatedUserName = user.Name
});
}
}
2 years ago
fdentity.BOOKINGNO = Yitter.IdGenerator.YitIdHelper.NextId().ToString();
2 years ago
fdentity.MBLNO = entity.MBLNO;
fdentity.CreatedUserId = user.Id;
fdentity.CreatedUserName = user.Name;
2 years ago
fdentity.CreatedTime = DateTime.Now;
2 years ago
fdentity.TenantId = UserManager.TENANT_ID;
fdentity.TenantName = UserManager.TENANT_NAME;
2 years ago
fdentity.ParentId = entity.Id;
await _rep.InsertAsync(fdentity);
if (item.ctnInputs != null)
{
foreach (var it in item.ctnInputs)
{
var ctnentity = item.Adapt<BookingCtn>();
ctnentity.BILLID = fdentity.Id;
ctnentity.CreatedUserId = user.Id;
ctnentity.CreatedUserName = user.Name;
2 years ago
ctnentity.CTNCODE = ctncode.Where(x => x.Name == ctnentity.CTNALL).Select(x => x.Code).FirstOrDefault();
2 years ago
await _repCtn.InsertAsync(ctnentity);
//这里保存有可能没有添加多品名,所有箱下没有货物信息
if (it.ctnDetailInputs != null)
{
foreach (var dit in it.ctnDetailInputs)
{
var ctndetail = dit.Adapt<BookingCtnDetail>();
ctndetail.CTNID = ctnentity.Id;
ctndetail.CreatedUserId = user.Id;
ctndetail.CreatedUserName = user.Name;
2 years ago
await _ctndetailrep.InsertAsync(ctndetail);
}
}
}
}
if (item.BookingEDIExt != null)
{
//写入EDI扩展
var ediExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
ediExtEntity.BookingId = fdentity.Id;
ediExtEntity.CreatedUserId = user.Id;
ediExtEntity.CreatedUserName = user.Name;
2 years ago
ediExtEntity.CreatedTime = DateTime.Now;
await _bookingEDIExt.InsertAsync(ediExtEntity);
}
////添加booking日志
await _bookinglog.InsertAsync(new BookingLog
{
Type = "Add",
BookingId = fdentity.Id,
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
CreatedTime = DateTime.Now,
CreatedUserId = user.Id,
2 years ago
CreatedUserName = "系统"
});
}
}
if (model.GoodsStatus != null)
{
foreach (var item in model.GoodsStatus)
{
if (!string.IsNullOrEmpty(item.StatusName))
{
var gc = goodsconfig.Where(x => x.StatusName == item.StatusName && x.CreatedUserId == user.Id).FirstOrDefault();
if (gc != null)
{
await _goodsStatus.InsertAsync(new BookingGoodsStatus
{
bookingId = entity.Id,
ConfigId = gc.Id,
FinishTime = item.FinishTime,
FinishUser = user.Name,
FinishUserId = user.Id,
Remark = item.Remark,
ExtData = item.ExtData
});
}
else
{
2 years ago
var configid = await _goodsStatusConfig.InsertReturnSnowflakeIdAsync(new BookingGoodsStatusConfig
{
StatusName = item.StatusName,
Sort = goodsconfig.Where(x => x.CreatedUserId == user.Id).Max(x => x.Sort) + 1,
2 years ago
CreatedTime = DateTime.Now,
CreatedUserId = user.Id,
CreatedUserName = user.Name,
IsDeleted = false
});
await _goodsStatus.InsertAsync(new BookingGoodsStatus
{
bookingId = entity.Id,
ConfigId = configid,
FinishTime = item.FinishTime,
FinishUser = user.Name,
FinishUserId = user.Id,
Remark = item.Remark,
ExtData = item.ExtData
});
}
}
}
}
2 years ago
if (!string.IsNullOrEmpty(model.CtnDayNum))
{
var gc = goodsconfig.Where(x => x.StatusName == "申请箱使" && x.CreatedUserId == user.Id).FirstOrDefault();
if (gc != null)
{
await _goodsStatus.InsertAsync(new BookingGoodsStatus
{
bookingId = entity.Id,
ConfigId = gc.Id,
FinishTime = DateTime.Now,
FinishUser = user.Name,
FinishUserId = user.Id,
Remark = "",
ExtData = model.CtnDayNum
});
}
else
{
var configid = await _goodsStatusConfig.InsertReturnSnowflakeIdAsync(new BookingGoodsStatusConfig
{
StatusName = "申请箱使",
Sort = goodsconfig.Where(x => x.CreatedUserId == user.Id).Max(x => x.Sort) + 1,
CreatedTime = DateTime.Now,
CreatedUserId = user.Id,
CreatedUserName = user.Name,
IsDeleted = false
});
await _goodsStatus.InsertAsync(new BookingGoodsStatus
{
bookingId = entity.Id,
ConfigId = configid,
FinishTime = DateTime.Now,
FinishUser = user.Name,
FinishUserId = user.Id,
Remark = "",
ExtData = model.CtnDayNum
});
}
}
2 years ago
#endregion
}
else
{
#region 编辑
if (string.IsNullOrWhiteSpace(model.MBLNO))
{
throw Oops.Bah("请填写提单号!");
}
2 years ago
JsonUtil.PropToUpper(model, "ORDNO", "BSSTATUS", "YARDID", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
2 years ago
var ms = JsonUtil.TrimFields(model);
if (!string.IsNullOrEmpty(ms))
{
throw Oops.Bah(ms);
}
if (model.ctnInputs != null)
{
var groupList = model.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
model.CNTRTOTAL = string.Join(" / ", groupList);
}
2 years ago
var main = await _rep.AsQueryable().Filter(null, true).Where(x => x.BSNO == model.BSNO && x.IsDeleted == false).FirstAsync();
2 years ago
var et = await _rep.AsQueryable().Filter(null, true).Where(x => x.MBLNO == model.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == model.HBLNO && x.BSNO != model.BSNO).FirstAsync();
if (et != null)
{
throw Oops.Bah("当前提单号已存在,请勿重复录入!");
}
var entity = model.Adapt<BookingOrder>();
entity.Id = main.Id;
entity.UpdatedUserName = user.Name;
entity.UpdatedUserId = user.Id;
2 years ago
entity.UpdatedTime = DateTime.Now;
if (!string.IsNullOrEmpty(entity.ROUTE))
{
entity.ROUTEID = userlist.Where(x => x.Name == entity.ROUTE).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.ROUTE).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (!string.IsNullOrEmpty(entity.SALE))
{
entity.SALEID = userlist.Where(x => x.Name == entity.SALE).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (!string.IsNullOrEmpty(entity.OP))
{
entity.OPID = userlist.Where(x => x.Name == entity.OP).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.OP).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (!string.IsNullOrEmpty(entity.DOC))
{
entity.DOCID = userlist.Where(x => x.Name == entity.DOC).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (!string.IsNullOrEmpty(entity.CUSTSERVICE))
{
entity.CUSTSERVICEID = userlist.Where(x => x.Name == entity.CUSTSERVICE).Count() == 0 ? "" : userlist.Where(x => x.Name == entity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
2 years ago
if (!string.IsNullOrEmpty(entity.CUSTOMSER))
{
entity.CUSTOMSERID = djycustomer.Where(x => x.ShortName == entity.CUSTOMSER && x.PropString == "customs_broker").Select(x => x.CodeName).FirstOrDefault();
2 years ago
}
if (!string.IsNullOrEmpty(entity.TRUCKER))
{
entity.TRUCKERID = djycustomer.Where(x => x.ShortName == entity.TRUCKER && x.PropString == "fleet").Select(x => x.CodeName).FirstOrDefault();
}
if (!string.IsNullOrEmpty(entity.CUSTOMERNAME))
{
entity.CUSTOMERID = djycustomer.Where(x => x.ShortName == entity.CUSTOMERNAME && x.PropString == "consignor").Select(x => x.Id).FirstOrDefault();
}
if (!string.IsNullOrEmpty(entity.FORWARDER))
{
entity.FORWARDERID = djycustomer.Where(x => x.ShortName == entity.FORWARDER && x.PropString == "booking_agent").Select(x => x.CodeName).FirstOrDefault();
2 years ago
}
2 years ago
if (!string.IsNullOrEmpty(entity.YARD))
{
entity.YARDID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == entity.YARD).Select(x => x.Code).FirstOrDefault();
}
2 years ago
if (!string.IsNullOrEmpty(entity.CARRIER))
2 years ago
{
2 years ago
entity.CARRIERID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == entity.CARRIER).Select(x => x.Code).FirstOrDefault();
if (string.IsNullOrEmpty(entity.CARRIERID))
{
entity.CARRIERID = mapcarrier.Where(x => x.MapName == entity.CARRIER).Select(x => x.Code).FirstOrDefault();
}
2 years ago
}
2 years ago
2 years ago
if (!string.IsNullOrEmpty(entity.LineName))
2 years ago
{
2 years ago
var line = _repline.AsQueryable().Filter(null, true).Where(m => m.TenantId == UserManager.TENANT_ID && m.LineName.Contains(entity.LineName)).FirstAsync();
2 years ago
if (line == null)
{
await _repline.InsertAsync(new DjyTenantLine
{
2 years ago
LineName = entity.LineName,
2 years ago
LineCode = "",
2 years ago
TenantId = UserManager.TENANT_ID,
CreatedUserId = user.Id,
CreatedUserName = user.Name
});
}
}
2 years ago
await _rep.AsUpdateable(entity).IgnoreColumns(it => new
{
2 years ago
it.BOOKINGNO,
2 years ago
it.ParentId,
it.TenantId,
2 years ago
it.TenantName,
2 years ago
it.YgtETD,
2 years ago
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName,
it.LstShipOrderCompareId,
it.LstShipOrderCompareDate,
it.LstShipOrderCompareRltName,
it.LstShipOrderCompareMode
2 years ago
}).ExecuteCommandAsync();
var ctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == main.Id).Select(x => x.Id).ToListAsync();
await _repCtn.DeleteAsync(x => x.BILLID == main.Id);
await _ctndetailrep.DeleteAsync(x => ctnlist.Contains((long)x.CTNID));
await _goodsStatus.DeleteAsync(x => x.bookingId == main.Id);
2 years ago
if (model.ctnInputs != null)
{
foreach (var item in model.ctnInputs)
{
var ctnentity = item.Adapt<BookingCtn>();
ctnentity.BILLID = main.Id;
ctnentity.CreatedUserId = user.Id;
ctnentity.CreatedUserName = user.Name;
2 years ago
ctnentity.CTNCODE = ctncode.Where(x => x.Name == ctnentity.CTNALL).Select(x => x.Code).FirstOrDefault();
2 years ago
await _repCtn.InsertAsync(ctnentity);
if (item.ctnDetailInputs != null)
{
foreach (var it in item.ctnDetailInputs)
{
var ctndetail = it.Adapt<BookingCtnDetail>();
ctndetail.CTNID = ctnentity.Id;
ctndetail.CreatedUserId = user.Id;
ctndetail.CreatedUserName = user.Name;
2 years ago
await _ctndetailrep.InsertAsync(ctndetail);
}
}
}
}
if (model.BookingEDIExt != null)
{
//检索EDI扩展
2 years ago
var ediExtEntity = await _bookingEDIExt.AsQueryable().Filter(null, true).Where(x => x.BookingId == main.Id).FirstAsync();
2 years ago
if (ediExtEntity == null)
{
//写入EDI扩展
ediExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
ediExtEntity.BookingId = main.Id;
ediExtEntity.CreatedUserId = user.Id;
ediExtEntity.CreatedUserName = user.Name;
2 years ago
ediExtEntity.CreatedTime = DateTime.Now;
await _bookingEDIExt.InsertAsync(ediExtEntity);
}
else
{
//更新EDI扩展
var currEdiExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
currEdiExtEntity.Id = ediExtEntity.Id;
currEdiExtEntity.UpdatedUserId = user.Id;
2 years ago
currEdiExtEntity.UpdatedTime = DateTime.Now;
await _bookingEDIExt.AsUpdateable(currEdiExtEntity).IgnoreColumns(it => new
{
it.BookingId,
it.TenantId,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName
}).ExecuteCommandAsync();
}
}
if (model.GoodsStatus != null)
{
foreach (var item in model.GoodsStatus)
{
if (!string.IsNullOrEmpty(item.StatusName))
{
var gc = goodsconfig.Where(x => x.StatusName == item.StatusName && x.CreatedUserId == user.Id).FirstOrDefault();
if (gc != null)
{
await _goodsStatus.InsertAsync(new BookingGoodsStatus
{
bookingId = entity.Id,
ConfigId = gc.Id,
FinishTime = item.FinishTime,
FinishUser = user.Name,
FinishUserId = user.Id,
Remark = item.Remark,
ExtData = item.ExtData
});
}
else
{
2 years ago
long configid = await _goodsStatusConfig.InsertReturnSnowflakeIdAsync(new BookingGoodsStatusConfig
{
StatusName = item.StatusName,
Sort = goodsconfig.Where(x => x.CreatedUserId == user.Id).Max(x => x.Sort) + 1,
2 years ago
CreatedTime = DateTime.Now,
CreatedUserId = user.Id,
CreatedUserName = user.Name,
IsDeleted = false
});
await _goodsStatus.InsertAsync(new BookingGoodsStatus
{
bookingId = entity.Id,
ConfigId = configid,
FinishTime = item.FinishTime,
FinishUser = user.Name,
FinishUserId = user.Id,
Remark = item.Remark,
ExtData = item.ExtData
});
}
}
}
}
2 years ago
if (!string.IsNullOrEmpty(model.CtnDayNum))
{
var gc = goodsconfig.Where(x => x.StatusName == "申请箱使" && x.CreatedUserId == user.Id).FirstOrDefault();
if (gc != null)
{
await _goodsStatus.InsertAsync(new BookingGoodsStatus
{
bookingId = entity.Id,
ConfigId = gc.Id,
FinishTime = DateTime.Now,
FinishUser = user.Name,
FinishUserId = user.Id,
Remark = "",
ExtData = model.CtnDayNum
});
}
else
{
2 years ago
var Sort = goodsconfig.Where(x => x.CreatedUserId == user.Id).Count();
2 years ago
var configid = await _goodsStatusConfig.InsertReturnSnowflakeIdAsync(new BookingGoodsStatusConfig
{
StatusName = "申请箱使",
2 years ago
Sort = Sort + 1,
2 years ago
CreatedTime = DateTime.Now,
CreatedUserId = user.Id,
CreatedUserName = user.Name,
IsDeleted = false
});
await _goodsStatus.InsertAsync(new BookingGoodsStatus
{
bookingId = entity.Id,
ConfigId = configid,
FinishTime = DateTime.Now,
FinishUser = user.Name,
FinishUserId = user.Id,
Remark = "",
ExtData = model.CtnDayNum
});
}
}
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 && !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 = user.Id,
CreatedUserName = user.Name
2 years ago
});
flag = false;
}
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
{
PId = bid,
Field = descriptor.Description,
OldValue = _oldvalue,
NewValue = _value,
});
}
}
//分单
if (model.childrens != null)
{
foreach (var item in model.childrens)
{
2 years ago
var fenlanename = item.LANECODE;
var fenlinename = item.LANENAME;
2 years ago
if (string.IsNullOrWhiteSpace(item.HBLNO))
2 years ago
{
2 years ago
throw Oops.Bah("请填写分提单号!");
2 years ago
}
2 years ago
JsonUtil.PropToUpper(item, "ORDNO", "BSSTATUS", "YARDID", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
2 years ago
var fms = JsonUtil.TrimFields(item);
if (!string.IsNullOrEmpty(fms))
{
throw Oops.Bah(fms);
}
if (item.ctnInputs != null)
{
var groupList = item.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
item.CNTRTOTAL = string.Join(" / ", groupList);
}
2 years ago
var fdmain = await _rep.AsQueryable().Filter(null, true).Where(x => x.BSNO == item.BSNO && x.IsDeleted == false).FirstAsync();
2 years ago
var fdentity = item.Adapt<BookingOrder>();
if (fdmain != null)
{
var fdet = await _rep.Where(x => x.MBLNO == item.MBLNO && x.TenantId == UserManager.TENANT_ID && x.HBLNO == item.HBLNO && x.BSNO != fdmain.BSNO).FirstAsync();
if (fdet != null)
{
throw Oops.Bah($"当前提单号{fdet.MBLNO}_{fdet.HBLNO}已存在,请勿重复录入!");
}
2 years ago
fdentity.MBLNO = entity.MBLNO;
2 years ago
fdentity.Id = fdmain.Id;
fdentity.UpdatedUserName = user.Name;
fdentity.UpdatedUserId = user.Id;
2 years ago
fdentity.UpdatedTime = DateTime.Now;
if (!string.IsNullOrEmpty(fdentity.ROUTE))
{
fdentity.ROUTEID = userlist.Where(x => x.Name == fdentity.ROUTE).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.ROUTE).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (!string.IsNullOrEmpty(fdentity.SALE))
{
fdentity.SALEID = userlist.Where(x => x.Name == fdentity.SALE).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (!string.IsNullOrEmpty(fdentity.OP))
{
fdentity.OPID = userlist.Where(x => x.Name == fdentity.OP).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.OP).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (!string.IsNullOrEmpty(fdentity.DOC))
{
fdentity.DOCID = userlist.Where(x => x.Name == fdentity.DOC).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (!string.IsNullOrEmpty(fdentity.CUSTSERVICE))
{
fdentity.CUSTSERVICEID = userlist.Where(x => x.Name == fdentity.CUSTSERVICE).Count() == 0 ? "" : userlist.Where(x => x.Name == fdentity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
2 years ago
}
if (!string.IsNullOrEmpty(fdentity.CUSTOMSER))
{
fdentity.CUSTOMSERID = djycustomer.Where(x => x.ShortName == fdentity.CUSTOMSER && x.PropString == "customs_broker").Select(x => x.CodeName).FirstOrDefault();
2 years ago
}
if (!string.IsNullOrEmpty(fdentity.TRUCKER))
{
fdentity.TRUCKERID = djycustomer.Where(x => x.ShortName == fdentity.TRUCKER && x.PropString == "fleet").Select(x => x.CodeName).FirstOrDefault();
}
if (!string.IsNullOrEmpty(fdentity.CUSTOMERNAME))
{
fdentity.CUSTOMERID = djycustomer.Where(x => x.ShortName == fdentity.CUSTOMERNAME && x.PropString == "consignor").Select(x => x.Id).FirstOrDefault();
}
if (!string.IsNullOrEmpty(fdentity.FORWARDER))
{
fdentity.FORWARDERID = djycustomer.Where(x => x.ShortName == fdentity.FORWARDER && x.PropString == "booking_agent").Select(x => x.CodeName).FirstOrDefault();
2 years ago
}
2 years ago
if (!string.IsNullOrEmpty(fdentity.YARD))
{
fdentity.YARDID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == fdentity.YARD).Select(x => x.Code).FirstOrDefault();
}
2 years ago
if (!string.IsNullOrEmpty(fdentity.CARRIER))
2 years ago
{
2 years ago
fdentity.CARRIERID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == fdentity.CARRIER).Select(x => x.Code).FirstOrDefault();
if (string.IsNullOrEmpty(fdentity.CARRIERID))
{
fdentity.CARRIERID = mapcarrier.Where(x => x.MapName == fdentity.CARRIER).Select(x => x.Code).FirstOrDefault();
}
2 years ago
}
2 years ago
if (!string.IsNullOrEmpty(fdentity.LineName))
2 years ago
{
2 years ago
var line = _repline.AsQueryable().Filter(null, true).Where(m => m.TenantId == UserManager.TENANT_ID && m.LineName.Contains(fdentity.LineName)).FirstAsync();
2 years ago
if (line == null)
{
await _repline.InsertAsync(new DjyTenantLine
{
2 years ago
LineName = fdentity.LineName,
2 years ago
LineCode = "",
2 years ago
TenantId = UserManager.TENANT_ID,
CreatedUserId = user.Id,
CreatedUserName = user.Name
});
}
}
2 years ago
await _rep.AsUpdateable(fdentity).IgnoreColumns(it => new
{
2 years ago
it.BOOKINGNO,
2 years ago
it.ParentId,
it.TenantId,
2 years ago
it.TenantName,
2 years ago
it.CreatedTime,
it.CreatedUserId,
2 years ago
it.YgtETD,
2 years ago
it.CreatedUserName,
it.LstShipOrderCompareId,
it.LstShipOrderCompareDate,
it.LstShipOrderCompareRltName,
it.LstShipOrderCompareMode
2 years ago
}).ExecuteCommandAsync();
var fdctnlist = await _repCtn.AsQueryable().Where(x => x.BILLID == fdmain.Id).Select(x => x.Id).ToListAsync();
await _repCtn.DeleteAsync(x => x.BILLID == fdmain.Id);
await _ctndetailrep.DeleteAsync(x => fdctnlist.Contains((long)x.CTNID));
if (item.ctnInputs != null)
{
foreach (var it in model.ctnInputs)
{
var ctnentity = item.Adapt<BookingCtn>();
ctnentity.BILLID = fdmain.Id;
ctnentity.CreatedUserId = user.Id;
ctnentity.CreatedUserName = user.Name;
2 years ago
ctnentity.CTNCODE = ctncode.Where(x => x.Name == ctnentity.CTNALL).Select(x => x.Code).FirstOrDefault();
2 years ago
await _repCtn.InsertAsync(ctnentity);
if (it.ctnDetailInputs != null)
{
foreach (var it_ in it.ctnDetailInputs)
{
var ctndetail = it_.Adapt<BookingCtnDetail>();
ctndetail.CTNID = ctnentity.Id;
ctndetail.CreatedUserId = user.Id;
ctndetail.CreatedUserName = user.Name;
2 years ago
await _ctndetailrep.InsertAsync(ctndetail);
}
}
}
}
2 years ago
if (item.BookingEDIExt != null)
{
//检索EDI扩展
var ediExtEntity = await _bookingEDIExt.AsQueryable().Filter(null, true).Where(x => x.BookingId == fdmain.Id).FirstAsync();
2 years ago
if (ediExtEntity == null)
{
//写入EDI扩展
ediExtEntity = item.BookingEDIExt.Adapt<BookingEDIExt>();
ediExtEntity.BookingId = fdmain.Id;
ediExtEntity.CreatedUserId = user.Id;
ediExtEntity.CreatedUserName = user.Name;
2 years ago
ediExtEntity.CreatedTime = DateTime.Now;
await _bookingEDIExt.InsertAsync(ediExtEntity);
}
else
{
//更新EDI扩展
var currEdiExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
currEdiExtEntity.Id = ediExtEntity.Id;
await _bookingEDIExt.AsUpdateable(currEdiExtEntity).IgnoreColumns(it => new
{
it.BookingId,
it.TenantId,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName
}).ExecuteCommandAsync();
}
}
bool fdflag = true;
long fdbid = 0;
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(fdentity))
{
string name = descriptor.Name;
if (name == "TenantId" || name == "CreatedTime" || name == "UpdatedTime" || name == "CreatedUserId" || name == "CreatedUserName")
{
continue;
}
object value = descriptor.GetValue(fdentity);
var oldvalue = fdmain.GetType().GetProperty(name).GetValue(fdmain, null);
2 years ago
2 years ago
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 (fdflag)
{
////添加booking日志
fdbid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog
{
Type = "Edit",
BookingId = fdentity.Id,
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
CreatedTime = DateTime.Now,
CreatedUserId = user.Id,
CreatedUserName = user.Name,
2 years ago
});
fdflag = false;
}
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
{
PId = fdbid,
Field = descriptor.Description,
OldValue = _oldvalue,
NewValue = _value,
});
2 years ago
2 years ago
}
}
2 years ago
}
else
{
fdentity.CreatedUserId = user.Id;
fdentity.CreatedUserName = user.Name;
2 years ago
fdentity.CreatedTime = DateTime.Now;
fdentity.ParentId = entity.Id;
await _rep.InsertAsync(fdentity);
if (item.ctnInputs != null)
{
foreach (var it in item.ctnInputs)
{
var ctnentity = item.Adapt<BookingCtn>();
ctnentity.BILLID = fdentity.Id;
ctnentity.CreatedUserId = user.Id;
ctnentity.CreatedUserName = user.Name;
2 years ago
await _repCtn.InsertAsync(ctnentity);
//这里保存有可能没有添加多品名,所有箱下没有货物信息
if (it.ctnDetailInputs != null)
{
foreach (var dit in it.ctnDetailInputs)
{
var ctndetail = dit.Adapt<BookingCtnDetail>();
ctndetail.CTNID = ctnentity.Id;
ctndetail.CreatedUserId = user.Id;
ctndetail.CreatedUserName = user.Name;
2 years ago
await _ctndetailrep.InsertAsync(ctndetail);
}
}
}
}
2 years ago
if (item.BookingEDIExt != null)
2 years ago
{
2 years ago
//检索EDI扩展
2 years ago
var ediExtEntity = await _bookingEDIExt.AsQueryable().Filter(null, true).Where(x => x.BookingId == fdentity.Id).FirstAsync();
2 years ago
if (ediExtEntity == null)
2 years ago
{
2 years ago
//写入EDI扩展
ediExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
ediExtEntity.BookingId = fdentity.Id;
ediExtEntity.CreatedUserId = user.Id;
ediExtEntity.CreatedUserName = user.Name;
2 years ago
ediExtEntity.CreatedTime = DateTime.Now;
await _bookingEDIExt.InsertAsync(ediExtEntity);
2 years ago
}
2 years ago
else
2 years ago
{
2 years ago
//更新EDI扩展
var currEdiExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
currEdiExtEntity.Id = ediExtEntity.Id;
currEdiExtEntity.UpdatedUserId = user.Id;
2 years ago
currEdiExtEntity.UpdatedTime = DateTime.Now;
await _bookingEDIExt.AsUpdateable(currEdiExtEntity).IgnoreColumns(it => new
2 years ago
{
2 years ago
it.BookingId,
it.TenantId,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName
}).ExecuteCommandAsync();
2 years ago
}
}
}
}
}
#endregion
}
}
}
2 years ago
/// <summary>
2 years ago
/// 爬虫上传船期港前
2 years ago
/// </summary>
/// <returns></returns>
2 years ago
[HttpPost("/DataSync/SaveSyncVesselDate"), ApiUser(ApiCode = "SaveSyncVesselDate")]
2 years ago
[SqlSugarUnitOfWork]
public async Task SaveSyncVesselDate(List<DjyVesselDto> dto)
{
var infolist = _vesselinfo.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false).ToList();
var orderlist = await _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false).ToListAsync();
2 years ago
foreach (var item in dto)
{
1 year ago
//var model = infolist.Where(x => x.Vessel == item.Vessel && x.Voyno == item.Voyno).FirstOrDefault();
//if (model != null)
//{
// model.ETA = item.ETA;
// model.YgtETD = item.ETD;
// model.ATD = item.ATD;
// model.UpdatedTime = DateTime.Now;
// await _vesselinfo.AsUpdateable(model).IgnoreColumns().ExecuteCommandAsync();
//}
1 year ago
await _vesselinfo.UpdateAsync(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false &&
x.Vessel == item.Vessel && x.Voyno == item.Voyno, x => new DjyVesselInfo { ETA = item.ETA, YgtETD = item.ETD, ATD = item.ATD, UpdatedTime = DateTime.Now });
2 years ago
var order = orderlist.Where(x => x.VESSEL == item.Vessel && x.VOYNO == item.Voyno).ToList();
2 years ago
bool issend = false;
2 years ago
if (order != null)
{
foreach (var it in order)
{
var old = it;
2 years ago
bool flag = false;
2 years ago
if (it.StartETA != item.ETA)
2 years ago
{
2 years ago
flag = true;
2 years ago
it.StartETA = item.ETA;
}
if (it.YgtETD != item.ETD)
{
2 years ago
flag = true;
2 years ago
it.YgtETD = item.ETD;
2 years ago
}
1 year ago
if (it.ATD != item.ATD && it.ATD == null)
2 years ago
{
2 years ago
flag = true;
2 years ago
it.ATD = item.ATD;
}
2 years ago
if (it.StartATA != item.ATA)
2 years ago
{
2 years ago
flag = true;
2 years ago
it.StartATA = item.ATA;
2 years ago
}
2 years ago
if (flag)
{
issend = true;
await _rep.AsUpdateable(it).IgnoreColumns().ExecuteCommandAsync();
await _bookingorderservice.SaveLog(it, old);
2 years ago
}
2 years ago
}
2 years ago
if (issend)
2 years ago
{
1 year ago
var ids = order.Where(x => x.ParentId == 0).Select(x => x.Id).ToArray();
if (ids.Count() > 0)
{
await _bookingorderservice.SendBookingOrder(ids);
}
2 years ago
}
2 years ago
}
}
}
2 years ago
2 years ago
/// <summary>
/// 爬虫上传船期港后
/// </summary>
/// <returns></returns>
[HttpPost("/DataSync/SaveSyncGHVesselDate"), ApiUser(ApiCode = "SaveSyncGHVesselDate")]
[SqlSugarUnitOfWork]
public async Task SaveSyncGHVesselDate(List<DjyVesselGHDto> dto)
{
var orderlist = await _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false).ToListAsync();
2 years ago
foreach (var item in dto)
{
2 years ago
2 years ago
//var model = _vesselinfo.AsQueryable().Filter(null, true).Where(x => x.Vessel == item.Vessel && x.Voyno == item.Voyno && x.TenantId == UserManager.TENANT_ID).FirstOrDefault();
2 years ago
//model.ETA = item.ETA;
//model.ETD = item.ETD;
//model.ATD = item.ATD;
//await _vesselinfo.AsUpdateable(model).IgnoreColumns().ExecuteCommandAsync();
2 years ago
var order = orderlist.Where(x => x.VESSEL == item.Vessel && x.VOYNO == item.Voyno).ToList();
2 years ago
bool issend = false;
2 years ago
if (order != null)
{
foreach (var it in order)
{
var old = it;
2 years ago
bool flag = false;
2 years ago
2 years ago
if (it.ETA != item.ETA)
{
2 years ago
flag = true;
2 years ago
it.ETA = item.ETA;
}
if (it.MiddleETA != item.MiddleETA)
{
2 years ago
flag = true;
2 years ago
it.MiddleETA = item.MiddleETA;
}
if (it.MiddleETD != item.MiddleETD)
{
2 years ago
flag = true;
2 years ago
it.MiddleETD = item.MiddleETD;
}
if (item.MiddleATA != it.MiddleATA)
{
2 years ago
flag = true;
2 years ago
it.MiddleATA = item.MiddleATA;
}
2 years ago
2 years ago
if (item.MiddleATD != it.MiddleATD)
{
2 years ago
flag = true;
2 years ago
it.MiddleATD = item.MiddleATD;
}
2 years ago
2 years ago
if (item.ATA != it.ATA)
{
2 years ago
flag = true;
2 years ago
it.ATA = item.ATA;
}
2 years ago
2 years ago
if (flag)
{
issend = true;
await _rep.AsUpdateable(it).IgnoreColumns().ExecuteCommandAsync();
await _bookingorderservice.SaveLog(it, old);
2 years ago
}
2 years ago
}
2 years ago
if (issend)
2 years ago
{
1 year ago
var ids = order.Where(x => x.ParentId == 0).Select(x => x.Id).ToArray();
if (ids.Count() > 0)
{
await _bookingorderservice.SendBookingOrder(ids);
}
2 years ago
2 years ago
}
2 years ago
2 years ago
}
}
2 years ago
}
/// <summary>
/// 航线上传同步
/// </summary>
/// <returns></returns>
[HttpPost("/DataSync/SyncLine"), ApiUser(ApiCode = "SyncLine")]
[SqlSugarUnitOfWork]
public async Task SyncLine(LineSyncDto dto)
{
var idList = dto.DataList.Select(x => x.Code).ToList();
var laneList = _codeLaneRep.Where(x => idList.Contains(x.Code)).ToList();
if (dto.Type == "save")
{
foreach (var dtoLine in dto.DataList)
{
var lane = laneList.FirstOrDefault(x => x.Code == dtoLine.Code);
if (lane != null)
{
lane.EnName = dtoLine.Name;
lane.CnName = dtoLine.Name;
lane.ModifyTime = DateTime.Now;
lane.ModifyUser = UserManager.Name;
await _codeLaneRep.UpdateAsync(lane);
}
else
{
lane = new CodeLane();
lane.GID = Guid.NewGuid().ToString();
lane.Code = dtoLine.Code;
lane.EnName = dtoLine.Name;
lane.CnName = dtoLine.Name;
lane.LaneType = "SEA";
lane.CreateTime = DateTime.Now;
lane.CreateUser = UserManager.Name;
await _codeLaneRep.InsertAsync(lane);
}
}
await _commonDBService.GetAllLane(false); //刷新缓存
}
else if (dto.Type == "del")
{
foreach (var lane in laneList)
{
await _codeLaneRep.DeleteAsync(lane);
}
await _commonDBService.GetAllLane(false); //刷新缓存
}
else
{
throw Oops.Bah($"同步类型无效:{dto.Type}");
}
}
/// <summary>
/// 目的港上传同步
/// </summary>
/// <returns></returns>
[HttpPost("/DataSync/SyncDisport"), ApiUser(ApiCode = "SyncDisport")]
[SqlSugarUnitOfWork]
public async Task SyncDisport(DisportSyncDto dto)
{
var idList = dto.DataList.Select(x => x.Code).ToList();
var portList = _codePortRep.Where(x => idList.Contains(x.Code)).ToList();
var relaList = _relaPortLane.Where(x => idList.Contains(x.PortCode) && (x.CarrierCode == null || x.CarrierCode == "") && (x.Module == null || x.Module == "")).ToList();
var laneList = _codeLaneRep.ToList();
if (dto.Type == "save")
{
foreach (var dtoPort in dto.DataList)
{
var port = portList.FirstOrDefault(x => x.Code == dtoPort.Code);
if (port != null)
{
dtoPort.Adapt(port);
port.ModifyTime = DateTime.Now;
port.ModifyUser = UserManager.Name;
await _codePortRep.UpdateAsync(port);
}
else
{
port = new CodePort();
port.GID = Guid.NewGuid().ToString();
dtoPort.Adapt(port);
port.CreateTime = DateTime.Now;
port.CreateUser = UserManager.Name;
await _codePortRep.InsertAsync(port);
}
//处理港口、航线对应关系
var lane = laneList.FirstOrDefault(x => x.CnName == port.ShippingRoute);
if (lane != null)
{
var rela = relaList.FirstOrDefault(x => x.PortCode == port.Code && x.LaneCode == lane.Code);
if (rela == null) //没有存在的映射关系,直接添加
{
rela = new RelaPortCarrierLane();
rela.GID = Guid.NewGuid().ToString();
rela.PortCode = port.Code;
rela.LaneCode = lane.Code;
rela.CarrierCode = "";
rela.Module = "";
rela.CreateTime = DateTime.Now;
rela.CreateUser = UserManager.Name;
await _relaPortLane.InsertAsync(rela);
}
else if (rela.LaneCode != lane.Code) //存在映射关系,但不是上传数据中的航线
{
rela.LaneCode = lane.Code; //修改航线映射
rela.ModifyTime = DateTime.Now;
rela.ModifyUser = UserManager.Name;
await _relaPortLane.UpdateAsync(rela);
}
}
}
await _commonDBService.GetAllPort(false); //刷新缓存
await _commonDBService.GetAllRelaPortCarrierLane(false); //刷新缓存
}
else if (dto.Type == "del")
{
//删除港口数据
foreach (var port in portList)
{
await _codePortRep.DeleteAsync(port);
}
//删除映射关系
foreach (var rela in relaList)
{
await _relaPortLane.DeleteAsync(rela);
}
await _commonDBService.GetAllPort(false); //刷新缓存
await _commonDBService.GetAllRelaPortCarrierLane(false); //刷新缓存
}
else
{
throw Oops.Bah($"同步类型无效:{dto.Type}");
}
}
/// <summary>
/// 船期获取异常提醒
/// </summary>
/// <returns></returns>
[HttpPost("/DataSync/SyncVesselDateExcept"), ApiUser(ApiCode = "SyncVesselDateExcept")]
public async Task SyncVesselDateExcept(List<DjyVesselExceptDto> dto)
{
if (dto != null)
{
string msg = string.Empty;
dto = dto.Distinct().ToList();
foreach (var item in dto)
{
2 years ago
msg += $"船名:{item.Vessel} 航次:{item.Voyno} 异常信息: {item.Message}";
2 years ago
msg += "\r\n";
}
//推送钉钉消息
2 years ago
DingTalkGroupHelper.SendDingTalkGroupMessage("hechuanVesselExcepNotify", "船期获取异常提醒", msg);
2 years ago
//推送和川钉钉群,@具体操作
SyncVesselExcepAtOp(dto);
}
}
//[HttpPost("/DataSync/SyncVesselDateTest"), ApiUser(ApiCode = "SaveSyncVesselDate")]
//public async Task SyncVesselDateTest(List<DjyVesselExceptDto> dto)
private async Task SyncVesselExcepAtOp(List<DjyVesselExceptDto> dto)
{
var tenantId = UserManager.TENANT_ID;
2 years ago
SpareTime.DoOnce(60000, (tmr, l) =>
{
try
{
_logger.LogInformation($"SaveSyncVesselDate @通知执行");
int maxSendLimit = 20; //钉钉每分钟发送限制
var usrList = _repUser.AsQueryable().Filter(null, true).Where(u => u.TenantId == tenantId && !u.IsDeleted).ToList();
Dictionary<string, List<string>> dic = new Dictionary<string, List<string>>();
//遍历船名航次,查询船期维护人
foreach (var item in dto)
{
var veUserList = _vesselinfo.AsQueryable().Filter(null, true)
.Where(v => v.TenantId == tenantId && v.Vessel == item.Vessel && v.Voyno == item.Voyno && !v.IsDeleted)
.Select(x => x.CreatedUserId)
.ToList();
if (veUserList.Count > 0)
{
var phoneList = usrList.Where(u => veUserList.Contains(u.Id) && u.Phone != "" && u.Phone != null).Select(x => x.Phone).ToList();
foreach (var phone in phoneList)
{
var msg = $"船名:{item.Vessel},航次:{item.Voyno}{item.Message}";
if (dic.ContainsKey(phone))
{
dic[phone].Add(msg);
}
else
{
dic.Add(phone, new List<string>(new string[] { msg }));
}
}
}
}
_logger.LogInformation($"处理发送后,准备给{dic.Count}个用户发送通知");
if (dic.Count > maxSendLimit) //大于限制,分多次发送
{
int times = (int)Math.Ceiling(dic.Count * 1.0 / maxSendLimit);
_logger.LogInformation($"发送通知超限,准备分为{times}次发送");
for (var t = 0; t < times; t++)
{
var keyList = dic.Keys.Skip(t * maxSendLimit).Take(maxSendLimit);
var currTimes = t + 1;
SpareTime.DoOnce(t == 0 ? 1000 : 70 * 1000 * t, doWhat: (st, val) =>
{
_logger.LogInformation($"超限第{currTimes}次发送,共{keyList.Count()}个");
foreach (var k in keyList)
{
var content = string.Join("\r\n", dic[k]);
_logger.LogInformation($"准备发送船期通知给 {k},内容:\r\n{content}");
2 years ago
DingTalkGroupHelper.SendDingTalkGroupMessage("hechuanVesselAtOpNotify", "船期提醒", content, false, new string[] { k }, null);
}
});
}
}
else
{
foreach (var item in dic)
{
var content = string.Join("\r\n", item.Value);
_logger.LogInformation($"准备发送船期通知给 {item.Key},内容:\r\n{content}");
2 years ago
DingTalkGroupHelper.SendDingTalkGroupMessage("hechuanVesselAtOpNotify", "船期提醒", content, false, new string[] { item.Key }, null);
}
}
}
catch (Exception ex)
{
var excep = ex;
while (excep != null)
{
_logger.LogError(excep.Message);
_logger.LogError(excep.StackTrace);
excep = excep.InnerException;
}
}
});
}
/// <summary>
/// 插入货运动态
/// </summary>
[SqlSugarUnitOfWork]
[HttpPost("/DataSync/AddBookingStatusLog"), ApiUser(ApiCode = "AddBookingStatusLog")]
public async Task AddBookingStatusLog(List<BookingStatusLogDto> all)
{
try
{
var old = await _repStatuslog.AsQueryable().Filter(null, true).Where(x => x.BookingId == all[0].BookingId && x.Category == "yunzong" && x.IsDeleted == false).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;
var list = await _repBookingStatus.AsQueryable().Filter(null, true).InnerJoin<SysDictData>((d, t) => d.StaCode == t.Code && d.StaCate == "book_sta_cate_billtrace" && d.BookingId == all[0].BookingId).Select((d, t) => new
{
BookingId = d.BookingId,
StaCode = d.StaCode,
StaName = d.StaName,
StaTime = d.StaTime,
Code = t.Code,
Value = t.Value
}).ToListAsync();
1 year ago
bool flag = false;
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);
1 year ago
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);
}
1 year ago
1 year ago
}
if (item.Status == "提箱")
{
await _bookingorderservice.AutoYardData(item.BookingId);
}
#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);
await _bookingorderservice.SetGoodsStatus("BG", item.BookingId);
1 year ago
flag = true;
}
}
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);
await _bookingorderservice.SetGoodsStatus("ZZFX", item.BookingId);
1 year ago
flag = true;
}
}
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);
await _bookingorderservice.SetGoodsStatus("MTFX", item.BookingId);
1 year ago
flag = true;
}
}
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);
}
}
if (item.Status == "MDGETA")
{
if (list.Where(x => x.Code == "sta_mdgeta").FirstOrDefault() == null)
{
BookingStatus bookingStatus = new BookingStatus();
bookingStatus.BookingId = item.BookingId;
bookingStatus.StaCode = "sta_atd";
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_mdgeta").Select(x => x.Value).FirstOrDefault();
bookingStatus.StaTime = item.OpTime;
bookingStatus.StaCate = "book_sta_cate_billtrace";
await _repBookingStatus.InsertAsync(bookingStatus);
1 year ago
}
}
if (item.Status == "MDGATA")
{
if (list.Where(x => x.Code == "sta_mdgeta").FirstOrDefault() == null)
{
BookingStatus bookingStatus = new BookingStatus();
bookingStatus.BookingId = item.BookingId;
bookingStatus.StaCode = "sta_mdgata";
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_mdgata").Select(x => x.Value).FirstOrDefault();
bookingStatus.StaTime = item.OpTime;
bookingStatus.StaCate = "book_sta_cate_billtrace";
await _repBookingStatus.InsertAsync(bookingStatus);
}
}
#region 入港时间
if (item.Status == "入港")
{
1 year ago
if (list.Where(x => x.Code == "sta_rugang").FirstOrDefault() == null)
{
BookingStatus bookingStatus = new BookingStatus();
bookingStatus.BookingId = item.BookingId;
bookingStatus.StaCode = "sta_rugang";
bookingStatus.StaName = dicdatalist.Where(x => x.Code == "sta_rugang").Select(x => x.Value).FirstOrDefault();
bookingStatus.StaTime = item.OpTime;
bookingStatus.StaCate = "book_sta_cate_billtrace";
await _repBookingStatus.InsertAsync(bookingStatus);
await _bookingorderservice.SetGoodsStatus("YRG", item.BookingId);
flag = true;
}
}
#endregion
#endregion
#region ATD MDGETA MDGATA
if (item.Status == "ATD")
{
var o = _rep.AsQueryable().Filter(null, true).Where(x => x.Id == all[0].BookingId && x.IsDeleted == false).First();
var oldorder = o;
var oldatd = o == null ? null : o.ATD;
if (oldatd != item.OpTime && item.OpTime != null)
{
o.ATD = item.OpTime;
await _rep.UpdateAsync(o);
1 year ago
flag = true;
await _bookingorderservice.SaveLog(o, oldorder);
}
if (!string.IsNullOrEmpty(o.VESSEL) && !string.IsNullOrEmpty(o.VOYNO) && !string.IsNullOrEmpty(o.CARRIERID))
{
var order = await _rep.AsQueryable().Filter(null, true).Where(x => x.VOYNO == o.VOYNO && x.VESSEL == o.VESSEL && x.CARRIERID == o.CARRIERID && x.TenantId == o.TenantId && x.IsDeleted == false && x.Id != item.BookingId).ToListAsync();
foreach (var it in order)
{
var _oldorder = it;
var _oldatd = it.ATD;
if (_oldatd != item.OpTime)
{
it.ATD = item.OpTime;
await _rep.UpdateAsync(it);
await _bookingorderservice.SaveLog(it, _oldorder);
1 year ago
await _bookingorderservice.SendBookingOrder(new long[] { it.Id });
}
}
}
}
if (item.Status == "MDGETA")
{
var o = _rep.AsQueryable().Filter(null, true).Where(x => x.Id == all[0].BookingId && x.IsDeleted == false).First();
var oldorder = o;
var oldeta = o == null ? null : o.ETA;
if (oldeta != item.OpTime && item.OpTime != null)
{
o.ETA = item.OpTime;
await _rep.UpdateAsync(o);
1 year ago
flag = true;
await _bookingorderservice.SaveLog(o, oldorder);
}
if (!string.IsNullOrEmpty(o.VESSEL) && !string.IsNullOrEmpty(o.VOYNO) && !string.IsNullOrEmpty(o.CARRIERID))
{
var order = await _rep.AsQueryable().Filter(null, true).Where(x => x.VOYNO == o.VOYNO && x.VESSEL == o.VESSEL && x.CARRIERID == o.CARRIERID && x.TenantId == o.TenantId && x.IsDeleted == false && x.Id != item.BookingId).ToListAsync();
foreach (var it in order)
{
var _oldorder = it;
var _oldatd = it.ETA;
if (_oldatd != item.OpTime)
{
it.ETA = item.OpTime;
await _rep.UpdateAsync(it);
1 year ago
await _bookingorderservice.SendBookingOrder(new long[] { it.Id });
await _bookingorderservice.SaveLog(it, _oldorder);
}
}
}
}
if (item.Status == "MDGATA")
{
var o = _rep.AsQueryable().Filter(null, true).Where(x => x.Id == all[0].BookingId && x.IsDeleted == false).First();
var oldorder = o;
var oldata = o == null ? null : o.ATA;
if (oldata != item.OpTime && item.OpTime != null)
{
o.ATA = item.OpTime;
await _rep.UpdateAsync(o);
1 year ago
flag = true;
await _bookingorderservice.SaveLog(o, oldorder);
}
if (!string.IsNullOrEmpty(o.VESSEL) && !string.IsNullOrEmpty(o.VOYNO) && !string.IsNullOrEmpty(o.CARRIERID))
{
var order = await _rep.AsQueryable().Filter(null, true).Where(x => x.VOYNO == o.VOYNO && x.VESSEL == o.VESSEL && x.CARRIERID == o.CARRIERID && x.TenantId == o.TenantId && x.IsDeleted == false && x.Id != item.BookingId).ToListAsync();
foreach (var it in order)
{
var _oldorder = it;
var _oldatd = it.ATA;
if (_oldatd != item.OpTime)
{
it.ATA = item.OpTime;
await _rep.UpdateAsync(it);
await _bookingorderservice.SendBookingOrder(new long[] { it.Id });
await _bookingorderservice.SaveLog(it, _oldorder);
}
}
}
}
1 year ago
#endregion
1 year ago
}
if (flag)
{
1 year ago
await _bookingorderservice.SendBookingOrder(new long[] { all[0].BookingId });
}
}
catch (Exception ex)
{
_logger.LogError(ex.Message);
_logger.LogError(ex.StackTrace);
}
}
#endregion
#region 下载数据
2 years ago
/// <summary>
/// 爬虫获取船名航次
/// </summary>
/// <returns></returns>
[HttpGet("/DataSync/GetSyncVesselDate"), ApiUser(ApiCode = "GetSyncVesselDate")]
public async Task<dynamic> GetSyncVesselDate()
{
var list = await _vesselinfo.AsQueryable().Filter(null, true)
.Where(x => x.Sign == false && x.ATD == null
&& x.IsDeleted == false
&& x.TenantId == UserManager.TENANT_ID
&& (x.Voyno != null && x.Voyno != "")
&& x.ETD < DateTime.Today.AddDays(15)) //2023年7月19日根据吴悦蓉反馈查询3周左右的即可再远的无效而且也会产生无效提醒2023年7月25日改为2周
.Select(x => new
{
Vessel = x.Vessel,
Voyno = x.Voyno,
CARRIER = x.CARRIER,
CARRIERID = x.CARRIERID
}).Distinct().ToListAsync();
2 years ago
2 years ago
return list;
}
2 years ago
#endregion
2 years ago
#region 其他
2 years ago
2 years ago
#endregion
#region 自动化接口
/// <summary>
/// 获取订舱数据
/// </summary>
/// <returns></returns>
[HttpGet("/DataSync/GetBookingOrder"), ApiUser(ApiCode = "GetBookingOrder")]
public async Task<dynamic> GetBookingOrder(QueryBookingOrder query)
{
if (query == null)
{
throw Oops.Bah("未录入正确查询条件");
}
if (string.IsNullOrEmpty(query.MBLNO) && string.IsNullOrEmpty(query.TMBLNO) && string.IsNullOrEmpty(query.BOOKINGNO))
{
return null;
}
var list = await _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false).
WhereIF(!string.IsNullOrEmpty(query.MBLNO), x => x.MBLNO == query.MBLNO).
WhereIF(!string.IsNullOrEmpty(query.TMBLNO), x => x.TMBLNO == query.TMBLNO).
WhereIF(!string.IsNullOrEmpty(query.BOOKINGNO), x => x.BOOKINGNO == query.BOOKINGNO).ToListAsync();
return list;
}
/// <summary>
/// 更新订舱
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[SqlSugarUnitOfWork]
[HttpPost("/DataSync/SaveBookingOrder"), ApiUser(ApiCode = "SaveBookingOrder")]
public async Task SaveBookingOrder(UpdateBookingOrder input)
{
if (input == null)
{
throw Oops.Bah("未录入数据");
}
if (string.IsNullOrEmpty(input.MBLNO) && string.IsNullOrEmpty(input.TMBLNO) && string.IsNullOrEmpty(input.BOOKINGNO) && input.Id == 0)
{
throw Oops.Bah("未录入正确数据");
}
var order = await _rep.AsQueryable().Filter(null, true).Where(x => x.Id == input.Id).FirstAsync();
var old = order;
order.MBLNO = input.MBLNO;
order.TMBLNO = input.TMBLNO;
order.BOOKINGNO = input.BOOKINGNO;
2 years ago
order.UpdatedUserId = order.CreatedUserId;
order.UpdatedUserName = order.CreatedUserName;
order.UpdatedTime = DateTime.Now;
await _rep.AsUpdateable(order).IgnoreColumns(it => new
{
it.ParentId,
it.TenantId,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName,
it.TenantName,
it.IsDeleted,
}).ExecuteCommandAsync();
await _bookingorderservice.SaveLog(order, old);
}
2 years ago
/// <summary>
/// 获取接口Key 个人或公司
/// </summary>
/// <param name="TypeCode"></param>
/// <param name="UserId"></param>
/// <returns></returns>
[HttpGet("/DataSync/GetAccountConfig"), ApiUser(ApiCode = "GetAccountConfig")]
public async Task<DjyWebsiteAccountConfig> GetAccountConfig(string TypeCode, long UserId)
{
if (string.IsNullOrWhiteSpace(TypeCode))
{
throw Oops.Bah("请传入正确参数!");
}
DjyWebsiteAccountConfig accountConfig = new DjyWebsiteAccountConfig();
if (UserId == 0)
{
accountConfig = await _accountconfig.AsQueryable().InnerJoin<SysUser>((d, t) => d.TenantId == t.TenantId).Where((d, t) => d.TypeCode == TypeCode && t.TenantId == UserManager.TENANT_ID && d.IsTenant == true).FirstAsync();
}
2 years ago
else
{
2 years ago
accountConfig = await _accountconfig.FirstOrDefaultAsync(x => x.TypeCode == TypeCode && x.CreatedUserId == UserId);
}
return accountConfig;
}
/// <summary>
/// 获取租户参数
/// </summary>
/// <returns></returns>
[HttpGet("/DataSync/GetParamValue"), ApiUser(ApiCode = "GetParamValue")]
2 years ago
public dynamic GetParamValue()
2 years ago
{
2 years ago
var list = _cache.GetAllTenantParam().Result.Where(x => x.TenantId == UserManager.TENANT_ID).OrderBy(x => x.Sort).ToList();
2 years ago
return list;
}
2 years ago
/// <summary>
/// 挂载订舱文件
/// </summary>
/// <param name="file"></param>
/// <param name="dto"></param>
/// <returns></returns>
[HttpPost("/DataSync/AddFile"), ApiUser(ApiCode = "AddFile")]
public async Task AddFile(IFormFile file, [FromForm] BookingFileDto dto)
{
//未上传文件
if (file == null || file.Length == 0)
{
throw Oops.Bah(BookingErrorCode.BOOK200);
}
2 years ago
2 years ago
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);
}
2 years ago
2 years ago
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);
}
}
2 years ago
#endregion
}
}