自动引入场站箱封号功能

optimize
wanghaomei 1 year ago
parent 7bd7329608
commit 43ea52026b

@ -7563,7 +7563,19 @@ namespace Myshipping.Application
throw Oops.Bah("请先选择场站");
}
var rtn = await YardDataHelper.GetYardData(UserManager.UserId, order.TenantId.Value, order.TenantName, order.MBLNO, order.YARDID, isWeb);
var listRtn = await GetYardDataAndMappingSystem(order, isWeb);
return listRtn.ToJsonString();
}
/// <summary>
/// 从爬虫获取场站数据,并映射为系统中的箱型
/// </summary>
/// <returns></returns>
private async Task<List<BookingGetYardDataDto>> GetYardDataAndMappingSystem(BookingOrder order, bool isWeb = false)
{
var rtn = await YardDataHelper.GetYardData(App.User.FindFirst(ClaimConst.CLAINM_USERID) == null ? order.CreatedUserId.Value : UserManager.UserId, order.TenantId.Value, order.TenantName, order.MBLNO, order.YARDID, isWeb);
if (!rtn.Key)
{
throw Oops.Bah(rtn.Value);
@ -7573,23 +7585,24 @@ namespace Myshipping.Application
var ctnList = await _cache.GetAllCodeCtn();
var mapCtn = await _cache.GetAllMappingCtn();
var jData = JArray.Parse(rtn.Value);
foreach (JObject item in jData)
var listRtn = JsonConvert.DeserializeObject<List<BookingGetYardDataDto>>(rtn.Value);
foreach (var item in listRtn)
{
var ctnall = item.GetStringValue("CTNALL");
var ctnall = item.CTNALL;
var findMap = mapCtn.FirstOrDefault(x => x.Module == "YardData" && x.MapCode == ctnall);
var findCtn = ctnList.FirstOrDefault(x => x.Name == ctnall);
if (findMap != null)
{
item.Add("CtnCode", findMap.Code);
item.CtnCode = findMap.Code;
findCtn = ctnList.First(c => c.Code == findMap.Code);
item["CTNALL"] = findCtn.Name; //名称显示维护的箱型
item.CTNALL = findCtn.Name; //名称显示维护的箱型
}
else if (findCtn != null)
{
item.Add("CtnCode", findCtn.Code);
item["CTNALL"] = findCtn.Name; //名称显示维护的箱型
item.CtnCode = findCtn.Code;
item.CTNALL = findCtn.Name; //名称显示维护的箱型
}
else
{
@ -7597,7 +7610,48 @@ namespace Myshipping.Application
}
}
return jData.ToString();
return listRtn;
}
/// <summary>
/// 自动引入场站箱型箱量数据
/// </summary>
/// <param name="bookId"></param>
/// <returns></returns>
private async Task AutoYardData(long bookId)
{
var order = _rep.AsQueryable().Filter(null, true).First(x => x.Id == bookId);
var ctns = _repCtn.AsQueryable().Filter(null, true).Where(x => x.BILLID == bookId).ToList();
if (ctns.Count(x => !string.IsNullOrEmpty(x.CNTRNO) || !string.IsNullOrEmpty(x.SEALNO)) > 0) //有数据填写了箱封号,不再处理
{
_logger.LogInformation($"{bookId}({order.MBLNO})的数据已填写过箱封号,不再处理自动引入");
return;
}
var rtn = await GetYardDataAndMappingSystem(order, false);
await _repCtn.DeleteAsync(x => x.BILLID == bookId);
foreach (var item in rtn)
{
var ctn = new BookingCtn();
ctn.BILLID = order.Id;
ctn.CTNCODE = item.CtnCode;
ctn.CTNALL = item.CTNALL;
ctn.CTNNUM = item.XiangLiang;
ctn.CNTRNO = item.CNTRNO;
ctn.SEALNO = item.SEALNO;
ctn.KINDPKGS = string.IsNullOrEmpty(item.KINDPKGS) ? order.KINDPKGS : item.KINDPKGS;
ctn.PKGS = item.PKGS;
ctn.KGS = Convert.ToDecimal(item.KGS);
ctn.CBM = Convert.ToDecimal(item.CBM);
ctn.TAREWEIGHT = Convert.ToDecimal(item.TAREWEIGHT);
ctn.TenantId = order.TenantId;
ctn.CreatedUserId = order.CreatedUserId;
ctn.CreatedUserName = "系统";
await _repCtn.InsertAsync(ctn);
}
}
/// <summary>
@ -8310,162 +8364,11 @@ namespace Myshipping.Application
"} ";
}
[HttpGet("/BookingOrder/XHZGLJ"), AllowAnonymous]
public async Task XHZGLJ(long bookId = 432917132775494)
[HttpGet("/BookingOrder/AutoYard"), AllowAnonymous]
public async Task AutoYard(long bookId = 437779259732037)
{
var order = _rep.AsQueryable().Filter(null, true).First(x => x.Id == bookId);
var ctns = _repCtn.AsQueryable().Filter(null, true).Where(x => x.BILLID == bookId).ToList();
MemoryStream ms = new MemoryStream(File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XhzGlj.xls")));
var workbook = new HSSFWorkbook(ms);
FileStream fs = new FileStream(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XhzGlj_1.xls"), FileMode.Create);
var sheet = workbook.GetSheetAt(0);
//第一行标题
var title = $"下货纸清单-{order.LANENAME} SERVICE";
sheet.GetRow(0).GetCell(0).SetCellValue(title);
//船期B2
sheet.GetRow(1).GetCell(1).SetCellValue(order.ETD.HasValue ? order.ETD.Value.ToString("yyyy.MM.dd") : "");
//船名B3
sheet.GetRow(2).GetCell(1).SetCellValue(order.VESSEL);
//航次F3
sheet.GetRow(2).GetCell(5).SetCellValue(order.VOYNO);
//代理B4
sheet.GetRow(3).GetCell(1).SetCellValue(order.TenantName);
//联系电话F4
var usr = _repUser.AsQueryable().Filter(null, true).First(u => u.Id == order.CreatedUserId);
if (!string.IsNullOrEmpty(usr.Tel))
{
sheet.GetRow(3).GetCell(5).SetCellValue(usr.Tel);
}
else if (!string.IsNullOrEmpty(usr.Phone))
{
sheet.GetRow(3).GetCell(5).SetCellValue(usr.Phone);
}
else
{
sheet.GetRow(3).GetCell(5).SetCellValue("");
}
//订舱号B7
sheet.GetRow(6).GetCell(1).SetCellValue(order.CUSTNO);
//目的港C7
sheet.GetRow(6).GetCell(2).SetCellValue(order.PORTDISCHARGE);
//中转港D7
sheet.GetRow(6).GetCell(3).SetCellValue("");
//货名E7
sheet.GetRow(6).GetCell(4).SetCellValue(order.DESCRIPTION);
//件数F7
sheet.GetRow(6).GetCell(5).SetCellValue(order.PKGS.Value.ToString());
//重量G7
sheet.GetRow(6).GetCell(6).SetCellValue(Convert.ToDouble(order.KGS.Value).ToString());
//尺码H7
sheet.GetRow(6).GetCell(7).SetCellValue(Convert.ToDouble(order.CBM.Value).ToString());
//冻柜信息 温度C I7
if (order.CARGOID == "R")
{
sheet.GetRow(6).GetCell(8).SetCellValue(order.TEMPSET);
}
else
{
sheet.GetRow(6).GetCell(8).SetCellValue("");
}
//冻柜信息 通风CBM/H J7
if (order.CARGOID == "R")
{
sheet.GetRow(6).GetCell(9).SetCellValue(order.REEFERF);
}
else
{
sheet.GetRow(6).GetCell(9).SetCellValue("");
}
//冻柜信息 湿度% K7
if (order.CARGOID == "R")
{
sheet.GetRow(6).GetCell(10).SetCellValue(order.HUMIDITY);
}
else
{
sheet.GetRow(6).GetCell(10).SetCellValue("");
}
//整理箱型箱量
var groupList = ctns.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => new { CTNALL = g.Key.Replace("'", ""), CTNNUM = g.Sum(gg => gg.CTNNUM) });
//箱量 20GP L7
var findCtn = groupList.FirstOrDefault(x => x.CTNALL == "20GP");
if (findCtn != null)
{
sheet.GetRow(6).GetCell(11).SetCellValue(findCtn.CTNNUM.Value.ToString());
}
else
{
sheet.GetRow(6).GetCell(11).SetCellValue("");
}
//箱量 40GP M7
findCtn = groupList.FirstOrDefault(x => x.CTNALL == "40GP");
if (findCtn != null)
{
sheet.GetRow(6).GetCell(12).SetCellValue(findCtn.CTNNUM.Value.ToString());
}
else
{
sheet.GetRow(6).GetCell(12).SetCellValue("");
}
//箱量 40HC N7
findCtn = groupList.FirstOrDefault(x => x.CTNALL == "40HC");
if (findCtn != null)
{
sheet.GetRow(6).GetCell(13).SetCellValue(findCtn.CTNNUM.Value.ToString());
}
else
{
sheet.GetRow(6).GetCell(13).SetCellValue("");
}
//箱量 20RF O7
findCtn = groupList.FirstOrDefault(x => x.CTNALL == "20RF");
if (findCtn != null)
{
sheet.GetRow(6).GetCell(14).SetCellValue(findCtn.CTNNUM.Value.ToString());
}
else
{
sheet.GetRow(6).GetCell(14).SetCellValue("");
}
//箱量 40RH P7
findCtn = groupList.FirstOrDefault(x => x.CTNALL == "40RH");
if (findCtn != null)
{
sheet.GetRow(6).GetCell(15).SetCellValue(findCtn.CTNNUM.Value.ToString());
}
else
{
sheet.GetRow(6).GetCell(15).SetCellValue("");
}
//备注 场站/特殊要求 Q7
sheet.GetRow(6).GetCell(16).SetCellValue(order.YARDREMARK);
await AutoYardData(bookId);
workbook.Write(fs);
fs.Flush();
fs.Close();
}
#endregion

@ -0,0 +1,137 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application.Service.BookingOrder.Dto
{
public class BookingYardDataRtn
{
/// <summary>
/// 箱号
/// </summary>
public string CNTRNO { get; set; }
/// <summary>
/// 封号
/// </summary>
public string SEALNO { get; set; }
/// <summary>
/// 箱型
/// </summary>
public string CTNALL { get; set; }
/// <summary>
/// 箱量
/// </summary>
public int XiangLiang { get; set; }
/// <summary>
/// 船名
/// </summary>
public string VESSEL { get; set; }
/// <summary>
/// 航次
/// </summary>
public string VOYNO { get; set; }
/// <summary>
/// 中转港
/// </summary>
public string tra_name { get; set; }
/// <summary>
/// 卸货港
/// </summary>
public string pod_name { get; set; }
/// <summary>
/// 目的港
/// </summary>
public string Destination { get; set; }
/// <summary>
/// 皮重
/// </summary>
public float? TAREWEIGHT { get; set; }
/// <summary>
/// 车号
/// </summary>
public string CheHao { get; set; }
/// <summary>
/// 包装
/// </summary>
public string KINDPKGS { get; set; }
/// <summary>
/// 件数
/// </summary>
public int PKGS { get; set; }
/// <summary>
/// 尺码
/// </summary>
public float? CBM { get; set; }
/// <summary>
/// 货重
/// </summary>
public float? KGS { get; set; }
/// <summary>
/// 提箱时间
/// </summary>
public string TiXiangShiJian { get; set; }
/// <summary>
/// 返场时间
/// </summary>
public string FanChangShiJian { get; set; }
/// <summary>
/// 集港时间
/// </summary>
public string JiGangShiJian { get; set; }
/// <summary>
/// 计划集港开始时间
/// </summary>
public string PortStartPlanTime { get; set; }
/// <summary>
/// 计划集港结束时间
/// </summary>
public string PortEndPlanTime { get; set; }
/// <summary>
/// 完船时间
/// </summary>
public string WanChuanShiJian { get; set; }
/// <summary>
/// 危险品主等级
/// </summary>
public string DClass { get; set; }
/// <summary>
/// 危险品编号
/// </summary>
public string DUNNo { get; set; }
/// <summary>
/// 危险品副等级
/// </summary>
public string FuDClass { get; set; }
/// <summary>
/// 危险品副编号
/// </summary>
public string FuDUNNo { get; set; }
/// <summary>
/// 海污
/// </summary>
public string HaiWu { get; set; }
/// <summary>
/// 温度
/// </summary>
public string TempSet { get; set; }
/// <summary>
/// 通风
/// </summary>
public string Reeferf { get; set; }
/// <summary>
/// 湿度
/// </summary>
public string Humidity { get; set; }
}
public class BookingGetYardDataDto: BookingYardDataRtn
{
/// <summary>
/// 箱型代码
/// </summary>
public string CtnCode { get; set; }
}
}
Loading…
Cancel
Save