diff --git a/ds-wms-service/DS.WMS.Core/Code/Interface/ICodeLanesService.cs b/ds-wms-service/DS.WMS.Core/Code/Interface/ICodeLanesService.cs index 5d04c90e..d987c385 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Interface/ICodeLanesService.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Interface/ICodeLanesService.cs @@ -74,4 +74,16 @@ public interface ICodeLanesService /// public DataResult BatchDelCodeLanes(IdModel req); + /// + /// 获取航线基础数据 + /// + /// 是否从缓存提取 true-从缓存读取 false-从数据库读取 + /// 返回箱型基础数据列表 + Task>> GetAllList(bool isFromCache = true); + + /// + /// 加载到缓存 + /// + /// + Task LoadCache(); } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/Code/Method/CodeLanesService.cs b/ds-wms-service/DS.WMS.Core/Code/Method/CodeLanesService.cs index d182e247..6fbd6f8a 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Method/CodeLanesService.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Method/CodeLanesService.cs @@ -6,8 +6,10 @@ using DS.Module.UserModule; using DS.WMS.Core.Code.Dtos; using DS.WMS.Core.Code.Entity; using DS.WMS.Core.Code.Interface; +using DS.WMS.Core.Sys.Interface; using Mapster; using Microsoft.Extensions.DependencyInjection; +using Newtonsoft.Json; using SqlSugar; namespace DS.WMS.Core.Code.Method; @@ -18,6 +20,8 @@ public class CodeLanesService:ICodeLanesService private readonly ISqlSugarClient db; private readonly IUser user; private readonly ISaasDbService saasService; + private readonly ISysCacheService _sysCacheService; + /// /// /// @@ -28,6 +32,7 @@ public class CodeLanesService:ICodeLanesService db = _serviceProvider.GetRequiredService(); user = _serviceProvider.GetRequiredService(); saasService = _serviceProvider.GetRequiredService(); + _sysCacheService = _serviceProvider.GetRequiredService(); } public DataResult> GetListByPage(PageRequest request) @@ -53,7 +58,7 @@ public class CodeLanesService:ICodeLanesService var data = req.Adapt(); var entity = db.Insertable(data).ExecuteReturnEntity(); - + _sysCacheService.RemoveCache(Sys.Method.SysCacheCategoryEnum.CommonCodeLanes, "DS8").GetAwaiter().GetResult(); return DataResult.Successed("添加成功!", entity.Id,MultiLanguageConst.DataCreateSuccess); } else @@ -63,6 +68,7 @@ public class CodeLanesService:ICodeLanesService info = req.Adapt(info); db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); + _sysCacheService.RemoveCache(Sys.Method.SysCacheCategoryEnum.CommonCodeLanes, "DS8").GetAwaiter().GetResult(); return DataResult.Successed("更新成功!",MultiLanguageConst.DataUpdateSuccess); } } @@ -101,7 +107,7 @@ public class CodeLanesService:ICodeLanesService var data = req.Adapt(); var entity = tenantDb.Insertable(data).ExecuteReturnEntity(); - + _sysCacheService.RemoveCache(Sys.Method.SysCacheCategoryEnum.CommonCodeLanes, "DS8").GetAwaiter().GetResult(); return DataResult.Successed("添加成功!", entity.Id,MultiLanguageConst.DataCreateSuccess); } else @@ -111,6 +117,7 @@ public class CodeLanesService:ICodeLanesService info = req.Adapt(info); tenantDb.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); + _sysCacheService.RemoveCache(Sys.Method.SysCacheCategoryEnum.CommonCodeLanes, "DS8").GetAwaiter().GetResult(); return DataResult.Successed("更新成功!",MultiLanguageConst.DataUpdateSuccess); } } @@ -150,6 +157,7 @@ public class CodeLanesService:ICodeLanesService } tenantDb.Insertable(list).ExecuteCommand(); + _sysCacheService.RemoveCache(Sys.Method.SysCacheCategoryEnum.CommonCodeLanes, "DS8").GetAwaiter().GetResult(); return DataResult.Successed("引入成功!",MultiLanguageConst.DataImportSuccess); } @@ -173,6 +181,65 @@ public class CodeLanesService:ICodeLanesService { tenantDb.Deleteable(list).ExecuteCommand(); } + _sysCacheService.RemoveCache(Sys.Method.SysCacheCategoryEnum.CommonCodeLanes, "DS8").GetAwaiter().GetResult(); return DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess); } + + /// + /// 获取航线基础数据 + /// + /// 是否从缓存提取 true-从缓存读取 false-从数据库读取 + /// 返回箱型基础数据列表 + public async Task>> GetAllList(bool isFromCache = true) + { + List list = new List(); + + bool isLoad = false; + + if (isFromCache) + { + var rlt = await _sysCacheService.GetAllCommonCodeFromCache(Sys.Method.SysCacheCategoryEnum.CommonCodeLanes, "DS8"); + + if (rlt.Succeeded) + return rlt; + + isLoad = true; + } + + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + + list = tenantDb.Queryable() + .Select() + .Where(a => a.Status == StatusEnum.Enable).ToList(); + + if (list.Count > 0) + { + if (isLoad) + { + await _sysCacheService.SetCommonCode(JsonConvert.SerializeObject(list), Sys.Method.SysCacheCategoryEnum.CommonCodeLanes, "DS8"); + } + + return DataResult>.Success(list); + } + + return DataResult>.FailedData(list); + } + + /// + /// 加载到缓存 + /// + /// + public async Task LoadCache() + { + var rlt = await GetAllList(false); + + if (rlt.Succeeded) + { + await _sysCacheService.SetCommonCode(JsonConvert.SerializeObject(rlt.Data), Sys.Method.SysCacheCategoryEnum.CommonCodeLanes, "DS8"); + + return DataResult.Successed(MultiLanguageConst.LoadCacheSucc); + } + + return DataResult.Failed(MultiLanguageConst.LoadCacheFailDataNull); + } } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/Op/Interface/BookingSlot/IBookingSlotService.cs b/ds-wms-service/DS.WMS.Core/Op/Interface/BookingSlot/IBookingSlotService.cs index 948d11d4..aed5a3c1 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Interface/BookingSlot/IBookingSlotService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Interface/BookingSlot/IBookingSlotService.cs @@ -162,7 +162,7 @@ namespace DS.WMS.Core.Op.Interface /// 舱位主键 /// 请求批次号用来区分对应的哪个批次任务 /// - Task PushCompareBCInfo(ParserBCInfoDto bcSrcDto, ParserBCInfoDto bcTargetDto, long slotId, string reqBatchNo); + Task> PushCompareBCInfo(ParserBCInfoDto bcSrcDto, ParserBCInfoDto bcTargetDto, long slotId, string reqBatchNo); /// /// 估算差异重要提醒 @@ -201,5 +201,12 @@ namespace DS.WMS.Core.Op.Interface /// 生成订舱订单请求 /// 返回回执 Task MergeCreateBookingOrder(BookingGenerateDto model); + + /// + /// 导出舱位为Excel + /// + /// 请求参数 + /// + Task> ExportOrder(BookingSlotBasePageInput input); } } diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/BookingSlot/BookingSlotService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/BookingSlot/BookingSlotService.cs index ef8965ca..a589150b 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/BookingSlot/BookingSlotService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/BookingSlot/BookingSlotService.cs @@ -50,6 +50,7 @@ using DS.Module.Core.Extensions; using DS.Module.Core.Constants; using DS.Module.Core.Data; using DS.WMS.Core.TaskPlat.Dtos; +using NPOI.XSSF.UserModel; namespace DS.WMS.Core.Op.Method { @@ -76,7 +77,8 @@ namespace DS.WMS.Core.Op.Method private readonly ICodePortService _codePortService; private readonly IMappingPortService _mappingPortService; private readonly ICodeCountryService _codeCountryService; - + private readonly ICodeLanesService _codeLanesService; + private readonly string bcCompareUrl; @@ -129,6 +131,7 @@ namespace DS.WMS.Core.Op.Method _mappingPortService = _serviceProvider.GetRequiredService(); _mappingCarrierService = _serviceProvider.GetRequiredService(); _codeCountryService = _serviceProvider.GetRequiredService(); + _codeLanesService = _serviceProvider.GetRequiredService(); bcCompareUrl = AppSetting.app(new string[] { "BCCompare", "Url" }); } @@ -1450,7 +1453,7 @@ namespace DS.WMS.Core.Op.Method /// 附件类型名称 /// 附件模块代码 /// - private async Task SaveEDIFile(long boookId, string FilePath, string fileName, long tenantId, + private async Task> SaveEDIFile(long boookId, string FilePath, string fileName, long tenantId, string fileTypeCode = "bc", string fileTypeName = "Booking Confirmation", string moudle = "BookingSlot") { /* @@ -1469,6 +1472,8 @@ namespace DS.WMS.Core.Op.Method }; await tenantDb.Insertable(newFile).ExecuteCommandAsync(); + + return DataResult.Success(string.Empty); } #endregion @@ -1572,7 +1577,7 @@ namespace DS.WMS.Core.Op.Method /// 请求批次号用来区分对应的哪个批次任务 /// [NonAction] - public async Task PushCompareBCInfo(ParserBCInfoDto bcSrcDto, ParserBCInfoDto bcTargetDto, long slotId, string reqBatchNo) + public async Task> PushCompareBCInfo(ParserBCInfoDto bcSrcDto, ParserBCInfoDto bcTargetDto, long slotId, string reqBatchNo) { var tenantDb = saasService.GetBizDbScopeById(user.TenantId); @@ -1651,6 +1656,8 @@ namespace DS.WMS.Core.Op.Method { //new EmailNoticeHelper().SendEmailNotice($"MBLNO={bcSrcDto.MBLNo} 与舱位比对差异失败,未获取到比对结果", $"MBLNO={bcSrcDto.MBLNo} 与舱位比对差异失败,未获取到比对结果", App.Configuration["EmailNoticeDefaultUser"].GetUserEmailList()); } + + return DataResult.Success(string.Empty); } #endregion @@ -2772,9 +2779,9 @@ namespace DS.WMS.Core.Op.Method /// 新舱位详情 /// 舱位ID /// - public async Task MeasureDiffCautionTask(ParserBCInfoDto bcSrcDto, ParserBCInfoDto bcTargetDto, long slotId) + public async Task> MeasureDiffCautionTask(ParserBCInfoDto bcSrcDto, ParserBCInfoDto bcTargetDto, long slotId) { - return; + return DataResult.Success(string.Empty); } /// @@ -2789,6 +2796,7 @@ namespace DS.WMS.Core.Op.Method return null; } + #region 导入舱位 /// /// 导入舱位 /// @@ -2796,8 +2804,656 @@ namespace DS.WMS.Core.Op.Method /// 返回回执 public async Task ImportSlotFromFile(IFormFile file) { - return null; + TaskManageOrderResultDto result = new TaskManageOrderResultDto(); + + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + + try + { + 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().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> data = new(rowCount); + //List data = new(rowCount); + + var cacheMappCarrier = _mappingCarrierService.GetAllList().GetAwaiter().GetResult().Data; + var cachePort = _codePortService.GetAllList().GetAwaiter().GetResult().Data; + var cacheLane = _codeLanesService.GetAllList().GetAwaiter().GetResult().Data; + var cacheCtnCode = _codeCtnService.GetAllList().GetAwaiter().GetResult().Data; + + 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.SlotBookingNo = value; break; + case 1: slot.CarrierCode = value; break; + case 2: slot.Vessel = value; break; + case 3: slot.Voyno = value; break; + case 4: slot.ContractNo = value; break; + case 5: slot.BookingSlotTypeName = value; break; + case 6: + slot.ETD = cell.DateCellValue; break; + //{ + // if (DateTime.TryParse(value, out DateTime temp)) slot.ETD = temp; break; + //} + case 7: + slot.ETA = cell.DateCellValue; break; + //{ + // if (DateTime.TryParse(value, out DateTime temp)) slot.ETA = temp; break; + //} + case 8: slot.BookingParty = value; break; + case 9: slot.PlaceReceipt = value; break; + case 10: slot.PlaceDelivery = value; break; + case 11: slot.PortLoadCode = value; break; + case 12: slot.PortDischargeCode = value; break; + case 13: + { + if (int.TryParse(value, out int temp)) slot.WeekAt = temp; break; + } + case 14: + { + //if (DateTime.TryParse(value, out DateTime temp)) slot.SI_CUT_DATE = temp; break; + slot.SICutDate = cell.DateCellValue; break; + } + case 15: + { + //if (DateTime.TryParse(value, out DateTime temp)) slot.VGM_SUBMISSION_CUT_DATE = temp; break; + slot.VGMSubmissionCutDate = cell.DateCellValue; break; + } + case 16: + { + //if (DateTime.TryParse(value, out DateTime temp)) slot.CY_CUT_DATE = temp; break; + slot.CYCutDate = cell.DateCellValue; break; + } + case 17: + { + //if (DateTime.TryParse(value, out DateTime temp)) slot.MANIFEST_CUT_DATE = temp; break; + slot.ManifestCutDate = cell.DateCellValue; break; + } + case 18: + { + //if (DateTime.TryParse(value, out DateTime temp)) slot.MDGF_CUT_DATE = temp; break; + slot.MDGFCutDate = cell.DateCellValue; break; + } + case 19: slot.LaneName = value; break; // + case 20: + { + if (int.TryParse(value, out int temp)) slot.DetensionFreeDays = temp; break; + } + case 21: + { + //if (DateTime.TryParse(value, out DateTime temp)) slot.CreatedTime = temp; break; + slot.CreateTime = cell.DateCellValue.Value; break; + } + case 22: + { + //if (DateTime.TryParse(value, out DateTime temp)) slot.PRICE_CALCULATION_DATE = temp; break; + slot.PriceCalculationDate = cell.DateCellValue; break; + } + default: break; + } + } + // 特殊处理 + if (!string.IsNullOrWhiteSpace(slot.CarrierCode)) slot.Carrier = cacheCarrier.FirstOrDefault(x => x.EnName == slot.CarrierCode)?.CnName; + if (!string.IsNullOrWhiteSpace(slot.PortLoadCode)) slot.PortLoad = cachePort.FirstOrDefault(x => x.EdiCode == slot.PortLoadCode)?.PortName; + if (!string.IsNullOrWhiteSpace(slot.PortDischargeCode)) slot.PortDischarge = cachePort.FirstOrDefault(x => x.EdiCode == slot.PortDischargeCode)?.PortName; + if (!string.IsNullOrWhiteSpace(slot.LaneName)) slot.LaneCode = cacheLane.FirstOrDefault(x => x.LaneName == slot.LaneName)?.Code; + if (!string.IsNullOrWhiteSpace(slot.BookingSlotTypeName)) + slot.BookingSlotType = slot.BookingSlotTypeName switch + { + "合约订舱" => "CONTRACT_ORDER", + "SPOT订舱" => "SPOT_ORDER", + _ => null + }; + + var ctns = new List(); + + 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.SlotBookingNo).ToList(); + var existsNoList = await tenantDb.Queryable() + .Where(x => noList.Contains(x.SlotBookingNo)) + .Select(x => x.SlotBookingNo) + .ToListAsync(); + + List list = new List(); + result.ext = list; + foreach (var item in data) + { + if (existsNoList.Contains(item.Key.SlotBookingNo)) + { + list.Add(new + { + IsSuccess = false, + FailReason = "此订舱编号已存在", + SlotBookingNo = item.Key.SlotBookingNo + }); + continue; + } + + await tenantDb.Insertable(item.Key).ExecuteReturnEntityAsync(); + var id = item.Key.Id; + if (item.Value.Any()) + { + item.Value.ForEach(x => + { + x.SlotId = id; + }); + await tenantDb.Insertable(item.Value).ExecuteCommandAsync(); + } + list.Add(new + { + IsSuccess = true, + SlotBookingNo = item.Key.SlotBookingNo + }); + } + + result.succ = true; + + var group = data.Keys.Where(x => + !existsNoList.Contains(x.SlotBookingNo) + && !string.IsNullOrEmpty(x.Vessel) + && !string.IsNullOrEmpty(x.Voyno) + && !string.IsNullOrEmpty(x.ContractNo) + && !string.IsNullOrEmpty(x.BookingSlotType) + && !string.IsNullOrEmpty(x.CarrierCode) + && !string.IsNullOrEmpty(x.PortLoadCode) + && !string.IsNullOrEmpty(x.PortDischargeCode)) + .GroupBy(x => new + { + x.Vessel, + x.Voyno, + x.CarrierCode, + x.BookingSlotType, + x.PortDischargeCode, + x.PortLoadCode, + x.ContractNo + }).ToList(); + + foreach (var item in group) + { + await _bookingSlotStockService.BookingSlotStock(new BookingSlotStockUpdateModel + { + BookingSlotType = item.Key.BookingSlotType, + CarrierCode = item.Key.CarrierCode, + ContractNo = item.Key.ContractNo, + Vessel = item.Key.Vessel, + Voyno = item.Key.Voyno, + PortLoadId = item.Key.PortLoadCode, + PortDischargeId = item.Key.PortDischargeCode, + TenantId = long.Parse(user.TenantId) + }); + } + } + catch (Exception ex) + { + Logger.Log(NLog.LogLevel.Error, $"导入舱位异常,原因:{ex.Message}"); + + result.succ = false; + result.msg = $"导入舱位异常,原因:{ex.Message}"; + } + + return result; } + #endregion + + #region 导出舱位为Excel + /// + /// 导出舱位为Excel + /// + /// 请求参数 + /// + public async Task> ExportOrder(BookingSlotBasePageInput input) + { + ISugarQueryable select = null; + + /* + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + // 箱型筛选 + string[] ctnCodeArr = null; + if (!string.IsNullOrEmpty(input.CTN_STAT)) + { + ctnCodeArr = input.CTN_STAT.Split(','); + select = tenantDb.Queryable().InnerJoin((u, c) => u.Id == c.SlotId); + } + else + { + select = tenantDb.Queryable(); + } + + select = select.WhereIF(!string.IsNullOrEmpty(input.SLOT_BOOKING_NO), u => u.SlotBookingNo.Contains(input.SLOT_BOOKING_NO)) + .WhereIF(!string.IsNullOrEmpty(input.SLOT_BOOKING_NO), u => u.SlotBookingNo.Contains(input.SLOT_BOOKING_NO)) + .WhereIF(input.STATUS == 1, u => !u.IsCancellation) + .WhereIF(input.STATUS == 2, u => u.IsCancellation) + .WhereIF(!string.IsNullOrEmpty(input.VESSEL), u => u.Vessel.Contains(input.VESSEL)) + .WhereIF(!string.IsNullOrEmpty(input.VOYNO), u => u.Voyno.Contains(input.VOYNO)) + .WhereIF(!string.IsNullOrEmpty(input.PORTLOAD), u => u.PORTLOAD.Contains(input.PORTLOAD)) + .WhereIF(!string.IsNullOrEmpty(input.PORTDISCHARGE), u => u.PORTDISCHARGE.Contains(input.PORTDISCHARGE)) + + .WhereIF(input.ETD_START.HasValue, u => u.ETD >= input.ETD_START.Value) + .WhereIF(input.ETD_END.HasValue, u => u.ETD < input.ETD_END.Value.AddDays(1)) + .WhereIF(input.ETA_START.HasValue, u => u.ETA >= input.ETA_START.Value) + .WhereIF(input.ETA_END.HasValue, u => u.ETA < input.ETA_END.Value.AddDays(1)) + .WhereIF(!string.IsNullOrEmpty(input.CreatedUserName), u => u.CreatedUserName.Contains(input.CreatedUserName)) + .WhereIF(!string.IsNullOrEmpty(input.UpdatedUserName), u => u.UpdatedUserName.Contains(input.UpdatedUserName)) + + .WhereIF(!string.IsNullOrEmpty(input.CARRIER), u => u.CARRIER.Contains(input.CARRIER)) + .WhereIF(!string.IsNullOrEmpty(input.CONTRACT_NO), u => u.CONTRACT_NO.Contains(input.CONTRACT_NO)) + .WhereIF(!string.IsNullOrEmpty(input.SI_RLT_STAT), u => u.SI_RLT_STAT == input.SI_RLT_STAT) + .WhereIF(!string.IsNullOrEmpty(input.VGM_RLT_STAT), u => u.VGM_RLT_STAT == input.VGM_RLT_STAT) + .WhereIF(!string.IsNullOrEmpty(input.CARRIAGE_TYPE), u => u.CARRIAGE_TYPE == input.CARRIAGE_TYPE) + .WhereIF(!string.IsNullOrEmpty(input.BOOKING_SLOT_TYPE), u => u.BOOKING_SLOT_TYPE == input.BOOKING_SLOT_TYPE) + + .WhereIF(!string.IsNullOrEmpty(input.LANENAME), u => u.LANENAME.Contains(input.LANENAME)) + .WhereIF(input.WEEK_AT != null, u => u.WEEK_AT == input.WEEK_AT) + + //.WhereIF(isEnableCustomerAuthority, u => SqlFunc.Subqueryable() + // .Where(x => x.BOOKING_SLOT_ID == u.Id) + // .NotAny() + // || SqlFunc.Subqueryable() + // .Where(x => x.BOOKING_SLOT_ID == u.Id + // && userList.Contains((long)x.CreatedUserId) + // || userListStr.Contains(x.OPID) + // || userListStr.Contains(x.SALEID) + // || userListStr.Contains(x.DOCID) + // || userListStr.Contains(x.CUSTSERVICEID)) + // .Any()) + // 标签筛选 + .WhereIF(input.LabelIdArray != null && input.LabelIdArray.Length > 0, + u => SqlFunc.Subqueryable() + .Where(x => x.BusinessId == u.Id && input.LabelIdArray.Contains(x.LabelId)) + .Any()); + + if (ctnCodeArr != null && ctnCodeArr.Length > 0) + { + var tempSelect = select as ISugarQueryable; + tempSelect.Where((u, c) => ctnCodeArr.Contains(c.CTNCODE)); + } + //var sql = select.OrderByDescending(u => u.CreatedTime).ToSqlString(); + + var entities = await select.OrderByDescending(u => u.Id).ToListAsync(); + + var data = entities.Adapt>(); + + var slotIds = entities.Select(x => x.Id); + + if (slotIds.Any()) + { + // 查询舱位绑定的销售信息,赋值到舱位对象中 + List allocationInfoList = await _repAllocation.AsQueryable() + .Where(x => slotIds.Contains(x.BOOKING_SLOT_ID)) + .Select(x => new BookingSlotSaleInfoDto + { + Id = x.Id, + BOOKING_ID = x.BOOKING_ID, + BOOKING_SLOT_ID = x.BOOKING_SLOT_ID, + CUSTOMERID = x.CUSTOMERID, + CUSTOMERNAME = x.CUSTOMERNAME, + CUSTSERVICEID = x.CUSTSERVICEID, + CUSTSERVICE = x.CUSTSERVICE, + SALEID = x.SALEID, + SALE = x.SALE, + OPID = x.OPID, + OP = x.OP, + DOCID = x.DOCID, + DOC = x.DOC, + BUSINESS = x.BUSINESS, + BUSINESSID = x.BUSINESSID, + SALE_TIME = x.SALE_TIME, + SHIPPER = x.SHIPPER, + GOODSNAME = x.GOODSNAME, + SELLING_PRICE = x.SELLING_PRICE + }).ToListAsync(); + if (allocationInfoList.Any()) + { + // 判断是否启用了委托单位查看控制权限 + var tenantParamList = await _cache.GetAllTenantParam(); + var isEnableCustomerAuthority = tenantParamList.FirstOrDefault(x => x.TenantId == UserManager.TENANT_ID + && x.ParaCode == TenantParamCode.IS_ENABLE_CUSTOMER_AUTHORITY)?.ItemCode == "YES"; + List userList = null; + List userListStr = null; + if (isEnableCustomerAuthority) + { + userList = await _sysDataUserMenuService.GetDataScopeList(MenuConst.MenuDjyCustomer); + if (userList == null || userList.Count == 0) + { + isEnableCustomerAuthority = false; + } + else + { + userListStr = userList.Select(x => x.ToString()).ToList(); + } + } + + var saleInfoGroup = allocationInfoList.GroupBy(x => x.BOOKING_SLOT_ID); + foreach (var item in saleInfoGroup) + { + if (isEnableCustomerAuthority) + { + // 遍历销售信息,如果销售信息中的“销售、操作、单证、客服、创建人”中不在当前登陆人的权限范围,则隐藏客户信息 + foreach (BookingSlotSaleInfoDto saleInfoItem in item) + { + if (!userList.Contains(saleInfoItem.CreatedUserId ?? 0) + && !userListStr.Contains(saleInfoItem.OPID) + && !userListStr.Contains(saleInfoItem.DOCID) + && !userListStr.Contains(saleInfoItem.SALEID) + && !userListStr.Contains(saleInfoItem.CUSTSERVICEID)) + { + saleInfoItem.CUSTOMERID = 0; + saleInfoItem.CUSTOMERNAME = "--"; + saleInfoItem.OPID = ""; + saleInfoItem.OP = "--"; + saleInfoItem.DOCID = ""; + saleInfoItem.DOC = "--"; + saleInfoItem.SALEID = ""; + saleInfoItem.SALE = "--"; + saleInfoItem.SHIPPER = "--"; + saleInfoItem.GOODSNAME = "--"; + saleInfoItem.CUSTSERVICEID = ""; + saleInfoItem.CUSTSERVICE = "--"; + } + } + } + + var slot = data.FirstOrDefault(x => x.Id == item.Key); + if (slot != null) + { + slot.BookingSlotSaleInfoList = item.ToList(); + } + } + } + + // 查询舱位绑定的标签信息,赋值到舱位对象中 + var labelCacheList = await _bookingLabelService.List(1); + var labelAllocationList = await _repLabelAllocation.AsQueryable() + .Where(x => slotIds.Contains(x.BusinessId)) + .ToListAsync(); + if (labelAllocationList.Any()) + { + var labelInfoGroup = labelAllocationList.GroupBy(x => x.BusinessId); + foreach (var item in labelInfoGroup) + { + var slot = data.FirstOrDefault(x => x.Id == item.Key); + if (slot != null) + { + slot.LabelList = item.Select(x => + { + var labelCache = labelCacheList.FirstOrDefault(l => l.Id == x.LabelId); + if (labelCache != null) + { + return new BookingLabelBaseDto + { + Id = x.LabelId, + Name = labelCache.Name, + Color = labelCache.Color, + Scope = labelCache.Scope + }; + } + return null; + }).ToList(); + slot.LabelList.RemoveAll(x => x == null); + } + } + } + + } + + var opt = App.GetOptions(); + var dirAbs = opt.basePath; + if (string.IsNullOrEmpty(dirAbs)) + { + dirAbs = App.WebHostEnvironment.WebRootPath; + } + var fileAbsPath = Path.Combine(dirAbs, "upload/printtemplate/舱位信息导出模板.xlsx"); + if (!File.Exists(fileAbsPath)) + { + throw Oops.Bah("舱位导出模板文件不存在"); + } + var fs = new FileStream(fileAbsPath, FileMode.Open); + var excelwork = new XSSFWorkbook(fs); + var sheet = excelwork.GetSheet("导出"); + + var rowIndex = 1; + var dateStr = "yyyy-MM-dd"; + var dateTimeStr = "yyyy-MM-dd HH:mm:ss"; + foreach (BookingSlotBaseListOutput item in data) + { + var row = sheet.GetRow(rowIndex); + if (row == null) + { + row = sheet.CreateRow(rowIndex); + } + + for (int i = 0; i <= 35; i++) + { + var cell = row.GetCell(i); + if (cell == null) + { + cell = row.CreateCell(i); + } + var value = i switch + { + 0 => item.SLOT_BOOKING_NO, + 1 => item.CARRIER, + 2 => item.VESSEL, + 3 => item.VOYNO, + 4 => item.CONTRACT_NO, + 5 => item.BOOKING_SLOT_TYPE_NAME, + 6 => item.ETD?.ToString(dateTimeStr), + 7 => item.ETA?.ToString(dateTimeStr), + 8 => item.BOOKING_PARTY, + 9 => item.IS_CANCELLATION ? "是" : "", + 10 => item.PLACERECEIPT, + 11 => item.PLACEDELIVERY, + 12 => item.PORTLOAD, + 13 => item.PORTDISCHARGE, + 14 => item.CTN_STAT, + 15 => item.WEEK_AT?.ToString(), + 16 => item.SI_CUT_DATE?.ToString(dateTimeStr), + 17 => item.VGM_SUBMISSION_CUT_DATE?.ToString(dateTimeStr), + 18 => item.CY_CUT_DATE?.ToString(dateTimeStr), + 19 => item.MANIFEST_CUT_DATE?.ToString(dateTimeStr), + 20 => item.MDGF_CUT_DATE?.ToString(dateTimeStr), + 21 => item.LANENAME, + 22 => item.DETENSION_FREE_DAYS?.ToString(), + 23 => item.CreatedTime?.ToString(dateTimeStr), + 24 => item.VGM_RLT_STAT, + 25 => item.SI_RLT_STAT, + 26 => item.TAKE_CTN_RLT_STAT, + 27 => item.RETURN_CTN_RLT_STAT, + 28 => item.NOMINATION_RLT_STAT, + 29 => item.AMENDMENT_RLT_STAT, + 30 => item.CANCELLATION_RLT_STAT, + 31 => item.DISCHARGE_FULL_RLT_STAT, + 32 => item.GATE_OUTFULL_RLT_STAT, + 33 => "", + 34 => item.REMARK, + 35 => item.PRICE_CALCULATION_DATE?.ToString(dateStr), + _ => "" + }; + cell.SetCellValue(value); + } + + if (item.BookingSlotSaleInfoList != null && item.BookingSlotSaleInfoList.Count > 0) + { + for (int m = 0; m < item.BookingSlotSaleInfoList.Count; m++) + { + BookingSlotSaleInfoDto saleItem = item.BookingSlotSaleInfoList[m]; + var row2 = sheet.GetRow(rowIndex); + if (row2 == null) + { + row2 = sheet.CreateRow(rowIndex); + } + for (int i = 36; i <= 42; i++) + { + var cell2 = row2.GetCell(i); + if (cell2 == null) + { + cell2 = row2.CreateCell(i); + } + var value2 = i switch + { + 36 => saleItem.CUSTOMERNAME, + 37 => saleItem.CUSTSERVICE, + 38 => saleItem.SALE, + 39 => saleItem.SHIPPER, + 40 => saleItem.GOODSNAME, + 41 => saleItem.SELLING_PRICE?.ToString(), + 42 => saleItem.SALE_TIME?.ToString(dateTimeStr), + _ => "" + }; + cell2.SetCellValue(value2); + } + // 如果不是最后一条数据,创建新行 + if (m < item.BookingSlotSaleInfoList.Count - 1) + { + rowIndex++; + } + } + } + rowIndex++; + } + + var fileFullPath = Path.Combine(App.WebHostEnvironment.WebRootPath, App.GetOptions().Path);//服务器路径 + if (!Directory.Exists(fileFullPath)) + { + Directory.CreateDirectory(fileFullPath); + } + var fileName = $"舱位导出_{DateTime.Now.ToString("yyyyMMdd-HHmmss")}.xlsx";//名称 + var filestream = new FileStream(Path.Combine(fileFullPath, fileName), FileMode.OpenOrCreate, FileAccess.ReadWrite); + excelwork.Write(filestream); + + await Task.Delay(2000); + //return HttpUtility.UrlEncode(fileName, Encoding.GetEncoding("UTF-8")); + return fileName;*/ + + return ""; + } + #endregion Task>> IBookingSlotService.GetAvailableSlots(BookingSlotBaseDto slotInput, List slotIdListInput, PageWithTotal pageInfo) { diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/SpaceBooking/SpaceBookingMSKAPIService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/SpaceBooking/SpaceBookingMSKAPIService.cs index 4750a82d..7a79329d 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/SpaceBooking/SpaceBookingMSKAPIService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/SpaceBooking/SpaceBookingMSKAPIService.cs @@ -711,16 +711,19 @@ namespace DS.WMS.Core.Op.Method //throw Oops.Bah($"查询船期错误,pid={model.PId} 预计到港日期arrivalDateTime 格式解析错误"); } - currDto.transportMode = new MSKAPIBookingTransportMode + if (detail.transport.vessel != null) { - vessel = new MSKAPIBookingTransportModeVessel + currDto.transportMode = new MSKAPIBookingTransportMode { - name = detail.transport.vessel.vesselName, - maerskVesselCode = detail.transport.vessel.carrierVesselCode, - vesselIMONumber = detail.transport.vessel.vesselIMONumber - }, - exportVoyageNumber = detail.transport.carrierDepartureVoyageNumber, - }; + vessel = new MSKAPIBookingTransportModeVessel + { + name = detail.transport.vessel.vesselName, + maerskVesselCode = detail.transport.vessel.carrierVesselCode, + vesselIMONumber = detail.transport.vessel.vesselIMONumber + }, + exportVoyageNumber = detail.transport.carrierDepartureVoyageNumber, + }; + } currDto.serviceCode = detail.transport.carrierServiceCode; currDto.transportModeCode = detail.transport.transportMode; diff --git a/ds-wms-service/DS.WMS.Core/Sys/Method/SysCacheService.cs b/ds-wms-service/DS.WMS.Core/Sys/Method/SysCacheService.cs index 825d75ee..34ab6536 100644 --- a/ds-wms-service/DS.WMS.Core/Sys/Method/SysCacheService.cs +++ b/ds-wms-service/DS.WMS.Core/Sys/Method/SysCacheService.cs @@ -115,6 +115,11 @@ namespace DS.WMS.Core.Sys.Method [Description("国家基础信息")] CommonCodeCountry, /// + /// 航线基础信息 + /// + [Description("航线基础信息")] + CommonCodeLanes, + /// /// 场站映射信息 /// [Description("场站映射信息")]