|
|
using Amazon.Runtime.Internal.Util;
|
|
|
using AngleSharp.Dom;
|
|
|
using DS.Module.Core;
|
|
|
using DS.Module.Core.Data;
|
|
|
using DS.Module.Core.Extensions;
|
|
|
using DS.Module.SqlSugar;
|
|
|
using DS.Module.UserModule;
|
|
|
using DS.WMS.Core.Code.Entity;
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
using DS.WMS.Core.Map.Entity;
|
|
|
using DS.WMS.Core.Op.Dtos;
|
|
|
using DS.WMS.Core.Op.EDI;
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
using DS.WMS.Core.Op.Interface;
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
using Mapster;
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
using SqlSugar;
|
|
|
using NLog;
|
|
|
using Logger = NLog.Logger;
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
using DS.Module.Core.Helpers;
|
|
|
|
|
|
namespace DS.WMS.Core.Op.Method
|
|
|
{
|
|
|
public class ShippingBillService : IShippingBillService
|
|
|
{
|
|
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
private readonly ISqlSugarClient db;
|
|
|
private readonly IUser user;
|
|
|
private readonly ISaasDbService saasService;
|
|
|
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
|
|
private readonly ISeaExportCommonService seaComService;
|
|
|
/// <summary>
|
|
|
///
|
|
|
/// </summary>
|
|
|
/// <param name="serviceProvider"></param>
|
|
|
public ShippingBillService(IServiceProvider serviceProvider)
|
|
|
{
|
|
|
_serviceProvider = serviceProvider;
|
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
|
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
|
|
|
seaComService = _serviceProvider.GetRequiredService<ISeaExportCommonService>();
|
|
|
#region 设置对象映射
|
|
|
TypeAdapterConfig<SeaExportShippingBill, MDATA>
|
|
|
.NewConfig()
|
|
|
.Map(dto => dto.MBLNO, poco => poco.MBLNO)
|
|
|
.Map(dto => dto.HBLNO, poco => poco.HBLNO)
|
|
|
.Map(dto => dto.ETD, poco => poco.ETD)
|
|
|
.Map(dto => dto.FORWARDER, poco => poco.Forwarder)
|
|
|
.Map(dto => dto.VESSEL, poco => poco.Vessel)
|
|
|
.Map(dto => dto.VOYNO, poco => poco.Voyno)
|
|
|
.Map(dto => dto.CARRIER, poco => poco.Carrier)
|
|
|
.Map(dto => dto.SHIPPERNAME, poco => poco.ShipperName)
|
|
|
.Map(dto => dto.SHIPPERADDR1, poco => poco.ShipperAddress)
|
|
|
.Map(dto => dto.SHIPPERCOUNTRY, poco => poco.ShipperCountry)
|
|
|
.Map(dto => dto.SHIPPERTEL, poco => poco.ShipperTel)
|
|
|
.Map(dto => dto.CONSIGNEENAME, poco => poco.ConsigneeName)
|
|
|
.Map(dto => dto.CONSIGNEEADDR1, poco => poco.ConsigneeAddress)
|
|
|
.Map(dto => dto.CONSIGNEECOUNTRY, poco => poco.ConsigneeCountry)
|
|
|
.Map(dto => dto.CONSIGNEETEL, poco => poco.ConsigneeTel)
|
|
|
.Map(dto => dto.NOTIFYPARTYNAME, poco => poco.NotifyPartyName)
|
|
|
.Map(dto => dto.NOTIFYPARTYADDR1, poco => poco.NotifyPartyAddress)
|
|
|
.Map(dto => dto.NOTIFYPARTYCOUNTRY, poco => poco.NotifyPartyCountry)
|
|
|
.Map(dto => dto.NOTIFYPARTYTEL, poco => poco.NotifyPartyTel)
|
|
|
.Map(dto => dto.PORTLOAD, poco => poco.LoadPort)
|
|
|
.Map(dto => dto.PORTLOADID, poco => poco.LoadPortCode)
|
|
|
.Map(dto => dto.PORTDISCHARGE, poco => poco.DischargePort)
|
|
|
.Map(dto => dto.PORTDISCHARGEID, poco => poco.DischargePortCode)
|
|
|
.Map(dto => dto.MARKS, poco => poco.Marks)
|
|
|
.Map(dto => dto.DESCRIPTION, poco => poco.Description)
|
|
|
.Map(dto => dto.CARGOID, poco => poco.CargoId)
|
|
|
.Map(dto => dto.TEMPSET, poco => poco.TemperatureSet)
|
|
|
.Map(dto => dto.TEMPID, poco => poco.TemperatureUnit)
|
|
|
.Map(dto => dto.REEFERF, poco => poco.ReeferQuantity)
|
|
|
.Map(dto => dto.DCLASS, poco => poco.DangerClass)
|
|
|
.Map(dto => dto.DUNNO, poco => poco.DangerNo)
|
|
|
.Map(dto => dto.DATTN, poco => poco.DangerAttn)
|
|
|
.Map(dto => dto.DTEL, poco => poco.DangerTel)
|
|
|
.Map(dto => dto.KINDPKGS, poco => poco.KindPkgs)
|
|
|
.Map(dto => dto.PLACEDELIVERY, poco => poco.DeliveryPlace)
|
|
|
.Map(dto => dto.SENDREMARK, poco => poco.SendRemark)
|
|
|
.Map(dto => dto.PLACEDELIVERYID, poco => poco.DeliveryPlaceCode)
|
|
|
.Map(dto => dto.YARDID, poco => poco.YardCode);
|
|
|
TypeAdapterConfig<SeaExportShippingBillCtn, CTNDATAItem>
|
|
|
.NewConfig()
|
|
|
.Map(dto => dto.SIZE, poco => poco.Size)
|
|
|
.Map(dto => dto.CTN, poco => poco.Ctn)
|
|
|
.Map(dto => dto.CTNALL, poco => poco.CtnAll)
|
|
|
.Map(dto => dto.CNTRNO, poco => poco.CntrNo)
|
|
|
.Map(dto => dto.SEALNO, poco => poco.SealNo)
|
|
|
.Map(dto => dto.PKGS, poco => poco.PKGS)
|
|
|
.Map(dto => dto.KINDPKGS, poco => poco.KindPkgs)
|
|
|
.Map(dto => dto.KGS, poco => poco.KGS)
|
|
|
.Map(dto => dto.CBM, poco => poco.CBM);
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 列表
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
public DataResult<List<ShippingBillRes>> GetListByPage(PageRequest request)
|
|
|
{
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
//序列化查询条件
|
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
|
var data = tenantDb.Queryable<SeaExportShippingBill>()
|
|
|
.Where(whereList)
|
|
|
.Select<ShippingBillRes>().ToQueryPage(request.PageCondition);
|
|
|
return data;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 编辑
|
|
|
/// </summary>
|
|
|
/// <param name="req"></param>
|
|
|
/// <returns></returns>
|
|
|
public DataResult EditShippingBill(ShippingBillReq req)
|
|
|
{
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
if (!string.IsNullOrWhiteSpace(req.MBLNO))
|
|
|
{
|
|
|
var et = tenantDb.Queryable<SeaExportShippingBill>().Where(x => x.MBLNO == req.MBLNO && x.HBLNO == req.HBLNO && x.Id != req.Id).First();
|
|
|
if (et != null)
|
|
|
{
|
|
|
return DataResult.Failed("当前提单号已存在,请勿重复录入!");
|
|
|
|
|
|
}
|
|
|
}
|
|
|
if (req.Id == 0)
|
|
|
{
|
|
|
var data = req.Adapt<SeaExportShippingBill>();
|
|
|
data.State = "已录入";
|
|
|
|
|
|
if (data.CarrierId != 0)
|
|
|
{
|
|
|
data.Carrier = tenantDb.Queryable<MappingCarrier>().Where(x => x.LinkId == data.CarrierId).Select(x => x.MapCode).First();
|
|
|
}
|
|
|
if (data.CargoId != "D")
|
|
|
{
|
|
|
|
|
|
data.DangerClass = string.Empty;
|
|
|
data.DangerNo = string.Empty;
|
|
|
}
|
|
|
var entity = tenantDb.Insertable(data).ExecuteReturnEntity();
|
|
|
if (req.CtnInfo.Count > 0)
|
|
|
{
|
|
|
|
|
|
foreach (var item in req.CtnInfo)
|
|
|
{
|
|
|
var ctn = item.Adapt<SeaExportShippingBillCtn>();
|
|
|
ctn.Pid = entity.Id;
|
|
|
if (ctn.CtnAll.Length == 4)
|
|
|
{
|
|
|
ctn.Size = ctn.CtnAll != null ? ctn.CtnAll.Substring(0, 2) : "";
|
|
|
ctn.Ctn = ctn.CtnAll != null ? ctn.CtnAll.Substring(2, 2) : "";
|
|
|
|
|
|
}
|
|
|
if (ctn.CtnAll.Contains("'"))
|
|
|
{
|
|
|
ctn.Size = ctn.CtnAll.Split("'")[0].ToString();
|
|
|
ctn.Ctn = ctn.CtnAll.Split("'")[1].ToString();
|
|
|
|
|
|
}
|
|
|
tenantDb.Insertable(ctn).ExecuteCommand();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var info = tenantDb.Queryable<SeaExportShippingBill>().Where(x => x.Id == req.Id).First();
|
|
|
|
|
|
if (info.State != "已录入")
|
|
|
{
|
|
|
if (req.State != info.State)
|
|
|
{
|
|
|
req.State = info.State; //防止前端数据覆盖状态
|
|
|
}
|
|
|
|
|
|
if (req.HBLNO != info.HBLNO)
|
|
|
{
|
|
|
return DataResult.Failed("已直发状态不能修改分单号");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
info = req.Adapt(info);
|
|
|
if (info.CarrierId != 0)
|
|
|
{
|
|
|
info.Carrier = tenantDb.Queryable<MappingCarrier>().Where(x => x.LinkId == info.CarrierId).Select(x => x.MapCode).First();
|
|
|
}
|
|
|
if (info.CargoId != "D")
|
|
|
{
|
|
|
|
|
|
info.DangerClass = string.Empty;
|
|
|
info.DangerNo = string.Empty;
|
|
|
}
|
|
|
tenantDb.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).IgnoreColumns(it => new
|
|
|
{
|
|
|
it.MBLNO,
|
|
|
it.BusinessId,
|
|
|
}).ExecuteCommand();
|
|
|
|
|
|
if (req.CtnInfo.Count > 0)
|
|
|
{
|
|
|
var ctnList = tenantDb.Queryable<SeaExportShippingBillCtn>().Where(x => x.Pid == req.Id).ToList();
|
|
|
foreach (var item in req.CtnInfo)
|
|
|
{
|
|
|
if (item.Id == 0)
|
|
|
{
|
|
|
var ctn = item.Adapt<SeaExportShippingBillCtn>();
|
|
|
ctn.Pid = info.Id;
|
|
|
if (ctn.CtnAll.Length == 4)
|
|
|
{
|
|
|
ctn.Size = ctn.CtnAll != null ? ctn.CtnAll.Substring(0, 2) : "";
|
|
|
ctn.Ctn = ctn.CtnAll != null ? ctn.CtnAll.Substring(2, 2) : "";
|
|
|
|
|
|
}
|
|
|
if (ctn.CtnAll.Contains("'"))
|
|
|
{
|
|
|
ctn.Size = ctn.CtnAll.Split("'")[0].ToString();
|
|
|
ctn.Ctn = ctn.CtnAll.Split("'")[1].ToString();
|
|
|
|
|
|
}
|
|
|
tenantDb.Insertable(ctn).ExecuteCommand();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var ctn = ctnList.First(x => x.Id == item.Id);
|
|
|
ctn = item.Adapt(ctn);
|
|
|
if (ctn.CtnAll.Length == 4)
|
|
|
{
|
|
|
ctn.Size = ctn.CtnAll != null ? ctn.CtnAll.Substring(0, 2) : "";
|
|
|
ctn.Ctn = ctn.CtnAll != null ? ctn.CtnAll.Substring(2, 2) : "";
|
|
|
|
|
|
}
|
|
|
if (ctn.CtnAll.Contains("'"))
|
|
|
{
|
|
|
ctn.Size = ctn.CtnAll.Split("'")[0].ToString();
|
|
|
ctn.Ctn = ctn.CtnAll.Split("'")[1].ToString();
|
|
|
|
|
|
}
|
|
|
tenantDb.Updateable(ctn).ExecuteCommand();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 详情
|
|
|
/// </summary>
|
|
|
/// <param name="id"></param>
|
|
|
/// <returns></returns>
|
|
|
public DataResult<ShippingBillRes> GetShippingBillInfo(string id)
|
|
|
{
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
var data = tenantDb.Queryable<SeaExportShippingBill>()
|
|
|
.Where(a => a.Id == long.Parse(id))
|
|
|
.Select<ShippingBillRes>()
|
|
|
.First();
|
|
|
return DataResult<ShippingBillRes>.Success(data, MultiLanguageConst.DataQuerySuccess);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除
|
|
|
/// </summary>
|
|
|
/// <param name="id"></param>
|
|
|
/// <returns></returns>
|
|
|
public DataResult DelShippingBill(string id)
|
|
|
{
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
var info = tenantDb.Queryable<SeaExportShippingBill>().Where(x => x.Id == long.Parse(id)).First();
|
|
|
if (info == null)
|
|
|
{
|
|
|
return DataResult.Failed("舱单信息不存在!", MultiLanguageConst.ShippingBillNotExist);
|
|
|
}
|
|
|
|
|
|
var ctns = tenantDb.Queryable<SeaExportShippingBillCtn>().Where(x => x.Pid == long.Parse(id)).ToList();
|
|
|
tenantDb.Deleteable(ctns).ExecuteCommand();
|
|
|
|
|
|
tenantDb.Deleteable(info).ExecuteCommand();
|
|
|
return DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 批量删除
|
|
|
/// </summary>
|
|
|
/// <param name="req"></param>
|
|
|
/// <returns></returns>
|
|
|
public DataResult BatchDelShippingBill(IdModel req)
|
|
|
{
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
var list = tenantDb.Queryable<SeaExportShippingBill>().Where(x => req.Ids.Contains(x.Id)).ToList();
|
|
|
if (list.Count > 0)
|
|
|
{
|
|
|
var ctns = tenantDb.Queryable<SeaExportShippingBillCtn>().Where(x => req.Ids.Contains(x.Pid)).ToList();
|
|
|
tenantDb.Deleteable(ctns).ExecuteCommand();
|
|
|
|
|
|
tenantDb.Deleteable(list).ExecuteCommand();
|
|
|
}
|
|
|
return DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 舱单发送
|
|
|
/// </summary>
|
|
|
/// <param name="req"></param>
|
|
|
/// <returns></returns>
|
|
|
public async Task<DataResult<string>> SendShippingBill(ShippingBillSendReq req)
|
|
|
{
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
//var info = tenantDb.Queryable<SeaExportShippingBill>().Where(x => x.Id == long.Parse(id)).First();
|
|
|
//if (info == null)
|
|
|
//{
|
|
|
// return DataResult.Failed("舱单信息不存在!", MultiLanguageConst.ShippingBillNotExist);
|
|
|
//}
|
|
|
if (req.Ids.Count() > 0)
|
|
|
{
|
|
|
var custEDIDtos = new List<ShippingBillEdiDto>();
|
|
|
var key = tenantDb.Queryable<CodeThirdParty>().Where(x => x.AccountType == "DjyCangDan").First();
|
|
|
//var key = _webAccountConfig.GetAccountConfig("DjyCangDan", UserManager.UserId).Result; x.CustomerId == req.YardId &&
|
|
|
if (key == null)
|
|
|
{
|
|
|
return await Task.FromResult(DataResult<string>.Failed("当前用户未配置key,请联系管理员"));
|
|
|
}
|
|
|
var dicUrl = db.Queryable<SysConfig>().Filter(null, true).Where(x => x.Code == "request_emf" && x.TenantId == 1288018625843826688).First().Value;
|
|
|
|
|
|
long bookingId = 0;
|
|
|
foreach (var item in req.Ids)
|
|
|
{
|
|
|
long Id = item;
|
|
|
var order = await tenantDb.Queryable<SeaExportShippingBill>().Where(x => x.Id == Id).FirstAsync();
|
|
|
var ctns = await tenantDb.Queryable<SeaExportShippingBillCtn>().Where(x => x.Pid == order.Id).ToListAsync();
|
|
|
|
|
|
bookingId = order.BusinessId;
|
|
|
//船公司
|
|
|
if (string.IsNullOrEmpty(order.Carrier))
|
|
|
{
|
|
|
return await Task.FromResult(DataResult<string>.Failed("船公司未正确填写"));
|
|
|
}
|
|
|
//提单号不能为空
|
|
|
if (string.IsNullOrEmpty(order.MBLNO))
|
|
|
{
|
|
|
return await Task.FromResult(DataResult<string>.Failed("提单号不能为空"));
|
|
|
}
|
|
|
|
|
|
|
|
|
MDATA mDATA = new MDATA();
|
|
|
List<CTNDATAItem> CTNDATA = new List<CTNDATAItem>();
|
|
|
mDATA = order.Adapt<MDATA>();
|
|
|
if (string.IsNullOrEmpty(mDATA.FORWARDER))
|
|
|
{
|
|
|
return await Task.FromResult(DataResult<string>.Failed("船代不能为空"));
|
|
|
}
|
|
|
if (string.IsNullOrEmpty(mDATA.YARDID))
|
|
|
{
|
|
|
return await Task.FromResult(DataResult<string>.Failed("场站不能为空"));
|
|
|
}
|
|
|
mDATA.SENDREMARK = req.SendRemark;
|
|
|
var FORWARDER = mDATA.FORWARDER;
|
|
|
var YardCode = mDATA.YARDID;
|
|
|
if (tenantDb.Queryable<MappingForwarder>().Where(x => x.LinkId == order.ForwarderId && x.Module == "cangdan").Select(x => x.MapCode).First() == null)
|
|
|
{
|
|
|
return await Task.FromResult(DataResult<string>.Failed("暂不支持此船代"));
|
|
|
}
|
|
|
mDATA.FORWARDER =
|
|
|
tenantDb.Queryable<MappingForwarder>().Where(x => x.LinkId == order.ForwarderId && x.Module == "cangdan").Select(x => x.MapCode).First();
|
|
|
|
|
|
mDATA.YARDID = tenantDb.Queryable<MappingYard>().Where(x => x.LinkId == order.YardId && x.Module == "cangdan").Select(x => x.MapCode).First();
|
|
|
|
|
|
CTNDATA = ctns.Adapt<List<CTNDATAItem>>();
|
|
|
|
|
|
foreach (var ctn in ctns)
|
|
|
{
|
|
|
var temp = ctn.Adapt<CTNDATAItem>();
|
|
|
temp.KINDPKGS = tenantDb.Queryable<CodePackage>().Where(x => x.PackageName == ctn.KindPkgs).Select(x => x.EdiCode).First();
|
|
|
CTNDATA.Add(temp);
|
|
|
;
|
|
|
}
|
|
|
|
|
|
//foreach (var ctn in CTNDATA)
|
|
|
//{
|
|
|
// ctn.KINDPKGS = _cache.GetAllCodePackage().Result.Where(x => x.Name == ctn.KINDPKGS).Select(x => x.EdiCode).FirstOrDefault();
|
|
|
//}
|
|
|
custEDIDtos.Add(new ShippingBillEdiDto
|
|
|
{
|
|
|
MDATA = mDATA,
|
|
|
CTNDATA = CTNDATA
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region 舱单发送前,校验
|
|
|
if (req.IsCheck == true && (req.Type is "1" or "0") && custEDIDtos.Count > 0)
|
|
|
{
|
|
|
// 需要在舱单发送前增加以下字段的比对,由舱单字段与订舱数据字段做比对,比对存在异常提醒客户是否确认发送,对比字段如下:
|
|
|
// 主单提单号:主单主单提单号与订舱主提单号不一致时提醒
|
|
|
// 船名航次,唛头,货描 ,起运港,卸货港:主单与订舱 或 分单与主单不一致时提醒
|
|
|
// 件数,重量,尺码(按箱子判断):分单之和>主单 或 主单 != 订舱 时提醒
|
|
|
// 箱封号、箱型:主单的箱封号+箱型与订舱不一致时提醒、分单中出现主单中不存在的箱封号+箱型时提醒
|
|
|
|
|
|
var seaeList = await tenantDb.Queryable<SeaExportShippingBill>()
|
|
|
.Where(x => x.BusinessId == bookingId)
|
|
|
.ToListAsync();
|
|
|
|
|
|
var seaeCtnList = await tenantDb.Queryable<SeaExportShippingBillCtn>()
|
|
|
.Where(x => seaeList.Select(x => x.Id).Contains(x.Pid) && x.Deleted == false)
|
|
|
.ToListAsync();
|
|
|
var bkOrder = await tenantDb.Queryable<SeaExport>()
|
|
|
.Filter(null, true)
|
|
|
.Where(x => x.Id == bookingId && x.Deleted == false)
|
|
|
.FirstAsync();
|
|
|
var bkOrderCtnList = await tenantDb.Queryable<OpCtn>()
|
|
|
.Filter(null, true)
|
|
|
.Where(x => x.BSNO == bookingId.ToString() && x.Deleted == false)
|
|
|
.ToListAsync();
|
|
|
if (bkOrder == null)
|
|
|
{
|
|
|
return await Task.FromResult(DataResult<string>.Failed("未找到订舱数据"));
|
|
|
}
|
|
|
|
|
|
var checkResult = new List<string>();
|
|
|
|
|
|
// 舱单主单
|
|
|
var mainSeaOrder = seaeList.FirstOrDefault(x => string.IsNullOrWhiteSpace(x.HBLNO));
|
|
|
|
|
|
// 舱单分单
|
|
|
var subSeaOrderList = seaeList.Where(x => !string.IsNullOrWhiteSpace(x.HBLNO)).ToList();
|
|
|
|
|
|
// 校验规则1:船名航次,唛头,货描 ,起运港,卸货港,主单提单号
|
|
|
if (bkOrder.MBLNO != mainSeaOrder.MBLNO) checkResult.Add("舱单主单与订舱【提单号】不一致");
|
|
|
if (bkOrder.Vessel != mainSeaOrder.Vessel) checkResult.Add("舱单主单与订舱【船名】不一致");
|
|
|
if (bkOrder.Voyno != mainSeaOrder.Voyno) checkResult.Add("舱单主单与订舱【航次】不一致");
|
|
|
if (bkOrder.Marks != mainSeaOrder.Marks) checkResult.Add("舱单主单与订舱【唛头】不一致");
|
|
|
if (bkOrder.Description != mainSeaOrder.Description) checkResult.Add("舱单主单与订舱【货描】不一致");
|
|
|
//if (bkOrder.LoadPort != mainSeaOrder.LoadPortCode || bkOrder.PORTLOAD != mainSeaOrder.PORTLOAD) checkResult.Add("舱单主单与订舱【起运港】不一致");
|
|
|
//if (bkOrder.DischargePort != mainSeaOrder.DischargePortCode || bkOrder.PORTDISCHARGE != mainSeaOrder.PORTDISCHARGE) checkResult.Add("舱单主单与订舱【卸货港】不一致");
|
|
|
if (bkOrder.LoadPort != mainSeaOrder.LoadPortCode) checkResult.Add("舱单主单与订舱【起运港】不一致");
|
|
|
if (bkOrder.DischargePort != mainSeaOrder.DischargePortCode) checkResult.Add("舱单主单与订舱【卸货港】不一致");
|
|
|
|
|
|
subSeaOrderList.ForEach(x =>
|
|
|
{
|
|
|
if (bkOrder.Vessel != x.Vessel) checkResult.Add($"舱单分单【{x.HBLNO}】与订舱【船名】不一致");
|
|
|
if (bkOrder.Voyno != x.Voyno) checkResult.Add($"舱单分单【{x.HBLNO}】与订舱【航次】不一致");
|
|
|
if (bkOrder.Marks != x.Marks) checkResult.Add($"舱单分单【{x.HBLNO}】与订舱【唛头】不一致");
|
|
|
if (bkOrder.Description != x.Description) checkResult.Add($"舱单分单【{x.HBLNO}】与订舱【货描】不一致");
|
|
|
if (bkOrder.LoadPort != x.LoadPortCode) checkResult.Add($"舱单分单【{x.HBLNO}】与订舱【起运港】不一致");
|
|
|
if (bkOrder.DischargePort != x.DischargePortCode) checkResult.Add($"舱单分单【{x.HBLNO}】与订舱【卸货港】不一致");
|
|
|
//if (bkOrder.LoadPort != x.LoadPortCode || bkOrder.PORTLOAD != x.PORTLOAD) checkResult.Add($"舱单分单【{x.HBLNO}】与订舱【起运港】不一致");
|
|
|
//if (bkOrder.DischargePort != x.DischargePortCode || bkOrder.PORTDISCHARGE != x.PORTDISCHARGE) checkResult.Add($"舱单分单【{x.HBLNO}】与订舱【卸货港】不一致");
|
|
|
});
|
|
|
|
|
|
|
|
|
// 校验规则2:件重尺
|
|
|
// 先进行件重尺总数的比较
|
|
|
var 主单箱子列表 = seaeCtnList.Where(x => x.Pid == mainSeaOrder.Id).ToList();
|
|
|
var 分单箱子列表 = seaeCtnList.Where(x => x.Pid != mainSeaOrder.Id).ToList();
|
|
|
|
|
|
if (主单箱子列表.Sum(x => x.PKGS) != bkOrderCtnList.Sum(x => x.PKGS))
|
|
|
{
|
|
|
checkResult.Add($"舱单主单中箱子的【总件数】与订舱中箱子的【总件数】不一致");
|
|
|
}
|
|
|
if (主单箱子列表.Sum(x => x.KGS) != bkOrderCtnList.Sum(x => x.KGS))
|
|
|
{
|
|
|
checkResult.Add($"舱单主单中箱子的【总重量】与订舱中箱子的【总重量】不一致");
|
|
|
}
|
|
|
if (主单箱子列表.Sum(x => x.CBM) != bkOrderCtnList.Sum(x => x.CBM))
|
|
|
{
|
|
|
checkResult.Add($"舱单主单中箱子的【总尺码】与订舱中箱子的【总尺码】不一致");
|
|
|
}
|
|
|
|
|
|
if (分单箱子列表.Count > 0)
|
|
|
{
|
|
|
if (分单箱子列表.Sum(x => x.PKGS) != bkOrderCtnList.Sum(x => x.PKGS))
|
|
|
{
|
|
|
checkResult.Add($"舱单分单中箱子的【总件数】与订舱中箱子的【总件数】不一致");
|
|
|
}
|
|
|
if (分单箱子列表.Sum(x => x.KGS) != bkOrderCtnList.Sum(x => x.KGS))
|
|
|
{
|
|
|
checkResult.Add($"舱单分单中箱子的【总重量】与订舱中箱子的【总重量】不一致");
|
|
|
}
|
|
|
if (分单箱子列表.Sum(x => x.CBM) != bkOrderCtnList.Sum(x => x.CBM))
|
|
|
{
|
|
|
checkResult.Add($"舱单分单中箱子的【总尺码】与订舱中箱子的【总尺码】不一致");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// 再按箱号比较
|
|
|
foreach (var item in 主单箱子列表.GroupBy(x => x.CntrNo))
|
|
|
{
|
|
|
if (item.Sum(x => x.PKGS) != bkOrderCtnList.Where(x => x.CntrNo == item.Key).Sum(x => x.PKGS))
|
|
|
{
|
|
|
checkResult.Add($"箱号为【{item.Key}】的箱子,在舱单主单中的【件数】与订舱中同箱号箱子的【件数】不一致");
|
|
|
}
|
|
|
if (item.Sum(x => x.KGS) != bkOrderCtnList.Where(x => x.CntrNo == item.Key).Sum(x => x.KGS))
|
|
|
{
|
|
|
checkResult.Add($"箱号为【{item.Key}】的箱子,在舱单主单中的【重量】与订舱中同箱号箱子的【重量】不一致");
|
|
|
}
|
|
|
if (item.Sum(x => x.CBM) != bkOrderCtnList.Where(x => x.CntrNo == item.Key).Sum(x => x.CBM))
|
|
|
{
|
|
|
checkResult.Add($"箱号为【{item.Key}】的箱子,在舱单主单中的【尺码】与订舱中同箱号箱子的【尺码】不一致");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
foreach (var item in 分单箱子列表.GroupBy(x => x.CntrNo))
|
|
|
{
|
|
|
if (item.Sum(x => x.PKGS) != bkOrderCtnList.Where(x => x.CntrNo == item.Key).Sum(x => x.PKGS))
|
|
|
{
|
|
|
checkResult.Add($"箱号为【{item.Key}】的箱子,在舱单各分单中的【总件数】与订舱中同箱号箱子的【件数】不一致");
|
|
|
}
|
|
|
if (item.Sum(x => x.KGS) != bkOrderCtnList.Where(x => x.CntrNo == item.Key).Sum(x => x.KGS))
|
|
|
{
|
|
|
checkResult.Add($"箱号为【{item.Key}】的箱子,在舱单各分单中的【总重量】与订舱中同箱号箱子的【重量】不一致");
|
|
|
}
|
|
|
if (item.Sum(x => x.CBM) != bkOrderCtnList.Where(x => x.CntrNo == item.Key).Sum(x => x.CBM))
|
|
|
{
|
|
|
checkResult.Add($"箱号为【{item.Key}】的箱子,在舱单各分单中的【总尺码】与订舱中同箱号箱子的【尺码】不一致");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 校验规则3:箱号+封号+箱型
|
|
|
var 订舱箱封号箱型列表 = bkOrderCtnList.Select(x => $"箱号[{x.CntrNo}] 封号[{x.SealNo}] 箱型[{x.CtnAll.Replace("'", "")}]").ToList();
|
|
|
var 主单箱封号箱型列表 = 主单箱子列表.Select(x => $"箱号[{x.CntrNo}] 封号[{x.SealNo}] 箱型[{x.CtnAll.Replace("'", "")}]").ToList();
|
|
|
var 分单箱封号箱型列表 = 分单箱子列表.Select(x => $"箱号[{x.CntrNo}] 封号[{x.SealNo}] 箱型[{x.CtnAll.Replace("'", "")}]").Distinct().ToList();
|
|
|
|
|
|
var list1 = 订舱箱封号箱型列表.Except(主单箱封号箱型列表);
|
|
|
if (list1.Any())
|
|
|
{
|
|
|
checkResult.Add($"订舱中的下列箱信息在舱单主单中不存在:{string.Join(",", list1)}");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var list2 = 主单箱封号箱型列表.Except(订舱箱封号箱型列表);
|
|
|
if (list2.Any())
|
|
|
{
|
|
|
checkResult.Add($"舱单主单中的下列箱信息在订舱中不存在:{string.Join(",", list2)}");
|
|
|
}
|
|
|
}
|
|
|
var list3 = 分单箱封号箱型列表.Except(订舱箱封号箱型列表);
|
|
|
if (list3.Any())
|
|
|
{
|
|
|
checkResult.Add($"舱单分单中存在未知的箱信息:{string.Join(",", list3)}");
|
|
|
}
|
|
|
|
|
|
if (checkResult.Count > 0)
|
|
|
{
|
|
|
return await Task.FromResult(DataResult<string>.Failed(checkResult.ToString()));
|
|
|
//UnifyContext.Fill(new { checkResult });
|
|
|
//throw new Exception("校验不通过");
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
string strPostObj = custEDIDtos.ToJsonString();
|
|
|
var userInfo = await db.Queryable<SysUser>().Filter(null, true).FirstAsync(x => x.Id == long.Parse(user.UserId));
|
|
|
var sendObj = new
|
|
|
{
|
|
|
ac = "emf",
|
|
|
uid = userInfo.DjyUserId,
|
|
|
skey = key.AppSecret,
|
|
|
optype = req.Type,
|
|
|
data = strPostObj
|
|
|
};
|
|
|
_logger.Info($"调用舱单接口 {dicUrl} 传递数据:{strPostObj}");
|
|
|
//var strResp = await dicUrl.Value.SetContentType("multipart/form-data").SetBody(sendObj).PostAsStringAsync();
|
|
|
var strResp = RequestHelper.Post(sendObj.ToJsonString(), dicUrl);
|
|
|
_logger.Info($"调用舱单接口返回:{strResp}");
|
|
|
|
|
|
|
|
|
var jobjResp = JObject.Parse(strResp);
|
|
|
bool respCode = jobjResp.GetBooleanValue("Success");
|
|
|
if (respCode == false)
|
|
|
{
|
|
|
return await Task.FromResult(DataResult<string>.Failed(jobjResp.GetStringValue("Message").Replace("<br />", "\r\n").Replace("<br/>", "")));
|
|
|
}
|
|
|
|
|
|
foreach (var ar in req.Ids)
|
|
|
{
|
|
|
long Id = ar;
|
|
|
var order = await tenantDb.Queryable<SeaExportShippingBill>().Where(x => x.Id == Id).FirstAsync();
|
|
|
//货运动态
|
|
|
var bsl = new BookingStatusLog();
|
|
|
bsl.BusinessId = order.BusinessId;
|
|
|
if (req.Type == "3")
|
|
|
{
|
|
|
bsl.Status = $"保存舱单";
|
|
|
}
|
|
|
if (req.Type == "0")
|
|
|
{
|
|
|
bsl.Status = $"直发舱单";
|
|
|
}
|
|
|
if (req.Type == "1")
|
|
|
{
|
|
|
bsl.Status = $"修改舱单";
|
|
|
}
|
|
|
if (req.Type == "2")
|
|
|
{
|
|
|
bsl.Status = $"删除舱单";
|
|
|
}
|
|
|
if (req.Type == "4")
|
|
|
{
|
|
|
bsl.Status = $"作废舱单";
|
|
|
}
|
|
|
bsl.OpTime = DateTime.Now;
|
|
|
bsl.Group = "ship";
|
|
|
bsl.MBLNO = order.MBLNO;
|
|
|
await tenantDb.Insertable(bsl).ExecuteCommandAsync();
|
|
|
if (req.Type == "3")
|
|
|
{
|
|
|
await tenantDb.Updateable<SeaExportShippingBill>().SetColumns(x => new SeaExportShippingBill { State = "已发送", SendRemark = req.SendRemark })
|
|
|
.Where(it => it.Id == Id).ExecuteCommandAsync();
|
|
|
}
|
|
|
if (req.Type == "0" || req.Type == "1")
|
|
|
{
|
|
|
await tenantDb.Updateable<SeaExportShippingBill>().SetColumns(x => new SeaExportShippingBill { State = "已直发", SendRemark = req.SendRemark })
|
|
|
.Where(it => it.Id == Id).ExecuteCommandAsync();
|
|
|
if (string.IsNullOrEmpty(order.HBLNO))
|
|
|
{
|
|
|
await seaComService.SetGoodsStatus("YFCD", order.BusinessId);
|
|
|
//await _rep.SendBookingOrder(new long[] { order.BookingId });
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (req.Type == "2")
|
|
|
{
|
|
|
await tenantDb.Updateable<SeaExportShippingBill>().SetColumns(x => new SeaExportShippingBill { State = "已删除", SendRemark = req.SendRemark })
|
|
|
.Where(it => it.Id == Id).ExecuteCommandAsync();
|
|
|
}
|
|
|
if (req.Type == "4")
|
|
|
{
|
|
|
await tenantDb.Updateable<SeaExportShippingBill>().SetColumns(x => new SeaExportShippingBill { State = "已作废", SendRemark = req.SendRemark })
|
|
|
.Where(it => it.Id == Id).ExecuteCommandAsync();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Success("发送成功!"));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return await Task.FromResult(DataResult<string>.Failed("参数不正确"));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|