修改BC生成任务默认值

修改海领截单
master
jianghaiqing 5 months ago
parent 975f171678
commit 7b6b435dec

@ -1,5 +1,9 @@
using Furion.FriendlyException; using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using Furion.FriendlyException;
using Furion.Logging; using Furion.Logging;
using Microsoft.VisualBasic;
using Myshipping.Application.EDI.VOLTA; using Myshipping.Application.EDI.VOLTA;
using NPOI.HPSF; using NPOI.HPSF;
using NPOI.HSSF.UserModel; using NPOI.HSSF.UserModel;
@ -16,6 +20,7 @@ using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yitter.IdGenerator;
namespace Myshipping.Application.EDI.SeaLead namespace Myshipping.Application.EDI.SeaLead
{ {
@ -45,9 +50,287 @@ namespace Myshipping.Application.EDI.SeaLead
DateTime nowDate = DateTime.Now; DateTime nowDate = DateTime.Now;
var excelFileName = string.Empty;
//读取文件 //读取文件
var file = new FileStream(fileAbsPath, FileMode.Open); //var file = new FileStream(fileAbsPath, FileMode.Open);
var fileName = $"{model.BookingId}_SLS_{DateTime.Now.Ticks.ToString()}.xlsx";//名称
excelFileName = Path.Combine(model.FilePath, fileName);
System.IO.File.Copy(fileAbsPath, excelFileName, true);
using (SpreadsheetDocument spreadSheetDocument = SpreadsheetDocument.Open(excelFileName, true))
{
WorkbookPart wbPart = spreadSheetDocument.WorkbookPart;
IEnumerable<Sheet> sheets = spreadSheetDocument.WorkbookPart.Workbook.GetFirstChild<Sheets>().Elements<Sheet>();
var sheetNameArgs = sheets.Select(sh =>
{
return sh.Id.Value;
}).ToArray();
int startNo = 1;
foreach (var sheet in sheetNameArgs)
{
var sheetInfo = new ParserSheetInfo();
WorksheetPart worksheetPart = (WorksheetPart)spreadSheetDocument.WorkbookPart.GetPartById(sheet);
Worksheet workSheet = worksheetPart.Worksheet;
SheetData sheetData = workSheet.GetFirstChild<SheetData>();
var rowList = sheetData.Descendants<DocumentFormat.OpenXml.Spreadsheet.Row>().ToList();
if (startNo == 1)
{
var baseColsDict = rowList.ElementAt(rowList.Count - 1).Select((col, idx) =>
{
var cell = (Cell)col;
var colInfo = new ParserColsInfo
{
colsIndx = idx,
colsName = (string)GetCellValue(spreadSheetDocument, cell),
};
return colInfo;
}).ToDictionary(a => a.colsIndx, b => b.colsName);
var newRow = new Row
{
RowIndex = (UInt32)(rowList.Count + 1)
};
for (int i = 0; i < baseColsDict.Count; i++)
{
#region 主信息填值
if (baseColsDict[i].Equals("Booking ID", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.BookingId, i, newRow);
}
else if (baseColsDict[i].Equals("Shipper", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ShpperName, i, newRow);
}
else if (baseColsDict[i].Equals("Consignee", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ConsigneeName, i, newRow);
}
else if (baseColsDict[i].Equals("Notify Party", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.NotifyName, i, newRow);
}
else if (baseColsDict[i].Equals("Additional Notify Party", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.NotifySecondName, i, newRow);
}
else if (baseColsDict[i].Equals("Shipper Address", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ShpperAddr, i, newRow);
}
else if (baseColsDict[i].Equals("Consignee Address", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ConsigneeAddr, i, newRow);
}
else if (baseColsDict[i].Equals("Notify Party Address", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.NotifyAddr, i, newRow);
}
else if (baseColsDict[i].Equals("Additional Notify Party Address", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.NotifySecondAddr, i, newRow);
}
else if (baseColsDict[i].Equals("Shipper Export Reference", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ShipperExportReference, i, newRow);
}
else if (baseColsDict[i].Equals("Shipper Export Reference Type", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ShipperExportReferenceType, i, newRow);
}
else if (baseColsDict[i].Equals("Payment Term", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.BLFRT, i, newRow);
}
else if (baseColsDict[i].Equals("Marks and Numbers", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.Marks, i, newRow);
}
else if (baseColsDict[i].Equals("Description of Pkgs", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.CargoDescription, i, newRow);
}
else if (baseColsDict[i].Equals("Document type", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.DocumentTypeCode, i, newRow);
}
else if (baseColsDict[i].Equals("Port Of Loading", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.LoadPort, i, newRow);
}
else if (baseColsDict[i].Equals("Port Of Discharge", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.DischargePort, i, newRow);
}
else if (baseColsDict[i].Equals("Place of Receipt by Precarrier", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.PlaceOfOrigin, i, newRow);
}
else if (baseColsDict[i].Equals("Place of Final Delivery by On Carrier", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.FinalDestination, i, newRow);
}
else if (baseColsDict[i].Equals("HS Code", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.HSCode, i, newRow);
}
else if (baseColsDict[i].Equals("Precarriage", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.Precarriage, i, newRow);
}
#endregion
}
sheetData.Append(newRow);
}
else if(startNo == 2)
{
var ctnColsDict = rowList.ElementAt(rowList.Count - 1).Select((col, idx) =>
{
var cell = (Cell)col;
var colInfo = new ParserColsInfo
{
colsIndx = idx,
colsName = (string)GetCellValue(spreadSheetDocument, cell),
};
return colInfo;
}).ToDictionary(a => a.colsIndx, b => b.colsName);
for (int j = 0; j < model.ContaList.Count; j++)
{
var newCtnRow = new Row
{
RowIndex = (UInt32)(rowList.Count + 1)
};
GenerateCellInfoOpenXml(model.ContaList[j].SNo.ToString(), 0, newCtnRow);
for (int k = 0; k < ctnColsDict.Count; k++)
{
#region 箱信息填写
if (ctnColsDict[k].Equals("Container Serial Number", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].ContaNo, k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Container type", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].CtnType, k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Outer package ID", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].OuterPackageID, k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Type of Package", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].EdiPkgs, k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Number of outer packages", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].Qty.HasValue ? model.ContaList[j].Qty.Value.ToString("0.##") : "", k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Weight value", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].GWt.HasValue ? model.ContaList[j].GWt.Value.ToString("0.##") : "", k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Gross Weight UoM", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].WTUnit, k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Volume value", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].CBM.HasValue ? model.ContaList[j].CBM.Value.ToString("0.##") : "", k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Gross Volume UoM", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].CBMUnit, k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Length", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].Length.HasValue ? model.ContaList[j].Length.Value.ToString("0.##") : "", k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Width", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].Width.HasValue ? model.ContaList[j].Width.Value.ToString("0.##") : "", k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Height", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].Height.HasValue ? model.ContaList[j].Height.Value.ToString("0.##") : "", k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Unit of Measure", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].UnitofMeasure, k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Vehicle Identification Number", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].VehicleIdNumber, k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Vehicle Registration PI", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].VehicleRegistPI, k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Seal Number 1", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].SealNo, k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Seal Number 2", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].SealNumber2, k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Seal Number 3", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].SealNumber3, k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Seal Number 4", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].SealNumber4, k + 1, newCtnRow);
}
else if (ctnColsDict[k].Equals("Seal Number 5", StringComparison.OrdinalIgnoreCase))
{
GenerateCellInfoOpenXml(model.ContaList[j].SealNumber5, k + 1, newCtnRow);
}
#endregion
}
sheetData.Append(newCtnRow);
}
}
startNo++;
}
wbPart.Workbook.Save();
//byte[] pReadByte = new byte[file.Length];
////var bytes = file.();
//var filestream = new FileStream(excelFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
//file.Write(pReadByte, 0, pReadByte.Length);
////ar fileStream = new FileStream(filepath, FileMode.Create, FileAccess.Write, FileShare.Read);
////fileStream.Write(bytes, 0, bytes.Length);
//file.Flush();
//file.Close();
//file.Dispose();
//document.Close();
}
/*
var excelwork = new XSSFWorkbook(file); var excelwork = new XSSFWorkbook(file);
//截单主信息 //截单主信息
@ -291,9 +574,7 @@ namespace Myshipping.Application.EDI.SeaLead
excelwork.SetActiveSheet(0); excelwork.SetActiveSheet(0);
var fileName = $"{model.BookingId}_SLS_{DateTime.Now.Ticks.ToString()}.xlsx";//名称
var excelFileName = Path.Combine(model.FilePath, fileName);
var filestream = new FileStream(excelFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite); var filestream = new FileStream(excelFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
@ -302,9 +583,9 @@ namespace Myshipping.Application.EDI.SeaLead
//filestream.Flush(); //filestream.Flush();
//filestream.Position = 0; //filestream.Position = 0;
*/
filestream.Close(); //
filestream.Dispose(); //filestream.Dispose();
result.succ = true; result.succ = true;
result.extra = excelFileName; result.extra = excelFileName;
@ -320,13 +601,32 @@ namespace Myshipping.Application.EDI.SeaLead
} }
#endregion #endregion
private static void GenerateCellInfo(string val, int cellIndex, XSSFRow row, CellType cellType = CellType.String) public static string GetCellValue(SpreadsheetDocument document, Cell cell)
{
SharedStringTablePart stringTablePart = document.WorkbookPart.SharedStringTablePart;
string value = String.Empty;
if (cell.CellValue != null)
value = cell.CellValue.InnerXml;
if (cell.DataType != null && (cell.DataType.Value == CellValues.SharedString || cell.DataType.Value == CellValues.String || cell.DataType.Value == CellValues.Number))
{
return stringTablePart.SharedStringTable.ChildElements[Int32.Parse(value)].InnerText;
}
else //浮点数和日期对应的cell.DataType都为NULL
{
// DateTime.FromOADate((double.Parse(value)); 如果确定是日期就可以直接用过该方法转换为日期对象可是无法确定DataType==NULL的时候这个CELL 数据到底是浮点型还是日期.(日期被自动转换为浮点
return value;
}
}
private static void GenerateCellInfo(string val, int cellIndex, XSSFRow row, NPOI.SS.UserModel.CellType cellType = NPOI.SS.UserModel.CellType.String)
{ {
if (!string.IsNullOrWhiteSpace(val)) if (!string.IsNullOrWhiteSpace(val))
{ {
var currCell = (XSSFCell)row.CreateCell(cellIndex, cellType); var currCell = (XSSFCell)row.CreateCell(cellIndex, cellType);
if (cellType == CellType.Numeric) if (cellType == NPOI.SS.UserModel.CellType.Numeric)
{ {
currCell.SetCellValue(double.Parse(val)); currCell.SetCellValue(double.Parse(val));
} }
@ -344,10 +644,33 @@ namespace Myshipping.Application.EDI.SeaLead
private static void GenerateCellInfoWithInt(int val, int cellIndex, XSSFRow row) private static void GenerateCellInfoWithInt(int val, int cellIndex, XSSFRow row)
{ {
var currCell = (XSSFCell)row.CreateCell(cellIndex,CellType.String); var currCell = (XSSFCell)row.CreateCell(cellIndex, NPOI.SS.UserModel.CellType.String);
currCell.SetCellValue(val.ToString()); currCell.SetCellValue(val.ToString());
} }
private static void GenerateCellInfoOpenXml(string val, int cellIndex, Row row)
{
if (!string.IsNullOrWhiteSpace(val))
{
var cell = new Cell
{
CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue(val),
DataType = new EnumValue<CellValues>(CellValues.String),
};
row.AppendChild(cell);
}
else
{
var cell = new Cell
{
CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue(""),
DataType = new EnumValue<CellValues>(CellValues.String)
};
row.AppendChild(cell);
}
}
#region 校验VOLTA请求参数s #region 校验VOLTA请求参数s
/// <summary> /// <summary>
/// 校验VOLTA请求参数 /// 校验VOLTA请求参数

@ -42,6 +42,7 @@
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" /> <PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
<PackageReference Include="NPOI" Version="2.6.0" /> <PackageReference Include="NPOI" Version="2.6.0" />
<PackageReference Include="Npoi.Mapper" Version="4.1.0" /> <PackageReference Include="Npoi.Mapper" Version="4.1.0" />
<PackageReference Include="Open-XML-SDK" Version="2.9.1" />
<PackageReference Include="RabbitMQ.Client" Version="6.5.0" /> <PackageReference Include="RabbitMQ.Client" Version="6.5.0" />
<PackageReference Include="Scriban" Version="5.7.0" /> <PackageReference Include="Scriban" Version="5.7.0" />
</ItemGroup> </ItemGroup>

@ -964,7 +964,7 @@ namespace Myshipping.Application.Service.BookingOrder
if (string.IsNullOrWhiteSpace(model.bookedByCompanyContactEmail)) if (string.IsNullOrWhiteSpace(model.bookedByCompanyContactEmail))
throw Oops.Bah($"订舱方公司邮箱必填"); throw Oops.Bah($"订舱方公司邮箱必填");
if (string.IsNullOrWhiteSpace(model.priceOwnerContactName)) if (string.IsNullOrWhiteSpace(model.priceOwnerCompanyName))
throw Oops.Bah($"持约方公司名称必填"); throw Oops.Bah($"持约方公司名称必填");
if (string.IsNullOrWhiteSpace(model.priceOwnerMaerskPartyCode)) if (string.IsNullOrWhiteSpace(model.priceOwnerMaerskPartyCode))

@ -1096,7 +1096,7 @@ namespace Myshipping.Application.Service.BookingOrder
if (string.IsNullOrWhiteSpace(model.bookedByCompanyContactEmail)) if (string.IsNullOrWhiteSpace(model.bookedByCompanyContactEmail))
throw Oops.Bah($"订舱方公司邮箱必填"); throw Oops.Bah($"订舱方公司邮箱必填");
if (string.IsNullOrWhiteSpace(model.priceOwnerContactName)) if (string.IsNullOrWhiteSpace(model.priceOwnerCompanyName))
throw Oops.Bah($"持约方公司名称必填"); throw Oops.Bah($"持约方公司名称必填");
if (string.IsNullOrWhiteSpace(model.priceOwnerMaerskPartyCode)) if (string.IsNullOrWhiteSpace(model.priceOwnerMaerskPartyCode))

@ -40,5 +40,10 @@
/// 订舱途径选择 /// 订舱途径选择
/// </summary> /// </summary>
public const string BOOKING_CHANNEL_SELECT_SHOW = "BOOKING_CHANNEL_SELECT_SHOW"; public const string BOOKING_CHANNEL_SELECT_SHOW = "BOOKING_CHANNEL_SELECT_SHOW";
/// <summary>
/// BC任务生成默认选项
/// </summary>
public const string BC_TASK_CREATE_ORDER = "BC_TASK_CREATE_ORDER";
} }
} }

@ -913,6 +913,11 @@
订舱途径选择 订舱途径选择
</summary> </summary>
</member> </member>
<member name="F:Myshipping.Core.Const.TenantParamCode.BC_TASK_CREATE_ORDER">
<summary>
BC任务生成默认选项
</summary>
</member>
<member name="P:Myshipping.Core.Entity.CodeCarrier.Code"> <member name="P:Myshipping.Core.Entity.CodeCarrier.Code">
<summary> <summary>
代码 代码

@ -261,7 +261,8 @@ public class AuthService : IAuthService, IDynamicApiController, ITransient
} }
// 返回前端需要使用的租户参数 // 返回前端需要使用的租户参数
var paraCodeArr = new string[] { TenantParamCode.ENABLE_SLOT_ABILITY, TenantParamCode.ENABLE_FEE_ABILITY, TenantParamCode.VESSEL_FROM_CONFIG_ONLY, TenantParamCode.BOOKING_CHANNEL_SELECT_SHOW }; var paraCodeArr = new string[] { TenantParamCode.ENABLE_SLOT_ABILITY, TenantParamCode.ENABLE_FEE_ABILITY, TenantParamCode.VESSEL_FROM_CONFIG_ONLY,
TenantParamCode.BOOKING_CHANNEL_SELECT_SHOW, TenantParamCode.BC_TASK_CREATE_ORDER };
loginOutput.TenantParams = await _djyTenantParamService.GetParaCodeWithValue(paraCodeArr); loginOutput.TenantParams = await _djyTenantParamService.GetParaCodeWithValue(paraCodeArr);
//多账号关联 //多账号关联

Loading…
Cancel
Save