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.

2237 lines
119 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;
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
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<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)
{
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;
}
#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)
{
2 years ago
if (string.IsNullOrWhiteSpace(model.ShortName))
{
2 years ago
throw Oops.Bah("简称未录入");
2 years ago
}
2 years ago
var m = await _djycustomer.AsQueryable().Filter(null, true).Where(x => x.ShortName == model.ShortName && x.IsDeleted == false).FirstAsync();
2 years ago
var entity = model.Adapt<DjyCustomer>();
if (m == null)
{
await _djycustomer.InsertAsync(entity);
foreach (var item in model.ContactList)
{
var contact = item.Adapt<DjyCustomerContact>();
contact.CustomerId = entity.Id;
await _djycustomercontact.InsertAsync(contact);
}
2 years ago
}
else
{
entity.Id = m.Id;
2 years ago
await _djycustomer.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
await _djycustomercontact.DeleteAsync(x => x.CustomerId == entity.Id);
foreach (var item in model.ContactList)
{
var contact = item.Adapt<DjyCustomerContact>();
contact.CustomerId = entity.Id;
await _djycustomercontact.InsertAsync(contact);
}
}
return entity.Id;
}
2 years ago
2 years ago
/// <summary>
/// 批量同步客户无返回值
/// </summary>
/// <param name="model">参数</param>
/// <returns></returns>
[HttpPost("/DataSync/SyncCustomerList"), ApiUser(ApiCode = "SyncCustomerList")]
public async Task SyncCustomer(List<DjyCustomerSyncDto> model)
{
foreach (var item in model)
{
if (string.IsNullOrWhiteSpace(item.ShortName))
{
throw Oops.Bah("简称未录入");
}
var m = await _djycustomer.AsQueryable().Filter(null, true).Where(x => x.ShortName == item.ShortName && x.IsDeleted == false).FirstAsync();
2 years ago
var entity = item.Adapt<DjyCustomer>();
2 years ago
if (m == null)
{
await _djycustomer.InsertAsync(entity);
foreach (var it in item.ContactList)
{
var contact = it.Adapt<DjyCustomerContact>();
contact.CustomerId = entity.Id;
await _djycustomercontact.InsertAsync(contact);
}
}
else
{
entity.Id = m.Id;
await _djycustomer.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
await _djycustomercontact.DeleteAsync(x => x.CustomerId == entity.Id);
foreach (var it in item.ContactList)
{
var contact = it.Adapt<DjyCustomerContact>();
contact.CustomerId = entity.Id;
await _djycustomercontact.InsertAsync(contact);
}
}
}
}
2 years ago
/// <summary>
/// 同步船期
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost("/DataSync/SyncVesselDate"), ApiUser(ApiCode = "SyncVesselDate")]
2 years ago
[SqlSugarUnitOfWork]
public async Task<long> SyncVesselDate(DjyVesselInfoDto model)
2 years ago
{
2 years ago
if (string.IsNullOrWhiteSpace(model.BSNO))
2 years ago
{
2 years ago
throw Oops.Bah("BSNO未录入");
2 years ago
}
2 years ago
var userlist = _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false).ToListAsync();
2 years ago
var m = await _vesselinfo.AsQueryable().Filter(null, true).Where(x => x.BSNO == model.BSNO).FirstAsync();
2 years ago
var entity = model.Adapt<DjyVesselInfo>();
entity.Vessel = model.Vessel.ToUpper().Trim();
2 years ago
if (!string.IsNullOrEmpty(model.CARRIER))
{
2 years ago
entity.CARRIERID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == entity.CARRIER).Select(x => x.Code).FirstOrDefault();
2 years ago
}
if (!string.IsNullOrEmpty(model.CreatedUserName))
{
entity.CreatedUserId = userlist.Result.Where(x => x.Name == model.CreatedUserName).Select(x => x.Id).FirstOrDefault();
2 years ago
}
2 years ago
if (m == null)
{
await _vesselinfo.InsertAsync(entity);
}
else
{
entity.Id = m.Id;
await _vesselinfo.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
2 years ago
////根据船公司船名航次更新船期信息
if (!string.IsNullOrEmpty(model.CARRIER) && !string.IsNullOrEmpty(model.Vessel) && (!string.IsNullOrEmpty(model.Voyno) || !string.IsNullOrWhiteSpace(model.VoynoInside)))
{
2 years ago
var order = await _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.CARRIERID == model.CARRIERID && x.VESSEL == model.Vessel && x.IsDeleted == false)
2 years ago
.WhereIF(!string.IsNullOrEmpty(model.Voyno), x => x.VOYNO == model.Voyno)
.WhereIF(!string.IsNullOrEmpty(model.VoynoInside), x => x.VOYNOINNER == model.VoynoInside).ToListAsync();
_logger.LogInformation($"同步船期_查询到{UserManager.TENANT_NAME}需要更新{order.Count()}条订舱数据");
foreach (var item in order)
{
//更新订舱船期
if (item.ETD != model.ETD)
{
item.ETD = model.ETD;
}
if (item.ATD != model.ATD)
{
item.ATD = model.ATD;
}
await _rep.AsUpdateable(item).IgnoreColumns(it => new
{
it.ParentId,
it.TenantId,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName,
it.TenantName,
it.IsDeleted,
it.BOOKINGNO
}).ExecuteCommandAsync();
//记录日志
////添加booking日志
var bid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog
{
Type = "Edit",
BookingId = item.Id,
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
CreatedTime = DateTime.Now,
CreatedUserId = UserManager.UserId,
CreatedUserName = UserManager.Name
});
if (item.ETD != model.ETD)
{
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
{
PId = bid,
Field = "ETD",
OldValue = item.ETD != null ? item.ETD.ToSqlValue() : null,
NewValue = model.ETD != null ? model.ETD.ToSqlValue() : null,
});
}
if (item.ATD != model.ATD)
{
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
{
PId = bid,
Field = "ATD",
OldValue = item.ATD != null ? item.ATD.ToSqlValue() : null,
NewValue = model.ATD != null ? model.ATD.ToSqlValue() : null,
});
}
}
}
2 years ago
return entity.Id;
}
2 years ago
2 years ago
/// <summary>
/// 批量同步船期无返回值
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost("/DataSync/SyncVesselDateList"), ApiUser(ApiCode = "SyncVesselDateList")]
[SqlSugarUnitOfWork]
public async Task SyncVesselDateList(List<DjyVesselInfoDto> model)
{
foreach (var item in model)
{
if (string.IsNullOrWhiteSpace(item.BSNO))
{
throw Oops.Bah("BSNO未录入");
}
var userlist = _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false).ToListAsync();
var m = await _vesselinfo.AsQueryable().Filter(null, true).Where(x => x.BSNO == item.BSNO).FirstAsync();
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
}
if (!string.IsNullOrEmpty(item.CreatedUserName))
{
entity.CreatedUserId = userlist.Result.Where(x => x.Name == item.CreatedUserName).Select(x => x.Id).FirstOrDefault();
}
if (m == null)
{
await _vesselinfo.InsertAsync(entity);
}
else
{
entity.Id = m.Id;
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 = await _rep.AsQueryable().Filter(null, true).Where(x => x.TenantId == UserManager.TENANT_ID && x.CARRIERID == item.CARRIERID && x.VESSEL == item.Vessel && x.IsDeleted == false)
.WhereIF(!string.IsNullOrEmpty(item.Voyno), x => x.VOYNO == item.Voyno)
.WhereIF(!string.IsNullOrEmpty(item.VoynoInside), x => x.VOYNOINNER == item.VoynoInside).ToListAsync();
_logger.LogInformation($"同步船期_查询到{UserManager.TENANT_NAME}需要更新{order.Count()}条订舱数据");
foreach (var it in order)
{
//更新订舱船期
if (it.ETD != item.ETD)
{
it.ETD = item.ETD;
}
if (it.ATD != item.ATD)
{
it.ATD = item.ATD;
}
await _rep.AsUpdateable(it).IgnoreColumns(it => new
{
it.ParentId,
it.TenantId,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName,
it.TenantName,
it.IsDeleted,
it.BOOKINGNO
}).ExecuteCommandAsync();
//记录日志
////添加booking日志
var bid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog
{
Type = "Edit",
BookingId = it.Id,
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
CreatedTime = DateTime.Now,
CreatedUserId = UserManager.UserId,
CreatedUserName = UserManager.Name
});
if (it.ETD != item.ETD)
{
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
{
PId = bid,
Field = "ETD",
OldValue = it.ETD != null ? it.ETD.ToSqlValue() : null,
NewValue = item.ETD != null ? item.ETD.ToSqlValue() : null,
});
}
if (it.ATD != item.ATD)
{
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
{
PId = bid,
Field = "ATD",
OldValue = it.ATD != null ? it.ATD.ToSqlValue() : null,
NewValue = item.ATD != null ? item.ATD.ToSqlValue() : null,
});
}
}
}
}
}
2 years ago
#region
///// <summary>
///// 同步订舱
///// </summary>
///// <param name="model"></param>
///// <returns></returns>
//[SqlSugarUnitOfWork]
//[HttpPost("/DataSync/SyncBooking"), ApiUser(ApiCode = "SyncBooking")]
//public async Task<long> SyncBooking(SyncBookingOrderDto model)
//{
// if (string.IsNullOrWhiteSpace(model.BSNO))
// {
// throw Oops.Bah("主单BSNO未录入");
// }
// if (string.IsNullOrWhiteSpace(model.CreatedUserName))
// {
// throw Oops.Bah("未录入创建人");
// }
// var userlist = _repUser.AsQueryable().Filter(null, true).ToListAsync();
// var djycustomer = _djycustomer.AsQueryable().Filter(null, true).ToListAsync();
// var user = _repUser.AsQueryable().Filter(null, true).Where(x => x.Name == model.CreatedUserName.Trim()).FirstAsync();
// if (user.Result == null)
// {
// throw Oops.Bah($"未匹配到创建人 {model.CreatedUserName.Trim()} 请联系管理员添加相关用户");
// }
// var order = await _rep.AsQueryable().Filter(null, true).Where(x => x.BSNO == model.BSNO).FirstAsync();
// List<CodeCtn> ctncode = await _cache.GetAllCodeCtn();
// if (order == null)
// {
// #region 新增
// if (string.IsNullOrWhiteSpace(model.MBLNO))
// {
// throw Oops.Bah("请填写提单号!");
// }
// JsonUtil.PropToUpper(model, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
// 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.Result.Where(x => x.Name == entity.ROUTE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.ROUTE).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(entity.SALE))
// {
// entity.SALEID = userlist.Result.Where(x => x.Name == entity.SALE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(entity.OP))
// {
// entity.OPID = userlist.Result.Where(x => x.Name == entity.OP).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.OP).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(entity.DOC))
// {
// entity.DOCID = userlist.Result.Where(x => x.Name == entity.DOC).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(entity.CUSTSERVICE))
// {
// entity.CUSTSERVICEID = userlist.Result.Where(x => x.Name == entity.CUSTSERVICE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(entity.CUSTOMSER))
// {
// entity.CUSTOMSERID = djycustomer.Result.Where(x => x.ShortName == entity.CUSTOMSER && x.PropString == "customs_broker").Select(x => x.CodeName).FirstOrDefault();
// }
// if (!string.IsNullOrEmpty(entity.TRUCKER))
// {
// entity.TRUCKERID = djycustomer.Result.Where(x => x.ShortName == entity.TRUCKER && x.PropString == "fleet").Select(x => x.CodeName).FirstOrDefault();
// }
// if (!string.IsNullOrEmpty(entity.CUSTOMERNAME))
// {
// entity.CUSTOMERID = djycustomer.Result.Where(x => x.ShortName == entity.CUSTOMERNAME && x.PropString == "consignor").Select(x => x.Id).FirstOrDefault();
// }
// if (!string.IsNullOrEmpty(entity.FORWARDER))
// {
// entity.FORWARDERID = djycustomer.Result.Where(x => x.ShortName == entity.FORWARDER && x.PropString == "booking_agent").Select(x => x.CodeName).FirstOrDefault();
// }
// if (!string.IsNullOrEmpty(entity.CARRIER))
// {
// entity.CARRIERID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == entity.CARRIER).Select(x => x.Code).FirstOrDefault();
// }
// entity.CreatedUserId = user.Result.Id;
// entity.CreatedUserName = user.Result.Name.ToString();
// entity.CreatedTime = DateTime.Now;
// 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.Result.Id;
// ctnentity.CreatedUserName = user.Result.Name;
// ctnentity.CTNCODE = ctncode.Where(x => x.Name == ctnentity.CTNALL).Select(x => x.Code).FirstOrDefault();
// 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.Result.Id;
// ctndetail.CreatedUserName = user.Result.Name;
// await _ctndetailrep.InsertAsync(ctndetail);
// }
// }
// }
// }
// if (model.BookingEDIExt != null)
// {
// //写入EDI扩展
// var ediExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
// ediExtEntity.BookingId = entity.Id;
// ediExtEntity.CreatedUserId = user.Result.Id;
// ediExtEntity.CreatedUserName = user.Result.Name;
// ediExtEntity.CreatedTime = DateTime.Now;
// ediExtEntity.CreatedUserId = user.Result.Id;
// ediExtEntity.CreatedUserName = user.Result.Name;
// 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.Result.Id,
// CreatedUserName = "系统"
// });
// //分单
// if (model.childrens != null)
// {
// foreach (var item in model.childrens)
// {
// JsonUtil.PropToUpper(item, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
// if (string.IsNullOrWhiteSpace(item.HBLNO))
// {
// throw Oops.Bah("请填写分提单号!");
// }
// 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.Result.Where(x => x.Name == fdentity.ROUTE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == fdentity.ROUTE).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(fdentity.SALE))
// {
// fdentity.SALEID = userlist.Result.Where(x => x.Name == fdentity.SALE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == fdentity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(fdentity.OP))
// {
// fdentity.OPID = userlist.Result.Where(x => x.Name == fdentity.OP).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == fdentity.OP).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(fdentity.DOC))
// {
// fdentity.DOCID = userlist.Result.Where(x => x.Name == fdentity.DOC).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == fdentity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(fdentity.CUSTSERVICE))
// {
// fdentity.CUSTSERVICEID = userlist.Result.Where(x => x.Name == fdentity.CUSTSERVICE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == fdentity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(fdentity.CUSTOMSER))
// {
// fdentity.CUSTOMSERID = djycustomer.Result.Where(x => x.ShortName == fdentity.CUSTOMSER && x.PropString == "customs_broker").Select(x => x.CodeName).FirstOrDefault();
// }
// if (!string.IsNullOrEmpty(fdentity.TRUCKER))
// {
// fdentity.TRUCKERID = djycustomer.Result.Where(x => x.ShortName == fdentity.TRUCKER && x.PropString == "fleet").Select(x => x.CodeName).FirstOrDefault();
// }
// if (!string.IsNullOrEmpty(fdentity.CUSTOMERNAME))
// {
// fdentity.CUSTOMERID = djycustomer.Result.Where(x => x.ShortName == fdentity.CUSTOMERNAME && x.PropString == "consignor").Select(x => x.Id).FirstOrDefault();
// }
// if (!string.IsNullOrEmpty(fdentity.FORWARDER))
// {
// fdentity.FORWARDERID = djycustomer.Result.Where(x => x.ShortName == fdentity.FORWARDER && x.PropString == "booking_agent").Select(x => x.CodeName).FirstOrDefault();
// }
// if (!string.IsNullOrEmpty(entity.CARRIER))
// {
// fdentity.CARRIERID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == entity.CARRIER).Select(x => x.Code).FirstOrDefault();
// }
// fdentity.MBLNO = entity.MBLNO;
// fdentity.CreatedUserId = user.Result.Id;
// fdentity.CreatedUserName = user.Result.Name;
// 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.Result.Id;
// ctnentity.CreatedUserName = user.Result.Name;
// ctnentity.CTNCODE = ctncode.Where(x => x.Name == ctnentity.CTNALL).Select(x => x.Code).FirstOrDefault();
// 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.Result.Id;
// ctndetail.CreatedUserName = user.Result.Name;
// await _ctndetailrep.InsertAsync(ctndetail);
// }
// }
// }
// }
// if (item.BookingEDIExt != null)
// {
// //写入EDI扩展
// var ediExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
// ediExtEntity.BookingId = fdentity.Id;
// ediExtEntity.CreatedUserId = user.Result.Id;
// ediExtEntity.CreatedUserName = user.Result.Name;
// 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.Result.Id,
// CreatedUserName = "系统"
// });
// }
// }
// return entity.Id;
// #endregion
// }
// else
// {
// #region 编辑
// if (string.IsNullOrWhiteSpace(model.MBLNO))
// {
// throw Oops.Bah("请填写提单号!");
// }
// JsonUtil.PropToUpper(model, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
// 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 main = await _rep.AsQueryable().Filter(null, true).Where(x => x.BSNO == model.BSNO).FirstAsync();
// 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.Result.Name;
// entity.UpdatedUserId = user.Result.Id;
// entity.UpdatedTime = DateTime.Now;
// if (!string.IsNullOrEmpty(entity.ROUTE))
// {
// entity.ROUTEID = userlist.Result.Where(x => x.Name == entity.ROUTE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.ROUTE).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(entity.SALE))
// {
// entity.SALEID = userlist.Result.Where(x => x.Name == entity.SALE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(entity.OP))
// {
// entity.OPID = userlist.Result.Where(x => x.Name == entity.OP).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.OP).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(entity.DOC))
// {
// entity.DOCID = userlist.Result.Where(x => x.Name == entity.DOC).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(entity.CUSTSERVICE))
// {
// entity.CUSTSERVICEID = userlist.Result.Where(x => x.Name == entity.CUSTSERVICE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == entity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(entity.CUSTOMSER))
// {
// entity.CUSTOMSERID = djycustomer.Result.Where(x => x.ShortName == entity.CUSTOMSER && x.PropString == "customs_broker").Select(x => x.CodeName).FirstOrDefault();
// }
// if (!string.IsNullOrEmpty(entity.TRUCKER))
// {
// entity.TRUCKERID = djycustomer.Result.Where(x => x.ShortName == entity.TRUCKER && x.PropString == "fleet").Select(x => x.CodeName).FirstOrDefault();
// }
// if (!string.IsNullOrEmpty(entity.CUSTOMERNAME))
// {
// entity.CUSTOMERID = djycustomer.Result.Where(x => x.ShortName == entity.CUSTOMERNAME && x.PropString == "consignor").Select(x => x.Id).FirstOrDefault();
// }
// if (!string.IsNullOrEmpty(entity.FORWARDER))
// {
// entity.FORWARDERID = djycustomer.Result.Where(x => x.ShortName == entity.FORWARDER && x.PropString == "booking_agent").Select(x => x.CodeName).FirstOrDefault();
// }
// if (!string.IsNullOrEmpty(entity.CARRIER))
// {
// entity.CARRIERID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == entity.CARRIER).Select(x => x.Code).FirstOrDefault();
// }
// entity.IsDeleted = false;
// await _rep.AsUpdateable(entity).IgnoreColumns(it => new
// {
// it.ParentId,
// it.TenantId,
// it.CreatedTime,
// it.CreatedUserId,
// it.CreatedUserName
// }).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));
// if (model.ctnInputs != null)
// {
// foreach (var item in model.ctnInputs)
// {
// var ctnentity = item.Adapt<BookingCtn>();
// ctnentity.BILLID = main.Id;
// ctnentity.CreatedUserId = user.Result.Id;
// ctnentity.CreatedUserName = user.Result.Name;
// ctnentity.CTNCODE = ctncode.Where(x => x.Name == ctnentity.CTNALL).Select(x => x.Code).FirstOrDefault();
// 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.Result.Id;
// ctndetail.CreatedUserName = user.Result.Name;
// await _ctndetailrep.InsertAsync(ctndetail);
// }
// }
// }
// }
// if (model.BookingEDIExt != null)
// {
// //检索EDI扩展
// var ediExtEntity = _bookingEDIExt.FirstOrDefault(u => u.BookingId == main.Id);
// if (ediExtEntity == null)
// {
// //写入EDI扩展
// ediExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
// ediExtEntity.BookingId = main.Id;
// ediExtEntity.CreatedUserId = user.Result.Id;
// ediExtEntity.CreatedUserName = user.Result.Name;
// ediExtEntity.CreatedTime = DateTime.Now;
// await _bookingEDIExt.InsertAsync(ediExtEntity);
// }
// else
// {
// //更新EDI扩展
// var currEdiExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
// currEdiExtEntity.Id = ediExtEntity.Id;
// currEdiExtEntity.UpdatedUserId = user.Result.Id;
// currEdiExtEntity.UpdatedTime = DateTime.Now;
// await _bookingEDIExt.AsUpdateable(currEdiExtEntity).IgnoreColumns(it => new
// {
// it.BookingId,
// it.TenantId,
// it.CreatedTime,
// it.CreatedUserId,
// it.CreatedUserName
// }).ExecuteCommandAsync();
// }
// }
// bool flag = true;
// long bid = 0;
// foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(entity))
// {
// string name = descriptor.Name;
// if (name == "TenantId" || name == "CreatedTime" || name == "UpdatedTime" || name == "CreatedUserId" || name == "CreatedUserName")
// {
// continue;
// }
// object value = descriptor.GetValue(entity);
// var oldvalue = main.GetType().GetProperty(name).GetValue(main, null);
// if (name == "KGS" || name == "CBM")
// {
// if (Convert.ToDecimal(value) == Convert.ToDecimal(oldvalue))
// {
// continue;
// }
// }
// string _oldvalue = oldvalue != null ? oldvalue.ToString() : "";
// string _value = value != null ? value.ToString() : "";
// if (_oldvalue != _value && !string.IsNullOrWhiteSpace(descriptor.Description))
// {
// if (flag)
// {
// ////添加booking日志
// bid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog
// {
// Type = "Edit",
// BookingId = entity.Id,
// TenantId = Convert.ToInt64(UserManager.TENANT_ID),
// CreatedTime = DateTime.Now,
// CreatedUserId = user.Result.Id,
// CreatedUserName = user.Result.Name
// });
// 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)
// {
// if (string.IsNullOrWhiteSpace(item.HBLNO))
// {
// throw Oops.Bah("请填写分提单号!");
// }
// JsonUtil.PropToUpper(item, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
// 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 fdmain = await _rep.AsQueryable().Filter(null, true).Where(x => x.BSNO == item.BSNO).FirstAsync();
// 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}已存在,请勿重复录入!");
// }
// fdentity.MBLNO = entity.MBLNO;
// fdentity.Id = fdmain.Id;
// fdentity.UpdatedUserName = user.Result.Name;
// fdentity.UpdatedUserId = user.Result.Id;
// fdentity.UpdatedTime = DateTime.Now;
// if (!string.IsNullOrEmpty(fdentity.ROUTE))
// {
// fdentity.ROUTEID = userlist.Result.Where(x => x.Name == fdentity.ROUTE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == fdentity.ROUTE).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(fdentity.SALE))
// {
// fdentity.SALEID = userlist.Result.Where(x => x.Name == fdentity.SALE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == fdentity.SALE).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(fdentity.OP))
// {
// fdentity.OPID = userlist.Result.Where(x => x.Name == fdentity.OP).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == fdentity.OP).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(fdentity.DOC))
// {
// fdentity.DOCID = userlist.Result.Where(x => x.Name == fdentity.DOC).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == fdentity.DOC).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(fdentity.CUSTSERVICE))
// {
// fdentity.CUSTSERVICEID = userlist.Result.Where(x => x.Name == fdentity.CUSTSERVICE).Count() == 0 ? "" : userlist.Result.Where(x => x.Name == fdentity.CUSTSERVICE).Select(x => x.Id).FirstOrDefault().ToString();
// }
// if (!string.IsNullOrEmpty(fdentity.CUSTOMSER))
// {
// fdentity.CUSTOMSERID = djycustomer.Result.Where(x => x.ShortName == fdentity.CUSTOMSER && x.PropString == "customs_broker").Select(x => x.CodeName).FirstOrDefault();
// }
// if (!string.IsNullOrEmpty(fdentity.TRUCKER))
// {
// fdentity.TRUCKERID = djycustomer.Result.Where(x => x.ShortName == fdentity.TRUCKER && x.PropString == "fleet").Select(x => x.CodeName).FirstOrDefault();
// }
// if (!string.IsNullOrEmpty(fdentity.CUSTOMERNAME))
// {
// fdentity.CUSTOMERID = djycustomer.Result.Where(x => x.ShortName == fdentity.CUSTOMERNAME && x.PropString == "consignor").Select(x => x.Id).FirstOrDefault();
// }
// if (!string.IsNullOrEmpty(fdentity.FORWARDER))
// {
// fdentity.FORWARDERID = djycustomer.Result.Where(x => x.ShortName == fdentity.FORWARDER && x.PropString == "booking_agent").Select(x => x.CodeName).FirstOrDefault();
// }
// if (!string.IsNullOrEmpty(entity.CARRIER))
// {
// fdentity.CARRIER = entity.CARRIER;
// fdentity.CARRIERID = _cache.GetAllCodeCarrier().Result.Where(x => x.CnName == entity.CARRIER).Select(x => x.Code).FirstOrDefault();
// }
// await _rep.AsUpdateable(fdentity).IgnoreColumns(it => new
// {
// it.ParentId,
// it.TenantId,
// it.CreatedTime,
// it.CreatedUserId,
// it.CreatedUserName
// }).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.Result.Id;
// ctnentity.CreatedUserName = user.Result.Name;
// ctnentity.CTNCODE = ctncode.Where(x => x.Name == ctnentity.CTNALL).Select(x => x.Code).FirstOrDefault();
// 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.Result.Id;
// ctndetail.CreatedUserName = user.Result.Name;
// await _ctndetailrep.InsertAsync(ctndetail);
// }
// }
// }
// }
// if (item.BookingEDIExt != null)
// {
// //检索EDI扩展
// var ediExtEntity = _bookingEDIExt.FirstOrDefault(u => u.BookingId == fdmain.Id);
// if (ediExtEntity == null)
// {
// //写入EDI扩展
// ediExtEntity = item.BookingEDIExt.Adapt<BookingEDIExt>();
// ediExtEntity.BookingId = fdmain.Id;
// ediExtEntity.CreatedUserId = user.Result.Id;
// ediExtEntity.CreatedUserName = user.Result.Name;
// 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);
// 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.Result.Id,
// CreatedUserName = user.Result.Name,
// });
// fdflag = false;
// }
// await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
// {
// PId = fdbid,
// Field = descriptor.Description,
// OldValue = _oldvalue,
// NewValue = _value,
// });
// }
// }
// }
// else
// {
// fdentity.CreatedUserId = user.Result.Id;
// fdentity.CreatedUserName = user.Result.Name;
// 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.Result.Id;
// ctnentity.CreatedUserName = user.Result.Name;
// 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.Result.Id;
// ctndetail.CreatedUserName = user.Result.Name;
// await _ctndetailrep.InsertAsync(ctndetail);
// }
// }
// }
// }
// if (item.BookingEDIExt != null)
// {
// //检索EDI扩展
// var ediExtEntity = _bookingEDIExt.FirstOrDefault(u => u.BookingId == fdentity.Id);
// if (ediExtEntity == null)
// {
// //写入EDI扩展
// ediExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
// ediExtEntity.BookingId = fdentity.Id;
// ediExtEntity.CreatedUserId = user.Result.Id;
// ediExtEntity.CreatedUserName = user.Result.Name;
// ediExtEntity.CreatedTime = DateTime.Now;
// await _bookingEDIExt.InsertAsync(ediExtEntity);
// }
// else
// {
// //更新EDI扩展
// var currEdiExtEntity = model.BookingEDIExt.Adapt<BookingEDIExt>();
// currEdiExtEntity.Id = ediExtEntity.Id;
// currEdiExtEntity.UpdatedUserId = user.Result.Id;
// currEdiExtEntity.UpdatedTime = DateTime.Now;
// await _bookingEDIExt.AsUpdateable(currEdiExtEntity).IgnoreColumns(it => new
// {
// it.BookingId,
// it.TenantId,
// it.CreatedTime,
// it.CreatedUserId,
// it.CreatedUserName
// }).ExecuteCommandAsync();
// }
// }
// }
// }
// }
// return main.Id;
// #endregion
// }
//}
#endregion
2 years 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 userlist = await _repUser.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false).ToListAsync();
var djycustomer = await _djycustomer.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false).ToListAsync();
var goodsconfig = await _goodsStatusConfig.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false).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("未录入创建人");
}
2 years ago
var user = await _repUser.AsQueryable().Filter(null, true).Where(x => x.Name == model.CreatedUserName.Trim() && x.IsDeleted == false).FirstAsync();
if (user == null)
2 years ago
{
2 years ago
throw Oops.Bah($"未匹配到创建人{model.CreatedUserName.Trim()}请联系管理员添加相关用户");
2 years ago
}
2 years ago
var order = await _rep.AsQueryable().Filter(null, true).Where(x => x.BSNO == model.BSNO && x.IsDeleted == false).FirstAsync();
2 years ago
var lanename = model.LANECODE;
var linename = model.LANENAME;
2 years ago
if (order == null)
{
#region 新增
if (string.IsNullOrWhiteSpace(model.MBLNO))
{
throw Oops.Bah("请填写提单号!");
}
JsonUtil.PropToUpper(model, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
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.CARRIERID))
2 years ago
{
2 years ago
entity.CARRIER = _cache.GetAllCodeCarrier().Result.Where(x => x.Code == entity.CARRIERID).Select(x => x.CnName).FirstOrDefault();
2 years ago
}
2 years ago
if (!string.IsNullOrEmpty(linename))
2 years ago
{
2 years ago
var line = _repline.AsQueryable().Filter(null, true).Where(m => m.TenantId == UserManager.TENANT_ID && m.LineName.Contains(linename)).FirstAsync();
2 years ago
if (line == null)
{
await _repline.InsertAsync(new DjyTenantLine
{
2 years ago
LineName = linename,
LineCode ="",
2 years ago
TenantId = UserManager.TENANT_ID,
CreatedUserId = user.Id,
CreatedUserName = user.Name
});
}
}
2 years ago
entity.LANENAME = lanename;
entity.LineName = linename;
2 years ago
entity.CUSTNO = model.BOOKINGNO;
2 years ago
entity.VOYNOINNER = model.VOYNO;
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;
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
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扩展
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;
ediExtEntity.CreatedUserId = user.Id;
ediExtEntity.CreatedUserName = user.Name;
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
var fenlanename = item.LANECODE;
var fenlinename = item.LANENAME;
2 years ago
if (string.IsNullOrWhiteSpace(item.HBLNO))
{
throw Oops.Bah("请填写分提单号!");
}
JsonUtil.PropToUpper(item, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
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(fenlinename))
2 years ago
{
2 years ago
var line = _repline.AsQueryable().Filter(null, true).Where(m => m.TenantId == UserManager.TENANT_ID && m.LineName.Contains(fenlinename)).FirstAsync();
2 years ago
if (line == null)
{
await _repline.InsertAsync(new DjyTenantLine
{
2 years ago
LineName = fenlinename,
LineCode = "",
2 years ago
TenantId = UserManager.TENANT_ID,
CreatedUserId = user.Id,
CreatedUserName = user.Name
});
}
}
2 years ago
fdentity.CUSTNO = item.BOOKINGNO;
2 years ago
fdentity.VOYNOINNER = item.VOYNO;
2 years ago
fdentity.LANENAME = fenlanename;
fdentity.LineName = fenlinename;
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;
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
#endregion
}
else
{
#region 编辑
if (string.IsNullOrWhiteSpace(model.MBLNO))
{
throw Oops.Bah("请填写提单号!");
}
JsonUtil.PropToUpper(model, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
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.CARRIERID))
2 years ago
{
2 years ago
entity.CARRIER = _cache.GetAllCodeCarrier().Result.Where(x => x.Code == entity.CARRIERID).Select(x => x.CnName).FirstOrDefault();
2 years ago
}
2 years ago
2 years ago
if (!string.IsNullOrEmpty(linename))
2 years ago
{
2 years ago
var line = _repline.AsQueryable().Filter(null, true).Where(m => m.TenantId == UserManager.TENANT_ID && m.LineName.Contains(linename)).FirstAsync();
2 years ago
if (line == null)
{
await _repline.InsertAsync(new DjyTenantLine
{
2 years ago
LineName = linename,
LineCode = "",
2 years ago
TenantId = UserManager.TENANT_ID,
CreatedUserId = user.Id,
CreatedUserName = user.Name
});
}
}
2 years ago
entity.LANENAME = lanename;
entity.LineName = linename;
2 years ago
entity.CUSTNO = model.BOOKINGNO;
2 years ago
entity.VOYNOINNER = model.VOYNO;
2 years ago
await _rep.AsUpdateable(entity).IgnoreColumns(it => new
{
2 years ago
it.BOOKINGNO,
2 years ago
it.ParentId,
it.TenantId,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName
}).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扩展
var ediExtEntity = _bookingEDIExt.FirstOrDefault(u => u.BookingId == main.Id);
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
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
}
JsonUtil.PropToUpper(item, "ORDNO", "BSSTATUS", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME");
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.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(fenlinename))
2 years ago
{
2 years ago
var line = _repline.AsQueryable().Filter(null, true).Where(m => m.TenantId == UserManager.TENANT_ID && m.LineName.Contains(fenlinename)).FirstAsync();
2 years ago
if (line == null)
{
await _repline.InsertAsync(new DjyTenantLine
{
2 years ago
LineName = fenlinename,
LineCode = "",
2 years ago
TenantId = UserManager.TENANT_ID,
CreatedUserId = user.Id,
CreatedUserName = user.Name
});
}
}
2 years ago
fdentity.CUSTNO = item.BOOKINGNO;
2 years ago
fdentity.LANENAME = fenlanename;
fdentity.LineName = fenlinename;
2 years ago
fdentity.VOYNOINNER = item.VOYNO;
2 years ago
await _rep.AsUpdateable(fdentity).IgnoreColumns(it => new
{
2 years ago
it.BOOKINGNO,
2 years ago
it.ParentId,
it.TenantId,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName
}).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 = _bookingEDIExt.FirstOrDefault(u => u.BookingId == fdmain.Id);
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扩展
var ediExtEntity = _bookingEDIExt.FirstOrDefault(u => u.BookingId == fdentity.Id);
2 years ago
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
2 years ago
/// <summary>
/// 爬虫上传船期
/// </summary>
/// <returns></returns>
2 years ago
[HttpPost("/DataSync/SaveSyncVesselDate"), ApiUser(ApiCode = "SaveSyncVesselDate")]
2 years ago
[SqlSugarUnitOfWork]
public async Task SaveSyncVesselDate(List<DjyVesselDto> dto)
{
foreach (var item in dto)
{
var model = _vesselinfo.Where(x => x.Vessel == item.Vessel && x.Voyno == item.Voyno && x.CARRIERID == item.CARRIERID && x.TenantId == UserManager.TENANT_ID).First();
model.ETA = item.ETA;
model.ETD = item.ETD;
await _vesselinfo.AsUpdateable(model).IgnoreColumns().ExecuteCommandAsync();
var order = await _rep.AsQueryable().Where(x => x.VESSEL == item.Vessel && x.VOYNO == item.Voyno && x.CARRIERID == item.CARRIERID && x.TenantId == UserManager.TENANT_ID).ToListAsync();
if (order != null)
{
foreach (var it in order)
{
if (it.ETA != item.ETA)
{
////添加booking日志
var bid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog
{
Type = "Edit",
BookingId = it.Id,
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
CreatedTime = DateTime.Now,
CreatedUserId = UserManager.UserId,
CreatedUserName = UserManager.Name
});
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
{
PId = bid,
Field = "ETA",
OldValue = it.ETA == null ? "" : it.ETA.ToString(),
NewValue = item.ETA == null ? "" : item.ETA.ToString(),
});
it.ETA = item.ETA;
}
if (it.ETD != item.ETD)
{
////添加booking日志
var bid = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog
{
Type = "Edit",
BookingId = it.Id,
TenantId = Convert.ToInt64(UserManager.TENANT_ID),
CreatedTime = DateTime.Now,
CreatedUserId = UserManager.UserId,
CreatedUserName = UserManager.Name
});
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
{
PId = bid,
Field = "ETD",
OldValue = it.ETD == null ? "" : it.ETD.ToString(),
NewValue = item.ETD == null ? "" : item.ETD.ToString(),
});
it.ETD = item.ETD;
}
await _rep.AsUpdateable(it).IgnoreColumns().ExecuteCommandAsync();
}
}
}
}
#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().Where(x => x.ETD != null && x.ATD != null && x.TenantId == UserManager.TENANT_ID).Select(x => new DjyVesselDto
{
Vessel = x.Vessel,
Voyno = x.Voyno,
VoynoInside = x.VoynoInside,
CARRIER = x.CARRIER,
CARRIERID = x.CARRIERID,
ETD = null,
ETA = null
}).ToListAsync();
return list;
}
2 years ago
#endregion
2 years ago
#region 其他
2 years ago
2 years ago
2 years ago
#endregion
}
}