|
|
|
@ -1851,12 +1851,254 @@ namespace Myshipping.Application
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
1、只支持Excel导入
|
|
|
|
|
2、
|
|
|
|
|
*/
|
|
|
|
|
result.succ = false;
|
|
|
|
|
if (file == null)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "附件不能为空";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileInfo fileInfo = new FileInfo(file.FileName);
|
|
|
|
|
if (fileInfo.Extension != ".xlsx")
|
|
|
|
|
{
|
|
|
|
|
result.msg = "请上传指定模板文件";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
var tempDic = Path.Combine(App.WebHostEnvironment.WebRootPath, App.GetOptions<TempFileOptions>().Path, DateTime.Now.Ticks.ToString());
|
|
|
|
|
Directory.CreateDirectory(tempDic);
|
|
|
|
|
var filePath = Path.Combine(tempDic, file.FileName);
|
|
|
|
|
|
|
|
|
|
using (var stream = File.Create(filePath))
|
|
|
|
|
{
|
|
|
|
|
await file.CopyToAsync(stream);
|
|
|
|
|
}
|
|
|
|
|
using FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);
|
|
|
|
|
var readbook = new XSSFWorkbook(fs);
|
|
|
|
|
var sheet = readbook.GetSheet("导入");
|
|
|
|
|
if (sheet == null)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "内容为空";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var rowCount = sheet.LastRowNum;
|
|
|
|
|
if (rowCount <= 1)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "内容为空";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dictionary<BookingSlotBase, List<BookingSlotCtn>> data = new(rowCount);
|
|
|
|
|
//List<BookingSlotBase> data = new(rowCount);
|
|
|
|
|
|
|
|
|
|
var cacheCarrier = await _cache.GetAllCodeCarrier();
|
|
|
|
|
var cachePortLoad = await _cache.GetAllCodePortLoad();
|
|
|
|
|
var cachePort = await _cache.GetAllCodePort();
|
|
|
|
|
var cacheLane = await _cache.GetAllCodeLane();
|
|
|
|
|
var cacheCtnCode = await _cache.GetAllCodeCtn();
|
|
|
|
|
|
|
|
|
|
BookingSlotBase lastSlot = null;
|
|
|
|
|
for (int i = 1; i < rowCount; i++)
|
|
|
|
|
{
|
|
|
|
|
var row = sheet.GetRow(i);
|
|
|
|
|
if (row == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrWhiteSpace(row.GetCell(0)?.StringCellValue))
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(row.GetCell(23)?.ToString()))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BookingSlotCtn ctnExt = new();
|
|
|
|
|
// 解析箱信息
|
|
|
|
|
for (int n = 23; n <= 24; n++)
|
|
|
|
|
{
|
|
|
|
|
var cell = row.GetCell(n);
|
|
|
|
|
if (cell == null) continue;
|
|
|
|
|
|
|
|
|
|
var value = cell.ToString();
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(value)) continue;
|
|
|
|
|
|
|
|
|
|
switch (n)
|
|
|
|
|
{
|
|
|
|
|
case 23:
|
|
|
|
|
{
|
|
|
|
|
ctnExt.CTNALL = value;
|
|
|
|
|
ctnExt.CTNCODE = cacheCtnCode.FirstOrDefault(x => x.Name == value)?.Code;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 24:
|
|
|
|
|
{
|
|
|
|
|
if (int.TryParse(value, out int temp)) ctnExt.CTNNUM = temp; break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrEmpty(ctnExt.CTNCODE) && data.TryGetValue(lastSlot, out var ctnList))
|
|
|
|
|
{
|
|
|
|
|
ctnList.Add(ctnExt);
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
var slot = new BookingSlotBase();
|
|
|
|
|
|
|
|
|
|
// 解析舱位信息
|
|
|
|
|
for (int n = 0; n <= 22; n++)
|
|
|
|
|
{
|
|
|
|
|
var cell = row.GetCell(n);
|
|
|
|
|
if (cell == null) continue;
|
|
|
|
|
|
|
|
|
|
//var value = cell.StringCellValue;
|
|
|
|
|
var value = cell.ToString().Trim();
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(value)) continue;
|
|
|
|
|
|
|
|
|
|
switch (n)
|
|
|
|
|
{
|
|
|
|
|
case 0: slot.SLOT_BOOKING_NO = value; break;
|
|
|
|
|
case 1: slot.CARRIERID = value; break;
|
|
|
|
|
case 2: slot.VESSEL = value; break;
|
|
|
|
|
case 3: slot.VOYNO = value; break;
|
|
|
|
|
case 4: slot.CONTRACT_NO = value; break;
|
|
|
|
|
case 5: slot.BOOKING_SLOT_TYPE_NAME = value; break;
|
|
|
|
|
case 6:
|
|
|
|
|
{
|
|
|
|
|
if (DateTime.TryParse(value, out DateTime temp)) slot.ETD = temp; break;
|
|
|
|
|
}
|
|
|
|
|
case 7:
|
|
|
|
|
{
|
|
|
|
|
if (DateTime.TryParse(value, out DateTime temp)) slot.ETA = temp; break;
|
|
|
|
|
}
|
|
|
|
|
case 8: slot.BOOKING_PARTY = value; break;
|
|
|
|
|
case 9: slot.PLACERECEIPT = value; break;
|
|
|
|
|
case 10: slot.PLACEDELIVERY = value; break;
|
|
|
|
|
case 11: slot.PORTLOADID = value; break;
|
|
|
|
|
case 12: slot.PORTDISCHARGEID = value; break;
|
|
|
|
|
case 13:
|
|
|
|
|
{
|
|
|
|
|
if (int.TryParse(value, out int temp)) slot.WEEK_AT = temp; break;
|
|
|
|
|
}
|
|
|
|
|
case 14:
|
|
|
|
|
{
|
|
|
|
|
if (DateTime.TryParse(value, out DateTime temp)) slot.SI_CUT_DATE = temp; break;
|
|
|
|
|
}
|
|
|
|
|
case 15:
|
|
|
|
|
{
|
|
|
|
|
if (DateTime.TryParse(value, out DateTime temp)) slot.VGM_SUBMISSION_CUT_DATE = temp; break;
|
|
|
|
|
}
|
|
|
|
|
case 16:
|
|
|
|
|
{
|
|
|
|
|
if (DateTime.TryParse(value, out DateTime temp)) slot.CY_CUT_DATE = temp; break;
|
|
|
|
|
}
|
|
|
|
|
case 17:
|
|
|
|
|
{
|
|
|
|
|
if (DateTime.TryParse(value, out DateTime temp)) slot.MANIFEST_CUT_DATE = temp; break;
|
|
|
|
|
}
|
|
|
|
|
case 18:
|
|
|
|
|
{
|
|
|
|
|
if (DateTime.TryParse(value, out DateTime temp)) slot.MDGF_CUT_DATE = temp; break;
|
|
|
|
|
}
|
|
|
|
|
case 19: slot.LANENAME = value; break; //
|
|
|
|
|
case 20:
|
|
|
|
|
{
|
|
|
|
|
if (int.TryParse(value, out int temp)) slot.DETENSION_FREE_DAYS = temp; break;
|
|
|
|
|
}
|
|
|
|
|
case 21:
|
|
|
|
|
{
|
|
|
|
|
if (DateTime.TryParse(value, out DateTime temp)) slot.CreatedTime = temp; break;
|
|
|
|
|
}
|
|
|
|
|
case 22:
|
|
|
|
|
{
|
|
|
|
|
if (DateTime.TryParse(value, out DateTime temp)) slot.PRICE_CALCULATION_DATE = temp; break;
|
|
|
|
|
}
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 特殊处理
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(slot.CARRIERID)) slot.CARRIER = cacheCarrier.FirstOrDefault(x => x.EnName == slot.CARRIERID)?.CnName;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(slot.PORTLOADID)) slot.PORTLOAD = cachePortLoad.FirstOrDefault(x => x.EdiCode == slot.PORTLOADID)?.EnName;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(slot.PORTDISCHARGEID)) slot.PORTDISCHARGE = cachePort.FirstOrDefault(x => x.EdiCode == slot.PORTDISCHARGEID)?.EnName;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(slot.LANENAME)) slot.LANECODE = cacheLane.FirstOrDefault(x => x.CnName == slot.LANENAME)?.Code;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(slot.BOOKING_SLOT_TYPE_NAME))
|
|
|
|
|
slot.BOOKING_SLOT_TYPE = slot.BOOKING_SLOT_TYPE_NAME switch
|
|
|
|
|
{
|
|
|
|
|
"合约订舱" => "CONTRACT_ORDER",
|
|
|
|
|
"SPOT订舱" => "SPOT_ORDER",
|
|
|
|
|
_ => null
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var ctns = new List<BookingSlotCtn>();
|
|
|
|
|
|
|
|
|
|
BookingSlotCtn ctn = new();
|
|
|
|
|
// 解析箱信息
|
|
|
|
|
for (int n = 23; n <= 24; n++)
|
|
|
|
|
{
|
|
|
|
|
var cell = row.GetCell(n);
|
|
|
|
|
if (cell == null) continue;
|
|
|
|
|
|
|
|
|
|
var value = cell.ToString();
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(value)) continue;
|
|
|
|
|
|
|
|
|
|
switch (n)
|
|
|
|
|
{
|
|
|
|
|
case 23:
|
|
|
|
|
{
|
|
|
|
|
ctn.CTNALL = value;
|
|
|
|
|
ctn.CTNCODE = cacheCtnCode.FirstOrDefault(x => x.Name == value)?.Code;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 24:
|
|
|
|
|
{
|
|
|
|
|
if (int.TryParse(value, out int temp)) ctn.CTNNUM = temp; break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrEmpty(ctn.CTNCODE))
|
|
|
|
|
{
|
|
|
|
|
ctns.Add(ctn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data.Add(slot, ctns);
|
|
|
|
|
lastSlot = slot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 判断是否已经存在
|
|
|
|
|
var noList = data.Select(x => x.Key).Select(x => x.SLOT_BOOKING_NO).ToList();
|
|
|
|
|
var existsNoList = await _repBase.AsQueryable()
|
|
|
|
|
.Where(x => noList.Contains(x.SLOT_BOOKING_NO))
|
|
|
|
|
.Select(x => x.SLOT_BOOKING_NO)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
foreach (var item in data)
|
|
|
|
|
{
|
|
|
|
|
if (existsNoList.Contains(item.Key.SLOT_BOOKING_NO))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await _repBase.InsertAsync(item.Key);
|
|
|
|
|
var id = item.Key.Id;
|
|
|
|
|
if (item.Value.Any())
|
|
|
|
|
{
|
|
|
|
|
item.Value.ForEach(x =>
|
|
|
|
|
{
|
|
|
|
|
x.SLOT_ID = id;
|
|
|
|
|
});
|
|
|
|
|
await _repCtn.InsertAsync(item.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.succ = true;
|
|
|
|
|
result.msg = "导入成功";
|
|
|
|
|
result.msg = $"导入成功,共导入{data.Count}条舱位信息";
|
|
|
|
|
|
|
|
|
|
if (existsNoList.Any())
|
|
|
|
|
{
|
|
|
|
|
result.msg += $";其中下列订舱编号因已在系统中已存在所以未导入:{string.Join("、", existsNoList)}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
@ -2014,7 +2256,7 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
var fs = new FileStream(fileAbsPath, FileMode.Open);
|
|
|
|
|
var excelwork = new XSSFWorkbook(fs);
|
|
|
|
|
var sheet = excelwork.GetSheetAt(0);
|
|
|
|
|
var sheet = excelwork.GetSheet("导出");
|
|
|
|
|
|
|
|
|
|
var rowIndex = 1;
|
|
|
|
|
var dateStr = "yyyy-MM-dd";
|
|
|
|
|